mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 06:12:27 +00:00
Revert whitespace fixes to third_party (#501)
This commit is contained in:
parent
d4000bb8f7
commit
9de3d8f1e6
365 changed files with 39190 additions and 39211 deletions
132
third_party/sqlite3/alter.c
vendored
132
third_party/sqlite3/alter.c
vendored
|
@ -30,7 +30,7 @@
|
|||
** Or, if zName is not a system table, zero is returned.
|
||||
*/
|
||||
static int isAlterableTable(Parse *pParse, Table *pTab){
|
||||
if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
|
||||
if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|| ( (pTab->tabFlags & TF_Shadow)!=0
|
||||
&& sqlite3ReadOnlyShadowTables(pParse->db)
|
||||
|
@ -58,7 +58,7 @@ static void renameTestSchema(
|
|||
const char *zDropColumn /* Name of column being dropped */
|
||||
){
|
||||
pParse->colNamesSet = 1;
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"SELECT 1 "
|
||||
"FROM \"%w\"." DFLT_SCHEMA_TABLE " "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
|
@ -69,7 +69,7 @@ static void renameTestSchema(
|
|||
);
|
||||
|
||||
if( bTemp==0 ){
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"SELECT 1 "
|
||||
"FROM temp." DFLT_SCHEMA_TABLE " "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
|
@ -94,8 +94,8 @@ static void renameReloadSchema(Parse *pParse, int iDb, u16 p5){
|
|||
}
|
||||
|
||||
/*
|
||||
** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
|
||||
** command.
|
||||
** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
|
||||
** command.
|
||||
*/
|
||||
void sqlite3AlterRenameTable(
|
||||
Parse *pParse, /* Parser context. */
|
||||
|
@ -105,7 +105,7 @@ void sqlite3AlterRenameTable(
|
|||
int iDb; /* Database that contains the table */
|
||||
char *zDb; /* Name of database iDb */
|
||||
Table *pTab; /* Table being renamed */
|
||||
char *zName = 0; /* NULL-terminated version of pName */
|
||||
char *zName = 0; /* NULL-terminated version of pName */
|
||||
sqlite3 *db = pParse->db; /* Database connection */
|
||||
int nTabName; /* Number of UTF-8 characters in zTabName */
|
||||
const char *zTabName; /* Original name of the table */
|
||||
|
@ -113,7 +113,7 @@ void sqlite3AlterRenameTable(
|
|||
VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
|
||||
u32 savedDbFlags; /* Saved value of db->mDbFlags */
|
||||
|
||||
savedDbFlags = db->mDbFlags;
|
||||
savedDbFlags = db->mDbFlags;
|
||||
if( NEVER(db->mallocFailed) ) goto exit_rename_table;
|
||||
assert( pSrc->nSrc==1 );
|
||||
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
|
||||
|
@ -135,7 +135,7 @@ void sqlite3AlterRenameTable(
|
|||
|| sqlite3FindIndex(db, zName, zDb)
|
||||
|| sqlite3IsShadowTableOf(db, pTab, zName)
|
||||
){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"there is already another table or index with this name: %s", zName);
|
||||
goto exit_rename_table;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ void sqlite3AlterRenameTable(
|
|||
|
||||
/* Begin a transaction for database iDb. Then modify the schema cookie
|
||||
** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
|
||||
** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
|
||||
** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
|
||||
** nested SQL may raise an exception. */
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ){
|
||||
|
@ -192,7 +192,7 @@ void sqlite3AlterRenameTable(
|
|||
|
||||
/* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
|
||||
** the schema to use the new table name. */
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
|
||||
"WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
|
||||
|
@ -212,14 +212,14 @@ void sqlite3AlterRenameTable(
|
|||
"'sqlite_autoindex_' || %Q || substr(name,%d+18) "
|
||||
"ELSE name END "
|
||||
"WHERE tbl_name=%Q COLLATE nocase AND "
|
||||
"(type='table' OR type='index' OR type='trigger');",
|
||||
"(type='table' OR type='index' OR type='trigger');",
|
||||
zDb,
|
||||
zName, zName, zName,
|
||||
zName, zName, zName,
|
||||
nTabName, zTabName
|
||||
);
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
/* If the sqlite_sequence table exists in this database, then update
|
||||
/* If the sqlite_sequence table exists in this database, then update
|
||||
** it with the new table name.
|
||||
*/
|
||||
if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
|
||||
|
@ -230,10 +230,10 @@ void sqlite3AlterRenameTable(
|
|||
#endif
|
||||
|
||||
/* If the table being renamed is not itself part of the temp database,
|
||||
** edit view and trigger definitions within the temp database
|
||||
** edit view and trigger definitions within the temp database
|
||||
** as required. */
|
||||
if( iDb!=1 ){
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE sqlite_temp_schema SET "
|
||||
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
|
||||
"tbl_name = "
|
||||
|
@ -339,7 +339,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
|||
return;
|
||||
}
|
||||
if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){
|
||||
/* If the default value for the new column was specified with a
|
||||
/* If the default value for the new column was specified with a
|
||||
** literal NULL, then set pDflt to 0. This simplifies checking
|
||||
** for an SQL NULL default below.
|
||||
*/
|
||||
|
@ -391,11 +391,11 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
|||
db->mDbFlags |= DBFLAG_PreferBuiltin;
|
||||
/* substr() operations on characters, but addColOffset is in bytes. So we
|
||||
** have to use printf() to translate between these units: */
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = printf('%%.%ds, ',sql) || %Q"
|
||||
" || substr(sql,1+length(printf('%%.%ds',sql))) "
|
||||
"WHERE type = 'table' AND name = %Q",
|
||||
"WHERE type = 'table' AND name = %Q",
|
||||
zDb, pNew->addColOffset, zCol, pNew->addColOffset,
|
||||
zTab
|
||||
);
|
||||
|
@ -425,14 +425,14 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
|||
|
||||
/*
|
||||
** This function is called by the parser after the table-name in
|
||||
** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
|
||||
** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
|
||||
** pSrc is the full-name of the table being altered.
|
||||
**
|
||||
** This routine makes a (partial) copy of the Table structure
|
||||
** for the table being altered and sets Parse.pNewTable to point
|
||||
** to it. Routines called by the parser as the column definition
|
||||
** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
|
||||
** the copy. The copy of the Table structure is deleted by tokenize.c
|
||||
** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
|
||||
** the copy. The copy of the Table structure is deleted by tokenize.c
|
||||
** after parsing is finished.
|
||||
**
|
||||
** Routine sqlite3AlterFinishAddColumn() will be called to complete
|
||||
|
@ -533,7 +533,7 @@ static int isRealTable(Parse *pParse, Table *pTab, int bDrop){
|
|||
}
|
||||
#endif
|
||||
if( zType ){
|
||||
sqlite3ErrorMsg(pParse, "cannot %s %s \"%s\"",
|
||||
sqlite3ErrorMsg(pParse, "cannot %s %s \"%s\"",
|
||||
(bDrop ? "drop column from" : "rename columns of"),
|
||||
zType, pTab->zName
|
||||
);
|
||||
|
@ -573,7 +573,7 @@ void sqlite3AlterRenameColumn(
|
|||
if( SQLITE_OK!=isAlterableTable(pParse, pTab) ) goto exit_rename_column;
|
||||
if( SQLITE_OK!=isRealTable(pParse, pTab, 0) ) goto exit_rename_column;
|
||||
|
||||
/* Which schema holds the table to be altered */
|
||||
/* Which schema holds the table to be altered */
|
||||
iSchema = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iSchema>=0 );
|
||||
zDb = db->aDb[iSchema].zDbSName;
|
||||
|
@ -606,7 +606,7 @@ void sqlite3AlterRenameColumn(
|
|||
if( !zNew ) goto exit_rename_column;
|
||||
assert( pNew->n>0 );
|
||||
bQuote = sqlite3Isquote(pNew->z[0]);
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
|
||||
|
@ -617,7 +617,7 @@ void sqlite3AlterRenameColumn(
|
|||
pTab->zName
|
||||
);
|
||||
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE temp." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) "
|
||||
"WHERE type IN ('trigger', 'view')",
|
||||
|
@ -667,7 +667,7 @@ struct RenameCtx {
|
|||
RenameToken *pList; /* List of tokens to overwrite */
|
||||
int nList; /* Number of tokens in pList */
|
||||
int iCol; /* Index of column being renamed */
|
||||
Table *pTab; /* Table being ALTERed */
|
||||
Table *pTab; /* Table being ALTERed */
|
||||
const char *zOld; /* Old column name */
|
||||
};
|
||||
|
||||
|
@ -675,14 +675,14 @@ struct RenameCtx {
|
|||
/*
|
||||
** This function is only for debugging. It performs two tasks:
|
||||
**
|
||||
** 1. Checks that pointer pPtr does not already appear in the
|
||||
** 1. Checks that pointer pPtr does not already appear in the
|
||||
** rename-token list.
|
||||
**
|
||||
** 2. Dereferences each pointer in the rename-token list.
|
||||
**
|
||||
** The second is most effective when debugging under valgrind or
|
||||
** address-sanitizer or similar. If any of these pointers no longer
|
||||
** point to valid objects, an exception is raised by the memory-checking
|
||||
** address-sanitizer or similar. If any of these pointers no longer
|
||||
** point to valid objects, an exception is raised by the memory-checking
|
||||
** tool.
|
||||
**
|
||||
** The point of this is to prevent comparisons of invalid pointer values.
|
||||
|
@ -845,7 +845,7 @@ void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){
|
|||
}
|
||||
|
||||
/*
|
||||
** Remove all nodes that are part of expression-list pEList from the
|
||||
** Remove all nodes that are part of expression-list pEList from the
|
||||
** rename list.
|
||||
*/
|
||||
void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){
|
||||
|
@ -886,8 +886,8 @@ static void renameTokenFree(sqlite3 *db, RenameToken *pToken){
|
|||
** the list maintained by the RenameCtx object.
|
||||
*/
|
||||
static RenameToken *renameTokenFind(
|
||||
Parse *pParse,
|
||||
struct RenameCtx *pCtx,
|
||||
Parse *pParse,
|
||||
struct RenameCtx *pCtx,
|
||||
void *pPtr
|
||||
){
|
||||
RenameToken **pp;
|
||||
|
@ -929,13 +929,13 @@ static int renameColumnSelectCb(Walker *pWalker, Select *p){
|
|||
*/
|
||||
static int renameColumnExprCb(Walker *pWalker, Expr *pExpr){
|
||||
RenameCtx *p = pWalker->u.pRename;
|
||||
if( pExpr->op==TK_TRIGGER
|
||||
&& pExpr->iColumn==p->iCol
|
||||
if( pExpr->op==TK_TRIGGER
|
||||
&& pExpr->iColumn==p->iCol
|
||||
&& pWalker->pParse->pTriggerTab==p->pTab
|
||||
){
|
||||
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
|
||||
}else if( pExpr->op==TK_COLUMN
|
||||
&& pExpr->iColumn==p->iCol
|
||||
}else if( pExpr->op==TK_COLUMN
|
||||
&& pExpr->iColumn==p->iCol
|
||||
&& p->pTab==pExpr->y.pTab
|
||||
){
|
||||
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
|
||||
|
@ -974,7 +974,7 @@ static RenameToken *renameColumnTokenNext(RenameCtx *pCtx){
|
|||
** adds context to the error message and then stores it in pCtx.
|
||||
*/
|
||||
static void renameColumnParseError(
|
||||
sqlite3_context *pCtx,
|
||||
sqlite3_context *pCtx,
|
||||
const char *zWhen,
|
||||
sqlite3_value *pType,
|
||||
sqlite3_value *pObject,
|
||||
|
@ -984,7 +984,7 @@ static void renameColumnParseError(
|
|||
const char *zN = (const char*)sqlite3_value_text(pObject);
|
||||
char *zErr;
|
||||
|
||||
zErr = sqlite3_mprintf("error in %s %s%s%s: %s",
|
||||
zErr = sqlite3_mprintf("error in %s %s%s%s: %s",
|
||||
zT, zN, (zWhen[0] ? " " : ""), zWhen,
|
||||
pParse->zErrMsg
|
||||
);
|
||||
|
@ -994,14 +994,14 @@ static void renameColumnParseError(
|
|||
|
||||
/*
|
||||
** For each name in the the expression-list pEList (i.e. each
|
||||
** pEList->a[i].zName) that matches the string in zOld, extract the
|
||||
** pEList->a[i].zName) that matches the string in zOld, extract the
|
||||
** corresponding rename-token from Parse object pParse and add it
|
||||
** to the RenameCtx pCtx.
|
||||
*/
|
||||
static void renameColumnElistNames(
|
||||
Parse *pParse,
|
||||
RenameCtx *pCtx,
|
||||
ExprList *pEList,
|
||||
Parse *pParse,
|
||||
RenameCtx *pCtx,
|
||||
ExprList *pEList,
|
||||
const char *zOld
|
||||
){
|
||||
if( pEList ){
|
||||
|
@ -1019,14 +1019,14 @@ static void renameColumnElistNames(
|
|||
}
|
||||
|
||||
/*
|
||||
** For each name in the the id-list pIdList (i.e. each pIdList->a[i].zName)
|
||||
** that matches the string in zOld, extract the corresponding rename-token
|
||||
** For each name in the the id-list pIdList (i.e. each pIdList->a[i].zName)
|
||||
** that matches the string in zOld, extract the corresponding rename-token
|
||||
** from Parse object pParse and add it to the RenameCtx pCtx.
|
||||
*/
|
||||
static void renameColumnIdlistNames(
|
||||
Parse *pParse,
|
||||
RenameCtx *pCtx,
|
||||
IdList *pIdList,
|
||||
Parse *pParse,
|
||||
RenameCtx *pCtx,
|
||||
IdList *pIdList,
|
||||
const char *zOld
|
||||
){
|
||||
if( pIdList ){
|
||||
|
@ -1074,8 +1074,8 @@ static int renameParseSql(
|
|||
assert( rc!=SQLITE_OK || zErr==0 );
|
||||
p->zErrMsg = zErr;
|
||||
if( db->mallocFailed ) rc = SQLITE_NOMEM;
|
||||
if( rc==SQLITE_OK
|
||||
&& p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0
|
||||
if( rc==SQLITE_OK
|
||||
&& p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0
|
||||
){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
@ -1121,8 +1121,8 @@ static int renameEditSql(
|
|||
char *zOut;
|
||||
int nQuot;
|
||||
|
||||
/* Set zQuot to point to a buffer containing a quoted copy of the
|
||||
** identifier zNew. If the corresponding identifier in the original
|
||||
/* Set zQuot to point to a buffer containing a quoted copy of the
|
||||
** identifier zNew. If the corresponding identifier in the original
|
||||
** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
|
||||
** point to zQuot so that all substitutions are made using the
|
||||
** quoted version of the new column name. */
|
||||
|
@ -1162,7 +1162,7 @@ static int renameEditSql(
|
|||
|
||||
iOff = pBest->t.z - zSql;
|
||||
if( pBest->t.n!=nReplace ){
|
||||
memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n],
|
||||
memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n],
|
||||
nOut - (iOff + pBest->t.n)
|
||||
);
|
||||
nOut += nReplace - pBest->t.n;
|
||||
|
@ -1184,7 +1184,7 @@ static int renameEditSql(
|
|||
|
||||
/*
|
||||
** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
|
||||
** it was read from the schema of database zDb. Return SQLITE_OK if
|
||||
** it was read from the schema of database zDb. Return SQLITE_OK if
|
||||
** successful. Otherwise, return an SQLite error code and leave an error
|
||||
** message in the Parse object.
|
||||
*/
|
||||
|
@ -1198,7 +1198,7 @@ static int renameResolveTrigger(Parse *pParse){
|
|||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
assert( pNew->pTabSchema );
|
||||
pParse->pTriggerTab = sqlite3FindTable(db, pNew->table,
|
||||
pParse->pTriggerTab = sqlite3FindTable(db, pNew->table,
|
||||
db->aDb[sqlite3SchemaToIndex(db, pNew->pTabSchema)].zDbSName
|
||||
);
|
||||
pParse->eTriggerOp = pNew->op;
|
||||
|
@ -1467,7 +1467,7 @@ static void renameColumnFunc(
|
|||
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
|
||||
|
||||
for(pStep=sParse.pNewTrigger->step_list; pStep; pStep=pStep->pNext){
|
||||
if( pStep->zTarget ){
|
||||
if( pStep->zTarget ){
|
||||
Table *pTarget = sqlite3LocateTable(&sParse, 0, pStep->zTarget, zDb);
|
||||
if( pTarget==pTab ){
|
||||
if( pStep->pUpsert ){
|
||||
|
@ -1511,7 +1511,7 @@ renameColumnFunc_done:
|
|||
}
|
||||
|
||||
/*
|
||||
** Walker expression callback used by "RENAME TABLE".
|
||||
** Walker expression callback used by "RENAME TABLE".
|
||||
*/
|
||||
static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
|
||||
RenameCtx *p = pWalker->u.pRename;
|
||||
|
@ -1522,7 +1522,7 @@ static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
|
|||
}
|
||||
|
||||
/*
|
||||
** Walker select callback used by "RENAME TABLE".
|
||||
** Walker select callback used by "RENAME TABLE".
|
||||
*/
|
||||
static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
|
||||
int i;
|
||||
|
@ -1548,7 +1548,7 @@ static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
|
|||
/*
|
||||
** This C function implements an SQL user function that is used by SQL code
|
||||
** generated by the ALTER TABLE ... RENAME command to modify the definition
|
||||
** of any foreign key constraints that use the table being renamed as the
|
||||
** of any foreign key constraints that use the table being renamed as the
|
||||
** parent table. It is passed three arguments:
|
||||
**
|
||||
** 0: The database containing the table being renamed.
|
||||
|
@ -1659,7 +1659,7 @@ static void renameTableFunc(
|
|||
else{
|
||||
Trigger *pTrigger = sParse.pNewTrigger;
|
||||
TriggerStep *pStep;
|
||||
if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld)
|
||||
if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld)
|
||||
&& sCtx.pTab->pSchema==pTrigger->pTabSchema
|
||||
){
|
||||
renameTokenFind(&sParse, &sCtx, sParse.pNewTrigger->table);
|
||||
|
@ -1780,7 +1780,7 @@ static void renameTableTest(
|
|||
|
||||
/*
|
||||
** The implementation of internal UDF sqlite_drop_column().
|
||||
**
|
||||
**
|
||||
** Arguments:
|
||||
**
|
||||
** argv[0]: An integer - the index of the schema containing the table
|
||||
|
@ -1816,7 +1816,7 @@ static void dropColumnFunc(
|
|||
rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1, 0);
|
||||
if( rc!=SQLITE_OK ) goto drop_column_done;
|
||||
pTab = sParse.pNewTable;
|
||||
if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
|
||||
if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
|
||||
/* This can happen if the sqlite_schema table is corrupt */
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto drop_column_done;
|
||||
|
@ -1847,7 +1847,7 @@ drop_column_done:
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is called by the parser upon parsing an
|
||||
** This function is called by the parser upon parsing an
|
||||
**
|
||||
** ALTER TABLE pSrc DROP COLUMN pName
|
||||
**
|
||||
|
@ -1869,7 +1869,7 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, Token *pName){
|
|||
pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
|
||||
if( !pTab ) goto exit_drop_column;
|
||||
|
||||
/* Make sure this is not an attempt to ALTER a view, virtual table or
|
||||
/* Make sure this is not an attempt to ALTER a view, virtual table or
|
||||
** system table. */
|
||||
if( SQLITE_OK!=isAlterableTable(pParse, pTab) ) goto exit_drop_column;
|
||||
if( SQLITE_OK!=isRealTable(pParse, pTab, 1) ) goto exit_drop_column;
|
||||
|
@ -1886,10 +1886,10 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, Token *pName){
|
|||
goto exit_drop_column;
|
||||
}
|
||||
|
||||
/* Do not allow the user to drop a PRIMARY KEY column or a column
|
||||
/* Do not allow the user to drop a PRIMARY KEY column or a column
|
||||
** constrained by a UNIQUE constraint. */
|
||||
if( pTab->aCol[iCol].colFlags & (COLFLAG_PRIMKEY|COLFLAG_UNIQUE) ){
|
||||
sqlite3ErrorMsg(pParse, "cannot drop %s column: \"%s\"",
|
||||
sqlite3ErrorMsg(pParse, "cannot drop %s column: \"%s\"",
|
||||
(pTab->aCol[iCol].colFlags&COLFLAG_PRIMKEY) ? "PRIMARY KEY" : "UNIQUE",
|
||||
zCol
|
||||
);
|
||||
|
@ -1907,7 +1907,7 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, Token *pName){
|
|||
assert( iDb>=0 );
|
||||
zDb = db->aDb[iDb].zDbSName;
|
||||
renameTestSchema(pParse, zDb, iDb==1, "", 0);
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_drop_column(%d, sql, %d) "
|
||||
"WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
|
||||
|
|
104
third_party/sqlite3/analyze.c
vendored
104
third_party/sqlite3/analyze.c
vendored
|
@ -209,9 +209,9 @@ static void openStatTable(
|
|||
aCreateTbl[i] = 0;
|
||||
if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
|
||||
if( i<nToOpen ){
|
||||
/* The sqlite_statN table does not exist. Create it. Note that a
|
||||
** side-effect of the CREATE TABLE statement is to leave the rootpage
|
||||
** of the new table in register pParse->regRoot. This is important
|
||||
/* The sqlite_statN table does not exist. Create it. Note that a
|
||||
** side-effect of the CREATE TABLE statement is to leave the rootpage
|
||||
** of the new table in register pParse->regRoot. This is important
|
||||
** because the OpenWrite opcode below will be needing it. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
|
||||
|
@ -220,7 +220,7 @@ static void openStatTable(
|
|||
aCreateTbl[i] = OPFLAG_P2ISREG;
|
||||
}
|
||||
}else{
|
||||
/* The table already exists. If zWhere is not NULL, delete all entries
|
||||
/* The table already exists. If zWhere is not NULL, delete all entries
|
||||
** associated with the table zWhere. If zWhere is NULL, delete the
|
||||
** entire contents of the table. */
|
||||
aRoot[i] = pStat->tnum;
|
||||
|
@ -278,7 +278,7 @@ struct StatSample {
|
|||
int iCol; /* If !isPSample, the reason for inclusion */
|
||||
u32 iHash; /* Tiebreaker hash */
|
||||
#endif
|
||||
};
|
||||
};
|
||||
struct StatAccum {
|
||||
sqlite3 *db; /* Database connection, for malloc() */
|
||||
tRowcnt nEst; /* Estimated number of rows */
|
||||
|
@ -382,7 +382,7 @@ static void statAccumDestructor(void *pOld){
|
|||
** N: The number of columns in the index including the rowid/pk (note 1)
|
||||
** K: The number of columns in the index excluding the rowid/pk.
|
||||
** C: Estimated number of rows in the index
|
||||
** L: A limit on the number of rows to scan, or 0 for no-limit
|
||||
** L: A limit on the number of rows to scan, or 0 for no-limit
|
||||
**
|
||||
** Note 1: In the special case of the covering index that implements a
|
||||
** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
|
||||
|
@ -393,7 +393,7 @@ static void statAccumDestructor(void *pOld){
|
|||
** PRIMARY KEY of the table. The covering index that implements the
|
||||
** original WITHOUT ROWID table as N==K as a special case.
|
||||
**
|
||||
** This routine allocates the StatAccum object in heap memory. The return
|
||||
** This routine allocates the StatAccum object in heap memory. The return
|
||||
** value is a pointer to the StatAccum object. The datatype of the
|
||||
** return value is BLOB, but it is really just a pointer to the StatAccum
|
||||
** object.
|
||||
|
@ -424,7 +424,7 @@ static void statInit(
|
|||
assert( nKeyCol>0 );
|
||||
|
||||
/* Allocate the space required for the StatAccum object */
|
||||
n = sizeof(*p)
|
||||
n = sizeof(*p)
|
||||
+ sizeof(tRowcnt)*nColUp /* StatAccum.anEq */
|
||||
+ sizeof(tRowcnt)*nColUp; /* StatAccum.anDLt */
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
|
@ -461,7 +461,7 @@ static void statInit(
|
|||
p->nPSample = (tRowcnt)(p->nEst/(mxSample/3+1) + 1);
|
||||
p->current.anLt = &p->current.anEq[nColUp];
|
||||
p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
|
||||
|
||||
|
||||
/* Set up the StatAccum.a[] and aBest[] arrays */
|
||||
p->a = (struct StatSample*)&p->current.anLt[nColUp];
|
||||
p->aBest = &p->a[mxSample];
|
||||
|
@ -472,7 +472,7 @@ static void statInit(
|
|||
p->a[i].anDLt = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp);
|
||||
}
|
||||
assert( (pSpace - (u8*)p)==n );
|
||||
|
||||
|
||||
for(i=0; i<nCol; i++){
|
||||
p->aBest[i].iCol = i;
|
||||
}
|
||||
|
@ -499,19 +499,19 @@ static const FuncDef statInitFuncdef = {
|
|||
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
/*
|
||||
** pNew and pOld are both candidate non-periodic samples selected for
|
||||
** the same column (pNew->iCol==pOld->iCol). Ignoring this column and
|
||||
** pNew and pOld are both candidate non-periodic samples selected for
|
||||
** the same column (pNew->iCol==pOld->iCol). Ignoring this column and
|
||||
** considering only any trailing columns and the sample hash value, this
|
||||
** function returns true if sample pNew is to be preferred over pOld.
|
||||
** In other words, if we assume that the cardinalities of the selected
|
||||
** column for pNew and pOld are equal, is pNew to be preferred over pOld.
|
||||
**
|
||||
** This function assumes that for each argument sample, the contents of
|
||||
** the anEq[] array from pSample->anEq[pSample->iCol+1] onwards are valid.
|
||||
** the anEq[] array from pSample->anEq[pSample->iCol+1] onwards are valid.
|
||||
*/
|
||||
static int sampleIsBetterPost(
|
||||
StatAccum *pAccum,
|
||||
StatSample *pNew,
|
||||
StatAccum *pAccum,
|
||||
StatSample *pNew,
|
||||
StatSample *pOld
|
||||
){
|
||||
int nCol = pAccum->nCol;
|
||||
|
@ -531,11 +531,11 @@ static int sampleIsBetterPost(
|
|||
** Return true if pNew is to be preferred over pOld.
|
||||
**
|
||||
** This function assumes that for each argument sample, the contents of
|
||||
** the anEq[] array from pSample->anEq[pSample->iCol] onwards are valid.
|
||||
** the anEq[] array from pSample->anEq[pSample->iCol] onwards are valid.
|
||||
*/
|
||||
static int sampleIsBetter(
|
||||
StatAccum *pAccum,
|
||||
StatSample *pNew,
|
||||
StatAccum *pAccum,
|
||||
StatSample *pNew,
|
||||
StatSample *pOld
|
||||
){
|
||||
tRowcnt nEqNew = pNew->anEq[pNew->iCol];
|
||||
|
@ -573,7 +573,7 @@ static void sampleInsert(StatAccum *p, StatSample *pNew, int nEqZero){
|
|||
StatSample *pUpgrade = 0;
|
||||
assert( pNew->anEq[pNew->iCol]>0 );
|
||||
|
||||
/* This sample is being added because the prefix that ends in column
|
||||
/* This sample is being added because the prefix that ends in column
|
||||
** iCol occurs many times in the table. However, if we have already
|
||||
** added a sample that shares this prefix, there is no need to add
|
||||
** this one. Instead, upgrade the priority of the highest priority
|
||||
|
@ -615,7 +615,7 @@ static void sampleInsert(StatAccum *p, StatSample *pNew, int nEqZero){
|
|||
/* The "rows less-than" for the rowid column must be greater than that
|
||||
** for the last sample in the p->a[] array. Otherwise, the samples would
|
||||
** be out of order. */
|
||||
assert( p->nSample==0
|
||||
assert( p->nSample==0
|
||||
|| pNew->anLt[p->nCol-1] > p->a[p->nSample-1].anLt[p->nCol-1] );
|
||||
|
||||
/* Insert the new sample */
|
||||
|
@ -822,9 +822,9 @@ static void statGet(
|
|||
/* STAT4 has a parameter on this routine. */
|
||||
int eCall = sqlite3_value_int(argv[1]);
|
||||
assert( argc==2 );
|
||||
assert( eCall==STAT_GET_STAT1 || eCall==STAT_GET_NEQ
|
||||
assert( eCall==STAT_GET_STAT1 || eCall==STAT_GET_NEQ
|
||||
|| eCall==STAT_GET_ROWID || eCall==STAT_GET_NLT
|
||||
|| eCall==STAT_GET_NDLT
|
||||
|| eCall==STAT_GET_NDLT
|
||||
);
|
||||
assert( eCall==STAT_GET_STAT1 || p->mxSample );
|
||||
if( eCall==STAT_GET_STAT1 )
|
||||
|
@ -835,20 +835,20 @@ static void statGet(
|
|||
/* Return the value to store in the "stat" column of the sqlite_stat1
|
||||
** table for this index.
|
||||
**
|
||||
** The value is a string composed of a list of integers describing
|
||||
** the index. The first integer in the list is the total number of
|
||||
** entries in the index. There is one additional integer in the list
|
||||
** The value is a string composed of a list of integers describing
|
||||
** the index. The first integer in the list is the total number of
|
||||
** entries in the index. There is one additional integer in the list
|
||||
** for each indexed column. This additional integer is an estimate of
|
||||
** the number of rows matched by a equality query on the index using
|
||||
** a key with the corresponding number of fields. In other words,
|
||||
** if the index is on columns (a,b) and the sqlite_stat1 value is
|
||||
** if the index is on columns (a,b) and the sqlite_stat1 value is
|
||||
** "100 10 2", then SQLite estimates that:
|
||||
**
|
||||
** * the index contains 100 rows,
|
||||
** * "WHERE a=?" matches 10 rows, and
|
||||
** * "WHERE a=? AND b=?" matches 2 rows.
|
||||
**
|
||||
** If D is the count of distinct values and K is the total number of
|
||||
** If D is the count of distinct values and K is the total number of
|
||||
** rows, then each estimate is computed as:
|
||||
**
|
||||
** I = (K+D-1)/D
|
||||
|
@ -862,7 +862,7 @@ static void statGet(
|
|||
return;
|
||||
}
|
||||
|
||||
sqlite3_snprintf(24, zRet, "%llu",
|
||||
sqlite3_snprintf(24, zRet, "%llu",
|
||||
p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
|
||||
z = zRet + sqlite3Strlen30(zRet);
|
||||
for(i=0; i<p->nKeyCol; i++){
|
||||
|
@ -899,7 +899,7 @@ static void statGet(
|
|||
case STAT_GET_NEQ: aCnt = p->a[p->iGet].anEq; break;
|
||||
case STAT_GET_NLT: aCnt = p->a[p->iGet].anLt; break;
|
||||
default: {
|
||||
aCnt = p->a[p->iGet].anDLt;
|
||||
aCnt = p->a[p->iGet].anDLt;
|
||||
p->iGet++;
|
||||
break;
|
||||
}
|
||||
|
@ -1008,7 +1008,7 @@ static void analyzeOneTable(
|
|||
int regStat1 = iMem++; /* Value for the stat column of sqlite_stat1 */
|
||||
int regPrev = iMem; /* MUST BE LAST (see below) */
|
||||
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
Table *pStat1 = 0;
|
||||
Table *pStat1 = 0;
|
||||
#endif
|
||||
|
||||
pParse->nMem = MAX(pParse->nMem, iMem);
|
||||
|
@ -1047,7 +1047,7 @@ static void analyzeOneTable(
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Establish a read-lock on the table at the shared-cache level.
|
||||
/* Establish a read-lock on the table at the shared-cache level.
|
||||
** Open a read-only cursor on the table. Also allocate a cursor number
|
||||
** to use for scanning indexes (iIdxCur). No index cursor is opened at
|
||||
** this time though. */
|
||||
|
@ -1113,9 +1113,9 @@ static void analyzeOneTable(
|
|||
** end_of_scan:
|
||||
*/
|
||||
|
||||
/* Make sure there are enough memory cells allocated to accommodate
|
||||
/* Make sure there are enough memory cells allocated to accommodate
|
||||
** the regPrev array and a trailing rowid (the rowid slot is required
|
||||
** when building a record to insert into the sample column of
|
||||
** when building a record to insert into the sample column of
|
||||
** the sqlite_stat4 table. */
|
||||
pParse->nMem = MAX(pParse->nMem, regPrev+nColTest);
|
||||
|
||||
|
@ -1126,7 +1126,7 @@ static void analyzeOneTable(
|
|||
VdbeComment((v, "%s", pIdx->zName));
|
||||
|
||||
/* Invoke the stat_init() function. The arguments are:
|
||||
**
|
||||
**
|
||||
** (1) the number of columns in the index including the rowid
|
||||
** (or for a WITHOUT ROWID table, the number of PK columns),
|
||||
** (2) the number of columns in the key without the rowid/pk
|
||||
|
@ -1183,7 +1183,7 @@ static void analyzeOneTable(
|
|||
addrNextRow = sqlite3VdbeCurrentAddr(v);
|
||||
if( nColTest==1 && pIdx->nKeyCol==1 && IsUniqueIndex(pIdx) ){
|
||||
/* For a single-column UNIQUE index, once we have found a non-NULL
|
||||
** row, we know that all the rest will be distinct, so skip
|
||||
** row, we know that all the rest will be distinct, so skip
|
||||
** subsequent distinctness tests. */
|
||||
sqlite3VdbeAddOp2(v, OP_NotNull, regPrev, endDistinctTest);
|
||||
VdbeCoverage(v);
|
||||
|
@ -1193,15 +1193,15 @@ static void analyzeOneTable(
|
|||
sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
|
||||
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
|
||||
analyzeVdbeCommentIndexWithColumnName(v,pIdx,i);
|
||||
aGotoChng[i] =
|
||||
aGotoChng[i] =
|
||||
sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
|
||||
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
|
||||
VdbeCoverage(v);
|
||||
}
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
|
||||
sqlite3VdbeGoto(v, endDistinctTest);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** chng_addr_0:
|
||||
** regPrev(0) = idx(0)
|
||||
|
@ -1218,7 +1218,7 @@ static void analyzeOneTable(
|
|||
sqlite3VdbeResolveLabel(v, endDistinctTest);
|
||||
sqlite3DbFree(db, aGotoChng);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** chng_addr_N:
|
||||
** regRowid = idx(rowid) // STAT4 only
|
||||
|
@ -1537,7 +1537,7 @@ static void decodeIntArray(
|
|||
|
||||
/*
|
||||
** This callback is invoked once for each index when reading the
|
||||
** sqlite_stat1 table.
|
||||
** sqlite_stat1 table.
|
||||
**
|
||||
** argv[0] = name of the table
|
||||
** argv[1] = name of the index (might be NULL)
|
||||
|
@ -1575,7 +1575,7 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
|
|||
tRowcnt *aiRowEst = 0;
|
||||
int nCol = pIndex->nKeyCol+1;
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
/* Index.aiRowEst may already be set here if there are duplicate
|
||||
/* Index.aiRowEst may already be set here if there are duplicate
|
||||
** sqlite_stat1 entries for this index. In that case just clobber
|
||||
** the old data with the new instead of allocating a new array. */
|
||||
if( pIndex->aiRowEst==0 ){
|
||||
|
@ -1632,7 +1632,7 @@ void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
|
|||
#ifdef SQLITE_ENABLE_STAT4
|
||||
/*
|
||||
** Populate the pIdx->aAvgEq[] array based on the samples currently
|
||||
** stored in pIdx->aSample[].
|
||||
** stored in pIdx->aSample[].
|
||||
*/
|
||||
static void initAvgEq(Index *pIdx){
|
||||
if( pIdx ){
|
||||
|
@ -1668,12 +1668,12 @@ static void initAvgEq(Index *pIdx){
|
|||
pIdx->nRowEst0 = nRow;
|
||||
|
||||
/* Set nSum to the number of distinct (iCol+1) field prefixes that
|
||||
** occur in the stat4 table for this index. Set sumEq to the sum of
|
||||
** the nEq values for column iCol for the same set (adding the value
|
||||
** occur in the stat4 table for this index. Set sumEq to the sum of
|
||||
** the nEq values for column iCol for the same set (adding the value
|
||||
** only once where there exist duplicate prefixes). */
|
||||
for(i=0; i<nSample; i++){
|
||||
if( i==(pIdx->nSample-1)
|
||||
|| aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol]
|
||||
|| aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol]
|
||||
){
|
||||
sumEq += aSample[i].anEq[iCol];
|
||||
nSum100 += 100;
|
||||
|
@ -1801,7 +1801,7 @@ static int loadStatTbl(
|
|||
if( zIndex==0 ) continue;
|
||||
pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
|
||||
if( pIdx==0 ) continue;
|
||||
/* This next condition is true if data has already been loaded from
|
||||
/* This next condition is true if data has already been loaded from
|
||||
** the sqlite_stat4 table. */
|
||||
nCol = pIdx->nSampleCol;
|
||||
if( pIdx!=pPrevIdx ){
|
||||
|
@ -1836,7 +1836,7 @@ static int loadStatTbl(
|
|||
}
|
||||
|
||||
/*
|
||||
** Load content from the sqlite_stat4 table into
|
||||
** Load content from the sqlite_stat4 table into
|
||||
** the Index.aSample[] arrays of all indices.
|
||||
*/
|
||||
static int loadStat4(sqlite3 *db, const char *zDb){
|
||||
|
@ -1845,7 +1845,7 @@ static int loadStat4(sqlite3 *db, const char *zDb){
|
|||
assert( db->lookaside.bDisable );
|
||||
if( sqlite3FindTable(db, "sqlite_stat4", zDb) ){
|
||||
rc = loadStatTbl(db,
|
||||
"SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx",
|
||||
"SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx",
|
||||
"SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4",
|
||||
zDb
|
||||
);
|
||||
|
@ -1861,11 +1861,11 @@ static int loadStat4(sqlite3 *db, const char *zDb){
|
|||
** Index.aSample[] arrays.
|
||||
**
|
||||
** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
|
||||
** is returned. In this case, even if SQLITE_ENABLE_STAT4 was defined
|
||||
** during compilation and the sqlite_stat4 table is present, no data is
|
||||
** is returned. In this case, even if SQLITE_ENABLE_STAT4 was defined
|
||||
** during compilation and the sqlite_stat4 table is present, no data is
|
||||
** read from it.
|
||||
**
|
||||
** If SQLITE_ENABLE_STAT4 was defined during compilation and the
|
||||
** If SQLITE_ENABLE_STAT4 was defined during compilation and the
|
||||
** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
|
||||
** returned. However, in this case, data is read from the sqlite_stat1
|
||||
** table (if it is present) before returning.
|
||||
|
@ -1903,7 +1903,7 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
|
|||
sInfo.db = db;
|
||||
sInfo.zDatabase = db->aDb[iDb].zDbSName;
|
||||
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
|
||||
zSql = sqlite3MPrintf(db,
|
||||
zSql = sqlite3MPrintf(db,
|
||||
"SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
|
||||
if( zSql==0 ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
|
|
30
third_party/sqlite3/appendvfs.c
vendored
30
third_party/sqlite3/appendvfs.c
vendored
|
@ -182,7 +182,7 @@ static sqlite3_vfs apnd_vfs = {
|
|||
1024, /* mxPathname */
|
||||
0, /* pNext */
|
||||
"apndvfs", /* zName */
|
||||
0, /* pAppData (set when registered) */
|
||||
0, /* pAppData (set when registered) */
|
||||
apndOpen, /* xOpen */
|
||||
apndDelete, /* xDelete */
|
||||
apndAccess, /* xAccess */
|
||||
|
@ -235,9 +235,9 @@ static int apndClose(sqlite3_file *pFile){
|
|||
** Read data from an apnd-file.
|
||||
*/
|
||||
static int apndRead(
|
||||
sqlite3_file *pFile,
|
||||
void *zBuf,
|
||||
int iAmt,
|
||||
sqlite3_file *pFile,
|
||||
void *zBuf,
|
||||
int iAmt,
|
||||
sqlite_int64 iOfst
|
||||
){
|
||||
ApndFile *paf = (ApndFile *)pFile;
|
||||
|
@ -540,7 +540,7 @@ static int apndOpen(
|
|||
}
|
||||
if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
|
||||
/* The file being opened appears to be just an ordinary DB. Copy
|
||||
** the base dispatch-table so this instance mimics the base VFS.
|
||||
** the base dispatch-table so this instance mimics the base VFS.
|
||||
*/
|
||||
memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
|
||||
return SQLITE_OK;
|
||||
|
@ -555,7 +555,7 @@ static int apndOpen(
|
|||
rc = SQLITE_CANTOPEN;
|
||||
pFile->pMethods = 0;
|
||||
}else{
|
||||
/* Round newly added appendvfs location to #define'd page boundary.
|
||||
/* Round newly added appendvfs location to #define'd page boundary.
|
||||
** Note that nothing has yet been written to the underlying file.
|
||||
** The append mark will be written along with first content write.
|
||||
** Until then, paf->iMark value indicates it is not yet written.
|
||||
|
@ -579,18 +579,18 @@ static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
|
|||
** All other VFS methods are pass-thrus.
|
||||
*/
|
||||
static int apndAccess(
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int flags,
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int flags,
|
||||
int *pResOut
|
||||
){
|
||||
return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
|
||||
}
|
||||
|
||||
static int apndFullPathname(
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int nOut,
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int nOut,
|
||||
char *zOut
|
||||
){
|
||||
return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
|
||||
|
@ -651,13 +651,13 @@ static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
|
|||
return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** This routine is called when the extension is loaded.
|
||||
** Register the new VFS.
|
||||
*/
|
||||
int sqlite3_appendvfs_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
|
|
20
third_party/sqlite3/attach.c
vendored
20
third_party/sqlite3/attach.c
vendored
|
@ -123,7 +123,7 @@ static void attachFunc(
|
|||
** * Specified database name already being used.
|
||||
*/
|
||||
if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
|
||||
zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
|
||||
zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
|
||||
db->aLimit[SQLITE_LIMIT_ATTACHED]
|
||||
);
|
||||
goto attach_error;
|
||||
|
@ -135,7 +135,7 @@ static void attachFunc(
|
|||
goto attach_error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Allocate the new entry in the db->aDb[] array and initialize the schema
|
||||
** hash tables.
|
||||
*/
|
||||
|
@ -150,7 +150,7 @@ static void attachFunc(
|
|||
db->aDb = aNew;
|
||||
pNew = &db->aDb[db->nDb];
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
|
||||
|
||||
/* Open the database file. If the btree is successfully opened, use
|
||||
** it to obtain the database schema. At this point the schema may
|
||||
** or may not be initialized.
|
||||
|
@ -179,7 +179,7 @@ static void attachFunc(
|
|||
if( !pNew->pSchema ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
}else if( pNew->pSchema->file_format && pNew->pSchema->enc!=ENC(db) ){
|
||||
zErrDyn = sqlite3MPrintf(db,
|
||||
zErrDyn = sqlite3MPrintf(db,
|
||||
"attached databases must use the same text encoding as main database");
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ static void attachFunc(
|
|||
sqlite3_free_filename( zPath );
|
||||
|
||||
/* If the file was opened successfully, read the schema for the new database.
|
||||
** If this fails, or if opening the file failed, then close the file and
|
||||
** If this fails, or if opening the file failed, then close the file and
|
||||
** remove the entry from the db->aDb[] array. i.e. put everything back the
|
||||
** way we found it.
|
||||
*/
|
||||
|
@ -245,7 +245,7 @@ static void attachFunc(
|
|||
}
|
||||
goto attach_error;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
|
||||
attach_error:
|
||||
|
@ -346,7 +346,7 @@ static void codeAttach(
|
|||
memset(&sName, 0, sizeof(NameContext));
|
||||
sName.pParse = pParse;
|
||||
|
||||
if(
|
||||
if(
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
|
||||
|
@ -386,7 +386,7 @@ static void codeAttach(
|
|||
*/
|
||||
sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));
|
||||
}
|
||||
|
||||
|
||||
attach_end:
|
||||
sqlite3ExprDelete(db, pFilename);
|
||||
sqlite3ExprDelete(db, pDbname);
|
||||
|
@ -538,7 +538,7 @@ int sqlite3FixSrcList(
|
|||
){
|
||||
int res = 0;
|
||||
if( pList ){
|
||||
Select s;
|
||||
Select s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
s.pSrc = pList;
|
||||
res = sqlite3WalkSelect(&pFix->w, &s);
|
||||
|
@ -567,7 +567,7 @@ int sqlite3FixTriggerStep(
|
|||
){
|
||||
while( pStep ){
|
||||
if( sqlite3WalkSelect(&pFix->w, pStep->pSelect)
|
||||
|| sqlite3WalkExpr(&pFix->w, pStep->pWhere)
|
||||
|| sqlite3WalkExpr(&pFix->w, pStep->pWhere)
|
||||
|| sqlite3WalkExprList(&pFix->w, pStep->pExprList)
|
||||
|| sqlite3FixSrcList(pFix, pStep->pFrom)
|
||||
){
|
||||
|
|
6
third_party/sqlite3/auth.c
vendored
6
third_party/sqlite3/auth.c
vendored
|
@ -131,10 +131,10 @@ int sqlite3AuthReadCol(
|
|||
|
||||
/*
|
||||
** The pExpr should be a TK_COLUMN expression. The table referred to
|
||||
** is in pTabList or else it is the NEW or OLD table of a trigger.
|
||||
** is in pTabList or else it is the NEW or OLD table of a trigger.
|
||||
** Check to see if it is OK to read this particular column.
|
||||
**
|
||||
** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
|
||||
** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
|
||||
** instruction into a TK_NULL. If the auth function returns SQLITE_DENY,
|
||||
** then generate an error.
|
||||
*/
|
||||
|
@ -246,7 +246,7 @@ int sqlite3AuthCheck(
|
|||
*/
|
||||
void sqlite3AuthContextPush(
|
||||
Parse *pParse,
|
||||
AuthContext *pContext,
|
||||
AuthContext *pContext,
|
||||
const char *zContext
|
||||
){
|
||||
assert( pParse );
|
||||
|
|
76
third_party/sqlite3/backup.c
vendored
76
third_party/sqlite3/backup.c
vendored
|
@ -47,15 +47,15 @@ struct sqlite3_backup {
|
|||
** Once it has been created using backup_init(), a single sqlite3_backup
|
||||
** structure may be accessed via two groups of thread-safe entry points:
|
||||
**
|
||||
** * Via the sqlite3_backup_XXX() API function backup_step() and
|
||||
** * Via the sqlite3_backup_XXX() API function backup_step() and
|
||||
** backup_finish(). Both these functions obtain the source database
|
||||
** handle mutex and the mutex associated with the source BtShared
|
||||
** handle mutex and the mutex associated with the source BtShared
|
||||
** structure, in that order.
|
||||
**
|
||||
** * Via the BackupUpdate() and BackupRestart() functions, which are
|
||||
** invoked by the pager layer to report various state changes in
|
||||
** the page cache associated with the source database. The mutex
|
||||
** associated with the source database BtShared structure will always
|
||||
** associated with the source database BtShared structure will always
|
||||
** be held when either of these functions are invoked.
|
||||
**
|
||||
** The other sqlite3_backup_XXX() API functions, backup_remaining() and
|
||||
|
@ -76,8 +76,8 @@ struct sqlite3_backup {
|
|||
** in connection handle pDb. If such a database cannot be found, return
|
||||
** a NULL pointer and write an error message to pErrorDb.
|
||||
**
|
||||
** If the "temp" database is requested, it may need to be opened by this
|
||||
** function. If an error occurs while doing so, return 0 and write an
|
||||
** If the "temp" database is requested, it may need to be opened by this
|
||||
** function. If an error occurs while doing so, return 0 and write an
|
||||
** error message to pErrorDb.
|
||||
*/
|
||||
static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
|
||||
|
@ -120,7 +120,7 @@ static int setDestPgsz(sqlite3_backup *p){
|
|||
/*
|
||||
** Check that there is no open read-transaction on the b-tree passed as the
|
||||
** second argument. If there is not, return SQLITE_OK. Otherwise, if there
|
||||
** is an open read-transaction, return SQLITE_ERROR and leave an error
|
||||
** is an open read-transaction, return SQLITE_ERROR and leave an error
|
||||
** message in database handle db.
|
||||
*/
|
||||
static int checkReadTransaction(sqlite3 *db, Btree *p){
|
||||
|
@ -190,13 +190,13 @@ sqlite3_backup *sqlite3_backup_init(
|
|||
p->iNext = 1;
|
||||
p->isAttached = 0;
|
||||
|
||||
if( 0==p->pSrc || 0==p->pDest
|
||||
|| checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK
|
||||
if( 0==p->pSrc || 0==p->pDest
|
||||
|| checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK
|
||||
){
|
||||
/* One (or both) of the named databases did not exist or an OOM
|
||||
** error was hit. Or there is a transaction open on the destination
|
||||
** database. The error has already been written into the pDestDb
|
||||
** handle. All that is left to do here is free the sqlite3_backup
|
||||
** database. The error has already been written into the pDestDb
|
||||
** handle. All that is left to do here is free the sqlite3_backup
|
||||
** structure. */
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
|
@ -212,7 +212,7 @@ sqlite3_backup *sqlite3_backup_init(
|
|||
}
|
||||
|
||||
/*
|
||||
** Argument rc is an SQLite error code. Return true if this error is
|
||||
** Argument rc is an SQLite error code. Return true if this error is
|
||||
** considered fatal if encountered during a backup operation. All errors
|
||||
** are considered fatal except for SQLITE_BUSY and SQLITE_LOCKED.
|
||||
*/
|
||||
|
@ -221,8 +221,8 @@ static int isFatalError(int rc){
|
|||
}
|
||||
|
||||
/*
|
||||
** Parameter zSrcData points to a buffer containing the data for
|
||||
** page iSrcPg from the source database. Copy this data into the
|
||||
** Parameter zSrcData points to a buffer containing the data for
|
||||
** page iSrcPg from the source database. Copy this data into the
|
||||
** destination database.
|
||||
*/
|
||||
static int backupOnePage(
|
||||
|
@ -246,13 +246,13 @@ static int backupOnePage(
|
|||
assert( zSrcData );
|
||||
|
||||
/* Catch the case where the destination is an in-memory database and the
|
||||
** page sizes of the source and destination differ.
|
||||
** page sizes of the source and destination differ.
|
||||
*/
|
||||
if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){
|
||||
rc = SQLITE_READONLY;
|
||||
}
|
||||
|
||||
/* This loop runs once for each destination page spanned by the source
|
||||
/* This loop runs once for each destination page spanned by the source
|
||||
** page. For each iteration, variable iOff is set to the byte offset
|
||||
** of the destination page.
|
||||
*/
|
||||
|
@ -271,7 +271,7 @@ static int backupOnePage(
|
|||
** Then clear the Btree layer MemPage.isInit flag. Both this module
|
||||
** and the pager code use this trick (clearing the first byte
|
||||
** of the page 'extra' space to invalidate the Btree layers
|
||||
** cached parse of the page). MemPage.isInit is marked
|
||||
** cached parse of the page). MemPage.isInit is marked
|
||||
** "MUST BE FIRST" for this purpose.
|
||||
*/
|
||||
memcpy(zOut, zIn, nCopy);
|
||||
|
@ -291,7 +291,7 @@ static int backupOnePage(
|
|||
** exactly iSize bytes. If pFile is not larger than iSize bytes, then
|
||||
** this function is a no-op.
|
||||
**
|
||||
** Return SQLITE_OK if everything is successful, or an SQLite error
|
||||
** Return SQLITE_OK if everything is successful, or an SQLite error
|
||||
** code if an error occurs.
|
||||
*/
|
||||
static int backupTruncateFile(sqlite3_file *pFile, i64 iSize){
|
||||
|
@ -373,7 +373,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
/* Lock the destination database, if it is not locked already. */
|
||||
if( SQLITE_OK==rc && p->bDestLocked==0
|
||||
&& SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2,
|
||||
(int*)&p->iDestSchema))
|
||||
(int*)&p->iDestSchema))
|
||||
){
|
||||
p->bDestLocked = 1;
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
if( SQLITE_OK==rc && destMode==PAGER_JOURNALMODE_WAL && pgszSrc!=pgszDest ){
|
||||
rc = SQLITE_READONLY;
|
||||
}
|
||||
|
||||
|
||||
/* Now that there is a read-lock on the source database, query the
|
||||
** source pager for the number of pages in the database.
|
||||
*/
|
||||
|
@ -413,7 +413,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
attachBackupObject(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Update the schema version field in the destination database. This
|
||||
** is to make sure that the schema-version really does change in
|
||||
** the case where the source and destination databases have the
|
||||
|
@ -439,12 +439,12 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
int nDestTruncate;
|
||||
/* Set nDestTruncate to the final number of pages in the destination
|
||||
** database. The complication here is that the destination page
|
||||
** size may be different to the source page size.
|
||||
** size may be different to the source page size.
|
||||
**
|
||||
** If the source page size is smaller than the destination page size,
|
||||
** If the source page size is smaller than the destination page size,
|
||||
** round up. In this case the call to sqlite3OsTruncate() below will
|
||||
** fix the size of the file. However it is important to call
|
||||
** sqlite3PagerTruncateImage() here so that any pages in the
|
||||
** sqlite3PagerTruncateImage() here so that any pages in the
|
||||
** destination file that lie beyond the nDestTruncate page mark are
|
||||
** journalled by PagerCommitPhaseOne() before they are destroyed
|
||||
** by the file truncation.
|
||||
|
@ -468,7 +468,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
**
|
||||
** * The destination may need to be truncated, and
|
||||
**
|
||||
** * Data stored on the pages immediately following the
|
||||
** * Data stored on the pages immediately following the
|
||||
** pending-byte page in the source database may need to be
|
||||
** copied into the destination database.
|
||||
*/
|
||||
|
@ -480,7 +480,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
i64 iEnd;
|
||||
|
||||
assert( pFile );
|
||||
assert( nDestTruncate==0
|
||||
assert( nDestTruncate==0
|
||||
|| (i64)nDestTruncate*(i64)pgszDest >= iSize || (
|
||||
nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
|
||||
&& iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
|
||||
|
@ -490,7 +490,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
** database has been stored in the journal for pDestPager and the
|
||||
** journal synced to disk. So at this point we may safely modify
|
||||
** the database file in any way, knowing that if a power failure
|
||||
** occurs, the original database will be reconstructed from the
|
||||
** occurs, the original database will be reconstructed from the
|
||||
** journal file. */
|
||||
sqlite3PagerPagecount(pDestPager, &nDstPage);
|
||||
for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
|
||||
|
@ -510,8 +510,8 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
/* Write the extra pages and truncate the database file as required */
|
||||
iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
|
||||
for(
|
||||
iOff=PENDING_BYTE+pgszSrc;
|
||||
rc==SQLITE_OK && iOff<iEnd;
|
||||
iOff=PENDING_BYTE+pgszSrc;
|
||||
rc==SQLITE_OK && iOff<iEnd;
|
||||
iOff+=pgszSrc
|
||||
){
|
||||
PgHdr *pSrcPg = 0;
|
||||
|
@ -535,7 +535,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
|
||||
rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Finish committing the transaction to the destination database. */
|
||||
if( SQLITE_OK==rc
|
||||
&& SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
|
||||
|
@ -544,7 +544,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If bCloseTrans is true, then this function opened a read transaction
|
||||
** on the source database. Close the read transaction here. There is
|
||||
** no need to check the return values of the btree methods here, as
|
||||
|
@ -556,7 +556,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
|
|||
TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
|
||||
assert( rc2==SQLITE_OK );
|
||||
}
|
||||
|
||||
|
||||
if( rc==SQLITE_IOERR_NOMEM ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
|
@ -638,7 +638,7 @@ int sqlite3_backup_remaining(sqlite3_backup *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** Return the total number of pages in the source database as of the most
|
||||
** Return the total number of pages in the source database as of the most
|
||||
** recent call to sqlite3_backup_step().
|
||||
*/
|
||||
int sqlite3_backup_pagecount(sqlite3_backup *p){
|
||||
|
@ -653,7 +653,7 @@ int sqlite3_backup_pagecount(sqlite3_backup *p){
|
|||
|
||||
/*
|
||||
** This function is called after the contents of page iPage of the
|
||||
** source database have been modified. If page iPage has already been
|
||||
** source database have been modified. If page iPage has already been
|
||||
** copied into the destination database, then the data written to the
|
||||
** destination is now invalidated. The destination copy of iPage needs
|
||||
** to be updated with the new data before the backup operation is
|
||||
|
@ -696,7 +696,7 @@ void sqlite3BackupUpdate(sqlite3_backup *pBackup, Pgno iPage, const u8 *aData){
|
|||
** Restart the backup process. This is called when the pager layer
|
||||
** detects that the database has been modified by an external database
|
||||
** connection. In this case there is no way of knowing which of the
|
||||
** pages that have been copied into the destination database are still
|
||||
** pages that have been copied into the destination database are still
|
||||
** valid and which are not, so the entire process needs to be restarted.
|
||||
**
|
||||
** It is assumed that the mutex associated with the BtShared object
|
||||
|
@ -716,8 +716,8 @@ void sqlite3BackupRestart(sqlite3_backup *pBackup){
|
|||
** Copy the complete content of pBtFrom into pBtTo. A transaction
|
||||
** must be active for both files.
|
||||
**
|
||||
** The size of file pTo may be reduced by this operation. If anything
|
||||
** goes wrong, the transaction on pTo is rolled back. If successful, the
|
||||
** The size of file pTo may be reduced by this operation. If anything
|
||||
** goes wrong, the transaction on pTo is rolled back. If successful, the
|
||||
** transaction is committed before returning.
|
||||
*/
|
||||
int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
|
||||
|
@ -749,9 +749,9 @@ int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
|
|||
|
||||
/* 0x7FFFFFFF is the hard limit for the number of pages in a database
|
||||
** file. By passing this as the number of pages to copy to
|
||||
** sqlite3_backup_step(), we can guarantee that the copy finishes
|
||||
** sqlite3_backup_step(), we can guarantee that the copy finishes
|
||||
** within a single call (unless an error occurs). The assert() statement
|
||||
** checks this assumption - (p->rc) should be set to either SQLITE_DONE
|
||||
** checks this assumption - (p->rc) should be set to either SQLITE_DONE
|
||||
** or an error code. */
|
||||
sqlite3_backup_step(&b, 0x7FFFFFFF);
|
||||
assert( b.rc!=SQLITE_OK );
|
||||
|
|
16
third_party/sqlite3/bitvec.c
vendored
16
third_party/sqlite3/bitvec.c
vendored
|
@ -40,13 +40,13 @@
|
|||
/* Size of the Bitvec structure in bytes. */
|
||||
#define BITVEC_SZ 512
|
||||
|
||||
/* Round the union size down to the nearest pointer boundary, since that's how
|
||||
/* Round the union size down to the nearest pointer boundary, since that's how
|
||||
** it will be aligned within the Bitvec struct. */
|
||||
#define BITVEC_USIZE \
|
||||
(((BITVEC_SZ-(3*sizeof(u32)))/sizeof(Bitvec*))*sizeof(Bitvec*))
|
||||
|
||||
/* Type of the array "element" for the bitmap representation.
|
||||
** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE.
|
||||
/* Type of the array "element" for the bitmap representation.
|
||||
** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE.
|
||||
** Setting this to the "natural word" size of your CPU may improve
|
||||
** performance. */
|
||||
#define BITVEC_TELEM u8
|
||||
|
@ -59,12 +59,12 @@
|
|||
|
||||
/* Number of u32 values in hash table. */
|
||||
#define BITVEC_NINT (BITVEC_USIZE/sizeof(u32))
|
||||
/* Maximum number of entries in hash table before
|
||||
/* Maximum number of entries in hash table before
|
||||
** sub-dividing and re-hashing. */
|
||||
#define BITVEC_MXHASH (BITVEC_NINT/2)
|
||||
/* Hashing function for the aHash representation.
|
||||
** Empirical testing showed that the *37 multiplier
|
||||
** (an arbitrary prime)in the hash function provided
|
||||
** Empirical testing showed that the *37 multiplier
|
||||
** (an arbitrary prime)in the hash function provided
|
||||
** no fewer collisions than the no-op *1. */
|
||||
#define BITVEC_HASH(X) (((X)*1)%BITVEC_NINT)
|
||||
|
||||
|
@ -110,7 +110,7 @@ struct Bitvec {
|
|||
|
||||
/*
|
||||
** Create a new bitmap object able to handle bits between 0 and iSize,
|
||||
** inclusive. Return a pointer to the new object. Return NULL if
|
||||
** inclusive. Return a pointer to the new object. Return NULL if
|
||||
** malloc fails.
|
||||
*/
|
||||
Bitvec *sqlite3BitvecCreate(u32 iSize){
|
||||
|
@ -366,7 +366,7 @@ int sqlite3BitvecBuiltinTest(int sz, int *aOp){
|
|||
break;
|
||||
}
|
||||
case 3:
|
||||
case 4:
|
||||
case 4:
|
||||
default: {
|
||||
nx = 2;
|
||||
sqlite3_randomness(sizeof(i), &i);
|
||||
|
|
6
third_party/sqlite3/btmutex.c
vendored
6
third_party/sqlite3/btmutex.c
vendored
|
@ -291,10 +291,10 @@ void sqlite3BtreeEnterAll(sqlite3 *db){
|
|||
|
||||
#ifndef SQLITE_OMIT_INCRBLOB
|
||||
/*
|
||||
** Enter a mutex on a Btree given a cursor owned by that Btree.
|
||||
** Enter a mutex on a Btree given a cursor owned by that Btree.
|
||||
**
|
||||
** These entry points are used by incremental I/O only. Enter() is required
|
||||
** any time OMIT_SHARED_CACHE is not defined, regardless of whether or not
|
||||
** These entry points are used by incremental I/O only. Enter() is required
|
||||
** any time OMIT_SHARED_CACHE is not defined, regardless of whether or not
|
||||
** the build is threadsafe. Leave() is only required by threadsafe builds.
|
||||
*/
|
||||
void sqlite3BtreeEnterCursor(BtCursor *pCur){
|
||||
|
|
672
third_party/sqlite3/btree.c
vendored
672
third_party/sqlite3/btree.c
vendored
File diff suppressed because it is too large
Load diff
14
third_party/sqlite3/btree.inc
vendored
14
third_party/sqlite3/btree.inc
vendored
|
@ -80,13 +80,13 @@ int sqlite3BtreeSchemaLocked(Btree *pBtree);
|
|||
int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
|
||||
#endif
|
||||
|
||||
/* Savepoints are named, nestable SQL transactions mostly implemented */
|
||||
/* Savepoints are named, nestable SQL transactions mostly implemented */
|
||||
/* in vdbe.c and pager.c See https://sqlite.org/lang_savepoint.html */
|
||||
int sqlite3BtreeSavepoint(Btree *, int, int);
|
||||
|
||||
/* "Checkpoint" only refers to WAL. See https://sqlite.org/wal.html#ckpt */
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
|
||||
int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
|
||||
#endif
|
||||
|
||||
const char *sqlite3BtreeGetFilename(Btree *);
|
||||
|
@ -120,7 +120,7 @@ int sqlite3BtreeNewDb(Btree *p);
|
|||
|
||||
/*
|
||||
** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
|
||||
** should be one of the following values. The integer values are assigned
|
||||
** should be one of the following values. The integer values are assigned
|
||||
** to constants so that the offset of the corresponding field in an
|
||||
** SQLite database header may be found using the following formula:
|
||||
**
|
||||
|
@ -191,7 +191,7 @@ int sqlite3BtreeNewDb(Btree *p);
|
|||
#define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
|
||||
#define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */
|
||||
|
||||
/*
|
||||
/*
|
||||
** Flags passed as the third argument to sqlite3BtreeCursor().
|
||||
**
|
||||
** For read-only cursors the wrFlag argument is always zero. For read-write
|
||||
|
@ -260,7 +260,7 @@ int sqlite3BtreeDelete(BtCursor*, u8 flags);
|
|||
** The nMem field might be zero, indicating that no decomposition is available.
|
||||
**
|
||||
** Table btrees (used for rowid tables) contain an integer rowid used as
|
||||
** the key and passed in the nKey field. The pKey field is zero.
|
||||
** the key and passed in the nKey field. The pKey field is zero.
|
||||
** pData,nData hold the content of the new entry. nZero extra zero bytes
|
||||
** are appended to the end of the content when constructing the entry.
|
||||
** The aMem,nMem fields are uninitialized for table btrees.
|
||||
|
@ -279,7 +279,7 @@ int sqlite3BtreeDelete(BtCursor*, u8 flags);
|
|||
**
|
||||
** This object is used to pass information into sqlite3BtreeInsert(). The
|
||||
** same information used to be passed as five separate parameters. But placing
|
||||
** the information into this object helps to keep the interface more
|
||||
** the information into this object helps to keep the interface more
|
||||
** organized and understandable, and it also helps the resulting code to
|
||||
** run a little faster by using fewer registers for parameter passing.
|
||||
*/
|
||||
|
@ -362,7 +362,7 @@ int sqlite3BtreeTransferRow(BtCursor*, BtCursor*, i64);
|
|||
void sqlite3BtreeEnterCursor(BtCursor*);
|
||||
int sqlite3BtreeConnectionCount(Btree*);
|
||||
#else
|
||||
# define sqlite3BtreeEnter(X)
|
||||
# define sqlite3BtreeEnter(X)
|
||||
# define sqlite3BtreeEnterAll(X)
|
||||
# define sqlite3BtreeSharable(X) 0
|
||||
# define sqlite3BtreeEnterCursor(X)
|
||||
|
|
34
third_party/sqlite3/btreeInt.inc
vendored
34
third_party/sqlite3/btreeInt.inc
vendored
|
@ -242,7 +242,7 @@ typedef struct CellInfo CellInfo;
|
|||
** -DSQLITE_FILE_HEADER="..." on the compiler command-line. The
|
||||
** header must be exactly 16 bytes including the zero-terminator so
|
||||
** the string itself should be 15 characters long. If you change
|
||||
** the header, then your custom library will not be able to read
|
||||
** the header, then your custom library will not be able to read
|
||||
** databases generated by the standard tools and the standard tools
|
||||
** will not be able to read databases created by your custom library.
|
||||
*/
|
||||
|
@ -305,7 +305,7 @@ struct MemPage {
|
|||
|
||||
/*
|
||||
** A linked list of the following structures is stored at BtShared.pLock.
|
||||
** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
|
||||
** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
|
||||
** is opened on the table with root page BtShared.iTable. Locks are removed
|
||||
** from this list when a transaction is committed or rolled back, or when
|
||||
** a btree handle is closed.
|
||||
|
@ -329,7 +329,7 @@ struct BtLock {
|
|||
** see the internals of this structure and only deals with pointers to
|
||||
** this structure.
|
||||
**
|
||||
** For some database files, the same underlying database cache might be
|
||||
** For some database files, the same underlying database cache might be
|
||||
** shared between multiple connections. In that case, each connection
|
||||
** has it own instance of this object. But each instance of this object
|
||||
** points to the same BtShared object. The database cache and the
|
||||
|
@ -337,7 +337,7 @@ struct BtLock {
|
|||
** the BtShared object.
|
||||
**
|
||||
** All fields in this structure are accessed under sqlite3.mutex.
|
||||
** The pBt pointer itself may not be changed while there exists cursors
|
||||
** The pBt pointer itself may not be changed while there exists cursors
|
||||
** in the referenced BtShared that point back to this Btree since those
|
||||
** cursors have to go through this Btree to find their BtShared and
|
||||
** they often do so without holding sqlite3.mutex.
|
||||
|
@ -389,7 +389,7 @@ struct Btree {
|
|||
|
||||
/*
|
||||
** An instance of this object represents a single database file.
|
||||
**
|
||||
**
|
||||
** A single database file can be in use at the same time by two
|
||||
** or more database connections. When two or more connections are
|
||||
** sharing the same database file, each connection has it own
|
||||
|
@ -508,7 +508,7 @@ struct CellInfo {
|
|||
** particular database connection identified BtCursor.pBtree.db.
|
||||
**
|
||||
** Fields in this structure are accessed under the BtShared.mutex
|
||||
** found at self->pBt->mutex.
|
||||
** found at self->pBt->mutex.
|
||||
**
|
||||
** skipNext meaning:
|
||||
** The meaning of skipNext depends on the value of eState:
|
||||
|
@ -565,7 +565,7 @@ struct BtCursor {
|
|||
** Potential values for BtCursor.eState.
|
||||
**
|
||||
** CURSOR_INVALID:
|
||||
** Cursor does not point to a valid entry. This can happen (for example)
|
||||
** Cursor does not point to a valid entry. This can happen (for example)
|
||||
** because the table is empty or because BtreeCursorFirst() has not been
|
||||
** called.
|
||||
**
|
||||
|
@ -578,9 +578,9 @@ struct BtCursor {
|
|||
** operation should be a no-op.
|
||||
**
|
||||
** CURSOR_REQUIRESEEK:
|
||||
** The table that this cursor was opened on still exists, but has been
|
||||
** The table that this cursor was opened on still exists, but has been
|
||||
** modified since the cursor was last used. The cursor position is saved
|
||||
** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
|
||||
** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
|
||||
** this state, restoreCursorPosition() can be called to attempt to
|
||||
** seek the cursor to the saved position.
|
||||
**
|
||||
|
@ -597,13 +597,13 @@ struct BtCursor {
|
|||
#define CURSOR_REQUIRESEEK 3
|
||||
#define CURSOR_FAULT 4
|
||||
|
||||
/*
|
||||
/*
|
||||
** The database page the PENDING_BYTE occupies. This page is never used.
|
||||
*/
|
||||
# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
|
||||
|
||||
/*
|
||||
** These macros define the location of the pointer-map entry for a
|
||||
** These macros define the location of the pointer-map entry for a
|
||||
** database page. The first argument to each is the number of usable
|
||||
** bytes on each page of the database (often 1024). The second is the
|
||||
** page number to look up in the pointer map.
|
||||
|
@ -638,10 +638,10 @@ struct BtCursor {
|
|||
** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
|
||||
** used in this case.
|
||||
**
|
||||
** PTRMAP_FREEPAGE: The database page is an unused (free) page. The page-number
|
||||
** PTRMAP_FREEPAGE: The database page is an unused (free) page. The page-number
|
||||
** is not used in this case.
|
||||
**
|
||||
** PTRMAP_OVERFLOW1: The database page is the first page in a list of
|
||||
** PTRMAP_OVERFLOW1: The database page is the first page in a list of
|
||||
** overflow pages. The page number identifies the page that
|
||||
** contains the cell with a pointer to this overflow page.
|
||||
**
|
||||
|
@ -663,13 +663,13 @@ struct BtCursor {
|
|||
*/
|
||||
#define btreeIntegrity(p) \
|
||||
assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
|
||||
assert( p->pBt->inTransaction>=p->inTrans );
|
||||
assert( p->pBt->inTransaction>=p->inTrans );
|
||||
|
||||
|
||||
/*
|
||||
** The ISAUTOVACUUM macro is used within balance_nonroot() to determine
|
||||
** if the database supports auto-vacuum or not. Because it is used
|
||||
** within an expression that is an argument to another macro
|
||||
** within an expression that is an argument to another macro
|
||||
** (sqliteMallocRaw), it is not possible to use conditional compilation.
|
||||
** So, this macro is defined instead.
|
||||
*/
|
||||
|
@ -686,8 +686,8 @@ struct BtCursor {
|
|||
**
|
||||
** The aRef[] array is allocated so that there is 1 bit for each page in
|
||||
** the database. As the integrity-check proceeds, for each page used in
|
||||
** the database the corresponding bit is set. This allows integrity-check to
|
||||
** detect pages that are used twice and orphaned pages (both of which
|
||||
** the database the corresponding bit is set. This allows integrity-check to
|
||||
** detect pages that are used twice and orphaned pages (both of which
|
||||
** indicate corruption).
|
||||
*/
|
||||
typedef struct IntegrityCk IntegrityCk;
|
||||
|
|
200
third_party/sqlite3/build.c
vendored
200
third_party/sqlite3/build.c
vendored
|
@ -39,7 +39,7 @@ struct TableLock {
|
|||
};
|
||||
|
||||
/*
|
||||
** Record the fact that we want to lock a table at run-time.
|
||||
** Record the fact that we want to lock a table at run-time.
|
||||
**
|
||||
** The table to be locked has root page iTab and is found in database iDb.
|
||||
** A read or a write lock can be taken depending on isWritelock.
|
||||
|
@ -93,7 +93,7 @@ void sqlite3TableLock(
|
|||
*/
|
||||
static void codeTableLocks(Parse *pParse){
|
||||
int i;
|
||||
Vdbe *pVdbe = pParse->pVdbe;
|
||||
Vdbe *pVdbe = pParse->pVdbe;
|
||||
assert( pVdbe!=0 );
|
||||
|
||||
for(i=0; i<pParse->nTableLock; i++){
|
||||
|
@ -154,7 +154,7 @@ void sqlite3FinishCoding(Parse *pParse){
|
|||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
assert( !pParse->isMultiWrite
|
||||
assert( !pParse->isMultiWrite
|
||||
|| sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
|
||||
if( v ){
|
||||
if( pParse->bReturning ){
|
||||
|
@ -194,7 +194,7 @@ void sqlite3FinishCoding(Parse *pParse){
|
|||
** transaction on each used database and to verify the schema cookie
|
||||
** on each used database.
|
||||
*/
|
||||
if( db->mallocFailed==0
|
||||
if( db->mallocFailed==0
|
||||
&& (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
|
||||
){
|
||||
int iDb, i;
|
||||
|
@ -224,8 +224,8 @@ void sqlite3FinishCoding(Parse *pParse){
|
|||
pParse->nVtabLock = 0;
|
||||
#endif
|
||||
|
||||
/* Once all the cookies have been verified and transactions opened,
|
||||
** obtain the required table-locks. This is a no-op unless the
|
||||
/* Once all the cookies have been verified and transactions opened,
|
||||
** obtain the required table-locks. This is a no-op unless the
|
||||
** shared-cache feature is enabled.
|
||||
*/
|
||||
codeTableLocks(pParse);
|
||||
|
@ -372,7 +372,7 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
|
|||
|| sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0
|
||||
|| sqlite3StrICmp(zName+7, &DFLT_SCHEMA_TABLE[7])==0
|
||||
){
|
||||
p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
|
||||
p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
|
||||
DFLT_TEMP_SCHEMA_TABLE);
|
||||
}
|
||||
}else{
|
||||
|
@ -399,7 +399,7 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
|
|||
if( sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 ){
|
||||
p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, DFLT_SCHEMA_TABLE);
|
||||
}else if( sqlite3StrICmp(zName+7, &ALT_TEMP_SCHEMA_TABLE[7])==0 ){
|
||||
p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
|
||||
p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
|
||||
DFLT_TEMP_SCHEMA_TABLE);
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ Table *sqlite3LocateTable(
|
|||
|
||||
/* Read the database schema. If an error occurs, leave an error message
|
||||
** and code in pParse and return NULL. */
|
||||
if( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0
|
||||
if( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0
|
||||
&& SQLITE_OK!=sqlite3ReadSchema(pParse)
|
||||
){
|
||||
return 0;
|
||||
|
@ -478,7 +478,7 @@ Table *sqlite3LocateTable(
|
|||
** sqlite3FixSrcList() for details.
|
||||
*/
|
||||
Table *sqlite3LocateTableItem(
|
||||
Parse *pParse,
|
||||
Parse *pParse,
|
||||
u32 flags,
|
||||
SrcItem *p
|
||||
){
|
||||
|
@ -494,7 +494,7 @@ Table *sqlite3LocateTableItem(
|
|||
}
|
||||
|
||||
/*
|
||||
** Locate the in-memory structure that describes
|
||||
** Locate the in-memory structure that describes
|
||||
** a particular index given the name of that index
|
||||
** and the name of the database that contains the index.
|
||||
** Return NULL if not found.
|
||||
|
@ -682,10 +682,10 @@ void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
|
|||
**
|
||||
** This routine just deletes the data structure. It does not unlink
|
||||
** the table data structure from the hash table. But it does destroy
|
||||
** memory structures of the indices and foreign keys associated with
|
||||
** memory structures of the indices and foreign keys associated with
|
||||
** the table.
|
||||
**
|
||||
** The db parameter is optional. It is needed if the Table object
|
||||
** The db parameter is optional. It is needed if the Table object
|
||||
** contains lookaside memory. (Table objects in the schema do not use
|
||||
** lookaside memory, but some ephemeral Table objects do.) Or the
|
||||
** db parameter can be used with db->pnBytesFreed to measure the memory
|
||||
|
@ -697,7 +697,7 @@ static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
|
|||
#ifdef SQLITE_DEBUG
|
||||
/* Record the number of outstanding lookaside allocations in schema Tables
|
||||
** prior to doing any free() operations. Since schema Tables do not use
|
||||
** lookaside, this number should not change.
|
||||
** lookaside, this number should not change.
|
||||
**
|
||||
** If malloc has already failed, it may be that it failed while allocating
|
||||
** a Table object that was going to be marked ephemeral. So do not check
|
||||
|
@ -714,7 +714,7 @@ static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
|
|||
assert( pIndex->pSchema==pTable->pSchema
|
||||
|| (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
|
||||
if( (db==0 || db->pnBytesFreed==0) && !IsVirtual(pTable) ){
|
||||
char *zName = pIndex->zName;
|
||||
char *zName = pIndex->zName;
|
||||
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
|
||||
&pIndex->pSchema->idxHash, zName, 0
|
||||
);
|
||||
|
@ -829,7 +829,7 @@ int sqlite3FindDbName(sqlite3 *db, const char *zName){
|
|||
/*
|
||||
** The token *pName contains the name of a database (either "main" or
|
||||
** "temp" or the name of an attached db). This routine returns the
|
||||
** index of the named database in db->aDb[], or -1 if the named db
|
||||
** index of the named database in db->aDb[], or -1 if the named db
|
||||
** does not exist.
|
||||
*/
|
||||
int sqlite3FindDb(sqlite3 *db, Token *pName){
|
||||
|
@ -845,7 +845,7 @@ int sqlite3FindDb(sqlite3 *db, Token *pName){
|
|||
** pName1 and pName2. If the table name was fully qualified, for example:
|
||||
**
|
||||
** CREATE TABLE xxx.yyy (...);
|
||||
**
|
||||
**
|
||||
** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if
|
||||
** the table name is not fully qualified, i.e.:
|
||||
**
|
||||
|
@ -999,7 +999,7 @@ i16 sqlite3StorageColumnToTable(Table *pTab, i16 iCol){
|
|||
** The storage column number (0,1,2,....) is the index of the value
|
||||
** as it appears in the record on disk. Or, if the input column is
|
||||
** the N-th virtual column (zero-based) then the storage number is
|
||||
** the number of non-virtual columns in the table plus N.
|
||||
** the number of non-virtual columns in the table plus N.
|
||||
**
|
||||
** The true column number is the index (0,1,2,...) of the column in
|
||||
** the CREATE TABLE statement.
|
||||
|
@ -1090,7 +1090,7 @@ void sqlite3StartTable(
|
|||
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
|
||||
if( iDb<0 ) return;
|
||||
if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
|
||||
/* If creating a temp table, the name may not be qualified. Unless
|
||||
/* If creating a temp table, the name may not be qualified. Unless
|
||||
** the database name is "temp" anyway. */
|
||||
sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
|
||||
return;
|
||||
|
@ -1190,7 +1190,7 @@ void sqlite3StartTable(
|
|||
** the schema table. Note in particular that we must go ahead
|
||||
** and allocate the record number for the table entry now. Before any
|
||||
** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
|
||||
** indices to be created and the table record must come before the
|
||||
** indices to be created and the table record must come before the
|
||||
** indices. Hence, the record number for the table must be allocated
|
||||
** now.
|
||||
*/
|
||||
|
@ -1208,7 +1208,7 @@ void sqlite3StartTable(
|
|||
}
|
||||
#endif
|
||||
|
||||
/* If the file format and encoding in the database have not been set,
|
||||
/* If the file format and encoding in the database have not been set,
|
||||
** set them now.
|
||||
*/
|
||||
reg1 = pParse->regRowid = ++pParse->nMem;
|
||||
|
@ -1396,7 +1396,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){
|
|||
pCol->zName = z;
|
||||
pCol->hName = hName;
|
||||
sqlite3ColumnPropertiesFromName(p, pCol);
|
||||
|
||||
|
||||
if( pType->n==0 ){
|
||||
/* If there is no type specified, columns have the default affinity
|
||||
** 'BLOB' with a default size of 4 bytes. */
|
||||
|
@ -1452,11 +1452,11 @@ void sqlite3AddNotNull(Parse *pParse, int onError){
|
|||
** Scan the column type name zType (length nType) and return the
|
||||
** associated affinity type.
|
||||
**
|
||||
** This routine does a case-independent search of zType for the
|
||||
** This routine does a case-independent search of zType for the
|
||||
** substrings in the following table. If one of the substrings is
|
||||
** found, the corresponding affinity is returned. If zType contains
|
||||
** more than one of the substrings, entries toward the top of
|
||||
** the table take priority. For example, if zType is 'BLOBINT',
|
||||
** more than one of the substrings, entries toward the top of
|
||||
** the table take priority. For example, if zType is 'BLOBINT',
|
||||
** SQLITE_AFF_INTEGER is returned.
|
||||
**
|
||||
** Substring | Affinity
|
||||
|
@ -1595,7 +1595,7 @@ void sqlite3AddDefaultValue(
|
|||
|
||||
/*
|
||||
** Backwards Compatibility Hack:
|
||||
**
|
||||
**
|
||||
** Historical versions of SQLite accepted strings as column names in
|
||||
** indexes and PRIMARY KEY constraints and in UNIQUE constraints. Example:
|
||||
**
|
||||
|
@ -1629,11 +1629,11 @@ static void makeColumnPartOfPrimaryKey(Parse *pParse, Column *pCol){
|
|||
sqlite3ErrorMsg(pParse,
|
||||
"generated columns cannot be part of the PRIMARY KEY");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Designate the PRIMARY KEY for the table. pList is a list of names
|
||||
** Designate the PRIMARY KEY for the table. pList is a list of names
|
||||
** of columns that form the primary key. If pList is NULL, then the
|
||||
** most recently added column of the table is the primary key.
|
||||
**
|
||||
|
@ -1663,7 +1663,7 @@ void sqlite3AddPrimaryKey(
|
|||
int nTerm;
|
||||
if( pTab==0 ) goto primary_key_exit;
|
||||
if( pTab->tabFlags & TF_HasPrimaryKey ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"table \"%s\" has more than one primary key", pTab->zName);
|
||||
goto primary_key_exit;
|
||||
}
|
||||
|
@ -1746,7 +1746,7 @@ void sqlite3AddCheckConstraint(
|
|||
while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; }
|
||||
t.z = zStart;
|
||||
t.n = (int)(zEnd - t.z);
|
||||
sqlite3ExprListSetName(pParse, pTab->pCheck, &t, 1);
|
||||
sqlite3ExprListSetName(pParse, pTab->pCheck, &t, 1);
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
@ -1775,7 +1775,7 @@ void sqlite3AddCollateType(Parse *pParse, Token *pToken){
|
|||
Index *pIdx;
|
||||
sqlite3DbFree(db, p->aCol[i].zColl);
|
||||
p->aCol[i].zColl = zColl;
|
||||
|
||||
|
||||
/* If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
|
||||
** then an index may have been created on this column before the
|
||||
** collation type was added. Correct this if it is the case.
|
||||
|
@ -1866,7 +1866,7 @@ void sqlite3ChangeCookie(Parse *pParse, int iDb){
|
|||
sqlite3 *db = pParse->db;
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION,
|
||||
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION,
|
||||
(int)(1+(unsigned)db->aDb[iDb].pSchema->schema_cookie));
|
||||
}
|
||||
|
||||
|
@ -1887,13 +1887,13 @@ static int identLength(const char *z){
|
|||
}
|
||||
|
||||
/*
|
||||
** The first parameter is a pointer to an output buffer. The second
|
||||
** The first parameter is a pointer to an output buffer. The second
|
||||
** parameter is a pointer to an integer that contains the offset at
|
||||
** which to write into the output buffer. This function copies the
|
||||
** nul-terminated string pointed to by the third parameter, zSignedIdent,
|
||||
** to the specified offset in the buffer and updates *pIdx to refer
|
||||
** to the first byte after the last byte written before returning.
|
||||
**
|
||||
**
|
||||
** If the string zSignedIdent consists entirely of alpha-numeric
|
||||
** characters, does not begin with a digit and is not an SQL keyword,
|
||||
** then it is copied to the output buffer exactly as it is. Otherwise,
|
||||
|
@ -1937,7 +1937,7 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
|||
n += identLength(pCol->zName) + 5;
|
||||
}
|
||||
n += identLength(p->zName);
|
||||
if( n<50 ){
|
||||
if( n<50 ){
|
||||
zSep = "";
|
||||
zSep2 = ",";
|
||||
zEnd = ")";
|
||||
|
@ -1978,10 +1978,10 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
|||
testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
|
||||
testcase( pCol->affinity==SQLITE_AFF_INTEGER );
|
||||
testcase( pCol->affinity==SQLITE_AFF_REAL );
|
||||
|
||||
|
||||
zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
|
||||
len = sqlite3Strlen30(zType);
|
||||
assert( pCol->affinity==SQLITE_AFF_BLOB
|
||||
assert( pCol->affinity==SQLITE_AFF_BLOB
|
||||
|| pCol->affinity==sqlite3AffinityType(zType, 0) );
|
||||
memcpy(&zStmt[k], zType, len);
|
||||
k += len;
|
||||
|
@ -2087,7 +2087,7 @@ static int isDupColumn(Index *pIdx, int nKey, Index *pPk, int iCol){
|
|||
assert( j!=XN_ROWID && j!=XN_EXPR );
|
||||
for(i=0; i<nKey; i++){
|
||||
assert( pIdx->aiColumn[i]>=0 || j>=0 );
|
||||
if( pIdx->aiColumn[i]==j
|
||||
if( pIdx->aiColumn[i]==j
|
||||
&& sqlite3StrICmp(pIdx->azColl[i], pPk->azColl[iCol])==0
|
||||
){
|
||||
return 1;
|
||||
|
@ -2138,7 +2138,7 @@ static void recomputeColumnsNotIndexed(Index *pIdx){
|
|||
** Changes include:
|
||||
**
|
||||
** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
|
||||
** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
|
||||
** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
|
||||
** into BTREE_BLOBKEY.
|
||||
** (3) Bypass the creation of the sqlite_schema table entry
|
||||
** for the PRIMARY KEY as the primary key index is now
|
||||
|
@ -2184,13 +2184,13 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
|||
}
|
||||
|
||||
/* Locate the PRIMARY KEY index. Or, if this table was originally
|
||||
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
|
||||
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
|
||||
*/
|
||||
if( pTab->iPKey>=0 ){
|
||||
ExprList *pList;
|
||||
Token ipkToken;
|
||||
sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
|
||||
pList = sqlite3ExprListAppend(pParse, 0,
|
||||
pList = sqlite3ExprListAppend(pParse, 0,
|
||||
sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
|
||||
if( pList==0 ) return;
|
||||
if( IN_RENAME_OBJECT ){
|
||||
|
@ -2386,7 +2386,7 @@ static void markExprListImmutable(ExprList *pList){
|
|||
** the sqlite_schema table. We do not want to create it again.
|
||||
**
|
||||
** If the pSelect argument is not NULL, it means that this routine
|
||||
** was called to create a table generated from a
|
||||
** was called to create a table generated from a
|
||||
** "CREATE TABLE ... AS SELECT ..." statement. The column names of
|
||||
** the new table will match the result set of the SELECT.
|
||||
*/
|
||||
|
@ -2523,7 +2523,7 @@ void sqlite3EndTable(
|
|||
|
||||
sqlite3VdbeAddOp1(v, OP_Close, 0);
|
||||
|
||||
/*
|
||||
/*
|
||||
** Initialize zType for the new view or table.
|
||||
*/
|
||||
if( p->pSelect==0 ){
|
||||
|
@ -2602,12 +2602,12 @@ void sqlite3EndTable(
|
|||
Token *pEnd2 = tabOpts ? &pParse->sLastToken : pEnd;
|
||||
n = (int)(pEnd2->z - pParse->sNameToken.z);
|
||||
if( pEnd2->z[0]!=';' ) n += pEnd2->n;
|
||||
zStmt = sqlite3MPrintf(db,
|
||||
zStmt = sqlite3MPrintf(db,
|
||||
"CREATE %s %.*s", zType2, n, pParse->sNameToken.z
|
||||
);
|
||||
}
|
||||
|
||||
/* A slot for the record has already been allocated in the
|
||||
/* A slot for the record has already been allocated in the
|
||||
** schema table. We just need to update that slot with all
|
||||
** the information we've collected.
|
||||
*/
|
||||
|
@ -2800,7 +2800,7 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
|||
** Actually, the error above is now caught prior to reaching this point.
|
||||
** But the following test is still important as it does come up
|
||||
** in the following:
|
||||
**
|
||||
**
|
||||
** CREATE TABLE main.ex1(a);
|
||||
** CREATE TEMP VIEW ex1 AS SELECT a FROM ex1;
|
||||
** SELECT * FROM temp.ex1;
|
||||
|
@ -2846,9 +2846,9 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
|||
** normally holds CHECK constraints on an ordinary table, but for
|
||||
** a VIEW it holds the list of column names.
|
||||
*/
|
||||
sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
|
||||
sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
|
||||
&pTable->nCol, &pTable->aCol);
|
||||
if( db->mallocFailed==0
|
||||
if( db->mallocFailed==0
|
||||
&& pParse->nErr==0
|
||||
&& pTable->nCol==pSel->pEList->nExpr
|
||||
){
|
||||
|
@ -2882,7 +2882,7 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
|||
pTable->nCol = 0;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_VIEW */
|
||||
return nErr;
|
||||
return nErr;
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
|
||||
|
||||
|
@ -2918,7 +2918,7 @@ static void sqliteViewResetAll(sqlite3 *db, int idx){
|
|||
** on tables and/or indices that are the process of being deleted.
|
||||
** If you are unlucky, one of those deleted indices or tables might
|
||||
** have the same rootpage number as the real table or index that is
|
||||
** being moved. So we cannot stop searching after the first match
|
||||
** being moved. So we cannot stop searching after the first match
|
||||
** because the first match might be for one of the deleted indices
|
||||
** or tables and not the table/index that is actually being moved.
|
||||
** We must continue looping until all tables and indices with
|
||||
|
@ -2955,7 +2955,7 @@ void sqlite3RootPageMoved(sqlite3 *db, int iDb, Pgno iFrom, Pgno iTo){
|
|||
** Also write code to modify the sqlite_schema table and internal schema
|
||||
** if a root-page of another table is moved by the btree-layer whilst
|
||||
** erasing iTable (this can happen with an auto-vacuum database).
|
||||
*/
|
||||
*/
|
||||
static void destroyRootPage(Parse *pParse, int iTable, int iDb){
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
int r1 = sqlite3GetTempReg(pParse);
|
||||
|
@ -2972,7 +2972,7 @@ static void destroyRootPage(Parse *pParse, int iTable, int iDb){
|
|||
** is in register NNN. See grammar rules associated with the TK_REGISTER
|
||||
** token for additional information.
|
||||
*/
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE %Q." DFLT_SCHEMA_TABLE
|
||||
" SET rootpage=%d WHERE #%d AND rootpage=#%d",
|
||||
pParse->db->aDb[iDb].zDbSName, iTable, r1, r1);
|
||||
|
@ -2989,7 +2989,7 @@ static void destroyRootPage(Parse *pParse, int iTable, int iDb){
|
|||
static void destroyTable(Parse *pParse, Table *pTab){
|
||||
/* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
|
||||
** is not defined), then it is important to call OP_Destroy on the
|
||||
** table and index root-pages in order, starting with the numerically
|
||||
** table and index root-pages in order, starting with the numerically
|
||||
** largest root-page number. This guarantees that none of the root-pages
|
||||
** to be destroyed is relocated by an earlier OP_Destroy. i.e. if the
|
||||
** following were coded:
|
||||
|
@ -2999,7 +2999,7 @@ static void destroyTable(Parse *pParse, Table *pTab){
|
|||
** OP_Destroy 5 0
|
||||
**
|
||||
** and root page 5 happened to be the largest root-page number in the
|
||||
** database, then root page 5 would be moved to page 4 by the
|
||||
** database, then root page 5 would be moved to page 4 by the
|
||||
** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
|
||||
** a free-list page.
|
||||
*/
|
||||
|
@ -3080,7 +3080,7 @@ void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
|
|||
*/
|
||||
pTrigger = sqlite3TriggerList(pParse, pTab);
|
||||
while( pTrigger ){
|
||||
assert( pTrigger->pSchema==pTab->pSchema ||
|
||||
assert( pTrigger->pSchema==pTab->pSchema ||
|
||||
pTrigger->pSchema==db->aDb[1].pSchema );
|
||||
sqlite3DropTriggerPtr(pParse, pTrigger);
|
||||
pTrigger = pTrigger->pNext;
|
||||
|
@ -3107,7 +3107,7 @@ void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
|
|||
** created in the temp database that refers to a table in another
|
||||
** database.
|
||||
*/
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"DELETE FROM %Q." DFLT_SCHEMA_TABLE
|
||||
" WHERE tbl_name=%Q and type!='trigger'",
|
||||
pDb->zDbSName, pTab->zName);
|
||||
|
@ -3350,8 +3350,8 @@ void sqlite3CreateForeignKey(
|
|||
}
|
||||
}
|
||||
if( j>=p->nCol ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"unknown column \"%s\" in foreign key definition",
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"unknown column \"%s\" in foreign key definition",
|
||||
pFromCol->a[i].zEName);
|
||||
goto fk_end;
|
||||
}
|
||||
|
@ -3377,7 +3377,7 @@ void sqlite3CreateForeignKey(
|
|||
pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */
|
||||
|
||||
assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
|
||||
pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
|
||||
pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
|
||||
pFKey->zTo, (void *)pFKey
|
||||
);
|
||||
if( pNextTo==pFKey ){
|
||||
|
@ -3483,7 +3483,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
|
|||
sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
|
||||
sqlite3VdbeJumpHere(v, addr1);
|
||||
if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
|
||||
sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, (int)tnum, iDb,
|
||||
sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, (int)tnum, iDb,
|
||||
(char *)pKey, P4_KEYINFO);
|
||||
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
|
||||
|
||||
|
@ -3502,7 +3502,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
|
|||
** user function that throws an exception when it is evaluated. But the
|
||||
** overhead of adding a statement journal to a CREATE INDEX statement is
|
||||
** very small (since most of the pages written do not contain content that
|
||||
** needs to be restored if the statement aborts), so we call
|
||||
** needs to be restored if the statement aborts), so we call
|
||||
** sqlite3MayAbort() for all CREATE INDEX statements. */
|
||||
sqlite3MayAbort(pParse);
|
||||
addr2 = sqlite3VdbeCurrentAddr(v);
|
||||
|
@ -3575,7 +3575,7 @@ int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
|
|||
for(i=0; i<pList->nExpr; i++){
|
||||
if( pList->a[i].bNulls ){
|
||||
u8 sf = pList->a[i].sortFlags;
|
||||
sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
|
||||
sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
|
||||
(sf==0 || sf==3) ? "FIRST" : "LAST"
|
||||
);
|
||||
return 1;
|
||||
|
@ -3586,8 +3586,8 @@ int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
|
|||
}
|
||||
|
||||
/*
|
||||
** Create a new index for an SQL table. pName1.pName2 is the name of the index
|
||||
** and pTblList is the name of the table that is to be indexed. Both will
|
||||
** Create a new index for an SQL table. pName1.pName2 is the name of the index
|
||||
** and pTblList is the name of the table that is to be indexed. Both will
|
||||
** be NULL for a primary key or an index that is created to satisfy a
|
||||
** UNIQUE constraint. If pTable and pIndex are NULL, use pParse->pNewTable
|
||||
** as the table to be indexed. pParse->pNewTable is a table that is
|
||||
|
@ -3595,7 +3595,7 @@ int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
|
|||
**
|
||||
** pList is a list of columns to be indexed. pList will be NULL if this
|
||||
** is a primary key or unique-constraint on the most recent column added
|
||||
** to the table currently under construction.
|
||||
** to the table currently under construction.
|
||||
*/
|
||||
void sqlite3CreateIndex(
|
||||
Parse *pParse, /* All information about this parse */
|
||||
|
@ -3645,7 +3645,7 @@ void sqlite3CreateIndex(
|
|||
*/
|
||||
if( pTblName!=0 ){
|
||||
|
||||
/* Use the two-part index name to determine the database
|
||||
/* Use the two-part index name to determine the database
|
||||
** to search for the table. 'Fix' the table name to this db
|
||||
** before looking up the table.
|
||||
*/
|
||||
|
@ -3677,7 +3677,7 @@ void sqlite3CreateIndex(
|
|||
assert( db->mallocFailed==0 || pTab==0 );
|
||||
if( pTab==0 ) goto exit_create_index;
|
||||
if( iDb==1 && db->aDb[iDb].pSchema!=pTab->pSchema ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"cannot create a TEMP index on non-TEMP table \"%s\"",
|
||||
pTab->zName);
|
||||
goto exit_create_index;
|
||||
|
@ -3694,7 +3694,7 @@ void sqlite3CreateIndex(
|
|||
|
||||
assert( pTab!=0 );
|
||||
assert( pParse->nErr==0 );
|
||||
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
|
||||
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
|
||||
&& db->init.busy==0
|
||||
&& pTblName!=0
|
||||
#if SQLITE_USER_AUTHENTICATION
|
||||
|
@ -3719,7 +3719,7 @@ void sqlite3CreateIndex(
|
|||
|
||||
/*
|
||||
** Find the name of the index. Make sure there is not already another
|
||||
** index or table with the same name.
|
||||
** index or table with the same name.
|
||||
**
|
||||
** Exception: If we are reading the names of permanent indices from the
|
||||
** sqlite_schema table (because some other process changed the schema) and
|
||||
|
@ -3817,8 +3817,8 @@ void sqlite3CreateIndex(
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate the index structure.
|
||||
/*
|
||||
** Allocate the index structure.
|
||||
*/
|
||||
nName = sqlite3Strlen30(zName);
|
||||
nExtraCol = pPk ? pPk->nKeyCol : 1;
|
||||
|
@ -3936,7 +3936,7 @@ void sqlite3CreateIndex(
|
|||
int x = pPk->aiColumn[j];
|
||||
assert( x>=0 );
|
||||
if( isDupColumn(pIndex, pIndex->nKeyCol, pPk, j) ){
|
||||
pIndex->nColumn--;
|
||||
pIndex->nColumn--;
|
||||
}else{
|
||||
testcase( hasColumn(pIndex->aiColumn,pIndex->nKeyCol,x) );
|
||||
pIndex->aiColumn[i] = x;
|
||||
|
@ -3955,7 +3955,7 @@ void sqlite3CreateIndex(
|
|||
|
||||
/* If this index contains every column of its table, then mark
|
||||
** it as a covering index */
|
||||
assert( HasRowid(pTab)
|
||||
assert( HasRowid(pTab)
|
||||
|| pTab->iPKey<0 || sqlite3TableColumnToIndex(pIndex, pTab->iPKey)>=0 );
|
||||
recomputeColumnsNotIndexed(pIndex);
|
||||
if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){
|
||||
|
@ -4011,13 +4011,13 @@ void sqlite3CreateIndex(
|
|||
if( pIdx->onError!=pIndex->onError ){
|
||||
/* This constraint creates the same index as a previous
|
||||
** constraint specified somewhere in the CREATE TABLE statement.
|
||||
** However the ON CONFLICT clauses are different. If both this
|
||||
** However the ON CONFLICT clauses are different. If both this
|
||||
** constraint and the previous equivalent constraint have explicit
|
||||
** ON CONFLICT clauses this is an error. Otherwise, use the
|
||||
** explicitly specified behavior for the index.
|
||||
*/
|
||||
if( !(pIdx->onError==OE_Default || pIndex->onError==OE_Default) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"conflicting ON CONFLICT clauses specified", 0);
|
||||
}
|
||||
if( pIdx->onError==OE_Default ){
|
||||
|
@ -4038,7 +4038,7 @@ void sqlite3CreateIndex(
|
|||
if( !IN_RENAME_OBJECT ){
|
||||
|
||||
/* Link the new Index structure to its table and to the other
|
||||
** in-memory database structures.
|
||||
** in-memory database structures.
|
||||
*/
|
||||
assert( pParse->nErr==0 );
|
||||
if( db->init.busy ){
|
||||
|
@ -4053,7 +4053,7 @@ void sqlite3CreateIndex(
|
|||
goto exit_create_index;
|
||||
}
|
||||
}
|
||||
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
|
||||
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
|
||||
pIndex->zName, pIndex);
|
||||
if( p ){
|
||||
assert( p==pIndex ); /* Malloc must have failed */
|
||||
|
@ -4087,9 +4087,9 @@ void sqlite3CreateIndex(
|
|||
sqlite3BeginWriteOperation(pParse, 1, iDb);
|
||||
|
||||
/* Create the rootpage for the index using CreateIndex. But before
|
||||
** doing so, code a Noop instruction and store its address in
|
||||
** Index.tnum. This is required in case this index is actually a
|
||||
** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
|
||||
** doing so, code a Noop instruction and store its address in
|
||||
** Index.tnum. This is required in case this index is actually a
|
||||
** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
|
||||
** that case the convertToWithoutRowidTable() routine will replace
|
||||
** the Noop with a Goto to jump over the VDBE code generated below. */
|
||||
pIndex->tnum = (Pgno)sqlite3VdbeAddOp0(v, OP_Noop);
|
||||
|
@ -4113,7 +4113,7 @@ void sqlite3CreateIndex(
|
|||
|
||||
/* Add an entry in sqlite_schema for this index
|
||||
*/
|
||||
sqlite3NestedParse(pParse,
|
||||
sqlite3NestedParse(pParse,
|
||||
"INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);",
|
||||
db->aDb[iDb].zDbSName,
|
||||
pIndex->zName,
|
||||
|
@ -4215,7 +4215,7 @@ void sqlite3DefaultRowEst(Index *pIdx){
|
|||
/* Indexes with default row estimates should not have stat1 data */
|
||||
assert( !pIdx->hasStat1 );
|
||||
|
||||
/* Set the first entry (number of rows in the index) to the estimated
|
||||
/* Set the first entry (number of rows in the index) to the estimated
|
||||
** number of rows in the table, or half the number of rows in the table
|
||||
** for a partial index.
|
||||
**
|
||||
|
@ -4510,7 +4510,7 @@ SrcList *sqlite3SrcListEnlarge(
|
|||
** database name prefix. Like this: "database.table". The pDatabase
|
||||
** points to the table name and the pTable points to the database name.
|
||||
** The SrcList.a[].zName field is filled with the table name which might
|
||||
** come from pTable (if pDatabase is NULL) or from pDatabase.
|
||||
** come from pTable (if pDatabase is NULL) or from pDatabase.
|
||||
** SrcList.a[].zDatabase is filled with the database name from pTable,
|
||||
** or with NULL if no database is specified.
|
||||
**
|
||||
|
@ -4641,7 +4641,7 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
|||
SrcItem *pItem;
|
||||
sqlite3 *db = pParse->db;
|
||||
if( !p && (pOn || pUsing) ){
|
||||
sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s",
|
||||
sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s",
|
||||
(pOn ? "ON" : "USING")
|
||||
);
|
||||
goto append_from_error;
|
||||
|
@ -4676,7 +4676,7 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
|||
}
|
||||
|
||||
/*
|
||||
** Add an INDEXED BY or NOT INDEXED clause to the most recently added
|
||||
** Add an INDEXED BY or NOT INDEXED clause to the most recently added
|
||||
** element of the source-list passed as the second argument.
|
||||
*/
|
||||
void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
|
||||
|
@ -4689,7 +4689,7 @@ void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
|
|||
assert( pItem->fg.isIndexedBy==0 );
|
||||
assert( pItem->fg.isTabFunc==0 );
|
||||
if( pIndexedBy->n==1 && !pIndexedBy->z ){
|
||||
/* A "NOT INDEXED" clause was supplied. See parse.y
|
||||
/* A "NOT INDEXED" clause was supplied. See parse.y
|
||||
** construct "indexed_opt" for details. */
|
||||
pItem->fg.notIndexed = 1;
|
||||
}else{
|
||||
|
@ -4703,7 +4703,7 @@ void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
|
|||
** Append the contents of SrcList p2 to SrcList p1 and return the resulting
|
||||
** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
|
||||
** are deleted by this function.
|
||||
*/
|
||||
*/
|
||||
SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
|
||||
assert( p1 && p1->nSrc==1 );
|
||||
if( p2 ){
|
||||
|
@ -4808,7 +4808,7 @@ void sqlite3EndTransaction(Parse *pParse, int eType){
|
|||
assert( pParse->db!=0 );
|
||||
assert( eType==TK_COMMIT || eType==TK_END || eType==TK_ROLLBACK );
|
||||
isRollback = eType==TK_ROLLBACK;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION,
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION,
|
||||
isRollback ? "ROLLBACK" : "COMMIT", 0, 0) ){
|
||||
return;
|
||||
}
|
||||
|
@ -4820,7 +4820,7 @@ void sqlite3EndTransaction(Parse *pParse, int eType){
|
|||
|
||||
/*
|
||||
** This function is called by the parser when it parses a command to create,
|
||||
** release or rollback an SQL savepoint.
|
||||
** release or rollback an SQL savepoint.
|
||||
*/
|
||||
void sqlite3Savepoint(Parse *pParse, int op, Token *pName){
|
||||
char *zName = sqlite3NameFromToken(pParse->db, pName);
|
||||
|
@ -4847,7 +4847,7 @@ int sqlite3OpenTempDatabase(Parse *pParse){
|
|||
if( db->aDb[1].pBt==0 && !pParse->explain ){
|
||||
int rc;
|
||||
Btree *pBt;
|
||||
static const int flags =
|
||||
static const int flags =
|
||||
SQLITE_OPEN_READWRITE |
|
||||
SQLITE_OPEN_CREATE |
|
||||
SQLITE_OPEN_EXCLUSIVE |
|
||||
|
@ -4895,7 +4895,7 @@ void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
|
|||
|
||||
|
||||
/*
|
||||
** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
|
||||
** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
|
||||
** attached database. Otherwise, invoke it for the database named zDb only.
|
||||
*/
|
||||
void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){
|
||||
|
@ -4941,9 +4941,9 @@ void sqlite3MultiWrite(Parse *pParse){
|
|||
pToplevel->isMultiWrite = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** The code generator calls this routine if is discovers that it is
|
||||
** possible to abort a statement prior to completion. In order to
|
||||
** possible to abort a statement prior to completion. In order to
|
||||
** perform this abort without corrupting the database, we need to make
|
||||
** sure that the statement is protected by a statement transaction.
|
||||
**
|
||||
|
@ -4952,7 +4952,7 @@ void sqlite3MultiWrite(Parse *pParse){
|
|||
** such that the abort must occur after the multiwrite. This makes
|
||||
** some statements involving the REPLACE conflict resolution algorithm
|
||||
** go a little faster. But taking advantage of this time dependency
|
||||
** makes it more difficult to prove that the code is correct (in
|
||||
** makes it more difficult to prove that the code is correct (in
|
||||
** particular, it prevents us from writing an effective
|
||||
** implementation of sqlite3AssertMayAbort()) and so we have chosen
|
||||
** to take the safe route and skip the optimization.
|
||||
|
@ -4999,7 +4999,7 @@ void sqlite3UniqueConstraint(
|
|||
StrAccum errMsg;
|
||||
Table *pTab = pIdx->pTable;
|
||||
|
||||
sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
|
||||
sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
|
||||
pParse->db->aLimit[SQLITE_LIMIT_LENGTH]);
|
||||
if( pIdx->aColExpr ){
|
||||
sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
|
||||
|
@ -5015,8 +5015,8 @@ void sqlite3UniqueConstraint(
|
|||
}
|
||||
}
|
||||
zErr = sqlite3StrAccumFinish(&errMsg);
|
||||
sqlite3HaltConstraint(pParse,
|
||||
IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
|
||||
sqlite3HaltConstraint(pParse,
|
||||
IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
|
||||
: SQLITE_CONSTRAINT_UNIQUE,
|
||||
onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
|
||||
}
|
||||
|
@ -5028,7 +5028,7 @@ void sqlite3UniqueConstraint(
|
|||
void sqlite3RowidConstraint(
|
||||
Parse *pParse, /* Parsing context */
|
||||
int onError, /* Conflict resolution algorithm */
|
||||
Table *pTab /* The table with the non-unique rowid */
|
||||
Table *pTab /* The table with the non-unique rowid */
|
||||
){
|
||||
char *zMsg;
|
||||
int rc;
|
||||
|
@ -5270,8 +5270,8 @@ void sqlite3CteDelete(sqlite3 *db, Cte *pCte){
|
|||
sqlite3DbFree(db, pCte);
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is invoked once per CTE by the parser while parsing a
|
||||
/*
|
||||
** This routine is invoked once per CTE by the parser while parsing a
|
||||
** WITH clause. The CTE described by teh third argument is added to
|
||||
** the WITH clause of the second argument. If the second argument is
|
||||
** NULL, then a new WITH argument is created.
|
||||
|
|
22
third_party/sqlite3/callback.c
vendored
22
third_party/sqlite3/callback.c
vendored
|
@ -73,7 +73,7 @@ static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
|
|||
** that have not been defined by sqlite3_create_collation() etc.
|
||||
**
|
||||
** If required, this routine calls the 'collation needed' callback to
|
||||
** request a definition of the collating sequence. If this doesn't work,
|
||||
** request a definition of the collating sequence. If this doesn't work,
|
||||
** an equivalent collating sequence that uses a text encoding different
|
||||
** from the main database is substituted, if one is available.
|
||||
*/
|
||||
|
@ -127,7 +127,7 @@ static CollSeq *findCollSeqEntry(
|
|||
memcpy(pColl[0].zName, zName, nName);
|
||||
pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
|
||||
|
||||
/* If a malloc() failure occurred in sqlite3HashInsert(), it will
|
||||
/* If a malloc() failure occurred in sqlite3HashInsert(), it will
|
||||
** return the pColl pointer to be deleted (because it wasn't added
|
||||
** to the hash table).
|
||||
*/
|
||||
|
@ -183,7 +183,7 @@ void sqlite3SetTextEncoding(sqlite3 *db, u8 enc){
|
|||
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
|
||||
db->enc = enc;
|
||||
/* EVIDENCE-OF: R-08308-17224 The default collating function for all
|
||||
** strings is BINARY.
|
||||
** strings is BINARY.
|
||||
*/
|
||||
db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
|
||||
}
|
||||
|
@ -192,8 +192,8 @@ void sqlite3SetTextEncoding(sqlite3 *db, u8 enc){
|
|||
** This function is responsible for invoking the collation factory callback
|
||||
** or substituting a collation sequence of a different encoding when the
|
||||
** requested collation sequence is not available in the desired encoding.
|
||||
**
|
||||
** If it is not NULL, then pColl must point to the database native encoding
|
||||
**
|
||||
** If it is not NULL, then pColl must point to the database native encoding
|
||||
** collation sequence with name zName, length nName.
|
||||
**
|
||||
** The return value is either the collation sequence to be used in database
|
||||
|
@ -277,7 +277,7 @@ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName){
|
|||
** is also -1. In other words, we are searching for a function that
|
||||
** takes a variable number of arguments.
|
||||
**
|
||||
** If nArg is -2 that means that we are searching for any function
|
||||
** If nArg is -2 that means that we are searching for any function
|
||||
** regardless of the number of arguments it uses, so return a positive
|
||||
** match score for any
|
||||
**
|
||||
|
@ -371,8 +371,8 @@ void sqlite3InsertBuiltinFuncs(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Locate a user function given a name, a number of arguments and a flag
|
||||
|
@ -433,7 +433,7 @@ FuncDef *sqlite3FindFunction(
|
|||
** have fields overwritten with new information appropriate for the
|
||||
** new function. But the FuncDefs for built-in functions are read-only.
|
||||
** So we must not search for built-ins when creating a new function.
|
||||
*/
|
||||
*/
|
||||
if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
|
||||
bestScore = 0;
|
||||
h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName);
|
||||
|
@ -452,7 +452,7 @@ FuncDef *sqlite3FindFunction(
|
|||
** exact match for the name, number of arguments and encoding, then add a
|
||||
** new entry to the hash table and return it.
|
||||
*/
|
||||
if( createFlag && bestScore<FUNC_PERFECT_MATCH &&
|
||||
if( createFlag && bestScore<FUNC_PERFECT_MATCH &&
|
||||
(pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
|
||||
FuncDef *pOther;
|
||||
u8 *z;
|
||||
|
@ -479,7 +479,7 @@ FuncDef *sqlite3FindFunction(
|
|||
|
||||
/*
|
||||
** Free all resources held by the schema structure. The void* argument points
|
||||
** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
|
||||
** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
|
||||
** pointer itself, it just cleans up subsidiary resources (i.e. the contents
|
||||
** of the schema hash tables).
|
||||
**
|
||||
|
|
2
third_party/sqlite3/complete.c
vendored
2
third_party/sqlite3/complete.c
vendored
|
@ -69,7 +69,7 @@ extern const char sqlite3IsEbcdicIdChar[];
|
|||
** (2) NORMAL We are in the middle of statement which ends with a single
|
||||
** semicolon.
|
||||
**
|
||||
** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
|
||||
** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
|
||||
** a statement.
|
||||
**
|
||||
** (4) CREATE The keyword CREATE has been seen at the beginning of a
|
||||
|
|
10
third_party/sqlite3/completion.c
vendored
10
third_party/sqlite3/completion.c
vendored
|
@ -348,11 +348,11 @@ static int completionEof(sqlite3_vtab_cursor *cur){
|
|||
/*
|
||||
** This method is called to "rewind" the completion_cursor object back
|
||||
** to the first row of output. This method is always called at least
|
||||
** once prior to any call to completionColumn() or completionRowid() or
|
||||
** once prior to any call to completionColumn() or completionRowid() or
|
||||
** completionEof().
|
||||
*/
|
||||
static int completionFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -444,7 +444,7 @@ static int completionBestIndex(
|
|||
}
|
||||
|
||||
/*
|
||||
** This following structure defines all the methods for the
|
||||
** This following structure defines all the methods for the
|
||||
** completion virtual table.
|
||||
*/
|
||||
static sqlite3_module completionModule = {
|
||||
|
@ -485,8 +485,8 @@ int sqlite3CompletionVtabInit(sqlite3 *db){
|
|||
}
|
||||
|
||||
int sqlite3_completion_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
|
|
10
third_party/sqlite3/ctime.c
vendored
10
third_party/sqlite3/ctime.c
vendored
|
@ -29,7 +29,7 @@
|
|||
#define CTIMEOPT_VAL2(opt) CTIMEOPT_VAL2_(opt)
|
||||
|
||||
/*
|
||||
** An array of names of all compile-time options. This array should
|
||||
** An array of names of all compile-time options. This array should
|
||||
** be sorted A-Z.
|
||||
**
|
||||
** This array looks large, but in a typical installation actually uses
|
||||
|
@ -38,8 +38,8 @@
|
|||
*/
|
||||
static const char * const sqlite3azCompileOpt[] = {
|
||||
|
||||
/*
|
||||
** BEGIN CODE GENERATED BY tool/mkctime.tcl
|
||||
/*
|
||||
** BEGIN CODE GENERATED BY tool/mkctime.tcl
|
||||
*/
|
||||
#if SQLITE_32BIT_ROWID
|
||||
"32BIT_ROWID",
|
||||
|
@ -744,8 +744,8 @@ static const char * const sqlite3azCompileOpt[] = {
|
|||
#if SQLITE_ZERO_MALLOC
|
||||
"ZERO_MALLOC",
|
||||
#endif
|
||||
/*
|
||||
** END CODE GENERATED BY tool/mkctime.tcl
|
||||
/*
|
||||
** END CODE GENERATED BY tool/mkctime.tcl
|
||||
*/
|
||||
};
|
||||
|
||||
|
|
22
third_party/sqlite3/date.c
vendored
22
third_party/sqlite3/date.c
vendored
|
@ -371,7 +371,7 @@ static void setRawDateNumber(DateTime *p, double r){
|
|||
** The following are acceptable forms for the input string:
|
||||
**
|
||||
** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
|
||||
** DDDD.DD
|
||||
** DDDD.DD
|
||||
** now
|
||||
**
|
||||
** In the first form, the +/-HH:MM is always optional. The fractional
|
||||
|
@ -381,8 +381,8 @@ static void setRawDateNumber(DateTime *p, double r){
|
|||
** as there is a year and date.
|
||||
*/
|
||||
static int parseDateOrTime(
|
||||
sqlite3_context *context,
|
||||
const char *zDate,
|
||||
sqlite3_context *context,
|
||||
const char *zDate,
|
||||
DateTime *p
|
||||
){
|
||||
double r;
|
||||
|
@ -403,7 +403,7 @@ static int parseDateOrTime(
|
|||
** Multiplying this by 86400000 gives 464269060799999 as the maximum value
|
||||
** for DateTime.iJD.
|
||||
**
|
||||
** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with
|
||||
** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with
|
||||
** such a large integer literal, so we have to encode it.
|
||||
*/
|
||||
#define INT_464269060799999 ((((i64)0x1a640)<<32)|0x1072fdff)
|
||||
|
@ -485,14 +485,14 @@ static void clearYMD_HMS_TZ(DateTime *p){
|
|||
#ifndef SQLITE_OMIT_LOCALTIME
|
||||
/*
|
||||
** On recent Windows platforms, the localtime_s() function is available
|
||||
** as part of the "Secure CRT". It is essentially equivalent to
|
||||
** localtime_r() available under most POSIX platforms, except that the
|
||||
** as part of the "Secure CRT". It is essentially equivalent to
|
||||
** localtime_r() available under most POSIX platforms, except that the
|
||||
** order of the parameters is reversed.
|
||||
**
|
||||
** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
|
||||
**
|
||||
** If the user has not indicated to use localtime_r() or localtime_s()
|
||||
** already, check for an MSVC build environment that provides
|
||||
** already, check for an MSVC build environment that provides
|
||||
** localtime_s().
|
||||
*/
|
||||
#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S \
|
||||
|
@ -548,7 +548,7 @@ static int osLocaltime(time_t *t, struct tm *pTm){
|
|||
/*
|
||||
** Compute the difference (in milliseconds) between localtime and UTC
|
||||
** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
|
||||
** return this value and set *pRc to SQLITE_OK.
|
||||
** return this value and set *pRc to SQLITE_OK.
|
||||
**
|
||||
** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value
|
||||
** is undefined in this case.
|
||||
|
@ -875,9 +875,9 @@ static int parseModifier(
|
|||
** then assume a default value of "now" for argv[0].
|
||||
*/
|
||||
static int isDate(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv,
|
||||
DateTime *p
|
||||
){
|
||||
int i, n;
|
||||
|
|
72
third_party/sqlite3/dbdata.c
vendored
72
third_party/sqlite3/dbdata.c
vendored
|
@ -78,7 +78,7 @@
|
|||
|
||||
SQLITE_EXTENSION_INIT1
|
||||
|
||||
#define DBDATA_PADDING_BYTES 100
|
||||
#define DBDATA_PADDING_BYTES 100
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef struct DbdataTable DbdataTable;
|
||||
|
@ -105,7 +105,7 @@ struct DbdataCursor {
|
|||
int iField; /* Current field number */
|
||||
u8 *pHdrPtr;
|
||||
u8 *pPtr;
|
||||
|
||||
|
||||
sqlite3_int64 iIntkey; /* Integer key value */
|
||||
};
|
||||
|
||||
|
@ -144,7 +144,7 @@ struct DbdataTable {
|
|||
")"
|
||||
|
||||
/*
|
||||
** Connect to an sqlite_dbdata (pAux==0) or sqlite_dbptr (pAux!=0) virtual
|
||||
** Connect to an sqlite_dbdata (pAux==0) or sqlite_dbptr (pAux!=0) virtual
|
||||
** table.
|
||||
*/
|
||||
static int dbdataConnect(
|
||||
|
@ -263,7 +263,7 @@ static int dbdataOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
|
|||
}
|
||||
|
||||
/*
|
||||
** Restore a cursor object to the state it was in when first allocated
|
||||
** Restore a cursor object to the state it was in when first allocated
|
||||
** by dbdataOpen().
|
||||
*/
|
||||
static void dbdataResetCursor(DbdataCursor *pCsr){
|
||||
|
@ -294,8 +294,8 @@ static int dbdataClose(sqlite3_vtab_cursor *pCursor){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Utility methods to decode 16 and 32-bit big-endian unsigned integers.
|
||||
/*
|
||||
** Utility methods to decode 16 and 32-bit big-endian unsigned integers.
|
||||
*/
|
||||
static unsigned int get_uint16(unsigned char *a){
|
||||
return (a[0]<<8)|a[1];
|
||||
|
@ -402,26 +402,26 @@ static int dbdataValueBytes(int eType){
|
|||
** result of context object pCtx.
|
||||
*/
|
||||
static void dbdataValue(
|
||||
sqlite3_context *pCtx,
|
||||
int eType,
|
||||
sqlite3_context *pCtx,
|
||||
int eType,
|
||||
u8 *pData,
|
||||
int nData
|
||||
){
|
||||
if( eType>=0 && dbdataValueBytes(eType)<=nData ){
|
||||
switch( eType ){
|
||||
case 0:
|
||||
case 10:
|
||||
case 11:
|
||||
case 0:
|
||||
case 10:
|
||||
case 11:
|
||||
sqlite3_result_null(pCtx);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
|
||||
case 8:
|
||||
sqlite3_result_int(pCtx, 0);
|
||||
break;
|
||||
case 9:
|
||||
sqlite3_result_int(pCtx, 1);
|
||||
break;
|
||||
|
||||
|
||||
case 1: case 2: case 3: case 4: case 5: case 6: case 7: {
|
||||
sqlite3_uint64 v = (signed char)pData[0];
|
||||
pData++;
|
||||
|
@ -433,7 +433,7 @@ static void dbdataValue(
|
|||
case 3: v = (v<<8) + pData[0]; pData++;
|
||||
case 2: v = (v<<8) + pData[0]; pData++;
|
||||
}
|
||||
|
||||
|
||||
if( eType==7 ){
|
||||
double r;
|
||||
memcpy(&r, &v, sizeof(r));
|
||||
|
@ -443,7 +443,7 @@ static void dbdataValue(
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default: {
|
||||
int n = ((eType-12) / 2);
|
||||
if( eType % 2 ){
|
||||
|
@ -504,7 +504,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
|
|||
int iHdr;
|
||||
int U, X;
|
||||
int nLocal;
|
||||
|
||||
|
||||
switch( pCsr->aPage[iOff] ){
|
||||
case 0x02:
|
||||
nPointer = 4;
|
||||
|
@ -523,29 +523,29 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
|
|||
if( pCsr->iCell>=pCsr->nCell ){
|
||||
bNextPage = 1;
|
||||
}else{
|
||||
|
||||
|
||||
iOff += 8 + nPointer + pCsr->iCell*2;
|
||||
if( iOff>pCsr->nPage ){
|
||||
bNextPage = 1;
|
||||
}else{
|
||||
iOff = get_uint16(&pCsr->aPage[iOff]);
|
||||
}
|
||||
|
||||
|
||||
/* For an interior node cell, skip past the child-page number */
|
||||
iOff += nPointer;
|
||||
|
||||
|
||||
/* Load the "byte of payload including overflow" field */
|
||||
if( bNextPage || iOff>pCsr->nPage ){
|
||||
bNextPage = 1;
|
||||
}else{
|
||||
iOff += dbdataGetVarint(&pCsr->aPage[iOff], &nPayload);
|
||||
}
|
||||
|
||||
|
||||
/* If this is a leaf intkey cell, load the rowid */
|
||||
if( bHasRowid && !bNextPage && iOff<pCsr->nPage ){
|
||||
iOff += dbdataGetVarint(&pCsr->aPage[iOff], &pCsr->iIntkey);
|
||||
}
|
||||
|
||||
|
||||
/* Figure out how much data to read from the local page */
|
||||
U = pCsr->nPage;
|
||||
if( bHasRowid ){
|
||||
|
@ -571,7 +571,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
|
|||
}else{
|
||||
|
||||
/* Allocate space for payload. And a bit more to catch small buffer
|
||||
** overruns caused by attempting to read a varint or similar from
|
||||
** overruns caused by attempting to read a varint or similar from
|
||||
** near the end of a corrupt record. */
|
||||
pCsr->pRec = (u8*)sqlite3_malloc64(nPayload+DBDATA_PADDING_BYTES);
|
||||
if( pCsr->pRec==0 ) return SQLITE_NOMEM;
|
||||
|
@ -604,7 +604,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
|
|||
sqlite3_free(aOvfl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
iHdr = dbdataGetVarint(pCsr->pRec, &nHdr);
|
||||
pCsr->nHdr = nHdr;
|
||||
pCsr->pHdrPtr = &pCsr->pRec[iHdr];
|
||||
|
@ -650,7 +650,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Return true if the cursor is at EOF.
|
||||
*/
|
||||
static int dbdataEof(sqlite3_vtab_cursor *pCursor){
|
||||
|
@ -658,9 +658,9 @@ static int dbdataEof(sqlite3_vtab_cursor *pCursor){
|
|||
return pCsr->aPage==0;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Determine the size in pages of database zSchema (where zSchema is
|
||||
** "main", "temp" or the name of an attached database) and set
|
||||
** "main", "temp" or the name of an attached database) and set
|
||||
** pCsr->szDb accordingly. If successful, return SQLITE_OK. Otherwise,
|
||||
** an SQLite error code.
|
||||
*/
|
||||
|
@ -682,11 +682,11 @@ static int dbdataDbsize(DbdataCursor *pCsr, const char *zSchema){
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** xFilter method for sqlite_dbdata and sqlite_dbptr.
|
||||
*/
|
||||
static int dbdataFilter(
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -713,7 +713,7 @@ static int dbdataFilter(
|
|||
pCsr->pStmt = pTab->pStmt;
|
||||
pTab->pStmt = 0;
|
||||
}else{
|
||||
rc = sqlite3_prepare_v2(pTab->db,
|
||||
rc = sqlite3_prepare_v2(pTab->db,
|
||||
"SELECT data FROM sqlite_dbpage(?) WHERE pgno=?", -1,
|
||||
&pCsr->pStmt, 0
|
||||
);
|
||||
|
@ -730,12 +730,12 @@ static int dbdataFilter(
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Return a column for the sqlite_dbdata or sqlite_dbptr table.
|
||||
*/
|
||||
static int dbdataColumn(
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_context *ctx,
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_context *ctx,
|
||||
int i
|
||||
){
|
||||
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
|
||||
|
@ -788,7 +788,7 @@ static int dbdataColumn(
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Return the rowid for an sqlite_dbdata or sqlite_dptr table.
|
||||
*/
|
||||
static int dbdataRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
|
||||
|
@ -837,8 +837,8 @@ static int sqlite3DbdataRegister(sqlite3 *db){
|
|||
}
|
||||
|
||||
int sqlite3_dbdata_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
|
|
12
third_party/sqlite3/dbpage.c
vendored
12
third_party/sqlite3/dbpage.c
vendored
|
@ -76,7 +76,7 @@ static int dbpageConnect(
|
|||
int rc = SQLITE_OK;
|
||||
|
||||
sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
|
||||
if( rc==SQLITE_OK ){
|
||||
pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable));
|
||||
|
@ -216,7 +216,7 @@ static int dbpageEof(sqlite3_vtab_cursor *pCursor){
|
|||
** idxStr is not used
|
||||
*/
|
||||
static int dbpageFilter(
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -227,7 +227,7 @@ static int dbpageFilter(
|
|||
Btree *pBt;
|
||||
|
||||
/* Default setting is no rows of result */
|
||||
pCsr->pgno = 1;
|
||||
pCsr->pgno = 1;
|
||||
pCsr->mxPgno = 0;
|
||||
|
||||
if( idxNum & 2 ){
|
||||
|
@ -262,8 +262,8 @@ static int dbpageFilter(
|
|||
}
|
||||
|
||||
static int dbpageColumn(
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_context *ctx,
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_context *ctx,
|
||||
int i
|
||||
){
|
||||
DbpageCursor *pCsr = (DbpageCursor *)pCursor;
|
||||
|
@ -340,7 +340,7 @@ static int dbpageUpdate(
|
|||
goto update_fail;
|
||||
}
|
||||
szPage = sqlite3BtreeGetPageSize(pBt);
|
||||
if( sqlite3_value_type(argv[3])!=SQLITE_BLOB
|
||||
if( sqlite3_value_type(argv[3])!=SQLITE_BLOB
|
||||
|| sqlite3_value_bytes(argv[3])!=szPage
|
||||
){
|
||||
zErr = "bad page value";
|
||||
|
|
30
third_party/sqlite3/dbstat.c
vendored
30
third_party/sqlite3/dbstat.c
vendored
|
@ -29,22 +29,22 @@
|
|||
|
||||
/*
|
||||
** Page paths:
|
||||
**
|
||||
** The value of the 'path' column describes the path taken from the
|
||||
** root-node of the b-tree structure to each page. The value of the
|
||||
**
|
||||
** The value of the 'path' column describes the path taken from the
|
||||
** root-node of the b-tree structure to each page. The value of the
|
||||
** root-node path is '/'.
|
||||
**
|
||||
** The value of the path for the left-most child page of the root of
|
||||
** a b-tree is '/000/'. (Btrees store content ordered from left to right
|
||||
** so the pages to the left have smaller keys than the pages to the right.)
|
||||
** The next to left-most child of the root page is
|
||||
** '/001', and so on, each sibling page identified by a 3-digit hex
|
||||
** '/001', and so on, each sibling page identified by a 3-digit hex
|
||||
** value. The children of the 451st left-most sibling have paths such
|
||||
** as '/1c2/000/, '/1c2/001/' etc.
|
||||
**
|
||||
** Overflow pages are specified by appending a '+' character and a
|
||||
** Overflow pages are specified by appending a '+' character and a
|
||||
** six-digit hexadecimal value to the path to the cell they are linked
|
||||
** from. For example, the three overflow pages in a chain linked from
|
||||
** from. For example, the three overflow pages in a chain linked from
|
||||
** the left-most cell of the 450th child of the root page are identified
|
||||
** by the paths:
|
||||
**
|
||||
|
@ -58,7 +58,7 @@
|
|||
**
|
||||
** '/1c2/000/' // Left-most child of 451st child of root
|
||||
*/
|
||||
static const char zDbstatSchema[] =
|
||||
static const char zDbstatSchema[] =
|
||||
"CREATE TABLE x("
|
||||
" name TEXT," /* 0 Name of table or index */
|
||||
" path TEXT," /* 1 Path to page from root (NULL for agg) */
|
||||
|
@ -253,8 +253,8 @@ static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
|||
}
|
||||
pIdxInfo->estimatedCost = 1.0;
|
||||
|
||||
/* Records are always returned in ascending order of (name, path).
|
||||
** If this will satisfy the client, set the orderByConsumed flag so that
|
||||
/* Records are always returned in ascending order of (name, path).
|
||||
** If this will satisfy the client, set the orderByConsumed flag so that
|
||||
** SQLite does not do an external sort.
|
||||
*/
|
||||
if( ( pIdxInfo->nOrderBy==1
|
||||
|
@ -360,7 +360,7 @@ static int getLocalPayload(
|
|||
int nLocal;
|
||||
int nMinLocal;
|
||||
int nMaxLocal;
|
||||
|
||||
|
||||
if( flags==0x0D ){ /* Table leaf node */
|
||||
nMinLocal = (nUsable - 12) * 32 / 255 - 23;
|
||||
nMaxLocal = nUsable - 35;
|
||||
|
@ -471,7 +471,7 @@ static int statDecodePage(Btree *pBt, StatPage *p){
|
|||
if( rc!=SQLITE_OK ){
|
||||
assert( pPg==0 );
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
|
||||
sqlite3PagerUnref(pPg);
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ statNextRestart:
|
|||
while( pCell->iOvfl<pCell->nOvfl ){
|
||||
int nUsable, iOvfl;
|
||||
sqlite3BtreeEnter(pBt);
|
||||
nUsable = sqlite3BtreeGetPageSize(pBt) -
|
||||
nUsable = sqlite3BtreeGetPageSize(pBt) -
|
||||
sqlite3BtreeGetReserveNoMutex(pBt);
|
||||
sqlite3BtreeLeave(pBt);
|
||||
pCsr->nPage++;
|
||||
|
@ -686,7 +686,7 @@ static int statEof(sqlite3_vtab_cursor *pCursor){
|
|||
** meaning of the bits in idxNum.
|
||||
*/
|
||||
static int statFilter(
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -752,8 +752,8 @@ static int statFilter(
|
|||
}
|
||||
|
||||
static int statColumn(
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_context *ctx,
|
||||
sqlite3_vtab_cursor *pCursor,
|
||||
sqlite3_context *ctx,
|
||||
int i
|
||||
){
|
||||
StatCursor *pCsr = (StatCursor *)pCursor;
|
||||
|
|
8
third_party/sqlite3/decimal.c
vendored
8
third_party/sqlite3/decimal.c
vendored
|
@ -135,7 +135,7 @@ static Decimal *decimal_new(
|
|||
p->nFrac = 0;
|
||||
}
|
||||
}
|
||||
if( iExp>0 ){
|
||||
if( iExp>0 ){
|
||||
p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
|
||||
if( p->a==0 ) goto new_no_mem;
|
||||
memset(p->a+p->nDigit, 0, iExp);
|
||||
|
@ -537,7 +537,7 @@ static void decimalMulFunc(
|
|||
int i, j, k;
|
||||
int minFrac;
|
||||
if( pA==0 || pA->oom || pA->isNull
|
||||
|| pB==0 || pB->oom || pB->isNull
|
||||
|| pB==0 || pB->oom || pB->isNull
|
||||
){
|
||||
goto mul_end;
|
||||
}
|
||||
|
@ -580,8 +580,8 @@ mul_end:
|
|||
}
|
||||
|
||||
int sqlite3_decimal_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
|
|
78
third_party/sqlite3/delete.c
vendored
78
third_party/sqlite3/delete.c
vendored
|
@ -21,7 +21,7 @@
|
|||
** (as in the FROM clause of a SELECT statement) in this case it contains
|
||||
** the name of a single table, as one might find in an INSERT, DELETE,
|
||||
** or UPDATE statement. Look up that table in the symbol table and
|
||||
** return a pointer. Set an error message and return NULL if the table
|
||||
** return a pointer. Set an error message and return NULL if the table
|
||||
** name is not found or if any other error occurs.
|
||||
**
|
||||
** The following fields are initialized appropriate in pSrc:
|
||||
|
@ -54,7 +54,7 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
|||
** has been provided
|
||||
**
|
||||
** 2) It is a system table (i.e. sqlite_schema), this call is not
|
||||
** part of a nested parse and writable_schema pragma has not
|
||||
** part of a nested parse and writable_schema pragma has not
|
||||
** been specified
|
||||
**
|
||||
** 3) The table is a shadow table, the database connection is in
|
||||
|
@ -123,7 +123,7 @@ void sqlite3MaterializeView(
|
|||
assert( pFrom->a[0].pOn==0 );
|
||||
assert( pFrom->a[0].pUsing==0 );
|
||||
}
|
||||
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
|
||||
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
|
||||
SF_IncludeHidden, pLimit);
|
||||
sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
|
||||
sqlite3Select(pParse, pSel, &dest);
|
||||
|
@ -172,11 +172,11 @@ Expr *sqlite3LimitWhere(
|
|||
return pWhere;
|
||||
}
|
||||
|
||||
/* Generate a select expression tree to enforce the limit/offset
|
||||
/* Generate a select expression tree to enforce the limit/offset
|
||||
** term for the DELETE or UPDATE statement. For example:
|
||||
** DELETE FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
|
||||
** becomes:
|
||||
** DELETE FROM table_a WHERE rowid IN (
|
||||
** DELETE FROM table_a WHERE rowid IN (
|
||||
** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
|
||||
** );
|
||||
*/
|
||||
|
@ -220,7 +220,7 @@ Expr *sqlite3LimitWhere(
|
|||
}
|
||||
|
||||
/* generate the SELECT expression tree. */
|
||||
pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
|
||||
pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
|
||||
pOrderBy,0,pLimit
|
||||
);
|
||||
|
||||
|
@ -276,7 +276,7 @@ void sqlite3DeleteFrom(
|
|||
int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
|
||||
int bComplex; /* True if there are triggers or FKs or
|
||||
** subqueries in the WHERE clause */
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to delete from a view */
|
||||
Trigger *pTrigger; /* List of table triggers, if required */
|
||||
|
@ -335,7 +335,7 @@ void sqlite3DeleteFrom(
|
|||
}
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb<db->nDb );
|
||||
rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0,
|
||||
rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0,
|
||||
db->aDb[iDb].zDbSName);
|
||||
assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
|
||||
if( rcauth==SQLITE_DENY ){
|
||||
|
@ -371,7 +371,7 @@ void sqlite3DeleteFrom(
|
|||
*/
|
||||
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
|
||||
if( isView ){
|
||||
sqlite3MaterializeView(pParse, pTab,
|
||||
sqlite3MaterializeView(pParse, pTab,
|
||||
pWhere, pOrderBy, pLimit, iTabCur
|
||||
);
|
||||
iDataCur = iIdxCur = iTabCur;
|
||||
|
@ -404,7 +404,7 @@ void sqlite3DeleteFrom(
|
|||
#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
|
||||
/* Special case: A DELETE without a WHERE clause deletes everything.
|
||||
** It is easier just to erase the whole table. Prior to version 3.6.5,
|
||||
** this optimization caused the row change count (the value returned by
|
||||
** this optimization caused the row change count (the value returned by
|
||||
** API function sqlite3_count_changes) to be set incorrectly.
|
||||
**
|
||||
** The "rcauth==SQLITE_OK" terms is the
|
||||
|
@ -455,7 +455,7 @@ void sqlite3DeleteFrom(
|
|||
addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk);
|
||||
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
|
||||
}
|
||||
|
||||
|
||||
/* Construct a query to find the rowid or primary key for every row
|
||||
** to be deleted, based on the WHERE clause. Set variable eOnePass
|
||||
** to indicate the strategy used to implement this delete:
|
||||
|
@ -473,12 +473,12 @@ void sqlite3DeleteFrom(
|
|||
if( sqlite3WhereUsesDeferredSeek(pWInfo) ){
|
||||
sqlite3VdbeAddOp1(v, OP_FinishSeek, iTabCur);
|
||||
}
|
||||
|
||||
|
||||
/* Keep track of the number of rows to be deleted */
|
||||
if( memCnt ){
|
||||
sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
|
||||
}
|
||||
|
||||
|
||||
/* Extract the rowid or primary key for the current row */
|
||||
if( pPk ){
|
||||
for(i=0; i<nPk; i++){
|
||||
|
@ -491,7 +491,7 @@ void sqlite3DeleteFrom(
|
|||
iKey = ++pParse->nMem;
|
||||
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, -1, iKey);
|
||||
}
|
||||
|
||||
|
||||
if( eOnePass!=ONEPASS_OFF ){
|
||||
/* For ONEPASS, no need to store the rowid/primary-key. There is only
|
||||
** one, so just keep it in its register(s) and fall through to the
|
||||
|
@ -523,10 +523,10 @@ void sqlite3DeleteFrom(
|
|||
}
|
||||
sqlite3WhereEnd(pWInfo);
|
||||
}
|
||||
|
||||
/* Unless this is a view, open cursors for the table we are
|
||||
|
||||
/* Unless this is a view, open cursors for the table we are
|
||||
** deleting from and all its indices. If this is a view, then the
|
||||
** only effect this statement has is to fire the INSTEAD OF
|
||||
** only effect this statement has is to fire the INSTEAD OF
|
||||
** triggers.
|
||||
*/
|
||||
if( !isView ){
|
||||
|
@ -543,7 +543,7 @@ void sqlite3DeleteFrom(
|
|||
sqlite3VdbeJumpHereOrPopInst(v, iAddrOnce);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Set up a loop over the rowids/primary-keys that were found in the
|
||||
** where-clause loop above.
|
||||
*/
|
||||
|
@ -566,8 +566,8 @@ void sqlite3DeleteFrom(
|
|||
addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
|
||||
VdbeCoverage(v);
|
||||
assert( nKey==1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Delete the row */
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
if( IsVirtual(pTab) ){
|
||||
|
@ -590,7 +590,7 @@ void sqlite3DeleteFrom(
|
|||
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
|
||||
iKey, nKey, count, OE_Default, eOnePass, aiCurOnePass[1]);
|
||||
}
|
||||
|
||||
|
||||
/* End of the loop over all rowids/primary-keys. */
|
||||
if( eOnePass!=ONEPASS_OFF ){
|
||||
sqlite3VdbeResolveLabel(v, addrBypass);
|
||||
|
@ -601,7 +601,7 @@ void sqlite3DeleteFrom(
|
|||
}else{
|
||||
sqlite3VdbeGoto(v, addrLoop);
|
||||
sqlite3VdbeJumpHere(v, addrLoop);
|
||||
}
|
||||
}
|
||||
} /* End non-truncate path */
|
||||
|
||||
/* Update the sqlite_sequence table by storing the content of the
|
||||
|
@ -612,7 +612,7 @@ void sqlite3DeleteFrom(
|
|||
sqlite3AutoincrementEnd(pParse);
|
||||
}
|
||||
|
||||
/* Return the number of rows that were deleted. If this routine is
|
||||
/* Return the number of rows that were deleted. If this routine is
|
||||
** generating code because of a call to sqlite3NestedParse(), do not
|
||||
** invoke the callback function.
|
||||
*/
|
||||
|
@ -626,7 +626,7 @@ delete_from_cleanup:
|
|||
sqlite3AuthContextPop(&sContext);
|
||||
sqlite3SrcListDelete(db, pTabList);
|
||||
sqlite3ExprDelete(db, pWhere);
|
||||
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
|
||||
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
|
||||
sqlite3ExprListDelete(db, pOrderBy);
|
||||
sqlite3ExprDelete(db, pLimit);
|
||||
#endif
|
||||
|
@ -671,7 +671,7 @@ delete_from_cleanup:
|
|||
** and nPk before reading from it.
|
||||
**
|
||||
** If eMode is ONEPASS_MULTI, then this call is being made as part
|
||||
** of a ONEPASS delete that affects multiple rows. In this case, if
|
||||
** of a ONEPASS delete that affects multiple rows. In this case, if
|
||||
** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
|
||||
** iDataCur, then its position should be preserved following the delete
|
||||
** operation. Or, if iIdxNoSeek is not a valid cursor number, the
|
||||
|
@ -707,7 +707,7 @@ void sqlite3GenerateRowDelete(
|
|||
VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
|
||||
iDataCur, iIdxCur, iPk, (int)nPk));
|
||||
|
||||
/* Seek cursor iCur to the row to delete. If this row no longer exists
|
||||
/* Seek cursor iCur to the row to delete. If this row no longer exists
|
||||
** (this can happen if a trigger program has already deleted it), do
|
||||
** not attempt to delete it or fire any DELETE triggers. */
|
||||
iLabel = sqlite3VdbeMakeLabel(pParse);
|
||||
|
@ -717,7 +717,7 @@ void sqlite3GenerateRowDelete(
|
|||
VdbeCoverageIf(v, opSeek==OP_NotExists);
|
||||
VdbeCoverageIf(v, opSeek==OP_NotFound);
|
||||
}
|
||||
|
||||
|
||||
/* If there are any triggers to fire, allocate a range of registers to
|
||||
** use for the old.* references in the triggers. */
|
||||
if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
|
||||
|
@ -734,7 +734,7 @@ void sqlite3GenerateRowDelete(
|
|||
iOld = pParse->nMem+1;
|
||||
pParse->nMem += (1 + pTab->nCol);
|
||||
|
||||
/* Populate the OLD.* pseudo-table register array. These values will be
|
||||
/* Populate the OLD.* pseudo-table register array. These values will be
|
||||
** used by any BEFORE and AFTER triggers that exist. */
|
||||
sqlite3VdbeAddOp2(v, OP_Copy, iPk, iOld);
|
||||
for(iCol=0; iCol<pTab->nCol; iCol++){
|
||||
|
@ -748,11 +748,11 @@ void sqlite3GenerateRowDelete(
|
|||
|
||||
/* Invoke BEFORE DELETE trigger programs. */
|
||||
addrStart = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger,
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger,
|
||||
TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
|
||||
);
|
||||
|
||||
/* If any BEFORE triggers were coded, then seek the cursor to the
|
||||
/* If any BEFORE triggers were coded, then seek the cursor to the
|
||||
** row to be deleted again. It may be that the BEFORE triggers moved
|
||||
** the cursor or already deleted the row that the cursor was
|
||||
** pointing to.
|
||||
|
@ -769,21 +769,21 @@ void sqlite3GenerateRowDelete(
|
|||
}
|
||||
|
||||
/* Do FK processing. This call checks that any FK constraints that
|
||||
** refer to this table (i.e. constraints attached to other tables)
|
||||
** refer to this table (i.e. constraints attached to other tables)
|
||||
** are not violated by deleting this row. */
|
||||
sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* Delete the index and table entries. Skip this step if pTab is really
|
||||
** a view (in which case the only effect of the DELETE statement is to
|
||||
** fire the INSTEAD OF triggers).
|
||||
** fire the INSTEAD OF triggers).
|
||||
**
|
||||
** If variable 'count' is non-zero, then this OP_Delete instruction should
|
||||
** invoke the update-hook. The pre-update-hook, on the other hand should
|
||||
** be invoked unless table pTab is a system table. The difference is that
|
||||
** the update-hook is not invoked for rows removed by REPLACE, but the
|
||||
** the update-hook is not invoked for rows removed by REPLACE, but the
|
||||
** pre-update-hook is.
|
||||
*/
|
||||
*/
|
||||
if( pTab->pSelect==0 ){
|
||||
u8 p5 = 0;
|
||||
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
|
||||
|
@ -803,16 +803,16 @@ void sqlite3GenerateRowDelete(
|
|||
|
||||
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
|
||||
** handle rows (possibly in other tables) that refer via a foreign key
|
||||
** to the row just deleted. */
|
||||
** to the row just deleted. */
|
||||
sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
|
||||
|
||||
/* Invoke AFTER DELETE trigger programs. */
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger,
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger,
|
||||
TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
|
||||
);
|
||||
|
||||
/* Jump here if the row had already been deleted before any BEFORE
|
||||
** trigger programs were invoked. Or if a trigger program throws a
|
||||
** trigger programs were invoked. Or if a trigger program throws a
|
||||
** RAISE(IGNORE) exception. */
|
||||
sqlite3VdbeResolveLabel(v, iLabel);
|
||||
VdbeModuleComment((v, "END: GenRowDel()"));
|
||||
|
@ -897,7 +897,7 @@ void sqlite3GenerateRowIndexDelete(
|
|||
** its key into the same sequence of registers and if pPrior and pIdx share
|
||||
** a column in common, then the register corresponding to that column already
|
||||
** holds the correct value and the loading of that register is skipped.
|
||||
** This optimization is helpful when doing a DELETE or an INTEGRITY_CHECK
|
||||
** This optimization is helpful when doing a DELETE or an INTEGRITY_CHECK
|
||||
** on a table with multiple indices, and especially with the ROWID or
|
||||
** PRIMARY KEY columns of the index.
|
||||
*/
|
||||
|
@ -920,7 +920,7 @@ int sqlite3GenerateIndexKey(
|
|||
if( pIdx->pPartIdxWhere ){
|
||||
*piPartIdxLabel = sqlite3VdbeMakeLabel(pParse);
|
||||
pParse->iSelfTab = iDataCur + 1;
|
||||
sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
|
||||
sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
|
||||
SQLITE_JUMPIFNULL);
|
||||
pParse->iSelfTab = 0;
|
||||
pPrior = 0; /* Ticket a9efb42811fa41ee 2019-11-02;
|
||||
|
|
280
third_party/sqlite3/expr.c
vendored
280
third_party/sqlite3/expr.c
vendored
|
@ -32,7 +32,7 @@ char sqlite3TableColumnAffinity(Table *pTab, int iCol){
|
|||
** Return the 'affinity' of the expression pExpr if any.
|
||||
**
|
||||
** If pExpr is a column, a reference to a column via an 'AS' alias,
|
||||
** or a sub-select with a column as the return value, then the
|
||||
** or a sub-select with a column as the return value, then the
|
||||
** affinity of that column is returned. Otherwise, 0x00 is returned,
|
||||
** indicating no affinity for the expression.
|
||||
**
|
||||
|
@ -132,7 +132,7 @@ Expr *sqlite3ExprSkipCollate(Expr *pExpr){
|
|||
while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
|
||||
assert( pExpr->op==TK_COLLATE );
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
}
|
||||
return pExpr;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
|
|||
assert( pExpr->op==TK_COLLATE );
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pExpr;
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){
|
|||
Expr *pNext = p->pRight;
|
||||
/* The Expr.x union is never used at the same time as Expr.pRight */
|
||||
assert( p->x.pList==0 || p->pRight==0 );
|
||||
if( p->x.pList!=0
|
||||
if( p->x.pList!=0
|
||||
&& !db->mallocFailed
|
||||
&& ALWAYS(!ExprHasProperty(p, EP_xIsSelect))
|
||||
){
|
||||
|
@ -226,7 +226,7 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){
|
|||
break;
|
||||
}
|
||||
}
|
||||
if( sqlite3CheckCollSeq(pParse, pColl) ){
|
||||
if( sqlite3CheckCollSeq(pParse, pColl) ){
|
||||
pColl = 0;
|
||||
}
|
||||
return pColl;
|
||||
|
@ -346,8 +346,8 @@ static u8 binaryCompareP5(
|
|||
** it is not considered.
|
||||
*/
|
||||
CollSeq *sqlite3BinaryCompareCollSeq(
|
||||
Parse *pParse,
|
||||
const Expr *pLeft,
|
||||
Parse *pParse,
|
||||
const Expr *pLeft,
|
||||
const Expr *pRight
|
||||
){
|
||||
CollSeq *pColl;
|
||||
|
@ -425,7 +425,7 @@ int sqlite3ExprIsVector(Expr *pExpr){
|
|||
}
|
||||
|
||||
/*
|
||||
** If the expression passed as the only argument is of type TK_VECTOR
|
||||
** If the expression passed as the only argument is of type TK_VECTOR
|
||||
** return the number of expressions in the vector. Or, if the expression
|
||||
** is a sub-select, return the number of columns in the sub-select. For
|
||||
** any other type of expression, return 1.
|
||||
|
@ -475,7 +475,7 @@ Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
|
|||
** sqlite3ExprCode() will generate all necessary code to compute
|
||||
** the iField-th column of the vector expression pVector.
|
||||
**
|
||||
** It is ok for pVector to be a scalar (as long as iField==0).
|
||||
** It is ok for pVector to be a scalar (as long as iField==0).
|
||||
** In that case, this routine works like sqlite3ExprDup().
|
||||
**
|
||||
** The caller owns the returned Expr object and is responsible for
|
||||
|
@ -533,7 +533,7 @@ Expr *sqlite3ExprForVectorField(
|
|||
|
||||
/*
|
||||
** If expression pExpr is of type TK_SELECT, generate code to evaluate
|
||||
** it. Return the register in which the result is stored (or, if the
|
||||
** it. Return the register in which the result is stored (or, if the
|
||||
** sub-select returns more than one column, the first in an array
|
||||
** of registers in which the result is stored).
|
||||
**
|
||||
|
@ -555,10 +555,10 @@ static int exprCodeSubselect(Parse *pParse, Expr *pExpr){
|
|||
** the register number of a register that contains the value of
|
||||
** element iField of the vector.
|
||||
**
|
||||
** If pVector is a TK_SELECT expression, then code for it must have
|
||||
** If pVector is a TK_SELECT expression, then code for it must have
|
||||
** already been generated using the exprCodeSubselect() routine. In this
|
||||
** case parameter regSelect should be the first in an array of registers
|
||||
** containing the results of the sub-select.
|
||||
** containing the results of the sub-select.
|
||||
**
|
||||
** If pVector is of type TK_VECTOR, then code for the requested field
|
||||
** is generated. In this case (*pRegFree) may be set to the number of
|
||||
|
@ -624,10 +624,10 @@ static void codeVectorCompare(
|
|||
sqlite3ErrorMsg(pParse, "row value misused");
|
||||
return;
|
||||
}
|
||||
assert( pExpr->op==TK_EQ || pExpr->op==TK_NE
|
||||
|| pExpr->op==TK_IS || pExpr->op==TK_ISNOT
|
||||
|| pExpr->op==TK_LT || pExpr->op==TK_GT
|
||||
|| pExpr->op==TK_LE || pExpr->op==TK_GE
|
||||
assert( pExpr->op==TK_EQ || pExpr->op==TK_NE
|
||||
|| pExpr->op==TK_IS || pExpr->op==TK_ISNOT
|
||||
|| pExpr->op==TK_LT || pExpr->op==TK_GT
|
||||
|| pExpr->op==TK_LE || pExpr->op==TK_GE
|
||||
);
|
||||
assert( pExpr->op==op || (pExpr->op==TK_IS && op==TK_EQ)
|
||||
|| (pExpr->op==TK_ISNOT && op==TK_NE) );
|
||||
|
@ -643,7 +643,7 @@ static void codeVectorCompare(
|
|||
|
||||
for(i=0; 1 /*Loop exits by "break"*/; i++){
|
||||
int regFree1 = 0, regFree2 = 0;
|
||||
Expr *pL, *pR;
|
||||
Expr *pL, *pR;
|
||||
int r1, r2;
|
||||
assert( i>=0 && i<nLeft );
|
||||
r1 = exprVectorRegister(pParse, pLeft, i, regLeft, &pL, ®Free1);
|
||||
|
@ -689,7 +689,7 @@ int sqlite3ExprCheckHeight(Parse *pParse, int nHeight){
|
|||
int rc = SQLITE_OK;
|
||||
int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
|
||||
if( nHeight>mxHeight ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"Expression tree is too large (maximum depth %d)", mxHeight
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
|
@ -734,10 +734,10 @@ static void heightOfSelect(Select *pSelect, int *pnHeight){
|
|||
}
|
||||
|
||||
/*
|
||||
** Set the Expr.nHeight variable in the structure passed as an
|
||||
** argument. An expression with no children, Expr.pList or
|
||||
** Set the Expr.nHeight variable in the structure passed as an
|
||||
** argument. An expression with no children, Expr.pList or
|
||||
** Expr.pSelect member has a height of 1. Any other expression
|
||||
** has a height equal to the maximum height of any other
|
||||
** has a height equal to the maximum height of any other
|
||||
** referenced Expr plus one.
|
||||
**
|
||||
** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
|
||||
|
@ -762,7 +762,7 @@ static void exprSetHeight(Expr *p){
|
|||
** leave an error in pParse.
|
||||
**
|
||||
** Also propagate all EP_Propagate flags from the Expr.x.pList into
|
||||
** Expr.flags.
|
||||
** Expr.flags.
|
||||
*/
|
||||
void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
|
||||
if( pParse->nErr ) return;
|
||||
|
@ -782,7 +782,7 @@ int sqlite3SelectExprHeight(Select *p){
|
|||
#else /* ABOVE: Height enforcement enabled. BELOW: Height enforcement off */
|
||||
/*
|
||||
** Propagate all EP_Propagate flags from the Expr.x.pList into
|
||||
** Expr.flags.
|
||||
** Expr.flags.
|
||||
*/
|
||||
void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
|
||||
if( pParse->nErr ) return;
|
||||
|
@ -852,7 +852,7 @@ Expr *sqlite3ExprAlloc(
|
|||
}
|
||||
#if SQLITE_MAX_EXPR_DEPTH>0
|
||||
pNew->nHeight = 1;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
|
@ -959,7 +959,7 @@ Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
|
|||
return pRight;
|
||||
}else if( pRight==0 ){
|
||||
return pLeft;
|
||||
}else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
|
||||
}else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
|
||||
&& !IN_RENAME_OBJECT
|
||||
){
|
||||
sqlite3ExprDeferredDelete(pParse, pLeft);
|
||||
|
@ -1024,7 +1024,7 @@ void sqlite3ExprFunctionUsable(
|
|||
/* Functions prohibited in triggers and views if:
|
||||
** (1) tagged with SQLITE_DIRECTONLY
|
||||
** (2) not tagged with SQLITE_INNOCUOUS (which means it
|
||||
** is tagged with SQLITE_FUNC_UNSAFE) and
|
||||
** is tagged with SQLITE_FUNC_UNSAFE) and
|
||||
** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
|
||||
** that the schema is possibly tainted).
|
||||
*/
|
||||
|
@ -1035,7 +1035,7 @@ void sqlite3ExprFunctionUsable(
|
|||
|
||||
/*
|
||||
** Assign a variable number to an expression that encodes a wildcard
|
||||
** in the original SQL statement.
|
||||
** in the original SQL statement.
|
||||
**
|
||||
** Wildcards consisting of a single "?" are assigned the next sequential
|
||||
** variable number.
|
||||
|
@ -1172,7 +1172,7 @@ void sqlite3ExprDelete(sqlite3 *db, Expr *p){
|
|||
** pExpr to the pParse->pConstExpr list with a register number of 0.
|
||||
*/
|
||||
void sqlite3ExprDeferredDelete(Parse *pParse, Expr *pExpr){
|
||||
pParse->pConstExpr =
|
||||
pParse->pConstExpr =
|
||||
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
|
||||
}
|
||||
|
||||
|
@ -1189,7 +1189,7 @@ void sqlite3ExprUnmapAndDelete(Parse *pParse, Expr *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** Return the number of bytes allocated for the expression structure
|
||||
** Return the number of bytes allocated for the expression structure
|
||||
** passed as the first argument. This is always one of EXPR_FULLSIZE,
|
||||
** EXPR_REDUCEDSIZE or EXPR_TOKENONLYSIZE.
|
||||
*/
|
||||
|
@ -1204,14 +1204,14 @@ static int exprStructSize(Expr *p){
|
|||
** to store a copy of an expression or expression tree. They differ in
|
||||
** how much of the tree is measured.
|
||||
**
|
||||
** dupedExprStructSize() Size of only the Expr structure
|
||||
** dupedExprStructSize() Size of only the Expr structure
|
||||
** dupedExprNodeSize() Size of Expr + space for token
|
||||
** dupedExprSize() Expr + token + subtree components
|
||||
**
|
||||
***************************************************************************
|
||||
**
|
||||
** The dupedExprStructSize() function returns two values OR-ed together:
|
||||
** (1) the space required for a copy of the Expr structure only and
|
||||
** The dupedExprStructSize() function returns two values OR-ed together:
|
||||
** (1) the space required for a copy of the Expr structure only and
|
||||
** (2) the EP_xxx flags that indicate what the structure size should be.
|
||||
** The return values is always one of:
|
||||
**
|
||||
|
@ -1238,7 +1238,7 @@ static int dupedExprStructSize(Expr *p, int flags){
|
|||
assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
|
||||
assert( EXPR_FULLSIZE<=0xfff );
|
||||
assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
|
||||
if( 0==flags || p->op==TK_SELECT_COLUMN
|
||||
if( 0==flags || p->op==TK_SELECT_COLUMN
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
|| ExprHasProperty(p, EP_WinFunc)
|
||||
#endif
|
||||
|
@ -1246,7 +1246,7 @@ static int dupedExprStructSize(Expr *p, int flags){
|
|||
nSize = EXPR_FULLSIZE;
|
||||
}else{
|
||||
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(p, EP_FromJoin) );
|
||||
assert( !ExprHasProperty(p, EP_FromJoin) );
|
||||
assert( !ExprHasProperty(p, EP_MemToken) );
|
||||
assert( !ExprHasVVAProperty(p, EP_NoReduce) );
|
||||
if( p->pLeft || p->x.pList ){
|
||||
|
@ -1260,7 +1260,7 @@ static int dupedExprStructSize(Expr *p, int flags){
|
|||
}
|
||||
|
||||
/*
|
||||
** This function returns the space in bytes required to store the copy
|
||||
** This function returns the space in bytes required to store the copy
|
||||
** of the Expr structure and a copy of the Expr.u.zToken string (if that
|
||||
** string is defined.)
|
||||
*/
|
||||
|
@ -1273,16 +1273,16 @@ static int dupedExprNodeSize(Expr *p, int flags){
|
|||
}
|
||||
|
||||
/*
|
||||
** Return the number of bytes required to create a duplicate of the
|
||||
** Return the number of bytes required to create a duplicate of the
|
||||
** expression passed as the first argument. The second argument is a
|
||||
** mask containing EXPRDUP_XXX flags.
|
||||
**
|
||||
** The value returned includes space to create a copy of the Expr struct
|
||||
** itself and the buffer referred to by Expr.u.zToken, if any.
|
||||
**
|
||||
** If the EXPRDUP_REDUCE flag is set, then the return value includes
|
||||
** space to duplicate all Expr nodes in the tree formed by Expr.pLeft
|
||||
** and Expr.pRight variables (but not for any structures pointed to or
|
||||
** If the EXPRDUP_REDUCE flag is set, then the return value includes
|
||||
** space to duplicate all Expr nodes in the tree formed by Expr.pLeft
|
||||
** and Expr.pRight variables (but not for any structures pointed to or
|
||||
** descended from the Expr.x.pList or Expr.x.pSelect variables).
|
||||
*/
|
||||
static int dupedExprSize(Expr *p, int flags){
|
||||
|
@ -1297,8 +1297,8 @@ static int dupedExprSize(Expr *p, int flags){
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is similar to sqlite3ExprDup(), except that if pzBuffer
|
||||
** is not NULL then *pzBuffer is assumed to point to a buffer large enough
|
||||
** This function is similar to sqlite3ExprDup(), except that if pzBuffer
|
||||
** is not NULL then *pzBuffer is assumed to point to a buffer large enough
|
||||
** to store the copy of expression p, the copies of p->u.zToken
|
||||
** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
|
||||
** if any. Before returning, *pzBuffer is set to the first byte past the
|
||||
|
@ -1344,7 +1344,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
|
|||
}else{
|
||||
u32 nSize = (u32)exprStructSize(p);
|
||||
memcpy(zAlloc, p, nSize);
|
||||
if( nSize<EXPR_FULLSIZE ){
|
||||
if( nSize<EXPR_FULLSIZE ){
|
||||
memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
|
||||
}
|
||||
}
|
||||
|
@ -1408,7 +1408,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
|
|||
}
|
||||
|
||||
/*
|
||||
** Create and return a deep copy of the object passed as the second
|
||||
** Create and return a deep copy of the object passed as the second
|
||||
** argument. If an OOM condition is encountered, NULL is returned
|
||||
** and the db->mallocFailed flag set.
|
||||
*/
|
||||
|
@ -1474,7 +1474,7 @@ static void gatherSelectWindows(Select *p){
|
|||
** without effecting the originals.
|
||||
**
|
||||
** The expression list, ID, and source lists return by sqlite3ExprListDup(),
|
||||
** sqlite3IdListDup(), and sqlite3SrcListDup() can not be further expanded
|
||||
** sqlite3IdListDup(), and sqlite3SrcListDup() can not be further expanded
|
||||
** by subsequent calls to sqlite*ListAppend() routines.
|
||||
**
|
||||
** Any tables that the SrcList might point to are not duplicated.
|
||||
|
@ -1504,9 +1504,9 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
|
|||
Expr *pOldExpr = pOldItem->pExpr;
|
||||
Expr *pNewExpr;
|
||||
pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
|
||||
if( pOldExpr
|
||||
if( pOldExpr
|
||||
&& pOldExpr->op==TK_SELECT_COLUMN
|
||||
&& (pNewExpr = pItem->pExpr)!=0
|
||||
&& (pNewExpr = pItem->pExpr)!=0
|
||||
){
|
||||
assert( pNewExpr->iColumn==0 || i>0 );
|
||||
if( pNewExpr->iColumn==0 ){
|
||||
|
@ -1533,7 +1533,7 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
|
|||
|
||||
/*
|
||||
** If cursors, triggers, views and subqueries are all omitted from
|
||||
** the build, then none of the following routines, except for
|
||||
** the build, then none of the following routines, except for
|
||||
** sqlite3SelectDup(), can be called. sqlite3SelectDup() is sometimes
|
||||
** called with a NULL argument.
|
||||
*/
|
||||
|
@ -1569,7 +1569,7 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
|
|||
pNewItem->u2.pCteUse->nUse++;
|
||||
}
|
||||
if( pNewItem->fg.isTabFunc ){
|
||||
pNewItem->u1.pFuncArg =
|
||||
pNewItem->u1.pFuncArg =
|
||||
sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
|
||||
}
|
||||
pTab = pNewItem->pTab = pOldItem->pTab;
|
||||
|
@ -1686,7 +1686,7 @@ ExprList *sqlite3ExprListAppend(
|
|||
pList->nExpr = 0;
|
||||
}else if( (pList->nExpr & (pList->nExpr-1))==0 ){
|
||||
ExprList *pNew;
|
||||
pNew = sqlite3DbRealloc(db, pList,
|
||||
pNew = sqlite3DbRealloc(db, pList,
|
||||
sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
|
||||
if( pNew==0 ){
|
||||
goto no_mem;
|
||||
|
@ -1700,7 +1700,7 @@ ExprList *sqlite3ExprListAppend(
|
|||
pItem->pExpr = pExpr;
|
||||
return pList;
|
||||
|
||||
no_mem:
|
||||
no_mem:
|
||||
/* Avoid leaking memory if malloc has failed. */
|
||||
sqlite3ExprDelete(db, pExpr);
|
||||
sqlite3ExprListDelete(db, pList);
|
||||
|
@ -1733,8 +1733,8 @@ ExprList *sqlite3ExprListAppendVector(
|
|||
if( NEVER(pColumns==0) ) goto vector_append_error;
|
||||
if( pExpr==0 ) goto vector_append_error;
|
||||
|
||||
/* If the RHS is a vector, then we can immediately check to see that
|
||||
** the size of the RHS and LHS match. But if the RHS is a SELECT,
|
||||
/* If the RHS is a vector, then we can immediately check to see that
|
||||
** the size of the RHS and LHS match. But if the RHS is a SELECT,
|
||||
** wildcards ("*") in the result set of the SELECT must be expanded before
|
||||
** we can do the size check, so defer the size check until code generation.
|
||||
*/
|
||||
|
@ -1762,7 +1762,7 @@ ExprList *sqlite3ExprListAppendVector(
|
|||
Expr *pFirst = pList->a[iFirst].pExpr;
|
||||
assert( pFirst!=0 );
|
||||
assert( pFirst->op==TK_SELECT_COLUMN );
|
||||
|
||||
|
||||
/* Store the SELECT statement in pRight so it will be deleted when
|
||||
** sqlite3ExprListDelete() is called */
|
||||
pFirst->pRight = pExpr;
|
||||
|
@ -1788,13 +1788,13 @@ void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder, int eNulls){
|
|||
assert( p->nExpr>0 );
|
||||
|
||||
assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC==0 && SQLITE_SO_DESC>0 );
|
||||
assert( iSortOrder==SQLITE_SO_UNDEFINED
|
||||
|| iSortOrder==SQLITE_SO_ASC
|
||||
|| iSortOrder==SQLITE_SO_DESC
|
||||
assert( iSortOrder==SQLITE_SO_UNDEFINED
|
||||
|| iSortOrder==SQLITE_SO_ASC
|
||||
|| iSortOrder==SQLITE_SO_DESC
|
||||
);
|
||||
assert( eNulls==SQLITE_SO_UNDEFINED
|
||||
|| eNulls==SQLITE_SO_ASC
|
||||
|| eNulls==SQLITE_SO_DESC
|
||||
assert( eNulls==SQLITE_SO_UNDEFINED
|
||||
|| eNulls==SQLITE_SO_ASC
|
||||
|| eNulls==SQLITE_SO_DESC
|
||||
);
|
||||
|
||||
pItem = &p->a[p->nExpr-1];
|
||||
|
@ -2031,7 +2031,7 @@ Expr *sqlite3ExprSimplifiedAndOr(Expr *pExpr){
|
|||
** when parsing an existing schema out of the sqlite_schema table and 4
|
||||
** when processing a new CREATE TABLE statement. A bound parameter raises
|
||||
** an error for new statements, but is silently converted
|
||||
** to NULL for existing schemas. This allows sqlite_schema tables that
|
||||
** to NULL for existing schemas. This allows sqlite_schema tables that
|
||||
** contain a bound parameter because they were generated by older versions
|
||||
** of SQLite to be parsed by newer versions of SQLite without raising a
|
||||
** malformed schema error.
|
||||
|
@ -2191,7 +2191,7 @@ static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
|
|||
|
||||
/*
|
||||
** Walk the expression tree passed as the first argument. Return non-zero
|
||||
** if the expression consists entirely of constants or copies of terms
|
||||
** if the expression consists entirely of constants or copies of terms
|
||||
** in pGroupBy that sort with the BINARY collation sequence.
|
||||
**
|
||||
** This routine is used to determine if a term of the HAVING clause can
|
||||
|
@ -2221,7 +2221,7 @@ int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){
|
|||
|
||||
/*
|
||||
** Walk an expression tree for the DEFAULT field of a column definition
|
||||
** in a CREATE TABLE statement. Return non-zero if the expression is
|
||||
** in a CREATE TABLE statement. Return non-zero if the expression is
|
||||
** acceptable for use as a DEFAULT. That is to say, return non-zero if
|
||||
** the expression is constant or a function call with constant arguments.
|
||||
** Return and 0 if there are any variables.
|
||||
|
@ -2305,7 +2305,7 @@ int sqlite3ExprIsInteger(Expr *p, int *pValue){
|
|||
** Return FALSE if there is no chance that the expression can be NULL.
|
||||
**
|
||||
** If the expression might be NULL or if the expression is too complex
|
||||
** to tell return TRUE.
|
||||
** to tell return TRUE.
|
||||
**
|
||||
** This routine is used as an optimization, to skip OP_IsNull opcodes
|
||||
** when we know that a value cannot be NULL. Hence, a false positive
|
||||
|
@ -2393,7 +2393,7 @@ int sqlite3IsRowid(const char *z){
|
|||
}
|
||||
|
||||
/*
|
||||
** pX is the RHS of an IN operator. If pX is a SELECT statement
|
||||
** pX is the RHS of an IN operator. If pX is a SELECT statement
|
||||
** that can be simplified to a direct table access, then return
|
||||
** a pointer to the SELECT statement. If pX is not a SELECT statement,
|
||||
** or if the SELECT statement needs to be manifested into a transient
|
||||
|
@ -2459,7 +2459,7 @@ static void sqlite3SetHasNullFlag(Vdbe *v, int iCur, int regHasNull){
|
|||
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
/*
|
||||
** The argument is an IN operator with a list (not a subquery) on the
|
||||
** The argument is an IN operator with a list (not a subquery) on the
|
||||
** right-hand side. Return TRUE if that list is constant.
|
||||
*/
|
||||
static int sqlite3InRhsIsConstant(Expr *pIn){
|
||||
|
@ -2518,9 +2518,9 @@ static int sqlite3InRhsIsConstant(Expr *pIn){
|
|||
** to be unique - either because it is an INTEGER PRIMARY KEY or due to
|
||||
** a UNIQUE constraint or index.
|
||||
**
|
||||
** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
|
||||
** for fast set membership tests) then an epheremal table must
|
||||
** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
|
||||
** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
|
||||
** for fast set membership tests) then an epheremal table must
|
||||
** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
|
||||
** index can be found with the specified <columns> as its left-most.
|
||||
**
|
||||
** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and
|
||||
|
@ -2532,7 +2532,7 @@ static int sqlite3InRhsIsConstant(Expr *pIn){
|
|||
**
|
||||
** When the b-tree is being used for membership tests, the calling function
|
||||
** might need to know whether or not the RHS side of the IN operator
|
||||
** contains a NULL. If prRhsHasNull is not a NULL pointer and
|
||||
** contains a NULL. If prRhsHasNull is not a NULL pointer and
|
||||
** if there is any chance that the (...) might contain a NULL value at
|
||||
** runtime, then a register is allocated and the register number written
|
||||
** to *prRhsHasNull. If there is no chance that the (...) contains a
|
||||
|
@ -2572,9 +2572,9 @@ int sqlite3FindInIndex(
|
|||
assert( pX->op==TK_IN );
|
||||
mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
|
||||
|
||||
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
|
||||
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
|
||||
** whether or not the SELECT result contains NULL values, check whether
|
||||
** or not NULL is actually possible (it may not be, for example, due
|
||||
** or not NULL is actually possible (it may not be, for example, due
|
||||
** to NOT NULL constraints in the schema). If no NULL values are possible,
|
||||
** set prRhsHasNull to 0 before continuing. */
|
||||
if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){
|
||||
|
@ -2589,7 +2589,7 @@ int sqlite3FindInIndex(
|
|||
}
|
||||
|
||||
/* Check to see if an existing table or index can be used to
|
||||
** satisfy the query. This is preferable to generating a new
|
||||
** satisfy the query. This is preferable to generating a new
|
||||
** ephemeral table. */
|
||||
if( pParse->nErr==0 && (p = isCandidateForInOpt(pX))!=0 ){
|
||||
sqlite3 *db = pParse->db; /* Database connection */
|
||||
|
@ -2625,7 +2625,7 @@ int sqlite3FindInIndex(
|
|||
int affinity_ok = 1;
|
||||
int i;
|
||||
|
||||
/* Check that the affinity that will be used to perform each
|
||||
/* Check that the affinity that will be used to perform each
|
||||
** comparison is the same as the affinity of each column in table
|
||||
** on the RHS of the IN operator. If it not, it is not possible to
|
||||
** use any index of the RHS table. */
|
||||
|
@ -2670,14 +2670,14 @@ int sqlite3FindInIndex(
|
|||
continue; /* This index is not unique over the IN RHS columns */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
colUsed = 0; /* Columns of index used so far */
|
||||
for(i=0; i<nExpr; i++){
|
||||
Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
|
||||
Expr *pRhs = pEList->a[i].pExpr;
|
||||
CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
|
||||
int j;
|
||||
|
||||
|
||||
assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr );
|
||||
for(j=0; j<nExpr; j++){
|
||||
if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
|
||||
|
@ -2693,7 +2693,7 @@ int sqlite3FindInIndex(
|
|||
colUsed |= mCol;
|
||||
if( aiMap ) aiMap[i] = j;
|
||||
}
|
||||
|
||||
|
||||
assert( i==nExpr || colUsed!=(MASKBIT(nExpr)-1) );
|
||||
if( colUsed==(MASKBIT(nExpr)-1) ){
|
||||
/* If we reach this point, that means the index pIdx is usable */
|
||||
|
@ -2705,11 +2705,11 @@ int sqlite3FindInIndex(
|
|||
VdbeComment((v, "%s", pIdx->zName));
|
||||
assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
|
||||
eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
|
||||
|
||||
|
||||
if( prRhsHasNull ){
|
||||
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
|
||||
i64 mask = (1<<nExpr)-1;
|
||||
sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed,
|
||||
sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed,
|
||||
iTab, 0, 0, (u8*)&mask, P4_INT64);
|
||||
#endif
|
||||
*prRhsHasNull = ++pParse->nMem;
|
||||
|
@ -2771,8 +2771,8 @@ int sqlite3FindInIndex(
|
|||
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
/*
|
||||
** Argument pExpr is an (?, ?...) IN(...) expression. This
|
||||
** function allocates and returns a nul-terminated string containing
|
||||
** Argument pExpr is an (?, ?...) IN(...) expression. This
|
||||
** function allocates and returns a nul-terminated string containing
|
||||
** the affinities to be used for each column of the comparison.
|
||||
**
|
||||
** It is the responsibility of the caller to ensure that the returned
|
||||
|
@ -2805,11 +2805,11 @@ static char *exprINAffinity(Parse *pParse, Expr *pExpr){
|
|||
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
/*
|
||||
** Load the Parse object passed as the first argument with an error
|
||||
** Load the Parse object passed as the first argument with an error
|
||||
** message of the form:
|
||||
**
|
||||
** "sub-select returns N columns - expected M"
|
||||
*/
|
||||
*/
|
||||
void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
|
||||
if( pParse->nErr==0 ){
|
||||
const char *zFmt = "sub-select returns %d columns - expected %d";
|
||||
|
@ -2820,7 +2820,7 @@ void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
|
|||
|
||||
/*
|
||||
** Expression pExpr is a vector that has been used in a context where
|
||||
** it is not permitted. If pExpr is a sub-select vector, this routine
|
||||
** it is not permitted. If pExpr is a sub-select vector, this routine
|
||||
** loads the Parse object with a message of the form:
|
||||
**
|
||||
** "sub-select returns N columns - expected 1"
|
||||
|
@ -2828,7 +2828,7 @@ void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
|
|||
** Or, if it is a regular scalar vector:
|
||||
**
|
||||
** "row value misused"
|
||||
*/
|
||||
*/
|
||||
void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
if( pExpr->flags & EP_xIsSelect ){
|
||||
|
@ -2891,7 +2891,7 @@ void sqlite3CodeRhsOfIN(
|
|||
if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
|
||||
/* Reuse of the RHS is allowed */
|
||||
/* If this routine has already been coded, but the previous code
|
||||
** might not have been invoked yet, so invoke it now as a subroutine.
|
||||
** might not have been invoked yet, so invoke it now as a subroutine.
|
||||
*/
|
||||
if( ExprHasProperty(pExpr, EP_Subrtn) ){
|
||||
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
|
||||
|
@ -3045,7 +3045,7 @@ void sqlite3CodeRhsOfIN(
|
|||
**
|
||||
** The pExpr parameter is the SELECT or EXISTS operator to be coded.
|
||||
**
|
||||
** Return the register that holds the result. For a multi-column SELECT,
|
||||
** Return the register that holds the result. For a multi-column SELECT,
|
||||
** the result is stored in a contiguous array of registers and the
|
||||
** return value is the register of the left-most result column.
|
||||
** Return 0 if an error occurs.
|
||||
|
@ -3096,7 +3096,7 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
|||
|
||||
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
|
||||
}
|
||||
|
||||
|
||||
/* For a SELECT, generate code to put the values for all columns of
|
||||
** the first row into an array of registers and return the index of
|
||||
** the first register.
|
||||
|
@ -3104,7 +3104,7 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
|||
** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
|
||||
** into a register and return that register number.
|
||||
**
|
||||
** In both cases, the query is augmented with "LIMIT 1". Any
|
||||
** In both cases, the query is augmented with "LIMIT 1". Any
|
||||
** preexisting limit is discarded in place of the new LIMIT 1.
|
||||
*/
|
||||
ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
|
||||
|
@ -3161,9 +3161,9 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
|||
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
/*
|
||||
** Expr pIn is an IN(...) expression. This function checks that the
|
||||
** sub-select on the RHS of the IN() operator has the same number of
|
||||
** columns as the vector on the LHS. Or, if the RHS of the IN() is not
|
||||
** Expr pIn is an IN(...) expression. This function checks that the
|
||||
** sub-select on the RHS of the IN() operator has the same number of
|
||||
** columns as the vector on the LHS. Or, if the RHS of the IN() is not
|
||||
** a sub-query, that the LHS is a vector of size 1.
|
||||
*/
|
||||
int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
|
||||
|
@ -3188,18 +3188,18 @@ int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
|
|||
** x IN (SELECT ...)
|
||||
** x IN (value, value, ...)
|
||||
**
|
||||
** The left-hand side (LHS) is a scalar or vector expression. The
|
||||
** The left-hand side (LHS) is a scalar or vector expression. The
|
||||
** right-hand side (RHS) is an array of zero or more scalar values, or a
|
||||
** subquery. If the RHS is a subquery, the number of result columns must
|
||||
** match the number of columns in the vector on the LHS. If the RHS is
|
||||
** a list of values, the LHS must be a scalar.
|
||||
** a list of values, the LHS must be a scalar.
|
||||
**
|
||||
** The IN operator is true if the LHS value is contained within the RHS.
|
||||
** The result is false if the LHS is definitely not in the RHS. The
|
||||
** result is NULL if the presence of the LHS in the RHS cannot be
|
||||
** The result is false if the LHS is definitely not in the RHS. The
|
||||
** result is NULL if the presence of the LHS in the RHS cannot be
|
||||
** determined due to NULLs.
|
||||
**
|
||||
** This routine generates code that jumps to destIfFalse if the LHS is not
|
||||
** This routine generates code that jumps to destIfFalse if the LHS is not
|
||||
** contained within the RHS. If due to NULLs we cannot determine if the LHS
|
||||
** is contained in the RHS then jump to destIfNull. If the LHS is contained
|
||||
** within the RHS then fall through.
|
||||
|
@ -3228,7 +3228,7 @@ static void sqlite3ExprCodeIN(
|
|||
int destStep6 = 0; /* Start of code for Step 6 */
|
||||
int addrTruthOp; /* Address of opcode that determines the IN is true */
|
||||
int destNotNull; /* Jump here if a comparison is not true in step 6 */
|
||||
int addrTop; /* Top of the step-6 loop */
|
||||
int addrTop; /* Top of the step-6 loop */
|
||||
int iTab = 0; /* Index to use */
|
||||
u8 okConstFactor = pParse->okConstFactor;
|
||||
|
||||
|
@ -3255,7 +3255,7 @@ static void sqlite3ExprCodeIN(
|
|||
aiMap, &iTab);
|
||||
|
||||
assert( pParse->nErr || nVector==1 || eType==IN_INDEX_EPH
|
||||
|| eType==IN_INDEX_INDEX_ASC || eType==IN_INDEX_INDEX_DESC
|
||||
|| eType==IN_INDEX_INDEX_ASC || eType==IN_INDEX_INDEX_DESC
|
||||
);
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* Confirm that aiMap[] contains nVector integer values between 0 and
|
||||
|
@ -3267,8 +3267,8 @@ static void sqlite3ExprCodeIN(
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Code the LHS, the <expr> from "<expr> IN (...)". If the LHS is a
|
||||
** vector, then it is stored in an array of nVector registers starting
|
||||
/* Code the LHS, the <expr> from "<expr> IN (...)". If the LHS is a
|
||||
** vector, then it is stored in an array of nVector registers starting
|
||||
** at r1.
|
||||
**
|
||||
** sqlite3FindInIndex() might have reordered the fields of the LHS vector
|
||||
|
@ -3398,7 +3398,7 @@ static void sqlite3ExprCodeIN(
|
|||
}
|
||||
|
||||
/* Step 5. If we do not care about the difference between NULL and
|
||||
** FALSE, then just return false.
|
||||
** FALSE, then just return false.
|
||||
*/
|
||||
if( destIfFalse==destIfNull ) sqlite3VdbeGoto(v, destIfFalse);
|
||||
|
||||
|
@ -3459,7 +3459,7 @@ sqlite3ExprCodeIN_oom_error:
|
|||
** Generate an instruction that will put the floating point
|
||||
** value described by z[0..n-1] into register iMem.
|
||||
**
|
||||
** The z[] string will probably not be zero-terminated. But the
|
||||
** The z[] string will probably not be zero-terminated. But the
|
||||
** z[n] character is guaranteed to be something that does not look
|
||||
** like the continuation of the number.
|
||||
*/
|
||||
|
@ -3620,7 +3620,7 @@ void sqlite3ExprCodeGetColumnOfTable(
|
|||
|
||||
/*
|
||||
** Generate code that will extract the iColumn-th column from
|
||||
** table pTab and store the column value in register iReg.
|
||||
** table pTab and store the column value in register iReg.
|
||||
**
|
||||
** There must be an open cursor to pTab in iTable when this routine
|
||||
** is called. If iColumn<0 then code is generated that extracts the rowid.
|
||||
|
@ -3752,7 +3752,7 @@ static int exprCodeInlineFunction(
|
|||
return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
|
||||
}
|
||||
|
||||
default: {
|
||||
default: {
|
||||
/* The UNLIKELY() function is a no-op. The result is the value
|
||||
** of the first argument.
|
||||
*/
|
||||
|
@ -3768,7 +3768,7 @@ static int exprCodeInlineFunction(
|
|||
case INLINEFUNC_expr_compare: {
|
||||
/* Compare two expressions using sqlite3ExprCompare() */
|
||||
assert( nFarg==2 );
|
||||
sqlite3VdbeAddOp2(v, OP_Integer,
|
||||
sqlite3VdbeAddOp2(v, OP_Integer,
|
||||
sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
|
||||
target);
|
||||
break;
|
||||
|
@ -3777,7 +3777,7 @@ static int exprCodeInlineFunction(
|
|||
case INLINEFUNC_expr_implies_expr: {
|
||||
/* Compare two expressions using sqlite3ExprImpliesExpr() */
|
||||
assert( nFarg==2 );
|
||||
sqlite3VdbeAddOp2(v, OP_Integer,
|
||||
sqlite3VdbeAddOp2(v, OP_Integer,
|
||||
sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1),
|
||||
target);
|
||||
break;
|
||||
|
@ -3789,7 +3789,7 @@ static int exprCodeInlineFunction(
|
|||
assert( nFarg==2 );
|
||||
pA1 = pFarg->a[1].pExpr;
|
||||
if( pA1->op==TK_COLUMN ){
|
||||
sqlite3VdbeAddOp2(v, OP_Integer,
|
||||
sqlite3VdbeAddOp2(v, OP_Integer,
|
||||
sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable),
|
||||
target);
|
||||
}else{
|
||||
|
@ -3808,7 +3808,7 @@ static int exprCodeInlineFunction(
|
|||
char aff;
|
||||
assert( nFarg==1 );
|
||||
aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
|
||||
sqlite3VdbeLoadString(v, target,
|
||||
sqlite3VdbeLoadString(v, target,
|
||||
(aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
|
||||
break;
|
||||
}
|
||||
|
@ -4074,7 +4074,7 @@ expr_code_doover:
|
|||
case TK_BITOR:
|
||||
case TK_SLASH:
|
||||
case TK_LSHIFT:
|
||||
case TK_RSHIFT:
|
||||
case TK_RSHIFT:
|
||||
case TK_CONCAT: {
|
||||
assert( TK_AND==OP_And ); testcase( op==TK_AND );
|
||||
assert( TK_OR==OP_Or ); testcase( op==TK_OR );
|
||||
|
@ -4245,7 +4245,7 @@ expr_code_doover:
|
|||
assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
|
||||
assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
|
||||
testcase( pDef->funcFlags & OPFLAG_LENGTHARG );
|
||||
pFarg->a[0].pExpr->op2 =
|
||||
pFarg->a[0].pExpr->op2 =
|
||||
pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
|
||||
}
|
||||
}
|
||||
|
@ -4264,7 +4264,7 @@ expr_code_doover:
|
|||
** see if it is a column in a virtual table. This is done because
|
||||
** the left operand of infix functions (the operand we want to
|
||||
** control overloading) ends up as the second argument to the
|
||||
** function. The expression "A glob B" is equivalent to
|
||||
** function. The expression "A glob B" is equivalent to
|
||||
** "glob(B,A). We want to use the A in "A glob B" to test
|
||||
** for function overloading. But we use the B term in "glob(B,A)".
|
||||
*/
|
||||
|
@ -4275,7 +4275,7 @@ expr_code_doover:
|
|||
}
|
||||
#endif
|
||||
if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
|
||||
if( !pColl ) pColl = db->pDfltColl;
|
||||
if( !pColl ) pColl = db->pDfltColl;
|
||||
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
|
||||
}
|
||||
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
|
@ -4360,7 +4360,7 @@ expr_code_doover:
|
|||
return target;
|
||||
}
|
||||
case TK_SPAN:
|
||||
case TK_COLLATE:
|
||||
case TK_COLLATE:
|
||||
case TK_UPLUS: {
|
||||
pExpr = pExpr->pLeft;
|
||||
goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
|
||||
|
@ -4376,7 +4376,7 @@ expr_code_doover:
|
|||
**
|
||||
** The expression is implemented using an OP_Param opcode. The p1
|
||||
** parameter is set to 0 for an old.rowid reference, or to (i+1)
|
||||
** to reference another column of the old.* pseudo-table, where
|
||||
** to reference another column of the old.* pseudo-table, where
|
||||
** i is the index of the column. For a new.rowid reference, p1 is
|
||||
** set to (n+1), where n is the number of columns in each pseudo-table.
|
||||
** For a reference to any other column in the new.* pseudo-table, p1
|
||||
|
@ -4390,11 +4390,11 @@ expr_code_doover:
|
|||
**
|
||||
** p1==0 -> old.rowid p1==3 -> new.rowid
|
||||
** p1==1 -> old.a p1==4 -> new.a
|
||||
** p1==2 -> old.b p1==5 -> new.b
|
||||
** p1==2 -> old.b p1==5 -> new.b
|
||||
*/
|
||||
Table *pTab = pExpr->y.pTab;
|
||||
int iCol = pExpr->iColumn;
|
||||
int p1 = pExpr->iTable * (pTab->nCol+1) + 1
|
||||
int p1 = pExpr->iTable * (pTab->nCol+1) + 1
|
||||
+ sqlite3TableColumnToStorage(pTab, iCol);
|
||||
|
||||
assert( pExpr->iTable==0 || pExpr->iTable==1 );
|
||||
|
@ -4534,7 +4534,7 @@ expr_code_doover:
|
|||
}
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
case TK_RAISE: {
|
||||
assert( pExpr->affExpr==OE_Rollback
|
||||
assert( pExpr->affExpr==OE_Rollback
|
||||
|| pExpr->affExpr==OE_Abort
|
||||
|| pExpr->affExpr==OE_Fail
|
||||
|| pExpr->affExpr==OE_Ignore
|
||||
|
@ -4577,8 +4577,8 @@ expr_code_doover:
|
|||
** the end of the prepared statement in the initialization section.
|
||||
**
|
||||
** If regDest>=0 then the result is always stored in that register and the
|
||||
** result is not reusable. If regDest<0 then this routine is free to
|
||||
** store the value whereever it wants. The register where the expression
|
||||
** result is not reusable. If regDest<0 then this routine is free to
|
||||
** store the value whereever it wants. The register where the expression
|
||||
** is stored is returned. When regDest<0, two identical expressions might
|
||||
** code to the same register, if they do not contain function calls and hence
|
||||
** are factored out into the initialization section at the end of the
|
||||
|
@ -4794,7 +4794,7 @@ int sqlite3ExprCodeExprList(
|
|||
**
|
||||
** x BETWEEN y AND z
|
||||
**
|
||||
** The above is equivalent to
|
||||
** The above is equivalent to
|
||||
**
|
||||
** x>=y AND x<=z
|
||||
**
|
||||
|
@ -5011,7 +5011,7 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
|
|||
}
|
||||
}
|
||||
sqlite3ReleaseTempReg(pParse, regFree1);
|
||||
sqlite3ReleaseTempReg(pParse, regFree2);
|
||||
sqlite3ReleaseTempReg(pParse, regFree2);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5171,7 +5171,7 @@ void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
|
|||
}
|
||||
#endif
|
||||
default: {
|
||||
default_expr:
|
||||
default_expr:
|
||||
if( ExprAlwaysFalse(pExpr) ){
|
||||
sqlite3VdbeGoto(v, dest);
|
||||
}else if( ExprAlwaysTrue(pExpr) ){
|
||||
|
@ -5221,7 +5221,7 @@ static int exprCompareVariable(Parse *pParse, Expr *pVar, Expr *pExpr){
|
|||
int res = 0;
|
||||
int iVar;
|
||||
sqlite3_value *pL, *pR = 0;
|
||||
|
||||
|
||||
sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, SQLITE_AFF_BLOB, &pR);
|
||||
if( pR ){
|
||||
iVar = pVar->iColumn;
|
||||
|
@ -5263,9 +5263,9 @@ static int exprCompareVariable(Parse *pParse, Expr *pVar, Expr *pExpr){
|
|||
** an incorrect 0 or 1 could lead to a malfunction.
|
||||
**
|
||||
** If pParse is not NULL then TK_VARIABLE terms in pA with bindings in
|
||||
** pParse->pReprepare can be matched against literals in pB. The
|
||||
** pParse->pReprepare can be matched against literals in pB. The
|
||||
** pParse->pVdbe->expmask bitmask is updated for each variable referenced.
|
||||
** If pParse is NULL (the normal case) then any TK_VARIABLE term in
|
||||
** If pParse is NULL (the normal case) then any TK_VARIABLE term in
|
||||
** Argument pParse should normally be NULL. If it is not NULL and pA or
|
||||
** pB causes a return value of 2.
|
||||
*/
|
||||
|
@ -5339,7 +5339,7 @@ int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){
|
|||
|
||||
/*
|
||||
** Compare two ExprList objects. Return 0 if they are identical, 1
|
||||
** if they are certainly different, or 2 if it is not possible to
|
||||
** if they are certainly different, or 2 if it is not possible to
|
||||
** determine if they are identical or not.
|
||||
**
|
||||
** If any subelement of pB has Expr.iTable==(-1) then it is allowed
|
||||
|
@ -5426,8 +5426,8 @@ static int exprImpliesNotNull(
|
|||
case TK_MINUS:
|
||||
case TK_BITOR:
|
||||
case TK_LSHIFT:
|
||||
case TK_RSHIFT:
|
||||
case TK_CONCAT:
|
||||
case TK_RSHIFT:
|
||||
case TK_CONCAT:
|
||||
seenNot = 1;
|
||||
/* no break */ deliberate_fall_through
|
||||
case TK_STAR:
|
||||
|
@ -5472,9 +5472,9 @@ static int exprImpliesNotNull(
|
|||
** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has
|
||||
** Expr.iTable<0 then assume a table number given by iTab.
|
||||
**
|
||||
** If pParse is not NULL, then the values of bound variables in pE1 are
|
||||
** If pParse is not NULL, then the values of bound variables in pE1 are
|
||||
** compared against literal values in pE2 and pParse->pVdbe->expmask is
|
||||
** modified to record which bound variables are referenced. If pParse
|
||||
** modified to record which bound variables are referenced. If pParse
|
||||
** is NULL, then false will be returned if pE1 contains any bound variables.
|
||||
**
|
||||
** When in doubt, return false. Returning true might give a performance
|
||||
|
@ -5647,7 +5647,7 @@ struct IdxCover {
|
|||
};
|
||||
|
||||
/*
|
||||
** Check to see if there are references to columns in table
|
||||
** Check to see if there are references to columns in table
|
||||
** pWalker->u.pIdxCover->iCur can be satisfied using the index
|
||||
** pWalker->u.pIdxCover->pIdx.
|
||||
*/
|
||||
|
@ -5691,7 +5691,7 @@ int sqlite3ExprCoveredByIndex(
|
|||
|
||||
/*
|
||||
** An instance of the following structure is used by the tree walker
|
||||
** to count references to table columns in the arguments of an
|
||||
** to count references to table columns in the arguments of an
|
||||
** aggregate function, in order to implement the
|
||||
** sqlite3FunctionThisSrc() routine.
|
||||
*/
|
||||
|
@ -5721,8 +5721,8 @@ static int selectSrcCount(Walker *pWalker, Select *pSel){
|
|||
*/
|
||||
static int exprSrcCount(Walker *pWalker, Expr *pExpr){
|
||||
/* There was once a NEVER() on the second term on the grounds that
|
||||
** sqlite3FunctionUsesThisSrc() was always called before
|
||||
** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet
|
||||
** sqlite3FunctionUsesThisSrc() was always called before
|
||||
** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet
|
||||
** been converted into TK_AGG_COLUMN. But this is no longer true due
|
||||
** to window functions - sqlite3WindowRewrite() may now indirectly call
|
||||
** FunctionUsesThisSrc() when creating a new sub-select. */
|
||||
|
@ -5843,7 +5843,7 @@ static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
|
|||
&i
|
||||
);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Add a new element to the pAggInfo->aFunc[] array. Return the index of
|
||||
|
@ -5852,7 +5852,7 @@ static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
|
|||
static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
|
||||
int i;
|
||||
pInfo->aFunc = sqlite3ArrayAllocate(
|
||||
db,
|
||||
db,
|
||||
pInfo->aFunc,
|
||||
sizeof(pInfo->aFunc[0]),
|
||||
&pInfo->nFunc,
|
||||
|
@ -5888,7 +5888,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
|||
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
if( pExpr->iTable==pItem->iCursor ){
|
||||
/* If we reach this point, it means that pExpr refers to a table
|
||||
** that is in the FROM clause of the aggregate query.
|
||||
** that is in the FROM clause of the aggregate query.
|
||||
**
|
||||
** Make an entry for the column in pAggInfo->aCol[] if there
|
||||
** is not an entry there already.
|
||||
|
@ -5902,7 +5902,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
|||
}
|
||||
}
|
||||
if( (k>=pAggInfo->nColumn)
|
||||
&& (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
|
||||
&& (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
|
||||
){
|
||||
pCol = &pAggInfo->aCol[k];
|
||||
pCol->pTab = pExpr->y.pTab;
|
||||
|
@ -5948,7 +5948,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
|||
if( (pNC->ncFlags & NC_InAggFunc)==0
|
||||
&& pWalker->walkerDepth==pExpr->op2
|
||||
){
|
||||
/* Check to see if pExpr is a duplicate of another aggregate
|
||||
/* Check to see if pExpr is a duplicate of another aggregate
|
||||
** function that is already in the pAggInfo structure
|
||||
*/
|
||||
struct AggInfo_func *pItem = pAggInfo->aFunc;
|
||||
|
@ -5969,7 +5969,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
|||
pItem->iMem = ++pParse->nMem;
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue) );
|
||||
pItem->pFunc = sqlite3FindFunction(pParse->db,
|
||||
pExpr->u.zToken,
|
||||
pExpr->u.zToken,
|
||||
pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
|
||||
if( pExpr->flags & EP_Distinct ){
|
||||
pItem->iDistinct = pParse->nTab++;
|
||||
|
|
22
third_party/sqlite3/fileio.c
vendored
22
third_party/sqlite3/fileio.c
vendored
|
@ -105,7 +105,7 @@ SQLITE_EXTENSION_INIT1
|
|||
|
||||
|
||||
/*
|
||||
** Set the result stored by context ctx to a blob containing the
|
||||
** Set the result stored by context ctx to a blob containing the
|
||||
** contents of file zName. Or, leave the result unchanged (NULL)
|
||||
** if the file does not exist or is unreadable.
|
||||
**
|
||||
|
@ -261,7 +261,7 @@ static int makeDirectory(
|
|||
}
|
||||
|
||||
/*
|
||||
** This function does the work for the writefile() UDF. Refer to
|
||||
** This function does the work for the writefile() UDF. Refer to
|
||||
** header comments at the top of this file for details.
|
||||
*/
|
||||
static int writeFile(
|
||||
|
@ -329,7 +329,7 @@ static int writeFile(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
|
||||
** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
|
||||
** Refer to header comments at the top of this file for details.
|
||||
*/
|
||||
static void writefileFunc(
|
||||
|
@ -343,7 +343,7 @@ static void writefileFunc(
|
|||
sqlite3_int64 mtime = -1;
|
||||
|
||||
if( argc<2 || argc>4 ){
|
||||
sqlite3_result_error(context,
|
||||
sqlite3_result_error(context,
|
||||
"wrong number of arguments to function writefile()", -1
|
||||
);
|
||||
return;
|
||||
|
@ -413,7 +413,7 @@ static void lsModeFunc(
|
|||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|
||||
/*
|
||||
/*
|
||||
** Cursor type for recursively iterating through a directory structure.
|
||||
*/
|
||||
typedef struct fsdir_cursor fsdir_cursor;
|
||||
|
@ -561,7 +561,7 @@ static int fsdirNext(sqlite3_vtab_cursor *cur){
|
|||
}
|
||||
pCur->iLvl = iNew;
|
||||
pLvl = &pCur->aLvl[iNew];
|
||||
|
||||
|
||||
pLvl->zDir = pCur->zPath;
|
||||
pCur->zPath = 0;
|
||||
pLvl->pDir = opendir(pLvl->zDir);
|
||||
|
@ -690,7 +690,7 @@ static int fsdirEof(sqlite3_vtab_cursor *cur){
|
|||
** idxNum==2 Both PATH and DIR supplied
|
||||
*/
|
||||
static int fsdirFilter(
|
||||
sqlite3_vtab_cursor *cur,
|
||||
sqlite3_vtab_cursor *cur,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -779,7 +779,7 @@ static int fsdirBestIndex(
|
|||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( seenPath || seenDir ){
|
||||
/* If input parameters are unusable, disallow this plan */
|
||||
|
@ -847,14 +847,14 @@ static int fsdirRegister(sqlite3 *db){
|
|||
#endif
|
||||
|
||||
int sqlite3_fileio_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused parameter */
|
||||
rc = sqlite3_create_function(db, "readfile", 1,
|
||||
rc = sqlite3_create_function(db, "readfile", 1,
|
||||
SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
|
||||
readfileFunc, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
|
|
228
third_party/sqlite3/fkey.c
vendored
228
third_party/sqlite3/fkey.c
vendored
|
@ -25,25 +25,25 @@
|
|||
** Foreign keys in SQLite come in two flavours: deferred and immediate.
|
||||
** If an immediate foreign key constraint is violated,
|
||||
** SQLITE_CONSTRAINT_FOREIGNKEY is returned and the current
|
||||
** statement transaction rolled back. If a
|
||||
** deferred foreign key constraint is violated, no action is taken
|
||||
** immediately. However if the application attempts to commit the
|
||||
** statement transaction rolled back. If a
|
||||
** deferred foreign key constraint is violated, no action is taken
|
||||
** immediately. However if the application attempts to commit the
|
||||
** transaction before fixing the constraint violation, the attempt fails.
|
||||
**
|
||||
** Deferred constraints are implemented using a simple counter associated
|
||||
** with the database handle. The counter is set to zero each time a
|
||||
** database transaction is opened. Each time a statement is executed
|
||||
** with the database handle. The counter is set to zero each time a
|
||||
** database transaction is opened. Each time a statement is executed
|
||||
** that causes a foreign key violation, the counter is incremented. Each
|
||||
** time a statement is executed that removes an existing violation from
|
||||
** the database, the counter is decremented. When the transaction is
|
||||
** committed, the commit fails if the current value of the counter is
|
||||
** greater than zero. This scheme has two big drawbacks:
|
||||
**
|
||||
** * When a commit fails due to a deferred foreign key constraint,
|
||||
** * When a commit fails due to a deferred foreign key constraint,
|
||||
** there is no way to tell which foreign constraint is not satisfied,
|
||||
** or which row it is not satisfied for.
|
||||
**
|
||||
** * If the database contains foreign key violations when the
|
||||
** * If the database contains foreign key violations when the
|
||||
** transaction is opened, this may cause the mechanism to malfunction.
|
||||
**
|
||||
** Despite these problems, this approach is adopted as it seems simpler
|
||||
|
@ -55,26 +55,26 @@
|
|||
** the parent table for a match. If none is found increment the
|
||||
** constraint counter.
|
||||
**
|
||||
** I.2) For each FK for which the table is the parent table,
|
||||
** I.2) For each FK for which the table is the parent table,
|
||||
** search the child table for rows that correspond to the new
|
||||
** row in the parent table. Decrement the counter for each row
|
||||
** found (as the constraint is now satisfied).
|
||||
**
|
||||
** DELETE operations:
|
||||
**
|
||||
** D.1) For each FK for which the table is the child table,
|
||||
** search the parent table for a row that corresponds to the
|
||||
** deleted row in the child table. If such a row is not found,
|
||||
** D.1) For each FK for which the table is the child table,
|
||||
** search the parent table for a row that corresponds to the
|
||||
** deleted row in the child table. If such a row is not found,
|
||||
** decrement the counter.
|
||||
**
|
||||
** D.2) For each FK for which the table is the parent table, search
|
||||
** the child table for rows that correspond to the deleted row
|
||||
** D.2) For each FK for which the table is the parent table, search
|
||||
** the child table for rows that correspond to the deleted row
|
||||
** in the parent table. For each found increment the counter.
|
||||
**
|
||||
** UPDATE operations:
|
||||
**
|
||||
** An UPDATE command requires that all 4 steps above are taken, but only
|
||||
** for FK constraints for which the affected columns are actually
|
||||
** for FK constraints for which the affected columns are actually
|
||||
** modified (values must be compared at runtime).
|
||||
**
|
||||
** Note that I.1 and D.1 are very similar operations, as are I.2 and D.2.
|
||||
|
@ -83,10 +83,10 @@
|
|||
** For the purposes of immediate FK constraints, the OR REPLACE conflict
|
||||
** resolution is considered to delete rows before the new row is inserted.
|
||||
** If a delete caused by OR REPLACE violates an FK constraint, an exception
|
||||
** is thrown, even if the FK constraint would be satisfied after the new
|
||||
** is thrown, even if the FK constraint would be satisfied after the new
|
||||
** row is inserted.
|
||||
**
|
||||
** Immediate constraints are usually handled similarly. The only difference
|
||||
** Immediate constraints are usually handled similarly. The only difference
|
||||
** is that the counter used is stored as part of each individual statement
|
||||
** object (struct Vdbe). If, after the statement has run, its immediate
|
||||
** constraint counter is greater than zero,
|
||||
|
@ -97,7 +97,7 @@
|
|||
** INSERT violates a foreign key constraint. This is necessary as such
|
||||
** an INSERT does not open a statement transaction.
|
||||
**
|
||||
** TODO: How should dropping a table be handled? How should renaming a
|
||||
** TODO: How should dropping a table be handled? How should renaming a
|
||||
** table be handled?
|
||||
**
|
||||
**
|
||||
|
@ -108,7 +108,7 @@
|
|||
** for those two operations needs to know whether or not the operation
|
||||
** requires any FK processing and, if so, which columns of the original
|
||||
** row are required by the FK processing VDBE code (i.e. if FKs were
|
||||
** implemented using triggers, which of the old.* columns would be
|
||||
** implemented using triggers, which of the old.* columns would be
|
||||
** accessed). No information is required by the code-generator before
|
||||
** coding an INSERT operation. The functions used by the UPDATE/DELETE
|
||||
** generation code to query for this information are:
|
||||
|
@ -145,13 +145,13 @@
|
|||
/*
|
||||
** A foreign key constraint requires that the key columns in the parent
|
||||
** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
|
||||
** Given that pParent is the parent table for foreign key constraint pFKey,
|
||||
** search the schema for a unique index on the parent key columns.
|
||||
**
|
||||
** If successful, zero is returned. If the parent key is an INTEGER PRIMARY
|
||||
** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx
|
||||
** is set to point to the unique index.
|
||||
** Given that pParent is the parent table for foreign key constraint pFKey,
|
||||
** search the schema for a unique index on the parent key columns.
|
||||
**
|
||||
** If successful, zero is returned. If the parent key is an INTEGER PRIMARY
|
||||
** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx
|
||||
** is set to point to the unique index.
|
||||
**
|
||||
** If the parent key consists of a single column (the foreign key constraint
|
||||
** is not a composite foreign key), output variable *paiCol is set to NULL.
|
||||
** Otherwise, it is set to point to an allocated array of size N, where
|
||||
|
@ -174,8 +174,8 @@
|
|||
** PRIMARY KEY, or
|
||||
**
|
||||
** 4) No parent key columns were provided explicitly as part of the
|
||||
** foreign key definition, and the PRIMARY KEY of the parent table
|
||||
** consists of a different number of columns to the child key in
|
||||
** foreign key definition, and the PRIMARY KEY of the parent table
|
||||
** consists of a different number of columns to the child key in
|
||||
** the child table.
|
||||
**
|
||||
** then non-zero is returned, and a "foreign key mismatch" error loaded
|
||||
|
@ -199,9 +199,9 @@ int sqlite3FkLocateIndex(
|
|||
assert( !paiCol || *paiCol==0 );
|
||||
assert( pParse );
|
||||
|
||||
/* If this is a non-composite (single column) foreign key, check if it
|
||||
** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
|
||||
** and *paiCol set to zero and return early.
|
||||
/* If this is a non-composite (single column) foreign key, check if it
|
||||
** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
|
||||
** and *paiCol set to zero and return early.
|
||||
**
|
||||
** Otherwise, for a composite foreign key (more than one column), allocate
|
||||
** space for the aiCol array (returned via output parameter *paiCol).
|
||||
|
@ -210,7 +210,7 @@ int sqlite3FkLocateIndex(
|
|||
if( nCol==1 ){
|
||||
/* The FK maps to the IPK if any of the following are true:
|
||||
**
|
||||
** 1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
|
||||
** 1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
|
||||
** mapped to the primary key of table pParent, or
|
||||
** 2) The FK is explicitly mapped to a column declared as INTEGER
|
||||
** PRIMARY KEY.
|
||||
|
@ -227,14 +227,14 @@ int sqlite3FkLocateIndex(
|
|||
}
|
||||
|
||||
for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
|
||||
if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
|
||||
/* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
|
||||
** of columns. If each indexed column corresponds to a foreign key
|
||||
** column of pFKey, then this index is a winner. */
|
||||
|
||||
if( zKey==0 ){
|
||||
/* If zKey is NULL, then this foreign key is implicitly mapped to
|
||||
** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
|
||||
/* If zKey is NULL, then this foreign key is implicitly mapped to
|
||||
** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
|
||||
** identified by the test. */
|
||||
if( IsPrimaryKeyIndex(pIdx) ){
|
||||
if( aiCol ){
|
||||
|
@ -292,15 +292,15 @@ int sqlite3FkLocateIndex(
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is called when a row is inserted into or deleted from the
|
||||
** child table of foreign key constraint pFKey. If an SQL UPDATE is executed
|
||||
** This function is called when a row is inserted into or deleted from the
|
||||
** child table of foreign key constraint pFKey. If an SQL UPDATE is executed
|
||||
** on the child table of pFKey, this function is invoked twice for each row
|
||||
** affected - once to "delete" the old row, and then again to "insert" the
|
||||
** new row.
|
||||
**
|
||||
** Each time it is called, this function generates VDBE code to locate the
|
||||
** row in the parent table that corresponds to the row being inserted into
|
||||
** or deleted from the child table. If the parent row can be found, no
|
||||
** row in the parent table that corresponds to the row being inserted into
|
||||
** or deleted from the child table. If the parent row can be found, no
|
||||
** special action is taken. Otherwise, if the parent row can *not* be
|
||||
** found in the parent table:
|
||||
**
|
||||
|
@ -314,7 +314,7 @@ int sqlite3FkLocateIndex(
|
|||
**
|
||||
** DELETE deferred Decrement the "deferred constraint counter".
|
||||
**
|
||||
** These operations are identified in the comment at the top of this file
|
||||
** These operations are identified in the comment at the top of this file
|
||||
** (fkey.c) as "I.1" and "D.1".
|
||||
*/
|
||||
static void fkLookupParent(
|
||||
|
@ -336,15 +336,15 @@ static void fkLookupParent(
|
|||
sqlite3VdbeVerifyAbortable(v,
|
||||
(!pFKey->isDeferred
|
||||
&& !(pParse->db->flags & SQLITE_DeferFKs)
|
||||
&& !pParse->pToplevel
|
||||
&& !pParse->pToplevel
|
||||
&& !pParse->isMultiWrite) ? OE_Abort : OE_Ignore);
|
||||
|
||||
/* If nIncr is less than zero, then check at runtime if there are any
|
||||
** outstanding constraints to resolve. If there are not, there is no need
|
||||
** to check if deleting this row resolves any outstanding violations.
|
||||
**
|
||||
** Check if any of the key columns in the child table row are NULL. If
|
||||
** any are, then the constraint is considered satisfied. No need to
|
||||
** Check if any of the key columns in the child table row are NULL. If
|
||||
** any are, then the constraint is considered satisfied. No need to
|
||||
** search for a matching row in the parent table. */
|
||||
if( nIncr<0 ){
|
||||
sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
|
||||
|
@ -361,17 +361,17 @@ static void fkLookupParent(
|
|||
** column of the parent table (table pTab). */
|
||||
int iMustBeInt; /* Address of MustBeInt instruction */
|
||||
int regTemp = sqlite3GetTempReg(pParse);
|
||||
|
||||
/* Invoke MustBeInt to coerce the child key value to an integer (i.e.
|
||||
|
||||
/* Invoke MustBeInt to coerce the child key value to an integer (i.e.
|
||||
** apply the affinity of the parent key). If this fails, then there
|
||||
** is no matching parent key. Before using MustBeInt, make a copy of
|
||||
** the value. Otherwise, the value inserted into the child key column
|
||||
** will have INTEGER affinity applied to it, which may not be correct. */
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy,
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy,
|
||||
sqlite3TableColumnToStorage(pFKey->pFrom,aiCol[0])+1+regData, regTemp);
|
||||
iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
|
||||
VdbeCoverage(v);
|
||||
|
||||
|
||||
/* If the parent table is the same as the child table, and we are about
|
||||
** to increment the constraint-counter (i.e. this is an INSERT operation),
|
||||
** then check if the row being inserted matches itself. If so, do not
|
||||
|
@ -380,7 +380,7 @@ static void fkLookupParent(
|
|||
sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
|
||||
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
|
||||
}
|
||||
|
||||
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
|
||||
sqlite3VdbeGoto(v, iOk);
|
||||
|
@ -391,21 +391,21 @@ static void fkLookupParent(
|
|||
int nCol = pFKey->nCol;
|
||||
int regTemp = sqlite3GetTempRange(pParse, nCol);
|
||||
int regRec = sqlite3GetTempReg(pParse);
|
||||
|
||||
|
||||
sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
|
||||
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp2(v, OP_Copy,
|
||||
sqlite3VdbeAddOp2(v, OP_Copy,
|
||||
sqlite3TableColumnToStorage(pFKey->pFrom, aiCol[i])+1+regData,
|
||||
regTemp+i);
|
||||
}
|
||||
|
||||
|
||||
/* If the parent table is the same as the child table, and we are about
|
||||
** to increment the constraint-counter (i.e. this is an INSERT operation),
|
||||
** then check if the row being inserted matches itself. If so, do not
|
||||
** increment the constraint-counter.
|
||||
** increment the constraint-counter.
|
||||
**
|
||||
** If any of the parent-key values are NULL, then the row cannot match
|
||||
** If any of the parent-key values are NULL, then the row cannot match
|
||||
** itself. So set JUMPIFNULL to make sure we do the OP_Found if any
|
||||
** of the parent-key values are NULL (at this point it is known that
|
||||
** none of the child key values are).
|
||||
|
@ -429,19 +429,19 @@ static void fkLookupParent(
|
|||
}
|
||||
sqlite3VdbeGoto(v, iOk);
|
||||
}
|
||||
|
||||
|
||||
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
|
||||
sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
|
||||
sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
|
||||
|
||||
|
||||
sqlite3ReleaseTempReg(pParse, regRec);
|
||||
sqlite3ReleaseTempRange(pParse, regTemp, nCol);
|
||||
}
|
||||
}
|
||||
|
||||
if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
|
||||
&& !pParse->pToplevel
|
||||
&& !pParse->isMultiWrite
|
||||
&& !pParse->pToplevel
|
||||
&& !pParse->isMultiWrite
|
||||
){
|
||||
/* Special case: If this is an INSERT statement that will insert exactly
|
||||
** one row into the table, raise a constraint immediately instead of
|
||||
|
@ -519,7 +519,7 @@ static Expr *exprTableColumn(
|
|||
|
||||
/*
|
||||
** This function is called to generate code executed when a row is deleted
|
||||
** from the parent table of foreign key constraint pFKey and, if pFKey is
|
||||
** from the parent table of foreign key constraint pFKey and, if pFKey is
|
||||
** deferred, when a row is inserted into the same table. When generating
|
||||
** code for an SQL UPDATE operation, this function may be called twice -
|
||||
** once to "delete" the old row and once to "insert" the new row.
|
||||
|
@ -546,7 +546,7 @@ static Expr *exprTableColumn(
|
|||
**
|
||||
** INSERT deferred Decrement the "deferred constraint counter".
|
||||
**
|
||||
** These operations are identified in the comment at the top of this file
|
||||
** These operations are identified in the comment at the top of this file
|
||||
** (fkey.c) as "I.2" and "D.2".
|
||||
*/
|
||||
static void fkScanChildren(
|
||||
|
@ -589,7 +589,7 @@ static void fkScanChildren(
|
|||
Expr *pLeft; /* Value from parent table row */
|
||||
Expr *pRight; /* Column ref to child table */
|
||||
Expr *pEq; /* Expression (pLeft = pRight) */
|
||||
i16 iCol; /* Index of column in child table */
|
||||
i16 iCol; /* Index of column in child table */
|
||||
const char *zCol; /* Name of column in child table */
|
||||
|
||||
iCol = pIdx ? pIdx->aiColumn[i] : -1;
|
||||
|
@ -611,7 +611,7 @@ static void fkScanChildren(
|
|||
**
|
||||
** The first form is used for rowid tables. The second form is used
|
||||
** for WITHOUT ROWID tables. In the second form, the *parent* key is
|
||||
** (a,b,...). Either the parent or primary key could be used to
|
||||
** (a,b,...). Either the parent or primary key could be used to
|
||||
** uniquely identify the current row, but the parent key is more convenient
|
||||
** as the required values have already been loaded into registers
|
||||
** by the caller.
|
||||
|
@ -683,7 +683,7 @@ FKey *sqlite3FkReferences(Table *pTab){
|
|||
}
|
||||
|
||||
/*
|
||||
** The second argument is a Trigger structure allocated by the
|
||||
** The second argument is a Trigger structure allocated by the
|
||||
** fkActionTrigger() routine. This function deletes the Trigger structure
|
||||
** and all of its sub-components.
|
||||
**
|
||||
|
@ -711,7 +711,7 @@ static void fkTriggerDelete(sqlite3 *dbMem, Trigger *p){
|
|||
**
|
||||
** (a) The table is the parent table of a FK constraint, or
|
||||
** (b) The table is the child table of a deferred FK constraint and it is
|
||||
** determined at runtime that there are outstanding deferred FK
|
||||
** determined at runtime that there are outstanding deferred FK
|
||||
** constraint violations in the database,
|
||||
**
|
||||
** then the equivalent of "DELETE FROM <tbl>" is executed before dropping
|
||||
|
@ -728,7 +728,7 @@ void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
|
|||
assert( pTab->pSelect==0 ); /* Not a view */
|
||||
if( sqlite3FkReferences(pTab)==0 ){
|
||||
/* Search for a deferred foreign key constraint for which this table
|
||||
** is the child table. If one cannot be found, return without
|
||||
** is the child table. If one cannot be found, return without
|
||||
** generating any VDBE code. If one can be found, then jump over
|
||||
** the entire DELETE if there are no outstanding deferred constraints
|
||||
** when this statement is run. */
|
||||
|
@ -745,10 +745,10 @@ void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
|
|||
sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
|
||||
pParse->disableTriggers = 0;
|
||||
|
||||
/* If the DELETE has generated immediate foreign key constraint
|
||||
/* If the DELETE has generated immediate foreign key constraint
|
||||
** violations, halt the VDBE and return an error at this point, before
|
||||
** any modifications to the schema are made. This is because statement
|
||||
** transactions are not able to rollback schema changes.
|
||||
** transactions are not able to rollback schema changes.
|
||||
**
|
||||
** If the SQLITE_DeferFKs flag is set, then this is not required, as
|
||||
** the statement transaction will not be rolled back even if FK
|
||||
|
@ -772,7 +772,7 @@ void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
|
|||
/*
|
||||
** The second argument points to an FKey object representing a foreign key
|
||||
** for which pTab is the child table. An UPDATE statement against pTab
|
||||
** is currently being processed. For each column of the table that is
|
||||
** is currently being processed. For each column of the table that is
|
||||
** actually updated, the corresponding element in the aChange[] array
|
||||
** is zero or greater (if a column is unmodified the corresponding element
|
||||
** is set to -1). If the rowid column is modified by the UPDATE statement
|
||||
|
@ -799,7 +799,7 @@ static int fkChildIsModified(
|
|||
/*
|
||||
** The second argument points to an FKey object representing a foreign key
|
||||
** for which pTab is the parent table. An UPDATE statement against pTab
|
||||
** is currently being processed. For each column of the table that is
|
||||
** is currently being processed. For each column of the table that is
|
||||
** actually updated, the corresponding element in the aChange[] array
|
||||
** is zero or greater (if a column is unmodified the corresponding element
|
||||
** is set to -1). If the rowid column is modified by the UPDATE statement
|
||||
|
@ -809,9 +809,9 @@ static int fkChildIsModified(
|
|||
** parent key for FK constraint *p are modified.
|
||||
*/
|
||||
static int fkParentIsModified(
|
||||
Table *pTab,
|
||||
FKey *p,
|
||||
int *aChange,
|
||||
Table *pTab,
|
||||
FKey *p,
|
||||
int *aChange,
|
||||
int bChngRowid
|
||||
){
|
||||
int i;
|
||||
|
@ -852,7 +852,7 @@ static int isSetNullAction(Parse *pParse, FKey *pFKey){
|
|||
|
||||
/*
|
||||
** This function is called when inserting, deleting or updating a row of
|
||||
** table pTab to generate VDBE code to perform foreign key constraint
|
||||
** table pTab to generate VDBE code to perform foreign key constraint
|
||||
** processing for the operation.
|
||||
**
|
||||
** For a DELETE operation, parameter regOld is passed the index of the
|
||||
|
@ -868,11 +868,11 @@ static int isSetNullAction(Parse *pParse, FKey *pFKey){
|
|||
** For an UPDATE operation, this function is called twice. Once before
|
||||
** the original record is deleted from the table using the calling convention
|
||||
** described for DELETE. Then again after the original record is deleted
|
||||
** but before the new record is inserted using the INSERT convention.
|
||||
** but before the new record is inserted using the INSERT convention.
|
||||
*/
|
||||
void sqlite3FkCheck(
|
||||
Parse *pParse, /* Parse context */
|
||||
Table *pTab, /* Row is being deleted from this table */
|
||||
Table *pTab, /* Row is being deleted from this table */
|
||||
int regOld, /* Previous row data is stored here */
|
||||
int regNew, /* New row data is stored here */
|
||||
int *aChange, /* Array indicating UPDATEd columns (or 0) */
|
||||
|
@ -904,16 +904,16 @@ void sqlite3FkCheck(
|
|||
int i;
|
||||
int bIgnore = 0;
|
||||
|
||||
if( aChange
|
||||
if( aChange
|
||||
&& sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
|
||||
&& fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
|
||||
&& fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
|
||||
){
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Find the parent table of this foreign key. Also find a unique index
|
||||
** on the parent key columns in the parent table. If either of these
|
||||
** schema items cannot be located, set an error in pParse and return
|
||||
/* Find the parent table of this foreign key. Also find a unique index
|
||||
** on the parent key columns in the parent table. If either of these
|
||||
** schema items cannot be located, set an error in pParse and return
|
||||
** early. */
|
||||
if( pParse->disableTriggers ){
|
||||
pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
|
||||
|
@ -957,7 +957,7 @@ void sqlite3FkCheck(
|
|||
}
|
||||
assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
/* Request permission to read the parent key columns. If the
|
||||
/* Request permission to read the parent key columns. If the
|
||||
** authorization callback returns SQLITE_IGNORE, behave as if any
|
||||
** values read from the parent table are NULL. */
|
||||
if( db->xAuth ){
|
||||
|
@ -969,24 +969,24 @@ void sqlite3FkCheck(
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Take a shared-cache advisory read-lock on the parent table. Allocate
|
||||
** a cursor to use to search the unique index on the parent key columns
|
||||
/* Take a shared-cache advisory read-lock on the parent table. Allocate
|
||||
** a cursor to use to search the unique index on the parent key columns
|
||||
** in the parent table. */
|
||||
sqlite3TableLock(pParse, iDb, pTo->tnum, 0, pTo->zName);
|
||||
pParse->nTab++;
|
||||
|
||||
if( regOld!=0 ){
|
||||
/* A row is being removed from the child table. Search for the parent.
|
||||
** If the parent does not exist, removing the child row resolves an
|
||||
** If the parent does not exist, removing the child row resolves an
|
||||
** outstanding foreign key constraint violation. */
|
||||
fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
|
||||
}
|
||||
if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
|
||||
/* A row is being added to the child table. If a parent row cannot
|
||||
** be found, adding the child row has violated the FK constraint.
|
||||
** be found, adding the child row has violated the FK constraint.
|
||||
**
|
||||
** If this operation is being performed as part of a trigger program
|
||||
** that is actually a "SET NULL" action belonging to this very
|
||||
** that is actually a "SET NULL" action belonging to this very
|
||||
** foreign key, then omit this scan altogether. As all child key
|
||||
** values are guaranteed to be NULL, it is not possible for adding
|
||||
** this row to cause an FK violation. */
|
||||
|
@ -1007,8 +1007,8 @@ void sqlite3FkCheck(
|
|||
continue;
|
||||
}
|
||||
|
||||
if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
|
||||
&& !pParse->pToplevel && !pParse->isMultiWrite
|
||||
if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
|
||||
&& !pParse->pToplevel && !pParse->isMultiWrite
|
||||
){
|
||||
assert( regOld==0 && regNew!=0 );
|
||||
/* Inserting a single row into a parent table cannot cause (or fix)
|
||||
|
@ -1031,7 +1031,7 @@ void sqlite3FkCheck(
|
|||
pItem->zName = pFKey->pFrom->zName;
|
||||
pItem->pTab->nTabRef++;
|
||||
pItem->iCursor = pParse->nTab++;
|
||||
|
||||
|
||||
if( regNew!=0 ){
|
||||
fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
|
||||
}
|
||||
|
@ -1050,10 +1050,10 @@ void sqlite3FkCheck(
|
|||
**
|
||||
** Note 2: At first glance it may seem like SQLite could simply omit
|
||||
** all OP_FkCounter related scans when either CASCADE or SET NULL
|
||||
** applies. The trouble starts if the CASCADE or SET NULL action
|
||||
** trigger causes other triggers or action rules attached to the
|
||||
** applies. The trouble starts if the CASCADE or SET NULL action
|
||||
** trigger causes other triggers or action rules attached to the
|
||||
** child table to fire. In these cases the fk constraint counters
|
||||
** might be set incorrectly if any OP_FkCounter related scans are
|
||||
** might be set incorrectly if any OP_FkCounter related scans are
|
||||
** omitted. */
|
||||
if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){
|
||||
sqlite3MayAbort(pParse);
|
||||
|
@ -1069,7 +1069,7 @@ void sqlite3FkCheck(
|
|||
#define COLUMN_MASK(x) (((x)>31) ? 0xffffffff : ((u32)1<<(x)))
|
||||
|
||||
/*
|
||||
** This function is called before generating code to update or delete a
|
||||
** This function is called before generating code to update or delete a
|
||||
** row contained in table pTab.
|
||||
*/
|
||||
u32 sqlite3FkOldmask(
|
||||
|
@ -1099,17 +1099,17 @@ u32 sqlite3FkOldmask(
|
|||
|
||||
|
||||
/*
|
||||
** This function is called before generating code to update or delete a
|
||||
** This function is called before generating code to update or delete a
|
||||
** row contained in table pTab. If the operation is a DELETE, then
|
||||
** parameter aChange is passed a NULL value. For an UPDATE, aChange points
|
||||
** to an array of size N, where N is the number of columns in table pTab.
|
||||
** If the i'th column is not modified by the UPDATE, then the corresponding
|
||||
** If the i'th column is not modified by the UPDATE, then the corresponding
|
||||
** entry in the aChange[] array is set to -1. If the column is modified,
|
||||
** the value is 0 or greater. Parameter chngRowid is set to true if the
|
||||
** UPDATE statement modifies the rowid fields of the table.
|
||||
**
|
||||
** If any foreign key processing will be required, this function returns
|
||||
** non-zero. If there is no foreign key related processing, this function
|
||||
** non-zero. If there is no foreign key related processing, this function
|
||||
** returns zero.
|
||||
**
|
||||
** For an UPDATE, this function returns 2 if:
|
||||
|
@ -1132,8 +1132,8 @@ int sqlite3FkRequired(
|
|||
int bHaveFK = 0; /* If FK processing is required */
|
||||
if( pParse->db->flags&SQLITE_ForeignKeys ){
|
||||
if( !aChange ){
|
||||
/* A DELETE operation. Foreign key processing is required if the
|
||||
** table in question is either the child or parent table for any
|
||||
/* A DELETE operation. Foreign key processing is required if the
|
||||
** table in question is either the child or parent table for any
|
||||
** foreign key constraint. */
|
||||
bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey);
|
||||
}else{
|
||||
|
@ -1162,7 +1162,7 @@ int sqlite3FkRequired(
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is called when an UPDATE or DELETE operation is being
|
||||
** This function is called when an UPDATE or DELETE operation is being
|
||||
** compiled on table pTab, which is the parent table of foreign-key pFKey.
|
||||
** If the current operation is an UPDATE, then the pChanges parameter is
|
||||
** passed a pointer to the list of columns being modified. If it is a
|
||||
|
@ -1174,7 +1174,7 @@ int sqlite3FkRequired(
|
|||
** returned (these actions require no special handling by the triggers
|
||||
** sub-system, code for them is created by fkScanChildren()).
|
||||
**
|
||||
** For example, if pFKey is the foreign key and pTab is table "p" in
|
||||
** For example, if pFKey is the foreign key and pTab is table "p" in
|
||||
** the following schema:
|
||||
**
|
||||
** CREATE TABLE p(pk PRIMARY KEY);
|
||||
|
@ -1187,7 +1187,7 @@ int sqlite3FkRequired(
|
|||
** END;
|
||||
**
|
||||
** The returned pointer is cached as part of the foreign key object. It
|
||||
** is eventually freed along with the rest of the foreign key object by
|
||||
** is eventually freed along with the rest of the foreign key object by
|
||||
** sqlite3FkDelete().
|
||||
*/
|
||||
static Trigger *fkActionTrigger(
|
||||
|
@ -1243,7 +1243,7 @@ static Trigger *fkActionTrigger(
|
|||
** that the affinity and collation sequence associated with the
|
||||
** parent table are used for the comparison. */
|
||||
pEq = sqlite3PExpr(pParse, TK_EQ,
|
||||
sqlite3PExpr(pParse, TK_DOT,
|
||||
sqlite3PExpr(pParse, TK_DOT,
|
||||
sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
|
||||
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
|
||||
sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
|
||||
|
@ -1257,20 +1257,20 @@ static Trigger *fkActionTrigger(
|
|||
*/
|
||||
if( pChanges ){
|
||||
pEq = sqlite3PExpr(pParse, TK_IS,
|
||||
sqlite3PExpr(pParse, TK_DOT,
|
||||
sqlite3PExpr(pParse, TK_DOT,
|
||||
sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
|
||||
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
|
||||
sqlite3PExpr(pParse, TK_DOT,
|
||||
sqlite3PExpr(pParse, TK_DOT,
|
||||
sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
|
||||
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
|
||||
);
|
||||
pWhen = sqlite3ExprAnd(pParse, pWhen, pEq);
|
||||
}
|
||||
|
||||
|
||||
if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
|
||||
Expr *pNew;
|
||||
if( action==OE_Cascade ){
|
||||
pNew = sqlite3PExpr(pParse, TK_DOT,
|
||||
pNew = sqlite3PExpr(pParse, TK_DOT,
|
||||
sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
|
||||
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
|
||||
}else if( action==OE_SetDflt ){
|
||||
|
@ -1302,7 +1302,7 @@ static Trigger *fkActionTrigger(
|
|||
|
||||
if( action==OE_Restrict ){
|
||||
Token tFrom;
|
||||
Expr *pRaise;
|
||||
Expr *pRaise;
|
||||
|
||||
tFrom.z = zFrom;
|
||||
tFrom.n = nFrom;
|
||||
|
@ -1310,7 +1310,7 @@ static Trigger *fkActionTrigger(
|
|||
if( pRaise ){
|
||||
pRaise->affExpr = OE_Abort;
|
||||
}
|
||||
pSelect = sqlite3SelectNew(pParse,
|
||||
pSelect = sqlite3SelectNew(pParse,
|
||||
sqlite3ExprListAppend(pParse, 0, pRaise),
|
||||
sqlite3SrcListAppend(pParse, 0, &tFrom, 0),
|
||||
pWhere,
|
||||
|
@ -1322,7 +1322,7 @@ static Trigger *fkActionTrigger(
|
|||
/* Disable lookaside memory allocation */
|
||||
DisableLookaside;
|
||||
|
||||
pTrigger = (Trigger *)sqlite3DbMallocZero(db,
|
||||
pTrigger = (Trigger *)sqlite3DbMallocZero(db,
|
||||
sizeof(Trigger) + /* struct Trigger */
|
||||
sizeof(TriggerStep) + /* Single step in trigger program */
|
||||
nFrom + 1 /* Space for pStep->zTarget */
|
||||
|
@ -1331,7 +1331,7 @@ static Trigger *fkActionTrigger(
|
|||
pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
|
||||
pStep->zTarget = (char *)&pStep[1];
|
||||
memcpy((char *)pStep->zTarget, zFrom, nFrom);
|
||||
|
||||
|
||||
pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
|
||||
pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
|
||||
pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
|
||||
|
@ -1359,10 +1359,10 @@ static Trigger *fkActionTrigger(
|
|||
case OE_Restrict:
|
||||
pStep->op = TK_SELECT;
|
||||
break;
|
||||
case OE_Cascade:
|
||||
if( !pChanges ){
|
||||
pStep->op = TK_DELETE;
|
||||
break;
|
||||
case OE_Cascade:
|
||||
if( !pChanges ){
|
||||
pStep->op = TK_DELETE;
|
||||
break;
|
||||
}
|
||||
/* no break */ deliberate_fall_through
|
||||
default:
|
||||
|
@ -1390,9 +1390,9 @@ void sqlite3FkActions(
|
|||
int *aChange, /* Array indicating UPDATEd columns (or 0) */
|
||||
int bChngRowid /* True if rowid is UPDATEd */
|
||||
){
|
||||
/* If foreign-key support is enabled, iterate through all FKs that
|
||||
** refer to table pTab. If there is an action associated with the FK
|
||||
** for this operation (either update or delete), invoke the associated
|
||||
/* If foreign-key support is enabled, iterate through all FKs that
|
||||
** refer to table pTab. If there is an action associated with the FK
|
||||
** for this operation (either update or delete), invoke the associated
|
||||
** trigger sub-program. */
|
||||
if( pParse->db->flags&SQLITE_ForeignKeys ){
|
||||
FKey *pFKey; /* Iterator variable */
|
||||
|
|
480
third_party/sqlite3/fts3.c
vendored
480
third_party/sqlite3/fts3.c
vendored
File diff suppressed because it is too large
Load diff
60
third_party/sqlite3/fts3Int.inc
vendored
60
third_party/sqlite3/fts3Int.inc
vendored
|
@ -15,7 +15,7 @@
|
|||
#define _FTSINT_H
|
||||
/* clang-format off */
|
||||
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
# define NDEBUG 1
|
||||
#endif
|
||||
|
||||
|
@ -48,7 +48,7 @@ SQLITE_EXTENSION_INIT3
|
|||
|
||||
/*
|
||||
** This constant determines the maximum depth of an FTS expression tree
|
||||
** that the library will create and use. FTS uses recursion to perform
|
||||
** that the library will create and use. FTS uses recursion to perform
|
||||
** various operations on the query tree, so the disadvantage of a large
|
||||
** limit is that it may allow very large queries to use large amounts
|
||||
** of stack space (perhaps causing a stack overflow).
|
||||
|
@ -66,11 +66,11 @@ SQLITE_EXTENSION_INIT3
|
|||
#define FTS3_MERGE_COUNT 16
|
||||
|
||||
/*
|
||||
** This is the maximum amount of data (in bytes) to store in the
|
||||
** This is the maximum amount of data (in bytes) to store in the
|
||||
** Fts3Table.pendingTerms hash table. Normally, the hash table is
|
||||
** populated as documents are inserted/updated/deleted in a transaction
|
||||
** and used to create a new segment when the transaction is committed.
|
||||
** However if this limit is reached midway through a transaction, a new
|
||||
** However if this limit is reached midway through a transaction, a new
|
||||
** segment is created and the hash table cleared immediately.
|
||||
*/
|
||||
#define FTS3_MAX_PENDING_DATA (1*1024*1024)
|
||||
|
@ -101,7 +101,7 @@ SQLITE_EXTENSION_INIT3
|
|||
/*
|
||||
** FTS4 virtual tables may maintain multiple indexes - one index of all terms
|
||||
** in the document set and zero or more prefix indexes. All indexes are stored
|
||||
** as one or more b+-trees in the %_segments and %_segdir tables.
|
||||
** as one or more b+-trees in the %_segments and %_segdir tables.
|
||||
**
|
||||
** It is possible to determine which index a b+-tree belongs to based on the
|
||||
** value stored in the "%_segdir.level" column. Given this value L, the index
|
||||
|
@ -109,8 +109,8 @@ SQLITE_EXTENSION_INIT3
|
|||
** level values between 0 and 1023 (inclusive) belong to index 0, all levels
|
||||
** between 1024 and 2047 to index 1, and so on.
|
||||
**
|
||||
** It is considered impossible for an index to use more than 1024 levels. In
|
||||
** theory though this may happen, but only after at least
|
||||
** It is considered impossible for an index to use more than 1024 levels. In
|
||||
** theory though this may happen, but only after at least
|
||||
** (FTS3_MERGE_COUNT^1024) separate flushes of the pending-terms tables.
|
||||
*/
|
||||
#define FTS3_SEGDIR_MAXLEVEL 1024
|
||||
|
@ -128,11 +128,11 @@ SQLITE_EXTENSION_INIT3
|
|||
** Terminator values for position-lists and column-lists.
|
||||
*/
|
||||
#define POS_COLUMN (1) /* Column-list terminator */
|
||||
#define POS_END (0) /* Position-list terminator */
|
||||
#define POS_END (0) /* Position-list terminator */
|
||||
|
||||
/*
|
||||
** The assert_fts3_nc() macro is similar to the assert() macro, except that it
|
||||
** is used for assert() conditions that are true only if it can be
|
||||
** is used for assert() conditions that are true only if it can be
|
||||
** guranteed that the database is not corrupt.
|
||||
*/
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
|
@ -144,7 +144,7 @@ extern int sqlite3_fts3_may_be_corrupt;
|
|||
|
||||
/*
|
||||
** This section provides definitions to allow the
|
||||
** FTS3 extension to be compiled outside of the
|
||||
** FTS3 extension to be compiled outside of the
|
||||
** amalgamation.
|
||||
*/
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
|
@ -182,7 +182,7 @@ typedef sqlite3_int64 i64; /* 8-byte signed integer */
|
|||
/*
|
||||
** Activate assert() only if SQLITE_TEST is enabled.
|
||||
*/
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
# define NDEBUG 1
|
||||
#endif
|
||||
|
||||
|
@ -247,8 +247,8 @@ struct Fts3Table {
|
|||
u32 nLeafAdd; /* Number of leaf blocks added this trans */
|
||||
int bLock; /* Used to prevent recursive content= tbls */
|
||||
|
||||
/* Precompiled statements used by the implementation. Each of these
|
||||
** statements is run and reset within a single virtual table API call.
|
||||
/* Precompiled statements used by the implementation. Each of these
|
||||
** statements is run and reset within a single virtual table API call.
|
||||
*/
|
||||
sqlite3_stmt *aStmt[40];
|
||||
sqlite3_stmt *pSeekStmt; /* Cache for fts3CursorSeekStmt() */
|
||||
|
@ -266,8 +266,8 @@ struct Fts3Table {
|
|||
char *zSegmentsTbl; /* Name of %_segments table */
|
||||
sqlite3_blob *pSegments; /* Blob handle open on %_segments table */
|
||||
|
||||
/*
|
||||
** The following array of hash tables is used to buffer pending index
|
||||
/*
|
||||
** The following array of hash tables is used to buffer pending index
|
||||
** updates during transactions. All pending updates buffered at any one
|
||||
** time must share a common language-id (see the FTS4 langid= feature).
|
||||
** The current language id is stored in variable iPrevLangid.
|
||||
|
@ -277,10 +277,10 @@ struct Fts3Table {
|
|||
** terms that appear in the document set. Each subsequent index in aIndex[]
|
||||
** is an index of prefixes of a specific length.
|
||||
**
|
||||
** Variable nPendingData contains an estimate the memory consumed by the
|
||||
** Variable nPendingData contains an estimate the memory consumed by the
|
||||
** pending data structures, including hash table overhead, but not including
|
||||
** malloc overhead. When nPendingData exceeds nMaxPendingData, all hash
|
||||
** tables are flushed to disk. Variable iPrevDocid is the docid of the most
|
||||
** tables are flushed to disk. Variable iPrevDocid is the docid of the most
|
||||
** recently inserted record.
|
||||
*/
|
||||
int nIndex; /* Size of aIndex[] */
|
||||
|
@ -363,10 +363,10 @@ struct Fts3Cursor {
|
|||
**
|
||||
** CREATE VIRTUAL TABLE ex1 USING fts3(a,b,c,d);
|
||||
** SELECT docid FROM ex1 WHERE b MATCH 'one two three';
|
||||
**
|
||||
**
|
||||
** Because the LHS of the MATCH operator is 2nd column "b",
|
||||
** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a,
|
||||
** +1 for b, +2 for c, +3 for d.) If the LHS of MATCH were "ex1"
|
||||
** +1 for b, +2 for c, +3 for d.) If the LHS of MATCH were "ex1"
|
||||
** indicating that all columns should be searched,
|
||||
** then eSearch would be set to FTS3_FULLTEXT_SEARCH+4.
|
||||
*/
|
||||
|
@ -425,8 +425,8 @@ struct Fts3Phrase {
|
|||
char *pOrPoslist;
|
||||
i64 iOrDocid;
|
||||
|
||||
/* Variables below this point are populated by fts3_expr.c when parsing
|
||||
** a MATCH expression. Everything above is part of the evaluation phase.
|
||||
/* Variables below this point are populated by fts3_expr.c when parsing
|
||||
** a MATCH expression. Everything above is part of the evaluation phase.
|
||||
*/
|
||||
int nToken; /* Number of tokens in the phrase */
|
||||
int iColumn; /* Index of column this phrase must match */
|
||||
|
@ -436,10 +436,10 @@ struct Fts3Phrase {
|
|||
/*
|
||||
** A tree of these objects forms the RHS of a MATCH operator.
|
||||
**
|
||||
** If Fts3Expr.eType is FTSQUERY_PHRASE and isLoaded is true, then aDoclist
|
||||
** points to a malloced buffer, size nDoclist bytes, containing the results
|
||||
** of this phrase query in FTS3 doclist format. As usual, the initial
|
||||
** "Length" field found in doclists stored on disk is omitted from this
|
||||
** If Fts3Expr.eType is FTSQUERY_PHRASE and isLoaded is true, then aDoclist
|
||||
** points to a malloced buffer, size nDoclist bytes, containing the results
|
||||
** of this phrase query in FTS3 doclist format. As usual, the initial
|
||||
** "Length" field found in doclists stored on disk is omitted from this
|
||||
** buffer.
|
||||
**
|
||||
** Variable aMI is used only for FTSQUERY_NEAR nodes to store the global
|
||||
|
@ -451,7 +451,7 @@ struct Fts3Phrase {
|
|||
** aMI[iCol*3 + 1] = Number of occurrences
|
||||
** aMI[iCol*3 + 2] = Number of rows containing at least one instance
|
||||
**
|
||||
** The aMI array is allocated using sqlite3_malloc(). It should be freed
|
||||
** The aMI array is allocated using sqlite3_malloc(). It should be freed
|
||||
** when the expression node is.
|
||||
*/
|
||||
struct Fts3Expr {
|
||||
|
@ -475,7 +475,7 @@ struct Fts3Expr {
|
|||
|
||||
/*
|
||||
** Candidate values for Fts3Query.eType. Note that the order of the first
|
||||
** four values is in order of precedence when parsing expressions. For
|
||||
** four values is in order of precedence when parsing expressions. For
|
||||
** example, the following:
|
||||
**
|
||||
** "a OR b AND c NOT d NEAR e"
|
||||
|
@ -532,7 +532,7 @@ int sqlite3Fts3SegReaderStart(Fts3Table*, Fts3MultiSegReader*, Fts3SegFilter*);
|
|||
int sqlite3Fts3SegReaderStep(Fts3Table *, Fts3MultiSegReader *);
|
||||
void sqlite3Fts3SegReaderFinish(Fts3MultiSegReader *);
|
||||
|
||||
int sqlite3Fts3SegReaderCursor(Fts3Table *,
|
||||
int sqlite3Fts3SegReaderCursor(Fts3Table *,
|
||||
int, int, int, const char *, int, int, int, Fts3MultiSegReader *);
|
||||
|
||||
/* Flags allowed as part of the 4th argument to SegmentReaderIterate() */
|
||||
|
@ -599,7 +599,7 @@ int sqlite3Fts3ReadInt(const char *z, int *pnOut);
|
|||
/* fts3_tokenizer.c */
|
||||
const char *sqlite3Fts3NextToken(const char *, int *);
|
||||
int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *);
|
||||
int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *,
|
||||
int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *,
|
||||
sqlite3_tokenizer **, char **
|
||||
);
|
||||
int sqlite3Fts3IsIdChar(char);
|
||||
|
@ -635,7 +635,7 @@ int sqlite3Fts3MsrIncrStart(
|
|||
Fts3Table*, Fts3MultiSegReader*, int, const char*, int);
|
||||
int sqlite3Fts3MsrIncrNext(
|
||||
Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *);
|
||||
int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
|
||||
int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
|
||||
int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
|
||||
int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
|
||||
|
||||
|
|
22
third_party/sqlite3/fts3_aux.c
vendored
22
third_party/sqlite3/fts3_aux.c
vendored
|
@ -80,11 +80,11 @@ static int fts3auxConnectMethod(
|
|||
*/
|
||||
if( argc!=4 && argc!=5 ) goto bad_args;
|
||||
|
||||
zDb = argv[1];
|
||||
zDb = argv[1];
|
||||
nDb = (int)strlen(zDb);
|
||||
if( argc==5 ){
|
||||
if( nDb==4 && 0==sqlite3_strnicmp("temp", zDb, 4) ){
|
||||
zDb = argv[3];
|
||||
zDb = argv[3];
|
||||
nDb = (int)strlen(zDb);
|
||||
zFts3 = argv[4];
|
||||
}else{
|
||||
|
@ -148,7 +148,7 @@ static int fts3auxDisconnectMethod(sqlite3_vtab *pVtab){
|
|||
** xBestIndex - Analyze a WHERE and ORDER BY clause.
|
||||
*/
|
||||
static int fts3auxBestIndexMethod(
|
||||
sqlite3_vtab *pVTab,
|
||||
sqlite3_vtab *pVTab,
|
||||
sqlite3_index_info *pInfo
|
||||
){
|
||||
int i;
|
||||
|
@ -161,14 +161,14 @@ static int fts3auxBestIndexMethod(
|
|||
UNUSED_PARAMETER(pVTab);
|
||||
|
||||
/* This vtab delivers always results in "ORDER BY term ASC" order. */
|
||||
if( pInfo->nOrderBy==1
|
||||
&& pInfo->aOrderBy[0].iColumn==0
|
||||
if( pInfo->nOrderBy==1
|
||||
&& pInfo->aOrderBy[0].iColumn==0
|
||||
&& pInfo->aOrderBy[0].desc==0
|
||||
){
|
||||
pInfo->orderByConsumed = 1;
|
||||
}
|
||||
|
||||
/* Search for equality and range constraints on the "term" column.
|
||||
/* Search for equality and range constraints on the "term" column.
|
||||
** And equality constraints on the hidden "languageid" column. */
|
||||
for(i=0; i<pInfo->nConstraint; i++){
|
||||
if( pInfo->aConstraint[i].usable ){
|
||||
|
@ -249,11 +249,11 @@ static int fts3auxCloseMethod(sqlite3_vtab_cursor *pCursor){
|
|||
static int fts3auxGrowStatArray(Fts3auxCursor *pCsr, int nSize){
|
||||
if( nSize>pCsr->nStat ){
|
||||
struct Fts3auxColstats *aNew;
|
||||
aNew = (struct Fts3auxColstats *)sqlite3_realloc64(pCsr->aStat,
|
||||
aNew = (struct Fts3auxColstats *)sqlite3_realloc64(pCsr->aStat,
|
||||
sizeof(struct Fts3auxColstats) * nSize
|
||||
);
|
||||
if( aNew==0 ) return SQLITE_NOMEM;
|
||||
memset(&aNew[pCsr->nStat], 0,
|
||||
memset(&aNew[pCsr->nStat], 0,
|
||||
sizeof(struct Fts3auxColstats) * (nSize - pCsr->nStat)
|
||||
);
|
||||
pCsr->aStat = aNew;
|
||||
|
@ -313,8 +313,8 @@ static int fts3auxNextMethod(sqlite3_vtab_cursor *pCursor){
|
|||
|
||||
/* State 1. In this state we are expecting either a 1, indicating
|
||||
** that the following integer will be a column number, or the
|
||||
** start of a position list for column 0.
|
||||
**
|
||||
** start of a position list for column 0.
|
||||
**
|
||||
** The only difference between state 1 and state 2 is that if the
|
||||
** integer encountered in state 1 is not 0 or 1, then we need to
|
||||
** increment the column 0 "nDoc" count for this term.
|
||||
|
@ -427,7 +427,7 @@ static int fts3auxFilterMethod(
|
|||
if( pCsr->zStop==0 ) return SQLITE_NOMEM;
|
||||
pCsr->nStop = (int)strlen(pCsr->zStop);
|
||||
}
|
||||
|
||||
|
||||
if( iLangid>=0 ){
|
||||
iLangVal = sqlite3_value_int(apVal[iLangid]);
|
||||
|
||||
|
|
96
third_party/sqlite3/fts3_expr.c
vendored
96
third_party/sqlite3/fts3_expr.c
vendored
|
@ -20,7 +20,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
/*
|
||||
** By default, this module parses the legacy syntax that has been
|
||||
** By default, this module parses the legacy syntax that has been
|
||||
** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
** is defined, then it uses the new syntax. The differences between
|
||||
** the new and the old syntaxes are:
|
||||
|
@ -29,7 +29,7 @@
|
|||
**
|
||||
** b) The new syntax supports the AND and NOT operators. The old does not.
|
||||
**
|
||||
** c) The old syntax supports the "-" token qualifier. This is not
|
||||
** c) The old syntax supports the "-" token qualifier. This is not
|
||||
** supported by the new syntax (it is replaced by the NOT operator).
|
||||
**
|
||||
** d) When using the old syntax, the OR operator has a greater precedence
|
||||
|
@ -38,7 +38,7 @@
|
|||
**
|
||||
** If compiled with SQLITE_TEST defined, then this module exports the
|
||||
** symbol "int sqlite3_fts3_enable_parentheses". Setting this variable
|
||||
** to zero causes the module to use the old syntax. If it is set to
|
||||
** to zero causes the module to use the old syntax. If it is set to
|
||||
** non-zero the new syntax is activated. This is so both syntaxes can
|
||||
** be tested using a single build of testfixture.
|
||||
**
|
||||
|
@ -67,7 +67,7 @@
|
|||
#ifdef SQLITE_TEST
|
||||
int sqlite3_fts3_enable_parentheses = 0;
|
||||
#else
|
||||
# ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
# ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
# define sqlite3_fts3_enable_parentheses 1
|
||||
# else
|
||||
# define sqlite3_fts3_enable_parentheses 0
|
||||
|
@ -85,7 +85,7 @@ int sqlite3_fts3_enable_parentheses = 0;
|
|||
/*
|
||||
** isNot:
|
||||
** This variable is used by function getNextNode(). When getNextNode() is
|
||||
** called, it sets ParseContext.isNot to true if the 'next node' is a
|
||||
** called, it sets ParseContext.isNot to true if the 'next node' is a
|
||||
** FTSQUERY_PHRASE with a unary "-" attached to it. i.e. "mysql" in the
|
||||
** FTS3 query "sqlite -mysql". Otherwise, ParseContext.isNot is set to
|
||||
** zero.
|
||||
|
@ -104,7 +104,7 @@ struct ParseContext {
|
|||
};
|
||||
|
||||
/*
|
||||
** This function is equivalent to the standard isspace() function.
|
||||
** This function is equivalent to the standard isspace() function.
|
||||
**
|
||||
** The standard isspace() can be awkward to use safely, because although it
|
||||
** is defined to accept an argument of type int, its behavior when passed
|
||||
|
@ -120,7 +120,7 @@ static int fts3isspace(char c){
|
|||
|
||||
/*
|
||||
** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
|
||||
** zero the memory before returning a pointer to it. If unsuccessful,
|
||||
** zero the memory before returning a pointer to it. If unsuccessful,
|
||||
** return NULL.
|
||||
*/
|
||||
static void *fts3MallocZero(sqlite3_int64 nByte){
|
||||
|
@ -168,7 +168,7 @@ static int fts3ExprParse(ParseContext *, const char *, int, Fts3Expr **, int *);
|
|||
** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
|
||||
** single token and set *ppExpr to point to it. If the end of the buffer is
|
||||
** reached before a token is found, set *ppExpr to zero. It is the
|
||||
** responsibility of the caller to eventually deallocate the allocated
|
||||
** responsibility of the caller to eventually deallocate the allocated
|
||||
** Fts3Expr structure (if any) by passing it to sqlite3_free().
|
||||
**
|
||||
** Return SQLITE_OK if successful, or SQLITE_NOMEM if a memory allocation
|
||||
|
@ -222,8 +222,8 @@ static int getNextToken(
|
|||
}
|
||||
|
||||
while( 1 ){
|
||||
if( !sqlite3_fts3_enable_parentheses
|
||||
&& iStart>0 && z[iStart-1]=='-'
|
||||
if( !sqlite3_fts3_enable_parentheses
|
||||
&& iStart>0 && z[iStart-1]=='-'
|
||||
){
|
||||
pParse->isNot = 1;
|
||||
iStart--;
|
||||
|
@ -243,7 +243,7 @@ static int getNextToken(
|
|||
|
||||
pModule->xClose(pCursor);
|
||||
}
|
||||
|
||||
|
||||
*ppExpr = pRet;
|
||||
return rc;
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ static void *fts3ReallocOrFree(void *pOrig, sqlite3_int64 nNew){
|
|||
** Buffer zInput, length nInput, contains the contents of a quoted string
|
||||
** that appeared as part of an fts3 query expression. Neither quote character
|
||||
** is included in the buffer. This function attempts to tokenize the entire
|
||||
** input buffer and create an Fts3Expr structure of type FTSQUERY_PHRASE
|
||||
** input buffer and create an Fts3Expr structure of type FTSQUERY_PHRASE
|
||||
** containing the results.
|
||||
**
|
||||
** If successful, SQLITE_OK is returned and *ppExpr set to point at the
|
||||
|
@ -290,7 +290,7 @@ static int getNextString(
|
|||
int nToken = 0;
|
||||
|
||||
/* The final Fts3Expr data structure, including the Fts3Phrase,
|
||||
** Fts3PhraseToken structures token buffers are all stored as a single
|
||||
** Fts3PhraseToken structures token buffers are all stored as a single
|
||||
** allocation so that the expression can be freed with a single call to
|
||||
** sqlite3_free(). Setting this up requires a two pass approach.
|
||||
**
|
||||
|
@ -299,7 +299,7 @@ static int getNextString(
|
|||
** to assemble data in two dynamic buffers:
|
||||
**
|
||||
** Buffer p: Points to the Fts3Expr structure, followed by the Fts3Phrase
|
||||
** structure, followed by the array of Fts3PhraseToken
|
||||
** structure, followed by the array of Fts3PhraseToken
|
||||
** structures. This pass only populates the Fts3PhraseToken array.
|
||||
**
|
||||
** Buffer zTemp: Contains copies of all tokens.
|
||||
|
@ -384,7 +384,7 @@ no_mem:
|
|||
}
|
||||
|
||||
/*
|
||||
** The output variable *ppExpr is populated with an allocated Fts3Expr
|
||||
** The output variable *ppExpr is populated with an allocated Fts3Expr
|
||||
** structure, or set to 0 if the end of the input buffer is reached.
|
||||
**
|
||||
** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM
|
||||
|
@ -420,7 +420,7 @@ static int getNextNode(
|
|||
pParse->isNot = 0;
|
||||
|
||||
/* Skip over any whitespace before checking for a keyword, an open or
|
||||
** close bracket, or a quoted string.
|
||||
** close bracket, or a quoted string.
|
||||
*/
|
||||
while( nInput>0 && fts3isspace(*zInput) ){
|
||||
nInput--;
|
||||
|
@ -453,10 +453,10 @@ static int getNextNode(
|
|||
|
||||
/* At this point this is probably a keyword. But for that to be true,
|
||||
** the next byte must contain either whitespace, an open or close
|
||||
** parenthesis, a quote character, or EOF.
|
||||
** parenthesis, a quote character, or EOF.
|
||||
*/
|
||||
cNext = zInput[nKey];
|
||||
if( fts3isspace(cNext)
|
||||
if( fts3isspace(cNext)
|
||||
|| cNext=='"' || cNext=='(' || cNext==')' || cNext==0
|
||||
){
|
||||
pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr));
|
||||
|
@ -510,15 +510,15 @@ static int getNextNode(
|
|||
}
|
||||
}
|
||||
|
||||
/* If control flows to this point, this must be a regular token, or
|
||||
/* If control flows to this point, this must be a regular token, or
|
||||
** the end of the input. Read a regular token using the sqlite3_tokenizer
|
||||
** interface. Before doing so, figure out if there is an explicit
|
||||
** column specifier for the token.
|
||||
** column specifier for the token.
|
||||
**
|
||||
** TODO: Strangely, it is not possible to associate a column specifier
|
||||
** with a quoted phrase, only with a single token. Not sure if this was
|
||||
** an implementation artifact or an intentional decision when fts3 was
|
||||
** first implemented. Whichever it was, this module duplicates the
|
||||
** first implemented. Whichever it was, this module duplicates the
|
||||
** limitation.
|
||||
*/
|
||||
iCol = pParse->iDefaultCol;
|
||||
|
@ -526,8 +526,8 @@ static int getNextNode(
|
|||
for(ii=0; ii<pParse->nCol; ii++){
|
||||
const char *zStr = pParse->azCol[ii];
|
||||
int nStr = (int)strlen(zStr);
|
||||
if( nInput>nStr && zInput[nStr]==':'
|
||||
&& sqlite3_strnicmp(zStr, zInput, nStr)==0
|
||||
if( nInput>nStr && zInput[nStr]==':'
|
||||
&& sqlite3_strnicmp(zStr, zInput, nStr)==0
|
||||
){
|
||||
iCol = ii;
|
||||
iColLen = (int)((zInput - z) + nStr + 1);
|
||||
|
@ -572,7 +572,7 @@ static int opPrecedence(Fts3Expr *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** Argument ppHead contains a pointer to the current head of a query
|
||||
** Argument ppHead contains a pointer to the current head of a query
|
||||
** expression tree being parsed. pPrev is the expression node most recently
|
||||
** inserted into the tree. This function adds pNew, which is always a binary
|
||||
** operator node, into the expression tree based on the relative precedence
|
||||
|
@ -602,7 +602,7 @@ static void insertBinaryOperator(
|
|||
|
||||
/*
|
||||
** Parse the fts3 query expression found in buffer z, length n. This function
|
||||
** returns either when the end of the buffer is reached or an unmatched
|
||||
** returns either when the end of the buffer is reached or an unmatched
|
||||
** closing bracket - ')' - is encountered.
|
||||
**
|
||||
** If successful, SQLITE_OK is returned, *ppExpr is set to point to the
|
||||
|
@ -634,8 +634,8 @@ static int fts3ExprParse(
|
|||
if( p ){
|
||||
int isPhrase;
|
||||
|
||||
if( !sqlite3_fts3_enable_parentheses
|
||||
&& p->eType==FTSQUERY_PHRASE && pParse->isNot
|
||||
if( !sqlite3_fts3_enable_parentheses
|
||||
&& p->eType==FTSQUERY_PHRASE && pParse->isNot
|
||||
){
|
||||
/* Create an implicit NOT operator. */
|
||||
Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr));
|
||||
|
@ -756,13 +756,13 @@ exprparse_out:
|
|||
}
|
||||
|
||||
/*
|
||||
** Return SQLITE_ERROR if the maximum depth of the expression tree passed
|
||||
** Return SQLITE_ERROR if the maximum depth of the expression tree passed
|
||||
** as the only argument is more than nMaxDepth.
|
||||
*/
|
||||
static int fts3ExprCheckDepth(Fts3Expr *p, int nMaxDepth){
|
||||
int rc = SQLITE_OK;
|
||||
if( p ){
|
||||
if( nMaxDepth<0 ){
|
||||
if( nMaxDepth<0 ){
|
||||
rc = SQLITE_TOOBIG;
|
||||
}else{
|
||||
rc = fts3ExprCheckDepth(p->pLeft, nMaxDepth-1);
|
||||
|
@ -777,12 +777,12 @@ static int fts3ExprCheckDepth(Fts3Expr *p, int nMaxDepth){
|
|||
/*
|
||||
** This function attempts to transform the expression tree at (*pp) to
|
||||
** an equivalent but more balanced form. The tree is modified in place.
|
||||
** If successful, SQLITE_OK is returned and (*pp) set to point to the
|
||||
** new root expression node.
|
||||
** If successful, SQLITE_OK is returned and (*pp) set to point to the
|
||||
** new root expression node.
|
||||
**
|
||||
** nMaxDepth is the maximum allowable depth of the balanced sub-tree.
|
||||
**
|
||||
** Otherwise, if an error occurs, an SQLite error code is returned and
|
||||
** Otherwise, if an error occurs, an SQLite error code is returned and
|
||||
** expression (*pp) freed.
|
||||
*/
|
||||
static int fts3ExprBalance(Fts3Expr **pp, int nMaxDepth){
|
||||
|
@ -897,7 +897,7 @@ static int fts3ExprBalance(Fts3Expr **pp, int nMaxDepth){
|
|||
}
|
||||
pRoot = p;
|
||||
}else{
|
||||
/* An error occurred. Delete the contents of the apLeaf[] array
|
||||
/* An error occurred. Delete the contents of the apLeaf[] array
|
||||
** and pFree list. Everything else is cleaned up by the call to
|
||||
** sqlite3Fts3ExprFree(pRoot) below. */
|
||||
Fts3Expr *pDel;
|
||||
|
@ -939,7 +939,7 @@ static int fts3ExprBalance(Fts3Expr **pp, int nMaxDepth){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3Fts3ExprFree(pRoot);
|
||||
pRoot = 0;
|
||||
|
@ -953,9 +953,9 @@ static int fts3ExprBalance(Fts3Expr **pp, int nMaxDepth){
|
|||
** differences:
|
||||
**
|
||||
** 1. It does not do expression rebalancing.
|
||||
** 2. It does not check that the expression does not exceed the
|
||||
** 2. It does not check that the expression does not exceed the
|
||||
** maximum allowable depth.
|
||||
** 3. Even if it fails, *ppExpr may still be set to point to an
|
||||
** 3. Even if it fails, *ppExpr may still be set to point to an
|
||||
** expression tree. It should be deleted using sqlite3Fts3ExprFree()
|
||||
** in this case.
|
||||
*/
|
||||
|
@ -994,7 +994,7 @@ static int fts3ExprParseUnbalanced(
|
|||
if( rc==SQLITE_OK && sParse.nNest ){
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -1013,7 +1013,7 @@ static int fts3ExprParseUnbalanced(
|
|||
** The first parameter, pTokenizer, is passed the fts3 tokenizer module to
|
||||
** use to normalize query tokens while parsing the expression. The azCol[]
|
||||
** array, which is assumed to contain nCol entries, should contain the names
|
||||
** of each column in the target fts3 table, in order from left to right.
|
||||
** of each column in the target fts3 table, in order from left to right.
|
||||
** Column names must be nul-terminated strings.
|
||||
**
|
||||
** The iDefaultCol parameter should be passed the index of the table column
|
||||
|
@ -1036,7 +1036,7 @@ int sqlite3Fts3ExprParse(
|
|||
int rc = fts3ExprParseUnbalanced(
|
||||
pTokenizer, iLangid, azCol, bFts4, nCol, iDefaultCol, z, n, ppExpr
|
||||
);
|
||||
|
||||
|
||||
/* Rebalance the expression. And check that its depth does not exceed
|
||||
** SQLITE_FTS3_MAX_EXPR_DEPTH. */
|
||||
if( rc==SQLITE_OK && *ppExpr ){
|
||||
|
@ -1051,7 +1051,7 @@ int sqlite3Fts3ExprParse(
|
|||
*ppExpr = 0;
|
||||
if( rc==SQLITE_TOOBIG ){
|
||||
sqlite3Fts3ErrMsg(pzErr,
|
||||
"FTS expression tree is too large (maximum depth %d)",
|
||||
"FTS expression tree is too large (maximum depth %d)",
|
||||
SQLITE_FTS3_MAX_EXPR_DEPTH
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
|
@ -1113,11 +1113,11 @@ void sqlite3Fts3ExprFree(Fts3Expr *pDel){
|
|||
/*
|
||||
** Return a pointer to a buffer containing a text representation of the
|
||||
** expression passed as the first argument. The buffer is obtained from
|
||||
** sqlite3_malloc(). It is the responsibility of the caller to use
|
||||
** sqlite3_malloc(). It is the responsibility of the caller to use
|
||||
** sqlite3_free() to release the memory. If an OOM condition is encountered,
|
||||
** NULL is returned.
|
||||
**
|
||||
** If the second argument is not NULL, then its contents are prepended to
|
||||
** If the second argument is not NULL, then its contents are prepended to
|
||||
** the returned expression text and then freed using sqlite3_free().
|
||||
*/
|
||||
static char *exprToString(Fts3Expr *pExpr, char *zBuf){
|
||||
|
@ -1131,7 +1131,7 @@ static char *exprToString(Fts3Expr *pExpr, char *zBuf){
|
|||
zBuf = sqlite3_mprintf(
|
||||
"%zPHRASE %d 0", zBuf, pPhrase->iColumn);
|
||||
for(i=0; zBuf && i<pPhrase->nToken; i++){
|
||||
zBuf = sqlite3_mprintf("%z %.*s%s", zBuf,
|
||||
zBuf = sqlite3_mprintf("%z %.*s%s", zBuf,
|
||||
pPhrase->aToken[i].n, pPhrase->aToken[i].z,
|
||||
(pPhrase->aToken[i].isPrefix?"+":"")
|
||||
);
|
||||
|
@ -1164,7 +1164,7 @@ static char *exprToString(Fts3Expr *pExpr, char *zBuf){
|
|||
}
|
||||
|
||||
/*
|
||||
** This is the implementation of a scalar SQL function used to test the
|
||||
** This is the implementation of a scalar SQL function used to test the
|
||||
** expression parser. It should be called as follows:
|
||||
**
|
||||
** fts3_exprtest(<tokenizer>, <expr>, <column 1>, ...);
|
||||
|
@ -1197,7 +1197,7 @@ static void fts3ExprTestCommon(
|
|||
char *zErr = 0;
|
||||
|
||||
if( argc<3 ){
|
||||
sqlite3_result_error(context,
|
||||
sqlite3_result_error(context,
|
||||
"Usage: fts3_exprtest(tokenizer, expr, col1, ...", -1
|
||||
);
|
||||
return;
|
||||
|
@ -1275,15 +1275,15 @@ static void fts3ExprTestRebalance(
|
|||
}
|
||||
|
||||
/*
|
||||
** Register the query expression parser test function fts3_exprtest()
|
||||
** with database connection db.
|
||||
** Register the query expression parser test function fts3_exprtest()
|
||||
** with database connection db.
|
||||
*/
|
||||
int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash *pHash){
|
||||
int rc = sqlite3_create_function(
|
||||
db, "fts3_exprtest", -1, SQLITE_UTF8, (void*)pHash, fts3ExprTest, 0, 0
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(db, "fts3_exprtest_rebalance",
|
||||
rc = sqlite3_create_function(db, "fts3_exprtest_rebalance",
|
||||
-1, SQLITE_UTF8, (void*)pHash, fts3ExprTestRebalance, 0, 0
|
||||
);
|
||||
}
|
||||
|
|
18
third_party/sqlite3/fts3_hash.c
vendored
18
third_party/sqlite3/fts3_hash.c
vendored
|
@ -50,8 +50,8 @@ static void fts3HashFree(void *p){
|
|||
** fields of the Hash structure.
|
||||
**
|
||||
** "pNew" is a pointer to the hash table that is to be initialized.
|
||||
** keyClass is one of the constants
|
||||
** FTS3_HASH_BINARY or FTS3_HASH_STRING. The value of keyClass
|
||||
** keyClass is one of the constants
|
||||
** FTS3_HASH_BINARY or FTS3_HASH_STRING. The value of keyClass
|
||||
** determines what kind of key the hash table will use. "copyKey" is
|
||||
** true if the hash table should make its own private copy of keys and
|
||||
** false if it should just use the supplied pointer.
|
||||
|
@ -128,7 +128,7 @@ static int fts3BinCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
|||
/*
|
||||
** Return a pointer to the appropriate hash function given the key class.
|
||||
**
|
||||
** The C syntax in this function definition may be unfamilar to some
|
||||
** The C syntax in this function definition may be unfamilar to some
|
||||
** programmers, so we provide the following additional explanation:
|
||||
**
|
||||
** The name of the function is "ftsHashFunction". The function takes a
|
||||
|
@ -188,7 +188,7 @@ static void fts3HashInsertElement(
|
|||
|
||||
|
||||
/* Resize the hash table so that it cantains "new_size" buckets.
|
||||
** "new_size" must be a power of 2. The hash table might fail
|
||||
** "new_size" must be a power of 2. The hash table might fail
|
||||
** to resize if sqliteMalloc() fails.
|
||||
**
|
||||
** Return non-zero if a memory allocation error occurs.
|
||||
|
@ -233,7 +233,7 @@ static Fts3HashElem *fts3FindElementByHash(
|
|||
count = pEntry->count;
|
||||
xCompare = ftsCompareFunction(pH->keyClass);
|
||||
while( count-- && elem ){
|
||||
if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
|
||||
if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
|
||||
return elem;
|
||||
}
|
||||
elem = elem->next;
|
||||
|
@ -252,7 +252,7 @@ static void fts3RemoveElementByHash(
|
|||
){
|
||||
struct _fts3ht *pEntry;
|
||||
if( elem->prev ){
|
||||
elem->prev->next = elem->next;
|
||||
elem->prev->next = elem->next;
|
||||
}else{
|
||||
pH->first = elem->next;
|
||||
}
|
||||
|
@ -280,8 +280,8 @@ static void fts3RemoveElementByHash(
|
|||
}
|
||||
|
||||
Fts3HashElem *sqlite3Fts3HashFindElem(
|
||||
const Fts3Hash *pH,
|
||||
const void *pKey,
|
||||
const Fts3Hash *pH,
|
||||
const void *pKey,
|
||||
int nKey
|
||||
){
|
||||
int h; /* A hash on key */
|
||||
|
@ -295,7 +295,7 @@ Fts3HashElem *sqlite3Fts3HashFindElem(
|
|||
return fts3FindElementByHash(pH,pKey,nKey, h & (pH->htsize-1));
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Attempt to locate an element of the hash table pH with a key
|
||||
** that matches pKey,nKey. Return the data for this element if it is
|
||||
** found, or NULL if there is no match.
|
||||
|
|
6
third_party/sqlite3/fts3_hash.inc
vendored
6
third_party/sqlite3/fts3_hash.inc
vendored
|
@ -42,7 +42,7 @@ struct Fts3Hash {
|
|||
} *ht;
|
||||
};
|
||||
|
||||
/* Each element in the hash table is an instance of the following
|
||||
/* Each element in the hash table is an instance of the following
|
||||
** structure. All elements are stored on a single doubly-linked list.
|
||||
**
|
||||
** Again, this structure is intended to be opaque, but it can't really
|
||||
|
@ -61,10 +61,10 @@ struct Fts3HashElem {
|
|||
** (including the null-terminator, if any). Case
|
||||
** is respected in comparisons.
|
||||
**
|
||||
** FTS3_HASH_BINARY pKey points to binary data nKey bytes long.
|
||||
** FTS3_HASH_BINARY pKey points to binary data nKey bytes long.
|
||||
** memcmp() is used to compare keys.
|
||||
**
|
||||
** A copy of the key is made if the copyKey parameter to fts3HashInit is 1.
|
||||
** A copy of the key is made if the copyKey parameter to fts3HashInit is 1.
|
||||
*/
|
||||
#define FTS3_HASH_STRING 1
|
||||
#define FTS3_HASH_BINARY 2
|
||||
|
|
4
third_party/sqlite3/fts3_icu.c
vendored
4
third_party/sqlite3/fts3_icu.c
vendored
|
@ -85,7 +85,7 @@ static int icuDestroy(sqlite3_tokenizer *pTokenizer){
|
|||
/*
|
||||
** Prepare to begin tokenizing a particular string. The input
|
||||
** string to be tokenized is pInput[0..nBytes-1]. A cursor
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** *ppCursor.
|
||||
*/
|
||||
static int icuOpen(
|
||||
|
@ -127,7 +127,7 @@ static int icuOpen(
|
|||
pCsr->aOffset = (int *)&pCsr->aChar[(nChar+3)&~3];
|
||||
|
||||
pCsr->aOffset[iOut] = iInput;
|
||||
U8_NEXT(zInput, iInput, nInput, c);
|
||||
U8_NEXT(zInput, iInput, nInput, c);
|
||||
while( c>0 ){
|
||||
int isError = 0;
|
||||
c = u_foldCase(c, opt);
|
||||
|
|
20
third_party/sqlite3/fts3_porter.c
vendored
20
third_party/sqlite3/fts3_porter.c
vendored
|
@ -83,7 +83,7 @@ static int porterDestroy(sqlite3_tokenizer *pTokenizer){
|
|||
/*
|
||||
** Prepare to begin tokenizing a particular string. The input
|
||||
** string to be tokenized is zInput[0..nInput-1]. A cursor
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** *ppCursor.
|
||||
*/
|
||||
static int porterOpen(
|
||||
|
@ -136,7 +136,7 @@ static const char cType[] = {
|
|||
/*
|
||||
** isConsonant() and isVowel() determine if their first character in
|
||||
** the string they point to is a consonant or a vowel, according
|
||||
** to Porter ruls.
|
||||
** to Porter ruls.
|
||||
**
|
||||
** A consonate is any letter other than 'a', 'e', 'i', 'o', or 'u'.
|
||||
** 'Y' is a consonant unless it follows another consonant,
|
||||
|
@ -256,11 +256,11 @@ static int star_oh(const char *z){
|
|||
|
||||
/*
|
||||
** If the word ends with zFrom and xCond() is true for the stem
|
||||
** of the word that preceeds the zFrom ending, then change the
|
||||
** of the word that preceeds the zFrom ending, then change the
|
||||
** ending to zTo.
|
||||
**
|
||||
** The input word *pz and zFrom are both in reverse order. zTo
|
||||
** is in normal order.
|
||||
** is in normal order.
|
||||
**
|
||||
** Return TRUE if zFrom matches. Return FALSE if zFrom does not
|
||||
** match. Not that TRUE is returned even if xCond() fails and
|
||||
|
@ -329,9 +329,9 @@ static void copy_stemmer(const char *zIn, int nIn, char *zOut, int *pnOut){
|
|||
** word contains digits, 3 bytes are taken from the beginning and
|
||||
** 3 bytes from the end. For long words without digits, 10 bytes
|
||||
** are taken from each end. US-ASCII case folding still applies.
|
||||
**
|
||||
** If the input word contains not digits but does characters not
|
||||
** in [a-zA-Z] then no stemming is attempted and this routine just
|
||||
**
|
||||
** If the input word contains not digits but does characters not
|
||||
** in [a-zA-Z] then no stemming is attempted and this routine just
|
||||
** copies the input into the input into the output with US-ASCII
|
||||
** case folding.
|
||||
**
|
||||
|
@ -376,11 +376,11 @@ static void porter_stemmer(const char *zIn, int nIn, char *zOut, int *pnOut){
|
|||
}
|
||||
}
|
||||
|
||||
/* Step 1b */
|
||||
/* Step 1b */
|
||||
z2 = z;
|
||||
if( stem(&z, "dee", "ee", m_gt_0) ){
|
||||
/* Do nothing. The work was all in the test */
|
||||
}else if(
|
||||
}else if(
|
||||
(stem(&z, "gni", "", hasVowel) || stem(&z, "de", "", hasVowel))
|
||||
&& z!=z2
|
||||
){
|
||||
|
@ -419,7 +419,7 @@ static void porter_stemmer(const char *zIn, int nIn, char *zOut, int *pnOut){
|
|||
stem(&z, "igol", "log", m_gt_0);
|
||||
break;
|
||||
case 'l':
|
||||
if( !stem(&z, "ilb", "ble", m_gt_0)
|
||||
if( !stem(&z, "ilb", "ble", m_gt_0)
|
||||
&& !stem(&z, "illa", "al", m_gt_0)
|
||||
&& !stem(&z, "iltne", "ent", m_gt_0)
|
||||
&& !stem(&z, "ile", "e", m_gt_0)
|
||||
|
|
112
third_party/sqlite3/fts3_snippet.c
vendored
112
third_party/sqlite3/fts3_snippet.c
vendored
|
@ -32,7 +32,7 @@
|
|||
#define FTS3_MATCHINFO_LHITS_BM 'b' /* nCol*nPhrase values */
|
||||
|
||||
/*
|
||||
** The default value for the second argument to matchinfo().
|
||||
** The default value for the second argument to matchinfo().
|
||||
*/
|
||||
#define FTS3_MATCHINFO_DEFAULT "pcx"
|
||||
|
||||
|
@ -49,7 +49,7 @@ struct LoadDoclistCtx {
|
|||
};
|
||||
|
||||
/*
|
||||
** The following types are used as part of the implementation of the
|
||||
** The following types are used as part of the implementation of the
|
||||
** fts3BestSnippet() routine.
|
||||
*/
|
||||
typedef struct SnippetIter SnippetIter;
|
||||
|
@ -82,7 +82,7 @@ struct SnippetFragment {
|
|||
};
|
||||
|
||||
/*
|
||||
** This type is used as an fts3ExprIterate() context object while
|
||||
** This type is used as an fts3ExprIterate() context object while
|
||||
** accumulating the data returned by the matchinfo() function.
|
||||
*/
|
||||
typedef struct MatchInfo MatchInfo;
|
||||
|
@ -153,8 +153,8 @@ static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
|
|||
static void fts3MIBufferFree(void *p){
|
||||
MatchinfoBuffer *pBuf = (MatchinfoBuffer*)((u8*)p - ((u32*)p)[-1]);
|
||||
|
||||
assert( (u32*)p==&pBuf->aMatchinfo[1]
|
||||
|| (u32*)p==&pBuf->aMatchinfo[pBuf->nElem+2]
|
||||
assert( (u32*)p==&pBuf->aMatchinfo[1]
|
||||
|| (u32*)p==&pBuf->aMatchinfo[pBuf->nElem+2]
|
||||
);
|
||||
if( (u32*)p==&pBuf->aMatchinfo[1] ){
|
||||
pBuf->aRef[1] = 0;
|
||||
|
@ -210,7 +210,7 @@ void sqlite3Fts3MIBufferFree(MatchinfoBuffer *p){
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** End of MatchinfoBuffer code.
|
||||
*************************************************************************/
|
||||
|
||||
|
@ -271,7 +271,7 @@ static int fts3ExprIterate2(
|
|||
** are part of a sub-tree that is the right-hand-side of a NOT operator.
|
||||
** For each phrase node found, the supplied callback function is invoked.
|
||||
**
|
||||
** If the callback function returns anything other than SQLITE_OK,
|
||||
** If the callback function returns anything other than SQLITE_OK,
|
||||
** the iteration is abandoned and the error code returned immediately.
|
||||
** Otherwise, SQLITE_OK is returned after a callback has been made for
|
||||
** all eligible phrase nodes.
|
||||
|
@ -306,11 +306,11 @@ static int fts3ExprLoadDoclistsCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
|
|||
|
||||
/*
|
||||
** Load the doclists for each phrase in the query associated with FTS3 cursor
|
||||
** pCsr.
|
||||
** pCsr.
|
||||
**
|
||||
** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
|
||||
** phrases in the expression (all phrases except those directly or
|
||||
** indirectly descended from the right-hand-side of a NOT operator). If
|
||||
** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
|
||||
** phrases in the expression (all phrases except those directly or
|
||||
** indirectly descended from the right-hand-side of a NOT operator). If
|
||||
** pnToken is not NULL, then it is set to the number of tokens in all
|
||||
** matchable phrases of the expression.
|
||||
*/
|
||||
|
@ -340,7 +340,7 @@ static int fts3ExprPhraseCount(Fts3Expr *pExpr){
|
|||
}
|
||||
|
||||
/*
|
||||
** Advance the position list iterator specified by the first two
|
||||
** Advance the position list iterator specified by the first two
|
||||
** arguments so that it points to the first element with a value greater
|
||||
** than or equal to parameter iNext.
|
||||
*/
|
||||
|
@ -409,7 +409,7 @@ static int fts3SnippetNextCandidate(SnippetIter *pIter){
|
|||
}
|
||||
|
||||
/*
|
||||
** Retrieve information about the current candidate snippet of snippet
|
||||
** Retrieve information about the current candidate snippet of snippet
|
||||
** iterator pIter.
|
||||
*/
|
||||
static void fts3SnippetDetails(
|
||||
|
@ -489,7 +489,7 @@ static int fts3SnippetFindPositions(Fts3Expr *pExpr, int iPhrase, void *ctx){
|
|||
}
|
||||
}else{
|
||||
assert( rc!=SQLITE_OK || (
|
||||
pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
|
||||
pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -497,14 +497,14 @@ static int fts3SnippetFindPositions(Fts3Expr *pExpr, int iPhrase, void *ctx){
|
|||
}
|
||||
|
||||
/*
|
||||
** Select the fragment of text consisting of nFragment contiguous tokens
|
||||
** Select the fragment of text consisting of nFragment contiguous tokens
|
||||
** from column iCol that represent the "best" snippet. The best snippet
|
||||
** is the snippet with the highest score, where scores are calculated
|
||||
** by adding:
|
||||
**
|
||||
** (a) +1 point for each occurrence of a matchable phrase in the snippet.
|
||||
**
|
||||
** (b) +1000 points for the first occurrence of each matchable phrase in
|
||||
** (b) +1000 points for the first occurrence of each matchable phrase in
|
||||
** the snippet for which the corresponding mCovered bit is not set.
|
||||
**
|
||||
** The selected snippet parameters are stored in structure *pFragment before
|
||||
|
@ -565,7 +565,7 @@ static int fts3BestSnippet(
|
|||
}
|
||||
}
|
||||
|
||||
/* Loop through all candidate snippets. Store the best snippet in
|
||||
/* Loop through all candidate snippets. Store the best snippet in
|
||||
** *pFragment. Store its associated 'score' in iBestScore.
|
||||
*/
|
||||
pFragment->iCol = iCol;
|
||||
|
@ -637,8 +637,8 @@ static int fts3StringAppend(
|
|||
**
|
||||
** ........X.....X
|
||||
**
|
||||
** This function "shifts" the beginning of the snippet forward in the
|
||||
** document so that there are approximately the same number of
|
||||
** This function "shifts" the beginning of the snippet forward in the
|
||||
** document so that there are approximately the same number of
|
||||
** non-highlighted terms to the right of the final highlighted term as there
|
||||
** are to the left of the first highlighted term. For example, to this:
|
||||
**
|
||||
|
@ -646,8 +646,8 @@ static int fts3StringAppend(
|
|||
**
|
||||
** This is done as part of extracting the snippet text, not when selecting
|
||||
** the snippet. Snippet selection is done based on doclists only, so there
|
||||
** is no way for fts3BestSnippet() to know whether or not the document
|
||||
** actually contains terms that follow the final highlighted term.
|
||||
** is no way for fts3BestSnippet() to know whether or not the document
|
||||
** actually contains terms that follow the final highlighted term.
|
||||
*/
|
||||
static int fts3SnippetShift(
|
||||
Fts3Table *pTab, /* FTS3 table snippet comes from */
|
||||
|
@ -737,7 +737,7 @@ static int fts3SnippetText(
|
|||
int iCol = pFragment->iCol+1; /* Query column to extract text from */
|
||||
sqlite3_tokenizer_module *pMod; /* Tokenizer module methods object */
|
||||
sqlite3_tokenizer_cursor *pC; /* Tokenizer cursor open on zDoc/nDoc */
|
||||
|
||||
|
||||
zDoc = (const char *)sqlite3_column_text(pCsr->pStmt, iCol);
|
||||
if( zDoc==0 ){
|
||||
if( sqlite3_column_type(pCsr->pStmt, iCol)!=SQLITE_NULL ){
|
||||
|
@ -777,7 +777,7 @@ static int fts3SnippetText(
|
|||
if( rc==SQLITE_DONE ){
|
||||
/* Special case - the last token of the snippet is also the last token
|
||||
** of the column. Append any punctuation that occurred between the end
|
||||
** of the previous token and the end of the document to the output.
|
||||
** of the previous token and the end of the document to the output.
|
||||
** Then break out of the loop. */
|
||||
rc = fts3StringAppend(pOut, &zDoc[iEnd], -1);
|
||||
}
|
||||
|
@ -794,7 +794,7 @@ static int fts3SnippetText(
|
|||
|
||||
/* Now that the shift has been done, check if the initial "..." are
|
||||
** required. They are required if (a) this is not the first fragment,
|
||||
** or (b) this fragment does not begin at position 0 of its column.
|
||||
** or (b) this fragment does not begin at position 0 of its column.
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
if( iPos>0 || iFragment>0 ){
|
||||
|
@ -830,8 +830,8 @@ static int fts3SnippetText(
|
|||
|
||||
|
||||
/*
|
||||
** This function is used to count the entries in a column-list (a
|
||||
** delta-encoded list of term offsets within a single column of a single
|
||||
** This function is used to count the entries in a column-list (a
|
||||
** delta-encoded list of term offsets within a single column of a single
|
||||
** row). When this function is called, *ppCollist should point to the
|
||||
** beginning of the first varint in the column-list (the varint that
|
||||
** contains the position of the first matching term in the column data).
|
||||
|
@ -917,11 +917,11 @@ static int fts3ExprLHitGather(
|
|||
|
||||
/*
|
||||
** fts3ExprIterate() callback used to collect the "global" matchinfo stats
|
||||
** for a single query.
|
||||
** for a single query.
|
||||
**
|
||||
** fts3ExprIterate() callback to load the 'global' elements of a
|
||||
** FTS3_MATCHINFO_HITS matchinfo array. The global stats are those elements
|
||||
** of the matchinfo array that are constant for all rows returned by the
|
||||
** FTS3_MATCHINFO_HITS matchinfo array. The global stats are those elements
|
||||
** of the matchinfo array that are constant for all rows returned by the
|
||||
** current query.
|
||||
**
|
||||
** Argument pCtx is actually a pointer to a struct of type MatchInfo. This
|
||||
|
@ -937,7 +937,7 @@ static int fts3ExprLHitGather(
|
|||
** at least one instance of phrase iPhrase.
|
||||
**
|
||||
** If the phrase pExpr consists entirely of deferred tokens, then all X and
|
||||
** Y values are set to nDoc, where nDoc is the number of documents in the
|
||||
** Y values are set to nDoc, where nDoc is the number of documents in the
|
||||
** file system. This is done because the full-text index doclist is required
|
||||
** to calculate these values properly, and the full-text index doclist is
|
||||
** not available for deferred tokens.
|
||||
|
@ -955,7 +955,7 @@ static int fts3ExprGlobalHitsCb(
|
|||
|
||||
/*
|
||||
** fts3ExprIterate() callback used to collect the "local" part of the
|
||||
** FTS3_MATCHINFO_HITS array. The local stats are those elements of the
|
||||
** FTS3_MATCHINFO_HITS array. The local stats are those elements of the
|
||||
** array that are different for each row returned by the query.
|
||||
*/
|
||||
static int fts3ExprLocalHitsCb(
|
||||
|
@ -982,7 +982,7 @@ static int fts3ExprLocalHitsCb(
|
|||
}
|
||||
|
||||
static int fts3MatchinfoCheck(
|
||||
Fts3Table *pTab,
|
||||
Fts3Table *pTab,
|
||||
char cArg,
|
||||
char **pzErr
|
||||
){
|
||||
|
@ -1007,8 +1007,8 @@ static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
|
|||
|
||||
switch( cArg ){
|
||||
case FTS3_MATCHINFO_NDOC:
|
||||
case FTS3_MATCHINFO_NPHRASE:
|
||||
case FTS3_MATCHINFO_NCOL:
|
||||
case FTS3_MATCHINFO_NPHRASE:
|
||||
case FTS3_MATCHINFO_NCOL:
|
||||
nVal = 1;
|
||||
break;
|
||||
|
||||
|
@ -1074,7 +1074,7 @@ static int fts3MatchinfoSelectDoctotal(
|
|||
}
|
||||
|
||||
/*
|
||||
** An instance of the following structure is used to store state while
|
||||
** An instance of the following structure is used to store state while
|
||||
** iterating through a multi-column position-list corresponding to the
|
||||
** hits for a single phrase on a single row in order to calculate the
|
||||
** values for a matchinfo() FTS3_MATCHINFO_LCS request.
|
||||
|
@ -1087,7 +1087,7 @@ struct LcsIterator {
|
|||
int iPos; /* Current position */
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
** If LcsIterator.iCol is set to the following value, the iterator has
|
||||
** finished iterating through all offsets for all columns.
|
||||
*/
|
||||
|
@ -1124,16 +1124,16 @@ static int fts3LcsIteratorAdvance(LcsIterator *pIter){
|
|||
pIter->pRead = pRead;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This function implements the FTS3_MATCHINFO_LCS matchinfo() flag.
|
||||
** This function implements the FTS3_MATCHINFO_LCS matchinfo() flag.
|
||||
**
|
||||
** If the call is successful, the longest-common-substring lengths for each
|
||||
** column are written into the first nCol elements of the pInfo->aMatchinfo[]
|
||||
** column are written into the first nCol elements of the pInfo->aMatchinfo[]
|
||||
** array before returning. SQLITE_OK is returned in this case.
|
||||
**
|
||||
** Otherwise, if an error occurs, an SQLite error code is returned and the
|
||||
** data written to the first nCol elements of pInfo->aMatchinfo[] is
|
||||
** data written to the first nCol elements of pInfo->aMatchinfo[] is
|
||||
** undefined.
|
||||
*/
|
||||
static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
|
||||
|
@ -1210,7 +1210,7 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
|
|||
|
||||
/*
|
||||
** Populate the buffer pInfo->aMatchinfo[] with an array of integers to
|
||||
** be returned by the matchinfo() function. Argument zArg contains the
|
||||
** be returned by the matchinfo() function. Argument zArg contains the
|
||||
** format string passed as the second argument to matchinfo (or the
|
||||
** default value "pcx" if no second argument was specified). The format
|
||||
** string has already been validated and the pInfo->aMatchinfo[] array
|
||||
|
@ -1221,7 +1221,7 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
|
|||
** rows (i.e. FTS3_MATCHINFO_NPHRASE, NCOL, NDOC, AVGLENGTH and part of HITS)
|
||||
** have already been populated.
|
||||
**
|
||||
** Return SQLITE_OK if successful, or an SQLite error code if an error
|
||||
** Return SQLITE_OK if successful, or an SQLite error code if an error
|
||||
** occurs. If a value other than SQLITE_OK is returned, the state the
|
||||
** pInfo->aMatchinfo[] buffer is left in is undefined.
|
||||
*/
|
||||
|
@ -1246,7 +1246,7 @@ static int fts3MatchinfoValues(
|
|||
case FTS3_MATCHINFO_NCOL:
|
||||
if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nCol;
|
||||
break;
|
||||
|
||||
|
||||
case FTS3_MATCHINFO_NDOC:
|
||||
if( bGlobal ){
|
||||
sqlite3_int64 nDoc = 0;
|
||||
|
@ -1255,7 +1255,7 @@ static int fts3MatchinfoValues(
|
|||
}
|
||||
break;
|
||||
|
||||
case FTS3_MATCHINFO_AVGLENGTH:
|
||||
case FTS3_MATCHINFO_AVGLENGTH:
|
||||
if( bGlobal ){
|
||||
sqlite3_int64 nDoc; /* Number of rows in table */
|
||||
const char *a; /* Aggregate column length array */
|
||||
|
@ -1344,7 +1344,7 @@ static int fts3MatchinfoValues(
|
|||
|
||||
|
||||
/*
|
||||
** Populate pCsr->aMatchinfo[] with data for the current row. The
|
||||
** Populate pCsr->aMatchinfo[] with data for the current row. The
|
||||
** 'matchinfo' data is an array of 32-bit unsigned integers (C type u32).
|
||||
*/
|
||||
static void fts3GetMatchinfo(
|
||||
|
@ -1364,8 +1364,8 @@ static void fts3GetMatchinfo(
|
|||
sInfo.pCursor = pCsr;
|
||||
sInfo.nCol = pTab->nColumn;
|
||||
|
||||
/* If there is cached matchinfo() data, but the format string for the
|
||||
** cache does not match the format string for this request, discard
|
||||
/* If there is cached matchinfo() data, but the format string for the
|
||||
** cache does not match the format string for this request, discard
|
||||
** the cached data. */
|
||||
if( pCsr->pMIBuffer && strcmp(pCsr->pMIBuffer->zMatchinfo, zArg) ){
|
||||
sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
|
||||
|
@ -1373,7 +1373,7 @@ static void fts3GetMatchinfo(
|
|||
}
|
||||
|
||||
/* If Fts3Cursor.pMIBuffer is NULL, then this is the first time the
|
||||
** matchinfo function has been called for this query. In this case
|
||||
** matchinfo function has been called for this query. In this case
|
||||
** allocate the array used to accumulate the matchinfo data and
|
||||
** initialize those elements that are constant for every row.
|
||||
*/
|
||||
|
@ -1448,7 +1448,7 @@ void sqlite3Fts3Snippet(
|
|||
|
||||
/* The returned text includes up to four fragments of text extracted from
|
||||
** the data in the current row. The first iteration of the for(...) loop
|
||||
** below attempts to locate a single fragment of text nToken tokens in
|
||||
** below attempts to locate a single fragment of text nToken tokens in
|
||||
** size that contains at least one instance of all phrases in the query
|
||||
** expression that appear in the current row. If such a fragment of text
|
||||
** cannot be found, the second iteration of the loop attempts to locate
|
||||
|
@ -1519,7 +1519,7 @@ void sqlite3Fts3Snippet(
|
|||
assert( nFToken>0 );
|
||||
|
||||
for(i=0; i<nSnippet && rc==SQLITE_OK; i++){
|
||||
rc = fts3SnippetText(pCsr, &aSnippet[i],
|
||||
rc = fts3SnippetText(pCsr, &aSnippet[i],
|
||||
i, (i==nSnippet-1), nFToken, zStart, zEnd, zEllipsis, &res
|
||||
);
|
||||
}
|
||||
|
@ -1617,7 +1617,7 @@ void sqlite3Fts3Offsets(
|
|||
sCtx.iDocid = pCsr->iPrevId;
|
||||
sCtx.pCsr = pCsr;
|
||||
|
||||
/* Loop through the table columns, appending offset information to
|
||||
/* Loop through the table columns, appending offset information to
|
||||
** string-buffer res for each column.
|
||||
*/
|
||||
for(iCol=0; iCol<pTab->nColumn; iCol++){
|
||||
|
@ -1630,7 +1630,7 @@ void sqlite3Fts3Offsets(
|
|||
const char *zDoc;
|
||||
int nDoc;
|
||||
|
||||
/* Initialize the contents of sCtx.aTerm[] for column iCol. There is
|
||||
/* Initialize the contents of sCtx.aTerm[] for column iCol. There is
|
||||
** no way that this operation can fail, so the return code from
|
||||
** fts3ExprIterate() can be discarded.
|
||||
*/
|
||||
|
@ -1638,11 +1638,11 @@ void sqlite3Fts3Offsets(
|
|||
sCtx.iTerm = 0;
|
||||
(void)fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx);
|
||||
|
||||
/* Retreive the text stored in column iCol. If an SQL NULL is stored
|
||||
/* Retreive the text stored in column iCol. If an SQL NULL is stored
|
||||
** in column iCol, jump immediately to the next iteration of the loop.
|
||||
** If an OOM occurs while retrieving the data (this can happen if SQLite
|
||||
** needs to transform the data from utf-16 to utf-8), return SQLITE_NOMEM
|
||||
** to the caller.
|
||||
** needs to transform the data from utf-16 to utf-8), return SQLITE_NOMEM
|
||||
** to the caller.
|
||||
*/
|
||||
zDoc = (const char *)sqlite3_column_text(pCsr->pStmt, iCol+1);
|
||||
nDoc = sqlite3_column_bytes(pCsr->pStmt, iCol+1);
|
||||
|
@ -1689,7 +1689,7 @@ void sqlite3Fts3Offsets(
|
|||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
char aBuffer[64];
|
||||
sqlite3_snprintf(sizeof(aBuffer), aBuffer,
|
||||
sqlite3_snprintf(sizeof(aBuffer), aBuffer,
|
||||
"%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
|
||||
);
|
||||
rc = fts3StringAppend(&res, aBuffer, -1);
|
||||
|
|
12
third_party/sqlite3/fts3_tokenize_vtab.c
vendored
12
third_party/sqlite3/fts3_tokenize_vtab.c
vendored
|
@ -96,7 +96,7 @@ static int fts3tokQueryTokenizer(
|
|||
|
||||
/*
|
||||
** The second argument, argv[], is an array of pointers to nul-terminated
|
||||
** strings. This function makes a copy of the array and strings into a
|
||||
** strings. This function makes a copy of the array and strings into a
|
||||
** single block of memory. It then dequotes any of the strings that appear
|
||||
** to be quoted.
|
||||
**
|
||||
|
@ -152,7 +152,7 @@ static int fts3tokDequoteArray(
|
|||
** and xCreate are identical operations.
|
||||
**
|
||||
** argv[0]: module name
|
||||
** argv[1]: database name
|
||||
** argv[1]: database name
|
||||
** argv[2]: table name
|
||||
** argv[3]: first argument (tokenizer name)
|
||||
*/
|
||||
|
@ -233,16 +233,16 @@ static int fts3tokDisconnectMethod(sqlite3_vtab *pVtab){
|
|||
** xBestIndex - Analyze a WHERE and ORDER BY clause.
|
||||
*/
|
||||
static int fts3tokBestIndexMethod(
|
||||
sqlite3_vtab *pVTab,
|
||||
sqlite3_vtab *pVTab,
|
||||
sqlite3_index_info *pInfo
|
||||
){
|
||||
int i;
|
||||
UNUSED_PARAMETER(pVTab);
|
||||
|
||||
for(i=0; i<pInfo->nConstraint; i++){
|
||||
if( pInfo->aConstraint[i].usable
|
||||
&& pInfo->aConstraint[i].iColumn==0
|
||||
&& pInfo->aConstraint[i].op==SQLITE_INDEX_CONSTRAINT_EQ
|
||||
if( pInfo->aConstraint[i].usable
|
||||
&& pInfo->aConstraint[i].iColumn==0
|
||||
&& pInfo->aConstraint[i].op==SQLITE_INDEX_CONSTRAINT_EQ
|
||||
){
|
||||
pInfo->idxNum = 1;
|
||||
pInfo->aConstraintUsage[i].argvIndex = 1;
|
||||
|
|
30
third_party/sqlite3/fts3_tokenizer.c
vendored
30
third_party/sqlite3/fts3_tokenizer.c
vendored
|
@ -43,7 +43,7 @@ static int fts3TokenizerEnabled(sqlite3_context *context){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the SQL scalar function for accessing the underlying
|
||||
** Implementation of the SQL scalar function for accessing the underlying
|
||||
** hash table. This function may be called as follows:
|
||||
**
|
||||
** SELECT <function-name>(<key-name>);
|
||||
|
@ -215,7 +215,7 @@ int sqlite3Fts3InitTokenizer(
|
|||
if( rc!=SQLITE_OK ){
|
||||
sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer");
|
||||
}else{
|
||||
(*ppTok)->pModule = m;
|
||||
(*ppTok)->pModule = m;
|
||||
}
|
||||
sqlite3_free((void *)aArg);
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ int sqlite3Fts3InitTokenizer(
|
|||
#include "libc/str/str.h"
|
||||
|
||||
/*
|
||||
** Implementation of a special SQL scalar function for testing tokenizers
|
||||
** Implementation of a special SQL scalar function for testing tokenizers
|
||||
** designed to be used in concert with the Tcl testing framework. This
|
||||
** function must be called with two or more arguments:
|
||||
**
|
||||
|
@ -241,9 +241,9 @@ int sqlite3Fts3InitTokenizer(
|
|||
**
|
||||
** The return value is a string that may be interpreted as a Tcl
|
||||
** list. For each token in the <input-string>, three elements are
|
||||
** added to the returned list. The first is the token position, the
|
||||
** added to the returned list. The first is the token position, the
|
||||
** second is the token text (folded, stemmed, etc.) and the third is the
|
||||
** substring of <input-string> associated with the token. For example,
|
||||
** substring of <input-string> associated with the token. For example,
|
||||
** using the built-in "simple" tokenizer:
|
||||
**
|
||||
** SELECT fts_tokenizer_test('simple', 'I don't see how');
|
||||
|
@ -251,7 +251,7 @@ int sqlite3Fts3InitTokenizer(
|
|||
** will return the string:
|
||||
**
|
||||
** "{0 i I 1 dont don't 2 see see 3 how how}"
|
||||
**
|
||||
**
|
||||
*/
|
||||
static void testFunc(
|
||||
sqlite3_context *context,
|
||||
|
@ -346,8 +346,8 @@ finish:
|
|||
|
||||
static
|
||||
int registerTokenizer(
|
||||
sqlite3 *db,
|
||||
char *zName,
|
||||
sqlite3 *db,
|
||||
char *zName,
|
||||
const sqlite3_tokenizer_module *p
|
||||
){
|
||||
int rc;
|
||||
|
@ -369,8 +369,8 @@ int registerTokenizer(
|
|||
|
||||
static
|
||||
int queryTokenizer(
|
||||
sqlite3 *db,
|
||||
char *zName,
|
||||
sqlite3 *db,
|
||||
char *zName,
|
||||
const sqlite3_tokenizer_module **pp
|
||||
){
|
||||
int rc;
|
||||
|
@ -455,23 +455,23 @@ static void intTestFunc(
|
|||
/*
|
||||
** Set up SQL objects in database db used to access the contents of
|
||||
** the hash table pointed to by argument pHash. The hash table must
|
||||
** been initialized to use string keys, and to take a private copy
|
||||
** been initialized to use string keys, and to take a private copy
|
||||
** of the key when a value is inserted. i.e. by a call similar to:
|
||||
**
|
||||
** sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
|
||||
**
|
||||
** This function adds a scalar function (see header comment above
|
||||
** fts3TokenizerFunc() in this file for details) and, if ENABLE_TABLE is
|
||||
** defined at compilation time, a temporary virtual table (see header
|
||||
** comment above struct HashTableVtab) to the database schema. Both
|
||||
** defined at compilation time, a temporary virtual table (see header
|
||||
** comment above struct HashTableVtab) to the database schema. Both
|
||||
** provide read/write access to the contents of *pHash.
|
||||
**
|
||||
** The third argument to this function, zName, is used as the name
|
||||
** of both the scalar and, if created, the virtual table.
|
||||
*/
|
||||
int sqlite3Fts3InitHashTable(
|
||||
sqlite3 *db,
|
||||
Fts3Hash *pHash,
|
||||
sqlite3 *db,
|
||||
Fts3Hash *pHash,
|
||||
const char *zName
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
|
|
14
third_party/sqlite3/fts3_tokenizer.inc
vendored
14
third_party/sqlite3/fts3_tokenizer.inc
vendored
|
@ -36,7 +36,7 @@
|
|||
** When an fts3 table is created, it passes any arguments passed to
|
||||
** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the
|
||||
** sqlite3_tokenizer_module.xCreate() function of the requested tokenizer
|
||||
** implementation. The xCreate() function in turn returns an
|
||||
** implementation. The xCreate() function in turn returns an
|
||||
** sqlite3_tokenizer structure representing the specific tokenizer to
|
||||
** be used for the fts3 table (customized by the tokenizer clause arguments).
|
||||
**
|
||||
|
@ -68,7 +68,7 @@ struct sqlite3_tokenizer_module {
|
|||
** then argc is set to 2, and the argv[] array contains pointers
|
||||
** to the strings "arg1" and "arg2".
|
||||
**
|
||||
** This method should return either SQLITE_OK (0), or an SQLite error
|
||||
** This method should return either SQLITE_OK (0), or an SQLite error
|
||||
** code. If SQLITE_OK is returned, then *ppTokenizer should be set
|
||||
** to point at the newly created tokenizer structure. The generic
|
||||
** sqlite3_tokenizer.pModule variable should not be initialized by
|
||||
|
@ -89,7 +89,7 @@ struct sqlite3_tokenizer_module {
|
|||
/*
|
||||
** Create a tokenizer cursor to tokenize an input buffer. The caller
|
||||
** is responsible for ensuring that the input buffer remains valid
|
||||
** until the cursor is closed (using the xClose() method).
|
||||
** until the cursor is closed (using the xClose() method).
|
||||
*/
|
||||
int (*xOpen)(
|
||||
sqlite3_tokenizer *pTokenizer, /* Tokenizer object */
|
||||
|
@ -98,7 +98,7 @@ struct sqlite3_tokenizer_module {
|
|||
);
|
||||
|
||||
/*
|
||||
** Destroy an existing tokenizer cursor. The fts3 module calls this
|
||||
** Destroy an existing tokenizer cursor. The fts3 module calls this
|
||||
** method exactly once for each successful call to xOpen().
|
||||
*/
|
||||
int (*xClose)(sqlite3_tokenizer_cursor *pCursor);
|
||||
|
@ -109,7 +109,7 @@ struct sqlite3_tokenizer_module {
|
|||
** "OUT" variables identified below, or SQLITE_DONE to indicate that
|
||||
** the end of the buffer has been reached, or an SQLite error code.
|
||||
**
|
||||
** *ppToken should be set to point at a buffer containing the
|
||||
** *ppToken should be set to point at a buffer containing the
|
||||
** normalized version of the token (i.e. after any case-folding and/or
|
||||
** stemming has been performed). *pnBytes should be set to the length
|
||||
** of this buffer in bytes. The input text that generated the token is
|
||||
|
@ -121,7 +121,7 @@ struct sqlite3_tokenizer_module {
|
|||
**
|
||||
** The buffer *ppToken is set to point at is managed by the tokenizer
|
||||
** implementation. It is only required to be valid until the next call
|
||||
** to xNext() or xClose().
|
||||
** to xNext() or xClose().
|
||||
*/
|
||||
/* TODO(shess) current implementation requires pInput to be
|
||||
** nul-terminated. This should either be fixed, or pInput/nBytes
|
||||
|
@ -139,7 +139,7 @@ struct sqlite3_tokenizer_module {
|
|||
** Methods below this point are only available if iVersion>=1.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
** Configure the language id of a tokenizer cursor.
|
||||
*/
|
||||
int (*xLanguageid)(sqlite3_tokenizer_cursor *pCsr, int iLangid);
|
||||
|
|
2
third_party/sqlite3/fts3_tokenizer1.c
vendored
2
third_party/sqlite3/fts3_tokenizer1.c
vendored
|
@ -107,7 +107,7 @@ static int simpleDestroy(sqlite3_tokenizer *pTokenizer){
|
|||
/*
|
||||
** Prepare to begin tokenizing a particular string. The input
|
||||
** string to be tokenized is pInput[0..nBytes-1]. A cursor
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** *ppCursor.
|
||||
*/
|
||||
static int simpleOpen(
|
||||
|
|
16
third_party/sqlite3/fts3_unicode.c
vendored
16
third_party/sqlite3/fts3_unicode.c
vendored
|
@ -118,7 +118,7 @@ static int unicodeDestroy(sqlite3_tokenizer *pTokenizer){
|
|||
**
|
||||
** For each codepoint in the zIn/nIn string, this function checks if the
|
||||
** sqlite3FtsUnicodeIsalnum() function already returns the desired result.
|
||||
** If so, no action is taken. Otherwise, the codepoint is added to the
|
||||
** If so, no action is taken. Otherwise, the codepoint is added to the
|
||||
** unicode_tokenizer.aiException[] array. For the purposes of tokenization,
|
||||
** the return value of sqlite3FtsUnicodeIsalnum() is inverted for all
|
||||
** codepoints in the aiException[] array.
|
||||
|
@ -144,8 +144,8 @@ static int unicodeAddExceptions(
|
|||
while( z<zTerm ){
|
||||
READ_UTF8(z, zTerm, iCode);
|
||||
assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
|
||||
if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
|
||||
&& sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
|
||||
if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
|
||||
&& sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
|
||||
){
|
||||
nEntry++;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ static int unicodeAddExceptions(
|
|||
z = (const unsigned char *)zIn;
|
||||
while( z<zTerm ){
|
||||
READ_UTF8(z, zTerm, iCode);
|
||||
if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
|
||||
if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
|
||||
&& sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
|
||||
){
|
||||
int i, j;
|
||||
|
@ -265,7 +265,7 @@ static int unicodeCreate(
|
|||
/*
|
||||
** Prepare to begin tokenizing a particular string. The input
|
||||
** string to be tokenized is pInput[0..nBytes-1]. A cursor
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** used to incrementally tokenize this string is returned in
|
||||
** *ppCursor.
|
||||
*/
|
||||
static int unicodeOpen(
|
||||
|
@ -330,7 +330,7 @@ static int unicodeNext(
|
|||
const unsigned char *zTerm = &pCsr->aInput[pCsr->nInput];
|
||||
|
||||
/* Scan past any delimiter characters before the start of the next token.
|
||||
** Return SQLITE_DONE early if this takes us all the way to the end of
|
||||
** Return SQLITE_DONE early if this takes us all the way to the end of
|
||||
** the input. */
|
||||
while( z<zTerm ){
|
||||
READ_UTF8(z, zTerm, iCode);
|
||||
|
@ -362,7 +362,7 @@ static int unicodeNext(
|
|||
/* If the cursor is not at EOF, read the next character */
|
||||
if( z>=zTerm ) break;
|
||||
READ_UTF8(z, zTerm, iCode);
|
||||
}while( unicodeIsAlnum(p, (int)iCode)
|
||||
}while( unicodeIsAlnum(p, (int)iCode)
|
||||
|| sqlite3FtsUnicodeIsdiacritic((int)iCode)
|
||||
);
|
||||
|
||||
|
@ -377,7 +377,7 @@ static int unicodeNext(
|
|||
}
|
||||
|
||||
/*
|
||||
** Set *ppModule to a pointer to the sqlite3_tokenizer_module
|
||||
** Set *ppModule to a pointer to the sqlite3_tokenizer_module
|
||||
** structure for the unicode tokenizer.
|
||||
*/
|
||||
void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const **ppModule){
|
||||
|
|
106
third_party/sqlite3/fts3_unicode2.c
vendored
106
third_party/sqlite3/fts3_unicode2.c
vendored
|
@ -33,11 +33,11 @@ int sqlite3FtsUnicodeIsalnum(int c){
|
|||
** range of unicode codepoints that are not either letters or numbers (i.e.
|
||||
** codepoints for which this function should return 0).
|
||||
**
|
||||
** The most significant 22 bits in each 32-bit value contain the first
|
||||
** The most significant 22 bits in each 32-bit value contain the first
|
||||
** codepoint in the range. The least significant 10 bits are used to store
|
||||
** the size of the range (always at least 1). In other words, the value
|
||||
** ((C<<22) + N) represents a range of N codepoints starting with codepoint
|
||||
** C. It is not possible to represent a range larger than 1023 codepoints
|
||||
** the size of the range (always at least 1). In other words, the value
|
||||
** ((C<<22) + N) represents a range of N codepoints starting with codepoint
|
||||
** C. It is not possible to represent a range larger than 1023 codepoints
|
||||
** using this format.
|
||||
*/
|
||||
static const unsigned int aEntry[] = {
|
||||
|
@ -162,46 +162,46 @@ int sqlite3FtsUnicodeIsalnum(int c){
|
|||
*/
|
||||
static int remove_diacritic(int c, int bComplex){
|
||||
unsigned short aDia[] = {
|
||||
0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
|
||||
2024, 2040, 2060, 2110, 2168, 2206, 2264, 2286,
|
||||
2344, 2383, 2472, 2488, 2516, 2596, 2668, 2732,
|
||||
2782, 2842, 2894, 2954, 2984, 3000, 3028, 3336,
|
||||
3456, 3696, 3712, 3728, 3744, 3766, 3832, 3896,
|
||||
3912, 3928, 3944, 3968, 4008, 4040, 4056, 4106,
|
||||
4138, 4170, 4202, 4234, 4266, 4296, 4312, 4344,
|
||||
4408, 4424, 4442, 4472, 4488, 4504, 6148, 6198,
|
||||
6264, 6280, 6360, 6429, 6505, 6529, 61448, 61468,
|
||||
61512, 61534, 61592, 61610, 61642, 61672, 61688, 61704,
|
||||
61726, 61784, 61800, 61816, 61836, 61880, 61896, 61914,
|
||||
61948, 61998, 62062, 62122, 62154, 62184, 62200, 62218,
|
||||
62252, 62302, 62364, 62410, 62442, 62478, 62536, 62554,
|
||||
62584, 62604, 62640, 62648, 62656, 62664, 62730, 62766,
|
||||
62830, 62890, 62924, 62974, 63032, 63050, 63082, 63118,
|
||||
63182, 63242, 63274, 63310, 63368, 63390,
|
||||
0, 1797, 1848, 1859, 1891, 1928, 1940, 1995,
|
||||
2024, 2040, 2060, 2110, 2168, 2206, 2264, 2286,
|
||||
2344, 2383, 2472, 2488, 2516, 2596, 2668, 2732,
|
||||
2782, 2842, 2894, 2954, 2984, 3000, 3028, 3336,
|
||||
3456, 3696, 3712, 3728, 3744, 3766, 3832, 3896,
|
||||
3912, 3928, 3944, 3968, 4008, 4040, 4056, 4106,
|
||||
4138, 4170, 4202, 4234, 4266, 4296, 4312, 4344,
|
||||
4408, 4424, 4442, 4472, 4488, 4504, 6148, 6198,
|
||||
6264, 6280, 6360, 6429, 6505, 6529, 61448, 61468,
|
||||
61512, 61534, 61592, 61610, 61642, 61672, 61688, 61704,
|
||||
61726, 61784, 61800, 61816, 61836, 61880, 61896, 61914,
|
||||
61948, 61998, 62062, 62122, 62154, 62184, 62200, 62218,
|
||||
62252, 62302, 62364, 62410, 62442, 62478, 62536, 62554,
|
||||
62584, 62604, 62640, 62648, 62656, 62664, 62730, 62766,
|
||||
62830, 62890, 62924, 62974, 63032, 63050, 63082, 63118,
|
||||
63182, 63242, 63274, 63310, 63368, 63390,
|
||||
};
|
||||
#define HIBIT ((unsigned char)0x80)
|
||||
unsigned char aChar[] = {
|
||||
'\0', 'a', 'c', 'e', 'i', 'n',
|
||||
'o', 'u', 'y', 'y', 'a', 'c',
|
||||
'd', 'e', 'e', 'g', 'h', 'i',
|
||||
'j', 'k', 'l', 'n', 'o', 'r',
|
||||
's', 't', 'u', 'u', 'w', 'y',
|
||||
'z', 'o', 'u', 'a', 'i', 'o',
|
||||
'u', 'u'|HIBIT, 'a'|HIBIT, 'g', 'k', 'o',
|
||||
'o'|HIBIT, 'j', 'g', 'n', 'a'|HIBIT, 'a',
|
||||
'e', 'i', 'o', 'r', 'u', 's',
|
||||
't', 'h', 'a', 'e', 'o'|HIBIT, 'o',
|
||||
'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', 'a', 'b',
|
||||
'c'|HIBIT, 'd', 'd', 'e'|HIBIT, 'e', 'e'|HIBIT,
|
||||
'f', 'g', 'h', 'h', 'i', 'i'|HIBIT,
|
||||
'k', 'l', 'l'|HIBIT, 'l', 'm', 'n',
|
||||
'o'|HIBIT, 'p', 'r', 'r'|HIBIT, 'r', 's',
|
||||
's'|HIBIT, 't', 'u', 'u'|HIBIT, 'v', 'w',
|
||||
'w', 'x', 'y', 'z', 'h', 't',
|
||||
'w', 'y', 'a', 'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT,
|
||||
'e', 'e'|HIBIT, 'e'|HIBIT, 'i', 'o', 'o'|HIBIT,
|
||||
'o'|HIBIT, 'o'|HIBIT, 'u', 'u'|HIBIT, 'u'|HIBIT, 'y',
|
||||
'\0', 'a', 'c', 'e', 'i', 'n',
|
||||
'o', 'u', 'y', 'y', 'a', 'c',
|
||||
'd', 'e', 'e', 'g', 'h', 'i',
|
||||
'j', 'k', 'l', 'n', 'o', 'r',
|
||||
's', 't', 'u', 'u', 'w', 'y',
|
||||
'z', 'o', 'u', 'a', 'i', 'o',
|
||||
'u', 'u'|HIBIT, 'a'|HIBIT, 'g', 'k', 'o',
|
||||
'o'|HIBIT, 'j', 'g', 'n', 'a'|HIBIT, 'a',
|
||||
'e', 'i', 'o', 'r', 'u', 's',
|
||||
't', 'h', 'a', 'e', 'o'|HIBIT, 'o',
|
||||
'o'|HIBIT, 'y', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', 'a', 'b',
|
||||
'c'|HIBIT, 'd', 'd', 'e'|HIBIT, 'e', 'e'|HIBIT,
|
||||
'f', 'g', 'h', 'h', 'i', 'i'|HIBIT,
|
||||
'k', 'l', 'l'|HIBIT, 'l', 'm', 'n',
|
||||
'o'|HIBIT, 'p', 'r', 'r'|HIBIT, 'r', 's',
|
||||
's'|HIBIT, 't', 'u', 'u'|HIBIT, 'v', 'w',
|
||||
'w', 'x', 'y', 'z', 'h', 't',
|
||||
'w', 'y', 'a', 'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT,
|
||||
'e', 'e'|HIBIT, 'e'|HIBIT, 'i', 'o', 'o'|HIBIT,
|
||||
'o'|HIBIT, 'o'|HIBIT, 'u', 'u'|HIBIT, 'u'|HIBIT, 'y',
|
||||
};
|
||||
|
||||
unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
|
||||
|
@ -323,19 +323,19 @@ int sqlite3FtsUnicodeFold(int c, int eRemoveDiacritic){
|
|||
{42802, 1, 62}, {42873, 1, 4}, {42877, 76, 1},
|
||||
{42878, 1, 10}, {42891, 0, 1}, {42893, 74, 1},
|
||||
{42896, 1, 4}, {42912, 1, 10}, {42922, 72, 1},
|
||||
{65313, 14, 26},
|
||||
{65313, 14, 26},
|
||||
};
|
||||
static const unsigned short aiOff[] = {
|
||||
1, 2, 8, 15, 16, 26, 28, 32,
|
||||
37, 38, 40, 48, 63, 64, 69, 71,
|
||||
79, 80, 116, 202, 203, 205, 206, 207,
|
||||
209, 210, 211, 213, 214, 217, 218, 219,
|
||||
775, 7264, 10792, 10795, 23228, 23256, 30204, 54721,
|
||||
54753, 54754, 54756, 54787, 54793, 54809, 57153, 57274,
|
||||
57921, 58019, 58363, 61722, 65268, 65341, 65373, 65406,
|
||||
65408, 65410, 65415, 65424, 65436, 65439, 65450, 65462,
|
||||
65472, 65476, 65478, 65480, 65482, 65488, 65506, 65511,
|
||||
65514, 65521, 65527, 65528, 65529,
|
||||
1, 2, 8, 15, 16, 26, 28, 32,
|
||||
37, 38, 40, 48, 63, 64, 69, 71,
|
||||
79, 80, 116, 202, 203, 205, 206, 207,
|
||||
209, 210, 211, 213, 214, 217, 218, 219,
|
||||
775, 7264, 10792, 10795, 23228, 23256, 30204, 54721,
|
||||
54753, 54754, 54756, 54787, 54793, 54809, 57153, 57274,
|
||||
57921, 58019, 58363, 61722, 65268, 65341, 65373, 65406,
|
||||
65408, 65410, 65415, 65424, 65436, 65439, 65450, 65462,
|
||||
65472, 65476, 65478, 65480, 65482, 65488, 65506, 65511,
|
||||
65514, 65521, 65527, 65528, 65529,
|
||||
};
|
||||
|
||||
int ret = c;
|
||||
|
@ -373,7 +373,7 @@ int sqlite3FtsUnicodeFold(int c, int eRemoveDiacritic){
|
|||
ret = remove_diacritic(ret, eRemoveDiacritic==2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if( c>=66560 && c<66600 ){
|
||||
ret = c + 40;
|
||||
}
|
||||
|
|
490
third_party/sqlite3/fts3_write.c
vendored
490
third_party/sqlite3/fts3_write.c
vendored
File diff suppressed because it is too large
Load diff
2478
third_party/sqlite3/fts5.c
vendored
2478
third_party/sqlite3/fts5.c
vendored
File diff suppressed because it is too large
Load diff
100
third_party/sqlite3/fts5.inc
vendored
100
third_party/sqlite3/fts5.inc
vendored
|
@ -56,19 +56,19 @@ struct Fts5PhraseIter {
|
|||
** EXTENSION API FUNCTIONS
|
||||
**
|
||||
** xUserData(pFts):
|
||||
** Return a copy of the context pointer the extension function was
|
||||
** Return a copy of the context pointer the extension function was
|
||||
** registered with.
|
||||
**
|
||||
** xColumnTotalSize(pFts, iCol, pnToken):
|
||||
** If parameter iCol is less than zero, set output variable *pnToken
|
||||
** to the total number of tokens in the FTS5 table. Or, if iCol is
|
||||
** non-negative but less than the number of columns in the table, return
|
||||
** the total number of tokens in column iCol, considering all rows in
|
||||
** the total number of tokens in column iCol, considering all rows in
|
||||
** the FTS5 table.
|
||||
**
|
||||
** If parameter iCol is greater than or equal to the number of columns
|
||||
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
|
||||
** an OOM condition or IO error), an appropriate SQLite error code is
|
||||
** an OOM condition or IO error), an appropriate SQLite error code is
|
||||
** returned.
|
||||
**
|
||||
** xColumnCount(pFts):
|
||||
|
@ -82,7 +82,7 @@ struct Fts5PhraseIter {
|
|||
**
|
||||
** If parameter iCol is greater than or equal to the number of columns
|
||||
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
|
||||
** an OOM condition or IO error), an appropriate SQLite error code is
|
||||
** an OOM condition or IO error), an appropriate SQLite error code is
|
||||
** returned.
|
||||
**
|
||||
** This function may be quite inefficient if used with an FTS5 table
|
||||
|
@ -109,8 +109,8 @@ struct Fts5PhraseIter {
|
|||
** an error code (i.e. SQLITE_NOMEM) if an error occurs.
|
||||
**
|
||||
** This API can be quite slow if used with an FTS5 table created with the
|
||||
** "detail=none" or "detail=column" option. If the FTS5 table is created
|
||||
** with either "detail=none" or "detail=column" and "content=" option
|
||||
** "detail=none" or "detail=column" option. If the FTS5 table is created
|
||||
** with either "detail=none" or "detail=column" and "content=" option
|
||||
** (i.e. if it is a contentless table), then this API always returns 0.
|
||||
**
|
||||
** xInst:
|
||||
|
@ -125,7 +125,7 @@ struct Fts5PhraseIter {
|
|||
** code (i.e. SQLITE_NOMEM) if an error occurs.
|
||||
**
|
||||
** This API can be quite slow if used with an FTS5 table created with the
|
||||
** "detail=none" or "detail=column" option.
|
||||
** "detail=none" or "detail=column" option.
|
||||
**
|
||||
** xRowid:
|
||||
** Returns the rowid of the current row.
|
||||
|
@ -141,11 +141,11 @@ struct Fts5PhraseIter {
|
|||
**
|
||||
** with $p set to a phrase equivalent to the phrase iPhrase of the
|
||||
** current query is executed. Any column filter that applies to
|
||||
** phrase iPhrase of the current query is included in $p. For each
|
||||
** row visited, the callback function passed as the fourth argument
|
||||
** is invoked. The context and API objects passed to the callback
|
||||
** phrase iPhrase of the current query is included in $p. For each
|
||||
** row visited, the callback function passed as the fourth argument
|
||||
** is invoked. The context and API objects passed to the callback
|
||||
** function may be used to access the properties of each matched row.
|
||||
** Invoking Api.xUserData() returns a copy of the pointer passed as
|
||||
** Invoking Api.xUserData() returns a copy of the pointer passed as
|
||||
** the third argument to pUserData.
|
||||
**
|
||||
** If the callback function returns any value other than SQLITE_OK, the
|
||||
|
@ -160,14 +160,14 @@ struct Fts5PhraseIter {
|
|||
**
|
||||
** xSetAuxdata(pFts5, pAux, xDelete)
|
||||
**
|
||||
** Save the pointer passed as the second argument as the extension function's
|
||||
** Save the pointer passed as the second argument as the extension function's
|
||||
** "auxiliary data". The pointer may then be retrieved by the current or any
|
||||
** future invocation of the same fts5 extension function made as part of
|
||||
** the same MATCH query using the xGetAuxdata() API.
|
||||
**
|
||||
** Each extension function is allocated a single auxiliary data slot for
|
||||
** each FTS query (MATCH expression). If the extension function is invoked
|
||||
** more than once for a single FTS query, then all invocations share a
|
||||
** each FTS query (MATCH expression). If the extension function is invoked
|
||||
** more than once for a single FTS query, then all invocations share a
|
||||
** single auxiliary data context.
|
||||
**
|
||||
** If there is already an auxiliary data pointer when this function is
|
||||
|
@ -186,7 +186,7 @@ struct Fts5PhraseIter {
|
|||
**
|
||||
** xGetAuxdata(pFts5, bClear)
|
||||
**
|
||||
** Returns the current auxiliary data pointer for the fts5 extension
|
||||
** Returns the current auxiliary data pointer for the fts5 extension
|
||||
** function. See the xSetAuxdata() method for details.
|
||||
**
|
||||
** If the bClear argument is non-zero, then the auxiliary data is cleared
|
||||
|
@ -206,7 +206,7 @@ struct Fts5PhraseIter {
|
|||
** method, to iterate through all instances of a single query phrase within
|
||||
** the current row. This is the same information as is accessible via the
|
||||
** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
|
||||
** to use, this API may be faster under some circumstances. To iterate
|
||||
** to use, this API may be faster under some circumstances. To iterate
|
||||
** through instances of phrase iPhrase, use the following code:
|
||||
**
|
||||
** Fts5PhraseIter iter;
|
||||
|
@ -224,8 +224,8 @@ struct Fts5PhraseIter {
|
|||
** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
|
||||
**
|
||||
** This API can be quite slow if used with an FTS5 table created with the
|
||||
** "detail=none" or "detail=column" option. If the FTS5 table is created
|
||||
** with either "detail=none" or "detail=column" and "content=" option
|
||||
** "detail=none" or "detail=column" option. If the FTS5 table is created
|
||||
** with either "detail=none" or "detail=column" and "content=" option
|
||||
** (i.e. if it is a contentless table), then this API always iterates
|
||||
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
|
||||
**
|
||||
|
@ -249,16 +249,16 @@ struct Fts5PhraseIter {
|
|||
** }
|
||||
**
|
||||
** This API can be quite slow if used with an FTS5 table created with the
|
||||
** "detail=none" option. If the FTS5 table is created with either
|
||||
** "detail=none" "content=" option (i.e. if it is a contentless table),
|
||||
** then this API always iterates through an empty set (all calls to
|
||||
** "detail=none" option. If the FTS5 table is created with either
|
||||
** "detail=none" "content=" option (i.e. if it is a contentless table),
|
||||
** then this API always iterates through an empty set (all calls to
|
||||
** xPhraseFirstColumn() set iCol to -1).
|
||||
**
|
||||
** The information accessed using this API and its companion
|
||||
** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
|
||||
** (or xInst/xInstCount). The chief advantage of this API is that it is
|
||||
** significantly more efficient than those alternatives when used with
|
||||
** "detail=column" tables.
|
||||
** "detail=column" tables.
|
||||
**
|
||||
** xPhraseNextColumn()
|
||||
** See xPhraseFirstColumn above.
|
||||
|
@ -272,7 +272,7 @@ struct Fts5ExtensionApi {
|
|||
int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
|
||||
int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);
|
||||
|
||||
int (*xTokenize)(Fts5Context*,
|
||||
int (*xTokenize)(Fts5Context*,
|
||||
const char *pText, int nText, /* Text to tokenize */
|
||||
void *pCtx, /* Context passed to xToken() */
|
||||
int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
|
||||
|
@ -301,15 +301,15 @@ struct Fts5ExtensionApi {
|
|||
void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
** CUSTOM AUXILIARY FUNCTIONS
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
** CUSTOM TOKENIZERS
|
||||
**
|
||||
** Applications may also register custom tokenizer types. A tokenizer
|
||||
** is registered by providing fts5 with a populated instance of the
|
||||
** Applications may also register custom tokenizer types. A tokenizer
|
||||
** is registered by providing fts5 with a populated instance of the
|
||||
** following structure. All structure methods must be defined, setting
|
||||
** any member of the fts5_tokenizer struct to NULL leads to undefined
|
||||
** behaviour. The structure methods are expected to function as follows:
|
||||
|
@ -320,16 +320,16 @@ struct Fts5ExtensionApi {
|
|||
**
|
||||
** The first argument passed to this function is a copy of the (void*)
|
||||
** pointer provided by the application when the fts5_tokenizer object
|
||||
** was registered with FTS5 (the third argument to xCreateTokenizer()).
|
||||
** was registered with FTS5 (the third argument to xCreateTokenizer()).
|
||||
** The second and third arguments are an array of nul-terminated strings
|
||||
** containing the tokenizer arguments, if any, specified following the
|
||||
** tokenizer name as part of the CREATE VIRTUAL TABLE statement used
|
||||
** to create the FTS5 table.
|
||||
**
|
||||
** The final argument is an output variable. If successful, (*ppOut)
|
||||
** The final argument is an output variable. If successful, (*ppOut)
|
||||
** should be set to point to the new tokenizer handle and SQLITE_OK
|
||||
** returned. If an error occurs, some value other than SQLITE_OK should
|
||||
** be returned. In this case, fts5 assumes that the final value of *ppOut
|
||||
** be returned. In this case, fts5 assumes that the final value of *ppOut
|
||||
** is undefined.
|
||||
**
|
||||
** xDelete:
|
||||
|
@ -338,7 +338,7 @@ struct Fts5ExtensionApi {
|
|||
** be invoked exactly once for each successful call to xCreate().
|
||||
**
|
||||
** xTokenize:
|
||||
** This function is expected to tokenize the nText byte string indicated
|
||||
** This function is expected to tokenize the nText byte string indicated
|
||||
** by argument pText. pText may or may not be nul-terminated. The first
|
||||
** argument passed to this function is a pointer to an Fts5Tokenizer object
|
||||
** returned by an earlier call to xCreate().
|
||||
|
@ -352,8 +352,8 @@ struct Fts5ExtensionApi {
|
|||
** determine the set of tokens to add to (or delete from) the
|
||||
** FTS index.
|
||||
**
|
||||
** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
|
||||
** against the FTS index. The tokenizer is being called to tokenize
|
||||
** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
|
||||
** against the FTS index. The tokenizer is being called to tokenize
|
||||
** a bareword or quoted string specified as part of the query.
|
||||
**
|
||||
** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
|
||||
|
@ -361,10 +361,10 @@ struct Fts5ExtensionApi {
|
|||
** followed by a "*" character, indicating that the last token
|
||||
** returned by the tokenizer will be treated as a token prefix.
|
||||
**
|
||||
** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
|
||||
** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
|
||||
** satisfy an fts5_api.xTokenize() request made by an auxiliary
|
||||
** function. Or an fts5_api.xColumnSize() request made by the same
|
||||
** on a columnsize=0 database.
|
||||
** on a columnsize=0 database.
|
||||
** </ul>
|
||||
**
|
||||
** For each token in the input string, the supplied callback xToken() must
|
||||
|
@ -376,10 +376,10 @@ struct Fts5ExtensionApi {
|
|||
** which the token is derived within the input.
|
||||
**
|
||||
** The second argument passed to the xToken() callback ("tflags") should
|
||||
** normally be set to 0. The exception is if the tokenizer supports
|
||||
** normally be set to 0. The exception is if the tokenizer supports
|
||||
** synonyms. In this case see the discussion below for details.
|
||||
**
|
||||
** FTS5 assumes the xToken() callback is invoked for each token in the
|
||||
** FTS5 assumes the xToken() callback is invoked for each token in the
|
||||
** order that they occur within the input text.
|
||||
**
|
||||
** If an xToken() callback returns any value other than SQLITE_OK, then
|
||||
|
@ -393,7 +393,7 @@ struct Fts5ExtensionApi {
|
|||
** SYNONYM SUPPORT
|
||||
**
|
||||
** Custom tokenizers may also support synonyms. Consider a case in which a
|
||||
** user wishes to query for a phrase such as "first place". Using the
|
||||
** user wishes to query for a phrase such as "first place". Using the
|
||||
** built-in tokenizers, the FTS5 query 'first + place' will match instances
|
||||
** of "first place" within the document set, but not alternative forms
|
||||
** such as "1st place". In some applications, it would be better to match
|
||||
|
@ -413,34 +413,34 @@ struct Fts5ExtensionApi {
|
|||
**
|
||||
** <li> By querying the index for all synonyms of each query term
|
||||
** separately. In this case, when tokenizing query text, the
|
||||
** tokenizer may provide multiple synonyms for a single term
|
||||
** within the document. FTS5 then queries the index for each
|
||||
** tokenizer may provide multiple synonyms for a single term
|
||||
** within the document. FTS5 then queries the index for each
|
||||
** synonym individually. For example, faced with the query:
|
||||
**
|
||||
** <codeblock>
|
||||
** ... MATCH 'first place'</codeblock>
|
||||
**
|
||||
** the tokenizer offers both "1st" and "first" as synonyms for the
|
||||
** first token in the MATCH query and FTS5 effectively runs a query
|
||||
** first token in the MATCH query and FTS5 effectively runs a query
|
||||
** similar to:
|
||||
**
|
||||
** <codeblock>
|
||||
** ... MATCH '(first OR 1st) place'</codeblock>
|
||||
**
|
||||
** except that, for the purposes of auxiliary functions, the query
|
||||
** still appears to contain just two phrases - "(first OR 1st)"
|
||||
** still appears to contain just two phrases - "(first OR 1st)"
|
||||
** being treated as a single phrase.
|
||||
**
|
||||
** <li> By adding multiple synonyms for a single term to the FTS index.
|
||||
** Using this method, when tokenizing document text, the tokenizer
|
||||
** provides multiple synonyms for each token. So that when a
|
||||
** provides multiple synonyms for each token. So that when a
|
||||
** document such as "I won first place" is tokenized, entries are
|
||||
** added to the FTS index for "i", "won", "first", "1st" and
|
||||
** "place".
|
||||
**
|
||||
** This way, even if the tokenizer does not provide synonyms
|
||||
** when tokenizing query text (it should not - to do so would be
|
||||
** inefficient), it doesn't matter if the user queries for
|
||||
** inefficient), it doesn't matter if the user queries for
|
||||
** 'first + place' or '1st + place', as there are entries in the
|
||||
** FTS index corresponding to both forms of the first token.
|
||||
** </ol>
|
||||
|
@ -461,11 +461,11 @@ struct Fts5ExtensionApi {
|
|||
**
|
||||
** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
|
||||
** xToken() is called. Multiple synonyms may be specified for a single token
|
||||
** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
|
||||
** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
|
||||
** There is no limit to the number of synonyms that may be provided for a
|
||||
** single token.
|
||||
**
|
||||
** In many cases, method (1) above is the best approach. It does not add
|
||||
** In many cases, method (1) above is the best approach. It does not add
|
||||
** extra data to the FTS index or require FTS5 to query for multiple terms,
|
||||
** so it is efficient in terms of disk space and query speed. However, it
|
||||
** does not support prefix queries very well. If, as suggested above, the
|
||||
|
@ -477,18 +477,18 @@ struct Fts5ExtensionApi {
|
|||
** will not match documents that contain the token "1st" (as the tokenizer
|
||||
** will probably not map "1s" to any prefix of "first").
|
||||
**
|
||||
** For full prefix support, method (3) may be preferred. In this case,
|
||||
** For full prefix support, method (3) may be preferred. In this case,
|
||||
** because the index contains entries for both "first" and "1st", prefix
|
||||
** queries such as 'fi*' or '1s*' will match correctly. However, because
|
||||
** extra entries are added to the FTS index, this method uses more space
|
||||
** within the database.
|
||||
**
|
||||
** Method (2) offers a midpoint between (1) and (3). Using this method,
|
||||
** a query such as '1s*' will match documents that contain the literal
|
||||
** a query such as '1s*' will match documents that contain the literal
|
||||
** token "1st", but not "first" (assuming the tokenizer is not able to
|
||||
** provide synonyms for prefixes). However, a non-prefix query like '1st'
|
||||
** will match against "1st" and "first". This method does not require
|
||||
** extra disk space, as no extra entries are added to the FTS index.
|
||||
** extra disk space, as no extra entries are added to the FTS index.
|
||||
** On the other hand, it may require more CPU cycles to run MATCH queries,
|
||||
** as separate queries of the FTS index are required for each synonym.
|
||||
**
|
||||
|
@ -502,10 +502,10 @@ typedef struct fts5_tokenizer fts5_tokenizer;
|
|||
struct fts5_tokenizer {
|
||||
int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
|
||||
void (*xDelete)(Fts5Tokenizer*);
|
||||
int (*xTokenize)(Fts5Tokenizer*,
|
||||
int (*xTokenize)(Fts5Tokenizer*,
|
||||
void *pCtx,
|
||||
int flags, /* Mask of FTS5_TOKENIZE_* flags */
|
||||
const char *pText, int nText,
|
||||
const char *pText, int nText,
|
||||
int (*xToken)(
|
||||
void *pCtx, /* Copy of 2nd argument to xTokenize() */
|
||||
int tflags, /* Mask of FTS5_TOKEN_* flags */
|
||||
|
|
72
third_party/sqlite3/func.c
vendored
72
third_party/sqlite3/func.c
vendored
|
@ -142,7 +142,7 @@ static void lengthFunc(
|
|||
** Implementation of the abs() function.
|
||||
**
|
||||
** IMP: R-23979-26855 The abs(X) function returns the absolute value of
|
||||
** the numeric argument X.
|
||||
** the numeric argument X.
|
||||
*/
|
||||
static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
assert( argc==1 );
|
||||
|
@ -159,7 +159,7 @@ static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
return;
|
||||
}
|
||||
iVal = -iVal;
|
||||
}
|
||||
}
|
||||
sqlite3_result_int64(context, iVal);
|
||||
break;
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
*/
|
||||
if( r<-4503599627370496.0 || r>+4503599627370496.0 ){
|
||||
/* The value has no fractional part so there is nothing to round */
|
||||
}else if( n==0 ){
|
||||
}else if( n==0 ){
|
||||
r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5)));
|
||||
}else{
|
||||
zBuf = sqlite3_mprintf("%.*f",n,r);
|
||||
|
@ -504,7 +504,7 @@ static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
#define noopFunc versionFunc /* Substitute function - never called */
|
||||
|
||||
/*
|
||||
** Implementation of random(). Return a random integer.
|
||||
** Implementation of random(). Return a random integer.
|
||||
*/
|
||||
static void randomFunc(
|
||||
sqlite3_context *context,
|
||||
|
@ -515,11 +515,11 @@ static void randomFunc(
|
|||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
if( r<0 ){
|
||||
/* We need to prevent a random number of 0x8000000000000000
|
||||
/* We need to prevent a random number of 0x8000000000000000
|
||||
** (or -9223372036854775808) since when you do abs() of that
|
||||
** number of you get the same value back again. To do this
|
||||
** in a way that is testable, mask the sign bit off of negative
|
||||
** values, resulting in a positive value. Then take the
|
||||
** values, resulting in a positive value. Then take the
|
||||
** 2s complement of that positive value. The end result can
|
||||
** therefore be no less than -9223372036854775807.
|
||||
*/
|
||||
|
@ -557,8 +557,8 @@ static void randomBlob(
|
|||
** value is the same as the sqlite3_last_insert_rowid() API function.
|
||||
*/
|
||||
static void last_insert_rowid(
|
||||
sqlite3_context *context,
|
||||
int NotUsed,
|
||||
sqlite3_context *context,
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
|
@ -666,7 +666,7 @@ static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
|
|||
** it the last character in the list.
|
||||
**
|
||||
** Like matching rules:
|
||||
**
|
||||
**
|
||||
** '%' Matches any sequence of zero or more characters
|
||||
**
|
||||
*** '_' Matches any one character
|
||||
|
@ -689,13 +689,13 @@ static int patternCompare(
|
|||
u32 matchAll = pInfo->matchAll; /* "*" or "%" */
|
||||
u8 noCase = pInfo->noCase; /* True if uppercase==lowercase */
|
||||
const u8 *zEscaped = 0; /* One past the last escaped input char */
|
||||
|
||||
|
||||
while( (c = Utf8Read(zPattern))!=0 ){
|
||||
if( c==matchAll ){ /* Match "*" */
|
||||
/* Skip over multiple "*" characters in the pattern. If there
|
||||
** are also "?" characters, skip those as well, but consume a
|
||||
** single character of the input string for each "?" skipped */
|
||||
while( (c=Utf8Read(zPattern)) == matchAll
|
||||
while( (c=Utf8Read(zPattern)) == matchAll
|
||||
|| (c == matchOne && matchOne!=0) ){
|
||||
if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
|
||||
return SQLITE_NOWILDCARDMATCH;
|
||||
|
@ -846,8 +846,8 @@ int sqlite3_like_count = 0;
|
|||
** the GLOB operator.
|
||||
*/
|
||||
static void likeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const unsigned char *zA, *zB;
|
||||
|
@ -886,7 +886,7 @@ static void likeFunc(
|
|||
const unsigned char *zEsc = sqlite3_value_text(argv[2]);
|
||||
if( zEsc==0 ) return;
|
||||
if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){
|
||||
sqlite3_result_error(context,
|
||||
sqlite3_result_error(context,
|
||||
"ESCAPE expression must be a single character", -1);
|
||||
return;
|
||||
}
|
||||
|
@ -999,8 +999,8 @@ static void compileoptionusedFunc(
|
|||
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite_compileoption_get() function.
|
||||
** The result is a string that identifies the compiler options
|
||||
** Implementation of the sqlite_compileoption_get() function.
|
||||
** The result is a string that identifies the compiler options
|
||||
** used to build SQLite.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
|
||||
|
@ -1024,7 +1024,7 @@ static void compileoptiongetFunc(
|
|||
** digits. */
|
||||
static const char hexdigits[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -1059,7 +1059,7 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
char const *zBlob = sqlite3_value_blob(argv[0]);
|
||||
int nBlob = sqlite3_value_bytes(argv[0]);
|
||||
assert( zBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
|
||||
zText = (char *)contextMalloc(context, (2*(i64)nBlob)+4);
|
||||
zText = (char *)contextMalloc(context, (2*(i64)nBlob)+4);
|
||||
if( zText ){
|
||||
int i;
|
||||
for(i=0; i<nBlob; i++){
|
||||
|
@ -1108,7 +1108,7 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
|
||||
/*
|
||||
** The unicode() function. Return the integer unicode code-point value
|
||||
** for the first character of the input string.
|
||||
** for the first character of the input string.
|
||||
*/
|
||||
static void unicodeFunc(
|
||||
sqlite3_context *context,
|
||||
|
@ -1264,7 +1264,7 @@ static void replaceFunc(
|
|||
if( zOut==0 ){
|
||||
return;
|
||||
}
|
||||
loopLimit = nStr - nPattern;
|
||||
loopLimit = nStr - nPattern;
|
||||
cntExpand = 0;
|
||||
for(i=j=0; i<=loopLimit; i++){
|
||||
if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){
|
||||
|
@ -1420,7 +1420,7 @@ static void unknownFunc(
|
|||
** Compute the soundex encoding of a word.
|
||||
**
|
||||
** IMP: R-59782-00072 The soundex(X) function returns a string that is the
|
||||
** soundex encoding of the string X.
|
||||
** soundex encoding of the string X.
|
||||
*/
|
||||
static void soundexFunc(
|
||||
sqlite3_context *context,
|
||||
|
@ -1509,7 +1509,7 @@ static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
typedef struct SumCtx SumCtx;
|
||||
struct SumCtx {
|
||||
double rSum; /* Floating point sum */
|
||||
i64 iSum; /* Integer sum */
|
||||
i64 iSum; /* Integer sum */
|
||||
i64 cnt; /* Number of elements summed */
|
||||
u8 overflow; /* True if integer overflow seen */
|
||||
u8 approx; /* True if non-integer value was input to the sum */
|
||||
|
@ -1623,13 +1623,13 @@ static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
/* The sqlite3_aggregate_count() function is deprecated. But just to make
|
||||
** sure it still operates correctly, verify that its count agrees with our
|
||||
** sure it still operates correctly, verify that its count agrees with our
|
||||
** internal count when using count(*) and when the total count can be
|
||||
** expressed as a 32-bit integer. */
|
||||
assert( argc==1 || p==0 || p->n>0x7fffffff || p->bInverse
|
||||
|| p->n==sqlite3_aggregate_count(context) );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
static void countFinalize(sqlite3_context *context){
|
||||
CountCtx *p;
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
|
@ -1646,7 +1646,7 @@ static void countInverse(sqlite3_context *ctx, int argc, sqlite3_value **argv){
|
|||
p->bInverse = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define countInverse 0
|
||||
#endif /* SQLITE_OMIT_WINDOWFUNC */
|
||||
|
@ -1655,8 +1655,8 @@ static void countInverse(sqlite3_context *ctx, int argc, sqlite3_value **argv){
|
|||
** Routines to implement min() and max() aggregate functions.
|
||||
*/
|
||||
static void minmaxStep(
|
||||
sqlite3_context *context,
|
||||
int NotUsed,
|
||||
sqlite3_context *context,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
Mem *pArg = (Mem *)argv[0];
|
||||
|
@ -1788,8 +1788,8 @@ static void groupConcatFinalize(sqlite3_context *context){
|
|||
sqlite3_result_error_toobig(context);
|
||||
}else if( pAccum->accError==SQLITE_NOMEM ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
}else{
|
||||
sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
|
||||
}else{
|
||||
sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
|
||||
sqlite3_free);
|
||||
}
|
||||
}
|
||||
|
@ -1803,7 +1803,7 @@ static void groupConcatValue(sqlite3_context *context){
|
|||
sqlite3_result_error_toobig(context);
|
||||
}else if( pAccum->accError==SQLITE_NOMEM ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
}else{
|
||||
}else{
|
||||
const char *zText = sqlite3_str_value(pAccum);
|
||||
sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
@ -1851,7 +1851,7 @@ void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
|
|||
** pExpr points to an expression which implements a function. If
|
||||
** it is appropriate to apply the LIKE optimization to that function
|
||||
** then set aWc[0] through aWc[2] to the wildcard characters and the
|
||||
** escape character and then return TRUE. If the function is not a
|
||||
** escape character and then return TRUE. If the function is not a
|
||||
** LIKE-style function then return FALSE.
|
||||
**
|
||||
** The expression "a LIKE b ESCAPE c" is only considered a valid LIKE
|
||||
|
@ -2201,15 +2201,15 @@ void sqlite3RegisterBuiltinFunctions(void){
|
|||
WAGGREGATE(sum, 1,0,0, sumStep, sumFinalize, sumFinalize, sumInverse, 0),
|
||||
WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
|
||||
WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
|
||||
WAGGREGATE(count, 0,0,0, countStep,
|
||||
WAGGREGATE(count, 0,0,0, countStep,
|
||||
countFinalize, countFinalize, countInverse, SQLITE_FUNC_COUNT ),
|
||||
WAGGREGATE(count, 1,0,0, countStep,
|
||||
WAGGREGATE(count, 1,0,0, countStep,
|
||||
countFinalize, countFinalize, countInverse, 0 ),
|
||||
WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
|
||||
WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
|
||||
groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
|
||||
WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep,
|
||||
WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep,
|
||||
groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
|
||||
|
||||
|
||||
LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
|
||||
#ifdef SQLITE_CASE_SENSITIVE_LIKE
|
||||
LIKEFUNC(like, 2, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
|
||||
|
|
54
third_party/sqlite3/geopoly.inc
vendored
54
third_party/sqlite3/geopoly.inc
vendored
|
@ -362,7 +362,7 @@ static void geopolyBlobFunc(
|
|||
){
|
||||
GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
|
||||
if( p ){
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
4+8*p->nVertex, SQLITE_TRANSIENT);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ static void geopolyXformFunc(
|
|||
GeoX(p,ii) = x1;
|
||||
GeoY(p,ii) = y1;
|
||||
}
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
4+8*p->nVertex, SQLITE_TRANSIENT);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
|
@ -514,7 +514,7 @@ static void geopolyAreaFunc(
|
|||
if( p ){
|
||||
sqlite3_result_double(context, geopolyArea(p));
|
||||
sqlite3_free(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -522,7 +522,7 @@ static void geopolyAreaFunc(
|
|||
**
|
||||
** If the rotation of polygon X is clockwise (incorrect) instead of
|
||||
** counter-clockwise (the correct winding order according to RFC7946)
|
||||
** then reverse the order of the vertexes in polygon X.
|
||||
** then reverse the order of the vertexes in polygon X.
|
||||
**
|
||||
** In other words, this routine returns a CCW polygon regardless of the
|
||||
** winding order of its input.
|
||||
|
@ -548,10 +548,10 @@ static void geopolyCcwFunc(
|
|||
GeoY(p,jj) = t;
|
||||
}
|
||||
}
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
4+8*p->nVertex, SQLITE_TRANSIENT);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define GEOPOLY_PI 3.1415926535897932385
|
||||
|
@ -700,7 +700,7 @@ static void geopolyBBoxFunc(
|
|||
){
|
||||
GeoPoly *p = geopolyBBox(context, argv[0], 0, 0);
|
||||
if( p ){
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
4+8*p->nVertex, SQLITE_TRANSIENT);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ static void geopolyBBoxFinal(
|
|||
if( pBBox==0 ) return;
|
||||
p = geopolyBBox(context, 0, pBBox->a, 0);
|
||||
if( p ){
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
4+8*p->nVertex, SQLITE_TRANSIENT);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
|
@ -931,7 +931,7 @@ static void geopolyAddOneSegment(
|
|||
pEvent->eType = 1;
|
||||
pEvent->pSeg = pSeg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -971,7 +971,7 @@ static GeoEvent *geopolyEventMerge(GeoEvent *pLeft, GeoEvent *pRight){
|
|||
}
|
||||
}
|
||||
pLast->pNext = pRight ? pRight : pLeft;
|
||||
return head.pNext;
|
||||
return head.pNext;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1020,7 +1020,7 @@ static GeoSegment *geopolySegmentMerge(GeoSegment *pLeft, GeoSegment *pRight){
|
|||
}
|
||||
}
|
||||
pLast->pNext = pRight ? pRight : pLeft;
|
||||
return head.pNext;
|
||||
return head.pNext;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1065,8 +1065,8 @@ static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
|
|||
GeoSegment *pSeg;
|
||||
unsigned char aOverlap[4];
|
||||
|
||||
nByte = sizeof(GeoEvent)*nVertex*2
|
||||
+ sizeof(GeoSegment)*nVertex
|
||||
nByte = sizeof(GeoEvent)*nVertex*2
|
||||
+ sizeof(GeoSegment)*nVertex
|
||||
+ sizeof(GeoOverlap);
|
||||
p = sqlite3_malloc64( nByte );
|
||||
if( p==0 ) return -1;
|
||||
|
@ -1208,7 +1208,7 @@ static void geopolyDebugFunc(
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** This function is the implementation of both the xConnect and xCreate
|
||||
** methods of the geopoly virtual table.
|
||||
**
|
||||
|
@ -1298,7 +1298,7 @@ geopolyInit_fail:
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
** GEOPOLY virtual table module xCreate method.
|
||||
*/
|
||||
static int geopolyCreate(
|
||||
|
@ -1311,7 +1311,7 @@ static int geopolyCreate(
|
|||
return geopolyInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** GEOPOLY virtual table module xConnect method.
|
||||
*/
|
||||
static int geopolyConnect(
|
||||
|
@ -1325,7 +1325,7 @@ static int geopolyConnect(
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
** GEOPOLY virtual table module xFilter method.
|
||||
**
|
||||
** Query plans:
|
||||
|
@ -1375,8 +1375,8 @@ static int geopolyFilter(
|
|||
pCsr->atEOF = 1;
|
||||
}
|
||||
}else{
|
||||
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
|
||||
** with the configured constraints.
|
||||
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
|
||||
** with the configured constraints.
|
||||
*/
|
||||
rc = nodeAcquire(pRtree, 1, 0, &pRoot);
|
||||
if( rc==SQLITE_OK && idxNum<=3 ){
|
||||
|
@ -1457,7 +1457,7 @@ geopoly_filter_end:
|
|||
|
||||
/*
|
||||
** Rtree virtual table module xBestIndex method. There are three
|
||||
** table scan strategies to choose from (in order from most to
|
||||
** table scan strategies to choose from (in order from most to
|
||||
** least desirable):
|
||||
**
|
||||
** idxNum idxStr Strategy
|
||||
|
@ -1517,7 +1517,7 @@ static int geopolyBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
** GEOPOLY virtual table module xColumn method.
|
||||
*/
|
||||
static int geopolyColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
||||
|
@ -1537,7 +1537,7 @@ static int geopolyColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
|||
&pCsr->pReadAux, 0);
|
||||
if( rc ) return rc;
|
||||
}
|
||||
sqlite3_bind_int64(pCsr->pReadAux, 1,
|
||||
sqlite3_bind_int64(pCsr->pReadAux, 1,
|
||||
nodeGetRowid(pRtree, pNode, p->iCell));
|
||||
rc = sqlite3_step(pCsr->pReadAux);
|
||||
if( rc==SQLITE_ROW ){
|
||||
|
@ -1576,9 +1576,9 @@ static int geopolyColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
|||
** argv[3] = new value for first application-defined column....
|
||||
*/
|
||||
static int geopolyUpdate(
|
||||
sqlite3_vtab *pVtab,
|
||||
int nData,
|
||||
sqlite3_value **aData,
|
||||
sqlite3_vtab *pVtab,
|
||||
int nData,
|
||||
sqlite3_value **aData,
|
||||
sqlite_int64 *pRowid
|
||||
){
|
||||
Rtree *pRtree = (Rtree *)pVtab;
|
||||
|
@ -1620,7 +1620,7 @@ static int geopolyUpdate(
|
|||
}
|
||||
coordChange = 1;
|
||||
|
||||
/* If a rowid value was supplied, check if it is already present in
|
||||
/* If a rowid value was supplied, check if it is already present in
|
||||
** the table. If so, the constraint has failed. */
|
||||
if( newRowidValid && (!oldRowidValid || oldRowid!=newRowid) ){
|
||||
int steprc;
|
||||
|
@ -1800,7 +1800,7 @@ static int sqlite3_geopoly_init(sqlite3 *db){
|
|||
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, 1,
|
||||
rc = sqlite3_create_function(db, aAgg[i].zName, 1,
|
||||
SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, 0,
|
||||
0, aAgg[i].xStep, aAgg[i].xFinal);
|
||||
}
|
||||
|
|
10
third_party/sqlite3/global.c
vendored
10
third_party/sqlite3/global.c
vendored
|
@ -16,7 +16,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
/* An array to map all upper-case characters into their corresponding
|
||||
** lower-case character.
|
||||
** lower-case character.
|
||||
**
|
||||
** SQLite only considers US-ASCII (or EBCDIC) characters. We do not
|
||||
** handle case conversions for the UTF character set since the tables
|
||||
|
@ -83,7 +83,7 @@ const unsigned char sqlite3UpperToLower[] = {
|
|||
** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
|
||||
** array. tolower() is used more often than toupper() by SQLite.
|
||||
**
|
||||
** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
|
||||
** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
|
||||
** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any
|
||||
** non-ASCII UTF character. Hence the test for whether or not a character is
|
||||
** part of an identifier is 0x46.
|
||||
|
@ -148,7 +148,7 @@ const unsigned char sqlite3CtypeMap[256] = {
|
|||
#if !defined(SQLITE_ALLOW_COVERING_INDEX_SCAN)
|
||||
# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
|
||||
#else
|
||||
# if !SQLITE_ALLOW_COVERING_INDEX_SCAN
|
||||
# if !SQLITE_ALLOW_COVERING_INDEX_SCAN
|
||||
# error "Compile-time disabling of covering index scan using the\
|
||||
-DSQLITE_ALLOW_COVERING_INDEX_SCAN=0 option is deprecated.\
|
||||
Contact SQLite developers if this is a problem for you, and\
|
||||
|
@ -171,7 +171,7 @@ const unsigned char sqlite3CtypeMap[256] = {
|
|||
** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this
|
||||
** setting.)
|
||||
*/
|
||||
#ifndef SQLITE_STMTJRNL_SPILL
|
||||
#ifndef SQLITE_STMTJRNL_SPILL
|
||||
# define SQLITE_STMTJRNL_SPILL (64*1024)
|
||||
#endif
|
||||
|
||||
|
@ -312,7 +312,7 @@ u32 sqlite3WhereTrace = 0;
|
|||
** Properties of opcodes. The OPFLG_INITIALIZER macro is
|
||||
** created by mkopcodeh.awk during compilation. Data is obtained
|
||||
** from the comments following the "case OP_xxxx:" statements in
|
||||
** the vdbe.c file.
|
||||
** the vdbe.c file.
|
||||
*/
|
||||
const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER;
|
||||
|
||||
|
|
6
third_party/sqlite3/hash.c
vendored
6
third_party/sqlite3/hash.c
vendored
|
@ -117,7 +117,7 @@ static int rehash(Hash *pH, unsigned int new_size){
|
|||
|
||||
/* The inability to allocates space for a larger hash table is
|
||||
** a performance hit but it is not a fatal error. So mark the
|
||||
** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of
|
||||
** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of
|
||||
** sqlite3MallocZero() to make the allocation, as sqlite3MallocZero()
|
||||
** only zeroes the requested number of bytes whereas this module will
|
||||
** use the actual amount of space allocated for the hash table (which
|
||||
|
@ -169,7 +169,7 @@ static HashElem *findElementWithHash(
|
|||
if( pHash ) *pHash = h;
|
||||
while( count-- ){
|
||||
assert( elem!=0 );
|
||||
if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
|
||||
if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
|
||||
return elem;
|
||||
}
|
||||
elem = elem->next;
|
||||
|
@ -187,7 +187,7 @@ static void removeElementGivenHash(
|
|||
){
|
||||
struct _ht *pEntry;
|
||||
if( elem->prev ){
|
||||
elem->prev->next = elem->next;
|
||||
elem->prev->next = elem->next;
|
||||
}else{
|
||||
pH->first = elem->next;
|
||||
}
|
||||
|
|
4
third_party/sqlite3/hash.inc
vendored
4
third_party/sqlite3/hash.inc
vendored
|
@ -36,7 +36,7 @@ typedef struct HashElem HashElem;
|
|||
** element pointed to plus the next _ht.count-1 elements in the list.
|
||||
**
|
||||
** Hash.htsize and Hash.ht may be zero. In that case lookup is done
|
||||
** by a linear search of the global list. For small tables, the
|
||||
** by a linear search of the global list. For small tables, the
|
||||
** Hash.ht table is never allocated because if there are few elements
|
||||
** in the table, it is faster to do a linear search than to manage
|
||||
** the hash table.
|
||||
|
@ -51,7 +51,7 @@ struct Hash {
|
|||
} *ht;
|
||||
};
|
||||
|
||||
/* Each element in the hash table is an instance of the following
|
||||
/* Each element in the hash table is an instance of the following
|
||||
** structure. All elements are stored on a single doubly-linked list.
|
||||
**
|
||||
** Again, this structure is intended to be opaque, but it can't really
|
||||
|
|
2
third_party/sqlite3/hwtime.inc
vendored
2
third_party/sqlite3/hwtime.inc
vendored
|
@ -53,7 +53,7 @@
|
|||
__asm__ __volatile__ ("rdtsc" : "=A" (val));
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
|
||||
|
||||
__inline__ sqlite_uint64 sqlite3Hwtime(void){
|
||||
|
|
40
third_party/sqlite3/icu.c
vendored
40
third_party/sqlite3/icu.c
vendored
|
@ -47,7 +47,7 @@ SQLITE_EXTENSION_INIT1
|
|||
** This function is called when an ICU function called from within
|
||||
** the implementation of an SQL scalar function returns an error.
|
||||
**
|
||||
** The scalar function context passed as the first argument is
|
||||
** The scalar function context passed as the first argument is
|
||||
** loaded with an error message based on the following two args.
|
||||
*/
|
||||
static void icuFunctionError(
|
||||
|
@ -112,7 +112,7 @@ static const unsigned char icuUtf8Trans1[] = {
|
|||
|
||||
/*
|
||||
** Compare two UTF-8 strings for equality where the first string is
|
||||
** a "LIKE" expression. Return true (1) if they are the same and
|
||||
** a "LIKE" expression. Return true (1) if they are the same and
|
||||
** false (0) if they are different.
|
||||
*/
|
||||
static int icuLikeCompare(
|
||||
|
@ -144,7 +144,7 @@ static int icuLikeCompare(
|
|||
uint8_t c;
|
||||
|
||||
/* Skip any MATCH_ALL or MATCH_ONE characters that follow a
|
||||
** MATCH_ALL. For each MATCH_ONE, skip one character in the
|
||||
** MATCH_ALL. For each MATCH_ONE, skip one character in the
|
||||
** test string.
|
||||
*/
|
||||
while( (c=*zPattern) == MATCH_ALL || c == MATCH_ONE ){
|
||||
|
@ -197,15 +197,15 @@ static int icuLikeCompare(
|
|||
**
|
||||
** A LIKE B
|
||||
**
|
||||
** is implemented as like(B, A). If there is an escape character E,
|
||||
** is implemented as like(B, A). If there is an escape character E,
|
||||
**
|
||||
** A LIKE B ESCAPE E
|
||||
**
|
||||
** is mapped to like(B, A, E).
|
||||
*/
|
||||
static void icuLikeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const unsigned char *zA = sqlite3_value_text(argv[0]);
|
||||
|
@ -231,7 +231,7 @@ static void icuLikeFunc(
|
|||
if( zE==0 ) return;
|
||||
U8_NEXT(zE, i, nE, uEsc);
|
||||
if( i!=nE){
|
||||
sqlite3_result_error(context,
|
||||
sqlite3_result_error(context,
|
||||
"ESCAPE expression must be a single character", -1);
|
||||
return;
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ static void icuRegexpDelete(void *p){
|
|||
/*
|
||||
** Implementation of SQLite REGEXP operator. This scalar function takes
|
||||
** two arguments. The first is a regular expression pattern to compile
|
||||
** the second is a string to match against that pattern. If either
|
||||
** the second is a string to match against that pattern. If either
|
||||
** argument is an SQL NULL, then NULL Is returned. Otherwise, the result
|
||||
** is 1 if the string matches the pattern, or 0 otherwise.
|
||||
**
|
||||
|
@ -278,8 +278,8 @@ static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
|
|||
|
||||
(void)nArg; /* Unused parameter */
|
||||
|
||||
/* If the left hand side of the regexp operator is NULL,
|
||||
** then the result is also NULL.
|
||||
/* If the left hand side of the regexp operator is NULL,
|
||||
** then the result is also NULL.
|
||||
*/
|
||||
if( !zString ){
|
||||
return;
|
||||
|
@ -317,7 +317,7 @@ static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
|
|||
}
|
||||
|
||||
/* Set the text that the regular expression operates on to a NULL
|
||||
** pointer. This is not really necessary, but it is tidier than
|
||||
** pointer. This is not really necessary, but it is tidier than
|
||||
** leaving the regular expression object configured with an invalid
|
||||
** pointer after this function returns.
|
||||
*/
|
||||
|
@ -328,7 +328,7 @@ static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementations of scalar functions for case mapping - upper() and
|
||||
** Implementations of scalar functions for case mapping - upper() and
|
||||
** lower(). Function upper() converts its input to upper-case (ABC).
|
||||
** Function lower() converts to lower-case (abc).
|
||||
**
|
||||
|
@ -336,7 +336,7 @@ static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
|
|||
** "language specific". Refer to ICU documentation for the differences
|
||||
** between the two.
|
||||
**
|
||||
** To utilise "general" case mapping, the upper() or lower() scalar
|
||||
** To utilise "general" case mapping, the upper() or lower() scalar
|
||||
** functions are invoked with one argument:
|
||||
**
|
||||
** upper('ABC') -> 'abc'
|
||||
|
@ -444,7 +444,7 @@ static int icuCollationColl(
|
|||
/*
|
||||
** Implementation of the scalar function icu_load_collation().
|
||||
**
|
||||
** This scalar function is used to add ICU collation based collation
|
||||
** This scalar function is used to add ICU collation based collation
|
||||
** types to an SQLite database connection. It is intended to be called
|
||||
** as follows:
|
||||
**
|
||||
|
@ -455,8 +455,8 @@ static int icuCollationColl(
|
|||
** collation sequence to create.
|
||||
*/
|
||||
static void icuLoadCollation(
|
||||
sqlite3_context *p,
|
||||
int nArg,
|
||||
sqlite3_context *p,
|
||||
int nArg,
|
||||
sqlite3_value **apArg
|
||||
){
|
||||
sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
|
||||
|
@ -482,7 +482,7 @@ static void icuLoadCollation(
|
|||
}
|
||||
assert(p);
|
||||
|
||||
rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
|
||||
rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
|
||||
icuCollationColl, icuCollationDel
|
||||
);
|
||||
if( rc!=SQLITE_OK ){
|
||||
|
@ -520,11 +520,11 @@ int sqlite3IcuInit(sqlite3 *db){
|
|||
};
|
||||
int rc = SQLITE_OK;
|
||||
int i;
|
||||
|
||||
|
||||
for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
|
||||
const struct IcuScalar *p = &scalars[i];
|
||||
rc = sqlite3_create_function(
|
||||
db, p->zName, p->nArg, p->enc,
|
||||
db, p->zName, p->nArg, p->enc,
|
||||
p->iContext ? (void*)db : (void*)0,
|
||||
p->xFunc, 0, 0
|
||||
);
|
||||
|
@ -538,7 +538,7 @@ int sqlite3IcuInit(sqlite3 *db){
|
|||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_icu_init(
|
||||
sqlite3 *db,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
|
|
4
third_party/sqlite3/ieee754.c
vendored
4
third_party/sqlite3/ieee754.c
vendored
|
@ -248,8 +248,8 @@ static void ieee754func_to_blob(
|
|||
}
|
||||
|
||||
int sqlite3_ieee_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
static const struct {
|
||||
|
|
102
third_party/sqlite3/insert.c
vendored
102
third_party/sqlite3/insert.c
vendored
|
@ -16,7 +16,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
/*
|
||||
** Generate code that will
|
||||
** Generate code that will
|
||||
**
|
||||
** (1) acquire a lock for table pTab then
|
||||
** (2) open pTab as cursor iCur.
|
||||
|
@ -36,7 +36,7 @@ void sqlite3OpenTable(
|
|||
assert( pParse->pVdbe!=0 );
|
||||
v = pParse->pVdbe;
|
||||
assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum,
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum,
|
||||
(opcode==OP_OpenWrite)?1:0, pTab->zName);
|
||||
if( HasRowid(pTab) ){
|
||||
sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
|
||||
|
@ -53,7 +53,7 @@ void sqlite3OpenTable(
|
|||
|
||||
/*
|
||||
** Return a pointer to the column affinity string associated with index
|
||||
** pIdx. A column affinity string has one character for each column in
|
||||
** pIdx. A column affinity string has one character for each column in
|
||||
** the table, according to the affinity of the column:
|
||||
**
|
||||
** Character Column affinity
|
||||
|
@ -106,7 +106,7 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
|
|||
}
|
||||
pIdx->zColAff[n] = 0;
|
||||
}
|
||||
|
||||
|
||||
return pIdx->zColAff;
|
||||
}
|
||||
|
||||
|
@ -165,9 +165,9 @@ void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
|
|||
|
||||
/*
|
||||
** Return non-zero if the table pTab in database iDb or any of its indices
|
||||
** have been opened at any point in the VDBE program. This is used to see if
|
||||
** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
|
||||
** run without using a temporary table for the results of the SELECT.
|
||||
** have been opened at any point in the VDBE program. This is used to see if
|
||||
** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
|
||||
** run without using a temporary table for the results of the SELECT.
|
||||
*/
|
||||
static int readsTable(Parse *p, int iDb, Table *pTab){
|
||||
Vdbe *v = sqlite3GetVdbe(p);
|
||||
|
@ -389,7 +389,7 @@ static int autoIncBegin(
|
|||
|
||||
/*
|
||||
** This routine generates code that will initialize all of the
|
||||
** register used by the autoincrement tracker.
|
||||
** register used by the autoincrement tracker.
|
||||
*/
|
||||
void sqlite3AutoincrementBegin(Parse *pParse){
|
||||
AutoincInfo *p; /* Information about an AUTOINCREMENT */
|
||||
|
@ -418,7 +418,7 @@ void sqlite3AutoincrementBegin(Parse *pParse){
|
|||
/* 8 */ {OP_Goto, 0, 11, 0},
|
||||
/* 9 */ {OP_Next, 0, 2, 0},
|
||||
/* 10 */ {OP_Integer, 0, 0, 0},
|
||||
/* 11 */ {OP_Close, 0, 0, 0}
|
||||
/* 11 */ {OP_Close, 0, 0, 0}
|
||||
};
|
||||
VdbeOp *aOp;
|
||||
pDb = &db->aDb[p->iDb];
|
||||
|
@ -770,7 +770,7 @@ void sqlite3Insert(
|
|||
regData = regRowid+1;
|
||||
|
||||
/* If the INSERT statement included an IDLIST term, then make sure
|
||||
** all elements of the IDLIST really are columns of the table and
|
||||
** all elements of the IDLIST really are columns of the table and
|
||||
** remember the column indices.
|
||||
**
|
||||
** If the table has an INTEGER PRIMARY KEY column and that column
|
||||
|
@ -803,7 +803,7 @@ void sqlite3Insert(
|
|||
}
|
||||
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"cannot INSERT into generated column \"%s\"",
|
||||
pTab->aCol[j].zName);
|
||||
goto insert_cleanup;
|
||||
|
@ -858,7 +858,7 @@ void sqlite3Insert(
|
|||
** the destination table (template 3).
|
||||
**
|
||||
** A temp table must be used if the table being updated is also one
|
||||
** of the tables being read by the SELECT statement. Also use a
|
||||
** of the tables being read by the SELECT statement. Also use a
|
||||
** temp table in the case of row triggers.
|
||||
*/
|
||||
if( pTrigger || readsTable(pParse, iDb, pTab) ){
|
||||
|
@ -894,7 +894,7 @@ void sqlite3Insert(
|
|||
sqlite3ReleaseTempReg(pParse, regTempRowid);
|
||||
}
|
||||
}else{
|
||||
/* This is the case if the data for the INSERT is coming from a
|
||||
/* This is the case if the data for the INSERT is coming from a
|
||||
** single-row VALUES clause
|
||||
*/
|
||||
NameContext sNC;
|
||||
|
@ -913,7 +913,7 @@ void sqlite3Insert(
|
|||
}
|
||||
|
||||
/* If there is no IDLIST term but the table has an integer primary
|
||||
** key, the set the ipkColumn variable to the integer primary key
|
||||
** key, the set the ipkColumn variable to the integer primary key
|
||||
** column index in the original table definition.
|
||||
*/
|
||||
if( pColumn==0 && nColumn>0 ){
|
||||
|
@ -944,7 +944,7 @@ void sqlite3Insert(
|
|||
}
|
||||
}
|
||||
if( nColumn!=(pTab->nCol-nHidden) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"table %S has %d columns but %d values were supplied",
|
||||
pTabList, 0, pTab->nCol-nHidden, nColumn);
|
||||
goto insert_cleanup;
|
||||
|
@ -954,7 +954,7 @@ void sqlite3Insert(
|
|||
sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
|
||||
/* Initialize the count of rows to be inserted
|
||||
*/
|
||||
if( (db->flags & SQLITE_CountRows)!=0
|
||||
|
@ -1111,7 +1111,7 @@ void sqlite3Insert(
|
|||
}
|
||||
|
||||
if( useTempTable ){
|
||||
sqlite3VdbeAddOp3(v, OP_Column, srcTab, k, iRegStore);
|
||||
sqlite3VdbeAddOp3(v, OP_Column, srcTab, k, iRegStore);
|
||||
}else if( pSelect ){
|
||||
if( regFromSelect!=regData ){
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
|
||||
|
@ -1177,7 +1177,7 @@ void sqlite3Insert(
|
|||
}
|
||||
|
||||
/* Fire BEFORE or INSTEAD OF triggers */
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
|
||||
pTab, regCols-pTab->nCol-1, onError, endOfLoop);
|
||||
|
||||
sqlite3ReleaseTempRange(pParse, regCols, pTab->nCol+1);
|
||||
|
@ -1260,7 +1260,7 @@ void sqlite3Insert(
|
|||
** constraints or (b) there are no triggers and this table is not a
|
||||
** parent table in a foreign key constraint. It is safe to set the
|
||||
** flag in the second case as if any REPLACE constraint is hit, an
|
||||
** OP_Delete or OP_IdxDelete instruction will be executed on each
|
||||
** OP_Delete or OP_IdxDelete instruction will be executed on each
|
||||
** cursor that is disturbed. And these instructions both clear the
|
||||
** VdbeCursor.seekResult variable, disabling the OPFLAG_USESEEKRESULT
|
||||
** functionality. */
|
||||
|
@ -1279,7 +1279,7 @@ void sqlite3Insert(
|
|||
|
||||
if( pTrigger ){
|
||||
/* Code AFTER triggers */
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_AFTER,
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_AFTER,
|
||||
pTab, regData-2-pTab->nCol, onError, endOfLoop);
|
||||
}
|
||||
|
||||
|
@ -1317,7 +1317,7 @@ insert_end:
|
|||
}
|
||||
|
||||
/*
|
||||
** Return the number of rows inserted. If this routine is
|
||||
** Return the number of rows inserted. If this routine is
|
||||
** generating code because of a call to sqlite3NestedParse(), do not
|
||||
** invoke the callback function.
|
||||
*/
|
||||
|
@ -1350,7 +1350,7 @@ insert_cleanup:
|
|||
#endif
|
||||
|
||||
/*
|
||||
** Meanings of bits in of pWalker->eCode for
|
||||
** Meanings of bits in of pWalker->eCode for
|
||||
** sqlite3ExprReferencesUpdatedColumn()
|
||||
*/
|
||||
#define CKCNSTRNT_COLUMN 0x01 /* CHECK constraint uses a changing column */
|
||||
|
@ -1431,7 +1431,7 @@ struct IndexIterator {
|
|||
union {
|
||||
struct { /* Use this object for eType==0: A Index.pNext list */
|
||||
Index *pIdx; /* The current Index */
|
||||
} lx;
|
||||
} lx;
|
||||
struct { /* Use this object for eType==1; Array of IndexListTerm */
|
||||
int nIdx; /* Size of the array */
|
||||
IndexListTerm *aIdx; /* Array of IndexListTerms */
|
||||
|
@ -1475,7 +1475,7 @@ static Index *indexIteratorNext(IndexIterator *pIter, int *pIx){
|
|||
return pIter->u.lx.pIdx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Generate code to do constraint checks prior to an INSERT or an UPDATE
|
||||
** on table pTab.
|
||||
|
@ -1614,9 +1614,9 @@ void sqlite3GenerateConstraintChecks(
|
|||
assert( v!=0 );
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
nCol = pTab->nCol;
|
||||
|
||||
|
||||
/* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
|
||||
** normal rowid tables. nPkField is the number of key fields in the
|
||||
** normal rowid tables. nPkField is the number of key fields in the
|
||||
** pPk index or 1 for a rowid table. In other words, nPkField is the
|
||||
** number of fields in the true primary key of the table. */
|
||||
if( HasRowid(pTab) ){
|
||||
|
@ -1990,10 +1990,10 @@ void sqlite3GenerateConstraintChecks(
|
|||
** the triggers and remove both the table and index b-tree entries.
|
||||
**
|
||||
** Otherwise, if there are no triggers or the recursive-triggers
|
||||
** flag is not set, but the table has one or more indexes, call
|
||||
** GenerateRowIndexDelete(). This removes the index b-tree entries
|
||||
** only. The table b-tree entry will be replaced by the new entry
|
||||
** when it is inserted.
|
||||
** flag is not set, but the table has one or more indexes, call
|
||||
** GenerateRowIndexDelete(). This removes the index b-tree entries
|
||||
** only. The table b-tree entry will be replaced by the new entry
|
||||
** when it is inserted.
|
||||
**
|
||||
** If either GenerateRowDelete() or GenerateRowIndexDelete() is called,
|
||||
** also invoke MultiWrite() to indicate that this VDBE may require
|
||||
|
@ -2125,7 +2125,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
#endif
|
||||
sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0);
|
||||
|
||||
/* In an UPDATE operation, if this index is the PRIMARY KEY index
|
||||
/* In an UPDATE operation, if this index is the PRIMARY KEY index
|
||||
** of a WITHOUT ROWID table and there has been no change the
|
||||
** primary key, then no collision is possible. The collision detection
|
||||
** logic below can all be skipped. */
|
||||
|
@ -2136,7 +2136,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
|
||||
/* Find out what action to take in case there is a uniqueness conflict */
|
||||
onError = pIdx->onError;
|
||||
if( onError==OE_None ){
|
||||
if( onError==OE_None ){
|
||||
sqlite3VdbeResolveLabel(v, addrUniqueOk);
|
||||
continue; /* pIdx is not a UNIQUE index */
|
||||
}
|
||||
|
@ -2164,7 +2164,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
**
|
||||
** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
|
||||
** must be explicitly deleted in order to ensure any pre-update hook
|
||||
** is invoked. */
|
||||
** is invoked. */
|
||||
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
|
||||
&& pPk==pIdx /* Condition 2 */
|
||||
|
@ -2181,7 +2181,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
|
||||
/* Check to see if the new index entry will be unique */
|
||||
sqlite3VdbeVerifyAbortable(v, onError);
|
||||
addrConflictCk =
|
||||
addrConflictCk =
|
||||
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
|
||||
regIdx, pIdx->nKeyCol); VdbeCoverage(v);
|
||||
|
||||
|
@ -2211,7 +2211,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
}
|
||||
}
|
||||
if( isUpdate ){
|
||||
/* If currently processing the PRIMARY KEY of a WITHOUT ROWID
|
||||
/* If currently processing the PRIMARY KEY of a WITHOUT ROWID
|
||||
** table, only conflict if the new PRIMARY KEY values are actually
|
||||
** different from the old.
|
||||
**
|
||||
|
@ -2221,7 +2221,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
|
||||
int op = OP_Ne;
|
||||
int regCmp = (IsPrimaryKeyIndex(pIdx) ? regIdx : regR);
|
||||
|
||||
|
||||
for(i=0; i<pPk->nKeyCol; i++){
|
||||
char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
|
||||
x = pPk->aiColumn[i];
|
||||
|
@ -2231,7 +2231,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
op = OP_Eq;
|
||||
}
|
||||
x = sqlite3TableColumnToStorage(pTab, x);
|
||||
sqlite3VdbeAddOp4(v, op,
|
||||
sqlite3VdbeAddOp4(v, op,
|
||||
regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
|
||||
);
|
||||
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
|
||||
|
@ -2340,7 +2340,7 @@ void sqlite3GenerateConstraintChecks(
|
|||
}
|
||||
sqlite3VdbeResolveLabel(v, addrUniqueOk);
|
||||
if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
|
||||
if( pUpsertClause
|
||||
if( pUpsertClause
|
||||
&& upsertIpkReturn
|
||||
&& sqlite3UpsertNextIsIPK(pUpsertClause)
|
||||
){
|
||||
|
@ -2656,7 +2656,7 @@ static int xferCompatibleIndex(Index *pDest, Index *pSrc){
|
|||
**
|
||||
** INSERT INTO tab1 SELECT * FROM tab2;
|
||||
**
|
||||
** The xfer optimization transfers raw records from tab2 over to tab1.
|
||||
** The xfer optimization transfers raw records from tab2 over to tab1.
|
||||
** Columns are not decoded and reassembled, which greatly improves
|
||||
** performance. Raw index records are transferred in the same way.
|
||||
**
|
||||
|
@ -2791,8 +2791,8 @@ static int xferOptimization(
|
|||
Column *pDestCol = &pDest->aCol[i];
|
||||
Column *pSrcCol = &pSrc->aCol[i];
|
||||
#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
|
||||
if( (db->mDbFlags & DBFLAG_Vacuum)==0
|
||||
&& (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN
|
||||
if( (db->mDbFlags & DBFLAG_Vacuum)==0
|
||||
&& (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN
|
||||
){
|
||||
return 0; /* Neither table may have __hidden__ columns */
|
||||
}
|
||||
|
@ -2809,7 +2809,7 @@ static int xferOptimization(
|
|||
**
|
||||
** Nevertheless, this is a useful notational shorthand to tell SQLite
|
||||
** to do a bulk transfer all of the content from t1 over to t2.
|
||||
**
|
||||
**
|
||||
** We could, in theory, disable this (except for internal use by the
|
||||
** VACUUM command where it is actually needed). But why do that? It
|
||||
** seems harmless enough, and provides a useful service.
|
||||
|
@ -2843,7 +2843,7 @@ static int xferOptimization(
|
|||
if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
|
||||
assert( pDestCol->pDflt==0 || pDestCol->pDflt->op==TK_SPAN );
|
||||
assert( pSrcCol->pDflt==0 || pSrcCol->pDflt->op==TK_SPAN );
|
||||
if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0)
|
||||
if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0)
|
||||
|| (pDestCol->pDflt && strcmp(pDestCol->pDflt->u.zToken,
|
||||
pSrcCol->pDflt->u.zToken)!=0)
|
||||
){
|
||||
|
@ -2877,7 +2877,7 @@ static int xferOptimization(
|
|||
#ifndef SQLITE_OMIT_FOREIGN_KEY
|
||||
/* Disallow the transfer optimization if the destination table constains
|
||||
** any foreign key constraints. This is more restrictive than necessary.
|
||||
** But the main beneficiary of the transfer optimization is the VACUUM
|
||||
** But the main beneficiary of the transfer optimization is the VACUUM
|
||||
** command, and the VACUUM command disables foreign key constraints. So
|
||||
** the extra complication to make this rule less restrictive is probably
|
||||
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
|
||||
|
@ -2925,7 +2925,7 @@ static int xferOptimization(
|
|||
** (If the destination is not initially empty, the rowid fields
|
||||
** of index entries might need to change.)
|
||||
**
|
||||
** (2) The destination has a unique index. (The xfer optimization
|
||||
** (2) The destination has a unique index. (The xfer optimization
|
||||
** is unable to test uniqueness.)
|
||||
**
|
||||
** (3) onError is something other than OE_Abort and OE_Rollback.
|
||||
|
@ -3001,14 +3001,14 @@ static int xferOptimization(
|
|||
/* This INSERT command is part of a VACUUM operation, which guarantees
|
||||
** that the destination table is empty. If all indexed columns use
|
||||
** collation sequence BINARY, then it can also be assumed that the
|
||||
** index will be populated by inserting keys in strictly sorted
|
||||
** index will be populated by inserting keys in strictly sorted
|
||||
** order. In this case, instead of seeking within the b-tree as part
|
||||
** of every OP_IdxInsert opcode, an OP_SeekEnd is added before the
|
||||
** OP_IdxInsert to seek to the point within the b-tree where each key
|
||||
** OP_IdxInsert to seek to the point within the b-tree where each key
|
||||
** should be inserted. This is faster.
|
||||
**
|
||||
** If any of the indexed columns use a collation sequence other than
|
||||
** BINARY, this optimization is disabled. This is because the user
|
||||
** BINARY, this optimization is disabled. This is because the user
|
||||
** might change the definition of a collation sequence and then run
|
||||
** a VACUUM command. In that case keys may not be written in strictly
|
||||
** sorted order. */
|
||||
|
@ -3026,9 +3026,9 @@ static int xferOptimization(
|
|||
}
|
||||
if( idxInsFlags!=(OPFLAG_USESEEKRESULT|OPFLAG_PREFORMAT) ){
|
||||
sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
|
||||
if( (db->mDbFlags & DBFLAG_Vacuum)==0
|
||||
&& !HasRowid(pDest)
|
||||
&& IsPrimaryKeyIndex(pDestIdx)
|
||||
if( (db->mDbFlags & DBFLAG_Vacuum)==0
|
||||
&& !HasRowid(pDest)
|
||||
&& IsPrimaryKeyIndex(pDestIdx)
|
||||
){
|
||||
codeWithoutRowidPreupdate(pParse, pDest, iDest, regData);
|
||||
}
|
||||
|
|
26
third_party/sqlite3/json1.c
vendored
26
third_party/sqlite3/json1.c
vendored
|
@ -220,7 +220,7 @@ static void jsonReset(JsonString *p){
|
|||
}
|
||||
|
||||
|
||||
/* Report an out-of-memory (OOM) condition
|
||||
/* Report an out-of-memory (OOM) condition
|
||||
*/
|
||||
static void jsonOom(JsonString *p){
|
||||
p->bErr = 1;
|
||||
|
@ -338,7 +338,7 @@ static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
|
|||
}
|
||||
|
||||
/*
|
||||
** Append a function parameter value to the JSON string under
|
||||
** Append a function parameter value to the JSON string under
|
||||
** construction.
|
||||
*/
|
||||
static void jsonAppendValue(
|
||||
|
@ -383,7 +383,7 @@ static void jsonAppendValue(
|
|||
*/
|
||||
static void jsonResult(JsonString *p){
|
||||
if( p->bErr==0 ){
|
||||
sqlite3_result_text64(p->pCtx, p->zBuf, p->nUsed,
|
||||
sqlite3_result_text64(p->pCtx, p->zBuf, p->nUsed,
|
||||
p->bStatic ? SQLITE_TRANSIENT : sqlite3_free,
|
||||
SQLITE_UTF8);
|
||||
jsonZero(p);
|
||||
|
@ -626,7 +626,7 @@ static void jsonReturn(
|
|||
if( pNode->jnFlags & JNODE_RAW ){
|
||||
sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
|
||||
SQLITE_TRANSIENT);
|
||||
}else
|
||||
}else
|
||||
#endif
|
||||
assert( (pNode->jnFlags & JNODE_RAW)==0 );
|
||||
if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
|
||||
|
@ -1347,7 +1347,7 @@ static void jsonWrongNumArgs(
|
|||
char *zMsg = sqlite3_mprintf("json_%s() needs an odd number of arguments",
|
||||
zFuncName);
|
||||
sqlite3_result_error(pCtx, zMsg, -1);
|
||||
sqlite3_free(zMsg);
|
||||
sqlite3_free(zMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1434,7 +1434,7 @@ static void jsonTest1Func(
|
|||
|
||||
/*
|
||||
** Implementation of the json_QUOTE(VALUE) function. Return a JSON value
|
||||
** corresponding to the SQL value input. Mostly this means putting
|
||||
** corresponding to the SQL value input. Mostly this means putting
|
||||
** double-quotes around strings and returning the unquoted string "null"
|
||||
** when given a NULL input.
|
||||
*/
|
||||
|
@ -1481,7 +1481,7 @@ static void jsonArrayFunc(
|
|||
** json_array_length(JSON)
|
||||
** json_array_length(JSON, PATH)
|
||||
**
|
||||
** Return the number of elements in the top-level JSON array.
|
||||
** Return the number of elements in the top-level JSON array.
|
||||
** Return 0 if the input is not a well-formed JSON array.
|
||||
*/
|
||||
static void jsonArrayLengthFunc(
|
||||
|
@ -1974,7 +1974,7 @@ static void jsonGroupInverse(
|
|||
if( c=='}' || c==']' ) nNest--;
|
||||
}
|
||||
}
|
||||
pStr->nUsed -= i;
|
||||
pStr->nUsed -= i;
|
||||
memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1);
|
||||
}
|
||||
#else
|
||||
|
@ -2090,7 +2090,7 @@ static int jsonEachConnect(
|
|||
UNUSED_PARAM(argv);
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(pAux);
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,"
|
||||
"json HIDDEN,root HIDDEN)");
|
||||
if( rc==SQLITE_OK ){
|
||||
|
@ -2269,7 +2269,7 @@ static int jsonEachColumn(
|
|||
break;
|
||||
}
|
||||
case JEACH_ID: {
|
||||
sqlite3_result_int64(ctx,
|
||||
sqlite3_result_int64(ctx,
|
||||
(sqlite3_int64)p->i + ((pThis->jnFlags & JNODE_LABEL)!=0));
|
||||
break;
|
||||
}
|
||||
|
@ -2589,7 +2589,7 @@ int sqlite3Json1Init(sqlite3 *db){
|
|||
{ "json_tree", &jsonTreeModule },
|
||||
};
|
||||
#endif
|
||||
static const int enc =
|
||||
static const int enc =
|
||||
SQLITE_UTF8 |
|
||||
SQLITE_DETERMINISTIC |
|
||||
SQLITE_INNOCUOUS;
|
||||
|
@ -2620,8 +2620,8 @@ int sqlite3Json1Init(sqlite3 *db){
|
|||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_json_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
|
|
60
third_party/sqlite3/keywordhash.inc
vendored
60
third_party/sqlite3/keywordhash.inc
vendored
|
@ -127,36 +127,36 @@ static const unsigned short int aKWOffset[147] = {
|
|||
};
|
||||
/* aKWCode[i] is the parser symbol code for the i-th keyword */
|
||||
static const unsigned char aKWCode[147] = {
|
||||
TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
|
||||
TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
|
||||
TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
|
||||
TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
|
||||
TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
|
||||
TK_EXCLUDE, TK_DELETE, TK_TEMP, TK_TEMP, TK_OR,
|
||||
TK_ISNULL, TK_NULLS, TK_SAVEPOINT, TK_INTERSECT, TK_TIES,
|
||||
TK_NOTNULL, TK_NOT, TK_NO, TK_NULL, TK_LIKE_KW,
|
||||
TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
|
||||
TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_CONSTRAINT,
|
||||
TK_INTO, TK_OFFSET, TK_OF, TK_SET, TK_TRIGGER,
|
||||
TK_RANGE, TK_GENERATED, TK_DETACH, TK_HAVING, TK_LIKE_KW,
|
||||
TK_BEGIN, TK_JOIN_KW, TK_REFERENCES, TK_UNIQUE, TK_QUERY,
|
||||
TK_WITHOUT, TK_WITH, TK_JOIN_KW, TK_RELEASE, TK_ATTACH,
|
||||
TK_BETWEEN, TK_NOTHING, TK_GROUPS, TK_GROUP, TK_CASCADE,
|
||||
TK_ASC, TK_DEFAULT, TK_CASE, TK_COLLATE, TK_CREATE,
|
||||
TK_CTIME_KW, TK_IMMEDIATE, TK_JOIN, TK_INSERT, TK_MATCH,
|
||||
TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_MATERIALIZED, TK_DEFERRED,
|
||||
TK_DISTINCT, TK_IS, TK_UPDATE, TK_VALUES, TK_VIRTUAL,
|
||||
TK_ALWAYS, TK_WHEN, TK_WHERE, TK_RECURSIVE, TK_ABORT,
|
||||
TK_AFTER, TK_RENAME, TK_AND, TK_DROP, TK_PARTITION,
|
||||
TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW,
|
||||
TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW,
|
||||
TK_CURRENT, TK_PRECEDING, TK_FAIL, TK_LAST, TK_FILTER,
|
||||
TK_REPLACE, TK_FIRST, TK_FOLLOWING, TK_FROM, TK_JOIN_KW,
|
||||
TK_LIMIT, TK_IF, TK_ORDER, TK_RESTRICT, TK_OTHERS,
|
||||
TK_OVER, TK_RETURNING, TK_JOIN_KW, TK_ROLLBACK, TK_ROWS,
|
||||
TK_ROW, TK_UNBOUNDED, TK_UNION, TK_USING, TK_VACUUM,
|
||||
TK_VIEW, TK_WINDOW, TK_DO, TK_BY, TK_INITIALLY,
|
||||
TK_ALL, TK_PRIMARY,
|
||||
TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
|
||||
TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
|
||||
TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
|
||||
TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
|
||||
TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
|
||||
TK_EXCLUDE, TK_DELETE, TK_TEMP, TK_TEMP, TK_OR,
|
||||
TK_ISNULL, TK_NULLS, TK_SAVEPOINT, TK_INTERSECT, TK_TIES,
|
||||
TK_NOTNULL, TK_NOT, TK_NO, TK_NULL, TK_LIKE_KW,
|
||||
TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
|
||||
TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_CONSTRAINT,
|
||||
TK_INTO, TK_OFFSET, TK_OF, TK_SET, TK_TRIGGER,
|
||||
TK_RANGE, TK_GENERATED, TK_DETACH, TK_HAVING, TK_LIKE_KW,
|
||||
TK_BEGIN, TK_JOIN_KW, TK_REFERENCES, TK_UNIQUE, TK_QUERY,
|
||||
TK_WITHOUT, TK_WITH, TK_JOIN_KW, TK_RELEASE, TK_ATTACH,
|
||||
TK_BETWEEN, TK_NOTHING, TK_GROUPS, TK_GROUP, TK_CASCADE,
|
||||
TK_ASC, TK_DEFAULT, TK_CASE, TK_COLLATE, TK_CREATE,
|
||||
TK_CTIME_KW, TK_IMMEDIATE, TK_JOIN, TK_INSERT, TK_MATCH,
|
||||
TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_MATERIALIZED, TK_DEFERRED,
|
||||
TK_DISTINCT, TK_IS, TK_UPDATE, TK_VALUES, TK_VIRTUAL,
|
||||
TK_ALWAYS, TK_WHEN, TK_WHERE, TK_RECURSIVE, TK_ABORT,
|
||||
TK_AFTER, TK_RENAME, TK_AND, TK_DROP, TK_PARTITION,
|
||||
TK_AUTOINCR, TK_TO, TK_IN, TK_CAST, TK_COLUMNKW,
|
||||
TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW,
|
||||
TK_CURRENT, TK_PRECEDING, TK_FAIL, TK_LAST, TK_FILTER,
|
||||
TK_REPLACE, TK_FIRST, TK_FOLLOWING, TK_FROM, TK_JOIN_KW,
|
||||
TK_LIMIT, TK_IF, TK_ORDER, TK_RESTRICT, TK_OTHERS,
|
||||
TK_OVER, TK_RETURNING, TK_JOIN_KW, TK_ROLLBACK, TK_ROWS,
|
||||
TK_ROW, TK_UNBOUNDED, TK_UNION, TK_USING, TK_VACUUM,
|
||||
TK_VIEW, TK_WINDOW, TK_DO, TK_BY, TK_INITIALLY,
|
||||
TK_ALL, TK_PRIMARY,
|
||||
};
|
||||
/* Hash table decoded:
|
||||
** 0: INSERT
|
||||
|
|
2
third_party/sqlite3/legacy.c
vendored
2
third_party/sqlite3/legacy.c
vendored
|
@ -68,7 +68,7 @@ int sqlite3_exec(
|
|||
rc = sqlite3_step(pStmt);
|
||||
|
||||
/* Invoke the callback function if required */
|
||||
if( xCallback && (SQLITE_ROW==rc ||
|
||||
if( xCallback && (SQLITE_ROW==rc ||
|
||||
(SQLITE_DONE==rc && !callbackIsInit
|
||||
&& db->flags&SQLITE_NullCallback)) ){
|
||||
if( !callbackIsInit ){
|
||||
|
|
16
third_party/sqlite3/loadext.c
vendored
16
third_party/sqlite3/loadext.c
vendored
|
@ -299,8 +299,8 @@ static const sqlite3_api_routines sqlite3Apis = {
|
|||
sqlite3_memory_highwater,
|
||||
sqlite3_memory_used,
|
||||
#ifdef SQLITE_MUTEX_OMIT
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -499,7 +499,7 @@ static const sqlite3_api_routines sqlite3Apis = {
|
|||
**
|
||||
** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
|
||||
**
|
||||
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
|
||||
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
|
||||
** error message text. The calling function should free this memory
|
||||
** by calling sqlite3DbFree(db, ).
|
||||
*/
|
||||
|
@ -523,7 +523,7 @@ static int sqlite3LoadExtension(
|
|||
/* Shared library endings to try if zFile cannot be loaded as written */
|
||||
static const char *azEndings[] = {
|
||||
#if SQLITE_OS_WIN
|
||||
"dll"
|
||||
"dll"
|
||||
#elif defined(__APPLE__)
|
||||
"dylib"
|
||||
#else
|
||||
|
@ -563,7 +563,7 @@ static int sqlite3LoadExtension(
|
|||
if( pzErrMsg ){
|
||||
*pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
|
||||
if( zErrmsg ){
|
||||
sqlite3_snprintf(nMsg, zErrmsg,
|
||||
sqlite3_snprintf(nMsg, zErrmsg,
|
||||
"unable to open shared library [%s]", zFile);
|
||||
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
|
||||
}
|
||||
|
@ -575,9 +575,9 @@ static int sqlite3LoadExtension(
|
|||
/* If no entry point was specified and the default legacy
|
||||
** entry point name "sqlite3_extension_init" was not found, then
|
||||
** construct an entry point name "sqlite3_X_init" where the X is
|
||||
** replaced by the lowercase value of every ASCII alphabetic
|
||||
** replaced by the lowercase value of every ASCII alphabetic
|
||||
** character in the filename after the last "/" upto the first ".",
|
||||
** and eliding the first three characters if they are "lib".
|
||||
** and eliding the first three characters if they are "lib".
|
||||
** Examples:
|
||||
**
|
||||
** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
|
||||
|
@ -697,7 +697,7 @@ int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
|
|||
*/
|
||||
typedef struct sqlite3AutoExtList sqlite3AutoExtList;
|
||||
static SQLITE_WSD struct sqlite3AutoExtList {
|
||||
u32 nExt; /* Number of entries in aExt[] */
|
||||
u32 nExt; /* Number of entries in aExt[] */
|
||||
void (**aExt)(void); /* Pointers to the extension init functions */
|
||||
} sqlite3Autoext = { 0, 0 };
|
||||
|
||||
|
|
190
third_party/sqlite3/main.c
vendored
190
third_party/sqlite3/main.c
vendored
|
@ -107,7 +107,7 @@ const char sqlite3_version[] = SQLITE_VERSION;
|
|||
#endif
|
||||
|
||||
/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
|
||||
** a pointer to the to the sqlite3_version[] string constant.
|
||||
** a pointer to the to the sqlite3_version[] string constant.
|
||||
*/
|
||||
const char *sqlite3_libversion(void){ return sqlite3_version; }
|
||||
|
||||
|
@ -171,13 +171,13 @@ char *sqlite3_temp_directory = 0;
|
|||
char *sqlite3_data_directory = 0;
|
||||
|
||||
/*
|
||||
** Initialize SQLite.
|
||||
** Initialize SQLite.
|
||||
**
|
||||
** This routine must be called to initialize the memory allocation,
|
||||
** VFS, and mutex subsystems prior to doing any serious work with
|
||||
** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT
|
||||
** this routine will be called automatically by key routines such as
|
||||
** sqlite3_open().
|
||||
** sqlite3_open().
|
||||
**
|
||||
** This routine is a no-op except on its very first call for the process,
|
||||
** or for the first call after a call to sqlite3_shutdown.
|
||||
|
@ -230,7 +230,7 @@ int sqlite3_initialize(void){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Make sure the mutex subsystem is initialized. If unable to
|
||||
/* Make sure the mutex subsystem is initialized. If unable to
|
||||
** initialize the mutex subsystem, return early with the error.
|
||||
** If the system is so sick that we are unable to allocate a mutex,
|
||||
** there is not much SQLite is going to be able to do.
|
||||
|
@ -312,7 +312,7 @@ int sqlite3_initialize(void){
|
|||
}
|
||||
#endif
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
|
||||
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
|
||||
sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
|
||||
sqlite3MemoryBarrier();
|
||||
sqlite3GlobalConfig.isInit = 1;
|
||||
|
@ -530,7 +530,7 @@ int sqlite3_config(int op, ...){
|
|||
** a single parameter which is a pointer to an integer and writes into
|
||||
** that integer the number of extra bytes per page required for each page
|
||||
** in SQLITE_CONFIG_PAGECACHE. */
|
||||
*va_arg(ap, int*) =
|
||||
*va_arg(ap, int*) =
|
||||
sqlite3HeaderSizeBtree() +
|
||||
sqlite3HeaderSizePcache() +
|
||||
sqlite3HeaderSizePcache1();
|
||||
|
@ -617,7 +617,7 @@ int sqlite3_config(int op, ...){
|
|||
sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Record a pointer to the logger function and its first argument.
|
||||
** The default is NULL. Logging is disabled if the function pointer is
|
||||
** NULL.
|
||||
|
@ -739,7 +739,7 @@ int sqlite3_config(int op, ...){
|
|||
|
||||
/*
|
||||
** Set up the lookaside buffers for a database connection.
|
||||
** Return SQLITE_OK on success.
|
||||
** Return SQLITE_OK on success.
|
||||
** If lookaside is already active, return SQLITE_BUSY.
|
||||
**
|
||||
** The sz parameter is the number of bytes in each lookaside slot.
|
||||
|
@ -754,12 +754,12 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
|
|||
sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
|
||||
int nBig; /* Number of full-size slots */
|
||||
int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
|
||||
|
||||
|
||||
if( sqlite3LookasideUsed(db,0)>0 ){
|
||||
return SQLITE_BUSY;
|
||||
}
|
||||
/* Free any existing lookaside buffer for this handle before
|
||||
** allocating a new one so we don't have to have space for
|
||||
** allocating a new one so we don't have to have space for
|
||||
** both at the same time.
|
||||
*/
|
||||
if( db->lookaside.bMalloced ){
|
||||
|
@ -1034,7 +1034,7 @@ int sqlite3IsBinary(const CollSeq *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** Another built-in collating sequence: NOCASE.
|
||||
** Another built-in collating sequence: NOCASE.
|
||||
**
|
||||
** This collating sequence is intended to be used for "case independent
|
||||
** comparison". SQLite's knowledge of upper and lower case equivalents
|
||||
|
@ -1176,7 +1176,7 @@ static void disconnectAllVtab(sqlite3 *db){
|
|||
|
||||
/*
|
||||
** Return TRUE if database connection db has unfinalized prepared
|
||||
** statements or unfinished sqlite3_backup objects.
|
||||
** statements or unfinished sqlite3_backup objects.
|
||||
*/
|
||||
static int connectionIsBusy(sqlite3 *db){
|
||||
int j;
|
||||
|
@ -1392,7 +1392,7 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
|||
/* The temp-database schema is allocated differently from the other schema
|
||||
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
|
||||
** So it needs to be freed here. Todo: Why not roll the temp schema into
|
||||
** the same sqliteMalloc() as the one that allocates the database
|
||||
** the same sqliteMalloc() as the one that allocates the database
|
||||
** structure?
|
||||
*/
|
||||
sqlite3DbFree(db, db->aDb[1].pSchema);
|
||||
|
@ -1420,7 +1420,7 @@ void sqlite3RollbackAll(sqlite3 *db, int tripCode){
|
|||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
sqlite3BeginBenignMalloc();
|
||||
|
||||
/* Obtain all b-tree mutexes before making any calls to BtreeRollback().
|
||||
/* Obtain all b-tree mutexes before making any calls to BtreeRollback().
|
||||
** This is important in case the transaction being rolled back has
|
||||
** modified the database schema. If the b-tree mutexes are not taken
|
||||
** here, then another shared-cache connection might sneak in between
|
||||
|
@ -1705,7 +1705,7 @@ int sqlite3InvokeBusyHandler(BusyHandler *p){
|
|||
}else{
|
||||
p->nBusy++;
|
||||
}
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1736,9 +1736,9 @@ int sqlite3_busy_handler(
|
|||
** be invoked every nOps opcodes.
|
||||
*/
|
||||
void sqlite3_progress_handler(
|
||||
sqlite3 *db,
|
||||
sqlite3 *db,
|
||||
int nOps,
|
||||
int (*xProgress)(void*),
|
||||
int (*xProgress)(void*),
|
||||
void *pArg
|
||||
){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
|
@ -1798,7 +1798,7 @@ void sqlite3_interrupt(sqlite3 *db){
|
|||
** This function is exactly the same as sqlite3_create_function(), except
|
||||
** that it is designed to be called by internal code. The difference is
|
||||
** that if a malloc() fails in sqlite3_create_function(), an error code
|
||||
** is returned and the mallocFailed flag cleared.
|
||||
** is returned and the mallocFailed flag cleared.
|
||||
*/
|
||||
int sqlite3CreateFunc(
|
||||
sqlite3 *db,
|
||||
|
@ -1840,7 +1840,7 @@ int sqlite3CreateFunc(
|
|||
assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS );
|
||||
extraFlags ^= SQLITE_FUNC_UNSAFE;
|
||||
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/* If SQLITE_UTF16 is specified as the encoding type, transform this
|
||||
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
|
||||
|
@ -1869,7 +1869,7 @@ int sqlite3CreateFunc(
|
|||
#else
|
||||
enc = SQLITE_UTF8;
|
||||
#endif
|
||||
|
||||
|
||||
/* Check if an existing function is being overridden or deleted. If so,
|
||||
** and there are active VMs, then return SQLITE_BUSY. If a function
|
||||
** is being overridden/deleted but there are no active VMs, allow the
|
||||
|
@ -1878,7 +1878,7 @@ int sqlite3CreateFunc(
|
|||
p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
|
||||
if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==(u32)enc && p->nArg==nArg ){
|
||||
if( db->nVdbeActive ){
|
||||
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
||||
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
||||
"unable to delete/modify user-function due to active statements");
|
||||
assert( !db->mallocFailed );
|
||||
return SQLITE_BUSY;
|
||||
|
@ -1953,7 +1953,7 @@ static int createFunctionApi(
|
|||
pArg->xDestroy = xDestroy;
|
||||
pArg->pUserData = p;
|
||||
}
|
||||
rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p,
|
||||
rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p,
|
||||
xSFunc, xStep, xFinal, xValue, xInverse, pArg
|
||||
);
|
||||
if( pArg && pArg->nRef==0 ){
|
||||
|
@ -2070,7 +2070,7 @@ static void sqlite3InvalidFunction(
|
|||
**
|
||||
** If the function already exists as a regular global function, then
|
||||
** this routine is a no-op. If the function does not exist, then create
|
||||
** a new one that always throws a run-time error.
|
||||
** a new one that always throws a run-time error.
|
||||
**
|
||||
** When virtual tables intend to provide an overloaded function, they
|
||||
** should call this routine to make sure the global function exists.
|
||||
|
@ -2103,7 +2103,7 @@ int sqlite3_overload_function(
|
|||
#ifndef SQLITE_OMIT_TRACE
|
||||
/*
|
||||
** Register a trace function. The pArg from the previously registered trace
|
||||
** is returned.
|
||||
** is returned.
|
||||
**
|
||||
** A NULL trace function means that no tracing is executes. A non-NULL
|
||||
** trace is a pointer to a function that is invoked at the start of each
|
||||
|
@ -2154,8 +2154,8 @@ int sqlite3_trace_v2(
|
|||
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
/*
|
||||
** Register a profile function. The pArg from the previously registered
|
||||
** profile function is returned.
|
||||
** Register a profile function. The pArg from the previously registered
|
||||
** profile function is returned.
|
||||
**
|
||||
** A NULL profile function means that no profiling is executes. A non-NULL
|
||||
** profile is a pointer to a function that is invoked at the conclusion of
|
||||
|
@ -2289,7 +2289,7 @@ void *sqlite3_preupdate_hook(
|
|||
** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
|
||||
** is greater than sqlite3.pWalArg cast to an integer (the value configured by
|
||||
** wal_autocheckpoint()).
|
||||
*/
|
||||
*/
|
||||
int sqlite3WalDefaultHook(
|
||||
void *pClientData, /* Argument */
|
||||
sqlite3 *db, /* Connection */
|
||||
|
@ -2425,7 +2425,7 @@ int sqlite3_wal_checkpoint_v2(
|
|||
|
||||
/*
|
||||
** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
|
||||
** to contains a zero-length string, all attached databases are
|
||||
** to contains a zero-length string, all attached databases are
|
||||
** checkpointed.
|
||||
*/
|
||||
int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
|
||||
|
@ -2439,9 +2439,9 @@ int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
|
|||
** Run a checkpoint on database iDb. This is a no-op if database iDb is
|
||||
** not currently open in WAL mode.
|
||||
**
|
||||
** If a transaction is open on the database being checkpointed, this
|
||||
** function returns SQLITE_LOCKED and a checkpoint is not attempted. If
|
||||
** an error occurs while running the checkpoint, an SQLite error code is
|
||||
** If a transaction is open on the database being checkpointed, this
|
||||
** function returns SQLITE_LOCKED and a checkpoint is not attempted. If
|
||||
** an error occurs while running the checkpoint, an SQLite error code is
|
||||
** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
|
||||
**
|
||||
** The mutex on database handle db should be held by the caller. The mutex
|
||||
|
@ -2612,7 +2612,7 @@ int sqlite3_extended_errcode(sqlite3 *db){
|
|||
}
|
||||
int sqlite3_system_errno(sqlite3 *db){
|
||||
return db ? db->iSysErrno : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a string that describes the kind of error specified in the
|
||||
|
@ -2629,7 +2629,7 @@ const char *sqlite3_errstr(int rc){
|
|||
*/
|
||||
static int createCollation(
|
||||
sqlite3* db,
|
||||
const char *zName,
|
||||
const char *zName,
|
||||
u8 enc,
|
||||
void* pCtx,
|
||||
int(*xCompare)(void*,int,const void*,int,const void*),
|
||||
|
@ -2637,7 +2637,7 @@ static int createCollation(
|
|||
){
|
||||
CollSeq *pColl;
|
||||
int enc2;
|
||||
|
||||
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
|
||||
/* If SQLITE_UTF16 is specified as the encoding type, transform this
|
||||
|
@ -2654,14 +2654,14 @@ static int createCollation(
|
|||
return SQLITE_MISUSE_BKPT;
|
||||
}
|
||||
|
||||
/* Check if this call is removing or replacing an existing collation
|
||||
/* Check if this call is removing or replacing an existing collation
|
||||
** sequence. If so, and there are active VMs, return busy. If there
|
||||
** are no active VMs, invalidate any pre-compiled statements.
|
||||
*/
|
||||
pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
|
||||
if( pColl && pColl->xCmp ){
|
||||
if( db->nVdbeActive ){
|
||||
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
||||
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
||||
"unable to delete/modify collation sequence due to active statements");
|
||||
return SQLITE_BUSY;
|
||||
}
|
||||
|
@ -2672,7 +2672,7 @@ static int createCollation(
|
|||
** then any copies made by synthCollSeq() need to be invalidated.
|
||||
** Also, collation destructor - CollSeq.xDel() - function may need
|
||||
** to be called.
|
||||
*/
|
||||
*/
|
||||
if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){
|
||||
CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName);
|
||||
int j;
|
||||
|
@ -2821,7 +2821,7 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
|||
** query parameter. The second argument contains the URI (or non-URI filename)
|
||||
** itself. When this function is called the *pFlags variable should contain
|
||||
** the default flags to open the database handle with. The value stored in
|
||||
** *pFlags may be updated before returning if the URI filename contains
|
||||
** *pFlags may be updated before returning if the URI filename contains
|
||||
** "cache=xxx" or "mode=xxx" query parameters.
|
||||
**
|
||||
** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
|
||||
|
@ -2833,7 +2833,7 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
|||
** the value returned in *pzFile to avoid a memory leak.
|
||||
**
|
||||
** If an error occurs, then an SQLite error code is returned and *pzErrMsg
|
||||
** may be set to point to a buffer containing an English language error
|
||||
** may be set to point to a buffer containing an English language error
|
||||
** message. It is the responsibility of the caller to eventually release
|
||||
** this buffer by calling sqlite3_free().
|
||||
*/
|
||||
|
@ -2841,7 +2841,7 @@ int sqlite3ParseUri(
|
|||
const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */
|
||||
const char *zUri, /* Nul-terminated URI to parse */
|
||||
unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
|
||||
sqlite3_vfs **ppVfs, /* OUT: VFS to use */
|
||||
sqlite3_vfs **ppVfs, /* OUT: VFS to use */
|
||||
char **pzFile, /* OUT: Filename component of URI */
|
||||
char **pzErrMsg /* OUT: Error message (if rc!=SQLITE_OK) */
|
||||
){
|
||||
|
@ -2864,7 +2864,7 @@ int sqlite3ParseUri(
|
|||
int iOut = 0; /* Output character index */
|
||||
u64 nByte = nUri+8; /* Bytes of space to allocate */
|
||||
|
||||
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
|
||||
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
|
||||
** method that there may be extra parameters following the file-name. */
|
||||
flags |= SQLITE_OPEN_URI;
|
||||
|
||||
|
@ -2882,7 +2882,7 @@ int sqlite3ParseUri(
|
|||
/* The following condition causes URIs with five leading / characters
|
||||
** like file://///host/path to be converted into UNCs like //host/path.
|
||||
** The correct URI for that UNC has only two or four leading / characters
|
||||
** file://host/path or file:////host/path. But 5 leading slashes is a
|
||||
** file://host/path or file:////host/path. But 5 leading slashes is a
|
||||
** common error, we are told, so we handle it as a special case. */
|
||||
if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
|
||||
}else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
|
||||
|
@ -2894,7 +2894,7 @@ int sqlite3ParseUri(
|
|||
iIn = 7;
|
||||
while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
|
||||
if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
|
||||
*pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
|
||||
*pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
|
||||
iIn-7, &zUri[7]);
|
||||
rc = SQLITE_ERROR;
|
||||
goto parse_uri_out;
|
||||
|
@ -2902,8 +2902,8 @@ int sqlite3ParseUri(
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Copy the filename and any query parameters into the zFile buffer.
|
||||
** Decode %HH escape codes along the way.
|
||||
/* Copy the filename and any query parameters into the zFile buffer.
|
||||
** Decode %HH escape codes along the way.
|
||||
**
|
||||
** Within this loop, variable eState may be set to 0, 1 or 2, depending
|
||||
** on the parsing context. As follows:
|
||||
|
@ -2915,9 +2915,9 @@ int sqlite3ParseUri(
|
|||
eState = 0;
|
||||
while( (c = zUri[iIn])!=0 && c!='#' ){
|
||||
iIn++;
|
||||
if( c=='%'
|
||||
&& sqlite3Isxdigit(zUri[iIn])
|
||||
&& sqlite3Isxdigit(zUri[iIn+1])
|
||||
if( c=='%'
|
||||
&& sqlite3Isxdigit(zUri[iIn])
|
||||
&& sqlite3Isxdigit(zUri[iIn+1])
|
||||
){
|
||||
int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
|
||||
octet += sqlite3HexToInt(zUri[iIn++]);
|
||||
|
@ -2929,7 +2929,7 @@ int sqlite3ParseUri(
|
|||
** case we ignore all text in the remainder of the path, name or
|
||||
** value currently being parsed. So ignore the current character
|
||||
** and skip to the next "?", "=" or "&", as appropriate. */
|
||||
while( (c = zUri[iIn])!=0 && c!='#'
|
||||
while( (c = zUri[iIn])!=0 && c!='#'
|
||||
&& (eState!=0 || c!='?')
|
||||
&& (eState!=1 || (c!='=' && c!='&'))
|
||||
&& (eState!=2 || c!='&')
|
||||
|
@ -2966,7 +2966,7 @@ int sqlite3ParseUri(
|
|||
if( eState==1 ) zFile[iOut++] = '\0';
|
||||
memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */
|
||||
|
||||
/* Check if there were any options specified that should be interpreted
|
||||
/* Check if there were any options specified that should be interpreted
|
||||
** here. Options that are interpreted here include "vfs" and those that
|
||||
** correspond to flags that may be passed to the sqlite3_open_v2()
|
||||
** method. */
|
||||
|
@ -3002,7 +3002,7 @@ int sqlite3ParseUri(
|
|||
if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
|
||||
static struct OpenMode aOpenMode[] = {
|
||||
{ "ro", SQLITE_OPEN_READONLY },
|
||||
{ "rw", SQLITE_OPEN_READWRITE },
|
||||
{ "rw", SQLITE_OPEN_READWRITE },
|
||||
{ "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
|
||||
{ "memory", SQLITE_OPEN_MEMORY },
|
||||
{ 0, 0 }
|
||||
|
@ -3089,7 +3089,7 @@ static const char *uriParameter(const char *zFilename, const char *zParam){
|
|||
|
||||
/*
|
||||
** This routine does the work of opening a database on behalf of
|
||||
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
|
||||
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
|
||||
** is UTF-8 encoded.
|
||||
*/
|
||||
static int openDatabase(
|
||||
|
@ -3142,11 +3142,11 @@ static int openDatabase(
|
|||
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
|
||||
SQLITE_OPEN_EXCLUSIVE |
|
||||
SQLITE_OPEN_MAIN_DB |
|
||||
SQLITE_OPEN_TEMP_DB |
|
||||
SQLITE_OPEN_TRANSIENT_DB |
|
||||
SQLITE_OPEN_MAIN_JOURNAL |
|
||||
SQLITE_OPEN_TEMP_JOURNAL |
|
||||
SQLITE_OPEN_SUBJOURNAL |
|
||||
SQLITE_OPEN_TEMP_DB |
|
||||
SQLITE_OPEN_TRANSIENT_DB |
|
||||
SQLITE_OPEN_MAIN_JOURNAL |
|
||||
SQLITE_OPEN_TEMP_JOURNAL |
|
||||
SQLITE_OPEN_SUBJOURNAL |
|
||||
SQLITE_OPEN_SUPER_JOURNAL |
|
||||
SQLITE_OPEN_NOMUTEX |
|
||||
SQLITE_OPEN_FULLMUTEX |
|
||||
|
@ -3156,7 +3156,7 @@ static int openDatabase(
|
|||
/* Allocate the sqlite data structure */
|
||||
db = sqlite3MallocZero( sizeof(sqlite3) );
|
||||
if( db==0 ) goto opendb_out;
|
||||
if( isThreadsafe
|
||||
if( isThreadsafe
|
||||
#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
|
||||
|| sqlite3GlobalConfig.bCoreMutex
|
||||
#endif
|
||||
|
@ -3199,7 +3199,7 @@ static int openDatabase(
|
|||
**
|
||||
** SQLITE_DQS SQLITE_DBCONFIG_DQS_DDL SQLITE_DBCONFIG_DQS_DML
|
||||
** ---------- ----------------------- -----------------------
|
||||
** undefined on on
|
||||
** undefined on on
|
||||
** 3 on on
|
||||
** 2 on off
|
||||
** 1 off on
|
||||
|
@ -3279,7 +3279,7 @@ static int openDatabase(
|
|||
|
||||
/* Parse the filename/URI argument
|
||||
**
|
||||
** Only allow sensible combinations of bits in the flags argument.
|
||||
** Only allow sensible combinations of bits in the flags argument.
|
||||
** Throw an error if any non-sense combination is used. If we
|
||||
** do not block illegal combinations here, it could trigger
|
||||
** assert() statements in deeper layers. Sensible combinations
|
||||
|
@ -3327,7 +3327,7 @@ static int openDatabase(
|
|||
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
|
||||
|
||||
/* The default safety_level for the main database is FULL; for the temp
|
||||
** database it is OFF. This matches the pager layer defaults.
|
||||
** database it is OFF. This matches the pager layer defaults.
|
||||
*/
|
||||
db->aDb[0].zDbSName = "main";
|
||||
db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
|
||||
|
@ -3366,7 +3366,7 @@ static int openDatabase(
|
|||
|
||||
#ifdef SQLITE_ENABLE_INTERNAL_FUNCTIONS
|
||||
/* Testing use only!!! The -DSQLITE_ENABLE_INTERNAL_FUNCTIONS=1 compile-time
|
||||
** option gives access to internal functions by default.
|
||||
** option gives access to internal functions by default.
|
||||
** Testing use only!!! */
|
||||
db->mDbFlags |= DBFLAG_InternalFunc;
|
||||
#endif
|
||||
|
@ -3420,8 +3420,8 @@ opendb_out:
|
|||
** Open a new database handle.
|
||||
*/
|
||||
int sqlite3_open(
|
||||
const char *zFilename,
|
||||
sqlite3 **ppDb
|
||||
const char *zFilename,
|
||||
sqlite3 **ppDb
|
||||
){
|
||||
return openDatabase(zFilename, ppDb,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
|
||||
|
@ -3440,7 +3440,7 @@ int sqlite3_open_v2(
|
|||
** Open a new database handle.
|
||||
*/
|
||||
int sqlite3_open16(
|
||||
const void *zFilename,
|
||||
const void *zFilename,
|
||||
sqlite3 **ppDb
|
||||
){
|
||||
char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
|
||||
|
@ -3479,9 +3479,9 @@ int sqlite3_open16(
|
|||
** Register a new collation sequence with the database handle db.
|
||||
*/
|
||||
int sqlite3_create_collation(
|
||||
sqlite3* db,
|
||||
const char *zName,
|
||||
int enc,
|
||||
sqlite3* db,
|
||||
const char *zName,
|
||||
int enc,
|
||||
void* pCtx,
|
||||
int(*xCompare)(void*,int,const void*,int,const void*)
|
||||
){
|
||||
|
@ -3492,9 +3492,9 @@ int sqlite3_create_collation(
|
|||
** Register a new collation sequence with the database handle db.
|
||||
*/
|
||||
int sqlite3_create_collation_v2(
|
||||
sqlite3* db,
|
||||
const char *zName,
|
||||
int enc,
|
||||
sqlite3* db,
|
||||
const char *zName,
|
||||
int enc,
|
||||
void* pCtx,
|
||||
int(*xCompare)(void*,int,const void*,int,const void*),
|
||||
void(*xDel)(void*)
|
||||
|
@ -3517,9 +3517,9 @@ int sqlite3_create_collation_v2(
|
|||
** Register a new collation sequence with the database handle db.
|
||||
*/
|
||||
int sqlite3_create_collation16(
|
||||
sqlite3* db,
|
||||
sqlite3* db,
|
||||
const void *zName,
|
||||
int enc,
|
||||
int enc,
|
||||
void* pCtx,
|
||||
int(*xCompare)(void*,int,const void*,int,const void*)
|
||||
){
|
||||
|
@ -3547,8 +3547,8 @@ int sqlite3_create_collation16(
|
|||
** db. Replace any previously installed collation sequence factory.
|
||||
*/
|
||||
int sqlite3_collation_needed(
|
||||
sqlite3 *db,
|
||||
void *pCollNeededArg,
|
||||
sqlite3 *db,
|
||||
void *pCollNeededArg,
|
||||
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
|
||||
){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
|
@ -3568,8 +3568,8 @@ int sqlite3_collation_needed(
|
|||
** db. Replace any previously installed collation sequence factory.
|
||||
*/
|
||||
int sqlite3_collation_needed16(
|
||||
sqlite3 *db,
|
||||
void *pCollNeededArg,
|
||||
sqlite3 *db,
|
||||
void *pCollNeededArg,
|
||||
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
|
||||
){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
|
@ -3741,13 +3741,13 @@ int sqlite3_table_column_metadata(
|
|||
/* The following block stores the meta information that will be returned
|
||||
** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
|
||||
** and autoinc. At this point there are two possibilities:
|
||||
**
|
||||
** 1. The specified column name was rowid", "oid" or "_rowid_"
|
||||
** and there is no explicitly declared IPK column.
|
||||
**
|
||||
** 1. The specified column name was rowid", "oid" or "_rowid_"
|
||||
** and there is no explicitly declared IPK column.
|
||||
**
|
||||
** 2. The table is not a view and the column name identified an
|
||||
** 2. The table is not a view and the column name identified an
|
||||
** explicitly declared column. Copy meta information from *pCol.
|
||||
*/
|
||||
*/
|
||||
if( pCol ){
|
||||
zDataType = sqlite3ColumnType(pCol,0);
|
||||
zCollSeq = pCol->zColl;
|
||||
|
@ -3797,7 +3797,7 @@ int sqlite3_sleep(int ms){
|
|||
pVfs = sqlite3_vfs_find(0);
|
||||
if( pVfs==0 ) return 0;
|
||||
|
||||
/* This function works in milliseconds, but the underlying OsSleep()
|
||||
/* This function works in milliseconds, but the underlying OsSleep()
|
||||
** API uses microseconds. Hence the 1000's.
|
||||
*/
|
||||
rc = (sqlite3OsSleep(pVfs, 1000*ms)/1000);
|
||||
|
@ -3970,7 +3970,7 @@ int sqlite3_test_control(int op, ...){
|
|||
/*
|
||||
** sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd)
|
||||
**
|
||||
** Register hooks to call to indicate which malloc() failures
|
||||
** Register hooks to call to indicate which malloc() failures
|
||||
** are benign.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: {
|
||||
|
@ -4068,7 +4068,7 @@ int sqlite3_test_control(int op, ...){
|
|||
** 10 little-endian, determined at run-time
|
||||
** 432101 big-endian, determined at compile-time
|
||||
** 123410 little-endian, determined at compile-time
|
||||
*/
|
||||
*/
|
||||
case SQLITE_TESTCTRL_BYTEORDER: {
|
||||
rc = SQLITE_BYTEORDER*100 + SQLITE_LITTLEENDIAN*10 + SQLITE_BIGENDIAN;
|
||||
break;
|
||||
|
@ -4076,7 +4076,7 @@ int sqlite3_test_control(int op, ...){
|
|||
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
|
||||
**
|
||||
** Enable or disable various optimizations for testing purposes. The
|
||||
** Enable or disable various optimizations for testing purposes. The
|
||||
** argument N is a bitmask of optimizations to be disabled. For normal
|
||||
** operation N should be 0. The idea is that a test program (like the
|
||||
** SQL Logic Test or SLT test module) can run the same SQL multiple times
|
||||
|
@ -4152,7 +4152,7 @@ int sqlite3_test_control(int op, ...){
|
|||
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
|
||||
**
|
||||
** Set the VDBE coverage callback function to xCallback with context
|
||||
** Set the VDBE coverage callback function to xCallback with context
|
||||
** pointer ptr.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_VDBE_COVERAGE: {
|
||||
|
@ -4262,7 +4262,7 @@ int sqlite3_test_control(int op, ...){
|
|||
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, op, ptr)
|
||||
**
|
||||
** "ptr" is a pointer to a u32.
|
||||
** "ptr" is a pointer to a u32.
|
||||
**
|
||||
** op==0 Store the current sqlite3SelectTrace in *ptr
|
||||
** op==1 Set sqlite3SelectTrace to the value *ptr
|
||||
|
@ -4365,7 +4365,7 @@ void sqlite3_free_filename(char *p){
|
|||
|
||||
/*
|
||||
** This is a utility routine, useful to VFS implementations, that checks
|
||||
** to see if a database file was a URI that contained a specific query
|
||||
** to see if a database file was a URI that contained a specific query
|
||||
** parameter, and if so obtains the value of the query parameter.
|
||||
**
|
||||
** The zFilename argument is the filename pointer passed into the xOpen()
|
||||
|
@ -4493,11 +4493,11 @@ int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
|
|||
|
||||
#ifdef SQLITE_ENABLE_SNAPSHOT
|
||||
/*
|
||||
** Obtain a snapshot handle for the snapshot of database zDb currently
|
||||
** Obtain a snapshot handle for the snapshot of database zDb currently
|
||||
** being read by handle db.
|
||||
*/
|
||||
int sqlite3_snapshot_get(
|
||||
sqlite3 *db,
|
||||
sqlite3 *db,
|
||||
const char *zDb,
|
||||
sqlite3_snapshot **ppSnapshot
|
||||
){
|
||||
|
@ -4533,8 +4533,8 @@ int sqlite3_snapshot_get(
|
|||
** Open a read-transaction on the snapshot idendified by pSnapshot.
|
||||
*/
|
||||
int sqlite3_snapshot_open(
|
||||
sqlite3 *db,
|
||||
const char *zDb,
|
||||
sqlite3 *db,
|
||||
const char *zDb,
|
||||
sqlite3_snapshot *pSnapshot
|
||||
){
|
||||
int rc = SQLITE_ERROR;
|
||||
|
@ -4636,7 +4636,7 @@ int sqlite3_compileoption_used(const char *zOptName){
|
|||
int i, n;
|
||||
int nOpt;
|
||||
const char **azCompileOpt;
|
||||
|
||||
|
||||
#if SQLITE_ENABLE_API_ARMOR
|
||||
if( zOptName==0 ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
|
@ -4649,7 +4649,7 @@ int sqlite3_compileoption_used(const char *zOptName){
|
|||
if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
|
||||
n = sqlite3Strlen30(zOptName);
|
||||
|
||||
/* Since nOpt is normally in single digits, a linear search is
|
||||
/* Since nOpt is normally in single digits, a linear search is
|
||||
** adequate. No need for a binary search. */
|
||||
for(i=0; i<nOpt; i++){
|
||||
if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
|
||||
|
|
26
third_party/sqlite3/malloc.c
vendored
26
third_party/sqlite3/malloc.c
vendored
|
@ -214,7 +214,7 @@ sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
|
|||
}
|
||||
|
||||
/*
|
||||
** Trigger the alarm
|
||||
** Trigger the alarm
|
||||
*/
|
||||
static void sqlite3MallocAlarm(int nByte){
|
||||
if( mem0.alarmThreshold<=0 ) return;
|
||||
|
@ -334,11 +334,11 @@ int sqlite3MallocSize(void *p){
|
|||
return sqlite3GlobalConfig.m.xSize(p);
|
||||
}
|
||||
static int lookasideMallocSize(sqlite3 *db, void *p){
|
||||
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
|
||||
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
|
||||
return p<db->lookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL;
|
||||
#else
|
||||
return db->lookaside.szTrue;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
int sqlite3DbMallocSize(sqlite3 *db, void *p){
|
||||
assert( p!=0 );
|
||||
|
@ -479,7 +479,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){
|
|||
sqlite3_mutex_enter(mem0.mutex);
|
||||
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
|
||||
nDiff = nNew - nOld;
|
||||
if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >=
|
||||
if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >=
|
||||
mem0.alarmThreshold-nDiff ){
|
||||
sqlite3MallocAlarm(nDiff);
|
||||
if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){
|
||||
|
@ -527,7 +527,7 @@ void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
|
|||
|
||||
/*
|
||||
** Allocate and zero memory.
|
||||
*/
|
||||
*/
|
||||
void *sqlite3MallocZero(u64 n){
|
||||
void *p = sqlite3Malloc(n);
|
||||
if( p ){
|
||||
|
@ -557,13 +557,13 @@ static SQLITE_NOINLINE void *dbMallocRawFinish(sqlite3 *db, u64 n){
|
|||
assert( db!=0 );
|
||||
p = sqlite3Malloc(n);
|
||||
if( !p ) sqlite3OomFault(db);
|
||||
sqlite3MemdebugSetType(p,
|
||||
sqlite3MemdebugSetType(p,
|
||||
(db->lookaside.bDisable==0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate memory, either lookaside (if possible) or heap.
|
||||
** Allocate memory, either lookaside (if possible) or heap.
|
||||
** If the allocation fails, set the mallocFailed flag in
|
||||
** the connection pointer.
|
||||
**
|
||||
|
@ -599,7 +599,7 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){
|
|||
assert( db->pnBytesFreed==0 );
|
||||
if( n>db->lookaside.sz ){
|
||||
if( !db->lookaside.bDisable ){
|
||||
db->lookaside.anStat[1]++;
|
||||
db->lookaside.anStat[1]++;
|
||||
}else if( db->mallocFailed ){
|
||||
return 0;
|
||||
}
|
||||
|
@ -703,9 +703,9 @@ void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, u64 n){
|
|||
}
|
||||
|
||||
/*
|
||||
** Make a copy of a string in memory obtained from sqliteMalloc(). These
|
||||
** Make a copy of a string in memory obtained from sqliteMalloc(). These
|
||||
** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This
|
||||
** is because when memory debugging is turned on, these two functions are
|
||||
** is because when memory debugging is turned on, these two functions are
|
||||
** called via macros that record the current file and line number in the
|
||||
** ThreadData structure.
|
||||
*/
|
||||
|
@ -804,20 +804,20 @@ static SQLITE_NOINLINE int apiHandleError(sqlite3 *db, int rc){
|
|||
}
|
||||
|
||||
/*
|
||||
** This function must be called before exiting any API function (i.e.
|
||||
** This function must be called before exiting any API function (i.e.
|
||||
** returning control to the user) that has called sqlite3_malloc or
|
||||
** sqlite3_realloc.
|
||||
**
|
||||
** The returned value is normally a copy of the second argument to this
|
||||
** function. However, if a malloc() failure has occurred since the previous
|
||||
** invocation SQLITE_NOMEM is returned instead.
|
||||
** invocation SQLITE_NOMEM is returned instead.
|
||||
**
|
||||
** If an OOM as occurred, then the connection error-code (the value
|
||||
** returned by sqlite3_errcode()) is set to SQLITE_NOMEM.
|
||||
*/
|
||||
int sqlite3ApiExit(sqlite3* db, int rc){
|
||||
/* If the db handle must hold the connection handle mutex here.
|
||||
** Otherwise the read (and possible write) of db->mallocFailed
|
||||
** Otherwise the read (and possible write) of db->mallocFailed
|
||||
** is unsafe, as is the call to sqlite3Error().
|
||||
*/
|
||||
assert( db!=0 );
|
||||
|
|
4
third_party/sqlite3/mem1.c
vendored
4
third_party/sqlite3/mem1.c
vendored
|
@ -71,7 +71,7 @@ static malloc_zone_t* _sqliteZone_;
|
|||
#else /* if not __APPLE__ */
|
||||
|
||||
/*
|
||||
** Use standard C library malloc and free on non-Apple systems.
|
||||
** Use standard C library malloc and free on non-Apple systems.
|
||||
** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
|
||||
*/
|
||||
#define SQLITE_MALLOC(x) malloc(x)
|
||||
|
@ -251,7 +251,7 @@ static int sqlite3MemInit(void *NotUsed){
|
|||
/* defer MT decisions to system malloc */
|
||||
_sqliteZone_ = malloc_default_zone();
|
||||
}else{
|
||||
/* only 1 core, use our own zone to contention over global locks,
|
||||
/* only 1 core, use our own zone to contention over global locks,
|
||||
** e.g. we have our own dedicated locks */
|
||||
_sqliteZone_ = malloc_create_zone(4096, 0);
|
||||
malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");
|
||||
|
|
24
third_party/sqlite3/mem2.c
vendored
24
third_party/sqlite3/mem2.c
vendored
|
@ -81,7 +81,7 @@ struct MemBlockHdr {
|
|||
** when this module is combined with other in the amalgamation.
|
||||
*/
|
||||
static struct {
|
||||
|
||||
|
||||
/*
|
||||
** Mutex to control access to the memory allocation subsystem.
|
||||
*/
|
||||
|
@ -92,7 +92,7 @@ static struct {
|
|||
*/
|
||||
struct MemBlockHdr *pFirst;
|
||||
struct MemBlockHdr *pLast;
|
||||
|
||||
|
||||
/*
|
||||
** The number of levels of backtrace to save in new allocations.
|
||||
*/
|
||||
|
@ -105,7 +105,7 @@ static struct {
|
|||
int nTitle; /* Bytes of zTitle to save. Includes '\0' and padding */
|
||||
char zTitle[100]; /* The title text */
|
||||
|
||||
/*
|
||||
/*
|
||||
** sqlite3MallocDisallow() increments the following counter.
|
||||
** sqlite3MallocAllow() decrements it.
|
||||
*/
|
||||
|
@ -164,7 +164,7 @@ static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){
|
|||
pU8 = (u8*)pAllocation;
|
||||
assert( pInt[nReserve/sizeof(int)]==(int)REARGUARD );
|
||||
/* This checks any of the "extra" bytes allocated due
|
||||
** to rounding up to an 8 byte boundary to ensure
|
||||
** to rounding up to an 8 byte boundary to ensure
|
||||
** they haven't been overwritten.
|
||||
*/
|
||||
while( nReserve-- > p->iSize ) assert( pU8[nReserve]==0x65 );
|
||||
|
@ -293,7 +293,7 @@ static void *sqlite3MemMalloc(int nByte){
|
|||
p = (void*)pInt;
|
||||
}
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
return p;
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -303,7 +303,7 @@ static void sqlite3MemFree(void *pPrior){
|
|||
struct MemBlockHdr *pHdr;
|
||||
void **pBt;
|
||||
char *z;
|
||||
assert( sqlite3GlobalConfig.bMemstat || sqlite3GlobalConfig.bCoreMutex==0
|
||||
assert( sqlite3GlobalConfig.bMemstat || sqlite3GlobalConfig.bCoreMutex==0
|
||||
|| mem.mutex!=0 );
|
||||
pHdr = sqlite3MemsysGetHeader(pPrior);
|
||||
pBt = (void**)pHdr;
|
||||
|
@ -329,15 +329,15 @@ static void sqlite3MemFree(void *pPrior){
|
|||
randomFill(z, sizeof(void*)*pHdr->nBacktraceSlots + sizeof(*pHdr) +
|
||||
(int)pHdr->iSize + sizeof(int) + pHdr->nTitle);
|
||||
free(z);
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the size of an existing memory allocation.
|
||||
**
|
||||
** For this debugging implementation, we *always* make a copy of the
|
||||
** allocation into a new place in memory. In this way, if the
|
||||
** higher level code is using pointer to the old allocation, it is
|
||||
** allocation into a new place in memory. In this way, if the
|
||||
** higher level code is using pointer to the old allocation, it is
|
||||
** much more likely to break and we are much more liking to find
|
||||
** the error.
|
||||
*/
|
||||
|
@ -471,7 +471,7 @@ void sqlite3MemdebugSync(){
|
|||
}
|
||||
|
||||
/*
|
||||
** Open the file indicated and write a log of all unfreed memory
|
||||
** Open the file indicated and write a log of all unfreed memory
|
||||
** allocations into that log.
|
||||
*/
|
||||
void sqlite3MemdebugDump(const char *zFilename){
|
||||
|
@ -488,7 +488,7 @@ void sqlite3MemdebugDump(const char *zFilename){
|
|||
for(pHdr=mem.pFirst; pHdr; pHdr=pHdr->pNext){
|
||||
char *z = (char*)pHdr;
|
||||
z -= pHdr->nBacktraceSlots*sizeof(void*) + pHdr->nTitle;
|
||||
fprintf(out, "**** %lld bytes at %p from %s ****\n",
|
||||
fprintf(out, "**** %lld bytes at %p from %s ****\n",
|
||||
pHdr->iSize, &pHdr[1], pHdr->nTitle ? z : "???");
|
||||
if( pHdr->nBacktrace ){
|
||||
fflush(out);
|
||||
|
@ -501,7 +501,7 @@ void sqlite3MemdebugDump(const char *zFilename){
|
|||
fprintf(out, "COUNTS:\n");
|
||||
for(i=0; i<NCSIZE-1; i++){
|
||||
if( mem.nAlloc[i] ){
|
||||
fprintf(out, " %5d: %10d %10d %10d\n",
|
||||
fprintf(out, " %5d: %10d %10d %10d\n",
|
||||
i*8, mem.nAlloc[i], mem.nCurrent[i], mem.mxCurrent[i]);
|
||||
}
|
||||
}
|
||||
|
|
38
third_party/sqlite3/mem3.c
vendored
38
third_party/sqlite3/mem3.c
vendored
|
@ -47,8 +47,8 @@
|
|||
#define N_HASH 61
|
||||
|
||||
/*
|
||||
** A memory allocation (also called a "chunk") consists of two or
|
||||
** more blocks where each block is 8 bytes. The first 8 bytes are
|
||||
** A memory allocation (also called a "chunk") consists of two or
|
||||
** more blocks where each block is 8 bytes. The first 8 bytes are
|
||||
** a header that is not returned to the user.
|
||||
**
|
||||
** A chunk is two or more blocks that is either checked out or
|
||||
|
@ -71,10 +71,10 @@
|
|||
**
|
||||
** The second block of free chunks is of the form u.list. The
|
||||
** two fields form a double-linked list of chunks of related sizes.
|
||||
** Pointers to the head of the list are stored in mem3.aiSmall[]
|
||||
** Pointers to the head of the list are stored in mem3.aiSmall[]
|
||||
** for smaller chunks and mem3.aiHash[] for larger chunks.
|
||||
**
|
||||
** The second block of a chunk is user data if the chunk is checked
|
||||
** The second block of a chunk is user data if the chunk is checked
|
||||
** out. If a chunk is checked out, the user data may extend into
|
||||
** the u.hdr.prevSize value of the following chunk.
|
||||
*/
|
||||
|
@ -110,12 +110,12 @@ static SQLITE_WSD struct Mem3Global {
|
|||
** True if we are evaluating an out-of-memory callback.
|
||||
*/
|
||||
int alarmBusy;
|
||||
|
||||
|
||||
/*
|
||||
** Mutex to control access to the memory allocation subsystem.
|
||||
*/
|
||||
sqlite3_mutex *mutex;
|
||||
|
||||
|
||||
/*
|
||||
** The minimum amount of free space that we have seen.
|
||||
*/
|
||||
|
@ -131,7 +131,7 @@ static SQLITE_WSD struct Mem3Global {
|
|||
u32 szKeyBlk;
|
||||
|
||||
/*
|
||||
** Array of lists of free blocks according to the block size
|
||||
** Array of lists of free blocks according to the block size
|
||||
** for smaller chunks, or a hash on the block size for larger
|
||||
** chunks.
|
||||
*/
|
||||
|
@ -162,7 +162,7 @@ static void memsys3UnlinkFromList(u32 i, u32 *pRoot){
|
|||
}
|
||||
|
||||
/*
|
||||
** Unlink the chunk at index i from
|
||||
** Unlink the chunk at index i from
|
||||
** whatever list is currently a member of.
|
||||
*/
|
||||
static void memsys3Unlink(u32 i){
|
||||
|
@ -246,8 +246,8 @@ static void memsys3OutOfMemory(int nByte){
|
|||
|
||||
|
||||
/*
|
||||
** Chunk i is a free chunk that has been unlinked. Adjust its
|
||||
** size parameters for check-out and return a pointer to the
|
||||
** Chunk i is a free chunk that has been unlinked. Adjust its
|
||||
** size parameters for check-out and return a pointer to the
|
||||
** user portion of the chunk.
|
||||
*/
|
||||
static void *memsys3Checkout(u32 i, u32 nBlock){
|
||||
|
@ -300,12 +300,12 @@ static void *memsys3FromKeyBlk(u32 nBlock){
|
|||
/*
|
||||
** *pRoot is the head of a list of free chunks of the same size
|
||||
** or same size hash. In other words, *pRoot is an entry in either
|
||||
** mem3.aiSmall[] or mem3.aiHash[].
|
||||
** mem3.aiSmall[] or mem3.aiHash[].
|
||||
**
|
||||
** This routine examines all entries on the given list and tries
|
||||
** to coalesce each entries with adjacent free chunks.
|
||||
** to coalesce each entries with adjacent free chunks.
|
||||
**
|
||||
** If it sees a chunk that is larger than mem3.iKeyBlk, it replaces
|
||||
** If it sees a chunk that is larger than mem3.iKeyBlk, it replaces
|
||||
** the current mem3.iKeyBlk with the new larger chunk. In order for
|
||||
** this mem3.iKeyBlk replacement to work, the key chunk must be
|
||||
** linked into the hash tables. That is not the normal state of
|
||||
|
@ -396,7 +396,7 @@ static void *memsys3MallocUnsafe(int nByte){
|
|||
}
|
||||
|
||||
|
||||
/* STEP 3:
|
||||
/* STEP 3:
|
||||
** Loop through the entire memory pool. Coalesce adjacent free
|
||||
** chunks. Recompute the key chunk as the largest free chunk.
|
||||
** Then try again to satisfy the allocation by carving a piece off
|
||||
|
@ -503,7 +503,7 @@ static void *memsys3Malloc(int nBytes){
|
|||
memsys3Enter();
|
||||
p = memsys3MallocUnsafe(nBytes);
|
||||
memsys3Leave();
|
||||
return (void*)p;
|
||||
return (void*)p;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -584,7 +584,7 @@ static void memsys3Shutdown(void *NotUsed){
|
|||
|
||||
|
||||
/*
|
||||
** Open the file indicated and write a log of all unfreed memory
|
||||
** Open the file indicated and write a log of all unfreed memory
|
||||
** allocations into that log.
|
||||
*/
|
||||
void sqlite3Memsys3Dump(const char *zFilename){
|
||||
|
@ -635,7 +635,7 @@ void sqlite3Memsys3Dump(const char *zFilename){
|
|||
fprintf(out, " %p(%d)", &mem3.aPool[j],
|
||||
(mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
for(i=0; i<N_HASH; i++){
|
||||
if( mem3.aiHash[i]==0 ) continue;
|
||||
|
@ -644,7 +644,7 @@ void sqlite3Memsys3Dump(const char *zFilename){
|
|||
fprintf(out, " %p(%d)", &mem3.aPool[j],
|
||||
(mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fprintf(out, "key=%d\n", mem3.iKeyBlk);
|
||||
fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szKeyBlk*8);
|
||||
|
@ -661,7 +661,7 @@ void sqlite3Memsys3Dump(const char *zFilename){
|
|||
}
|
||||
|
||||
/*
|
||||
** This routine is the only routine in this file with external
|
||||
** This routine is the only routine in this file with external
|
||||
** linkage.
|
||||
**
|
||||
** Populate the low-level memory allocation function pointers in
|
||||
|
|
18
third_party/sqlite3/mem5.c
vendored
18
third_party/sqlite3/mem5.c
vendored
|
@ -52,7 +52,7 @@
|
|||
/* clang-format off */
|
||||
|
||||
/*
|
||||
** This version of the memory allocator is used only when
|
||||
** This version of the memory allocator is used only when
|
||||
** SQLITE_ENABLE_MEMSYS5 is defined.
|
||||
*/
|
||||
#ifdef SQLITE_ENABLE_MEMSYS5
|
||||
|
@ -97,7 +97,7 @@ static SQLITE_WSD struct Mem5Global {
|
|||
int szAtom; /* Smallest possible allocation in bytes */
|
||||
int nBlock; /* Number of szAtom sized blocks in zPool */
|
||||
u8 *zPool; /* Memory available to be allocated */
|
||||
|
||||
|
||||
/*
|
||||
** Mutex to control access to the memory allocation subsystem.
|
||||
*/
|
||||
|
@ -116,7 +116,7 @@ static SQLITE_WSD struct Mem5Global {
|
|||
u32 maxCount; /* Maximum instantaneous currentCount */
|
||||
u32 maxRequest; /* Largest allocation (exclusive of internal frag) */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Lists of free blocks. aiFreelist[0] is a list of free blocks of
|
||||
** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2.
|
||||
|
@ -292,7 +292,7 @@ static void memsys5FreeUnsafe(void *pOld){
|
|||
u32 size, iLogsize;
|
||||
int iBlock;
|
||||
|
||||
/* Set iBlock to the index of the block pointed to by pOld in
|
||||
/* Set iBlock to the index of the block pointed to by pOld in
|
||||
** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
|
||||
*/
|
||||
iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom);
|
||||
|
@ -361,7 +361,7 @@ static void *memsys5Malloc(int nBytes){
|
|||
p = memsys5MallocUnsafe(nBytes);
|
||||
memsys5Leave();
|
||||
}
|
||||
return (void*)p;
|
||||
return (void*)p;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -374,14 +374,14 @@ static void memsys5Free(void *pPrior){
|
|||
assert( pPrior!=0 );
|
||||
memsys5Enter();
|
||||
memsys5FreeUnsafe(pPrior);
|
||||
memsys5Leave();
|
||||
memsys5Leave();
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the size of an existing memory allocation.
|
||||
**
|
||||
** The outer layer memory allocator prevents this routine from
|
||||
** being called with pPrior==0.
|
||||
** being called with pPrior==0.
|
||||
**
|
||||
** nBytes is always a value obtained from a prior call to
|
||||
** memsys5Round(). Hence nBytes is always a non-negative power
|
||||
|
@ -514,7 +514,7 @@ static void memsys5Shutdown(void *NotUsed){
|
|||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** Open the file indicated and write a log of all unfreed memory
|
||||
** Open the file indicated and write a log of all unfreed memory
|
||||
** allocations into that log.
|
||||
*/
|
||||
void sqlite3Memsys5Dump(const char *zFilename){
|
||||
|
@ -556,7 +556,7 @@ void sqlite3Memsys5Dump(const char *zFilename){
|
|||
#endif
|
||||
|
||||
/*
|
||||
** This routine is the only routine in this file with external
|
||||
** This routine is the only routine in this file with external
|
||||
** linkage. It returns a pointer to a static sqlite3_mem_methods
|
||||
** struct populated with the memsys5 methods.
|
||||
*/
|
||||
|
|
40
third_party/sqlite3/memdb.c
vendored
40
third_party/sqlite3/memdb.c
vendored
|
@ -83,7 +83,7 @@ static sqlite3_vfs memdb_vfs = {
|
|||
1024, /* mxPathname */
|
||||
0, /* pNext */
|
||||
"memdb", /* zName */
|
||||
0, /* pAppData (set when registered) */
|
||||
0, /* pAppData (set when registered) */
|
||||
memdbOpen, /* xOpen */
|
||||
0, /* memdbDelete, */ /* xDelete */
|
||||
memdbAccess, /* xAccess */
|
||||
|
@ -108,7 +108,7 @@ static const sqlite3_io_methods memdb_io_methods = {
|
|||
memdbSync, /* xSync */
|
||||
memdbFileSize, /* xFileSize */
|
||||
memdbLock, /* xLock */
|
||||
memdbLock, /* xUnlock - same as xLock in this case */
|
||||
memdbLock, /* xUnlock - same as xLock in this case */
|
||||
0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
|
||||
memdbFileControl, /* xFileControl */
|
||||
0, /* memdbSectorSize,*/ /* xSectorSize */
|
||||
|
@ -142,9 +142,9 @@ static int memdbClose(sqlite3_file *pFile){
|
|||
** Read data from an memdb-file.
|
||||
*/
|
||||
static int memdbRead(
|
||||
sqlite3_file *pFile,
|
||||
void *zBuf,
|
||||
int iAmt,
|
||||
sqlite3_file *pFile,
|
||||
void *zBuf,
|
||||
int iAmt,
|
||||
sqlite_int64 iOfst
|
||||
){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
|
@ -212,7 +212,7 @@ static int memdbWrite(
|
|||
static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
if( NEVER(size>p->sz) ) return SQLITE_FULL;
|
||||
p->sz = size;
|
||||
p->sz = size;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
|
|||
*/
|
||||
static int memdbLock(sqlite3_file *pFile, int eLock){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
if( eLock>SQLITE_LOCK_SHARED
|
||||
if( eLock>SQLITE_LOCK_SHARED
|
||||
&& (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
|
||||
){
|
||||
return SQLITE_READONLY;
|
||||
|
@ -295,7 +295,7 @@ static int memdbSectorSize(sqlite3_file *pFile){
|
|||
** Return the device characteristic flags supported by an memdb-file.
|
||||
*/
|
||||
static int memdbDeviceCharacteristics(sqlite3_file *pFile){
|
||||
return SQLITE_IOCAP_ATOMIC |
|
||||
return SQLITE_IOCAP_ATOMIC |
|
||||
SQLITE_IOCAP_POWERSAFE_OVERWRITE |
|
||||
SQLITE_IOCAP_SAFE_APPEND |
|
||||
SQLITE_IOCAP_SEQUENTIAL;
|
||||
|
@ -367,9 +367,9 @@ static int memdbDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
|
|||
** With memdb, no files ever exist on disk. So always return false.
|
||||
*/
|
||||
static int memdbAccess(
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int flags,
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int flags,
|
||||
int *pResOut
|
||||
){
|
||||
*pResOut = 0;
|
||||
|
@ -382,9 +382,9 @@ static int memdbAccess(
|
|||
** of at least (INST_MAX_PATHNAME+1) bytes.
|
||||
*/
|
||||
static int memdbFullPathname(
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int nOut,
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int nOut,
|
||||
char *zOut
|
||||
){
|
||||
sqlite3_snprintf(nOut, zOut, "%s", zPath);
|
||||
|
@ -400,7 +400,7 @@ static void *memdbDlOpen(sqlite3_vfs *pVfs, const char *zPath){
|
|||
|
||||
/*
|
||||
** Populate the buffer zErrMsg (size nByte bytes) with a human readable
|
||||
** utf-8 string describing the most recent error encountered associated
|
||||
** utf-8 string describing the most recent error encountered associated
|
||||
** with dynamic libraries.
|
||||
*/
|
||||
static void memdbDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
|
||||
|
@ -422,7 +422,7 @@ static void memdbDlClose(sqlite3_vfs *pVfs, void *pHandle){
|
|||
}
|
||||
|
||||
/*
|
||||
** Populate the buffer pointed to by zBufOut with nByte bytes of
|
||||
** Populate the buffer pointed to by zBufOut with nByte bytes of
|
||||
** random data.
|
||||
*/
|
||||
static int memdbRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
|
||||
|
@ -430,7 +430,7 @@ static int memdbRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
|
|||
}
|
||||
|
||||
/*
|
||||
** Sleep for nMicro microseconds. Return the number of microseconds
|
||||
** Sleep for nMicro microseconds. Return the number of microseconds
|
||||
** actually slept.
|
||||
*/
|
||||
static int memdbSleep(sqlite3_vfs *pVfs, int nMicro){
|
||||
|
@ -536,7 +536,7 @@ unsigned char *sqlite3_serialize(
|
|||
}else{
|
||||
memset(pTo, 0, szPage);
|
||||
}
|
||||
sqlite3PagerUnref(pPage);
|
||||
sqlite3PagerUnref(pPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ int sqlite3_deserialize(
|
|||
if( iDb<0 ){
|
||||
rc = SQLITE_ERROR;
|
||||
goto end_deserialize;
|
||||
}
|
||||
}
|
||||
zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema);
|
||||
if( zSql==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
|
@ -617,7 +617,7 @@ end_deserialize:
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** This routine is called when the extension is loaded.
|
||||
** Register the new VFS.
|
||||
*/
|
||||
|
|
24
third_party/sqlite3/memjournal.c
vendored
24
third_party/sqlite3/memjournal.c
vendored
|
@ -102,7 +102,7 @@ static int memjrnlRead(
|
|||
assert( p->readpoint.iOffset==0 || p->readpoint.pChunk!=0 );
|
||||
if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
|
||||
sqlite3_int64 iOff = 0;
|
||||
for(pChunk=p->pFirst;
|
||||
for(pChunk=p->pFirst;
|
||||
ALWAYS(pChunk) && (iOff+p->nChunkSize)<=iOfst;
|
||||
pChunk=pChunk->pNext
|
||||
){
|
||||
|
@ -137,7 +137,7 @@ static void memjrnlFreeChunks(FileChunk *pFirst){
|
|||
for(pIter=pFirst; pIter; pIter=pNext){
|
||||
pNext = pIter->pNext;
|
||||
sqlite3_free(pIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -208,7 +208,7 @@ static int memjrnlWrite(
|
|||
** access writes are not required. The only exception to this is when
|
||||
** the in-memory journal is being used by a connection using the
|
||||
** atomic-write optimization. In this case the first 28 bytes of the
|
||||
** journal file may be written as part of committing the transaction. */
|
||||
** journal file may be written as part of committing the transaction. */
|
||||
assert( iOfst==p->endpoint.iOffset || iOfst==0 );
|
||||
#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
|
||||
|| defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
|
||||
|
@ -293,8 +293,8 @@ static int memjrnlClose(sqlite3_file *pJfd){
|
|||
/*
|
||||
** Sync the file.
|
||||
**
|
||||
** If the real file has been created, call its xSync method. Otherwise,
|
||||
** syncing an in-memory journal is a no-op.
|
||||
** If the real file has been created, call its xSync method. Otherwise,
|
||||
** syncing an in-memory journal is a no-op.
|
||||
*/
|
||||
static int memjrnlSync(sqlite3_file *pJfd, int flags){
|
||||
UNUSED_PARAMETER2(pJfd, flags);
|
||||
|
@ -335,11 +335,11 @@ static const struct sqlite3_io_methods MemJournalMethods = {
|
|||
0 /* xUnfetch */
|
||||
};
|
||||
|
||||
/*
|
||||
** Open a journal file.
|
||||
/*
|
||||
** Open a journal file.
|
||||
**
|
||||
** The behaviour of the journal file depends on the value of parameter
|
||||
** nSpill. If nSpill is 0, then the journal file is always create and
|
||||
** The behaviour of the journal file depends on the value of parameter
|
||||
** nSpill. If nSpill is 0, then the journal file is always create and
|
||||
** accessed using the underlying VFS. If nSpill is less than zero, then
|
||||
** all content is always stored in main-memory. Finally, if nSpill is a
|
||||
** positive value, then the journal file is initially created in-memory
|
||||
|
@ -390,9 +390,9 @@ void sqlite3MemJournalOpen(sqlite3_file *pJfd){
|
|||
#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
|
||||
|| defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
|
||||
/*
|
||||
** If the argument p points to a MemJournal structure that is not an
|
||||
** If the argument p points to a MemJournal structure that is not an
|
||||
** in-memory-only journal file (i.e. is one that was opened with a +ve
|
||||
** nSpill parameter or as SQLITE_OPEN_MAIN_JOURNAL), and the underlying
|
||||
** nSpill parameter or as SQLITE_OPEN_MAIN_JOURNAL), and the underlying
|
||||
** file has not yet been created, create it now.
|
||||
*/
|
||||
int sqlite3JournalCreate(sqlite3_file *pJfd){
|
||||
|
@ -426,7 +426,7 @@ int sqlite3JournalIsInMemory(sqlite3_file *p){
|
|||
return p->pMethods==&MemJournalMethods;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Return the number of bytes required to store a JournalFile that uses vfs
|
||||
** pVfs to create the underlying on-disk files.
|
||||
*/
|
||||
|
|
2
third_party/sqlite3/memtrace.c
vendored
2
third_party/sqlite3/memtrace.c
vendored
|
@ -34,7 +34,7 @@ static FILE *memtraceOut;
|
|||
/* Methods that trace memory allocations */
|
||||
static void *memtraceMalloc(int n){
|
||||
if( memtraceOut ){
|
||||
fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
|
||||
fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
|
||||
memtraceBase.xRoundup(n));
|
||||
}
|
||||
return memtraceBase.xMalloc(n);
|
||||
|
|
24
third_party/sqlite3/mutex.c
vendored
24
third_party/sqlite3/mutex.c
vendored
|
@ -32,7 +32,7 @@ static SQLITE_WSD int mutexIsInit = 0;
|
|||
/*
|
||||
** This block (enclosed by SQLITE_ENABLE_MULTITHREADED_CHECKS) contains
|
||||
** the implementation of a wrapper around the system default mutex
|
||||
** implementation (sqlite3DefaultMutex()).
|
||||
** implementation (sqlite3DefaultMutex()).
|
||||
**
|
||||
** Most calls are passed directly through to the underlying default
|
||||
** mutex implementation. Except, if a mutex is configured by calling
|
||||
|
@ -43,7 +43,7 @@ static SQLITE_WSD int mutexIsInit = 0;
|
|||
** apps that usually use SQLITE_CONFIG_MULTITHREAD mode.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
** Type for all mutexes used when SQLITE_ENABLE_MULTITHREADED_CHECKS
|
||||
** is defined. Variable CheckMutex.mutex is a pointer to the real mutex
|
||||
** allocated by the system mutex implementation. Variable iType is usually set
|
||||
|
@ -60,9 +60,9 @@ struct CheckMutex {
|
|||
|
||||
#define SQLITE_MUTEX_WARNONCONTENTION (-1)
|
||||
|
||||
/*
|
||||
/*
|
||||
** Pointer to real mutex methods object used by the CheckMutex
|
||||
** implementation. Set by checkMutexInit().
|
||||
** implementation. Set by checkMutexInit().
|
||||
*/
|
||||
static SQLITE_WSD const sqlite3_mutex_methods *pGlobalMutexMethods;
|
||||
|
||||
|
@ -78,13 +78,13 @@ static int checkMutexNotheld(sqlite3_mutex *p){
|
|||
/*
|
||||
** Initialize and deinitialize the mutex subsystem.
|
||||
*/
|
||||
static int checkMutexInit(void){
|
||||
static int checkMutexInit(void){
|
||||
pGlobalMutexMethods = sqlite3DefaultMutex();
|
||||
return SQLITE_OK;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int checkMutexEnd(void){
|
||||
static int checkMutexEnd(void){
|
||||
pGlobalMutexMethods = 0;
|
||||
return SQLITE_OK;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -158,7 +158,7 @@ static void checkMutexEnter(sqlite3_mutex *p){
|
|||
if( SQLITE_OK==pGlobalMutexMethods->xMutexTry(pCheck->mutex) ){
|
||||
return;
|
||||
}
|
||||
sqlite3_log(SQLITE_MISUSE,
|
||||
sqlite3_log(SQLITE_MISUSE,
|
||||
"illegal multi-threaded access to database connection"
|
||||
);
|
||||
}
|
||||
|
@ -217,11 +217,11 @@ void sqlite3MutexWarnOnContention(sqlite3_mutex *p){
|
|||
/*
|
||||
** Initialize the mutex system.
|
||||
*/
|
||||
int sqlite3MutexInit(void){
|
||||
int sqlite3MutexInit(void){
|
||||
int rc = SQLITE_OK;
|
||||
if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
|
||||
/* If the xMutexAlloc method has not been set, then the user did not
|
||||
** install a mutex implementation via sqlite3_config() prior to
|
||||
** install a mutex implementation via sqlite3_config() prior to
|
||||
** sqlite3_initialize() being called. This block copies pointers to
|
||||
** the default implementation into the sqlite3GlobalConfig structure.
|
||||
*/
|
||||
|
@ -333,7 +333,7 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
|
|||
|
||||
/*
|
||||
** The sqlite3_mutex_leave() routine exits a mutex that was previously
|
||||
** entered by the same thread. The behavior is undefined if the mutex
|
||||
** entered by the same thread. The behavior is undefined if the mutex
|
||||
** is not currently entered. If a NULL pointer is passed as an argument
|
||||
** this function is a no-op.
|
||||
*/
|
||||
|
|
4
third_party/sqlite3/mutex.inc
vendored
4
third_party/sqlite3/mutex.inc
vendored
|
@ -57,9 +57,9 @@
|
|||
*/
|
||||
#define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
|
||||
#define sqlite3_mutex_free(X)
|
||||
#define sqlite3_mutex_enter(X)
|
||||
#define sqlite3_mutex_enter(X)
|
||||
#define sqlite3_mutex_try(X) SQLITE_OK
|
||||
#define sqlite3_mutex_leave(X)
|
||||
#define sqlite3_mutex_leave(X)
|
||||
#define sqlite3_mutex_held(X) ((void)(X),1)
|
||||
#define sqlite3_mutex_notheld(X) ((void)(X),1)
|
||||
#define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
|
||||
|
|
6
third_party/sqlite3/mutex_noop.c
vendored
6
third_party/sqlite3/mutex_noop.c
vendored
|
@ -38,9 +38,9 @@
|
|||
*/
|
||||
static int noopMutexInit(void){ return SQLITE_OK; }
|
||||
static int noopMutexEnd(void){ return SQLITE_OK; }
|
||||
static sqlite3_mutex *noopMutexAlloc(int id){
|
||||
static sqlite3_mutex *noopMutexAlloc(int id){
|
||||
UNUSED_PARAMETER(id);
|
||||
return (sqlite3_mutex*)8;
|
||||
return (sqlite3_mutex*)8;
|
||||
}
|
||||
static void noopMutexFree(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; }
|
||||
static void noopMutexEnter(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; }
|
||||
|
@ -105,7 +105,7 @@ static int debugMutexEnd(void){ return SQLITE_OK; }
|
|||
/*
|
||||
** The sqlite3_mutex_alloc() routine allocates a new
|
||||
** mutex and returns a pointer to it. If it returns NULL
|
||||
** that means that a mutex could not be allocated.
|
||||
** that means that a mutex could not be allocated.
|
||||
*/
|
||||
static sqlite3_mutex *debugMutexAlloc(int id){
|
||||
static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_VFS3 - 1];
|
||||
|
|
8
third_party/sqlite3/mutex_unix.c
vendored
8
third_party/sqlite3/mutex_unix.c
vendored
|
@ -65,7 +65,7 @@ struct sqlite3_mutex {
|
|||
** there might be race conditions that can cause these routines to
|
||||
** deliver incorrect results. In particular, if pthread_equal() is
|
||||
** not an atomic operation, then these routines might delivery
|
||||
** incorrect results. On most platforms, pthread_equal() is a
|
||||
** incorrect results. On most platforms, pthread_equal() is a
|
||||
** comparison of two integers and is therefore atomic. But we are
|
||||
** told that HPUX is not such a platform. If so, then these routines
|
||||
** will not always work correctly on HPUX.
|
||||
|
@ -147,7 +147,7 @@ static int pthreadMutexEnd(void){ return SQLITE_OK; }
|
|||
**
|
||||
** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
|
||||
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
|
||||
** returns a different mutex on every call. But for the static
|
||||
** returns a different mutex on every call. But for the static
|
||||
** mutex types, the same mutex is returned on every call that has
|
||||
** the same type number.
|
||||
*/
|
||||
|
@ -258,7 +258,7 @@ static void pthreadMutexEnter(sqlite3_mutex *p){
|
|||
** is atomic - that it cannot be deceived into thinking self
|
||||
** and p->owner are equal if p->owner changes between two values
|
||||
** that are not equal to self while the comparison is taking place.
|
||||
** This implementation also assumes a coherent cache - that
|
||||
** This implementation also assumes a coherent cache - that
|
||||
** separate processes cannot read different values from the same
|
||||
** address at the same time. If either of these two conditions
|
||||
** are not met, then the mutexes will fail and problems will result.
|
||||
|
@ -301,7 +301,7 @@ static int pthreadMutexTry(sqlite3_mutex *p){
|
|||
** is atomic - that it cannot be deceived into thinking self
|
||||
** and p->owner are equal if p->owner changes between two values
|
||||
** that are not equal to self while the comparison is taking place.
|
||||
** This implementation also assumes a coherent cache - that
|
||||
** This implementation also assumes a coherent cache - that
|
||||
** separate processes cannot read different values from the same
|
||||
** address at the same time. If either of these two conditions
|
||||
** are not met, then the mutexes will fail and problems will result.
|
||||
|
|
28
third_party/sqlite3/notify.c
vendored
28
third_party/sqlite3/notify.c
vendored
|
@ -42,13 +42,13 @@ static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0;
|
|||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
** This function is a complex assert() that verifies the following
|
||||
** This function is a complex assert() that verifies the following
|
||||
** properties of the blocked connections list:
|
||||
**
|
||||
** 1) Each entry in the list has a non-NULL value for either
|
||||
** 1) Each entry in the list has a non-NULL value for either
|
||||
** pUnlockConnection or pBlockingConnection, or both.
|
||||
**
|
||||
** 2) All entries in the list that share a common value for
|
||||
** 2) All entries in the list that share a common value for
|
||||
** xUnlockNotify are grouped together.
|
||||
**
|
||||
** 3) If the argument db is not NULL, then none of the entries in the
|
||||
|
@ -100,8 +100,8 @@ static void addToBlockedList(sqlite3 *db){
|
|||
sqlite3 **pp;
|
||||
assertMutexHeld();
|
||||
for(
|
||||
pp=&sqlite3BlockedList;
|
||||
*pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
|
||||
pp=&sqlite3BlockedList;
|
||||
*pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
|
||||
pp=&(*pp)->pNextBlocked
|
||||
);
|
||||
db->pNextBlocked = *pp;
|
||||
|
@ -163,9 +163,9 @@ int sqlite3_unlock_notify(
|
|||
db->xUnlockNotify = 0;
|
||||
db->pUnlockArg = 0;
|
||||
}else if( 0==db->pBlockingConnection ){
|
||||
/* The blocking transaction has been concluded. Or there never was a
|
||||
/* The blocking transaction has been concluded. Or there never was a
|
||||
** blocking transaction. In either case, invoke the notify callback
|
||||
** immediately.
|
||||
** immediately.
|
||||
*/
|
||||
xNotify(&pArg, 1);
|
||||
}else{
|
||||
|
@ -191,7 +191,7 @@ int sqlite3_unlock_notify(
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is called while stepping or preparing a statement
|
||||
** This function is called while stepping or preparing a statement
|
||||
** associated with connection db. The operation will return SQLITE_LOCKED
|
||||
** to the user because it requires a lock that will not be available
|
||||
** until connection pBlocker concludes its current transaction.
|
||||
|
@ -207,7 +207,7 @@ void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
|
|||
|
||||
/*
|
||||
** This function is called when
|
||||
** the transaction opened by database db has just finished. Locks held
|
||||
** the transaction opened by database db has just finished. Locks held
|
||||
** by database connection db have been released.
|
||||
**
|
||||
** This function loops through each entry in the blocked connections
|
||||
|
@ -267,7 +267,7 @@ void sqlite3ConnectionUnlocked(sqlite3 *db){
|
|||
}else{
|
||||
/* This occurs when the array of context pointers that need to
|
||||
** be passed to the unlock-notify callback is larger than the
|
||||
** aStatic[] array allocated on the stack and the attempt to
|
||||
** aStatic[] array allocated on the stack and the attempt to
|
||||
** allocate a larger array from the heap has failed.
|
||||
**
|
||||
** This is a difficult situation to handle. Returning an error
|
||||
|
@ -275,17 +275,17 @@ void sqlite3ConnectionUnlocked(sqlite3 *db){
|
|||
** is returned the transaction on connection db will still be
|
||||
** closed and the unlock-notify callbacks on blocked connections
|
||||
** will go unissued. This might cause the application to wait
|
||||
** indefinitely for an unlock-notify callback that will never
|
||||
** indefinitely for an unlock-notify callback that will never
|
||||
** arrive.
|
||||
**
|
||||
** Instead, invoke the unlock-notify callback with the context
|
||||
** array already accumulated. We can then clear the array and
|
||||
** begin accumulating any further context pointers without
|
||||
** begin accumulating any further context pointers without
|
||||
** requiring any dynamic allocation. This is sub-optimal because
|
||||
** it means that instead of one callback with a large array of
|
||||
** context pointers the application will receive two or more
|
||||
** callbacks with smaller arrays of context pointers, which will
|
||||
** reduce the applications ability to prioritize multiple
|
||||
** reduce the applications ability to prioritize multiple
|
||||
** connections. But it is the best that can be done under the
|
||||
** circumstances.
|
||||
*/
|
||||
|
@ -320,7 +320,7 @@ void sqlite3ConnectionUnlocked(sqlite3 *db){
|
|||
}
|
||||
|
||||
/*
|
||||
** This is called when the database connection passed as an argument is
|
||||
** This is called when the database connection passed as an argument is
|
||||
** being closed. The connection is removed from the blocked list.
|
||||
*/
|
||||
void sqlite3ConnectionClosed(sqlite3 *db){
|
||||
|
|
2
third_party/sqlite3/os.c
vendored
2
third_party/sqlite3/os.c
vendored
|
@ -274,7 +274,7 @@ int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
|
|||
}else{
|
||||
return pVfs->xRandomness(pVfs, nByte, zBufOut);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
|
||||
return pVfs->xSleep(pVfs, nMicro);
|
||||
|
|
24
third_party/sqlite3/os.inc
vendored
24
third_party/sqlite3/os.inc
vendored
|
@ -53,10 +53,10 @@
|
|||
** 2006-10-31: The default prefix used to be "sqlite_". But then
|
||||
** Mcafee started using SQLite in their anti-virus product and it
|
||||
** started putting files with the "sqlite" name in the c:/temp folder.
|
||||
** This annoyed many windows users. Those users would then do a
|
||||
** This annoyed many windows users. Those users would then do a
|
||||
** Google search for "sqlite", find the telephone numbers of the
|
||||
** developers and call to wake them up at night and complain.
|
||||
** For this reason, the default name prefix is changed to be "sqlite"
|
||||
** For this reason, the default name prefix is changed to be "sqlite"
|
||||
** spelled backwards. So the temp files are still identified, but
|
||||
** anybody smart enough to figure out the code is also likely smart
|
||||
** enough to know that calling the developer will not help get rid
|
||||
|
@ -97,9 +97,9 @@
|
|||
** UnlockFile().
|
||||
**
|
||||
** LockFile() prevents not just writing but also reading by other processes.
|
||||
** A SHARED_LOCK is obtained by locking a single randomly-chosen
|
||||
** byte out of a specific range of bytes. The lock byte is obtained at
|
||||
** random so two separate readers can probably access the file at the
|
||||
** A SHARED_LOCK is obtained by locking a single randomly-chosen
|
||||
** byte out of a specific range of bytes. The lock byte is obtained at
|
||||
** random so two separate readers can probably access the file at the
|
||||
** same time, unless they are unlucky and choose the same lock byte.
|
||||
** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
|
||||
** There can only be one writer. A RESERVED_LOCK is obtained by locking
|
||||
|
@ -118,7 +118,7 @@
|
|||
** The following #defines specify the range of bytes used for locking.
|
||||
** SHARED_SIZE is the number of bytes available in the pool from which
|
||||
** a random byte is selected for a shared lock. The pool of bytes for
|
||||
** shared locks begins at SHARED_FIRST.
|
||||
** shared locks begins at SHARED_FIRST.
|
||||
**
|
||||
** The same locking strategy and
|
||||
** byte ranges are used for Unix. This leaves open the possibility of having
|
||||
|
@ -134,7 +134,7 @@
|
|||
** that all locks will fit on a single page even at the minimum page size.
|
||||
** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
|
||||
** is set high so that we don't have to allocate an unused page except
|
||||
** for very large databases. But one should test the page skipping logic
|
||||
** for very large databases. But one should test the page skipping logic
|
||||
** by setting PENDING_BYTE low and running the entire regression suite.
|
||||
**
|
||||
** Changing the value of PENDING_BYTE results in a subtly incompatible
|
||||
|
@ -158,8 +158,8 @@
|
|||
*/
|
||||
int sqlite3OsInit(void);
|
||||
|
||||
/*
|
||||
** Functions for accessing sqlite3_file methods
|
||||
/*
|
||||
** Functions for accessing sqlite3_file methods
|
||||
*/
|
||||
void sqlite3OsClose(sqlite3_file*);
|
||||
int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
|
||||
|
@ -185,8 +185,8 @@ int sqlite3OsFetch(sqlite3_file *id, i64, int, void **);
|
|||
int sqlite3OsUnfetch(sqlite3_file *, i64, void *);
|
||||
|
||||
|
||||
/*
|
||||
** Functions for accessing sqlite3_vfs methods
|
||||
/*
|
||||
** Functions for accessing sqlite3_vfs methods
|
||||
*/
|
||||
int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
|
||||
int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
|
||||
|
@ -204,7 +204,7 @@ int sqlite3OsGetLastError(sqlite3_vfs*);
|
|||
int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
|
||||
|
||||
/*
|
||||
** Convenience functions for opening and closing files using
|
||||
** Convenience functions for opening and closing files using
|
||||
** sqlite3_malloc() to obtain space for the file-handle structure.
|
||||
*/
|
||||
int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
|
||||
|
|
676
third_party/sqlite3/os_unix.c
vendored
676
third_party/sqlite3/os_unix.c
vendored
File diff suppressed because it is too large
Load diff
2
third_party/sqlite3/os_win.c
vendored
2
third_party/sqlite3/os_win.c
vendored
|
@ -5272,7 +5272,7 @@ static int winOpen(
|
|||
pFile->ctrlFlags |= WINFILE_RDONLY;
|
||||
}
|
||||
if( (flags & SQLITE_OPEN_MAIN_DB)
|
||||
&& sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE)
|
||||
&& sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE)
|
||||
){
|
||||
pFile->ctrlFlags |= WINFILE_PSOW;
|
||||
}
|
||||
|
|
1080
third_party/sqlite3/pager.c
vendored
1080
third_party/sqlite3/pager.c
vendored
File diff suppressed because it is too large
Load diff
18
third_party/sqlite3/pager.inc
vendored
18
third_party/sqlite3/pager.inc
vendored
|
@ -19,8 +19,8 @@
|
|||
#define SQLITE_PAGER_H
|
||||
|
||||
/*
|
||||
** Default maximum size for persistent journal files. A negative
|
||||
** value means no limit. This value may be overridden using the
|
||||
** Default maximum size for persistent journal files. A negative
|
||||
** value means no limit. This value may be overridden using the
|
||||
** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
|
||||
*/
|
||||
#ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
|
||||
|
@ -46,9 +46,9 @@ typedef struct PgHdr DbPage;
|
|||
/*
|
||||
** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
|
||||
** reserved for working around a windows/posix incompatibility). It is
|
||||
** used in the journal to signify that the remainder of the journal file
|
||||
** used in the journal to signify that the remainder of the journal file
|
||||
** is devoted to storing a super-journal name - there are no more pages to
|
||||
** roll back. See comments for function writeSuperJournal() in pager.c
|
||||
** roll back. See comments for function writeSuperJournal() in pager.c
|
||||
** for details.
|
||||
*/
|
||||
#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
|
||||
|
@ -109,11 +109,11 @@ typedef struct PgHdr DbPage;
|
|||
|
||||
/*
|
||||
** The remainder of this file contains the declarations of the functions
|
||||
** that make up the Pager sub-system API. See source code comments for
|
||||
** that make up the Pager sub-system API. See source code comments for
|
||||
** a detailed description of each routine.
|
||||
*/
|
||||
|
||||
/* Open and close a Pager connection. */
|
||||
/* Open and close a Pager connection. */
|
||||
int sqlite3PagerOpen(
|
||||
sqlite3_vfs*,
|
||||
Pager **ppPager,
|
||||
|
@ -143,7 +143,7 @@ i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
|
|||
sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
|
||||
int sqlite3PagerFlush(Pager*);
|
||||
|
||||
/* Functions used to obtain and release page references. */
|
||||
/* Functions used to obtain and release page references. */
|
||||
int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
|
||||
DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
|
||||
void sqlite3PagerRef(DbPage*);
|
||||
|
@ -156,8 +156,8 @@ int sqlite3PagerWrite(DbPage*);
|
|||
void sqlite3PagerDontWrite(DbPage*);
|
||||
int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
|
||||
int sqlite3PagerPageRefcount(DbPage*);
|
||||
void *sqlite3PagerGetData(DbPage *);
|
||||
void *sqlite3PagerGetExtra(DbPage *);
|
||||
void *sqlite3PagerGetData(DbPage *);
|
||||
void *sqlite3PagerGetExtra(DbPage *);
|
||||
|
||||
/* Functions used to manage pager transactions and savepoints. */
|
||||
void sqlite3PagerPagecount(Pager*, int*);
|
||||
|
|
58
third_party/sqlite3/parse.c
vendored
58
third_party/sqlite3/parse.c
vendored
|
@ -122,7 +122,7 @@ static void updateDeleteLimitError(
|
|||
pNext = pLoop;
|
||||
pLoop = pLoop->pPrior;
|
||||
if( pLoop==0 ) break;
|
||||
cnt++;
|
||||
cnt++;
|
||||
if( pLoop->pOrderBy || pLoop->pLimit ){
|
||||
sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
|
||||
pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT",
|
||||
|
@ -130,7 +130,7 @@ static void updateDeleteLimitError(
|
|||
break;
|
||||
}
|
||||
}
|
||||
if( (p->selFlags & SF_MultiValue)==0 &&
|
||||
if( (p->selFlags & SF_MultiValue)==0 &&
|
||||
(mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
|
||||
cnt>mxSelect
|
||||
){
|
||||
|
@ -181,7 +181,7 @@ static void updateDeleteLimitError(
|
|||
}
|
||||
#if SQLITE_MAX_EXPR_DEPTH>0
|
||||
p->nHeight = 1;
|
||||
#endif
|
||||
#endif
|
||||
if( IN_RENAME_OBJECT ){
|
||||
return (Expr*)sqlite3RenameTokenMap(pParse, (void*)p, &t);
|
||||
}
|
||||
|
@ -439,7 +439,7 @@ static void updateDeleteLimitError(
|
|||
** the minor type might be the name of the identifier.
|
||||
** Each non-terminal can have a different minor type.
|
||||
** Terminal symbols all have the same minor type, though.
|
||||
** This macros defines the minor type for terminal
|
||||
** This macros defines the minor type for terminal
|
||||
** symbols.
|
||||
** YYMINORTYPE is the data type used for all minor types.
|
||||
** This is typically a union of many types, one of
|
||||
|
@ -541,7 +541,7 @@ typedef union {
|
|||
/* Next are the tables used to determine what action to take based on the
|
||||
** current state and lookahead token. These tables are used to implement
|
||||
** functions that take a state number and lookahead value and return an
|
||||
** action integer.
|
||||
** action integer.
|
||||
**
|
||||
** Suppose the action integer is N. Then the action is determined as
|
||||
** follows
|
||||
|
@ -1185,9 +1185,9 @@ static const YYACTIONTYPE yy_default[] = {
|
|||
};
|
||||
/********** End of lemon-generated parsing tables *****************************/
|
||||
|
||||
/* The next table maps tokens (terminal symbols) into fallback tokens.
|
||||
/* The next table maps tokens (terminal symbols) into fallback tokens.
|
||||
** If a construct like the following:
|
||||
**
|
||||
**
|
||||
** %fallback ID X Y Z.
|
||||
**
|
||||
** appears in the grammar, then ID becomes a fallback token for X, Y,
|
||||
|
@ -1443,10 +1443,10 @@ static char *yyTracePrompt = 0;
|
|||
#endif /* NDEBUG */
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
/*
|
||||
** Turn parser tracing on by giving a stream to which to write the trace
|
||||
** and a prompt to preface each trace message. Tracing is turned off
|
||||
** by making either argument NULL
|
||||
** by making either argument NULL
|
||||
**
|
||||
** Inputs:
|
||||
** <ul>
|
||||
|
@ -1471,7 +1471,7 @@ void sqlite3ParserTrace(FILE *TraceFILE, char *zTracePrompt){
|
|||
#if defined(YYCOVERAGE) || !defined(NDEBUG)
|
||||
/* For tracing shifts, the names of all terminals and nonterminals
|
||||
** are required. The following table supplies these names */
|
||||
static const char *const yyTokenName[] = {
|
||||
static const char *const yyTokenName[] = {
|
||||
/* 0 */ "$",
|
||||
/* 1 */ "SEMI",
|
||||
/* 2 */ "EXPLAIN",
|
||||
|
@ -2226,7 +2226,7 @@ static int yyGrowStack(yyParser *p){
|
|||
#endif
|
||||
p->yystksz = newSize;
|
||||
}
|
||||
return pNew==0;
|
||||
return pNew==0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2268,7 +2268,7 @@ void sqlite3ParserInit(void *yypRawParser sqlite3ParserCTX_PDECL){
|
|||
}
|
||||
|
||||
#ifndef sqlite3Parser_ENGINEALWAYSONSTACK
|
||||
/*
|
||||
/*
|
||||
** This function allocates a new parser.
|
||||
** The only argument is a pointer to a function which works like
|
||||
** malloc.
|
||||
|
@ -2295,7 +2295,7 @@ void *sqlite3ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) sqlite3ParserCTX_P
|
|||
/* The following function deletes the "minor type" or semantic value
|
||||
** associated with a symbol. The symbol can be either a terminal
|
||||
** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
|
||||
** a pointer to the value to be deleted. The code used to do the
|
||||
** a pointer to the value to be deleted. The code used to do the
|
||||
** deletions is derived from the %destructor and/or %token_destructor
|
||||
** directives of the input grammar.
|
||||
*/
|
||||
|
@ -2310,7 +2310,7 @@ static void yy_destructor(
|
|||
/* Here is inserted the actions which take place when a
|
||||
** terminal or non-terminal is destroyed. This can happen
|
||||
** when the symbol is popped from the stack during a
|
||||
** reduce or during error processing or when a parser is
|
||||
** reduce or during error processing or when a parser is
|
||||
** being destroyed before it is finished parsing.
|
||||
**
|
||||
** Note: during a reduce, the only symbols destroyed are those
|
||||
|
@ -2460,7 +2460,7 @@ void sqlite3ParserFinalize(void *p){
|
|||
}
|
||||
|
||||
#ifndef sqlite3Parser_ENGINEALWAYSONSTACK
|
||||
/*
|
||||
/*
|
||||
** Deallocate and destroy a parser. Destructors are called for
|
||||
** all stack elements before shutting the parser down.
|
||||
**
|
||||
|
@ -2682,7 +2682,7 @@ static void yy_shift(
|
|||
assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
|
||||
}
|
||||
#endif
|
||||
#if YYSTACKDEPTH>0
|
||||
#if YYSTACKDEPTH>0
|
||||
if( yypParser->yytos>yypParser->yystackEnd ){
|
||||
yypParser->yytos--;
|
||||
yyStackOverflow(yypParser);
|
||||
|
@ -4053,7 +4053,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
}
|
||||
break;
|
||||
case 118: /* xfullname ::= nm AS nm */
|
||||
{
|
||||
{
|
||||
yymsp[-2].minor.yy291 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
|
||||
if( yymsp[-2].minor.yy291 ) yymsp[-2].minor.yy291->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
|
||||
}
|
||||
|
@ -4157,7 +4157,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
case 155: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */
|
||||
{
|
||||
sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy291, &yymsp[-4].minor.yy0);
|
||||
sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy338,"set list");
|
||||
sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy338,"set list");
|
||||
yymsp[-5].minor.yy291 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy291, yymsp[-1].minor.yy291);
|
||||
sqlite3Update(pParse,yymsp[-5].minor.yy291,yymsp[-2].minor.yy338,yymsp[0].minor.yy602,yymsp[-6].minor.yy60,0,0,0);
|
||||
}
|
||||
|
@ -4428,7 +4428,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
yymsp[-4].minor.yy602->x.pList = pList;
|
||||
}else{
|
||||
sqlite3ExprListDelete(pParse->db, pList);
|
||||
}
|
||||
}
|
||||
if( yymsp[-3].minor.yy60 ) yymsp[-4].minor.yy602 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy602, 0);
|
||||
}
|
||||
break;
|
||||
|
@ -4533,7 +4533,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
break;
|
||||
case 232: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
|
||||
{
|
||||
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
|
||||
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
|
||||
sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy338, yymsp[-10].minor.yy60,
|
||||
&yymsp[-11].minor.yy0, yymsp[0].minor.yy602, SQLITE_SO_ASC, yymsp[-8].minor.yy60, SQLITE_IDXTYPE_APPDEF);
|
||||
if( IN_RENAME_OBJECT && pParse->pNewIndex ){
|
||||
|
@ -4636,7 +4636,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
}
|
||||
break;
|
||||
case 264: /* trigger_cmd_list ::= trigger_cmd SEMI */
|
||||
{
|
||||
{
|
||||
assert( yymsp[-1].minor.yy483!=0 );
|
||||
yymsp[-1].minor.yy483->pLast = yymsp[-1].minor.yy483;
|
||||
}
|
||||
|
@ -4644,7 +4644,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
case 265: /* trnm ::= nm DOT nm */
|
||||
{
|
||||
yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
|
||||
"statements within triggers");
|
||||
}
|
||||
|
@ -4683,7 +4683,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
break;
|
||||
case 272: /* expr ::= RAISE LP IGNORE RP */
|
||||
{
|
||||
yymsp[-3].minor.yy602 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
|
||||
yymsp[-3].minor.yy602 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
|
||||
if( yymsp[-3].minor.yy602 ){
|
||||
yymsp[-3].minor.yy602->affExpr = OE_Ignore;
|
||||
}
|
||||
|
@ -4691,7 +4691,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
break;
|
||||
case 273: /* expr ::= RAISE LP raisetype COMMA nm RP */
|
||||
{
|
||||
yymsp[-5].minor.yy602 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
|
||||
yymsp[-5].minor.yy602 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
|
||||
if( yymsp[-5].minor.yy602 ) {
|
||||
yymsp[-5].minor.yy602->affExpr = (char)yymsp[-3].minor.yy60;
|
||||
}
|
||||
|
@ -4907,7 +4907,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
#ifdef SQLITE_OMIT_WINDOWFUNC
|
||||
goto SqliteOmitWindowfunc;
|
||||
#else
|
||||
{
|
||||
{
|
||||
yymsp[1].minor.yy19 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
@ -4916,7 +4916,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
#ifdef SQLITE_OMIT_WINDOWFUNC
|
||||
goto SqliteOmitWindowfunc;
|
||||
#else
|
||||
{
|
||||
{
|
||||
yylhsminor.yy19 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy60, yymsp[-1].minor.yy113.eType, yymsp[-1].minor.yy113.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy570);
|
||||
}
|
||||
yymsp[-2].minor.yy19 = yylhsminor.yy19;
|
||||
|
@ -4926,7 +4926,7 @@ static YYACTIONTYPE yy_reduce(
|
|||
#ifdef SQLITE_OMIT_WINDOWFUNC
|
||||
goto SqliteOmitWindowfunc;
|
||||
#else
|
||||
{
|
||||
{
|
||||
yylhsminor.yy19 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy60, yymsp[-3].minor.yy113.eType, yymsp[-3].minor.yy113.pExpr, yymsp[-1].minor.yy113.eType, yymsp[-1].minor.yy113.pExpr, yymsp[0].minor.yy570);
|
||||
}
|
||||
yymsp[-5].minor.yy19 = yylhsminor.yy19;
|
||||
|
@ -5267,7 +5267,7 @@ void sqlite3Parser(
|
|||
(int)(yypParser->yytos - yypParser->yystack));
|
||||
}
|
||||
#endif
|
||||
#if YYSTACKDEPTH>0
|
||||
#if YYSTACKDEPTH>0
|
||||
if( yypParser->yytos>=yypParser->yystackEnd ){
|
||||
yyStackOverflow(yypParser);
|
||||
break;
|
||||
|
@ -5306,7 +5306,7 @@ void sqlite3Parser(
|
|||
#ifdef YYERRORSYMBOL
|
||||
/* A syntax error has occurred.
|
||||
** The response to an error depends upon whether or not the
|
||||
** grammar defines an error token "ERROR".
|
||||
** grammar defines an error token "ERROR".
|
||||
**
|
||||
** This is what we do if the grammar does define ERROR:
|
||||
**
|
||||
|
|
46
third_party/sqlite3/pcache.c
vendored
46
third_party/sqlite3/pcache.c
vendored
|
@ -32,7 +32,7 @@
|
|||
**
|
||||
** The PCache.pSynced variable is used to optimize searching for a dirty
|
||||
** page to eject from the cache mid-transaction. It is better to eject
|
||||
** a page that does not require a journal sync than one that does.
|
||||
** a page that does not require a journal sync than one that does.
|
||||
** Therefore, pSynced is maintained so that it *almost* always points
|
||||
** to either the oldest page in the pDirty/pDirtyTail list that has a
|
||||
** clear PGHDR_NEED_SYNC flag or to a page that is older than this one
|
||||
|
@ -73,7 +73,7 @@ struct PCache {
|
|||
sqlite3_pcache_page *pLower;
|
||||
PgHdr *pPg;
|
||||
unsigned char *a;
|
||||
|
||||
|
||||
if( sqlite3PcacheTrace<2 ) return;
|
||||
if( pCache->pCache==0 ) return;
|
||||
N = sqlite3PcachePagecount(pCache);
|
||||
|
@ -165,12 +165,12 @@ static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
|
|||
if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
|
||||
assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
|
||||
assert( pPage->pDirtyPrev || pPage==p->pDirty );
|
||||
|
||||
|
||||
/* Update the PCache1.pSynced variable if necessary. */
|
||||
if( p->pSynced==pPage ){
|
||||
p->pSynced = pPage->pDirtyPrev;
|
||||
}
|
||||
|
||||
|
||||
if( pPage->pDirtyNext ){
|
||||
pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
|
||||
}else{
|
||||
|
@ -180,7 +180,7 @@ static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
|
|||
if( pPage->pDirtyPrev ){
|
||||
pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
|
||||
}else{
|
||||
/* If there are now no dirty pages in the cache, set eCreate to 2.
|
||||
/* If there are now no dirty pages in the cache, set eCreate to 2.
|
||||
** This is an optimization that allows sqlite3PcacheFetch() to skip
|
||||
** searching for a dirty page to eject from the cache when it might
|
||||
** otherwise have to. */
|
||||
|
@ -209,11 +209,11 @@ static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
|
|||
p->pDirty = pPage;
|
||||
|
||||
/* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
|
||||
** pSynced to point to it. Checking the NEED_SYNC flag is an
|
||||
** pSynced to point to it. Checking the NEED_SYNC flag is an
|
||||
** optimization, as if pSynced points to a page with the NEED_SYNC
|
||||
** flag set sqlite3PcacheFetchStress() searches through all newer
|
||||
** flag set sqlite3PcacheFetchStress() searches through all newer
|
||||
** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
|
||||
if( !p->pSynced
|
||||
if( !p->pSynced
|
||||
&& 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
|
||||
){
|
||||
p->pSynced = pPage;
|
||||
|
@ -254,7 +254,7 @@ static int numberOfCachePages(PCache *p){
|
|||
|
||||
/*************************************************** General Interfaces ******
|
||||
**
|
||||
** Initialize and shutdown the page cache subsystem. Neither of these
|
||||
** Initialize and shutdown the page cache subsystem. Neither of these
|
||||
** functions are threadsafe.
|
||||
*/
|
||||
int sqlite3PcacheInitialize(void){
|
||||
|
@ -281,8 +281,8 @@ int sqlite3PcacheSize(void){ return sizeof(PCache); }
|
|||
|
||||
/*
|
||||
** Create a new PCache object. Storage space to hold the object
|
||||
** has already been allocated and is passed in as the p pointer.
|
||||
** The caller discovers how much space needs to be allocated by
|
||||
** has already been allocated and is passed in as the p pointer.
|
||||
** The caller discovers how much space needs to be allocated by
|
||||
** calling sqlite3PcacheSize().
|
||||
**
|
||||
** szExtra is some extra space allocated for each page. The first
|
||||
|
@ -394,7 +394,7 @@ sqlite3_pcache_page *sqlite3PcacheFetch(
|
|||
/*
|
||||
** If the sqlite3PcacheFetch() routine is unable to allocate a new
|
||||
** page because no clean pages are available for reuse and the cache
|
||||
** size limit has been reached, then this routine can be invoked to
|
||||
** size limit has been reached, then this routine can be invoked to
|
||||
** try harder to allocate a page. This routine might invoke the stress
|
||||
** callback to spill dirty pages to the journal. It will then try to
|
||||
** allocate the new page and will only fail to allocate a new page on
|
||||
|
@ -411,17 +411,17 @@ int sqlite3PcacheFetchStress(
|
|||
if( pCache->eCreate==2 ) return 0;
|
||||
|
||||
if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
|
||||
/* Find a dirty page to write-out and recycle. First try to find a
|
||||
/* Find a dirty page to write-out and recycle. First try to find a
|
||||
** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
|
||||
** cleared), but if that is not possible settle for any other
|
||||
** cleared), but if that is not possible settle for any other
|
||||
** unreferenced dirty page.
|
||||
**
|
||||
** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
|
||||
** flag is currently referenced, then the following may leave pSynced
|
||||
** set incorrectly (pointing to other than the LRU page with NEED_SYNC
|
||||
** cleared). This is Ok, as pSynced is just an optimization. */
|
||||
for(pPg=pCache->pSynced;
|
||||
pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
|
||||
for(pPg=pCache->pSynced;
|
||||
pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
|
||||
pPg=pPg->pDirtyPrev
|
||||
);
|
||||
pCache->pSynced = pPg;
|
||||
|
@ -431,7 +431,7 @@ int sqlite3PcacheFetchStress(
|
|||
if( pPg ){
|
||||
int rc;
|
||||
#ifdef SQLITE_LOG_CACHE_SPILL
|
||||
sqlite3_log(SQLITE_FULL,
|
||||
sqlite3_log(SQLITE_FULL,
|
||||
"spill page %d making room for %d - cache used: %d/%d",
|
||||
pPg->pgno, pgno,
|
||||
sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
|
||||
|
@ -616,7 +616,7 @@ void sqlite3PcacheClearSyncFlags(PCache *pCache){
|
|||
}
|
||||
|
||||
/*
|
||||
** Change the page number of page p to newPgno.
|
||||
** Change the page number of page p to newPgno.
|
||||
*/
|
||||
void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
|
||||
PCache *pCache = p->pCache;
|
||||
|
@ -679,7 +679,7 @@ void sqlite3PcacheClose(PCache *pCache){
|
|||
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Discard the contents of the cache.
|
||||
*/
|
||||
void sqlite3PcacheClear(PCache *pCache){
|
||||
|
@ -770,7 +770,7 @@ PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
|
|||
return pcacheSortDirtyList(pCache->pDirty);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Return the total number of references to all pages held by the cache.
|
||||
**
|
||||
** This is not the total number of pages referenced, but the sum of the
|
||||
|
@ -787,7 +787,7 @@ int sqlite3PcachePageRefcount(PgHdr *p){
|
|||
return p->nRef;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Return the total number of pages in the cache.
|
||||
*/
|
||||
int sqlite3PcachePagecount(PCache *pCache){
|
||||
|
@ -829,7 +829,7 @@ int sqlite3PcacheSetSpillsize(PCache *p, int mxPage){
|
|||
p->szSpill = mxPage;
|
||||
}
|
||||
res = numberOfCachePages(p);
|
||||
if( res<p->szSpill ) res = p->szSpill;
|
||||
if( res<p->szSpill ) res = p->szSpill;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -860,7 +860,7 @@ int sqlite3PCachePercentDirty(PCache *pCache){
|
|||
}
|
||||
|
||||
#ifdef SQLITE_DIRECT_OVERFLOW_READ
|
||||
/*
|
||||
/*
|
||||
** Return true if there are one or more dirty pages in the cache. Else false.
|
||||
*/
|
||||
int sqlite3PCacheIsDirty(PCache *pCache){
|
||||
|
|
6
third_party/sqlite3/pcache.inc
vendored
6
third_party/sqlite3/pcache.inc
vendored
|
@ -37,7 +37,7 @@ struct PgHdr {
|
|||
u16 flags; /* PGHDR flags defined below */
|
||||
|
||||
/**********************************************************************
|
||||
** Elements above, except pCache, are public. All that follow are
|
||||
** Elements above, except pCache, are public. All that follow are
|
||||
** private to pcache.c and should not be accessed by other modules.
|
||||
** pCache is grouped with the public elements for efficiency.
|
||||
*/
|
||||
|
@ -90,7 +90,7 @@ int sqlite3PcacheSetPageSize(PCache *, int);
|
|||
int sqlite3PcacheSize(void);
|
||||
|
||||
/* One release per successful fetch. Page is pinned until released.
|
||||
** Reference counted.
|
||||
** Reference counted.
|
||||
*/
|
||||
sqlite3_pcache_page *sqlite3PcacheFetch(PCache*, Pgno, int createFlag);
|
||||
int sqlite3PcacheFetchStress(PCache*, Pgno, sqlite3_pcache_page**);
|
||||
|
@ -134,7 +134,7 @@ int sqlite3PcachePagecount(PCache*);
|
|||
|
||||
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
|
||||
/* Iterate through all dirty pages currently stored in the cache. This
|
||||
** interface is only available if SQLITE_CHECK_PAGES is defined when the
|
||||
** interface is only available if SQLITE_CHECK_PAGES is defined when the
|
||||
** library is built.
|
||||
*/
|
||||
void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
|
||||
|
|
94
third_party/sqlite3/pcache1.c
vendored
94
third_party/sqlite3/pcache1.c
vendored
|
@ -89,16 +89,16 @@ typedef struct PgFreeslot PgFreeslot;
|
|||
typedef struct PGroup PGroup;
|
||||
|
||||
/*
|
||||
** Each cache entry is represented by an instance of the following
|
||||
** Each cache entry is represented by an instance of the following
|
||||
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
|
||||
** PgHdr1.pCache->szPage bytes is allocated directly before this structure
|
||||
** PgHdr1.pCache->szPage bytes is allocated directly before this structure
|
||||
** in memory.
|
||||
**
|
||||
** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
|
||||
** but causes a 2-byte gap in the structure for most architectures (since
|
||||
** but causes a 2-byte gap in the structure for most architectures (since
|
||||
** pointers must be either 4 or 8-byte aligned). As this structure is located
|
||||
** in memory directly after the associated page data, if the database is
|
||||
** corrupt, code at the b-tree layer may overread the page buffer and
|
||||
** corrupt, code at the b-tree layer may overread the page buffer and
|
||||
** read part of this structure before the corruption is detected. This
|
||||
** can cause a valgrind error if the unitialized gap is accessed. Using u16
|
||||
** ensures there is no such gap, and therefore no bytes of unitialized memory
|
||||
|
@ -123,7 +123,7 @@ struct PgHdr1 {
|
|||
#define PAGE_IS_PINNED(p) ((p)->pLruNext==0)
|
||||
#define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0)
|
||||
|
||||
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
|
||||
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
|
||||
** of one or more PCaches that are able to recycle each other's unpinned
|
||||
** pages when they are under memory pressure. A PGroup is an instance of
|
||||
** the following object.
|
||||
|
@ -159,13 +159,13 @@ struct PGroup {
|
|||
** temporary or transient database) has a single page cache which
|
||||
** is an instance of this object.
|
||||
**
|
||||
** Pointers to structures of this type are cast and returned as
|
||||
** Pointers to structures of this type are cast and returned as
|
||||
** opaque sqlite3_pcache* handles.
|
||||
*/
|
||||
struct PCache1 {
|
||||
/* Cache configuration parameters. Page size (szPage) and the purgeable
|
||||
** flag (bPurgeable) and the pnPurgeable pointer are all set when the
|
||||
** cache is created and are never changed thereafter. nMax may be
|
||||
** cache is created and are never changed thereafter. nMax may be
|
||||
** modified at any time by a call to the pcache1Cachesize() method.
|
||||
** The PGroup mutex must be held when accessing nMax.
|
||||
*/
|
||||
|
@ -213,7 +213,7 @@ static SQLITE_WSD struct PCacheGlobal {
|
|||
*/
|
||||
int isInit; /* True if initialized */
|
||||
int separateCache; /* Use a new PGroup for each PCache */
|
||||
int nInitPage; /* Initial bulk allocation size */
|
||||
int nInitPage; /* Initial bulk allocation size */
|
||||
int szSlot; /* Size of each free slot */
|
||||
int nSlot; /* The number of pcache slots */
|
||||
int nReserve; /* Try to keep nFreeSlot above this */
|
||||
|
@ -254,7 +254,7 @@ static SQLITE_WSD struct PCacheGlobal {
|
|||
|
||||
|
||||
/*
|
||||
** This function is called during initialization if a static buffer is
|
||||
** This function is called during initialization if a static buffer is
|
||||
** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
|
||||
** verb to sqlite3_config(). Parameter pBuf points to an allocation large
|
||||
** enough to contain 'n' buffers of 'sz' bytes each.
|
||||
|
@ -324,8 +324,8 @@ static int pcache1InitBulk(PCache1 *pCache){
|
|||
|
||||
/*
|
||||
** Malloc function used within this file to allocate space from the buffer
|
||||
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
|
||||
** such buffer exists or there is no space left in it, this function falls
|
||||
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
|
||||
** such buffer exists or there is no space left in it, this function falls
|
||||
** back to sqlite3Malloc().
|
||||
**
|
||||
** Multiple threads can run this routine at the same time. Global variables
|
||||
|
@ -432,7 +432,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
|
|||
}else{
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
/* The group mutex must be released before pcache1Alloc() is called. This
|
||||
** is because it might call sqlite3_release_memory(), which assumes that
|
||||
** is because it might call sqlite3_release_memory(), which assumes that
|
||||
** this mutex is not held. */
|
||||
assert( pcache1.separateCache==0 );
|
||||
assert( pCache->pGroup==&pcache1.grp );
|
||||
|
@ -574,7 +574,7 @@ static void pcache1ResizeHash(PCache1 *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is used internally to remove the page pPage from the
|
||||
** This function is used internally to remove the page pPage from the
|
||||
** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
|
||||
** LRU list, then this function is a no-op.
|
||||
**
|
||||
|
@ -599,7 +599,7 @@ static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
|
|||
|
||||
|
||||
/*
|
||||
** Remove the page supplied as an argument from the hash table
|
||||
** Remove the page supplied as an argument from the hash table
|
||||
** (PCache1.apHash structure) that it is currently stored in.
|
||||
** Also free the page if freePage is true.
|
||||
**
|
||||
|
@ -642,8 +642,8 @@ static void pcache1EnforceMaxPage(PCache1 *pCache){
|
|||
}
|
||||
|
||||
/*
|
||||
** Discard all pages from cache pCache with a page number (key value)
|
||||
** greater than or equal to iLimit. Any pinned pages that meet this
|
||||
** Discard all pages from cache pCache with a page number (key value)
|
||||
** greater than or equal to iLimit. Any pinned pages that meet this
|
||||
** criteria are unpinned before they are discarded.
|
||||
**
|
||||
** The PCache mutex must be held when this function is called.
|
||||
|
@ -675,7 +675,7 @@ static void pcache1TruncateUnsafe(
|
|||
PgHdr1 **pp;
|
||||
PgHdr1 *pPage;
|
||||
assert( h<pCache->nHash );
|
||||
pp = &pCache->apHash[h];
|
||||
pp = &pCache->apHash[h];
|
||||
while( (pPage = *pp)!=0 ){
|
||||
if( pPage->iKey>=iLimit ){
|
||||
pCache->nPage--;
|
||||
|
@ -714,7 +714,7 @@ static int pcache1Init(void *NotUsed){
|
|||
**
|
||||
** * Use a unified cache in single-threaded applications that have
|
||||
** configured a start-time buffer for use as page-cache memory using
|
||||
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
|
||||
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
|
||||
** pBuf argument.
|
||||
**
|
||||
** * Otherwise use separate caches (mode-1)
|
||||
|
@ -749,7 +749,7 @@ static int pcache1Init(void *NotUsed){
|
|||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xShutdown method.
|
||||
** Note that the static mutex allocated in xInit does
|
||||
** Note that the static mutex allocated in xInit does
|
||||
** not need to be freed.
|
||||
*/
|
||||
static void pcache1Shutdown(void *NotUsed){
|
||||
|
@ -812,7 +812,7 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xCachesize method.
|
||||
** Implementation of the sqlite3_pcache.xCachesize method.
|
||||
**
|
||||
** Configure the cache_size limit for a cache.
|
||||
*/
|
||||
|
@ -831,7 +831,7 @@ static void pcache1Cachesize(sqlite3_pcache *p, int nMax){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xShrink method.
|
||||
** Implementation of the sqlite3_pcache.xShrink method.
|
||||
**
|
||||
** Free up as much memory as possible.
|
||||
*/
|
||||
|
@ -850,7 +850,7 @@ static void pcache1Shrink(sqlite3_pcache *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xPagecount method.
|
||||
** Implementation of the sqlite3_pcache.xPagecount method.
|
||||
*/
|
||||
static int pcache1Pagecount(sqlite3_pcache *p){
|
||||
int n;
|
||||
|
@ -871,8 +871,8 @@ static int pcache1Pagecount(sqlite3_pcache *p){
|
|||
** for these steps, the main pcache1Fetch() procedure can run faster.
|
||||
*/
|
||||
static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
||||
PCache1 *pCache,
|
||||
unsigned int iKey,
|
||||
PCache1 *pCache,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
unsigned int nPinned;
|
||||
|
@ -914,8 +914,8 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
}
|
||||
}
|
||||
|
||||
/* Step 5. If a usable page buffer has still not been found,
|
||||
** attempt to allocate a new one.
|
||||
/* Step 5. If a usable page buffer has still not been found,
|
||||
** attempt to allocate a new one.
|
||||
*/
|
||||
if( !pPage ){
|
||||
pPage = pcache1AllocPage(pCache, createFlag==1);
|
||||
|
@ -940,13 +940,13 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xFetch method.
|
||||
** Implementation of the sqlite3_pcache.xFetch method.
|
||||
**
|
||||
** Fetch a page by key value.
|
||||
**
|
||||
** Whether or not a new page may be allocated by this function depends on
|
||||
** the value of the createFlag argument. 0 means do not allocate a new
|
||||
** page. 1 means allocate a new page if space is easily available. 2
|
||||
** page. 1 means allocate a new page if space is easily available. 2
|
||||
** means to try really hard to allocate a new page.
|
||||
**
|
||||
** For a non-purgeable cache (a cache used as the storage for an in-memory
|
||||
|
@ -957,7 +957,7 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
** There are three different approaches to obtaining space for a page,
|
||||
** depending on the value of parameter createFlag (which may be 0, 1 or 2).
|
||||
**
|
||||
** 1. Regardless of the value of createFlag, the cache is searched for a
|
||||
** 1. Regardless of the value of createFlag, the cache is searched for a
|
||||
** copy of the requested page. If one is found, it is returned.
|
||||
**
|
||||
** 2. If createFlag==0 and the page is not already in the cache, NULL is
|
||||
|
@ -971,13 +971,13 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
** PCache1.nMax, or
|
||||
**
|
||||
** (b) the number of pages pinned by the cache is greater than
|
||||
** the sum of nMax for all purgeable caches, less the sum of
|
||||
** the sum of nMax for all purgeable caches, less the sum of
|
||||
** nMin for all other purgeable caches, or
|
||||
**
|
||||
** 4. If none of the first three conditions apply and the cache is marked
|
||||
** as purgeable, and if one of the following is true:
|
||||
**
|
||||
** (a) The number of pages allocated for the cache is already
|
||||
** (a) The number of pages allocated for the cache is already
|
||||
** PCache1.nMax, or
|
||||
**
|
||||
** (b) The number of pages allocated for all purgeable caches is
|
||||
|
@ -989,7 +989,7 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
**
|
||||
** then attempt to recycle a page from the LRU list. If it is the right
|
||||
** size, return the recycled buffer. Otherwise, free the buffer and
|
||||
** proceed to step 5.
|
||||
** proceed to step 5.
|
||||
**
|
||||
** 5. Otherwise, allocate and return a new page buffer.
|
||||
**
|
||||
|
@ -999,8 +999,8 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
** invokes the appropriate routine.
|
||||
*/
|
||||
static PgHdr1 *pcache1FetchNoMutex(
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
|
@ -1029,8 +1029,8 @@ static PgHdr1 *pcache1FetchNoMutex(
|
|||
}
|
||||
#if PCACHE1_MIGHT_USE_GROUP_MUTEX
|
||||
static PgHdr1 *pcache1FetchWithMutex(
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
|
@ -1044,8 +1044,8 @@ static PgHdr1 *pcache1FetchWithMutex(
|
|||
}
|
||||
#endif
|
||||
static sqlite3_pcache_page *pcache1Fetch(
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
#if PCACHE1_MIGHT_USE_GROUP_MUTEX || defined(SQLITE_DEBUG)
|
||||
|
@ -1075,18 +1075,18 @@ static sqlite3_pcache_page *pcache1Fetch(
|
|||
** Mark a page as unpinned (eligible for asynchronous recycling).
|
||||
*/
|
||||
static void pcache1Unpin(
|
||||
sqlite3_pcache *p,
|
||||
sqlite3_pcache_page *pPg,
|
||||
sqlite3_pcache *p,
|
||||
sqlite3_pcache_page *pPg,
|
||||
int reuseUnlikely
|
||||
){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = (PgHdr1 *)pPg;
|
||||
PGroup *pGroup = pCache->pGroup;
|
||||
|
||||
|
||||
assert( pPage->pCache==pCache );
|
||||
pcache1EnterMutex(pGroup);
|
||||
|
||||
/* It is an error to call this function if the page is already
|
||||
/* It is an error to call this function if the page is already
|
||||
** part of the PGroup LRU list.
|
||||
*/
|
||||
assert( pPage->pLruNext==0 );
|
||||
|
@ -1107,7 +1107,7 @@ static void pcache1Unpin(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xRekey method.
|
||||
** Implementation of the sqlite3_pcache.xRekey method.
|
||||
*/
|
||||
static void pcache1Rekey(
|
||||
sqlite3_pcache *p,
|
||||
|
@ -1118,7 +1118,7 @@ static void pcache1Rekey(
|
|||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = (PgHdr1 *)pPg;
|
||||
PgHdr1 **pp;
|
||||
unsigned int h;
|
||||
unsigned int h;
|
||||
assert( pPage->iKey==iOld );
|
||||
assert( pPage->pCache==pCache );
|
||||
|
||||
|
@ -1143,7 +1143,7 @@ static void pcache1Rekey(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xTruncate method.
|
||||
** Implementation of the sqlite3_pcache.xTruncate method.
|
||||
**
|
||||
** Discard all unpinned pages in the cache with a page number equal to
|
||||
** or greater than parameter iLimit. Any pinned pages with a page number
|
||||
|
@ -1160,7 +1160,7 @@ static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xDestroy method.
|
||||
** Implementation of the sqlite3_pcache.xDestroy method.
|
||||
**
|
||||
** Destroy a cache allocated using pcache1Create().
|
||||
*/
|
||||
|
@ -1226,7 +1226,7 @@ sqlite3_mutex *sqlite3Pcache1Mutex(void){
|
|||
** by the current thread may be sqlite3_free()ed.
|
||||
**
|
||||
** nReq is the number of bytes of memory required. Once this much has
|
||||
** been released, the function returns. The return value is the total number
|
||||
** been released, the function returns. The return value is the total number
|
||||
** of bytes of memory released.
|
||||
*/
|
||||
int sqlite3PcacheReleaseMemory(int nReq){
|
||||
|
|
90
third_party/sqlite3/pragma.c
vendored
90
third_party/sqlite3/pragma.c
vendored
|
@ -27,13 +27,13 @@
|
|||
** that includes the PragType_XXXX macro definitions and the aPragmaName[]
|
||||
** object. This ensures that the aPragmaName[] table is arranged in
|
||||
** lexicographical order to facility a binary search of the pragma name.
|
||||
** Do not edit pragma.h directly. Edit and rerun the script in at
|
||||
** Do not edit pragma.h directly. Edit and rerun the script in at
|
||||
** ../tool/mkpragmatab.tcl. */
|
||||
#include "third_party/sqlite3/pragma.inc"
|
||||
|
||||
/*
|
||||
** Interpret the given string as a safety level. Return 0 for OFF,
|
||||
** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or
|
||||
** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or
|
||||
** unrecognized string argument. The FULL and EXTRA option is disallowed
|
||||
** if the omitFull parameter it 1.
|
||||
**
|
||||
|
@ -92,7 +92,7 @@ static int getLockingMode(const char *z){
|
|||
/*
|
||||
** Interpret the given string as an auto-vacuum mode value.
|
||||
**
|
||||
** The following strings, "none", "full" and "incremental" are
|
||||
** The following strings, "none", "full" and "incremental" are
|
||||
** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
|
||||
*/
|
||||
static int getAutoVacuum(const char *z){
|
||||
|
@ -246,7 +246,7 @@ static const char *actionName(u8 action){
|
|||
case OE_SetDflt: zName = "SET DEFAULT"; break;
|
||||
case OE_Cascade: zName = "CASCADE"; break;
|
||||
case OE_Restrict: zName = "RESTRICT"; break;
|
||||
default: zName = "NO ACTION";
|
||||
default: zName = "NO ACTION";
|
||||
assert( action==OE_None ); break;
|
||||
}
|
||||
return zName;
|
||||
|
@ -310,7 +310,7 @@ static void pragmaFunclistLine(
|
|||
){
|
||||
for(; p; p=p->pNext){
|
||||
const char *zType;
|
||||
static const u32 mask =
|
||||
static const u32 mask =
|
||||
SQLITE_DETERMINISTIC |
|
||||
SQLITE_DIRECTONLY |
|
||||
SQLITE_SUBTYPE |
|
||||
|
@ -329,7 +329,7 @@ static void pragmaFunclistLine(
|
|||
&& showInternFuncs==0
|
||||
){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if( p->xValue!=0 ){
|
||||
zType = "w";
|
||||
}else if( p->xFinalize!=0 ){
|
||||
|
@ -364,7 +364,7 @@ static int integrityCheckResultRow(Vdbe *v){
|
|||
}
|
||||
|
||||
/*
|
||||
** Process a pragma statement.
|
||||
** Process a pragma statement.
|
||||
**
|
||||
** Pragmas are of this form:
|
||||
**
|
||||
|
@ -379,7 +379,7 @@ static int integrityCheckResultRow(Vdbe *v){
|
|||
** id and pId2 is any empty string.
|
||||
*/
|
||||
void sqlite3Pragma(
|
||||
Parse *pParse,
|
||||
Parse *pParse,
|
||||
Token *pId1, /* First part of [schema.]id field */
|
||||
Token *pId2, /* Second part of [schema.]id field, or NULL */
|
||||
Token *pValue, /* Token for <value>, or NULL */
|
||||
|
@ -407,8 +407,8 @@ void sqlite3Pragma(
|
|||
if( iDb<0 ) return;
|
||||
pDb = &db->aDb[iDb];
|
||||
|
||||
/* If the temp database has been explicitly named as part of the
|
||||
** pragma, make sure it is open.
|
||||
/* If the temp database has been explicitly named as part of the
|
||||
** pragma, make sure it is open.
|
||||
*/
|
||||
if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
|
||||
return;
|
||||
|
@ -476,7 +476,7 @@ void sqlite3Pragma(
|
|||
}
|
||||
|
||||
/* Register the result column names for pragmas that return results */
|
||||
if( (pPragma->mPragFlg & PragFlg_NoColumns)==0
|
||||
if( (pPragma->mPragFlg & PragFlg_NoColumns)==0
|
||||
&& ((pPragma->mPragFlg & PragFlg_NoColumns1)==0 || zRight==0)
|
||||
){
|
||||
setPragmaResultColumnNames(v, pPragma);
|
||||
|
@ -484,7 +484,7 @@ void sqlite3Pragma(
|
|||
|
||||
/* Jump to the appropriate pragma handler */
|
||||
switch( pPragma->ePragTyp ){
|
||||
|
||||
|
||||
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
|
||||
/*
|
||||
** PRAGMA [schema.]default_cache_size
|
||||
|
@ -600,7 +600,7 @@ void sqlite3Pragma(
|
|||
** PRAGMA [schema.]max_page_count=N
|
||||
**
|
||||
** The first form reports the current setting for the
|
||||
** maximum number of pages in the database file. The
|
||||
** maximum number of pages in the database file. The
|
||||
** second form attempts to change this setting. Both
|
||||
** forms return the current setting.
|
||||
**
|
||||
|
@ -767,7 +767,7 @@ void sqlite3Pragma(
|
|||
*/
|
||||
rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
|
||||
if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
|
||||
/* When setting the auto_vacuum mode to either "full" or
|
||||
/* When setting the auto_vacuum mode to either "full" or
|
||||
** "incremental", write the value of meta[6] in the database
|
||||
** file. Before writing to meta[6], check that meta[3] indicates
|
||||
** that this really is an auto-vacuum capable database.
|
||||
|
@ -869,7 +869,7 @@ void sqlite3Pragma(
|
|||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||
if( !zRight ){
|
||||
returnSingleInt(v,
|
||||
(db->flags & SQLITE_CacheSpill)==0 ? 0 :
|
||||
(db->flags & SQLITE_CacheSpill)==0 ? 0 :
|
||||
sqlite3BtreeSetSpillSize(pDb->pBt,0));
|
||||
}else{
|
||||
int size = 1;
|
||||
|
@ -1043,7 +1043,7 @@ void sqlite3Pragma(
|
|||
Pager *pPager = sqlite3BtreePager(pDb->pBt);
|
||||
char *proxy_file_path = NULL;
|
||||
sqlite3_file *pFile = sqlite3PagerFile(pPager);
|
||||
sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
|
||||
sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
|
||||
&proxy_file_path);
|
||||
returnSingleText(v, proxy_file_path);
|
||||
}else{
|
||||
|
@ -1051,10 +1051,10 @@ void sqlite3Pragma(
|
|||
sqlite3_file *pFile = sqlite3PagerFile(pPager);
|
||||
int res;
|
||||
if( zRight[0] ){
|
||||
res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
|
||||
res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
|
||||
zRight);
|
||||
} else {
|
||||
res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
|
||||
res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
|
||||
NULL);
|
||||
}
|
||||
if( res!=SQLITE_OK ){
|
||||
|
@ -1064,8 +1064,8 @@ void sqlite3Pragma(
|
|||
}
|
||||
break;
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
|
||||
|
||||
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
|
||||
|
||||
/*
|
||||
** PRAGMA [schema.]synchronous
|
||||
** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL|EXTRA
|
||||
|
@ -1080,7 +1080,7 @@ void sqlite3Pragma(
|
|||
returnSingleInt(v, pDb->safety_level-1);
|
||||
}else{
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"Safety level may not be changed inside a transaction");
|
||||
}else if( iDb!=1 ){
|
||||
int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
|
||||
|
@ -1120,7 +1120,7 @@ void sqlite3Pragma(
|
|||
if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
|
||||
}
|
||||
|
||||
/* Many of the flag-pragmas modify the code generated by the SQL
|
||||
/* Many of the flag-pragmas modify the code generated by the SQL
|
||||
** compiler (eg. count_changes). So add an opcode to expire all
|
||||
** compiled SQL statements after modifying a pragma value.
|
||||
*/
|
||||
|
@ -1362,7 +1362,7 @@ void sqlite3Pragma(
|
|||
pFK = pTab->pFKey;
|
||||
if( pFK ){
|
||||
int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
pParse->nMem = 8;
|
||||
sqlite3CodeVerifySchema(pParse, iTabDb);
|
||||
while(pFK){
|
||||
|
@ -1459,8 +1459,8 @@ void sqlite3Pragma(
|
|||
addrOk = sqlite3VdbeMakeLabel(pParse);
|
||||
|
||||
/* Generate code to read the child key values into registers
|
||||
** regRow..regRow+n. If any of the child key values are NULL, this
|
||||
** row cannot cause an FK violation. Jump directly to addrOk in
|
||||
** regRow..regRow+n. If any of the child key values are NULL, this
|
||||
** row cannot cause an FK violation. Jump directly to addrOk in
|
||||
** this case. */
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
|
||||
|
@ -1525,7 +1525,7 @@ void sqlite3Pragma(
|
|||
**
|
||||
** Verify the integrity of the database.
|
||||
**
|
||||
** The "quick_check" is reduced version of
|
||||
** The "quick_check" is reduced version of
|
||||
** integrity_check designed to detect most database corruption
|
||||
** without the overhead of cross-checking indexes. Quick_check
|
||||
** is linear time wherease integrity_check is O(NlogN).
|
||||
|
@ -1655,7 +1655,7 @@ void sqlite3Pragma(
|
|||
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
|
||||
1, 0, &iDataCur, &iIdxCur);
|
||||
/* reg[7] counts the number of entries in the table.
|
||||
** reg[8+i] counts the number of entries in the i-th index
|
||||
** reg[8+i] counts the number of entries in the i-th index
|
||||
*/
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
|
@ -1699,7 +1699,7 @@ void sqlite3Pragma(
|
|||
for(k=pCheck->nExpr-1; k>0; k--){
|
||||
sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
|
||||
}
|
||||
sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
|
||||
sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
|
||||
SQLITE_JUMPIFNULL);
|
||||
sqlite3VdbeResolveLabel(v, addrCkFault);
|
||||
pParse->iSelfTab = 0;
|
||||
|
@ -1774,7 +1774,7 @@ void sqlite3Pragma(
|
|||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
static const int iLn = VDBE_OFFSET_LINENO(2);
|
||||
|
@ -1816,7 +1816,7 @@ void sqlite3Pragma(
|
|||
** encoding that will be used for the main database file if a new file
|
||||
** is created. If an existing main database file is opened, then the
|
||||
** default text encoding for the existing database is used.
|
||||
**
|
||||
**
|
||||
** In all cases new databases created using the ATTACH command are
|
||||
** created to use the same default text encoding as the main database. If
|
||||
** the main database has not been initialized and/or created when ATTACH
|
||||
|
@ -1999,8 +1999,8 @@ void sqlite3Pragma(
|
|||
if( zRight ){
|
||||
sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
|
||||
}
|
||||
returnSingleInt(v,
|
||||
db->xWalCallback==sqlite3WalDefaultHook ?
|
||||
returnSingleInt(v,
|
||||
db->xWalCallback==sqlite3WalDefaultHook ?
|
||||
SQLITE_PTR_TO_INT(db->pWalArg) : 0);
|
||||
}
|
||||
break;
|
||||
|
@ -2040,7 +2040,7 @@ void sqlite3Pragma(
|
|||
** 0x0002 Run ANALYZE on tables that might benefit. On by default.
|
||||
** See below for additional information.
|
||||
**
|
||||
** 0x0004 (Not yet implemented) Record usage and performance
|
||||
** 0x0004 (Not yet implemented) Record usage and performance
|
||||
** information from the current session in the
|
||||
** database file so that it will be available to "optimize"
|
||||
** pragmas run by future database connections.
|
||||
|
@ -2051,7 +2051,7 @@ void sqlite3Pragma(
|
|||
** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
|
||||
** of the optimizations listed above except Debug Mode, including new
|
||||
** optimizations that have not yet been invented. If new optimizations are
|
||||
** ever added that should be off by default, those off-by-default
|
||||
** ever added that should be off by default, those off-by-default
|
||||
** optimizations will have bitmasks of 0x10000 or larger.
|
||||
**
|
||||
** DETERMINATION OF WHEN TO RUN ANALYZE
|
||||
|
@ -2112,7 +2112,7 @@ void sqlite3Pragma(
|
|||
}
|
||||
if( szThreshold ){
|
||||
sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
|
||||
sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur,
|
||||
sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur,
|
||||
sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold);
|
||||
VdbeCoverage(v);
|
||||
}
|
||||
|
@ -2246,7 +2246,7 @@ void sqlite3Pragma(
|
|||
pBt = db->aDb[i].pBt;
|
||||
if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
|
||||
zState = "closed";
|
||||
}else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
|
||||
}else if( sqlite3_file_control(db, i ? db->aDb[i].zDbSName : 0,
|
||||
SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
|
||||
zState = azLockName[j];
|
||||
}
|
||||
|
@ -2270,7 +2270,7 @@ void sqlite3Pragma(
|
|||
/* The following block is a no-op unless SQLITE_DEBUG is defined. Its only
|
||||
** purpose is to execute assert() statements to verify that if the
|
||||
** PragFlg_NoColumns1 flag is set and the caller specified an argument
|
||||
** to the PRAGMA, the implementation has not added any OP_ResultRow
|
||||
** to the PRAGMA, the implementation has not added any OP_ResultRow
|
||||
** instructions to the VM. */
|
||||
if( (pPragma->mPragFlg & PragFlg_NoColumns1) && zRight ){
|
||||
sqlite3VdbeVerifyNoResultRow(v);
|
||||
|
@ -2301,7 +2301,7 @@ struct PragmaVtabCursor {
|
|||
char *azArg[2]; /* Value of the argument and schema */
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
** Pragma virtual table module xConnect method.
|
||||
*/
|
||||
static int pragmaVtabConnect(
|
||||
|
@ -2363,7 +2363,7 @@ static int pragmaVtabConnect(
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Pragma virtual table module xDisconnect method.
|
||||
*/
|
||||
static int pragmaVtabDisconnect(sqlite3_vtab *pVtab){
|
||||
|
@ -2461,11 +2461,11 @@ static int pragmaVtabNext(sqlite3_vtab_cursor *pVtabCursor){
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Pragma virtual table module xFilter method.
|
||||
*/
|
||||
static int pragmaVtabFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -2520,11 +2520,11 @@ static int pragmaVtabEof(sqlite3_vtab_cursor *pVtabCursor){
|
|||
}
|
||||
|
||||
/* The xColumn method simply returns the corresponding column from
|
||||
** the PRAGMA.
|
||||
** the PRAGMA.
|
||||
*/
|
||||
static int pragmaVtabColumn(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
sqlite3_context *ctx,
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
sqlite3_context *ctx,
|
||||
int i
|
||||
){
|
||||
PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
|
||||
|
@ -2537,7 +2537,7 @@ static int pragmaVtabColumn(
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Pragma virtual table module xRowid method.
|
||||
*/
|
||||
static int pragmaVtabRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *p){
|
||||
|
|
76
third_party/sqlite3/pragma.inc
vendored
76
third_party/sqlite3/pragma.inc
vendored
|
@ -68,57 +68,57 @@
|
|||
*/
|
||||
static const char *const pragCName[] = {
|
||||
/* 0 */ "id", /* Used by: foreign_key_list */
|
||||
/* 1 */ "seq",
|
||||
/* 2 */ "table",
|
||||
/* 3 */ "from",
|
||||
/* 4 */ "to",
|
||||
/* 5 */ "on_update",
|
||||
/* 6 */ "on_delete",
|
||||
/* 7 */ "match",
|
||||
/* 1 */ "seq",
|
||||
/* 2 */ "table",
|
||||
/* 3 */ "from",
|
||||
/* 4 */ "to",
|
||||
/* 5 */ "on_update",
|
||||
/* 6 */ "on_delete",
|
||||
/* 7 */ "match",
|
||||
/* 8 */ "cid", /* Used by: table_xinfo */
|
||||
/* 9 */ "name",
|
||||
/* 10 */ "type",
|
||||
/* 11 */ "notnull",
|
||||
/* 12 */ "dflt_value",
|
||||
/* 13 */ "pk",
|
||||
/* 14 */ "hidden",
|
||||
/* 9 */ "name",
|
||||
/* 10 */ "type",
|
||||
/* 11 */ "notnull",
|
||||
/* 12 */ "dflt_value",
|
||||
/* 13 */ "pk",
|
||||
/* 14 */ "hidden",
|
||||
/* table_info reuses 8 */
|
||||
/* 15 */ "seqno", /* Used by: index_xinfo */
|
||||
/* 16 */ "cid",
|
||||
/* 17 */ "name",
|
||||
/* 18 */ "desc",
|
||||
/* 19 */ "coll",
|
||||
/* 20 */ "key",
|
||||
/* 16 */ "cid",
|
||||
/* 17 */ "name",
|
||||
/* 18 */ "desc",
|
||||
/* 19 */ "coll",
|
||||
/* 20 */ "key",
|
||||
/* 21 */ "name", /* Used by: function_list */
|
||||
/* 22 */ "builtin",
|
||||
/* 23 */ "type",
|
||||
/* 24 */ "enc",
|
||||
/* 25 */ "narg",
|
||||
/* 26 */ "flags",
|
||||
/* 22 */ "builtin",
|
||||
/* 23 */ "type",
|
||||
/* 24 */ "enc",
|
||||
/* 25 */ "narg",
|
||||
/* 26 */ "flags",
|
||||
/* 27 */ "tbl", /* Used by: stats */
|
||||
/* 28 */ "idx",
|
||||
/* 29 */ "wdth",
|
||||
/* 30 */ "hght",
|
||||
/* 31 */ "flgs",
|
||||
/* 28 */ "idx",
|
||||
/* 29 */ "wdth",
|
||||
/* 30 */ "hght",
|
||||
/* 31 */ "flgs",
|
||||
/* 32 */ "seq", /* Used by: index_list */
|
||||
/* 33 */ "name",
|
||||
/* 34 */ "unique",
|
||||
/* 35 */ "origin",
|
||||
/* 36 */ "partial",
|
||||
/* 33 */ "name",
|
||||
/* 34 */ "unique",
|
||||
/* 35 */ "origin",
|
||||
/* 36 */ "partial",
|
||||
/* 37 */ "table", /* Used by: foreign_key_check */
|
||||
/* 38 */ "rowid",
|
||||
/* 39 */ "parent",
|
||||
/* 40 */ "fkid",
|
||||
/* 38 */ "rowid",
|
||||
/* 39 */ "parent",
|
||||
/* 40 */ "fkid",
|
||||
/* index_info reuses 15 */
|
||||
/* 41 */ "seq", /* Used by: database_list */
|
||||
/* 42 */ "name",
|
||||
/* 43 */ "file",
|
||||
/* 42 */ "name",
|
||||
/* 43 */ "file",
|
||||
/* 44 */ "busy", /* Used by: wal_checkpoint */
|
||||
/* 45 */ "log",
|
||||
/* 45 */ "log",
|
||||
/* 46 */ "checkpointed",
|
||||
/* collation_list reuses 32 */
|
||||
/* 47 */ "database", /* Used by: lock_status */
|
||||
/* 48 */ "status",
|
||||
/* 48 */ "status",
|
||||
/* 49 */ "cache_size", /* Used by: default_cache_size */
|
||||
/* module_list pragma_list reuses 9 */
|
||||
/* 50 */ "timeout", /* Used by: busy_timeout */
|
||||
|
|
38
third_party/sqlite3/prepare.c
vendored
38
third_party/sqlite3/prepare.c
vendored
|
@ -31,8 +31,8 @@ static void corruptSchema(
|
|||
}else if( pData->pzErrMsg[0]!=0 ){
|
||||
/* A error message has already been generated. Do not overwrite it */
|
||||
}else if( pData->mInitFlags & (INITFLAG_AlterRename|INITFLAG_AlterDrop) ){
|
||||
*pData->pzErrMsg = sqlite3MPrintf(db,
|
||||
"error in %s %s after %s: %s", azObj[0], azObj[1],
|
||||
*pData->pzErrMsg = sqlite3MPrintf(db,
|
||||
"error in %s %s after %s: %s", azObj[0], azObj[1],
|
||||
(pData->mInitFlags & INITFLAG_AlterRename) ? "rename" : "drop column",
|
||||
zExtra
|
||||
);
|
||||
|
@ -249,7 +249,7 @@ int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFlags){
|
|||
}
|
||||
|
||||
/* If there is not already a read-only (or read-write) transaction opened
|
||||
** on the b-tree database, open one now. If a transaction is opened, it
|
||||
** on the b-tree database, open one now. If a transaction is opened, it
|
||||
** will be closed before this function returns. */
|
||||
sqlite3BtreeEnter(pDb->pBt);
|
||||
if( sqlite3BtreeTxnState(pDb->pBt)==SQLITE_TXN_NONE ){
|
||||
|
@ -356,7 +356,7 @@ int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFlags){
|
|||
initData.mxPage = sqlite3BtreeLastPage(pDb->pBt);
|
||||
{
|
||||
char *zSql;
|
||||
zSql = sqlite3MPrintf(db,
|
||||
zSql = sqlite3MPrintf(db,
|
||||
"SELECT*FROM\"%w\".%s ORDER BY rowid",
|
||||
db->aDb[iDb].zDbSName, zSchemaTabName);
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
|
@ -384,7 +384,7 @@ int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFlags){
|
|||
}
|
||||
if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
|
||||
/* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
|
||||
** the schema loaded, even if errors occurred. In this situation the
|
||||
** the schema loaded, even if errors occurred. In this situation the
|
||||
** current sqlite3_prepare() operation will fail, but the following one
|
||||
** will attempt to compile the supplied statement against whatever subset
|
||||
** of the schema was loaded before the error occurred. The primary
|
||||
|
@ -423,12 +423,12 @@ error_out:
|
|||
** error occurs, write an error message into *pzErrMsg.
|
||||
**
|
||||
** After a database is initialized, the DB_SchemaLoaded bit is set
|
||||
** bit is set in the flags field of the Db structure.
|
||||
** bit is set in the flags field of the Db structure.
|
||||
*/
|
||||
int sqlite3Init(sqlite3 *db, char **pzErrMsg){
|
||||
int i, rc;
|
||||
int commit_internal = !(db->mDbFlags&DBFLAG_SchemaChange);
|
||||
|
||||
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
|
||||
assert( db->init.busy==0 );
|
||||
|
@ -493,7 +493,7 @@ static void schemaIsValid(Parse *pParse){
|
|||
if( pBt==0 ) continue;
|
||||
|
||||
/* If there is not already a read-only (or read-write) transaction opened
|
||||
** on the b-tree database, open one now. If a transaction is opened, it
|
||||
** on the b-tree database, open one now. If a transaction is opened, it
|
||||
** will be closed immediately after reading the meta-value. */
|
||||
if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_NONE ){
|
||||
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
|
||||
|
@ -504,7 +504,7 @@ static void schemaIsValid(Parse *pParse){
|
|||
openedTransaction = 1;
|
||||
}
|
||||
|
||||
/* Read the schema cookie from the database. If it does not match the
|
||||
/* Read the schema cookie from the database. If it does not match the
|
||||
** value stored as part of the in-memory schema representation,
|
||||
** set Parse.rc to SQLITE_SCHEMA. */
|
||||
sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
|
||||
|
@ -531,13 +531,13 @@ static void schemaIsValid(Parse *pParse){
|
|||
int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
|
||||
int i = -32768;
|
||||
|
||||
/* If pSchema is NULL, then return -32768. This happens when code in
|
||||
/* If pSchema is NULL, then return -32768. This happens when code in
|
||||
** expr.c is trying to resolve a reference to a transient table (i.e. one
|
||||
** created by a sub-select). In this case the return value of this
|
||||
** created by a sub-select). In this case the return value of this
|
||||
** function should never be used.
|
||||
**
|
||||
** We return -32768 instead of the more usual -1 simply because using
|
||||
** -32768 as the incorrect index into db->aDb[] is much
|
||||
** -32768 as the incorrect index into db->aDb[] is much
|
||||
** more likely to cause a segfault than -1 (of course there are assert()
|
||||
** statements too, but it never hurts to play the odds) and
|
||||
** -32768 will still fit into a 16-bit signed integer.
|
||||
|
@ -675,8 +675,8 @@ static int sqlite3Prepare(
|
|||
** This thread is currently holding mutexes on all Btrees (because
|
||||
** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
|
||||
** is not possible for another thread to start a new schema change
|
||||
** while this routine is running. Hence, we do not need to hold
|
||||
** locks on the schema, we just need to make sure nobody else is
|
||||
** while this routine is running. Hence, we do not need to hold
|
||||
** locks on the schema, we just need to make sure nobody else is
|
||||
** holding them.
|
||||
**
|
||||
** Note that setting READ_UNCOMMITTED overrides most lock detection,
|
||||
|
@ -914,7 +914,7 @@ int sqlite3_prepare_v3(
|
|||
** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
|
||||
*/
|
||||
static int sqlite3Prepare16(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const void *zSql, /* UTF-16 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
u32 prepFlags, /* Zero or more SQLITE_PREPARE_* flags */
|
||||
|
@ -957,7 +957,7 @@ static int sqlite3Prepare16(
|
|||
int chars_parsed = sqlite3Utf8CharLen(zSql8, (int)(zTail8-zSql8));
|
||||
*pzTail = (u8 *)zSql + sqlite3Utf16ByteLen(zSql, chars_parsed);
|
||||
}
|
||||
sqlite3DbFree(db, zSql8);
|
||||
sqlite3DbFree(db, zSql8);
|
||||
rc = sqlite3ApiExit(db, rc);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return rc;
|
||||
|
@ -972,7 +972,7 @@ static int sqlite3Prepare16(
|
|||
** occurs.
|
||||
*/
|
||||
int sqlite3_prepare16(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const void *zSql, /* UTF-16 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
|
||||
|
@ -984,7 +984,7 @@ int sqlite3_prepare16(
|
|||
return rc;
|
||||
}
|
||||
int sqlite3_prepare16_v2(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const void *zSql, /* UTF-16 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
|
||||
|
@ -996,7 +996,7 @@ int sqlite3_prepare16_v2(
|
|||
return rc;
|
||||
}
|
||||
int sqlite3_prepare16_v3(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const void *zSql, /* UTF-16 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_* flags */
|
||||
|
|
6
third_party/sqlite3/printf.c
vendored
6
third_party/sqlite3/printf.c
vendored
|
@ -243,7 +243,7 @@ void sqlite3_str_vappendf(
|
|||
PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
|
||||
char buf[etBUFSIZE]; /* Conversion buffer */
|
||||
|
||||
/* pAccum never starts out with an empty buffer that was obtained from
|
||||
/* pAccum never starts out with an empty buffer that was obtained from
|
||||
** malloc(). This precondition is required by the mprintf("%z...")
|
||||
** optimization. */
|
||||
assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 );
|
||||
|
@ -410,7 +410,7 @@ void sqlite3_str_vappendf(
|
|||
sizeof(char*)==sizeof(long int) ? 1 : 0;
|
||||
/* no break */ deliberate_fall_through
|
||||
case etORDINAL:
|
||||
case etRADIX:
|
||||
case etRADIX:
|
||||
cThousand = 0;
|
||||
/* no break */ deliberate_fall_through
|
||||
case etDECIMAL:
|
||||
|
@ -1167,7 +1167,7 @@ char *sqlite3_vmprintf(const char *zFormat, va_list ap){
|
|||
char zBase[SQLITE_PRINT_BUF_SIZE];
|
||||
StrAccum acc;
|
||||
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( zFormat==0 ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
|
|
76
third_party/sqlite3/resolve.c
vendored
76
third_party/sqlite3/resolve.c
vendored
|
@ -88,7 +88,7 @@ static void resolveAlias(
|
|||
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
|
||||
}
|
||||
|
||||
/* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
|
||||
/* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
|
||||
** prevents ExprDelete() from deleting the Expr structure itself,
|
||||
** allowing it to be repopulated by the memcpy() on the following line.
|
||||
** The pExpr->u.zToken might point into memory that will be freed by the
|
||||
|
@ -193,7 +193,7 @@ Bitmask sqlite3ExprColUsed(Expr *pExpr){
|
|||
pExTab = pExpr->y.pTab;
|
||||
assert( pExTab!=0 );
|
||||
if( (pExTab->tabFlags & TF_HasGenerated)!=0
|
||||
&& (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
|
||||
&& (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
|
||||
){
|
||||
testcase( pExTab->nCol==BMS-1 );
|
||||
testcase( pExTab->nCol==BMS );
|
||||
|
@ -208,7 +208,7 @@ Bitmask sqlite3ExprColUsed(Expr *pExpr){
|
|||
|
||||
/*
|
||||
** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
|
||||
** that name in the set of source tables in pSrcList and make the pExpr
|
||||
** that name in the set of source tables in pSrcList and make the pExpr
|
||||
** expression node refer back to that source column. The following changes
|
||||
** are made to pExpr:
|
||||
**
|
||||
|
@ -338,7 +338,7 @@ static int lookupName(
|
|||
for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
|
||||
if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
|
||||
/* If there has been exactly one prior match and this match
|
||||
** is for the right-hand table of a NATURAL JOIN or is in a
|
||||
** is for the right-hand table of a NATURAL JOIN or is in a
|
||||
** USING clause, then skip this match.
|
||||
*/
|
||||
if( cnt==1 ){
|
||||
|
@ -366,7 +366,7 @@ static int lookupName(
|
|||
} /* if( pSrcList ) */
|
||||
|
||||
#if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT)
|
||||
/* If we have not already resolved the name, then maybe
|
||||
/* If we have not already resolved the name, then maybe
|
||||
** it is a new.* or old.* trigger argument reference. Or
|
||||
** maybe it is an excluded.* from an upsert. Or maybe it is
|
||||
** a reference in the RETURNING clause to a table being modified.
|
||||
|
@ -403,7 +403,7 @@ static int lookupName(
|
|||
}
|
||||
#endif /* SQLITE_OMIT_UPSERT */
|
||||
|
||||
if( pTab ){
|
||||
if( pTab ){
|
||||
int iCol;
|
||||
u8 hCol = sqlite3StrIHash(zCol);
|
||||
pSchema = pTab->pSchema;
|
||||
|
@ -538,7 +538,7 @@ static int lookupName(
|
|||
}
|
||||
goto lookupname_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Advance to the next name context. The loop will exit when either
|
||||
|
@ -705,7 +705,7 @@ Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
|
|||
**
|
||||
** static void notValid(
|
||||
** Parse *pParse, // Leave error message here
|
||||
** NameContext *pNC, // The name context
|
||||
** NameContext *pNC, // The name context
|
||||
** const char *zMsg, // Type of error
|
||||
** int validMask, // Set of contexts for which prohibited
|
||||
** Expr *pExpr // Invalidate this expression on error
|
||||
|
@ -783,7 +783,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
|
||||
/* The special operator TK_ROW means use the rowid for the first
|
||||
** column in the FROM clause. This is used by the LIMIT and ORDER BY
|
||||
** clause processing on UPDATE and DELETE statements, and by
|
||||
** clause processing on UPDATE and DELETE statements, and by
|
||||
** UPDATE ... FROM statement processing.
|
||||
*/
|
||||
case TK_ROW: {
|
||||
|
@ -818,7 +818,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
int anRef[8];
|
||||
NameContext *p;
|
||||
int i;
|
||||
for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
|
||||
for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
|
||||
anRef[i] = p->nRef;
|
||||
}
|
||||
sqlite3WalkExpr(pWalker, pExpr->pLeft);
|
||||
|
@ -845,7 +845,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
** Or a database, table and column: ID.ID.ID
|
||||
**
|
||||
** The TK_ID and TK_OUT cases are combined so that there will only
|
||||
** be one call to lookupName(). Then the compiler will in-line
|
||||
** be one call to lookupName(). Then the compiler will in-line
|
||||
** lookupName() for a size reduction and performance increase.
|
||||
*/
|
||||
case TK_ID:
|
||||
|
@ -934,7 +934,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
** to likelihood(X,0.9375). */
|
||||
/* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
|
||||
pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
|
@ -996,11 +996,11 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
|| (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize)
|
||||
);
|
||||
if( pDef && pDef->xValue==0 && pWin ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"%.*s() may not be used as a window function", nId, zId
|
||||
);
|
||||
pNC->nErr++;
|
||||
}else if(
|
||||
}else if(
|
||||
(is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
|
||||
|| (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
|
||||
|| (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
|
||||
|
@ -1036,8 +1036,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
}
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"FILTER may not be used with non-aggregate %.*s()",
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"FILTER may not be used with non-aggregate %.*s()",
|
||||
nId, zId
|
||||
);
|
||||
pNC->nErr++;
|
||||
|
@ -1100,7 +1100,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
pNC->ncFlags |= savedAllowFlags;
|
||||
}
|
||||
/* FIX ME: Compute pExpr->affinity based on the expected return
|
||||
** type of the function
|
||||
** type of the function
|
||||
*/
|
||||
return WRC_Prune;
|
||||
}
|
||||
|
@ -1185,7 +1185,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
|||
testcase( pExpr->op==TK_BETWEEN );
|
||||
sqlite3ErrorMsg(pParse, "row value misused");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
|
||||
|
@ -1296,7 +1296,7 @@ static void resolveOutOfRangeError(
|
|||
int i, /* The index (1-based) of the term out of range */
|
||||
int mx /* Largest permissible value of i */
|
||||
){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"%r %s BY term out of range - should be "
|
||||
"between 1 and %d", i, zType, mx);
|
||||
}
|
||||
|
@ -1361,7 +1361,7 @@ static int resolveCompoundOrderBy(
|
|||
iCol = resolveAsName(pParse, pEList, pE);
|
||||
if( iCol==0 ){
|
||||
/* Now test if expression pE matches one of the values returned
|
||||
** by pSelect. In the usual case this is done by duplicating the
|
||||
** by pSelect. In the usual case this is done by duplicating the
|
||||
** expression, resolving any symbols in it, and then comparing
|
||||
** it against each expression returned by the SELECT statement.
|
||||
** Once the comparisons are finished, the duplicate expression
|
||||
|
@ -1585,7 +1585,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
ExprList *pGroupBy; /* The GROUP BY clause */
|
||||
Select *pLeftmost; /* Left-most of SELECT of a compound */
|
||||
sqlite3 *db; /* Database connection */
|
||||
|
||||
|
||||
|
||||
assert( p!=0 );
|
||||
if( p->selFlags & SF_Resolved ){
|
||||
|
@ -1639,7 +1639,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
pSub->pOrderBy = p->pOrderBy;
|
||||
p->pOrderBy = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Recursively resolve names in all subqueries
|
||||
*/
|
||||
for(i=0; i<p->pSrc->nSrc; i++){
|
||||
|
@ -1665,19 +1665,19 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
|
||||
** resolve the result-set expression list.
|
||||
*/
|
||||
sNC.ncFlags = NC_AllowAgg|NC_AllowWin;
|
||||
sNC.pSrcList = p->pSrc;
|
||||
sNC.pNext = pOuterNC;
|
||||
|
||||
|
||||
/* Resolve names in the result set. */
|
||||
if( sqlite3ResolveExprListNames(&sNC, p->pEList) ) return WRC_Abort;
|
||||
sNC.ncFlags &= ~NC_AllowWin;
|
||||
|
||||
/* If there are no aggregate functions in the result-set, and no GROUP BY
|
||||
|
||||
/* If there are no aggregate functions in the result-set, and no GROUP BY
|
||||
** expression, do not allow aggregates in any of the other expressions.
|
||||
*/
|
||||
assert( (p->selFlags & SF_Aggregate)==0 );
|
||||
|
@ -1688,14 +1688,14 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
}else{
|
||||
sNC.ncFlags &= ~NC_AllowAgg;
|
||||
}
|
||||
|
||||
|
||||
/* If a HAVING clause is present, then there must be a GROUP BY clause.
|
||||
*/
|
||||
if( p->pHaving && !pGroupBy ){
|
||||
sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
|
||||
return WRC_Abort;
|
||||
}
|
||||
|
||||
|
||||
/* Add the output column list to the name-context before parsing the
|
||||
** other expressions in the SELECT statement. This is so that
|
||||
** expressions in the WHERE clause (etc.) can refer to expressions by
|
||||
|
@ -1714,19 +1714,19 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
for(i=0; i<p->pSrc->nSrc; i++){
|
||||
SrcItem *pItem = &p->pSrc->a[i];
|
||||
if( pItem->fg.isTabFunc
|
||||
&& sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg)
|
||||
&& sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg)
|
||||
){
|
||||
return WRC_Abort;
|
||||
}
|
||||
}
|
||||
|
||||
/* The ORDER BY and GROUP BY clauses may not refer to terms in
|
||||
** outer queries
|
||||
** outer queries
|
||||
*/
|
||||
sNC.pNext = 0;
|
||||
sNC.ncFlags |= NC_AllowAgg|NC_AllowWin;
|
||||
|
||||
/* If this is a converted compound query, move the ORDER BY clause from
|
||||
/* If this is a converted compound query, move the ORDER BY clause from
|
||||
** the sub-query back to the parent query. At this point each term
|
||||
** within the ORDER BY clause has been transformed to an integer value.
|
||||
** These integers will be replaced by copies of the corresponding result
|
||||
|
@ -1756,13 +1756,13 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
return WRC_Abort;
|
||||
}
|
||||
sNC.ncFlags &= ~NC_AllowWin;
|
||||
|
||||
/* Resolve the GROUP BY clause. At the same time, make sure
|
||||
|
||||
/* Resolve the GROUP BY clause. At the same time, make sure
|
||||
** the GROUP BY clause does not contain aggregate functions.
|
||||
*/
|
||||
if( pGroupBy ){
|
||||
struct ExprList_item *pItem;
|
||||
|
||||
|
||||
if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
|
||||
return WRC_Abort;
|
||||
}
|
||||
|
@ -1817,7 +1817,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
** checking on function usage and set a flag if any aggregate functions
|
||||
** are seen.
|
||||
**
|
||||
** To resolve table columns references we look for nodes (or subtrees) of the
|
||||
** To resolve table columns references we look for nodes (or subtrees) of the
|
||||
** form X.Y.Z or Y.Z or just Z where
|
||||
**
|
||||
** X: The name of a database. Ex: "main" or "temp" or
|
||||
|
@ -1849,7 +1849,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
**
|
||||
** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b;
|
||||
**
|
||||
** Function calls are checked to make sure that the function is
|
||||
** Function calls are checked to make sure that the function is
|
||||
** defined and that the correct number of arguments are specified.
|
||||
** If the function is an aggregate function, then the NC_HasAgg flag is
|
||||
** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION.
|
||||
|
@ -1859,7 +1859,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
|||
** An error message is left in pParse if anything is amiss. The number
|
||||
** if errors is returned.
|
||||
*/
|
||||
int sqlite3ResolveExprNames(
|
||||
int sqlite3ResolveExprNames(
|
||||
NameContext *pNC, /* Namespace to resolve expressions in. */
|
||||
Expr *pExpr /* The expression to be analyzed. */
|
||||
){
|
||||
|
@ -1898,7 +1898,7 @@ int sqlite3ResolveExprNames(
|
|||
** just like sqlite3ResolveExprNames() except that it works for an expression
|
||||
** list rather than a single expression.
|
||||
*/
|
||||
int sqlite3ResolveExprListNames(
|
||||
int sqlite3ResolveExprListNames(
|
||||
NameContext *pNC, /* Namespace to resolve expressions in. */
|
||||
ExprList *pList /* The expression list to be analyzed. */
|
||||
){
|
||||
|
|
8
third_party/sqlite3/rowset.c
vendored
8
third_party/sqlite3/rowset.c
vendored
|
@ -84,7 +84,7 @@
|
|||
** in the list, pLeft points to the tree, and v is unused. The
|
||||
** RowSet.pForest value points to the head of this forest list.
|
||||
*/
|
||||
struct RowSetEntry {
|
||||
struct RowSetEntry {
|
||||
i64 v; /* ROWID value for this entry */
|
||||
struct RowSetEntry *pRight; /* Right subtree (larger entries) or list */
|
||||
struct RowSetEntry *pLeft; /* Left subtree (smaller entries) */
|
||||
|
@ -236,7 +236,7 @@ void sqlite3RowSetInsert(RowSet *p, i64 rowid){
|
|||
/*
|
||||
** Merge two lists of RowSetEntry objects. Remove duplicates.
|
||||
**
|
||||
** The input lists are connected via pRight pointers and are
|
||||
** The input lists are connected via pRight pointers and are
|
||||
** assumed to each already be in sorted order.
|
||||
*/
|
||||
static struct RowSetEntry *rowSetEntryMerge(
|
||||
|
@ -273,7 +273,7 @@ static struct RowSetEntry *rowSetEntryMerge(
|
|||
/*
|
||||
** Sort all elements on the list of RowSetEntry objects into order of
|
||||
** increasing v.
|
||||
*/
|
||||
*/
|
||||
static struct RowSetEntry *rowSetEntrySort(struct RowSetEntry *pIn){
|
||||
unsigned int i;
|
||||
struct RowSetEntry *pNext, *aBucket[40];
|
||||
|
@ -346,7 +346,7 @@ static struct RowSetEntry *rowSetNDeepTree(
|
|||
struct RowSetEntry *pLeft; /* Left subtree */
|
||||
if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
|
||||
/* Prevent unnecessary deep recursion when we run out of entries */
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
if( iDepth>1 ){ /*OPTIMIZATION-IF-TRUE*/
|
||||
/* This branch causes a *balanced* tree to be generated. A valid tree
|
||||
|
|
286
third_party/sqlite3/rtree.c
vendored
286
third_party/sqlite3/rtree.c
vendored
|
@ -18,7 +18,7 @@
|
|||
** Database Format of R-Tree Tables
|
||||
** --------------------------------
|
||||
**
|
||||
** The data structure for a single virtual r-tree table is stored in three
|
||||
** The data structure for a single virtual r-tree table is stored in three
|
||||
** native SQLite tables declared as follows. In each case, the '%' character
|
||||
** in the table name is replaced with the user-supplied name of the r-tree
|
||||
** table.
|
||||
|
@ -44,7 +44,7 @@
|
|||
** of the node contain the tree depth as a big-endian integer.
|
||||
** For non-root nodes, the first 2 bytes are left unused.
|
||||
**
|
||||
** 2. The next 2 bytes contain the number of entries currently
|
||||
** 2. The next 2 bytes contain the number of entries currently
|
||||
** stored in the node.
|
||||
**
|
||||
** 3. The remainder of the node contains the node entries. Each entry
|
||||
|
@ -108,7 +108,7 @@ typedef struct RtreeSearchPoint RtreeSearchPoint;
|
|||
#define RTREE_MAX_AUX_COLUMN 100
|
||||
|
||||
/* Size of hash table Rtree.aHash. This hash table is not expected to
|
||||
** ever contain very many entries, so a fixed number of buckets is
|
||||
** ever contain very many entries, so a fixed number of buckets is
|
||||
** used.
|
||||
*/
|
||||
#define HASHSIZE 97
|
||||
|
@ -117,13 +117,13 @@ typedef struct RtreeSearchPoint RtreeSearchPoint;
|
|||
** the number of rows in the virtual table to calculate the costs of
|
||||
** various strategies. If possible, this estimate is loaded from the
|
||||
** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
|
||||
** Otherwise, if no sqlite_stat1 entry is available, use
|
||||
** Otherwise, if no sqlite_stat1 entry is available, use
|
||||
** RTREE_DEFAULT_ROWEST.
|
||||
*/
|
||||
#define RTREE_DEFAULT_ROWEST 1048576
|
||||
#define RTREE_MIN_ROWEST 100
|
||||
|
||||
/*
|
||||
/*
|
||||
** An rtree virtual-table object.
|
||||
*/
|
||||
struct Rtree {
|
||||
|
@ -142,7 +142,7 @@ struct Rtree {
|
|||
#endif
|
||||
int iDepth; /* Current depth of the r-tree structure */
|
||||
char *zDb; /* Name of database containing r-tree table */
|
||||
char *zName; /* Name of r-tree table */
|
||||
char *zName; /* Name of r-tree table */
|
||||
u32 nBusy; /* Current number of users of this structure */
|
||||
i64 nRowEst; /* Estimated number of rows in this table */
|
||||
u32 nCursor; /* Number of open cursors */
|
||||
|
@ -151,7 +151,7 @@ struct Rtree {
|
|||
|
||||
/* List of nodes removed during a CondenseTree operation. List is
|
||||
** linked together via the pointer normally used for hash chains -
|
||||
** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
|
||||
** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
|
||||
** headed by the node (leaf nodes have RtreeNode.iNode==0).
|
||||
*/
|
||||
RtreeNode *pDeleted;
|
||||
|
@ -177,7 +177,7 @@ struct Rtree {
|
|||
/* Statement for writing to the "aux:" fields, if there are any */
|
||||
sqlite3_stmt *pWriteAux;
|
||||
|
||||
RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
|
||||
RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
|
||||
};
|
||||
|
||||
/* Possible values for Rtree.eCoordType: */
|
||||
|
@ -226,7 +226,7 @@ struct RtreeSearchPoint {
|
|||
};
|
||||
|
||||
/*
|
||||
** The minimum number of cells allowed for a node is a third of the
|
||||
** The minimum number of cells allowed for a node is a third of the
|
||||
** maximum. In Gutman's notation:
|
||||
**
|
||||
** m = M/3
|
||||
|
@ -241,7 +241,7 @@ struct RtreeSearchPoint {
|
|||
/*
|
||||
** The smallest possible node-size is (512-64)==448 bytes. And the largest
|
||||
** supported cell size is 48 bytes (8 byte rowid + ten 4 byte coordinates).
|
||||
** Therefore all non-root nodes must contain at least 3 entries. Since
|
||||
** Therefore all non-root nodes must contain at least 3 entries. Since
|
||||
** 3^40 is greater than 2^64, an r-tree structure always has a depth of
|
||||
** 40 or less.
|
||||
*/
|
||||
|
@ -255,7 +255,7 @@ struct RtreeSearchPoint {
|
|||
*/
|
||||
#define RTREE_CACHE_SZ 5
|
||||
|
||||
/*
|
||||
/*
|
||||
** An rtree cursor object.
|
||||
*/
|
||||
struct RtreeCursor {
|
||||
|
@ -335,7 +335,7 @@ struct RtreeConstraint {
|
|||
#define RTREE_TRUE 0x3f /* ? */
|
||||
#define RTREE_FALSE 0x40 /* @ */
|
||||
|
||||
/*
|
||||
/*
|
||||
** An rtree structure node.
|
||||
*/
|
||||
struct RtreeNode {
|
||||
|
@ -350,7 +350,7 @@ struct RtreeNode {
|
|||
/* Return the number of cells in a node */
|
||||
#define NCELL(pNode) readInt16(&(pNode)->zData[2])
|
||||
|
||||
/*
|
||||
/*
|
||||
** A single cell from a node, deserialized
|
||||
*/
|
||||
struct RtreeCell {
|
||||
|
@ -365,11 +365,11 @@ struct RtreeCell {
|
|||
** sqlite3_rtree_query_callback() and which appear on the right of MATCH
|
||||
** operators in order to constrain a search.
|
||||
**
|
||||
** xGeom and xQueryFunc are the callback functions. Exactly one of
|
||||
** xGeom and xQueryFunc are the callback functions. Exactly one of
|
||||
** xGeom and xQueryFunc fields is non-NULL, depending on whether the
|
||||
** SQL function was created using sqlite3_rtree_geometry_callback() or
|
||||
** sqlite3_rtree_query_callback().
|
||||
**
|
||||
**
|
||||
** This object is deleted automatically by the destructor mechanism in
|
||||
** sqlite3_create_function_v2().
|
||||
*/
|
||||
|
@ -487,9 +487,9 @@ static void readCoord(u8 *p, RtreeCoord *pCoord){
|
|||
pCoord->u = *(u32*)p;
|
||||
#else
|
||||
pCoord->u = (
|
||||
(((u32)p[0]) << 24) +
|
||||
(((u32)p[1]) << 16) +
|
||||
(((u32)p[2]) << 8) +
|
||||
(((u32)p[0]) << 24) +
|
||||
(((u32)p[1]) << 16) +
|
||||
(((u32)p[2]) << 8) +
|
||||
(((u32)p[3]) << 0)
|
||||
);
|
||||
#endif
|
||||
|
@ -509,13 +509,13 @@ static i64 readInt64(u8 *p){
|
|||
return x;
|
||||
#else
|
||||
return (i64)(
|
||||
(((u64)p[0]) << 56) +
|
||||
(((u64)p[1]) << 48) +
|
||||
(((u64)p[2]) << 40) +
|
||||
(((u64)p[3]) << 32) +
|
||||
(((u64)p[4]) << 24) +
|
||||
(((u64)p[5]) << 16) +
|
||||
(((u64)p[6]) << 8) +
|
||||
(((u64)p[0]) << 56) +
|
||||
(((u64)p[1]) << 48) +
|
||||
(((u64)p[2]) << 40) +
|
||||
(((u64)p[3]) << 32) +
|
||||
(((u64)p[4]) << 24) +
|
||||
(((u64)p[5]) << 16) +
|
||||
(((u64)p[6]) << 8) +
|
||||
(((u64)p[7]) << 0)
|
||||
);
|
||||
#endif
|
||||
|
@ -769,7 +769,7 @@ static int nodeAcquire(
|
|||
}
|
||||
|
||||
/* If no error has occurred so far, check if the "number of entries"
|
||||
** field on the node is too large. If so, set the return code to
|
||||
** field on the node is too large. If so, set the return code to
|
||||
** SQLITE_CORRUPT_VTAB.
|
||||
*/
|
||||
if( pNode && rc==SQLITE_OK ){
|
||||
|
@ -968,7 +968,7 @@ static int rtreeInit(
|
|||
sqlite3 *, void *, int, const char *const*, sqlite3_vtab **, char **, int
|
||||
);
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xCreate method.
|
||||
*/
|
||||
static int rtreeCreate(
|
||||
|
@ -981,7 +981,7 @@ static int rtreeCreate(
|
|||
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xConnect method.
|
||||
*/
|
||||
static int rtreeConnect(
|
||||
|
@ -1026,7 +1026,7 @@ static void rtreeRelease(Rtree *pRtree){
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xDisconnect method.
|
||||
*/
|
||||
static int rtreeDisconnect(sqlite3_vtab *pVtab){
|
||||
|
@ -1034,7 +1034,7 @@ static int rtreeDisconnect(sqlite3_vtab *pVtab){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xDestroy method.
|
||||
*/
|
||||
static int rtreeDestroy(sqlite3_vtab *pVtab){
|
||||
|
@ -1044,7 +1044,7 @@ static int rtreeDestroy(sqlite3_vtab *pVtab){
|
|||
"DROP TABLE '%q'.'%q_node';"
|
||||
"DROP TABLE '%q'.'%q_rowid';"
|
||||
"DROP TABLE '%q'.'%q_parent';",
|
||||
pRtree->zDb, pRtree->zName,
|
||||
pRtree->zDb, pRtree->zName,
|
||||
pRtree->zDb, pRtree->zName,
|
||||
pRtree->zDb, pRtree->zName
|
||||
);
|
||||
|
@ -1062,7 +1062,7 @@ static int rtreeDestroy(sqlite3_vtab *pVtab){
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xOpen method.
|
||||
*/
|
||||
static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
|
||||
|
@ -1111,7 +1111,7 @@ static void resetCursor(RtreeCursor *pCsr){
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xClose method.
|
||||
*/
|
||||
static int rtreeClose(sqlite3_vtab_cursor *cur){
|
||||
|
@ -1129,7 +1129,7 @@ static int rtreeClose(sqlite3_vtab_cursor *cur){
|
|||
/*
|
||||
** Rtree virtual table module xEof method.
|
||||
**
|
||||
** Return non-zero if the cursor does not currently point to a valid
|
||||
** Return non-zero if the cursor does not currently point to a valid
|
||||
** record (i.e if the scan has finished), or zero otherwise.
|
||||
*/
|
||||
static int rtreeEof(sqlite3_vtab_cursor *cur){
|
||||
|
@ -1185,7 +1185,7 @@ static int rtreeEof(sqlite3_vtab_cursor *cur){
|
|||
|
||||
/*
|
||||
** Check the RTree node or entry given by pCellData and p against the MATCH
|
||||
** constraint pConstraint.
|
||||
** constraint pConstraint.
|
||||
*/
|
||||
static int rtreeCallbackConstraint(
|
||||
RtreeConstraint *pConstraint, /* The constraint to test */
|
||||
|
@ -1258,7 +1258,7 @@ static int rtreeCallbackConstraint(
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Check the internal RTree node given by pCellData against constraint p.
|
||||
** If this constraint cannot be satisfied by any child within the node,
|
||||
** set *peWithin to NOT_WITHIN.
|
||||
|
@ -1276,7 +1276,7 @@ static void rtreeNonleafConstraint(
|
|||
*/
|
||||
pCellData += 8 + 4*(p->iCoord&0xfe);
|
||||
|
||||
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
|
||||
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
|
||||
|| p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
|
||||
|| p->op==RTREE_FALSE );
|
||||
assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
|
||||
|
@ -1319,7 +1319,7 @@ static void rtreeLeafConstraint(
|
|||
){
|
||||
RtreeDValue xN; /* Coordinate value converted to a double */
|
||||
|
||||
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
|
||||
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
|
||||
|| p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
|
||||
|| p->op==RTREE_FALSE );
|
||||
pCellData += 8 + p->iCoord*4;
|
||||
|
@ -1338,12 +1338,12 @@ static void rtreeLeafConstraint(
|
|||
}
|
||||
|
||||
/*
|
||||
** One of the cells in node pNode is guaranteed to have a 64-bit
|
||||
** One of the cells in node pNode is guaranteed to have a 64-bit
|
||||
** integer value equal to iRowid. Return the index of this cell.
|
||||
*/
|
||||
static int nodeRowidIndex(
|
||||
Rtree *pRtree,
|
||||
RtreeNode *pNode,
|
||||
Rtree *pRtree,
|
||||
RtreeNode *pNode,
|
||||
i64 iRowid,
|
||||
int *piIndex
|
||||
){
|
||||
|
@ -1485,7 +1485,7 @@ static RtreeSearchPoint *rtreeSearchPointNew(
|
|||
pFirst = rtreeSearchPointFirst(pCur);
|
||||
pCur->anQueue[iLevel]++;
|
||||
if( pFirst==0
|
||||
|| pFirst->rScore>rScore
|
||||
|| pFirst->rScore>rScore
|
||||
|| (pFirst->rScore==rScore && pFirst->iLevel>iLevel)
|
||||
){
|
||||
if( pCur->bPoint ){
|
||||
|
@ -1669,7 +1669,7 @@ static int rtreeStepToLeaf(RtreeCursor *pCur){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xNext method.
|
||||
*/
|
||||
static int rtreeNext(sqlite3_vtab_cursor *pVtabCursor){
|
||||
|
@ -1687,7 +1687,7 @@ static int rtreeNext(sqlite3_vtab_cursor *pVtabCursor){
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xRowid method.
|
||||
*/
|
||||
static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
|
||||
|
@ -1701,7 +1701,7 @@ static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xColumn method.
|
||||
*/
|
||||
static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
||||
|
@ -1734,7 +1734,7 @@ static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
|||
&pCsr->pReadAux, 0);
|
||||
if( rc ) return rc;
|
||||
}
|
||||
sqlite3_bind_int64(pCsr->pReadAux, 1,
|
||||
sqlite3_bind_int64(pCsr->pReadAux, 1,
|
||||
nodeGetRowid(pRtree, pNode, p->iCell));
|
||||
rc = sqlite3_step(pCsr->pReadAux);
|
||||
if( rc==SQLITE_ROW ){
|
||||
|
@ -1747,12 +1747,12 @@ static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
|||
}
|
||||
sqlite3_result_value(ctx,
|
||||
sqlite3_column_value(pCsr->pReadAux, i - pRtree->nDim2 + 1));
|
||||
}
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Use nodeAcquire() to obtain the leaf node containing the record with
|
||||
/*
|
||||
** Use nodeAcquire() to obtain the leaf node containing the record with
|
||||
** rowid iRowid. If successful, set *ppLeaf to point to the node and
|
||||
** return SQLITE_OK. If there is no such record in the table, set
|
||||
** *ppLeaf to 0 and return SQLITE_OK. If an error occurs, set *ppLeaf
|
||||
|
@ -1811,11 +1811,11 @@ static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Rtree virtual table module xFilter method.
|
||||
*/
|
||||
static int rtreeFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -1860,8 +1860,8 @@ static int rtreeFilter(
|
|||
pCsr->atEOF = 1;
|
||||
}
|
||||
}else{
|
||||
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
|
||||
** with the configured constraints.
|
||||
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
|
||||
** with the configured constraints.
|
||||
*/
|
||||
rc = nodeAcquire(pRtree, 1, 0, &pRoot);
|
||||
if( rc==SQLITE_OK && argc>0 ){
|
||||
|
@ -1932,7 +1932,7 @@ static int rtreeFilter(
|
|||
|
||||
/*
|
||||
** Rtree virtual table module xBestIndex method. There are three
|
||||
** table scan strategies to choose from (in order from most to
|
||||
** table scan strategies to choose from (in order from most to
|
||||
** least desirable):
|
||||
**
|
||||
** idxNum idxStr Strategy
|
||||
|
@ -1942,8 +1942,8 @@ static int rtreeFilter(
|
|||
** ------------------------------------------------
|
||||
**
|
||||
** If strategy 1 is used, then idxStr is not meaningful. If strategy
|
||||
** 2 is used, idxStr is formatted to contain 2 bytes for each
|
||||
** constraint used. The first two bytes of idxStr correspond to
|
||||
** 2 is used, idxStr is formatted to contain 2 bytes for each
|
||||
** constraint used. The first two bytes of idxStr correspond to
|
||||
** the constraint in sqlite3_index_info.aConstraintUsage[] with
|
||||
** (argvIndex==1) etc.
|
||||
**
|
||||
|
@ -1989,8 +1989,8 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
|||
for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
|
||||
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
|
||||
|
||||
if( bMatch==0 && p->usable
|
||||
&& p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
|
||||
if( bMatch==0 && p->usable
|
||||
&& p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
|
||||
){
|
||||
/* We have an equality constraint on the rowid. Use strategy 1. */
|
||||
int jj;
|
||||
|
@ -2003,11 +2003,11 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
|||
pIdxInfo->aConstraintUsage[jj].omit = 1;
|
||||
|
||||
/* This strategy involves a two rowid lookups on an B-Tree structures
|
||||
** and then a linear search of an R-Tree node. This should be
|
||||
** considered almost as quick as a direct rowid lookup (for which
|
||||
** and then a linear search of an R-Tree node. This should be
|
||||
** considered almost as quick as a direct rowid lookup (for which
|
||||
** sqlite uses an internal cost of 0.0). It is expected to return
|
||||
** a single row.
|
||||
*/
|
||||
*/
|
||||
pIdxInfo->estimatedCost = 30.0;
|
||||
pIdxInfo->estimatedRows = 1;
|
||||
pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_UNIQUE;
|
||||
|
@ -2123,8 +2123,8 @@ static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
|
|||
for(ii=0; ii<pRtree->nDim2; ii+=2){
|
||||
RtreeCoord *a1 = &p1->aCoord[ii];
|
||||
RtreeCoord *a2 = &p2->aCoord[ii];
|
||||
if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f))
|
||||
|| ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i))
|
||||
if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f))
|
||||
|| ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i))
|
||||
){
|
||||
return 0;
|
||||
}
|
||||
|
@ -2145,9 +2145,9 @@ static RtreeDValue cellGrowth(Rtree *pRtree, RtreeCell *p, RtreeCell *pCell){
|
|||
}
|
||||
|
||||
static RtreeDValue cellOverlap(
|
||||
Rtree *pRtree,
|
||||
RtreeCell *p,
|
||||
RtreeCell *aCell,
|
||||
Rtree *pRtree,
|
||||
RtreeCell *p,
|
||||
RtreeCell *aCell,
|
||||
int nCell
|
||||
){
|
||||
int ii;
|
||||
|
@ -2258,7 +2258,7 @@ static int AdjustTree(
|
|||
cellUnion(pRtree, &cell, pCell);
|
||||
nodeOverwriteCell(pRtree, pParent, &cell, iCell);
|
||||
}
|
||||
|
||||
|
||||
p = pParent;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
|
@ -2289,7 +2289,7 @@ static int rtreeInsertCell(Rtree *, RtreeNode *, RtreeCell *, int);
|
|||
|
||||
/*
|
||||
** Arguments aIdx, aDistance and aSpare all point to arrays of size
|
||||
** nIdx. The aIdx array contains the set of integers from 0 to
|
||||
** nIdx. The aIdx array contains the set of integers from 0 to
|
||||
** (nIdx-1) in no particular order. This function sorts the values
|
||||
** in aIdx according to the indexed values in aDistance. For
|
||||
** example, assuming the inputs:
|
||||
|
@ -2305,9 +2305,9 @@ static int rtreeInsertCell(Rtree *, RtreeNode *, RtreeCell *, int);
|
|||
** sorting algorithm.
|
||||
*/
|
||||
static void SortByDistance(
|
||||
int *aIdx,
|
||||
int nIdx,
|
||||
RtreeDValue *aDistance,
|
||||
int *aIdx,
|
||||
int nIdx,
|
||||
RtreeDValue *aDistance,
|
||||
int *aSpare
|
||||
){
|
||||
if( nIdx>1 ){
|
||||
|
@ -2361,7 +2361,7 @@ static void SortByDistance(
|
|||
|
||||
/*
|
||||
** Arguments aIdx, aCell and aSpare all point to arrays of size
|
||||
** nIdx. The aIdx array contains the set of integers from 0 to
|
||||
** nIdx. The aIdx array contains the set of integers from 0 to
|
||||
** (nIdx-1) in no particular order. This function sorts the values
|
||||
** in aIdx according to dimension iDim of the cells in aCell. The
|
||||
** minimum value of dimension iDim is considered first, the
|
||||
|
@ -2372,10 +2372,10 @@ static void SortByDistance(
|
|||
*/
|
||||
static void SortByDimension(
|
||||
Rtree *pRtree,
|
||||
int *aIdx,
|
||||
int nIdx,
|
||||
int iDim,
|
||||
RtreeCell *aCell,
|
||||
int *aIdx,
|
||||
int nIdx,
|
||||
int iDim,
|
||||
RtreeCell *aCell,
|
||||
int *aSpare
|
||||
){
|
||||
if( nIdx>1 ){
|
||||
|
@ -2472,8 +2472,8 @@ static int splitNodeStartree(
|
|||
int nLeft;
|
||||
|
||||
for(
|
||||
nLeft=RTREE_MINCELLS(pRtree);
|
||||
nLeft<=(nCell-RTREE_MINCELLS(pRtree));
|
||||
nLeft=RTREE_MINCELLS(pRtree);
|
||||
nLeft<=(nCell-RTREE_MINCELLS(pRtree));
|
||||
nLeft++
|
||||
){
|
||||
RtreeCell left;
|
||||
|
@ -2528,9 +2528,9 @@ static int splitNodeStartree(
|
|||
|
||||
|
||||
static int updateMapping(
|
||||
Rtree *pRtree,
|
||||
i64 iRowid,
|
||||
RtreeNode *pNode,
|
||||
Rtree *pRtree,
|
||||
i64 iRowid,
|
||||
RtreeNode *pNode,
|
||||
int iHeight
|
||||
){
|
||||
int (*xSetMapping)(Rtree *, sqlite3_int64, sqlite3_int64);
|
||||
|
@ -2566,7 +2566,7 @@ static int SplitNode(
|
|||
RtreeCell leftbbox;
|
||||
RtreeCell rightbbox;
|
||||
|
||||
/* Allocate an array and populate it with a copy of pCell and
|
||||
/* Allocate an array and populate it with a copy of pCell and
|
||||
** all cells from node pLeft. Then zero the original node.
|
||||
*/
|
||||
aCell = sqlite3_malloc64((sizeof(RtreeCell)+sizeof(int))*(nCell+1));
|
||||
|
@ -2683,14 +2683,14 @@ splitnode_out:
|
|||
}
|
||||
|
||||
/*
|
||||
** If node pLeaf is not the root of the r-tree and its pParent pointer is
|
||||
** If node pLeaf is not the root of the r-tree and its pParent pointer is
|
||||
** still NULL, load all ancestor nodes of pLeaf into memory and populate
|
||||
** the pLeaf->pParent chain all the way up to the root node.
|
||||
**
|
||||
** This operation is required when a row is deleted (or updated - an update
|
||||
** is implemented as a delete followed by an insert). SQLite provides the
|
||||
** rowid of the row to delete, which can be used to find the leaf on which
|
||||
** the entry resides (argument pLeaf). Once the leaf is located, this
|
||||
** the entry resides (argument pLeaf). Once the leaf is located, this
|
||||
** function is called to determine its ancestry.
|
||||
*/
|
||||
static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
|
||||
|
@ -2764,7 +2764,7 @@ static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
|
|||
if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteParent)) ){
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/* Remove the node from the in-memory hash table and link it into
|
||||
** the Rtree.pDeleted list. Its contents will be re-inserted later on.
|
||||
*/
|
||||
|
@ -2779,9 +2779,9 @@ static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
|
|||
|
||||
static int fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){
|
||||
RtreeNode *pParent = pNode->pParent;
|
||||
int rc = SQLITE_OK;
|
||||
int rc = SQLITE_OK;
|
||||
if( pParent ){
|
||||
int ii;
|
||||
int ii;
|
||||
int nCell = NCELL(pNode);
|
||||
RtreeCell box; /* Bounding box for pNode */
|
||||
nodeGetCell(pRtree, pNode, 0, &box);
|
||||
|
@ -2836,9 +2836,9 @@ static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){
|
|||
}
|
||||
|
||||
static int Reinsert(
|
||||
Rtree *pRtree,
|
||||
RtreeNode *pNode,
|
||||
RtreeCell *pCell,
|
||||
Rtree *pRtree,
|
||||
RtreeNode *pNode,
|
||||
RtreeCell *pCell,
|
||||
int iHeight
|
||||
){
|
||||
int *aOrder;
|
||||
|
@ -2892,7 +2892,7 @@ static int Reinsert(
|
|||
for(ii=0; ii<nCell; ii++){
|
||||
aDistance[ii] = RTREE_ZERO;
|
||||
for(iDim=0; iDim<pRtree->nDim; iDim++){
|
||||
RtreeDValue coord = (DCOORD(aCell[ii].aCoord[iDim*2+1]) -
|
||||
RtreeDValue coord = (DCOORD(aCell[ii].aCoord[iDim*2+1]) -
|
||||
DCOORD(aCell[ii].aCoord[iDim*2]));
|
||||
aDistance[ii] += (coord-aCenterCoord[iDim])*(coord-aCenterCoord[iDim]);
|
||||
}
|
||||
|
@ -2937,7 +2937,7 @@ static int Reinsert(
|
|||
}
|
||||
|
||||
/*
|
||||
** Insert cell pCell into node pNode. Node pNode is the head of a
|
||||
** Insert cell pCell into node pNode. Node pNode is the head of a
|
||||
** subtree iHeight high (leaf nodes have iHeight==0).
|
||||
*/
|
||||
static int rtreeInsertCell(
|
||||
|
@ -3027,8 +3027,8 @@ static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
|
|||
/* Obtain a reference to the root node to initialize Rtree.iDepth */
|
||||
rc = nodeAcquire(pRtree, 1, 0, &pRoot);
|
||||
|
||||
/* Obtain a reference to the leaf node that contains the entry
|
||||
** about to be deleted.
|
||||
/* Obtain a reference to the leaf node that contains the entry
|
||||
** about to be deleted.
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
|
||||
|
@ -3059,11 +3059,11 @@ static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
|
|||
}
|
||||
|
||||
/* Check if the root node now has exactly one child. If so, remove
|
||||
** it, schedule the contents of the child for reinsertion and
|
||||
** it, schedule the contents of the child for reinsertion and
|
||||
** reduce the tree height by one.
|
||||
**
|
||||
** This is equivalent to copying the contents of the child into
|
||||
** the root node (the operation that Gutman's paper says to perform
|
||||
** the root node (the operation that Gutman's paper says to perform
|
||||
** in this scenario).
|
||||
*/
|
||||
if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
|
||||
|
@ -3133,8 +3133,8 @@ static RtreeValue rtreeValueUp(sqlite3_value *v){
|
|||
#endif /* !defined(SQLITE_RTREE_INT_ONLY) */
|
||||
|
||||
/*
|
||||
** A constraint has failed while inserting a row into an rtree table.
|
||||
** Assuming no OOM error occurs, this function sets the error message
|
||||
** A constraint has failed while inserting a row into an rtree table.
|
||||
** Assuming no OOM error occurs, this function sets the error message
|
||||
** (at pRtree->base.zErrMsg) to an appropriate value and returns
|
||||
** SQLITE_CONSTRAINT.
|
||||
**
|
||||
|
@ -3147,7 +3147,7 @@ static RtreeValue rtreeValueUp(sqlite3_value *v){
|
|||
*/
|
||||
static int rtreeConstraintError(Rtree *pRtree, int iCol){
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
char *zSql;
|
||||
char *zSql;
|
||||
int rc;
|
||||
|
||||
assert( iCol==0 || iCol%2 );
|
||||
|
@ -3184,9 +3184,9 @@ static int rtreeConstraintError(Rtree *pRtree, int iCol){
|
|||
** The xUpdate method for rtree module virtual tables.
|
||||
*/
|
||||
static int rtreeUpdate(
|
||||
sqlite3_vtab *pVtab,
|
||||
int nData,
|
||||
sqlite3_value **aData,
|
||||
sqlite3_vtab *pVtab,
|
||||
int nData,
|
||||
sqlite3_value **aData,
|
||||
sqlite_int64 *pRowid
|
||||
){
|
||||
Rtree *pRtree = (Rtree *)pVtab;
|
||||
|
@ -3253,7 +3253,7 @@ static int rtreeUpdate(
|
|||
}
|
||||
}
|
||||
|
||||
/* If a rowid value was supplied, check if it is already present in
|
||||
/* If a rowid value was supplied, check if it is already present in
|
||||
** the table. If so, the constraint has failed. */
|
||||
if( sqlite3_value_type(aData[2])!=SQLITE_NULL ){
|
||||
cell.iRowid = sqlite3_value_int64(aData[2]);
|
||||
|
@ -3359,8 +3359,8 @@ static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){
|
|||
"ALTER TABLE %Q.'%q_node' RENAME TO \"%w_node\";"
|
||||
"ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";"
|
||||
"ALTER TABLE %Q.'%q_rowid' RENAME TO \"%w_rowid\";"
|
||||
, pRtree->zDb, pRtree->zName, zNewName
|
||||
, pRtree->zDb, pRtree->zName, zNewName
|
||||
, pRtree->zDb, pRtree->zName, zNewName
|
||||
, pRtree->zDb, pRtree->zName, zNewName
|
||||
, pRtree->zDb, pRtree->zName, zNewName
|
||||
);
|
||||
if( zSql ){
|
||||
|
@ -3375,8 +3375,8 @@ static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){
|
|||
** The xSavepoint method.
|
||||
**
|
||||
** This module does not need to do anything to support savepoints. However,
|
||||
** it uses this hook to close any open blob handle. This is done because a
|
||||
** DROP TABLE command - which fortunately always opens a savepoint - cannot
|
||||
** it uses this hook to close any open blob handle. This is done because a
|
||||
** DROP TABLE command - which fortunately always opens a savepoint - cannot
|
||||
** succeed if there are any open blob handles. i.e. if the blob handle were
|
||||
** not closed here, the following would fail:
|
||||
**
|
||||
|
@ -3483,10 +3483,10 @@ static sqlite3_module rtreeModule = {
|
|||
};
|
||||
|
||||
static int rtreeSqlInit(
|
||||
Rtree *pRtree,
|
||||
sqlite3 *db,
|
||||
const char *zDb,
|
||||
const char *zPrefix,
|
||||
Rtree *pRtree,
|
||||
sqlite3 *db,
|
||||
const char *zDb,
|
||||
const char *zPrefix,
|
||||
int isCreate
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
|
@ -3566,7 +3566,7 @@ static int rtreeSqlInit(
|
|||
}
|
||||
zSql = sqlite3_mprintf(zFormat, zDb, zPrefix);
|
||||
if( zSql ){
|
||||
rc = sqlite3_prepare_v3(db, zSql, -1, f, appStmt[i], 0);
|
||||
rc = sqlite3_prepare_v3(db, zSql, -1, f, appStmt[i], 0);
|
||||
}else{
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
|
@ -3596,7 +3596,7 @@ static int rtreeSqlInit(
|
|||
if( zSql==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
|
||||
rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
|
||||
sqlite3_free(zSql);
|
||||
}
|
||||
}
|
||||
|
@ -3637,9 +3637,9 @@ static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
|
|||
** table already exists. In this case the node-size is determined by inspecting
|
||||
** the root node of the tree.
|
||||
**
|
||||
** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
|
||||
** This ensures that each node is stored on a single database page. If the
|
||||
** database page-size is so large that more than RTREE_MAXCELLS entries
|
||||
** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
|
||||
** This ensures that each node is stored on a single database page. If the
|
||||
** database page-size is so large that more than RTREE_MAXCELLS entries
|
||||
** would fit in a single node, use a smaller node-size.
|
||||
*/
|
||||
static int getNodeSize(
|
||||
|
@ -3690,7 +3690,7 @@ static int rtreeTokenLength(const char *z){
|
|||
return sqlite3GetToken((const unsigned char*)z,&dummy);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** This function is the implementation of both the xConnect and xCreate
|
||||
** methods of the r-tree virtual table.
|
||||
**
|
||||
|
@ -3755,7 +3755,7 @@ static int rtreeInit(
|
|||
** the r-tree table schema.
|
||||
*/
|
||||
pSql = sqlite3_str_new(db);
|
||||
sqlite3_str_appendf(pSql, "CREATE TABLE x(%.*s INT",
|
||||
sqlite3_str_appendf(pSql, "CREATE TABLE x(%.*s INT",
|
||||
rtreeTokenLength(argv[3]), argv[3]);
|
||||
for(ii=4; ii<argc; ii++){
|
||||
const char *zArg = argv[ii];
|
||||
|
@ -3833,7 +3833,7 @@ rtreeInit_fail:
|
|||
**
|
||||
** The human readable string takes the form of a Tcl list with one
|
||||
** entry for each cell in the r-tree node. Each entry is itself a
|
||||
** list, containing the 8-byte rowid/pageno followed by the
|
||||
** list, containing the 8-byte rowid/pageno followed by the
|
||||
** <num-dimension>*2 coordinates.
|
||||
*/
|
||||
static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
|
||||
|
@ -3889,10 +3889,10 @@ static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
|
|||
*/
|
||||
static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
|
||||
UNUSED_PARAMETER(nArg);
|
||||
if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
|
||||
if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
|
||||
|| sqlite3_value_bytes(apArg[0])<2
|
||||
){
|
||||
sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1);
|
||||
sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1);
|
||||
}else{
|
||||
u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
|
||||
sqlite3_result_int(ctx, readInt16(zBlob));
|
||||
|
@ -3975,7 +3975,7 @@ static void rtreeCheckAppendMsg(RtreeCheck *pCheck, const char *zFmt, ...){
|
|||
if( z==0 ){
|
||||
pCheck->rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
pCheck->zReport = sqlite3_mprintf("%z%s%z",
|
||||
pCheck->zReport = sqlite3_mprintf("%z%s%z",
|
||||
pCheck->zReport, (pCheck->zReport ? "\n" : ""), z
|
||||
);
|
||||
if( pCheck->zReport==0 ){
|
||||
|
@ -4006,7 +4006,7 @@ static u8 *rtreeCheckGetNode(RtreeCheck *pCheck, i64 iNode, int *pnNode){
|
|||
|
||||
if( pCheck->rc==SQLITE_OK && pCheck->pGetNode==0 ){
|
||||
pCheck->pGetNode = rtreeCheckPrepare(pCheck,
|
||||
"SELECT data FROM %Q.'%q_node' WHERE nodeno=?",
|
||||
"SELECT data FROM %Q.'%q_node' WHERE nodeno=?",
|
||||
pCheck->zDb, pCheck->zTab
|
||||
);
|
||||
}
|
||||
|
@ -4076,7 +4076,7 @@ static void rtreeCheckMapping(
|
|||
}else if( rc==SQLITE_ROW ){
|
||||
i64 ii = sqlite3_column_int64(pStmt, 0);
|
||||
if( ii!=iVal ){
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
"Found (%lld -> %lld) in %s table, expected (%lld -> %lld)",
|
||||
iKey, ii, (bLeaf ? "%_rowid" : "%_parent"), iKey, iVal
|
||||
);
|
||||
|
@ -4092,13 +4092,13 @@ static void rtreeCheckMapping(
|
|||
** if they are not.
|
||||
**
|
||||
** Additionally, if pParent is not NULL, then it is assumed to point to
|
||||
** the array of coordinates on the parent page that bound the page
|
||||
** the array of coordinates on the parent page that bound the page
|
||||
** containing pCell. In this case it is also verified that the two
|
||||
** sets of coordinates are mutually consistent and an error message added
|
||||
** to the RtreeCheck object if they are not.
|
||||
*/
|
||||
static void rtreeCheckCellCoord(
|
||||
RtreeCheck *pCheck,
|
||||
RtreeCheck *pCheck,
|
||||
i64 iNode, /* Node id to use in error messages */
|
||||
int iCell, /* Cell number to use in error messages */
|
||||
u8 *pCell, /* Pointer to cell coordinates */
|
||||
|
@ -4114,7 +4114,7 @@ static void rtreeCheckCellCoord(
|
|||
|
||||
/* printf("%e, %e\n", c1.u.f, c2.u.f); */
|
||||
if( pCheck->bInt ? c1.i>c2.i : c1.f>c2.f ){
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
"Dimension %d of cell %d on node %lld is corrupt", i, iCell, iNode
|
||||
);
|
||||
}
|
||||
|
@ -4123,10 +4123,10 @@ static void rtreeCheckCellCoord(
|
|||
readCoord(&pParent[4*2*i], &p1);
|
||||
readCoord(&pParent[4*(2*i + 1)], &p2);
|
||||
|
||||
if( (pCheck->bInt ? c1.i<p1.i : c1.f<p1.f)
|
||||
if( (pCheck->bInt ? c1.i<p1.i : c1.f<p1.f)
|
||||
|| (pCheck->bInt ? c2.i>p2.i : c2.f>p2.f)
|
||||
){
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
"Dimension %d of cell %d on node %lld is corrupt relative to parent"
|
||||
, i, iCell, iNode
|
||||
);
|
||||
|
@ -4158,7 +4158,7 @@ static void rtreeCheckNode(
|
|||
aNode = rtreeCheckGetNode(pCheck, iNode, &nNode);
|
||||
if( aNode ){
|
||||
if( nNode<4 ){
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
"Node %lld is too small (%d bytes)", iNode, nNode
|
||||
);
|
||||
}else{
|
||||
|
@ -4174,8 +4174,8 @@ static void rtreeCheckNode(
|
|||
}
|
||||
nCell = readInt16(&aNode[2]);
|
||||
if( (4 + nCell*(8 + pCheck->nDim*2*4))>nNode ){
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
"Node %lld is too small for cell count of %d (%d bytes)",
|
||||
rtreeCheckAppendMsg(pCheck,
|
||||
"Node %lld is too small for cell count of %d (%d bytes)",
|
||||
iNode, nCell, nNode
|
||||
);
|
||||
}else{
|
||||
|
@ -4318,11 +4318,11 @@ static int rtreeCheckTable(
|
|||
** b) unless the cell is on the root node, that the cell is bounded
|
||||
** by the parent cell on the parent node.
|
||||
**
|
||||
** c) for leaf nodes, that there is an entry in the %_rowid
|
||||
** table corresponding to the cell's rowid value that
|
||||
** c) for leaf nodes, that there is an entry in the %_rowid
|
||||
** table corresponding to the cell's rowid value that
|
||||
** points to the correct node.
|
||||
**
|
||||
** d) for cells on non-leaf nodes, that there is an entry in the
|
||||
** d) for cells on non-leaf nodes, that there is an entry in the
|
||||
** %_parent table mapping from the cell's child node to the
|
||||
** node that it resides on.
|
||||
**
|
||||
|
@ -4331,17 +4331,17 @@ static int rtreeCheckTable(
|
|||
** is a leaf cell that corresponds to each entry in the %_rowid table.
|
||||
**
|
||||
** 3. That there are the same number of entries in the %_parent table
|
||||
** as there are non-leaf cells in the r-tree structure, and that
|
||||
** there is a non-leaf cell that corresponds to each entry in the
|
||||
** as there are non-leaf cells in the r-tree structure, and that
|
||||
** there is a non-leaf cell that corresponds to each entry in the
|
||||
** %_parent table.
|
||||
*/
|
||||
static void rtreecheck(
|
||||
sqlite3_context *ctx,
|
||||
int nArg,
|
||||
sqlite3_context *ctx,
|
||||
int nArg,
|
||||
sqlite3_value **apArg
|
||||
){
|
||||
if( nArg!=1 && nArg!=2 ){
|
||||
sqlite3_result_error(ctx,
|
||||
sqlite3_result_error(ctx,
|
||||
"wrong number of arguments to function rtreecheck()", -1
|
||||
);
|
||||
}else{
|
||||
|
@ -4372,7 +4372,7 @@ static void rtreecheck(
|
|||
|
||||
/*
|
||||
** Register the r-tree module with database handle db. This creates the
|
||||
** virtual table module "rtree" and the debugging/analysis scalar
|
||||
** virtual table module "rtree" and the debugging/analysis scalar
|
||||
** function "rtreenode".
|
||||
*/
|
||||
int sqlite3RtreeInit(sqlite3 *db){
|
||||
|
@ -4499,7 +4499,7 @@ int sqlite3_rtree_geometry_callback(
|
|||
pGeomCtx->xQueryFunc = 0;
|
||||
pGeomCtx->xDestructor = 0;
|
||||
pGeomCtx->pContext = pContext;
|
||||
return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
|
||||
return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
|
||||
(void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
|
||||
);
|
||||
}
|
||||
|
@ -4524,7 +4524,7 @@ int sqlite3_rtree_query_callback(
|
|||
pGeomCtx->xQueryFunc = xQueryFunc;
|
||||
pGeomCtx->xDestructor = xDestructor;
|
||||
pGeomCtx->pContext = pContext;
|
||||
return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
|
||||
return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
|
||||
(void *)pGeomCtx, geomCallback, 0, 0, rtreeFreeCallback
|
||||
);
|
||||
}
|
||||
|
|
332
third_party/sqlite3/select.c
vendored
332
third_party/sqlite3/select.c
vendored
File diff suppressed because it is too large
Load diff
14
third_party/sqlite3/series.c
vendored
14
third_party/sqlite3/series.c
vendored
|
@ -225,7 +225,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
|
|||
}
|
||||
}
|
||||
|
||||
/* True to cause run-time checking of the start=, stop=, and/or step=
|
||||
/* True to cause run-time checking of the start=, stop=, and/or step=
|
||||
** parameters. The only reason to do this is for testing the
|
||||
** constraint checking logic for virtual tables in the SQLite core.
|
||||
*/
|
||||
|
@ -236,7 +236,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
|
|||
/*
|
||||
** This method is called to "rewind" the series_cursor object back
|
||||
** to the first row of output. This method is always called at least
|
||||
** once prior to any call to seriesColumn() or seriesRowid() or
|
||||
** once prior to any call to seriesColumn() or seriesRowid() or
|
||||
** seriesEof().
|
||||
**
|
||||
** The query plan selected by seriesBestIndex is passed in the idxNum
|
||||
|
@ -256,7 +256,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
|
|||
** (so that seriesEof() will return true) if the table is empty.
|
||||
*/
|
||||
static int seriesFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStrUnused,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -369,7 +369,7 @@ static int seriesBestIndex(
|
|||
return SQLITE_CONSTRAINT;
|
||||
}
|
||||
if( (idxNum & 3)==3 ){
|
||||
/* Both start= and stop= boundaries are available. This is the
|
||||
/* Both start= and stop= boundaries are available. This is the
|
||||
** the preferred case */
|
||||
pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0));
|
||||
pIdxInfo->estimatedRows = 1000;
|
||||
|
@ -392,7 +392,7 @@ static int seriesBestIndex(
|
|||
}
|
||||
|
||||
/*
|
||||
** This following structure defines all the methods for the
|
||||
** This following structure defines all the methods for the
|
||||
** generate_series virtual table.
|
||||
*/
|
||||
static sqlite3_module seriesModule = {
|
||||
|
@ -425,8 +425,8 @@ static sqlite3_module seriesModule = {
|
|||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
int sqlite3_series_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
|
|
2
third_party/sqlite3/shathree.c
vendored
2
third_party/sqlite3/shathree.c
vendored
|
@ -491,7 +491,7 @@ static unsigned char *SHA3Final(SHA3Context *p){
|
|||
** Implementation of the sha3(X,SIZE) function.
|
||||
**
|
||||
** Return a BLOB which is the SIZE-bit SHA3 hash of X. The default
|
||||
** size is 256. If X is a BLOB, it is hashed as is.
|
||||
** size is 256. If X is a BLOB, it is hashed as is.
|
||||
** For all other non-NULL types of input, X is converted into a UTF-8 string
|
||||
** and the string is hashed without the trailing 0x00 terminator. The hash
|
||||
** of a NULL value is NULL.
|
||||
|
|
162
third_party/sqlite3/shell.c
vendored
162
third_party/sqlite3/shell.c
vendored
|
@ -1293,7 +1293,7 @@ static void editFunc(
|
|||
}
|
||||
sz = j;
|
||||
p[sz] = 0;
|
||||
}
|
||||
}
|
||||
sqlite3_result_text64(context, (const char*)p, sz,
|
||||
sqlite3_free, SQLITE_UTF8);
|
||||
}
|
||||
|
@ -2885,7 +2885,7 @@ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
|
|||
** characters
|
||||
*/
|
||||
static void print_box_line(FILE *out, int N){
|
||||
const char zDash[] =
|
||||
const char zDash[] =
|
||||
BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24
|
||||
BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24;
|
||||
const int nDash = sizeof(zDash) - 1;
|
||||
|
@ -3168,8 +3168,8 @@ static void exec_prepared_stmt(
|
|||
** caller to eventually free this buffer using sqlite3_free().
|
||||
*/
|
||||
static int expertHandleSQL(
|
||||
ShellState *pState,
|
||||
const char *zSql,
|
||||
ShellState *pState,
|
||||
const char *zSql,
|
||||
char **pzErr
|
||||
){
|
||||
assert( pState->expert.pExpert );
|
||||
|
@ -3179,7 +3179,7 @@ static int expertHandleSQL(
|
|||
|
||||
/*
|
||||
** This function is called either to silently clean up the object
|
||||
** created by the ".expert" command (if bCancel==1), or to generate a
|
||||
** created by the ".expert" command (if bCancel==1), or to generate a
|
||||
** report from it and then clean it up (if bCancel==0).
|
||||
**
|
||||
** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
|
||||
|
@ -3862,7 +3862,7 @@ static const char *(azHelp[]) = {
|
|||
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
|
||||
#ifdef SQLITE_DEBUG
|
||||
".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
|
||||
#endif
|
||||
#endif
|
||||
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
|
||||
" Options:",
|
||||
" --append Use appendvfs to append database to the end of FILE",
|
||||
|
@ -4185,7 +4185,7 @@ int deduceDatabaseType(const char *zName, int dfltZip){
|
|||
}
|
||||
}
|
||||
fclose(f);
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
|
@ -4286,8 +4286,8 @@ readHexDb_error:
|
|||
** offset (4*<arg2>) of the blob.
|
||||
*/
|
||||
static void shellInt32(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const unsigned char *pBlob;
|
||||
|
@ -4314,8 +4314,8 @@ static void shellInt32(
|
|||
** using "..." with internal double-quote characters doubled.
|
||||
*/
|
||||
static void shellIdQuote(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zName = (const char*)sqlite3_value_text(argv[0]);
|
||||
|
@ -4330,8 +4330,8 @@ static void shellIdQuote(
|
|||
** Scalar function "usleep(X)" invokes sqlite3_sleep(X) and returns X.
|
||||
*/
|
||||
static void shellUSleepFunc(
|
||||
sqlite3_context *context,
|
||||
int argcUnused,
|
||||
sqlite3_context *context,
|
||||
int argcUnused,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int sleep = sqlite3_value_int(argv[0]);
|
||||
|
@ -4343,7 +4343,7 @@ static void shellUSleepFunc(
|
|||
/*
|
||||
** Scalar function "shell_escape_crnl" used by the .recover command.
|
||||
** The argument passed to this function is the output of built-in
|
||||
** function quote(). If the first character of the input is "'",
|
||||
** function quote(). If the first character of the input is "'",
|
||||
** indicating that the value passed to quote() was a text value,
|
||||
** then this function searches the input for "\n" and "\r" characters
|
||||
** and adds a wrapper similar to the following:
|
||||
|
@ -4354,8 +4354,8 @@ static void shellUSleepFunc(
|
|||
** of the input is returned.
|
||||
*/
|
||||
static void shellEscapeCrnl(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zText = (const char*)sqlite3_value_text(argv[0]);
|
||||
|
@ -4454,13 +4454,13 @@ static void open_db(ShellState *p, int openFlags){
|
|||
if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
|
||||
p->openMode = SHELL_OPEN_NORMAL;
|
||||
}else{
|
||||
p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
|
||||
p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
|
||||
(openFlags & OPEN_DB_ZIPFILE)!=0);
|
||||
}
|
||||
}
|
||||
switch( p->openMode ){
|
||||
case SHELL_OPEN_APPENDVFS: {
|
||||
sqlite3_open_v2(p->zDbFilename, &p->db,
|
||||
sqlite3_open_v2(p->zDbFilename, &p->db,
|
||||
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
|
||||
break;
|
||||
}
|
||||
|
@ -4574,7 +4574,7 @@ void close_db(sqlite3 *db){
|
|||
if( rc ){
|
||||
utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n",
|
||||
rc, sqlite3_errmsg(db));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_READLINE || HAVE_EDITLINE
|
||||
|
@ -5806,16 +5806,16 @@ static int lintDotCommand(
|
|||
|
||||
#if !defined SQLITE_OMIT_VIRTUALTABLE
|
||||
static void shellPrepare(
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
const char *zSql,
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
const char *zSql,
|
||||
sqlite3_stmt **ppStmt
|
||||
){
|
||||
*ppStmt = 0;
|
||||
if( *pRc==SQLITE_OK ){
|
||||
int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
raw_printf(stderr, "sql error: %s (%d)\n",
|
||||
raw_printf(stderr, "sql error: %s (%d)\n",
|
||||
sqlite3_errmsg(db), sqlite3_errcode(db)
|
||||
);
|
||||
*pRc = rc;
|
||||
|
@ -5831,10 +5831,10 @@ static void shellPrepare(
|
|||
** nuisance compiler warnings about "defined but not used".
|
||||
*/
|
||||
void shellPreparePrintf(
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
sqlite3_stmt **ppStmt,
|
||||
const char *zFmt,
|
||||
const char *zFmt,
|
||||
...
|
||||
){
|
||||
*ppStmt = 0;
|
||||
|
@ -5860,7 +5860,7 @@ void shellPreparePrintf(
|
|||
** nuisance compiler warnings about "defined but not used".
|
||||
*/
|
||||
void shellFinalize(
|
||||
int *pRc,
|
||||
int *pRc,
|
||||
sqlite3_stmt *pStmt
|
||||
){
|
||||
if( pStmt ){
|
||||
|
@ -5882,7 +5882,7 @@ void shellFinalize(
|
|||
** nuisance compiler warnings about "defined but not used".
|
||||
*/
|
||||
void shellReset(
|
||||
int *pRc,
|
||||
int *pRc,
|
||||
sqlite3_stmt *pStmt
|
||||
){
|
||||
int rc = sqlite3_reset(pStmt);
|
||||
|
@ -5929,7 +5929,7 @@ static int arUsage(FILE *f){
|
|||
}
|
||||
|
||||
/*
|
||||
** Print an error message for the .ar command to stderr and return
|
||||
** Print an error message for the .ar command to stderr and return
|
||||
** SQLITE_ERROR.
|
||||
*/
|
||||
static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){
|
||||
|
@ -6004,7 +6004,7 @@ static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
|
|||
/*
|
||||
** Parse the command line for an ".ar" command. The results are written into
|
||||
** structure (*pAr). SQLITE_OK is returned if the command line is parsed
|
||||
** successfully, otherwise an error message is written to stderr and
|
||||
** successfully, otherwise an error message is written to stderr and
|
||||
** SQLITE_ERROR returned.
|
||||
*/
|
||||
static int arParseCommand(
|
||||
|
@ -6145,7 +6145,7 @@ static int arParseCommand(
|
|||
|
||||
/*
|
||||
** This function assumes that all arguments within the ArCommand.azArg[]
|
||||
** array refer to archive members, as for the --extract or --list commands.
|
||||
** array refer to archive members, as for the --extract or --list commands.
|
||||
** It checks that each of them are present. If any specified file is not
|
||||
** present in the archive, an error is printed to stderr and an error
|
||||
** code returned. Otherwise, if all specified arguments are present in
|
||||
|
@ -6162,7 +6162,7 @@ static int arCheckEntries(ArCommand *pAr){
|
|||
sqlite3_stmt *pTest = 0;
|
||||
|
||||
shellPreparePrintf(pAr->db, &rc, &pTest,
|
||||
"SELECT name FROM %s WHERE name=$name",
|
||||
"SELECT name FROM %s WHERE name=$name",
|
||||
pAr->zSrcTable
|
||||
);
|
||||
j = sqlite3_bind_parameter_index(pTest, "$name");
|
||||
|
@ -6195,8 +6195,8 @@ static int arCheckEntries(ArCommand *pAr){
|
|||
** any non-NULL (*pzWhere) value.
|
||||
*/
|
||||
static void arWhereClause(
|
||||
int *pRc,
|
||||
ArCommand *pAr,
|
||||
int *pRc,
|
||||
ArCommand *pAr,
|
||||
char **pzWhere /* OUT: New WHERE clause */
|
||||
){
|
||||
char *zWhere = 0;
|
||||
|
@ -6209,7 +6209,7 @@ static void arWhereClause(
|
|||
for(i=0; i<pAr->nArg; i++){
|
||||
const char *z = pAr->azArg[i];
|
||||
zWhere = sqlite3_mprintf(
|
||||
"%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
|
||||
"%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
|
||||
zWhere, zSep, z, strlen30(z)+1, z
|
||||
);
|
||||
if( zWhere==0 ){
|
||||
|
@ -6224,10 +6224,10 @@ static void arWhereClause(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of .ar "lisT" command.
|
||||
** Implementation of .ar "lisT" command.
|
||||
*/
|
||||
static int arListCommand(ArCommand *pAr){
|
||||
const char *zSql = "SELECT %s FROM %s WHERE %s";
|
||||
const char *zSql = "SELECT %s FROM %s WHERE %s";
|
||||
const char *azCols[] = {
|
||||
"name",
|
||||
"lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
|
||||
|
@ -6249,7 +6249,7 @@ static int arListCommand(ArCommand *pAr){
|
|||
if( pAr->bVerbose ){
|
||||
utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
|
||||
sqlite3_column_text(pSql, 0),
|
||||
sqlite3_column_int(pSql, 1),
|
||||
sqlite3_column_int(pSql, 1),
|
||||
sqlite3_column_text(pSql, 2),
|
||||
sqlite3_column_text(pSql, 3)
|
||||
);
|
||||
|
@ -6265,17 +6265,17 @@ static int arListCommand(ArCommand *pAr){
|
|||
|
||||
|
||||
/*
|
||||
** Implementation of .ar "eXtract" command.
|
||||
** Implementation of .ar "eXtract" command.
|
||||
*/
|
||||
static int arExtractCommand(ArCommand *pAr){
|
||||
const char *zSql1 =
|
||||
const char *zSql1 =
|
||||
"SELECT "
|
||||
" ($dir || name),"
|
||||
" writefile(($dir || name), %s, mode, mtime) "
|
||||
"FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)"
|
||||
" AND name NOT GLOB '*..[/\\]*'";
|
||||
|
||||
const char *azExtraArg[] = {
|
||||
const char *azExtraArg[] = {
|
||||
"sqlar_uncompress(data, sz)",
|
||||
"data"
|
||||
};
|
||||
|
@ -6301,7 +6301,7 @@ static int arExtractCommand(ArCommand *pAr){
|
|||
if( zDir==0 ) rc = SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
|
||||
shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
|
||||
azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
|
||||
);
|
||||
|
||||
|
@ -6379,7 +6379,7 @@ static int arCreateOrUpdateCommand(
|
|||
int bUpdate, /* true for a --create. */
|
||||
int bOnlyIfChanged /* Only update if file has changed */
|
||||
){
|
||||
const char *zCreate =
|
||||
const char *zCreate =
|
||||
"CREATE TABLE IF NOT EXISTS sqlar(\n"
|
||||
" name TEXT PRIMARY KEY, -- name of the file\n"
|
||||
" mode INT, -- access permissions\n"
|
||||
|
@ -6421,7 +6421,7 @@ static int arCreateOrUpdateCommand(
|
|||
arExecSql(pAr, "PRAGMA page_size=512");
|
||||
rc = arExecSql(pAr, "SAVEPOINT ar;");
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
zTemp[0] = 0;
|
||||
zTemp[0] = 0;
|
||||
if( pAr->bZip ){
|
||||
/* Initialize the zipfile virtual table, if necessary */
|
||||
if( pAr->zFile ){
|
||||
|
@ -6515,7 +6515,7 @@ static int arDotCommand(
|
|||
}else if( cmd.zFile ){
|
||||
int flags;
|
||||
if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
|
||||
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
|
||||
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
|
||||
|| cmd.eCmd==AR_CMD_UPDATE ){
|
||||
flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
|
||||
}else{
|
||||
|
@ -6526,10 +6526,10 @@ static int arDotCommand(
|
|||
utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
|
||||
eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
|
||||
}
|
||||
rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
|
||||
rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
|
||||
eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
utf8_printf(stderr, "cannot open file: %s (%s)\n",
|
||||
utf8_printf(stderr, "cannot open file: %s (%s)\n",
|
||||
cmd.zFile, sqlite3_errmsg(cmd.db)
|
||||
);
|
||||
goto end_ar_command;
|
||||
|
@ -6650,12 +6650,12 @@ static void *shellMalloc(int *pRc, sqlite3_int64 nByte){
|
|||
/*
|
||||
** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
|
||||
** Otherwise, zFmt is treated as a printf() style string. The result of
|
||||
** formatting it along with any trailing arguments is written into a
|
||||
** formatting it along with any trailing arguments is written into a
|
||||
** buffer obtained from sqlite3_malloc(), and pointer to which is returned.
|
||||
** It is the responsibility of the caller to eventually free this buffer
|
||||
** using a call to sqlite3_free().
|
||||
**
|
||||
** If an OOM error occurs, (*pRc) is set to SQLITE_NOMEM and a NULL
|
||||
**
|
||||
** If an OOM error occurs, (*pRc) is set to SQLITE_NOMEM and a NULL
|
||||
** pointer returned.
|
||||
*/
|
||||
static char *shellMPrintf(int *pRc, const char *zFmt, ...){
|
||||
|
@ -6714,7 +6714,7 @@ static RecoverTable *recoverNewTable(
|
|||
int *pRc, /* IN/OUT: Error code */
|
||||
const char *zName, /* Name of table */
|
||||
const char *zSql, /* CREATE TABLE statement */
|
||||
int bIntkey,
|
||||
int bIntkey,
|
||||
int nCol
|
||||
){
|
||||
sqlite3 *dbtmp = 0; /* sqlite3 handle for testing CREATE TABLE */
|
||||
|
@ -6726,7 +6726,7 @@ static RecoverTable *recoverNewTable(
|
|||
int nSqlCol = 0;
|
||||
int bSqlIntkey = 0;
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
|
||||
|
||||
rc = sqlite3_open("", &dbtmp);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_create_function(dbtmp, "shell_idquote", 1, SQLITE_UTF8, 0,
|
||||
|
@ -6742,7 +6742,7 @@ static RecoverTable *recoverNewTable(
|
|||
goto finished;
|
||||
}
|
||||
}
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
"SELECT count(*) FROM pragma_table_info(%Q)", zName
|
||||
);
|
||||
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
|
@ -6754,7 +6754,7 @@ static RecoverTable *recoverNewTable(
|
|||
goto finished;
|
||||
}
|
||||
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
"SELECT ("
|
||||
" SELECT substr(data,1,1)==X'0D' FROM sqlite_dbpage WHERE pgno=rootpage"
|
||||
") FROM sqlite_schema WHERE name = %Q", zName
|
||||
|
@ -6776,7 +6776,7 @@ static RecoverTable *recoverNewTable(
|
|||
** leave zPk as "_rowid_" and pTab->iPk at -2. */
|
||||
pTab->iPk = -2;
|
||||
if( bIntkey ){
|
||||
shellPreparePrintf(dbtmp, &rc, &pPkFinder,
|
||||
shellPreparePrintf(dbtmp, &rc, &pPkFinder,
|
||||
"SELECT cid, name FROM pragma_table_info(%Q) "
|
||||
" WHERE pk=1 AND type='integer' COLLATE nocase"
|
||||
" AND NOT EXISTS (SELECT cid FROM pragma_table_info(%Q) WHERE pk=2)"
|
||||
|
@ -6798,11 +6798,11 @@ static RecoverTable *recoverNewTable(
|
|||
pTab->azlCol[0] = shellMPrintf(&rc, "");
|
||||
}
|
||||
i = 1;
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
"SELECT %Q || group_concat(shell_idquote(name), ', ') "
|
||||
" FILTER (WHERE cid!=%d) OVER (ORDER BY %s cid) "
|
||||
"FROM pragma_table_info(%Q)",
|
||||
bIntkey ? ", " : "", pTab->iPk,
|
||||
"FROM pragma_table_info(%Q)",
|
||||
bIntkey ? ", " : "", pTab->iPk,
|
||||
bIntkey ? "" : "(CASE WHEN pk=0 THEN 1000000 ELSE pk END), ",
|
||||
zName
|
||||
);
|
||||
|
@ -6836,7 +6836,7 @@ static RecoverTable *recoverNewTable(
|
|||
** those.
|
||||
**
|
||||
** If a table is found, a (RecoverTable*) object is returned. Or, if
|
||||
** no such table is found, but bIntkey is false and iRoot is the
|
||||
** no such table is found, but bIntkey is false and iRoot is the
|
||||
** root page of an index in the recovered schema, then (*pbNoop) is
|
||||
** set to true and NULL returned. Or, if there is no such table or
|
||||
** index, NULL is returned and (*pbNoop) set to 0, indicating that
|
||||
|
@ -6930,7 +6930,7 @@ static RecoverTable *recoverOrphanTable(
|
|||
recoverFreeTable(pTab);
|
||||
pTab = 0;
|
||||
}else{
|
||||
raw_printf(pState->out,
|
||||
raw_printf(pState->out,
|
||||
"CREATE TABLE %s(rootpgno INTEGER, "
|
||||
"pgno INTEGER, nfield INTEGER, id INTEGER", pTab->zQuoted
|
||||
);
|
||||
|
@ -6983,14 +6983,14 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
bRowids = 0;
|
||||
}
|
||||
else{
|
||||
utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
|
||||
utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
|
||||
showHelp(pState->out, azArg[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
shellExecPrintf(pState->db, &rc,
|
||||
/* Attach an in-memory database named 'recovery'. Create an indexed
|
||||
/* Attach an in-memory database named 'recovery'. Create an indexed
|
||||
** cache of the sqlite_dbptr virtual table. */
|
||||
"PRAGMA writable_schema = on;"
|
||||
"ATTACH %Q AS recovery;"
|
||||
|
@ -7024,9 +7024,9 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
}
|
||||
|
||||
/* If this is an auto-vacuum database, add all pointer-map pages to
|
||||
** the freelist table. Do this regardless of whether or not
|
||||
** the freelist table. Do this regardless of whether or not
|
||||
** --freelist-corrupt was specified. */
|
||||
shellExec(pState->db, &rc,
|
||||
shellExec(pState->db, &rc,
|
||||
"WITH ptrmap(pgno) AS ("
|
||||
" SELECT 2 WHERE shell_int32("
|
||||
" (SELECT data FROM sqlite_dbpage WHERE pgno=1), 13"
|
||||
|
@ -7038,7 +7038,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
"REPLACE INTO recovery.freelist SELECT pgno FROM ptrmap"
|
||||
);
|
||||
|
||||
shellExec(pState->db, &rc,
|
||||
shellExec(pState->db, &rc,
|
||||
"CREATE TABLE recovery.dbptr("
|
||||
" pgno, child, PRIMARY KEY(child, pgno)"
|
||||
") WITHOUT ROWID;"
|
||||
|
@ -7058,7 +7058,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
");"
|
||||
|
||||
/* Create the "map" table that will (eventually) contain instructions
|
||||
** for dealing with each page in the db that contains one or more
|
||||
** for dealing with each page in the db that contains one or more
|
||||
** records. */
|
||||
"CREATE TABLE recovery.map("
|
||||
"pgno INTEGER PRIMARY KEY, maxlen INT, intkey, root INT"
|
||||
|
@ -7107,7 +7107,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
"CREATE INDEX recovery.schema_rootpage ON schema(rootpage);"
|
||||
);
|
||||
|
||||
/* Open a transaction, then print out all non-virtual, non-"sqlite_%"
|
||||
/* Open a transaction, then print out all non-virtual, non-"sqlite_%"
|
||||
** CREATE TABLE statements that extracted from the existing schema. */
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
|
@ -7124,7 +7124,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
);
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
const char *zCreateTable = (const char*)sqlite3_column_text(pStmt, 0);
|
||||
raw_printf(pState->out, "CREATE TABLE IF NOT EXISTS %s;\n",
|
||||
raw_printf(pState->out, "CREATE TABLE IF NOT EXISTS %s;\n",
|
||||
&zCreateTable[12]
|
||||
);
|
||||
}
|
||||
|
@ -7133,7 +7133,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
|
||||
/* Figure out if an orphan table will be required. And if so, how many
|
||||
** user columns it should contain */
|
||||
shellPrepare(pState->db, &rc,
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT coalesce(max(maxlen), -2) FROM recovery.map WHERE root>1"
|
||||
, &pLoop
|
||||
);
|
||||
|
@ -7157,8 +7157,8 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
);
|
||||
|
||||
/* Loop through each root page. */
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT root, intkey, max(maxlen) FROM recovery.map"
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT root, intkey, max(maxlen) FROM recovery.map"
|
||||
" WHERE root>1 GROUP BY root, intkey ORDER BY root=("
|
||||
" SELECT rootpage FROM recovery.schema WHERE name='sqlite_sequence'"
|
||||
")", &pLoop
|
||||
|
@ -7211,13 +7211,13 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
|
||||
nField = nField+1;
|
||||
if( pTab2==pOrphan ){
|
||||
raw_printf(pState->out,
|
||||
raw_printf(pState->out,
|
||||
"INSERT INTO %s VALUES(%d, %d, %d, %s%s%s);\n",
|
||||
pTab2->zQuoted, iRoot, iPgno, nField,
|
||||
iMin<0 ? "" : "NULL, ", zVal, pTab2->azlCol[nField]
|
||||
);
|
||||
}else{
|
||||
raw_printf(pState->out, "INSERT INTO %s(%s) VALUES( %s );\n",
|
||||
raw_printf(pState->out, "INSERT INTO %s(%s) VALUES( %s );\n",
|
||||
pTab2->zQuoted, pTab2->azlCol[nField], zVal
|
||||
);
|
||||
}
|
||||
|
@ -7235,7 +7235,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
/* The rest of the schema */
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
shellPrepare(pState->db, &rc,
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT sql, name FROM recovery.schema "
|
||||
"WHERE sql NOT LIKE 'create table%'", &pStmt
|
||||
);
|
||||
|
@ -7243,7 +7243,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
|
||||
if( sqlite3_strnicmp(zSql, "create virt", 11)==0 ){
|
||||
const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
|
||||
char *zPrint = shellMPrintf(&rc,
|
||||
char *zPrint = shellMPrintf(&rc,
|
||||
"INSERT INTO sqlite_schema VALUES('table', %Q, %Q, 0, %Q)",
|
||||
zName, zName, zSql
|
||||
);
|
||||
|
@ -7379,7 +7379,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
return 1;
|
||||
}
|
||||
if( zDb==0 ) zDb = "main";
|
||||
rc = sqlite3_open_v2(zDestFile, &pDest,
|
||||
rc = sqlite3_open_v2(zDestFile, &pDest,
|
||||
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
|
||||
if( rc!=SQLITE_OK ){
|
||||
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
|
||||
|
@ -7573,7 +7573,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
if( nArg>1 && ii==ArraySize(aDbConfig) ){
|
||||
utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
|
||||
utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
|
||||
|
@ -7593,7 +7593,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
int i;
|
||||
int savedShowHeader = p->showHeader;
|
||||
int savedShellFlags = p->shellFlgs;
|
||||
ShellClearFlag(p,
|
||||
ShellClearFlag(p,
|
||||
SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo
|
||||
|SHFLG_DumpDataOnly|SHFLG_DumpNoSys);
|
||||
for(i=1; i<nArg; i++){
|
||||
|
@ -7768,7 +7768,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
} aCtrl[] = {
|
||||
{ "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
|
||||
{ "data_version", SQLITE_FCNTL_DATA_VERSION, "" },
|
||||
{ "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
|
||||
{ "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
|
||||
{ "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
|
||||
{ "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
|
||||
/* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
|
||||
|
@ -7789,7 +7789,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
open_db(p, 0);
|
||||
zCmd = nArg>=2 ? azArg[1] : "help";
|
||||
|
||||
if( zCmd[0]=='-'
|
||||
if( zCmd[0]=='-'
|
||||
&& (strcmp(zCmd,"--schema")==0 || strcmp(zCmd,"-schema")==0)
|
||||
&& nArg>=4
|
||||
){
|
||||
|
@ -8055,7 +8055,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
goto meta_command_exit;
|
||||
}
|
||||
if( nSep>1 ){
|
||||
raw_printf(stderr,
|
||||
raw_printf(stderr,
|
||||
"Error: multi-character column separators not allowed"
|
||||
" for import\n");
|
||||
rc = 1;
|
||||
|
|
162
third_party/sqlite3/shell.c.in
vendored
162
third_party/sqlite3/shell.c.in
vendored
|
@ -1395,7 +1395,7 @@ static void editFunc(
|
|||
}
|
||||
sz = j;
|
||||
p[sz] = 0;
|
||||
}
|
||||
}
|
||||
sqlite3_result_text64(context, (const char*)p, sz,
|
||||
sqlite3_free, SQLITE_UTF8);
|
||||
}
|
||||
|
@ -2987,7 +2987,7 @@ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
|
|||
** characters
|
||||
*/
|
||||
static void print_box_line(FILE *out, int N){
|
||||
const char zDash[] =
|
||||
const char zDash[] =
|
||||
BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24
|
||||
BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24;
|
||||
const int nDash = sizeof(zDash) - 1;
|
||||
|
@ -3270,8 +3270,8 @@ static void exec_prepared_stmt(
|
|||
** caller to eventually free this buffer using sqlite3_free().
|
||||
*/
|
||||
static int expertHandleSQL(
|
||||
ShellState *pState,
|
||||
const char *zSql,
|
||||
ShellState *pState,
|
||||
const char *zSql,
|
||||
char **pzErr
|
||||
){
|
||||
assert( pState->expert.pExpert );
|
||||
|
@ -3281,7 +3281,7 @@ static int expertHandleSQL(
|
|||
|
||||
/*
|
||||
** This function is called either to silently clean up the object
|
||||
** created by the ".expert" command (if bCancel==1), or to generate a
|
||||
** created by the ".expert" command (if bCancel==1), or to generate a
|
||||
** report from it and then clean it up (if bCancel==0).
|
||||
**
|
||||
** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
|
||||
|
@ -3964,7 +3964,7 @@ static const char *(azHelp[]) = {
|
|||
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
|
||||
#ifdef SQLITE_DEBUG
|
||||
".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
|
||||
#endif
|
||||
#endif
|
||||
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
|
||||
" Options:",
|
||||
" --append Use appendvfs to append database to the end of FILE",
|
||||
|
@ -4287,7 +4287,7 @@ int deduceDatabaseType(const char *zName, int dfltZip){
|
|||
}
|
||||
}
|
||||
fclose(f);
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
|
@ -4388,8 +4388,8 @@ readHexDb_error:
|
|||
** offset (4*<arg2>) of the blob.
|
||||
*/
|
||||
static void shellInt32(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const unsigned char *pBlob;
|
||||
|
@ -4416,8 +4416,8 @@ static void shellInt32(
|
|||
** using "..." with internal double-quote characters doubled.
|
||||
*/
|
||||
static void shellIdQuote(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zName = (const char*)sqlite3_value_text(argv[0]);
|
||||
|
@ -4432,8 +4432,8 @@ static void shellIdQuote(
|
|||
** Scalar function "usleep(X)" invokes sqlite3_sleep(X) and returns X.
|
||||
*/
|
||||
static void shellUSleepFunc(
|
||||
sqlite3_context *context,
|
||||
int argcUnused,
|
||||
sqlite3_context *context,
|
||||
int argcUnused,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int sleep = sqlite3_value_int(argv[0]);
|
||||
|
@ -4445,7 +4445,7 @@ static void shellUSleepFunc(
|
|||
/*
|
||||
** Scalar function "shell_escape_crnl" used by the .recover command.
|
||||
** The argument passed to this function is the output of built-in
|
||||
** function quote(). If the first character of the input is "'",
|
||||
** function quote(). If the first character of the input is "'",
|
||||
** indicating that the value passed to quote() was a text value,
|
||||
** then this function searches the input for "\n" and "\r" characters
|
||||
** and adds a wrapper similar to the following:
|
||||
|
@ -4456,8 +4456,8 @@ static void shellUSleepFunc(
|
|||
** of the input is returned.
|
||||
*/
|
||||
static void shellEscapeCrnl(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zText = (const char*)sqlite3_value_text(argv[0]);
|
||||
|
@ -4556,13 +4556,13 @@ static void open_db(ShellState *p, int openFlags){
|
|||
if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
|
||||
p->openMode = SHELL_OPEN_NORMAL;
|
||||
}else{
|
||||
p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
|
||||
p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
|
||||
(openFlags & OPEN_DB_ZIPFILE)!=0);
|
||||
}
|
||||
}
|
||||
switch( p->openMode ){
|
||||
case SHELL_OPEN_APPENDVFS: {
|
||||
sqlite3_open_v2(p->zDbFilename, &p->db,
|
||||
sqlite3_open_v2(p->zDbFilename, &p->db,
|
||||
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
|
||||
break;
|
||||
}
|
||||
|
@ -4676,7 +4676,7 @@ void close_db(sqlite3 *db){
|
|||
if( rc ){
|
||||
utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n",
|
||||
rc, sqlite3_errmsg(db));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_READLINE || HAVE_EDITLINE
|
||||
|
@ -5908,16 +5908,16 @@ static int lintDotCommand(
|
|||
|
||||
#if !defined SQLITE_OMIT_VIRTUALTABLE
|
||||
static void shellPrepare(
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
const char *zSql,
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
const char *zSql,
|
||||
sqlite3_stmt **ppStmt
|
||||
){
|
||||
*ppStmt = 0;
|
||||
if( *pRc==SQLITE_OK ){
|
||||
int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
raw_printf(stderr, "sql error: %s (%d)\n",
|
||||
raw_printf(stderr, "sql error: %s (%d)\n",
|
||||
sqlite3_errmsg(db), sqlite3_errcode(db)
|
||||
);
|
||||
*pRc = rc;
|
||||
|
@ -5933,10 +5933,10 @@ static void shellPrepare(
|
|||
** nuisance compiler warnings about "defined but not used".
|
||||
*/
|
||||
void shellPreparePrintf(
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
sqlite3 *db,
|
||||
int *pRc,
|
||||
sqlite3_stmt **ppStmt,
|
||||
const char *zFmt,
|
||||
const char *zFmt,
|
||||
...
|
||||
){
|
||||
*ppStmt = 0;
|
||||
|
@ -5962,7 +5962,7 @@ void shellPreparePrintf(
|
|||
** nuisance compiler warnings about "defined but not used".
|
||||
*/
|
||||
void shellFinalize(
|
||||
int *pRc,
|
||||
int *pRc,
|
||||
sqlite3_stmt *pStmt
|
||||
){
|
||||
if( pStmt ){
|
||||
|
@ -5984,7 +5984,7 @@ void shellFinalize(
|
|||
** nuisance compiler warnings about "defined but not used".
|
||||
*/
|
||||
void shellReset(
|
||||
int *pRc,
|
||||
int *pRc,
|
||||
sqlite3_stmt *pStmt
|
||||
){
|
||||
int rc = sqlite3_reset(pStmt);
|
||||
|
@ -6031,7 +6031,7 @@ static int arUsage(FILE *f){
|
|||
}
|
||||
|
||||
/*
|
||||
** Print an error message for the .ar command to stderr and return
|
||||
** Print an error message for the .ar command to stderr and return
|
||||
** SQLITE_ERROR.
|
||||
*/
|
||||
static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){
|
||||
|
@ -6106,7 +6106,7 @@ static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
|
|||
/*
|
||||
** Parse the command line for an ".ar" command. The results are written into
|
||||
** structure (*pAr). SQLITE_OK is returned if the command line is parsed
|
||||
** successfully, otherwise an error message is written to stderr and
|
||||
** successfully, otherwise an error message is written to stderr and
|
||||
** SQLITE_ERROR returned.
|
||||
*/
|
||||
static int arParseCommand(
|
||||
|
@ -6247,7 +6247,7 @@ static int arParseCommand(
|
|||
|
||||
/*
|
||||
** This function assumes that all arguments within the ArCommand.azArg[]
|
||||
** array refer to archive members, as for the --extract or --list commands.
|
||||
** array refer to archive members, as for the --extract or --list commands.
|
||||
** It checks that each of them are present. If any specified file is not
|
||||
** present in the archive, an error is printed to stderr and an error
|
||||
** code returned. Otherwise, if all specified arguments are present in
|
||||
|
@ -6264,7 +6264,7 @@ static int arCheckEntries(ArCommand *pAr){
|
|||
sqlite3_stmt *pTest = 0;
|
||||
|
||||
shellPreparePrintf(pAr->db, &rc, &pTest,
|
||||
"SELECT name FROM %s WHERE name=$name",
|
||||
"SELECT name FROM %s WHERE name=$name",
|
||||
pAr->zSrcTable
|
||||
);
|
||||
j = sqlite3_bind_parameter_index(pTest, "$name");
|
||||
|
@ -6297,8 +6297,8 @@ static int arCheckEntries(ArCommand *pAr){
|
|||
** any non-NULL (*pzWhere) value.
|
||||
*/
|
||||
static void arWhereClause(
|
||||
int *pRc,
|
||||
ArCommand *pAr,
|
||||
int *pRc,
|
||||
ArCommand *pAr,
|
||||
char **pzWhere /* OUT: New WHERE clause */
|
||||
){
|
||||
char *zWhere = 0;
|
||||
|
@ -6311,7 +6311,7 @@ static void arWhereClause(
|
|||
for(i=0; i<pAr->nArg; i++){
|
||||
const char *z = pAr->azArg[i];
|
||||
zWhere = sqlite3_mprintf(
|
||||
"%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
|
||||
"%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
|
||||
zWhere, zSep, z, strlen30(z)+1, z
|
||||
);
|
||||
if( zWhere==0 ){
|
||||
|
@ -6326,10 +6326,10 @@ static void arWhereClause(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of .ar "lisT" command.
|
||||
** Implementation of .ar "lisT" command.
|
||||
*/
|
||||
static int arListCommand(ArCommand *pAr){
|
||||
const char *zSql = "SELECT %s FROM %s WHERE %s";
|
||||
const char *zSql = "SELECT %s FROM %s WHERE %s";
|
||||
const char *azCols[] = {
|
||||
"name",
|
||||
"lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
|
||||
|
@ -6351,7 +6351,7 @@ static int arListCommand(ArCommand *pAr){
|
|||
if( pAr->bVerbose ){
|
||||
utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
|
||||
sqlite3_column_text(pSql, 0),
|
||||
sqlite3_column_int(pSql, 1),
|
||||
sqlite3_column_int(pSql, 1),
|
||||
sqlite3_column_text(pSql, 2),
|
||||
sqlite3_column_text(pSql, 3)
|
||||
);
|
||||
|
@ -6367,17 +6367,17 @@ static int arListCommand(ArCommand *pAr){
|
|||
|
||||
|
||||
/*
|
||||
** Implementation of .ar "eXtract" command.
|
||||
** Implementation of .ar "eXtract" command.
|
||||
*/
|
||||
static int arExtractCommand(ArCommand *pAr){
|
||||
const char *zSql1 =
|
||||
const char *zSql1 =
|
||||
"SELECT "
|
||||
" ($dir || name),"
|
||||
" writefile(($dir || name), %s, mode, mtime) "
|
||||
"FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)"
|
||||
" AND name NOT GLOB '*..[/\\]*'";
|
||||
|
||||
const char *azExtraArg[] = {
|
||||
const char *azExtraArg[] = {
|
||||
"sqlar_uncompress(data, sz)",
|
||||
"data"
|
||||
};
|
||||
|
@ -6403,7 +6403,7 @@ static int arExtractCommand(ArCommand *pAr){
|
|||
if( zDir==0 ) rc = SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
|
||||
shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
|
||||
azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
|
||||
);
|
||||
|
||||
|
@ -6481,7 +6481,7 @@ static int arCreateOrUpdateCommand(
|
|||
int bUpdate, /* true for a --create. */
|
||||
int bOnlyIfChanged /* Only update if file has changed */
|
||||
){
|
||||
const char *zCreate =
|
||||
const char *zCreate =
|
||||
"CREATE TABLE IF NOT EXISTS sqlar(\n"
|
||||
" name TEXT PRIMARY KEY, -- name of the file\n"
|
||||
" mode INT, -- access permissions\n"
|
||||
|
@ -6523,7 +6523,7 @@ static int arCreateOrUpdateCommand(
|
|||
arExecSql(pAr, "PRAGMA page_size=512");
|
||||
rc = arExecSql(pAr, "SAVEPOINT ar;");
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
zTemp[0] = 0;
|
||||
zTemp[0] = 0;
|
||||
if( pAr->bZip ){
|
||||
/* Initialize the zipfile virtual table, if necessary */
|
||||
if( pAr->zFile ){
|
||||
|
@ -6617,7 +6617,7 @@ static int arDotCommand(
|
|||
}else if( cmd.zFile ){
|
||||
int flags;
|
||||
if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
|
||||
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
|
||||
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
|
||||
|| cmd.eCmd==AR_CMD_UPDATE ){
|
||||
flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
|
||||
}else{
|
||||
|
@ -6628,10 +6628,10 @@ static int arDotCommand(
|
|||
utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
|
||||
eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
|
||||
}
|
||||
rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
|
||||
rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
|
||||
eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
utf8_printf(stderr, "cannot open file: %s (%s)\n",
|
||||
utf8_printf(stderr, "cannot open file: %s (%s)\n",
|
||||
cmd.zFile, sqlite3_errmsg(cmd.db)
|
||||
);
|
||||
goto end_ar_command;
|
||||
|
@ -6752,12 +6752,12 @@ static void *shellMalloc(int *pRc, sqlite3_int64 nByte){
|
|||
/*
|
||||
** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
|
||||
** Otherwise, zFmt is treated as a printf() style string. The result of
|
||||
** formatting it along with any trailing arguments is written into a
|
||||
** formatting it along with any trailing arguments is written into a
|
||||
** buffer obtained from sqlite3_malloc(), and pointer to which is returned.
|
||||
** It is the responsibility of the caller to eventually free this buffer
|
||||
** using a call to sqlite3_free().
|
||||
**
|
||||
** If an OOM error occurs, (*pRc) is set to SQLITE_NOMEM and a NULL
|
||||
**
|
||||
** If an OOM error occurs, (*pRc) is set to SQLITE_NOMEM and a NULL
|
||||
** pointer returned.
|
||||
*/
|
||||
static char *shellMPrintf(int *pRc, const char *zFmt, ...){
|
||||
|
@ -6816,7 +6816,7 @@ static RecoverTable *recoverNewTable(
|
|||
int *pRc, /* IN/OUT: Error code */
|
||||
const char *zName, /* Name of table */
|
||||
const char *zSql, /* CREATE TABLE statement */
|
||||
int bIntkey,
|
||||
int bIntkey,
|
||||
int nCol
|
||||
){
|
||||
sqlite3 *dbtmp = 0; /* sqlite3 handle for testing CREATE TABLE */
|
||||
|
@ -6828,7 +6828,7 @@ static RecoverTable *recoverNewTable(
|
|||
int nSqlCol = 0;
|
||||
int bSqlIntkey = 0;
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
|
||||
|
||||
rc = sqlite3_open("", &dbtmp);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_create_function(dbtmp, "shell_idquote", 1, SQLITE_UTF8, 0,
|
||||
|
@ -6844,7 +6844,7 @@ static RecoverTable *recoverNewTable(
|
|||
goto finished;
|
||||
}
|
||||
}
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
"SELECT count(*) FROM pragma_table_info(%Q)", zName
|
||||
);
|
||||
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
|
@ -6856,7 +6856,7 @@ static RecoverTable *recoverNewTable(
|
|||
goto finished;
|
||||
}
|
||||
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
"SELECT ("
|
||||
" SELECT substr(data,1,1)==X'0D' FROM sqlite_dbpage WHERE pgno=rootpage"
|
||||
") FROM sqlite_schema WHERE name = %Q", zName
|
||||
|
@ -6878,7 +6878,7 @@ static RecoverTable *recoverNewTable(
|
|||
** leave zPk as "_rowid_" and pTab->iPk at -2. */
|
||||
pTab->iPk = -2;
|
||||
if( bIntkey ){
|
||||
shellPreparePrintf(dbtmp, &rc, &pPkFinder,
|
||||
shellPreparePrintf(dbtmp, &rc, &pPkFinder,
|
||||
"SELECT cid, name FROM pragma_table_info(%Q) "
|
||||
" WHERE pk=1 AND type='integer' COLLATE nocase"
|
||||
" AND NOT EXISTS (SELECT cid FROM pragma_table_info(%Q) WHERE pk=2)"
|
||||
|
@ -6900,11 +6900,11 @@ static RecoverTable *recoverNewTable(
|
|||
pTab->azlCol[0] = shellMPrintf(&rc, "");
|
||||
}
|
||||
i = 1;
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
shellPreparePrintf(dbtmp, &rc, &pStmt,
|
||||
"SELECT %Q || group_concat(shell_idquote(name), ', ') "
|
||||
" FILTER (WHERE cid!=%d) OVER (ORDER BY %s cid) "
|
||||
"FROM pragma_table_info(%Q)",
|
||||
bIntkey ? ", " : "", pTab->iPk,
|
||||
"FROM pragma_table_info(%Q)",
|
||||
bIntkey ? ", " : "", pTab->iPk,
|
||||
bIntkey ? "" : "(CASE WHEN pk=0 THEN 1000000 ELSE pk END), ",
|
||||
zName
|
||||
);
|
||||
|
@ -6938,7 +6938,7 @@ static RecoverTable *recoverNewTable(
|
|||
** those.
|
||||
**
|
||||
** If a table is found, a (RecoverTable*) object is returned. Or, if
|
||||
** no such table is found, but bIntkey is false and iRoot is the
|
||||
** no such table is found, but bIntkey is false and iRoot is the
|
||||
** root page of an index in the recovered schema, then (*pbNoop) is
|
||||
** set to true and NULL returned. Or, if there is no such table or
|
||||
** index, NULL is returned and (*pbNoop) set to 0, indicating that
|
||||
|
@ -7032,7 +7032,7 @@ static RecoverTable *recoverOrphanTable(
|
|||
recoverFreeTable(pTab);
|
||||
pTab = 0;
|
||||
}else{
|
||||
raw_printf(pState->out,
|
||||
raw_printf(pState->out,
|
||||
"CREATE TABLE %s(rootpgno INTEGER, "
|
||||
"pgno INTEGER, nfield INTEGER, id INTEGER", pTab->zQuoted
|
||||
);
|
||||
|
@ -7085,14 +7085,14 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
bRowids = 0;
|
||||
}
|
||||
else{
|
||||
utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
|
||||
utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
|
||||
showHelp(pState->out, azArg[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
shellExecPrintf(pState->db, &rc,
|
||||
/* Attach an in-memory database named 'recovery'. Create an indexed
|
||||
/* Attach an in-memory database named 'recovery'. Create an indexed
|
||||
** cache of the sqlite_dbptr virtual table. */
|
||||
"PRAGMA writable_schema = on;"
|
||||
"ATTACH %Q AS recovery;"
|
||||
|
@ -7126,9 +7126,9 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
}
|
||||
|
||||
/* If this is an auto-vacuum database, add all pointer-map pages to
|
||||
** the freelist table. Do this regardless of whether or not
|
||||
** the freelist table. Do this regardless of whether or not
|
||||
** --freelist-corrupt was specified. */
|
||||
shellExec(pState->db, &rc,
|
||||
shellExec(pState->db, &rc,
|
||||
"WITH ptrmap(pgno) AS ("
|
||||
" SELECT 2 WHERE shell_int32("
|
||||
" (SELECT data FROM sqlite_dbpage WHERE pgno=1), 13"
|
||||
|
@ -7140,7 +7140,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
"REPLACE INTO recovery.freelist SELECT pgno FROM ptrmap"
|
||||
);
|
||||
|
||||
shellExec(pState->db, &rc,
|
||||
shellExec(pState->db, &rc,
|
||||
"CREATE TABLE recovery.dbptr("
|
||||
" pgno, child, PRIMARY KEY(child, pgno)"
|
||||
") WITHOUT ROWID;"
|
||||
|
@ -7160,7 +7160,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
");"
|
||||
|
||||
/* Create the "map" table that will (eventually) contain instructions
|
||||
** for dealing with each page in the db that contains one or more
|
||||
** for dealing with each page in the db that contains one or more
|
||||
** records. */
|
||||
"CREATE TABLE recovery.map("
|
||||
"pgno INTEGER PRIMARY KEY, maxlen INT, intkey, root INT"
|
||||
|
@ -7209,7 +7209,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
"CREATE INDEX recovery.schema_rootpage ON schema(rootpage);"
|
||||
);
|
||||
|
||||
/* Open a transaction, then print out all non-virtual, non-"sqlite_%"
|
||||
/* Open a transaction, then print out all non-virtual, non-"sqlite_%"
|
||||
** CREATE TABLE statements that extracted from the existing schema. */
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
|
@ -7226,7 +7226,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
);
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
const char *zCreateTable = (const char*)sqlite3_column_text(pStmt, 0);
|
||||
raw_printf(pState->out, "CREATE TABLE IF NOT EXISTS %s;\n",
|
||||
raw_printf(pState->out, "CREATE TABLE IF NOT EXISTS %s;\n",
|
||||
&zCreateTable[12]
|
||||
);
|
||||
}
|
||||
|
@ -7235,7 +7235,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
|
||||
/* Figure out if an orphan table will be required. And if so, how many
|
||||
** user columns it should contain */
|
||||
shellPrepare(pState->db, &rc,
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT coalesce(max(maxlen), -2) FROM recovery.map WHERE root>1"
|
||||
, &pLoop
|
||||
);
|
||||
|
@ -7259,8 +7259,8 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
);
|
||||
|
||||
/* Loop through each root page. */
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT root, intkey, max(maxlen) FROM recovery.map"
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT root, intkey, max(maxlen) FROM recovery.map"
|
||||
" WHERE root>1 GROUP BY root, intkey ORDER BY root=("
|
||||
" SELECT rootpage FROM recovery.schema WHERE name='sqlite_sequence'"
|
||||
")", &pLoop
|
||||
|
@ -7313,13 +7313,13 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
|
||||
nField = nField+1;
|
||||
if( pTab2==pOrphan ){
|
||||
raw_printf(pState->out,
|
||||
raw_printf(pState->out,
|
||||
"INSERT INTO %s VALUES(%d, %d, %d, %s%s%s);\n",
|
||||
pTab2->zQuoted, iRoot, iPgno, nField,
|
||||
iMin<0 ? "" : "NULL, ", zVal, pTab2->azlCol[nField]
|
||||
);
|
||||
}else{
|
||||
raw_printf(pState->out, "INSERT INTO %s(%s) VALUES( %s );\n",
|
||||
raw_printf(pState->out, "INSERT INTO %s(%s) VALUES( %s );\n",
|
||||
pTab2->zQuoted, pTab2->azlCol[nField], zVal
|
||||
);
|
||||
}
|
||||
|
@ -7337,7 +7337,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
/* The rest of the schema */
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
shellPrepare(pState->db, &rc,
|
||||
shellPrepare(pState->db, &rc,
|
||||
"SELECT sql, name FROM recovery.schema "
|
||||
"WHERE sql NOT LIKE 'create table%'", &pStmt
|
||||
);
|
||||
|
@ -7345,7 +7345,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
|
|||
const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
|
||||
if( sqlite3_strnicmp(zSql, "create virt", 11)==0 ){
|
||||
const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
|
||||
char *zPrint = shellMPrintf(&rc,
|
||||
char *zPrint = shellMPrintf(&rc,
|
||||
"INSERT INTO sqlite_schema VALUES('table', %Q, %Q, 0, %Q)",
|
||||
zName, zName, zSql
|
||||
);
|
||||
|
@ -7481,7 +7481,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
return 1;
|
||||
}
|
||||
if( zDb==0 ) zDb = "main";
|
||||
rc = sqlite3_open_v2(zDestFile, &pDest,
|
||||
rc = sqlite3_open_v2(zDestFile, &pDest,
|
||||
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
|
||||
if( rc!=SQLITE_OK ){
|
||||
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
|
||||
|
@ -7675,7 +7675,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
if( nArg>1 && ii==ArraySize(aDbConfig) ){
|
||||
utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
|
||||
utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
|
||||
|
@ -7695,7 +7695,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
int i;
|
||||
int savedShowHeader = p->showHeader;
|
||||
int savedShellFlags = p->shellFlgs;
|
||||
ShellClearFlag(p,
|
||||
ShellClearFlag(p,
|
||||
SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo
|
||||
|SHFLG_DumpDataOnly|SHFLG_DumpNoSys);
|
||||
for(i=1; i<nArg; i++){
|
||||
|
@ -7870,7 +7870,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
} aCtrl[] = {
|
||||
{ "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
|
||||
{ "data_version", SQLITE_FCNTL_DATA_VERSION, "" },
|
||||
{ "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
|
||||
{ "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
|
||||
{ "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
|
||||
{ "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
|
||||
/* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
|
||||
|
@ -7891,7 +7891,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
open_db(p, 0);
|
||||
zCmd = nArg>=2 ? azArg[1] : "help";
|
||||
|
||||
if( zCmd[0]=='-'
|
||||
if( zCmd[0]=='-'
|
||||
&& (strcmp(zCmd,"--schema")==0 || strcmp(zCmd,"-schema")==0)
|
||||
&& nArg>=4
|
||||
){
|
||||
|
@ -8157,7 +8157,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||
goto meta_command_exit;
|
||||
}
|
||||
if( nSep>1 ){
|
||||
raw_printf(stderr,
|
||||
raw_printf(stderr,
|
||||
"Error: multi-character column separators not allowed"
|
||||
" for import\n");
|
||||
rc = 1;
|
||||
|
|
6
third_party/sqlite3/sqlar.c
vendored
6
third_party/sqlite3/sqlar.c
vendored
|
@ -103,14 +103,14 @@ static void sqlarUncompressFunc(
|
|||
}
|
||||
|
||||
int sqlite3_sqlar_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused parameter */
|
||||
rc = sqlite3_create_function(db, "sqlar_compress", 1,
|
||||
rc = sqlite3_create_function(db, "sqlar_compress", 1,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
|
||||
sqlarCompressFunc, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
|
|
96
third_party/sqlite3/sqlite3expert.c
vendored
96
third_party/sqlite3/sqlite3expert.c
vendored
|
@ -17,7 +17,7 @@
|
|||
#include "third_party/sqlite3/sqlite3expert.h"
|
||||
// clang-format off
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|
||||
typedef sqlite3_int64 i64;
|
||||
typedef sqlite3_uint64 u64;
|
||||
|
@ -69,7 +69,7 @@ struct IdxScan {
|
|||
};
|
||||
|
||||
/*
|
||||
** Information regarding a single database table. Extracted from
|
||||
** Information regarding a single database table. Extracted from
|
||||
** "PRAGMA table_info" by function idxGetTableInfo().
|
||||
*/
|
||||
struct IdxColumn {
|
||||
|
@ -153,7 +153,7 @@ struct sqlite3expert {
|
|||
|
||||
|
||||
/*
|
||||
** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
|
||||
** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
|
||||
** If the allocation fails, set *pRc to SQLITE_NOMEM and return NULL.
|
||||
*/
|
||||
static void *idxMalloc(int *pRc, int nByte){
|
||||
|
@ -209,11 +209,11 @@ static int idxHashString(const char *z, int n){
|
|||
/*
|
||||
** If zKey is already present in the hash table, return non-zero and do
|
||||
** nothing. Otherwise, add an entry with key zKey and payload string zVal to
|
||||
** the hash table passed as the second argument.
|
||||
** the hash table passed as the second argument.
|
||||
*/
|
||||
static int idxHashAdd(
|
||||
int *pRc,
|
||||
IdxHash *pHash,
|
||||
int *pRc,
|
||||
IdxHash *pHash,
|
||||
const char *zKey,
|
||||
const char *zVal
|
||||
){
|
||||
|
@ -245,7 +245,7 @@ static int idxHashAdd(
|
|||
}
|
||||
|
||||
/*
|
||||
** If zKey/nKey is present in the hash table, return a pointer to the
|
||||
** If zKey/nKey is present in the hash table, return a pointer to the
|
||||
** hash-entry object.
|
||||
*/
|
||||
static IdxHashEntry *idxHashFind(IdxHash *pHash, const char *zKey, int nKey){
|
||||
|
@ -384,7 +384,7 @@ static char *expertDequote(const char *zIn){
|
|||
return zRet;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** This function is the implementation of both the xConnect and xCreate
|
||||
** methods of the r-tree virtual table.
|
||||
**
|
||||
|
@ -440,7 +440,7 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
|
|||
int rc = SQLITE_OK;
|
||||
int n = 0;
|
||||
IdxScan *pScan;
|
||||
const int opmask =
|
||||
const int opmask =
|
||||
SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_GT |
|
||||
SQLITE_INDEX_CONSTRAINT_LT | SQLITE_INDEX_CONSTRAINT_GE |
|
||||
SQLITE_INDEX_CONSTRAINT_LE;
|
||||
|
@ -457,10 +457,10 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
|
|||
/* Add the constraints to the IdxScan object */
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++){
|
||||
struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
|
||||
if( pCons->usable
|
||||
&& pCons->iColumn>=0
|
||||
if( pCons->usable
|
||||
&& pCons->iColumn>=0
|
||||
&& p->pTab->aCol[pCons->iColumn].iPk==0
|
||||
&& (pCons->op & opmask)
|
||||
&& (pCons->op & opmask)
|
||||
){
|
||||
IdxConstraint *pNew;
|
||||
const char *zColl = sqlite3_vtab_collation(pIdxInfo, i);
|
||||
|
@ -503,9 +503,9 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
|
|||
}
|
||||
|
||||
static int expertUpdate(
|
||||
sqlite3_vtab *pVtab,
|
||||
int nData,
|
||||
sqlite3_value **azData,
|
||||
sqlite3_vtab *pVtab,
|
||||
int nData,
|
||||
sqlite3_value **azData,
|
||||
sqlite_int64 *pRowid
|
||||
){
|
||||
(void)pVtab;
|
||||
|
@ -515,7 +515,7 @@ static int expertUpdate(
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Virtual table module xOpen method.
|
||||
*/
|
||||
static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
|
||||
|
@ -527,7 +527,7 @@ static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Virtual table module xClose method.
|
||||
*/
|
||||
static int expertClose(sqlite3_vtab_cursor *cur){
|
||||
|
@ -540,7 +540,7 @@ static int expertClose(sqlite3_vtab_cursor *cur){
|
|||
/*
|
||||
** Virtual table module xEof method.
|
||||
**
|
||||
** Return non-zero if the cursor does not currently point to a valid
|
||||
** Return non-zero if the cursor does not currently point to a valid
|
||||
** record (i.e if the scan has finished), or zero otherwise.
|
||||
*/
|
||||
static int expertEof(sqlite3_vtab_cursor *cur){
|
||||
|
@ -548,7 +548,7 @@ static int expertEof(sqlite3_vtab_cursor *cur){
|
|||
return pCsr->pData==0;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Virtual table module xNext method.
|
||||
*/
|
||||
static int expertNext(sqlite3_vtab_cursor *cur){
|
||||
|
@ -567,7 +567,7 @@ static int expertNext(sqlite3_vtab_cursor *cur){
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Virtual table module xRowid method.
|
||||
*/
|
||||
static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
|
@ -576,7 +576,7 @@ static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Virtual table module xColumn method.
|
||||
*/
|
||||
static int expertColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
||||
|
@ -589,11 +589,11 @@ static int expertColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
** Virtual table module xFilter method.
|
||||
*/
|
||||
static int expertFilter(
|
||||
sqlite3_vtab_cursor *cur,
|
||||
sqlite3_vtab_cursor *cur,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
|
@ -748,7 +748,7 @@ static int idxGetTableInfo(
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is a no-op if *pRc is set to anything other than
|
||||
** This function is a no-op if *pRc is set to anything other than
|
||||
** SQLITE_OK when it is called.
|
||||
**
|
||||
** If *pRc is initially set to SQLITE_OK, then the text specified by
|
||||
|
@ -838,7 +838,7 @@ static char *idxAppendColDefn(
|
|||
|
||||
/*
|
||||
** Search database dbm for an index compatible with the one idxCreateFromCons()
|
||||
** would create from arguments pScan, pEq and pTail. If no error occurs and
|
||||
** would create from arguments pScan, pEq and pTail. If no error occurs and
|
||||
** such an index is found, return non-zero. Or, if no such index is found,
|
||||
** return zero.
|
||||
**
|
||||
|
@ -914,7 +914,7 @@ static int idxFindCompatible(
|
|||
static int idxCreateFromCons(
|
||||
sqlite3expert *p,
|
||||
IdxScan *pScan,
|
||||
IdxConstraint *pEq,
|
||||
IdxConstraint *pEq,
|
||||
IdxConstraint *pTail
|
||||
){
|
||||
sqlite3 *dbm = p->dbm;
|
||||
|
@ -943,7 +943,7 @@ static int idxCreateFromCons(
|
|||
h += ((h<<3) + zCols[i]);
|
||||
}
|
||||
zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
|
||||
if( zName==0 ){
|
||||
if( zName==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
if( idxIdentifierRequiresQuotes(zTable) ){
|
||||
|
@ -981,7 +981,7 @@ static int idxFindConstraint(IdxConstraint *pList, IdxConstraint *p){
|
|||
}
|
||||
|
||||
static int idxCreateFromWhere(
|
||||
sqlite3expert *p,
|
||||
sqlite3expert *p,
|
||||
IdxScan *pScan, /* Create indexes for this scan */
|
||||
IdxConstraint *pTail /* range/ORDER BY constraints for inclusion */
|
||||
){
|
||||
|
@ -1016,7 +1016,7 @@ static int idxCreateFromWhere(
|
|||
}
|
||||
|
||||
/*
|
||||
** Create candidate indexes in database [dbm] based on the data in
|
||||
** Create candidate indexes in database [dbm] based on the data in
|
||||
** linked-list pScan.
|
||||
*/
|
||||
static int idxCreateCandidates(sqlite3expert *p){
|
||||
|
@ -1063,7 +1063,7 @@ static void idxScanFree(IdxScan *pScan, IdxScan *pLast){
|
|||
}
|
||||
|
||||
/*
|
||||
** Free all elements of the linked list starting from pStatement up
|
||||
** Free all elements of the linked list starting from pStatement up
|
||||
** until pLast (pLast is not freed).
|
||||
*/
|
||||
static void idxStatementFree(IdxStatement *pStatement, IdxStatement *pLast){
|
||||
|
@ -1141,8 +1141,8 @@ int idxFindIndexes(
|
|||
const char *zIdx = 0;
|
||||
if( i+13<nDetail && memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
|
||||
zIdx = &zDetail[i+13];
|
||||
}else if( i+22<nDetail
|
||||
&& memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0
|
||||
}else if( i+22<nDetail
|
||||
&& memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0
|
||||
){
|
||||
zIdx = &zDetail[i+22];
|
||||
}
|
||||
|
@ -1218,15 +1218,15 @@ static int idxAuthCallback(
|
|||
}
|
||||
|
||||
static int idxProcessOneTrigger(
|
||||
sqlite3expert *p,
|
||||
IdxWrite *pWrite,
|
||||
sqlite3expert *p,
|
||||
IdxWrite *pWrite,
|
||||
char **pzErr
|
||||
){
|
||||
static const char *zInt = UNIQUE_TABLE_NAME;
|
||||
static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
|
||||
IdxTable *pTab = pWrite->pTab;
|
||||
const char *zTab = pTab->zName;
|
||||
const char *zSql =
|
||||
const char *zSql =
|
||||
"SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_schema "
|
||||
"WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
|
||||
"ORDER BY type;";
|
||||
|
@ -1267,7 +1267,7 @@ static int idxProcessOneTrigger(
|
|||
int i;
|
||||
zWrite = idxAppendText(&rc, zWrite, "UPDATE %Q SET ", zInt);
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ",
|
||||
zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ",
|
||||
pTab->aCol[i].zName
|
||||
);
|
||||
}
|
||||
|
@ -1355,14 +1355,14 @@ static int idxCreateVtabSchema(sqlite3expert *p, char **pzErrmsg){
|
|||
/* The statement the vtab will pass to sqlite3_declare_vtab() */
|
||||
zInner = idxAppendText(&rc, 0, "CREATE TABLE x(");
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
|
||||
zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
|
||||
(i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl
|
||||
);
|
||||
}
|
||||
zInner = idxAppendText(&rc, zInner, ")");
|
||||
|
||||
/* The CVT statement to create the vtab */
|
||||
zOuter = idxAppendText(&rc, 0,
|
||||
zOuter = idxAppendText(&rc, 0,
|
||||
"CREATE VIRTUAL TABLE %Q USING expert(%Q)", zName, zInner
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
|
@ -1500,7 +1500,7 @@ static void idxRemFunc(
|
|||
|
||||
static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
|
||||
int rc = SQLITE_OK;
|
||||
const char *zMax =
|
||||
const char *zMax =
|
||||
"SELECT max(i.seqno) FROM "
|
||||
" sqlite_schema AS s, "
|
||||
" pragma_index_list(s.name) AS l, "
|
||||
|
@ -1543,7 +1543,7 @@ static int idxPopulateOneStat1(
|
|||
const char *zComma = zCols==0 ? "" : ", ";
|
||||
const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0);
|
||||
const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1);
|
||||
zCols = idxAppendText(&rc, zCols,
|
||||
zCols = idxAppendText(&rc, zCols,
|
||||
"%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl
|
||||
);
|
||||
zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
|
||||
|
@ -1640,13 +1640,13 @@ static int idxBuildSampleTable(sqlite3expert *p, const char *zTab){
|
|||
** indexes have already been created in database sqlite3expert.dbm, this
|
||||
** function populates sqlite_stat1 table in the same database.
|
||||
**
|
||||
** The stat1 data is generated by querying the
|
||||
** The stat1 data is generated by querying the
|
||||
*/
|
||||
static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
|
||||
int rc = SQLITE_OK;
|
||||
int nMax =0;
|
||||
struct IdxRemCtx *pCtx = 0;
|
||||
struct IdxSampleCtx samplectx;
|
||||
struct IdxSampleCtx samplectx;
|
||||
int i;
|
||||
i64 iPrev = -100000;
|
||||
sqlite3_stmt *pAllIndex = 0;
|
||||
|
@ -1658,7 +1658,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
|
|||
" sqlite_schema AS s, "
|
||||
" pragma_index_list(s.name) AS l "
|
||||
"WHERE s.type = 'table'";
|
||||
const char *zIndexXInfo =
|
||||
const char *zIndexXInfo =
|
||||
"SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
|
||||
const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
|
||||
|
||||
|
@ -1714,7 +1714,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
|
|||
iPrev = iRowid;
|
||||
}
|
||||
if( rc==SQLITE_OK && p->iSample<100 ){
|
||||
rc = sqlite3_exec(p->dbv,
|
||||
rc = sqlite3_exec(p->dbv,
|
||||
"DROP TABLE IF EXISTS temp." UNIQUE_TABLE_NAME, 0,0,0
|
||||
);
|
||||
}
|
||||
|
@ -1764,12 +1764,12 @@ sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErrmsg){
|
|||
sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Copy the entire schema of database [db] into [dbm]. */
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_stmt *pSql;
|
||||
rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
|
||||
rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
|
||||
"SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
|
||||
" AND sql NOT LIKE 'CREATE VIRTUAL %%'"
|
||||
);
|
||||
|
@ -1890,8 +1890,8 @@ int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr){
|
|||
|
||||
/* Formulate the EXPERT_REPORT_CANDIDATES text */
|
||||
for(pEntry=p->hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
|
||||
p->zCandidates = idxAppendText(&rc, p->zCandidates,
|
||||
"%s;%s%s\n", pEntry->zVal,
|
||||
p->zCandidates = idxAppendText(&rc, p->zCandidates,
|
||||
"%s;%s%s\n", pEntry->zVal,
|
||||
pEntry->zVal2 ? " -- stat1: " : "", pEntry->zVal2
|
||||
);
|
||||
}
|
||||
|
|
4
third_party/sqlite3/sqlite3ext.h
vendored
4
third_party/sqlite3/sqlite3ext.h
vendored
|
@ -638,14 +638,14 @@ typedef int (*sqlite3_loadext_entry)(
|
|||
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
||||
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
/* This case when the file really is being compiled as a loadable
|
||||
/* This case when the file really is being compiled as a loadable
|
||||
** extension */
|
||||
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
|
||||
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
|
||||
# define SQLITE_EXTENSION_INIT3 \
|
||||
extern const sqlite3_api_routines *sqlite3_api;
|
||||
#else
|
||||
/* This case when the file is being statically linked into the
|
||||
/* This case when the file is being statically linked into the
|
||||
** application */
|
||||
# define SQLITE_EXTENSION_INIT1 /*no-op*/
|
||||
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
|
||||
|
|
478
third_party/sqlite3/sqlite3rbu.c
vendored
478
third_party/sqlite3/sqlite3rbu.c
vendored
File diff suppressed because it is too large
Load diff
192
third_party/sqlite3/sqlite3rbu.inc
vendored
192
third_party/sqlite3/sqlite3rbu.inc
vendored
|
@ -17,36 +17,36 @@
|
|||
/*
|
||||
** SUMMARY
|
||||
**
|
||||
** Writing a transaction containing a large number of operations on
|
||||
** Writing a transaction containing a large number of operations on
|
||||
** b-tree indexes that are collectively larger than the available cache
|
||||
** memory can be very inefficient.
|
||||
** memory can be very inefficient.
|
||||
**
|
||||
** The problem is that in order to update a b-tree, the leaf page (at least)
|
||||
** containing the entry being inserted or deleted must be modified. If the
|
||||
** working set of leaves is larger than the available cache memory, then a
|
||||
** single leaf that is modified more than once as part of the transaction
|
||||
** working set of leaves is larger than the available cache memory, then a
|
||||
** single leaf that is modified more than once as part of the transaction
|
||||
** may be loaded from or written to the persistent media multiple times.
|
||||
** Additionally, because the index updates are likely to be applied in
|
||||
** random order, access to pages within the database is also likely to be in
|
||||
** random order, access to pages within the database is also likely to be in
|
||||
** random order, which is itself quite inefficient.
|
||||
**
|
||||
** One way to improve the situation is to sort the operations on each index
|
||||
** by index key before applying them to the b-tree. This leads to an IO
|
||||
** pattern that resembles a single linear scan through the index b-tree,
|
||||
** and all but guarantees each modified leaf page is loaded and stored
|
||||
** and all but guarantees each modified leaf page is loaded and stored
|
||||
** exactly once. SQLite uses this trick to improve the performance of
|
||||
** CREATE INDEX commands. This extension allows it to be used to improve
|
||||
** the performance of large transactions on existing databases.
|
||||
**
|
||||
** Additionally, this extension allows the work involved in writing the
|
||||
** large transaction to be broken down into sub-transactions performed
|
||||
** sequentially by separate processes. This is useful if the system cannot
|
||||
** guarantee that a single update process will run for long enough to apply
|
||||
** the entire update, for example because the update is being applied on a
|
||||
** mobile device that is frequently rebooted. Even after the writer process
|
||||
** Additionally, this extension allows the work involved in writing the
|
||||
** large transaction to be broken down into sub-transactions performed
|
||||
** sequentially by separate processes. This is useful if the system cannot
|
||||
** guarantee that a single update process will run for long enough to apply
|
||||
** the entire update, for example because the update is being applied on a
|
||||
** mobile device that is frequently rebooted. Even after the writer process
|
||||
** has committed one or more sub-transactions, other database clients continue
|
||||
** to read from the original database snapshot. In other words, partially
|
||||
** applied transactions are not visible to other clients.
|
||||
** to read from the original database snapshot. In other words, partially
|
||||
** applied transactions are not visible to other clients.
|
||||
**
|
||||
** "RBU" stands for "Resumable Bulk Update". As in a large database update
|
||||
** transmitted via a wireless network to a mobile device. A transaction
|
||||
|
@ -62,9 +62,9 @@
|
|||
**
|
||||
** * INSERT statements may not use any default values.
|
||||
**
|
||||
** * UPDATE and DELETE statements must identify their target rows by
|
||||
** * UPDATE and DELETE statements must identify their target rows by
|
||||
** non-NULL PRIMARY KEY values. Rows with NULL values stored in PRIMARY
|
||||
** KEY fields may not be updated or deleted. If the table being written
|
||||
** KEY fields may not be updated or deleted. If the table being written
|
||||
** has no PRIMARY KEY, affected rows must be identified by rowid.
|
||||
**
|
||||
** * UPDATE statements may not modify PRIMARY KEY columns.
|
||||
|
@ -81,10 +81,10 @@
|
|||
** PREPARATION
|
||||
**
|
||||
** An "RBU update" is stored as a separate SQLite database. A database
|
||||
** containing an RBU update is an "RBU database". For each table in the
|
||||
** containing an RBU update is an "RBU database". For each table in the
|
||||
** target database to be updated, the RBU database should contain a table
|
||||
** named "data_<target name>" containing the same set of columns as the
|
||||
** target table, and one more - "rbu_control". The data_% table should
|
||||
** target table, and one more - "rbu_control". The data_% table should
|
||||
** have no PRIMARY KEY or UNIQUE constraints, but each column should have
|
||||
** the same type as the corresponding column in the target database.
|
||||
** The "rbu_control" column should have no type at all. For example, if
|
||||
|
@ -99,22 +99,22 @@
|
|||
** The order of the columns in the data_% table does not matter.
|
||||
**
|
||||
** Instead of a regular table, the RBU database may also contain virtual
|
||||
** tables or view named using the data_<target> naming scheme.
|
||||
** tables or view named using the data_<target> naming scheme.
|
||||
**
|
||||
** Instead of the plain data_<target> naming scheme, RBU database tables
|
||||
** Instead of the plain data_<target> naming scheme, RBU database tables
|
||||
** may also be named data<integer>_<target>, where <integer> is any sequence
|
||||
** of zero or more numeric characters (0-9). This can be significant because
|
||||
** tables within the RBU database are always processed in order sorted by
|
||||
** tables within the RBU database are always processed in order sorted by
|
||||
** name. By judicious selection of the <integer> portion of the names
|
||||
** of the RBU tables the user can therefore control the order in which they
|
||||
** are processed. This can be useful, for example, to ensure that "external
|
||||
** content" FTS4 tables are updated before their underlying content tables.
|
||||
**
|
||||
** If the target database table is a virtual table or a table that has no
|
||||
** PRIMARY KEY declaration, the data_% table must also contain a column
|
||||
** named "rbu_rowid". This column is mapped to the tables implicit primary
|
||||
** key column - "rowid". Virtual tables for which the "rowid" column does
|
||||
** not function like a primary key value cannot be updated using RBU. For
|
||||
** PRIMARY KEY declaration, the data_% table must also contain a column
|
||||
** named "rbu_rowid". This column is mapped to the tables implicit primary
|
||||
** key column - "rowid". Virtual tables for which the "rowid" column does
|
||||
** not function like a primary key value cannot be updated using RBU. For
|
||||
** example, if the target db contains either of the following:
|
||||
**
|
||||
** CREATE VIRTUAL TABLE x1 USING fts3(a, b);
|
||||
|
@ -137,35 +137,35 @@
|
|||
** CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control);
|
||||
** CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control);
|
||||
**
|
||||
** For each row to INSERT into the target database as part of the RBU
|
||||
** For each row to INSERT into the target database as part of the RBU
|
||||
** update, the corresponding data_% table should contain a single record
|
||||
** with the "rbu_control" column set to contain integer value 0. The
|
||||
** other columns should be set to the values that make up the new record
|
||||
** to insert.
|
||||
** other columns should be set to the values that make up the new record
|
||||
** to insert.
|
||||
**
|
||||
** If the target database table has an INTEGER PRIMARY KEY, it is not
|
||||
** possible to insert a NULL value into the IPK column. Attempting to
|
||||
** If the target database table has an INTEGER PRIMARY KEY, it is not
|
||||
** possible to insert a NULL value into the IPK column. Attempting to
|
||||
** do so results in an SQLITE_MISMATCH error.
|
||||
**
|
||||
** For each row to DELETE from the target database as part of the RBU
|
||||
** For each row to DELETE from the target database as part of the RBU
|
||||
** update, the corresponding data_% table should contain a single record
|
||||
** with the "rbu_control" column set to contain integer value 1. The
|
||||
** real primary key values of the row to delete should be stored in the
|
||||
** corresponding columns of the data_% table. The values stored in the
|
||||
** other columns are not used.
|
||||
**
|
||||
** For each row to UPDATE from the target database as part of the RBU
|
||||
** For each row to UPDATE from the target database as part of the RBU
|
||||
** update, the corresponding data_% table should contain a single record
|
||||
** with the "rbu_control" column set to contain a value of type text.
|
||||
** The real primary key values identifying the row to update should be
|
||||
** The real primary key values identifying the row to update should be
|
||||
** stored in the corresponding columns of the data_% table row, as should
|
||||
** the new values of all columns being update. The text value in the
|
||||
** the new values of all columns being update. The text value in the
|
||||
** "rbu_control" column must contain the same number of characters as
|
||||
** there are columns in the target database table, and must consist entirely
|
||||
** of 'x' and '.' characters (or in some special cases 'd' - see below). For
|
||||
** of 'x' and '.' characters (or in some special cases 'd' - see below). For
|
||||
** each column that is being updated, the corresponding character is set to
|
||||
** 'x'. For those that remain as they are, the corresponding character of the
|
||||
** rbu_control value should be set to '.'. For example, given the tables
|
||||
** rbu_control value should be set to '.'. For example, given the tables
|
||||
** above, the update statement:
|
||||
**
|
||||
** UPDATE t1 SET c = 'usa' WHERE a = 4;
|
||||
|
@ -179,30 +179,30 @@
|
|||
** target table with the value stored in the corresponding data_% column, the
|
||||
** user-defined SQL function "rbu_delta()" is invoked and the result stored in
|
||||
** the target table column. rbu_delta() is invoked with two arguments - the
|
||||
** original value currently stored in the target table column and the
|
||||
** original value currently stored in the target table column and the
|
||||
** value specified in the data_xxx table.
|
||||
**
|
||||
** For example, this row:
|
||||
**
|
||||
** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
|
||||
**
|
||||
** is similar to an UPDATE statement such as:
|
||||
** is similar to an UPDATE statement such as:
|
||||
**
|
||||
** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
|
||||
**
|
||||
** Finally, if an 'f' character appears in place of a 'd' or 's' in an
|
||||
** Finally, if an 'f' character appears in place of a 'd' or 's' in an
|
||||
** ota_control string, the contents of the data_xxx table column is assumed
|
||||
** to be a "fossil delta" - a patch to be applied to a blob value in the
|
||||
** format used by the fossil source-code management system. In this case
|
||||
** the existing value within the target database table must be of type BLOB.
|
||||
** the existing value within the target database table must be of type BLOB.
|
||||
** It is replaced by the result of applying the specified fossil delta to
|
||||
** itself.
|
||||
**
|
||||
** If the target database table is a virtual table or a table with no PRIMARY
|
||||
** KEY, the rbu_control value should not include a character corresponding
|
||||
** KEY, the rbu_control value should not include a character corresponding
|
||||
** to the rbu_rowid value. For example, this:
|
||||
**
|
||||
** INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control)
|
||||
** INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control)
|
||||
** VALUES(NULL, 'usa', 12, '.x');
|
||||
**
|
||||
** causes a result similar to:
|
||||
|
@ -212,14 +212,14 @@
|
|||
** The data_xxx tables themselves should have no PRIMARY KEY declarations.
|
||||
** However, RBU is more efficient if reading the rows in from each data_xxx
|
||||
** table in "rowid" order is roughly the same as reading them sorted by
|
||||
** the PRIMARY KEY of the corresponding target database table. In other
|
||||
** words, rows should be sorted using the destination table PRIMARY KEY
|
||||
** the PRIMARY KEY of the corresponding target database table. In other
|
||||
** words, rows should be sorted using the destination table PRIMARY KEY
|
||||
** fields before they are inserted into the data_xxx tables.
|
||||
**
|
||||
** USAGE
|
||||
**
|
||||
** The API declared below allows an application to apply an RBU update
|
||||
** stored on disk to an existing target database. Essentially, the
|
||||
** The API declared below allows an application to apply an RBU update
|
||||
** stored on disk to an existing target database. Essentially, the
|
||||
** application:
|
||||
**
|
||||
** 1) Opens an RBU handle using the sqlite3rbu_open() function.
|
||||
|
@ -230,24 +230,24 @@
|
|||
**
|
||||
** 3) Calls the sqlite3rbu_step() function one or more times on
|
||||
** the new handle. Each call to sqlite3rbu_step() performs a single
|
||||
** b-tree operation, so thousands of calls may be required to apply
|
||||
** b-tree operation, so thousands of calls may be required to apply
|
||||
** a complete update.
|
||||
**
|
||||
** 4) Calls sqlite3rbu_close() to close the RBU update handle. If
|
||||
** sqlite3rbu_step() has been called enough times to completely
|
||||
** apply the update to the target database, then the RBU database
|
||||
** is marked as fully applied. Otherwise, the state of the RBU
|
||||
** update application is saved in the RBU database for later
|
||||
** is marked as fully applied. Otherwise, the state of the RBU
|
||||
** update application is saved in the RBU database for later
|
||||
** resumption.
|
||||
**
|
||||
** See comments below for more detail on APIs.
|
||||
**
|
||||
** If an update is only partially applied to the target database by the
|
||||
** time sqlite3rbu_close() is called, various state information is saved
|
||||
** time sqlite3rbu_close() is called, various state information is saved
|
||||
** within the RBU database. This allows subsequent processes to automatically
|
||||
** resume the RBU update from where it left off.
|
||||
**
|
||||
** To remove all RBU extension state information, returning an RBU database
|
||||
** To remove all RBU extension state information, returning an RBU database
|
||||
** to its original contents, it is sufficient to drop all tables that begin
|
||||
** with the prefix "rbu_"
|
||||
**
|
||||
|
@ -283,21 +283,21 @@ typedef struct sqlite3rbu sqlite3rbu;
|
|||
** the path to the RBU database. Each call to this function must be matched
|
||||
** by a call to sqlite3rbu_close(). When opening the databases, RBU passes
|
||||
** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget
|
||||
** or zRbu begin with "file:", it will be interpreted as an SQLite
|
||||
** or zRbu begin with "file:", it will be interpreted as an SQLite
|
||||
** database URI, not a regular file name.
|
||||
**
|
||||
** If the zState argument is passed a NULL value, the RBU extension stores
|
||||
** the current state of the update (how many rows have been updated, which
|
||||
** If the zState argument is passed a NULL value, the RBU extension stores
|
||||
** the current state of the update (how many rows have been updated, which
|
||||
** indexes are yet to be updated etc.) within the RBU database itself. This
|
||||
** can be convenient, as it means that the RBU application does not need to
|
||||
** organize removing a separate state file after the update is concluded.
|
||||
** Or, if zState is non-NULL, it must be a path to a database file in which
|
||||
** organize removing a separate state file after the update is concluded.
|
||||
** Or, if zState is non-NULL, it must be a path to a database file in which
|
||||
** the RBU extension can store the state of the update.
|
||||
**
|
||||
** When resuming an RBU update, the zState argument must be passed the same
|
||||
** value as when the RBU update was started.
|
||||
**
|
||||
** Once the RBU update is finished, the RBU extension does not
|
||||
** Once the RBU update is finished, the RBU extension does not
|
||||
** automatically remove any zState database file, even if it created it.
|
||||
**
|
||||
** By default, RBU uses the default VFS to access the files on disk. To
|
||||
|
@ -310,7 +310,7 @@ typedef struct sqlite3rbu sqlite3rbu;
|
|||
** the zipvfs_create_vfs() API below for details on using RBU with zipvfs.
|
||||
*/
|
||||
SQLITE_API sqlite3rbu *sqlite3rbu_open(
|
||||
const char *zTarget,
|
||||
const char *zTarget,
|
||||
const char *zRbu,
|
||||
const char *zState
|
||||
);
|
||||
|
@ -320,13 +320,13 @@ SQLITE_API sqlite3rbu *sqlite3rbu_open(
|
|||
** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
|
||||
** that it can be suspended and resumed like an RBU update.
|
||||
**
|
||||
** The second argument to this function identifies a database in which
|
||||
** to store the state of the RBU vacuum operation if it is suspended. The
|
||||
** The second argument to this function identifies a database in which
|
||||
** to store the state of the RBU vacuum operation if it is suspended. The
|
||||
** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
|
||||
** operation, the state database should either not exist or be empty
|
||||
** (contain no tables). If an RBU vacuum is suspended by calling
|
||||
** (contain no tables). If an RBU vacuum is suspended by calling
|
||||
** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
|
||||
** returned SQLITE_DONE, the vacuum state is stored in the state database.
|
||||
** returned SQLITE_DONE, the vacuum state is stored in the state database.
|
||||
** The vacuum can be resumed by calling this function to open a new RBU
|
||||
** handle specifying the same target and state databases.
|
||||
**
|
||||
|
@ -334,26 +334,26 @@ SQLITE_API sqlite3rbu *sqlite3rbu_open(
|
|||
** name of the state database is "<database>-vacuum", where <database>
|
||||
** is the name of the target database file. In this case, on UNIX, if the
|
||||
** state database is not already present in the file-system, it is created
|
||||
** with the same permissions as the target db is made.
|
||||
** with the same permissions as the target db is made.
|
||||
**
|
||||
** With an RBU vacuum, it is an SQLITE_MISUSE error if the name of the
|
||||
** state database ends with "-vactmp". This name is reserved for internal
|
||||
** With an RBU vacuum, it is an SQLITE_MISUSE error if the name of the
|
||||
** state database ends with "-vactmp". This name is reserved for internal
|
||||
** use.
|
||||
**
|
||||
** This function does not delete the state database after an RBU vacuum
|
||||
** is completed, even if it created it. However, if the call to
|
||||
** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
|
||||
** of the state tables within the state database are zeroed. This way,
|
||||
** the next call to sqlite3rbu_vacuum() opens a handle that starts a
|
||||
** the next call to sqlite3rbu_vacuum() opens a handle that starts a
|
||||
** new RBU vacuum operation.
|
||||
**
|
||||
** As with sqlite3rbu_open(), Zipvfs users should rever to the comment
|
||||
** describing the sqlite3rbu_create_vfs() API function below for
|
||||
** a description of the complications associated with using RBU with
|
||||
** describing the sqlite3rbu_create_vfs() API function below for
|
||||
** a description of the complications associated with using RBU with
|
||||
** zipvfs databases.
|
||||
*/
|
||||
SQLITE_API sqlite3rbu *sqlite3rbu_vacuum(
|
||||
const char *zTarget,
|
||||
const char *zTarget,
|
||||
const char *zState
|
||||
);
|
||||
|
||||
|
@ -365,7 +365,7 @@ SQLITE_API sqlite3rbu *sqlite3rbu_vacuum(
|
|||
** is removed entirely. If the second parameter is negative, the limit is
|
||||
** not modified (this is useful for querying the current limit).
|
||||
**
|
||||
** In all cases the returned value is the current limit in bytes (zero
|
||||
** In all cases the returned value is the current limit in bytes (zero
|
||||
** indicates unlimited).
|
||||
**
|
||||
** If the temp space limit is exceeded during operation, an SQLITE_FULL
|
||||
|
@ -374,13 +374,13 @@ SQLITE_API sqlite3rbu *sqlite3rbu_vacuum(
|
|||
SQLITE_API sqlite3_int64 sqlite3rbu_temp_size_limit(sqlite3rbu*, sqlite3_int64);
|
||||
|
||||
/*
|
||||
** Return the current amount of temp file space, in bytes, currently used by
|
||||
** Return the current amount of temp file space, in bytes, currently used by
|
||||
** the RBU handle passed as the only argument.
|
||||
*/
|
||||
SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu*);
|
||||
|
||||
/*
|
||||
** Internally, each RBU connection uses a separate SQLite database
|
||||
** Internally, each RBU connection uses a separate SQLite database
|
||||
** connection to access the target and rbu update databases. This
|
||||
** API allows the application direct access to these database handles.
|
||||
**
|
||||
|
@ -391,10 +391,10 @@ SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu*);
|
|||
** following scenarios:
|
||||
**
|
||||
** * If any target tables are virtual tables, it may be necessary to
|
||||
** call sqlite3_create_module() on the target database handle to
|
||||
** call sqlite3_create_module() on the target database handle to
|
||||
** register the required virtual table implementations.
|
||||
**
|
||||
** * If the data_xxx tables in the RBU source database are virtual
|
||||
** * If the data_xxx tables in the RBU source database are virtual
|
||||
** tables, the application may need to call sqlite3_create_module() on
|
||||
** the rbu update db handle to any required virtual table
|
||||
** implementations.
|
||||
|
@ -413,12 +413,12 @@ SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu*);
|
|||
SQLITE_API sqlite3 *sqlite3rbu_db(sqlite3rbu*, int bRbu);
|
||||
|
||||
/*
|
||||
** Do some work towards applying the RBU update to the target db.
|
||||
** Do some work towards applying the RBU update to the target db.
|
||||
**
|
||||
** Return SQLITE_DONE if the update has been completely applied, or
|
||||
** Return SQLITE_DONE if the update has been completely applied, or
|
||||
** SQLITE_OK if no error occurs but there remains work to do to apply
|
||||
** the RBU update. If an error does occur, some other error code is
|
||||
** returned.
|
||||
** the RBU update. If an error does occur, some other error code is
|
||||
** returned.
|
||||
**
|
||||
** Once a call to sqlite3rbu_step() has returned a value other than
|
||||
** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
|
||||
|
@ -431,7 +431,7 @@ SQLITE_API int sqlite3rbu_step(sqlite3rbu *pRbu);
|
|||
**
|
||||
** If a power failure or application crash occurs during an update, following
|
||||
** system recovery RBU may resume the update from the point at which the state
|
||||
** was last saved. In other words, from the most recent successful call to
|
||||
** was last saved. In other words, from the most recent successful call to
|
||||
** sqlite3rbu_close() or this function.
|
||||
**
|
||||
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
|
||||
|
@ -439,7 +439,7 @@ SQLITE_API int sqlite3rbu_step(sqlite3rbu *pRbu);
|
|||
SQLITE_API int sqlite3rbu_savestate(sqlite3rbu *pRbu);
|
||||
|
||||
/*
|
||||
** Close an RBU handle.
|
||||
** Close an RBU handle.
|
||||
**
|
||||
** If the RBU update has been completely applied, mark the RBU database
|
||||
** as fully applied. Otherwise, assuming no error has occurred, save the
|
||||
|
@ -453,20 +453,20 @@ SQLITE_API int sqlite3rbu_savestate(sqlite3rbu *pRbu);
|
|||
** eventually free any such buffer using sqlite3_free().
|
||||
**
|
||||
** Otherwise, if no error occurs, this function returns SQLITE_OK if the
|
||||
** update has been partially applied, or SQLITE_DONE if it has been
|
||||
** update has been partially applied, or SQLITE_DONE if it has been
|
||||
** completely applied.
|
||||
*/
|
||||
SQLITE_API int sqlite3rbu_close(sqlite3rbu *pRbu, char **pzErrmsg);
|
||||
|
||||
/*
|
||||
** Return the total number of key-value operations (inserts, deletes or
|
||||
** Return the total number of key-value operations (inserts, deletes or
|
||||
** updates) that have been performed on the target database since the
|
||||
** current RBU update was started.
|
||||
*/
|
||||
SQLITE_API sqlite3_int64 sqlite3rbu_progress(sqlite3rbu *pRbu);
|
||||
|
||||
/*
|
||||
** Obtain permyriadage (permyriadage is to 10000 as percentage is to 100)
|
||||
** Obtain permyriadage (permyriadage is to 10000 as percentage is to 100)
|
||||
** progress indications for the two stages of an RBU update. This API may
|
||||
** be useful for driving GUI progress indicators and similar.
|
||||
**
|
||||
|
@ -479,16 +479,16 @@ SQLITE_API sqlite3_int64 sqlite3rbu_progress(sqlite3rbu *pRbu);
|
|||
** The update is visible to non-RBU clients during stage 2. During stage 1
|
||||
** non-RBU reader clients may see the original database.
|
||||
**
|
||||
** If this API is called during stage 2 of the update, output variable
|
||||
** If this API is called during stage 2 of the update, output variable
|
||||
** (*pnOne) is set to 10000 to indicate that stage 1 has finished and (*pnTwo)
|
||||
** to a value between 0 and 10000 to indicate the permyriadage progress of
|
||||
** stage 2. A value of 5000 indicates that stage 2 is half finished,
|
||||
** stage 2. A value of 5000 indicates that stage 2 is half finished,
|
||||
** 9000 indicates that it is 90% finished, and so on.
|
||||
**
|
||||
** If this API is called during stage 1 of the update, output variable
|
||||
** If this API is called during stage 1 of the update, output variable
|
||||
** (*pnTwo) is set to 0 to indicate that stage 2 has not yet started. The
|
||||
** value to which (*pnOne) is set depends on whether or not the RBU
|
||||
** database contains an "rbu_count" table. The rbu_count table, if it
|
||||
** value to which (*pnOne) is set depends on whether or not the RBU
|
||||
** database contains an "rbu_count" table. The rbu_count table, if it
|
||||
** exists, must contain the same columns as the following:
|
||||
**
|
||||
** CREATE TABLE rbu_count(tbl TEXT PRIMARY KEY, cnt INTEGER) WITHOUT ROWID;
|
||||
|
@ -547,20 +547,20 @@ SQLITE_API int sqlite3rbu_state(sqlite3rbu *pRbu);
|
|||
|
||||
/*
|
||||
** Create an RBU VFS named zName that accesses the underlying file-system
|
||||
** via existing VFS zParent. Or, if the zParent parameter is passed NULL,
|
||||
** via existing VFS zParent. Or, if the zParent parameter is passed NULL,
|
||||
** then the new RBU VFS uses the default system VFS to access the file-system.
|
||||
** The new object is registered as a non-default VFS with SQLite before
|
||||
** The new object is registered as a non-default VFS with SQLite before
|
||||
** returning.
|
||||
**
|
||||
** Part of the RBU implementation uses a custom VFS object. Usually, this
|
||||
** object is created and deleted automatically by RBU.
|
||||
** object is created and deleted automatically by RBU.
|
||||
**
|
||||
** The exception is for applications that also use zipvfs. In this case,
|
||||
** the custom VFS must be explicitly created by the user before the RBU
|
||||
** handle is opened. The RBU VFS should be installed so that the zipvfs
|
||||
** VFS uses the RBU VFS, which in turn uses any other VFS layers in use
|
||||
** VFS uses the RBU VFS, which in turn uses any other VFS layers in use
|
||||
** (for example multiplexor) to access the file-system. For example,
|
||||
** to assemble an RBU enabled VFS stack that uses both zipvfs and
|
||||
** to assemble an RBU enabled VFS stack that uses both zipvfs and
|
||||
** multiplexor (error checking omitted):
|
||||
**
|
||||
** // Create a VFS named "multiplex" (not the default).
|
||||
|
@ -582,9 +582,9 @@ SQLITE_API int sqlite3rbu_state(sqlite3rbu *pRbu);
|
|||
** may be used by RBU clients. Attempting to use RBU with a zipvfs VFS stack
|
||||
** that does not include the RBU layer results in an error.
|
||||
**
|
||||
** The overhead of adding the "rbu" VFS to the system is negligible for
|
||||
** non-RBU users. There is no harm in an application accessing the
|
||||
** file-system via "rbu" all the time, even if it only uses RBU functionality
|
||||
** The overhead of adding the "rbu" VFS to the system is negligible for
|
||||
** non-RBU users. There is no harm in an application accessing the
|
||||
** file-system via "rbu" all the time, even if it only uses RBU functionality
|
||||
** occasionally.
|
||||
*/
|
||||
SQLITE_API int sqlite3rbu_create_vfs(const char *zName, const char *zParent);
|
||||
|
|
4
third_party/sqlite3/sqlite3rtree.inc
vendored
4
third_party/sqlite3/sqlite3rtree.inc
vendored
|
@ -60,7 +60,7 @@ struct sqlite3_rtree_geometry {
|
|||
};
|
||||
|
||||
/*
|
||||
** Register a 2nd-generation geometry callback named zScore that can be
|
||||
** Register a 2nd-generation geometry callback named zScore that can be
|
||||
** used as part of an R-Tree geometry query as follows:
|
||||
**
|
||||
** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
|
||||
|
@ -75,7 +75,7 @@ int sqlite3_rtree_query_callback(
|
|||
|
||||
|
||||
/*
|
||||
** A pointer to a structure of the following type is passed as the
|
||||
** A pointer to a structure of the following type is passed as the
|
||||
** argument to scored geometry callback registered using
|
||||
** sqlite3_rtree_query_callback().
|
||||
**
|
||||
|
|
386
third_party/sqlite3/sqlite3session.inc
vendored
386
third_party/sqlite3/sqlite3session.inc
vendored
|
@ -51,7 +51,7 @@ typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;
|
|||
** is not possible for an application to register a pre-update hook on a
|
||||
** database handle that has one or more session objects attached. Nor is
|
||||
** it possible to create a session object attached to a database handle for
|
||||
** which a pre-update hook is already defined. The results of attempting
|
||||
** which a pre-update hook is already defined. The results of attempting
|
||||
** either of these things are undefined.
|
||||
**
|
||||
** The session object will be used to create changesets for tables in
|
||||
|
@ -69,13 +69,13 @@ int sqlite3session_create(
|
|||
** CAPI3REF: Delete A Session Object
|
||||
** DESTRUCTOR: sqlite3_session
|
||||
**
|
||||
** Delete a session object previously allocated using
|
||||
** Delete a session object previously allocated using
|
||||
** [sqlite3session_create()]. Once a session object has been deleted, the
|
||||
** results of attempting to use pSession with any other session module
|
||||
** function are undefined.
|
||||
**
|
||||
** Session objects must be deleted before the database handle to which they
|
||||
** are attached is closed. Refer to the documentation for
|
||||
** are attached is closed. Refer to the documentation for
|
||||
** [sqlite3session_create()] for details.
|
||||
*/
|
||||
void sqlite3session_delete(sqlite3_session *pSession);
|
||||
|
@ -93,10 +93,10 @@ void sqlite3session_delete(sqlite3_session *pSession);
|
|||
** the eventual changesets.
|
||||
**
|
||||
** Passing zero to this function disables the session. Passing a value
|
||||
** greater than zero enables it. Passing a value less than zero is a
|
||||
** greater than zero enables it. Passing a value less than zero is a
|
||||
** no-op, and may be used to query the current state of the session.
|
||||
**
|
||||
** The return value indicates the final state of the session object: 0 if
|
||||
** The return value indicates the final state of the session object: 0 if
|
||||
** the session is disabled, or 1 if it is enabled.
|
||||
*/
|
||||
int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
|
||||
|
@ -111,7 +111,7 @@ int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
|
|||
** <ul>
|
||||
** <li> The session object "indirect" flag is set when the change is
|
||||
** made, or
|
||||
** <li> The change is made by an SQL trigger or foreign key action
|
||||
** <li> The change is made by an SQL trigger or foreign key action
|
||||
** instead of directly as a result of a users SQL statement.
|
||||
** </ul>
|
||||
**
|
||||
|
@ -123,10 +123,10 @@ int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
|
|||
** flag. If the second argument passed to this function is zero, then the
|
||||
** indirect flag is cleared. If it is greater than zero, the indirect flag
|
||||
** is set. Passing a value less than zero does not modify the current value
|
||||
** of the indirect flag, and may be used to query the current state of the
|
||||
** of the indirect flag, and may be used to query the current state of the
|
||||
** indirect flag for the specified session object.
|
||||
**
|
||||
** The return value indicates the final state of the indirect flag: 0 if
|
||||
** The return value indicates the final state of the indirect flag: 0 if
|
||||
** it is clear, or 1 if it is set.
|
||||
*/
|
||||
int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
|
||||
|
@ -136,20 +136,20 @@ int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
|
|||
** METHOD: sqlite3_session
|
||||
**
|
||||
** If argument zTab is not NULL, then it is the name of a table to attach
|
||||
** to the session object passed as the first argument. All subsequent changes
|
||||
** made to the table while the session object is enabled will be recorded. See
|
||||
** to the session object passed as the first argument. All subsequent changes
|
||||
** made to the table while the session object is enabled will be recorded. See
|
||||
** documentation for [sqlite3session_changeset()] for further details.
|
||||
**
|
||||
** Or, if argument zTab is NULL, then changes are recorded for all tables
|
||||
** in the database. If additional tables are added to the database (by
|
||||
** executing "CREATE TABLE" statements) after this call is made, changes for
|
||||
** in the database. If additional tables are added to the database (by
|
||||
** executing "CREATE TABLE" statements) after this call is made, changes for
|
||||
** the new tables are also recorded.
|
||||
**
|
||||
** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
|
||||
** defined as part of their CREATE TABLE statement. It does not matter if the
|
||||
** defined as part of their CREATE TABLE statement. It does not matter if the
|
||||
** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
|
||||
** KEY may consist of a single column, or may be a composite key.
|
||||
**
|
||||
**
|
||||
** It is not an error if the named table does not exist in the database. Nor
|
||||
** is it an error if the named table does not have a PRIMARY KEY. However,
|
||||
** no changes will be recorded in either of these scenarios.
|
||||
|
@ -157,29 +157,29 @@ int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
|
|||
** Changes are not recorded for individual rows that have NULL values stored
|
||||
** in one or more of their PRIMARY KEY columns.
|
||||
**
|
||||
** SQLITE_OK is returned if the call completes without error. Or, if an error
|
||||
** SQLITE_OK is returned if the call completes without error. Or, if an error
|
||||
** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
|
||||
**
|
||||
** <h3>Special sqlite_stat1 Handling</h3>
|
||||
**
|
||||
** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
|
||||
** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
|
||||
** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
|
||||
** <pre>
|
||||
** CREATE TABLE sqlite_stat1(tbl,idx,stat)
|
||||
** CREATE TABLE sqlite_stat1(tbl,idx,stat)
|
||||
** </pre>
|
||||
**
|
||||
** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
|
||||
** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
|
||||
** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
|
||||
** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
|
||||
** are recorded for rows for which (idx IS NULL) is true. However, for such
|
||||
** rows a zero-length blob (SQL value X'') is stored in the changeset or
|
||||
** patchset instead of a NULL value. This allows such changesets to be
|
||||
** manipulated by legacy implementations of sqlite3changeset_invert(),
|
||||
** concat() and similar.
|
||||
**
|
||||
** The sqlite3changeset_apply() function automatically converts the
|
||||
** The sqlite3changeset_apply() function automatically converts the
|
||||
** zero-length blob back to a NULL value when updating the sqlite_stat1
|
||||
** table. However, if the application calls sqlite3changeset_new(),
|
||||
** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
|
||||
** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
|
||||
** iterator directly (including on a changeset iterator passed to a
|
||||
** conflict-handler callback) then the X'' value is returned. The application
|
||||
** must translate X'' to NULL itself if required.
|
||||
|
@ -198,10 +198,10 @@ int sqlite3session_attach(
|
|||
** CAPI3REF: Set a table filter on a Session Object.
|
||||
** METHOD: sqlite3_session
|
||||
**
|
||||
** The second argument (xFilter) is the "filter callback". For changes to rows
|
||||
** The second argument (xFilter) is the "filter callback". For changes to rows
|
||||
** in tables that are not attached to the Session object, the filter is called
|
||||
** to determine whether changes to the table's rows should be tracked or not.
|
||||
** If xFilter returns 0, changes are not tracked. Note that once a table is
|
||||
** to determine whether changes to the table's rows should be tracked or not.
|
||||
** If xFilter returns 0, changes are not tracked. Note that once a table is
|
||||
** attached, xFilter will not be called again.
|
||||
*/
|
||||
void sqlite3session_table_filter(
|
||||
|
@ -217,9 +217,9 @@ void sqlite3session_table_filter(
|
|||
** CAPI3REF: Generate A Changeset From A Session Object
|
||||
** METHOD: sqlite3_session
|
||||
**
|
||||
** Obtain a changeset containing changes to the tables attached to the
|
||||
** session object passed as the first argument. If successful,
|
||||
** set *ppChangeset to point to a buffer containing the changeset
|
||||
** Obtain a changeset containing changes to the tables attached to the
|
||||
** session object passed as the first argument. If successful,
|
||||
** set *ppChangeset to point to a buffer containing the changeset
|
||||
** and *pnChangeset to the size of the changeset in bytes before returning
|
||||
** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
|
||||
** zero and return an SQLite error code.
|
||||
|
@ -234,7 +234,7 @@ void sqlite3session_table_filter(
|
|||
** modifies the values of primary key columns. If such a change is made, it
|
||||
** is represented in a changeset as a DELETE followed by an INSERT.
|
||||
**
|
||||
** Changes are not recorded for rows that have NULL values stored in one or
|
||||
** Changes are not recorded for rows that have NULL values stored in one or
|
||||
** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
|
||||
** no corresponding change is present in the changesets returned by this
|
||||
** function. If an existing row with one or more NULL values stored in
|
||||
|
@ -287,14 +287,14 @@ void sqlite3session_table_filter(
|
|||
** <ul>
|
||||
** <li> For each record generated by an insert, the database is queried
|
||||
** for a row with a matching primary key. If one is found, an INSERT
|
||||
** change is added to the changeset. If no such row is found, no change
|
||||
** change is added to the changeset. If no such row is found, no change
|
||||
** is added to the changeset.
|
||||
**
|
||||
** <li> For each record generated by an update or delete, the database is
|
||||
** <li> For each record generated by an update or delete, the database is
|
||||
** queried for a row with a matching primary key. If such a row is
|
||||
** found and one or more of the non-primary key fields have been
|
||||
** modified from their original values, an UPDATE change is added to
|
||||
** the changeset. Or, if no such row is found in the table, a DELETE
|
||||
** modified from their original values, an UPDATE change is added to
|
||||
** the changeset. Or, if no such row is found in the table, a DELETE
|
||||
** change is added to the changeset. If there is a row with a matching
|
||||
** primary key in the database, but all fields contain their original
|
||||
** values, no change is added to the changeset.
|
||||
|
@ -302,7 +302,7 @@ void sqlite3session_table_filter(
|
|||
**
|
||||
** This means, amongst other things, that if a row is inserted and then later
|
||||
** deleted while a session object is active, neither the insert nor the delete
|
||||
** will be present in the changeset. Or if a row is deleted and then later a
|
||||
** will be present in the changeset. Or if a row is deleted and then later a
|
||||
** row with the same primary key values inserted while a session object is
|
||||
** active, the resulting changeset will contain an UPDATE change instead of
|
||||
** a DELETE and an INSERT.
|
||||
|
@ -311,10 +311,10 @@ void sqlite3session_table_filter(
|
|||
** it does not accumulate records when rows are inserted, updated or deleted.
|
||||
** This may appear to have some counter-intuitive effects if a single row
|
||||
** is written to more than once during a session. For example, if a row
|
||||
** is inserted while a session object is enabled, then later deleted while
|
||||
** is inserted while a session object is enabled, then later deleted while
|
||||
** the same session object is disabled, no INSERT record will appear in the
|
||||
** changeset, even though the delete took place while the session was disabled.
|
||||
** Or, if one field of a row is updated while a session is disabled, and
|
||||
** Or, if one field of a row is updated while a session is disabled, and
|
||||
** another field of the same row is updated while the session is enabled, the
|
||||
** resulting changeset will contain an UPDATE change that updates both fields.
|
||||
*/
|
||||
|
@ -335,7 +335,7 @@ int sqlite3session_changeset(
|
|||
** an error).
|
||||
**
|
||||
** Argument zFromDb must be the name of a database ("main", "temp" etc.)
|
||||
** attached to the same database handle as the session object that contains
|
||||
** attached to the same database handle as the session object that contains
|
||||
** a table compatible with the table attached to the session by this function.
|
||||
** A table is considered compatible if it:
|
||||
**
|
||||
|
@ -351,25 +351,25 @@ int sqlite3session_changeset(
|
|||
** APIs, tables without PRIMARY KEYs are simply ignored.
|
||||
**
|
||||
** This function adds a set of changes to the session object that could be
|
||||
** used to update the table in database zFrom (call this the "from-table")
|
||||
** so that its content is the same as the table attached to the session
|
||||
** used to update the table in database zFrom (call this the "from-table")
|
||||
** so that its content is the same as the table attached to the session
|
||||
** object (call this the "to-table"). Specifically:
|
||||
**
|
||||
** <ul>
|
||||
** <li> For each row (primary key) that exists in the to-table but not in
|
||||
** <li> For each row (primary key) that exists in the to-table but not in
|
||||
** the from-table, an INSERT record is added to the session object.
|
||||
**
|
||||
** <li> For each row (primary key) that exists in the to-table but not in
|
||||
** <li> For each row (primary key) that exists in the to-table but not in
|
||||
** the from-table, a DELETE record is added to the session object.
|
||||
**
|
||||
** <li> For each row (primary key) that exists in both tables, but features
|
||||
** <li> For each row (primary key) that exists in both tables, but features
|
||||
** different non-PK values in each, an UPDATE record is added to the
|
||||
** session.
|
||||
** session.
|
||||
** </ul>
|
||||
**
|
||||
** To clarify, if this function is called and then a changeset constructed
|
||||
** using [sqlite3session_changeset()], then after applying that changeset to
|
||||
** database zFrom the contents of the two compatible tables would be
|
||||
** using [sqlite3session_changeset()], then after applying that changeset to
|
||||
** database zFrom the contents of the two compatible tables would be
|
||||
** identical.
|
||||
**
|
||||
** It an error if database zFrom does not exist or does not contain the
|
||||
|
@ -377,7 +377,7 @@ int sqlite3session_changeset(
|
|||
**
|
||||
** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
|
||||
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
|
||||
** may be set to point to a buffer containing an English language error
|
||||
** may be set to point to a buffer containing an English language error
|
||||
** message. It is the responsibility of the caller to free this buffer using
|
||||
** sqlite3_free().
|
||||
*/
|
||||
|
@ -396,19 +396,19 @@ int sqlite3session_diff(
|
|||
** The differences between a patchset and a changeset are that:
|
||||
**
|
||||
** <ul>
|
||||
** <li> DELETE records consist of the primary key fields only. The
|
||||
** <li> DELETE records consist of the primary key fields only. The
|
||||
** original values of other fields are omitted.
|
||||
** <li> The original values of any modified fields are omitted from
|
||||
** <li> The original values of any modified fields are omitted from
|
||||
** UPDATE records.
|
||||
** </ul>
|
||||
**
|
||||
** A patchset blob may be used with up to date versions of all
|
||||
** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
|
||||
** A patchset blob may be used with up to date versions of all
|
||||
** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
|
||||
** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
|
||||
** attempting to use a patchset blob with old versions of the
|
||||
** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
|
||||
** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
|
||||
**
|
||||
** Because the non-primary key "old.*" fields are omitted, no
|
||||
** Because the non-primary key "old.*" fields are omitted, no
|
||||
** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
|
||||
** is passed to the sqlite3changeset_apply() API. Other conflict types work
|
||||
** in the same way as for changesets.
|
||||
|
@ -427,16 +427,16 @@ int sqlite3session_patchset(
|
|||
/*
|
||||
** CAPI3REF: Test if a changeset has recorded any changes.
|
||||
**
|
||||
** Return non-zero if no changes to attached tables have been recorded by
|
||||
** the session object passed as the first argument. Otherwise, if one or
|
||||
** Return non-zero if no changes to attached tables have been recorded by
|
||||
** the session object passed as the first argument. Otherwise, if one or
|
||||
** more changes have been recorded, return zero.
|
||||
**
|
||||
** Even if this function returns zero, it is possible that calling
|
||||
** [sqlite3session_changeset()] on the session handle may still return a
|
||||
** changeset that contains no changes. This can happen when a row in
|
||||
** an attached table is modified and then later on the original values
|
||||
** changeset that contains no changes. This can happen when a row in
|
||||
** an attached table is modified and then later on the original values
|
||||
** are restored. However, if this function returns non-zero, then it is
|
||||
** guaranteed that a call to sqlite3session_changeset() will return a
|
||||
** guaranteed that a call to sqlite3session_changeset() will return a
|
||||
** changeset containing zero changes.
|
||||
*/
|
||||
int sqlite3session_isempty(sqlite3_session *pSession);
|
||||
|
@ -444,13 +444,13 @@ int sqlite3session_isempty(sqlite3_session *pSession);
|
|||
/*
|
||||
** CAPI3REF: Query for the amount of heap memory used by a session object.
|
||||
**
|
||||
** This API returns the total amount of heap memory in bytes currently
|
||||
** This API returns the total amount of heap memory in bytes currently
|
||||
** used by the session object passed as the only argument.
|
||||
*/
|
||||
sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Create An Iterator To Traverse A Changeset
|
||||
** CAPI3REF: Create An Iterator To Traverse A Changeset
|
||||
** CONSTRUCTOR: sqlite3_changeset_iter
|
||||
**
|
||||
** Create an iterator used to iterate through the contents of a changeset.
|
||||
|
@ -458,7 +458,7 @@ sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
|
|||
** is returned. Otherwise, if an error occurs, *pp is set to zero and an
|
||||
** SQLite error code is returned.
|
||||
**
|
||||
** The following functions can be used to advance and query a changeset
|
||||
** The following functions can be used to advance and query a changeset
|
||||
** iterator created by this function:
|
||||
**
|
||||
** <ul>
|
||||
|
@ -475,12 +475,12 @@ sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
|
|||
**
|
||||
** Assuming the changeset blob was created by one of the
|
||||
** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
|
||||
** [sqlite3changeset_invert()] functions, all changes within the changeset
|
||||
** that apply to a single table are grouped together. This means that when
|
||||
** an application iterates through a changeset using an iterator created by
|
||||
** this function, all changes that relate to a single table are visited
|
||||
** consecutively. There is no chance that the iterator will visit a change
|
||||
** the applies to table X, then one for table Y, and then later on visit
|
||||
** [sqlite3changeset_invert()] functions, all changes within the changeset
|
||||
** that apply to a single table are grouped together. This means that when
|
||||
** an application iterates through a changeset using an iterator created by
|
||||
** this function, all changes that relate to a single table are visited
|
||||
** consecutively. There is no chance that the iterator will visit a change
|
||||
** the applies to table X, then one for table Y, and then later on visit
|
||||
** another change for table X.
|
||||
**
|
||||
** The behavior of sqlite3changeset_start_v2() and its streaming equivalent
|
||||
|
@ -531,12 +531,12 @@ int sqlite3changeset_start_v2(
|
|||
** point to the first change in the changeset. Each subsequent call advances
|
||||
** the iterator to point to the next change in the changeset (if any). If
|
||||
** no error occurs and the iterator points to a valid change after a call
|
||||
** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
|
||||
** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
|
||||
** Otherwise, if all changes in the changeset have already been visited,
|
||||
** SQLITE_DONE is returned.
|
||||
**
|
||||
** If an error occurs, an SQLite error code is returned. Possible error
|
||||
** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
|
||||
** If an error occurs, an SQLite error code is returned. Possible error
|
||||
** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
|
||||
** SQLITE_NOMEM.
|
||||
*/
|
||||
int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
|
||||
|
@ -552,7 +552,7 @@ int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
|
|||
** is not the case, this function returns [SQLITE_MISUSE].
|
||||
**
|
||||
** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
|
||||
** outputs are set through these pointers:
|
||||
** outputs are set through these pointers:
|
||||
**
|
||||
** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
|
||||
** depending on the type of change that the iterator currently points to;
|
||||
|
@ -620,7 +620,7 @@ int sqlite3changeset_pk(
|
|||
** The pIter argument passed to this function may either be an iterator
|
||||
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
|
||||
** created by [sqlite3changeset_start()]. In the latter case, the most recent
|
||||
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
|
||||
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
|
||||
** Furthermore, it may only be called if the type of change that the iterator
|
||||
** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
|
||||
** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
|
||||
|
@ -630,9 +630,9 @@ int sqlite3changeset_pk(
|
|||
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
|
||||
**
|
||||
** If successful, this function sets *ppValue to point to a protected
|
||||
** sqlite3_value object containing the iVal'th value from the vector of
|
||||
** sqlite3_value object containing the iVal'th value from the vector of
|
||||
** original row values stored as part of the UPDATE or DELETE change and
|
||||
** returns SQLITE_OK. The name of the function comes from the fact that this
|
||||
** returns SQLITE_OK. The name of the function comes from the fact that this
|
||||
** is similar to the "old.*" columns available to update or delete triggers.
|
||||
**
|
||||
** If some other error occurs (e.g. an OOM condition), an SQLite error code
|
||||
|
@ -651,7 +651,7 @@ int sqlite3changeset_old(
|
|||
** The pIter argument passed to this function may either be an iterator
|
||||
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
|
||||
** created by [sqlite3changeset_start()]. In the latter case, the most recent
|
||||
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
|
||||
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
|
||||
** Furthermore, it may only be called if the type of change that the iterator
|
||||
** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
|
||||
** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
|
||||
|
@ -661,12 +661,12 @@ int sqlite3changeset_old(
|
|||
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
|
||||
**
|
||||
** If successful, this function sets *ppValue to point to a protected
|
||||
** sqlite3_value object containing the iVal'th value from the vector of
|
||||
** sqlite3_value object containing the iVal'th value from the vector of
|
||||
** new row values stored as part of the UPDATE or INSERT change and
|
||||
** returns SQLITE_OK. If the change is an UPDATE and does not include
|
||||
** a new value for the requested column, *ppValue is set to NULL and
|
||||
** SQLITE_OK returned. The name of the function comes from the fact that
|
||||
** this is similar to the "new.*" columns available to update or delete
|
||||
** a new value for the requested column, *ppValue is set to NULL and
|
||||
** SQLITE_OK returned. The name of the function comes from the fact that
|
||||
** this is similar to the "new.*" columns available to update or delete
|
||||
** triggers.
|
||||
**
|
||||
** If some other error occurs (e.g. an OOM condition), an SQLite error code
|
||||
|
@ -693,7 +693,7 @@ int sqlite3changeset_new(
|
|||
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
|
||||
**
|
||||
** If successful, this function sets *ppValue to point to a protected
|
||||
** sqlite3_value object containing the iVal'th value from the
|
||||
** sqlite3_value object containing the iVal'th value from the
|
||||
** "conflicting row" associated with the current conflict-handler callback
|
||||
** and returns SQLITE_OK.
|
||||
**
|
||||
|
@ -737,7 +737,7 @@ int sqlite3changeset_fk_conflicts(
|
|||
** call has no effect.
|
||||
**
|
||||
** If an error was encountered within a call to an sqlite3changeset_xxx()
|
||||
** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
|
||||
** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
|
||||
** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
|
||||
** to that error is returned by this function. Otherwise, SQLITE_OK is
|
||||
** returned. This is to allow the following pattern (pseudo-code):
|
||||
|
@ -749,7 +749,7 @@ int sqlite3changeset_fk_conflicts(
|
|||
** }
|
||||
** rc = sqlite3changeset_finalize();
|
||||
** if( rc!=SQLITE_OK ){
|
||||
** // An error has occurred
|
||||
** // An error has occurred
|
||||
** }
|
||||
** </pre>
|
||||
*/
|
||||
|
@ -777,7 +777,7 @@ int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
|
|||
** zeroed and an SQLite error code returned.
|
||||
**
|
||||
** It is the responsibility of the caller to eventually call sqlite3_free()
|
||||
** on the *ppOut pointer to free the buffer allocation following a successful
|
||||
** on the *ppOut pointer to free the buffer allocation following a successful
|
||||
** call to this function.
|
||||
**
|
||||
** WARNING/TODO: This function currently assumes that the input is a valid
|
||||
|
@ -791,11 +791,11 @@ int sqlite3changeset_invert(
|
|||
/*
|
||||
** CAPI3REF: Concatenate Two Changeset Objects
|
||||
**
|
||||
** This function is used to concatenate two changesets, A and B, into a
|
||||
** This function is used to concatenate two changesets, A and B, into a
|
||||
** single changeset. The result is a changeset equivalent to applying
|
||||
** changeset A followed by changeset B.
|
||||
** changeset A followed by changeset B.
|
||||
**
|
||||
** This function combines the two input changesets using an
|
||||
** This function combines the two input changesets using an
|
||||
** sqlite3_changegroup object. Calling it produces similar results as the
|
||||
** following code fragment:
|
||||
**
|
||||
|
@ -827,7 +827,7 @@ int sqlite3changeset_concat(
|
|||
/*
|
||||
** CAPI3REF: Changegroup Handle
|
||||
**
|
||||
** A changegroup is an object used to combine two or more
|
||||
** A changegroup is an object used to combine two or more
|
||||
** [changesets] or [patchsets]
|
||||
*/
|
||||
typedef struct sqlite3_changegroup sqlite3_changegroup;
|
||||
|
@ -843,7 +843,7 @@ typedef struct sqlite3_changegroup sqlite3_changegroup;
|
|||
**
|
||||
** If successful, this function returns SQLITE_OK and populates (*pp) with
|
||||
** a pointer to a new sqlite3_changegroup object before returning. The caller
|
||||
** should eventually free the returned object using a call to
|
||||
** should eventually free the returned object using a call to
|
||||
** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
|
||||
** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
|
||||
**
|
||||
|
@ -855,7 +855,7 @@ typedef struct sqlite3_changegroup sqlite3_changegroup;
|
|||
** <li> Zero or more changesets (or patchsets) are added to the object
|
||||
** by calling sqlite3changegroup_add().
|
||||
**
|
||||
** <li> The result of combining all input changesets together is obtained
|
||||
** <li> The result of combining all input changesets together is obtained
|
||||
** by the application via a call to sqlite3changegroup_output().
|
||||
**
|
||||
** <li> The object is deleted using a call to sqlite3changegroup_delete().
|
||||
|
@ -864,7 +864,7 @@ typedef struct sqlite3_changegroup sqlite3_changegroup;
|
|||
** Any number of calls to add() and output() may be made between the calls to
|
||||
** new() and delete(), and in any order.
|
||||
**
|
||||
** As well as the regular sqlite3changegroup_add() and
|
||||
** As well as the regular sqlite3changegroup_add() and
|
||||
** sqlite3changegroup_output() functions, also available are the streaming
|
||||
** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
|
||||
*/
|
||||
|
@ -875,7 +875,7 @@ int sqlite3changegroup_new(sqlite3_changegroup **pp);
|
|||
** METHOD: sqlite3_changegroup
|
||||
**
|
||||
** Add all changes within the changeset (or patchset) in buffer pData (size
|
||||
** nData bytes) to the changegroup.
|
||||
** nData bytes) to the changegroup.
|
||||
**
|
||||
** If the buffer contains a patchset, then all prior calls to this function
|
||||
** on the same changegroup object must also have specified patchsets. Or, if
|
||||
|
@ -902,7 +902,7 @@ int sqlite3changegroup_new(sqlite3_changegroup **pp);
|
|||
** changeset was recorded immediately after the changesets already
|
||||
** added to the changegroup.
|
||||
** <tr><td>INSERT <td>UPDATE <td>
|
||||
** The INSERT change remains in the changegroup. The values in the
|
||||
** The INSERT change remains in the changegroup. The values in the
|
||||
** INSERT change are modified as if the row was inserted by the
|
||||
** existing change and then updated according to the new change.
|
||||
** <tr><td>INSERT <td>DELETE <td>
|
||||
|
@ -913,17 +913,17 @@ int sqlite3changegroup_new(sqlite3_changegroup **pp);
|
|||
** changeset was recorded immediately after the changesets already
|
||||
** added to the changegroup.
|
||||
** <tr><td>UPDATE <td>UPDATE <td>
|
||||
** The existing UPDATE remains within the changegroup. It is amended
|
||||
** so that the accompanying values are as if the row was updated once
|
||||
** The existing UPDATE remains within the changegroup. It is amended
|
||||
** so that the accompanying values are as if the row was updated once
|
||||
** by the existing change and then again by the new change.
|
||||
** <tr><td>UPDATE <td>DELETE <td>
|
||||
** The existing UPDATE is replaced by the new DELETE within the
|
||||
** changegroup.
|
||||
** <tr><td>DELETE <td>INSERT <td>
|
||||
** If one or more of the column values in the row inserted by the
|
||||
** new change differ from those in the row deleted by the existing
|
||||
** new change differ from those in the row deleted by the existing
|
||||
** change, the existing DELETE is replaced by an UPDATE within the
|
||||
** changegroup. Otherwise, if the inserted row is exactly the same
|
||||
** changegroup. Otherwise, if the inserted row is exactly the same
|
||||
** as the deleted row, the existing DELETE is simply discarded.
|
||||
** <tr><td>DELETE <td>UPDATE <td>
|
||||
** The new change is ignored. This case does not occur if the new
|
||||
|
@ -968,7 +968,7 @@ int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
|
|||
**
|
||||
** If an error occurs, an SQLite error code is returned and the output
|
||||
** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
|
||||
** is returned and the output variables are set to the size of and a
|
||||
** is returned and the output variables are set to the size of and a
|
||||
** pointer to the output buffer, respectively. In this case it is the
|
||||
** responsibility of the caller to eventually free the buffer using a
|
||||
** call to sqlite3_free().
|
||||
|
@ -990,7 +990,7 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
|
|||
**
|
||||
** Apply a changeset or patchset to a database. These functions attempt to
|
||||
** update the "main" database attached to handle db with the changes found in
|
||||
** the changeset passed via the second and third arguments.
|
||||
** the changeset passed via the second and third arguments.
|
||||
**
|
||||
** The fourth argument (xFilter) passed to these functions is the "filter
|
||||
** callback". If it is not NULL, then for each table affected by at least one
|
||||
|
@ -1001,16 +1001,16 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
|
|||
** Otherwise, if the return value is non-zero or the xFilter argument to
|
||||
** is NULL, all changes related to the table are attempted.
|
||||
**
|
||||
** For each table that is not excluded by the filter callback, this function
|
||||
** tests that the target database contains a compatible table. A table is
|
||||
** For each table that is not excluded by the filter callback, this function
|
||||
** tests that the target database contains a compatible table. A table is
|
||||
** considered compatible if all of the following are true:
|
||||
**
|
||||
** <ul>
|
||||
** <li> The table has the same name as the name recorded in the
|
||||
** <li> The table has the same name as the name recorded in the
|
||||
** changeset, and
|
||||
** <li> The table has at least as many columns as recorded in the
|
||||
** <li> The table has at least as many columns as recorded in the
|
||||
** changeset, and
|
||||
** <li> The table has primary key columns in the same position as
|
||||
** <li> The table has primary key columns in the same position as
|
||||
** recorded in the changeset.
|
||||
** </ul>
|
||||
**
|
||||
|
@ -1019,11 +1019,11 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
|
|||
** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
|
||||
** one such warning is issued for each table in the changeset.
|
||||
**
|
||||
** For each change for which there is a compatible table, an attempt is made
|
||||
** to modify the table contents according to the UPDATE, INSERT or DELETE
|
||||
** change. If a change cannot be applied cleanly, the conflict handler
|
||||
** function passed as the fifth argument to sqlite3changeset_apply() may be
|
||||
** invoked. A description of exactly when the conflict handler is invoked for
|
||||
** For each change for which there is a compatible table, an attempt is made
|
||||
** to modify the table contents according to the UPDATE, INSERT or DELETE
|
||||
** change. If a change cannot be applied cleanly, the conflict handler
|
||||
** function passed as the fifth argument to sqlite3changeset_apply() may be
|
||||
** invoked. A description of exactly when the conflict handler is invoked for
|
||||
** each type of change is below.
|
||||
**
|
||||
** Unlike the xFilter argument, xConflict may not be passed NULL. The results
|
||||
|
@ -1031,23 +1031,23 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
|
|||
** argument are undefined.
|
||||
**
|
||||
** Each time the conflict handler function is invoked, it must return one
|
||||
** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
|
||||
** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
|
||||
** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
|
||||
** if the second argument passed to the conflict handler is either
|
||||
** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
|
||||
** returns an illegal value, any changes already made are rolled back and
|
||||
** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
|
||||
** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
|
||||
** actions are taken by sqlite3changeset_apply() depending on the value
|
||||
** returned by each invocation of the conflict-handler function. Refer to
|
||||
** the documentation for the three
|
||||
** the documentation for the three
|
||||
** [SQLITE_CHANGESET_OMIT|available return values] for details.
|
||||
**
|
||||
** <dl>
|
||||
** <dt>DELETE Changes<dd>
|
||||
** For each DELETE change, the function checks if the target database
|
||||
** contains a row with the same primary key value (or values) as the
|
||||
** original row values stored in the changeset. If it does, and the values
|
||||
** stored in all non-primary key columns also match the values stored in
|
||||
** For each DELETE change, the function checks if the target database
|
||||
** contains a row with the same primary key value (or values) as the
|
||||
** original row values stored in the changeset. If it does, and the values
|
||||
** stored in all non-primary key columns also match the values stored in
|
||||
** the changeset the row is deleted from the target database.
|
||||
**
|
||||
** If a row with matching primary key values is found, but one or more of
|
||||
|
@ -1076,22 +1076,22 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
|
|||
** database table, the trailing fields are populated with their default
|
||||
** values.
|
||||
**
|
||||
** If the attempt to insert the row fails because the database already
|
||||
** If the attempt to insert the row fails because the database already
|
||||
** contains a row with the same primary key values, the conflict handler
|
||||
** function is invoked with the second argument set to
|
||||
** function is invoked with the second argument set to
|
||||
** [SQLITE_CHANGESET_CONFLICT].
|
||||
**
|
||||
** If the attempt to insert the row fails because of some other constraint
|
||||
** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
|
||||
** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
|
||||
** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
|
||||
** This includes the case where the INSERT operation is re-attempted because
|
||||
** an earlier call to the conflict handler function returned
|
||||
** This includes the case where the INSERT operation is re-attempted because
|
||||
** an earlier call to the conflict handler function returned
|
||||
** [SQLITE_CHANGESET_REPLACE].
|
||||
**
|
||||
** <dt>UPDATE Changes<dd>
|
||||
** For each UPDATE change, the function checks if the target database
|
||||
** contains a row with the same primary key value (or values) as the
|
||||
** original row values stored in the changeset. If it does, and the values
|
||||
** For each UPDATE change, the function checks if the target database
|
||||
** contains a row with the same primary key value (or values) as the
|
||||
** original row values stored in the changeset. If it does, and the values
|
||||
** stored in all modified non-primary key columns also match the values
|
||||
** stored in the changeset the row is updated within the target database.
|
||||
**
|
||||
|
@ -1107,12 +1107,12 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
|
|||
** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
|
||||
** passed as the second argument.
|
||||
**
|
||||
** If the UPDATE operation is attempted, but SQLite returns
|
||||
** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
|
||||
** If the UPDATE operation is attempted, but SQLite returns
|
||||
** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
|
||||
** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
|
||||
** This includes the case where the UPDATE operation is attempted after
|
||||
** This includes the case where the UPDATE operation is attempted after
|
||||
** an earlier call to the conflict handler function returned
|
||||
** [SQLITE_CHANGESET_REPLACE].
|
||||
** [SQLITE_CHANGESET_REPLACE].
|
||||
** </dl>
|
||||
**
|
||||
** It is safe to execute SQL statements, including those that write to the
|
||||
|
@ -1123,12 +1123,12 @@ void sqlite3changegroup_delete(sqlite3_changegroup*);
|
|||
** All changes made by these functions are enclosed in a savepoint transaction.
|
||||
** If any other error (aside from a constraint failure when attempting to
|
||||
** write to the target database) occurs, then the savepoint transaction is
|
||||
** rolled back, restoring the target database to its original state, and an
|
||||
** rolled back, restoring the target database to its original state, and an
|
||||
** SQLite error code returned.
|
||||
**
|
||||
** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
|
||||
** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
|
||||
** may set (*ppRebase) to point to a "rebase" that may be used with the
|
||||
** may set (*ppRebase) to point to a "rebase" that may be used with the
|
||||
** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
|
||||
** is set to the size of the buffer in bytes. It is the responsibility of the
|
||||
** caller to eventually free any such buffer using sqlite3_free(). The buffer
|
||||
|
@ -1189,7 +1189,7 @@ int sqlite3changeset_apply_v2(
|
|||
** SAVEPOINT is committed if the changeset or patchset is successfully
|
||||
** applied, or rolled back if an error occurs. Specifying this flag
|
||||
** causes the sessions module to omit this savepoint. In this case, if the
|
||||
** caller has an open transaction or savepoint when apply_v2() is called,
|
||||
** caller has an open transaction or savepoint when apply_v2() is called,
|
||||
** it may revert the partially applied changeset by rolling it back.
|
||||
**
|
||||
** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
|
||||
|
@ -1200,7 +1200,7 @@ int sqlite3changeset_apply_v2(
|
|||
#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
|
||||
#define SQLITE_CHANGESETAPPLY_INVERT 0x0002
|
||||
|
||||
/*
|
||||
/*
|
||||
** CAPI3REF: Constants Passed To The Conflict Handler
|
||||
**
|
||||
** Values that may be passed as the second argument to a conflict-handler.
|
||||
|
@ -1209,32 +1209,32 @@ int sqlite3changeset_apply_v2(
|
|||
** <dt>SQLITE_CHANGESET_DATA<dd>
|
||||
** The conflict handler is invoked with CHANGESET_DATA as the second argument
|
||||
** when processing a DELETE or UPDATE change if a row with the required
|
||||
** PRIMARY KEY fields is present in the database, but one or more other
|
||||
** (non primary-key) fields modified by the update do not contain the
|
||||
** PRIMARY KEY fields is present in the database, but one or more other
|
||||
** (non primary-key) fields modified by the update do not contain the
|
||||
** expected "before" values.
|
||||
**
|
||||
**
|
||||
** The conflicting row, in this case, is the database row with the matching
|
||||
** primary key.
|
||||
**
|
||||
**
|
||||
** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
|
||||
** The conflict handler is invoked with CHANGESET_NOTFOUND as the second
|
||||
** argument when processing a DELETE or UPDATE change if a row with the
|
||||
** required PRIMARY KEY fields is not present in the database.
|
||||
**
|
||||
**
|
||||
** There is no conflicting row in this case. The results of invoking the
|
||||
** sqlite3changeset_conflict() API are undefined.
|
||||
**
|
||||
**
|
||||
** <dt>SQLITE_CHANGESET_CONFLICT<dd>
|
||||
** CHANGESET_CONFLICT is passed as the second argument to the conflict
|
||||
** handler while processing an INSERT change if the operation would result
|
||||
** handler while processing an INSERT change if the operation would result
|
||||
** in duplicate primary key values.
|
||||
**
|
||||
**
|
||||
** The conflicting row in this case is the database row with the matching
|
||||
** primary key.
|
||||
**
|
||||
** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
|
||||
** If foreign key handling is enabled, and applying a changeset leaves the
|
||||
** database in a state containing foreign key violations, the conflict
|
||||
** database in a state containing foreign key violations, the conflict
|
||||
** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
|
||||
** exactly once before the changeset is committed. If the conflict handler
|
||||
** returns CHANGESET_OMIT, the changes, including those that caused the
|
||||
|
@ -1244,12 +1244,12 @@ int sqlite3changeset_apply_v2(
|
|||
** No current or conflicting row information is provided. The only function
|
||||
** it is possible to call on the supplied sqlite3_changeset_iter handle
|
||||
** is sqlite3changeset_fk_conflicts().
|
||||
**
|
||||
**
|
||||
** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
|
||||
** If any other constraint violation occurs while applying a change (i.e.
|
||||
** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
|
||||
** If any other constraint violation occurs while applying a change (i.e.
|
||||
** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
|
||||
** invoked with CHANGESET_CONSTRAINT as the second argument.
|
||||
**
|
||||
**
|
||||
** There is no conflicting row in this case. The results of invoking the
|
||||
** sqlite3changeset_conflict() API are undefined.
|
||||
**
|
||||
|
@ -1261,7 +1261,7 @@ int sqlite3changeset_apply_v2(
|
|||
#define SQLITE_CHANGESET_CONSTRAINT 4
|
||||
#define SQLITE_CHANGESET_FOREIGN_KEY 5
|
||||
|
||||
/*
|
||||
/*
|
||||
** CAPI3REF: Constants Returned By The Conflict Handler
|
||||
**
|
||||
** A conflict handler callback must return one of the following three values.
|
||||
|
@ -1269,13 +1269,13 @@ int sqlite3changeset_apply_v2(
|
|||
** <dl>
|
||||
** <dt>SQLITE_CHANGESET_OMIT<dd>
|
||||
** If a conflict handler returns this value no special action is taken. The
|
||||
** change that caused the conflict is not applied. The session module
|
||||
** change that caused the conflict is not applied. The session module
|
||||
** continues to the next change in the changeset.
|
||||
**
|
||||
** <dt>SQLITE_CHANGESET_REPLACE<dd>
|
||||
** This value may only be returned if the second argument to the conflict
|
||||
** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
|
||||
** is not the case, any changes applied so far are rolled back and the
|
||||
** is not the case, any changes applied so far are rolled back and the
|
||||
** call to sqlite3changeset_apply() returns SQLITE_MISUSE.
|
||||
**
|
||||
** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
|
||||
|
@ -1288,7 +1288,7 @@ int sqlite3changeset_apply_v2(
|
|||
** the original row is restored to the database before continuing.
|
||||
**
|
||||
** <dt>SQLITE_CHANGESET_ABORT<dd>
|
||||
** If this value is returned, any changes applied so far are rolled back
|
||||
** If this value is returned, any changes applied so far are rolled back
|
||||
** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
|
||||
** </dl>
|
||||
*/
|
||||
|
@ -1296,20 +1296,20 @@ int sqlite3changeset_apply_v2(
|
|||
#define SQLITE_CHANGESET_REPLACE 1
|
||||
#define SQLITE_CHANGESET_ABORT 2
|
||||
|
||||
/*
|
||||
/*
|
||||
** CAPI3REF: Rebasing changesets
|
||||
** EXPERIMENTAL
|
||||
**
|
||||
** Suppose there is a site hosting a database in state S0. And that
|
||||
** modifications are made that move that database to state S1 and a
|
||||
** changeset recorded (the "local" changeset). Then, a changeset based
|
||||
** on S0 is received from another site (the "remote" changeset) and
|
||||
** applied to the database. The database is then in state
|
||||
** on S0 is received from another site (the "remote" changeset) and
|
||||
** applied to the database. The database is then in state
|
||||
** (S1+"remote"), where the exact state depends on any conflict
|
||||
** resolution decisions (OMIT or REPLACE) made while applying "remote".
|
||||
** Rebasing a changeset is to update it to take those conflict
|
||||
** Rebasing a changeset is to update it to take those conflict
|
||||
** resolution decisions into account, so that the same conflicts
|
||||
** do not have to be resolved elsewhere in the network.
|
||||
** do not have to be resolved elsewhere in the network.
|
||||
**
|
||||
** For example, if both the local and remote changesets contain an
|
||||
** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
|
||||
|
@ -1328,7 +1328,7 @@ int sqlite3changeset_apply_v2(
|
|||
**
|
||||
** <dl>
|
||||
** <dt>Local INSERT<dd>
|
||||
** This may only conflict with a remote INSERT. If the conflict
|
||||
** This may only conflict with a remote INSERT. If the conflict
|
||||
** resolution was OMIT, then add an UPDATE change to the rebased
|
||||
** changeset. Or, if the conflict resolution was REPLACE, add
|
||||
** nothing to the rebased changeset.
|
||||
|
@ -1352,12 +1352,12 @@ int sqlite3changeset_apply_v2(
|
|||
** the old.* values are rebased using the new.* values in the remote
|
||||
** change. Or, if the resolution is REPLACE, then the change is copied
|
||||
** into the rebased changeset with updates to columns also updated by
|
||||
** the conflicting remote UPDATE removed. If this means no columns would
|
||||
** the conflicting remote UPDATE removed. If this means no columns would
|
||||
** be updated, the change is omitted.
|
||||
** </dl>
|
||||
**
|
||||
** A local change may be rebased against multiple remote changes
|
||||
** simultaneously. If a single key is modified by multiple remote
|
||||
** A local change may be rebased against multiple remote changes
|
||||
** simultaneously. If a single key is modified by multiple remote
|
||||
** changesets, they are combined as follows before the local changeset
|
||||
** is rebased:
|
||||
**
|
||||
|
@ -1370,10 +1370,10 @@ int sqlite3changeset_apply_v2(
|
|||
** of the OMIT resolutions.
|
||||
** </ul>
|
||||
**
|
||||
** Note that conflict resolutions from multiple remote changesets are
|
||||
** combined on a per-field basis, not per-row. This means that in the
|
||||
** case of multiple remote UPDATE operations, some fields of a single
|
||||
** local change may be rebased for REPLACE while others are rebased for
|
||||
** Note that conflict resolutions from multiple remote changesets are
|
||||
** combined on a per-field basis, not per-row. This means that in the
|
||||
** case of multiple remote UPDATE operations, some fields of a single
|
||||
** local change may be rebased for REPLACE while others are rebased for
|
||||
** OMIT.
|
||||
**
|
||||
** In order to rebase a local changeset, the remote changeset must first
|
||||
|
@ -1381,7 +1381,7 @@ int sqlite3changeset_apply_v2(
|
|||
** the buffer of rebase information captured. Then:
|
||||
**
|
||||
** <ol>
|
||||
** <li> An sqlite3_rebaser object is created by calling
|
||||
** <li> An sqlite3_rebaser object is created by calling
|
||||
** sqlite3rebaser_create().
|
||||
** <li> The new object is configured with the rebase buffer obtained from
|
||||
** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
|
||||
|
@ -1402,8 +1402,8 @@ typedef struct sqlite3_rebaser sqlite3_rebaser;
|
|||
**
|
||||
** Allocate a new changeset rebaser object. If successful, set (*ppNew) to
|
||||
** point to the new object and return SQLITE_OK. Otherwise, if an error
|
||||
** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)
|
||||
** to NULL.
|
||||
** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)
|
||||
** to NULL.
|
||||
*/
|
||||
int sqlite3rebaser_create(sqlite3_rebaser **ppNew);
|
||||
|
||||
|
@ -1417,9 +1417,9 @@ int sqlite3rebaser_create(sqlite3_rebaser **ppNew);
|
|||
** sqlite3changeset_apply_v2().
|
||||
*/
|
||||
int sqlite3rebaser_configure(
|
||||
sqlite3_rebaser*,
|
||||
sqlite3_rebaser*,
|
||||
int nRebase, const void *pRebase
|
||||
);
|
||||
);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Rebase a changeset
|
||||
|
@ -1429,7 +1429,7 @@ int sqlite3rebaser_configure(
|
|||
** in size. This function allocates and populates a buffer with a copy
|
||||
** of the changeset rebased according to the configuration of the
|
||||
** rebaser object passed as the first argument. If successful, (*ppOut)
|
||||
** is set to point to the new buffer containing the rebased changeset and
|
||||
** is set to point to the new buffer containing the rebased changeset and
|
||||
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
|
||||
** responsibility of the caller to eventually free the new buffer using
|
||||
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
|
||||
|
@ -1437,8 +1437,8 @@ int sqlite3rebaser_configure(
|
|||
*/
|
||||
int sqlite3rebaser_rebase(
|
||||
sqlite3_rebaser*,
|
||||
int nIn, const void *pIn,
|
||||
int *pnOut, void **ppOut
|
||||
int nIn, const void *pIn,
|
||||
int *pnOut, void **ppOut
|
||||
);
|
||||
|
||||
/*
|
||||
|
@ -1449,30 +1449,30 @@ int sqlite3rebaser_rebase(
|
|||
** should be one call to this function for each successful invocation
|
||||
** of sqlite3rebaser_create().
|
||||
*/
|
||||
void sqlite3rebaser_delete(sqlite3_rebaser *p);
|
||||
void sqlite3rebaser_delete(sqlite3_rebaser *p);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Streaming Versions of API functions.
|
||||
**
|
||||
** The six streaming API xxx_strm() functions serve similar purposes to the
|
||||
** The six streaming API xxx_strm() functions serve similar purposes to the
|
||||
** corresponding non-streaming API functions:
|
||||
**
|
||||
** <table border=1 style="margin-left:8ex;margin-right:8ex">
|
||||
** <tr><th>Streaming function<th>Non-streaming equivalent</th>
|
||||
** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
|
||||
** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]
|
||||
** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
|
||||
** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
|
||||
** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
|
||||
** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
|
||||
** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
|
||||
** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
|
||||
** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]
|
||||
** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
|
||||
** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
|
||||
** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
|
||||
** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
|
||||
** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
|
||||
** </table>
|
||||
**
|
||||
** Non-streaming functions that accept changesets (or patchsets) as input
|
||||
** require that the entire changeset be stored in a single buffer in memory.
|
||||
** Similarly, those that return a changeset or patchset do so by returning
|
||||
** a pointer to a single large buffer allocated using sqlite3_malloc().
|
||||
** Normally this is convenient. However, if an application running in a
|
||||
** require that the entire changeset be stored in a single buffer in memory.
|
||||
** Similarly, those that return a changeset or patchset do so by returning
|
||||
** a pointer to a single large buffer allocated using sqlite3_malloc().
|
||||
** Normally this is convenient. However, if an application running in a
|
||||
** low-memory environment is required to handle very large changesets, the
|
||||
** large contiguous memory allocations required can become onerous.
|
||||
**
|
||||
|
@ -1494,12 +1494,12 @@ void sqlite3rebaser_delete(sqlite3_rebaser *p);
|
|||
** </pre>
|
||||
**
|
||||
** Each time the xInput callback is invoked by the sessions module, the first
|
||||
** argument passed is a copy of the supplied pIn context pointer. The second
|
||||
** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
|
||||
** error occurs the xInput method should copy up to (*pnData) bytes of data
|
||||
** into the buffer and set (*pnData) to the actual number of bytes copied
|
||||
** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
|
||||
** should be set to zero to indicate this. Or, if an error occurs, an SQLite
|
||||
** argument passed is a copy of the supplied pIn context pointer. The second
|
||||
** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
|
||||
** error occurs the xInput method should copy up to (*pnData) bytes of data
|
||||
** into the buffer and set (*pnData) to the actual number of bytes copied
|
||||
** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
|
||||
** should be set to zero to indicate this. Or, if an error occurs, an SQLite
|
||||
** error code should be returned. In all cases, if an xInput callback returns
|
||||
** an error, all processing is abandoned and the streaming API function
|
||||
** returns a copy of the error code to the caller.
|
||||
|
@ -1507,7 +1507,7 @@ void sqlite3rebaser_delete(sqlite3_rebaser *p);
|
|||
** In the case of sqlite3changeset_start_strm(), the xInput callback may be
|
||||
** invoked by the sessions module at any point during the lifetime of the
|
||||
** iterator. If such an xInput callback returns an error, the iterator enters
|
||||
** an error state, whereby all subsequent calls to iterator functions
|
||||
** an error state, whereby all subsequent calls to iterator functions
|
||||
** immediately fail with the same error code as returned by xInput.
|
||||
**
|
||||
** Similarly, streaming API functions that return changesets (or patchsets)
|
||||
|
@ -1537,7 +1537,7 @@ void sqlite3rebaser_delete(sqlite3_rebaser *p);
|
|||
** is immediately abandoned and the streaming API function returns a copy
|
||||
** of the xOutput error code to the application.
|
||||
**
|
||||
** The sessions module never invokes an xOutput callback with the third
|
||||
** The sessions module never invokes an xOutput callback with the third
|
||||
** parameter set to a value less than or equal to zero. Other than this,
|
||||
** no guarantees are made as to the size of the chunks of data returned.
|
||||
*/
|
||||
|
@ -1608,12 +1608,12 @@ int sqlite3session_patchset_strm(
|
|||
int (*xOutput)(void *pOut, const void *pData, int nData),
|
||||
void *pOut
|
||||
);
|
||||
int sqlite3changegroup_add_strm(sqlite3_changegroup*,
|
||||
int sqlite3changegroup_add_strm(sqlite3_changegroup*,
|
||||
int (*xInput)(void *pIn, void *pData, int *pnData),
|
||||
void *pIn
|
||||
);
|
||||
int sqlite3changegroup_output_strm(sqlite3_changegroup*,
|
||||
int (*xOutput)(void *pOut, const void *pData, int nData),
|
||||
int (*xOutput)(void *pOut, const void *pData, int nData),
|
||||
void *pOut
|
||||
);
|
||||
int sqlite3rebaser_rebase_strm(
|
||||
|
@ -1628,16 +1628,16 @@ int sqlite3rebaser_rebase_strm(
|
|||
** CAPI3REF: Configure global parameters
|
||||
**
|
||||
** The sqlite3session_config() interface is used to make global configuration
|
||||
** changes to the sessions module in order to tune it to the specific needs
|
||||
** changes to the sessions module in order to tune it to the specific needs
|
||||
** of the application.
|
||||
**
|
||||
** The sqlite3session_config() interface is not threadsafe. If it is invoked
|
||||
** while any other thread is inside any other sessions method then the
|
||||
** results are undefined. Furthermore, if it is invoked after any sessions
|
||||
** related objects have been created, the results are also undefined.
|
||||
** related objects have been created, the results are also undefined.
|
||||
**
|
||||
** The first argument to the sqlite3session_config() function must be one
|
||||
** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The
|
||||
** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The
|
||||
** interpretation of the (void*) value passed as the second parameter and
|
||||
** the effect of calling this function depends on the value of the first
|
||||
** parameter.
|
||||
|
|
2
third_party/sqlite3/sqlite3userauth.inc
vendored
2
third_party/sqlite3/sqlite3userauth.inc
vendored
|
@ -67,7 +67,7 @@ int sqlite3_user_add(
|
|||
** The sqlite3_user_change() interface can be used to change a users
|
||||
** login credentials or admin privilege. Any user can change their own
|
||||
** login credentials. Only an admin user can change another users login
|
||||
** credentials or admin privilege setting. No user may change their own
|
||||
** credentials or admin privilege setting. No user may change their own
|
||||
** admin privilege setting.
|
||||
*/
|
||||
int sqlite3_user_change(
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue