danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2005 May 25 |
| 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 | ** This file contains the implementation of the sqlite3_prepare() |
| 13 | ** interface, and routines that contribute to loading the database schema |
| 14 | ** from disk. |
| 15 | ** |
drh | 3c23a88 | 2007-01-09 14:01:13 +0000 | [diff] [blame^] | 16 | ** $Id: prepare.c,v 1.43 2007/01/09 14:01:13 drh Exp $ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 17 | */ |
| 18 | #include "sqliteInt.h" |
| 19 | #include "os.h" |
| 20 | #include <ctype.h> |
| 21 | |
| 22 | /* |
| 23 | ** Fill the InitData structure with an error message that indicates |
| 24 | ** that the database is corrupt. |
| 25 | */ |
| 26 | static void corruptSchema(InitData *pData, const char *zExtra){ |
danielk1977 | 9e12800 | 2006-01-18 16:51:35 +0000 | [diff] [blame] | 27 | if( !sqlite3MallocFailed() ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 28 | sqlite3SetString(pData->pzErrMsg, "malformed database schema", |
| 29 | zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0); |
| 30 | } |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 31 | pData->rc = SQLITE_CORRUPT; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /* |
| 35 | ** This is the callback routine for the code that initializes the |
| 36 | ** database. See sqlite3Init() below for additional information. |
| 37 | ** This routine is also called from the OP_ParseSchema opcode of the VDBE. |
| 38 | ** |
| 39 | ** Each callback contains the following information: |
| 40 | ** |
| 41 | ** argv[0] = name of thing being created |
danielk1977 | 78efaba | 2006-06-12 06:09:17 +0000 | [diff] [blame] | 42 | ** argv[1] = root page number for table or index. 0 for trigger or view. |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 43 | ** argv[2] = SQL text for the CREATE statement. |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 44 | ** |
| 45 | */ |
| 46 | int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){ |
| 47 | InitData *pData = (InitData*)pInit; |
| 48 | sqlite3 *db = pData->db; |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 49 | int iDb = pData->iDb; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 50 | |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 51 | pData->rc = SQLITE_OK; |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 52 | DbClearProperty(db, iDb, DB_Empty); |
danielk1977 | 9e12800 | 2006-01-18 16:51:35 +0000 | [diff] [blame] | 53 | if( sqlite3MallocFailed() ){ |
drh | fe5a816 | 2006-08-12 13:28:23 +0000 | [diff] [blame] | 54 | corruptSchema(pData, 0); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 55 | return SQLITE_NOMEM; |
| 56 | } |
| 57 | |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 58 | assert( argc==3 ); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 59 | if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 60 | if( argv[1]==0 ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 61 | corruptSchema(pData, 0); |
| 62 | return 1; |
| 63 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 64 | assert( iDb>=0 && iDb<db->nDb ); |
| 65 | if( argv[2] && argv[2][0] ){ |
| 66 | /* Call the parser to process a CREATE TABLE, INDEX or VIEW. |
| 67 | ** But because db->init.busy is set to 1, no VDBE code is generated |
| 68 | ** or executed. All the parser does is build the internal data |
| 69 | ** structures that describe the table, index, or view. |
| 70 | */ |
| 71 | char *zErr; |
| 72 | int rc; |
| 73 | assert( db->init.busy ); |
| 74 | db->init.iDb = iDb; |
| 75 | db->init.newTnum = atoi(argv[1]); |
| 76 | rc = sqlite3_exec(db, argv[2], 0, 0, &zErr); |
| 77 | db->init.iDb = 0; |
drh | 43617e9 | 2006-03-06 20:55:46 +0000 | [diff] [blame] | 78 | assert( rc!=SQLITE_OK || zErr==0 ); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 79 | if( SQLITE_OK!=rc ){ |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 80 | pData->rc = rc; |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 81 | if( rc==SQLITE_NOMEM ){ |
danielk1977 | 9e12800 | 2006-01-18 16:51:35 +0000 | [diff] [blame] | 82 | sqlite3FailedMalloc(); |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 83 | }else if( rc!=SQLITE_INTERRUPT ){ |
danielk1977 | 9e12800 | 2006-01-18 16:51:35 +0000 | [diff] [blame] | 84 | corruptSchema(pData, zErr); |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 85 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 86 | sqlite3_free(zErr); |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 87 | return 1; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 88 | } |
| 89 | }else{ |
| 90 | /* If the SQL column is blank it means this is an index that |
| 91 | ** was created to be the PRIMARY KEY or to fulfill a UNIQUE |
| 92 | ** constraint for a CREATE TABLE. The index should have already |
| 93 | ** been created when we processed the CREATE TABLE. All we have |
| 94 | ** to do here is record the root page number for that index. |
| 95 | */ |
| 96 | Index *pIndex; |
| 97 | pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName); |
| 98 | if( pIndex==0 || pIndex->tnum!=0 ){ |
| 99 | /* This can occur if there exists an index on a TEMP table which |
| 100 | ** has the same name as another index on a permanent index. Since |
| 101 | ** the permanent table is hidden by the TEMP table, we can also |
| 102 | ** safely ignore the index on the permanent table. |
| 103 | */ |
| 104 | /* Do Nothing */; |
| 105 | }else{ |
| 106 | pIndex->tnum = atoi(argv[1]); |
| 107 | } |
| 108 | } |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | ** Attempt to read the database schema and initialize internal |
| 114 | ** data structures for a single database file. The index of the |
| 115 | ** database file is given by iDb. iDb==0 is used for the main |
| 116 | ** database. iDb==1 should never be used. iDb>=2 is used for |
| 117 | ** auxiliary databases. Return one of the SQLITE_ error codes to |
| 118 | ** indicate success or failure. |
| 119 | */ |
| 120 | static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ |
| 121 | int rc; |
| 122 | BtCursor *curMain; |
| 123 | int size; |
| 124 | Table *pTab; |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 125 | Db *pDb; |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 126 | char const *azArg[4]; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 127 | int meta[10]; |
| 128 | InitData initData; |
| 129 | char const *zMasterSchema; |
| 130 | char const *zMasterName = SCHEMA_TABLE(iDb); |
| 131 | |
| 132 | /* |
| 133 | ** The master database table has a structure like this |
| 134 | */ |
| 135 | static const char master_schema[] = |
| 136 | "CREATE TABLE sqlite_master(\n" |
| 137 | " type text,\n" |
| 138 | " name text,\n" |
| 139 | " tbl_name text,\n" |
| 140 | " rootpage integer,\n" |
| 141 | " sql text\n" |
| 142 | ")" |
| 143 | ; |
| 144 | #ifndef SQLITE_OMIT_TEMPDB |
| 145 | static const char temp_master_schema[] = |
| 146 | "CREATE TEMP TABLE sqlite_temp_master(\n" |
| 147 | " type text,\n" |
| 148 | " name text,\n" |
| 149 | " tbl_name text,\n" |
| 150 | " rootpage integer,\n" |
| 151 | " sql text\n" |
| 152 | ")" |
| 153 | ; |
| 154 | #else |
| 155 | #define temp_master_schema 0 |
| 156 | #endif |
| 157 | |
| 158 | assert( iDb>=0 && iDb<db->nDb ); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 159 | assert( db->aDb[iDb].pSchema ); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 160 | |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 161 | /* zMasterSchema and zInitScript are set to point at the master schema |
| 162 | ** and initialisation script appropriate for the database being |
| 163 | ** initialised. zMasterName is the name of the master table. |
| 164 | */ |
| 165 | if( !OMIT_TEMPDB && iDb==1 ){ |
| 166 | zMasterSchema = temp_master_schema; |
| 167 | }else{ |
| 168 | zMasterSchema = master_schema; |
| 169 | } |
| 170 | zMasterName = SCHEMA_TABLE(iDb); |
| 171 | |
| 172 | /* Construct the schema tables. */ |
| 173 | sqlite3SafetyOff(db); |
| 174 | azArg[0] = zMasterName; |
| 175 | azArg[1] = "1"; |
| 176 | azArg[2] = zMasterSchema; |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 177 | azArg[3] = 0; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 178 | initData.db = db; |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 179 | initData.iDb = iDb; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 180 | initData.pzErrMsg = pzErrMsg; |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 181 | rc = sqlite3InitCallback(&initData, 3, (char **)azArg, 0); |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 182 | if( rc ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 183 | sqlite3SafetyOn(db); |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 184 | return initData.rc; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 185 | } |
| 186 | pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName); |
| 187 | if( pTab ){ |
| 188 | pTab->readOnly = 1; |
| 189 | } |
| 190 | sqlite3SafetyOn(db); |
| 191 | |
| 192 | /* Create a cursor to hold the database open |
| 193 | */ |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 194 | pDb = &db->aDb[iDb]; |
| 195 | if( pDb->pBt==0 ){ |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 196 | if( !OMIT_TEMPDB && iDb==1 ){ |
| 197 | DbSetProperty(db, 1, DB_SchemaLoaded); |
| 198 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 199 | return SQLITE_OK; |
| 200 | } |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 201 | rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, 0, &curMain); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 202 | if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){ |
| 203 | sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); |
| 204 | return rc; |
| 205 | } |
| 206 | |
| 207 | /* Get the database meta information. |
| 208 | ** |
| 209 | ** Meta values are as follows: |
| 210 | ** meta[0] Schema cookie. Changes with each schema change. |
| 211 | ** meta[1] File format of schema layer. |
| 212 | ** meta[2] Size of the page cache. |
| 213 | ** meta[3] Use freelist if 0. Autovacuum if greater than zero. |
drh | 8159a35 | 2006-05-23 23:22:29 +0000 | [diff] [blame] | 214 | ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 215 | ** meta[5] The user cookie. Used by the application. |
| 216 | ** meta[6] |
| 217 | ** meta[7] |
| 218 | ** meta[8] |
| 219 | ** meta[9] |
| 220 | ** |
drh | f248e21 | 2006-01-25 22:50:38 +0000 | [diff] [blame] | 221 | ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 222 | ** the possible values of meta[4]. |
| 223 | */ |
| 224 | if( rc==SQLITE_OK ){ |
| 225 | int i; |
| 226 | for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){ |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 227 | rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 228 | } |
| 229 | if( rc ){ |
| 230 | sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); |
| 231 | sqlite3BtreeCloseCursor(curMain); |
| 232 | return rc; |
| 233 | } |
| 234 | }else{ |
| 235 | memset(meta, 0, sizeof(meta)); |
| 236 | } |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 237 | pDb->pSchema->schema_cookie = meta[0]; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 238 | |
| 239 | /* If opening a non-empty database, check the text encoding. For the |
| 240 | ** main database, set sqlite3.enc to the encoding of the main database. |
| 241 | ** For an attached db, it is an error if the encoding is not the same |
| 242 | ** as sqlite3.enc. |
| 243 | */ |
| 244 | if( meta[4] ){ /* text encoding */ |
| 245 | if( iDb==0 ){ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 246 | /* If opening the main database, set ENC(db). */ |
| 247 | ENC(db) = (u8)meta[4]; |
danielk1977 | b3bf556 | 2006-01-10 17:58:23 +0000 | [diff] [blame] | 248 | db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 249 | }else{ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 250 | /* If opening an attached database, the encoding much match ENC(db) */ |
| 251 | if( meta[4]!=ENC(db) ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 252 | sqlite3BtreeCloseCursor(curMain); |
| 253 | sqlite3SetString(pzErrMsg, "attached databases must use the same" |
| 254 | " text encoding as main database", (char*)0); |
| 255 | return SQLITE_ERROR; |
| 256 | } |
| 257 | } |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 258 | }else{ |
| 259 | DbSetProperty(db, iDb, DB_Empty); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 260 | } |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 261 | pDb->pSchema->enc = ENC(db); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 262 | |
| 263 | size = meta[2]; |
| 264 | if( size==0 ){ size = MAX_PAGES; } |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 265 | pDb->pSchema->cache_size = size; |
| 266 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | ** file_format==1 Version 3.0.0. |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 270 | ** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN |
| 271 | ** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults |
drh | d946db0 | 2005-12-29 19:23:06 +0000 | [diff] [blame] | 272 | ** file_format==4 Version 3.3.0. // DESC indices. Boolean constants |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 273 | */ |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 274 | pDb->pSchema->file_format = meta[1]; |
| 275 | if( pDb->pSchema->file_format==0 ){ |
| 276 | pDb->pSchema->file_format = 1; |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 277 | } |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 278 | if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 279 | sqlite3BtreeCloseCursor(curMain); |
| 280 | sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0); |
| 281 | return SQLITE_ERROR; |
| 282 | } |
| 283 | |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 284 | |
| 285 | /* Read the schema information out of the schema tables |
| 286 | */ |
| 287 | assert( db->init.busy ); |
| 288 | if( rc==SQLITE_EMPTY ){ |
| 289 | /* For an empty database, there is nothing to read */ |
| 290 | rc = SQLITE_OK; |
| 291 | }else{ |
| 292 | char *zSql; |
| 293 | zSql = sqlite3MPrintf( |
drh | ece3c72 | 2006-09-23 20:36:01 +0000 | [diff] [blame] | 294 | "SELECT name, rootpage, sql FROM '%q'.%s", |
| 295 | db->aDb[iDb].zName, zMasterName); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 296 | sqlite3SafetyOff(db); |
| 297 | rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); |
drh | 15ca1df | 2006-07-26 13:43:30 +0000 | [diff] [blame] | 298 | if( rc==SQLITE_ABORT ) rc = initData.rc; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 299 | sqlite3SafetyOn(db); |
| 300 | sqliteFree(zSql); |
drh | 497e446 | 2005-07-23 03:18:40 +0000 | [diff] [blame] | 301 | #ifndef SQLITE_OMIT_ANALYZE |
| 302 | if( rc==SQLITE_OK ){ |
| 303 | sqlite3AnalysisLoad(db, iDb); |
| 304 | } |
| 305 | #endif |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 306 | sqlite3BtreeCloseCursor(curMain); |
| 307 | } |
danielk1977 | 9e12800 | 2006-01-18 16:51:35 +0000 | [diff] [blame] | 308 | if( sqlite3MallocFailed() ){ |
| 309 | /* sqlite3SetString(pzErrMsg, "out of memory", (char*)0); */ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 310 | rc = SQLITE_NOMEM; |
| 311 | sqlite3ResetInternalSchema(db, 0); |
| 312 | } |
| 313 | if( rc==SQLITE_OK ){ |
| 314 | DbSetProperty(db, iDb, DB_SchemaLoaded); |
| 315 | }else{ |
| 316 | sqlite3ResetInternalSchema(db, iDb); |
| 317 | } |
| 318 | return rc; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | ** Initialize all database files - the main database file, the file |
| 323 | ** used to store temporary tables, and any additional database files |
| 324 | ** created using ATTACH statements. Return a success code. If an |
| 325 | ** error occurs, write an error message into *pzErrMsg. |
| 326 | ** |
danielk1977 | e725929 | 2006-01-13 06:33:23 +0000 | [diff] [blame] | 327 | ** After a database is initialized, the DB_SchemaLoaded bit is set |
| 328 | ** bit is set in the flags field of the Db structure. If the database |
| 329 | ** file was of zero-length, then the DB_Empty flag is also set. |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 330 | */ |
| 331 | int sqlite3Init(sqlite3 *db, char **pzErrMsg){ |
| 332 | int i, rc; |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 333 | int called_initone = 0; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 334 | |
| 335 | if( db->init.busy ) return SQLITE_OK; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 336 | rc = SQLITE_OK; |
| 337 | db->init.busy = 1; |
| 338 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 339 | if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; |
| 340 | rc = sqlite3InitOne(db, i, pzErrMsg); |
| 341 | if( rc ){ |
| 342 | sqlite3ResetInternalSchema(db, i); |
| 343 | } |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 344 | called_initone = 1; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /* Once all the other databases have been initialised, load the schema |
| 348 | ** for the TEMP database. This is loaded last, as the TEMP database |
| 349 | ** schema may contain references to objects in other databases. |
| 350 | */ |
| 351 | #ifndef SQLITE_OMIT_TEMPDB |
| 352 | if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ |
| 353 | rc = sqlite3InitOne(db, 1, pzErrMsg); |
| 354 | if( rc ){ |
| 355 | sqlite3ResetInternalSchema(db, 1); |
| 356 | } |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 357 | called_initone = 1; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 358 | } |
| 359 | #endif |
| 360 | |
| 361 | db->init.busy = 0; |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 362 | if( rc==SQLITE_OK && called_initone ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 363 | sqlite3CommitInternalChanges(db); |
| 364 | } |
| 365 | |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 366 | return rc; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /* |
| 370 | ** This routine is a no-op if the database schema is already initialised. |
| 371 | ** Otherwise, the schema is loaded. An error code is returned. |
| 372 | */ |
| 373 | int sqlite3ReadSchema(Parse *pParse){ |
| 374 | int rc = SQLITE_OK; |
| 375 | sqlite3 *db = pParse->db; |
| 376 | if( !db->init.busy ){ |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 377 | rc = sqlite3Init(db, &pParse->zErrMsg); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 378 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 379 | if( rc!=SQLITE_OK ){ |
| 380 | pParse->rc = rc; |
| 381 | pParse->nErr++; |
| 382 | } |
| 383 | return rc; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | /* |
| 388 | ** Check schema cookies in all databases. If any cookie is out |
| 389 | ** of date, return 0. If all schema cookies are current, return 1. |
| 390 | */ |
| 391 | static int schemaIsValid(sqlite3 *db){ |
| 392 | int iDb; |
| 393 | int rc; |
| 394 | BtCursor *curTemp; |
| 395 | int cookie; |
| 396 | int allOk = 1; |
| 397 | |
| 398 | for(iDb=0; allOk && iDb<db->nDb; iDb++){ |
| 399 | Btree *pBt; |
| 400 | pBt = db->aDb[iDb].pBt; |
| 401 | if( pBt==0 ) continue; |
| 402 | rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp); |
| 403 | if( rc==SQLITE_OK ){ |
| 404 | rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 405 | if( rc==SQLITE_OK && cookie!=db->aDb[iDb].pSchema->schema_cookie ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 406 | allOk = 0; |
| 407 | } |
| 408 | sqlite3BtreeCloseCursor(curTemp); |
| 409 | } |
| 410 | } |
| 411 | return allOk; |
| 412 | } |
| 413 | |
| 414 | /* |
drh | f248e21 | 2006-01-25 22:50:38 +0000 | [diff] [blame] | 415 | ** Convert a schema pointer into the iDb index that indicates |
| 416 | ** which database file in db->aDb[] the schema refers to. |
| 417 | ** |
| 418 | ** If the same database is attached more than once, the first |
| 419 | ** attached database is returned. |
| 420 | */ |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 421 | int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){ |
drh | 198bf39 | 2006-01-06 21:52:49 +0000 | [diff] [blame] | 422 | int i = -1000000; |
| 423 | |
| 424 | /* If pSchema is NULL, then return -1000000. This happens when code in |
| 425 | ** expr.c is trying to resolve a reference to a transient table (i.e. one |
| 426 | ** created by a sub-select). In this case the return value of this |
| 427 | ** function should never be used. |
| 428 | ** |
| 429 | ** We return -1000000 instead of the more usual -1 simply because using |
| 430 | ** -1000000 as incorrectly using -1000000 index into db->aDb[] is much |
| 431 | ** more likely to cause a segfault than -1 (of course there are assert() |
| 432 | ** statements too, but it never hurts to play the odds). |
| 433 | */ |
| 434 | if( pSchema ){ |
| 435 | for(i=0; i<db->nDb; i++){ |
| 436 | if( db->aDb[i].pSchema==pSchema ){ |
| 437 | break; |
| 438 | } |
| 439 | } |
| 440 | assert( i>=0 &&i>=0 && i<db->nDb ); |
| 441 | } |
| 442 | return i; |
| 443 | } |
| 444 | |
| 445 | /* |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 446 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 447 | */ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 448 | int sqlite3Prepare( |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 449 | sqlite3 *db, /* Database handle. */ |
| 450 | const char *zSql, /* UTF-8 encoded SQL statement. */ |
| 451 | int nBytes, /* Length of zSql in bytes. */ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 452 | int saveSqlFlag, /* True to copy SQL text into the sqlite3_stmt */ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 453 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 454 | const char **pzTail /* OUT: End of parsed string */ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 455 | ){ |
| 456 | Parse sParse; |
| 457 | char *zErrMsg = 0; |
| 458 | int rc = SQLITE_OK; |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 459 | int i; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 460 | |
danielk1977 | efaaf57 | 2006-01-16 11:29:19 +0000 | [diff] [blame] | 461 | /* Assert that malloc() has not failed */ |
danielk1977 | 9e12800 | 2006-01-18 16:51:35 +0000 | [diff] [blame] | 462 | assert( !sqlite3MallocFailed() ); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 463 | |
| 464 | assert( ppStmt ); |
| 465 | *ppStmt = 0; |
| 466 | if( sqlite3SafetyOn(db) ){ |
| 467 | return SQLITE_MISUSE; |
| 468 | } |
| 469 | |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 470 | /* If any attached database schemas are locked, do not proceed with |
| 471 | ** compilation. Instead return SQLITE_LOCKED immediately. |
| 472 | */ |
| 473 | for(i=0; i<db->nDb; i++) { |
| 474 | Btree *pBt = db->aDb[i].pBt; |
| 475 | if( pBt && sqlite3BtreeSchemaLocked(pBt) ){ |
| 476 | const char *zDb = db->aDb[i].zName; |
| 477 | sqlite3Error(db, SQLITE_LOCKED, "database schema is locked: %s", zDb); |
| 478 | sqlite3SafetyOff(db); |
| 479 | return SQLITE_LOCKED; |
| 480 | } |
| 481 | } |
| 482 | |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 483 | memset(&sParse, 0, sizeof(sParse)); |
| 484 | sParse.db = db; |
drh | 9051a42 | 2006-01-30 22:35:43 +0000 | [diff] [blame] | 485 | if( nBytes>=0 && zSql[nBytes]!=0 ){ |
| 486 | char *zSqlCopy = sqlite3StrNDup(zSql, nBytes); |
| 487 | sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg); |
| 488 | sParse.zTail += zSql - zSqlCopy; |
| 489 | sqliteFree(zSqlCopy); |
| 490 | }else{ |
| 491 | sqlite3RunParser(&sParse, zSql, &zErrMsg); |
| 492 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 493 | |
danielk1977 | 9e12800 | 2006-01-18 16:51:35 +0000 | [diff] [blame] | 494 | if( sqlite3MallocFailed() ){ |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 495 | sParse.rc = SQLITE_NOMEM; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 496 | } |
| 497 | if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK; |
drh | 4d91a70 | 2006-01-04 15:54:36 +0000 | [diff] [blame] | 498 | if( sParse.checkSchema && !schemaIsValid(db) ){ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 499 | sParse.rc = SQLITE_SCHEMA; |
| 500 | } |
| 501 | if( sParse.rc==SQLITE_SCHEMA ){ |
| 502 | sqlite3ResetInternalSchema(db, 0); |
| 503 | } |
drh | 344a627 | 2006-06-26 12:50:09 +0000 | [diff] [blame] | 504 | if( sqlite3MallocFailed() ){ |
| 505 | sParse.rc = SQLITE_NOMEM; |
| 506 | } |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 507 | if( pzTail ){ |
| 508 | *pzTail = sParse.zTail; |
| 509 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 510 | rc = sParse.rc; |
| 511 | |
| 512 | #ifndef SQLITE_OMIT_EXPLAIN |
| 513 | if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){ |
drh | ecc9242 | 2005-09-10 16:46:12 +0000 | [diff] [blame] | 514 | if( sParse.explain==2 ){ |
| 515 | sqlite3VdbeSetNumCols(sParse.pVdbe, 3); |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 516 | sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", P3_STATIC); |
| 517 | sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P3_STATIC); |
| 518 | sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P3_STATIC); |
drh | ecc9242 | 2005-09-10 16:46:12 +0000 | [diff] [blame] | 519 | }else{ |
| 520 | sqlite3VdbeSetNumCols(sParse.pVdbe, 5); |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 521 | sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P3_STATIC); |
| 522 | sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P3_STATIC); |
| 523 | sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P3_STATIC); |
| 524 | sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P3_STATIC); |
| 525 | sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P3_STATIC); |
drh | ecc9242 | 2005-09-10 16:46:12 +0000 | [diff] [blame] | 526 | } |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 527 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 528 | #endif |
| 529 | |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 530 | if( sqlite3SafetyOff(db) ){ |
| 531 | rc = SQLITE_MISUSE; |
| 532 | } |
| 533 | if( rc==SQLITE_OK ){ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 534 | if( saveSqlFlag ){ |
| 535 | sqlite3VdbeSetSql(sParse.pVdbe, zSql, sParse.zTail - zSql); |
| 536 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 537 | *ppStmt = (sqlite3_stmt*)sParse.pVdbe; |
| 538 | }else if( sParse.pVdbe ){ |
| 539 | sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe); |
| 540 | } |
| 541 | |
| 542 | if( zErrMsg ){ |
| 543 | sqlite3Error(db, rc, "%s", zErrMsg); |
| 544 | sqliteFree(zErrMsg); |
| 545 | }else{ |
| 546 | sqlite3Error(db, rc, 0); |
| 547 | } |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 548 | |
danielk1977 | 54f0198 | 2006-01-18 15:25:17 +0000 | [diff] [blame] | 549 | rc = sqlite3ApiExit(db, rc); |
drh | 4b494d6 | 2006-01-12 12:43:36 +0000 | [diff] [blame] | 550 | sqlite3ReleaseThreadData(); |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 551 | assert( (rc&db->errMask)==rc ); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 552 | return rc; |
| 553 | } |
| 554 | |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 555 | /* |
| 556 | ** Rerun the compilation of a statement after a schema change. |
| 557 | ** Return true if the statement was recompiled successfully. |
| 558 | ** Return false if there is an error of some kind. |
| 559 | */ |
| 560 | int sqlite3Reprepare(Vdbe *p){ |
| 561 | int rc; |
| 562 | Vdbe *pNew; |
| 563 | const char *zSql; |
| 564 | sqlite3 *db; |
| 565 | |
| 566 | zSql = sqlite3VdbeGetSql(p); |
| 567 | if( zSql==0 ){ |
| 568 | return 0; |
| 569 | } |
| 570 | db = sqlite3VdbeDb(p); |
| 571 | rc = sqlite3Prepare(db, zSql, -1, 0, (sqlite3_stmt**)&pNew, 0); |
| 572 | if( rc ){ |
| 573 | assert( pNew==0 ); |
| 574 | return 0; |
| 575 | }else{ |
| 576 | assert( pNew!=0 ); |
| 577 | } |
drh | c515525 | 2007-01-08 21:07:17 +0000 | [diff] [blame] | 578 | sqlite3VdbeSwap(pNew, p); |
| 579 | sqlite3_transfer_bindings((sqlite3_stmt*)pNew, (sqlite3_stmt*)p); |
drh | 3c23a88 | 2007-01-09 14:01:13 +0000 | [diff] [blame^] | 580 | sqlite3VdbeResetStepResult(pNew); |
| 581 | sqlite3VdbeFinalize(pNew); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 582 | return 1; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | /* |
| 587 | ** Two versions of the official API. Legacy and new use. In the legacy |
| 588 | ** version, the original SQL text is not saved in the prepared statement |
| 589 | ** and so if a schema change occurs, SQLITE_SCHEMA is returned by |
| 590 | ** sqlite3_step(). In the new version, the original SQL text is retained |
| 591 | ** and the statement is automatically recompiled if an schema change |
| 592 | ** occurs. |
| 593 | */ |
| 594 | int sqlite3_prepare( |
| 595 | sqlite3 *db, /* Database handle. */ |
| 596 | const char *zSql, /* UTF-8 encoded SQL statement. */ |
| 597 | int nBytes, /* Length of zSql in bytes. */ |
| 598 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 599 | const char **pzTail /* OUT: End of parsed string */ |
| 600 | ){ |
| 601 | return sqlite3Prepare(db,zSql,nBytes,0,ppStmt,pzTail); |
| 602 | } |
| 603 | int sqlite3_prepare_v2( |
| 604 | sqlite3 *db, /* Database handle. */ |
| 605 | const char *zSql, /* UTF-8 encoded SQL statement. */ |
| 606 | int nBytes, /* Length of zSql in bytes. */ |
| 607 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 608 | const char **pzTail /* OUT: End of parsed string */ |
| 609 | ){ |
| 610 | return sqlite3Prepare(db,zSql,nBytes,1,ppStmt,pzTail); |
| 611 | } |
| 612 | |
| 613 | |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 614 | #ifndef SQLITE_OMIT_UTF16 |
| 615 | /* |
| 616 | ** Compile the UTF-16 encoded SQL statement zSql into a statement handle. |
| 617 | */ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 618 | static int sqlite3Prepare16( |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 619 | sqlite3 *db, /* Database handle. */ |
| 620 | const void *zSql, /* UTF-8 encoded SQL statement. */ |
| 621 | int nBytes, /* Length of zSql in bytes. */ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 622 | int saveSqlFlag, /* True to save SQL text into the sqlite3_stmt */ |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 623 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 624 | const void **pzTail /* OUT: End of parsed string */ |
| 625 | ){ |
| 626 | /* This function currently works by first transforming the UTF-16 |
| 627 | ** encoded string to UTF-8, then invoking sqlite3_prepare(). The |
| 628 | ** tricky bit is figuring out the pointer to return in *pzTail. |
| 629 | */ |
danielk1977 | 54f0198 | 2006-01-18 15:25:17 +0000 | [diff] [blame] | 630 | char *zSql8; |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 631 | const char *zTail8 = 0; |
danielk1977 | 54f0198 | 2006-01-18 15:25:17 +0000 | [diff] [blame] | 632 | int rc = SQLITE_OK; |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 633 | |
| 634 | if( sqlite3SafetyCheck(db) ){ |
| 635 | return SQLITE_MISUSE; |
| 636 | } |
drh | af9a7c2 | 2005-12-15 03:04:10 +0000 | [diff] [blame] | 637 | zSql8 = sqlite3utf16to8(zSql, nBytes); |
danielk1977 | 54f0198 | 2006-01-18 15:25:17 +0000 | [diff] [blame] | 638 | if( zSql8 ){ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 639 | rc = sqlite3Prepare(db, zSql8, -1, saveSqlFlag, ppStmt, &zTail8); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 640 | } |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 641 | |
| 642 | if( zTail8 && pzTail ){ |
| 643 | /* If sqlite3_prepare returns a tail pointer, we calculate the |
| 644 | ** equivalent pointer into the UTF-16 string by counting the unicode |
| 645 | ** characters between zSql8 and zTail8, and then returning a pointer |
| 646 | ** the same number of characters into the UTF-16 string. |
| 647 | */ |
| 648 | int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8); |
| 649 | *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed); |
| 650 | } |
drh | af9a7c2 | 2005-12-15 03:04:10 +0000 | [diff] [blame] | 651 | sqliteFree(zSql8); |
danielk1977 | 54f0198 | 2006-01-18 15:25:17 +0000 | [diff] [blame] | 652 | return sqlite3ApiExit(db, rc); |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 653 | } |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 654 | |
| 655 | /* |
| 656 | ** Two versions of the official API. Legacy and new use. In the legacy |
| 657 | ** version, the original SQL text is not saved in the prepared statement |
| 658 | ** and so if a schema change occurs, SQLITE_SCHEMA is returned by |
| 659 | ** sqlite3_step(). In the new version, the original SQL text is retained |
| 660 | ** and the statement is automatically recompiled if an schema change |
| 661 | ** occurs. |
| 662 | */ |
| 663 | int sqlite3_prepare16( |
| 664 | sqlite3 *db, /* Database handle. */ |
| 665 | const void *zSql, /* UTF-8 encoded SQL statement. */ |
| 666 | int nBytes, /* Length of zSql in bytes. */ |
| 667 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 668 | const void **pzTail /* OUT: End of parsed string */ |
| 669 | ){ |
| 670 | return sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail); |
| 671 | } |
| 672 | int sqlite3_prepare16_v2( |
| 673 | sqlite3 *db, /* Database handle. */ |
| 674 | const void *zSql, /* UTF-8 encoded SQL statement. */ |
| 675 | int nBytes, /* Length of zSql in bytes. */ |
| 676 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 677 | const void **pzTail /* OUT: End of parsed string */ |
| 678 | ){ |
| 679 | return sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail); |
| 680 | } |
| 681 | |
danielk1977 | fa256a3 | 2005-05-25 04:11:56 +0000 | [diff] [blame] | 682 | #endif /* SQLITE_OMIT_UTF16 */ |