sqlite3.h 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  1. /*
  2. ** 2001 September 15
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** This header file defines the interface that the SQLite library
  13. ** presents to client programs.
  14. **
  15. ** @(#) $Id: sqlite3.h,v 1.2 2006-09-14 04:56:10 sabrogden Exp $
  16. */
  17. #ifndef _SQLITE3_H_
  18. #define _SQLITE3_H_
  19. #include <stdarg.h> /* Needed for the definition of va_list */
  20. /*
  21. ** Make sure we can call this stuff from C++.
  22. */
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /*
  27. ** The version of the SQLite library.
  28. */
  29. #ifdef SQLITE_VERSION
  30. # undef SQLITE_VERSION
  31. #endif
  32. #define SQLITE_VERSION "3.3.7"
  33. /*
  34. ** The format of the version string is "X.Y.Z<trailing string>", where
  35. ** X is the major version number, Y is the minor version number and Z
  36. ** is the release number. The trailing string is often "alpha" or "beta".
  37. ** For example "3.1.1beta".
  38. **
  39. ** The SQLITE_VERSION_NUMBER is an integer with the value
  40. ** (X*100000 + Y*1000 + Z). For example, for version "3.1.1beta",
  41. ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using
  42. ** version 3.1.1 or greater at compile time, programs may use the test
  43. ** (SQLITE_VERSION_NUMBER>=3001001).
  44. */
  45. #ifdef SQLITE_VERSION_NUMBER
  46. # undef SQLITE_VERSION_NUMBER
  47. #endif
  48. #define SQLITE_VERSION_NUMBER 3003007
  49. /*
  50. ** The version string is also compiled into the library so that a program
  51. ** can check to make sure that the lib*.a file and the *.h file are from
  52. ** the same version. The sqlite3_libversion() function returns a pointer
  53. ** to the sqlite3_version variable - useful in DLLs which cannot access
  54. ** global variables.
  55. */
  56. extern const char sqlite3_version[];
  57. const char *sqlite3_libversion(void);
  58. /*
  59. ** Return the value of the SQLITE_VERSION_NUMBER macro when the
  60. ** library was compiled.
  61. */
  62. int sqlite3_libversion_number(void);
  63. /*
  64. ** Each open sqlite database is represented by an instance of the
  65. ** following opaque structure.
  66. */
  67. typedef struct sqlite3 sqlite3;
  68. /*
  69. ** Some compilers do not support the "long long" datatype. So we have
  70. ** to do a typedef that for 64-bit integers that depends on what compiler
  71. ** is being used.
  72. */
  73. #ifdef SQLITE_INT64_TYPE
  74. typedef SQLITE_INT64_TYPE sqlite_int64;
  75. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  76. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  77. typedef __int64 sqlite_int64;
  78. typedef unsigned __int64 sqlite_uint64;
  79. #else
  80. typedef long long int sqlite_int64;
  81. typedef unsigned long long int sqlite_uint64;
  82. #endif
  83. /*
  84. ** If compiling for a processor that lacks floating point support,
  85. ** substitute integer for floating-point
  86. */
  87. #ifdef SQLITE_OMIT_FLOATING_POINT
  88. # define double sqlite_int64
  89. #endif
  90. /*
  91. ** A function to close the database.
  92. **
  93. ** Call this function with a pointer to a structure that was previously
  94. ** returned from sqlite3_open() and the corresponding database will by closed.
  95. **
  96. ** All SQL statements prepared using sqlite3_prepare() or
  97. ** sqlite3_prepare16() must be deallocated using sqlite3_finalize() before
  98. ** this routine is called. Otherwise, SQLITE_BUSY is returned and the
  99. ** database connection remains open.
  100. */
  101. int sqlite3_close(sqlite3 *);
  102. /*
  103. ** The type for a callback function.
  104. */
  105. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  106. /*
  107. ** A function to executes one or more statements of SQL.
  108. **
  109. ** If one or more of the SQL statements are queries, then
  110. ** the callback function specified by the 3rd parameter is
  111. ** invoked once for each row of the query result. This callback
  112. ** should normally return 0. If the callback returns a non-zero
  113. ** value then the query is aborted, all subsequent SQL statements
  114. ** are skipped and the sqlite3_exec() function returns the SQLITE_ABORT.
  115. **
  116. ** The 4th parameter is an arbitrary pointer that is passed
  117. ** to the callback function as its first parameter.
  118. **
  119. ** The 2nd parameter to the callback function is the number of
  120. ** columns in the query result. The 3rd parameter to the callback
  121. ** is an array of strings holding the values for each column.
  122. ** The 4th parameter to the callback is an array of strings holding
  123. ** the names of each column.
  124. **
  125. ** The callback function may be NULL, even for queries. A NULL
  126. ** callback is not an error. It just means that no callback
  127. ** will be invoked.
  128. **
  129. ** If an error occurs while parsing or evaluating the SQL (but
  130. ** not while executing the callback) then an appropriate error
  131. ** message is written into memory obtained from malloc() and
  132. ** *errmsg is made to point to that message. The calling function
  133. ** is responsible for freeing the memory that holds the error
  134. ** message. Use sqlite3_free() for this. If errmsg==NULL,
  135. ** then no error message is ever written.
  136. **
  137. ** The return value is is SQLITE_OK if there are no errors and
  138. ** some other return code if there is an error. The particular
  139. ** return value depends on the type of error.
  140. **
  141. ** If the query could not be executed because a database file is
  142. ** locked or busy, then this function returns SQLITE_BUSY. (This
  143. ** behavior can be modified somewhat using the sqlite3_busy_handler()
  144. ** and sqlite3_busy_timeout() functions below.)
  145. */
  146. int sqlite3_exec(
  147. sqlite3*, /* An open database */
  148. const char *sql, /* SQL to be executed */
  149. sqlite3_callback, /* Callback function */
  150. void *, /* 1st argument to callback function */
  151. char **errmsg /* Error msg written here */
  152. );
  153. /*
  154. ** Return values for sqlite3_exec() and sqlite3_step()
  155. */
  156. #define SQLITE_OK 0 /* Successful result */
  157. /* beginning-of-error-codes */
  158. #define SQLITE_ERROR 1 /* SQL error or missing database */
  159. #define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
  160. #define SQLITE_PERM 3 /* Access permission denied */
  161. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  162. #define SQLITE_BUSY 5 /* The database file is locked */
  163. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  164. #define SQLITE_NOMEM 7 /* A malloc() failed */
  165. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  166. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  167. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  168. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  169. #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
  170. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  171. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  172. #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
  173. #define SQLITE_EMPTY 16 /* Database is empty */
  174. #define SQLITE_SCHEMA 17 /* The database schema changed */
  175. #define SQLITE_TOOBIG 18 /* NOT USED. Too much data for one row */
  176. #define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
  177. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  178. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  179. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  180. #define SQLITE_AUTH 23 /* Authorization denied */
  181. #define SQLITE_FORMAT 24 /* Auxiliary database format error */
  182. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  183. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  184. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  185. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  186. /* end-of-error-codes */
  187. /*
  188. ** Each entry in an SQLite table has a unique integer key. (The key is
  189. ** the value of the INTEGER PRIMARY KEY column if there is such a column,
  190. ** otherwise the key is generated at random. The unique key is always
  191. ** available as the ROWID, OID, or _ROWID_ column.) The following routine
  192. ** returns the integer key of the most recent insert in the database.
  193. **
  194. ** This function is similar to the mysql_insert_id() function from MySQL.
  195. */
  196. sqlite_int64 sqlite3_last_insert_rowid(sqlite3*);
  197. /*
  198. ** This function returns the number of database rows that were changed
  199. ** (or inserted or deleted) by the most recent called sqlite3_exec().
  200. **
  201. ** All changes are counted, even if they were later undone by a
  202. ** ROLLBACK or ABORT. Except, changes associated with creating and
  203. ** dropping tables are not counted.
  204. **
  205. ** If a callback invokes sqlite3_exec() recursively, then the changes
  206. ** in the inner, recursive call are counted together with the changes
  207. ** in the outer call.
  208. **
  209. ** SQLite implements the command "DELETE FROM table" without a WHERE clause
  210. ** by dropping and recreating the table. (This is much faster than going
  211. ** through and deleting individual elements form the table.) Because of
  212. ** this optimization, the change count for "DELETE FROM table" will be
  213. ** zero regardless of the number of elements that were originally in the
  214. ** table. To get an accurate count of the number of rows deleted, use
  215. ** "DELETE FROM table WHERE 1" instead.
  216. */
  217. int sqlite3_changes(sqlite3*);
  218. /*
  219. ** This function returns the number of database rows that have been
  220. ** modified by INSERT, UPDATE or DELETE statements since the database handle
  221. ** was opened. This includes UPDATE, INSERT and DELETE statements executed
  222. ** as part of trigger programs. All changes are counted as soon as the
  223. ** statement that makes them is completed (when the statement handle is
  224. ** passed to sqlite3_reset() or sqlite_finalise()).
  225. **
  226. ** SQLite implements the command "DELETE FROM table" without a WHERE clause
  227. ** by dropping and recreating the table. (This is much faster than going
  228. ** through and deleting individual elements form the table.) Because of
  229. ** this optimization, the change count for "DELETE FROM table" will be
  230. ** zero regardless of the number of elements that were originally in the
  231. ** table. To get an accurate count of the number of rows deleted, use
  232. ** "DELETE FROM table WHERE 1" instead.
  233. */
  234. int sqlite3_total_changes(sqlite3*);
  235. /* This function causes any pending database operation to abort and
  236. ** return at its earliest opportunity. This routine is typically
  237. ** called in response to a user action such as pressing "Cancel"
  238. ** or Ctrl-C where the user wants a long query operation to halt
  239. ** immediately.
  240. */
  241. void sqlite3_interrupt(sqlite3*);
  242. /* These functions return true if the given input string comprises
  243. ** one or more complete SQL statements. For the sqlite3_complete() call,
  244. ** the parameter must be a nul-terminated UTF-8 string. For
  245. ** sqlite3_complete16(), a nul-terminated machine byte order UTF-16 string
  246. ** is required.
  247. **
  248. ** The algorithm is simple. If the last token other than spaces
  249. ** and comments is a semicolon, then return true. otherwise return
  250. ** false.
  251. */
  252. int sqlite3_complete(const char *sql);
  253. int sqlite3_complete16(const void *sql);
  254. /*
  255. ** This routine identifies a callback function that is invoked
  256. ** whenever an attempt is made to open a database table that is
  257. ** currently locked by another process or thread. If the busy callback
  258. ** is NULL, then sqlite3_exec() returns SQLITE_BUSY immediately if
  259. ** it finds a locked table. If the busy callback is not NULL, then
  260. ** sqlite3_exec() invokes the callback with three arguments. The
  261. ** second argument is the name of the locked table and the third
  262. ** argument is the number of times the table has been busy. If the
  263. ** busy callback returns 0, then sqlite3_exec() immediately returns
  264. ** SQLITE_BUSY. If the callback returns non-zero, then sqlite3_exec()
  265. ** tries to open the table again and the cycle repeats.
  266. **
  267. ** The default busy callback is NULL.
  268. **
  269. ** Sqlite is re-entrant, so the busy handler may start a new query.
  270. ** (It is not clear why anyone would every want to do this, but it
  271. ** is allowed, in theory.) But the busy handler may not close the
  272. ** database. Closing the database from a busy handler will delete
  273. ** data structures out from under the executing query and will
  274. ** probably result in a coredump.
  275. */
  276. int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  277. /*
  278. ** This routine sets a busy handler that sleeps for a while when a
  279. ** table is locked. The handler will sleep multiple times until
  280. ** at least "ms" milleseconds of sleeping have been done. After
  281. ** "ms" milleseconds of sleeping, the handler returns 0 which
  282. ** causes sqlite3_exec() to return SQLITE_BUSY.
  283. **
  284. ** Calling this routine with an argument less than or equal to zero
  285. ** turns off all busy handlers.
  286. */
  287. int sqlite3_busy_timeout(sqlite3*, int ms);
  288. /*
  289. ** This next routine is really just a wrapper around sqlite3_exec().
  290. ** Instead of invoking a user-supplied callback for each row of the
  291. ** result, this routine remembers each row of the result in memory
  292. ** obtained from malloc(), then returns all of the result after the
  293. ** query has finished.
  294. **
  295. ** As an example, suppose the query result where this table:
  296. **
  297. ** Name | Age
  298. ** -----------------------
  299. ** Alice | 43
  300. ** Bob | 28
  301. ** Cindy | 21
  302. **
  303. ** If the 3rd argument were &azResult then after the function returns
  304. ** azResult will contain the following data:
  305. **
  306. ** azResult[0] = "Name";
  307. ** azResult[1] = "Age";
  308. ** azResult[2] = "Alice";
  309. ** azResult[3] = "43";
  310. ** azResult[4] = "Bob";
  311. ** azResult[5] = "28";
  312. ** azResult[6] = "Cindy";
  313. ** azResult[7] = "21";
  314. **
  315. ** Notice that there is an extra row of data containing the column
  316. ** headers. But the *nrow return value is still 3. *ncolumn is
  317. ** set to 2. In general, the number of values inserted into azResult
  318. ** will be ((*nrow) + 1)*(*ncolumn).
  319. **
  320. ** After the calling function has finished using the result, it should
  321. ** pass the result data pointer to sqlite3_free_table() in order to
  322. ** release the memory that was malloc-ed. Because of the way the
  323. ** malloc() happens, the calling function must not try to call
  324. ** free() directly. Only sqlite3_free_table() is able to release
  325. ** the memory properly and safely.
  326. **
  327. ** The return value of this routine is the same as from sqlite3_exec().
  328. */
  329. int sqlite3_get_table(
  330. sqlite3*, /* An open database */
  331. const char *sql, /* SQL to be executed */
  332. char ***resultp, /* Result written to a char *[] that this points to */
  333. int *nrow, /* Number of result rows written here */
  334. int *ncolumn, /* Number of result columns written here */
  335. char **errmsg /* Error msg written here */
  336. );
  337. /*
  338. ** Call this routine to free the memory that sqlite3_get_table() allocated.
  339. */
  340. void sqlite3_free_table(char **result);
  341. /*
  342. ** The following routines are variants of the "sprintf()" from the
  343. ** standard C library. The resulting string is written into memory
  344. ** obtained from malloc() so that there is never a possiblity of buffer
  345. ** overflow. These routines also implement some additional formatting
  346. ** options that are useful for constructing SQL statements.
  347. **
  348. ** The strings returned by these routines should be freed by calling
  349. ** sqlite3_free().
  350. **
  351. ** All of the usual printf formatting options apply. In addition, there
  352. ** is a "%q" option. %q works like %s in that it substitutes a null-terminated
  353. ** string from the argument list. But %q also doubles every '\'' character.
  354. ** %q is designed for use inside a string literal. By doubling each '\''
  355. ** character it escapes that character and allows it to be inserted into
  356. ** the string.
  357. **
  358. ** For example, so some string variable contains text as follows:
  359. **
  360. ** char *zText = "It's a happy day!";
  361. **
  362. ** We can use this text in an SQL statement as follows:
  363. **
  364. ** char *z = sqlite3_mprintf("INSERT INTO TABLES('%q')", zText);
  365. ** sqlite3_exec(db, z, callback1, 0, 0);
  366. ** sqlite3_free(z);
  367. **
  368. ** Because the %q format string is used, the '\'' character in zText
  369. ** is escaped and the SQL generated is as follows:
  370. **
  371. ** INSERT INTO table1 VALUES('It''s a happy day!')
  372. **
  373. ** This is correct. Had we used %s instead of %q, the generated SQL
  374. ** would have looked like this:
  375. **
  376. ** INSERT INTO table1 VALUES('It's a happy day!');
  377. **
  378. ** This second example is an SQL syntax error. As a general rule you
  379. ** should always use %q instead of %s when inserting text into a string
  380. ** literal.
  381. */
  382. char *sqlite3_mprintf(const char*,...);
  383. char *sqlite3_vmprintf(const char*, va_list);
  384. char *sqlite3_snprintf(int,char*,const char*, ...);
  385. /*
  386. ** SQLite uses its own memory allocator. On many installations, this
  387. ** memory allocator is identical to the standard malloc()/realloc()/free()
  388. ** and can be used interchangable. On others, the implementations are
  389. ** different. For maximum portability, it is best not to mix calls
  390. ** to the standard malloc/realloc/free with the sqlite versions.
  391. */
  392. void *sqlite3_malloc(int);
  393. void *sqlite3_realloc(void*, int);
  394. void sqlite3_free(void*);
  395. #ifndef SQLITE_OMIT_AUTHORIZATION
  396. /*
  397. ** This routine registers a callback with the SQLite library. The
  398. ** callback is invoked (at compile-time, not at run-time) for each
  399. ** attempt to access a column of a table in the database. The callback
  400. ** returns SQLITE_OK if access is allowed, SQLITE_DENY if the entire
  401. ** SQL statement should be aborted with an error and SQLITE_IGNORE
  402. ** if the column should be treated as a NULL value.
  403. */
  404. int sqlite3_set_authorizer(
  405. sqlite3*,
  406. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  407. void *pUserData
  408. );
  409. #endif
  410. /*
  411. ** The second parameter to the access authorization function above will
  412. ** be one of the values below. These values signify what kind of operation
  413. ** is to be authorized. The 3rd and 4th parameters to the authorization
  414. ** function will be parameters or NULL depending on which of the following
  415. ** codes is used as the second parameter. The 5th parameter is the name
  416. ** of the database ("main", "temp", etc.) if applicable. The 6th parameter
  417. ** is the name of the inner-most trigger or view that is responsible for
  418. ** the access attempt or NULL if this access attempt is directly from
  419. ** input SQL code.
  420. **
  421. ** Arg-3 Arg-4
  422. */
  423. #define SQLITE_COPY 0 /* Table Name File Name */
  424. #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
  425. #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
  426. #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
  427. #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
  428. #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
  429. #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
  430. #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
  431. #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
  432. #define SQLITE_DELETE 9 /* Table Name NULL */
  433. #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
  434. #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
  435. #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
  436. #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
  437. #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
  438. #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
  439. #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
  440. #define SQLITE_DROP_VIEW 17 /* View Name NULL */
  441. #define SQLITE_INSERT 18 /* Table Name NULL */
  442. #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
  443. #define SQLITE_READ 20 /* Table Name Column Name */
  444. #define SQLITE_SELECT 21 /* NULL NULL */
  445. #define SQLITE_TRANSACTION 22 /* NULL NULL */
  446. #define SQLITE_UPDATE 23 /* Table Name Column Name */
  447. #define SQLITE_ATTACH 24 /* Filename NULL */
  448. #define SQLITE_DETACH 25 /* Database Name NULL */
  449. #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
  450. #define SQLITE_REINDEX 27 /* Index Name NULL */
  451. #define SQLITE_ANALYZE 28 /* Table Name NULL */
  452. #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
  453. #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
  454. /*
  455. ** The return value of the authorization function should be one of the
  456. ** following constants:
  457. */
  458. /* #define SQLITE_OK 0 // Allow access (This is actually defined above) */
  459. #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
  460. #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
  461. /*
  462. ** Register a function for tracing SQL command evaluation. The function
  463. ** registered by sqlite3_trace() is invoked at the first sqlite3_step()
  464. ** for the evaluation of an SQL statement. The function registered by
  465. ** sqlite3_profile() runs at the end of each SQL statement and includes
  466. ** information on how long that statement ran.
  467. **
  468. ** The sqlite3_profile() API is currently considered experimental and
  469. ** is subject to change.
  470. */
  471. void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  472. void *sqlite3_profile(sqlite3*,
  473. void(*xProfile)(void*,const char*,sqlite_uint64), void*);
  474. /*
  475. ** This routine configures a callback function - the progress callback - that
  476. ** is invoked periodically during long running calls to sqlite3_exec(),
  477. ** sqlite3_step() and sqlite3_get_table(). An example use for this API is to
  478. ** keep a GUI updated during a large query.
  479. **
  480. ** The progress callback is invoked once for every N virtual machine opcodes,
  481. ** where N is the second argument to this function. The progress callback
  482. ** itself is identified by the third argument to this function. The fourth
  483. ** argument to this function is a void pointer passed to the progress callback
  484. ** function each time it is invoked.
  485. **
  486. ** If a call to sqlite3_exec(), sqlite3_step() or sqlite3_get_table() results
  487. ** in less than N opcodes being executed, then the progress callback is not
  488. ** invoked.
  489. **
  490. ** To remove the progress callback altogether, pass NULL as the third
  491. ** argument to this function.
  492. **
  493. ** If the progress callback returns a result other than 0, then the current
  494. ** query is immediately terminated and any database changes rolled back. If the
  495. ** query was part of a larger transaction, then the transaction is not rolled
  496. ** back and remains active. The sqlite3_exec() call returns SQLITE_ABORT.
  497. **
  498. ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
  499. */
  500. void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  501. /*
  502. ** Register a callback function to be invoked whenever a new transaction
  503. ** is committed. The pArg argument is passed through to the callback.
  504. ** callback. If the callback function returns non-zero, then the commit
  505. ** is converted into a rollback.
  506. **
  507. ** If another function was previously registered, its pArg value is returned.
  508. ** Otherwise NULL is returned.
  509. **
  510. ** Registering a NULL function disables the callback.
  511. **
  512. ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
  513. */
  514. void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  515. /*
  516. ** Open the sqlite database file "filename". The "filename" is UTF-8
  517. ** encoded for sqlite3_open() and UTF-16 encoded in the native byte order
  518. ** for sqlite3_open16(). An sqlite3* handle is returned in *ppDb, even
  519. ** if an error occurs. If the database is opened (or created) successfully,
  520. ** then SQLITE_OK is returned. Otherwise an error code is returned. The
  521. ** sqlite3_errmsg() or sqlite3_errmsg16() routines can be used to obtain
  522. ** an English language description of the error.
  523. **
  524. ** If the database file does not exist, then a new database is created.
  525. ** The encoding for the database is UTF-8 if sqlite3_open() is called and
  526. ** UTF-16 if sqlite3_open16 is used.
  527. **
  528. ** Whether or not an error occurs when it is opened, resources associated
  529. ** with the sqlite3* handle should be released by passing it to
  530. ** sqlite3_close() when it is no longer required.
  531. */
  532. int sqlite3_open(
  533. const char *filename, /* Database filename (UTF-8) */
  534. sqlite3 **ppDb /* OUT: SQLite db handle */
  535. );
  536. int sqlite3_open16(
  537. const void *filename, /* Database filename (UTF-16) */
  538. sqlite3 **ppDb /* OUT: SQLite db handle */
  539. );
  540. /*
  541. ** Return the error code for the most recent sqlite3_* API call associated
  542. ** with sqlite3 handle 'db'. SQLITE_OK is returned if the most recent
  543. ** API call was successful.
  544. **
  545. ** Calls to many sqlite3_* functions set the error code and string returned
  546. ** by sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16()
  547. ** (overwriting the previous values). Note that calls to sqlite3_errcode(),
  548. ** sqlite3_errmsg() and sqlite3_errmsg16() themselves do not affect the
  549. ** results of future invocations.
  550. **
  551. ** Assuming no other intervening sqlite3_* API calls are made, the error
  552. ** code returned by this function is associated with the same error as
  553. ** the strings returned by sqlite3_errmsg() and sqlite3_errmsg16().
  554. */
  555. int sqlite3_errcode(sqlite3 *db);
  556. /*
  557. ** Return a pointer to a UTF-8 encoded string describing in english the
  558. ** error condition for the most recent sqlite3_* API call. The returned
  559. ** string is always terminated by an 0x00 byte.
  560. **
  561. ** The string "not an error" is returned when the most recent API call was
  562. ** successful.
  563. */
  564. const char *sqlite3_errmsg(sqlite3*);
  565. /*
  566. ** Return a pointer to a UTF-16 native byte order encoded string describing
  567. ** in english the error condition for the most recent sqlite3_* API call.
  568. ** The returned string is always terminated by a pair of 0x00 bytes.
  569. **
  570. ** The string "not an error" is returned when the most recent API call was
  571. ** successful.
  572. */
  573. const void *sqlite3_errmsg16(sqlite3*);
  574. /*
  575. ** An instance of the following opaque structure is used to represent
  576. ** a compiled SQL statment.
  577. */
  578. typedef struct sqlite3_stmt sqlite3_stmt;
  579. /*
  580. ** To execute an SQL query, it must first be compiled into a byte-code
  581. ** program using one of the following routines. The only difference between
  582. ** them is that the second argument, specifying the SQL statement to
  583. ** compile, is assumed to be encoded in UTF-8 for the sqlite3_prepare()
  584. ** function and UTF-16 for sqlite3_prepare16().
  585. **
  586. ** The first parameter "db" is an SQLite database handle. The second
  587. ** parameter "zSql" is the statement to be compiled, encoded as either
  588. ** UTF-8 or UTF-16 (see above). If the next parameter, "nBytes", is less
  589. ** than zero, then zSql is read up to the first nul terminator. If
  590. ** "nBytes" is not less than zero, then it is the length of the string zSql
  591. ** in bytes (not characters).
  592. **
  593. ** *pzTail is made to point to the first byte past the end of the first
  594. ** SQL statement in zSql. This routine only compiles the first statement
  595. ** in zSql, so *pzTail is left pointing to what remains uncompiled.
  596. **
  597. ** *ppStmt is left pointing to a compiled SQL statement that can be
  598. ** executed using sqlite3_step(). Or if there is an error, *ppStmt may be
  599. ** set to NULL. If the input text contained no SQL (if the input is and
  600. ** empty string or a comment) then *ppStmt is set to NULL.
  601. **
  602. ** On success, SQLITE_OK is returned. Otherwise an error code is returned.
  603. */
  604. int sqlite3_prepare(
  605. sqlite3 *db, /* Database handle */
  606. const char *zSql, /* SQL statement, UTF-8 encoded */
  607. int nBytes, /* Length of zSql in bytes. */
  608. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  609. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  610. );
  611. int sqlite3_prepare16(
  612. sqlite3 *db, /* Database handle */
  613. const void *zSql, /* SQL statement, UTF-16 encoded */
  614. int nBytes, /* Length of zSql in bytes. */
  615. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  616. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  617. );
  618. /*
  619. ** Pointers to the following two opaque structures are used to communicate
  620. ** with the implementations of user-defined functions.
  621. */
  622. typedef struct sqlite3_context sqlite3_context;
  623. typedef struct Mem sqlite3_value;
  624. /*
  625. ** In the SQL strings input to sqlite3_prepare() and sqlite3_prepare16(),
  626. ** one or more literals can be replace by parameters "?" or ":AAA" or
  627. ** "$VVV" where AAA is an identifer and VVV is a variable name according
  628. ** to the syntax rules of the TCL programming language.
  629. ** The value of these parameters (also called "host parameter names") can
  630. ** be set using the routines listed below.
  631. **
  632. ** In every case, the first parameter is a pointer to the sqlite3_stmt
  633. ** structure returned from sqlite3_prepare(). The second parameter is the
  634. ** index of the parameter. The first parameter as an index of 1. For
  635. ** named parameters (":AAA" or "$VVV") you can use
  636. ** sqlite3_bind_parameter_index() to get the correct index value given
  637. ** the parameters name. If the same named parameter occurs more than
  638. ** once, it is assigned the same index each time.
  639. **
  640. ** The fifth parameter to sqlite3_bind_blob(), sqlite3_bind_text(), and
  641. ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  642. ** text after SQLite has finished with it. If the fifth argument is the
  643. ** special value SQLITE_STATIC, then the library assumes that the information
  644. ** is in static, unmanaged space and does not need to be freed. If the
  645. ** fifth argument has the value SQLITE_TRANSIENT, then SQLite makes its
  646. ** own private copy of the data.
  647. **
  648. ** The sqlite3_bind_* routine must be called before sqlite3_step() after
  649. ** an sqlite3_prepare() or sqlite3_reset(). Unbound parameterss are
  650. ** interpreted as NULL.
  651. */
  652. int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  653. int sqlite3_bind_double(sqlite3_stmt*, int, double);
  654. int sqlite3_bind_int(sqlite3_stmt*, int, int);
  655. int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite_int64);
  656. int sqlite3_bind_null(sqlite3_stmt*, int);
  657. int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
  658. int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  659. int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  660. /*
  661. ** Return the number of parameters in a compiled SQL statement. This
  662. ** routine was added to support DBD::SQLite.
  663. */
  664. int sqlite3_bind_parameter_count(sqlite3_stmt*);
  665. /*
  666. ** Return the name of the i-th parameter. Ordinary parameters "?" are
  667. ** nameless and a NULL is returned. For parameters of the form :AAA or
  668. ** $VVV the complete text of the parameter name is returned, including
  669. ** the initial ":" or "$". NULL is returned if the index is out of range.
  670. */
  671. const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  672. /*
  673. ** Return the index of a parameter with the given name. The name
  674. ** must match exactly. If no parameter with the given name is found,
  675. ** return 0.
  676. */
  677. int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  678. /*
  679. ** Set all the parameters in the compiled SQL statement to NULL.
  680. */
  681. int sqlite3_clear_bindings(sqlite3_stmt*);
  682. /*
  683. ** Return the number of columns in the result set returned by the compiled
  684. ** SQL statement. This routine returns 0 if pStmt is an SQL statement
  685. ** that does not return data (for example an UPDATE).
  686. */
  687. int sqlite3_column_count(sqlite3_stmt *pStmt);
  688. /*
  689. ** The first parameter is a compiled SQL statement. This function returns
  690. ** the column heading for the Nth column of that statement, where N is the
  691. ** second function parameter. The string returned is UTF-8 for
  692. ** sqlite3_column_name() and UTF-16 for sqlite3_column_name16().
  693. */
  694. const char *sqlite3_column_name(sqlite3_stmt*,int);
  695. const void *sqlite3_column_name16(sqlite3_stmt*,int);
  696. /*
  697. ** The first parameter to the following calls is a compiled SQL statement.
  698. ** These functions return information about the Nth column returned by
  699. ** the statement, where N is the second function argument.
  700. **
  701. ** If the Nth column returned by the statement is not a column value,
  702. ** then all of the functions return NULL. Otherwise, the return the
  703. ** name of the attached database, table and column that the expression
  704. ** extracts a value from.
  705. **
  706. ** As with all other SQLite APIs, those postfixed with "16" return UTF-16
  707. ** encoded strings, the other functions return UTF-8. The memory containing
  708. ** the returned strings is valid until the statement handle is finalized().
  709. **
  710. ** These APIs are only available if the library was compiled with the
  711. ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
  712. */
  713. const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  714. const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  715. const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  716. const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  717. const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  718. const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  719. /*
  720. ** The first parameter is a compiled SQL statement. If this statement
  721. ** is a SELECT statement, the Nth column of the returned result set
  722. ** of the SELECT is a table column then the declared type of the table
  723. ** column is returned. If the Nth column of the result set is not at table
  724. ** column, then a NULL pointer is returned. The returned string is always
  725. ** UTF-8 encoded. For example, in the database schema:
  726. **
  727. ** CREATE TABLE t1(c1 VARIANT);
  728. **
  729. ** And the following statement compiled:
  730. **
  731. ** SELECT c1 + 1, c1 FROM t1;
  732. **
  733. ** Then this routine would return the string "VARIANT" for the second
  734. ** result column (i==1), and a NULL pointer for the first result column
  735. ** (i==0).
  736. */
  737. const char *sqlite3_column_decltype(sqlite3_stmt *, int i);
  738. /*
  739. ** The first parameter is a compiled SQL statement. If this statement
  740. ** is a SELECT statement, the Nth column of the returned result set
  741. ** of the SELECT is a table column then the declared type of the table
  742. ** column is returned. If the Nth column of the result set is not at table
  743. ** column, then a NULL pointer is returned. The returned string is always
  744. ** UTF-16 encoded. For example, in the database schema:
  745. **
  746. ** CREATE TABLE t1(c1 INTEGER);
  747. **
  748. ** And the following statement compiled:
  749. **
  750. ** SELECT c1 + 1, c1 FROM t1;
  751. **
  752. ** Then this routine would return the string "INTEGER" for the second
  753. ** result column (i==1), and a NULL pointer for the first result column
  754. ** (i==0).
  755. */
  756. const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  757. /*
  758. ** After an SQL query has been compiled with a call to either
  759. ** sqlite3_prepare() or sqlite3_prepare16(), then this function must be
  760. ** called one or more times to execute the statement.
  761. **
  762. ** The return value will be either SQLITE_BUSY, SQLITE_DONE,
  763. ** SQLITE_ROW, SQLITE_ERROR, or SQLITE_MISUSE.
  764. **
  765. ** SQLITE_BUSY means that the database engine attempted to open
  766. ** a locked database and there is no busy callback registered.
  767. ** Call sqlite3_step() again to retry the open.
  768. **
  769. ** SQLITE_DONE means that the statement has finished executing
  770. ** successfully. sqlite3_step() should not be called again on this virtual
  771. ** machine.
  772. **
  773. ** If the SQL statement being executed returns any data, then
  774. ** SQLITE_ROW is returned each time a new row of data is ready
  775. ** for processing by the caller. The values may be accessed using
  776. ** the sqlite3_column_*() functions described below. sqlite3_step()
  777. ** is called again to retrieve the next row of data.
  778. **
  779. ** SQLITE_ERROR means that a run-time error (such as a constraint
  780. ** violation) has occurred. sqlite3_step() should not be called again on
  781. ** the VM. More information may be found by calling sqlite3_errmsg().
  782. **
  783. ** SQLITE_MISUSE means that the this routine was called inappropriately.
  784. ** Perhaps it was called on a virtual machine that had already been
  785. ** finalized or on one that had previously returned SQLITE_ERROR or
  786. ** SQLITE_DONE. Or it could be the case the the same database connection
  787. ** is being used simulataneously by two or more threads.
  788. */
  789. int sqlite3_step(sqlite3_stmt*);
  790. /*
  791. ** Return the number of values in the current row of the result set.
  792. **
  793. ** After a call to sqlite3_step() that returns SQLITE_ROW, this routine
  794. ** will return the same value as the sqlite3_column_count() function.
  795. ** After sqlite3_step() has returned an SQLITE_DONE, SQLITE_BUSY or
  796. ** error code, or before sqlite3_step() has been called on a
  797. ** compiled SQL statement, this routine returns zero.
  798. */
  799. int sqlite3_data_count(sqlite3_stmt *pStmt);
  800. /*
  801. ** Values are stored in the database in one of the following fundamental
  802. ** types.
  803. */
  804. #define SQLITE_INTEGER 1
  805. #define SQLITE_FLOAT 2
  806. /* #define SQLITE_TEXT 3 // See below */
  807. #define SQLITE_BLOB 4
  808. #define SQLITE_NULL 5
  809. /*
  810. ** SQLite version 2 defines SQLITE_TEXT differently. To allow both
  811. ** version 2 and version 3 to be included, undefine them both if a
  812. ** conflict is seen. Define SQLITE3_TEXT to be the version 3 value.
  813. */
  814. #ifdef SQLITE_TEXT
  815. # undef SQLITE_TEXT
  816. #else
  817. # define SQLITE_TEXT 3
  818. #endif
  819. #define SQLITE3_TEXT 3
  820. /*
  821. ** The next group of routines returns information about the information
  822. ** in a single column of the current result row of a query. In every
  823. ** case the first parameter is a pointer to the SQL statement that is being
  824. ** executed (the sqlite_stmt* that was returned from sqlite3_prepare()) and
  825. ** the second argument is the index of the column for which information
  826. ** should be returned. iCol is zero-indexed. The left-most column as an
  827. ** index of 0.
  828. **
  829. ** If the SQL statement is not currently point to a valid row, or if the
  830. ** the colulmn index is out of range, the result is undefined.
  831. **
  832. ** These routines attempt to convert the value where appropriate. For
  833. ** example, if the internal representation is FLOAT and a text result
  834. ** is requested, sprintf() is used internally to do the conversion
  835. ** automatically. The following table details the conversions that
  836. ** are applied:
  837. **
  838. ** Internal Type Requested Type Conversion
  839. ** ------------- -------------- --------------------------
  840. ** NULL INTEGER Result is 0
  841. ** NULL FLOAT Result is 0.0
  842. ** NULL TEXT Result is an empty string
  843. ** NULL BLOB Result is a zero-length BLOB
  844. ** INTEGER FLOAT Convert from integer to float
  845. ** INTEGER TEXT ASCII rendering of the integer
  846. ** INTEGER BLOB Same as for INTEGER->TEXT
  847. ** FLOAT INTEGER Convert from float to integer
  848. ** FLOAT TEXT ASCII rendering of the float
  849. ** FLOAT BLOB Same as FLOAT->TEXT
  850. ** TEXT INTEGER Use atoi()
  851. ** TEXT FLOAT Use atof()
  852. ** TEXT BLOB No change
  853. ** BLOB INTEGER Convert to TEXT then use atoi()
  854. ** BLOB FLOAT Convert to TEXT then use atof()
  855. ** BLOB TEXT Add a \000 terminator if needed
  856. **
  857. ** The following access routines are provided:
  858. **
  859. ** _type() Return the datatype of the result. This is one of
  860. ** SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB,
  861. ** or SQLITE_NULL.
  862. ** _blob() Return the value of a BLOB.
  863. ** _bytes() Return the number of bytes in a BLOB value or the number
  864. ** of bytes in a TEXT value represented as UTF-8. The \000
  865. ** terminator is included in the byte count for TEXT values.
  866. ** _bytes16() Return the number of bytes in a BLOB value or the number
  867. ** of bytes in a TEXT value represented as UTF-16. The \u0000
  868. ** terminator is included in the byte count for TEXT values.
  869. ** _double() Return a FLOAT value.
  870. ** _int() Return an INTEGER value in the host computer's native
  871. ** integer representation. This might be either a 32- or 64-bit
  872. ** integer depending on the host.
  873. ** _int64() Return an INTEGER value as a 64-bit signed integer.
  874. ** _text() Return the value as UTF-8 text.
  875. ** _text16() Return the value as UTF-16 text.
  876. */
  877. const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  878. int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  879. int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  880. double sqlite3_column_double(sqlite3_stmt*, int iCol);
  881. int sqlite3_column_int(sqlite3_stmt*, int iCol);
  882. sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  883. const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  884. const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  885. int sqlite3_column_type(sqlite3_stmt*, int iCol);
  886. int sqlite3_column_numeric_type(sqlite3_stmt*, int iCol);
  887. sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  888. /*
  889. ** The sqlite3_finalize() function is called to delete a compiled
  890. ** SQL statement obtained by a previous call to sqlite3_prepare()
  891. ** or sqlite3_prepare16(). If the statement was executed successfully, or
  892. ** not executed at all, then SQLITE_OK is returned. If execution of the
  893. ** statement failed then an error code is returned.
  894. **
  895. ** This routine can be called at any point during the execution of the
  896. ** virtual machine. If the virtual machine has not completed execution
  897. ** when this routine is called, that is like encountering an error or
  898. ** an interrupt. (See sqlite3_interrupt().) Incomplete updates may be
  899. ** rolled back and transactions cancelled, depending on the circumstances,
  900. ** and the result code returned will be SQLITE_ABORT.
  901. */
  902. int sqlite3_finalize(sqlite3_stmt *pStmt);
  903. /*
  904. ** The sqlite3_reset() function is called to reset a compiled SQL
  905. ** statement obtained by a previous call to sqlite3_prepare() or
  906. ** sqlite3_prepare16() back to it's initial state, ready to be re-executed.
  907. ** Any SQL statement variables that had values bound to them using
  908. ** the sqlite3_bind_*() API retain their values.
  909. */
  910. int sqlite3_reset(sqlite3_stmt *pStmt);
  911. /*
  912. ** The following two functions are used to add user functions or aggregates
  913. ** implemented in C to the SQL langauge interpreted by SQLite. The
  914. ** difference only between the two is that the second parameter, the
  915. ** name of the (scalar) function or aggregate, is encoded in UTF-8 for
  916. ** sqlite3_create_function() and UTF-16 for sqlite3_create_function16().
  917. **
  918. ** The first argument is the database handle that the new function or
  919. ** aggregate is to be added to. If a single program uses more than one
  920. ** database handle internally, then user functions or aggregates must
  921. ** be added individually to each database handle with which they will be
  922. ** used.
  923. **
  924. ** The third parameter is the number of arguments that the function or
  925. ** aggregate takes. If this parameter is negative, then the function or
  926. ** aggregate may take any number of arguments.
  927. **
  928. ** The fourth parameter is one of SQLITE_UTF* values defined below,
  929. ** indicating the encoding that the function is most likely to handle
  930. ** values in. This does not change the behaviour of the programming
  931. ** interface. However, if two versions of the same function are registered
  932. ** with different encoding values, SQLite invokes the version likely to
  933. ** minimize conversions between text encodings.
  934. **
  935. ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
  936. ** pointers to user implemented C functions that implement the user
  937. ** function or aggregate. A scalar function requires an implementation of
  938. ** the xFunc callback only, NULL pointers should be passed as the xStep
  939. ** and xFinal parameters. An aggregate function requires an implementation
  940. ** of xStep and xFinal, but NULL should be passed for xFunc. To delete an
  941. ** existing user function or aggregate, pass NULL for all three function
  942. ** callback. Specifying an inconstent set of callback values, such as an
  943. ** xFunc and an xFinal, or an xStep but no xFinal, SQLITE_ERROR is
  944. ** returned.
  945. */
  946. int sqlite3_create_function(
  947. sqlite3 *,
  948. const char *zFunctionName,
  949. int nArg,
  950. int eTextRep,
  951. void*,
  952. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  953. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  954. void (*xFinal)(sqlite3_context*)
  955. );
  956. int sqlite3_create_function16(
  957. sqlite3*,
  958. const void *zFunctionName,
  959. int nArg,
  960. int eTextRep,
  961. void*,
  962. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  963. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  964. void (*xFinal)(sqlite3_context*)
  965. );
  966. /*
  967. ** This function is deprecated. Do not use it. It continues to exist
  968. ** so as not to break legacy code. But new code should avoid using it.
  969. */
  970. int sqlite3_aggregate_count(sqlite3_context*);
  971. /*
  972. ** The next group of routines returns information about parameters to
  973. ** a user-defined function. Function implementations use these routines
  974. ** to access their parameters. These routines are the same as the
  975. ** sqlite3_column_* routines except that these routines take a single
  976. ** sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  977. ** column number.
  978. */
  979. const void *sqlite3_value_blob(sqlite3_value*);
  980. int sqlite3_value_bytes(sqlite3_value*);
  981. int sqlite3_value_bytes16(sqlite3_value*);
  982. double sqlite3_value_double(sqlite3_value*);
  983. int sqlite3_value_int(sqlite3_value*);
  984. sqlite_int64 sqlite3_value_int64(sqlite3_value*);
  985. const unsigned char *sqlite3_value_text(sqlite3_value*);
  986. const void *sqlite3_value_text16(sqlite3_value*);
  987. const void *sqlite3_value_text16le(sqlite3_value*);
  988. const void *sqlite3_value_text16be(sqlite3_value*);
  989. int sqlite3_value_type(sqlite3_value*);
  990. int sqlite3_value_numeric_type(sqlite3_value*);
  991. /*
  992. ** Aggregate functions use the following routine to allocate
  993. ** a structure for storing their state. The first time this routine
  994. ** is called for a particular aggregate, a new structure of size nBytes
  995. ** is allocated, zeroed, and returned. On subsequent calls (for the
  996. ** same aggregate instance) the same buffer is returned. The implementation
  997. ** of the aggregate can use the returned buffer to accumulate data.
  998. **
  999. ** The buffer allocated is freed automatically by SQLite.
  1000. */
  1001. void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  1002. /*
  1003. ** The pUserData parameter to the sqlite3_create_function()
  1004. ** routine used to register user functions is available to
  1005. ** the implementation of the function using this call.
  1006. */
  1007. void *sqlite3_user_data(sqlite3_context*);
  1008. /*
  1009. ** The following two functions may be used by scalar user functions to
  1010. ** associate meta-data with argument values. If the same value is passed to
  1011. ** multiple invocations of the user-function during query execution, under
  1012. ** some circumstances the associated meta-data may be preserved. This may
  1013. ** be used, for example, to add a regular-expression matching scalar
  1014. ** function. The compiled version of the regular expression is stored as
  1015. ** meta-data associated with the SQL value passed as the regular expression
  1016. ** pattern.
  1017. **
  1018. ** Calling sqlite3_get_auxdata() returns a pointer to the meta data
  1019. ** associated with the Nth argument value to the current user function
  1020. ** call, where N is the second parameter. If no meta-data has been set for
  1021. ** that value, then a NULL pointer is returned.
  1022. **
  1023. ** The sqlite3_set_auxdata() is used to associate meta data with a user
  1024. ** function argument. The third parameter is a pointer to the meta data
  1025. ** to be associated with the Nth user function argument value. The fourth
  1026. ** parameter specifies a 'delete function' that will be called on the meta
  1027. ** data pointer to release it when it is no longer required. If the delete
  1028. ** function pointer is NULL, it is not invoked.
  1029. **
  1030. ** In practice, meta-data is preserved between function calls for
  1031. ** expressions that are constant at compile time. This includes literal
  1032. ** values and SQL variables.
  1033. */
  1034. void *sqlite3_get_auxdata(sqlite3_context*, int);
  1035. void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));
  1036. /*
  1037. ** These are special value for the destructor that is passed in as the
  1038. ** final argument to routines like sqlite3_result_blob(). If the destructor
  1039. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  1040. ** and will never change. It does not need to be destroyed. The
  1041. ** SQLITE_TRANSIENT value means that the content will likely change in
  1042. ** the near future and that SQLite should make its own private copy of
  1043. ** the content before returning.
  1044. */
  1045. #define SQLITE_STATIC ((void(*)(void *))0)
  1046. #define SQLITE_TRANSIENT ((void(*)(void *))-1)
  1047. /*
  1048. ** User-defined functions invoke the following routines in order to
  1049. ** set their return value.
  1050. */
  1051. void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  1052. void sqlite3_result_double(sqlite3_context*, double);
  1053. void sqlite3_result_error(sqlite3_context*, const char*, int);
  1054. void sqlite3_result_error16(sqlite3_context*, const void*, int);
  1055. void sqlite3_result_int(sqlite3_context*, int);
  1056. void sqlite3_result_int64(sqlite3_context*, sqlite_int64);
  1057. void sqlite3_result_null(sqlite3_context*);
  1058. void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  1059. void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  1060. void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  1061. void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  1062. void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  1063. /*
  1064. ** These are the allowed values for the eTextRep argument to
  1065. ** sqlite3_create_collation and sqlite3_create_function.
  1066. */
  1067. #define SQLITE_UTF8 1
  1068. #define SQLITE_UTF16LE 2
  1069. #define SQLITE_UTF16BE 3
  1070. #define SQLITE_UTF16 4 /* Use native byte order */
  1071. #define SQLITE_ANY 5 /* sqlite3_create_function only */
  1072. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  1073. /*
  1074. ** These two functions are used to add new collation sequences to the
  1075. ** sqlite3 handle specified as the first argument.
  1076. **
  1077. ** The name of the new collation sequence is specified as a UTF-8 string
  1078. ** for sqlite3_create_collation() and a UTF-16 string for
  1079. ** sqlite3_create_collation16(). In both cases the name is passed as the
  1080. ** second function argument.
  1081. **
  1082. ** The third argument must be one of the constants SQLITE_UTF8,
  1083. ** SQLITE_UTF16LE or SQLITE_UTF16BE, indicating that the user-supplied
  1084. ** routine expects to be passed pointers to strings encoded using UTF-8,
  1085. ** UTF-16 little-endian or UTF-16 big-endian respectively.
  1086. **
  1087. ** A pointer to the user supplied routine must be passed as the fifth
  1088. ** argument. If it is NULL, this is the same as deleting the collation
  1089. ** sequence (so that SQLite cannot call it anymore). Each time the user
  1090. ** supplied function is invoked, it is passed a copy of the void* passed as
  1091. ** the fourth argument to sqlite3_create_collation() or
  1092. ** sqlite3_create_collation16() as its first parameter.
  1093. **
  1094. ** The remaining arguments to the user-supplied routine are two strings,
  1095. ** each represented by a [length, data] pair and encoded in the encoding
  1096. ** that was passed as the third argument when the collation sequence was
  1097. ** registered. The user routine should return negative, zero or positive if
  1098. ** the first string is less than, equal to, or greater than the second
  1099. ** string. i.e. (STRING1 - STRING2).
  1100. */
  1101. int sqlite3_create_collation(
  1102. sqlite3*,
  1103. const char *zName,
  1104. int eTextRep,
  1105. void*,
  1106. int(*xCompare)(void*,int,const void*,int,const void*)
  1107. );
  1108. int sqlite3_create_collation16(
  1109. sqlite3*,
  1110. const char *zName,
  1111. int eTextRep,
  1112. void*,
  1113. int(*xCompare)(void*,int,const void*,int,const void*)
  1114. );
  1115. /*
  1116. ** To avoid having to register all collation sequences before a database
  1117. ** can be used, a single callback function may be registered with the
  1118. ** database handle to be called whenever an undefined collation sequence is
  1119. ** required.
  1120. **
  1121. ** If the function is registered using the sqlite3_collation_needed() API,
  1122. ** then it is passed the names of undefined collation sequences as strings
  1123. ** encoded in UTF-8. If sqlite3_collation_needed16() is used, the names
  1124. ** are passed as UTF-16 in machine native byte order. A call to either
  1125. ** function replaces any existing callback.
  1126. **
  1127. ** When the user-function is invoked, the first argument passed is a copy
  1128. ** of the second argument to sqlite3_collation_needed() or
  1129. ** sqlite3_collation_needed16(). The second argument is the database
  1130. ** handle. The third argument is one of SQLITE_UTF8, SQLITE_UTF16BE or
  1131. ** SQLITE_UTF16LE, indicating the most desirable form of the collation
  1132. ** sequence function required. The fourth parameter is the name of the
  1133. ** required collation sequence.
  1134. **
  1135. ** The collation sequence is returned to SQLite by a collation-needed
  1136. ** callback using the sqlite3_create_collation() or
  1137. ** sqlite3_create_collation16() APIs, described above.
  1138. */
  1139. int sqlite3_collation_needed(
  1140. sqlite3*,
  1141. void*,
  1142. void(*)(void*,sqlite3*,int eTextRep,const char*)
  1143. );
  1144. int sqlite3_collation_needed16(
  1145. sqlite3*,
  1146. void*,
  1147. void(*)(void*,sqlite3*,int eTextRep,const void*)
  1148. );
  1149. /*
  1150. ** Specify the key for an encrypted database. This routine should be
  1151. ** called right after sqlite3_open().
  1152. **
  1153. ** The code to implement this API is not available in the public release
  1154. ** of SQLite.
  1155. */
  1156. int sqlite3_key(
  1157. sqlite3 *db, /* Database to be rekeyed */
  1158. const void *pKey, int nKey /* The key */
  1159. );
  1160. /*
  1161. ** Change the key on an open database. If the current database is not
  1162. ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
  1163. ** database is decrypted.
  1164. **
  1165. ** The code to implement this API is not available in the public release
  1166. ** of SQLite.
  1167. */
  1168. int sqlite3_rekey(
  1169. sqlite3 *db, /* Database to be rekeyed */
  1170. const void *pKey, int nKey /* The new key */
  1171. );
  1172. /*
  1173. ** Sleep for a little while. The second parameter is the number of
  1174. ** miliseconds to sleep for.
  1175. **
  1176. ** If the operating system does not support sleep requests with
  1177. ** milisecond time resolution, then the time will be rounded up to
  1178. ** the nearest second. The number of miliseconds of sleep actually
  1179. ** requested from the operating system is returned.
  1180. */
  1181. int sqlite3_sleep(int);
  1182. /*
  1183. ** Return TRUE (non-zero) if the statement supplied as an argument needs
  1184. ** to be recompiled. A statement needs to be recompiled whenever the
  1185. ** execution environment changes in a way that would alter the program
  1186. ** that sqlite3_prepare() generates. For example, if new functions or
  1187. ** collating sequences are registered or if an authorizer function is
  1188. ** added or changed.
  1189. **
  1190. */
  1191. int sqlite3_expired(sqlite3_stmt*);
  1192. /*
  1193. ** Move all bindings from the first prepared statement over to the second.
  1194. ** This routine is useful, for example, if the first prepared statement
  1195. ** fails with an SQLITE_SCHEMA error. The same SQL can be prepared into
  1196. ** the second prepared statement then all of the bindings transfered over
  1197. ** to the second statement before the first statement is finalized.
  1198. */
  1199. int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  1200. /*
  1201. ** If the following global variable is made to point to a
  1202. ** string which is the name of a directory, then all temporary files
  1203. ** created by SQLite will be placed in that directory. If this variable
  1204. ** is NULL pointer, then SQLite does a search for an appropriate temporary
  1205. ** file directory.
  1206. **
  1207. ** Once sqlite3_open() has been called, changing this variable will invalidate
  1208. ** the current temporary database, if any.
  1209. */
  1210. extern char *sqlite3_temp_directory;
  1211. /*
  1212. ** This function is called to recover from a malloc() failure that occured
  1213. ** within the SQLite library. Normally, after a single malloc() fails the
  1214. ** library refuses to function (all major calls return SQLITE_NOMEM).
  1215. ** This function restores the library state so that it can be used again.
  1216. **
  1217. ** All existing statements (sqlite3_stmt pointers) must be finalized or
  1218. ** reset before this call is made. Otherwise, SQLITE_BUSY is returned.
  1219. ** If any in-memory databases are in use, either as a main or TEMP
  1220. ** database, SQLITE_ERROR is returned. In either of these cases, the
  1221. ** library is not reset and remains unusable.
  1222. **
  1223. ** This function is *not* threadsafe. Calling this from within a threaded
  1224. ** application when threads other than the caller have used SQLite is
  1225. ** dangerous and will almost certainly result in malfunctions.
  1226. **
  1227. ** This functionality can be omitted from a build by defining the
  1228. ** SQLITE_OMIT_GLOBALRECOVER at compile time.
  1229. */
  1230. int sqlite3_global_recover(void);
  1231. /*
  1232. ** Test to see whether or not the database connection is in autocommit
  1233. ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
  1234. ** by default. Autocommit is disabled by a BEGIN statement and reenabled
  1235. ** by the next COMMIT or ROLLBACK.
  1236. */
  1237. int sqlite3_get_autocommit(sqlite3*);
  1238. /*
  1239. ** Return the sqlite3* database handle to which the prepared statement given
  1240. ** in the argument belongs. This is the same database handle that was
  1241. ** the first argument to the sqlite3_prepare() that was used to create
  1242. ** the statement in the first place.
  1243. */
  1244. sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  1245. /*
  1246. ** Register a callback function with the database connection identified by the
  1247. ** first argument to be invoked whenever a row is updated, inserted or deleted.
  1248. ** Any callback set by a previous call to this function for the same
  1249. ** database connection is overridden.
  1250. **
  1251. ** The second argument is a pointer to the function to invoke when a
  1252. ** row is updated, inserted or deleted. The first argument to the callback is
  1253. ** a copy of the third argument to sqlite3_update_hook. The second callback
  1254. ** argument is one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE, depending
  1255. ** on the operation that caused the callback to be invoked. The third and
  1256. ** fourth arguments to the callback contain pointers to the database and
  1257. ** table name containing the affected row. The final callback parameter is
  1258. ** the rowid of the row. In the case of an update, this is the rowid after
  1259. ** the update takes place.
  1260. **
  1261. ** The update hook is not invoked when internal system tables are
  1262. ** modified (i.e. sqlite_master and sqlite_sequence).
  1263. **
  1264. ** If another function was previously registered, its pArg value is returned.
  1265. ** Otherwise NULL is returned.
  1266. */
  1267. void *sqlite3_update_hook(
  1268. sqlite3*,
  1269. void(*)(void *,int ,char const *,char const *,sqlite_int64),
  1270. void*
  1271. );
  1272. /*
  1273. ** Register a callback to be invoked whenever a transaction is rolled
  1274. ** back.
  1275. **
  1276. ** The new callback function overrides any existing rollback-hook
  1277. ** callback. If there was an existing callback, then it's pArg value
  1278. ** (the third argument to sqlite3_rollback_hook() when it was registered)
  1279. ** is returned. Otherwise, NULL is returned.
  1280. **
  1281. ** For the purposes of this API, a transaction is said to have been
  1282. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  1283. ** an error or constraint causes an implicit rollback to occur. The
  1284. ** callback is not invoked if a transaction is automatically rolled
  1285. ** back because the database connection is closed.
  1286. */
  1287. void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  1288. /*
  1289. ** This function is only available if the library is compiled without
  1290. ** the SQLITE_OMIT_SHARED_CACHE macro defined. It is used to enable or
  1291. ** disable (if the argument is true or false, respectively) the
  1292. ** "shared pager" feature.
  1293. */
  1294. int sqlite3_enable_shared_cache(int);
  1295. /*
  1296. ** Attempt to free N bytes of heap memory by deallocating non-essential
  1297. ** memory allocations held by the database library (example: memory
  1298. ** used to cache database pages to improve performance).
  1299. **
  1300. ** This function is not a part of standard builds. It is only created
  1301. ** if SQLite is compiled with the SQLITE_ENABLE_MEMORY_MANAGEMENT macro.
  1302. */
  1303. int sqlite3_release_memory(int);
  1304. /*
  1305. ** Place a "soft" limit on the amount of heap memory that may be allocated by
  1306. ** SQLite within the current thread. If an internal allocation is requested
  1307. ** that would exceed the specified limit, sqlite3_release_memory() is invoked
  1308. ** one or more times to free up some space before the allocation is made.
  1309. **
  1310. ** The limit is called "soft", because if sqlite3_release_memory() cannot free
  1311. ** sufficient memory to prevent the limit from being exceeded, the memory is
  1312. ** allocated anyway and the current operation proceeds.
  1313. **
  1314. ** This function is only available if the library was compiled with the
  1315. ** SQLITE_ENABLE_MEMORY_MANAGEMENT option set.
  1316. ** memory-management has been enabled.
  1317. */
  1318. void sqlite3_soft_heap_limit(int);
  1319. /*
  1320. ** This routine makes sure that all thread-local storage has been
  1321. ** deallocated for the current thread.
  1322. **
  1323. ** This routine is not technically necessary. All thread-local storage
  1324. ** will be automatically deallocated once memory-management and
  1325. ** shared-cache are disabled and the soft heap limit has been set
  1326. ** to zero. This routine is provided as a convenience for users who
  1327. ** want to make absolutely sure they have not forgotten something
  1328. ** prior to killing off a thread.
  1329. */
  1330. void sqlite3_thread_cleanup(void);
  1331. /*
  1332. ** Return meta information about a specific column of a specific database
  1333. ** table accessible using the connection handle passed as the first function
  1334. ** argument.
  1335. **
  1336. ** The column is identified by the second, third and fourth parameters to
  1337. ** this function. The second parameter is either the name of the database
  1338. ** (i.e. "main", "temp" or an attached database) containing the specified
  1339. ** table or NULL. If it is NULL, then all attached databases are searched
  1340. ** for the table using the same algorithm as the database engine uses to
  1341. ** resolve unqualified table references.
  1342. **
  1343. ** The third and fourth parameters to this function are the table and column
  1344. ** name of the desired column, respectively. Neither of these parameters
  1345. ** may be NULL.
  1346. **
  1347. ** Meta information is returned by writing to the memory locations passed as
  1348. ** the 5th and subsequent parameters to this function. Any of these
  1349. ** arguments may be NULL, in which case the corresponding element of meta
  1350. ** information is ommitted.
  1351. **
  1352. ** Parameter Output Type Description
  1353. ** -----------------------------------
  1354. **
  1355. ** 5th const char* Data type
  1356. ** 6th const char* Name of the default collation sequence
  1357. ** 7th int True if the column has a NOT NULL constraint
  1358. ** 8th int True if the column is part of the PRIMARY KEY
  1359. ** 9th int True if the column is AUTOINCREMENT
  1360. **
  1361. **
  1362. ** The memory pointed to by the character pointers returned for the
  1363. ** declaration type and collation sequence is valid only until the next
  1364. ** call to any sqlite API function.
  1365. **
  1366. ** If the specified table is actually a view, then an error is returned.
  1367. **
  1368. ** If the specified column is "rowid", "oid" or "_rowid_" and an
  1369. ** INTEGER PRIMARY KEY column has been explicitly declared, then the output
  1370. ** parameters are set for the explicitly declared column. If there is no
  1371. ** explicitly declared IPK column, then the output parameters are set as
  1372. ** follows:
  1373. **
  1374. ** data type: "INTEGER"
  1375. ** collation sequence: "BINARY"
  1376. ** not null: 0
  1377. ** primary key: 1
  1378. ** auto increment: 0
  1379. **
  1380. ** This function may load one or more schemas from database files. If an
  1381. ** error occurs during this process, or if the requested table or column
  1382. ** cannot be found, an SQLITE error code is returned and an error message
  1383. ** left in the database handle (to be retrieved using sqlite3_errmsg()).
  1384. **
  1385. ** This API is only available if the library was compiled with the
  1386. ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
  1387. */
  1388. int sqlite3_table_column_metadata(
  1389. sqlite3 *db, /* Connection handle */
  1390. const char *zDbName, /* Database name or NULL */
  1391. const char *zTableName, /* Table name */
  1392. const char *zColumnName, /* Column name */
  1393. char const **pzDataType, /* OUTPUT: Declared data type */
  1394. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  1395. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  1396. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  1397. int *pAutoinc /* OUTPUT: True if colums is auto-increment */
  1398. );
  1399. /*
  1400. ****** EXPERIMENTAL - subject to change without notice **************
  1401. **
  1402. ** Attempt to load an SQLite extension library contained in the file
  1403. ** zFile. The entry point is zProc. zProc may be 0 in which case the
  1404. ** name of the entry point defaults to "sqlite3_extension_init".
  1405. **
  1406. ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
  1407. **
  1408. ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
  1409. ** error message text. The calling function should free this memory
  1410. ** by calling sqlite3_free().
  1411. **
  1412. ** Extension loading must be enabled using sqlite3_enable_load_extension()
  1413. ** prior to calling this API or an error will be returned.
  1414. **
  1415. ****** EXPERIMENTAL - subject to change without notice **************
  1416. */
  1417. int sqlite3_load_extension(
  1418. sqlite3 *db, /* Load the extension into this database connection */
  1419. const char *zFile, /* Name of the shared library containing extension */
  1420. const char *zProc, /* Entry point. Derived from zFile if 0 */
  1421. char **pzErrMsg /* Put error message here if not 0 */
  1422. );
  1423. /*
  1424. ** So as not to open security holes in older applications that are
  1425. ** unprepared to deal with extension load, and as a means of disabling
  1426. ** extension loading while executing user-entered SQL, the following
  1427. ** API is provided to turn the extension loading mechanism on and
  1428. ** off. It is off by default. See ticket #1863.
  1429. **
  1430. ** Call this routine with onoff==1 to turn extension loading on
  1431. ** and call it with onoff==0 to turn it back off again.
  1432. */
  1433. int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  1434. /*
  1435. ****** EXPERIMENTAL - subject to change without notice **************
  1436. **
  1437. ** The interface to the virtual-table mechanism is currently considered
  1438. ** to be experimental. The interface might change in incompatible ways.
  1439. ** If this is a problem for you, do not use the interface at this time.
  1440. **
  1441. ** When the virtual-table mechanism stablizes, we will declare the
  1442. ** interface fixed, support it indefinitely, and remove this comment.
  1443. */
  1444. /*
  1445. ** Structures used by the virtual table interface
  1446. */
  1447. typedef struct sqlite3_vtab sqlite3_vtab;
  1448. typedef struct sqlite3_index_info sqlite3_index_info;
  1449. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  1450. typedef struct sqlite3_module sqlite3_module;
  1451. /*
  1452. ** A module is a class of virtual tables. Each module is defined
  1453. ** by an instance of the following structure. This structure consists
  1454. ** mostly of methods for the module.
  1455. */
  1456. struct sqlite3_module {
  1457. int iVersion;
  1458. int (*xCreate)(sqlite3*, void *pAux,
  1459. int argc, char **argv,
  1460. sqlite3_vtab **ppVTab);
  1461. int (*xConnect)(sqlite3*, void *pAux,
  1462. int argc, char **argv,
  1463. sqlite3_vtab **ppVTab);
  1464. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  1465. int (*xDisconnect)(sqlite3_vtab *pVTab);
  1466. int (*xDestroy)(sqlite3_vtab *pVTab);
  1467. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  1468. int (*xClose)(sqlite3_vtab_cursor*);
  1469. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  1470. int argc, sqlite3_value **argv);
  1471. int (*xNext)(sqlite3_vtab_cursor*);
  1472. int (*xEof)(sqlite3_vtab_cursor*);
  1473. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  1474. int (*xRowid)(sqlite3_vtab_cursor*, sqlite_int64 *pRowid);
  1475. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite_int64 *);
  1476. int (*xBegin)(sqlite3_vtab *pVTab);
  1477. int (*xSync)(sqlite3_vtab *pVTab);
  1478. int (*xCommit)(sqlite3_vtab *pVTab);
  1479. int (*xRollback)(sqlite3_vtab *pVTab);
  1480. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  1481. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  1482. void **ppArg);
  1483. };
  1484. /*
  1485. ** The sqlite3_index_info structure and its substructures is used to
  1486. ** pass information into and receive the reply from the xBestIndex
  1487. ** method of an sqlite3_module. The fields under **Inputs** are the
  1488. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  1489. ** results into the **Outputs** fields.
  1490. **
  1491. ** The aConstraint[] array records WHERE clause constraints of the
  1492. ** form:
  1493. **
  1494. ** column OP expr
  1495. **
  1496. ** Where OP is =, <, <=, >, or >=. The particular operator is stored
  1497. ** in aConstraint[].op. The index of the column is stored in
  1498. ** aConstraint[].iColumn. aConstraint[].usable is TRUE if the
  1499. ** expr on the right-hand side can be evaluated (and thus the constraint
  1500. ** is usable) and false if it cannot.
  1501. **
  1502. ** The optimizer automatically inverts terms of the form "expr OP column"
  1503. ** and makes other simplificatinos to the WHERE clause in an attempt to
  1504. ** get as many WHERE clause terms into the form shown above as possible.
  1505. ** The aConstraint[] array only reports WHERE clause terms in the correct
  1506. ** form that refer to the particular virtual table being queried.
  1507. **
  1508. ** Information about the ORDER BY clause is stored in aOrderBy[].
  1509. ** Each term of aOrderBy records a column of the ORDER BY clause.
  1510. **
  1511. ** The xBestIndex method must fill aConstraintUsage[] with information
  1512. ** about what parameters to pass to xFilter. If argvIndex>0 then
  1513. ** the right-hand side of the corresponding aConstraint[] is evaluated
  1514. ** and becomes the argvIndex-th entry in argv. If aConstraintUsage[].omit
  1515. ** is true, then the constraint is assumed to be fully handled by the
  1516. ** virtual table and is not checked again by SQLite.
  1517. **
  1518. ** The idxNum and idxPtr values are recorded and passed into xFilter.
  1519. ** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
  1520. **
  1521. ** The orderByConsumed means that output from xFilter will occur in
  1522. ** the correct order to satisfy the ORDER BY clause so that no separate
  1523. ** sorting step is required.
  1524. **
  1525. ** The estimatedCost value is an estimate of the cost of doing the
  1526. ** particular lookup. A full scan of a table with N entries should have
  1527. ** a cost of N. A binary search of a table of N entries should have a
  1528. ** cost of approximately log(N).
  1529. */
  1530. struct sqlite3_index_info {
  1531. /* Inputs */
  1532. const int nConstraint; /* Number of entries in aConstraint */
  1533. const struct sqlite3_index_constraint {
  1534. int iColumn; /* Column on left-hand side of constraint */
  1535. unsigned char op; /* Constraint operator */
  1536. unsigned char usable; /* True if this constraint is usable */
  1537. int iTermOffset; /* Used internally - xBestIndex should ignore */
  1538. } *const aConstraint; /* Table of WHERE clause constraints */
  1539. const int nOrderBy; /* Number of terms in the ORDER BY clause */
  1540. const struct sqlite3_index_orderby {
  1541. int iColumn; /* Column number */
  1542. unsigned char desc; /* True for DESC. False for ASC. */
  1543. } *const aOrderBy; /* The ORDER BY clause */
  1544. /* Outputs */
  1545. struct sqlite3_index_constraint_usage {
  1546. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  1547. unsigned char omit; /* Do not code a test for this constraint */
  1548. } *const aConstraintUsage;
  1549. int idxNum; /* Number used to identify the index */
  1550. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  1551. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  1552. int orderByConsumed; /* True if output is already ordered */
  1553. double estimatedCost; /* Estimated cost of using this index */
  1554. };
  1555. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  1556. #define SQLITE_INDEX_CONSTRAINT_GT 4
  1557. #define SQLITE_INDEX_CONSTRAINT_LE 8
  1558. #define SQLITE_INDEX_CONSTRAINT_LT 16
  1559. #define SQLITE_INDEX_CONSTRAINT_GE 32
  1560. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  1561. /*
  1562. ** This routine is used to register a new module name with an SQLite
  1563. ** connection. Module names must be registered before creating new
  1564. ** virtual tables on the module, or before using preexisting virtual
  1565. ** tables of the module.
  1566. */
  1567. int sqlite3_create_module(
  1568. sqlite3 *db, /* SQLite connection to register module with */
  1569. const char *zName, /* Name of the module */
  1570. const sqlite3_module *, /* Methods for the module */
  1571. void * /* Client data for xCreate/xConnect */
  1572. );
  1573. /*
  1574. ** Every module implementation uses a subclass of the following structure
  1575. ** to describe a particular instance of the module. Each subclass will
  1576. ** be taylored to the specific needs of the module implementation. The
  1577. ** purpose of this superclass is to define certain fields that are common
  1578. ** to all module implementations.
  1579. */
  1580. struct sqlite3_vtab {
  1581. const sqlite3_module *pModule; /* The module for this virtual table */
  1582. int nRef; /* Used internally */
  1583. /* Virtual table implementations will typically add additional fields */
  1584. };
  1585. /* Every module implementation uses a subclass of the following structure
  1586. ** to describe cursors that point into the virtual table and are used
  1587. ** to loop through the virtual table. Cursors are created using the
  1588. ** xOpen method of the module. Each module implementation will define
  1589. ** the content of a cursor structure to suit its own needs.
  1590. **
  1591. ** This superclass exists in order to define fields of the cursor that
  1592. ** are common to all implementations.
  1593. */
  1594. struct sqlite3_vtab_cursor {
  1595. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  1596. /* Virtual table implementations will typically add additional fields */
  1597. };
  1598. /*
  1599. ** The xCreate and xConnect methods of a module use the following API
  1600. ** to declare the format (the names and datatypes of the columns) of
  1601. ** the virtual tables they implement.
  1602. */
  1603. int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
  1604. /*
  1605. ** The interface to the virtual-table mechanism defined above (back up
  1606. ** to a comment remarkably similar to this one) is currently considered
  1607. ** to be experimental. The interface might change in incompatible ways.
  1608. ** If this is a problem for you, do not use the interface at this time.
  1609. **
  1610. ** When the virtual-table mechanism stablizes, we will declare the
  1611. ** interface fixed, support it indefinitely, and remove this comment.
  1612. **
  1613. ****** EXPERIMENTAL - subject to change without notice **************
  1614. */
  1615. /*
  1616. ** Undo the hack that converts floating point types to integer for
  1617. ** builds on processors without floating point support.
  1618. */
  1619. #ifdef SQLITE_OMIT_FLOATING_POINT
  1620. # undef double
  1621. #endif
  1622. #ifdef __cplusplus
  1623. } /* End of the 'extern "C"' block */
  1624. #endif
  1625. #endif