📄 sqlite.h
字号:
/*** 2001 September 15**** The author disclaims copyright to this source code. In place of** a legal notice, here is a blessing:**** May you do good and not evil.** May you find forgiveness for yourself and forgive others.** May you share freely, never taking more than you give.***************************************************************************** This header file defines the interface that the SQLite library** presents to client programs.**** @(#) $Id: sqlite.h.in,v 1.60.2.1 2004/10/06 15:52:36 drh Exp $*/#ifndef _SQLITE_H_#define _SQLITE_H_#include <stdarg.h> /* Needed for the definition of va_list *//*** Make sure we can call this stuff from C++.*/#ifdef __cplusplusextern "C" {#endif/*** The version of the SQLite library.*/#ifdef SQLITE_VERSION# undef SQLITE_VERSION#else# define SQLITE_VERSION "2.8.17"#endif/*** The version string is also compiled into the library so that a program** can check to make sure that the lib*.a file and the *.h file are from** the same version.*/extern const char sqlite_version[];/*** The SQLITE_UTF8 macro is defined if the library expects to see** UTF-8 encoded data. The SQLITE_ISO8859 macro is defined if the** iso8859 encoded should be used.*/#define SQLITE_ISO8859 1/*** The following constant holds one of two strings, "UTF-8" or "iso8859",** depending on which character encoding the SQLite library expects to** see. The character encoding makes a difference for the LIKE and GLOB** operators and for the LENGTH() and SUBSTR() functions.*/extern const char sqlite_encoding[];/*** Each open sqlite database is represented by an instance of the** following opaque structure.*/typedef struct sqlite sqlite;/*** A function to open a new sqlite database. **** If the database does not exist and mode indicates write** permission, then a new database is created. If the database** does not exist and mode does not indicate write permission,** then the open fails, an error message generated (if errmsg!=0)** and the function returns 0.** ** If mode does not indicates user write permission, then the ** database is opened read-only.**** The Truth: As currently implemented, all databases are opened** for writing all the time. Maybe someday we will provide the** ability to open a database readonly. The mode parameters is** provided in anticipation of that enhancement.*/sqlite *sqlite_open(const char *filename, int mode, char **errmsg);/*** A function to close the database.**** Call this function with a pointer to a structure that was previously** returned from sqlite_open() and the corresponding database will by closed.*/void sqlite_close(sqlite *);/*** The type for a callback function.*/typedef int (*sqlite_callback)(void*,int,char**, char**);/*** A function to executes one or more statements of SQL.**** If one or more of the SQL statements are queries, then** the callback function specified by the 3rd parameter is** invoked once for each row of the query result. This callback** should normally return 0. If the callback returns a non-zero** value then the query is aborted, all subsequent SQL statements** are skipped and the sqlite_exec() function returns the SQLITE_ABORT.**** The 4th parameter is an arbitrary pointer that is passed** to the callback function as its first parameter.**** The 2nd parameter to the callback function is the number of** columns in the query result. The 3rd parameter to the callback** is an array of strings holding the values for each column.** The 4th parameter to the callback is an array of strings holding** the names of each column.**** The callback function may be NULL, even for queries. A NULL** callback is not an error. It just means that no callback** will be invoked.**** If an error occurs while parsing or evaluating the SQL (but** not while executing the callback) then an appropriate error** message is written into memory obtained from malloc() and** *errmsg is made to point to that message. The calling function** is responsible for freeing the memory that holds the error** message. Use sqlite_freemem() for this. If errmsg==NULL,** then no error message is ever written.**** The return value is is SQLITE_OK if there are no errors and** some other return code if there is an error. The particular** return value depends on the type of error. **** If the query could not be executed because a database file is** locked or busy, then this function returns SQLITE_BUSY. (This** behavior can be modified somewhat using the sqlite_busy_handler()** and sqlite_busy_timeout() functions below.)*/int sqlite_exec( sqlite*, /* An open database */ const char *sql, /* SQL to be executed */ sqlite_callback, /* Callback function */ void *, /* 1st argument to callback function */ char **errmsg /* Error msg written here */);/*** Return values for sqlite_exec() and sqlite_step()*/#define SQLITE_OK 0 /* Successful result */#define SQLITE_ERROR 1 /* SQL error or missing database */#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */#define SQLITE_PERM 3 /* Access permission denied */#define SQLITE_ABORT 4 /* Callback routine requested an abort */#define SQLITE_BUSY 5 /* The database file is locked */#define SQLITE_LOCKED 6 /* A table in the database is locked */#define SQLITE_NOMEM 7 /* A malloc() failed */#define SQLITE_READONLY 8 /* Attempt to write a readonly database */#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite_interrupt() */#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */#define SQLITE_CORRUPT 11 /* The database disk image is malformed */#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */#define SQLITE_FULL 13 /* Insertion failed because database is full */#define SQLITE_CANTOPEN 14 /* Unable to open the database file */#define SQLITE_PROTOCOL 15 /* Database lock protocol error */#define SQLITE_EMPTY 16 /* (Internal Only) Database table is empty */#define SQLITE_SCHEMA 17 /* The database schema changed */#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */#define SQLITE_MISMATCH 20 /* Data type mismatch */#define SQLITE_MISUSE 21 /* Library used incorrectly */#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */#define SQLITE_AUTH 23 /* Authorization denied */#define SQLITE_FORMAT 24 /* Auxiliary database format error */#define SQLITE_RANGE 25 /* 2nd parameter to sqlite_bind out of range */#define SQLITE_NOTADB 26 /* File opened that is not a database file */#define SQLITE_ROW 100 /* sqlite_step() has another row ready */#define SQLITE_DONE 101 /* sqlite_step() has finished executing *//*** Each entry in an SQLite table has a unique integer key. (The key is** the value of the INTEGER PRIMARY KEY column if there is such a column,** otherwise the key is generated at random. The unique key is always** available as the ROWID, OID, or _ROWID_ column.) The following routine** returns the integer key of the most recent insert in the database.**** This function is similar to the mysql_insert_id() function from MySQL.*/int sqlite_last_insert_rowid(sqlite*);/*** This function returns the number of database rows that were changed** (or inserted or deleted) by the most recent called sqlite_exec().**** 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 sqlite_exec() 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 sqlite_changes(sqlite*);/*** This function returns the number of database rows that were changed** by the last INSERT, UPDATE, or DELETE statment executed by sqlite_exec(),** or by the last VM to run to completion. The change count is not updated** by SQL statements other than INSERT, UPDATE or DELETE.**** Changes are counted, even if they are later undone by a ROLLBACK or** ABORT. Changes associated with trigger programs that execute as a** result of the INSERT, UPDATE, or DELETE statement are not counted.**** If a callback invokes sqlite_exec() 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.********* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE *******/int sqlite_last_statement_changes(sqlite*);/* If the parameter to this routine is one of the return value constants** defined above, then this routine returns a constant text string which** descripts (in English) the meaning of the return value.*/const char *sqlite_error_string(int);#define sqliteErrStr sqlite_error_string /* Legacy. Do not use in new code. *//* 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.*/void sqlite_interrupt(sqlite*);/* This function returns true if the given input string comprises** one or more complete SQL statements.**** The algorithm is simple. If the last token other than spaces** and comments is a semicolon, then return true. otherwise return** false.*/int sqlite_complete(const char *sql);/*** This routine identifies a callback function that is invoked** whenever an attempt is made to open a database table that is** currently locked by another process or thread. If the busy callback** is NULL, then sqlite_exec() returns SQLITE_BUSY immediately if** it finds a locked table. If the busy callback is not NULL, then** sqlite_exec() invokes the callback with three arguments. The** second argument is the name of the locked table and the third** argument is the number of times the table has been busy. If the** busy callback returns 0, then sqlite_exec() immediately returns** SQLITE_BUSY. If the callback returns non-zero, then sqlite_exec()** tries to open the table again and the cycle repeats.**** The default busy callback is NULL.**** 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 coredump.*/void sqlite_busy_handler(sqlite*, int(*)(void*,const char*,int), void*);/*** 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" milleseconds of sleeping have been done. After** "ms" milleseconds of sleeping, the handler returns 0 which** causes sqlite_exec() to return SQLITE_BUSY.**** Calling this routine with an argument less than or equal to zero** turns off all busy handlers.*/void sqlite_busy_timeout(sqlite*, int ms);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -