]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a problem in the schemalint code that comes up when a sub-query uses one or more...
authordan <dan@noemail.net>
Wed, 9 Mar 2016 08:07:31 +0000 (08:07 +0000)
committerdan <dan@noemail.net>
Wed, 9 Mar 2016 08:07:31 +0000 (08:07 +0000)
FossilOrigin-Name: fc18cc9293fb0080b7152c16baac49f44e2db7b3

manifest
manifest.uuid
src/shell_indexes.c
src/where.c
test/schemalint.test [deleted file]
test/shell6.test

index 1ea78374dd452e9fdc6622dd7359421efcfc7b1b..7b7e824272855dd62291fd4c608f5dfd3030d95e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\stest\sscript\sshell6.test,\scontaining\stests\sfor\sschemalint.
-D 2016-02-22T19:51:08.971
+C Fix\sa\sproblem\sin\sthe\sschemalint\scode\sthat\scomes\sup\swhen\sa\ssub-query\suses\sone\sor\smore\sof\sthe\ssame\stables\sas\sits\sparent.
+D 2016-03-09T08:07:31.577
 F Makefile.in dac2776c84e0d533b158a9af6e57e05c4a6b19f3
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b0493f10caddb8adf992a4e6f1943141fc7c6816
@@ -350,7 +350,7 @@ F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c
 F src/rowset.c 9fe4b3ad7cc00944386bb600233d8f523de07a6e
 F src/select.c ff80004a9a6ece891a8d9327a88e7b6e2588ee6d
 F src/shell.c 2cde87e03712204231167c4a6c61b0eb5129e105
-F src/shell_indexes.c e10b3c2c4bc9a87f7bff1cf622473717b1a00698
+F src/shell_indexes.c 23c4b7f7bb8e9b0a8b912c389a85922939bb0769
 F src/sqlite.h.in c7db059d3b810b70b83d9ed1436fa813eba22462
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d
@@ -428,7 +428,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c d21b99fd1458159d0b1ecdccc8ee6ada4fdc4c54
 F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c
 F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354
-F src/where.c 0ecce6da62ad521cac83dfa1b60a37936b36b6a1
+F src/where.c 59f267a53d29db13880597011323745b69e14f24
 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a
 F src/wherecode.c 791a784bbf8749d560fdb0b990b607bc4f44a38d
 F src/whereexpr.c de117970b29471177a6901d60ad83a194671dc03
@@ -988,7 +988,6 @@ F test/schema2.test 906408621ea881fdb496d878b1822572a34e32c5
 F test/schema3.test 1bc1008e1f8cb5654b248c55f27249366eb7ed38
 F test/schema4.test e6a66e20cc69f0e306667c08be7fda3d11707dc5
 F test/schema5.test 29699b4421f183c8f0e88bd28ce7d75d13ea653e
-F test/schemalint.test cee9f375637fcc8c6e77d971abe044445c23e024
 F test/securedel.test 21749c32ccc30f1ea9e4b9f33295a6521ec20fa0
 F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5
 F test/select1.test be62204d2bd9a5a8a149e9974cfddce893d8f686
@@ -1025,7 +1024,7 @@ F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862
 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29
 F test/shell4.test ddf0a99044e2245a87fc17423e3aaa1445b3243b
 F test/shell5.test c04e9f9f948305706b88377c464c7f08ce7479f9
-F test/shell6.test dc93ef3f42c5c385e66b97729374fa1c017ea5ed
+F test/shell6.test 4ce53ce53e1206742e003b5ae609b6c2be438df1
 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5
 F test/shrink.test 1b4330b1fd9e818c04726d45cb28db73087535ce
@@ -1431,7 +1430,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 02fbf699c07286f842d9617755f071b0fffc5d40
-R a01d8436d914e04ca0b643f78b3bf6ab
+P 0b73406595c9a077399b0f4c17af3a826cf3612f
+R d77c52a71510d468f62d262501df9c9f
 U dan
-Z 48d2e83e55b4a0cbf023823a82d88ee7
+Z c51c58b805618dc47dc45d8f0cd33733
index a71d648d17ce5230d8654b2b1d424281ebb5215f..e9344a7af68feba1b94f3a8977b3b6dbeffcfebb 100644 (file)
@@ -1 +1 @@
-0b73406595c9a077399b0f4c17af3a826cf3612f
\ No newline at end of file
+fc18cc9293fb0080b7152c16baac49f44e2db7b3
\ No newline at end of file
index 738a035f02f3ff79e92fd9bf2a661186406902de..c5e172cb974c69560df508a85e169030ffc175c0 100644 (file)
@@ -413,7 +413,6 @@ static int idxGetTableInfo(
   return rc;
 }
 
-
 static int idxCreateTables(
   sqlite3 *db,                    /* User database */
   sqlite3 *dbm,                   /* In-memory database to create tables in */
@@ -424,6 +423,22 @@ static int idxCreateTables(
   IdxScan *pIter;
   for(pIter=pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){
     rc = idxGetTableInfo(db, pIter, pzErrmsg);
+
+    /* Test if table has already been created. If so, jump to the next
+    ** iteration of the loop.  */
+    if( rc==SQLITE_OK ){
+      sqlite3_stmt *pSql = 0;
+      rc = idxPrintfPrepareStmt(dbm, &pSql, pzErrmsg, 
+          "SELECT 1 FROM sqlite_master WHERE tbl_name = %Q", pIter->zTable
+      );
+      if( rc==SQLITE_OK ){
+        int bSkip = 0;
+        if( sqlite3_step(pSql)==SQLITE_ROW ) bSkip = 1;
+        rc = sqlite3_finalize(pSql);
+        if( bSkip ) continue;
+      }
+    }
+
     if( rc==SQLITE_OK ){
       int rc2;
       sqlite3_stmt *pSql = 0;
@@ -799,6 +814,7 @@ int idxFindIndexes(
   sqlite3 *dbm = pCtx->dbm;
   sqlite3_stmt *pExplain = 0;
   sqlite3_stmt *pSelect = 0;
+  sqlite3_stmt *pInsert = 0;
   int rc, rc2;
   int bFound = 0;
 
@@ -808,6 +824,11 @@ int idxFindIndexes(
         "SELECT rowid, sql FROM sqlite_master WHERE name = ?"
     );
   }
+  if( rc==SQLITE_OK ){
+    rc = idxPrepareStmt(dbm, &pInsert, pzErr,
+        "INSERT OR IGNORE INTO aux.indexes VALUES(?)"
+    );
+  }
 
   while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
     int i;
@@ -831,8 +852,10 @@ int idxFindIndexes(
           i64 iRowid = sqlite3_column_int64(pSelect, 0);
           const char *zSql = (const char*)sqlite3_column_text(pSelect, 1);
           if( iRowid>=pCtx->iIdxRowid ){
-            xOut(pOutCtx, zSql);
-            bFound = 1;
+            sqlite3_bind_text(pInsert, 1, zSql, -1, SQLITE_STATIC);
+            sqlite3_step(pInsert);
+            rc = sqlite3_reset(pInsert);
+            if( rc ) goto find_indexes_out;
           }
         }
         rc = sqlite3_reset(pSelect);
@@ -843,8 +866,19 @@ int idxFindIndexes(
   rc2 = sqlite3_reset(pExplain);
   if( rc==SQLITE_OK ) rc = rc2;
   if( rc==SQLITE_OK ){
-    if( bFound==0 ) xOut(pOutCtx, "(no new indexes)");
-    xOut(pOutCtx, "");
+    sqlite3_stmt *pLoop = 0;
+    rc = idxPrepareStmt(dbm, &pLoop, pzErr, "SELECT name FROM aux.indexes");
+    if( rc==SQLITE_OK ){
+      while( SQLITE_ROW==sqlite3_step(pLoop) ){
+        bFound = 1;
+        xOut(pOutCtx, sqlite3_column_text(pLoop, 0));
+      }
+      rc = sqlite3_finalize(pLoop);
+    }
+    if( rc==SQLITE_OK ){
+      if( bFound==0 ) xOut(pOutCtx, "(no new indexes)");
+      xOut(pOutCtx, "");
+    }
   }
 
   while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
@@ -868,6 +902,8 @@ int idxFindIndexes(
   if( rc==SQLITE_OK ) rc = rc2;
   rc2 = sqlite3_finalize(pSelect);
   if( rc==SQLITE_OK ) rc = rc2;
+  rc2 = sqlite3_finalize(pInsert);
+  if( rc==SQLITE_OK ) rc = rc2;
 
   return rc;
 }
@@ -911,7 +947,7 @@ int shellIndexesCommand(
   /* Prepare an INSERT statement for writing to aux.depmask */
   if( rc==SQLITE_OK ){
     rc = idxPrepareStmt(dbm, &ctx.pInsertMask, pzErrmsg,
-        "INSERT OR IGNORE INTO depmask SELECT mask | ?1 FROM depmask;"
+        "INSERT OR IGNORE INTO aux.depmask SELECT mask | ?1 FROM aux.depmask;"
     );
   }
 
index 6275fc8d1e754dfaca16ed77dd1d287eafbc74ce..abe1015b95ebd3440f8710eb49d906c58df70c51 100644 (file)
@@ -3990,7 +3990,6 @@ static void whereTraceBuilder(
           for(i=0; i<p->pOrderBy->nExpr; i++){
             Expr *pExpr = p->pOrderBy->a[i].pExpr; 
             CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr);
-            assert( pColl || pParse->rc );
             pExpr = sqlite3ExprSkipCollate(pExpr);
             if( pExpr->op==TK_COLUMN && pExpr->iTable==pItem->iCursor ){
               int iCol = pExpr->iColumn;
diff --git a/test/schemalint.test b/test/schemalint.test
deleted file mode 100644 (file)
index 7e0eba4..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-
-
-set testdir [file dirname $argv0]
-source $testdir/tester.tcl
-set testprefix schemalint
-
-proc xTrace {zMsg} {
-  lappend ::trace_out $zMsg
-}
-db trace xTrace
-
-proc do_trace_test {tn sql res} {
-  uplevel [list do_test $tn [subst -nocommands {
-    set ::trace_out [list]
-    set stmt [sqlite3_prepare db "$sql" -1 x]
-    sqlite3_finalize [set stmt]
-    set ::trace_out
-  }] [list {*}$res]]
-}
-
-
-do_execsql_test 1.0 {
-  CREATE TABLE t1(a, b, c);
-  CREATE TABLE t2(x, y, z);
-}
-
-do_trace_test 1.1 {
-  SELECT b, c, y, z FROM t1, t2 WHERE c=? AND z=?
-} {
-  {"t1" {cols "b" "c"} {eq "c" "BINARY" 0}}
-  {"t2" {cols "y" "z"} {eq "z" "BINARY" 0}}
-}
-
-do_trace_test 1.2 {
-  SELECT a FROM t1 WHERE b>10
-} {
-  {"t1" {cols "a" "b"} {range "b" "BINARY" 0}}
-}
-
-do_trace_test 1.3 {
-  SELECT b FROM t1 WHERE b IN (10, 20, 30)
-} {
-  {"t1" {cols "b"} {eq "b" "BINARY" 0}}
-}
-
-do_trace_test 1.4 {
-  SELECT * FROM t1, t2 WHERE x=a
-} {
-  {"t1" {cols "a" "b" "c"} {eq "a" "BINARY" 2}} 
-  {"t2" {cols "x" "y" "z"} {eq "x" "BINARY" 1}}
-}
-
-do_trace_test 1.5 {
-  SELECT * FROM t1 WHERE a IN (1, 2, 3)
-} {
-  {"t1" {cols "a" "b" "c"} {eq "a" "BINARY" 0}}
-}
-
-#-----------------------------------------------------------------------
-# Cases involving OR clauses in the WHERE clause.
-#
-do_trace_test 2.1 {
-  SELECT * FROM t1 WHERE a=? OR b=?
-} {
-  {"t1" {cols "a" "b" "c"} {or {{eq "a" "BINARY" 0}} {{eq "b" "BINARY" 0}}}}
-}
-
-do_trace_test 2.2 {
-  SELECT * FROM t1 WHERE a=? OR (b=? AND c=?)
-} {
-  {"t1" {cols "a" "b" "c"} {or {{eq "a" "BINARY" 0}} {{eq "b" "BINARY" 0} {eq "c" "BINARY" 0}}}}
-}
-
-do_trace_test 2.3 {
-  SELECT * FROM t1 WHERE (a=? AND b=?) OR c=?
-} {
-  {"t1" {cols "a" "b" "c"} {or {{eq "c" "BINARY" 0}} {{eq "a" "BINARY" 0} {eq "b" "BINARY" 0}}}}
-}
-
-#-----------------------------------------------------------------------
-# Cases involving ORDER BY.
-#
-do_trace_test 3.1 {
-  SELECT * FROM t1 ORDER BY a;
-} {{"t1" {cols "a" "b" "c"} {orderby "a" "BINARY" ASC}}}
-
-do_trace_test 3.2 {
-  SELECT * FROM t1 WHERE a=? ORDER BY b;
-} {{"t1" {cols "a" "b" "c"} {eq "a" "BINARY" 0} {orderby "b" "BINARY" ASC}}}
-
-do_trace_test 3.3 {
-  SELECT min(a) FROM t1;
-} {{"t1" {cols "a"} {orderby "a" "BINARY" ASC}}}
-
-do_trace_test 3.4 {
-  SELECT max(a) FROM t1;
-} {{"t1" {cols "a"} {orderby "a" "BINARY" DESC}}}
-
-finish_test
-
index 2b200a27571ad44a07e605387cae036724a30ce8..ce8c24ceba79e8b86d24789e4c35d85e602f558c 100644 (file)
@@ -182,8 +182,8 @@ do_setup_rec_test 10.1 {
 } {
   SELECT * FROM t5, t6 WHERE a=? AND b=c AND c=?
 } {
-  CREATE INDEX t6_idx_00000063 ON t6(c) 
   CREATE INDEX t5_idx_000123a7 ON t5(a, b) 
+  CREATE INDEX t6_idx_00000063 ON t6(c) 
   0|0|1|SEARCH TABLE t6 USING INDEX t6_idx_00000063 (c=?) 
   0|1|0|SEARCH TABLE t5 USING COVERING INDEX t5_idx_000123a7 (a=? AND b=?)
 }