kexi
sqlite.h
00001 /* 00002 ** 2001 September 15 00003 ** 00004 ** The author disclaims copyright to this source code. In place of 00005 ** a legal notice, here is a blessing: 00006 ** 00007 ** May you do good and not evil. 00008 ** May you find forgiveness for yourself and forgive others. 00009 ** May you share freely, never taking more than you give. 00010 ** 00011 ************************************************************************* 00012 ** This header file defines the interface that the SQLite library 00013 ** presents to client programs. 00014 ** 00015 ** @(#) $Id: sqlite.h 410099 2005-05-06 17:52:07Z staniek $ 00016 */ 00017 #ifndef _SQLITE_H_ 00018 #define _SQLITE_H_ 00019 #include <stdarg.h> /* Needed for the definition of va_list */ 00020 00021 /* 00022 ** Make sure we can call this stuff from C++. 00023 */ 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* 00029 ** The version of the SQLite library. 00030 */ 00031 #define SQLITE_VERSION "2.8.2" 00032 00033 /* 00034 ** The version string is also compiled into the library so that a program 00035 ** can check to make sure that the lib*.a file and the *.h file are from 00036 ** the same version. 00037 */ 00038 extern const char sqlite_version[]; 00039 00040 /* 00041 ** The SQLITE_UTF8 macro is defined if the library expects to see 00042 ** UTF-8 encoded data. The SQLITE_ISO8859 macro is defined if the 00043 ** iso8859 encoded should be used. 00044 */ 00045 #define SQLITE_ISO8859 1 00046 00047 /* 00048 ** The following constant holds one of two strings, "UTF-8" or "iso8859", 00049 ** depending on which character encoding the SQLite library expects to 00050 ** see. The character encoding makes a difference for the LIKE and GLOB 00051 ** operators and for the LENGTH() and SUBSTR() functions. 00052 */ 00053 extern const char sqlite_encoding[]; 00054 00055 /* 00056 ** Each open sqlite database is represented by an instance of the 00057 ** following opaque structure. 00058 */ 00059 typedef struct sqlite sqlite; 00060 00061 /* 00062 ** A function to open a new sqlite database. 00063 ** 00064 ** If the database does not exist and mode indicates write 00065 ** permission, then a new database is created. If the database 00066 ** does not exist and mode does not indicate write permission, 00067 ** then the open fails, an error message generated (if errmsg!=0) 00068 ** and the function returns 0. 00069 ** 00070 ** If mode does not indicates user write permission, then the 00071 ** database is opened read-only. 00072 ** 00073 ** The Truth: As currently implemented, all databases are opened 00074 ** for writing all the time. Maybe someday we will provide the 00075 ** ability to open a database readonly. The mode parameters is 00076 ** provided in anticipation of that enhancement. 00077 */ 00078 sqlite *sqlite_open(const char *filename, int mode, char **errmsg); 00079 00080 /* 00081 ** A function to close the database. 00082 ** 00083 ** Call this function with a pointer to a structure that was previously 00084 ** returned from sqlite_open() and the corresponding database will by closed. 00085 */ 00086 void sqlite_close(sqlite *); 00087 00088 /* 00089 ** The type for a callback function. 00090 */ 00091 typedef int (*sqlite_callback)(void*,int,char**, char**); 00092 00093 /* 00094 ** A function to executes one or more statements of SQL. 00095 ** 00096 ** If one or more of the SQL statements are queries, then 00097 ** the callback function specified by the 3rd parameter is 00098 ** invoked once for each row of the query result. This callback 00099 ** should normally return 0. If the callback returns a non-zero 00100 ** value then the query is aborted, all subsequent SQL statements 00101 ** are skipped and the sqlite_exec() function returns the SQLITE_ABORT. 00102 ** 00103 ** The 4th parameter is an arbitrary pointer that is passed 00104 ** to the callback function as its first parameter. 00105 ** 00106 ** The 2nd parameter to the callback function is the number of 00107 ** columns in the query result. The 3rd parameter to the callback 00108 ** is an array of strings holding the values for each column. 00109 ** The 4th parameter to the callback is an array of strings holding 00110 ** the names of each column. 00111 ** 00112 ** The callback function may be NULL, even for queries. A NULL 00113 ** callback is not an error. It just means that no callback 00114 ** will be invoked. 00115 ** 00116 ** If an error occurs while parsing or evaluating the SQL (but 00117 ** not while executing the callback) then an appropriate error 00118 ** message is written into memory obtained from malloc() and 00119 ** *errmsg is made to point to that message. The calling function 00120 ** is responsible for freeing the memory that holds the error 00121 ** message. Use sqlite_freemem() for this. If errmsg==NULL, 00122 ** then no error message is ever written. 00123 ** 00124 ** The return value is is SQLITE_OK if there are no errors and 00125 ** some other return code if there is an error. The particular 00126 ** return value depends on the type of error. 00127 ** 00128 ** If the query could not be executed because a database file is 00129 ** locked or busy, then this function returns SQLITE_BUSY. (This 00130 ** behavior can be modified somewhat using the sqlite_busy_handler() 00131 ** and sqlite_busy_timeout() functions below.) 00132 */ 00133 int sqlite_exec( 00134 sqlite*, /* An open database */ 00135 const char *sql, /* SQL to be executed */ 00136 sqlite_callback, /* Callback function */ 00137 void *, /* 1st argument to callback function */ 00138 char **errmsg /* Error msg written here */ 00139 ); 00140 00141 /* 00142 ** Return values for sqlite_exec() and sqlite_step() 00143 */ 00144 #define SQLITE_OK 0 /* Successful result */ 00145 #define SQLITE_ERROR 1 /* SQL error or missing database */ 00146 #define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */ 00147 #define SQLITE_PERM 3 /* Access permission denied */ 00148 #define SQLITE_ABORT 4 /* Callback routine requested an abort */ 00149 #define SQLITE_BUSY 5 /* The database file is locked */ 00150 #define SQLITE_LOCKED 6 /* A table in the database is locked */ 00151 #define SQLITE_NOMEM 7 /* A malloc() failed */ 00152 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 00153 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite_interrupt() */ 00154 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 00155 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 00156 #define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */ 00157 #define SQLITE_FULL 13 /* Insertion failed because database is full */ 00158 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 00159 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 00160 #define SQLITE_EMPTY 16 /* (Internal Only) Database table is empty */ 00161 #define SQLITE_SCHEMA 17 /* The database schema changed */ 00162 #define SQLITE_TOOBIG 18 /* Too much data for one row of a table */ 00163 #define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */ 00164 #define SQLITE_MISMATCH 20 /* Data type mismatch */ 00165 #define SQLITE_MISUSE 21 /* Library used incorrectly */ 00166 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 00167 #define SQLITE_AUTH 23 /* Authorization denied */ 00168 #define SQLITE_FORMAT 24 /* Auxiliary database format error */ 00169 #define SQLITE_ROW 100 /* sqlite_step() has another row ready */ 00170 #define SQLITE_DONE 101 /* sqlite_step() has finished executing */ 00171 00172 /* 00173 ** Each entry in an SQLite table has a unique integer key. (The key is 00174 ** the value of the INTEGER PRIMARY KEY column if there is such a column, 00175 ** otherwise the key is generated at random. The unique key is always 00176 ** available as the ROWID, OID, or _ROWID_ column.) The following routine 00177 ** returns the integer key of the most recent insert in the database. 00178 ** 00179 ** This function is similar to the mysql_insert_id() function from MySQL. 00180 */ 00181 int sqlite_last_insert_rowid(sqlite*); 00182 00183 /* 00184 ** This function returns the number of database rows that were changed 00185 ** (or inserted or deleted) by the most recent called sqlite_exec(). 00186 ** 00187 ** All changes are counted, even if they were later undone by a 00188 ** ROLLBACK or ABORT. Except, changes associated with creating and 00189 ** dropping tables are not counted. 00190 ** 00191 ** If a callback invokes sqlite_exec() recursively, then the changes 00192 ** in the inner, recursive call are counted together with the changes 00193 ** in the outer call. 00194 ** 00195 ** SQLite implements the command "DELETE FROM table" without a WHERE clause 00196 ** by dropping and recreating the table. (This is much faster than going 00197 ** through and deleting individual elements form the table.) Because of 00198 ** this optimization, the change count for "DELETE FROM table" will be 00199 ** zero regardless of the number of elements that were originally in the 00200 ** table. To get an accurate count of the number of rows deleted, use 00201 ** "DELETE FROM table WHERE 1" instead. 00202 */ 00203 int sqlite_changes(sqlite*); 00204 00205 /* If the parameter to this routine is one of the return value constants 00206 ** defined above, then this routine returns a constant text string which 00207 ** descripts (in English) the meaning of the return value. 00208 */ 00209 const char *sqlite_error_string(int); 00210 #define sqliteErrStr sqlite_error_string /* Legacy. Do not use in new code. */ 00211 00212 /* This function causes any pending database operation to abort and 00213 ** return at its earliest opportunity. This routine is typically 00214 ** called in response to a user action such as pressing "Cancel" 00215 ** or Ctrl-C where the user wants a long query operation to halt 00216 ** immediately. 00217 */ 00218 void sqlite_interrupt(sqlite*); 00219 00220 00221 /* This function returns true if the given input string comprises 00222 ** one or more complete SQL statements. 00223 ** 00224 ** The algorithm is simple. If the last token other than spaces 00225 ** and comments is a semicolon, then return true. otherwise return 00226 ** false. 00227 */ 00228 int sqlite_complete(const char *sql); 00229 00230 /* 00231 ** This routine identifies a callback function that is invoked 00232 ** whenever an attempt is made to open a database table that is 00233 ** currently locked by another process or thread. If the busy callback 00234 ** is NULL, then sqlite_exec() returns SQLITE_BUSY immediately if 00235 ** it finds a locked table. If the busy callback is not NULL, then 00236 ** sqlite_exec() invokes the callback with three arguments. The 00237 ** second argument is the name of the locked table and the third 00238 ** argument is the number of times the table has been busy. If the 00239 ** busy callback returns 0, then sqlite_exec() immediately returns 00240 ** SQLITE_BUSY. If the callback returns non-zero, then sqlite_exec() 00241 ** tries to open the table again and the cycle repeats. 00242 ** 00243 ** The default busy callback is NULL. 00244 ** 00245 ** Sqlite is re-entrant, so the busy handler may start a new query. 00246 ** (It is not clear why anyone would every want to do this, but it 00247 ** is allowed, in theory.) But the busy handler may not close the 00248 ** database. Closing the database from a busy handler will delete 00249 ** data structures out from under the executing query and will 00250 ** probably result in a coredump. 00251 */ 00252 void sqlite_busy_handler(sqlite*, int(*)(void*,const char*,int), void*); 00253 00254 /* 00255 ** This routine sets a busy handler that sleeps for a while when a 00256 ** table is locked. The handler will sleep multiple times until 00257 ** at least "ms" milleseconds of sleeping have been done. After 00258 ** "ms" milleseconds of sleeping, the handler returns 0 which 00259 ** causes sqlite_exec() to return SQLITE_BUSY. 00260 ** 00261 ** Calling this routine with an argument less than or equal to zero 00262 ** turns off all busy handlers. 00263 */ 00264 void sqlite_busy_timeout(sqlite*, int ms); 00265 00266 /* 00267 ** This next routine is really just a wrapper around sqlite_exec(). 00268 ** Instead of invoking a user-supplied callback for each row of the 00269 ** result, this routine remembers each row of the result in memory 00270 ** obtained from malloc(), then returns all of the result after the 00271 ** query has finished. 00272 ** 00273 ** As an example, suppose the query result where this table: 00274 ** 00275 ** Name | Age 00276 ** ----------------------- 00277 ** Alice | 43 00278 ** Bob | 28 00279 ** Cindy | 21 00280 ** 00281 ** If the 3rd argument were &azResult then after the function returns 00282 ** azResult will contain the following data: 00283 ** 00284 ** azResult[0] = "Name"; 00285 ** azResult[1] = "Age"; 00286 ** azResult[2] = "Alice"; 00287 ** azResult[3] = "43"; 00288 ** azResult[4] = "Bob"; 00289 ** azResult[5] = "28"; 00290 ** azResult[6] = "Cindy"; 00291 ** azResult[7] = "21"; 00292 ** 00293 ** Notice that there is an extra row of data containing the column 00294 ** headers. But the *nrow return value is still 3. *ncolumn is 00295 ** set to 2. In general, the number of values inserted into azResult 00296 ** will be ((*nrow) + 1)*(*ncolumn). 00297 ** 00298 ** After the calling function has finished using the result, it should 00299 ** pass the result data pointer to sqlite_free_table() in order to 00300 ** release the memory that was malloc-ed. Because of the way the 00301 ** malloc() happens, the calling function must not try to call 00302 ** malloc() directly. Only sqlite_free_table() is able to release 00303 ** the memory properly and safely. 00304 ** 00305 ** The return value of this routine is the same as from sqlite_exec(). 00306 */ 00307 int sqlite_get_table( 00308 sqlite*, /* An open database */ 00309 const char *sql, /* SQL to be executed */ 00310 char ***resultp, /* Result written to a char *[] that this points to */ 00311 int *nrow, /* Number of result rows written here */ 00312 int *ncolumn, /* Number of result columns written here */ 00313 char **errmsg /* Error msg written here */ 00314 ); 00315 00316 /* 00317 ** Call this routine to free the memory that sqlite_get_table() allocated. 00318 */ 00319 void sqlite_free_table(char **result); 00320 00321 /* 00322 ** The following routines are wrappers around sqlite_exec() and 00323 ** sqlite_get_table(). The only difference between the routines that 00324 ** follow and the originals is that the second argument to the 00325 ** routines that follow is really a printf()-style format 00326 ** string describing the SQL to be executed. Arguments to the format 00327 ** string appear at the end of the argument list. 00328 ** 00329 ** All of the usual printf formatting options apply. In addition, there 00330 ** is a "%q" option. %q works like %s in that it substitutes a null-terminated 00331 ** string from the argument list. But %q also doubles every '\'' character. 00332 ** %q is designed for use inside a string literal. By doubling each '\'' 00333 ** character it escapes that character and allows it to be inserted into 00334 ** the string. 00335 ** 00336 ** For example, so some string variable contains text as follows: 00337 ** 00338 ** char *zText = "It's a happy day!"; 00339 ** 00340 ** We can use this text in an SQL statement as follows: 00341 ** 00342 ** sqlite_exec_printf(db, "INSERT INTO table VALUES('%q')", 00343 ** callback1, 0, 0, zText); 00344 ** 00345 ** Because the %q format string is used, the '\'' character in zText 00346 ** is escaped and the SQL generated is as follows: 00347 ** 00348 ** INSERT INTO table1 VALUES('It''s a happy day!') 00349 ** 00350 ** This is correct. Had we used %s instead of %q, the generated SQL 00351 ** would have looked like this: 00352 ** 00353 ** INSERT INTO table1 VALUES('It's a happy day!'); 00354 ** 00355 ** This second example is an SQL syntax error. As a general rule you 00356 ** should always use %q instead of %s when inserting text into a string 00357 ** literal. 00358 */ 00359 int sqlite_exec_printf( 00360 sqlite*, /* An open database */ 00361 const char *sqlFormat, /* printf-style format string for the SQL */ 00362 sqlite_callback, /* Callback function */ 00363 void *, /* 1st argument to callback function */ 00364 char **errmsg, /* Error msg written here */ 00365 ... /* Arguments to the format string. */ 00366 ); 00367 int sqlite_exec_vprintf( 00368 sqlite*, /* An open database */ 00369 const char *sqlFormat, /* printf-style format string for the SQL */ 00370 sqlite_callback, /* Callback function */ 00371 void *, /* 1st argument to callback function */ 00372 char **errmsg, /* Error msg written here */ 00373 va_list ap /* Arguments to the format string. */ 00374 ); 00375 int sqlite_get_table_printf( 00376 sqlite*, /* An open database */ 00377 const char *sqlFormat, /* printf-style format string for the SQL */ 00378 char ***resultp, /* Result written to a char *[] that this points to */ 00379 int *nrow, /* Number of result rows written here */ 00380 int *ncolumn, /* Number of result columns written here */ 00381 char **errmsg, /* Error msg written here */ 00382 ... /* Arguments to the format string */ 00383 ); 00384 int sqlite_get_table_vprintf( 00385 sqlite*, /* An open database */ 00386 const char *sqlFormat, /* printf-style format string for the SQL */ 00387 char ***resultp, /* Result written to a char *[] that this points to */ 00388 int *nrow, /* Number of result rows written here */ 00389 int *ncolumn, /* Number of result columns written here */ 00390 char **errmsg, /* Error msg written here */ 00391 va_list ap /* Arguments to the format string */ 00392 ); 00393 char *sqlite_mprintf(const char*,...); 00394 00395 /* 00396 ** Windows systems should call this routine to free memory that 00397 ** is returned in the in the errmsg parameter of sqlite_open() when 00398 ** SQLite is a DLL. For some reason, it does not work to call free() 00399 ** directly. 00400 */ 00401 void sqlite_freemem(void *p); 00402 00403 /* 00404 ** Windows systems need functions to call to return the sqlite_version 00405 ** and sqlite_encoding strings. 00406 */ 00407 const char *sqlite_libversion(void); 00408 const char *sqlite_libencoding(void); 00409 00410 /* 00411 ** A pointer to the following structure is used to communicate with 00412 ** the implementations of user-defined functions. 00413 */ 00414 typedef struct sqlite_func sqlite_func; 00415 00416 /* 00417 ** Use the following routines to create new user-defined functions. See 00418 ** the documentation for details. 00419 */ 00420 int sqlite_create_function( 00421 sqlite*, /* Database where the new function is registered */ 00422 const char *zName, /* Name of the new function */ 00423 int nArg, /* Number of arguments. -1 means any number */ 00424 void (*xFunc)(sqlite_func*,int,const char**), /* C code to implement */ 00425 void *pUserData /* Available via the sqlite_user_data() call */ 00426 ); 00427 int sqlite_create_aggregate( 00428 sqlite*, /* Database where the new function is registered */ 00429 const char *zName, /* Name of the function */ 00430 int nArg, /* Number of arguments */ 00431 void (*xStep)(sqlite_func*,int,const char**), /* Called for each row */ 00432 void (*xFinalize)(sqlite_func*), /* Called once to get final result */ 00433 void *pUserData /* Available via the sqlite_user_data() call */ 00434 ); 00435 00436 /* 00437 ** Use the following routine to define the datatype returned by a 00438 ** user-defined function. The second argument can be one of the 00439 ** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it 00440 ** can be an integer greater than or equal to zero. The datatype 00441 ** will be numeric or text (the only two types supported) if the 00442 ** argument is SQLITE_NUMERIC or SQLITE_TEXT. If the argument is 00443 ** SQLITE_ARGS, then the datatype is numeric if any argument to the 00444 ** function is numeric and is text otherwise. If the second argument 00445 ** is an integer, then the datatype of the result is the same as the 00446 ** parameter to the function that corresponds to that integer. 00447 */ 00448 int sqlite_function_type( 00449 sqlite *db, /* The database there the function is registered */ 00450 const char *zName, /* Name of the function */ 00451 int datatype /* The datatype for this function */ 00452 ); 00453 #define SQLITE_NUMERIC (-1) 00454 #define SQLITE_TEXT (-2) 00455 #define SQLITE_ARGS (-3) 00456 00457 /* 00458 ** The user function implementations call one of the following four routines 00459 ** in order to return their results. The first parameter to each of these 00460 ** routines is a copy of the first argument to xFunc() or xFinialize(). 00461 ** The second parameter to these routines is the result to be returned. 00462 ** A NULL can be passed as the second parameter to sqlite_set_result_string() 00463 ** in order to return a NULL result. 00464 ** 00465 ** The 3rd argument to _string and _error is the number of characters to 00466 ** take from the string. If this argument is negative, then all characters 00467 ** up to and including the first '\000' are used. 00468 ** 00469 ** The sqlite_set_result_string() function allocates a buffer to hold the 00470 ** result and returns a pointer to this buffer. The calling routine 00471 ** (that is, the implmentation of a user function) can alter the content 00472 ** of this buffer if desired. 00473 */ 00474 char *sqlite_set_result_string(sqlite_func*,const char*,int); 00475 void sqlite_set_result_int(sqlite_func*,int); 00476 void sqlite_set_result_double(sqlite_func*,double); 00477 void sqlite_set_result_error(sqlite_func*,const char*,int); 00478 00479 /* 00480 ** The pUserData parameter to the sqlite_create_function() and 00481 ** sqlite_create_aggregate() routines used to register user functions 00482 ** is available to the implementation of the function using this 00483 ** call. 00484 */ 00485 void *sqlite_user_data(sqlite_func*); 00486 00487 /* 00488 ** Aggregate functions use the following routine to allocate 00489 ** a structure for storing their state. The first time this routine 00490 ** is called for a particular aggregate, a new structure of size nBytes 00491 ** is allocated, zeroed, and returned. On subsequent calls (for the 00492 ** same aggregate instance) the same buffer is returned. The implementation 00493 ** of the aggregate can use the returned buffer to accumulate data. 00494 ** 00495 ** The buffer allocated is freed automatically be SQLite. 00496 */ 00497 void *sqlite_aggregate_context(sqlite_func*, int nBytes); 00498 00499 /* 00500 ** The next routine returns the number of calls to xStep for a particular 00501 ** aggregate function instance. The current call to xStep counts so this 00502 ** routine always returns at least 1. 00503 */ 00504 int sqlite_aggregate_count(sqlite_func*); 00505 00506 /* 00507 ** This routine registers a callback with the SQLite library. The 00508 ** callback is invoked (at compile-time, not at run-time) for each 00509 ** attempt to access a column of a table in the database. The callback 00510 ** returns SQLITE_OK if access is allowed, SQLITE_DENY if the entire 00511 ** SQL statement should be aborted with an error and SQLITE_IGNORE 00512 ** if the column should be treated as a NULL value. 00513 */ 00514 int sqlite_set_authorizer( 00515 sqlite*, 00516 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 00517 void *pUserData 00518 ); 00519 00520 /* 00521 ** The second parameter to the access authorization function above will 00522 ** be one of the values below. These values signify what kind of operation 00523 ** is to be authorized. The 3rd and 4th parameters to the authorization 00524 ** function will be parameters or NULL depending on which of the following 00525 ** codes is used as the second parameter. The 5th parameter is the name 00526 ** of the database ("main", "temp", etc.) if applicable. The 6th parameter 00527 ** is the name of the inner-most trigger or view that is responsible for 00528 ** the access attempt or NULL if this access attempt is directly from 00529 ** input SQL code. 00530 ** 00531 ** Arg-3 Arg-4 00532 */ 00533 #define SQLITE_COPY 0 /* Table Name File Name */ 00534 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 00535 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 00536 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 00537 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 00538 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 00539 #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 00540 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 00541 #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 00542 #define SQLITE_DELETE 9 /* Table Name NULL */ 00543 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 00544 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 00545 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 00546 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 00547 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 00548 #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 00549 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 00550 #define SQLITE_DROP_VIEW 17 /* View Name NULL */ 00551 #define SQLITE_INSERT 18 /* Table Name NULL */ 00552 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 00553 #define SQLITE_READ 20 /* Table Name Column Name */ 00554 #define SQLITE_SELECT 21 /* NULL NULL */ 00555 #define SQLITE_TRANSACTION 22 /* NULL NULL */ 00556 #define SQLITE_UPDATE 23 /* Table Name Column Name */ 00557 00558 /* 00559 ** The return value of the authorization function should be one of the 00560 ** following constants: 00561 */ 00562 /* #define SQLITE_OK 0 // Allow access (This is actually defined above) */ 00563 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 00564 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 00565 00566 /* 00567 ** Register a function that is called at every invocation of sqlite_exec() 00568 ** or sqlite_compile(). This function can be used (for example) to generate 00569 ** a log file of all SQL executed against a database. 00570 */ 00571 void *sqlite_trace(sqlite*, void(*xTrace)(void*,const char*), void*); 00572 00573 /*** The Callback-Free API 00574 ** 00575 ** The following routines implement a new way to access SQLite that does not 00576 ** involve the use of callbacks. 00577 ** 00578 ** An sqlite_vm is an opaque object that represents a single SQL statement 00579 ** that is ready to be executed. 00580 */ 00581 typedef struct sqlite_vm sqlite_vm; 00582 00583 /* 00584 ** To execute an SQLite query without the use of callbacks, you first have 00585 ** to compile the SQL using this routine. The 1st parameter "db" is a pointer 00586 ** to an sqlite object obtained from sqlite_open(). The 2nd parameter 00587 ** "zSql" is the text of the SQL to be compiled. The remaining parameters 00588 ** are all outputs. 00589 ** 00590 ** *pzTail is made to point to the first character past the end of the first 00591 ** SQL statement in zSql. This routine only compiles the first statement 00592 ** in zSql, so *pzTail is left pointing to what remains uncompiled. 00593 ** 00594 ** *ppVm is left pointing to a "virtual machine" that can be used to execute 00595 ** the compiled statement. Or if there is an error, *ppVm may be set to NULL. 00596 ** If the input text contained no SQL (if the input is and empty string or 00597 ** a comment) then *ppVm is set to NULL. 00598 ** 00599 ** If any errors are detected during compilation, an error message is written 00600 ** into space obtained from malloc() and *pzErrMsg is made to point to that 00601 ** error message. The calling routine is responsible for freeing the text 00602 ** of this message when it has finished with it. Use sqlite_freemem() to 00603 ** free the message. pzErrMsg may be NULL in which case no error message 00604 ** will be generated. 00605 ** 00606 ** On success, SQLITE_OK is returned. Otherwise and error code is returned. 00607 */ 00608 int sqlite_compile( 00609 sqlite *db, /* The open database */ 00610 const char *zSql, /* SQL statement to be compiled */ 00611 const char **pzTail, /* OUT: uncompiled tail of zSql */ 00612 sqlite_vm **ppVm, /* OUT: the virtual machine to execute zSql */ 00613 char **pzErrmsg /* OUT: Error message. */ 00614 ); 00615 00616 /* 00617 ** After an SQL statement has been compiled, it is handed to this routine 00618 ** to be executed. This routine executes the statement as far as it can 00619 ** go then returns. The return value will be one of SQLITE_DONE, 00620 ** SQLITE_ERROR, SQLITE_BUSY, SQLITE_ROW, or SQLITE_MISUSE. 00621 ** 00622 ** SQLITE_DONE means that the execute of the SQL statement is complete 00623 ** an no errors have occurred. sqlite_step() should not be called again 00624 ** for the same virtual machine. *pN is set to the number of columns in 00625 ** the result set and *pazColName is set to an array of strings that 00626 ** describe the column names and datatypes. The name of the i-th column 00627 ** is (*pazColName)[i] and the datatype of the i-th column is 00628 ** (*pazColName)[i+*pN]. *pazValue is set to NULL. 00629 ** 00630 ** SQLITE_ERROR means that the virtual machine encountered a run-time 00631 ** error. sqlite_step() should not be called again for the same 00632 ** virtual machine. *pN is set to 0 and *pazColName and *pazValue are set 00633 ** to NULL. Use sqlite_finalize() to obtain the specific error code 00634 ** and the error message text for the error. 00635 ** 00636 ** SQLITE_BUSY means that an attempt to open the database failed because 00637 ** another thread or process is holding a lock. The calling routine 00638 ** can try again to open the database by calling sqlite_step() again. 00639 ** The return code will only be SQLITE_BUSY if no busy handler is registered 00640 ** using the sqlite_busy_handler() or sqlite_busy_timeout() routines. If 00641 ** a busy handler callback has been registered but returns 0, then this 00642 ** routine will return SQLITE_ERROR and sqltie_finalize() will return 00643 ** SQLITE_BUSY when it is called. 00644 ** 00645 ** SQLITE_ROW means that a single row of the result is now available. 00646 ** The data is contained in *pazValue. The value of the i-th column is 00647 ** (*azValue)[i]. *pN and *pazColName are set as described in SQLITE_DONE. 00648 ** Invoke sqlite_step() again to advance to the next row. 00649 ** 00650 ** SQLITE_MISUSE is returned if sqlite_step() is called incorrectly. 00651 ** For example, if you call sqlite_step() after the virtual machine 00652 ** has halted (after a prior call to sqlite_step() has returned SQLITE_DONE) 00653 ** or if you call sqlite_step() with an incorrectly initialized virtual 00654 ** machine or a virtual machine that has been deleted or that is associated 00655 ** with an sqlite structure that has been closed. 00656 */ 00657 int sqlite_step( 00658 sqlite_vm *pVm, /* The virtual machine to execute */ 00659 int *pN, /* OUT: Number of columns in result */ 00660 const char ***pazValue, /* OUT: Column data */ 00661 const char ***pazColName /* OUT: Column names and datatypes */ 00662 ); 00663 00664 /* 00665 ** This routine is called to delete a virtual machine after it has finished 00666 ** executing. The return value is the result code. SQLITE_OK is returned 00667 ** if the statement executed successfully and some other value is returned if 00668 ** there was any kind of error. If an error occurred and pzErrMsg is not 00669 ** NULL, then an error message is written into memory obtained from malloc() 00670 ** and *pzErrMsg is made to point to that error message. The calling routine 00671 ** should use sqlite_freemem() to delete this message when it has finished 00672 ** with it. 00673 ** 00674 ** This routine can be called at any point during the execution of the 00675 ** virtual machine. If the virtual machine has not completed execution 00676 ** when this routine is called, that is like encountering an error or 00677 ** an interrupt. (See sqlite_interrupt().) Incomplete updates may be 00678 ** rolled back and transactions cancelled, depending on the circumstances, 00679 ** and the result code returned will be SQLITE_ABORT. 00680 */ 00681 int sqlite_finalize(sqlite_vm*, char **pzErrMsg); 00682 00683 #ifdef __cplusplus 00684 } /* End of the 'extern "C"' block */ 00685 #endif 00686 00687 #endif /* _SQLITE_H_ */