📄 sqlite.h.in
字号:
/*** CAPI3REF: Formatted String Printing Functions**** These routines are workalikes of the "printf()" family of functions** from the standard C library.**** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their** results into memory obtained from [sqlite_malloc()].** The strings returned by these two routines should be** released by [sqlite3_free()]. Both routines return a** NULL pointer if [sqlite3_malloc()] is unable to allocate enough** memory to hold the resulting string.**** In sqlite3_snprintf() routine is similar to "snprintf()" from** the standard C library. The result is written into the** buffer supplied as the second parameter whose size is given by** the first parameter. Note that the order of the** first two parameters is reversed from snprintf(). This is an** historical accident that cannot be fixed without breaking** backwards compatibility. Note also that sqlite3_snprintf()** returns a pointer to its buffer instead of the number of** characters actually written into the buffer. We admit that** the number of characters written would be a more useful return** value but we cannot change the implementation of sqlite3_snprintf()** now without breaking compatibility.**** As long as the buffer size is greater than zero, sqlite3_snprintf()** guarantees that the buffer is always zero-terminated. The first** parameter "n" is the total size of the buffer, including space for** the zero terminator. So the longest string that can be completely** written will be n-1 characters.**** These routines all implement some additional formatting** options that are useful for constructing SQL statements.** All of the usual printf formatting options apply. In addition, there** is are "%q" and "%Q" options.**** The %q option 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:**** <blockquote><pre>** char *zText = "It's a happy day!";** </pre></blockquote>**** One can use this text in an SQL statement as follows:**** <blockquote><pre>** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);** sqlite3_exec(db, zSQL, 0, 0, 0);** sqlite3_free(zSQL);** </pre></blockquote>**** Because the %q format string is used, the '\'' character in zText** is escaped and the SQL generated is as follows:**** <blockquote><pre>** INSERT INTO table1 VALUES('It''s a happy day!')** </pre></blockquote>**** This is correct. Had we used %s instead of %q, the generated SQL** would have looked like this:**** <blockquote><pre>** INSERT INTO table1 VALUES('It's a happy day!');** </pre></blockquote>**** 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.**** The %Q option works like %q except it also adds single quotes around** the outside of the total string. Or if the parameter in the argument** list is a NULL pointer, %Q substitutes the text "NULL" (without single** quotes) in place of the %Q option. So, for example, one could say:**** <blockquote><pre>** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);** sqlite3_exec(db, zSQL, 0, 0, 0);** sqlite3_free(zSQL);** </pre></blockquote>**** The code above will render a correct SQL statement in the zSQL** variable even if the zText variable is a NULL pointer.*/char *sqlite3_mprintf(const char*,...);char *sqlite3_vmprintf(const char*, va_list);char *sqlite3_snprintf(int,char*,const char*, ...);/*** CAPI3REF: Memory Allocation Functions**** SQLite uses its own memory allocator. On some installations, this** memory allocator is identical to the standard malloc()/realloc()/free()** and can be used interchangable. On others, the implementations are** different. For maximum portability, it is best not to mix calls** to the standard malloc/realloc/free with the sqlite versions.*/void *sqlite3_malloc(int);void *sqlite3_realloc(void*, int);void sqlite3_free(void*);/*** CAPI3REF: Compile-Time Authorization Callbacks***** This routine registers a authorizer callback with the SQLite library. ** The authorizer callback is invoked as SQL statements are being compiled** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. At various** points during the compilation process, as logic is being created** to perform various actions, the authorizer callback is invoked to** see if those actions are allowed. The authorizer callback should** return SQLITE_OK to allow the action, [SQLITE_IGNORE] to disallow the** specific action but allow the SQL statement to continue to be** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be** rejected with an error. **** Depending on the action, the [SQLITE_IGNORE] and [SQLITE_DENY] return** codes might mean something different or they might mean the same** thing. If the action is, for example, to perform a delete opertion,** then [SQLITE_IGNORE] and [SQLITE_DENY] both cause the statement compilation** to fail with an error. But if the action is to read a specific column** from a specific table, then [SQLITE_DENY] will cause the entire** statement to fail but [SQLITE_IGNORE] will cause a NULL value to be** read instead of the actual column value.**** The first parameter to the authorizer callback is a copy of** the third parameter to the sqlite3_set_authorizer() interface.** The second parameter to the callback is an integer ** [SQLITE_COPY | action code] that specifies the particular action** to be authorized. The available action codes are** [SQLITE_COPY | documented separately]. The third through sixth** parameters to the callback are strings that contain additional** details about the action to be authorized.**** An authorizer is used when preparing SQL statements from an untrusted** source, to ensure that the SQL statements do not try to access data** that they are not allowed to see, or that they do not try to** execute malicious statements that damage the database. For** example, an application may allow a user to enter arbitrary** SQL queries for evaluation by a database. But the application does** not want the user to be able to make arbitrary changes to the** database. An authorizer could then be put in place while the** user-entered SQL is being prepared that disallows everything** except SELECT statements. **** Only a single authorizer can be in place on a database connection** at a time. Each call to sqlite3_set_authorizer overrides the** previous call. A NULL authorizer means that no authorization** callback is invoked. The default authorizer is NULL.**** Note that the authorizer callback is invoked only during ** [sqlite3_prepare()] or its variants. Authorization is not** performed during statement evaluation in [sqlite3_step()].*/int sqlite3_set_authorizer( sqlite3*, int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), void *pUserData);/*** CAPI3REF: Authorizer Return Codes**** The [sqlite3_set_authorizer | authorizer callback function] must** return either [SQLITE_OK] or one of these two constants in order** to signal SQLite whether or not the action is permitted. See the** [sqlite3_set_authorizer | authorizer documentation] for additional** information.*/#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 *//*** CAPI3REF: Authorizer Action Codes**** The [sqlite3_set_authorizer()] interface registers a callback function** that is invoked to authorizer certain SQL statement actions. The** second parameter to the callback is an integer code that specifies** what action is being authorized. These are the integer action codes that** the authorizer callback may be passed.**** These action code values signify what kind of operation is to be ** authorized. The 3rd and 4th parameters to the authorization callback** function will be parameters or NULL depending on which of these** codes is used as the second parameter. The 5th parameter to the** authorizer callback is the name of the database ("main", "temp", ** etc.) if applicable. The 6th parameter to the authorizer callback** 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 ** top-level SQL code.*//******************************************* 3rd ************ 4th ***********/#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 */#define SQLITE_ANALYZE 28 /* Table Name NULL */#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */#define SQLITE_FUNCTION 31 /* Function Name NULL */#define SQLITE_COPY 0 /* No longer used *//*** CAPI3REF: Tracing And Profiling Functions**** These routines register callback functions that can be used for** tracing and profiling the execution of SQL statements.** The callback function registered by sqlite3_trace() is invoked** at the first [sqlite3_step()] for the evaluation of an SQL statement.** The callback function registered by sqlite3_profile() is invoked** as each SQL statement finishes and includes** information on how long that statement ran.**** The sqlite3_profile() API is currently considered experimental and** is subject to change.*/void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);void *sqlite3_profile(sqlite3*, void(*xProfile)(void*,const char*,sqlite_uint64), void*);/*** CAPI3REF: Query Progress Callbacks**** 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 ** interface 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 fewer than N opcodes being executed, then the progress ** callback is never invoked.** ** Only a single progress callback function may be registered for each** open database connection. Every call to sqlite3_progress_handler()** overwrites the results of the previous call.** 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.** The containing [sqlite3_exec()], [sqlite3_step()], or** [sqlite3_get_table()] call returns SQLITE_INTERRUPT. This feature** can be used, for example, to implement the "Cancel" button on a** progress dialog box in a GUI.*/void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);/*** CAPI3REF: Opening A New Database Connection**** 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -