annotate sqlite/vdbeapi.c @ 1581:68aec931b0b6 trunk

[svn] - gcc 4.1.1 fixes
author nenolod
date Mon, 14 Aug 2006 17:47:24 -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 ** 2004 May 26
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 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
13 ** This file contains code use to implement APIs that are part of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
14 ** VDBE.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
15 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
16 #include "sqliteInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
17 #include "vdbeInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
18 #include "os.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
19
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
20 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
21 ** Return TRUE (non-zero) of the statement supplied as an argument needs
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
22 ** to be recompiled. A statement needs to be recompiled whenever the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
23 ** execution environment changes in a way that would alter the program
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
24 ** that sqlite3_prepare() generates. For example, if new functions or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
25 ** collating sequences are registered or if an authorizer function is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
26 ** added or changed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
27 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
28 int sqlite3_expired(sqlite3_stmt *pStmt){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
29 Vdbe *p = (Vdbe*)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
30 return p==0 || p->expired;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
31 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
32
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
33 /**************************** sqlite3_value_ *******************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
34 ** The following routines extract information from a Mem or sqlite3_value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
35 ** structure.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
36 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
37 const void *sqlite3_value_blob(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
38 Mem *p = (Mem*)pVal;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
39 if( p->flags & (MEM_Blob|MEM_Str) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
40 return p->z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
41 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
42 return sqlite3_value_text(pVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
43 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
44 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
45 int sqlite3_value_bytes(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
46 return sqlite3ValueBytes(pVal, SQLITE_UTF8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
47 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
48 int sqlite3_value_bytes16(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
49 return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
50 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
51 double sqlite3_value_double(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
52 return sqlite3VdbeRealValue((Mem*)pVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
53 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
54 int sqlite3_value_int(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
55 return sqlite3VdbeIntValue((Mem*)pVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
56 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
57 sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
58 return sqlite3VdbeIntValue((Mem*)pVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
59 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
60 const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
61 return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
62 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
63 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
64 const void *sqlite3_value_text16(sqlite3_value* pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
65 return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
66 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
67 const void *sqlite3_value_text16be(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
68 return sqlite3ValueText(pVal, SQLITE_UTF16BE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
69 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
70 const void *sqlite3_value_text16le(sqlite3_value *pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
71 return sqlite3ValueText(pVal, SQLITE_UTF16LE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
72 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
73 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
74 int sqlite3_value_type(sqlite3_value* pVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
75 return pVal->type;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
76 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
77 /* sqlite3_value_numeric_type() defined in vdbe.c */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
78
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
79 /**************************** sqlite3_result_ *******************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
80 ** The following routines are used by user-defined functions to specify
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
81 ** the function result.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
82 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
83 void sqlite3_result_blob(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
84 sqlite3_context *pCtx,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
85 const void *z,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
86 int n,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
87 void (*xDel)(void *)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
88 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
89 assert( n>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
90 sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
91 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
92 void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
93 sqlite3VdbeMemSetDouble(&pCtx->s, rVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
94 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
95 void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
96 pCtx->isError = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
97 sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
98 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
99 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
100 void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
101 pCtx->isError = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
102 sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
103 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
104 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
105 void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
106 sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
107 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
108 void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
109 sqlite3VdbeMemSetInt64(&pCtx->s, iVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
110 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
111 void sqlite3_result_null(sqlite3_context *pCtx){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
112 sqlite3VdbeMemSetNull(&pCtx->s);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
113 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
114 void sqlite3_result_text(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
115 sqlite3_context *pCtx,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
116 const char *z,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
117 int n,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
118 void (*xDel)(void *)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
119 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
120 sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
121 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
122 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
123 void sqlite3_result_text16(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
124 sqlite3_context *pCtx,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
125 const void *z,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
126 int n,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
127 void (*xDel)(void *)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
128 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
129 sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, xDel);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
130 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
131 void sqlite3_result_text16be(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
132 sqlite3_context *pCtx,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
133 const void *z,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
134 int n,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
135 void (*xDel)(void *)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
136 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
137 sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16BE, xDel);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
138 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
139 void sqlite3_result_text16le(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
140 sqlite3_context *pCtx,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
141 const void *z,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
142 int n,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
143 void (*xDel)(void *)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
144 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
145 sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16LE, xDel);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
146 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
147 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
148 void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
149 sqlite3VdbeMemCopy(&pCtx->s, pValue);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
150 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
151
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
152
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
153 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
154 ** Execute the statement pStmt, either until a row of data is ready, the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
155 ** statement is completely executed or an error occurs.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
156 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
157 int sqlite3_step(sqlite3_stmt *pStmt){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
158 Vdbe *p = (Vdbe*)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
159 sqlite3 *db;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
160 int rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
161
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
162 /* Assert that malloc() has not failed */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
163 assert( !sqlite3MallocFailed() );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
164
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
165 if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
166 return SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
167 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
168 if( p->aborted ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
169 return SQLITE_ABORT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
170 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
171 if( p->pc<=0 && p->expired ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
172 if( p->rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
173 p->rc = SQLITE_SCHEMA;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
174 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
175 return SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
176 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
177 db = p->db;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
178 if( sqlite3SafetyOn(db) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
179 p->rc = SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
180 return SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
181 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
182 if( p->pc<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
183 #ifndef SQLITE_OMIT_TRACE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
184 /* Invoke the trace callback if there is one
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
185 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
186 if( db->xTrace && !db->init.busy ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
187 assert( p->nOp>0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
188 assert( p->aOp[p->nOp-1].opcode==OP_Noop );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
189 assert( p->aOp[p->nOp-1].p3!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
190 assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
191 sqlite3SafetyOff(db);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
192 db->xTrace(db->pTraceArg, p->aOp[p->nOp-1].p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
193 if( sqlite3SafetyOn(db) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
194 p->rc = SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
195 return SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
196 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
197 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
198 if( db->xProfile && !db->init.busy ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
199 double rNow;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
200 sqlite3OsCurrentTime(&rNow);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
201 p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
202 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
203 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
204
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
205 /* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
206 ** on in debugging mode.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
207 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
208 #ifdef SQLITE_DEBUG
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
209 if( (db->flags & SQLITE_SqlTrace)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
210 sqlite3DebugPrintf("SQL-trace: %s\n", p->aOp[p->nOp-1].p3);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
211 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
212 #endif /* SQLITE_DEBUG */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
213
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
214 db->activeVdbeCnt++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
215 p->pc = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
216 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
217 #ifndef SQLITE_OMIT_EXPLAIN
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
218 if( p->explain ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
219 rc = sqlite3VdbeList(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
220 }else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
221 #endif /* SQLITE_OMIT_EXPLAIN */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
222 {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
223 rc = sqlite3VdbeExec(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
224 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
225
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
226 if( sqlite3SafetyOff(db) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
227 rc = SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
228 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
229
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
230 #ifndef SQLITE_OMIT_TRACE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
231 /* Invoke the profile callback if there is one
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
232 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
233 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
234 double rNow;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
235 u64 elapseTime;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
236
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
237 sqlite3OsCurrentTime(&rNow);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
238 elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
239 assert( p->nOp>0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
240 assert( p->aOp[p->nOp-1].opcode==OP_Noop );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
241 assert( p->aOp[p->nOp-1].p3!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
242 assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
243 db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
244 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
245 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
246
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
247 sqlite3Error(p->db, rc, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
248 p->rc = sqlite3ApiExit(p->db, p->rc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
249 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
250 }
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 ** Extract the user data from a sqlite3_context structure and return a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
254 ** pointer to it.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
255 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
256 void *sqlite3_user_data(sqlite3_context *p){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
257 assert( p && p->pFunc );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
258 return p->pFunc->pUserData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
259 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
260
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
261 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
262 ** Allocate or return the aggregate context for a user function. A new
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
263 ** context is allocated on the first call. Subsequent calls return the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
264 ** same context that was returned on prior calls.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
265 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
266 void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
267 Mem *pMem = p->pMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
268 assert( p && p->pFunc && p->pFunc->xStep );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
269 if( (pMem->flags & MEM_Agg)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
270 if( nByte==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
271 assert( pMem->flags==MEM_Null );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
272 pMem->z = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
273 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
274 pMem->flags = MEM_Agg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
275 pMem->xDel = sqlite3FreeX;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
276 *(FuncDef**)&pMem->i = p->pFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
277 if( nByte<=NBFS ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
278 pMem->z = pMem->zShort;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
279 memset(pMem->z, 0, nByte);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
280 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
281 pMem->z = sqliteMalloc( nByte );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
282 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
283 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
284 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
285 return (void*)pMem->z;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
286 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
287
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
288 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
289 ** Return the auxilary data pointer, if any, for the iArg'th argument to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
290 ** the user-function defined by pCtx.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
291 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
292 void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
293 VdbeFunc *pVdbeFunc = pCtx->pVdbeFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
294 if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
295 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
296 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
297 return pVdbeFunc->apAux[iArg].pAux;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
298 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
299
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
300 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
301 ** Set the auxilary data pointer and delete function, for the iArg'th
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
302 ** argument to the user-function defined by pCtx. Any previous value is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
303 ** deleted by calling the delete function specified when it was set.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
304 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
305 void sqlite3_set_auxdata(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
306 sqlite3_context *pCtx,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
307 int iArg,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
308 void *pAux,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
309 void (*xDelete)(void*)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
310 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
311 struct AuxData *pAuxData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
312 VdbeFunc *pVdbeFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
313 if( iArg<0 ) return;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
314
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
315 pVdbeFunc = pCtx->pVdbeFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
316 if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
317 int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
318 pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
319 if( !pVdbeFunc ) return;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
320 pCtx->pVdbeFunc = pVdbeFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
321 memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
322 sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
323 pVdbeFunc->nAux = iArg+1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
324 pVdbeFunc->pFunc = pCtx->pFunc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
325 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
326
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
327 pAuxData = &pVdbeFunc->apAux[iArg];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
328 if( pAuxData->pAux && pAuxData->xDelete ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
329 pAuxData->xDelete(pAuxData->pAux);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
330 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
331 pAuxData->pAux = pAux;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
332 pAuxData->xDelete = xDelete;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
333 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
334
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
335 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
336 ** Return the number of times the Step function of a aggregate has been
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
337 ** called.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
338 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
339 ** This function is deprecated. Do not use it for new code. It is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
340 ** provide only to avoid breaking legacy code. New aggregate function
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
341 ** implementations should keep their own counts within their aggregate
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
342 ** context.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
343 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
344 int sqlite3_aggregate_count(sqlite3_context *p){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
345 assert( p && p->pFunc && p->pFunc->xStep );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
346 return p->pMem->n;
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 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
350 ** Return the number of columns in the result set for the statement pStmt.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
351 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
352 int sqlite3_column_count(sqlite3_stmt *pStmt){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
353 Vdbe *pVm = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
354 return pVm ? pVm->nResColumn : 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
355 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
356
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
357 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
358 ** Return the number of values available from the current row of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
359 ** currently executing statement pStmt.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
360 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
361 int sqlite3_data_count(sqlite3_stmt *pStmt){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
362 Vdbe *pVm = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
363 if( pVm==0 || !pVm->resOnStack ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
364 return pVm->nResColumn;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
365 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
366
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 ** Check to see if column iCol of the given statement is valid. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
370 ** it is, return a pointer to the Mem for the value of that column.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
371 ** If iCol is not valid, return a pointer to a Mem which has a value
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
372 ** of NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
373 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
374 static Mem *columnMem(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
375 Vdbe *pVm = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
376 int vals = sqlite3_data_count(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
377 if( i>=vals || i<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
378 static Mem nullMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
379 if( nullMem.flags==0 ){ nullMem.flags = MEM_Null; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
380 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
381 return &nullMem;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
382 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
383 return &pVm->pTos[(1-vals)+i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
384 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
385
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
386 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
387 ** This function is called after invoking an sqlite3_value_XXX function on a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
388 ** column value (i.e. a value returned by evaluating an SQL expression in the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
389 ** select list of a SELECT statement) that may cause a malloc() failure. If
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
390 ** malloc() has failed, the threads mallocFailed flag is cleared and the result
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
391 ** code of statement pStmt set to SQLITE_NOMEM.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
392 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
393 ** Specificly, this is called from within:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
394 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
395 ** sqlite3_column_int()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
396 ** sqlite3_column_int64()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
397 ** sqlite3_column_text()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
398 ** sqlite3_column_text16()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
399 ** sqlite3_column_real()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
400 ** sqlite3_column_bytes()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
401 ** sqlite3_column_bytes16()
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
402 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
403 ** But not for sqlite3_column_blob(), which never calls malloc().
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
404 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
405 static void columnMallocFailure(sqlite3_stmt *pStmt)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
406 {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
407 /* If malloc() failed during an encoding conversion within an
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
408 ** sqlite3_column_XXX API, then set the return code of the statement to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
409 ** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
410 ** and _finalize() will return NOMEM.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
411 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
412 Vdbe *p = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
413 p->rc = sqlite3ApiExit(0, p->rc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
414 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
415
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
416 /**************************** sqlite3_column_ *******************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
417 ** The following routines are used to access elements of the current row
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
418 ** in the result set.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
419 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
420 const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
421 const void *val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
422 sqlite3MallocDisallow();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
423 val = sqlite3_value_blob( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
424 sqlite3MallocAllow();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
425 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
426 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
427 int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
428 int val = sqlite3_value_bytes( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
429 columnMallocFailure(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
430 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
431 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
432 int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
433 int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
434 columnMallocFailure(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
435 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
436 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
437 double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
438 double val = sqlite3_value_double( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
439 columnMallocFailure(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
440 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
441 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
442 int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
443 int val = sqlite3_value_int( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
444 columnMallocFailure(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
445 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
446 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
447 sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
448 sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
449 columnMallocFailure(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
450 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
451 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
452 const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
453 const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
454 columnMallocFailure(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
455 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
456 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
457 #if 0
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
458 sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
459 return columnMem(pStmt, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
460 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
461 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
462 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
463 const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
464 const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
465 columnMallocFailure(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
466 return val;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
467 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
468 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
469 int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
470 return sqlite3_value_type( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
471 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
472
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
473 /* The following function is experimental and subject to change or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
474 ** removal */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
475 /*int sqlite3_column_numeric_type(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
476 ** return sqlite3_value_numeric_type( columnMem(pStmt,i) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
477 **}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
478 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
479
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
480 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
481 ** Convert the N-th element of pStmt->pColName[] into a string using
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
482 ** xFunc() then return that string. If N is out of range, return 0.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
483 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
484 ** There are up to 5 names for each column. useType determines which
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
485 ** name is returned. Here are the names:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
486 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
487 ** 0 The column name as it should be displayed for output
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
488 ** 1 The datatype name for the column
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
489 ** 2 The name of the database that the column derives from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
490 ** 3 The name of the table that the column derives from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
491 ** 4 The name of the table column that the result column derives from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
492 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
493 ** If the result is not a simple column reference (if it is an expression
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
494 ** or a constant) then useTypes 2, 3, and 4 return NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
495 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
496 static const void *columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
497 sqlite3_stmt *pStmt,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
498 int N,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
499 const void *(*xFunc)(Mem*),
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
500 int useType
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
501 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
502 const void *ret;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
503 Vdbe *p = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
504 int n = sqlite3_column_count(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
505
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
506 if( p==0 || N>=n || N<0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
507 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
508 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
509 N += useType*n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
510 ret = xFunc(&p->aColName[N]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
511
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
512 /* A malloc may have failed inside of the xFunc() call. If this is the case,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
513 ** clear the mallocFailed flag and return NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
514 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
515 sqlite3ApiExit(0, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
516 return ret;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
517 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
518
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
519 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
520 ** Return the name of the Nth column of the result set returned by SQL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
521 ** statement pStmt.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
522 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
523 const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
524 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
525 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
526 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
527 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
528 const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
529 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
530 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
531 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
532 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
533
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
534 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
535 ** Return the column declaration type (if applicable) of the 'i'th column
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
536 ** of the result set of SQL statement pStmt.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
537 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
538 const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
539 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
540 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
541 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
542 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
543 const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
544 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
545 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
546 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
547 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
548
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
549 #ifdef SQLITE_ENABLE_COLUMN_METADATA
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
550 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
551 ** Return the name of the database from which a result column derives.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
552 ** NULL is returned if the result column is an expression or constant or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
553 ** anything else which is not an unabiguous reference to a database column.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
554 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
555 const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
556 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
557 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
558 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
559 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
560 const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
561 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
562 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
563 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
564 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
565
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
566 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
567 ** Return the name of the table from which a result column derives.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
568 ** NULL is returned if the result column is an expression or constant or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
569 ** anything else which is not an unabiguous reference to a database column.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
570 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
571 const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
572 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
573 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
574 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
575 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
576 const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
577 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
578 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
579 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
580 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
581
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
582 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
583 ** Return the name of the table column from which a result column derives.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
584 ** NULL is returned if the result column is an expression or constant or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
585 ** anything else which is not an unabiguous reference to a database column.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
586 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
587 const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
588 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
589 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
590 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
591 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
592 const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
593 return columnName(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
594 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
595 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
596 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
597 #endif /* SQLITE_ENABLE_COLUMN_METADATA */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
598
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
599
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
600 /******************************* sqlite3_bind_ ***************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
601 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
602 ** Routines used to attach values to wildcards in a compiled SQL statement.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
603 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
604 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
605 ** Unbind the value bound to variable i in virtual machine p. This is the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
606 ** the same as binding a NULL value to the column. If the "i" parameter is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
607 ** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
608 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
609 ** The error code stored in database p->db is overwritten with the return
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
610 ** value in any case.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
611 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
612 static int vdbeUnbind(Vdbe *p, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
613 Mem *pVar;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
614 if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
615 if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
616 return SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
617 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
618 if( i<1 || i>p->nVar ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
619 sqlite3Error(p->db, SQLITE_RANGE, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
620 return SQLITE_RANGE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
621 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
622 i--;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
623 pVar = &p->aVar[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
624 sqlite3VdbeMemRelease(pVar);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
625 pVar->flags = MEM_Null;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
626 sqlite3Error(p->db, SQLITE_OK, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
627 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
628 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
629
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
630 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
631 ** Bind a text or BLOB value.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
632 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
633 static int bindText(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
634 sqlite3_stmt *pStmt,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
635 int i,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
636 const void *zData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
637 int nData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
638 void (*xDel)(void*),
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
639 int encoding
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
640 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
641 Vdbe *p = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
642 Mem *pVar;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
643 int rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
644
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
645 rc = vdbeUnbind(p, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
646 if( rc || zData==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
647 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
648 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
649 pVar = &p->aVar[i-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
650 rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
651 if( rc==SQLITE_OK && encoding!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
652 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
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 sqlite3Error(((Vdbe *)pStmt)->db, rc, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
656 return sqlite3ApiExit(((Vdbe *)pStmt)->db, rc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
657 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
658
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
659
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
660 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
661 ** Bind a blob value to an SQL statement variable.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
662 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
663 int sqlite3_bind_blob(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
664 sqlite3_stmt *pStmt,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
665 int i,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
666 const void *zData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
667 int nData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
668 void (*xDel)(void*)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
669 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
670 return bindText(pStmt, i, zData, nData, xDel, 0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
671 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
672 int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
673 int rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
674 Vdbe *p = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
675 rc = vdbeUnbind(p, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
676 if( rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
677 sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
678 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
679 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
680 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
681 int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
682 return sqlite3_bind_int64(p, i, (i64)iValue);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
683 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
684 int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
685 int rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
686 Vdbe *p = (Vdbe *)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
687 rc = vdbeUnbind(p, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
688 if( rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
689 sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
690 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
691 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
692 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
693 int sqlite3_bind_null(sqlite3_stmt* p, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
694 return vdbeUnbind((Vdbe *)p, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
695 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
696 int sqlite3_bind_text(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
697 sqlite3_stmt *pStmt,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
698 int i,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
699 const char *zData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
700 int nData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
701 void (*xDel)(void*)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
702 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
703 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
704 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
705 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
706 int sqlite3_bind_text16(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
707 sqlite3_stmt *pStmt,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
708 int i,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
709 const void *zData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
710 int nData,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
711 void (*xDel)(void*)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
712 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
713 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
714 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
715 #endif /* SQLITE_OMIT_UTF16 */
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 ** Return the number of wildcards that can be potentially bound to.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
719 ** This routine is added to support DBD::SQLite.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
720 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
721 int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
722 Vdbe *p = (Vdbe*)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
723 return p ? p->nVar : 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
724 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
725
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
726 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
727 ** Create a mapping from variable numbers to variable names
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
728 ** in the Vdbe.azVar[] array, if such a mapping does not already
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
729 ** exist.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
730 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
731 static void createVarMap(Vdbe *p){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
732 if( !p->okVar ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
733 int j;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
734 Op *pOp;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
735 for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
736 if( pOp->opcode==OP_Variable ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
737 assert( pOp->p1>0 && pOp->p1<=p->nVar );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
738 p->azVar[pOp->p1-1] = pOp->p3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
739 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
740 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
741 p->okVar = 1;
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
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
745 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
746 ** Return the name of a wildcard parameter. Return NULL if the index
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
747 ** is out of range or if the wildcard is unnamed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
748 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
749 ** The result is always UTF-8.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
750 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
751 const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
752 Vdbe *p = (Vdbe*)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
753 if( p==0 || i<1 || i>p->nVar ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
754 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
755 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
756 createVarMap(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
757 return p->azVar[i-1];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
758 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
759
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
760 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
761 ** Given a wildcard parameter name, return the index of the variable
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
762 ** with that name. If there is no variable with the given name,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
763 ** return 0.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
764 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
765 int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
766 Vdbe *p = (Vdbe*)pStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
767 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
768 if( p==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
769 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
770 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
771 createVarMap(p);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
772 if( zName ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
773 for(i=0; i<p->nVar; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
774 const char *z = p->azVar[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
775 if( z && strcmp(z,zName)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
776 return i+1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
777 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
778 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
779 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
780 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
781 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
782
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
783 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
784 ** Transfer all bindings from the first statement over to the second.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
785 ** If the two statements contain a different number of bindings, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
786 ** an SQLITE_ERROR is returned.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
787 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
788 int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
789 Vdbe *pFrom = (Vdbe*)pFromStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
790 Vdbe *pTo = (Vdbe*)pToStmt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
791 int i, rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
792 if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
793 || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
794 return SQLITE_MISUSE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
795 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
796 if( pFrom->nVar!=pTo->nVar ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
797 return SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
798 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
799 for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
800 sqlite3MallocDisallow();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
801 rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
802 sqlite3MallocAllow();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
803 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
804 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
805 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
806
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
807 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
808 ** Return the sqlite3* database handle to which the prepared statement given
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
809 ** in the argument belongs. This is the same database handle that was
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
810 ** the first argument to the sqlite3_prepare() that was used to create
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
811 ** the statement in the first place.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
812 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
813 sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
814 return pStmt ? ((Vdbe*)pStmt)->db : 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
815 }