Back to index

lightning-sunbird  0.9+nobinonly
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.102 2006/03/17 13:56:34 drh 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 ** A single instruction of the virtual machine has an opcode
00033 ** and as many as three operands.  The instruction is recorded
00034 ** as an instance of the following structure:
00035 */
00036 struct VdbeOp {
00037   u8 opcode;          /* What operation to perform */
00038   int p1;             /* First operand */
00039   int p2;             /* Second parameter (often the jump destination) */
00040   char *p3;           /* Third parameter */
00041   int p3type;         /* One of the P3_xxx constants defined below */
00042 #ifdef VDBE_PROFILE
00043   int cnt;            /* Number of times this instruction was executed */
00044   long long cycles;   /* Total time spend executing this instruction */
00045 #endif
00046 };
00047 typedef struct VdbeOp VdbeOp;
00048 
00049 /*
00050 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
00051 ** it takes up less space.
00052 */
00053 struct VdbeOpList {
00054   u8 opcode;          /* What operation to perform */
00055   signed char p1;     /* First operand */
00056   short int p2;       /* Second parameter (often the jump destination) */
00057   char *p3;           /* Third parameter */
00058 };
00059 typedef struct VdbeOpList VdbeOpList;
00060 
00061 /*
00062 ** Allowed values of VdbeOp.p3type
00063 */
00064 #define P3_NOTUSED    0   /* The P3 parameter is not used */
00065 #define P3_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
00066 #define P3_STATIC   (-2)  /* Pointer to a static string */
00067 #define P3_COLLSEQ  (-4)  /* P3 is a pointer to a CollSeq structure */
00068 #define P3_FUNCDEF  (-5)  /* P3 is a pointer to a FuncDef structure */
00069 #define P3_KEYINFO  (-6)  /* P3 is a pointer to a KeyInfo structure */
00070 #define P3_VDBEFUNC (-7)  /* P3 is a pointer to a VdbeFunc structure */
00071 #define P3_MEM      (-8)  /* P3 is a pointer to a Mem*    structure */
00072 #define P3_TRANSIENT (-9)  /* P3 is a pointer to a transient string */
00073 
00074 /* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
00075 ** is made.  That copy is freed when the Vdbe is finalized.  But if the
00076 ** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used.  It still
00077 ** gets freed when the Vdbe is finalized so it still should be obtained
00078 ** from a single sqliteMalloc().  But no copy is made and the calling
00079 ** function should *not* try to free the KeyInfo.
00080 */
00081 #define P3_KEYINFO_HANDOFF (-9)
00082 
00083 /*
00084 ** The Vdbe.aColName array contains 5n Mem structures, where n is the 
00085 ** number of columns of data returned by the statement.
00086 */
00087 #define COLNAME_NAME     0
00088 #define COLNAME_DECLTYPE 1
00089 #define COLNAME_DATABASE 2
00090 #define COLNAME_TABLE    3
00091 #define COLNAME_COLUMN   4
00092 #define COLNAME_N        5      /* Number of COLNAME_xxx symbols */
00093 
00094 /*
00095 ** The following macro converts a relative address in the p2 field
00096 ** of a VdbeOp structure into a negative number so that 
00097 ** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
00098 ** the macro again restores the address.
00099 */
00100 #define ADDR(X)  (-1-(X))
00101 
00102 /*
00103 ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
00104 ** header file that defines a number for each opcode used by the VDBE.
00105 */
00106 #include "opcodes.h"
00107 
00108 /*
00109 ** Prototypes for the VDBE interface.  See comments on the implementation
00110 ** for a description of what each of these routines does.
00111 */
00112 Vdbe *sqlite3VdbeCreate(sqlite3*);
00113 void sqlite3VdbeCreateCallback(Vdbe*, int*);
00114 int sqlite3VdbeAddOp(Vdbe*,int,int,int);
00115 int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
00116 int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
00117 void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
00118 void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
00119 void sqlite3VdbeJumpHere(Vdbe*, int addr);
00120 void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
00121 void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
00122 VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
00123 int sqlite3VdbeMakeLabel(Vdbe*);
00124 void sqlite3VdbeDelete(Vdbe*);
00125 void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
00126 int sqlite3VdbeFinalize(Vdbe*);
00127 void sqlite3VdbeResolveLabel(Vdbe*, int);
00128 int sqlite3VdbeCurrentAddr(Vdbe*);
00129 void sqlite3VdbeTrace(Vdbe*,FILE*);
00130 int sqlite3VdbeReset(Vdbe*);
00131 int sqliteVdbeSetVariables(Vdbe*,int,const char**);
00132 void sqlite3VdbeSetNumCols(Vdbe*,int);
00133 int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
00134 void sqlite3VdbeCountChanges(Vdbe*);
00135 sqlite3 *sqlite3VdbeDb(Vdbe*);
00136 
00137 #ifndef NDEBUG
00138   void sqlite3VdbeComment(Vdbe*, const char*, ...);
00139 # define VdbeComment(X)  sqlite3VdbeComment X
00140 #else
00141 # define VdbeComment(X)
00142 #endif
00143 
00144 #endif