1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix a problem with using streaming iterators with sqlite3changegroup_add_change().

FossilOrigin-Name: 3dbde727146d28c316df47c7b5116be7f2476a0a0c893207c2a4ca3ab285cb5e
This commit is contained in:
dan
2025-05-22 18:04:48 +00:00
parent 4a0b7a332f
commit 96e16194b8
5 changed files with 66 additions and 22 deletions

View File

@ -1459,6 +1459,9 @@ struct TestChangegroup {
typedef struct TestChangeIter TestChangeIter;
struct TestChangeIter {
sqlite3_changeset_iter *pIter;
/* If this iter uses streaming. */
TestStreamInput in;
};
@ -1681,6 +1684,7 @@ static int SQLITE_TCLAPI test_sqlite3changeset_start(
sqlite3_changeset_iter *pIter = 0;
int flags = 0;
int rc = SQLITE_OK;
int nAlloc = 0; /* Bytes of space to allocate */
static int iCmd = 1;
char zCmd[64];
@ -1696,18 +1700,36 @@ static int SQLITE_TCLAPI test_sqlite3changeset_start(
return TCL_ERROR;
}
flags = isInvert ? SQLITE_CHANGESETSTART_INVERT : 0;
pChangeset = (void *)Tcl_GetByteArrayFromObj(objv[objc-1], &nChangeset);
rc = sqlite3changeset_start_v2(&pIter, (int)nChangeset, pChangeset, flags);
flags = isInvert ? SQLITE_CHANGESETSTART_INVERT : 0;
nAlloc = sizeof(TestChangeIter);
if( test_tcl_integer(interp, SESSION_STREAM_TCL_VAR) ){
nAlloc += nChangeset;
}
pNew = (TestChangeIter*)ckalloc(nAlloc);
memset(pNew, 0, nAlloc);
if( test_tcl_integer(interp, SESSION_STREAM_TCL_VAR) ){
pNew->in.nStream = test_tcl_integer(interp, SESSION_STREAM_TCL_VAR);
pNew->in.nData = nChangeset;
pNew->in.aData = (unsigned char*)&pNew[1];
memcpy(pNew->in.aData, pChangeset, nChangeset);
}
if( pNew->in.nStream ){
void *pCtx = (void*)&pNew->in;
rc = sqlite3changeset_start_v2_strm(&pIter, testStreamInput, pCtx, flags);
}else{
rc = sqlite3changeset_start_v2(&pIter, (int)nChangeset, pChangeset, flags);
}
if( rc!=SQLITE_OK ){
char *zErr = sqlite3_mprintf(
"error in sqlite3changeset_start_v2() - %d", rc
);
Tcl_AppendResult(interp, zErr, (char*)0);
ckfree(pNew);
return TCL_ERROR;
}
pNew = (TestChangeIter*)ckalloc(sizeof(TestChangeIter));
pNew->pIter = pIter;
sprintf(zCmd, "csiter%d", iCmd++);