mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
updated to sqlite 3.3.4 sources
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that used to generate VDBE code
|
||||
** that implements the ALTER TABLE command.
|
||||
**
|
||||
** $Id: alter.c,v 1.3 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: alter.c,v 1.4 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -47,7 +47,7 @@ static void renameTableFunc(
|
||||
|
||||
int token;
|
||||
Token tname;
|
||||
char const *zCsr = zSql;
|
||||
unsigned char const *zCsr = zSql;
|
||||
int len = 0;
|
||||
char *zRet;
|
||||
|
||||
@@ -96,7 +96,7 @@ static void renameTriggerFunc(
|
||||
int token;
|
||||
Token tname;
|
||||
int dist = 3;
|
||||
char const *zCsr = zSql;
|
||||
unsigned char const *zCsr = zSql;
|
||||
int len = 0;
|
||||
char *zRet;
|
||||
|
||||
@@ -162,7 +162,7 @@ void sqlite3AlterFunctions(sqlite3 *db){
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
sqlite3CreateFunc(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -177,9 +177,16 @@ static char *whereTempTriggers(Parse *pParse, Table *pTab){
|
||||
Trigger *pTrig;
|
||||
char *zWhere = 0;
|
||||
char *tmp = 0;
|
||||
if( pTab->iDb!=1 ){
|
||||
const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
|
||||
|
||||
/* If the table is not located in the temp-db (in which case NULL is
|
||||
** returned, loop through the tables list of triggers. For each trigger
|
||||
** that is not part of the temp-db schema, add a clause to the WHERE
|
||||
** expression being built up in zWhere.
|
||||
*/
|
||||
if( pTab->pSchema!=pTempSchema ){
|
||||
for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
|
||||
if( pTrig->iDb==1 ){
|
||||
if( pTrig->pSchema==pTempSchema ){
|
||||
if( !zWhere ){
|
||||
zWhere = sqlite3MPrintf("name=%Q", pTrig->name);
|
||||
}else{
|
||||
@@ -204,20 +211,22 @@ static char *whereTempTriggers(Parse *pParse, Table *pTab){
|
||||
static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
|
||||
Vdbe *v;
|
||||
char *zWhere;
|
||||
int iDb;
|
||||
int iDb; /* Index of database containing pTab */
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
Trigger *pTrig;
|
||||
#endif
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
iDb = pTab->iDb;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
assert( iDb>=0 );
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* Drop any table triggers from the internal schema. */
|
||||
for(pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext){
|
||||
assert( pTrig->iDb==iDb || pTrig->iDb==1 );
|
||||
sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
|
||||
int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
|
||||
assert( iTrigDb==iDb || iTrigDb==1 );
|
||||
sqlite3VdbeOp3(v, OP_DropTrigger, iTrigDb, 0, pTrig->name, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -233,7 +242,7 @@ static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
|
||||
/* Now, if the table is not stored in the temp database, reload any temp
|
||||
** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
|
||||
*/
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zWhere, P3_DYNAMIC);
|
||||
}
|
||||
#endif
|
||||
@@ -258,11 +267,12 @@ void sqlite3AlterRenameTable(
|
||||
char *zWhere = 0; /* Where clause to locate temp triggers */
|
||||
#endif
|
||||
|
||||
if( sqlite3MallocFailed() ) goto exit_rename_table;
|
||||
assert( pSrc->nSrc==1 );
|
||||
|
||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||
if( !pTab ) goto exit_rename_table;
|
||||
iDb = pTab->iDb;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
zDb = db->aDb[iDb].zName;
|
||||
|
||||
/* Get a NULL terminated version of the new table name. */
|
||||
@@ -348,7 +358,7 @@ void sqlite3AlterRenameTable(
|
||||
** table. Don't do this if the table being ALTERed is itself located in
|
||||
** the temp database.
|
||||
*/
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE sqlite_temp_master SET "
|
||||
"sql = sqlite_rename_trigger(sql, %Q), "
|
||||
@@ -384,13 +394,12 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
char *zCol; /* Null-terminated column definition */
|
||||
Column *pCol; /* The new column */
|
||||
Expr *pDflt; /* Default value for the new column */
|
||||
Vdbe *v;
|
||||
|
||||
if( pParse->nErr ) return;
|
||||
pNew = pParse->pNewTable;
|
||||
assert( pNew );
|
||||
|
||||
iDb = pNew->iDb;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pNew->pSchema);
|
||||
zDb = pParse->db->aDb[iDb].zName;
|
||||
zTab = pNew->zName;
|
||||
pCol = &pNew->aCol[pNew->nCol-1];
|
||||
@@ -398,6 +407,13 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
pTab = sqlite3FindTable(pParse->db, zTab, zDb);
|
||||
assert( pTab );
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
/* Invoke the authorization callback. */
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 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.
|
||||
@@ -441,7 +457,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
}
|
||||
|
||||
/* Modify the CREATE TABLE statement. */
|
||||
zCol = sqliteStrNDup(pColDef->z, pColDef->n);
|
||||
zCol = sqliteStrNDup((char*)pColDef->z, pColDef->n);
|
||||
if( zCol ){
|
||||
char *zEnd = &zCol[pColDef->n-1];
|
||||
while( (zEnd>zCol && *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
|
||||
@@ -461,22 +477,12 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
** format to 2. If the default value of the new column is not NULL,
|
||||
** the file format becomes 3.
|
||||
*/
|
||||
if( (v=sqlite3GetVdbe(pParse)) ){
|
||||
int f = (pDflt?3:2);
|
||||
|
||||
/* Only set the file format to $f if it is currently less than $f. */
|
||||
sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ge, 0, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 1);
|
||||
}
|
||||
sqlite3MinimumFileFormat(pParse, iDb, pDflt ? 3 : 2);
|
||||
|
||||
/* Reload the schema of the modified table. */
|
||||
reloadTableSchema(pParse, pTab, pTab->zName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This function is called by the parser after the table-name in
|
||||
** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
|
||||
@@ -501,7 +507,8 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
int nAlloc;
|
||||
|
||||
/* Look up the table being altered. */
|
||||
assert( !pParse->pNewTable );
|
||||
assert( pParse->pNewTable==0 );
|
||||
if( sqlite3MallocFailed() ) goto exit_begin_add_column;
|
||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||
if( !pTab ) goto exit_begin_add_column;
|
||||
|
||||
@@ -512,7 +519,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
}
|
||||
|
||||
assert( pTab->addColOffset>0 );
|
||||
iDb = pTab->iDb;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
|
||||
/* Put a copy of the Table struct in Parse.pNewTable for the
|
||||
** sqlite3AddColumn() function and friends to modify.
|
||||
@@ -520,6 +527,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
pNew = (Table *)sqliteMalloc(sizeof(Table));
|
||||
if( !pNew ) goto exit_begin_add_column;
|
||||
pParse->pNewTable = pNew;
|
||||
pNew->nRef = 1;
|
||||
pNew->nCol = pTab->nCol;
|
||||
assert( pNew->nCol>0 );
|
||||
nAlloc = (((pNew->nCol-1)/8)*8)+8;
|
||||
@@ -533,11 +541,13 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
for(i=0; i<pNew->nCol; i++){
|
||||
Column *pCol = &pNew->aCol[i];
|
||||
pCol->zName = sqliteStrDup(pCol->zName);
|
||||
pCol->zColl = 0;
|
||||
pCol->zType = 0;
|
||||
pCol->pDflt = 0;
|
||||
}
|
||||
pNew->iDb = iDb;
|
||||
pNew->pSchema = pParse->db->aDb[iDb].pSchema;
|
||||
pNew->addColOffset = pTab->addColOffset;
|
||||
pNew->nRef = 1;
|
||||
|
||||
/* Begin a transaction and increment the schema cookie. */
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
|
||||
403
sqlitebrowser/sqlitebrowser/sqlite_source/analyze.c
Normal file
403
sqlitebrowser/sqlitebrowser/sqlite_source/analyze.c
Normal file
@@ -0,0 +1,403 @@
|
||||
/*
|
||||
** 2005 July 8
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains code associated with the ANALYZE command.
|
||||
**
|
||||
** @(#) $Id: analyze.c,v 1.1 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_ANALYZE
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This routine generates code that opens the sqlite_stat1 table on cursor
|
||||
** iStatCur.
|
||||
**
|
||||
** If the sqlite_stat1 tables does not previously exist, it is created.
|
||||
** If it does previously exist, all entires associated with table zWhere
|
||||
** are removed. If zWhere==0 then all entries are removed.
|
||||
*/
|
||||
static void openStatTable(
|
||||
Parse *pParse, /* Parsing context */
|
||||
int iDb, /* The database we are looking in */
|
||||
int iStatCur, /* Open the sqlite_stat1 table on this cursor */
|
||||
const char *zWhere /* Delete entries associated with this table */
|
||||
){
|
||||
sqlite3 *db = pParse->db;
|
||||
Db *pDb;
|
||||
int iRootPage;
|
||||
Table *pStat;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
|
||||
pDb = &db->aDb[iDb];
|
||||
if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){
|
||||
/* The sqlite_stat1 tables does not exist. Create it.
|
||||
** Note that a side-effect of the CREATE TABLE statement is to leave
|
||||
** the rootpage of the new table on the top of the stack. This is
|
||||
** important because the OpenWrite opcode below will be needing it. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"CREATE TABLE %Q.sqlite_stat1(tbl,idx,stat)",
|
||||
pDb->zName
|
||||
);
|
||||
iRootPage = 0; /* Cause rootpage to be taken from top of stack */
|
||||
}else if( zWhere ){
|
||||
/* The sqlite_stat1 table exists. Delete all entries associated with
|
||||
** the table zWhere. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q",
|
||||
pDb->zName, zWhere
|
||||
);
|
||||
iRootPage = pStat->tnum;
|
||||
}else{
|
||||
/* The sqlite_stat1 table already exists. Delete all rows. */
|
||||
iRootPage = pStat->tnum;
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pStat->tnum, iDb);
|
||||
}
|
||||
|
||||
/* Open the sqlite_stat1 table for writing. Unless it was created
|
||||
** by this vdbe program, lock it for writing at the shared-cache level.
|
||||
** If this vdbe did create the sqlite_stat1 table, then it must have
|
||||
** already obtained a schema-lock, making the write-lock redundant.
|
||||
*/
|
||||
if( iRootPage>0 ){
|
||||
sqlite3TableLock(pParse, iDb, iRootPage, 1, "sqlite_stat1");
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code to do an analysis of all indices associated with
|
||||
** a single table.
|
||||
*/
|
||||
static void analyzeOneTable(
|
||||
Parse *pParse, /* Parser context */
|
||||
Table *pTab, /* Table whose indices are to be analyzed */
|
||||
int iStatCur, /* Cursor that writes to the sqlite_stat1 table */
|
||||
int iMem /* Available memory locations begin here */
|
||||
){
|
||||
Index *pIdx; /* An index to being analyzed */
|
||||
int iIdxCur; /* Cursor number for index being analyzed */
|
||||
int nCol; /* Number of columns in the index */
|
||||
Vdbe *v; /* The virtual machine being built up */
|
||||
int i; /* Loop counter */
|
||||
int topOfLoop; /* The top of the loop */
|
||||
int endOfLoop; /* The end of the loop */
|
||||
int addr; /* The address of an instruction */
|
||||
int iDb; /* Index of database containing pTab */
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( pTab==0 || pTab->pIndex==0 ){
|
||||
/* Do no analysis for tables that have no indices */
|
||||
return;
|
||||
}
|
||||
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
assert( iDb>=0 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
|
||||
pParse->db->aDb[iDb].zName ) ){
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Establish a read-lock on the table at the shared-cache level. */
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
|
||||
|
||||
iIdxCur = pParse->nTab;
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||
|
||||
/* Open a cursor to the index to be analyzed
|
||||
*/
|
||||
assert( iDb==sqlite3SchemaToIndex(pParse->db, pIdx->pSchema) );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
VdbeComment((v, "# %s", pIdx->zName));
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum,
|
||||
(char *)pKey, P3_KEYINFO_HANDOFF);
|
||||
nCol = pIdx->nColumn;
|
||||
if( iMem+nCol*2>=pParse->nMem ){
|
||||
pParse->nMem = iMem+nCol*2+1;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, nCol+1);
|
||||
|
||||
/* Memory cells are used as follows:
|
||||
**
|
||||
** mem[iMem]: The total number of rows in the table.
|
||||
** mem[iMem+1]: Number of distinct values in column 1
|
||||
** ...
|
||||
** mem[iMem+nCol]: Number of distinct values in column N
|
||||
** mem[iMem+nCol+1] Last observed value of column 1
|
||||
** ...
|
||||
** mem[iMem+nCol+nCol]: Last observed value of column N
|
||||
**
|
||||
** Cells iMem through iMem+nCol are initialized to 0. The others
|
||||
** are initialized to NULL.
|
||||
*/
|
||||
for(i=0; i<=nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem+i);
|
||||
}
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_MemNull, iMem+nCol+i+1, 0);
|
||||
}
|
||||
|
||||
/* Do the analysis.
|
||||
*/
|
||||
endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);
|
||||
topOfLoop = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, iMem);
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+nCol+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 0x100, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, endOfLoop);
|
||||
for(i=0; i<nCol; i++){
|
||||
addr = sqlite3VdbeAddOp(v, OP_MemIncr, 1, iMem+i+1);
|
||||
sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, 1);
|
||||
}
|
||||
sqlite3VdbeResolveLabel(v, endOfLoop);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iIdxCur, topOfLoop);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iIdxCur, 0);
|
||||
|
||||
/* Store the results.
|
||||
**
|
||||
** The result is a single row of the sqlite_stmt1 table. The first
|
||||
** two columns are the names of the table and index. The third column
|
||||
** is a string composed of a list of integer statistics about the
|
||||
** index. The first integer in the list is the total number of entires
|
||||
** in the index. There is one additional integer in the list for each
|
||||
** column of the table. This additional integer is a guess of how many
|
||||
** rows of the table the index will select. If D is the count of distinct
|
||||
** values and K is the total number of rows, then the integer is computed
|
||||
** as:
|
||||
**
|
||||
** I = (K+D-1)/D
|
||||
**
|
||||
** If K==0 then no entry is made into the sqlite_stat1 table.
|
||||
** If K>0 then it is always the case the D>0 so division by zero
|
||||
** is never possible.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_IfNot, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, iStatCur, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, " ", 0);
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Add, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, -1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Divide, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ToInt, 0, 0);
|
||||
if( i==nCol-1 ){
|
||||
sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "aaa", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0);
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will cause the most recent index analysis to
|
||||
** be laoded into internal hash tables where is can be used.
|
||||
*/
|
||||
static void loadAnalysis(Parse *pParse, int iDb){
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
sqlite3VdbeAddOp(v, OP_LoadAnalysis, iDb, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will do an analysis of an entire database
|
||||
*/
|
||||
static void analyzeDatabase(Parse *pParse, int iDb){
|
||||
sqlite3 *db = pParse->db;
|
||||
Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
|
||||
HashElem *k;
|
||||
int iStatCur;
|
||||
int iMem;
|
||||
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
iStatCur = pParse->nTab++;
|
||||
openStatTable(pParse, iDb, iStatCur, 0);
|
||||
iMem = pParse->nMem;
|
||||
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
|
||||
Table *pTab = (Table*)sqliteHashData(k);
|
||||
analyzeOneTable(pParse, pTab, iStatCur, iMem);
|
||||
}
|
||||
loadAnalysis(pParse, iDb);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will do an analysis of a single table in
|
||||
** a database.
|
||||
*/
|
||||
static void analyzeTable(Parse *pParse, Table *pTab){
|
||||
int iDb;
|
||||
int iStatCur;
|
||||
|
||||
assert( pTab!=0 );
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
iStatCur = pParse->nTab++;
|
||||
openStatTable(pParse, iDb, iStatCur, pTab->zName);
|
||||
analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem);
|
||||
loadAnalysis(pParse, iDb);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code for the ANALYZE command. The parser calls this routine
|
||||
** when it recognizes an ANALYZE command.
|
||||
**
|
||||
** ANALYZE -- 1
|
||||
** ANALYZE <database> -- 2
|
||||
** ANALYZE ?<database>.?<tablename> -- 3
|
||||
**
|
||||
** Form 1 causes all indices in all attached databases to be analyzed.
|
||||
** Form 2 analyzes all indices the single database named.
|
||||
** Form 3 analyzes all indices associated with the named table.
|
||||
*/
|
||||
void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
int i;
|
||||
char *z, *zDb;
|
||||
Table *pTab;
|
||||
Token *pTableName;
|
||||
|
||||
/* Read the database schema. If an error occurs, leave an error message
|
||||
** and code in pParse and return NULL. */
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
|
||||
return;
|
||||
}
|
||||
|
||||
if( pName1==0 ){
|
||||
/* Form 1: Analyze everything */
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( i==1 ) continue; /* Do not analyze the TEMP database */
|
||||
analyzeDatabase(pParse, i);
|
||||
}
|
||||
}else if( pName2==0 || pName2->n==0 ){
|
||||
/* Form 2: Analyze the database or table named */
|
||||
iDb = sqlite3FindDb(db, pName1);
|
||||
if( iDb>=0 ){
|
||||
analyzeDatabase(pParse, iDb);
|
||||
}else{
|
||||
z = sqlite3NameFromToken(pName1);
|
||||
pTab = sqlite3LocateTable(pParse, z, 0);
|
||||
sqliteFree(z);
|
||||
if( pTab ){
|
||||
analyzeTable(pParse, pTab);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
/* Form 3: Analyze the fully qualified table name */
|
||||
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
|
||||
if( iDb>=0 ){
|
||||
zDb = db->aDb[iDb].zName;
|
||||
z = sqlite3NameFromToken(pTableName);
|
||||
pTab = sqlite3LocateTable(pParse, z, zDb);
|
||||
sqliteFree(z);
|
||||
if( pTab ){
|
||||
analyzeTable(pParse, pTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Used to pass information from the analyzer reader through to the
|
||||
** callback routine.
|
||||
*/
|
||||
typedef struct analysisInfo analysisInfo;
|
||||
struct analysisInfo {
|
||||
sqlite3 *db;
|
||||
const char *zDatabase;
|
||||
};
|
||||
|
||||
/*
|
||||
** This callback is invoked once for each index when reading the
|
||||
** sqlite_stat1 table.
|
||||
**
|
||||
** argv[0] = name of the index
|
||||
** argv[1] = results of analysis - on integer for each column
|
||||
*/
|
||||
static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
|
||||
analysisInfo *pInfo = (analysisInfo*)pData;
|
||||
Index *pIndex;
|
||||
int i, c;
|
||||
unsigned int v;
|
||||
const char *z;
|
||||
|
||||
assert( argc==2 );
|
||||
if( argv==0 || argv[0]==0 || argv[1]==0 ){
|
||||
return 0;
|
||||
}
|
||||
pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
|
||||
if( pIndex==0 ){
|
||||
return 0;
|
||||
}
|
||||
z = argv[1];
|
||||
for(i=0; *z && i<=pIndex->nColumn; i++){
|
||||
v = 0;
|
||||
while( (c=z[0])>='0' && c<='9' ){
|
||||
v = v*10 + c - '0';
|
||||
z++;
|
||||
}
|
||||
pIndex->aiRowEst[i] = v;
|
||||
if( *z==' ' ) z++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Load the content of the sqlite_stat1 table into the index hash tables.
|
||||
*/
|
||||
void sqlite3AnalysisLoad(sqlite3 *db, int iDb){
|
||||
analysisInfo sInfo;
|
||||
HashElem *i;
|
||||
char *zSql;
|
||||
|
||||
/* Clear any prior statistics */
|
||||
for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
|
||||
Index *pIdx = sqliteHashData(i);
|
||||
sqlite3DefaultRowEst(pIdx);
|
||||
}
|
||||
|
||||
/* Check to make sure the sqlite_stat1 table existss */
|
||||
sInfo.db = db;
|
||||
sInfo.zDatabase = db->aDb[iDb].zName;
|
||||
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Load new statistics out of the sqlite_stat1 table */
|
||||
zSql = sqlite3MPrintf("SELECT idx, stat FROM %Q.sqlite_stat1",
|
||||
sInfo.zDatabase);
|
||||
sqlite3SafetyOff(db);
|
||||
sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
|
||||
sqlite3SafetyOn(db);
|
||||
sqliteFree(zSql);
|
||||
}
|
||||
|
||||
|
||||
#endif /* SQLITE_OMIT_ANALYZE */
|
||||
@@ -11,201 +11,342 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: attach.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This routine is called by the parser to process an ATTACH statement:
|
||||
** Resolve an expression that was part of an ATTACH or DETACH statement. This
|
||||
** is slightly different from resolving a normal SQL expression, because simple
|
||||
** identifiers are treated as strings, not possible column names or aliases.
|
||||
**
|
||||
** ATTACH DATABASE filename AS dbname
|
||||
** i.e. if the parser sees:
|
||||
**
|
||||
** The pFilename and pDbname arguments are the tokens that define the
|
||||
** filename and dbname in the ATTACH statement.
|
||||
** ATTACH DATABASE abc AS def
|
||||
**
|
||||
** it treats the two expressions as literal strings 'abc' and 'def' instead of
|
||||
** looking for columns of the same name.
|
||||
**
|
||||
** This only applies to the root node of pExpr, so the statement:
|
||||
**
|
||||
** ATTACH DATABASE abc||def AS 'db2'
|
||||
**
|
||||
** will fail because neither abc or def can be resolved.
|
||||
*/
|
||||
void sqlite3Attach(
|
||||
Parse *pParse, /* The parser context */
|
||||
Token *pFilename, /* Name of database file */
|
||||
Token *pDbname, /* Name of the database to use internally */
|
||||
int keyType, /* 0: no key. 1: TEXT, 2: BLOB */
|
||||
Token *pKey /* Text of the key for keytype 1 and 2 */
|
||||
static int resolveAttachExpr(NameContext *pName, Expr *pExpr)
|
||||
{
|
||||
int rc = SQLITE_OK;
|
||||
if( pExpr ){
|
||||
if( pExpr->op!=TK_ID ){
|
||||
rc = sqlite3ExprResolveNames(pName, pExpr);
|
||||
}else{
|
||||
pExpr->op = TK_STRING;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** An SQL user-function registered to do the work of an ATTACH statement. The
|
||||
** three arguments to the function come directly from an attach statement:
|
||||
**
|
||||
** ATTACH DATABASE x AS y KEY z
|
||||
**
|
||||
** SELECT sqlite_attach(x, y, z)
|
||||
**
|
||||
** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the
|
||||
** third argument.
|
||||
*/
|
||||
static void attachFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int i;
|
||||
int rc = 0;
|
||||
sqlite3 *db = sqlite3_user_data(context);
|
||||
const char *zName;
|
||||
const char *zFile;
|
||||
Db *aNew;
|
||||
int rc, i;
|
||||
char *zFile = 0;
|
||||
char *zName = 0;
|
||||
sqlite3 *db;
|
||||
Vdbe *v;
|
||||
char zErr[128];
|
||||
char *zErrDyn = 0;
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
zFile = (const char *)sqlite3_value_text(argv[0]);
|
||||
zName = (const char *)sqlite3_value_text(argv[1]);
|
||||
|
||||
/* Check for the following errors:
|
||||
**
|
||||
** * Too many attached databases,
|
||||
** * Transaction currently open
|
||||
** * Specified database name already being used.
|
||||
*/
|
||||
if( db->nDb>=MAX_ATTACHED+2 ){
|
||||
sqlite3ErrorMsg(pParse, "too many attached databases - max %d",
|
||||
MAX_ATTACHED);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
sqlite3_snprintf(
|
||||
127, zErr, "too many attached databases - max %d", MAX_ATTACHED
|
||||
);
|
||||
goto attach_error;
|
||||
}
|
||||
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse, "cannot ATTACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
zFile = sqlite3NameFromToken(pFilename);
|
||||
if( zFile==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
|
||||
goto attach_end;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
if( zName==0 ){
|
||||
goto attach_end;
|
||||
strcpy(zErr, "cannot ATTACH database within transaction");
|
||||
goto attach_error;
|
||||
}
|
||||
for(i=0; i<db->nDb; i++){
|
||||
char *z = db->aDb[i].zName;
|
||||
if( z && sqlite3StrICmp(z, zName)==0 ){
|
||||
sqlite3ErrorMsg(pParse, "database %s is already in use", zName);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
goto attach_end;
|
||||
sqlite3_snprintf(127, zErr, "database %s is already in use", zName);
|
||||
goto attach_error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate the new entry in the db->aDb[] array and initialise the schema
|
||||
** hash tables.
|
||||
*/
|
||||
if( db->aDb==db->aDbStatic ){
|
||||
aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
|
||||
if( aNew==0 ){
|
||||
goto attach_end;
|
||||
return;
|
||||
}
|
||||
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
|
||||
}else{
|
||||
aNew = sqliteRealloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
|
||||
if( aNew==0 ){
|
||||
goto attach_end;
|
||||
return;
|
||||
}
|
||||
}
|
||||
db->aDb = aNew;
|
||||
aNew = &db->aDb[db->nDb++];
|
||||
memset(aNew, 0, sizeof(*aNew));
|
||||
sqlite3HashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
|
||||
aNew->zName = zName;
|
||||
zName = 0;
|
||||
aNew->safety_level = 3;
|
||||
|
||||
/* 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 initialised.
|
||||
*/
|
||||
rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
if( rc ){
|
||||
sqlite3ErrorMsg(pParse, "unable to open database: %s", zFile);
|
||||
if( rc==SQLITE_OK ){
|
||||
aNew->pSchema = sqlite3SchemaGet(aNew->pBt);
|
||||
if( !aNew->pSchema ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
|
||||
strcpy(zErr,
|
||||
"attached databases must use the same text encoding as main database");
|
||||
goto attach_error;
|
||||
}
|
||||
}
|
||||
aNew->zName = sqliteStrDup(zName);
|
||||
aNew->safety_level = 3;
|
||||
|
||||
#if SQLITE_HAS_CODEC
|
||||
{
|
||||
extern int sqlite3CodecAttach(sqlite3*, int, void*, int);
|
||||
char *zKey;
|
||||
extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
|
||||
int nKey;
|
||||
if( keyType==0 ){
|
||||
/* No key specified. Use the key from the main database */
|
||||
extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
}else if( keyType==1 ){
|
||||
/* Key specified as text */
|
||||
zKey = sqlite3NameFromToken(pKey);
|
||||
nKey = strlen(zKey);
|
||||
}else{
|
||||
/* Key specified as a BLOB */
|
||||
char *zTemp;
|
||||
assert( keyType==2 );
|
||||
pKey->z++;
|
||||
pKey->n--;
|
||||
zTemp = sqlite3NameFromToken(pKey);
|
||||
zKey = sqlite3HexToBlob(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
if( keyType ){
|
||||
sqliteFree(zKey);
|
||||
char *zKey;
|
||||
int t = sqlite3_value_type(argv[2]);
|
||||
switch( t ){
|
||||
case SQLITE_INTEGER:
|
||||
case SQLITE_FLOAT:
|
||||
zErrDyn = sqliteStrDup("Invalid key value");
|
||||
rc = SQLITE_ERROR;
|
||||
break;
|
||||
|
||||
case SQLITE_TEXT:
|
||||
case SQLITE_BLOB:
|
||||
nKey = sqlite3_value_bytes(argv[2]);
|
||||
zKey = (char *)sqlite3_value_blob(argv[2]);
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
break;
|
||||
|
||||
case SQLITE_NULL:
|
||||
/* No key specified. Use the key from the main database */
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
if( pParse->nErr==0 && rc==SQLITE_OK ){
|
||||
rc = sqlite3ReadSchema(pParse);
|
||||
|
||||
/* 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
|
||||
** remove the entry from the db->aDb[] array. i.e. put everything back the way
|
||||
** we found it.
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3SafetyOn(db);
|
||||
rc = sqlite3Init(db, &zErrDyn);
|
||||
sqlite3SafetyOff(db);
|
||||
}
|
||||
if( rc ){
|
||||
int i = db->nDb - 1;
|
||||
assert( i>=2 );
|
||||
if( db->aDb[i].pBt ){
|
||||
sqlite3BtreeClose(db->aDb[i].pBt);
|
||||
db->aDb[i].pBt = 0;
|
||||
int iDb = db->nDb - 1;
|
||||
assert( iDb>=2 );
|
||||
if( db->aDb[iDb].pBt ){
|
||||
sqlite3BtreeClose(db->aDb[iDb].pBt);
|
||||
db->aDb[iDb].pBt = 0;
|
||||
db->aDb[iDb].pSchema = 0;
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
if( 0==pParse->nErr ){
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
db->nDb = iDb;
|
||||
sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile);
|
||||
goto attach_error;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
attach_end:
|
||||
sqliteFree(zFile);
|
||||
sqliteFree(zName);
|
||||
attach_error:
|
||||
/* Return an error if we get here */
|
||||
if( zErrDyn ){
|
||||
sqlite3_result_error(context, zErrDyn, -1);
|
||||
sqliteFree(zErrDyn);
|
||||
}else{
|
||||
zErr[sizeof(zErr)-1] = 0;
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called by the parser to process a DETACH statement:
|
||||
** An SQL user-function registered to do the work of an DETACH statement. The
|
||||
** three arguments to the function come directly from a detach statement:
|
||||
**
|
||||
** DETACH DATABASE dbname
|
||||
** DETACH DATABASE x
|
||||
**
|
||||
** The pDbname argument is the name of the database in the DETACH statement.
|
||||
** SELECT sqlite_detach(x)
|
||||
*/
|
||||
void sqlite3Detach(Parse *pParse, Token *pDbname){
|
||||
static void detachFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zName = (const char *)sqlite3_value_text(argv[0]);
|
||||
sqlite3 *db = sqlite3_user_data(context);
|
||||
int i;
|
||||
sqlite3 *db;
|
||||
Vdbe *v;
|
||||
Db *pDb = 0;
|
||||
char *zName;
|
||||
char zErr[128];
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
if( zName==0 ) return;
|
||||
assert(zName);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 ) continue;
|
||||
if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
|
||||
}
|
||||
|
||||
if( i>=db->nDb ){
|
||||
sqlite3ErrorMsg(pParse, "no such database: %z", zName);
|
||||
return;
|
||||
sqlite3_snprintf(sizeof(zErr), zErr, "no such database: %s", zName);
|
||||
goto detach_error;
|
||||
}
|
||||
if( i<2 ){
|
||||
sqlite3ErrorMsg(pParse, "cannot detach database %z", zName);
|
||||
return;
|
||||
sqlite3_snprintf(sizeof(zErr), zErr, "cannot detach database %s", zName);
|
||||
goto detach_error;
|
||||
}
|
||||
sqliteFree(zName);
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
strcpy(zErr, "cannot DETACH database within transaction");
|
||||
goto detach_error;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
pDb->pSchema = 0;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
return;
|
||||
|
||||
detach_error:
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure generates VDBE code for a single invocation of either the
|
||||
** sqlite_detach() or sqlite_attach() SQL user functions.
|
||||
*/
|
||||
static void codeAttach(
|
||||
Parse *pParse, /* The parser context */
|
||||
int type, /* Either SQLITE_ATTACH or SQLITE_DETACH */
|
||||
const char *zFunc, /* Either "sqlite_attach" or "sqlite_detach */
|
||||
int nFunc, /* Number of args to pass to zFunc */
|
||||
Expr *pAuthArg, /* Expression to pass to authorization callback */
|
||||
Expr *pFilename, /* Name of database file */
|
||||
Expr *pDbname, /* Name of the database to use internally */
|
||||
Expr *pKey /* Database key for encryption extension */
|
||||
){
|
||||
int rc;
|
||||
NameContext sName;
|
||||
Vdbe *v;
|
||||
FuncDef *pFunc;
|
||||
sqlite3* db = pParse->db;
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
assert( sqlite3MallocFailed() || pAuthArg );
|
||||
if( pAuthArg ){
|
||||
char *zAuthArg = sqlite3NameFromToken(&pAuthArg->span);
|
||||
if( !zAuthArg ){
|
||||
goto attach_end;
|
||||
}
|
||||
rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
|
||||
sqliteFree(zAuthArg);
|
||||
if(rc!=SQLITE_OK ){
|
||||
goto attach_end;
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
memset(&sName, 0, sizeof(NameContext));
|
||||
sName.pParse = pParse;
|
||||
|
||||
if(
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
|
||||
){
|
||||
pParse->nErr++;
|
||||
goto attach_end;
|
||||
}
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
sqlite3ExprCode(pParse, pFilename);
|
||||
sqlite3ExprCode(pParse, pDbname);
|
||||
sqlite3ExprCode(pParse, pKey);
|
||||
|
||||
assert( v || sqlite3MallocFailed() );
|
||||
if( v ){
|
||||
sqlite3VdbeAddOp(v, OP_Function, 0, nFunc);
|
||||
pFunc = sqlite3FindFunction(db, zFunc, strlen(zFunc), nFunc, SQLITE_UTF8,0);
|
||||
sqlite3VdbeChangeP3(v, -1, (char *)pFunc, P3_FUNCDEF);
|
||||
|
||||
/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
|
||||
** statement only). For DETACH, set it to false (expire all existing
|
||||
** statements).
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Expire, (type==SQLITE_ATTACH), 0);
|
||||
}
|
||||
|
||||
attach_end:
|
||||
sqlite3ExprDelete(pFilename);
|
||||
sqlite3ExprDelete(pDbname);
|
||||
sqlite3ExprDelete(pKey);
|
||||
}
|
||||
|
||||
/*
|
||||
** Called by the parser to compile a DETACH statement.
|
||||
**
|
||||
** DETACH pDbname
|
||||
*/
|
||||
void sqlite3Detach(Parse *pParse, Expr *pDbname){
|
||||
codeAttach(pParse, SQLITE_DETACH, "sqlite_detach", 1, pDbname, 0, 0, pDbname);
|
||||
}
|
||||
|
||||
/*
|
||||
** Called by the parser to compile an ATTACH statement.
|
||||
**
|
||||
** ATTACH p AS pDbname KEY pKey
|
||||
*/
|
||||
void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
|
||||
codeAttach(pParse, SQLITE_ATTACH, "sqlite_attach", 3, p, p, pDbname, pKey);
|
||||
}
|
||||
|
||||
/*
|
||||
** Register the functions sqlite_attach and sqlite_detach.
|
||||
*/
|
||||
void sqlite3AttachFunctions(sqlite3 *db){
|
||||
static const int enc = SQLITE_UTF8;
|
||||
sqlite3CreateFunc(db, "sqlite_attach", 3, enc, db, attachFunc, 0, 0);
|
||||
sqlite3CreateFunc(db, "sqlite_detach", 1, enc, db, detachFunc, 0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
** systems that do not need this facility may omit it by recompiling
|
||||
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
|
||||
**
|
||||
** $Id: auth.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: auth.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -112,9 +112,17 @@ void sqlite3AuthRead(
|
||||
int iSrc; /* Index in pTabList->a[] of table being read */
|
||||
const char *zDBase; /* Name of database being accessed */
|
||||
TriggerStack *pStack; /* The stack of current triggers */
|
||||
int iDb; /* The index of the database the expression refers to */
|
||||
|
||||
if( db->xAuth==0 ) return;
|
||||
if( pExpr->op==TK_AS ) return;
|
||||
assert( pExpr->op==TK_COLUMN );
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pExpr->pSchema);
|
||||
if( iDb<0 ){
|
||||
/* An attempt to read a column out of a subquery or other
|
||||
** temporary table. */
|
||||
return;
|
||||
}
|
||||
for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){
|
||||
if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
|
||||
}
|
||||
@@ -139,14 +147,14 @@ void sqlite3AuthRead(
|
||||
}else{
|
||||
zCol = "ROWID";
|
||||
}
|
||||
assert( pExpr->iDb<db->nDb );
|
||||
zDBase = db->aDb[pExpr->iDb].zName;
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
zDBase = db->aDb[iDb].zName;
|
||||
rc = db->xAuth(db->pAuthArg, SQLITE_READ, pTab->zName, zCol, zDBase,
|
||||
pParse->zAuthContext);
|
||||
if( rc==SQLITE_IGNORE ){
|
||||
pExpr->op = TK_NULL;
|
||||
}else if( rc==SQLITE_DENY ){
|
||||
if( db->nDb>2 || pExpr->iDb!=0 ){
|
||||
if( db->nDb>2 || iDb!=0 ){
|
||||
sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",
|
||||
zDBase, pTab->zName, zCol);
|
||||
}else{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,7 @@
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** @(#) $Id: btree.h,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
@@ -36,10 +36,12 @@
|
||||
*/
|
||||
typedef struct Btree Btree;
|
||||
typedef struct BtCursor BtCursor;
|
||||
typedef struct BtShared BtShared;
|
||||
|
||||
|
||||
int sqlite3BtreeOpen(
|
||||
const char *zFilename, /* Name of database file to open */
|
||||
sqlite3 *db, /* Associated database connection */
|
||||
Btree **, /* Return open Btree* here */
|
||||
int flags /* Flags */
|
||||
);
|
||||
@@ -57,7 +59,8 @@ int sqlite3BtreeOpen(
|
||||
int sqlite3BtreeClose(Btree*);
|
||||
int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*);
|
||||
int sqlite3BtreeSetCacheSize(Btree*,int);
|
||||
int sqlite3BtreeSetSafetyLevel(Btree*,int);
|
||||
int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
|
||||
int sqlite3BtreeSyncDisabled(Btree*);
|
||||
int sqlite3BtreeSetPageSize(Btree*,int,int);
|
||||
int sqlite3BtreeGetPageSize(Btree*);
|
||||
int sqlite3BtreeGetReserve(Btree*);
|
||||
@@ -73,7 +76,9 @@ int sqlite3BtreeCreateTable(Btree*, int*, int flags);
|
||||
int sqlite3BtreeIsInTrans(Btree*);
|
||||
int sqlite3BtreeIsInStmt(Btree*);
|
||||
int sqlite3BtreeSync(Btree*, const char *zMaster);
|
||||
int sqlite3BtreeReset(Btree *);
|
||||
void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
|
||||
int sqlite3BtreeSchemaLocked(Btree *);
|
||||
int sqlite3BtreeLockTable(Btree *, int, u8);
|
||||
|
||||
const char *sqlite3BtreeGetFilename(Btree *);
|
||||
const char *sqlite3BtreeGetDirname(Btree *);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
314
sqlitebrowser/sqlitebrowser/sqlite_source/callback.c
Normal file
314
sqlitebrowser/sqlitebrowser/sqlite_source/callback.c
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
** 2005 May 23
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This file contains functions used to access the internal hash tables
|
||||
** of user defined functions and collation sequences.
|
||||
**
|
||||
** $Id: callback.c,v 1.1 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Invoke the 'collation needed' callback to request a collation sequence
|
||||
** in the database text encoding of name zName, length nName.
|
||||
** If the collation sequence
|
||||
*/
|
||||
static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
|
||||
assert( !db->xCollNeeded || !db->xCollNeeded16 );
|
||||
if( nName<0 ) nName = strlen(zName);
|
||||
if( db->xCollNeeded ){
|
||||
char *zExternal = sqliteStrNDup(zName, nName);
|
||||
if( !zExternal ) return;
|
||||
db->xCollNeeded(db->pCollNeededArg, db, (int)ENC(db), zExternal);
|
||||
sqliteFree(zExternal);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
if( db->xCollNeeded16 ){
|
||||
char const *zExternal;
|
||||
sqlite3_value *pTmp = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC);
|
||||
zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
|
||||
if( zExternal ){
|
||||
db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
|
||||
}
|
||||
sqlite3ValueFree(pTmp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called if the collation factory fails to deliver a
|
||||
** collation function in the best encoding but there may be other versions
|
||||
** of this collation function (for other text encodings) available. Use one
|
||||
** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
|
||||
** possible.
|
||||
*/
|
||||
static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
|
||||
CollSeq *pColl2;
|
||||
char *z = pColl->zName;
|
||||
int n = strlen(z);
|
||||
int i;
|
||||
static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
|
||||
for(i=0; i<3; i++){
|
||||
pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0);
|
||||
if( pColl2->xCmp!=0 ){
|
||||
memcpy(pColl, pColl2, sizeof(CollSeq));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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 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
|
||||
** db for collation type name zName, length nName, or NULL, if no collation
|
||||
** sequence can be found.
|
||||
*/
|
||||
CollSeq *sqlite3GetCollSeq(
|
||||
sqlite3* db,
|
||||
CollSeq *pColl,
|
||||
const char *zName,
|
||||
int nName
|
||||
){
|
||||
CollSeq *p;
|
||||
|
||||
p = pColl;
|
||||
if( !p ){
|
||||
p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0);
|
||||
}
|
||||
if( !p || !p->xCmp ){
|
||||
/* No collation sequence of this type for this encoding is registered.
|
||||
** Call the collation factory to see if it can supply us with one.
|
||||
*/
|
||||
callCollNeeded(db, zName, nName);
|
||||
p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0);
|
||||
}
|
||||
if( p && !p->xCmp && synthCollSeq(db, p) ){
|
||||
p = 0;
|
||||
}
|
||||
assert( !p || p->xCmp );
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called on a collation sequence before it is used to
|
||||
** check that it is defined. An undefined collation sequence exists when
|
||||
** a database is loaded that contains references to collation sequences
|
||||
** 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,
|
||||
** an equivalent collating sequence that uses a text encoding different
|
||||
** from the main database is substituted, if one is available.
|
||||
*/
|
||||
int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){
|
||||
if( pColl ){
|
||||
const char *zName = pColl->zName;
|
||||
CollSeq *p = sqlite3GetCollSeq(pParse->db, pColl, zName, -1);
|
||||
if( !p ){
|
||||
if( pParse->nErr==0 ){
|
||||
sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName);
|
||||
}
|
||||
pParse->nErr++;
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
assert( p==pColl );
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Locate and return an entry from the db.aCollSeq hash table. If the entry
|
||||
** specified by zName and nName is not found and parameter 'create' is
|
||||
** true, then create a new entry. Otherwise return NULL.
|
||||
**
|
||||
** Each pointer stored in the sqlite3.aCollSeq hash table contains an
|
||||
** array of three CollSeq structures. The first is the collation sequence
|
||||
** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
|
||||
**
|
||||
** Stored immediately after the three collation sequences is a copy of
|
||||
** the collation sequence name. A pointer to this string is stored in
|
||||
** each collation sequence structure.
|
||||
*/
|
||||
static CollSeq *findCollSeqEntry(
|
||||
sqlite3 *db,
|
||||
const char *zName,
|
||||
int nName,
|
||||
int create
|
||||
){
|
||||
CollSeq *pColl;
|
||||
if( nName<0 ) nName = strlen(zName);
|
||||
pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
|
||||
|
||||
if( 0==pColl && create ){
|
||||
pColl = sqliteMalloc( 3*sizeof(*pColl) + nName + 1 );
|
||||
if( pColl ){
|
||||
CollSeq *pDel = 0;
|
||||
pColl[0].zName = (char*)&pColl[3];
|
||||
pColl[0].enc = SQLITE_UTF8;
|
||||
pColl[1].zName = (char*)&pColl[3];
|
||||
pColl[1].enc = SQLITE_UTF16LE;
|
||||
pColl[2].zName = (char*)&pColl[3];
|
||||
pColl[2].enc = SQLITE_UTF16BE;
|
||||
memcpy(pColl[0].zName, zName, nName);
|
||||
pColl[0].zName[nName] = 0;
|
||||
pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
|
||||
|
||||
/* If a malloc() failure occured in sqlite3HashInsert(), it will
|
||||
** return the pColl pointer to be deleted (because it wasn't added
|
||||
** to the hash table).
|
||||
*/
|
||||
assert( !pDel ||
|
||||
(sqlite3MallocFailed() && pDel==pColl) );
|
||||
sqliteFree(pDel);
|
||||
}
|
||||
}
|
||||
return pColl;
|
||||
}
|
||||
|
||||
/*
|
||||
** Parameter zName points to a UTF-8 encoded string nName bytes long.
|
||||
** Return the CollSeq* pointer for the collation sequence named zName
|
||||
** for the encoding 'enc' from the database 'db'.
|
||||
**
|
||||
** If the entry specified is not found and 'create' is true, then create a
|
||||
** new entry. Otherwise return NULL.
|
||||
*/
|
||||
CollSeq *sqlite3FindCollSeq(
|
||||
sqlite3 *db,
|
||||
u8 enc,
|
||||
const char *zName,
|
||||
int nName,
|
||||
int create
|
||||
){
|
||||
CollSeq *pColl;
|
||||
if( zName ){
|
||||
pColl = findCollSeqEntry(db, zName, nName, create);
|
||||
}else{
|
||||
pColl = db->pDfltColl;
|
||||
}
|
||||
assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
|
||||
assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
|
||||
if( pColl ) pColl += enc-1;
|
||||
return pColl;
|
||||
}
|
||||
|
||||
/*
|
||||
** Locate a user function given a name, a number of arguments and a flag
|
||||
** indicating whether the function prefers UTF-16 over UTF-8. Return a
|
||||
** pointer to the FuncDef structure that defines that function, or return
|
||||
** NULL if the function does not exist.
|
||||
**
|
||||
** If the createFlag argument is true, then a new (blank) FuncDef
|
||||
** structure is created and liked into the "db" structure if a
|
||||
** no matching function previously existed. When createFlag is true
|
||||
** and the nArg parameter is -1, then only a function that accepts
|
||||
** any number of arguments will be returned.
|
||||
**
|
||||
** If createFlag is false and nArg is -1, then the first valid
|
||||
** function found is returned. A function is valid if either xFunc
|
||||
** or xStep is non-zero.
|
||||
**
|
||||
** If createFlag is false, then a function with the required name and
|
||||
** number of arguments may be returned even if the eTextRep flag does not
|
||||
** match that requested.
|
||||
*/
|
||||
FuncDef *sqlite3FindFunction(
|
||||
sqlite3 *db, /* An open database */
|
||||
const char *zName, /* Name of the function. Not null-terminated */
|
||||
int nName, /* Number of characters in the name */
|
||||
int nArg, /* Number of arguments. -1 means any number */
|
||||
u8 enc, /* Preferred text encoding */
|
||||
int createFlag /* Create new entry if true and does not otherwise exist */
|
||||
){
|
||||
FuncDef *p; /* Iterator variable */
|
||||
FuncDef *pFirst; /* First function with this name */
|
||||
FuncDef *pBest = 0; /* Best match found so far */
|
||||
int bestmatch = 0;
|
||||
|
||||
|
||||
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
|
||||
if( nArg<-1 ) nArg = -1;
|
||||
|
||||
pFirst = (FuncDef*)sqlite3HashFind(&db->aFunc, zName, nName);
|
||||
for(p=pFirst; p; p=p->pNext){
|
||||
/* During the search for the best function definition, bestmatch is set
|
||||
** as follows to indicate the quality of the match with the definition
|
||||
** pointed to by pBest:
|
||||
**
|
||||
** 0: pBest is NULL. No match has been found.
|
||||
** 1: A variable arguments function that prefers UTF-8 when a UTF-16
|
||||
** encoding is requested, or vice versa.
|
||||
** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
|
||||
** requested, or vice versa.
|
||||
** 3: A variable arguments function using the same text encoding.
|
||||
** 4: A function with the exact number of arguments requested that
|
||||
** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
|
||||
** 5: A function with the exact number of arguments requested that
|
||||
** prefers UTF-16LE when UTF-16BE is requested, or vice versa.
|
||||
** 6: An exact match.
|
||||
**
|
||||
** A larger value of 'matchqual' indicates a more desirable match.
|
||||
*/
|
||||
if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){
|
||||
int match = 1; /* Quality of this match */
|
||||
if( p->nArg==nArg || nArg==-1 ){
|
||||
match = 4;
|
||||
}
|
||||
if( enc==p->iPrefEnc ){
|
||||
match += 2;
|
||||
}
|
||||
else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) ||
|
||||
(enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){
|
||||
match += 1;
|
||||
}
|
||||
|
||||
if( match>bestmatch ){
|
||||
pBest = p;
|
||||
bestmatch = match;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If the createFlag parameter is true, and the seach did not reveal an
|
||||
** exact match for the name, number of arguments and encoding, then add a
|
||||
** new entry to the hash table and return it.
|
||||
*/
|
||||
if( createFlag && bestmatch<6 &&
|
||||
(pBest = sqliteMalloc(sizeof(*pBest)+nName))!=0 ){
|
||||
pBest->nArg = nArg;
|
||||
pBest->pNext = pFirst;
|
||||
pBest->iPrefEnc = enc;
|
||||
memcpy(pBest->zName, zName, nName);
|
||||
pBest->zName[nName] = 0;
|
||||
if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
|
||||
sqliteFree(pBest);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
|
||||
return pBest;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
263
sqlitebrowser/sqlitebrowser/sqlite_source/complete.c
Normal file
263
sqlitebrowser/sqlitebrowser/sqlite_source/complete.c
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
** 2001 September 15
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** An tokenizer for SQL
|
||||
**
|
||||
** This file contains C code that implements the sqlite3_complete() API.
|
||||
** This code used to be part of the tokenizer.c source file. But by
|
||||
** separating it out, the code will be automatically omitted from
|
||||
** static links that do not use it.
|
||||
**
|
||||
** $Id: complete.c,v 1.1 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#ifndef SQLITE_OMIT_COMPLETE
|
||||
|
||||
/*
|
||||
** This is defined in tokenize.c. We just have to import the definition.
|
||||
*/
|
||||
extern const char sqlite3IsIdChar[];
|
||||
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
|
||||
|
||||
|
||||
/*
|
||||
** Token types used by the sqlite3_complete() routine. See the header
|
||||
** comments on that procedure for additional information.
|
||||
*/
|
||||
#define tkSEMI 0
|
||||
#define tkWS 1
|
||||
#define tkOTHER 2
|
||||
#define tkEXPLAIN 3
|
||||
#define tkCREATE 4
|
||||
#define tkTEMP 5
|
||||
#define tkTRIGGER 6
|
||||
#define tkEND 7
|
||||
|
||||
/*
|
||||
** Return TRUE if the given SQL string ends in a semicolon.
|
||||
**
|
||||
** Special handling is require for CREATE TRIGGER statements.
|
||||
** Whenever the CREATE TRIGGER keywords are seen, the statement
|
||||
** must end with ";END;".
|
||||
**
|
||||
** This implementation uses a state machine with 7 states:
|
||||
**
|
||||
** (0) START At the beginning or end of an SQL statement. This routine
|
||||
** returns 1 if it ends in the START state and 0 if it ends
|
||||
** in any other state.
|
||||
**
|
||||
** (1) NORMAL We are in the middle of statement which ends with a single
|
||||
** semicolon.
|
||||
**
|
||||
** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
|
||||
** a statement.
|
||||
**
|
||||
** (3) CREATE The keyword CREATE has been seen at the beginning of a
|
||||
** statement, possibly preceeded by EXPLAIN and/or followed by
|
||||
** TEMP or TEMPORARY
|
||||
**
|
||||
** (4) TRIGGER We are in the middle of a trigger definition that must be
|
||||
** ended by a semicolon, the keyword END, and another semicolon.
|
||||
**
|
||||
** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
|
||||
** the end of a trigger definition.
|
||||
**
|
||||
** (6) END We've seen the ";END" of the ";END;" that occurs at the end
|
||||
** of a trigger difinition.
|
||||
**
|
||||
** Transitions between states above are determined by tokens extracted
|
||||
** from the input. The following tokens are significant:
|
||||
**
|
||||
** (0) tkSEMI A semicolon.
|
||||
** (1) tkWS Whitespace
|
||||
** (2) tkOTHER Any other SQL token.
|
||||
** (3) tkEXPLAIN The "explain" keyword.
|
||||
** (4) tkCREATE The "create" keyword.
|
||||
** (5) tkTEMP The "temp" or "temporary" keyword.
|
||||
** (6) tkTRIGGER The "trigger" keyword.
|
||||
** (7) tkEND The "end" keyword.
|
||||
**
|
||||
** Whitespace never causes a state transition and is always ignored.
|
||||
**
|
||||
** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
|
||||
** to recognize the end of a trigger can be omitted. All we have to do
|
||||
** is look for a semicolon that is not part of an string or comment.
|
||||
*/
|
||||
int sqlite3_complete(const char *zSql){
|
||||
u8 state = 0; /* Current state, using numbers defined in header comment */
|
||||
u8 token; /* Value of the next token */
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* A complex statement machine used to detect the end of a CREATE TRIGGER
|
||||
** statement. This is the normal case.
|
||||
*/
|
||||
static const u8 trans[7][8] = {
|
||||
/* Token: */
|
||||
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
|
||||
/* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, },
|
||||
/* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, },
|
||||
/* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, },
|
||||
/* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, },
|
||||
/* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, },
|
||||
/* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, },
|
||||
/* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, },
|
||||
};
|
||||
#else
|
||||
/* If triggers are not suppored by this compile then the statement machine
|
||||
** used to detect the end of a statement is much simplier
|
||||
*/
|
||||
static const u8 trans[2][3] = {
|
||||
/* Token: */
|
||||
/* State: ** SEMI WS OTHER */
|
||||
/* 0 START: */ { 0, 0, 1, },
|
||||
/* 1 NORMAL: */ { 0, 1, 1, },
|
||||
};
|
||||
#endif /* SQLITE_OMIT_TRIGGER */
|
||||
|
||||
while( *zSql ){
|
||||
switch( *zSql ){
|
||||
case ';': { /* A semicolon */
|
||||
token = tkSEMI;
|
||||
break;
|
||||
}
|
||||
case ' ':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\f': { /* White space is ignored */
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '/': { /* C-style comments */
|
||||
if( zSql[1]!='*' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
zSql += 2;
|
||||
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
|
||||
if( zSql[0]==0 ) return 0;
|
||||
zSql++;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '-': { /* SQL-style comments from "--" to end of line */
|
||||
if( zSql[1]!='-' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
while( *zSql && *zSql!='\n' ){ zSql++; }
|
||||
if( *zSql==0 ) return state==0;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '[': { /* Microsoft-style identifiers in [...] */
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=']' ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
case '`': /* Grave-accent quoted symbols used by MySQL */
|
||||
case '"': /* single- and double-quoted strings */
|
||||
case '\'': {
|
||||
int c = *zSql;
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=c ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
int c;
|
||||
if( IdChar((u8)*zSql) ){
|
||||
/* Keywords and unquoted identifiers */
|
||||
int nId;
|
||||
for(nId=1; IdChar(zSql[nId]); nId++){}
|
||||
#ifdef SQLITE_OMIT_TRIGGER
|
||||
token = tkOTHER;
|
||||
#else
|
||||
switch( *zSql ){
|
||||
case 'c': case 'C': {
|
||||
if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
|
||||
token = tkCREATE;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't': case 'T': {
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
|
||||
token = tkTRIGGER;
|
||||
}else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
|
||||
token = tkTEMP;
|
||||
}else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
|
||||
token = tkTEMP;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': {
|
||||
if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
|
||||
token = tkEND;
|
||||
}else
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
|
||||
token = tkEXPLAIN;
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_OMIT_TRIGGER */
|
||||
zSql += nId-1;
|
||||
}else{
|
||||
/* Operators and special symbols */
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = trans[state][token];
|
||||
zSql++;
|
||||
}
|
||||
return state==0;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** This routine is the same as the sqlite3_complete() routine described
|
||||
** above, except that the parameter is required to be UTF-16 encoded, not
|
||||
** UTF-8.
|
||||
*/
|
||||
int sqlite3_complete16(const void *zSql){
|
||||
sqlite3_value *pVal;
|
||||
char const *zSql8;
|
||||
int rc = 0;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_complete(zSql8);
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
return sqlite3ApiExit(0, rc);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
#endif /* SQLITE_OMIT_COMPLETE */
|
||||
@@ -16,7 +16,7 @@
|
||||
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.3 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: date.c,v 1.4 2006-02-16 10:11:46 jmiltner Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
@@ -105,18 +105,20 @@ static int getDigits(const char *zDate, ...){
|
||||
val = 0;
|
||||
while( N-- ){
|
||||
if( !isdigit(*(u8*)zDate) ){
|
||||
return cnt;
|
||||
goto end_getDigits;
|
||||
}
|
||||
val = val*10 + *zDate - '0';
|
||||
zDate++;
|
||||
}
|
||||
if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){
|
||||
return cnt;
|
||||
goto end_getDigits;
|
||||
}
|
||||
*pVal = val;
|
||||
zDate++;
|
||||
cnt++;
|
||||
}while( nextC );
|
||||
end_getDigits:
|
||||
va_end(ap);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -124,11 +126,7 @@ static int getDigits(const char *zDate, ...){
|
||||
** Read text from z[] and convert into a floating point number. Return
|
||||
** the number of digits converted.
|
||||
*/
|
||||
static int getValue(const char *z, double *pR){
|
||||
const char *zEnd;
|
||||
*pR = sqlite3AtoF(z, &zEnd);
|
||||
return zEnd - z;
|
||||
}
|
||||
#define getValue sqlite3AtoF
|
||||
|
||||
/*
|
||||
** Parse a timezone extension on the end of a date-time.
|
||||
@@ -240,7 +238,7 @@ static void computeJD(DateTime *p){
|
||||
if( p->validHMS ){
|
||||
p->rJD += (p->h*3600.0 + p->m*60.0 + p->s)/86400.0;
|
||||
if( p->validTZ ){
|
||||
p->rJD += p->tz*60/86400.0;
|
||||
p->rJD -= p->tz*60/86400.0;
|
||||
p->validHMS = 0;
|
||||
p->validTZ = 0;
|
||||
}
|
||||
@@ -320,7 +318,7 @@ static int parseDateOrTime(const char *zDate, DateTime *p){
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){
|
||||
p->rJD = sqlite3AtoF(zDate, 0);
|
||||
getValue(zDate, &p->rJD);
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -643,10 +641,10 @@ static int isDate(int argc, sqlite3_value **argv, DateTime *p){
|
||||
int i;
|
||||
if( argc==0 ) return 1;
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ||
|
||||
parseDateOrTime(sqlite3_value_text(argv[0]), p) ) return 1;
|
||||
parseDateOrTime((char*)sqlite3_value_text(argv[0]), p) ) return 1;
|
||||
for(i=1; i<argc; i++){
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[i]) ||
|
||||
parseModifier(sqlite3_value_text(argv[i]), p) ) return 1;
|
||||
parseModifier((char*)sqlite3_value_text(argv[i]), p) ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -759,7 +757,7 @@ static void strftimeFunc(
|
||||
DateTime x;
|
||||
int n, i, j;
|
||||
char *z;
|
||||
const char *zFmt = sqlite3_value_text(argv[0]);
|
||||
const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
|
||||
char zBuf[100];
|
||||
if( zFmt==0 || isDate(argc-1, argv+1, &x) ) return;
|
||||
for(i=0, n=1; zFmt[i]; i++, n++){
|
||||
@@ -820,20 +818,20 @@ static void strftimeFunc(
|
||||
case 'H': sprintf(&z[j],"%02d",x.h); j+=2; break;
|
||||
case 'W': /* Fall thru */
|
||||
case 'j': {
|
||||
int n; /* Number of days since 1st day of year */
|
||||
int nDay; /* Number of days since 1st day of year */
|
||||
DateTime y = x;
|
||||
y.validJD = 0;
|
||||
y.M = 1;
|
||||
y.D = 1;
|
||||
computeJD(&y);
|
||||
n = x.rJD - y.rJD;
|
||||
nDay = x.rJD - y.rJD;
|
||||
if( zFmt[i]=='W' ){
|
||||
int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
|
||||
wd = ((int)(x.rJD+0.5)) % 7;
|
||||
sprintf(&z[j],"%02d",(n+7-wd)/7);
|
||||
sprintf(&z[j],"%02d",(nDay+7-wd)/7);
|
||||
j += 2;
|
||||
}else{
|
||||
sprintf(&z[j],"%03d",n+1);
|
||||
sprintf(&z[j],"%03d",nDay+1);
|
||||
j += 3;
|
||||
}
|
||||
break;
|
||||
@@ -978,7 +976,7 @@ void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
sqlite3CreateFunc(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
|
||||
}
|
||||
#else
|
||||
@@ -993,7 +991,7 @@ void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, 0, SQLITE_UTF8,
|
||||
sqlite3CreateFunc(db, aFuncs[i].zName, 0, SQLITE_UTF8,
|
||||
aFuncs[i].zFormat, currentTimeFunc, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** in order to generate code for DELETE FROM statements.
|
||||
**
|
||||
** $Id: delete.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: delete.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -27,7 +27,11 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
struct SrcList_item *pItem;
|
||||
for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
|
||||
pTab = sqlite3LocateTable(pParse, pItem->zName, pItem->zDatabase);
|
||||
sqlite3DeleteTable(pParse->db, pItem->pTab);
|
||||
pItem->pTab = pTab;
|
||||
if( pTab ){
|
||||
pTab->nRef++;
|
||||
}
|
||||
}
|
||||
return pTab;
|
||||
}
|
||||
@@ -55,14 +59,19 @@ int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
/*
|
||||
** Generate code that will open a table for reading.
|
||||
*/
|
||||
void sqlite3OpenTableForReading(
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
void sqlite3OpenTable(
|
||||
Parse *p, /* Generate code into this VDBE */
|
||||
int iCur, /* The cursor number of the table */
|
||||
Table *pTab /* The table to be opened */
|
||||
int iDb, /* The database index in sqlite3.aDb[] */
|
||||
Table *pTab, /* The table to be opened */
|
||||
int opcode /* OP_OpenRead or OP_OpenWrite */
|
||||
){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
Vdbe *v = sqlite3GetVdbe(p);
|
||||
assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
|
||||
sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite), pTab->zName);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
VdbeComment((v, "# %s", pTab->zName));
|
||||
sqlite3VdbeAddOp(v, opcode, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
}
|
||||
|
||||
@@ -91,6 +100,7 @@ void sqlite3DeleteFrom(
|
||||
AuthContext sContext; /* Authorization context */
|
||||
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
|
||||
NameContext sNC; /* Name context to resolve expressions in */
|
||||
int iDb;
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to delete from a view */
|
||||
@@ -98,7 +108,7 @@ void sqlite3DeleteFrom(
|
||||
#endif
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite3_malloc_failed ){
|
||||
if( pParse->nErr || sqlite3MallocFailed() ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
db = pParse->db;
|
||||
@@ -130,8 +140,9 @@ void sqlite3DeleteFrom(
|
||||
if( sqlite3IsReadOnly(pParse, pTab, triggers_exist) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb<db->nDb );
|
||||
zDb = db->aDb[iDb].zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
@@ -172,14 +183,14 @@ void sqlite3DeleteFrom(
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb);
|
||||
sqlite3BeginWriteOperation(pParse, triggers_exist, iDb);
|
||||
|
||||
/* If we are trying to delete from a view, construct that view into
|
||||
** a temporary table.
|
||||
/* If we are trying to delete from a view, realize that view into
|
||||
** a ephemeral table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
|
||||
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
}
|
||||
|
||||
@@ -199,20 +210,24 @@ void sqlite3DeleteFrom(
|
||||
/* If counting rows deleted, just count the total number of
|
||||
** entries in the table. */
|
||||
int endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
int addr;
|
||||
int addr2;
|
||||
if( !isView ){
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
|
||||
addr = sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iCur, addr);
|
||||
addr2 = sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iCur, addr2);
|
||||
sqlite3VdbeResolveLabel(v, endOfLoop);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pTab->tnum, iDb);
|
||||
if( !pParse->nested ){
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
||||
}
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pIdx->tnum, iDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,13 +236,6 @@ void sqlite3DeleteFrom(
|
||||
** the table and pick which records to delete.
|
||||
*/
|
||||
else{
|
||||
/* Ensure all required collation sequences are available. */
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
|
||||
@@ -235,8 +243,8 @@ void sqlite3DeleteFrom(
|
||||
|
||||
/* Remember the rowid of every item to be deleted.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
}
|
||||
@@ -256,22 +264,21 @@ void sqlite3DeleteFrom(
|
||||
** database scan. We have to delete items after the scan is complete
|
||||
** because deleting an item can change the scan order.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
end = sqlite3VdbeMakeLabel(v);
|
||||
|
||||
/* This is the beginning of the delete loop when there are
|
||||
** row triggers.
|
||||
*/
|
||||
if( triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
@@ -284,7 +291,7 @@ void sqlite3DeleteFrom(
|
||||
if( !isView ){
|
||||
/* Open cursors for the table we are deleting from and all its
|
||||
** indices. If there are row triggers, this happens inside the
|
||||
** OP_ListRead loop because the cursor have to all be closed
|
||||
** OP_FifoRead loop because the cursor have to all be closed
|
||||
** before the trigger fires. If there are no row triggers, the
|
||||
** cursors are opened only once on the outside the loop.
|
||||
*/
|
||||
@@ -293,7 +300,7 @@ void sqlite3DeleteFrom(
|
||||
/* This is the beginning of the delete loop when there are no
|
||||
** row triggers */
|
||||
if( !triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
|
||||
}
|
||||
|
||||
/* Delete the row */
|
||||
@@ -318,7 +325,6 @@ void sqlite3DeleteFrom(
|
||||
/* End of the delete loop */
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqlite3VdbeResolveLabel(v, end);
|
||||
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
|
||||
/* Close the cursors after the loop if there are no row triggers */
|
||||
if( !triggers_exist ){
|
||||
@@ -337,7 +343,7 @@ void sqlite3DeleteFrom(
|
||||
if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows deleted", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", P3_STATIC);
|
||||
}
|
||||
|
||||
delete_from_cleanup:
|
||||
@@ -378,7 +384,10 @@ void sqlite3GenerateRowDelete(
|
||||
addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
if( count ){
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -428,7 +437,7 @@ void sqlite3GenerateIndexKey(
|
||||
int j;
|
||||
Table *pTab = pIdx->pTable;
|
||||
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
int idx = pIdx->aiColumn[j];
|
||||
if( idx==pTab->iPKey ){
|
||||
@@ -438,6 +447,6 @@ void sqlite3GenerateIndexKey(
|
||||
sqlite3ColumnDefault(v, pTab, idx);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
|
||||
sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
** This file contains C code routines that are not a part of the official
|
||||
** SQLite API. These routines are unsupported.
|
||||
**
|
||||
** $Id: experimental.c,v 1.2 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: experimental.c,v 1.3 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** Set all the parameters in the compiled SQL statement to NULL.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,16 +16,19 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: func.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
/* #include <math.h> */
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** Return the collating function associated with a function.
|
||||
*/
|
||||
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
|
||||
return context->pColl;
|
||||
}
|
||||
@@ -78,6 +81,7 @@ static void typeofFunc(
|
||||
sqlite3_result_text(context, z, -1, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Implementation of the length() function
|
||||
*/
|
||||
@@ -97,7 +101,7 @@ static void lengthFunc(
|
||||
break;
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
const char *z = sqlite3_value_text(argv[0]);
|
||||
const unsigned char *z = sqlite3_value_text(argv[0]);
|
||||
for(len=0; *z; z++){ if( (0xc0&*z)!=0x80 ) len++; }
|
||||
sqlite3_result_int(context, len);
|
||||
break;
|
||||
@@ -142,8 +146,8 @@ static void substrFunc(
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *z;
|
||||
const char *z2;
|
||||
const unsigned char *z;
|
||||
const unsigned char *z2;
|
||||
int i;
|
||||
int p1, p2, len;
|
||||
|
||||
@@ -174,7 +178,7 @@ static void substrFunc(
|
||||
}
|
||||
while( z[i] && (z[i]&0xc0)==0x80 ){ i++; p2++; }
|
||||
if( p2<0 ) p2 = 0;
|
||||
sqlite3_result_text(context, &z[p1], p2, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, (char*)&z[p1], p2, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -183,7 +187,7 @@ static void substrFunc(
|
||||
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
int n = 0;
|
||||
double r;
|
||||
char zBuf[100];
|
||||
char zBuf[500]; /* larger than the %f representation of the largest double */
|
||||
assert( argc==1 || argc==2 );
|
||||
if( argc==2 ){
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
|
||||
@@ -193,7 +197,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
}
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
|
||||
r = sqlite3_value_double(argv[0]);
|
||||
sprintf(zBuf,"%.*f",n,r);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
@@ -206,11 +210,11 @@ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
|
||||
z = sqliteMalloc(sqlite3_value_bytes(argv[0])+1);
|
||||
if( z==0 ) return;
|
||||
strcpy(z, sqlite3_value_text(argv[0]));
|
||||
strcpy((char*)z, (char*)sqlite3_value_text(argv[0]));
|
||||
for(i=0; z[i]; i++){
|
||||
z[i] = toupper(z[i]);
|
||||
}
|
||||
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, (char*)z, -1, SQLITE_TRANSIENT);
|
||||
sqliteFree(z);
|
||||
}
|
||||
static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
@@ -219,11 +223,11 @@ static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
|
||||
z = sqliteMalloc(sqlite3_value_bytes(argv[0])+1);
|
||||
if( z==0 ) return;
|
||||
strcpy(z, sqlite3_value_text(argv[0]));
|
||||
strcpy((char*)z, (char*)sqlite3_value_text(argv[0]));
|
||||
for(i=0; z[i]; i++){
|
||||
z[i] = tolower(z[i]);
|
||||
}
|
||||
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, (char*)z, -1, SQLITE_TRANSIENT);
|
||||
sqliteFree(z);
|
||||
}
|
||||
|
||||
@@ -307,8 +311,14 @@ struct compareInfo {
|
||||
u8 matchSet;
|
||||
u8 noCase;
|
||||
};
|
||||
|
||||
static const struct compareInfo globInfo = { '*', '?', '[', 0 };
|
||||
static const struct compareInfo likeInfo = { '%', '_', 0, 1 };
|
||||
/* The correct SQL-92 behavior is for the LIKE operator to ignore
|
||||
** case. Thus 'a' LIKE 'A' would be true. */
|
||||
static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 };
|
||||
/* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
|
||||
** is case sensitive causing 'a' LIKE 'A' to be false */
|
||||
static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
|
||||
|
||||
/*
|
||||
** X is a pointer to the first byte of a UTF-8 character. Increment
|
||||
@@ -450,6 +460,15 @@ static int patternCompare(
|
||||
return *zString==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Count the number of times that the LIKE operator (or GLOB which is
|
||||
** just a variation of LIKE) gets called. This is used for testing
|
||||
** only.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_like_count = 0;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Implementation of the like() SQL function. This function implements
|
||||
@@ -460,8 +479,8 @@ static int patternCompare(
|
||||
**
|
||||
** is implemented as like(B,A).
|
||||
**
|
||||
** If the pointer retrieved by via a call to sqlite3_user_data() is
|
||||
** not NULL, then this function uses UTF-16. Otherwise UTF-8.
|
||||
** This same function (with a different compareInfo structure) computes
|
||||
** the GLOB operator.
|
||||
*/
|
||||
static void likeFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -476,7 +495,7 @@ static void likeFunc(
|
||||
** Otherwise, return an error.
|
||||
*/
|
||||
const unsigned char *zEsc = sqlite3_value_text(argv[2]);
|
||||
if( sqlite3utf8CharLen(zEsc, -1)!=1 ){
|
||||
if( sqlite3utf8CharLen((char*)zEsc, -1)!=1 ){
|
||||
sqlite3_result_error(context,
|
||||
"ESCAPE expression must be a single character", -1);
|
||||
return;
|
||||
@@ -484,24 +503,11 @@ static void likeFunc(
|
||||
escape = sqlite3ReadUtf8(zEsc);
|
||||
}
|
||||
if( zA && zB ){
|
||||
sqlite3_result_int(context, patternCompare(zA, zB, &likeInfo, escape));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the glob() SQL function. This function implements
|
||||
** the build-in GLOB operator. The first argument to the function is the
|
||||
** string and the second argument is the pattern. So, the SQL statements:
|
||||
**
|
||||
** A GLOB B
|
||||
**
|
||||
** is implemented as glob(B,A).
|
||||
*/
|
||||
static void globFunc(sqlite3_context *context, int arg, sqlite3_value **argv){
|
||||
const unsigned char *zA = sqlite3_value_text(argv[0]);
|
||||
const unsigned char *zB = sqlite3_value_text(argv[1]);
|
||||
if( zA && zB ){
|
||||
sqlite3_result_int(context, patternCompare(zA, zB, &globInfo, 0));
|
||||
struct compareInfo *pInfo = sqlite3_user_data(context);
|
||||
#ifdef SQLITE_TEST
|
||||
sqlite3_like_count++;
|
||||
#endif
|
||||
sqlite3_result_int(context, patternCompare(zA, zB, pInfo, escape));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,7 +592,7 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
int i,j,n;
|
||||
const char *zArg = sqlite3_value_text(argv[0]);
|
||||
const unsigned char *zArg = sqlite3_value_text(argv[0]);
|
||||
char *z;
|
||||
|
||||
for(i=n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; }
|
||||
@@ -686,7 +692,7 @@ static void randStr(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
sqlite3_result_text(context, zBuf, n, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, (char*)zBuf, n, SQLITE_TRANSIENT);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
@@ -722,17 +728,17 @@ static void test_destructor(
|
||||
test_destructor_count_var++;
|
||||
assert( nArg==1 );
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
len = sqlite3ValueBytes(argv[0], db->enc);
|
||||
len = sqlite3ValueBytes(argv[0], ENC(db));
|
||||
zVal = sqliteMalloc(len+3);
|
||||
zVal[len] = 0;
|
||||
zVal[len-1] = 0;
|
||||
assert( zVal );
|
||||
zVal++;
|
||||
memcpy(zVal, sqlite3ValueText(argv[0], db->enc), len);
|
||||
if( db->enc==SQLITE_UTF8 ){
|
||||
memcpy(zVal, sqlite3ValueText(argv[0], ENC(db)), len);
|
||||
if( ENC(db)==SQLITE_UTF8 ){
|
||||
sqlite3_result_text(pCtx, zVal, -1, destructor);
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
}else if( db->enc==SQLITE_UTF16LE ){
|
||||
}else if( ENC(db)==SQLITE_UTF16LE ){
|
||||
sqlite3_result_text16le(pCtx, zVal, -1, destructor);
|
||||
}else{
|
||||
sqlite3_result_text16be(pCtx, zVal, -1, destructor);
|
||||
@@ -770,7 +776,7 @@ static void test_auxdata(
|
||||
char *zRet = sqliteMalloc(nArg*2);
|
||||
if( !zRet ) return;
|
||||
for(i=0; i<nArg; i++){
|
||||
char const *z = sqlite3_value_text(argv[i]);
|
||||
char const *z = (char*)sqlite3_value_text(argv[i]);
|
||||
if( z ){
|
||||
char *zAux = sqlite3_get_auxdata(pCtx, i);
|
||||
if( zAux ){
|
||||
@@ -801,7 +807,7 @@ static void test_error(
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_result_error(pCtx, sqlite3_value_text(argv[0]), 0);
|
||||
sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), 0);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
@@ -811,45 +817,72 @@ static void test_error(
|
||||
*/
|
||||
typedef struct SumCtx SumCtx;
|
||||
struct SumCtx {
|
||||
double sum; /* Sum of terms */
|
||||
int cnt; /* Number of elements summed */
|
||||
LONGDOUBLE_TYPE sum; /* Sum of terms */
|
||||
i64 cnt; /* Number of elements summed */
|
||||
u8 approx; /* True if sum is approximate */
|
||||
};
|
||||
|
||||
/*
|
||||
** Routines used to compute the sum or average.
|
||||
** Routines used to compute the sum, average, and total.
|
||||
**
|
||||
** The SUM() function follows the (broken) SQL standard which means
|
||||
** that it returns NULL if it sums over no inputs. TOTAL returns
|
||||
** 0.0 in that case. In addition, TOTAL always returns a float where
|
||||
** SUM might return an integer if it never encounters a floating point
|
||||
** value.
|
||||
**
|
||||
** I am told that SUM() should raise an exception if it encounters
|
||||
** a integer overflow. But after pondering this, I decided that
|
||||
** behavior leads to brittle programs. So instead, I have coded
|
||||
** SUM() to revert to using floating point if it encounters an
|
||||
** integer overflow. The answer may not be exact, but it will be
|
||||
** close. If the SUM() function returns an integer, the value is
|
||||
** exact. If SUM() returns a floating point value, it means the
|
||||
** value might be approximated.
|
||||
*/
|
||||
static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
SumCtx *p;
|
||||
if( argc<1 ) return;
|
||||
int type;
|
||||
assert( argc==1 );
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p && SQLITE_NULL!=sqlite3_value_type(argv[0]) ){
|
||||
p->sum += sqlite3_value_double(argv[0]);
|
||||
type = sqlite3_value_numeric_type(argv[0]);
|
||||
if( p && type!=SQLITE_NULL ){
|
||||
p->cnt++;
|
||||
if( type==SQLITE_INTEGER ){
|
||||
p->sum += sqlite3_value_int64(argv[0]);
|
||||
if( !p->approx ){
|
||||
i64 iVal;
|
||||
p->approx = p->sum!=(LONGDOUBLE_TYPE)(iVal = (i64)p->sum);
|
||||
}
|
||||
}else{
|
||||
p->sum += sqlite3_value_double(argv[0]);
|
||||
p->approx = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void sumFinalize(sqlite3_context *context){
|
||||
SumCtx *p;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
sqlite3_result_double(context, p ? p->sum : 0.0);
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
if( p && p->cnt>0 ){
|
||||
if( p->approx ){
|
||||
sqlite3_result_double(context, p->sum);
|
||||
}else{
|
||||
sqlite3_result_int64(context, (i64)p->sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void avgFinalize(sqlite3_context *context){
|
||||
SumCtx *p;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
if( p && p->cnt>0 ){
|
||||
sqlite3_result_double(context, p->sum/(double)p->cnt);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** An instance of the following structure holds the context of a
|
||||
** variance or standard deviation computation.
|
||||
*/
|
||||
typedef struct StdDevCtx StdDevCtx;
|
||||
struct StdDevCtx {
|
||||
double sum; /* Sum of terms */
|
||||
double sum2; /* Sum of the squares of terms */
|
||||
int cnt; /* Number of terms counted */
|
||||
};
|
||||
static void totalFinalize(sqlite3_context *context){
|
||||
SumCtx *p;
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
sqlite3_result_double(context, p ? p->sum : 0.0);
|
||||
}
|
||||
|
||||
/*
|
||||
** The following structure keeps track of state information for the
|
||||
@@ -857,7 +890,7 @@ struct StdDevCtx {
|
||||
*/
|
||||
typedef struct CountCtx CountCtx;
|
||||
struct CountCtx {
|
||||
int n;
|
||||
i64 n;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -872,20 +905,10 @@ static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
}
|
||||
static void countFinalize(sqlite3_context *context){
|
||||
CountCtx *p;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
sqlite3_result_int(context, p ? p->n : 0);
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
sqlite3_result_int64(context, p ? p->n : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** This function tracks state information for the min() and max()
|
||||
** aggregate functions.
|
||||
*/
|
||||
typedef struct MinMaxCtx MinMaxCtx;
|
||||
struct MinMaxCtx {
|
||||
char *z; /* The best so far */
|
||||
char zBuf[28]; /* Space that can be used for storage */
|
||||
};
|
||||
|
||||
/*
|
||||
** Routines to implement min() and max() aggregate functions.
|
||||
*/
|
||||
@@ -920,11 +943,13 @@ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv)
|
||||
}
|
||||
static void minMaxFinalize(sqlite3_context *context){
|
||||
sqlite3_value *pRes;
|
||||
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, sizeof(Mem));
|
||||
if( pRes->flags ){
|
||||
sqlite3_result_value(context, pRes);
|
||||
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
|
||||
if( pRes ){
|
||||
if( pRes->flags ){
|
||||
sqlite3_result_value(context, pRes);
|
||||
}
|
||||
sqlite3VdbeMemRelease(pRes);
|
||||
}
|
||||
sqlite3VdbeMemRelease(pRes);
|
||||
}
|
||||
|
||||
|
||||
@@ -962,9 +987,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
{ "coalesce", 1, 0, SQLITE_UTF8, 0, 0 },
|
||||
{ "ifnull", 2, 0, SQLITE_UTF8, 1, ifnullFunc },
|
||||
{ "random", -1, 0, SQLITE_UTF8, 0, randomFunc },
|
||||
{ "like", 2, 0, SQLITE_UTF8, 0, likeFunc },
|
||||
{ "like", 3, 0, SQLITE_UTF8, 0, likeFunc },
|
||||
{ "glob", 2, 0, SQLITE_UTF8, 0, globFunc },
|
||||
{ "nullif", 2, 0, SQLITE_UTF8, 1, nullifFunc },
|
||||
{ "sqlite_version", 0, 0, SQLITE_UTF8, 0, versionFunc},
|
||||
{ "quote", 1, 0, SQLITE_UTF8, 0, quoteFunc },
|
||||
@@ -993,6 +1015,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
{ "min", 1, 0, 1, minmaxStep, minMaxFinalize },
|
||||
{ "max", 1, 2, 1, minmaxStep, minMaxFinalize },
|
||||
{ "sum", 1, 0, 0, sumStep, sumFinalize },
|
||||
{ "total", 1, 0, 0, sumStep, totalFinalize },
|
||||
{ "avg", 1, 0, 0, sumStep, avgFinalize },
|
||||
{ "count", 0, 0, 0, countStep, countFinalize },
|
||||
{ "count", 1, 0, 0, countStep, countFinalize },
|
||||
@@ -1005,7 +1028,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
case 1: pArg = db; break;
|
||||
case 2: pArg = (void *)(-1); break;
|
||||
}
|
||||
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
sqlite3CreateFunc(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
aFuncs[i].eTextRep, pArg, aFuncs[i].xFunc, 0, 0);
|
||||
if( aFuncs[i].needCollSeq ){
|
||||
FuncDef *pFunc = sqlite3FindFunction(db, aFuncs[i].zName,
|
||||
@@ -1017,6 +1040,9 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
}
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
sqlite3AlterFunctions(db);
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_PARSER
|
||||
sqlite3AttachFunctions(db);
|
||||
#endif
|
||||
for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
|
||||
void *pArg = 0;
|
||||
@@ -1024,7 +1050,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
case 1: pArg = db; break;
|
||||
case 2: pArg = (void *)(-1); break;
|
||||
}
|
||||
sqlite3_create_function(db, aAggs[i].zName, aAggs[i].nArg, SQLITE_UTF8,
|
||||
sqlite3CreateFunc(db, aAggs[i].zName, aAggs[i].nArg, SQLITE_UTF8,
|
||||
pArg, 0, aAggs[i].xStep, aAggs[i].xFinalize);
|
||||
if( aAggs[i].needCollSeq ){
|
||||
FuncDef *pFunc = sqlite3FindFunction( db, aAggs[i].zName,
|
||||
@@ -1035,4 +1061,77 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
}
|
||||
}
|
||||
sqlite3RegisterDateTimeFunctions(db);
|
||||
#ifdef SQLITE_SSE
|
||||
sqlite3SseFunctions(db);
|
||||
#endif
|
||||
#ifdef SQLITE_CASE_SENSITIVE_LIKE
|
||||
sqlite3RegisterLikeFunctions(db, 1);
|
||||
#else
|
||||
sqlite3RegisterLikeFunctions(db, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the LIKEOPT flag on the 2-argument function with the given name.
|
||||
*/
|
||||
static void setLikeOptFlag(sqlite3 *db, const char *zName, int flagVal){
|
||||
FuncDef *pDef;
|
||||
pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0);
|
||||
if( pDef ){
|
||||
pDef->flags = flagVal;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Register the built-in LIKE and GLOB functions. The caseSensitive
|
||||
** parameter determines whether or not the LIKE operator is case
|
||||
** sensitive. GLOB is always case sensitive.
|
||||
*/
|
||||
void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
|
||||
struct compareInfo *pInfo;
|
||||
if( caseSensitive ){
|
||||
pInfo = (struct compareInfo*)&likeInfoAlt;
|
||||
}else{
|
||||
pInfo = (struct compareInfo*)&likeInfoNorm;
|
||||
}
|
||||
sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
|
||||
sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
|
||||
sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
|
||||
(struct compareInfo*)&globInfo, likeFunc, 0,0);
|
||||
setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
|
||||
setLikeOptFlag(db, "like",
|
||||
caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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
|
||||
** return TRUE. If the function is not a LIKE-style function then
|
||||
** return FALSE.
|
||||
*/
|
||||
int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
FuncDef *pDef;
|
||||
if( pExpr->op!=TK_FUNCTION ){
|
||||
return 0;
|
||||
}
|
||||
if( pExpr->pList->nExpr!=2 ){
|
||||
return 0;
|
||||
}
|
||||
pDef = sqlite3FindFunction(db, (char*)pExpr->token.z, pExpr->token.n, 2,
|
||||
SQLITE_UTF8, 0);
|
||||
if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The memcpy() statement assumes that the wildcard characters are
|
||||
** the first three statements in the compareInfo structure. The
|
||||
** asserts() that follow verify that assumption
|
||||
*/
|
||||
memcpy(aWc, pDef->pUserData, 3);
|
||||
assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
|
||||
assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
|
||||
assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
|
||||
*pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This is the implementation of generic hash-tables
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: hash.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
@@ -294,6 +294,11 @@ static void removeElementGivenHash(
|
||||
}
|
||||
sqliteFree( elem );
|
||||
pH->count--;
|
||||
if( pH->count<=0 ){
|
||||
assert( pH->first==0 );
|
||||
assert( pH->count==0 );
|
||||
sqlite3HashClear(pH);
|
||||
}
|
||||
}
|
||||
|
||||
/* Attempt to locate an element of the hash table pH with a key
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This is the header file for the generic hash-table implemenation
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.h,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: hash.h,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_HASH_H_
|
||||
#define _SQLITE_HASH_H_
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle INSERT statements in SQLite.
|
||||
**
|
||||
** $Id: insert.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: insert.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
**
|
||||
** Character Column affinity
|
||||
** ------------------------------
|
||||
** 'n' NUMERIC
|
||||
** 'i' INTEGER
|
||||
** 't' TEXT
|
||||
** 'o' NONE
|
||||
** 'a' TEXT
|
||||
** 'b' NONE
|
||||
** 'c' NUMERIC
|
||||
** 'd' INTEGER
|
||||
** 'e' REAL
|
||||
*/
|
||||
void sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
|
||||
if( !pIdx->zColAff ){
|
||||
@@ -61,10 +62,11 @@ void sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
|
||||
**
|
||||
** Character Column affinity
|
||||
** ------------------------------
|
||||
** 'n' NUMERIC
|
||||
** 'i' INTEGER
|
||||
** 't' TEXT
|
||||
** 'o' NONE
|
||||
** 'a' TEXT
|
||||
** 'b' NONE
|
||||
** 'c' NUMERIC
|
||||
** 'd' INTEGER
|
||||
** 'e' REAL
|
||||
*/
|
||||
void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
|
||||
/* The first time a column affinity string for a particular table
|
||||
@@ -102,15 +104,15 @@ void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
|
||||
**
|
||||
** No checking is done for sub-selects that are part of expressions.
|
||||
*/
|
||||
static int selectReadsTable(Select *p, int iDb, int iTab){
|
||||
static int selectReadsTable(Select *p, Schema *pSchema, int iTab){
|
||||
int i;
|
||||
struct SrcList_item *pItem;
|
||||
if( p->pSrc==0 ) return 0;
|
||||
for(i=0, pItem=p->pSrc->a; i<p->pSrc->nSrc; i++, pItem++){
|
||||
if( pItem->pSelect ){
|
||||
if( selectReadsTable(pItem->pSelect, iDb, iTab) ) return 1;
|
||||
if( selectReadsTable(pItem->pSelect, pSchema, iTab) ) return 1;
|
||||
}else{
|
||||
if( pItem->pTab->iDb==iDb && pItem->pTab->tnum==iTab ) return 1;
|
||||
if( pItem->pTab->pSchema==pSchema && pItem->pTab->tnum==iTab ) return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -212,6 +214,7 @@ void sqlite3Insert(
|
||||
int newIdx = -1; /* Cursor for the NEW table */
|
||||
Db *pDb; /* The database containing table being inserted into */
|
||||
int counterMem = 0; /* Memory cell holding AUTOINCREMENT counter */
|
||||
int iDb;
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to insert into a view */
|
||||
@@ -219,10 +222,12 @@ void sqlite3Insert(
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
int counterRowid; /* Memory cell holding rowid of autoinc counter */
|
||||
int counterRowid = 0; /* Memory cell holding rowid of autoinc counter */
|
||||
#endif
|
||||
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
if( pParse->nErr || sqlite3MallocFailed() ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
db = pParse->db;
|
||||
|
||||
/* Locate the table into which we will be inserting new information.
|
||||
@@ -234,8 +239,9 @@ void sqlite3Insert(
|
||||
if( pTab==0 ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
assert( pTab->iDb<db->nDb );
|
||||
pDb = &db->aDb[pTab->iDb];
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb<db->nDb );
|
||||
pDb = &db->aDb[iDb];
|
||||
zDb = pDb->zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
|
||||
goto insert_cleanup;
|
||||
@@ -271,19 +277,12 @@ void sqlite3Insert(
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
/* Ensure all required collation sequences are available. */
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate a VDBE
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto insert_cleanup;
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, pSelect || triggers_exist, pTab->iDb);
|
||||
sqlite3BeginWriteOperation(pParse, pSelect || triggers_exist, iDb);
|
||||
|
||||
/* if there are row triggers, allocate a temp table for new.* references. */
|
||||
if( triggers_exist ){
|
||||
@@ -298,22 +297,20 @@ void sqlite3Insert(
|
||||
*/
|
||||
if( pTab->autoInc ){
|
||||
int iCur = pParse->nTab;
|
||||
int base = sqlite3VdbeCurrentAddr(v);
|
||||
int addr = sqlite3VdbeCurrentAddr(v);
|
||||
counterRowid = pParse->nMem++;
|
||||
counterMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pDb->pSeqTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, 2);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, base+13);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, addr+13);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 28417, base+12);
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 0x100, addr+12);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, counterRowid, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, counterMem, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, base+13);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iCur, base+4);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr+13);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iCur, addr+4);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTOINCREMENT */
|
||||
@@ -336,7 +333,9 @@ void sqlite3Insert(
|
||||
|
||||
/* Resolve the expressions in the SELECT statement and execute it. */
|
||||
rc = sqlite3Select(pParse, pSelect, SRT_Subroutine, iInsertBlock,0,0,0,0);
|
||||
if( rc || pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
if( rc || pParse->nErr || sqlite3MallocFailed() ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
iCleanup = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iCleanup);
|
||||
@@ -351,7 +350,7 @@ void sqlite3Insert(
|
||||
** of the tables being read by the SELECT statement. Also use a
|
||||
** temp table in the case of row triggers.
|
||||
*/
|
||||
if( triggers_exist || selectReadsTable(pSelect, pTab->iDb, pTab->tnum) ){
|
||||
if( triggers_exist || selectReadsTable(pSelect,pTab->pSchema,pTab->tnum) ){
|
||||
useTempTable = 1;
|
||||
}
|
||||
|
||||
@@ -362,23 +361,22 @@ void sqlite3Insert(
|
||||
srcTab = pParse->nTab++;
|
||||
sqlite3VdbeResolveLabel(v, iInsertBlock);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Return, 0, 0);
|
||||
|
||||
/* The following code runs first because the GOTO at the very top
|
||||
** of the program jumps to it. Create the temporary table, then jump
|
||||
** back up and execute the SELECT code above.
|
||||
*/
|
||||
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeAddOp(v, OP_OpenTemp, srcTab, 0);
|
||||
sqlite3VdbeJumpHere(v, iInitCode);
|
||||
sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqlite3VdbeResolveLabel(v, iCleanup);
|
||||
}else{
|
||||
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, iInitCode);
|
||||
}
|
||||
}else{
|
||||
/* This is the case if the data for the INSERT is coming from a VALUES
|
||||
@@ -470,8 +468,7 @@ void sqlite3Insert(
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
iCntMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iCntMem, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, iCntMem);
|
||||
}
|
||||
|
||||
/* Open tables and indices if there are no row triggers */
|
||||
@@ -547,7 +544,7 @@ void sqlite3Insert(
|
||||
if( !isView ){
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
|
||||
|
||||
/* Fire BEFORE or INSTEAD OF triggers */
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_BEFORE, pTab,
|
||||
@@ -565,7 +562,7 @@ void sqlite3Insert(
|
||||
}
|
||||
|
||||
/* Push the record number for the new entry onto the stack. The
|
||||
** record number is a randomly generate integer created by NewRecno
|
||||
** record number is a randomly generate integer created by NewRowid
|
||||
** except when the table has an INTEGER PRIMARY KEY column, in which
|
||||
** case the record number is the same as that column.
|
||||
*/
|
||||
@@ -578,15 +575,15 @@ void sqlite3Insert(
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
}
|
||||
/* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
|
||||
/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
|
||||
** to generate a unique primary key value.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, base, counterMem);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, base, counterMem);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
if( pTab->autoInc ){
|
||||
@@ -603,7 +600,7 @@ void sqlite3Insert(
|
||||
** Whenever this column is read, the record number will be substituted
|
||||
** in its place. So will fill this column with a NULL to avoid
|
||||
** taking up data space with information that will never be used. */
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
if( pColumn==0 ){
|
||||
@@ -636,7 +633,7 @@ void sqlite3Insert(
|
||||
/* Update the count of rows that are inserted
|
||||
*/
|
||||
if( (db->flags & SQLITE_CountRows)!=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, iCntMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, iCntMem);
|
||||
}
|
||||
|
||||
if( triggers_exist ){
|
||||
@@ -683,18 +680,16 @@ void sqlite3Insert(
|
||||
*/
|
||||
if( pTab->autoInc ){
|
||||
int iCur = pParse->nTab;
|
||||
int base = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pDb->pSeqTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, 2);
|
||||
int addr = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, counterRowid, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, base+7);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, addr+7);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, iCur, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, counterMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, 2, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
#endif
|
||||
@@ -708,7 +703,7 @@ void sqlite3Insert(
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iCntMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows inserted", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", P3_STATIC);
|
||||
}
|
||||
|
||||
insert_cleanup:
|
||||
@@ -724,11 +719,11 @@ insert_cleanup:
|
||||
** When this routine is called, the stack contains (from bottom to top)
|
||||
** the following values:
|
||||
**
|
||||
** 1. The recno of the row to be updated before the update. This
|
||||
** 1. The rowid of the row to be updated before the update. This
|
||||
** value is omitted unless we are doing an UPDATE that involves a
|
||||
** change to the record number.
|
||||
**
|
||||
** 2. The recno of the row after the update.
|
||||
** 2. The rowid of the row after the update.
|
||||
**
|
||||
** 3. The data in the first column of the entry after the update.
|
||||
**
|
||||
@@ -736,9 +731,9 @@ insert_cleanup:
|
||||
**
|
||||
** N. The data in the last column of the entry after the update.
|
||||
**
|
||||
** The old recno shown as entry (1) above is omitted unless both isUpdate
|
||||
** and recnoChng are 1. isUpdate is true for UPDATEs and false for
|
||||
** INSERTs and recnoChng is true if the record number is being changed.
|
||||
** The old rowid shown as entry (1) above is omitted unless both isUpdate
|
||||
** and rowidChng are 1. isUpdate is true for UPDATEs and false for
|
||||
** INSERTs and rowidChng is true if the record number is being changed.
|
||||
**
|
||||
** The code generated by this routine pushes additional entries onto
|
||||
** the stack which are the keys for new index entries for the new record.
|
||||
@@ -802,7 +797,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
char *aIdxUsed, /* Which indices are used. NULL means all are used */
|
||||
int recnoChng, /* True if the record number will change */
|
||||
int rowidChng, /* True if the record number will change */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int overrideError, /* Override onError to this if not OE_Default */
|
||||
int ignoreDest /* Jump to this label on an OE_Ignore resolution */
|
||||
@@ -817,8 +812,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
Index *pIdx;
|
||||
int seenReplace = 0;
|
||||
int jumpInst1=0, jumpInst2;
|
||||
int contAddr;
|
||||
int hasTwoRecnos = (isUpdate && recnoChng);
|
||||
int hasTwoRowids = (isUpdate && rowidChng);
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
@@ -857,7 +851,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
@@ -867,18 +861,29 @@ void sqlite3GenerateConstraintChecks(
|
||||
break;
|
||||
}
|
||||
}
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
|
||||
/* Test all CHECK constraints
|
||||
*/
|
||||
/**** TBD ****/
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
|
||||
int allOk = sqlite3VdbeMakeLabel(v);
|
||||
assert( pParse->ckOffset==0 );
|
||||
pParse->ckOffset = nCol;
|
||||
sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, 1);
|
||||
assert( pParse->ckOffset==nCol );
|
||||
pParse->ckOffset = 0;
|
||||
sqlite3VdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort);
|
||||
sqlite3VdbeResolveLabel(v, allOk);
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_CHECK) */
|
||||
|
||||
/* If we have an INTEGER PRIMARY KEY, make sure the primary key
|
||||
** of the new record does not previously exist. Except, if this
|
||||
** is an UPDATE and the primary key is not changing, that is OK.
|
||||
*/
|
||||
if( recnoChng ){
|
||||
if( rowidChng ){
|
||||
onError = pTab->keyConf;
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
@@ -908,7 +913,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
case OE_Replace: {
|
||||
sqlite3GenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRowids, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
@@ -916,15 +921,14 @@ void sqlite3GenerateConstraintChecks(
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
contAddr = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
|
||||
sqlite3VdbeJumpHere(v, jumpInst2);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeChangeP2(v, jumpInst1, contAddr);
|
||||
sqlite3VdbeJumpHere(v, jumpInst1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
}
|
||||
@@ -949,7 +953,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1);
|
||||
}
|
||||
}
|
||||
jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
|
||||
jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
|
||||
/* Find out what action to take in case there is an indexing conflict */
|
||||
@@ -967,7 +971,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
|
||||
|
||||
/* Check to see if the new index entry will be unique */
|
||||
sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRowids, 1);
|
||||
jumpInst2 = sqlite3VdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
|
||||
|
||||
/* Generate code that executes if the new index entry is not unique */
|
||||
@@ -1004,26 +1008,24 @@ void sqlite3GenerateConstraintChecks(
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRowids, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqlite3GenerateRowDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
contAddr = sqlite3VdbeCurrentAddr(v);
|
||||
assert( contAddr<(1<<24) );
|
||||
#if NULL_DISTINCT_FOR_UNIQUE
|
||||
sqlite3VdbeChangeP2(v, jumpInst1, contAddr | (1<<24));
|
||||
sqlite3VdbeJumpHere(v, jumpInst1);
|
||||
#endif
|
||||
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
|
||||
sqlite3VdbeJumpHere(v, jumpInst2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1031,7 +1033,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
** This routine generates code to finish the INSERT or UPDATE operation
|
||||
** that was started by a prior call to sqlite3GenerateConstraintChecks.
|
||||
** The stack must contain keys for all active indices followed by data
|
||||
** and the recno for the new entry. This routine creates the new
|
||||
** and the rowid for the new entry. This routine creates the new
|
||||
** entries in all indices and in the main table.
|
||||
**
|
||||
** The arguments to this routine should be the same as the first six
|
||||
@@ -1042,7 +1044,7 @@ void sqlite3CompleteInsertion(
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
char *aIdxUsed, /* Which indices are used. NULL means all are used */
|
||||
int recnoChng, /* True if the record number will change */
|
||||
int rowidChng, /* True if the record number will change */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int newIdx /* Index of NEW table for triggers. -1 if none */
|
||||
){
|
||||
@@ -1058,7 +1060,7 @@ void sqlite3CompleteInsertion(
|
||||
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
|
||||
for(i=nIdx-1; i>=0; i--){
|
||||
if( aIdxUsed && aIdxUsed[i]==0 ) continue;
|
||||
sqlite3VdbeAddOp(v, OP_IdxPut, base+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IdxInsert, base+i+1, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
@@ -1066,17 +1068,21 @@ void sqlite3CompleteInsertion(
|
||||
if( newIdx>=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
|
||||
}
|
||||
#endif
|
||||
if( pParse->nested ){
|
||||
pik_flags = 0;
|
||||
}else{
|
||||
pik_flags = (OPFLAG_NCHANGE|(isUpdate?0:OPFLAG_LASTROWID));
|
||||
pik_flags = OPFLAG_NCHANGE;
|
||||
pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Insert, base, pik_flags);
|
||||
if( !pParse->nested ){
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, base, pik_flags);
|
||||
|
||||
if( isUpdate && recnoChng ){
|
||||
if( isUpdate && rowidChng ){
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
}
|
||||
}
|
||||
@@ -1093,17 +1099,17 @@ void sqlite3OpenTableAndIndices(
|
||||
int op /* OP_OpenRead or OP_OpenWrite */
|
||||
){
|
||||
int i;
|
||||
int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
Index *pIdx;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, op, base, pTab->tnum);
|
||||
VdbeComment((v, "# %s", pTab->zName));
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol);
|
||||
sqlite3OpenTable(pParse, base, iDb, pTab, op);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, op, i+base, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
VdbeComment((v, "# %s", pIdx->zName));
|
||||
sqlite3VdbeOp3(v, op, i+base, pIdx->tnum, (char*)pKey, P3_KEYINFO_HANDOFF);
|
||||
}
|
||||
if( pParse->nTab<=base+i ){
|
||||
pParse->nTab = base+i;
|
||||
|
||||
@@ -1,83 +1,85 @@
|
||||
/* Hash score: 151 */
|
||||
/* Hash score: 159 */
|
||||
static int keywordCode(const char *z, int n){
|
||||
static const char zText[510] =
|
||||
static const char zText[537] =
|
||||
"ABORTABLEFTEMPORARYADDATABASELECTHENDEFAULTRANSACTIONATURALTER"
|
||||
"AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREINDEXCLUSIVEXISTS"
|
||||
"TATEMENTANDEFERRABLEXPLAINITIALLYATTACHAVINGLOBEFOREIGNORENAME"
|
||||
"AUTOINCREMENTBEGINNEREPLACEBETWEENOTNULLIKEBYCASCADEFERREDELETE"
|
||||
"CASECOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSSCURRENT_DATE"
|
||||
"CURRENT_TIMESTAMPRAGMATCHDESCDETACHDISTINCTDROPRIMARYFAILIMIT"
|
||||
"FROMFULLGROUPDATEIMMEDIATEINSERTINSTEADINTOFFSETISNULLJOINORDER"
|
||||
"ESTRICTOUTERIGHTROLLBACKROWHENUNIONUNIQUEUSINGVACUUMVALUESVIEW"
|
||||
"HERE";
|
||||
"AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYANALYZE"
|
||||
"XCLUSIVEXISTSTATEMENTANDEFERRABLEATTACHAVINGLOBEFOREIGNOREINDEX"
|
||||
"AUTOINCREMENTBEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETE"
|
||||
"CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS"
|
||||
"CURRENT_DATECURRENT_TIMESTAMPLANDESCDETACHDISTINCTDROPRAGMATCH"
|
||||
"FAILIMITFROMFULLGROUPDATEIFIMMEDIATEINSERTINSTEADINTOFFSETISNULL"
|
||||
"JOINORDEREPLACEOUTERESTRICTPRIMARYQUERYRIGHTROLLBACKROWHENUNION"
|
||||
"UNIQUEUSINGVACUUMVALUESVIEWHERE";
|
||||
static const unsigned char aHash[127] = {
|
||||
89, 79, 101, 88, 0, 4, 0, 0, 108, 0, 75, 0, 0,
|
||||
92, 44, 0, 90, 0, 100, 103, 94, 0, 0, 10, 0, 0,
|
||||
107, 0, 104, 98, 0, 11, 47, 0, 41, 0, 0, 63, 69,
|
||||
0, 62, 19, 0, 0, 33, 81, 0, 102, 72, 0, 0, 30,
|
||||
0, 60, 34, 0, 8, 0, 109, 38, 12, 0, 76, 40, 25,
|
||||
64, 0, 0, 37, 80, 52, 36, 49, 20, 86, 0, 31, 0,
|
||||
73, 26, 0, 70, 0, 0, 0, 0, 46, 65, 22, 85, 35,
|
||||
67, 84, 0, 1, 0, 9, 51, 57, 18, 0, 106, 74, 96,
|
||||
53, 6, 83, 0, 0, 48, 91, 0, 99, 0, 68, 0, 0,
|
||||
15, 0, 110, 50, 55, 0, 2, 54, 0, 105,
|
||||
92, 80, 107, 91, 0, 4, 0, 0, 114, 0, 83, 0, 0,
|
||||
96, 44, 76, 93, 0, 106, 109, 97, 90, 0, 10, 0, 0,
|
||||
113, 0, 110, 103, 0, 28, 48, 0, 41, 0, 0, 65, 71,
|
||||
0, 63, 19, 0, 105, 36, 104, 0, 108, 75, 0, 0, 33,
|
||||
0, 61, 37, 0, 8, 0, 115, 38, 12, 0, 77, 40, 25,
|
||||
66, 0, 0, 31, 81, 53, 30, 50, 20, 88, 0, 34, 0,
|
||||
74, 26, 0, 72, 0, 0, 0, 64, 47, 67, 22, 87, 29,
|
||||
69, 86, 0, 1, 0, 9, 101, 58, 18, 0, 112, 82, 99,
|
||||
54, 6, 85, 0, 0, 49, 94, 0, 102, 0, 70, 0, 0,
|
||||
15, 0, 116, 51, 56, 0, 2, 55, 0, 111,
|
||||
};
|
||||
static const unsigned char aNext[110] = {
|
||||
static const unsigned char aNext[116] = {
|
||||
0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0,
|
||||
0, 0, 0, 5, 13, 0, 7, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0,
|
||||
0, 16, 0, 23, 45, 0, 0, 0, 0, 28, 58, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 71, 42, 0, 0, 24, 59, 21,
|
||||
0, 78, 0, 66, 0, 0, 82, 29, 0, 0, 0, 0, 0,
|
||||
0, 0, 39, 93, 95, 0, 0, 97, 14, 27, 77, 0, 56,
|
||||
87, 0, 32, 0, 61, 0,
|
||||
0, 11, 0, 0, 0, 0, 5, 13, 0, 7, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0,
|
||||
0, 0, 16, 0, 23, 52, 0, 0, 0, 0, 45, 0, 59,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 42, 73, 0, 24, 60,
|
||||
21, 0, 79, 0, 0, 68, 0, 0, 84, 46, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 39, 95, 98, 0, 0, 100, 0, 32,
|
||||
0, 14, 27, 78, 0, 57, 89, 0, 35, 0, 62, 0,
|
||||
};
|
||||
static const unsigned char aLen[110] = {
|
||||
static const unsigned char aLen[116] = {
|
||||
5, 5, 4, 4, 9, 2, 3, 8, 2, 6, 4, 3, 7,
|
||||
11, 2, 7, 5, 5, 4, 5, 3, 5, 10, 6, 4, 6,
|
||||
7, 7, 5, 9, 6, 9, 3, 10, 7, 9, 3, 6, 6,
|
||||
4, 6, 3, 7, 6, 6, 13, 2, 2, 5, 5, 7, 7,
|
||||
3, 7, 4, 4, 2, 7, 3, 8, 6, 4, 7, 6, 6,
|
||||
8, 10, 9, 6, 5, 12, 12, 17, 6, 5, 4, 6, 8,
|
||||
2, 4, 7, 4, 5, 4, 4, 5, 6, 9, 6, 7, 4,
|
||||
2, 6, 3, 6, 4, 5, 8, 5, 5, 8, 3, 4, 5,
|
||||
6, 5, 6, 6, 4, 5,
|
||||
7, 6, 7, 9, 3, 7, 9, 6, 9, 3, 10, 6, 6,
|
||||
4, 6, 3, 7, 6, 7, 5, 13, 2, 2, 5, 5, 6,
|
||||
7, 3, 7, 4, 4, 2, 7, 3, 8, 6, 4, 4, 7,
|
||||
6, 6, 8, 10, 9, 6, 5, 12, 17, 12, 4, 4, 6,
|
||||
8, 2, 4, 6, 5, 4, 5, 4, 4, 5, 6, 2, 9,
|
||||
6, 7, 4, 6, 2, 3, 6, 4, 5, 7, 5, 8, 7,
|
||||
5, 5, 8, 3, 4, 5, 6, 5, 6, 6, 4, 5,
|
||||
};
|
||||
static const unsigned short int aOffset[110] = {
|
||||
static const unsigned short int aOffset[116] = {
|
||||
0, 4, 7, 10, 10, 14, 19, 21, 26, 27, 32, 34, 36,
|
||||
42, 51, 52, 57, 61, 65, 67, 71, 74, 78, 86, 91, 94,
|
||||
99, 105, 107, 110, 118, 123, 132, 134, 143, 148, 153, 157, 162,
|
||||
167, 170, 172, 172, 176, 180, 186, 188, 190, 199, 202, 206, 213,
|
||||
219, 219, 222, 225, 229, 231, 232, 236, 243, 249, 253, 260, 266,
|
||||
272, 280, 287, 296, 302, 307, 319, 319, 335, 339, 344, 348, 354,
|
||||
355, 362, 365, 372, 375, 380, 384, 388, 391, 397, 406, 412, 419,
|
||||
422, 422, 425, 428, 434, 438, 442, 450, 454, 459, 467, 469, 473,
|
||||
478, 484, 489, 495, 501, 504,
|
||||
99, 105, 108, 113, 118, 122, 128, 136, 141, 150, 152, 162, 167,
|
||||
172, 175, 177, 177, 181, 185, 187, 192, 194, 196, 205, 208, 212,
|
||||
218, 224, 224, 227, 230, 234, 236, 237, 241, 248, 254, 258, 262,
|
||||
269, 275, 281, 289, 296, 305, 311, 316, 328, 328, 344, 348, 352,
|
||||
358, 359, 366, 369, 373, 378, 381, 386, 390, 394, 397, 403, 405,
|
||||
414, 420, 427, 430, 430, 433, 436, 442, 446, 450, 457, 461, 469,
|
||||
476, 481, 486, 494, 496, 500, 505, 511, 516, 522, 528, 531,
|
||||
};
|
||||
static const unsigned char aCode[110] = {
|
||||
static const unsigned char aCode[116] = {
|
||||
TK_ABORT, TK_TABLE, TK_JOIN_KW, TK_TEMP, TK_TEMP,
|
||||
TK_OR, TK_ADD, TK_DATABASE, TK_AS, TK_SELECT,
|
||||
TK_THEN, TK_END, TK_DEFAULT, TK_TRANSACTION,TK_ON,
|
||||
TK_JOIN_KW, TK_ALTER, TK_RAISE, TK_EACH, TK_CHECK,
|
||||
TK_KEY, TK_AFTER, TK_REFERENCES, TK_ESCAPE, TK_ELSE,
|
||||
TK_EXCEPT, TK_TRIGGER, TK_REINDEX, TK_INDEX, TK_EXCLUSIVE,
|
||||
TK_EXISTS, TK_STATEMENT, TK_AND, TK_DEFERRABLE, TK_EXPLAIN,
|
||||
TK_INITIALLY, TK_ALL, TK_ATTACH, TK_HAVING, TK_GLOB,
|
||||
TK_BEFORE, TK_FOR, TK_FOREIGN, TK_IGNORE, TK_RENAME,
|
||||
TK_AUTOINCR, TK_TO, TK_IN, TK_BEGIN, TK_JOIN_KW,
|
||||
TK_REPLACE, TK_BETWEEN, TK_NOT, TK_NOTNULL, TK_NULL,
|
||||
TK_LIKE, TK_BY, TK_CASCADE, TK_ASC, TK_DEFERRED,
|
||||
TK_DELETE, TK_CASE, TK_COLLATE, TK_COLUMNKW, TK_COMMIT,
|
||||
TK_CONFLICT, TK_CONSTRAINT, TK_INTERSECT, TK_CREATE, TK_JOIN_KW,
|
||||
TK_CDATE, TK_CTIME, TK_CTIMESTAMP, TK_PRAGMA, TK_MATCH,
|
||||
TK_DESC, TK_DETACH, TK_DISTINCT, TK_IS, TK_DROP,
|
||||
TK_PRIMARY, TK_FAIL, TK_LIMIT, TK_FROM, TK_JOIN_KW,
|
||||
TK_GROUP, TK_UPDATE, TK_IMMEDIATE, TK_INSERT, TK_INSTEAD,
|
||||
TK_INTO, TK_OF, TK_OFFSET, TK_SET, TK_ISNULL,
|
||||
TK_JOIN, TK_ORDER, TK_RESTRICT, TK_JOIN_KW, TK_JOIN_KW,
|
||||
TK_ROLLBACK, TK_ROW, TK_WHEN, TK_UNION, TK_UNIQUE,
|
||||
TK_USING, TK_VACUUM, TK_VALUES, TK_VIEW, TK_WHERE,
|
||||
TK_EXCEPT, TK_TRIGGER, TK_LIKE_KW, TK_EXPLAIN, TK_INITIALLY,
|
||||
TK_ALL, TK_ANALYZE, TK_EXCLUSIVE, TK_EXISTS, TK_STATEMENT,
|
||||
TK_AND, TK_DEFERRABLE, TK_ATTACH, TK_HAVING, TK_LIKE_KW,
|
||||
TK_BEFORE, TK_FOR, TK_FOREIGN, TK_IGNORE, TK_REINDEX,
|
||||
TK_INDEX, TK_AUTOINCR, TK_TO, TK_IN, TK_BEGIN,
|
||||
TK_JOIN_KW, TK_RENAME, TK_BETWEEN, TK_NOT, TK_NOTNULL,
|
||||
TK_NULL, TK_LIKE_KW, TK_BY, TK_CASCADE, TK_ASC,
|
||||
TK_DEFERRED, TK_DELETE, TK_CASE, TK_CAST, TK_COLLATE,
|
||||
TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, TK_CONSTRAINT, TK_INTERSECT,
|
||||
TK_CREATE, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW, TK_CTIME_KW,
|
||||
TK_PLAN, TK_DESC, TK_DETACH, TK_DISTINCT, TK_IS,
|
||||
TK_DROP, TK_PRAGMA, TK_MATCH, TK_FAIL, TK_LIMIT,
|
||||
TK_FROM, TK_JOIN_KW, TK_GROUP, TK_UPDATE, TK_IF,
|
||||
TK_IMMEDIATE, TK_INSERT, TK_INSTEAD, TK_INTO, TK_OFFSET,
|
||||
TK_OF, TK_SET, TK_ISNULL, TK_JOIN, TK_ORDER,
|
||||
TK_REPLACE, TK_JOIN_KW, TK_RESTRICT, TK_PRIMARY, TK_QUERY,
|
||||
TK_JOIN_KW, TK_ROLLBACK, TK_ROW, TK_WHEN, TK_UNION,
|
||||
TK_UNIQUE, TK_USING, TK_VACUUM, TK_VALUES, TK_VIEW,
|
||||
TK_WHERE,
|
||||
};
|
||||
int h, i;
|
||||
if( n<2 ) return TK_ID;
|
||||
@@ -91,6 +93,6 @@ static int keywordCode(const char *z, int n){
|
||||
}
|
||||
return TK_ID;
|
||||
}
|
||||
int sqlite3KeywordCode(const char *z, int n){
|
||||
return keywordCode(z, n);
|
||||
int sqlite3KeywordCode(const unsigned char *z, int n){
|
||||
return keywordCode((char*)z, n);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: legacy.c,v 1.3 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: legacy.c,v 1.4 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
@@ -68,9 +68,8 @@ int sqlite3_exec(
|
||||
nCallback = 0;
|
||||
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
azCols = sqliteMalloc(2*nCol*sizeof(const char *));
|
||||
if( nCol && !azCols ){
|
||||
rc = SQLITE_NOMEM;
|
||||
azCols = sqliteMalloc(2*nCol*sizeof(const char *) + 1);
|
||||
if( azCols==0 ){
|
||||
goto exec_out;
|
||||
}
|
||||
|
||||
@@ -122,9 +121,7 @@ exec_out:
|
||||
if( pStmt ) sqlite3_finalize(pStmt);
|
||||
if( azCols ) sqliteFree(azCols);
|
||||
|
||||
if( sqlite3_malloc_failed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
rc = sqlite3ApiExit(0, rc);
|
||||
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
|
||||
*pzErrMsg = malloc(1+strlen(sqlite3_errmsg(db)));
|
||||
if( *pzErrMsg ){
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,136 +2,146 @@
|
||||
/* See the mkopcodec.awk script for details. */
|
||||
#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
|
||||
const char *const sqlite3OpcodeNames[] = { "?",
|
||||
/* 1 */ "MemLoad",
|
||||
/* 2 */ "Column",
|
||||
/* 3 */ "SetCookie",
|
||||
/* 4 */ "IfMemPos",
|
||||
/* 5 */ "MoveGt",
|
||||
/* 6 */ "AggFocus",
|
||||
/* 7 */ "RowKey",
|
||||
/* 8 */ "IdxRecno",
|
||||
/* 9 */ "AggNext",
|
||||
/* 10 */ "OpenWrite",
|
||||
/* 11 */ "If",
|
||||
/* 12 */ "PutStrKey",
|
||||
/* 13 */ "Pop",
|
||||
/* 14 */ "SortPut",
|
||||
/* 15 */ "AggContextPush",
|
||||
/* 16 */ "CollSeq",
|
||||
/* 17 */ "OpenRead",
|
||||
/* 18 */ "Expire",
|
||||
/* 19 */ "SortReset",
|
||||
/* 20 */ "AutoCommit",
|
||||
/* 21 */ "Sort",
|
||||
/* 22 */ "ListRewind",
|
||||
/* 23 */ "IntegrityCk",
|
||||
/* 24 */ "Function",
|
||||
/* 25 */ "Noop",
|
||||
/* 26 */ "Return",
|
||||
/* 27 */ "Variable",
|
||||
/* 28 */ "String",
|
||||
/* 29 */ "ParseSchema",
|
||||
/* 30 */ "PutIntKey",
|
||||
/* 31 */ "AggFunc",
|
||||
/* 32 */ "Close",
|
||||
/* 33 */ "ListWrite",
|
||||
/* 34 */ "CreateIndex",
|
||||
/* 35 */ "IsUnique",
|
||||
/* 36 */ "IdxIsNull",
|
||||
/* 37 */ "NotFound",
|
||||
/* 38 */ "MustBeInt",
|
||||
/* 39 */ "Halt",
|
||||
/* 40 */ "IdxLT",
|
||||
/* 41 */ "AddImm",
|
||||
/* 42 */ "Statement",
|
||||
/* 43 */ "RowData",
|
||||
/* 44 */ "MemMax",
|
||||
/* 45 */ "Push",
|
||||
/* 46 */ "KeyAsData",
|
||||
/* 47 */ "NotExists",
|
||||
/* 48 */ "OpenTemp",
|
||||
/* 49 */ "MemIncr",
|
||||
/* 50 */ "Gosub",
|
||||
/* 51 */ "AggSet",
|
||||
/* 52 */ "Integer",
|
||||
/* 53 */ "SortNext",
|
||||
/* 54 */ "Prev",
|
||||
/* 55 */ "CreateTable",
|
||||
/* 56 */ "Last",
|
||||
/* 57 */ "ResetCount",
|
||||
/* 58 */ "Callback",
|
||||
/* 59 */ "ContextPush",
|
||||
/* 60 */ "DropTrigger",
|
||||
/* 61 */ "DropIndex",
|
||||
/* 62 */ "FullKey",
|
||||
/* 63 */ "IdxGE",
|
||||
/* 64 */ "Or",
|
||||
/* 65 */ "And",
|
||||
/* 66 */ "Not",
|
||||
/* 67 */ "IdxDelete",
|
||||
/* 68 */ "Vacuum",
|
||||
/* 69 */ "MoveLe",
|
||||
/* 70 */ "IsNull",
|
||||
/* 71 */ "NotNull",
|
||||
/* 72 */ "Ne",
|
||||
/* 73 */ "Eq",
|
||||
/* 74 */ "Gt",
|
||||
/* 75 */ "Le",
|
||||
/* 76 */ "Lt",
|
||||
/* 77 */ "Ge",
|
||||
/* 78 */ "IfNot",
|
||||
/* 79 */ "BitAnd",
|
||||
/* 80 */ "BitOr",
|
||||
/* 81 */ "ShiftLeft",
|
||||
/* 82 */ "ShiftRight",
|
||||
/* 83 */ "Add",
|
||||
/* 84 */ "Subtract",
|
||||
/* 85 */ "Multiply",
|
||||
/* 86 */ "Divide",
|
||||
/* 87 */ "Remainder",
|
||||
/* 88 */ "Concat",
|
||||
/* 89 */ "Negative",
|
||||
/* 90 */ "DropTable",
|
||||
/* 91 */ "BitNot",
|
||||
/* 92 */ "String8",
|
||||
/* 93 */ "MakeRecord",
|
||||
/* 94 */ "Delete",
|
||||
/* 95 */ "AggContextPop",
|
||||
/* 96 */ "ListRead",
|
||||
/* 97 */ "ListReset",
|
||||
/* 98 */ "Dup",
|
||||
/* 99 */ "Goto",
|
||||
/* 100 */ "Clear",
|
||||
/* 101 */ "IdxGT",
|
||||
/* 102 */ "MoveLt",
|
||||
/* 103 */ "VerifyCookie",
|
||||
/* 104 */ "Pull",
|
||||
/* 105 */ "SetNumColumns",
|
||||
/* 106 */ "AbsValue",
|
||||
/* 107 */ "Transaction",
|
||||
/* 108 */ "AggGet",
|
||||
/* 109 */ "ContextPop",
|
||||
/* 110 */ "Next",
|
||||
/* 111 */ "AggInit",
|
||||
/* 112 */ "Distinct",
|
||||
/* 113 */ "NewRecno",
|
||||
/* 114 */ "AggReset",
|
||||
/* 115 */ "Destroy",
|
||||
/* 116 */ "ReadCookie",
|
||||
/* 117 */ "ForceInt",
|
||||
/* 118 */ "Recno",
|
||||
/* 119 */ "OpenPseudo",
|
||||
/* 120 */ "Blob",
|
||||
/* 121 */ "MemStore",
|
||||
/* 122 */ "Rewind",
|
||||
/* 123 */ "MoveGe",
|
||||
/* 124 */ "IdxPut",
|
||||
/* 125 */ "Found",
|
||||
/* 126 */ "NullRow",
|
||||
/* 1 */ "ReadCookie",
|
||||
/* 2 */ "AutoCommit",
|
||||
/* 3 */ "Found",
|
||||
/* 4 */ "NullRow",
|
||||
/* 5 */ "MoveLe",
|
||||
/* 6 */ "Variable",
|
||||
/* 7 */ "Pull",
|
||||
/* 8 */ "RealAffinity",
|
||||
/* 9 */ "Sort",
|
||||
/* 10 */ "IfNot",
|
||||
/* 11 */ "Gosub",
|
||||
/* 12 */ "NotFound",
|
||||
/* 13 */ "MoveLt",
|
||||
/* 14 */ "Rowid",
|
||||
/* 15 */ "CreateIndex",
|
||||
/* 16 */ "Not",
|
||||
/* 17 */ "Push",
|
||||
/* 18 */ "Explain",
|
||||
/* 19 */ "Statement",
|
||||
/* 20 */ "Callback",
|
||||
/* 21 */ "MemLoad",
|
||||
/* 22 */ "DropIndex",
|
||||
/* 23 */ "Null",
|
||||
/* 24 */ "Int64",
|
||||
/* 25 */ "LoadAnalysis",
|
||||
/* 26 */ "IdxInsert",
|
||||
/* 27 */ "Next",
|
||||
/* 28 */ "SetNumColumns",
|
||||
/* 29 */ "MemInt",
|
||||
/* 30 */ "Dup",
|
||||
/* 31 */ "Rewind",
|
||||
/* 32 */ "Last",
|
||||
/* 33 */ "MustBeInt",
|
||||
/* 34 */ "MoveGe",
|
||||
/* 35 */ "String",
|
||||
/* 36 */ "ForceInt",
|
||||
/* 37 */ "Close",
|
||||
/* 38 */ "AggFinal",
|
||||
/* 39 */ "AbsValue",
|
||||
/* 40 */ "RowData",
|
||||
/* 41 */ "IdxRowid",
|
||||
/* 42 */ "MoveGt",
|
||||
/* 43 */ "OpenPseudo",
|
||||
/* 44 */ "Halt",
|
||||
/* 45 */ "MemMove",
|
||||
/* 46 */ "NewRowid",
|
||||
/* 47 */ "IdxLT",
|
||||
/* 48 */ "Distinct",
|
||||
/* 49 */ "MemMax",
|
||||
/* 50 */ "Function",
|
||||
/* 51 */ "IntegrityCk",
|
||||
/* 52 */ "FifoWrite",
|
||||
/* 53 */ "NotExists",
|
||||
/* 54 */ "MemStore",
|
||||
/* 55 */ "IdxDelete",
|
||||
/* 56 */ "Vacuum",
|
||||
/* 57 */ "If",
|
||||
/* 58 */ "Destroy",
|
||||
/* 59 */ "Or",
|
||||
/* 60 */ "And",
|
||||
/* 61 */ "AggStep",
|
||||
/* 62 */ "Clear",
|
||||
/* 63 */ "Insert",
|
||||
/* 64 */ "IsNull",
|
||||
/* 65 */ "NotNull",
|
||||
/* 66 */ "Ne",
|
||||
/* 67 */ "Eq",
|
||||
/* 68 */ "Gt",
|
||||
/* 69 */ "Le",
|
||||
/* 70 */ "Lt",
|
||||
/* 71 */ "Ge",
|
||||
/* 72 */ "IdxGE",
|
||||
/* 73 */ "BitAnd",
|
||||
/* 74 */ "BitOr",
|
||||
/* 75 */ "ShiftLeft",
|
||||
/* 76 */ "ShiftRight",
|
||||
/* 77 */ "Add",
|
||||
/* 78 */ "Subtract",
|
||||
/* 79 */ "Multiply",
|
||||
/* 80 */ "Divide",
|
||||
/* 81 */ "Remainder",
|
||||
/* 82 */ "Concat",
|
||||
/* 83 */ "Negative",
|
||||
/* 84 */ "IfMemZero",
|
||||
/* 85 */ "BitNot",
|
||||
/* 86 */ "String8",
|
||||
/* 87 */ "MakeRecord",
|
||||
/* 88 */ "SetCookie",
|
||||
/* 89 */ "Prev",
|
||||
/* 90 */ "ContextPush",
|
||||
/* 91 */ "DropTrigger",
|
||||
/* 92 */ "IdxGT",
|
||||
/* 93 */ "MemNull",
|
||||
/* 94 */ "IfMemNeg",
|
||||
/* 95 */ "Return",
|
||||
/* 96 */ "OpenWrite",
|
||||
/* 97 */ "Integer",
|
||||
/* 98 */ "Transaction",
|
||||
/* 99 */ "OpenVirtual",
|
||||
/* 100 */ "CollSeq",
|
||||
/* 101 */ "Sequence",
|
||||
/* 102 */ "ContextPop",
|
||||
/* 103 */ "CreateTable",
|
||||
/* 104 */ "AddImm",
|
||||
/* 105 */ "IdxIsNull",
|
||||
/* 106 */ "DropTable",
|
||||
/* 107 */ "IsUnique",
|
||||
/* 108 */ "Noop",
|
||||
/* 109 */ "RowKey",
|
||||
/* 110 */ "Expire",
|
||||
/* 111 */ "FifoRead",
|
||||
/* 112 */ "Delete",
|
||||
/* 113 */ "IfMemPos",
|
||||
/* 114 */ "MemIncr",
|
||||
/* 115 */ "Blob",
|
||||
/* 116 */ "MakeIdxRec",
|
||||
/* 117 */ "Goto",
|
||||
/* 118 */ "ParseSchema",
|
||||
/* 119 */ "Pop",
|
||||
/* 120 */ "TableLock",
|
||||
/* 121 */ "VerifyCookie",
|
||||
/* 122 */ "Column",
|
||||
/* 123 */ "OpenRead",
|
||||
/* 124 */ "Real",
|
||||
/* 125 */ "HexBlob",
|
||||
/* 126 */ "ResetCount",
|
||||
/* 127 */ "NotUsed_127",
|
||||
/* 128 */ "NotUsed_128",
|
||||
/* 129 */ "NotUsed_129",
|
||||
/* 130 */ "Real",
|
||||
/* 131 */ "HexBlob",
|
||||
/* 130 */ "NotUsed_130",
|
||||
/* 131 */ "NotUsed_131",
|
||||
/* 132 */ "NotUsed_132",
|
||||
/* 133 */ "NotUsed_133",
|
||||
/* 134 */ "NotUsed_134",
|
||||
/* 135 */ "NotUsed_135",
|
||||
/* 136 */ "NotUsed_136",
|
||||
/* 137 */ "ToText",
|
||||
/* 138 */ "ToBlob",
|
||||
/* 139 */ "ToNumeric",
|
||||
/* 140 */ "ToInt",
|
||||
/* 141 */ "ToReal",
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,146 +1,159 @@
|
||||
/* Automatically generated. Do not edit */
|
||||
/* See the mkopcodeh.awk script for details */
|
||||
#define OP_MemLoad 1
|
||||
#define OP_HexBlob 131 /* same as TK_BLOB */
|
||||
#define OP_Column 2
|
||||
#define OP_SetCookie 3
|
||||
#define OP_IfMemPos 4
|
||||
#define OP_Real 130 /* same as TK_FLOAT */
|
||||
#define OP_MoveGt 5
|
||||
#define OP_Ge 77 /* same as TK_GE */
|
||||
#define OP_AggFocus 6
|
||||
#define OP_RowKey 7
|
||||
#define OP_IdxRecno 8
|
||||
#define OP_AggNext 9
|
||||
#define OP_Eq 73 /* same as TK_EQ */
|
||||
#define OP_OpenWrite 10
|
||||
#define OP_NotNull 71 /* same as TK_NOTNULL */
|
||||
#define OP_If 11
|
||||
#define OP_PutStrKey 12
|
||||
#define OP_String8 92 /* same as TK_STRING */
|
||||
#define OP_Pop 13
|
||||
#define OP_SortPut 14
|
||||
#define OP_AggContextPush 15
|
||||
#define OP_CollSeq 16
|
||||
#define OP_OpenRead 17
|
||||
#define OP_Expire 18
|
||||
#define OP_SortReset 19
|
||||
#define OP_AutoCommit 20
|
||||
#define OP_Gt 74 /* same as TK_GT */
|
||||
#define OP_Sort 21
|
||||
#define OP_ListRewind 22
|
||||
#define OP_IntegrityCk 23
|
||||
#define OP_Function 24
|
||||
#define OP_Subtract 84 /* same as TK_MINUS */
|
||||
#define OP_And 65 /* same as TK_AND */
|
||||
#define OP_Noop 25
|
||||
#define OP_Return 26
|
||||
#define OP_Remainder 87 /* same as TK_REM */
|
||||
#define OP_Multiply 85 /* same as TK_STAR */
|
||||
#define OP_Variable 27
|
||||
#define OP_String 28
|
||||
#define OP_ParseSchema 29
|
||||
#define OP_PutIntKey 30
|
||||
#define OP_AggFunc 31
|
||||
#define OP_Close 32
|
||||
#define OP_ListWrite 33
|
||||
#define OP_CreateIndex 34
|
||||
#define OP_IsUnique 35
|
||||
#define OP_IdxIsNull 36
|
||||
#define OP_NotFound 37
|
||||
#define OP_MustBeInt 38
|
||||
#define OP_Halt 39
|
||||
#define OP_IdxLT 40
|
||||
#define OP_AddImm 41
|
||||
#define OP_Statement 42
|
||||
#define OP_RowData 43
|
||||
#define OP_MemMax 44
|
||||
#define OP_Push 45
|
||||
#define OP_Or 64 /* same as TK_OR */
|
||||
#define OP_KeyAsData 46
|
||||
#define OP_NotExists 47
|
||||
#define OP_OpenTemp 48
|
||||
#define OP_MemIncr 49
|
||||
#define OP_Gosub 50
|
||||
#define OP_Divide 86 /* same as TK_SLASH */
|
||||
#define OP_AggSet 51
|
||||
#define OP_Integer 52
|
||||
#define OP_SortNext 53
|
||||
#define OP_Prev 54
|
||||
#define OP_Concat 88 /* same as TK_CONCAT */
|
||||
#define OP_BitAnd 79 /* same as TK_BITAND */
|
||||
#define OP_CreateTable 55
|
||||
#define OP_Last 56
|
||||
#define OP_IsNull 70 /* same as TK_ISNULL */
|
||||
#define OP_ShiftRight 82 /* same as TK_RSHIFT */
|
||||
#define OP_ResetCount 57
|
||||
#define OP_Callback 58
|
||||
#define OP_ContextPush 59
|
||||
#define OP_DropTrigger 60
|
||||
#define OP_DropIndex 61
|
||||
#define OP_FullKey 62
|
||||
#define OP_IdxGE 63
|
||||
#define OP_IdxDelete 67
|
||||
#define OP_Vacuum 68
|
||||
#define OP_MoveLe 69
|
||||
#define OP_IfNot 78
|
||||
#define OP_DropTable 90
|
||||
#define OP_MakeRecord 93
|
||||
#define OP_Delete 94
|
||||
#define OP_AggContextPop 95
|
||||
#define OP_ListRead 96
|
||||
#define OP_ListReset 97
|
||||
#define OP_ShiftLeft 81 /* same as TK_LSHIFT */
|
||||
#define OP_Dup 98
|
||||
#define OP_Goto 99
|
||||
#define OP_Clear 100
|
||||
#define OP_IdxGT 101
|
||||
#define OP_MoveLt 102
|
||||
#define OP_Le 75 /* same as TK_LE */
|
||||
#define OP_VerifyCookie 103
|
||||
#define OP_Pull 104
|
||||
#define OP_Not 66 /* same as TK_NOT */
|
||||
#define OP_SetNumColumns 105
|
||||
#define OP_AbsValue 106
|
||||
#define OP_Transaction 107
|
||||
#define OP_Negative 89 /* same as TK_UMINUS */
|
||||
#define OP_Ne 72 /* same as TK_NE */
|
||||
#define OP_AggGet 108
|
||||
#define OP_ContextPop 109
|
||||
#define OP_BitOr 80 /* same as TK_BITOR */
|
||||
#define OP_Next 110
|
||||
#define OP_AggInit 111
|
||||
#define OP_Distinct 112
|
||||
#define OP_NewRecno 113
|
||||
#define OP_Lt 76 /* same as TK_LT */
|
||||
#define OP_AggReset 114
|
||||
#define OP_Destroy 115
|
||||
#define OP_ReadCookie 116
|
||||
#define OP_ForceInt 117
|
||||
#define OP_Recno 118
|
||||
#define OP_OpenPseudo 119
|
||||
#define OP_Blob 120
|
||||
#define OP_Add 83 /* same as TK_PLUS */
|
||||
#define OP_MemStore 121
|
||||
#define OP_Rewind 122
|
||||
#define OP_MoveGe 123
|
||||
#define OP_IdxPut 124
|
||||
#define OP_BitNot 91 /* same as TK_BITNOT */
|
||||
#define OP_Found 125
|
||||
#define OP_NullRow 126
|
||||
#define OP_ReadCookie 1
|
||||
#define OP_AutoCommit 2
|
||||
#define OP_Found 3
|
||||
#define OP_NullRow 4
|
||||
#define OP_Lt 70 /* same as TK_LT */
|
||||
#define OP_MoveLe 5
|
||||
#define OP_Variable 6
|
||||
#define OP_Pull 7
|
||||
#define OP_RealAffinity 8
|
||||
#define OP_Sort 9
|
||||
#define OP_IfNot 10
|
||||
#define OP_Gosub 11
|
||||
#define OP_Add 77 /* same as TK_PLUS */
|
||||
#define OP_NotFound 12
|
||||
#define OP_IsNull 64 /* same as TK_ISNULL */
|
||||
#define OP_MoveLt 13
|
||||
#define OP_Rowid 14
|
||||
#define OP_CreateIndex 15
|
||||
#define OP_Push 17
|
||||
#define OP_Explain 18
|
||||
#define OP_Statement 19
|
||||
#define OP_Callback 20
|
||||
#define OP_MemLoad 21
|
||||
#define OP_DropIndex 22
|
||||
#define OP_Null 23
|
||||
#define OP_ToInt 140 /* same as TK_TO_INT */
|
||||
#define OP_Int64 24
|
||||
#define OP_LoadAnalysis 25
|
||||
#define OP_IdxInsert 26
|
||||
#define OP_Next 27
|
||||
#define OP_SetNumColumns 28
|
||||
#define OP_ToNumeric 139 /* same as TK_TO_NUMERIC*/
|
||||
#define OP_Ge 71 /* same as TK_GE */
|
||||
#define OP_BitNot 85 /* same as TK_BITNOT */
|
||||
#define OP_MemInt 29
|
||||
#define OP_Dup 30
|
||||
#define OP_Rewind 31
|
||||
#define OP_Multiply 79 /* same as TK_STAR */
|
||||
#define OP_ToReal 141 /* same as TK_TO_REAL */
|
||||
#define OP_Gt 68 /* same as TK_GT */
|
||||
#define OP_Last 32
|
||||
#define OP_MustBeInt 33
|
||||
#define OP_Ne 66 /* same as TK_NE */
|
||||
#define OP_MoveGe 34
|
||||
#define OP_String 35
|
||||
#define OP_ForceInt 36
|
||||
#define OP_Close 37
|
||||
#define OP_AggFinal 38
|
||||
#define OP_AbsValue 39
|
||||
#define OP_RowData 40
|
||||
#define OP_IdxRowid 41
|
||||
#define OP_BitOr 74 /* same as TK_BITOR */
|
||||
#define OP_NotNull 65 /* same as TK_NOTNULL */
|
||||
#define OP_MoveGt 42
|
||||
#define OP_Not 16 /* same as TK_NOT */
|
||||
#define OP_OpenPseudo 43
|
||||
#define OP_Halt 44
|
||||
#define OP_MemMove 45
|
||||
#define OP_NewRowid 46
|
||||
#define OP_Real 124 /* same as TK_FLOAT */
|
||||
#define OP_IdxLT 47
|
||||
#define OP_Distinct 48
|
||||
#define OP_MemMax 49
|
||||
#define OP_Function 50
|
||||
#define OP_IntegrityCk 51
|
||||
#define OP_Remainder 81 /* same as TK_REM */
|
||||
#define OP_HexBlob 125 /* same as TK_BLOB */
|
||||
#define OP_ShiftLeft 75 /* same as TK_LSHIFT */
|
||||
#define OP_FifoWrite 52
|
||||
#define OP_BitAnd 73 /* same as TK_BITAND */
|
||||
#define OP_Or 59 /* same as TK_OR */
|
||||
#define OP_NotExists 53
|
||||
#define OP_MemStore 54
|
||||
#define OP_IdxDelete 55
|
||||
#define OP_Vacuum 56
|
||||
#define OP_If 57
|
||||
#define OP_Destroy 58
|
||||
#define OP_AggStep 61
|
||||
#define OP_Clear 62
|
||||
#define OP_Insert 63
|
||||
#define OP_IdxGE 72
|
||||
#define OP_Divide 80 /* same as TK_SLASH */
|
||||
#define OP_String8 86 /* same as TK_STRING */
|
||||
#define OP_IfMemZero 84
|
||||
#define OP_Concat 82 /* same as TK_CONCAT */
|
||||
#define OP_MakeRecord 87
|
||||
#define OP_SetCookie 88
|
||||
#define OP_Prev 89
|
||||
#define OP_ContextPush 90
|
||||
#define OP_DropTrigger 91
|
||||
#define OP_IdxGT 92
|
||||
#define OP_MemNull 93
|
||||
#define OP_IfMemNeg 94
|
||||
#define OP_And 60 /* same as TK_AND */
|
||||
#define OP_Return 95
|
||||
#define OP_OpenWrite 96
|
||||
#define OP_Integer 97
|
||||
#define OP_Transaction 98
|
||||
#define OP_OpenVirtual 99
|
||||
#define OP_CollSeq 100
|
||||
#define OP_ToBlob 138 /* same as TK_TO_BLOB */
|
||||
#define OP_Sequence 101
|
||||
#define OP_ContextPop 102
|
||||
#define OP_ShiftRight 76 /* same as TK_RSHIFT */
|
||||
#define OP_CreateTable 103
|
||||
#define OP_AddImm 104
|
||||
#define OP_ToText 137 /* same as TK_TO_TEXT */
|
||||
#define OP_IdxIsNull 105
|
||||
#define OP_DropTable 106
|
||||
#define OP_IsUnique 107
|
||||
#define OP_Noop 108
|
||||
#define OP_RowKey 109
|
||||
#define OP_Expire 110
|
||||
#define OP_FifoRead 111
|
||||
#define OP_Delete 112
|
||||
#define OP_IfMemPos 113
|
||||
#define OP_Subtract 78 /* same as TK_MINUS */
|
||||
#define OP_MemIncr 114
|
||||
#define OP_Blob 115
|
||||
#define OP_MakeIdxRec 116
|
||||
#define OP_Goto 117
|
||||
#define OP_Negative 83 /* same as TK_UMINUS */
|
||||
#define OP_ParseSchema 118
|
||||
#define OP_Eq 67 /* same as TK_EQ */
|
||||
#define OP_Pop 119
|
||||
#define OP_Le 69 /* same as TK_LE */
|
||||
#define OP_TableLock 120
|
||||
#define OP_VerifyCookie 121
|
||||
#define OP_Column 122
|
||||
#define OP_OpenRead 123
|
||||
#define OP_ResetCount 126
|
||||
|
||||
/* The following opcode values are never used */
|
||||
#define OP_NotUsed_127 127
|
||||
#define OP_NotUsed_128 128
|
||||
#define OP_NotUsed_129 129
|
||||
#define OP_NotUsed_130 130
|
||||
#define OP_NotUsed_131 131
|
||||
#define OP_NotUsed_132 132
|
||||
#define OP_NotUsed_133 133
|
||||
#define OP_NotUsed_134 134
|
||||
#define OP_NotUsed_135 135
|
||||
#define OP_NotUsed_136 136
|
||||
|
||||
#define NOPUSH_MASK_0 65144
|
||||
#define NOPUSH_MASK_1 59007
|
||||
#define NOPUSH_MASK_2 63483
|
||||
#define NOPUSH_MASK_3 48975
|
||||
#define NOPUSH_MASK_4 65535
|
||||
#define NOPUSH_MASK_5 52991
|
||||
#define NOPUSH_MASK_6 60410
|
||||
#define NOPUSH_MASK_7 32421
|
||||
#define NOPUSH_MASK_8 0
|
||||
#define NOPUSH_MASK_9 0
|
||||
/* Opcodes that are guaranteed to never push a value onto the stack
|
||||
** contain a 1 their corresponding position of the following mask
|
||||
** set. See the opcodeNoPush() function in vdbeaux.c */
|
||||
#define NOPUSH_MASK_0 0x3fbc
|
||||
#define NOPUSH_MASK_1 0x9e5b
|
||||
#define NOPUSH_MASK_2 0x9c77
|
||||
#define NOPUSH_MASK_3 0xfbf3
|
||||
#define NOPUSH_MASK_4 0xffff
|
||||
#define NOPUSH_MASK_5 0xdf3b
|
||||
#define NOPUSH_MASK_6 0x5f5d
|
||||
#define NOPUSH_MASK_7 0x4be7
|
||||
#define NOPUSH_MASK_8 0x3e00
|
||||
#define NOPUSH_MASK_9 0x0000
|
||||
|
||||
92
sqlitebrowser/sqlitebrowser/sqlite_source/os.c
Executable file
92
sqlitebrowser/sqlitebrowser/sqlite_source/os.c
Executable file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
** 2005 November 29
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This file contains OS interface code that is common to all
|
||||
** architectures.
|
||||
*/
|
||||
#define _SQLITE_OS_C_ 1
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** The following routines are convenience wrappers around methods
|
||||
** of the OsFile object. This is mostly just syntactic sugar. All
|
||||
** of this would be completely automatic if SQLite were coded using
|
||||
** C++ instead of plain old C.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile **pId){
|
||||
OsFile *id;
|
||||
if( pId!=0 && (id = *pId)!=0 ){
|
||||
return id->pMethod->xClose(pId);
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
int sqlite3OsOpenDirectory(OsFile *id, const char *zName){
|
||||
return id->pMethod->xOpenDirectory(id, zName);
|
||||
}
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
return id->pMethod->xRead(id, pBuf, amt);
|
||||
}
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
return id->pMethod->xWrite(id, pBuf, amt);
|
||||
}
|
||||
int sqlite3OsSeek(OsFile *id, i64 offset){
|
||||
return id->pMethod->xSeek(id, offset);
|
||||
}
|
||||
int sqlite3OsTruncate(OsFile *id, i64 size){
|
||||
return id->pMethod->xTruncate(id, size);
|
||||
}
|
||||
int sqlite3OsSync(OsFile *id, int fullsync){
|
||||
return id->pMethod->xSync(id, fullsync);
|
||||
}
|
||||
void sqlite3OsSetFullSync(OsFile *id, int value){
|
||||
id->pMethod->xSetFullSync(id, value);
|
||||
}
|
||||
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
|
||||
/* This method is currently only used while interactively debugging the
|
||||
** pager. More specificly, it can only be used when sqlite3DebugPrintf() is
|
||||
** included in the build. */
|
||||
int sqlite3OsFileHandle(OsFile *id){
|
||||
return id->pMethod->xFileHandle(id);
|
||||
}
|
||||
#endif
|
||||
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
|
||||
return id->pMethod->xFileSize(id, pSize);
|
||||
}
|
||||
int sqlite3OsLock(OsFile *id, int lockType){
|
||||
return id->pMethod->xLock(id, lockType);
|
||||
}
|
||||
int sqlite3OsUnlock(OsFile *id, int lockType){
|
||||
return id->pMethod->xUnlock(id, lockType);
|
||||
}
|
||||
int sqlite3OsLockState(OsFile *id){
|
||||
return id->pMethod->xLockState(id);
|
||||
}
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
return id->pMethod->xCheckReservedLock(id);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_REDEF_IO
|
||||
/*
|
||||
** A function to return a pointer to the virtual function table.
|
||||
** This routine really does not accomplish very much since the
|
||||
** virtual function table is a global variable and anybody who
|
||||
** can call this function can just as easily access the variable
|
||||
** for themselves. Nevertheless, we include this routine for
|
||||
** backwards compatibility with an earlier redefinable I/O
|
||||
** interface design.
|
||||
*/
|
||||
struct sqlite3OsVtbl *sqlite3_os_switch(void){
|
||||
return &sqlite3Os;
|
||||
}
|
||||
#endif
|
||||
@@ -18,12 +18,11 @@
|
||||
#define _SQLITE_OS_H_
|
||||
|
||||
/*
|
||||
** Figure out if we are dealing with Unix, Windows or MacOS.
|
||||
**
|
||||
** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
|
||||
** The MacOS build is designed to use CodeWarrior (tested with v8)
|
||||
** Figure out if we are dealing with Unix, Windows, or some other
|
||||
** operating system.
|
||||
*/
|
||||
#if !defined(OS_UNIX) && !defined(OS_TEST)
|
||||
#if !defined(OS_UNIX) && !defined(OS_OTHER)
|
||||
# define OS_OTHER 0
|
||||
# ifndef OS_WIN
|
||||
# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
|
||||
# define OS_WIN 1
|
||||
@@ -41,17 +40,15 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Invoke the appropriate operating-system specific header file.
|
||||
** Define the maximum size of a temporary filename
|
||||
*/
|
||||
#if OS_TEST
|
||||
# include "os_test.h"
|
||||
#endif
|
||||
#if OS_UNIX
|
||||
# include "os_unix.h"
|
||||
#endif
|
||||
#if OS_WIN
|
||||
# include "os_win.h"
|
||||
# include <windows.h>
|
||||
# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
|
||||
#else
|
||||
# define SQLITE_TEMPNAME_SIZE 200
|
||||
#endif
|
||||
|
||||
/* If the SET_FULLSYNC macro is not defined above, then make it
|
||||
@@ -74,6 +71,104 @@
|
||||
# define TEMP_FILE_PREFIX "sqlite_"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Define the interfaces for Unix and for Windows.
|
||||
*/
|
||||
#if OS_UNIX
|
||||
#define sqlite3OsOpenReadWrite sqlite3UnixOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3UnixOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3UnixOpenReadOnly
|
||||
#define sqlite3OsDelete sqlite3UnixDelete
|
||||
#define sqlite3OsFileExists sqlite3UnixFileExists
|
||||
#define sqlite3OsFullPathname sqlite3UnixFullPathname
|
||||
#define sqlite3OsIsDirWritable sqlite3UnixIsDirWritable
|
||||
#define sqlite3OsSyncDirectory sqlite3UnixSyncDirectory
|
||||
#define sqlite3OsTempFileName sqlite3UnixTempFileName
|
||||
#define sqlite3OsRandomSeed sqlite3UnixRandomSeed
|
||||
#define sqlite3OsSleep sqlite3UnixSleep
|
||||
#define sqlite3OsCurrentTime sqlite3UnixCurrentTime
|
||||
#define sqlite3OsEnterMutex sqlite3UnixEnterMutex
|
||||
#define sqlite3OsLeaveMutex sqlite3UnixLeaveMutex
|
||||
#define sqlite3OsInMutex sqlite3UnixInMutex
|
||||
#define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
|
||||
#define sqlite3OsMalloc sqlite3GenericMalloc
|
||||
#define sqlite3OsRealloc sqlite3GenericRealloc
|
||||
#define sqlite3OsFree sqlite3GenericFree
|
||||
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
|
||||
#endif
|
||||
#if OS_WIN
|
||||
#define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3WinOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3WinOpenReadOnly
|
||||
#define sqlite3OsDelete sqlite3WinDelete
|
||||
#define sqlite3OsFileExists sqlite3WinFileExists
|
||||
#define sqlite3OsFullPathname sqlite3WinFullPathname
|
||||
#define sqlite3OsIsDirWritable sqlite3WinIsDirWritable
|
||||
#define sqlite3OsSyncDirectory sqlite3WinSyncDirectory
|
||||
#define sqlite3OsTempFileName sqlite3WinTempFileName
|
||||
#define sqlite3OsRandomSeed sqlite3WinRandomSeed
|
||||
#define sqlite3OsSleep sqlite3WinSleep
|
||||
#define sqlite3OsCurrentTime sqlite3WinCurrentTime
|
||||
#define sqlite3OsEnterMutex sqlite3WinEnterMutex
|
||||
#define sqlite3OsLeaveMutex sqlite3WinLeaveMutex
|
||||
#define sqlite3OsInMutex sqlite3WinInMutex
|
||||
#define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
|
||||
#define sqlite3OsMalloc sqlite3GenericMalloc
|
||||
#define sqlite3OsRealloc sqlite3GenericRealloc
|
||||
#define sqlite3OsFree sqlite3GenericFree
|
||||
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If using an alternative OS interface, then we must have an "os_other.h"
|
||||
** header file available for that interface. Presumably the "os_other.h"
|
||||
** header file contains #defines similar to those above.
|
||||
*/
|
||||
#if OS_OTHER
|
||||
# include "os_other.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Forward declarations
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
typedef struct IoMethod IoMethod;
|
||||
|
||||
/*
|
||||
** An instance of the following structure contains pointers to all
|
||||
** methods on an OsFile object.
|
||||
*/
|
||||
struct IoMethod {
|
||||
int (*xClose)(OsFile**);
|
||||
int (*xOpenDirectory)(OsFile*, const char*);
|
||||
int (*xRead)(OsFile*, void*, int amt);
|
||||
int (*xWrite)(OsFile*, const void*, int amt);
|
||||
int (*xSeek)(OsFile*, i64 offset);
|
||||
int (*xTruncate)(OsFile*, i64 size);
|
||||
int (*xSync)(OsFile*, int);
|
||||
void (*xSetFullSync)(OsFile *id, int setting);
|
||||
int (*xFileHandle)(OsFile *id);
|
||||
int (*xFileSize)(OsFile*, i64 *pSize);
|
||||
int (*xLock)(OsFile*, int);
|
||||
int (*xUnlock)(OsFile*, int);
|
||||
int (*xLockState)(OsFile *id);
|
||||
int (*xCheckReservedLock)(OsFile *id);
|
||||
};
|
||||
|
||||
/*
|
||||
** The OsFile object describes an open disk file in an OS-dependent way.
|
||||
** The version of OsFile defined here is a generic version. Each OS
|
||||
** implementation defines its own subclass of this structure that contains
|
||||
** additional information needed to handle file I/O. But the pMethod
|
||||
** entry (pointing to the virtual function table) always occurs first
|
||||
** so that we can always find the appropriate methods.
|
||||
*/
|
||||
struct OsFile {
|
||||
IoMethod const *pMethod;
|
||||
};
|
||||
|
||||
/*
|
||||
** The following values may be passed as the second argument to
|
||||
** sqlite3OsLock(). The various locks exhibit the following semantics:
|
||||
@@ -128,8 +223,10 @@
|
||||
** a random byte is selected for a shared lock. The pool of bytes for
|
||||
** shared locks begins at SHARED_FIRST.
|
||||
**
|
||||
** These #defines are available in os.h so that Unix can use the same
|
||||
** byte ranges for locking. This leaves open the possiblity of having
|
||||
** These #defines are available in sqlite_aux.h so that adaptors for
|
||||
** connecting SQLite to other operating systems can use the same byte
|
||||
** ranges for locking. In particular, the same locking strategy and
|
||||
** byte ranges are used for Unix. This leaves open the possiblity of having
|
||||
** clients on win95, winNT, and unix all talking to the same shared file
|
||||
** and all locking correctly. To do so would require that samba (or whatever
|
||||
** tool is being used for file sharing) implements locks correctly between
|
||||
@@ -152,38 +249,192 @@
|
||||
** 1GB boundary.
|
||||
**
|
||||
*/
|
||||
#ifndef SQLITE_TEST
|
||||
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
|
||||
/* #define PENDING_BYTE 0x5400 // Page 22 - for testing */
|
||||
#else
|
||||
extern unsigned int sqlite3_pending_byte;
|
||||
#define PENDING_BYTE sqlite3_pending_byte
|
||||
#endif
|
||||
|
||||
#define RESERVED_BYTE (PENDING_BYTE+1)
|
||||
#define SHARED_FIRST (PENDING_BYTE+2)
|
||||
#define SHARED_SIZE 510
|
||||
|
||||
|
||||
int sqlite3OsDelete(const char*);
|
||||
int sqlite3OsFileExists(const char*);
|
||||
int sqlite3OsOpenReadWrite(const char*, OsFile*, int*);
|
||||
int sqlite3OsOpenExclusive(const char*, OsFile*, int);
|
||||
int sqlite3OsOpenReadOnly(const char*, OsFile*);
|
||||
int sqlite3OsOpenDirectory(const char*, OsFile*);
|
||||
int sqlite3OsSyncDirectory(const char*);
|
||||
int sqlite3OsTempFileName(char*);
|
||||
int sqlite3OsIsDirWritable(char*);
|
||||
int sqlite3OsClose(OsFile*);
|
||||
/*
|
||||
** Prototypes for operating system interface routines.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile**);
|
||||
int sqlite3OsOpenDirectory(OsFile*, const char*);
|
||||
int sqlite3OsRead(OsFile*, void*, int amt);
|
||||
int sqlite3OsWrite(OsFile*, const void*, int amt);
|
||||
int sqlite3OsSeek(OsFile*, i64 offset);
|
||||
int sqlite3OsSync(OsFile*);
|
||||
int sqlite3OsTruncate(OsFile*, i64 size);
|
||||
int sqlite3OsSync(OsFile*, int);
|
||||
void sqlite3OsSetFullSync(OsFile *id, int setting);
|
||||
int sqlite3OsFileHandle(OsFile *id);
|
||||
int sqlite3OsFileSize(OsFile*, i64 *pSize);
|
||||
int sqlite3OsLock(OsFile*, int);
|
||||
int sqlite3OsUnlock(OsFile*, int);
|
||||
int sqlite3OsLockState(OsFile *id);
|
||||
int sqlite3OsCheckReservedLock(OsFile *id);
|
||||
int sqlite3OsOpenReadWrite(const char*, OsFile**, int*);
|
||||
int sqlite3OsOpenExclusive(const char*, OsFile**, int);
|
||||
int sqlite3OsOpenReadOnly(const char*, OsFile**);
|
||||
int sqlite3OsDelete(const char*);
|
||||
int sqlite3OsFileExists(const char*);
|
||||
char *sqlite3OsFullPathname(const char*);
|
||||
int sqlite3OsIsDirWritable(char*);
|
||||
int sqlite3OsSyncDirectory(const char*);
|
||||
int sqlite3OsTempFileName(char*);
|
||||
int sqlite3OsRandomSeed(char*);
|
||||
int sqlite3OsSleep(int ms);
|
||||
int sqlite3OsCurrentTime(double*);
|
||||
int sqlite3OsFileModTime(OsFile*, double*);
|
||||
void sqlite3OsEnterMutex(void);
|
||||
void sqlite3OsLeaveMutex(void);
|
||||
char *sqlite3OsFullPathname(const char*);
|
||||
int sqlite3OsLock(OsFile*, int);
|
||||
int sqlite3OsUnlock(OsFile*, int);
|
||||
int sqlite3OsCheckReservedLock(OsFile *id);
|
||||
int sqlite3OsInMutex(int);
|
||||
ThreadData *sqlite3OsThreadSpecificData(int);
|
||||
void *sqlite3OsMalloc(int);
|
||||
void *sqlite3OsRealloc(void *, int);
|
||||
void sqlite3OsFree(void *);
|
||||
int sqlite3OsAllocationSize(void *);
|
||||
|
||||
/*
|
||||
** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
|
||||
** interface routines are not called directly but are invoked using
|
||||
** pointers to functions. This allows the implementation of various
|
||||
** OS-layer interface routines to be modified at run-time. There are
|
||||
** obscure but legitimate reasons for wanting to do this. But for
|
||||
** most users, a direct call to the underlying interface is preferable
|
||||
** so the the redefinable I/O interface is turned off by default.
|
||||
*/
|
||||
#ifdef SQLITE_ENABLE_REDEF_IO
|
||||
|
||||
/*
|
||||
** When redefinable I/O is enabled, a single global instance of the
|
||||
** following structure holds pointers to the routines that SQLite
|
||||
** uses to talk with the underlying operating system. Modify this
|
||||
** structure (before using any SQLite API!) to accomodate perculiar
|
||||
** operating system interfaces or behaviors.
|
||||
*/
|
||||
struct sqlite3OsVtbl {
|
||||
int (*xOpenReadWrite)(const char*, OsFile**, int*);
|
||||
int (*xOpenExclusive)(const char*, OsFile**, int);
|
||||
int (*xOpenReadOnly)(const char*, OsFile**);
|
||||
|
||||
int (*xDelete)(const char*);
|
||||
int (*xFileExists)(const char*);
|
||||
char *(*xFullPathname)(const char*);
|
||||
int (*xIsDirWritable)(char*);
|
||||
int (*xSyncDirectory)(const char*);
|
||||
int (*xTempFileName)(char*);
|
||||
|
||||
int (*xRandomSeed)(char*);
|
||||
int (*xSleep)(int ms);
|
||||
int (*xCurrentTime)(double*);
|
||||
|
||||
void (*xEnterMutex)(void);
|
||||
void (*xLeaveMutex)(void);
|
||||
int (*xInMutex)(int);
|
||||
ThreadData *(*xThreadSpecificData)(int);
|
||||
|
||||
void *(*xMalloc)(int);
|
||||
void *(*xRealloc)(void *, int);
|
||||
void (*xFree)(void *);
|
||||
int (*xAllocationSize)(void *);
|
||||
};
|
||||
|
||||
/* Macro used to comment out routines that do not exists when there is
|
||||
** no disk I/O
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_DISKIO
|
||||
# define IF_DISKIO(X) 0
|
||||
#else
|
||||
# define IF_DISKIO(X) X
|
||||
#endif
|
||||
|
||||
#ifdef _SQLITE_OS_C_
|
||||
/*
|
||||
** The os.c file implements the global virtual function table.
|
||||
*/
|
||||
struct sqlite3OsVtbl sqlite3Os = {
|
||||
IF_DISKIO( sqlite3OsOpenReadWrite ),
|
||||
IF_DISKIO( sqlite3OsOpenExclusive ),
|
||||
IF_DISKIO( sqlite3OsOpenReadOnly ),
|
||||
IF_DISKIO( sqlite3OsDelete ),
|
||||
IF_DISKIO( sqlite3OsFileExists ),
|
||||
IF_DISKIO( sqlite3OsFullPathname ),
|
||||
IF_DISKIO( sqlite3OsIsDirWritable ),
|
||||
IF_DISKIO( sqlite3OsSyncDirectory ),
|
||||
IF_DISKIO( sqlite3OsTempFileName ),
|
||||
sqlite3OsRandomSeed,
|
||||
sqlite3OsSleep,
|
||||
sqlite3OsCurrentTime,
|
||||
sqlite3OsEnterMutex,
|
||||
sqlite3OsLeaveMutex,
|
||||
sqlite3OsInMutex,
|
||||
sqlite3OsThreadSpecificData,
|
||||
sqlite3OsMalloc,
|
||||
sqlite3OsRealloc,
|
||||
sqlite3OsFree,
|
||||
sqlite3OsAllocationSize
|
||||
};
|
||||
#else
|
||||
/*
|
||||
** Files other than os.c just reference the global virtual function table.
|
||||
*/
|
||||
extern struct sqlite3OsVtbl sqlite3Os;
|
||||
#endif /* _SQLITE_OS_C_ */
|
||||
|
||||
|
||||
/* This additional API routine is available with redefinable I/O */
|
||||
struct sqlite3OsVtbl *sqlite3_os_switch(void);
|
||||
|
||||
|
||||
/*
|
||||
** Redefine the OS interface to go through the virtual function table
|
||||
** rather than calling routines directly.
|
||||
*/
|
||||
#undef sqlite3OsOpenReadWrite
|
||||
#undef sqlite3OsOpenExclusive
|
||||
#undef sqlite3OsOpenReadOnly
|
||||
#undef sqlite3OsDelete
|
||||
#undef sqlite3OsFileExists
|
||||
#undef sqlite3OsFullPathname
|
||||
#undef sqlite3OsIsDirWritable
|
||||
#undef sqlite3OsSyncDirectory
|
||||
#undef sqlite3OsTempFileName
|
||||
#undef sqlite3OsRandomSeed
|
||||
#undef sqlite3OsSleep
|
||||
#undef sqlite3OsCurrentTime
|
||||
#undef sqlite3OsEnterMutex
|
||||
#undef sqlite3OsLeaveMutex
|
||||
#undef sqlite3OsInMutex
|
||||
#undef sqlite3OsThreadSpecificData
|
||||
#undef sqlite3OsMalloc
|
||||
#undef sqlite3OsRealloc
|
||||
#undef sqlite3OsFree
|
||||
#undef sqlite3OsAllocationSize
|
||||
#define sqlite3OsOpenReadWrite sqlite3Os.xOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3Os.xOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3Os.xOpenReadOnly
|
||||
#define sqlite3OsDelete sqlite3Os.xDelete
|
||||
#define sqlite3OsFileExists sqlite3Os.xFileExists
|
||||
#define sqlite3OsFullPathname sqlite3Os.xFullPathname
|
||||
#define sqlite3OsIsDirWritable sqlite3Os.xIsDirWritable
|
||||
#define sqlite3OsSyncDirectory sqlite3Os.xSyncDirectory
|
||||
#define sqlite3OsTempFileName sqlite3Os.xTempFileName
|
||||
#define sqlite3OsRandomSeed sqlite3Os.xRandomSeed
|
||||
#define sqlite3OsSleep sqlite3Os.xSleep
|
||||
#define sqlite3OsCurrentTime sqlite3Os.xCurrentTime
|
||||
#define sqlite3OsEnterMutex sqlite3Os.xEnterMutex
|
||||
#define sqlite3OsLeaveMutex sqlite3Os.xLeaveMutex
|
||||
#define sqlite3OsInMutex sqlite3Os.xInMutex
|
||||
#define sqlite3OsThreadSpecificData sqlite3Os.xThreadSpecificData
|
||||
#define sqlite3OsMalloc sqlite3Os.xMalloc
|
||||
#define sqlite3OsRealloc sqlite3Os.xRealloc
|
||||
#define sqlite3OsFree sqlite3Os.xFree
|
||||
#define sqlite3OsAllocationSize sqlite3Os.xAllocationSize
|
||||
|
||||
#endif /* SQLITE_ENABLE_REDEF_IO */
|
||||
|
||||
#endif /* _SQLITE_OS_H_ */
|
||||
|
||||
@@ -28,6 +28,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* When testing, this global variable stores the location of the
|
||||
* pending-byte in the database file.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
unsigned int sqlite3_pending_byte = 0x40000000;
|
||||
#endif
|
||||
|
||||
int sqlite3_os_trace = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
static int last_page = 0;
|
||||
@@ -80,17 +88,26 @@ static unsigned int elapse;
|
||||
** is used for testing the I/O recovery logic.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_io_error_hit = 0;
|
||||
int sqlite3_io_error_pending = 0;
|
||||
int sqlite3_diskfull_pending = 0;
|
||||
int sqlite3_diskfull = 0;
|
||||
#define SimulateIOError(A) \
|
||||
if( sqlite3_io_error_pending ) \
|
||||
if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
|
||||
static void local_ioerr(){
|
||||
sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */
|
||||
sqlite3_io_error_hit = 1; /* Really just a place to set a breakpoint */
|
||||
}
|
||||
#define SimulateDiskfullError \
|
||||
if( sqlite3_diskfull_pending ) \
|
||||
if( sqlite3_diskfull_pending-- == 1 ){ local_ioerr(); return SQLITE_FULL; }
|
||||
if( sqlite3_diskfull_pending ){ \
|
||||
if( sqlite3_diskfull_pending == 1 ){ \
|
||||
local_ioerr(); \
|
||||
sqlite3_diskfull = 1; \
|
||||
return SQLITE_FULL; \
|
||||
}else{ \
|
||||
sqlite3_diskfull_pending--; \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define SimulateIOError(A)
|
||||
#define SimulateDiskfullError
|
||||
@@ -105,3 +122,67 @@ int sqlite3_open_file_count = 0;
|
||||
#else
|
||||
#define OpenCounter(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** sqlite3GenericMalloc
|
||||
** sqlite3GenericRealloc
|
||||
** sqlite3GenericOsFree
|
||||
** sqlite3GenericAllocationSize
|
||||
**
|
||||
** Implementation of the os level dynamic memory allocation interface in terms
|
||||
** of the standard malloc(), realloc() and free() found in many operating
|
||||
** systems. No rocket science here.
|
||||
**
|
||||
** There are two versions of these four functions here. The version
|
||||
** implemented here is only used if memory-management or memory-debugging is
|
||||
** enabled. This version allocates an extra 8-bytes at the beginning of each
|
||||
** block and stores the size of the allocation there.
|
||||
**
|
||||
** If neither memory-management or debugging is enabled, the second
|
||||
** set of implementations is used instead.
|
||||
*/
|
||||
#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || defined (SQLITE_MEMDEBUG)
|
||||
void *sqlite3GenericMalloc(int n){
|
||||
char *p = (char *)malloc(n+8);
|
||||
assert(n>0);
|
||||
assert(sizeof(int)<=8);
|
||||
if( p ){
|
||||
*(int *)p = n;
|
||||
p += 8;
|
||||
}
|
||||
return (void *)p;
|
||||
}
|
||||
void *sqlite3GenericRealloc(void *p, int n){
|
||||
char *p2 = ((char *)p - 8);
|
||||
assert(n>0);
|
||||
p2 = (char*)realloc(p2, n+8);
|
||||
if( p2 ){
|
||||
*(int *)p2 = n;
|
||||
p2 += 8;
|
||||
}
|
||||
return (void *)p2;
|
||||
}
|
||||
void sqlite3GenericFree(void *p){
|
||||
assert(p);
|
||||
free((void *)((char *)p - 8));
|
||||
}
|
||||
int sqlite3GenericAllocationSize(void *p){
|
||||
return p ? *(int *)((char *)p - 8) : 0;
|
||||
}
|
||||
#else
|
||||
void *sqlite3GenericMalloc(int n){
|
||||
char *p = (char *)malloc(n);
|
||||
return (void *)p;
|
||||
}
|
||||
void *sqlite3GenericRealloc(void *p, int n){
|
||||
assert(n>0);
|
||||
p = realloc(p, n);
|
||||
return p;
|
||||
}
|
||||
void sqlite3GenericFree(void *p){
|
||||
assert(p);
|
||||
free(p);
|
||||
}
|
||||
/* Never actually used, but needed for the linker */
|
||||
int sqlite3GenericAllocationSize(void *p){ return 0; }
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -13,9 +13,12 @@
|
||||
** subsystem. The page cache subsystem reads and writes a file a page
|
||||
** at a time and provides a journal for rollback.
|
||||
**
|
||||
** @(#) $Id: pager.h,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** @(#) $Id: pager.h,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PAGER_H_
|
||||
#define _PAGER_H_
|
||||
|
||||
/*
|
||||
** The default size of a database page.
|
||||
*/
|
||||
@@ -34,7 +37,7 @@
|
||||
** reasonable, like 1024.
|
||||
*/
|
||||
#ifndef SQLITE_MAX_PAGE_SIZE
|
||||
# define SQLITE_MAX_PAGE_SIZE 8192
|
||||
# define SQLITE_MAX_PAGE_SIZE 32768
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -71,7 +74,7 @@ int sqlite3pager_open(Pager **ppPager, const char *zFilename,
|
||||
void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
|
||||
void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
|
||||
void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
|
||||
void sqlite3pager_set_pagesize(Pager*, int);
|
||||
int sqlite3pager_set_pagesize(Pager*, int);
|
||||
void sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
|
||||
void sqlite3pager_set_cachesize(Pager*, int);
|
||||
int sqlite3pager_close(Pager *pPager);
|
||||
@@ -96,14 +99,16 @@ int sqlite3pager_stmt_rollback(Pager*);
|
||||
void sqlite3pager_dont_rollback(void*);
|
||||
void sqlite3pager_dont_write(Pager*, Pgno);
|
||||
int *sqlite3pager_stats(Pager*);
|
||||
void sqlite3pager_set_safety_level(Pager*,int);
|
||||
void sqlite3pager_set_safety_level(Pager*,int,int);
|
||||
const char *sqlite3pager_filename(Pager*);
|
||||
const char *sqlite3pager_dirname(Pager*);
|
||||
const char *sqlite3pager_journalname(Pager*);
|
||||
int sqlite3pager_nosync(Pager*);
|
||||
int sqlite3pager_rename(Pager*, const char *zNewName);
|
||||
void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
|
||||
int sqlite3pager_movepage(Pager*,void*,Pgno);
|
||||
int sqlite3pager_reset(Pager*);
|
||||
int sqlite3pager_release_memory(int);
|
||||
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
int sqlite3pager_lockstate(Pager*);
|
||||
@@ -113,3 +118,5 @@ int sqlite3pager_lockstate(Pager*);
|
||||
void sqlite3pager_refdump(Pager*);
|
||||
int pager3_refinfo_enable;
|
||||
#endif
|
||||
|
||||
#endif /* _PAGER_H_ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,142 +1,151 @@
|
||||
#define TK_END_OF_FILE 1
|
||||
#define TK_ILLEGAL 2
|
||||
#define TK_SPACE 3
|
||||
#define TK_UNCLOSED_STRING 4
|
||||
#define TK_COMMENT 5
|
||||
#define TK_FUNCTION 6
|
||||
#define TK_COLUMN 7
|
||||
#define TK_AGG_FUNCTION 8
|
||||
#define TK_SEMI 9
|
||||
#define TK_EXPLAIN 10
|
||||
#define TK_BEGIN 11
|
||||
#define TK_TRANSACTION 12
|
||||
#define TK_DEFERRED 13
|
||||
#define TK_IMMEDIATE 14
|
||||
#define TK_EXCLUSIVE 15
|
||||
#define TK_COMMIT 16
|
||||
#define TK_END 17
|
||||
#define TK_ROLLBACK 18
|
||||
#define TK_CREATE 19
|
||||
#define TK_TABLE 20
|
||||
#define TK_TEMP 21
|
||||
#define TK_LP 22
|
||||
#define TK_RP 23
|
||||
#define TK_AS 24
|
||||
#define TK_COMMA 25
|
||||
#define TK_ID 26
|
||||
#define TK_ABORT 27
|
||||
#define TK_AFTER 28
|
||||
#define TK_ASC 29
|
||||
#define TK_ATTACH 30
|
||||
#define TK_BEFORE 31
|
||||
#define TK_CASCADE 32
|
||||
#define TK_CONFLICT 33
|
||||
#define TK_DATABASE 34
|
||||
#define TK_DESC 35
|
||||
#define TK_DETACH 36
|
||||
#define TK_EACH 37
|
||||
#define TK_FAIL 38
|
||||
#define TK_FOR 39
|
||||
#define TK_GLOB 40
|
||||
#define TK_IGNORE 41
|
||||
#define TK_INITIALLY 42
|
||||
#define TK_INSTEAD 43
|
||||
#define TK_LIKE 44
|
||||
#define TK_MATCH 45
|
||||
#define TK_KEY 46
|
||||
#define TK_OF 47
|
||||
#define TK_OFFSET 48
|
||||
#define TK_PRAGMA 49
|
||||
#define TK_RAISE 50
|
||||
#define TK_REPLACE 51
|
||||
#define TK_RESTRICT 52
|
||||
#define TK_ROW 53
|
||||
#define TK_STATEMENT 54
|
||||
#define TK_TRIGGER 55
|
||||
#define TK_VACUUM 56
|
||||
#define TK_VIEW 57
|
||||
#define TK_REINDEX 58
|
||||
#define TK_RENAME 59
|
||||
#define TK_CDATE 60
|
||||
#define TK_CTIME 61
|
||||
#define TK_CTIMESTAMP 62
|
||||
#define TK_ALTER 63
|
||||
#define TK_OR 64
|
||||
#define TK_AND 65
|
||||
#define TK_NOT 66
|
||||
#define TK_IS 67
|
||||
#define TK_BETWEEN 68
|
||||
#define TK_IN 69
|
||||
#define TK_ISNULL 70
|
||||
#define TK_NOTNULL 71
|
||||
#define TK_NE 72
|
||||
#define TK_EQ 73
|
||||
#define TK_GT 74
|
||||
#define TK_LE 75
|
||||
#define TK_LT 76
|
||||
#define TK_GE 77
|
||||
#define TK_ESCAPE 78
|
||||
#define TK_BITAND 79
|
||||
#define TK_BITOR 80
|
||||
#define TK_LSHIFT 81
|
||||
#define TK_RSHIFT 82
|
||||
#define TK_PLUS 83
|
||||
#define TK_MINUS 84
|
||||
#define TK_STAR 85
|
||||
#define TK_SLASH 86
|
||||
#define TK_REM 87
|
||||
#define TK_CONCAT 88
|
||||
#define TK_UMINUS 89
|
||||
#define TK_UPLUS 90
|
||||
#define TK_BITNOT 91
|
||||
#define TK_STRING 92
|
||||
#define TK_JOIN_KW 93
|
||||
#define TK_CONSTRAINT 94
|
||||
#define TK_DEFAULT 95
|
||||
#define TK_NULL 96
|
||||
#define TK_PRIMARY 97
|
||||
#define TK_UNIQUE 98
|
||||
#define TK_CHECK 99
|
||||
#define TK_REFERENCES 100
|
||||
#define TK_COLLATE 101
|
||||
#define TK_AUTOINCR 102
|
||||
#define TK_ON 103
|
||||
#define TK_DELETE 104
|
||||
#define TK_UPDATE 105
|
||||
#define TK_INSERT 106
|
||||
#define TK_SET 107
|
||||
#define TK_DEFERRABLE 108
|
||||
#define TK_FOREIGN 109
|
||||
#define TK_DROP 110
|
||||
#define TK_UNION 111
|
||||
#define TK_ALL 112
|
||||
#define TK_INTERSECT 113
|
||||
#define TK_EXCEPT 114
|
||||
#define TK_SELECT 115
|
||||
#define TK_DISTINCT 116
|
||||
#define TK_DOT 117
|
||||
#define TK_FROM 118
|
||||
#define TK_JOIN 119
|
||||
#define TK_USING 120
|
||||
#define TK_ORDER 121
|
||||
#define TK_BY 122
|
||||
#define TK_GROUP 123
|
||||
#define TK_HAVING 124
|
||||
#define TK_LIMIT 125
|
||||
#define TK_WHERE 126
|
||||
#define TK_INTO 127
|
||||
#define TK_VALUES 128
|
||||
#define TK_INTEGER 129
|
||||
#define TK_FLOAT 130
|
||||
#define TK_BLOB 131
|
||||
#define TK_REGISTER 132
|
||||
#define TK_VARIABLE 133
|
||||
#define TK_EXISTS 134
|
||||
#define TK_CASE 135
|
||||
#define TK_WHEN 136
|
||||
#define TK_THEN 137
|
||||
#define TK_ELSE 138
|
||||
#define TK_INDEX 139
|
||||
#define TK_TO 140
|
||||
#define TK_ADD 141
|
||||
#define TK_COLUMNKW 142
|
||||
#define TK_SEMI 1
|
||||
#define TK_EXPLAIN 2
|
||||
#define TK_QUERY 3
|
||||
#define TK_PLAN 4
|
||||
#define TK_BEGIN 5
|
||||
#define TK_TRANSACTION 6
|
||||
#define TK_DEFERRED 7
|
||||
#define TK_IMMEDIATE 8
|
||||
#define TK_EXCLUSIVE 9
|
||||
#define TK_COMMIT 10
|
||||
#define TK_END 11
|
||||
#define TK_ROLLBACK 12
|
||||
#define TK_CREATE 13
|
||||
#define TK_TABLE 14
|
||||
#define TK_IF 15
|
||||
#define TK_NOT 16
|
||||
#define TK_EXISTS 17
|
||||
#define TK_TEMP 18
|
||||
#define TK_LP 19
|
||||
#define TK_RP 20
|
||||
#define TK_AS 21
|
||||
#define TK_COMMA 22
|
||||
#define TK_ID 23
|
||||
#define TK_ABORT 24
|
||||
#define TK_AFTER 25
|
||||
#define TK_ANALYZE 26
|
||||
#define TK_ASC 27
|
||||
#define TK_ATTACH 28
|
||||
#define TK_BEFORE 29
|
||||
#define TK_CASCADE 30
|
||||
#define TK_CAST 31
|
||||
#define TK_CONFLICT 32
|
||||
#define TK_DATABASE 33
|
||||
#define TK_DESC 34
|
||||
#define TK_DETACH 35
|
||||
#define TK_EACH 36
|
||||
#define TK_FAIL 37
|
||||
#define TK_FOR 38
|
||||
#define TK_IGNORE 39
|
||||
#define TK_INITIALLY 40
|
||||
#define TK_INSTEAD 41
|
||||
#define TK_LIKE_KW 42
|
||||
#define TK_MATCH 43
|
||||
#define TK_KEY 44
|
||||
#define TK_OF 45
|
||||
#define TK_OFFSET 46
|
||||
#define TK_PRAGMA 47
|
||||
#define TK_RAISE 48
|
||||
#define TK_REPLACE 49
|
||||
#define TK_RESTRICT 50
|
||||
#define TK_ROW 51
|
||||
#define TK_STATEMENT 52
|
||||
#define TK_TRIGGER 53
|
||||
#define TK_VACUUM 54
|
||||
#define TK_VIEW 55
|
||||
#define TK_REINDEX 56
|
||||
#define TK_RENAME 57
|
||||
#define TK_CTIME_KW 58
|
||||
#define TK_OR 59
|
||||
#define TK_AND 60
|
||||
#define TK_IS 61
|
||||
#define TK_BETWEEN 62
|
||||
#define TK_IN 63
|
||||
#define TK_ISNULL 64
|
||||
#define TK_NOTNULL 65
|
||||
#define TK_NE 66
|
||||
#define TK_EQ 67
|
||||
#define TK_GT 68
|
||||
#define TK_LE 69
|
||||
#define TK_LT 70
|
||||
#define TK_GE 71
|
||||
#define TK_ESCAPE 72
|
||||
#define TK_BITAND 73
|
||||
#define TK_BITOR 74
|
||||
#define TK_LSHIFT 75
|
||||
#define TK_RSHIFT 76
|
||||
#define TK_PLUS 77
|
||||
#define TK_MINUS 78
|
||||
#define TK_STAR 79
|
||||
#define TK_SLASH 80
|
||||
#define TK_REM 81
|
||||
#define TK_CONCAT 82
|
||||
#define TK_UMINUS 83
|
||||
#define TK_UPLUS 84
|
||||
#define TK_BITNOT 85
|
||||
#define TK_STRING 86
|
||||
#define TK_JOIN_KW 87
|
||||
#define TK_CONSTRAINT 88
|
||||
#define TK_DEFAULT 89
|
||||
#define TK_NULL 90
|
||||
#define TK_PRIMARY 91
|
||||
#define TK_UNIQUE 92
|
||||
#define TK_CHECK 93
|
||||
#define TK_REFERENCES 94
|
||||
#define TK_COLLATE 95
|
||||
#define TK_AUTOINCR 96
|
||||
#define TK_ON 97
|
||||
#define TK_DELETE 98
|
||||
#define TK_UPDATE 99
|
||||
#define TK_INSERT 100
|
||||
#define TK_SET 101
|
||||
#define TK_DEFERRABLE 102
|
||||
#define TK_FOREIGN 103
|
||||
#define TK_DROP 104
|
||||
#define TK_UNION 105
|
||||
#define TK_ALL 106
|
||||
#define TK_EXCEPT 107
|
||||
#define TK_INTERSECT 108
|
||||
#define TK_SELECT 109
|
||||
#define TK_DISTINCT 110
|
||||
#define TK_DOT 111
|
||||
#define TK_FROM 112
|
||||
#define TK_JOIN 113
|
||||
#define TK_USING 114
|
||||
#define TK_ORDER 115
|
||||
#define TK_BY 116
|
||||
#define TK_GROUP 117
|
||||
#define TK_HAVING 118
|
||||
#define TK_LIMIT 119
|
||||
#define TK_WHERE 120
|
||||
#define TK_INTO 121
|
||||
#define TK_VALUES 122
|
||||
#define TK_INTEGER 123
|
||||
#define TK_FLOAT 124
|
||||
#define TK_BLOB 125
|
||||
#define TK_REGISTER 126
|
||||
#define TK_VARIABLE 127
|
||||
#define TK_CASE 128
|
||||
#define TK_WHEN 129
|
||||
#define TK_THEN 130
|
||||
#define TK_ELSE 131
|
||||
#define TK_INDEX 132
|
||||
#define TK_ALTER 133
|
||||
#define TK_TO 134
|
||||
#define TK_ADD 135
|
||||
#define TK_COLUMNKW 136
|
||||
#define TK_TO_TEXT 137
|
||||
#define TK_TO_BLOB 138
|
||||
#define TK_TO_NUMERIC 139
|
||||
#define TK_TO_INT 140
|
||||
#define TK_TO_REAL 141
|
||||
#define TK_END_OF_FILE 142
|
||||
#define TK_ILLEGAL 143
|
||||
#define TK_SPACE 144
|
||||
#define TK_UNCLOSED_STRING 145
|
||||
#define TK_COMMENT 146
|
||||
#define TK_FUNCTION 147
|
||||
#define TK_COLUMN 148
|
||||
#define TK_AGG_FUNCTION 149
|
||||
#define TK_AGG_COLUMN 150
|
||||
#define TK_CONST_FUNC 151
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: pragma.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
/* Ignore this whole file if pragmas are disabled
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_PRAGMA
|
||||
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
|
||||
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
# include "pager.h"
|
||||
@@ -36,7 +36,7 @@
|
||||
** to support legacy SQL code. The safety level used to be boolean
|
||||
** and older scripts may have used numbers 0 for OFF and 1 for ON.
|
||||
*/
|
||||
static int getSafetyLevel(const u8 *z){
|
||||
static int getSafetyLevel(const char *z){
|
||||
/* 123456789 123456789 */
|
||||
static const char zText[] = "onoffalseyestruefull";
|
||||
static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
|
||||
@@ -58,7 +58,7 @@ static int getSafetyLevel(const u8 *z){
|
||||
/*
|
||||
** Interpret the given string as a boolean value.
|
||||
*/
|
||||
static int getBoolean(const u8 *z){
|
||||
static int getBoolean(const char *z){
|
||||
return getSafetyLevel(z)&1;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, value, 0);
|
||||
if( pParse->explain==0 ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, zLabel, P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
@@ -151,9 +151,18 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
{ "short_column_names", SQLITE_ShortColNames },
|
||||
{ "count_changes", SQLITE_CountRows },
|
||||
{ "empty_result_callbacks", SQLITE_NullCallback },
|
||||
{ "legacy_file_format", SQLITE_LegacyFileFmt },
|
||||
{ "fullfsync", SQLITE_FullFSync },
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
{ "ignore_check_constraints", SQLITE_IgnoreChecks },
|
||||
#endif
|
||||
/* The following is VERY experimental */
|
||||
{ "writable_schema", SQLITE_WriteSchema },
|
||||
{ "omit_readlock", SQLITE_NoReadlock },
|
||||
|
||||
/* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
|
||||
** flag if there are any active statements. */
|
||||
{ "read_uncommitted", SQLITE_ReadUncommitted },
|
||||
};
|
||||
int i;
|
||||
const struct sPragmaType *p;
|
||||
@@ -172,10 +181,6 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
db->flags &= ~p->mask;
|
||||
}
|
||||
}
|
||||
/* If one of these pragmas is executed, any prepared statements
|
||||
** need to be recompiled.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -266,7 +271,7 @@ void sqlite3Pragma(
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
if( !zRight ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "cache_size", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P3_STATIC);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
sqlite3VdbeChangeP1(v, addr, iDb);
|
||||
sqlite3VdbeChangeP1(v, addr+5, MAX_PAGES);
|
||||
@@ -280,8 +285,8 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
|
||||
sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2);
|
||||
pDb->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size);
|
||||
pDb->pSchema->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -342,12 +347,12 @@ void sqlite3Pragma(
|
||||
if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
if( !zRight ){
|
||||
returnSingleInt(pParse, "cache_size", pDb->cache_size);
|
||||
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
|
||||
}else{
|
||||
int size = atoi(zRight);
|
||||
if( size<0 ) size = -size;
|
||||
pDb->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size);
|
||||
pDb->pSchema->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -384,7 +389,8 @@ void sqlite3Pragma(
|
||||
if( !zRight ){
|
||||
if( sqlite3_temp_directory ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "temp_store_directory", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
|
||||
"temp_store_directory", P3_STATIC);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
@@ -428,7 +434,6 @@ void sqlite3Pragma(
|
||||
"Safety level may not be changed inside a transaction");
|
||||
}else{
|
||||
pDb->safety_level = getSafetyLevel(zRight)+1;
|
||||
sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level);
|
||||
}
|
||||
}
|
||||
}else
|
||||
@@ -460,22 +465,23 @@ void sqlite3Pragma(
|
||||
pTab = sqlite3FindTable(db, zRight, zDb);
|
||||
if( pTab ){
|
||||
int i;
|
||||
Column *pCol;
|
||||
sqlite3VdbeSetNumCols(v, 6);
|
||||
sqlite3VdbeSetColName(v, 0, "cid", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "type", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, "notnull", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, "dflt_value", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 5, "pk", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);
|
||||
sqlite3ViewGetColumnNames(pParse, pTab);
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
|
||||
pCol->zType ? pCol->zType : "numeric", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);
|
||||
sqlite3ExprCode(pParse, pCol->pDflt);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
|
||||
}
|
||||
}
|
||||
@@ -490,9 +496,9 @@ void sqlite3Pragma(
|
||||
int i;
|
||||
pTab = pIdx->pTable;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
sqlite3VdbeSetColName(v, 0, "seqno", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "cid", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC);
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
int cnum = pIdx->aiColumn[i];
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
@@ -515,9 +521,9 @@ void sqlite3Pragma(
|
||||
if( pIdx ){
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "unique", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC);
|
||||
while(pIdx){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
|
||||
@@ -534,9 +540,9 @@ void sqlite3Pragma(
|
||||
int i;
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "file", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].pBt==0 ) continue;
|
||||
assert( db->aDb[i].zName!=0 );
|
||||
@@ -552,8 +558,8 @@ void sqlite3Pragma(
|
||||
int i = 0;
|
||||
HashElem *p;
|
||||
sqlite3VdbeSetNumCols(v, 2);
|
||||
sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
|
||||
for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
|
||||
CollSeq *pColl = (CollSeq *)sqliteHashData(p);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
|
||||
@@ -575,20 +581,21 @@ void sqlite3Pragma(
|
||||
if( pFK ){
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 5);
|
||||
sqlite3VdbeSetColName(v, 0, "id", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "table", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, "from", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, "to", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC);
|
||||
while(pFK){
|
||||
int j;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
char *zCol = pFK->aCol[j].zCol;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, j, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->aCol[j].zCol, 0);
|
||||
sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
|
||||
}
|
||||
++i;
|
||||
@@ -602,26 +609,29 @@ void sqlite3Pragma(
|
||||
#ifndef NDEBUG
|
||||
if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
|
||||
extern void sqlite3ParserTrace(FILE*, char *);
|
||||
if( getBoolean(zRight) ){
|
||||
sqlite3ParserTrace(stdout, "parser: ");
|
||||
}else{
|
||||
sqlite3ParserTrace(0, 0);
|
||||
if( zRight ){
|
||||
if( getBoolean(zRight) ){
|
||||
sqlite3ParserTrace(stderr, "parser: ");
|
||||
}else{
|
||||
sqlite3ParserTrace(0, 0);
|
||||
}
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
|
||||
** used will be case sensitive or not depending on the RHS.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
|
||||
if( zRight ){
|
||||
sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
|
||||
}
|
||||
}else
|
||||
|
||||
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
|
||||
if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
|
||||
int i, j, addr;
|
||||
|
||||
/* Code that initializes the integrity check program. Set the
|
||||
** error count 0
|
||||
*/
|
||||
static const VdbeOpList initCode[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_MemStore, 0, 1, 0},
|
||||
};
|
||||
|
||||
/* Code that appears at the end of the integrity check. If no error
|
||||
** messages have been generated, output OK. Otherwise output the
|
||||
** error message
|
||||
@@ -637,12 +647,13 @@ void sqlite3Pragma(
|
||||
/* Initialize the VDBE program */
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
|
||||
sqlite3VdbeAddOpList(v, ArraySize(initCode), initCode);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, 0); /* Initialize error count to 0 */
|
||||
|
||||
/* Do an integrity check on each database file */
|
||||
for(i=0; i<db->nDb; i++){
|
||||
HashElem *x;
|
||||
Hash *pTbls;
|
||||
int cnt = 0;
|
||||
|
||||
if( OMIT_TEMPDB && i==1 ) continue;
|
||||
@@ -651,13 +662,13 @@ void sqlite3Pragma(
|
||||
|
||||
/* Do an integrity check of the B-Tree
|
||||
*/
|
||||
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
|
||||
pTbls = &db->aDb[i].pSchema->tblHash;
|
||||
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
|
||||
Table *pTab = sqliteHashData(x);
|
||||
Index *pIdx;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->tnum, 0);
|
||||
cnt++;
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto pragma_out;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->tnum, 0);
|
||||
cnt++;
|
||||
}
|
||||
@@ -666,34 +677,34 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeAddOp(v, OP_IntegrityCk, cnt, i);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 1);
|
||||
addr = sqlite3VdbeOp3(v, OP_String8, 0, 0, "ok", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_Eq, 0, addr+6);
|
||||
sqlite3VdbeAddOp(v, OP_Eq, 0, addr+7);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
sqlite3MPrintf("*** in database %s ***\n", db->aDb[i].zName),
|
||||
P3_DYNAMIC);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Concat, 0, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
|
||||
/* Make sure all the indices are constructed correctly.
|
||||
*/
|
||||
sqlite3CodeVerifySchema(pParse, i);
|
||||
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
|
||||
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
|
||||
Table *pTab = sqliteHashData(x);
|
||||
Index *pIdx;
|
||||
int loopTop;
|
||||
|
||||
if( pTab->pIndex==0 ) continue;
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, 1, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
|
||||
loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 1);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
int jmp2;
|
||||
static const VdbeOpList idxErr[] = {
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_MemIncr, 1, 0, 0},
|
||||
{ OP_String8, 0, 0, "rowid "},
|
||||
{ OP_Recno, 1, 0, 0},
|
||||
{ OP_Rowid, 1, 0, 0},
|
||||
{ OP_String8, 0, 0, " missing from index "},
|
||||
{ OP_String8, 0, 0, 0}, /* 4 */
|
||||
{ OP_Concat, 2, 0, 0},
|
||||
@@ -703,39 +714,38 @@ void sqlite3Pragma(
|
||||
jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
|
||||
sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
|
||||
sqlite3VdbeChangeP2(v, jmp2, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, jmp2);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
|
||||
sqlite3VdbeChangeP2(v, loopTop, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, loopTop);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
static const VdbeOpList cntIdx[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_MemStore, 2, 1, 0},
|
||||
{ OP_Rewind, 0, 0, 0}, /* 2 */
|
||||
{ OP_MemIncr, 2, 0, 0},
|
||||
{ OP_Next, 0, 0, 0}, /* 4 */
|
||||
{ OP_MemInt, 0, 2, 0},
|
||||
{ OP_Rewind, 0, 0, 0}, /* 1 */
|
||||
{ OP_MemIncr, 1, 2, 0},
|
||||
{ OP_Next, 0, 0, 0}, /* 3 */
|
||||
{ OP_MemLoad, 1, 0, 0},
|
||||
{ OP_MemLoad, 2, 0, 0},
|
||||
{ OP_Eq, 0, 0, 0}, /* 7 */
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_Eq, 0, 0, 0}, /* 6 */
|
||||
{ OP_MemIncr, 1, 0, 0},
|
||||
{ OP_String8, 0, 0, "wrong # of entries in index "},
|
||||
{ OP_String8, 0, 0, 0}, /* 10 */
|
||||
{ OP_String8, 0, 0, 0}, /* 9 */
|
||||
{ OP_Concat, 0, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( pIdx->tnum==0 ) continue;
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
|
||||
sqlite3VdbeChangeP1(v, addr+2, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+2, addr+5);
|
||||
sqlite3VdbeChangeP1(v, addr+4, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+4, addr+3);
|
||||
sqlite3VdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
|
||||
sqlite3VdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
|
||||
sqlite3VdbeChangeP1(v, addr+1, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+1, addr+4);
|
||||
sqlite3VdbeChangeP1(v, addr+3, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+3, addr+2);
|
||||
sqlite3VdbeJumpHere(v, addr+6);
|
||||
sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
|
||||
sqlite3VdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
|
||||
sqlite3VdbeJumpHere(v, addr+2);
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
|
||||
|
||||
@@ -782,10 +792,10 @@ void sqlite3Pragma(
|
||||
if( !zRight ){ /* "PRAGMA encoding" */
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "encoding", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( pEnc->enc==pParse->db->enc ){
|
||||
if( pEnc->enc==ENC(pParse->db) ){
|
||||
sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
|
||||
break;
|
||||
}
|
||||
@@ -797,10 +807,13 @@ void sqlite3Pragma(
|
||||
** will be overwritten when the schema is next loaded. If it does not
|
||||
** already exists, it will be created to use the new encoding value.
|
||||
*/
|
||||
if( !(pParse->db->flags&SQLITE_Initialized) ){
|
||||
if(
|
||||
!(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
|
||||
DbHasProperty(db, 0, DB_Empty)
|
||||
){
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
|
||||
pParse->db->enc = pEnc->enc;
|
||||
ENC(pParse->db) = pEnc->enc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -885,19 +898,19 @@ void sqlite3Pragma(
|
||||
int i;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
sqlite3VdbeSetNumCols(v, 2);
|
||||
sqlite3VdbeSetColName(v, 0, "database", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "status", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P3_STATIC);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
Btree *pBt;
|
||||
Pager *pPager;
|
||||
if( db->aDb[i].zName==0 ) continue;
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, P3_STATIC);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
|
||||
pBt = db->aDb[i].pBt;
|
||||
if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0, "closed", P3_STATIC);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
|
||||
}else{
|
||||
int j = sqlite3pager_lockstate(pPager);
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0,
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
(j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
|
||||
@@ -905,6 +918,23 @@ void sqlite3Pragma(
|
||||
}else
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_SSE
|
||||
/*
|
||||
** Check to see if the sqlite_statements table exists. Create it
|
||||
** if it does not.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
|
||||
extern int sqlite3CreateStatementsTable(Parse*);
|
||||
sqlite3CreateStatementsTable(pParse);
|
||||
}else
|
||||
#endif
|
||||
|
||||
#if SQLITE_HAS_CODEC
|
||||
if( sqlite3StrICmp(zLeft, "key")==0 ){
|
||||
sqlite3_key(db, zRight, strlen(zRight));
|
||||
}else
|
||||
#endif
|
||||
|
||||
{}
|
||||
|
||||
if( v ){
|
||||
@@ -913,10 +943,19 @@ void sqlite3Pragma(
|
||||
** are only valid for a single execution.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
|
||||
|
||||
/*
|
||||
** Reset the safety level, in case the fullfsync flag or synchronous
|
||||
** setting changed.
|
||||
*/
|
||||
if( db->autoCommit ){
|
||||
sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
|
||||
(db->flags&SQLITE_FullFSync)!=0);
|
||||
}
|
||||
}
|
||||
pragma_out:
|
||||
sqliteFree(zLeft);
|
||||
sqliteFree(zRight);
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_PRAGMA */
|
||||
#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */
|
||||
|
||||
633
sqlitebrowser/sqlitebrowser/sqlite_source/prepare.c
Normal file
633
sqlitebrowser/sqlitebrowser/sqlite_source/prepare.c
Normal file
@@ -0,0 +1,633 @@
|
||||
/*
|
||||
** 2005 May 25
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains the implementation of the sqlite3_prepare()
|
||||
** interface, and routines that contribute to loading the database schema
|
||||
** from disk.
|
||||
**
|
||||
** $Id: prepare.c,v 1.1 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** Fill the InitData structure with an error message that indicates
|
||||
** that the database is corrupt.
|
||||
*/
|
||||
static void corruptSchema(InitData *pData, const char *zExtra){
|
||||
if( !sqlite3MallocFailed() ){
|
||||
sqlite3SetString(pData->pzErrMsg, "malformed database schema",
|
||||
zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the callback routine for the code that initializes the
|
||||
** database. See sqlite3Init() below for additional information.
|
||||
** This routine is also called from the OP_ParseSchema opcode of the VDBE.
|
||||
**
|
||||
** Each callback contains the following information:
|
||||
**
|
||||
** argv[0] = name of thing being created
|
||||
** argv[1] = root page number for table or index. NULL for trigger or view.
|
||||
** argv[2] = SQL text for the CREATE statement.
|
||||
** argv[3] = "1" for temporary files, "0" for main database, "2" or more
|
||||
** for auxiliary database files.
|
||||
**
|
||||
*/
|
||||
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
|
||||
InitData *pData = (InitData*)pInit;
|
||||
sqlite3 *db = pData->db;
|
||||
int iDb;
|
||||
|
||||
if( sqlite3MallocFailed() ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
assert( argc==4 );
|
||||
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
||||
if( argv[1]==0 || argv[3]==0 ){
|
||||
corruptSchema(pData, 0);
|
||||
return 1;
|
||||
}
|
||||
iDb = atoi(argv[3]);
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
if( argv[2] && argv[2][0] ){
|
||||
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
|
||||
** But because db->init.busy is set to 1, no VDBE code is generated
|
||||
** or executed. All the parser does is build the internal data
|
||||
** structures that describe the table, index, or view.
|
||||
*/
|
||||
char *zErr;
|
||||
int rc;
|
||||
assert( db->init.busy );
|
||||
db->init.iDb = iDb;
|
||||
db->init.newTnum = atoi(argv[1]);
|
||||
rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
|
||||
db->init.iDb = 0;
|
||||
if( SQLITE_OK!=rc ){
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
sqlite3FailedMalloc();
|
||||
}else{
|
||||
corruptSchema(pData, zErr);
|
||||
}
|
||||
sqlite3_free(zErr);
|
||||
return rc;
|
||||
}
|
||||
}else{
|
||||
/* If the SQL column is blank it means this is an index that
|
||||
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
|
||||
** constraint for a CREATE TABLE. The index should have already
|
||||
** been created when we processed the CREATE TABLE. All we have
|
||||
** to do here is record the root page number for that index.
|
||||
*/
|
||||
Index *pIndex;
|
||||
pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
|
||||
if( pIndex==0 || pIndex->tnum!=0 ){
|
||||
/* This can occur if there exists an index on a TEMP table which
|
||||
** has the same name as another index on a permanent index. Since
|
||||
** the permanent table is hidden by the TEMP table, we can also
|
||||
** safely ignore the index on the permanent table.
|
||||
*/
|
||||
/* Do Nothing */;
|
||||
}else{
|
||||
pIndex->tnum = atoi(argv[1]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to read the database schema and initialize internal
|
||||
** data structures for a single database file. The index of the
|
||||
** database file is given by iDb. iDb==0 is used for the main
|
||||
** database. iDb==1 should never be used. iDb>=2 is used for
|
||||
** auxiliary databases. Return one of the SQLITE_ error codes to
|
||||
** indicate success or failure.
|
||||
*/
|
||||
static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
int rc;
|
||||
BtCursor *curMain;
|
||||
int size;
|
||||
Table *pTab;
|
||||
Db *pDb;
|
||||
char const *azArg[5];
|
||||
char zDbNum[30];
|
||||
int meta[10];
|
||||
InitData initData;
|
||||
char const *zMasterSchema;
|
||||
char const *zMasterName = SCHEMA_TABLE(iDb);
|
||||
|
||||
/*
|
||||
** The master database table has a structure like this
|
||||
*/
|
||||
static const char master_schema[] =
|
||||
"CREATE TABLE sqlite_master(\n"
|
||||
" type text,\n"
|
||||
" name text,\n"
|
||||
" tbl_name text,\n"
|
||||
" rootpage integer,\n"
|
||||
" sql text\n"
|
||||
")"
|
||||
;
|
||||
#ifndef SQLITE_OMIT_TEMPDB
|
||||
static const char temp_master_schema[] =
|
||||
"CREATE TEMP TABLE sqlite_temp_master(\n"
|
||||
" type text,\n"
|
||||
" name text,\n"
|
||||
" tbl_name text,\n"
|
||||
" rootpage integer,\n"
|
||||
" sql text\n"
|
||||
")"
|
||||
;
|
||||
#else
|
||||
#define temp_master_schema 0
|
||||
#endif
|
||||
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
assert( db->aDb[iDb].pSchema );
|
||||
|
||||
/* zMasterSchema and zInitScript are set to point at the master schema
|
||||
** and initialisation script appropriate for the database being
|
||||
** initialised. zMasterName is the name of the master table.
|
||||
*/
|
||||
if( !OMIT_TEMPDB && iDb==1 ){
|
||||
zMasterSchema = temp_master_schema;
|
||||
}else{
|
||||
zMasterSchema = master_schema;
|
||||
}
|
||||
zMasterName = SCHEMA_TABLE(iDb);
|
||||
|
||||
/* Construct the schema tables. */
|
||||
sqlite3SafetyOff(db);
|
||||
azArg[0] = zMasterName;
|
||||
azArg[1] = "1";
|
||||
azArg[2] = zMasterSchema;
|
||||
sprintf(zDbNum, "%d", iDb);
|
||||
azArg[3] = zDbNum;
|
||||
azArg[4] = 0;
|
||||
initData.db = db;
|
||||
initData.pzErrMsg = pzErrMsg;
|
||||
rc = sqlite3InitCallback(&initData, 4, (char **)azArg, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3SafetyOn(db);
|
||||
return rc;
|
||||
}
|
||||
pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
|
||||
if( pTab ){
|
||||
pTab->readOnly = 1;
|
||||
}
|
||||
sqlite3SafetyOn(db);
|
||||
|
||||
/* Create a cursor to hold the database open
|
||||
*/
|
||||
pDb = &db->aDb[iDb];
|
||||
if( pDb->pBt==0 ){
|
||||
if( !OMIT_TEMPDB && iDb==1 ){
|
||||
DbSetProperty(db, 1, DB_SchemaLoaded);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, 0, &curMain);
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
|
||||
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Get the database meta information.
|
||||
**
|
||||
** Meta values are as follows:
|
||||
** meta[0] Schema cookie. Changes with each schema change.
|
||||
** meta[1] File format of schema layer.
|
||||
** meta[2] Size of the page cache.
|
||||
** meta[3] Use freelist if 0. Autovacuum if greater than zero.
|
||||
** meta[4] Db text encoding. 1:UTF-8 3:UTF-16 LE 4:UTF-16 BE
|
||||
** meta[5] The user cookie. Used by the application.
|
||||
** meta[6]
|
||||
** meta[7]
|
||||
** meta[8]
|
||||
** meta[9]
|
||||
**
|
||||
** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
|
||||
** the possible values of meta[4].
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
int i;
|
||||
for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
|
||||
rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
|
||||
}
|
||||
if( rc ){
|
||||
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
return rc;
|
||||
}
|
||||
}else{
|
||||
memset(meta, 0, sizeof(meta));
|
||||
}
|
||||
pDb->pSchema->schema_cookie = meta[0];
|
||||
|
||||
/* If opening a non-empty database, check the text encoding. For the
|
||||
** main database, set sqlite3.enc to the encoding of the main database.
|
||||
** For an attached db, it is an error if the encoding is not the same
|
||||
** as sqlite3.enc.
|
||||
*/
|
||||
if( meta[4] ){ /* text encoding */
|
||||
if( iDb==0 ){
|
||||
/* If opening the main database, set ENC(db). */
|
||||
ENC(db) = (u8)meta[4];
|
||||
db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0);
|
||||
}else{
|
||||
/* If opening an attached database, the encoding much match ENC(db) */
|
||||
if( meta[4]!=ENC(db) ){
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
sqlite3SetString(pzErrMsg, "attached databases must use the same"
|
||||
" text encoding as main database", (char*)0);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
DbSetProperty(db, iDb, DB_Empty);
|
||||
}
|
||||
pDb->pSchema->enc = ENC(db);
|
||||
|
||||
size = meta[2];
|
||||
if( size==0 ){ size = MAX_PAGES; }
|
||||
pDb->pSchema->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
|
||||
|
||||
/*
|
||||
** file_format==1 Version 3.0.0.
|
||||
** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
|
||||
** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults
|
||||
** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
|
||||
*/
|
||||
pDb->pSchema->file_format = meta[1];
|
||||
if( pDb->pSchema->file_format==0 ){
|
||||
pDb->pSchema->file_format = 1;
|
||||
}
|
||||
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Read the schema information out of the schema tables
|
||||
*/
|
||||
assert( db->init.busy );
|
||||
if( rc==SQLITE_EMPTY ){
|
||||
/* For an empty database, there is nothing to read */
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
char *zSql;
|
||||
zSql = sqlite3MPrintf(
|
||||
"SELECT name, rootpage, sql, '%s' FROM '%q'.%s",
|
||||
zDbNum, db->aDb[iDb].zName, zMasterName);
|
||||
sqlite3SafetyOff(db);
|
||||
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
|
||||
sqlite3SafetyOn(db);
|
||||
sqliteFree(zSql);
|
||||
#ifndef SQLITE_OMIT_ANALYZE
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3AnalysisLoad(db, iDb);
|
||||
}
|
||||
#endif
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
}
|
||||
if( sqlite3MallocFailed() ){
|
||||
/* sqlite3SetString(pzErrMsg, "out of memory", (char*)0); */
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
DbSetProperty(db, iDb, DB_SchemaLoaded);
|
||||
}else{
|
||||
sqlite3ResetInternalSchema(db, iDb);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize all database files - the main database file, the file
|
||||
** used to store temporary tables, and any additional database files
|
||||
** created using ATTACH statements. Return a success code. If an
|
||||
** 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. If the database
|
||||
** file was of zero-length, then the DB_Empty flag is also set.
|
||||
*/
|
||||
int sqlite3Init(sqlite3 *db, char **pzErrMsg){
|
||||
int i, rc;
|
||||
int called_initone = 0;
|
||||
|
||||
if( db->init.busy ) return SQLITE_OK;
|
||||
rc = SQLITE_OK;
|
||||
db->init.busy = 1;
|
||||
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
||||
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
|
||||
rc = sqlite3InitOne(db, i, pzErrMsg);
|
||||
if( rc ){
|
||||
sqlite3ResetInternalSchema(db, i);
|
||||
}
|
||||
called_initone = 1;
|
||||
}
|
||||
|
||||
/* Once all the other databases have been initialised, load the schema
|
||||
** for the TEMP database. This is loaded last, as the TEMP database
|
||||
** schema may contain references to objects in other databases.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TEMPDB
|
||||
if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
|
||||
rc = sqlite3InitOne(db, 1, pzErrMsg);
|
||||
if( rc ){
|
||||
sqlite3ResetInternalSchema(db, 1);
|
||||
}
|
||||
called_initone = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
db->init.busy = 0;
|
||||
if( rc==SQLITE_OK && called_initone ){
|
||||
sqlite3CommitInternalChanges(db);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is a no-op if the database schema is already initialised.
|
||||
** Otherwise, the schema is loaded. An error code is returned.
|
||||
*/
|
||||
int sqlite3ReadSchema(Parse *pParse){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3 *db = pParse->db;
|
||||
if( !db->init.busy ){
|
||||
rc = sqlite3Init(db, &pParse->zErrMsg);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
pParse->rc = rc;
|
||||
pParse->nErr++;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Check schema cookies in all databases. If any cookie is out
|
||||
** of date, return 0. If all schema cookies are current, return 1.
|
||||
*/
|
||||
static int schemaIsValid(sqlite3 *db){
|
||||
int iDb;
|
||||
int rc;
|
||||
BtCursor *curTemp;
|
||||
int cookie;
|
||||
int allOk = 1;
|
||||
|
||||
for(iDb=0; allOk && iDb<db->nDb; iDb++){
|
||||
Btree *pBt;
|
||||
pBt = db->aDb[iDb].pBt;
|
||||
if( pBt==0 ) continue;
|
||||
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie);
|
||||
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].pSchema->schema_cookie ){
|
||||
allOk = 0;
|
||||
}
|
||||
sqlite3BtreeCloseCursor(curTemp);
|
||||
}
|
||||
}
|
||||
return allOk;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free all resources held by the schema structure. The void* argument points
|
||||
** at a Schema struct. This function does not call sqliteFree() on the
|
||||
** pointer itself, it just cleans up subsiduary resources (i.e. the contents
|
||||
** of the schema hash tables).
|
||||
*/
|
||||
void sqlite3SchemaFree(void *p){
|
||||
Hash temp1;
|
||||
Hash temp2;
|
||||
HashElem *pElem;
|
||||
Schema *pSchema = (Schema *)p;
|
||||
|
||||
temp1 = pSchema->tblHash;
|
||||
temp2 = pSchema->trigHash;
|
||||
sqlite3HashInit(&pSchema->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashClear(&pSchema->aFKey);
|
||||
sqlite3HashClear(&pSchema->idxHash);
|
||||
for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
|
||||
sqlite3DeleteTrigger((Trigger*)sqliteHashData(pElem));
|
||||
}
|
||||
sqlite3HashClear(&temp2);
|
||||
sqlite3HashInit(&pSchema->tblHash, SQLITE_HASH_STRING, 0);
|
||||
for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
|
||||
Table *pTab = sqliteHashData(pElem);
|
||||
sqlite3DeleteTable(0, pTab);
|
||||
}
|
||||
sqlite3HashClear(&temp1);
|
||||
pSchema->pSeqTab = 0;
|
||||
pSchema->flags &= ~DB_SchemaLoaded;
|
||||
}
|
||||
|
||||
/*
|
||||
** Find and return the schema associated with a BTree. Create
|
||||
** a new one if necessary.
|
||||
*/
|
||||
Schema *sqlite3SchemaGet(Btree *pBt){
|
||||
Schema * p;
|
||||
if( pBt ){
|
||||
p = (Schema *)sqlite3BtreeSchema(pBt,sizeof(Schema),sqlite3SchemaFree);
|
||||
}else{
|
||||
p = (Schema *)sqliteMalloc(sizeof(Schema));
|
||||
}
|
||||
if( p && 0==p->file_format ){
|
||||
sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&p->aFKey, SQLITE_HASH_STRING, 1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert a schema pointer into the iDb index that indicates
|
||||
** which database file in db->aDb[] the schema refers to.
|
||||
**
|
||||
** If the same database is attached more than once, the first
|
||||
** attached database is returned.
|
||||
*/
|
||||
int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
|
||||
int i = -1000000;
|
||||
|
||||
/* If pSchema is NULL, then return -1000000. 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
|
||||
** function should never be used.
|
||||
**
|
||||
** We return -1000000 instead of the more usual -1 simply because using
|
||||
** -1000000 as incorrectly using -1000000 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).
|
||||
*/
|
||||
if( pSchema ){
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].pSchema==pSchema ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert( i>=0 &&i>=0 && i<db->nDb );
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
|
||||
*/
|
||||
int sqlite3_prepare(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const char *zSql, /* UTF-8 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
|
||||
const char** pzTail /* OUT: End of parsed string */
|
||||
){
|
||||
Parse sParse;
|
||||
char *zErrMsg = 0;
|
||||
int rc = SQLITE_OK;
|
||||
int i;
|
||||
|
||||
/* Assert that malloc() has not failed */
|
||||
assert( !sqlite3MallocFailed() );
|
||||
|
||||
assert( ppStmt );
|
||||
*ppStmt = 0;
|
||||
if( sqlite3SafetyOn(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
/* If any attached database schemas are locked, do not proceed with
|
||||
** compilation. Instead return SQLITE_LOCKED immediately.
|
||||
*/
|
||||
for(i=0; i<db->nDb; i++) {
|
||||
Btree *pBt = db->aDb[i].pBt;
|
||||
if( pBt && sqlite3BtreeSchemaLocked(pBt) ){
|
||||
const char *zDb = db->aDb[i].zName;
|
||||
sqlite3Error(db, SQLITE_LOCKED, "database schema is locked: %s", zDb);
|
||||
sqlite3SafetyOff(db);
|
||||
return SQLITE_LOCKED;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&sParse, 0, sizeof(sParse));
|
||||
sParse.db = db;
|
||||
if( nBytes>=0 && zSql[nBytes]!=0 ){
|
||||
char *zSqlCopy = sqlite3StrNDup(zSql, nBytes);
|
||||
sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg);
|
||||
sParse.zTail += zSql - zSqlCopy;
|
||||
sqliteFree(zSqlCopy);
|
||||
}else{
|
||||
sqlite3RunParser(&sParse, zSql, &zErrMsg);
|
||||
}
|
||||
|
||||
if( sqlite3MallocFailed() ){
|
||||
sParse.rc = SQLITE_NOMEM;
|
||||
}
|
||||
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
|
||||
if( sParse.checkSchema && !schemaIsValid(db) ){
|
||||
sParse.rc = SQLITE_SCHEMA;
|
||||
}
|
||||
if( sParse.rc==SQLITE_SCHEMA ){
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
if( pzTail ) *pzTail = sParse.zTail;
|
||||
rc = sParse.rc;
|
||||
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
|
||||
if( sParse.explain==2 ){
|
||||
sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P3_STATIC);
|
||||
}else{
|
||||
sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P3_STATIC);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if( sqlite3SafetyOff(db) ){
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
*ppStmt = (sqlite3_stmt*)sParse.pVdbe;
|
||||
}else if( sParse.pVdbe ){
|
||||
sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
|
||||
}
|
||||
|
||||
if( zErrMsg ){
|
||||
sqlite3Error(db, rc, "%s", zErrMsg);
|
||||
sqliteFree(zErrMsg);
|
||||
}else{
|
||||
sqlite3Error(db, rc, 0);
|
||||
}
|
||||
|
||||
rc = sqlite3ApiExit(db, rc);
|
||||
sqlite3ReleaseThreadData();
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
|
||||
*/
|
||||
int sqlite3_prepare16(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const void *zSql, /* UTF-8 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
|
||||
const void **pzTail /* OUT: End of parsed string */
|
||||
){
|
||||
/* This function currently works by first transforming the UTF-16
|
||||
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
|
||||
** tricky bit is figuring out the pointer to return in *pzTail.
|
||||
*/
|
||||
char *zSql8;
|
||||
const char *zTail8 = 0;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
if( sqlite3SafetyCheck(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
zSql8 = sqlite3utf16to8(zSql, nBytes);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
|
||||
}
|
||||
|
||||
if( zTail8 && pzTail ){
|
||||
/* If sqlite3_prepare returns a tail pointer, we calculate the
|
||||
** equivalent pointer into the UTF-16 string by counting the unicode
|
||||
** characters between zSql8 and zTail8, and then returning a pointer
|
||||
** the same number of characters into the UTF-16 string.
|
||||
*/
|
||||
int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
|
||||
*pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
|
||||
}
|
||||
sqliteFree(zSql8);
|
||||
return sqlite3ApiExit(db, rc);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
@@ -111,6 +111,7 @@ static const char aPrefix[] = "-x0\000X0";
|
||||
static const et_info fmtinfo[] = {
|
||||
{ 'd', 10, 1, etRADIX, 0, 0 },
|
||||
{ 's', 0, 4, etSTRING, 0, 0 },
|
||||
{ 'g', 0, 1, etGENERIC, 30, 0 },
|
||||
{ 'z', 0, 6, etDYNSTRING, 0, 0 },
|
||||
{ 'q', 0, 4, etSQLESCAPE, 0, 0 },
|
||||
{ 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
|
||||
@@ -119,11 +120,12 @@ static const et_info fmtinfo[] = {
|
||||
{ 'u', 10, 0, etRADIX, 0, 0 },
|
||||
{ 'x', 16, 0, etRADIX, 16, 1 },
|
||||
{ 'X', 16, 0, etRADIX, 0, 4 },
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
{ 'f', 0, 1, etFLOAT, 0, 0 },
|
||||
{ 'e', 0, 1, etEXP, 30, 0 },
|
||||
{ 'E', 0, 1, etEXP, 14, 0 },
|
||||
{ 'g', 0, 1, etGENERIC, 30, 0 },
|
||||
{ 'G', 0, 1, etGENERIC, 14, 0 },
|
||||
#endif
|
||||
{ 'i', 10, 1, etRADIX, 0, 0 },
|
||||
{ 'n', 0, 0, etSIZE, 0, 0 },
|
||||
{ '%', 0, 0, etPERCENT, 0, 0 },
|
||||
@@ -134,10 +136,10 @@ static const et_info fmtinfo[] = {
|
||||
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
|
||||
|
||||
/*
|
||||
** If NOFLOATINGPOINT is defined, then none of the floating point
|
||||
** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
|
||||
** conversions will work.
|
||||
*/
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
/*
|
||||
** "*val" is a double such that 0.1 <= *val < 10.0
|
||||
** Return the ascii code for the leading digit of *val, then
|
||||
@@ -161,9 +163,17 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
|
||||
*val = (*val - d)*10.0;
|
||||
return digit;
|
||||
}
|
||||
#endif
|
||||
#endif /* SQLITE_OMIT_FLOATING_POINT */
|
||||
|
||||
#define etBUFSIZE 1000 /* Size of the output buffer */
|
||||
/*
|
||||
** On machines with a small stack size, you can redefine the
|
||||
** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for
|
||||
** smaller values some %f conversions may go into an infinite loop.
|
||||
*/
|
||||
#ifndef SQLITE_PRINT_BUF_SIZE
|
||||
# define SQLITE_PRINT_BUF_SIZE 350
|
||||
#endif
|
||||
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
|
||||
|
||||
/*
|
||||
** The root program. All variations call this core.
|
||||
@@ -210,9 +220,11 @@ static int vxprintf(
|
||||
etByte flag_plussign; /* True if "+" flag is present */
|
||||
etByte flag_blanksign; /* True if " " flag is present */
|
||||
etByte flag_alternateform; /* True if "#" flag is present */
|
||||
etByte flag_altform2; /* True if "!" flag is present */
|
||||
etByte flag_zeropad; /* True if field width constant starts with zero */
|
||||
etByte flag_long; /* True if "l" flag is present */
|
||||
etByte flag_longlong; /* True if the "ll" flag is present */
|
||||
etByte done; /* Loop termination flag */
|
||||
UINT64_TYPE longvalue; /* Value for integer types */
|
||||
LONGDOUBLE_TYPE realvalue; /* Value for real types */
|
||||
const et_info *infop; /* Pointer to the appropriate info structure */
|
||||
@@ -224,8 +236,8 @@ static int vxprintf(
|
||||
static const char spaces[] =
|
||||
" ";
|
||||
#define etSPACESIZE (sizeof(spaces)-1)
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
int exp; /* exponent of real numbers */
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
int exp, e2; /* exponent of real numbers */
|
||||
double rounder; /* Used for rounding floating point values */
|
||||
etByte flag_dp; /* True if decimal point should be shown */
|
||||
etByte flag_rtz; /* True if trailing zeros should be removed */
|
||||
@@ -254,17 +266,19 @@ static int vxprintf(
|
||||
}
|
||||
/* Find out what flags are present */
|
||||
flag_leftjustify = flag_plussign = flag_blanksign =
|
||||
flag_alternateform = flag_zeropad = 0;
|
||||
flag_alternateform = flag_altform2 = flag_zeropad = 0;
|
||||
done = 0;
|
||||
do{
|
||||
switch( c ){
|
||||
case '-': flag_leftjustify = 1; c = 0; break;
|
||||
case '+': flag_plussign = 1; c = 0; break;
|
||||
case ' ': flag_blanksign = 1; c = 0; break;
|
||||
case '#': flag_alternateform = 1; c = 0; break;
|
||||
case '0': flag_zeropad = 1; c = 0; break;
|
||||
default: break;
|
||||
case '-': flag_leftjustify = 1; break;
|
||||
case '+': flag_plussign = 1; break;
|
||||
case ' ': flag_blanksign = 1; break;
|
||||
case '#': flag_alternateform = 1; break;
|
||||
case '!': flag_altform2 = 1; break;
|
||||
case '0': flag_zeropad = 1; break;
|
||||
default: done = 1; break;
|
||||
}
|
||||
}while( c==0 && (c=(*++fmt))!=0 );
|
||||
}while( !done && (c=(*++fmt))!=0 );
|
||||
/* Get the field width */
|
||||
width = 0;
|
||||
if( c=='*' ){
|
||||
@@ -336,6 +350,7 @@ static int vxprintf(
|
||||
** At this point, variables are initialized as follows:
|
||||
**
|
||||
** flag_alternateform TRUE if a '#' is present.
|
||||
** flag_altform2 TRUE if a '!' is present.
|
||||
** flag_plussign TRUE if a '+' is present.
|
||||
** flag_leftjustify TRUE if a '-' is present or if the
|
||||
** field width was negative.
|
||||
@@ -412,9 +427,9 @@ static int vxprintf(
|
||||
case etEXP:
|
||||
case etGENERIC:
|
||||
realvalue = va_arg(ap,double);
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
if( precision<0 ) precision = 6; /* Set default precision */
|
||||
if( precision>etBUFSIZE-10 ) precision = etBUFSIZE-10;
|
||||
if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
|
||||
if( realvalue<0.0 ){
|
||||
realvalue = -realvalue;
|
||||
prefix = '-';
|
||||
@@ -423,8 +438,7 @@ static int vxprintf(
|
||||
else if( flag_blanksign ) prefix = ' ';
|
||||
else prefix = 0;
|
||||
}
|
||||
if( infop->type==etGENERIC && precision>0 ) precision--;
|
||||
rounder = 0.0;
|
||||
if( xtype==etGENERIC && precision>0 ) precision--;
|
||||
#if 0
|
||||
/* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
|
||||
for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
|
||||
@@ -432,10 +446,11 @@ static int vxprintf(
|
||||
/* It makes more sense to use 0.5 */
|
||||
for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);
|
||||
#endif
|
||||
if( infop->type==etFLOAT ) realvalue += rounder;
|
||||
if( xtype==etFLOAT ) realvalue += rounder;
|
||||
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
|
||||
exp = 0;
|
||||
if( realvalue>0.0 ){
|
||||
while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
|
||||
while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
|
||||
while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
|
||||
while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
|
||||
@@ -467,51 +482,67 @@ static int vxprintf(
|
||||
}else{
|
||||
flag_rtz = 0;
|
||||
}
|
||||
/*
|
||||
** The "exp+precision" test causes output to be of type etEXP if
|
||||
** the precision is too large to fit in buf[].
|
||||
*/
|
||||
if( xtype==etEXP ){
|
||||
e2 = 0;
|
||||
}else{
|
||||
e2 = exp;
|
||||
}
|
||||
nsd = 0;
|
||||
if( xtype==etFLOAT && exp+precision<etBUFSIZE-30 ){
|
||||
flag_dp = (precision>0 || flag_alternateform);
|
||||
if( prefix ) *(bufpt++) = prefix; /* Sign */
|
||||
if( exp<0 ) *(bufpt++) = '0'; /* Digits before "." */
|
||||
else for(; exp>=0; exp--) *(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
if( flag_dp ) *(bufpt++) = '.'; /* The decimal point */
|
||||
for(exp++; exp<0 && precision>0; precision--, exp++){
|
||||
*(bufpt++) = '0';
|
||||
}
|
||||
while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
*(bufpt--) = 0; /* Null terminate */
|
||||
if( flag_rtz && flag_dp ){ /* Remove trailing zeros and "." */
|
||||
while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;
|
||||
if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;
|
||||
}
|
||||
bufpt++; /* point to next free slot */
|
||||
}else{ /* etEXP or etGENERIC */
|
||||
flag_dp = (precision>0 || flag_alternateform);
|
||||
if( prefix ) *(bufpt++) = prefix; /* Sign */
|
||||
*(bufpt++) = et_getdigit(&realvalue,&nsd); /* First digit */
|
||||
if( flag_dp ) *(bufpt++) = '.'; /* Decimal point */
|
||||
while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
bufpt--; /* point to last digit */
|
||||
if( flag_rtz && flag_dp ){ /* Remove tail zeros */
|
||||
while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;
|
||||
if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;
|
||||
}
|
||||
bufpt++; /* point to next free slot */
|
||||
if( exp || flag_exp ){
|
||||
*(bufpt++) = aDigits[infop->charset];
|
||||
if( exp<0 ){ *(bufpt++) = '-'; exp = -exp; } /* sign of exp */
|
||||
else { *(bufpt++) = '+'; }
|
||||
if( exp>=100 ){
|
||||
*(bufpt++) = (exp/100)+'0'; /* 100's digit */
|
||||
exp %= 100;
|
||||
}
|
||||
*(bufpt++) = exp/10+'0'; /* 10's digit */
|
||||
*(bufpt++) = exp%10+'0'; /* 1's digit */
|
||||
flag_dp = (precision>0) | flag_alternateform | flag_altform2;
|
||||
/* The sign in front of the number */
|
||||
if( prefix ){
|
||||
*(bufpt++) = prefix;
|
||||
}
|
||||
/* Digits prior to the decimal point */
|
||||
if( e2<0 ){
|
||||
*(bufpt++) = '0';
|
||||
}else{
|
||||
for(; e2>=0; e2--){
|
||||
*(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
}
|
||||
}
|
||||
/* The decimal point */
|
||||
if( flag_dp ){
|
||||
*(bufpt++) = '.';
|
||||
}
|
||||
/* "0" digits after the decimal point but before the first
|
||||
** significant digit of the number */
|
||||
for(e2++; e2<0 && precision>0; precision--, e2++){
|
||||
*(bufpt++) = '0';
|
||||
}
|
||||
/* Significant digits after the decimal point */
|
||||
while( (precision--)>0 ){
|
||||
*(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
}
|
||||
/* Remove trailing zeros and the "." if no digits follow the "." */
|
||||
if( flag_rtz && flag_dp ){
|
||||
while( bufpt[-1]=='0' ) *(--bufpt) = 0;
|
||||
assert( bufpt>buf );
|
||||
if( bufpt[-1]=='.' ){
|
||||
if( flag_altform2 ){
|
||||
*(bufpt++) = '0';
|
||||
}else{
|
||||
*(--bufpt) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Add the "eNNN" suffix */
|
||||
if( flag_exp || (xtype==etEXP && exp) ){
|
||||
*(bufpt++) = aDigits[infop->charset];
|
||||
if( exp<0 ){
|
||||
*(bufpt++) = '-'; exp = -exp;
|
||||
}else{
|
||||
*(bufpt++) = '+';
|
||||
}
|
||||
if( exp>=100 ){
|
||||
*(bufpt++) = (exp/100)+'0'; /* 100's digit */
|
||||
exp %= 100;
|
||||
}
|
||||
*(bufpt++) = exp/10+'0'; /* 10's digit */
|
||||
*(bufpt++) = exp%10+'0'; /* 1's digit */
|
||||
}
|
||||
*bufpt = 0;
|
||||
|
||||
/* The converted number is in buf[] and zero terminated. Output it.
|
||||
** Note that the number is in the usual order, not reversed as with
|
||||
** integer conversions. */
|
||||
@@ -564,40 +595,39 @@ static int vxprintf(
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
break;
|
||||
case etSQLESCAPE:
|
||||
case etSQLESCAPE2:
|
||||
{
|
||||
int i, j, n, c, isnull;
|
||||
int needQuote;
|
||||
char *arg = va_arg(ap,char*);
|
||||
isnull = arg==0;
|
||||
if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
|
||||
for(i=n=0; (c=arg[i])!=0; i++){
|
||||
if( c=='\'' ) n++;
|
||||
}
|
||||
needQuote = !isnull && xtype==etSQLESCAPE2;
|
||||
n += i + 1 + needQuote*2;
|
||||
if( n>etBUFSIZE ){
|
||||
bufpt = zExtra = sqliteMalloc( n );
|
||||
if( bufpt==0 ) return -1;
|
||||
}else{
|
||||
bufpt = buf;
|
||||
}
|
||||
j = 0;
|
||||
if( needQuote ) bufpt[j++] = '\'';
|
||||
for(i=0; (c=arg[i])!=0; i++){
|
||||
bufpt[j++] = c;
|
||||
if( c=='\'' ) bufpt[j++] = c;
|
||||
}
|
||||
if( needQuote ) bufpt[j++] = '\'';
|
||||
bufpt[j] = 0;
|
||||
length = j;
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
case etSQLESCAPE2: {
|
||||
int i, j, n, ch, isnull;
|
||||
int needQuote;
|
||||
char *escarg = va_arg(ap,char*);
|
||||
isnull = escarg==0;
|
||||
if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
|
||||
for(i=n=0; (ch=escarg[i])!=0; i++){
|
||||
if( ch=='\'' ) n++;
|
||||
}
|
||||
needQuote = !isnull && xtype==etSQLESCAPE2;
|
||||
n += i + 1 + needQuote*2;
|
||||
if( n>etBUFSIZE ){
|
||||
bufpt = zExtra = sqliteMalloc( n );
|
||||
if( bufpt==0 ) return -1;
|
||||
}else{
|
||||
bufpt = buf;
|
||||
}
|
||||
j = 0;
|
||||
if( needQuote ) bufpt[j++] = '\'';
|
||||
for(i=0; (ch=escarg[i])!=0; i++){
|
||||
bufpt[j++] = ch;
|
||||
if( ch=='\'' ) bufpt[j++] = ch;
|
||||
}
|
||||
if( needQuote ) bufpt[j++] = '\'';
|
||||
bufpt[j] = 0;
|
||||
length = j;
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
break;
|
||||
}
|
||||
case etTOKEN: {
|
||||
Token *pToken = va_arg(ap, Token*);
|
||||
if( pToken && pToken->z ){
|
||||
(*func)(arg, pToken->z, pToken->n);
|
||||
(*func)(arg, (char*)pToken->z, pToken->n);
|
||||
}
|
||||
length = width = 0;
|
||||
break;
|
||||
@@ -698,7 +728,11 @@ static void mout(void *arg, const char *zNewText, int nNewChar){
|
||||
memcpy(pM->zText, pM->zBase, pM->nChar);
|
||||
}
|
||||
}else{
|
||||
pM->zText = pM->xRealloc(pM->zText, pM->nAlloc);
|
||||
char *zNew;
|
||||
zNew = pM->xRealloc(pM->zText, pM->nAlloc);
|
||||
if( zNew ){
|
||||
pM->zText = zNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -736,7 +770,10 @@ static char *base_vprintf(
|
||||
memcpy(sM.zText, sM.zBase, sM.nChar+1);
|
||||
}
|
||||
}else if( sM.nAlloc>sM.nChar+10 ){
|
||||
sM.zText = xRealloc(sM.zText, sM.nChar+1);
|
||||
char *zNew = xRealloc(sM.zText, sM.nChar+1);
|
||||
if( zNew ){
|
||||
sM.zText = zNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sM.zText;
|
||||
@@ -754,7 +791,7 @@ static void *printf_realloc(void *old, int size){
|
||||
** %-conversion extensions.
|
||||
*/
|
||||
char *sqlite3VMPrintf(const char *zFormat, va_list ap){
|
||||
char zBase[1000];
|
||||
char zBase[SQLITE_PRINT_BUF_SIZE];
|
||||
return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
|
||||
}
|
||||
|
||||
@@ -765,7 +802,7 @@ char *sqlite3VMPrintf(const char *zFormat, va_list ap){
|
||||
char *sqlite3MPrintf(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char *z;
|
||||
char zBase[1000];
|
||||
char zBase[SQLITE_PRINT_BUF_SIZE];
|
||||
va_start(ap, zFormat);
|
||||
z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
** Random numbers are used by some of the database backends in order
|
||||
** to generate random integer keys for tables or random filenames.
|
||||
**
|
||||
** $Id: random.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: random.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -26,13 +26,16 @@
|
||||
** must be held while executing this routine.
|
||||
**
|
||||
** Why not just use a library random generator like lrand48() for this?
|
||||
** Because the OP_NewRecno opcode in the VDBE depends on having a very
|
||||
** Because the OP_NewRowid opcode in the VDBE depends on having a very
|
||||
** good source of random numbers. The lrand48() library function may
|
||||
** well be good enough. But maybe not. Or maybe lrand48() has some
|
||||
** subtle problems on some systems that could cause problems. It is hard
|
||||
** to know. To minimize the risk of problems due to bad lrand48()
|
||||
** implementations, SQLite uses this random number generator based
|
||||
** on RC4, which we know works very well.
|
||||
**
|
||||
** (Later): Actually, OP_NewRowid does not depend on a good source of
|
||||
** randomness any more. But we will leave this code in all the same.
|
||||
*/
|
||||
static int randomByte(){
|
||||
unsigned char t;
|
||||
@@ -95,6 +98,3 @@ void sqlite3Randomness(int N, void *pBuf){
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@
|
||||
** This header file defines the interface that the SQLite library
|
||||
** presents to client programs.
|
||||
**
|
||||
** @(#) $Id: sqlite3.h,v 1.3 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** @(#) $Id: sqlite3.h,v 1.4 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#ifndef _SQLITE3_H_
|
||||
#define _SQLITE3_H_
|
||||
@@ -31,7 +31,7 @@ extern "C" {
|
||||
#ifdef SQLITE_VERSION
|
||||
# undef SQLITE_VERSION
|
||||
#endif
|
||||
#define SQLITE_VERSION "3.2.1"
|
||||
#define SQLITE_VERSION "3.3.4"
|
||||
|
||||
/*
|
||||
** The format of the version string is "X.Y.Z<trailing string>", where
|
||||
@@ -48,7 +48,7 @@ extern "C" {
|
||||
#ifdef SQLITE_VERSION_NUMBER
|
||||
# undef SQLITE_VERSION_NUMBER
|
||||
#endif
|
||||
#define SQLITE_VERSION_NUMBER 3002001
|
||||
#define SQLITE_VERSION_NUMBER 3003004
|
||||
|
||||
/*
|
||||
** The version string is also compiled into the library so that a program
|
||||
@@ -86,6 +86,13 @@ typedef struct sqlite3 sqlite3;
|
||||
typedef unsigned long long int sqlite_uint64;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If compiling for a processor that lacks floating point support,
|
||||
** substitute integer for floating-point
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_FLOATING_POINT
|
||||
# define double sqlite_int64
|
||||
#endif
|
||||
|
||||
/*
|
||||
** A function to close the database.
|
||||
@@ -157,8 +164,9 @@ int sqlite3_exec(
|
||||
** Return values for sqlite3_exec() and sqlite3_step()
|
||||
*/
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
/* beginning-of-error-codes */
|
||||
#define SQLITE_ERROR 1 /* SQL error or missing database */
|
||||
#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */
|
||||
#define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
|
||||
#define SQLITE_PERM 3 /* Access permission denied */
|
||||
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SQLITE_BUSY 5 /* The database file is locked */
|
||||
@@ -168,13 +176,13 @@ int sqlite3_exec(
|
||||
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
|
||||
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */
|
||||
#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
|
||||
#define SQLITE_FULL 13 /* Insertion failed because database is full */
|
||||
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
|
||||
#define SQLITE_EMPTY 16 /* Database is empty */
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */
|
||||
#define SQLITE_TOOBIG 18 /* NOT USED. Too much data for one row */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
@@ -185,6 +193,7 @@ int sqlite3_exec(
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||
/* end-of-error-codes */
|
||||
|
||||
/*
|
||||
** Each entry in an SQLite table has a unique integer key. (The key is
|
||||
@@ -373,8 +382,9 @@ void sqlite3_free_table(char **result);
|
||||
**
|
||||
** We can use this text in an SQL statement as follows:
|
||||
**
|
||||
** sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')",
|
||||
** callback1, 0, 0, zText);
|
||||
** char *z = sqlite3_mprintf("INSERT INTO TABLES('%q')", zText);
|
||||
** sqlite3_exec(db, z, callback1, 0, 0);
|
||||
** sqlite3_free(z);
|
||||
**
|
||||
** Because the %q format string is used, the '\'' character in zText
|
||||
** is escaped and the SQL generated is as follows:
|
||||
@@ -452,6 +462,7 @@ int sqlite3_set_authorizer(
|
||||
#define SQLITE_DETACH 25 /* Database Name NULL */
|
||||
#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
|
||||
#define SQLITE_REINDEX 27 /* Index Name NULL */
|
||||
#define SQLITE_ANALYZE 28 /* Table Name NULL */
|
||||
|
||||
|
||||
/*
|
||||
@@ -463,11 +474,18 @@ int sqlite3_set_authorizer(
|
||||
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
|
||||
|
||||
/*
|
||||
** Register a function that is called at every invocation of sqlite3_exec()
|
||||
** or sqlite3_prepare(). This function can be used (for example) to generate
|
||||
** a log file of all SQL executed against a database.
|
||||
** Register a function for tracing SQL command evaluation. The function
|
||||
** registered by sqlite3_trace() is invoked at the first sqlite3_step()
|
||||
** for the evaluation of an SQL statement. The function registered by
|
||||
** sqlite3_profile() runs at the end of each SQL statement and includes
|
||||
** information on how long that statement ran.
|
||||
**
|
||||
** The sqlite3_profile() API is currently considered experimental and
|
||||
** is subject to change.
|
||||
*/
|
||||
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
|
||||
void *sqlite3_profile(sqlite3*,
|
||||
void(*xProfile)(void*,const char*,sqlite_uint64), void*);
|
||||
|
||||
/*
|
||||
** This routine configures a callback function - the progress callback - that
|
||||
@@ -688,8 +706,6 @@ int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
|
||||
|
||||
/*
|
||||
** Set all the parameters in the compiled SQL statement to NULL.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
int sqlite3_clear_bindings(sqlite3_stmt*);
|
||||
|
||||
@@ -709,6 +725,30 @@ int sqlite3_column_count(sqlite3_stmt *pStmt);
|
||||
const char *sqlite3_column_name(sqlite3_stmt*,int);
|
||||
const void *sqlite3_column_name16(sqlite3_stmt*,int);
|
||||
|
||||
/*
|
||||
** The first parameter to the following calls is a compiled SQL statement.
|
||||
** These functions return information about the Nth column returned by
|
||||
** the statement, where N is the second function argument.
|
||||
**
|
||||
** If the Nth column returned by the statement is not a column value,
|
||||
** then all of the functions return NULL. Otherwise, the return the
|
||||
** name of the attached database, table and column that the expression
|
||||
** extracts a value from.
|
||||
**
|
||||
** As with all other SQLite APIs, those postfixed with "16" return UTF-16
|
||||
** encoded strings, the other functions return UTF-8. The memory containing
|
||||
** the returned strings is valid until the statement handle is finalized().
|
||||
**
|
||||
** These APIs are only available if the library was compiled with the
|
||||
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
|
||||
*/
|
||||
const char *sqlite3_column_database_name(sqlite3_stmt*,int);
|
||||
const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
|
||||
const char *sqlite3_column_table_name(sqlite3_stmt*,int);
|
||||
const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
|
||||
const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
|
||||
const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
|
||||
|
||||
/*
|
||||
** The first parameter is a compiled SQL statement. If this statement
|
||||
** is a SELECT statement, the Nth column of the returned result set
|
||||
@@ -721,7 +761,7 @@ const void *sqlite3_column_name16(sqlite3_stmt*,int);
|
||||
**
|
||||
** And the following statement compiled:
|
||||
**
|
||||
** SELECT c1 + 1, 0 FROM t1;
|
||||
** SELECT c1 + 1, c1 FROM t1;
|
||||
**
|
||||
** Then this routine would return the string "VARIANT" for the second
|
||||
** result column (i==1), and a NULL pointer for the first result column
|
||||
@@ -741,7 +781,7 @@ const char *sqlite3_column_decltype(sqlite3_stmt *, int i);
|
||||
**
|
||||
** And the following statement compiled:
|
||||
**
|
||||
** SELECT c1 + 1, 0 FROM t1;
|
||||
** SELECT c1 + 1, c1 FROM t1;
|
||||
**
|
||||
** Then this routine would return the string "INTEGER" for the second
|
||||
** result column (i==1), and a NULL pointer for the first result column
|
||||
@@ -882,6 +922,7 @@ sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
|
||||
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
|
||||
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
|
||||
int sqlite3_column_type(sqlite3_stmt*, int iCol);
|
||||
int sqlite3_column_numeric_type(sqlite3_stmt*, int iCol);
|
||||
|
||||
/*
|
||||
** The sqlite3_finalize() function is called to delete a compiled
|
||||
@@ -965,9 +1006,8 @@ int sqlite3_create_function16(
|
||||
);
|
||||
|
||||
/*
|
||||
** The next routine returns the number of calls to xStep for a particular
|
||||
** aggregate function instance. The current call to xStep counts so this
|
||||
** routine always returns at least 1.
|
||||
** This function is deprecated. Do not use it. It continues to exist
|
||||
** so as not to break legacy code. But new code should avoid using it.
|
||||
*/
|
||||
int sqlite3_aggregate_count(sqlite3_context*);
|
||||
|
||||
@@ -990,6 +1030,7 @@ const void *sqlite3_value_text16(sqlite3_value*);
|
||||
const void *sqlite3_value_text16le(sqlite3_value*);
|
||||
const void *sqlite3_value_text16be(sqlite3_value*);
|
||||
int sqlite3_value_type(sqlite3_value*);
|
||||
int sqlite3_value_numeric_type(sqlite3_value*);
|
||||
|
||||
/*
|
||||
** Aggregate functions use the following routine to allocate
|
||||
@@ -1004,10 +1045,9 @@ int sqlite3_value_type(sqlite3_value*);
|
||||
void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
|
||||
|
||||
/*
|
||||
** The pUserData parameter to the sqlite3_create_function() and
|
||||
** sqlite3_create_aggregate() routines used to register user functions
|
||||
** is available to the implementation of the function using this
|
||||
** call.
|
||||
** The pUserData parameter to the sqlite3_create_function()
|
||||
** routine used to register user functions is available to
|
||||
** the implementation of the function using this call.
|
||||
*/
|
||||
void *sqlite3_user_data(sqlite3_context*);
|
||||
|
||||
@@ -1191,20 +1231,17 @@ int sqlite3_rekey(
|
||||
** milisecond time resolution, then the time will be rounded up to
|
||||
** the nearest second. The number of miliseconds of sleep actually
|
||||
** requested from the operating system is returned.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
int sqlite3_sleep(int);
|
||||
|
||||
/*
|
||||
** Return TRUE (non-zero) of the statement supplied as an argument needs
|
||||
** Return TRUE (non-zero) if the statement supplied as an argument needs
|
||||
** to be recompiled. A statement needs to be recompiled whenever the
|
||||
** execution environment changes in a way that would alter the program
|
||||
** that sqlite3_prepare() generates. For example, if new functions or
|
||||
** collating sequences are registered or if an authorizer function is
|
||||
** added or changed.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
int sqlite3_expired(sqlite3_stmt*);
|
||||
|
||||
@@ -1214,8 +1251,6 @@ int sqlite3_expired(sqlite3_stmt*);
|
||||
** fails with an SQLITE_SCHEMA error. The same SQL can be prepared into
|
||||
** the second prepared statement then all of the bindings transfered over
|
||||
** to the second statement before the first statement is finalized.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
|
||||
|
||||
@@ -1250,7 +1285,192 @@ extern char *sqlite3_temp_directory;
|
||||
** This functionality can be omitted from a build by defining the
|
||||
** SQLITE_OMIT_GLOBALRECOVER at compile time.
|
||||
*/
|
||||
int sqlite3_global_recover();
|
||||
int sqlite3_global_recover(void);
|
||||
|
||||
/*
|
||||
** Test to see whether or not the database connection is in autocommit
|
||||
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
|
||||
** by default. Autocommit is disabled by a BEGIN statement and reenabled
|
||||
** by the next COMMIT or ROLLBACK.
|
||||
*/
|
||||
int sqlite3_get_autocommit(sqlite3*);
|
||||
|
||||
/*
|
||||
** Return the sqlite3* database handle to which the prepared statement given
|
||||
** in the argument belongs. This is the same database handle that was
|
||||
** the first argument to the sqlite3_prepare() that was used to create
|
||||
** the statement in the first place.
|
||||
*/
|
||||
sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
|
||||
|
||||
/*
|
||||
** Register a callback function with the database connection identified by the
|
||||
** first argument to be invoked whenever a row is updated, inserted or deleted.
|
||||
** Any callback set by a previous call to this function for the same
|
||||
** database connection is overridden.
|
||||
**
|
||||
** The second argument is a pointer to the function to invoke when a
|
||||
** row is updated, inserted or deleted. The first argument to the callback is
|
||||
** a copy of the third argument to sqlite3_update_hook. The second callback
|
||||
** argument is one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE, depending
|
||||
** on the operation that caused the callback to be invoked. The third and
|
||||
** fourth arguments to the callback contain pointers to the database and
|
||||
** table name containing the affected row. The final callback parameter is
|
||||
** the rowid of the row. In the case of an update, this is the rowid after
|
||||
** the update takes place.
|
||||
**
|
||||
** The update hook is not invoked when internal system tables are
|
||||
** modified (i.e. sqlite_master and sqlite_sequence).
|
||||
**
|
||||
** If another function was previously registered, its pArg value is returned.
|
||||
** Otherwise NULL is returned.
|
||||
*/
|
||||
void *sqlite3_update_hook(
|
||||
sqlite3*,
|
||||
void(*)(void *,int ,char const *,char const *,sqlite_int64),
|
||||
void*
|
||||
);
|
||||
|
||||
/*
|
||||
** Register a callback to be invoked whenever a transaction is rolled
|
||||
** back.
|
||||
**
|
||||
** The new callback function overrides any existing rollback-hook
|
||||
** callback. If there was an existing callback, then it's pArg value
|
||||
** (the third argument to sqlite3_rollback_hook() when it was registered)
|
||||
** is returned. Otherwise, NULL is returned.
|
||||
**
|
||||
** For the purposes of this API, a transaction is said to have been
|
||||
** rolled back if an explicit "ROLLBACK" statement is executed, or
|
||||
** an error or constraint causes an implicit rollback to occur. The
|
||||
** callback is not invoked if a transaction is automatically rolled
|
||||
** back because the database connection is closed.
|
||||
*/
|
||||
void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
|
||||
|
||||
/*
|
||||
** This function is only available if the library is compiled without
|
||||
** the SQLITE_OMIT_SHARED_CACHE macro defined. It is used to enable or
|
||||
** disable (if the argument is true or false, respectively) the
|
||||
** "shared pager" feature.
|
||||
*/
|
||||
int sqlite3_enable_shared_cache(int);
|
||||
|
||||
/*
|
||||
** Attempt to free N bytes of heap memory by deallocating non-essential
|
||||
** memory allocations held by the database library (example: memory
|
||||
** used to cache database pages to improve performance).
|
||||
**
|
||||
** This function is not a part of standard builds. It is only created
|
||||
** if SQLite is compiled with the SQLITE_ENABLE_MEMORY_MANAGEMENT macro.
|
||||
*/
|
||||
int sqlite3_release_memory(int);
|
||||
|
||||
/*
|
||||
** Place a "soft" limit on the amount of heap memory that may be allocated by
|
||||
** SQLite within the current thread. If an internal allocation is requested
|
||||
** that would exceed the specified limit, sqlite3_release_memory() is invoked
|
||||
** one or more times to free up some space before the allocation is made.
|
||||
**
|
||||
** The limit is called "soft", because if sqlite3_release_memory() cannot free
|
||||
** sufficient memory to prevent the limit from being exceeded, the memory is
|
||||
** allocated anyway and the current operation proceeds.
|
||||
**
|
||||
** This function is only available if the library was compiled with the
|
||||
** SQLITE_ENABLE_MEMORY_MANAGEMENT option set.
|
||||
** memory-management has been enabled.
|
||||
*/
|
||||
void sqlite3_soft_heap_limit(int);
|
||||
|
||||
/*
|
||||
** This routine makes sure that all thread-local storage has been
|
||||
** deallocated for the current thread.
|
||||
**
|
||||
** This routine is not technically necessary. All thread-local storage
|
||||
** will be automatically deallocated once memory-management and
|
||||
** shared-cache are disabled and the soft heap limit has been set
|
||||
** to zero. This routine is provided as a convenience for users who
|
||||
** want to make absolutely sure they have not forgotten something
|
||||
** prior to killing off a thread.
|
||||
*/
|
||||
void sqlite3_thread_cleanup(void);
|
||||
|
||||
/*
|
||||
** Return meta information about a specific column of a specific database
|
||||
** table accessible using the connection handle passed as the first function
|
||||
** argument.
|
||||
**
|
||||
** The column is identified by the second, third and fourth parameters to
|
||||
** this function. The second parameter is either the name of the database
|
||||
** (i.e. "main", "temp" or an attached database) containing the specified
|
||||
** table or NULL. If it is NULL, then all attached databases are searched
|
||||
** for the table using the same algorithm as the database engine uses to
|
||||
** resolve unqualified table references.
|
||||
**
|
||||
** The third and fourth parameters to this function are the table and column
|
||||
** name of the desired column, respectively. Neither of these parameters
|
||||
** may be NULL.
|
||||
**
|
||||
** Meta information is returned by writing to the memory locations passed as
|
||||
** the 5th and subsequent parameters to this function. Any of these
|
||||
** arguments may be NULL, in which case the corresponding element of meta
|
||||
** information is ommitted.
|
||||
**
|
||||
** Parameter Output Type Description
|
||||
** -----------------------------------
|
||||
**
|
||||
** 5th const char* Data type
|
||||
** 6th const char* Name of the default collation sequence
|
||||
** 7th int True if the column has a NOT NULL constraint
|
||||
** 8th int True if the column is part of the PRIMARY KEY
|
||||
** 9th int True if the column is AUTOINCREMENT
|
||||
**
|
||||
**
|
||||
** The memory pointed to by the character pointers returned for the
|
||||
** declaration type and collation sequence is valid only until the next
|
||||
** call to any sqlite API function.
|
||||
**
|
||||
** If the specified table is actually a view, then an error is returned.
|
||||
**
|
||||
** If the specified column is "rowid", "oid" or "_rowid_" and an
|
||||
** INTEGER PRIMARY KEY column has been explicitly declared, then the output
|
||||
** parameters are set for the explicitly declared column. If there is no
|
||||
** explicitly declared IPK column, then the output parameters are set as
|
||||
** follows:
|
||||
**
|
||||
** data type: "INTEGER"
|
||||
** collation sequence: "BINARY"
|
||||
** not null: 0
|
||||
** primary key: 1
|
||||
** auto increment: 0
|
||||
**
|
||||
** This function may load one or more schemas from database files. If an
|
||||
** error occurs during this process, or if the requested table or column
|
||||
** cannot be found, an SQLITE error code is returned and an error message
|
||||
** left in the database handle (to be retrieved using sqlite3_errmsg()).
|
||||
**
|
||||
** This API is only available if the library was compiled with the
|
||||
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
|
||||
*/
|
||||
int sqlite3_table_column_metadata(
|
||||
sqlite3 *db, /* Connection handle */
|
||||
const char *zDbName, /* Database name or NULL */
|
||||
const char *zTableName, /* Table name */
|
||||
const char *zColumnName, /* Column name */
|
||||
char const **pzDataType, /* OUTPUT: Declared data type */
|
||||
char const **pzCollSeq, /* OUTPUT: Collation sequence name */
|
||||
int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
|
||||
int *pPrimaryKey, /* OUTPUT: True if column part of PK */
|
||||
int *pAutoinc /* OUTPUT: True if colums is auto-increment */
|
||||
);
|
||||
|
||||
/*
|
||||
** Undo the hack that converts floating point types to integer for
|
||||
** builds on processors without floating point support.
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_FLOATING_POINT
|
||||
# undef double
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* End of the 'extern "C"' block */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,11 @@
|
||||
SOURCES += where.c \
|
||||
alter.c \
|
||||
SOURCES += alter.c \
|
||||
analyze.c \
|
||||
attach.c \
|
||||
auth.c \
|
||||
btree.c \
|
||||
build.c \
|
||||
callback.c \
|
||||
complete.c \
|
||||
date.c \
|
||||
delete.c \
|
||||
experimental.c \
|
||||
@@ -16,9 +18,11 @@ SOURCES += where.c \
|
||||
opcodes.c \
|
||||
os_unix.c \
|
||||
os_win.c \
|
||||
os.c \
|
||||
pager.c \
|
||||
parse.c \
|
||||
pragma.c \
|
||||
prepare.c \
|
||||
printf.c \
|
||||
random.c \
|
||||
select.c \
|
||||
@@ -32,7 +36,9 @@ SOURCES += where.c \
|
||||
vdbe.c \
|
||||
vdbeapi.c \
|
||||
vdbeaux.c \
|
||||
vdbemem.c
|
||||
vdbefifo.c \
|
||||
vdbemem.c \
|
||||
where.c
|
||||
HEADERS += btree.h \
|
||||
config.h \
|
||||
hash.h \
|
||||
@@ -58,6 +64,9 @@ mac {
|
||||
MOC_DIR = .moc
|
||||
OBJECTS_DIR = .obj
|
||||
DEFINES += HAVE_USLEEP=1
|
||||
QMAKE_CC = gcc-3.3
|
||||
QMAKE_CXX = g++-3.3
|
||||
QMAKE_LINK = $$QMAKE_CXX
|
||||
}
|
||||
TEMPLATE =lib
|
||||
CONFIG += qt warn_on release staticlib
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
** These routines are in a separate files so that they will not be linked
|
||||
** if they are not used.
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#ifndef SQLITE_OMIT_GET_TABLE
|
||||
|
||||
/*
|
||||
** This structure is used to pass data from sqlite3_get_table() through
|
||||
@@ -143,6 +145,7 @@ int sqlite3_get_table(
|
||||
res.azResult[0] = 0;
|
||||
rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
|
||||
if( res.azResult ){
|
||||
assert( sizeof(res.azResult[0])>= sizeof(res.nData) );
|
||||
res.azResult[0] = (char*)res.nData;
|
||||
}
|
||||
if( rc==SQLITE_ABORT ){
|
||||
@@ -193,3 +196,5 @@ void sqlite3_free_table(
|
||||
free(azResult);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_GET_TABLE */
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.5 2005-04-29 04:26:02 tabuleiro Exp $
|
||||
** $Id: tokenize.c,v 1.6 2006-02-16 10:11:46 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
/*
|
||||
** If X is a character that can be used in an identifier and
|
||||
** X&0x80==0 then isIdChar[X] will be 1. If X&0x80==0x80 then
|
||||
** X&0x80==0 then sqlite3IsIdChar[X] will be 1. If X&0x80==0x80 then
|
||||
** X is always an identifier character. (Hence all UTF-8
|
||||
** characters can be part of an identifier). isIdChar[X] will
|
||||
** characters can be part of an identifier). sqlite3IsIdChar[X] will
|
||||
** be 0 for every character in the lower 128 ASCII characters
|
||||
** that cannot be used as part of an identifier.
|
||||
**
|
||||
@@ -55,7 +55,7 @@
|
||||
** SQLite will allow '$' in identifiers for compatibility.
|
||||
** But the feature is undocumented.
|
||||
*/
|
||||
static const char isIdChar[] = {
|
||||
const char sqlite3IsIdChar[] = {
|
||||
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
|
||||
@@ -65,7 +65,7 @@ static const char isIdChar[] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
|
||||
};
|
||||
|
||||
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && isIdChar[c-0x20]))
|
||||
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
|
||||
|
||||
/*
|
||||
** Return the length of the token that begins at z[0].
|
||||
@@ -183,12 +183,9 @@ static int getToken(const unsigned char *z, int *tokenType){
|
||||
*tokenType = TK_BITNOT;
|
||||
return 1;
|
||||
}
|
||||
case '#': {
|
||||
for(i=1; isdigit(z[i]) || (i==1 && z[1]=='-'); i++){}
|
||||
*tokenType = TK_REGISTER;
|
||||
return i;
|
||||
}
|
||||
case '\'': case '"': {
|
||||
case '`':
|
||||
case '\'':
|
||||
case '"': {
|
||||
int delim = z[0];
|
||||
for(i=1; (c=z[i])!=0; i++){
|
||||
if( c==delim ){
|
||||
@@ -199,21 +196,32 @@ static int getToken(const unsigned char *z, int *tokenType){
|
||||
}
|
||||
}
|
||||
}
|
||||
if( c ) i++;
|
||||
*tokenType = TK_STRING;
|
||||
return i;
|
||||
if( c ){
|
||||
*tokenType = TK_STRING;
|
||||
return i+1;
|
||||
}else{
|
||||
*tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
case '.': {
|
||||
*tokenType = TK_DOT;
|
||||
return 1;
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
if( !isdigit(z[1]) )
|
||||
#endif
|
||||
{
|
||||
*tokenType = TK_DOT;
|
||||
return 1;
|
||||
}
|
||||
/* If the next character is a digit, this is a floating point
|
||||
** number that begins with ".". Fall thru into the next case */
|
||||
}
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9': {
|
||||
*tokenType = TK_INTEGER;
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
for(i=0; isdigit(z[i]); i++){}
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
if( z[i]=='.' && isdigit(z[i+1]) ){
|
||||
i += 2;
|
||||
if( z[i]=='.' ){
|
||||
i++;
|
||||
while( isdigit(z[i]) ){ i++; }
|
||||
*tokenType = TK_FLOAT;
|
||||
}
|
||||
@@ -239,50 +247,48 @@ static int getToken(const unsigned char *z, int *tokenType){
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
return i;
|
||||
}
|
||||
case ':': {
|
||||
for(i=1; IdChar(z[i]); i++){}
|
||||
*tokenType = i>1 ? TK_VARIABLE : TK_ILLEGAL;
|
||||
return i;
|
||||
case '#': {
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
if( i>1 ){
|
||||
/* Parameters of the form #NNN (where NNN is a number) are used
|
||||
** internally by sqlite3NestedParse. */
|
||||
*tokenType = TK_REGISTER;
|
||||
return i;
|
||||
}
|
||||
/* Fall through into the next case if the '#' is not followed by
|
||||
** a digit. Try to match #AAAA where AAAA is a parameter name. */
|
||||
}
|
||||
#ifndef SQLITE_OMIT_TCL_VARIABLE
|
||||
case '$': {
|
||||
case '$':
|
||||
#endif
|
||||
case '@': /* For compatibility with MS SQL Server */
|
||||
case ':': {
|
||||
int n = 0;
|
||||
*tokenType = TK_VARIABLE;
|
||||
if( z[1]=='{' ){
|
||||
int nBrace = 1;
|
||||
for(i=2; (c=z[i])!=0 && nBrace; i++){
|
||||
if( c=='{' ){
|
||||
nBrace++;
|
||||
}else if( c=='}' ){
|
||||
nBrace--;
|
||||
}
|
||||
}
|
||||
if( c==0 ) *tokenType = TK_ILLEGAL;
|
||||
}else{
|
||||
int n = 0;
|
||||
for(i=1; (c=z[i])!=0; i++){
|
||||
if( isalnum(c) || c=='_' ){
|
||||
n++;
|
||||
}else if( c=='(' && n>0 ){
|
||||
do{
|
||||
i++;
|
||||
}while( (c=z[i])!=0 && !isspace(c) && c!=')' );
|
||||
if( c==')' ){
|
||||
i++;
|
||||
}else{
|
||||
*tokenType = TK_ILLEGAL;
|
||||
}
|
||||
break;
|
||||
}else if( c==':' && z[i+1]==':' ){
|
||||
for(i=1; (c=z[i])!=0; i++){
|
||||
if( IdChar(c) ){
|
||||
n++;
|
||||
#ifndef SQLITE_OMIT_TCL_VARIABLE
|
||||
}else if( c=='(' && n>0 ){
|
||||
do{
|
||||
i++;
|
||||
}while( (c=z[i])!=0 && !isspace(c) && c!=')' );
|
||||
if( c==')' ){
|
||||
i++;
|
||||
}else{
|
||||
break;
|
||||
*tokenType = TK_ILLEGAL;
|
||||
}
|
||||
break;
|
||||
}else if( c==':' && z[i+1]==':' ){
|
||||
i++;
|
||||
#endif
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
if( n==0 ) *tokenType = TK_ILLEGAL;
|
||||
}
|
||||
if( n==0 ) *tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_BLOB_LITERAL
|
||||
case 'x': case 'X': {
|
||||
if( (c=z[1])=='\'' || c=='"' ){
|
||||
@@ -341,10 +347,9 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
db->flags &= ~SQLITE_Interrupt;
|
||||
pParse->rc = SQLITE_OK;
|
||||
i = 0;
|
||||
pEngine = sqlite3ParserAlloc((void*(*)(int))malloc);
|
||||
pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);
|
||||
if( pEngine==0 ){
|
||||
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
|
||||
return 1;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
assert( pParse->pNewTable==0 );
|
||||
@@ -354,9 +359,9 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
assert( pParse->nVarExprAlloc==0 );
|
||||
assert( pParse->apVarExpr==0 );
|
||||
pParse->zTail = pParse->zSql = zSql;
|
||||
while( sqlite3_malloc_failed==0 && zSql[i]!=0 ){
|
||||
while( !sqlite3MallocFailed() && zSql[i]!=0 ){
|
||||
assert( i>=0 );
|
||||
pParse->sLastToken.z = &zSql[i];
|
||||
pParse->sLastToken.z = (u8*)&zSql[i];
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);
|
||||
i += pParse->sLastToken.n;
|
||||
@@ -401,13 +406,12 @@ abort_parse:
|
||||
}
|
||||
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqlite3ParserFree(pEngine, free);
|
||||
if( sqlite3_malloc_failed ){
|
||||
sqlite3ParserFree(pEngine, sqlite3FreeX);
|
||||
if( sqlite3MallocFailed() ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
|
||||
sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc),
|
||||
(char*)0);
|
||||
sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc), (char*)0);
|
||||
}
|
||||
if( pParse->zErrMsg ){
|
||||
if( pzErrMsg && *pzErrMsg==0 ){
|
||||
@@ -422,6 +426,13 @@ abort_parse:
|
||||
sqlite3VdbeDelete(pParse->pVdbe);
|
||||
pParse->pVdbe = 0;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
if( pParse->nested==0 ){
|
||||
sqliteFree(pParse->aTableLock);
|
||||
pParse->aTableLock = 0;
|
||||
pParse->nTableLock = 0;
|
||||
}
|
||||
#endif
|
||||
sqlite3DeleteTable(pParse->db, pParse->pNewTable);
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
sqliteFree(pParse->apVarExpr);
|
||||
@@ -430,241 +441,3 @@ abort_parse:
|
||||
}
|
||||
return nErr;
|
||||
}
|
||||
|
||||
/* The sqlite3_complete() API may be omitted (to save code space) by
|
||||
** defining the following symbol.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_COMPLETE
|
||||
|
||||
/*
|
||||
** Token types used by the sqlite3_complete() routine. See the header
|
||||
** comments on that procedure for additional information.
|
||||
*/
|
||||
#define tkSEMI 0
|
||||
#define tkWS 1
|
||||
#define tkOTHER 2
|
||||
#define tkEXPLAIN 3
|
||||
#define tkCREATE 4
|
||||
#define tkTEMP 5
|
||||
#define tkTRIGGER 6
|
||||
#define tkEND 7
|
||||
|
||||
/*
|
||||
** Return TRUE if the given SQL string ends in a semicolon.
|
||||
**
|
||||
** Special handling is require for CREATE TRIGGER statements.
|
||||
** Whenever the CREATE TRIGGER keywords are seen, the statement
|
||||
** must end with ";END;".
|
||||
**
|
||||
** This implementation uses a state machine with 7 states:
|
||||
**
|
||||
** (0) START At the beginning or end of an SQL statement. This routine
|
||||
** returns 1 if it ends in the START state and 0 if it ends
|
||||
** in any other state.
|
||||
**
|
||||
** (1) NORMAL We are in the middle of statement which ends with a single
|
||||
** semicolon.
|
||||
**
|
||||
** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
|
||||
** a statement.
|
||||
**
|
||||
** (3) CREATE The keyword CREATE has been seen at the beginning of a
|
||||
** statement, possibly preceeded by EXPLAIN and/or followed by
|
||||
** TEMP or TEMPORARY
|
||||
**
|
||||
** (4) TRIGGER We are in the middle of a trigger definition that must be
|
||||
** ended by a semicolon, the keyword END, and another semicolon.
|
||||
**
|
||||
** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
|
||||
** the end of a trigger definition.
|
||||
**
|
||||
** (6) END We've seen the ";END" of the ";END;" that occurs at the end
|
||||
** of a trigger difinition.
|
||||
**
|
||||
** Transitions between states above are determined by tokens extracted
|
||||
** from the input. The following tokens are significant:
|
||||
**
|
||||
** (0) tkSEMI A semicolon.
|
||||
** (1) tkWS Whitespace
|
||||
** (2) tkOTHER Any other SQL token.
|
||||
** (3) tkEXPLAIN The "explain" keyword.
|
||||
** (4) tkCREATE The "create" keyword.
|
||||
** (5) tkTEMP The "temp" or "temporary" keyword.
|
||||
** (6) tkTRIGGER The "trigger" keyword.
|
||||
** (7) tkEND The "end" keyword.
|
||||
**
|
||||
** Whitespace never causes a state transition and is always ignored.
|
||||
**
|
||||
** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
|
||||
** to recognize the end of a trigger can be omitted. All we have to do
|
||||
** is look for a semicolon that is not part of an string or comment.
|
||||
*/
|
||||
int sqlite3_complete(const char *zSql){
|
||||
u8 state = 0; /* Current state, using numbers defined in header comment */
|
||||
u8 token; /* Value of the next token */
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* A complex statement machine used to detect the end of a CREATE TRIGGER
|
||||
** statement. This is the normal case.
|
||||
*/
|
||||
static const u8 trans[7][8] = {
|
||||
/* Token: */
|
||||
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
|
||||
/* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, },
|
||||
/* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, },
|
||||
/* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, },
|
||||
/* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, },
|
||||
/* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, },
|
||||
/* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, },
|
||||
/* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, },
|
||||
};
|
||||
#else
|
||||
/* If triggers are not suppored by this compile then the statement machine
|
||||
** used to detect the end of a statement is much simplier
|
||||
*/
|
||||
static const u8 trans[2][3] = {
|
||||
/* Token: */
|
||||
/* State: ** SEMI WS OTHER */
|
||||
/* 0 START: */ { 0, 0, 1, },
|
||||
/* 1 NORMAL: */ { 0, 1, 1, },
|
||||
};
|
||||
#endif /* SQLITE_OMIT_TRIGGER */
|
||||
|
||||
while( *zSql ){
|
||||
switch( *zSql ){
|
||||
case ';': { /* A semicolon */
|
||||
token = tkSEMI;
|
||||
break;
|
||||
}
|
||||
case ' ':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\f': { /* White space is ignored */
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '/': { /* C-style comments */
|
||||
if( zSql[1]!='*' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
zSql += 2;
|
||||
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
|
||||
if( zSql[0]==0 ) return 0;
|
||||
zSql++;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '-': { /* SQL-style comments from "--" to end of line */
|
||||
if( zSql[1]!='-' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
while( *zSql && *zSql!='\n' ){ zSql++; }
|
||||
if( *zSql==0 ) return state==0;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '[': { /* Microsoft-style identifiers in [...] */
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=']' ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
case '"': /* single- and double-quoted strings */
|
||||
case '\'': {
|
||||
int c = *zSql;
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=c ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
int c;
|
||||
if( IdChar((u8)*zSql) ){
|
||||
/* Keywords and unquoted identifiers */
|
||||
int nId;
|
||||
for(nId=1; IdChar(zSql[nId]); nId++){}
|
||||
#ifdef SQLITE_OMIT_TRIGGER
|
||||
token = tkOTHER;
|
||||
#else
|
||||
switch( *zSql ){
|
||||
case 'c': case 'C': {
|
||||
if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
|
||||
token = tkCREATE;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't': case 'T': {
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
|
||||
token = tkTRIGGER;
|
||||
}else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
|
||||
token = tkTEMP;
|
||||
}else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
|
||||
token = tkTEMP;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': {
|
||||
if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
|
||||
token = tkEND;
|
||||
}else
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
|
||||
token = tkEXPLAIN;
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_OMIT_TRIGGER */
|
||||
zSql += nId-1;
|
||||
}else{
|
||||
/* Operators and special symbols */
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = trans[state][token];
|
||||
zSql++;
|
||||
}
|
||||
return state==0;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** This routine is the same as the sqlite3_complete() routine described
|
||||
** above, except that the parameter is required to be UTF-16 encoded, not
|
||||
** UTF-8.
|
||||
*/
|
||||
int sqlite3_complete16(const void *zSql){
|
||||
sqlite3_value *pVal;
|
||||
char const *zSql8;
|
||||
int rc = 0;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_complete(zSql8);
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
return rc;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
#endif /* SQLITE_OMIT_COMPLETE */
|
||||
|
||||
@@ -58,6 +58,7 @@ void sqlite3BeginTrigger(
|
||||
int iDb; /* The database to store the trigger in */
|
||||
Token *pName; /* The unqualified db name */
|
||||
DbFixer sFix;
|
||||
int iTabDb;
|
||||
|
||||
if( isTemp ){
|
||||
/* If TEMP was specified, then the trigger name may not be qualified. */
|
||||
@@ -80,14 +81,16 @@ void sqlite3BeginTrigger(
|
||||
** If sqlite3SrcListLookup() returns 0, indicating the table does not
|
||||
** exist, the error is caught by the block below.
|
||||
*/
|
||||
if( !pTableName || sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
if( !pTableName || sqlite3MallocFailed() ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
if( pName2->n==0 && pTab && pTab->iDb==1 ){
|
||||
if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
|
||||
iDb = 1;
|
||||
}
|
||||
|
||||
/* Ensure the table name matches database name and that the table exists */
|
||||
if( sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
if( sqlite3MallocFailed() ) goto trigger_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
|
||||
sqlite3FixSrcList(&sFix, pTableName) ){
|
||||
@@ -105,7 +108,7 @@ void sqlite3BeginTrigger(
|
||||
if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqlite3HashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
|
||||
if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash), zName,pName->n+1) ){
|
||||
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
@@ -130,17 +133,18 @@ void sqlite3BeginTrigger(
|
||||
" trigger on table: %S", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_CREATE_TRIGGER;
|
||||
const char *zDb = db->aDb[pTab->iDb].zName;
|
||||
const char *zDb = db->aDb[iTabDb].zName;
|
||||
const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
|
||||
if( pTab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(pTab->iDb),0,zDb)){
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -161,8 +165,8 @@ void sqlite3BeginTrigger(
|
||||
pTrigger->name = zName;
|
||||
zName = 0;
|
||||
pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
|
||||
pTrigger->iDb = iDb;
|
||||
pTrigger->iTabDb = pTab->iDb;
|
||||
pTrigger->pSchema = db->aDb[iDb].pSchema;
|
||||
pTrigger->pTabSchema = pTab->pSchema;
|
||||
pTrigger->op = op;
|
||||
pTrigger->tr_tm = tr_tm==TK_BEFORE ? TRIGGER_BEFORE : TRIGGER_AFTER;
|
||||
pTrigger->pWhen = sqlite3ExprDup(pWhen);
|
||||
@@ -196,16 +200,18 @@ void sqlite3FinishTrigger(
|
||||
Trigger *pTrig = 0; /* The trigger whose construction is finishing up */
|
||||
sqlite3 *db = pParse->db; /* The database */
|
||||
DbFixer sFix;
|
||||
int iDb; /* Database containing the trigger */
|
||||
|
||||
pTrig = pParse->pNewTrigger;
|
||||
pParse->pNewTrigger = 0;
|
||||
if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup;
|
||||
if( pParse->nErr || !pTrig ) goto triggerfinish_cleanup;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
|
||||
pTrig->step_list = pStepList;
|
||||
while( pStepList ){
|
||||
pStepList->pTrig = pTrig;
|
||||
pStepList = pStepList->pNext;
|
||||
}
|
||||
if( sqlite3FixInit(&sFix, pParse, pTrig->iDb, "trigger", &pTrig->nameToken)
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &pTrig->nameToken)
|
||||
&& sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
@@ -215,7 +221,7 @@ void sqlite3FinishTrigger(
|
||||
*/
|
||||
if( !db->init.busy ){
|
||||
static const VdbeOpList insertTrig[] = {
|
||||
{ OP_NewRecno, 0, 0, 0 },
|
||||
{ OP_NewRowid, 0, 0, 0 },
|
||||
{ OP_String8, 0, 0, "trigger" },
|
||||
{ OP_String8, 0, 0, 0 }, /* 2: trigger name */
|
||||
{ OP_String8, 0, 0, 0 }, /* 3: table name */
|
||||
@@ -223,8 +229,8 @@ void sqlite3FinishTrigger(
|
||||
{ OP_String8, 0, 0, "CREATE TRIGGER "},
|
||||
{ OP_String8, 0, 0, 0 }, /* 6: SQL */
|
||||
{ OP_Concat, 0, 0, 0 },
|
||||
{ OP_MakeRecord, 5, 0, "tttit" },
|
||||
{ OP_PutIntKey, 0, 0, 0 },
|
||||
{ OP_MakeRecord, 5, 0, "aaada" },
|
||||
{ OP_Insert, 0, 0, 0 },
|
||||
};
|
||||
int addr;
|
||||
Vdbe *v;
|
||||
@@ -232,28 +238,30 @@ void sqlite3FinishTrigger(
|
||||
/* Make an entry in the sqlite_master table */
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto triggerfinish_cleanup;
|
||||
sqlite3BeginWriteOperation(pParse, 0, pTrig->iDb);
|
||||
sqlite3OpenMasterTable(v, pTrig->iDb);
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3OpenMasterTable(pParse, iDb);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
|
||||
sqlite3VdbeChangeP3(v, addr+2, pTrig->name, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+3, pTrig->table, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+6, pAll->z, pAll->n);
|
||||
sqlite3ChangeCookie(db, v, pTrig->iDb);
|
||||
sqlite3VdbeChangeP3(v, addr+6, (char*)pAll->z, pAll->n);
|
||||
sqlite3ChangeCookie(db, v, iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, pTrig->iDb, 0,
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0,
|
||||
sqlite3MPrintf("type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC);
|
||||
}
|
||||
|
||||
if( db->init.busy ){
|
||||
int n;
|
||||
Table *pTab;
|
||||
Trigger *pDel;
|
||||
pDel = sqlite3HashInsert(&db->aDb[pTrig->iDb].trigHash,
|
||||
pDel = sqlite3HashInsert(&db->aDb[iDb].pSchema->trigHash,
|
||||
pTrig->name, strlen(pTrig->name)+1, pTrig);
|
||||
if( pDel ){
|
||||
assert( sqlite3_malloc_failed && pDel==pTrig );
|
||||
assert( sqlite3MallocFailed() && pDel==pTrig );
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
pTab = sqlite3LocateTable(pParse,pTrig->table,db->aDb[pTrig->iTabDb].zName);
|
||||
n = strlen(pTrig->table) + 1;
|
||||
pTab = sqlite3HashFind(&pTrig->pTabSchema->tblHash, pTrig->table, n);
|
||||
assert( pTab!=0 );
|
||||
pTrig->pNext = pTab->pTrigger;
|
||||
pTab->pTrigger = pTrig;
|
||||
@@ -278,7 +286,7 @@ triggerfinish_cleanup:
|
||||
*/
|
||||
static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
if( p->target.z ){
|
||||
p->target.z = sqliteStrNDup(p->target.z, p->target.n);
|
||||
p->target.z = (u8*)sqliteStrNDup((char*)p->target.z, p->target.n);
|
||||
p->target.dyn = 1;
|
||||
}
|
||||
if( p->pSelect ){
|
||||
@@ -312,7 +320,10 @@ static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
*/
|
||||
TriggerStep *sqlite3TriggerSelectStep(Select *pSelect){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
if( pTriggerStep==0 ) {
|
||||
sqlite3SelectDelete(pSelect);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pTriggerStep->op = TK_SELECT;
|
||||
pTriggerStep->pSelect = pSelect;
|
||||
@@ -430,7 +441,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
int nName;
|
||||
sqlite3 *db = pParse->db;
|
||||
|
||||
if( sqlite3_malloc_failed ) goto drop_trigger_cleanup;
|
||||
if( sqlite3MallocFailed() ) goto drop_trigger_cleanup;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
|
||||
goto drop_trigger_cleanup;
|
||||
}
|
||||
@@ -442,7 +453,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
||||
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
|
||||
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
|
||||
pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
|
||||
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName+1);
|
||||
if( pTrigger ) break;
|
||||
}
|
||||
if( !pTrigger ){
|
||||
@@ -460,7 +471,8 @@ drop_trigger_cleanup:
|
||||
** is set on.
|
||||
*/
|
||||
static Table *tableOfTrigger(sqlite3 *db, Trigger *pTrigger){
|
||||
return sqlite3FindTable(db,pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
|
||||
int n = strlen(pTrigger->table) + 1;
|
||||
return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table, n);
|
||||
}
|
||||
|
||||
|
||||
@@ -475,11 +487,11 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
|
||||
iDb = pTrigger->iDb;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
pTable = tableOfTrigger(db, pTrigger);
|
||||
assert(pTable);
|
||||
assert( pTable->iDb==iDb || iDb==1 );
|
||||
assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_DROP_TRIGGER;
|
||||
@@ -510,7 +522,7 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
};
|
||||
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3OpenMasterTable(v, iDb);
|
||||
sqlite3OpenMasterTable(pParse, iDb);
|
||||
base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
|
||||
sqlite3VdbeChangeP3(v, base+1, pTrigger->name, 0);
|
||||
sqlite3ChangeCookie(db, v, iDb);
|
||||
@@ -525,7 +537,7 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
|
||||
Trigger *pTrigger;
|
||||
int nName = strlen(zName);
|
||||
pTrigger = sqlite3HashInsert(&(db->aDb[iDb].trigHash), zName, nName+1, 0);
|
||||
pTrigger = sqlite3HashInsert(&(db->aDb[iDb].pSchema->trigHash), zName, nName+1, 0);
|
||||
if( pTrigger ){
|
||||
Table *pTable = tableOfTrigger(db, pTrigger);
|
||||
assert( pTable!=0 );
|
||||
@@ -617,11 +629,11 @@ static SrcList *targetSrcList(
|
||||
int iDb; /* Index of the database to use */
|
||||
SrcList *pSrc; /* SrcList to be returned */
|
||||
|
||||
iDb = pStep->pTrig->iDb;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
|
||||
if( iDb==0 || iDb>=2 ){
|
||||
assert( iDb<pParse->db->nDb );
|
||||
sDb.z = pParse->db->aDb[iDb].zName;
|
||||
sDb.n = strlen(sDb.z);
|
||||
sDb.z = (u8*)pParse->db->aDb[iDb].zName;
|
||||
sDb.n = strlen((char*)sDb.z);
|
||||
pSrc = sqlite3SrcListAppend(0, &sDb, &pStep->target);
|
||||
} else {
|
||||
pSrc = sqlite3SrcListAppend(0, &pStep->target, 0);
|
||||
@@ -730,8 +742,7 @@ int sqlite3CodeRowTrigger(
|
||||
int orconf, /* ON CONFLICT policy */
|
||||
int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
|
||||
){
|
||||
Trigger *pTrigger;
|
||||
TriggerStack *pStack;
|
||||
Trigger *p;
|
||||
TriggerStack trigStackEntry;
|
||||
|
||||
assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
|
||||
@@ -739,21 +750,20 @@ int sqlite3CodeRowTrigger(
|
||||
|
||||
assert(newIdx != -1 || oldIdx != -1);
|
||||
|
||||
pTrigger = pTab->pTrigger;
|
||||
while( pTrigger ){
|
||||
for(p=pTab->pTrigger; p; p=p->pNext){
|
||||
int fire_this = 0;
|
||||
|
||||
/* determine whether we should code this trigger */
|
||||
if( pTrigger->op == op && pTrigger->tr_tm == tr_tm ){
|
||||
fire_this = 1;
|
||||
for(pStack=pParse->trigStack; pStack; pStack=pStack->pNext){
|
||||
if( pStack->pTrigger==pTrigger ){
|
||||
fire_this = 0;
|
||||
}
|
||||
}
|
||||
if( op == TK_UPDATE && pTrigger->pColumns &&
|
||||
!checkColumnOverLap(pTrigger->pColumns, pChanges) ){
|
||||
fire_this = 0;
|
||||
/* Determine whether we should code this trigger */
|
||||
if(
|
||||
p->op==op &&
|
||||
p->tr_tm==tr_tm &&
|
||||
(p->pSchema==p->pTabSchema || p->pSchema==pParse->db->aDb[1].pSchema) &&
|
||||
(op!=TK_UPDATE||!p->pColumns||checkColumnOverLap(p->pColumns,pChanges))
|
||||
){
|
||||
TriggerStack *pS; /* Pointer to trigger-stack entry */
|
||||
for(pS=pParse->trigStack; pS && p!=pS->pTrigger; pS=pS->pNext);
|
||||
if( !pS ){
|
||||
fire_this = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -767,18 +777,18 @@ int sqlite3CodeRowTrigger(
|
||||
sNC.pParse = pParse;
|
||||
|
||||
/* Push an entry on to the trigger stack */
|
||||
trigStackEntry.pTrigger = pTrigger;
|
||||
trigStackEntry.pTrigger = p;
|
||||
trigStackEntry.newIdx = newIdx;
|
||||
trigStackEntry.oldIdx = oldIdx;
|
||||
trigStackEntry.pTab = pTab;
|
||||
trigStackEntry.pNext = pParse->trigStack;
|
||||
trigStackEntry.ignoreJump = ignoreJump;
|
||||
pParse->trigStack = &trigStackEntry;
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTrigger->name);
|
||||
sqlite3AuthContextPush(pParse, &sContext, p->name);
|
||||
|
||||
/* code the WHEN clause */
|
||||
endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe);
|
||||
whenExpr = sqlite3ExprDup(pTrigger->pWhen);
|
||||
whenExpr = sqlite3ExprDup(p->pWhen);
|
||||
if( sqlite3ExprResolveNames(&sNC, whenExpr) ){
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
@@ -787,7 +797,7 @@ int sqlite3CodeRowTrigger(
|
||||
sqlite3ExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
|
||||
codeTriggerProgram(pParse, pTrigger->step_list, orconf);
|
||||
codeTriggerProgram(pParse, p->step_list, orconf);
|
||||
|
||||
/* Pop the entry off the trigger stack */
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
@@ -795,7 +805,6 @@ int sqlite3CodeRowTrigger(
|
||||
|
||||
sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
}
|
||||
pTrigger = pTrigger->pNext;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle UPDATE statements.
|
||||
**
|
||||
** $Id: update.c,v 1.5 2005-04-29 04:26:03 tabuleiro Exp $
|
||||
** $Id: update.c,v 1.6 2006-02-16 10:11:47 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** The most recently coded instruction was an OP_Column to retrieve column
|
||||
** 'i' of table pTab. This routine sets the P3 parameter of the
|
||||
** The most recently coded instruction was an OP_Column to retrieve the
|
||||
** i-th column of table pTab. This routine sets the P3 parameter of the
|
||||
** OP_Column to the default value, if any.
|
||||
**
|
||||
** The default value of a column is specified by a DEFAULT clause in the
|
||||
@@ -44,10 +44,14 @@
|
||||
void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){
|
||||
if( pTab && !pTab->pSelect ){
|
||||
sqlite3_value *pValue;
|
||||
u8 enc = sqlite3VdbeDb(v)->enc;
|
||||
u8 enc = ENC(sqlite3VdbeDb(v));
|
||||
Column *pCol = &pTab->aCol[i];
|
||||
sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue);
|
||||
sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM);
|
||||
if( pValue ){
|
||||
sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM);
|
||||
}else{
|
||||
VdbeComment((v, "# %s.%s", pTab->zName, pCol->zName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,11 +84,12 @@ void sqlite3Update(
|
||||
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
|
||||
** an expression for the i-th column of the table.
|
||||
** aXRef[i]==-1 if the i-th column is not changed. */
|
||||
int chngRecno; /* True if the record number is being changed */
|
||||
Expr *pRecnoExpr = 0; /* Expression defining the new record number */
|
||||
int chngRowid; /* True if the record number is being changed */
|
||||
Expr *pRowidExpr = 0; /* Expression defining the new record number */
|
||||
int openAll = 0; /* True if all indices need to be opened */
|
||||
AuthContext sContext; /* The authorization context */
|
||||
NameContext sNC; /* The name-context to resolve expressions in */
|
||||
int iDb; /* Database containing the table being updated */
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* Trying to update a view */
|
||||
@@ -95,7 +100,9 @@ void sqlite3Update(
|
||||
int oldIdx = -1; /* index of trigger "old" temp table */
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto update_cleanup;
|
||||
if( pParse->nErr || sqlite3MallocFailed() ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
db = pParse->db;
|
||||
assert( pTabList->nSrc==1 );
|
||||
|
||||
@@ -103,6 +110,7 @@ void sqlite3Update(
|
||||
*/
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto update_cleanup;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
|
||||
/* Figure out if we have any triggers and if the table being
|
||||
** updated is a view
|
||||
@@ -160,7 +168,7 @@ void sqlite3Update(
|
||||
** column to be updated, make sure we have authorization to change
|
||||
** that column.
|
||||
*/
|
||||
chngRecno = 0;
|
||||
chngRowid = 0;
|
||||
for(i=0; i<pChanges->nExpr; i++){
|
||||
if( sqlite3ExprResolveNames(&sNC, pChanges->a[i].pExpr) ){
|
||||
goto update_cleanup;
|
||||
@@ -168,8 +176,8 @@ void sqlite3Update(
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
|
||||
if( j==pTab->iPKey ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
chngRowid = 1;
|
||||
pRowidExpr = pChanges->a[i].pExpr;
|
||||
}
|
||||
aXRef[j] = i;
|
||||
break;
|
||||
@@ -177,8 +185,8 @@ void sqlite3Update(
|
||||
}
|
||||
if( j>=pTab->nCol ){
|
||||
if( sqlite3IsRowid(pChanges->a[i].zName) ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
chngRowid = 1;
|
||||
pRowidExpr = pChanges->a[i].pExpr;
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
|
||||
goto update_cleanup;
|
||||
@@ -188,7 +196,7 @@ void sqlite3Update(
|
||||
{
|
||||
int rc;
|
||||
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
|
||||
pTab->aCol[j].zName, db->aDb[pTab->iDb].zName);
|
||||
pTab->aCol[j].zName, db->aDb[iDb].zName);
|
||||
if( rc==SQLITE_DENY ){
|
||||
goto update_cleanup;
|
||||
}else if( rc==SQLITE_IGNORE ){
|
||||
@@ -204,7 +212,7 @@ void sqlite3Update(
|
||||
** number of the original table entry is changing.
|
||||
*/
|
||||
for(nIdx=nIdxTotal=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdxTotal++){
|
||||
if( chngRecno ){
|
||||
if( chngRowid ){
|
||||
i = 0;
|
||||
}else {
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
@@ -219,7 +227,7 @@ void sqlite3Update(
|
||||
aIdxUsed = (char*)&apIdx[nIdx];
|
||||
}
|
||||
for(nIdx=j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
if( chngRecno ){
|
||||
if( chngRowid ){
|
||||
i = 0;
|
||||
}else{
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
@@ -227,7 +235,6 @@ void sqlite3Update(
|
||||
}
|
||||
}
|
||||
if( i<pIdx->nColumn ){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto update_cleanup;
|
||||
apIdx[nIdx++] = pIdx;
|
||||
aIdxUsed[j] = 1;
|
||||
}else{
|
||||
@@ -253,15 +260,15 @@ void sqlite3Update(
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto update_cleanup;
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
sqlite3BeginWriteOperation(pParse, 1, iDb);
|
||||
|
||||
/* If we are trying to update a view, construct that view into
|
||||
** a temporary table.
|
||||
/* If we are trying to update a view, realize that view into
|
||||
** a ephemeral table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView;
|
||||
pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
|
||||
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
}
|
||||
|
||||
@@ -272,8 +279,8 @@ void sqlite3Update(
|
||||
|
||||
/* Remember the index of every item to be updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
@@ -295,8 +302,7 @@ void sqlite3Update(
|
||||
|
||||
/* The top of the update loop for when there are triggers.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0);
|
||||
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
@@ -304,26 +310,26 @@ void sqlite3Update(
|
||||
/* Open a cursor and make it point to the record that is
|
||||
** being updated.
|
||||
*/
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
|
||||
/* Generate the OLD table
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
|
||||
|
||||
/* Generate the NEW table
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqlite3ExprCodeAndCache(pParse, pRecnoExpr);
|
||||
if( chngRowid ){
|
||||
sqlite3ExprCodeAndCache(pParse, pRowidExpr);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
@@ -339,7 +345,7 @@ void sqlite3Update(
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
}
|
||||
if( pParse->nErr ) goto update_cleanup;
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
@@ -359,9 +365,7 @@ void sqlite3Update(
|
||||
** action, then we need to open all indices because we might need
|
||||
** to be deleting some records.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
|
||||
if( onError==OE_Replace ){
|
||||
openAll = 1;
|
||||
}else{
|
||||
@@ -375,9 +379,10 @@ void sqlite3Update(
|
||||
}
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenWrite, iCur+i+1, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
(char*)pKey, P3_KEYINFO_HANDOFF);
|
||||
assert( pParse->nTab>iCur+i+1 );
|
||||
}
|
||||
}
|
||||
@@ -389,8 +394,7 @@ void sqlite3Update(
|
||||
** So make the cursor point at the old record.
|
||||
*/
|
||||
if( !triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr);
|
||||
@@ -399,8 +403,8 @@ void sqlite3Update(
|
||||
** will be after the update. (The old record number is currently
|
||||
** on top of the stack.)
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqlite3ExprCode(pParse, pRecnoExpr);
|
||||
if( chngRowid ){
|
||||
sqlite3ExprCode(pParse, pRowidExpr);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}
|
||||
|
||||
@@ -408,7 +412,7 @@ void sqlite3Update(
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
@@ -422,7 +426,7 @@ void sqlite3Update(
|
||||
|
||||
/* Do constraint checks
|
||||
*/
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRowid, 1,
|
||||
onError, addr);
|
||||
|
||||
/* Delete the old indices for the current record.
|
||||
@@ -431,13 +435,13 @@ void sqlite3Update(
|
||||
|
||||
/* If changing the record number, delete the old record.
|
||||
*/
|
||||
if( chngRecno ){
|
||||
if( chngRowid ){
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, 0);
|
||||
}
|
||||
|
||||
/* Create the new index entries and the new record.
|
||||
*/
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRowid, 1, -1);
|
||||
}
|
||||
|
||||
/* Increment the row counter
|
||||
@@ -467,8 +471,7 @@ void sqlite3Update(
|
||||
** all record selected by the WHERE clause have been updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
|
||||
/* Close all tables if there were no FOR EACH ROW triggers */
|
||||
if( !triggers_exist ){
|
||||
@@ -491,7 +494,7 @@ void sqlite3Update(
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows updated", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", P3_STATIC);
|
||||
}
|
||||
|
||||
update_cleanup:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This file contains routines used to translate between UTF-8,
|
||||
** UTF-16, UTF-16BE, and UTF-16LE.
|
||||
**
|
||||
** $Id: utf.c,v 1.3 2005-04-29 04:26:03 tabuleiro Exp $
|
||||
** $Id: utf.c,v 1.4 2006-02-16 10:11:47 jmiltner Exp $
|
||||
**
|
||||
** Notes on UTF-8:
|
||||
**
|
||||
@@ -272,7 +272,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
assert( rc==SQLITE_NOMEM );
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
zIn = pMem->z;
|
||||
zIn = (u8*)pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
while( zIn<zTerm ){
|
||||
temp = *zIn;
|
||||
@@ -308,7 +308,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
** obtained from malloc(), or Mem.zShort, if it large enough and not in
|
||||
** use, or the zShort array on the stack (see above).
|
||||
*/
|
||||
zIn = pMem->z;
|
||||
zIn = (u8*)pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
if( len>NBFS ){
|
||||
zOut = sqliteMallocRaw(len);
|
||||
@@ -360,12 +360,12 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
pMem->enc = desiredEnc;
|
||||
if( zOut==zShort ){
|
||||
memcpy(pMem->zShort, zOut, len);
|
||||
zOut = pMem->zShort;
|
||||
zOut = (u8*)pMem->zShort;
|
||||
pMem->flags |= (MEM_Term|MEM_Short);
|
||||
}else{
|
||||
pMem->flags |= (MEM_Term|MEM_Dyn);
|
||||
}
|
||||
pMem->z = zOut;
|
||||
pMem->z = (char*)zOut;
|
||||
|
||||
translate_out:
|
||||
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
|
||||
@@ -450,6 +450,23 @@ int sqlite3utf8CharLen(const char *z, int nByte){
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** Convert a UTF-16 string in the native encoding into a UTF-8 string.
|
||||
** Memory to hold the UTF-8 string is obtained from malloc and must be
|
||||
** freed by the calling function.
|
||||
**
|
||||
** NULL is returned if there is an allocation error.
|
||||
*/
|
||||
char *sqlite3utf16to8(const void *z, int nByte){
|
||||
Mem m;
|
||||
memset(&m, 0, sizeof(m));
|
||||
sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);
|
||||
assert( m.flags & MEM_Term );
|
||||
assert( m.flags & MEM_Str );
|
||||
return (m.flags & MEM_Dyn)!=0 ? m.z : sqliteStrDup(m.z);
|
||||
}
|
||||
|
||||
/*
|
||||
** pZ is a UTF-16 encoded unicode string. If nChar is less than zero,
|
||||
** return the number of bytes up to (but not including), the first pair
|
||||
@@ -462,6 +479,15 @@ int sqlite3utf16ByteLen(const void *zIn, int nChar){
|
||||
char const *z = zIn;
|
||||
int n = 0;
|
||||
if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){
|
||||
/* Using an "if (SQLITE_UTF16NATIVE==SQLITE_UTF16BE)" construct here
|
||||
** and in other parts of this file means that at one branch will
|
||||
** not be covered by coverage testing on any single host. But coverage
|
||||
** will be complete if the tests are run on both a little-endian and
|
||||
** big-endian host. Because both the UTF16NATIVE and SQLITE_UTF16BE
|
||||
** macros are constant at compile time the compiler can determine
|
||||
** which branch will be followed. It is therefore assumed that no runtime
|
||||
** penalty is paid for this "if" statement.
|
||||
*/
|
||||
while( c && ((nChar<0) || n<nChar) ){
|
||||
READ_UTF16BE(z, c);
|
||||
n++;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,9 +14,10 @@
|
||||
** Most of the code in this file may be omitted by defining the
|
||||
** SQLITE_OMIT_VACUUM macro.
|
||||
**
|
||||
** $Id: vacuum.c,v 1.5 2005-04-29 04:26:03 tabuleiro Exp $
|
||||
** $Id: vacuum.c,v 1.6 2006-02-16 10:11:47 jmiltner Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h"
|
||||
|
||||
#ifndef SQLITE_OMIT_VACUUM
|
||||
@@ -58,7 +59,7 @@ static int execExecSql(sqlite3 *db, const char *zSql){
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
rc = execSql(db, sqlite3_column_text(pStmt, 0));
|
||||
rc = execSql(db, (char*)sqlite3_column_text(pStmt, 0));
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_finalize(pStmt);
|
||||
return rc;
|
||||
@@ -100,6 +101,12 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
Btree *pMain; /* The database being vacuumed */
|
||||
Btree *pTemp;
|
||||
char *zSql = 0;
|
||||
int saved_flags; /* Saved value of the db->flags */
|
||||
Db *pDb = 0; /* Database to detach at end of vacuum */
|
||||
|
||||
/* Save the current value of the write-schema flag before setting it. */
|
||||
saved_flags = db->flags;
|
||||
db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
|
||||
|
||||
if( !db->autoCommit ){
|
||||
sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
@@ -159,19 +166,23 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
sqliteFree(zSql);
|
||||
zSql = 0;
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
pDb = &db->aDb[db->nDb-1];
|
||||
assert( strcmp(db->aDb[db->nDb-1].zName,"vacuum_db")==0 );
|
||||
pTemp = db->aDb[db->nDb-1].pBt;
|
||||
sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain),
|
||||
sqlite3BtreeGetReserve(pMain));
|
||||
assert( sqlite3BtreeGetPageSize(pTemp)==sqlite3BtreeGetPageSize(pMain) );
|
||||
execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
|
||||
rc = execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
sqlite3BtreeSetAutoVacuum(pTemp, sqlite3BtreeGetAutoVacuum(pMain));
|
||||
#endif
|
||||
|
||||
/* Begin a transaction */
|
||||
rc = execSql(db, "BEGIN;");
|
||||
rc = execSql(db, "BEGIN EXCLUSIVE;");
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Query the schema of the main database. Create a mirror schema
|
||||
@@ -242,7 +253,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
** opened for writing. This way, the SQL transaction used to create the
|
||||
** temporary database never needs to be committed.
|
||||
*/
|
||||
if( sqlite3BtreeIsInTrans(pTemp) ){
|
||||
if( rc==SQLITE_OK ){
|
||||
u32 meta;
|
||||
int i;
|
||||
|
||||
@@ -259,23 +270,28 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
6, 0, /* Preserve the user version */
|
||||
};
|
||||
|
||||
assert( 0==sqlite3BtreeIsInTrans(pMain) );
|
||||
rc = sqlite3BtreeBeginTrans(pMain, 1);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
assert( 1==sqlite3BtreeIsInTrans(pTemp) );
|
||||
assert( 1==sqlite3BtreeIsInTrans(pMain) );
|
||||
|
||||
/* Copy Btree meta values */
|
||||
for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){
|
||||
rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
}
|
||||
|
||||
rc = sqlite3BtreeCopyFile(pMain, pTemp);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeCommit(pTemp);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeCommit(pMain);
|
||||
}
|
||||
|
||||
end_of_vacuum:
|
||||
/* Restore the original value of db->flags */
|
||||
db->flags = saved_flags;
|
||||
|
||||
/* Currently there is an SQL level transaction open on the vacuum
|
||||
** database. No locks are held on any other files (since the main file
|
||||
** was committed at the btree level). So it safe to end the transaction
|
||||
@@ -284,17 +300,30 @@ end_of_vacuum:
|
||||
** is closed by the DETACH.
|
||||
*/
|
||||
db->autoCommit = 1;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = execSql(db, "DETACH vacuum_db;");
|
||||
}else{
|
||||
execSql(db, "DETACH vacuum_db;");
|
||||
|
||||
if( pDb ){
|
||||
sqlite3MallocDisallow();
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
sqlite3MallocAllow();
|
||||
pDb->pBt = 0;
|
||||
pDb->pSchema = 0;
|
||||
}
|
||||
|
||||
/* If one of the execSql() calls above returned SQLITE_NOMEM, then the
|
||||
** mallocFailed flag will be clear (because execSql() calls sqlite3_exec()).
|
||||
** Fix this so the flag and return code match.
|
||||
*/
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
sqlite3MallocFailed();
|
||||
}
|
||||
|
||||
if( zTemp ){
|
||||
sqlite3OsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}
|
||||
if( zSql ) sqliteFree( zSql );
|
||||
sqliteFree( zSql );
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@
|
||||
** or VDBE. The VDBE implements an abstract machine that runs a
|
||||
** simple program to access and modify the underlying database.
|
||||
**
|
||||
** $Id: vdbe.h,v 1.5 2005-04-29 04:26:04 tabuleiro Exp $
|
||||
** $Id: vdbe.h,v 1.6 2006-02-16 10:11:47 jmiltner Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_VDBE_H_
|
||||
#define _SQLITE_VDBE_H_
|
||||
@@ -38,7 +38,7 @@ struct VdbeOp {
|
||||
int p1; /* First operand */
|
||||
int p2; /* Second parameter (often the jump destination) */
|
||||
char *p3; /* Third parameter */
|
||||
int p3type; /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
|
||||
int p3type; /* One of the P3_xxx constants defined below */
|
||||
#ifdef VDBE_PROFILE
|
||||
int cnt; /* Number of times this instruction was executed */
|
||||
long long cycles; /* Total time spend executing this instruction */
|
||||
@@ -64,12 +64,12 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
#define P3_NOTUSED 0 /* The P3 parameter is not used */
|
||||
#define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
|
||||
#define P3_STATIC (-2) /* Pointer to a static string */
|
||||
#define P3_POINTER (-3) /* P3 is a pointer to some structure or object */
|
||||
#define P3_COLLSEQ (-4) /* P3 is a pointer to a CollSeq structure */
|
||||
#define P3_FUNCDEF (-5) /* P3 is a pointer to a FuncDef structure */
|
||||
#define P3_KEYINFO (-6) /* P3 is a pointer to a KeyInfo structure */
|
||||
#define P3_VDBEFUNC (-7) /* P3 is a pointer to a VdbeFunc structure */
|
||||
#define P3_MEM (-8) /* P3 is a pointer to a Mem* structure */
|
||||
#define P3_TRANSIENT (-9) /* P3 is a pointer to a transient string */
|
||||
|
||||
/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
|
||||
** is made. That copy is freed when the Vdbe is finalized. But if the
|
||||
@@ -80,6 +80,17 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
*/
|
||||
#define P3_KEYINFO_HANDOFF (-9)
|
||||
|
||||
/*
|
||||
** The Vdbe.aColName array contains 5n Mem structures, where n is the
|
||||
** number of columns of data returned by the statement.
|
||||
*/
|
||||
#define COLNAME_NAME 0
|
||||
#define COLNAME_DECLTYPE 1
|
||||
#define COLNAME_DATABASE 2
|
||||
#define COLNAME_TABLE 3
|
||||
#define COLNAME_COLUMN 4
|
||||
#define COLNAME_N 5 /* Number of COLNAME_xxx symbols */
|
||||
|
||||
/*
|
||||
** The following macro converts a relative address in the p2 field
|
||||
** of a VdbeOp structure into a negative number so that
|
||||
@@ -105,13 +116,12 @@ int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
|
||||
int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
|
||||
void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
|
||||
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
|
||||
void sqlite3VdbeJumpHere(Vdbe*, int addr);
|
||||
void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
|
||||
void sqlite3VdbeDequoteP3(Vdbe*, int addr);
|
||||
int sqlite3VdbeFindOp(Vdbe*, int, int, int);
|
||||
VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
|
||||
int sqlite3VdbeMakeLabel(Vdbe*);
|
||||
void sqlite3VdbeDelete(Vdbe*);
|
||||
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int);
|
||||
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
|
||||
int sqlite3VdbeFinalize(Vdbe*);
|
||||
void sqlite3VdbeResolveLabel(Vdbe*, int);
|
||||
int sqlite3VdbeCurrentAddr(Vdbe*);
|
||||
@@ -119,7 +129,7 @@ void sqlite3VdbeTrace(Vdbe*,FILE*);
|
||||
int sqlite3VdbeReset(Vdbe*);
|
||||
int sqliteVdbeSetVariables(Vdbe*,int,const char**);
|
||||
void sqlite3VdbeSetNumCols(Vdbe*,int);
|
||||
int sqlite3VdbeSetColName(Vdbe*, int, const char *, int);
|
||||
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
|
||||
void sqlite3VdbeCountChanges(Vdbe*);
|
||||
sqlite3 *sqlite3VdbeDb(Vdbe*);
|
||||
|
||||
|
||||
@@ -60,19 +60,19 @@ typedef unsigned char Bool;
|
||||
*/
|
||||
struct Cursor {
|
||||
BtCursor *pCursor; /* The cursor structure of the backend */
|
||||
i64 lastRecno; /* Last recno from a Next or NextIdx operation */
|
||||
int iDb; /* Index of cursor database in db->aDb[] (or -1) */
|
||||
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
|
||||
i64 nextRowid; /* Next rowid returned by OP_NewRowid */
|
||||
Bool zeroed; /* True if zeroed out and ready for reuse */
|
||||
Bool recnoIsValid; /* True if lastRecno is valid */
|
||||
Bool keyAsData; /* The OP_Column command works on key instead of data */
|
||||
Bool rowidIsValid; /* True if lastRowid is valid */
|
||||
Bool atFirst; /* True if pointing to first entry */
|
||||
Bool useRandomRowid; /* Generate new record numbers semi-randomly */
|
||||
Bool nullRow; /* True if pointing to a row with no data */
|
||||
Bool nextRowidValid; /* True if the nextRowid field is valid */
|
||||
Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */
|
||||
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
|
||||
Bool intKey; /* True if the table requires integer keys */
|
||||
Bool zeroData; /* True if table contains keys only - no data */
|
||||
Bool isTable; /* True if a table requiring integer keys */
|
||||
Bool isIndex; /* True if an index containing keys only - no data */
|
||||
u8 bogusIncrKey; /* Something for pIncrKey to point to if pKeyInfo==0 */
|
||||
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
|
||||
Btree *pBt; /* Separate file holding temporary table */
|
||||
@@ -82,12 +82,14 @@ struct Cursor {
|
||||
u8 *pIncrKey; /* Pointer to pKeyInfo->incrKey */
|
||||
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
|
||||
int nField; /* Number of fields in the header */
|
||||
i64 seqCount; /* Sequence counter */
|
||||
|
||||
/* Cached information about the header for the data record that the
|
||||
** cursor is currently pointing to. Only valid if cacheValid is true.
|
||||
** zRow might point to (ephemeral) data for the current row, or it might
|
||||
** be NULL. */
|
||||
Bool cacheValid; /* True if the cache is valid */
|
||||
** aRow might point to (ephemeral) data for the current row, or it might
|
||||
** be NULL.
|
||||
*/
|
||||
int cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
|
||||
int payloadSize; /* Total number of bytes in the record */
|
||||
u32 *aType; /* Type values for all entries in the record */
|
||||
u32 *aOffset; /* Cached offsets to the start of each columns data */
|
||||
@@ -102,6 +104,11 @@ typedef struct Cursor Cursor;
|
||||
*/
|
||||
#define NBFS 32
|
||||
|
||||
/*
|
||||
** A value for Cursor.cacheValid that means the cache is always invalid.
|
||||
*/
|
||||
#define CACHE_STALE 0
|
||||
|
||||
/*
|
||||
** Internally, the vdbe manipulates nearly all SQL values as Mem
|
||||
** structures. Each Mem struct may cache multiple representations (string,
|
||||
@@ -114,35 +121,18 @@ typedef struct Cursor Cursor;
|
||||
** SQLITE_BLOB.
|
||||
*/
|
||||
struct Mem {
|
||||
i64 i; /* Integer value */
|
||||
i64 i; /* Integer value. Or FuncDef* when flags==MEM_Agg */
|
||||
double r; /* Real value */
|
||||
char *z; /* String or BLOB value */
|
||||
int n; /* Number of characters in string value, including '\0' */
|
||||
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
u8 type; /* One of MEM_Null, MEM_Str, etc. */
|
||||
u8 enc; /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */
|
||||
double r; /* Real value */
|
||||
char *z; /* String or BLOB value */
|
||||
void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
|
||||
char zShort[NBFS]; /* Space for short strings */
|
||||
};
|
||||
typedef struct Mem Mem;
|
||||
|
||||
/*
|
||||
** A sorter builds a list of elements to be sorted. Each element of
|
||||
** the list is an instance of the following structure.
|
||||
*/
|
||||
typedef struct Sorter Sorter;
|
||||
struct Sorter {
|
||||
int nKey; /* Number of bytes in the key */
|
||||
char *zKey; /* The key by which we will sort */
|
||||
Mem data;
|
||||
Sorter *pNext; /* Next in the list */
|
||||
};
|
||||
|
||||
/*
|
||||
** Number of buckets used for merge-sort.
|
||||
*/
|
||||
#define NSORT 30
|
||||
|
||||
/* One or more of the following flags are set to indicate the validOK
|
||||
** representations of the value stored in the Mem struct.
|
||||
**
|
||||
@@ -174,12 +164,7 @@ struct Sorter {
|
||||
#define MEM_Static 0x0080 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x0100 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Short 0x0200 /* Mem.z points to Mem.zShort */
|
||||
|
||||
/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
|
||||
** It indicates that the corresponding AggElem.aMem.z points to a
|
||||
** aggregate function context that needs to be finalized.
|
||||
*/
|
||||
#define MEM_AggCtx 0x0400 /* Mem.z points to an agg function context */
|
||||
#define MEM_Agg 0x0400 /* Mem.z points to an agg function context */
|
||||
|
||||
|
||||
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
|
||||
@@ -211,41 +196,16 @@ typedef struct VdbeFunc VdbeFunc;
|
||||
** But this file is the only place where the internal details of this
|
||||
** structure are known.
|
||||
**
|
||||
** This structure is defined inside of vdbe.c because it uses substructures
|
||||
** This structure is defined inside of vdbeInt.h because it uses substructures
|
||||
** (Mem) which are only defined there.
|
||||
*/
|
||||
struct sqlite3_context {
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
|
||||
Mem s; /* The return value is stored here */
|
||||
void *pAgg; /* Aggregate context */
|
||||
u8 isError; /* Set to true for an error */
|
||||
int cnt; /* Number of times that the step function has been called */
|
||||
CollSeq *pColl;
|
||||
};
|
||||
|
||||
/*
|
||||
** An Agg structure describes an Aggregator. Each Agg consists of
|
||||
** zero or more Aggregator elements (AggElem). Each AggElem contains
|
||||
** a key and one or more values. The values are used in processing
|
||||
** aggregate functions in a SELECT. The key is used to implement
|
||||
** the GROUP BY clause of a select.
|
||||
*/
|
||||
typedef struct Agg Agg;
|
||||
typedef struct AggElem AggElem;
|
||||
struct Agg {
|
||||
int nMem; /* Number of values stored in each AggElem */
|
||||
AggElem *pCurrent; /* The AggElem currently in focus */
|
||||
FuncDef **apFunc; /* Information about aggregate functions */
|
||||
Btree *pBtree; /* The tmp. btree used to group elements, if required. */
|
||||
BtCursor *pCsr; /* Read/write cursor to the table in pBtree */
|
||||
int nTab; /* Root page of the table in pBtree */
|
||||
u8 searching; /* True between the first AggNext and AggReset */
|
||||
};
|
||||
struct AggElem {
|
||||
char *zKey; /* The key to this AggElem */
|
||||
int nKey; /* Number of bytes in the key, including '\0' at end */
|
||||
Mem aMem[1]; /* The values for this AggElem */
|
||||
Mem s; /* The return value is stored here */
|
||||
Mem *pMem; /* Memory cell used to store aggregate context */
|
||||
u8 isError; /* Set to true for an error */
|
||||
CollSeq *pColl; /* Collating sequence */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -261,17 +221,29 @@ struct Set {
|
||||
};
|
||||
|
||||
/*
|
||||
** A Keylist is a bunch of keys into a table. The keylist can
|
||||
** grow without bound. The keylist stores the ROWIDs of database
|
||||
** records that need to be deleted or updated.
|
||||
** A FifoPage structure holds a single page of valves. Pages are arranged
|
||||
** in a list.
|
||||
*/
|
||||
typedef struct Keylist Keylist;
|
||||
struct Keylist {
|
||||
int nKey; /* Number of slots in aKey[] */
|
||||
int nUsed; /* Next unwritten slot in aKey[] */
|
||||
int nRead; /* Next unread slot in aKey[] */
|
||||
Keylist *pNext; /* Next block of keys */
|
||||
i64 aKey[1]; /* One or more keys. Extra space allocated as needed */
|
||||
typedef struct FifoPage FifoPage;
|
||||
struct FifoPage {
|
||||
int nSlot; /* Number of entries aSlot[] */
|
||||
int iWrite; /* Push the next value into this entry in aSlot[] */
|
||||
int iRead; /* Read the next value from this entry in aSlot[] */
|
||||
FifoPage *pNext; /* Next page in the fifo */
|
||||
i64 aSlot[1]; /* One or more slots for rowid values */
|
||||
};
|
||||
|
||||
/*
|
||||
** The Fifo structure is typedef-ed in vdbeInt.h. But the implementation
|
||||
** of that structure is private to this file.
|
||||
**
|
||||
** The Fifo structure describes the entire fifo.
|
||||
*/
|
||||
typedef struct Fifo Fifo;
|
||||
struct Fifo {
|
||||
int nEntry; /* Total number of entries */
|
||||
FifoPage *pFirst; /* First page on the list */
|
||||
FifoPage *pLast; /* Last page on the list */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -285,9 +257,9 @@ struct Keylist {
|
||||
*/
|
||||
typedef struct Context Context;
|
||||
struct Context {
|
||||
int lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
|
||||
i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
|
||||
int nChange; /* Statement changes (Vdbe.nChanges) */
|
||||
Keylist *pList; /* Records that will participate in a DELETE or UPDATE */
|
||||
Fifo sFifo; /* Records that will participate in a DELETE or UPDATE */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -313,8 +285,6 @@ struct Vdbe {
|
||||
Mem *aColName; /* Column names to return */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
Cursor **apCsr; /* One element of this array for each open cursor */
|
||||
Sorter *pSort; /* A linked list of objects to be sorted */
|
||||
Sorter *pSortTail; /* Last element on the pSort list */
|
||||
int nVar; /* Number of entries in aVar[] */
|
||||
Mem *aVar; /* Values for the OP_Variable opcode. */
|
||||
char **azVar; /* Name of variables */
|
||||
@@ -322,11 +292,9 @@ struct Vdbe {
|
||||
int magic; /* Magic number for sanity checking */
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
Mem *aMem; /* The memory locations */
|
||||
int nAgg; /* Number of elements in apAgg */
|
||||
Agg *apAgg; /* Array of aggregate contexts */
|
||||
Agg *pAgg; /* Current aggregate context */
|
||||
int nCallback; /* Number of callbacks invoked so far */
|
||||
Keylist *pList; /* A list of ROWIDs */
|
||||
int cacheCtr; /* Cursor row cache generation counter */
|
||||
Fifo sFifo; /* A list of ROWIDs */
|
||||
int contextStackTop; /* Index of top element in the context stack */
|
||||
int contextStackDepth; /* The size of the "context" stack */
|
||||
Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/
|
||||
@@ -346,7 +314,9 @@ struct Vdbe {
|
||||
u8 changeCntOn; /* True to update the change-counter */
|
||||
u8 aborted; /* True if ROLLBACK in another VM causes an abort */
|
||||
u8 expired; /* True if the VM needs to be recompiled */
|
||||
u8 minWriteFileFormat; /* Minimum file format for writable database files */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -361,9 +331,6 @@ struct Vdbe {
|
||||
** Function prototypes
|
||||
*/
|
||||
void sqlite3VdbeFreeCursor(Cursor*);
|
||||
void sqlite3VdbeSorterReset(Vdbe*);
|
||||
int sqlite3VdbeAggReset(sqlite3*, Agg *, KeyInfo *);
|
||||
void sqlite3VdbeKeylistFree(Keylist*);
|
||||
void sqliteVdbePopStack(Vdbe*,int);
|
||||
int sqlite3VdbeCursorMoveto(Cursor*);
|
||||
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
|
||||
@@ -373,8 +340,8 @@ void sqlite3VdbePrintOp(FILE*, int, Op*);
|
||||
void sqlite3VdbePrintSql(Vdbe*);
|
||||
#endif
|
||||
int sqlite3VdbeSerialTypeLen(u32);
|
||||
u32 sqlite3VdbeSerialType(Mem*);
|
||||
int sqlite3VdbeSerialPut(unsigned char*, Mem*);
|
||||
u32 sqlite3VdbeSerialType(Mem*, int);
|
||||
int sqlite3VdbeSerialPut(unsigned char*, Mem*, int);
|
||||
int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
|
||||
|
||||
@@ -402,9 +369,12 @@ int sqlite3VdbeMemStringify(Mem*, int);
|
||||
i64 sqlite3VdbeIntValue(Mem*);
|
||||
int sqlite3VdbeMemIntegerify(Mem*);
|
||||
double sqlite3VdbeRealValue(Mem*);
|
||||
void sqlite3VdbeIntegerAffinity(Mem*);
|
||||
int sqlite3VdbeMemRealify(Mem*);
|
||||
int sqlite3VdbeMemNumerify(Mem*);
|
||||
int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
|
||||
void sqlite3VdbeMemRelease(Mem *p);
|
||||
int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
|
||||
#ifndef NDEBUG
|
||||
void sqlite3VdbeMemSanity(Mem*, u8);
|
||||
int sqlite3VdbeOpcodeNoPush(u8);
|
||||
@@ -412,3 +382,7 @@ int sqlite3VdbeOpcodeNoPush(u8);
|
||||
int sqlite3VdbeMemTranslate(Mem*, u8);
|
||||
void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf);
|
||||
int sqlite3VdbeMemHandleBom(Mem *pMem);
|
||||
void sqlite3VdbeFifoInit(Fifo*);
|
||||
int sqlite3VdbeFifoPush(Fifo*, i64);
|
||||
int sqlite3VdbeFifoPop(Fifo*, i64*);
|
||||
void sqlite3VdbeFifoClear(Fifo*);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** Return TRUE (non-zero) of the statement supplied as an argument needs
|
||||
@@ -23,8 +24,6 @@
|
||||
** that sqlite3_prepare() generates. For example, if new functions or
|
||||
** collating sequences are registered or if an authorizer function is
|
||||
** added or changed.
|
||||
**
|
||||
***** EXPERIMENTAL ******
|
||||
*/
|
||||
int sqlite3_expired(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
@@ -59,7 +58,7 @@ sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
||||
return sqlite3VdbeIntValue((Mem*)pVal);
|
||||
}
|
||||
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
|
||||
return (const char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_value_text16(sqlite3_value* pVal){
|
||||
@@ -75,6 +74,7 @@ const void *sqlite3_value_text16le(sqlite3_value *pVal){
|
||||
int sqlite3_value_type(sqlite3_value* pVal){
|
||||
return pVal->type;
|
||||
}
|
||||
/* sqlite3_value_numeric_type() defined in vdbe.c */
|
||||
|
||||
/**************************** sqlite3_result_ *******************************
|
||||
** The following routines are used by user-defined functions to specify
|
||||
@@ -86,7 +86,7 @@ void sqlite3_result_blob(
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
assert( n>0 );
|
||||
assert( n>=0 );
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel);
|
||||
}
|
||||
void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
|
||||
@@ -96,10 +96,12 @@ void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
|
||||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
|
||||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
|
||||
}
|
||||
#endif
|
||||
void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
|
||||
sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal);
|
||||
}
|
||||
@@ -157,6 +159,9 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
/* Assert that malloc() has not failed */
|
||||
assert( !sqlite3MallocFailed() );
|
||||
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
@@ -175,9 +180,10 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( p->pc<0 ){
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
/* Invoke the trace callback if there is one
|
||||
*/
|
||||
if( (db = p->db)->xTrace && !db->init.busy ){
|
||||
if( db->xTrace && !db->init.busy ){
|
||||
assert( p->nOp>0 );
|
||||
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
|
||||
assert( p->aOp[p->nOp-1].p3!=0 );
|
||||
@@ -189,6 +195,12 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
}
|
||||
if( db->xProfile && !db->init.busy ){
|
||||
double rNow;
|
||||
sqlite3OsCurrentTime(&rNow);
|
||||
p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned
|
||||
** on in debugging mode.
|
||||
@@ -215,7 +227,25 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
sqlite3Error(p->db, rc, p->zErrMsg);
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
/* Invoke the profile callback if there is one
|
||||
*/
|
||||
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){
|
||||
double rNow;
|
||||
u64 elapseTime;
|
||||
|
||||
sqlite3OsCurrentTime(&rNow);
|
||||
elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;
|
||||
assert( p->nOp>0 );
|
||||
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
|
||||
assert( p->aOp[p->nOp-1].p3!=0 );
|
||||
assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
|
||||
db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
sqlite3Error(p->db, rc, 0);
|
||||
p->rc = sqlite3ApiExit(p->db, p->rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -232,22 +262,27 @@ void *sqlite3_user_data(sqlite3_context *p){
|
||||
** Allocate or return the aggregate context for a user function. A new
|
||||
** context is allocated on the first call. Subsequent calls return the
|
||||
** same context that was returned on prior calls.
|
||||
**
|
||||
** This routine is defined here in vdbe.c because it depends on knowing
|
||||
** the internals of the sqlite3_context structure which is only defined in
|
||||
** this source file.
|
||||
*/
|
||||
void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
|
||||
Mem *pMem = p->pMem;
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
if( p->pAgg==0 ){
|
||||
if( nByte<=NBFS ){
|
||||
p->pAgg = (void*)p->s.z;
|
||||
memset(p->pAgg, 0, nByte);
|
||||
if( (pMem->flags & MEM_Agg)==0 ){
|
||||
if( nByte==0 ){
|
||||
assert( pMem->flags==MEM_Null );
|
||||
pMem->z = 0;
|
||||
}else{
|
||||
p->pAgg = sqliteMalloc( nByte );
|
||||
pMem->flags = MEM_Agg;
|
||||
pMem->xDel = sqlite3FreeX;
|
||||
*(FuncDef**)&pMem->i = p->pFunc;
|
||||
if( nByte<=NBFS ){
|
||||
pMem->z = pMem->zShort;
|
||||
memset(pMem->z, 0, nByte);
|
||||
}else{
|
||||
pMem->z = sqliteMalloc( nByte );
|
||||
}
|
||||
}
|
||||
}
|
||||
return p->pAgg;
|
||||
return (void*)pMem->z;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -280,8 +315,9 @@ void sqlite3_set_auxdata(
|
||||
pVdbeFunc = pCtx->pVdbeFunc;
|
||||
if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
|
||||
int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
|
||||
pCtx->pVdbeFunc = pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
|
||||
pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
|
||||
if( !pVdbeFunc ) return;
|
||||
pCtx->pVdbeFunc = pVdbeFunc;
|
||||
memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0,
|
||||
sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux));
|
||||
pVdbeFunc->nAux = iArg+1;
|
||||
@@ -300,13 +336,14 @@ void sqlite3_set_auxdata(
|
||||
** Return the number of times the Step function of a aggregate has been
|
||||
** called.
|
||||
**
|
||||
** This routine is defined here in vdbe.c because it depends on knowing
|
||||
** the internals of the sqlite3_context structure which is only defined in
|
||||
** this source file.
|
||||
** This function is deprecated. Do not use it for new code. It is
|
||||
** provide only to avoid breaking legacy code. New aggregate function
|
||||
** implementations should keep their own counts within their aggregate
|
||||
** context.
|
||||
*/
|
||||
int sqlite3_aggregate_count(sqlite3_context *p){
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
return p->cnt;
|
||||
return p->pMem->n;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -346,45 +383,115 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){
|
||||
return &pVm->pTos[(1-vals)+i];
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called after invoking an sqlite3_value_XXX function on a
|
||||
** column value (i.e. a value returned by evaluating an SQL expression in the
|
||||
** select list of a SELECT statement) that may cause a malloc() failure. If
|
||||
** malloc() has failed, the threads mallocFailed flag is cleared and the result
|
||||
** code of statement pStmt set to SQLITE_NOMEM.
|
||||
**
|
||||
** Specificly, this is called from within:
|
||||
**
|
||||
** sqlite3_column_int()
|
||||
** sqlite3_column_int64()
|
||||
** sqlite3_column_text()
|
||||
** sqlite3_column_text16()
|
||||
** sqlite3_column_real()
|
||||
** sqlite3_column_bytes()
|
||||
** sqlite3_column_bytes16()
|
||||
**
|
||||
** But not for sqlite3_column_blob(), which never calls malloc().
|
||||
*/
|
||||
static void columnMallocFailure(sqlite3_stmt *pStmt)
|
||||
{
|
||||
/* If malloc() failed during an encoding conversion within an
|
||||
** sqlite3_column_XXX API, then set the return code of the statement to
|
||||
** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
|
||||
** and _finalize() will return NOMEM.
|
||||
*/
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
p->rc = sqlite3ApiExit(0, p->rc);
|
||||
}
|
||||
|
||||
/**************************** sqlite3_column_ *******************************
|
||||
** The following routines are used to access elements of the current row
|
||||
** in the result set.
|
||||
*/
|
||||
const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
const void *val;
|
||||
sqlite3MallocDisallow();
|
||||
val = sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
sqlite3MallocAllow();
|
||||
return val;
|
||||
}
|
||||
int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
int val = sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_double( columnMem(pStmt,i) );
|
||||
double val = sqlite3_value_double( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int( columnMem(pStmt,i) );
|
||||
int val = sqlite3_value_int( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int64( columnMem(pStmt,i) );
|
||||
sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text( columnMem(pStmt,i) );
|
||||
const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
#if 0
|
||||
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
|
||||
return columnMem(pStmt, i);
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_type( columnMem(pStmt,i) );
|
||||
}
|
||||
|
||||
/* The following function is experimental and subject to change or
|
||||
** removal */
|
||||
/*int sqlite3_column_numeric_type(sqlite3_stmt *pStmt, int i){
|
||||
** return sqlite3_value_numeric_type( columnMem(pStmt,i) );
|
||||
**}
|
||||
*/
|
||||
|
||||
/*
|
||||
** Convert the N-th element of pStmt->pColName[] into a string using
|
||||
** xFunc() then return that string. If N is out of range, return 0.
|
||||
** If useType is 1, then use the second set of N elements (the datatype
|
||||
** names) instead of the first set.
|
||||
**
|
||||
** There are up to 5 names for each column. useType determines which
|
||||
** name is returned. Here are the names:
|
||||
**
|
||||
** 0 The column name as it should be displayed for output
|
||||
** 1 The datatype name for the column
|
||||
** 2 The name of the database that the column derives from
|
||||
** 3 The name of the table that the column derives from
|
||||
** 4 The name of the table column that the result column derives from
|
||||
**
|
||||
** If the result is not a simple column reference (if it is an expression
|
||||
** or a constant) then useTypes 2, 3, and 4 return NULL.
|
||||
*/
|
||||
static const void *columnName(
|
||||
sqlite3_stmt *pStmt,
|
||||
@@ -392,53 +499,104 @@ static const void *columnName(
|
||||
const void *(*xFunc)(Mem*),
|
||||
int useType
|
||||
){
|
||||
const void *ret;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
int n = sqlite3_column_count(pStmt);
|
||||
|
||||
if( p==0 || N>=n || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
if( useType ){
|
||||
N += n;
|
||||
}
|
||||
return xFunc(&p->aColName[N]);
|
||||
}
|
||||
N += useType*n;
|
||||
ret = xFunc(&p->aColName[N]);
|
||||
|
||||
/* A malloc may have failed inside of the xFunc() call. If this is the case,
|
||||
** clear the mallocFailed flag and return NULL.
|
||||
*/
|
||||
sqlite3ApiExit(0, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the name of the Nth column of the result set returned by SQL
|
||||
** statement pStmt.
|
||||
*/
|
||||
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Return the column declaration type (if applicable) of the 'i'th column
|
||||
** of the result set of SQL statement pStmt, encoded as UTF-8.
|
||||
** of the result set of SQL statement pStmt.
|
||||
*/
|
||||
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 1);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** Return the name of the 'i'th column of the result set of SQL statement
|
||||
** pStmt, encoded as UTF-16.
|
||||
*/
|
||||
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the column declaration type (if applicable) of the 'i'th column
|
||||
** of the result set of SQL statement pStmt, encoded as UTF-16.
|
||||
*/
|
||||
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
/*
|
||||
** Return the name of the database from which a result column derives.
|
||||
** NULL is returned if the result column is an expression or constant or
|
||||
** anything else which is not an unabiguous reference to a database column.
|
||||
*/
|
||||
const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Return the name of the table from which a result column derives.
|
||||
** NULL is returned if the result column is an expression or constant or
|
||||
** anything else which is not an unabiguous reference to a database column.
|
||||
*/
|
||||
const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Return the name of the table column from which a result column derives.
|
||||
** NULL is returned if the result column is an expression or constant or
|
||||
** anything else which is not an unabiguous reference to a database column.
|
||||
*/
|
||||
const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
#endif /* SQLITE_ENABLE_COLUMN_METADATA */
|
||||
|
||||
|
||||
/******************************* sqlite3_bind_ ***************************
|
||||
**
|
||||
** Routines used to attach values to wildcards in a compiled SQL statement.
|
||||
@@ -454,7 +612,7 @@ const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
|
||||
static int vdbeUnbind(Vdbe *p, int i){
|
||||
Mem *pVar;
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
|
||||
sqlite3Error(p->db, SQLITE_MISUSE, 0);
|
||||
if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( i<1 || i>p->nVar ){
|
||||
@@ -490,13 +648,12 @@ static int bindText(
|
||||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
if( rc==SQLITE_OK && encoding!=0 ){
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
|
||||
}
|
||||
return rc;
|
||||
|
||||
sqlite3Error(((Vdbe *)pStmt)->db, rc, 0);
|
||||
return sqlite3ApiExit(((Vdbe *)pStmt)->db, rc);
|
||||
}
|
||||
|
||||
|
||||
@@ -623,8 +780,7 @@ int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EXPERIMENTAL
|
||||
**
|
||||
/*
|
||||
** Transfer all bindings from the first statement over to the second.
|
||||
** If the two statements contain a different number of bindings, then
|
||||
** an SQLITE_ERROR is returned.
|
||||
@@ -641,7 +797,19 @@ int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){
|
||||
sqlite3MallocDisallow();
|
||||
rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
|
||||
sqlite3MallocAllow();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the sqlite3* database handle to which the prepared statement given
|
||||
** in the argument belongs. This is the same database handle that was
|
||||
** the first argument to the sqlite3_prepare() that was used to create
|
||||
** the statement in the first place.
|
||||
*/
|
||||
sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
|
||||
return pStmt ? ((Vdbe*)pStmt)->db : 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
114
sqlitebrowser/sqlitebrowser/sqlite_source/vdbefifo.c
Normal file
114
sqlitebrowser/sqlitebrowser/sqlite_source/vdbefifo.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
** 2005 June 16
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file implements a FIFO queue of rowids used for processing
|
||||
** UPDATE and DELETE statements.
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
** Allocate a new FifoPage and return a pointer to it. Return NULL if
|
||||
** we run out of memory. Leave space on the page for nEntry entries.
|
||||
*/
|
||||
static FifoPage *allocatePage(int nEntry){
|
||||
FifoPage *pPage;
|
||||
if( nEntry>32767 ){
|
||||
nEntry = 32767;
|
||||
}
|
||||
pPage = sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
|
||||
if( pPage ){
|
||||
pPage->nSlot = nEntry;
|
||||
pPage->iWrite = 0;
|
||||
pPage->iRead = 0;
|
||||
pPage->pNext = 0;
|
||||
}
|
||||
return pPage;
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize a Fifo structure.
|
||||
*/
|
||||
void sqlite3VdbeFifoInit(Fifo *pFifo){
|
||||
memset(pFifo, 0, sizeof(*pFifo));
|
||||
}
|
||||
|
||||
/*
|
||||
** Push a single 64-bit integer value into the Fifo. Return SQLITE_OK
|
||||
** normally. SQLITE_NOMEM is returned if we are unable to allocate
|
||||
** memory.
|
||||
*/
|
||||
int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){
|
||||
FifoPage *pPage;
|
||||
pPage = pFifo->pLast;
|
||||
if( pPage==0 ){
|
||||
pPage = pFifo->pLast = pFifo->pFirst = allocatePage(20);
|
||||
if( pPage==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
}else if( pPage->iWrite>=pPage->nSlot ){
|
||||
pPage->pNext = allocatePage(pFifo->nEntry);
|
||||
if( pPage->pNext==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pPage = pFifo->pLast = pPage->pNext;
|
||||
}
|
||||
pPage->aSlot[pPage->iWrite++] = val;
|
||||
pFifo->nEntry++;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Extract a single 64-bit integer value from the Fifo. The integer
|
||||
** extracted is the one least recently inserted. If the Fifo is empty
|
||||
** return SQLITE_DONE.
|
||||
*/
|
||||
int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){
|
||||
FifoPage *pPage;
|
||||
if( pFifo->nEntry==0 ){
|
||||
return SQLITE_DONE;
|
||||
}
|
||||
assert( pFifo->nEntry>0 );
|
||||
pPage = pFifo->pFirst;
|
||||
assert( pPage!=0 );
|
||||
assert( pPage->iWrite>pPage->iRead );
|
||||
assert( pPage->iWrite<=pPage->nSlot );
|
||||
assert( pPage->iRead<pPage->nSlot );
|
||||
assert( pPage->iRead>=0 );
|
||||
*pVal = pPage->aSlot[pPage->iRead++];
|
||||
pFifo->nEntry--;
|
||||
if( pPage->iRead>=pPage->iWrite ){
|
||||
pFifo->pFirst = pPage->pNext;
|
||||
sqliteFree(pPage);
|
||||
if( pFifo->nEntry==0 ){
|
||||
assert( pFifo->pLast==pPage );
|
||||
pFifo->pLast = 0;
|
||||
}else{
|
||||
assert( pFifo->pFirst!=0 );
|
||||
}
|
||||
}else{
|
||||
assert( pFifo->nEntry>0 );
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete all information from a Fifo object. Free all memory held
|
||||
** by the Fifo.
|
||||
*/
|
||||
void sqlite3VdbeFifoClear(Fifo *pFifo){
|
||||
FifoPage *pPage, *pNextPage;
|
||||
for(pPage=pFifo->pFirst; pPage; pPage=pNextPage){
|
||||
pNextPage = pPage->pNext;
|
||||
sqliteFree(pPage);
|
||||
}
|
||||
sqlite3VdbeFifoInit(pFifo);
|
||||
}
|
||||
@@ -41,11 +41,21 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
|
||||
#ifdef SQLITE_OMIT_UTF16
|
||||
return SQLITE_ERROR;
|
||||
#else
|
||||
|
||||
/* MemTranslate() may return SQLITE_OK or SQLITE_NOMEM. If NOMEM is returned,
|
||||
** then the encoding of the value may not have changed.
|
||||
*/
|
||||
rc = sqlite3VdbeMemTranslate(pMem, desiredEnc);
|
||||
assert(rc==SQLITE_OK || rc==SQLITE_NOMEM);
|
||||
assert(rc==SQLITE_OK || pMem->enc!=desiredEnc);
|
||||
assert(rc==SQLITE_NOMEM || pMem->enc==desiredEnc);
|
||||
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
/*
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->z = 0;
|
||||
*/
|
||||
}
|
||||
return rc;
|
||||
#endif
|
||||
@@ -73,7 +83,7 @@ int sqlite3VdbeMemDynamicify(Mem *pMem){
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = z;
|
||||
pMem->z = (char*)z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static|MEM_Short);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -93,7 +103,7 @@ int sqlite3VdbeMemMakeWriteable(Mem *pMem){
|
||||
assert( (pMem->flags & MEM_Dyn)==0 );
|
||||
assert( pMem->flags & (MEM_Str|MEM_Blob) );
|
||||
if( (n = pMem->n)+2<sizeof(pMem->zShort) ){
|
||||
z = pMem->zShort;
|
||||
z = (u8*)pMem->zShort;
|
||||
pMem->flags |= MEM_Short|MEM_Term;
|
||||
}else{
|
||||
z = sqliteMallocRaw( n+2 );
|
||||
@@ -106,7 +116,7 @@ int sqlite3VdbeMemMakeWriteable(Mem *pMem){
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = z;
|
||||
pMem->z = (char*)z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -162,7 +172,7 @@ int sqlite3VdbeMemNulTerminate(Mem *pMem){
|
||||
int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
int rc = SQLITE_OK;
|
||||
int fg = pMem->flags;
|
||||
u8 *z = pMem->zShort;
|
||||
char *z = pMem->zShort;
|
||||
|
||||
assert( !(fg&(MEM_Str|MEM_Blob)) );
|
||||
assert( fg&(MEM_Int|MEM_Real) );
|
||||
@@ -173,11 +183,11 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
**
|
||||
** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
|
||||
*/
|
||||
if( fg & MEM_Real ){
|
||||
sqlite3_snprintf(NBFS, z, "%.15g", pMem->r);
|
||||
}else{
|
||||
assert( fg & MEM_Int );
|
||||
if( fg & MEM_Int ){
|
||||
sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
|
||||
}else{
|
||||
assert( fg & MEM_Real );
|
||||
sqlite3_snprintf(NBFS, z, "%!.15g", pMem->r);
|
||||
}
|
||||
pMem->n = strlen(z);
|
||||
pMem->z = z;
|
||||
@@ -187,15 +197,54 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Memory cell pMem contains the context of an aggregate function.
|
||||
** This routine calls the finalize method for that function. The
|
||||
** result of the aggregate is stored back into pMem.
|
||||
**
|
||||
** Return SQLITE_ERROR if the finalizer reports an error. SQLITE_OK
|
||||
** otherwise.
|
||||
*/
|
||||
int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
|
||||
int rc = SQLITE_OK;
|
||||
if( pFunc && pFunc->xFinalize ){
|
||||
sqlite3_context ctx;
|
||||
assert( (pMem->flags & MEM_Null)!=0 || pFunc==*(FuncDef**)&pMem->i );
|
||||
ctx.s.flags = MEM_Null;
|
||||
ctx.s.z = pMem->zShort;
|
||||
ctx.pMem = pMem;
|
||||
ctx.pFunc = pFunc;
|
||||
ctx.isError = 0;
|
||||
pFunc->xFinalize(&ctx);
|
||||
if( pMem->z && pMem->z!=pMem->zShort ){
|
||||
sqliteFree( pMem->z );
|
||||
}
|
||||
*pMem = ctx.s;
|
||||
if( pMem->flags & MEM_Short ){
|
||||
pMem->z = pMem->zShort;
|
||||
}
|
||||
if( ctx.isError ){
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Release any memory held by the Mem. This may leave the Mem in an
|
||||
** inconsistent state, for example with (Mem.z==0) and
|
||||
** (Mem.type==SQLITE_TEXT).
|
||||
*/
|
||||
void sqlite3VdbeMemRelease(Mem *p){
|
||||
if( p->flags & MEM_Dyn ){
|
||||
if( p->flags & (MEM_Dyn|MEM_Agg) ){
|
||||
if( p->xDel ){
|
||||
p->xDel((void *)p->z);
|
||||
if( p->flags & MEM_Agg ){
|
||||
sqlite3VdbeMemFinalize(p, *(FuncDef**)&p->i);
|
||||
assert( (p->flags & MEM_Agg)==0 );
|
||||
sqlite3VdbeMemRelease(p);
|
||||
}else{
|
||||
p->xDel((void *)p->z);
|
||||
}
|
||||
}else{
|
||||
sqliteFree(p->z);
|
||||
}
|
||||
@@ -224,7 +273,7 @@ i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
i64 value;
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
return 0;
|
||||
}
|
||||
assert( pMem->z );
|
||||
sqlite3atoi64(pMem->z, &value);
|
||||
@@ -234,16 +283,6 @@ i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem to type integer. Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
pMem->i = sqlite3VdbeIntValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the best representation of pMem that we can get into a
|
||||
** double. If pMem is already a double or an integer, return its
|
||||
@@ -256,20 +295,44 @@ double sqlite3VdbeRealValue(Mem *pMem){
|
||||
}else if( pMem->flags & MEM_Int ){
|
||||
return (double)pMem->i;
|
||||
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
|
||||
double val = 0.0;
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
return 0.0;
|
||||
}
|
||||
assert( pMem->z );
|
||||
return sqlite3AtoF(pMem->z, 0);
|
||||
sqlite3AtoF(pMem->z, &val);
|
||||
return val;
|
||||
}else{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem so that it is of type MEM_Real. Invalidate any
|
||||
** prior representations.
|
||||
** The MEM structure is already a MEM_Real. Try to also make it a
|
||||
** MEM_Int if we can.
|
||||
*/
|
||||
void sqlite3VdbeIntegerAffinity(Mem *pMem){
|
||||
assert( pMem->flags & MEM_Real );
|
||||
pMem->i = pMem->r;
|
||||
if( ((double)pMem->i)==pMem->r ){
|
||||
pMem->flags |= MEM_Int;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem to type integer. Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
pMem->i = sqlite3VdbeIntValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem so that it is of type MEM_Real.
|
||||
** Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
pMem->r = sqlite3VdbeRealValue(pMem);
|
||||
@@ -278,6 +341,16 @@ int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem so that it has types MEM_Real or MEM_Int or both.
|
||||
** Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemNumerify(Mem *pMem){
|
||||
sqlite3VdbeMemRealify(pMem);
|
||||
sqlite3VdbeIntegerAffinity(pMem);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to NULL.
|
||||
*/
|
||||
@@ -285,6 +358,7 @@ void sqlite3VdbeMemSetNull(Mem *pMem){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->type = SQLITE_NULL;
|
||||
pMem->n = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -406,6 +480,7 @@ int sqlite3VdbeMemSetStr(
|
||||
switch( enc ){
|
||||
case 0:
|
||||
pMem->flags |= MEM_Blob;
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
break;
|
||||
|
||||
case SQLITE_UTF8:
|
||||
@@ -513,9 +588,9 @@ int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
|
||||
assert( pMem1->enc==SQLITE_UTF8 ||
|
||||
pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
|
||||
|
||||
/* This assert may fail if the collation sequence is deleted after this
|
||||
** vdbe program is compiled. The documentation defines this as an
|
||||
** undefined condition. A crash is usual result.
|
||||
/* The collation sequence must be defined at this point, even if
|
||||
** the user deletes the collation sequence after the vdbe program is
|
||||
** compiled (this was not always the case).
|
||||
*/
|
||||
assert( !pColl || pColl->xCmp );
|
||||
|
||||
@@ -608,8 +683,13 @@ int sqlite3VdbeMemFromBtree(
|
||||
zData[amt] = 0;
|
||||
zData[amt+1] = 0;
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( amt>NBFS ){
|
||||
if( amt>NBFS-2 ){
|
||||
assert( zData!=pMem->zShort );
|
||||
assert( pMem->flags & MEM_Dyn );
|
||||
sqliteFree(zData);
|
||||
} else {
|
||||
assert( zData==pMem->zShort );
|
||||
assert( pMem->flags & MEM_Short );
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -661,9 +741,9 @@ void sqlite3VdbeMemSanity(Mem *pMem, u8 db_enc){
|
||||
/* MEM_Null excludes all other types */
|
||||
assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
|
||||
|| (pMem->flags&MEM_Null)==0 );
|
||||
if( (pMem->flags & (MEM_Int|MEM_Real))==(MEM_Int|MEM_Real) ){
|
||||
assert( pMem->r==pMem->i );
|
||||
}
|
||||
/* If the MEM is both real and integer, the values are equal */
|
||||
assert( (pMem->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real)
|
||||
|| pMem->r==pMem->i );
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -680,18 +760,21 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
|
||||
if( pVal->flags&MEM_Null ){
|
||||
return 0;
|
||||
}
|
||||
assert( (MEM_Blob>>3) == MEM_Str );
|
||||
pVal->flags |= (pVal->flags & MEM_Blob)>>3;
|
||||
if( pVal->flags&MEM_Str ){
|
||||
sqlite3VdbeChangeEncoding(pVal, enc);
|
||||
}else if( !(pVal->flags&MEM_Blob) ){
|
||||
sqlite3VdbeMemStringify(pVal, enc);
|
||||
}
|
||||
return (const void *)(pVal->z);
|
||||
assert(pVal->enc==enc || sqlite3MallocFailed() );
|
||||
return (const void *)(pVal->enc==enc ? (pVal->z) : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new sqlite3_value object.
|
||||
*/
|
||||
sqlite3_value* sqlite3ValueNew(){
|
||||
sqlite3_value* sqlite3ValueNew(void){
|
||||
Mem *p = sqliteMalloc(sizeof(*p));
|
||||
if( p ){
|
||||
p->flags = MEM_Null;
|
||||
@@ -727,7 +810,7 @@ int sqlite3ValueFromExpr(
|
||||
op = pExpr->op;
|
||||
|
||||
if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
|
||||
zVal = sqliteStrNDup(pExpr->token.z, pExpr->token.n);
|
||||
zVal = sqliteStrNDup((char*)pExpr->token.z, pExpr->token.n);
|
||||
pVal = sqlite3ValueNew();
|
||||
if( !zVal || !pVal ) goto no_mem;
|
||||
sqlite3Dequote(zVal);
|
||||
@@ -747,7 +830,7 @@ int sqlite3ValueFromExpr(
|
||||
else if( op==TK_BLOB ){
|
||||
int nVal;
|
||||
pVal = sqlite3ValueNew();
|
||||
zVal = sqliteStrNDup(pExpr->token.z+1, pExpr->token.n-1);
|
||||
zVal = sqliteStrNDup((char*)pExpr->token.z+1, pExpr->token.n-1);
|
||||
if( !zVal || !pVal ) goto no_mem;
|
||||
sqlite3Dequote(zVal);
|
||||
nVal = strlen(zVal)/2;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user