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