#include <stdio.h>
/*
-** apKeyVal:
-** If sqlite3_intck_unlock() is called when there is a running pCheck
-** statement, this array is allocated and populated with the key values
-** required to restart the check. If the intck object has not been
-** suspended, this is set to NULL.
-**
** nKeyVal:
-** The size of the apKeyVal[] array, if it is allocated.
+** The number of values that make up the 'key' for the current pCheck
+** statement.
*/
struct sqlite3_intck {
sqlite3 *db;
char *zObj; /* Current object. Or NULL. */
sqlite3_stmt *pCheck; /* Current check statement */
+ char *zKey;
int nKeyVal;
- sqlite3_value **apKeyVal;
char *zMessage;
int bCorruptSchema;
** Free the sqlite3_intck.apKeyVal, if it is allocated and populated.
*/
static void intckSavedKeyClear(sqlite3_intck *p){
- if( p->apKeyVal ){
- int ii;
- for(ii=0; ii<p->nKeyVal; ii++){
- sqlite3_value_free(p->apKeyVal[ii]);
- }
- sqlite3_free(p->apKeyVal);
- p->apKeyVal = 0;
- }
+ sqlite3_free(p->zKey);
+ p->zKey = 0;
}
/*
** occurs within this function, set sqlite3_intck.rc before returning
** and return NULL.
*/
-static char *intckSavedKeyToText(sqlite3_intck *p){
- char *zRet = 0;
- if( p->apKeyVal ){
- int ii;
- const char *zSep = "SELECT '(' || ";
- char *zSql = 0;
- sqlite3_stmt *pStmt = 0;
+static void intckSavedKeySave(sqlite3_intck *p){
+ int ii;
+ const char *zSep = "SELECT '(' || ";
+ char *zSql = 0;
+ sqlite3_stmt *pStmt = 0;
+
+ assert( p->pCheck );
+ assert( p->zKey==0 );
+
+
+ for(ii=0; ii<p->nKeyVal; ii++){
+ zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep);
+ zSep = " || ', ' || ";
+ }
+ zSql = intckMprintf(p, "%z || ')'", zSql);
+ pStmt = intckPrepare(p, "%s", zSql);
+ if( p->rc==SQLITE_OK ){
for(ii=0; ii<p->nKeyVal; ii++){
- zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep);
- zSep = " || ', ' || ";
+ sqlite3_bind_value(pStmt, ii+1, sqlite3_column_value(p->pCheck, ii+1));
}
- zSql = intckMprintf(p, "%z || ')'", zSql);
-
- pStmt = intckPrepare(p, "%s", zSql);
- if( p->rc==SQLITE_OK ){
- for(ii=0; ii<p->nKeyVal; ii++){
- sqlite3_bind_value(pStmt, ii+1, p->apKeyVal[ii]);
- }
- if( SQLITE_ROW==sqlite3_step(pStmt) ){
- zRet = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0));
- }
- intckFinalize(p, pStmt);
+ if( SQLITE_ROW==sqlite3_step(pStmt) ){
+ p->zKey = intckStrdup(p, (const char*)sqlite3_column_text(pStmt, 0));
}
- sqlite3_free(zSql);
+ intckFinalize(p, pStmt);
}
- return zRet;
+ sqlite3_free(zSql);
}
/*
"SELECT table_name FROM tables "
"WHERE ?1 IS NULL OR table_name%s?1 "
"ORDER BY 1"
- , p->zDb, (p->apKeyVal ? ">=" : ">")
+ , p->zDb, (p->zKey ? ">=" : ">")
);
if( p->rc==SQLITE_OK ){
static void intckCheckObject(sqlite3_intck *p){
char *zSql = 0;
- char *zKey = 0;
- zKey = intckSavedKeyToText(p);
- zSql = intckCheckObjectSql(p, p->zObj, zKey, &p->nKeyVal);
+ zSql = intckCheckObjectSql(p, p->zObj, p->zKey, &p->nKeyVal);
p->pCheck = intckPrepare(p, "%s", zSql);
sqlite3_free(zSql);
- sqlite3_free(zKey);
intckSavedKeyClear(p);
}
return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc);
}
-
-static sqlite3_value *intckValueDup(sqlite3_intck *p, sqlite3_value *pIn){
- sqlite3_value *pRet = 0;
- if( p->rc==SQLITE_OK ){
- pRet = sqlite3_value_dup(pIn);
- if( pRet==0 ){
- p->rc = SQLITE_NOMEM;
- }
- }
- return pRet;
-}
-
int sqlite3_intck_unlock(sqlite3_intck *p){
if( p->pCheck && p->rc==SQLITE_OK ){
- const int nByte = sizeof(sqlite3_value*) * p->nKeyVal;
- int ii;
- assert( p->apKeyVal==0 && p->nKeyVal>0 );
- p->apKeyVal = (sqlite3_value**)intckMalloc(p, nByte);
- for(ii=0; p->rc==SQLITE_OK && ii<p->nKeyVal; ii++){
- p->apKeyVal[ii] = intckValueDup(p, sqlite3_column_value(p->pCheck, ii+1));
- }
+ assert( p->zKey==0 && p->nKeyVal>0 );
+ intckSavedKeySave(p);
intckFinalize(p, p->pCheck);
p->pCheck = 0;
}
p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0);
}else{
if( p->zObj ){
- char *zKey = intckSavedKeyToText(p);
- p->zTestSql = intckCheckObjectSql(p, p->zObj, zKey, 0);
- sqlite3_free(zKey);
+ p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0);
}else{
sqlite3_free(p->zTestSql);
p->zTestSql = 0;
-C Add\sdocumentation\sto\sext/intck/sqlite3intck.h.
-D 2024-02-21T19:17:45.632
+C Simplify\sthe\sway\sthe\srestart\skey\sis\ssaved\sinternally\sby\sthe\sintck\sextension.
+D 2024-02-21T19:31:00.293
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F ext/intck/intck2.test b65d7f627342f767e1d2c447d25619666cec36f516786dd56568bd741e5d7e67
F ext/intck/intck_common.tcl b8a63ae820dbcdf50ddaba474f130b43c26ba81f4b7720ff1d8b9a6592bdd420
F ext/intck/intckcorrupt.test 3211ef68ac53e83951b6c8f6a8d2396506d123fe5898f97f848a25837744ec56
-F ext/intck/sqlite3intck.c edc93065be0e16394891bb6ad7d279cb54220db65cc66228ac6d6e0bc3919a63
+F ext/intck/sqlite3intck.c c437aaa1f4af77621ba984718a62c57722ad9d071151be79335fd87f2c2c2dde
F ext/intck/sqlite3intck.h 2b40c38e7063ab822c974c0bd4aed97dabb579ccfe2e180a4639bb3bbef0f1c9
F ext/intck/test_intck.c dec07fc82e2626a1450e58be474e351643627b04ee08ce8fae6495a533b87e85
F ext/jni/GNUmakefile 59eb05f2a363bdfac8d15d66bed624bfe1ff289229184f3861b95f98a19cf4b2
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 11d6816c060b6edb9cd61f29297ab95e75e2b46f29c0a796820d94fc13586f6d
-R f33ba3131334feff25011177f18e259c
+P 4cc19bd74f05fe92658cc392a1d1afa173d93181a77303af6bc5684436ae832e
+R 735ea6d5058bc579028d0f5e808c7418
U dan
-Z fc231a0a5c69f02b295f0b4d4c9d9f6a
+Z b84fa961179c349189e714cd49d2cd34
# Remove this line to create a well-formed Fossil manifest.