File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sqlite3 / test / fts3conf.test
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 17:04:16 2012 UTC (12 years, 10 months ago) by misho
Branches: sqlite3, MAIN
CVS tags: v3_7_10, HEAD
sqlite3

    1: # 2011 April 25
    2: #
    3: # The author disclaims copyright to this source code.  In place of
    4: # a legal notice, here is a blessing:
    5: #
    6: #    May you do good and not evil.
    7: #    May you find forgiveness for yourself and forgive others.
    8: #    May you share freely, never taking more than you give.
    9: #
   10: #*************************************************************************
   11: # This file implements regression tests for SQLite library.  The
   12: # focus of this script is testing the FTS3 module.
   13: 
   14: 
   15: set testdir [file dirname $argv0]
   16: source $testdir/tester.tcl
   17: set testprefix fts3conf
   18: 
   19: # If SQLITE_ENABLE_FTS3 is defined, omit this file.
   20: ifcapable !fts3 {
   21:   finish_test
   22:   return
   23: }
   24: 
   25: 
   26: proc fts3_integrity {tn db tbl} {
   27: 
   28:   if {[sqlite3_get_autocommit $db]==0} {
   29:     error "fts3_integrity does not work with an open transaction"
   30:   }
   31: 
   32:   set sql [db one {SELECT sql FROM sqlite_master WHERE name = $tbl}]
   33:   regexp -nocase {[^(]* using (.*)} $sql -> tail
   34:   set cols [list]
   35:   $db eval "PRAGMA table_info($tbl)" {
   36:     lappend cols $name
   37:   }
   38:   set cols [join [concat docid $cols] ,]
   39: 
   40:   $db eval [subst {
   41:     CREATE VIRTUAL TABLE fts3check USING fts4term($tbl);
   42:     CREATE VIRTUAL TABLE temp.fts3check2 USING $tail;
   43:     INSERT INTO temp.fts3check2($cols) SELECT docid, * FROM $tbl;
   44:     CREATE VIRTUAL TABLE temp.fts3check3 USING fts4term(fts3check2);
   45:   }]
   46: 
   47:   set m1 [$db one {SELECT md5sum(term, docid, col, pos) FROM fts3check}]
   48:   set m2 [$db one {SELECT md5sum(term, docid, col, pos) FROM fts3check3}]
   49: 
   50:   $db eval {
   51:     DROP TABLE fts3check;
   52:     DROP TABLE temp.fts3check2;
   53:     DROP TABLE temp.fts3check3;
   54:   }
   55:   
   56:   uplevel [list do_test $tn [list set {} $m1] $m2]
   57: }
   58: 
   59: do_execsql_test 1.0.1 {
   60:   CREATE VIRTUAL TABLE t1 USING fts3(x);
   61:   INSERT INTO t1(rowid, x) VALUES(1, 'a b c d');
   62:   INSERT INTO t1(rowid, x) VALUES(2, 'e f g h');
   63: 
   64:   CREATE TABLE source(a, b);
   65:   INSERT INTO source VALUES(4, 'z');
   66:   INSERT INTO source VALUES(2, 'y');
   67: }
   68: db_save_and_close
   69: 
   70: set T1 "INTO t1(rowid, x) VALUES(1, 'x')"
   71: set T2 "INTO t1(rowid, x) SELECT * FROM source"
   72: 
   73: set T3 "t1 SET docid = 2 WHERE docid = 1"
   74: set T4 "t1 SET docid = CASE WHEN docid = 1 THEN 4 ELSE 3 END WHERE docid <=2"
   75: 
   76: foreach {tn sql uses constraint data} [subst {
   77:   1    "INSERT OR ROLLBACK $T1"   0 1 {{a b c d} {e f g h}}
   78:   2    "INSERT OR ABORT    $T1"   0 1 {{a b c d} {e f g h} {i j k l}}
   79:   3    "INSERT OR FAIL     $T1"   0 1 {{a b c d} {e f g h} {i j k l}}
   80:   4    "INSERT OR IGNORE   $T1"   0 0 {{a b c d} {e f g h} {i j k l}}
   81:   5    "INSERT OR REPLACE  $T1"   0 0 {x {e f g h} {i j k l}}
   82: 
   83:   6    "INSERT OR ROLLBACK $T2"   1 1 {{a b c d} {e f g h}}
   84:   7    "INSERT OR ABORT    $T2"   1 1 {{a b c d} {e f g h} {i j k l}}
   85:   8    "INSERT OR FAIL     $T2"   1 1 {{a b c d} {e f g h} {i j k l} z}
   86:   9    "INSERT OR IGNORE   $T2"   1 0 {{a b c d} {e f g h} {i j k l} z}
   87:   10   "INSERT OR REPLACE  $T2"   1 0 {{a b c d} y {i j k l} z}
   88: 
   89:   11   "UPDATE OR ROLLBACK $T3"   1 1 {{a b c d} {e f g h}}
   90:   12   "UPDATE OR ABORT    $T3"   1 1 {{a b c d} {e f g h} {i j k l}}
   91:   13   "UPDATE OR FAIL     $T3"   1 1 {{a b c d} {e f g h} {i j k l}}
   92:   14   "UPDATE OR IGNORE   $T3"   1 0 {{a b c d} {e f g h} {i j k l}}
   93:   15   "UPDATE OR REPLACE  $T3"   1 0 {{a b c d} {i j k l}}
   94: 
   95:   16   "UPDATE OR ROLLBACK $T4"   1 1 {{a b c d} {e f g h}}
   96:   17   "UPDATE OR ABORT    $T4"   1 1 {{a b c d} {e f g h} {i j k l}}
   97:   18   "UPDATE OR FAIL     $T4"   1 1 {{e f g h} {i j k l} {a b c d}}
   98:   19   "UPDATE OR IGNORE   $T4"   1 0 {{e f g h} {i j k l} {a b c d}}
   99:   20   "UPDATE OR REPLACE  $T4"   1 0 {{e f g h} {a b c d}}
  100: }] {
  101:   db_restore_and_reopen
  102:   execsql { 
  103:     BEGIN;
  104:       INSERT INTO t1(rowid, x) VALUES(3, 'i j k l');
  105:   }
  106:   set R(0) {0 {}}
  107:   set R(1) {1 {constraint failed}}
  108:   do_catchsql_test 1.$tn.1 $sql $R($constraint)
  109:   do_catchsql_test 1.$tn.2 { SELECT * FROM t1 } [list 0 $data]
  110:   catchsql COMMIT
  111: 
  112:   fts3_integrity 1.$tn.3 db t1
  113: 
  114:   do_test 1.$tn.4 [list sql_uses_stmt db $sql] $uses
  115: }
  116: 
  117: do_execsql_test 2.1.1 {
  118:   DELETE FROM t1;
  119:   BEGIN;
  120:     INSERT INTO t1 VALUES('a b c');
  121:     SAVEPOINT a;
  122:       INSERT INTO t1 VALUES('x y z');
  123:     ROLLBACK TO a;
  124:   COMMIT;
  125: }
  126: fts3_integrity 2.1.2 db t1
  127: 
  128: do_catchsql_test 2.2.1 {
  129:   DELETE FROM t1;
  130:   BEGIN;
  131:     INSERT INTO t1(docid, x) VALUES(0, 'a b c');
  132:     INSERT INTO t1(docid, x) VALUES(1, 'a b c');
  133:     REPLACE INTO t1(docid, x) VALUES('zero', 'd e f');
  134: } {1 {datatype mismatch}}
  135: do_execsql_test 2.2.2 { COMMIT }
  136: do_execsql_test 2.2.3 { SELECT * FROM t1 } {{a b c} {a b c}}
  137: fts3_integrity 2.2.4 db t1
  138: 
  139: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>