vdbe.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.115 2007/11/14 06:48:48 danielk1977 Exp $
  19. */
  20. #ifndef _SQLITE_VDBE_H_
  21. #define _SQLITE_VDBE_H_
  22. #include <stdio.h>
  23. /*
  24. ** A single VDBE is an opaque structure named "Vdbe". Only routines
  25. ** in the source file sqliteVdbe.c are allowed to see the insides
  26. ** of this structure.
  27. */
  28. typedef struct Vdbe Vdbe;
  29. /*
  30. ** A single instruction of the virtual machine has an opcode
  31. ** and as many as three operands. The instruction is recorded
  32. ** as an instance of the following structure:
  33. */
  34. struct VdbeOp {
  35. u8 opcode; /* What operation to perform */
  36. int p1; /* First operand */
  37. int p2; /* Second parameter (often the jump destination) */
  38. char *p3; /* Third parameter */
  39. int p3type; /* One of the P3_xxx constants defined below */
  40. #ifdef VDBE_PROFILE
  41. int cnt; /* Number of times this instruction was executed */
  42. long long cycles; /* Total time spend executing this instruction */
  43. #endif
  44. };
  45. typedef struct VdbeOp VdbeOp;
  46. /*
  47. ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
  48. ** it takes up less space.
  49. */
  50. struct VdbeOpList {
  51. u8 opcode; /* What operation to perform */
  52. signed char p1; /* First operand */
  53. short int p2; /* Second parameter (often the jump destination) */
  54. char *p3; /* Third parameter */
  55. };
  56. typedef struct VdbeOpList VdbeOpList;
  57. /*
  58. ** Allowed values of VdbeOp.p3type
  59. */
  60. #define P3_NOTUSED 0 /* The P3 parameter is not used */
  61. #define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
  62. #define P3_STATIC (-2) /* Pointer to a static string */
  63. #define P3_COLLSEQ (-4) /* P3 is a pointer to a CollSeq structure */
  64. #define P3_FUNCDEF (-5) /* P3 is a pointer to a FuncDef structure */
  65. #define P3_KEYINFO (-6) /* P3 is a pointer to a KeyInfo structure */
  66. #define P3_VDBEFUNC (-7) /* P3 is a pointer to a VdbeFunc structure */
  67. #define P3_MEM (-8) /* P3 is a pointer to a Mem* structure */
  68. #define P3_TRANSIENT (-9) /* P3 is a pointer to a transient string */
  69. #define P3_VTAB (-10) /* P3 is a pointer to an sqlite3_vtab structure */
  70. #define P3_MPRINTF (-11) /* P3 is a string obtained from sqlite3_mprintf() */
  71. #define P3_REAL (-12) /* P3 is a 64-bit floating point value */
  72. #define P3_INT64 (-13) /* P3 is a 64-bit signed integer */
  73. /* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
  74. ** is made. That copy is freed when the Vdbe is finalized. But if the
  75. ** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used. It still
  76. ** gets freed when the Vdbe is finalized so it still should be obtained
  77. ** from a single sqliteMalloc(). But no copy is made and the calling
  78. ** function should *not* try to free the KeyInfo.
  79. */
  80. #define P3_KEYINFO_HANDOFF (-9)
  81. /*
  82. ** The Vdbe.aColName array contains 5n Mem structures, where n is the
  83. ** number of columns of data returned by the statement.
  84. */
  85. #define COLNAME_NAME 0
  86. #define COLNAME_DECLTYPE 1
  87. #define COLNAME_DATABASE 2
  88. #define COLNAME_TABLE 3
  89. #define COLNAME_COLUMN 4
  90. #define COLNAME_N 5 /* Number of COLNAME_xxx symbols */
  91. /*
  92. ** The following macro converts a relative address in the p2 field
  93. ** of a VdbeOp structure into a negative number so that
  94. ** sqlite3VdbeAddOpList() knows that the address is relative. Calling
  95. ** the macro again restores the address.
  96. */
  97. #define ADDR(X) (-1-(X))
  98. /*
  99. ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
  100. ** header file that defines a number for each opcode used by the VDBE.
  101. */
  102. #include "opcodes.h"
  103. /*
  104. ** Prototypes for the VDBE interface. See comments on the implementation
  105. ** for a description of what each of these routines does.
  106. */
  107. Vdbe *sqlite3VdbeCreate(sqlite3*);
  108. int sqlite3VdbeAddOp(Vdbe*,int,int,int);
  109. int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
  110. int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
  111. void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
  112. void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
  113. void sqlite3VdbeJumpHere(Vdbe*, int addr);
  114. void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
  115. void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
  116. void sqlite3VdbeUsesBtree(Vdbe*, int);
  117. VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
  118. int sqlite3VdbeMakeLabel(Vdbe*);
  119. void sqlite3VdbeDelete(Vdbe*);
  120. void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
  121. int sqlite3VdbeFinalize(Vdbe*);
  122. void sqlite3VdbeResolveLabel(Vdbe*, int);
  123. int sqlite3VdbeCurrentAddr(Vdbe*);
  124. #ifdef SQLITE_DEBUG
  125. void sqlite3VdbeTrace(Vdbe*,FILE*);
  126. #endif
  127. void sqlite3VdbeResetStepResult(Vdbe*);
  128. int sqlite3VdbeReset(Vdbe*);
  129. void sqlite3VdbeSetNumCols(Vdbe*,int);
  130. int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
  131. void sqlite3VdbeCountChanges(Vdbe*);
  132. sqlite3 *sqlite3VdbeDb(Vdbe*);
  133. void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
  134. void sqlite3VdbeSwap(Vdbe*,Vdbe*);
  135. #ifndef NDEBUG
  136. void sqlite3VdbeComment(Vdbe*, const char*, ...);
  137. # define VdbeComment(X) sqlite3VdbeComment X
  138. #else
  139. # define VdbeComment(X)
  140. #endif
  141. #endif