diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/fts3/tool/fts3view.c | 2 | ||||
-rw-r--r-- | ext/fts5/fts5_aux.c | 2 | ||||
-rw-r--r-- | ext/fts5/fts5_expr.c | 8 | ||||
-rw-r--r-- | ext/fts5/fts5_hash.c | 2 | ||||
-rw-r--r-- | ext/fts5/fts5_index.c | 19 | ||||
-rw-r--r-- | ext/fts5/fts5_main.c | 6 | ||||
-rw-r--r-- | ext/fts5/fts5_storage.c | 2 | ||||
-rw-r--r-- | ext/fts5/fts5_tokenize.c | 4 | ||||
-rw-r--r-- | ext/misc/json1.c | 112 | ||||
-rw-r--r-- | ext/misc/spellfix.c | 10 |
10 files changed, 143 insertions, 24 deletions
diff --git a/ext/fts3/tool/fts3view.c b/ext/fts3/tool/fts3view.c index 6dada352b..a8d7981af 100644 --- a/ext/fts3/tool/fts3view.c +++ b/ext/fts3/tool/fts3view.c @@ -398,7 +398,7 @@ static void showSegmentStats(sqlite3 *db, const char *zTab){ if( sqlite3_step(pStmt)==SQLITE_ROW && (nLeaf = sqlite3_column_int(pStmt, 0))>0 ){ - int nIdx = sqlite3_column_int(pStmt, 5); + nIdx = sqlite3_column_int(pStmt, 5); sqlite3_int64 sz; printf("For level %d:\n", i); printf(" Number of indexes...................... %9d\n", nIdx); diff --git a/ext/fts5/fts5_aux.c b/ext/fts5/fts5_aux.c index 928a26a8b..011064d40 100644 --- a/ext/fts5/fts5_aux.c +++ b/ext/fts5/fts5_aux.c @@ -544,7 +544,7 @@ int sqlite3Fts5AuxInit(fts5_api *pApi){ int rc = SQLITE_OK; /* Return code */ int i; /* To iterate through builtin functions */ - for(i=0; rc==SQLITE_OK && i<sizeof(aBuiltin)/sizeof(aBuiltin[0]); i++){ + for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aBuiltin); i++){ rc = pApi->xCreateFunction(pApi, aBuiltin[i].zFunc, aBuiltin[i].pUserData, diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index 59deda613..a747a64c9 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -407,7 +407,7 @@ static int fts5ExprPhraseIsMatch( /* If the aStatic[] array is not large enough, allocate a large array ** using sqlite3_malloc(). This approach could be improved upon. */ - if( pPhrase->nTerm>(sizeof(aStatic) / sizeof(aStatic[0])) ){ + if( pPhrase->nTerm>(int)ArraySize(aStatic) ){ int nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm; aIter = (Fts5PoslistReader*)sqlite3_malloc(nByte); if( !aIter ) return SQLITE_NOMEM; @@ -430,7 +430,7 @@ static int fts5ExprPhraseIsMatch( } if( rc!=SQLITE_OK ) goto ismatch_out; sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]); - aIter[i].bFlag = bFlag; + aIter[i].bFlag = (u8)bFlag; if( aIter[i].bEof ) goto ismatch_out; } @@ -543,7 +543,7 @@ static int fts5ExprNearIsMatch(int *pRc, Fts5ExprNearset *pNear){ /* If the aStatic[] array is not large enough, allocate a large array ** using sqlite3_malloc(). This approach could be improved upon. */ - if( pNear->nPhrase>(sizeof(aStatic) / sizeof(aStatic[0])) ){ + if( pNear->nPhrase>(int)ArraySize(aStatic) ){ int nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase; a = (Fts5NearTrimmer*)sqlite3Fts5MallocZero(&rc, nByte); }else{ @@ -2190,7 +2190,7 @@ int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){ int rc = SQLITE_OK; void *pCtx = (void*)pGlobal; - for(i=0; rc==SQLITE_OK && i<(sizeof(aFunc) / sizeof(aFunc[0])); i++){ + for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aFunc); i++){ struct Fts5ExprFunc *p = &aFunc[i]; rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0); } diff --git a/ext/fts5/fts5_hash.c b/ext/fts5/fts5_hash.c index e1b5bcdf8..f184957af 100644 --- a/ext/fts5/fts5_hash.c +++ b/ext/fts5/fts5_hash.c @@ -190,7 +190,7 @@ static void fts5HashAddPoslistSize(Fts5HashEntry *p){ assert( p->bDel==0 || p->bDel==1 ); if( nPos<=127 ){ - pPtr[p->iSzPoslist] = nPos; + pPtr[p->iSzPoslist] = (u8)nPos; }else{ int nByte = sqlite3Fts5GetVarintLen((u32)nPos); memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz); diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index b7374f980..c11abda5b 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -2393,7 +2393,7 @@ static int fts5MultiIterDoCompare(Fts5IndexIter *pIter, int iOut){ } } - pRes->iFirst = iRes; + pRes->iFirst = (u16)iRes; return 0; } @@ -2560,7 +2560,7 @@ static int fts5MultiIterAdvanceRowid( pIter->iSwitchRowid = pOther->iRowid; } } - pRes->iFirst = (pNew - pIter->aSeg); + pRes->iFirst = (u16)(pNew - pIter->aSeg); if( i==1 ) break; pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ]; @@ -2711,7 +2711,7 @@ static void fts5MultiIterNew( *ppOut = pNew = fts5MultiIterAlloc(p, nSeg); if( pNew==0 ) return; pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC)); - pNew->bSkipEmpty = bSkipEmpty; + pNew->bSkipEmpty = (u8)bSkipEmpty; pNew->pStruct = pStruct; fts5StructureRef(pStruct); @@ -3174,7 +3174,7 @@ static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){ /* Set the szLeaf header field. */ assert( 0==fts5GetU16(&pPage->buf.p[2]) ); - fts5PutU16(&pPage->buf.p[2], pPage->buf.n); + fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n); if( pWriter->bFirstTermInPage ){ /* No term was written to this page. */ @@ -3306,7 +3306,7 @@ static void fts5WriteAppendRowid( ** rowid-pointer in the page-header. Also append a value to the dlidx ** buffer, in case a doclist-index is required. */ if( pWriter->bFirstRowidInPage ){ - fts5PutU16(pPage->buf.p, pPage->buf.n); + fts5PutU16(pPage->buf.p, (u16)pPage->buf.n); fts5WriteDlidxAppend(p, pWriter, iRowid); } @@ -3464,7 +3464,7 @@ static void fts5TrimSegments(Fts5Index *p, Fts5IndexIter *pIter){ fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]); if( p->rc==SQLITE_OK ){ /* Set the szLeaf field */ - fts5PutU16(&buf.p[2], buf.n); + fts5PutU16(&buf.p[2], (u16)buf.n); } /* Set up the new page-index array */ @@ -3830,7 +3830,7 @@ static void fts5FlushOneHash(Fts5Index *p){ iRowid += iDelta; if( writer.bFirstRowidInPage ){ - fts5PutU16(&pBuf->p[0], pBuf->n); /* first rowid on page */ + fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */ pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid); writer.bFirstRowidInPage = 0; fts5WriteDlidxAppend(p, &writer, iRowid); @@ -4627,7 +4627,8 @@ int sqlite3Fts5IndexWrite( int nByte = fts5IndexCharlenToBytelen(pToken, nToken, pConfig->aPrefix[i]); if( nByte ){ rc = sqlite3Fts5HashWrite(p->pHash, - p->iWriteRowid, iCol, iPos, FTS5_MAIN_PREFIX+i+1, pToken, nByte + p->iWriteRowid, iCol, iPos, (char)(FTS5_MAIN_PREFIX+i+1), pToken, + nByte ); } } @@ -4677,7 +4678,7 @@ int sqlite3Fts5IndexQuery( if( iIdx<=pConfig->nPrefix ){ Fts5Structure *pStruct = fts5StructureRead(p); - buf.p[0] = FTS5_MAIN_PREFIX + iIdx; + buf.p[0] = (u8)(FTS5_MAIN_PREFIX + iIdx); if( pStruct ){ fts5MultiIterNew(p, pStruct, 1, flags, buf.p, nToken+1, -1, 0, &pRet); fts5StructureRelease(pStruct); diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index 9390cb6cb..70912de4f 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -537,7 +537,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ for(i=0; i<pInfo->nConstraint; i++){ struct sqlite3_index_constraint *p = &pInfo->aConstraint[i]; int j; - for(j=0; j<sizeof(aConstraint)/sizeof(aConstraint[0]); j++){ + for(j=0; j<(int)ArraySize(aConstraint); j++){ struct Constraint *pC = &aConstraint[j]; if( p->iColumn==aColMap[pC->iCol] && p->op & pC->op ){ if( p->usable ){ @@ -584,11 +584,11 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ /* Assign argvIndex values to each constraint in use. */ iNext = 1; - for(i=0; i<sizeof(aConstraint)/sizeof(aConstraint[0]); i++){ + for(i=0; i<(int)ArraySize(aConstraint); i++){ struct Constraint *pC = &aConstraint[i]; if( pC->iConsIndex>=0 ){ pInfo->aConstraintUsage[pC->iConsIndex].argvIndex = iNext++; - pInfo->aConstraintUsage[pC->iConsIndex].omit = pC->omit; + pInfo->aConstraintUsage[pC->iConsIndex].omit = (unsigned char)pC->omit; } } diff --git a/ext/fts5/fts5_storage.c b/ext/fts5/fts5_storage.c index 5fd5dc51a..13297c150 100644 --- a/ext/fts5/fts5_storage.c +++ b/ext/fts5/fts5_storage.c @@ -338,7 +338,7 @@ int sqlite3Fts5StorageClose(Fts5Storage *p){ int i; /* Finalize all SQL statements */ - for(i=0; i<ArraySize(p->aStmt); i++){ + for(i=0; i<(int)ArraySize(p->aStmt); i++){ sqlite3_finalize(p->aStmt[i]); } diff --git a/ext/fts5/fts5_tokenize.c b/ext/fts5/fts5_tokenize.c index 44b154e4c..e60183c09 100644 --- a/ext/fts5/fts5_tokenize.c +++ b/ext/fts5/fts5_tokenize.c @@ -256,7 +256,7 @@ static int fts5UnicodeAddExceptions( int bToken; READ_UTF8(zCsr, zTerm, iCode); if( iCode<128 ){ - p->aTokenChar[iCode] = bTokenChars; + p->aTokenChar[iCode] = (unsigned char)bTokenChars; }else{ bToken = sqlite3Fts5UnicodeIsalnum(iCode); assert( (bToken==0 || bToken==1) ); @@ -1220,7 +1220,7 @@ int sqlite3Fts5TokenizerInit(fts5_api *pApi){ int rc = SQLITE_OK; /* Return code */ int i; /* To iterate through builtin functions */ - for(i=0; rc==SQLITE_OK && i<sizeof(aBuiltin)/sizeof(aBuiltin[0]); i++){ + for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aBuiltin); i++){ rc = pApi->xCreateTokenizer(pApi, aBuiltin[i].zName, (void*)pApi, diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 61d013ea4..370751666 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1181,7 +1181,7 @@ static void jsonTest1Func( #endif /* SQLITE_DEBUG */ /**************************************************************************** -** SQL function implementations +** Scalar SQL function implementations ****************************************************************************/ /* @@ -1514,6 +1514,102 @@ static void jsonValidFunc( sqlite3_result_int(ctx, rc); } + +/**************************************************************************** +** Aggregate SQL function implementations +****************************************************************************/ +/* +** json_group_array(VALUE) +** +** Return a JSON array composed of all values in the aggregate. +*/ +static void jsonArrayStep( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + JsonString *pStr; + pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr)); + if( pStr ){ + if( pStr->zBuf==0 ){ + jsonInit(pStr, ctx); + jsonAppendChar(pStr, '['); + }else{ + jsonAppendChar(pStr, ','); + pStr->pCtx = ctx; + } + jsonAppendValue(pStr, argv[0]); + } +} +static void jsonArrayFinal(sqlite3_context *ctx){ + JsonString *pStr; + pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); + if( pStr ){ + pStr->pCtx = ctx; + jsonAppendChar(pStr, ']'); + if( pStr->bErr ){ + sqlite3_result_error_nomem(ctx); + assert( pStr->bStatic ); + }else{ + sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed, + pStr->bStatic ? SQLITE_TRANSIENT : sqlite3_free); + pStr->bStatic = 1; + } + }else{ + sqlite3_result_text(ctx, "[]", 2, SQLITE_STATIC); + } + sqlite3_result_subtype(ctx, JSON_SUBTYPE); +} + +/* +** json_group_obj(NAME,VALUE) +** +** Return a JSON object composed of all names and values in the aggregate. +*/ +static void jsonObjectStep( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + JsonString *pStr; + const char *z; + u32 n; + pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr)); + if( pStr ){ + if( pStr->zBuf==0 ){ + jsonInit(pStr, ctx); + jsonAppendChar(pStr, '{'); + }else{ + jsonAppendChar(pStr, ','); + pStr->pCtx = ctx; + } + z = (const char*)sqlite3_value_text(argv[0]); + n = (u32)sqlite3_value_bytes(argv[0]); + jsonAppendString(pStr, z, n); + jsonAppendChar(pStr, ':'); + jsonAppendValue(pStr, argv[1]); + } +} +static void jsonObjectFinal(sqlite3_context *ctx){ + JsonString *pStr; + pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); + if( pStr ){ + jsonAppendChar(pStr, '}'); + if( pStr->bErr ){ + sqlite3_result_error_nomem(ctx); + assert( pStr->bStatic ); + }else{ + sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed, + pStr->bStatic ? SQLITE_TRANSIENT : sqlite3_free); + pStr->bStatic = 1; + } + }else{ + sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC); + } + sqlite3_result_subtype(ctx, JSON_SUBTYPE); +} + + #ifndef SQLITE_OMIT_VIRTUALTABLE /**************************************************************************** ** The json_each virtual table @@ -2012,6 +2108,15 @@ int sqlite3Json1Init(sqlite3 *db){ { "json_test1", 1, 0, jsonTest1Func }, #endif }; + static const struct { + const char *zName; + int nArg; + void (*xStep)(sqlite3_context*,int,sqlite3_value**); + void (*xFinal)(sqlite3_context*); + } aAgg[] = { + { "json_group_array", 1, jsonArrayStep, jsonArrayFinal }, + { "json_group_object", 2, jsonObjectStep, jsonObjectFinal }, + }; #ifndef SQLITE_OMIT_VIRTUALTABLE static const struct { const char *zName; @@ -2027,6 +2132,11 @@ int sqlite3Json1Init(sqlite3 *db){ (void*)&aFunc[i].flag, aFunc[i].xFunc, 0, 0); } + for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){ + rc = sqlite3_create_function(db, aAgg[i].zName, aAgg[i].nArg, + SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, + 0, aAgg[i].xStep, aAgg[i].xFinal); + } #ifndef SQLITE_OMIT_VIRTUALTABLE for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){ rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0); diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index 0515b7bc6..c0da6b339 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -1717,17 +1717,23 @@ static void scriptCodeSqlFunc( # define SCRIPT_LATIN 0x0001 # define SCRIPT_CYRILLIC 0x0002 # define SCRIPT_GREEK 0x0004 +# define SCRIPT_HEBREW 0x0008 +# define SCRIPT_ARABIC 0x0010 while( nIn>0 ){ c = utf8Read(zIn, nIn, &sz); zIn += sz; nIn -= sz; - if( c<0x02af ){ + if( c<0x02af && (c>=0x80 || midClass[c&0x7f]<CCLASS_DIGIT) ){ scriptMask |= SCRIPT_LATIN; }else if( c>=0x0400 && c<=0x04ff ){ scriptMask |= SCRIPT_CYRILLIC; }else if( c>=0x0386 && c<=0x03ce ){ scriptMask |= SCRIPT_GREEK; + }else if( c>=0x0590 && c<=0x05ff ){ + scriptMask |= SCRIPT_HEBREW; + }else if( c>=0x0600 && c<=0x06ff ){ + scriptMask |= SCRIPT_ARABIC; } } switch( scriptMask ){ @@ -1735,6 +1741,8 @@ static void scriptCodeSqlFunc( case SCRIPT_LATIN: res = 215; break; case SCRIPT_CYRILLIC: res = 220; break; case SCRIPT_GREEK: res = 200; break; + case SCRIPT_HEBREW: res = 125; break; + case SCRIPT_ARABIC: res = 160; break; default: res = 998; break; } sqlite3_result_int(context, res); |