]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplify the way the restart key is saved internally by the intck extension.
authordan <Dan Kennedy>
Wed, 21 Feb 2024 19:31:00 +0000 (19:31 +0000)
committerdan <Dan Kennedy>
Wed, 21 Feb 2024 19:31:00 +0000 (19:31 +0000)
FossilOrigin-Name: 0e39962baae8a82a3021077676b792ac30c79426bcd8c075b5e92bee55e8c3a5

ext/intck/sqlite3intck.c
manifest
manifest.uuid

index d00b5ef529900118f729f183fc649a9566476cd8..24bceb27d0ee2bc3b3118816d7634f95b44c5b82 100644 (file)
 #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;
@@ -32,8 +27,8 @@ struct sqlite3_intck {
   char *zObj;                     /* Current object. Or NULL. */
 
   sqlite3_stmt *pCheck;           /* Current check statement */
+  char *zKey;
   int nKeyVal;
-  sqlite3_value **apKeyVal;
 
   char *zMessage;
   int bCorruptSchema;
@@ -161,14 +156,8 @@ static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){
 ** 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;
 }
 
 /*
@@ -182,33 +171,33 @@ static void intckSavedKeyClear(sqlite3_intck *p){
 ** 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);
 }
 
 /*
@@ -234,7 +223,7 @@ static void intckFindObject(sqlite3_intck *p){
     "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 ){
@@ -733,12 +722,9 @@ static char *intckCheckObjectSql(
 
 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);
 }
 
@@ -849,27 +835,10 @@ int sqlite3_intck_error(sqlite3_intck *p, const char **pzErr){
   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;
   }
@@ -882,9 +851,7 @@ const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){
     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;
index 32648946aa75d430f59a18ccc88555144c0e1d1c..172f8e84358ec21351f971a6660bd500500f5afb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-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
@@ -252,7 +252,7 @@ F ext/intck/intck1.test 15e94ee868e939c6d3aef6884c5652d969b28d3eac940a15585511cf
 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
@@ -2169,8 +2169,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 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.
index 12f0b62ab84b46c467838b659252600d090aa492..4d5fa2bca4d24dc86ecc9723383aa3f5398db230 100644 (file)
@@ -1 +1 @@
-4cc19bd74f05fe92658cc392a1d1afa173d93181a77303af6bc5684436ae832e
\ No newline at end of file
+0e39962baae8a82a3021077676b792ac30c79426bcd8c075b5e92bee55e8c3a5
\ No newline at end of file