]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a bug introduced by the fts3 refactoring (segfault when creating a table with...
authordan <dan@noemail.net>
Sat, 28 Nov 2009 12:40:32 +0000 (12:40 +0000)
committerdan <dan@noemail.net>
Sat, 28 Nov 2009 12:40:32 +0000 (12:40 +0000)
FossilOrigin-Name: eada284bc10cafcab9beb3473bb0c70b3b4de2f9

ext/fts3/fts3.c
ext/fts3/fts3_write.c
manifest
manifest.uuid
test/e_fts3.test [new file with mode: 0644]
test/fts3_common.tcl
test/tester.tcl

index 483db5ae076afb6c09361e55739232274636213a..725fe5e0b0a535201003990482aa8a6cc679cc04 100644 (file)
@@ -634,7 +634,7 @@ static int fts3CreateTables(Fts3Table *p){
 **   argv[0]   -> module name
 **   argv[1]   -> database name
 **   argv[2]   -> table name
-**   argv[...] -> "column name" fields...
+**   argv[...] -> "column name" and other module argument fields.
 */
 int fts3InitVtab(
   int isCreate,                   /* True for xCreate, false for xConnect */
@@ -646,10 +646,10 @@ int fts3InitVtab(
   char **pzErr                    /* Write any error message here */
 ){
   Fts3Hash *pHash = (Fts3Hash *)pAux;
-  Fts3Table *p;               /* Pointer to allocated vtab */
+  Fts3Table *p;                   /* Pointer to allocated vtab */
   int rc;                         /* Return code */
-  int i;
-  int nByte;
+  int i;                          /* Iterator variable */
+  int nByte;                      /* Size of allocation used for *p */
   int iCol;
   int nString = 0;
   int nCol = 0;
@@ -681,6 +681,10 @@ int fts3InitVtab(
     assert( pTokenizer );
   }
 
+  if( nCol==0 ){
+    nCol = 1;
+  }
+
   /* Allocate and populate the Fts3Table structure. */
   nByte = sizeof(Fts3Table) +              /* Fts3Table */
           nCol * sizeof(char *) +              /* azColumn */
@@ -726,6 +730,10 @@ int fts3InitVtab(
       assert( zCsr <= &((char *)p)[nByte] );
     }
   }
+  if( iCol==0 ){
+    assert( nCol==1 );
+    p->azColumn[0] = "content";
+  }
 
   /* If this is an xCreate call, create the underlying tables in the 
   ** database. TODO: For xConnect(), it could verify that said tables exist.
index ccb7161182bfb031bbc40635bf8411b3344542c7..3007982c733ed2251308a0a69390ff3de5e1feac 100644 (file)
@@ -409,7 +409,9 @@ static int fts3PendingListAppend(
   if( iCol>=0 ){
     assert( iPos>p->iLastPos || (iPos==0 && p->iLastPos==0) );
     rc = fts3PendingListAppendVarint(&p, 2+iPos-p->iLastPos);
-    p->iLastPos = iPos;
+    if( rc==SQLITE_OK ){
+      p->iLastPos = iPos;
+    }
   }
 
  pendinglistappend_out:
index fc07fd1b44ad35e8eb1b6732760630a6b53e76cd..1aa398398ac91d6ea22920cf1c3d6404161764f7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Change\sthe\stest\snumbers\sin\se_fkey.test\sso\sthat\sthey\sare\sin\sorder.
-D 2009-11-27T18:31:41
+C Fix\sa\sbug\sintroduced\sby\sthe\sfts3\srefactoring\s(segfault\swhen\screating\sa\stable\swith\szero\smodule\sargs).\sAlso\sa\sfix\sto\shandle\san\sOOM\serror.
+D 2009-11-28T12:40:32
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in c5827ead754ab32b9585487177c93bb00b9497b3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -56,7 +56,7 @@ F ext/fts2/mkfts2amal.tcl 974d5d438cb3f7c4a652639262f82418c1e4cff0
 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
 F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9
 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
-F ext/fts3/fts3.c c2776bb39a5cd97d8a96fcfd86f9ad17d3120606
+F ext/fts3/fts3.c 524b080a1a7e9c4ebe7ce49e63f8f22a40a8b795
 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
 F ext/fts3/fts3Int.h 74b21db1c4479c220e803ecf45a78de3b5ac9480
 F ext/fts3/fts3_expr.c bdf11f3602f62f36f0e42823680bf22033dae0de
@@ -68,7 +68,7 @@ F ext/fts3/fts3_snippet.c 082f2906deaaa2656f19b88834e89d099352af6e
 F ext/fts3/fts3_tokenizer.c 36f78d1a43a29b0feaec1ced6da9e56b9c653d1f
 F ext/fts3/fts3_tokenizer.h 7ff73caa3327589bf6550f60d93ebdd1f6a0fb5c
 F ext/fts3/fts3_tokenizer1.c 0a5bcc579f35de5d24a9345d7908dc25ae403ee7
-F ext/fts3/fts3_write.c ac1c03d0df946031062324ce89d8e65cb48031b5
+F ext/fts3/fts3_write.c f1bffadc003b243bb804732c336c9ea55b85de09
 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100
 F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33
 F ext/icu/icu.c 12e763d288d23b5a49de37caa30737b971a2f1e2
@@ -326,6 +326,7 @@ F test/descidx3.test 3394ad4d089335cac743c36a14129d6d931c316f
 F test/diskfull.test 0cede7ef9d8f415d9d3944005c76be7589bb5ebb
 F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
 F test/e_fkey.test f0fbfbcc01b24ad840ed61227b66a05201a7856d
+F test/e_fts3.test 50fcbde25544ee8ab268bfa1e06dda1e570d12d1
 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
 F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
 F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
@@ -376,7 +377,7 @@ F test/fts2q.test b2fbbe038b7a31a52a6079b215e71226d8c6a682
 F test/fts2r.test b154c30b63061d8725e320fba1a39e2201cadd5e
 F test/fts2token.test d8070b241a15ff13592a9ae4a8b7c171af6f445a
 F test/fts3.test f4f380d3717493605270dfa3b0fa893ea0afb18d
-F test/fts3_common.tcl c6493126a3847355c007bb36e0d15e496899aeb5
+F test/fts3_common.tcl b4d857bbc29ea8039cec556e49671168812cca08
 F test/fts3aa.test 5327d4c1d9b6c61021696746cc9a6cdc5bf159c0
 F test/fts3ab.test 09aeaa162aee6513d9ff336b6932211008b9d1f9
 F test/fts3ac.test 356280144a2c92aa7b11474afadfe62a437fcd69
@@ -585,7 +586,7 @@ F test/tclsqlite.test bf4227eb236a4c097aa7974a2bf7d3225acf34be
 F test/tempdb.test 1bf52da28a9c24e29717362a87722dff08feb72b
 F test/temptable.test f42121a0d29a62f00f93274464164177ab1cc24a
 F test/temptrigger.test b0273db072ce5f37cf19140ceb1f0d524bbe9f05
-F test/tester.tcl 2caf7980d7dbb99dab9507ae0646802bc4d12c79
+F test/tester.tcl 02f671e71d1646440d226bed2dde8433f0a7bfa9
 F test/thread001.test a3e6a7254d1cb057836cb3145b60c10bf5b7e60f
 F test/thread002.test afd20095e6e845b405df4f2c920cb93301ca69db
 F test/thread003.test b824d4f52b870ae39fc5bae4d8070eca73085dca
@@ -774,7 +775,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 97d332416069d2fbce323740b276d0e7523eeee5
-R 8971b6fda5645b10b7224031af4ab0a0
+P ca73be44cc2dab5edc48292c467adc8362ddf645
+R 07cb40380182af95ccf713911fe63989
 U dan
-Z 0e0e27ba021e9cea945070788ad7bfa7
+Z d54fff7775225c261880c5e74340ae2b
index 52edfd5668057ac3003ceaf73d2a2f848914a4dd..70e47bbfd2aba8cc628b343d8a4e520893bc1f4e 100644 (file)
@@ -1 +1 @@
-ca73be44cc2dab5edc48292c467adc8362ddf645
\ No newline at end of file
+eada284bc10cafcab9beb3473bb0c70b3b4de2f9
\ No newline at end of file
diff --git a/test/e_fts3.test b/test/e_fts3.test
new file mode 100644 (file)
index 0000000..36cff85
--- /dev/null
@@ -0,0 +1,72 @@
+# 2009 November 28
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file implements tests to verify the "testable statements" in the
+# fts3.in document.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !fts3 {
+  finish_test
+  return
+}
+source $testdir/fts3_common.tcl
+
+set DO_MALLOC_TEST 0
+
+# Procs used to make the tests in this file easier to read.
+#
+proc ddl_test {tn ddl} {
+  uplevel [list do_write_test e_fts3-$tn sqlite_master $ddl]
+}
+proc write_test {tn tbl sql} {
+  uplevel [list do_write_test e_fts3-$tn $tbl $sql]
+}
+proc read_test {tn sql result} {
+  uplevel [list do_select_test e_fts3-$tn $sql $result]
+}
+
+#-----------------------------------------------------------------
+# Test the example CREATE VIRTUAL TABLE statements in section 1.1 
+# of fts3.in.
+#
+ddl_test   1.1.1 {CREATE VIRTUAL TABLE data USING fts3()}
+read_test  1.1.2 {PRAGMA table_info(data)} {0 content {} 0 {} 0}
+
+ddl_test   1.2.1 {
+  CREATE VIRTUAL TABLE pages USING fts3(title, keywords, body)
+}
+read_test  1.2.2 {
+  PRAGMA table_info(pages)
+} {0 title {} 0 {} 0 1 keywords {} 0 {} 0 2 body {} 0 {} 0}
+
+ddl_test   1.3.1 {
+  CREATE VIRTUAL TABLE mail USING fts3(
+      subject VARCHAR(256) NOT NULL,
+      body TEXT CHECK(length(body)<10240)
+  )
+}
+read_test  1.3.2 {
+  PRAGMA table_info(mail)
+} {0 subject {} 0 {} 0 1 body {} 0 {} 0}
+
+# A very large string. Used to test if the constraint on column "body" of
+# table "mail" is enforced (it should not be - FTS3 tables do not support
+# constraints).
+set largetext [string repeat "the quick brown fox " 5000]
+write_test 1.3.3 mail_content { INSERT INTO mail VALUES(NULL, $largetext) }
+read_test  1.3.4 {
+  SELECT subject IS NULL, length(body) FROM mail
+} [list 1 100000]
+
+finish_test
index a12ef4f72ecf7df562c02a137644c9cbb9820c03..c8c73d5c4d81b4b016e56ee54b277badcc1a81ee 100644 (file)
@@ -286,3 +286,125 @@ proc fts3_read {tbl where varname} {
   }
 }
 
+##########################################################################
+
+#-------------------------------------------------------------------------
+# This proc is used to test a single SELECT statement. Parameter $name is
+# passed a name for the test case (i.e. "fts3_malloc-1.4.1") and parameter
+# $sql is passed the text of the SELECT statement. Parameter $result is
+# set to the expected output if the SELECT statement is successfully
+# executed using [db eval].
+#
+# Example:
+#
+#   do_select_test testcase-1.1 "SELECT 1+1, 1+2" {1 2}
+#
+# If global variable DO_MALLOC_TEST is set to a non-zero value, or if
+# it is not defined at all, then OOM testing is performed on the SELECT
+# statement. Each OOM test case is said to pass if either (a) executing
+# the SELECT statement succeeds and the results match those specified
+# by parameter $result, or (b) TCL throws an "out of memory" error.
+#
+# If DO_MALLOC_TEST is defined and set to zero, then the SELECT statement
+# is executed just once. In this case the test case passes if the results
+# match the expected results passed via parameter $result.
+#
+proc do_select_test {name sql result} {
+  doPassiveTest $name $sql [list 0 $result]
+}
+
+proc do_error_test {name sql error} {
+  doPassiveTest $name $sql [list 1 $error]
+}
+
+proc doPassiveTest {name sql catchres} {
+  if {![info exists ::DO_MALLOC_TEST]} { set ::DO_MALLOC_TEST 1 }
+
+  if {$::DO_MALLOC_TEST} {
+    set answers [list {1 {out of memory}} $catchres]
+    set modes [list 100000 transient 1 persistent]
+  } else {
+    set answers [list $catchres]
+    set modes [list 0 nofail]
+  }
+  set str [join $answers " OR "]
+
+  foreach {nRepeat zName} $modes {
+    for {set iFail 1} 1 {incr iFail} {
+      if {$::DO_MALLOC_TEST} {sqlite3_memdebug_fail $iFail -repeat $nRepeat}
+
+      set res [catchsql $sql]
+      if {[lsearch $answers $res]>=0} {
+        set res $str
+      }
+      do_test $name.$zName.$iFail [list set {} $res] $str
+      set nFail [sqlite3_memdebug_fail -1 -benigncnt nBenign]
+      if {$nFail==0} break
+    }
+  }
+}
+
+
+#-------------------------------------------------------------------------
+# Test a single write to the database. In this case a  "write" is a 
+# DELETE, UPDATE or INSERT statement.
+#
+# If OOM testing is performed, there are several acceptable outcomes:
+#
+#   1) The write succeeds. No error is returned.
+#
+#   2) An "out of memory" exception is thrown and:
+#
+#     a) The statement has no effect, OR
+#     b) The current transaction is rolled back, OR
+#     c) The statement succeeds. This can only happen if the connection
+#        is in auto-commit mode (after the statement is executed, so this
+#        includes COMMIT statements).
+#
+# If the write operation eventually succeeds, zero is returned. If a
+# transaction is rolled back, non-zero is returned.
+#
+# Parameter $name is the name to use for the test case (or test cases).
+# The second parameter, $tbl, should be the name of the database table
+# being modified. Parameter $sql contains the SQL statement to test.
+#
+proc do_write_test {name tbl sql} {
+  if {![info exists ::DO_MALLOC_TEST]} { set ::DO_MALLOC_TEST 1 }
+
+  # Figure out an statement to get a checksum for table $tbl.
+  db eval "SELECT * FROM $tbl" V break
+  set cksumsql "SELECT md5sum([join [concat rowid $V(*)] ,]) FROM $tbl"
+
+  # Calculate the initial table checksum.
+  set cksum1 [db one $cksumsql]
+
+
+  if {$::DO_MALLOC_TEST } {
+    set answers [list {1 {out of memory}} {0 {}}]
+    set modes [list 100000 transient 1 persistent]
+  } else {
+    set answers [list {0 {}}]
+    set modes [list 0 nofail]
+  }
+  set str [join $answers " OR "]
+
+  foreach {nRepeat zName} $modes {
+    for {set iFail 1} 1 {incr iFail} {
+      if {$::DO_MALLOC_TEST} {sqlite3_memdebug_fail $iFail -repeat $nRepeat}
+
+      set res [uplevel [list catchsql $sql]]
+      set nFail [sqlite3_memdebug_fail -1 -benigncnt nBenign]
+      if {$nFail==0} {
+        do_test $name.$zName.$iFail [list set {} $res] {0 {}}
+        return
+      } else {
+        if {[lsearch $answers $res]>=0} {
+          set res $str
+        }
+        do_test $name.$zName.$iFail [list set {} $res] $str
+        set cksum2 [db one $cksumsql]
+        if {$cksum1 != $cksum2} return
+      }
+    }
+  }
+}
index 7651017a258ae90aca0c1951a80b8248d857d7b7..73a7c30c9a6b2a75c3de735dda885e844269130e 100644 (file)
@@ -412,7 +412,7 @@ proc execsql {sql {db db}} {
 #
 proc catchsql {sql {db db}} {
   # puts "SQL = $sql"
-  set r [catch {$db eval $sql} msg]
+  set r [catch [list uplevel [list $db eval $sql]] msg]
   lappend r $msg
   return $r
 }