~ubuntu-branches/ubuntu/lucid/php5/lucid

« back to all changes in this revision

Viewing changes to ext/sqlite3/libsqlite/sqlite3.h

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-03-16 09:09:50 UTC
  • mfrom: (1.1.18 upstream) (0.3.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100316090950-e36m0pzranoixifd
Tags: 5.3.2-1ubuntu1
* Merge from debian unstable: 
  - debian/control:
    * Dropped firebird2.1-dev, libc-client-dev, libmcrypt-dev as it is in universe.
    * Dropped libmysqlclient15-dev, build against mysql 5.1.
    * Dropped libcurl-dev not in the archive.
    * Suggest php5-suhosin rather than recommends.
    * Dropped php5-imap, php5-interbase, php5-mcrypt since we have versions already in
      universe.
    * Dropped libonig-dev and libqgdbm since its in universe. (will be re-added in lucid+1)
    * Dropped locales-all.
  - modulelist: Drop imap, interbase, and mcrypt.
  - debian/rules:
    * Dropped building of mcrypt, imap, and interbase.
    * Install apport hook for php5.
  - Dropped debian/patches/libedit_is_editline.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
#endif
82
82
 
83
83
/*
84
 
** CAPI3REF: Compile-Time Library Version Numbers {H10010} <S60100>
85
 
**
86
 
** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in
87
 
** the sqlite3.h file specify the version of SQLite with which
88
 
** that header file is associated.
89
 
**
90
 
** The "version" of SQLite is a string of the form "W.X.Y" or "W.X.Y.Z".
91
 
** The W value is major version number and is always 3 in SQLite3.
92
 
** The W value only changes when backwards compatibility is
93
 
** broken and we intend to never break backwards compatibility.
94
 
** The X value is the minor version number and only changes when
95
 
** there are major feature enhancements that are forwards compatible
96
 
** but not backwards compatible.
97
 
** The Y value is the release number and is incremented with
98
 
** each release but resets back to 0 whenever X is incremented.
99
 
** The Z value only appears on branch releases.
100
 
**
101
 
** The SQLITE_VERSION_NUMBER is an integer that is computed as
102
 
** follows:
103
 
**
104
 
** <blockquote><pre>
105
 
** SQLITE_VERSION_NUMBER = W*1000000 + X*1000 + Y
106
 
** </pre></blockquote>
 
84
** CAPI3REF: Compile-Time Library Version Numbers
 
85
**
 
86
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
 
87
** evaluates to a string literal that is the SQLite version in the
 
88
** format "X.Y.Z" where X is the major version number (always 3 for
 
89
** SQLite3) and Y is the minor version number and Z is the release number.)^
 
90
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
 
91
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
 
92
** numbers used in [SQLITE_VERSION].)^
 
93
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
 
94
** be larger than the release from which it is derived.  Either Y will
 
95
** be held constant and Z will be incremented or else Y will be incremented
 
96
** and Z will be reset to zero.
107
97
**
108
98
** Since version 3.6.18, SQLite source code has been stored in the
109
 
** <a href="http://www.fossil-scm.org/">fossil configuration management
110
 
** system</a>.  The SQLITE_SOURCE_ID
111
 
** macro is a string which identifies a particular check-in of SQLite
112
 
** within its configuration management system.  The string contains the
113
 
** date and time of the check-in (UTC) and an SHA1 hash of the entire
114
 
** source tree.
 
99
** <a href="http://www.fossil-scm.org/">Fossil configuration management
 
100
** system</a>.  ^The SQLITE_SOURCE_ID macro evalutes to
 
101
** a string which identifies a particular check-in of SQLite
 
102
** within its configuration management system.  ^The SQLITE_SOURCE_ID
 
103
** string contains the date and time of the check-in (UTC) and an SHA1
 
104
** hash of the entire source tree.
115
105
**
116
106
** See also: [sqlite3_libversion()],
117
107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
118
108
** [sqlite_version()] and [sqlite_source_id()].
119
 
**
120
 
** Requirements: [H10011] [H10014]
121
109
*/
122
 
#define SQLITE_VERSION        "3.6.19"
123
 
#define SQLITE_VERSION_NUMBER 3006019
124
 
#define SQLITE_SOURCE_ID      "2009-10-14 11:33:55 c1d499afc50d54b376945b4efb65c56c787a073d"
 
110
#define SQLITE_VERSION        "3.6.22"
 
111
#define SQLITE_VERSION_NUMBER 3006022
 
112
#define SQLITE_SOURCE_ID      "2010-01-05 15:30:36 28d0d7710761114a44a1a3a425a6883c661f06e7"
125
113
 
126
114
/*
127
 
** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
 
115
** CAPI3REF: Run-Time Library Version Numbers
128
116
** KEYWORDS: sqlite3_version
129
117
**
130
118
** These interfaces provide the same information as the [SQLITE_VERSION],
131
 
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] #defines in the header,
132
 
** but are associated with the library instead of the header file.  Cautious
 
119
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
 
120
** but are associated with the library instead of the header file.  ^(Cautious
133
121
** programmers might include assert() statements in their application to
134
122
** verify that values returned by these interfaces match the macros in
135
123
** the header, and thus insure that the application is
138
126
** <blockquote><pre>
139
127
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
140
128
** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
141
 
** assert( strcmp(sqlite3_libversion,SQLITE_VERSION)==0 );
142
 
** </pre></blockquote>
 
129
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
 
130
** </pre></blockquote>)^
143
131
**
144
 
** The sqlite3_libversion() function returns the same information as is
145
 
** in the sqlite3_version[] string constant.  The function is provided
146
 
** for use in DLLs since DLL users usually do not have direct access to string
147
 
** constants within the DLL.  Similarly, the sqlite3_sourceid() function
148
 
** returns the same information as is in the [SQLITE_SOURCE_ID] #define of
149
 
** the header file.
 
132
** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
 
133
** macro.  ^The sqlite3_libversion() function returns a pointer to the
 
134
** to the sqlite3_version[] string constant.  The sqlite3_libversion()
 
135
** function is provided for use in DLLs since DLL users usually do not have
 
136
** direct access to string constants within the DLL.  ^The
 
137
** sqlite3_libversion_number() function returns an integer equal to
 
138
** [SQLITE_VERSION_NUMBER].  ^The sqlite3_sourceid() function a pointer
 
139
** to a string constant whose value is the same as the [SQLITE_SOURCE_ID]
 
140
** C preprocessor macro.
150
141
**
151
142
** See also: [sqlite_version()] and [sqlite_source_id()].
152
 
**
153
 
** Requirements: [H10021] [H10022] [H10023]
154
143
*/
155
144
SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
156
145
SQLITE_API const char *sqlite3_libversion(void);
158
147
SQLITE_API int sqlite3_libversion_number(void);
159
148
 
160
149
/*
161
 
** CAPI3REF: Test To See If The Library Is Threadsafe {H10100} <S60100>
 
150
** CAPI3REF: Test To See If The Library Is Threadsafe
 
151
**
 
152
** ^The sqlite3_threadsafe() function returns zero if and only if
 
153
** SQLite was compiled mutexing code omitted due to the
 
154
** [SQLITE_THREADSAFE] compile-time option being set to 0.
162
155
**
163
156
** SQLite can be compiled with or without mutexes.  When
164
157
** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
170
163
** Enabling mutexes incurs a measurable performance penalty.
171
164
** So if speed is of utmost importance, it makes sense to disable
172
165
** the mutexes.  But for maximum safety, mutexes should be enabled.
173
 
** The default behavior is for mutexes to be enabled.
 
166
** ^The default behavior is for mutexes to be enabled.
174
167
**
175
168
** This interface can be used by an application to make sure that the
176
169
** version of SQLite that it is linking against was compiled with
178
171
**
179
172
** This interface only reports on the compile-time mutex setting
180
173
** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
181
 
** SQLITE_THREADSAFE=1 then mutexes are enabled by default but
 
174
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
182
175
** can be fully or partially disabled using a call to [sqlite3_config()]
183
176
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
184
 
** or [SQLITE_CONFIG_MUTEX].  The return value of this function shows
185
 
** only the default compile-time setting, not any run-time changes
186
 
** to that setting.
 
177
** or [SQLITE_CONFIG_MUTEX].  ^(The return value of the
 
178
** sqlite3_threadsafe() function shows only the compile-time setting of
 
179
** thread safety, not any run-time changes to that setting made by
 
180
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
 
181
** is unchanged by calls to sqlite3_config().)^
187
182
**
188
183
** See the [threading mode] documentation for additional information.
189
 
**
190
 
** Requirements: [H10101] [H10102]
191
184
*/
192
185
SQLITE_API int sqlite3_threadsafe(void);
193
186
 
194
187
/*
195
 
** CAPI3REF: Database Connection Handle {H12000} <S40200>
 
188
** CAPI3REF: Database Connection Handle
196
189
** KEYWORDS: {database connection} {database connections}
197
190
**
198
191
** Each open SQLite database is represented by a pointer to an instance of
207
200
typedef struct sqlite3 sqlite3;
208
201
 
209
202
/*
210
 
** CAPI3REF: 64-Bit Integer Types {H10200} <S10110>
 
203
** CAPI3REF: 64-Bit Integer Types
211
204
** KEYWORDS: sqlite_int64 sqlite_uint64
212
205
**
213
206
** Because there is no cross-platform way to specify 64-bit integer types
217
210
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
218
211
** compatibility only.
219
212
**
220
 
** Requirements: [H10201] [H10202]
 
213
** ^The sqlite3_int64 and sqlite_int64 types can store integer values
 
214
** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
 
215
** sqlite3_uint64 and sqlite_uint64 types can store integer values 
 
216
** between 0 and +18446744073709551615 inclusive.
221
217
*/
222
218
#ifdef SQLITE_INT64_TYPE
223
219
  typedef SQLITE_INT64_TYPE sqlite_int64;
241
237
#endif
242
238
 
243
239
/*
244
 
** CAPI3REF: Closing A Database Connection {H12010} <S30100><S40200>
245
 
**
246
 
** This routine is the destructor for the [sqlite3] object.
247
 
**
248
 
** Applications should [sqlite3_finalize | finalize] all [prepared statements]
 
240
** CAPI3REF: Closing A Database Connection
 
241
**
 
242
** ^The sqlite3_close() routine is the destructor for the [sqlite3] object.
 
243
** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is
 
244
** successfullly destroyed and all associated resources are deallocated.
 
245
**
 
246
** Applications must [sqlite3_finalize | finalize] all [prepared statements]
249
247
** and [sqlite3_blob_close | close] all [BLOB handles] associated with
250
 
** the [sqlite3] object prior to attempting to close the object.
251
 
** The [sqlite3_next_stmt()] interface can be used to locate all
252
 
** [prepared statements] associated with a [database connection] if desired.
253
 
** Typical code might look like this:
254
 
**
255
 
** <blockquote><pre>
256
 
** sqlite3_stmt *pStmt;
257
 
** while( (pStmt = sqlite3_next_stmt(db, 0))!=0 ){
258
 
** &nbsp;   sqlite3_finalize(pStmt);
259
 
** }
260
 
** </pre></blockquote>
261
 
**
262
 
** If [sqlite3_close()] is invoked while a transaction is open,
 
248
** the [sqlite3] object prior to attempting to close the object.  ^If
 
249
** sqlite3_close() is called on a [database connection] that still has
 
250
** outstanding [prepared statements] or [BLOB handles], then it returns
 
251
** SQLITE_BUSY.
 
252
**
 
253
** ^If [sqlite3_close()] is invoked while a transaction is open,
263
254
** the transaction is automatically rolled back.
264
255
**
265
256
** The C parameter to [sqlite3_close(C)] must be either a NULL
266
257
** pointer or an [sqlite3] object pointer obtained
267
258
** from [sqlite3_open()], [sqlite3_open16()], or
268
259
** [sqlite3_open_v2()], and not previously closed.
269
 
**
270
 
** Requirements:
271
 
** [H12011] [H12012] [H12013] [H12014] [H12015] [H12019]
 
260
** ^Calling sqlite3_close() with a NULL pointer argument is a 
 
261
** harmless no-op.
272
262
*/
273
263
SQLITE_API int sqlite3_close(sqlite3 *);
274
264
 
280
270
typedef int (*sqlite3_callback)(void*,int,char**, char**);
281
271
 
282
272
/*
283
 
** CAPI3REF: One-Step Query Execution Interface {H12100} <S10000>
284
 
**
285
 
** The sqlite3_exec() interface is a convenient way of running one or more
286
 
** SQL statements without having to write a lot of C code.  The UTF-8 encoded
287
 
** SQL statements are passed in as the second parameter to sqlite3_exec().
288
 
** The statements are evaluated one by one until either an error or
289
 
** an interrupt is encountered, or until they are all done.  The 3rd parameter
290
 
** is an optional callback that is invoked once for each row of any query
291
 
** results produced by the SQL statements.  The 5th parameter tells where
292
 
** to write any error messages.
293
 
**
294
 
** The error message passed back through the 5th parameter is held
295
 
** in memory obtained from [sqlite3_malloc()].  To avoid a memory leak,
296
 
** the calling application should call [sqlite3_free()] on any error
297
 
** message returned through the 5th parameter when it has finished using
298
 
** the error message.
299
 
**
300
 
** If the SQL statement in the 2nd parameter is NULL or an empty string
301
 
** or a string containing only whitespace and comments, then no SQL
302
 
** statements are evaluated and the database is not changed.
303
 
**
304
 
** The sqlite3_exec() interface is implemented in terms of
305
 
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
306
 
** The sqlite3_exec() routine does nothing to the database that cannot be done
307
 
** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
308
 
**
309
 
** The first parameter to [sqlite3_exec()] must be an valid and open
310
 
** [database connection].
311
 
**
312
 
** The database connection must not be closed while
313
 
** [sqlite3_exec()] is running.
314
 
**
315
 
** The calling function should use [sqlite3_free()] to free
316
 
** the memory that *errmsg is left pointing at once the error
317
 
** message is no longer needed.
318
 
**
319
 
** The SQL statement text in the 2nd parameter to [sqlite3_exec()]
320
 
** must remain unchanged while [sqlite3_exec()] is running.
321
 
**
322
 
** Requirements:
323
 
** [H12101] [H12102] [H12104] [H12105] [H12107] [H12110] [H12113] [H12116]
324
 
** [H12119] [H12122] [H12125] [H12131] [H12134] [H12137] [H12138]
 
273
** CAPI3REF: One-Step Query Execution Interface
 
274
**
 
275
** The sqlite3_exec() interface is a convenience wrapper around
 
276
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
 
277
** that allows an application to run multiple statements of SQL
 
278
** without having to use a lot of C code. 
 
279
**
 
280
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
 
281
** semicolon-separate SQL statements passed into its 2nd argument,
 
282
** in the context of the [database connection] passed in as its 1st
 
283
** argument.  ^If the callback function of the 3rd argument to
 
284
** sqlite3_exec() is not NULL, then it is invoked for each result row
 
285
** coming out of the evaluated SQL statements.  ^The 4th argument to
 
286
** to sqlite3_exec() is relayed through to the 1st argument of each
 
287
** callback invocation.  ^If the callback pointer to sqlite3_exec()
 
288
** is NULL, then no callback is ever invoked and result rows are
 
289
** ignored.
 
290
**
 
291
** ^If an error occurs while evaluating the SQL statements passed into
 
292
** sqlite3_exec(), then execution of the current statement stops and
 
293
** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
 
294
** is not NULL then any error message is written into memory obtained
 
295
** from [sqlite3_malloc()] and passed back through the 5th parameter.
 
296
** To avoid memory leaks, the application should invoke [sqlite3_free()]
 
297
** on error message strings returned through the 5th parameter of
 
298
** of sqlite3_exec() after the error message string is no longer needed.
 
299
** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
 
300
** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
 
301
** NULL before returning.
 
302
**
 
303
** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
 
304
** routine returns SQLITE_ABORT without invoking the callback again and
 
305
** without running any subsequent SQL statements.
 
306
**
 
307
** ^The 2nd argument to the sqlite3_exec() callback function is the
 
308
** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
 
309
** callback is an array of pointers to strings obtained as if from
 
310
** [sqlite3_column_text()], one for each column.  ^If an element of a
 
311
** result row is NULL then the corresponding string pointer for the
 
312
** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
 
313
** sqlite3_exec() callback is an array of pointers to strings where each
 
314
** entry represents the name of corresponding result column as obtained
 
315
** from [sqlite3_column_name()].
 
316
**
 
317
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
 
318
** to an empty string, or a pointer that contains only whitespace and/or 
 
319
** SQL comments, then no SQL statements are evaluated and the database
 
320
** is not changed.
 
321
**
 
322
** Restrictions:
 
323
**
 
324
** <ul>
 
325
** <li> The application must insure that the 1st parameter to sqlite3_exec()
 
326
**      is a valid and open [database connection].
 
327
** <li> The application must not close [database connection] specified by
 
328
**      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
 
329
** <li> The application must not modify the SQL statement text passed into
 
330
**      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
 
331
** </ul>
325
332
*/
326
333
SQLITE_API int sqlite3_exec(
327
334
  sqlite3*,                                  /* An open database */
332
339
);
333
340
 
334
341
/*
335
 
** CAPI3REF: Result Codes {H10210} <S10700>
 
342
** CAPI3REF: Result Codes
336
343
** KEYWORDS: SQLITE_OK {error code} {error codes}
337
344
** KEYWORDS: {result code} {result codes}
338
345
**
376
383
/* end-of-error-codes */
377
384
 
378
385
/*
379
 
** CAPI3REF: Extended Result Codes {H10220} <S10700>
 
386
** CAPI3REF: Extended Result Codes
380
387
** KEYWORDS: {extended error code} {extended error codes}
381
388
** KEYWORDS: {extended result code} {extended result codes}
382
389
**
418
425
#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED | (1<<8) )
419
426
 
420
427
/*
421
 
** CAPI3REF: Flags For File Open Operations {H10230} <H11120> <H12700>
 
428
** CAPI3REF: Flags For File Open Operations
422
429
**
423
430
** These bit values are intended for use in the
424
431
** 3rd parameter to the [sqlite3_open_v2()] interface and
443
450
#define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
444
451
 
445
452
/*
446
 
** CAPI3REF: Device Characteristics {H10240} <H11120>
 
453
** CAPI3REF: Device Characteristics
447
454
**
448
455
** The xDeviceCapabilities method of the [sqlite3_io_methods]
449
456
** object returns an integer which is a vector of the these
475
482
#define SQLITE_IOCAP_SEQUENTIAL      0x00000400
476
483
 
477
484
/*
478
 
** CAPI3REF: File Locking Levels {H10250} <H11120> <H11310>
 
485
** CAPI3REF: File Locking Levels
479
486
**
480
487
** SQLite uses one of these integer values as the second
481
488
** argument to calls it makes to the xLock() and xUnlock() methods
488
495
#define SQLITE_LOCK_EXCLUSIVE     4
489
496
 
490
497
/*
491
 
** CAPI3REF: Synchronization Type Flags {H10260} <H11120>
 
498
** CAPI3REF: Synchronization Type Flags
492
499
**
493
500
** When SQLite invokes the xSync() method of an
494
501
** [sqlite3_io_methods] object it uses a combination of
506
513
#define SQLITE_SYNC_DATAONLY      0x00010
507
514
 
508
515
/*
509
 
** CAPI3REF: OS Interface Open File Handle {H11110} <S20110>
 
516
** CAPI3REF: OS Interface Open File Handle
510
517
**
511
518
** An [sqlite3_file] object represents an open file in the 
512
519
** [sqlite3_vfs | OS interface layer].  Individual OS interface
522
529
};
523
530
 
524
531
/*
525
 
** CAPI3REF: OS Interface File Virtual Methods Object {H11120} <S20110>
 
532
** CAPI3REF: OS Interface File Virtual Methods Object
526
533
**
527
534
** Every file opened by the [sqlite3_vfs] xOpen method populates an
528
535
** [sqlite3_file] object (or, more commonly, a subclass of the
627
634
};
628
635
 
629
636
/*
630
 
** CAPI3REF: Standard File Control Opcodes {H11310} <S30800>
 
637
** CAPI3REF: Standard File Control Opcodes
631
638
**
632
639
** These integer constants are opcodes for the xFileControl method
633
640
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
647
654
#define SQLITE_LAST_ERRNO             4
648
655
 
649
656
/*
650
 
** CAPI3REF: Mutex Handle {H17110} <S20130>
 
657
** CAPI3REF: Mutex Handle
651
658
**
652
659
** The mutex module within SQLite defines [sqlite3_mutex] to be an
653
660
** abstract type for a mutex object.  The SQLite core never looks
659
666
typedef struct sqlite3_mutex sqlite3_mutex;
660
667
 
661
668
/*
662
 
** CAPI3REF: OS Interface Object {H11140} <S20100>
 
669
** CAPI3REF: OS Interface Object
663
670
**
664
671
** An instance of the sqlite3_vfs object defines the interface between
665
672
** the SQLite core and the underlying operating system.  The "vfs"
813
820
};
814
821
 
815
822
/*
816
 
** CAPI3REF: Flags for the xAccess VFS method {H11190} <H11140>
 
823
** CAPI3REF: Flags for the xAccess VFS method
817
824
**
818
825
** These integer constants can be used as the third parameter to
819
 
** the xAccess method of an [sqlite3_vfs] object. {END}  They determine
 
826
** the xAccess method of an [sqlite3_vfs] object.  They determine
820
827
** what kind of permissions the xAccess method is looking for.
821
828
** With SQLITE_ACCESS_EXISTS, the xAccess method
822
829
** simply checks whether the file exists.
830
837
#define SQLITE_ACCESS_READ      2
831
838
 
832
839
/*
833
 
** CAPI3REF: Initialize The SQLite Library {H10130} <S20000><S30100>
 
840
** CAPI3REF: Initialize The SQLite Library
834
841
**
835
 
** The sqlite3_initialize() routine initializes the
836
 
** SQLite library.  The sqlite3_shutdown() routine
 
842
** ^The sqlite3_initialize() routine initializes the
 
843
** SQLite library.  ^The sqlite3_shutdown() routine
837
844
** deallocates any resources that were allocated by sqlite3_initialize().
 
845
** These routines are designed to aid in process initialization and
 
846
** shutdown on embedded systems.  Workstation applications using
 
847
** SQLite normally do not need to invoke either of these routines.
838
848
**
839
849
** A call to sqlite3_initialize() is an "effective" call if it is
840
850
** the first time sqlite3_initialize() is invoked during the lifetime of
841
851
** the process, or if it is the first time sqlite3_initialize() is invoked
842
 
** following a call to sqlite3_shutdown().  Only an effective call
 
852
** following a call to sqlite3_shutdown().  ^(Only an effective call
843
853
** of sqlite3_initialize() does any initialization.  All other calls
844
 
** are harmless no-ops.
 
854
** are harmless no-ops.)^
845
855
**
846
856
** A call to sqlite3_shutdown() is an "effective" call if it is the first
847
 
** call to sqlite3_shutdown() since the last sqlite3_initialize().  Only
 
857
** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
848
858
** an effective call to sqlite3_shutdown() does any deinitialization.
849
 
** All other calls to sqlite3_shutdown() are harmless no-ops.
850
 
**
851
 
** Among other things, sqlite3_initialize() shall invoke
852
 
** sqlite3_os_init().  Similarly, sqlite3_shutdown()
853
 
** shall invoke sqlite3_os_end().
854
 
**
855
 
** The sqlite3_initialize() routine returns [SQLITE_OK] on success.
856
 
** If for some reason, sqlite3_initialize() is unable to initialize
 
859
** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
 
860
**
 
861
** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
 
862
** is not.  The sqlite3_shutdown() interface must only be called from a
 
863
** single thread.  All open [database connections] must be closed and all
 
864
** other SQLite resources must be deallocated prior to invoking
 
865
** sqlite3_shutdown().
 
866
**
 
867
** Among other things, ^sqlite3_initialize() will invoke
 
868
** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
 
869
** will invoke sqlite3_os_end().
 
870
**
 
871
** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
 
872
** ^If for some reason, sqlite3_initialize() is unable to initialize
857
873
** the library (perhaps it is unable to allocate a needed resource such
858
874
** as a mutex) it returns an [error code] other than [SQLITE_OK].
859
875
**
860
 
** The sqlite3_initialize() routine is called internally by many other
 
876
** ^The sqlite3_initialize() routine is called internally by many other
861
877
** SQLite interfaces so that an application usually does not need to
862
878
** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
863
879
** calls sqlite3_initialize() so the SQLite library will be automatically
864
880
** initialized when [sqlite3_open()] is called if it has not be initialized
865
 
** already.  However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
 
881
** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
866
882
** compile-time option, then the automatic calls to sqlite3_initialize()
867
883
** are omitted and the application must call sqlite3_initialize() directly
868
884
** prior to using any other SQLite interface.  For maximum portability,
901
917
SQLITE_API int sqlite3_os_end(void);
902
918
 
903
919
/*
904
 
** CAPI3REF: Configuring The SQLite Library {H14100} <S20000><S30200>
 
920
** CAPI3REF: Configuring The SQLite Library
905
921
** EXPERIMENTAL
906
922
**
907
923
** The sqlite3_config() interface is used to make global configuration
915
931
** threads while sqlite3_config() is running.  Furthermore, sqlite3_config()
916
932
** may only be invoked prior to library initialization using
917
933
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
918
 
** Note, however, that sqlite3_config() can be called as part of the
 
934
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
 
935
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
 
936
** Note, however, that ^sqlite3_config() can be called as part of the
919
937
** implementation of an application-defined [sqlite3_os_init()].
920
938
**
921
939
** The first argument to sqlite3_config() is an integer
924
942
** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
925
943
** in the first argument.
926
944
**
927
 
** When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
928
 
** If the option is unknown or SQLite is unable to set the option
 
945
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
 
946
** ^If the option is unknown or SQLite is unable to set the option
929
947
** then this routine returns a non-zero [error code].
930
 
**
931
 
** Requirements:
932
 
** [H14103] [H14106] [H14120] [H14123] [H14126] [H14129] [H14132] [H14135]
933
 
** [H14138] [H14141] [H14144] [H14147] [H14150] [H14153] [H14156] [H14159]
934
 
** [H14162] [H14165] [H14168]
935
948
*/
936
949
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
937
950
 
938
951
/*
939
 
** CAPI3REF: Configure database connections  {H14200} <S20000>
 
952
** CAPI3REF: Configure database connections
940
953
** EXPERIMENTAL
941
954
**
942
955
** The sqlite3_db_config() interface is used to make configuration
943
956
** changes to a [database connection].  The interface is similar to
944
957
** [sqlite3_config()] except that the changes apply to a single
945
958
** [database connection] (specified in the first argument).  The
946
 
** sqlite3_db_config() interface can only be used immediately after
 
959
** sqlite3_db_config() interface should only be used immediately after
947
960
** the database connection is created using [sqlite3_open()],
948
961
** [sqlite3_open16()], or [sqlite3_open_v2()].  
949
962
**
954
967
** New verbs are likely to be added in future releases of SQLite.
955
968
** Additional arguments depend on the verb.
956
969
**
957
 
** Requirements:
958
 
** [H14203] [H14206] [H14209] [H14212] [H14215]
 
970
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
 
971
** the call is considered successful.
959
972
*/
960
973
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
961
974
 
962
975
/*
963
 
** CAPI3REF: Memory Allocation Routines {H10155} <S20120>
 
976
** CAPI3REF: Memory Allocation Routines
964
977
** EXPERIMENTAL
965
978
**
966
979
** An instance of this object defines the interface between SQLite
990
1003
** The xRealloc method must work like realloc() from the standard C library
991
1004
** with the exception that if the second argument to xRealloc is zero,
992
1005
** xRealloc must be a no-op - it must not perform any allocation or
993
 
** deallocation.  SQLite guaranteeds that the second argument to
 
1006
** deallocation.  ^SQLite guarantees that the second argument to
994
1007
** xRealloc is always a value returned by a prior call to xRoundup.
995
1008
** And so in cases where xRoundup always returns a positive number,
996
1009
** xRealloc can perform exactly as the standard library realloc() and
1042
1055
};
1043
1056
 
1044
1057
/*
1045
 
** CAPI3REF: Configuration Options {H10160} <S20000>
 
1058
** CAPI3REF: Configuration Options
1046
1059
** EXPERIMENTAL
1047
1060
**
1048
1061
** These constants are the available integer configuration options that
1057
1070
**
1058
1071
** <dl>
1059
1072
** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1060
 
** <dd>There are no arguments to this option.  This option disables
 
1073
** <dd>There are no arguments to this option.  ^This option sets the
 
1074
** [threading mode] to Single-thread.  In other words, it disables
1061
1075
** all mutexing and puts SQLite into a mode where it can only be used
1062
 
** by a single thread.</dd>
 
1076
** by a single thread.   ^If SQLite is compiled with
 
1077
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
 
1078
** it is not possible to change the [threading mode] from its default
 
1079
** value of Single-thread and so [sqlite3_config()] will return 
 
1080
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
 
1081
** configuration option.</dd>
1063
1082
**
1064
1083
** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1065
 
** <dd>There are no arguments to this option.  This option disables
 
1084
** <dd>There are no arguments to this option.  ^This option sets the
 
1085
** [threading mode] to Multi-thread.  In other words, it disables
1066
1086
** mutexing on [database connection] and [prepared statement] objects.
1067
1087
** The application is responsible for serializing access to
1068
1088
** [database connections] and [prepared statements].  But other mutexes
1069
1089
** are enabled so that SQLite will be safe to use in a multi-threaded
1070
1090
** environment as long as no two threads attempt to use the same
1071
 
** [database connection] at the same time.  See the [threading mode]
1072
 
** documentation for additional information.</dd>
 
1091
** [database connection] at the same time.  ^If SQLite is compiled with
 
1092
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
 
1093
** it is not possible to set the Multi-thread [threading mode] and
 
1094
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
 
1095
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1073
1096
**
1074
1097
** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1075
 
** <dd>There are no arguments to this option.  This option enables
 
1098
** <dd>There are no arguments to this option.  ^This option sets the
 
1099
** [threading mode] to Serialized. In other words, this option enables
1076
1100
** all mutexes including the recursive
1077
1101
** mutexes on [database connection] and [prepared statement] objects.
1078
1102
** In this mode (which is the default when SQLite is compiled with
1080
1104
** to [database connections] and [prepared statements] so that the
1081
1105
** application is free to use the same [database connection] or the
1082
1106
** same [prepared statement] in different threads at the same time.
1083
 
** See the [threading mode] documentation for additional information.</dd>
 
1107
** ^If SQLite is compiled with
 
1108
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
 
1109
** it is not possible to set the Serialized [threading mode] and
 
1110
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
 
1111
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1084
1112
**
1085
1113
** <dt>SQLITE_CONFIG_MALLOC</dt>
1086
 
** <dd>This option takes a single argument which is a pointer to an
 
1114
** <dd> ^(This option takes a single argument which is a pointer to an
1087
1115
** instance of the [sqlite3_mem_methods] structure.  The argument specifies
1088
1116
** alternative low-level memory allocation routines to be used in place of
1089
 
** the memory allocation routines built into SQLite.</dd>
 
1117
** the memory allocation routines built into SQLite.)^ ^SQLite makes
 
1118
** its own private copy of the content of the [sqlite3_mem_methods] structure
 
1119
** before the [sqlite3_config()] call returns.</dd>
1090
1120
**
1091
1121
** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1092
 
** <dd>This option takes a single argument which is a pointer to an
 
1122
** <dd> ^(This option takes a single argument which is a pointer to an
1093
1123
** instance of the [sqlite3_mem_methods] structure.  The [sqlite3_mem_methods]
1094
 
** structure is filled with the currently defined memory allocation routines.
 
1124
** structure is filled with the currently defined memory allocation routines.)^
1095
1125
** This option can be used to overload the default memory allocation
1096
1126
** routines with a wrapper that simulations memory allocation failure or
1097
 
** tracks memory usage, for example.</dd>
 
1127
** tracks memory usage, for example. </dd>
1098
1128
**
1099
1129
** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1100
 
** <dd>This option takes single argument of type int, interpreted as a 
 
1130
** <dd> ^This option takes single argument of type int, interpreted as a 
1101
1131
** boolean, which enables or disables the collection of memory allocation 
1102
 
** statistics. When disabled, the following SQLite interfaces become 
1103
 
** non-operational:
 
1132
** statistics. ^(When memory allocation statistics are disabled, the 
 
1133
** following SQLite interfaces become non-operational:
1104
1134
**   <ul>
1105
1135
**   <li> [sqlite3_memory_used()]
1106
1136
**   <li> [sqlite3_memory_highwater()]
1107
1137
**   <li> [sqlite3_soft_heap_limit()]
1108
1138
**   <li> [sqlite3_status()]
1109
 
**   </ul>
 
1139
**   </ul>)^
 
1140
** ^Memory allocation statistics are enabled by default unless SQLite is
 
1141
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
 
1142
** allocation statistics are disabled by default.
1110
1143
** </dd>
1111
1144
**
1112
1145
** <dt>SQLITE_CONFIG_SCRATCH</dt>
1113
 
** <dd>This option specifies a static memory buffer that SQLite can use for
 
1146
** <dd> ^This option specifies a static memory buffer that SQLite can use for
1114
1147
** scratch memory.  There are three arguments:  A pointer an 8-byte
1115
1148
** aligned memory buffer from which the scrach allocations will be
1116
1149
** drawn, the size of each scratch allocation (sz),
1117
1150
** and the maximum number of scratch allocations (N).  The sz
1118
1151
** argument must be a multiple of 16. The sz parameter should be a few bytes
1119
1152
** larger than the actual scratch space required due to internal overhead.
1120
 
** The first argument should pointer to an 8-byte aligned buffer
 
1153
** The first argument must be a pointer to an 8-byte aligned buffer
1121
1154
** of at least sz*N bytes of memory.
1122
 
** SQLite will use no more than one scratch buffer at once per thread, so
1123
 
** N should be set to the expected maximum number of threads.  The sz
1124
 
** parameter should be 6 times the size of the largest database page size.
1125
 
** Scratch buffers are used as part of the btree balance operation.  If
1126
 
** The btree balancer needs additional memory beyond what is provided by
1127
 
** scratch buffers or if no scratch buffer space is specified, then SQLite
1128
 
** goes to [sqlite3_malloc()] to obtain the memory it needs.</dd>
 
1155
** ^SQLite will use no more than one scratch buffer per thread.  So
 
1156
** N should be set to the expected maximum number of threads.  ^SQLite will
 
1157
** never require a scratch buffer that is more than 6 times the database
 
1158
** page size. ^If SQLite needs needs additional scratch memory beyond 
 
1159
** what is provided by this configuration option, then 
 
1160
** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1129
1161
**
1130
1162
** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1131
 
** <dd>This option specifies a static memory buffer that SQLite can use for
 
1163
** <dd> ^This option specifies a static memory buffer that SQLite can use for
1132
1164
** the database page cache with the default page cache implemenation.  
1133
1165
** This configuration should not be used if an application-define page
1134
1166
** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
1136
1168
** memory, the size of each page buffer (sz), and the number of pages (N).
1137
1169
** The sz argument should be the size of the largest database page
1138
1170
** (a power of two between 512 and 32768) plus a little extra for each
1139
 
** page header.  The page header size is 20 to 40 bytes depending on
1140
 
** the host architecture.  It is harmless, apart from the wasted memory,
 
1171
** page header.  ^The page header size is 20 to 40 bytes depending on
 
1172
** the host architecture.  ^It is harmless, apart from the wasted memory,
1141
1173
** to make sz a little too large.  The first
1142
1174
** argument should point to an allocation of at least sz*N bytes of memory.
1143
 
** SQLite will use the memory provided by the first argument to satisfy its
1144
 
** memory needs for the first N pages that it adds to cache.  If additional
 
1175
** ^SQLite will use the memory provided by the first argument to satisfy its
 
1176
** memory needs for the first N pages that it adds to cache.  ^If additional
1145
1177
** page cache memory is needed beyond what is provided by this option, then
1146
1178
** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1147
 
** The implementation might use one or more of the N buffers to hold 
 
1179
** ^The implementation might use one or more of the N buffers to hold 
1148
1180
** memory accounting information. The pointer in the first argument must
1149
1181
** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1150
1182
** will be undefined.</dd>
1151
1183
**
1152
1184
** <dt>SQLITE_CONFIG_HEAP</dt>
1153
 
** <dd>This option specifies a static memory buffer that SQLite will use
 
1185
** <dd> ^This option specifies a static memory buffer that SQLite will use
1154
1186
** for all of its dynamic memory allocation needs beyond those provided
1155
1187
** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1156
1188
** There are three arguments: An 8-byte aligned pointer to the memory,
1157
1189
** the number of bytes in the memory buffer, and the minimum allocation size.
1158
 
** If the first pointer (the memory pointer) is NULL, then SQLite reverts
 
1190
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1159
1191
** to using its default memory allocator (the system malloc() implementation),
1160
 
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  If the
 
1192
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
1161
1193
** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1162
1194
** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1163
1195
** allocator is engaged to handle all of SQLites memory allocation needs.
1165
1197
** boundary or subsequent behavior of SQLite will be undefined.</dd>
1166
1198
**
1167
1199
** <dt>SQLITE_CONFIG_MUTEX</dt>
1168
 
** <dd>This option takes a single argument which is a pointer to an
 
1200
** <dd> ^(This option takes a single argument which is a pointer to an
1169
1201
** instance of the [sqlite3_mutex_methods] structure.  The argument specifies
1170
1202
** alternative low-level mutex routines to be used in place
1171
 
** the mutex routines built into SQLite.</dd>
 
1203
** the mutex routines built into SQLite.)^  ^SQLite makes a copy of the
 
1204
** content of the [sqlite3_mutex_methods] structure before the call to
 
1205
** [sqlite3_config()] returns. ^If SQLite is compiled with
 
1206
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
 
1207
** the entire mutexing subsystem is omitted from the build and hence calls to
 
1208
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
 
1209
** return [SQLITE_ERROR].</dd>
1172
1210
**
1173
1211
** <dt>SQLITE_CONFIG_GETMUTEX</dt>
1174
 
** <dd>This option takes a single argument which is a pointer to an
 
1212
** <dd> ^(This option takes a single argument which is a pointer to an
1175
1213
** instance of the [sqlite3_mutex_methods] structure.  The
1176
1214
** [sqlite3_mutex_methods]
1177
 
** structure is filled with the currently defined mutex routines.
 
1215
** structure is filled with the currently defined mutex routines.)^
1178
1216
** This option can be used to overload the default mutex allocation
1179
1217
** routines with a wrapper used to track mutex usage for performance
1180
 
** profiling or testing, for example.</dd>
 
1218
** profiling or testing, for example.   ^If SQLite is compiled with
 
1219
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
 
1220
** the entire mutexing subsystem is omitted from the build and hence calls to
 
1221
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
 
1222
** return [SQLITE_ERROR].</dd>
1181
1223
**
1182
1224
** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1183
 
** <dd>This option takes two arguments that determine the default
1184
 
** memory allocation lookaside optimization.  The first argument is the
 
1225
** <dd> ^(This option takes two arguments that determine the default
 
1226
** memory allocation for the lookaside memory allocator on each
 
1227
** [database connection].  The first argument is the
1185
1228
** size of each lookaside buffer slot and the second is the number of
1186
 
** slots allocated to each database connection.  This option sets the
1187
 
** <i>default</i> lookaside size.  The [SQLITE_DBCONFIG_LOOKASIDE]
 
1229
** slots allocated to each database connection.)^  ^(This option sets the
 
1230
** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1188
1231
** verb to [sqlite3_db_config()] can be used to change the lookaside
1189
 
** configuration on individual connections.</dd>
 
1232
** configuration on individual connections.)^ </dd>
1190
1233
**
1191
1234
** <dt>SQLITE_CONFIG_PCACHE</dt>
1192
 
** <dd>This option takes a single argument which is a pointer to
 
1235
** <dd> ^(This option takes a single argument which is a pointer to
1193
1236
** an [sqlite3_pcache_methods] object.  This object specifies the interface
1194
 
** to a custom page cache implementation.  SQLite makes a copy of the
 
1237
** to a custom page cache implementation.)^  ^SQLite makes a copy of the
1195
1238
** object and uses it for page cache memory allocations.</dd>
1196
1239
**
1197
1240
** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1198
 
** <dd>This option takes a single argument which is a pointer to an
 
1241
** <dd> ^(This option takes a single argument which is a pointer to an
1199
1242
** [sqlite3_pcache_methods] object.  SQLite copies of the current
1200
 
** page cache implementation into that object.</dd>
 
1243
** page cache implementation into that object.)^ </dd>
1201
1244
**
1202
1245
** </dl>
1203
1246
*/
1218
1261
#define SQLITE_CONFIG_GETPCACHE    15  /* sqlite3_pcache_methods* */
1219
1262
 
1220
1263
/*
1221
 
** CAPI3REF: Configuration Options {H10170} <S20000>
 
1264
** CAPI3REF: Configuration Options
1222
1265
** EXPERIMENTAL
1223
1266
**
1224
1267
** These constants are the available integer configuration options that
1227
1270
** New configuration options may be added in future releases of SQLite.
1228
1271
** Existing configuration options might be discontinued.  Applications
1229
1272
** should check the return code from [sqlite3_db_config()] to make sure that
1230
 
** the call worked.  The [sqlite3_db_config()] interface will return a
 
1273
** the call worked.  ^The [sqlite3_db_config()] interface will return a
1231
1274
** non-zero [error code] if a discontinued or unsupported configuration option
1232
1275
** is invoked.
1233
1276
**
1234
1277
** <dl>
1235
1278
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
1236
 
** <dd>This option takes three additional arguments that determine the 
 
1279
** <dd> ^This option takes three additional arguments that determine the 
1237
1280
** [lookaside memory allocator] configuration for the [database connection].
1238
 
** The first argument (the third parameter to [sqlite3_db_config()] is a
 
1281
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
1239
1282
** pointer to an memory buffer to use for lookaside memory.
1240
 
** The first argument may be NULL in which case SQLite will allocate the
1241
 
** lookaside buffer itself using [sqlite3_malloc()].  The second argument is the
1242
 
** size of each lookaside buffer slot and the third argument is the number of
 
1283
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
 
1284
** may be NULL in which case SQLite will allocate the
 
1285
** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
 
1286
** size of each lookaside buffer slot.  ^The third argument is the number of
1243
1287
** slots.  The size of the buffer in the first argument must be greater than
1244
1288
** or equal to the product of the second and third arguments.  The buffer
1245
 
** must be aligned to an 8-byte boundary.  If the second argument is not
1246
 
** a multiple of 8, it is internally rounded down to the next smaller
 
1289
** must be aligned to an 8-byte boundary.  ^If the second argument to
 
1290
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
 
1291
** rounded down to the next smaller
1247
1292
** multiple of 8.  See also: [SQLITE_CONFIG_LOOKASIDE]</dd>
1248
1293
**
1249
1294
** </dl>
1252
1297
 
1253
1298
 
1254
1299
/*
1255
 
** CAPI3REF: Enable Or Disable Extended Result Codes {H12200} <S10700>
1256
 
**
1257
 
** The sqlite3_extended_result_codes() routine enables or disables the
1258
 
** [extended result codes] feature of SQLite. The extended result
1259
 
** codes are disabled by default for historical compatibility considerations.
1260
 
**
1261
 
** Requirements:
1262
 
** [H12201] [H12202]
 
1300
** CAPI3REF: Enable Or Disable Extended Result Codes
 
1301
**
 
1302
** ^The sqlite3_extended_result_codes() routine enables or disables the
 
1303
** [extended result codes] feature of SQLite. ^The extended result
 
1304
** codes are disabled by default for historical compatibility.
1263
1305
*/
1264
1306
SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
1265
1307
 
1266
1308
/*
1267
 
** CAPI3REF: Last Insert Rowid {H12220} <S10700>
 
1309
** CAPI3REF: Last Insert Rowid
1268
1310
**
1269
 
** Each entry in an SQLite table has a unique 64-bit signed
1270
 
** integer key called the [ROWID | "rowid"]. The rowid is always available
 
1311
** ^Each entry in an SQLite table has a unique 64-bit signed
 
1312
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1271
1313
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1272
 
** names are not also used by explicitly declared columns. If
 
1314
** names are not also used by explicitly declared columns. ^If
1273
1315
** the table has a column of type [INTEGER PRIMARY KEY] then that column
1274
1316
** is another alias for the rowid.
1275
1317
**
1276
 
** This routine returns the [rowid] of the most recent
 
1318
** ^This routine returns the [rowid] of the most recent
1277
1319
** successful [INSERT] into the database from the [database connection]
1278
 
** in the first argument.  If no successful [INSERT]s
 
1320
** in the first argument.  ^If no successful [INSERT]s
1279
1321
** have ever occurred on that database connection, zero is returned.
1280
1322
**
1281
 
** If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
 
1323
** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
1282
1324
** row is returned by this routine as long as the trigger is running.
1283
1325
** But once the trigger terminates, the value returned by this routine
1284
 
** reverts to the last value inserted before the trigger fired.
 
1326
** reverts to the last value inserted before the trigger fired.)^
1285
1327
**
1286
 
** An [INSERT] that fails due to a constraint violation is not a
 
1328
** ^An [INSERT] that fails due to a constraint violation is not a
1287
1329
** successful [INSERT] and does not change the value returned by this
1288
 
** routine.  Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
 
1330
** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
1289
1331
** and INSERT OR ABORT make no changes to the return value of this
1290
 
** routine when their insertion fails.  When INSERT OR REPLACE
 
1332
** routine when their insertion fails.  ^(When INSERT OR REPLACE
1291
1333
** encounters a constraint violation, it does not fail.  The
1292
1334
** INSERT continues to completion after deleting rows that caused
1293
1335
** the constraint problem so INSERT OR REPLACE will always change
1294
 
** the return value of this interface.
 
1336
** the return value of this interface.)^
1295
1337
**
1296
 
** For the purposes of this routine, an [INSERT] is considered to
 
1338
** ^For the purposes of this routine, an [INSERT] is considered to
1297
1339
** be successful even if it is subsequently rolled back.
1298
1340
**
1299
 
** Requirements:
1300
 
** [H12221] [H12223]
 
1341
** This function is accessible to SQL statements via the
 
1342
** [last_insert_rowid() SQL function].
1301
1343
**
1302
1344
** If a separate thread performs a new [INSERT] on the same
1303
1345
** database connection while the [sqlite3_last_insert_rowid()]
1309
1351
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1310
1352
 
1311
1353
/*
1312
 
** CAPI3REF: Count The Number Of Rows Modified {H12240} <S10600>
 
1354
** CAPI3REF: Count The Number Of Rows Modified
1313
1355
**
1314
 
** This function returns the number of database rows that were changed
 
1356
** ^This function returns the number of database rows that were changed
1315
1357
** or inserted or deleted by the most recently completed SQL statement
1316
1358
** on the [database connection] specified by the first parameter.
1317
 
** Only changes that are directly specified by the [INSERT], [UPDATE],
 
1359
** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
1318
1360
** or [DELETE] statement are counted.  Auxiliary changes caused by
1319
 
** triggers or [foreign key actions] are not counted. Use the
 
1361
** triggers or [foreign key actions] are not counted.)^ Use the
1320
1362
** [sqlite3_total_changes()] function to find the total number of changes
1321
1363
** including changes caused by triggers and foreign key actions.
1322
1364
**
1323
 
** Changes to a view that are simulated by an [INSTEAD OF trigger]
 
1365
** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
1324
1366
** are not counted.  Only real table changes are counted.
1325
1367
**
1326
 
** A "row change" is a change to a single row of a single table
 
1368
** ^(A "row change" is a change to a single row of a single table
1327
1369
** caused by an INSERT, DELETE, or UPDATE statement.  Rows that
1328
1370
** are changed as side effects of [REPLACE] constraint resolution,
1329
1371
** rollback, ABORT processing, [DROP TABLE], or by any other
1330
 
** mechanisms do not count as direct row changes.
 
1372
** mechanisms do not count as direct row changes.)^
1331
1373
**
1332
1374
** A "trigger context" is a scope of execution that begins and
1333
1375
** ends with the script of a [CREATE TRIGGER | trigger]. 
1337
1379
** new trigger context is entered for the duration of that one
1338
1380
** trigger.  Subtriggers create subcontexts for their duration.
1339
1381
**
1340
 
** Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
 
1382
** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
1341
1383
** not create a new trigger context.
1342
1384
**
1343
 
** This function returns the number of direct row changes in the
 
1385
** ^This function returns the number of direct row changes in the
1344
1386
** most recent INSERT, UPDATE, or DELETE statement within the same
1345
1387
** trigger context.
1346
1388
**
1347
 
** Thus, when called from the top level, this function returns the
 
1389
** ^Thus, when called from the top level, this function returns the
1348
1390
** number of changes in the most recent INSERT, UPDATE, or DELETE
1349
 
** that also occurred at the top level.  Within the body of a trigger,
 
1391
** that also occurred at the top level.  ^(Within the body of a trigger,
1350
1392
** the sqlite3_changes() interface can be called to find the number of
1351
1393
** changes in the most recently completed INSERT, UPDATE, or DELETE
1352
1394
** statement within the body of the same trigger.
1353
1395
** However, the number returned does not include changes
1354
 
** caused by subtriggers since those have their own context.
1355
 
**
1356
 
** See also the [sqlite3_total_changes()] interface and the
1357
 
** [count_changes pragma].
1358
 
**
1359
 
** Requirements:
1360
 
** [H12241] [H12243]
 
1396
** caused by subtriggers since those have their own context.)^
 
1397
**
 
1398
** See also the [sqlite3_total_changes()] interface, the
 
1399
** [count_changes pragma], and the [changes() SQL function].
1361
1400
**
1362
1401
** If a separate thread makes changes on the same database connection
1363
1402
** while [sqlite3_changes()] is running then the value returned
1366
1405
SQLITE_API int sqlite3_changes(sqlite3*);
1367
1406
 
1368
1407
/*
1369
 
** CAPI3REF: Total Number Of Rows Modified {H12260} <S10600>
 
1408
** CAPI3REF: Total Number Of Rows Modified
1370
1409
**
1371
 
** This function returns the number of row changes caused by [INSERT],
 
1410
** ^This function returns the number of row changes caused by [INSERT],
1372
1411
** [UPDATE] or [DELETE] statements since the [database connection] was opened.
1373
 
** The count includes all changes from all [CREATE TRIGGER | trigger] 
1374
 
** contexts and changes made by [foreign key actions]. However,
 
1412
** ^(The count returned by sqlite3_total_changes() includes all changes
 
1413
** from all [CREATE TRIGGER | trigger] contexts and changes made by
 
1414
** [foreign key actions]. However,
1375
1415
** the count does not include changes used to implement [REPLACE] constraints,
1376
1416
** do rollbacks or ABORT processing, or [DROP TABLE] processing.  The
1377
1417
** count does not include rows of views that fire an [INSTEAD OF trigger],
1378
1418
** though if the INSTEAD OF trigger makes changes of its own, those changes 
1379
 
** are counted.
1380
 
** The changes are counted as soon as the statement that makes them is
1381
 
** completed (when the statement handle is passed to [sqlite3_reset()] or
1382
 
** [sqlite3_finalize()]).
1383
 
**
1384
 
** See also the [sqlite3_changes()] interface and the
1385
 
** [count_changes pragma].
1386
 
**
1387
 
** Requirements:
1388
 
** [H12261] [H12263]
 
1419
** are counted.)^
 
1420
** ^The sqlite3_total_changes() function counts the changes as soon as
 
1421
** the statement that makes them is completed (when the statement handle
 
1422
** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
 
1423
**
 
1424
** See also the [sqlite3_changes()] interface, the
 
1425
** [count_changes pragma], and the [total_changes() SQL function].
1389
1426
**
1390
1427
** If a separate thread makes changes on the same database connection
1391
1428
** while [sqlite3_total_changes()] is running then the value
1394
1431
SQLITE_API int sqlite3_total_changes(sqlite3*);
1395
1432
 
1396
1433
/*
1397
 
** CAPI3REF: Interrupt A Long-Running Query {H12270} <S30500>
 
1434
** CAPI3REF: Interrupt A Long-Running Query
1398
1435
**
1399
 
** This function causes any pending database operation to abort and
 
1436
** ^This function causes any pending database operation to abort and
1400
1437
** return at its earliest opportunity. This routine is typically
1401
1438
** called in response to a user action such as pressing "Cancel"
1402
1439
** or Ctrl-C where the user wants a long query operation to halt
1403
1440
** immediately.
1404
1441
**
1405
 
** It is safe to call this routine from a thread different from the
 
1442
** ^It is safe to call this routine from a thread different from the
1406
1443
** thread that is currently running the database operation.  But it
1407
1444
** is not safe to call this routine with a [database connection] that
1408
1445
** is closed or might close before sqlite3_interrupt() returns.
1409
1446
**
1410
 
** If an SQL operation is very nearly finished at the time when
 
1447
** ^If an SQL operation is very nearly finished at the time when
1411
1448
** sqlite3_interrupt() is called, then it might not have an opportunity
1412
1449
** to be interrupted and might continue to completion.
1413
1450
**
1414
 
** An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
1415
 
** If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
 
1451
** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
 
1452
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
1416
1453
** that is inside an explicit transaction, then the entire transaction
1417
1454
** will be rolled back automatically.
1418
1455
**
1419
 
** The sqlite3_interrupt(D) call is in effect until all currently running
1420
 
** SQL statements on [database connection] D complete.  Any new SQL statements
 
1456
** ^The sqlite3_interrupt(D) call is in effect until all currently running
 
1457
** SQL statements on [database connection] D complete.  ^Any new SQL statements
1421
1458
** that are started after the sqlite3_interrupt() call and before the 
1422
1459
** running statements reaches zero are interrupted as if they had been
1423
 
** running prior to the sqlite3_interrupt() call.  New SQL statements
 
1460
** running prior to the sqlite3_interrupt() call.  ^New SQL statements
1424
1461
** that are started after the running statement count reaches zero are
1425
1462
** not effected by the sqlite3_interrupt().
1426
 
** A call to sqlite3_interrupt(D) that occurs when there are no running
 
1463
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
1427
1464
** SQL statements is a no-op and has no effect on SQL statements
1428
1465
** that are started after the sqlite3_interrupt() call returns.
1429
1466
**
1430
 
** Requirements:
1431
 
** [H12271] [H12272]
1432
 
**
1433
1467
** If the database connection closes while [sqlite3_interrupt()]
1434
1468
** is running then bad things will likely happen.
1435
1469
*/
1436
1470
SQLITE_API void sqlite3_interrupt(sqlite3*);
1437
1471
 
1438
1472
/*
1439
 
** CAPI3REF: Determine If An SQL Statement Is Complete {H10510} <S70200>
 
1473
** CAPI3REF: Determine If An SQL Statement Is Complete
1440
1474
**
1441
1475
** These routines are useful during command-line input to determine if the
1442
1476
** currently entered text seems to form a complete SQL statement or
1443
1477
** if additional input is needed before sending the text into
1444
 
** SQLite for parsing.  These routines return 1 if the input string
1445
 
** appears to be a complete SQL statement.  A statement is judged to be
 
1478
** SQLite for parsing.  ^These routines return 1 if the input string
 
1479
** appears to be a complete SQL statement.  ^A statement is judged to be
1446
1480
** complete if it ends with a semicolon token and is not a prefix of a
1447
 
** well-formed CREATE TRIGGER statement.  Semicolons that are embedded within
 
1481
** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
1448
1482
** string literals or quoted identifier names or comments are not
1449
1483
** independent tokens (they are part of the token in which they are
1450
 
** embedded) and thus do not count as a statement terminator.  Whitespace
 
1484
** embedded) and thus do not count as a statement terminator.  ^Whitespace
1451
1485
** and comments that follow the final semicolon are ignored.
1452
1486
**
1453
 
** These routines return 0 if the statement is incomplete.  If a
 
1487
** ^These routines return 0 if the statement is incomplete.  ^If a
1454
1488
** memory allocation fails, then SQLITE_NOMEM is returned.
1455
1489
**
1456
 
** These routines do not parse the SQL statements thus
 
1490
** ^These routines do not parse the SQL statements thus
1457
1491
** will not detect syntactically incorrect SQL.
1458
1492
**
1459
 
** If SQLite has not been initialized using [sqlite3_initialize()] prior 
 
1493
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 
1460
1494
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
1461
1495
** automatically by sqlite3_complete16().  If that initialization fails,
1462
1496
** then the return value from sqlite3_complete16() will be non-zero
1463
 
** regardless of whether or not the input SQL is complete.
1464
 
**
1465
 
** Requirements: [H10511] [H10512]
 
1497
** regardless of whether or not the input SQL is complete.)^
1466
1498
**
1467
1499
** The input to [sqlite3_complete()] must be a zero-terminated
1468
1500
** UTF-8 string.
1474
1506
SQLITE_API int sqlite3_complete16(const void *sql);
1475
1507
 
1476
1508
/*
1477
 
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {H12310} <S40400>
 
1509
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
1478
1510
**
1479
 
** This routine sets a callback function that might be invoked whenever
 
1511
** ^This routine sets a callback function that might be invoked whenever
1480
1512
** an attempt is made to open a database table that another thread
1481
1513
** or process has locked.
1482
1514
**
1483
 
** If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
1484
 
** is returned immediately upon encountering the lock. If the busy callback
1485
 
** is not NULL, then the callback will be invoked with two arguments.
 
1515
** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
 
1516
** is returned immediately upon encountering the lock.  ^If the busy callback
 
1517
** is not NULL, then the callback might be invoked with two arguments.
1486
1518
**
1487
 
** The first argument to the handler is a copy of the void* pointer which
1488
 
** is the third argument to sqlite3_busy_handler().  The second argument to
1489
 
** the handler callback is the number of times that the busy handler has
1490
 
** been invoked for this locking event.  If the
 
1519
** ^The first argument to the busy handler is a copy of the void* pointer which
 
1520
** is the third argument to sqlite3_busy_handler().  ^The second argument to
 
1521
** the busy handler callback is the number of times that the busy handler has
 
1522
** been invoked for this locking event.  ^If the
1491
1523
** busy callback returns 0, then no additional attempts are made to
1492
1524
** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
1493
 
** If the callback returns non-zero, then another attempt
 
1525
** ^If the callback returns non-zero, then another attempt
1494
1526
** is made to open the database for reading and the cycle repeats.
1495
1527
**
1496
1528
** The presence of a busy handler does not guarantee that it will be invoked
1497
 
** when there is lock contention. If SQLite determines that invoking the busy
 
1529
** when there is lock contention. ^If SQLite determines that invoking the busy
1498
1530
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
1499
1531
** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
1500
1532
** Consider a scenario where one process is holding a read lock that
1508
1540
** will induce the first process to release its read lock and allow
1509
1541
** the second process to proceed.
1510
1542
**
1511
 
** The default busy callback is NULL.
 
1543
** ^The default busy callback is NULL.
1512
1544
**
1513
 
** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
 
1545
** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
1514
1546
** when SQLite is in the middle of a large transaction where all the
1515
1547
** changes will not fit into the in-memory cache.  SQLite will
1516
1548
** already hold a RESERVED lock on the database file, but it needs
1517
1549
** to promote this lock to EXCLUSIVE so that it can spill cache
1518
1550
** pages into the database file without harm to concurrent
1519
 
** readers.  If it is unable to promote the lock, then the in-memory
 
1551
** readers.  ^If it is unable to promote the lock, then the in-memory
1520
1552
** cache will be left in an inconsistent state and so the error
1521
1553
** code is promoted from the relatively benign [SQLITE_BUSY] to
1522
 
** the more severe [SQLITE_IOERR_BLOCKED].  This error code promotion
 
1554
** the more severe [SQLITE_IOERR_BLOCKED].  ^This error code promotion
1523
1555
** forces an automatic rollback of the changes.  See the
1524
1556
** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
1525
1557
** CorruptionFollowingBusyError</a> wiki page for a discussion of why
1526
1558
** this is important.
1527
1559
**
1528
 
** There can only be a single busy handler defined for each
 
1560
** ^(There can only be a single busy handler defined for each
1529
1561
** [database connection].  Setting a new busy handler clears any
1530
 
** previously set handler.  Note that calling [sqlite3_busy_timeout()]
 
1562
** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
1531
1563
** will also set or clear the busy handler.
1532
1564
**
1533
1565
** The busy callback should not take any actions which modify the
1534
1566
** database connection that invoked the busy handler.  Any such actions
1535
1567
** result in undefined behavior.
1536
1568
** 
1537
 
** Requirements:
1538
 
** [H12311] [H12312] [H12314] [H12316] [H12318]
1539
 
**
1540
1569
** A busy handler must not close the database connection
1541
1570
** or [prepared statement] that invoked the busy handler.
1542
1571
*/
1543
1572
SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
1544
1573
 
1545
1574
/*
1546
 
** CAPI3REF: Set A Busy Timeout {H12340} <S40410>
 
1575
** CAPI3REF: Set A Busy Timeout
1547
1576
**
1548
 
** This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
1549
 
** for a specified amount of time when a table is locked.  The handler
 
1577
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
 
1578
** for a specified amount of time when a table is locked.  ^The handler
1550
1579
** will sleep multiple times until at least "ms" milliseconds of sleeping
1551
 
** have accumulated. {H12343} After "ms" milliseconds of sleeping,
 
1580
** have accumulated.  ^After at least "ms" milliseconds of sleeping,
1552
1581
** the handler returns 0 which causes [sqlite3_step()] to return
1553
1582
** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
1554
1583
**
1555
 
** Calling this routine with an argument less than or equal to zero
 
1584
** ^Calling this routine with an argument less than or equal to zero
1556
1585
** turns off all busy handlers.
1557
1586
**
1558
 
** There can only be a single busy handler for a particular
 
1587
** ^(There can only be a single busy handler for a particular
1559
1588
** [database connection] any any given moment.  If another busy handler
1560
1589
** was defined  (using [sqlite3_busy_handler()]) prior to calling
1561
 
** this routine, that other busy handler is cleared.
1562
 
**
1563
 
** Requirements:
1564
 
** [H12341] [H12343] [H12344]
 
1590
** this routine, that other busy handler is cleared.)^
1565
1591
*/
1566
1592
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
1567
1593
 
1568
1594
/*
1569
 
** CAPI3REF: Convenience Routines For Running Queries {H12370} <S10000>
 
1595
** CAPI3REF: Convenience Routines For Running Queries
1570
1596
**
1571
1597
** Definition: A <b>result table</b> is memory data structure created by the
1572
1598
** [sqlite3_get_table()] interface.  A result table records the
1614
1640
**        azResult&#91;7] = "21";
1615
1641
** </pre></blockquote>
1616
1642
**
1617
 
** The sqlite3_get_table() function evaluates one or more
 
1643
** ^The sqlite3_get_table() function evaluates one or more
1618
1644
** semicolon-separated SQL statements in the zero-terminated UTF-8
1619
 
** string of its 2nd parameter.  It returns a result table to the
 
1645
** string of its 2nd parameter and returns a result table to the
1620
1646
** pointer given in its 3rd parameter.
1621
1647
**
1622
 
** After the calling function has finished using the result, it should
1623
 
** pass the pointer to the result table to sqlite3_free_table() in order to
 
1648
** After the application has finished with the result from sqlite3_get_table(),
 
1649
** it should pass the result table pointer to sqlite3_free_table() in order to
1624
1650
** release the memory that was malloced.  Because of the way the
1625
1651
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
1626
1652
** function must not try to call [sqlite3_free()] directly.  Only
1627
1653
** [sqlite3_free_table()] is able to release the memory properly and safely.
1628
1654
**
1629
 
** The sqlite3_get_table() interface is implemented as a wrapper around
 
1655
** ^(The sqlite3_get_table() interface is implemented as a wrapper around
1630
1656
** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
1631
1657
** to any internal data structures of SQLite.  It uses only the public
1632
1658
** interface defined here.  As a consequence, errors that occur in the
1633
1659
** wrapper layer outside of the internal [sqlite3_exec()] call are not
1634
 
** reflected in subsequent calls to [sqlite3_errcode()] or [sqlite3_errmsg()].
1635
 
**
1636
 
** Requirements:
1637
 
** [H12371] [H12373] [H12374] [H12376] [H12379] [H12382]
 
1660
** reflected in subsequent calls to [sqlite3_errcode()] or
 
1661
** [sqlite3_errmsg()].)^
1638
1662
*/
1639
1663
SQLITE_API int sqlite3_get_table(
1640
1664
  sqlite3 *db,          /* An open database */
1647
1671
SQLITE_API void sqlite3_free_table(char **result);
1648
1672
 
1649
1673
/*
1650
 
** CAPI3REF: Formatted String Printing Functions {H17400} <S70000><S20000>
 
1674
** CAPI3REF: Formatted String Printing Functions
1651
1675
**
1652
1676
** These routines are work-alikes of the "printf()" family of functions
1653
1677
** from the standard C library.
1654
1678
**
1655
 
** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
 
1679
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
1656
1680
** results into memory obtained from [sqlite3_malloc()].
1657
1681
** The strings returned by these two routines should be
1658
 
** released by [sqlite3_free()].  Both routines return a
 
1682
** released by [sqlite3_free()].  ^Both routines return a
1659
1683
** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
1660
1684
** memory to hold the resulting string.
1661
1685
**
1662
 
** In sqlite3_snprintf() routine is similar to "snprintf()" from
 
1686
** ^(In sqlite3_snprintf() routine is similar to "snprintf()" from
1663
1687
** the standard C library.  The result is written into the
1664
1688
** buffer supplied as the second parameter whose size is given by
1665
1689
** the first parameter. Note that the order of the
1666
 
** first two parameters is reversed from snprintf().  This is an
 
1690
** first two parameters is reversed from snprintf().)^  This is an
1667
1691
** historical accident that cannot be fixed without breaking
1668
 
** backwards compatibility.  Note also that sqlite3_snprintf()
 
1692
** backwards compatibility.  ^(Note also that sqlite3_snprintf()
1669
1693
** returns a pointer to its buffer instead of the number of
1670
 
** characters actually written into the buffer.  We admit that
 
1694
** characters actually written into the buffer.)^  We admit that
1671
1695
** the number of characters written would be a more useful return
1672
1696
** value but we cannot change the implementation of sqlite3_snprintf()
1673
1697
** now without breaking compatibility.
1674
1698
**
1675
 
** As long as the buffer size is greater than zero, sqlite3_snprintf()
1676
 
** guarantees that the buffer is always zero-terminated.  The first
 
1699
** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
 
1700
** guarantees that the buffer is always zero-terminated.  ^The first
1677
1701
** parameter "n" is the total size of the buffer, including space for
1678
1702
** the zero terminator.  So the longest string that can be completely
1679
1703
** written will be n-1 characters.
1683
1707
** All of the usual printf() formatting options apply.  In addition, there
1684
1708
** is are "%q", "%Q", and "%z" options.
1685
1709
**
1686
 
** The %q option works like %s in that it substitutes a null-terminated
 
1710
** ^(The %q option works like %s in that it substitutes a null-terminated
1687
1711
** string from the argument list.  But %q also doubles every '\'' character.
1688
 
** %q is designed for use inside a string literal.  By doubling each '\''
 
1712
** %q is designed for use inside a string literal.)^  By doubling each '\''
1689
1713
** character it escapes that character and allows it to be inserted into
1690
1714
** the string.
1691
1715
**
1720
1744
** This second example is an SQL syntax error.  As a general rule you should
1721
1745
** always use %q instead of %s when inserting text into a string literal.
1722
1746
**
1723
 
** The %Q option works like %q except it also adds single quotes around
 
1747
** ^(The %Q option works like %q except it also adds single quotes around
1724
1748
** the outside of the total string.  Additionally, if the parameter in the
1725
1749
** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
1726
 
** single quotes) in place of the %Q option.  So, for example, one could say:
 
1750
** single quotes).)^  So, for example, one could say:
1727
1751
**
1728
1752
** <blockquote><pre>
1729
1753
**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
1734
1758
** The code above will render a correct SQL statement in the zSQL
1735
1759
** variable even if the zText variable is a NULL pointer.
1736
1760
**
1737
 
** The "%z" formatting option works exactly like "%s" with the
 
1761
** ^(The "%z" formatting option works like "%s" but with the
1738
1762
** addition that after the string has been read and copied into
1739
 
** the result, [sqlite3_free()] is called on the input string. {END}
1740
 
**
1741
 
** Requirements:
1742
 
** [H17403] [H17406] [H17407]
 
1763
** the result, [sqlite3_free()] is called on the input string.)^
1743
1764
*/
1744
1765
SQLITE_API char *sqlite3_mprintf(const char*,...);
1745
1766
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
1746
1767
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
1747
1768
 
1748
1769
/*
1749
 
** CAPI3REF: Memory Allocation Subsystem {H17300} <S20000>
 
1770
** CAPI3REF: Memory Allocation Subsystem
1750
1771
**
1751
 
** The SQLite core  uses these three routines for all of its own
 
1772
** The SQLite core uses these three routines for all of its own
1752
1773
** internal memory allocation needs. "Core" in the previous sentence
1753
1774
** does not include operating-system specific VFS implementation.  The
1754
1775
** Windows VFS uses native malloc() and free() for some operations.
1755
1776
**
1756
 
** The sqlite3_malloc() routine returns a pointer to a block
 
1777
** ^The sqlite3_malloc() routine returns a pointer to a block
1757
1778
** of memory at least N bytes in length, where N is the parameter.
1758
 
** If sqlite3_malloc() is unable to obtain sufficient free
1759
 
** memory, it returns a NULL pointer.  If the parameter N to
 
1779
** ^If sqlite3_malloc() is unable to obtain sufficient free
 
1780
** memory, it returns a NULL pointer.  ^If the parameter N to
1760
1781
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
1761
1782
** a NULL pointer.
1762
1783
**
1763
 
** Calling sqlite3_free() with a pointer previously returned
 
1784
** ^Calling sqlite3_free() with a pointer previously returned
1764
1785
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
1765
 
** that it might be reused.  The sqlite3_free() routine is
 
1786
** that it might be reused.  ^The sqlite3_free() routine is
1766
1787
** a no-op if is called with a NULL pointer.  Passing a NULL pointer
1767
1788
** to sqlite3_free() is harmless.  After being freed, memory
1768
1789
** should neither be read nor written.  Even reading previously freed
1771
1792
** might result if sqlite3_free() is called with a non-NULL pointer that
1772
1793
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
1773
1794
**
1774
 
** The sqlite3_realloc() interface attempts to resize a
 
1795
** ^(The sqlite3_realloc() interface attempts to resize a
1775
1796
** prior memory allocation to be at least N bytes, where N is the
1776
1797
** second parameter.  The memory allocation to be resized is the first
1777
 
** parameter.  If the first parameter to sqlite3_realloc()
 
1798
** parameter.)^ ^ If the first parameter to sqlite3_realloc()
1778
1799
** is a NULL pointer then its behavior is identical to calling
1779
1800
** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
1780
 
** If the second parameter to sqlite3_realloc() is zero or
 
1801
** ^If the second parameter to sqlite3_realloc() is zero or
1781
1802
** negative then the behavior is exactly the same as calling
1782
1803
** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
1783
 
** sqlite3_realloc() returns a pointer to a memory allocation
 
1804
** ^sqlite3_realloc() returns a pointer to a memory allocation
1784
1805
** of at least N bytes in size or NULL if sufficient memory is unavailable.
1785
 
** If M is the size of the prior allocation, then min(N,M) bytes
 
1806
** ^If M is the size of the prior allocation, then min(N,M) bytes
1786
1807
** of the prior allocation are copied into the beginning of buffer returned
1787
1808
** by sqlite3_realloc() and the prior allocation is freed.
1788
 
** If sqlite3_realloc() returns NULL, then the prior allocation
 
1809
** ^If sqlite3_realloc() returns NULL, then the prior allocation
1789
1810
** is not freed.
1790
1811
**
1791
 
** The memory returned by sqlite3_malloc() and sqlite3_realloc()
1792
 
** is always aligned to at least an 8 byte boundary. {END}
1793
 
**
1794
 
** The default implementation of the memory allocation subsystem uses
1795
 
** the malloc(), realloc() and free() provided by the standard C library.
1796
 
** {H17382} However, if SQLite is compiled with the
1797
 
** SQLITE_MEMORY_SIZE=<i>NNN</i> C preprocessor macro (where <i>NNN</i>
1798
 
** is an integer), then SQLite create a static array of at least
1799
 
** <i>NNN</i> bytes in size and uses that array for all of its dynamic
1800
 
** memory allocation needs. {END}  Additional memory allocator options
1801
 
** may be added in future releases.
 
1812
** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
 
1813
** is always aligned to at least an 8 byte boundary.
1802
1814
**
1803
1815
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
1804
1816
** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
1813
1825
** they are reported back as [SQLITE_CANTOPEN] or
1814
1826
** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
1815
1827
**
1816
 
** Requirements:
1817
 
** [H17303] [H17304] [H17305] [H17306] [H17310] [H17312] [H17315] [H17318]
1818
 
** [H17321] [H17322] [H17323]
1819
 
**
1820
1828
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
1821
1829
** must be either NULL or else pointers obtained from a prior
1822
1830
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
1831
1839
SQLITE_API void sqlite3_free(void*);
1832
1840
 
1833
1841
/*
1834
 
** CAPI3REF: Memory Allocator Statistics {H17370} <S30210>
 
1842
** CAPI3REF: Memory Allocator Statistics
1835
1843
**
1836
1844
** SQLite provides these two interfaces for reporting on the status
1837
1845
** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
1838
1846
** routines, which form the built-in memory allocation subsystem.
1839
1847
**
1840
 
** Requirements:
1841
 
** [H17371] [H17373] [H17374] [H17375]
 
1848
** ^The [sqlite3_memory_used()] routine returns the number of bytes
 
1849
** of memory currently outstanding (malloced but not freed).
 
1850
** ^The [sqlite3_memory_highwater()] routine returns the maximum
 
1851
** value of [sqlite3_memory_used()] since the high-water mark
 
1852
** was last reset.  ^The values returned by [sqlite3_memory_used()] and
 
1853
** [sqlite3_memory_highwater()] include any overhead
 
1854
** added by SQLite in its implementation of [sqlite3_malloc()],
 
1855
** but not overhead added by the any underlying system library
 
1856
** routines that [sqlite3_malloc()] may call.
 
1857
**
 
1858
** ^The memory high-water mark is reset to the current value of
 
1859
** [sqlite3_memory_used()] if and only if the parameter to
 
1860
** [sqlite3_memory_highwater()] is true.  ^The value returned
 
1861
** by [sqlite3_memory_highwater(1)] is the high-water mark
 
1862
** prior to the reset.
1842
1863
*/
1843
1864
SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
1844
1865
SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
1845
1866
 
1846
1867
/*
1847
 
** CAPI3REF: Pseudo-Random Number Generator {H17390} <S20000>
 
1868
** CAPI3REF: Pseudo-Random Number Generator
1848
1869
**
1849
1870
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
1850
1871
** select random [ROWID | ROWIDs] when inserting new records into a table that
1852
1873
** the build-in random() and randomblob() SQL functions.  This interface allows
1853
1874
** applications to access the same PRNG for other purposes.
1854
1875
**
1855
 
** A call to this routine stores N bytes of randomness into buffer P.
 
1876
** ^A call to this routine stores N bytes of randomness into buffer P.
1856
1877
**
1857
 
** The first time this routine is invoked (either internally or by
 
1878
** ^The first time this routine is invoked (either internally or by
1858
1879
** the application) the PRNG is seeded using randomness obtained
1859
1880
** from the xRandomness method of the default [sqlite3_vfs] object.
1860
 
** On all subsequent invocations, the pseudo-randomness is generated
 
1881
** ^On all subsequent invocations, the pseudo-randomness is generated
1861
1882
** internally and without recourse to the [sqlite3_vfs] xRandomness
1862
1883
** method.
1863
 
**
1864
 
** Requirements:
1865
 
** [H17392]
1866
1884
*/
1867
1885
SQLITE_API void sqlite3_randomness(int N, void *P);
1868
1886
 
1869
1887
/*
1870
 
** CAPI3REF: Compile-Time Authorization Callbacks {H12500} <S70100>
 
1888
** CAPI3REF: Compile-Time Authorization Callbacks
1871
1889
**
1872
 
** This routine registers a authorizer callback with a particular
 
1890
** ^This routine registers a authorizer callback with a particular
1873
1891
** [database connection], supplied in the first argument.
1874
 
** The authorizer callback is invoked as SQL statements are being compiled
 
1892
** ^The authorizer callback is invoked as SQL statements are being compiled
1875
1893
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
1876
 
** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  At various
 
1894
** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
1877
1895
** points during the compilation process, as logic is being created
1878
1896
** to perform various actions, the authorizer callback is invoked to
1879
 
** see if those actions are allowed.  The authorizer callback should
 
1897
** see if those actions are allowed.  ^The authorizer callback should
1880
1898
** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
1881
1899
** specific action but allow the SQL statement to continue to be
1882
1900
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
1883
 
** rejected with an error.  If the authorizer callback returns
 
1901
** rejected with an error.  ^If the authorizer callback returns
1884
1902
** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
1885
1903
** then the [sqlite3_prepare_v2()] or equivalent call that triggered
1886
1904
** the authorizer will fail with an error message.
1887
1905
**
1888
1906
** When the callback returns [SQLITE_OK], that means the operation
1889
 
** requested is ok.  When the callback returns [SQLITE_DENY], the
 
1907
** requested is ok.  ^When the callback returns [SQLITE_DENY], the
1890
1908
** [sqlite3_prepare_v2()] or equivalent call that triggered the
1891
1909
** authorizer will fail with an error message explaining that
1892
1910
** access is denied. 
1893
1911
**
1894
 
** The first parameter to the authorizer callback is a copy of the third
1895
 
** parameter to the sqlite3_set_authorizer() interface. The second parameter
 
1912
** ^The first parameter to the authorizer callback is a copy of the third
 
1913
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
1896
1914
** to the callback is an integer [SQLITE_COPY | action code] that specifies
1897
 
** the particular action to be authorized. The third through sixth parameters
 
1915
** the particular action to be authorized. ^The third through sixth parameters
1898
1916
** to the callback are zero-terminated strings that contain additional
1899
1917
** details about the action to be authorized.
1900
1918
**
1901
 
** If the action code is [SQLITE_READ]
 
1919
** ^If the action code is [SQLITE_READ]
1902
1920
** and the callback returns [SQLITE_IGNORE] then the
1903
1921
** [prepared statement] statement is constructed to substitute
1904
1922
** a NULL value in place of the table column that would have
1905
1923
** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
1906
1924
** return can be used to deny an untrusted user access to individual
1907
1925
** columns of a table.
1908
 
** If the action code is [SQLITE_DELETE] and the callback returns
 
1926
** ^If the action code is [SQLITE_DELETE] and the callback returns
1909
1927
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
1910
1928
** [truncate optimization] is disabled and all rows are deleted individually.
1911
1929
**
1925
1943
** and limiting database size using the [max_page_count] [PRAGMA]
1926
1944
** in addition to using an authorizer.
1927
1945
**
1928
 
** Only a single authorizer can be in place on a database connection
 
1946
** ^(Only a single authorizer can be in place on a database connection
1929
1947
** at a time.  Each call to sqlite3_set_authorizer overrides the
1930
 
** previous call.  Disable the authorizer by installing a NULL callback.
 
1948
** previous call.)^  ^Disable the authorizer by installing a NULL callback.
1931
1949
** The authorizer is disabled by default.
1932
1950
**
1933
1951
** The authorizer callback must not do anything that will modify
1935
1953
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
1936
1954
** database connections for the meaning of "modify" in this paragraph.
1937
1955
**
1938
 
** When [sqlite3_prepare_v2()] is used to prepare a statement, the
 
1956
** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
1939
1957
** statement might be re-prepared during [sqlite3_step()] due to a 
1940
1958
** schema change.  Hence, the application should ensure that the
1941
1959
** correct authorizer callback remains in place during the [sqlite3_step()].
1942
1960
**
1943
 
** Note that the authorizer callback is invoked only during
 
1961
** ^Note that the authorizer callback is invoked only during
1944
1962
** [sqlite3_prepare()] or its variants.  Authorization is not
1945
1963
** performed during statement evaluation in [sqlite3_step()], unless
1946
1964
** as stated in the previous paragraph, sqlite3_step() invokes
1947
1965
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
1948
 
**
1949
 
** Requirements:
1950
 
** [H12501] [H12502] [H12503] [H12504] [H12505] [H12506] [H12507] [H12510]
1951
 
** [H12511] [H12512] [H12520] [H12521] [H12522]
1952
1966
*/
1953
1967
SQLITE_API int sqlite3_set_authorizer(
1954
1968
  sqlite3*,
1957
1971
);
1958
1972
 
1959
1973
/*
1960
 
** CAPI3REF: Authorizer Return Codes {H12590} <H12500>
 
1974
** CAPI3REF: Authorizer Return Codes
1961
1975
**
1962
1976
** The [sqlite3_set_authorizer | authorizer callback function] must
1963
1977
** return either [SQLITE_OK] or one of these two constants in order
1969
1983
#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
1970
1984
 
1971
1985
/*
1972
 
** CAPI3REF: Authorizer Action Codes {H12550} <H12500>
 
1986
** CAPI3REF: Authorizer Action Codes
1973
1987
**
1974
1988
** The [sqlite3_set_authorizer()] interface registers a callback function
1975
1989
** that is invoked to authorize certain SQL statement actions.  The
1980
1994
** These action code values signify what kind of operation is to be
1981
1995
** authorized.  The 3rd and 4th parameters to the authorization
1982
1996
** callback function will be parameters or NULL depending on which of these
1983
 
** codes is used as the second parameter.  The 5th parameter to the
 
1997
** codes is used as the second parameter.  ^(The 5th parameter to the
1984
1998
** authorizer callback is the name of the database ("main", "temp",
1985
 
** etc.) if applicable.  The 6th parameter to the authorizer callback
 
1999
** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
1986
2000
** is the name of the inner-most trigger or view that is responsible for
1987
2001
** the access attempt or NULL if this access attempt is directly from
1988
2002
** top-level SQL code.
1989
 
**
1990
 
** Requirements:
1991
 
** [H12551] [H12552] [H12553] [H12554]
1992
2003
*/
1993
2004
/******************************************* 3rd ************ 4th ***********/
1994
2005
#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
2026
2037
#define SQLITE_COPY                  0   /* No longer used */
2027
2038
 
2028
2039
/*
2029
 
** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
 
2040
** CAPI3REF: Tracing And Profiling Functions
2030
2041
** EXPERIMENTAL
2031
2042
**
2032
2043
** These routines register callback functions that can be used for
2033
2044
** tracing and profiling the execution of SQL statements.
2034
2045
**
2035
 
** The callback function registered by sqlite3_trace() is invoked at
 
2046
** ^The callback function registered by sqlite3_trace() is invoked at
2036
2047
** various times when an SQL statement is being run by [sqlite3_step()].
2037
 
** The callback returns a UTF-8 rendering of the SQL statement text
2038
 
** as the statement first begins executing.  Additional callbacks occur
 
2048
** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
 
2049
** SQL statement text as the statement first begins executing.
 
2050
** ^(Additional sqlite3_trace() callbacks might occur
2039
2051
** as each triggered subprogram is entered.  The callbacks for triggers
2040
 
** contain a UTF-8 SQL comment that identifies the trigger.
 
2052
** contain a UTF-8 SQL comment that identifies the trigger.)^
2041
2053
**
2042
 
** The callback function registered by sqlite3_profile() is invoked
2043
 
** as each SQL statement finishes.  The profile callback contains
 
2054
** ^The callback function registered by sqlite3_profile() is invoked
 
2055
** as each SQL statement finishes.  ^The profile callback contains
2044
2056
** the original statement text and an estimate of wall-clock time
2045
2057
** of how long that statement took to run.
2046
 
**
2047
 
** Requirements:
2048
 
** [H12281] [H12282] [H12283] [H12284] [H12285] [H12287] [H12288] [H12289]
2049
 
** [H12290]
2050
2058
*/
2051
2059
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2052
2060
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2053
2061
   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2054
2062
 
2055
2063
/*
2056
 
** CAPI3REF: Query Progress Callbacks {H12910} <S60400>
 
2064
** CAPI3REF: Query Progress Callbacks
2057
2065
**
2058
 
** This routine configures a callback function - the
 
2066
** ^This routine configures a callback function - the
2059
2067
** progress callback - that is invoked periodically during long
2060
2068
** running calls to [sqlite3_exec()], [sqlite3_step()] and
2061
2069
** [sqlite3_get_table()].  An example use for this
2062
2070
** interface is to keep a GUI updated during a large query.
2063
2071
**
2064
 
** If the progress callback returns non-zero, the operation is
 
2072
** ^If the progress callback returns non-zero, the operation is
2065
2073
** interrupted.  This feature can be used to implement a
2066
2074
** "Cancel" button on a GUI progress dialog box.
2067
2075
**
2070
2078
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2071
2079
** database connections for the meaning of "modify" in this paragraph.
2072
2080
**
2073
 
** Requirements:
2074
 
** [H12911] [H12912] [H12913] [H12914] [H12915] [H12916] [H12917] [H12918]
2075
 
**
2076
2081
*/
2077
2082
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2078
2083
 
2079
2084
/*
2080
 
** CAPI3REF: Opening A New Database Connection {H12700} <S40200>
 
2085
** CAPI3REF: Opening A New Database Connection
2081
2086
**
2082
 
** These routines open an SQLite database file whose name is given by the
2083
 
** filename argument. The filename argument is interpreted as UTF-8 for
 
2087
** ^These routines open an SQLite database file whose name is given by the
 
2088
** filename argument. ^The filename argument is interpreted as UTF-8 for
2084
2089
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2085
 
** order for sqlite3_open16(). A [database connection] handle is usually
 
2090
** order for sqlite3_open16(). ^(A [database connection] handle is usually
2086
2091
** returned in *ppDb, even if an error occurs.  The only exception is that
2087
2092
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
2088
2093
** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
2089
 
** object. If the database is opened (and/or created) successfully, then
2090
 
** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.  The
 
2094
** object.)^ ^(If the database is opened (and/or created) successfully, then
 
2095
** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
2091
2096
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
2092
 
** an English language description of the error.
 
2097
** an English language description of the error following a failure of any
 
2098
** of the sqlite3_open() routines.
2093
2099
**
2094
 
** The default encoding for the database will be UTF-8 if
 
2100
** ^The default encoding for the database will be UTF-8 if
2095
2101
** sqlite3_open() or sqlite3_open_v2() is called and
2096
2102
** UTF-16 in the native byte order if sqlite3_open16() is used.
2097
2103
**
2101
2107
**
2102
2108
** The sqlite3_open_v2() interface works like sqlite3_open()
2103
2109
** except that it accepts two additional parameters for additional control
2104
 
** over the new database connection.  The flags parameter can take one of
 
2110
** over the new database connection.  ^(The flags parameter to
 
2111
** sqlite3_open_v2() can take one of
2105
2112
** the following three values, optionally combined with the 
2106
2113
** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2107
 
** and/or [SQLITE_OPEN_PRIVATECACHE] flags:
 
2114
** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
2108
2115
**
2109
2116
** <dl>
2110
 
** <dt>[SQLITE_OPEN_READONLY]</dt>
 
2117
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
2111
2118
** <dd>The database is opened in read-only mode.  If the database does not
2112
 
** already exist, an error is returned.</dd>
 
2119
** already exist, an error is returned.</dd>)^
2113
2120
**
2114
 
** <dt>[SQLITE_OPEN_READWRITE]</dt>
 
2121
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
2115
2122
** <dd>The database is opened for reading and writing if possible, or reading
2116
2123
** only if the file is write protected by the operating system.  In either
2117
 
** case the database must already exist, otherwise an error is returned.</dd>
 
2124
** case the database must already exist, otherwise an error is returned.</dd>)^
2118
2125
**
2119
 
** <dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
 
2126
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2120
2127
** <dd>The database is opened for reading and writing, and is creates it if
2121
2128
** it does not already exist. This is the behavior that is always used for
2122
 
** sqlite3_open() and sqlite3_open16().</dd>
 
2129
** sqlite3_open() and sqlite3_open16().</dd>)^
2123
2130
** </dl>
2124
2131
**
2125
2132
** If the 3rd parameter to sqlite3_open_v2() is not one of the
2128
2135
** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags,
2129
2136
** then the behavior is undefined.
2130
2137
**
2131
 
** If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
 
2138
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2132
2139
** opens in the multi-thread [threading mode] as long as the single-thread
2133
 
** mode has not been set at compile-time or start-time.  If the
 
2140
** mode has not been set at compile-time or start-time.  ^If the
2134
2141
** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
2135
2142
** in the serialized [threading mode] unless single-thread was
2136
2143
** previously selected at compile-time or start-time.
2137
 
** The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
 
2144
** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
2138
2145
** eligible to use [shared cache mode], regardless of whether or not shared
2139
 
** cache is enabled using [sqlite3_enable_shared_cache()].  The
 
2146
** cache is enabled using [sqlite3_enable_shared_cache()].  ^The
2140
2147
** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2141
2148
** participate in [shared cache mode] even if it is enabled.
2142
2149
**
2143
 
** If the filename is ":memory:", then a private, temporary in-memory database
2144
 
** is created for the connection.  This in-memory database will vanish when
 
2150
** ^If the filename is ":memory:", then a private, temporary in-memory database
 
2151
** is created for the connection.  ^This in-memory database will vanish when
2145
2152
** the database connection is closed.  Future versions of SQLite might
2146
2153
** make use of additional special filenames that begin with the ":" character.
2147
2154
** It is recommended that when a database filename actually does begin with
2148
2155
** a ":" character you should prefix the filename with a pathname such as
2149
2156
** "./" to avoid ambiguity.
2150
2157
**
2151
 
** If the filename is an empty string, then a private, temporary
2152
 
** on-disk database will be created.  This private database will be
 
2158
** ^If the filename is an empty string, then a private, temporary
 
2159
** on-disk database will be created.  ^This private database will be
2153
2160
** automatically deleted as soon as the database connection is closed.
2154
2161
**
2155
 
** The fourth parameter to sqlite3_open_v2() is the name of the
 
2162
** ^The fourth parameter to sqlite3_open_v2() is the name of the
2156
2163
** [sqlite3_vfs] object that defines the operating system interface that
2157
 
** the new database connection should use.  If the fourth parameter is
 
2164
** the new database connection should use.  ^If the fourth parameter is
2158
2165
** a NULL pointer then the default [sqlite3_vfs] object is used.
2159
2166
**
2160
2167
** <b>Note to Windows users:</b>  The encoding used for the filename argument
2162
2169
** codepage is currently defined.  Filenames containing international
2163
2170
** characters must be converted to UTF-8 prior to passing them into
2164
2171
** sqlite3_open() or sqlite3_open_v2().
2165
 
**
2166
 
** Requirements:
2167
 
** [H12701] [H12702] [H12703] [H12704] [H12706] [H12707] [H12709] [H12711]
2168
 
** [H12712] [H12713] [H12714] [H12717] [H12719] [H12721] [H12723]
2169
2172
*/
2170
2173
SQLITE_API int sqlite3_open(
2171
2174
  const char *filename,   /* Database filename (UTF-8) */
2183
2186
);
2184
2187
 
2185
2188
/*
2186
 
** CAPI3REF: Error Codes And Messages {H12800} <S60200>
 
2189
** CAPI3REF: Error Codes And Messages
2187
2190
**
2188
 
** The sqlite3_errcode() interface returns the numeric [result code] or
 
2191
** ^The sqlite3_errcode() interface returns the numeric [result code] or
2189
2192
** [extended result code] for the most recent failed sqlite3_* API call
2190
2193
** associated with a [database connection]. If a prior API call failed
2191
2194
** but the most recent API call succeeded, the return value from
2192
 
** sqlite3_errcode() is undefined.  The sqlite3_extended_errcode()
 
2195
** sqlite3_errcode() is undefined.  ^The sqlite3_extended_errcode()
2193
2196
** interface is the same except that it always returns the 
2194
2197
** [extended result code] even when extended result codes are
2195
2198
** disabled.
2196
2199
**
2197
 
** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
 
2200
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
2198
2201
** text that describes the error, as either UTF-8 or UTF-16 respectively.
2199
 
** Memory to hold the error message string is managed internally.
 
2202
** ^(Memory to hold the error message string is managed internally.
2200
2203
** The application does not need to worry about freeing the result.
2201
2204
** However, the error string might be overwritten or deallocated by
2202
 
** subsequent calls to other SQLite interface functions.
 
2205
** subsequent calls to other SQLite interface functions.)^
2203
2206
**
2204
2207
** When the serialized [threading mode] is in use, it might be the
2205
2208
** case that a second error occurs on a separate thread in between
2214
2217
** If an interface fails with SQLITE_MISUSE, that means the interface
2215
2218
** was invoked incorrectly by the application.  In that case, the
2216
2219
** error code and message may or may not be set.
2217
 
**
2218
 
** Requirements:
2219
 
** [H12801] [H12802] [H12803] [H12807] [H12808] [H12809]
2220
2220
*/
2221
2221
SQLITE_API int sqlite3_errcode(sqlite3 *db);
2222
2222
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
2224
2224
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
2225
2225
 
2226
2226
/*
2227
 
** CAPI3REF: SQL Statement Object {H13000} <H13010>
 
2227
** CAPI3REF: SQL Statement Object
2228
2228
** KEYWORDS: {prepared statement} {prepared statements}
2229
2229
**
2230
2230
** An instance of this object represents a single SQL statement.
2250
2250
typedef struct sqlite3_stmt sqlite3_stmt;
2251
2251
 
2252
2252
/*
2253
 
** CAPI3REF: Run-time Limits {H12760} <S20600>
 
2253
** CAPI3REF: Run-time Limits
2254
2254
**
2255
 
** This interface allows the size of various constructs to be limited
 
2255
** ^(This interface allows the size of various constructs to be limited
2256
2256
** on a connection by connection basis.  The first parameter is the
2257
2257
** [database connection] whose limit is to be set or queried.  The
2258
2258
** second parameter is one of the [limit categories] that define a
2259
2259
** class of constructs to be size limited.  The third parameter is the
2260
 
** new limit for that construct.  The function returns the old limit.
 
2260
** new limit for that construct.  The function returns the old limit.)^
2261
2261
**
2262
 
** If the new limit is a negative number, the limit is unchanged.
2263
 
** For the limit category of SQLITE_LIMIT_XYZ there is a 
 
2262
** ^If the new limit is a negative number, the limit is unchanged.
 
2263
** ^(For the limit category of SQLITE_LIMIT_XYZ there is a 
2264
2264
** [limits | hard upper bound]
2265
2265
** set by a compile-time C preprocessor macro named 
2266
2266
** [limits | SQLITE_MAX_XYZ].
2267
 
** (The "_LIMIT_" in the name is changed to "_MAX_".)
2268
 
** Attempts to increase a limit above its hard upper bound are
2269
 
** silently truncated to the hard upper limit.
 
2267
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
 
2268
** ^Attempts to increase a limit above its hard upper bound are
 
2269
** silently truncated to the hard upper bound.
2270
2270
**
2271
 
** Run time limits are intended for use in applications that manage
 
2271
** Run-time limits are intended for use in applications that manage
2272
2272
** both their own internal database and also databases that are controlled
2273
2273
** by untrusted external sources.  An example application might be a
2274
2274
** web browser that has its own databases for storing history and
2282
2282
** [max_page_count] [PRAGMA].
2283
2283
**
2284
2284
** New run-time limit categories may be added in future releases.
2285
 
**
2286
 
** Requirements:
2287
 
** [H12762] [H12766] [H12769]
2288
2285
*/
2289
2286
SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
2290
2287
 
2291
2288
/*
2292
 
** CAPI3REF: Run-Time Limit Categories {H12790} <H12760>
2293
 
** KEYWORDS: {limit category} {limit categories}
 
2289
** CAPI3REF: Run-Time Limit Categories
 
2290
** KEYWORDS: {limit category} {*limit categories}
2294
2291
**
2295
2292
** These constants define various performance limits
2296
2293
** that can be lowered at run-time using [sqlite3_limit()].
2298
2295
** Additional information is available at [limits | Limits in SQLite].
2299
2296
**
2300
2297
** <dl>
2301
 
** <dt>SQLITE_LIMIT_LENGTH</dt>
2302
 
** <dd>The maximum size of any string or BLOB or table row.<dd>
2303
 
**
2304
 
** <dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2305
 
** <dd>The maximum length of an SQL statement.</dd>
2306
 
**
2307
 
** <dt>SQLITE_LIMIT_COLUMN</dt>
 
2298
** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
 
2299
** <dd>The maximum size of any string or BLOB or table row.<dd>)^
 
2300
**
 
2301
** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
 
2302
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
 
2303
**
 
2304
** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
2308
2305
** <dd>The maximum number of columns in a table definition or in the
2309
2306
** result set of a [SELECT] or the maximum number of columns in an index
2310
 
** or in an ORDER BY or GROUP BY clause.</dd>
2311
 
**
2312
 
** <dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
2313
 
** <dd>The maximum depth of the parse tree on any expression.</dd>
2314
 
**
2315
 
** <dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2316
 
** <dd>The maximum number of terms in a compound SELECT statement.</dd>
2317
 
**
2318
 
** <dt>SQLITE_LIMIT_VDBE_OP</dt>
 
2307
** or in an ORDER BY or GROUP BY clause.</dd>)^
 
2308
**
 
2309
** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
 
2310
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
 
2311
**
 
2312
** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
 
2313
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
 
2314
**
 
2315
** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2319
2316
** <dd>The maximum number of instructions in a virtual machine program
2320
 
** used to implement an SQL statement.</dd>
2321
 
**
2322
 
** <dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2323
 
** <dd>The maximum number of arguments on a function.</dd>
2324
 
**
2325
 
** <dt>SQLITE_LIMIT_ATTACHED</dt>
2326
 
** <dd>The maximum number of [ATTACH | attached databases].</dd>
2327
 
**
2328
 
** <dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
 
2317
** used to implement an SQL statement.</dd>)^
 
2318
**
 
2319
** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
 
2320
** <dd>The maximum number of arguments on a function.</dd>)^
 
2321
**
 
2322
** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
 
2323
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
 
2324
**
 
2325
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2329
2326
** <dd>The maximum length of the pattern argument to the [LIKE] or
2330
 
** [GLOB] operators.</dd>
 
2327
** [GLOB] operators.</dd>)^
2331
2328
**
2332
 
** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
 
2329
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2333
2330
** <dd>The maximum number of variables in an SQL statement that can
2334
 
** be bound.</dd>
 
2331
** be bound.</dd>)^
2335
2332
**
2336
 
** <dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2337
 
** <dd>The maximum depth of recursion for triggers.</dd>
 
2333
** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
 
2334
** <dd>The maximum depth of recursion for triggers.</dd>)^
2338
2335
** </dl>
2339
2336
*/
2340
2337
#define SQLITE_LIMIT_LENGTH                    0
2350
2347
#define SQLITE_LIMIT_TRIGGER_DEPTH            10
2351
2348
 
2352
2349
/*
2353
 
** CAPI3REF: Compiling An SQL Statement {H13010} <S10000>
 
2350
** CAPI3REF: Compiling An SQL Statement
2354
2351
** KEYWORDS: {SQL statement compiler}
2355
2352
**
2356
2353
** To execute an SQL query, it must first be compiled into a byte-code
2365
2362
** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
2366
2363
** use UTF-16.
2367
2364
**
2368
 
** If the nByte argument is less than zero, then zSql is read up to the
2369
 
** first zero terminator. If nByte is non-negative, then it is the maximum
2370
 
** number of  bytes read from zSql.  When nByte is non-negative, the
 
2365
** ^If the nByte argument is less than zero, then zSql is read up to the
 
2366
** first zero terminator. ^If nByte is non-negative, then it is the maximum
 
2367
** number of  bytes read from zSql.  ^When nByte is non-negative, the
2371
2368
** zSql string ends at either the first '\000' or '\u0000' character or
2372
2369
** the nByte-th byte, whichever comes first. If the caller knows
2373
2370
** that the supplied string is nul-terminated, then there is a small
2375
2372
** is equal to the number of bytes in the input string <i>including</i>
2376
2373
** the nul-terminator bytes.
2377
2374
**
2378
 
** If pzTail is not NULL then *pzTail is made to point to the first byte
 
2375
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
2379
2376
** past the end of the first SQL statement in zSql.  These routines only
2380
2377
** compile the first statement in zSql, so *pzTail is left pointing to
2381
2378
** what remains uncompiled.
2382
2379
**
2383
 
** *ppStmt is left pointing to a compiled [prepared statement] that can be
2384
 
** executed using [sqlite3_step()].  If there is an error, *ppStmt is set
2385
 
** to NULL.  If the input text contains no SQL (if the input is an empty
 
2380
** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
 
2381
** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
 
2382
** to NULL.  ^If the input text contains no SQL (if the input is an empty
2386
2383
** string or a comment) then *ppStmt is set to NULL.
2387
2384
** The calling procedure is responsible for deleting the compiled
2388
2385
** SQL statement using [sqlite3_finalize()] after it has finished with it.
2389
2386
** ppStmt may not be NULL.
2390
2387
**
2391
 
** On success, [SQLITE_OK] is returned, otherwise an [error code] is returned.
 
2388
** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
 
2389
** otherwise an [error code] is returned.
2392
2390
**
2393
2391
** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
2394
2392
** recommended for all new programs. The two older interfaces are retained
2395
2393
** for backwards compatibility, but their use is discouraged.
2396
 
** In the "v2" interfaces, the prepared statement
 
2394
** ^In the "v2" interfaces, the prepared statement
2397
2395
** that is returned (the [sqlite3_stmt] object) contains a copy of the
2398
2396
** original SQL text. This causes the [sqlite3_step()] interface to
2399
 
** behave a differently in two ways:
 
2397
** behave differently in three ways:
2400
2398
**
2401
2399
** <ol>
2402
2400
** <li>
2403
 
** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
 
2401
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
2404
2402
** always used to do, [sqlite3_step()] will automatically recompile the SQL
2405
 
** statement and try to run it again.  If the schema has changed in
 
2403
** statement and try to run it again.  ^If the schema has changed in
2406
2404
** a way that makes the statement no longer valid, [sqlite3_step()] will still
2407
2405
** return [SQLITE_SCHEMA].  But unlike the legacy behavior, [SQLITE_SCHEMA] is
2408
2406
** now a fatal error.  Calling [sqlite3_prepare_v2()] again will not make the
2411
2409
** </li>
2412
2410
**
2413
2411
** <li>
2414
 
** When an error occurs, [sqlite3_step()] will return one of the detailed
2415
 
** [error codes] or [extended error codes].  The legacy behavior was that
 
2412
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
 
2413
** [error codes] or [extended error codes].  ^The legacy behavior was that
2416
2414
** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
2417
 
** and you would have to make a second call to [sqlite3_reset()] in order
2418
 
** to find the underlying cause of the problem. With the "v2" prepare
 
2415
** and the application would have to make a second call to [sqlite3_reset()]
 
2416
** in order to find the underlying cause of the problem. With the "v2" prepare
2419
2417
** interfaces, the underlying reason for the error is returned immediately.
2420
2418
** </li>
 
2419
**
 
2420
** <li>
 
2421
** ^If the value of a [parameter | host parameter] in the WHERE clause might
 
2422
** change the query plan for a statement, then the statement may be
 
2423
** automatically recompiled (as if there had been a schema change) on the first 
 
2424
** [sqlite3_step()] call following any change to the 
 
2425
** [sqlite3_bind_text | bindings] of the [parameter]. 
 
2426
** </li>
2421
2427
** </ol>
2422
 
**
2423
 
** Requirements:
2424
 
** [H13011] [H13012] [H13013] [H13014] [H13015] [H13016] [H13019] [H13021]
2425
 
**
2426
2428
*/
2427
2429
SQLITE_API int sqlite3_prepare(
2428
2430
  sqlite3 *db,            /* Database handle */
2454
2456
);
2455
2457
 
2456
2458
/*
2457
 
** CAPI3REF: Retrieving Statement SQL {H13100} <H13000>
 
2459
** CAPI3REF: Retrieving Statement SQL
2458
2460
**
2459
 
** This interface can be used to retrieve a saved copy of the original
 
2461
** ^This interface can be used to retrieve a saved copy of the original
2460
2462
** SQL text used to create a [prepared statement] if that statement was
2461
2463
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
2462
 
**
2463
 
** Requirements:
2464
 
** [H13101] [H13102] [H13103]
2465
2464
*/
2466
2465
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
2467
2466
 
2468
2467
/*
2469
 
** CAPI3REF: Dynamically Typed Value Object {H15000} <S20200>
 
2468
** CAPI3REF: Dynamically Typed Value Object
2470
2469
** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
2471
2470
**
2472
2471
** SQLite uses the sqlite3_value object to represent all values
2473
2472
** that can be stored in a database table. SQLite uses dynamic typing
2474
 
** for the values it stores. Values stored in sqlite3_value objects
 
2473
** for the values it stores.  ^Values stored in sqlite3_value objects
2475
2474
** can be integers, floating point values, strings, BLOBs, or NULL.
2476
2475
**
2477
2476
** An sqlite3_value object may be either "protected" or "unprotected".
2493
2492
** still make the distinction between between protected and unprotected
2494
2493
** sqlite3_value objects even when not strictly required.
2495
2494
**
2496
 
** The sqlite3_value objects that are passed as parameters into the
 
2495
** ^The sqlite3_value objects that are passed as parameters into the
2497
2496
** implementation of [application-defined SQL functions] are protected.
2498
 
** The sqlite3_value object returned by
 
2497
** ^The sqlite3_value object returned by
2499
2498
** [sqlite3_column_value()] is unprotected.
2500
2499
** Unprotected sqlite3_value objects may only be used with
2501
2500
** [sqlite3_result_value()] and [sqlite3_bind_value()].
2505
2504
typedef struct Mem sqlite3_value;
2506
2505
 
2507
2506
/*
2508
 
** CAPI3REF: SQL Function Context Object {H16001} <S20200>
 
2507
** CAPI3REF: SQL Function Context Object
2509
2508
**
2510
2509
** The context in which an SQL function executes is stored in an
2511
 
** sqlite3_context object.  A pointer to an sqlite3_context object
 
2510
** sqlite3_context object.  ^A pointer to an sqlite3_context object
2512
2511
** is always first parameter to [application-defined SQL functions].
2513
2512
** The application-defined SQL function implementation will pass this
2514
2513
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
2519
2518
typedef struct sqlite3_context sqlite3_context;
2520
2519
 
2521
2520
/*
2522
 
** CAPI3REF: Binding Values To Prepared Statements {H13500} <S70300>
 
2521
** CAPI3REF: Binding Values To Prepared Statements
2523
2522
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
2524
2523
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
2525
2524
**
2526
 
** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
 
2525
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
2527
2526
** literals may be replaced by a [parameter] that matches one of following
2528
2527
** templates:
2529
2528
**
2536
2535
** </ul>
2537
2536
**
2538
2537
** In the templates above, NNN represents an integer literal,
2539
 
** and VVV represents an alphanumeric identifer.  The values of these
 
2538
** and VVV represents an alphanumeric identifer.)^  ^The values of these
2540
2539
** parameters (also called "host parameter names" or "SQL parameters")
2541
2540
** can be set using the sqlite3_bind_*() routines defined here.
2542
2541
**
2543
 
** The first argument to the sqlite3_bind_*() routines is always
 
2542
** ^The first argument to the sqlite3_bind_*() routines is always
2544
2543
** a pointer to the [sqlite3_stmt] object returned from
2545
2544
** [sqlite3_prepare_v2()] or its variants.
2546
2545
**
2547
 
** The second argument is the index of the SQL parameter to be set.
2548
 
** The leftmost SQL parameter has an index of 1.  When the same named
 
2546
** ^The second argument is the index of the SQL parameter to be set.
 
2547
** ^The leftmost SQL parameter has an index of 1.  ^When the same named
2549
2548
** SQL parameter is used more than once, second and subsequent
2550
2549
** occurrences have the same index as the first occurrence.
2551
 
** The index for named parameters can be looked up using the
2552
 
** [sqlite3_bind_parameter_index()] API if desired.  The index
 
2550
** ^The index for named parameters can be looked up using the
 
2551
** [sqlite3_bind_parameter_index()] API if desired.  ^The index
2553
2552
** for "?NNN" parameters is the value of NNN.
2554
 
** The NNN value must be between 1 and the [sqlite3_limit()]
 
2553
** ^The NNN value must be between 1 and the [sqlite3_limit()]
2555
2554
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
2556
2555
**
2557
 
** The third argument is the value to bind to the parameter.
 
2556
** ^The third argument is the value to bind to the parameter.
2558
2557
**
2559
 
** In those routines that have a fourth argument, its value is the
 
2558
** ^(In those routines that have a fourth argument, its value is the
2560
2559
** number of bytes in the parameter.  To be clear: the value is the
2561
 
** number of <u>bytes</u> in the value, not the number of characters.
2562
 
** If the fourth parameter is negative, the length of the string is
 
2560
** number of <u>bytes</u> in the value, not the number of characters.)^
 
2561
** ^If the fourth parameter is negative, the length of the string is
2563
2562
** the number of bytes up to the first zero terminator.
2564
2563
**
2565
 
** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
 
2564
** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
2566
2565
** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
2567
 
** string after SQLite has finished with it. If the fifth argument is
 
2566
** string after SQLite has finished with it. ^If the fifth argument is
2568
2567
** the special value [SQLITE_STATIC], then SQLite assumes that the
2569
2568
** information is in static, unmanaged space and does not need to be freed.
2570
 
** If the fifth argument has the value [SQLITE_TRANSIENT], then
 
2569
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
2571
2570
** SQLite makes its own private copy of the data immediately, before
2572
2571
** the sqlite3_bind_*() routine returns.
2573
2572
**
2574
 
** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
2575
 
** is filled with zeroes.  A zeroblob uses a fixed amount of memory
 
2573
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
 
2574
** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
2576
2575
** (just an integer to hold its size) while it is being processed.
2577
2576
** Zeroblobs are intended to serve as placeholders for BLOBs whose
2578
2577
** content is later written using
2579
2578
** [sqlite3_blob_open | incremental BLOB I/O] routines.
2580
 
** A negative value for the zeroblob results in a zero-length BLOB.
2581
 
**
2582
 
** The sqlite3_bind_*() routines must be called after
2583
 
** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
2584
 
** before [sqlite3_step()].
2585
 
** Bindings are not cleared by the [sqlite3_reset()] routine.
2586
 
** Unbound parameters are interpreted as NULL.
2587
 
**
2588
 
** These routines return [SQLITE_OK] on success or an error code if
2589
 
** anything goes wrong.  [SQLITE_RANGE] is returned if the parameter
2590
 
** index is out of range.  [SQLITE_NOMEM] is returned if malloc() fails.
2591
 
** [SQLITE_MISUSE] might be returned if these routines are called on a
2592
 
** virtual machine that is the wrong state or which has already been finalized.
2593
 
** Detection of misuse is unreliable.  Applications should not depend
2594
 
** on SQLITE_MISUSE returns.  SQLITE_MISUSE is intended to indicate a
2595
 
** a logic error in the application.  Future versions of SQLite might
2596
 
** panic rather than return SQLITE_MISUSE.
 
2579
** ^A negative value for the zeroblob results in a zero-length BLOB.
 
2580
**
 
2581
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
 
2582
** for the [prepared statement] or with a prepared statement for which
 
2583
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
 
2584
** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
 
2585
** routine is passed a [prepared statement] that has been finalized, the
 
2586
** result is undefined and probably harmful.
 
2587
**
 
2588
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
 
2589
** ^Unbound parameters are interpreted as NULL.
 
2590
**
 
2591
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
 
2592
** [error code] if anything goes wrong.
 
2593
** ^[SQLITE_RANGE] is returned if the parameter
 
2594
** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
2597
2595
**
2598
2596
** See also: [sqlite3_bind_parameter_count()],
2599
2597
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
2600
 
**
2601
 
** Requirements:
2602
 
** [H13506] [H13509] [H13512] [H13515] [H13518] [H13521] [H13524] [H13527]
2603
 
** [H13530] [H13533] [H13536] [H13539] [H13542] [H13545] [H13548] [H13551]
2604
 
**
2605
2598
*/
2606
2599
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
2607
2600
SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
2614
2607
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
2615
2608
 
2616
2609
/*
2617
 
** CAPI3REF: Number Of SQL Parameters {H13600} <S70300>
 
2610
** CAPI3REF: Number Of SQL Parameters
2618
2611
**
2619
 
** This routine can be used to find the number of [SQL parameters]
 
2612
** ^This routine can be used to find the number of [SQL parameters]
2620
2613
** in a [prepared statement].  SQL parameters are tokens of the
2621
2614
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
2622
2615
** placeholders for values that are [sqlite3_bind_blob | bound]
2623
2616
** to the parameters at a later time.
2624
2617
**
2625
 
** This routine actually returns the index of the largest (rightmost)
 
2618
** ^(This routine actually returns the index of the largest (rightmost)
2626
2619
** parameter. For all forms except ?NNN, this will correspond to the
2627
 
** number of unique parameters.  If parameters of the ?NNN are used,
2628
 
** there may be gaps in the list.
 
2620
** number of unique parameters.  If parameters of the ?NNN form are used,
 
2621
** there may be gaps in the list.)^
2629
2622
**
2630
2623
** See also: [sqlite3_bind_blob|sqlite3_bind()],
2631
2624
** [sqlite3_bind_parameter_name()], and
2632
2625
** [sqlite3_bind_parameter_index()].
2633
 
**
2634
 
** Requirements:
2635
 
** [H13601]
2636
2626
*/
2637
2627
SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
2638
2628
 
2639
2629
/*
2640
 
** CAPI3REF: Name Of A Host Parameter {H13620} <S70300>
 
2630
** CAPI3REF: Name Of A Host Parameter
2641
2631
**
2642
 
** This routine returns a pointer to the name of the n-th
2643
 
** [SQL parameter] in a [prepared statement].
2644
 
** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
 
2632
** ^The sqlite3_bind_parameter_name(P,N) interface returns
 
2633
** the name of the N-th [SQL parameter] in the [prepared statement] P.
 
2634
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
2645
2635
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
2646
2636
** respectively.
2647
2637
** In other words, the initial ":" or "$" or "@" or "?"
2648
 
** is included as part of the name.
2649
 
** Parameters of the form "?" without a following integer have no name
2650
 
** and are also referred to as "anonymous parameters".
2651
 
**
2652
 
** The first host parameter has an index of 1, not 0.
2653
 
**
2654
 
** If the value n is out of range or if the n-th parameter is
2655
 
** nameless, then NULL is returned.  The returned string is
 
2638
** is included as part of the name.)^
 
2639
** ^Parameters of the form "?" without a following integer have no name
 
2640
** and are referred to as "nameless" or "anonymous parameters".
 
2641
**
 
2642
** ^The first host parameter has an index of 1, not 0.
 
2643
**
 
2644
** ^If the value N is out of range or if the N-th parameter is
 
2645
** nameless, then NULL is returned.  ^The returned string is
2656
2646
** always in UTF-8 encoding even if the named parameter was
2657
2647
** originally specified as UTF-16 in [sqlite3_prepare16()] or
2658
2648
** [sqlite3_prepare16_v2()].
2660
2650
** See also: [sqlite3_bind_blob|sqlite3_bind()],
2661
2651
** [sqlite3_bind_parameter_count()], and
2662
2652
** [sqlite3_bind_parameter_index()].
2663
 
**
2664
 
** Requirements:
2665
 
** [H13621]
2666
2653
*/
2667
2654
SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
2668
2655
 
2669
2656
/*
2670
 
** CAPI3REF: Index Of A Parameter With A Given Name {H13640} <S70300>
 
2657
** CAPI3REF: Index Of A Parameter With A Given Name
2671
2658
**
2672
 
** Return the index of an SQL parameter given its name.  The
 
2659
** ^Return the index of an SQL parameter given its name.  ^The
2673
2660
** index value returned is suitable for use as the second
2674
 
** parameter to [sqlite3_bind_blob|sqlite3_bind()].  A zero
2675
 
** is returned if no matching parameter is found.  The parameter
 
2661
** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
 
2662
** is returned if no matching parameter is found.  ^The parameter
2676
2663
** name must be given in UTF-8 even if the original statement
2677
2664
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
2678
2665
**
2679
2666
** See also: [sqlite3_bind_blob|sqlite3_bind()],
2680
2667
** [sqlite3_bind_parameter_count()], and
2681
2668
** [sqlite3_bind_parameter_index()].
2682
 
**
2683
 
** Requirements:
2684
 
** [H13641]
2685
2669
*/
2686
2670
SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
2687
2671
 
2688
2672
/*
2689
 
** CAPI3REF: Reset All Bindings On A Prepared Statement {H13660} <S70300>
 
2673
** CAPI3REF: Reset All Bindings On A Prepared Statement
2690
2674
**
2691
 
** Contrary to the intuition of many, [sqlite3_reset()] does not reset
 
2675
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
2692
2676
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
2693
 
** Use this routine to reset all host parameters to NULL.
2694
 
**
2695
 
** Requirements:
2696
 
** [H13661]
 
2677
** ^Use this routine to reset all host parameters to NULL.
2697
2678
*/
2698
2679
SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
2699
2680
 
2700
2681
/*
2701
 
** CAPI3REF: Number Of Columns In A Result Set {H13710} <S10700>
 
2682
** CAPI3REF: Number Of Columns In A Result Set
2702
2683
**
2703
 
** Return the number of columns in the result set returned by the
2704
 
** [prepared statement]. This routine returns 0 if pStmt is an SQL
 
2684
** ^Return the number of columns in the result set returned by the
 
2685
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
2705
2686
** statement that does not return data (for example an [UPDATE]).
2706
 
**
2707
 
** Requirements:
2708
 
** [H13711]
2709
2687
*/
2710
2688
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
2711
2689
 
2712
2690
/*
2713
 
** CAPI3REF: Column Names In A Result Set {H13720} <S10700>
 
2691
** CAPI3REF: Column Names In A Result Set
2714
2692
**
2715
 
** These routines return the name assigned to a particular column
2716
 
** in the result set of a [SELECT] statement.  The sqlite3_column_name()
 
2693
** ^These routines return the name assigned to a particular column
 
2694
** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
2717
2695
** interface returns a pointer to a zero-terminated UTF-8 string
2718
2696
** and sqlite3_column_name16() returns a pointer to a zero-terminated
2719
 
** UTF-16 string.  The first parameter is the [prepared statement]
2720
 
** that implements the [SELECT] statement. The second parameter is the
2721
 
** column number.  The leftmost column is number 0.
 
2697
** UTF-16 string.  ^The first parameter is the [prepared statement]
 
2698
** that implements the [SELECT] statement. ^The second parameter is the
 
2699
** column number.  ^The leftmost column is number 0.
2722
2700
**
2723
 
** The returned string pointer is valid until either the [prepared statement]
 
2701
** ^The returned string pointer is valid until either the [prepared statement]
2724
2702
** is destroyed by [sqlite3_finalize()] or until the next call to
2725
2703
** sqlite3_column_name() or sqlite3_column_name16() on the same column.
2726
2704
**
2727
 
** If sqlite3_malloc() fails during the processing of either routine
 
2705
** ^If sqlite3_malloc() fails during the processing of either routine
2728
2706
** (for example during a conversion from UTF-8 to UTF-16) then a
2729
2707
** NULL pointer is returned.
2730
2708
**
2731
 
** The name of a result column is the value of the "AS" clause for
 
2709
** ^The name of a result column is the value of the "AS" clause for
2732
2710
** that column, if there is an AS clause.  If there is no AS clause
2733
2711
** then the name of the column is unspecified and may change from
2734
2712
** one release of SQLite to the next.
2735
 
**
2736
 
** Requirements:
2737
 
** [H13721] [H13723] [H13724] [H13725] [H13726] [H13727]
2738
2713
*/
2739
2714
SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
2740
2715
SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
2741
2716
 
2742
2717
/*
2743
 
** CAPI3REF: Source Of Data In A Query Result {H13740} <S10700>
 
2718
** CAPI3REF: Source Of Data In A Query Result
2744
2719
**
2745
 
** These routines provide a means to determine what column of what
2746
 
** table in which database a result of a [SELECT] statement comes from.
2747
 
** The name of the database or table or column can be returned as
2748
 
** either a UTF-8 or UTF-16 string.  The _database_ routines return
 
2720
** ^These routines provide a means to determine the database, table, and
 
2721
** table column that is the origin of a particular result column in
 
2722
** [SELECT] statement.
 
2723
** ^The name of the database or table or column can be returned as
 
2724
** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
2749
2725
** the database name, the _table_ routines return the table name, and
2750
2726
** the origin_ routines return the column name.
2751
 
** The returned string is valid until the [prepared statement] is destroyed
 
2727
** ^The returned string is valid until the [prepared statement] is destroyed
2752
2728
** using [sqlite3_finalize()] or until the same information is requested
2753
2729
** again in a different encoding.
2754
2730
**
2755
 
** The names returned are the original un-aliased names of the
 
2731
** ^The names returned are the original un-aliased names of the
2756
2732
** database, table, and column.
2757
2733
**
2758
 
** The first argument to the following calls is a [prepared statement].
2759
 
** These functions return information about the Nth column returned by
 
2734
** ^The first argument to these interfaces is a [prepared statement].
 
2735
** ^These functions return information about the Nth result column returned by
2760
2736
** the statement, where N is the second function argument.
 
2737
** ^The left-most column is column 0 for these routines.
2761
2738
**
2762
 
** If the Nth column returned by the statement is an expression or
 
2739
** ^If the Nth column returned by the statement is an expression or
2763
2740
** subquery and is not a column value, then all of these functions return
2764
 
** NULL.  These routine might also return NULL if a memory allocation error
2765
 
** occurs.  Otherwise, they return the name of the attached database, table
2766
 
** and column that query result column was extracted from.
2767
 
**
2768
 
** As with all other SQLite APIs, those postfixed with "16" return
2769
 
** UTF-16 encoded strings, the other functions return UTF-8. {END}
2770
 
**
2771
 
** These APIs are only available if the library was compiled with the
2772
 
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
2773
 
**
2774
 
** {A13751}
 
2741
** NULL.  ^These routine might also return NULL if a memory allocation error
 
2742
** occurs.  ^Otherwise, they return the name of the attached database, table,
 
2743
** or column that query result column was extracted from.
 
2744
**
 
2745
** ^As with all other SQLite APIs, those whose names end with "16" return
 
2746
** UTF-16 encoded strings and the other functions return UTF-8.
 
2747
**
 
2748
** ^These APIs are only available if the library was compiled with the
 
2749
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
 
2750
**
2775
2751
** If two or more threads call one or more of these routines against the same
2776
2752
** prepared statement and column at the same time then the results are
2777
2753
** undefined.
2778
2754
**
2779
 
** Requirements:
2780
 
** [H13741] [H13742] [H13743] [H13744] [H13745] [H13746] [H13748]
2781
 
**
2782
2755
** If two or more threads call one or more
2783
2756
** [sqlite3_column_database_name | column metadata interfaces]
2784
2757
** for the same [prepared statement] and result column
2792
2765
SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
2793
2766
 
2794
2767
/*
2795
 
** CAPI3REF: Declared Datatype Of A Query Result {H13760} <S10700>
 
2768
** CAPI3REF: Declared Datatype Of A Query Result
2796
2769
**
2797
 
** The first parameter is a [prepared statement].
 
2770
** ^(The first parameter is a [prepared statement].
2798
2771
** If this statement is a [SELECT] statement and the Nth column of the
2799
2772
** returned result set of that [SELECT] is a table column (not an
2800
2773
** expression or subquery) then the declared type of the table
2801
 
** column is returned.  If the Nth column of the result set is an
 
2774
** column is returned.)^  ^If the Nth column of the result set is an
2802
2775
** expression or subquery, then a NULL pointer is returned.
2803
 
** The returned string is always UTF-8 encoded. {END}
 
2776
** ^The returned string is always UTF-8 encoded.
2804
2777
**
2805
 
** For example, given the database schema:
 
2778
** ^(For example, given the database schema:
2806
2779
**
2807
2780
** CREATE TABLE t1(c1 VARIANT);
2808
2781
**
2811
2784
** SELECT c1 + 1, c1 FROM t1;
2812
2785
**
2813
2786
** this routine would return the string "VARIANT" for the second result
2814
 
** column (i==1), and a NULL pointer for the first result column (i==0).
 
2787
** column (i==1), and a NULL pointer for the first result column (i==0).)^
2815
2788
**
2816
 
** SQLite uses dynamic run-time typing.  So just because a column
 
2789
** ^SQLite uses dynamic run-time typing.  ^So just because a column
2817
2790
** is declared to contain a particular type does not mean that the
2818
2791
** data stored in that column is of the declared type.  SQLite is
2819
 
** strongly typed, but the typing is dynamic not static.  Type
 
2792
** strongly typed, but the typing is dynamic not static.  ^Type
2820
2793
** is associated with individual values, not with the containers
2821
2794
** used to hold those values.
2822
 
**
2823
 
** Requirements:
2824
 
** [H13761] [H13762] [H13763]
2825
2795
*/
2826
2796
SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
2827
2797
SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
2828
2798
 
2829
2799
/*
2830
 
** CAPI3REF: Evaluate An SQL Statement {H13200} <S10000>
 
2800
** CAPI3REF: Evaluate An SQL Statement
2831
2801
**
2832
2802
** After a [prepared statement] has been prepared using either
2833
2803
** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
2841
2811
** new "v2" interface is recommended for new applications but the legacy
2842
2812
** interface will continue to be supported.
2843
2813
**
2844
 
** In the legacy interface, the return value will be either [SQLITE_BUSY],
 
2814
** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
2845
2815
** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
2846
 
** With the "v2" interface, any of the other [result codes] or
 
2816
** ^With the "v2" interface, any of the other [result codes] or
2847
2817
** [extended result codes] might be returned as well.
2848
2818
**
2849
 
** [SQLITE_BUSY] means that the database engine was unable to acquire the
2850
 
** database locks it needs to do its job.  If the statement is a [COMMIT]
 
2819
** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
 
2820
** database locks it needs to do its job.  ^If the statement is a [COMMIT]
2851
2821
** or occurs outside of an explicit transaction, then you can retry the
2852
2822
** statement.  If the statement is not a [COMMIT] and occurs within a
2853
2823
** explicit transaction then you should rollback the transaction before
2854
2824
** continuing.
2855
2825
**
2856
 
** [SQLITE_DONE] means that the statement has finished executing
 
2826
** ^[SQLITE_DONE] means that the statement has finished executing
2857
2827
** successfully.  sqlite3_step() should not be called again on this virtual
2858
2828
** machine without first calling [sqlite3_reset()] to reset the virtual
2859
2829
** machine back to its initial state.
2860
2830
**
2861
 
** If the SQL statement being executed returns any data, then [SQLITE_ROW]
 
2831
** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
2862
2832
** is returned each time a new row of data is ready for processing by the
2863
2833
** caller. The values may be accessed using the [column access functions].
2864
2834
** sqlite3_step() is called again to retrieve the next row of data.
2865
2835
**
2866
 
** [SQLITE_ERROR] means that a run-time error (such as a constraint
 
2836
** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
2867
2837
** violation) has occurred.  sqlite3_step() should not be called again on
2868
2838
** the VM. More information may be found by calling [sqlite3_errmsg()].
2869
 
** With the legacy interface, a more specific error code (for example,
 
2839
** ^With the legacy interface, a more specific error code (for example,
2870
2840
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
2871
2841
** can be obtained by calling [sqlite3_reset()] on the
2872
 
** [prepared statement].  In the "v2" interface,
 
2842
** [prepared statement].  ^In the "v2" interface,
2873
2843
** the more specific error code is returned directly by sqlite3_step().
2874
2844
**
2875
2845
** [SQLITE_MISUSE] means that the this routine was called inappropriately.
2890
2860
** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
2891
2861
** then the more specific [error codes] are returned directly
2892
2862
** by sqlite3_step().  The use of the "v2" interface is recommended.
2893
 
**
2894
 
** Requirements:
2895
 
** [H13202] [H15304] [H15306] [H15308] [H15310]
2896
2863
*/
2897
2864
SQLITE_API int sqlite3_step(sqlite3_stmt*);
2898
2865
 
2899
2866
/*
2900
 
** CAPI3REF: Number of columns in a result set {H13770} <S10700>
2901
 
**
2902
 
** Returns the number of values in the current row of the result set.
2903
 
**
2904
 
** Requirements:
2905
 
** [H13771] [H13772]
 
2867
** CAPI3REF: Number of columns in a result set
 
2868
**
 
2869
** ^The sqlite3_data_count(P) the number of columns in the
 
2870
** of the result set of [prepared statement] P.
2906
2871
*/
2907
2872
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
2908
2873
 
2909
2874
/*
2910
 
** CAPI3REF: Fundamental Datatypes {H10265} <S10110><S10120>
 
2875
** CAPI3REF: Fundamental Datatypes
2911
2876
** KEYWORDS: SQLITE_TEXT
2912
2877
**
2913
 
** {H10266} Every value in SQLite has one of five fundamental datatypes:
 
2878
** ^(Every value in SQLite has one of five fundamental datatypes:
2914
2879
**
2915
2880
** <ul>
2916
2881
** <li> 64-bit signed integer
2918
2883
** <li> string
2919
2884
** <li> BLOB
2920
2885
** <li> NULL
2921
 
** </ul> {END}
 
2886
** </ul>)^
2922
2887
**
2923
2888
** These constants are codes for each of those types.
2924
2889
**
2939
2904
#define SQLITE3_TEXT     3
2940
2905
 
2941
2906
/*
2942
 
** CAPI3REF: Result Values From A Query {H13800} <S10700>
 
2907
** CAPI3REF: Result Values From A Query
2943
2908
** KEYWORDS: {column access functions}
2944
2909
**
2945
 
** These routines form the "result set query" interface.
 
2910
** These routines form the "result set" interface.
2946
2911
**
2947
 
** These routines return information about a single column of the current
2948
 
** result row of a query.  In every case the first argument is a pointer
 
2912
** ^These routines return information about a single column of the current
 
2913
** result row of a query.  ^In every case the first argument is a pointer
2949
2914
** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
2950
2915
** that was returned from [sqlite3_prepare_v2()] or one of its variants)
2951
2916
** and the second argument is the index of the column for which information
2952
 
** should be returned.  The leftmost column of the result set has the index 0.
 
2917
** should be returned. ^The leftmost column of the result set has the index 0.
 
2918
** ^The number of columns in the result can be determined using
 
2919
** [sqlite3_column_count()].
2953
2920
**
2954
2921
** If the SQL statement does not currently point to a valid row, or if the
2955
2922
** column index is out of range, the result is undefined.
2963
2930
** are called from a different thread while any of these routines
2964
2931
** are pending, then the results are undefined.
2965
2932
**
2966
 
** The sqlite3_column_type() routine returns the
 
2933
** ^The sqlite3_column_type() routine returns the
2967
2934
** [SQLITE_INTEGER | datatype code] for the initial data type
2968
 
** of the result column.  The returned value is one of [SQLITE_INTEGER],
 
2935
** of the result column.  ^The returned value is one of [SQLITE_INTEGER],
2969
2936
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
2970
2937
** returned by sqlite3_column_type() is only meaningful if no type
2971
2938
** conversions have occurred as described below.  After a type conversion,
2973
2940
** versions of SQLite may change the behavior of sqlite3_column_type()
2974
2941
** following a type conversion.
2975
2942
**
2976
 
** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
 
2943
** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
2977
2944
** routine returns the number of bytes in that BLOB or string.
2978
 
** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
 
2945
** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
2979
2946
** the string to UTF-8 and then returns the number of bytes.
2980
 
** If the result is a numeric value then sqlite3_column_bytes() uses
 
2947
** ^If the result is a numeric value then sqlite3_column_bytes() uses
2981
2948
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
2982
2949
** the number of bytes in that string.
2983
 
** The value returned does not include the zero terminator at the end
2984
 
** of the string.  For clarity: the value returned is the number of
 
2950
** ^The value returned does not include the zero terminator at the end
 
2951
** of the string.  ^For clarity: the value returned is the number of
2985
2952
** bytes in the string, not the number of characters.
2986
2953
**
2987
 
** Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
2988
 
** even empty strings, are always zero terminated.  The return
 
2954
** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
 
2955
** even empty strings, are always zero terminated.  ^The return
2989
2956
** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
2990
2957
** pointer, possibly even a NULL pointer.
2991
2958
**
2992
 
** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
 
2959
** ^The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
2993
2960
** but leaves the result in UTF-16 in native byte order instead of UTF-8.
2994
 
** The zero terminator is not included in this count.
 
2961
** ^The zero terminator is not included in this count.
2995
2962
**
2996
 
** The object returned by [sqlite3_column_value()] is an
 
2963
** ^The object returned by [sqlite3_column_value()] is an
2997
2964
** [unprotected sqlite3_value] object.  An unprotected sqlite3_value object
2998
2965
** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
2999
2966
** If the [unprotected sqlite3_value] object returned by
3001
2968
** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
3002
2969
** or [sqlite3_value_bytes()], then the behavior is undefined.
3003
2970
**
3004
 
** These routines attempt to convert the value where appropriate.  For
 
2971
** These routines attempt to convert the value where appropriate.  ^For
3005
2972
** example, if the internal representation is FLOAT and a text result
3006
2973
** is requested, [sqlite3_snprintf()] is used internally to perform the
3007
 
** conversion automatically.  The following table details the conversions
 
2974
** conversion automatically.  ^(The following table details the conversions
3008
2975
** that are applied:
3009
2976
**
3010
2977
** <blockquote>
3028
2995
** <tr><td>  BLOB    <td>  FLOAT    <td> Convert to TEXT then use atof()
3029
2996
** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
3030
2997
** </table>
3031
 
** </blockquote>
 
2998
** </blockquote>)^
3032
2999
**
3033
3000
** The table above makes reference to standard C library functions atoi()
3034
3001
** and atof().  SQLite does not really use these functions.  It has its
3036
3003
** used in the table for brevity and because they are familiar to most
3037
3004
** C programmers.
3038
3005
**
3039
 
** Note that when type conversions occur, pointers returned by prior
 
3006
** ^Note that when type conversions occur, pointers returned by prior
3040
3007
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
3041
3008
** sqlite3_column_text16() may be invalidated.
3042
 
** Type conversions and pointer invalidations might occur
 
3009
** ^(Type conversions and pointer invalidations might occur
3043
3010
** in the following cases:
3044
3011
**
3045
3012
** <ul>
3052
3019
** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
3053
3020
**      sqlite3_column_text() is called.  The content must be converted
3054
3021
**      to UTF-8.</li>
3055
 
** </ul>
 
3022
** </ul>)^
3056
3023
**
3057
 
** Conversions between UTF-16be and UTF-16le are always done in place and do
 
3024
** ^Conversions between UTF-16be and UTF-16le are always done in place and do
3058
3025
** not invalidate a prior pointer, though of course the content of the buffer
3059
3026
** that the prior pointer points to will have been modified.  Other kinds
3060
3027
** of conversion are done in place when it is possible, but sometimes they
3061
3028
** are not possible and in those cases prior pointers are invalidated.
3062
3029
**
3063
 
** The safest and easiest to remember policy is to invoke these routines
 
3030
** ^(The safest and easiest to remember policy is to invoke these routines
3064
3031
** in one of the following ways:
3065
3032
**
3066
3033
** <ul>
3067
3034
**  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
3068
3035
**  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
3069
3036
**  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3070
 
** </ul>
 
3037
** </ul>)^
3071
3038
**
3072
3039
** In other words, you should call sqlite3_column_text(),
3073
3040
** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
3077
3044
** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
3078
3045
** with calls to sqlite3_column_bytes().
3079
3046
**
3080
 
** The pointers returned are valid until a type conversion occurs as
 
3047
** ^The pointers returned are valid until a type conversion occurs as
3081
3048
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3082
 
** [sqlite3_finalize()] is called.  The memory space used to hold strings
 
3049
** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
3083
3050
** and BLOBs is freed automatically.  Do <b>not</b> pass the pointers returned
3084
3051
** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3085
3052
** [sqlite3_free()].
3086
3053
**
3087
 
** If a memory allocation error occurs during the evaluation of any
 
3054
** ^(If a memory allocation error occurs during the evaluation of any
3088
3055
** of these routines, a default value is returned.  The default value
3089
3056
** is either the integer 0, the floating point number 0.0, or a NULL
3090
3057
** pointer.  Subsequent calls to [sqlite3_errcode()] will return
3091
 
** [SQLITE_NOMEM].
3092
 
**
3093
 
** Requirements:
3094
 
** [H13803] [H13806] [H13809] [H13812] [H13815] [H13818] [H13821] [H13824]
3095
 
** [H13827] [H13830]
 
3058
** [SQLITE_NOMEM].)^
3096
3059
*/
3097
3060
SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
3098
3061
SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
3106
3069
SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
3107
3070
 
3108
3071
/*
3109
 
** CAPI3REF: Destroy A Prepared Statement Object {H13300} <S70300><S30100>
 
3072
** CAPI3REF: Destroy A Prepared Statement Object
3110
3073
**
3111
 
** The sqlite3_finalize() function is called to delete a [prepared statement].
3112
 
** If the statement was executed successfully or not executed at all, then
3113
 
** SQLITE_OK is returned. If execution of the statement failed then an
 
3074
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
 
3075
** ^If the statement was executed successfully or not executed at all, then
 
3076
** SQLITE_OK is returned. ^If execution of the statement failed then an
3114
3077
** [error code] or [extended error code] is returned.
3115
3078
**
3116
 
** This routine can be called at any point during the execution of the
3117
 
** [prepared statement].  If the virtual machine has not
 
3079
** ^This routine can be called at any point during the execution of the
 
3080
** [prepared statement].  ^If the virtual machine has not
3118
3081
** completed execution when this routine is called, that is like
3119
3082
** encountering an error or an [sqlite3_interrupt | interrupt].
3120
 
** Incomplete updates may be rolled back and transactions canceled,
 
3083
** ^Incomplete updates may be rolled back and transactions canceled,
3121
3084
** depending on the circumstances, and the
3122
3085
** [error code] returned will be [SQLITE_ABORT].
3123
 
**
3124
 
** Requirements:
3125
 
** [H11302] [H11304]
3126
3086
*/
3127
3087
SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
3128
3088
 
3129
3089
/*
3130
 
** CAPI3REF: Reset A Prepared Statement Object {H13330} <S70300>
 
3090
** CAPI3REF: Reset A Prepared Statement Object
3131
3091
**
3132
3092
** The sqlite3_reset() function is called to reset a [prepared statement]
3133
3093
** object back to its initial state, ready to be re-executed.
3134
 
** Any SQL statement variables that had values bound to them using
 
3094
** ^Any SQL statement variables that had values bound to them using
3135
3095
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
3136
3096
** Use [sqlite3_clear_bindings()] to reset the bindings.
3137
3097
**
3138
 
** {H11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S
3139
 
**          back to the beginning of its program.
3140
 
**
3141
 
** {H11334} If the most recent call to [sqlite3_step(S)] for the
3142
 
**          [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
3143
 
**          or if [sqlite3_step(S)] has never before been called on S,
3144
 
**          then [sqlite3_reset(S)] returns [SQLITE_OK].
3145
 
**
3146
 
** {H11336} If the most recent call to [sqlite3_step(S)] for the
3147
 
**          [prepared statement] S indicated an error, then
3148
 
**          [sqlite3_reset(S)] returns an appropriate [error code].
3149
 
**
3150
 
** {H11338} The [sqlite3_reset(S)] interface does not change the values
3151
 
**          of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
 
3098
** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
 
3099
** back to the beginning of its program.
 
3100
**
 
3101
** ^If the most recent call to [sqlite3_step(S)] for the
 
3102
** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
 
3103
** or if [sqlite3_step(S)] has never before been called on S,
 
3104
** then [sqlite3_reset(S)] returns [SQLITE_OK].
 
3105
**
 
3106
** ^If the most recent call to [sqlite3_step(S)] for the
 
3107
** [prepared statement] S indicated an error, then
 
3108
** [sqlite3_reset(S)] returns an appropriate [error code].
 
3109
**
 
3110
** ^The [sqlite3_reset(S)] interface does not change the values
 
3111
** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
3152
3112
*/
3153
3113
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
3154
3114
 
3155
3115
/*
3156
 
** CAPI3REF: Create Or Redefine SQL Functions {H16100} <S20200>
 
3116
** CAPI3REF: Create Or Redefine SQL Functions
3157
3117
** KEYWORDS: {function creation routines}
3158
3118
** KEYWORDS: {application-defined SQL function}
3159
3119
** KEYWORDS: {application-defined SQL functions}
3160
3120
**
3161
 
** These two functions (collectively known as "function creation routines")
 
3121
** ^These two functions (collectively known as "function creation routines")
3162
3122
** are used to add SQL functions or aggregates or to redefine the behavior
3163
3123
** of existing SQL functions or aggregates.  The only difference between the
3164
3124
** two is that the second parameter, the name of the (scalar) function or
3165
3125
** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
3166
3126
** for sqlite3_create_function16().
3167
3127
**
3168
 
** The first parameter is the [database connection] to which the SQL
3169
 
** function is to be added.  If a single program uses more than one database
3170
 
** connection internally, then SQL functions must be added individually to
3171
 
** each database connection.
 
3128
** ^The first parameter is the [database connection] to which the SQL
 
3129
** function is to be added.  ^If an application uses more than one database
 
3130
** connection then application-defined SQL functions must be added
 
3131
** to each database connection separately.
3172
3132
**
3173
3133
** The second parameter is the name of the SQL function to be created or
3174
 
** redefined.  The length of the name is limited to 255 bytes, exclusive of
 
3134
** redefined.  ^The length of the name is limited to 255 bytes, exclusive of
3175
3135
** the zero-terminator.  Note that the name length limit is in bytes, not
3176
 
** characters.  Any attempt to create a function with a longer name
 
3136
** characters.  ^Any attempt to create a function with a longer name
3177
3137
** will result in [SQLITE_ERROR] being returned.
3178
3138
**
3179
 
** The third parameter (nArg)
 
3139
** ^The third parameter (nArg)
3180
3140
** is the number of arguments that the SQL function or
3181
 
** aggregate takes. If this parameter is -1, then the SQL function or
 
3141
** aggregate takes. ^If this parameter is -1, then the SQL function or
3182
3142
** aggregate may take any number of arguments between 0 and the limit
3183
3143
** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]).  If the third
3184
3144
** parameter is less than -1 or greater than 127 then the behavior is
3188
3148
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3189
3149
** its parameters.  Any SQL function implementation should be able to work
3190
3150
** work with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
3191
 
** more efficient with one encoding than another.  An application may
 
3151
** more efficient with one encoding than another.  ^An application may
3192
3152
** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3193
3153
** times with the same function but with different values of eTextRep.
3194
 
** When multiple implementations of the same function are available, SQLite
 
3154
** ^When multiple implementations of the same function are available, SQLite
3195
3155
** will pick the one that involves the least amount of data conversion.
3196
3156
** If there is only a single implementation which does not care what text
3197
3157
** encoding is used, then the fourth argument should be [SQLITE_ANY].
3198
3158
**
3199
 
** The fifth parameter is an arbitrary pointer.  The implementation of the
3200
 
** function can gain access to this pointer using [sqlite3_user_data()].
 
3159
** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
 
3160
** function can gain access to this pointer using [sqlite3_user_data()].)^
3201
3161
**
3202
3162
** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3203
3163
** pointers to C-language functions that implement the SQL function or
3204
 
** aggregate. A scalar SQL function requires an implementation of the xFunc
3205
 
** callback only, NULL pointers should be passed as the xStep and xFinal
3206
 
** parameters. An aggregate SQL function requires an implementation of xStep
3207
 
** and xFinal and NULL should be passed for xFunc. To delete an existing
 
3164
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
 
3165
** callback only; NULL pointers should be passed as the xStep and xFinal
 
3166
** parameters. ^An aggregate SQL function requires an implementation of xStep
 
3167
** and xFinal and NULL should be passed for xFunc. ^To delete an existing
3208
3168
** SQL function or aggregate, pass NULL for all three function callbacks.
3209
3169
**
3210
 
** It is permitted to register multiple implementations of the same
 
3170
** ^It is permitted to register multiple implementations of the same
3211
3171
** functions with the same name but with either differing numbers of
3212
 
** arguments or differing preferred text encodings.  SQLite will use
 
3172
** arguments or differing preferred text encodings.  ^SQLite will use
3213
3173
** the implementation that most closely matches the way in which the
3214
 
** SQL function is used.  A function implementation with a non-negative
 
3174
** SQL function is used.  ^A function implementation with a non-negative
3215
3175
** nArg parameter is a better match than a function implementation with
3216
 
** a negative nArg.  A function where the preferred text encoding
 
3176
** a negative nArg.  ^A function where the preferred text encoding
3217
3177
** matches the database encoding is a better
3218
3178
** match than a function where the encoding is different.  
3219
 
** A function where the encoding difference is between UTF16le and UTF16be
 
3179
** ^A function where the encoding difference is between UTF16le and UTF16be
3220
3180
** is a closer match than a function where the encoding difference is
3221
3181
** between UTF8 and UTF16.
3222
3182
**
3223
 
** Built-in functions may be overloaded by new application-defined functions.
3224
 
** The first application-defined function with a given name overrides all
 
3183
** ^Built-in functions may be overloaded by new application-defined functions.
 
3184
** ^The first application-defined function with a given name overrides all
3225
3185
** built-in functions in the same [database connection] with the same name.
3226
 
** Subsequent application-defined functions of the same name only override 
 
3186
** ^Subsequent application-defined functions of the same name only override 
3227
3187
** prior application-defined functions that are an exact match for the
3228
3188
** number of parameters and preferred encoding.
3229
3189
**
3230
 
** An application-defined function is permitted to call other
 
3190
** ^An application-defined function is permitted to call other
3231
3191
** SQLite interfaces.  However, such calls must not
3232
3192
** close the database connection nor finalize or reset the prepared
3233
3193
** statement in which the function is running.
3234
 
**
3235
 
** Requirements:
3236
 
** [H16103] [H16106] [H16109] [H16112] [H16118] [H16121] [H16127]
3237
 
** [H16130] [H16133] [H16136] [H16139] [H16142]
3238
3194
*/
3239
3195
SQLITE_API int sqlite3_create_function(
3240
3196
  sqlite3 *db,
3258
3214
);
3259
3215
 
3260
3216
/*
3261
 
** CAPI3REF: Text Encodings {H10267} <S50200> <H16100>
 
3217
** CAPI3REF: Text Encodings
3262
3218
**
3263
3219
** These constant define integer codes that represent the various
3264
3220
** text encodings supported by SQLite.
3290
3246
#endif
3291
3247
 
3292
3248
/*
3293
 
** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} <S20200>
 
3249
** CAPI3REF: Obtaining SQL Function Parameter Values
3294
3250
**
3295
3251
** The C-language implementation of SQL functions and aggregates uses
3296
3252
** this set of interface routines to access the parameter values on
3308
3264
** Any attempt to use these routines on an [unprotected sqlite3_value]
3309
3265
** object results in undefined behavior.
3310
3266
**
3311
 
** These routines work just like the corresponding [column access functions]
 
3267
** ^These routines work just like the corresponding [column access functions]
3312
3268
** except that  these routines take a single [protected sqlite3_value] object
3313
3269
** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
3314
3270
**
3315
 
** The sqlite3_value_text16() interface extracts a UTF-16 string
3316
 
** in the native byte-order of the host machine.  The
 
3271
** ^The sqlite3_value_text16() interface extracts a UTF-16 string
 
3272
** in the native byte-order of the host machine.  ^The
3317
3273
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
3318
3274
** extract UTF-16 strings as big-endian and little-endian respectively.
3319
3275
**
3320
 
** The sqlite3_value_numeric_type() interface attempts to apply
 
3276
** ^(The sqlite3_value_numeric_type() interface attempts to apply
3321
3277
** numeric affinity to the value.  This means that an attempt is
3322
3278
** made to convert the value to an integer or floating point.  If
3323
3279
** such a conversion is possible without loss of information (in other
3324
3280
** words, if the value is a string that looks like a number)
3325
3281
** then the conversion is performed.  Otherwise no conversion occurs.
3326
 
** The [SQLITE_INTEGER | datatype] after conversion is returned.
 
3282
** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
3327
3283
**
3328
3284
** Please pay particular attention to the fact that the pointer returned
3329
3285
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
3333
3289
**
3334
3290
** These routines must be called from the same thread as
3335
3291
** the SQL function that supplied the [sqlite3_value*] parameters.
3336
 
**
3337
 
** Requirements:
3338
 
** [H15103] [H15106] [H15109] [H15112] [H15115] [H15118] [H15121] [H15124]
3339
 
** [H15127] [H15130] [H15133] [H15136]
3340
3292
*/
3341
3293
SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
3342
3294
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
3352
3304
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
3353
3305
 
3354
3306
/*
3355
 
** CAPI3REF: Obtain Aggregate Function Context {H16210} <S20200>
3356
 
**
3357
 
** The implementation of aggregate SQL functions use this routine to allocate
3358
 
** a structure for storing their state.
3359
 
**
3360
 
** The first time the sqlite3_aggregate_context() routine is called for a
3361
 
** particular aggregate, SQLite allocates nBytes of memory, zeroes out that
3362
 
** memory, and returns a pointer to it. On second and subsequent calls to
3363
 
** sqlite3_aggregate_context() for the same aggregate function index,
3364
 
** the same buffer is returned. The implementation of the aggregate can use
3365
 
** the returned buffer to accumulate data.
3366
 
**
3367
 
** SQLite automatically frees the allocated buffer when the aggregate
3368
 
** query concludes.
3369
 
**
3370
 
** The first parameter should be a copy of the
 
3307
** CAPI3REF: Obtain Aggregate Function Context
 
3308
**
 
3309
** Implementions of aggregate SQL functions use this
 
3310
** routine to allocate memory for storing their state.
 
3311
**
 
3312
** ^The first time the sqlite3_aggregate_context(C,N) routine is called 
 
3313
** for a particular aggregate function, SQLite
 
3314
** allocates N of memory, zeroes out that memory, and returns a pointer
 
3315
** to the new memory. ^On second and subsequent calls to
 
3316
** sqlite3_aggregate_context() for the same aggregate function instance,
 
3317
** the same buffer is returned.  Sqlite3_aggregate_context() is normally
 
3318
** called once for each invocation of the xStep callback and then one
 
3319
** last time when the xFinal callback is invoked.  ^(When no rows match
 
3320
** an aggregate query, the xStep() callback of the aggregate function
 
3321
** implementation is never called and xFinal() is called exactly once.
 
3322
** In those cases, sqlite3_aggregate_context() might be called for the
 
3323
** first time from within xFinal().)^
 
3324
**
 
3325
** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
 
3326
** less than or equal to zero or if a memory allocate error occurs.
 
3327
**
 
3328
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
 
3329
** determined by the N parameter on first successful call.  Changing the
 
3330
** value of N in subsequent call to sqlite3_aggregate_context() within
 
3331
** the same aggregate function instance will not resize the memory
 
3332
** allocation.)^
 
3333
**
 
3334
** ^SQLite automatically frees the memory allocated by 
 
3335
** sqlite3_aggregate_context() when the aggregate query concludes.
 
3336
**
 
3337
** The first parameter must be a copy of the
3371
3338
** [sqlite3_context | SQL function context] that is the first parameter
3372
 
** to the callback routine that implements the aggregate function.
 
3339
** to the xStep or xFinal callback routine that implements the aggregate
 
3340
** function.
3373
3341
**
3374
3342
** This routine must be called from the same thread in which
3375
3343
** the aggregate SQL function is running.
3376
 
**
3377
 
** Requirements:
3378
 
** [H16211] [H16213] [H16215] [H16217]
3379
3344
*/
3380
3345
SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
3381
3346
 
3382
3347
/*
3383
 
** CAPI3REF: User Data For Functions {H16240} <S20200>
 
3348
** CAPI3REF: User Data For Functions
3384
3349
**
3385
 
** The sqlite3_user_data() interface returns a copy of
 
3350
** ^The sqlite3_user_data() interface returns a copy of
3386
3351
** the pointer that was the pUserData parameter (the 5th parameter)
3387
3352
** of the [sqlite3_create_function()]
3388
3353
** and [sqlite3_create_function16()] routines that originally
3389
 
** registered the application defined function. {END}
 
3354
** registered the application defined function.
3390
3355
**
3391
3356
** This routine must be called from the same thread in which
3392
3357
** the application-defined function is running.
3393
 
**
3394
 
** Requirements:
3395
 
** [H16243]
3396
3358
*/
3397
3359
SQLITE_API void *sqlite3_user_data(sqlite3_context*);
3398
3360
 
3399
3361
/*
3400
 
** CAPI3REF: Database Connection For Functions {H16250} <S60600><S20200>
 
3362
** CAPI3REF: Database Connection For Functions
3401
3363
**
3402
 
** The sqlite3_context_db_handle() interface returns a copy of
 
3364
** ^The sqlite3_context_db_handle() interface returns a copy of
3403
3365
** the pointer to the [database connection] (the 1st parameter)
3404
3366
** of the [sqlite3_create_function()]
3405
3367
** and [sqlite3_create_function16()] routines that originally
3406
3368
** registered the application defined function.
3407
 
**
3408
 
** Requirements:
3409
 
** [H16253]
3410
3369
*/
3411
3370
SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
3412
3371
 
3413
3372
/*
3414
 
** CAPI3REF: Function Auxiliary Data {H16270} <S20200>
 
3373
** CAPI3REF: Function Auxiliary Data
3415
3374
**
3416
3375
** The following two functions may be used by scalar SQL functions to
3417
3376
** associate metadata with argument values. If the same value is passed to
3424
3383
** invocations of the same function so that the original pattern string
3425
3384
** does not need to be recompiled on each invocation.
3426
3385
**
3427
 
** The sqlite3_get_auxdata() interface returns a pointer to the metadata
 
3386
** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
3428
3387
** associated by the sqlite3_set_auxdata() function with the Nth argument
3429
 
** value to the application-defined function. If no metadata has been ever
 
3388
** value to the application-defined function. ^If no metadata has been ever
3430
3389
** been set for the Nth argument of the function, or if the corresponding
3431
3390
** function parameter has changed since the meta-data was set,
3432
3391
** then sqlite3_get_auxdata() returns a NULL pointer.
3433
3392
**
3434
 
** The sqlite3_set_auxdata() interface saves the metadata
 
3393
** ^The sqlite3_set_auxdata() interface saves the metadata
3435
3394
** pointed to by its 3rd parameter as the metadata for the N-th
3436
3395
** argument of the application-defined function.  Subsequent
3437
3396
** calls to sqlite3_get_auxdata() might return this data, if it has
3438
3397
** not been destroyed.
3439
 
** If it is not NULL, SQLite will invoke the destructor
 
3398
** ^If it is not NULL, SQLite will invoke the destructor
3440
3399
** function given by the 4th parameter to sqlite3_set_auxdata() on
3441
3400
** the metadata when the corresponding function parameter changes
3442
3401
** or when the SQL statement completes, whichever comes first.
3443
3402
**
3444
3403
** SQLite is free to call the destructor and drop metadata on any
3445
 
** parameter of any function at any time.  The only guarantee is that
 
3404
** parameter of any function at any time.  ^The only guarantee is that
3446
3405
** the destructor will be called before the metadata is dropped.
3447
3406
**
3448
 
** In practice, metadata is preserved between function calls for
 
3407
** ^(In practice, metadata is preserved between function calls for
3449
3408
** expressions that are constant at compile time. This includes literal
3450
 
** values and SQL variables.
 
3409
** values and [parameters].)^
3451
3410
**
3452
3411
** These routines must be called from the same thread in which
3453
3412
** the SQL function is running.
3454
 
**
3455
 
** Requirements:
3456
 
** [H16272] [H16274] [H16276] [H16277] [H16278] [H16279]
3457
3413
*/
3458
3414
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
3459
3415
SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
3460
3416
 
3461
3417
 
3462
3418
/*
3463
 
** CAPI3REF: Constants Defining Special Destructor Behavior {H10280} <S30100>
 
3419
** CAPI3REF: Constants Defining Special Destructor Behavior
3464
3420
**
3465
3421
** These are special values for the destructor that is passed in as the
3466
 
** final argument to routines like [sqlite3_result_blob()].  If the destructor
 
3422
** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
3467
3423
** argument is SQLITE_STATIC, it means that the content pointer is constant
3468
 
** and will never change.  It does not need to be destroyed.  The
 
3424
** and will never change.  It does not need to be destroyed.  ^The
3469
3425
** SQLITE_TRANSIENT value means that the content will likely change in
3470
3426
** the near future and that SQLite should make its own private copy of
3471
3427
** the content before returning.
3478
3434
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
3479
3435
 
3480
3436
/*
3481
 
** CAPI3REF: Setting The Result Of An SQL Function {H16400} <S20200>
 
3437
** CAPI3REF: Setting The Result Of An SQL Function
3482
3438
**
3483
3439
** These routines are used by the xFunc or xFinal callbacks that
3484
3440
** implement SQL functions and aggregates.  See
3489
3445
** functions used to bind values to host parameters in prepared statements.
3490
3446
** Refer to the [SQL parameter] documentation for additional information.
3491
3447
**
3492
 
** The sqlite3_result_blob() interface sets the result from
 
3448
** ^The sqlite3_result_blob() interface sets the result from
3493
3449
** an application-defined function to be the BLOB whose content is pointed
3494
3450
** to by the second parameter and which is N bytes long where N is the
3495
3451
** third parameter.
3496
3452
**
3497
 
** The sqlite3_result_zeroblob() interfaces set the result of
 
3453
** ^The sqlite3_result_zeroblob() interfaces set the result of
3498
3454
** the application-defined function to be a BLOB containing all zero
3499
3455
** bytes and N bytes in size, where N is the value of the 2nd parameter.
3500
3456
**
3501
 
** The sqlite3_result_double() interface sets the result from
 
3457
** ^The sqlite3_result_double() interface sets the result from
3502
3458
** an application-defined function to be a floating point value specified
3503
3459
** by its 2nd argument.
3504
3460
**
3505
 
** The sqlite3_result_error() and sqlite3_result_error16() functions
 
3461
** ^The sqlite3_result_error() and sqlite3_result_error16() functions
3506
3462
** cause the implemented SQL function to throw an exception.
3507
 
** SQLite uses the string pointed to by the
 
3463
** ^SQLite uses the string pointed to by the
3508
3464
** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
3509
 
** as the text of an error message.  SQLite interprets the error
3510
 
** message string from sqlite3_result_error() as UTF-8. SQLite
 
3465
** as the text of an error message.  ^SQLite interprets the error
 
3466
** message string from sqlite3_result_error() as UTF-8. ^SQLite
3511
3467
** interprets the string from sqlite3_result_error16() as UTF-16 in native
3512
 
** byte order.  If the third parameter to sqlite3_result_error()
 
3468
** byte order.  ^If the third parameter to sqlite3_result_error()
3513
3469
** or sqlite3_result_error16() is negative then SQLite takes as the error
3514
3470
** message all text up through the first zero character.
3515
 
** If the third parameter to sqlite3_result_error() or
 
3471
** ^If the third parameter to sqlite3_result_error() or
3516
3472
** sqlite3_result_error16() is non-negative then SQLite takes that many
3517
3473
** bytes (not characters) from the 2nd parameter as the error message.
3518
 
** The sqlite3_result_error() and sqlite3_result_error16()
 
3474
** ^The sqlite3_result_error() and sqlite3_result_error16()
3519
3475
** routines make a private copy of the error message text before
3520
3476
** they return.  Hence, the calling function can deallocate or
3521
3477
** modify the text after they return without harm.
3522
 
** The sqlite3_result_error_code() function changes the error code
3523
 
** returned by SQLite as a result of an error in a function.  By default,
3524
 
** the error code is SQLITE_ERROR.  A subsequent call to sqlite3_result_error()
 
3478
** ^The sqlite3_result_error_code() function changes the error code
 
3479
** returned by SQLite as a result of an error in a function.  ^By default,
 
3480
** the error code is SQLITE_ERROR.  ^A subsequent call to sqlite3_result_error()
3525
3481
** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
3526
3482
**
3527
 
** The sqlite3_result_toobig() interface causes SQLite to throw an error
3528
 
** indicating that a string or BLOB is to long to represent.
 
3483
** ^The sqlite3_result_toobig() interface causes SQLite to throw an error
 
3484
** indicating that a string or BLOB is too long to represent.
3529
3485
**
3530
 
** The sqlite3_result_nomem() interface causes SQLite to throw an error
 
3486
** ^The sqlite3_result_nomem() interface causes SQLite to throw an error
3531
3487
** indicating that a memory allocation failed.
3532
3488
**
3533
 
** The sqlite3_result_int() interface sets the return value
 
3489
** ^The sqlite3_result_int() interface sets the return value
3534
3490
** of the application-defined function to be the 32-bit signed integer
3535
3491
** value given in the 2nd argument.
3536
 
** The sqlite3_result_int64() interface sets the return value
 
3492
** ^The sqlite3_result_int64() interface sets the return value
3537
3493
** of the application-defined function to be the 64-bit signed integer
3538
3494
** value given in the 2nd argument.
3539
3495
**
3540
 
** The sqlite3_result_null() interface sets the return value
 
3496
** ^The sqlite3_result_null() interface sets the return value
3541
3497
** of the application-defined function to be NULL.
3542
3498
**
3543
 
** The sqlite3_result_text(), sqlite3_result_text16(),
 
3499
** ^The sqlite3_result_text(), sqlite3_result_text16(),
3544
3500
** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
3545
3501
** set the return value of the application-defined function to be
3546
3502
** a text string which is represented as UTF-8, UTF-16 native byte order,
3547
3503
** UTF-16 little endian, or UTF-16 big endian, respectively.
3548
 
** SQLite takes the text result from the application from
 
3504
** ^SQLite takes the text result from the application from
3549
3505
** the 2nd parameter of the sqlite3_result_text* interfaces.
3550
 
** If the 3rd parameter to the sqlite3_result_text* interfaces
 
3506
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
3551
3507
** is negative, then SQLite takes result text from the 2nd parameter
3552
3508
** through the first zero character.
3553
 
** If the 3rd parameter to the sqlite3_result_text* interfaces
 
3509
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
3554
3510
** is non-negative, then as many bytes (not characters) of the text
3555
3511
** pointed to by the 2nd parameter are taken as the application-defined
3556
3512
** function result.
3557
 
** If the 4th parameter to the sqlite3_result_text* interfaces
 
3513
** ^If the 4th parameter to the sqlite3_result_text* interfaces
3558
3514
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
3559
3515
** function as the destructor on the text or BLOB result when it has
3560
3516
** finished using that result.
3561
 
** If the 4th parameter to the sqlite3_result_text* interfaces or to
 
3517
** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
3562
3518
** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
3563
3519
** assumes that the text or BLOB result is in constant space and does not
3564
3520
** copy the content of the parameter nor call a destructor on the content
3565
3521
** when it has finished using that result.
3566
 
** If the 4th parameter to the sqlite3_result_text* interfaces
 
3522
** ^If the 4th parameter to the sqlite3_result_text* interfaces
3567
3523
** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
3568
3524
** then SQLite makes a copy of the result into space obtained from
3569
3525
** from [sqlite3_malloc()] before it returns.
3570
3526
**
3571
 
** The sqlite3_result_value() interface sets the result of
 
3527
** ^The sqlite3_result_value() interface sets the result of
3572
3528
** the application-defined function to be a copy the
3573
 
** [unprotected sqlite3_value] object specified by the 2nd parameter.  The
 
3529
** [unprotected sqlite3_value] object specified by the 2nd parameter.  ^The
3574
3530
** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
3575
3531
** so that the [sqlite3_value] specified in the parameter may change or
3576
3532
** be deallocated after sqlite3_result_value() returns without harm.
3577
 
** A [protected sqlite3_value] object may always be used where an
 
3533
** ^A [protected sqlite3_value] object may always be used where an
3578
3534
** [unprotected sqlite3_value] object is required, so either
3579
3535
** kind of [sqlite3_value] object can be used with this interface.
3580
3536
**
3581
3537
** If these routines are called from within the different thread
3582
3538
** than the one containing the application-defined function that received
3583
3539
** the [sqlite3_context] pointer, the results are undefined.
3584
 
**
3585
 
** Requirements:
3586
 
** [H16403] [H16406] [H16409] [H16412] [H16415] [H16418] [H16421] [H16424]
3587
 
** [H16427] [H16430] [H16433] [H16436] [H16439] [H16442] [H16445] [H16448]
3588
 
** [H16451] [H16454] [H16457] [H16460] [H16463]
3589
3540
*/
3590
3541
SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
3591
3542
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
3605
3556
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
3606
3557
 
3607
3558
/*
3608
 
** CAPI3REF: Define New Collating Sequences {H16600} <S20300>
 
3559
** CAPI3REF: Define New Collating Sequences
3609
3560
**
3610
3561
** These functions are used to add new collation sequences to the
3611
3562
** [database connection] specified as the first argument.
3612
3563
**
3613
 
** The name of the new collation sequence is specified as a UTF-8 string
 
3564
** ^The name of the new collation sequence is specified as a UTF-8 string
3614
3565
** for sqlite3_create_collation() and sqlite3_create_collation_v2()
3615
 
** and a UTF-16 string for sqlite3_create_collation16(). In all cases
 
3566
** and a UTF-16 string for sqlite3_create_collation16(). ^In all cases
3616
3567
** the name is passed as the second function argument.
3617
3568
**
3618
 
** The third argument may be one of the constants [SQLITE_UTF8],
 
3569
** ^The third argument may be one of the constants [SQLITE_UTF8],
3619
3570
** [SQLITE_UTF16LE], or [SQLITE_UTF16BE], indicating that the user-supplied
3620
3571
** routine expects to be passed pointers to strings encoded using UTF-8,
3621
 
** UTF-16 little-endian, or UTF-16 big-endian, respectively. The
 
3572
** UTF-16 little-endian, or UTF-16 big-endian, respectively. ^The
3622
3573
** third argument might also be [SQLITE_UTF16] to indicate that the routine
3623
3574
** expects pointers to be UTF-16 strings in the native byte order, or the
3624
3575
** argument can be [SQLITE_UTF16_ALIGNED] if the
3626
3577
** of UTF-16 in the native byte order.
3627
3578
**
3628
3579
** A pointer to the user supplied routine must be passed as the fifth
3629
 
** argument.  If it is NULL, this is the same as deleting the collation
 
3580
** argument.  ^If it is NULL, this is the same as deleting the collation
3630
3581
** sequence (so that SQLite cannot call it anymore).
3631
 
** Each time the application supplied function is invoked, it is passed
 
3582
** ^Each time the application supplied function is invoked, it is passed
3632
3583
** as its first parameter a copy of the void* passed as the fourth argument
3633
3584
** to sqlite3_create_collation() or sqlite3_create_collation16().
3634
3585
**
3635
 
** The remaining arguments to the application-supplied routine are two strings,
 
3586
** ^The remaining arguments to the application-supplied routine are two strings,
3636
3587
** each represented by a (length, data) pair and encoded in the encoding
3637
3588
** that was passed as the third argument when the collation sequence was
3638
 
** registered. {END}  The application defined collation routine should
 
3589
** registered.  The application defined collation routine should
3639
3590
** return negative, zero or positive if the first string is less than,
3640
3591
** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
3641
3592
**
3642
 
** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
 
3593
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
3643
3594
** except that it takes an extra argument which is a destructor for
3644
 
** the collation.  The destructor is called when the collation is
 
3595
** the collation.  ^The destructor is called when the collation is
3645
3596
** destroyed and is passed a copy of the fourth parameter void* pointer
3646
3597
** of the sqlite3_create_collation_v2().
3647
 
** Collations are destroyed when they are overridden by later calls to the
 
3598
** ^Collations are destroyed when they are overridden by later calls to the
3648
3599
** collation creation functions or when the [database connection] is closed
3649
3600
** using [sqlite3_close()].
3650
3601
**
3651
3602
** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
3652
 
**
3653
 
** Requirements:
3654
 
** [H16603] [H16604] [H16606] [H16609] [H16612] [H16615] [H16618] [H16621]
3655
 
** [H16624] [H16627] [H16630]
3656
3603
*/
3657
3604
SQLITE_API int sqlite3_create_collation(
3658
3605
  sqlite3*, 
3678
3625
);
3679
3626
 
3680
3627
/*
3681
 
** CAPI3REF: Collation Needed Callbacks {H16700} <S20300>
 
3628
** CAPI3REF: Collation Needed Callbacks
3682
3629
**
3683
 
** To avoid having to register all collation sequences before a database
 
3630
** ^To avoid having to register all collation sequences before a database
3684
3631
** can be used, a single callback function may be registered with the
3685
 
** [database connection] to be called whenever an undefined collation
 
3632
** [database connection] to be invoked whenever an undefined collation
3686
3633
** sequence is required.
3687
3634
**
3688
 
** If the function is registered using the sqlite3_collation_needed() API,
 
3635
** ^If the function is registered using the sqlite3_collation_needed() API,
3689
3636
** then it is passed the names of undefined collation sequences as strings
3690
 
** encoded in UTF-8. {H16703} If sqlite3_collation_needed16() is used,
 
3637
** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
3691
3638
** the names are passed as UTF-16 in machine native byte order.
3692
 
** A call to either function replaces any existing callback.
 
3639
** ^A call to either function replaces the existing collation-needed callback.
3693
3640
**
3694
 
** When the callback is invoked, the first argument passed is a copy
 
3641
** ^(When the callback is invoked, the first argument passed is a copy
3695
3642
** of the second argument to sqlite3_collation_needed() or
3696
3643
** sqlite3_collation_needed16().  The second argument is the database
3697
3644
** connection.  The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
3698
3645
** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
3699
3646
** sequence function required.  The fourth parameter is the name of the
3700
 
** required collation sequence.
 
3647
** required collation sequence.)^
3701
3648
**
3702
3649
** The callback function should register the desired collation using
3703
3650
** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
3704
3651
** [sqlite3_create_collation_v2()].
3705
 
**
3706
 
** Requirements:
3707
 
** [H16702] [H16704] [H16706]
3708
3652
*/
3709
3653
SQLITE_API int sqlite3_collation_needed(
3710
3654
  sqlite3*, 
3743
3687
);
3744
3688
 
3745
3689
/*
3746
 
** CAPI3REF: Suspend Execution For A Short Time {H10530} <S40410>
 
3690
** CAPI3REF: Suspend Execution For A Short Time
3747
3691
**
3748
 
** The sqlite3_sleep() function causes the current thread to suspend execution
 
3692
** ^The sqlite3_sleep() function causes the current thread to suspend execution
3749
3693
** for at least a number of milliseconds specified in its parameter.
3750
3694
**
3751
 
** If the operating system does not support sleep requests with
 
3695
** ^If the operating system does not support sleep requests with
3752
3696
** millisecond time resolution, then the time will be rounded up to
3753
 
** the nearest second. The number of milliseconds of sleep actually
 
3697
** the nearest second. ^The number of milliseconds of sleep actually
3754
3698
** requested from the operating system is returned.
3755
3699
**
3756
 
** SQLite implements this interface by calling the xSleep()
 
3700
** ^SQLite implements this interface by calling the xSleep()
3757
3701
** method of the default [sqlite3_vfs] object.
3758
 
**
3759
 
** Requirements: [H10533] [H10536]
3760
3702
*/
3761
3703
SQLITE_API int sqlite3_sleep(int);
3762
3704
 
3763
3705
/*
3764
 
** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
 
3706
** CAPI3REF: Name Of The Folder Holding Temporary Files
3765
3707
**
3766
 
** If this global variable is made to point to a string which is
 
3708
** ^(If this global variable is made to point to a string which is
3767
3709
** the name of a folder (a.k.a. directory), then all temporary files
3768
 
** created by SQLite will be placed in that directory.  If this variable
 
3710
** created by SQLite when using a built-in [sqlite3_vfs | VFS]
 
3711
** will be placed in that directory.)^  ^If this variable
3769
3712
** is a NULL pointer, then SQLite performs a search for an appropriate
3770
3713
** temporary file directory.
3771
3714
**
3778
3721
** routines have been called and that this variable remain unchanged
3779
3722
** thereafter.
3780
3723
**
3781
 
** The [temp_store_directory pragma] may modify this variable and cause
3782
 
** it to point to memory obtained from [sqlite3_malloc].  Furthermore,
 
3724
** ^The [temp_store_directory pragma] may modify this variable and cause
 
3725
** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
3783
3726
** the [temp_store_directory pragma] always assumes that any string
3784
3727
** that this variable points to is held in memory obtained from 
3785
3728
** [sqlite3_malloc] and the pragma may attempt to free that memory
3791
3734
SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
3792
3735
 
3793
3736
/*
3794
 
** CAPI3REF: Test For Auto-Commit Mode {H12930} <S60200>
 
3737
** CAPI3REF: Test For Auto-Commit Mode
3795
3738
** KEYWORDS: {autocommit mode}
3796
3739
**
3797
 
** The sqlite3_get_autocommit() interface returns non-zero or
 
3740
** ^The sqlite3_get_autocommit() interface returns non-zero or
3798
3741
** zero if the given database connection is or is not in autocommit mode,
3799
 
** respectively.  Autocommit mode is on by default.
3800
 
** Autocommit mode is disabled by a [BEGIN] statement.
3801
 
** Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
 
3742
** respectively.  ^Autocommit mode is on by default.
 
3743
** ^Autocommit mode is disabled by a [BEGIN] statement.
 
3744
** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
3802
3745
**
3803
3746
** If certain kinds of errors occur on a statement within a multi-statement
3804
3747
** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
3810
3753
** If another thread changes the autocommit status of the database
3811
3754
** connection while this routine is running, then the return value
3812
3755
** is undefined.
3813
 
**
3814
 
** Requirements: [H12931] [H12932] [H12933] [H12934]
3815
3756
*/
3816
3757
SQLITE_API int sqlite3_get_autocommit(sqlite3*);
3817
3758
 
3818
3759
/*
3819
 
** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} <S60600>
 
3760
** CAPI3REF: Find The Database Handle Of A Prepared Statement
3820
3761
**
3821
 
** The sqlite3_db_handle interface returns the [database connection] handle
3822
 
** to which a [prepared statement] belongs.  The [database connection]
3823
 
** returned by sqlite3_db_handle is the same [database connection] that was the first argument
 
3762
** ^The sqlite3_db_handle interface returns the [database connection] handle
 
3763
** to which a [prepared statement] belongs.  ^The [database connection]
 
3764
** returned by sqlite3_db_handle is the same [database connection]
 
3765
** that was the first argument
3824
3766
** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
3825
3767
** create the statement in the first place.
3826
 
**
3827
 
** Requirements: [H13123]
3828
3768
*/
3829
3769
SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
3830
3770
 
3831
3771
/*
3832
 
** CAPI3REF: Find the next prepared statement {H13140} <S60600>
 
3772
** CAPI3REF: Find the next prepared statement
3833
3773
**
3834
 
** This interface returns a pointer to the next [prepared statement] after
3835
 
** pStmt associated with the [database connection] pDb.  If pStmt is NULL
 
3774
** ^This interface returns a pointer to the next [prepared statement] after
 
3775
** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
3836
3776
** then this interface returns a pointer to the first prepared statement
3837
 
** associated with the database connection pDb.  If no prepared statement
 
3777
** associated with the database connection pDb.  ^If no prepared statement
3838
3778
** satisfies the conditions of this routine, it returns NULL.
3839
3779
**
3840
3780
** The [database connection] pointer D in a call to
3841
3781
** [sqlite3_next_stmt(D,S)] must refer to an open database
3842
3782
** connection and in particular must not be a NULL pointer.
3843
 
**
3844
 
** Requirements: [H13143] [H13146] [H13149] [H13152]
3845
3783
*/
3846
3784
SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
3847
3785
 
3848
3786
/*
3849
 
** CAPI3REF: Commit And Rollback Notification Callbacks {H12950} <S60400>
 
3787
** CAPI3REF: Commit And Rollback Notification Callbacks
3850
3788
**
3851
 
** The sqlite3_commit_hook() interface registers a callback
 
3789
** ^The sqlite3_commit_hook() interface registers a callback
3852
3790
** function to be invoked whenever a transaction is [COMMIT | committed].
3853
 
** Any callback set by a previous call to sqlite3_commit_hook()
 
3791
** ^Any callback set by a previous call to sqlite3_commit_hook()
3854
3792
** for the same database connection is overridden.
3855
 
** The sqlite3_rollback_hook() interface registers a callback
 
3793
** ^The sqlite3_rollback_hook() interface registers a callback
3856
3794
** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
3857
 
** Any callback set by a previous call to sqlite3_commit_hook()
 
3795
** ^Any callback set by a previous call to sqlite3_rollback_hook()
3858
3796
** for the same database connection is overridden.
3859
 
** The pArg argument is passed through to the callback.
3860
 
** If the callback on a commit hook function returns non-zero,
 
3797
** ^The pArg argument is passed through to the callback.
 
3798
** ^If the callback on a commit hook function returns non-zero,
3861
3799
** then the commit is converted into a rollback.
3862
3800
**
3863
 
** If another function was previously registered, its
3864
 
** pArg value is returned.  Otherwise NULL is returned.
 
3801
** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
 
3802
** return the P argument from the previous call of the same function
 
3803
** on the same [database connection] D, or NULL for
 
3804
** the first call for each function on D.
3865
3805
**
3866
3806
** The callback implementation must not do anything that will modify
3867
3807
** the database connection that invoked the callback.  Any actions
3871
3811
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3872
3812
** database connections for the meaning of "modify" in this paragraph.
3873
3813
**
3874
 
** Registering a NULL function disables the callback.
 
3814
** ^Registering a NULL function disables the callback.
3875
3815
**
3876
 
** When the commit hook callback routine returns zero, the [COMMIT]
3877
 
** operation is allowed to continue normally.  If the commit hook
 
3816
** ^When the commit hook callback routine returns zero, the [COMMIT]
 
3817
** operation is allowed to continue normally.  ^If the commit hook
3878
3818
** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
3879
 
** The rollback hook is invoked on a rollback that results from a commit
 
3819
** ^The rollback hook is invoked on a rollback that results from a commit
3880
3820
** hook returning non-zero, just as it would be with any other rollback.
3881
3821
**
3882
 
** For the purposes of this API, a transaction is said to have been
 
3822
** ^For the purposes of this API, a transaction is said to have been
3883
3823
** rolled back if an explicit "ROLLBACK" statement is executed, or
3884
3824
** an error or constraint causes an implicit rollback to occur.
3885
 
** The rollback callback is not invoked if a transaction is
 
3825
** ^The rollback callback is not invoked if a transaction is
3886
3826
** automatically rolled back because the database connection is closed.
3887
 
** The rollback callback is not invoked if a transaction is
 
3827
** ^The rollback callback is not invoked if a transaction is
3888
3828
** rolled back because a commit callback returned non-zero.
3889
 
** <todo> Check on this </todo>
3890
3829
**
3891
3830
** See also the [sqlite3_update_hook()] interface.
3892
 
**
3893
 
** Requirements:
3894
 
** [H12951] [H12952] [H12953] [H12954] [H12955]
3895
 
** [H12961] [H12962] [H12963] [H12964]
3896
3831
*/
3897
3832
SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
3898
3833
SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
3899
3834
 
3900
3835
/*
3901
 
** CAPI3REF: Data Change Notification Callbacks {H12970} <S60400>
 
3836
** CAPI3REF: Data Change Notification Callbacks
3902
3837
**
3903
 
** The sqlite3_update_hook() interface registers a callback function
 
3838
** ^The sqlite3_update_hook() interface registers a callback function
3904
3839
** with the [database connection] identified by the first argument
3905
3840
** to be invoked whenever a row is updated, inserted or deleted.
3906
 
** Any callback set by a previous call to this function
 
3841
** ^Any callback set by a previous call to this function
3907
3842
** for the same database connection is overridden.
3908
3843
**
3909
 
** The second argument is a pointer to the function to invoke when a
 
3844
** ^The second argument is a pointer to the function to invoke when a
3910
3845
** row is updated, inserted or deleted.
3911
 
** The first argument to the callback is a copy of the third argument
 
3846
** ^The first argument to the callback is a copy of the third argument
3912
3847
** to sqlite3_update_hook().
3913
 
** The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
 
3848
** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
3914
3849
** or [SQLITE_UPDATE], depending on the operation that caused the callback
3915
3850
** to be invoked.
3916
 
** The third and fourth arguments to the callback contain pointers to the
 
3851
** ^The third and fourth arguments to the callback contain pointers to the
3917
3852
** database and table name containing the affected row.
3918
 
** The final callback parameter is the [rowid] of the row.
3919
 
** In the case of an update, this is the [rowid] after the update takes place.
3920
 
**
3921
 
** The update hook is not invoked when internal system tables are
3922
 
** modified (i.e. sqlite_master and sqlite_sequence).
3923
 
**
3924
 
** In the current implementation, the update hook
 
3853
** ^The final callback parameter is the [rowid] of the row.
 
3854
** ^In the case of an update, this is the [rowid] after the update takes place.
 
3855
**
 
3856
** ^(The update hook is not invoked when internal system tables are
 
3857
** modified (i.e. sqlite_master and sqlite_sequence).)^
 
3858
**
 
3859
** ^In the current implementation, the update hook
3925
3860
** is not invoked when duplication rows are deleted because of an
3926
 
** [ON CONFLICT | ON CONFLICT REPLACE] clause.  Nor is the update hook
 
3861
** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
3927
3862
** invoked when rows are deleted using the [truncate optimization].
3928
3863
** The exceptions defined in this paragraph might change in a future
3929
3864
** release of SQLite.
3935
3870
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3936
3871
** database connections for the meaning of "modify" in this paragraph.
3937
3872
**
3938
 
** If another function was previously registered, its pArg value
3939
 
** is returned.  Otherwise NULL is returned.
 
3873
** ^The sqlite3_update_hook(D,C,P) function
 
3874
** returns the P argument from the previous call
 
3875
** on the same [database connection] D, or NULL for
 
3876
** the first call on D.
3940
3877
**
3941
3878
** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()]
3942
3879
** interfaces.
3943
 
**
3944
 
** Requirements:
3945
 
** [H12971] [H12973] [H12975] [H12977] [H12979] [H12981] [H12983] [H12986]
3946
3880
*/
3947
3881
SQLITE_API void *sqlite3_update_hook(
3948
3882
  sqlite3*, 
3951
3885
);
3952
3886
 
3953
3887
/*
3954
 
** CAPI3REF: Enable Or Disable Shared Pager Cache {H10330} <S30900>
 
3888
** CAPI3REF: Enable Or Disable Shared Pager Cache
3955
3889
** KEYWORDS: {shared cache}
3956
3890
**
3957
 
** This routine enables or disables the sharing of the database cache
 
3891
** ^(This routine enables or disables the sharing of the database cache
3958
3892
** and schema data structures between [database connection | connections]
3959
3893
** to the same database. Sharing is enabled if the argument is true
3960
 
** and disabled if the argument is false.
 
3894
** and disabled if the argument is false.)^
3961
3895
**
3962
 
** Cache sharing is enabled and disabled for an entire process.
 
3896
** ^Cache sharing is enabled and disabled for an entire process.
3963
3897
** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
3964
3898
** sharing was enabled or disabled for each thread separately.
3965
3899
**
3966
 
** The cache sharing mode set by this interface effects all subsequent
 
3900
** ^(The cache sharing mode set by this interface effects all subsequent
3967
3901
** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
3968
3902
** Existing database connections continue use the sharing mode
3969
 
** that was in effect at the time they were opened.
3970
 
**
3971
 
** Virtual tables cannot be used with a shared cache.  When shared
3972
 
** cache is enabled, the [sqlite3_create_module()] API used to register
3973
 
** virtual tables will always return an error.
3974
 
**
3975
 
** This routine returns [SQLITE_OK] if shared cache was enabled or disabled
3976
 
** successfully.  An [error code] is returned otherwise.
3977
 
**
3978
 
** Shared cache is disabled by default. But this might change in
 
3903
** that was in effect at the time they were opened.)^
 
3904
**
 
3905
** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
 
3906
** successfully.  An [error code] is returned otherwise.)^
 
3907
**
 
3908
** ^Shared cache is disabled by default. But this might change in
3979
3909
** future releases of SQLite.  Applications that care about shared
3980
3910
** cache setting should set it explicitly.
3981
3911
**
3982
3912
** See Also:  [SQLite Shared-Cache Mode]
3983
 
**
3984
 
** Requirements: [H10331] [H10336] [H10337] [H10339]
3985
3913
*/
3986
3914
SQLITE_API int sqlite3_enable_shared_cache(int);
3987
3915
 
3988
3916
/*
3989
 
** CAPI3REF: Attempt To Free Heap Memory {H17340} <S30220>
 
3917
** CAPI3REF: Attempt To Free Heap Memory
3990
3918
**
3991
 
** The sqlite3_release_memory() interface attempts to free N bytes
 
3919
** ^The sqlite3_release_memory() interface attempts to free N bytes
3992
3920
** of heap memory by deallocating non-essential memory allocations
3993
 
** held by the database library. {END}  Memory used to cache database
 
3921
** held by the database library.   Memory used to cache database
3994
3922
** pages to improve performance is an example of non-essential memory.
3995
 
** sqlite3_release_memory() returns the number of bytes actually freed,
 
3923
** ^sqlite3_release_memory() returns the number of bytes actually freed,
3996
3924
** which might be more or less than the amount requested.
3997
 
**
3998
 
** Requirements: [H17341] [H17342]
3999
3925
*/
4000
3926
SQLITE_API int sqlite3_release_memory(int);
4001
3927
 
4002
3928
/*
4003
 
** CAPI3REF: Impose A Limit On Heap Size {H17350} <S30220>
 
3929
** CAPI3REF: Impose A Limit On Heap Size
4004
3930
**
4005
 
** The sqlite3_soft_heap_limit() interface places a "soft" limit
 
3931
** ^The sqlite3_soft_heap_limit() interface places a "soft" limit
4006
3932
** on the amount of heap memory that may be allocated by SQLite.
4007
 
** If an internal allocation is requested that would exceed the
 
3933
** ^If an internal allocation is requested that would exceed the
4008
3934
** soft heap limit, [sqlite3_release_memory()] is invoked one or
4009
3935
** more times to free up some space before the allocation is performed.
4010
3936
**
4011
 
** The limit is called "soft", because if [sqlite3_release_memory()]
 
3937
** ^The limit is called "soft" because if [sqlite3_release_memory()]
4012
3938
** cannot free sufficient memory to prevent the limit from being exceeded,
4013
3939
** the memory is allocated anyway and the current operation proceeds.
4014
3940
**
4015
 
** A negative or zero value for N means that there is no soft heap limit and
 
3941
** ^A negative or zero value for N means that there is no soft heap limit and
4016
3942
** [sqlite3_release_memory()] will only be called when memory is exhausted.
4017
 
** The default value for the soft heap limit is zero.
 
3943
** ^The default value for the soft heap limit is zero.
4018
3944
**
4019
 
** SQLite makes a best effort to honor the soft heap limit.
 
3945
** ^(SQLite makes a best effort to honor the soft heap limit.
4020
3946
** But if the soft heap limit cannot be honored, execution will
4021
 
** continue without error or notification.  This is why the limit is
 
3947
** continue without error or notification.)^  This is why the limit is
4022
3948
** called a "soft" limit.  It is advisory only.
4023
3949
**
4024
3950
** Prior to SQLite version 3.5.0, this routine only constrained the memory
4028
3954
** is an upper bound on the total memory allocation for all threads. In
4029
3955
** version 3.5.0 there is no mechanism for limiting the heap usage for
4030
3956
** individual threads.
4031
 
**
4032
 
** Requirements:
4033
 
** [H16351] [H16352] [H16353] [H16354] [H16355] [H16358]
4034
3957
*/
4035
3958
SQLITE_API void sqlite3_soft_heap_limit(int);
4036
3959
 
4037
3960
/*
4038
 
** CAPI3REF: Extract Metadata About A Column Of A Table {H12850} <S60300>
 
3961
** CAPI3REF: Extract Metadata About A Column Of A Table
4039
3962
**
4040
 
** This routine returns metadata about a specific column of a specific
 
3963
** ^This routine returns metadata about a specific column of a specific
4041
3964
** database table accessible using the [database connection] handle
4042
3965
** passed as the first function argument.
4043
3966
**
4044
 
** The column is identified by the second, third and fourth parameters to
4045
 
** this function. The second parameter is either the name of the database
4046
 
** (i.e. "main", "temp" or an attached database) containing the specified
4047
 
** table or NULL. If it is NULL, then all attached databases are searched
 
3967
** ^The column is identified by the second, third and fourth parameters to
 
3968
** this function. ^The second parameter is either the name of the database
 
3969
** (i.e. "main", "temp", or an attached database) containing the specified
 
3970
** table or NULL. ^If it is NULL, then all attached databases are searched
4048
3971
** for the table using the same algorithm used by the database engine to
4049
3972
** resolve unqualified table references.
4050
3973
**
4051
 
** The third and fourth parameters to this function are the table and column
 
3974
** ^The third and fourth parameters to this function are the table and column
4052
3975
** name of the desired column, respectively. Neither of these parameters
4053
3976
** may be NULL.
4054
3977
**
4055
 
** Metadata is returned by writing to the memory locations passed as the 5th
4056
 
** and subsequent parameters to this function. Any of these arguments may be
 
3978
** ^Metadata is returned by writing to the memory locations passed as the 5th
 
3979
** and subsequent parameters to this function. ^Any of these arguments may be
4057
3980
** NULL, in which case the corresponding element of metadata is omitted.
4058
3981
**
4059
 
** <blockquote>
 
3982
** ^(<blockquote>
4060
3983
** <table border="1">
4061
3984
** <tr><th> Parameter <th> Output<br>Type <th>  Description
4062
3985
**
4066
3989
** <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
4067
3990
** <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
4068
3991
** </table>
4069
 
** </blockquote>
 
3992
** </blockquote>)^
4070
3993
**
4071
 
** The memory pointed to by the character pointers returned for the
 
3994
** ^The memory pointed to by the character pointers returned for the
4072
3995
** declaration type and collation sequence is valid only until the next
4073
3996
** call to any SQLite API function.
4074
3997
**
4075
 
** If the specified table is actually a view, an [error code] is returned.
 
3998
** ^If the specified table is actually a view, an [error code] is returned.
4076
3999
**
4077
 
** If the specified column is "rowid", "oid" or "_rowid_" and an
 
4000
** ^If the specified column is "rowid", "oid" or "_rowid_" and an
4078
4001
** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
4079
 
** parameters are set for the explicitly declared column. If there is no
 
4002
** parameters are set for the explicitly declared column. ^(If there is no
4080
4003
** explicitly declared [INTEGER PRIMARY KEY] column, then the output
4081
4004
** parameters are set as follows:
4082
4005
**
4086
4009
**     not null: 0
4087
4010
**     primary key: 1
4088
4011
**     auto increment: 0
4089
 
** </pre>
 
4012
** </pre>)^
4090
4013
**
4091
 
** This function may load one or more schemas from database files. If an
 
4014
** ^(This function may load one or more schemas from database files. If an
4092
4015
** error occurs during this process, or if the requested table or column
4093
4016
** cannot be found, an [error code] is returned and an error message left
4094
 
** in the [database connection] (to be retrieved using sqlite3_errmsg()).
 
4017
** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
4095
4018
**
4096
 
** This API is only available if the library was compiled with the
 
4019
** ^This API is only available if the library was compiled with the
4097
4020
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
4098
4021
*/
4099
4022
SQLITE_API int sqlite3_table_column_metadata(
4109
4032
);
4110
4033
 
4111
4034
/*
4112
 
** CAPI3REF: Load An Extension {H12600} <S20500>
4113
 
**
4114
 
** This interface loads an SQLite extension library from the named file.
4115
 
**
4116
 
** {H12601} The sqlite3_load_extension() interface attempts to load an
4117
 
**          SQLite extension library contained in the file zFile.
4118
 
**
4119
 
** {H12602} The entry point is zProc.
4120
 
**
4121
 
** {H12603} zProc may be 0, in which case the name of the entry point
4122
 
**          defaults to "sqlite3_extension_init".
4123
 
**
4124
 
** {H12604} The sqlite3_load_extension() interface shall return
4125
 
**          [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
4126
 
**
4127
 
** {H12605} If an error occurs and pzErrMsg is not 0, then the
4128
 
**          [sqlite3_load_extension()] interface shall attempt to
4129
 
**          fill *pzErrMsg with error message text stored in memory
4130
 
**          obtained from [sqlite3_malloc()]. {END}  The calling function
4131
 
**          should free this memory by calling [sqlite3_free()].
4132
 
**
4133
 
** {H12606} Extension loading must be enabled using
4134
 
**          [sqlite3_enable_load_extension()] prior to calling this API,
4135
 
**          otherwise an error will be returned.
 
4035
** CAPI3REF: Load An Extension
 
4036
**
 
4037
** ^This interface loads an SQLite extension library from the named file.
 
4038
**
 
4039
** ^The sqlite3_load_extension() interface attempts to load an
 
4040
** SQLite extension library contained in the file zFile.
 
4041
**
 
4042
** ^The entry point is zProc.
 
4043
** ^zProc may be 0, in which case the name of the entry point
 
4044
** defaults to "sqlite3_extension_init".
 
4045
** ^The sqlite3_load_extension() interface returns
 
4046
** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
 
4047
** ^If an error occurs and pzErrMsg is not 0, then the
 
4048
** [sqlite3_load_extension()] interface shall attempt to
 
4049
** fill *pzErrMsg with error message text stored in memory
 
4050
** obtained from [sqlite3_malloc()]. The calling function
 
4051
** should free this memory by calling [sqlite3_free()].
 
4052
**
 
4053
** ^Extension loading must be enabled using
 
4054
** [sqlite3_enable_load_extension()] prior to calling this API,
 
4055
** otherwise an error will be returned.
 
4056
**
 
4057
** See also the [load_extension() SQL function].
4136
4058
*/
4137
4059
SQLITE_API int sqlite3_load_extension(
4138
4060
  sqlite3 *db,          /* Load the extension into this database connection */
4142
4064
);
4143
4065
 
4144
4066
/*
4145
 
** CAPI3REF: Enable Or Disable Extension Loading {H12620} <S20500>
 
4067
** CAPI3REF: Enable Or Disable Extension Loading
4146
4068
**
4147
 
** So as not to open security holes in older applications that are
 
4069
** ^So as not to open security holes in older applications that are
4148
4070
** unprepared to deal with extension loading, and as a means of disabling
4149
4071
** extension loading while evaluating user-entered SQL, the following API
4150
4072
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
4151
4073
**
4152
 
** Extension loading is off by default. See ticket #1863.
4153
 
**
4154
 
** {H12621} Call the sqlite3_enable_load_extension() routine with onoff==1
4155
 
**          to turn extension loading on and call it with onoff==0 to turn
4156
 
**          it back off again.
4157
 
**
4158
 
** {H12622} Extension loading is off by default.
 
4074
** ^Extension loading is off by default. See ticket #1863.
 
4075
** ^Call the sqlite3_enable_load_extension() routine with onoff==1
 
4076
** to turn extension loading on and call it with onoff==0 to turn
 
4077
** it back off again.
4159
4078
*/
4160
4079
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4161
4080
 
4162
4081
/*
4163
 
** CAPI3REF: Automatically Load An Extensions {H12640} <S20500>
 
4082
** CAPI3REF: Automatically Load An Extensions
4164
4083
**
4165
 
** This API can be invoked at program startup in order to register
 
4084
** ^This API can be invoked at program startup in order to register
4166
4085
** one or more statically linked extensions that will be available
4167
 
** to all new [database connections]. {END}
4168
 
**
4169
 
** This routine stores a pointer to the extension in an array that is
4170
 
** obtained from [sqlite3_malloc()].  If you run a memory leak checker
4171
 
** on your program and it reports a leak because of this array, invoke
4172
 
** [sqlite3_reset_auto_extension()] prior to shutdown to free the memory.
4173
 
**
4174
 
** {H12641} This function registers an extension entry point that is
4175
 
**          automatically invoked whenever a new [database connection]
4176
 
**          is opened using [sqlite3_open()], [sqlite3_open16()],
4177
 
**          or [sqlite3_open_v2()].
4178
 
**
4179
 
** {H12642} Duplicate extensions are detected so calling this routine
4180
 
**          multiple times with the same extension is harmless.
4181
 
**
4182
 
** {H12643} This routine stores a pointer to the extension in an array
4183
 
**          that is obtained from [sqlite3_malloc()].
4184
 
**
4185
 
** {H12644} Automatic extensions apply across all threads.
 
4086
** to all new [database connections].
 
4087
**
 
4088
** ^(This routine stores a pointer to the extension entry point
 
4089
** in an array that is obtained from [sqlite3_malloc()].  That memory
 
4090
** is deallocated by [sqlite3_reset_auto_extension()].)^
 
4091
**
 
4092
** ^This function registers an extension entry point that is
 
4093
** automatically invoked whenever a new [database connection]
 
4094
** is opened using [sqlite3_open()], [sqlite3_open16()],
 
4095
** or [sqlite3_open_v2()].
 
4096
** ^Duplicate extensions are detected so calling this routine
 
4097
** multiple times with the same extension is harmless.
 
4098
** ^Automatic extensions apply across all threads.
4186
4099
*/
4187
4100
SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
4188
4101
 
4189
4102
/*
4190
 
** CAPI3REF: Reset Automatic Extension Loading {H12660} <S20500>
4191
 
**
4192
 
** This function disables all previously registered automatic
4193
 
** extensions. {END}  It undoes the effect of all prior
4194
 
** [sqlite3_auto_extension()] calls.
4195
 
**
4196
 
** {H12661} This function disables all previously registered
4197
 
**          automatic extensions.
4198
 
**
4199
 
** {H12662} This function disables automatic extensions in all threads.
 
4103
** CAPI3REF: Reset Automatic Extension Loading
 
4104
**
 
4105
** ^(This function disables all previously registered automatic
 
4106
** extensions. It undoes the effect of all prior
 
4107
** [sqlite3_auto_extension()] calls.)^
 
4108
**
 
4109
** ^This function disables automatic extensions in all threads.
4200
4110
*/
4201
4111
SQLITE_API void sqlite3_reset_auto_extension(void);
4202
4112
 
4220
4130
typedef struct sqlite3_module sqlite3_module;
4221
4131
 
4222
4132
/*
4223
 
** CAPI3REF: Virtual Table Object {H18000} <S20400>
 
4133
** CAPI3REF: Virtual Table Object
4224
4134
** KEYWORDS: sqlite3_module {virtual table module}
4225
4135
** EXPERIMENTAL
4226
4136
**
4228
4138
** defines the implementation of a [virtual tables].  
4229
4139
** This structure consists mostly of methods for the module.
4230
4140
**
4231
 
** A virtual table module is created by filling in a persistent
 
4141
** ^A virtual table module is created by filling in a persistent
4232
4142
** instance of this structure and passing a pointer to that instance
4233
4143
** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
4234
 
** The registration remains valid until it is replaced by a different
 
4144
** ^The registration remains valid until it is replaced by a different
4235
4145
** module or until the [database connection] closes.  The content
4236
4146
** of this structure must not change while it is registered with
4237
4147
** any database connection.
4267
4177
};
4268
4178
 
4269
4179
/*
4270
 
** CAPI3REF: Virtual Table Indexing Information {H18100} <S20400>
 
4180
** CAPI3REF: Virtual Table Indexing Information
4271
4181
** KEYWORDS: sqlite3_index_info
4272
4182
** EXPERIMENTAL
4273
4183
**
4277
4187
** inputs to xBestIndex and are read-only.  xBestIndex inserts its
4278
4188
** results into the **Outputs** fields.
4279
4189
**
4280
 
** The aConstraint[] array records WHERE clause constraints of the form:
 
4190
** ^(The aConstraint[] array records WHERE clause constraints of the form:
4281
4191
**
4282
4192
** <pre>column OP expr</pre>
4283
4193
**
4284
 
** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.  The particular operator is
4285
 
** stored in aConstraint[].op.  The index of the column is stored in
4286
 
** aConstraint[].iColumn.  aConstraint[].usable is TRUE if the
 
4194
** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
 
4195
** stored in aConstraint[].op.)^  ^(The index of the column is stored in
 
4196
** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
4287
4197
** expr on the right-hand side can be evaluated (and thus the constraint
4288
 
** is usable) and false if it cannot.
 
4198
** is usable) and false if it cannot.)^
4289
4199
**
4290
 
** The optimizer automatically inverts terms of the form "expr OP column"
 
4200
** ^The optimizer automatically inverts terms of the form "expr OP column"
4291
4201
** and makes other simplifications to the WHERE clause in an attempt to
4292
4202
** get as many WHERE clause terms into the form shown above as possible.
4293
 
** The aConstraint[] array only reports WHERE clause terms in the correct
4294
 
** form that refer to the particular virtual table being queried.
 
4203
** ^The aConstraint[] array only reports WHERE clause terms that are
 
4204
** relevant to the particular virtual table being queried.
4295
4205
**
4296
 
** Information about the ORDER BY clause is stored in aOrderBy[].
4297
 
** Each term of aOrderBy records a column of the ORDER BY clause.
 
4206
** ^Information about the ORDER BY clause is stored in aOrderBy[].
 
4207
** ^Each term of aOrderBy records a column of the ORDER BY clause.
4298
4208
**
4299
4209
** The [xBestIndex] method must fill aConstraintUsage[] with information
4300
 
** about what parameters to pass to xFilter.  If argvIndex>0 then
 
4210
** about what parameters to pass to xFilter.  ^If argvIndex>0 then
4301
4211
** the right-hand side of the corresponding aConstraint[] is evaluated
4302
 
** and becomes the argvIndex-th entry in argv.  If aConstraintUsage[].omit
 
4212
** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
4303
4213
** is true, then the constraint is assumed to be fully handled by the
4304
 
** virtual table and is not checked again by SQLite.
 
4214
** virtual table and is not checked again by SQLite.)^
4305
4215
**
4306
 
** The idxNum and idxPtr values are recorded and passed into the
 
4216
** ^The idxNum and idxPtr values are recorded and passed into the
4307
4217
** [xFilter] method.
4308
 
** [sqlite3_free()] is used to free idxPtr if and only iff
 
4218
** ^[sqlite3_free()] is used to free idxPtr if and only if
4309
4219
** needToFreeIdxPtr is true.
4310
4220
**
4311
 
** The orderByConsumed means that output from [xFilter]/[xNext] will occur in
 
4221
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
4312
4222
** the correct order to satisfy the ORDER BY clause so that no separate
4313
4223
** sorting step is required.
4314
4224
**
4315
 
** The estimatedCost value is an estimate of the cost of doing the
 
4225
** ^The estimatedCost value is an estimate of the cost of doing the
4316
4226
** particular lookup.  A full scan of a table with N entries should have
4317
4227
** a cost of N.  A binary search of a table of N entries should have a
4318
4228
** cost of approximately log(N).
4350
4260
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
4351
4261
 
4352
4262
/*
4353
 
** CAPI3REF: Register A Virtual Table Implementation {H18200} <S20400>
 
4263
** CAPI3REF: Register A Virtual Table Implementation
4354
4264
** EXPERIMENTAL
4355
4265
**
4356
 
** This routine is used to register a new [virtual table module] name.
4357
 
** Module names must be registered before
4358
 
** creating a new [virtual table] using the module, or before using a
 
4266
** ^These routines are used to register a new [virtual table module] name.
 
4267
** ^Module names must be registered before
 
4268
** creating a new [virtual table] using the module and before using a
4359
4269
** preexisting [virtual table] for the module.
4360
4270
**
4361
 
** The module name is registered on the [database connection] specified
4362
 
** by the first parameter.  The name of the module is given by the 
4363
 
** second parameter.  The third parameter is a pointer to
4364
 
** the implementation of the [virtual table module].   The fourth
 
4271
** ^The module name is registered on the [database connection] specified
 
4272
** by the first parameter.  ^The name of the module is given by the 
 
4273
** second parameter.  ^The third parameter is a pointer to
 
4274
** the implementation of the [virtual table module].   ^The fourth
4365
4275
** parameter is an arbitrary client data pointer that is passed through
4366
4276
** into the [xCreate] and [xConnect] methods of the virtual table module
4367
4277
** when a new virtual table is be being created or reinitialized.
4368
4278
**
4369
 
** This interface has exactly the same effect as calling
4370
 
** [sqlite3_create_module_v2()] with a NULL client data destructor.
 
4279
** ^The sqlite3_create_module_v2() interface has a fifth parameter which
 
4280
** is a pointer to a destructor for the pClientData.  ^SQLite will
 
4281
** invoke the destructor function (if it is not NULL) when SQLite
 
4282
** no longer needs the pClientData pointer.  ^The sqlite3_create_module()
 
4283
** interface is equivalent to sqlite3_create_module_v2() with a NULL
 
4284
** destructor.
4371
4285
*/
4372
4286
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4373
4287
  sqlite3 *db,               /* SQLite connection to register module with */
4375
4289
  const sqlite3_module *p,   /* Methods for the module */
4376
4290
  void *pClientData          /* Client data for xCreate/xConnect */
4377
4291
);
4378
 
 
4379
 
/*
4380
 
** CAPI3REF: Register A Virtual Table Implementation {H18210} <S20400>
4381
 
** EXPERIMENTAL
4382
 
**
4383
 
** This routine is identical to the [sqlite3_create_module()] method,
4384
 
** except that it has an extra parameter to specify 
4385
 
** a destructor function for the client data pointer.  SQLite will
4386
 
** invoke the destructor function (if it is not NULL) when SQLite
4387
 
** no longer needs the pClientData pointer.  
4388
 
*/
4389
4292
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4390
4293
  sqlite3 *db,               /* SQLite connection to register module with */
4391
4294
  const char *zName,         /* Name of the module */
4395
4298
);
4396
4299
 
4397
4300
/*
4398
 
** CAPI3REF: Virtual Table Instance Object {H18010} <S20400>
 
4301
** CAPI3REF: Virtual Table Instance Object
4399
4302
** KEYWORDS: sqlite3_vtab
4400
4303
** EXPERIMENTAL
4401
4304
**
4402
4305
** Every [virtual table module] implementation uses a subclass
4403
 
** of the following structure to describe a particular instance
 
4306
** of this object to describe a particular instance
4404
4307
** of the [virtual table].  Each subclass will
4405
4308
** be tailored to the specific needs of the module implementation.
4406
4309
** The purpose of this superclass is to define certain fields that are
4407
4310
** common to all module implementations.
4408
4311
**
4409
 
** Virtual tables methods can set an error message by assigning a
 
4312
** ^Virtual tables methods can set an error message by assigning a
4410
4313
** string obtained from [sqlite3_mprintf()] to zErrMsg.  The method should
4411
4314
** take care that any prior string is freed by a call to [sqlite3_free()]
4412
 
** prior to assigning a new string to zErrMsg.  After the error message
 
4315
** prior to assigning a new string to zErrMsg.  ^After the error message
4413
4316
** is delivered up to the client application, the string will be automatically
4414
4317
** freed by sqlite3_free() and the zErrMsg field will be zeroed.
4415
4318
*/
4421
4324
};
4422
4325
 
4423
4326
/*
4424
 
** CAPI3REF: Virtual Table Cursor Object  {H18020} <S20400>
 
4327
** CAPI3REF: Virtual Table Cursor Object
4425
4328
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4426
4329
** EXPERIMENTAL
4427
4330
**
4430
4333
** [virtual table] and are used
4431
4334
** to loop through the virtual table.  Cursors are created using the
4432
4335
** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
4433
 
** by the [sqlite3_module.xClose | xClose] method.  Cussors are used
 
4336
** by the [sqlite3_module.xClose | xClose] method.  Cursors are used
4434
4337
** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
4435
4338
** of the module.  Each module implementation will define
4436
4339
** the content of a cursor structure to suit its own needs.
4444
4347
};
4445
4348
 
4446
4349
/*
4447
 
** CAPI3REF: Declare The Schema Of A Virtual Table {H18280} <S20400>
 
4350
** CAPI3REF: Declare The Schema Of A Virtual Table
4448
4351
** EXPERIMENTAL
4449
4352
**
4450
 
** The [xCreate] and [xConnect] methods of a
 
4353
** ^The [xCreate] and [xConnect] methods of a
4451
4354
** [virtual table module] call this interface
4452
4355
** to declare the format (the names and datatypes of the columns) of
4453
4356
** the virtual tables they implement.
4455
4358
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4456
4359
 
4457
4360
/*
4458
 
** CAPI3REF: Overload A Function For A Virtual Table {H18300} <S20400>
 
4361
** CAPI3REF: Overload A Function For A Virtual Table
4459
4362
** EXPERIMENTAL
4460
4363
**
4461
 
** Virtual tables can provide alternative implementations of functions
 
4364
** ^(Virtual tables can provide alternative implementations of functions
4462
4365
** using the [xFindFunction] method of the [virtual table module].  
4463
4366
** But global versions of those functions
4464
 
** must exist in order to be overloaded.
 
4367
** must exist in order to be overloaded.)^
4465
4368
**
4466
 
** This API makes sure a global version of a function with a particular
 
4369
** ^(This API makes sure a global version of a function with a particular
4467
4370
** name and number of parameters exists.  If no such function exists
4468
 
** before this API is called, a new function is created.  The implementation
 
4371
** before this API is called, a new function is created.)^  ^The implementation
4469
4372
** of the new function always causes an exception to be thrown.  So
4470
4373
** the new function is not good for anything by itself.  Its only
4471
4374
** purpose is to be a placeholder function that can be overloaded
4486
4389
*/
4487
4390
 
4488
4391
/*
4489
 
** CAPI3REF: A Handle To An Open BLOB {H17800} <S30230>
 
4392
** CAPI3REF: A Handle To An Open BLOB
4490
4393
** KEYWORDS: {BLOB handle} {BLOB handles}
4491
4394
**
4492
4395
** An instance of this object represents an open BLOB on which
4493
4396
** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
4494
 
** Objects of this type are created by [sqlite3_blob_open()]
 
4397
** ^Objects of this type are created by [sqlite3_blob_open()]
4495
4398
** and destroyed by [sqlite3_blob_close()].
4496
 
** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
 
4399
** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
4497
4400
** can be used to read or write small subsections of the BLOB.
4498
 
** The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
 
4401
** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
4499
4402
*/
4500
4403
typedef struct sqlite3_blob sqlite3_blob;
4501
4404
 
4502
4405
/*
4503
 
** CAPI3REF: Open A BLOB For Incremental I/O {H17810} <S30230>
 
4406
** CAPI3REF: Open A BLOB For Incremental I/O
4504
4407
**
4505
 
** This interfaces opens a [BLOB handle | handle] to the BLOB located
 
4408
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
4506
4409
** in row iRow, column zColumn, table zTable in database zDb;
4507
4410
** in other words, the same BLOB that would be selected by:
4508
4411
**
4509
4412
** <pre>
4510
4413
**     SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
4511
 
** </pre> {END}
 
4414
** </pre>)^
4512
4415
**
4513
 
** If the flags parameter is non-zero, then the BLOB is opened for read
4514
 
** and write access. If it is zero, the BLOB is opened for read access.
4515
 
** It is not possible to open a column that is part of an index or primary 
 
4416
** ^If the flags parameter is non-zero, then the BLOB is opened for read
 
4417
** and write access. ^If it is zero, the BLOB is opened for read access.
 
4418
** ^It is not possible to open a column that is part of an index or primary 
4516
4419
** key for writing. ^If [foreign key constraints] are enabled, it is 
4517
4420
** not possible to open a column that is part of a [child key] for writing.
4518
4421
**
4519
 
** Note that the database name is not the filename that contains
 
4422
** ^Note that the database name is not the filename that contains
4520
4423
** the database but rather the symbolic name of the database that
4521
 
** is assigned when the database is connected using [ATTACH].
4522
 
** For the main database file, the database name is "main".
4523
 
** For TEMP tables, the database name is "temp".
 
4424
** appears after the AS keyword when the database is connected using [ATTACH].
 
4425
** ^For the main database file, the database name is "main".
 
4426
** ^For TEMP tables, the database name is "temp".
4524
4427
**
4525
 
** On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
 
4428
** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
4526
4429
** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
4527
 
** to be a null pointer.
4528
 
** This function sets the [database connection] error code and message
 
4430
** to be a null pointer.)^
 
4431
** ^This function sets the [database connection] error code and message
4529
4432
** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
4530
 
** functions.  Note that the *ppBlob variable is always initialized in a
 
4433
** functions. ^Note that the *ppBlob variable is always initialized in a
4531
4434
** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
4532
4435
** regardless of the success or failure of this routine.
4533
4436
**
4534
 
** If the row that a BLOB handle points to is modified by an
 
4437
** ^(If the row that a BLOB handle points to is modified by an
4535
4438
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
4536
4439
** then the BLOB handle is marked as "expired".
4537
4440
** This is true if any column of the row is changed, even a column
4538
 
** other than the one the BLOB handle is open on.
4539
 
** Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
 
4441
** other than the one the BLOB handle is open on.)^
 
4442
** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
4540
4443
** a expired BLOB handle fail with an return code of [SQLITE_ABORT].
4541
 
** Changes written into a BLOB prior to the BLOB expiring are not
4542
 
** rollback by the expiration of the BLOB.  Such changes will eventually
4543
 
** commit if the transaction continues to completion.
 
4444
** ^(Changes written into a BLOB prior to the BLOB expiring are not
 
4445
** rolled back by the expiration of the BLOB.  Such changes will eventually
 
4446
** commit if the transaction continues to completion.)^
4544
4447
**
4545
 
** Use the [sqlite3_blob_bytes()] interface to determine the size of
4546
 
** the opened blob.  The size of a blob may not be changed by this
 
4448
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
 
4449
** the opened blob.  ^The size of a blob may not be changed by this
4547
4450
** interface.  Use the [UPDATE] SQL command to change the size of a
4548
4451
** blob.
4549
4452
**
4550
 
** The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
 
4453
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
4551
4454
** and the built-in [zeroblob] SQL function can be used, if desired,
4552
4455
** to create an empty, zero-filled blob in which to read or write using
4553
4456
** this interface.
4554
4457
**
4555
4458
** To avoid a resource leak, every open [BLOB handle] should eventually
4556
4459
** be released by a call to [sqlite3_blob_close()].
4557
 
**
4558
 
** Requirements:
4559
 
** [H17813] [H17814] [H17816] [H17819] [H17821] [H17824]
4560
4460
*/
4561
4461
SQLITE_API int sqlite3_blob_open(
4562
4462
  sqlite3*,
4569
4469
);
4570
4470
 
4571
4471
/*
4572
 
** CAPI3REF: Close A BLOB Handle {H17830} <S30230>
4573
 
**
4574
 
** Closes an open [BLOB handle].
4575
 
**
4576
 
** Closing a BLOB shall cause the current transaction to commit
 
4472
** CAPI3REF: Close A BLOB Handle
 
4473
**
 
4474
** ^Closes an open [BLOB handle].
 
4475
**
 
4476
** ^Closing a BLOB shall cause the current transaction to commit
4577
4477
** if there are no other BLOBs, no pending prepared statements, and the
4578
4478
** database connection is in [autocommit mode].
4579
 
** If any writes were made to the BLOB, they might be held in cache
 
4479
** ^If any writes were made to the BLOB, they might be held in cache
4580
4480
** until the close operation if they will fit.
4581
4481
**
4582
 
** Closing the BLOB often forces the changes
 
4482
** ^(Closing the BLOB often forces the changes
4583
4483
** out to disk and so if any I/O errors occur, they will likely occur
4584
4484
** at the time when the BLOB is closed.  Any errors that occur during
4585
 
** closing are reported as a non-zero return value.
4586
 
**
4587
 
** The BLOB is closed unconditionally.  Even if this routine returns
4588
 
** an error code, the BLOB is still closed.
4589
 
**
4590
 
** Calling this routine with a null pointer (which as would be returned
4591
 
** by failed call to [sqlite3_blob_open()]) is a harmless no-op.
4592
 
**
4593
 
** Requirements:
4594
 
** [H17833] [H17836] [H17839]
 
4485
** closing are reported as a non-zero return value.)^
 
4486
**
 
4487
** ^(The BLOB is closed unconditionally.  Even if this routine returns
 
4488
** an error code, the BLOB is still closed.)^
 
4489
**
 
4490
** ^Calling this routine with a null pointer (such as would be returned
 
4491
** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
4595
4492
*/
4596
4493
SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
4597
4494
 
4598
4495
/*
4599
 
** CAPI3REF: Return The Size Of An Open BLOB {H17840} <S30230>
 
4496
** CAPI3REF: Return The Size Of An Open BLOB
4600
4497
**
4601
 
** Returns the size in bytes of the BLOB accessible via the 
4602
 
** successfully opened [BLOB handle] in its only argument.  The
 
4498
** ^Returns the size in bytes of the BLOB accessible via the 
 
4499
** successfully opened [BLOB handle] in its only argument.  ^The
4603
4500
** incremental blob I/O routines can only read or overwriting existing
4604
4501
** blob content; they cannot change the size of a blob.
4605
4502
**
4607
4504
** by a prior successful call to [sqlite3_blob_open()] and which has not
4608
4505
** been closed by [sqlite3_blob_close()].  Passing any other pointer in
4609
4506
** to this routine results in undefined and probably undesirable behavior.
4610
 
**
4611
 
** Requirements:
4612
 
** [H17843]
4613
4507
*/
4614
4508
SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
4615
4509
 
4616
4510
/*
4617
 
** CAPI3REF: Read Data From A BLOB Incrementally {H17850} <S30230>
 
4511
** CAPI3REF: Read Data From A BLOB Incrementally
4618
4512
**
4619
 
** This function is used to read data from an open [BLOB handle] into a
 
4513
** ^(This function is used to read data from an open [BLOB handle] into a
4620
4514
** caller-supplied buffer. N bytes of data are copied into buffer Z
4621
 
** from the open BLOB, starting at offset iOffset.
 
4515
** from the open BLOB, starting at offset iOffset.)^
4622
4516
**
4623
 
** If offset iOffset is less than N bytes from the end of the BLOB,
4624
 
** [SQLITE_ERROR] is returned and no data is read.  If N or iOffset is
 
4517
** ^If offset iOffset is less than N bytes from the end of the BLOB,
 
4518
** [SQLITE_ERROR] is returned and no data is read.  ^If N or iOffset is
4625
4519
** less than zero, [SQLITE_ERROR] is returned and no data is read.
4626
 
** The size of the blob (and hence the maximum value of N+iOffset)
 
4520
** ^The size of the blob (and hence the maximum value of N+iOffset)
4627
4521
** can be determined using the [sqlite3_blob_bytes()] interface.
4628
4522
**
4629
 
** An attempt to read from an expired [BLOB handle] fails with an
 
4523
** ^An attempt to read from an expired [BLOB handle] fails with an
4630
4524
** error code of [SQLITE_ABORT].
4631
4525
**
4632
 
** On success, SQLITE_OK is returned.
4633
 
** Otherwise, an [error code] or an [extended error code] is returned.
 
4526
** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
 
4527
** Otherwise, an [error code] or an [extended error code] is returned.)^
4634
4528
**
4635
4529
** This routine only works on a [BLOB handle] which has been created
4636
4530
** by a prior successful call to [sqlite3_blob_open()] and which has not
4638
4532
** to this routine results in undefined and probably undesirable behavior.
4639
4533
**
4640
4534
** See also: [sqlite3_blob_write()].
4641
 
**
4642
 
** Requirements:
4643
 
** [H17853] [H17856] [H17859] [H17862] [H17863] [H17865] [H17868]
4644
4535
*/
4645
4536
SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
4646
4537
 
4647
4538
/*
4648
 
** CAPI3REF: Write Data Into A BLOB Incrementally {H17870} <S30230>
 
4539
** CAPI3REF: Write Data Into A BLOB Incrementally
4649
4540
**
4650
 
** This function is used to write data into an open [BLOB handle] from a
4651
 
** caller-supplied buffer. N bytes of data are copied from the buffer Z
 
4541
** ^This function is used to write data into an open [BLOB handle] from a
 
4542
** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
4652
4543
** into the open BLOB, starting at offset iOffset.
4653
4544
**
4654
 
** If the [BLOB handle] passed as the first argument was not opened for
 
4545
** ^If the [BLOB handle] passed as the first argument was not opened for
4655
4546
** writing (the flags parameter to [sqlite3_blob_open()] was zero),
4656
4547
** this function returns [SQLITE_READONLY].
4657
4548
**
4658
 
** This function may only modify the contents of the BLOB; it is
 
4549
** ^This function may only modify the contents of the BLOB; it is
4659
4550
** not possible to increase the size of a BLOB using this API.
4660
 
** If offset iOffset is less than N bytes from the end of the BLOB,
4661
 
** [SQLITE_ERROR] is returned and no data is written.  If N is
 
4551
** ^If offset iOffset is less than N bytes from the end of the BLOB,
 
4552
** [SQLITE_ERROR] is returned and no data is written.  ^If N is
4662
4553
** less than zero [SQLITE_ERROR] is returned and no data is written.
4663
4554
** The size of the BLOB (and hence the maximum value of N+iOffset)
4664
4555
** can be determined using the [sqlite3_blob_bytes()] interface.
4665
4556
**
4666
 
** An attempt to write to an expired [BLOB handle] fails with an
4667
 
** error code of [SQLITE_ABORT].  Writes to the BLOB that occurred
 
4557
** ^An attempt to write to an expired [BLOB handle] fails with an
 
4558
** error code of [SQLITE_ABORT].  ^Writes to the BLOB that occurred
4668
4559
** before the [BLOB handle] expired are not rolled back by the
4669
4560
** expiration of the handle, though of course those changes might
4670
4561
** have been overwritten by the statement that expired the BLOB handle
4671
4562
** or by other independent statements.
4672
4563
**
4673
 
** On success, SQLITE_OK is returned.
4674
 
** Otherwise, an  [error code] or an [extended error code] is returned.
 
4564
** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
 
4565
** Otherwise, an  [error code] or an [extended error code] is returned.)^
4675
4566
**
4676
4567
** This routine only works on a [BLOB handle] which has been created
4677
4568
** by a prior successful call to [sqlite3_blob_open()] and which has not
4679
4570
** to this routine results in undefined and probably undesirable behavior.
4680
4571
**
4681
4572
** See also: [sqlite3_blob_read()].
4682
 
**
4683
 
** Requirements:
4684
 
** [H17873] [H17874] [H17875] [H17876] [H17877] [H17879] [H17882] [H17885]
4685
 
** [H17888]
4686
4573
*/
4687
4574
SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
4688
4575
 
4689
4576
/*
4690
 
** CAPI3REF: Virtual File System Objects {H11200} <S20100>
 
4577
** CAPI3REF: Virtual File System Objects
4691
4578
**
4692
4579
** A virtual filesystem (VFS) is an [sqlite3_vfs] object
4693
4580
** that SQLite uses to interact
4696
4583
** New VFSes can be registered and existing VFSes can be unregistered.
4697
4584
** The following interfaces are provided.
4698
4585
**
4699
 
** The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
4700
 
** Names are case sensitive.
4701
 
** Names are zero-terminated UTF-8 strings.
4702
 
** If there is no match, a NULL pointer is returned.
4703
 
** If zVfsName is NULL then the default VFS is returned.
 
4586
** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
 
4587
** ^Names are case sensitive.
 
4588
** ^Names are zero-terminated UTF-8 strings.
 
4589
** ^If there is no match, a NULL pointer is returned.
 
4590
** ^If zVfsName is NULL then the default VFS is returned.
4704
4591
**
4705
 
** New VFSes are registered with sqlite3_vfs_register().
4706
 
** Each new VFS becomes the default VFS if the makeDflt flag is set.
4707
 
** The same VFS can be registered multiple times without injury.
4708
 
** To make an existing VFS into the default VFS, register it again
 
4592
** ^New VFSes are registered with sqlite3_vfs_register().
 
4593
** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
 
4594
** ^The same VFS can be registered multiple times without injury.
 
4595
** ^To make an existing VFS into the default VFS, register it again
4709
4596
** with the makeDflt flag set.  If two different VFSes with the
4710
4597
** same name are registered, the behavior is undefined.  If a
4711
4598
** VFS is registered with a name that is NULL or an empty string,
4712
4599
** then the behavior is undefined.
4713
4600
**
4714
 
** Unregister a VFS with the sqlite3_vfs_unregister() interface.
4715
 
** If the default VFS is unregistered, another VFS is chosen as
4716
 
** the default.  The choice for the new VFS is arbitrary.
4717
 
**
4718
 
** Requirements:
4719
 
** [H11203] [H11206] [H11209] [H11212] [H11215] [H11218]
 
4601
** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
 
4602
** ^(If the default VFS is unregistered, another VFS is chosen as
 
4603
** the default.  The choice for the new VFS is arbitrary.)^
4720
4604
*/
4721
4605
SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
4722
4606
SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
4723
4607
SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
4724
4608
 
4725
4609
/*
4726
 
** CAPI3REF: Mutexes {H17000} <S20000>
 
4610
** CAPI3REF: Mutexes
4727
4611
**
4728
4612
** The SQLite core uses these routines for thread
4729
4613
** synchronization. Though they are intended for internal
4732
4616
**
4733
4617
** The SQLite source code contains multiple implementations
4734
4618
** of these mutex routines.  An appropriate implementation
4735
 
** is selected automatically at compile-time.  The following
 
4619
** is selected automatically at compile-time.  ^(The following
4736
4620
** implementations are available in the SQLite core:
4737
4621
**
4738
4622
** <ul>
4740
4624
** <li>   SQLITE_MUTEX_PTHREAD
4741
4625
** <li>   SQLITE_MUTEX_W32
4742
4626
** <li>   SQLITE_MUTEX_NOOP
4743
 
** </ul>
 
4627
** </ul>)^
4744
4628
**
4745
 
** The SQLITE_MUTEX_NOOP implementation is a set of routines
 
4629
** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
4746
4630
** that does no real locking and is appropriate for use in
4747
 
** a single-threaded application.  The SQLITE_MUTEX_OS2,
 
4631
** a single-threaded application.  ^The SQLITE_MUTEX_OS2,
4748
4632
** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
4749
4633
** are appropriate for use on OS/2, Unix, and Windows.
4750
4634
**
4751
 
** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
 
4635
** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
4752
4636
** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
4753
4637
** implementation is included with the library. In this case the
4754
4638
** application must supply a custom mutex implementation using the
4755
4639
** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
4756
4640
** before calling sqlite3_initialize() or any other public sqlite3_
4757
 
** function that calls sqlite3_initialize().
 
4641
** function that calls sqlite3_initialize().)^
4758
4642
**
4759
 
** {H17011} The sqlite3_mutex_alloc() routine allocates a new
4760
 
** mutex and returns a pointer to it. {H17012} If it returns NULL
4761
 
** that means that a mutex could not be allocated. {H17013} SQLite
4762
 
** will unwind its stack and return an error. {H17014} The argument
 
4643
** ^The sqlite3_mutex_alloc() routine allocates a new
 
4644
** mutex and returns a pointer to it. ^If it returns NULL
 
4645
** that means that a mutex could not be allocated.  ^SQLite
 
4646
** will unwind its stack and return an error.  ^(The argument
4763
4647
** to sqlite3_mutex_alloc() is one of these integer constants:
4764
4648
**
4765
4649
** <ul>
4771
4655
** <li>  SQLITE_MUTEX_STATIC_PRNG
4772
4656
** <li>  SQLITE_MUTEX_STATIC_LRU
4773
4657
** <li>  SQLITE_MUTEX_STATIC_LRU2
4774
 
** </ul>
 
4658
** </ul>)^
4775
4659
**
4776
 
** {H17015} The first two constants cause sqlite3_mutex_alloc() to create
4777
 
** a new mutex.  The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
4778
 
** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END}
 
4660
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
 
4661
** cause sqlite3_mutex_alloc() to create
 
4662
** a new mutex.  ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
 
4663
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
4779
4664
** The mutex implementation does not need to make a distinction
4780
4665
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
4781
 
** not want to.  {H17016} But SQLite will only request a recursive mutex in
4782
 
** cases where it really needs one.  {END} If a faster non-recursive mutex
 
4666
** not want to.  ^SQLite will only request a recursive mutex in
 
4667
** cases where it really needs one.  ^If a faster non-recursive mutex
4783
4668
** implementation is available on the host platform, the mutex subsystem
4784
4669
** might return such a mutex in response to SQLITE_MUTEX_FAST.
4785
4670
**
4786
 
** {H17017} The other allowed parameters to sqlite3_mutex_alloc() each return
4787
 
** a pointer to a static preexisting mutex. {END}  Six static mutexes are
 
4671
** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
 
4672
** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
 
4673
** a pointer to a static preexisting mutex.  ^Six static mutexes are
4788
4674
** used by the current version of SQLite.  Future versions of SQLite
4789
4675
** may add additional static mutexes.  Static mutexes are for internal
4790
4676
** use by SQLite only.  Applications that use SQLite mutexes should
4791
4677
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
4792
4678
** SQLITE_MUTEX_RECURSIVE.
4793
4679
**
4794
 
** {H17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
 
4680
** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
4795
4681
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
4796
 
** returns a different mutex on every call.  {H17034} But for the static
 
4682
** returns a different mutex on every call.  ^But for the static
4797
4683
** mutex types, the same mutex is returned on every call that has
4798
4684
** the same type number.
4799
4685
**
4800
 
** {H17019} The sqlite3_mutex_free() routine deallocates a previously
4801
 
** allocated dynamic mutex. {H17020} SQLite is careful to deallocate every
4802
 
** dynamic mutex that it allocates. {A17021} The dynamic mutexes must not be in
4803
 
** use when they are deallocated. {A17022} Attempting to deallocate a static
4804
 
** mutex results in undefined behavior. {H17023} SQLite never deallocates
4805
 
** a static mutex. {END}
 
4686
** ^The sqlite3_mutex_free() routine deallocates a previously
 
4687
** allocated dynamic mutex.  ^SQLite is careful to deallocate every
 
4688
** dynamic mutex that it allocates.  The dynamic mutexes must not be in
 
4689
** use when they are deallocated.  Attempting to deallocate a static
 
4690
** mutex results in undefined behavior.  ^SQLite never deallocates
 
4691
** a static mutex.
4806
4692
**
4807
 
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
4808
 
** to enter a mutex. {H17024} If another thread is already within the mutex,
 
4693
** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
 
4694
** to enter a mutex.  ^If another thread is already within the mutex,
4809
4695
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
4810
 
** SQLITE_BUSY. {H17025}  The sqlite3_mutex_try() interface returns [SQLITE_OK]
4811
 
** upon successful entry.  {H17026} Mutexes created using
 
4696
** SQLITE_BUSY.  ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
 
4697
** upon successful entry.  ^(Mutexes created using
4812
4698
** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
4813
 
** {H17027} In such cases the,
 
4699
** In such cases the,
4814
4700
** mutex must be exited an equal number of times before another thread
4815
 
** can enter.  {A17028} If the same thread tries to enter any other
 
4701
** can enter.)^  ^(If the same thread tries to enter any other
4816
4702
** kind of mutex more than once, the behavior is undefined.
4817
 
** {H17029} SQLite will never exhibit
4818
 
** such behavior in its own use of mutexes.
 
4703
** SQLite will never exhibit
 
4704
** such behavior in its own use of mutexes.)^
4819
4705
**
4820
 
** Some systems (for example, Windows 95) do not support the operation
 
4706
** ^(Some systems (for example, Windows 95) do not support the operation
4821
4707
** implemented by sqlite3_mutex_try().  On those systems, sqlite3_mutex_try()
4822
 
** will always return SQLITE_BUSY.  {H17030} The SQLite core only ever uses
4823
 
** sqlite3_mutex_try() as an optimization so this is acceptable behavior.
 
4708
** will always return SQLITE_BUSY.  The SQLite core only ever uses
 
4709
** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
4824
4710
**
4825
 
** {H17031} The sqlite3_mutex_leave() routine exits a mutex that was
4826
 
** previously entered by the same thread.  {A17032} The behavior
 
4711
** ^The sqlite3_mutex_leave() routine exits a mutex that was
 
4712
** previously entered by the same thread.   ^(The behavior
4827
4713
** is undefined if the mutex is not currently entered by the
4828
 
** calling thread or is not currently allocated.  {H17033} SQLite will
4829
 
** never do either. {END}
 
4714
** calling thread or is not currently allocated.  SQLite will
 
4715
** never do either.)^
4830
4716
**
4831
 
** If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
 
4717
** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
4832
4718
** sqlite3_mutex_leave() is a NULL pointer, then all three routines
4833
4719
** behave as no-ops.
4834
4720
**
4841
4727
SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
4842
4728
 
4843
4729
/*
4844
 
** CAPI3REF: Mutex Methods Object {H17120} <S20130>
 
4730
** CAPI3REF: Mutex Methods Object
4845
4731
** EXPERIMENTAL
4846
4732
**
4847
4733
** An instance of this structure defines the low-level routines
4857
4743
** output variable when querying the system for the current mutex
4858
4744
** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
4859
4745
**
4860
 
** The xMutexInit method defined by this structure is invoked as
 
4746
** ^The xMutexInit method defined by this structure is invoked as
4861
4747
** part of system initialization by the sqlite3_initialize() function.
4862
 
** {H17001} The xMutexInit routine shall be called by SQLite once for each
 
4748
** ^The xMutexInit routine is calle by SQLite exactly once for each
4863
4749
** effective call to [sqlite3_initialize()].
4864
4750
**
4865
 
** The xMutexEnd method defined by this structure is invoked as
 
4751
** ^The xMutexEnd method defined by this structure is invoked as
4866
4752
** part of system shutdown by the sqlite3_shutdown() function. The
4867
4753
** implementation of this method is expected to release all outstanding
4868
4754
** resources obtained by the mutex methods implementation, especially
4869
 
** those obtained by the xMutexInit method. {H17003} The xMutexEnd()
4870
 
** interface shall be invoked once for each call to [sqlite3_shutdown()].
 
4755
** those obtained by the xMutexInit method.  ^The xMutexEnd()
 
4756
** interface is invoked exactly once for each call to [sqlite3_shutdown()].
4871
4757
**
4872
 
** The remaining seven methods defined by this structure (xMutexAlloc,
 
4758
** ^(The remaining seven methods defined by this structure (xMutexAlloc,
4873
4759
** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
4874
4760
** xMutexNotheld) implement the following interfaces (respectively):
4875
4761
**
4881
4767
**   <li>  [sqlite3_mutex_leave()] </li>
4882
4768
**   <li>  [sqlite3_mutex_held()] </li>
4883
4769
**   <li>  [sqlite3_mutex_notheld()] </li>
4884
 
** </ul>
 
4770
** </ul>)^
4885
4771
**
4886
4772
** The only difference is that the public sqlite3_XXX functions enumerated
4887
4773
** above silently ignore any invocations that pass a NULL pointer instead
4891
4777
** (i.e. it is acceptable to provide an implementation that segfaults if
4892
4778
** it is passed a NULL pointer).
4893
4779
**
4894
 
** The xMutexInit() method must be threadsafe.  It must be harmless to
 
4780
** The xMutexInit() method must be threadsafe.  ^It must be harmless to
4895
4781
** invoke xMutexInit() mutiple times within the same process and without
4896
4782
** intervening calls to xMutexEnd().  Second and subsequent calls to
4897
4783
** xMutexInit() must be no-ops.
4898
4784
**
4899
 
** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
4900
 
** and its associates).  Similarly, xMutexAlloc() must not use SQLite memory
4901
 
** allocation for a static mutex.  However xMutexAlloc() may use SQLite
 
4785
** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
 
4786
** and its associates).  ^Similarly, xMutexAlloc() must not use SQLite memory
 
4787
** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
4902
4788
** memory allocation for a fast or recursive mutex.
4903
4789
**
4904
 
** SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
 
4790
** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
4905
4791
** called, but only if the prior call to xMutexInit returned SQLITE_OK.
4906
4792
** If xMutexInit fails in any way, it is expected to clean up after itself
4907
4793
** prior to returning.
4920
4806
};
4921
4807
 
4922
4808
/*
4923
 
** CAPI3REF: Mutex Verification Routines {H17080} <S20130> <S30800>
 
4809
** CAPI3REF: Mutex Verification Routines
4924
4810
**
4925
4811
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
4926
 
** are intended for use inside assert() statements. {H17081} The SQLite core
 
4812
** are intended for use inside assert() statements.  ^The SQLite core
4927
4813
** never uses these routines except inside an assert() and applications
4928
 
** are advised to follow the lead of the core.  {H17082} The core only
 
4814
** are advised to follow the lead of the core.  ^The SQLite core only
4929
4815
** provides implementations for these routines when it is compiled
4930
 
** with the SQLITE_DEBUG flag.  {A17087} External mutex implementations
 
4816
** with the SQLITE_DEBUG flag.  ^External mutex implementations
4931
4817
** are only required to provide these routines if SQLITE_DEBUG is
4932
4818
** defined and if NDEBUG is not defined.
4933
4819
**
4934
 
** {H17083} These routines should return true if the mutex in their argument
 
4820
** ^These routines should return true if the mutex in their argument
4935
4821
** is held or not held, respectively, by the calling thread.
4936
4822
**
4937
 
** {X17084} The implementation is not required to provided versions of these
 
4823
** ^The implementation is not required to provided versions of these
4938
4824
** routines that actually work. If the implementation does not provide working
4939
4825
** versions of these routines, it should at least provide stubs that always
4940
4826
** return true so that one does not get spurious assertion failures.
4941
4827
**
4942
 
** {H17085} If the argument to sqlite3_mutex_held() is a NULL pointer then
4943
 
** the routine should return 1.  {END} This seems counter-intuitive since
 
4828
** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
 
4829
** the routine should return 1.   This seems counter-intuitive since
4944
4830
** clearly the mutex cannot be held if it does not exist.  But the
4945
4831
** the reason the mutex does not exist is because the build is not
4946
4832
** using mutexes.  And we do not want the assert() containing the
4947
4833
** call to sqlite3_mutex_held() to fail, so a non-zero return is
4948
 
** the appropriate thing to do.  {H17086} The sqlite3_mutex_notheld()
 
4834
** the appropriate thing to do.  ^The sqlite3_mutex_notheld()
4949
4835
** interface should also return 1 when given a NULL pointer.
4950
4836
*/
 
4837
#ifndef NDEBUG
4951
4838
SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
4952
4839
SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
 
4840
#endif
4953
4841
 
4954
4842
/*
4955
 
** CAPI3REF: Mutex Types {H17001} <H17000>
 
4843
** CAPI3REF: Mutex Types
4956
4844
**
4957
4845
** The [sqlite3_mutex_alloc()] interface takes a single argument
4958
4846
** which is one of these integer constants.
4972
4860
#define SQLITE_MUTEX_STATIC_LRU2      7  /* lru page list */
4973
4861
 
4974
4862
/*
4975
 
** CAPI3REF: Retrieve the mutex for a database connection {H17002} <H17000>
 
4863
** CAPI3REF: Retrieve the mutex for a database connection
4976
4864
**
4977
 
** This interface returns a pointer the [sqlite3_mutex] object that 
 
4865
** ^This interface returns a pointer the [sqlite3_mutex] object that 
4978
4866
** serializes access to the [database connection] given in the argument
4979
4867
** when the [threading mode] is Serialized.
4980
 
** If the [threading mode] is Single-thread or Multi-thread then this
 
4868
** ^If the [threading mode] is Single-thread or Multi-thread then this
4981
4869
** routine returns a NULL pointer.
4982
4870
*/
4983
4871
SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
4984
4872
 
4985
4873
/*
4986
 
** CAPI3REF: Low-Level Control Of Database Files {H11300} <S30800>
 
4874
** CAPI3REF: Low-Level Control Of Database Files
4987
4875
**
4988
 
** {H11301} The [sqlite3_file_control()] interface makes a direct call to the
 
4876
** ^The [sqlite3_file_control()] interface makes a direct call to the
4989
4877
** xFileControl method for the [sqlite3_io_methods] object associated
4990
 
** with a particular database identified by the second argument. {H11302} The
4991
 
** name of the database is the name assigned to the database by the
4992
 
** <a href="lang_attach.html">ATTACH</a> SQL command that opened the
4993
 
** database. {H11303} To control the main database file, use the name "main"
4994
 
** or a NULL pointer. {H11304} The third and fourth parameters to this routine
 
4878
** with a particular database identified by the second argument. ^The
 
4879
** name of the database "main" for the main database or "temp" for the
 
4880
** TEMP database, or the name that appears after the AS keyword for
 
4881
** databases that are added using the [ATTACH] SQL command.
 
4882
** ^A NULL pointer can be used in place of "main" to refer to the
 
4883
** main database file.
 
4884
** ^The third and fourth parameters to this routine
4995
4885
** are passed directly through to the second and third parameters of
4996
 
** the xFileControl method.  {H11305} The return value of the xFileControl
 
4886
** the xFileControl method.  ^The return value of the xFileControl
4997
4887
** method becomes the return value of this routine.
4998
4888
**
4999
 
** {H11306} If the second parameter (zDbName) does not match the name of any
5000
 
** open database file, then SQLITE_ERROR is returned. {H11307} This error
 
4889
** ^If the second parameter (zDbName) does not match the name of any
 
4890
** open database file, then SQLITE_ERROR is returned.  ^This error
5001
4891
** code is not remembered and will not be recalled by [sqlite3_errcode()]
5002
 
** or [sqlite3_errmsg()]. {A11308} The underlying xFileControl method might
5003
 
** also return SQLITE_ERROR.  {A11309} There is no way to distinguish between
 
4892
** or [sqlite3_errmsg()].  The underlying xFileControl method might
 
4893
** also return SQLITE_ERROR.  There is no way to distinguish between
5004
4894
** an incorrect zDbName and an SQLITE_ERROR return from the underlying
5005
 
** xFileControl method. {END}
 
4895
** xFileControl method.
5006
4896
**
5007
4897
** See also: [SQLITE_FCNTL_LOCKSTATE]
5008
4898
*/
5009
4899
SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
5010
4900
 
5011
4901
/*
5012
 
** CAPI3REF: Testing Interface {H11400} <S30800>
 
4902
** CAPI3REF: Testing Interface
5013
4903
**
5014
 
** The sqlite3_test_control() interface is used to read out internal
 
4904
** ^The sqlite3_test_control() interface is used to read out internal
5015
4905
** state of SQLite and to inject faults into SQLite for testing
5016
 
** purposes.  The first parameter is an operation code that determines
 
4906
** purposes.  ^The first parameter is an operation code that determines
5017
4907
** the number, meaning, and operation of all subsequent parameters.
5018
4908
**
5019
4909
** This interface is not for use by applications.  It exists solely
5028
4918
SQLITE_API int sqlite3_test_control(int op, ...);
5029
4919
 
5030
4920
/*
5031
 
** CAPI3REF: Testing Interface Operation Codes {H11410} <H11400>
 
4921
** CAPI3REF: Testing Interface Operation Codes
5032
4922
**
5033
4923
** These constants are the valid operation code parameters used
5034
4924
** as the first argument to [sqlite3_test_control()].
5038
4928
** Applications should not use any of these parameters or the
5039
4929
** [sqlite3_test_control()] interface.
5040
4930
*/
 
4931
#define SQLITE_TESTCTRL_FIRST                    5
5041
4932
#define SQLITE_TESTCTRL_PRNG_SAVE                5
5042
4933
#define SQLITE_TESTCTRL_PRNG_RESTORE             6
5043
4934
#define SQLITE_TESTCTRL_PRNG_RESET               7
5048
4939
#define SQLITE_TESTCTRL_ASSERT                  12
5049
4940
#define SQLITE_TESTCTRL_ALWAYS                  13
5050
4941
#define SQLITE_TESTCTRL_RESERVE                 14
 
4942
#define SQLITE_TESTCTRL_OPTIMIZATIONS           15
 
4943
#define SQLITE_TESTCTRL_ISKEYWORD               16
 
4944
#define SQLITE_TESTCTRL_LAST                    16
5051
4945
 
5052
4946
/*
5053
 
** CAPI3REF: SQLite Runtime Status {H17200} <S60200>
 
4947
** CAPI3REF: SQLite Runtime Status
5054
4948
** EXPERIMENTAL
5055
4949
**
5056
 
** This interface is used to retrieve runtime status information
 
4950
** ^This interface is used to retrieve runtime status information
5057
4951
** about the preformance of SQLite, and optionally to reset various
5058
 
** highwater marks.  The first argument is an integer code for
5059
 
** the specific parameter to measure.  Recognized integer codes
5060
 
** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].
5061
 
** The current value of the parameter is returned into *pCurrent.
5062
 
** The highest recorded value is returned in *pHighwater.  If the
 
4952
** highwater marks.  ^The first argument is an integer code for
 
4953
** the specific parameter to measure.  ^(Recognized integer codes
 
4954
** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
 
4955
** ^The current value of the parameter is returned into *pCurrent.
 
4956
** ^The highest recorded value is returned in *pHighwater.  ^If the
5063
4957
** resetFlag is true, then the highest record value is reset after
5064
 
** *pHighwater is written. Some parameters do not record the highest
 
4958
** *pHighwater is written.  ^(Some parameters do not record the highest
5065
4959
** value.  For those parameters
5066
 
** nothing is written into *pHighwater and the resetFlag is ignored.
5067
 
** Other parameters record only the highwater mark and not the current
5068
 
** value.  For these latter parameters nothing is written into *pCurrent.
 
4960
** nothing is written into *pHighwater and the resetFlag is ignored.)^
 
4961
** ^(Other parameters record only the highwater mark and not the current
 
4962
** value.  For these latter parameters nothing is written into *pCurrent.)^
5069
4963
**
5070
 
** This routine returns SQLITE_OK on success and a non-zero
5071
 
** [error code] on failure.
 
4964
** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
 
4965
** non-zero [error code] on failure.
5072
4966
**
5073
4967
** This routine is threadsafe but is not atomic.  This routine can be
5074
4968
** called while other threads are running the same or different SQLite
5083
4977
 
5084
4978
 
5085
4979
/*
5086
 
** CAPI3REF: Status Parameters {H17250} <H17200>
 
4980
** CAPI3REF: Status Parameters
5087
4981
** EXPERIMENTAL
5088
4982
**
5089
4983
** These integer constants designate various run-time status parameters
5090
4984
** that can be returned by [sqlite3_status()].
5091
4985
**
5092
4986
** <dl>
5093
 
** <dt>SQLITE_STATUS_MEMORY_USED</dt>
 
4987
** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
5094
4988
** <dd>This parameter is the current amount of memory checked out
5095
4989
** using [sqlite3_malloc()], either directly or indirectly.  The
5096
4990
** figure includes calls made to [sqlite3_malloc()] by the application
5098
4992
** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
5099
4993
** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
5100
4994
** this parameter.  The amount returned is the sum of the allocation
5101
 
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>
 
4995
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
5102
4996
**
5103
 
** <dt>SQLITE_STATUS_MALLOC_SIZE</dt>
 
4997
** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
5104
4998
** <dd>This parameter records the largest memory allocation request
5105
4999
** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5106
5000
** internal equivalents).  Only the value returned in the
5107
5001
** *pHighwater parameter to [sqlite3_status()] is of interest.  
5108
 
** The value written into the *pCurrent parameter is undefined.</dd>
 
5002
** The value written into the *pCurrent parameter is undefined.</dd>)^
5109
5003
**
5110
 
** <dt>SQLITE_STATUS_PAGECACHE_USED</dt>
 
5004
** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5111
5005
** <dd>This parameter returns the number of pages used out of the
5112
5006
** [pagecache memory allocator] that was configured using 
5113
5007
** [SQLITE_CONFIG_PAGECACHE].  The
5114
 
** value returned is in pages, not in bytes.</dd>
 
5008
** value returned is in pages, not in bytes.</dd>)^
5115
5009
**
5116
 
** <dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
 
5010
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5117
5011
** <dd>This parameter returns the number of bytes of page cache
5118
5012
** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
5119
5013
** buffer and where forced to overflow to [sqlite3_malloc()].  The
5120
5014
** returned value includes allocations that overflowed because they
5121
5015
** where too large (they were larger than the "sz" parameter to
5122
5016
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5123
 
** no space was left in the page cache.</dd>
 
5017
** no space was left in the page cache.</dd>)^
5124
5018
**
5125
 
** <dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
 
5019
** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
5126
5020
** <dd>This parameter records the largest memory allocation request
5127
5021
** handed to [pagecache memory allocator].  Only the value returned in the
5128
5022
** *pHighwater parameter to [sqlite3_status()] is of interest.  
5129
 
** The value written into the *pCurrent parameter is undefined.</dd>
 
5023
** The value written into the *pCurrent parameter is undefined.</dd>)^
5130
5024
**
5131
 
** <dt>SQLITE_STATUS_SCRATCH_USED</dt>
 
5025
** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
5132
5026
** <dd>This parameter returns the number of allocations used out of the
5133
5027
** [scratch memory allocator] configured using
5134
5028
** [SQLITE_CONFIG_SCRATCH].  The value returned is in allocations, not
5135
5029
** in bytes.  Since a single thread may only have one scratch allocation
5136
5030
** outstanding at time, this parameter also reports the number of threads
5137
 
** using scratch memory at the same time.</dd>
 
5031
** using scratch memory at the same time.</dd>)^
5138
5032
**
5139
 
** <dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
 
5033
** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5140
5034
** <dd>This parameter returns the number of bytes of scratch memory
5141
5035
** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
5142
5036
** buffer and where forced to overflow to [sqlite3_malloc()].  The values
5144
5038
** larger (that is, because the requested allocation was larger than the
5145
5039
** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5146
5040
** slots were available.
5147
 
** </dd>
 
5041
** </dd>)^
5148
5042
**
5149
 
** <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
 
5043
** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
5150
5044
** <dd>This parameter records the largest memory allocation request
5151
5045
** handed to [scratch memory allocator].  Only the value returned in the
5152
5046
** *pHighwater parameter to [sqlite3_status()] is of interest.  
5153
 
** The value written into the *pCurrent parameter is undefined.</dd>
 
5047
** The value written into the *pCurrent parameter is undefined.</dd>)^
5154
5048
**
5155
 
** <dt>SQLITE_STATUS_PARSER_STACK</dt>
 
5049
** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
5156
5050
** <dd>This parameter records the deepest parser stack.  It is only
5157
 
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>
 
5051
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
5158
5052
** </dl>
5159
5053
**
5160
5054
** New status parameters may be added from time to time.
5170
5064
#define SQLITE_STATUS_SCRATCH_SIZE         8
5171
5065
 
5172
5066
/*
5173
 
** CAPI3REF: Database Connection Status {H17500} <S60200>
 
5067
** CAPI3REF: Database Connection Status
5174
5068
** EXPERIMENTAL
5175
5069
**
5176
 
** This interface is used to retrieve runtime status information 
5177
 
** about a single [database connection].  The first argument is the
5178
 
** database connection object to be interrogated.  The second argument
5179
 
** is the parameter to interrogate.  Currently, the only allowed value
 
5070
** ^This interface is used to retrieve runtime status information 
 
5071
** about a single [database connection].  ^The first argument is the
 
5072
** database connection object to be interrogated.  ^The second argument
 
5073
** is the parameter to interrogate.  ^Currently, the only allowed value
5180
5074
** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5181
5075
** Additional options will likely appear in future releases of SQLite.
5182
5076
**
5183
 
** The current value of the requested parameter is written into *pCur
5184
 
** and the highest instantaneous value is written into *pHiwtr.  If
 
5077
** ^The current value of the requested parameter is written into *pCur
 
5078
** and the highest instantaneous value is written into *pHiwtr.  ^If
5185
5079
** the resetFlg is true, then the highest instantaneous value is
5186
5080
** reset back down to the current value.
5187
5081
**
5190
5084
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5191
5085
 
5192
5086
/*
5193
 
** CAPI3REF: Status Parameters for database connections {H17520} <H17500>
 
5087
** CAPI3REF: Status Parameters for database connections
5194
5088
** EXPERIMENTAL
5195
5089
**
5196
5090
** These constants are the available integer "verbs" that can be passed as
5203
5097
** if a discontinued or unsupported verb is invoked.
5204
5098
**
5205
5099
** <dl>
5206
 
** <dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
 
5100
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5207
5101
** <dd>This parameter returns the number of lookaside memory slots currently
5208
 
** checked out.</dd>
 
5102
** checked out.</dd>)^
5209
5103
** </dl>
5210
5104
*/
5211
5105
#define SQLITE_DBSTATUS_LOOKASIDE_USED     0
5212
5106
 
5213
5107
 
5214
5108
/*
5215
 
** CAPI3REF: Prepared Statement Status {H17550} <S60200>
 
5109
** CAPI3REF: Prepared Statement Status
5216
5110
** EXPERIMENTAL
5217
5111
**
5218
 
** Each prepared statement maintains various
 
5112
** ^(Each prepared statement maintains various
5219
5113
** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5220
 
** of times it has performed specific operations.  These counters can
 
5114
** of times it has performed specific operations.)^  These counters can
5221
5115
** be used to monitor the performance characteristics of the prepared
5222
5116
** statements.  For example, if the number of table steps greatly exceeds
5223
5117
** the number of table searches or result rows, that would tend to indicate
5224
5118
** that the prepared statement is using a full table scan rather than
5225
5119
** an index.  
5226
5120
**
5227
 
** This interface is used to retrieve and reset counter values from
 
5121
** ^(This interface is used to retrieve and reset counter values from
5228
5122
** a [prepared statement].  The first argument is the prepared statement
5229
5123
** object to be interrogated.  The second argument
5230
5124
** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
5231
 
** to be interrogated. 
5232
 
** The current value of the requested counter is returned.
5233
 
** If the resetFlg is true, then the counter is reset to zero after this
 
5125
** to be interrogated.)^
 
5126
** ^The current value of the requested counter is returned.
 
5127
** ^If the resetFlg is true, then the counter is reset to zero after this
5234
5128
** interface call returns.
5235
5129
**
5236
5130
** See also: [sqlite3_status()] and [sqlite3_db_status()].
5238
5132
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5239
5133
 
5240
5134
/*
5241
 
** CAPI3REF: Status Parameters for prepared statements {H17570} <H17550>
 
5135
** CAPI3REF: Status Parameters for prepared statements
5242
5136
** EXPERIMENTAL
5243
5137
**
5244
5138
** These preprocessor macros define integer codes that name counter
5247
5141
**
5248
5142
** <dl>
5249
5143
** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
5250
 
** <dd>This is the number of times that SQLite has stepped forward in
 
5144
** <dd>^This is the number of times that SQLite has stepped forward in
5251
5145
** a table as part of a full table scan.  Large numbers for this counter
5252
5146
** may indicate opportunities for performance improvement through 
5253
5147
** careful use of indices.</dd>
5254
5148
**
5255
5149
** <dt>SQLITE_STMTSTATUS_SORT</dt>
5256
 
** <dd>This is the number of sort operations that have occurred.
 
5150
** <dd>^This is the number of sort operations that have occurred.
5257
5151
** A non-zero value in this counter may indicate an opportunity to
5258
5152
** improvement performance through careful use of indices.</dd>
5259
5153
**
5281
5175
** KEYWORDS: {page cache}
5282
5176
** EXPERIMENTAL
5283
5177
**
5284
 
** The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
 
5178
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5285
5179
** register an alternative page cache implementation by passing in an 
5286
 
** instance of the sqlite3_pcache_methods structure. The majority of the 
 
5180
** instance of the sqlite3_pcache_methods structure.)^ The majority of the 
5287
5181
** heap memory used by SQLite is used by the page cache to cache data read 
5288
5182
** from, or ready to be written to, the database file. By implementing a 
5289
5183
** custom page cache using this API, an application can control more 
5292
5186
** determine exactly which parts of a database file are cached and for 
5293
5187
** how long.
5294
5188
**
5295
 
** The contents of the sqlite3_pcache_methods structure are copied to an
 
5189
** ^(The contents of the sqlite3_pcache_methods structure are copied to an
5296
5190
** internal buffer by SQLite within the call to [sqlite3_config].  Hence
5297
5191
** the application may discard the parameter after the call to
5298
 
** [sqlite3_config()] returns.
5299
 
**
5300
 
** The xInit() method is called once for each call to [sqlite3_initialize()]
5301
 
** (usually only once during the lifetime of the process). It is passed
5302
 
** a copy of the sqlite3_pcache_methods.pArg value. It can be used to set
5303
 
** up global structures and mutexes required by the custom page cache 
5304
 
** implementation. 
5305
 
**
5306
 
** The xShutdown() method is called from within [sqlite3_shutdown()], 
 
5192
** [sqlite3_config()] returns.)^
 
5193
**
 
5194
** ^The xInit() method is called once for each call to [sqlite3_initialize()]
 
5195
** (usually only once during the lifetime of the process). ^(The xInit()
 
5196
** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
 
5197
** ^The xInit() method can set up up global structures and/or any mutexes
 
5198
** required by the custom page cache implementation. 
 
5199
**
 
5200
** ^The xShutdown() method is called from within [sqlite3_shutdown()], 
5307
5201
** if the application invokes this API. It can be used to clean up 
5308
5202
** any outstanding resources before process shutdown, if required.
5309
5203
**
5310
 
** SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes
5311
 
** the xInit method, so the xInit method need not be threadsafe.  The
 
5204
** ^SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes
 
5205
** the xInit method, so the xInit method need not be threadsafe.  ^The
5312
5206
** xShutdown method is only called from [sqlite3_shutdown()] so it does
5313
5207
** not need to be threadsafe either.  All other methods must be threadsafe
5314
5208
** in multithreaded applications.
5315
5209
**
5316
 
** SQLite will never invoke xInit() more than once without an intervening
 
5210
** ^SQLite will never invoke xInit() more than once without an intervening
5317
5211
** call to xShutdown().
5318
5212
**
5319
 
** The xCreate() method is used to construct a new cache instance.  SQLite
 
5213
** ^The xCreate() method is used to construct a new cache instance.  SQLite
5320
5214
** will typically create one cache instance for each open database file,
5321
 
** though this is not guaranteed. The
 
5215
** though this is not guaranteed. ^The
5322
5216
** first parameter, szPage, is the size in bytes of the pages that must
5323
 
** be allocated by the cache.  szPage will not be a power of two.  szPage
 
5217
** be allocated by the cache.  ^szPage will not be a power of two.  ^szPage
5324
5218
** will the page size of the database file that is to be cached plus an
5325
 
** increment (here called "R") of about 100 or 200.  SQLite will use the
 
5219
** increment (here called "R") of about 100 or 200.  ^SQLite will use the
5326
5220
** extra R bytes on each page to store metadata about the underlying
5327
5221
** database page on disk.  The value of R depends
5328
5222
** on the SQLite version, the target platform, and how SQLite was compiled.
5329
 
** R is constant for a particular build of SQLite.  The second argument to
 
5223
** ^R is constant for a particular build of SQLite.  ^The second argument to
5330
5224
** xCreate(), bPurgeable, is true if the cache being created will
5331
5225
** be used to cache database pages of a file stored on disk, or
5332
 
** false if it is used for an in-memory database. The cache implementation
 
5226
** false if it is used for an in-memory database. ^The cache implementation
5333
5227
** does not have to do anything special based with the value of bPurgeable;
5334
 
** it is purely advisory.  On a cache where bPurgeable is false, SQLite will
 
5228
** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
5335
5229
** never invoke xUnpin() except to deliberately delete a page.
5336
 
** In other words, a cache created with bPurgeable set to false will
 
5230
** ^In other words, a cache created with bPurgeable set to false will
5337
5231
** never contain any unpinned pages.
5338
5232
**
5339
 
** The xCachesize() method may be called at any time by SQLite to set the
 
5233
** ^(The xCachesize() method may be called at any time by SQLite to set the
5340
5234
** suggested maximum cache-size (number of pages stored by) the cache
5341
5235
** instance passed as the first argument. This is the value configured using
5342
 
** the SQLite "[PRAGMA cache_size]" command. As with the bPurgeable parameter,
5343
 
** the implementation is not required to do anything with this
 
5236
** the SQLite "[PRAGMA cache_size]" command.)^  ^As with the bPurgeable
 
5237
** parameter, the implementation is not required to do anything with this
5344
5238
** value; it is advisory only.
5345
5239
**
5346
 
** The xPagecount() method should return the number of pages currently
 
5240
** ^The xPagecount() method should return the number of pages currently
5347
5241
** stored in the cache.
5348
5242
** 
5349
 
** The xFetch() method is used to fetch a page and return a pointer to it. 
5350
 
** A 'page', in this context, is a buffer of szPage bytes aligned at an
5351
 
** 8-byte boundary. The page to be fetched is determined by the key. The
 
5243
** ^The xFetch() method is used to fetch a page and return a pointer to it. 
 
5244
** ^A 'page', in this context, is a buffer of szPage bytes aligned at an
 
5245
** 8-byte boundary. ^The page to be fetched is determined by the key. ^The
5352
5246
** mimimum key value is 1. After it has been retrieved using xFetch, the page 
5353
5247
** is considered to be "pinned".
5354
5248
**
5355
 
** If the requested page is already in the page cache, then the page cache
 
5249
** ^If the requested page is already in the page cache, then the page cache
5356
5250
** implementation must return a pointer to the page buffer with its content
5357
 
** intact.  If the requested page is not already in the cache, then the
 
5251
** intact.  ^(If the requested page is not already in the cache, then the
5358
5252
** behavior of the cache implementation is determined by the value of the
5359
5253
** createFlag parameter passed to xFetch, according to the following table:
5360
5254
**
5365
5259
**                 Otherwise return NULL.
5366
5260
** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
5367
5261
**                 NULL if allocating a new page is effectively impossible.
5368
 
** </table>
 
5262
** </table>)^
5369
5263
**
5370
5264
** SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  If
5371
5265
** a call to xFetch() with createFlag==1 returns NULL, then SQLite will
5374
5268
** attempting to unpin pages, the xFetch() method will be invoked again with
5375
5269
** a createFlag of 2.
5376
5270
**
5377
 
** xUnpin() is called by SQLite with a pointer to a currently pinned page
5378
 
** as its second argument. If the third parameter, discard, is non-zero,
 
5271
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
 
5272
** as its second argument. ^(If the third parameter, discard, is non-zero,
5379
5273
** then the page should be evicted from the cache. In this case SQLite 
5380
5274
** assumes that the next time the page is retrieved from the cache using
5381
 
** the xFetch() method, it will be zeroed. If the discard parameter is
5382
 
** zero, then the page is considered to be unpinned. The cache implementation
 
5275
** the xFetch() method, it will be zeroed.)^ ^If the discard parameter is
 
5276
** zero, then the page is considered to be unpinned. ^The cache implementation
5383
5277
** may choose to evict unpinned pages at any time.
5384
5278
**
5385
 
** The cache is not required to perform any reference counting. A single 
 
5279
** ^(The cache is not required to perform any reference counting. A single 
5386
5280
** call to xUnpin() unpins the page regardless of the number of prior calls 
5387
 
** to xFetch().
 
5281
** to xFetch().)^
5388
5282
**
5389
 
** The xRekey() method is used to change the key value associated with the
5390
 
** page passed as the second argument from oldKey to newKey. If the cache
 
5283
** ^The xRekey() method is used to change the key value associated with the
 
5284
** page passed as the second argument from oldKey to newKey. ^If the cache
5391
5285
** previously contains an entry associated with newKey, it should be
5392
 
** discarded. Any prior cache entry associated with newKey is guaranteed not
 
5286
** discarded. ^Any prior cache entry associated with newKey is guaranteed not
5393
5287
** to be pinned.
5394
5288
**
5395
 
** When SQLite calls the xTruncate() method, the cache must discard all
 
5289
** ^When SQLite calls the xTruncate() method, the cache must discard all
5396
5290
** existing cache entries with page numbers (keys) greater than or equal
5397
 
** to the value of the iLimit parameter passed to xTruncate(). If any
 
5291
** to the value of the iLimit parameter passed to xTruncate(). ^If any
5398
5292
** of these pages are pinned, they are implicitly unpinned, meaning that
5399
5293
** they can be safely discarded.
5400
5294
**
5401
 
** The xDestroy() method is used to delete a cache allocated by xCreate().
5402
 
** All resources associated with the specified cache should be freed. After
 
5295
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
 
5296
** All resources associated with the specified cache should be freed. ^After
5403
5297
** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
5404
5298
** handle invalid, and will not use it with any other sqlite3_pcache_methods
5405
5299
** functions.
5424
5318
** EXPERIMENTAL
5425
5319
**
5426
5320
** The sqlite3_backup object records state information about an ongoing
5427
 
** online backup operation.  The sqlite3_backup object is created by
 
5321
** online backup operation.  ^The sqlite3_backup object is created by
5428
5322
** a call to [sqlite3_backup_init()] and is destroyed by a call to
5429
5323
** [sqlite3_backup_finish()].
5430
5324
**
5436
5330
** CAPI3REF: Online Backup API.
5437
5331
** EXPERIMENTAL
5438
5332
**
5439
 
** This API is used to overwrite the contents of one database with that
5440
 
** of another. It is useful either for creating backups of databases or
 
5333
** The backup API copies the content of one database into another.
 
5334
** It is useful either for creating backups of databases or
5441
5335
** for copying in-memory databases to or from persistent files. 
5442
5336
**
5443
5337
** See Also: [Using the SQLite Online Backup API]
5444
5338
**
5445
 
** Exclusive access is required to the destination database for the 
5446
 
** duration of the operation. However the source database is only
5447
 
** read-locked while it is actually being read, it is not locked
5448
 
** continuously for the entire operation. Thus, the backup may be
5449
 
** performed on a live database without preventing other users from
5450
 
** writing to the database for an extended period of time.
 
5339
** ^Exclusive access is required to the destination database for the 
 
5340
** duration of the operation. ^However the source database is only
 
5341
** read-locked while it is actually being read; it is not locked
 
5342
** continuously for the entire backup operation. ^Thus, the backup may be
 
5343
** performed on a live source database without preventing other users from
 
5344
** reading or writing to the source database while the backup is underway.
5451
5345
** 
5452
 
** To perform a backup operation: 
 
5346
** ^(To perform a backup operation: 
5453
5347
**   <ol>
5454
5348
**     <li><b>sqlite3_backup_init()</b> is called once to initialize the
5455
5349
**         backup, 
5457
5351
**         the data between the two databases, and finally
5458
5352
**     <li><b>sqlite3_backup_finish()</b> is called to release all resources 
5459
5353
**         associated with the backup operation. 
5460
 
**   </ol>
 
5354
**   </ol>)^
5461
5355
** There should be exactly one call to sqlite3_backup_finish() for each
5462
5356
** successful call to sqlite3_backup_init().
5463
5357
**
5464
5358
** <b>sqlite3_backup_init()</b>
5465
5359
**
5466
 
** The first two arguments passed to [sqlite3_backup_init()] are the database
5467
 
** handle associated with the destination database and the database name 
5468
 
** used to attach the destination database to the handle. The database name
5469
 
** is "main" for the main database, "temp" for the temporary database, or
5470
 
** the name specified as part of the [ATTACH] statement if the destination is
5471
 
** an attached database. The third and fourth arguments passed to 
5472
 
** sqlite3_backup_init() identify the [database connection]
5473
 
** and database name used
5474
 
** to access the source database. The values passed for the source and 
5475
 
** destination [database connection] parameters must not be the same.
 
5360
** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 
 
5361
** [database connection] associated with the destination database 
 
5362
** and the database name, respectively.
 
5363
** ^The database name is "main" for the main database, "temp" for the
 
5364
** temporary database, or the name specified after the AS keyword in
 
5365
** an [ATTACH] statement for an attached database.
 
5366
** ^The S and M arguments passed to 
 
5367
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
 
5368
** and database name of the source database, respectively.
 
5369
** ^The source and destination [database connections] (parameters S and D)
 
5370
** must be different or else sqlite3_backup_init(D,N,S,M) will file with
 
5371
** an error.
5476
5372
**
5477
 
** If an error occurs within sqlite3_backup_init(), then NULL is returned
5478
 
** and an error code and error message written into the [database connection] 
5479
 
** passed as the first argument. They may be retrieved using the
5480
 
** [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()] functions.
5481
 
** Otherwise, if successful, a pointer to an [sqlite3_backup] object is
5482
 
** returned. This pointer may be used with the sqlite3_backup_step() and
 
5373
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
 
5374
** returned and an error code and error message are store3d in the
 
5375
** destination [database connection] D.
 
5376
** ^The error code and message for the failed call to sqlite3_backup_init()
 
5377
** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
 
5378
** [sqlite3_errmsg16()] functions.
 
5379
** ^A successful call to sqlite3_backup_init() returns a pointer to an
 
5380
** [sqlite3_backup] object.
 
5381
** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
5483
5382
** sqlite3_backup_finish() functions to perform the specified backup 
5484
5383
** operation.
5485
5384
**
5486
5385
** <b>sqlite3_backup_step()</b>
5487
5386
**
5488
 
** Function [sqlite3_backup_step()] is used to copy up to nPage pages between 
5489
 
** the source and destination databases, where nPage is the value of the 
5490
 
** second parameter passed to sqlite3_backup_step(). If nPage is a negative
5491
 
** value, all remaining source pages are copied. If the required pages are 
5492
 
** succesfully copied, but there are still more pages to copy before the 
5493
 
** backup is complete, it returns [SQLITE_OK]. If no error occured and there 
5494
 
** are no more pages to copy, then [SQLITE_DONE] is returned. If an error 
5495
 
** occurs, then an SQLite error code is returned. As well as [SQLITE_OK] and
 
5387
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 
 
5388
** the source and destination databases specified by [sqlite3_backup] object B.
 
5389
** ^If N is negative, all remaining source pages are copied. 
 
5390
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
 
5391
** are still more pages to be copied, then the function resturns [SQLITE_OK].
 
5392
** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
 
5393
** from source to destination, then it returns [SQLITE_DONE].
 
5394
** ^If an error occurs while running sqlite3_backup_step(B,N),
 
5395
** then an [error code] is returned. ^As well as [SQLITE_OK] and
5496
5396
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
5497
5397
** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
5498
5398
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
5499
5399
**
5500
 
** As well as the case where the destination database file was opened for
5501
 
** read-only access, sqlite3_backup_step() may return [SQLITE_READONLY] if
 
5400
** ^The sqlite3_backup_step() might return [SQLITE_READONLY] if the destination
 
5401
** database was opened read-only or if
5502
5402
** the destination is an in-memory database with a different page size
5503
5403
** from the source database.
5504
5404
**
5505
 
** If sqlite3_backup_step() cannot obtain a required file-system lock, then
 
5405
** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
5506
5406
** the [sqlite3_busy_handler | busy-handler function]
5507
 
** is invoked (if one is specified). If the 
 
5407
** is invoked (if one is specified). ^If the 
5508
5408
** busy-handler returns non-zero before the lock is available, then 
5509
 
** [SQLITE_BUSY] is returned to the caller. In this case the call to
5510
 
** sqlite3_backup_step() can be retried later. If the source
 
5409
** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
 
5410
** sqlite3_backup_step() can be retried later. ^If the source
5511
5411
** [database connection]
5512
5412
** is being used to write to the source database when sqlite3_backup_step()
5513
 
** is called, then [SQLITE_LOCKED] is returned immediately. Again, in this
5514
 
** case the call to sqlite3_backup_step() can be retried later on. If
 
5413
** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
 
5414
** case the call to sqlite3_backup_step() can be retried later on. ^(If
5515
5415
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
5516
5416
** [SQLITE_READONLY] is returned, then 
5517
5417
** there is no point in retrying the call to sqlite3_backup_step(). These 
5518
 
** errors are considered fatal. At this point the application must accept 
 
5418
** errors are considered fatal.)^  The application must accept 
5519
5419
** that the backup operation has failed and pass the backup operation handle 
5520
5420
** to the sqlite3_backup_finish() to release associated resources.
5521
5421
**
5522
 
** Following the first call to sqlite3_backup_step(), an exclusive lock is
5523
 
** obtained on the destination file. It is not released until either 
 
5422
** ^The first call to sqlite3_backup_step() obtains an exclusive lock
 
5423
** on the destination file. ^The exclusive lock is not released until either 
5524
5424
** sqlite3_backup_finish() is called or the backup operation is complete 
5525
 
** and sqlite3_backup_step() returns [SQLITE_DONE]. Additionally, each time 
5526
 
** a call to sqlite3_backup_step() is made a [shared lock] is obtained on
5527
 
** the source database file. This lock is released before the
5528
 
** sqlite3_backup_step() call returns. Because the source database is not
5529
 
** locked between calls to sqlite3_backup_step(), it may be modified mid-way
5530
 
** through the backup procedure. If the source database is modified by an
 
5425
** and sqlite3_backup_step() returns [SQLITE_DONE].  ^Every call to
 
5426
** sqlite3_backup_step() obtains a [shared lock] on the source database that
 
5427
** lasts for the duration of the sqlite3_backup_step() call.
 
5428
** ^Because the source database is not locked between calls to
 
5429
** sqlite3_backup_step(), the source database may be modified mid-way
 
5430
** through the backup process.  ^If the source database is modified by an
5531
5431
** external process or via a database connection other than the one being
5532
 
** used by the backup operation, then the backup will be transparently
5533
 
** restarted by the next call to sqlite3_backup_step(). If the source 
 
5432
** used by the backup operation, then the backup will be automatically
 
5433
** restarted by the next call to sqlite3_backup_step(). ^If the source 
5534
5434
** database is modified by the using the same database connection as is used
5535
 
** by the backup operation, then the backup database is transparently 
 
5435
** by the backup operation, then the backup database is automatically
5536
5436
** updated at the same time.
5537
5437
**
5538
5438
** <b>sqlite3_backup_finish()</b>
5539
5439
**
5540
 
** Once sqlite3_backup_step() has returned [SQLITE_DONE], or when the 
5541
 
** application wishes to abandon the backup operation, the [sqlite3_backup]
5542
 
** object should be passed to sqlite3_backup_finish(). This releases all
5543
 
** resources associated with the backup operation. If sqlite3_backup_step()
5544
 
** has not yet returned [SQLITE_DONE], then any active write-transaction on the
5545
 
** destination database is rolled back. The [sqlite3_backup] object is invalid
 
5440
** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 
 
5441
** application wishes to abandon the backup operation, the application
 
5442
** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
 
5443
** ^The sqlite3_backup_finish() interfaces releases all
 
5444
** resources associated with the [sqlite3_backup] object. 
 
5445
** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
 
5446
** active write-transaction on the destination database is rolled back.
 
5447
** The [sqlite3_backup] object is invalid
5546
5448
** and may not be used following a call to sqlite3_backup_finish().
5547
5449
**
5548
 
** The value returned by sqlite3_backup_finish is [SQLITE_OK] if no error
5549
 
** occurred, regardless or whether or not sqlite3_backup_step() was called
5550
 
** a sufficient number of times to complete the backup operation. Or, if
5551
 
** an out-of-memory condition or IO error occured during a call to
5552
 
** sqlite3_backup_step() then [SQLITE_NOMEM] or an
5553
 
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] error code
5554
 
** is returned. In this case the error code and an error message are
5555
 
** written to the destination [database connection].
 
5450
** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
 
5451
** sqlite3_backup_step() errors occurred, regardless or whether or not
 
5452
** sqlite3_backup_step() completed.
 
5453
** ^If an out-of-memory condition or IO error occurred during any prior
 
5454
** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
 
5455
** sqlite3_backup_finish() returns the corresponding [error code].
5556
5456
**
5557
 
** A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() is
5558
 
** not a permanent error and does not affect the return value of
 
5457
** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
 
5458
** is not a permanent error and does not affect the return value of
5559
5459
** sqlite3_backup_finish().
5560
5460
**
5561
5461
** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
5562
5462
**
5563
 
** Each call to sqlite3_backup_step() sets two values stored internally
5564
 
** by an [sqlite3_backup] object. The number of pages still to be backed
5565
 
** up, which may be queried by sqlite3_backup_remaining(), and the total
5566
 
** number of pages in the source database file, which may be queried by
5567
 
** sqlite3_backup_pagecount().
 
5463
** ^Each call to sqlite3_backup_step() sets two values inside
 
5464
** the [sqlite3_backup] object: the number of pages still to be backed
 
5465
** up and the total number of pages in the source databae file.
 
5466
** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
 
5467
** retrieve these two values, respectively.
5568
5468
**
5569
 
** The values returned by these functions are only updated by
5570
 
** sqlite3_backup_step(). If the source database is modified during a backup
 
5469
** ^The values returned by these functions are only updated by
 
5470
** sqlite3_backup_step(). ^If the source database is modified during a backup
5571
5471
** operation, then the values are not updated to account for any extra
5572
5472
** pages that need to be updated or the size of the source database file
5573
5473
** changing.
5574
5474
**
5575
5475
** <b>Concurrent Usage of Database Handles</b>
5576
5476
**
5577
 
** The source [database connection] may be used by the application for other
 
5477
** ^The source [database connection] may be used by the application for other
5578
5478
** purposes while a backup operation is underway or being initialized.
5579
 
** If SQLite is compiled and configured to support threadsafe database
 
5479
** ^If SQLite is compiled and configured to support threadsafe database
5580
5480
** connections, then the source database connection may be used concurrently
5581
5481
** from within other threads.
5582
5482
**
5583
 
** However, the application must guarantee that the destination database
5584
 
** connection handle is not passed to any other API (by any thread) after 
 
5483
** However, the application must guarantee that the destination 
 
5484
** [database connection] is not passed to any other API (by any thread) after 
5585
5485
** sqlite3_backup_init() is called and before the corresponding call to
5586
 
** sqlite3_backup_finish(). Unfortunately SQLite does not currently check
5587
 
** for this, if the application does use the destination [database connection]
5588
 
** for some other purpose during a backup operation, things may appear to
5589
 
** work correctly but in fact be subtly malfunctioning.  Use of the
5590
 
** destination database connection while a backup is in progress might
5591
 
** also cause a mutex deadlock.
 
5486
** sqlite3_backup_finish().  SQLite does not currently check to see
 
5487
** if the application incorrectly accesses the destination [database connection]
 
5488
** and so no error code is reported, but the operations may malfunction
 
5489
** nevertheless.  Use of the destination database connection while a
 
5490
** backup is in progress might also also cause a mutex deadlock.
5592
5491
**
5593
 
** Furthermore, if running in [shared cache mode], the application must
 
5492
** If running in [shared cache mode], the application must
5594
5493
** guarantee that the shared cache used by the destination database
5595
5494
** is not accessed while the backup is running. In practice this means
5596
 
** that the application must guarantee that the file-system file being 
 
5495
** that the application must guarantee that the disk file being 
5597
5496
** backed up to is not accessed by any connection within the process,
5598
5497
** not just the specific connection that was passed to sqlite3_backup_init().
5599
5498
**
5619
5518
** CAPI3REF: Unlock Notification
5620
5519
** EXPERIMENTAL
5621
5520
**
5622
 
** When running in shared-cache mode, a database operation may fail with
 
5521
** ^When running in shared-cache mode, a database operation may fail with
5623
5522
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
5624
5523
** individual tables within the shared-cache cannot be obtained. See
5625
5524
** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 
5626
 
** This API may be used to register a callback that SQLite will invoke 
 
5525
** ^This API may be used to register a callback that SQLite will invoke 
5627
5526
** when the connection currently holding the required lock relinquishes it.
5628
 
** This API is only available if the library was compiled with the
 
5527
** ^This API is only available if the library was compiled with the
5629
5528
** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
5630
5529
**
5631
5530
** See Also: [Using the SQLite Unlock Notification Feature].
5632
5531
**
5633
 
** Shared-cache locks are released when a database connection concludes
 
5532
** ^Shared-cache locks are released when a database connection concludes
5634
5533
** its current transaction, either by committing it or rolling it back. 
5635
5534
**
5636
 
** When a connection (known as the blocked connection) fails to obtain a
 
5535
** ^When a connection (known as the blocked connection) fails to obtain a
5637
5536
** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
5638
5537
** identity of the database connection (the blocking connection) that
5639
 
** has locked the required resource is stored internally. After an 
 
5538
** has locked the required resource is stored internally. ^After an 
5640
5539
** application receives an SQLITE_LOCKED error, it may call the
5641
5540
** sqlite3_unlock_notify() method with the blocked connection handle as 
5642
5541
** the first argument to register for a callback that will be invoked
5643
 
** when the blocking connections current transaction is concluded. The
 
5542
** when the blocking connections current transaction is concluded. ^The
5644
5543
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
5645
5544
** call that concludes the blocking connections transaction.
5646
5545
**
5647
 
** If sqlite3_unlock_notify() is called in a multi-threaded application,
 
5546
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
5648
5547
** there is a chance that the blocking connection will have already
5649
5548
** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
5650
5549
** If this happens, then the specified callback is invoked immediately,
5651
 
** from within the call to sqlite3_unlock_notify().
 
5550
** from within the call to sqlite3_unlock_notify().)^
5652
5551
**
5653
 
** If the blocked connection is attempting to obtain a write-lock on a
 
5552
** ^If the blocked connection is attempting to obtain a write-lock on a
5654
5553
** shared-cache table, and more than one other connection currently holds
5655
5554
** a read-lock on the same table, then SQLite arbitrarily selects one of 
5656
5555
** the other connections to use as the blocking connection.
5657
5556
**
5658
 
** There may be at most one unlock-notify callback registered by a 
 
5557
** ^(There may be at most one unlock-notify callback registered by a 
5659
5558
** blocked connection. If sqlite3_unlock_notify() is called when the
5660
5559
** blocked connection already has a registered unlock-notify callback,
5661
 
** then the new callback replaces the old. If sqlite3_unlock_notify() is
 
5560
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
5662
5561
** called with a NULL pointer as its second argument, then any existing
5663
 
** unlock-notify callback is cancelled. The blocked connections 
 
5562
** unlock-notify callback is cancelled. ^The blocked connections 
5664
5563
** unlock-notify callback may also be canceled by closing the blocked
5665
5564
** connection using [sqlite3_close()].
5666
5565
**
5668
5567
** any sqlite3_xxx API functions from within an unlock-notify callback, a
5669
5568
** crash or deadlock may be the result.
5670
5569
**
5671
 
** Unless deadlock is detected (see below), sqlite3_unlock_notify() always
 
5570
** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
5672
5571
** returns SQLITE_OK.
5673
5572
**
5674
5573
** <b>Callback Invocation Details</b>
5682
5581
**
5683
5582
** When a blocking connections transaction is concluded, there may be
5684
5583
** more than one blocked connection that has registered for an unlock-notify
5685
 
** callback. If two or more such blocked connections have specified the
 
5584
** callback. ^If two or more such blocked connections have specified the
5686
5585
** same callback function, then instead of invoking the callback function
5687
5586
** multiple times, it is invoked once with the set of void* context pointers
5688
5587
** specified by the blocked connections bundled together into an array.
5700
5599
** will proceed and the system may remain deadlocked indefinitely.
5701
5600
**
5702
5601
** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
5703
 
** detection. If a given call to sqlite3_unlock_notify() would put the
 
5602
** detection. ^If a given call to sqlite3_unlock_notify() would put the
5704
5603
** system in a deadlocked state, then SQLITE_LOCKED is returned and no
5705
5604
** unlock-notify callback is registered. The system is said to be in
5706
5605
** a deadlocked state if connection A has registered for an unlock-notify
5707
5606
** callback on the conclusion of connection B's transaction, and connection
5708
5607
** B has itself registered for an unlock-notify callback when connection
5709
 
** A's transaction is concluded. Indirect deadlock is also detected, so
 
5608
** A's transaction is concluded. ^Indirect deadlock is also detected, so
5710
5609
** the system is also considered to be deadlocked if connection B has
5711
5610
** registered for an unlock-notify callback on the conclusion of connection
5712
 
** C's transaction, where connection C is waiting on connection A. Any
 
5611
** C's transaction, where connection C is waiting on connection A. ^Any
5713
5612
** number of levels of indirection are allowed.
5714
5613
**
5715
5614
** <b>The "DROP TABLE" Exception</b>
5725
5624
** or "DROP INDEX" query, an infinite loop might be the result.
5726
5625
**
5727
5626
** One way around this problem is to check the extended error code returned
5728
 
** by an sqlite3_step() call. If there is a blocking connection, then the
 
5627
** by an sqlite3_step() call. ^(If there is a blocking connection, then the
5729
5628
** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
5730
5629
** the special "DROP TABLE/INDEX" case, the extended error code is just 
5731
 
** SQLITE_LOCKED.
 
5630
** SQLITE_LOCKED.)^
5732
5631
*/
5733
5632
SQLITE_API int sqlite3_unlock_notify(
5734
5633
  sqlite3 *pBlocked,                          /* Waiting connection */
5741
5640
** CAPI3REF: String Comparison
5742
5641
** EXPERIMENTAL
5743
5642
**
5744
 
** The [sqlite3_strnicmp()] API allows applications and extensions to
 
5643
** ^The [sqlite3_strnicmp()] API allows applications and extensions to
5745
5644
** compare the contents of two buffers containing UTF-8 strings in a
5746
5645
** case-indendent fashion, using the same definition of case independence 
5747
5646
** that SQLite uses internally when comparing identifiers.