📄 sqlite3.h
字号:
** 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.**** {F17411} 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. {END} 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.**** {F17412} The "%z" formatting option works exactly like "%s" with the** addition that after the string has been read and copied into** the result, [sqlite3_free()] is called on the input string. {END}*/char *sqlite3_mprintf(const char*,...);char *sqlite3_vmprintf(const char*, va_list);char *sqlite3_snprintf(int,char*,const char*, ...);/*** CAPI3REF: Memory Allocation Subsystem {F17300}**** {F17301} The SQLite core uses these three routines for all of its own** internal memory allocation needs. {END} "Core" in the previous sentence** does not include operating-system specific VFS implementation. The** windows VFS uses native malloc and free for some operations.**** {F17302} The sqlite3_malloc() routine returns a pointer to a block** of memory at least N bytes in length, where N is the parameter.** {F17303} If sqlite3_malloc() is unable to obtain sufficient free** memory, it returns a NULL pointer. {F17304} If the parameter N to** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns** a NULL pointer.**** {F17305} Calling sqlite3_free() with a pointer previously returned** by sqlite3_malloc() or sqlite3_realloc() releases that memory so** that it might be reused. {F17306} The sqlite3_free() routine is** a no-op if is called with a NULL pointer. Passing a NULL pointer** to sqlite3_free() is harmless. {U17307} After being freed, memory** should neither be read nor written. Even reading previously freed** memory might result in a segmentation fault or other severe error.** {U17309} Memory corruption, a segmentation fault, or other severe error** might result if sqlite3_free() is called with a non-NULL pointer that** was not obtained from sqlite3_malloc() or sqlite3_free().**** {F17310} The sqlite3_realloc() interface attempts to resize a** prior memory allocation to be at least N bytes, where N is the** second parameter. The memory allocation to be resized is the first** parameter. {F17311} If the first parameter to sqlite3_realloc()** is a NULL pointer then its behavior is identical to calling** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().** {F17312} If the second parameter to sqlite3_realloc() is zero or** negative then the behavior is exactly the same as calling** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().** {F17313} Sqlite3_realloc() returns a pointer to a memory allocation** of at least N bytes in size or NULL if sufficient memory is unavailable.** {F17314} If M is the size of the prior allocation, then min(N,M) bytes** of the prior allocation are copied into the beginning of buffer returned** by sqlite3_realloc() and the prior allocation is freed.** {F17315} If sqlite3_realloc() returns NULL, then the prior allocation** is not freed.**** {F17316} The memory returned by sqlite3_malloc() and sqlite3_realloc()** is always aligned to at least an 8 byte boundary. {END}**** {F17381} The default implementation** of the memory allocation subsystem uses the malloc(), realloc()** and free() provided by the standard C library. {F17382} However, if ** SQLite is compiled with the following C preprocessor macro**** <blockquote> SQLITE_MEMORY_SIZE=<i>NNN</i> </blockquote>**** where <i>NNN</i> is an integer, then SQLite create a static** array of at least <i>NNN</i> bytes in size and use that array** for all of its dynamic memory allocation needs. {END} Additional** memory allocator options may be added in future releases.**** In SQLite version 3.5.0 and 3.5.1, it was possible to define** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in** implementation of these routines to be omitted. That capability** is no longer provided. Only built-in memory allocators can be** used.**** The windows OS interface layer calls** the system malloc() and free() directly when converting** filenames between the UTF-8 encoding used by SQLite** and whatever filename encoding is used by the particular windows** installation. Memory allocation errors are detected, but** they are reported back as [SQLITE_CANTOPEN] or** [SQLITE_IOERR] rather than [SQLITE_NOMEM].*/void *sqlite3_malloc(int);void *sqlite3_realloc(void*, int);void sqlite3_free(void*);/*** CAPI3REF: Memory Allocator Statistics {F17370}**** In addition to the basic three allocation routines ** [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()],** the memory allocation subsystem included with the SQLite** sources provides the interfaces shown here.**** {F17371} The sqlite3_memory_used() routine returns the** number of bytes of memory currently outstanding (malloced but not freed).** {F17372} The value returned by sqlite3_memory_used() includes** any overhead added by SQLite, but not overhead added by the** library malloc() that backs the sqlite3_malloc() implementation.** {F17373} The sqlite3_memory_highwater() routines returns the** maximum number of bytes that have been outstanding at any time** since the highwater mark was last reset.** {F17374} The byte count returned by sqlite3_memory_highwater()** uses the same byte counting rules as sqlite3_memory_used(). {END}** In other words, overhead added internally by SQLite is counted,** but overhead from the underlying system malloc is not.** {F17375} If the parameter to sqlite3_memory_highwater() is true,** then the highwater mark is reset to the current value of** sqlite3_memory_used() and the prior highwater mark (before the** reset) is returned. {F17376} If the parameter to ** sqlite3_memory_highwater() is zero, then the highwater mark is** unchanged.*/sqlite3_int64 sqlite3_memory_used(void);sqlite3_int64 sqlite3_memory_highwater(int resetFlag);/*** CAPI3REF: Compile-Time Authorization Callbacks {F12500}**** {F12501} This routine registers a authorizer callback with a particular** database connection, supplied in the first argument. {F12502}** 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()]. {F12503} 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. {F12504} If the authorizer callback returns** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]** then [sqlite3_prepare_v2()] or equivalent call that triggered** the authorizer shall** fail with an SQLITE_ERROR error code and an appropriate error message. {END}**** When the callback returns [SQLITE_OK], that means the operation** requested is ok. {F12505} When the callback returns [SQLITE_DENY], the** [sqlite3_prepare_v2()] or equivalent call that triggered the** authorizer shall fail** with an SQLITE_ERROR error code and an error message explaining that** access is denied. {F12506} If the authorizer code (the 2nd parameter** to the authorizer callback is anything other than [SQLITE_READ], then** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY]. ** If the authorizer code is [SQLITE_READ] and the callback returns** [SQLITE_IGNORE] then the prepared statement is constructed to** insert a NULL value in place of the table column that would have** been read if [SQLITE_OK] had been returned. {END}**** {F12510} The first parameter to the authorizer callback is a copy of** the third parameter to the sqlite3_set_authorizer() interface.** {F12511} The second parameter to the callback is an integer ** [SQLITE_COPY | action code] that specifies the particular action** to be authorized. {END} The available action codes are** [SQLITE_COPY | documented separately]. {F12512} The third through sixth** parameters to the callback are zero-terminated strings that contain ** additional details about the action to be authorized. {END}**** 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. **** {F12520} 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. {F12521} A NULL authorizer means that no authorization** callback is invoked. {F12522} The default authorizer is NULL. {END}**** Note that the authorizer callback is invoked only during ** [sqlite3_prepare()] or its variants. {F12523} Authorization is not** performed during statement evaluation in [sqlite3_step()]. {END}*/int sqlite3_set_authorizer( sqlite3*, int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), void *pUserData);/*** CAPI3REF: Authorizer Return Codes {F12590}**** 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 {F12550}**** The [sqlite3_set_authorizer()] interface registers a callback function** that is invoked to authorizer certain SQL statement actions. {F12551} 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. {END}**** These action code values signify what kind of operation is to be ** authorized. {F12552} 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. {F12553} The 5th parameter to the** authorizer callback is the name of the database ("main", "temp", ** etc.) if applicable. {F12554} 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -