persistentstorage/sql/SQLite364/vdbe.h
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 /*
       
     2 ** 2001 September 15
       
     3 **
       
     4 ** The author disclaims copyright to this source code.  In place of
       
     5 ** a legal notice, here is a blessing:
       
     6 **
       
     7 **    May you do good and not evil.
       
     8 **    May you find forgiveness for yourself and forgive others.
       
     9 **    May you share freely, never taking more than you give.
       
    10 **
       
    11 *************************************************************************
       
    12 ** Header file for the Virtual DataBase Engine (VDBE)
       
    13 **
       
    14 ** This header defines the interface to the virtual database engine
       
    15 ** or VDBE.  The VDBE implements an abstract machine that runs a
       
    16 ** simple program to access and modify the underlying database.
       
    17 **
       
    18 ** $Id: vdbe.h,v 1.138 2008/08/20 22:06:48 drh Exp $
       
    19 */
       
    20 #ifndef _SQLITE_VDBE_H_
       
    21 #define _SQLITE_VDBE_H_
       
    22 #include <stdio.h>
       
    23 
       
    24 /*
       
    25 ** A single VDBE is an opaque structure named "Vdbe".  Only routines
       
    26 ** in the source file sqliteVdbe.c are allowed to see the insides
       
    27 ** of this structure.
       
    28 */
       
    29 typedef struct Vdbe Vdbe;
       
    30 
       
    31 /*
       
    32 ** The names of the following types declared in vdbeInt.h are required
       
    33 ** for the VdbeOp definition.
       
    34 */
       
    35 typedef struct VdbeFunc VdbeFunc;
       
    36 typedef struct Mem Mem;
       
    37 
       
    38 /*
       
    39 ** A single instruction of the virtual machine has an opcode
       
    40 ** and as many as three operands.  The instruction is recorded
       
    41 ** as an instance of the following structure:
       
    42 */
       
    43 struct VdbeOp {
       
    44   u8 opcode;          /* What operation to perform */
       
    45   signed char p4type; /* One of the P4_xxx constants for p4 */
       
    46   u8 opflags;         /* Not currently used */
       
    47   u8 p5;              /* Fifth parameter is an unsigned character */
       
    48   int p1;             /* First operand */
       
    49   int p2;             /* Second parameter (often the jump destination) */
       
    50   int p3;             /* The third parameter */
       
    51   union {             /* forth parameter */
       
    52     int i;                 /* Integer value if p4type==P4_INT32 */
       
    53     void *p;               /* Generic pointer */
       
    54     char *z;               /* Pointer to data for string (char array) types */
       
    55     i64 *pI64;             /* Used when p4type is P4_INT64 */
       
    56     double *pReal;         /* Used when p4type is P4_REAL */
       
    57     FuncDef *pFunc;        /* Used when p4type is P4_FUNCDEF */
       
    58     VdbeFunc *pVdbeFunc;   /* Used when p4type is P4_VDBEFUNC */
       
    59     CollSeq *pColl;        /* Used when p4type is P4_COLLSEQ */
       
    60     Mem *pMem;             /* Used when p4type is P4_MEM */
       
    61     sqlite3_vtab *pVtab;   /* Used when p4type is P4_VTAB */
       
    62     KeyInfo *pKeyInfo;     /* Used when p4type is P4_KEYINFO */
       
    63     int *ai;               /* Used when p4type is P4_INTARRAY */
       
    64   } p4;
       
    65 #ifdef SQLITE_DEBUG
       
    66   char *zComment;          /* Comment to improve readability */
       
    67 #endif
       
    68 #ifdef VDBE_PROFILE
       
    69   int cnt;                 /* Number of times this instruction was executed */
       
    70   u64 cycles;              /* Total time spent executing this instruction */
       
    71 #endif
       
    72 };
       
    73 typedef struct VdbeOp VdbeOp;
       
    74 
       
    75 /*
       
    76 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
       
    77 ** it takes up less space.
       
    78 */
       
    79 struct VdbeOpList {
       
    80   u8 opcode;          /* What operation to perform */
       
    81   signed char p1;     /* First operand */
       
    82   signed char p2;     /* Second parameter (often the jump destination) */
       
    83   signed char p3;     /* Third parameter */
       
    84 };
       
    85 typedef struct VdbeOpList VdbeOpList;
       
    86 
       
    87 /*
       
    88 ** Allowed values of VdbeOp.p3type
       
    89 */
       
    90 #define P4_NOTUSED    0   /* The P4 parameter is not used */
       
    91 #define P4_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
       
    92 #define P4_STATIC   (-2)  /* Pointer to a static string */
       
    93 #define P4_COLLSEQ  (-4)  /* P4 is a pointer to a CollSeq structure */
       
    94 #define P4_FUNCDEF  (-5)  /* P4 is a pointer to a FuncDef structure */
       
    95 #define P4_KEYINFO  (-6)  /* P4 is a pointer to a KeyInfo structure */
       
    96 #define P4_VDBEFUNC (-7)  /* P4 is a pointer to a VdbeFunc structure */
       
    97 #define P4_MEM      (-8)  /* P4 is a pointer to a Mem*    structure */
       
    98 #define P4_TRANSIENT (-9) /* P4 is a pointer to a transient string */
       
    99 #define P4_VTAB     (-10) /* P4 is a pointer to an sqlite3_vtab structure */
       
   100 #define P4_MPRINTF  (-11) /* P4 is a string obtained from sqlite3_mprintf() */
       
   101 #define P4_REAL     (-12) /* P4 is a 64-bit floating point value */
       
   102 #define P4_INT64    (-13) /* P4 is a 64-bit signed integer */
       
   103 #define P4_INT32    (-14) /* P4 is a 32-bit signed integer */
       
   104 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
       
   105 
       
   106 /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure
       
   107 ** is made.  That copy is freed when the Vdbe is finalized.  But if the
       
   108 ** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used.  It still
       
   109 ** gets freed when the Vdbe is finalized so it still should be obtained
       
   110 ** from a single sqliteMalloc().  But no copy is made and the calling
       
   111 ** function should *not* try to free the KeyInfo.
       
   112 */
       
   113 #define P4_KEYINFO_HANDOFF (-16)
       
   114 #define P4_KEYINFO_STATIC  (-17)
       
   115 
       
   116 /*
       
   117 ** The Vdbe.aColName array contains 5n Mem structures, where n is the 
       
   118 ** number of columns of data returned by the statement.
       
   119 */
       
   120 #define COLNAME_NAME     0
       
   121 #define COLNAME_DECLTYPE 1
       
   122 #define COLNAME_DATABASE 2
       
   123 #define COLNAME_TABLE    3
       
   124 #define COLNAME_COLUMN   4
       
   125 #ifdef SQLITE_ENABLE_COLUMN_METADATA
       
   126 # define COLNAME_N        5      /* Number of COLNAME_xxx symbols */
       
   127 #else
       
   128 # ifdef SQLITE_OMIT_DECLTYPE
       
   129 #   define COLNAME_N      1      /* Store only the name */
       
   130 # else
       
   131 #   define COLNAME_N      2      /* Store the name and decltype */
       
   132 # endif
       
   133 #endif
       
   134 
       
   135 /*
       
   136 ** The following macro converts a relative address in the p2 field
       
   137 ** of a VdbeOp structure into a negative number so that 
       
   138 ** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
       
   139 ** the macro again restores the address.
       
   140 */
       
   141 #define ADDR(X)  (-1-(X))
       
   142 
       
   143 /*
       
   144 ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
       
   145 ** header file that defines a number for each opcode used by the VDBE.
       
   146 */
       
   147 #include "opcodes.h"
       
   148 
       
   149 /*
       
   150 ** Prototypes for the VDBE interface.  See comments on the implementation
       
   151 ** for a description of what each of these routines does.
       
   152 */
       
   153 Vdbe *sqlite3VdbeCreate(sqlite3*);
       
   154 int sqlite3VdbeAddOp0(Vdbe*,int);
       
   155 int sqlite3VdbeAddOp1(Vdbe*,int,int);
       
   156 int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
       
   157 int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
       
   158 int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
       
   159 int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
       
   160 void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
       
   161 void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
       
   162 void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
       
   163 void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
       
   164 void sqlite3VdbeJumpHere(Vdbe*, int addr);
       
   165 void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
       
   166 void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
       
   167 void sqlite3VdbeUsesBtree(Vdbe*, int);
       
   168 VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
       
   169 int sqlite3VdbeMakeLabel(Vdbe*);
       
   170 void sqlite3VdbeDelete(Vdbe*);
       
   171 void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
       
   172 int sqlite3VdbeFinalize(Vdbe*);
       
   173 void sqlite3VdbeResolveLabel(Vdbe*, int);
       
   174 int sqlite3VdbeCurrentAddr(Vdbe*);
       
   175 #ifdef SQLITE_DEBUG
       
   176   void sqlite3VdbeTrace(Vdbe*,FILE*);
       
   177 #endif
       
   178 void sqlite3VdbeResetStepResult(Vdbe*);
       
   179 int sqlite3VdbeReset(Vdbe*);
       
   180 void sqlite3VdbeSetNumCols(Vdbe*,int);
       
   181 int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
       
   182 void sqlite3VdbeCountChanges(Vdbe*);
       
   183 sqlite3 *sqlite3VdbeDb(Vdbe*);
       
   184 void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
       
   185 void sqlite3VdbeSwap(Vdbe*,Vdbe*);
       
   186 
       
   187 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
       
   188 int sqlite3VdbeReleaseMemory(int);
       
   189 #endif
       
   190 UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,
       
   191                                         UnpackedRecord*,int);
       
   192 void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord*);
       
   193 int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
       
   194 
       
   195 
       
   196 #ifndef NDEBUG
       
   197   void sqlite3VdbeComment(Vdbe*, const char*, ...);
       
   198 # define VdbeComment(X)  sqlite3VdbeComment X
       
   199   void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
       
   200 # define VdbeNoopComment(X)  sqlite3VdbeNoopComment X
       
   201 #else
       
   202 # define VdbeComment(X)
       
   203 # define VdbeNoopComment(X)
       
   204 #endif
       
   205 
       
   206 #endif