📄 sqlite3.h
字号:
**** The SQLITE_OK result code will never be extended. It will always** be exactly zero.*/#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))/*** CAPI3REF: Enable Or Disable Extended Result Codes**** This routine enables or disables the** [SQLITE_IOERR_READ | extended result codes] feature.** By default, SQLite API routines return one of only 26 integer** [SQLITE_OK | result codes]. When extended result codes** are enabled by this routine, the repetoire of result codes can be** much larger and can (hopefully) provide more detailed information** about the cause of an error.**** The second argument is a boolean value that turns extended result** codes on and off. Extended result codes are off by default for** backwards compatibility with older versions of SQLite.*/int sqlite3_extended_result_codes(sqlite3*, int onoff);/*** CAPI3REF: Last Insert Rowid**** Each entry in an SQLite table has a unique 64-bit signed integer key** called the "rowid". The rowid is always available as an undeclared** column named ROWID, OID, or _ROWID_. If the table has a column of** type INTEGER PRIMARY KEY then that column is another an alias for the** rowid.**** This routine returns the rowid of the most recent INSERT into** the database from the database connection given in the first ** argument. If no inserts have ever occurred on this database** connection, zero is returned.**** If an INSERT occurs within a trigger, then the rowid of the** inserted row is returned by this routine as long as the trigger** is running. But once the trigger terminates, the value returned** by this routine reverts to the last value inserted before the** trigger fired.*/sqlite_int64 sqlite3_last_insert_rowid(sqlite3*);/*** CAPI3REF: Count The Number Of Rows Modified**** This function returns the number of database rows that were changed** (or inserted or deleted) by the most recent SQL statement. Only** changes that are directly specified by the INSERT, UPDATE, or** DELETE statement are counted. Auxiliary changes caused by** triggers are not counted. Use the [sqlite3_total_changes()] function** to find the total number of changes including changes caused by triggers.**** Within the body of a trigger, the sqlite3_changes() interface can be** called to find the number of** changes in the most recently completed INSERT, UPDATE, or DELETE** statement within the body of the trigger.**** All changes are counted, even if they were later undone by a** ROLLBACK or ABORT. Except, changes associated with creating and** dropping tables are not counted.**** If a callback invokes [sqlite3_exec()] or [sqlite3_step()] recursively,** then the changes in the inner, recursive call are counted together** with the changes in the outer call.**** SQLite implements the command "DELETE FROM table" without a WHERE clause** by dropping and recreating the table. (This is much faster than going** through and deleting individual elements form the table.) Because of** this optimization, the change count for "DELETE FROM table" will be** zero regardless of the number of elements that were originally in the** table. To get an accurate count of the number of rows deleted, use** "DELETE FROM table WHERE 1" instead.*/int sqlite3_changes(sqlite3*);/*** CAPI3REF: Total Number Of Rows Modified***** This function returns the number of database rows that have been** modified by INSERT, UPDATE or DELETE statements since the database handle** was opened. This includes UPDATE, INSERT and DELETE statements executed** as part of trigger programs. All changes are counted as soon as the** statement that makes them is completed (when the statement handle is** passed to [sqlite3_reset()] or [sqlite_finalise()]).**** See also the [sqlite3_change()] interface.**** SQLite implements the command "DELETE FROM table" without a WHERE clause** by dropping and recreating the table. (This is much faster than going** through and deleting individual elements form the table.) Because of** this optimization, the change count for "DELETE FROM table" will be** zero regardless of the number of elements that were originally in the** table. To get an accurate count of the number of rows deleted, use** "DELETE FROM table WHERE 1" instead.*/int sqlite3_total_changes(sqlite3*);/*** CAPI3REF: Interrupt A Long-Running Query**** This function causes any pending database operation to abort and** return at its earliest opportunity. This routine is typically** called in response to a user action such as pressing "Cancel"** or Ctrl-C where the user wants a long query operation to halt** immediately.**** It is safe to call this routine from a thread different from the** thread that is currently running the database operation.**** The SQL operation that is interrupted will return [SQLITE_INTERRUPT].** If an interrupted operation was an update that is inside an** explicit transaction, then the entire transaction will be rolled** back automatically.*/void sqlite3_interrupt(sqlite3*);/*** CAPI3REF: Determine If An SQL Statement Is Complete**** These functions return true if the given input string comprises** one or more complete SQL statements. For the sqlite3_complete() call,** the parameter must be a nul-terminated UTF-8 string. For** sqlite3_complete16(), a nul-terminated machine byte order UTF-16 string** is required.**** These routines are useful for command-line input to determine if the** currently entered text forms one or more complete SQL statements or** if additional input is needed before sending the statements into** SQLite for parsing. The algorithm is simple. If the ** last token other than spaces and comments is a semicolon, then return ** true. Actually, the algorithm is a little more complicated than that** in order to deal with triggers, but the basic idea is the same: the** statement is not complete unless it ends in a semicolon.*/int sqlite3_complete(const char *sql);int sqlite3_complete16(const void *sql);/*** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors**** This routine identifies a callback function that might be invoked** whenever an attempt is made to open a database table ** that another thread or process has locked.** If the busy callback is NULL, then [SQLITE_BUSY]** (or sometimes [SQLITE_IOERR_BLOCKED])** is returned immediately upon encountering the lock.** If the busy callback is not NULL, then the** callback will be invoked with two arguments. The** first argument to the handler is a copy of the void* pointer which** is the third argument to this routine. The second argument to** the handler is the number of times that the busy handler has** been invoked for this locking event. If the** busy callback returns 0, then no additional attempts are made to** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.** If the callback returns non-zero, then another attempt is made to open the** database for reading and the cycle repeats.**** The presence of a busy handler does not guarantee that** it will be invoked when there is lock contention.** If SQLite determines that invoking the busy handler could result in** a deadlock, it will return [SQLITE_BUSY] instead.** Consider a scenario where one process is holding a read lock that** it is trying to promote to a reserved lock and** a second process is holding a reserved lock that it is trying** to promote to an exclusive lock. The first process cannot proceed** because it is blocked by the second and the second process cannot** proceed because it is blocked by the first. If both processes** invoke the busy handlers, neither will make any progress. Therefore,** SQLite returns [SQLITE_BUSY] for the first process, hoping that this** will induce the first process to release its read lock and allow** the second process to proceed.**** The default busy callback is NULL.**** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] when** SQLite is in the middle of a large transaction where all the** changes will not fit into the in-memory cache. SQLite will** already hold a RESERVED lock on the database file, but it needs** to promote this lock to EXCLUSIVE so that it can spill cache** pages into the database file without harm to concurrent** readers. If it is unable to promote the lock, then the in-memory** cache will be left in an inconsistent state and so the error** code is promoted from the relatively benign [SQLITE_BUSY] to** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion** forces an automatic rollback of the changes. See the** <a href="http://www.sqlite.org/cvstrac/wiki?p=CorruptionFollowingBusyError">** CorruptionFollowingBusyError</a> wiki page for a discussion of why** this is important.** ** Sqlite is re-entrant, so the busy handler may start a new query. ** (It is not clear why anyone would every want to do this, but it** is allowed, in theory.) But the busy handler may not close the** database. Closing the database from a busy handler will delete ** data structures out from under the executing query and will ** probably result in a segmentation fault or other runtime error.**** There can only be a single busy handler defined for each database** connection. Setting a new busy handler clears any previous one.** Note that calling [sqlite3_busy_timeout()] will also set or clear** the busy handler.*/int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);/*** CAPI3REF: Set A Busy Timeout**** This routine sets a busy handler that sleeps for a while when a** table is locked. The handler will sleep multiple times until ** at least "ms" milliseconds of sleeping have been done. After** "ms" milliseconds of sleeping, the handler returns 0 which** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].**** Calling this routine with an argument less than or equal to zero** turns off all busy handlers.**** There can only be a single busy handler for a particular database** connection. If another busy handler was defined ** (using [sqlite3_busy_handler()]) prior to calling** this routine, that other busy handler is cleared.*/int sqlite3_busy_timeout(sqlite3*, int ms);/*** CAPI3REF: Convenience Routines For Running Queries**** This next routine is a convenience wrapper around [sqlite3_exec()].** Instead of invoking a user-supplied callback for each row of the** result, this routine remembers each row of the result in memory** obtained from [sqlite3_malloc()], then returns all of the result after the** query has finished. **** As an example, suppose the query result where this table:**** <pre>** Name | Age** -----------------------** Alice | 43** Bob | 28** Cindy | 21** </pre>**** If the 3rd argument were &azResult then after the function returns** azResult will contain the following data:**** <pre>** azResult[0] = "Name";** azResult[1] = "Age";** azResult[2] = "Alice";** azResult[3] = "43";** azResult[4] = "Bob";** azResult[5] = "28";** azResult[6] = "Cindy";** azResult[7] = "21";** </pre>**** 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 ** [sqlite3_malloc()] happens, the calling function must not try to call ** [sqlite3_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 */);void sqlite3_free_table(char **result);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -