diff --git a/patch/0006-Support-Binlog.patch b/patch/0006-Support-Binlog.patch index 1fcaa0c2c9275a4ca76f5ea27e1b7dcfc221dad1..09df1f6e14dafa20cb079accde0a505c59e9757c 100644 --- a/patch/0006-Support-Binlog.patch +++ b/patch/0006-Support-Binlog.patch @@ -1,14 +1,14 @@ -From 51e8e916320226d0dd6d85bdca8bceb4c0e40cf6 Mon Sep 17 00:00:00 2001 +From 2b214cecd67e4fbc413ee341daad9c14ac16b3a2 Mon Sep 17 00:00:00 2001 From: Liu Hongyang -Date: Fri, 11 Jul 2025 10:33:52 +0800 +Date: Thu, 17 Jul 2025 10:18:46 +0800 Subject: [PATCH 06/12] Support-Binlog --- - src/sqlite3.c | 1508 ++++++++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 1499 insertions(+), 9 deletions(-) + src/sqlite3.c | 1530 ++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 1521 insertions(+), 9 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index e7e8b3c..3f1195a 100644 +index e7e8b3c..9399be8 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -2938,7 +2938,9 @@ SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); @@ -322,14 +322,36 @@ index e7e8b3c..3f1195a 100644 } /* -@@ -91886,6 +92123,44 @@ SQLITE_API int sqlite3_set_droptable_handle(sqlite3 *db, void (*xFunc)(sqlite3*, +@@ -91886,6 +92123,66 @@ SQLITE_API int sqlite3_set_droptable_handle(sqlite3 *db, void (*xFunc)(sqlite3*, } #endif /* SQLITE_ENABLE_DROPTABLE_CALLBACK */ +#ifdef SQLITE_ENABLE_BINLOG ++ ++/** ++ * return 0 for cannot open and 1 for can open ++ */ ++SQLITE_PRIVATE int sqlite3BinlogCanOpen() ++{ ++ int isCanOpen = 0; ++#ifndef _WIN32 ++ void *handle = dlopen("libarkdata_db_core.z.so", RTLD_LAZY); ++ if (handle != NULL) { ++ dlclose(handle); ++ isCanOpen = 1; ++ } ++#endif ++ return isCanOpen; ++} ++ ++/* 0 for not support, 1 for support, -1 for not init */ ++static i8 binlogSoInit = -1; +SQLITE_API int sqlite3_is_support_binlog(void) +{ -+ return SQLITE_ERROR; ++ if (binlogSoInit < 0) { ++ binlogSoInit = sqlite3BinlogCanOpen(); ++ } ++ return binlogSoInit > 0 ? SQLITE_OK : SQLITE_ERROR; +} + +SQLITE_API int sqlite3_replay_binlog(sqlite3 *srcDb, sqlite3 *destDb) @@ -367,7 +389,7 @@ index e7e8b3c..3f1195a 100644 /* ** This is the top-level implementation of sqlite3_step(). Call ** sqlite3Step() to do most of the work. If a schema error occurs, -@@ -99189,6 +99464,12 @@ case OP_Found: { /* jump, in3, ncycle */ +@@ -99189,6 +99486,12 @@ case OP_Found: { /* jump, in3, ncycle */ pC->nullRow = 1-alreadyExists; pC->deferredMoveto = 0; pC->cacheStatus = CACHE_STALE; @@ -380,7 +402,7 @@ index e7e8b3c..3f1195a 100644 if( pOp->opcode==OP_Found ){ VdbeBranchTaken(alreadyExists!=0,2); if( alreadyExists ) goto jump_to_p2; -@@ -99584,6 +99865,15 @@ case OP_Insert: { +@@ -99584,6 +99887,15 @@ case OP_Insert: { } x.pKey = 0; assert( BTREE_PREFORMAT==OPFLAG_PREFORMAT ); @@ -396,7 +418,7 @@ index e7e8b3c..3f1195a 100644 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION|OPFLAG_PREFORMAT)), seekResult -@@ -99699,6 +99989,27 @@ case OP_Delete: { +@@ -99699,6 +100011,27 @@ case OP_Delete: { assert( CORRUPT_DB || pC->movetoTarget==iKey ); } #endif @@ -424,7 +446,7 @@ index e7e8b3c..3f1195a 100644 /* If the update-hook or pre-update-hook will be invoked, set zDb to ** the name of the db to pass as to it. Also set local pTab to a copy -@@ -100322,6 +100633,14 @@ case OP_IdxInsert: { /* in2 */ +@@ -100322,6 +100655,14 @@ case OP_IdxInsert: { /* in2 */ x.pKey = pIn2->z; x.aMem = aMem + pOp->p3; x.nMem = (u16)pOp->p4.i; @@ -439,7 +461,7 @@ index e7e8b3c..3f1195a 100644 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION|OPFLAG_PREFORMAT)), ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) -@@ -116953,7 +117272,11 @@ SQLITE_PRIVATE void sqlite3AlterRenameTable( +@@ -116953,7 +117294,11 @@ SQLITE_PRIVATE void sqlite3AlterRenameTable( renameReloadSchema(pParse, iDb, INITFLAG_AlterRename); renameTestSchema(pParse, zDb, iDb==1, "after rename", 0); @@ -452,7 +474,7 @@ index e7e8b3c..3f1195a 100644 exit_rename_table: sqlite3SrcListDelete(db, pSrc); sqlite3DbFree(db, zName); -@@ -117135,6 +117458,9 @@ SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ +@@ -117135,6 +117480,9 @@ SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ zTab, zDb ); } @@ -462,7 +484,7 @@ index e7e8b3c..3f1195a 100644 } } -@@ -117346,7 +117672,13 @@ SQLITE_PRIVATE void sqlite3AlterRenameColumn( +@@ -117346,7 +117694,13 @@ SQLITE_PRIVATE void sqlite3AlterRenameColumn( /* Drop and reload the database schema. */ renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename); renameTestSchema(pParse, zDb, iSchema==1, "after rename", 1); @@ -477,7 +499,7 @@ index e7e8b3c..3f1195a 100644 exit_rename_column: sqlite3SrcListDelete(db, pSrc); sqlite3DbFree(db, zOld); -@@ -118957,7 +119289,13 @@ SQLITE_PRIVATE void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const T +@@ -118957,7 +119311,13 @@ SQLITE_PRIVATE void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const T sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+1); VdbeCoverage(v); sqlite3VdbeJumpHere(v, addr); } @@ -492,7 +514,7 @@ index e7e8b3c..3f1195a 100644 exit_drop_column: sqlite3DbFree(db, zCol); sqlite3SrcListDelete(db, pSrc); -@@ -123295,6 +123633,9 @@ SQLITE_PRIVATE void sqlite3StartTable( +@@ -123295,6 +123655,9 @@ SQLITE_PRIVATE void sqlite3StartTable( sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1); sqlite3VdbeChangeP5(v, OPFLAG_APPEND); sqlite3VdbeAddOp0(v, OP_Close); @@ -502,7 +524,7 @@ index e7e8b3c..3f1195a 100644 } /* Normal (non-error) return. */ -@@ -124963,7 +125304,13 @@ SQLITE_PRIVATE void sqlite3CreateView( +@@ -124963,7 +125326,13 @@ SQLITE_PRIVATE void sqlite3CreateView( /* Use sqlite3EndTable() to add the view to the schema table */ sqlite3EndTable(pParse, 0, &sEnd, 0, 0); @@ -517,7 +539,7 @@ index e7e8b3c..3f1195a 100644 create_view_fail: sqlite3SelectDelete(db, pSelect); if( IN_RENAME_OBJECT ){ -@@ -125486,6 +125833,9 @@ SQLITE_PRIVATE void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, +@@ -125486,6 +125855,9 @@ SQLITE_PRIVATE void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, sqlite3FkDropTable(pParse, pName, pTab); } sqlite3CodeDropTable(pParse, pTab, iDb, isView); @@ -527,7 +549,7 @@ index e7e8b3c..3f1195a 100644 } exit_drop_table: -@@ -126344,6 +126694,9 @@ SQLITE_PRIVATE void sqlite3CreateIndex( +@@ -126344,6 +126716,9 @@ SQLITE_PRIVATE void sqlite3CreateIndex( /* A named index with an explicit CREATE INDEX statement */ zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s", onError==OE_None ? "" : " UNIQUE", n, pName->z); @@ -537,7 +559,7 @@ index e7e8b3c..3f1195a 100644 }else{ /* An automatic index created by a PRIMARY KEY or UNIQUE constraint */ /* zStmt = sqlite3MPrintf(""); */ -@@ -126546,6 +126899,9 @@ SQLITE_PRIVATE void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists +@@ -126546,6 +126921,9 @@ SQLITE_PRIVATE void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists sqlite3ChangeCookie(pParse, iDb); destroyRootPage(pParse, pIndex->tnum, iDb); sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0); @@ -547,7 +569,7 @@ index e7e8b3c..3f1195a 100644 } exit_drop_index: -@@ -127070,6 +127426,9 @@ SQLITE_PRIVATE void sqlite3BeginTransaction(Parse *pParse, int type){ +@@ -127070,6 +127448,9 @@ SQLITE_PRIVATE void sqlite3BeginTransaction(Parse *pParse, int type){ } } sqlite3VdbeAddOp0(v, OP_AutoCommit); @@ -557,7 +579,7 @@ index e7e8b3c..3f1195a 100644 } /* -@@ -127092,6 +127451,9 @@ SQLITE_PRIVATE void sqlite3EndTransaction(Parse *pParse, int eType){ +@@ -127092,6 +127473,9 @@ SQLITE_PRIVATE void sqlite3EndTransaction(Parse *pParse, int eType){ v = sqlite3GetVdbe(pParse); if( v ){ sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, isRollback); @@ -567,7 +589,7 @@ index e7e8b3c..3f1195a 100644 } } -@@ -127112,6 +127474,9 @@ SQLITE_PRIVATE void sqlite3Savepoint(Parse *pParse, int op, Token *pName){ +@@ -127112,6 +127496,9 @@ SQLITE_PRIVATE void sqlite3Savepoint(Parse *pParse, int op, Token *pName){ return; } sqlite3VdbeAddOp4(v, OP_Savepoint, op, 0, 0, zName, P4_DYNAMIC); @@ -577,7 +599,7 @@ index e7e8b3c..3f1195a 100644 } } -@@ -137480,6 +137845,13 @@ typedef int (*sqlite3_loadext_entry)( +@@ -137480,6 +137867,13 @@ typedef int (*sqlite3_loadext_entry)( /* handle after drop table done */ #define sqlite3_set_droptable_handle sqlite3_api->set_droptable_handle #endif /* SQLITE_ENABLE_DROPTABLE_CALLBACK */ @@ -591,7 +613,7 @@ index e7e8b3c..3f1195a 100644 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) -@@ -139533,6 +139905,9 @@ SQLITE_PRIVATE void sqlite3Pragma( +@@ -139533,6 +139927,9 @@ SQLITE_PRIVATE void sqlite3Pragma( if( v==0 ) return; sqlite3VdbeRunOnlyOnce(v); pParse->nMem = 2; @@ -601,7 +623,7 @@ index e7e8b3c..3f1195a 100644 /* Interpret the [schema.] part of the pragma statement. iDb is the ** index of the database this pragma is being applied to in db.aDb[]. */ -@@ -152286,7 +152661,13 @@ SQLITE_PRIVATE void sqlite3BeginTrigger( +@@ -152286,7 +152683,13 @@ SQLITE_PRIVATE void sqlite3BeginTrigger( if (tr_tm == TK_INSTEAD){ tr_tm = TK_BEFORE; } @@ -616,7 +638,7 @@ index e7e8b3c..3f1195a 100644 /* Build the Trigger object */ pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger)); if( pTrigger==0 ) goto trigger_cleanup; -@@ -152681,6 +153062,13 @@ SQLITE_PRIVATE void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr) +@@ -152681,6 +153084,13 @@ SQLITE_PRIVATE void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr) goto drop_trigger_cleanup; } sqlite3DropTriggerPtr(pParse, pTrigger); @@ -630,7 +652,7 @@ index e7e8b3c..3f1195a 100644 drop_trigger_cleanup: sqlite3SrcListDelete(db, pName); -@@ -153427,6 +153815,15 @@ SQLITE_PRIVATE void sqlite3CodeRowTrigger( +@@ -153427,6 +153837,15 @@ SQLITE_PRIVATE void sqlite3CodeRowTrigger( assert( tr_tm==TRIGGER_BEFORE || tr_tm==TRIGGER_AFTER ); assert( (op==TK_UPDATE)==(pChanges!=0) ); @@ -646,7 +668,7 @@ index e7e8b3c..3f1195a 100644 for(p=pTrigger; p; p=p->pNext){ /* Sanity checking: The schema for the trigger and for the table are -@@ -180656,6 +181053,13 @@ SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){ +@@ -180656,6 +181075,13 @@ SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){ break; } #endif /* SQLITE_SHARED_BLOCK_OPTIMIZATION */ @@ -660,7 +682,7 @@ index e7e8b3c..3f1195a 100644 default: { static const struct { int op; /* The opcode */ -@@ -181083,6 +181487,9 @@ SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){ +@@ -181083,6 +181509,9 @@ SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){ sqlite3CollapseDatabaseArray(db); assert( db->nDb<=2 ); assert( db->aDb==db->aDbStatic ); @@ -670,7 +692,7 @@ index e7e8b3c..3f1195a 100644 /* Tell the code in notify.c that the connection no longer holds any ** locks and does not require any further unlock-notify callbacks. -@@ -183308,6 +183715,9 @@ opendb_out: +@@ -183308,6 +183737,9 @@ opendb_out: db->mDropSchemaName = NULL; db->xDropTableHandle = NULL; #endif /* SQLITE_ENABLE_DROPTABLE_CALLBACK */ @@ -680,7 +702,7 @@ index e7e8b3c..3f1195a 100644 *ppDb = db; #ifdef SQLITE_ENABLE_SQLLOG if( sqlite3GlobalConfig.xSqllog ){ -@@ -256913,6 +257323,1074 @@ static void walLogCheckpointInfo(Wal *pWal, sqlite3 *db, sqlite3_int64 startTime +@@ -256913,6 +257345,1074 @@ static void walLogCheckpointInfo(Wal *pWal, sqlite3 *db, sqlite3_int64 startTime } #endif @@ -1755,7 +1777,7 @@ index e7e8b3c..3f1195a 100644 // hw export the symbols #ifdef SQLITE_EXPORT_SYMBOLS #ifndef SQLITE_CKSUMVFS_STATIC -@@ -256942,6 +258420,9 @@ struct sqlite3_api_routines_hw { +@@ -256942,6 +258442,9 @@ struct sqlite3_api_routines_hw { int (*key_v2)(sqlite3*,const char*,const void*,int); int (*rekey)(sqlite3*,const void*,int); int (*rekey_v2)(sqlite3*,const char*,const void*,int); @@ -1765,7 +1787,7 @@ index e7e8b3c..3f1195a 100644 }; typedef struct sqlite3_api_routines_hw sqlite3_api_routines_hw; -@@ -256952,13 +258433,22 @@ static const sqlite3_api_routines_hw sqlite3HwApis = { +@@ -256952,13 +258455,22 @@ static const sqlite3_api_routines_hw sqlite3HwApis = { sqlite3_key, sqlite3_key_v2, sqlite3_rekey,