Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: third_party/sqlite/src/ext/fts2/fts2.c

Issue 885473002: [sql] Rewrite sqlite patching "system". (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* fts2 has a design flaw which can lead to database corruption (see 1 /* fts2 has a design flaw which can lead to database corruption (see
2 ** below). It is recommended not to use it any longer, instead use 2 ** below). It is recommended not to use it any longer, instead use
3 ** fts3 (or higher). If you believe that your use of fts2 is safe, 3 ** fts3 (or higher). If you believe that your use of fts2 is safe,
4 ** add -DSQLITE_ENABLE_BROKEN_FTS2=1 to your CFLAGS. 4 ** add -DSQLITE_ENABLE_BROKEN_FTS2=1 to your CFLAGS.
5 */ 5 */
6 #if (!defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2)) \ 6 #if (!defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2)) \
7 && !defined(SQLITE_ENABLE_BROKEN_FTS2) 7 && !defined(SQLITE_ENABLE_BROKEN_FTS2)
8 #error fts2 has a design flaw and has been deprecated. 8 #error fts2 has a design flaw and has been deprecated.
9 #endif 9 #endif
10 /* The flaw is that fts2 uses the content table's unaliased rowid as 10 /* The flaw is that fts2 uses the content table's unaliased rowid as
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 #endif 317 #endif
318 318
319 #include <assert.h> 319 #include <assert.h>
320 #include <stdlib.h> 320 #include <stdlib.h>
321 #include <stdio.h> 321 #include <stdio.h>
322 #include <string.h> 322 #include <string.h>
323 #include "fts2.h" 323 #include "fts2.h"
324 #include "fts2_hash.h" 324 #include "fts2_hash.h"
325 #include "fts2_tokenizer.h" 325 #include "fts2_tokenizer.h"
326 #include "sqlite3.h" 326 #include "sqlite3.h"
327 #ifndef SQLITE_CORE 327 #ifndef SQLITE_CORE
328 # include "sqlite3ext.h" 328 # include "sqlite3ext.h"
329 SQLITE_EXTENSION_INIT1 329 SQLITE_EXTENSION_INIT1
330 #endif 330 #endif
331 331
332 332
333 /* TODO(shess) MAN, this thing needs some refactoring. At minimum, it 333 /* TODO(shess) MAN, this thing needs some refactoring. At minimum, it
334 ** would be nice to order the file better, perhaps something along the 334 ** would be nice to order the file better, perhaps something along the
335 ** lines of: 335 ** lines of:
336 ** 336 **
337 ** - utility functions 337 ** - utility functions
(...skipping 3420 matching lines...) Expand 10 before | Expand all | Expand 10 after
3758 * sets isPrefix correctly, but since that code doesn't eat the '*', the 3758 * sets isPrefix correctly, but since that code doesn't eat the '*', the
3759 * ICU tokenizer returns it as the next token. So eat it here until a 3759 * ICU tokenizer returns it as the next token. So eat it here until a
3760 * better solution presents itself. 3760 * better solution presents itself.
3761 */ 3761 */
3762 if( pQuery->nTerms>0 && nToken==1 && pSegment[iBegin]=='*' && 3762 if( pQuery->nTerms>0 && nToken==1 && pSegment[iBegin]=='*' &&
3763 iEndLast==iBegin){ 3763 iEndLast==iBegin){
3764 pQuery->pTerms[pQuery->nTerms-1].isPrefix = 1; 3764 pQuery->pTerms[pQuery->nTerms-1].isPrefix = 1;
3765 continue; 3765 continue;
3766 } 3766 }
3767 iEndLast = iEnd; 3767 iEndLast = iEnd;
3768 3768
3769 queryAdd(pQuery, pToken, nToken); 3769 queryAdd(pQuery, pToken, nToken);
3770 if( !inPhrase && iBegin>0 && pSegment[iBegin-1]=='-' ){ 3770 if( !inPhrase && iBegin>0 && pSegment[iBegin-1]=='-' ){
3771 pQuery->pTerms[pQuery->nTerms-1].isNot = 1; 3771 pQuery->pTerms[pQuery->nTerms-1].isNot = 1;
3772 } 3772 }
3773 if( iEnd<nSegment && pSegment[iEnd]=='*' ){ 3773 if( iEnd<nSegment && pSegment[iEnd]=='*' ){
3774 pQuery->pTerms[pQuery->nTerms-1].isPrefix = 1; 3774 pQuery->pTerms[pQuery->nTerms-1].isPrefix = 1;
3775 } 3775 }
3776 pQuery->pTerms[pQuery->nTerms-1].iPhrase = nTerm; 3776 pQuery->pTerms[pQuery->nTerms-1].iPhrase = nTerm;
3777 if( inPhrase ){ 3777 if( inPhrase ){
3778 nTerm++; 3778 nTerm++;
(...skipping 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after
5545 if( pData==NULL ){ 5545 if( pData==NULL ){
5546 rc = SQLITE_CORRUPT_BKPT; 5546 rc = SQLITE_CORRUPT_BKPT;
5547 break; 5547 break;
5548 } 5548 }
5549 rc = dlrInit(&dlReaders[i], DL_DEFAULT, 5549 rc = dlrInit(&dlReaders[i], DL_DEFAULT,
5550 pData, 5550 pData,
5551 leavesReaderDataBytes(pReaders+i)); 5551 leavesReaderDataBytes(pReaders+i));
5552 if( rc!=SQLITE_OK ) break; 5552 if( rc!=SQLITE_OK ) break;
5553 } 5553 }
5554 if( rc!=SQLITE_OK ){ 5554 if( rc!=SQLITE_OK ){
5555 while( i-->0 ){ 5555 while( i-->0 ){
5556 dlrDestroy(&dlReaders[i]); 5556 dlrDestroy(&dlReaders[i]);
5557 } 5557 }
5558 return rc; 5558 return rc;
5559 } 5559 }
5560 5560
5561 return leafWriterStepMerge(v, pWriter, pTerm, nTerm, dlReaders, nReaders); 5561 return leafWriterStepMerge(v, pWriter, pTerm, nTerm, dlReaders, nReaders);
5562 } 5562 }
5563 5563
5564 /* Forward ref due to mutual recursion with segdirNextIndex(). */ 5564 /* Forward ref due to mutual recursion with segdirNextIndex(). */
5565 static int segmentMerge(fulltext_vtab *v, int iLevel); 5565 static int segmentMerge(fulltext_vtab *v, int iLevel);
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
6894 */ 6894 */
6895 static void createDoclistResult(sqlite3_context *pContext, 6895 static void createDoclistResult(sqlite3_context *pContext,
6896 const char *pData, int nData){ 6896 const char *pData, int nData){
6897 DataBuffer dump; 6897 DataBuffer dump;
6898 DLReader dlReader; 6898 DLReader dlReader;
6899 int rc; 6899 int rc;
6900 6900
6901 assert( pData!=NULL && nData>0 ); 6901 assert( pData!=NULL && nData>0 );
6902 6902
6903 rc = dlrInit(&dlReader, DL_DEFAULT, pData, nData); 6903 rc = dlrInit(&dlReader, DL_DEFAULT, pData, nData);
6904 if( rc!=SQLITE_OK ) return rc; 6904 if( rc!=SQLITE_OK ) return;
6905 dataBufferInit(&dump, 0); 6905 dataBufferInit(&dump, 0);
6906 for( ; rc==SQLITE_OK && !dlrAtEnd(&dlReader); rc = dlrStep(&dlReader) ){ 6906 for( ; rc==SQLITE_OK && !dlrAtEnd(&dlReader); rc = dlrStep(&dlReader) ){
6907 char buf[256]; 6907 char buf[256];
6908 PLReader plReader; 6908 PLReader plReader;
6909 6909
6910 rc = plrInit(&plReader, &dlReader); 6910 rc = plrInit(&plReader, &dlReader);
6911 if( rc!=SQLITE_OK ) break; 6911 if( rc!=SQLITE_OK ) break;
6912 if( DL_DEFAULT==DL_DOCIDS || plrAtEnd(&plReader) ){ 6912 if( DL_DEFAULT==DL_DOCIDS || plrAtEnd(&plReader) ){
6913 sqlite3_snprintf(sizeof(buf), buf, "[%lld] ", dlrDocid(&dlReader)); 6913 sqlite3_snprintf(sizeof(buf), buf, "[%lld] ", dlrDocid(&dlReader));
6914 dataBufferAppend(&dump, buf, strlen(buf)); 6914 dataBufferAppend(&dump, buf, strlen(buf));
(...skipping 30 matching lines...) Expand all
6945 6945
6946 assert( dump.nData>0 ); 6946 assert( dump.nData>0 );
6947 dump.nData--; /* Overwrite trailing space. */ 6947 dump.nData--; /* Overwrite trailing space. */
6948 assert( dump.pData[dump.nData]==' '); 6948 assert( dump.pData[dump.nData]==' ');
6949 dataBufferAppend(&dump, "]] ", 3); 6949 dataBufferAppend(&dump, "]] ", 3);
6950 } 6950 }
6951 } 6951 }
6952 dlrDestroy(&dlReader); 6952 dlrDestroy(&dlReader);
6953 if( rc!=SQLITE_OK ){ 6953 if( rc!=SQLITE_OK ){
6954 dataBufferDestroy(&dump); 6954 dataBufferDestroy(&dump);
6955 return rc; 6955 return;
6956 } 6956 }
6957 6957
6958 assert( dump.nData>0 ); 6958 assert( dump.nData>0 );
6959 dump.nData--; /* Overwrite trailing space. */ 6959 dump.nData--; /* Overwrite trailing space. */
6960 assert( dump.pData[dump.nData]==' '); 6960 assert( dump.pData[dump.nData]==' ');
6961 dump.pData[dump.nData] = '\0'; 6961 dump.pData[dump.nData] = '\0';
6962 assert( dump.nData>0 ); 6962 assert( dump.nData>0 );
6963 6963
6964 /* Passes ownership of dump's buffer to pContext. */ 6964 /* Passes ownership of dump's buffer to pContext. */
6965 sqlite3_result_text(pContext, dump.pData, dump.nData, sqlite3_free); 6965 sqlite3_result_text(pContext, dump.pData, dump.nData, sqlite3_free);
6966 dump.pData = NULL; 6966 dump.pData = NULL;
6967 dump.nData = dump.nCapacity = 0; 6967 dump.nData = dump.nCapacity = 0;
6968 return SQLITE_OK;
6969 } 6968 }
6970 6969
6971 /* Implements dump_doclist() for use in inspecting the fts2 index from 6970 /* Implements dump_doclist() for use in inspecting the fts2 index from
6972 ** tests. TEXT result containing a string representation of the 6971 ** tests. TEXT result containing a string representation of the
6973 ** doclist for the indicated term. dump_doclist(t, term, level, idx) 6972 ** doclist for the indicated term. dump_doclist(t, term, level, idx)
6974 ** dumps the doclist for term from the segment specified by level, idx 6973 ** dumps the doclist for term from the segment specified by level, idx
6975 ** (in %_segdir), while dump_doclist(t, term) dumps the logical 6974 ** (in %_segdir), while dump_doclist(t, term) dumps the logical
6976 ** doclist for the term across all segments. The per-segment doclist 6975 ** doclist for the term across all segments. The per-segment doclist
6977 ** can contain deletions, while the full-index doclist will not 6976 ** can contain deletions, while the full-index doclist will not
6978 ** (deletions are omitted). 6977 ** (deletions are omitted).
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
7280 sqlite3 *db, 7279 sqlite3 *db,
7281 char **pzErrMsg, 7280 char **pzErrMsg,
7282 const sqlite3_api_routines *pApi 7281 const sqlite3_api_routines *pApi
7283 ){ 7282 ){
7284 SQLITE_EXTENSION_INIT2(pApi) 7283 SQLITE_EXTENSION_INIT2(pApi)
7285 return sqlite3Fts2Init(db); 7284 return sqlite3Fts2Init(db);
7286 } 7285 }
7287 #endif 7286 #endif
7288 7287
7289 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */ 7288 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698