Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
sqliteInt.h File Reference
#include "config.h"
#include "sqlite.h"
#include "hash.h"
#include "parse.h"
#include "btree.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "vdbe.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Db
struct  sqlite
struct  sqlite::sqliteInitInfo
struct  FuncDef
struct  Column
struct  Table
struct  FKey
struct  FKey::sColMap
struct  Index
struct  Token
struct  Expr
struct  ExprList
struct  ExprList::ExprList_item
struct  IdList
struct  IdList::IdList_item
struct  SrcList
struct  SrcList::SrcList_item
struct  WhereLevel
struct  WhereInfo
struct  Select
struct  AggExpr
struct  Parse
struct  AuthContext
struct  Trigger
struct  TriggerStep
struct  TriggerStack
struct  DbFixer

Defines

#define MAX_PAGES   2000
#define TEMP_PAGES   500
#define NULL_ALWAYS_DISTINCT   0
#define NULL_DISTINCT_FOR_UNIQUE   1
#define MAX_ATTACHED   10
#define TEMP_STORE   1
#define UINT32_TYPE   unsigned int
#define UINT16_TYPE   unsigned short int
#define INT16_TYPE   short int
#define UINT8_TYPE   unsigned char
#define INT8_TYPE   signed char
#define INTPTR_TYPE   long long
#define LONGDOUBLE_TYPE   long double
#define Addr(X)   ((uptr)X)
#define MAX_BYTES_PER_ROW   1048576
#define sqliteRealloc_(X, Y)   sqliteRealloc(X,Y)
#define sqliteStrRealloc(X)
#define MASTER_NAME   "sqlite_master"
#define TEMP_MASTER_NAME   "sqlite_temp_master"
#define SCHEMA_TABLE(x)   (x?TEMP_MASTER_NAME:MASTER_NAME)
#define ArraySize(X)   (sizeof(X)/sizeof(X[0]))
#define DbHasProperty(D, I, P)   (((D)->aDb[I].flags&(P))==(P))
#define DbHasAnyProperty(D, I, P)   (((D)->aDb[I].flags&(P))!=0)
#define DbSetProperty(D, I, P)   (D)->aDb[I].flags|=(P)
#define DbClearProperty(D, I, P)   (D)->aDb[I].flags&=~(P)
#define DB_Locked   0x0001 /* OP_Transaction opcode has been emitted */
#define DB_Cookie   0x0002 /* OP_VerifyCookie opcode has been emiited */
#define DB_SchemaLoaded   0x0004 /* The schema has been loaded */
#define DB_UnresetViews   0x0008 /* Some views have defined column names */
#define SQLITE_VdbeTrace   0x00000001 /* True to trace VDBE execution */
#define SQLITE_Initialized   0x00000002 /* True after initialization */
#define SQLITE_Interrupt   0x00000004 /* Cancel current operation */
#define SQLITE_InTrans   0x00000008 /* True if in a transaction */
#define SQLITE_InternChanges   0x00000010 /* Uncommitted Hash table changes */
#define SQLITE_FullColNames   0x00000020 /* Show full column names on SELECT */
#define SQLITE_ShortColNames   0x00000040 /* Show short columns names */
#define SQLITE_CountRows   0x00000080 /* Count rows changed by INSERT, */
#define SQLITE_NullCallback   0x00000100 /* Invoke the callback once if the */
#define SQLITE_ReportTypes   0x00000200 /* Include information on datatypes */
#define SQLITE_MAGIC_OPEN   0xa029a697 /* Database is open */
#define SQLITE_MAGIC_CLOSED   0x9f3c2d33 /* Database is closed */
#define SQLITE_MAGIC_BUSY   0xf03b7906 /* Database currently in use */
#define SQLITE_MAGIC_ERROR   0xb5357930 /* An SQLITE_MISUSE error occurred */
#define SQLITE_SO_UNK   0 /* Use the default collating type. (SCT_NUM) */
#define SQLITE_SO_TEXT   2 /* Sort using memcmp() */
#define SQLITE_SO_NUM   4 /* Sort using sqliteCompare() */
#define SQLITE_SO_TYPEMASK   6 /* Mask to extract the collating sequence */
#define SQLITE_SO_ASC   0 /* Sort in ascending order */
#define SQLITE_SO_DESC   1 /* Sort in descending order */
#define SQLITE_SO_DIRMASK   1 /* Mask to extract the sort direction */
#define OE_None   0 /* There is no constraint to check */
#define OE_Rollback   1 /* Fail the operation and rollback the transaction */
#define OE_Abort   2 /* Back out changes but do no rollback transaction */
#define OE_Fail   3 /* Stop the operation but leave all prior changes */
#define OE_Ignore   4 /* Ignore the error. Do not do the INSERT or UPDATE */
#define OE_Replace   5 /* Delete existing record, then do INSERT or UPDATE */
#define OE_Restrict   6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
#define OE_SetNull   7 /* Set the foreign key value to NULL */
#define OE_SetDflt   8 /* Set the foreign key value to its default */
#define OE_Cascade   9 /* Cascade the changes */
#define OE_Default   99 /* Do whatever the default action is */
#define EP_FromJoin   0x0001 /* Originated in ON or USING clause of a join */
#define ExprHasProperty(E, P)   (((E)->flags&(P))==(P))
#define ExprHasAnyProperty(E, P)   (((E)->flags&(P))!=0)
#define ExprSetProperty(E, P)   (E)->flags|=(P)
#define ExprClearProperty(E, P)   (E)->flags&=~(P)
#define JT_INNER   0x0001 /* Any kind of inner or cross join */
#define JT_NATURAL   0x0002 /* True for a "natural" join */
#define JT_LEFT   0x0004 /* Left outer join */
#define JT_RIGHT   0x0008 /* Right outer join */
#define JT_OUTER   0x0010 /* The "OUTER" keyword is present */
#define JT_ERROR   0x0020 /* unknown or unsupported join type */
#define SRT_Callback   1 /* Invoke a callback with each row of result */
#define SRT_Mem   2 /* Store result in a memory cell */
#define SRT_Set   3 /* Store result as unique keys in a table */
#define SRT_Union   5 /* Store result as keys in a table */
#define SRT_Except   6 /* Remove result from a UNION table */
#define SRT_Table   7 /* Store result as data with a unique key */
#define SRT_TempTable   8 /* Store result in a trasient table */
#define SRT_Discard   9 /* Do not save the results anywhere */
#define SRT_Sorter   10 /* Store results in the sorter */
#define SRT_Subroutine   11 /* Call a subroutine to handle results */
#define OPFLAG_NCHANGE   1 /* Set to update db->nChange */
#define OPFLAG_LASTROWID   2 /* Set to update db->lastRowid */
#define OPFLAG_CSCHANGE   4 /* Set to update db->csChange */
#define sqliteCheckMemory(a, b)

Typedefs

typedef UINT32_TYPE u32
typedef UINT16_TYPE u16
typedef INT16_TYPE i16
typedef UINT8_TYPE u8
typedef UINT8_TYPE i8
typedef INTPTR_TYPE ptr
typedef unsigned INTPTR_TYPE uptr
typedef struct Column
typedef struct Table
typedef struct Index
typedef struct Instruction
typedef struct Expr
typedef struct ExprList
typedef struct Parse
typedef struct Token
typedef struct IdList
typedef struct SrcList
typedef struct WhereInfo
typedef struct WhereLevel
typedef struct Select
typedef struct AggExpr
typedef struct FuncDef
typedef struct Trigger
typedef struct TriggerStep
typedef struct TriggerStack
typedef struct FKey
typedef struct Db
typedef struct AuthContext
typedef struct DbFixer

Functions

int sqliteStrICmp (const char *, const char *)
int sqliteStrNICmp (const char *, const char *, int)
int sqliteHashNoCase (const char *, int)
int sqliteIsNumber (const char *)
int sqliteCompare (const char *, const char *)
int sqliteSortCompare (const char *, const char *)
void sqliteRealToSortable (double r, char *)
void * sqliteMalloc (int)
void * sqliteMallocRaw (int)
void sqliteFree (void *)
void * sqliteRealloc (void *, int)
char * sqliteStrDup (const char *)
char * sqliteStrNDup (const char *, int)
char * sqliteMPrintf (const char *,...)
char * sqliteVMPrintf (const char *, va_list)
void sqliteSetString (char **,...)
void sqliteSetNString (char **,...)
void sqliteErrorMsg (Parse *, const char *,...)
void sqliteDequote (char *)
int sqliteKeywordCode (const char *, int)
int sqliteRunParser (Parse *, const char *, char **)
void sqliteExec (Parse *)
ExprsqliteExpr (int, Expr *, Expr *, Token *)
void sqliteExprSpan (Expr *, Token *, Token *)
ExprsqliteExprFunction (ExprList *, Token *)
void sqliteExprDelete (Expr *)
ExprListsqliteExprListAppend (ExprList *, Expr *, Token *)
void sqliteExprListDelete (ExprList *)
int sqliteInit (sqlite *, char **)
void sqlitePragma (Parse *, Token *, Token *, int)
void sqliteResetInternalSchema (sqlite *, int)
void sqliteBeginParse (Parse *, int)
void sqliteRollbackInternalChanges (sqlite *)
void sqliteCommitInternalChanges (sqlite *)
TablesqliteResultSetOfSelect (Parse *, char *, Select *)
void sqliteOpenMasterTable (Vdbe *v, int)
void sqliteStartTable (Parse *, Token *, Token *, int, int)
void sqliteAddColumn (Parse *, Token *)
void sqliteAddNotNull (Parse *, int)
void sqliteAddPrimaryKey (Parse *, IdList *, int)
void sqliteAddColumnType (Parse *, Token *, Token *)
void sqliteAddDefaultValue (Parse *, Token *, int)
int sqliteCollateType (const char *, int)
void sqliteAddCollateType (Parse *, int)
void sqliteEndTable (Parse *, Token *, Select *)
void sqliteCreateView (Parse *, Token *, Token *, Select *, int)
int sqliteViewGetColumnNames (Parse *, Table *)
void sqliteDropTable (Parse *, Token *, int)
void sqliteDeleteTable (sqlite *, Table *)
void sqliteInsert (Parse *, SrcList *, ExprList *, Select *, IdList *, int)
IdListsqliteIdListAppend (IdList *, Token *)
int sqliteIdListIndex (IdList *, const char *)
SrcListsqliteSrcListAppend (SrcList *, Token *, Token *)
void sqliteSrcListAddAlias (SrcList *, Token *)
void sqliteSrcListAssignCursors (Parse *, SrcList *)
void sqliteIdListDelete (IdList *)
void sqliteSrcListDelete (SrcList *)
void sqliteCreateIndex (Parse *, Token *, SrcList *, IdList *, int, Token *, Token *)
void sqliteDropIndex (Parse *, SrcList *)
void sqliteAddKeyType (Vdbe *, ExprList *)
void sqliteAddIdxKeyType (Vdbe *, Index *)
int sqliteSelect (Parse *, Select *, int, int, Select *, int, int *)
SelectsqliteSelectNew (ExprList *, SrcList *, Expr *, ExprList *, Expr *, ExprList *, int, int, int)
void sqliteSelectDelete (Select *)
void sqliteSelectUnbind (Select *)
TablesqliteSrcListLookup (Parse *, SrcList *)
int sqliteIsReadOnly (Parse *, Table *, int)
void sqliteDeleteFrom (Parse *, SrcList *, Expr *)
void sqliteUpdate (Parse *, SrcList *, ExprList *, Expr *, int)
WhereInfosqliteWhereBegin (Parse *, SrcList *, Expr *, int, ExprList **)
void sqliteWhereEnd (WhereInfo *)
void sqliteExprCode (Parse *, Expr *)
int sqliteExprCodeExprList (Parse *, ExprList *, int)
void sqliteExprIfTrue (Parse *, Expr *, int, int)
void sqliteExprIfFalse (Parse *, Expr *, int, int)
TablesqliteFindTable (sqlite *, const char *, const char *)
TablesqliteLocateTable (Parse *, const char *, const char *)
IndexsqliteFindIndex (sqlite *, const char *, const char *)
void sqliteUnlinkAndDeleteIndex (sqlite *, Index *)
void sqliteCopy (Parse *, SrcList *, Token *, Token *, int)
void sqliteVacuum (Parse *, Token *)
int sqliteRunVacuum (char **, sqlite *)
int sqliteGlobCompare (const unsigned char *, const unsigned char *)
int sqliteLikeCompare (const unsigned char *, const unsigned char *)
char * sqliteTableNameFromToken (Token *)
int sqliteExprCheck (Parse *, Expr *, int, int *)
int sqliteExprType (Expr *)
int sqliteExprCompare (Expr *, Expr *)
int sqliteFuncId (Token *)
int sqliteExprResolveIds (Parse *, SrcList *, ExprList *, Expr *)
int sqliteExprAnalyzeAggregates (Parse *, Expr *)
VdbesqliteGetVdbe (Parse *)
void sqliteRandomness (int, void *)
void sqliteRollbackAll (sqlite *)
void sqliteCodeVerifySchema (Parse *, int)
void sqliteBeginTransaction (Parse *, int)
void sqliteCommitTransaction (Parse *)
void sqliteRollbackTransaction (Parse *)
int sqliteExprIsConstant (Expr *)
int sqliteExprIsInteger (Expr *, int *)
int sqliteIsRowid (const char *)
void sqliteGenerateRowDelete (sqlite *, Vdbe *, Table *, int, int)
void sqliteGenerateRowIndexDelete (sqlite *, Vdbe *, Table *, int, char *)
void sqliteGenerateConstraintChecks (Parse *, Table *, int, char *, int, int, int, int)
void sqliteCompleteInsertion (Parse *, Table *, int, char *, int, int, int)
int sqliteOpenTableAndIndices (Parse *, Table *, int)
void sqliteBeginWriteOperation (Parse *, int, int)
void sqliteEndWriteOperation (Parse *)
ExprsqliteExprDup (Expr *)
void sqliteTokenCopy (Token *, Token *)
ExprListsqliteExprListDup (ExprList *)
SrcListsqliteSrcListDup (SrcList *)
IdListsqliteIdListDup (IdList *)
SelectsqliteSelectDup (Select *)
FuncDefsqliteFindFunction (sqlite *, const char *, int, int, int)
void sqliteRegisterBuiltinFunctions (sqlite *)
void sqliteRegisterDateTimeFunctions (sqlite *)
int sqliteSafetyOn (sqlite *)
int sqliteSafetyOff (sqlite *)
int sqliteSafetyCheck (sqlite *)
void sqliteChangeCookie (sqlite *, Vdbe *)
void sqliteBeginTrigger (Parse *, Token *, int, int, IdList *, SrcList *, int, Expr *, int)
void sqliteFinishTrigger (Parse *, TriggerStep *, Token *)
void sqliteDropTrigger (Parse *, SrcList *)
void sqliteDropTriggerPtr (Parse *, Trigger *, int)
int sqliteTriggersExist (Parse *, Trigger *, int, int, int, ExprList *)
int sqliteCodeRowTrigger (Parse *, int, ExprList *, int, Table *, int, int, int, int)
void sqliteViewTriggers (Parse *, Table *, Expr *, int, ExprList *)
void sqliteDeleteTriggerStep (TriggerStep *)
TriggerStepsqliteTriggerSelectStep (Select *)
TriggerStepsqliteTriggerInsertStep (Token *, IdList *, ExprList *, Select *, int)
TriggerStepsqliteTriggerUpdateStep (Token *, ExprList *, Expr *, int)
TriggerStepsqliteTriggerDeleteStep (Token *, Expr *)
void sqliteDeleteTrigger (Trigger *)
int sqliteJoinType (Parse *, Token *, Token *, Token *)
void sqliteCreateForeignKey (Parse *, IdList *, Token *, IdList *, int)
void sqliteDeferForeignKey (Parse *, int)
void sqliteAuthRead (Parse *, Expr *, SrcList *)
int sqliteAuthCheck (Parse *, int, const char *, const char *, const char *)
void sqliteAuthContextPush (Parse *, AuthContext *, const char *)
void sqliteAuthContextPop (AuthContext *)
void sqliteAttach (Parse *, Token *, Token *, Token *)
void sqliteDetach (Parse *, Token *)
int sqliteBtreeFactory (const sqlite *db, const char *zFilename, int mode, int nPg, Btree **ppBtree)
int sqliteFixInit (DbFixer *, Parse *, int, const char *, const Token *)
int sqliteFixSrcList (DbFixer *, SrcList *)
int sqliteFixSelect (DbFixer *, Select *)
int sqliteFixExpr (DbFixer *, Expr *)
int sqliteFixExprList (DbFixer *, ExprList *)
int sqliteFixTriggerStep (DbFixer *, TriggerStep *)
double sqliteAtoF (const char *z, const char **)
char * sqlite_snprintf (int, char *, const char *,...)
int sqliteFitsIn32Bits (const char *)

Variables

int sqlite_malloc_failed
int always_code_trigger_setup

Class Documentation

struct sqlite::sqliteInitInfo

Definition at line 368 of file sqliteInt.h.

Class Members
u8 busy
int iDb
int newTnum
struct Column

Definition at line 442 of file sqliteInt.h.

Collaboration diagram for Column:
Class Members
char affinity
u8 dottedName
u8 isHidden
u8 isPrimKey
u8 notNull
Expr * pDflt
u8 sortOrder
char * zColl
char * zDflt
char * zName
char * zType
struct Table

Definition at line 496 of file sqliteInt.h.

Collaboration diagram for Table:
Class Members
Column * aCol
int addColOffset
char ** azModuleArg
u8 hasPrimKey
u8 iDb
int iPKey
u8 isTransient
u8 keyConf
int nCol
int nModuleArg
u16 nRef
unsigned nRowEst
Expr * pCheck
FKey * pFKey
Index * pIndex
Table * pNextZombie
Schema * pSchema
Select * pSelect
Trigger * pTrigger
VTable * pVTable
u8 readOnly
u8 tabFlags
int tnum
char * zColAff
char * zName
struct FKey

Definition at line 538 of file sqliteInt.h.

Collaboration diagram for FKey:
Class Members
u8 aAction
struct sColMap * aCol
struct sColMap aCol
Trigger * apTrigger
u8 deleteConf
u8 insertConf
u8 isDeferred
int nCol
Table * pFrom
FKey * pNextFrom
FKey * pNextTo
FKey * pPrevTo
u8 updateConf
char * zTo
struct FKey::sColMap

Definition at line 544 of file sqliteInt.h.

Class Members
int iFrom
char * zCol
struct Index

Definition at line 619 of file sqliteInt.h.

Collaboration diagram for Index:
Class Members
int * aiColumn
unsigned * aiRowEst
IndexSample * aSample
u8 * aSortOrder
u8 autoIndex
char ** azColl
u8 bUnordered
u8 iDb
int nColumn
u8 onError
Index * pNext
Schema * pSchema
Table * pTable
int tnum
char * zColAff
char * zName
struct Token

Definition at line 639 of file sqliteInt.h.

Class Members
unsigned dyn: 1
unsigned n: 31
unsigned int n
const char * z
struct Expr

Definition at line 681 of file sqliteInt.h.

Collaboration diagram for Expr:
Class Members
char affinity
u8 dataType
u8 flags
u16 flags
u8 flags2
int iAgg
i16 iAgg
int iColumn
ynVar iColumn
u8 iDb
i16 iRightJoinTable
int iTable
int nHeight
u8 op
u8 op2
AggInfo * pAggInfo
CollSeq * pColl
Expr * pLeft
ExprList * pList
Expr * pRight
Select * pSelect
Table * pTab
Token span
Token token
union Expr u
union Expr x
struct ExprList

Definition at line 721 of file sqliteInt.h.

Collaboration diagram for ExprList:
Class Members
struct ExprList_item * a
int iECursor
int nAlloc
int nExpr
struct ExprList::ExprList_item

Definition at line 724 of file sqliteInt.h.

Collaboration diagram for ExprList::ExprList_item:
Class Members
u8 done
u16 iAlias
u16 iCol
u8 isAgg
Expr * pExpr
u8 sortOrder
char * zName
char * zSpan
struct IdList

Definition at line 748 of file sqliteInt.h.

Collaboration diagram for IdList:
Class Members
struct IdList_item * a
int nAlloc
int nId
struct IdList::IdList_item

Definition at line 751 of file sqliteInt.h.

Class Members
int idx
char * zName
struct SrcList

Definition at line 768 of file sqliteInt.h.

Collaboration diagram for SrcList:
Class Members
struct SrcList_item a
i16 nAlloc
i16 nSrc
struct SrcList::SrcList_item

Definition at line 771 of file sqliteInt.h.

Collaboration diagram for SrcList::SrcList_item:
Class Members
Bitmask colUsed
int iCursor
u8 iSelectId
u8 isPopulated
int jointype
u8 jointype
u8 notIndexed
Index * pIndex
Expr * pOn
Select * pSelect
Table * pTab
IdList * pUsing
char * zAlias
char * zDatabase
char * zIndex
char * zName
struct WhereLevel

Definition at line 800 of file sqliteInt.h.

Collaboration diagram for WhereLevel:
Class Members
int addrBrk
int addrCont
int addrFirst
int addrNxt
int bRev
int brk
int cont
int iCur
u8 iFrom
int iIdxCur
int iLeftJoin
int iMem
int inOp
int inP1
int inP2
int iTabCur
int op
u8 op
int p1
int p2
u8 p5
Index * pIdx
sqlite3_index_info * pIdxInfo
WherePlan plan
int score
int top
union WhereLevel u
struct WhereInfo

Definition at line 821 of file sqliteInt.h.

Collaboration diagram for WhereInfo:
Class Members
WhereLevel a
int iBreak
int iContinue
int iTop
int nLevel
double nRowOut
u8 okOnePass
int peakNTab
Parse * pParse
SrcList * pTabList
struct WhereClause * pWC
double savedNQueryLoop
int savedNTab
u8 untestedTerms
u16 wctrlFlags
struct Select

Definition at line 850 of file sqliteInt.h.

Collaboration diagram for Select:
Class Members
int addrOpenEphm
char affinity
int iLimit
int iOffset
u8 isDistinct
int nLimit
int nOffset
double nSelectRow
u8 op
ExprList * pEList
ExprList * pGroupBy
Expr * pHaving
Expr * pLimit
Select * pNext
Expr * pOffset
ExprList * pOrderBy
Select * pPrior
Select * pRightmost
SrcList * pSrc
Expr * pWhere
u16 selFlags
char * zSelect
struct AggExpr

Definition at line 898 of file sqliteInt.h.

Collaboration diagram for AggExpr:
Class Members
int isAgg
Expr * pExpr
FuncDef * pFunc
struct Parse

Definition at line 909 of file sqliteInt.h.

Collaboration diagram for Parse:
Class Members
AggExpr * aAgg
int * aAlias
struct yColCache aColCache
Table ** apVtabLock
TableLock * aTableLock
int aTempReg
char ** azVar
u8 checkSchema
int ckBase
u8 colNamesSet
int cookieGoto
yDbMask cookieMask
int cookieValue
sqlite * db
sqlite3 * db
u8 declareVtab
u8 disableTriggers
u8 eOrconf
u8 eTriggerOp
u8 explain
int iCacheCnt
int iCacheLevel
u8 iColCache
int iNextSelectId
int iRangeReg
int iSelectId
u8 isMultiWrite
u8 mayAbort
int nAgg
int nAlias
int nAliasAlloc
u8 nameClash
u8 nColCache
int nErr
u8 nested
u32 newmask
int nHeight
int nMaxArg
int nMem
double nQueryLoop
int nRangeReg
int nSet
int nTab
int nTableLock
u8 nTempInUse
u8 nTempReg
int nVar
int nVtabLock
int nzVar
u32 oldmask
AutoincInfo * pAinc
u8 parseError
Table * pNewTable
Trigger * pNewTrigger
Vdbe * pReprepare
Parse * pToplevel
TriggerPrg * pTriggerPrg
Table * pTriggerTab
Vdbe * pVdbe
Table * pZombieTab
int rc
int regRoot
int regRowid
Token sArg
Token sErrToken
Token sFirstToken
Token sLastToken
Token sNameToken
TriggerStack * trigStack
u8 useAgg
yDbMask writeMask
const char * zAuthContext
char * zErrMsg
const char * zTail
struct AuthContext

Definition at line 940 of file sqliteInt.h.

Collaboration diagram for AuthContext:
Class Members
Parse * pParse
const char * zAuthContext
struct Trigger

Definition at line 967 of file sqliteInt.h.

Collaboration diagram for Trigger:
Class Members
int foreach
u8 iDb
u8 iTabDb
char * name
Token nameToken
u8 op
IdList * pColumns
Trigger * pNext
Schema * pSchema
Schema * pTabSchema
Expr * pWhen
TriggerStep * step_list
char * table
u8 tr_tm
char * zName
struct TriggerStep

Definition at line 1022 of file sqliteInt.h.

Collaboration diagram for TriggerStep:
Class Members
int op
u8 op
int orconf
u8 orconf
ExprList * pExprList
IdList * pIdList
TriggerStep * pLast
TriggerStep * pNext
Select * pSelect
Trigger * pTrig
Expr * pWhere
Token target
struct TriggerStack

Definition at line 1065 of file sqliteInt.h.

Collaboration diagram for TriggerStack:
Class Members
int ignoreJump
int newIdx
int oldIdx
int orconf
TriggerStack * pNext
Table * pTab
Trigger * pTrigger
struct DbFixer

Definition at line 1081 of file sqliteInt.h.

Collaboration diagram for DbFixer:
Class Members
const Token * pName
Parse * pParse
const char * zDb
const char * zType

Define Documentation

#define Addr (   X)    ((uptr)X)

Definition at line 147 of file sqliteInt.h.

#define ArraySize (   X)    (sizeof(X)/sizeof(X[0]))

Definition at line 226 of file sqliteInt.h.

#define DB_Cookie   0x0002 /* OP_VerifyCookie opcode has been emiited */

Definition at line 301 of file sqliteInt.h.

#define DB_Locked   0x0001 /* OP_Transaction opcode has been emitted */

Definition at line 300 of file sqliteInt.h.

#define DB_SchemaLoaded   0x0004 /* The schema has been loaded */

Definition at line 302 of file sqliteInt.h.

#define DB_UnresetViews   0x0008 /* Some views have defined column names */

Definition at line 303 of file sqliteInt.h.

#define DbClearProperty (   D,
  I,
  P 
)    (D)->aDb[I].flags&=~(P)

Definition at line 281 of file sqliteInt.h.

#define DbHasAnyProperty (   D,
  I,
  P 
)    (((D)->aDb[I].flags&(P))!=0)

Definition at line 279 of file sqliteInt.h.

#define DbHasProperty (   D,
  I,
  P 
)    (((D)->aDb[I].flags&(P))==(P))

Definition at line 278 of file sqliteInt.h.

#define DbSetProperty (   D,
  I,
  P 
)    (D)->aDb[I].flags|=(P)

Definition at line 280 of file sqliteInt.h.

#define EP_FromJoin   0x0001 /* Originated in ON or USING clause of a join */

Definition at line 702 of file sqliteInt.h.

#define ExprClearProperty (   E,
  P 
)    (E)->flags&=~(P)

Definition at line 711 of file sqliteInt.h.

#define ExprHasAnyProperty (   E,
  P 
)    (((E)->flags&(P))!=0)

Definition at line 709 of file sqliteInt.h.

#define ExprHasProperty (   E,
  P 
)    (((E)->flags&(P))==(P))

Definition at line 708 of file sqliteInt.h.

#define ExprSetProperty (   E,
  P 
)    (E)->flags|=(P)

Definition at line 710 of file sqliteInt.h.

#define INT16_TYPE   short int

Definition at line 106 of file sqliteInt.h.

#define INT8_TYPE   signed char

Definition at line 112 of file sqliteInt.h.

#define INTPTR_TYPE   long long

Definition at line 118 of file sqliteInt.h.

#define JT_ERROR   0x0020 /* unknown or unsupported join type */

Definition at line 792 of file sqliteInt.h.

#define JT_INNER   0x0001 /* Any kind of inner or cross join */

Definition at line 787 of file sqliteInt.h.

#define JT_LEFT   0x0004 /* Left outer join */

Definition at line 789 of file sqliteInt.h.

#define JT_NATURAL   0x0002 /* True for a "natural" join */

Definition at line 788 of file sqliteInt.h.

#define JT_OUTER   0x0010 /* The "OUTER" keyword is present */

Definition at line 791 of file sqliteInt.h.

#define JT_RIGHT   0x0008 /* Right outer join */

Definition at line 790 of file sqliteInt.h.

#define LONGDOUBLE_TYPE   long double

Definition at line 140 of file sqliteInt.h.

#define MASTER_NAME   "sqlite_master"

Definition at line 214 of file sqliteInt.h.

#define MAX_ATTACHED   10

Definition at line 65 of file sqliteInt.h.

#define MAX_BYTES_PER_ROW   1048576

Definition at line 163 of file sqliteInt.h.

#define MAX_PAGES   2000

Definition at line 30 of file sqliteInt.h.

#define NULL_ALWAYS_DISTINCT   0

Definition at line 43 of file sqliteInt.h.

#define NULL_DISTINCT_FOR_UNIQUE   1

Definition at line 57 of file sqliteInt.h.

#define OE_Abort   2 /* Back out changes but do no rollback transaction */

Definition at line 581 of file sqliteInt.h.

#define OE_Cascade   9 /* Cascade the changes */

Definition at line 589 of file sqliteInt.h.

#define OE_Default   99 /* Do whatever the default action is */

Definition at line 591 of file sqliteInt.h.

#define OE_Fail   3 /* Stop the operation but leave all prior changes */

Definition at line 582 of file sqliteInt.h.

#define OE_Ignore   4 /* Ignore the error. Do not do the INSERT or UPDATE */

Definition at line 583 of file sqliteInt.h.

#define OE_None   0 /* There is no constraint to check */

Definition at line 579 of file sqliteInt.h.

#define OE_Replace   5 /* Delete existing record, then do INSERT or UPDATE */

Definition at line 584 of file sqliteInt.h.

#define OE_Restrict   6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */

Definition at line 586 of file sqliteInt.h.

#define OE_Rollback   1 /* Fail the operation and rollback the transaction */

Definition at line 580 of file sqliteInt.h.

#define OE_SetDflt   8 /* Set the foreign key value to its default */

Definition at line 588 of file sqliteInt.h.

#define OE_SetNull   7 /* Set the foreign key value to NULL */

Definition at line 587 of file sqliteInt.h.

#define OPFLAG_CSCHANGE   4 /* Set to update db->csChange */

Definition at line 950 of file sqliteInt.h.

#define OPFLAG_LASTROWID   2 /* Set to update db->lastRowid */

Definition at line 949 of file sqliteInt.h.

#define OPFLAG_NCHANGE   1 /* Set to update db->nChange */

Definition at line 948 of file sqliteInt.h.

#define SCHEMA_TABLE (   x)    (x?TEMP_MASTER_NAME:MASTER_NAME)

Definition at line 220 of file sqliteInt.h.

#define SQLITE_CountRows   0x00000080 /* Count rows changed by INSERT, */

Definition at line 402 of file sqliteInt.h.

#define SQLITE_FullColNames   0x00000020 /* Show full column names on SELECT */

Definition at line 400 of file sqliteInt.h.

#define SQLITE_Initialized   0x00000002 /* True after initialization */

Definition at line 396 of file sqliteInt.h.

#define SQLITE_InternChanges   0x00000010 /* Uncommitted Hash table changes */

Definition at line 399 of file sqliteInt.h.

#define SQLITE_Interrupt   0x00000004 /* Cancel current operation */

Definition at line 397 of file sqliteInt.h.

#define SQLITE_InTrans   0x00000008 /* True if in a transaction */

Definition at line 398 of file sqliteInt.h.

#define SQLITE_MAGIC_BUSY   0xf03b7906 /* Database currently in use */

Definition at line 417 of file sqliteInt.h.

#define SQLITE_MAGIC_CLOSED   0x9f3c2d33 /* Database is closed */

Definition at line 416 of file sqliteInt.h.

#define SQLITE_MAGIC_ERROR   0xb5357930 /* An SQLITE_MISUSE error occurred */

Definition at line 418 of file sqliteInt.h.

#define SQLITE_MAGIC_OPEN   0xa029a697 /* Database is open */

Definition at line 415 of file sqliteInt.h.

#define SQLITE_NullCallback   0x00000100 /* Invoke the callback once if the */

Definition at line 405 of file sqliteInt.h.

#define SQLITE_ReportTypes   0x00000200 /* Include information on datatypes */

Definition at line 407 of file sqliteInt.h.

#define SQLITE_ShortColNames   0x00000040 /* Show short columns names */

Definition at line 401 of file sqliteInt.h.

#define SQLITE_SO_ASC   0 /* Sort in ascending order */

Definition at line 462 of file sqliteInt.h.

#define SQLITE_SO_DESC   1 /* Sort in descending order */

Definition at line 463 of file sqliteInt.h.

#define SQLITE_SO_DIRMASK   1 /* Mask to extract the sort direction */

Definition at line 464 of file sqliteInt.h.

#define SQLITE_SO_NUM   4 /* Sort using sqliteCompare() */

Definition at line 460 of file sqliteInt.h.

#define SQLITE_SO_TEXT   2 /* Sort using memcmp() */

Definition at line 459 of file sqliteInt.h.

#define SQLITE_SO_TYPEMASK   6 /* Mask to extract the collating sequence */

Definition at line 461 of file sqliteInt.h.

#define SQLITE_SO_UNK   0 /* Use the default collating type. (SCT_NUM) */

Definition at line 458 of file sqliteInt.h.

#define SQLITE_VdbeTrace   0x00000001 /* True to trace VDBE execution */

Definition at line 395 of file sqliteInt.h.

#define sqliteCheckMemory (   a,
 
)

Definition at line 1119 of file sqliteInt.h.

#define sqliteRealloc_ (   X,
 
)    sqliteRealloc(X,Y)

Definition at line 189 of file sqliteInt.h.

#define sqliteStrRealloc (   X)

Definition at line 190 of file sqliteInt.h.

#define SRT_Callback   1 /* Invoke a callback with each row of result */

Definition at line 868 of file sqliteInt.h.

#define SRT_Discard   9 /* Do not save the results anywhere */

Definition at line 875 of file sqliteInt.h.

#define SRT_Except   6 /* Remove result from a UNION table */

Definition at line 872 of file sqliteInt.h.

#define SRT_Mem   2 /* Store result in a memory cell */

Definition at line 869 of file sqliteInt.h.

#define SRT_Set   3 /* Store result as unique keys in a table */

Definition at line 870 of file sqliteInt.h.

#define SRT_Sorter   10 /* Store results in the sorter */

Definition at line 876 of file sqliteInt.h.

#define SRT_Subroutine   11 /* Call a subroutine to handle results */

Definition at line 877 of file sqliteInt.h.

#define SRT_Table   7 /* Store result as data with a unique key */

Definition at line 873 of file sqliteInt.h.

#define SRT_TempTable   8 /* Store result in a trasient table */

Definition at line 874 of file sqliteInt.h.

#define SRT_Union   5 /* Store result as keys in a table */

Definition at line 871 of file sqliteInt.h.

#define TEMP_MASTER_NAME   "sqlite_temp_master"

Definition at line 215 of file sqliteInt.h.

#define TEMP_PAGES   500

Definition at line 31 of file sqliteInt.h.

#define TEMP_STORE   1

Definition at line 77 of file sqliteInt.h.

#define UINT16_TYPE   unsigned short int

Definition at line 103 of file sqliteInt.h.

#define UINT32_TYPE   unsigned int

Definition at line 100 of file sqliteInt.h.

#define UINT8_TYPE   unsigned char

Definition at line 109 of file sqliteInt.h.


Typedef Documentation

typedef struct AggExpr

Definition at line 244 of file sqliteInt.h.

typedef struct AuthContext

Definition at line 251 of file sqliteInt.h.

typedef struct Column

Definition at line 231 of file sqliteInt.h.

typedef struct Db

Definition at line 250 of file sqliteInt.h.

typedef struct DbFixer

Definition at line 1080 of file sqliteInt.h.

typedef struct Expr

Definition at line 235 of file sqliteInt.h.

typedef struct ExprList

Definition at line 236 of file sqliteInt.h.

typedef struct FKey

Definition at line 249 of file sqliteInt.h.

typedef struct FuncDef

Definition at line 245 of file sqliteInt.h.

typedef INT16_TYPE i16

Definition at line 123 of file sqliteInt.h.

typedef UINT8_TYPE i8

Definition at line 125 of file sqliteInt.h.

typedef struct IdList

Definition at line 239 of file sqliteInt.h.

typedef struct Index

Definition at line 233 of file sqliteInt.h.

typedef struct Instruction

Definition at line 234 of file sqliteInt.h.

typedef struct Parse

Definition at line 237 of file sqliteInt.h.

typedef INTPTR_TYPE ptr

Definition at line 126 of file sqliteInt.h.

typedef struct Select

Definition at line 243 of file sqliteInt.h.

typedef struct SrcList

Definition at line 240 of file sqliteInt.h.

typedef struct Table

Definition at line 232 of file sqliteInt.h.

typedef struct Token

Definition at line 238 of file sqliteInt.h.

typedef struct Trigger

Definition at line 246 of file sqliteInt.h.

typedef struct TriggerStack

Definition at line 248 of file sqliteInt.h.

typedef struct TriggerStep

Definition at line 247 of file sqliteInt.h.

typedef UINT16_TYPE u16

Definition at line 122 of file sqliteInt.h.

typedef UINT32_TYPE u32

Definition at line 121 of file sqliteInt.h.

typedef UINT8_TYPE u8

Definition at line 124 of file sqliteInt.h.

typedef unsigned INTPTR_TYPE uptr

Definition at line 127 of file sqliteInt.h.

typedef struct WhereInfo

Definition at line 241 of file sqliteInt.h.

typedef struct WhereLevel

Definition at line 242 of file sqliteInt.h.


Function Documentation

char* sqlite_snprintf ( int  ,
char *  ,
const char *  ,
  ... 
)

Definition at line 774 of file printf.c.

                                                                  {
  char *z;
  va_list ap;

  va_start(ap,zFormat);
  z = base_vprintf(0, 0, zBuf, n, zFormat, ap);
  va_end(ap);
  return z;

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteAddCollateType ( Parse ,
int   
)

Definition at line 751 of file build.c.

                                                      {
  Table *p;
  int i;
  if( (p = pParse->pNewTable)==0 ) return;
  i = p->nCol-1;
  if( i>=0 ) p->aCol[i].sortOrder = collType;
}

Here is the caller graph for this function:

void sqliteAddColumn ( Parse ,
Token  
)

Definition at line 556 of file build.c.

                                                 {
  Table *p;
  int i;
  char *z = 0;
  Column *pCol;
  if( (p = pParse->pNewTable)==0 ) return;
  sqliteSetNString(&z, pName->z, pName->n, 0);
  if( z==0 ) return;
  sqliteDequote(z);
  for(i=0; i<p->nCol; i++){
    if( sqliteStrICmp(z, p->aCol[i].zName)==0 ){
      sqliteErrorMsg(pParse, "duplicate column name: %s", z);
      sqliteFree(z);
      return;
    }
  }
  if( (p->nCol & 0x7)==0 ){
    Column *aNew;
    aNew = sqliteRealloc( p->aCol, (p->nCol+8)*sizeof(p->aCol[0]));
    if( aNew==0 ) return;
    p->aCol = aNew;
  }
  pCol = &p->aCol[p->nCol];
  memset(pCol, 0, sizeof(p->aCol[0]));
  pCol->zName = z;
  pCol->sortOrder = SQLITE_SO_NUM;
  p->nCol++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteAddColumnType ( Parse ,
Token ,
Token  
)

Definition at line 608 of file build.c.

                                                                    {
  Table *p;
  int i, j;
  int n;
  char *z, **pz;
  Column *pCol;
  if( (p = pParse->pNewTable)==0 ) return;
  i = p->nCol-1;
  if( i<0 ) return;
  pCol = &p->aCol[i];
  pz = &pCol->zType;
  n = pLast->n + Addr(pLast->z) - Addr(pFirst->z);
  sqliteSetNString(pz, pFirst->z, n, 0);
  z = *pz;
  if( z==0 ) return;
  for(i=j=0; z[i]; i++){
    int c = z[i];
    if( isspace(c) ) continue;
    z[j++] = c;
  }
  z[j] = 0;
  if( pParse->db->file_format>=4 ){
    pCol->sortOrder = sqliteCollateType(z, n);
  }else{
    pCol->sortOrder = SQLITE_SO_NUM;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteAddDefaultValue ( Parse ,
Token ,
int   
)

Definition at line 644 of file build.c.

                                                                     {
  Table *p;
  int i;
  char **pz;
  if( (p = pParse->pNewTable)==0 ) return;
  i = p->nCol-1;
  if( i<0 ) return;
  pz = &p->aCol[i].zDflt;
  if( minusFlag ){
    sqliteSetNString(pz, "-", 1, pVal->z, pVal->n, 0);
  }else{
    sqliteSetNString(pz, pVal->z, pVal->n, 0);
  }
  sqliteDequote(*pz);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteAddIdxKeyType ( Vdbe ,
Index  
)

Definition at line 1308 of file build.c.

                                              {
  char *zType;
  Table *pTab;
  int i, n;
  assert( pIdx!=0 && pIdx->pTable!=0 );
  pTab = pIdx->pTable;
  n = pIdx->nColumn;
  zType = sqliteMallocRaw( n+1 );
  if( zType==0 ) return;
  for(i=0; i<n; i++){
    int iCol = pIdx->aiColumn[i];
    assert( iCol>=0 && iCol<pTab->nCol );
    if( (pTab->aCol[iCol].sortOrder & SQLITE_SO_TYPEMASK)==SQLITE_SO_TEXT ){
      zType[i] = 't';
    }else{
      zType[i] = 'n';
    }
  }
  zType[n] = 0;
  sqliteVdbeChangeP3(v, -1, zType, n);
  sqliteFree(zType);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteAddKeyType ( Vdbe ,
ExprList  
)

Definition at line 355 of file select.c.

                                                {
  int nColumn = pEList->nExpr;
  char *zType = sqliteMalloc( nColumn+1 );
  int i;
  if( zType==0 ) return;
  for(i=0; i<nColumn; i++){
    zType[i] = sqliteExprType(pEList->a[i].pExpr)==SQLITE_SO_NUM ? 'n' : 't';
  }
  zType[i] = 0;
  sqliteVdbeChangeP3(v, -1, zType, P3_DYNAMIC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteAddNotNull ( Parse ,
int   
)

Definition at line 591 of file build.c.

                                                 {
  Table *p;
  int i;
  if( (p = pParse->pNewTable)==0 ) return;
  i = p->nCol-1;
  if( i>=0 ) p->aCol[i].notNull = onError;
}

Here is the caller graph for this function:

void sqliteAddPrimaryKey ( Parse ,
IdList ,
int   
)

Definition at line 680 of file build.c.

                                                                   {
  Table *pTab = pParse->pNewTable;
  char *zType = 0;
  int iCol = -1, i;
  if( pTab==0 ) goto primary_key_exit;
  if( pTab->hasPrimKey ){
    sqliteErrorMsg(pParse, 
      "table \"%s\" has more than one primary key", pTab->zName);
    goto primary_key_exit;
  }
  pTab->hasPrimKey = 1;
  if( pList==0 ){
    iCol = pTab->nCol - 1;
    pTab->aCol[iCol].isPrimKey = 1;
  }else{
    for(i=0; i<pList->nId; i++){
      for(iCol=0; iCol<pTab->nCol; iCol++){
        if( sqliteStrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ) break;
      }
      if( iCol<pTab->nCol ) pTab->aCol[iCol].isPrimKey = 1;
    }
    if( pList->nId>1 ) iCol = -1;
  }
  if( iCol>=0 && iCol<pTab->nCol ){
    zType = pTab->aCol[iCol].zType;
  }
  if( pParse->db->file_format>=1 && 
           zType && sqliteStrICmp(zType, "INTEGER")==0 ){
    pTab->iPKey = iCol;
    pTab->keyConf = onError;
  }else{
    sqliteCreateIndex(pParse, 0, 0, pList, onError, 0, 0);
    pList = 0;
  }

primary_key_exit:
  sqliteIdListDelete(pList);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double sqliteAtoF ( const char *  z,
const char **   
)

Definition at line 555 of file util.c.

                                                    {
  int sign = 1;
  LONGDOUBLE_TYPE v1 = 0.0;
  if( *z=='-' ){
    sign = -1;
    z++;
  }else if( *z=='+' ){
    z++;
  }
  while( isdigit(*z) ){
    v1 = v1*10.0 + (*z - '0');
    z++;
  }
  if( *z=='.' ){
    LONGDOUBLE_TYPE divisor = 1.0;
    z++;
    while( isdigit(*z) ){
      v1 = v1*10.0 + (*z - '0');
      divisor *= 10.0;
      z++;
    }
    v1 /= divisor;
  }
  if( *z=='e' || *z=='E' ){
    int esign = 1;
    int eval = 0;
    LONGDOUBLE_TYPE scale = 1.0;
    z++;
    if( *z=='-' ){
      esign = -1;
      z++;
    }else if( *z=='+' ){
      z++;
    }
    while( isdigit(*z) ){
      eval = eval*10 + *z - '0';
      z++;
    }
    while( eval>=64 ){ scale *= 1.0e+64; eval -= 64; }
    while( eval>=16 ){ scale *= 1.0e+16; eval -= 16; }
    while( eval>=4 ){ scale *= 1.0e+4; eval -= 4; }
    while( eval>=1 ){ scale *= 1.0e+1; eval -= 1; }
    if( esign<0 ){
      v1 /= scale;
    }else{
      v1 *= scale;
    }
  }
  if( pzEnd ) *pzEnd = z;
  return sign<0 ? -v1 : v1;
}

Here is the caller graph for this function:

void sqliteAttach ( Parse ,
Token ,
Token ,
Token  
)

Definition at line 26 of file attach.c.

                                                                               {
  Db *aNew;
  int rc, i;
  char *zFile, *zName;
  sqlite *db;
  Vdbe *v;

  v = sqliteGetVdbe(pParse);
  sqliteVdbeAddOp(v, OP_Halt, 0, 0);
  if( pParse->explain ) return;
  db = pParse->db;
  if( db->file_format<4 ){
    sqliteErrorMsg(pParse, "cannot attach auxiliary databases to an "
       "older format master database", 0);
    pParse->rc = SQLITE_ERROR;
    return;
  }
  if( db->nDb>=MAX_ATTACHED+2 ){
    sqliteErrorMsg(pParse, "too many attached databases - max %d", 
       MAX_ATTACHED);
    pParse->rc = SQLITE_ERROR;
    return;
  }

  zFile = 0;
  sqliteSetNString(&zFile, pFilename->z, pFilename->n, 0);
  if( zFile==0 ) return;
  sqliteDequote(zFile);
#ifndef SQLITE_OMIT_AUTHORIZATION
  if( sqliteAuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
    sqliteFree(zFile);
    return;
  }
#endif /* SQLITE_OMIT_AUTHORIZATION */

  zName = 0;
  sqliteSetNString(&zName, pDbname->z, pDbname->n, 0);
  if( zName==0 ) return;
  sqliteDequote(zName);
  for(i=0; i<db->nDb; i++){
    if( db->aDb[i].zName && sqliteStrICmp(db->aDb[i].zName, zName)==0 ){
      sqliteErrorMsg(pParse, "database %z is already in use", zName);
      pParse->rc = SQLITE_ERROR;
      sqliteFree(zFile);
      return;
    }
  }

  if( db->aDb==db->aDbStatic ){
    aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
    if( aNew==0 ) 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 ) return;
  }
  db->aDb = aNew;
  aNew = &db->aDb[db->nDb++];
  memset(aNew, 0, sizeof(*aNew));
  sqliteHashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);
  sqliteHashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);
  sqliteHashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
  sqliteHashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
  aNew->zName = zName;
  rc = sqliteBtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
  if( rc ){
    sqliteErrorMsg(pParse, "unable to open database: %s", zFile);
  }
#if SQLITE_HAS_CODEC
  {
    extern int sqliteCodecAttach(sqlite*, int, void*, int);
    char *zKey = 0;
    int nKey;
    if( pKey && pKey->z && pKey->n ){
      sqliteSetNString(&zKey, pKey->z, pKey->n, 0);
      sqliteDequote(zKey);
      nKey = strlen(zKey);
    }else{
      zKey = 0;
      nKey = 0;
    }
    sqliteCodecAttach(db, db->nDb-1, zKey, nKey);
  }
#endif
  sqliteFree(zFile);
  db->flags &= ~SQLITE_Initialized;
  if( pParse->nErr ) return;
  if( rc==SQLITE_OK ){
    rc = sqliteInit(pParse->db, &pParse->zErrMsg);
  }
  if( rc ){
    int i = db->nDb - 1;
    assert( i>=2 );
    if( db->aDb[i].pBt ){
      sqliteBtreeClose(db->aDb[i].pBt);
      db->aDb[i].pBt = 0;
    }
    sqliteResetInternalSchema(db, 0);
    pParse->nErr++;
    pParse->rc = SQLITE_ERROR;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteAuthCheck ( Parse ,
int  ,
const char *  ,
const char *  ,
const char *   
)

Definition at line 167 of file auth.c.

 {
  sqlite *db = pParse->db;
  int rc;

  if( db->init.busy || db->xAuth==0 ){
    return SQLITE_OK;
  }
  rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
  if( rc==SQLITE_DENY ){
    sqliteErrorMsg(pParse, "not authorized");
    pParse->rc = SQLITE_AUTH;
  }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
    rc = SQLITE_DENY;
    sqliteAuthBadReturnCode(pParse, rc);
  }
  return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 212 of file auth.c.

                                                {
  if( pContext->pParse ){
    pContext->pParse->zAuthContext = pContext->zAuthContext;
    pContext->pParse = 0;
  }
}

Here is the caller graph for this function:

void sqliteAuthContextPush ( Parse ,
AuthContext ,
const char *   
)

Definition at line 196 of file auth.c.

 {
  pContext->pParse = pParse;
  if( pParse ){
    pContext->zAuthContext = pParse->zAuthContext;
    pParse->zAuthContext = zContext;
  }
}

Here is the caller graph for this function:

void sqliteAuthRead ( Parse ,
Expr ,
SrcList  
)

Definition at line 103 of file auth.c.

 {
  sqlite *db = pParse->db;
  int rc;
  Table *pTab;          /* The table being read */
  const char *zCol;     /* Name of the column of the table */
  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 */

  if( db->xAuth==0 ) return;
  assert( pExpr->op==TK_COLUMN );
  for(iSrc=0; iSrc<pTabList->nSrc; iSrc++){
    if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
  }
  if( iSrc>=0 && iSrc<pTabList->nSrc ){
    pTab = pTabList->a[iSrc].pTab;
  }else if( (pStack = pParse->trigStack)!=0 ){
    /* This must be an attempt to read the NEW or OLD pseudo-tables
    ** of a trigger.
    */
    assert( pExpr->iTable==pStack->newIdx || pExpr->iTable==pStack->oldIdx );
    pTab = pStack->pTab;
  }else{
    return;
  }
  if( pTab==0 ) return;
  if( pExpr->iColumn>=0 ){
    assert( pExpr->iColumn<pTab->nCol );
    zCol = pTab->aCol[pExpr->iColumn].zName;
  }else if( pTab->iPKey>=0 ){
    assert( pTab->iPKey<pTab->nCol );
    zCol = pTab->aCol[pTab->iPKey].zName;
  }else{
    zCol = "ROWID";
  }
  assert( pExpr->iDb<db->nDb );
  zDBase = db->aDb[pExpr->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 ){
      sqliteErrorMsg(pParse, "access to %s.%s.%s is prohibited", 
         zDBase, pTab->zName, zCol);
    }else{
      sqliteErrorMsg(pParse, "access to %s.%s is prohibited", pTab->zName,zCol);
    }
    pParse->rc = SQLITE_AUTH;
  }else if( rc!=SQLITE_OK ){
    sqliteAuthBadReturnCode(pParse, rc);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteBeginParse ( Parse ,
int   
)

Definition at line 37 of file build.c.

                                                     {
  sqlite *db = pParse->db;
  int i;
  pParse->explain = explainFlag;
  if((db->flags & SQLITE_Initialized)==0 && db->init.busy==0 ){
    int rc = sqliteInit(db, &pParse->zErrMsg);
    if( rc!=SQLITE_OK ){
      pParse->rc = rc;
      pParse->nErr++;
    }
  }
  for(i=0; i<db->nDb; i++){
    DbClearProperty(db, i, DB_Locked);
    if( !db->aDb[i].inTrans ){
      DbClearProperty(db, i, DB_Cookie);
    }
  }
  pParse->nVar = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteBeginTransaction ( Parse ,
int   
)

Definition at line 2019 of file build.c.

                                                       {
  sqlite *db;

  if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return;
  if( pParse->nErr || sqlite_malloc_failed ) return;
  if( sqliteAuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ) return;
  if( db->flags & SQLITE_InTrans ){
    sqliteErrorMsg(pParse, "cannot start a transaction within a transaction");
    return;
  }
  sqliteBeginWriteOperation(pParse, 0, 0);
  if( !pParse->explain ){
    db->flags |= SQLITE_InTrans;
    db->onError = onError;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteBeginTrigger ( Parse ,
Token ,
int  ,
int  ,
IdList ,
SrcList ,
int  ,
Expr ,
int   
)

Definition at line 41 of file trigger.c.

 {
  Trigger *nt;
  Table   *tab;
  char *zName = 0;        /* Name of the trigger */
  sqlite *db = pParse->db;
  int iDb;                /* When database to store the trigger in */
  DbFixer sFix;

  /* Check that: 
  ** 1. the trigger name does not already exist.
  ** 2. the table (or view) does exist in the same database as the trigger.
  ** 3. that we are not trying to create a trigger on the sqlite_master table
  ** 4. That we are not trying to create an INSTEAD OF trigger on a table.
  ** 5. That we are not trying to create a BEFORE or AFTER trigger on a view.
  */
  if( sqlite_malloc_failed ) goto trigger_cleanup;
  assert( pTableName->nSrc==1 );
  if( db->init.busy
   && sqliteFixInit(&sFix, pParse, db->init.iDb, "trigger", pName)
   && sqliteFixSrcList(&sFix, pTableName)
  ){
    goto trigger_cleanup;
  }
  tab = sqliteSrcListLookup(pParse, pTableName);
  if( !tab ){
    goto trigger_cleanup;
  }
  iDb = isTemp ? 1 : tab->iDb;
  if( iDb>=2 && !db->init.busy ){
    sqliteErrorMsg(pParse, "triggers may not be added to auxiliary "
       "database %s", db->aDb[tab->iDb].zName);
    goto trigger_cleanup;
  }

  zName = sqliteStrNDup(pName->z, pName->n);
  sqliteDequote(zName);
  if( sqliteHashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
    sqliteErrorMsg(pParse, "trigger %T already exists", pName);
    goto trigger_cleanup;
  }
  if( sqliteStrNICmp(tab->zName, "sqlite_", 7)==0 ){
    sqliteErrorMsg(pParse, "cannot create trigger on system table");
    pParse->nErr++;
    goto trigger_cleanup;
  }
  if( tab->pSelect && tr_tm != TK_INSTEAD ){
    sqliteErrorMsg(pParse, "cannot create %s trigger on view: %S", 
        (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
    goto trigger_cleanup;
  }
  if( !tab->pSelect && tr_tm == TK_INSTEAD ){
    sqliteErrorMsg(pParse, "cannot create INSTEAD OF"
        " trigger on table: %S", pTableName, 0);
    goto trigger_cleanup;
  }
#ifndef SQLITE_OMIT_AUTHORIZATION
  {
    int code = SQLITE_CREATE_TRIGGER;
    const char *zDb = db->aDb[tab->iDb].zName;
    const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
    if( tab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
    if( sqliteAuthCheck(pParse, code, zName, tab->zName, zDbTrig) ){
      goto trigger_cleanup;
    }
    if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(tab->iDb), 0, zDb)){
      goto trigger_cleanup;
    }
  }
#endif

  /* INSTEAD OF triggers can only appear on views and BEGIN triggers
  ** cannot appear on views.  So we might as well translate every
  ** INSTEAD OF trigger into a BEFORE trigger.  It simplifies code
  ** elsewhere.
  */
  if (tr_tm == TK_INSTEAD){
    tr_tm = TK_BEFORE;
  }

  /* Build the Trigger object */
  nt = (Trigger*)sqliteMalloc(sizeof(Trigger));
  if( nt==0 ) goto trigger_cleanup;
  nt->name = zName;
  zName = 0;
  nt->table = sqliteStrDup(pTableName->a[0].zName);
  if( sqlite_malloc_failed ) goto trigger_cleanup;
  nt->iDb = iDb;
  nt->iTabDb = tab->iDb;
  nt->op = op;
  nt->tr_tm = tr_tm;
  nt->pWhen = sqliteExprDup(pWhen);
  nt->pColumns = sqliteIdListDup(pColumns);
  nt->foreach = foreach;
  sqliteTokenCopy(&nt->nameToken,pName);
  assert( pParse->pNewTrigger==0 );
  pParse->pNewTrigger = nt;

trigger_cleanup:
  sqliteFree(zName);
  sqliteSrcListDelete(pTableName);
  sqliteIdListDelete(pColumns);
  sqliteExprDelete(pWhen);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteBeginWriteOperation ( Parse ,
int  ,
int   
)

Definition at line 2115 of file build.c.

                                                                         {
  Vdbe *v;
  sqlite *db = pParse->db;
  if( DbHasProperty(db, iDb, DB_Locked) ) return;
  v = sqliteGetVdbe(pParse);
  if( v==0 ) return;
  if( !db->aDb[iDb].inTrans ){
    sqliteVdbeAddOp(v, OP_Transaction, iDb, 0);
    DbSetProperty(db, iDb, DB_Locked);
    sqliteCodeVerifySchema(pParse, iDb);
    if( iDb!=1 ){
      sqliteBeginWriteOperation(pParse, setCheckpoint, 1);
    }
  }else if( setCheckpoint ){
    sqliteVdbeAddOp(v, OP_Checkpoint, iDb, 0);
    DbSetProperty(db, iDb, DB_Locked);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteBtreeFactory ( const sqlite db,
const char *  zFilename,
int  mode,
int  nPg,
Btree **  ppBtree 
)

Definition at line 1109 of file main.c.

                  {         /* Pointer to new Btree object written here */

  assert( ppBtree != 0);

#ifndef SQLITE_OMIT_INMEMORYDB
  if( zFilename==0 ){
    if (TEMP_STORE == 0) {
      /* Always use file based temporary DB */
      return sqliteBtreeOpen(0, omitJournal, nCache, ppBtree);
    } else if (TEMP_STORE == 1 || TEMP_STORE == 2) {
      /* Switch depending on compile-time and/or runtime settings. */
      int location = db->temp_store==0 ? TEMP_STORE : db->temp_store;

      if (location == 1) {
        return sqliteBtreeOpen(zFilename, omitJournal, nCache, ppBtree);
      } else {
        return sqliteRbtreeOpen(0, 0, 0, ppBtree);
      }
    } else {
      /* Always use in-core DB */
      return sqliteRbtreeOpen(0, 0, 0, ppBtree);
    }
  }else if( zFilename[0]==':' && strcmp(zFilename,":memory:")==0 ){
    return sqliteRbtreeOpen(0, 0, 0, ppBtree);
  }else
#endif
  {
    return sqliteBtreeOpen(zFilename, omitJournal, nCache, ppBtree);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteChangeCookie ( sqlite ,
Vdbe  
)

Definition at line 776 of file build.c.

                                            {
  if( db->next_cookie==db->aDb[0].schema_cookie ){
    unsigned char r;
    sqliteRandomness(1, &r);
    db->next_cookie = db->aDb[0].schema_cookie + r + 1;
    db->flags |= SQLITE_InternChanges;
    sqliteVdbeAddOp(v, OP_Integer, db->next_cookie, 0);
    sqliteVdbeAddOp(v, OP_SetCookie, 0, 0);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteCodeRowTrigger ( Parse ,
int  ,
ExprList ,
int  ,
Table ,
int  ,
int  ,
int  ,
int   
)

Definition at line 679 of file trigger.c.

 {
  Trigger * pTrigger;
  TriggerStack * pTriggerStack;

  assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
  assert(tr_tm == TK_BEFORE || tr_tm == TK_AFTER );

  assert(newIdx != -1 || oldIdx != -1);

  pTrigger = pTab->pTrigger;
  while( pTrigger ){
    int fire_this = 0;

    /* determine whether we should code this trigger */
    if( pTrigger->op == op && pTrigger->tr_tm == tr_tm && 
        pTrigger->foreach == TK_ROW ){
      fire_this = 1;
      pTriggerStack = pParse->trigStack;
      while( pTriggerStack ){
        if( pTriggerStack->pTrigger == pTrigger ){
         fire_this = 0;
       }
        pTriggerStack = pTriggerStack->pNext;
      }
      if( op == TK_UPDATE && pTrigger->pColumns &&
          !checkColumnOverLap(pTrigger->pColumns, pChanges) ){
        fire_this = 0;
      }
    }

    if( fire_this && (pTriggerStack = sqliteMalloc(sizeof(TriggerStack)))!=0 ){
      int endTrigger;
      SrcList dummyTablist;
      Expr * whenExpr;
      AuthContext sContext;

      dummyTablist.nSrc = 0;

      /* Push an entry on to the trigger stack */
      pTriggerStack->pTrigger = pTrigger;
      pTriggerStack->newIdx = newIdx;
      pTriggerStack->oldIdx = oldIdx;
      pTriggerStack->pTab = pTab;
      pTriggerStack->pNext = pParse->trigStack;
      pTriggerStack->ignoreJump = ignoreJump;
      pParse->trigStack = pTriggerStack;
      sqliteAuthContextPush(pParse, &sContext, pTrigger->name);

      /* code the WHEN clause */
      endTrigger = sqliteVdbeMakeLabel(pParse->pVdbe);
      whenExpr = sqliteExprDup(pTrigger->pWhen);
      if( sqliteExprResolveIds(pParse, &dummyTablist, 0, whenExpr) ){
        pParse->trigStack = pParse->trigStack->pNext;
        sqliteFree(pTriggerStack);
        sqliteExprDelete(whenExpr);
        return 1;
      }
      sqliteExprIfFalse(pParse, whenExpr, endTrigger, 1);
      sqliteExprDelete(whenExpr);

      sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPush, 0, 0);
      codeTriggerProgram(pParse, pTrigger->step_list, orconf); 
      sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPop, 0, 0);

      /* Pop the entry off the trigger stack */
      pParse->trigStack = pParse->trigStack->pNext;
      sqliteAuthContextPop(&sContext);
      sqliteFree(pTriggerStack);

      sqliteVdbeResolveLabel(pParse->pVdbe, endTrigger);
    }
    pTrigger = pTrigger->pNext;
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteCodeVerifySchema ( Parse ,
int   
)

Definition at line 2086 of file build.c.

                                                   {
  sqlite *db = pParse->db;
  Vdbe *v = sqliteGetVdbe(pParse);
  assert( iDb>=0 && iDb<db->nDb );
  assert( db->aDb[iDb].pBt!=0 );
  if( iDb!=1 && !DbHasProperty(db, iDb, DB_Cookie) ){
    sqliteVdbeAddOp(v, OP_VerifyCookie, iDb, db->aDb[iDb].schema_cookie);
    DbSetProperty(db, iDb, DB_Cookie);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteCollateType ( const char *  ,
int   
)

Definition at line 728 of file build.c.

                                                   {
  int i;
  for(i=0; i<nType-3; i++){
    int c = *(zType++) | 0x60;
    if( (c=='b' || c=='c') && sqliteStrNICmp(zType, "lob", 3)==0 ){
      return SQLITE_SO_TEXT;
    }
    if( c=='c' && sqliteStrNICmp(zType, "har", 3)==0 ){
      return SQLITE_SO_TEXT;
    }
    if( c=='t' && sqliteStrNICmp(zType, "ext", 3)==0 ){
      return SQLITE_SO_TEXT;
    }
  }
  return SQLITE_SO_NUM;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 298 of file build.c.

                                            {
  db->aDb[0].schema_cookie = db->next_cookie;
  db->flags &= ~SQLITE_InternChanges;
}

Here is the caller graph for this function:

Definition at line 2039 of file build.c.

                                           {
  sqlite *db;

  if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return;
  if( pParse->nErr || sqlite_malloc_failed ) return;
  if( sqliteAuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ) return;
  if( (db->flags & SQLITE_InTrans)==0 ){
    sqliteErrorMsg(pParse, "cannot commit - no transaction is active");
    return;
  }
  if( !pParse->explain ){
    db->flags &= ~SQLITE_InTrans;
  }
  sqliteEndWriteOperation(pParse);
  if( !pParse->explain ){
    db->onError = OE_Default;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteCompare ( const char *  ,
const char *   
)

Definition at line 638 of file util.c.

                                                       {
  int result;
  int isNumA, isNumB;
  if( atext==0 ){
    return -1;
  }else if( btext==0 ){
    return 1;
  }
  isNumA = sqliteIsNumber(atext);
  isNumB = sqliteIsNumber(btext);
  if( isNumA ){
    if( !isNumB ){
      result = -1;
    }else{
      double rA, rB;
      rA = sqliteAtoF(atext, 0);
      rB = sqliteAtoF(btext, 0);
      if( rA<rB ){
        result = -1;
      }else if( rA>rB ){
        result = +1;
      }else{
        result = 0;
      }
    }
  }else if( isNumB ){
    result = +1;
  }else {
    result = strcmp(atext, btext);
  }
  return result; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteCompleteInsertion ( Parse ,
Table ,
int  ,
char *  ,
int  ,
int  ,
int   
)

Definition at line 863 of file insert.c.

 {
  int i;
  Vdbe *v;
  int nIdx;
  Index *pIdx;

  v = sqliteGetVdbe(pParse);
  assert( v!=0 );
  assert( pTab->pSelect==0 );  /* This table is not a VIEW */
  for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
  for(i=nIdx-1; i>=0; i--){
    if( aIdxUsed && aIdxUsed[i]==0 ) continue;
    sqliteVdbeAddOp(v, OP_IdxPut, base+i+1, 0);
  }
  sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
  if( newIdx>=0 ){
    sqliteVdbeAddOp(v, OP_Dup, 1, 0);
    sqliteVdbeAddOp(v, OP_Dup, 1, 0);
    sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
  }
  sqliteVdbeAddOp(v, OP_PutIntKey, base,
    (pParse->trigStack?0:OPFLAG_NCHANGE) |
    (isUpdate?0:OPFLAG_LASTROWID) | OPFLAG_CSCHANGE);
  if( isUpdate && recnoChng ){
    sqliteVdbeAddOp(v, OP_Pop, 1, 0);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteCopy ( Parse ,
SrcList ,
Token ,
Token ,
int   
)

Definition at line 29 of file copy.c.

 {
  Table *pTab;
  int i;
  Vdbe *v;
  int addr, end;
  char *zFile = 0;
  const char *zDb;
  sqlite *db = pParse->db;


  if( sqlite_malloc_failed  ) goto copy_cleanup;
  assert( pTableName->nSrc==1 );
  pTab = sqliteSrcListLookup(pParse, pTableName);
  if( pTab==0 || sqliteIsReadOnly(pParse, pTab, 0) ) goto copy_cleanup;
  zFile = sqliteStrNDup(pFilename->z, pFilename->n);
  sqliteDequote(zFile);
  assert( pTab->iDb<db->nDb );
  zDb = db->aDb[pTab->iDb].zName;
  if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb)
      || sqliteAuthCheck(pParse, SQLITE_COPY, pTab->zName, zFile, zDb) ){
    goto copy_cleanup;
  }
  v = sqliteGetVdbe(pParse);
  if( v ){
    sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
    addr = sqliteVdbeOp3(v, OP_FileOpen, 0, 0, pFilename->z, pFilename->n);
    sqliteVdbeDequoteP3(v, addr);
    sqliteOpenTableAndIndices(pParse, pTab, 0);
    if( db->flags & SQLITE_CountRows ){
      sqliteVdbeAddOp(v, OP_Integer, 0, 0);  /* Initialize the row count */
    }
    end = sqliteVdbeMakeLabel(v);
    addr = sqliteVdbeAddOp(v, OP_FileRead, pTab->nCol, end);
    if( pDelimiter ){
      sqliteVdbeChangeP3(v, addr, pDelimiter->z, pDelimiter->n);
      sqliteVdbeDequoteP3(v, addr);
    }else{
      sqliteVdbeChangeP3(v, addr, "\t", 1);
    }
    if( pTab->iPKey>=0 ){
      sqliteVdbeAddOp(v, OP_FileColumn, pTab->iPKey, 0);
      sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
    }else{
      sqliteVdbeAddOp(v, OP_NewRecno, 0, 0);
    }
    for(i=0; i<pTab->nCol; i++){
      if( i==pTab->iPKey ){
        /* The integer primary key column is filled with NULL since its
        ** value is always pulled from the record number */
        sqliteVdbeAddOp(v, OP_String, 0, 0);
      }else{
        sqliteVdbeAddOp(v, OP_FileColumn, i, 0);
      }
    }
    sqliteGenerateConstraintChecks(pParse, pTab, 0, 0, pTab->iPKey>=0, 
                                   0, onError, addr);
    sqliteCompleteInsertion(pParse, pTab, 0, 0, 0, 0, -1);
    if( (db->flags & SQLITE_CountRows)!=0 ){
      sqliteVdbeAddOp(v, OP_AddImm, 1, 0);  /* Increment row count */
    }
    sqliteVdbeAddOp(v, OP_Goto, 0, addr);
    sqliteVdbeResolveLabel(v, end);
    sqliteVdbeAddOp(v, OP_Noop, 0, 0);
    sqliteEndWriteOperation(pParse);
    if( db->flags & SQLITE_CountRows ){
      sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
      sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
      sqliteVdbeAddOp(v, OP_Callback, 1, 0);
    }
  }
  
copy_cleanup:
  sqliteSrcListDelete(pTableName);
  sqliteFree(zFile);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteCreateForeignKey ( Parse ,
IdList ,
Token ,
IdList ,
int   
)

Definition at line 1349 of file build.c.

 {
  Table *p = pParse->pNewTable;
  int nByte;
  int i;
  int nCol;
  char *z;
  FKey *pFKey = 0;

  assert( pTo!=0 );
  if( p==0 || pParse->nErr ) goto fk_end;
  if( pFromCol==0 ){
    int iCol = p->nCol-1;
    if( iCol<0 ) goto fk_end;
    if( pToCol && pToCol->nId!=1 ){
      sqliteErrorMsg(pParse, "foreign key on %s"
         " should reference only one column of table %T",
         p->aCol[iCol].zName, pTo);
      goto fk_end;
    }
    nCol = 1;
  }else if( pToCol && pToCol->nId!=pFromCol->nId ){
    sqliteErrorMsg(pParse,
        "number of columns in foreign key does not match the number of "
        "columns in the referenced table");
    goto fk_end;
  }else{
    nCol = pFromCol->nId;
  }
  nByte = sizeof(*pFKey) + nCol*sizeof(pFKey->aCol[0]) + pTo->n + 1;
  if( pToCol ){
    for(i=0; i<pToCol->nId; i++){
      nByte += strlen(pToCol->a[i].zName) + 1;
    }
  }
  pFKey = sqliteMalloc( nByte );
  if( pFKey==0 ) goto fk_end;
  pFKey->pFrom = p;
  pFKey->pNextFrom = p->pFKey;
  z = (char*)&pFKey[1];
  pFKey->aCol = (struct sColMap*)z;
  z += sizeof(struct sColMap)*nCol;
  pFKey->zTo = z;
  memcpy(z, pTo->z, pTo->n);
  z[pTo->n] = 0;
  z += pTo->n+1;
  pFKey->pNextTo = 0;
  pFKey->nCol = nCol;
  if( pFromCol==0 ){
    pFKey->aCol[0].iFrom = p->nCol-1;
  }else{
    for(i=0; i<nCol; i++){
      int j;
      for(j=0; j<p->nCol; j++){
        if( sqliteStrICmp(p->aCol[j].zName, pFromCol->a[i].zName)==0 ){
          pFKey->aCol[i].iFrom = j;
          break;
        }
      }
      if( j>=p->nCol ){
        sqliteErrorMsg(pParse, 
          "unknown column \"%s\" in foreign key definition", 
          pFromCol->a[i].zName);
        goto fk_end;
      }
    }
  }
  if( pToCol ){
    for(i=0; i<nCol; i++){
      int n = strlen(pToCol->a[i].zName);
      pFKey->aCol[i].zCol = z;
      memcpy(z, pToCol->a[i].zName, n);
      z[n] = 0;
      z += n+1;
    }
  }
  pFKey->isDeferred = 0;
  pFKey->deleteConf = flags & 0xff;
  pFKey->updateConf = (flags >> 8 ) & 0xff;
  pFKey->insertConf = (flags >> 16 ) & 0xff;

  /* Link the foreign key to the table as the last step.
  */
  p->pFKey = pFKey;
  pFKey = 0;

fk_end:
  sqliteFree(pFKey);
  sqliteIdListDelete(pFromCol);
  sqliteIdListDelete(pToCol);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteCreateIndex ( Parse ,
Token ,
SrcList ,
IdList ,
int  ,
Token ,
Token  
)

Definition at line 1472 of file build.c.

 {
  Table *pTab;     /* Table to be indexed */
  Index *pIndex;   /* The index to be created */
  char *zName = 0;
  int i, j;
  Token nullId;    /* Fake token for an empty ID list */
  DbFixer sFix;    /* For assigning database names to pTable */
  int isTemp;      /* True for a temporary index */
  sqlite *db = pParse->db;

  if( pParse->nErr || sqlite_malloc_failed ) goto exit_create_index;
  if( db->init.busy 
     && sqliteFixInit(&sFix, pParse, db->init.iDb, "index", pName)
     && sqliteFixSrcList(&sFix, pTable)
  ){
    goto exit_create_index;
  }

  /*
  ** Find the table that is to be indexed.  Return early if not found.
  */
  if( pTable!=0 ){
    assert( pName!=0 );
    assert( pTable->nSrc==1 );
    pTab =  sqliteSrcListLookup(pParse, pTable);
  }else{
    assert( pName==0 );
    pTab =  pParse->pNewTable;
  }
  if( pTab==0 || pParse->nErr ) goto exit_create_index;
  if( pTab->readOnly ){
    sqliteErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
    goto exit_create_index;
  }
  if( pTab->iDb>=2 && db->init.busy==0 ){
    sqliteErrorMsg(pParse, "table %s may not have indices added", pTab->zName);
    goto exit_create_index;
  }
  if( pTab->pSelect ){
    sqliteErrorMsg(pParse, "views may not be indexed");
    goto exit_create_index;
  }
  isTemp = pTab->iDb==1;

  /*
  ** Find the name of the index.  Make sure there is not already another
  ** index or table with the same name.  
  **
  ** Exception:  If we are reading the names of permanent indices from the
  ** sqlite_master table (because some other process changed the schema) and
  ** one of the index names collides with the name of a temporary table or
  ** index, then we will continue to process this index.
  **
  ** If pName==0 it means that we are
  ** dealing with a primary key or UNIQUE constraint.  We have to invent our
  ** own name.
  */
  if( pName && !db->init.busy ){
    Index *pISameName;    /* Another index with the same name */
    Table *pTSameName;    /* A table with same name as the index */
    zName = sqliteTableNameFromToken(pName);
    if( zName==0 ) goto exit_create_index;
    if( (pISameName = sqliteFindIndex(db, zName, 0))!=0 ){
      sqliteErrorMsg(pParse, "index %s already exists", zName);
      goto exit_create_index;
    }
    if( (pTSameName = sqliteFindTable(db, zName, 0))!=0 ){
      sqliteErrorMsg(pParse, "there is already a table named %s", zName);
      goto exit_create_index;
    }
  }else if( pName==0 ){
    char zBuf[30];
    int n;
    Index *pLoop;
    for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){}
    sprintf(zBuf,"%d)",n);
    zName = 0;
    sqliteSetString(&zName, "(", pTab->zName, " autoindex ", zBuf, (char*)0);
    if( zName==0 ) goto exit_create_index;
  }else{
    zName = sqliteTableNameFromToken(pName);
  }

  /* Check for authorization to create an index.
  */
#ifndef SQLITE_OMIT_AUTHORIZATION
  {
    const char *zDb = db->aDb[pTab->iDb].zName;

    assert( pTab->iDb==db->init.iDb || isTemp );
    if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
      goto exit_create_index;
    }
    i = SQLITE_CREATE_INDEX;
    if( isTemp ) i = SQLITE_CREATE_TEMP_INDEX;
    if( sqliteAuthCheck(pParse, i, zName, pTab->zName, zDb) ){
      goto exit_create_index;
    }
  }
#endif

  /* If pList==0, it means this routine was called to make a primary
  ** key out of the last column added to the table under construction.
  ** So create a fake list to simulate this.
  */
  if( pList==0 ){
    nullId.z = pTab->aCol[pTab->nCol-1].zName;
    nullId.n = strlen(nullId.z);
    pList = sqliteIdListAppend(0, &nullId);
    if( pList==0 ) goto exit_create_index;
  }

  /* 
  ** Allocate the index structure. 
  */
  pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 +
                        sizeof(int)*pList->nId );
  if( pIndex==0 ) goto exit_create_index;
  pIndex->aiColumn = (int*)&pIndex[1];
  pIndex->zName = (char*)&pIndex->aiColumn[pList->nId];
  strcpy(pIndex->zName, zName);
  pIndex->pTable = pTab;
  pIndex->nColumn = pList->nId;
  pIndex->onError = onError;
  pIndex->autoIndex = pName==0;
  pIndex->iDb = isTemp ? 1 : db->init.iDb;

  /* Scan the names of the columns of the table to be indexed and
  ** load the column indices into the Index structure.  Report an error
  ** if any column is not found.
  */
  for(i=0; i<pList->nId; i++){
    for(j=0; j<pTab->nCol; j++){
      if( sqliteStrICmp(pList->a[i].zName, pTab->aCol[j].zName)==0 ) break;
    }
    if( j>=pTab->nCol ){
      sqliteErrorMsg(pParse, "table %s has no column named %s",
        pTab->zName, pList->a[i].zName);
      sqliteFree(pIndex);
      goto exit_create_index;
    }
    pIndex->aiColumn[i] = j;
  }

  /* Link the new Index structure to its table and to the other
  ** in-memory database structures. 
  */
  if( !pParse->explain ){
    Index *p;
    p = sqliteHashInsert(&db->aDb[pIndex->iDb].idxHash, 
                         pIndex->zName, strlen(pIndex->zName)+1, pIndex);
    if( p ){
      assert( p==pIndex );  /* Malloc must have failed */
      sqliteFree(pIndex);
      goto exit_create_index;
    }
    db->flags |= SQLITE_InternChanges;
  }

  /* When adding an index to the list of indices for a table, make
  ** sure all indices labeled OE_Replace come after all those labeled
  ** OE_Ignore.  This is necessary for the correct operation of UPDATE
  ** and INSERT.
  */
  if( onError!=OE_Replace || pTab->pIndex==0
       || pTab->pIndex->onError==OE_Replace){
    pIndex->pNext = pTab->pIndex;
    pTab->pIndex = pIndex;
  }else{
    Index *pOther = pTab->pIndex;
    while( pOther->pNext && pOther->pNext->onError!=OE_Replace ){
      pOther = pOther->pNext;
    }
    pIndex->pNext = pOther->pNext;
    pOther->pNext = pIndex;
  }

  /* If the db->init.busy is 1 it means we are reading the SQL off the
  ** "sqlite_master" table on the disk.  So do not write to the disk
  ** again.  Extract the table number from the db->init.newTnum field.
  */
  if( db->init.busy && pTable!=0 ){
    pIndex->tnum = db->init.newTnum;
  }

  /* If the db->init.busy is 0 then create the index on disk.  This
  ** involves writing the index into the master table and filling in the
  ** index with the current table contents.
  **
  ** The db->init.busy is 0 when the user first enters a CREATE INDEX 
  ** command.  db->init.busy is 1 when a database is opened and 
  ** CREATE INDEX statements are read out of the master table.  In
  ** the latter case the index already exists on disk, which is why
  ** we don't want to recreate it.
  **
  ** If pTable==0 it means this index is generated as a primary key
  ** or UNIQUE constraint of a CREATE TABLE statement.  Since the table
  ** has just been created, it contains no data and the index initialization
  ** step can be skipped.
  */
  else if( db->init.busy==0 ){
    int n;
    Vdbe *v;
    int lbl1, lbl2;
    int i;
    int addr;

    v = sqliteGetVdbe(pParse);
    if( v==0 ) goto exit_create_index;
    if( pTable!=0 ){
      sqliteBeginWriteOperation(pParse, 0, isTemp);
      sqliteOpenMasterTable(v, isTemp);
    }
    sqliteVdbeAddOp(v, OP_NewRecno, 0, 0);
    sqliteVdbeOp3(v, OP_String, 0, 0, "index", P3_STATIC);
    sqliteVdbeOp3(v, OP_String, 0, 0, pIndex->zName, 0);
    sqliteVdbeOp3(v, OP_String, 0, 0, pTab->zName, 0);
    sqliteVdbeOp3(v, OP_CreateIndex, 0, isTemp,(char*)&pIndex->tnum,P3_POINTER);
    pIndex->tnum = 0;
    if( pTable ){
      sqliteVdbeCode(v,
          OP_Dup,       0,      0,
          OP_Integer,   isTemp, 0,
          OP_OpenWrite, 1,      0,
      0);
    }
    addr = sqliteVdbeAddOp(v, OP_String, 0, 0);
    if( pStart && pEnd ){
      n = Addr(pEnd->z) - Addr(pStart->z) + 1;
      sqliteVdbeChangeP3(v, addr, pStart->z, n);
    }
    sqliteVdbeAddOp(v, OP_MakeRecord, 5, 0);
    sqliteVdbeAddOp(v, OP_PutIntKey, 0, 0);
    if( pTable ){
      sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
      sqliteVdbeOp3(v, OP_OpenRead, 2, pTab->tnum, pTab->zName, 0);
      lbl2 = sqliteVdbeMakeLabel(v);
      sqliteVdbeAddOp(v, OP_Rewind, 2, lbl2);
      lbl1 = sqliteVdbeAddOp(v, OP_Recno, 2, 0);
      for(i=0; i<pIndex->nColumn; i++){
        int iCol = pIndex->aiColumn[i];
        if( pTab->iPKey==iCol ){
          sqliteVdbeAddOp(v, OP_Dup, i, 0);
        }else{
          sqliteVdbeAddOp(v, OP_Column, 2, iCol);
        }
      }
      sqliteVdbeAddOp(v, OP_MakeIdxKey, pIndex->nColumn, 0);
      if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIndex);
      sqliteVdbeOp3(v, OP_IdxPut, 1, pIndex->onError!=OE_None,
                      "indexed columns are not unique", P3_STATIC);
      sqliteVdbeAddOp(v, OP_Next, 2, lbl1);
      sqliteVdbeResolveLabel(v, lbl2);
      sqliteVdbeAddOp(v, OP_Close, 2, 0);
      sqliteVdbeAddOp(v, OP_Close, 1, 0);
    }
    if( pTable!=0 ){
      if( !isTemp ){
        sqliteChangeCookie(db, v);
      }
      sqliteVdbeAddOp(v, OP_Close, 0, 0);
      sqliteEndWriteOperation(pParse);
    }
  }

  /* Clean up before exiting */
exit_create_index:
  sqliteIdListDelete(pList);
  sqliteSrcListDelete(pTable);
  sqliteFree(zName);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteCreateView ( Parse ,
Token ,
Token ,
Select ,
int   
)

Definition at line 992 of file build.c.

 {
  Table *p;
  int n;
  const char *z;
  Token sEnd;
  DbFixer sFix;

  sqliteStartTable(pParse, pBegin, pName, isTemp, 1);
  p = pParse->pNewTable;
  if( p==0 || pParse->nErr ){
    sqliteSelectDelete(pSelect);
    return;
  }
  if( sqliteFixInit(&sFix, pParse, p->iDb, "view", pName)
    && sqliteFixSelect(&sFix, pSelect)
  ){
    sqliteSelectDelete(pSelect);
    return;
  }

  /* Make a copy of the entire SELECT statement that defines the view.
  ** This will force all the Expr.token.z values to be dynamically
  ** allocated rather than point to the input string - which means that
  ** they will persist after the current sqlite_exec() call returns.
  */
  p->pSelect = sqliteSelectDup(pSelect);
  sqliteSelectDelete(pSelect);
  if( !pParse->db->init.busy ){
    sqliteViewGetColumnNames(pParse, p);
  }

  /* Locate the end of the CREATE VIEW statement.  Make sEnd point to
  ** the end.
  */
  sEnd = pParse->sLastToken;
  if( sEnd.z[0]!=0 && sEnd.z[0]!=';' ){
    sEnd.z += sEnd.n;
  }
  sEnd.n = 0;
  n = sEnd.z - pBegin->z;
  z = pBegin->z;
  while( n>0 && (z[n-1]==';' || isspace(z[n-1])) ){ n--; }
  sEnd.z = &z[n-1];
  sEnd.n = 1;

  /* Use sqliteEndTable() to add the view to the SQLITE_MASTER table */
  sqliteEndTable(pParse, &sEnd, 0);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteDeferForeignKey ( Parse ,
int   
)

Definition at line 1453 of file build.c.

                                                         {
  Table *pTab;
  FKey *pFKey;
  if( (pTab = pParse->pNewTable)==0 || (pFKey = pTab->pFKey)==0 ) return;
  pFKey->isDeferred = isDeferred;
}

Here is the caller graph for this function:

void sqliteDeleteFrom ( Parse ,
SrcList ,
Expr  
)

Definition at line 56 of file delete.c.

 {
  Vdbe *v;               /* The virtual database engine */
  Table *pTab;           /* The table from which records will be deleted */
  const char *zDb;       /* Name of database holding pTab */
  int end, addr;         /* A couple addresses of generated code */
  int i;                 /* Loop counter */
  WhereInfo *pWInfo;     /* Information about the WHERE clause */
  Index *pIdx;           /* For looping over indices of the table */
  int iCur;              /* VDBE Cursor number for pTab */
  sqlite *db;            /* Main database structure */
  int isView;            /* True if attempting to delete from a view */
  AuthContext sContext;  /* Authorization context */

  int row_triggers_exist = 0;  /* True if any triggers exist */
  int before_triggers;         /* True if there are BEFORE triggers */
  int after_triggers;          /* True if there are AFTER triggers */
  int oldIdx = -1;             /* Cursor for the OLD table of AFTER triggers */

  sContext.pParse = 0;
  if( pParse->nErr || sqlite_malloc_failed ){
    pTabList = 0;
    goto delete_from_cleanup;
  }
  db = pParse->db;
  assert( pTabList->nSrc==1 );

  /* Locate the table which we want to delete.  This table has to be
  ** put in an SrcList structure because some of the subroutines we
  ** will be calling are designed to work with multiple tables and expect
  ** an SrcList* parameter instead of just a Table* parameter.
  */
  pTab = sqliteSrcListLookup(pParse, pTabList);
  if( pTab==0 )  goto delete_from_cleanup;
  before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, 
                         TK_DELETE, TK_BEFORE, TK_ROW, 0);
  after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, 
                         TK_DELETE, TK_AFTER, TK_ROW, 0);
  row_triggers_exist = before_triggers || after_triggers;
  isView = pTab->pSelect!=0;
  if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
    goto delete_from_cleanup;
  }
  assert( pTab->iDb<db->nDb );
  zDb = db->aDb[pTab->iDb].zName;
  if( sqliteAuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
    goto delete_from_cleanup;
  }

  /* If pTab is really a view, make sure it has been initialized.
  */
  if( isView && sqliteViewGetColumnNames(pParse, pTab) ){
    goto delete_from_cleanup;
  }

  /* Allocate a cursor used to store the old.* data for a trigger.
  */
  if( row_triggers_exist ){ 
    oldIdx = pParse->nTab++;
  }

  /* Resolve the column names in all the expressions.
  */
  assert( pTabList->nSrc==1 );
  iCur = pTabList->a[0].iCursor = pParse->nTab++;
  if( pWhere ){
    if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
      goto delete_from_cleanup;
    }
    if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
      goto delete_from_cleanup;
    }
  }

  /* Start the view context
  */
  if( isView ){
    sqliteAuthContextPush(pParse, &sContext, pTab->zName);
  }

  /* Begin generating code.
  */
  v = sqliteGetVdbe(pParse);
  if( v==0 ){
    goto delete_from_cleanup;
  }
  sqliteBeginWriteOperation(pParse, row_triggers_exist, pTab->iDb);

  /* If we are trying to delete from a view, construct that view into
  ** a temporary table.
  */
  if( isView ){
    Select *pView = sqliteSelectDup(pTab->pSelect);
    sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
    sqliteSelectDelete(pView);
  }

  /* Initialize the counter of the number of rows deleted, if
  ** we are counting rows.
  */
  if( db->flags & SQLITE_CountRows ){
    sqliteVdbeAddOp(v, OP_Integer, 0, 0);
  }

  /* Special case: A DELETE without a WHERE clause deletes everything.
  ** It is easier just to erase the whole table.  Note, however, that
  ** this means that the row change count will be incorrect.
  */
  if( pWhere==0 && !row_triggers_exist ){
    if( db->flags & SQLITE_CountRows ){
      /* If counting rows deleted, just count the total number of
      ** entries in the table. */
      int endOfLoop = sqliteVdbeMakeLabel(v);
      int addr;
      if( !isView ){
        sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
        sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
      }
      sqliteVdbeAddOp(v, OP_Rewind, iCur, sqliteVdbeCurrentAddr(v)+2);
      addr = sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
      sqliteVdbeAddOp(v, OP_Next, iCur, addr);
      sqliteVdbeResolveLabel(v, endOfLoop);
      sqliteVdbeAddOp(v, OP_Close, iCur, 0);
    }
    if( !isView ){
      sqliteVdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
      for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
        sqliteVdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
      }
    }
  }

  /* The usual case: There is a WHERE clause so we have to scan through
  ** the table and pick which records to delete.
  */
  else{
    /* Begin the database scan
    */
    pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1, 0);
    if( pWInfo==0 ) goto delete_from_cleanup;

    /* Remember the key of every item to be deleted.
    */
    sqliteVdbeAddOp(v, OP_ListWrite, 0, 0);
    if( db->flags & SQLITE_CountRows ){
      sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
    }

    /* End the database scan loop.
    */
    sqliteWhereEnd(pWInfo);

    /* Open the pseudo-table used to store OLD if there are triggers.
    */
    if( row_triggers_exist ){
      sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
    }

    /* Delete every item whose key was written to the list during the
    ** database scan.  We have to delete items after the scan is complete
    ** because deleting an item can change the scan order.
    */
    sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
    end = sqliteVdbeMakeLabel(v);

    /* This is the beginning of the delete loop when there are
    ** row triggers.
    */
    if( row_triggers_exist ){
      addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
      sqliteVdbeAddOp(v, OP_Dup, 0, 0);
      if( !isView ){
        sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
        sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
      }
      sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);

      sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
      sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
      sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
      if( !isView ){
        sqliteVdbeAddOp(v, OP_Close, iCur, 0);
      }

      sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1, 
          oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
         addr);
    }

    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
      ** before the trigger fires.  If there are no row triggers, the
      ** cursors are opened only once on the outside the loop.
      */
      pParse->nTab = iCur + 1;
      sqliteOpenTableAndIndices(pParse, pTab, iCur);

      /* This is the beginning of the delete loop when there are no
      ** row triggers */
      if( !row_triggers_exist ){ 
        addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
      }

      /* Delete the row */
      sqliteGenerateRowDelete(db, v, pTab, iCur, pParse->trigStack==0);
    }

    /* If there are row triggers, close all cursors then invoke
    ** the AFTER triggers
    */
    if( row_triggers_exist ){
      if( !isView ){
        for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
          sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
        }
        sqliteVdbeAddOp(v, OP_Close, iCur, 0);
      }
      sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1, 
          oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
         addr);
    }

    /* End of the delete loop */
    sqliteVdbeAddOp(v, OP_Goto, 0, addr);
    sqliteVdbeResolveLabel(v, end);
    sqliteVdbeAddOp(v, OP_ListReset, 0, 0);

    /* Close the cursors after the loop if there are no row triggers */
    if( !row_triggers_exist ){
      for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
        sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
      }
      sqliteVdbeAddOp(v, OP_Close, iCur, 0);
      pParse->nTab = iCur;
    }
  }
  sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
  sqliteEndWriteOperation(pParse);

  /*
  ** Return the number of rows that were deleted.
  */
  if( db->flags & SQLITE_CountRows ){
    sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
    sqliteVdbeChangeP3(v, -1, "rows deleted", P3_STATIC);
    sqliteVdbeAddOp(v, OP_Callback, 1, 0);
  }

delete_from_cleanup:
  sqliteAuthContextPop(&sContext);
  sqliteSrcListDelete(pTabList);
  sqliteExprDelete(pWhere);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteDeleteTable ( sqlite ,
Table  
)

Definition at line 318 of file build.c.

                                                 {
  int i;
  Index *pIndex, *pNext;
  FKey *pFKey, *pNextFKey;

  if( pTable==0 ) return;

  /* Delete all indices associated with this table
  */
  for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
    pNext = pIndex->pNext;
    assert( pIndex->iDb==pTable->iDb || (pTable->iDb==0 && pIndex->iDb==1) );
    sqliteDeleteIndex(db, pIndex);
  }

  /* Delete all foreign keys associated with this table.  The keys
  ** should have already been unlinked from the db->aFKey hash table 
  */
  for(pFKey=pTable->pFKey; pFKey; pFKey=pNextFKey){
    pNextFKey = pFKey->pNextFrom;
    assert( pTable->iDb<db->nDb );
    assert( sqliteHashFind(&db->aDb[pTable->iDb].aFKey,
                           pFKey->zTo, strlen(pFKey->zTo)+1)!=pFKey );
    sqliteFree(pFKey);
  }

  /* Delete the Table structure itself.
  */
  for(i=0; i<pTable->nCol; i++){
    sqliteFree(pTable->aCol[i].zName);
    sqliteFree(pTable->aCol[i].zDflt);
    sqliteFree(pTable->aCol[i].zType);
  }
  sqliteFree(pTable->zName);
  sqliteFree(pTable->aCol);
  sqliteSelectDelete(pTable->pSelect);
  sqliteFree(pTable);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 364 of file trigger.c.

                                           {
  if( pTrigger==0 ) return;
  sqliteDeleteTriggerStep(pTrigger->step_list);
  sqliteFree(pTrigger->name);
  sqliteFree(pTrigger->table);
  sqliteExprDelete(pTrigger->pWhen);
  sqliteIdListDelete(pTrigger->pColumns);
  if( pTrigger->nameToken.dyn ) sqliteFree((char*)pTrigger->nameToken.z);
  sqliteFree(pTrigger);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 18 of file trigger.c.

                                                       {
  while( pTriggerStep ){
    TriggerStep * pTmp = pTriggerStep;
    pTriggerStep = pTriggerStep->pNext;

    if( pTmp->target.dyn ) sqliteFree((char*)pTmp->target.z);
    sqliteExprDelete(pTmp->pWhere);
    sqliteExprListDelete(pTmp->pExprList);
    sqliteSelectDelete(pTmp->pSelect);
    sqliteIdListDelete(pTmp->pIdList);

    sqliteFree(pTmp);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteDequote ( char *  )

Definition at line 436 of file util.c.

                           {
  int quote;
  int i, j;
  if( z==0 ) return;
  quote = z[0];
  switch( quote ){
    case '\'':  break;
    case '"':   break;
    case '[':   quote = ']';  break;
    default:    return;
  }
  for(i=1, j=0; z[i]; i++){
    if( z[i]==quote ){
      if( z[i+1]==quote ){
        z[j++] = quote;
        i++;
      }else{
        z[j++] = 0;
        break;
      }
    }else{
      z[j++] = z[i];
    }
  }
}

Here is the caller graph for this function:

void sqliteDetach ( Parse ,
Token  
)

Definition at line 136 of file attach.c.

                                                {
  int i;
  sqlite *db;
  Vdbe *v;
  Db *pDb;

  v = sqliteGetVdbe(pParse);
  sqliteVdbeAddOp(v, OP_Halt, 0, 0);
  if( pParse->explain ) return;
  db = pParse->db;
  for(i=0; i<db->nDb; i++){
    pDb = &db->aDb[i];
    if( pDb->pBt==0 || pDb->zName==0 ) continue;
    if( strlen(pDb->zName)!=pDbname->n ) continue;
    if( sqliteStrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
  }
  if( i>=db->nDb ){
    sqliteErrorMsg(pParse, "no such database: %T", pDbname);
    return;
  }
  if( i<2 ){
    sqliteErrorMsg(pParse, "cannot detach database %T", pDbname);
    return;
  }
#ifndef SQLITE_OMIT_AUTHORIZATION
  if( sqliteAuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
    return;
  }
#endif /* SQLITE_OMIT_AUTHORIZATION */
  sqliteBtreeClose(pDb->pBt);
  pDb->pBt = 0;
  sqliteFree(pDb->zName);
  sqliteResetInternalSchema(db, i);
  if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux);
  db->nDb--;
  if( i<db->nDb ){
    db->aDb[i] = db->aDb[db->nDb];
    memset(&db->aDb[db->nDb], 0, sizeof(db->aDb[0]));
    sqliteResetInternalSchema(db, i);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteDropIndex ( Parse ,
SrcList  
)

Definition at line 1757 of file build.c.

                                                   {
  Index *pIndex;
  Vdbe *v;
  sqlite *db = pParse->db;

  if( pParse->nErr || sqlite_malloc_failed ) return;
  assert( pName->nSrc==1 );
  pIndex = sqliteFindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
  if( pIndex==0 ){
    sqliteErrorMsg(pParse, "no such index: %S", pName, 0);
    goto exit_drop_index;
  }
  if( pIndex->autoIndex ){
    sqliteErrorMsg(pParse, "index associated with UNIQUE "
      "or PRIMARY KEY constraint cannot be dropped", 0);
    goto exit_drop_index;
  }
  if( pIndex->iDb>1 ){
    sqliteErrorMsg(pParse, "cannot alter schema of attached "
       "databases", 0);
    goto exit_drop_index;
  }
#ifndef SQLITE_OMIT_AUTHORIZATION
  {
    int code = SQLITE_DROP_INDEX;
    Table *pTab = pIndex->pTable;
    const char *zDb = db->aDb[pIndex->iDb].zName;
    const char *zTab = SCHEMA_TABLE(pIndex->iDb);
    if( sqliteAuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
      goto exit_drop_index;
    }
    if( pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX;
    if( sqliteAuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){
      goto exit_drop_index;
    }
  }
#endif

  /* Generate code to remove the index and from the master table */
  v = sqliteGetVdbe(pParse);
  if( v ){
    static VdbeOpList dropIndex[] = {
      { OP_Rewind,     0, ADDR(9), 0}, 
      { OP_String,     0, 0,       0}, /* 1 */
      { OP_MemStore,   1, 1,       0},
      { OP_MemLoad,    1, 0,       0}, /* 3 */
      { OP_Column,     0, 1,       0},
      { OP_Eq,         0, ADDR(8), 0},
      { OP_Next,       0, ADDR(3), 0},
      { OP_Goto,       0, ADDR(9), 0},
      { OP_Delete,     0, 0,       0}, /* 8 */
    };
    int base;

    sqliteBeginWriteOperation(pParse, 0, pIndex->iDb);
    sqliteOpenMasterTable(v, pIndex->iDb);
    base = sqliteVdbeAddOpList(v, ArraySize(dropIndex), dropIndex);
    sqliteVdbeChangeP3(v, base+1, pIndex->zName, 0);
    if( pIndex->iDb==0 ){
      sqliteChangeCookie(db, v);
    }
    sqliteVdbeAddOp(v, OP_Close, 0, 0);
    sqliteVdbeAddOp(v, OP_Destroy, pIndex->tnum, pIndex->iDb);
    sqliteEndWriteOperation(pParse);
  }

  /* Delete the in-memory description of this index.
  */
  if( !pParse->explain ){
    sqliteUnlinkAndDeleteIndex(db, pIndex);
    db->flags |= SQLITE_InternChanges;
  }

exit_drop_index:
  sqliteSrcListDelete(pName);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteDropTable ( Parse ,
Token ,
int   
)

Definition at line 1175 of file build.c.

                                                             {
  Table *pTable;
  Vdbe *v;
  int base;
  sqlite *db = pParse->db;
  int iDb;

  if( pParse->nErr || sqlite_malloc_failed ) return;
  pTable = sqliteTableFromToken(pParse, pName);
  if( pTable==0 ) return;
  iDb = pTable->iDb;
  assert( iDb>=0 && iDb<db->nDb );
#ifndef SQLITE_OMIT_AUTHORIZATION
  {
    int code;
    const char *zTab = SCHEMA_TABLE(pTable->iDb);
    const char *zDb = db->aDb[pTable->iDb].zName;
    if( sqliteAuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)){
      return;
    }
    if( isView ){
      if( iDb==1 ){
        code = SQLITE_DROP_TEMP_VIEW;
      }else{
        code = SQLITE_DROP_VIEW;
      }
    }else{
      if( iDb==1 ){
        code = SQLITE_DROP_TEMP_TABLE;
      }else{
        code = SQLITE_DROP_TABLE;
      }
    }
    if( sqliteAuthCheck(pParse, code, pTable->zName, 0, zDb) ){
      return;
    }
    if( sqliteAuthCheck(pParse, SQLITE_DELETE, pTable->zName, 0, zDb) ){
      return;
    }
  }
#endif
  if( pTable->readOnly ){
    sqliteErrorMsg(pParse, "table %s may not be dropped", pTable->zName);
    pParse->nErr++;
    return;
  }
  if( isView && pTable->pSelect==0 ){
    sqliteErrorMsg(pParse, "use DROP TABLE to delete table %s", pTable->zName);
    return;
  }
  if( !isView && pTable->pSelect ){
    sqliteErrorMsg(pParse, "use DROP VIEW to delete view %s", pTable->zName);
    return;
  }

  /* Generate code to remove the table from the master table
  ** on disk.
  */
  v = sqliteGetVdbe(pParse);
  if( v ){
    static VdbeOpList dropTable[] = {
      { OP_Rewind,     0, ADDR(8),  0},
      { OP_String,     0, 0,        0}, /* 1 */
      { OP_MemStore,   1, 1,        0},
      { OP_MemLoad,    1, 0,        0}, /* 3 */
      { OP_Column,     0, 2,        0},
      { OP_Ne,         0, ADDR(7),  0},
      { OP_Delete,     0, 0,        0},
      { OP_Next,       0, ADDR(3),  0}, /* 7 */
    };
    Index *pIdx;
    Trigger *pTrigger;
    sqliteBeginWriteOperation(pParse, 0, pTable->iDb);

    /* Drop all triggers associated with the table being dropped */
    pTrigger = pTable->pTrigger;
    while( pTrigger ){
      assert( pTrigger->iDb==pTable->iDb || pTrigger->iDb==1 );
      sqliteDropTriggerPtr(pParse, pTrigger, 1);
      if( pParse->explain ){
        pTrigger = pTrigger->pNext;
      }else{
        pTrigger = pTable->pTrigger;
      }
    }

    /* Drop all SQLITE_MASTER entries that refer to the table */
    sqliteOpenMasterTable(v, pTable->iDb);
    base = sqliteVdbeAddOpList(v, ArraySize(dropTable), dropTable);
    sqliteVdbeChangeP3(v, base+1, pTable->zName, 0);

    /* Drop all SQLITE_TEMP_MASTER entries that refer to the table */
    if( pTable->iDb!=1 ){
      sqliteOpenMasterTable(v, 1);
      base = sqliteVdbeAddOpList(v, ArraySize(dropTable), dropTable);
      sqliteVdbeChangeP3(v, base+1, pTable->zName, 0);
    }

    if( pTable->iDb==0 ){
      sqliteChangeCookie(db, v);
    }
    sqliteVdbeAddOp(v, OP_Close, 0, 0);
    if( !isView ){
      sqliteVdbeAddOp(v, OP_Destroy, pTable->tnum, pTable->iDb);
      for(pIdx=pTable->pIndex; pIdx; pIdx=pIdx->pNext){
        sqliteVdbeAddOp(v, OP_Destroy, pIdx->tnum, pIdx->iDb);
      }
    }
    sqliteEndWriteOperation(pParse);
  }

  /* Delete the in-memory description of the table.
  **
  ** Exception: if the SQL statement began with the EXPLAIN keyword,
  ** then no changes should be made.
  */
  if( !pParse->explain ){
    sqliteUnlinkAndDeleteTable(db, pTable);
    db->flags |= SQLITE_InternChanges;
  }
  sqliteViewResetAll(db, iDb);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteDropTrigger ( Parse ,
SrcList  
)

Definition at line 388 of file trigger.c.

                                                     {
  Trigger *pTrigger;
  int i;
  const char *zDb;
  const char *zName;
  int nName;
  sqlite *db = pParse->db;

  if( sqlite_malloc_failed ) goto drop_trigger_cleanup;
  assert( pName->nSrc==1 );
  zDb = pName->a[0].zDatabase;
  zName = pName->a[0].zName;
  nName = strlen(zName);
  for(i=0; i<db->nDb; i++){
    int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
    if( zDb && sqliteStrICmp(db->aDb[j].zName, zDb) ) continue;
    pTrigger = sqliteHashFind(&(db->aDb[j].trigHash), zName, nName+1);
    if( pTrigger ) break;
  }
  if( !pTrigger ){
    sqliteErrorMsg(pParse, "no such trigger: %S", pName, 0);
    goto drop_trigger_cleanup;
  }
  sqliteDropTriggerPtr(pParse, pTrigger, 0);

drop_trigger_cleanup:
  sqliteSrcListDelete(pName);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteDropTriggerPtr ( Parse ,
Trigger ,
int   
)

Definition at line 422 of file trigger.c.

                                                                       {
  Table   *pTable;
  Vdbe *v;
  sqlite *db = pParse->db;

  assert( pTrigger->iDb<db->nDb );
  if( pTrigger->iDb>=2 ){
    sqliteErrorMsg(pParse, "triggers may not be removed from "
       "auxiliary database %s", db->aDb[pTrigger->iDb].zName);
    return;
  }
  pTable = sqliteFindTable(db, pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
  assert(pTable);
  assert( pTable->iDb==pTrigger->iDb || pTrigger->iDb==1 );
#ifndef SQLITE_OMIT_AUTHORIZATION
  {
    int code = SQLITE_DROP_TRIGGER;
    const char *zDb = db->aDb[pTrigger->iDb].zName;
    const char *zTab = SCHEMA_TABLE(pTrigger->iDb);
    if( pTrigger->iDb ) code = SQLITE_DROP_TEMP_TRIGGER;
    if( sqliteAuthCheck(pParse, code, pTrigger->name, pTable->zName, zDb) ||
      sqliteAuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
      return;
    }
  }
#endif

  /* Generate code to destroy the database record of the trigger.
  */
  if( pTable!=0 && !nested && (v = sqliteGetVdbe(pParse))!=0 ){
    int base;
    static VdbeOpList dropTrigger[] = {
      { OP_Rewind,     0, ADDR(9),  0},
      { OP_String,     0, 0,        0}, /* 1 */
      { OP_Column,     0, 1,        0},
      { OP_Ne,         0, ADDR(8),  0},
      { OP_String,     0, 0,        "trigger"},
      { OP_Column,     0, 0,        0},
      { OP_Ne,         0, ADDR(8),  0},
      { OP_Delete,     0, 0,        0},
      { OP_Next,       0, ADDR(1),  0}, /* 8 */
    };

    sqliteBeginWriteOperation(pParse, 0, 0);
    sqliteOpenMasterTable(v, pTrigger->iDb);
    base = sqliteVdbeAddOpList(v,  ArraySize(dropTrigger), dropTrigger);
    sqliteVdbeChangeP3(v, base+1, pTrigger->name, 0);
    if( pTrigger->iDb==0 ){
      sqliteChangeCookie(db, v);
    }
    sqliteVdbeAddOp(v, OP_Close, 0, 0);
    sqliteEndWriteOperation(pParse);
  }

  /*
   * If this is not an "explain", then delete the trigger structure.
   */
  if( !pParse->explain ){
    const char *zName = pTrigger->name;
    int nName = strlen(zName);
    if( pTable->pTrigger == pTrigger ){
      pTable->pTrigger = pTrigger->pNext;
    }else{
      Trigger *cc = pTable->pTrigger;
      while( cc ){ 
        if( cc->pNext == pTrigger ){
          cc->pNext = cc->pNext->pNext;
          break;
        }
        cc = cc->pNext;
      }
      assert(cc);
    }
    sqliteHashInsert(&(db->aDb[pTrigger->iDb].trigHash), zName, nName+1, 0);
    sqliteDeleteTrigger(pTrigger);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteEndTable ( Parse ,
Token ,
Select  
)

Definition at line 883 of file build.c.

                                                                {
  Table *p;
  sqlite *db = pParse->db;

  if( (pEnd==0 && pSelect==0) || pParse->nErr || sqlite_malloc_failed ) return;
  p = pParse->pNewTable;
  if( p==0 ) return;

  /* If the table is generated from a SELECT, then construct the
  ** list of columns and the text of the table.
  */
  if( pSelect ){
    Table *pSelTab = sqliteResultSetOfSelect(pParse, 0, pSelect);
    if( pSelTab==0 ) return;
    assert( p->aCol==0 );
    p->nCol = pSelTab->nCol;
    p->aCol = pSelTab->aCol;
    pSelTab->nCol = 0;
    pSelTab->aCol = 0;
    sqliteDeleteTable(0, pSelTab);
  }

  /* If the db->init.busy is 1 it means we are reading the SQL off the
  ** "sqlite_master" or "sqlite_temp_master" table on the disk.
  ** So do not write to the disk again.  Extract the root page number
  ** for the table from the db->init.newTnum field.  (The page number
  ** should have been put there by the sqliteOpenCb routine.)
  */
  if( db->init.busy ){
    p->tnum = db->init.newTnum;
  }

  /* If not initializing, then create a record for the new table
  ** in the SQLITE_MASTER table of the database.  The record number
  ** for the new table entry should already be on the stack.
  **
  ** If this is a TEMPORARY table, write the entry into the auxiliary
  ** file instead of into the main database file.
  */
  if( !db->init.busy ){
    int n;
    Vdbe *v;

    v = sqliteGetVdbe(pParse);
    if( v==0 ) return;
    if( p->pSelect==0 ){
      /* A regular table */
      sqliteVdbeOp3(v, OP_CreateTable, 0, p->iDb, (char*)&p->tnum, P3_POINTER);
    }else{
      /* A view */
      sqliteVdbeAddOp(v, OP_Integer, 0, 0);
    }
    p->tnum = 0;
    sqliteVdbeAddOp(v, OP_Pull, 1, 0);
    sqliteVdbeOp3(v, OP_String, 0, 0, p->pSelect==0?"table":"view", P3_STATIC);
    sqliteVdbeOp3(v, OP_String, 0, 0, p->zName, 0);
    sqliteVdbeOp3(v, OP_String, 0, 0, p->zName, 0);
    sqliteVdbeAddOp(v, OP_Dup, 4, 0);
    sqliteVdbeAddOp(v, OP_String, 0, 0);
    if( pSelect ){
      char *z = createTableStmt(p);
      n = z ? strlen(z) : 0;
      sqliteVdbeChangeP3(v, -1, z, n);
      sqliteFree(z);
    }else{
      assert( pEnd!=0 );
      n = Addr(pEnd->z) - Addr(pParse->sFirstToken.z) + 1;
      sqliteVdbeChangeP3(v, -1, pParse->sFirstToken.z, n);
    }
    sqliteVdbeAddOp(v, OP_MakeRecord, 5, 0);
    sqliteVdbeAddOp(v, OP_PutIntKey, 0, 0);
    if( !p->iDb ){
      sqliteChangeCookie(db, v);
    }
    sqliteVdbeAddOp(v, OP_Close, 0, 0);
    if( pSelect ){
      sqliteVdbeAddOp(v, OP_Integer, p->iDb, 0);
      sqliteVdbeAddOp(v, OP_OpenWrite, 1, 0);
      pParse->nTab = 2;
      sqliteSelect(pParse, pSelect, SRT_Table, 1, 0, 0, 0);
    }
    sqliteEndWriteOperation(pParse);
  }

  /* Add the table to the in-memory representation of the database.
  */
  if( pParse->explain==0 && pParse->nErr==0 ){
    Table *pOld;
    FKey *pFKey;
    pOld = sqliteHashInsert(&db->aDb[p->iDb].tblHash, 
                            p->zName, strlen(p->zName)+1, p);
    if( pOld ){
      assert( p==pOld );  /* Malloc must have failed inside HashInsert() */
      return;
    }
    for(pFKey=p->pFKey; pFKey; pFKey=pFKey->pNextFrom){
      int nTo = strlen(pFKey->zTo) + 1;
      pFKey->pNextTo = sqliteHashFind(&db->aDb[p->iDb].aFKey, pFKey->zTo, nTo);
      sqliteHashInsert(&db->aDb[p->iDb].aFKey, pFKey->zTo, nTo, pFKey);
    }
    pParse->pNewTable = 0;
    db->nTable++;
    db->flags |= SQLITE_InternChanges;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2144 of file build.c.

                                           {
  Vdbe *v;
  sqlite *db = pParse->db;
  if( pParse->trigStack ) return; /* if this is in a trigger */
  v = sqliteGetVdbe(pParse);
  if( v==0 ) return;
  if( db->flags & SQLITE_InTrans ){
    /* A BEGIN has executed.  Do not commit until we see an explicit
    ** COMMIT statement. */
  }else{
    sqliteVdbeAddOp(v, OP_Commit, 0, 0);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteErrorMsg ( Parse ,
const char *  ,
  ... 
)

Definition at line 417 of file util.c.

                                                            {
  va_list ap;
  pParse->nErr++;
  sqliteFree(pParse->zErrMsg);
  va_start(ap, zFormat);
  pParse->zErrMsg = sqliteVMPrintf(zFormat, ap);
  va_end(ap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteExec ( Parse )

Definition at line 67 of file build.c.

                              {
  sqlite *db = pParse->db;
  Vdbe *v = pParse->pVdbe;

  if( v==0 && (v = sqliteGetVdbe(pParse))!=0 ){
    sqliteVdbeAddOp(v, OP_Halt, 0, 0);
  }
  if( sqlite_malloc_failed ) return;
  if( v && pParse->nErr==0 ){
    FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
    sqliteVdbeTrace(v, trace);
    sqliteVdbeMakeReady(v, pParse->nVar, pParse->explain);
    pParse->rc = pParse->nErr ? SQLITE_ERROR : SQLITE_DONE;
    pParse->colNamesSet = 0;
  }else if( pParse->rc==SQLITE_OK ){
    pParse->rc = SQLITE_ERROR;
  }
  pParse->nTab = 0;
  pParse->nMem = 0;
  pParse->nSet = 0;
  pParse->nAgg = 0;
  pParse->nVar = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Expr* sqliteExpr ( int  ,
Expr ,
Expr ,
Token  
)

Definition at line 25 of file expr.c.

                                                                  {
  Expr *pNew;
  pNew = sqliteMalloc( sizeof(Expr) );
  if( pNew==0 ){
    /* When malloc fails, we leak memory from pLeft and pRight */
    return 0;
  }
  pNew->op = op;
  pNew->pLeft = pLeft;
  pNew->pRight = pRight;
  if( pToken ){
    assert( pToken->dyn==0 );
    pNew->token = *pToken;
    pNew->span = *pToken;
  }else{
    assert( pNew->token.dyn==0 );
    assert( pNew->token.z==0 );
    assert( pNew->token.n==0 );
    if( pLeft && pRight ){
      sqliteExprSpan(pNew, &pLeft->span, &pRight->span);
    }else{
      pNew->span = pNew->token;
    }
  }
  return pNew;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1550 of file expr.c.

                                                           {
  int i;
  AggExpr *aAgg;
  int nErr = 0;

  if( pExpr==0 ) return 0;
  switch( pExpr->op ){
    case TK_COLUMN: {
      aAgg = pParse->aAgg;
      for(i=0; i<pParse->nAgg; i++){
        if( aAgg[i].isAgg ) continue;
        if( aAgg[i].pExpr->iTable==pExpr->iTable
         && aAgg[i].pExpr->iColumn==pExpr->iColumn ){
          break;
        }
      }
      if( i>=pParse->nAgg ){
        i = appendAggInfo(pParse);
        if( i<0 ) return 1;
        pParse->aAgg[i].isAgg = 0;
        pParse->aAgg[i].pExpr = pExpr;
      }
      pExpr->iAgg = i;
      break;
    }
    case TK_AGG_FUNCTION: {
      aAgg = pParse->aAgg;
      for(i=0; i<pParse->nAgg; i++){
        if( !aAgg[i].isAgg ) continue;
        if( sqliteExprCompare(aAgg[i].pExpr, pExpr) ){
          break;
        }
      }
      if( i>=pParse->nAgg ){
        i = appendAggInfo(pParse);
        if( i<0 ) return 1;
        pParse->aAgg[i].isAgg = 1;
        pParse->aAgg[i].pExpr = pExpr;
        pParse->aAgg[i].pFunc = sqliteFindFunction(pParse->db,
             pExpr->token.z, pExpr->token.n,
             pExpr->pList ? pExpr->pList->nExpr : 0, 0);
      }
      pExpr->iAgg = i;
      break;
    }
    default: {
      if( pExpr->pLeft ){
        nErr = sqliteExprAnalyzeAggregates(pParse, pExpr->pLeft);
      }
      if( nErr==0 && pExpr->pRight ){
        nErr = sqliteExprAnalyzeAggregates(pParse, pExpr->pRight);
      }
      if( nErr==0 && pExpr->pList ){
        int n = pExpr->pList->nExpr;
        int i;
        for(i=0; nErr==0 && i<n; i++){
          nErr = sqliteExprAnalyzeAggregates(pParse, pExpr->pList->a[i].pExpr);
        }
      }
      break;
    }
  }
  return nErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteExprCheck ( Parse ,
Expr ,
int  ,
int  
)

Definition at line 823 of file expr.c.

                                                                          {
  int nErr = 0;
  if( pExpr==0 ) return 0;
  switch( pExpr->op ){
    case TK_GLOB:
    case TK_LIKE:
    case TK_FUNCTION: {
      int n = pExpr->pList ? pExpr->pList->nExpr : 0;  /* Number of arguments */
      int no_such_func = 0;       /* True if no such function exists */
      int wrong_num_args = 0;     /* True if wrong number of arguments */
      int is_agg = 0;             /* True if is an aggregate function */
      int i;
      int nId;                    /* Number of characters in function name */
      const char *zId;            /* The function name. */
      FuncDef *pDef;

      getFunctionName(pExpr, &zId, &nId);
      pDef = sqliteFindFunction(pParse->db, zId, nId, n, 0);
      if( pDef==0 ){
        pDef = sqliteFindFunction(pParse->db, zId, nId, -1, 0);
        if( pDef==0 ){
          no_such_func = 1;
        }else{
          wrong_num_args = 1;
        }
      }else{
        is_agg = pDef->xFunc==0;
      }
      if( is_agg && !allowAgg ){
        sqliteErrorMsg(pParse, "misuse of aggregate function %.*s()", nId, zId);
        nErr++;
        is_agg = 0;
      }else if( no_such_func ){
        sqliteErrorMsg(pParse, "no such function: %.*s", nId, zId);
        nErr++;
      }else if( wrong_num_args ){
        sqliteErrorMsg(pParse,"wrong number of arguments to function %.*s()",
             nId, zId);
        nErr++;
      }
      if( is_agg ){
        pExpr->op = TK_AGG_FUNCTION;
        if( pIsAgg ) *pIsAgg = 1;
      }
      for(i=0; nErr==0 && i<n; i++){
        nErr = sqliteExprCheck(pParse, pExpr->pList->a[i].pExpr,
                               allowAgg && !is_agg, pIsAgg);
      }
      if( pDef==0 ){
        /* Already reported an error */
      }else if( pDef->dataType>=0 ){
        if( pDef->dataType<n ){
          pExpr->dataType = 
             sqliteExprType(pExpr->pList->a[pDef->dataType].pExpr);
        }else{
          pExpr->dataType = SQLITE_SO_NUM;
        }
      }else if( pDef->dataType==SQLITE_ARGS ){
        pDef->dataType = SQLITE_SO_TEXT;
        for(i=0; i<n; i++){
          if( sqliteExprType(pExpr->pList->a[i].pExpr)==SQLITE_SO_NUM ){
            pExpr->dataType = SQLITE_SO_NUM;
            break;
          }
        }
      }else if( pDef->dataType==SQLITE_NUMERIC ){
        pExpr->dataType = SQLITE_SO_NUM;
      }else{
        pExpr->dataType = SQLITE_SO_TEXT;
      }
    }
    default: {
      if( pExpr->pLeft ){
        nErr = sqliteExprCheck(pParse, pExpr->pLeft, allowAgg, pIsAgg);
      }
      if( nErr==0 && pExpr->pRight ){
        nErr = sqliteExprCheck(pParse, pExpr->pRight, allowAgg, pIsAgg);
      }
      if( nErr==0 && pExpr->pList ){
        int n = pExpr->pList->nExpr;
        int i;
        for(i=0; nErr==0 && i<n; i++){
          Expr *pE2 = pExpr->pList->a[i].pExpr;
          nErr = sqliteExprCheck(pParse, pE2, allowAgg, pIsAgg);
        }
      }
      break;
    }
  }
  return nErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteExprCode ( Parse ,
Expr  
)

Definition at line 1011 of file expr.c.

                                               {
  Vdbe *v = pParse->pVdbe;
  int op;
  if( v==0 || pExpr==0 ) return;
  switch( pExpr->op ){
    case TK_PLUS:     op = OP_Add;      break;
    case TK_MINUS:    op = OP_Subtract; break;
    case TK_STAR:     op = OP_Multiply; break;
    case TK_SLASH:    op = OP_Divide;   break;
    case TK_AND:      op = OP_And;      break;
    case TK_OR:       op = OP_Or;       break;
    case TK_LT:       op = OP_Lt;       break;
    case TK_LE:       op = OP_Le;       break;
    case TK_GT:       op = OP_Gt;       break;
    case TK_GE:       op = OP_Ge;       break;
    case TK_NE:       op = OP_Ne;       break;
    case TK_EQ:       op = OP_Eq;       break;
    case TK_ISNULL:   op = OP_IsNull;   break;
    case TK_NOTNULL:  op = OP_NotNull;  break;
    case TK_NOT:      op = OP_Not;      break;
    case TK_UMINUS:   op = OP_Negative; break;
    case TK_BITAND:   op = OP_BitAnd;   break;
    case TK_BITOR:    op = OP_BitOr;    break;
    case TK_BITNOT:   op = OP_BitNot;   break;
    case TK_LSHIFT:   op = OP_ShiftLeft;  break;
    case TK_RSHIFT:   op = OP_ShiftRight; break;
    case TK_REM:      op = OP_Remainder;  break;
    default: break;
  }
  switch( pExpr->op ){
    case TK_COLUMN: {
      if( pParse->useAgg ){
        sqliteVdbeAddOp(v, OP_AggGet, 0, pExpr->iAgg);
      }else if( pExpr->iColumn>=0 ){
        sqliteVdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn);
      }else{
        sqliteVdbeAddOp(v, OP_Recno, pExpr->iTable, 0);
      }
      break;
    }
    case TK_STRING:
    case TK_FLOAT:
    case TK_INTEGER: {
      if( pExpr->op==TK_INTEGER && sqliteFitsIn32Bits(pExpr->token.z) ){
        sqliteVdbeAddOp(v, OP_Integer, atoi(pExpr->token.z), 0);
      }else{
        sqliteVdbeAddOp(v, OP_String, 0, 0);
      }
      assert( pExpr->token.z );
      sqliteVdbeChangeP3(v, -1, pExpr->token.z, pExpr->token.n);
      sqliteVdbeDequoteP3(v, -1);
      break;
    }
    case TK_NULL: {
      sqliteVdbeAddOp(v, OP_String, 0, 0);
      break;
    }
    case TK_VARIABLE: {
      sqliteVdbeAddOp(v, OP_Variable, pExpr->iTable, 0);
      break;
    }
    case TK_LT:
    case TK_LE:
    case TK_GT:
    case TK_GE:
    case TK_NE:
    case TK_EQ: {
      if( pParse->db->file_format>=4 && sqliteExprType(pExpr)==SQLITE_SO_TEXT ){
        op += 6;  /* Convert numeric opcodes to text opcodes */
      }
      /* Fall through into the next case */
    }
    case TK_AND:
    case TK_OR:
    case TK_PLUS:
    case TK_STAR:
    case TK_MINUS:
    case TK_REM:
    case TK_BITAND:
    case TK_BITOR:
    case TK_SLASH: {
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteExprCode(pParse, pExpr->pRight);
      sqliteVdbeAddOp(v, op, 0, 0);
      break;
    }
    case TK_LSHIFT:
    case TK_RSHIFT: {
      sqliteExprCode(pParse, pExpr->pRight);
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteVdbeAddOp(v, op, 0, 0);
      break;
    }
    case TK_CONCAT: {
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteExprCode(pParse, pExpr->pRight);
      sqliteVdbeAddOp(v, OP_Concat, 2, 0);
      break;
    }
    case TK_UMINUS: {
      assert( pExpr->pLeft );
      if( pExpr->pLeft->op==TK_FLOAT || pExpr->pLeft->op==TK_INTEGER ){
        Token *p = &pExpr->pLeft->token;
        char *z = sqliteMalloc( p->n + 2 );
        sprintf(z, "-%.*s", p->n, p->z);
        if( pExpr->pLeft->op==TK_INTEGER && sqliteFitsIn32Bits(z) ){
          sqliteVdbeAddOp(v, OP_Integer, atoi(z), 0);
        }else{
          sqliteVdbeAddOp(v, OP_String, 0, 0);
        }
        sqliteVdbeChangeP3(v, -1, z, p->n+1);
        sqliteFree(z);
        break;
      }
      /* Fall through into TK_NOT */
    }
    case TK_BITNOT:
    case TK_NOT: {
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteVdbeAddOp(v, op, 0, 0);
      break;
    }
    case TK_ISNULL:
    case TK_NOTNULL: {
      int dest;
      sqliteVdbeAddOp(v, OP_Integer, 1, 0);
      sqliteExprCode(pParse, pExpr->pLeft);
      dest = sqliteVdbeCurrentAddr(v) + 2;
      sqliteVdbeAddOp(v, op, 1, dest);
      sqliteVdbeAddOp(v, OP_AddImm, -1, 0);
      break;
    }
    case TK_AGG_FUNCTION: {
      sqliteVdbeAddOp(v, OP_AggGet, 0, pExpr->iAgg);
      break;
    }
    case TK_GLOB:
    case TK_LIKE:
    case TK_FUNCTION: {
      ExprList *pList = pExpr->pList;
      int nExpr = pList ? pList->nExpr : 0;
      FuncDef *pDef;
      int nId;
      const char *zId;
      getFunctionName(pExpr, &zId, &nId);
      pDef = sqliteFindFunction(pParse->db, zId, nId, nExpr, 0);
      assert( pDef!=0 );
      nExpr = sqliteExprCodeExprList(pParse, pList, pDef->includeTypes);
      sqliteVdbeOp3(v, OP_Function, nExpr, 0, (char*)pDef, P3_POINTER);
      break;
    }
    case TK_SELECT: {
      sqliteVdbeAddOp(v, OP_MemLoad, pExpr->iColumn, 0);
      break;
    }
    case TK_IN: {
      int addr;
      sqliteVdbeAddOp(v, OP_Integer, 1, 0);
      sqliteExprCode(pParse, pExpr->pLeft);
      addr = sqliteVdbeCurrentAddr(v);
      sqliteVdbeAddOp(v, OP_NotNull, -1, addr+4);
      sqliteVdbeAddOp(v, OP_Pop, 2, 0);
      sqliteVdbeAddOp(v, OP_String, 0, 0);
      sqliteVdbeAddOp(v, OP_Goto, 0, addr+6);
      if( pExpr->pSelect ){
        sqliteVdbeAddOp(v, OP_Found, pExpr->iTable, addr+6);
      }else{
        sqliteVdbeAddOp(v, OP_SetFound, pExpr->iTable, addr+6);
      }
      sqliteVdbeAddOp(v, OP_AddImm, -1, 0);
      break;
    }
    case TK_BETWEEN: {
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteVdbeAddOp(v, OP_Dup, 0, 0);
      sqliteExprCode(pParse, pExpr->pList->a[0].pExpr);
      sqliteVdbeAddOp(v, OP_Ge, 0, 0);
      sqliteVdbeAddOp(v, OP_Pull, 1, 0);
      sqliteExprCode(pParse, pExpr->pList->a[1].pExpr);
      sqliteVdbeAddOp(v, OP_Le, 0, 0);
      sqliteVdbeAddOp(v, OP_And, 0, 0);
      break;
    }
    case TK_UPLUS:
    case TK_AS: {
      sqliteExprCode(pParse, pExpr->pLeft);
      break;
    }
    case TK_CASE: {
      int expr_end_label;
      int jumpInst;
      int addr;
      int nExpr;
      int i;

      assert(pExpr->pList);
      assert((pExpr->pList->nExpr % 2) == 0);
      assert(pExpr->pList->nExpr > 0);
      nExpr = pExpr->pList->nExpr;
      expr_end_label = sqliteVdbeMakeLabel(v);
      if( pExpr->pLeft ){
        sqliteExprCode(pParse, pExpr->pLeft);
      }
      for(i=0; i<nExpr; i=i+2){
        sqliteExprCode(pParse, pExpr->pList->a[i].pExpr);
        if( pExpr->pLeft ){
          sqliteVdbeAddOp(v, OP_Dup, 1, 1);
          jumpInst = sqliteVdbeAddOp(v, OP_Ne, 1, 0);
          sqliteVdbeAddOp(v, OP_Pop, 1, 0);
        }else{
          jumpInst = sqliteVdbeAddOp(v, OP_IfNot, 1, 0);
        }
        sqliteExprCode(pParse, pExpr->pList->a[i+1].pExpr);
        sqliteVdbeAddOp(v, OP_Goto, 0, expr_end_label);
        addr = sqliteVdbeCurrentAddr(v);
        sqliteVdbeChangeP2(v, jumpInst, addr);
      }
      if( pExpr->pLeft ){
        sqliteVdbeAddOp(v, OP_Pop, 1, 0);
      }
      if( pExpr->pRight ){
        sqliteExprCode(pParse, pExpr->pRight);
      }else{
        sqliteVdbeAddOp(v, OP_String, 0, 0);
      }
      sqliteVdbeResolveLabel(v, expr_end_label);
      break;
    }
    case TK_RAISE: {
      if( !pParse->trigStack ){
        sqliteErrorMsg(pParse,
                       "RAISE() may only be used within a trigger-program");
        pParse->nErr++;
       return;
      }
      if( pExpr->iColumn == OE_Rollback ||
         pExpr->iColumn == OE_Abort ||
         pExpr->iColumn == OE_Fail ){
         sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn,
                           pExpr->token.z, pExpr->token.n);
         sqliteVdbeDequoteP3(v, -1);
      } else {
         assert( pExpr->iColumn == OE_Ignore );
         sqliteVdbeOp3(v, OP_Goto, 0, pParse->trigStack->ignoreJump,
                           "(IGNORE jump)", 0);
      }
    }
    break;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1270 of file expr.c.

 {
  struct ExprList_item *pItem;
  int i, n;
  Vdbe *v;
  if( pList==0 ) return 0;
  v = sqliteGetVdbe(pParse);
  n = pList->nExpr;
  for(pItem=pList->a, i=0; i<n; i++, pItem++){
    sqliteExprCode(pParse, pItem->pExpr);
    if( includeTypes ){
      sqliteVdbeOp3(v, OP_String, 0, 0, 
         sqliteExprType(pItem->pExpr)==SQLITE_SO_NUM ? "numeric" : "text",
         P3_STATIC);
    }
  }
  return includeTypes ? n*2 : n;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteExprCompare ( Expr ,
Expr  
)

Definition at line 1492 of file expr.c.

                                         {
  int i;
  if( pA==0 ){
    return pB==0;
  }else if( pB==0 ){
    return 0;
  }
  if( pA->op!=pB->op ) return 0;
  if( !sqliteExprCompare(pA->pLeft, pB->pLeft) ) return 0;
  if( !sqliteExprCompare(pA->pRight, pB->pRight) ) return 0;
  if( pA->pList ){
    if( pB->pList==0 ) return 0;
    if( pA->pList->nExpr!=pB->pList->nExpr ) return 0;
    for(i=0; i<pA->pList->nExpr; i++){
      if( !sqliteExprCompare(pA->pList->a[i].pExpr, pB->pList->a[i].pExpr) ){
        return 0;
      }
    }
  }else if( pB->pList ){
    return 0;
  }
  if( pA->pSelect || pB->pSelect ) return 0;
  if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 0;
  if( pA->token.z ){
    if( pB->token.z==0 ) return 0;
    if( pB->token.n!=pA->token.n ) return 0;
    if( sqliteStrNICmp(pA->token.z, pB->token.z, pB->token.n)!=0 ) return 0;
  }
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteExprDelete ( Expr )

Definition at line 96 of file expr.c.

                              {
  if( p==0 ) return;
  if( p->span.dyn ) sqliteFree((char*)p->span.z);
  if( p->token.dyn ) sqliteFree((char*)p->token.z);
  sqliteExprDelete(p->pLeft);
  sqliteExprDelete(p->pRight);
  sqliteExprListDelete(p->pList);
  sqliteSelectDelete(p->pSelect);
  sqliteFree(p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 120 of file expr.c.

                            {
  Expr *pNew;
  if( p==0 ) return 0;
  pNew = sqliteMallocRaw( sizeof(*p) );
  if( pNew==0 ) return 0;
  memcpy(pNew, p, sizeof(*pNew));
  if( p->token.z!=0 ){
    pNew->token.z = sqliteStrNDup(p->token.z, p->token.n);
    pNew->token.dyn = 1;
  }else{
    assert( pNew->token.z==0 );
  }
  pNew->span.z = 0;
  pNew->pLeft = sqliteExprDup(p->pLeft);
  pNew->pRight = sqliteExprDup(p->pRight);
  pNew->pList = sqliteExprListDup(p->pList);
  pNew->pSelect = sqliteSelectDup(p->pSelect);
  return pNew;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 74 of file expr.c.

                                                        {
  Expr *pNew;
  pNew = sqliteMalloc( sizeof(Expr) );
  if( pNew==0 ){
    /* sqliteExprListDelete(pList); // Leak pList when malloc fails */
    return 0;
  }
  pNew->op = TK_FUNCTION;
  pNew->pList = pList;
  if( pToken ){
    assert( pToken->dyn==0 );
    pNew->token = *pToken;
  }else{
    pNew->token.z = 0;
  }
  pNew->span = pNew->token;
  return pNew;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteExprIfFalse ( Parse ,
Expr ,
int  ,
int   
)

Definition at line 1395 of file expr.c.

                                                                            {
  Vdbe *v = pParse->pVdbe;
  int op = 0;
  if( v==0 || pExpr==0 ) return;
  switch( pExpr->op ){
    case TK_LT:       op = OP_Ge;       break;
    case TK_LE:       op = OP_Gt;       break;
    case TK_GT:       op = OP_Le;       break;
    case TK_GE:       op = OP_Lt;       break;
    case TK_NE:       op = OP_Eq;       break;
    case TK_EQ:       op = OP_Ne;       break;
    case TK_ISNULL:   op = OP_NotNull;  break;
    case TK_NOTNULL:  op = OP_IsNull;   break;
    default:  break;
  }
  switch( pExpr->op ){
    case TK_AND: {
      sqliteExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
      sqliteExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
      break;
    }
    case TK_OR: {
      int d2 = sqliteVdbeMakeLabel(v);
      sqliteExprIfTrue(pParse, pExpr->pLeft, d2, !jumpIfNull);
      sqliteExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
      sqliteVdbeResolveLabel(v, d2);
      break;
    }
    case TK_NOT: {
      sqliteExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
      break;
    }
    case TK_LT:
    case TK_LE:
    case TK_GT:
    case TK_GE:
    case TK_NE:
    case TK_EQ: {
      if( pParse->db->file_format>=4 && sqliteExprType(pExpr)==SQLITE_SO_TEXT ){
        /* Convert numeric comparison opcodes into text comparison opcodes.
        ** This step depends on the fact that the text comparision opcodes are
        ** always 6 greater than their corresponding numeric comparison
        ** opcodes.
        */
        assert( OP_Eq+6 == OP_StrEq );
        op += 6;
      }
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteExprCode(pParse, pExpr->pRight);
      sqliteVdbeAddOp(v, op, jumpIfNull, dest);
      break;
    }
    case TK_ISNULL:
    case TK_NOTNULL: {
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteVdbeAddOp(v, op, 1, dest);
      break;
    }
    case TK_IN: {
      int addr;
      sqliteExprCode(pParse, pExpr->pLeft);
      addr = sqliteVdbeCurrentAddr(v);
      sqliteVdbeAddOp(v, OP_NotNull, -1, addr+3);
      sqliteVdbeAddOp(v, OP_Pop, 1, 0);
      sqliteVdbeAddOp(v, OP_Goto, 0, jumpIfNull ? dest : addr+4);
      if( pExpr->pSelect ){
        sqliteVdbeAddOp(v, OP_NotFound, pExpr->iTable, dest);
      }else{
        sqliteVdbeAddOp(v, OP_SetNotFound, pExpr->iTable, dest);
      }
      break;
    }
    case TK_BETWEEN: {
      int addr;
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteVdbeAddOp(v, OP_Dup, 0, 0);
      sqliteExprCode(pParse, pExpr->pList->a[0].pExpr);
      addr = sqliteVdbeCurrentAddr(v);
      sqliteVdbeAddOp(v, OP_Ge, !jumpIfNull, addr+3);
      sqliteVdbeAddOp(v, OP_Pop, 1, 0);
      sqliteVdbeAddOp(v, OP_Goto, 0, dest);
      sqliteExprCode(pParse, pExpr->pList->a[1].pExpr);
      sqliteVdbeAddOp(v, OP_Gt, jumpIfNull, dest);
      break;
    }
    default: {
      sqliteExprCode(pParse, pExpr);
      sqliteVdbeAddOp(v, OP_IfNot, jumpIfNull, dest);
      break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteExprIfTrue ( Parse ,
Expr ,
int  ,
int   
)

Definition at line 1300 of file expr.c.

                                                                           {
  Vdbe *v = pParse->pVdbe;
  int op = 0;
  if( v==0 || pExpr==0 ) return;
  switch( pExpr->op ){
    case TK_LT:       op = OP_Lt;       break;
    case TK_LE:       op = OP_Le;       break;
    case TK_GT:       op = OP_Gt;       break;
    case TK_GE:       op = OP_Ge;       break;
    case TK_NE:       op = OP_Ne;       break;
    case TK_EQ:       op = OP_Eq;       break;
    case TK_ISNULL:   op = OP_IsNull;   break;
    case TK_NOTNULL:  op = OP_NotNull;  break;
    default:  break;
  }
  switch( pExpr->op ){
    case TK_AND: {
      int d2 = sqliteVdbeMakeLabel(v);
      sqliteExprIfFalse(pParse, pExpr->pLeft, d2, !jumpIfNull);
      sqliteExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
      sqliteVdbeResolveLabel(v, d2);
      break;
    }
    case TK_OR: {
      sqliteExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
      sqliteExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
      break;
    }
    case TK_NOT: {
      sqliteExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
      break;
    }
    case TK_LT:
    case TK_LE:
    case TK_GT:
    case TK_GE:
    case TK_NE:
    case TK_EQ: {
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteExprCode(pParse, pExpr->pRight);
      if( pParse->db->file_format>=4 && sqliteExprType(pExpr)==SQLITE_SO_TEXT ){
        op += 6;  /* Convert numeric opcodes to text opcodes */
      }
      sqliteVdbeAddOp(v, op, jumpIfNull, dest);
      break;
    }
    case TK_ISNULL:
    case TK_NOTNULL: {
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteVdbeAddOp(v, op, 1, dest);
      break;
    }
    case TK_IN: {
      int addr;
      sqliteExprCode(pParse, pExpr->pLeft);
      addr = sqliteVdbeCurrentAddr(v);
      sqliteVdbeAddOp(v, OP_NotNull, -1, addr+3);
      sqliteVdbeAddOp(v, OP_Pop, 1, 0);
      sqliteVdbeAddOp(v, OP_Goto, 0, jumpIfNull ? dest : addr+4);
      if( pExpr->pSelect ){
        sqliteVdbeAddOp(v, OP_Found, pExpr->iTable, dest);
      }else{
        sqliteVdbeAddOp(v, OP_SetFound, pExpr->iTable, dest);
      }
      break;
    }
    case TK_BETWEEN: {
      int addr;
      sqliteExprCode(pParse, pExpr->pLeft);
      sqliteVdbeAddOp(v, OP_Dup, 0, 0);
      sqliteExprCode(pParse, pExpr->pList->a[0].pExpr);
      addr = sqliteVdbeAddOp(v, OP_Lt, !jumpIfNull, 0);
      sqliteExprCode(pParse, pExpr->pList->a[1].pExpr);
      sqliteVdbeAddOp(v, OP_Le, jumpIfNull, dest);
      sqliteVdbeAddOp(v, OP_Integer, 0, 0);
      sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
      sqliteVdbeAddOp(v, OP_Pop, 1, 0);
      break;
    }
    default: {
      sqliteExprCode(pParse, pExpr);
      sqliteVdbeAddOp(v, OP_If, jumpIfNull, dest);
      break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 303 of file expr.c.

                                 {
  switch( p->op ){
    case TK_ID:
    case TK_COLUMN:
    case TK_DOT:
    case TK_FUNCTION:
      return 0;
    case TK_NULL:
    case TK_STRING:
    case TK_INTEGER:
    case TK_FLOAT:
    case TK_VARIABLE:
      return 1;
    default: {
      if( p->pLeft && !sqliteExprIsConstant(p->pLeft) ) return 0;
      if( p->pRight && !sqliteExprIsConstant(p->pRight) ) return 0;
      if( p->pList ){
        int i;
        for(i=0; i<p->pList->nExpr; i++){
          if( !sqliteExprIsConstant(p->pList->a[i].pExpr) ) return 0;
        }
      }
      return p->pLeft!=0 || p->pRight!=0 || (p->pList && p->pList->nExpr>0);
    }
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteExprIsInteger ( Expr ,
int  
)

Definition at line 337 of file expr.c.

                                             {
  switch( p->op ){
    case TK_INTEGER: {
      if( sqliteFitsIn32Bits(p->token.z) ){
        *pValue = atoi(p->token.z);
        return 1;
      }
      break;
    }
    case TK_STRING: {
      const char *z = p->token.z;
      int n = p->token.n;
      if( n>0 && z[0]=='-' ){ z++; n--; }
      while( n>0 && *z && isdigit(*z) ){ z++; n--; }
      if( n==0 && sqliteFitsIn32Bits(p->token.z) ){
        *pValue = atoi(p->token.z);
        return 1;
      }
      break;
    }
    case TK_UPLUS: {
      return sqliteExprIsInteger(p->pLeft, pValue);
    }
    case TK_UMINUS: {
      int v;
      if( sqliteExprIsInteger(p->pLeft, &v) ){
        *pValue = -v;
        return 1;
      }
      break;
    }
    default: break;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ExprList* sqliteExprListAppend ( ExprList ,
Expr ,
Token  
)

Definition at line 248 of file expr.c.

                                                                          {
  if( pList==0 ){
    pList = sqliteMalloc( sizeof(ExprList) );
    if( pList==0 ){
      /* sqliteExprDelete(pExpr); // Leak memory if malloc fails */
      return 0;
    }
    assert( pList->nAlloc==0 );
  }
  if( pList->nAlloc<=pList->nExpr ){
    pList->nAlloc = pList->nAlloc*2 + 4;
    pList->a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]));
    if( pList->a==0 ){
      /* sqliteExprDelete(pExpr); // Leak memory if malloc fails */
      pList->nExpr = pList->nAlloc = 0;
      return pList;
    }
  }
  assert( pList->a!=0 );
  if( pExpr || pName ){
    struct ExprList_item *pItem = &pList->a[pList->nExpr++];
    memset(pItem, 0, sizeof(*pItem));
    pItem->pExpr = pExpr;
    if( pName ){
      sqliteSetNString(&pItem->zName, pName->z, pName->n, 0);
      sqliteDequote(pItem->zName);
    }
  }
  return pList;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 282 of file expr.c.

                                          {
  int i;
  if( pList==0 ) return;
  assert( pList->a!=0 || (pList->nExpr==0 && pList->nAlloc==0) );
  assert( pList->nExpr<=pList->nAlloc );
  for(i=0; i<pList->nExpr; i++){
    sqliteExprDelete(pList->a[i].pExpr);
    sqliteFree(pList->a[i].zName);
  }
  sqliteFree(pList->a);
  sqliteFree(pList);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 149 of file expr.c.

                                        {
  ExprList *pNew;
  struct ExprList_item *pItem;
  int i;
  if( p==0 ) return 0;
  pNew = sqliteMalloc( sizeof(*pNew) );
  if( pNew==0 ) return 0;
  pNew->nExpr = pNew->nAlloc = p->nExpr;
  pNew->a = pItem = sqliteMalloc( p->nExpr*sizeof(p->a[0]) );
  if( pItem==0 ){
    sqliteFree(pNew);
    return 0;
  }
  for(i=0; i<p->nExpr; i++, pItem++){
    Expr *pNewExpr, *pOldExpr;
    pItem->pExpr = pNewExpr = sqliteExprDup(pOldExpr = p->a[i].pExpr);
    if( pOldExpr->span.z!=0 && pNewExpr ){
      /* Always make a copy of the span for top-level expressions in the
      ** expression list.  The logic in SELECT processing that determines
      ** the names of columns in the result set needs this information */
      sqliteTokenCopy(&pNewExpr->span, &pOldExpr->span);
    }
    assert( pNewExpr==0 || pNewExpr->span.z!=0 
            || pOldExpr->span.z==0 || sqlite_malloc_failed );
    pItem->zName = sqliteStrDup(p->a[i].zName);
    pItem->sortOrder = p->a[i].sortOrder;
    pItem->isAgg = p->a[i].isAgg;
    pItem->done = 0;
  }
  return pNew;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sqliteExprResolveIds ( Parse ,
SrcList ,
ExprList ,
Expr  
)

Definition at line 629 of file expr.c.

 {
  int i;

  if( pExpr==0 || pSrcList==0 ) return 0;
  for(i=0; i<pSrcList->nSrc; i++){
    assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab );
  }
  switch( pExpr->op ){
    /* Double-quoted strings (ex: "abc") are used as identifiers if
    ** possible.  Otherwise they remain as strings.  Single-quoted
    ** strings (ex: 'abc') are always string literals.
    */
    case TK_STRING: {
      if( pExpr->token.z[0]=='\'' ) break;
      /* Fall thru into the TK_ID case if this is a double-quoted string */
    }
    /* A lone identifier is the name of a columnd.
    */
    case TK_ID: {
      if( lookupName(pParse, 0, 0, &pExpr->token, pSrcList, pEList, pExpr) ){
        return 1;
      }
      break; 
    }
  
    /* A table name and column name:     ID.ID
    ** Or a database, table and column:  ID.ID.ID
    */
    case TK_DOT: {
      Token *pColumn;
      Token *pTable;
      Token *pDb;
      Expr *pRight;

      pRight = pExpr->pRight;
      if( pRight->op==TK_ID ){
        pDb = 0;
        pTable = &pExpr->pLeft->token;
        pColumn = &pRight->token;
      }else{
        assert( pRight->op==TK_DOT );
        pDb = &pExpr->pLeft->token;
        pTable = &pRight->pLeft->token;
        pColumn = &pRight->pRight->token;
      }
      if( lookupName(pParse, pDb, pTable, pColumn, pSrcList, 0, pExpr) ){
        return 1;
      }
      break;
    }

    case TK_IN: {
      Vdbe *v = sqliteGetVdbe(pParse);
      if( v==0 ) return 1;
      if( sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pLeft) ){
        return 1;
      }
      if( pExpr->pSelect ){
        /* Case 1:     expr IN (SELECT ...)
        **
        ** Generate code to write the results of the select into a temporary
        ** table.  The cursor number of the temporary table has already
        ** been put in iTable by sqliteExprResolveInSelect().
        */
        pExpr->iTable = pParse->nTab++;
        sqliteVdbeAddOp(v, OP_OpenTemp, pExpr->iTable, 1);
        sqliteSelect(pParse, pExpr->pSelect, SRT_Set, pExpr->iTable, 0,0,0);
      }else if( pExpr->pList ){
        /* Case 2:     expr IN (exprlist)
        **
        ** Create a set to put the exprlist values in.  The Set id is stored
        ** in iTable.
        */
        int i, iSet;
        for(i=0; i<pExpr->pList->nExpr; i++){
          Expr *pE2 = pExpr->pList->a[i].pExpr;
          if( !sqliteExprIsConstant(pE2) ){
            sqliteErrorMsg(pParse,
              "right-hand side of IN operator must be constant");
            return 1;
          }
          if( sqliteExprCheck(pParse, pE2, 0, 0) ){
            return 1;
          }
        }
        iSet = pExpr->iTable = pParse->nSet++;
        for(i=0; i<pExpr->pList->nExpr; i++){
          Expr *pE2 = pExpr->pList->a[i].pExpr;
          switch( pE2->op ){
            case TK_FLOAT:
            case TK_INTEGER:
            case TK_STRING: {
              int addr;
              assert( pE2->token.z );
              addr = sqliteVdbeOp3(v, OP_SetInsert, iSet, 0,
                                  pE2->token.z, pE2->token.n);
              sqliteVdbeDequoteP3(v, addr);
              break;
            }
            default: {
              sqliteExprCode(pParse, pE2);
              sqliteVdbeAddOp(v, OP_SetInsert, iSet, 0);
              break;
            }
          }
        }
      }
      break;
    }

    case TK_SELECT: {
      /* This has to be a scalar SELECT.  Generate code to put the
      ** value of this select in a memory cell and record the number
      ** of the memory cell in iColumn.
      */
      pExpr->iColumn = pParse->nMem++;
      if( sqliteSelect(pParse, pExpr->pSelect, SRT_Mem, pExpr->iColumn,0,0,0) ){
        return 1;
      }
      break;
    }

    /* For all else, just recursively walk the tree */
    default: {
      if( pExpr->pLeft
      && sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pLeft) ){
        return 1;
      }
      if( pExpr->pRight 
      && sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pRight) ){
        return 1;
      }
      if( pExpr->pList ){
        int i;
        ExprList *pList = pExpr->pList;
        for(i=0; i<pList->nExpr; i++){
          Expr *pArg = pList->a[i].pExpr;
          if( sqliteExprResolveIds(pParse, pSrcList, pEList, pArg) ){
            return 1;
          }
        }
      }
    }
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sqliteExprSpan ( Expr ,
Token ,
Token  
)

Definition at line 56 of file expr.c.

                                                             {
  assert( pRight!=0 );
  assert( pLeft!=0 );
  /* Note: pExpr might be NULL due to a prior malloc failure */
  if( pExpr && pRight->z && pLeft->z ){
    if( pLeft->dyn==0 && pRight->dyn==0 ){
      pExpr->span.z = pLeft->z;
      pExpr->span.n = pRight->n + Addr(pRight->z) - Addr(pLeft->z);
    }else{
      pExpr->span.z = 0;
    }
  }
}

Here is the caller graph for this function: