annotate sqlite/vdbe.c @ 1453:1c0cd95ef1ed trunk

[svn] - fix nemo's bug
author nenolod
date Fri, 28 Jul 2006 14:12:59 -0700
parents b6b61becdf4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1434
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2 ** 2001 September 15
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4 ** The author disclaims copyright to this source code. In place of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
5 ** a legal notice, here is a blessing:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
6 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
7 ** May you do good and not evil.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
8 ** May you find forgiveness for yourself and forgive others.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
9 ** May you share freely, never taking more than you give.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
10 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
11 *************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
12 ** The code in this file implements execution method of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
13 ** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c")
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
14 ** handles housekeeping details such as creating and deleting
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
15 ** VDBE instances. This file is solely interested in executing
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
16 ** the VDBE program.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
17 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
18 ** In the external interface, an "sqlite3_stmt*" is an opaque pointer
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
19 ** to a VDBE.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
20 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
21 ** The SQL parser generates a program which is then executed by
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
22 ** the VDBE to do the work of the SQL statement. VDBE programs are
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
23 ** similar in form to assembly language. The program consists of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
24 ** a linear sequence of operations. Each operation has an opcode
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
25 ** and 3 operands. Operands P1 and P2 are integers. Operand P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
26 ** is a null-terminated string. The P2 operand must be non-negative.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
27 ** Opcodes will typically ignore one or more operands. Many opcodes
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
28 ** ignore all three operands.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
29 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
30 ** Computation results are stored on a stack. Each entry on the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
31 ** stack is either an integer, a null-terminated string, a floating point
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
32 ** number, or the SQL "NULL" value. An inplicit conversion from one
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
33 ** type to the other occurs as necessary.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
34 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
35 ** Most of the code in this file is taken up by the sqlite3VdbeExec()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
36 ** function which does the work of interpreting a VDBE program.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
37 ** But other routines are also provided to help in building up
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
38 ** a program instruction by instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
39 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
40 ** Various scripts scan this source file in order to generate HTML
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
41 ** documentation, headers files, or other derived files. The formatting
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
42 ** of the code in this file is, therefore, important. See other comments
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
43 ** in this file for details. If in doubt, do not deviate from existing
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
44 ** commenting and indentation practices when changing or adding code.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
45 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
46 ** $Id: vdbe.c,v 1.550 2006/06/03 18:04:17 drh Exp $
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
47 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
48 #include "sqliteInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
49 #include "os.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
50 #include <ctype.h>
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
51 #include "vdbeInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
52
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
53 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
54 ** The following global variable is incremented every time a cursor
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
55 ** moves, either by the OP_MoveXX, OP_Next, or OP_Prev opcodes. The test
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
56 ** procedures use this information to make sure that indices are
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
57 ** working correctly. This variable has no function other than to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
58 ** help verify the correct operation of the library.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
59 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
60 int sqlite3_search_count = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
61
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
62 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
63 ** When this global variable is positive, it gets decremented once before
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
64 ** each instruction in the VDBE. When reaches zero, the SQLITE_Interrupt
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
65 ** of the db.flags field is set in order to simulate and interrupt.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
66 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
67 ** This facility is used for testing purposes only. It does not function
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
68 ** in an ordinary build.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
69 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
70 int sqlite3_interrupt_count = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
71
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
72 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
73 ** The next global variable is incremented each type the OP_Sort opcode
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
74 ** is executed. The test procedures use this information to make sure that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
75 ** sorting is occurring or not occuring at appropriate times. This variable
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
76 ** has no function other than to help verify the correct operation of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
77 ** library.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
78 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
79 int sqlite3_sort_count = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
80
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
81 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
82 ** Release the memory associated with the given stack level. This
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
83 ** leaves the Mem.flags field in an inconsistent state.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
84 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
85 #define Release(P) if((P)->flags&MEM_Dyn){ sqlite3VdbeMemRelease(P); }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
86
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
87 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
88 ** Convert the given stack entity into a string if it isn't one
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
89 ** already. Return non-zero if a malloc() fails.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
90 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
91 #define Stringify(P, enc) \
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
92 if(((P)->flags&(MEM_Str|MEM_Blob))==0 && sqlite3VdbeMemStringify(P,enc)) \
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
93 { goto no_mem; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
94
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
95 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
96 ** Convert the given stack entity into a string that has been obtained
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
97 ** from sqliteMalloc(). This is different from Stringify() above in that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
98 ** Stringify() will use the NBFS bytes of static string space if the string
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
99 ** will fit but this routine always mallocs for space.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
100 ** Return non-zero if we run out of memory.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
101 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
102 #define Dynamicify(P,enc) sqlite3VdbeMemDynamicify(P)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
103
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
104 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
105 ** The header of a record consists of a sequence variable-length integers.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
106 ** These integers are almost always small and are encoded as a single byte.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
107 ** The following macro takes advantage this fact to provide a fast decode
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
108 ** of the integers in a record header. It is faster for the common case
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
109 ** where the integer is a single byte. It is a little slower when the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
110 ** integer is two or more bytes. But overall it is faster.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
111 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
112 ** The following expressions are equivalent:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
113 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
114 ** x = sqlite3GetVarint32( A, &B );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
115 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
116 ** x = GetVarint( A, B );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
117 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
118 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
119 #define GetVarint(A,B) ((B = *(A))<=0x7f ? 1 : sqlite3GetVarint32(A, &B))
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
120
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
121 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
122 ** An ephemeral string value (signified by the MEM_Ephem flag) contains
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
123 ** a pointer to a dynamically allocated string where some other entity
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
124 ** is responsible for deallocating that string. Because the stack entry
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
125 ** does not control the string, it might be deleted without the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
126 ** entry knowing it.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
127 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
128 ** This routine converts an ephemeral string into a dynamically allocated
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
129 ** string that the stack entry itself controls. In other words, it
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
130 ** converts an MEM_Ephem string into an MEM_Dyn string.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
131 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
132 #define Deephemeralize(P) \
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
133 if( ((P)->flags&MEM_Ephem)!=0 \
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
134 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
135
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
136 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
137 ** Argument pMem points at a memory cell that will be passed to a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
138 ** user-defined function or returned to the user as the result of a query.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
139 ** The second argument, 'db_enc' is the text encoding used by the vdbe for
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
140 ** stack variables. This routine sets the pMem->enc and pMem->type
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
141 ** variables used by the sqlite3_value_*() routines.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
142 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
143 #define storeTypeInfo(A,B) _storeTypeInfo(A)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
144 static void _storeTypeInfo(Mem *pMem){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
145 int flags = pMem->flags;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
146 if( flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
147 pMem->type = SQLITE_NULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
148 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
149 else if( flags & MEM_Int ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
150 pMem->type = SQLITE_INTEGER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
151 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
152 else if( flags & MEM_Real ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
153 pMem->type = SQLITE_FLOAT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
154 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
155 else if( flags & MEM_Str ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
156 pMem->type = SQLITE_TEXT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
157 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
158 pMem->type = SQLITE_BLOB;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
159 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
160 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
161
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
162 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
163 ** Pop the stack N times.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
164 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
165 static void popStack(Mem **ppTos, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
166 Mem *pTos = *ppTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
167 while( N>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
168 N--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
169 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
170 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
171 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
172 *ppTos = pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
173 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
174
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
175 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
176 ** Allocate cursor number iCur. Return a pointer to it. Return NULL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
177 ** if we run out of memory.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
178 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
179 static Cursor *allocateCursor(Vdbe *p, int iCur, int iDb){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
180 Cursor *pCx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
181 assert( iCur<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
182 if( p->apCsr[iCur] ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
183 sqlite3VdbeFreeCursor(p->apCsr[iCur]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
184 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
185 p->apCsr[iCur] = pCx = sqliteMalloc( sizeof(Cursor) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
186 if( pCx ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
187 pCx->iDb = iDb;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
188 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
189 return pCx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
190 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
191
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
192 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
193 ** Try to convert a value into a numeric representation if we can
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
194 ** do so without loss of information. In other words, if the string
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
195 ** looks like a number, convert it into a number. If it does not
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
196 ** look like a number, leave it alone.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
197 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
198 static void applyNumericAffinity(Mem *pRec){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
199 if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
200 int realnum;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
201 sqlite3VdbeMemNulTerminate(pRec);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
202 if( (pRec->flags&MEM_Str)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
203 && sqlite3IsNumber(pRec->z, &realnum, pRec->enc) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
204 i64 value;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
205 sqlite3VdbeChangeEncoding(pRec, SQLITE_UTF8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
206 if( !realnum && sqlite3atoi64(pRec->z, &value) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
207 sqlite3VdbeMemRelease(pRec);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
208 pRec->i = value;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
209 pRec->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
210 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
211 sqlite3VdbeMemRealify(pRec);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
212 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
213 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
214 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
215 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
216
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
217 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
218 ** Processing is determine by the affinity parameter:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
219 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
220 ** SQLITE_AFF_INTEGER:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
221 ** SQLITE_AFF_REAL:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
222 ** SQLITE_AFF_NUMERIC:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
223 ** Try to convert pRec to an integer representation or a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
224 ** floating-point representation if an integer representation
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
225 ** is not possible. Note that the integer representation is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
226 ** always preferred, even if the affinity is REAL, because
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
227 ** an integer representation is more space efficient on disk.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
228 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
229 ** SQLITE_AFF_TEXT:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
230 ** Convert pRec to a text representation.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
231 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
232 ** SQLITE_AFF_NONE:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
233 ** No-op. pRec is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
234 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
235 static void applyAffinity(Mem *pRec, char affinity, u8 enc){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
236 if( affinity==SQLITE_AFF_TEXT ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
237 /* Only attempt the conversion to TEXT if there is an integer or real
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
238 ** representation (blob and NULL do not get converted) but no string
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
239 ** representation.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
240 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
241 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
242 sqlite3VdbeMemStringify(pRec, enc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
243 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
244 pRec->flags &= ~(MEM_Real|MEM_Int);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
245 }else if( affinity!=SQLITE_AFF_NONE ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
246 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
247 || affinity==SQLITE_AFF_NUMERIC );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
248 applyNumericAffinity(pRec);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
249 if( pRec->flags & MEM_Real ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
250 sqlite3VdbeIntegerAffinity(pRec);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
251 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
252 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
253 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
254
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
255 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
256 ** Try to convert the type of a function argument or a result column
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
257 ** into a numeric representation. Use either INTEGER or REAL whichever
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
258 ** is appropriate. But only do the conversion if it is possible without
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
259 ** loss of information and return the revised type of the argument.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
260 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
261 ** This is an EXPERIMENTAL api and is subject to change or removal.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
262 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
263 int sqlite3_value_numeric_type(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
264 Mem *pMem = (Mem*)pVal;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
265 applyNumericAffinity(pMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
266 storeTypeInfo(pMem, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
267 return pMem->type;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
268 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
269
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
270 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
271 ** Exported version of applyAffinity(). This one works on sqlite3_value*,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
272 ** not the internal Mem* type.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
273 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
274 void sqlite3ValueApplyAffinity(sqlite3_value *pVal, u8 affinity, u8 enc){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
275 applyAffinity((Mem *)pVal, affinity, enc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
276 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
277
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
278 #ifdef SQLITE_DEBUG
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
279 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
280 ** Write a nice string representation of the contents of cell pMem
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
281 ** into buffer zBuf, length nBuf.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
282 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
283 void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
284 char *zCsr = zBuf;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
285 int f = pMem->flags;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
286
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
287 static const char *const encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"};
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
288
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
289 if( f&MEM_Blob ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
290 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
291 char c;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
292 if( f & MEM_Dyn ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
293 c = 'z';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
294 assert( (f & (MEM_Static|MEM_Ephem))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
295 }else if( f & MEM_Static ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
296 c = 't';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
297 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
298 }else if( f & MEM_Ephem ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
299 c = 'e';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
300 assert( (f & (MEM_Static|MEM_Dyn))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
301 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
302 c = 's';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
303 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
304
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
305 zCsr += sprintf(zCsr, "%c", c);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
306 zCsr += sprintf(zCsr, "%d[", pMem->n);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
307 for(i=0; i<16 && i<pMem->n; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
308 zCsr += sprintf(zCsr, "%02X ", ((int)pMem->z[i] & 0xFF));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
309 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
310 for(i=0; i<16 && i<pMem->n; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
311 char z = pMem->z[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
312 if( z<32 || z>126 ) *zCsr++ = '.';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
313 else *zCsr++ = z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
314 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
315
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
316 zCsr += sprintf(zCsr, "]");
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
317 *zCsr = '\0';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
318 }else if( f & MEM_Str ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
319 int j, k;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
320 zBuf[0] = ' ';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
321 if( f & MEM_Dyn ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
322 zBuf[1] = 'z';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
323 assert( (f & (MEM_Static|MEM_Ephem))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
324 }else if( f & MEM_Static ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
325 zBuf[1] = 't';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
326 assert( (f & (MEM_Dyn|MEM_Ephem))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
327 }else if( f & MEM_Ephem ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
328 zBuf[1] = 'e';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
329 assert( (f & (MEM_Static|MEM_Dyn))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
330 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
331 zBuf[1] = 's';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
332 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
333 k = 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
334 k += sprintf(&zBuf[k], "%d", pMem->n);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
335 zBuf[k++] = '[';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
336 for(j=0; j<15 && j<pMem->n; j++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
337 u8 c = pMem->z[j];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
338 if( c>=0x20 && c<0x7f ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
339 zBuf[k++] = c;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
340 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
341 zBuf[k++] = '.';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
342 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
343 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
344 zBuf[k++] = ']';
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
345 k += sprintf(&zBuf[k], encnames[pMem->enc]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
346 zBuf[k++] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
347 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
348 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
349 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
350
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
351
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
352 #ifdef VDBE_PROFILE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
353 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
354 ** The following routine only works on pentium-class processors.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
355 ** It uses the RDTSC opcode to read the cycle count value out of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
356 ** processor and returns that value. This can be used for high-res
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
357 ** profiling.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
358 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
359 __inline__ unsigned long long int hwtime(void){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
360 unsigned long long int x;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
361 __asm__("rdtsc\n\t"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
362 "mov %%edx, %%ecx\n\t"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
363 :"=A" (x));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
364 return x;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
365 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
366 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
367
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
368 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
369 ** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
370 ** sqlite3_interrupt() routine has been called. If it has been, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
371 ** processing of the VDBE program is interrupted.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
372 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
373 ** This macro added to every instruction that does a jump in order to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
374 ** implement a loop. This test used to be on every single instruction,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
375 ** but that meant we more testing that we needed. By only testing the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
376 ** flag on jump instructions, we get a (small) speed improvement.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
377 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
378 #define CHECK_FOR_INTERRUPT \
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
379 if( db->flags & SQLITE_Interrupt ) goto abort_due_to_interrupt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
380
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
381
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
382 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
383 ** Execute as much of a VDBE program as we can then return.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
384 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
385 ** sqlite3VdbeMakeReady() must be called before this routine in order to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
386 ** close the program with a final OP_Halt and to set up the callbacks
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
387 ** and the error message pointer.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
388 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
389 ** Whenever a row or result data is available, this routine will either
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
390 ** invoke the result callback (if there is one) or return with
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
391 ** SQLITE_ROW.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
392 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
393 ** If an attempt is made to open a locked database, then this routine
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
394 ** will either invoke the busy callback (if there is one) or it will
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
395 ** return SQLITE_BUSY.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
396 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
397 ** If an error occurs, an error message is written to memory obtained
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
398 ** from sqliteMalloc() and p->zErrMsg is made to point to that memory.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
399 ** The error code is stored in p->rc and this routine returns SQLITE_ERROR.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
400 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
401 ** If the callback ever returns non-zero, then the program exits
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
402 ** immediately. There will be no error message but the p->rc field is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
403 ** set to SQLITE_ABORT and this routine will return SQLITE_ERROR.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
404 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
405 ** A memory allocation error causes p->rc to be set to SQLITE_NOMEM and this
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
406 ** routine to return SQLITE_ERROR.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
407 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
408 ** Other fatal errors return SQLITE_ERROR.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
409 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
410 ** After this routine has finished, sqlite3VdbeFinalize() should be
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
411 ** used to clean up the mess that was left behind.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
412 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
413 int sqlite3VdbeExec(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
414 Vdbe *p /* The VDBE */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
415 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
416 int pc; /* The program counter */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
417 Op *pOp; /* Current operation */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
418 int rc = SQLITE_OK; /* Value to return */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
419 sqlite3 *db = p->db; /* The database */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
420 u8 encoding = ENC(db); /* The database encoding */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
421 Mem *pTos; /* Top entry in the operand stack */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
422 #ifdef VDBE_PROFILE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
423 unsigned long long start; /* CPU clock count at start of opcode */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
424 int origPc; /* Program counter at start of opcode */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
425 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
426 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
427 int nProgressOps = 0; /* Opcodes executed since progress callback. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
428 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
429 #ifndef NDEBUG
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
430 Mem *pStackLimit;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
431 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
432
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
433 if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
434 assert( db->magic==SQLITE_MAGIC_BUSY );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
435 pTos = p->pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
436 if( p->rc==SQLITE_NOMEM ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
437 /* This happens if a malloc() inside a call to sqlite3_column_text() or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
438 ** sqlite3_column_text16() failed. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
439 goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
440 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
441 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
442 p->rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
443 assert( p->explain==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
444 if( p->popStack ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
445 popStack(&pTos, p->popStack);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
446 p->popStack = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
447 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
448 p->resOnStack = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
449 db->busyHandler.nBusy = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
450 CHECK_FOR_INTERRUPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
451 for(pc=p->pc; rc==SQLITE_OK; pc++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
452 assert( pc>=0 && pc<p->nOp );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
453 assert( pTos<=&p->aStack[pc] );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
454 if( sqlite3MallocFailed() ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
455 #ifdef VDBE_PROFILE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
456 origPc = pc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
457 start = hwtime();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
458 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
459 pOp = &p->aOp[pc];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
460
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
461 /* Only allow tracing if SQLITE_DEBUG is defined.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
462 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
463 #ifdef SQLITE_DEBUG
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
464 if( p->trace ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
465 if( pc==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
466 printf("VDBE Execution Trace:\n");
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
467 sqlite3VdbePrintSql(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
468 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
469 sqlite3VdbePrintOp(p->trace, pc, pOp);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
470 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
471 if( p->trace==0 && pc==0 && sqlite3OsFileExists("vdbe_sqltrace") ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
472 sqlite3VdbePrintSql(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
473 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
474 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
475
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
476
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
477 /* Check to see if we need to simulate an interrupt. This only happens
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
478 ** if we have a special test build.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
479 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
480 #ifdef SQLITE_TEST
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
481 if( sqlite3_interrupt_count>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
482 sqlite3_interrupt_count--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
483 if( sqlite3_interrupt_count==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
484 sqlite3_interrupt(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
485 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
486 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
487 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
488
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
489 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
490 /* Call the progress callback if it is configured and the required number
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
491 ** of VDBE ops have been executed (either since this invocation of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
492 ** sqlite3VdbeExec() or since last time the progress callback was called).
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
493 ** If the progress callback returns non-zero, exit the virtual machine with
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
494 ** a return code SQLITE_ABORT.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
495 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
496 if( db->xProgress ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
497 if( db->nProgressOps==nProgressOps ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
498 if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
499 if( db->xProgress(db->pProgressArg)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
500 sqlite3SafetyOn(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
501 rc = SQLITE_ABORT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
502 continue; /* skip to the next iteration of the for loop */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
503 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
504 nProgressOps = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
505 if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
506 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
507 nProgressOps++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
508 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
509 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
510
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
511 #ifndef NDEBUG
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
512 /* This is to check that the return value of static function
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
513 ** opcodeNoPush() (see vdbeaux.c) returns values that match the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
514 ** implementation of the virtual machine in this file. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
515 ** opcodeNoPush() returns non-zero, then the stack is guarenteed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
516 ** not to grow when the opcode is executed. If it returns zero, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
517 ** the stack may grow by at most 1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
518 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
519 ** The global wrapper function sqlite3VdbeOpcodeUsesStack() is not
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
520 ** available if NDEBUG is defined at build time.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
521 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
522 pStackLimit = pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
523 if( !sqlite3VdbeOpcodeNoPush(pOp->opcode) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
524 pStackLimit++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
525 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
526 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
527
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
528 switch( pOp->opcode ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
529
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
530 /*****************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
531 ** What follows is a massive switch statement where each case implements a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
532 ** separate instruction in the virtual machine. If we follow the usual
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
533 ** indentation conventions, each case should be indented by 6 spaces. But
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
534 ** that is a lot of wasted space on the left margin. So the code within
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
535 ** the switch statement will break with convention and be flush-left. Another
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
536 ** big comment (similar to this one) will mark the point in the code where
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
537 ** we transition back to normal indentation.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
538 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
539 ** The formatting of each case is important. The makefile for SQLite
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
540 ** generates two C files "opcodes.h" and "opcodes.c" by scanning this
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
541 ** file looking for lines that begin with "case OP_". The opcodes.h files
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
542 ** will be filled with #defines that give unique integer values to each
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
543 ** opcode and the opcodes.c file is filled with an array of strings where
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
544 ** each string is the symbolic name for the corresponding opcode. If the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
545 ** case statement is followed by a comment of the form "/# same as ... #/"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
546 ** that comment is used to determine the particular value of the opcode.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
547 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
548 ** If a comment on the same line as the "case OP_" construction contains
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
549 ** the word "no-push", then the opcode is guarenteed not to grow the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
550 ** vdbe stack when it is executed. See function opcode() in
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
551 ** vdbeaux.c for details.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
552 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
553 ** Documentation about VDBE opcodes is generated by scanning this file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
554 ** for lines of that contain "Opcode:". That line and all subsequent
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
555 ** comment lines are used in the generation of the opcode.html documentation
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
556 ** file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
557 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
558 ** SUMMARY:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
559 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
560 ** Formatting is important to scripts that scan this file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
561 ** Do not deviate from the formatting style currently in use.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
562 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
563 *****************************************************************************/
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
564
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
565 /* Opcode: Goto * P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
566 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
567 ** An unconditional jump to address P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
568 ** The next instruction executed will be
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
569 ** the one at index P2 from the beginning of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
570 ** the program.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
571 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
572 case OP_Goto: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
573 CHECK_FOR_INTERRUPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
574 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
575 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
576 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
577
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
578 /* Opcode: Gosub * P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
579 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
580 ** Push the current address plus 1 onto the return address stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
581 ** and then jump to address P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
582 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
583 ** The return address stack is of limited depth. If too many
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
584 ** OP_Gosub operations occur without intervening OP_Returns, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
585 ** the return address stack will fill up and processing will abort
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
586 ** with a fatal error.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
587 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
588 case OP_Gosub: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
589 assert( p->returnDepth<sizeof(p->returnStack)/sizeof(p->returnStack[0]) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
590 p->returnStack[p->returnDepth++] = pc+1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
591 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
592 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
593 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
594
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
595 /* Opcode: Return * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
596 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
597 ** Jump immediately to the next instruction after the last unreturned
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
598 ** OP_Gosub. If an OP_Return has occurred for all OP_Gosubs, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
599 ** processing aborts with a fatal error.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
600 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
601 case OP_Return: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
602 assert( p->returnDepth>0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
603 p->returnDepth--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
604 pc = p->returnStack[p->returnDepth] - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
605 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
606 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
607
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
608 /* Opcode: Halt P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
609 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
610 ** Exit immediately. All open cursors, Fifos, etc are closed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
611 ** automatically.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
612 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
613 ** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
614 ** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
615 ** For errors, it can be some other value. If P1!=0 then P2 will determine
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
616 ** whether or not to rollback the current transaction. Do not rollback
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
617 ** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
618 ** then back out all changes that have occurred during this execution of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
619 ** VDBE, but do not rollback the transaction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
620 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
621 ** If P3 is not null then it is an error message string.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
622 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
623 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
624 ** every program. So a jump past the last instruction of the program
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
625 ** is the same as executing Halt.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
626 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
627 case OP_Halt: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
628 p->pTos = pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
629 p->rc = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
630 p->pc = pc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
631 p->errorAction = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
632 if( pOp->p3 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
633 sqlite3SetString(&p->zErrMsg, pOp->p3, (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
634 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
635 rc = sqlite3VdbeHalt(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
636 assert( rc==SQLITE_BUSY || rc==SQLITE_OK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
637 if( rc==SQLITE_BUSY ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
638 p->rc = SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
639 return SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
640 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
641 return p->rc ? SQLITE_ERROR : SQLITE_DONE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
642 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
643
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
644 /* Opcode: Integer P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
645 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
646 ** The 32-bit integer value P1 is pushed onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
647 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
648 case OP_Integer: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
649 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
650 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
651 pTos->i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
652 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
653 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
654
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
655 /* Opcode: Int64 * * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
656 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
657 ** P3 is a string representation of an integer. Convert that integer
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
658 ** to a 64-bit value and push it onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
659 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
660 case OP_Int64: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
661 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
662 assert( pOp->p3!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
663 pTos->flags = MEM_Str|MEM_Static|MEM_Term;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
664 pTos->z = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
665 pTos->n = strlen(pTos->z);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
666 pTos->enc = SQLITE_UTF8;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
667 pTos->i = sqlite3VdbeIntValue(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
668 pTos->flags |= MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
669 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
670 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
671
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
672 /* Opcode: Real * * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
673 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
674 ** The string value P3 is converted to a real and pushed on to the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
675 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
676 case OP_Real: { /* same as TK_FLOAT, */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
677 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
678 pTos->flags = MEM_Str|MEM_Static|MEM_Term;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
679 pTos->z = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
680 pTos->n = strlen(pTos->z);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
681 pTos->enc = SQLITE_UTF8;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
682 pTos->r = sqlite3VdbeRealValue(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
683 pTos->flags |= MEM_Real;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
684 sqlite3VdbeChangeEncoding(pTos, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
685 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
686 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
687
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
688 /* Opcode: String8 * * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
689 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
690 ** P3 points to a nul terminated UTF-8 string. This opcode is transformed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
691 ** into an OP_String before it is executed for the first time.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
692 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
693 case OP_String8: { /* same as TK_STRING */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
694 assert( pOp->p3!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
695 pOp->opcode = OP_String;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
696 pOp->p1 = strlen(pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
697
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
698 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
699 if( encoding!=SQLITE_UTF8 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
700 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
701 sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
702 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, encoding) ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
703 if( SQLITE_OK!=sqlite3VdbeMemDynamicify(pTos) ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
704 pTos->flags &= ~(MEM_Dyn);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
705 pTos->flags |= MEM_Static;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
706 if( pOp->p3type==P3_DYNAMIC ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
707 sqliteFree(pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
708 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
709 pOp->p3type = P3_DYNAMIC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
710 pOp->p3 = pTos->z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
711 pOp->p1 = pTos->n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
712 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
713 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
714 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
715 /* Otherwise fall through to the next case, OP_String */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
716 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
717
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
718 /* Opcode: String P1 * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
719 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
720 ** The string value P3 of length P1 (bytes) is pushed onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
721 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
722 case OP_String: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
723 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
724 assert( pOp->p3!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
725 pTos->flags = MEM_Str|MEM_Static|MEM_Term;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
726 pTos->z = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
727 pTos->n = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
728 pTos->enc = encoding;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
729 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
730 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
731
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
732 /* Opcode: Null * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
733 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
734 ** Push a NULL onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
735 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
736 case OP_Null: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
737 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
738 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
739 pTos->n = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
740 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
741 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
742
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
743
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
744 #ifndef SQLITE_OMIT_BLOB_LITERAL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
745 /* Opcode: HexBlob * * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
746 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
747 ** P3 is an UTF-8 SQL hex encoding of a blob. The blob is pushed onto the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
748 ** vdbe stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
749 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
750 ** The first time this instruction executes, in transforms itself into a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
751 ** 'Blob' opcode with a binary blob as P3.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
752 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
753 case OP_HexBlob: { /* same as TK_BLOB */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
754 pOp->opcode = OP_Blob;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
755 pOp->p1 = strlen(pOp->p3)/2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
756 if( pOp->p1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
757 char *zBlob = sqlite3HexToBlob(pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
758 if( !zBlob ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
759 if( pOp->p3type==P3_DYNAMIC ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
760 sqliteFree(pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
761 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
762 pOp->p3 = zBlob;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
763 pOp->p3type = P3_DYNAMIC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
764 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
765 if( pOp->p3type==P3_DYNAMIC ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
766 sqliteFree(pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
767 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
768 pOp->p3type = P3_STATIC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
769 pOp->p3 = "";
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
770 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
771
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
772 /* Fall through to the next case, OP_Blob. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
773 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
774
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
775 /* Opcode: Blob P1 * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
776 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
777 ** P3 points to a blob of data P1 bytes long. Push this
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
778 ** value onto the stack. This instruction is not coded directly
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
779 ** by the compiler. Instead, the compiler layer specifies
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
780 ** an OP_HexBlob opcode, with the hex string representation of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
781 ** the blob as P3. This opcode is transformed to an OP_Blob
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
782 ** the first time it is executed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
783 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
784 case OP_Blob: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
785 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
786 sqlite3VdbeMemSetStr(pTos, pOp->p3, pOp->p1, 0, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
787 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
788 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
789 #endif /* SQLITE_OMIT_BLOB_LITERAL */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
790
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
791 /* Opcode: Variable P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
792 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
793 ** Push the value of variable P1 onto the stack. A variable is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
794 ** an unknown in the original SQL string as handed to sqlite3_compile().
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
795 ** Any occurance of the '?' character in the original SQL is considered
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
796 ** a variable. Variables in the SQL string are number from left to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
797 ** right beginning with 1. The values of variables are set using the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
798 ** sqlite3_bind() API.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
799 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
800 case OP_Variable: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
801 int j = pOp->p1 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
802 assert( j>=0 && j<p->nVar );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
803
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
804 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
805 sqlite3VdbeMemShallowCopy(pTos, &p->aVar[j], MEM_Static);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
806 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
807 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
808
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
809 /* Opcode: Pop P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
810 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
811 ** P1 elements are popped off of the top of stack and discarded.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
812 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
813 case OP_Pop: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
814 assert( pOp->p1>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
815 popStack(&pTos, pOp->p1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
816 assert( pTos>=&p->aStack[-1] );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
817 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
818 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
819
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
820 /* Opcode: Dup P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
821 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
822 ** A copy of the P1-th element of the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
823 ** is made and pushed onto the top of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
824 ** The top of the stack is element 0. So the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
825 ** instruction "Dup 0 0 0" will make a copy of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
826 ** top of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
827 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
828 ** If the content of the P1-th element is a dynamically
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
829 ** allocated string, then a new copy of that string
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
830 ** is made if P2==0. If P2!=0, then just a pointer
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
831 ** to the string is copied.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
832 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
833 ** Also see the Pull instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
834 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
835 case OP_Dup: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
836 Mem *pFrom = &pTos[-pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
837 assert( pFrom<=pTos && pFrom>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
838 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
839 sqlite3VdbeMemShallowCopy(pTos, pFrom, MEM_Ephem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
840 if( pOp->p2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
841 Deephemeralize(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
842 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
843 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
844 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
845
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
846 /* Opcode: Pull P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
847 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
848 ** The P1-th element is removed from its current location on
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
849 ** the stack and pushed back on top of the stack. The
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
850 ** top of the stack is element 0, so "Pull 0 0 0" is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
851 ** a no-op. "Pull 1 0 0" swaps the top two elements of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
852 ** the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
853 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
854 ** See also the Dup instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
855 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
856 case OP_Pull: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
857 Mem *pFrom = &pTos[-pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
858 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
859 Mem ts;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
860
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
861 ts = *pFrom;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
862 Deephemeralize(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
863 for(i=0; i<pOp->p1; i++, pFrom++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
864 Deephemeralize(&pFrom[1]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
865 assert( (pFrom->flags & MEM_Ephem)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
866 *pFrom = pFrom[1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
867 if( pFrom->flags & MEM_Short ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
868 assert( pFrom->flags & (MEM_Str|MEM_Blob) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
869 assert( pFrom->z==pFrom[1].zShort );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
870 pFrom->z = pFrom->zShort;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
871 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
872 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
873 *pTos = ts;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
874 if( pTos->flags & MEM_Short ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
875 assert( pTos->flags & (MEM_Str|MEM_Blob) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
876 assert( pTos->z==pTos[-pOp->p1].zShort );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
877 pTos->z = pTos->zShort;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
878 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
879 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
880 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
881
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
882 /* Opcode: Push P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
883 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
884 ** Overwrite the value of the P1-th element down on the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
885 ** stack (P1==0 is the top of the stack) with the value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
886 ** of the top of the stack. Then pop the top of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
887 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
888 case OP_Push: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
889 Mem *pTo = &pTos[-pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
890
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
891 assert( pTo>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
892 sqlite3VdbeMemMove(pTo, pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
893 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
894 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
895 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
896
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
897 /* Opcode: Callback P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
898 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
899 ** The top P1 values on the stack represent a single result row from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
900 ** a query. This opcode causes the sqlite3_step() call to terminate
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
901 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
902 ** structure to provide access to the top P1 values as the result
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
903 ** row. When the sqlite3_step() function is run again, the top P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
904 ** values will be automatically popped from the stack before the next
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
905 ** instruction executes.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
906 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
907 case OP_Callback: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
908 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
909 Mem *pFirstColumn;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
910 assert( p->nResColumn==pOp->p1 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
911
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
912 /* Data in the pager might be moved or changed out from under us
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
913 ** in between the return from this sqlite3_step() call and the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
914 ** next call to sqlite3_step(). So deephermeralize everything on
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
915 ** the stack. Note that ephemeral data is never stored in memory
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
916 ** cells so we do not have to worry about them.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
917 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
918 pFirstColumn = &pTos[0-pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
919 for(pMem = p->aStack; pMem<pFirstColumn; pMem++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
920 Deephemeralize(pMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
921 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
922
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
923 /* Invalidate all ephemeral cursor row caches */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
924 p->cacheCtr = (p->cacheCtr + 2)|1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
925
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
926 /* Make sure the results of the current row are \000 terminated
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
927 ** and have an assigned type. The results are deephemeralized as
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
928 ** as side effect.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
929 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
930 for(; pMem<=pTos; pMem++ ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
931 sqlite3VdbeMemNulTerminate(pMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
932 storeTypeInfo(pMem, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
933 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
934
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
935 /* Set up the statement structure so that it will pop the current
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
936 ** results from the stack when the statement returns.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
937 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
938 p->resOnStack = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
939 p->nCallback++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
940 p->popStack = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
941 p->pc = pc + 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
942 p->pTos = pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
943 return SQLITE_ROW;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
944 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
945
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
946 /* Opcode: Concat P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
947 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
948 ** Look at the first P1+2 elements of the stack. Append them all
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
949 ** together with the lowest element first. The original P1+2 elements
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
950 ** are popped from the stack if P2==0 and retained if P2==1. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
951 ** any element of the stack is NULL, then the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
952 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
953 ** When P1==1, this routine makes a copy of the top stack element
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
954 ** into memory obtained from sqliteMalloc().
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
955 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
956 case OP_Concat: { /* same as TK_CONCAT */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
957 char *zNew;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
958 int nByte;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
959 int nField;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
960 int i, j;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
961 Mem *pTerm;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
962
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
963 /* Loop through the stack elements to see how long the result will be. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
964 nField = pOp->p1 + 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
965 pTerm = &pTos[1-nField];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
966 nByte = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
967 for(i=0; i<nField; i++, pTerm++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
968 assert( pOp->p2==0 || (pTerm->flags&MEM_Str) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
969 if( pTerm->flags&MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
970 nByte = -1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
971 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
972 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
973 Stringify(pTerm, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
974 nByte += pTerm->n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
975 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
976
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
977 if( nByte<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
978 /* If nByte is less than zero, then there is a NULL value on the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
979 ** In this case just pop the values off the stack (if required) and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
980 ** push on a NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
981 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
982 if( pOp->p2==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
983 popStack(&pTos, nField);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
984 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
985 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
986 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
987 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
988 /* Otherwise malloc() space for the result and concatenate all the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
989 ** stack values.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
990 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
991 zNew = sqliteMallocRaw( nByte+2 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
992 if( zNew==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
993 j = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
994 pTerm = &pTos[1-nField];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
995 for(i=j=0; i<nField; i++, pTerm++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
996 int n = pTerm->n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
997 assert( pTerm->flags & (MEM_Str|MEM_Blob) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
998 memcpy(&zNew[j], pTerm->z, n);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
999 j += n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1000 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1001 zNew[j] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1002 zNew[j+1] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1003 assert( j==nByte );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1004
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1005 if( pOp->p2==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1006 popStack(&pTos, nField);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1007 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1008 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1009 pTos->n = j;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1010 pTos->flags = MEM_Str|MEM_Dyn|MEM_Term;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1011 pTos->xDel = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1012 pTos->enc = encoding;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1013 pTos->z = zNew;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1014 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1015 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1016 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1017
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1018 /* Opcode: Add * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1019 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1020 ** Pop the top two elements from the stack, add them together,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1021 ** and push the result back onto the stack. If either element
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1022 ** is a string then it is converted to a double using the atof()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1023 ** function before the addition.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1024 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1025 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1026 /* Opcode: Multiply * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1027 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1028 ** Pop the top two elements from the stack, multiply them together,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1029 ** and push the result back onto the stack. If either element
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1030 ** is a string then it is converted to a double using the atof()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1031 ** function before the multiplication.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1032 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1033 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1034 /* Opcode: Subtract * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1035 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1036 ** Pop the top two elements from the stack, subtract the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1037 ** first (what was on top of the stack) from the second (the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1038 ** next on stack)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1039 ** and push the result back onto the stack. If either element
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1040 ** is a string then it is converted to a double using the atof()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1041 ** function before the subtraction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1042 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1043 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1044 /* Opcode: Divide * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1045 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1046 ** Pop the top two elements from the stack, divide the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1047 ** first (what was on top of the stack) from the second (the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1048 ** next on stack)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1049 ** and push the result back onto the stack. If either element
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1050 ** is a string then it is converted to a double using the atof()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1051 ** function before the division. Division by zero returns NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1052 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1053 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1054 /* Opcode: Remainder * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1055 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1056 ** Pop the top two elements from the stack, divide the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1057 ** first (what was on top of the stack) from the second (the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1058 ** next on stack)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1059 ** and push the remainder after division onto the stack. If either element
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1060 ** is a string then it is converted to a double using the atof()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1061 ** function before the division. Division by zero returns NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1062 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1063 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1064 case OP_Add: /* same as TK_PLUS, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1065 case OP_Subtract: /* same as TK_MINUS, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1066 case OP_Multiply: /* same as TK_STAR, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1067 case OP_Divide: /* same as TK_SLASH, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1068 case OP_Remainder: { /* same as TK_REM, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1069 Mem *pNos = &pTos[-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1070 int flags;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1071 assert( pNos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1072 flags = pTos->flags | pNos->flags;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1073 if( (flags & MEM_Null)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1074 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1075 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1076 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1077 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1078 }else if( (pTos->flags & pNos->flags & MEM_Int)==MEM_Int ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1079 i64 a, b;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1080 a = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1081 b = pNos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1082 switch( pOp->opcode ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1083 case OP_Add: b += a; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1084 case OP_Subtract: b -= a; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1085 case OP_Multiply: b *= a; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1086 case OP_Divide: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1087 if( a==0 ) goto divide_by_zero;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1088 b /= a;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1089 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1090 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1091 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1092 if( a==0 ) goto divide_by_zero;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1093 b %= a;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1094 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1095 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1096 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1097 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1098 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1099 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1100 pTos->i = b;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1101 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1102 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1103 double a, b;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1104 a = sqlite3VdbeRealValue(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1105 b = sqlite3VdbeRealValue(pNos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1106 switch( pOp->opcode ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1107 case OP_Add: b += a; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1108 case OP_Subtract: b -= a; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1109 case OP_Multiply: b *= a; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1110 case OP_Divide: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1111 if( a==0.0 ) goto divide_by_zero;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1112 b /= a;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1113 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1114 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1115 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1116 int ia = (int)a;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1117 int ib = (int)b;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1118 if( ia==0.0 ) goto divide_by_zero;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1119 b = ib % ia;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1120 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1121 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1122 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1123 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1124 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1125 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1126 pTos->r = b;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1127 pTos->flags = MEM_Real;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1128 if( (flags & MEM_Real)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1129 sqlite3VdbeIntegerAffinity(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1130 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1131 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1132 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1133
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1134 divide_by_zero:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1135 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1136 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1137 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1138 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1139 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1140 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1141
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1142 /* Opcode: CollSeq * * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1143 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1144 ** P3 is a pointer to a CollSeq struct. If the next call to a user function
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1145 ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1146 ** be returned. This is used by the built-in min(), max() and nullif()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1147 ** functions.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1148 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1149 ** The interface used by the implementation of the aforementioned functions
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1150 ** to retrieve the collation sequence set by this opcode is not available
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1151 ** publicly, only to user functions defined in func.c.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1152 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1153 case OP_CollSeq: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1154 assert( pOp->p3type==P3_COLLSEQ );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1155 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1156 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1157
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1158 /* Opcode: Function P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1159 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1160 ** Invoke a user function (P3 is a pointer to a Function structure that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1161 ** defines the function) with P2 arguments taken from the stack. Pop all
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1162 ** arguments from the stack and push back the result.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1163 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1164 ** P1 is a 32-bit bitmask indicating whether or not each argument to the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1165 ** function was determined to be constant at compile time. If the first
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1166 ** argument was constant then bit 0 of P1 is set. This is used to determine
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1167 ** whether meta data associated with a user function argument using the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1168 ** sqlite3_set_auxdata() API may be safely retained until the next
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1169 ** invocation of this opcode.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1170 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1171 ** See also: AggStep and AggFinal
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1172 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1173 case OP_Function: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1174 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1175 Mem *pArg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1176 sqlite3_context ctx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1177 sqlite3_value **apVal;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1178 int n = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1179
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1180 apVal = p->apArg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1181 assert( apVal || n==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1182
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1183 pArg = &pTos[1-n];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1184 for(i=0; i<n; i++, pArg++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1185 apVal[i] = pArg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1186 storeTypeInfo(pArg, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1187 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1188
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1189 assert( pOp->p3type==P3_FUNCDEF || pOp->p3type==P3_VDBEFUNC );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1190 if( pOp->p3type==P3_FUNCDEF ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1191 ctx.pFunc = (FuncDef*)pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1192 ctx.pVdbeFunc = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1193 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1194 ctx.pVdbeFunc = (VdbeFunc*)pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1195 ctx.pFunc = ctx.pVdbeFunc->pFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1196 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1197
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1198 ctx.s.flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1199 ctx.s.z = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1200 ctx.s.xDel = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1201 ctx.isError = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1202 if( ctx.pFunc->needCollSeq ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1203 assert( pOp>p->aOp );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1204 assert( pOp[-1].p3type==P3_COLLSEQ );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1205 assert( pOp[-1].opcode==OP_CollSeq );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1206 ctx.pColl = (CollSeq *)pOp[-1].p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1207 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1208 if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1209 (*ctx.pFunc->xFunc)(&ctx, n, apVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1210 if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1211 if( sqlite3MallocFailed() ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1212 popStack(&pTos, n);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1213
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1214 /* If any auxilary data functions have been called by this user function,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1215 ** immediately call the destructor for any non-static values.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1216 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1217 if( ctx.pVdbeFunc ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1218 sqlite3VdbeDeleteAuxData(ctx.pVdbeFunc, pOp->p1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1219 pOp->p3 = (char *)ctx.pVdbeFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1220 pOp->p3type = P3_VDBEFUNC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1221 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1222
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1223 /* If the function returned an error, throw an exception */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1224 if( ctx.isError ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1225 sqlite3SetString(&p->zErrMsg, sqlite3_value_text(&ctx.s), (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1226 rc = SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1227 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1228
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1229 /* Copy the result of the function to the top of the stack */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1230 sqlite3VdbeChangeEncoding(&ctx.s, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1231 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1232 pTos->flags = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1233 sqlite3VdbeMemMove(pTos, &ctx.s);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1234 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1235 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1236
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1237 /* Opcode: BitAnd * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1238 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1239 ** Pop the top two elements from the stack. Convert both elements
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1240 ** to integers. Push back onto the stack the bit-wise AND of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1241 ** two elements.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1242 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1243 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1244 /* Opcode: BitOr * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1245 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1246 ** Pop the top two elements from the stack. Convert both elements
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1247 ** to integers. Push back onto the stack the bit-wise OR of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1248 ** two elements.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1249 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1250 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1251 /* Opcode: ShiftLeft * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1252 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1253 ** Pop the top two elements from the stack. Convert both elements
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1254 ** to integers. Push back onto the stack the second element shifted
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1255 ** left by N bits where N is the top element on the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1256 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1257 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1258 /* Opcode: ShiftRight * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1259 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1260 ** Pop the top two elements from the stack. Convert both elements
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1261 ** to integers. Push back onto the stack the second element shifted
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1262 ** right by N bits where N is the top element on the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1263 ** If either operand is NULL, the result is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1264 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1265 case OP_BitAnd: /* same as TK_BITAND, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1266 case OP_BitOr: /* same as TK_BITOR, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1267 case OP_ShiftLeft: /* same as TK_LSHIFT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1268 case OP_ShiftRight: { /* same as TK_RSHIFT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1269 Mem *pNos = &pTos[-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1270 i64 a, b;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1271
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1272 assert( pNos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1273 if( (pTos->flags | pNos->flags) & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1274 popStack(&pTos, 2);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1275 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1276 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1277 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1278 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1279 a = sqlite3VdbeIntValue(pNos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1280 b = sqlite3VdbeIntValue(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1281 switch( pOp->opcode ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1282 case OP_BitAnd: a &= b; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1283 case OP_BitOr: a |= b; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1284 case OP_ShiftLeft: a <<= b; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1285 case OP_ShiftRight: a >>= b; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1286 default: /* CANT HAPPEN */ break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1287 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1288 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1289 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1290 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1291 pTos->i = a;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1292 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1293 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1294 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1295
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1296 /* Opcode: AddImm P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1297 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1298 ** Add the value P1 to whatever is on top of the stack. The result
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1299 ** is always an integer.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1300 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1301 ** To force the top of the stack to be an integer, just add 0.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1302 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1303 case OP_AddImm: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1304 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1305 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1306 pTos->i += pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1307 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1308 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1309
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1310 /* Opcode: ForceInt P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1311 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1312 ** Convert the top of the stack into an integer. If the current top of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1313 ** the stack is not numeric (meaning that is is a NULL or a string that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1314 ** does not look like an integer or floating point number) then pop the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1315 ** stack and jump to P2. If the top of the stack is numeric then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1316 ** convert it into the least integer that is greater than or equal to its
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1317 ** current value if P1==0, or to the least integer that is strictly
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1318 ** greater than its current value if P1==1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1319 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1320 case OP_ForceInt: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1321 i64 v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1322 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1323 applyAffinity(pTos, SQLITE_AFF_NUMERIC, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1324 if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1325 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1326 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1327 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1328 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1329 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1330 if( pTos->flags & MEM_Int ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1331 v = pTos->i + (pOp->p1!=0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1332 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1333 /* FIX ME: should this not be assert( pTos->flags & MEM_Real ) ??? */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1334 sqlite3VdbeMemRealify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1335 v = (int)pTos->r;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1336 if( pTos->r>(double)v ) v++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1337 if( pOp->p1 && pTos->r==(double)v ) v++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1338 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1339 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1340 pTos->i = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1341 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1342 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1343 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1344
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1345 /* Opcode: MustBeInt P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1346 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1347 ** Force the top of the stack to be an integer. If the top of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1348 ** stack is not an integer and cannot be converted into an integer
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1349 ** with out data loss, then jump immediately to P2, or if P2==0
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1350 ** raise an SQLITE_MISMATCH exception.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1351 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1352 ** If the top of the stack is not an integer and P2 is not zero and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1353 ** P1 is 1, then the stack is popped. In all other cases, the depth
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1354 ** of the stack is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1355 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1356 case OP_MustBeInt: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1357 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1358 applyAffinity(pTos, SQLITE_AFF_NUMERIC, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1359 if( (pTos->flags & MEM_Int)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1360 if( pOp->p2==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1361 rc = SQLITE_MISMATCH;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1362 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1363 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1364 if( pOp->p1 ) popStack(&pTos, 1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1365 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1366 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1367 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1368 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1369 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1370 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1371 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1372 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1373
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1374 /* Opcode: RealAffinity * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1375 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1376 ** If the top of the stack is an integer, convert it to a real value.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1377 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1378 ** This opcode is used when extracting information from a column that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1379 ** has REAL affinity. Such column values may still be stored as
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1380 ** integers, for space efficiency, but after extraction we want them
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1381 ** to have only a real value.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1382 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1383 case OP_RealAffinity: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1384 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1385 if( pTos->flags & MEM_Int ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1386 sqlite3VdbeMemRealify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1387 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1388 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1389 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1390
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1391 #ifndef SQLITE_OMIT_CAST
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1392 /* Opcode: ToText * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1393 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1394 ** Force the value on the top of the stack to be text.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1395 ** If the value is numeric, convert it to a string using the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1396 ** equivalent of printf(). Blob values are unchanged and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1397 ** are afterwards simply interpreted as text.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1398 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1399 ** A NULL value is not changed by this routine. It remains NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1400 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1401 case OP_ToText: { /* same as TK_TO_TEXT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1402 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1403 if( pTos->flags & MEM_Null ) break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1404 assert( MEM_Str==(MEM_Blob>>3) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1405 pTos->flags |= (pTos->flags&MEM_Blob)>>3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1406 applyAffinity(pTos, SQLITE_AFF_TEXT, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1407 assert( pTos->flags & MEM_Str );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1408 pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Blob);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1409 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1410 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1411
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1412 /* Opcode: ToBlob * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1413 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1414 ** Force the value on the top of the stack to be a BLOB.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1415 ** If the value is numeric, convert it to a string first.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1416 ** Strings are simply reinterpreted as blobs with no change
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1417 ** to the underlying data.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1418 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1419 ** A NULL value is not changed by this routine. It remains NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1420 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1421 case OP_ToBlob: { /* same as TK_TO_BLOB, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1422 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1423 if( pTos->flags & MEM_Null ) break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1424 if( (pTos->flags & MEM_Blob)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1425 applyAffinity(pTos, SQLITE_AFF_TEXT, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1426 assert( pTos->flags & MEM_Str );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1427 pTos->flags |= MEM_Blob;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1428 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1429 pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Str);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1430 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1431 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1432
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1433 /* Opcode: ToNumeric * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1434 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1435 ** Force the value on the top of the stack to be numeric (either an
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1436 ** integer or a floating-point number.)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1437 ** If the value is text or blob, try to convert it to an using the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1438 ** equivalent of atoi() or atof() and store 0 if no such conversion
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1439 ** is possible.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1440 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1441 ** A NULL value is not changed by this routine. It remains NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1442 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1443 case OP_ToNumeric: { /* same as TK_TO_NUMERIC, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1444 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1445 if( (pTos->flags & MEM_Null)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1446 sqlite3VdbeMemNumerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1447 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1448 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1449 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1450 #endif /* SQLITE_OMIT_CAST */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1451
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1452 /* Opcode: ToInt * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1453 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1454 ** Force the value on the top of the stack to be an integer. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1455 ** The value is currently a real number, drop its fractional part.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1456 ** If the value is text or blob, try to convert it to an integer using the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1457 ** equivalent of atoi() and store 0 if no such conversion is possible.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1458 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1459 ** A NULL value is not changed by this routine. It remains NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1460 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1461 case OP_ToInt: { /* same as TK_TO_INT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1462 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1463 if( (pTos->flags & MEM_Null)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1464 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1465 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1466 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1467 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1468
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1469 #ifndef SQLITE_OMIT_CAST
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1470 /* Opcode: ToReal * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1471 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1472 ** Force the value on the top of the stack to be a floating point number.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1473 ** If The value is currently an integer, convert it.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1474 ** If the value is text or blob, try to convert it to an integer using the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1475 ** equivalent of atoi() and store 0 if no such conversion is possible.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1476 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1477 ** A NULL value is not changed by this routine. It remains NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1478 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1479 case OP_ToReal: { /* same as TK_TO_REAL, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1480 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1481 if( (pTos->flags & MEM_Null)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1482 sqlite3VdbeMemRealify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1483 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1484 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1485 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1486 #endif /* SQLITE_OMIT_CAST */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1487
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1488 /* Opcode: Eq P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1489 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1490 ** Pop the top two elements from the stack. If they are equal, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1491 ** jump to instruction P2. Otherwise, continue to the next instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1492 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1493 ** If the 0x100 bit of P1 is true and either operand is NULL then take the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1494 ** jump. If the 0x100 bit of P1 is clear then fall thru if either operand
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1495 ** is NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1496 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1497 ** If the 0x200 bit of P1 is set and either operand is NULL then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1498 ** both operands are converted to integers prior to comparison.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1499 ** NULL operands are converted to zero and non-NULL operands are
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1500 ** converted to 1. Thus, for example, with 0x200 set, NULL==NULL is true
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1501 ** whereas it would normally be NULL. Similarly, NULL==123 is false when
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1502 ** 0x200 is set but is NULL when the 0x200 bit of P1 is clear.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1503 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1504 ** The least significant byte of P1 (mask 0xff) must be an affinity character -
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1505 ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1506 ** to coerce both values
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1507 ** according to the affinity before the comparison is made. If the byte is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1508 ** 0x00, then numeric affinity is used.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1509 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1510 ** Once any conversions have taken place, and neither value is NULL,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1511 ** the values are compared. If both values are blobs, or both are text,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1512 ** then memcmp() is used to determine the results of the comparison. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1513 ** both values are numeric, then a numeric comparison is used. If the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1514 ** two values are of different types, then they are inequal.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1515 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1516 ** If P2 is zero, do not jump. Instead, push an integer 1 onto the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1517 ** stack if the jump would have been taken, or a 0 if not. Push a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1518 ** NULL if either operand was NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1519 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1520 ** If P3 is not NULL it is a pointer to a collating sequence (a CollSeq
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1521 ** structure) that defines how to compare text.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1522 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1523 /* Opcode: Ne P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1524 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1525 ** This works just like the Eq opcode except that the jump is taken if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1526 ** the operands from the stack are not equal. See the Eq opcode for
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1527 ** additional information.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1528 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1529 /* Opcode: Lt P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1530 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1531 ** This works just like the Eq opcode except that the jump is taken if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1532 ** the 2nd element down on the stack is less than the top of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1533 ** See the Eq opcode for additional information.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1534 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1535 /* Opcode: Le P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1536 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1537 ** This works just like the Eq opcode except that the jump is taken if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1538 ** the 2nd element down on the stack is less than or equal to the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1539 ** top of the stack. See the Eq opcode for additional information.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1540 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1541 /* Opcode: Gt P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1542 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1543 ** This works just like the Eq opcode except that the jump is taken if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1544 ** the 2nd element down on the stack is greater than the top of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1545 ** See the Eq opcode for additional information.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1546 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1547 /* Opcode: Ge P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1548 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1549 ** This works just like the Eq opcode except that the jump is taken if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1550 ** the 2nd element down on the stack is greater than or equal to the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1551 ** top of the stack. See the Eq opcode for additional information.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1552 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1553 case OP_Eq: /* same as TK_EQ, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1554 case OP_Ne: /* same as TK_NE, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1555 case OP_Lt: /* same as TK_LT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1556 case OP_Le: /* same as TK_LE, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1557 case OP_Gt: /* same as TK_GT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1558 case OP_Ge: { /* same as TK_GE, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1559 Mem *pNos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1560 int flags;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1561 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1562 char affinity;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1563
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1564 pNos = &pTos[-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1565 flags = pTos->flags|pNos->flags;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1566
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1567 /* If either value is a NULL P2 is not zero, take the jump if the least
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1568 ** significant byte of P1 is true. If P2 is zero, then push a NULL onto
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1569 ** the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1570 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1571 if( flags&MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1572 if( (pOp->p1 & 0x200)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1573 /* The 0x200 bit of P1 means, roughly "do not treat NULL as the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1574 ** magic SQL value it normally is - treat it as if it were another
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1575 ** integer".
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1576 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1577 ** With 0x200 set, if either operand is NULL then both operands
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1578 ** are converted to integers prior to being passed down into the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1579 ** normal comparison logic below. NULL operands are converted to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1580 ** zero and non-NULL operands are converted to 1. Thus, for example,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1581 ** with 0x200 set, NULL==NULL is true whereas it would normally
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1582 ** be NULL. Similarly, NULL!=123 is true.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1583 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1584 sqlite3VdbeMemSetInt64(pTos, (pTos->flags & MEM_Null)==0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1585 sqlite3VdbeMemSetInt64(pNos, (pNos->flags & MEM_Null)==0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1586 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1587 /* If the 0x200 bit of P1 is clear and either operand is NULL then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1588 ** the result is always NULL. The jump is taken if the 0x100 bit
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1589 ** of P1 is set.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1590 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1591 popStack(&pTos, 2);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1592 if( pOp->p2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1593 if( pOp->p1 & 0x100 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1594 pc = pOp->p2-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1595 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1596 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1597 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1598 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1599 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1600 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1601 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1602 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1603
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1604 affinity = pOp->p1 & 0xFF;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1605 if( affinity ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1606 applyAffinity(pNos, affinity, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1607 applyAffinity(pTos, affinity, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1608 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1609
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1610 assert( pOp->p3type==P3_COLLSEQ || pOp->p3==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1611 res = sqlite3MemCompare(pNos, pTos, (CollSeq*)pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1612 switch( pOp->opcode ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1613 case OP_Eq: res = res==0; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1614 case OP_Ne: res = res!=0; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1615 case OP_Lt: res = res<0; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1616 case OP_Le: res = res<=0; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1617 case OP_Gt: res = res>0; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1618 default: res = res>=0; break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1619 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1620
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1621 popStack(&pTos, 2);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1622 if( pOp->p2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1623 if( res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1624 pc = pOp->p2-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1625 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1626 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1627 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1628 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1629 pTos->i = res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1630 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1631 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1632 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1633
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1634 /* Opcode: And * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1635 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1636 ** Pop two values off the stack. Take the logical AND of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1637 ** two values and push the resulting boolean value back onto the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1638 ** stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1639 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1640 /* Opcode: Or * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1641 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1642 ** Pop two values off the stack. Take the logical OR of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1643 ** two values and push the resulting boolean value back onto the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1644 ** stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1645 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1646 case OP_And: /* same as TK_AND, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1647 case OP_Or: { /* same as TK_OR, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1648 Mem *pNos = &pTos[-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1649 int v1, v2; /* 0==TRUE, 1==FALSE, 2==UNKNOWN or NULL */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1650
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1651 assert( pNos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1652 if( pTos->flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1653 v1 = 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1654 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1655 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1656 v1 = pTos->i==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1657 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1658 if( pNos->flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1659 v2 = 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1660 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1661 sqlite3VdbeMemIntegerify(pNos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1662 v2 = pNos->i==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1663 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1664 if( pOp->opcode==OP_And ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1665 static const unsigned char and_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1666 v1 = and_logic[v1*3+v2];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1667 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1668 static const unsigned char or_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1669 v1 = or_logic[v1*3+v2];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1670 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1671 popStack(&pTos, 2);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1672 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1673 if( v1==2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1674 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1675 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1676 pTos->i = v1==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1677 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1678 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1679 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1680 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1681
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1682 /* Opcode: Negative * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1683 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1684 ** Treat the top of the stack as a numeric quantity. Replace it
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1685 ** with its additive inverse. If the top of the stack is NULL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1686 ** its value is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1687 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1688 /* Opcode: AbsValue * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1689 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1690 ** Treat the top of the stack as a numeric quantity. Replace it
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1691 ** with its absolute value. If the top of the stack is NULL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1692 ** its value is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1693 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1694 case OP_Negative: /* same as TK_UMINUS, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1695 case OP_AbsValue: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1696 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1697 if( pTos->flags & MEM_Real ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1698 neg_abs_real_case:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1699 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1700 if( pOp->opcode==OP_Negative || pTos->r<0.0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1701 pTos->r = -pTos->r;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1702 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1703 pTos->flags = MEM_Real;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1704 }else if( pTos->flags & MEM_Int ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1705 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1706 if( pOp->opcode==OP_Negative || pTos->i<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1707 pTos->i = -pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1708 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1709 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1710 }else if( pTos->flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1711 /* Do nothing */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1712 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1713 sqlite3VdbeMemNumerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1714 goto neg_abs_real_case;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1715 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1716 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1717 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1718
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1719 /* Opcode: Not * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1720 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1721 ** Interpret the top of the stack as a boolean value. Replace it
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1722 ** with its complement. If the top of the stack is NULL its value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1723 ** is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1724 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1725 case OP_Not: { /* same as TK_NOT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1726 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1727 if( pTos->flags & MEM_Null ) break; /* Do nothing to NULLs */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1728 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1729 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1730 pTos->i = !pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1731 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1732 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1733 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1734
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1735 /* Opcode: BitNot * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1736 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1737 ** Interpret the top of the stack as an value. Replace it
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1738 ** with its ones-complement. If the top of the stack is NULL its
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1739 ** value is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1740 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1741 case OP_BitNot: { /* same as TK_BITNOT, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1742 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1743 if( pTos->flags & MEM_Null ) break; /* Do nothing to NULLs */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1744 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1745 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1746 pTos->i = ~pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1747 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1748 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1749 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1750
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1751 /* Opcode: Noop * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1752 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1753 ** Do nothing. This instruction is often useful as a jump
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1754 ** destination.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1755 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1756 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1757 ** The magic Explain opcode are only inserted when explain==2 (which
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1758 ** is to say when the EXPLAIN QUERY PLAN syntax is used.)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1759 ** This opcode records information from the optimizer. It is the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1760 ** the same as a no-op. This opcodesnever appears in a real VM program.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1761 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1762 case OP_Explain:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1763 case OP_Noop: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1764 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1765 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1766
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1767 /* Opcode: If P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1768 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1769 ** Pop a single boolean from the stack. If the boolean popped is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1770 ** true, then jump to p2. Otherwise continue to the next instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1771 ** An integer is false if zero and true otherwise. A string is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1772 ** false if it has zero length and true otherwise.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1773 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1774 ** If the value popped of the stack is NULL, then take the jump if P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1775 ** is true and fall through if P1 is false.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1776 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1777 /* Opcode: IfNot P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1778 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1779 ** Pop a single boolean from the stack. If the boolean popped is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1780 ** false, then jump to p2. Otherwise continue to the next instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1781 ** An integer is false if zero and true otherwise. A string is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1782 ** false if it has zero length and true otherwise.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1783 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1784 ** If the value popped of the stack is NULL, then take the jump if P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1785 ** is true and fall through if P1 is false.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1786 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1787 case OP_If: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1788 case OP_IfNot: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1789 int c;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1790 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1791 if( pTos->flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1792 c = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1793 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1794 #ifdef SQLITE_OMIT_FLOATING_POINT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1795 c = sqlite3VdbeIntValue(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1796 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1797 c = sqlite3VdbeRealValue(pTos)!=0.0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1798 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1799 if( pOp->opcode==OP_IfNot ) c = !c;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1800 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1801 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1802 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1803 if( c ) pc = pOp->p2-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1804 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1805 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1806
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1807 /* Opcode: IsNull P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1808 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1809 ** If any of the top abs(P1) values on the stack are NULL, then jump
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1810 ** to P2. Pop the stack P1 times if P1>0. If P1<0 leave the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1811 ** unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1812 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1813 case OP_IsNull: { /* same as TK_ISNULL, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1814 int i, cnt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1815 Mem *pTerm;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1816 cnt = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1817 if( cnt<0 ) cnt = -cnt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1818 pTerm = &pTos[1-cnt];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1819 assert( pTerm>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1820 for(i=0; i<cnt; i++, pTerm++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1821 if( pTerm->flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1822 pc = pOp->p2-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1823 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1824 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1825 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1826 if( pOp->p1>0 ) popStack(&pTos, cnt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1827 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1828 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1829
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1830 /* Opcode: NotNull P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1831 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1832 ** Jump to P2 if the top P1 values on the stack are all not NULL. Pop the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1833 ** stack if P1 times if P1 is greater than zero. If P1 is less than
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1834 ** zero then leave the stack unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1835 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1836 case OP_NotNull: { /* same as TK_NOTNULL, no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1837 int i, cnt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1838 cnt = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1839 if( cnt<0 ) cnt = -cnt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1840 assert( &pTos[1-cnt] >= p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1841 for(i=0; i<cnt && (pTos[1+i-cnt].flags & MEM_Null)==0; i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1842 if( i>=cnt ) pc = pOp->p2-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1843 if( pOp->p1>0 ) popStack(&pTos, cnt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1844 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1845 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1846
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1847 /* Opcode: SetNumColumns P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1848 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1849 ** Before the OP_Column opcode can be executed on a cursor, this
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1850 ** opcode must be called to set the number of fields in the table.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1851 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1852 ** This opcode sets the number of columns for cursor P1 to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1853 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1854 ** If OP_KeyAsData is to be applied to cursor P1, it must be executed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1855 ** before this op-code.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1856 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1857 case OP_SetNumColumns: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1858 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1859 assert( (pOp->p1)<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1860 assert( p->apCsr[pOp->p1]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1861 pC = p->apCsr[pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1862 pC->nField = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1863 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1864 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1865
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1866 /* Opcode: Column P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1867 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1868 ** Interpret the data that cursor P1 points to as a structure built using
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1869 ** the MakeRecord instruction. (See the MakeRecord opcode for additional
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1870 ** information about the format of the data.) Push onto the stack the value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1871 ** of the P2-th column contained in the data. If there are less that (P2+1)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1872 ** values in the record, push a NULL onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1873 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1874 ** If the KeyAsData opcode has previously executed on this cursor, then the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1875 ** field might be extracted from the key rather than the data.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1876 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1877 ** If the column contains fewer than P2 fields, then push a NULL. Or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1878 ** if P3 is of type P3_MEM, then push the P3 value. The P3 value will
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1879 ** be default value for a column that has been added using the ALTER TABLE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1880 ** ADD COLUMN command. If P3 is an ordinary string, just push a NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1881 ** When P3 is a string it is really just a comment describing the value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1882 ** to be pushed, not a default value.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1883 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1884 case OP_Column: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1885 u32 payloadSize; /* Number of bytes in the record */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1886 int p1 = pOp->p1; /* P1 value of the opcode */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1887 int p2 = pOp->p2; /* column number to retrieve */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1888 Cursor *pC = 0; /* The VDBE cursor */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1889 char *zRec; /* Pointer to complete record-data */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1890 BtCursor *pCrsr; /* The BTree cursor */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1891 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1892 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1893 u32 nField; /* number of fields in the record */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1894 int len; /* The length of the serialized data for the column */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1895 int i; /* Loop counter */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1896 char *zData; /* Part of the record being decoded */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1897 Mem sMem; /* For storing the record being decoded */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1898
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1899 sMem.flags = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1900 assert( p1<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1901 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1902 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1903
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1904 /* This block sets the variable payloadSize to be the total number of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1905 ** bytes in the record.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1906 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1907 ** zRec is set to be the complete text of the record if it is available.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1908 ** The complete record text is always available for pseudo-tables
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1909 ** If the record is stored in a cursor, the complete record text
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1910 ** might be available in the pC->aRow cache. Or it might not be.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1911 ** If the data is unavailable, zRec is set to NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1912 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1913 ** We also compute the number of columns in the record. For cursors,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1914 ** the number of columns is stored in the Cursor.nField element. For
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1915 ** records on the stack, the next entry down on the stack is an integer
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1916 ** which is the number of records.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1917 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1918 pC = p->apCsr[p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1919 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1920 if( pC->pCursor!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1921 /* The record is stored in a B-Tree */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1922 rc = sqlite3VdbeCursorMoveto(pC);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1923 if( rc ) goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1924 zRec = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1925 pCrsr = pC->pCursor;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1926 if( pC->nullRow ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1927 payloadSize = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1928 }else if( pC->cacheStatus==p->cacheCtr ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1929 payloadSize = pC->payloadSize;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1930 zRec = (char*)pC->aRow;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1931 }else if( pC->isIndex ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1932 i64 payloadSize64;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1933 sqlite3BtreeKeySize(pCrsr, &payloadSize64);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1934 payloadSize = payloadSize64;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1935 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1936 sqlite3BtreeDataSize(pCrsr, &payloadSize);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1937 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1938 nField = pC->nField;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1939 }else if( pC->pseudoTable ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1940 /* The record is the sole entry of a pseudo-table */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1941 payloadSize = pC->nData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1942 zRec = pC->pData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1943 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1944 assert( payloadSize==0 || zRec!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1945 nField = pC->nField;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1946 pCrsr = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1947 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1948 zRec = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1949 payloadSize = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1950 pCrsr = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1951 nField = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1952 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1953
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1954 /* If payloadSize is 0, then just push a NULL onto the stack. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1955 if( payloadSize==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1956 assert( pTos->flags==MEM_Null );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1957 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1958 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1959
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1960 assert( p2<nField );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1961
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1962 /* Read and parse the table header. Store the results of the parse
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1963 ** into the record header cache fields of the cursor.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1964 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1965 if( pC && pC->cacheStatus==p->cacheCtr ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1966 aType = pC->aType;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1967 aOffset = pC->aOffset;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1968 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1969 u8 *zIdx; /* Index into header */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1970 u8 *zEndHdr; /* Pointer to first byte after the header */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1971 u32 offset; /* Offset into the data */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1972 int szHdrSz; /* Size of the header size field at start of record */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1973 int avail; /* Number of bytes of available data */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1974
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1975 aType = pC->aType;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1976 if( aType==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1977 pC->aType = aType = sqliteMallocRaw( 2*nField*sizeof(aType) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1978 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1979 if( aType==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1980 goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1981 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1982 pC->aOffset = aOffset = &aType[nField];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1983 pC->payloadSize = payloadSize;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1984 pC->cacheStatus = p->cacheCtr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1985
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1986 /* Figure out how many bytes are in the header */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1987 if( zRec ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1988 zData = zRec;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1989 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1990 if( pC->isIndex ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1991 zData = (char*)sqlite3BtreeKeyFetch(pCrsr, &avail);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1992 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1993 zData = (char*)sqlite3BtreeDataFetch(pCrsr, &avail);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1994 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1995 /* If KeyFetch()/DataFetch() managed to get the entire payload,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1996 ** save the payload in the pC->aRow cache. That will save us from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1997 ** having to make additional calls to fetch the content portion of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1998 ** the record.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1999 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2000 if( avail>=payloadSize ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2001 zRec = zData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2002 pC->aRow = (u8*)zData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2003 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2004 pC->aRow = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2005 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2006 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2007 assert( zRec!=0 || avail>=payloadSize || avail>=9 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2008 szHdrSz = GetVarint((u8*)zData, offset);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2009
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2010 /* The KeyFetch() or DataFetch() above are fast and will get the entire
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2011 ** record header in most cases. But they will fail to get the complete
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2012 ** record header if the record header does not fit on a single page
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2013 ** in the B-Tree. When that happens, use sqlite3VdbeMemFromBtree() to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2014 ** acquire the complete header text.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2015 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2016 if( !zRec && avail<offset ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2017 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, offset, pC->isIndex, &sMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2018 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2019 goto op_column_out;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2020 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2021 zData = sMem.z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2022 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2023 zEndHdr = (u8 *)&zData[offset];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2024 zIdx = (u8 *)&zData[szHdrSz];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2025
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2026 /* Scan the header and use it to fill in the aType[] and aOffset[]
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2027 ** arrays. aType[i] will contain the type integer for the i-th
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2028 ** column and aOffset[i] will contain the offset from the beginning
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2029 ** of the record to the start of the data for the i-th column
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2030 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2031 for(i=0; i<nField; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2032 if( zIdx<zEndHdr ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2033 aOffset[i] = offset;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2034 zIdx += GetVarint(zIdx, aType[i]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2035 offset += sqlite3VdbeSerialTypeLen(aType[i]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2036 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2037 /* If i is less that nField, then there are less fields in this
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2038 ** record than SetNumColumns indicated there are columns in the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2039 ** table. Set the offset for any extra columns not present in
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2040 ** the record to 0. This tells code below to push a NULL onto the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2041 ** stack instead of deserializing a value from the record.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2042 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2043 aOffset[i] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2044 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2045 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2046 Release(&sMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2047 sMem.flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2048
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2049 /* If we have read more header data than was contained in the header,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2050 ** or if the end of the last field appears to be past the end of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2051 ** record, then we must be dealing with a corrupt database.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2052 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2053 if( zIdx>zEndHdr || offset>payloadSize ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2054 rc = SQLITE_CORRUPT_BKPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2055 goto op_column_out;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2056 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2057 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2058
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2059 /* Get the column information. If aOffset[p2] is non-zero, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2060 ** deserialize the value from the record. If aOffset[p2] is zero,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2061 ** then there are not enough fields in the record to satisfy the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2062 ** request. In this case, set the value NULL or to P3 if P3 is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2063 ** a pointer to a Mem object.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2064 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2065 if( aOffset[p2] ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2066 assert( rc==SQLITE_OK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2067 if( zRec ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2068 zData = &zRec[aOffset[p2]];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2069 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2070 len = sqlite3VdbeSerialTypeLen(aType[p2]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2071 rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, pC->isIndex,&sMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2072 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2073 goto op_column_out;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2074 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2075 zData = sMem.z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2076 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2077 sqlite3VdbeSerialGet((u8*)zData, aType[p2], pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2078 pTos->enc = encoding;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2079 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2080 if( pOp->p3type==P3_MEM ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2081 sqlite3VdbeMemShallowCopy(pTos, (Mem *)(pOp->p3), MEM_Static);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2082 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2083 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2084 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2085 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2086
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2087 /* If we dynamically allocated space to hold the data (in the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2088 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2089 ** dynamically allocated space over to the pTos structure.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2090 ** This prevents a memory copy.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2091 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2092 if( (sMem.flags & MEM_Dyn)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2093 assert( pTos->flags & MEM_Ephem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2094 assert( pTos->flags & (MEM_Str|MEM_Blob) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2095 assert( pTos->z==sMem.z );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2096 assert( sMem.flags & MEM_Term );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2097 pTos->flags &= ~MEM_Ephem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2098 pTos->flags |= MEM_Dyn|MEM_Term;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2099 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2100
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2101 /* pTos->z might be pointing to sMem.zShort[]. Fix that so that we
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2102 ** can abandon sMem */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2103 rc = sqlite3VdbeMemMakeWriteable(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2104
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2105 op_column_out:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2106 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2107 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2108
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2109 /* Opcode: MakeRecord P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2110 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2111 ** Convert the top abs(P1) entries of the stack into a single entry
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2112 ** suitable for use as a data record in a database table or as a key
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2113 ** in an index. The details of the format are irrelavant as long as
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2114 ** the OP_Column opcode can decode the record later and as long as the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2115 ** sqlite3VdbeRecordCompare function will correctly compare two encoded
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2116 ** records. Refer to source code comments for the details of the record
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2117 ** format.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2118 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2119 ** The original stack entries are popped from the stack if P1>0 but
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2120 ** remain on the stack if P1<0.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2121 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2122 ** If P2 is not zero and one or more of the entries are NULL, then jump
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2123 ** to the address given by P2. This feature can be used to skip a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2124 ** uniqueness test on indices.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2125 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2126 ** P3 may be a string that is P1 characters long. The nth character of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2127 ** string indicates the column affinity that should be used for the nth
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2128 ** field of the index key (i.e. the first character of P3 corresponds to the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2129 ** lowest element on the stack).
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2130 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2131 ** The mapping from character to affinity is given by the SQLITE_AFF_
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2132 ** macros defined in sqliteInt.h.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2133 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2134 ** If P3 is NULL then all index fields have the affinity NONE.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2135 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2136 ** See also OP_MakeIdxRec
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2137 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2138 /* Opcode: MakeIdxRec P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2139 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2140 ** This opcode works just OP_MakeRecord except that it reads an extra
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2141 ** integer from the stack (thus reading a total of abs(P1+1) entries)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2142 ** and appends that extra integer to the end of the record as a varint.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2143 ** This results in an index key.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2144 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2145 case OP_MakeIdxRec:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2146 case OP_MakeRecord: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2147 /* Assuming the record contains N fields, the record format looks
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2148 ** like this:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2149 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2150 ** ------------------------------------------------------------------------
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2151 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2152 ** ------------------------------------------------------------------------
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2153 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2154 ** Data(0) is taken from the lowest element of the stack and data(N-1) is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2155 ** the top of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2156 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2157 ** Each type field is a varint representing the serial type of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2158 ** corresponding data element (see sqlite3VdbeSerialType()). The
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2159 ** hdr-size field is also a varint which is the offset from the beginning
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2160 ** of the record to data0.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2161 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2162 unsigned char *zNewRecord;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2163 unsigned char *zCsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2164 Mem *pRec;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2165 Mem *pRowid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2166 int nData = 0; /* Number of bytes of data space */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2167 int nHdr = 0; /* Number of bytes of header space */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2168 int nByte = 0; /* Space required for this record */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2169 int nVarint; /* Number of bytes in a varint */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2170 u32 serial_type; /* Type field */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2171 int containsNull = 0; /* True if any of the data fields are NULL */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2172 char zTemp[NBFS]; /* Space to hold small records */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2173 Mem *pData0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2174
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2175 int leaveOnStack; /* If true, leave the entries on the stack */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2176 int nField; /* Number of fields in the record */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2177 int jumpIfNull; /* Jump here if non-zero and any entries are NULL. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2178 int addRowid; /* True to append a rowid column at the end */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2179 char *zAffinity; /* The affinity string for the record */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2180 int file_format; /* File format to use for encoding */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2181
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2182 leaveOnStack = ((pOp->p1<0)?1:0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2183 nField = pOp->p1 * (leaveOnStack?-1:1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2184 jumpIfNull = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2185 addRowid = pOp->opcode==OP_MakeIdxRec;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2186 zAffinity = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2187
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2188 pData0 = &pTos[1-nField];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2189 assert( pData0>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2190 containsNull = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2191 file_format = p->minWriteFileFormat;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2192
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2193 /* Loop through the elements that will make up the record to figure
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2194 ** out how much space is required for the new record.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2195 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2196 for(pRec=pData0; pRec<=pTos; pRec++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2197 if( zAffinity ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2198 applyAffinity(pRec, zAffinity[pRec-pData0], encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2199 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2200 if( pRec->flags&MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2201 containsNull = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2202 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2203 serial_type = sqlite3VdbeSerialType(pRec, file_format);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2204 nData += sqlite3VdbeSerialTypeLen(serial_type);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2205 nHdr += sqlite3VarintLen(serial_type);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2206 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2207
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2208 /* If we have to append a varint rowid to this record, set 'rowid'
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2209 ** to the value of the rowid and increase nByte by the amount of space
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2210 ** required to store it and the 0x00 seperator byte.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2211 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2212 if( addRowid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2213 pRowid = &pTos[0-nField];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2214 assert( pRowid>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2215 sqlite3VdbeMemIntegerify(pRowid);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2216 serial_type = sqlite3VdbeSerialType(pRowid, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2217 nData += sqlite3VdbeSerialTypeLen(serial_type);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2218 nHdr += sqlite3VarintLen(serial_type);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2219 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2220
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2221 /* Add the initial header varint and total the size */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2222 nHdr += nVarint = sqlite3VarintLen(nHdr);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2223 if( nVarint<sqlite3VarintLen(nHdr) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2224 nHdr++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2225 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2226 nByte = nHdr+nData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2227
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2228 /* Allocate space for the new record. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2229 if( nByte>sizeof(zTemp) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2230 zNewRecord = sqliteMallocRaw(nByte);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2231 if( !zNewRecord ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2232 goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2233 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2234 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2235 zNewRecord = (u8*)zTemp;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2236 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2237
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2238 /* Write the record */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2239 zCsr = zNewRecord;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2240 zCsr += sqlite3PutVarint(zCsr, nHdr);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2241 for(pRec=pData0; pRec<=pTos; pRec++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2242 serial_type = sqlite3VdbeSerialType(pRec, file_format);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2243 zCsr += sqlite3PutVarint(zCsr, serial_type); /* serial type */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2244 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2245 if( addRowid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2246 zCsr += sqlite3PutVarint(zCsr, sqlite3VdbeSerialType(pRowid, 0));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2247 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2248 for(pRec=pData0; pRec<=pTos; pRec++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2249 zCsr += sqlite3VdbeSerialPut(zCsr, pRec, file_format); /* serial data */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2250 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2251 if( addRowid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2252 zCsr += sqlite3VdbeSerialPut(zCsr, pRowid, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2253 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2254 assert( zCsr==(zNewRecord+nByte) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2255
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2256 /* Pop entries off the stack if required. Push the new record on. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2257 if( !leaveOnStack ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2258 popStack(&pTos, nField+addRowid);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2259 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2260 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2261 pTos->n = nByte;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2262 if( nByte<=sizeof(zTemp) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2263 assert( zNewRecord==(unsigned char *)zTemp );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2264 pTos->z = pTos->zShort;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2265 memcpy(pTos->zShort, zTemp, nByte);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2266 pTos->flags = MEM_Blob | MEM_Short;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2267 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2268 assert( zNewRecord!=(unsigned char *)zTemp );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2269 pTos->z = (char*)zNewRecord;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2270 pTos->flags = MEM_Blob | MEM_Dyn;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2271 pTos->xDel = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2272 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2273 pTos->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2274
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2275 /* If a NULL was encountered and jumpIfNull is non-zero, take the jump. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2276 if( jumpIfNull && containsNull ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2277 pc = jumpIfNull - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2278 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2279 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2280 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2281
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2282 /* Opcode: Statement P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2283 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2284 ** Begin an individual statement transaction which is part of a larger
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2285 ** BEGIN..COMMIT transaction. This is needed so that the statement
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2286 ** can be rolled back after an error without having to roll back the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2287 ** entire transaction. The statement transaction will automatically
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2288 ** commit when the VDBE halts.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2289 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2290 ** The statement is begun on the database file with index P1. The main
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2291 ** database file has an index of 0 and the file used for temporary tables
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2292 ** has an index of 1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2293 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2294 case OP_Statement: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2295 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2296 Btree *pBt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2297 if( i>=0 && i<db->nDb && (pBt = db->aDb[i].pBt)!=0 && !(db->autoCommit) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2298 assert( sqlite3BtreeIsInTrans(pBt) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2299 if( !sqlite3BtreeIsInStmt(pBt) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2300 rc = sqlite3BtreeBeginStmt(pBt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2301 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2302 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2303 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2304 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2305
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2306 /* Opcode: AutoCommit P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2307 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2308 ** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2309 ** back any currently active btree transactions. If there are any active
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2310 ** VMs (apart from this one), then the COMMIT or ROLLBACK statement fails.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2311 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2312 ** This instruction causes the VM to halt.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2313 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2314 case OP_AutoCommit: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2315 u8 i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2316 u8 rollback = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2317
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2318 assert( i==1 || i==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2319 assert( i==1 || rollback==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2320
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2321 assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2322
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2323 if( db->activeVdbeCnt>1 && i && !db->autoCommit ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2324 /* If this instruction implements a COMMIT or ROLLBACK, other VMs are
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2325 ** still running, and a transaction is active, return an error indicating
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2326 ** that the other VMs must complete first.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2327 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2328 sqlite3SetString(&p->zErrMsg, "cannot ", rollback?"rollback":"commit",
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2329 " transaction - SQL statements in progress", (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2330 rc = SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2331 }else if( i!=db->autoCommit ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2332 if( pOp->p2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2333 assert( i==1 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2334 sqlite3RollbackAll(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2335 db->autoCommit = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2336 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2337 db->autoCommit = i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2338 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2339 p->pTos = pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2340 p->pc = pc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2341 db->autoCommit = 1-i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2342 p->rc = SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2343 return SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2344 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2345 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2346 return SQLITE_DONE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2347 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2348 sqlite3SetString(&p->zErrMsg,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2349 (!i)?"cannot start a transaction within a transaction":(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2350 (rollback)?"cannot rollback - no transaction is active":
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2351 "cannot commit - no transaction is active"), (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2352
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2353 rc = SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2354 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2355 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2356 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2357
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2358 /* Opcode: Transaction P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2359 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2360 ** Begin a transaction. The transaction ends when a Commit or Rollback
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2361 ** opcode is encountered. Depending on the ON CONFLICT setting, the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2362 ** transaction might also be rolled back if an error is encountered.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2363 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2364 ** P1 is the index of the database file on which the transaction is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2365 ** started. Index 0 is the main database file and index 1 is the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2366 ** file used for temporary tables.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2367 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2368 ** If P2 is non-zero, then a write-transaction is started. A RESERVED lock is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2369 ** obtained on the database file when a write-transaction is started. No
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2370 ** other process can start another write transaction while this transaction is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2371 ** underway. Starting a write transaction also creates a rollback journal. A
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2372 ** write transaction must be started before any changes can be made to the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2373 ** database. If P2 is 2 or greater then an EXCLUSIVE lock is also obtained
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2374 ** on the file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2375 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2376 ** If P2 is zero, then a read-lock is obtained on the database file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2377 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2378 case OP_Transaction: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2379 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2380 Btree *pBt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2381
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2382 assert( i>=0 && i<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2383 pBt = db->aDb[i].pBt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2384
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2385 if( pBt ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2386 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2387 if( rc==SQLITE_BUSY ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2388 p->pc = pc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2389 p->rc = SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2390 p->pTos = pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2391 return SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2392 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2393 if( rc!=SQLITE_OK && rc!=SQLITE_READONLY /* && rc!=SQLITE_BUSY */ ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2394 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2395 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2396 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2397 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2398 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2399
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2400 /* Opcode: ReadCookie P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2401 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2402 ** Read cookie number P2 from database P1 and push it onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2403 ** P2==0 is the schema version. P2==1 is the database format.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2404 ** P2==2 is the recommended pager cache size, and so forth. P1==0 is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2405 ** the main database file and P1==1 is the database file used to store
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2406 ** temporary tables.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2407 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2408 ** There must be a read-lock on the database (either a transaction
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2409 ** must be started or there must be an open cursor) before
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2410 ** executing this instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2411 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2412 case OP_ReadCookie: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2413 int iMeta;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2414 assert( pOp->p2<SQLITE_N_BTREE_META );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2415 assert( pOp->p1>=0 && pOp->p1<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2416 assert( db->aDb[pOp->p1].pBt!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2417 /* The indexing of meta values at the schema layer is off by one from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2418 ** the indexing in the btree layer. The btree considers meta[0] to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2419 ** be the number of free pages in the database (a read-only value)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2420 ** and meta[1] to be the schema cookie. The schema layer considers
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2421 ** meta[1] to be the schema cookie. So we have to shift the index
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2422 ** by one in the following statement.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2423 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2424 rc = sqlite3BtreeGetMeta(db->aDb[pOp->p1].pBt, 1 + pOp->p2, (u32 *)&iMeta);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2425 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2426 pTos->i = iMeta;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2427 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2428 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2429 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2430
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2431 /* Opcode: SetCookie P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2432 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2433 ** Write the top of the stack into cookie number P2 of database P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2434 ** P2==0 is the schema version. P2==1 is the database format.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2435 ** P2==2 is the recommended pager cache size, and so forth. P1==0 is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2436 ** the main database file and P1==1 is the database file used to store
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2437 ** temporary tables.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2438 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2439 ** A transaction must be started before executing this opcode.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2440 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2441 case OP_SetCookie: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2442 Db *pDb;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2443 assert( pOp->p2<SQLITE_N_BTREE_META );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2444 assert( pOp->p1>=0 && pOp->p1<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2445 pDb = &db->aDb[pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2446 assert( pDb->pBt!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2447 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2448 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2449 /* See note about index shifting on OP_ReadCookie */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2450 rc = sqlite3BtreeUpdateMeta(pDb->pBt, 1+pOp->p2, (int)pTos->i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2451 if( pOp->p2==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2452 /* When the schema cookie changes, record the new cookie internally */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2453 pDb->pSchema->schema_cookie = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2454 db->flags |= SQLITE_InternChanges;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2455 }else if( pOp->p2==1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2456 /* Record changes in the file format */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2457 pDb->pSchema->file_format = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2458 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2459 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2460 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2461 if( pOp->p1==1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2462 /* Invalidate all prepared statements whenever the TEMP database
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2463 ** schema is changed. Ticket #1644 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2464 sqlite3ExpirePreparedStatements(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2465 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2466 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2467 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2468
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2469 /* Opcode: VerifyCookie P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2470 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2471 ** Check the value of global database parameter number 0 (the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2472 ** schema version) and make sure it is equal to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2473 ** P1 is the database number which is 0 for the main database file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2474 ** and 1 for the file holding temporary tables and some higher number
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2475 ** for auxiliary databases.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2476 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2477 ** The cookie changes its value whenever the database schema changes.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2478 ** This operation is used to detect when that the cookie has changed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2479 ** and that the current process needs to reread the schema.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2480 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2481 ** Either a transaction needs to have been started or an OP_Open needs
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2482 ** to be executed (to establish a read lock) before this opcode is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2483 ** invoked.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2484 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2485 case OP_VerifyCookie: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2486 int iMeta;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2487 Btree *pBt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2488 assert( pOp->p1>=0 && pOp->p1<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2489 pBt = db->aDb[pOp->p1].pBt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2490 if( pBt ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2491 rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&iMeta);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2492 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2493 rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2494 iMeta = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2495 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2496 if( rc==SQLITE_OK && iMeta!=pOp->p2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2497 sqlite3SetString(&p->zErrMsg, "database schema has changed", (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2498 rc = SQLITE_SCHEMA;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2499 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2500 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2501 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2502
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2503 /* Opcode: OpenRead P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2504 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2505 ** Open a read-only cursor for the database table whose root page is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2506 ** P2 in a database file. The database file is determined by an
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2507 ** integer from the top of the stack. 0 means the main database and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2508 ** 1 means the database used for temporary tables. Give the new
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2509 ** cursor an identifier of P1. The P1 values need not be contiguous
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2510 ** but all P1 values should be small integers. It is an error for
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2511 ** P1 to be negative.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2512 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2513 ** If P2==0 then take the root page number from the next of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2514 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2515 ** There will be a read lock on the database whenever there is an
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2516 ** open cursor. If the database was unlocked prior to this instruction
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2517 ** then a read lock is acquired as part of this instruction. A read
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2518 ** lock allows other processes to read the database but prohibits
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2519 ** any other process from modifying the database. The read lock is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2520 ** released when all cursors are closed. If this instruction attempts
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2521 ** to get a read lock but fails, the script terminates with an
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2522 ** SQLITE_BUSY error code.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2523 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2524 ** The P3 value is a pointer to a KeyInfo structure that defines the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2525 ** content and collating sequence of indices. P3 is NULL for cursors
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2526 ** that are not pointing to indices.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2527 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2528 ** See also OpenWrite.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2529 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2530 /* Opcode: OpenWrite P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2531 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2532 ** Open a read/write cursor named P1 on the table or index whose root
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2533 ** page is P2. If P2==0 then take the root page number from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2534 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2535 ** The P3 value is a pointer to a KeyInfo structure that defines the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2536 ** content and collating sequence of indices. P3 is NULL for cursors
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2537 ** that are not pointing to indices.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2538 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2539 ** This instruction works just like OpenRead except that it opens the cursor
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2540 ** in read/write mode. For a given table, there can be one or more read-only
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2541 ** cursors or a single read/write cursor but not both.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2542 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2543 ** See also OpenRead.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2544 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2545 case OP_OpenRead: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2546 case OP_OpenWrite: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2547 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2548 int p2 = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2549 int wrFlag;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2550 Btree *pX;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2551 int iDb;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2552 Cursor *pCur;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2553 Db *pDb;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2554
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2555 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2556 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2557 iDb = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2558 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2559 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2560 assert( iDb>=0 && iDb<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2561 pDb = &db->aDb[iDb];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2562 pX = pDb->pBt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2563 assert( pX!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2564 if( pOp->opcode==OP_OpenWrite ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2565 wrFlag = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2566 if( pDb->pSchema->file_format < p->minWriteFileFormat ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2567 p->minWriteFileFormat = pDb->pSchema->file_format;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2568 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2569 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2570 wrFlag = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2571 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2572 if( p2<=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2573 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2574 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2575 p2 = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2576 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2577 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2578 assert( p2>=2 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2579 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2580 assert( i>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2581 pCur = allocateCursor(p, i, iDb);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2582 if( pCur==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2583 pCur->nullRow = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2584 if( pX==0 ) break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2585 /* We always provide a key comparison function. If the table being
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2586 ** opened is of type INTKEY, the comparision function will be ignored. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2587 rc = sqlite3BtreeCursor(pX, p2, wrFlag,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2588 sqlite3VdbeRecordCompare, pOp->p3,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2589 &pCur->pCursor);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2590 if( pOp->p3type==P3_KEYINFO ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2591 pCur->pKeyInfo = (KeyInfo*)pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2592 pCur->pIncrKey = &pCur->pKeyInfo->incrKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2593 pCur->pKeyInfo->enc = ENC(p->db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2594 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2595 pCur->pKeyInfo = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2596 pCur->pIncrKey = &pCur->bogusIncrKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2597 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2598 switch( rc ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2599 case SQLITE_BUSY: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2600 p->pc = pc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2601 p->rc = SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2602 p->pTos = &pTos[1 + (pOp->p2<=0)]; /* Operands must remain on stack */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2603 return SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2604 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2605 case SQLITE_OK: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2606 int flags = sqlite3BtreeFlags(pCur->pCursor);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2607 /* Sanity checking. Only the lower four bits of the flags byte should
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2608 ** be used. Bit 3 (mask 0x08) is unpreditable. The lower 3 bits
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2609 ** (mask 0x07) should be either 5 (intkey+leafdata for tables) or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2610 ** 2 (zerodata for indices). If these conditions are not met it can
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2611 ** only mean that we are dealing with a corrupt database file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2612 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2613 if( (flags & 0xf0)!=0 || ((flags & 0x07)!=5 && (flags & 0x07)!=2) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2614 rc = SQLITE_CORRUPT_BKPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2615 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2616 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2617 pCur->isTable = (flags & BTREE_INTKEY)!=0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2618 pCur->isIndex = (flags & BTREE_ZERODATA)!=0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2619 /* If P3==0 it means we are expected to open a table. If P3!=0 then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2620 ** we expect to be opening an index. If this is not what happened,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2621 ** then the database is corrupt
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2622 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2623 if( (pCur->isTable && pOp->p3type==P3_KEYINFO)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2624 || (pCur->isIndex && pOp->p3type!=P3_KEYINFO) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2625 rc = SQLITE_CORRUPT_BKPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2626 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2627 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2628 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2629 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2630 case SQLITE_EMPTY: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2631 pCur->isTable = pOp->p3type!=P3_KEYINFO;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2632 pCur->isIndex = !pCur->isTable;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2633 rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2634 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2635 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2636 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2637 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2638 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2639 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2640 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2641 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2642
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2643 /* Opcode: OpenVirtual P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2644 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2645 ** Open a new cursor P1 to a transient or virtual table.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2646 ** The cursor is always opened read/write even if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2647 ** the main database is read-only. The transient or virtual
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2648 ** table is deleted automatically when the cursor is closed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2649 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2650 ** P2 is the number of columns in the virtual table.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2651 ** The cursor points to a BTree table if P3==0 and to a BTree index
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2652 ** if P3 is not 0. If P3 is not NULL, it points to a KeyInfo structure
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2653 ** that defines the format of keys in the index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2654 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2655 case OP_OpenVirtual: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2656 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2657 Cursor *pCx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2658 assert( i>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2659 pCx = allocateCursor(p, i, -1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2660 if( pCx==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2661 pCx->nullRow = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2662 rc = sqlite3BtreeFactory(db, 0, 1, TEMP_PAGES, &pCx->pBt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2663 if( rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2664 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2665 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2666 if( rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2667 /* If a transient index is required, create it by calling
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2668 ** sqlite3BtreeCreateTable() with the BTREE_ZERODATA flag before
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2669 ** opening it. If a transient table is required, just use the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2670 ** automatically created table with root-page 1 (an INTKEY table).
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2671 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2672 if( pOp->p3 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2673 int pgno;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2674 assert( pOp->p3type==P3_KEYINFO );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2675 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_ZERODATA);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2676 if( rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2677 assert( pgno==MASTER_ROOT+1 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2678 rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, sqlite3VdbeRecordCompare,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2679 pOp->p3, &pCx->pCursor);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2680 pCx->pKeyInfo = (KeyInfo*)pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2681 pCx->pKeyInfo->enc = ENC(p->db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2682 pCx->pIncrKey = &pCx->pKeyInfo->incrKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2683 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2684 pCx->isTable = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2685 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2686 rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, 0, &pCx->pCursor);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2687 pCx->isTable = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2688 pCx->pIncrKey = &pCx->bogusIncrKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2689 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2690 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2691 pCx->nField = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2692 pCx->isIndex = !pCx->isTable;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2693 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2694 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2695
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2696 /* Opcode: OpenPseudo P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2697 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2698 ** Open a new cursor that points to a fake table that contains a single
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2699 ** row of data. Any attempt to write a second row of data causes the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2700 ** first row to be deleted. All data is deleted when the cursor is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2701 ** closed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2702 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2703 ** A pseudo-table created by this opcode is useful for holding the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2704 ** NEW or OLD tables in a trigger. Also used to hold the a single
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2705 ** row output from the sorter so that the row can be decomposed into
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2706 ** individual columns using the OP_Column opcode.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2707 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2708 case OP_OpenPseudo: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2709 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2710 Cursor *pCx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2711 assert( i>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2712 pCx = allocateCursor(p, i, -1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2713 if( pCx==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2714 pCx->nullRow = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2715 pCx->pseudoTable = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2716 pCx->pIncrKey = &pCx->bogusIncrKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2717 pCx->isTable = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2718 pCx->isIndex = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2719 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2720 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2721
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2722 /* Opcode: Close P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2723 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2724 ** Close a cursor previously opened as P1. If P1 is not
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2725 ** currently open, this instruction is a no-op.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2726 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2727 case OP_Close: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2728 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2729 if( i>=0 && i<p->nCursor ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2730 sqlite3VdbeFreeCursor(p->apCsr[i]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2731 p->apCsr[i] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2732 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2733 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2734 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2735
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2736 /* Opcode: MoveGe P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2737 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2738 ** Pop the top of the stack and use its value as a key. Reposition
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2739 ** cursor P1 so that it points to the smallest entry that is greater
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2740 ** than or equal to the key that was popped ffrom the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2741 ** If there are no records greater than or equal to the key and P2
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2742 ** is not zero, then jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2743 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2744 ** See also: Found, NotFound, Distinct, MoveLt, MoveGt, MoveLe
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2745 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2746 /* Opcode: MoveGt P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2747 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2748 ** Pop the top of the stack and use its value as a key. Reposition
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2749 ** cursor P1 so that it points to the smallest entry that is greater
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2750 ** than the key from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2751 ** If there are no records greater than the key and P2 is not zero,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2752 ** then jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2753 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2754 ** See also: Found, NotFound, Distinct, MoveLt, MoveGe, MoveLe
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2755 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2756 /* Opcode: MoveLt P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2757 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2758 ** Pop the top of the stack and use its value as a key. Reposition
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2759 ** cursor P1 so that it points to the largest entry that is less
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2760 ** than the key from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2761 ** If there are no records less than the key and P2 is not zero,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2762 ** then jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2763 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2764 ** See also: Found, NotFound, Distinct, MoveGt, MoveGe, MoveLe
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2765 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2766 /* Opcode: MoveLe P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2767 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2768 ** Pop the top of the stack and use its value as a key. Reposition
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2769 ** cursor P1 so that it points to the largest entry that is less than
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2770 ** or equal to the key that was popped from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2771 ** If there are no records less than or eqal to the key and P2 is not zero,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2772 ** then jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2773 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2774 ** See also: Found, NotFound, Distinct, MoveGt, MoveGe, MoveLt
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2775 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2776 case OP_MoveLt: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2777 case OP_MoveLe: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2778 case OP_MoveGe: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2779 case OP_MoveGt: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2780 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2781 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2782
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2783 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2784 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2785 pC = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2786 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2787 if( pC->pCursor!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2788 int res, oc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2789 oc = pOp->opcode;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2790 pC->nullRow = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2791 *pC->pIncrKey = oc==OP_MoveGt || oc==OP_MoveLe;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2792 if( pC->isTable ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2793 i64 iKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2794 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2795 iKey = intToKey(pTos->i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2796 if( pOp->p2==0 && pOp->opcode==OP_MoveGe ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2797 pC->movetoTarget = iKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2798 pC->deferredMoveto = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2799 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2800 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2801 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2802 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2803 rc = sqlite3BtreeMoveto(pC->pCursor, 0, (u64)iKey, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2804 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2805 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2806 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2807 pC->lastRowid = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2808 pC->rowidIsValid = res==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2809 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2810 assert( pTos->flags & MEM_Blob );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2811 /* Stringify(pTos, encoding); */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2812 rc = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2813 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2814 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2815 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2816 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2817 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2818 pC->deferredMoveto = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2819 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2820 *pC->pIncrKey = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2821 sqlite3_search_count++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2822 if( oc==OP_MoveGe || oc==OP_MoveGt ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2823 if( res<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2824 rc = sqlite3BtreeNext(pC->pCursor, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2825 if( rc!=SQLITE_OK ) goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2826 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2827 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2828 res = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2829 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2830 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2831 assert( oc==OP_MoveLt || oc==OP_MoveLe );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2832 if( res>=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2833 rc = sqlite3BtreePrevious(pC->pCursor, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2834 if( rc!=SQLITE_OK ) goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2835 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2836 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2837 /* res might be negative because the table is empty. Check to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2838 ** see if this is the case.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2839 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2840 res = sqlite3BtreeEof(pC->pCursor);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2841 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2842 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2843 if( res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2844 if( pOp->p2>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2845 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2846 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2847 pC->nullRow = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2848 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2849 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2850 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2851 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2852 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2853 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2854 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2855
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2856 /* Opcode: Distinct P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2857 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2858 ** Use the top of the stack as a record created using MakeRecord. P1 is a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2859 ** cursor on a table that declared as an index. If that table contains an
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2860 ** entry that matches the top of the stack fall thru. If the top of the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2861 ** matches no entry in P1 then jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2862 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2863 ** The cursor is left pointing at the matching entry if it exists. The
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2864 ** record on the top of the stack is not popped.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2865 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2866 ** This instruction is similar to NotFound except that this operation
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2867 ** does not pop the key from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2868 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2869 ** The instruction is used to implement the DISTINCT operator on SELECT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2870 ** statements. The P1 table is not a true index but rather a record of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2871 ** all results that have produced so far.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2872 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2873 ** See also: Found, NotFound, MoveTo, IsUnique, NotExists
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2874 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2875 /* Opcode: Found P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2876 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2877 ** Top of the stack holds a blob constructed by MakeRecord. P1 is an index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2878 ** If an entry that matches the top of the stack exists in P1 then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2879 ** jump to P2. If the top of the stack does not match any entry in P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2880 ** then fall thru. The P1 cursor is left pointing at the matching entry
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2881 ** if it exists. The blob is popped off the top of the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2882 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2883 ** This instruction is used to implement the IN operator where the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2884 ** left-hand side is a SELECT statement. P1 is not a true index but
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2885 ** is instead a temporary index that holds the results of the SELECT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2886 ** statement. This instruction just checks to see if the left-hand side
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2887 ** of the IN operator (stored on the top of the stack) exists in the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2888 ** result of the SELECT statement.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2889 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2890 ** See also: Distinct, NotFound, MoveTo, IsUnique, NotExists
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2891 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2892 /* Opcode: NotFound P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2893 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2894 ** The top of the stack holds a blob constructed by MakeRecord. P1 is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2895 ** an index. If no entry exists in P1 that matches the blob then jump
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2896 ** to P1. If an entry does existing, fall through. The cursor is left
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2897 ** pointing to the entry that matches. The blob is popped from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2898 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2899 ** The difference between this operation and Distinct is that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2900 ** Distinct does not pop the key from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2901 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2902 ** See also: Distinct, Found, MoveTo, NotExists, IsUnique
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2903 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2904 case OP_Distinct: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2905 case OP_NotFound: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2906 case OP_Found: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2907 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2908 int alreadyExists = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2909 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2910 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2911 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2912 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2913 if( (pC = p->apCsr[i])->pCursor!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2914 int res, rx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2915 assert( pC->isTable==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2916 Stringify(pTos, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2917 rx = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2918 alreadyExists = rx==SQLITE_OK && res==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2919 pC->deferredMoveto = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2920 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2921 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2922 if( pOp->opcode==OP_Found ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2923 if( alreadyExists ) pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2924 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2925 if( !alreadyExists ) pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2926 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2927 if( pOp->opcode!=OP_Distinct ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2928 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2929 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2930 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2931 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2932 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2933
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2934 /* Opcode: IsUnique P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2935 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2936 ** The top of the stack is an integer record number. Call this
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2937 ** record number R. The next on the stack is an index key created
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2938 ** using MakeIdxRec. Call it K. This instruction pops R from the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2939 ** stack but it leaves K unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2940 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2941 ** P1 is an index. So it has no data and its key consists of a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2942 ** record generated by OP_MakeRecord where the last field is the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2943 ** rowid of the entry that the index refers to.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2944 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2945 ** This instruction asks if there is an entry in P1 where the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2946 ** fields matches K but the rowid is different from R.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2947 ** If there is no such entry, then there is an immediate
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2948 ** jump to P2. If any entry does exist where the index string
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2949 ** matches K but the record number is not R, then the record
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2950 ** number for that entry is pushed onto the stack and control
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2951 ** falls through to the next instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2952 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2953 ** See also: Distinct, NotFound, NotExists, Found
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2954 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2955 case OP_IsUnique: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2956 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2957 Mem *pNos = &pTos[-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2958 Cursor *pCx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2959 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2960 i64 R;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2961
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2962 /* Pop the value R off the top of the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2963 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2964 assert( pNos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2965 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2966 R = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2967 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2968 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2969 assert( i>=0 && i<=p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2970 pCx = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2971 assert( pCx!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2972 pCrsr = pCx->pCursor;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2973 if( pCrsr!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2974 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2975 i64 v; /* The record number on the P1 entry that matches K */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2976 char *zKey; /* The value of K */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2977 int nKey; /* Number of bytes in K */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2978 int len; /* Number of bytes in K without the rowid at the end */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2979 int szRowid; /* Size of the rowid column at the end of zKey */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2980
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2981 /* Make sure K is a string and make zKey point to K
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2982 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2983 Stringify(pNos, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2984 zKey = pNos->z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2985 nKey = pNos->n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2986
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2987 szRowid = sqlite3VdbeIdxRowidLen((u8*)zKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2988 len = nKey-szRowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2989
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2990 /* Search for an entry in P1 where all but the last four bytes match K.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2991 ** If there is no such entry, jump immediately to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2992 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2993 assert( pCx->deferredMoveto==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2994 pCx->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2995 rc = sqlite3BtreeMoveto(pCrsr, zKey, len, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2996 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2997 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2998 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2999 if( res<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3000 rc = sqlite3BtreeNext(pCrsr, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3001 if( res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3002 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3003 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3004 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3005 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3006 rc = sqlite3VdbeIdxKeyCompare(pCx, len, (u8*)zKey, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3007 if( rc!=SQLITE_OK ) goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3008 if( res>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3009 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3010 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3011 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3012
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3013 /* At this point, pCrsr is pointing to an entry in P1 where all but
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3014 ** the final entry (the rowid) matches K. Check to see if the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3015 ** final rowid column is different from R. If it equals R then jump
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3016 ** immediately to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3017 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3018 rc = sqlite3VdbeIdxRowid(pCrsr, &v);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3019 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3020 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3021 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3022 if( v==R ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3023 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3024 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3025 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3026
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3027 /* The final varint of the key is different from R. Push it onto
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3028 ** the stack. (The record number of an entry that violates a UNIQUE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3029 ** constraint.)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3030 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3031 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3032 pTos->i = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3033 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3034 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3035 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3036 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3037
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3038 /* Opcode: NotExists P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3039 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3040 ** Use the top of the stack as a integer key. If a record with that key
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3041 ** does not exist in table of P1, then jump to P2. If the record
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3042 ** does exist, then fall thru. The cursor is left pointing to the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3043 ** record if it exists. The integer key is popped from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3044 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3045 ** The difference between this operation and NotFound is that this
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3046 ** operation assumes the key is an integer and that P1 is a table whereas
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3047 ** NotFound assumes key is a blob constructed from MakeRecord and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3048 ** P1 is an index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3049 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3050 ** See also: Distinct, Found, MoveTo, NotFound, IsUnique
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3051 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3052 case OP_NotExists: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3053 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3054 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3055 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3056 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3057 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3058 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3059 if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3060 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3061 u64 iKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3062 assert( pTos->flags & MEM_Int );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3063 assert( p->apCsr[i]->isTable );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3064 iKey = intToKey(pTos->i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3065 rc = sqlite3BtreeMoveto(pCrsr, 0, iKey, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3066 pC->lastRowid = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3067 pC->rowidIsValid = res==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3068 pC->nullRow = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3069 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3070 if( res!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3071 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3072 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3073 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3074 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3075 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3076 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3077 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3078 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3079
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3080 /* Opcode: Sequence P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3081 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3082 ** Push an integer onto the stack which is the next available
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3083 ** sequence number for cursor P1. The sequence number on the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3084 ** cursor is incremented after the push.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3085 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3086 case OP_Sequence: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3087 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3088 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3089 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3090 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3091 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3092 pTos->i = p->apCsr[i]->seqCount++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3093 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3094 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3095 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3096
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3097
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3098 /* Opcode: NewRowid P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3099 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3100 ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3101 ** The record number is not previously used as a key in the database
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3102 ** table that cursor P1 points to. The new record number is pushed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3103 ** onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3104 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3105 ** If P2>0 then P2 is a memory cell that holds the largest previously
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3106 ** generated record number. No new record numbers are allowed to be less
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3107 ** than this value. When this value reaches its maximum, a SQLITE_FULL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3108 ** error is generated. The P2 memory cell is updated with the generated
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3109 ** record number. This P2 mechanism is used to help implement the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3110 ** AUTOINCREMENT feature.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3111 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3112 case OP_NewRowid: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3113 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3114 i64 v = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3115 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3116 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3117 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3118 if( (pC = p->apCsr[i])->pCursor==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3119 /* The zero initialization above is all that is needed */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3120 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3121 /* The next rowid or record number (different terms for the same
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3122 ** thing) is obtained in a two-step algorithm.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3123 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3124 ** First we attempt to find the largest existing rowid and add one
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3125 ** to that. But if the largest existing rowid is already the maximum
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3126 ** positive integer, we have to fall through to the second
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3127 ** probabilistic algorithm
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3128 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3129 ** The second algorithm is to select a rowid at random and see if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3130 ** it already exists in the table. If it does not exist, we have
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3131 ** succeeded. If the random rowid does exist, we select a new one
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3132 ** and try again, up to 1000 times.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3133 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3134 ** For a table with less than 2 billion entries, the probability
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3135 ** of not finding a unused rowid is about 1.0e-300. This is a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3136 ** non-zero probability, but it is still vanishingly small and should
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3137 ** never cause a problem. You are much, much more likely to have a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3138 ** hardware failure than for this algorithm to fail.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3139 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3140 ** The analysis in the previous paragraph assumes that you have a good
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3141 ** source of random numbers. Is a library function like lrand48()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3142 ** good enough? Maybe. Maybe not. It's hard to know whether there
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3143 ** might be subtle bugs is some implementations of lrand48() that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3144 ** could cause problems. To avoid uncertainty, SQLite uses its own
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3145 ** random number generator based on the RC4 algorithm.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3146 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3147 ** To promote locality of reference for repetitive inserts, the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3148 ** first few attempts at chosing a random rowid pick values just a little
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3149 ** larger than the previous rowid. This has been shown experimentally
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3150 ** to double the speed of the COPY operation.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3151 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3152 int res, rx=SQLITE_OK, cnt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3153 i64 x;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3154 cnt = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3155 if( (sqlite3BtreeFlags(pC->pCursor)&(BTREE_INTKEY|BTREE_ZERODATA)) !=
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3156 BTREE_INTKEY ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3157 rc = SQLITE_CORRUPT_BKPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3158 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3159 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3160 assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_INTKEY)!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3161 assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_ZERODATA)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3162
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3163 #ifdef SQLITE_32BIT_ROWID
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3164 # define MAX_ROWID 0x7fffffff
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3165 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3166 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3167 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3168 ** to provide the constant while making all compilers happy.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3169 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3170 # define MAX_ROWID ( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3171 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3172
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3173 if( !pC->useRandomRowid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3174 if( pC->nextRowidValid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3175 v = pC->nextRowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3176 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3177 rc = sqlite3BtreeLast(pC->pCursor, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3178 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3179 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3180 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3181 if( res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3182 v = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3183 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3184 sqlite3BtreeKeySize(pC->pCursor, &v);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3185 v = keyToInt(v);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3186 if( v==MAX_ROWID ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3187 pC->useRandomRowid = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3188 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3189 v++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3190 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3191 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3192 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3193
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3194 #ifndef SQLITE_OMIT_AUTOINCREMENT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3195 if( pOp->p2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3196 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3197 assert( pOp->p2>0 && pOp->p2<p->nMem ); /* P2 is a valid memory cell */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3198 pMem = &p->aMem[pOp->p2];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3199 sqlite3VdbeMemIntegerify(pMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3200 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P2) holds an integer */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3201 if( pMem->i==MAX_ROWID || pC->useRandomRowid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3202 rc = SQLITE_FULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3203 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3204 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3205 if( v<pMem->i+1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3206 v = pMem->i + 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3207 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3208 pMem->i = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3209 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3210 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3211
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3212 if( v<MAX_ROWID ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3213 pC->nextRowidValid = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3214 pC->nextRowid = v+1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3215 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3216 pC->nextRowidValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3217 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3218 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3219 if( pC->useRandomRowid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3220 assert( pOp->p2==0 ); /* SQLITE_FULL must have occurred prior to this */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3221 v = db->priorNewRowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3222 cnt = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3223 do{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3224 if( v==0 || cnt>2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3225 sqlite3Randomness(sizeof(v), &v);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3226 if( cnt<5 ) v &= 0xffffff;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3227 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3228 unsigned char r;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3229 sqlite3Randomness(1, &r);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3230 v += r + 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3231 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3232 if( v==0 ) continue;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3233 x = intToKey(v);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3234 rx = sqlite3BtreeMoveto(pC->pCursor, 0, (u64)x, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3235 cnt++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3236 }while( cnt<1000 && rx==SQLITE_OK && res==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3237 db->priorNewRowid = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3238 if( rx==SQLITE_OK && res==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3239 rc = SQLITE_FULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3240 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3241 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3242 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3243 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3244 pC->deferredMoveto = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3245 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3246 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3247 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3248 pTos->i = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3249 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3250 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3251 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3252
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3253 /* Opcode: Insert P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3254 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3255 ** Write an entry into the table of cursor P1. A new entry is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3256 ** created if it doesn't already exist or the data for an existing
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3257 ** entry is overwritten. The data is the value on the top of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3258 ** stack. The key is the next value down on the stack. The key must
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3259 ** be an integer. The stack is popped twice by this instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3260 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3261 ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3262 ** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P2 is set,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3263 ** then rowid is stored for subsequent return by the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3264 ** sqlite3_last_insert_rowid() function (otherwise it's unmodified).
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3265 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3266 ** This instruction only works on tables. The equivalent instruction
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3267 ** for indices is OP_IdxInsert.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3268 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3269 case OP_Insert: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3270 Mem *pNos = &pTos[-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3271 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3272 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3273 assert( pNos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3274 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3275 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3276 if( ((pC = p->apCsr[i])->pCursor!=0 || pC->pseudoTable) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3277 i64 iKey; /* The integer ROWID or key for the record to be inserted */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3278
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3279 assert( pNos->flags & MEM_Int );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3280 assert( pC->isTable );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3281 iKey = intToKey(pNos->i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3282
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3283 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3284 if( pOp->p2 & OPFLAG_LASTROWID ) db->lastRowid = pNos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3285 if( pC->nextRowidValid && pNos->i>=pC->nextRowid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3286 pC->nextRowidValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3287 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3288 if( pTos->flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3289 pTos->z = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3290 pTos->n = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3291 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3292 assert( pTos->flags & (MEM_Blob|MEM_Str) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3293 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3294 if( pC->pseudoTable ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3295 sqliteFree(pC->pData);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3296 pC->iKey = iKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3297 pC->nData = pTos->n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3298 if( pTos->flags & MEM_Dyn ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3299 pC->pData = pTos->z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3300 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3301 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3302 pC->pData = sqliteMallocRaw( pC->nData+2 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3303 if( !pC->pData ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3304 memcpy(pC->pData, pTos->z, pC->nData);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3305 pC->pData[pC->nData] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3306 pC->pData[pC->nData+1] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3307 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3308 pC->nullRow = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3309 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3310 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, pTos->z, pTos->n);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3311 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3312
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3313 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3314 pC->deferredMoveto = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3315 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3316
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3317 /* Invoke the update-hook if required. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3318 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p3 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3319 const char *zDb = db->aDb[pC->iDb].zName;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3320 const char *zTbl = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3321 int op = ((pOp->p2 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3322 assert( pC->isTable );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3323 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3324 assert( pC->iDb>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3325 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3326 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3327 popStack(&pTos, 2);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3328
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3329 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3330 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3331
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3332 /* Opcode: Delete P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3333 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3334 ** Delete the record at which the P1 cursor is currently pointing.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3335 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3336 ** The cursor will be left pointing at either the next or the previous
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3337 ** record in the table. If it is left pointing at the next record, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3338 ** the next Next instruction will be a no-op. Hence it is OK to delete
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3339 ** a record from within an Next loop.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3340 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3341 ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3342 ** incremented (otherwise not).
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3343 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3344 ** If P1 is a pseudo-table, then this instruction is a no-op.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3345 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3346 case OP_Delete: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3347 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3348 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3349 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3350 pC = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3351 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3352 if( pC->pCursor!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3353 i64 iKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3354
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3355 /* If the update-hook will be invoked, set iKey to the rowid of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3356 ** row being deleted.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3357 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3358 if( db->xUpdateCallback && pOp->p3 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3359 assert( pC->isTable );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3360 if( pC->rowidIsValid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3361 iKey = pC->lastRowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3362 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3363 rc = sqlite3BtreeKeySize(pC->pCursor, &iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3364 if( rc ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3365 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3366 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3367 iKey = keyToInt(iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3368 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3369 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3370
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3371 rc = sqlite3VdbeCursorMoveto(pC);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3372 if( rc ) goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3373 rc = sqlite3BtreeDelete(pC->pCursor);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3374 pC->nextRowidValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3375 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3376
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3377 /* Invoke the update-hook if required. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3378 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p3 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3379 const char *zDb = db->aDb[pC->iDb].zName;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3380 const char *zTbl = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3381 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3382 assert( pC->iDb>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3383 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3384 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3385 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3386 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3387 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3388
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3389 /* Opcode: ResetCount P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3390 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3391 ** This opcode resets the VMs internal change counter to 0. If P1 is true,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3392 ** then the value of the change counter is copied to the database handle
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3393 ** change counter (returned by subsequent calls to sqlite3_changes())
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3394 ** before it is reset. This is used by trigger programs.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3395 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3396 case OP_ResetCount: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3397 if( pOp->p1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3398 sqlite3VdbeSetChanges(db, p->nChange);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3399 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3400 p->nChange = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3401 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3402 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3403
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3404 /* Opcode: RowData P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3405 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3406 ** Push onto the stack the complete row data for cursor P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3407 ** There is no interpretation of the data. It is just copied
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3408 ** onto the stack exactly as it is found in the database file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3409 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3410 ** If the cursor is not pointing to a valid row, a NULL is pushed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3411 ** onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3412 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3413 /* Opcode: RowKey P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3414 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3415 ** Push onto the stack the complete row key for cursor P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3416 ** There is no interpretation of the key. It is just copied
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3417 ** onto the stack exactly as it is found in the database file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3418 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3419 ** If the cursor is not pointing to a valid row, a NULL is pushed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3420 ** onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3421 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3422 case OP_RowKey:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3423 case OP_RowData: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3424 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3425 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3426 u32 n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3427
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3428 /* Note that RowKey and RowData are really exactly the same instruction */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3429 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3430 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3431 pC = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3432 assert( pC->isTable || pOp->opcode==OP_RowKey );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3433 assert( pC->isIndex || pOp->opcode==OP_RowData );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3434 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3435 if( pC->nullRow ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3436 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3437 }else if( pC->pCursor!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3438 BtCursor *pCrsr = pC->pCursor;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3439 rc = sqlite3VdbeCursorMoveto(pC);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3440 if( rc ) goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3441 if( pC->nullRow ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3442 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3443 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3444 }else if( pC->isIndex ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3445 i64 n64;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3446 assert( !pC->isTable );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3447 sqlite3BtreeKeySize(pCrsr, &n64);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3448 n = n64;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3449 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3450 sqlite3BtreeDataSize(pCrsr, &n);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3451 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3452 pTos->n = n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3453 if( n<=NBFS ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3454 pTos->flags = MEM_Blob | MEM_Short;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3455 pTos->z = pTos->zShort;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3456 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3457 char *z = sqliteMallocRaw( n );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3458 if( z==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3459 pTos->flags = MEM_Blob | MEM_Dyn;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3460 pTos->xDel = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3461 pTos->z = z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3462 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3463 if( pC->isIndex ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3464 sqlite3BtreeKey(pCrsr, 0, n, pTos->z);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3465 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3466 sqlite3BtreeData(pCrsr, 0, n, pTos->z);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3467 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3468 }else if( pC->pseudoTable ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3469 pTos->n = pC->nData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3470 pTos->z = pC->pData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3471 pTos->flags = MEM_Blob|MEM_Ephem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3472 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3473 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3474 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3475 pTos->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3476 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3477 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3478
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3479 /* Opcode: Rowid P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3480 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3481 ** Push onto the stack an integer which is the key of the table entry that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3482 ** P1 is currently point to.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3483 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3484 case OP_Rowid: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3485 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3486 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3487 i64 v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3488
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3489 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3490 pC = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3491 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3492 rc = sqlite3VdbeCursorMoveto(pC);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3493 if( rc ) goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3494 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3495 if( pC->rowidIsValid ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3496 v = pC->lastRowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3497 }else if( pC->pseudoTable ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3498 v = keyToInt(pC->iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3499 }else if( pC->nullRow || pC->pCursor==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3500 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3501 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3502 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3503 assert( pC->pCursor!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3504 sqlite3BtreeKeySize(pC->pCursor, &v);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3505 v = keyToInt(v);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3506 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3507 pTos->i = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3508 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3509 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3510 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3511
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3512 /* Opcode: NullRow P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3513 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3514 ** Move the cursor P1 to a null row. Any OP_Column operations
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3515 ** that occur while the cursor is on the null row will always push
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3516 ** a NULL onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3517 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3518 case OP_NullRow: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3519 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3520 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3521
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3522 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3523 pC = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3524 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3525 pC->nullRow = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3526 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3527 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3528 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3529
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3530 /* Opcode: Last P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3531 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3532 ** The next use of the Rowid or Column or Next instruction for P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3533 ** will refer to the last entry in the database table or index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3534 ** If the table or index is empty and P2>0, then jump immediately to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3535 ** If P2 is 0 or if the table or index is not empty, fall through
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3536 ** to the following instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3537 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3538 case OP_Last: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3539 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3540 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3541 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3542
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3543 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3544 pC = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3545 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3546 if( (pCrsr = pC->pCursor)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3547 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3548 rc = sqlite3BtreeLast(pCrsr, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3549 pC->nullRow = res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3550 pC->deferredMoveto = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3551 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3552 if( res && pOp->p2>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3553 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3554 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3555 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3556 pC->nullRow = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3557 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3558 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3559 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3560
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3561
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3562 /* Opcode: Sort P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3563 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3564 ** This opcode does exactly the same thing as OP_Rewind except that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3565 ** it increments an undocumented global variable used for testing.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3566 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3567 ** Sorting is accomplished by writing records into a sorting index,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3568 ** then rewinding that index and playing it back from beginning to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3569 ** end. We use the OP_Sort opcode instead of OP_Rewind to do the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3570 ** rewinding so that the global variable will be incremented and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3571 ** regression tests can determine whether or not the optimizer is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3572 ** correctly optimizing out sorts.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3573 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3574 case OP_Sort: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3575 sqlite3_sort_count++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3576 sqlite3_search_count--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3577 /* Fall through into OP_Rewind */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3578 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3579 /* Opcode: Rewind P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3580 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3581 ** The next use of the Rowid or Column or Next instruction for P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3582 ** will refer to the first entry in the database table or index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3583 ** If the table or index is empty and P2>0, then jump immediately to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3584 ** If P2 is 0 or if the table or index is not empty, fall through
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3585 ** to the following instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3586 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3587 case OP_Rewind: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3588 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3589 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3590 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3591 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3592
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3593 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3594 pC = p->apCsr[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3595 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3596 if( (pCrsr = pC->pCursor)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3597 rc = sqlite3BtreeFirst(pCrsr, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3598 pC->atFirst = res==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3599 pC->deferredMoveto = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3600 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3601 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3602 res = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3603 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3604 pC->nullRow = res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3605 if( res && pOp->p2>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3606 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3607 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3608 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3609 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3610
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3611 /* Opcode: Next P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3612 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3613 ** Advance cursor P1 so that it points to the next key/data pair in its
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3614 ** table or index. If there are no more key/value pairs then fall through
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3615 ** to the following instruction. But if the cursor advance was successful,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3616 ** jump immediately to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3617 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3618 ** See also: Prev
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3619 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3620 /* Opcode: Prev P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3621 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3622 ** Back up cursor P1 so that it points to the previous key/data pair in its
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3623 ** table or index. If there is no previous key/value pairs then fall through
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3624 ** to the following instruction. But if the cursor backup was successful,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3625 ** jump immediately to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3626 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3627 case OP_Prev: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3628 case OP_Next: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3629 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3630 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3631
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3632 CHECK_FOR_INTERRUPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3633 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3634 pC = p->apCsr[pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3635 assert( pC!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3636 if( (pCrsr = pC->pCursor)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3637 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3638 if( pC->nullRow ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3639 res = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3640 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3641 assert( pC->deferredMoveto==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3642 rc = pOp->opcode==OP_Next ? sqlite3BtreeNext(pCrsr, &res) :
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3643 sqlite3BtreePrevious(pCrsr, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3644 pC->nullRow = res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3645 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3646 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3647 if( res==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3648 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3649 sqlite3_search_count++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3650 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3651 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3652 pC->nullRow = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3653 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3654 pC->rowidIsValid = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3655 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3656 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3657
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3658 /* Opcode: IdxInsert P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3659 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3660 ** The top of the stack holds a SQL index key made using either the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3661 ** MakeIdxRec or MakeRecord instructions. This opcode writes that key
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3662 ** into the index P1. Data for the entry is nil.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3663 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3664 ** This instruction only works for indices. The equivalent instruction
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3665 ** for tables is OP_Insert.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3666 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3667 case OP_IdxInsert: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3668 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3669 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3670 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3671 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3672 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3673 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3674 assert( pTos->flags & MEM_Blob );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3675 assert( pOp->p2==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3676 if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3677 int nKey = pTos->n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3678 const char *zKey = pTos->z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3679 assert( pC->isTable==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3680 rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3681 assert( pC->deferredMoveto==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3682 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3683 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3684 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3685 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3686 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3687 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3688
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3689 /* Opcode: IdxDelete P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3690 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3691 ** The top of the stack is an index key built using the either the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3692 ** MakeIdxRec or MakeRecord opcodes.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3693 ** This opcode removes that entry from the index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3694 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3695 case OP_IdxDelete: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3696 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3697 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3698 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3699 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3700 assert( pTos->flags & MEM_Blob );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3701 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3702 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3703 if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3704 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3705 rc = sqlite3BtreeMoveto(pCrsr, pTos->z, pTos->n, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3706 if( rc==SQLITE_OK && res==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3707 rc = sqlite3BtreeDelete(pCrsr);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3708 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3709 assert( pC->deferredMoveto==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3710 pC->cacheStatus = CACHE_STALE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3711 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3712 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3713 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3714 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3715 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3716
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3717 /* Opcode: IdxRowid P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3718 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3719 ** Push onto the stack an integer which is the last entry in the record at
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3720 ** the end of the index key pointed to by cursor P1. This integer should be
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3721 ** the rowid of the table entry to which this index entry points.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3722 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3723 ** See also: Rowid, MakeIdxRec.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3724 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3725 case OP_IdxRowid: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3726 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3727 BtCursor *pCrsr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3728 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3729
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3730 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3731 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3732 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3733 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3734 if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3735 i64 rowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3736
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3737 assert( pC->deferredMoveto==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3738 assert( pC->isTable==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3739 if( pC->nullRow ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3740 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3741 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3742 rc = sqlite3VdbeIdxRowid(pCrsr, &rowid);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3743 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3744 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3745 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3746 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3747 pTos->i = rowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3748 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3749 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3750 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3751 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3752
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3753 /* Opcode: IdxGT P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3754 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3755 ** The top of the stack is an index entry that omits the ROWID. Compare
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3756 ** the top of stack against the index that P1 is currently pointing to.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3757 ** Ignore the ROWID on the P1 index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3758 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3759 ** The top of the stack might have fewer columns that P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3760 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3761 ** If the P1 index entry is greater than the top of the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3762 ** then jump to P2. Otherwise fall through to the next instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3763 ** In either case, the stack is popped once.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3764 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3765 /* Opcode: IdxGE P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3766 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3767 ** The top of the stack is an index entry that omits the ROWID. Compare
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3768 ** the top of stack against the index that P1 is currently pointing to.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3769 ** Ignore the ROWID on the P1 index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3770 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3771 ** If the P1 index entry is greater than or equal to the top of the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3772 ** then jump to P2. Otherwise fall through to the next instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3773 ** In either case, the stack is popped once.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3774 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3775 ** If P3 is the "+" string (or any other non-NULL string) then the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3776 ** index taken from the top of the stack is temporarily increased by
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3777 ** an epsilon prior to the comparison. This make the opcode work
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3778 ** like IdxGT except that if the key from the stack is a prefix of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3779 ** the key in the cursor, the result is false whereas it would be
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3780 ** true with IdxGT.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3781 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3782 /* Opcode: IdxLT P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3783 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3784 ** The top of the stack is an index entry that omits the ROWID. Compare
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3785 ** the top of stack against the index that P1 is currently pointing to.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3786 ** Ignore the ROWID on the P1 index.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3787 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3788 ** If the P1 index entry is less than the top of the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3789 ** then jump to P2. Otherwise fall through to the next instruction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3790 ** In either case, the stack is popped once.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3791 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3792 ** If P3 is the "+" string (or any other non-NULL string) then the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3793 ** index taken from the top of the stack is temporarily increased by
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3794 ** an epsilon prior to the comparison. This makes the opcode work
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3795 ** like IdxLE.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3796 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3797 case OP_IdxLT: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3798 case OP_IdxGT: /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3799 case OP_IdxGE: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3800 int i= pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3801 Cursor *pC;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3802
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3803 assert( i>=0 && i<p->nCursor );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3804 assert( p->apCsr[i]!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3805 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3806 if( (pC = p->apCsr[i])->pCursor!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3807 int res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3808
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3809 assert( pTos->flags & MEM_Blob ); /* Created using OP_Make*Key */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3810 Stringify(pTos, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3811 assert( pC->deferredMoveto==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3812 *pC->pIncrKey = pOp->p3!=0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3813 assert( pOp->p3==0 || pOp->opcode!=OP_IdxGT );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3814 rc = sqlite3VdbeIdxKeyCompare(pC, pTos->n, (u8*)pTos->z, &res);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3815 *pC->pIncrKey = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3816 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3817 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3818 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3819 if( pOp->opcode==OP_IdxLT ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3820 res = -res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3821 }else if( pOp->opcode==OP_IdxGE ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3822 res++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3823 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3824 if( res>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3825 pc = pOp->p2 - 1 ;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3826 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3827 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3828 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3829 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3830 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3831 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3832
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3833 /* Opcode: IdxIsNull P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3834 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3835 ** The top of the stack contains an index entry such as might be generated
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3836 ** by the MakeIdxRec opcode. This routine looks at the first P1 fields of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3837 ** that key. If any of the first P1 fields are NULL, then a jump is made
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3838 ** to address P2. Otherwise we fall straight through.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3839 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3840 ** The index entry is always popped from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3841 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3842 case OP_IdxIsNull: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3843 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3844 int k, n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3845 const char *z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3846 u32 serial_type;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3847
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3848 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3849 assert( pTos->flags & MEM_Blob );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3850 z = pTos->z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3851 n = pTos->n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3852 k = sqlite3GetVarint32((u8*)z, &serial_type);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3853 for(; k<n && i>0; i--){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3854 k += sqlite3GetVarint32((u8*)&z[k], &serial_type);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3855 if( serial_type==0 ){ /* Serial type 0 is a NULL */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3856 pc = pOp->p2-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3857 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3858 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3859 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3860 Release(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3861 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3862 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3863 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3864
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3865 /* Opcode: Destroy P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3866 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3867 ** Delete an entire database table or index whose root page in the database
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3868 ** file is given by P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3869 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3870 ** The table being destroyed is in the main database file if P2==0. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3871 ** P2==1 then the table to be clear is in the auxiliary database file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3872 ** that is used to store tables create using CREATE TEMPORARY TABLE.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3873 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3874 ** If AUTOVACUUM is enabled then it is possible that another root page
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3875 ** might be moved into the newly deleted root page in order to keep all
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3876 ** root pages contiguous at the beginning of the database. The former
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3877 ** value of the root page that moved - its value before the move occurred -
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3878 ** is pushed onto the stack. If no page movement was required (because
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3879 ** the table being dropped was already the last one in the database) then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3880 ** a zero is pushed onto the stack. If AUTOVACUUM is disabled
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3881 ** then a zero is pushed onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3882 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3883 ** See also: Clear
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3884 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3885 case OP_Destroy: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3886 int iMoved;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3887 if( db->activeVdbeCnt>1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3888 rc = SQLITE_LOCKED;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3889 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3890 assert( db->activeVdbeCnt==1 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3891 rc = sqlite3BtreeDropTable(db->aDb[pOp->p2].pBt, pOp->p1, &iMoved);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3892 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3893 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3894 pTos->i = iMoved;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3895 #ifndef SQLITE_OMIT_AUTOVACUUM
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3896 if( rc==SQLITE_OK && iMoved!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3897 sqlite3RootPageMoved(&db->aDb[pOp->p2], iMoved, pOp->p1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3898 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3899 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3900 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3901 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3902 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3903
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3904 /* Opcode: Clear P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3905 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3906 ** Delete all contents of the database table or index whose root page
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3907 ** in the database file is given by P1. But, unlike Destroy, do not
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3908 ** remove the table or index from the database file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3909 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3910 ** The table being clear is in the main database file if P2==0. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3911 ** P2==1 then the table to be clear is in the auxiliary database file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3912 ** that is used to store tables create using CREATE TEMPORARY TABLE.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3913 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3914 ** See also: Destroy
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3915 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3916 case OP_Clear: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3917
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3918 /* For consistency with the way other features of SQLite operate
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3919 ** with a truncate, we will also skip the update callback.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3920 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3921 #if 0
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3922 Btree *pBt = db->aDb[pOp->p2].pBt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3923 if( db->xUpdateCallback && pOp->p3 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3924 const char *zDb = db->aDb[pOp->p2].zName;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3925 const char *zTbl = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3926 BtCursor *pCur = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3927 int fin = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3928
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3929 rc = sqlite3BtreeCursor(pBt, pOp->p1, 0, 0, 0, &pCur);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3930 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3931 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3932 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3933 for(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3934 rc=sqlite3BtreeFirst(pCur, &fin);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3935 rc==SQLITE_OK && !fin;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3936 rc=sqlite3BtreeNext(pCur, &fin)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3937 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3938 i64 iKey;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3939 rc = sqlite3BtreeKeySize(pCur, &iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3940 if( rc ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3941 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3942 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3943 iKey = keyToInt(iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3944 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, iKey);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3945 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3946 sqlite3BtreeCloseCursor(pCur);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3947 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3948 goto abort_due_to_error;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3949 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3950 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3951 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3952 rc = sqlite3BtreeClearTable(db->aDb[pOp->p2].pBt, pOp->p1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3953 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3954 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3955
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3956 /* Opcode: CreateTable P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3957 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3958 ** Allocate a new table in the main database file if P2==0 or in the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3959 ** auxiliary database file if P2==1. Push the page number
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3960 ** for the root page of the new table onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3961 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3962 ** The difference between a table and an index is this: A table must
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3963 ** have a 4-byte integer key and can have arbitrary data. An index
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3964 ** has an arbitrary key but no data.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3965 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3966 ** See also: CreateIndex
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3967 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3968 /* Opcode: CreateIndex P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3969 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3970 ** Allocate a new index in the main database file if P2==0 or in the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3971 ** auxiliary database file if P2==1. Push the page number of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3972 ** root page of the new index onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3973 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3974 ** See documentation on OP_CreateTable for additional information.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3975 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3976 case OP_CreateIndex:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3977 case OP_CreateTable: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3978 int pgno;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3979 int flags;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3980 Db *pDb;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3981 assert( pOp->p1>=0 && pOp->p1<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3982 pDb = &db->aDb[pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3983 assert( pDb->pBt!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3984 if( pOp->opcode==OP_CreateTable ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3985 /* flags = BTREE_INTKEY; */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3986 flags = BTREE_LEAFDATA|BTREE_INTKEY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3987 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3988 flags = BTREE_ZERODATA;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3989 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3990 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3991 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3992 if( rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3993 pTos->i = pgno;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3994 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3995 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3996 pTos->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3997 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3998 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3999 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4000
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4001 /* Opcode: ParseSchema P1 * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4002 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4003 ** Read and parse all entries from the SQLITE_MASTER table of database P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4004 ** that match the WHERE clause P3.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4005 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4006 ** This opcode invokes the parser to create a new virtual machine,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4007 ** then runs the new virtual machine. It is thus a reentrant opcode.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4008 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4009 case OP_ParseSchema: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4010 char *zSql;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4011 int iDb = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4012 const char *zMaster;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4013 InitData initData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4014
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4015 assert( iDb>=0 && iDb<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4016 if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4017 zMaster = SCHEMA_TABLE(iDb);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4018 initData.db = db;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4019 initData.pzErrMsg = &p->zErrMsg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4020 zSql = sqlite3MPrintf(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4021 "SELECT name, rootpage, sql, %d FROM '%q'.%s WHERE %s",
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4022 pOp->p1, db->aDb[iDb].zName, zMaster, pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4023 if( zSql==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4024 sqlite3SafetyOff(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4025 assert( db->init.busy==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4026 db->init.busy = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4027 assert( !sqlite3MallocFailed() );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4028 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4029 sqliteFree(zSql);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4030 db->init.busy = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4031 sqlite3SafetyOn(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4032 if( rc==SQLITE_NOMEM ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4033 sqlite3FailedMalloc();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4034 goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4035 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4036 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4037 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4038
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4039 #if !defined(SQLITE_OMIT_ANALYZE) && !defined(SQLITE_OMIT_PARSER)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4040 /* Opcode: LoadAnalysis P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4041 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4042 ** Read the sqlite_stat1 table for database P1 and load the content
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4043 ** of that table into the internal index hash table. This will cause
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4044 ** the analysis to be used when preparing all subsequent queries.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4045 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4046 case OP_LoadAnalysis: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4047 int iDb = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4048 assert( iDb>=0 && iDb<db->nDb );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4049 sqlite3AnalysisLoad(db, iDb);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4050 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4051 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4052 #endif /* !defined(SQLITE_OMIT_ANALYZE) && !defined(SQLITE_OMIT_PARSER) */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4053
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4054 /* Opcode: DropTable P1 * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4055 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4056 ** Remove the internal (in-memory) data structures that describe
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4057 ** the table named P3 in database P1. This is called after a table
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4058 ** is dropped in order to keep the internal representation of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4059 ** schema consistent with what is on disk.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4060 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4061 case OP_DropTable: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4062 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4063 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4064 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4065
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4066 /* Opcode: DropIndex P1 * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4067 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4068 ** Remove the internal (in-memory) data structures that describe
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4069 ** the index named P3 in database P1. This is called after an index
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4070 ** is dropped in order to keep the internal representation of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4071 ** schema consistent with what is on disk.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4072 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4073 case OP_DropIndex: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4074 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4075 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4076 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4077
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4078 /* Opcode: DropTrigger P1 * P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4079 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4080 ** Remove the internal (in-memory) data structures that describe
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4081 ** the trigger named P3 in database P1. This is called after a trigger
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4082 ** is dropped in order to keep the internal representation of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4083 ** schema consistent with what is on disk.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4084 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4085 case OP_DropTrigger: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4086 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4087 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4088 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4089
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4090
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4091 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4092 /* Opcode: IntegrityCk * P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4093 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4094 ** Do an analysis of the currently open database. Push onto the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4095 ** stack the text of an error message describing any problems.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4096 ** If there are no errors, push a "ok" onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4097 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4098 ** The root page numbers of all tables in the database are integer
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4099 ** values on the stack. This opcode pulls as many integers as it
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4100 ** can off of the stack and uses those numbers as the root pages.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4101 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4102 ** If P2 is not zero, the check is done on the auxiliary database
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4103 ** file, not the main database file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4104 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4105 ** This opcode is used for testing purposes only.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4106 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4107 case OP_IntegrityCk: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4108 int nRoot;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4109 int *aRoot;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4110 int j;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4111 char *z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4112
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4113 for(nRoot=0; &pTos[-nRoot]>=p->aStack; nRoot++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4114 if( (pTos[-nRoot].flags & MEM_Int)==0 ) break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4115 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4116 assert( nRoot>0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4117 aRoot = sqliteMallocRaw( sizeof(int*)*(nRoot+1) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4118 if( aRoot==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4119 for(j=0; j<nRoot; j++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4120 Mem *pMem = &pTos[-j];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4121 aRoot[j] = pMem->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4122 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4123 aRoot[j] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4124 popStack(&pTos, nRoot);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4125 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4126 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4127 if( z==0 || z[0]==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4128 if( z ) sqliteFree(z);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4129 pTos->z = "ok";
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4130 pTos->n = 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4131 pTos->flags = MEM_Str | MEM_Static | MEM_Term;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4132 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4133 pTos->z = z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4134 pTos->n = strlen(z);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4135 pTos->flags = MEM_Str | MEM_Dyn | MEM_Term;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4136 pTos->xDel = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4137 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4138 pTos->enc = SQLITE_UTF8;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4139 sqlite3VdbeChangeEncoding(pTos, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4140 sqliteFree(aRoot);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4141 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4142 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4143 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4144
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4145 /* Opcode: FifoWrite * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4146 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4147 ** Write the integer on the top of the stack
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4148 ** into the Fifo.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4149 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4150 case OP_FifoWrite: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4151 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4152 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4153 sqlite3VdbeFifoPush(&p->sFifo, pTos->i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4154 assert( (pTos->flags & MEM_Dyn)==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4155 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4156 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4157 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4158
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4159 /* Opcode: FifoRead * P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4160 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4161 ** Attempt to read a single integer from the Fifo
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4162 ** and push it onto the stack. If the Fifo is empty
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4163 ** push nothing but instead jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4164 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4165 case OP_FifoRead: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4166 i64 v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4167 CHECK_FOR_INTERRUPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4168 if( sqlite3VdbeFifoPop(&p->sFifo, &v)==SQLITE_DONE ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4169 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4170 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4171 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4172 pTos->i = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4173 pTos->flags = MEM_Int;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4174 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4175 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4176 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4177
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4178 #ifndef SQLITE_OMIT_TRIGGER
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4179 /* Opcode: ContextPush * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4180 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4181 ** Save the current Vdbe context such that it can be restored by a ContextPop
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4182 ** opcode. The context stores the last insert row id, the last statement change
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4183 ** count, and the current statement change count.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4184 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4185 case OP_ContextPush: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4186 int i = p->contextStackTop++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4187 Context *pContext;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4188
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4189 assert( i>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4190 /* FIX ME: This should be allocated as part of the vdbe at compile-time */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4191 if( i>=p->contextStackDepth ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4192 p->contextStackDepth = i+1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4193 sqliteReallocOrFree((void**)&p->contextStack, sizeof(Context)*(i+1));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4194 if( p->contextStack==0 ) goto no_mem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4195 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4196 pContext = &p->contextStack[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4197 pContext->lastRowid = db->lastRowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4198 pContext->nChange = p->nChange;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4199 pContext->sFifo = p->sFifo;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4200 sqlite3VdbeFifoInit(&p->sFifo);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4201 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4202 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4203
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4204 /* Opcode: ContextPop * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4205 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4206 ** Restore the Vdbe context to the state it was in when contextPush was last
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4207 ** executed. The context stores the last insert row id, the last statement
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4208 ** change count, and the current statement change count.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4209 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4210 case OP_ContextPop: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4211 Context *pContext = &p->contextStack[--p->contextStackTop];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4212 assert( p->contextStackTop>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4213 db->lastRowid = pContext->lastRowid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4214 p->nChange = pContext->nChange;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4215 sqlite3VdbeFifoClear(&p->sFifo);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4216 p->sFifo = pContext->sFifo;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4217 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4218 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4219 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4220
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4221 /* Opcode: MemStore P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4222 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4223 ** Write the top of the stack into memory location P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4224 ** P1 should be a small integer since space is allocated
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4225 ** for all memory locations between 0 and P1 inclusive.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4226 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4227 ** After the data is stored in the memory location, the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4228 ** stack is popped once if P2 is 1. If P2 is zero, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4229 ** the original data remains on the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4230 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4231 case OP_MemStore: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4232 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4233 assert( pOp->p1>=0 && pOp->p1<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4234 rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4235 pTos--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4236
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4237 /* If P2 is 0 then fall thru to the next opcode, OP_MemLoad, that will
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4238 ** restore the top of the stack to its original value.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4239 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4240 if( pOp->p2 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4241 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4242 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4243 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4244 /* Opcode: MemLoad P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4245 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4246 ** Push a copy of the value in memory location P1 onto the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4247 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4248 ** If the value is a string, then the value pushed is a pointer to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4249 ** the string that is stored in the memory location. If the memory
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4250 ** location is subsequently changed (using OP_MemStore) then the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4251 ** value pushed onto the stack will change too.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4252 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4253 case OP_MemLoad: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4254 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4255 assert( i>=0 && i<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4256 pTos++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4257 sqlite3VdbeMemShallowCopy(pTos, &p->aMem[i], MEM_Ephem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4258 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4259 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4260
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4261 #ifndef SQLITE_OMIT_AUTOINCREMENT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4262 /* Opcode: MemMax P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4263 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4264 ** Set the value of memory cell P1 to the maximum of its current value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4265 ** and the value on the top of the stack. The stack is unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4266 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4267 ** This instruction throws an error if the memory cell is not initially
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4268 ** an integer.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4269 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4270 case OP_MemMax: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4271 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4272 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4273 assert( pTos>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4274 assert( i>=0 && i<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4275 pMem = &p->aMem[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4276 sqlite3VdbeMemIntegerify(pMem);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4277 sqlite3VdbeMemIntegerify(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4278 if( pMem->i<pTos->i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4279 pMem->i = pTos->i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4280 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4281 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4282 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4283 #endif /* SQLITE_OMIT_AUTOINCREMENT */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4284
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4285 /* Opcode: MemIncr P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4286 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4287 ** Increment the integer valued memory cell P2 by the value in P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4288 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4289 ** It is illegal to use this instruction on a memory cell that does
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4290 ** not contain an integer. An assertion fault will result if you try.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4291 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4292 case OP_MemIncr: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4293 int i = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4294 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4295 assert( i>=0 && i<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4296 pMem = &p->aMem[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4297 assert( pMem->flags==MEM_Int );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4298 pMem->i += pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4299 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4300 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4301
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4302 /* Opcode: IfMemPos P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4303 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4304 ** If the value of memory cell P1 is 1 or greater, jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4305 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4306 ** It is illegal to use this instruction on a memory cell that does
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4307 ** not contain an integer. An assertion fault will result if you try.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4308 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4309 case OP_IfMemPos: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4310 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4311 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4312 assert( i>=0 && i<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4313 pMem = &p->aMem[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4314 assert( pMem->flags==MEM_Int );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4315 if( pMem->i>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4316 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4317 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4318 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4319 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4320
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4321 /* Opcode: IfMemNeg P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4322 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4323 ** If the value of memory cell P1 is less than zero, jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4324 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4325 ** It is illegal to use this instruction on a memory cell that does
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4326 ** not contain an integer. An assertion fault will result if you try.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4327 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4328 case OP_IfMemNeg: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4329 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4330 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4331 assert( i>=0 && i<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4332 pMem = &p->aMem[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4333 assert( pMem->flags==MEM_Int );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4334 if( pMem->i<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4335 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4336 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4337 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4338 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4339
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4340 /* Opcode: IfMemZero P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4341 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4342 ** If the value of memory cell P1 is exactly 0, jump to P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4343 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4344 ** It is illegal to use this instruction on a memory cell that does
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4345 ** not contain an integer. An assertion fault will result if you try.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4346 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4347 case OP_IfMemZero: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4348 int i = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4349 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4350 assert( i>=0 && i<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4351 pMem = &p->aMem[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4352 assert( pMem->flags==MEM_Int );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4353 if( pMem->i==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4354 pc = pOp->p2 - 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4355 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4356 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4357 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4358
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4359 /* Opcode: MemNull P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4360 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4361 ** Store a NULL in memory cell P1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4362 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4363 case OP_MemNull: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4364 assert( pOp->p1>=0 && pOp->p1<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4365 sqlite3VdbeMemSetNull(&p->aMem[pOp->p1]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4366 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4367 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4368
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4369 /* Opcode: MemInt P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4370 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4371 ** Store the integer value P1 in memory cell P2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4372 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4373 case OP_MemInt: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4374 assert( pOp->p2>=0 && pOp->p2<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4375 sqlite3VdbeMemSetInt64(&p->aMem[pOp->p2], pOp->p1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4376 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4377 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4378
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4379 /* Opcode: MemMove P1 P2 *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4380 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4381 ** Move the content of memory cell P2 over to memory cell P1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4382 ** Any prior content of P1 is erased. Memory cell P2 is left
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4383 ** containing a NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4384 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4385 case OP_MemMove: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4386 assert( pOp->p1>=0 && pOp->p1<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4387 assert( pOp->p2>=0 && pOp->p2<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4388 rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], &p->aMem[pOp->p2]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4389 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4390 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4391
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4392 /* Opcode: AggStep P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4393 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4394 ** Execute the step function for an aggregate. The
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4395 ** function has P2 arguments. P3 is a pointer to the FuncDef
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4396 ** structure that specifies the function. Use memory location
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4397 ** P1 as the accumulator.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4398 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4399 ** The P2 arguments are popped from the stack.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4400 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4401 case OP_AggStep: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4402 int n = pOp->p2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4403 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4404 Mem *pMem, *pRec;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4405 sqlite3_context ctx;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4406 sqlite3_value **apVal;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4407
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4408 assert( n>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4409 pRec = &pTos[1-n];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4410 assert( pRec>=p->aStack );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4411 apVal = p->apArg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4412 assert( apVal || n==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4413 for(i=0; i<n; i++, pRec++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4414 apVal[i] = pRec;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4415 storeTypeInfo(pRec, encoding);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4416 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4417 ctx.pFunc = (FuncDef*)pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4418 assert( pOp->p1>=0 && pOp->p1<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4419 ctx.pMem = pMem = &p->aMem[pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4420 pMem->n++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4421 ctx.s.flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4422 ctx.s.z = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4423 ctx.s.xDel = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4424 ctx.isError = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4425 ctx.pColl = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4426 if( ctx.pFunc->needCollSeq ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4427 assert( pOp>p->aOp );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4428 assert( pOp[-1].p3type==P3_COLLSEQ );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4429 assert( pOp[-1].opcode==OP_CollSeq );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4430 ctx.pColl = (CollSeq *)pOp[-1].p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4431 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4432 (ctx.pFunc->xStep)(&ctx, n, apVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4433 popStack(&pTos, n);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4434 if( ctx.isError ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4435 sqlite3SetString(&p->zErrMsg, sqlite3_value_text(&ctx.s), (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4436 rc = SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4437 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4438 sqlite3VdbeMemRelease(&ctx.s);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4439 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4440 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4441
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4442 /* Opcode: AggFinal P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4443 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4444 ** Execute the finalizer function for an aggregate. P1 is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4445 ** the memory location that is the accumulator for the aggregate.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4446 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4447 ** P2 is the number of arguments that the step function takes and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4448 ** P3 is a pointer to the FuncDef for this function. The P2
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4449 ** argument is not used by this opcode. It is only there to disambiguate
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4450 ** functions that can take varying numbers of arguments. The
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4451 ** P3 argument is only needed for the degenerate case where
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4452 ** the step function was not previously called.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4453 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4454 case OP_AggFinal: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4455 Mem *pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4456 assert( pOp->p1>=0 && pOp->p1<p->nMem );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4457 pMem = &p->aMem[pOp->p1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4458 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4459 rc = sqlite3VdbeMemFinalize(pMem, (FuncDef*)pOp->p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4460 if( rc==SQLITE_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4461 sqlite3SetString(&p->zErrMsg, sqlite3_value_text(pMem), (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4462 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4463 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4464 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4465
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4466
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4467 /* Opcode: Vacuum * * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4468 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4469 ** Vacuum the entire database. This opcode will cause other virtual
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4470 ** machines to be created and run. It may not be called from within
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4471 ** a transaction.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4472 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4473 case OP_Vacuum: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4474 if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4475 rc = sqlite3RunVacuum(&p->zErrMsg, db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4476 if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4477 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4478 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4479
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4480 /* Opcode: Expire P1 * *
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4481 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4482 ** Cause precompiled statements to become expired. An expired statement
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4483 ** fails with an error code of SQLITE_SCHEMA if it is ever executed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4484 ** (via sqlite3_step()).
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4485 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4486 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4487 ** then only the currently executing statement is affected.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4488 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4489 case OP_Expire: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4490 if( !pOp->p1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4491 sqlite3ExpirePreparedStatements(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4492 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4493 p->expired = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4494 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4495 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4496 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4497
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4498 #ifndef SQLITE_OMIT_SHARED_CACHE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4499 /* Opcode: TableLock P1 P2 P3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4500 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4501 ** Obtain a lock on a particular table. This instruction is only used when
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4502 ** the shared-cache feature is enabled.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4503 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4504 ** If P1 is not negative, then it is the index of the database
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4505 ** in sqlite3.aDb[] and a read-lock is required. If P1 is negative, a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4506 ** write-lock is required. In this case the index of the database is the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4507 ** absolute value of P1 minus one (iDb = abs(P1) - 1;) and a write-lock is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4508 ** required.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4509 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4510 ** P2 contains the root-page of the table to lock.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4511 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4512 ** P3 contains a pointer to the name of the table being locked. This is only
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4513 ** used to generate an error message if the lock cannot be obtained.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4514 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4515 case OP_TableLock: { /* no-push */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4516 int p1 = pOp->p1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4517 u8 isWriteLock = (p1<0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4518 if( isWriteLock ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4519 p1 = (-1*p1)-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4520 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4521 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4522 if( rc==SQLITE_LOCKED ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4523 const char *z = (const char *)pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4524 sqlite3SetString(&p->zErrMsg, "database table is locked: ", z, (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4525 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4526 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4527 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4528 #endif /* SHARED_OMIT_SHARED_CACHE */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4529
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4530 /* An other opcode is illegal...
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4531 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4532 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4533 assert( 0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4534 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4535 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4536
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4537 /*****************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4538 ** The cases of the switch statement above this line should all be indented
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4539 ** by 6 spaces. But the left-most 6 spaces have been removed to improve the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4540 ** readability. From this point on down, the normal indentation rules are
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4541 ** restored.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4542 *****************************************************************************/
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4543 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4544
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4545 /* Make sure the stack limit was not exceeded */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4546 assert( pTos<=pStackLimit );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4547
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4548 #ifdef VDBE_PROFILE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4549 {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4550 long long elapse = hwtime() - start;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4551 pOp->cycles += elapse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4552 pOp->cnt++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4553 #if 0
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4554 fprintf(stdout, "%10lld ", elapse);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4555 sqlite3VdbePrintOp(stdout, origPc, &p->aOp[origPc]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4556 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4557 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4558 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4559
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4560 /* The following code adds nothing to the actual functionality
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4561 ** of the program. It is only here for testing and debugging.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4562 ** On the other hand, it does burn CPU cycles every time through
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4563 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4564 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4565 #ifndef NDEBUG
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4566 /* Sanity checking on the top element of the stack */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4567 if( pTos>=p->aStack ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4568 sqlite3VdbeMemSanity(pTos);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4569 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4570 assert( pc>=-1 && pc<p->nOp );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4571 #ifdef SQLITE_DEBUG
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4572 /* Code for tracing the vdbe stack. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4573 if( p->trace && pTos>=p->aStack ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4574 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4575 fprintf(p->trace, "Stack:");
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4576 for(i=0; i>-5 && &pTos[i]>=p->aStack; i--){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4577 if( pTos[i].flags & MEM_Null ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4578 fprintf(p->trace, " NULL");
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4579 }else if( (pTos[i].flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4580 fprintf(p->trace, " si:%lld", pTos[i].i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4581 }else if( pTos[i].flags & MEM_Int ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4582 fprintf(p->trace, " i:%lld", pTos[i].i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4583 }else if( pTos[i].flags & MEM_Real ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4584 fprintf(p->trace, " r:%g", pTos[i].r);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4585 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4586 char zBuf[100];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4587 sqlite3VdbeMemPrettyPrint(&pTos[i], zBuf);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4588 fprintf(p->trace, " ");
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4589 fprintf(p->trace, "%s", zBuf);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4590 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4591 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4592 if( rc!=0 ) fprintf(p->trace," rc=%d",rc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4593 fprintf(p->trace,"\n");
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4594 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4595 #endif /* SQLITE_DEBUG */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4596 #endif /* NDEBUG */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4597 } /* The end of the for(;;) loop the loops through opcodes */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4598
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4599 /* If we reach this point, it means that execution is finished.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4600 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4601 vdbe_halt:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4602 if( rc ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4603 p->rc = rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4604 rc = SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4605 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4606 rc = SQLITE_DONE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4607 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4608 sqlite3VdbeHalt(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4609 p->pTos = pTos;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4610 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4611
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4612 /* Jump to here if a malloc() fails. It's hard to get a malloc()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4613 ** to fail on a modern VM computer, so this code is untested.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4614 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4615 no_mem:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4616 sqlite3SetString(&p->zErrMsg, "out of memory", (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4617 rc = SQLITE_NOMEM;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4618 goto vdbe_halt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4619
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4620 /* Jump to here for an SQLITE_MISUSE error.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4621 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4622 abort_due_to_misuse:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4623 rc = SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4624 /* Fall thru into abort_due_to_error */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4625
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4626 /* Jump to here for any other kind of fatal error. The "rc" variable
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4627 ** should hold the error number.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4628 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4629 abort_due_to_error:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4630 if( p->zErrMsg==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4631 if( sqlite3MallocFailed() ) rc = SQLITE_NOMEM;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4632 sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4633 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4634 goto vdbe_halt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4635
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4636 /* Jump to here if the sqlite3_interrupt() API sets the interrupt
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4637 ** flag.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4638 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4639 abort_due_to_interrupt:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4640 assert( db->flags & SQLITE_Interrupt );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4641 db->flags &= ~SQLITE_Interrupt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4642 if( db->magic!=SQLITE_MAGIC_BUSY ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4643 rc = SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4644 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4645 rc = SQLITE_INTERRUPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4646 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4647 p->rc = rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4648 sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4649 goto vdbe_halt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4650 }