]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Change the fts5 content= option so that it matches fts5 columns with the underlying...
authordan <dan@noemail.net>
Mon, 27 Apr 2015 16:21:49 +0000 (16:21 +0000)
committerdan <dan@noemail.net>
Mon, 27 Apr 2015 16:21:49 +0000 (16:21 +0000)
FossilOrigin-Name: e38e2bb637844dae8ae5d5f3e23d8369e1b91e45

ext/fts5/fts5Int.h
ext/fts5/fts5_config.c
ext/fts5/fts5_index.c
ext/fts5/fts5_storage.c
ext/fts5/test/fts5content.test
ext/fts5/test/fts5fault2.test
ext/fts5/tool/showfts5.tcl [new file with mode: 0644]
manifest
manifest.uuid

index c553fac5b8643b44348c250d8380b1ae59c230f8..2695cd0ff86bf446bdcdd83e53216a162ea41daf 100644 (file)
@@ -85,6 +85,16 @@ typedef struct Fts5Config Fts5Config;
 **   The minimum number of segments that an auto-merge operation should
 **   attempt to merge together. A value of 1 sets the object to use the 
 **   compile time default. Zero disables auto-merge altogether.
+**
+** zContent:
+**
+** zContentRowid:
+**   The value of the content_rowid= option, if one was specified. Or 
+**   the string "rowid" otherwise. This text is not quoted - if it is
+**   used as part of an SQL statement it needs to be quoted appropriately.
+**
+** zContentExprlist:
+**
 */
 struct Fts5Config {
   sqlite3 *db;                    /* Database handle */
@@ -98,6 +108,7 @@ struct Fts5Config {
   int eContent;                   /* An FTS5_CONTENT value */
   char *zContent;                 /* content table */ 
   char *zContentRowid;            /* "content_rowid=" option value */ 
+  char *zContentExprlist;
   Fts5Tokenizer *pTok;
   fts5_tokenizer *pTokApi;
 
index fb840932b701a8cb81dd08e5c3ec60bb7458568a..0c79cdfc039320f9ff292ed0e224573be8bdb407 100644 (file)
@@ -370,7 +370,7 @@ static int fts5ConfigParseSpecial(
       *pzErr = sqlite3_mprintf("multiple content_rowid=... directives");
       rc = SQLITE_ERROR;
     }else{
-      pConfig->zContentRowid = fts5EscapeName(&rc, zArg);
+      pConfig->zContentRowid = fts5Strdup(&rc, zArg);
     }
     return rc;
   }
@@ -469,6 +469,31 @@ static int fts5ConfigParseColumn(
   return rc;
 }
 
+/*
+** Populate the Fts5Config.zContentExprlist string.
+*/
+static int fts5ConfigMakeExprlist(Fts5Config *p){
+  int i;
+  int rc = SQLITE_OK;
+  Fts5Buffer buf = {0, 0, 0};
+  const char *zSep = "";
+
+  sqlite3Fts5BufferAppendPrintf(&rc, &buf, "T.%Q", p->zContentRowid);
+  if( p->eContent!=FTS5_CONTENT_NONE ){
+    for(i=0; i<p->nCol; i++){
+      if( p->eContent==FTS5_CONTENT_EXTERNAL ){
+        sqlite3Fts5BufferAppendPrintf(&rc, &buf, ", T.%Q", p->azCol[i]);
+      }else{
+        sqlite3Fts5BufferAppendPrintf(&rc, &buf, ", T.c%d", i);
+      }
+    }
+  }
+
+  assert( p->zContentExprlist==0 );
+  p->zContentExprlist = (char*)buf.p;
+  return rc;
+}
+
 /*
 ** Arguments nArg/azArg contain the string arguments passed to the xCreate
 ** or xConnect method of the virtual table. This function attempts to 
@@ -571,6 +596,11 @@ int sqlite3Fts5ConfigParse(
     pRet->zContentRowid = fts5Strdup(&rc, "rowid");
   }
 
+  /* Formulate the zContentExprlist text */
+  if( rc==SQLITE_OK ){
+    rc = fts5ConfigMakeExprlist(pRet);
+  }
+
   if( rc!=SQLITE_OK ){
     sqlite3Fts5ConfigFree(pRet);
     *ppOut = 0;
@@ -598,6 +628,7 @@ void sqlite3Fts5ConfigFree(Fts5Config *pConfig){
     sqlite3_free(pConfig->zRankArgs);
     sqlite3_free(pConfig->zContent);
     sqlite3_free(pConfig->zContentRowid);
+    sqlite3_free(pConfig->zContentExprlist);
     sqlite3_free(pConfig);
   }
 }
index 6990225cae6c9a2065ec1582fcbef9c5130ea0ff..a0cc72b567ae9f169caef6838c8e7567c0b2d213 100644 (file)
@@ -4729,7 +4729,7 @@ static void fts5IndexIntegrityCheckSegment(
 ){
   Fts5BtreeIter iter;             /* Used to iterate through b-tree hierarchy */
 
-  if( pSeg->pgnoFirst==0 && pSeg->pgnoLast==0 ) return;
+  if( pSeg->pgnoFirst==0 ) return;
 
   /* Iterate through the b-tree hierarchy.  */
   for(fts5BtreeIterInit(p, iIdx, pSeg, &iter);
@@ -5148,10 +5148,8 @@ static int fts5DecodeDoclist(int *pRc, Fts5Buffer *pBuf, const u8 *a, int n){
   i64 iDocid;
   int iOff = 0;
 
-  if( iOff<n ){
-    iOff += sqlite3GetVarint(&a[iOff], (u64*)&iDocid);
-    sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " rowid=%lld", iDocid);
-  }
+  iOff = sqlite3GetVarint(&a[iOff], (u64*)&iDocid);
+  sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " rowid=%lld", iDocid);
   while( iOff<n ){
     int nPos;
     int bDummy;
index 866e6b75c70ecace96b4267bdd209954f611a583..ff60c0dece05a8042ba7d646b265a2cd151a96a5 100644 (file)
@@ -65,9 +65,9 @@ static int fts5StorageGetStmt(
   assert( eStmt>=0 && eStmt<ArraySize(p->aStmt) );
   if( p->aStmt[eStmt]==0 ){
     const char *azStmt[] = {
-      "SELECT * FROM %s ORDER BY %s ASC",               /* SCAN_ASC */
-      "SELECT * FROM %s ORDER BY %s DESC",              /* SCAN_DESC */
-      "SELECT * FROM %s WHERE %s=?",                    /* LOOKUP  */
+      "SELECT %s FROM %s T ORDER BY T.%Q ASC",          /* SCAN_ASC */
+      "SELECT %s FROM %s T ORDER BY T.%Q DESC",         /* SCAN_DESC */
+      "SELECT %s FROM %s T WHERE    T.%Q=?",            /* LOOKUP  */
 
       "INSERT INTO %Q.'%q_content' VALUES(%s)",         /* INSERT_CONTENT  */
       "REPLACE INTO %Q.'%q_content' VALUES(%s)",        /* REPLACE_CONTENT */
@@ -86,7 +86,9 @@ static int fts5StorageGetStmt(
       case FTS5_STMT_SCAN_ASC:
       case FTS5_STMT_SCAN_DESC:
       case FTS5_STMT_LOOKUP:
-        zSql = sqlite3_mprintf(azStmt[eStmt], pC->zContent, pC->zContentRowid);
+        zSql = sqlite3_mprintf(azStmt[eStmt], 
+            pC->zContentExprlist, pC->zContent, pC->zContentRowid
+        );
         break;
 
       case FTS5_STMT_INSERT_CONTENT: 
index 145fa4b6a9418d6ac63de1b70f3aeb86e5d15bb9..be2b56a76dbd5413bd2307711294f04b93996bef 100644 (file)
@@ -9,6 +9,7 @@
 #
 #***********************************************************************
 #
+# This file contains tests for the content= and content_rowid= options.
 #
 
 source [file join [file dirname [info script]] fts5_common.tcl]
@@ -186,5 +187,35 @@ do_catchsql_test 3.8 {
   INSERT INTO t4(t4) VALUES('delete-all');
 } {1 {'delete-all' may only be used with a contentless or external content fts5 table}}
 
+#-------------------------------------------------------------------------
+# Test an external content table with a more interesting schema.
+#
+do_execsql_test 4.1 {
+  CREATE TABLE x2(a, "key col" PRIMARY KEY, b, c) WITHOUT ROWID;
+  INSERT INTO x2 VALUES('a b',   1, 'c d' , 'e f');
+  INSERT INTO x2 VALUES('x y', -40, 'z z' , 'y x');
+
+  CREATE VIRTUAL TABLE t2 USING fts5(a, c, content=x2, content_rowid='key col');
+  INSERT INTO t2(t2) VALUES('rebuild');
+}
+
+do_execsql_test 4.2 { SELECT rowid FROM t2 } {-40 1}
+do_execsql_test 4.3 { SELECT rowid FROM t2 WHERE t2 MATCH 'c'} {}
+do_execsql_test 4.4 { SELECT rowid FROM t2 WHERE t2 MATCH 'a'} {1}
+do_execsql_test 4.5 { SELECT rowid FROM t2 WHERE t2 MATCH 'x'} {-40}
+
+do_execsql_test 4.6 { INSERT INTO t2(t2) VALUES('integrity-check') } {}
+
+do_execsql_test 4.7 { 
+  DELETE FROM x2 WHERE "key col" = 1;
+  INSERT INTO t2(t2, rowid, a, c) VALUES('delete', 1, 'a b', 'e f');
+  INSERT INTO t2(t2) VALUES('integrity-check');
+}
+
+do_execsql_test 4.8 { SELECT rowid FROM t2 WHERE t2 MATCH 'b'} {}
+do_execsql_test 4.9 { SELECT rowid FROM t2 WHERE t2 MATCH 'y'} {-40}
+
+
 finish_test
 
+
index fe1d205ec8761c6fee71f4607d2038451e8458c2..9bf9b85e2b8bc67f6a5e4646bc957e0ed58375ce 100644 (file)
@@ -98,5 +98,24 @@ do_faultsim_test 3.1 -faults oom-trans* -prep {
   faultsim_test_result {0 {}}
 }
 
+#-------------------------------------------------------------------------
+# OOM within an 'integrity-check' operation.
+#
+reset_db 
+db func rnddoc fts5_rnddoc
+do_execsql_test 4.0 {
+  CREATE VIRTUAL TABLE zzz USING fts5(z);
+  INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32);
+  WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<10)
+  INSERT INTO zzz SELECT rnddoc(10) || ' xccc' FROM ii;
+}
+
+do_faultsim_test 4.1 -faults oom-trans* -prep {
+} -body {
+  execsql { INSERT INTO zzz(zzz) VALUES('integrity-check') }
+} -test {
+  faultsim_test_result {0 {}}
+}
+
 finish_test
 
diff --git a/ext/fts5/tool/showfts5.tcl b/ext/fts5/tool/showfts5.tcl
new file mode 100644 (file)
index 0000000..3ed5680
--- /dev/null
@@ -0,0 +1,31 @@
+
+
+proc usage {} {
+  puts stderr "usage: $::argv0 database table"
+  puts stderr ""
+  exit 1
+}
+
+set o(vtab)       fts5
+set o(tok)        ""
+set o(limit)      0
+set o(automerge)  -1
+set o(crisismerge)  -1
+
+if {[llength $argv]!=2} usage
+
+set database [lindex $argv 0]
+set tbl [lindex $argv 1]
+
+sqlite3 db $database
+
+db eval "SELECT fts5_decode(rowid, block) AS d FROM ${tbl}_data WHERE id=10" {
+  foreach lvl [lrange $d 1 end] {
+    puts $lvl
+  }
+}
+
+
+
+
+
index 3e37056c0331dbbd59aa6b704ee919348d0e9255..7fdbb961907db31a5c1cecce5ccb14da861f72fe 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Further\stests\sfor\sfts5.
-D 2015-04-27T11:31:56.573
+C Change\sthe\sfts5\scontent=\soption\sso\sthat\sit\smatches\sfts5\scolumns\swith\sthe\sunderlying\stable\scolumns\sby\sname,\snot\sby\stheir\sposition\swithin\sthe\sCREATE\sTABLE\sstatement.
+D 2015-04-27T16:21:49.481
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 31b38b9da2e4b36f54a013bd71a5c3f6e45ca78f
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -106,14 +106,14 @@ F ext/fts3/unicode/mkunicode.tcl 159c1194da0bc72f51b3c2eb71022568006dc5ad
 F ext/fts5/extract_api_docs.tcl 55a6d648d516f35d9a1e580ac00de27154e1904a
 F ext/fts5/fts5.c 3383b8a44766c68bda812b68ce74684c6b87787f
 F ext/fts5/fts5.h 24a2cc35b5e76eec57b37ba48c12d9d2cb522b3a
-F ext/fts5/fts5Int.h 7dc902e195e00c5820b85d71c2476500c2cf9027
+F ext/fts5/fts5Int.h d148c951deae924105d77f21f25287b60c57327a
 F ext/fts5/fts5_aux.c fcea18b1a2a3f95a498b52aba2983557d7678a22
 F ext/fts5/fts5_buffer.c 3ba56cc6824c9f7b1e0695159e0a9c636f6b4a23
-F ext/fts5/fts5_config.c 43fcf838d3a3390d1245e3d5e651fa5cc1df575b
+F ext/fts5/fts5_config.c f344ffa24d2add70fd5bde2b73c44846ad7a06bd
 F ext/fts5/fts5_expr.c 05da381ab26031243266069302c6eb4094b2c5dd
 F ext/fts5/fts5_hash.c 3cb5a3d04dd2030eb0ac8d544711dfd37c0e6529
-F ext/fts5/fts5_index.c 5f969f5b6f5e022c9c62973dd6e4e82e1d5f3f30
-F ext/fts5/fts5_storage.c 87f85986a6d07391f4e0ddfa9799dbecc40fa165
+F ext/fts5/fts5_index.c 65d5a75b1ba5f6db9f283f91e71aaa14105dcef7
+F ext/fts5/fts5_storage.c d5c3567b31a0e334ac7d4ac67a2be1c6ae9165cd
 F ext/fts5/fts5_tcl.c 10bf0eb678d34c1bfdcfaf653d2e6dd92afa8b38
 F ext/fts5/fts5_tokenize.c c07f2c2f749282c1dbbf46bde1f6d7095c740b8b
 F ext/fts5/fts5_unicode2.c f74f53316377068812a1fa5a37819e6b8124631d
@@ -134,14 +134,14 @@ F ext/fts5/test/fts5ak.test 7b8c5df96df599293f920b7e5521ebc79f647592
 F ext/fts5/test/fts5al.test 6a5717faaf7f1e0e866360022d284903f3a4eede
 F ext/fts5/test/fts5auxdata.test c69b86092bf1a157172de5f9169731af3403179b
 F ext/fts5/test/fts5bigpl.test b1cfd00561350ab04994ba7dd9d48468e5e0ec3b
-F ext/fts5/test/fts5content.test 8dc302fccdff834d946497e9d862750ea87d4517
+F ext/fts5/test/fts5content.test c4f5b0fe1bc7523bb6706591d05d1194a0aec452
 F ext/fts5/test/fts5corrupt.test 9e8524281aa322c522c1d6e2b347e24e060c2727
 F ext/fts5/test/fts5corrupt2.test 494111fd4f2dab36499cf97718eaba1f7c11e9d0
 F ext/fts5/test/fts5dlidx.test 748a84ceb74a4154725096a26dfa854260b0182f
 F ext/fts5/test/fts5ea.test 04695560a444fcc00c3c4f27783bdcfbf71f030c
 F ext/fts5/test/fts5eb.test 728a1f23f263548f5c29b29dfb851b5f2dbe723e
 F ext/fts5/test/fts5fault1.test ed71717a479bef32d05f02d9c48691011d160d4d
-F ext/fts5/test/fts5fault2.test 37c325cb3e6e27c74c122bb49673b4ae0862df33
+F ext/fts5/test/fts5fault2.test 26c3d70648f691e2cc9391e14bbc11a973656383
 F ext/fts5/test/fts5fault3.test f8935b92976ae645d43205562fdbb0c8511dd049
 F ext/fts5/test/fts5full.test 0924bdca5416a242103239ace79c6f5aa34bab8d
 F ext/fts5/test/fts5merge.test 453a0717881aa7784885217b2040f3f275caff03
@@ -156,6 +156,7 @@ F ext/fts5/test/fts5unicode.test 79b3e34eb29ce4929628aa514a40cb467fdabe4d
 F ext/fts5/test/fts5unicode2.test 64a5267fd6082fcb46439892ebd0cbaa5c38acee
 F ext/fts5/test/fts5unindexed.test f388605341a476b6ab622b4c267cd168f59a5944
 F ext/fts5/tool/loadfts5.tcl 1e126891d14ab85dcdb0fac7755a4cd5ba52e8b8
+F ext/fts5/tool/showfts5.tcl 921f33b30c3189deefd2b2cc81f951638544aaf1
 F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43
 F ext/icu/icu.c d415ccf984defeb9df2c0e1afcfaa2f6dc05eacb
 F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
@@ -1307,7 +1308,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P e5aaa01306597ffd2475dcb83ae889393f68d315
-R 328723993a482062ac5cfa3f373fa969
+P ffeb3ef3cfec3681b72bb28cfa612aa15e07887d
+R 16d25c5b756f9ed2c991a70239bfd1f6
 U dan
-Z dd82cb2122e4379a606aef38aa888497
+Z e5577dade0e18372482b97b5f2daae05
index 02c02a50418bcbe5722d0c1554cc92ab15d64cec..c88421cb6e58745a8a6cd64a257fc26e38b042a6 100644 (file)
@@ -1 +1 @@
-ffeb3ef3cfec3681b72bb28cfa612aa15e07887d
\ No newline at end of file
+e38e2bb637844dae8ae5d5f3e23d8369e1b91e45
\ No newline at end of file