OLD | NEW |
1 /* | 1 /* |
2 ** 2006 Oct 10 | 2 ** 2006 Oct 10 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 ** we simply write the new doclist. Segment merges overwrite older | 284 ** we simply write the new doclist. Segment merges overwrite older |
285 ** data for a particular docid with newer data, so deletes or updates | 285 ** data for a particular docid with newer data, so deletes or updates |
286 ** will eventually overtake the earlier data and knock it out. The | 286 ** will eventually overtake the earlier data and knock it out. The |
287 ** query logic likewise merges doclists so that newer data knocks out | 287 ** query logic likewise merges doclists so that newer data knocks out |
288 ** older data. | 288 ** older data. |
289 ** | 289 ** |
290 ** TODO(shess) Provide a VACUUM type operation to clear out all | 290 ** TODO(shess) Provide a VACUUM type operation to clear out all |
291 ** deletions and duplications. This would basically be a forced merge | 291 ** deletions and duplications. This would basically be a forced merge |
292 ** into a single segment. | 292 ** into a single segment. |
293 */ | 293 */ |
294 #define CHROMIUM_FTS3_CHANGES 1 | |
295 | 294 |
296 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) | 295 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
297 | 296 |
298 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE) | 297 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE) |
299 # define SQLITE_CORE 1 | 298 # define SQLITE_CORE 1 |
300 #endif | 299 #endif |
301 | 300 |
302 #include "fts3Int.h" | 301 #include "fts3Int.h" |
303 | 302 |
304 #include <assert.h> | 303 #include <assert.h> |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 | 622 |
624 zSql = sqlite3_mprintf("PRAGMA %Q.page_size", p->zDb); | 623 zSql = sqlite3_mprintf("PRAGMA %Q.page_size", p->zDb); |
625 if( !zSql ){ | 624 if( !zSql ){ |
626 rc = SQLITE_NOMEM; | 625 rc = SQLITE_NOMEM; |
627 }else{ | 626 }else{ |
628 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0); | 627 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0); |
629 if( rc==SQLITE_OK ){ | 628 if( rc==SQLITE_OK ){ |
630 sqlite3_step(pStmt); | 629 sqlite3_step(pStmt); |
631 p->nPgsz = sqlite3_column_int(pStmt, 0); | 630 p->nPgsz = sqlite3_column_int(pStmt, 0); |
632 rc = sqlite3_finalize(pStmt); | 631 rc = sqlite3_finalize(pStmt); |
633 }else if( rc==SQLITE_AUTH ){ | |
634 p->nPgsz = 1024; | |
635 rc = SQLITE_OK; | |
636 } | 632 } |
637 } | 633 } |
638 assert( p->nPgsz>0 || rc!=SQLITE_OK ); | 634 assert( p->nPgsz>0 || rc!=SQLITE_OK ); |
639 sqlite3_free(zSql); | 635 sqlite3_free(zSql); |
640 *pRc = rc; | 636 *pRc = rc; |
641 } | 637 } |
642 } | 638 } |
643 | 639 |
644 /* | 640 /* |
645 ** "Special" FTS4 arguments are column specifications of the following form: | 641 ** "Special" FTS4 arguments are column specifications of the following form: |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 int nBuffer; /* Total term size */ | 1219 int nBuffer; /* Total term size */ |
1224 | 1220 |
1225 /* Load the next term on the node into zBuffer. Use realloc() to expand | 1221 /* Load the next term on the node into zBuffer. Use realloc() to expand |
1226 ** the size of zBuffer if required. */ | 1222 ** the size of zBuffer if required. */ |
1227 if( !isFirstTerm ){ | 1223 if( !isFirstTerm ){ |
1228 zCsr += sqlite3Fts3GetVarint32(zCsr, &nPrefix); | 1224 zCsr += sqlite3Fts3GetVarint32(zCsr, &nPrefix); |
1229 } | 1225 } |
1230 isFirstTerm = 0; | 1226 isFirstTerm = 0; |
1231 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix); | 1227 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix); |
1232 | 1228 |
1233 /* NOTE(shess): Previous code checked for negative nPrefix and | 1229 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){ |
1234 ** nSuffix and suffix overrunning zEnd. Additionally corrupt if | |
1235 ** the prefix is longer than the previous term, or if the suffix | |
1236 ** causes overflow. | |
1237 */ | |
1238 if( nPrefix<0 || nSuffix<0 /* || nPrefix>nBuffer */ | |
1239 || &zCsr[nSuffix]<zCsr || &zCsr[nSuffix]>zEnd ){ | |
1240 rc = SQLITE_CORRUPT; | 1230 rc = SQLITE_CORRUPT; |
1241 goto finish_scan; | 1231 goto finish_scan; |
1242 } | 1232 } |
1243 if( nPrefix+nSuffix>nAlloc ){ | 1233 if( nPrefix+nSuffix>nAlloc ){ |
1244 char *zNew; | 1234 char *zNew; |
1245 nAlloc = (nPrefix+nSuffix) * 2; | 1235 nAlloc = (nPrefix+nSuffix) * 2; |
1246 zNew = (char *)sqlite3_realloc(zBuffer, nAlloc); | 1236 zNew = (char *)sqlite3_realloc(zBuffer, nAlloc); |
1247 if( !zNew ){ | 1237 if( !zNew ){ |
1248 rc = SQLITE_NOMEM; | 1238 rc = SQLITE_NOMEM; |
1249 goto finish_scan; | 1239 goto finish_scan; |
(...skipping 2399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3649 if( rc==SQLITE_OK ){ | 3639 if( rc==SQLITE_OK ){ |
3650 rc = sqlite3Fts3ExprInitTestInterface(db); | 3640 rc = sqlite3Fts3ExprInitTestInterface(db); |
3651 } | 3641 } |
3652 #endif | 3642 #endif |
3653 | 3643 |
3654 /* Create the virtual table wrapper around the hash-table and overload | 3644 /* Create the virtual table wrapper around the hash-table and overload |
3655 ** the two scalar functions. If this is successful, register the | 3645 ** the two scalar functions. If this is successful, register the |
3656 ** module with sqlite. | 3646 ** module with sqlite. |
3657 */ | 3647 */ |
3658 if( SQLITE_OK==rc | 3648 if( SQLITE_OK==rc |
3659 #if CHROMIUM_FTS3_CHANGES && !SQLITE_TEST | |
3660 /* fts3_tokenizer() disabled for security reasons. */ | |
3661 #else | |
3662 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer")) | 3649 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer")) |
3663 #endif | |
3664 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1)) | 3650 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1)) |
3665 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1)) | 3651 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1)) |
3666 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1)) | 3652 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1)) |
3667 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2)) | 3653 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2)) |
3668 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1)) | 3654 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1)) |
3669 ){ | 3655 ){ |
3670 rc = sqlite3_create_module_v2( | 3656 rc = sqlite3_create_module_v2( |
3671 db, "fts3", &fts3Module, (void *)pHash, hashDestroy | 3657 db, "fts3", &fts3Module, (void *)pHash, hashDestroy |
3672 ); | 3658 ); |
3673 #if CHROMIUM_FTS3_CHANGES && !SQLITE_TEST | |
3674 /* Disable fts4 pending review. */ | |
3675 #else | |
3676 if( rc==SQLITE_OK ){ | 3659 if( rc==SQLITE_OK ){ |
3677 rc = sqlite3_create_module_v2( | 3660 rc = sqlite3_create_module_v2( |
3678 db, "fts4", &fts3Module, (void *)pHash, 0 | 3661 db, "fts4", &fts3Module, (void *)pHash, 0 |
3679 ); | 3662 ); |
3680 } | 3663 } |
3681 #endif | |
3682 return rc; | 3664 return rc; |
3683 } | 3665 } |
3684 | 3666 |
3685 /* An error has occurred. Delete the hash table and return the error code. */ | 3667 /* An error has occurred. Delete the hash table and return the error code. */ |
3686 assert( rc!=SQLITE_OK ); | 3668 assert( rc!=SQLITE_OK ); |
3687 if( pHash ){ | 3669 if( pHash ){ |
3688 sqlite3Fts3HashClear(pHash); | 3670 sqlite3Fts3HashClear(pHash); |
3689 sqlite3_free(pHash); | 3671 sqlite3_free(pHash); |
3690 } | 3672 } |
3691 return rc; | 3673 return rc; |
3692 } | 3674 } |
3693 | 3675 |
3694 #if !SQLITE_CORE | 3676 #if !SQLITE_CORE |
3695 int sqlite3_extension_init( | 3677 int sqlite3_extension_init( |
3696 sqlite3 *db, | 3678 sqlite3 *db, |
3697 char **pzErrMsg, | 3679 char **pzErrMsg, |
3698 const sqlite3_api_routines *pApi | 3680 const sqlite3_api_routines *pApi |
3699 ){ | 3681 ){ |
3700 SQLITE_EXTENSION_INIT2(pApi) | 3682 SQLITE_EXTENSION_INIT2(pApi) |
3701 return sqlite3Fts3Init(db); | 3683 return sqlite3Fts3Init(db); |
3702 } | 3684 } |
3703 #endif | 3685 #endif |
3704 | 3686 |
3705 #endif | 3687 #endif |
OLD | NEW |