[patches] [PATCH 1/4] sql: Return last updated tuple if requested
v.shpilevoy at tarantool.org
v.shpilevoy at tarantool.org
Tue Mar 20 21:12:23 MSK 2018
>> diff --git a/src/box/sql.c b/src/box/sql.c
>> index e32ff2383..73fd13996 100644
>> --- a/src/box/sql.c
>> +++ b/src/box/sql.c
>> @@ -519,7 +519,8 @@ int tarantoolSqlite3EphemeralDrop(BtCursor *pCur)
>> return SQLITE_OK;
>> }
>>
>> -static int insertOrReplace(BtCursor *pCur, int operationType)
>> +static int
>> +insertOrReplace(BtCursor *pCur, int operationType, struct tuple **tuple)
>> {
>> assert(pCur->curFlags & BTCF_TaCursor);
>> assert(operationType == TARANTOOL_INDEX_INSERT ||
>> @@ -527,27 +528,33 @@ static int insertOrReplace(BtCursor *pCur, int operationType)
>>
>> int space_id = SQLITE_PAGENO_TO_SPACEID(pCur->pgnoRoot);
>> int rc;
>> + if (tuple != NULL && *tuple != NULL) {
>> + tuple_unref(*tuple);
>> + *tuple = NULL;
>> + }
>
> When do you ever need to dereference the previous tuple? If you
> simply emit it from sqlite3_step(), you won't have to worry about
> dereference.
It is wrong. You again forgot about multiple replace/insert. This functions is called multiple times on multiple DML, and only last tuple must be saved. But we must to reference each one and unreference a previous, because we do not know which is last.
>
> --
> Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
> http://tarantool.org - www.twitter.com/kostja_osipov
More information about the Tarantool-patches
mailing list