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 | ){ |
| 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 | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 372 | #ifndef SQLITE_OMIT_UTF16 |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 373 | const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){ |
| 374 | return sqlite3_value_text16( columnMem(pStmt,i) ); |
| 375 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 376 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 377 | int sqlite3_column_type(sqlite3_stmt *pStmt, int i){ |
| 378 | return sqlite3_value_type( columnMem(pStmt,i) ); |
| 379 | } |
| 380 | |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 381 | /* |
| 382 | ** Convert the N-th element of pStmt->pColName[] into a string using |
| 383 | ** xFunc() then return that string. If N is out of range, return 0. |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 384 | ** |
| 385 | ** There are up to 5 names for each column. useType determines which |
| 386 | ** name is returned. Here are the names: |
| 387 | ** |
| 388 | ** 0 The column name as it should be displayed for output |
| 389 | ** 1 The datatype name for the column |
| 390 | ** 2 The name of the database that the column derives from |
| 391 | ** 3 The name of the table that the column derives from |
| 392 | ** 4 The name of the table column that the result column derives from |
| 393 | ** |
| 394 | ** If the result is not a simple column reference (if it is an expression |
| 395 | ** or a constant) then useTypes 2, 3, and 4 return NULL. |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 396 | */ |
| 397 | static const void *columnName( |
| 398 | sqlite3_stmt *pStmt, |
| 399 | int N, |
| 400 | const void *(*xFunc)(Mem*), |
| 401 | int useType |
| 402 | ){ |
| 403 | Vdbe *p = (Vdbe *)pStmt; |
| 404 | int n = sqlite3_column_count(pStmt); |
| 405 | |
| 406 | if( p==0 || N>=n || N<0 ){ |
| 407 | return 0; |
| 408 | } |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 409 | N += useType*n; |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 410 | return xFunc(&p->aColName[N]); |
| 411 | } |
| 412 | |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 413 | |
| 414 | /* |
| 415 | ** Return the name of the Nth column of the result set returned by SQL |
| 416 | ** statement pStmt. |
| 417 | */ |
| 418 | const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 419 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 420 | } |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 421 | #ifndef SQLITE_OMIT_UTF16 |
| 422 | const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){ |
| 423 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0); |
| 424 | } |
| 425 | #endif |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 426 | |
| 427 | /* |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 428 | ** Return the column declaration type (if applicable) of the 'i'th column |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 429 | ** of the result set of SQL statement pStmt. |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 430 | */ |
| 431 | const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){ |
| 432 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 1); |
| 433 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 434 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 76d505b | 2004-05-28 13:13:02 +0000 | [diff] [blame] | 435 | const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 436 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 437 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 438 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 439 | |
drh | e590fbd | 2005-05-20 19:36:01 +0000 | [diff] [blame] | 440 | #if !defined(SQLITE_OMIT_ORIGIN_NAMES) && 0 |
| 441 | /* |
| 442 | ** Return the name of the database from which a result column derives. |
| 443 | ** NULL is returned if the result column is an expression or constant or |
| 444 | ** anything else which is not an unabiguous reference to a database column. |
| 445 | */ |
| 446 | const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){ |
| 447 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 2); |
| 448 | } |
| 449 | #ifndef SQLITE_OMIT_UTF16 |
| 450 | const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){ |
| 451 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 2); |
| 452 | } |
| 453 | #endif /* SQLITE_OMIT_UTF16 */ |
| 454 | |
| 455 | /* |
| 456 | ** Return the name of the table from which a result column derives. |
| 457 | ** NULL is returned if the result column is an expression or constant or |
| 458 | ** anything else which is not an unabiguous reference to a database column. |
| 459 | */ |
| 460 | const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){ |
| 461 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 3); |
| 462 | } |
| 463 | #ifndef SQLITE_OMIT_UTF16 |
| 464 | const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){ |
| 465 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 3); |
| 466 | } |
| 467 | #endif /* SQLITE_OMIT_UTF16 */ |
| 468 | |
| 469 | /* |
| 470 | ** Return the name of the table column from which a result column derives. |
| 471 | ** NULL is returned if the result column is an expression or constant or |
| 472 | ** anything else which is not an unabiguous reference to a database column. |
| 473 | */ |
| 474 | const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){ |
| 475 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 4); |
| 476 | } |
| 477 | #ifndef SQLITE_OMIT_UTF16 |
| 478 | const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){ |
| 479 | return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 4); |
| 480 | } |
| 481 | #endif /* SQLITE_OMIT_UTF16 */ |
| 482 | #endif /* SQLITE_OMIT_ORIGIN_NAMES */ |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 487 | /******************************* sqlite3_bind_ *************************** |
| 488 | ** |
| 489 | ** Routines used to attach values to wildcards in a compiled SQL statement. |
| 490 | */ |
| 491 | /* |
| 492 | ** Unbind the value bound to variable i in virtual machine p. This is the |
| 493 | ** the same as binding a NULL value to the column. If the "i" parameter is |
| 494 | ** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK. |
| 495 | ** |
| 496 | ** The error code stored in database p->db is overwritten with the return |
| 497 | ** value in any case. |
| 498 | */ |
| 499 | static int vdbeUnbind(Vdbe *p, int i){ |
| 500 | Mem *pVar; |
drh | 1bcdb0c | 2004-08-28 14:49:46 +0000 | [diff] [blame] | 501 | if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){ |
drh | 473d179 | 2005-06-06 17:54:55 +0000 | [diff] [blame] | 502 | if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 503 | return SQLITE_MISUSE; |
| 504 | } |
| 505 | if( i<1 || i>p->nVar ){ |
| 506 | sqlite3Error(p->db, SQLITE_RANGE, 0); |
| 507 | return SQLITE_RANGE; |
| 508 | } |
| 509 | i--; |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 510 | pVar = &p->aVar[i]; |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 511 | sqlite3VdbeMemRelease(pVar); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 512 | pVar->flags = MEM_Null; |
| 513 | sqlite3Error(p->db, SQLITE_OK, 0); |
| 514 | return SQLITE_OK; |
| 515 | } |
| 516 | |
| 517 | /* |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 518 | ** Bind a text or BLOB value. |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 519 | */ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 520 | static int bindText( |
drh | f447950 | 2004-05-27 03:12:53 +0000 | [diff] [blame] | 521 | sqlite3_stmt *pStmt, |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 522 | int i, |
| 523 | const void *zData, |
| 524 | int nData, |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 525 | void (*xDel)(void*), |
| 526 | int encoding |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 527 | ){ |
| 528 | Vdbe *p = (Vdbe *)pStmt; |
| 529 | Mem *pVar; |
| 530 | int rc; |
| 531 | |
| 532 | rc = vdbeUnbind(p, i); |
drh | feac5f8 | 2004-08-01 00:10:45 +0000 | [diff] [blame] | 533 | if( rc || zData==0 ){ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 534 | return rc; |
| 535 | } |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 536 | pVar = &p->aVar[i-1]; |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 537 | rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel); |
| 538 | if( rc ){ |
| 539 | return rc; |
| 540 | } |
| 541 | if( rc==SQLITE_OK && encoding!=0 ){ |
| 542 | rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc); |
| 543 | } |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 544 | return rc; |
| 545 | } |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 546 | |
| 547 | |
| 548 | /* |
| 549 | ** Bind a blob value to an SQL statement variable. |
| 550 | */ |
| 551 | int sqlite3_bind_blob( |
| 552 | sqlite3_stmt *pStmt, |
| 553 | int i, |
| 554 | const void *zData, |
| 555 | int nData, |
| 556 | void (*xDel)(void*) |
| 557 | ){ |
| 558 | return bindText(pStmt, i, zData, nData, xDel, 0); |
| 559 | } |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 560 | int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){ |
| 561 | int rc; |
| 562 | Vdbe *p = (Vdbe *)pStmt; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 563 | rc = vdbeUnbind(p, i); |
| 564 | if( rc==SQLITE_OK ){ |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 565 | sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 566 | } |
danielk1977 | f461889 | 2004-06-28 13:09:11 +0000 | [diff] [blame] | 567 | return rc; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 568 | } |
| 569 | int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){ |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 570 | return sqlite3_bind_int64(p, i, (i64)iValue); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 571 | } |
drh | efad999 | 2004-06-22 12:13:55 +0000 | [diff] [blame] | 572 | int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){ |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 573 | int rc; |
| 574 | Vdbe *p = (Vdbe *)pStmt; |
| 575 | rc = vdbeUnbind(p, i); |
| 576 | if( rc==SQLITE_OK ){ |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 577 | sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 578 | } |
| 579 | return rc; |
| 580 | } |
| 581 | int sqlite3_bind_null(sqlite3_stmt* p, int i){ |
| 582 | return vdbeUnbind((Vdbe *)p, i); |
| 583 | } |
| 584 | int sqlite3_bind_text( |
| 585 | sqlite3_stmt *pStmt, |
| 586 | int i, |
| 587 | const char *zData, |
| 588 | int nData, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 589 | void (*xDel)(void*) |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 590 | ){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 591 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 592 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 593 | #ifndef SQLITE_OMIT_UTF16 |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 594 | int sqlite3_bind_text16( |
| 595 | sqlite3_stmt *pStmt, |
| 596 | int i, |
| 597 | const void *zData, |
| 598 | int nData, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 599 | void (*xDel)(void*) |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 600 | ){ |
drh | 5e2517e | 2004-09-24 23:59:12 +0000 | [diff] [blame] | 601 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE); |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 602 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 603 | #endif /* SQLITE_OMIT_UTF16 */ |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 604 | |
| 605 | /* |
| 606 | ** Return the number of wildcards that can be potentially bound to. |
| 607 | ** This routine is added to support DBD::SQLite. |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 608 | */ |
| 609 | int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){ |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 610 | Vdbe *p = (Vdbe*)pStmt; |
| 611 | return p ? p->nVar : 0; |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 612 | } |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 613 | |
| 614 | /* |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 615 | ** Create a mapping from variable numbers to variable names |
| 616 | ** in the Vdbe.azVar[] array, if such a mapping does not already |
| 617 | ** exist. |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 618 | */ |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 619 | static void createVarMap(Vdbe *p){ |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 620 | if( !p->okVar ){ |
| 621 | int j; |
| 622 | Op *pOp; |
| 623 | for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){ |
| 624 | if( pOp->opcode==OP_Variable ){ |
| 625 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 626 | p->azVar[pOp->p1-1] = pOp->p3; |
| 627 | } |
| 628 | } |
| 629 | p->okVar = 1; |
| 630 | } |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* |
| 634 | ** Return the name of a wildcard parameter. Return NULL if the index |
| 635 | ** is out of range or if the wildcard is unnamed. |
| 636 | ** |
| 637 | ** The result is always UTF-8. |
| 638 | */ |
| 639 | const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){ |
| 640 | Vdbe *p = (Vdbe*)pStmt; |
| 641 | if( p==0 || i<1 || i>p->nVar ){ |
| 642 | return 0; |
| 643 | } |
| 644 | createVarMap(p); |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 645 | return p->azVar[i-1]; |
| 646 | } |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 647 | |
| 648 | /* |
| 649 | ** Given a wildcard parameter name, return the index of the variable |
| 650 | ** with that name. If there is no variable with the given name, |
| 651 | ** return 0. |
| 652 | */ |
| 653 | int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){ |
| 654 | Vdbe *p = (Vdbe*)pStmt; |
| 655 | int i; |
| 656 | if( p==0 ){ |
| 657 | return 0; |
| 658 | } |
| 659 | createVarMap(p); |
drh | 6a8903c | 2004-12-10 18:00:04 +0000 | [diff] [blame] | 660 | if( zName ){ |
| 661 | for(i=0; i<p->nVar; i++){ |
| 662 | const char *z = p->azVar[i]; |
| 663 | if( z && strcmp(z,zName)==0 ){ |
| 664 | return i+1; |
| 665 | } |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | return 0; |
| 669 | } |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 670 | |
drh | 51942bc | 2005-06-12 22:01:42 +0000 | [diff] [blame^] | 671 | /* |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 672 | ** Transfer all bindings from the first statement over to the second. |
| 673 | ** If the two statements contain a different number of bindings, then |
| 674 | ** an SQLITE_ERROR is returned. |
| 675 | */ |
| 676 | int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ |
| 677 | Vdbe *pFrom = (Vdbe*)pFromStmt; |
| 678 | Vdbe *pTo = (Vdbe*)pToStmt; |
| 679 | int i, rc = SQLITE_OK; |
| 680 | if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT) |
| 681 | || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) ){ |
| 682 | return SQLITE_MISUSE; |
| 683 | } |
| 684 | if( pFrom->nVar!=pTo->nVar ){ |
| 685 | return SQLITE_ERROR; |
| 686 | } |
| 687 | for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){ |
| 688 | rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]); |
| 689 | } |
| 690 | return rc; |
| 691 | } |
drh | 51942bc | 2005-06-12 22:01:42 +0000 | [diff] [blame^] | 692 | |
| 693 | /* |
| 694 | ** Return the sqlite3* database handle to which the prepared statement given |
| 695 | ** in the argument belongs. This is the same database handle that was |
| 696 | ** the first argument to the sqlite3_prepare() that was used to create |
| 697 | ** the statement in the first place. |
| 698 | */ |
| 699 | sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){ |
| 700 | return pStmt ? ((Vdbe*)pStmt)->db : 0; |
| 701 | } |