drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2004 May 26 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** |
| 13 | ** This file contains code use to implement APIs that are part of the |
| 14 | ** VDBE. |
| 15 | */ |
| 16 | #include "sqliteInt.h" |
| 17 | #include "vdbeInt.h" |
| 18 | |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 19 | /* |
| 20 | ** Return TRUE (non-zero) of the statement supplied as an argument needs |
| 21 | ** to be recompiled. A statement needs to be recompiled whenever the |
| 22 | ** execution environment changes in a way that would alter the program |
| 23 | ** that sqlite3_prepare() generates. For example, if new functions or |
| 24 | ** collating sequences are registered or if an authorizer function is |
| 25 | ** added or changed. |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 26 | */ |
| 27 | int sqlite3_expired(sqlite3_stmt *pStmt){ |
| 28 | Vdbe *p = (Vdbe*)pStmt; |
| 29 | return p==0 || p->expired; |
| 30 | } |
| 31 | |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 32 | /**************************** sqlite3_value_ ******************************* |
| 33 | ** The following routines extract information from a Mem or sqlite3_value |
| 34 | ** structure. |
| 35 | */ |
| 36 | const void *sqlite3_value_blob(sqlite3_value *pVal){ |
| 37 | Mem *p = (Mem*)pVal; |
| 38 | if( p->flags & (MEM_Blob|MEM_Str) ){ |
| 39 | return p->z; |
| 40 | }else{ |
| 41 | return sqlite3_value_text(pVal); |
| 42 | } |
| 43 | } |
| 44 | int sqlite3_value_bytes(sqlite3_value *pVal){ |
danielk1977 | 1307393 | 2004-06-30 11:54:06 +0000 | [diff] [blame] | 45 | return sqlite3ValueBytes(pVal, SQLITE_UTF8); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 46 | } |
| 47 | int sqlite3_value_bytes16(sqlite3_value *pVal){ |
danielk1977 | 1307393 | 2004-06-30 11:54:06 +0000 | [diff] [blame] | 48 | return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 49 | } |
| 50 | double sqlite3_value_double(sqlite3_value *pVal){ |
drh | 6a6124e | 2004-06-27 01:56:33 +0000 | [diff] [blame] | 51 | return sqlite3VdbeRealValue((Mem*)pVal); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 52 | } |
| 53 | int sqlite3_value_int(sqlite3_value *pVal){ |
drh | 6a6124e | 2004-06-27 01:56:33 +0000 | [diff] [blame] | 54 | return sqlite3VdbeIntValue((Mem*)pVal); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 55 | } |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 56 | sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){ |
drh | 6a6124e | 2004-06-27 01:56:33 +0000 | [diff] [blame] | 57 | return sqlite3VdbeIntValue((Mem*)pVal); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 58 | } |
| 59 | const unsigned char *sqlite3_value_text(sqlite3_value *pVal){ |
danielk1977 | dc8453f | 2004-06-12 00:42:34 +0000 | [diff] [blame] | 60 | return (const char *)sqlite3ValueText(pVal, SQLITE_UTF8); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 61 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 62 | #ifndef SQLITE_OMIT_UTF16 |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 63 | const void *sqlite3_value_text16(sqlite3_value* pVal){ |
danielk1977 | dc8453f | 2004-06-12 00:42:34 +0000 | [diff] [blame] | 64 | return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 65 | } |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 66 | const void *sqlite3_value_text16be(sqlite3_value *pVal){ |
| 67 | return sqlite3ValueText(pVal, SQLITE_UTF16BE); |
| 68 | } |
| 69 | const void *sqlite3_value_text16le(sqlite3_value *pVal){ |
| 70 | return sqlite3ValueText(pVal, SQLITE_UTF16LE); |
| 71 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 72 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 73 | int sqlite3_value_type(sqlite3_value* pVal){ |
drh | f447950 | 2004-05-27 03:12:53 +0000 | [diff] [blame] | 74 | return pVal->type; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /**************************** sqlite3_result_ ******************************* |
| 78 | ** The following routines are used by user-defined functions to specify |
| 79 | ** the function result. |
| 80 | */ |
| 81 | void sqlite3_result_blob( |
| 82 | sqlite3_context *pCtx, |
| 83 | const void *z, |
| 84 | int n, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 85 | void (*xDel)(void *) |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 86 | ){ |
drh | 5708d2d | 2005-06-22 10:53:59 +0000 | [diff] [blame] | 87 | assert( n>=0 ); |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 88 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 89 | } |
| 90 | void sqlite3_result_double(sqlite3_context *pCtx, double rVal){ |
| 91 | sqlite3VdbeMemSetDouble(&pCtx->s, rVal); |
| 92 | } |
| 93 | void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ |
| 94 | pCtx->isError = 1; |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 95 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 96 | } |
| 97 | void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ |
| 98 | pCtx->isError = 1; |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 99 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 100 | } |
drh | f447950 | 2004-05-27 03:12:53 +0000 | [diff] [blame] | 101 | void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 102 | sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal); |
| 103 | } |
| 104 | void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){ |
| 105 | sqlite3VdbeMemSetInt64(&pCtx->s, iVal); |
| 106 | } |
| 107 | void sqlite3_result_null(sqlite3_context *pCtx){ |
drh | f447950 | 2004-05-27 03:12:53 +0000 | [diff] [blame] | 108 | sqlite3VdbeMemSetNull(&pCtx->s); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 109 | } |
| 110 | void sqlite3_result_text( |
| 111 | sqlite3_context *pCtx, |
| 112 | const char *z, |
| 113 | int n, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 114 | void (*xDel)(void *) |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 115 | ){ |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 116 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 117 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 118 | #ifndef SQLITE_OMIT_UTF16 |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 119 | void sqlite3_result_text16( |
| 120 | sqlite3_context *pCtx, |
| 121 | const void *z, |
| 122 | int n, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 123 | void (*xDel)(void *) |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 124 | ){ |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 125 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, xDel); |
| 126 | } |
| 127 | void sqlite3_result_text16be( |
| 128 | sqlite3_context *pCtx, |
| 129 | const void *z, |
| 130 | int n, |
| 131 | void (*xDel)(void *) |
| 132 | ){ |
| 133 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16BE, xDel); |
| 134 | } |
| 135 | void sqlite3_result_text16le( |
| 136 | sqlite3_context *pCtx, |
| 137 | const void *z, |
| 138 | int n, |
| 139 | void (*xDel)(void *) |
| 140 | ){ |
| 141 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16LE, xDel); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 142 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 143 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 144 | void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){ |
| 145 | sqlite3VdbeMemCopy(&pCtx->s, pValue); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | /* |
| 150 | ** Execute the statement pStmt, either until a row of data is ready, the |
| 151 | ** statement is completely executed or an error occurs. |
| 152 | */ |
| 153 | int sqlite3_step(sqlite3_stmt *pStmt){ |
| 154 | Vdbe *p = (Vdbe*)pStmt; |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 155 | sqlite3 *db; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 156 | int rc; |
| 157 | |
drh | 1bcdb0c | 2004-08-28 14:49:46 +0000 | [diff] [blame] | 158 | if( p==0 || p->magic!=VDBE_MAGIC_RUN ){ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 159 | return SQLITE_MISUSE; |
| 160 | } |
drh | 91b48aa | 2004-06-30 11:14:18 +0000 | [diff] [blame] | 161 | if( p->aborted ){ |
| 162 | return SQLITE_ABORT; |
| 163 | } |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 164 | if( p->pc<=0 && p->expired ){ |
| 165 | if( p->rc==SQLITE_OK ){ |
| 166 | p->rc = SQLITE_SCHEMA; |
| 167 | } |
| 168 | return SQLITE_ERROR; |
| 169 | } |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 170 | db = p->db; |
| 171 | if( sqlite3SafetyOn(db) ){ |
| 172 | p->rc = SQLITE_MISUSE; |
| 173 | return SQLITE_MISUSE; |
| 174 | } |
danielk1977 | 1d850a7 | 2004-05-31 08:26:49 +0000 | [diff] [blame] | 175 | if( p->pc<0 ){ |
drh | c16a03b | 2004-09-15 13:38:10 +0000 | [diff] [blame] | 176 | /* Invoke the trace callback if there is one |
| 177 | */ |
| 178 | if( (db = p->db)->xTrace && !db->init.busy ){ |
| 179 | assert( p->nOp>0 ); |
| 180 | assert( p->aOp[p->nOp-1].opcode==OP_Noop ); |
| 181 | assert( p->aOp[p->nOp-1].p3!=0 ); |
| 182 | assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC ); |
| 183 | sqlite3SafetyOff(db); |
| 184 | db->xTrace(db->pTraceArg, p->aOp[p->nOp-1].p3); |
| 185 | if( sqlite3SafetyOn(db) ){ |
| 186 | p->rc = SQLITE_MISUSE; |
| 187 | return SQLITE_MISUSE; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned |
| 192 | ** on in debugging mode. |
| 193 | */ |
| 194 | #ifdef SQLITE_DEBUG |
| 195 | if( (db->flags & SQLITE_SqlTrace)!=0 ){ |
| 196 | sqlite3DebugPrintf("SQL-trace: %s\n", p->aOp[p->nOp-1].p3); |
| 197 | } |
| 198 | #endif /* SQLITE_DEBUG */ |
| 199 | |
danielk1977 | 1d850a7 | 2004-05-31 08:26:49 +0000 | [diff] [blame] | 200 | db->activeVdbeCnt++; |
| 201 | p->pc = 0; |
| 202 | } |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 203 | #ifndef SQLITE_OMIT_EXPLAIN |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 204 | if( p->explain ){ |
| 205 | rc = sqlite3VdbeList(p); |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 206 | }else |
| 207 | #endif /* SQLITE_OMIT_EXPLAIN */ |
| 208 | { |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 209 | rc = sqlite3VdbeExec(p); |
| 210 | } |
| 211 | |
| 212 | if( sqlite3SafetyOff(db) ){ |
| 213 | rc = SQLITE_MISUSE; |
| 214 | } |
| 215 | |
| 216 | sqlite3Error(p->db, rc, p->zErrMsg); |
| 217 | return rc; |
| 218 | } |
| 219 | |
| 220 | /* |
drh | eb2e176 | 2004-05-27 01:53:56 +0000 | [diff] [blame] | 221 | ** Extract the user data from a sqlite3_context structure and return a |
| 222 | ** pointer to it. |
| 223 | */ |
| 224 | void *sqlite3_user_data(sqlite3_context *p){ |
| 225 | assert( p && p->pFunc ); |
| 226 | return p->pFunc->pUserData; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | ** Allocate or return the aggregate context for a user function. A new |
| 231 | ** context is allocated on the first call. Subsequent calls return the |
| 232 | ** same context that was returned on prior calls. |
| 233 | ** |
| 234 | ** This routine is defined here in vdbe.c because it depends on knowing |
| 235 | ** the internals of the sqlite3_context structure which is only defined in |
| 236 | ** this source file. |
| 237 | */ |
| 238 | void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){ |
| 239 | assert( p && p->pFunc && p->pFunc->xStep ); |
| 240 | if( p->pAgg==0 ){ |
| 241 | if( nByte<=NBFS ){ |
| 242 | p->pAgg = (void*)p->s.z; |
| 243 | memset(p->pAgg, 0, nByte); |
| 244 | }else{ |
| 245 | p->pAgg = sqliteMalloc( nByte ); |
| 246 | } |
| 247 | } |
| 248 | return p->pAgg; |
| 249 | } |
| 250 | |
| 251 | /* |
danielk1977 | 682f68b | 2004-06-05 10:22:17 +0000 | [diff] [blame] | 252 | ** Return the auxilary data pointer, if any, for the iArg'th argument to |
| 253 | ** the user-function defined by pCtx. |
| 254 | */ |
| 255 | void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 256 | VdbeFunc *pVdbeFunc = pCtx->pVdbeFunc; |
| 257 | if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){ |
| 258 | return 0; |
| 259 | } |
drh | f92c7ff | 2004-06-19 15:40:23 +0000 | [diff] [blame] | 260 | return pVdbeFunc->apAux[iArg].pAux; |
danielk1977 | 682f68b | 2004-06-05 10:22:17 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* |
| 264 | ** Set the auxilary data pointer and delete function, for the iArg'th |
| 265 | ** argument to the user-function defined by pCtx. Any previous value is |
| 266 | ** deleted by calling the delete function specified when it was set. |
| 267 | */ |
| 268 | void sqlite3_set_auxdata( |
| 269 | sqlite3_context *pCtx, |
| 270 | int iArg, |
| 271 | void *pAux, |
| 272 | void (*xDelete)(void*) |
| 273 | ){ |
| 274 | struct AuxData *pAuxData; |
drh | f92c7ff | 2004-06-19 15:40:23 +0000 | [diff] [blame] | 275 | VdbeFunc *pVdbeFunc; |
danielk1977 | 682f68b | 2004-06-05 10:22:17 +0000 | [diff] [blame] | 276 | if( iArg<0 ) return; |
| 277 | |
drh | f92c7ff | 2004-06-19 15:40:23 +0000 | [diff] [blame] | 278 | pVdbeFunc = pCtx->pVdbeFunc; |
| 279 | if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){ |
| 280 | int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg; |
| 281 | pCtx->pVdbeFunc = pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc); |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 282 | if( !pVdbeFunc ) return; |
drh | 0e3d747 | 2004-06-19 17:33:07 +0000 | [diff] [blame] | 283 | memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0, |
| 284 | sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux)); |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 285 | pVdbeFunc->nAux = iArg+1; |
| 286 | pVdbeFunc->pFunc = pCtx->pFunc; |
danielk1977 | 682f68b | 2004-06-05 10:22:17 +0000 | [diff] [blame] | 287 | } |
| 288 | |
drh | f92c7ff | 2004-06-19 15:40:23 +0000 | [diff] [blame] | 289 | pAuxData = &pVdbeFunc->apAux[iArg]; |
danielk1977 | 682f68b | 2004-06-05 10:22:17 +0000 | [diff] [blame] | 290 | if( pAuxData->pAux && pAuxData->xDelete ){ |
| 291 | pAuxData->xDelete(pAuxData->pAux); |
| 292 | } |
| 293 | pAuxData->pAux = pAux; |
| 294 | pAuxData->xDelete = xDelete; |
| 295 | } |
| 296 | |
| 297 | /* |
drh | eb2e176 | 2004-05-27 01:53:56 +0000 | [diff] [blame] | 298 | ** Return the number of times the Step function of a aggregate has been |
| 299 | ** called. |
| 300 | ** |
| 301 | ** This routine is defined here in vdbe.c because it depends on knowing |
| 302 | ** the internals of the sqlite3_context structure which is only defined in |
| 303 | ** this source file. |
| 304 | */ |
| 305 | int sqlite3_aggregate_count(sqlite3_context *p){ |
| 306 | assert( p && p->pFunc && p->pFunc->xStep ); |
| 307 | return p->cnt; |
| 308 | } |
| 309 | |
| 310 | /* |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 311 | ** Return the number of columns in the result set for the statement pStmt. |
| 312 | */ |
| 313 | int sqlite3_column_count(sqlite3_stmt *pStmt){ |
| 314 | Vdbe *pVm = (Vdbe *)pStmt; |
drh | 1bcdb0c | 2004-08-28 14:49:46 +0000 | [diff] [blame] | 315 | return pVm ? pVm->nResColumn : 0; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* |
| 319 | ** Return the number of values available from the current row of the |
| 320 | ** currently executing statement pStmt. |
| 321 | */ |
| 322 | int sqlite3_data_count(sqlite3_stmt *pStmt){ |
| 323 | Vdbe *pVm = (Vdbe *)pStmt; |
drh | 1bcdb0c | 2004-08-28 14:49:46 +0000 | [diff] [blame] | 324 | if( pVm==0 || !pVm->resOnStack ) return 0; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 325 | return pVm->nResColumn; |
| 326 | } |
| 327 | |
| 328 | |
| 329 | /* |
| 330 | ** Check to see if column iCol of the given statement is valid. If |
| 331 | ** it is, return a pointer to the Mem for the value of that column. |
| 332 | ** If iCol is not valid, return a pointer to a Mem which has a value |
| 333 | ** of NULL. |
| 334 | */ |
| 335 | static Mem *columnMem(sqlite3_stmt *pStmt, int i){ |
| 336 | Vdbe *pVm = (Vdbe *)pStmt; |
| 337 | int vals = sqlite3_data_count(pStmt); |
| 338 | if( i>=vals || i<0 ){ |
| 339 | static Mem nullMem; |
| 340 | if( nullMem.flags==0 ){ nullMem.flags = MEM_Null; } |
| 341 | sqlite3Error(pVm->db, SQLITE_RANGE, 0); |
| 342 | return &nullMem; |
| 343 | } |
| 344 | return &pVm->pTos[(1-vals)+i]; |
| 345 | } |
| 346 | |
| 347 | /**************************** sqlite3_column_ ******************************* |
| 348 | ** The following routines are used to access elements of the current row |
| 349 | ** in the result set. |
| 350 | */ |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 351 | const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){ |
| 352 | return sqlite3_value_blob( columnMem(pStmt,i) ); |
| 353 | } |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 354 | int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){ |
| 355 | return sqlite3_value_bytes( columnMem(pStmt,i) ); |
| 356 | } |
| 357 | int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){ |
| 358 | return sqlite3_value_bytes16( columnMem(pStmt,i) ); |
| 359 | } |
| 360 | double sqlite3_column_double(sqlite3_stmt *pStmt, int i){ |
| 361 | return sqlite3_value_double( columnMem(pStmt,i) ); |
| 362 | } |
| 363 | int sqlite3_column_int(sqlite3_stmt *pStmt, int i){ |
| 364 | return sqlite3_value_int( columnMem(pStmt,i) ); |
| 365 | } |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 366 | sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 367 | return sqlite3_value_int64( columnMem(pStmt,i) ); |
| 368 | } |
| 369 | const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){ |
| 370 | return sqlite3_value_text( columnMem(pStmt,i) ); |
| 371 | } |
drh | d1e4733 | 2005-06-26 17:55:33 +0000 | [diff] [blame^] | 372 | #if 0 |
| 373 | sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){ |
| 374 | return columnMem(pStmt, i); |
| 375 | } |
| 376 | #endif |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 377 | #ifndef SQLITE_OMIT_UTF16 |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 378 | const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){ |
| 379 | return sqlite3_value_text16( columnMem(pStmt,i) ); |
| 380 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 381 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 382 | int sqlite3_column_type(sqlite3_stmt *pStmt, int i){ |
| 383 | return sqlite3_value_type( columnMem(pStmt,i) ); |
| 384 | } |
| 385 | |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 386 | /* |
| 387 | ** Convert the N-th element of pStmt->pColName[] into a string using |
| 388 | ** xFunc() then return that string. If N is out of range, return 0. |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 389 | ** |
| 390 | ** There are up to 5 names for each column. useType determines which |
| 391 | ** name is returned. Here are the names: |
| 392 | ** |
| 393 | ** 0 The column name as it should be displayed for output |
| 394 | ** 1 The datatype name for the column |
| 395 | ** 2 The name of the database that the column derives from |
| 396 | ** 3 The name of the table that the column derives from |
| 397 | ** 4 The name of the table column that the result column derives from |
| 398 | ** |
| 399 | ** If the result is not a simple column reference (if it is an expression |
| 400 | ** or a constant) then useTypes 2, 3, and 4 return NULL. |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 401 | */ |
| 402 | static const void *columnName( |
| 403 | sqlite3_stmt *pStmt, |
| 404 | int N, |
| 405 | const void *(*xFunc)(Mem*), |
| 406 | int useType |
| 407 | ){ |
| 408 | Vdbe *p = (Vdbe *)pStmt; |
| 409 | int n = sqlite3_column_count(pStmt); |
| 410 | |
| 411 | if( p==0 || N>=n || N<0 ){ |
| 412 | return 0; |
| 413 | } |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 414 | N += useType*n; |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 415 | return xFunc(&p->aColName[N]); |
| 416 | } |
| 417 | |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | ** Return the name of the Nth column of the result set returned by SQL |
| 421 | ** statement pStmt. |
| 422 | */ |
| 423 | const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 424 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 425 | } |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 426 | #ifndef SQLITE_OMIT_UTF16 |
| 427 | const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){ |
| 428 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0); |
| 429 | } |
| 430 | #endif |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 431 | |
| 432 | /* |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 433 | ** Return the column declaration type (if applicable) of the 'i'th column |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 434 | ** of the result set of SQL statement pStmt. |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 435 | */ |
| 436 | const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){ |
| 437 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 1); |
| 438 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 439 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 76d505b | 2004-05-28 13:13:02 +0000 | [diff] [blame] | 440 | const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 441 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 442 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 443 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 444 | |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 445 | #if !defined(SQLITE_OMIT_ORIGIN_NAMES) && 0 |
| 446 | /* |
| 447 | ** Return the name of the database from which a result column derives. |
| 448 | ** NULL is returned if the result column is an expression or constant or |
| 449 | ** anything else which is not an unabiguous reference to a database column. |
| 450 | */ |
| 451 | const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){ |
| 452 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 2); |
| 453 | } |
| 454 | #ifndef SQLITE_OMIT_UTF16 |
| 455 | const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){ |
| 456 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 2); |
| 457 | } |
| 458 | #endif /* SQLITE_OMIT_UTF16 */ |
| 459 | |
| 460 | /* |
| 461 | ** Return the name of the table from which a result column derives. |
| 462 | ** NULL is returned if the result column is an expression or constant or |
| 463 | ** anything else which is not an unabiguous reference to a database column. |
| 464 | */ |
| 465 | const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){ |
| 466 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 3); |
| 467 | } |
| 468 | #ifndef SQLITE_OMIT_UTF16 |
| 469 | const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){ |
| 470 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 3); |
| 471 | } |
| 472 | #endif /* SQLITE_OMIT_UTF16 */ |
| 473 | |
| 474 | /* |
| 475 | ** Return the name of the table column from which a result column derives. |
| 476 | ** NULL is returned if the result column is an expression or constant or |
| 477 | ** anything else which is not an unabiguous reference to a database column. |
| 478 | */ |
| 479 | const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){ |
| 480 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 4); |
| 481 | } |
| 482 | #ifndef SQLITE_OMIT_UTF16 |
| 483 | const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){ |
| 484 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 4); |
| 485 | } |
| 486 | #endif /* SQLITE_OMIT_UTF16 */ |
| 487 | #endif /* SQLITE_OMIT_ORIGIN_NAMES */ |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 492 | /******************************* sqlite3_bind_ *************************** |
| 493 | ** |
| 494 | ** Routines used to attach values to wildcards in a compiled SQL statement. |
| 495 | */ |
| 496 | /* |
| 497 | ** Unbind the value bound to variable i in virtual machine p. This is the |
| 498 | ** the same as binding a NULL value to the column. If the "i" parameter is |
| 499 | ** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK. |
| 500 | ** |
| 501 | ** The error code stored in database p->db is overwritten with the return |
| 502 | ** value in any case. |
| 503 | */ |
| 504 | static int vdbeUnbind(Vdbe *p, int i){ |
| 505 | Mem *pVar; |
drh | 1bcdb0c | 2004-08-28 14:49:46 +0000 | [diff] [blame] | 506 | if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){ |
drh | 473d179 | 2005-06-06 17:54:55 +0000 | [diff] [blame] | 507 | if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 508 | return SQLITE_MISUSE; |
| 509 | } |
| 510 | if( i<1 || i>p->nVar ){ |
| 511 | sqlite3Error(p->db, SQLITE_RANGE, 0); |
| 512 | return SQLITE_RANGE; |
| 513 | } |
| 514 | i--; |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 515 | pVar = &p->aVar[i]; |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 516 | sqlite3VdbeMemRelease(pVar); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 517 | pVar->flags = MEM_Null; |
| 518 | sqlite3Error(p->db, SQLITE_OK, 0); |
| 519 | return SQLITE_OK; |
| 520 | } |
| 521 | |
| 522 | /* |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 523 | ** Bind a text or BLOB value. |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 524 | */ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 525 | static int bindText( |
drh | f447950 | 2004-05-27 03:12:53 +0000 | [diff] [blame] | 526 | sqlite3_stmt *pStmt, |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 527 | int i, |
| 528 | const void *zData, |
| 529 | int nData, |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 530 | void (*xDel)(void*), |
| 531 | int encoding |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 532 | ){ |
| 533 | Vdbe *p = (Vdbe *)pStmt; |
| 534 | Mem *pVar; |
| 535 | int rc; |
| 536 | |
| 537 | rc = vdbeUnbind(p, i); |
drh | feac5f8 | 2004-08-01 00:10:45 +0000 | [diff] [blame] | 538 | if( rc || zData==0 ){ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 539 | return rc; |
| 540 | } |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 541 | pVar = &p->aVar[i-1]; |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 542 | rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel); |
| 543 | if( rc ){ |
| 544 | return rc; |
| 545 | } |
| 546 | if( rc==SQLITE_OK && encoding!=0 ){ |
| 547 | rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc); |
| 548 | } |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 549 | return rc; |
| 550 | } |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 551 | |
| 552 | |
| 553 | /* |
| 554 | ** Bind a blob value to an SQL statement variable. |
| 555 | */ |
| 556 | int sqlite3_bind_blob( |
| 557 | sqlite3_stmt *pStmt, |
| 558 | int i, |
| 559 | const void *zData, |
| 560 | int nData, |
| 561 | void (*xDel)(void*) |
| 562 | ){ |
| 563 | return bindText(pStmt, i, zData, nData, xDel, 0); |
| 564 | } |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 565 | int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){ |
| 566 | int rc; |
| 567 | Vdbe *p = (Vdbe *)pStmt; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 568 | rc = vdbeUnbind(p, i); |
| 569 | if( rc==SQLITE_OK ){ |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 570 | sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 571 | } |
danielk1977 | f461889 | 2004-06-28 13:09:11 +0000 | [diff] [blame] | 572 | return rc; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 573 | } |
| 574 | int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){ |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 575 | return sqlite3_bind_int64(p, i, (i64)iValue); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 576 | } |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 577 | int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 578 | int rc; |
| 579 | Vdbe *p = (Vdbe *)pStmt; |
| 580 | rc = vdbeUnbind(p, i); |
| 581 | if( rc==SQLITE_OK ){ |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 582 | sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 583 | } |
| 584 | return rc; |
| 585 | } |
| 586 | int sqlite3_bind_null(sqlite3_stmt* p, int i){ |
| 587 | return vdbeUnbind((Vdbe *)p, i); |
| 588 | } |
| 589 | int sqlite3_bind_text( |
| 590 | sqlite3_stmt *pStmt, |
| 591 | int i, |
| 592 | const char *zData, |
| 593 | int nData, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 594 | void (*xDel)(void*) |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 595 | ){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 596 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 597 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 598 | #ifndef SQLITE_OMIT_UTF16 |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 599 | int sqlite3_bind_text16( |
| 600 | sqlite3_stmt *pStmt, |
| 601 | int i, |
| 602 | const void *zData, |
| 603 | int nData, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 604 | void (*xDel)(void*) |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 605 | ){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 606 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 607 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 608 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 609 | |
| 610 | /* |
| 611 | ** Return the number of wildcards that can be potentially bound to. |
| 612 | ** This routine is added to support DBD::SQLite. |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 613 | */ |
| 614 | int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){ |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 615 | Vdbe *p = (Vdbe*)pStmt; |
| 616 | return p ? p->nVar : 0; |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 617 | } |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 618 | |
| 619 | /* |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 620 | ** Create a mapping from variable numbers to variable names |
| 621 | ** in the Vdbe.azVar[] array, if such a mapping does not already |
| 622 | ** exist. |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 623 | */ |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 624 | static void createVarMap(Vdbe *p){ |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 625 | if( !p->okVar ){ |
| 626 | int j; |
| 627 | Op *pOp; |
| 628 | for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){ |
| 629 | if( pOp->opcode==OP_Variable ){ |
| 630 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 631 | p->azVar[pOp->p1-1] = pOp->p3; |
| 632 | } |
| 633 | } |
| 634 | p->okVar = 1; |
| 635 | } |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /* |
| 639 | ** Return the name of a wildcard parameter. Return NULL if the index |
| 640 | ** is out of range or if the wildcard is unnamed. |
| 641 | ** |
| 642 | ** The result is always UTF-8. |
| 643 | */ |
| 644 | const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){ |
| 645 | Vdbe *p = (Vdbe*)pStmt; |
| 646 | if( p==0 || i<1 || i>p->nVar ){ |
| 647 | return 0; |
| 648 | } |
| 649 | createVarMap(p); |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 650 | return p->azVar[i-1]; |
| 651 | } |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | ** Given a wildcard parameter name, return the index of the variable |
| 655 | ** with that name. If there is no variable with the given name, |
| 656 | ** return 0. |
| 657 | */ |
| 658 | int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){ |
| 659 | Vdbe *p = (Vdbe*)pStmt; |
| 660 | int i; |
| 661 | if( p==0 ){ |
| 662 | return 0; |
| 663 | } |
| 664 | createVarMap(p); |
drh | 6a8903c | 2004-12-10 18:00:04 +0000 | [diff] [blame] | 665 | if( zName ){ |
| 666 | for(i=0; i<p->nVar; i++){ |
| 667 | const char *z = p->azVar[i]; |
| 668 | if( z && strcmp(z,zName)==0 ){ |
| 669 | return i+1; |
| 670 | } |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | return 0; |
| 674 | } |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 675 | |
drh | 51942bc | 2005-06-12 22:01:42 +0000 | [diff] [blame] | 676 | /* |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 677 | ** Transfer all bindings from the first statement over to the second. |
| 678 | ** If the two statements contain a different number of bindings, then |
| 679 | ** an SQLITE_ERROR is returned. |
| 680 | */ |
| 681 | int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ |
| 682 | Vdbe *pFrom = (Vdbe*)pFromStmt; |
| 683 | Vdbe *pTo = (Vdbe*)pToStmt; |
| 684 | int i, rc = SQLITE_OK; |
| 685 | if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT) |
| 686 | || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) ){ |
| 687 | return SQLITE_MISUSE; |
| 688 | } |
| 689 | if( pFrom->nVar!=pTo->nVar ){ |
| 690 | return SQLITE_ERROR; |
| 691 | } |
| 692 | for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){ |
| 693 | rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]); |
| 694 | } |
| 695 | return rc; |
| 696 | } |
drh | 51942bc | 2005-06-12 22:01:42 +0000 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | ** Return the sqlite3* database handle to which the prepared statement given |
| 700 | ** in the argument belongs. This is the same database handle that was |
| 701 | ** the first argument to the sqlite3_prepare() that was used to create |
| 702 | ** the statement in the first place. |
| 703 | */ |
| 704 | sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){ |
| 705 | return pStmt ? ((Vdbe*)pStmt)->db : 0; |
| 706 | } |