extensions/sqlite/sqlite-source/vdbe.h
author Asher Baker <asherkin@gmail.com>
Thu Apr 26 16:58:18 2012 +0100 (2012-04-26)
changeset 3488 bee90c8ef6c3
parent 1952 b7aa2b626807
permissions -rw-r--r--
Fixed client serials not being unique on Windows (bug 5285, r=psychonic).
ds@1952
     1
/*
ds@1952
     2
** 2001 September 15
ds@1952
     3
**
ds@1952
     4
** The author disclaims copyright to this source code.  In place of
ds@1952
     5
** a legal notice, here is a blessing:
ds@1952
     6
**
ds@1952
     7
**    May you do good and not evil.
ds@1952
     8
**    May you find forgiveness for yourself and forgive others.
ds@1952
     9
**    May you share freely, never taking more than you give.
ds@1952
    10
**
ds@1952
    11
*************************************************************************
ds@1952
    12
** Header file for the Virtual DataBase Engine (VDBE)
ds@1952
    13
**
ds@1952
    14
** This header defines the interface to the virtual database engine
ds@1952
    15
** or VDBE.  The VDBE implements an abstract machine that runs a
ds@1952
    16
** simple program to access and modify the underlying database.
ds@1952
    17
**
ds@1952
    18
** $Id$
ds@1952
    19
*/
ds@1952
    20
#ifndef _SQLITE_VDBE_H_
ds@1952
    21
#define _SQLITE_VDBE_H_
ds@1952
    22
#include <stdio.h>
ds@1952
    23
ds@1952
    24
/*
ds@1952
    25
** A single VDBE is an opaque structure named "Vdbe".  Only routines
ds@1952
    26
** in the source file sqliteVdbe.c are allowed to see the insides
ds@1952
    27
** of this structure.
ds@1952
    28
*/
ds@1952
    29
typedef struct Vdbe Vdbe;
ds@1952
    30
ds@1952
    31
/*
ds@1952
    32
** A single instruction of the virtual machine has an opcode
ds@1952
    33
** and as many as three operands.  The instruction is recorded
ds@1952
    34
** as an instance of the following structure:
ds@1952
    35
*/
ds@1952
    36
struct VdbeOp {
ds@1952
    37
  u8 opcode;          /* What operation to perform */
ds@1952
    38
  int p1;             /* First operand */
ds@1952
    39
  int p2;             /* Second parameter (often the jump destination) */
ds@1952
    40
  char *p3;           /* Third parameter */
ds@1952
    41
  int p3type;         /* One of the P3_xxx constants defined below */
ds@1952
    42
#ifdef VDBE_PROFILE
ds@1952
    43
  int cnt;            /* Number of times this instruction was executed */
ds@1952
    44
  long long cycles;   /* Total time spend executing this instruction */
ds@1952
    45
#endif
ds@1952
    46
};
ds@1952
    47
typedef struct VdbeOp VdbeOp;
ds@1952
    48
ds@1952
    49
/*
ds@1952
    50
** A smaller version of VdbeOp used for the VdbeAddOpList() function because
ds@1952
    51
** it takes up less space.
ds@1952
    52
*/
ds@1952
    53
struct VdbeOpList {
ds@1952
    54
  u8 opcode;          /* What operation to perform */
ds@1952
    55
  signed char p1;     /* First operand */
ds@1952
    56
  short int p2;       /* Second parameter (often the jump destination) */
ds@1952
    57
  char *p3;           /* Third parameter */
ds@1952
    58
};
ds@1952
    59
typedef struct VdbeOpList VdbeOpList;
ds@1952
    60
ds@1952
    61
/*
ds@1952
    62
** Allowed values of VdbeOp.p3type
ds@1952
    63
*/
ds@1952
    64
#define P3_NOTUSED    0   /* The P3 parameter is not used */
ds@1952
    65
#define P3_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
ds@1952
    66
#define P3_STATIC   (-2)  /* Pointer to a static string */
ds@1952
    67
#define P3_COLLSEQ  (-4)  /* P3 is a pointer to a CollSeq structure */
ds@1952
    68
#define P3_FUNCDEF  (-5)  /* P3 is a pointer to a FuncDef structure */
ds@1952
    69
#define P3_KEYINFO  (-6)  /* P3 is a pointer to a KeyInfo structure */
ds@1952
    70
#define P3_VDBEFUNC (-7)  /* P3 is a pointer to a VdbeFunc structure */
ds@1952
    71
#define P3_MEM      (-8)  /* P3 is a pointer to a Mem*    structure */
ds@1952
    72
#define P3_TRANSIENT (-9) /* P3 is a pointer to a transient string */
ds@1952
    73
#define P3_VTAB     (-10) /* P3 is a pointer to an sqlite3_vtab structure */
ds@1952
    74
#define P3_MPRINTF  (-11) /* P3 is a string obtained from sqlite3_mprintf() */
ds@1952
    75
ds@1952
    76
/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
ds@1952
    77
** is made.  That copy is freed when the Vdbe is finalized.  But if the
ds@1952
    78
** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used.  It still
ds@1952
    79
** gets freed when the Vdbe is finalized so it still should be obtained
ds@1952
    80
** from a single sqliteMalloc().  But no copy is made and the calling
ds@1952
    81
** function should *not* try to free the KeyInfo.
ds@1952
    82
*/
ds@1952
    83
#define P3_KEYINFO_HANDOFF (-9)
ds@1952
    84
ds@1952
    85
/*
ds@1952
    86
** The Vdbe.aColName array contains 5n Mem structures, where n is the 
ds@1952
    87
** number of columns of data returned by the statement.
ds@1952
    88
*/
ds@1952
    89
#define COLNAME_NAME     0
ds@1952
    90
#define COLNAME_DECLTYPE 1
ds@1952
    91
#define COLNAME_DATABASE 2
ds@1952
    92
#define COLNAME_TABLE    3
ds@1952
    93
#define COLNAME_COLUMN   4
ds@1952
    94
#define COLNAME_N        5      /* Number of COLNAME_xxx symbols */
ds@1952
    95
ds@1952
    96
/*
ds@1952
    97
** The following macro converts a relative address in the p2 field
ds@1952
    98
** of a VdbeOp structure into a negative number so that 
ds@1952
    99
** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
ds@1952
   100
** the macro again restores the address.
ds@1952
   101
*/
ds@1952
   102
#define ADDR(X)  (-1-(X))
ds@1952
   103
ds@1952
   104
/*
ds@1952
   105
** The makefile scans the vdbe.c source file and creates the "opcodes.h"
ds@1952
   106
** header file that defines a number for each opcode used by the VDBE.
ds@1952
   107
*/
ds@1952
   108
#include "opcodes.h"
ds@1952
   109
ds@1952
   110
/*
ds@1952
   111
** Prototypes for the VDBE interface.  See comments on the implementation
ds@1952
   112
** for a description of what each of these routines does.
ds@1952
   113
*/
ds@1952
   114
Vdbe *sqlite3VdbeCreate(sqlite3*);
ds@1952
   115
int sqlite3VdbeAddOp(Vdbe*,int,int,int);
ds@1952
   116
int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
ds@1952
   117
int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
ds@1952
   118
void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
ds@1952
   119
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
ds@1952
   120
void sqlite3VdbeJumpHere(Vdbe*, int addr);
ds@1952
   121
void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
ds@1952
   122
void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
ds@1952
   123
void sqlite3VdbeUsesBtree(Vdbe*, int);
ds@1952
   124
VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
ds@1952
   125
int sqlite3VdbeMakeLabel(Vdbe*);
ds@1952
   126
void sqlite3VdbeDelete(Vdbe*);
ds@1952
   127
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
ds@1952
   128
int sqlite3VdbeFinalize(Vdbe*);
ds@1952
   129
void sqlite3VdbeResolveLabel(Vdbe*, int);
ds@1952
   130
int sqlite3VdbeCurrentAddr(Vdbe*);
ds@1952
   131
#ifdef SQLITE_DEBUG
ds@1952
   132
  void sqlite3VdbeTrace(Vdbe*,FILE*);
ds@1952
   133
#endif
ds@1952
   134
void sqlite3VdbeResetStepResult(Vdbe*);
ds@1952
   135
int sqlite3VdbeReset(Vdbe*);
ds@1952
   136
void sqlite3VdbeSetNumCols(Vdbe*,int);
ds@1952
   137
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
ds@1952
   138
void sqlite3VdbeCountChanges(Vdbe*);
ds@1952
   139
sqlite3 *sqlite3VdbeDb(Vdbe*);
ds@1952
   140
void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
ds@1952
   141
const char *sqlite3VdbeGetSql(Vdbe*);
ds@1952
   142
void sqlite3VdbeSwap(Vdbe*,Vdbe*);
ds@1952
   143
ds@1952
   144
#ifndef NDEBUG
ds@1952
   145
  void sqlite3VdbeComment(Vdbe*, const char*, ...);
ds@1952
   146
# define VdbeComment(X)  sqlite3VdbeComment X
ds@1952
   147
#else
ds@1952
   148
# define VdbeComment(X)
ds@1952
   149
#endif
ds@1952
   150
ds@1952
   151
#endif