📄 sqlite3.h
字号:
** azResult[2] = "Alice";** azResult[3] = "43";** azResult[4] = "Bob";** azResult[5] = "28";** azResult[6] = "Cindy";** azResult[7] = "21";**** Notice that there is an extra row of data containing the column** headers. But the *nrow return value is still 3. *ncolumn is** set to 2. In general, the number of values inserted into azResult** will be ((*nrow) + 1)*(*ncolumn).**** After the calling function has finished using the result, it should ** pass the result data pointer to sqlite3_free_table() in order to ** release the memory that was malloc-ed. Because of the way the ** malloc() happens, the calling function must not try to call ** free() directly. Only sqlite3_free_table() is able to release ** the memory properly and safely.**** The return value of this routine is the same as from sqlite3_exec().*/int sqlite3_get_table( sqlite3*, /* An open database */ const char *sql, /* SQL to be executed */ char ***resultp, /* Result written to a char *[] that this points to */ int *nrow, /* Number of result rows written here */ int *ncolumn, /* Number of result columns written here */ char **errmsg /* Error msg written here */);/*** Call this routine to free the memory that sqlite3_get_table() allocated.*/void sqlite3_free_table(char **result);/*** The following routines are variants of the "sprintf()" from the** standard C library. The resulting string is written into memory** obtained from malloc() so that there is never a possiblity of buffer** overflow. These routines also implement some additional formatting** options that are useful for constructing SQL statements.**** The strings returned by these routines should be freed by calling** sqlite3_free().**** All of the usual printf formatting options apply. In addition, there** is a "%q" option. %q works like %s in that it substitutes a null-terminated** string from the argument list. But %q also doubles every '\'' character.** %q is designed for use inside a string literal. By doubling each '\''** character it escapes that character and allows it to be inserted into** the string.**** For example, so some string variable contains text as follows:**** char *zText = "It's a happy day!";**** We can use this text in an SQL statement as follows:**** sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')",** callback1, 0, 0, zText);**** Because the %q format string is used, the '\'' character in zText** is escaped and the SQL generated is as follows:**** INSERT INTO table1 VALUES('It''s a happy day!')**** This is correct. Had we used %s instead of %q, the generated SQL** would have looked like this:**** INSERT INTO table1 VALUES('It's a happy day!');**** This second example is an SQL syntax error. As a general rule you** should always use %q instead of %s when inserting text into a string ** literal.*/char *sqlite3_mprintf(const char*,...);char *sqlite3_vmprintf(const char*, va_list);void sqlite3_free(char *z);char *sqlite3_snprintf(int,char*,const char*, ...);#ifndef SQLITE_OMIT_AUTHORIZATION/*** This routine registers a callback with the SQLite library. The** callback is invoked (at compile-time, not at run-time) for each** attempt to access a column of a table in the database. The callback** returns SQLITE_OK if access is allowed, SQLITE_DENY if the entire** SQL statement should be aborted with an error and SQLITE_IGNORE** if the column should be treated as a NULL value.*/int sqlite3_set_authorizer( sqlite3*, int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), void *pUserData);#endif/*** The second parameter to the access authorization function above will** be one of the values below. These values signify what kind of operation** is to be authorized. The 3rd and 4th parameters to the authorization** function will be parameters or NULL depending on which of the following** codes is used as the second parameter. The 5th parameter is the name** of the database ("main", "temp", etc.) if applicable. The 6th parameter** is the name of the inner-most trigger or view that is responsible for** the access attempt or NULL if this access attempt is directly from ** input SQL code.**** Arg-3 Arg-4*/#define SQLITE_COPY 0 /* Table Name File Name */#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */#define SQLITE_CREATE_VIEW 8 /* View Name NULL */#define SQLITE_DELETE 9 /* Table Name NULL */#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */#define SQLITE_DROP_TABLE 11 /* Table Name NULL */#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */#define SQLITE_DROP_VIEW 17 /* View Name NULL */#define SQLITE_INSERT 18 /* Table Name NULL */#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */#define SQLITE_READ 20 /* Table Name Column Name */#define SQLITE_SELECT 21 /* NULL NULL */#define SQLITE_TRANSACTION 22 /* NULL NULL */#define SQLITE_UPDATE 23 /* Table Name Column Name */#define SQLITE_ATTACH 24 /* Filename NULL */#define SQLITE_DETACH 25 /* Database Name NULL */#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */#define SQLITE_REINDEX 27 /* Index Name NULL *//*** The return value of the authorization function should be one of the** following constants:*//* #define SQLITE_OK 0 // Allow access (This is actually defined above) */#define SQLITE_DENY 1 /* Abort the SQL statement with an error */#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error *//*** Register a function that is called at every invocation of sqlite3_exec()** or sqlite3_prepare(). This function can be used (for example) to generate** a log file of all SQL executed against a database.*/void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);/*** This routine configures a callback function - the progress callback - that** is invoked periodically during long running calls to sqlite3_exec(),** sqlite3_step() and sqlite3_get_table(). An example use for this API is to ** keep a GUI updated during a large query.**** The progress callback is invoked once for every N virtual machine opcodes,** where N is the second argument to this function. The progress callback** itself is identified by the third argument to this function. The fourth** argument to this function is a void pointer passed to the progress callback** function each time it is invoked.**** If a call to sqlite3_exec(), sqlite3_step() or sqlite3_get_table() results ** in less than N opcodes being executed, then the progress callback is not** invoked.** ** To remove the progress callback altogether, pass NULL as the third** argument to this function.**** If the progress callback returns a result other than 0, then the current ** query is immediately terminated and any database changes rolled back. If the** query was part of a larger transaction, then the transaction is not rolled** back and remains active. The sqlite3_exec() call returns SQLITE_ABORT. ********* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE *******/void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);/*** Register a callback function to be invoked whenever a new transaction** is committed. The pArg argument is passed through to the callback.** callback. If the callback function returns non-zero, then the commit** is converted into a rollback.**** If another function was previously registered, its pArg value is returned.** Otherwise NULL is returned.**** Registering a NULL function disables the callback.********* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE *******/void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);/*** Open the sqlite database file "filename". The "filename" is UTF-8** encoded for sqlite3_open() and UTF-16 encoded in the native byte order** for sqlite3_open16(). An sqlite3* handle is returned in *ppDb, even** if an error occurs. If the database is opened (or created) successfully,** then SQLITE_OK is returned. Otherwise an error code is returned. The** sqlite3_errmsg() or sqlite3_errmsg16() routines can be used to obtain** an English language description of the error.**** If the database file does not exist, then a new database is created.** The encoding for the database is UTF-8 if sqlite3_open() is called and** UTF-16 if sqlite3_open16 is used.**** Whether or not an error occurs when it is opened, resources associated** with the sqlite3* handle should be released by passing it to** sqlite3_close() when it is no longer required.*/int sqlite3_open( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb /* OUT: SQLite db handle */);int sqlite3_open16( const void *filename, /* Database filename (UTF-16) */ sqlite3 **ppDb /* OUT: SQLite db handle */);/*** Return the error code for the most recent sqlite3_* API call associated** with sqlite3 handle 'db'. SQLITE_OK is returned if the most recent ** API call was successful.**** Calls to many sqlite3_* functions set the error code and string returned** by sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16()** (overwriting the previous values). Note that calls to sqlite3_errcode(),** sqlite3_errmsg() and sqlite3_errmsg16() themselves do not affect the** results of future invocations.**** Assuming no other intervening sqlite3_* API calls are made, the error** code returned by this function is associated with the same error as** the strings returned by sqlite3_errmsg() and sqlite3_errmsg16().*/int sqlite3_errcode(sqlite3 *db);/*** Return a pointer to a UTF-8 encoded string describing in english the** error condition for the most recent sqlite3_* API call. The returned** string is always terminated by an 0x00 byte.**** The string "not an error" is returned when the most recent API call was** successful.*/const char *sqlite3_errmsg(sqlite3*);/*** Return a pointer to a UTF-16 native byte order encoded string describing** in english the error condition for the most recent sqlite3_* API call.** The returned string is always terminated by a pair of 0x00 bytes.**** The string "not an error" is returned when the most recent API call was** successful.*/const void *sqlite3_errmsg16(sqlite3*);/*** An instance of the following opaque structure is used to represent** a compiled SQL statment.*/typedef struct sqlite3_stmt sqlite3_stmt;/*** To execute an SQL query, it must first be compiled into a byte-code** program using one of the following routines. The only difference between** them is that the second argument, specifying the SQL statement to** compile, is assumed to be encoded in UTF-8 for the sqlite3_prepare()** function and UTF-16 for sqlite3_prepare16().**** The first parameter "db" is an SQLite database handle. The second** parameter "zSql" is the statement to be compiled, encoded as either** UTF-8 or UTF-16 (see above). If the next parameter, "nBytes", is less** than zero, then zSql is read up to the first nul terminator. If** "nBytes" is not less than zero, then it is the length of the string zSql** in bytes (not characters).**** *pzTail is made to point to the first byte past the end of the first** SQL statement in zSql. This routine only compiles the first statement** in zSql, so *pzTail is left pointing to what remains uncompiled.**** *ppStmt is left pointing to a compiled SQL statement that can be** executed using sqlite3_step(). Or if there is an error, *ppStmt may be** set to NULL. If the input text contained no SQL (if the input is and** empty string or a comment) then *ppStmt is set to NULL.**** On success, SQLITE_OK is returned. Otherwise an error code is returned.*/int sqlite3_prepare( sqlite3 *db, /* Database handle */ const char *zSql, /* SQL statement, UTF-8 encoded */ int nBytes, /* Length of zSql in bytes. */ sqlite3_stmt **ppStmt, /* OUT: Statement handle */ const char **pzTail /* OUT: Pointer to unused portion of zSql */);int sqlite3_prepare16( sqlite3 *db, /* Database handle */ const void *zSql, /* SQL statement, UTF-16 encoded */ int nBytes, /* Length of zSql in bytes. */ sqlite3_stmt **ppStmt, /* OUT: Statement handle */ const void **pzTail /* OUT: Pointer to unused portion of zSql */);/*** Pointers to the following two opaque structures are used to communicate** with the implementations of user-defined functions.*/typedef struct sqlite3_context sqlite3_context;typedef struct Mem sqlite3_value;/*** In the SQL strings input to sqlite3_prepare() and sqlite3_prepare16(),** one or more literals can be replace by parameters "?" or ":AAA" or** "$VVV" where AAA is an identifer and VVV is a variable name according
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -