os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts2a.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2006 September 9
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#*************************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.  The
sl@0
    12
# focus of this script is testing the FTS2 module.
sl@0
    13
#
sl@0
    14
# $Id: fts2a.test,v 1.2 2007/05/21 21:59:18 shess Exp $
sl@0
    15
#
sl@0
    16
sl@0
    17
set testdir [file dirname $argv0]
sl@0
    18
source $testdir/tester.tcl
sl@0
    19
sl@0
    20
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
sl@0
    21
ifcapable !fts2 {
sl@0
    22
  finish_test
sl@0
    23
  return
sl@0
    24
}
sl@0
    25
sl@0
    26
# Construct a full-text search table containing five keywords:
sl@0
    27
# one, two, three, four, and five, in various combinations.  The
sl@0
    28
# rowid for each will be a bitmask for the elements it contains.
sl@0
    29
#
sl@0
    30
db eval {
sl@0
    31
  CREATE VIRTUAL TABLE t1 USING fts2(content);
sl@0
    32
  INSERT INTO t1(content) VALUES('one');
sl@0
    33
  INSERT INTO t1(content) VALUES('two');
sl@0
    34
  INSERT INTO t1(content) VALUES('one two');
sl@0
    35
  INSERT INTO t1(content) VALUES('three');
sl@0
    36
  INSERT INTO t1(content) VALUES('one three');
sl@0
    37
  INSERT INTO t1(content) VALUES('two three');
sl@0
    38
  INSERT INTO t1(content) VALUES('one two three');
sl@0
    39
  INSERT INTO t1(content) VALUES('four');
sl@0
    40
  INSERT INTO t1(content) VALUES('one four');
sl@0
    41
  INSERT INTO t1(content) VALUES('two four');
sl@0
    42
  INSERT INTO t1(content) VALUES('one two four');
sl@0
    43
  INSERT INTO t1(content) VALUES('three four');
sl@0
    44
  INSERT INTO t1(content) VALUES('one three four');
sl@0
    45
  INSERT INTO t1(content) VALUES('two three four');
sl@0
    46
  INSERT INTO t1(content) VALUES('one two three four');
sl@0
    47
  INSERT INTO t1(content) VALUES('five');
sl@0
    48
  INSERT INTO t1(content) VALUES('one five');
sl@0
    49
  INSERT INTO t1(content) VALUES('two five');
sl@0
    50
  INSERT INTO t1(content) VALUES('one two five');
sl@0
    51
  INSERT INTO t1(content) VALUES('three five');
sl@0
    52
  INSERT INTO t1(content) VALUES('one three five');
sl@0
    53
  INSERT INTO t1(content) VALUES('two three five');
sl@0
    54
  INSERT INTO t1(content) VALUES('one two three five');
sl@0
    55
  INSERT INTO t1(content) VALUES('four five');
sl@0
    56
  INSERT INTO t1(content) VALUES('one four five');
sl@0
    57
  INSERT INTO t1(content) VALUES('two four five');
sl@0
    58
  INSERT INTO t1(content) VALUES('one two four five');
sl@0
    59
  INSERT INTO t1(content) VALUES('three four five');
sl@0
    60
  INSERT INTO t1(content) VALUES('one three four five');
sl@0
    61
  INSERT INTO t1(content) VALUES('two three four five');
sl@0
    62
  INSERT INTO t1(content) VALUES('one two three four five');
sl@0
    63
}
sl@0
    64
sl@0
    65
do_test fts2a-1.1 {
sl@0
    66
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
sl@0
    67
} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
sl@0
    68
do_test fts2a-1.2 {
sl@0
    69
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
sl@0
    70
} {3 7 11 15 19 23 27 31}
sl@0
    71
do_test fts2a-1.3 {
sl@0
    72
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
sl@0
    73
} {3 7 11 15 19 23 27 31}
sl@0
    74
do_test fts2a-1.4 {
sl@0
    75
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
sl@0
    76
} {7 15 23 31}
sl@0
    77
do_test fts2a-1.5 {
sl@0
    78
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
sl@0
    79
} {7 15 23 31}
sl@0
    80
do_test fts2a-1.6 {
sl@0
    81
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
sl@0
    82
} {7 15 23 31}
sl@0
    83
do_test fts2a-1.7 {
sl@0
    84
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
sl@0
    85
} {7 15 23 31}
sl@0
    86
do_test fts2a-1.8 {
sl@0
    87
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
sl@0
    88
} {7 15 23 31}
sl@0
    89
do_test fts2a-1.9 {
sl@0
    90
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
sl@0
    91
} {7 15 23 31}
sl@0
    92
do_test fts2a-1.10 {
sl@0
    93
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
sl@0
    94
} {7 15 23 31}
sl@0
    95
do_test fts2a-1.11 {
sl@0
    96
  execsql {SELECT rowid FROM t1 WHERE content MATCH '  ONE    Two   three  '}
sl@0
    97
} {7 15 23 31}
sl@0
    98
sl@0
    99
do_test fts2a-2.1 {
sl@0
   100
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'}
sl@0
   101
} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
sl@0
   102
do_test fts2a-2.2 {
sl@0
   103
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
sl@0
   104
} {3 7 11 15 19 23 27 31}
sl@0
   105
do_test fts2a-2.3 {
sl@0
   106
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
sl@0
   107
} {}
sl@0
   108
do_test fts2a-2.4 {
sl@0
   109
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
sl@0
   110
} {7 15 23 31}
sl@0
   111
do_test fts2a-2.5 {
sl@0
   112
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
sl@0
   113
} {}
sl@0
   114
do_test fts2a-2.6 {
sl@0
   115
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
sl@0
   116
} {15 31}
sl@0
   117
do_test fts2a-2.7 {
sl@0
   118
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
sl@0
   119
} {}
sl@0
   120
do_test fts2a-2.8 {
sl@0
   121
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
sl@0
   122
} {21}
sl@0
   123
do_test fts2a-2.9 {
sl@0
   124
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
sl@0
   125
} {21 29}
sl@0
   126
do_test fts2a-2.10 {
sl@0
   127
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
sl@0
   128
} {21 29}
sl@0
   129
do_test fts2a-2.11 {
sl@0
   130
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
sl@0
   131
} {29}
sl@0
   132
do_test fts2a-2.12 {
sl@0
   133
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
sl@0
   134
} {29}
sl@0
   135
do_test fts2a-2.13 {
sl@0
   136
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
sl@0
   137
} {29}
sl@0
   138
sl@0
   139
do_test fts2a-3.1 {
sl@0
   140
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
sl@0
   141
} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
sl@0
   142
do_test fts2a-3.2 {
sl@0
   143
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
sl@0
   144
} {1 5 9 13 17 21 25 29}
sl@0
   145
do_test fts2a-3.3 {
sl@0
   146
  execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
sl@0
   147
} {1 5 9 13 17 21 25 29}
sl@0
   148
sl@0
   149
do_test fts2a-4.1 {
sl@0
   150
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
sl@0
   151
} {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
sl@0
   152
do_test fts2a-4.2 {
sl@0
   153
  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
sl@0
   154
} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
sl@0
   155
do_test fts2a-4.3 {
sl@0
   156
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
sl@0
   157
} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
sl@0
   158
do_test fts2a-4.4 {
sl@0
   159
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
sl@0
   160
} {3 5 7 11 13 15 19 21 23 27 29 31}
sl@0
   161
do_test fts2a-4.5 {
sl@0
   162
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
sl@0
   163
} {3 5 7 11 13 15 19 21 23 27 29 31}
sl@0
   164
do_test fts2a-4.6 {
sl@0
   165
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
sl@0
   166
} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
sl@0
   167
do_test fts2a-4.7 {
sl@0
   168
  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
sl@0
   169
} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
sl@0
   170
sl@0
   171
# Test the ability to handle NULL content
sl@0
   172
#
sl@0
   173
do_test fts2a-5.1 {
sl@0
   174
  execsql {INSERT INTO t1(content) VALUES(NULL)}
sl@0
   175
} {}
sl@0
   176
do_test fts2a-5.2 {
sl@0
   177
  set rowid [db last_insert_rowid]
sl@0
   178
  execsql {SELECT content FROM t1 WHERE rowid=$rowid}
sl@0
   179
} {{}}
sl@0
   180
do_test fts2a-5.3 {
sl@0
   181
  execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
sl@0
   182
} {}
sl@0
   183
sl@0
   184
# Test the ability to handle non-positive rowids
sl@0
   185
#
sl@0
   186
do_test fts2a-6.0 {
sl@0
   187
  execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')}
sl@0
   188
} {}
sl@0
   189
do_test fts2a-6.1 {
sl@0
   190
  execsql {SELECT content FROM t1 WHERE rowid = 0}
sl@0
   191
} {{four five}}
sl@0
   192
do_test fts2a-6.2 {
sl@0
   193
  execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')}
sl@0
   194
} {}
sl@0
   195
do_test fts2a-6.3 {
sl@0
   196
  execsql {SELECT content FROM t1 WHERE rowid = -1}
sl@0
   197
} {{three four}}
sl@0
   198
do_test fts2a-6.4 {
sl@0
   199
  execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'}
sl@0
   200
} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31}
sl@0
   201
sl@0
   202
finish_test