modernc.org/cc@v1.0.1/v2/testdata/_sqlite/test/fts3misc.test (about)

     1  # 2017 March 22
     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 fts3misc
    18  
    19  # If SQLITE_ENABLE_FTS3 is defined, omit this file.
    20  ifcapable !fts3 {
    21    finish_test
    22    return
    23  }
    24  
    25  #-------------------------------------------------------------------------
    26  # A self-join.
    27  #
    28  do_execsql_test 1.0 {
    29    CREATE VIRTUAL TABLE t1 USING fts3(a, b);
    30    INSERT INTO t1 VALUES('one', 'i');
    31    INSERT INTO t1 VALUES('one', 'ii');
    32    INSERT INTO t1 VALUES('two', 'i');
    33    INSERT INTO t1 VALUES('two', 'ii');
    34  }
    35  
    36  do_execsql_test 1.1 {
    37    SELECT a.a, b.b FROM t1 a, t1 b WHERE a.t1 MATCH 'two' AND b.t1 MATCH 'i'
    38  } {two i two i two i two i}
    39  
    40  #-------------------------------------------------------------------------
    41  # FTS tables with 128 or more columns.
    42  #
    43  proc v1 {v} {
    44    set vector [list a b c d e f g h]
    45    set res [list]
    46    for {set i 0} {$i<8} {incr i} {
    47      if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
    48    }
    49    set res
    50  }
    51  proc v2 {v} {
    52    set vector [list d e f g h i j k]
    53    set res [list]
    54    for {set i 0} {$i<8} {incr i} {
    55      if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
    56    }
    57    set res
    58  }
    59  db func v1 v1
    60  db func v2 v2
    61  
    62  do_test 2.0 {
    63    set cols [list]
    64    for {set i 0} {$i<200} {incr i} {
    65      lappend cols "c$i"
    66    }
    67    execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])"
    68    execsql {
    69      WITH data(i) AS (
    70        SELECT 1 UNION ALL SELECT i+1 FROM data WHERE i<200
    71      )
    72      INSERT INTO t2(c198, c199) SELECT v1(i), v2(i) FROM data;
    73    }
    74  } {}
    75  do_execsql_test 2.1 {
    76    SELECT rowid FROM t2 WHERE t2 MATCH '"a b c"'
    77  } {
    78    7 15 23 31 39 47 55 63 71 79 87 95 103 111 
    79    119 127 135 143 151 159 167 175 183 191 199
    80  }
    81  do_execsql_test 2.2 {
    82    SELECT rowid FROM t2 WHERE t2 MATCH '"g h i"'
    83  } {
    84    56 57 58 59 60 61 62 63 120 121 122 123 124 
    85    125 126 127 184 185 186 187 188 189 190 191
    86  }
    87  do_execsql_test 2.3 {
    88    SELECT rowid FROM t2 WHERE t2 MATCH '"i h"'
    89  } {
    90  }
    91  do_execsql_test 2.4 {
    92    SELECT rowid FROM t2 WHERE t2 MATCH '"f e"'
    93  } {
    94  }
    95  do_execsql_test 2.5 {
    96    SELECT rowid FROM t2 WHERE t2 MATCH '"e f"'
    97  } {
    98    6 7 14 15 22 23 30 31 38 39 46 47 48 49 50 51 52 53 54 55 56 
    99    57 58 59 60 61 62 63 70 71 78 79 86 87 94 95 102 103 110 
   100    111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
   101    134 135 142 143 150 151 158 159 166 167 174 175 176 177 178 179 180 
   102    181 182 183 184 185 186 187 188 189 190 191 198 199
   103  }
   104  
   105  #-------------------------------------------------------------------------
   106  # Range constraints on the docid using non-integer values.
   107  #
   108  do_execsql_test 2.6 {
   109    SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN NULL AND 45;
   110  } {}
   111  do_execsql_test 2.7 {
   112    SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN 11.5 AND 48.2;
   113  } {
   114    14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
   115    29 30 31 34 35 38 39 42 43 46 47 48
   116  }
   117  do_execsql_test 2.8 {
   118    SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN '11.5' AND '48.2';
   119  } {
   120    14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
   121    29 30 31 34 35 38 39 42 43 46 47 48
   122  }
   123  
   124  #-------------------------------------------------------------------------
   125  # Phrase query tests. 
   126  #
   127  do_execsql_test 3.1.1 {
   128    CREATE VIRTUAL TABLE t3 USING fts3;
   129    INSERT INTO t3 VALUES('a b c');
   130    INSERT INTO t3 VALUES('d e f');
   131    INSERT INTO t3 VALUES('a b d');
   132    INSERT INTO t3 VALUES('1 2 3 4 5 6 7 8 9 10 11');
   133  }
   134  do_execsql_test 3.1.2 {
   135    SELECT * FROM t3 WHERE t3 MATCH '"a b x y"' ORDER BY docid DESC
   136  }
   137  do_execsql_test 3.1.3 {
   138    SELECT * FROM t3 WHERE t3 MATCH '"a b c" OR "a b x y"' ORDER BY docid DESC
   139  } {{a b c}}
   140  do_execsql_test 3.1.4 {
   141    SELECT * FROM t3 WHERE t3 MATCH '"a* b* x* a*"'
   142  }
   143  do_execsql_test 3.1.5 {
   144    SELECT rowid FROM t3 WHERE t3 MATCH '"2 3 4 5 6 7 8 9"'
   145  } {4}
   146  
   147  #-------------------------------------------------------------------------
   148  #
   149  reset_db
   150  ifcapable fts4_deferred {
   151    do_execsql_test 4.0 {
   152      PRAGMA page_size = 512;
   153      CREATE VIRTUAL TABLE t4 USING fts4;
   154      WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<8000 )
   155      INSERT INTO t4 SELECT 'a b c a b c a b c' FROM s;
   156    }
   157    do_execsql_test 4.1 {
   158      SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
   159    } {8000}
   160    do_execsql_test 4.2 {
   161      SELECT quote(value) from t4_stat where id=0
   162    } {X'C03EC0B204C0A608'}
   163    do_execsql_test 4.3 {
   164      UPDATE t4_stat SET value = X'C03EC0B204C0A60800' WHERE id=0;
   165    }
   166    do_catchsql_test 4.4 {
   167      SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
   168    } {1 {database disk image is malformed}}
   169    do_execsql_test 4.5 {
   170      UPDATE t4_stat SET value = X'00C03EC0B204C0A608' WHERE id=0;
   171    }
   172    do_catchsql_test 4.6 {
   173      SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
   174    } {1 {database disk image is malformed}}
   175  }
   176  
   177  #-------------------------------------------------------------------------
   178  #
   179  reset_db
   180  do_execsql_test 5.0 {
   181    CREATE VIRTUAL TABLE t5 USING fts4;
   182    INSERT INTO t5 VALUES('a x x x x b x x x x c');
   183    INSERT INTO t5 VALUES('a x x x x b x x x x c');
   184    INSERT INTO t5 VALUES('a x x x x b x x x x c');
   185  }
   186  do_execsql_test 5.1 {
   187    SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/4 c'
   188  } {1 2 3}
   189  do_execsql_test 5.2 {
   190    SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/3 b NEAR/4 c'
   191  } {}
   192  do_execsql_test 5.3 {
   193    SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/3 c'
   194  } {}
   195  do_execsql_test 5.4 {
   196    SELECT rowid FROM t5 WHERE t5 MATCH 'y NEAR/4 b NEAR/4 c'
   197  } {}
   198  do_execsql_test 5.5 {
   199    SELECT rowid FROM t5 WHERE t5 MATCH 'x OR a NEAR/3 b NEAR/3 c'
   200  } {1 2 3}
   201  do_execsql_test 5.5 {
   202    SELECT rowid FROM t5 WHERE t5 MATCH 'x OR y NEAR/3 b NEAR/3 c'
   203  } {1 2 3}
   204  
   205  #-------------------------------------------------------------------------
   206  #
   207  reset_db
   208  do_execsql_test 6.0 {
   209    CREATE VIRTUAL TABLE t6 USING fts4;
   210  
   211    BEGIN;
   212    WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000)
   213      INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s;
   214  
   215    INSERT INTO t6 VALUES('x x x x x x x x x x x A');
   216    INSERT INTO t6 VALUES('x x x x x x x x x x x B');
   217    INSERT INTO t6 VALUES('x x x x x x x x x x x A');
   218    INSERT INTO t6 VALUES('x x x x x x x x x x x B');
   219  
   220    WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000)
   221      INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s;
   222    COMMIT;
   223  }
   224  do_execsql_test 6.1 {
   225    SELECT rowid FROM t6 WHERE t6 MATCH 'b OR "x a"'
   226  } {50001 50002 50003 50004}
   227  
   228  
   229  finish_test