blob: 51231af2aed5466e492ba8f1f7b26acef864f444 [file] [log] [blame]
drh75897232000-05-29 14:26:00 +00001/*
drhb19a2bc2001-09-16 00:13:26 +00002** 2001 September 15
drh75897232000-05-29 14:26:00 +00003**
drhb19a2bc2001-09-16 00:13:26 +00004** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
drh75897232000-05-29 14:26:00 +00006**
drhb19a2bc2001-09-16 00:13:26 +00007** 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.
drh75897232000-05-29 14:26:00 +000010**
11*************************************************************************
12** Main file for the SQLite library. The routines in this file
13** implement the programmer interface to the library. Routines in
14** other files are for internal use by SQLite and should not be
15** accessed by users of the library.
16**
drh8cfbf082001-09-19 13:22:39 +000017** $Id: main.c,v 1.39 2001/09/19 13:22:40 drh Exp $
drh75897232000-05-29 14:26:00 +000018*/
19#include "sqliteInt.h"
drh8cfbf082001-09-19 13:22:39 +000020#include "os.h"
drh75897232000-05-29 14:26:00 +000021
22/*
23** This is the callback routine for the code that initializes the
drhd78eeee2001-09-13 16:18:53 +000024** database. Each callback contains the following information:
drh28037572000-08-02 13:47:41 +000025**
drhd78eeee2001-09-13 16:18:53 +000026** argv[0] = "meta" or "table" or "index"
drhe3c41372001-09-17 20:25:58 +000027** argv[1] = table or index name or meta statement type.
28** argv[2] = root page number for table or index. NULL for meta.
29** argv[3] = root page number of primary key for tables or NULL.
30** argv[4] = SQL create statement for the table or index
drhd78eeee2001-09-13 16:18:53 +000031**
drh75897232000-05-29 14:26:00 +000032*/
33static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
34 sqlite *db = (sqlite*)pDb;
35 Parse sParse;
drhd78eeee2001-09-13 16:18:53 +000036 int nErr = 0;
drh75897232000-05-29 14:26:00 +000037
drhe3c41372001-09-17 20:25:58 +000038/* TODO: Do some validity checks on all fields. In particular,
39** make sure fields do not contain NULLs. */
40
41 assert( argc==5 );
drhd78eeee2001-09-13 16:18:53 +000042 switch( argv[0][0] ){
43 case 'm': { /* Meta information */
drh50e5dad2001-09-15 00:57:28 +000044 if( strcmp(argv[1],"file-format")==0 ){
drhe3c41372001-09-17 20:25:58 +000045 db->file_format = atoi(argv[4]);
drh50e5dad2001-09-15 00:57:28 +000046 }else if( strcmp(argv[1],"schema-cookie")==0 ){
drhe3c41372001-09-17 20:25:58 +000047 db->schema_cookie = atoi(argv[4]);
drh50e5dad2001-09-15 00:57:28 +000048 db->next_cookie = db->schema_cookie;
49 }
drhd78eeee2001-09-13 16:18:53 +000050 break;
drh28037572000-08-02 13:47:41 +000051 }
drhd78eeee2001-09-13 16:18:53 +000052 case 'i':
53 case 't': { /* CREATE TABLE and CREATE INDEX statements */
54 memset(&sParse, 0, sizeof(sParse));
55 sParse.db = db;
56 sParse.initFlag = 1;
57 sParse.newTnum = atoi(argv[2]);
drhe3c41372001-09-17 20:25:58 +000058 sParse.newKnum = argv[3] ? atoi(argv[3]) : 0;
59 nErr = sqliteRunParser(&sParse, argv[4], 0);
drhd78eeee2001-09-13 16:18:53 +000060 break;
61 }
62 default: {
63 /* This can not happen! */
64 nErr = 1;
65 assert( nErr==0 );
66 }
drh28037572000-08-02 13:47:41 +000067 }
drh75897232000-05-29 14:26:00 +000068 return nErr;
69}
70
71/*
drh58b95762000-06-02 01:17:37 +000072** Attempt to read the database schema and initialize internal
73** data structures. Return one of the SQLITE_ error codes to
74** indicate success or failure.
drhbed86902000-06-02 13:27:59 +000075**
76** After the database is initialized, the SQLITE_Initialized
77** bit is set in the flags field of the sqlite structure. An
78** attempt is made to initialize the database as soon as it
79** is opened. If that fails (perhaps because another process
80** has the sqlite_master table locked) than another attempt
81** is made the first time the database is accessed.
drh75897232000-05-29 14:26:00 +000082*/
drh58b95762000-06-02 01:17:37 +000083static int sqliteInit(sqlite *db, char **pzErrMsg){
drh75897232000-05-29 14:26:00 +000084 Vdbe *vdbe;
drh58b95762000-06-02 01:17:37 +000085 int rc;
86
87 /*
88 ** The master database table has a structure like this
89 */
drh75897232000-05-29 14:26:00 +000090 static char master_schema[] =
91 "CREATE TABLE " MASTER_NAME " (\n"
92 " type text,\n"
93 " name text,\n"
94 " tbl_name text,\n"
drhe3c41372001-09-17 20:25:58 +000095 " tnum integer,\n"
96 " knum integer,\n"
drh75897232000-05-29 14:26:00 +000097 " sql text\n"
98 ")"
99 ;
100
101 /* The following program is used to initialize the internal
102 ** structure holding the tables and indexes of the database.
103 ** The database contains a special table named "sqlite_master"
104 ** defined as follows:
105 **
106 ** CREATE TABLE sqlite_master (
drh28037572000-08-02 13:47:41 +0000107 ** type text, -- Either "table" or "index" or "meta"
drh75897232000-05-29 14:26:00 +0000108 ** name text, -- Name of table or index
109 ** tbl_name text, -- Associated table
drhe3c41372001-09-17 20:25:58 +0000110 ** tnum integer, -- The integer page number of root page
111 ** knum integer, -- Root page of primary key, or NULL
drh75897232000-05-29 14:26:00 +0000112 ** sql text -- The CREATE statement for this object
113 ** );
114 **
115 ** The sqlite_master table contains a single entry for each table
drh967e8b72000-06-21 13:59:10 +0000116 ** and each index. The "type" column tells whether the entry is
117 ** a table or index. The "name" column is the name of the object.
drh75897232000-05-29 14:26:00 +0000118 ** The "tbl_name" is the name of the associated table. For tables,
drh967e8b72000-06-21 13:59:10 +0000119 ** the tbl_name column is always the same as name. For indices, the
120 ** tbl_name column contains the name of the table that the index
121 ** indexes. Finally, the "sql" column contains the complete text of
drh75897232000-05-29 14:26:00 +0000122 ** the CREATE TABLE or CREATE INDEX statement that originally created
123 ** the table or index.
124 **
drh28037572000-08-02 13:47:41 +0000125 ** If the "type" column has the value "meta", then the "sql" column
126 ** contains extra information about the database, such as the
127 ** file format version number. All meta information must be processed
128 ** before any tables or indices are constructed.
129 **
drh75897232000-05-29 14:26:00 +0000130 ** The following program invokes its callback on the SQL for each
131 ** table then goes back and invokes the callback on the
132 ** SQL for each index. The callback will invoke the
133 ** parser to build the internal representation of the
134 ** database scheme.
135 */
136 static VdbeOp initProg[] = {
drh5e00f6c2001-09-13 13:46:56 +0000137 { OP_Open, 0, 2, 0},
drhd78eeee2001-09-13 16:18:53 +0000138 { OP_Rewind, 0, 0, 0},
drhe3c41372001-09-17 20:25:58 +0000139 { OP_Next, 0, 13, 0}, /* 2 */
drh5e00f6c2001-09-13 13:46:56 +0000140 { OP_Column, 0, 0, 0},
drh28037572000-08-02 13:47:41 +0000141 { OP_String, 0, 0, "meta"},
drhd78eeee2001-09-13 16:18:53 +0000142 { OP_Ne, 0, 2, 0},
drh5e00f6c2001-09-13 13:46:56 +0000143 { OP_Column, 0, 0, 0},
drhd78eeee2001-09-13 16:18:53 +0000144 { OP_Column, 0, 1, 0},
drhe3c41372001-09-17 20:25:58 +0000145 { OP_Column, 0, 3, 0},
146 { OP_Null, 0, 0, 0},
147 { OP_Column, 0, 5, 0},
148 { OP_Callback, 5, 0, 0},
drhd78eeee2001-09-13 16:18:53 +0000149 { OP_Goto, 0, 2, 0},
drhe3c41372001-09-17 20:25:58 +0000150 { OP_Rewind, 0, 0, 0}, /* 13 */
151 { OP_Next, 0, 25, 0}, /* 14 */
drh5e00f6c2001-09-13 13:46:56 +0000152 { OP_Column, 0, 0, 0},
drh75897232000-05-29 14:26:00 +0000153 { OP_String, 0, 0, "table"},
drhe3c41372001-09-17 20:25:58 +0000154 { OP_Ne, 0, 14, 0},
drhd78eeee2001-09-13 16:18:53 +0000155 { OP_Column, 0, 0, 0},
156 { OP_Column, 0, 1, 0},
drhe3c41372001-09-17 20:25:58 +0000157 { OP_Column, 0, 3, 0},
drh5e00f6c2001-09-13 13:46:56 +0000158 { OP_Column, 0, 4, 0},
drhe3c41372001-09-17 20:25:58 +0000159 { OP_Column, 0, 5, 0},
160 { OP_Callback, 5, 0, 0},
161 { OP_Goto, 0, 14, 0},
162 { OP_Rewind, 0, 0, 0}, /* 25 */
163 { OP_Next, 0, 37, 0}, /* 26 */
drh5e00f6c2001-09-13 13:46:56 +0000164 { OP_Column, 0, 0, 0},
drh75897232000-05-29 14:26:00 +0000165 { OP_String, 0, 0, "index"},
drhe3c41372001-09-17 20:25:58 +0000166 { OP_Ne, 0, 26, 0},
drhd78eeee2001-09-13 16:18:53 +0000167 { OP_Column, 0, 0, 0},
168 { OP_Column, 0, 1, 0},
drhe3c41372001-09-17 20:25:58 +0000169 { OP_Column, 0, 3, 0},
170 { OP_Null, 0, 0, 0},
171 { OP_Column, 0, 5, 0},
172 { OP_Callback, 5, 0, 0},
173 { OP_Goto, 0, 26, 0},
174 { OP_String, 0, 0, "meta"}, /* 37 */
drh50e5dad2001-09-15 00:57:28 +0000175 { OP_String, 0, 0, "schema-cookie"},
drhe3c41372001-09-17 20:25:58 +0000176 { OP_Null, 0, 0, 0},
177 { OP_Null, 0, 0, 0},
drh50e5dad2001-09-15 00:57:28 +0000178 { OP_ReadCookie,0,0, 0},
drhe3c41372001-09-17 20:25:58 +0000179 { OP_Callback, 5, 0, 0},
drh50e5dad2001-09-15 00:57:28 +0000180 { OP_Close, 0, 0, 0},
drh5e00f6c2001-09-13 13:46:56 +0000181 { OP_Halt, 0, 0, 0},
drh75897232000-05-29 14:26:00 +0000182 };
183
drh58b95762000-06-02 01:17:37 +0000184 /* Create a virtual machine to run the initialization program. Run
185 ** the program. The delete the virtual machine.
186 */
drh4c504392000-10-16 22:06:40 +0000187 vdbe = sqliteVdbeCreate(db);
drhd8bc7082000-06-07 23:51:50 +0000188 if( vdbe==0 ){
drhdaffd0e2001-04-11 14:28:42 +0000189 sqliteSetString(pzErrMsg, "out of memory");
190 return SQLITE_NOMEM;
drhd8bc7082000-06-07 23:51:50 +0000191 }
drh58b95762000-06-02 01:17:37 +0000192 sqliteVdbeAddOpList(vdbe, sizeof(initProg)/sizeof(initProg[0]), initProg);
drh2dfbbca2000-07-28 14:32:48 +0000193 rc = sqliteVdbeExec(vdbe, sqliteOpenCb, db, pzErrMsg,
194 db->pBusyArg, db->xBusyCallback);
drh58b95762000-06-02 01:17:37 +0000195 sqliteVdbeDelete(vdbe);
drhd78eeee2001-09-13 16:18:53 +0000196 if( rc==SQLITE_OK && db->file_format>1 && db->nTable>0 ){
197 sqliteSetString(pzErrMsg, "unsupported file format", 0);
drh28037572000-08-02 13:47:41 +0000198 rc = SQLITE_ERROR;
199 }
drh58b95762000-06-02 01:17:37 +0000200 if( rc==SQLITE_OK ){
201 Table *pTab;
drhe3c41372001-09-17 20:25:58 +0000202 char *azArg[6];
drhd78eeee2001-09-13 16:18:53 +0000203 azArg[0] = "table";
204 azArg[1] = MASTER_NAME;
205 azArg[2] = "2";
drhe3c41372001-09-17 20:25:58 +0000206 azArg[3] = 0;
207 azArg[4] = master_schema;
208 azArg[5] = 0;
209 sqliteOpenCb(db, 5, azArg, 0);
drh58b95762000-06-02 01:17:37 +0000210 pTab = sqliteFindTable(db, MASTER_NAME);
211 if( pTab ){
212 pTab->readOnly = 1;
213 }
214 db->flags |= SQLITE_Initialized;
drh5e00f6c2001-09-13 13:46:56 +0000215 sqliteCommitInternalChanges(db);
drh58b95762000-06-02 01:17:37 +0000216 }
217 return rc;
218}
219
220/*
drhb217a572000-08-22 13:40:18 +0000221** The version of the library
222*/
drh3d0b5592000-08-22 13:40:51 +0000223const char sqlite_version[] = SQLITE_VERSION;
drhb217a572000-08-22 13:40:18 +0000224
225/*
drh297ecf12001-04-05 15:57:13 +0000226** Does the library expect data to be encoded as UTF-8 or iso8859? The
227** following global constant always lets us know.
228*/
229#ifdef SQLITE_UTF8
drhfbc3eab2001-04-06 16:13:42 +0000230const char sqlite_encoding[] = "UTF-8";
drh297ecf12001-04-05 15:57:13 +0000231#else
drhfbc3eab2001-04-06 16:13:42 +0000232const char sqlite_encoding[] = "iso8859";
drh297ecf12001-04-05 15:57:13 +0000233#endif
234
235/*
drh58b95762000-06-02 01:17:37 +0000236** Open a new SQLite database. Construct an "sqlite" structure to define
237** the state of this database and return a pointer to that structure.
238**
239** An attempt is made to initialize the in-memory data structures that
240** hold the database schema. But if this fails (because the schema file
241** is locked) then that step is deferred until the first call to
242** sqlite_exec().
243*/
244sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
245 sqlite *db;
246 int rc;
247
248 /* Allocate the sqlite data structure */
drh75897232000-05-29 14:26:00 +0000249 db = sqliteMalloc( sizeof(sqlite) );
250 if( pzErrMsg ) *pzErrMsg = 0;
drhdaffd0e2001-04-11 14:28:42 +0000251 if( db==0 ) goto no_mem_on_open;
drh75897232000-05-29 14:26:00 +0000252
253 /* Open the backend database driver */
drha1b351a2001-09-14 16:42:12 +0000254 rc = sqliteBtreeOpen(zFilename, mode, MAX_PAGES, &db->pBe);
drh5e00f6c2001-09-13 13:46:56 +0000255 if( rc!=SQLITE_OK ){
256 switch( rc ){
257 default: {
258 if( pzErrMsg ){
259 sqliteSetString(pzErrMsg, "unable to open database: ", zFilename, 0);
260 }
261 }
262 }
drh75897232000-05-29 14:26:00 +0000263 sqliteFree(db);
drh5edc3122001-09-13 21:53:09 +0000264 sqliteStrRealloc(pzErrMsg);
drhbe0072d2001-09-13 14:46:09 +0000265 return 0;
drh75897232000-05-29 14:26:00 +0000266 }
267
drh28037572000-08-02 13:47:41 +0000268 /* Assume file format 1 unless the database says otherwise */
269 db->file_format = 1;
270
drh58b95762000-06-02 01:17:37 +0000271 /* Attempt to read the schema */
272 rc = sqliteInit(db, pzErrMsg);
drhdaffd0e2001-04-11 14:28:42 +0000273 if( sqlite_malloc_failed ){
274 goto no_mem_on_open;
275 }else if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
drh58b95762000-06-02 01:17:37 +0000276 sqlite_close(db);
drh5edc3122001-09-13 21:53:09 +0000277 sqliteStrRealloc(pzErrMsg);
drh58b95762000-06-02 01:17:37 +0000278 return 0;
drh4c504392000-10-16 22:06:40 +0000279 }else /* if( pzErrMsg ) */{
drhdaffd0e2001-04-11 14:28:42 +0000280 sqliteFree(*pzErrMsg);
drhbed86902000-06-02 13:27:59 +0000281 *pzErrMsg = 0;
drh75897232000-05-29 14:26:00 +0000282 }
drh75897232000-05-29 14:26:00 +0000283 return db;
drhdaffd0e2001-04-11 14:28:42 +0000284
285no_mem_on_open:
286 sqliteSetString(pzErrMsg, "out of memory", 0);
287 sqliteStrRealloc(pzErrMsg);
288 return 0;
drh75897232000-05-29 14:26:00 +0000289}
290
291/*
drh50e5dad2001-09-15 00:57:28 +0000292** Erase all schema information from the schema hash table.
293**
294** The database schema is normally read in once when the database
295** is first opened and stored in a hash table in the sqlite structure.
296** This routine erases the stored schema. This erasure occurs because
297** either the database is being closed or because some other process
298** changed the schema and this process needs to reread it.
drh75897232000-05-29 14:26:00 +0000299*/
drh50e5dad2001-09-15 00:57:28 +0000300static void clearHashTable(sqlite *db){
drh75897232000-05-29 14:26:00 +0000301 int i;
drh75897232000-05-29 14:26:00 +0000302 for(i=0; i<N_HASH; i++){
303 Table *pNext, *pList = db->apTblHash[i];
304 db->apTblHash[i] = 0;
305 while( pList ){
306 pNext = pList->pHash;
307 pList->pHash = 0;
308 sqliteDeleteTable(db, pList);
309 pList = pNext;
310 }
311 }
drh50e5dad2001-09-15 00:57:28 +0000312 db->flags &= ~SQLITE_Initialized;
313}
314
315/*
316** Close an existing SQLite database
317*/
318void sqlite_close(sqlite *db){
319 sqliteBtreeClose(db->pBe);
320 clearHashTable(db);
drh75897232000-05-29 14:26:00 +0000321 sqliteFree(db);
322}
323
324/*
325** Return TRUE if the given SQL string ends in a semicolon.
326*/
327int sqlite_complete(const char *zSql){
drh8c82b352000-12-10 18:23:50 +0000328 int isComplete = 0;
329 while( *zSql ){
330 switch( *zSql ){
331 case ';': {
332 isComplete = 1;
drh75897232000-05-29 14:26:00 +0000333 break;
drh8c82b352000-12-10 18:23:50 +0000334 }
335 case ' ':
336 case '\t':
337 case '\n':
338 case '\f': {
drh75897232000-05-29 14:26:00 +0000339 break;
drh8c82b352000-12-10 18:23:50 +0000340 }
341 case '\'': {
342 isComplete = 0;
343 zSql++;
344 while( *zSql && *zSql!='\'' ){ zSql++; }
345 if( *zSql==0 ) return 0;
drh75897232000-05-29 14:26:00 +0000346 break;
drh8c82b352000-12-10 18:23:50 +0000347 }
348 case '"': {
349 isComplete = 0;
350 zSql++;
351 while( *zSql && *zSql!='"' ){ zSql++; }
352 if( *zSql==0 ) return 0;
353 break;
354 }
355 case '-': {
356 if( zSql[1]!='-' ){
357 isComplete = 0;
358 break;
359 }
360 while( *zSql && *zSql!='\n' ){ zSql++; }
361 if( *zSql==0 ) return isComplete;
362 break;
363 }
364 default: {
365 isComplete = 0;
366 break;
367 }
drh75897232000-05-29 14:26:00 +0000368 }
drh8c82b352000-12-10 18:23:50 +0000369 zSql++;
drh75897232000-05-29 14:26:00 +0000370 }
drh8c82b352000-12-10 18:23:50 +0000371 return isComplete;
drh75897232000-05-29 14:26:00 +0000372}
373
374/*
drhbed86902000-06-02 13:27:59 +0000375** Execute SQL code. Return one of the SQLITE_ success/failure
376** codes. Also write an error message into memory obtained from
377** malloc() and make *pzErrMsg point to that message.
378**
379** If the SQL is a query, then for each row in the query result
380** the xCallback() function is called. pArg becomes the first
381** argument to xCallback(). If xCallback=NULL then no callback
382** is invoked, even for queries.
drh75897232000-05-29 14:26:00 +0000383*/
384int sqlite_exec(
385 sqlite *db, /* The database on which the SQL executes */
386 char *zSql, /* The SQL to be executed */
387 sqlite_callback xCallback, /* Invoke this callback routine */
388 void *pArg, /* First argument to xCallback() */
389 char **pzErrMsg /* Write error messages here */
390){
391 Parse sParse;
drh75897232000-05-29 14:26:00 +0000392
393 if( pzErrMsg ) *pzErrMsg = 0;
drh58b95762000-06-02 01:17:37 +0000394 if( (db->flags & SQLITE_Initialized)==0 ){
395 int rc = sqliteInit(db, pzErrMsg);
drhdaffd0e2001-04-11 14:28:42 +0000396 if( rc!=SQLITE_OK ){
397 sqliteStrRealloc(pzErrMsg);
398 return rc;
399 }
drh58b95762000-06-02 01:17:37 +0000400 }
drh75897232000-05-29 14:26:00 +0000401 memset(&sParse, 0, sizeof(sParse));
402 sParse.db = db;
drh5e00f6c2001-09-13 13:46:56 +0000403 sParse.pBe = db->pBe;
drh75897232000-05-29 14:26:00 +0000404 sParse.xCallback = xCallback;
405 sParse.pArg = pArg;
drh4c504392000-10-16 22:06:40 +0000406 sqliteRunParser(&sParse, zSql, pzErrMsg);
drhdaffd0e2001-04-11 14:28:42 +0000407 if( sqlite_malloc_failed ){
408 sqliteSetString(pzErrMsg, "out of memory", 0);
409 sParse.rc = SQLITE_NOMEM;
410 }
411 sqliteStrRealloc(pzErrMsg);
drh50e5dad2001-09-15 00:57:28 +0000412 if( sParse.rc==SQLITE_SCHEMA ){
413 clearHashTable(db);
414 }
drh4c504392000-10-16 22:06:40 +0000415 return sParse.rc;
drh75897232000-05-29 14:26:00 +0000416}
drh2dfbbca2000-07-28 14:32:48 +0000417
418/*
419** This routine implements a busy callback that sleeps and tries
420** again until a timeout value is reached. The timeout value is
421** an integer number of milliseconds passed in as the first
422** argument.
423*/
drhdaffd0e2001-04-11 14:28:42 +0000424static int sqliteDefaultBusyCallback(
drh2dfbbca2000-07-28 14:32:48 +0000425 void *Timeout, /* Maximum amount of time to wait */
426 const char *NotUsed, /* The name of the table that is busy */
427 int count /* Number of times table has been busy */
428){
drh8cfbf082001-09-19 13:22:39 +0000429#if SQLITE_MIN_SLEEP_MS==1
430 int delay = 10;
drh2dfbbca2000-07-28 14:32:48 +0000431 int prior_delay = 0;
432 int timeout = (int)Timeout;
433 int i;
434
435 for(i=1; i<count; i++){
436 prior_delay += delay;
437 delay = delay*2;
drh8cfbf082001-09-19 13:22:39 +0000438 if( delay>=1000 ){
439 delay = 1000;
440 prior_delay += 1000*(count - i - 1);
drh2dfbbca2000-07-28 14:32:48 +0000441 break;
442 }
443 }
444 if( prior_delay + delay > timeout*1000 ){
445 delay = timeout*1000 - prior_delay;
446 if( delay<=0 ) return 0;
447 }
drh8cfbf082001-09-19 13:22:39 +0000448 sqliteOsSleep(delay);
drh2dfbbca2000-07-28 14:32:48 +0000449 return 1;
450#else
451 int timeout = (int)Timeout;
452 if( (count+1)*1000 > timeout ){
453 return 0;
454 }
drh8cfbf082001-09-19 13:22:39 +0000455 sqliteOsSleep(1000);
drh2dfbbca2000-07-28 14:32:48 +0000456 return 1;
457#endif
458}
459
460/*
461** This routine sets the busy callback for an Sqlite database to the
462** given callback function with the given argument.
463*/
464void sqlite_busy_handler(
465 sqlite *db,
466 int (*xBusy)(void*,const char*,int),
467 void *pArg
468){
469 db->xBusyCallback = xBusy;
470 db->pBusyArg = pArg;
471}
472
473/*
474** This routine installs a default busy handler that waits for the
475** specified number of milliseconds before returning 0.
476*/
477void sqlite_busy_timeout(sqlite *db, int ms){
478 if( ms>0 ){
drhdaffd0e2001-04-11 14:28:42 +0000479 sqlite_busy_handler(db, sqliteDefaultBusyCallback, (void*)ms);
drh2dfbbca2000-07-28 14:32:48 +0000480 }else{
481 sqlite_busy_handler(db, 0, 0);
482 }
483}
drh4c504392000-10-16 22:06:40 +0000484
485/*
486** Cause any pending operation to stop at its earliest opportunity.
487*/
488void sqlite_interrupt(sqlite *db){
489 db->flags |= SQLITE_Interrupt;
490}