/ Check-in [065ab83a6c]
Login

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

Overview
Comment:Increase test coverage of fts5_vocab.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts5
Files: files | file ages | folders
SHA1: 065ab83a6ce36e16d3b95a61505aa3cff0bfea84
User & Date: dan 2015-05-22 07:44:44
Context
2015-05-23
15:43
Avoid making redundant copies of position-lists within the fts5 code. check-in: 5165de548b user: dan tags: fts5
2015-05-22
07:44
Increase test coverage of fts5_vocab.c. check-in: 065ab83a6c user: dan tags: fts5
06:08
Improve test coverage of fts5_unicode2.c. check-in: fea8a4db9d user: dan tags: fts5
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_vocab.c.

256
257
258
259
260
261
262


263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  );
  if( zSql==0 ){
    rc = SQLITE_NOMEM;
  }else{
    rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
  }
  sqlite3_free(zSql);



  if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
    i64 iId = sqlite3_column_int64(pStmt, 0);
    pIndex = sqlite3Fts5IndexFromCsrid(pTab->pGlobal, iId, &nCol);
  }

  if( rc==SQLITE_OK && pIndex==0 ){
    rc = sqlite3_finalize(pStmt);
    pStmt = 0;
    if( rc==SQLITE_OK ){
      pVTab->zErrMsg = sqlite3_mprintf(
          "no such fts5 table: %Q.%Q", pTab->zFts5Db, pTab->zFts5Tbl
          );
      rc = SQLITE_ERROR;
    }
  }

  nByte = nCol * sizeof(i64) * 2 + sizeof(Fts5VocabCursor);
  pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte);
  if( pCsr ){
................................................................................
}

/*
** Close the cursor.  For additional information see the documentation
** on the xClose method of the virtual table interface.
*/
static int fts5VocabCloseMethod(sqlite3_vtab_cursor *pCursor){
  if( pCursor ){
    Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
    fts5VocabResetCursor(pCsr);
    sqlite3Fts5BufferFree(&pCsr->term);
    sqlite3_finalize(pCsr->pStmt);
    sqlite3_free(pCsr);
  }
  return SQLITE_OK;
}


/*
** Advance the cursor to the next row in the table.
*/







>
>

|









|
|







 







<
|
|
|
|
|
<







256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
...
302
303
304
305
306
307
308

309
310
311
312
313

314
315
316
317
318
319
320
  );
  if( zSql==0 ){
    rc = SQLITE_NOMEM;
  }else{
    rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
  }
  sqlite3_free(zSql);
  assert( rc==SQLITE_OK || pStmt==0 );
  if( rc==SQLITE_ERROR ) rc = SQLITE_OK;

  if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
    i64 iId = sqlite3_column_int64(pStmt, 0);
    pIndex = sqlite3Fts5IndexFromCsrid(pTab->pGlobal, iId, &nCol);
  }

  if( rc==SQLITE_OK && pIndex==0 ){
    rc = sqlite3_finalize(pStmt);
    pStmt = 0;
    if( rc==SQLITE_OK ){
      pVTab->zErrMsg = sqlite3_mprintf(
          "no such fts5 table: %s.%s", pTab->zFts5Db, pTab->zFts5Tbl
      );
      rc = SQLITE_ERROR;
    }
  }

  nByte = nCol * sizeof(i64) * 2 + sizeof(Fts5VocabCursor);
  pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte);
  if( pCsr ){
................................................................................
}

/*
** Close the cursor.  For additional information see the documentation
** on the xClose method of the virtual table interface.
*/
static int fts5VocabCloseMethod(sqlite3_vtab_cursor *pCursor){

  Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
  fts5VocabResetCursor(pCsr);
  sqlite3Fts5BufferFree(&pCsr->term);
  sqlite3_finalize(pCsr->pStmt);
  sqlite3_free(pCsr);

  return SQLITE_OK;
}


/*
** Advance the cursor to the next row in the table.
*/

Changes to ext/fts5/test/fts5fault4.test.

330
331
332
333
334
335
336
337




































338
339
  CREATE VIRTUAL TABLE ft USING fts5(x);
}
do_faultsim_test 11.1 -faults oom-t* -body {
  db eval { INSERT INTO ft(ft, rank) VALUES('rank', 'bm25(10.0, 5.0)') }
} -test {
  faultsim_test_result {0 {}} {1 {disk I/O error}}
}





































finish_test









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
  CREATE VIRTUAL TABLE ft USING fts5(x);
}
do_faultsim_test 11.1 -faults oom-t* -body {
  db eval { INSERT INTO ft(ft, rank) VALUES('rank', 'bm25(10.0, 5.0)') }
} -test {
  faultsim_test_result {0 {}} {1 {disk I/O error}}
}

#-------------------------------------------------------------------------
# OOM while creating an fts5vocab table.
#
reset_db
do_execsql_test 12.0 {
  CREATE VIRTUAL TABLE ft USING fts5(x);
}
faultsim_save_and_close
do_faultsim_test 12.1 -faults oom-t* -prep {
  faultsim_restore_and_reopen
  db eval { SELECT * FROM sqlite_master }
} -body {
  db eval { CREATE VIRTUAL TABLE vv USING fts5vocab(ft, 'row') }
} -test {
  faultsim_test_result {0 {}} 
}

#-------------------------------------------------------------------------
# OOM while querying an fts5vocab table.
#
reset_db
do_execsql_test 13.0 {
  CREATE VIRTUAL TABLE ft USING fts5(x);
  INSERT INTO ft VALUES('a b');
  CREATE VIRTUAL TABLE vv USING fts5vocab(ft, 'row');
}
faultsim_save_and_close
do_faultsim_test 13.1 -faults oom-t* -prep {
  faultsim_restore_and_reopen
  db eval { SELECT * FROM vv }
} -body {
  db eval { SELECT * FROM vv }
} -test {
  faultsim_test_result {0 {a 1 1 b 1 1}} 
}

finish_test

Changes to ext/fts5/test/fts5vocab.test.

116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131













































































132
133
    DROP TABLE IF EXISTS tv;
    CREATE VIRTUAL TABLE tv USING $tbl;
    SELECT * FROM tv;
  " [set $resname]
}

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

#
foreach {tn sql} {
  1 { CREATE VIRTUAL TABLE aa USING fts5vocab() }
  2 { CREATE VIRTUAL TABLE aa USING fts5vocab(x) }
  3 { CREATE VIRTUAL TABLE aa USING fts5vocab(x,y,z) }
  4 { CREATE VIRTUAL TABLE temp.aa USING fts5vocab(x,y,z,y) }
} {
  do_catchsql_test 3.$tn $sql {1 {wrong number of vtable arguments}}
}













































































finish_test








>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


116
117
118
119
120
121
122
123
124
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
202
203
204
205
206
207
208
209
210
211
    DROP TABLE IF EXISTS tv;
    CREATE VIRTUAL TABLE tv USING $tbl;
    SELECT * FROM tv;
  " [set $resname]
}

#-------------------------------------------------------------------------
# Test errors in the CREATE VIRTUAL TABLE statement.
#
foreach {tn sql} {
  1 { CREATE VIRTUAL TABLE aa USING fts5vocab() }
  2 { CREATE VIRTUAL TABLE aa USING fts5vocab(x) }
  3 { CREATE VIRTUAL TABLE aa USING fts5vocab(x,y,z) }
  4 { CREATE VIRTUAL TABLE temp.aa USING fts5vocab(x,y,z,y) }
} {
  do_catchsql_test 3.$tn $sql {1 {wrong number of vtable arguments}}
}

do_catchsql_test 4.0 {
  CREATE VIRTUAL TABLE cc USING fts5vocab(tbl, unknown);
} {1 {fts5vocab: unknown table type: 'unknown'}}

do_catchsql_test 4.1 {
  ATTACH 'test.db' AS aux;
  CREATE VIRTUAL TABLE aux.cc USING fts5vocab(main, tbl, row);
} {1 {wrong number of vtable arguments}}

#-------------------------------------------------------------------------
# Test fts5vocab tables created in the temp schema. 
#
reset_db
forcedelete test.db2
do_execsql_test 5.0 {
  ATTACH 'test.db2' AS aux;
  CREATE VIRTUAL TABLE t1 USING fts5(x);
  CREATE VIRTUAL TABLE temp.t1 USING fts5(x);
  CREATE VIRTUAL TABLE aux.t1 USING fts5(x);

  INSERT INTO main.t1 VALUES('a b c');
  INSERT INTO main.t1 VALUES('d e f');
  INSERT INTO main.t1 VALUES('a e c');

  INSERT INTO temp.t1 VALUES('1 2 3');
  INSERT INTO temp.t1 VALUES('4 5 6');
  INSERT INTO temp.t1 VALUES('1 5 3');

  INSERT INTO aux.t1 VALUES('x y z');
  INSERT INTO aux.t1 VALUES('m n o');
  INSERT INTO aux.t1 VALUES('x n z');
}

breakpoint
do_execsql_test 5.1 {
  CREATE VIRTUAL TABLE temp.vm  USING fts5vocab(main, t1, row);
  CREATE VIRTUAL TABLE temp.vt1 USING fts5vocab(t1, row);
  CREATE VIRTUAL TABLE temp.vt2 USING fts5vocab(temp, t1, row);
  CREATE VIRTUAL TABLE temp.va  USING fts5vocab(aux, t1, row);
}

do_execsql_test 5.2 { SELECT * FROM vm } {
  a 2 2 b 1 1 c 2 2 d 1 1 e 2 2 f 1 1
}
do_execsql_test 5.3 { SELECT * FROM vt1 } {
  1 2 2 2 1 1 3 2 2 4 1 1 5 2 2 6 1 1
}
do_execsql_test 5.4 { SELECT * FROM vt2 } {
  1 2 2 2 1 1 3 2 2 4 1 1 5 2 2 6 1 1
}
do_execsql_test 5.5 { SELECT * FROM va } {
  m 1 1 n 2 2 o 1 1 x 2 2 y 1 1 z 2 2
}

#-------------------------------------------------------------------------
#
do_execsql_test 6.0 {
  CREATE TABLE iii(iii);
  CREATE TABLE jjj(x);
}

do_catchsql_test 6.1 {
  CREATE VIRTUAL TABLE vocab1 USING fts5vocab(iii, row);
  SELECT * FROM vocab1;
} {1 {no such fts5 table: main.iii}}

do_catchsql_test 6.2 {
  CREATE VIRTUAL TABLE vocab2 USING fts5vocab(jjj, row);
  SELECT * FROM vocab2;
} {1 {no such fts5 table: main.jjj}}

do_catchsql_test 6.2 {
  CREATE VIRTUAL TABLE vocab3 USING fts5vocab(lll, row);
  SELECT * FROM vocab3;
} {1 {no such fts5 table: main.lll}}

finish_test