vdbe.h

Go to the documentation of this file.
00001 /*
00002 ** 2001 September 15
00003 **
00004 ** The author disclaims copyright to this source code.  In place of
00005 ** a legal notice, here is a blessing:
00006 **
00007 **    May you do good and not evil.
00008 **    May you find forgiveness for yourself and forgive others.
00009 **    May you share freely, never taking more than you give.
00010 **
00011 *************************************************************************
00012 ** Header file for the Virtual DataBase Engine (VDBE)
00013 **
00014 ** This header defines the interface to the virtual database engine
00015 ** or VDBE.  The VDBE implements an abstract machine that runs a
00016 ** simple program to access and modify the underlying database.
00017 **
00018 ** $Id: vdbe.h,v 1.139 2008/10/31 10:53:23 danielk1977 Exp $
00019 */
00020 #ifndef _SQLITE_VDBE_H_
00021 #define _SQLITE_VDBE_H_
00022 #include <stdio.h>
00023 
00024 /*
00025 ** A single VDBE is an opaque structure named "Vdbe".  Only routines
00026 ** in the source file sqliteVdbe.c are allowed to see the insides
00027 ** of this structure.
00028 */
00029 typedef struct Vdbe Vdbe;
00030 
00031 /*
00032 ** The names of the following types declared in vdbeInt.h are required
00033 ** for the VdbeOp definition.
00034 */
00035 typedef struct VdbeFunc VdbeFunc;
00036 typedef struct Mem Mem;
00037 
00038 /*
00039 ** A single instruction of the virtual machine has an opcode
00040 ** and as many as three operands.  The instruction is recorded
00041 ** as an instance of the following structure:
00042 */
00043 struct VdbeOp {
00044   u8 opcode;          /* What operation to perform */
00045   signed char p4type; /* One of the P4_xxx constants for p4 */
00046   u8 opflags;         /* Not currently used */
00047   u8 p5;              /* Fifth parameter is an unsigned character */
00048   int p1;             /* First operand */
00049   int p2;             /* Second parameter (often the jump destination) */
00050   int p3;             /* The third parameter */
00051   union {             /* forth parameter */
00052     int i;                 /* Integer value if p4type==P4_INT32 */
00053     void *p;               /* Generic pointer */
00054     char *z;               /* Pointer to data for string (char array) types */
00055     i64 *pI64;             /* Used when p4type is P4_INT64 */
00056     double *pReal;         /* Used when p4type is P4_REAL */
00057     FuncDef *pFunc;        /* Used when p4type is P4_FUNCDEF */
00058     VdbeFunc *pVdbeFunc;   /* Used when p4type is P4_VDBEFUNC */
00059     CollSeq *pColl;        /* Used when p4type is P4_COLLSEQ */
00060     Mem *pMem;             /* Used when p4type is P4_MEM */
00061     sqlite3_vtab *pVtab;   /* Used when p4type is P4_VTAB */
00062     KeyInfo *pKeyInfo;     /* Used when p4type is P4_KEYINFO */
00063     int *ai;               /* Used when p4type is P4_INTARRAY */
00064   } p4;
00065 #ifdef SQLITE_DEBUG
00066   char *zComment;          /* Comment to improve readability */
00067 #endif
00068 #ifdef VDBE_PROFILE
00069   int cnt;                 /* Number of times this instruction was executed */
00070   u64 cycles;              /* Total time spent executing this instruction */
00071 #endif
00072 };
00073 typedef struct VdbeOp VdbeOp;
00074 
00075 /*
00076 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
00077 ** it takes up less space.
00078 */
00079 struct VdbeOpList {
00080   u8 opcode;          /* What operation to perform */
00081   signed char p1;     /* First operand */
00082   signed char p2;     /* Second parameter (often the jump destination) */
00083   signed char p3;     /* Third parameter */
00084 };
00085 typedef struct VdbeOpList VdbeOpList;
00086 
00087 /*
00088 ** Allowed values of VdbeOp.p3type
00089 */
00090 #define P4_NOTUSED    0   /* The P4 parameter is not used */
00091 #define P4_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
00092 #define P4_STATIC   (-2)  /* Pointer to a static string */
00093 #define P4_COLLSEQ  (-4)  /* P4 is a pointer to a CollSeq structure */
00094 #define P4_FUNCDEF  (-5)  /* P4 is a pointer to a FuncDef structure */
00095 #define P4_KEYINFO  (-6)  /* P4 is a pointer to a KeyInfo structure */
00096 #define P4_VDBEFUNC (-7)  /* P4 is a pointer to a VdbeFunc structure */
00097 #define P4_MEM      (-8)  /* P4 is a pointer to a Mem*    structure */
00098 #define P4_TRANSIENT (-9) /* P4 is a pointer to a transient string */
00099 #define P4_VTAB     (-10) /* P4 is a pointer to an sqlite3_vtab structure */
00100 #define P4_MPRINTF  (-11) /* P4 is a string obtained from sqlite3_mprintf() */
00101 #define P4_REAL     (-12) /* P4 is a 64-bit floating point value */
00102 #define P4_INT64    (-13) /* P4 is a 64-bit signed integer */
00103 #define P4_INT32    (-14) /* P4 is a 32-bit signed integer */
00104 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
00105 
00106 /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure
00107 ** is made.  That copy is freed when the Vdbe is finalized.  But if the
00108 ** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used.  It still
00109 ** gets freed when the Vdbe is finalized so it still should be obtained
00110 ** from a single sqliteMalloc().  But no copy is made and the calling
00111 ** function should *not* try to free the KeyInfo.
00112 */
00113 #define P4_KEYINFO_HANDOFF (-16)
00114 #define P4_KEYINFO_STATIC  (-17)
00115 
00116 /*
00117 ** The Vdbe.aColName array contains 5n Mem structures, where n is the 
00118 ** number of columns of data returned by the statement.
00119 */
00120 #define COLNAME_NAME     0
00121 #define COLNAME_DECLTYPE 1
00122 #define COLNAME_DATABASE 2
00123 #define COLNAME_TABLE    3
00124 #define COLNAME_COLUMN   4
00125 #ifdef SQLITE_ENABLE_COLUMN_METADATA
00126 # define COLNAME_N        5      /* Number of COLNAME_xxx symbols */
00127 #else
00128 # ifdef SQLITE_OMIT_DECLTYPE
00129 #   define COLNAME_N      1      /* Store only the name */
00130 # else
00131 #   define COLNAME_N      2      /* Store the name and decltype */
00132 # endif
00133 #endif
00134 
00135 /*
00136 ** The following macro converts a relative address in the p2 field
00137 ** of a VdbeOp structure into a negative number so that 
00138 ** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
00139 ** the macro again restores the address.
00140 */
00141 #define ADDR(X)  (-1-(X))
00142 
00143 /*
00144 ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
00145 ** header file that defines a number for each opcode used by the VDBE.
00146 */
00147 #include "opcodes.h"
00148 
00149 /*
00150 ** Prototypes for the VDBE interface.  See comments on the implementation
00151 ** for a description of what each of these routines does.
00152 */
00153 Vdbe *sqlite3VdbeCreate(sqlite3*);
00154 int sqlite3VdbeAddOp0(Vdbe*,int);
00155 int sqlite3VdbeAddOp1(Vdbe*,int,int);
00156 int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
00157 int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
00158 int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
00159 int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
00160 void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
00161 void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
00162 void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
00163 void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
00164 void sqlite3VdbeJumpHere(Vdbe*, int addr);
00165 void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
00166 void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
00167 void sqlite3VdbeUsesBtree(Vdbe*, int);
00168 VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
00169 int sqlite3VdbeMakeLabel(Vdbe*);
00170 void sqlite3VdbeDelete(Vdbe*);
00171 void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
00172 int sqlite3VdbeFinalize(Vdbe*);
00173 void sqlite3VdbeResolveLabel(Vdbe*, int);
00174 int sqlite3VdbeCurrentAddr(Vdbe*);
00175 #ifdef SQLITE_DEBUG
00176   void sqlite3VdbeTrace(Vdbe*,FILE*);
00177 #endif
00178 void sqlite3VdbeResetStepResult(Vdbe*);
00179 int sqlite3VdbeReset(Vdbe*);
00180 void sqlite3VdbeSetNumCols(Vdbe*,int);
00181 int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
00182 void sqlite3VdbeCountChanges(Vdbe*);
00183 sqlite3 *sqlite3VdbeDb(Vdbe*);
00184 void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
00185 void sqlite3VdbeSwap(Vdbe*,Vdbe*);
00186 
00187 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
00188 int sqlite3VdbeReleaseMemory(int);
00189 #endif
00190 UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,
00191                                         UnpackedRecord*,int);
00192 void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord*);
00193 int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
00194 
00195 
00196 #ifndef NDEBUG
00197   void sqlite3VdbeComment(Vdbe*, const char*, ...);
00198 # define VdbeComment(X)  sqlite3VdbeComment X
00199   void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
00200 # define VdbeNoopComment(X)  sqlite3VdbeNoopComment X
00201 #else
00202 # define VdbeComment(X)
00203 # define VdbeNoopComment(X)
00204 #endif
00205 
00206 #endif

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1