📄 sqlite3.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.136 2005/06/12 22:12:39 drh Exp $*/#ifndef _SQLITE3_H_#define _SQLITE3_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#endif#define SQLITE_VERSION "3.2.2"/*** The format of the version string is "X.Y.Z<trailing string>", where** X is the major version number, Y is the minor version number and Z** is the release number. The trailing string is often "alpha" or "beta".** For example "3.1.1beta".**** The SQLITE_VERSION_NUMBER is an integer with the value ** (X*100000 + Y*1000 + Z). For example, for version "3.1.1beta", ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using ** version 3.1.1 or greater at compile time, programs may use the test ** (SQLITE_VERSION_NUMBER>=3001001).*/#ifdef SQLITE_VERSION_NUMBER# undef SQLITE_VERSION_NUMBER#endif#define SQLITE_VERSION_NUMBER 3002002/*** 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. The sqlite3_libversion() function returns a pointer** to the sqlite3_version variable - useful in DLLs which cannot access** global variables.*/extern const char sqlite3_version[];const char *sqlite3_libversion(void);/*** Return the value of the SQLITE_VERSION_NUMBER macro when the** library was compiled.*/int sqlite3_libversion_number(void);/*** Each open sqlite database is represented by an instance of the** following opaque structure.*/typedef struct sqlite3 sqlite3;/*** Some compilers do not support the "long long" datatype. So we have** to do a typedef that for 64-bit integers that depends on what compiler** is being used.*/#if defined(_MSC_VER) || defined(__BORLANDC__) typedef __int64 sqlite_int64; typedef unsigned __int64 sqlite_uint64;#else typedef long long int sqlite_int64; typedef unsigned long long int sqlite_uint64;#endif/*** A function to close the database.**** Call this function with a pointer to a structure that was previously** returned from sqlite3_open() and the corresponding database will by closed.**** All SQL statements prepared using sqlite3_prepare() or** sqlite3_prepare16() must be deallocated using sqlite3_finalize() before** this routine is called. Otherwise, SQLITE_BUSY is returned and the** database connection remains open.*/int sqlite3_close(sqlite3 *);/*** The type for a callback function.*/typedef int (*sqlite3_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 sqlite3_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 sqlite3_free() 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 sqlite3_busy_handler()** and sqlite3_busy_timeout() functions below.)*/int sqlite3_exec( sqlite3*, /* An open database */ const char *sql, /* SQL to be executed */ sqlite3_callback, /* Callback function */ void *, /* 1st argument to callback function */ char **errmsg /* Error msg written here */);/*** Return values for sqlite3_exec() and sqlite3_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 sqlite3_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 /* Database 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 sqlite3_bind out of range */#define SQLITE_NOTADB 26 /* File opened that is not a database file */#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */#define SQLITE_DONE 101 /* sqlite3_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.*/sqlite_int64 sqlite3_last_insert_rowid(sqlite3*);/*** This function returns the number of database rows that were changed** (or inserted or deleted) by the most recent called sqlite3_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 sqlite3_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 sqlite3_changes(sqlite3*);/*** 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()).**** 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*);/* 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 sqlite3_interrupt(sqlite3*);/* 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.**** The algorithm is simple. If the last token other than spaces** and comments is a semicolon, then return true. otherwise return** false.*/int sqlite3_complete(const char *sql);int sqlite3_complete16(const void *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 sqlite3_exec() returns SQLITE_BUSY immediately if** it finds a locked table. If the busy callback is not NULL, then** sqlite3_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 sqlite3_exec() immediately returns** SQLITE_BUSY. If the callback returns non-zero, then sqlite3_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.*/int sqlite3_busy_handler(sqlite3*, int(*)(void*,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 sqlite3_exec() to return SQLITE_BUSY.**** Calling this routine with an argument less than or equal to zero** turns off all busy handlers.*/int sqlite3_busy_timeout(sqlite3*, int ms);/*** This next routine is really just a 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 malloc(), then returns all of the result after the** query has finished. **** As an example, suppose the query result where this table:**** Name | Age** -----------------------** Alice | 43** Bob | 28** Cindy | 21**** If the 3rd argument were &azResult then after the function returns** azResult will contain the following data:**** azResult[0] = "Name";** azResult[1] = "Age";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -