/ Check-in [8dc261b7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add tests (and a fix) for large and small fts docid values with various languageid_bits settings.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts-languageid-bits
Files: files | file ages | folders
SHA1: 8dc261b765e580b100a3a9616ac540eedad345d5
User & Date: dan 2013-06-20 11:48:02
Context
2013-06-20
16:22
Add extra tests for fts with a non-zero languageid_bits setting. Fix querying by docid with the same. check-in: b1df00f3 user: dan tags: fts-languageid-bits
11:48
Add tests (and a fix) for large and small fts docid values with various languageid_bits settings. check-in: 8dc261b7 user: dan tags: fts-languageid-bits
11:01
Fix fts handling of the case where both a rowid and docid are specified as part of an insert statement. check-in: 610e7e96 user: dan tags: fts-languageid-bits
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
  p->bAutoincrmerge = 0xff;   /* 0xff means setting unknown */
  p->zContentTbl = zContent;
  p->zLanguageid = zLanguageid;
  zContent = 0;
  zLanguageid = 0;
  if( zLanguageidBits && p->zLanguageid && p->zContentTbl==0 ){
    p->nLanguageidBits = atoi(zLanguageidBits);
    if( p->nLanguageidBits>32 || p->nLanguageidBits<0 ){
      rc = SQLITE_ERROR;
      *pzErr = sqlite3_mprintf("languageid_bits parameter out of range");
      goto fts3_init_out;
    }
  }

  TESTONLY( p->inTransaction = -1 );







|







1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
  p->bAutoincrmerge = 0xff;   /* 0xff means setting unknown */
  p->zContentTbl = zContent;
  p->zLanguageid = zLanguageid;
  zContent = 0;
  zLanguageid = 0;
  if( zLanguageidBits && p->zLanguageid && p->zContentTbl==0 ){
    p->nLanguageidBits = atoi(zLanguageidBits);
    if( p->nLanguageidBits>30 || p->nLanguageidBits<0 ){
      rc = SQLITE_ERROR;
      *pzErr = sqlite3_mprintf("languageid_bits parameter out of range");
      goto fts3_init_out;
    }
  }

  TESTONLY( p->inTransaction = -1 );

Changes to ext/fts3/fts3_write.c.

5327
5328
5329
5330
5331
5332
5333
5334

5335

5336
5337
5338

5339
5340
5341
5342
5343
5344
5345
  ** value. If the languageid_bits option was specified when this table 
  ** was created, it must also be less than (2 ^ nLanguageidBits).  
  **
  ** Also check that if a non-zero languageid_bits value was configured,
  ** the specified rowid value must be NULL.
  */
  if( nArg>1 ){
    iLangid = sqlite3_value_int(apVal[2 + p->nColumn + 2]);

    if( iLangid<0 || (p->nLanguageidBits && iLangid>=(1<<p->nLanguageidBits)) ){

      rc = SQLITE_CONSTRAINT;
      goto update_out;
    }


    if( p->nLanguageidBits 
     && sqlite3_value_type(apVal[0])==SQLITE_NULL
     && sqlite3_value_type(apVal[1])!=SQLITE_NULL
    ){
      rc = SQLITE_CONSTRAINT;
      goto update_out;







|
>
|
>



>







5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
  ** value. If the languageid_bits option was specified when this table 
  ** was created, it must also be less than (2 ^ nLanguageidBits).  
  **
  ** Also check that if a non-zero languageid_bits value was configured,
  ** the specified rowid value must be NULL.
  */
  if( nArg>1 ){
    i64 iLangid64 = sqlite3_value_int64(apVal[2 + p->nColumn + 2]);
    if( iLangid64<0 
     || (p->nLanguageidBits && iLangid64>=((i64)1<<p->nLanguageidBits)) 
    ){
      rc = SQLITE_CONSTRAINT;
      goto update_out;
    }
    iLangid = (int)iLangid64;

    if( p->nLanguageidBits 
     && sqlite3_value_type(apVal[0])==SQLITE_NULL
     && sqlite3_value_type(apVal[1])!=SQLITE_NULL
    ){
      rc = SQLITE_CONSTRAINT;
      goto update_out;

Changes to test/fts4langid2.test.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
..
97
98
99
100
101
102
103

104
105
106
107
108
109
110
...
124
125
126
127
128
129
130


131

































































132
133
}


#-------------------------------------------------------------------------
# Test out-of-range values for the languageid_bits= parameter.
#
do_catchsql_test 1.1 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=33);
} {1 {languageid_bits parameter out of range}}

do_catchsql_test 1.2 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=-1);
} {1 {languageid_bits parameter out of range}}

do_catchsql_test 1.3 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=0);
  CREATE VIRTUAL TABLE t2 USING fts4(languageid=lid, languageid_bits=32);
} {0 {}}

do_execsql_test 1.4 {
  DROP TABLE t1;
  DROP TABLE t2;
}

................................................................................

do_execsql_test 3.4 {
  DROP TABLE t1;
  DROP TABLE t2;
}

#-------------------------------------------------------------------------

#
do_execsql_test 4.1 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=5);
}

do_execsql_test 4.2 {
  INSERT INTO t1 (docid, lid, content) VALUES(1, 0, '1 2 3');
................................................................................
} {1 1 {1 2 3 4}}

do_execsql_test 4.6 {
  UPDATE t1 SET content = 'x y z' || lid;
  SELECT docid, lid FROM t1;
} {1 0 1 1}





































































finish_test








|








|







 







>







 







>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
}


#-------------------------------------------------------------------------
# Test out-of-range values for the languageid_bits= parameter.
#
do_catchsql_test 1.1 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=31);
} {1 {languageid_bits parameter out of range}}

do_catchsql_test 1.2 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=-1);
} {1 {languageid_bits parameter out of range}}

do_catchsql_test 1.3 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=0);
  CREATE VIRTUAL TABLE t2 USING fts4(languageid=lid, languageid_bits=30);
} {0 {}}

do_execsql_test 1.4 {
  DROP TABLE t1;
  DROP TABLE t2;
}

................................................................................

do_execsql_test 3.4 {
  DROP TABLE t1;
  DROP TABLE t2;
}

#-------------------------------------------------------------------------
# Simple tests inserting data with multiple languageid values.
#
do_execsql_test 4.1 {
  CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=5);
}

do_execsql_test 4.2 {
  INSERT INTO t1 (docid, lid, content) VALUES(1, 0, '1 2 3');
................................................................................
} {1 1 {1 2 3 4}}

do_execsql_test 4.6 {
  UPDATE t1 SET content = 'x y z' || lid;
  SELECT docid, lid FROM t1;
} {1 0 1 1}

do_execsql_test 3.4 {
  DROP TABLE t1;
}

#-------------------------------------------------------------------------
# Tests for docid range boundary conditions. 
#
for {set bits 1} {$bits <= 30} {incr bits} {
  do_execsql_test 5.$bits.1 "
    CREATE VIRTUAL TABLE t1 USING fts4(languageid=lid, languageid_bits=$bits);
  "

  set max_docid [expr int(1<<(63-$bits))-1]
  set min_docid [expr -1*int(1<<(63-$bits))]
  set max_langid [expr (1<<$bits)-1]
  set min_langid 0


  do_catchsql_test 5.$bits.2.1 {
    INSERT INTO t1(docid, lid, content) VALUES($max_docid+1, 4, '');
  } {1 {constraint failed}}
  do_catchsql_test 5.$bits.2.2 {
    INSERT INTO t1(docid, lid, content) VALUES($min_docid-1, 4, '');
  } {1 {constraint failed}}

  do_test 5.$bits.3 {
    foreach {a b c} "
      $min_docid  $min_langid  {1 min min x}
      $min_docid  $max_langid  {2 min max x}
      $max_docid  $min_langid  {3 max min x}
      $max_docid  $max_langid  {4 max max x}
    " {
      execsql { INSERT INTO t1(docid, lid, content) VALUES($a, $b, $c) }
    }
  } {}

  do_execsql_test 5.$bits.4.1 {
    SELECT docid, lid, content FROM t1 ORDER BY content
  } "
      $min_docid  $min_langid  {1 min min x}
      $min_docid  $max_langid  {2 min max x}
      $max_docid  $min_langid  {3 max min x}
      $max_docid  $max_langid  {4 max max x}
  "

  do_execsql_test 5.$bits.4.2 {
    SELECT docid, lid, content FROM t1 WHERE lid=$min_langid AND t1 MATCH 'x'
  } "
      $min_docid  $min_langid  {1 min min x}
      $max_docid  $min_langid  {3 max min x}
  "

  do_execsql_test 5.$bits.4.3 {
    SELECT docid, lid, content FROM t1 WHERE lid=$max_langid AND t1 MATCH 'x'
  } "
      $min_docid  $max_langid  {2 min max x}
      $max_docid  $max_langid  {4 max max x}
  "

  do_execsql_test 5.$bits.4.4 {
    SELECT docid, lid, content FROM t1 WHERE t1 MATCH '1'
  } "
      $min_docid  $min_langid  {1 min min x}
  "

  do_execsql_test 5.$bits.5 { DROP TABLE t1 }
}

finish_test