1 | /****************************************************************************** |
2 | ** This file is an amalgamation of many separate C source files from SQLite |
3 | ** version 3.28.0. By combining all the individual C code files into this |
4 | ** single large file, the entire code can be compiled as a single translation |
5 | ** unit. This allows many compilers to do optimizations that would not be |
6 | ** possible if the files were compiled separately. Performance improvements |
7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
8 | ** translation unit. |
9 | ** |
10 | ** This file is all you need to compile SQLite. To use SQLite in other |
11 | ** programs, you need this file and the "sqlite3.h" header file that defines |
12 | ** the programming interface to the SQLite library. (If you do not have |
13 | ** the "sqlite3.h" header file at hand, you will find a copy embedded within |
14 | ** the text of this file. Search for "Begin file sqlite3.h" to find the start |
15 | ** of the embedded sqlite3.h header file.) Additional code files may be needed |
16 | ** if you want a wrapper to interface SQLite with your choice of programming |
17 | ** language. The code for the "sqlite3" command-line shell is also in a |
18 | ** separate file. This file contains only code for the core SQLite library. |
19 | */ |
20 | #define SQLITE_CORE 1 |
21 | #define SQLITE_AMALGAMATION 1 |
22 | #ifndef SQLITE_PRIVATE |
23 | # define SQLITE_PRIVATE static |
24 | #endif |
25 | /************** Begin file ctime.c *******************************************/ |
26 | /* |
27 | ** 2010 February 23 |
28 | ** |
29 | ** The author disclaims copyright to this source code. In place of |
30 | ** a legal notice, here is a blessing: |
31 | ** |
32 | ** May you do good and not evil. |
33 | ** May you find forgiveness for yourself and forgive others. |
34 | ** May you share freely, never taking more than you give. |
35 | ** |
36 | ************************************************************************* |
37 | ** |
38 | ** This file implements routines used to report what compile-time options |
39 | ** SQLite was built with. |
40 | */ |
41 | |
42 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
43 | |
44 | /* |
45 | ** Include the configuration header output by 'configure' if we're using the |
46 | ** autoconf-based build |
47 | */ |
48 | #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H) |
49 | #include "config.h" |
50 | #define SQLITECONFIG_H 1 |
51 | #endif |
52 | |
53 | /* These macros are provided to "stringify" the value of the define |
54 | ** for those options in which the value is meaningful. */ |
55 | #define CTIMEOPT_VAL_(opt) #opt |
56 | #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt) |
57 | |
58 | /* Like CTIMEOPT_VAL, but especially for SQLITE_DEFAULT_LOOKASIDE. This |
59 | ** option requires a separate macro because legal values contain a single |
60 | ** comma. e.g. (-DSQLITE_DEFAULT_LOOKASIDE="100,100") */ |
61 | #define CTIMEOPT_VAL2_(opt1,opt2) #opt1 "," #opt2 |
62 | #define CTIMEOPT_VAL2(opt) CTIMEOPT_VAL2_(opt) |
63 | |
64 | /* |
65 | ** An array of names of all compile-time options. This array should |
66 | ** be sorted A-Z. |
67 | ** |
68 | ** This array looks large, but in a typical installation actually uses |
69 | ** only a handful of compile-time options, so most times this array is usually |
70 | ** rather short and uses little memory space. |
71 | */ |
72 | static const char * const sqlite3azCompileOpt[] = { |
73 | |
74 | /* |
75 | ** BEGIN CODE GENERATED BY tool/mkctime.tcl |
76 | */ |
77 | #if SQLITE_32BIT_ROWID |
78 | "32BIT_ROWID" , |
79 | #endif |
80 | #if SQLITE_4_BYTE_ALIGNED_MALLOC |
81 | "4_BYTE_ALIGNED_MALLOC" , |
82 | #endif |
83 | #if SQLITE_64BIT_STATS |
84 | "64BIT_STATS" , |
85 | #endif |
86 | #if SQLITE_ALLOW_COVERING_INDEX_SCAN |
87 | "ALLOW_COVERING_INDEX_SCAN" , |
88 | #endif |
89 | #if SQLITE_ALLOW_URI_AUTHORITY |
90 | "ALLOW_URI_AUTHORITY" , |
91 | #endif |
92 | #ifdef SQLITE_BITMASK_TYPE |
93 | "BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE), |
94 | #endif |
95 | #if SQLITE_BUG_COMPATIBLE_20160819 |
96 | "BUG_COMPATIBLE_20160819" , |
97 | #endif |
98 | #if SQLITE_CASE_SENSITIVE_LIKE |
99 | "CASE_SENSITIVE_LIKE" , |
100 | #endif |
101 | #if SQLITE_CHECK_PAGES |
102 | "CHECK_PAGES" , |
103 | #endif |
104 | #if defined(__clang__) && defined(__clang_major__) |
105 | "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "." |
106 | CTIMEOPT_VAL(__clang_minor__) "." |
107 | CTIMEOPT_VAL(__clang_patchlevel__), |
108 | #elif defined(_MSC_VER) |
109 | "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER), |
110 | #elif defined(__GNUC__) && defined(__VERSION__) |
111 | "COMPILER=gcc-" __VERSION__, |
112 | #endif |
113 | #if SQLITE_COVERAGE_TEST |
114 | "COVERAGE_TEST" , |
115 | #endif |
116 | #if SQLITE_DEBUG |
117 | "DEBUG" , |
118 | #endif |
119 | #if SQLITE_DEFAULT_AUTOMATIC_INDEX |
120 | "DEFAULT_AUTOMATIC_INDEX" , |
121 | #endif |
122 | #if SQLITE_DEFAULT_AUTOVACUUM |
123 | "DEFAULT_AUTOVACUUM" , |
124 | #endif |
125 | #ifdef SQLITE_DEFAULT_CACHE_SIZE |
126 | "DEFAULT_CACHE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_CACHE_SIZE), |
127 | #endif |
128 | #if SQLITE_DEFAULT_CKPTFULLFSYNC |
129 | "DEFAULT_CKPTFULLFSYNC" , |
130 | #endif |
131 | #ifdef SQLITE_DEFAULT_FILE_FORMAT |
132 | "DEFAULT_FILE_FORMAT=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_FORMAT), |
133 | #endif |
134 | #ifdef SQLITE_DEFAULT_FILE_PERMISSIONS |
135 | "DEFAULT_FILE_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_PERMISSIONS), |
136 | #endif |
137 | #if SQLITE_DEFAULT_FOREIGN_KEYS |
138 | "DEFAULT_FOREIGN_KEYS" , |
139 | #endif |
140 | #ifdef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT |
141 | "DEFAULT_JOURNAL_SIZE_LIMIT=" CTIMEOPT_VAL(SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT), |
142 | #endif |
143 | #ifdef SQLITE_DEFAULT_LOCKING_MODE |
144 | "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), |
145 | #endif |
146 | #ifdef SQLITE_DEFAULT_LOOKASIDE |
147 | "DEFAULT_LOOKASIDE=" CTIMEOPT_VAL2(SQLITE_DEFAULT_LOOKASIDE), |
148 | #endif |
149 | #if SQLITE_DEFAULT_MEMSTATUS |
150 | "DEFAULT_MEMSTATUS" , |
151 | #endif |
152 | #ifdef SQLITE_DEFAULT_MMAP_SIZE |
153 | "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), |
154 | #endif |
155 | #ifdef SQLITE_DEFAULT_PAGE_SIZE |
156 | "DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_PAGE_SIZE), |
157 | #endif |
158 | #ifdef SQLITE_DEFAULT_PCACHE_INITSZ |
159 | "DEFAULT_PCACHE_INITSZ=" CTIMEOPT_VAL(SQLITE_DEFAULT_PCACHE_INITSZ), |
160 | #endif |
161 | #ifdef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS |
162 | "DEFAULT_PROXYDIR_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_PROXYDIR_PERMISSIONS), |
163 | #endif |
164 | #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS |
165 | "DEFAULT_RECURSIVE_TRIGGERS" , |
166 | #endif |
167 | #ifdef SQLITE_DEFAULT_ROWEST |
168 | "DEFAULT_ROWEST=" CTIMEOPT_VAL(SQLITE_DEFAULT_ROWEST), |
169 | #endif |
170 | #ifdef SQLITE_DEFAULT_SECTOR_SIZE |
171 | "DEFAULT_SECTOR_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_SECTOR_SIZE), |
172 | #endif |
173 | #ifdef SQLITE_DEFAULT_SYNCHRONOUS |
174 | "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS), |
175 | #endif |
176 | #ifdef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
177 | "DEFAULT_WAL_AUTOCHECKPOINT=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_AUTOCHECKPOINT), |
178 | #endif |
179 | #ifdef SQLITE_DEFAULT_WAL_SYNCHRONOUS |
180 | "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS), |
181 | #endif |
182 | #ifdef SQLITE_DEFAULT_WORKER_THREADS |
183 | "DEFAULT_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WORKER_THREADS), |
184 | #endif |
185 | #if SQLITE_DIRECT_OVERFLOW_READ |
186 | "DIRECT_OVERFLOW_READ" , |
187 | #endif |
188 | #if SQLITE_DISABLE_DIRSYNC |
189 | "DISABLE_DIRSYNC" , |
190 | #endif |
191 | #if SQLITE_DISABLE_FTS3_UNICODE |
192 | "DISABLE_FTS3_UNICODE" , |
193 | #endif |
194 | #if SQLITE_DISABLE_FTS4_DEFERRED |
195 | "DISABLE_FTS4_DEFERRED" , |
196 | #endif |
197 | #if SQLITE_DISABLE_INTRINSIC |
198 | "DISABLE_INTRINSIC" , |
199 | #endif |
200 | #if SQLITE_DISABLE_LFS |
201 | "DISABLE_LFS" , |
202 | #endif |
203 | #if SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS |
204 | "DISABLE_PAGECACHE_OVERFLOW_STATS" , |
205 | #endif |
206 | #if SQLITE_DISABLE_SKIPAHEAD_DISTINCT |
207 | "DISABLE_SKIPAHEAD_DISTINCT" , |
208 | #endif |
209 | #ifdef SQLITE_ENABLE_8_3_NAMES |
210 | "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES), |
211 | #endif |
212 | #if SQLITE_ENABLE_API_ARMOR |
213 | "ENABLE_API_ARMOR" , |
214 | #endif |
215 | #if SQLITE_ENABLE_ATOMIC_WRITE |
216 | "ENABLE_ATOMIC_WRITE" , |
217 | #endif |
218 | #if SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
219 | "ENABLE_BATCH_ATOMIC_WRITE" , |
220 | #endif |
221 | #if SQLITE_ENABLE_CEROD |
222 | "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD), |
223 | #endif |
224 | #if SQLITE_ENABLE_COLUMN_METADATA |
225 | "ENABLE_COLUMN_METADATA" , |
226 | #endif |
227 | #if SQLITE_ENABLE_COLUMN_USED_MASK |
228 | "ENABLE_COLUMN_USED_MASK" , |
229 | #endif |
230 | #if SQLITE_ENABLE_COSTMULT |
231 | "ENABLE_COSTMULT" , |
232 | #endif |
233 | #if SQLITE_ENABLE_CURSOR_HINTS |
234 | "ENABLE_CURSOR_HINTS" , |
235 | #endif |
236 | #if SQLITE_ENABLE_DBSTAT_VTAB |
237 | "ENABLE_DBSTAT_VTAB" , |
238 | #endif |
239 | #if SQLITE_ENABLE_EXPENSIVE_ASSERT |
240 | "ENABLE_EXPENSIVE_ASSERT" , |
241 | #endif |
242 | #if SQLITE_ENABLE_FTS1 |
243 | "ENABLE_FTS1" , |
244 | #endif |
245 | #if SQLITE_ENABLE_FTS2 |
246 | "ENABLE_FTS2" , |
247 | #endif |
248 | #if SQLITE_ENABLE_FTS3 |
249 | "ENABLE_FTS3" , |
250 | #endif |
251 | #if SQLITE_ENABLE_FTS3_PARENTHESIS |
252 | "ENABLE_FTS3_PARENTHESIS" , |
253 | #endif |
254 | #if SQLITE_ENABLE_FTS3_TOKENIZER |
255 | "ENABLE_FTS3_TOKENIZER" , |
256 | #endif |
257 | #if SQLITE_ENABLE_FTS4 |
258 | "ENABLE_FTS4" , |
259 | #endif |
260 | #if SQLITE_ENABLE_FTS5 |
261 | "ENABLE_FTS5" , |
262 | #endif |
263 | #if SQLITE_ENABLE_GEOPOLY |
264 | "ENABLE_GEOPOLY" , |
265 | #endif |
266 | #if SQLITE_ENABLE_HIDDEN_COLUMNS |
267 | "ENABLE_HIDDEN_COLUMNS" , |
268 | #endif |
269 | #if SQLITE_ENABLE_ICU |
270 | "ENABLE_ICU" , |
271 | #endif |
272 | #if SQLITE_ENABLE_IOTRACE |
273 | "ENABLE_IOTRACE" , |
274 | #endif |
275 | #if SQLITE_ENABLE_JSON1 |
276 | "ENABLE_JSON1" , |
277 | #endif |
278 | #if SQLITE_ENABLE_LOAD_EXTENSION |
279 | "ENABLE_LOAD_EXTENSION" , |
280 | #endif |
281 | #ifdef SQLITE_ENABLE_LOCKING_STYLE |
282 | "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE), |
283 | #endif |
284 | #if SQLITE_ENABLE_MEMORY_MANAGEMENT |
285 | "ENABLE_MEMORY_MANAGEMENT" , |
286 | #endif |
287 | #if SQLITE_ENABLE_MEMSYS3 |
288 | "ENABLE_MEMSYS3" , |
289 | #endif |
290 | #if SQLITE_ENABLE_MEMSYS5 |
291 | "ENABLE_MEMSYS5" , |
292 | #endif |
293 | #if SQLITE_ENABLE_MULTIPLEX |
294 | "ENABLE_MULTIPLEX" , |
295 | #endif |
296 | #if SQLITE_ENABLE_NORMALIZE |
297 | "ENABLE_NORMALIZE" , |
298 | #endif |
299 | #if SQLITE_ENABLE_NULL_TRIM |
300 | "ENABLE_NULL_TRIM" , |
301 | #endif |
302 | #if SQLITE_ENABLE_OVERSIZE_CELL_CHECK |
303 | "ENABLE_OVERSIZE_CELL_CHECK" , |
304 | #endif |
305 | #if SQLITE_ENABLE_PREUPDATE_HOOK |
306 | "ENABLE_PREUPDATE_HOOK" , |
307 | #endif |
308 | #if SQLITE_ENABLE_QPSG |
309 | "ENABLE_QPSG" , |
310 | #endif |
311 | #if SQLITE_ENABLE_RBU |
312 | "ENABLE_RBU" , |
313 | #endif |
314 | #if SQLITE_ENABLE_RTREE |
315 | "ENABLE_RTREE" , |
316 | #endif |
317 | #if SQLITE_ENABLE_SELECTTRACE |
318 | "ENABLE_SELECTTRACE" , |
319 | #endif |
320 | #if SQLITE_ENABLE_SESSION |
321 | "ENABLE_SESSION" , |
322 | #endif |
323 | #if SQLITE_ENABLE_SNAPSHOT |
324 | "ENABLE_SNAPSHOT" , |
325 | #endif |
326 | #if SQLITE_ENABLE_SORTER_REFERENCES |
327 | "ENABLE_SORTER_REFERENCES" , |
328 | #endif |
329 | #if SQLITE_ENABLE_SQLLOG |
330 | "ENABLE_SQLLOG" , |
331 | #endif |
332 | #if defined(SQLITE_ENABLE_STAT4) |
333 | "ENABLE_STAT4" , |
334 | #elif defined(SQLITE_ENABLE_STAT3) |
335 | "ENABLE_STAT3" , |
336 | #endif |
337 | #if SQLITE_ENABLE_STMTVTAB |
338 | "ENABLE_STMTVTAB" , |
339 | #endif |
340 | #if SQLITE_ENABLE_STMT_SCANSTATUS |
341 | "ENABLE_STMT_SCANSTATUS" , |
342 | #endif |
343 | #if SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
344 | "ENABLE_UNKNOWN_SQL_FUNCTION" , |
345 | #endif |
346 | #if SQLITE_ENABLE_UNLOCK_NOTIFY |
347 | "ENABLE_UNLOCK_NOTIFY" , |
348 | #endif |
349 | #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
350 | "ENABLE_UPDATE_DELETE_LIMIT" , |
351 | #endif |
352 | #if SQLITE_ENABLE_URI_00_ERROR |
353 | "ENABLE_URI_00_ERROR" , |
354 | #endif |
355 | #if SQLITE_ENABLE_VFSTRACE |
356 | "ENABLE_VFSTRACE" , |
357 | #endif |
358 | #if SQLITE_ENABLE_WHERETRACE |
359 | "ENABLE_WHERETRACE" , |
360 | #endif |
361 | #if SQLITE_ENABLE_ZIPVFS |
362 | "ENABLE_ZIPVFS" , |
363 | #endif |
364 | #if SQLITE_EXPLAIN_ESTIMATED_ROWS |
365 | "EXPLAIN_ESTIMATED_ROWS" , |
366 | #endif |
367 | #if SQLITE_EXTRA_IFNULLROW |
368 | "EXTRA_IFNULLROW" , |
369 | #endif |
370 | #ifdef SQLITE_EXTRA_INIT |
371 | "EXTRA_INIT=" CTIMEOPT_VAL(SQLITE_EXTRA_INIT), |
372 | #endif |
373 | #ifdef SQLITE_EXTRA_SHUTDOWN |
374 | "EXTRA_SHUTDOWN=" CTIMEOPT_VAL(SQLITE_EXTRA_SHUTDOWN), |
375 | #endif |
376 | #ifdef SQLITE_FTS3_MAX_EXPR_DEPTH |
377 | "FTS3_MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_FTS3_MAX_EXPR_DEPTH), |
378 | #endif |
379 | #if SQLITE_FTS5_ENABLE_TEST_MI |
380 | "FTS5_ENABLE_TEST_MI" , |
381 | #endif |
382 | #if SQLITE_FTS5_NO_WITHOUT_ROWID |
383 | "FTS5_NO_WITHOUT_ROWID" , |
384 | #endif |
385 | #if SQLITE_HAS_CODEC |
386 | "HAS_CODEC" , |
387 | #endif |
388 | #if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
389 | "HAVE_ISNAN" , |
390 | #endif |
391 | #if SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
392 | "HOMEGROWN_RECURSIVE_MUTEX" , |
393 | #endif |
394 | #if SQLITE_IGNORE_AFP_LOCK_ERRORS |
395 | "IGNORE_AFP_LOCK_ERRORS" , |
396 | #endif |
397 | #if SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
398 | "IGNORE_FLOCK_LOCK_ERRORS" , |
399 | #endif |
400 | #if SQLITE_INLINE_MEMCPY |
401 | "INLINE_MEMCPY" , |
402 | #endif |
403 | #if SQLITE_INT64_TYPE |
404 | "INT64_TYPE" , |
405 | #endif |
406 | #ifdef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
407 | "INTEGRITY_CHECK_ERROR_MAX=" CTIMEOPT_VAL(SQLITE_INTEGRITY_CHECK_ERROR_MAX), |
408 | #endif |
409 | #if SQLITE_LIKE_DOESNT_MATCH_BLOBS |
410 | "LIKE_DOESNT_MATCH_BLOBS" , |
411 | #endif |
412 | #if SQLITE_LOCK_TRACE |
413 | "LOCK_TRACE" , |
414 | #endif |
415 | #if SQLITE_LOG_CACHE_SPILL |
416 | "LOG_CACHE_SPILL" , |
417 | #endif |
418 | #ifdef SQLITE_MALLOC_SOFT_LIMIT |
419 | "MALLOC_SOFT_LIMIT=" CTIMEOPT_VAL(SQLITE_MALLOC_SOFT_LIMIT), |
420 | #endif |
421 | #ifdef SQLITE_MAX_ATTACHED |
422 | "MAX_ATTACHED=" CTIMEOPT_VAL(SQLITE_MAX_ATTACHED), |
423 | #endif |
424 | #ifdef SQLITE_MAX_COLUMN |
425 | "MAX_COLUMN=" CTIMEOPT_VAL(SQLITE_MAX_COLUMN), |
426 | #endif |
427 | #ifdef SQLITE_MAX_COMPOUND_SELECT |
428 | "MAX_COMPOUND_SELECT=" CTIMEOPT_VAL(SQLITE_MAX_COMPOUND_SELECT), |
429 | #endif |
430 | #ifdef SQLITE_MAX_DEFAULT_PAGE_SIZE |
431 | "MAX_DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_DEFAULT_PAGE_SIZE), |
432 | #endif |
433 | #ifdef SQLITE_MAX_EXPR_DEPTH |
434 | "MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_EXPR_DEPTH), |
435 | #endif |
436 | #ifdef SQLITE_MAX_FUNCTION_ARG |
437 | "MAX_FUNCTION_ARG=" CTIMEOPT_VAL(SQLITE_MAX_FUNCTION_ARG), |
438 | #endif |
439 | #ifdef SQLITE_MAX_LENGTH |
440 | "MAX_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LENGTH), |
441 | #endif |
442 | #ifdef SQLITE_MAX_LIKE_PATTERN_LENGTH |
443 | "MAX_LIKE_PATTERN_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LIKE_PATTERN_LENGTH), |
444 | #endif |
445 | #ifdef SQLITE_MAX_MEMORY |
446 | "MAX_MEMORY=" CTIMEOPT_VAL(SQLITE_MAX_MEMORY), |
447 | #endif |
448 | #ifdef SQLITE_MAX_MMAP_SIZE |
449 | "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE), |
450 | #endif |
451 | #ifdef SQLITE_MAX_MMAP_SIZE_ |
452 | "MAX_MMAP_SIZE_=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE_), |
453 | #endif |
454 | #ifdef SQLITE_MAX_PAGE_COUNT |
455 | "MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT), |
456 | #endif |
457 | #ifdef SQLITE_MAX_PAGE_SIZE |
458 | "MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE), |
459 | #endif |
460 | #ifdef SQLITE_MAX_SCHEMA_RETRY |
461 | "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY), |
462 | #endif |
463 | #ifdef SQLITE_MAX_SQL_LENGTH |
464 | "MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH), |
465 | #endif |
466 | #ifdef SQLITE_MAX_TRIGGER_DEPTH |
467 | "MAX_TRIGGER_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_TRIGGER_DEPTH), |
468 | #endif |
469 | #ifdef SQLITE_MAX_VARIABLE_NUMBER |
470 | "MAX_VARIABLE_NUMBER=" CTIMEOPT_VAL(SQLITE_MAX_VARIABLE_NUMBER), |
471 | #endif |
472 | #ifdef SQLITE_MAX_VDBE_OP |
473 | "MAX_VDBE_OP=" CTIMEOPT_VAL(SQLITE_MAX_VDBE_OP), |
474 | #endif |
475 | #ifdef SQLITE_MAX_WORKER_THREADS |
476 | "MAX_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_MAX_WORKER_THREADS), |
477 | #endif |
478 | #if SQLITE_MEMDEBUG |
479 | "MEMDEBUG" , |
480 | #endif |
481 | #if SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
482 | "MIXED_ENDIAN_64BIT_FLOAT" , |
483 | #endif |
484 | #if SQLITE_MMAP_READWRITE |
485 | "MMAP_READWRITE" , |
486 | #endif |
487 | #if SQLITE_MUTEX_NOOP |
488 | "MUTEX_NOOP" , |
489 | #endif |
490 | #if SQLITE_MUTEX_NREF |
491 | "MUTEX_NREF" , |
492 | #endif |
493 | #if SQLITE_MUTEX_OMIT |
494 | "MUTEX_OMIT" , |
495 | #endif |
496 | #if SQLITE_MUTEX_PTHREADS |
497 | "MUTEX_PTHREADS" , |
498 | #endif |
499 | #if SQLITE_MUTEX_W32 |
500 | "MUTEX_W32" , |
501 | #endif |
502 | #if SQLITE_NEED_ERR_NAME |
503 | "NEED_ERR_NAME" , |
504 | #endif |
505 | #if SQLITE_NOINLINE |
506 | "NOINLINE" , |
507 | #endif |
508 | #if SQLITE_NO_SYNC |
509 | "NO_SYNC" , |
510 | #endif |
511 | #if SQLITE_OMIT_ALTERTABLE |
512 | "OMIT_ALTERTABLE" , |
513 | #endif |
514 | #if SQLITE_OMIT_ANALYZE |
515 | "OMIT_ANALYZE" , |
516 | #endif |
517 | #if SQLITE_OMIT_ATTACH |
518 | "OMIT_ATTACH" , |
519 | #endif |
520 | #if SQLITE_OMIT_AUTHORIZATION |
521 | "OMIT_AUTHORIZATION" , |
522 | #endif |
523 | #if SQLITE_OMIT_AUTOINCREMENT |
524 | "OMIT_AUTOINCREMENT" , |
525 | #endif |
526 | #if SQLITE_OMIT_AUTOINIT |
527 | "OMIT_AUTOINIT" , |
528 | #endif |
529 | #if SQLITE_OMIT_AUTOMATIC_INDEX |
530 | "OMIT_AUTOMATIC_INDEX" , |
531 | #endif |
532 | #if SQLITE_OMIT_AUTORESET |
533 | "OMIT_AUTORESET" , |
534 | #endif |
535 | #if SQLITE_OMIT_AUTOVACUUM |
536 | "OMIT_AUTOVACUUM" , |
537 | #endif |
538 | #if SQLITE_OMIT_BETWEEN_OPTIMIZATION |
539 | "OMIT_BETWEEN_OPTIMIZATION" , |
540 | #endif |
541 | #if SQLITE_OMIT_BLOB_LITERAL |
542 | "OMIT_BLOB_LITERAL" , |
543 | #endif |
544 | #if SQLITE_OMIT_BTREECOUNT |
545 | "OMIT_BTREECOUNT" , |
546 | #endif |
547 | #if SQLITE_OMIT_CAST |
548 | "OMIT_CAST" , |
549 | #endif |
550 | #if SQLITE_OMIT_CHECK |
551 | "OMIT_CHECK" , |
552 | #endif |
553 | #if SQLITE_OMIT_COMPLETE |
554 | "OMIT_COMPLETE" , |
555 | #endif |
556 | #if SQLITE_OMIT_COMPOUND_SELECT |
557 | "OMIT_COMPOUND_SELECT" , |
558 | #endif |
559 | #if SQLITE_OMIT_CONFLICT_CLAUSE |
560 | "OMIT_CONFLICT_CLAUSE" , |
561 | #endif |
562 | #if SQLITE_OMIT_CTE |
563 | "OMIT_CTE" , |
564 | #endif |
565 | #if SQLITE_OMIT_DATETIME_FUNCS |
566 | "OMIT_DATETIME_FUNCS" , |
567 | #endif |
568 | #if SQLITE_OMIT_DECLTYPE |
569 | "OMIT_DECLTYPE" , |
570 | #endif |
571 | #if SQLITE_OMIT_DEPRECATED |
572 | "OMIT_DEPRECATED" , |
573 | #endif |
574 | #if SQLITE_OMIT_DISKIO |
575 | "OMIT_DISKIO" , |
576 | #endif |
577 | #if SQLITE_OMIT_EXPLAIN |
578 | "OMIT_EXPLAIN" , |
579 | #endif |
580 | #if SQLITE_OMIT_FLAG_PRAGMAS |
581 | "OMIT_FLAG_PRAGMAS" , |
582 | #endif |
583 | #if SQLITE_OMIT_FLOATING_POINT |
584 | "OMIT_FLOATING_POINT" , |
585 | #endif |
586 | #if SQLITE_OMIT_FOREIGN_KEY |
587 | "OMIT_FOREIGN_KEY" , |
588 | #endif |
589 | #if SQLITE_OMIT_GET_TABLE |
590 | "OMIT_GET_TABLE" , |
591 | #endif |
592 | #if SQLITE_OMIT_HEX_INTEGER |
593 | "OMIT_HEX_INTEGER" , |
594 | #endif |
595 | #if SQLITE_OMIT_INCRBLOB |
596 | "OMIT_INCRBLOB" , |
597 | #endif |
598 | #if SQLITE_OMIT_INTEGRITY_CHECK |
599 | "OMIT_INTEGRITY_CHECK" , |
600 | #endif |
601 | #if SQLITE_OMIT_LIKE_OPTIMIZATION |
602 | "OMIT_LIKE_OPTIMIZATION" , |
603 | #endif |
604 | #if SQLITE_OMIT_LOAD_EXTENSION |
605 | "OMIT_LOAD_EXTENSION" , |
606 | #endif |
607 | #if SQLITE_OMIT_LOCALTIME |
608 | "OMIT_LOCALTIME" , |
609 | #endif |
610 | #if SQLITE_OMIT_LOOKASIDE |
611 | "OMIT_LOOKASIDE" , |
612 | #endif |
613 | #if SQLITE_OMIT_MEMORYDB |
614 | "OMIT_MEMORYDB" , |
615 | #endif |
616 | #if SQLITE_OMIT_OR_OPTIMIZATION |
617 | "OMIT_OR_OPTIMIZATION" , |
618 | #endif |
619 | #if SQLITE_OMIT_PAGER_PRAGMAS |
620 | "OMIT_PAGER_PRAGMAS" , |
621 | #endif |
622 | #if SQLITE_OMIT_PARSER_TRACE |
623 | "OMIT_PARSER_TRACE" , |
624 | #endif |
625 | #if SQLITE_OMIT_POPEN |
626 | "OMIT_POPEN" , |
627 | #endif |
628 | #if SQLITE_OMIT_PRAGMA |
629 | "OMIT_PRAGMA" , |
630 | #endif |
631 | #if SQLITE_OMIT_PROGRESS_CALLBACK |
632 | "OMIT_PROGRESS_CALLBACK" , |
633 | #endif |
634 | #if SQLITE_OMIT_QUICKBALANCE |
635 | "OMIT_QUICKBALANCE" , |
636 | #endif |
637 | #if SQLITE_OMIT_REINDEX |
638 | "OMIT_REINDEX" , |
639 | #endif |
640 | #if SQLITE_OMIT_SCHEMA_PRAGMAS |
641 | "OMIT_SCHEMA_PRAGMAS" , |
642 | #endif |
643 | #if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
644 | "OMIT_SCHEMA_VERSION_PRAGMAS" , |
645 | #endif |
646 | #if SQLITE_OMIT_SHARED_CACHE |
647 | "OMIT_SHARED_CACHE" , |
648 | #endif |
649 | #if SQLITE_OMIT_SHUTDOWN_DIRECTORIES |
650 | "OMIT_SHUTDOWN_DIRECTORIES" , |
651 | #endif |
652 | #if SQLITE_OMIT_SUBQUERY |
653 | "OMIT_SUBQUERY" , |
654 | #endif |
655 | #if SQLITE_OMIT_TCL_VARIABLE |
656 | "OMIT_TCL_VARIABLE" , |
657 | #endif |
658 | #if SQLITE_OMIT_TEMPDB |
659 | "OMIT_TEMPDB" , |
660 | #endif |
661 | #if SQLITE_OMIT_TEST_CONTROL |
662 | "OMIT_TEST_CONTROL" , |
663 | #endif |
664 | #if SQLITE_OMIT_TRACE |
665 | "OMIT_TRACE" , |
666 | #endif |
667 | #if SQLITE_OMIT_TRIGGER |
668 | "OMIT_TRIGGER" , |
669 | #endif |
670 | #if SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
671 | "OMIT_TRUNCATE_OPTIMIZATION" , |
672 | #endif |
673 | #if SQLITE_OMIT_UTF16 |
674 | "OMIT_UTF16" , |
675 | #endif |
676 | #if SQLITE_OMIT_VACUUM |
677 | "OMIT_VACUUM" , |
678 | #endif |
679 | #if SQLITE_OMIT_VIEW |
680 | "OMIT_VIEW" , |
681 | #endif |
682 | #if SQLITE_OMIT_VIRTUALTABLE |
683 | "OMIT_VIRTUALTABLE" , |
684 | #endif |
685 | #if SQLITE_OMIT_WAL |
686 | "OMIT_WAL" , |
687 | #endif |
688 | #if SQLITE_OMIT_WSD |
689 | "OMIT_WSD" , |
690 | #endif |
691 | #if SQLITE_OMIT_XFER_OPT |
692 | "OMIT_XFER_OPT" , |
693 | #endif |
694 | #if SQLITE_PCACHE_SEPARATE_HEADER |
695 | "PCACHE_SEPARATE_HEADER" , |
696 | #endif |
697 | #if SQLITE_PERFORMANCE_TRACE |
698 | "PERFORMANCE_TRACE" , |
699 | #endif |
700 | #if SQLITE_POWERSAFE_OVERWRITE |
701 | "POWERSAFE_OVERWRITE" , |
702 | #endif |
703 | #if SQLITE_PREFER_PROXY_LOCKING |
704 | "PREFER_PROXY_LOCKING" , |
705 | #endif |
706 | #if SQLITE_PROXY_DEBUG |
707 | "PROXY_DEBUG" , |
708 | #endif |
709 | #if SQLITE_REVERSE_UNORDERED_SELECTS |
710 | "REVERSE_UNORDERED_SELECTS" , |
711 | #endif |
712 | #if SQLITE_RTREE_INT_ONLY |
713 | "RTREE_INT_ONLY" , |
714 | #endif |
715 | #if SQLITE_SECURE_DELETE |
716 | "SECURE_DELETE" , |
717 | #endif |
718 | #if SQLITE_SMALL_STACK |
719 | "SMALL_STACK" , |
720 | #endif |
721 | #ifdef SQLITE_SORTER_PMASZ |
722 | "SORTER_PMASZ=" CTIMEOPT_VAL(SQLITE_SORTER_PMASZ), |
723 | #endif |
724 | #if SQLITE_SOUNDEX |
725 | "SOUNDEX" , |
726 | #endif |
727 | #ifdef SQLITE_STAT4_SAMPLES |
728 | "STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES), |
729 | #endif |
730 | #ifdef SQLITE_STMTJRNL_SPILL |
731 | "STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL), |
732 | #endif |
733 | #if SQLITE_SUBSTR_COMPATIBILITY |
734 | "SUBSTR_COMPATIBILITY" , |
735 | #endif |
736 | #if SQLITE_SYSTEM_MALLOC |
737 | "SYSTEM_MALLOC" , |
738 | #endif |
739 | #if SQLITE_TCL |
740 | "TCL" , |
741 | #endif |
742 | #ifdef SQLITE_TEMP_STORE |
743 | "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE), |
744 | #endif |
745 | #if SQLITE_TEST |
746 | "TEST" , |
747 | #endif |
748 | #if defined(SQLITE_THREADSAFE) |
749 | "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
750 | #elif defined(THREADSAFE) |
751 | "THREADSAFE=" CTIMEOPT_VAL(THREADSAFE), |
752 | #else |
753 | "THREADSAFE=1" , |
754 | #endif |
755 | #if SQLITE_UNLINK_AFTER_CLOSE |
756 | "UNLINK_AFTER_CLOSE" , |
757 | #endif |
758 | #if SQLITE_UNTESTABLE |
759 | "UNTESTABLE" , |
760 | #endif |
761 | #if SQLITE_USER_AUTHENTICATION |
762 | "USER_AUTHENTICATION" , |
763 | #endif |
764 | #if SQLITE_USE_ALLOCA |
765 | "USE_ALLOCA" , |
766 | #endif |
767 | #if SQLITE_USE_FCNTL_TRACE |
768 | "USE_FCNTL_TRACE" , |
769 | #endif |
770 | #if SQLITE_USE_URI |
771 | "USE_URI" , |
772 | #endif |
773 | #if SQLITE_VDBE_COVERAGE |
774 | "VDBE_COVERAGE" , |
775 | #endif |
776 | #if SQLITE_WIN32_MALLOC |
777 | "WIN32_MALLOC" , |
778 | #endif |
779 | #if SQLITE_ZERO_MALLOC |
780 | "ZERO_MALLOC" , |
781 | #endif |
782 | /* |
783 | ** END CODE GENERATED BY tool/mkctime.tcl |
784 | */ |
785 | }; |
786 | |
787 | SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){ |
788 | *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); |
789 | return (const char**)sqlite3azCompileOpt; |
790 | } |
791 | |
792 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
793 | |
794 | /************** End of ctime.c ***********************************************/ |
795 | /************** Begin file sqliteInt.h ***************************************/ |
796 | /* |
797 | ** 2001 September 15 |
798 | ** |
799 | ** The author disclaims copyright to this source code. In place of |
800 | ** a legal notice, here is a blessing: |
801 | ** |
802 | ** May you do good and not evil. |
803 | ** May you find forgiveness for yourself and forgive others. |
804 | ** May you share freely, never taking more than you give. |
805 | ** |
806 | ************************************************************************* |
807 | ** Internal interface definitions for SQLite. |
808 | ** |
809 | */ |
810 | #ifndef SQLITEINT_H |
811 | #define SQLITEINT_H |
812 | |
813 | /* Special Comments: |
814 | ** |
815 | ** Some comments have special meaning to the tools that measure test |
816 | ** coverage: |
817 | ** |
818 | ** NO_TEST - The branches on this line are not |
819 | ** measured by branch coverage. This is |
820 | ** used on lines of code that actually |
821 | ** implement parts of coverage testing. |
822 | ** |
823 | ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false |
824 | ** and the correct answer is still obtained, |
825 | ** though perhaps more slowly. |
826 | ** |
827 | ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true |
828 | ** and the correct answer is still obtained, |
829 | ** though perhaps more slowly. |
830 | ** |
831 | ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread |
832 | ** that would be harmless and undetectable |
833 | ** if it did occur. |
834 | ** |
835 | ** In all cases, the special comment must be enclosed in the usual |
836 | ** slash-asterisk...asterisk-slash comment marks, with no spaces between the |
837 | ** asterisks and the comment text. |
838 | */ |
839 | |
840 | /* |
841 | ** Make sure the Tcl calling convention macro is defined. This macro is |
842 | ** only used by test code and Tcl integration code. |
843 | */ |
844 | #ifndef SQLITE_TCLAPI |
845 | # define SQLITE_TCLAPI |
846 | #endif |
847 | |
848 | /* |
849 | ** Include the header file used to customize the compiler options for MSVC. |
850 | ** This should be done first so that it can successfully prevent spurious |
851 | ** compiler warnings due to subsequent content in this file and other files |
852 | ** that are included by this file. |
853 | */ |
854 | /************** Include msvc.h in the middle of sqliteInt.h ******************/ |
855 | /************** Begin file msvc.h ********************************************/ |
856 | /* |
857 | ** 2015 January 12 |
858 | ** |
859 | ** The author disclaims copyright to this source code. In place of |
860 | ** a legal notice, here is a blessing: |
861 | ** |
862 | ** May you do good and not evil. |
863 | ** May you find forgiveness for yourself and forgive others. |
864 | ** May you share freely, never taking more than you give. |
865 | ** |
866 | ****************************************************************************** |
867 | ** |
868 | ** This file contains code that is specific to MSVC. |
869 | */ |
870 | #ifndef SQLITE_MSVC_H |
871 | #define SQLITE_MSVC_H |
872 | |
873 | #if defined(_MSC_VER) |
874 | #pragma warning(disable : 4054) |
875 | #pragma warning(disable : 4055) |
876 | #pragma warning(disable : 4100) |
877 | #pragma warning(disable : 4127) |
878 | #pragma warning(disable : 4130) |
879 | #pragma warning(disable : 4152) |
880 | #pragma warning(disable : 4189) |
881 | #pragma warning(disable : 4206) |
882 | #pragma warning(disable : 4210) |
883 | #pragma warning(disable : 4232) |
884 | #pragma warning(disable : 4244) |
885 | #pragma warning(disable : 4305) |
886 | #pragma warning(disable : 4306) |
887 | #pragma warning(disable : 4702) |
888 | #pragma warning(disable : 4706) |
889 | #endif /* defined(_MSC_VER) */ |
890 | |
891 | #endif /* SQLITE_MSVC_H */ |
892 | |
893 | /************** End of msvc.h ************************************************/ |
894 | /************** Continuing where we left off in sqliteInt.h ******************/ |
895 | |
896 | /* |
897 | ** Special setup for VxWorks |
898 | */ |
899 | /************** Include vxworks.h in the middle of sqliteInt.h ***************/ |
900 | /************** Begin file vxworks.h *****************************************/ |
901 | /* |
902 | ** 2015-03-02 |
903 | ** |
904 | ** The author disclaims copyright to this source code. In place of |
905 | ** a legal notice, here is a blessing: |
906 | ** |
907 | ** May you do good and not evil. |
908 | ** May you find forgiveness for yourself and forgive others. |
909 | ** May you share freely, never taking more than you give. |
910 | ** |
911 | ****************************************************************************** |
912 | ** |
913 | ** This file contains code that is specific to Wind River's VxWorks |
914 | */ |
915 | #if defined(__RTP__) || defined(_WRS_KERNEL) |
916 | /* This is VxWorks. Set up things specially for that OS |
917 | */ |
918 | #include <vxWorks.h> |
919 | #include <pthread.h> /* amalgamator: dontcache */ |
920 | #define OS_VXWORKS 1 |
921 | #define SQLITE_OS_OTHER 0 |
922 | #define SQLITE_HOMEGROWN_RECURSIVE_MUTEX 1 |
923 | #define SQLITE_OMIT_LOAD_EXTENSION 1 |
924 | #define SQLITE_ENABLE_LOCKING_STYLE 0 |
925 | #define HAVE_UTIME 1 |
926 | #else |
927 | /* This is not VxWorks. */ |
928 | #define OS_VXWORKS 0 |
929 | #define HAVE_FCHOWN 1 |
930 | #define HAVE_READLINK 1 |
931 | #define HAVE_LSTAT 1 |
932 | #endif /* defined(_WRS_KERNEL) */ |
933 | |
934 | /************** End of vxworks.h *********************************************/ |
935 | /************** Continuing where we left off in sqliteInt.h ******************/ |
936 | |
937 | /* |
938 | ** These #defines should enable >2GB file support on POSIX if the |
939 | ** underlying operating system supports it. If the OS lacks |
940 | ** large file support, or if the OS is windows, these should be no-ops. |
941 | ** |
942 | ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
943 | ** system #includes. Hence, this block of code must be the very first |
944 | ** code in all source files. |
945 | ** |
946 | ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
947 | ** on the compiler command line. This is necessary if you are compiling |
948 | ** on a recent machine (ex: Red Hat 7.2) but you want your code to work |
949 | ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 |
950 | ** without this option, LFS is enable. But LFS does not exist in the kernel |
951 | ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary |
952 | ** portability you should omit LFS. |
953 | ** |
954 | ** The previous paragraph was written in 2005. (This paragraph is written |
955 | ** on 2008-11-28.) These days, all Linux kernels support large files, so |
956 | ** you should probably leave LFS enabled. But some embedded platforms might |
957 | ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful. |
958 | ** |
959 | ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. |
960 | */ |
961 | #ifndef SQLITE_DISABLE_LFS |
962 | # define _LARGE_FILE 1 |
963 | # ifndef _FILE_OFFSET_BITS |
964 | # define _FILE_OFFSET_BITS 64 |
965 | # endif |
966 | # define _LARGEFILE_SOURCE 1 |
967 | #endif |
968 | |
969 | /* The GCC_VERSION and MSVC_VERSION macros are used to |
970 | ** conditionally include optimizations for each of these compilers. A |
971 | ** value of 0 means that compiler is not being used. The |
972 | ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific |
973 | ** optimizations, and hence set all compiler macros to 0 |
974 | ** |
975 | ** There was once also a CLANG_VERSION macro. However, we learn that the |
976 | ** version numbers in clang are for "marketing" only and are inconsistent |
977 | ** and unreliable. Fortunately, all versions of clang also recognize the |
978 | ** gcc version numbers and have reasonable settings for gcc version numbers, |
979 | ** so the GCC_VERSION macro will be set to a correct non-zero value even |
980 | ** when compiling with clang. |
981 | */ |
982 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
983 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
984 | #else |
985 | # define GCC_VERSION 0 |
986 | #endif |
987 | #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC) |
988 | # define MSVC_VERSION _MSC_VER |
989 | #else |
990 | # define MSVC_VERSION 0 |
991 | #endif |
992 | |
993 | /* Needed for various definitions... */ |
994 | #if defined(__GNUC__) && !defined(_GNU_SOURCE) |
995 | # define _GNU_SOURCE |
996 | #endif |
997 | |
998 | #if defined(__OpenBSD__) && !defined(_BSD_SOURCE) |
999 | # define _BSD_SOURCE |
1000 | #endif |
1001 | |
1002 | /* |
1003 | ** For MinGW, check to see if we can include the header file containing its |
1004 | ** version information, among other things. Normally, this internal MinGW |
1005 | ** header file would [only] be included automatically by other MinGW header |
1006 | ** files; however, the contained version information is now required by this |
1007 | ** header file to work around binary compatibility issues (see below) and |
1008 | ** this is the only known way to reliably obtain it. This entire #if block |
1009 | ** would be completely unnecessary if there was any other way of detecting |
1010 | ** MinGW via their preprocessor (e.g. if they customized their GCC to define |
1011 | ** some MinGW-specific macros). When compiling for MinGW, either the |
1012 | ** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be |
1013 | ** defined; otherwise, detection of conditions specific to MinGW will be |
1014 | ** disabled. |
1015 | */ |
1016 | #if defined(_HAVE_MINGW_H) |
1017 | # include "mingw.h" |
1018 | #elif defined(_HAVE__MINGW_H) |
1019 | # include "_mingw.h" |
1020 | #endif |
1021 | |
1022 | /* |
1023 | ** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T |
1024 | ** define is required to maintain binary compatibility with the MSVC runtime |
1025 | ** library in use (e.g. for Windows XP). |
1026 | */ |
1027 | #if !defined(_USE_32BIT_TIME_T) && !defined(_USE_64BIT_TIME_T) && \ |
1028 | defined(_WIN32) && !defined(_WIN64) && \ |
1029 | defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \ |
1030 | defined(__MSVCRT__) |
1031 | # define _USE_32BIT_TIME_T |
1032 | #endif |
1033 | |
1034 | /* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear |
1035 | ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for |
1036 | ** MinGW. |
1037 | */ |
1038 | /************** Include sqlite3.h in the middle of sqliteInt.h ***************/ |
1039 | /************** Begin file sqlite3.h *****************************************/ |
1040 | /* |
1041 | ** 2001-09-15 |
1042 | ** |
1043 | ** The author disclaims copyright to this source code. In place of |
1044 | ** a legal notice, here is a blessing: |
1045 | ** |
1046 | ** May you do good and not evil. |
1047 | ** May you find forgiveness for yourself and forgive others. |
1048 | ** May you share freely, never taking more than you give. |
1049 | ** |
1050 | ************************************************************************* |
1051 | ** This header file defines the interface that the SQLite library |
1052 | ** presents to client programs. If a C-function, structure, datatype, |
1053 | ** or constant definition does not appear in this file, then it is |
1054 | ** not a published API of SQLite, is subject to change without |
1055 | ** notice, and should not be referenced by programs that use SQLite. |
1056 | ** |
1057 | ** Some of the definitions that are in this file are marked as |
1058 | ** "experimental". Experimental interfaces are normally new |
1059 | ** features recently added to SQLite. We do not anticipate changes |
1060 | ** to experimental interfaces but reserve the right to make minor changes |
1061 | ** if experience from use "in the wild" suggest such changes are prudent. |
1062 | ** |
1063 | ** The official C-language API documentation for SQLite is derived |
1064 | ** from comments in this file. This file is the authoritative source |
1065 | ** on how SQLite interfaces are supposed to operate. |
1066 | ** |
1067 | ** The name of this file under configuration management is "sqlite.h.in". |
1068 | ** The makefile makes some minor changes to this file (such as inserting |
1069 | ** the version number) and changes its name to "sqlite3.h" as |
1070 | ** part of the build process. |
1071 | */ |
1072 | #ifndef SQLITE3_H |
1073 | #define SQLITE3_H |
1074 | #include <stdarg.h> /* Needed for the definition of va_list */ |
1075 | |
1076 | /* |
1077 | ** Make sure we can call this stuff from C++. |
1078 | */ |
1079 | #if 0 |
1080 | extern "C" { |
1081 | #endif |
1082 | |
1083 | |
1084 | /* |
1085 | ** Provide the ability to override linkage features of the interface. |
1086 | */ |
1087 | #ifndef SQLITE_EXTERN |
1088 | # define SQLITE_EXTERN extern |
1089 | #endif |
1090 | #ifndef SQLITE_API |
1091 | # define SQLITE_API |
1092 | #endif |
1093 | #ifndef SQLITE_CDECL |
1094 | # define SQLITE_CDECL |
1095 | #endif |
1096 | #ifndef SQLITE_APICALL |
1097 | # define SQLITE_APICALL |
1098 | #endif |
1099 | #ifndef SQLITE_STDCALL |
1100 | # define SQLITE_STDCALL SQLITE_APICALL |
1101 | #endif |
1102 | #ifndef SQLITE_CALLBACK |
1103 | # define SQLITE_CALLBACK |
1104 | #endif |
1105 | #ifndef SQLITE_SYSAPI |
1106 | # define SQLITE_SYSAPI |
1107 | #endif |
1108 | |
1109 | /* |
1110 | ** These no-op macros are used in front of interfaces to mark those |
1111 | ** interfaces as either deprecated or experimental. New applications |
1112 | ** should not use deprecated interfaces - they are supported for backwards |
1113 | ** compatibility only. Application writers should be aware that |
1114 | ** experimental interfaces are subject to change in point releases. |
1115 | ** |
1116 | ** These macros used to resolve to various kinds of compiler magic that |
1117 | ** would generate warning messages when they were used. But that |
1118 | ** compiler magic ended up generating such a flurry of bug reports |
1119 | ** that we have taken it all out and gone back to using simple |
1120 | ** noop macros. |
1121 | */ |
1122 | #define SQLITE_DEPRECATED |
1123 | #define SQLITE_EXPERIMENTAL |
1124 | |
1125 | /* |
1126 | ** Ensure these symbols were not defined by some previous header file. |
1127 | */ |
1128 | #ifdef SQLITE_VERSION |
1129 | # undef SQLITE_VERSION |
1130 | #endif |
1131 | #ifdef SQLITE_VERSION_NUMBER |
1132 | # undef SQLITE_VERSION_NUMBER |
1133 | #endif |
1134 | |
1135 | /* |
1136 | ** CAPI3REF: Compile-Time Library Version Numbers |
1137 | ** |
1138 | ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header |
1139 | ** evaluates to a string literal that is the SQLite version in the |
1140 | ** format "X.Y.Z" where X is the major version number (always 3 for |
1141 | ** SQLite3) and Y is the minor version number and Z is the release number.)^ |
1142 | ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer |
1143 | ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same |
1144 | ** numbers used in [SQLITE_VERSION].)^ |
1145 | ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also |
1146 | ** be larger than the release from which it is derived. Either Y will |
1147 | ** be held constant and Z will be incremented or else Y will be incremented |
1148 | ** and Z will be reset to zero. |
1149 | ** |
1150 | ** Since [version 3.6.18] ([dateof:3.6.18]), |
1151 | ** SQLite source code has been stored in the |
1152 | ** <a href="http://www.fossil-scm.org/">Fossil configuration management |
1153 | ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to |
1154 | ** a string which identifies a particular check-in of SQLite |
1155 | ** within its configuration management system. ^The SQLITE_SOURCE_ID |
1156 | ** string contains the date and time of the check-in (UTC) and a SHA1 |
1157 | ** or SHA3-256 hash of the entire source tree. If the source code has |
1158 | ** been edited in any way since it was last checked in, then the last |
1159 | ** four hexadecimal digits of the hash may be modified. |
1160 | ** |
1161 | ** See also: [sqlite3_libversion()], |
1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
1164 | */ |
1165 | #define SQLITE_VERSION "3.28.0" |
1166 | #define SQLITE_VERSION_NUMBER 3028000 |
1167 | #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50" |
1168 | |
1169 | /* |
1170 | ** CAPI3REF: Run-Time Library Version Numbers |
1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
1172 | ** |
1173 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
1174 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
1175 | ** but are associated with the library instead of the header file. ^(Cautious |
1176 | ** programmers might include assert() statements in their application to |
1177 | ** verify that values returned by these interfaces match the macros in |
1178 | ** the header, and thus ensure that the application is |
1179 | ** compiled with matching library and header files. |
1180 | ** |
1181 | ** <blockquote><pre> |
1182 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
1183 | ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 ); |
1184 | ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); |
1185 | ** </pre></blockquote>)^ |
1186 | ** |
1187 | ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] |
1188 | ** macro. ^The sqlite3_libversion() function returns a pointer to the |
1189 | ** to the sqlite3_version[] string constant. The sqlite3_libversion() |
1190 | ** function is provided for use in DLLs since DLL users usually do not have |
1191 | ** direct access to string constants within the DLL. ^The |
1192 | ** sqlite3_libversion_number() function returns an integer equal to |
1193 | ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns |
1194 | ** a pointer to a string constant whose value is the same as the |
1195 | ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built |
1196 | ** using an edited copy of [the amalgamation], then the last four characters |
1197 | ** of the hash might be different from [SQLITE_SOURCE_ID].)^ |
1198 | ** |
1199 | ** See also: [sqlite_version()] and [sqlite_source_id()]. |
1200 | */ |
1201 | SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; |
1202 | SQLITE_API const char *sqlite3_libversion(void); |
1203 | SQLITE_API const char *sqlite3_sourceid(void); |
1204 | SQLITE_API int sqlite3_libversion_number(void); |
1205 | |
1206 | /* |
1207 | ** CAPI3REF: Run-Time Library Compilation Options Diagnostics |
1208 | ** |
1209 | ** ^The sqlite3_compileoption_used() function returns 0 or 1 |
1210 | ** indicating whether the specified option was defined at |
1211 | ** compile time. ^The SQLITE_ prefix may be omitted from the |
1212 | ** option name passed to sqlite3_compileoption_used(). |
1213 | ** |
1214 | ** ^The sqlite3_compileoption_get() function allows iterating |
1215 | ** over the list of options that were defined at compile time by |
1216 | ** returning the N-th compile time option string. ^If N is out of range, |
1217 | ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ |
1218 | ** prefix is omitted from any strings returned by |
1219 | ** sqlite3_compileoption_get(). |
1220 | ** |
1221 | ** ^Support for the diagnostic functions sqlite3_compileoption_used() |
1222 | ** and sqlite3_compileoption_get() may be omitted by specifying the |
1223 | ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. |
1224 | ** |
1225 | ** See also: SQL functions [sqlite_compileoption_used()] and |
1226 | ** [sqlite_compileoption_get()] and the [compile_options pragma]. |
1227 | */ |
1228 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
1229 | SQLITE_API int sqlite3_compileoption_used(const char *zOptName); |
1230 | SQLITE_API const char *sqlite3_compileoption_get(int N); |
1231 | #else |
1232 | # define sqlite3_compileoption_used(X) 0 |
1233 | # define sqlite3_compileoption_get(X) ((void*)0) |
1234 | #endif |
1235 | |
1236 | /* |
1237 | ** CAPI3REF: Test To See If The Library Is Threadsafe |
1238 | ** |
1239 | ** ^The sqlite3_threadsafe() function returns zero if and only if |
1240 | ** SQLite was compiled with mutexing code omitted due to the |
1241 | ** [SQLITE_THREADSAFE] compile-time option being set to 0. |
1242 | ** |
1243 | ** SQLite can be compiled with or without mutexes. When |
1244 | ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes |
1245 | ** are enabled and SQLite is threadsafe. When the |
1246 | ** [SQLITE_THREADSAFE] macro is 0, |
1247 | ** the mutexes are omitted. Without the mutexes, it is not safe |
1248 | ** to use SQLite concurrently from more than one thread. |
1249 | ** |
1250 | ** Enabling mutexes incurs a measurable performance penalty. |
1251 | ** So if speed is of utmost importance, it makes sense to disable |
1252 | ** the mutexes. But for maximum safety, mutexes should be enabled. |
1253 | ** ^The default behavior is for mutexes to be enabled. |
1254 | ** |
1255 | ** This interface can be used by an application to make sure that the |
1256 | ** version of SQLite that it is linking against was compiled with |
1257 | ** the desired setting of the [SQLITE_THREADSAFE] macro. |
1258 | ** |
1259 | ** This interface only reports on the compile-time mutex setting |
1260 | ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with |
1261 | ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but |
1262 | ** can be fully or partially disabled using a call to [sqlite3_config()] |
1263 | ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], |
1264 | ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the |
1265 | ** sqlite3_threadsafe() function shows only the compile-time setting of |
1266 | ** thread safety, not any run-time changes to that setting made by |
1267 | ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() |
1268 | ** is unchanged by calls to sqlite3_config().)^ |
1269 | ** |
1270 | ** See the [threading mode] documentation for additional information. |
1271 | */ |
1272 | SQLITE_API int sqlite3_threadsafe(void); |
1273 | |
1274 | /* |
1275 | ** CAPI3REF: Database Connection Handle |
1276 | ** KEYWORDS: {database connection} {database connections} |
1277 | ** |
1278 | ** Each open SQLite database is represented by a pointer to an instance of |
1279 | ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 |
1280 | ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and |
1281 | ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] |
1282 | ** and [sqlite3_close_v2()] are its destructors. There are many other |
1283 | ** interfaces (such as |
1284 | ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and |
1285 | ** [sqlite3_busy_timeout()] to name but three) that are methods on an |
1286 | ** sqlite3 object. |
1287 | */ |
1288 | typedef struct sqlite3 sqlite3; |
1289 | |
1290 | /* |
1291 | ** CAPI3REF: 64-Bit Integer Types |
1292 | ** KEYWORDS: sqlite_int64 sqlite_uint64 |
1293 | ** |
1294 | ** Because there is no cross-platform way to specify 64-bit integer types |
1295 | ** SQLite includes typedefs for 64-bit signed and unsigned integers. |
1296 | ** |
1297 | ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. |
1298 | ** The sqlite_int64 and sqlite_uint64 types are supported for backwards |
1299 | ** compatibility only. |
1300 | ** |
1301 | ** ^The sqlite3_int64 and sqlite_int64 types can store integer values |
1302 | ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The |
1303 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
1304 | ** between 0 and +18446744073709551615 inclusive. |
1305 | */ |
1306 | #ifdef SQLITE_INT64_TYPE |
1307 | typedef SQLITE_INT64_TYPE sqlite_int64; |
1308 | # ifdef SQLITE_UINT64_TYPE |
1309 | typedef SQLITE_UINT64_TYPE sqlite_uint64; |
1310 | # else |
1311 | typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; |
1312 | # endif |
1313 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
1314 | typedef __int64 sqlite_int64; |
1315 | typedef unsigned __int64 sqlite_uint64; |
1316 | #else |
1317 | typedef long long int sqlite_int64; |
1318 | typedef unsigned long long int sqlite_uint64; |
1319 | #endif |
1320 | typedef sqlite_int64 sqlite3_int64; |
1321 | typedef sqlite_uint64 sqlite3_uint64; |
1322 | |
1323 | /* |
1324 | ** If compiling for a processor that lacks floating point support, |
1325 | ** substitute integer for floating-point. |
1326 | */ |
1327 | #ifdef SQLITE_OMIT_FLOATING_POINT |
1328 | # define double sqlite3_int64 |
1329 | #endif |
1330 | |
1331 | /* |
1332 | ** CAPI3REF: Closing A Database Connection |
1333 | ** DESTRUCTOR: sqlite3 |
1334 | ** |
1335 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
1336 | ** for the [sqlite3] object. |
1337 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
1338 | ** the [sqlite3] object is successfully destroyed and all associated |
1339 | ** resources are deallocated. |
1340 | ** |
1341 | ** ^If the database connection is associated with unfinalized prepared |
1342 | ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
1343 | ** will leave the database connection open and return [SQLITE_BUSY]. |
1344 | ** ^If sqlite3_close_v2() is called with unfinalized prepared statements |
1345 | ** and/or unfinished sqlite3_backups, then the database connection becomes |
1346 | ** an unusable "zombie" which will automatically be deallocated when the |
1347 | ** last prepared statement is finalized or the last sqlite3_backup is |
1348 | ** finished. The sqlite3_close_v2() interface is intended for use with |
1349 | ** host languages that are garbage collected, and where the order in which |
1350 | ** destructors are called is arbitrary. |
1351 | ** |
1352 | ** Applications should [sqlite3_finalize | finalize] all [prepared statements], |
1353 | ** [sqlite3_blob_close | close] all [BLOB handles], and |
1354 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
1355 | ** with the [sqlite3] object prior to attempting to close the object. ^If |
1356 | ** sqlite3_close_v2() is called on a [database connection] that still has |
1357 | ** outstanding [prepared statements], [BLOB handles], and/or |
1358 | ** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation |
1359 | ** of resources is deferred until all [prepared statements], [BLOB handles], |
1360 | ** and [sqlite3_backup] objects are also destroyed. |
1361 | ** |
1362 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
1363 | ** the transaction is automatically rolled back. |
1364 | ** |
1365 | ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)] |
1366 | ** must be either a NULL |
1367 | ** pointer or an [sqlite3] object pointer obtained |
1368 | ** from [sqlite3_open()], [sqlite3_open16()], or |
1369 | ** [sqlite3_open_v2()], and not previously closed. |
1370 | ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer |
1371 | ** argument is a harmless no-op. |
1372 | */ |
1373 | SQLITE_API int sqlite3_close(sqlite3*); |
1374 | SQLITE_API int sqlite3_close_v2(sqlite3*); |
1375 | |
1376 | /* |
1377 | ** The type for a callback function. |
1378 | ** This is legacy and deprecated. It is included for historical |
1379 | ** compatibility and is not documented. |
1380 | */ |
1381 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
1382 | |
1383 | /* |
1384 | ** CAPI3REF: One-Step Query Execution Interface |
1385 | ** METHOD: sqlite3 |
1386 | ** |
1387 | ** The sqlite3_exec() interface is a convenience wrapper around |
1388 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
1389 | ** that allows an application to run multiple statements of SQL |
1390 | ** without having to use a lot of C code. |
1391 | ** |
1392 | ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, |
1393 | ** semicolon-separate SQL statements passed into its 2nd argument, |
1394 | ** in the context of the [database connection] passed in as its 1st |
1395 | ** argument. ^If the callback function of the 3rd argument to |
1396 | ** sqlite3_exec() is not NULL, then it is invoked for each result row |
1397 | ** coming out of the evaluated SQL statements. ^The 4th argument to |
1398 | ** sqlite3_exec() is relayed through to the 1st argument of each |
1399 | ** callback invocation. ^If the callback pointer to sqlite3_exec() |
1400 | ** is NULL, then no callback is ever invoked and result rows are |
1401 | ** ignored. |
1402 | ** |
1403 | ** ^If an error occurs while evaluating the SQL statements passed into |
1404 | ** sqlite3_exec(), then execution of the current statement stops and |
1405 | ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() |
1406 | ** is not NULL then any error message is written into memory obtained |
1407 | ** from [sqlite3_malloc()] and passed back through the 5th parameter. |
1408 | ** To avoid memory leaks, the application should invoke [sqlite3_free()] |
1409 | ** on error message strings returned through the 5th parameter of |
1410 | ** sqlite3_exec() after the error message string is no longer needed. |
1411 | ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors |
1412 | ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to |
1413 | ** NULL before returning. |
1414 | ** |
1415 | ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() |
1416 | ** routine returns SQLITE_ABORT without invoking the callback again and |
1417 | ** without running any subsequent SQL statements. |
1418 | ** |
1419 | ** ^The 2nd argument to the sqlite3_exec() callback function is the |
1420 | ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() |
1421 | ** callback is an array of pointers to strings obtained as if from |
1422 | ** [sqlite3_column_text()], one for each column. ^If an element of a |
1423 | ** result row is NULL then the corresponding string pointer for the |
1424 | ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the |
1425 | ** sqlite3_exec() callback is an array of pointers to strings where each |
1426 | ** entry represents the name of corresponding result column as obtained |
1427 | ** from [sqlite3_column_name()]. |
1428 | ** |
1429 | ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer |
1430 | ** to an empty string, or a pointer that contains only whitespace and/or |
1431 | ** SQL comments, then no SQL statements are evaluated and the database |
1432 | ** is not changed. |
1433 | ** |
1434 | ** Restrictions: |
1435 | ** |
1436 | ** <ul> |
1437 | ** <li> The application must ensure that the 1st parameter to sqlite3_exec() |
1438 | ** is a valid and open [database connection]. |
1439 | ** <li> The application must not close the [database connection] specified by |
1440 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
1441 | ** <li> The application must not modify the SQL statement text passed into |
1442 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
1443 | ** </ul> |
1444 | */ |
1445 | SQLITE_API int sqlite3_exec( |
1446 | sqlite3*, /* An open database */ |
1447 | const char *sql, /* SQL to be evaluated */ |
1448 | int (*callback)(void*,int,char**,char**), /* Callback function */ |
1449 | void *, /* 1st argument to callback */ |
1450 | char **errmsg /* Error msg written here */ |
1451 | ); |
1452 | |
1453 | /* |
1454 | ** CAPI3REF: Result Codes |
1455 | ** KEYWORDS: {result code definitions} |
1456 | ** |
1457 | ** Many SQLite functions return an integer result code from the set shown |
1458 | ** here in order to indicate success or failure. |
1459 | ** |
1460 | ** New error codes may be added in future versions of SQLite. |
1461 | ** |
1462 | ** See also: [extended result code definitions] |
1463 | */ |
1464 | #define SQLITE_OK 0 /* Successful result */ |
1465 | /* beginning-of-error-codes */ |
1466 | #define SQLITE_ERROR 1 /* Generic error */ |
1467 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
1468 | #define SQLITE_PERM 3 /* Access permission denied */ |
1469 | #define SQLITE_ABORT 4 /* Callback routine requested an abort */ |
1470 | #define SQLITE_BUSY 5 /* The database file is locked */ |
1471 | #define SQLITE_LOCKED 6 /* A table in the database is locked */ |
1472 | #define SQLITE_NOMEM 7 /* A malloc() failed */ |
1473 | #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ |
1474 | #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ |
1475 | #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ |
1476 | #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ |
1477 | #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ |
1478 | #define SQLITE_FULL 13 /* Insertion failed because database is full */ |
1479 | #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ |
1480 | #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ |
1481 | #define SQLITE_EMPTY 16 /* Internal use only */ |
1482 | #define SQLITE_SCHEMA 17 /* The database schema changed */ |
1483 | #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ |
1484 | #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ |
1485 | #define SQLITE_MISMATCH 20 /* Data type mismatch */ |
1486 | #define SQLITE_MISUSE 21 /* Library used incorrectly */ |
1487 | #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ |
1488 | #define SQLITE_AUTH 23 /* Authorization denied */ |
1489 | #define SQLITE_FORMAT 24 /* Not used */ |
1490 | #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ |
1491 | #define SQLITE_NOTADB 26 /* File opened that is not a database file */ |
1492 | #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ |
1493 | #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ |
1494 | #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ |
1495 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
1496 | /* end-of-error-codes */ |
1497 | |
1498 | /* |
1499 | ** CAPI3REF: Extended Result Codes |
1500 | ** KEYWORDS: {extended result code definitions} |
1501 | ** |
1502 | ** In its default configuration, SQLite API routines return one of 30 integer |
1503 | ** [result codes]. However, experience has shown that many of |
1504 | ** these result codes are too coarse-grained. They do not provide as |
1505 | ** much information about problems as programmers might like. In an effort to |
1506 | ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8] |
1507 | ** and later) include |
1508 | ** support for additional result codes that provide more detailed information |
1509 | ** about errors. These [extended result codes] are enabled or disabled |
1510 | ** on a per database connection basis using the |
1511 | ** [sqlite3_extended_result_codes()] API. Or, the extended code for |
1512 | ** the most recent error can be obtained using |
1513 | ** [sqlite3_extended_errcode()]. |
1514 | */ |
1515 | #define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) |
1516 | #define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) |
1517 | #define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8)) |
1518 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
1519 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
1520 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
1521 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
1522 | #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) |
1523 | #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) |
1524 | #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) |
1525 | #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) |
1526 | #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) |
1527 | #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) |
1528 | #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) |
1529 | #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) |
1530 | #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) |
1531 | #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) |
1532 | #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) |
1533 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
1534 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
1535 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
1536 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
1537 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
1538 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
1539 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
1540 | #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) |
1541 | #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) |
1542 | #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) |
1543 | #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) |
1544 | #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) |
1545 | #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) |
1546 | #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8)) |
1547 | #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8)) |
1548 | #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8)) |
1549 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
1550 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
1551 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
1552 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
1553 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
1554 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
1555 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
1556 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
1557 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
1558 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
1559 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
1560 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
1561 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
1562 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
1563 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
1564 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
1565 | #define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) |
1566 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
1567 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
1568 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
1569 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
1570 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
1571 | #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) |
1572 | #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) |
1573 | #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) |
1574 | #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) |
1575 | #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) |
1576 | #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) |
1577 | #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
1578 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
1579 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
1580 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
1581 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
1582 | |
1583 | /* |
1584 | ** CAPI3REF: Flags For File Open Operations |
1585 | ** |
1586 | ** These bit values are intended for use in the |
1587 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
1588 | ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. |
1589 | */ |
1590 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
1591 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
1592 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
1593 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
1594 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
1595 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
1596 | #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ |
1597 | #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ |
1598 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
1599 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
1600 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
1601 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
1602 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
1603 | #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ |
1604 | #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ |
1605 | #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ |
1606 | #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
1607 | #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
1608 | #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
1609 | #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
1610 | |
1611 | /* Reserved: 0x00F00000 */ |
1612 | |
1613 | /* |
1614 | ** CAPI3REF: Device Characteristics |
1615 | ** |
1616 | ** The xDeviceCharacteristics method of the [sqlite3_io_methods] |
1617 | ** object returns an integer which is a vector of these |
1618 | ** bit values expressing I/O characteristics of the mass storage |
1619 | ** device that holds the file that the [sqlite3_io_methods] |
1620 | ** refers to. |
1621 | ** |
1622 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
1623 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
1624 | ** mean that writes of blocks that are nnn bytes in size and |
1625 | ** are aligned to an address which is an integer multiple of |
1626 | ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means |
1627 | ** that when data is appended to a file, the data is appended |
1628 | ** first then the size of the file is extended, never the other |
1629 | ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that |
1630 | ** information is written to disk in the same order as calls |
1631 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
1632 | ** after reboot following a crash or power loss, the only bytes in a |
1633 | ** file that were written at the application level might have changed |
1634 | ** and that adjacent bytes, even bytes within the same sector are |
1635 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
1636 | ** flag indicates that a file cannot be deleted when open. The |
1637 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
1638 | ** read-only media and cannot be changed even by processes with |
1639 | ** elevated privileges. |
1640 | ** |
1641 | ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying |
1642 | ** filesystem supports doing multiple write operations atomically when those |
1643 | ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and |
1644 | ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. |
1645 | */ |
1646 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
1647 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
1648 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
1649 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
1650 | #define SQLITE_IOCAP_ATOMIC4K 0x00000010 |
1651 | #define SQLITE_IOCAP_ATOMIC8K 0x00000020 |
1652 | #define SQLITE_IOCAP_ATOMIC16K 0x00000040 |
1653 | #define SQLITE_IOCAP_ATOMIC32K 0x00000080 |
1654 | #define SQLITE_IOCAP_ATOMIC64K 0x00000100 |
1655 | #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 |
1656 | #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 |
1657 | #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 |
1658 | #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 |
1659 | #define SQLITE_IOCAP_IMMUTABLE 0x00002000 |
1660 | #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 |
1661 | |
1662 | /* |
1663 | ** CAPI3REF: File Locking Levels |
1664 | ** |
1665 | ** SQLite uses one of these integer values as the second |
1666 | ** argument to calls it makes to the xLock() and xUnlock() methods |
1667 | ** of an [sqlite3_io_methods] object. |
1668 | */ |
1669 | #define SQLITE_LOCK_NONE 0 |
1670 | #define SQLITE_LOCK_SHARED 1 |
1671 | #define SQLITE_LOCK_RESERVED 2 |
1672 | #define SQLITE_LOCK_PENDING 3 |
1673 | #define SQLITE_LOCK_EXCLUSIVE 4 |
1674 | |
1675 | /* |
1676 | ** CAPI3REF: Synchronization Type Flags |
1677 | ** |
1678 | ** When SQLite invokes the xSync() method of an |
1679 | ** [sqlite3_io_methods] object it uses a combination of |
1680 | ** these integer values as the second argument. |
1681 | ** |
1682 | ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the |
1683 | ** sync operation only needs to flush data to mass storage. Inode |
1684 | ** information need not be flushed. If the lower four bits of the flag |
1685 | ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. |
1686 | ** If the lower four bits equal SQLITE_SYNC_FULL, that means |
1687 | ** to use Mac OS X style fullsync instead of fsync(). |
1688 | ** |
1689 | ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags |
1690 | ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL |
1691 | ** settings. The [synchronous pragma] determines when calls to the |
1692 | ** xSync VFS method occur and applies uniformly across all platforms. |
1693 | ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how |
1694 | ** energetic or rigorous or forceful the sync operations are and |
1695 | ** only make a difference on Mac OSX for the default SQLite code. |
1696 | ** (Third-party VFS implementations might also make the distinction |
1697 | ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the |
1698 | ** operating systems natively supported by SQLite, only Mac OSX |
1699 | ** cares about the difference.) |
1700 | */ |
1701 | #define SQLITE_SYNC_NORMAL 0x00002 |
1702 | #define SQLITE_SYNC_FULL 0x00003 |
1703 | #define SQLITE_SYNC_DATAONLY 0x00010 |
1704 | |
1705 | /* |
1706 | ** CAPI3REF: OS Interface Open File Handle |
1707 | ** |
1708 | ** An [sqlite3_file] object represents an open file in the |
1709 | ** [sqlite3_vfs | OS interface layer]. Individual OS interface |
1710 | ** implementations will |
1711 | ** want to subclass this object by appending additional fields |
1712 | ** for their own use. The pMethods entry is a pointer to an |
1713 | ** [sqlite3_io_methods] object that defines methods for performing |
1714 | ** I/O operations on the open file. |
1715 | */ |
1716 | typedef struct sqlite3_file sqlite3_file; |
1717 | struct sqlite3_file { |
1718 | const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ |
1719 | }; |
1720 | |
1721 | /* |
1722 | ** CAPI3REF: OS Interface File Virtual Methods Object |
1723 | ** |
1724 | ** Every file opened by the [sqlite3_vfs.xOpen] method populates an |
1725 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
1726 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
1727 | ** This object defines the methods used to perform various operations |
1728 | ** against the open file represented by the [sqlite3_file] object. |
1729 | ** |
1730 | ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element |
1731 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
1732 | ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The |
1733 | ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] |
1734 | ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element |
1735 | ** to NULL. |
1736 | ** |
1737 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
1738 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
1739 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
1740 | ** flag may be ORed in to indicate that only the data of the file |
1741 | ** and not its inode needs to be synced. |
1742 | ** |
1743 | ** The integer values to xLock() and xUnlock() are one of |
1744 | ** <ul> |
1745 | ** <li> [SQLITE_LOCK_NONE], |
1746 | ** <li> [SQLITE_LOCK_SHARED], |
1747 | ** <li> [SQLITE_LOCK_RESERVED], |
1748 | ** <li> [SQLITE_LOCK_PENDING], or |
1749 | ** <li> [SQLITE_LOCK_EXCLUSIVE]. |
1750 | ** </ul> |
1751 | ** xLock() increases the lock. xUnlock() decreases the lock. |
1752 | ** The xCheckReservedLock() method checks whether any database connection, |
1753 | ** either in this process or in some other process, is holding a RESERVED, |
1754 | ** PENDING, or EXCLUSIVE lock on the file. It returns true |
1755 | ** if such a lock exists and false otherwise. |
1756 | ** |
1757 | ** The xFileControl() method is a generic interface that allows custom |
1758 | ** VFS implementations to directly control an open file using the |
1759 | ** [sqlite3_file_control()] interface. The second "op" argument is an |
1760 | ** integer opcode. The third argument is a generic pointer intended to |
1761 | ** point to a structure that may contain arguments or space in which to |
1762 | ** write return values. Potential uses for xFileControl() might be |
1763 | ** functions to enable blocking locks with timeouts, to change the |
1764 | ** locking strategy (for example to use dot-file locks), to inquire |
1765 | ** about the status of a lock, or to break stale locks. The SQLite |
1766 | ** core reserves all opcodes less than 100 for its own use. |
1767 | ** A [file control opcodes | list of opcodes] less than 100 is available. |
1768 | ** Applications that define a custom xFileControl method should use opcodes |
1769 | ** greater than 100 to avoid conflicts. VFS implementations should |
1770 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
1771 | ** recognize. |
1772 | ** |
1773 | ** The xSectorSize() method returns the sector size of the |
1774 | ** device that underlies the file. The sector size is the |
1775 | ** minimum write that can be performed without disturbing |
1776 | ** other bytes in the file. The xDeviceCharacteristics() |
1777 | ** method returns a bit vector describing behaviors of the |
1778 | ** underlying device: |
1779 | ** |
1780 | ** <ul> |
1781 | ** <li> [SQLITE_IOCAP_ATOMIC] |
1782 | ** <li> [SQLITE_IOCAP_ATOMIC512] |
1783 | ** <li> [SQLITE_IOCAP_ATOMIC1K] |
1784 | ** <li> [SQLITE_IOCAP_ATOMIC2K] |
1785 | ** <li> [SQLITE_IOCAP_ATOMIC4K] |
1786 | ** <li> [SQLITE_IOCAP_ATOMIC8K] |
1787 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
1788 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
1789 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
1790 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
1791 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
1792 | ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] |
1793 | ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] |
1794 | ** <li> [SQLITE_IOCAP_IMMUTABLE] |
1795 | ** <li> [SQLITE_IOCAP_BATCH_ATOMIC] |
1796 | ** </ul> |
1797 | ** |
1798 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
1799 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
1800 | ** mean that writes of blocks that are nnn bytes in size and |
1801 | ** are aligned to an address which is an integer multiple of |
1802 | ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means |
1803 | ** that when data is appended to a file, the data is appended |
1804 | ** first then the size of the file is extended, never the other |
1805 | ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that |
1806 | ** information is written to disk in the same order as calls |
1807 | ** to xWrite(). |
1808 | ** |
1809 | ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill |
1810 | ** in the unread portions of the buffer with zeros. A VFS that |
1811 | ** fails to zero-fill short reads might seem to work. However, |
1812 | ** failure to zero-fill short reads will eventually lead to |
1813 | ** database corruption. |
1814 | */ |
1815 | typedef struct sqlite3_io_methods sqlite3_io_methods; |
1816 | struct sqlite3_io_methods { |
1817 | int iVersion; |
1818 | int (*xClose)(sqlite3_file*); |
1819 | int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
1820 | int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); |
1821 | int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); |
1822 | int (*xSync)(sqlite3_file*, int flags); |
1823 | int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); |
1824 | int (*xLock)(sqlite3_file*, int); |
1825 | int (*xUnlock)(sqlite3_file*, int); |
1826 | int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); |
1827 | int (*xFileControl)(sqlite3_file*, int op, void *pArg); |
1828 | int (*xSectorSize)(sqlite3_file*); |
1829 | int (*xDeviceCharacteristics)(sqlite3_file*); |
1830 | /* Methods above are valid for version 1 */ |
1831 | int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); |
1832 | int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); |
1833 | void (*xShmBarrier)(sqlite3_file*); |
1834 | int (*xShmUnmap)(sqlite3_file*, int deleteFlag); |
1835 | /* Methods above are valid for version 2 */ |
1836 | int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); |
1837 | int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p); |
1838 | /* Methods above are valid for version 3 */ |
1839 | /* Additional methods may be added in future releases */ |
1840 | }; |
1841 | |
1842 | /* |
1843 | ** CAPI3REF: Standard File Control Opcodes |
1844 | ** KEYWORDS: {file control opcodes} {file control opcode} |
1845 | ** |
1846 | ** These integer constants are opcodes for the xFileControl method |
1847 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
1848 | ** interface. |
1849 | ** |
1850 | ** <ul> |
1851 | ** <li>[[SQLITE_FCNTL_LOCKSTATE]] |
1852 | ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This |
1853 | ** opcode causes the xFileControl method to write the current state of |
1854 | ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], |
1855 | ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) |
1856 | ** into an integer that the pArg argument points to. This capability |
1857 | ** is used during testing and is only available when the SQLITE_TEST |
1858 | ** compile-time option is used. |
1859 | ** |
1860 | ** <li>[[SQLITE_FCNTL_SIZE_HINT]] |
1861 | ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS |
1862 | ** layer a hint of how large the database file will grow to be during the |
1863 | ** current transaction. This hint is not guaranteed to be accurate but it |
1864 | ** is often close. The underlying VFS might choose to preallocate database |
1865 | ** file space based on this hint in order to help writes to the database |
1866 | ** file run faster. |
1867 | ** |
1868 | ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]] |
1869 | ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that |
1870 | ** implements [sqlite3_deserialize()] to set an upper bound on the size |
1871 | ** of the in-memory database. The argument is a pointer to a [sqlite3_int64]. |
1872 | ** If the integer pointed to is negative, then it is filled in with the |
1873 | ** current limit. Otherwise the limit is set to the larger of the value |
1874 | ** of the integer pointed to and the current database size. The integer |
1875 | ** pointed to is set to the new limit. |
1876 | ** |
1877 | ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]] |
1878 | ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS |
1879 | ** extends and truncates the database file in chunks of a size specified |
1880 | ** by the user. The fourth argument to [sqlite3_file_control()] should |
1881 | ** point to an integer (type int) containing the new chunk-size to use |
1882 | ** for the nominated database. Allocating database file space in large |
1883 | ** chunks (say 1MB at a time), may reduce file-system fragmentation and |
1884 | ** improve performance on some systems. |
1885 | ** |
1886 | ** <li>[[SQLITE_FCNTL_FILE_POINTER]] |
1887 | ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer |
1888 | ** to the [sqlite3_file] object associated with a particular database |
1889 | ** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER]. |
1890 | ** |
1891 | ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]] |
1892 | ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer |
1893 | ** to the [sqlite3_file] object associated with the journal file (either |
1894 | ** the [rollback journal] or the [write-ahead log]) for a particular database |
1895 | ** connection. See also [SQLITE_FCNTL_FILE_POINTER]. |
1896 | ** |
1897 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
1898 | ** No longer in use. |
1899 | ** |
1900 | ** <li>[[SQLITE_FCNTL_SYNC]] |
1901 | ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and |
1902 | ** sent to the VFS immediately before the xSync method is invoked on a |
1903 | ** database file descriptor. Or, if the xSync method is not invoked |
1904 | ** because the user has configured SQLite with |
1905 | ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place |
1906 | ** of the xSync method. In most cases, the pointer argument passed with |
1907 | ** this file-control is NULL. However, if the database file is being synced |
1908 | ** as part of a multi-database commit, the argument points to a nul-terminated |
1909 | ** string containing the transactions master-journal file name. VFSes that |
1910 | ** do not need this signal should silently ignore this opcode. Applications |
1911 | ** should not call [sqlite3_file_control()] with this opcode as doing so may |
1912 | ** disrupt the operation of the specialized VFSes that do require it. |
1913 | ** |
1914 | ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] |
1915 | ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite |
1916 | ** and sent to the VFS after a transaction has been committed immediately |
1917 | ** but before the database is unlocked. VFSes that do not need this signal |
1918 | ** should silently ignore this opcode. Applications should not call |
1919 | ** [sqlite3_file_control()] with this opcode as doing so may disrupt the |
1920 | ** operation of the specialized VFSes that do require it. |
1921 | ** |
1922 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
1923 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
1924 | ** retry counts and intervals for certain disk I/O operations for the |
1925 | ** windows [VFS] in order to provide robustness in the presence of |
1926 | ** anti-virus programs. By default, the windows VFS will retry file read, |
1927 | ** file write, and file delete operations up to 10 times, with a delay |
1928 | ** of 25 milliseconds before the first retry and with the delay increasing |
1929 | ** by an additional 25 milliseconds with each subsequent retry. This |
1930 | ** opcode allows these two values (10 retries and 25 milliseconds of delay) |
1931 | ** to be adjusted. The values are changed for all database connections |
1932 | ** within the same process. The argument is a pointer to an array of two |
1933 | ** integers where the first integer is the new retry count and the second |
1934 | ** integer is the delay. If either integer is negative, then the setting |
1935 | ** is not changed but instead the prior value of that setting is written |
1936 | ** into the array entry, allowing the current retry settings to be |
1937 | ** interrogated. The zDbName parameter is ignored. |
1938 | ** |
1939 | ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] |
1940 | ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the |
1941 | ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary |
1942 | ** write ahead log ([WAL file]) and shared memory |
1943 | ** files used for transaction control |
1944 | ** are automatically deleted when the latest connection to the database |
1945 | ** closes. Setting persistent WAL mode causes those files to persist after |
1946 | ** close. Persisting the files is useful when other processes that do not |
1947 | ** have write permission on the directory containing the database file want |
1948 | ** to read the database file, as the WAL and shared memory files must exist |
1949 | ** in order for the database to be readable. The fourth parameter to |
1950 | ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
1951 | ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent |
1952 | ** WAL mode. If the integer is -1, then it is overwritten with the current |
1953 | ** WAL persistence setting. |
1954 | ** |
1955 | ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]] |
1956 | ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the |
1957 | ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting |
1958 | ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the |
1959 | ** xDeviceCharacteristics methods. The fourth parameter to |
1960 | ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
1961 | ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage |
1962 | ** mode. If the integer is -1, then it is overwritten with the current |
1963 | ** zero-damage mode setting. |
1964 | ** |
1965 | ** <li>[[SQLITE_FCNTL_OVERWRITE]] |
1966 | ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening |
1967 | ** a write transaction to indicate that, unless it is rolled back for some |
1968 | ** reason, the entire database file will be overwritten by the current |
1969 | ** transaction. This is used by VACUUM operations. |
1970 | ** |
1971 | ** <li>[[SQLITE_FCNTL_VFSNAME]] |
1972 | ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of |
1973 | ** all [VFSes] in the VFS stack. The names are of all VFS shims and the |
1974 | ** final bottom-level VFS are written into memory obtained from |
1975 | ** [sqlite3_malloc()] and the result is stored in the char* variable |
1976 | ** that the fourth parameter of [sqlite3_file_control()] points to. |
1977 | ** The caller is responsible for freeing the memory when done. As with |
1978 | ** all file-control actions, there is no guarantee that this will actually |
1979 | ** do anything. Callers should initialize the char* variable to a NULL |
1980 | ** pointer in case this file-control is not implemented. This file-control |
1981 | ** is intended for diagnostic use only. |
1982 | ** |
1983 | ** <li>[[SQLITE_FCNTL_VFS_POINTER]] |
1984 | ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level |
1985 | ** [VFSes] currently in use. ^(The argument X in |
1986 | ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be |
1987 | ** of type "[sqlite3_vfs] **". This opcodes will set *X |
1988 | ** to a pointer to the top-level VFS.)^ |
1989 | ** ^When there are multiple VFS shims in the stack, this opcode finds the |
1990 | ** upper-most shim only. |
1991 | ** |
1992 | ** <li>[[SQLITE_FCNTL_PRAGMA]] |
1993 | ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] |
1994 | ** file control is sent to the open [sqlite3_file] object corresponding |
1995 | ** to the database file to which the pragma statement refers. ^The argument |
1996 | ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of |
1997 | ** pointers to strings (char**) in which the second element of the array |
1998 | ** is the name of the pragma and the third element is the argument to the |
1999 | ** pragma or NULL if the pragma has no argument. ^The handler for an |
2000 | ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element |
2001 | ** of the char** argument point to a string obtained from [sqlite3_mprintf()] |
2002 | ** or the equivalent and that string will become the result of the pragma or |
2003 | ** the error message if the pragma fails. ^If the |
2004 | ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal |
2005 | ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA] |
2006 | ** file control returns [SQLITE_OK], then the parser assumes that the |
2007 | ** VFS has handled the PRAGMA itself and the parser generates a no-op |
2008 | ** prepared statement if result string is NULL, or that returns a copy |
2009 | ** of the result string if the string is non-NULL. |
2010 | ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns |
2011 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
2012 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
2013 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
2014 | ** file control occurs at the beginning of pragma statement analysis and so |
2015 | ** it is able to override built-in [PRAGMA] statements. |
2016 | ** |
2017 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
2018 | ** ^The [SQLITE_FCNTL_BUSYHANDLER] |
2019 | ** file-control may be invoked by SQLite on the database file handle |
2020 | ** shortly after it is opened in order to provide a custom VFS with access |
2021 | ** to the connections busy-handler callback. The argument is of type (void **) |
2022 | ** - an array of two (void *) values. The first (void *) actually points |
2023 | ** to a function of type (int (*)(void *)). In order to invoke the connections |
2024 | ** busy-handler, this function should be invoked with the second (void *) in |
2025 | ** the array as the only argument. If it returns non-zero, then the operation |
2026 | ** should be retried. If it returns zero, the custom VFS should abandon the |
2027 | ** current operation. |
2028 | ** |
2029 | ** <li>[[SQLITE_FCNTL_TEMPFILENAME]] |
2030 | ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control |
2031 | ** to have SQLite generate a |
2032 | ** temporary filename using the same algorithm that is followed to generate |
2033 | ** temporary filenames for TEMP tables and other internal uses. The |
2034 | ** argument should be a char** which will be filled with the filename |
2035 | ** written into memory obtained from [sqlite3_malloc()]. The caller should |
2036 | ** invoke [sqlite3_free()] on the result to avoid a memory leak. |
2037 | ** |
2038 | ** <li>[[SQLITE_FCNTL_MMAP_SIZE]] |
2039 | ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the |
2040 | ** maximum number of bytes that will be used for memory-mapped I/O. |
2041 | ** The argument is a pointer to a value of type sqlite3_int64 that |
2042 | ** is an advisory maximum number of bytes in the file to memory map. The |
2043 | ** pointer is overwritten with the old value. The limit is not changed if |
2044 | ** the value originally pointed to is negative, and so the current limit |
2045 | ** can be queried by passing in a pointer to a negative number. This |
2046 | ** file-control is used internally to implement [PRAGMA mmap_size]. |
2047 | ** |
2048 | ** <li>[[SQLITE_FCNTL_TRACE]] |
2049 | ** The [SQLITE_FCNTL_TRACE] file control provides advisory information |
2050 | ** to the VFS about what the higher layers of the SQLite stack are doing. |
2051 | ** This file control is used by some VFS activity tracing [shims]. |
2052 | ** The argument is a zero-terminated string. Higher layers in the |
2053 | ** SQLite stack may generate instances of this file control if |
2054 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
2055 | ** |
2056 | ** <li>[[SQLITE_FCNTL_HAS_MOVED]] |
2057 | ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a |
2058 | ** pointer to an integer and it writes a boolean into that integer depending |
2059 | ** on whether or not the file has been renamed, moved, or deleted since it |
2060 | ** was first opened. |
2061 | ** |
2062 | ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]] |
2063 | ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the |
2064 | ** underlying native file handle associated with a file handle. This file |
2065 | ** control interprets its argument as a pointer to a native file handle and |
2066 | ** writes the resulting value there. |
2067 | ** |
2068 | ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]] |
2069 | ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This |
2070 | ** opcode causes the xFileControl method to swap the file handle with the one |
2071 | ** pointed to by the pArg argument. This capability is used during testing |
2072 | ** and only needs to be supported when SQLITE_TEST is defined. |
2073 | ** |
2074 | ** <li>[[SQLITE_FCNTL_WAL_BLOCK]] |
2075 | ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might |
2076 | ** be advantageous to block on the next WAL lock if the lock is not immediately |
2077 | ** available. The WAL subsystem issues this signal during rare |
2078 | ** circumstances in order to fix a problem with priority inversion. |
2079 | ** Applications should <em>not</em> use this file-control. |
2080 | ** |
2081 | ** <li>[[SQLITE_FCNTL_ZIPVFS]] |
2082 | ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other |
2083 | ** VFS should return SQLITE_NOTFOUND for this opcode. |
2084 | ** |
2085 | ** <li>[[SQLITE_FCNTL_RBU]] |
2086 | ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by |
2087 | ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for |
2088 | ** this opcode. |
2089 | ** |
2090 | ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]] |
2091 | ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then |
2092 | ** the file descriptor is placed in "batch write mode", which |
2093 | ** means all subsequent write operations will be deferred and done |
2094 | ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems |
2095 | ** that do not support batch atomic writes will return SQLITE_NOTFOUND. |
2096 | ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to |
2097 | ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or |
2098 | ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make |
2099 | ** no VFS interface calls on the same [sqlite3_file] file descriptor |
2100 | ** except for calls to the xWrite method and the xFileControl method |
2101 | ** with [SQLITE_FCNTL_SIZE_HINT]. |
2102 | ** |
2103 | ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]] |
2104 | ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write |
2105 | ** operations since the previous successful call to |
2106 | ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically. |
2107 | ** This file control returns [SQLITE_OK] if and only if the writes were |
2108 | ** all performed successfully and have been committed to persistent storage. |
2109 | ** ^Regardless of whether or not it is successful, this file control takes |
2110 | ** the file descriptor out of batch write mode so that all subsequent |
2111 | ** write operations are independent. |
2112 | ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without |
2113 | ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. |
2114 | ** |
2115 | ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]] |
2116 | ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write |
2117 | ** operations since the previous successful call to |
2118 | ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back. |
2119 | ** ^This file control takes the file descriptor out of batch write mode |
2120 | ** so that all subsequent write operations are independent. |
2121 | ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without |
2122 | ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. |
2123 | ** |
2124 | ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]] |
2125 | ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain |
2126 | ** a file lock using the xLock or xShmLock methods of the VFS to wait |
2127 | ** for up to M milliseconds before failing, where M is the single |
2128 | ** unsigned integer parameter. |
2129 | ** |
2130 | ** <li>[[SQLITE_FCNTL_DATA_VERSION]] |
2131 | ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to |
2132 | ** a database file. The argument is a pointer to a 32-bit unsigned integer. |
2133 | ** The "data version" for the pager is written into the pointer. The |
2134 | ** "data version" changes whenever any change occurs to the corresponding |
2135 | ** database file, either through SQL statements on the same database |
2136 | ** connection or through transactions committed by separate database |
2137 | ** connections possibly in other processes. The [sqlite3_total_changes()] |
2138 | ** interface can be used to find if any database on the connection has changed, |
2139 | ** but that interface responds to changes on TEMP as well as MAIN and does |
2140 | ** not provide a mechanism to detect changes to MAIN only. Also, the |
2141 | ** [sqlite3_total_changes()] interface responds to internal changes only and |
2142 | ** omits changes made by other database connections. The |
2143 | ** [PRAGMA data_version] command provide a mechanism to detect changes to |
2144 | ** a single attached database that occur due to other database connections, |
2145 | ** but omits changes implemented by the database connection on which it is |
2146 | ** called. This file control is the only mechanism to detect changes that |
2147 | ** happen either internally or externally and that are associated with |
2148 | ** a particular attached database. |
2149 | ** </ul> |
2150 | */ |
2151 | #define SQLITE_FCNTL_LOCKSTATE 1 |
2152 | #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 |
2153 | #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 |
2154 | #define SQLITE_FCNTL_LAST_ERRNO 4 |
2155 | #define SQLITE_FCNTL_SIZE_HINT 5 |
2156 | #define SQLITE_FCNTL_CHUNK_SIZE 6 |
2157 | #define SQLITE_FCNTL_FILE_POINTER 7 |
2158 | #define SQLITE_FCNTL_SYNC_OMITTED 8 |
2159 | #define SQLITE_FCNTL_WIN32_AV_RETRY 9 |
2160 | #define SQLITE_FCNTL_PERSIST_WAL 10 |
2161 | #define SQLITE_FCNTL_OVERWRITE 11 |
2162 | #define SQLITE_FCNTL_VFSNAME 12 |
2163 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
2164 | #define SQLITE_FCNTL_PRAGMA 14 |
2165 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
2166 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
2167 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
2168 | #define SQLITE_FCNTL_TRACE 19 |
2169 | #define SQLITE_FCNTL_HAS_MOVED 20 |
2170 | #define SQLITE_FCNTL_SYNC 21 |
2171 | #define SQLITE_FCNTL_COMMIT_PHASETWO 22 |
2172 | #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 |
2173 | #define SQLITE_FCNTL_WAL_BLOCK 24 |
2174 | #define SQLITE_FCNTL_ZIPVFS 25 |
2175 | #define SQLITE_FCNTL_RBU 26 |
2176 | #define SQLITE_FCNTL_VFS_POINTER 27 |
2177 | #define SQLITE_FCNTL_JOURNAL_POINTER 28 |
2178 | #define SQLITE_FCNTL_WIN32_GET_HANDLE 29 |
2179 | #define SQLITE_FCNTL_PDB 30 |
2180 | #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 |
2181 | #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 |
2182 | #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 |
2183 | #define SQLITE_FCNTL_LOCK_TIMEOUT 34 |
2184 | #define SQLITE_FCNTL_DATA_VERSION 35 |
2185 | #define SQLITE_FCNTL_SIZE_LIMIT 36 |
2186 | |
2187 | /* deprecated names */ |
2188 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
2189 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
2190 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
2191 | |
2192 | |
2193 | /* |
2194 | ** CAPI3REF: Mutex Handle |
2195 | ** |
2196 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
2197 | ** abstract type for a mutex object. The SQLite core never looks |
2198 | ** at the internal representation of an [sqlite3_mutex]. It only |
2199 | ** deals with pointers to the [sqlite3_mutex] object. |
2200 | ** |
2201 | ** Mutexes are created using [sqlite3_mutex_alloc()]. |
2202 | */ |
2203 | typedef struct sqlite3_mutex sqlite3_mutex; |
2204 | |
2205 | /* |
2206 | ** CAPI3REF: Loadable Extension Thunk |
2207 | ** |
2208 | ** A pointer to the opaque sqlite3_api_routines structure is passed as |
2209 | ** the third parameter to entry points of [loadable extensions]. This |
2210 | ** structure must be typedefed in order to work around compiler warnings |
2211 | ** on some platforms. |
2212 | */ |
2213 | typedef struct sqlite3_api_routines sqlite3_api_routines; |
2214 | |
2215 | /* |
2216 | ** CAPI3REF: OS Interface Object |
2217 | ** |
2218 | ** An instance of the sqlite3_vfs object defines the interface between |
2219 | ** the SQLite core and the underlying operating system. The "vfs" |
2220 | ** in the name of the object stands for "virtual file system". See |
2221 | ** the [VFS | VFS documentation] for further information. |
2222 | ** |
2223 | ** The VFS interface is sometimes extended by adding new methods onto |
2224 | ** the end. Each time such an extension occurs, the iVersion field |
2225 | ** is incremented. The iVersion value started out as 1 in |
2226 | ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2 |
2227 | ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased |
2228 | ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields |
2229 | ** may be appended to the sqlite3_vfs object and the iVersion value |
2230 | ** may increase again in future versions of SQLite. |
2231 | ** Note that the structure |
2232 | ** of the sqlite3_vfs object changes in the transition from |
2233 | ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0] |
2234 | ** and yet the iVersion field was not modified. |
2235 | ** |
2236 | ** The szOsFile field is the size of the subclassed [sqlite3_file] |
2237 | ** structure used by this VFS. mxPathname is the maximum length of |
2238 | ** a pathname in this VFS. |
2239 | ** |
2240 | ** Registered sqlite3_vfs objects are kept on a linked list formed by |
2241 | ** the pNext pointer. The [sqlite3_vfs_register()] |
2242 | ** and [sqlite3_vfs_unregister()] interfaces manage this list |
2243 | ** in a thread-safe way. The [sqlite3_vfs_find()] interface |
2244 | ** searches the list. Neither the application code nor the VFS |
2245 | ** implementation should use the pNext pointer. |
2246 | ** |
2247 | ** The pNext field is the only field in the sqlite3_vfs |
2248 | ** structure that SQLite will ever modify. SQLite will only access |
2249 | ** or modify this field while holding a particular static mutex. |
2250 | ** The application should never modify anything within the sqlite3_vfs |
2251 | ** object once the object has been registered. |
2252 | ** |
2253 | ** The zName field holds the name of the VFS module. The name must |
2254 | ** be unique across all VFS modules. |
2255 | ** |
2256 | ** [[sqlite3_vfs.xOpen]] |
2257 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
2258 | ** is either a NULL pointer or string obtained |
2259 | ** from xFullPathname() with an optional suffix added. |
2260 | ** ^If a suffix is added to the zFilename parameter, it will |
2261 | ** consist of a single "-" character followed by no more than |
2262 | ** 11 alphanumeric and/or "-" characters. |
2263 | ** ^SQLite further guarantees that |
2264 | ** the string will be valid and unchanged until xClose() is |
2265 | ** called. Because of the previous sentence, |
2266 | ** the [sqlite3_file] can safely store a pointer to the |
2267 | ** filename if it needs to remember the filename for some reason. |
2268 | ** If the zFilename parameter to xOpen is a NULL pointer then xOpen |
2269 | ** must invent its own temporary name for the file. ^Whenever the |
2270 | ** xFilename parameter is NULL it will also be the case that the |
2271 | ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. |
2272 | ** |
2273 | ** The flags argument to xOpen() includes all bits set in |
2274 | ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] |
2275 | ** or [sqlite3_open16()] is used, then flags includes at least |
2276 | ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. |
2277 | ** If xOpen() opens a file read-only then it sets *pOutFlags to |
2278 | ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. |
2279 | ** |
2280 | ** ^(SQLite will also add one of the following flags to the xOpen() |
2281 | ** call, depending on the object being opened: |
2282 | ** |
2283 | ** <ul> |
2284 | ** <li> [SQLITE_OPEN_MAIN_DB] |
2285 | ** <li> [SQLITE_OPEN_MAIN_JOURNAL] |
2286 | ** <li> [SQLITE_OPEN_TEMP_DB] |
2287 | ** <li> [SQLITE_OPEN_TEMP_JOURNAL] |
2288 | ** <li> [SQLITE_OPEN_TRANSIENT_DB] |
2289 | ** <li> [SQLITE_OPEN_SUBJOURNAL] |
2290 | ** <li> [SQLITE_OPEN_MASTER_JOURNAL] |
2291 | ** <li> [SQLITE_OPEN_WAL] |
2292 | ** </ul>)^ |
2293 | ** |
2294 | ** The file I/O implementation can use the object type flags to |
2295 | ** change the way it deals with files. For example, an application |
2296 | ** that does not care about crash recovery or rollback might make |
2297 | ** the open of a journal file a no-op. Writes to this journal would |
2298 | ** also be no-ops, and any attempt to read the journal would return |
2299 | ** SQLITE_IOERR. Or the implementation might recognize that a database |
2300 | ** file will be doing page-aligned sector reads and writes in a random |
2301 | ** order and set up its I/O subsystem accordingly. |
2302 | ** |
2303 | ** SQLite might also add one of the following flags to the xOpen method: |
2304 | ** |
2305 | ** <ul> |
2306 | ** <li> [SQLITE_OPEN_DELETEONCLOSE] |
2307 | ** <li> [SQLITE_OPEN_EXCLUSIVE] |
2308 | ** </ul> |
2309 | ** |
2310 | ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be |
2311 | ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] |
2312 | ** will be set for TEMP databases and their journals, transient |
2313 | ** databases, and subjournals. |
2314 | ** |
2315 | ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction |
2316 | ** with the [SQLITE_OPEN_CREATE] flag, which are both directly |
2317 | ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() |
2318 | ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the |
2319 | ** SQLITE_OPEN_CREATE, is used to indicate that file should always |
2320 | ** be created, and that it is an error if it already exists. |
2321 | ** It is <i>not</i> used to indicate the file should be opened |
2322 | ** for exclusive access. |
2323 | ** |
2324 | ** ^At least szOsFile bytes of memory are allocated by SQLite |
2325 | ** to hold the [sqlite3_file] structure passed as the third |
2326 | ** argument to xOpen. The xOpen method does not have to |
2327 | ** allocate the structure; it should just fill it in. Note that |
2328 | ** the xOpen method must set the sqlite3_file.pMethods to either |
2329 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
2330 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
2331 | ** element will be valid after xOpen returns regardless of the success |
2332 | ** or failure of the xOpen call. |
2333 | ** |
2334 | ** [[sqlite3_vfs.xAccess]] |
2335 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
2336 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
2337 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
2338 | ** to test whether a file is at least readable. The file can be a |
2339 | ** directory. |
2340 | ** |
2341 | ** ^SQLite will always allocate at least mxPathname+1 bytes for the |
2342 | ** output buffer xFullPathname. The exact size of the output buffer |
2343 | ** is also passed as a parameter to both methods. If the output buffer |
2344 | ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is |
2345 | ** handled as a fatal error by SQLite, vfs implementations should endeavor |
2346 | ** to prevent this by setting mxPathname to a sufficiently large value. |
2347 | ** |
2348 | ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() |
2349 | ** interfaces are not strictly a part of the filesystem, but they are |
2350 | ** included in the VFS structure for completeness. |
2351 | ** The xRandomness() function attempts to return nBytes bytes |
2352 | ** of good-quality randomness into zOut. The return value is |
2353 | ** the actual number of bytes of randomness obtained. |
2354 | ** The xSleep() method causes the calling thread to sleep for at |
2355 | ** least the number of microseconds given. ^The xCurrentTime() |
2356 | ** method returns a Julian Day Number for the current date and time as |
2357 | ** a floating point value. |
2358 | ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian |
2359 | ** Day Number multiplied by 86400000 (the number of milliseconds in |
2360 | ** a 24-hour day). |
2361 | ** ^SQLite will use the xCurrentTimeInt64() method to get the current |
2362 | ** date and time if that method is available (if iVersion is 2 or |
2363 | ** greater and the function pointer is not NULL) and will fall back |
2364 | ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. |
2365 | ** |
2366 | ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces |
2367 | ** are not used by the SQLite core. These optional interfaces are provided |
2368 | ** by some VFSes to facilitate testing of the VFS code. By overriding |
2369 | ** system calls with functions under its control, a test program can |
2370 | ** simulate faults and error conditions that would otherwise be difficult |
2371 | ** or impossible to induce. The set of system calls that can be overridden |
2372 | ** varies from one VFS to another, and from one version of the same VFS to the |
2373 | ** next. Applications that use these interfaces must be prepared for any |
2374 | ** or all of these interfaces to be NULL or for their behavior to change |
2375 | ** from one release to the next. Applications must not attempt to access |
2376 | ** any of these methods if the iVersion of the VFS is less than 3. |
2377 | */ |
2378 | typedef struct sqlite3_vfs sqlite3_vfs; |
2379 | typedef void (*sqlite3_syscall_ptr)(void); |
2380 | struct sqlite3_vfs { |
2381 | int iVersion; /* Structure version number (currently 3) */ |
2382 | int szOsFile; /* Size of subclassed sqlite3_file */ |
2383 | int mxPathname; /* Maximum file pathname length */ |
2384 | sqlite3_vfs *pNext; /* Next registered VFS */ |
2385 | const char *zName; /* Name of this virtual file system */ |
2386 | void *pAppData; /* Pointer to application-specific data */ |
2387 | int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, |
2388 | int flags, int *pOutFlags); |
2389 | int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); |
2390 | int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); |
2391 | int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); |
2392 | void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); |
2393 | void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); |
2394 | void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); |
2395 | void (*xDlClose)(sqlite3_vfs*, void*); |
2396 | int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); |
2397 | int (*xSleep)(sqlite3_vfs*, int microseconds); |
2398 | int (*xCurrentTime)(sqlite3_vfs*, double*); |
2399 | int (*xGetLastError)(sqlite3_vfs*, int, char *); |
2400 | /* |
2401 | ** The methods above are in version 1 of the sqlite_vfs object |
2402 | ** definition. Those that follow are added in version 2 or later |
2403 | */ |
2404 | int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); |
2405 | /* |
2406 | ** The methods above are in versions 1 and 2 of the sqlite_vfs object. |
2407 | ** Those below are for version 3 and greater. |
2408 | */ |
2409 | int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); |
2410 | sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); |
2411 | const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); |
2412 | /* |
2413 | ** The methods above are in versions 1 through 3 of the sqlite_vfs object. |
2414 | ** New fields may be appended in future versions. The iVersion |
2415 | ** value will increment whenever this happens. |
2416 | */ |
2417 | }; |
2418 | |
2419 | /* |
2420 | ** CAPI3REF: Flags for the xAccess VFS method |
2421 | ** |
2422 | ** These integer constants can be used as the third parameter to |
2423 | ** the xAccess method of an [sqlite3_vfs] object. They determine |
2424 | ** what kind of permissions the xAccess method is looking for. |
2425 | ** With SQLITE_ACCESS_EXISTS, the xAccess method |
2426 | ** simply checks whether the file exists. |
2427 | ** With SQLITE_ACCESS_READWRITE, the xAccess method |
2428 | ** checks whether the named directory is both readable and writable |
2429 | ** (in other words, if files can be added, removed, and renamed within |
2430 | ** the directory). |
2431 | ** The SQLITE_ACCESS_READWRITE constant is currently used only by the |
2432 | ** [temp_store_directory pragma], though this could change in a future |
2433 | ** release of SQLite. |
2434 | ** With SQLITE_ACCESS_READ, the xAccess method |
2435 | ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is |
2436 | ** currently unused, though it might be used in a future release of |
2437 | ** SQLite. |
2438 | */ |
2439 | #define SQLITE_ACCESS_EXISTS 0 |
2440 | #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ |
2441 | #define SQLITE_ACCESS_READ 2 /* Unused */ |
2442 | |
2443 | /* |
2444 | ** CAPI3REF: Flags for the xShmLock VFS method |
2445 | ** |
2446 | ** These integer constants define the various locking operations |
2447 | ** allowed by the xShmLock method of [sqlite3_io_methods]. The |
2448 | ** following are the only legal combinations of flags to the |
2449 | ** xShmLock method: |
2450 | ** |
2451 | ** <ul> |
2452 | ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED |
2453 | ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE |
2454 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
2455 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
2456 | ** </ul> |
2457 | ** |
2458 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
2459 | ** was given on the corresponding lock. |
2460 | ** |
2461 | ** The xShmLock method can transition between unlocked and SHARED or |
2462 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
2463 | ** and EXCLUSIVE. |
2464 | */ |
2465 | #define SQLITE_SHM_UNLOCK 1 |
2466 | #define SQLITE_SHM_LOCK 2 |
2467 | #define SQLITE_SHM_SHARED 4 |
2468 | #define SQLITE_SHM_EXCLUSIVE 8 |
2469 | |
2470 | /* |
2471 | ** CAPI3REF: Maximum xShmLock index |
2472 | ** |
2473 | ** The xShmLock method on [sqlite3_io_methods] may use values |
2474 | ** between 0 and this upper bound as its "offset" argument. |
2475 | ** The SQLite core will never attempt to acquire or release a |
2476 | ** lock outside of this range |
2477 | */ |
2478 | #define SQLITE_SHM_NLOCK 8 |
2479 | |
2480 | |
2481 | /* |
2482 | ** CAPI3REF: Initialize The SQLite Library |
2483 | ** |
2484 | ** ^The sqlite3_initialize() routine initializes the |
2485 | ** SQLite library. ^The sqlite3_shutdown() routine |
2486 | ** deallocates any resources that were allocated by sqlite3_initialize(). |
2487 | ** These routines are designed to aid in process initialization and |
2488 | ** shutdown on embedded systems. Workstation applications using |
2489 | ** SQLite normally do not need to invoke either of these routines. |
2490 | ** |
2491 | ** A call to sqlite3_initialize() is an "effective" call if it is |
2492 | ** the first time sqlite3_initialize() is invoked during the lifetime of |
2493 | ** the process, or if it is the first time sqlite3_initialize() is invoked |
2494 | ** following a call to sqlite3_shutdown(). ^(Only an effective call |
2495 | ** of sqlite3_initialize() does any initialization. All other calls |
2496 | ** are harmless no-ops.)^ |
2497 | ** |
2498 | ** A call to sqlite3_shutdown() is an "effective" call if it is the first |
2499 | ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only |
2500 | ** an effective call to sqlite3_shutdown() does any deinitialization. |
2501 | ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ |
2502 | ** |
2503 | ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() |
2504 | ** is not. The sqlite3_shutdown() interface must only be called from a |
2505 | ** single thread. All open [database connections] must be closed and all |
2506 | ** other SQLite resources must be deallocated prior to invoking |
2507 | ** sqlite3_shutdown(). |
2508 | ** |
2509 | ** Among other things, ^sqlite3_initialize() will invoke |
2510 | ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() |
2511 | ** will invoke sqlite3_os_end(). |
2512 | ** |
2513 | ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. |
2514 | ** ^If for some reason, sqlite3_initialize() is unable to initialize |
2515 | ** the library (perhaps it is unable to allocate a needed resource such |
2516 | ** as a mutex) it returns an [error code] other than [SQLITE_OK]. |
2517 | ** |
2518 | ** ^The sqlite3_initialize() routine is called internally by many other |
2519 | ** SQLite interfaces so that an application usually does not need to |
2520 | ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] |
2521 | ** calls sqlite3_initialize() so the SQLite library will be automatically |
2522 | ** initialized when [sqlite3_open()] is called if it has not be initialized |
2523 | ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] |
2524 | ** compile-time option, then the automatic calls to sqlite3_initialize() |
2525 | ** are omitted and the application must call sqlite3_initialize() directly |
2526 | ** prior to using any other SQLite interface. For maximum portability, |
2527 | ** it is recommended that applications always invoke sqlite3_initialize() |
2528 | ** directly prior to using any other SQLite interface. Future releases |
2529 | ** of SQLite may require this. In other words, the behavior exhibited |
2530 | ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the |
2531 | ** default behavior in some future release of SQLite. |
2532 | ** |
2533 | ** The sqlite3_os_init() routine does operating-system specific |
2534 | ** initialization of the SQLite library. The sqlite3_os_end() |
2535 | ** routine undoes the effect of sqlite3_os_init(). Typical tasks |
2536 | ** performed by these routines include allocation or deallocation |
2537 | ** of static resources, initialization of global variables, |
2538 | ** setting up a default [sqlite3_vfs] module, or setting up |
2539 | ** a default configuration using [sqlite3_config()]. |
2540 | ** |
2541 | ** The application should never invoke either sqlite3_os_init() |
2542 | ** or sqlite3_os_end() directly. The application should only invoke |
2543 | ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() |
2544 | ** interface is called automatically by sqlite3_initialize() and |
2545 | ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate |
2546 | ** implementations for sqlite3_os_init() and sqlite3_os_end() |
2547 | ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. |
2548 | ** When [custom builds | built for other platforms] |
2549 | ** (using the [SQLITE_OS_OTHER=1] compile-time |
2550 | ** option) the application must supply a suitable implementation for |
2551 | ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied |
2552 | ** implementation of sqlite3_os_init() or sqlite3_os_end() |
2553 | ** must return [SQLITE_OK] on success and some other [error code] upon |
2554 | ** failure. |
2555 | */ |
2556 | SQLITE_API int sqlite3_initialize(void); |
2557 | SQLITE_API int sqlite3_shutdown(void); |
2558 | SQLITE_API int sqlite3_os_init(void); |
2559 | SQLITE_API int sqlite3_os_end(void); |
2560 | |
2561 | /* |
2562 | ** CAPI3REF: Configuring The SQLite Library |
2563 | ** |
2564 | ** The sqlite3_config() interface is used to make global configuration |
2565 | ** changes to SQLite in order to tune SQLite to the specific needs of |
2566 | ** the application. The default configuration is recommended for most |
2567 | ** applications and so this routine is usually not necessary. It is |
2568 | ** provided to support rare applications with unusual needs. |
2569 | ** |
2570 | ** <b>The sqlite3_config() interface is not threadsafe. The application |
2571 | ** must ensure that no other SQLite interfaces are invoked by other |
2572 | ** threads while sqlite3_config() is running.</b> |
2573 | ** |
2574 | ** The sqlite3_config() interface |
2575 | ** may only be invoked prior to library initialization using |
2576 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
2577 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
2578 | ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
2579 | ** Note, however, that ^sqlite3_config() can be called as part of the |
2580 | ** implementation of an application-defined [sqlite3_os_init()]. |
2581 | ** |
2582 | ** The first argument to sqlite3_config() is an integer |
2583 | ** [configuration option] that determines |
2584 | ** what property of SQLite is to be configured. Subsequent arguments |
2585 | ** vary depending on the [configuration option] |
2586 | ** in the first argument. |
2587 | ** |
2588 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
2589 | ** ^If the option is unknown or SQLite is unable to set the option |
2590 | ** then this routine returns a non-zero [error code]. |
2591 | */ |
2592 | SQLITE_API int sqlite3_config(int, ...); |
2593 | |
2594 | /* |
2595 | ** CAPI3REF: Configure database connections |
2596 | ** METHOD: sqlite3 |
2597 | ** |
2598 | ** The sqlite3_db_config() interface is used to make configuration |
2599 | ** changes to a [database connection]. The interface is similar to |
2600 | ** [sqlite3_config()] except that the changes apply to a single |
2601 | ** [database connection] (specified in the first argument). |
2602 | ** |
2603 | ** The second argument to sqlite3_db_config(D,V,...) is the |
2604 | ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code |
2605 | ** that indicates what aspect of the [database connection] is being configured. |
2606 | ** Subsequent arguments vary depending on the configuration verb. |
2607 | ** |
2608 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
2609 | ** the call is considered successful. |
2610 | */ |
2611 | SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); |
2612 | |
2613 | /* |
2614 | ** CAPI3REF: Memory Allocation Routines |
2615 | ** |
2616 | ** An instance of this object defines the interface between SQLite |
2617 | ** and low-level memory allocation routines. |
2618 | ** |
2619 | ** This object is used in only one place in the SQLite interface. |
2620 | ** A pointer to an instance of this object is the argument to |
2621 | ** [sqlite3_config()] when the configuration option is |
2622 | ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. |
2623 | ** By creating an instance of this object |
2624 | ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) |
2625 | ** during configuration, an application can specify an alternative |
2626 | ** memory allocation subsystem for SQLite to use for all of its |
2627 | ** dynamic memory needs. |
2628 | ** |
2629 | ** Note that SQLite comes with several [built-in memory allocators] |
2630 | ** that are perfectly adequate for the overwhelming majority of applications |
2631 | ** and that this object is only useful to a tiny minority of applications |
2632 | ** with specialized memory allocation requirements. This object is |
2633 | ** also used during testing of SQLite in order to specify an alternative |
2634 | ** memory allocator that simulates memory out-of-memory conditions in |
2635 | ** order to verify that SQLite recovers gracefully from such |
2636 | ** conditions. |
2637 | ** |
2638 | ** The xMalloc, xRealloc, and xFree methods must work like the |
2639 | ** malloc(), realloc() and free() functions from the standard C library. |
2640 | ** ^SQLite guarantees that the second argument to |
2641 | ** xRealloc is always a value returned by a prior call to xRoundup. |
2642 | ** |
2643 | ** xSize should return the allocated size of a memory allocation |
2644 | ** previously obtained from xMalloc or xRealloc. The allocated size |
2645 | ** is always at least as big as the requested size but may be larger. |
2646 | ** |
2647 | ** The xRoundup method returns what would be the allocated size of |
2648 | ** a memory allocation given a particular requested size. Most memory |
2649 | ** allocators round up memory allocations at least to the next multiple |
2650 | ** of 8. Some allocators round up to a larger multiple or to a power of 2. |
2651 | ** Every memory allocation request coming in through [sqlite3_malloc()] |
2652 | ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, |
2653 | ** that causes the corresponding memory allocation to fail. |
2654 | ** |
2655 | ** The xInit method initializes the memory allocator. For example, |
2656 | ** it might allocate any require mutexes or initialize internal data |
2657 | ** structures. The xShutdown method is invoked (indirectly) by |
2658 | ** [sqlite3_shutdown()] and should deallocate any resources acquired |
2659 | ** by xInit. The pAppData pointer is used as the only parameter to |
2660 | ** xInit and xShutdown. |
2661 | ** |
2662 | ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes |
2663 | ** the xInit method, so the xInit method need not be threadsafe. The |
2664 | ** xShutdown method is only called from [sqlite3_shutdown()] so it does |
2665 | ** not need to be threadsafe either. For all other methods, SQLite |
2666 | ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the |
2667 | ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which |
2668 | ** it is by default) and so the methods are automatically serialized. |
2669 | ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other |
2670 | ** methods must be threadsafe or else make their own arrangements for |
2671 | ** serialization. |
2672 | ** |
2673 | ** SQLite will never invoke xInit() more than once without an intervening |
2674 | ** call to xShutdown(). |
2675 | */ |
2676 | typedef struct sqlite3_mem_methods sqlite3_mem_methods; |
2677 | struct sqlite3_mem_methods { |
2678 | void *(*xMalloc)(int); /* Memory allocation function */ |
2679 | void (*xFree)(void*); /* Free a prior allocation */ |
2680 | void *(*xRealloc)(void*,int); /* Resize an allocation */ |
2681 | int (*xSize)(void*); /* Return the size of an allocation */ |
2682 | int (*xRoundup)(int); /* Round up request size to allocation size */ |
2683 | int (*xInit)(void*); /* Initialize the memory allocator */ |
2684 | void (*xShutdown)(void*); /* Deinitialize the memory allocator */ |
2685 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
2686 | }; |
2687 | |
2688 | /* |
2689 | ** CAPI3REF: Configuration Options |
2690 | ** KEYWORDS: {configuration option} |
2691 | ** |
2692 | ** These constants are the available integer configuration options that |
2693 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
2694 | ** |
2695 | ** New configuration options may be added in future releases of SQLite. |
2696 | ** Existing configuration options might be discontinued. Applications |
2697 | ** should check the return code from [sqlite3_config()] to make sure that |
2698 | ** the call worked. The [sqlite3_config()] interface will return a |
2699 | ** non-zero [error code] if a discontinued or unsupported configuration option |
2700 | ** is invoked. |
2701 | ** |
2702 | ** <dl> |
2703 | ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> |
2704 | ** <dd>There are no arguments to this option. ^This option sets the |
2705 | ** [threading mode] to Single-thread. In other words, it disables |
2706 | ** all mutexing and puts SQLite into a mode where it can only be used |
2707 | ** by a single thread. ^If SQLite is compiled with |
2708 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2709 | ** it is not possible to change the [threading mode] from its default |
2710 | ** value of Single-thread and so [sqlite3_config()] will return |
2711 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
2712 | ** configuration option.</dd> |
2713 | ** |
2714 | ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> |
2715 | ** <dd>There are no arguments to this option. ^This option sets the |
2716 | ** [threading mode] to Multi-thread. In other words, it disables |
2717 | ** mutexing on [database connection] and [prepared statement] objects. |
2718 | ** The application is responsible for serializing access to |
2719 | ** [database connections] and [prepared statements]. But other mutexes |
2720 | ** are enabled so that SQLite will be safe to use in a multi-threaded |
2721 | ** environment as long as no two threads attempt to use the same |
2722 | ** [database connection] at the same time. ^If SQLite is compiled with |
2723 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2724 | ** it is not possible to set the Multi-thread [threading mode] and |
2725 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
2726 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
2727 | ** |
2728 | ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> |
2729 | ** <dd>There are no arguments to this option. ^This option sets the |
2730 | ** [threading mode] to Serialized. In other words, this option enables |
2731 | ** all mutexes including the recursive |
2732 | ** mutexes on [database connection] and [prepared statement] objects. |
2733 | ** In this mode (which is the default when SQLite is compiled with |
2734 | ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access |
2735 | ** to [database connections] and [prepared statements] so that the |
2736 | ** application is free to use the same [database connection] or the |
2737 | ** same [prepared statement] in different threads at the same time. |
2738 | ** ^If SQLite is compiled with |
2739 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2740 | ** it is not possible to set the Serialized [threading mode] and |
2741 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
2742 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
2743 | ** |
2744 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
2745 | ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is |
2746 | ** a pointer to an instance of the [sqlite3_mem_methods] structure. |
2747 | ** The argument specifies |
2748 | ** alternative low-level memory allocation routines to be used in place of |
2749 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
2750 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
2751 | ** before the [sqlite3_config()] call returns.</dd> |
2752 | ** |
2753 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
2754 | ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which |
2755 | ** is a pointer to an instance of the [sqlite3_mem_methods] structure. |
2756 | ** The [sqlite3_mem_methods] |
2757 | ** structure is filled with the currently defined memory allocation routines.)^ |
2758 | ** This option can be used to overload the default memory allocation |
2759 | ** routines with a wrapper that simulations memory allocation failure or |
2760 | ** tracks memory usage, for example. </dd> |
2761 | ** |
2762 | ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt> |
2763 | ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of |
2764 | ** type int, interpreted as a boolean, which if true provides a hint to |
2765 | ** SQLite that it should avoid large memory allocations if possible. |
2766 | ** SQLite will run faster if it is free to make large memory allocations, |
2767 | ** but some application might prefer to run slower in exchange for |
2768 | ** guarantees about memory fragmentation that are possible if large |
2769 | ** allocations are avoided. This hint is normally off. |
2770 | ** </dd> |
2771 | ** |
2772 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
2773 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
2774 | ** interpreted as a boolean, which enables or disables the collection of |
2775 | ** memory allocation statistics. ^(When memory allocation statistics are |
2776 | ** disabled, the following SQLite interfaces become non-operational: |
2777 | ** <ul> |
2778 | ** <li> [sqlite3_memory_used()] |
2779 | ** <li> [sqlite3_memory_highwater()] |
2780 | ** <li> [sqlite3_soft_heap_limit64()] |
2781 | ** <li> [sqlite3_status64()] |
2782 | ** </ul>)^ |
2783 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
2784 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
2785 | ** allocation statistics are disabled by default. |
2786 | ** </dd> |
2787 | ** |
2788 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
2789 | ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used. |
2790 | ** </dd> |
2791 | ** |
2792 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
2793 | ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool |
2794 | ** that SQLite can use for the database page cache with the default page |
2795 | ** cache implementation. |
2796 | ** This configuration option is a no-op if an application-define page |
2797 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]. |
2798 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to |
2799 | ** 8-byte aligned memory (pMem), the size of each page cache line (sz), |
2800 | ** and the number of cache lines (N). |
2801 | ** The sz argument should be the size of the largest database page |
2802 | ** (a power of two between 512 and 65536) plus some extra bytes for each |
2803 | ** page header. ^The number of extra bytes needed by the page header |
2804 | ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ]. |
2805 | ** ^It is harmless, apart from the wasted memory, |
2806 | ** for the sz parameter to be larger than necessary. The pMem |
2807 | ** argument must be either a NULL pointer or a pointer to an 8-byte |
2808 | ** aligned block of memory of at least sz*N bytes, otherwise |
2809 | ** subsequent behavior is undefined. |
2810 | ** ^When pMem is not NULL, SQLite will strive to use the memory provided |
2811 | ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if |
2812 | ** a page cache line is larger than sz bytes or if all of the pMem buffer |
2813 | ** is exhausted. |
2814 | ** ^If pMem is NULL and N is non-zero, then each database connection |
2815 | ** does an initial bulk allocation for page cache memory |
2816 | ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or |
2817 | ** of -1024*N bytes if N is negative, . ^If additional |
2818 | ** page cache memory is needed beyond what is provided by the initial |
2819 | ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each |
2820 | ** additional cache line. </dd> |
2821 | ** |
2822 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
2823 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
2824 | ** that SQLite will use for all of its dynamic memory allocation needs |
2825 | ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE]. |
2826 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
2827 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
2828 | ** [SQLITE_ERROR] if invoked otherwise. |
2829 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
2830 | ** An 8-byte aligned pointer to the memory, |
2831 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
2832 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
2833 | ** to using its default memory allocator (the system malloc() implementation), |
2834 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
2835 | ** memory pointer is not NULL then the alternative memory |
2836 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
2837 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
2838 | ** boundary or subsequent behavior of SQLite will be undefined. |
2839 | ** The minimum allocation size is capped at 2**12. Reasonable values |
2840 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
2841 | ** |
2842 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
2843 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
2844 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
2845 | ** The argument specifies alternative low-level mutex routines to be used |
2846 | ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of |
2847 | ** the content of the [sqlite3_mutex_methods] structure before the call to |
2848 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
2849 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2850 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
2851 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
2852 | ** return [SQLITE_ERROR].</dd> |
2853 | ** |
2854 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
2855 | ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which |
2856 | ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The |
2857 | ** [sqlite3_mutex_methods] |
2858 | ** structure is filled with the currently defined mutex routines.)^ |
2859 | ** This option can be used to overload the default mutex allocation |
2860 | ** routines with a wrapper used to track mutex usage for performance |
2861 | ** profiling or testing, for example. ^If SQLite is compiled with |
2862 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2863 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
2864 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
2865 | ** return [SQLITE_ERROR].</dd> |
2866 | ** |
2867 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
2868 | ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine |
2869 | ** the default size of lookaside memory on each [database connection]. |
2870 | ** The first argument is the |
2871 | ** size of each lookaside buffer slot and the second is the number of |
2872 | ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE |
2873 | ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
2874 | ** option to [sqlite3_db_config()] can be used to change the lookaside |
2875 | ** configuration on individual connections.)^ </dd> |
2876 | ** |
2877 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
2878 | ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is |
2879 | ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies |
2880 | ** the interface to a custom page cache implementation.)^ |
2881 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
2882 | ** |
2883 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
2884 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
2885 | ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of |
2886 | ** the current page cache implementation into that object.)^ </dd> |
2887 | ** |
2888 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
2889 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
2890 | ** global [error log]. |
2891 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
2892 | ** function with a call signature of void(*)(void*,int,const char*), |
2893 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
2894 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
2895 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
2896 | ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is |
2897 | ** passed through as the first parameter to the application-defined logger |
2898 | ** function whenever that function is invoked. ^The second parameter to |
2899 | ** the logger function is a copy of the first parameter to the corresponding |
2900 | ** [sqlite3_log()] call and is intended to be a [result code] or an |
2901 | ** [extended result code]. ^The third parameter passed to the logger is |
2902 | ** log message after formatting via [sqlite3_snprintf()]. |
2903 | ** The SQLite logging interface is not reentrant; the logger function |
2904 | ** supplied by the application must not invoke any SQLite interface. |
2905 | ** In a multi-threaded application, the application-defined logger |
2906 | ** function must be threadsafe. </dd> |
2907 | ** |
2908 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
2909 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
2910 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
2911 | ** then URI handling is globally disabled.)^ ^If URI handling is globally |
2912 | ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], |
2913 | ** [sqlite3_open16()] or |
2914 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
2915 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
2916 | ** connection is opened. ^If it is globally disabled, filenames are |
2917 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
2918 | ** database connection is opened. ^(By default, URI handling is globally |
2919 | ** disabled. The default value may be changed by compiling with the |
2920 | ** [SQLITE_USE_URI] symbol defined.)^ |
2921 | ** |
2922 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
2923 | ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer |
2924 | ** argument which is interpreted as a boolean in order to enable or disable |
2925 | ** the use of covering indices for full table scans in the query optimizer. |
2926 | ** ^The default setting is determined |
2927 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
2928 | ** if that compile-time option is omitted. |
2929 | ** The ability to disable the use of covering indices for full table scans |
2930 | ** is because some incorrectly coded legacy applications might malfunction |
2931 | ** when the optimization is enabled. Providing the ability to |
2932 | ** disable the optimization allows the older, buggy application code to work |
2933 | ** without change even with newer versions of SQLite. |
2934 | ** |
2935 | ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] |
2936 | ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE |
2937 | ** <dd> These options are obsolete and should not be used by new code. |
2938 | ** They are retained for backwards compatibility but are now no-ops. |
2939 | ** </dd> |
2940 | ** |
2941 | ** [[SQLITE_CONFIG_SQLLOG]] |
2942 | ** <dt>SQLITE_CONFIG_SQLLOG |
2943 | ** <dd>This option is only available if sqlite is compiled with the |
2944 | ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should |
2945 | ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int). |
2946 | ** The second should be of type (void*). The callback is invoked by the library |
2947 | ** in three separate circumstances, identified by the value passed as the |
2948 | ** fourth parameter. If the fourth parameter is 0, then the database connection |
2949 | ** passed as the second argument has just been opened. The third argument |
2950 | ** points to a buffer containing the name of the main database file. If the |
2951 | ** fourth parameter is 1, then the SQL statement that the third parameter |
2952 | ** points to has just been executed. Or, if the fourth parameter is 2, then |
2953 | ** the connection being passed as the second parameter is being closed. The |
2954 | ** third parameter is passed NULL In this case. An example of using this |
2955 | ** configuration option can be seen in the "test_sqllog.c" source file in |
2956 | ** the canonical SQLite source tree.</dd> |
2957 | ** |
2958 | ** [[SQLITE_CONFIG_MMAP_SIZE]] |
2959 | ** <dt>SQLITE_CONFIG_MMAP_SIZE |
2960 | ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values |
2961 | ** that are the default mmap size limit (the default setting for |
2962 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
2963 | ** ^The default setting can be overridden by each database connection using |
2964 | ** either the [PRAGMA mmap_size] command, or by using the |
2965 | ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
2966 | ** will be silently truncated if necessary so that it does not exceed the |
2967 | ** compile-time maximum mmap size set by the |
2968 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
2969 | ** ^If either argument to this option is negative, then that argument is |
2970 | ** changed to its compile-time default. |
2971 | ** |
2972 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
2973 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
2974 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
2975 | ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro |
2976 | ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
2977 | ** that specifies the maximum size of the created heap. |
2978 | ** |
2979 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
2980 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
2981 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
2982 | ** is a pointer to an integer and writes into that integer the number of extra |
2983 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. |
2984 | ** The amount of extra space required can change depending on the compiler, |
2985 | ** target platform, and SQLite version. |
2986 | ** |
2987 | ** [[SQLITE_CONFIG_PMASZ]] |
2988 | ** <dt>SQLITE_CONFIG_PMASZ |
2989 | ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which |
2990 | ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded |
2991 | ** sorter to that integer. The default minimum PMA Size is set by the |
2992 | ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched |
2993 | ** to help with sort operations when multithreaded sorting |
2994 | ** is enabled (using the [PRAGMA threads] command) and the amount of content |
2995 | ** to be sorted exceeds the page size times the minimum of the |
2996 | ** [PRAGMA cache_size] setting and this value. |
2997 | ** |
2998 | ** [[SQLITE_CONFIG_STMTJRNL_SPILL]] |
2999 | ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL |
3000 | ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which |
3001 | ** becomes the [statement journal] spill-to-disk threshold. |
3002 | ** [Statement journals] are held in memory until their size (in bytes) |
3003 | ** exceeds this threshold, at which point they are written to disk. |
3004 | ** Or if the threshold is -1, statement journals are always held |
3005 | ** exclusively in memory. |
3006 | ** Since many statement journals never become large, setting the spill |
3007 | ** threshold to a value such as 64KiB can greatly reduce the amount of |
3008 | ** I/O required to support statement rollback. |
3009 | ** The default value for this setting is controlled by the |
3010 | ** [SQLITE_STMTJRNL_SPILL] compile-time option. |
3011 | ** |
3012 | ** [[SQLITE_CONFIG_SORTERREF_SIZE]] |
3013 | ** <dt>SQLITE_CONFIG_SORTERREF_SIZE |
3014 | ** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter |
3015 | ** of type (int) - the new value of the sorter-reference size threshold. |
3016 | ** Usually, when SQLite uses an external sort to order records according |
3017 | ** to an ORDER BY clause, all fields required by the caller are present in the |
3018 | ** sorted records. However, if SQLite determines based on the declared type |
3019 | ** of a table column that its values are likely to be very large - larger |
3020 | ** than the configured sorter-reference size threshold - then a reference |
3021 | ** is stored in each sorted record and the required column values loaded |
3022 | ** from the database as records are returned in sorted order. The default |
3023 | ** value for this option is to never use this optimization. Specifying a |
3024 | ** negative value for this option restores the default behaviour. |
3025 | ** This option is only available if SQLite is compiled with the |
3026 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
3027 | ** |
3028 | ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] |
3029 | ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE |
3030 | ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter |
3031 | ** [sqlite3_int64] parameter which is the default maximum size for an in-memory |
3032 | ** database created using [sqlite3_deserialize()]. This default maximum |
3033 | ** size can be adjusted up or down for individual databases using the |
3034 | ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this |
3035 | ** configuration setting is never used, then the default maximum is determined |
3036 | ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that |
3037 | ** compile-time option is not set, then the default maximum is 1073741824. |
3038 | ** </dl> |
3039 | */ |
3040 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
3041 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
3042 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
3043 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
3044 | #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ |
3045 | #define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ |
3046 | #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ |
3047 | #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ |
3048 | #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ |
3049 | #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ |
3050 | #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ |
3051 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
3052 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
3053 | #define SQLITE_CONFIG_PCACHE 14 /* no-op */ |
3054 | #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ |
3055 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
3056 | #define SQLITE_CONFIG_URI 17 /* int */ |
3057 | #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ |
3058 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
3059 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
3060 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
3061 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
3062 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
3063 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
3064 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
3065 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
3066 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
3067 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
3068 | #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ |
3069 | |
3070 | /* |
3071 | ** CAPI3REF: Database Connection Configuration Options |
3072 | ** |
3073 | ** These constants are the available integer configuration options that |
3074 | ** can be passed as the second argument to the [sqlite3_db_config()] interface. |
3075 | ** |
3076 | ** New configuration options may be added in future releases of SQLite. |
3077 | ** Existing configuration options might be discontinued. Applications |
3078 | ** should check the return code from [sqlite3_db_config()] to make sure that |
3079 | ** the call worked. ^The [sqlite3_db_config()] interface will return a |
3080 | ** non-zero [error code] if a discontinued or unsupported configuration option |
3081 | ** is invoked. |
3082 | ** |
3083 | ** <dl> |
3084 | ** [[SQLITE_DBCONFIG_LOOKASIDE]] |
3085 | ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> |
3086 | ** <dd> ^This option takes three additional arguments that determine the |
3087 | ** [lookaside memory allocator] configuration for the [database connection]. |
3088 | ** ^The first argument (the third parameter to [sqlite3_db_config()] is a |
3089 | ** pointer to a memory buffer to use for lookaside memory. |
3090 | ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb |
3091 | ** may be NULL in which case SQLite will allocate the |
3092 | ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the |
3093 | ** size of each lookaside buffer slot. ^The third argument is the number of |
3094 | ** slots. The size of the buffer in the first argument must be greater than |
3095 | ** or equal to the product of the second and third arguments. The buffer |
3096 | ** must be aligned to an 8-byte boundary. ^If the second argument to |
3097 | ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally |
3098 | ** rounded down to the next smaller multiple of 8. ^(The lookaside memory |
3099 | ** configuration for a database connection can only be changed when that |
3100 | ** connection is not currently using lookaside memory, or in other words |
3101 | ** when the "current value" returned by |
3102 | ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. |
3103 | ** Any attempt to change the lookaside memory configuration when lookaside |
3104 | ** memory is in use leaves the configuration unchanged and returns |
3105 | ** [SQLITE_BUSY].)^</dd> |
3106 | ** |
3107 | ** [[SQLITE_DBCONFIG_ENABLE_FKEY]] |
3108 | ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> |
3109 | ** <dd> ^This option is used to enable or disable the enforcement of |
3110 | ** [foreign key constraints]. There should be two additional arguments. |
3111 | ** The first argument is an integer which is 0 to disable FK enforcement, |
3112 | ** positive to enable FK enforcement or negative to leave FK enforcement |
3113 | ** unchanged. The second parameter is a pointer to an integer into which |
3114 | ** is written 0 or 1 to indicate whether FK enforcement is off or on |
3115 | ** following this call. The second parameter may be a NULL pointer, in |
3116 | ** which case the FK enforcement setting is not reported back. </dd> |
3117 | ** |
3118 | ** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]] |
3119 | ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> |
3120 | ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. |
3121 | ** There should be two additional arguments. |
3122 | ** The first argument is an integer which is 0 to disable triggers, |
3123 | ** positive to enable triggers or negative to leave the setting unchanged. |
3124 | ** The second parameter is a pointer to an integer into which |
3125 | ** is written 0 or 1 to indicate whether triggers are disabled or enabled |
3126 | ** following this call. The second parameter may be a NULL pointer, in |
3127 | ** which case the trigger setting is not reported back. </dd> |
3128 | ** |
3129 | ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] |
3130 | ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> |
3131 | ** <dd> ^This option is used to enable or disable the |
3132 | ** [fts3_tokenizer()] function which is part of the |
3133 | ** [FTS3] full-text search engine extension. |
3134 | ** There should be two additional arguments. |
3135 | ** The first argument is an integer which is 0 to disable fts3_tokenizer() or |
3136 | ** positive to enable fts3_tokenizer() or negative to leave the setting |
3137 | ** unchanged. |
3138 | ** The second parameter is a pointer to an integer into which |
3139 | ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled |
3140 | ** following this call. The second parameter may be a NULL pointer, in |
3141 | ** which case the new setting is not reported back. </dd> |
3142 | ** |
3143 | ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]] |
3144 | ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> |
3145 | ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] |
3146 | ** interface independently of the [load_extension()] SQL function. |
3147 | ** The [sqlite3_enable_load_extension()] API enables or disables both the |
3148 | ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()]. |
3149 | ** There should be two additional arguments. |
3150 | ** When the first argument to this interface is 1, then only the C-API is |
3151 | ** enabled and the SQL function remains disabled. If the first argument to |
3152 | ** this interface is 0, then both the C-API and the SQL function are disabled. |
3153 | ** If the first argument is -1, then no changes are made to state of either the |
3154 | ** C-API or the SQL function. |
3155 | ** The second parameter is a pointer to an integer into which |
3156 | ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface |
3157 | ** is disabled or enabled following this call. The second parameter may |
3158 | ** be a NULL pointer, in which case the new setting is not reported back. |
3159 | ** </dd> |
3160 | ** |
3161 | ** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt> |
3162 | ** <dd> ^This option is used to change the name of the "main" database |
3163 | ** schema. ^The sole argument is a pointer to a constant UTF8 string |
3164 | ** which will become the new schema name in place of "main". ^SQLite |
3165 | ** does not make a copy of the new main schema name string, so the application |
3166 | ** must ensure that the argument passed into this DBCONFIG option is unchanged |
3167 | ** until after the database connection closes. |
3168 | ** </dd> |
3169 | ** |
3170 | ** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] |
3171 | ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt> |
3172 | ** <dd> Usually, when a database in wal mode is closed or detached from a |
3173 | ** database handle, SQLite checks if this will mean that there are now no |
3174 | ** connections at all to the database. If so, it performs a checkpoint |
3175 | ** operation before closing the connection. This option may be used to |
3176 | ** override this behaviour. The first parameter passed to this operation |
3177 | ** is an integer - positive to disable checkpoints-on-close, or zero (the |
3178 | ** default) to enable them, and negative to leave the setting unchanged. |
3179 | ** The second parameter is a pointer to an integer |
3180 | ** into which is written 0 or 1 to indicate whether checkpoints-on-close |
3181 | ** have been disabled - 0 if they are not disabled, 1 if they are. |
3182 | ** </dd> |
3183 | ** |
3184 | ** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt> |
3185 | ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates |
3186 | ** the [query planner stability guarantee] (QPSG). When the QPSG is active, |
3187 | ** a single SQL query statement will always use the same algorithm regardless |
3188 | ** of values of [bound parameters].)^ The QPSG disables some query optimizations |
3189 | ** that look at the values of bound parameters, which can make some queries |
3190 | ** slower. But the QPSG has the advantage of more predictable behavior. With |
3191 | ** the QPSG active, SQLite will always use the same query plan in the field as |
3192 | ** was used during testing in the lab. |
3193 | ** The first argument to this setting is an integer which is 0 to disable |
3194 | ** the QPSG, positive to enable QPSG, or negative to leave the setting |
3195 | ** unchanged. The second parameter is a pointer to an integer into which |
3196 | ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled |
3197 | ** following this call. |
3198 | ** </dd> |
3199 | ** |
3200 | ** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt> |
3201 | ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not |
3202 | ** include output for any operations performed by trigger programs. This |
3203 | ** option is used to set or clear (the default) a flag that governs this |
3204 | ** behavior. The first parameter passed to this operation is an integer - |
3205 | ** positive to enable output for trigger programs, or zero to disable it, |
3206 | ** or negative to leave the setting unchanged. |
3207 | ** The second parameter is a pointer to an integer into which is written |
3208 | ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if |
3209 | ** it is not disabled, 1 if it is. |
3210 | ** </dd> |
3211 | ** |
3212 | ** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt> |
3213 | ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run |
3214 | ** [VACUUM] in order to reset a database back to an empty database |
3215 | ** with no schema and no content. The following process works even for |
3216 | ** a badly corrupted database file: |
3217 | ** <ol> |
3218 | ** <li> If the database connection is newly opened, make sure it has read the |
3219 | ** database schema by preparing then discarding some query against the |
3220 | ** database, or calling sqlite3_table_column_metadata(), ignoring any |
3221 | ** errors. This step is only necessary if the application desires to keep |
3222 | ** the database in WAL mode after the reset if it was in WAL mode before |
3223 | ** the reset. |
3224 | ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0); |
3225 | ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0); |
3226 | ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0); |
3227 | ** </ol> |
3228 | ** Because resetting a database is destructive and irreversible, the |
3229 | ** process requires the use of this obscure API and multiple steps to help |
3230 | ** ensure that it does not happen by accident. |
3231 | ** |
3232 | ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt> |
3233 | ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the |
3234 | ** "defensive" flag for a database connection. When the defensive |
3235 | ** flag is enabled, language features that allow ordinary SQL to |
3236 | ** deliberately corrupt the database file are disabled. The disabled |
3237 | ** features include but are not limited to the following: |
3238 | ** <ul> |
3239 | ** <li> The [PRAGMA writable_schema=ON] statement. |
3240 | ** <li> Writes to the [sqlite_dbpage] virtual table. |
3241 | ** <li> Direct writes to [shadow tables]. |
3242 | ** </ul> |
3243 | ** </dd> |
3244 | ** |
3245 | ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt> |
3246 | ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the |
3247 | ** "writable_schema" flag. This has the same effect and is logically equivalent |
3248 | ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF]. |
3249 | ** The first argument to this setting is an integer which is 0 to disable |
3250 | ** the writable_schema, positive to enable writable_schema, or negative to |
3251 | ** leave the setting unchanged. The second parameter is a pointer to an |
3252 | ** integer into which is written 0 or 1 to indicate whether the writable_schema |
3253 | ** is enabled or disabled following this call. |
3254 | ** </dd> |
3255 | ** </dl> |
3256 | */ |
3257 | #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ |
3258 | #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ |
3259 | #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ |
3260 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
3261 | #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */ |
3262 | #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ |
3263 | #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ |
3264 | #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */ |
3265 | #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */ |
3266 | #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */ |
3267 | #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */ |
3268 | #define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */ |
3269 | #define SQLITE_DBCONFIG_MAX 1011 /* Largest DBCONFIG */ |
3270 | |
3271 | /* |
3272 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
3273 | ** METHOD: sqlite3 |
3274 | ** |
3275 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
3276 | ** [extended result codes] feature of SQLite. ^The extended result |
3277 | ** codes are disabled by default for historical compatibility. |
3278 | */ |
3279 | SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); |
3280 | |
3281 | /* |
3282 | ** CAPI3REF: Last Insert Rowid |
3283 | ** METHOD: sqlite3 |
3284 | ** |
3285 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
3286 | ** has a unique 64-bit signed |
3287 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
3288 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
3289 | ** names are not also used by explicitly declared columns. ^If |
3290 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
3291 | ** is another alias for the rowid. |
3292 | ** |
3293 | ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of |
3294 | ** the most recent successful [INSERT] into a rowid table or [virtual table] |
3295 | ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not |
3296 | ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred |
3297 | ** on the database connection D, then sqlite3_last_insert_rowid(D) returns |
3298 | ** zero. |
3299 | ** |
3300 | ** As well as being set automatically as rows are inserted into database |
3301 | ** tables, the value returned by this function may be set explicitly by |
3302 | ** [sqlite3_set_last_insert_rowid()] |
3303 | ** |
3304 | ** Some virtual table implementations may INSERT rows into rowid tables as |
3305 | ** part of committing a transaction (e.g. to flush data accumulated in memory |
3306 | ** to disk). In this case subsequent calls to this function return the rowid |
3307 | ** associated with these internal INSERT operations, which leads to |
3308 | ** unintuitive results. Virtual table implementations that do write to rowid |
3309 | ** tables in this way can avoid this problem by restoring the original |
3310 | ** rowid value using [sqlite3_set_last_insert_rowid()] before returning |
3311 | ** control to the user. |
3312 | ** |
3313 | ** ^(If an [INSERT] occurs within a trigger then this routine will |
3314 | ** return the [rowid] of the inserted row as long as the trigger is |
3315 | ** running. Once the trigger program ends, the value returned |
3316 | ** by this routine reverts to what it was before the trigger was fired.)^ |
3317 | ** |
3318 | ** ^An [INSERT] that fails due to a constraint violation is not a |
3319 | ** successful [INSERT] and does not change the value returned by this |
3320 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
3321 | ** and INSERT OR ABORT make no changes to the return value of this |
3322 | ** routine when their insertion fails. ^(When INSERT OR REPLACE |
3323 | ** encounters a constraint violation, it does not fail. The |
3324 | ** INSERT continues to completion after deleting rows that caused |
3325 | ** the constraint problem so INSERT OR REPLACE will always change |
3326 | ** the return value of this interface.)^ |
3327 | ** |
3328 | ** ^For the purposes of this routine, an [INSERT] is considered to |
3329 | ** be successful even if it is subsequently rolled back. |
3330 | ** |
3331 | ** This function is accessible to SQL statements via the |
3332 | ** [last_insert_rowid() SQL function]. |
3333 | ** |
3334 | ** If a separate thread performs a new [INSERT] on the same |
3335 | ** database connection while the [sqlite3_last_insert_rowid()] |
3336 | ** function is running and thus changes the last insert [rowid], |
3337 | ** then the value returned by [sqlite3_last_insert_rowid()] is |
3338 | ** unpredictable and might not equal either the old or the new |
3339 | ** last insert [rowid]. |
3340 | */ |
3341 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
3342 | |
3343 | /* |
3344 | ** CAPI3REF: Set the Last Insert Rowid value. |
3345 | ** METHOD: sqlite3 |
3346 | ** |
3347 | ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to |
3348 | ** set the value returned by calling sqlite3_last_insert_rowid(D) to R |
3349 | ** without inserting a row into the database. |
3350 | */ |
3351 | SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); |
3352 | |
3353 | /* |
3354 | ** CAPI3REF: Count The Number Of Rows Modified |
3355 | ** METHOD: sqlite3 |
3356 | ** |
3357 | ** ^This function returns the number of rows modified, inserted or |
3358 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
3359 | ** statement on the database connection specified by the only parameter. |
3360 | ** ^Executing any other type of SQL statement does not modify the value |
3361 | ** returned by this function. |
3362 | ** |
3363 | ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are |
3364 | ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], |
3365 | ** [foreign key actions] or [REPLACE] constraint resolution are not counted. |
3366 | ** |
3367 | ** Changes to a view that are intercepted by |
3368 | ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value |
3369 | ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or |
3370 | ** DELETE statement run on a view is always zero. Only changes made to real |
3371 | ** tables are counted. |
3372 | ** |
3373 | ** Things are more complicated if the sqlite3_changes() function is |
3374 | ** executed while a trigger program is running. This may happen if the |
3375 | ** program uses the [changes() SQL function], or if some other callback |
3376 | ** function invokes sqlite3_changes() directly. Essentially: |
3377 | ** |
3378 | ** <ul> |
3379 | ** <li> ^(Before entering a trigger program the value returned by |
3380 | ** sqlite3_changes() function is saved. After the trigger program |
3381 | ** has finished, the original value is restored.)^ |
3382 | ** |
3383 | ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE |
3384 | ** statement sets the value returned by sqlite3_changes() |
3385 | ** upon completion as normal. Of course, this value will not include |
3386 | ** any changes performed by sub-triggers, as the sqlite3_changes() |
3387 | ** value will be saved and restored after each sub-trigger has run.)^ |
3388 | ** </ul> |
3389 | ** |
3390 | ** ^This means that if the changes() SQL function (or similar) is used |
3391 | ** by the first INSERT, UPDATE or DELETE statement within a trigger, it |
3392 | ** returns the value as set when the calling statement began executing. |
3393 | ** ^If it is used by the second or subsequent such statement within a trigger |
3394 | ** program, the value returned reflects the number of rows modified by the |
3395 | ** previous INSERT, UPDATE or DELETE statement within the same trigger. |
3396 | ** |
3397 | ** If a separate thread makes changes on the same database connection |
3398 | ** while [sqlite3_changes()] is running then the value returned |
3399 | ** is unpredictable and not meaningful. |
3400 | ** |
3401 | ** See also: |
3402 | ** <ul> |
3403 | ** <li> the [sqlite3_total_changes()] interface |
3404 | ** <li> the [count_changes pragma] |
3405 | ** <li> the [changes() SQL function] |
3406 | ** <li> the [data_version pragma] |
3407 | ** </ul> |
3408 | */ |
3409 | SQLITE_API int sqlite3_changes(sqlite3*); |
3410 | |
3411 | /* |
3412 | ** CAPI3REF: Total Number Of Rows Modified |
3413 | ** METHOD: sqlite3 |
3414 | ** |
3415 | ** ^This function returns the total number of rows inserted, modified or |
3416 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
3417 | ** since the database connection was opened, including those executed as |
3418 | ** part of trigger programs. ^Executing any other type of SQL statement |
3419 | ** does not affect the value returned by sqlite3_total_changes(). |
3420 | ** |
3421 | ** ^Changes made as part of [foreign key actions] are included in the |
3422 | ** count, but those made as part of REPLACE constraint resolution are |
3423 | ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers |
3424 | ** are not counted. |
3425 | ** |
3426 | ** The [sqlite3_total_changes(D)] interface only reports the number |
3427 | ** of rows that changed due to SQL statement run against database |
3428 | ** connection D. Any changes by other database connections are ignored. |
3429 | ** To detect changes against a database file from other database |
3430 | ** connections use the [PRAGMA data_version] command or the |
3431 | ** [SQLITE_FCNTL_DATA_VERSION] [file control]. |
3432 | ** |
3433 | ** If a separate thread makes changes on the same database connection |
3434 | ** while [sqlite3_total_changes()] is running then the value |
3435 | ** returned is unpredictable and not meaningful. |
3436 | ** |
3437 | ** See also: |
3438 | ** <ul> |
3439 | ** <li> the [sqlite3_changes()] interface |
3440 | ** <li> the [count_changes pragma] |
3441 | ** <li> the [changes() SQL function] |
3442 | ** <li> the [data_version pragma] |
3443 | ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control] |
3444 | ** </ul> |
3445 | */ |
3446 | SQLITE_API int sqlite3_total_changes(sqlite3*); |
3447 | |
3448 | /* |
3449 | ** CAPI3REF: Interrupt A Long-Running Query |
3450 | ** METHOD: sqlite3 |
3451 | ** |
3452 | ** ^This function causes any pending database operation to abort and |
3453 | ** return at its earliest opportunity. This routine is typically |
3454 | ** called in response to a user action such as pressing "Cancel" |
3455 | ** or Ctrl-C where the user wants a long query operation to halt |
3456 | ** immediately. |
3457 | ** |
3458 | ** ^It is safe to call this routine from a thread different from the |
3459 | ** thread that is currently running the database operation. But it |
3460 | ** is not safe to call this routine with a [database connection] that |
3461 | ** is closed or might close before sqlite3_interrupt() returns. |
3462 | ** |
3463 | ** ^If an SQL operation is very nearly finished at the time when |
3464 | ** sqlite3_interrupt() is called, then it might not have an opportunity |
3465 | ** to be interrupted and might continue to completion. |
3466 | ** |
3467 | ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. |
3468 | ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE |
3469 | ** that is inside an explicit transaction, then the entire transaction |
3470 | ** will be rolled back automatically. |
3471 | ** |
3472 | ** ^The sqlite3_interrupt(D) call is in effect until all currently running |
3473 | ** SQL statements on [database connection] D complete. ^Any new SQL statements |
3474 | ** that are started after the sqlite3_interrupt() call and before the |
3475 | ** running statements reaches zero are interrupted as if they had been |
3476 | ** running prior to the sqlite3_interrupt() call. ^New SQL statements |
3477 | ** that are started after the running statement count reaches zero are |
3478 | ** not effected by the sqlite3_interrupt(). |
3479 | ** ^A call to sqlite3_interrupt(D) that occurs when there are no running |
3480 | ** SQL statements is a no-op and has no effect on SQL statements |
3481 | ** that are started after the sqlite3_interrupt() call returns. |
3482 | */ |
3483 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
3484 | |
3485 | /* |
3486 | ** CAPI3REF: Determine If An SQL Statement Is Complete |
3487 | ** |
3488 | ** These routines are useful during command-line input to determine if the |
3489 | ** currently entered text seems to form a complete SQL statement or |
3490 | ** if additional input is needed before sending the text into |
3491 | ** SQLite for parsing. ^These routines return 1 if the input string |
3492 | ** appears to be a complete SQL statement. ^A statement is judged to be |
3493 | ** complete if it ends with a semicolon token and is not a prefix of a |
3494 | ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within |
3495 | ** string literals or quoted identifier names or comments are not |
3496 | ** independent tokens (they are part of the token in which they are |
3497 | ** embedded) and thus do not count as a statement terminator. ^Whitespace |
3498 | ** and comments that follow the final semicolon are ignored. |
3499 | ** |
3500 | ** ^These routines return 0 if the statement is incomplete. ^If a |
3501 | ** memory allocation fails, then SQLITE_NOMEM is returned. |
3502 | ** |
3503 | ** ^These routines do not parse the SQL statements thus |
3504 | ** will not detect syntactically incorrect SQL. |
3505 | ** |
3506 | ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior |
3507 | ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked |
3508 | ** automatically by sqlite3_complete16(). If that initialization fails, |
3509 | ** then the return value from sqlite3_complete16() will be non-zero |
3510 | ** regardless of whether or not the input SQL is complete.)^ |
3511 | ** |
3512 | ** The input to [sqlite3_complete()] must be a zero-terminated |
3513 | ** UTF-8 string. |
3514 | ** |
3515 | ** The input to [sqlite3_complete16()] must be a zero-terminated |
3516 | ** UTF-16 string in native byte order. |
3517 | */ |
3518 | SQLITE_API int sqlite3_complete(const char *sql); |
3519 | SQLITE_API int sqlite3_complete16(const void *sql); |
3520 | |
3521 | /* |
3522 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
3523 | ** KEYWORDS: {busy-handler callback} {busy handler} |
3524 | ** METHOD: sqlite3 |
3525 | ** |
3526 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
3527 | ** that might be invoked with argument P whenever |
3528 | ** an attempt is made to access a database table associated with |
3529 | ** [database connection] D when another thread |
3530 | ** or process has the table locked. |
3531 | ** The sqlite3_busy_handler() interface is used to implement |
3532 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
3533 | ** |
3534 | ** ^If the busy callback is NULL, then [SQLITE_BUSY] |
3535 | ** is returned immediately upon encountering the lock. ^If the busy callback |
3536 | ** is not NULL, then the callback might be invoked with two arguments. |
3537 | ** |
3538 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
3539 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
3540 | ** the busy handler callback is the number of times that the busy handler has |
3541 | ** been invoked previously for the same locking event. ^If the |
3542 | ** busy callback returns 0, then no additional attempts are made to |
3543 | ** access the database and [SQLITE_BUSY] is returned |
3544 | ** to the application. |
3545 | ** ^If the callback returns non-zero, then another attempt |
3546 | ** is made to access the database and the cycle repeats. |
3547 | ** |
3548 | ** The presence of a busy handler does not guarantee that it will be invoked |
3549 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
3550 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
3551 | ** to the application instead of invoking the |
3552 | ** busy handler. |
3553 | ** Consider a scenario where one process is holding a read lock that |
3554 | ** it is trying to promote to a reserved lock and |
3555 | ** a second process is holding a reserved lock that it is trying |
3556 | ** to promote to an exclusive lock. The first process cannot proceed |
3557 | ** because it is blocked by the second and the second process cannot |
3558 | ** proceed because it is blocked by the first. If both processes |
3559 | ** invoke the busy handlers, neither will make any progress. Therefore, |
3560 | ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this |
3561 | ** will induce the first process to release its read lock and allow |
3562 | ** the second process to proceed. |
3563 | ** |
3564 | ** ^The default busy callback is NULL. |
3565 | ** |
3566 | ** ^(There can only be a single busy handler defined for each |
3567 | ** [database connection]. Setting a new busy handler clears any |
3568 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
3569 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
3570 | ** busy handler and thus clear any previously set busy handler. |
3571 | ** |
3572 | ** The busy callback should not take any actions which modify the |
3573 | ** database connection that invoked the busy handler. In other words, |
3574 | ** the busy handler is not reentrant. Any such actions |
3575 | ** result in undefined behavior. |
3576 | ** |
3577 | ** A busy handler must not close the database connection |
3578 | ** or [prepared statement] that invoked the busy handler. |
3579 | */ |
3580 | SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); |
3581 | |
3582 | /* |
3583 | ** CAPI3REF: Set A Busy Timeout |
3584 | ** METHOD: sqlite3 |
3585 | ** |
3586 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
3587 | ** for a specified amount of time when a table is locked. ^The handler |
3588 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
3589 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
3590 | ** the handler returns 0 which causes [sqlite3_step()] to return |
3591 | ** [SQLITE_BUSY]. |
3592 | ** |
3593 | ** ^Calling this routine with an argument less than or equal to zero |
3594 | ** turns off all busy handlers. |
3595 | ** |
3596 | ** ^(There can only be a single busy handler for a particular |
3597 | ** [database connection] at any given moment. If another busy handler |
3598 | ** was defined (using [sqlite3_busy_handler()]) prior to calling |
3599 | ** this routine, that other busy handler is cleared.)^ |
3600 | ** |
3601 | ** See also: [PRAGMA busy_timeout] |
3602 | */ |
3603 | SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); |
3604 | |
3605 | /* |
3606 | ** CAPI3REF: Convenience Routines For Running Queries |
3607 | ** METHOD: sqlite3 |
3608 | ** |
3609 | ** This is a legacy interface that is preserved for backwards compatibility. |
3610 | ** Use of this interface is not recommended. |
3611 | ** |
3612 | ** Definition: A <b>result table</b> is memory data structure created by the |
3613 | ** [sqlite3_get_table()] interface. A result table records the |
3614 | ** complete query results from one or more queries. |
3615 | ** |
3616 | ** The table conceptually has a number of rows and columns. But |
3617 | ** these numbers are not part of the result table itself. These |
3618 | ** numbers are obtained separately. Let N be the number of rows |
3619 | ** and M be the number of columns. |
3620 | ** |
3621 | ** A result table is an array of pointers to zero-terminated UTF-8 strings. |
3622 | ** There are (N+1)*M elements in the array. The first M pointers point |
3623 | ** to zero-terminated strings that contain the names of the columns. |
3624 | ** The remaining entries all point to query results. NULL values result |
3625 | ** in NULL pointers. All other values are in their UTF-8 zero-terminated |
3626 | ** string representation as returned by [sqlite3_column_text()]. |
3627 | ** |
3628 | ** A result table might consist of one or more memory allocations. |
3629 | ** It is not safe to pass a result table directly to [sqlite3_free()]. |
3630 | ** A result table should be deallocated using [sqlite3_free_table()]. |
3631 | ** |
3632 | ** ^(As an example of the result table format, suppose a query result |
3633 | ** is as follows: |
3634 | ** |
3635 | ** <blockquote><pre> |
3636 | ** Name | Age |
3637 | ** ----------------------- |
3638 | ** Alice | 43 |
3639 | ** Bob | 28 |
3640 | ** Cindy | 21 |
3641 | ** </pre></blockquote> |
3642 | ** |
3643 | ** There are two column (M==2) and three rows (N==3). Thus the |
3644 | ** result table has 8 entries. Suppose the result table is stored |
3645 | ** in an array names azResult. Then azResult holds this content: |
3646 | ** |
3647 | ** <blockquote><pre> |
3648 | ** azResult[0] = "Name"; |
3649 | ** azResult[1] = "Age"; |
3650 | ** azResult[2] = "Alice"; |
3651 | ** azResult[3] = "43"; |
3652 | ** azResult[4] = "Bob"; |
3653 | ** azResult[5] = "28"; |
3654 | ** azResult[6] = "Cindy"; |
3655 | ** azResult[7] = "21"; |
3656 | ** </pre></blockquote>)^ |
3657 | ** |
3658 | ** ^The sqlite3_get_table() function evaluates one or more |
3659 | ** semicolon-separated SQL statements in the zero-terminated UTF-8 |
3660 | ** string of its 2nd parameter and returns a result table to the |
3661 | ** pointer given in its 3rd parameter. |
3662 | ** |
3663 | ** After the application has finished with the result from sqlite3_get_table(), |
3664 | ** it must pass the result table pointer to sqlite3_free_table() in order to |
3665 | ** release the memory that was malloced. Because of the way the |
3666 | ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling |
3667 | ** function must not try to call [sqlite3_free()] directly. Only |
3668 | ** [sqlite3_free_table()] is able to release the memory properly and safely. |
3669 | ** |
3670 | ** The sqlite3_get_table() interface is implemented as a wrapper around |
3671 | ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access |
3672 | ** to any internal data structures of SQLite. It uses only the public |
3673 | ** interface defined here. As a consequence, errors that occur in the |
3674 | ** wrapper layer outside of the internal [sqlite3_exec()] call are not |
3675 | ** reflected in subsequent calls to [sqlite3_errcode()] or |
3676 | ** [sqlite3_errmsg()]. |
3677 | */ |
3678 | SQLITE_API int sqlite3_get_table( |
3679 | sqlite3 *db, /* An open database */ |
3680 | const char *zSql, /* SQL to be evaluated */ |
3681 | char ***pazResult, /* Results of the query */ |
3682 | int *pnRow, /* Number of result rows written here */ |
3683 | int *pnColumn, /* Number of result columns written here */ |
3684 | char **pzErrmsg /* Error msg written here */ |
3685 | ); |
3686 | SQLITE_API void sqlite3_free_table(char **result); |
3687 | |
3688 | /* |
3689 | ** CAPI3REF: Formatted String Printing Functions |
3690 | ** |
3691 | ** These routines are work-alikes of the "printf()" family of functions |
3692 | ** from the standard C library. |
3693 | ** These routines understand most of the common formatting options from |
3694 | ** the standard library printf() |
3695 | ** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]). |
3696 | ** See the [built-in printf()] documentation for details. |
3697 | ** |
3698 | ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their |
3699 | ** results into memory obtained from [sqlite3_malloc64()]. |
3700 | ** The strings returned by these two routines should be |
3701 | ** released by [sqlite3_free()]. ^Both routines return a |
3702 | ** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough |
3703 | ** memory to hold the resulting string. |
3704 | ** |
3705 | ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from |
3706 | ** the standard C library. The result is written into the |
3707 | ** buffer supplied as the second parameter whose size is given by |
3708 | ** the first parameter. Note that the order of the |
3709 | ** first two parameters is reversed from snprintf().)^ This is an |
3710 | ** historical accident that cannot be fixed without breaking |
3711 | ** backwards compatibility. ^(Note also that sqlite3_snprintf() |
3712 | ** returns a pointer to its buffer instead of the number of |
3713 | ** characters actually written into the buffer.)^ We admit that |
3714 | ** the number of characters written would be a more useful return |
3715 | ** value but we cannot change the implementation of sqlite3_snprintf() |
3716 | ** now without breaking compatibility. |
3717 | ** |
3718 | ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() |
3719 | ** guarantees that the buffer is always zero-terminated. ^The first |
3720 | ** parameter "n" is the total size of the buffer, including space for |
3721 | ** the zero terminator. So the longest string that can be completely |
3722 | ** written will be n-1 characters. |
3723 | ** |
3724 | ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). |
3725 | ** |
3726 | ** See also: [built-in printf()], [printf() SQL function] |
3727 | */ |
3728 | SQLITE_API char *sqlite3_mprintf(const char*,...); |
3729 | SQLITE_API char *sqlite3_vmprintf(const char*, va_list); |
3730 | SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); |
3731 | SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); |
3732 | |
3733 | /* |
3734 | ** CAPI3REF: Memory Allocation Subsystem |
3735 | ** |
3736 | ** The SQLite core uses these three routines for all of its own |
3737 | ** internal memory allocation needs. "Core" in the previous sentence |
3738 | ** does not include operating-system specific VFS implementation. The |
3739 | ** Windows VFS uses native malloc() and free() for some operations. |
3740 | ** |
3741 | ** ^The sqlite3_malloc() routine returns a pointer to a block |
3742 | ** of memory at least N bytes in length, where N is the parameter. |
3743 | ** ^If sqlite3_malloc() is unable to obtain sufficient free |
3744 | ** memory, it returns a NULL pointer. ^If the parameter N to |
3745 | ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns |
3746 | ** a NULL pointer. |
3747 | ** |
3748 | ** ^The sqlite3_malloc64(N) routine works just like |
3749 | ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead |
3750 | ** of a signed 32-bit integer. |
3751 | ** |
3752 | ** ^Calling sqlite3_free() with a pointer previously returned |
3753 | ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so |
3754 | ** that it might be reused. ^The sqlite3_free() routine is |
3755 | ** a no-op if is called with a NULL pointer. Passing a NULL pointer |
3756 | ** to sqlite3_free() is harmless. After being freed, memory |
3757 | ** should neither be read nor written. Even reading previously freed |
3758 | ** memory might result in a segmentation fault or other severe error. |
3759 | ** Memory corruption, a segmentation fault, or other severe error |
3760 | ** might result if sqlite3_free() is called with a non-NULL pointer that |
3761 | ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). |
3762 | ** |
3763 | ** ^The sqlite3_realloc(X,N) interface attempts to resize a |
3764 | ** prior memory allocation X to be at least N bytes. |
3765 | ** ^If the X parameter to sqlite3_realloc(X,N) |
3766 | ** is a NULL pointer then its behavior is identical to calling |
3767 | ** sqlite3_malloc(N). |
3768 | ** ^If the N parameter to sqlite3_realloc(X,N) is zero or |
3769 | ** negative then the behavior is exactly the same as calling |
3770 | ** sqlite3_free(X). |
3771 | ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation |
3772 | ** of at least N bytes in size or NULL if insufficient memory is available. |
3773 | ** ^If M is the size of the prior allocation, then min(N,M) bytes |
3774 | ** of the prior allocation are copied into the beginning of buffer returned |
3775 | ** by sqlite3_realloc(X,N) and the prior allocation is freed. |
3776 | ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the |
3777 | ** prior allocation is not freed. |
3778 | ** |
3779 | ** ^The sqlite3_realloc64(X,N) interfaces works the same as |
3780 | ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead |
3781 | ** of a 32-bit signed integer. |
3782 | ** |
3783 | ** ^If X is a memory allocation previously obtained from sqlite3_malloc(), |
3784 | ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then |
3785 | ** sqlite3_msize(X) returns the size of that memory allocation in bytes. |
3786 | ** ^The value returned by sqlite3_msize(X) might be larger than the number |
3787 | ** of bytes requested when X was allocated. ^If X is a NULL pointer then |
3788 | ** sqlite3_msize(X) returns zero. If X points to something that is not |
3789 | ** the beginning of memory allocation, or if it points to a formerly |
3790 | ** valid memory allocation that has now been freed, then the behavior |
3791 | ** of sqlite3_msize(X) is undefined and possibly harmful. |
3792 | ** |
3793 | ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(), |
3794 | ** sqlite3_malloc64(), and sqlite3_realloc64() |
3795 | ** is always aligned to at least an 8 byte boundary, or to a |
3796 | ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time |
3797 | ** option is used. |
3798 | ** |
3799 | ** In SQLite version 3.5.0 and 3.5.1, it was possible to define |
3800 | ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in |
3801 | ** implementation of these routines to be omitted. That capability |
3802 | ** is no longer provided. Only built-in memory allocators can be used. |
3803 | ** |
3804 | ** Prior to SQLite version 3.7.10, the Windows OS interface layer called |
3805 | ** the system malloc() and free() directly when converting |
3806 | ** filenames between the UTF-8 encoding used by SQLite |
3807 | ** and whatever filename encoding is used by the particular Windows |
3808 | ** installation. Memory allocation errors were detected, but |
3809 | ** they were reported back as [SQLITE_CANTOPEN] or |
3810 | ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. |
3811 | ** |
3812 | ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] |
3813 | ** must be either NULL or else pointers obtained from a prior |
3814 | ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have |
3815 | ** not yet been released. |
3816 | ** |
3817 | ** The application must not read or write any part of |
3818 | ** a block of memory after it has been released using |
3819 | ** [sqlite3_free()] or [sqlite3_realloc()]. |
3820 | */ |
3821 | SQLITE_API void *sqlite3_malloc(int); |
3822 | SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); |
3823 | SQLITE_API void *sqlite3_realloc(void*, int); |
3824 | SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); |
3825 | SQLITE_API void sqlite3_free(void*); |
3826 | SQLITE_API sqlite3_uint64 sqlite3_msize(void*); |
3827 | |
3828 | /* |
3829 | ** CAPI3REF: Memory Allocator Statistics |
3830 | ** |
3831 | ** SQLite provides these two interfaces for reporting on the status |
3832 | ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] |
3833 | ** routines, which form the built-in memory allocation subsystem. |
3834 | ** |
3835 | ** ^The [sqlite3_memory_used()] routine returns the number of bytes |
3836 | ** of memory currently outstanding (malloced but not freed). |
3837 | ** ^The [sqlite3_memory_highwater()] routine returns the maximum |
3838 | ** value of [sqlite3_memory_used()] since the high-water mark |
3839 | ** was last reset. ^The values returned by [sqlite3_memory_used()] and |
3840 | ** [sqlite3_memory_highwater()] include any overhead |
3841 | ** added by SQLite in its implementation of [sqlite3_malloc()], |
3842 | ** but not overhead added by the any underlying system library |
3843 | ** routines that [sqlite3_malloc()] may call. |
3844 | ** |
3845 | ** ^The memory high-water mark is reset to the current value of |
3846 | ** [sqlite3_memory_used()] if and only if the parameter to |
3847 | ** [sqlite3_memory_highwater()] is true. ^The value returned |
3848 | ** by [sqlite3_memory_highwater(1)] is the high-water mark |
3849 | ** prior to the reset. |
3850 | */ |
3851 | SQLITE_API sqlite3_int64 sqlite3_memory_used(void); |
3852 | SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); |
3853 | |
3854 | /* |
3855 | ** CAPI3REF: Pseudo-Random Number Generator |
3856 | ** |
3857 | ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to |
3858 | ** select random [ROWID | ROWIDs] when inserting new records into a table that |
3859 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
3860 | ** the build-in random() and randomblob() SQL functions. This interface allows |
3861 | ** applications to access the same PRNG for other purposes. |
3862 | ** |
3863 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
3864 | ** ^The P parameter can be a NULL pointer. |
3865 | ** |
3866 | ** ^If this routine has not been previously called or if the previous |
3867 | ** call had N less than one or a NULL pointer for P, then the PRNG is |
3868 | ** seeded using randomness obtained from the xRandomness method of |
3869 | ** the default [sqlite3_vfs] object. |
3870 | ** ^If the previous call to this routine had an N of 1 or more and a |
3871 | ** non-NULL P then the pseudo-randomness is generated |
3872 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
3873 | ** method. |
3874 | */ |
3875 | SQLITE_API void sqlite3_randomness(int N, void *P); |
3876 | |
3877 | /* |
3878 | ** CAPI3REF: Compile-Time Authorization Callbacks |
3879 | ** METHOD: sqlite3 |
3880 | ** KEYWORDS: {authorizer callback} |
3881 | ** |
3882 | ** ^This routine registers an authorizer callback with a particular |
3883 | ** [database connection], supplied in the first argument. |
3884 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
3885 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
3886 | ** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()], |
3887 | ** and [sqlite3_prepare16_v3()]. ^At various |
3888 | ** points during the compilation process, as logic is being created |
3889 | ** to perform various actions, the authorizer callback is invoked to |
3890 | ** see if those actions are allowed. ^The authorizer callback should |
3891 | ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the |
3892 | ** specific action but allow the SQL statement to continue to be |
3893 | ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be |
3894 | ** rejected with an error. ^If the authorizer callback returns |
3895 | ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] |
3896 | ** then the [sqlite3_prepare_v2()] or equivalent call that triggered |
3897 | ** the authorizer will fail with an error message. |
3898 | ** |
3899 | ** When the callback returns [SQLITE_OK], that means the operation |
3900 | ** requested is ok. ^When the callback returns [SQLITE_DENY], the |
3901 | ** [sqlite3_prepare_v2()] or equivalent call that triggered the |
3902 | ** authorizer will fail with an error message explaining that |
3903 | ** access is denied. |
3904 | ** |
3905 | ** ^The first parameter to the authorizer callback is a copy of the third |
3906 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
3907 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
3908 | ** the particular action to be authorized. ^The third through sixth parameters |
3909 | ** to the callback are either NULL pointers or zero-terminated strings |
3910 | ** that contain additional details about the action to be authorized. |
3911 | ** Applications must always be prepared to encounter a NULL pointer in any |
3912 | ** of the third through the sixth parameters of the authorization callback. |
3913 | ** |
3914 | ** ^If the action code is [SQLITE_READ] |
3915 | ** and the callback returns [SQLITE_IGNORE] then the |
3916 | ** [prepared statement] statement is constructed to substitute |
3917 | ** a NULL value in place of the table column that would have |
3918 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
3919 | ** return can be used to deny an untrusted user access to individual |
3920 | ** columns of a table. |
3921 | ** ^When a table is referenced by a [SELECT] but no column values are |
3922 | ** extracted from that table (for example in a query like |
3923 | ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback |
3924 | ** is invoked once for that table with a column name that is an empty string. |
3925 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
3926 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
3927 | ** [truncate optimization] is disabled and all rows are deleted individually. |
3928 | ** |
3929 | ** An authorizer is used when [sqlite3_prepare | preparing] |
3930 | ** SQL statements from an untrusted source, to ensure that the SQL statements |
3931 | ** do not try to access data they are not allowed to see, or that they do not |
3932 | ** try to execute malicious statements that damage the database. For |
3933 | ** example, an application may allow a user to enter arbitrary |
3934 | ** SQL queries for evaluation by a database. But the application does |
3935 | ** not want the user to be able to make arbitrary changes to the |
3936 | ** database. An authorizer could then be put in place while the |
3937 | ** user-entered SQL is being [sqlite3_prepare | prepared] that |
3938 | ** disallows everything except [SELECT] statements. |
3939 | ** |
3940 | ** Applications that need to process SQL from untrusted sources |
3941 | ** might also consider lowering resource limits using [sqlite3_limit()] |
3942 | ** and limiting database size using the [max_page_count] [PRAGMA] |
3943 | ** in addition to using an authorizer. |
3944 | ** |
3945 | ** ^(Only a single authorizer can be in place on a database connection |
3946 | ** at a time. Each call to sqlite3_set_authorizer overrides the |
3947 | ** previous call.)^ ^Disable the authorizer by installing a NULL callback. |
3948 | ** The authorizer is disabled by default. |
3949 | ** |
3950 | ** The authorizer callback must not do anything that will modify |
3951 | ** the database connection that invoked the authorizer callback. |
3952 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
3953 | ** database connections for the meaning of "modify" in this paragraph. |
3954 | ** |
3955 | ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the |
3956 | ** statement might be re-prepared during [sqlite3_step()] due to a |
3957 | ** schema change. Hence, the application should ensure that the |
3958 | ** correct authorizer callback remains in place during the [sqlite3_step()]. |
3959 | ** |
3960 | ** ^Note that the authorizer callback is invoked only during |
3961 | ** [sqlite3_prepare()] or its variants. Authorization is not |
3962 | ** performed during statement evaluation in [sqlite3_step()], unless |
3963 | ** as stated in the previous paragraph, sqlite3_step() invokes |
3964 | ** sqlite3_prepare_v2() to reprepare a statement after a schema change. |
3965 | */ |
3966 | SQLITE_API int sqlite3_set_authorizer( |
3967 | sqlite3*, |
3968 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
3969 | void *pUserData |
3970 | ); |
3971 | |
3972 | /* |
3973 | ** CAPI3REF: Authorizer Return Codes |
3974 | ** |
3975 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
3976 | ** return either [SQLITE_OK] or one of these two constants in order |
3977 | ** to signal SQLite whether or not the action is permitted. See the |
3978 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
3979 | ** information. |
3980 | ** |
3981 | ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] |
3982 | ** returned from the [sqlite3_vtab_on_conflict()] interface. |
3983 | */ |
3984 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
3985 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
3986 | |
3987 | /* |
3988 | ** CAPI3REF: Authorizer Action Codes |
3989 | ** |
3990 | ** The [sqlite3_set_authorizer()] interface registers a callback function |
3991 | ** that is invoked to authorize certain SQL statement actions. The |
3992 | ** second parameter to the callback is an integer code that specifies |
3993 | ** what action is being authorized. These are the integer action codes that |
3994 | ** the authorizer callback may be passed. |
3995 | ** |
3996 | ** These action code values signify what kind of operation is to be |
3997 | ** authorized. The 3rd and 4th parameters to the authorization |
3998 | ** callback function will be parameters or NULL depending on which of these |
3999 | ** codes is used as the second parameter. ^(The 5th parameter to the |
4000 | ** authorizer callback is the name of the database ("main", "temp", |
4001 | ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback |
4002 | ** is the name of the inner-most trigger or view that is responsible for |
4003 | ** the access attempt or NULL if this access attempt is directly from |
4004 | ** top-level SQL code. |
4005 | */ |
4006 | /******************************************* 3rd ************ 4th ***********/ |
4007 | #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ |
4008 | #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ |
4009 | #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ |
4010 | #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ |
4011 | #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ |
4012 | #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ |
4013 | #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ |
4014 | #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ |
4015 | #define SQLITE_DELETE 9 /* Table Name NULL */ |
4016 | #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ |
4017 | #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ |
4018 | #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ |
4019 | #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ |
4020 | #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ |
4021 | #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ |
4022 | #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ |
4023 | #define SQLITE_DROP_VIEW 17 /* View Name NULL */ |
4024 | #define SQLITE_INSERT 18 /* Table Name NULL */ |
4025 | #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ |
4026 | #define SQLITE_READ 20 /* Table Name Column Name */ |
4027 | #define SQLITE_SELECT 21 /* NULL NULL */ |
4028 | #define SQLITE_TRANSACTION 22 /* Operation NULL */ |
4029 | #define SQLITE_UPDATE 23 /* Table Name Column Name */ |
4030 | #define SQLITE_ATTACH 24 /* Filename NULL */ |
4031 | #define SQLITE_DETACH 25 /* Database Name NULL */ |
4032 | #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ |
4033 | #define SQLITE_REINDEX 27 /* Index Name NULL */ |
4034 | #define SQLITE_ANALYZE 28 /* Table Name NULL */ |
4035 | #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ |
4036 | #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ |
4037 | #define SQLITE_FUNCTION 31 /* NULL Function Name */ |
4038 | #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ |
4039 | #define SQLITE_COPY 0 /* No longer used */ |
4040 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
4041 | |
4042 | /* |
4043 | ** CAPI3REF: Tracing And Profiling Functions |
4044 | ** METHOD: sqlite3 |
4045 | ** |
4046 | ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface |
4047 | ** instead of the routines described here. |
4048 | ** |
4049 | ** These routines register callback functions that can be used for |
4050 | ** tracing and profiling the execution of SQL statements. |
4051 | ** |
4052 | ** ^The callback function registered by sqlite3_trace() is invoked at |
4053 | ** various times when an SQL statement is being run by [sqlite3_step()]. |
4054 | ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the |
4055 | ** SQL statement text as the statement first begins executing. |
4056 | ** ^(Additional sqlite3_trace() callbacks might occur |
4057 | ** as each triggered subprogram is entered. The callbacks for triggers |
4058 | ** contain a UTF-8 SQL comment that identifies the trigger.)^ |
4059 | ** |
4060 | ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit |
4061 | ** the length of [bound parameter] expansion in the output of sqlite3_trace(). |
4062 | ** |
4063 | ** ^The callback function registered by sqlite3_profile() is invoked |
4064 | ** as each SQL statement finishes. ^The profile callback contains |
4065 | ** the original statement text and an estimate of wall-clock time |
4066 | ** of how long that statement took to run. ^The profile callback |
4067 | ** time is in units of nanoseconds, however the current implementation |
4068 | ** is only capable of millisecond resolution so the six least significant |
4069 | ** digits in the time are meaningless. Future versions of SQLite |
4070 | ** might provide greater resolution on the profiler callback. Invoking |
4071 | ** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the |
4072 | ** profile callback. |
4073 | */ |
4074 | SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*, |
4075 | void(*xTrace)(void*,const char*), void*); |
4076 | SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, |
4077 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
4078 | |
4079 | /* |
4080 | ** CAPI3REF: SQL Trace Event Codes |
4081 | ** KEYWORDS: SQLITE_TRACE |
4082 | ** |
4083 | ** These constants identify classes of events that can be monitored |
4084 | ** using the [sqlite3_trace_v2()] tracing logic. The M argument |
4085 | ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of |
4086 | ** the following constants. ^The first argument to the trace callback |
4087 | ** is one of the following constants. |
4088 | ** |
4089 | ** New tracing constants may be added in future releases. |
4090 | ** |
4091 | ** ^A trace callback has four arguments: xCallback(T,C,P,X). |
4092 | ** ^The T argument is one of the integer type codes above. |
4093 | ** ^The C argument is a copy of the context pointer passed in as the |
4094 | ** fourth argument to [sqlite3_trace_v2()]. |
4095 | ** The P and X arguments are pointers whose meanings depend on T. |
4096 | ** |
4097 | ** <dl> |
4098 | ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt> |
4099 | ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement |
4100 | ** first begins running and possibly at other times during the |
4101 | ** execution of the prepared statement, such as at the start of each |
4102 | ** trigger subprogram. ^The P argument is a pointer to the |
4103 | ** [prepared statement]. ^The X argument is a pointer to a string which |
4104 | ** is the unexpanded SQL text of the prepared statement or an SQL comment |
4105 | ** that indicates the invocation of a trigger. ^The callback can compute |
4106 | ** the same text that would have been returned by the legacy [sqlite3_trace()] |
4107 | ** interface by using the X argument when X begins with "--" and invoking |
4108 | ** [sqlite3_expanded_sql(P)] otherwise. |
4109 | ** |
4110 | ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt> |
4111 | ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same |
4112 | ** information as is provided by the [sqlite3_profile()] callback. |
4113 | ** ^The P argument is a pointer to the [prepared statement] and the |
4114 | ** X argument points to a 64-bit integer which is the estimated of |
4115 | ** the number of nanosecond that the prepared statement took to run. |
4116 | ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes. |
4117 | ** |
4118 | ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt> |
4119 | ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared |
4120 | ** statement generates a single row of result. |
4121 | ** ^The P argument is a pointer to the [prepared statement] and the |
4122 | ** X argument is unused. |
4123 | ** |
4124 | ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt> |
4125 | ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database |
4126 | ** connection closes. |
4127 | ** ^The P argument is a pointer to the [database connection] object |
4128 | ** and the X argument is unused. |
4129 | ** </dl> |
4130 | */ |
4131 | #define SQLITE_TRACE_STMT 0x01 |
4132 | #define SQLITE_TRACE_PROFILE 0x02 |
4133 | #define SQLITE_TRACE_ROW 0x04 |
4134 | #define SQLITE_TRACE_CLOSE 0x08 |
4135 | |
4136 | /* |
4137 | ** CAPI3REF: SQL Trace Hook |
4138 | ** METHOD: sqlite3 |
4139 | ** |
4140 | ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback |
4141 | ** function X against [database connection] D, using property mask M |
4142 | ** and context pointer P. ^If the X callback is |
4143 | ** NULL or if the M mask is zero, then tracing is disabled. The |
4144 | ** M argument should be the bitwise OR-ed combination of |
4145 | ** zero or more [SQLITE_TRACE] constants. |
4146 | ** |
4147 | ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides |
4148 | ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2(). |
4149 | ** |
4150 | ** ^The X callback is invoked whenever any of the events identified by |
4151 | ** mask M occur. ^The integer return value from the callback is currently |
4152 | ** ignored, though this may change in future releases. Callback |
4153 | ** implementations should return zero to ensure future compatibility. |
4154 | ** |
4155 | ** ^A trace callback is invoked with four arguments: callback(T,C,P,X). |
4156 | ** ^The T argument is one of the [SQLITE_TRACE] |
4157 | ** constants to indicate why the callback was invoked. |
4158 | ** ^The C argument is a copy of the context pointer. |
4159 | ** The P and X arguments are pointers whose meanings depend on T. |
4160 | ** |
4161 | ** The sqlite3_trace_v2() interface is intended to replace the legacy |
4162 | ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which |
4163 | ** are deprecated. |
4164 | */ |
4165 | SQLITE_API int sqlite3_trace_v2( |
4166 | sqlite3*, |
4167 | unsigned uMask, |
4168 | int(*xCallback)(unsigned,void*,void*,void*), |
4169 | void *pCtx |
4170 | ); |
4171 | |
4172 | /* |
4173 | ** CAPI3REF: Query Progress Callbacks |
4174 | ** METHOD: sqlite3 |
4175 | ** |
4176 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
4177 | ** function X to be invoked periodically during long running calls to |
4178 | ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
4179 | ** database connection D. An example use for this |
4180 | ** interface is to keep a GUI updated during a large query. |
4181 | ** |
4182 | ** ^The parameter P is passed through as the only parameter to the |
4183 | ** callback function X. ^The parameter N is the approximate number of |
4184 | ** [virtual machine instructions] that are evaluated between successive |
4185 | ** invocations of the callback X. ^If N is less than one then the progress |
4186 | ** handler is disabled. |
4187 | ** |
4188 | ** ^Only a single progress handler may be defined at one time per |
4189 | ** [database connection]; setting a new progress handler cancels the |
4190 | ** old one. ^Setting parameter X to NULL disables the progress handler. |
4191 | ** ^The progress handler is also disabled by setting N to a value less |
4192 | ** than 1. |
4193 | ** |
4194 | ** ^If the progress callback returns non-zero, the operation is |
4195 | ** interrupted. This feature can be used to implement a |
4196 | ** "Cancel" button on a GUI progress dialog box. |
4197 | ** |
4198 | ** The progress handler callback must not do anything that will modify |
4199 | ** the database connection that invoked the progress handler. |
4200 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
4201 | ** database connections for the meaning of "modify" in this paragraph. |
4202 | ** |
4203 | */ |
4204 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
4205 | |
4206 | /* |
4207 | ** CAPI3REF: Opening A New Database Connection |
4208 | ** CONSTRUCTOR: sqlite3 |
4209 | ** |
4210 | ** ^These routines open an SQLite database file as specified by the |
4211 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
4212 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
4213 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
4214 | ** returned in *ppDb, even if an error occurs. The only exception is that |
4215 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
4216 | ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] |
4217 | ** object.)^ ^(If the database is opened (and/or created) successfully, then |
4218 | ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The |
4219 | ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain |
4220 | ** an English language description of the error following a failure of any |
4221 | ** of the sqlite3_open() routines. |
4222 | ** |
4223 | ** ^The default encoding will be UTF-8 for databases created using |
4224 | ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases |
4225 | ** created using sqlite3_open16() will be UTF-16 in the native byte order. |
4226 | ** |
4227 | ** Whether or not an error occurs when it is opened, resources |
4228 | ** associated with the [database connection] handle should be released by |
4229 | ** passing it to [sqlite3_close()] when it is no longer required. |
4230 | ** |
4231 | ** The sqlite3_open_v2() interface works like sqlite3_open() |
4232 | ** except that it accepts two additional parameters for additional control |
4233 | ** over the new database connection. ^(The flags parameter to |
4234 | ** sqlite3_open_v2() can take one of |
4235 | ** the following three values, optionally combined with the |
4236 | ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
4237 | ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ |
4238 | ** |
4239 | ** <dl> |
4240 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
4241 | ** <dd>The database is opened in read-only mode. If the database does not |
4242 | ** already exist, an error is returned.</dd>)^ |
4243 | ** |
4244 | ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> |
4245 | ** <dd>The database is opened for reading and writing if possible, or reading |
4246 | ** only if the file is write protected by the operating system. In either |
4247 | ** case the database must already exist, otherwise an error is returned.</dd>)^ |
4248 | ** |
4249 | ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> |
4250 | ** <dd>The database is opened for reading and writing, and is created if |
4251 | ** it does not already exist. This is the behavior that is always used for |
4252 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
4253 | ** </dl> |
4254 | ** |
4255 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
4256 | ** combinations shown above optionally combined with other |
4257 | ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
4258 | ** then the behavior is undefined. |
4259 | ** |
4260 | ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
4261 | ** opens in the multi-thread [threading mode] as long as the single-thread |
4262 | ** mode has not been set at compile-time or start-time. ^If the |
4263 | ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens |
4264 | ** in the serialized [threading mode] unless single-thread was |
4265 | ** previously selected at compile-time or start-time. |
4266 | ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
4267 | ** eligible to use [shared cache mode], regardless of whether or not shared |
4268 | ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
4269 | ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
4270 | ** participate in [shared cache mode] even if it is enabled. |
4271 | ** |
4272 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
4273 | ** [sqlite3_vfs] object that defines the operating system interface that |
4274 | ** the new database connection should use. ^If the fourth parameter is |
4275 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
4276 | ** |
4277 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
4278 | ** is created for the connection. ^This in-memory database will vanish when |
4279 | ** the database connection is closed. Future versions of SQLite might |
4280 | ** make use of additional special filenames that begin with the ":" character. |
4281 | ** It is recommended that when a database filename actually does begin with |
4282 | ** a ":" character you should prefix the filename with a pathname such as |
4283 | ** "./" to avoid ambiguity. |
4284 | ** |
4285 | ** ^If the filename is an empty string, then a private, temporary |
4286 | ** on-disk database will be created. ^This private database will be |
4287 | ** automatically deleted as soon as the database connection is closed. |
4288 | ** |
4289 | ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> |
4290 | ** |
4291 | ** ^If [URI filename] interpretation is enabled, and the filename argument |
4292 | ** begins with "file:", then the filename is interpreted as a URI. ^URI |
4293 | ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is |
4294 | ** set in the third argument to sqlite3_open_v2(), or if it has |
4295 | ** been enabled globally using the [SQLITE_CONFIG_URI] option with the |
4296 | ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. |
4297 | ** URI filename interpretation is turned off |
4298 | ** by default, but future releases of SQLite might enable URI filename |
4299 | ** interpretation by default. See "[URI filenames]" for additional |
4300 | ** information. |
4301 | ** |
4302 | ** URI filenames are parsed according to RFC 3986. ^If the URI contains an |
4303 | ** authority, then it must be either an empty string or the string |
4304 | ** "localhost". ^If the authority is not an empty string or "localhost", an |
4305 | ** error is returned to the caller. ^The fragment component of a URI, if |
4306 | ** present, is ignored. |
4307 | ** |
4308 | ** ^SQLite uses the path component of the URI as the name of the disk file |
4309 | ** which contains the database. ^If the path begins with a '/' character, |
4310 | ** then it is interpreted as an absolute path. ^If the path does not begin |
4311 | ** with a '/' (meaning that the authority section is omitted from the URI) |
4312 | ** then the path is interpreted as a relative path. |
4313 | ** ^(On windows, the first component of an absolute path |
4314 | ** is a drive specification (e.g. "C:").)^ |
4315 | ** |
4316 | ** [[core URI query parameters]] |
4317 | ** The query component of a URI may contain parameters that are interpreted |
4318 | ** either by SQLite itself, or by a [VFS | custom VFS implementation]. |
4319 | ** SQLite and its built-in [VFSes] interpret the |
4320 | ** following query parameters: |
4321 | ** |
4322 | ** <ul> |
4323 | ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of |
4324 | ** a VFS object that provides the operating system interface that should |
4325 | ** be used to access the database file on disk. ^If this option is set to |
4326 | ** an empty string the default VFS object is used. ^Specifying an unknown |
4327 | ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is |
4328 | ** present, then the VFS specified by the option takes precedence over |
4329 | ** the value passed as the fourth parameter to sqlite3_open_v2(). |
4330 | ** |
4331 | ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", |
4332 | ** "rwc", or "memory". Attempting to set it to any other value is |
4333 | ** an error)^. |
4334 | ** ^If "ro" is specified, then the database is opened for read-only |
4335 | ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the |
4336 | ** third argument to sqlite3_open_v2(). ^If the mode option is set to |
4337 | ** "rw", then the database is opened for read-write (but not create) |
4338 | ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had |
4339 | ** been set. ^Value "rwc" is equivalent to setting both |
4340 | ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is |
4341 | ** set to "memory" then a pure [in-memory database] that never reads |
4342 | ** or writes from disk is used. ^It is an error to specify a value for |
4343 | ** the mode parameter that is less restrictive than that specified by |
4344 | ** the flags passed in the third parameter to sqlite3_open_v2(). |
4345 | ** |
4346 | ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or |
4347 | ** "private". ^Setting it to "shared" is equivalent to setting the |
4348 | ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to |
4349 | ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is |
4350 | ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. |
4351 | ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in |
4352 | ** a URI filename, its value overrides any behavior requested by setting |
4353 | ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. |
4354 | ** |
4355 | ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the |
4356 | ** [powersafe overwrite] property does or does not apply to the |
4357 | ** storage media on which the database file resides. |
4358 | ** |
4359 | ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter |
4360 | ** which if set disables file locking in rollback journal modes. This |
4361 | ** is useful for accessing a database on a filesystem that does not |
4362 | ** support locking. Caution: Database corruption might result if two |
4363 | ** or more processes write to the same database and any one of those |
4364 | ** processes uses nolock=1. |
4365 | ** |
4366 | ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query |
4367 | ** parameter that indicates that the database file is stored on |
4368 | ** read-only media. ^When immutable is set, SQLite assumes that the |
4369 | ** database file cannot be changed, even by a process with higher |
4370 | ** privilege, and so the database is opened read-only and all locking |
4371 | ** and change detection is disabled. Caution: Setting the immutable |
4372 | ** property on a database file that does in fact change can result |
4373 | ** in incorrect query results and/or [SQLITE_CORRUPT] errors. |
4374 | ** See also: [SQLITE_IOCAP_IMMUTABLE]. |
4375 | ** |
4376 | ** </ul> |
4377 | ** |
4378 | ** ^Specifying an unknown parameter in the query component of a URI is not an |
4379 | ** error. Future versions of SQLite might understand additional query |
4380 | ** parameters. See "[query parameters with special meaning to SQLite]" for |
4381 | ** additional information. |
4382 | ** |
4383 | ** [[URI filename examples]] <h3>URI filename examples</h3> |
4384 | ** |
4385 | ** <table border="1" align=center cellpadding=5> |
4386 | ** <tr><th> URI filenames <th> Results |
4387 | ** <tr><td> file:data.db <td> |
4388 | ** Open the file "data.db" in the current directory. |
4389 | ** <tr><td> file:/home/fred/data.db<br> |
4390 | ** file:///home/fred/data.db <br> |
4391 | ** file://localhost/home/fred/data.db <br> <td> |
4392 | ** Open the database file "/home/fred/data.db". |
4393 | ** <tr><td> file://darkstar/home/fred/data.db <td> |
4394 | ** An error. "darkstar" is not a recognized authority. |
4395 | ** <tr><td style="white-space:nowrap"> |
4396 | ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db |
4397 | ** <td> Windows only: Open the file "data.db" on fred's desktop on drive |
4398 | ** C:. Note that the %20 escaping in this example is not strictly |
4399 | ** necessary - space characters can be used literally |
4400 | ** in URI filenames. |
4401 | ** <tr><td> file:data.db?mode=ro&cache=private <td> |
4402 | ** Open file "data.db" in the current directory for read-only access. |
4403 | ** Regardless of whether or not shared-cache mode is enabled by |
4404 | ** default, use a private cache. |
4405 | ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td> |
4406 | ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile" |
4407 | ** that uses dot-files in place of posix advisory locking. |
4408 | ** <tr><td> file:data.db?mode=readonly <td> |
4409 | ** An error. "readonly" is not a valid option for the "mode" parameter. |
4410 | ** </table> |
4411 | ** |
4412 | ** ^URI hexadecimal escape sequences (%HH) are supported within the path and |
4413 | ** query components of a URI. A hexadecimal escape sequence consists of a |
4414 | ** percent sign - "%" - followed by exactly two hexadecimal digits |
4415 | ** specifying an octet value. ^Before the path or query components of a |
4416 | ** URI filename are interpreted, they are encoded using UTF-8 and all |
4417 | ** hexadecimal escape sequences replaced by a single byte containing the |
4418 | ** corresponding octet. If this process generates an invalid UTF-8 encoding, |
4419 | ** the results are undefined. |
4420 | ** |
4421 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
4422 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
4423 | ** codepage is currently defined. Filenames containing international |
4424 | ** characters must be converted to UTF-8 prior to passing them into |
4425 | ** sqlite3_open() or sqlite3_open_v2(). |
4426 | ** |
4427 | ** <b>Note to Windows Runtime users:</b> The temporary directory must be set |
4428 | ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various |
4429 | ** features that require the use of temporary files may fail. |
4430 | ** |
4431 | ** See also: [sqlite3_temp_directory] |
4432 | */ |
4433 | SQLITE_API int sqlite3_open( |
4434 | const char *filename, /* Database filename (UTF-8) */ |
4435 | sqlite3 **ppDb /* OUT: SQLite db handle */ |
4436 | ); |
4437 | SQLITE_API int sqlite3_open16( |
4438 | const void *filename, /* Database filename (UTF-16) */ |
4439 | sqlite3 **ppDb /* OUT: SQLite db handle */ |
4440 | ); |
4441 | SQLITE_API int sqlite3_open_v2( |
4442 | const char *filename, /* Database filename (UTF-8) */ |
4443 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
4444 | int flags, /* Flags */ |
4445 | const char *zVfs /* Name of VFS module to use */ |
4446 | ); |
4447 | |
4448 | /* |
4449 | ** CAPI3REF: Obtain Values For URI Parameters |
4450 | ** |
4451 | ** These are utility routines, useful to VFS implementations, that check |
4452 | ** to see if a database file was a URI that contained a specific query |
4453 | ** parameter, and if so obtains the value of that query parameter. |
4454 | ** |
4455 | ** If F is the database filename pointer passed into the xOpen() method of |
4456 | ** a VFS implementation when the flags parameter to xOpen() has one or |
4457 | ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and |
4458 | ** P is the name of the query parameter, then |
4459 | ** sqlite3_uri_parameter(F,P) returns the value of the P |
4460 | ** parameter if it exists or a NULL pointer if P does not appear as a |
4461 | ** query parameter on F. If P is a query parameter of F |
4462 | ** has no explicit value, then sqlite3_uri_parameter(F,P) returns |
4463 | ** a pointer to an empty string. |
4464 | ** |
4465 | ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean |
4466 | ** parameter and returns true (1) or false (0) according to the value |
4467 | ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the |
4468 | ** value of query parameter P is one of "yes", "true", or "on" in any |
4469 | ** case or if the value begins with a non-zero number. The |
4470 | ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of |
4471 | ** query parameter P is one of "no", "false", or "off" in any case or |
4472 | ** if the value begins with a numeric zero. If P is not a query |
4473 | ** parameter on F or if the value of P is does not match any of the |
4474 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
4475 | ** |
4476 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
4477 | ** 64-bit signed integer and returns that integer, or D if P does not |
4478 | ** exist. If the value of P is something other than an integer, then |
4479 | ** zero is returned. |
4480 | ** |
4481 | ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and |
4482 | ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and |
4483 | ** is not a database file pathname pointer that SQLite passed into the xOpen |
4484 | ** VFS method, then the behavior of this routine is undefined and probably |
4485 | ** undesirable. |
4486 | ** |
4487 | ** See the [URI filename] documentation for additional information. |
4488 | */ |
4489 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); |
4490 | SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); |
4491 | SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
4492 | |
4493 | |
4494 | /* |
4495 | ** CAPI3REF: Error Codes And Messages |
4496 | ** METHOD: sqlite3 |
4497 | ** |
4498 | ** ^If the most recent sqlite3_* API call associated with |
4499 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
4500 | ** returns the numeric [result code] or [extended result code] for that |
4501 | ** API call. |
4502 | ** ^The sqlite3_extended_errcode() |
4503 | ** interface is the same except that it always returns the |
4504 | ** [extended result code] even when extended result codes are |
4505 | ** disabled. |
4506 | ** |
4507 | ** The values returned by sqlite3_errcode() and/or |
4508 | ** sqlite3_extended_errcode() might change with each API call. |
4509 | ** Except, there are some interfaces that are guaranteed to never |
4510 | ** change the value of the error code. The error-code preserving |
4511 | ** interfaces are: |
4512 | ** |
4513 | ** <ul> |
4514 | ** <li> sqlite3_errcode() |
4515 | ** <li> sqlite3_extended_errcode() |
4516 | ** <li> sqlite3_errmsg() |
4517 | ** <li> sqlite3_errmsg16() |
4518 | ** </ul> |
4519 | ** |
4520 | ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language |
4521 | ** text that describes the error, as either UTF-8 or UTF-16 respectively. |
4522 | ** ^(Memory to hold the error message string is managed internally. |
4523 | ** The application does not need to worry about freeing the result. |
4524 | ** However, the error string might be overwritten or deallocated by |
4525 | ** subsequent calls to other SQLite interface functions.)^ |
4526 | ** |
4527 | ** ^The sqlite3_errstr() interface returns the English-language text |
4528 | ** that describes the [result code], as UTF-8. |
4529 | ** ^(Memory to hold the error message string is managed internally |
4530 | ** and must not be freed by the application)^. |
4531 | ** |
4532 | ** When the serialized [threading mode] is in use, it might be the |
4533 | ** case that a second error occurs on a separate thread in between |
4534 | ** the time of the first error and the call to these interfaces. |
4535 | ** When that happens, the second error will be reported since these |
4536 | ** interfaces always report the most recent result. To avoid |
4537 | ** this, each thread can obtain exclusive use of the [database connection] D |
4538 | ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning |
4539 | ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after |
4540 | ** all calls to the interfaces listed here are completed. |
4541 | ** |
4542 | ** If an interface fails with SQLITE_MISUSE, that means the interface |
4543 | ** was invoked incorrectly by the application. In that case, the |
4544 | ** error code and message may or may not be set. |
4545 | */ |
4546 | SQLITE_API int sqlite3_errcode(sqlite3 *db); |
4547 | SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); |
4548 | SQLITE_API const char *sqlite3_errmsg(sqlite3*); |
4549 | SQLITE_API const void *sqlite3_errmsg16(sqlite3*); |
4550 | SQLITE_API const char *sqlite3_errstr(int); |
4551 | |
4552 | /* |
4553 | ** CAPI3REF: Prepared Statement Object |
4554 | ** KEYWORDS: {prepared statement} {prepared statements} |
4555 | ** |
4556 | ** An instance of this object represents a single SQL statement that |
4557 | ** has been compiled into binary form and is ready to be evaluated. |
4558 | ** |
4559 | ** Think of each SQL statement as a separate computer program. The |
4560 | ** original SQL text is source code. A prepared statement object |
4561 | ** is the compiled object code. All SQL must be converted into a |
4562 | ** prepared statement before it can be run. |
4563 | ** |
4564 | ** The life-cycle of a prepared statement object usually goes like this: |
4565 | ** |
4566 | ** <ol> |
4567 | ** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. |
4568 | ** <li> Bind values to [parameters] using the sqlite3_bind_*() |
4569 | ** interfaces. |
4570 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
4571 | ** <li> Reset the prepared statement using [sqlite3_reset()] then go back |
4572 | ** to step 2. Do this zero or more times. |
4573 | ** <li> Destroy the object using [sqlite3_finalize()]. |
4574 | ** </ol> |
4575 | */ |
4576 | typedef struct sqlite3_stmt sqlite3_stmt; |
4577 | |
4578 | /* |
4579 | ** CAPI3REF: Run-time Limits |
4580 | ** METHOD: sqlite3 |
4581 | ** |
4582 | ** ^(This interface allows the size of various constructs to be limited |
4583 | ** on a connection by connection basis. The first parameter is the |
4584 | ** [database connection] whose limit is to be set or queried. The |
4585 | ** second parameter is one of the [limit categories] that define a |
4586 | ** class of constructs to be size limited. The third parameter is the |
4587 | ** new limit for that construct.)^ |
4588 | ** |
4589 | ** ^If the new limit is a negative number, the limit is unchanged. |
4590 | ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a |
4591 | ** [limits | hard upper bound] |
4592 | ** set at compile-time by a C preprocessor macro called |
4593 | ** [limits | SQLITE_MAX_<i>NAME</i>]. |
4594 | ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ |
4595 | ** ^Attempts to increase a limit above its hard upper bound are |
4596 | ** silently truncated to the hard upper bound. |
4597 | ** |
4598 | ** ^Regardless of whether or not the limit was changed, the |
4599 | ** [sqlite3_limit()] interface returns the prior value of the limit. |
4600 | ** ^Hence, to find the current value of a limit without changing it, |
4601 | ** simply invoke this interface with the third parameter set to -1. |
4602 | ** |
4603 | ** Run-time limits are intended for use in applications that manage |
4604 | ** both their own internal database and also databases that are controlled |
4605 | ** by untrusted external sources. An example application might be a |
4606 | ** web browser that has its own databases for storing history and |
4607 | ** separate databases controlled by JavaScript applications downloaded |
4608 | ** off the Internet. The internal databases can be given the |
4609 | ** large, default limits. Databases managed by external sources can |
4610 | ** be given much smaller limits designed to prevent a denial of service |
4611 | ** attack. Developers might also want to use the [sqlite3_set_authorizer()] |
4612 | ** interface to further control untrusted SQL. The size of the database |
4613 | ** created by an untrusted script can be contained using the |
4614 | ** [max_page_count] [PRAGMA]. |
4615 | ** |
4616 | ** New run-time limit categories may be added in future releases. |
4617 | */ |
4618 | SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); |
4619 | |
4620 | /* |
4621 | ** CAPI3REF: Run-Time Limit Categories |
4622 | ** KEYWORDS: {limit category} {*limit categories} |
4623 | ** |
4624 | ** These constants define various performance limits |
4625 | ** that can be lowered at run-time using [sqlite3_limit()]. |
4626 | ** The synopsis of the meanings of the various limits is shown below. |
4627 | ** Additional information is available at [limits | Limits in SQLite]. |
4628 | ** |
4629 | ** <dl> |
4630 | ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> |
4631 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
4632 | ** |
4633 | ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> |
4634 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
4635 | ** |
4636 | ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> |
4637 | ** <dd>The maximum number of columns in a table definition or in the |
4638 | ** result set of a [SELECT] or the maximum number of columns in an index |
4639 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
4640 | ** |
4641 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
4642 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
4643 | ** |
4644 | ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
4645 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
4646 | ** |
4647 | ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
4648 | ** <dd>The maximum number of instructions in a virtual machine program |
4649 | ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or |
4650 | ** the equivalent tries to allocate space for more than this many opcodes |
4651 | ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^ |
4652 | ** |
4653 | ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
4654 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
4655 | ** |
4656 | ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
4657 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
4658 | ** |
4659 | ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] |
4660 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
4661 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
4662 | ** [GLOB] operators.</dd>)^ |
4663 | ** |
4664 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
4665 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
4666 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
4667 | ** |
4668 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
4669 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
4670 | ** |
4671 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
4672 | ** <dd>The maximum number of auxiliary worker threads that a single |
4673 | ** [prepared statement] may start.</dd>)^ |
4674 | ** </dl> |
4675 | */ |
4676 | #define SQLITE_LIMIT_LENGTH 0 |
4677 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
4678 | #define SQLITE_LIMIT_COLUMN 2 |
4679 | #define SQLITE_LIMIT_EXPR_DEPTH 3 |
4680 | #define SQLITE_LIMIT_COMPOUND_SELECT 4 |
4681 | #define SQLITE_LIMIT_VDBE_OP 5 |
4682 | #define SQLITE_LIMIT_FUNCTION_ARG 6 |
4683 | #define SQLITE_LIMIT_ATTACHED 7 |
4684 | #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 |
4685 | #define SQLITE_LIMIT_VARIABLE_NUMBER 9 |
4686 | #define SQLITE_LIMIT_TRIGGER_DEPTH 10 |
4687 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
4688 | |
4689 | /* |
4690 | ** CAPI3REF: Prepare Flags |
4691 | ** |
4692 | ** These constants define various flags that can be passed into |
4693 | ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and |
4694 | ** [sqlite3_prepare16_v3()] interfaces. |
4695 | ** |
4696 | ** New flags may be added in future releases of SQLite. |
4697 | ** |
4698 | ** <dl> |
4699 | ** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt> |
4700 | ** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner |
4701 | ** that the prepared statement will be retained for a long time and |
4702 | ** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()] |
4703 | ** and [sqlite3_prepare16_v3()] assume that the prepared statement will |
4704 | ** be used just once or at most a few times and then destroyed using |
4705 | ** [sqlite3_finalize()] relatively soon. The current implementation acts |
4706 | ** on this hint by avoiding the use of [lookaside memory] so as not to |
4707 | ** deplete the limited store of lookaside memory. Future versions of |
4708 | ** SQLite may act on this hint differently. |
4709 | ** |
4710 | ** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt> |
4711 | ** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used |
4712 | ** to be required for any prepared statement that wanted to use the |
4713 | ** [sqlite3_normalized_sql()] interface. However, the |
4714 | ** [sqlite3_normalized_sql()] interface is now available to all |
4715 | ** prepared statements, regardless of whether or not they use this |
4716 | ** flag. |
4717 | ** |
4718 | ** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt> |
4719 | ** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler |
4720 | ** to return an error (error code SQLITE_ERROR) if the statement uses |
4721 | ** any virtual tables. |
4722 | ** </dl> |
4723 | */ |
4724 | #define SQLITE_PREPARE_PERSISTENT 0x01 |
4725 | #define SQLITE_PREPARE_NORMALIZE 0x02 |
4726 | #define SQLITE_PREPARE_NO_VTAB 0x04 |
4727 | |
4728 | /* |
4729 | ** CAPI3REF: Compiling An SQL Statement |
4730 | ** KEYWORDS: {SQL statement compiler} |
4731 | ** METHOD: sqlite3 |
4732 | ** CONSTRUCTOR: sqlite3_stmt |
4733 | ** |
4734 | ** To execute an SQL statement, it must first be compiled into a byte-code |
4735 | ** program using one of these routines. Or, in other words, these routines |
4736 | ** are constructors for the [prepared statement] object. |
4737 | ** |
4738 | ** The preferred routine to use is [sqlite3_prepare_v2()]. The |
4739 | ** [sqlite3_prepare()] interface is legacy and should be avoided. |
4740 | ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used |
4741 | ** for special purposes. |
4742 | ** |
4743 | ** The use of the UTF-8 interfaces is preferred, as SQLite currently |
4744 | ** does all parsing using UTF-8. The UTF-16 interfaces are provided |
4745 | ** as a convenience. The UTF-16 interfaces work by converting the |
4746 | ** input text into UTF-8, then invoking the corresponding UTF-8 interface. |
4747 | ** |
4748 | ** The first argument, "db", is a [database connection] obtained from a |
4749 | ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or |
4750 | ** [sqlite3_open16()]. The database connection must not have been closed. |
4751 | ** |
4752 | ** The second argument, "zSql", is the statement to be compiled, encoded |
4753 | ** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(), |
4754 | ** and sqlite3_prepare_v3() |
4755 | ** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(), |
4756 | ** and sqlite3_prepare16_v3() use UTF-16. |
4757 | ** |
4758 | ** ^If the nByte argument is negative, then zSql is read up to the |
4759 | ** first zero terminator. ^If nByte is positive, then it is the |
4760 | ** number of bytes read from zSql. ^If nByte is zero, then no prepared |
4761 | ** statement is generated. |
4762 | ** If the caller knows that the supplied string is nul-terminated, then |
4763 | ** there is a small performance advantage to passing an nByte parameter that |
4764 | ** is the number of bytes in the input string <i>including</i> |
4765 | ** the nul-terminator. |
4766 | ** |
4767 | ** ^If pzTail is not NULL then *pzTail is made to point to the first byte |
4768 | ** past the end of the first SQL statement in zSql. These routines only |
4769 | ** compile the first statement in zSql, so *pzTail is left pointing to |
4770 | ** what remains uncompiled. |
4771 | ** |
4772 | ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be |
4773 | ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set |
4774 | ** to NULL. ^If the input text contains no SQL (if the input is an empty |
4775 | ** string or a comment) then *ppStmt is set to NULL. |
4776 | ** The calling procedure is responsible for deleting the compiled |
4777 | ** SQL statement using [sqlite3_finalize()] after it has finished with it. |
4778 | ** ppStmt may not be NULL. |
4779 | ** |
4780 | ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; |
4781 | ** otherwise an [error code] is returned. |
4782 | ** |
4783 | ** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(), |
4784 | ** and sqlite3_prepare16_v3() interfaces are recommended for all new programs. |
4785 | ** The older interfaces (sqlite3_prepare() and sqlite3_prepare16()) |
4786 | ** are retained for backwards compatibility, but their use is discouraged. |
4787 | ** ^In the "vX" interfaces, the prepared statement |
4788 | ** that is returned (the [sqlite3_stmt] object) contains a copy of the |
4789 | ** original SQL text. This causes the [sqlite3_step()] interface to |
4790 | ** behave differently in three ways: |
4791 | ** |
4792 | ** <ol> |
4793 | ** <li> |
4794 | ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it |
4795 | ** always used to do, [sqlite3_step()] will automatically recompile the SQL |
4796 | ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY] |
4797 | ** retries will occur before sqlite3_step() gives up and returns an error. |
4798 | ** </li> |
4799 | ** |
4800 | ** <li> |
4801 | ** ^When an error occurs, [sqlite3_step()] will return one of the detailed |
4802 | ** [error codes] or [extended error codes]. ^The legacy behavior was that |
4803 | ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code |
4804 | ** and the application would have to make a second call to [sqlite3_reset()] |
4805 | ** in order to find the underlying cause of the problem. With the "v2" prepare |
4806 | ** interfaces, the underlying reason for the error is returned immediately. |
4807 | ** </li> |
4808 | ** |
4809 | ** <li> |
4810 | ** ^If the specific value bound to [parameter | host parameter] in the |
4811 | ** WHERE clause might influence the choice of query plan for a statement, |
4812 | ** then the statement will be automatically recompiled, as if there had been |
4813 | ** a schema change, on the first [sqlite3_step()] call following any change |
4814 | ** to the [sqlite3_bind_text | bindings] of that [parameter]. |
4815 | ** ^The specific value of WHERE-clause [parameter] might influence the |
4816 | ** choice of query plan if the parameter is the left-hand side of a [LIKE] |
4817 | ** or [GLOB] operator or if the parameter is compared to an indexed column |
4818 | ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. |
4819 | ** </li> |
4820 | ** </ol> |
4821 | ** |
4822 | ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having |
4823 | ** the extra prepFlags parameter, which is a bit array consisting of zero or |
4824 | ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The |
4825 | ** sqlite3_prepare_v2() interface works exactly the same as |
4826 | ** sqlite3_prepare_v3() with a zero prepFlags parameter. |
4827 | */ |
4828 | SQLITE_API int sqlite3_prepare( |
4829 | sqlite3 *db, /* Database handle */ |
4830 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
4831 | int nByte, /* Maximum length of zSql in bytes. */ |
4832 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4833 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
4834 | ); |
4835 | SQLITE_API int sqlite3_prepare_v2( |
4836 | sqlite3 *db, /* Database handle */ |
4837 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
4838 | int nByte, /* Maximum length of zSql in bytes. */ |
4839 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4840 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
4841 | ); |
4842 | SQLITE_API int sqlite3_prepare_v3( |
4843 | sqlite3 *db, /* Database handle */ |
4844 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
4845 | int nByte, /* Maximum length of zSql in bytes. */ |
4846 | unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ |
4847 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4848 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
4849 | ); |
4850 | SQLITE_API int sqlite3_prepare16( |
4851 | sqlite3 *db, /* Database handle */ |
4852 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
4853 | int nByte, /* Maximum length of zSql in bytes. */ |
4854 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4855 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
4856 | ); |
4857 | SQLITE_API int sqlite3_prepare16_v2( |
4858 | sqlite3 *db, /* Database handle */ |
4859 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
4860 | int nByte, /* Maximum length of zSql in bytes. */ |
4861 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4862 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
4863 | ); |
4864 | SQLITE_API int sqlite3_prepare16_v3( |
4865 | sqlite3 *db, /* Database handle */ |
4866 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
4867 | int nByte, /* Maximum length of zSql in bytes. */ |
4868 | unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ |
4869 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4870 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
4871 | ); |
4872 | |
4873 | /* |
4874 | ** CAPI3REF: Retrieving Statement SQL |
4875 | ** METHOD: sqlite3_stmt |
4876 | ** |
4877 | ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8 |
4878 | ** SQL text used to create [prepared statement] P if P was |
4879 | ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], |
4880 | ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. |
4881 | ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8 |
4882 | ** string containing the SQL text of prepared statement P with |
4883 | ** [bound parameters] expanded. |
4884 | ** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8 |
4885 | ** string containing the normalized SQL text of prepared statement P. The |
4886 | ** semantics used to normalize a SQL statement are unspecified and subject |
4887 | ** to change. At a minimum, literal values will be replaced with suitable |
4888 | ** placeholders. |
4889 | ** |
4890 | ** ^(For example, if a prepared statement is created using the SQL |
4891 | ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345 |
4892 | ** and parameter :xyz is unbound, then sqlite3_sql() will return |
4893 | ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql() |
4894 | ** will return "SELECT 2345,NULL".)^ |
4895 | ** |
4896 | ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory |
4897 | ** is available to hold the result, or if the result would exceed the |
4898 | ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH]. |
4899 | ** |
4900 | ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of |
4901 | ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time |
4902 | ** option causes sqlite3_expanded_sql() to always return NULL. |
4903 | ** |
4904 | ** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P) |
4905 | ** are managed by SQLite and are automatically freed when the prepared |
4906 | ** statement is finalized. |
4907 | ** ^The string returned by sqlite3_expanded_sql(P), on the other hand, |
4908 | ** is obtained from [sqlite3_malloc()] and must be free by the application |
4909 | ** by passing it to [sqlite3_free()]. |
4910 | */ |
4911 | SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); |
4912 | SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); |
4913 | SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt); |
4914 | |
4915 | /* |
4916 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
4917 | ** METHOD: sqlite3_stmt |
4918 | ** |
4919 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
4920 | ** and only if the [prepared statement] X makes no direct changes to |
4921 | ** the content of the database file. |
4922 | ** |
4923 | ** Note that [application-defined SQL functions] or |
4924 | ** [virtual tables] might change the database indirectly as a side effect. |
4925 | ** ^(For example, if an application defines a function "eval()" that |
4926 | ** calls [sqlite3_exec()], then the following SQL statement would |
4927 | ** change the database file through side-effects: |
4928 | ** |
4929 | ** <blockquote><pre> |
4930 | ** SELECT eval('DELETE FROM t1') FROM t2; |
4931 | ** </pre></blockquote> |
4932 | ** |
4933 | ** But because the [SELECT] statement does not change the database file |
4934 | ** directly, sqlite3_stmt_readonly() would still return true.)^ |
4935 | ** |
4936 | ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], |
4937 | ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, |
4938 | ** since the statements themselves do not actually modify the database but |
4939 | ** rather they control the timing of when other statements modify the |
4940 | ** database. ^The [ATTACH] and [DETACH] statements also cause |
4941 | ** sqlite3_stmt_readonly() to return true since, while those statements |
4942 | ** change the configuration of a database connection, they do not make |
4943 | ** changes to the content of the database files on disk. |
4944 | ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since |
4945 | ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and |
4946 | ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so |
4947 | ** sqlite3_stmt_readonly() returns false for those commands. |
4948 | */ |
4949 | SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
4950 | |
4951 | /* |
4952 | ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement |
4953 | ** METHOD: sqlite3_stmt |
4954 | ** |
4955 | ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the |
4956 | ** prepared statement S is an EXPLAIN statement, or 2 if the |
4957 | ** statement S is an EXPLAIN QUERY PLAN. |
4958 | ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is |
4959 | ** an ordinary statement or a NULL pointer. |
4960 | */ |
4961 | SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt); |
4962 | |
4963 | /* |
4964 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
4965 | ** METHOD: sqlite3_stmt |
4966 | ** |
4967 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
4968 | ** [prepared statement] S has been stepped at least once using |
4969 | ** [sqlite3_step(S)] but has neither run to completion (returned |
4970 | ** [SQLITE_DONE] from [sqlite3_step(S)]) nor |
4971 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
4972 | ** interface returns false if S is a NULL pointer. If S is not a |
4973 | ** NULL pointer and is not a pointer to a valid [prepared statement] |
4974 | ** object, then the behavior is undefined and probably undesirable. |
4975 | ** |
4976 | ** This interface can be used in combination [sqlite3_next_stmt()] |
4977 | ** to locate all prepared statements associated with a database |
4978 | ** connection that are in need of being reset. This can be used, |
4979 | ** for example, in diagnostic routines to search for prepared |
4980 | ** statements that are holding a transaction open. |
4981 | */ |
4982 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); |
4983 | |
4984 | /* |
4985 | ** CAPI3REF: Dynamically Typed Value Object |
4986 | ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} |
4987 | ** |
4988 | ** SQLite uses the sqlite3_value object to represent all values |
4989 | ** that can be stored in a database table. SQLite uses dynamic typing |
4990 | ** for the values it stores. ^Values stored in sqlite3_value objects |
4991 | ** can be integers, floating point values, strings, BLOBs, or NULL. |
4992 | ** |
4993 | ** An sqlite3_value object may be either "protected" or "unprotected". |
4994 | ** Some interfaces require a protected sqlite3_value. Other interfaces |
4995 | ** will accept either a protected or an unprotected sqlite3_value. |
4996 | ** Every interface that accepts sqlite3_value arguments specifies |
4997 | ** whether or not it requires a protected sqlite3_value. The |
4998 | ** [sqlite3_value_dup()] interface can be used to construct a new |
4999 | ** protected sqlite3_value from an unprotected sqlite3_value. |
5000 | ** |
5001 | ** The terms "protected" and "unprotected" refer to whether or not |
5002 | ** a mutex is held. An internal mutex is held for a protected |
5003 | ** sqlite3_value object but no mutex is held for an unprotected |
5004 | ** sqlite3_value object. If SQLite is compiled to be single-threaded |
5005 | ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) |
5006 | ** or if SQLite is run in one of reduced mutex modes |
5007 | ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] |
5008 | ** then there is no distinction between protected and unprotected |
5009 | ** sqlite3_value objects and they can be used interchangeably. However, |
5010 | ** for maximum code portability it is recommended that applications |
5011 | ** still make the distinction between protected and unprotected |
5012 | ** sqlite3_value objects even when not strictly required. |
5013 | ** |
5014 | ** ^The sqlite3_value objects that are passed as parameters into the |
5015 | ** implementation of [application-defined SQL functions] are protected. |
5016 | ** ^The sqlite3_value object returned by |
5017 | ** [sqlite3_column_value()] is unprotected. |
5018 | ** Unprotected sqlite3_value objects may only be used as arguments |
5019 | ** to [sqlite3_result_value()], [sqlite3_bind_value()], and |
5020 | ** [sqlite3_value_dup()]. |
5021 | ** The [sqlite3_value_blob | sqlite3_value_type()] family of |
5022 | ** interfaces require protected sqlite3_value objects. |
5023 | */ |
5024 | typedef struct sqlite3_value sqlite3_value; |
5025 | |
5026 | /* |
5027 | ** CAPI3REF: SQL Function Context Object |
5028 | ** |
5029 | ** The context in which an SQL function executes is stored in an |
5030 | ** sqlite3_context object. ^A pointer to an sqlite3_context object |
5031 | ** is always first parameter to [application-defined SQL functions]. |
5032 | ** The application-defined SQL function implementation will pass this |
5033 | ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], |
5034 | ** [sqlite3_aggregate_context()], [sqlite3_user_data()], |
5035 | ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], |
5036 | ** and/or [sqlite3_set_auxdata()]. |
5037 | */ |
5038 | typedef struct sqlite3_context sqlite3_context; |
5039 | |
5040 | /* |
5041 | ** CAPI3REF: Binding Values To Prepared Statements |
5042 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
5043 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
5044 | ** METHOD: sqlite3_stmt |
5045 | ** |
5046 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
5047 | ** literals may be replaced by a [parameter] that matches one of following |
5048 | ** templates: |
5049 | ** |
5050 | ** <ul> |
5051 | ** <li> ? |
5052 | ** <li> ?NNN |
5053 | ** <li> :VVV |
5054 | ** <li> @VVV |
5055 | ** <li> $VVV |
5056 | ** </ul> |
5057 | ** |
5058 | ** In the templates above, NNN represents an integer literal, |
5059 | ** and VVV represents an alphanumeric identifier.)^ ^The values of these |
5060 | ** parameters (also called "host parameter names" or "SQL parameters") |
5061 | ** can be set using the sqlite3_bind_*() routines defined here. |
5062 | ** |
5063 | ** ^The first argument to the sqlite3_bind_*() routines is always |
5064 | ** a pointer to the [sqlite3_stmt] object returned from |
5065 | ** [sqlite3_prepare_v2()] or its variants. |
5066 | ** |
5067 | ** ^The second argument is the index of the SQL parameter to be set. |
5068 | ** ^The leftmost SQL parameter has an index of 1. ^When the same named |
5069 | ** SQL parameter is used more than once, second and subsequent |
5070 | ** occurrences have the same index as the first occurrence. |
5071 | ** ^The index for named parameters can be looked up using the |
5072 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
5073 | ** for "?NNN" parameters is the value of NNN. |
5074 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
5075 | ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). |
5076 | ** |
5077 | ** ^The third argument is the value to bind to the parameter. |
5078 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
5079 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
5080 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
5081 | ** |
5082 | ** ^(In those routines that have a fourth argument, its value is the |
5083 | ** number of bytes in the parameter. To be clear: the value is the |
5084 | ** number of <u>bytes</u> in the value, not the number of characters.)^ |
5085 | ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
5086 | ** is negative, then the length of the string is |
5087 | ** the number of bytes up to the first zero terminator. |
5088 | ** If the fourth parameter to sqlite3_bind_blob() is negative, then |
5089 | ** the behavior is undefined. |
5090 | ** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
5091 | ** or sqlite3_bind_text16() or sqlite3_bind_text64() then |
5092 | ** that parameter must be the byte offset |
5093 | ** where the NUL terminator would occur assuming the string were NUL |
5094 | ** terminated. If any NUL characters occur at byte offsets less than |
5095 | ** the value of the fourth parameter then the resulting string value will |
5096 | ** contain embedded NULs. The result of expressions involving strings |
5097 | ** with embedded NULs is undefined. |
5098 | ** |
5099 | ** ^The fifth argument to the BLOB and string binding interfaces |
5100 | ** is a destructor used to dispose of the BLOB or |
5101 | ** string after SQLite has finished with it. ^The destructor is called |
5102 | ** to dispose of the BLOB or string even if the call to the bind API fails, |
5103 | ** except the destructor is not called if the third parameter is a NULL |
5104 | ** pointer or the fourth parameter is negative. |
5105 | ** ^If the fifth argument is |
5106 | ** the special value [SQLITE_STATIC], then SQLite assumes that the |
5107 | ** information is in static, unmanaged space and does not need to be freed. |
5108 | ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then |
5109 | ** SQLite makes its own private copy of the data immediately, before |
5110 | ** the sqlite3_bind_*() routine returns. |
5111 | ** |
5112 | ** ^The sixth argument to sqlite3_bind_text64() must be one of |
5113 | ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE] |
5114 | ** to specify the encoding of the text in the third parameter. If |
5115 | ** the sixth argument to sqlite3_bind_text64() is not one of the |
5116 | ** allowed values shown above, or if the text encoding is different |
5117 | ** from the encoding specified by the sixth parameter, then the behavior |
5118 | ** is undefined. |
5119 | ** |
5120 | ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that |
5121 | ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory |
5122 | ** (just an integer to hold its size) while it is being processed. |
5123 | ** Zeroblobs are intended to serve as placeholders for BLOBs whose |
5124 | ** content is later written using |
5125 | ** [sqlite3_blob_open | incremental BLOB I/O] routines. |
5126 | ** ^A negative value for the zeroblob results in a zero-length BLOB. |
5127 | ** |
5128 | ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in |
5129 | ** [prepared statement] S to have an SQL value of NULL, but to also be |
5130 | ** associated with the pointer P of type T. ^D is either a NULL pointer or |
5131 | ** a pointer to a destructor function for P. ^SQLite will invoke the |
5132 | ** destructor D with a single argument of P when it is finished using |
5133 | ** P. The T parameter should be a static string, preferably a string |
5134 | ** literal. The sqlite3_bind_pointer() routine is part of the |
5135 | ** [pointer passing interface] added for SQLite 3.20.0. |
5136 | ** |
5137 | ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer |
5138 | ** for the [prepared statement] or with a prepared statement for which |
5139 | ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], |
5140 | ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() |
5141 | ** routine is passed a [prepared statement] that has been finalized, the |
5142 | ** result is undefined and probably harmful. |
5143 | ** |
5144 | ** ^Bindings are not cleared by the [sqlite3_reset()] routine. |
5145 | ** ^Unbound parameters are interpreted as NULL. |
5146 | ** |
5147 | ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an |
5148 | ** [error code] if anything goes wrong. |
5149 | ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB |
5150 | ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or |
5151 | ** [SQLITE_MAX_LENGTH]. |
5152 | ** ^[SQLITE_RANGE] is returned if the parameter |
5153 | ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. |
5154 | ** |
5155 | ** See also: [sqlite3_bind_parameter_count()], |
5156 | ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. |
5157 | */ |
5158 | SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); |
5159 | SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, |
5160 | void(*)(void*)); |
5161 | SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); |
5162 | SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); |
5163 | SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); |
5164 | SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); |
5165 | SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); |
5166 | SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); |
5167 | SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, |
5168 | void(*)(void*), unsigned char encoding); |
5169 | SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
5170 | SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*)); |
5171 | SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
5172 | SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64); |
5173 | |
5174 | /* |
5175 | ** CAPI3REF: Number Of SQL Parameters |
5176 | ** METHOD: sqlite3_stmt |
5177 | ** |
5178 | ** ^This routine can be used to find the number of [SQL parameters] |
5179 | ** in a [prepared statement]. SQL parameters are tokens of the |
5180 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
5181 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
5182 | ** to the parameters at a later time. |
5183 | ** |
5184 | ** ^(This routine actually returns the index of the largest (rightmost) |
5185 | ** parameter. For all forms except ?NNN, this will correspond to the |
5186 | ** number of unique parameters. If parameters of the ?NNN form are used, |
5187 | ** there may be gaps in the list.)^ |
5188 | ** |
5189 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
5190 | ** [sqlite3_bind_parameter_name()], and |
5191 | ** [sqlite3_bind_parameter_index()]. |
5192 | */ |
5193 | SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); |
5194 | |
5195 | /* |
5196 | ** CAPI3REF: Name Of A Host Parameter |
5197 | ** METHOD: sqlite3_stmt |
5198 | ** |
5199 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
5200 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
5201 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
5202 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
5203 | ** respectively. |
5204 | ** In other words, the initial ":" or "$" or "@" or "?" |
5205 | ** is included as part of the name.)^ |
5206 | ** ^Parameters of the form "?" without a following integer have no name |
5207 | ** and are referred to as "nameless" or "anonymous parameters". |
5208 | ** |
5209 | ** ^The first host parameter has an index of 1, not 0. |
5210 | ** |
5211 | ** ^If the value N is out of range or if the N-th parameter is |
5212 | ** nameless, then NULL is returned. ^The returned string is |
5213 | ** always in UTF-8 encoding even if the named parameter was |
5214 | ** originally specified as UTF-16 in [sqlite3_prepare16()], |
5215 | ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. |
5216 | ** |
5217 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
5218 | ** [sqlite3_bind_parameter_count()], and |
5219 | ** [sqlite3_bind_parameter_index()]. |
5220 | */ |
5221 | SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
5222 | |
5223 | /* |
5224 | ** CAPI3REF: Index Of A Parameter With A Given Name |
5225 | ** METHOD: sqlite3_stmt |
5226 | ** |
5227 | ** ^Return the index of an SQL parameter given its name. ^The |
5228 | ** index value returned is suitable for use as the second |
5229 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
5230 | ** is returned if no matching parameter is found. ^The parameter |
5231 | ** name must be given in UTF-8 even if the original statement |
5232 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or |
5233 | ** [sqlite3_prepare16_v3()]. |
5234 | ** |
5235 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
5236 | ** [sqlite3_bind_parameter_count()], and |
5237 | ** [sqlite3_bind_parameter_name()]. |
5238 | */ |
5239 | SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
5240 | |
5241 | /* |
5242 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
5243 | ** METHOD: sqlite3_stmt |
5244 | ** |
5245 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
5246 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
5247 | ** ^Use this routine to reset all host parameters to NULL. |
5248 | */ |
5249 | SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); |
5250 | |
5251 | /* |
5252 | ** CAPI3REF: Number Of Columns In A Result Set |
5253 | ** METHOD: sqlite3_stmt |
5254 | ** |
5255 | ** ^Return the number of columns in the result set returned by the |
5256 | ** [prepared statement]. ^If this routine returns 0, that means the |
5257 | ** [prepared statement] returns no data (for example an [UPDATE]). |
5258 | ** ^However, just because this routine returns a positive number does not |
5259 | ** mean that one or more rows of data will be returned. ^A SELECT statement |
5260 | ** will always have a positive sqlite3_column_count() but depending on the |
5261 | ** WHERE clause constraints and the table content, it might return no rows. |
5262 | ** |
5263 | ** See also: [sqlite3_data_count()] |
5264 | */ |
5265 | SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); |
5266 | |
5267 | /* |
5268 | ** CAPI3REF: Column Names In A Result Set |
5269 | ** METHOD: sqlite3_stmt |
5270 | ** |
5271 | ** ^These routines return the name assigned to a particular column |
5272 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
5273 | ** interface returns a pointer to a zero-terminated UTF-8 string |
5274 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
5275 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
5276 | ** that implements the [SELECT] statement. ^The second parameter is the |
5277 | ** column number. ^The leftmost column is number 0. |
5278 | ** |
5279 | ** ^The returned string pointer is valid until either the [prepared statement] |
5280 | ** is destroyed by [sqlite3_finalize()] or until the statement is automatically |
5281 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
5282 | ** or until the next call to |
5283 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
5284 | ** |
5285 | ** ^If sqlite3_malloc() fails during the processing of either routine |
5286 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
5287 | ** NULL pointer is returned. |
5288 | ** |
5289 | ** ^The name of a result column is the value of the "AS" clause for |
5290 | ** that column, if there is an AS clause. If there is no AS clause |
5291 | ** then the name of the column is unspecified and may change from |
5292 | ** one release of SQLite to the next. |
5293 | */ |
5294 | SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); |
5295 | SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); |
5296 | |
5297 | /* |
5298 | ** CAPI3REF: Source Of Data In A Query Result |
5299 | ** METHOD: sqlite3_stmt |
5300 | ** |
5301 | ** ^These routines provide a means to determine the database, table, and |
5302 | ** table column that is the origin of a particular result column in |
5303 | ** [SELECT] statement. |
5304 | ** ^The name of the database or table or column can be returned as |
5305 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
5306 | ** the database name, the _table_ routines return the table name, and |
5307 | ** the origin_ routines return the column name. |
5308 | ** ^The returned string is valid until the [prepared statement] is destroyed |
5309 | ** using [sqlite3_finalize()] or until the statement is automatically |
5310 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
5311 | ** or until the same information is requested |
5312 | ** again in a different encoding. |
5313 | ** |
5314 | ** ^The names returned are the original un-aliased names of the |
5315 | ** database, table, and column. |
5316 | ** |
5317 | ** ^The first argument to these interfaces is a [prepared statement]. |
5318 | ** ^These functions return information about the Nth result column returned by |
5319 | ** the statement, where N is the second function argument. |
5320 | ** ^The left-most column is column 0 for these routines. |
5321 | ** |
5322 | ** ^If the Nth column returned by the statement is an expression or |
5323 | ** subquery and is not a column value, then all of these functions return |
5324 | ** NULL. ^These routine might also return NULL if a memory allocation error |
5325 | ** occurs. ^Otherwise, they return the name of the attached database, table, |
5326 | ** or column that query result column was extracted from. |
5327 | ** |
5328 | ** ^As with all other SQLite APIs, those whose names end with "16" return |
5329 | ** UTF-16 encoded strings and the other functions return UTF-8. |
5330 | ** |
5331 | ** ^These APIs are only available if the library was compiled with the |
5332 | ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. |
5333 | ** |
5334 | ** If two or more threads call one or more of these routines against the same |
5335 | ** prepared statement and column at the same time then the results are |
5336 | ** undefined. |
5337 | ** |
5338 | ** If two or more threads call one or more |
5339 | ** [sqlite3_column_database_name | column metadata interfaces] |
5340 | ** for the same [prepared statement] and result column |
5341 | ** at the same time then the results are undefined. |
5342 | */ |
5343 | SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); |
5344 | SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); |
5345 | SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); |
5346 | SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); |
5347 | SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); |
5348 | SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); |
5349 | |
5350 | /* |
5351 | ** CAPI3REF: Declared Datatype Of A Query Result |
5352 | ** METHOD: sqlite3_stmt |
5353 | ** |
5354 | ** ^(The first parameter is a [prepared statement]. |
5355 | ** If this statement is a [SELECT] statement and the Nth column of the |
5356 | ** returned result set of that [SELECT] is a table column (not an |
5357 | ** expression or subquery) then the declared type of the table |
5358 | ** column is returned.)^ ^If the Nth column of the result set is an |
5359 | ** expression or subquery, then a NULL pointer is returned. |
5360 | ** ^The returned string is always UTF-8 encoded. |
5361 | ** |
5362 | ** ^(For example, given the database schema: |
5363 | ** |
5364 | ** CREATE TABLE t1(c1 VARIANT); |
5365 | ** |
5366 | ** and the following statement to be compiled: |
5367 | ** |
5368 | ** SELECT c1 + 1, c1 FROM t1; |
5369 | ** |
5370 | ** this routine would return the string "VARIANT" for the second result |
5371 | ** column (i==1), and a NULL pointer for the first result column (i==0).)^ |
5372 | ** |
5373 | ** ^SQLite uses dynamic run-time typing. ^So just because a column |
5374 | ** is declared to contain a particular type does not mean that the |
5375 | ** data stored in that column is of the declared type. SQLite is |
5376 | ** strongly typed, but the typing is dynamic not static. ^Type |
5377 | ** is associated with individual values, not with the containers |
5378 | ** used to hold those values. |
5379 | */ |
5380 | SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); |
5381 | SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); |
5382 | |
5383 | /* |
5384 | ** CAPI3REF: Evaluate An SQL Statement |
5385 | ** METHOD: sqlite3_stmt |
5386 | ** |
5387 | ** After a [prepared statement] has been prepared using any of |
5388 | ** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()], |
5389 | ** or [sqlite3_prepare16_v3()] or one of the legacy |
5390 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
5391 | ** must be called one or more times to evaluate the statement. |
5392 | ** |
5393 | ** The details of the behavior of the sqlite3_step() interface depend |
5394 | ** on whether the statement was prepared using the newer "vX" interfaces |
5395 | ** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()], |
5396 | ** [sqlite3_prepare16_v2()] or the older legacy |
5397 | ** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the |
5398 | ** new "vX" interface is recommended for new applications but the legacy |
5399 | ** interface will continue to be supported. |
5400 | ** |
5401 | ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], |
5402 | ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. |
5403 | ** ^With the "v2" interface, any of the other [result codes] or |
5404 | ** [extended result codes] might be returned as well. |
5405 | ** |
5406 | ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the |
5407 | ** database locks it needs to do its job. ^If the statement is a [COMMIT] |
5408 | ** or occurs outside of an explicit transaction, then you can retry the |
5409 | ** statement. If the statement is not a [COMMIT] and occurs within an |
5410 | ** explicit transaction then you should rollback the transaction before |
5411 | ** continuing. |
5412 | ** |
5413 | ** ^[SQLITE_DONE] means that the statement has finished executing |
5414 | ** successfully. sqlite3_step() should not be called again on this virtual |
5415 | ** machine without first calling [sqlite3_reset()] to reset the virtual |
5416 | ** machine back to its initial state. |
5417 | ** |
5418 | ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] |
5419 | ** is returned each time a new row of data is ready for processing by the |
5420 | ** caller. The values may be accessed using the [column access functions]. |
5421 | ** sqlite3_step() is called again to retrieve the next row of data. |
5422 | ** |
5423 | ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint |
5424 | ** violation) has occurred. sqlite3_step() should not be called again on |
5425 | ** the VM. More information may be found by calling [sqlite3_errmsg()]. |
5426 | ** ^With the legacy interface, a more specific error code (for example, |
5427 | ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) |
5428 | ** can be obtained by calling [sqlite3_reset()] on the |
5429 | ** [prepared statement]. ^In the "v2" interface, |
5430 | ** the more specific error code is returned directly by sqlite3_step(). |
5431 | ** |
5432 | ** [SQLITE_MISUSE] means that the this routine was called inappropriately. |
5433 | ** Perhaps it was called on a [prepared statement] that has |
5434 | ** already been [sqlite3_finalize | finalized] or on one that had |
5435 | ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could |
5436 | ** be the case that the same database connection is being used by two or |
5437 | ** more threads at the same moment in time. |
5438 | ** |
5439 | ** For all versions of SQLite up to and including 3.6.23.1, a call to |
5440 | ** [sqlite3_reset()] was required after sqlite3_step() returned anything |
5441 | ** other than [SQLITE_ROW] before any subsequent invocation of |
5442 | ** sqlite3_step(). Failure to reset the prepared statement using |
5443 | ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from |
5444 | ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1], |
5445 | ** sqlite3_step() began |
5446 | ** calling [sqlite3_reset()] automatically in this circumstance rather |
5447 | ** than returning [SQLITE_MISUSE]. This is not considered a compatibility |
5448 | ** break because any application that ever receives an SQLITE_MISUSE error |
5449 | ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option |
5450 | ** can be used to restore the legacy behavior. |
5451 | ** |
5452 | ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() |
5453 | ** API always returns a generic error code, [SQLITE_ERROR], following any |
5454 | ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call |
5455 | ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the |
5456 | ** specific [error codes] that better describes the error. |
5457 | ** We admit that this is a goofy design. The problem has been fixed |
5458 | ** with the "v2" interface. If you prepare all of your SQL statements |
5459 | ** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()] |
5460 | ** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead |
5461 | ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, |
5462 | ** then the more specific [error codes] are returned directly |
5463 | ** by sqlite3_step(). The use of the "vX" interfaces is recommended. |
5464 | */ |
5465 | SQLITE_API int sqlite3_step(sqlite3_stmt*); |
5466 | |
5467 | /* |
5468 | ** CAPI3REF: Number of columns in a result set |
5469 | ** METHOD: sqlite3_stmt |
5470 | ** |
5471 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
5472 | ** current row of the result set of [prepared statement] P. |
5473 | ** ^If prepared statement P does not have results ready to return |
5474 | ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
5475 | ** interfaces) then sqlite3_data_count(P) returns 0. |
5476 | ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. |
5477 | ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to |
5478 | ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P) |
5479 | ** will return non-zero if previous call to [sqlite3_step](P) returned |
5480 | ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum] |
5481 | ** where it always returns zero since each step of that multi-step |
5482 | ** pragma returns 0 columns of data. |
5483 | ** |
5484 | ** See also: [sqlite3_column_count()] |
5485 | */ |
5486 | SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); |
5487 | |
5488 | /* |
5489 | ** CAPI3REF: Fundamental Datatypes |
5490 | ** KEYWORDS: SQLITE_TEXT |
5491 | ** |
5492 | ** ^(Every value in SQLite has one of five fundamental datatypes: |
5493 | ** |
5494 | ** <ul> |
5495 | ** <li> 64-bit signed integer |
5496 | ** <li> 64-bit IEEE floating point number |
5497 | ** <li> string |
5498 | ** <li> BLOB |
5499 | ** <li> NULL |
5500 | ** </ul>)^ |
5501 | ** |
5502 | ** These constants are codes for each of those types. |
5503 | ** |
5504 | ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 |
5505 | ** for a completely different meaning. Software that links against both |
5506 | ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not |
5507 | ** SQLITE_TEXT. |
5508 | */ |
5509 | #define SQLITE_INTEGER 1 |
5510 | #define SQLITE_FLOAT 2 |
5511 | #define SQLITE_BLOB 4 |
5512 | #define SQLITE_NULL 5 |
5513 | #ifdef SQLITE_TEXT |
5514 | # undef SQLITE_TEXT |
5515 | #else |
5516 | # define SQLITE_TEXT 3 |
5517 | #endif |
5518 | #define SQLITE3_TEXT 3 |
5519 | |
5520 | /* |
5521 | ** CAPI3REF: Result Values From A Query |
5522 | ** KEYWORDS: {column access functions} |
5523 | ** METHOD: sqlite3_stmt |
5524 | ** |
5525 | ** <b>Summary:</b> |
5526 | ** <blockquote><table border=0 cellpadding=0 cellspacing=0> |
5527 | ** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result |
5528 | ** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result |
5529 | ** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result |
5530 | ** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result |
5531 | ** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result |
5532 | ** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result |
5533 | ** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an |
5534 | ** [sqlite3_value|unprotected sqlite3_value] object. |
5535 | ** <tr><td> <td> <td> |
5536 | ** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB |
5537 | ** or a UTF-8 TEXT result in bytes |
5538 | ** <tr><td><b>sqlite3_column_bytes16 </b> |
5539 | ** <td>→ <td>Size of UTF-16 |
5540 | ** TEXT in bytes |
5541 | ** <tr><td><b>sqlite3_column_type</b><td>→<td>Default |
5542 | ** datatype of the result |
5543 | ** </table></blockquote> |
5544 | ** |
5545 | ** <b>Details:</b> |
5546 | ** |
5547 | ** ^These routines return information about a single column of the current |
5548 | ** result row of a query. ^In every case the first argument is a pointer |
5549 | ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] |
5550 | ** that was returned from [sqlite3_prepare_v2()] or one of its variants) |
5551 | ** and the second argument is the index of the column for which information |
5552 | ** should be returned. ^The leftmost column of the result set has the index 0. |
5553 | ** ^The number of columns in the result can be determined using |
5554 | ** [sqlite3_column_count()]. |
5555 | ** |
5556 | ** If the SQL statement does not currently point to a valid row, or if the |
5557 | ** column index is out of range, the result is undefined. |
5558 | ** These routines may only be called when the most recent call to |
5559 | ** [sqlite3_step()] has returned [SQLITE_ROW] and neither |
5560 | ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. |
5561 | ** If any of these routines are called after [sqlite3_reset()] or |
5562 | ** [sqlite3_finalize()] or after [sqlite3_step()] has returned |
5563 | ** something other than [SQLITE_ROW], the results are undefined. |
5564 | ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] |
5565 | ** are called from a different thread while any of these routines |
5566 | ** are pending, then the results are undefined. |
5567 | ** |
5568 | ** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16) |
5569 | ** each return the value of a result column in a specific data format. If |
5570 | ** the result column is not initially in the requested format (for example, |
5571 | ** if the query returns an integer but the sqlite3_column_text() interface |
5572 | ** is used to extract the value) then an automatic type conversion is performed. |
5573 | ** |
5574 | ** ^The sqlite3_column_type() routine returns the |
5575 | ** [SQLITE_INTEGER | datatype code] for the initial data type |
5576 | ** of the result column. ^The returned value is one of [SQLITE_INTEGER], |
5577 | ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. |
5578 | ** The return value of sqlite3_column_type() can be used to decide which |
5579 | ** of the first six interface should be used to extract the column value. |
5580 | ** The value returned by sqlite3_column_type() is only meaningful if no |
5581 | ** automatic type conversions have occurred for the value in question. |
5582 | ** After a type conversion, the result of calling sqlite3_column_type() |
5583 | ** is undefined, though harmless. Future |
5584 | ** versions of SQLite may change the behavior of sqlite3_column_type() |
5585 | ** following a type conversion. |
5586 | ** |
5587 | ** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes() |
5588 | ** or sqlite3_column_bytes16() interfaces can be used to determine the size |
5589 | ** of that BLOB or string. |
5590 | ** |
5591 | ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() |
5592 | ** routine returns the number of bytes in that BLOB or string. |
5593 | ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts |
5594 | ** the string to UTF-8 and then returns the number of bytes. |
5595 | ** ^If the result is a numeric value then sqlite3_column_bytes() uses |
5596 | ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns |
5597 | ** the number of bytes in that string. |
5598 | ** ^If the result is NULL, then sqlite3_column_bytes() returns zero. |
5599 | ** |
5600 | ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() |
5601 | ** routine returns the number of bytes in that BLOB or string. |
5602 | ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts |
5603 | ** the string to UTF-16 and then returns the number of bytes. |
5604 | ** ^If the result is a numeric value then sqlite3_column_bytes16() uses |
5605 | ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns |
5606 | ** the number of bytes in that string. |
5607 | ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. |
5608 | ** |
5609 | ** ^The values returned by [sqlite3_column_bytes()] and |
5610 | ** [sqlite3_column_bytes16()] do not include the zero terminators at the end |
5611 | ** of the string. ^For clarity: the values returned by |
5612 | ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of |
5613 | ** bytes in the string, not the number of characters. |
5614 | ** |
5615 | ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), |
5616 | ** even empty strings, are always zero-terminated. ^The return |
5617 | ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. |
5618 | ** |
5619 | ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an |
5620 | ** [unprotected sqlite3_value] object. In a multithreaded environment, |
5621 | ** an unprotected sqlite3_value object may only be used safely with |
5622 | ** [sqlite3_bind_value()] and [sqlite3_result_value()]. |
5623 | ** If the [unprotected sqlite3_value] object returned by |
5624 | ** [sqlite3_column_value()] is used in any other way, including calls |
5625 | ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], |
5626 | ** or [sqlite3_value_bytes()], the behavior is not threadsafe. |
5627 | ** Hence, the sqlite3_column_value() interface |
5628 | ** is normally only useful within the implementation of |
5629 | ** [application-defined SQL functions] or [virtual tables], not within |
5630 | ** top-level application code. |
5631 | ** |
5632 | ** The these routines may attempt to convert the datatype of the result. |
5633 | ** ^For example, if the internal representation is FLOAT and a text result |
5634 | ** is requested, [sqlite3_snprintf()] is used internally to perform the |
5635 | ** conversion automatically. ^(The following table details the conversions |
5636 | ** that are applied: |
5637 | ** |
5638 | ** <blockquote> |
5639 | ** <table border="1"> |
5640 | ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion |
5641 | ** |
5642 | ** <tr><td> NULL <td> INTEGER <td> Result is 0 |
5643 | ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 |
5644 | ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer |
5645 | ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer |
5646 | ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float |
5647 | ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer |
5648 | ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT |
5649 | ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER |
5650 | ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float |
5651 | ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB |
5652 | ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER |
5653 | ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL |
5654 | ** <tr><td> TEXT <td> BLOB <td> No change |
5655 | ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER |
5656 | ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL |
5657 | ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed |
5658 | ** </table> |
5659 | ** </blockquote>)^ |
5660 | ** |
5661 | ** Note that when type conversions occur, pointers returned by prior |
5662 | ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or |
5663 | ** sqlite3_column_text16() may be invalidated. |
5664 | ** Type conversions and pointer invalidations might occur |
5665 | ** in the following cases: |
5666 | ** |
5667 | ** <ul> |
5668 | ** <li> The initial content is a BLOB and sqlite3_column_text() or |
5669 | ** sqlite3_column_text16() is called. A zero-terminator might |
5670 | ** need to be added to the string.</li> |
5671 | ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or |
5672 | ** sqlite3_column_text16() is called. The content must be converted |
5673 | ** to UTF-16.</li> |
5674 | ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or |
5675 | ** sqlite3_column_text() is called. The content must be converted |
5676 | ** to UTF-8.</li> |
5677 | ** </ul> |
5678 | ** |
5679 | ** ^Conversions between UTF-16be and UTF-16le are always done in place and do |
5680 | ** not invalidate a prior pointer, though of course the content of the buffer |
5681 | ** that the prior pointer references will have been modified. Other kinds |
5682 | ** of conversion are done in place when it is possible, but sometimes they |
5683 | ** are not possible and in those cases prior pointers are invalidated. |
5684 | ** |
5685 | ** The safest policy is to invoke these routines |
5686 | ** in one of the following ways: |
5687 | ** |
5688 | ** <ul> |
5689 | ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> |
5690 | ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> |
5691 | ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> |
5692 | ** </ul> |
5693 | ** |
5694 | ** In other words, you should call sqlite3_column_text(), |
5695 | ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result |
5696 | ** into the desired format, then invoke sqlite3_column_bytes() or |
5697 | ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls |
5698 | ** to sqlite3_column_text() or sqlite3_column_blob() with calls to |
5699 | ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() |
5700 | ** with calls to sqlite3_column_bytes(). |
5701 | ** |
5702 | ** ^The pointers returned are valid until a type conversion occurs as |
5703 | ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or |
5704 | ** [sqlite3_finalize()] is called. ^The memory space used to hold strings |
5705 | ** and BLOBs is freed automatically. Do not pass the pointers returned |
5706 | ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into |
5707 | ** [sqlite3_free()]. |
5708 | ** |
5709 | ** As long as the input parameters are correct, these routines will only |
5710 | ** fail if an out-of-memory error occurs during a format conversion. |
5711 | ** Only the following subset of interfaces are subject to out-of-memory |
5712 | ** errors: |
5713 | ** |
5714 | ** <ul> |
5715 | ** <li> sqlite3_column_blob() |
5716 | ** <li> sqlite3_column_text() |
5717 | ** <li> sqlite3_column_text16() |
5718 | ** <li> sqlite3_column_bytes() |
5719 | ** <li> sqlite3_column_bytes16() |
5720 | ** </ul> |
5721 | ** |
5722 | ** If an out-of-memory error occurs, then the return value from these |
5723 | ** routines is the same as if the column had contained an SQL NULL value. |
5724 | ** Valid SQL NULL returns can be distinguished from out-of-memory errors |
5725 | ** by invoking the [sqlite3_errcode()] immediately after the suspect |
5726 | ** return value is obtained and before any |
5727 | ** other SQLite interface is called on the same [database connection]. |
5728 | */ |
5729 | SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); |
5730 | SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); |
5731 | SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); |
5732 | SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); |
5733 | SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); |
5734 | SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); |
5735 | SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); |
5736 | SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); |
5737 | SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); |
5738 | SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); |
5739 | |
5740 | /* |
5741 | ** CAPI3REF: Destroy A Prepared Statement Object |
5742 | ** DESTRUCTOR: sqlite3_stmt |
5743 | ** |
5744 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
5745 | ** ^If the most recent evaluation of the statement encountered no errors |
5746 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
5747 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
5748 | ** sqlite3_finalize(S) returns the appropriate [error code] or |
5749 | ** [extended error code]. |
5750 | ** |
5751 | ** ^The sqlite3_finalize(S) routine can be called at any point during |
5752 | ** the life cycle of [prepared statement] S: |
5753 | ** before statement S is ever evaluated, after |
5754 | ** one or more calls to [sqlite3_reset()], or after any call |
5755 | ** to [sqlite3_step()] regardless of whether or not the statement has |
5756 | ** completed execution. |
5757 | ** |
5758 | ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. |
5759 | ** |
5760 | ** The application must finalize every [prepared statement] in order to avoid |
5761 | ** resource leaks. It is a grievous error for the application to try to use |
5762 | ** a prepared statement after it has been finalized. Any use of a prepared |
5763 | ** statement after it has been finalized can result in undefined and |
5764 | ** undesirable behavior such as segfaults and heap corruption. |
5765 | */ |
5766 | SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); |
5767 | |
5768 | /* |
5769 | ** CAPI3REF: Reset A Prepared Statement Object |
5770 | ** METHOD: sqlite3_stmt |
5771 | ** |
5772 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
5773 | ** object back to its initial state, ready to be re-executed. |
5774 | ** ^Any SQL statement variables that had values bound to them using |
5775 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
5776 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
5777 | ** |
5778 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
5779 | ** back to the beginning of its program. |
5780 | ** |
5781 | ** ^If the most recent call to [sqlite3_step(S)] for the |
5782 | ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], |
5783 | ** or if [sqlite3_step(S)] has never before been called on S, |
5784 | ** then [sqlite3_reset(S)] returns [SQLITE_OK]. |
5785 | ** |
5786 | ** ^If the most recent call to [sqlite3_step(S)] for the |
5787 | ** [prepared statement] S indicated an error, then |
5788 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
5789 | ** |
5790 | ** ^The [sqlite3_reset(S)] interface does not change the values |
5791 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
5792 | */ |
5793 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
5794 | |
5795 | /* |
5796 | ** CAPI3REF: Create Or Redefine SQL Functions |
5797 | ** KEYWORDS: {function creation routines} |
5798 | ** KEYWORDS: {application-defined SQL function} |
5799 | ** KEYWORDS: {application-defined SQL functions} |
5800 | ** METHOD: sqlite3 |
5801 | ** |
5802 | ** ^These functions (collectively known as "function creation routines") |
5803 | ** are used to add SQL functions or aggregates or to redefine the behavior |
5804 | ** of existing SQL functions or aggregates. The only differences between |
5805 | ** the three "sqlite3_create_function*" routines are the text encoding |
5806 | ** expected for the second parameter (the name of the function being |
5807 | ** created) and the presence or absence of a destructor callback for |
5808 | ** the application data pointer. Function sqlite3_create_window_function() |
5809 | ** is similar, but allows the user to supply the extra callback functions |
5810 | ** needed by [aggregate window functions]. |
5811 | ** |
5812 | ** ^The first parameter is the [database connection] to which the SQL |
5813 | ** function is to be added. ^If an application uses more than one database |
5814 | ** connection then application-defined SQL functions must be added |
5815 | ** to each database connection separately. |
5816 | ** |
5817 | ** ^The second parameter is the name of the SQL function to be created or |
5818 | ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 |
5819 | ** representation, exclusive of the zero-terminator. ^Note that the name |
5820 | ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. |
5821 | ** ^Any attempt to create a function with a longer name |
5822 | ** will result in [SQLITE_MISUSE] being returned. |
5823 | ** |
5824 | ** ^The third parameter (nArg) |
5825 | ** is the number of arguments that the SQL function or |
5826 | ** aggregate takes. ^If this parameter is -1, then the SQL function or |
5827 | ** aggregate may take any number of arguments between 0 and the limit |
5828 | ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third |
5829 | ** parameter is less than -1 or greater than 127 then the behavior is |
5830 | ** undefined. |
5831 | ** |
5832 | ** ^The fourth parameter, eTextRep, specifies what |
5833 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
5834 | ** its parameters. The application should set this parameter to |
5835 | ** [SQLITE_UTF16LE] if the function implementation invokes |
5836 | ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the |
5837 | ** implementation invokes [sqlite3_value_text16be()] on an input, or |
5838 | ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] |
5839 | ** otherwise. ^The same SQL function may be registered multiple times using |
5840 | ** different preferred text encodings, with different implementations for |
5841 | ** each encoding. |
5842 | ** ^When multiple implementations of the same function are available, SQLite |
5843 | ** will pick the one that involves the least amount of data conversion. |
5844 | ** |
5845 | ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] |
5846 | ** to signal that the function will always return the same result given |
5847 | ** the same inputs within a single SQL statement. Most SQL functions are |
5848 | ** deterministic. The built-in [random()] SQL function is an example of a |
5849 | ** function that is not deterministic. The SQLite query planner is able to |
5850 | ** perform additional optimizations on deterministic functions, so use |
5851 | ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. |
5852 | ** |
5853 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
5854 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
5855 | ** |
5856 | ** ^The sixth, seventh and eighth parameters passed to the three |
5857 | ** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are |
5858 | ** pointers to C-language functions that implement the SQL function or |
5859 | ** aggregate. ^A scalar SQL function requires an implementation of the xFunc |
5860 | ** callback only; NULL pointers must be passed as the xStep and xFinal |
5861 | ** parameters. ^An aggregate SQL function requires an implementation of xStep |
5862 | ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing |
5863 | ** SQL function or aggregate, pass NULL pointers for all three function |
5864 | ** callbacks. |
5865 | ** |
5866 | ** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue |
5867 | ** and xInverse) passed to sqlite3_create_window_function are pointers to |
5868 | ** C-language callbacks that implement the new function. xStep and xFinal |
5869 | ** must both be non-NULL. xValue and xInverse may either both be NULL, in |
5870 | ** which case a regular aggregate function is created, or must both be |
5871 | ** non-NULL, in which case the new function may be used as either an aggregate |
5872 | ** or aggregate window function. More details regarding the implementation |
5873 | ** of aggregate window functions are |
5874 | ** [user-defined window functions|available here]. |
5875 | ** |
5876 | ** ^(If the final parameter to sqlite3_create_function_v2() or |
5877 | ** sqlite3_create_window_function() is not NULL, then it is destructor for |
5878 | ** the application data pointer. The destructor is invoked when the function |
5879 | ** is deleted, either by being overloaded or when the database connection |
5880 | ** closes.)^ ^The destructor is also invoked if the call to |
5881 | ** sqlite3_create_function_v2() fails. ^When the destructor callback is |
5882 | ** invoked, it is passed a single argument which is a copy of the application |
5883 | ** data pointer which was the fifth parameter to sqlite3_create_function_v2(). |
5884 | ** |
5885 | ** ^It is permitted to register multiple implementations of the same |
5886 | ** functions with the same name but with either differing numbers of |
5887 | ** arguments or differing preferred text encodings. ^SQLite will use |
5888 | ** the implementation that most closely matches the way in which the |
5889 | ** SQL function is used. ^A function implementation with a non-negative |
5890 | ** nArg parameter is a better match than a function implementation with |
5891 | ** a negative nArg. ^A function where the preferred text encoding |
5892 | ** matches the database encoding is a better |
5893 | ** match than a function where the encoding is different. |
5894 | ** ^A function where the encoding difference is between UTF16le and UTF16be |
5895 | ** is a closer match than a function where the encoding difference is |
5896 | ** between UTF8 and UTF16. |
5897 | ** |
5898 | ** ^Built-in functions may be overloaded by new application-defined functions. |
5899 | ** |
5900 | ** ^An application-defined function is permitted to call other |
5901 | ** SQLite interfaces. However, such calls must not |
5902 | ** close the database connection nor finalize or reset the prepared |
5903 | ** statement in which the function is running. |
5904 | */ |
5905 | SQLITE_API int sqlite3_create_function( |
5906 | sqlite3 *db, |
5907 | const char *zFunctionName, |
5908 | int nArg, |
5909 | int eTextRep, |
5910 | void *pApp, |
5911 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
5912 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5913 | void (*xFinal)(sqlite3_context*) |
5914 | ); |
5915 | SQLITE_API int sqlite3_create_function16( |
5916 | sqlite3 *db, |
5917 | const void *zFunctionName, |
5918 | int nArg, |
5919 | int eTextRep, |
5920 | void *pApp, |
5921 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
5922 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5923 | void (*xFinal)(sqlite3_context*) |
5924 | ); |
5925 | SQLITE_API int sqlite3_create_function_v2( |
5926 | sqlite3 *db, |
5927 | const char *zFunctionName, |
5928 | int nArg, |
5929 | int eTextRep, |
5930 | void *pApp, |
5931 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
5932 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5933 | void (*xFinal)(sqlite3_context*), |
5934 | void(*xDestroy)(void*) |
5935 | ); |
5936 | SQLITE_API int sqlite3_create_window_function( |
5937 | sqlite3 *db, |
5938 | const char *zFunctionName, |
5939 | int nArg, |
5940 | int eTextRep, |
5941 | void *pApp, |
5942 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5943 | void (*xFinal)(sqlite3_context*), |
5944 | void (*xValue)(sqlite3_context*), |
5945 | void (*xInverse)(sqlite3_context*,int,sqlite3_value**), |
5946 | void(*xDestroy)(void*) |
5947 | ); |
5948 | |
5949 | /* |
5950 | ** CAPI3REF: Text Encodings |
5951 | ** |
5952 | ** These constant define integer codes that represent the various |
5953 | ** text encodings supported by SQLite. |
5954 | */ |
5955 | #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */ |
5956 | #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */ |
5957 | #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */ |
5958 | #define SQLITE_UTF16 4 /* Use native byte order */ |
5959 | #define SQLITE_ANY 5 /* Deprecated */ |
5960 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
5961 | |
5962 | /* |
5963 | ** CAPI3REF: Function Flags |
5964 | ** |
5965 | ** These constants may be ORed together with the |
5966 | ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
5967 | ** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
5968 | ** [sqlite3_create_function_v2()]. |
5969 | */ |
5970 | #define SQLITE_DETERMINISTIC 0x800 |
5971 | |
5972 | /* |
5973 | ** CAPI3REF: Deprecated Functions |
5974 | ** DEPRECATED |
5975 | ** |
5976 | ** These functions are [deprecated]. In order to maintain |
5977 | ** backwards compatibility with older code, these functions continue |
5978 | ** to be supported. However, new applications should avoid |
5979 | ** the use of these functions. To encourage programmers to avoid |
5980 | ** these functions, we will not explain what they do. |
5981 | */ |
5982 | #ifndef SQLITE_OMIT_DEPRECATED |
5983 | SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); |
5984 | SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); |
5985 | SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); |
5986 | SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); |
5987 | SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); |
5988 | SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), |
5989 | void*,sqlite3_int64); |
5990 | #endif |
5991 | |
5992 | /* |
5993 | ** CAPI3REF: Obtaining SQL Values |
5994 | ** METHOD: sqlite3_value |
5995 | ** |
5996 | ** <b>Summary:</b> |
5997 | ** <blockquote><table border=0 cellpadding=0 cellspacing=0> |
5998 | ** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value |
5999 | ** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value |
6000 | ** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value |
6001 | ** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value |
6002 | ** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value |
6003 | ** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value |
6004 | ** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in |
6005 | ** the native byteorder |
6006 | ** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value |
6007 | ** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value |
6008 | ** <tr><td> <td> <td> |
6009 | ** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB |
6010 | ** or a UTF-8 TEXT in bytes |
6011 | ** <tr><td><b>sqlite3_value_bytes16 </b> |
6012 | ** <td>→ <td>Size of UTF-16 |
6013 | ** TEXT in bytes |
6014 | ** <tr><td><b>sqlite3_value_type</b><td>→<td>Default |
6015 | ** datatype of the value |
6016 | ** <tr><td><b>sqlite3_value_numeric_type </b> |
6017 | ** <td>→ <td>Best numeric datatype of the value |
6018 | ** <tr><td><b>sqlite3_value_nochange </b> |
6019 | ** <td>→ <td>True if the column is unchanged in an UPDATE |
6020 | ** against a virtual table. |
6021 | ** <tr><td><b>sqlite3_value_frombind </b> |
6022 | ** <td>→ <td>True if value originated from a [bound parameter] |
6023 | ** </table></blockquote> |
6024 | ** |
6025 | ** <b>Details:</b> |
6026 | ** |
6027 | ** These routines extract type, size, and content information from |
6028 | ** [protected sqlite3_value] objects. Protected sqlite3_value objects |
6029 | ** are used to pass parameter information into implementation of |
6030 | ** [application-defined SQL functions] and [virtual tables]. |
6031 | ** |
6032 | ** These routines work only with [protected sqlite3_value] objects. |
6033 | ** Any attempt to use these routines on an [unprotected sqlite3_value] |
6034 | ** is not threadsafe. |
6035 | ** |
6036 | ** ^These routines work just like the corresponding [column access functions] |
6037 | ** except that these routines take a single [protected sqlite3_value] object |
6038 | ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. |
6039 | ** |
6040 | ** ^The sqlite3_value_text16() interface extracts a UTF-16 string |
6041 | ** in the native byte-order of the host machine. ^The |
6042 | ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces |
6043 | ** extract UTF-16 strings as big-endian and little-endian respectively. |
6044 | ** |
6045 | ** ^If [sqlite3_value] object V was initialized |
6046 | ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)] |
6047 | ** and if X and Y are strings that compare equal according to strcmp(X,Y), |
6048 | ** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise, |
6049 | ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer() |
6050 | ** routine is part of the [pointer passing interface] added for SQLite 3.20.0. |
6051 | ** |
6052 | ** ^(The sqlite3_value_type(V) interface returns the |
6053 | ** [SQLITE_INTEGER | datatype code] for the initial datatype of the |
6054 | ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER], |
6055 | ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^ |
6056 | ** Other interfaces might change the datatype for an sqlite3_value object. |
6057 | ** For example, if the datatype is initially SQLITE_INTEGER and |
6058 | ** sqlite3_value_text(V) is called to extract a text value for that |
6059 | ** integer, then subsequent calls to sqlite3_value_type(V) might return |
6060 | ** SQLITE_TEXT. Whether or not a persistent internal datatype conversion |
6061 | ** occurs is undefined and may change from one release of SQLite to the next. |
6062 | ** |
6063 | ** ^(The sqlite3_value_numeric_type() interface attempts to apply |
6064 | ** numeric affinity to the value. This means that an attempt is |
6065 | ** made to convert the value to an integer or floating point. If |
6066 | ** such a conversion is possible without loss of information (in other |
6067 | ** words, if the value is a string that looks like a number) |
6068 | ** then the conversion is performed. Otherwise no conversion occurs. |
6069 | ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ |
6070 | ** |
6071 | ** ^Within the [xUpdate] method of a [virtual table], the |
6072 | ** sqlite3_value_nochange(X) interface returns true if and only if |
6073 | ** the column corresponding to X is unchanged by the UPDATE operation |
6074 | ** that the xUpdate method call was invoked to implement and if |
6075 | ** and the prior [xColumn] method call that was invoked to extracted |
6076 | ** the value for that column returned without setting a result (probably |
6077 | ** because it queried [sqlite3_vtab_nochange()] and found that the column |
6078 | ** was unchanging). ^Within an [xUpdate] method, any value for which |
6079 | ** sqlite3_value_nochange(X) is true will in all other respects appear |
6080 | ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other |
6081 | ** than within an [xUpdate] method call for an UPDATE statement, then |
6082 | ** the return value is arbitrary and meaningless. |
6083 | ** |
6084 | ** ^The sqlite3_value_frombind(X) interface returns non-zero if the |
6085 | ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()] |
6086 | ** interfaces. ^If X comes from an SQL literal value, or a table column, |
6087 | ** and expression, then sqlite3_value_frombind(X) returns zero. |
6088 | ** |
6089 | ** Please pay particular attention to the fact that the pointer returned |
6090 | ** from [sqlite3_value_blob()], [sqlite3_value_text()], or |
6091 | ** [sqlite3_value_text16()] can be invalidated by a subsequent call to |
6092 | ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], |
6093 | ** or [sqlite3_value_text16()]. |
6094 | ** |
6095 | ** These routines must be called from the same thread as |
6096 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
6097 | ** |
6098 | ** As long as the input parameter is correct, these routines can only |
6099 | ** fail if an out-of-memory error occurs during a format conversion. |
6100 | ** Only the following subset of interfaces are subject to out-of-memory |
6101 | ** errors: |
6102 | ** |
6103 | ** <ul> |
6104 | ** <li> sqlite3_value_blob() |
6105 | ** <li> sqlite3_value_text() |
6106 | ** <li> sqlite3_value_text16() |
6107 | ** <li> sqlite3_value_text16le() |
6108 | ** <li> sqlite3_value_text16be() |
6109 | ** <li> sqlite3_value_bytes() |
6110 | ** <li> sqlite3_value_bytes16() |
6111 | ** </ul> |
6112 | ** |
6113 | ** If an out-of-memory error occurs, then the return value from these |
6114 | ** routines is the same as if the column had contained an SQL NULL value. |
6115 | ** Valid SQL NULL returns can be distinguished from out-of-memory errors |
6116 | ** by invoking the [sqlite3_errcode()] immediately after the suspect |
6117 | ** return value is obtained and before any |
6118 | ** other SQLite interface is called on the same [database connection]. |
6119 | */ |
6120 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
6121 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
6122 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
6123 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
6124 | SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*); |
6125 | SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); |
6126 | SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); |
6127 | SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); |
6128 | SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); |
6129 | SQLITE_API int sqlite3_value_bytes(sqlite3_value*); |
6130 | SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); |
6131 | SQLITE_API int sqlite3_value_type(sqlite3_value*); |
6132 | SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); |
6133 | SQLITE_API int sqlite3_value_nochange(sqlite3_value*); |
6134 | SQLITE_API int sqlite3_value_frombind(sqlite3_value*); |
6135 | |
6136 | /* |
6137 | ** CAPI3REF: Finding The Subtype Of SQL Values |
6138 | ** METHOD: sqlite3_value |
6139 | ** |
6140 | ** The sqlite3_value_subtype(V) function returns the subtype for |
6141 | ** an [application-defined SQL function] argument V. The subtype |
6142 | ** information can be used to pass a limited amount of context from |
6143 | ** one SQL function to another. Use the [sqlite3_result_subtype()] |
6144 | ** routine to set the subtype for the return value of an SQL function. |
6145 | */ |
6146 | SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*); |
6147 | |
6148 | /* |
6149 | ** CAPI3REF: Copy And Free SQL Values |
6150 | ** METHOD: sqlite3_value |
6151 | ** |
6152 | ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value] |
6153 | ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned |
6154 | ** is a [protected sqlite3_value] object even if the input is not. |
6155 | ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a |
6156 | ** memory allocation fails. |
6157 | ** |
6158 | ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object |
6159 | ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer |
6160 | ** then sqlite3_value_free(V) is a harmless no-op. |
6161 | */ |
6162 | SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*); |
6163 | SQLITE_API void sqlite3_value_free(sqlite3_value*); |
6164 | |
6165 | /* |
6166 | ** CAPI3REF: Obtain Aggregate Function Context |
6167 | ** METHOD: sqlite3_context |
6168 | ** |
6169 | ** Implementations of aggregate SQL functions use this |
6170 | ** routine to allocate memory for storing their state. |
6171 | ** |
6172 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
6173 | ** for a particular aggregate function, SQLite |
6174 | ** allocates N of memory, zeroes out that memory, and returns a pointer |
6175 | ** to the new memory. ^On second and subsequent calls to |
6176 | ** sqlite3_aggregate_context() for the same aggregate function instance, |
6177 | ** the same buffer is returned. Sqlite3_aggregate_context() is normally |
6178 | ** called once for each invocation of the xStep callback and then one |
6179 | ** last time when the xFinal callback is invoked. ^(When no rows match |
6180 | ** an aggregate query, the xStep() callback of the aggregate function |
6181 | ** implementation is never called and xFinal() is called exactly once. |
6182 | ** In those cases, sqlite3_aggregate_context() might be called for the |
6183 | ** first time from within xFinal().)^ |
6184 | ** |
6185 | ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer |
6186 | ** when first called if N is less than or equal to zero or if a memory |
6187 | ** allocate error occurs. |
6188 | ** |
6189 | ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is |
6190 | ** determined by the N parameter on first successful call. Changing the |
6191 | ** value of N in subsequent call to sqlite3_aggregate_context() within |
6192 | ** the same aggregate function instance will not resize the memory |
6193 | ** allocation.)^ Within the xFinal callback, it is customary to set |
6194 | ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no |
6195 | ** pointless memory allocations occur. |
6196 | ** |
6197 | ** ^SQLite automatically frees the memory allocated by |
6198 | ** sqlite3_aggregate_context() when the aggregate query concludes. |
6199 | ** |
6200 | ** The first parameter must be a copy of the |
6201 | ** [sqlite3_context | SQL function context] that is the first parameter |
6202 | ** to the xStep or xFinal callback routine that implements the aggregate |
6203 | ** function. |
6204 | ** |
6205 | ** This routine must be called from the same thread in which |
6206 | ** the aggregate SQL function is running. |
6207 | */ |
6208 | SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
6209 | |
6210 | /* |
6211 | ** CAPI3REF: User Data For Functions |
6212 | ** METHOD: sqlite3_context |
6213 | ** |
6214 | ** ^The sqlite3_user_data() interface returns a copy of |
6215 | ** the pointer that was the pUserData parameter (the 5th parameter) |
6216 | ** of the [sqlite3_create_function()] |
6217 | ** and [sqlite3_create_function16()] routines that originally |
6218 | ** registered the application defined function. |
6219 | ** |
6220 | ** This routine must be called from the same thread in which |
6221 | ** the application-defined function is running. |
6222 | */ |
6223 | SQLITE_API void *sqlite3_user_data(sqlite3_context*); |
6224 | |
6225 | /* |
6226 | ** CAPI3REF: Database Connection For Functions |
6227 | ** METHOD: sqlite3_context |
6228 | ** |
6229 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
6230 | ** the pointer to the [database connection] (the 1st parameter) |
6231 | ** of the [sqlite3_create_function()] |
6232 | ** and [sqlite3_create_function16()] routines that originally |
6233 | ** registered the application defined function. |
6234 | */ |
6235 | SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
6236 | |
6237 | /* |
6238 | ** CAPI3REF: Function Auxiliary Data |
6239 | ** METHOD: sqlite3_context |
6240 | ** |
6241 | ** These functions may be used by (non-aggregate) SQL functions to |
6242 | ** associate metadata with argument values. If the same value is passed to |
6243 | ** multiple invocations of the same SQL function during query execution, under |
6244 | ** some circumstances the associated metadata may be preserved. An example |
6245 | ** of where this might be useful is in a regular-expression matching |
6246 | ** function. The compiled version of the regular expression can be stored as |
6247 | ** metadata associated with the pattern string. |
6248 | ** Then as long as the pattern string remains the same, |
6249 | ** the compiled regular expression can be reused on multiple |
6250 | ** invocations of the same function. |
6251 | ** |
6252 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata |
6253 | ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument |
6254 | ** value to the application-defined function. ^N is zero for the left-most |
6255 | ** function argument. ^If there is no metadata |
6256 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface |
6257 | ** returns a NULL pointer. |
6258 | ** |
6259 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
6260 | ** argument of the application-defined function. ^Subsequent |
6261 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
6262 | ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or |
6263 | ** NULL if the metadata has been discarded. |
6264 | ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL, |
6265 | ** SQLite will invoke the destructor function X with parameter P exactly |
6266 | ** once, when the metadata is discarded. |
6267 | ** SQLite is free to discard the metadata at any time, including: <ul> |
6268 | ** <li> ^(when the corresponding function parameter changes)^, or |
6269 | ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the |
6270 | ** SQL statement)^, or |
6271 | ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same |
6272 | ** parameter)^, or |
6273 | ** <li> ^(during the original sqlite3_set_auxdata() call when a memory |
6274 | ** allocation error occurs.)^ </ul> |
6275 | ** |
6276 | ** Note the last bullet in particular. The destructor X in |
6277 | ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the |
6278 | ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata() |
6279 | ** should be called near the end of the function implementation and the |
6280 | ** function implementation should not make any use of P after |
6281 | ** sqlite3_set_auxdata() has been called. |
6282 | ** |
6283 | ** ^(In practice, metadata is preserved between function calls for |
6284 | ** function parameters that are compile-time constants, including literal |
6285 | ** values and [parameters] and expressions composed from the same.)^ |
6286 | ** |
6287 | ** The value of the N parameter to these interfaces should be non-negative. |
6288 | ** Future enhancements may make use of negative N values to define new |
6289 | ** kinds of function caching behavior. |
6290 | ** |
6291 | ** These routines must be called from the same thread in which |
6292 | ** the SQL function is running. |
6293 | */ |
6294 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
6295 | SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); |
6296 | |
6297 | |
6298 | /* |
6299 | ** CAPI3REF: Constants Defining Special Destructor Behavior |
6300 | ** |
6301 | ** These are special values for the destructor that is passed in as the |
6302 | ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor |
6303 | ** argument is SQLITE_STATIC, it means that the content pointer is constant |
6304 | ** and will never change. It does not need to be destroyed. ^The |
6305 | ** SQLITE_TRANSIENT value means that the content will likely change in |
6306 | ** the near future and that SQLite should make its own private copy of |
6307 | ** the content before returning. |
6308 | ** |
6309 | ** The typedef is necessary to work around problems in certain |
6310 | ** C++ compilers. |
6311 | */ |
6312 | typedef void (*sqlite3_destructor_type)(void*); |
6313 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
6314 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
6315 | |
6316 | /* |
6317 | ** CAPI3REF: Setting The Result Of An SQL Function |
6318 | ** METHOD: sqlite3_context |
6319 | ** |
6320 | ** These routines are used by the xFunc or xFinal callbacks that |
6321 | ** implement SQL functions and aggregates. See |
6322 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
6323 | ** for additional information. |
6324 | ** |
6325 | ** These functions work very much like the [parameter binding] family of |
6326 | ** functions used to bind values to host parameters in prepared statements. |
6327 | ** Refer to the [SQL parameter] documentation for additional information. |
6328 | ** |
6329 | ** ^The sqlite3_result_blob() interface sets the result from |
6330 | ** an application-defined function to be the BLOB whose content is pointed |
6331 | ** to by the second parameter and which is N bytes long where N is the |
6332 | ** third parameter. |
6333 | ** |
6334 | ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N) |
6335 | ** interfaces set the result of the application-defined function to be |
6336 | ** a BLOB containing all zero bytes and N bytes in size. |
6337 | ** |
6338 | ** ^The sqlite3_result_double() interface sets the result from |
6339 | ** an application-defined function to be a floating point value specified |
6340 | ** by its 2nd argument. |
6341 | ** |
6342 | ** ^The sqlite3_result_error() and sqlite3_result_error16() functions |
6343 | ** cause the implemented SQL function to throw an exception. |
6344 | ** ^SQLite uses the string pointed to by the |
6345 | ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() |
6346 | ** as the text of an error message. ^SQLite interprets the error |
6347 | ** message string from sqlite3_result_error() as UTF-8. ^SQLite |
6348 | ** interprets the string from sqlite3_result_error16() as UTF-16 in native |
6349 | ** byte order. ^If the third parameter to sqlite3_result_error() |
6350 | ** or sqlite3_result_error16() is negative then SQLite takes as the error |
6351 | ** message all text up through the first zero character. |
6352 | ** ^If the third parameter to sqlite3_result_error() or |
6353 | ** sqlite3_result_error16() is non-negative then SQLite takes that many |
6354 | ** bytes (not characters) from the 2nd parameter as the error message. |
6355 | ** ^The sqlite3_result_error() and sqlite3_result_error16() |
6356 | ** routines make a private copy of the error message text before |
6357 | ** they return. Hence, the calling function can deallocate or |
6358 | ** modify the text after they return without harm. |
6359 | ** ^The sqlite3_result_error_code() function changes the error code |
6360 | ** returned by SQLite as a result of an error in a function. ^By default, |
6361 | ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() |
6362 | ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. |
6363 | ** |
6364 | ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an |
6365 | ** error indicating that a string or BLOB is too long to represent. |
6366 | ** |
6367 | ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an |
6368 | ** error indicating that a memory allocation failed. |
6369 | ** |
6370 | ** ^The sqlite3_result_int() interface sets the return value |
6371 | ** of the application-defined function to be the 32-bit signed integer |
6372 | ** value given in the 2nd argument. |
6373 | ** ^The sqlite3_result_int64() interface sets the return value |
6374 | ** of the application-defined function to be the 64-bit signed integer |
6375 | ** value given in the 2nd argument. |
6376 | ** |
6377 | ** ^The sqlite3_result_null() interface sets the return value |
6378 | ** of the application-defined function to be NULL. |
6379 | ** |
6380 | ** ^The sqlite3_result_text(), sqlite3_result_text16(), |
6381 | ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces |
6382 | ** set the return value of the application-defined function to be |
6383 | ** a text string which is represented as UTF-8, UTF-16 native byte order, |
6384 | ** UTF-16 little endian, or UTF-16 big endian, respectively. |
6385 | ** ^The sqlite3_result_text64() interface sets the return value of an |
6386 | ** application-defined function to be a text string in an encoding |
6387 | ** specified by the fifth (and last) parameter, which must be one |
6388 | ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]. |
6389 | ** ^SQLite takes the text result from the application from |
6390 | ** the 2nd parameter of the sqlite3_result_text* interfaces. |
6391 | ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
6392 | ** is negative, then SQLite takes result text from the 2nd parameter |
6393 | ** through the first zero character. |
6394 | ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
6395 | ** is non-negative, then as many bytes (not characters) of the text |
6396 | ** pointed to by the 2nd parameter are taken as the application-defined |
6397 | ** function result. If the 3rd parameter is non-negative, then it |
6398 | ** must be the byte offset into the string where the NUL terminator would |
6399 | ** appear if the string where NUL terminated. If any NUL characters occur |
6400 | ** in the string at a byte offset that is less than the value of the 3rd |
6401 | ** parameter, then the resulting string will contain embedded NULs and the |
6402 | ** result of expressions operating on strings with embedded NULs is undefined. |
6403 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
6404 | ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that |
6405 | ** function as the destructor on the text or BLOB result when it has |
6406 | ** finished using that result. |
6407 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to |
6408 | ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite |
6409 | ** assumes that the text or BLOB result is in constant space and does not |
6410 | ** copy the content of the parameter nor call a destructor on the content |
6411 | ** when it has finished using that result. |
6412 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
6413 | ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT |
6414 | ** then SQLite makes a copy of the result into space obtained |
6415 | ** from [sqlite3_malloc()] before it returns. |
6416 | ** |
6417 | ** ^The sqlite3_result_value() interface sets the result of |
6418 | ** the application-defined function to be a copy of the |
6419 | ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The |
6420 | ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] |
6421 | ** so that the [sqlite3_value] specified in the parameter may change or |
6422 | ** be deallocated after sqlite3_result_value() returns without harm. |
6423 | ** ^A [protected sqlite3_value] object may always be used where an |
6424 | ** [unprotected sqlite3_value] object is required, so either |
6425 | ** kind of [sqlite3_value] object can be used with this interface. |
6426 | ** |
6427 | ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an |
6428 | ** SQL NULL value, just like [sqlite3_result_null(C)], except that it |
6429 | ** also associates the host-language pointer P or type T with that |
6430 | ** NULL value such that the pointer can be retrieved within an |
6431 | ** [application-defined SQL function] using [sqlite3_value_pointer()]. |
6432 | ** ^If the D parameter is not NULL, then it is a pointer to a destructor |
6433 | ** for the P parameter. ^SQLite invokes D with P as its only argument |
6434 | ** when SQLite is finished with P. The T parameter should be a static |
6435 | ** string and preferably a string literal. The sqlite3_result_pointer() |
6436 | ** routine is part of the [pointer passing interface] added for SQLite 3.20.0. |
6437 | ** |
6438 | ** If these routines are called from within the different thread |
6439 | ** than the one containing the application-defined function that received |
6440 | ** the [sqlite3_context] pointer, the results are undefined. |
6441 | */ |
6442 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
6443 | SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, |
6444 | sqlite3_uint64,void(*)(void*)); |
6445 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
6446 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
6447 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
6448 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
6449 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
6450 | SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); |
6451 | SQLITE_API void sqlite3_result_int(sqlite3_context*, int); |
6452 | SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); |
6453 | SQLITE_API void sqlite3_result_null(sqlite3_context*); |
6454 | SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); |
6455 | SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64, |
6456 | void(*)(void*), unsigned char encoding); |
6457 | SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); |
6458 | SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); |
6459 | SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); |
6460 | SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
6461 | SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*)); |
6462 | SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); |
6463 | SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); |
6464 | |
6465 | |
6466 | /* |
6467 | ** CAPI3REF: Setting The Subtype Of An SQL Function |
6468 | ** METHOD: sqlite3_context |
6469 | ** |
6470 | ** The sqlite3_result_subtype(C,T) function causes the subtype of |
6471 | ** the result from the [application-defined SQL function] with |
6472 | ** [sqlite3_context] C to be the value T. Only the lower 8 bits |
6473 | ** of the subtype T are preserved in current versions of SQLite; |
6474 | ** higher order bits are discarded. |
6475 | ** The number of subtype bytes preserved by SQLite might increase |
6476 | ** in future releases of SQLite. |
6477 | */ |
6478 | SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int); |
6479 | |
6480 | /* |
6481 | ** CAPI3REF: Define New Collating Sequences |
6482 | ** METHOD: sqlite3 |
6483 | ** |
6484 | ** ^These functions add, remove, or modify a [collation] associated |
6485 | ** with the [database connection] specified as the first argument. |
6486 | ** |
6487 | ** ^The name of the collation is a UTF-8 string |
6488 | ** for sqlite3_create_collation() and sqlite3_create_collation_v2() |
6489 | ** and a UTF-16 string in native byte order for sqlite3_create_collation16(). |
6490 | ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are |
6491 | ** considered to be the same name. |
6492 | ** |
6493 | ** ^(The third argument (eTextRep) must be one of the constants: |
6494 | ** <ul> |
6495 | ** <li> [SQLITE_UTF8], |
6496 | ** <li> [SQLITE_UTF16LE], |
6497 | ** <li> [SQLITE_UTF16BE], |
6498 | ** <li> [SQLITE_UTF16], or |
6499 | ** <li> [SQLITE_UTF16_ALIGNED]. |
6500 | ** </ul>)^ |
6501 | ** ^The eTextRep argument determines the encoding of strings passed |
6502 | ** to the collating function callback, xCallback. |
6503 | ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep |
6504 | ** force strings to be UTF16 with native byte order. |
6505 | ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin |
6506 | ** on an even byte address. |
6507 | ** |
6508 | ** ^The fourth argument, pArg, is an application data pointer that is passed |
6509 | ** through as the first argument to the collating function callback. |
6510 | ** |
6511 | ** ^The fifth argument, xCallback, is a pointer to the collating function. |
6512 | ** ^Multiple collating functions can be registered using the same name but |
6513 | ** with different eTextRep parameters and SQLite will use whichever |
6514 | ** function requires the least amount of data transformation. |
6515 | ** ^If the xCallback argument is NULL then the collating function is |
6516 | ** deleted. ^When all collating functions having the same name are deleted, |
6517 | ** that collation is no longer usable. |
6518 | ** |
6519 | ** ^The collating function callback is invoked with a copy of the pArg |
6520 | ** application data pointer and with two strings in the encoding specified |
6521 | ** by the eTextRep argument. The collating function must return an |
6522 | ** integer that is negative, zero, or positive |
6523 | ** if the first string is less than, equal to, or greater than the second, |
6524 | ** respectively. A collating function must always return the same answer |
6525 | ** given the same inputs. If two or more collating functions are registered |
6526 | ** to the same collation name (using different eTextRep values) then all |
6527 | ** must give an equivalent answer when invoked with equivalent strings. |
6528 | ** The collating function must obey the following properties for all |
6529 | ** strings A, B, and C: |
6530 | ** |
6531 | ** <ol> |
6532 | ** <li> If A==B then B==A. |
6533 | ** <li> If A==B and B==C then A==C. |
6534 | ** <li> If A<B THEN B>A. |
6535 | ** <li> If A<B and B<C then A<C. |
6536 | ** </ol> |
6537 | ** |
6538 | ** If a collating function fails any of the above constraints and that |
6539 | ** collating function is registered and used, then the behavior of SQLite |
6540 | ** is undefined. |
6541 | ** |
6542 | ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() |
6543 | ** with the addition that the xDestroy callback is invoked on pArg when |
6544 | ** the collating function is deleted. |
6545 | ** ^Collating functions are deleted when they are overridden by later |
6546 | ** calls to the collation creation functions or when the |
6547 | ** [database connection] is closed using [sqlite3_close()]. |
6548 | ** |
6549 | ** ^The xDestroy callback is <u>not</u> called if the |
6550 | ** sqlite3_create_collation_v2() function fails. Applications that invoke |
6551 | ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should |
6552 | ** check the return code and dispose of the application data pointer |
6553 | ** themselves rather than expecting SQLite to deal with it for them. |
6554 | ** This is different from every other SQLite interface. The inconsistency |
6555 | ** is unfortunate but cannot be changed without breaking backwards |
6556 | ** compatibility. |
6557 | ** |
6558 | ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. |
6559 | */ |
6560 | SQLITE_API int sqlite3_create_collation( |
6561 | sqlite3*, |
6562 | const char *zName, |
6563 | int eTextRep, |
6564 | void *pArg, |
6565 | int(*xCompare)(void*,int,const void*,int,const void*) |
6566 | ); |
6567 | SQLITE_API int sqlite3_create_collation_v2( |
6568 | sqlite3*, |
6569 | const char *zName, |
6570 | int eTextRep, |
6571 | void *pArg, |
6572 | int(*xCompare)(void*,int,const void*,int,const void*), |
6573 | void(*xDestroy)(void*) |
6574 | ); |
6575 | SQLITE_API int sqlite3_create_collation16( |
6576 | sqlite3*, |
6577 | const void *zName, |
6578 | int eTextRep, |
6579 | void *pArg, |
6580 | int(*xCompare)(void*,int,const void*,int,const void*) |
6581 | ); |
6582 | |
6583 | /* |
6584 | ** CAPI3REF: Collation Needed Callbacks |
6585 | ** METHOD: sqlite3 |
6586 | ** |
6587 | ** ^To avoid having to register all collation sequences before a database |
6588 | ** can be used, a single callback function may be registered with the |
6589 | ** [database connection] to be invoked whenever an undefined collation |
6590 | ** sequence is required. |
6591 | ** |
6592 | ** ^If the function is registered using the sqlite3_collation_needed() API, |
6593 | ** then it is passed the names of undefined collation sequences as strings |
6594 | ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, |
6595 | ** the names are passed as UTF-16 in machine native byte order. |
6596 | ** ^A call to either function replaces the existing collation-needed callback. |
6597 | ** |
6598 | ** ^(When the callback is invoked, the first argument passed is a copy |
6599 | ** of the second argument to sqlite3_collation_needed() or |
6600 | ** sqlite3_collation_needed16(). The second argument is the database |
6601 | ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], |
6602 | ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation |
6603 | ** sequence function required. The fourth parameter is the name of the |
6604 | ** required collation sequence.)^ |
6605 | ** |
6606 | ** The callback function should register the desired collation using |
6607 | ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or |
6608 | ** [sqlite3_create_collation_v2()]. |
6609 | */ |
6610 | SQLITE_API int sqlite3_collation_needed( |
6611 | sqlite3*, |
6612 | void*, |
6613 | void(*)(void*,sqlite3*,int eTextRep,const char*) |
6614 | ); |
6615 | SQLITE_API int sqlite3_collation_needed16( |
6616 | sqlite3*, |
6617 | void*, |
6618 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
6619 | ); |
6620 | |
6621 | #ifdef SQLITE_HAS_CODEC |
6622 | /* |
6623 | ** Specify the key for an encrypted database. This routine should be |
6624 | ** called right after sqlite3_open(). |
6625 | ** |
6626 | ** The code to implement this API is not available in the public release |
6627 | ** of SQLite. |
6628 | */ |
6629 | SQLITE_API int sqlite3_key( |
6630 | sqlite3 *db, /* Database to be rekeyed */ |
6631 | const void *pKey, int nKey /* The key */ |
6632 | ); |
6633 | SQLITE_API int sqlite3_key_v2( |
6634 | sqlite3 *db, /* Database to be rekeyed */ |
6635 | const char *zDbName, /* Name of the database */ |
6636 | const void *pKey, int nKey /* The key */ |
6637 | ); |
6638 | |
6639 | /* |
6640 | ** Change the key on an open database. If the current database is not |
6641 | ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the |
6642 | ** database is decrypted. |
6643 | ** |
6644 | ** The code to implement this API is not available in the public release |
6645 | ** of SQLite. |
6646 | */ |
6647 | SQLITE_API int sqlite3_rekey( |
6648 | sqlite3 *db, /* Database to be rekeyed */ |
6649 | const void *pKey, int nKey /* The new key */ |
6650 | ); |
6651 | SQLITE_API int sqlite3_rekey_v2( |
6652 | sqlite3 *db, /* Database to be rekeyed */ |
6653 | const char *zDbName, /* Name of the database */ |
6654 | const void *pKey, int nKey /* The new key */ |
6655 | ); |
6656 | |
6657 | /* |
6658 | ** Specify the activation key for a SEE database. Unless |
6659 | ** activated, none of the SEE routines will work. |
6660 | */ |
6661 | SQLITE_API void sqlite3_activate_see( |
6662 | const char *zPassPhrase /* Activation phrase */ |
6663 | ); |
6664 | #endif |
6665 | |
6666 | #ifdef SQLITE_ENABLE_CEROD |
6667 | /* |
6668 | ** Specify the activation key for a CEROD database. Unless |
6669 | ** activated, none of the CEROD routines will work. |
6670 | */ |
6671 | SQLITE_API void sqlite3_activate_cerod( |
6672 | const char *zPassPhrase /* Activation phrase */ |
6673 | ); |
6674 | #endif |
6675 | |
6676 | /* |
6677 | ** CAPI3REF: Suspend Execution For A Short Time |
6678 | ** |
6679 | ** The sqlite3_sleep() function causes the current thread to suspend execution |
6680 | ** for at least a number of milliseconds specified in its parameter. |
6681 | ** |
6682 | ** If the operating system does not support sleep requests with |
6683 | ** millisecond time resolution, then the time will be rounded up to |
6684 | ** the nearest second. The number of milliseconds of sleep actually |
6685 | ** requested from the operating system is returned. |
6686 | ** |
6687 | ** ^SQLite implements this interface by calling the xSleep() |
6688 | ** method of the default [sqlite3_vfs] object. If the xSleep() method |
6689 | ** of the default VFS is not implemented correctly, or not implemented at |
6690 | ** all, then the behavior of sqlite3_sleep() may deviate from the description |
6691 | ** in the previous paragraphs. |
6692 | */ |
6693 | SQLITE_API int sqlite3_sleep(int); |
6694 | |
6695 | /* |
6696 | ** CAPI3REF: Name Of The Folder Holding Temporary Files |
6697 | ** |
6698 | ** ^(If this global variable is made to point to a string which is |
6699 | ** the name of a folder (a.k.a. directory), then all temporary files |
6700 | ** created by SQLite when using a built-in [sqlite3_vfs | VFS] |
6701 | ** will be placed in that directory.)^ ^If this variable |
6702 | ** is a NULL pointer, then SQLite performs a search for an appropriate |
6703 | ** temporary file directory. |
6704 | ** |
6705 | ** Applications are strongly discouraged from using this global variable. |
6706 | ** It is required to set a temporary folder on Windows Runtime (WinRT). |
6707 | ** But for all other platforms, it is highly recommended that applications |
6708 | ** neither read nor write this variable. This global variable is a relic |
6709 | ** that exists for backwards compatibility of legacy applications and should |
6710 | ** be avoided in new projects. |
6711 | ** |
6712 | ** It is not safe to read or modify this variable in more than one |
6713 | ** thread at a time. It is not safe to read or modify this variable |
6714 | ** if a [database connection] is being used at the same time in a separate |
6715 | ** thread. |
6716 | ** It is intended that this variable be set once |
6717 | ** as part of process initialization and before any SQLite interface |
6718 | ** routines have been called and that this variable remain unchanged |
6719 | ** thereafter. |
6720 | ** |
6721 | ** ^The [temp_store_directory pragma] may modify this variable and cause |
6722 | ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, |
6723 | ** the [temp_store_directory pragma] always assumes that any string |
6724 | ** that this variable points to is held in memory obtained from |
6725 | ** [sqlite3_malloc] and the pragma may attempt to free that memory |
6726 | ** using [sqlite3_free]. |
6727 | ** Hence, if this variable is modified directly, either it should be |
6728 | ** made NULL or made to point to memory obtained from [sqlite3_malloc] |
6729 | ** or else the use of the [temp_store_directory pragma] should be avoided. |
6730 | ** Except when requested by the [temp_store_directory pragma], SQLite |
6731 | ** does not free the memory that sqlite3_temp_directory points to. If |
6732 | ** the application wants that memory to be freed, it must do |
6733 | ** so itself, taking care to only do so after all [database connection] |
6734 | ** objects have been destroyed. |
6735 | ** |
6736 | ** <b>Note to Windows Runtime users:</b> The temporary directory must be set |
6737 | ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various |
6738 | ** features that require the use of temporary files may fail. Here is an |
6739 | ** example of how to do this using C++ with the Windows Runtime: |
6740 | ** |
6741 | ** <blockquote><pre> |
6742 | ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current-> |
6743 | ** TemporaryFolder->Path->Data(); |
6744 | ** char zPathBuf[MAX_PATH + 1]; |
6745 | ** memset(zPathBuf, 0, sizeof(zPathBuf)); |
6746 | ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf), |
6747 | ** NULL, NULL); |
6748 | ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf); |
6749 | ** </pre></blockquote> |
6750 | */ |
6751 | SQLITE_API char *sqlite3_temp_directory; |
6752 | |
6753 | /* |
6754 | ** CAPI3REF: Name Of The Folder Holding Database Files |
6755 | ** |
6756 | ** ^(If this global variable is made to point to a string which is |
6757 | ** the name of a folder (a.k.a. directory), then all database files |
6758 | ** specified with a relative pathname and created or accessed by |
6759 | ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed |
6760 | ** to be relative to that directory.)^ ^If this variable is a NULL |
6761 | ** pointer, then SQLite assumes that all database files specified |
6762 | ** with a relative pathname are relative to the current directory |
6763 | ** for the process. Only the windows VFS makes use of this global |
6764 | ** variable; it is ignored by the unix VFS. |
6765 | ** |
6766 | ** Changing the value of this variable while a database connection is |
6767 | ** open can result in a corrupt database. |
6768 | ** |
6769 | ** It is not safe to read or modify this variable in more than one |
6770 | ** thread at a time. It is not safe to read or modify this variable |
6771 | ** if a [database connection] is being used at the same time in a separate |
6772 | ** thread. |
6773 | ** It is intended that this variable be set once |
6774 | ** as part of process initialization and before any SQLite interface |
6775 | ** routines have been called and that this variable remain unchanged |
6776 | ** thereafter. |
6777 | ** |
6778 | ** ^The [data_store_directory pragma] may modify this variable and cause |
6779 | ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, |
6780 | ** the [data_store_directory pragma] always assumes that any string |
6781 | ** that this variable points to is held in memory obtained from |
6782 | ** [sqlite3_malloc] and the pragma may attempt to free that memory |
6783 | ** using [sqlite3_free]. |
6784 | ** Hence, if this variable is modified directly, either it should be |
6785 | ** made NULL or made to point to memory obtained from [sqlite3_malloc] |
6786 | ** or else the use of the [data_store_directory pragma] should be avoided. |
6787 | */ |
6788 | SQLITE_API char *sqlite3_data_directory; |
6789 | |
6790 | /* |
6791 | ** CAPI3REF: Win32 Specific Interface |
6792 | ** |
6793 | ** These interfaces are available only on Windows. The |
6794 | ** [sqlite3_win32_set_directory] interface is used to set the value associated |
6795 | ** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to |
6796 | ** zValue, depending on the value of the type parameter. The zValue parameter |
6797 | ** should be NULL to cause the previous value to be freed via [sqlite3_free]; |
6798 | ** a non-NULL value will be copied into memory obtained from [sqlite3_malloc] |
6799 | ** prior to being used. The [sqlite3_win32_set_directory] interface returns |
6800 | ** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported, |
6801 | ** or [SQLITE_NOMEM] if memory could not be allocated. The value of the |
6802 | ** [sqlite3_data_directory] variable is intended to act as a replacement for |
6803 | ** the current directory on the sub-platforms of Win32 where that concept is |
6804 | ** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and |
6805 | ** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the |
6806 | ** sqlite3_win32_set_directory interface except the string parameter must be |
6807 | ** UTF-8 or UTF-16, respectively. |
6808 | */ |
6809 | SQLITE_API int sqlite3_win32_set_directory( |
6810 | unsigned long type, /* Identifier for directory being set or reset */ |
6811 | void *zValue /* New value for directory being set or reset */ |
6812 | ); |
6813 | SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue); |
6814 | SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue); |
6815 | |
6816 | /* |
6817 | ** CAPI3REF: Win32 Directory Types |
6818 | ** |
6819 | ** These macros are only available on Windows. They define the allowed values |
6820 | ** for the type argument to the [sqlite3_win32_set_directory] interface. |
6821 | */ |
6822 | #define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1 |
6823 | #define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2 |
6824 | |
6825 | /* |
6826 | ** CAPI3REF: Test For Auto-Commit Mode |
6827 | ** KEYWORDS: {autocommit mode} |
6828 | ** METHOD: sqlite3 |
6829 | ** |
6830 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
6831 | ** zero if the given database connection is or is not in autocommit mode, |
6832 | ** respectively. ^Autocommit mode is on by default. |
6833 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
6834 | ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. |
6835 | ** |
6836 | ** If certain kinds of errors occur on a statement within a multi-statement |
6837 | ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], |
6838 | ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the |
6839 | ** transaction might be rolled back automatically. The only way to |
6840 | ** find out whether SQLite automatically rolled back the transaction after |
6841 | ** an error is to use this function. |
6842 | ** |
6843 | ** If another thread changes the autocommit status of the database |
6844 | ** connection while this routine is running, then the return value |
6845 | ** is undefined. |
6846 | */ |
6847 | SQLITE_API int sqlite3_get_autocommit(sqlite3*); |
6848 | |
6849 | /* |
6850 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
6851 | ** METHOD: sqlite3_stmt |
6852 | ** |
6853 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
6854 | ** to which a [prepared statement] belongs. ^The [database connection] |
6855 | ** returned by sqlite3_db_handle is the same [database connection] |
6856 | ** that was the first argument |
6857 | ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to |
6858 | ** create the statement in the first place. |
6859 | */ |
6860 | SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); |
6861 | |
6862 | /* |
6863 | ** CAPI3REF: Return The Filename For A Database Connection |
6864 | ** METHOD: sqlite3 |
6865 | ** |
6866 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
6867 | ** associated with database N of connection D. ^The main database file |
6868 | ** has the name "main". If there is no attached database N on the database |
6869 | ** connection D, or if database N is a temporary or in-memory database, then |
6870 | ** this function will return either a NULL pointer or an empty string. |
6871 | ** |
6872 | ** ^The filename returned by this function is the output of the |
6873 | ** xFullPathname method of the [VFS]. ^In other words, the filename |
6874 | ** will be an absolute pathname, even if the filename used |
6875 | ** to open the database originally was a URI or relative pathname. |
6876 | */ |
6877 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
6878 | |
6879 | /* |
6880 | ** CAPI3REF: Determine if a database is read-only |
6881 | ** METHOD: sqlite3 |
6882 | ** |
6883 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
6884 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
6885 | ** the name of a database on connection D. |
6886 | */ |
6887 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
6888 | |
6889 | /* |
6890 | ** CAPI3REF: Find the next prepared statement |
6891 | ** METHOD: sqlite3 |
6892 | ** |
6893 | ** ^This interface returns a pointer to the next [prepared statement] after |
6894 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
6895 | ** then this interface returns a pointer to the first prepared statement |
6896 | ** associated with the database connection pDb. ^If no prepared statement |
6897 | ** satisfies the conditions of this routine, it returns NULL. |
6898 | ** |
6899 | ** The [database connection] pointer D in a call to |
6900 | ** [sqlite3_next_stmt(D,S)] must refer to an open database |
6901 | ** connection and in particular must not be a NULL pointer. |
6902 | */ |
6903 | SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
6904 | |
6905 | /* |
6906 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
6907 | ** METHOD: sqlite3 |
6908 | ** |
6909 | ** ^The sqlite3_commit_hook() interface registers a callback |
6910 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
6911 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
6912 | ** for the same database connection is overridden. |
6913 | ** ^The sqlite3_rollback_hook() interface registers a callback |
6914 | ** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. |
6915 | ** ^Any callback set by a previous call to sqlite3_rollback_hook() |
6916 | ** for the same database connection is overridden. |
6917 | ** ^The pArg argument is passed through to the callback. |
6918 | ** ^If the callback on a commit hook function returns non-zero, |
6919 | ** then the commit is converted into a rollback. |
6920 | ** |
6921 | ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions |
6922 | ** return the P argument from the previous call of the same function |
6923 | ** on the same [database connection] D, or NULL for |
6924 | ** the first call for each function on D. |
6925 | ** |
6926 | ** The commit and rollback hook callbacks are not reentrant. |
6927 | ** The callback implementation must not do anything that will modify |
6928 | ** the database connection that invoked the callback. Any actions |
6929 | ** to modify the database connection must be deferred until after the |
6930 | ** completion of the [sqlite3_step()] call that triggered the commit |
6931 | ** or rollback hook in the first place. |
6932 | ** Note that running any other SQL statements, including SELECT statements, |
6933 | ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify |
6934 | ** the database connections for the meaning of "modify" in this paragraph. |
6935 | ** |
6936 | ** ^Registering a NULL function disables the callback. |
6937 | ** |
6938 | ** ^When the commit hook callback routine returns zero, the [COMMIT] |
6939 | ** operation is allowed to continue normally. ^If the commit hook |
6940 | ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. |
6941 | ** ^The rollback hook is invoked on a rollback that results from a commit |
6942 | ** hook returning non-zero, just as it would be with any other rollback. |
6943 | ** |
6944 | ** ^For the purposes of this API, a transaction is said to have been |
6945 | ** rolled back if an explicit "ROLLBACK" statement is executed, or |
6946 | ** an error or constraint causes an implicit rollback to occur. |
6947 | ** ^The rollback callback is not invoked if a transaction is |
6948 | ** automatically rolled back because the database connection is closed. |
6949 | ** |
6950 | ** See also the [sqlite3_update_hook()] interface. |
6951 | */ |
6952 | SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
6953 | SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
6954 | |
6955 | /* |
6956 | ** CAPI3REF: Data Change Notification Callbacks |
6957 | ** METHOD: sqlite3 |
6958 | ** |
6959 | ** ^The sqlite3_update_hook() interface registers a callback function |
6960 | ** with the [database connection] identified by the first argument |
6961 | ** to be invoked whenever a row is updated, inserted or deleted in |
6962 | ** a [rowid table]. |
6963 | ** ^Any callback set by a previous call to this function |
6964 | ** for the same database connection is overridden. |
6965 | ** |
6966 | ** ^The second argument is a pointer to the function to invoke when a |
6967 | ** row is updated, inserted or deleted in a rowid table. |
6968 | ** ^The first argument to the callback is a copy of the third argument |
6969 | ** to sqlite3_update_hook(). |
6970 | ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], |
6971 | ** or [SQLITE_UPDATE], depending on the operation that caused the callback |
6972 | ** to be invoked. |
6973 | ** ^The third and fourth arguments to the callback contain pointers to the |
6974 | ** database and table name containing the affected row. |
6975 | ** ^The final callback parameter is the [rowid] of the row. |
6976 | ** ^In the case of an update, this is the [rowid] after the update takes place. |
6977 | ** |
6978 | ** ^(The update hook is not invoked when internal system tables are |
6979 | ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
6980 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
6981 | ** |
6982 | ** ^In the current implementation, the update hook |
6983 | ** is not invoked when conflicting rows are deleted because of an |
6984 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
6985 | ** invoked when rows are deleted using the [truncate optimization]. |
6986 | ** The exceptions defined in this paragraph might change in a future |
6987 | ** release of SQLite. |
6988 | ** |
6989 | ** The update hook implementation must not do anything that will modify |
6990 | ** the database connection that invoked the update hook. Any actions |
6991 | ** to modify the database connection must be deferred until after the |
6992 | ** completion of the [sqlite3_step()] call that triggered the update hook. |
6993 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
6994 | ** database connections for the meaning of "modify" in this paragraph. |
6995 | ** |
6996 | ** ^The sqlite3_update_hook(D,C,P) function |
6997 | ** returns the P argument from the previous call |
6998 | ** on the same [database connection] D, or NULL for |
6999 | ** the first call on D. |
7000 | ** |
7001 | ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()], |
7002 | ** and [sqlite3_preupdate_hook()] interfaces. |
7003 | */ |
7004 | SQLITE_API void *sqlite3_update_hook( |
7005 | sqlite3*, |
7006 | void(*)(void *,int ,char const *,char const *,sqlite3_int64), |
7007 | void* |
7008 | ); |
7009 | |
7010 | /* |
7011 | ** CAPI3REF: Enable Or Disable Shared Pager Cache |
7012 | ** |
7013 | ** ^(This routine enables or disables the sharing of the database cache |
7014 | ** and schema data structures between [database connection | connections] |
7015 | ** to the same database. Sharing is enabled if the argument is true |
7016 | ** and disabled if the argument is false.)^ |
7017 | ** |
7018 | ** ^Cache sharing is enabled and disabled for an entire process. |
7019 | ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). |
7020 | ** In prior versions of SQLite, |
7021 | ** sharing was enabled or disabled for each thread separately. |
7022 | ** |
7023 | ** ^(The cache sharing mode set by this interface effects all subsequent |
7024 | ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. |
7025 | ** Existing database connections continue use the sharing mode |
7026 | ** that was in effect at the time they were opened.)^ |
7027 | ** |
7028 | ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled |
7029 | ** successfully. An [error code] is returned otherwise.)^ |
7030 | ** |
7031 | ** ^Shared cache is disabled by default. But this might change in |
7032 | ** future releases of SQLite. Applications that care about shared |
7033 | ** cache setting should set it explicitly. |
7034 | ** |
7035 | ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 |
7036 | ** and will always return SQLITE_MISUSE. On those systems, |
7037 | ** shared cache mode should be enabled per-database connection via |
7038 | ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE]. |
7039 | ** |
7040 | ** This interface is threadsafe on processors where writing a |
7041 | ** 32-bit integer is atomic. |
7042 | ** |
7043 | ** See Also: [SQLite Shared-Cache Mode] |
7044 | */ |
7045 | SQLITE_API int sqlite3_enable_shared_cache(int); |
7046 | |
7047 | /* |
7048 | ** CAPI3REF: Attempt To Free Heap Memory |
7049 | ** |
7050 | ** ^The sqlite3_release_memory() interface attempts to free N bytes |
7051 | ** of heap memory by deallocating non-essential memory allocations |
7052 | ** held by the database library. Memory used to cache database |
7053 | ** pages to improve performance is an example of non-essential memory. |
7054 | ** ^sqlite3_release_memory() returns the number of bytes actually freed, |
7055 | ** which might be more or less than the amount requested. |
7056 | ** ^The sqlite3_release_memory() routine is a no-op returning zero |
7057 | ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. |
7058 | ** |
7059 | ** See also: [sqlite3_db_release_memory()] |
7060 | */ |
7061 | SQLITE_API int sqlite3_release_memory(int); |
7062 | |
7063 | /* |
7064 | ** CAPI3REF: Free Memory Used By A Database Connection |
7065 | ** METHOD: sqlite3 |
7066 | ** |
7067 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
7068 | ** memory as possible from database connection D. Unlike the |
7069 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
7070 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
7071 | ** omitted. |
7072 | ** |
7073 | ** See also: [sqlite3_release_memory()] |
7074 | */ |
7075 | SQLITE_API int sqlite3_db_release_memory(sqlite3*); |
7076 | |
7077 | /* |
7078 | ** CAPI3REF: Impose A Limit On Heap Size |
7079 | ** |
7080 | ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the |
7081 | ** soft limit on the amount of heap memory that may be allocated by SQLite. |
7082 | ** ^SQLite strives to keep heap memory utilization below the soft heap |
7083 | ** limit by reducing the number of pages held in the page cache |
7084 | ** as heap memory usages approaches the limit. |
7085 | ** ^The soft heap limit is "soft" because even though SQLite strives to stay |
7086 | ** below the limit, it will exceed the limit rather than generate |
7087 | ** an [SQLITE_NOMEM] error. In other words, the soft heap limit |
7088 | ** is advisory only. |
7089 | ** |
7090 | ** ^The return value from sqlite3_soft_heap_limit64() is the size of |
7091 | ** the soft heap limit prior to the call, or negative in the case of an |
7092 | ** error. ^If the argument N is negative |
7093 | ** then no change is made to the soft heap limit. Hence, the current |
7094 | ** size of the soft heap limit can be determined by invoking |
7095 | ** sqlite3_soft_heap_limit64() with a negative argument. |
7096 | ** |
7097 | ** ^If the argument N is zero then the soft heap limit is disabled. |
7098 | ** |
7099 | ** ^(The soft heap limit is not enforced in the current implementation |
7100 | ** if one or more of following conditions are true: |
7101 | ** |
7102 | ** <ul> |
7103 | ** <li> The soft heap limit is set to zero. |
7104 | ** <li> Memory accounting is disabled using a combination of the |
7105 | ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and |
7106 | ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. |
7107 | ** <li> An alternative page cache implementation is specified using |
7108 | ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...). |
7109 | ** <li> The page cache allocates from its own memory pool supplied |
7110 | ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than |
7111 | ** from the heap. |
7112 | ** </ul>)^ |
7113 | ** |
7114 | ** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]), |
7115 | ** the soft heap limit is enforced |
7116 | ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] |
7117 | ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], |
7118 | ** the soft heap limit is enforced on every memory allocation. Without |
7119 | ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced |
7120 | ** when memory is allocated by the page cache. Testing suggests that because |
7121 | ** the page cache is the predominate memory user in SQLite, most |
7122 | ** applications will achieve adequate soft heap limit enforcement without |
7123 | ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. |
7124 | ** |
7125 | ** The circumstances under which SQLite will enforce the soft heap limit may |
7126 | ** changes in future releases of SQLite. |
7127 | */ |
7128 | SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); |
7129 | |
7130 | /* |
7131 | ** CAPI3REF: Deprecated Soft Heap Limit Interface |
7132 | ** DEPRECATED |
7133 | ** |
7134 | ** This is a deprecated version of the [sqlite3_soft_heap_limit64()] |
7135 | ** interface. This routine is provided for historical compatibility |
7136 | ** only. All new applications should use the |
7137 | ** [sqlite3_soft_heap_limit64()] interface rather than this one. |
7138 | */ |
7139 | SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); |
7140 | |
7141 | |
7142 | /* |
7143 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
7144 | ** METHOD: sqlite3 |
7145 | ** |
7146 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
7147 | ** information about column C of table T in database D |
7148 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
7149 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
7150 | ** the final five arguments with appropriate values if the specified |
7151 | ** column exists. ^The sqlite3_table_column_metadata() interface returns |
7152 | ** SQLITE_ERROR and if the specified column does not exist. |
7153 | ** ^If the column-name parameter to sqlite3_table_column_metadata() is a |
7154 | ** NULL pointer, then this routine simply checks for the existence of the |
7155 | ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it |
7156 | ** does not. If the table name parameter T in a call to |
7157 | ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is |
7158 | ** undefined behavior. |
7159 | ** |
7160 | ** ^The column is identified by the second, third and fourth parameters to |
7161 | ** this function. ^(The second parameter is either the name of the database |
7162 | ** (i.e. "main", "temp", or an attached database) containing the specified |
7163 | ** table or NULL.)^ ^If it is NULL, then all attached databases are searched |
7164 | ** for the table using the same algorithm used by the database engine to |
7165 | ** resolve unqualified table references. |
7166 | ** |
7167 | ** ^The third and fourth parameters to this function are the table and column |
7168 | ** name of the desired column, respectively. |
7169 | ** |
7170 | ** ^Metadata is returned by writing to the memory locations passed as the 5th |
7171 | ** and subsequent parameters to this function. ^Any of these arguments may be |
7172 | ** NULL, in which case the corresponding element of metadata is omitted. |
7173 | ** |
7174 | ** ^(<blockquote> |
7175 | ** <table border="1"> |
7176 | ** <tr><th> Parameter <th> Output<br>Type <th> Description |
7177 | ** |
7178 | ** <tr><td> 5th <td> const char* <td> Data type |
7179 | ** <tr><td> 6th <td> const char* <td> Name of default collation sequence |
7180 | ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint |
7181 | ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY |
7182 | ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] |
7183 | ** </table> |
7184 | ** </blockquote>)^ |
7185 | ** |
7186 | ** ^The memory pointed to by the character pointers returned for the |
7187 | ** declaration type and collation sequence is valid until the next |
7188 | ** call to any SQLite API function. |
7189 | ** |
7190 | ** ^If the specified table is actually a view, an [error code] is returned. |
7191 | ** |
7192 | ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table |
7193 | ** is not a [WITHOUT ROWID] table and an |
7194 | ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output |
7195 | ** parameters are set for the explicitly declared column. ^(If there is no |
7196 | ** [INTEGER PRIMARY KEY] column, then the outputs |
7197 | ** for the [rowid] are set as follows: |
7198 | ** |
7199 | ** <pre> |
7200 | ** data type: "INTEGER" |
7201 | ** collation sequence: "BINARY" |
7202 | ** not null: 0 |
7203 | ** primary key: 1 |
7204 | ** auto increment: 0 |
7205 | ** </pre>)^ |
7206 | ** |
7207 | ** ^This function causes all database schemas to be read from disk and |
7208 | ** parsed, if that has not already been done, and returns an error if |
7209 | ** any errors are encountered while loading the schema. |
7210 | */ |
7211 | SQLITE_API int sqlite3_table_column_metadata( |
7212 | sqlite3 *db, /* Connection handle */ |
7213 | const char *zDbName, /* Database name or NULL */ |
7214 | const char *zTableName, /* Table name */ |
7215 | const char *zColumnName, /* Column name */ |
7216 | char const **pzDataType, /* OUTPUT: Declared data type */ |
7217 | char const **pzCollSeq, /* OUTPUT: Collation sequence name */ |
7218 | int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ |
7219 | int *pPrimaryKey, /* OUTPUT: True if column part of PK */ |
7220 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
7221 | ); |
7222 | |
7223 | /* |
7224 | ** CAPI3REF: Load An Extension |
7225 | ** METHOD: sqlite3 |
7226 | ** |
7227 | ** ^This interface loads an SQLite extension library from the named file. |
7228 | ** |
7229 | ** ^The sqlite3_load_extension() interface attempts to load an |
7230 | ** [SQLite extension] library contained in the file zFile. If |
7231 | ** the file cannot be loaded directly, attempts are made to load |
7232 | ** with various operating-system specific extensions added. |
7233 | ** So for example, if "samplelib" cannot be loaded, then names like |
7234 | ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might |
7235 | ** be tried also. |
7236 | ** |
7237 | ** ^The entry point is zProc. |
7238 | ** ^(zProc may be 0, in which case SQLite will try to come up with an |
7239 | ** entry point name on its own. It first tries "sqlite3_extension_init". |
7240 | ** If that does not work, it constructs a name "sqlite3_X_init" where the |
7241 | ** X is consists of the lower-case equivalent of all ASCII alphabetic |
7242 | ** characters in the filename from the last "/" to the first following |
7243 | ** "." and omitting any initial "lib".)^ |
7244 | ** ^The sqlite3_load_extension() interface returns |
7245 | ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. |
7246 | ** ^If an error occurs and pzErrMsg is not 0, then the |
7247 | ** [sqlite3_load_extension()] interface shall attempt to |
7248 | ** fill *pzErrMsg with error message text stored in memory |
7249 | ** obtained from [sqlite3_malloc()]. The calling function |
7250 | ** should free this memory by calling [sqlite3_free()]. |
7251 | ** |
7252 | ** ^Extension loading must be enabled using |
7253 | ** [sqlite3_enable_load_extension()] or |
7254 | ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL) |
7255 | ** prior to calling this API, |
7256 | ** otherwise an error will be returned. |
7257 | ** |
7258 | ** <b>Security warning:</b> It is recommended that the |
7259 | ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this |
7260 | ** interface. The use of the [sqlite3_enable_load_extension()] interface |
7261 | ** should be avoided. This will keep the SQL function [load_extension()] |
7262 | ** disabled and prevent SQL injections from giving attackers |
7263 | ** access to extension loading capabilities. |
7264 | ** |
7265 | ** See also the [load_extension() SQL function]. |
7266 | */ |
7267 | SQLITE_API int sqlite3_load_extension( |
7268 | sqlite3 *db, /* Load the extension into this database connection */ |
7269 | const char *zFile, /* Name of the shared library containing extension */ |
7270 | const char *zProc, /* Entry point. Derived from zFile if 0 */ |
7271 | char **pzErrMsg /* Put error message here if not 0 */ |
7272 | ); |
7273 | |
7274 | /* |
7275 | ** CAPI3REF: Enable Or Disable Extension Loading |
7276 | ** METHOD: sqlite3 |
7277 | ** |
7278 | ** ^So as not to open security holes in older applications that are |
7279 | ** unprepared to deal with [extension loading], and as a means of disabling |
7280 | ** [extension loading] while evaluating user-entered SQL, the following API |
7281 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
7282 | ** |
7283 | ** ^Extension loading is off by default. |
7284 | ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 |
7285 | ** to turn extension loading on and call it with onoff==0 to turn |
7286 | ** it back off again. |
7287 | ** |
7288 | ** ^This interface enables or disables both the C-API |
7289 | ** [sqlite3_load_extension()] and the SQL function [load_extension()]. |
7290 | ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..) |
7291 | ** to enable or disable only the C-API.)^ |
7292 | ** |
7293 | ** <b>Security warning:</b> It is recommended that extension loading |
7294 | ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method |
7295 | ** rather than this interface, so the [load_extension()] SQL function |
7296 | ** remains disabled. This will prevent SQL injections from giving attackers |
7297 | ** access to extension loading capabilities. |
7298 | */ |
7299 | SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); |
7300 | |
7301 | /* |
7302 | ** CAPI3REF: Automatically Load Statically Linked Extensions |
7303 | ** |
7304 | ** ^This interface causes the xEntryPoint() function to be invoked for |
7305 | ** each new [database connection] that is created. The idea here is that |
7306 | ** xEntryPoint() is the entry point for a statically linked [SQLite extension] |
7307 | ** that is to be automatically loaded into all new database connections. |
7308 | ** |
7309 | ** ^(Even though the function prototype shows that xEntryPoint() takes |
7310 | ** no arguments and returns void, SQLite invokes xEntryPoint() with three |
7311 | ** arguments and expects an integer result as if the signature of the |
7312 | ** entry point where as follows: |
7313 | ** |
7314 | ** <blockquote><pre> |
7315 | ** int xEntryPoint( |
7316 | ** sqlite3 *db, |
7317 | ** const char **pzErrMsg, |
7318 | ** const struct sqlite3_api_routines *pThunk |
7319 | ** ); |
7320 | ** </pre></blockquote>)^ |
7321 | ** |
7322 | ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg |
7323 | ** point to an appropriate error message (obtained from [sqlite3_mprintf()]) |
7324 | ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg |
7325 | ** is NULL before calling the xEntryPoint(). ^SQLite will invoke |
7326 | ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any |
7327 | ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], |
7328 | ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. |
7329 | ** |
7330 | ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already |
7331 | ** on the list of automatic extensions is a harmless no-op. ^No entry point |
7332 | ** will be called more than once for each database connection that is opened. |
7333 | ** |
7334 | ** See also: [sqlite3_reset_auto_extension()] |
7335 | ** and [sqlite3_cancel_auto_extension()] |
7336 | */ |
7337 | SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void)); |
7338 | |
7339 | /* |
7340 | ** CAPI3REF: Cancel Automatic Extension Loading |
7341 | ** |
7342 | ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the |
7343 | ** initialization routine X that was registered using a prior call to |
7344 | ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)] |
7345 | ** routine returns 1 if initialization routine X was successfully |
7346 | ** unregistered and it returns 0 if X was not on the list of initialization |
7347 | ** routines. |
7348 | */ |
7349 | SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void)); |
7350 | |
7351 | /* |
7352 | ** CAPI3REF: Reset Automatic Extension Loading |
7353 | ** |
7354 | ** ^This interface disables all automatic extensions previously |
7355 | ** registered using [sqlite3_auto_extension()]. |
7356 | */ |
7357 | SQLITE_API void sqlite3_reset_auto_extension(void); |
7358 | |
7359 | /* |
7360 | ** The interface to the virtual-table mechanism is currently considered |
7361 | ** to be experimental. The interface might change in incompatible ways. |
7362 | ** If this is a problem for you, do not use the interface at this time. |
7363 | ** |
7364 | ** When the virtual-table mechanism stabilizes, we will declare the |
7365 | ** interface fixed, support it indefinitely, and remove this comment. |
7366 | */ |
7367 | |
7368 | /* |
7369 | ** Structures used by the virtual table interface |
7370 | */ |
7371 | typedef struct sqlite3_vtab sqlite3_vtab; |
7372 | typedef struct sqlite3_index_info sqlite3_index_info; |
7373 | typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; |
7374 | typedef struct sqlite3_module sqlite3_module; |
7375 | |
7376 | /* |
7377 | ** CAPI3REF: Virtual Table Object |
7378 | ** KEYWORDS: sqlite3_module {virtual table module} |
7379 | ** |
7380 | ** This structure, sometimes called a "virtual table module", |
7381 | ** defines the implementation of a [virtual tables]. |
7382 | ** This structure consists mostly of methods for the module. |
7383 | ** |
7384 | ** ^A virtual table module is created by filling in a persistent |
7385 | ** instance of this structure and passing a pointer to that instance |
7386 | ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. |
7387 | ** ^The registration remains valid until it is replaced by a different |
7388 | ** module or until the [database connection] closes. The content |
7389 | ** of this structure must not change while it is registered with |
7390 | ** any database connection. |
7391 | */ |
7392 | struct sqlite3_module { |
7393 | int iVersion; |
7394 | int (*xCreate)(sqlite3*, void *pAux, |
7395 | int argc, const char *const*argv, |
7396 | sqlite3_vtab **ppVTab, char**); |
7397 | int (*xConnect)(sqlite3*, void *pAux, |
7398 | int argc, const char *const*argv, |
7399 | sqlite3_vtab **ppVTab, char**); |
7400 | int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); |
7401 | int (*xDisconnect)(sqlite3_vtab *pVTab); |
7402 | int (*xDestroy)(sqlite3_vtab *pVTab); |
7403 | int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); |
7404 | int (*xClose)(sqlite3_vtab_cursor*); |
7405 | int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, |
7406 | int argc, sqlite3_value **argv); |
7407 | int (*xNext)(sqlite3_vtab_cursor*); |
7408 | int (*xEof)(sqlite3_vtab_cursor*); |
7409 | int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); |
7410 | int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); |
7411 | int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); |
7412 | int (*xBegin)(sqlite3_vtab *pVTab); |
7413 | int (*xSync)(sqlite3_vtab *pVTab); |
7414 | int (*xCommit)(sqlite3_vtab *pVTab); |
7415 | int (*xRollback)(sqlite3_vtab *pVTab); |
7416 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
7417 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
7418 | void **ppArg); |
7419 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
7420 | /* The methods above are in version 1 of the sqlite_module object. Those |
7421 | ** below are for version 2 and greater. */ |
7422 | int (*xSavepoint)(sqlite3_vtab *pVTab, int); |
7423 | int (*xRelease)(sqlite3_vtab *pVTab, int); |
7424 | int (*xRollbackTo)(sqlite3_vtab *pVTab, int); |
7425 | /* The methods above are in versions 1 and 2 of the sqlite_module object. |
7426 | ** Those below are for version 3 and greater. */ |
7427 | int (*xShadowName)(const char*); |
7428 | }; |
7429 | |
7430 | /* |
7431 | ** CAPI3REF: Virtual Table Indexing Information |
7432 | ** KEYWORDS: sqlite3_index_info |
7433 | ** |
7434 | ** The sqlite3_index_info structure and its substructures is used as part |
7435 | ** of the [virtual table] interface to |
7436 | ** pass information into and receive the reply from the [xBestIndex] |
7437 | ** method of a [virtual table module]. The fields under **Inputs** are the |
7438 | ** inputs to xBestIndex and are read-only. xBestIndex inserts its |
7439 | ** results into the **Outputs** fields. |
7440 | ** |
7441 | ** ^(The aConstraint[] array records WHERE clause constraints of the form: |
7442 | ** |
7443 | ** <blockquote>column OP expr</blockquote> |
7444 | ** |
7445 | ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is |
7446 | ** stored in aConstraint[].op using one of the |
7447 | ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ |
7448 | ** ^(The index of the column is stored in |
7449 | ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the |
7450 | ** expr on the right-hand side can be evaluated (and thus the constraint |
7451 | ** is usable) and false if it cannot.)^ |
7452 | ** |
7453 | ** ^The optimizer automatically inverts terms of the form "expr OP column" |
7454 | ** and makes other simplifications to the WHERE clause in an attempt to |
7455 | ** get as many WHERE clause terms into the form shown above as possible. |
7456 | ** ^The aConstraint[] array only reports WHERE clause terms that are |
7457 | ** relevant to the particular virtual table being queried. |
7458 | ** |
7459 | ** ^Information about the ORDER BY clause is stored in aOrderBy[]. |
7460 | ** ^Each term of aOrderBy records a column of the ORDER BY clause. |
7461 | ** |
7462 | ** The colUsed field indicates which columns of the virtual table may be |
7463 | ** required by the current scan. Virtual table columns are numbered from |
7464 | ** zero in the order in which they appear within the CREATE TABLE statement |
7465 | ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), |
7466 | ** the corresponding bit is set within the colUsed mask if the column may be |
7467 | ** required by SQLite. If the table has at least 64 columns and any column |
7468 | ** to the right of the first 63 is required, then bit 63 of colUsed is also |
7469 | ** set. In other words, column iCol may be required if the expression |
7470 | ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to |
7471 | ** non-zero. |
7472 | ** |
7473 | ** The [xBestIndex] method must fill aConstraintUsage[] with information |
7474 | ** about what parameters to pass to xFilter. ^If argvIndex>0 then |
7475 | ** the right-hand side of the corresponding aConstraint[] is evaluated |
7476 | ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit |
7477 | ** is true, then the constraint is assumed to be fully handled by the |
7478 | ** virtual table and is not checked again by SQLite.)^ |
7479 | ** |
7480 | ** ^The idxNum and idxPtr values are recorded and passed into the |
7481 | ** [xFilter] method. |
7482 | ** ^[sqlite3_free()] is used to free idxPtr if and only if |
7483 | ** needToFreeIdxPtr is true. |
7484 | ** |
7485 | ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in |
7486 | ** the correct order to satisfy the ORDER BY clause so that no separate |
7487 | ** sorting step is required. |
7488 | ** |
7489 | ** ^The estimatedCost value is an estimate of the cost of a particular |
7490 | ** strategy. A cost of N indicates that the cost of the strategy is similar |
7491 | ** to a linear scan of an SQLite table with N rows. A cost of log(N) |
7492 | ** indicates that the expense of the operation is similar to that of a |
7493 | ** binary search on a unique indexed field of an SQLite table with N rows. |
7494 | ** |
7495 | ** ^The estimatedRows value is an estimate of the number of rows that |
7496 | ** will be returned by the strategy. |
7497 | ** |
7498 | ** The xBestIndex method may optionally populate the idxFlags field with a |
7499 | ** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag - |
7500 | ** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite |
7501 | ** assumes that the strategy may visit at most one row. |
7502 | ** |
7503 | ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then |
7504 | ** SQLite also assumes that if a call to the xUpdate() method is made as |
7505 | ** part of the same statement to delete or update a virtual table row and the |
7506 | ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback |
7507 | ** any database changes. In other words, if the xUpdate() returns |
7508 | ** SQLITE_CONSTRAINT, the database contents must be exactly as they were |
7509 | ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not |
7510 | ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by |
7511 | ** the xUpdate method are automatically rolled back by SQLite. |
7512 | ** |
7513 | ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info |
7514 | ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). |
7515 | ** If a virtual table extension is |
7516 | ** used with an SQLite version earlier than 3.8.2, the results of attempting |
7517 | ** to read or write the estimatedRows field are undefined (but are likely |
7518 | ** to included crashing the application). The estimatedRows field should |
7519 | ** therefore only be used if [sqlite3_libversion_number()] returns a |
7520 | ** value greater than or equal to 3008002. Similarly, the idxFlags field |
7521 | ** was added for [version 3.9.0] ([dateof:3.9.0]). |
7522 | ** It may therefore only be used if |
7523 | ** sqlite3_libversion_number() returns a value greater than or equal to |
7524 | ** 3009000. |
7525 | */ |
7526 | struct sqlite3_index_info { |
7527 | /* Inputs */ |
7528 | int nConstraint; /* Number of entries in aConstraint */ |
7529 | struct sqlite3_index_constraint { |
7530 | int iColumn; /* Column constrained. -1 for ROWID */ |
7531 | unsigned char op; /* Constraint operator */ |
7532 | unsigned char usable; /* True if this constraint is usable */ |
7533 | int iTermOffset; /* Used internally - xBestIndex should ignore */ |
7534 | } *aConstraint; /* Table of WHERE clause constraints */ |
7535 | int nOrderBy; /* Number of terms in the ORDER BY clause */ |
7536 | struct sqlite3_index_orderby { |
7537 | int iColumn; /* Column number */ |
7538 | unsigned char desc; /* True for DESC. False for ASC. */ |
7539 | } *aOrderBy; /* The ORDER BY clause */ |
7540 | /* Outputs */ |
7541 | struct sqlite3_index_constraint_usage { |
7542 | int argvIndex; /* if >0, constraint is part of argv to xFilter */ |
7543 | unsigned char omit; /* Do not code a test for this constraint */ |
7544 | } *aConstraintUsage; |
7545 | int idxNum; /* Number used to identify the index */ |
7546 | char *idxStr; /* String, possibly obtained from sqlite3_malloc */ |
7547 | int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ |
7548 | int orderByConsumed; /* True if output is already ordered */ |
7549 | double estimatedCost; /* Estimated cost of using this index */ |
7550 | /* Fields below are only available in SQLite 3.8.2 and later */ |
7551 | sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ |
7552 | /* Fields below are only available in SQLite 3.9.0 and later */ |
7553 | int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ |
7554 | /* Fields below are only available in SQLite 3.10.0 and later */ |
7555 | sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ |
7556 | }; |
7557 | |
7558 | /* |
7559 | ** CAPI3REF: Virtual Table Scan Flags |
7560 | ** |
7561 | ** Virtual table implementations are allowed to set the |
7562 | ** [sqlite3_index_info].idxFlags field to some combination of |
7563 | ** these bits. |
7564 | */ |
7565 | #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */ |
7566 | |
7567 | /* |
7568 | ** CAPI3REF: Virtual Table Constraint Operator Codes |
7569 | ** |
7570 | ** These macros defined the allowed values for the |
7571 | ** [sqlite3_index_info].aConstraint[].op field. Each value represents |
7572 | ** an operator that is part of a constraint term in the wHERE clause of |
7573 | ** a query that uses a [virtual table]. |
7574 | */ |
7575 | #define SQLITE_INDEX_CONSTRAINT_EQ 2 |
7576 | #define SQLITE_INDEX_CONSTRAINT_GT 4 |
7577 | #define SQLITE_INDEX_CONSTRAINT_LE 8 |
7578 | #define SQLITE_INDEX_CONSTRAINT_LT 16 |
7579 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
7580 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
7581 | #define SQLITE_INDEX_CONSTRAINT_LIKE 65 |
7582 | #define SQLITE_INDEX_CONSTRAINT_GLOB 66 |
7583 | #define SQLITE_INDEX_CONSTRAINT_REGEXP 67 |
7584 | #define SQLITE_INDEX_CONSTRAINT_NE 68 |
7585 | #define SQLITE_INDEX_CONSTRAINT_ISNOT 69 |
7586 | #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 |
7587 | #define SQLITE_INDEX_CONSTRAINT_ISNULL 71 |
7588 | #define SQLITE_INDEX_CONSTRAINT_IS 72 |
7589 | #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 |
7590 | |
7591 | /* |
7592 | ** CAPI3REF: Register A Virtual Table Implementation |
7593 | ** METHOD: sqlite3 |
7594 | ** |
7595 | ** ^These routines are used to register a new [virtual table module] name. |
7596 | ** ^Module names must be registered before |
7597 | ** creating a new [virtual table] using the module and before using a |
7598 | ** preexisting [virtual table] for the module. |
7599 | ** |
7600 | ** ^The module name is registered on the [database connection] specified |
7601 | ** by the first parameter. ^The name of the module is given by the |
7602 | ** second parameter. ^The third parameter is a pointer to |
7603 | ** the implementation of the [virtual table module]. ^The fourth |
7604 | ** parameter is an arbitrary client data pointer that is passed through |
7605 | ** into the [xCreate] and [xConnect] methods of the virtual table module |
7606 | ** when a new virtual table is be being created or reinitialized. |
7607 | ** |
7608 | ** ^The sqlite3_create_module_v2() interface has a fifth parameter which |
7609 | ** is a pointer to a destructor for the pClientData. ^SQLite will |
7610 | ** invoke the destructor function (if it is not NULL) when SQLite |
7611 | ** no longer needs the pClientData pointer. ^The destructor will also |
7612 | ** be invoked if the call to sqlite3_create_module_v2() fails. |
7613 | ** ^The sqlite3_create_module() |
7614 | ** interface is equivalent to sqlite3_create_module_v2() with a NULL |
7615 | ** destructor. |
7616 | */ |
7617 | SQLITE_API int sqlite3_create_module( |
7618 | sqlite3 *db, /* SQLite connection to register module with */ |
7619 | const char *zName, /* Name of the module */ |
7620 | const sqlite3_module *p, /* Methods for the module */ |
7621 | void *pClientData /* Client data for xCreate/xConnect */ |
7622 | ); |
7623 | SQLITE_API int sqlite3_create_module_v2( |
7624 | sqlite3 *db, /* SQLite connection to register module with */ |
7625 | const char *zName, /* Name of the module */ |
7626 | const sqlite3_module *p, /* Methods for the module */ |
7627 | void *pClientData, /* Client data for xCreate/xConnect */ |
7628 | void(*xDestroy)(void*) /* Module destructor function */ |
7629 | ); |
7630 | |
7631 | /* |
7632 | ** CAPI3REF: Virtual Table Instance Object |
7633 | ** KEYWORDS: sqlite3_vtab |
7634 | ** |
7635 | ** Every [virtual table module] implementation uses a subclass |
7636 | ** of this object to describe a particular instance |
7637 | ** of the [virtual table]. Each subclass will |
7638 | ** be tailored to the specific needs of the module implementation. |
7639 | ** The purpose of this superclass is to define certain fields that are |
7640 | ** common to all module implementations. |
7641 | ** |
7642 | ** ^Virtual tables methods can set an error message by assigning a |
7643 | ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should |
7644 | ** take care that any prior string is freed by a call to [sqlite3_free()] |
7645 | ** prior to assigning a new string to zErrMsg. ^After the error message |
7646 | ** is delivered up to the client application, the string will be automatically |
7647 | ** freed by sqlite3_free() and the zErrMsg field will be zeroed. |
7648 | */ |
7649 | struct sqlite3_vtab { |
7650 | const sqlite3_module *pModule; /* The module for this virtual table */ |
7651 | int nRef; /* Number of open cursors */ |
7652 | char *zErrMsg; /* Error message from sqlite3_mprintf() */ |
7653 | /* Virtual table implementations will typically add additional fields */ |
7654 | }; |
7655 | |
7656 | /* |
7657 | ** CAPI3REF: Virtual Table Cursor Object |
7658 | ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} |
7659 | ** |
7660 | ** Every [virtual table module] implementation uses a subclass of the |
7661 | ** following structure to describe cursors that point into the |
7662 | ** [virtual table] and are used |
7663 | ** to loop through the virtual table. Cursors are created using the |
7664 | ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed |
7665 | ** by the [sqlite3_module.xClose | xClose] method. Cursors are used |
7666 | ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods |
7667 | ** of the module. Each module implementation will define |
7668 | ** the content of a cursor structure to suit its own needs. |
7669 | ** |
7670 | ** This superclass exists in order to define fields of the cursor that |
7671 | ** are common to all implementations. |
7672 | */ |
7673 | struct sqlite3_vtab_cursor { |
7674 | sqlite3_vtab *pVtab; /* Virtual table of this cursor */ |
7675 | /* Virtual table implementations will typically add additional fields */ |
7676 | }; |
7677 | |
7678 | /* |
7679 | ** CAPI3REF: Declare The Schema Of A Virtual Table |
7680 | ** |
7681 | ** ^The [xCreate] and [xConnect] methods of a |
7682 | ** [virtual table module] call this interface |
7683 | ** to declare the format (the names and datatypes of the columns) of |
7684 | ** the virtual tables they implement. |
7685 | */ |
7686 | SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
7687 | |
7688 | /* |
7689 | ** CAPI3REF: Overload A Function For A Virtual Table |
7690 | ** METHOD: sqlite3 |
7691 | ** |
7692 | ** ^(Virtual tables can provide alternative implementations of functions |
7693 | ** using the [xFindFunction] method of the [virtual table module]. |
7694 | ** But global versions of those functions |
7695 | ** must exist in order to be overloaded.)^ |
7696 | ** |
7697 | ** ^(This API makes sure a global version of a function with a particular |
7698 | ** name and number of parameters exists. If no such function exists |
7699 | ** before this API is called, a new function is created.)^ ^The implementation |
7700 | ** of the new function always causes an exception to be thrown. So |
7701 | ** the new function is not good for anything by itself. Its only |
7702 | ** purpose is to be a placeholder function that can be overloaded |
7703 | ** by a [virtual table]. |
7704 | */ |
7705 | SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); |
7706 | |
7707 | /* |
7708 | ** The interface to the virtual-table mechanism defined above (back up |
7709 | ** to a comment remarkably similar to this one) is currently considered |
7710 | ** to be experimental. The interface might change in incompatible ways. |
7711 | ** If this is a problem for you, do not use the interface at this time. |
7712 | ** |
7713 | ** When the virtual-table mechanism stabilizes, we will declare the |
7714 | ** interface fixed, support it indefinitely, and remove this comment. |
7715 | */ |
7716 | |
7717 | /* |
7718 | ** CAPI3REF: A Handle To An Open BLOB |
7719 | ** KEYWORDS: {BLOB handle} {BLOB handles} |
7720 | ** |
7721 | ** An instance of this object represents an open BLOB on which |
7722 | ** [sqlite3_blob_open | incremental BLOB I/O] can be performed. |
7723 | ** ^Objects of this type are created by [sqlite3_blob_open()] |
7724 | ** and destroyed by [sqlite3_blob_close()]. |
7725 | ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces |
7726 | ** can be used to read or write small subsections of the BLOB. |
7727 | ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. |
7728 | */ |
7729 | typedef struct sqlite3_blob sqlite3_blob; |
7730 | |
7731 | /* |
7732 | ** CAPI3REF: Open A BLOB For Incremental I/O |
7733 | ** METHOD: sqlite3 |
7734 | ** CONSTRUCTOR: sqlite3_blob |
7735 | ** |
7736 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
7737 | ** in row iRow, column zColumn, table zTable in database zDb; |
7738 | ** in other words, the same BLOB that would be selected by: |
7739 | ** |
7740 | ** <pre> |
7741 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
7742 | ** </pre>)^ |
7743 | ** |
7744 | ** ^(Parameter zDb is not the filename that contains the database, but |
7745 | ** rather the symbolic name of the database. For attached databases, this is |
7746 | ** the name that appears after the AS keyword in the [ATTACH] statement. |
7747 | ** For the main database file, the database name is "main". For TEMP |
7748 | ** tables, the database name is "temp".)^ |
7749 | ** |
7750 | ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
7751 | ** and write access. ^If the flags parameter is zero, the BLOB is opened for |
7752 | ** read-only access. |
7753 | ** |
7754 | ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored |
7755 | ** in *ppBlob. Otherwise an [error code] is returned and, unless the error |
7756 | ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided |
7757 | ** the API is not misused, it is always safe to call [sqlite3_blob_close()] |
7758 | ** on *ppBlob after this function it returns. |
7759 | ** |
7760 | ** This function fails with SQLITE_ERROR if any of the following are true: |
7761 | ** <ul> |
7762 | ** <li> ^(Database zDb does not exist)^, |
7763 | ** <li> ^(Table zTable does not exist within database zDb)^, |
7764 | ** <li> ^(Table zTable is a WITHOUT ROWID table)^, |
7765 | ** <li> ^(Column zColumn does not exist)^, |
7766 | ** <li> ^(Row iRow is not present in the table)^, |
7767 | ** <li> ^(The specified column of row iRow contains a value that is not |
7768 | ** a TEXT or BLOB value)^, |
7769 | ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE |
7770 | ** constraint and the blob is being opened for read/write access)^, |
7771 | ** <li> ^([foreign key constraints | Foreign key constraints] are enabled, |
7772 | ** column zColumn is part of a [child key] definition and the blob is |
7773 | ** being opened for read/write access)^. |
7774 | ** </ul> |
7775 | ** |
7776 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
7777 | ** [database connection] error code and message accessible via |
7778 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
7779 | ** |
7780 | ** A BLOB referenced by sqlite3_blob_open() may be read using the |
7781 | ** [sqlite3_blob_read()] interface and modified by using |
7782 | ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a |
7783 | ** different row of the same table using the [sqlite3_blob_reopen()] |
7784 | ** interface. However, the column, table, or database of a [BLOB handle] |
7785 | ** cannot be changed after the [BLOB handle] is opened. |
7786 | ** |
7787 | ** ^(If the row that a BLOB handle points to is modified by an |
7788 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
7789 | ** then the BLOB handle is marked as "expired". |
7790 | ** This is true if any column of the row is changed, even a column |
7791 | ** other than the one the BLOB handle is open on.)^ |
7792 | ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for |
7793 | ** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. |
7794 | ** ^(Changes written into a BLOB prior to the BLOB expiring are not |
7795 | ** rolled back by the expiration of the BLOB. Such changes will eventually |
7796 | ** commit if the transaction continues to completion.)^ |
7797 | ** |
7798 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
7799 | ** the opened blob. ^The size of a blob may not be changed by this |
7800 | ** interface. Use the [UPDATE] SQL command to change the size of a |
7801 | ** blob. |
7802 | ** |
7803 | ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
7804 | ** and the built-in [zeroblob] SQL function may be used to create a |
7805 | ** zero-filled blob to read or write using the incremental-blob interface. |
7806 | ** |
7807 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
7808 | ** be released by a call to [sqlite3_blob_close()]. |
7809 | ** |
7810 | ** See also: [sqlite3_blob_close()], |
7811 | ** [sqlite3_blob_reopen()], [sqlite3_blob_read()], |
7812 | ** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. |
7813 | */ |
7814 | SQLITE_API int sqlite3_blob_open( |
7815 | sqlite3*, |
7816 | const char *zDb, |
7817 | const char *zTable, |
7818 | const char *zColumn, |
7819 | sqlite3_int64 iRow, |
7820 | int flags, |
7821 | sqlite3_blob **ppBlob |
7822 | ); |
7823 | |
7824 | /* |
7825 | ** CAPI3REF: Move a BLOB Handle to a New Row |
7826 | ** METHOD: sqlite3_blob |
7827 | ** |
7828 | ** ^This function is used to move an existing [BLOB handle] so that it points |
7829 | ** to a different row of the same database table. ^The new row is identified |
7830 | ** by the rowid value passed as the second argument. Only the row can be |
7831 | ** changed. ^The database, table and column on which the blob handle is open |
7832 | ** remain the same. Moving an existing [BLOB handle] to a new row is |
7833 | ** faster than closing the existing handle and opening a new one. |
7834 | ** |
7835 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
7836 | ** it must exist and there must be either a blob or text value stored in |
7837 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
7838 | ** it does not contain a blob or text value, or if another error occurs, an |
7839 | ** SQLite error code is returned and the blob handle is considered aborted. |
7840 | ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or |
7841 | ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return |
7842 | ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle |
7843 | ** always returns zero. |
7844 | ** |
7845 | ** ^This function sets the database handle error code and message. |
7846 | */ |
7847 | SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
7848 | |
7849 | /* |
7850 | ** CAPI3REF: Close A BLOB Handle |
7851 | ** DESTRUCTOR: sqlite3_blob |
7852 | ** |
7853 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
7854 | ** unconditionally. Even if this routine returns an error code, the |
7855 | ** handle is still closed.)^ |
7856 | ** |
7857 | ** ^If the blob handle being closed was opened for read-write access, and if |
7858 | ** the database is in auto-commit mode and there are no other open read-write |
7859 | ** blob handles or active write statements, the current transaction is |
7860 | ** committed. ^If an error occurs while committing the transaction, an error |
7861 | ** code is returned and the transaction rolled back. |
7862 | ** |
7863 | ** Calling this function with an argument that is not a NULL pointer or an |
7864 | ** open blob handle results in undefined behaviour. ^Calling this routine |
7865 | ** with a null pointer (such as would be returned by a failed call to |
7866 | ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function |
7867 | ** is passed a valid open blob handle, the values returned by the |
7868 | ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. |
7869 | */ |
7870 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
7871 | |
7872 | /* |
7873 | ** CAPI3REF: Return The Size Of An Open BLOB |
7874 | ** METHOD: sqlite3_blob |
7875 | ** |
7876 | ** ^Returns the size in bytes of the BLOB accessible via the |
7877 | ** successfully opened [BLOB handle] in its only argument. ^The |
7878 | ** incremental blob I/O routines can only read or overwriting existing |
7879 | ** blob content; they cannot change the size of a blob. |
7880 | ** |
7881 | ** This routine only works on a [BLOB handle] which has been created |
7882 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
7883 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
7884 | ** to this routine results in undefined and probably undesirable behavior. |
7885 | */ |
7886 | SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); |
7887 | |
7888 | /* |
7889 | ** CAPI3REF: Read Data From A BLOB Incrementally |
7890 | ** METHOD: sqlite3_blob |
7891 | ** |
7892 | ** ^(This function is used to read data from an open [BLOB handle] into a |
7893 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
7894 | ** from the open BLOB, starting at offset iOffset.)^ |
7895 | ** |
7896 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
7897 | ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is |
7898 | ** less than zero, [SQLITE_ERROR] is returned and no data is read. |
7899 | ** ^The size of the blob (and hence the maximum value of N+iOffset) |
7900 | ** can be determined using the [sqlite3_blob_bytes()] interface. |
7901 | ** |
7902 | ** ^An attempt to read from an expired [BLOB handle] fails with an |
7903 | ** error code of [SQLITE_ABORT]. |
7904 | ** |
7905 | ** ^(On success, sqlite3_blob_read() returns SQLITE_OK. |
7906 | ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
7907 | ** |
7908 | ** This routine only works on a [BLOB handle] which has been created |
7909 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
7910 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
7911 | ** to this routine results in undefined and probably undesirable behavior. |
7912 | ** |
7913 | ** See also: [sqlite3_blob_write()]. |
7914 | */ |
7915 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
7916 | |
7917 | /* |
7918 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
7919 | ** METHOD: sqlite3_blob |
7920 | ** |
7921 | ** ^(This function is used to write data into an open [BLOB handle] from a |
7922 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
7923 | ** into the open BLOB, starting at offset iOffset.)^ |
7924 | ** |
7925 | ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
7926 | ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
7927 | ** ^Unless SQLITE_MISUSE is returned, this function sets the |
7928 | ** [database connection] error code and message accessible via |
7929 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
7930 | ** |
7931 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
7932 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
7933 | ** this function returns [SQLITE_READONLY]. |
7934 | ** |
7935 | ** This function may only modify the contents of the BLOB; it is |
7936 | ** not possible to increase the size of a BLOB using this API. |
7937 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
7938 | ** [SQLITE_ERROR] is returned and no data is written. The size of the |
7939 | ** BLOB (and hence the maximum value of N+iOffset) can be determined |
7940 | ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less |
7941 | ** than zero [SQLITE_ERROR] is returned and no data is written. |
7942 | ** |
7943 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
7944 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
7945 | ** before the [BLOB handle] expired are not rolled back by the |
7946 | ** expiration of the handle, though of course those changes might |
7947 | ** have been overwritten by the statement that expired the BLOB handle |
7948 | ** or by other independent statements. |
7949 | ** |
7950 | ** This routine only works on a [BLOB handle] which has been created |
7951 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
7952 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
7953 | ** to this routine results in undefined and probably undesirable behavior. |
7954 | ** |
7955 | ** See also: [sqlite3_blob_read()]. |
7956 | */ |
7957 | SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); |
7958 | |
7959 | /* |
7960 | ** CAPI3REF: Virtual File System Objects |
7961 | ** |
7962 | ** A virtual filesystem (VFS) is an [sqlite3_vfs] object |
7963 | ** that SQLite uses to interact |
7964 | ** with the underlying operating system. Most SQLite builds come with a |
7965 | ** single default VFS that is appropriate for the host computer. |
7966 | ** New VFSes can be registered and existing VFSes can be unregistered. |
7967 | ** The following interfaces are provided. |
7968 | ** |
7969 | ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. |
7970 | ** ^Names are case sensitive. |
7971 | ** ^Names are zero-terminated UTF-8 strings. |
7972 | ** ^If there is no match, a NULL pointer is returned. |
7973 | ** ^If zVfsName is NULL then the default VFS is returned. |
7974 | ** |
7975 | ** ^New VFSes are registered with sqlite3_vfs_register(). |
7976 | ** ^Each new VFS becomes the default VFS if the makeDflt flag is set. |
7977 | ** ^The same VFS can be registered multiple times without injury. |
7978 | ** ^To make an existing VFS into the default VFS, register it again |
7979 | ** with the makeDflt flag set. If two different VFSes with the |
7980 | ** same name are registered, the behavior is undefined. If a |
7981 | ** VFS is registered with a name that is NULL or an empty string, |
7982 | ** then the behavior is undefined. |
7983 | ** |
7984 | ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. |
7985 | ** ^(If the default VFS is unregistered, another VFS is chosen as |
7986 | ** the default. The choice for the new VFS is arbitrary.)^ |
7987 | */ |
7988 | SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); |
7989 | SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); |
7990 | SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); |
7991 | |
7992 | /* |
7993 | ** CAPI3REF: Mutexes |
7994 | ** |
7995 | ** The SQLite core uses these routines for thread |
7996 | ** synchronization. Though they are intended for internal |
7997 | ** use by SQLite, code that links against SQLite is |
7998 | ** permitted to use any of these routines. |
7999 | ** |
8000 | ** The SQLite source code contains multiple implementations |
8001 | ** of these mutex routines. An appropriate implementation |
8002 | ** is selected automatically at compile-time. The following |
8003 | ** implementations are available in the SQLite core: |
8004 | ** |
8005 | ** <ul> |
8006 | ** <li> SQLITE_MUTEX_PTHREADS |
8007 | ** <li> SQLITE_MUTEX_W32 |
8008 | ** <li> SQLITE_MUTEX_NOOP |
8009 | ** </ul> |
8010 | ** |
8011 | ** The SQLITE_MUTEX_NOOP implementation is a set of routines |
8012 | ** that does no real locking and is appropriate for use in |
8013 | ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and |
8014 | ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix |
8015 | ** and Windows. |
8016 | ** |
8017 | ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor |
8018 | ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex |
8019 | ** implementation is included with the library. In this case the |
8020 | ** application must supply a custom mutex implementation using the |
8021 | ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function |
8022 | ** before calling sqlite3_initialize() or any other public sqlite3_ |
8023 | ** function that calls sqlite3_initialize(). |
8024 | ** |
8025 | ** ^The sqlite3_mutex_alloc() routine allocates a new |
8026 | ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc() |
8027 | ** routine returns NULL if it is unable to allocate the requested |
8028 | ** mutex. The argument to sqlite3_mutex_alloc() must one of these |
8029 | ** integer constants: |
8030 | ** |
8031 | ** <ul> |
8032 | ** <li> SQLITE_MUTEX_FAST |
8033 | ** <li> SQLITE_MUTEX_RECURSIVE |
8034 | ** <li> SQLITE_MUTEX_STATIC_MASTER |
8035 | ** <li> SQLITE_MUTEX_STATIC_MEM |
8036 | ** <li> SQLITE_MUTEX_STATIC_OPEN |
8037 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
8038 | ** <li> SQLITE_MUTEX_STATIC_LRU |
8039 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
8040 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
8041 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
8042 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
8043 | ** <li> SQLITE_MUTEX_STATIC_VFS1 |
8044 | ** <li> SQLITE_MUTEX_STATIC_VFS2 |
8045 | ** <li> SQLITE_MUTEX_STATIC_VFS3 |
8046 | ** </ul> |
8047 | ** |
8048 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
8049 | ** cause sqlite3_mutex_alloc() to create |
8050 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
8051 | ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. |
8052 | ** The mutex implementation does not need to make a distinction |
8053 | ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does |
8054 | ** not want to. SQLite will only request a recursive mutex in |
8055 | ** cases where it really needs one. If a faster non-recursive mutex |
8056 | ** implementation is available on the host platform, the mutex subsystem |
8057 | ** might return such a mutex in response to SQLITE_MUTEX_FAST. |
8058 | ** |
8059 | ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other |
8060 | ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return |
8061 | ** a pointer to a static preexisting mutex. ^Nine static mutexes are |
8062 | ** used by the current version of SQLite. Future versions of SQLite |
8063 | ** may add additional static mutexes. Static mutexes are for internal |
8064 | ** use by SQLite only. Applications that use SQLite mutexes should |
8065 | ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or |
8066 | ** SQLITE_MUTEX_RECURSIVE. |
8067 | ** |
8068 | ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST |
8069 | ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() |
8070 | ** returns a different mutex on every call. ^For the static |
8071 | ** mutex types, the same mutex is returned on every call that has |
8072 | ** the same type number. |
8073 | ** |
8074 | ** ^The sqlite3_mutex_free() routine deallocates a previously |
8075 | ** allocated dynamic mutex. Attempting to deallocate a static |
8076 | ** mutex results in undefined behavior. |
8077 | ** |
8078 | ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt |
8079 | ** to enter a mutex. ^If another thread is already within the mutex, |
8080 | ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return |
8081 | ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] |
8082 | ** upon successful entry. ^(Mutexes created using |
8083 | ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. |
8084 | ** In such cases, the |
8085 | ** mutex must be exited an equal number of times before another thread |
8086 | ** can enter.)^ If the same thread tries to enter any mutex other |
8087 | ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined. |
8088 | ** |
8089 | ** ^(Some systems (for example, Windows 95) do not support the operation |
8090 | ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() |
8091 | ** will always return SQLITE_BUSY. The SQLite core only ever uses |
8092 | ** sqlite3_mutex_try() as an optimization so this is acceptable |
8093 | ** behavior.)^ |
8094 | ** |
8095 | ** ^The sqlite3_mutex_leave() routine exits a mutex that was |
8096 | ** previously entered by the same thread. The behavior |
8097 | ** is undefined if the mutex is not currently entered by the |
8098 | ** calling thread or is not currently allocated. |
8099 | ** |
8100 | ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or |
8101 | ** sqlite3_mutex_leave() is a NULL pointer, then all three routines |
8102 | ** behave as no-ops. |
8103 | ** |
8104 | ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. |
8105 | */ |
8106 | SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); |
8107 | SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); |
8108 | SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); |
8109 | SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); |
8110 | SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); |
8111 | |
8112 | /* |
8113 | ** CAPI3REF: Mutex Methods Object |
8114 | ** |
8115 | ** An instance of this structure defines the low-level routines |
8116 | ** used to allocate and use mutexes. |
8117 | ** |
8118 | ** Usually, the default mutex implementations provided by SQLite are |
8119 | ** sufficient, however the application has the option of substituting a custom |
8120 | ** implementation for specialized deployments or systems for which SQLite |
8121 | ** does not provide a suitable implementation. In this case, the application |
8122 | ** creates and populates an instance of this structure to pass |
8123 | ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. |
8124 | ** Additionally, an instance of this structure can be used as an |
8125 | ** output variable when querying the system for the current mutex |
8126 | ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. |
8127 | ** |
8128 | ** ^The xMutexInit method defined by this structure is invoked as |
8129 | ** part of system initialization by the sqlite3_initialize() function. |
8130 | ** ^The xMutexInit routine is called by SQLite exactly once for each |
8131 | ** effective call to [sqlite3_initialize()]. |
8132 | ** |
8133 | ** ^The xMutexEnd method defined by this structure is invoked as |
8134 | ** part of system shutdown by the sqlite3_shutdown() function. The |
8135 | ** implementation of this method is expected to release all outstanding |
8136 | ** resources obtained by the mutex methods implementation, especially |
8137 | ** those obtained by the xMutexInit method. ^The xMutexEnd() |
8138 | ** interface is invoked exactly once for each call to [sqlite3_shutdown()]. |
8139 | ** |
8140 | ** ^(The remaining seven methods defined by this structure (xMutexAlloc, |
8141 | ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and |
8142 | ** xMutexNotheld) implement the following interfaces (respectively): |
8143 | ** |
8144 | ** <ul> |
8145 | ** <li> [sqlite3_mutex_alloc()] </li> |
8146 | ** <li> [sqlite3_mutex_free()] </li> |
8147 | ** <li> [sqlite3_mutex_enter()] </li> |
8148 | ** <li> [sqlite3_mutex_try()] </li> |
8149 | ** <li> [sqlite3_mutex_leave()] </li> |
8150 | ** <li> [sqlite3_mutex_held()] </li> |
8151 | ** <li> [sqlite3_mutex_notheld()] </li> |
8152 | ** </ul>)^ |
8153 | ** |
8154 | ** The only difference is that the public sqlite3_XXX functions enumerated |
8155 | ** above silently ignore any invocations that pass a NULL pointer instead |
8156 | ** of a valid mutex handle. The implementations of the methods defined |
8157 | ** by this structure are not required to handle this case, the results |
8158 | ** of passing a NULL pointer instead of a valid mutex handle are undefined |
8159 | ** (i.e. it is acceptable to provide an implementation that segfaults if |
8160 | ** it is passed a NULL pointer). |
8161 | ** |
8162 | ** The xMutexInit() method must be threadsafe. It must be harmless to |
8163 | ** invoke xMutexInit() multiple times within the same process and without |
8164 | ** intervening calls to xMutexEnd(). Second and subsequent calls to |
8165 | ** xMutexInit() must be no-ops. |
8166 | ** |
8167 | ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] |
8168 | ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory |
8169 | ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite |
8170 | ** memory allocation for a fast or recursive mutex. |
8171 | ** |
8172 | ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is |
8173 | ** called, but only if the prior call to xMutexInit returned SQLITE_OK. |
8174 | ** If xMutexInit fails in any way, it is expected to clean up after itself |
8175 | ** prior to returning. |
8176 | */ |
8177 | typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; |
8178 | struct sqlite3_mutex_methods { |
8179 | int (*xMutexInit)(void); |
8180 | int (*xMutexEnd)(void); |
8181 | sqlite3_mutex *(*xMutexAlloc)(int); |
8182 | void (*xMutexFree)(sqlite3_mutex *); |
8183 | void (*xMutexEnter)(sqlite3_mutex *); |
8184 | int (*xMutexTry)(sqlite3_mutex *); |
8185 | void (*xMutexLeave)(sqlite3_mutex *); |
8186 | int (*xMutexHeld)(sqlite3_mutex *); |
8187 | int (*xMutexNotheld)(sqlite3_mutex *); |
8188 | }; |
8189 | |
8190 | /* |
8191 | ** CAPI3REF: Mutex Verification Routines |
8192 | ** |
8193 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines |
8194 | ** are intended for use inside assert() statements. The SQLite core |
8195 | ** never uses these routines except inside an assert() and applications |
8196 | ** are advised to follow the lead of the core. The SQLite core only |
8197 | ** provides implementations for these routines when it is compiled |
8198 | ** with the SQLITE_DEBUG flag. External mutex implementations |
8199 | ** are only required to provide these routines if SQLITE_DEBUG is |
8200 | ** defined and if NDEBUG is not defined. |
8201 | ** |
8202 | ** These routines should return true if the mutex in their argument |
8203 | ** is held or not held, respectively, by the calling thread. |
8204 | ** |
8205 | ** The implementation is not required to provide versions of these |
8206 | ** routines that actually work. If the implementation does not provide working |
8207 | ** versions of these routines, it should at least provide stubs that always |
8208 | ** return true so that one does not get spurious assertion failures. |
8209 | ** |
8210 | ** If the argument to sqlite3_mutex_held() is a NULL pointer then |
8211 | ** the routine should return 1. This seems counter-intuitive since |
8212 | ** clearly the mutex cannot be held if it does not exist. But |
8213 | ** the reason the mutex does not exist is because the build is not |
8214 | ** using mutexes. And we do not want the assert() containing the |
8215 | ** call to sqlite3_mutex_held() to fail, so a non-zero return is |
8216 | ** the appropriate thing to do. The sqlite3_mutex_notheld() |
8217 | ** interface should also return 1 when given a NULL pointer. |
8218 | */ |
8219 | #ifndef NDEBUG |
8220 | SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); |
8221 | SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); |
8222 | #endif |
8223 | |
8224 | /* |
8225 | ** CAPI3REF: Mutex Types |
8226 | ** |
8227 | ** The [sqlite3_mutex_alloc()] interface takes a single argument |
8228 | ** which is one of these integer constants. |
8229 | ** |
8230 | ** The set of static mutexes may change from one SQLite release to the |
8231 | ** next. Applications that override the built-in mutex logic must be |
8232 | ** prepared to accommodate additional static mutexes. |
8233 | */ |
8234 | #define SQLITE_MUTEX_FAST 0 |
8235 | #define SQLITE_MUTEX_RECURSIVE 1 |
8236 | #define SQLITE_MUTEX_STATIC_MASTER 2 |
8237 | #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ |
8238 | #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ |
8239 | #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ |
8240 | #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ |
8241 | #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ |
8242 | #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ |
8243 | #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ |
8244 | #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */ |
8245 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
8246 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
8247 | #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ |
8248 | #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ |
8249 | #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ |
8250 | |
8251 | /* |
8252 | ** CAPI3REF: Retrieve the mutex for a database connection |
8253 | ** METHOD: sqlite3 |
8254 | ** |
8255 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
8256 | ** serializes access to the [database connection] given in the argument |
8257 | ** when the [threading mode] is Serialized. |
8258 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
8259 | ** routine returns a NULL pointer. |
8260 | */ |
8261 | SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); |
8262 | |
8263 | /* |
8264 | ** CAPI3REF: Low-Level Control Of Database Files |
8265 | ** METHOD: sqlite3 |
8266 | ** KEYWORDS: {file control} |
8267 | ** |
8268 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
8269 | ** xFileControl method for the [sqlite3_io_methods] object associated |
8270 | ** with a particular database identified by the second argument. ^The |
8271 | ** name of the database is "main" for the main database or "temp" for the |
8272 | ** TEMP database, or the name that appears after the AS keyword for |
8273 | ** databases that are added using the [ATTACH] SQL command. |
8274 | ** ^A NULL pointer can be used in place of "main" to refer to the |
8275 | ** main database file. |
8276 | ** ^The third and fourth parameters to this routine |
8277 | ** are passed directly through to the second and third parameters of |
8278 | ** the xFileControl method. ^The return value of the xFileControl |
8279 | ** method becomes the return value of this routine. |
8280 | ** |
8281 | ** A few opcodes for [sqlite3_file_control()] are handled directly |
8282 | ** by the SQLite core and never invoke the |
8283 | ** sqlite3_io_methods.xFileControl method. |
8284 | ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes |
8285 | ** a pointer to the underlying [sqlite3_file] object to be written into |
8286 | ** the space pointed to by the 4th parameter. The |
8287 | ** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns |
8288 | ** the [sqlite3_file] object associated with the journal file instead of |
8289 | ** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns |
8290 | ** a pointer to the underlying [sqlite3_vfs] object for the file. |
8291 | ** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter |
8292 | ** from the pager. |
8293 | ** |
8294 | ** ^If the second parameter (zDbName) does not match the name of any |
8295 | ** open database file, then SQLITE_ERROR is returned. ^This error |
8296 | ** code is not remembered and will not be recalled by [sqlite3_errcode()] |
8297 | ** or [sqlite3_errmsg()]. The underlying xFileControl method might |
8298 | ** also return SQLITE_ERROR. There is no way to distinguish between |
8299 | ** an incorrect zDbName and an SQLITE_ERROR return from the underlying |
8300 | ** xFileControl method. |
8301 | ** |
8302 | ** See also: [file control opcodes] |
8303 | */ |
8304 | SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); |
8305 | |
8306 | /* |
8307 | ** CAPI3REF: Testing Interface |
8308 | ** |
8309 | ** ^The sqlite3_test_control() interface is used to read out internal |
8310 | ** state of SQLite and to inject faults into SQLite for testing |
8311 | ** purposes. ^The first parameter is an operation code that determines |
8312 | ** the number, meaning, and operation of all subsequent parameters. |
8313 | ** |
8314 | ** This interface is not for use by applications. It exists solely |
8315 | ** for verifying the correct operation of the SQLite library. Depending |
8316 | ** on how the SQLite library is compiled, this interface might not exist. |
8317 | ** |
8318 | ** The details of the operation codes, their meanings, the parameters |
8319 | ** they take, and what they do are all subject to change without notice. |
8320 | ** Unlike most of the SQLite API, this function is not guaranteed to |
8321 | ** operate consistently from one release to the next. |
8322 | */ |
8323 | SQLITE_API int sqlite3_test_control(int op, ...); |
8324 | |
8325 | /* |
8326 | ** CAPI3REF: Testing Interface Operation Codes |
8327 | ** |
8328 | ** These constants are the valid operation code parameters used |
8329 | ** as the first argument to [sqlite3_test_control()]. |
8330 | ** |
8331 | ** These parameters and their meanings are subject to change |
8332 | ** without notice. These values are for testing purposes only. |
8333 | ** Applications should not use any of these parameters or the |
8334 | ** [sqlite3_test_control()] interface. |
8335 | */ |
8336 | #define SQLITE_TESTCTRL_FIRST 5 |
8337 | #define SQLITE_TESTCTRL_PRNG_SAVE 5 |
8338 | #define SQLITE_TESTCTRL_PRNG_RESTORE 6 |
8339 | #define SQLITE_TESTCTRL_PRNG_RESET 7 |
8340 | #define SQLITE_TESTCTRL_BITVEC_TEST 8 |
8341 | #define SQLITE_TESTCTRL_FAULT_INSTALL 9 |
8342 | #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 |
8343 | #define SQLITE_TESTCTRL_PENDING_BYTE 11 |
8344 | #define SQLITE_TESTCTRL_ASSERT 12 |
8345 | #define SQLITE_TESTCTRL_ALWAYS 13 |
8346 | #define SQLITE_TESTCTRL_RESERVE 14 |
8347 | #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 |
8348 | #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ |
8349 | #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ |
8350 | #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 |
8351 | #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
8352 | #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ |
8353 | #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 |
8354 | #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
8355 | #define SQLITE_TESTCTRL_VDBE_COVERAGE 21 |
8356 | #define SQLITE_TESTCTRL_BYTEORDER 22 |
8357 | #define SQLITE_TESTCTRL_ISINIT 23 |
8358 | #define SQLITE_TESTCTRL_SORTER_MMAP 24 |
8359 | #define SQLITE_TESTCTRL_IMPOSTER 25 |
8360 | #define SQLITE_TESTCTRL_PARSER_COVERAGE 26 |
8361 | #define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */ |
8362 | |
8363 | /* |
8364 | ** CAPI3REF: SQL Keyword Checking |
8365 | ** |
8366 | ** These routines provide access to the set of SQL language keywords |
8367 | ** recognized by SQLite. Applications can uses these routines to determine |
8368 | ** whether or not a specific identifier needs to be escaped (for example, |
8369 | ** by enclosing in double-quotes) so as not to confuse the parser. |
8370 | ** |
8371 | ** The sqlite3_keyword_count() interface returns the number of distinct |
8372 | ** keywords understood by SQLite. |
8373 | ** |
8374 | ** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and |
8375 | ** makes *Z point to that keyword expressed as UTF8 and writes the number |
8376 | ** of bytes in the keyword into *L. The string that *Z points to is not |
8377 | ** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns |
8378 | ** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z |
8379 | ** or L are NULL or invalid pointers then calls to |
8380 | ** sqlite3_keyword_name(N,Z,L) result in undefined behavior. |
8381 | ** |
8382 | ** The sqlite3_keyword_check(Z,L) interface checks to see whether or not |
8383 | ** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero |
8384 | ** if it is and zero if not. |
8385 | ** |
8386 | ** The parser used by SQLite is forgiving. It is often possible to use |
8387 | ** a keyword as an identifier as long as such use does not result in a |
8388 | ** parsing ambiguity. For example, the statement |
8389 | ** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and |
8390 | ** creates a new table named "BEGIN" with three columns named |
8391 | ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid |
8392 | ** using keywords as identifiers. Common techniques used to avoid keyword |
8393 | ** name collisions include: |
8394 | ** <ul> |
8395 | ** <li> Put all identifier names inside double-quotes. This is the official |
8396 | ** SQL way to escape identifier names. |
8397 | ** <li> Put identifier names inside [...]. This is not standard SQL, |
8398 | ** but it is what SQL Server does and so lots of programmers use this |
8399 | ** technique. |
8400 | ** <li> Begin every identifier with the letter "Z" as no SQL keywords start |
8401 | ** with "Z". |
8402 | ** <li> Include a digit somewhere in every identifier name. |
8403 | ** </ul> |
8404 | ** |
8405 | ** Note that the number of keywords understood by SQLite can depend on |
8406 | ** compile-time options. For example, "VACUUM" is not a keyword if |
8407 | ** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also, |
8408 | ** new keywords may be added to future releases of SQLite. |
8409 | */ |
8410 | SQLITE_API int sqlite3_keyword_count(void); |
8411 | SQLITE_API int sqlite3_keyword_name(int,const char**,int*); |
8412 | SQLITE_API int sqlite3_keyword_check(const char*,int); |
8413 | |
8414 | /* |
8415 | ** CAPI3REF: Dynamic String Object |
8416 | ** KEYWORDS: {dynamic string} |
8417 | ** |
8418 | ** An instance of the sqlite3_str object contains a dynamically-sized |
8419 | ** string under construction. |
8420 | ** |
8421 | ** The lifecycle of an sqlite3_str object is as follows: |
8422 | ** <ol> |
8423 | ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()]. |
8424 | ** <li> ^Text is appended to the sqlite3_str object using various |
8425 | ** methods, such as [sqlite3_str_appendf()]. |
8426 | ** <li> ^The sqlite3_str object is destroyed and the string it created |
8427 | ** is returned using the [sqlite3_str_finish()] interface. |
8428 | ** </ol> |
8429 | */ |
8430 | typedef struct sqlite3_str sqlite3_str; |
8431 | |
8432 | /* |
8433 | ** CAPI3REF: Create A New Dynamic String Object |
8434 | ** CONSTRUCTOR: sqlite3_str |
8435 | ** |
8436 | ** ^The [sqlite3_str_new(D)] interface allocates and initializes |
8437 | ** a new [sqlite3_str] object. To avoid memory leaks, the object returned by |
8438 | ** [sqlite3_str_new()] must be freed by a subsequent call to |
8439 | ** [sqlite3_str_finish(X)]. |
8440 | ** |
8441 | ** ^The [sqlite3_str_new(D)] interface always returns a pointer to a |
8442 | ** valid [sqlite3_str] object, though in the event of an out-of-memory |
8443 | ** error the returned object might be a special singleton that will |
8444 | ** silently reject new text, always return SQLITE_NOMEM from |
8445 | ** [sqlite3_str_errcode()], always return 0 for |
8446 | ** [sqlite3_str_length()], and always return NULL from |
8447 | ** [sqlite3_str_finish(X)]. It is always safe to use the value |
8448 | ** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter |
8449 | ** to any of the other [sqlite3_str] methods. |
8450 | ** |
8451 | ** The D parameter to [sqlite3_str_new(D)] may be NULL. If the |
8452 | ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum |
8453 | ** length of the string contained in the [sqlite3_str] object will be |
8454 | ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead |
8455 | ** of [SQLITE_MAX_LENGTH]. |
8456 | */ |
8457 | SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*); |
8458 | |
8459 | /* |
8460 | ** CAPI3REF: Finalize A Dynamic String |
8461 | ** DESTRUCTOR: sqlite3_str |
8462 | ** |
8463 | ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X |
8464 | ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()] |
8465 | ** that contains the constructed string. The calling application should |
8466 | ** pass the returned value to [sqlite3_free()] to avoid a memory leak. |
8467 | ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any |
8468 | ** errors were encountered during construction of the string. ^The |
8469 | ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the |
8470 | ** string in [sqlite3_str] object X is zero bytes long. |
8471 | */ |
8472 | SQLITE_API char *sqlite3_str_finish(sqlite3_str*); |
8473 | |
8474 | /* |
8475 | ** CAPI3REF: Add Content To A Dynamic String |
8476 | ** METHOD: sqlite3_str |
8477 | ** |
8478 | ** These interfaces add content to an sqlite3_str object previously obtained |
8479 | ** from [sqlite3_str_new()]. |
8480 | **< |
---|