Fossil SCM

Now really update the built-in SQLite to the first 3.8.10 beta, not only the command line shell.

jan.nijtmans 2015-05-05 06:49 trunk
Commit acd670f2519599aa965e12b2450368b480fd1524
2 files changed +1928 -724 +91 -15
+1928 -724
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.8.9. By combining all the individual C code files into this
3
+** version 3.8.10. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -68,10 +68,11 @@
6868
#if defined(_MSC_VER)
6969
#pragma warning(disable : 4054)
7070
#pragma warning(disable : 4055)
7171
#pragma warning(disable : 4100)
7272
#pragma warning(disable : 4127)
73
+#pragma warning(disable : 4130)
7374
#pragma warning(disable : 4152)
7475
#pragma warning(disable : 4189)
7576
#pragma warning(disable : 4206)
7677
#pragma warning(disable : 4210)
7778
#pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
315316
**
316317
** See also: [sqlite3_libversion()],
317318
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318319
** [sqlite_version()] and [sqlite_source_id()].
319320
*/
320
-#define SQLITE_VERSION "3.8.9"
321
-#define SQLITE_VERSION_NUMBER 3008009
322
-#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
321
+#define SQLITE_VERSION "3.8.10"
322
+#define SQLITE_VERSION_NUMBER 3008010
323
+#define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e"
323324
324325
/*
325326
** CAPI3REF: Run-Time Library Version Numbers
326327
** KEYWORDS: sqlite3_version, sqlite3_sourceid
327328
**
@@ -474,10 +475,11 @@
474475
# define double sqlite3_int64
475476
#endif
476477
477478
/*
478479
** CAPI3REF: Closing A Database Connection
480
+** DESTRUCTOR: sqlite3
479481
**
480482
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
481483
** for the [sqlite3] object.
482484
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
483485
** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
525527
*/
526528
typedef int (*sqlite3_callback)(void*,int,char**, char**);
527529
528530
/*
529531
** CAPI3REF: One-Step Query Execution Interface
532
+** METHOD: sqlite3
530533
**
531534
** The sqlite3_exec() interface is a convenience wrapper around
532535
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
533536
** that allows an application to run multiple statements of SQL
534537
** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
15821585
*/
15831586
SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
15841587
15851588
/*
15861589
** CAPI3REF: Configure database connections
1590
+** METHOD: sqlite3
15871591
**
15881592
** The sqlite3_db_config() interface is used to make configuration
15891593
** changes to a [database connection]. The interface is similar to
15901594
** [sqlite3_config()] except that the changes apply to a single
15911595
** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
20792083
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
20802084
20812085
20822086
/*
20832087
** CAPI3REF: Enable Or Disable Extended Result Codes
2088
+** METHOD: sqlite3
20842089
**
20852090
** ^The sqlite3_extended_result_codes() routine enables or disables the
20862091
** [extended result codes] feature of SQLite. ^The extended result
20872092
** codes are disabled by default for historical compatibility.
20882093
*/
20892094
SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
20902095
20912096
/*
20922097
** CAPI3REF: Last Insert Rowid
2098
+** METHOD: sqlite3
20932099
**
20942100
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
20952101
** has a unique 64-bit signed
20962102
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
20972103
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
21392145
*/
21402146
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
21412147
21422148
/*
21432149
** CAPI3REF: Count The Number Of Rows Modified
2150
+** METHOD: sqlite3
21442151
**
21452152
** ^This function returns the number of rows modified, inserted or
21462153
** deleted by the most recently completed INSERT, UPDATE or DELETE
21472154
** statement on the database connection specified by the only parameter.
21482155
** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
21912198
*/
21922199
SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
21932200
21942201
/*
21952202
** CAPI3REF: Total Number Of Rows Modified
2203
+** METHOD: sqlite3
21962204
**
21972205
** ^This function returns the total number of rows inserted, modified or
21982206
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
21992207
** since the database connection was opened, including those executed as
22002208
** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
22142222
*/
22152223
SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
22162224
22172225
/*
22182226
** CAPI3REF: Interrupt A Long-Running Query
2227
+** METHOD: sqlite3
22192228
**
22202229
** ^This function causes any pending database operation to abort and
22212230
** return at its earliest opportunity. This routine is typically
22222231
** called in response to a user action such as pressing "Cancel"
22232232
** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
22902299
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
22912300
22922301
/*
22932302
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
22942303
** KEYWORDS: {busy-handler callback} {busy handler}
2304
+** METHOD: sqlite3
22952305
**
22962306
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
22972307
** that might be invoked with argument P whenever
22982308
** an attempt is made to access a database table associated with
22992309
** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
23492359
*/
23502360
SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
23512361
23522362
/*
23532363
** CAPI3REF: Set A Busy Timeout
2364
+** METHOD: sqlite3
23542365
**
23552366
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
23562367
** for a specified amount of time when a table is locked. ^The handler
23572368
** will sleep multiple times until at least "ms" milliseconds of sleeping
23582369
** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
23712382
*/
23722383
SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
23732384
23742385
/*
23752386
** CAPI3REF: Convenience Routines For Running Queries
2387
+** METHOD: sqlite3
23762388
**
23772389
** This is a legacy interface that is preserved for backwards compatibility.
23782390
** Use of this interface is not recommended.
23792391
**
23802392
** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
27062718
*/
27072719
SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
27082720
27092721
/*
27102722
** CAPI3REF: Compile-Time Authorization Callbacks
2723
+** METHOD: sqlite3
27112724
**
27122725
** ^This routine registers an authorizer callback with a particular
27132726
** [database connection], supplied in the first argument.
27142727
** ^The authorizer callback is invoked as SQL statements are being compiled
27152728
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
28622875
#define SQLITE_COPY 0 /* No longer used */
28632876
#define SQLITE_RECURSIVE 33 /* NULL NULL */
28642877
28652878
/*
28662879
** CAPI3REF: Tracing And Profiling Functions
2880
+** METHOD: sqlite3
28672881
**
28682882
** These routines register callback functions that can be used for
28692883
** tracing and profiling the execution of SQL statements.
28702884
**
28712885
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
28942908
SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
28952909
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
28962910
28972911
/*
28982912
** CAPI3REF: Query Progress Callbacks
2913
+** METHOD: sqlite3
28992914
**
29002915
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
29012916
** function X to be invoked periodically during long running calls to
29022917
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
29032918
** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
29272942
*/
29282943
SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
29292944
29302945
/*
29312946
** CAPI3REF: Opening A New Database Connection
2947
+** CONSTRUCTOR: sqlite3
29322948
**
29332949
** ^These routines open an SQLite database file as specified by the
29342950
** filename argument. ^The filename argument is interpreted as UTF-8 for
29352951
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
29362952
** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
32123228
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
32133229
32143230
32153231
/*
32163232
** CAPI3REF: Error Codes And Messages
3233
+** METHOD: sqlite3
32173234
**
32183235
** ^If the most recent sqlite3_* API call associated with
32193236
** [database connection] D failed, then the sqlite3_errcode(D) interface
32203237
** returns the numeric [result code] or [extended result code] for that
32213238
** API call.
@@ -3257,37 +3274,38 @@
32573274
SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
32583275
SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
32593276
SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
32603277
32613278
/*
3262
-** CAPI3REF: SQL Statement Object
3279
+** CAPI3REF: Prepared Statement Object
32633280
** KEYWORDS: {prepared statement} {prepared statements}
32643281
**
3265
-** An instance of this object represents a single SQL statement.
3266
-** This object is variously known as a "prepared statement" or a
3267
-** "compiled SQL statement" or simply as a "statement".
3282
+** An instance of this object represents a single SQL statement that
3283
+** has been compiled into binary form and is ready to be evaluated.
32683284
**
3269
-** The life of a statement object goes something like this:
3285
+** Think of each SQL statement as a separate computer program. The
3286
+** original SQL text is source code. A prepared statement object
3287
+** is the compiled object code. All SQL must be converted into a
3288
+** prepared statement before it can be run.
3289
+**
3290
+** The life-cycle of a prepared statement object usually goes like this:
32703291
**
32713292
** <ol>
3272
-** <li> Create the object using [sqlite3_prepare_v2()] or a related
3273
-** function.
3274
-** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3293
+** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3294
+** <li> Bind values to [parameters] using the sqlite3_bind_*()
32753295
** interfaces.
32763296
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3277
-** <li> Reset the statement using [sqlite3_reset()] then go back
3297
+** <li> Reset the prepared statement using [sqlite3_reset()] then go back
32783298
** to step 2. Do this zero or more times.
32793299
** <li> Destroy the object using [sqlite3_finalize()].
32803300
** </ol>
3281
-**
3282
-** Refer to documentation on individual methods above for additional
3283
-** information.
32843301
*/
32853302
typedef struct sqlite3_stmt sqlite3_stmt;
32863303
32873304
/*
32883305
** CAPI3REF: Run-time Limits
3306
+** METHOD: sqlite3
32893307
**
32903308
** ^(This interface allows the size of various constructs to be limited
32913309
** on a connection by connection basis. The first parameter is the
32923310
** [database connection] whose limit is to be set or queried. The
32933311
** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
33953413
#define SQLITE_LIMIT_WORKER_THREADS 11
33963414
33973415
/*
33983416
** CAPI3REF: Compiling An SQL Statement
33993417
** KEYWORDS: {SQL statement compiler}
3418
+** METHOD: sqlite3
3419
+** CONSTRUCTOR: sqlite3_stmt
34003420
**
34013421
** To execute an SQL query, it must first be compiled into a byte-code
34023422
** program using one of these routines.
34033423
**
34043424
** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
35023522
const void **pzTail /* OUT: Pointer to unused portion of zSql */
35033523
);
35043524
35053525
/*
35063526
** CAPI3REF: Retrieving Statement SQL
3527
+** METHOD: sqlite3_stmt
35073528
**
35083529
** ^This interface can be used to retrieve a saved copy of the original
35093530
** SQL text used to create a [prepared statement] if that statement was
35103531
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
35113532
*/
35123533
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
35133534
35143535
/*
35153536
** CAPI3REF: Determine If An SQL Statement Writes The Database
3537
+** METHOD: sqlite3_stmt
35163538
**
35173539
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
35183540
** and only if the [prepared statement] X makes no direct changes to
35193541
** the content of the database file.
35203542
**
@@ -3542,10 +3564,11 @@
35423564
*/
35433565
SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
35443566
35453567
/*
35463568
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3569
+** METHOD: sqlite3_stmt
35473570
**
35483571
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
35493572
** [prepared statement] S has been stepped at least once using
35503573
** [sqlite3_step(S)] but has not run to completion and/or has not
35513574
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
36163639
36173640
/*
36183641
** CAPI3REF: Binding Values To Prepared Statements
36193642
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
36203643
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3644
+** METHOD: sqlite3_stmt
36213645
**
36223646
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
36233647
** literals may be replaced by a [parameter] that matches one of following
36243648
** templates:
36253649
**
@@ -3734,10 +3758,11 @@
37343758
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
37353759
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
37363760
37373761
/*
37383762
** CAPI3REF: Number Of SQL Parameters
3763
+** METHOD: sqlite3_stmt
37393764
**
37403765
** ^This routine can be used to find the number of [SQL parameters]
37413766
** in a [prepared statement]. SQL parameters are tokens of the
37423767
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
37433768
** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
37543779
*/
37553780
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
37563781
37573782
/*
37583783
** CAPI3REF: Name Of A Host Parameter
3784
+** METHOD: sqlite3_stmt
37593785
**
37603786
** ^The sqlite3_bind_parameter_name(P,N) interface returns
37613787
** the name of the N-th [SQL parameter] in the [prepared statement] P.
37623788
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
37633789
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
37813807
*/
37823808
SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
37833809
37843810
/*
37853811
** CAPI3REF: Index Of A Parameter With A Given Name
3812
+** METHOD: sqlite3_stmt
37863813
**
37873814
** ^Return the index of an SQL parameter given its name. ^The
37883815
** index value returned is suitable for use as the second
37893816
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
37903817
** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
37973824
*/
37983825
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
37993826
38003827
/*
38013828
** CAPI3REF: Reset All Bindings On A Prepared Statement
3829
+** METHOD: sqlite3_stmt
38023830
**
38033831
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
38043832
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
38053833
** ^Use this routine to reset all host parameters to NULL.
38063834
*/
38073835
SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
38083836
38093837
/*
38103838
** CAPI3REF: Number Of Columns In A Result Set
3839
+** METHOD: sqlite3_stmt
38113840
**
38123841
** ^Return the number of columns in the result set returned by the
38133842
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
38143843
** statement that does not return data (for example an [UPDATE]).
38153844
**
@@ -3817,10 +3846,11 @@
38173846
*/
38183847
SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
38193848
38203849
/*
38213850
** CAPI3REF: Column Names In A Result Set
3851
+** METHOD: sqlite3_stmt
38223852
**
38233853
** ^These routines return the name assigned to a particular column
38243854
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
38253855
** interface returns a pointer to a zero-terminated UTF-8 string
38263856
** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
38463876
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
38473877
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
38483878
38493879
/*
38503880
** CAPI3REF: Source Of Data In A Query Result
3881
+** METHOD: sqlite3_stmt
38513882
**
38523883
** ^These routines provide a means to determine the database, table, and
38533884
** table column that is the origin of a particular result column in
38543885
** [SELECT] statement.
38553886
** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
38983929
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
38993930
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
39003931
39013932
/*
39023933
** CAPI3REF: Declared Datatype Of A Query Result
3934
+** METHOD: sqlite3_stmt
39033935
**
39043936
** ^(The first parameter is a [prepared statement].
39053937
** If this statement is a [SELECT] statement and the Nth column of the
39063938
** returned result set of that [SELECT] is a table column (not an
39073939
** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
39303962
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
39313963
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
39323964
39333965
/*
39343966
** CAPI3REF: Evaluate An SQL Statement
3967
+** METHOD: sqlite3_stmt
39353968
**
39363969
** After a [prepared statement] has been prepared using either
39373970
** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
39383971
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
39393972
** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
40094042
*/
40104043
SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
40114044
40124045
/*
40134046
** CAPI3REF: Number of columns in a result set
4047
+** METHOD: sqlite3_stmt
40144048
**
40154049
** ^The sqlite3_data_count(P) interface returns the number of columns in the
40164050
** current row of the result set of [prepared statement] P.
40174051
** ^If prepared statement P does not have results ready to return
40184052
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
40624096
#define SQLITE3_TEXT 3
40634097
40644098
/*
40654099
** CAPI3REF: Result Values From A Query
40664100
** KEYWORDS: {column access functions}
4101
+** METHOD: sqlite3_stmt
40674102
**
40684103
** These routines form the "result set" interface.
40694104
**
40704105
** ^These routines return information about a single column of the current
40714106
** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
42344269
SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
42354270
SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
42364271
42374272
/*
42384273
** CAPI3REF: Destroy A Prepared Statement Object
4274
+** DESTRUCTOR: sqlite3_stmt
42394275
**
42404276
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
42414277
** ^If the most recent evaluation of the statement encountered no errors
42424278
** or if the statement is never been evaluated, then sqlite3_finalize() returns
42434279
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
42614297
*/
42624298
SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
42634299
42644300
/*
42654301
** CAPI3REF: Reset A Prepared Statement Object
4302
+** METHOD: sqlite3_stmt
42664303
**
42674304
** The sqlite3_reset() function is called to reset a [prepared statement]
42684305
** object back to its initial state, ready to be re-executed.
42694306
** ^Any SQL statement variables that had values bound to them using
42704307
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
42904327
/*
42914328
** CAPI3REF: Create Or Redefine SQL Functions
42924329
** KEYWORDS: {function creation routines}
42934330
** KEYWORDS: {application-defined SQL function}
42944331
** KEYWORDS: {application-defined SQL functions}
4332
+** METHOD: sqlite3
42954333
**
42964334
** ^These functions (collectively known as "function creation routines")
42974335
** are used to add SQL functions or aggregates or to redefine the behavior
42984336
** of existing SQL functions or aggregates. The only differences between
42994337
** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
44594497
void*,sqlite3_int64);
44604498
#endif
44614499
44624500
/*
44634501
** CAPI3REF: Obtaining SQL Function Parameter Values
4502
+** METHOD: sqlite3_value
44644503
**
44654504
** The C-language implementation of SQL functions and aggregates uses
44664505
** this set of interface routines to access the parameter values on
44674506
** the function or aggregate.
44684507
**
@@ -4517,10 +4556,11 @@
45174556
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
45184557
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
45194558
45204559
/*
45214560
** CAPI3REF: Obtain Aggregate Function Context
4561
+** METHOD: sqlite3_context
45224562
**
45234563
** Implementations of aggregate SQL functions use this
45244564
** routine to allocate memory for storing their state.
45254565
**
45264566
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
45614601
*/
45624602
SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
45634603
45644604
/*
45654605
** CAPI3REF: User Data For Functions
4606
+** METHOD: sqlite3_context
45664607
**
45674608
** ^The sqlite3_user_data() interface returns a copy of
45684609
** the pointer that was the pUserData parameter (the 5th parameter)
45694610
** of the [sqlite3_create_function()]
45704611
** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
45754616
*/
45764617
SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
45774618
45784619
/*
45794620
** CAPI3REF: Database Connection For Functions
4621
+** METHOD: sqlite3_context
45804622
**
45814623
** ^The sqlite3_context_db_handle() interface returns a copy of
45824624
** the pointer to the [database connection] (the 1st parameter)
45834625
** of the [sqlite3_create_function()]
45844626
** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
45864628
*/
45874629
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
45884630
45894631
/*
45904632
** CAPI3REF: Function Auxiliary Data
4633
+** METHOD: sqlite3_context
45914634
**
45924635
** These functions may be used by (non-aggregate) SQL functions to
45934636
** associate metadata with argument values. If the same value is passed to
45944637
** multiple invocations of the same SQL function during query execution, under
45954638
** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
46584701
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
46594702
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
46604703
46614704
/*
46624705
** CAPI3REF: Setting The Result Of An SQL Function
4706
+** METHOD: sqlite3_context
46634707
**
46644708
** These routines are used by the xFunc or xFinal callbacks that
46654709
** implement SQL functions and aggregates. See
46664710
** [sqlite3_create_function()] and [sqlite3_create_function16()]
46674711
** for additional information.
@@ -4793,10 +4837,11 @@
47934837
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
47944838
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
47954839
47964840
/*
47974841
** CAPI3REF: Define New Collating Sequences
4842
+** METHOD: sqlite3
47984843
**
47994844
** ^These functions add, remove, or modify a [collation] associated
48004845
** with the [database connection] specified as the first argument.
48014846
**
48024847
** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
48954940
int(*xCompare)(void*,int,const void*,int,const void*)
48964941
);
48974942
48984943
/*
48994944
** CAPI3REF: Collation Needed Callbacks
4945
+** METHOD: sqlite3
49004946
**
49014947
** ^To avoid having to register all collation sequences before a database
49024948
** can be used, a single callback function may be registered with the
49034949
** [database connection] to be invoked whenever an undefined collation
49044950
** sequence is required.
@@ -5102,10 +5148,11 @@
51025148
SQLITE_API char *sqlite3_data_directory;
51035149
51045150
/*
51055151
** CAPI3REF: Test For Auto-Commit Mode
51065152
** KEYWORDS: {autocommit mode}
5153
+** METHOD: sqlite3
51075154
**
51085155
** ^The sqlite3_get_autocommit() interface returns non-zero or
51095156
** zero if the given database connection is or is not in autocommit mode,
51105157
** respectively. ^Autocommit mode is on by default.
51115158
** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
51245171
*/
51255172
SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
51265173
51275174
/*
51285175
** CAPI3REF: Find The Database Handle Of A Prepared Statement
5176
+** METHOD: sqlite3_stmt
51295177
**
51305178
** ^The sqlite3_db_handle interface returns the [database connection] handle
51315179
** to which a [prepared statement] belongs. ^The [database connection]
51325180
** returned by sqlite3_db_handle is the same [database connection]
51335181
** that was the first argument
@@ -5136,10 +5184,11 @@
51365184
*/
51375185
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
51385186
51395187
/*
51405188
** CAPI3REF: Return The Filename For A Database Connection
5189
+** METHOD: sqlite3
51415190
**
51425191
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
51435192
** associated with database N of connection D. ^The main database file
51445193
** has the name "main". If there is no attached database N on the database
51455194
** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
51525201
*/
51535202
SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
51545203
51555204
/*
51565205
** CAPI3REF: Determine if a database is read-only
5206
+** METHOD: sqlite3
51575207
**
51585208
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
51595209
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
51605210
** the name of a database on connection D.
51615211
*/
51625212
SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
51635213
51645214
/*
51655215
** CAPI3REF: Find the next prepared statement
5216
+** METHOD: sqlite3
51665217
**
51675218
** ^This interface returns a pointer to the next [prepared statement] after
51685219
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
51695220
** then this interface returns a pointer to the first prepared statement
51705221
** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
51765227
*/
51775228
SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
51785229
51795230
/*
51805231
** CAPI3REF: Commit And Rollback Notification Callbacks
5232
+** METHOD: sqlite3
51815233
**
51825234
** ^The sqlite3_commit_hook() interface registers a callback
51835235
** function to be invoked whenever a transaction is [COMMIT | committed].
51845236
** ^Any callback set by a previous call to sqlite3_commit_hook()
51855237
** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
52255277
SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
52265278
SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
52275279
52285280
/*
52295281
** CAPI3REF: Data Change Notification Callbacks
5282
+** METHOD: sqlite3
52305283
**
52315284
** ^The sqlite3_update_hook() interface registers a callback function
52325285
** with the [database connection] identified by the first argument
52335286
** to be invoked whenever a row is updated, inserted or deleted in
52345287
** a rowid table.
@@ -5331,10 +5384,11 @@
53315384
*/
53325385
SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
53335386
53345387
/*
53355388
** CAPI3REF: Free Memory Used By A Database Connection
5389
+** METHOD: sqlite3
53365390
**
53375391
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
53385392
** memory as possible from database connection D. Unlike the
53395393
** [sqlite3_release_memory()] interface, this interface is in effect even
53405394
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
54085462
SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
54095463
54105464
54115465
/*
54125466
** CAPI3REF: Extract Metadata About A Column Of A Table
5467
+** METHOD: sqlite3
54135468
**
54145469
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
54155470
** information about column C of table T in database D
54165471
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
54175472
** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
54865541
int *pAutoinc /* OUTPUT: True if column is auto-increment */
54875542
);
54885543
54895544
/*
54905545
** CAPI3REF: Load An Extension
5546
+** METHOD: sqlite3
54915547
**
54925548
** ^This interface loads an SQLite extension library from the named file.
54935549
**
54945550
** ^The sqlite3_load_extension() interface attempts to load an
54955551
** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
55275583
char **pzErrMsg /* Put error message here if not 0 */
55285584
);
55295585
55305586
/*
55315587
** CAPI3REF: Enable Or Disable Extension Loading
5588
+** METHOD: sqlite3
55325589
**
55335590
** ^So as not to open security holes in older applications that are
55345591
** unprepared to deal with [extension loading], and as a means of disabling
55355592
** [extension loading] while evaluating user-entered SQL, the following API
55365593
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
57765833
#define SQLITE_INDEX_CONSTRAINT_GE 32
57775834
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
57785835
57795836
/*
57805837
** CAPI3REF: Register A Virtual Table Implementation
5838
+** METHOD: sqlite3
57815839
**
57825840
** ^These routines are used to register a new [virtual table module] name.
57835841
** ^Module names must be registered before
57845842
** creating a new [virtual table] using the module and before using a
57855843
** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
58725930
*/
58735931
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
58745932
58755933
/*
58765934
** CAPI3REF: Overload A Function For A Virtual Table
5935
+** METHOD: sqlite3
58775936
**
58785937
** ^(Virtual tables can provide alternative implementations of functions
58795938
** using the [xFindFunction] method of the [virtual table module].
58805939
** But global versions of those functions
58815940
** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
59145973
*/
59155974
typedef struct sqlite3_blob sqlite3_blob;
59165975
59175976
/*
59185977
** CAPI3REF: Open A BLOB For Incremental I/O
5978
+** METHOD: sqlite3
5979
+** CONSTRUCTOR: sqlite3_blob
59195980
**
59205981
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
59215982
** in row iRow, column zColumn, table zTable in database zDb;
59225983
** in other words, the same BLOB that would be selected by:
59235984
**
@@ -5995,10 +6056,11 @@
59956056
sqlite3_blob **ppBlob
59966057
);
59976058
59986059
/*
59996060
** CAPI3REF: Move a BLOB Handle to a New Row
6061
+** METHOD: sqlite3_blob
60006062
**
60016063
** ^This function is used to move an existing blob handle so that it points
60026064
** to a different row of the same database table. ^The new row is identified
60036065
** by the rowid value passed as the second argument. Only the row can be
60046066
** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
60196081
*/
60206082
SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
60216083
60226084
/*
60236085
** CAPI3REF: Close A BLOB Handle
6086
+** DESTRUCTOR: sqlite3_blob
60246087
**
60256088
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
60266089
** unconditionally. Even if this routine returns an error code, the
60276090
** handle is still closed.)^
60286091
**
@@ -6041,10 +6104,11 @@
60416104
*/
60426105
SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
60436106
60446107
/*
60456108
** CAPI3REF: Return The Size Of An Open BLOB
6109
+** METHOD: sqlite3_blob
60466110
**
60476111
** ^Returns the size in bytes of the BLOB accessible via the
60486112
** successfully opened [BLOB handle] in its only argument. ^The
60496113
** incremental blob I/O routines can only read or overwriting existing
60506114
** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
60566120
*/
60576121
SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
60586122
60596123
/*
60606124
** CAPI3REF: Read Data From A BLOB Incrementally
6125
+** METHOD: sqlite3_blob
60616126
**
60626127
** ^(This function is used to read data from an open [BLOB handle] into a
60636128
** caller-supplied buffer. N bytes of data are copied into buffer Z
60646129
** from the open BLOB, starting at offset iOffset.)^
60656130
**
@@ -6084,10 +6149,11 @@
60846149
*/
60856150
SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
60866151
60876152
/*
60886153
** CAPI3REF: Write Data Into A BLOB Incrementally
6154
+** METHOD: sqlite3_blob
60896155
**
60906156
** ^(This function is used to write data into an open [BLOB handle] from a
60916157
** caller-supplied buffer. N bytes of data are copied from the buffer Z
60926158
** into the open BLOB, starting at offset iOffset.)^
60936159
**
@@ -6411,10 +6477,11 @@
64116477
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
64126478
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
64136479
64146480
/*
64156481
** CAPI3REF: Retrieve the mutex for a database connection
6482
+** METHOD: sqlite3
64166483
**
64176484
** ^This interface returns a pointer the [sqlite3_mutex] object that
64186485
** serializes access to the [database connection] given in the argument
64196486
** when the [threading mode] is Serialized.
64206487
** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
64226489
*/
64236490
SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
64246491
64256492
/*
64266493
** CAPI3REF: Low-Level Control Of Database Files
6494
+** METHOD: sqlite3
64276495
**
64286496
** ^The [sqlite3_file_control()] interface makes a direct call to the
64296497
** xFileControl method for the [sqlite3_io_methods] object associated
64306498
** with a particular database identified by the second argument. ^The
64316499
** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
66386706
#define SQLITE_STATUS_SCRATCH_SIZE 8
66396707
#define SQLITE_STATUS_MALLOC_COUNT 9
66406708
66416709
/*
66426710
** CAPI3REF: Database Connection Status
6711
+** METHOD: sqlite3
66436712
**
66446713
** ^This interface is used to retrieve runtime status information
66456714
** about a single [database connection]. ^The first argument is the
66466715
** database connection object to be interrogated. ^The second argument
66476716
** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
67666835
#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
67676836
67686837
67696838
/*
67706839
** CAPI3REF: Prepared Statement Status
6840
+** METHOD: sqlite3_stmt
67716841
**
67726842
** ^(Each prepared statement maintains various
67736843
** [SQLITE_STMTSTATUS counters] that measure the number
67746844
** of times it has performed specific operations.)^ These counters can
67756845
** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
72697339
SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
72707340
SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
72717341
72727342
/*
72737343
** CAPI3REF: Unlock Notification
7344
+** METHOD: sqlite3
72747345
**
72757346
** ^When running in shared-cache mode, a database operation may fail with
72767347
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
72777348
** individual tables within the shared-cache cannot be obtained. See
72787349
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
74397510
*/
74407511
SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
74417512
74427513
/*
74437514
** CAPI3REF: Write-Ahead Log Commit Hook
7515
+** METHOD: sqlite3
74447516
**
74457517
** ^The [sqlite3_wal_hook()] function is used to register a callback that
74467518
** is invoked each time data is committed to a database in wal mode.
74477519
**
74487520
** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
74787550
void*
74797551
);
74807552
74817553
/*
74827554
** CAPI3REF: Configure an auto-checkpoint
7555
+** METHOD: sqlite3
74837556
**
74847557
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
74857558
** [sqlite3_wal_hook()] that causes any database on [database connection] D
74867559
** to automatically [checkpoint]
74877560
** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
75087581
*/
75097582
SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
75107583
75117584
/*
75127585
** CAPI3REF: Checkpoint a database
7586
+** METHOD: sqlite3
75137587
**
75147588
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
75157589
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
75167590
**
75177591
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
75297603
*/
75307604
SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
75317605
75327606
/*
75337607
** CAPI3REF: Checkpoint a database
7608
+** METHOD: sqlite3
75347609
**
75357610
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
75367611
** operation on database X of [database connection] D in mode M. Status
75377612
** information is written back into integers pointed to by L and C.)^
75387613
** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
77837858
#define SQLITE_SCANSTAT_EXPLAIN 4
77847859
#define SQLITE_SCANSTAT_SELECTID 5
77857860
77867861
/*
77877862
** CAPI3REF: Prepared Statement Scan Status
7863
+** METHOD: sqlite3_stmt
77887864
**
77897865
** This interface returns information about the predicted and measured
77907866
** performance for pStmt. Advanced applications can use this
77917867
** interface to compare the predicted and the measured performance and
77927868
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
78207896
void *pOut /* Result written here */
78217897
);
78227898
78237899
/*
78247900
** CAPI3REF: Zero Scan-Status Counters
7901
+** METHOD: sqlite3_stmt
78257902
**
78267903
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
78277904
**
78287905
** This API is only available if the library is built with pre-processor
78297906
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
84308507
#else
84318508
# define ALWAYS(X) (X)
84328509
# define NEVER(X) (X)
84338510
#endif
84348511
8512
+/*
8513
+** Declarations used for tracing the operating system interfaces.
8514
+*/
8515
+#if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
8516
+ (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8517
+ extern int sqlite3OSTrace;
8518
+# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
8519
+# define SQLITE_HAVE_OS_TRACE
8520
+#else
8521
+# define OSTRACE(X)
8522
+# undef SQLITE_HAVE_OS_TRACE
8523
+#endif
8524
+
8525
+/*
8526
+** Is the sqlite3ErrName() function needed in the build? Currently,
8527
+** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
8528
+** OSTRACE is enabled), and by several "test*.c" files (which are
8529
+** compiled using SQLITE_TEST).
8530
+*/
8531
+#if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \
8532
+ (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8533
+# define SQLITE_NEED_ERR_NAME
8534
+#else
8535
+# undef SQLITE_NEED_ERR_NAME
8536
+#endif
8537
+
84358538
/*
84368539
** Return true (non-zero) if the input is an integer that is too large
84378540
** to fit in 32-bits. This macro is used inside of various testcase()
84388541
** macros to verify that we have tested SQLite for large-file support.
84398542
*/
@@ -9841,37 +9944,36 @@
98419944
/* Properties such as "out2" or "jump" that are specified in
98429945
** comments following the "case" for each opcode in the vdbe.c
98439946
** are encoded into bitvectors as follows:
98449947
*/
98459948
#define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9846
-#define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
9847
-#define OPFLG_IN1 0x0004 /* in1: P1 is an input */
9848
-#define OPFLG_IN2 0x0008 /* in2: P2 is an input */
9849
-#define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9850
-#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9851
-#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9949
+#define OPFLG_IN1 0x0002 /* in1: P1 is an input */
9950
+#define OPFLG_IN2 0x0004 /* in2: P2 is an input */
9951
+#define OPFLG_IN3 0x0008 /* in3: P3 is an input */
9952
+#define OPFLG_OUT2 0x0010 /* out2: P2 is an output */
9953
+#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
98529954
#define OPFLG_INITIALIZER {\
98539955
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9854
-/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9855
-/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9856
-/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9857
-/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9858
-/* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\
9859
-/* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\
9860
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\
9861
-/* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\
9862
-/* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\
9863
-/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9864
-/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9865
-/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9866
-/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9867
-/* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9868
-/* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9869
-/* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9870
-/* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9956
+/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
9957
+/* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\
9958
+/* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\
9959
+/* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\
9960
+/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
9961
+/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\
9962
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\
9963
+/* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\
9964
+/* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
9965
+/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
9966
+/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
9967
+/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
9968
+/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
9969
+/* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\
9970
+/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9971
+/* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\
9972
+/* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\
98719973
/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9872
-/* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9974
+/* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,}
98739975
98749976
/************** End of opcodes.h *********************************************/
98759977
/************** Continuing where we left off in vdbe.h ***********************/
98769978
98779979
/*
@@ -9926,10 +10028,11 @@
992610028
#endif
992710029
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
992810030
992910031
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
993010032
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
10033
+SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
993110034
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
993210035
993310036
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
993410037
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
993510038
@@ -11063,10 +11166,11 @@
1106311166
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
1106411167
#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
1106511168
#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
1106611169
#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
1106711170
#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
11171
+#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
1106811172
1106911173
1107011174
/*
1107111175
** Bits of the sqlite3.dbOptFlags field that are used by the
1107211176
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
1139311497
int iSavepoint; /* Depth of the SAVEPOINT stack */
1139411498
VTable *pNext; /* Next in linked list (see above) */
1139511499
};
1139611500
1139711501
/*
11398
-** Each SQL table is represented in memory by an instance of the
11399
-** following structure.
11400
-**
11401
-** Table.zName is the name of the table. The case of the original
11402
-** CREATE TABLE statement is stored, but case is not significant for
11403
-** comparisons.
11404
-**
11405
-** Table.nCol is the number of columns in this table. Table.aCol is a
11406
-** pointer to an array of Column structures, one for each column.
11407
-**
11408
-** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
11409
-** the column that is that key. Otherwise Table.iPKey is negative. Note
11410
-** that the datatype of the PRIMARY KEY must be INTEGER for this field to
11411
-** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
11412
-** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
11413
-** is generated for each row of the table. TF_HasPrimaryKey is set if
11414
-** the table has any PRIMARY KEY, INTEGER or otherwise.
11415
-**
11416
-** Table.tnum is the page number for the root BTree page of the table in the
11417
-** database file. If Table.iDb is the index of the database table backend
11418
-** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
11419
-** holds temporary tables and indices. If TF_Ephemeral is set
11420
-** then the table is stored in a file that is automatically deleted
11421
-** when the VDBE cursor to the table is closed. In this case Table.tnum
11422
-** refers VDBE cursor number that holds the table open, not to the root
11423
-** page number. Transient tables are used to hold the results of a
11424
-** sub-query that appears instead of a real table name in the FROM clause
11425
-** of a SELECT statement.
11502
+** The schema for each SQL table and view is represented in memory
11503
+** by an instance of the following structure.
1142611504
*/
1142711505
struct Table {
1142811506
char *zName; /* Name of the table or view */
1142911507
Column *aCol; /* Information about each column */
1143011508
Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
1143211510
FKey *pFKey; /* Linked list of all foreign keys in this table */
1143311511
char *zColAff; /* String defining the affinity of each column */
1143411512
#ifndef SQLITE_OMIT_CHECK
1143511513
ExprList *pCheck; /* All CHECK constraints */
1143611514
#endif
11437
- LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11438
- int tnum; /* Root BTree node for this table (see note above) */
11439
- i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
11515
+ int tnum; /* Root BTree page for this table */
11516
+ i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1144011517
i16 nCol; /* Number of columns in this table */
1144111518
u16 nRef; /* Number of pointers to this Table */
11519
+ LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
1144211520
LogEst szTabRow; /* Estimated size of each table row in bytes */
1144311521
#ifdef SQLITE_ENABLE_COSTMULT
1144411522
LogEst costMult; /* Cost multiplier for using this table */
1144511523
#endif
1144611524
u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
1145811536
Table *pNextZombie; /* Next on the Parse.pZombieTab list */
1145911537
};
1146011538
1146111539
/*
1146211540
** Allowed values for Table.tabFlags.
11541
+**
11542
+** TF_OOOHidden applies to virtual tables that have hidden columns that are
11543
+** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
11544
+** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
11545
+** the TF_OOOHidden attribute would apply in this case. Such tables require
11546
+** special handling during INSERT processing.
1146311547
*/
1146411548
#define TF_Readonly 0x01 /* Read-only system table */
1146511549
#define TF_Ephemeral 0x02 /* An ephemeral table */
1146611550
#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
1146711551
#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
1146811552
#define TF_Virtual 0x10 /* Is a virtual table */
1146911553
#define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
11554
+#define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */
1147011555
1147111556
1147211557
/*
1147311558
** Test to see whether or not a table is a virtual table. This is
1147411559
** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
1222112306
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1222212307
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1222312308
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
1222412309
#define SF_Compound 0x0040 /* Part of a compound query */
1222512310
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
12226
-#define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12311
+#define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */
1222712312
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1222812313
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1222912314
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
1223012315
#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
1223112316
#define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
1260512690
*
1260612691
* (op == TK_INSERT)
1260712692
* orconf -> stores the ON CONFLICT algorithm
1260812693
* pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
1260912694
* this stores a pointer to the SELECT statement. Otherwise NULL.
12610
- * target -> A token holding the quoted name of the table to insert into.
12695
+ * zTarget -> Dequoted name of the table to insert into.
1261112696
* pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
1261212697
* this stores values to be inserted. Otherwise NULL.
1261312698
* pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
1261412699
* statement, then this stores the column-names to be
1261512700
* inserted into.
1261612701
*
1261712702
* (op == TK_DELETE)
12618
- * target -> A token holding the quoted name of the table to delete from.
12703
+ * zTarget -> Dequoted name of the table to delete from.
1261912704
* pWhere -> The WHERE clause of the DELETE statement if one is specified.
1262012705
* Otherwise NULL.
1262112706
*
1262212707
* (op == TK_UPDATE)
12623
- * target -> A token holding the quoted name of the table to update rows of.
12708
+ * zTarget -> Dequoted name of the table to update.
1262412709
* pWhere -> The WHERE clause of the UPDATE statement if one is specified.
1262512710
* Otherwise NULL.
1262612711
* pExprList -> A list of the columns to update and the expressions to update
1262712712
* them to. See sqlite3Update() documentation of "pChanges"
1262812713
* argument.
@@ -12630,12 +12715,12 @@
1263012715
*/
1263112716
struct TriggerStep {
1263212717
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
1263312718
u8 orconf; /* OE_Rollback etc. */
1263412719
Trigger *pTrig; /* The trigger that this step is a part of */
12635
- Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
12636
- Token target; /* Target table for DELETE, UPDATE, INSERT */
12720
+ Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
12721
+ char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
1263712722
Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
1263812723
ExprList *pExprList; /* SET clause for UPDATE. */
1263912724
IdList *pIdList; /* Column names for INSERT */
1264012725
TriggerStep *pNext; /* Next in the link-list */
1264112726
TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
1266412749
sqlite3 *db; /* Optional database for lookaside. Can be NULL */
1266512750
char *zBase; /* A base allocation. Not from malloc. */
1266612751
char *zText; /* The string collected so far */
1266712752
int nChar; /* Length of the string so far */
1266812753
int nAlloc; /* Amount of space allocated in zText */
12669
- int mxAlloc; /* Maximum allowed string length */
12670
- u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
12754
+ int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
1267112755
u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
1267212756
};
1267312757
#define STRACCUM_NOMEM 1
1267412758
#define STRACCUM_TOOBIG 2
1267512759
@@ -12982,11 +13066,11 @@
1298213066
SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
1298313067
SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
1298413068
SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
1298513069
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
1298613070
SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12987
-#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
13071
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
1298813072
SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
1298913073
#endif
1299013074
#if defined(SQLITE_TEST)
1299113075
SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
1299213076
#endif
@@ -13329,11 +13413,11 @@
1332913413
SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
1333013414
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
1333113415
SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
1333213416
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1333313417
13334
-#if defined(SQLITE_TEST)
13418
+#if defined(SQLITE_NEED_ERR_NAME)
1333513419
SQLITE_PRIVATE const char *sqlite3ErrName(int);
1333613420
#endif
1333713421
1333813422
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1333913423
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
1342313507
FuncDestructor *pDestructor
1342413508
);
1342513509
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1342613510
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1342713511
13428
-SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13512
+SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
1342913513
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
1343013514
SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
1343113515
SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
1343213516
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
1343313517
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -19807,20 +19891,10 @@
1980719891
*/
1980819892
#ifdef MEMORY_DEBUG
1980919893
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
1981019894
#endif
1981119895
19812
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19813
-# ifndef SQLITE_DEBUG_OS_TRACE
19814
-# define SQLITE_DEBUG_OS_TRACE 0
19815
-# endif
19816
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19817
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19818
-#else
19819
-# define OSTRACE(X)
19820
-#endif
19821
-
1982219896
/*
1982319897
** Macros for performance tracing. Normally turned off. Only works
1982419898
** on i486 hardware.
1982519899
*/
1982619900
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21475,11 @@
2140121475
2140221476
/*
2140321477
** Set the StrAccum object to an error mode.
2140421478
*/
2140521479
static void setStrAccumError(StrAccum *p, u8 eError){
21480
+ assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
2140621481
p->accError = eError;
2140721482
p->nAlloc = 0;
2140821483
}
2140921484
2141021485
/*
@@ -22018,11 +22093,11 @@
2201822093
if( p->accError ){
2201922094
testcase(p->accError==STRACCUM_TOOBIG);
2202022095
testcase(p->accError==STRACCUM_NOMEM);
2202122096
return 0;
2202222097
}
22023
- if( !p->useMalloc ){
22098
+ if( p->mxAlloc==0 ){
2202422099
N = p->nAlloc - p->nChar - 1;
2202522100
setStrAccumError(p, STRACCUM_TOOBIG);
2202622101
return N;
2202722102
}else{
2202822103
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22113,14 @@
2203822113
setStrAccumError(p, STRACCUM_TOOBIG);
2203922114
return 0;
2204022115
}else{
2204122116
p->nAlloc = (int)szNew;
2204222117
}
22043
- if( p->useMalloc==1 ){
22118
+ if( p->db ){
2204422119
zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
2204522120
}else{
22046
- zNew = sqlite3_realloc(zOld, p->nAlloc);
22121
+ zNew = sqlite3_realloc64(zOld, p->nAlloc);
2204722122
}
2204822123
if( zNew ){
2204922124
assert( p->zText!=0 || p->nChar==0 );
2205022125
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2205122126
p->zText = zNew;
@@ -22089,11 +22164,11 @@
2208922164
/*
2209022165
** Append N bytes of text from z to the StrAccum object. Increase the
2209122166
** size of the memory allocation for StrAccum if necessary.
2209222167
*/
2209322168
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22094
- assert( z!=0 );
22169
+ assert( z!=0 || N==0 );
2209522170
assert( p->zText!=0 || p->nChar==0 || p->accError );
2209622171
assert( N>=0 );
2209722172
assert( p->accError==0 || p->nAlloc==0 );
2209822173
if( p->nChar+N >= p->nAlloc ){
2209922174
enlargeAndAppend(p,z,N);
@@ -22118,16 +22193,12 @@
2211822193
** pointer if any kind of error was encountered.
2211922194
*/
2212022195
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
2212122196
if( p->zText ){
2212222197
p->zText[p->nChar] = 0;
22123
- if( p->useMalloc && p->zText==p->zBase ){
22124
- if( p->useMalloc==1 ){
22125
- p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22126
- }else{
22127
- p->zText = sqlite3_malloc(p->nChar+1);
22128
- }
22198
+ if( p->mxAlloc>0 && p->zText==p->zBase ){
22199
+ p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
2212922200
if( p->zText ){
2213022201
memcpy(p->zText, p->zBase, p->nChar+1);
2213122202
}else{
2213222203
setStrAccumError(p, STRACCUM_NOMEM);
2213322204
}
@@ -22139,29 +22210,35 @@
2213922210
/*
2214022211
** Reset an StrAccum string. Reclaim all malloced memory.
2214122212
*/
2214222213
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
2214322214
if( p->zText!=p->zBase ){
22144
- if( p->useMalloc==1 ){
22145
- sqlite3DbFree(p->db, p->zText);
22146
- }else{
22147
- sqlite3_free(p->zText);
22148
- }
22215
+ sqlite3DbFree(p->db, p->zText);
2214922216
}
2215022217
p->zText = 0;
2215122218
}
2215222219
2215322220
/*
22154
-** Initialize a string accumulator
22221
+** Initialize a string accumulator.
22222
+**
22223
+** p: The accumulator to be initialized.
22224
+** db: Pointer to a database connection. May be NULL. Lookaside
22225
+** memory is used if not NULL. db->mallocFailed is set appropriately
22226
+** when not NULL.
22227
+** zBase: An initial buffer. May be NULL in which case the initial buffer
22228
+** is malloced.
22229
+** n: Size of zBase in bytes. If total space requirements never exceed
22230
+** n then no memory allocations ever occur.
22231
+** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
22232
+** allocations will ever occur.
2215522233
*/
22156
-SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
22234
+SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
2215722235
p->zText = p->zBase = zBase;
22158
- p->db = 0;
22236
+ p->db = db;
2215922237
p->nChar = 0;
2216022238
p->nAlloc = n;
2216122239
p->mxAlloc = mx;
22162
- p->useMalloc = 1;
2216322240
p->accError = 0;
2216422241
}
2216522242
2216622243
/*
2216722244
** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22247,12 @@
2217022247
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
2217122248
char *z;
2217222249
char zBase[SQLITE_PRINT_BUF_SIZE];
2217322250
StrAccum acc;
2217422251
assert( db!=0 );
22175
- sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
22252
+ sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
2217622253
db->aLimit[SQLITE_LIMIT_LENGTH]);
22177
- acc.db = db;
2217822254
sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
2217922255
z = sqlite3StrAccumFinish(&acc);
2218022256
if( acc.accError==STRACCUM_NOMEM ){
2218122257
db->mallocFailed = 1;
2218222258
}
@@ -22230,12 +22306,11 @@
2223022306
}
2223122307
#endif
2223222308
#ifndef SQLITE_OMIT_AUTOINIT
2223322309
if( sqlite3_initialize() ) return 0;
2223422310
#endif
22235
- sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
22236
- acc.useMalloc = 2;
22311
+ sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
2223722312
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2223822313
z = sqlite3StrAccumFinish(&acc);
2223922314
return z;
2224022315
}
2224122316
@@ -22276,12 +22351,11 @@
2227622351
(void)SQLITE_MISUSE_BKPT;
2227722352
if( zBuf ) zBuf[0] = 0;
2227822353
return zBuf;
2227922354
}
2228022355
#endif
22281
- sqlite3StrAccumInit(&acc, zBuf, n, 0);
22282
- acc.useMalloc = 0;
22356
+ sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
2228322357
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2228422358
return sqlite3StrAccumFinish(&acc);
2228522359
}
2228622360
SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
2228722361
char *z;
@@ -22303,12 +22377,11 @@
2230322377
*/
2230422378
static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
2230522379
StrAccum acc; /* String accumulator */
2230622380
char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
2230722381
22308
- sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
22309
- acc.useMalloc = 0;
22382
+ sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
2231022383
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2231122384
sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
2231222385
sqlite3StrAccumFinish(&acc));
2231322386
}
2231422387
@@ -22322,22 +22395,21 @@
2232222395
renderLogMsg(iErrCode, zFormat, ap);
2232322396
va_end(ap);
2232422397
}
2232522398
}
2232622399
22327
-#if defined(SQLITE_DEBUG)
22400
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
2232822401
/*
2232922402
** A version of printf() that understands %lld. Used for debugging.
2233022403
** The printf() built into some versions of windows does not understand %lld
2233122404
** and segfaults if you give it a long long int.
2233222405
*/
2233322406
SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
2233422407
va_list ap;
2233522408
StrAccum acc;
2233622409
char zBuf[500];
22337
- sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22338
- acc.useMalloc = 0;
22410
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2233922411
va_start(ap,zFormat);
2234022412
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2234122413
va_end(ap);
2234222414
sqlite3StrAccumFinish(&acc);
2234322415
fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22432,11 @@
2236022432
*/
2236122433
/* Add a new subitem to the tree. The moreToFollow flag indicates that this
2236222434
** is not the last item in the tree. */
2236322435
SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
2236422436
if( p==0 ){
22365
- p = sqlite3_malloc( sizeof(*p) );
22437
+ p = sqlite3_malloc64( sizeof(*p) );
2236622438
if( p==0 ) return 0;
2236722439
memset(p, 0, sizeof(*p));
2236822440
}else{
2236922441
p->iLevel++;
2237022442
}
@@ -22383,12 +22455,11 @@
2238322455
SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
2238422456
va_list ap;
2238522457
int i;
2238622458
StrAccum acc;
2238722459
char zBuf[500];
22388
- sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22389
- acc.useMalloc = 0;
22460
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2239022461
if( p ){
2239122462
for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
2239222463
sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
2239322464
}
2239422465
sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24078,11 @@
2400724078
}else{
2400824079
return 0;
2400924080
}
2401024081
}
2401124082
#endif
24083
+ while( zNum[0]=='0' ) zNum++;
2401224084
for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
2401324085
v = v*10 + c;
2401424086
}
2401524087
2401624088
/* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25333,21 @@
2526125333
#if SQLITE_ENABLE_LOCKING_STYLE
2526225334
# include <sys/ioctl.h>
2526325335
# include <sys/file.h>
2526425336
# include <sys/param.h>
2526525337
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
25338
+
25339
+#if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
25340
+ (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
25341
+# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
25342
+ && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
25343
+# define HAVE_GETHOSTUUID 1
25344
+# else
25345
+# warning "gethostuuid() is disabled."
25346
+# endif
25347
+#endif
25348
+
2526625349
2526725350
#if OS_VXWORKS
2526825351
/* # include <sys/ioctl.h> */
2526925352
# include <semaphore.h>
2527025353
# include <limits.h>
@@ -25457,20 +25540,10 @@
2545725540
*/
2545825541
#ifdef MEMORY_DEBUG
2545925542
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
2546025543
#endif
2546125544
25462
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25463
-# ifndef SQLITE_DEBUG_OS_TRACE
25464
-# define SQLITE_DEBUG_OS_TRACE 0
25465
-# endif
25466
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
25467
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
25468
-#else
25469
-# define OSTRACE(X)
25470
-#endif
25471
-
2547225545
/*
2547325546
** Macros for performance tracing. Normally turned off. Only works
2547425547
** on i486 hardware.
2547525548
*/
2547625549
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26082,11 @@
2600926082
return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
2601026083
}
2601126084
#endif
2601226085
2601326086
26014
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
26087
+#ifdef SQLITE_HAVE_OS_TRACE
2601526088
/*
2601626089
** Helper function for printing out trace information from debugging
2601726090
** binaries. This returns the string representation of the supplied
2601826091
** integer lock-type.
2601926092
*/
@@ -26272,11 +26345,11 @@
2627226345
struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
2627326346
int n; /* Length of zAbsoluteName string */
2627426347
2627526348
assert( zAbsoluteName[0]=='/' );
2627626349
n = (int)strlen(zAbsoluteName);
26277
- pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) );
26350
+ pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) );
2627826351
if( pNew==0 ) return 0;
2627926352
pNew->zCanonicalName = (char*)&pNew[1];
2628026353
memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
2628126354
n = vxworksSimplifyName(pNew->zCanonicalName, n);
2628226355
@@ -26676,11 +26749,11 @@
2667626749
pInode = inodeList;
2667726750
while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
2667826751
pInode = pInode->pNext;
2667926752
}
2668026753
if( pInode==0 ){
26681
- pInode = sqlite3_malloc( sizeof(*pInode) );
26754
+ pInode = sqlite3_malloc64( sizeof(*pInode) );
2668226755
if( pInode==0 ){
2668326756
return SQLITE_NOMEM;
2668426757
}
2668526758
memset(pInode, 0, sizeof(*pInode));
2668626759
memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29270,11 @@
2919729270
case SQLITE_FCNTL_VFSNAME: {
2919829271
*(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
2919929272
return SQLITE_OK;
2920029273
}
2920129274
case SQLITE_FCNTL_TEMPFILENAME: {
29202
- char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
29275
+ char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
2920329276
if( zTFile ){
2920429277
unixGetTempname(pFile->pVfs->mxPathname, zTFile);
2920529278
*(char**)pArg = zTFile;
2920629279
}
2920729280
return SQLITE_OK;
@@ -29638,11 +29711,11 @@
2963829711
unixInodeInfo *pInode; /* The inode of fd */
2963929712
char *zShmFilename; /* Name of the file used for SHM */
2964029713
int nShmFilename; /* Size of the SHM filename in bytes */
2964129714
2964229715
/* Allocate space for the new unixShm object. */
29643
- p = sqlite3_malloc( sizeof(*p) );
29716
+ p = sqlite3_malloc64( sizeof(*p) );
2964429717
if( p==0 ) return SQLITE_NOMEM;
2964529718
memset(p, 0, sizeof(*p));
2964629719
assert( pDbFd->pShm==0 );
2964729720
2964829721
/* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29742,11 @@
2966929742
#ifdef SQLITE_SHM_DIRECTORY
2967029743
nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
2967129744
#else
2967229745
nShmFilename = 6 + (int)strlen(zBasePath);
2967329746
#endif
29674
- pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29747
+ pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
2967529748
if( pShmNode==0 ){
2967629749
rc = SQLITE_NOMEM;
2967729750
goto shm_open_err;
2967829751
}
2967929752
memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29952,11 @@
2987929952
if( pMem==MAP_FAILED ){
2988029953
rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
2988129954
goto shmpage_out;
2988229955
}
2988329956
}else{
29884
- pMem = sqlite3_malloc(szRegion);
29957
+ pMem = sqlite3_malloc64(szRegion);
2988529958
if( pMem==0 ){
2988629959
rc = SQLITE_NOMEM;
2988729960
goto shmpage_out;
2988829961
}
2988929962
memset(pMem, 0, szRegion);
@@ -30716,11 +30789,11 @@
3071630789
else if( pLockingStyle == &afpIoMethods ){
3071730790
/* AFP locking uses the file path so it needs to be included in
3071830791
** the afpLockingContext.
3071930792
*/
3072030793
afpLockingContext *pCtx;
30721
- pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) );
30794
+ pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
3072230795
if( pCtx==0 ){
3072330796
rc = SQLITE_NOMEM;
3072430797
}else{
3072530798
/* NB: zFilename exists and remains valid until the file is closed
3072630799
** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30819,11 @@
3074630819
*/
3074730820
char *zLockFile;
3074830821
int nFilename;
3074930822
assert( zFilename!=0 );
3075030823
nFilename = (int)strlen(zFilename) + 6;
30751
- zLockFile = (char *)sqlite3_malloc(nFilename);
30824
+ zLockFile = (char *)sqlite3_malloc64(nFilename);
3075230825
if( zLockFile==0 ){
3075330826
rc = SQLITE_NOMEM;
3075430827
}else{
3075530828
sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
3075630829
}
@@ -31123,11 +31196,11 @@
3112331196
UnixUnusedFd *pUnused;
3112431197
pUnused = findReusableFd(zName, flags);
3112531198
if( pUnused ){
3112631199
fd = pUnused->fd;
3112731200
}else{
31128
- pUnused = sqlite3_malloc(sizeof(*pUnused));
31201
+ pUnused = sqlite3_malloc64(sizeof(*pUnused));
3112931202
if( !pUnused ){
3113031203
return SQLITE_NOMEM;
3113131204
}
3113231205
}
3113331206
p->pUnused = pUnused;
@@ -31503,11 +31576,11 @@
3150331576
** that we always use the same random number sequence. This makes the
3150431577
** tests repeatable.
3150531578
*/
3150631579
memset(zBuf, 0, nBuf);
3150731580
randomnessPid = osGetpid(0);
31508
-#if !defined(SQLITE_TEST)
31581
+#if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
3150931582
{
3151031583
int fd, got;
3151131584
fd = robust_open("/dev/urandom", O_RDONLY, 0);
3151231585
if( fd<0 ){
3151331586
time_t t;
@@ -31915,11 +31988,11 @@
3191531988
*/
3191631989
pUnused = findReusableFd(path, openFlags);
3191731990
if( pUnused ){
3191831991
fd = pUnused->fd;
3191931992
}else{
31920
- pUnused = sqlite3_malloc(sizeof(*pUnused));
31993
+ pUnused = sqlite3_malloc64(sizeof(*pUnused));
3192131994
if( !pUnused ){
3192231995
return SQLITE_NOMEM;
3192331996
}
3192431997
}
3192531998
if( fd<0 ){
@@ -31948,11 +32021,11 @@
3194832021
default:
3194932022
return SQLITE_CANTOPEN_BKPT;
3195032023
}
3195132024
}
3195232025
31953
- pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew));
32026
+ pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
3195432027
if( pNew==NULL ){
3195532028
rc = SQLITE_NOMEM;
3195632029
goto end_create_proxy;
3195732030
}
3195832031
memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32054,22 @@
3198132054
SQLITE_API int sqlite3_hostid_num = 0;
3198232055
#endif
3198332056
3198432057
#define PROXY_HOSTIDLEN 16 /* conch file host id length */
3198532058
32059
+#ifdef HAVE_GETHOSTUUID
3198632060
/* Not always defined in the headers as it ought to be */
3198732061
extern int gethostuuid(uuid_t id, const struct timespec *wait);
32062
+#endif
3198832063
3198932064
/* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
3199032065
** bytes of writable memory.
3199132066
*/
3199232067
static int proxyGetHostID(unsigned char *pHostID, int *pError){
3199332068
assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
3199432069
memset(pHostID, 0, PROXY_HOSTIDLEN);
31995
-# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31996
- (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
32070
+#ifdef HAVE_GETHOSTUUID
3199732071
{
3199832072
struct timespec timeout = {1, 0}; /* 1 sec timeout */
3199932073
if( gethostuuid(pHostID, &timeout) ){
3200032074
int err = errno;
3200132075
if( pError ){
@@ -32409,11 +32483,11 @@
3240932483
return rc;
3241032484
}
3241132485
3241232486
/*
3241332487
** Given the name of a database file, compute the name of its conch file.
32414
-** Store the conch filename in memory obtained from sqlite3_malloc().
32488
+** Store the conch filename in memory obtained from sqlite3_malloc64().
3241532489
** Make *pConchPath point to the new name. Return SQLITE_OK on success
3241632490
** or SQLITE_NOMEM if unable to obtain memory.
3241732491
**
3241832492
** The caller is responsible for ensuring that the allocated memory
3241932493
** space is eventually freed.
@@ -32425,11 +32499,11 @@
3242532499
int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
3242632500
char *conchPath; /* buffer in which to construct conch name */
3242732501
3242832502
/* Allocate space for the conch filename and initialize the name to
3242932503
** the name of the original database file. */
32430
- *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8);
32504
+ *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
3243132505
if( conchPath==0 ){
3243232506
return SQLITE_NOMEM;
3243332507
}
3243432508
memcpy(conchPath, dbPath, len+1);
3243532509
@@ -32541,11 +32615,11 @@
3254132615
}
3254232616
3254332617
OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
3254432618
(lockPath ? lockPath : ":auto:"), osGetpid(0)));
3254532619
32546
- pCtx = sqlite3_malloc( sizeof(*pCtx) );
32620
+ pCtx = sqlite3_malloc64( sizeof(*pCtx) );
3254732621
if( pCtx==0 ){
3254832622
return SQLITE_NOMEM;
3254932623
}
3255032624
memset(pCtx, 0, sizeof(*pCtx));
3255132625
@@ -32985,20 +33059,10 @@
3298533059
*/
3298633060
#ifdef MEMORY_DEBUG
3298733061
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
3298833062
#endif
3298933063
32990
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
32991
-# ifndef SQLITE_DEBUG_OS_TRACE
32992
-# define SQLITE_DEBUG_OS_TRACE 0
32993
-# endif
32994
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
32995
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
32996
-#else
32997
-# define OSTRACE(X)
32998
-#endif
32999
-
3300033064
/*
3300133065
** Macros for performance tracing. Normally turned off. Only works
3300233066
** on i486 hardware.
3300333067
*/
3300433068
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35962,11 @@
3589835962
** Used only when SQLITE_NO_SYNC is not defined.
3589935963
*/
3590035964
BOOL rc;
3590135965
#endif
3590235966
#if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35903
- (defined(SQLITE_TEST) && defined(SQLITE_DEBUG))
35967
+ defined(SQLITE_HAVE_OS_TRACE)
3590435968
/*
3590535969
** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
3590635970
** OSTRACE() macros.
3590735971
*/
3590835972
winFile *pFile = (winFile*)id;
@@ -36575,11 +36639,11 @@
3657536639
DWORD lastErrno; /* The Windows errno from the last I/O error */
3657636640
3657736641
int nRef; /* Number of winShm objects pointing to this */
3657836642
winShm *pFirst; /* All winShm objects pointing to this */
3657936643
winShmNode *pNext; /* Next in list of all winShmNode objects */
36580
-#ifdef SQLITE_DEBUG
36644
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3658136645
u8 nextShmId; /* Next available winShm.id value */
3658236646
#endif
3658336647
};
3658436648
3658536649
/*
@@ -36606,11 +36670,11 @@
3660636670
winShmNode *pShmNode; /* The underlying winShmNode object */
3660736671
winShm *pNext; /* Next winShm with the same winShmNode */
3660836672
u8 hasMutex; /* True if holding the winShmNode mutex */
3660936673
u16 sharedMask; /* Mask of shared locks held */
3661036674
u16 exclMask; /* Mask of exclusive locks held */
36611
-#ifdef SQLITE_DEBUG
36675
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3661236676
u8 id; /* Id of this connection with its winShmNode */
3661336677
#endif
3661436678
};
3661536679
3661636680
/*
@@ -36797,11 +36861,11 @@
3679736861
if( rc ) goto shm_open_err;
3679836862
}
3679936863
3680036864
/* Make the new connection a child of the winShmNode */
3680136865
p->pShmNode = pShmNode;
36802
-#ifdef SQLITE_DEBUG
36866
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3680336867
p->id = pShmNode->nextShmId++;
3680436868
#endif
3680536869
pShmNode->nRef++;
3680636870
pDbFd->pShm = p;
3680736871
winShmLeaveMutex();
@@ -37066,11 +37130,11 @@
3706637130
goto shmpage_out;
3706737131
}
3706837132
}
3706937133
3707037134
/* Map the requested memory region into this processes address space. */
37071
- apNew = (struct ShmRegion *)sqlite3_realloc(
37135
+ apNew = (struct ShmRegion *)sqlite3_realloc64(
3707237136
pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
3707337137
);
3707437138
if( !apNew ){
3707537139
rc = SQLITE_IOERR_NOMEM;
3707637140
goto shmpage_out;
@@ -38513,11 +38577,11 @@
3851338577
** Write up to nBuf bytes of randomness into zBuf.
3851438578
*/
3851538579
static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
3851638580
int n = 0;
3851738581
UNUSED_PARAMETER(pVfs);
38518
-#if defined(SQLITE_TEST)
38582
+#if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
3851938583
n = nBuf;
3852038584
memset(zBuf, 0, nBuf);
3852138585
#else
3852238586
if( sizeof(SYSTEMTIME)<=nBuf-n ){
3852338587
SYSTEMTIME x;
@@ -38547,11 +38611,10 @@
3854738611
LARGE_INTEGER i;
3854838612
osQueryPerformanceCounter(&i);
3854938613
memcpy(&zBuf[n], &i, sizeof(i));
3855038614
n += sizeof(i);
3855138615
}
38552
-#endif
3855338616
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
3855438617
if( sizeof(UUID)<=nBuf-n ){
3855538618
UUID id;
3855638619
memset(&id, 0, sizeof(UUID));
3855738620
osUuidCreate(&id);
@@ -38564,10 +38627,11 @@
3856438627
osUuidCreateSequential(&id);
3856538628
memcpy(zBuf, &id, sizeof(UUID));
3856638629
n += sizeof(UUID);
3856738630
}
3856838631
#endif
38632
+#endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
3856938633
return n;
3857038634
}
3857138635
3857238636
3857338637
/*
@@ -39118,11 +39182,11 @@
3911839182
3911939183
/* Allocate the Bitvec to be tested and a linear array of
3912039184
** bits to act as the reference */
3912139185
pBitvec = sqlite3BitvecCreate( sz );
3912239186
pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39123
- pTmpSpace = sqlite3_malloc(BITVEC_SZ);
39187
+ pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
3912439188
if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
3912539189
3912639190
/* NULL pBitvec tests */
3912739191
sqlite3BitvecSet(0, 1);
3912839192
sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44671,11 @@
4460744671
Pgno nTruncate, /* Database size after this commit */
4460844672
int isCommit /* True if this is a commit */
4460944673
){
4461044674
int rc; /* Return code */
4461144675
int nList; /* Number of pages in pList */
44612
-#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
4461344676
PgHdr *p; /* For looping over pages */
44614
-#endif
4461544677
4461644678
assert( pPager->pWal );
4461744679
assert( pList );
4461844680
#ifdef SQLITE_DEBUG
4461944681
/* Verify that the page list is in accending order */
@@ -44626,11 +44688,10 @@
4462644688
if( isCommit ){
4462744689
/* If a WAL transaction is being committed, there is no point in writing
4462844690
** any pages with page numbers greater than nTruncate into the WAL file.
4462944691
** They will never be read by any client. So remove them from the pDirty
4463044692
** list here. */
44631
- PgHdr *p;
4463244693
PgHdr **ppNext = &pList;
4463344694
nList = 0;
4463444695
for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
4463544696
if( p->pgno<=nTruncate ){
4463644697
ppNext = &p->pDirty;
@@ -44646,11 +44707,10 @@
4464644707
if( pList->pgno==1 ) pager_write_changecounter(pList);
4464744708
rc = sqlite3WalFrames(pPager->pWal,
4464844709
pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
4464944710
);
4465044711
if( rc==SQLITE_OK && pPager->pBackup ){
44651
- PgHdr *p;
4465244712
for(p=pList; p; p=p->pDirty){
4465344713
sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
4465444714
}
4465544715
}
4465644716
@@ -48577,10 +48637,12 @@
4857748637
}else if( state==PAGER_OPEN ){
4857848638
pager_unlock(pPager);
4857948639
}
4858048640
assert( state==pPager->eState );
4858148641
}
48642
+ }else if( eMode==PAGER_JOURNALMODE_OFF ){
48643
+ sqlite3OsClose(pPager->jfd);
4858248644
}
4858348645
}
4858448646
4858548647
/* Return the new journal mode */
4858648648
return (int)pPager->journalMode;
@@ -49359,11 +49421,11 @@
4935949421
4936049422
/* Enlarge the pWal->apWiData[] array if required */
4936149423
if( pWal->nWiData<=iPage ){
4936249424
int nByte = sizeof(u32*)*(iPage+1);
4936349425
volatile u32 **apNew;
49364
- apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte);
49426
+ apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
4936549427
if( !apNew ){
4936649428
*ppPage = 0;
4936749429
return SQLITE_NOMEM;
4936849430
}
4936949431
memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50046,11 @@
4998450046
goto finished;
4998550047
}
4998650048
4998750049
/* Malloc a buffer to read frames into. */
4998850050
szFrame = szPage + WAL_FRAME_HDRSIZE;
49989
- aFrame = (u8 *)sqlite3_malloc(szFrame);
50051
+ aFrame = (u8 *)sqlite3_malloc64(szFrame);
4999050052
if( !aFrame ){
4999150053
rc = SQLITE_NOMEM;
4999250054
goto recovery_error;
4999350055
}
4999450056
aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50439,21 @@
5037750439
/* Allocate space for the WalIterator object. */
5037850440
nSegment = walFramePage(iLast) + 1;
5037950441
nByte = sizeof(WalIterator)
5038050442
+ (nSegment-1)*sizeof(struct WalSegment)
5038150443
+ iLast*sizeof(ht_slot);
50382
- p = (WalIterator *)sqlite3_malloc(nByte);
50444
+ p = (WalIterator *)sqlite3_malloc64(nByte);
5038350445
if( !p ){
5038450446
return SQLITE_NOMEM;
5038550447
}
5038650448
memset(p, 0, nByte);
5038750449
p->nSegment = nSegment;
5038850450
5038950451
/* Allocate temporary space used by the merge-sort routine. This block
5039050452
** of memory will be freed before this function returns.
5039150453
*/
50392
- aTmp = (ht_slot *)sqlite3_malloc(
50454
+ aTmp = (ht_slot *)sqlite3_malloc64(
5039350455
sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
5039450456
);
5039550457
if( !aTmp ){
5039650458
rc = SQLITE_NOMEM;
5039750459
}
@@ -50567,10 +50629,18 @@
5056750629
** cannot be backfilled from the WAL.
5056850630
*/
5056950631
mxSafeFrame = pWal->hdr.mxFrame;
5057050632
mxPage = pWal->hdr.nPage;
5057150633
for(i=1; i<WAL_NREADER; i++){
50634
+ /* Thread-sanitizer reports that the following is an unsafe read,
50635
+ ** as some other thread may be in the process of updating the value
50636
+ ** of the aReadMark[] slot. The assumption here is that if that is
50637
+ ** happening, the other client may only be increasing the value,
50638
+ ** not decreasing it. So assuming either that either the "old" or
50639
+ ** "new" version of the value is read, and not some arbitrary value
50640
+ ** that would never be written by a real client, things are still
50641
+ ** safe. */
5057250642
u32 y = pInfo->aReadMark[i];
5057350643
if( mxSafeFrame>y ){
5057450644
assert( y<=pWal->hdr.mxFrame );
5057550645
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
5057650646
if( rc==SQLITE_OK ){
@@ -57429,17 +57499,22 @@
5742957499
*/
5743057500
static const void *fetchPayload(
5743157501
BtCursor *pCur, /* Cursor pointing to entry to read from */
5743257502
u32 *pAmt /* Write the number of available bytes here */
5743357503
){
57504
+ u32 amt;
5743457505
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
5743557506
assert( pCur->eState==CURSOR_VALID );
5743657507
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5743757508
assert( cursorHoldsMutex(pCur) );
5743857509
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
5743957510
assert( pCur->info.nSize>0 );
57440
- *pAmt = pCur->info.nLocal;
57511
+ assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
57512
+ assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
57513
+ amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
57514
+ if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
57515
+ *pAmt = amt;
5744157516
return (void*)pCur->info.pPayload;
5744257517
}
5744357518
5744457519
5744557520
/*
@@ -59713,11 +59788,10 @@
5971359788
if( iParentIdx==0 ){
5971459789
nxDiv = 0;
5971559790
}else if( iParentIdx==i ){
5971659791
nxDiv = i-2+bBulk;
5971759792
}else{
59718
- assert( bBulk==0 );
5971959793
nxDiv = iParentIdx-1;
5972059794
}
5972159795
i = 2-bBulk;
5972259796
}
5972359797
nOld = i+1;
@@ -61501,10 +61575,61 @@
6150161575
iPage = get4byte(pOvflData);
6150261576
sqlite3PagerUnref(pOvflPage);
6150361577
}
6150461578
}
6150561579
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
61580
+
61581
+/*
61582
+** An implementation of a min-heap.
61583
+**
61584
+** aHeap[0] is the number of elements on the heap. aHeap[1] is the
61585
+** root element. The daughter nodes of aHeap[N] are aHeap[N*2]
61586
+** and aHeap[N*2+1].
61587
+**
61588
+** The heap property is this: Every node is less than or equal to both
61589
+** of its daughter nodes. A consequence of the heap property is that the
61590
+** root node aHeap[1] is always the minimum value currently in the heap.
61591
+**
61592
+** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
61593
+** the heap, preserving the heap property. The btreeHeapPull() routine
61594
+** removes the root element from the heap (the minimum value in the heap)
61595
+** and then moves other nodes around as necessary to preserve the heap
61596
+** property.
61597
+**
61598
+** This heap is used for cell overlap and coverage testing. Each u32
61599
+** entry represents the span of a cell or freeblock on a btree page.
61600
+** The upper 16 bits are the index of the first byte of a range and the
61601
+** lower 16 bits are the index of the last byte of that range.
61602
+*/
61603
+static void btreeHeapInsert(u32 *aHeap, u32 x){
61604
+ u32 j, i = ++aHeap[0];
61605
+ aHeap[i] = x;
61606
+ while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
61607
+ x = aHeap[j];
61608
+ aHeap[j] = aHeap[i];
61609
+ aHeap[i] = x;
61610
+ i = j;
61611
+ }
61612
+}
61613
+static int btreeHeapPull(u32 *aHeap, u32 *pOut){
61614
+ u32 j, i, x;
61615
+ if( (x = aHeap[0])==0 ) return 0;
61616
+ *pOut = aHeap[1];
61617
+ aHeap[1] = aHeap[x];
61618
+ aHeap[x] = 0xffffffff;
61619
+ aHeap[0]--;
61620
+ i = 1;
61621
+ while( (j = i*2)<=aHeap[0] ){
61622
+ if( aHeap[j]>aHeap[j+1] ) j++;
61623
+ if( aHeap[i]<aHeap[j] ) break;
61624
+ x = aHeap[i];
61625
+ aHeap[i] = aHeap[j];
61626
+ aHeap[j] = x;
61627
+ i = j;
61628
+ }
61629
+ return 1;
61630
+}
6150661631
6150761632
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
6150861633
/*
6150961634
** Do various sanity checks on a single page of a tree. Return
6151061635
** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61659,12 @@
6153461659
int hdr, cellStart;
6153561660
int nCell;
6153661661
u8 *data;
6153761662
BtShared *pBt;
6153861663
int usableSize;
61539
- char *hit = 0;
61664
+ u32 *heap = 0;
61665
+ u32 x, prev = 0;
6154061666
i64 nMinKey = 0;
6154161667
i64 nMaxKey = 0;
6154261668
const char *saved_zPfx = pCheck->zPfx;
6154361669
int saved_v1 = pCheck->v1;
6154461670
int saved_v2 = pCheck->v2;
@@ -61679,19 +61805,19 @@
6167961805
6168061806
/* Check for complete coverage of the page
6168161807
*/
6168261808
data = pPage->aData;
6168361809
hdr = pPage->hdrOffset;
61684
- hit = sqlite3PageMalloc( pBt->pageSize );
61810
+ heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
6168561811
pCheck->zPfx = 0;
61686
- if( hit==0 ){
61812
+ if( heap==0 ){
6168761813
pCheck->mallocFailed = 1;
6168861814
}else{
6168961815
int contentOffset = get2byteNotZero(&data[hdr+5]);
6169061816
assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61691
- memset(hit+contentOffset, 0, usableSize-contentOffset);
61692
- memset(hit, 1, contentOffset);
61817
+ heap[0] = 0;
61818
+ btreeHeapInsert(heap, contentOffset-1);
6169361819
/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
6169461820
** number of cells on the page. */
6169561821
nCell = get2byte(&data[hdr+3]);
6169661822
/* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
6169761823
** immediately follows the b-tree page header. */
@@ -61699,20 +61825,19 @@
6169961825
/* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
6170061826
** integer offsets to the cell contents. */
6170161827
for(i=0; i<nCell; i++){
6170261828
int pc = get2byte(&data[cellStart+i*2]);
6170361829
u32 size = 65536;
61704
- int j;
6170561830
if( pc<=usableSize-4 ){
6170661831
size = cellSizePtr(pPage, &data[pc]);
6170761832
}
6170861833
if( (int)(pc+size-1)>=usableSize ){
6170961834
pCheck->zPfx = 0;
6171061835
checkAppendMsg(pCheck,
6171161836
"Corruption detected in cell %d on page %d",i,iPage);
6171261837
}else{
61713
- for(j=pc+size-1; j>=pc; j--) hit[j]++;
61838
+ btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
6171461839
}
6171561840
}
6171661841
/* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
6171761842
** is the offset of the first freeblock, or zero if there are no
6171861843
** freeblocks on the page. */
@@ -61720,11 +61845,11 @@
6172061845
while( i>0 ){
6172161846
int size, j;
6172261847
assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
6172361848
size = get2byte(&data[i+2]);
6172461849
assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61725
- for(j=i+size-1; j>=i; j--) hit[j]++;
61850
+ btreeHeapInsert(heap, (i<<16)|(i+size-1));
6172661851
/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
6172761852
** big-endian integer which is the offset in the b-tree page of the next
6172861853
** freeblock in the chain, or zero if the freeblock is the last on the
6172961854
** chain. */
6173061855
j = get2byte(&data[i]);
@@ -61732,31 +61857,37 @@
6173261857
** increasing offset. */
6173361858
assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
6173461859
assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
6173561860
i = j;
6173661861
}
61737
- for(i=cnt=0; i<usableSize; i++){
61738
- if( hit[i]==0 ){
61739
- cnt++;
61740
- }else if( hit[i]>1 ){
61862
+ cnt = 0;
61863
+ assert( heap[0]>0 );
61864
+ assert( (heap[1]>>16)==0 );
61865
+ btreeHeapPull(heap,&prev);
61866
+ while( btreeHeapPull(heap,&x) ){
61867
+ if( (prev&0xffff)+1>(x>>16) ){
6174161868
checkAppendMsg(pCheck,
61742
- "Multiple uses for byte %d of page %d", i, iPage);
61869
+ "Multiple uses for byte %u of page %d", x>>16, iPage);
6174361870
break;
61871
+ }else{
61872
+ cnt += (x>>16) - (prev&0xffff) - 1;
61873
+ prev = x;
6174461874
}
6174561875
}
61876
+ cnt += usableSize - (prev&0xffff) - 1;
6174661877
/* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
6174761878
** is stored in the fifth field of the b-tree page header.
6174861879
** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
6174961880
** number of fragmented free bytes within the cell content area.
6175061881
*/
61751
- if( cnt!=data[hdr+7] ){
61882
+ if( heap[0]==0 && cnt!=data[hdr+7] ){
6175261883
checkAppendMsg(pCheck,
6175361884
"Fragmentation of %d bytes reported as %d on page %d",
6175461885
cnt, data[hdr+7], iPage);
6175561886
}
6175661887
}
61757
- sqlite3PageFree(hit);
61888
+ sqlite3PageFree(heap);
6175861889
releasePage(pPage);
6175961890
6176061891
end_of_check:
6176161892
pCheck->zPfx = saved_zPfx;
6176261893
pCheck->v1 = saved_v1;
@@ -61816,12 +61947,11 @@
6181661947
sqlite3BtreeLeave(p);
6181761948
return 0;
6181861949
}
6181961950
i = PENDING_BYTE_PAGE(pBt);
6182061951
if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61821
- sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
61822
- sCheck.errMsg.useMalloc = 2;
61952
+ sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
6182361953
6182461954
/* Check the integrity of the freelist
6182561955
*/
6182661956
sCheck.zPfx = "Main freelist: ";
6182761957
checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63283,15 @@
6315363283
return SQLITE_NOMEM;
6315463284
}
6315563285
pMem->z[pMem->n] = 0;
6315663286
pMem->z[pMem->n+1] = 0;
6315763287
pMem->flags |= MEM_Term;
63288
+ }
63289
+ pMem->flags &= ~MEM_Ephem;
6315863290
#ifdef SQLITE_DEBUG
63159
- pMem->pScopyFrom = 0;
63291
+ pMem->pScopyFrom = 0;
6316063292
#endif
63161
- }
6316263293
6316363294
return SQLITE_OK;
6316463295
}
6316563296
6316663297
/*
@@ -64600,11 +64731,11 @@
6460064731
int i;
6460164732
int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
6460264733
Mem *aMem = pRec->aMem;
6460364734
sqlite3 *db = aMem[0].db;
6460464735
for(i=0; i<nCol; i++){
64605
- if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
64736
+ sqlite3VdbeMemRelease(&aMem[i]);
6460664737
}
6460764738
sqlite3KeyInfoUnref(pRec->pKeyInfo);
6460864739
sqlite3DbFree(db, pRec);
6460964740
}
6461064741
}
@@ -66436,18 +66567,35 @@
6643666567
pVtabCursor->pVtab->nRef--;
6643766568
pModule->xClose(pVtabCursor);
6643866569
}
6643966570
#endif
6644066571
}
66572
+
66573
+/*
66574
+** Close all cursors in the current frame.
66575
+*/
66576
+static void closeCursorsInFrame(Vdbe *p){
66577
+ if( p->apCsr ){
66578
+ int i;
66579
+ for(i=0; i<p->nCursor; i++){
66580
+ VdbeCursor *pC = p->apCsr[i];
66581
+ if( pC ){
66582
+ sqlite3VdbeFreeCursor(p, pC);
66583
+ p->apCsr[i] = 0;
66584
+ }
66585
+ }
66586
+ }
66587
+}
6644166588
6644266589
/*
6644366590
** Copy the values stored in the VdbeFrame structure to its Vdbe. This
6644466591
** is used, for example, when a trigger sub-program is halted to restore
6644566592
** control to the main program.
6644666593
*/
6644766594
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
6644866595
Vdbe *v = pFrame->v;
66596
+ closeCursorsInFrame(v);
6644966597
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
6645066598
v->anExec = pFrame->anExec;
6645166599
#endif
6645266600
v->aOnceFlag = pFrame->aOnceFlag;
6645366601
v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66626,11 @@
6647866626
sqlite3VdbeFrameRestore(pFrame);
6647966627
p->pFrame = 0;
6648066628
p->nFrame = 0;
6648166629
}
6648266630
assert( p->nFrame==0 );
66483
-
66484
- if( p->apCsr ){
66485
- int i;
66486
- for(i=0; i<p->nCursor; i++){
66487
- VdbeCursor *pC = p->apCsr[i];
66488
- if( pC ){
66489
- sqlite3VdbeFreeCursor(p, pC);
66490
- p->apCsr[i] = 0;
66491
- }
66492
- }
66493
- }
66631
+ closeCursorsInFrame(p);
6649466632
if( p->aMem ){
6649566633
releaseMemArray(&p->aMem[1], p->nMem);
6649666634
}
6649766635
while( p->pDelFrame ){
6649866636
VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68371,11 @@
6823368371
** If database corruption is discovered, set pPKey2->errCode to
6823468372
** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
6823568373
** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
6823668374
** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
6823768375
*/
68238
-static int vdbeRecordCompareWithSkip(
68376
+SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
6823968377
int nKey1, const void *pKey1, /* Left key */
6824068378
UnpackedRecord *pPKey2, /* Right key */
6824168379
int bSkip /* If true, skip the first field */
6824268380
){
6824368381
u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68557,11 @@
6841968557
}
6842068558
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
6842168559
int nKey1, const void *pKey1, /* Left key */
6842268560
UnpackedRecord *pPKey2 /* Right key */
6842368561
){
68424
- return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68562
+ return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
6842568563
}
6842668564
6842768565
6842868566
/*
6842968567
** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68645,11 @@
6850768645
}else if( v<lhs ){
6850868646
res = pPKey2->r2;
6850968647
}else if( pPKey2->nField>1 ){
6851068648
/* The first fields of the two keys are equal. Compare the trailing
6851168649
** fields. */
68512
- res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68650
+ res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6851368651
}else{
6851468652
/* The first fields of the two keys are equal and there are no trailing
6851568653
** fields. Return pPKey2->default_rc in this case. */
6851668654
res = pPKey2->default_rc;
6851768655
}
@@ -68555,11 +68693,11 @@
6855568693
6855668694
if( res==0 ){
6855768695
res = nStr - pPKey2->aMem[0].n;
6855868696
if( res==0 ){
6855968697
if( pPKey2->nField>1 ){
68560
- res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68698
+ res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6856168699
}else{
6856268700
res = pPKey2->default_rc;
6856368701
}
6856468702
}else if( res>0 ){
6856568703
res = pPKey2->r2;
@@ -70497,21 +70635,22 @@
7049770635
Mem *pVar; /* Value of a host parameter */
7049870636
StrAccum out; /* Accumulate the output here */
7049970637
char zBase[100]; /* Initial working space */
7050070638
7050170639
db = p->db;
70502
- sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
70640
+ sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
7050370641
db->aLimit[SQLITE_LIMIT_LENGTH]);
70504
- out.db = db;
7050570642
if( db->nVdbeExec>1 ){
7050670643
while( *zRawSql ){
7050770644
const char *zStart = zRawSql;
7050870645
while( *(zRawSql++)!='\n' && *zRawSql );
7050970646
sqlite3StrAccumAppend(&out, "-- ", 3);
7051070647
assert( (zRawSql - zStart) > 0 );
7051170648
sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
7051270649
}
70650
+ }else if( p->nVar==0 ){
70651
+ sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
7051370652
}else{
7051470653
while( zRawSql[0] ){
7051570654
n = findNextHostParameter(zRawSql, &nToken);
7051670655
assert( n>0 );
7051770656
sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70663,16 @@
7052470663
sqlite3GetInt32(&zRawSql[1], &idx);
7052570664
}else{
7052670665
idx = nextIndex;
7052770666
}
7052870667
}else{
70529
- assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
70668
+ assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
70669
+ zRawSql[0]=='@' || zRawSql[0]=='#' );
7053070670
testcase( zRawSql[0]==':' );
7053170671
testcase( zRawSql[0]=='$' );
7053270672
testcase( zRawSql[0]=='@' );
70673
+ testcase( zRawSql[0]=='#' );
7053370674
idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
7053470675
assert( idx>0 );
7053570676
}
7053670677
zRawSql += nToken;
7053770678
nextIndex = idx + 1;
@@ -71202,21 +71343,38 @@
7120271343
assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
7120371344
return 1;
7120471345
}
7120571346
#endif
7120671347
71348
+/*
71349
+** Return the register of pOp->p2 after first preparing it to be
71350
+** overwritten with an integer value.
71351
+*/
71352
+static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
71353
+ Mem *pOut;
71354
+ assert( pOp->p2>0 );
71355
+ assert( pOp->p2<=(p->nMem-p->nCursor) );
71356
+ pOut = &p->aMem[pOp->p2];
71357
+ memAboutToChange(p, pOut);
71358
+ if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71359
+ pOut->flags = MEM_Int;
71360
+ return pOut;
71361
+}
71362
+
7120771363
7120871364
/*
7120971365
** Execute as much of a VDBE program as we can.
7121071366
** This is the core of sqlite3_step().
7121171367
*/
7121271368
SQLITE_PRIVATE int sqlite3VdbeExec(
7121371369
Vdbe *p /* The VDBE */
7121471370
){
71215
- int pc=0; /* The program counter */
7121671371
Op *aOp = p->aOp; /* Copy of p->aOp */
71217
- Op *pOp; /* Current operation */
71372
+ Op *pOp = aOp; /* Current operation */
71373
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71374
+ Op *pOrigOp; /* Value of pOp at the top of the loop */
71375
+#endif
7121871376
int rc = SQLITE_OK; /* Value to return */
7121971377
sqlite3 *db = p->db; /* The database */
7122071378
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
7122171379
u8 encoding = ENC(db); /* The database encoding */
7122271380
int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71446,26 @@
7128871446
}
7128971447
if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
7129071448
}
7129171449
sqlite3EndBenignMalloc();
7129271450
#endif
71293
- for(pc=p->pc; rc==SQLITE_OK; pc++){
71294
- assert( pc>=0 && pc<p->nOp );
71451
+ for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){
71452
+ assert( pOp>=aOp && pOp<&aOp[p->nOp]);
7129571453
if( db->mallocFailed ) goto no_mem;
7129671454
#ifdef VDBE_PROFILE
7129771455
start = sqlite3Hwtime();
7129871456
#endif
7129971457
nVmStep++;
71300
- pOp = &aOp[pc];
7130171458
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71302
- if( p->anExec ) p->anExec[pc]++;
71459
+ if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
7130371460
#endif
7130471461
7130571462
/* Only allow tracing if SQLITE_DEBUG is defined.
7130671463
*/
7130771464
#ifdef SQLITE_DEBUG
7130871465
if( db->flags & SQLITE_VdbeTrace ){
71309
- sqlite3VdbePrintOp(stdout, pc, pOp);
71466
+ sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
7131071467
}
7131171468
#endif
7131271469
7131371470
7131471471
/* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71478,13 @@
7132171478
sqlite3_interrupt(db);
7132271479
}
7132371480
}
7132471481
#endif
7132571482
71326
- /* On any opcode with the "out2-prerelease" tag, free any
71327
- ** external allocations out of mem[p2] and set mem[p2] to be
71328
- ** an undefined integer. Opcodes will either fill in the integer
71329
- ** value or convert mem[p2] to a different type.
71330
- */
71331
- assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71332
- if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
71333
- assert( pOp->p2>0 );
71334
- assert( pOp->p2<=(p->nMem-p->nCursor) );
71335
- pOut = &aMem[pOp->p2];
71336
- memAboutToChange(p, pOut);
71337
- if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71338
- pOut->flags = MEM_Int;
71339
- }
71340
-
7134171483
/* Sanity checking on other operands */
7134271484
#ifdef SQLITE_DEBUG
71485
+ assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
7134371486
if( (pOp->opflags & OPFLG_IN1)!=0 ){
7134471487
assert( pOp->p1>0 );
7134571488
assert( pOp->p1<=(p->nMem-p->nCursor) );
7134671489
assert( memIsValid(&aMem[pOp->p1]) );
7134771490
assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71513,13 @@
7137071513
assert( pOp->p3>0 );
7137171514
assert( pOp->p3<=(p->nMem-p->nCursor) );
7137271515
memAboutToChange(p, &aMem[pOp->p3]);
7137371516
}
7137471517
#endif
71518
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71519
+ pOrigOp = pOp;
71520
+#endif
7137571521
7137671522
switch( pOp->opcode ){
7137771523
7137871524
/*****************************************************************************
7137971525
** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71539,11 @@
7139371539
** case statement is followed by a comment of the form "/# same as ... #/"
7139471540
** that comment is used to determine the particular value of the opcode.
7139571541
**
7139671542
** Other keywords in the comment that follows each case are used to
7139771543
** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71398
-** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See
71544
+** Keywords include: in1, in2, in3, out2, out3. See
7139971545
** the mkopcodeh.awk script for additional information.
7140071546
**
7140171547
** Documentation about VDBE opcodes is generated by scanning this file
7140271548
** for lines of that contain "Opcode:". That line and all subsequent
7140371549
** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71567,12 @@
7142171567
** is sometimes set to 1 instead of 0 as a hint to the command-line shell
7142271568
** that this Goto is the bottom of a loop and that the lines from P2 down
7142371569
** to the current line should be indented for EXPLAIN output.
7142471570
*/
7142571571
case OP_Goto: { /* jump */
71426
- pc = pOp->p2 - 1;
71572
+jump_to_p2_and_check_for_interrupt:
71573
+ pOp = &aOp[pOp->p2 - 1];
7142771574
7142871575
/* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
7142971576
** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
7143071577
** completion. Check to see if sqlite3_interrupt() has been called
7143171578
** or if the progress callback needs to be invoked.
@@ -71466,13 +71613,17 @@
7146671613
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
7146771614
pIn1 = &aMem[pOp->p1];
7146871615
assert( VdbeMemDynamic(pIn1)==0 );
7146971616
memAboutToChange(p, pIn1);
7147071617
pIn1->flags = MEM_Int;
71471
- pIn1->u.i = pc;
71618
+ pIn1->u.i = (int)(pOp-aOp);
7147271619
REGISTER_TRACE(pOp->p1, pIn1);
71473
- pc = pOp->p2 - 1;
71620
+
71621
+ /* Most jump operations do a goto to this spot in order to update
71622
+ ** the pOp pointer. */
71623
+jump_to_p2:
71624
+ pOp = &aOp[pOp->p2 - 1];
7147471625
break;
7147571626
}
7147671627
7147771628
/* Opcode: Return P1 * * * *
7147871629
**
@@ -71480,11 +71631,11 @@
7148071631
** the jump, register P1 becomes undefined.
7148171632
*/
7148271633
case OP_Return: { /* in1 */
7148371634
pIn1 = &aMem[pOp->p1];
7148471635
assert( pIn1->flags==MEM_Int );
71485
- pc = (int)pIn1->u.i;
71636
+ pOp = &aOp[pIn1->u.i];
7148671637
pIn1->flags = MEM_Undefined;
7148771638
break;
7148871639
}
7148971640
7149071641
/* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71655,11 @@
7150471655
assert( pOp->p3>=0 && pOp->p3<p->nOp );
7150571656
pOut = &aMem[pOp->p1];
7150671657
assert( !VdbeMemDynamic(pOut) );
7150771658
pOut->u.i = pOp->p3 - 1;
7150871659
pOut->flags = MEM_Int;
71509
- if( pOp->p2 ) pc = pOp->p2 - 1;
71660
+ if( pOp->p2 ) goto jump_to_p2;
7151071661
break;
7151171662
}
7151271663
7151371664
/* Opcode: EndCoroutine P1 * * * *
7151471665
**
@@ -71524,11 +71675,11 @@
7152471675
assert( pIn1->flags==MEM_Int );
7152571676
assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
7152671677
pCaller = &aOp[pIn1->u.i];
7152771678
assert( pCaller->opcode==OP_Yield );
7152871679
assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71529
- pc = pCaller->p2 - 1;
71680
+ pOp = &aOp[pCaller->p2 - 1];
7153071681
pIn1->flags = MEM_Undefined;
7153171682
break;
7153271683
}
7153371684
7153471685
/* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71699,13 @@
7154871699
int pcDest;
7154971700
pIn1 = &aMem[pOp->p1];
7155071701
assert( VdbeMemDynamic(pIn1)==0 );
7155171702
pIn1->flags = MEM_Int;
7155271703
pcDest = (int)pIn1->u.i;
71553
- pIn1->u.i = pc;
71704
+ pIn1->u.i = (int)(pOp - aOp);
7155471705
REGISTER_TRACE(pOp->p1, pIn1);
71555
- pc = pcDest;
71706
+ pOp = &aOp[pcDest];
7155671707
break;
7155771708
}
7155871709
7155971710
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
7156071711
** Synopsis: if r[P3]=null halt
@@ -71601,34 +71752,38 @@
7160171752
** is the same as executing Halt.
7160271753
*/
7160371754
case OP_Halt: {
7160471755
const char *zType;
7160571756
const char *zLogFmt;
71757
+ VdbeFrame *pFrame;
71758
+ int pcx;
7160671759
71760
+ pcx = (int)(pOp - aOp);
7160771761
if( pOp->p1==SQLITE_OK && p->pFrame ){
7160871762
/* Halt the sub-program. Return control to the parent frame. */
71609
- VdbeFrame *pFrame = p->pFrame;
71763
+ pFrame = p->pFrame;
7161071764
p->pFrame = pFrame->pParent;
7161171765
p->nFrame--;
7161271766
sqlite3VdbeSetChanges(db, p->nChange);
71613
- pc = sqlite3VdbeFrameRestore(pFrame);
71767
+ pcx = sqlite3VdbeFrameRestore(pFrame);
7161471768
lastRowid = db->lastRowid;
7161571769
if( pOp->p2==OE_Ignore ){
71616
- /* Instruction pc is the OP_Program that invoked the sub-program
71770
+ /* Instruction pcx is the OP_Program that invoked the sub-program
7161771771
** currently being halted. If the p2 instruction of this OP_Halt
7161871772
** instruction is set to OE_Ignore, then the sub-program is throwing
7161971773
** an IGNORE exception. In this case jump to the address specified
7162071774
** as the p2 of the calling OP_Program. */
71621
- pc = p->aOp[pc].p2-1;
71775
+ pcx = p->aOp[pcx].p2-1;
7162271776
}
7162371777
aOp = p->aOp;
7162471778
aMem = p->aMem;
71779
+ pOp = &aOp[pcx];
7162571780
break;
7162671781
}
7162771782
p->rc = pOp->p1;
7162871783
p->errorAction = (u8)pOp->p2;
71629
- p->pc = pc;
71784
+ p->pc = pcx;
7163071785
if( p->rc ){
7163171786
if( pOp->p5 ){
7163271787
static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
7163371788
"FOREIGN KEY" };
7163471789
assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71803,11 @@
7164871803
}else if( pOp->p4.z ){
7164971804
sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
7165071805
}else{
7165171806
sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
7165271807
}
71653
- sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
71808
+ sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
7165471809
}
7165571810
rc = sqlite3VdbeHalt(p);
7165671811
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
7165771812
if( rc==SQLITE_BUSY ){
7165871813
p->rc = rc = SQLITE_BUSY;
@@ -71659,19 +71814,21 @@
7165971814
}else{
7166071815
assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
7166171816
assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
7166271817
rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
7166371818
}
71819
+ pOp = &aOp[pcx];
7166471820
goto vdbe_return;
7166571821
}
7166671822
7166771823
/* Opcode: Integer P1 P2 * * *
7166871824
** Synopsis: r[P2]=P1
7166971825
**
7167071826
** The 32-bit integer value P1 is written into register P2.
7167171827
*/
71672
-case OP_Integer: { /* out2-prerelease */
71828
+case OP_Integer: { /* out2 */
71829
+ pOut = out2Prerelease(p, pOp);
7167371830
pOut->u.i = pOp->p1;
7167471831
break;
7167571832
}
7167671833
7167771834
/* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71835,12 @@
7167871835
** Synopsis: r[P2]=P4
7167971836
**
7168071837
** P4 is a pointer to a 64-bit integer value.
7168171838
** Write that value into register P2.
7168271839
*/
71683
-case OP_Int64: { /* out2-prerelease */
71840
+case OP_Int64: { /* out2 */
71841
+ pOut = out2Prerelease(p, pOp);
7168471842
assert( pOp->p4.pI64!=0 );
7168571843
pOut->u.i = *pOp->p4.pI64;
7168671844
break;
7168771845
}
7168871846
@@ -71691,11 +71849,12 @@
7169171849
** Synopsis: r[P2]=P4
7169271850
**
7169371851
** P4 is a pointer to a 64-bit floating point value.
7169471852
** Write that value into register P2.
7169571853
*/
71696
-case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
71854
+case OP_Real: { /* same as TK_FLOAT, out2 */
71855
+ pOut = out2Prerelease(p, pOp);
7169771856
pOut->flags = MEM_Real;
7169871857
assert( !sqlite3IsNaN(*pOp->p4.pReal) );
7169971858
pOut->u.r = *pOp->p4.pReal;
7170071859
break;
7170171860
}
@@ -71707,12 +71866,13 @@
7170771866
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
7170871867
** into a String opcode before it is executed for the first time. During
7170971868
** this transformation, the length of string P4 is computed and stored
7171071869
** as the P1 parameter.
7171171870
*/
71712
-case OP_String8: { /* same as TK_STRING, out2-prerelease */
71871
+case OP_String8: { /* same as TK_STRING, out2 */
7171371872
assert( pOp->p4.z!=0 );
71873
+ pOut = out2Prerelease(p, pOp);
7171471874
pOp->opcode = OP_String;
7171571875
pOp->p1 = sqlite3Strlen30(pOp->p4.z);
7171671876
7171771877
#ifndef SQLITE_OMIT_UTF16
7171871878
if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71905,13 @@
7174571905
** If P5!=0 and the content of register P3 is greater than zero, then
7174671906
** the datatype of the register P2 is converted to BLOB. The content is
7174771907
** the same sequence of bytes, it is merely interpreted as a BLOB instead
7174871908
** of a string, as if it had been CAST.
7174971909
*/
71750
-case OP_String: { /* out2-prerelease */
71910
+case OP_String: { /* out2 */
7175171911
assert( pOp->p4.z!=0 );
71912
+ pOut = out2Prerelease(p, pOp);
7175271913
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
7175371914
pOut->z = pOp->p4.z;
7175471915
pOut->n = pOp->p1;
7175571916
pOut->enc = encoding;
7175671917
UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71935,14 @@
7177471935
**
7177571936
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
7177671937
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
7177771938
** OP_Ne or OP_Eq.
7177871939
*/
71779
-case OP_Null: { /* out2-prerelease */
71940
+case OP_Null: { /* out2 */
7178071941
int cnt;
7178171942
u16 nullFlag;
71943
+ pOut = out2Prerelease(p, pOp);
7178271944
cnt = pOp->p3-pOp->p2;
7178371945
assert( pOp->p3<=(p->nMem-p->nCursor) );
7178471946
pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
7178571947
while( cnt>0 ){
7178671948
pOut++;
@@ -71811,12 +71973,13 @@
7181171973
** Synopsis: r[P2]=P4 (len=P1)
7181271974
**
7181371975
** P4 points to a blob of data P1 bytes long. Store this
7181471976
** blob in register P2.
7181571977
*/
71816
-case OP_Blob: { /* out2-prerelease */
71978
+case OP_Blob: { /* out2 */
7181771979
assert( pOp->p1 <= SQLITE_MAX_LENGTH );
71980
+ pOut = out2Prerelease(p, pOp);
7181871981
sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
7181971982
pOut->enc = encoding;
7182071983
UPDATE_MAX_BLOBSIZE(pOut);
7182171984
break;
7182271985
}
@@ -71827,19 +71990,20 @@
7182771990
** Transfer the values of bound parameter P1 into register P2
7182871991
**
7182971992
** If the parameter is named, then its name appears in P4.
7183071993
** The P4 value is used by sqlite3_bind_parameter_name().
7183171994
*/
71832
-case OP_Variable: { /* out2-prerelease */
71995
+case OP_Variable: { /* out2 */
7183371996
Mem *pVar; /* Value being transferred */
7183471997
7183571998
assert( pOp->p1>0 && pOp->p1<=p->nVar );
7183671999
assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
7183772000
pVar = &p->aVar[pOp->p1 - 1];
7183872001
if( sqlite3VdbeMemTooBig(pVar) ){
7183972002
goto too_big;
7184072003
}
72004
+ pOut = out2Prerelease(p, pOp);
7184172005
sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
7184272006
UPDATE_MAX_BLOBSIZE(pOut);
7184372007
break;
7184472008
}
7184572009
@@ -71870,14 +72034,15 @@
7187072034
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
7187172035
assert( memIsValid(pIn1) );
7187272036
memAboutToChange(p, pOut);
7187372037
sqlite3VdbeMemMove(pOut, pIn1);
7187472038
#ifdef SQLITE_DEBUG
71875
- if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
71876
- pOut->pScopyFrom += p1 - pOp->p2;
72039
+ if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
72040
+ pOut->pScopyFrom += pOp->p2 - p1;
7187772041
}
7187872042
#endif
72043
+ Deephemeralize(pOut);
7187972044
REGISTER_TRACE(p2++, pOut);
7188072045
pIn1++;
7188172046
pOut++;
7188272047
}while( --n );
7188372048
break;
@@ -72012,11 +72177,11 @@
7201272177
}
7201372178
if( db->mallocFailed ) goto no_mem;
7201472179
7201572180
/* Return SQLITE_ROW
7201672181
*/
72017
- p->pc = pc + 1;
72182
+ p->pc = (int)(pOp - aOp) + 1;
7201872183
rc = SQLITE_ROW;
7201972184
goto vdbe_return;
7202072185
}
7202172186
7202272187
/* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72423,11 @@
7225872423
REGISTER_TRACE(pOp->p2+i, pArg);
7225972424
}
7226072425
7226172426
assert( pOp->p4type==P4_FUNCDEF );
7226272427
ctx.pFunc = pOp->p4.pFunc;
72263
- ctx.iOp = pc;
72428
+ ctx.iOp = (int)(pOp - aOp);
7226472429
ctx.pVdbe = p;
7226572430
MemSetTypeFlag(ctx.pOut, MEM_Null);
7226672431
ctx.fErrorOrAux = 0;
7226772432
db->lastRowid = lastRowid;
7226872433
(*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72437,11 @@
7227272437
if( ctx.fErrorOrAux ){
7227372438
if( ctx.isError ){
7227472439
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
7227572440
rc = ctx.isError;
7227672441
}
72277
- sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
72442
+ sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1);
7227872443
}
7227972444
7228072445
/* Copy the result of the function into register P3 */
7228172446
sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
7228272447
if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72566,11 @@
7240172566
if( (pIn1->flags & MEM_Int)==0 ){
7240272567
if( pOp->p2==0 ){
7240372568
rc = SQLITE_MISMATCH;
7240472569
goto abort_due_to_error;
7240572570
}else{
72406
- pc = pOp->p2 - 1;
72407
- break;
72571
+ goto jump_to_p2;
7240872572
}
7240972573
}
7241072574
}
7241172575
MemSetTypeFlag(pIn1, MEM_Int);
7241272576
break;
@@ -72588,11 +72752,11 @@
7258872752
MemSetTypeFlag(pOut, MEM_Null);
7258972753
REGISTER_TRACE(pOp->p2, pOut);
7259072754
}else{
7259172755
VdbeBranchTaken(2,3);
7259272756
if( pOp->p5 & SQLITE_JUMPIFNULL ){
72593
- pc = pOp->p2-1;
72757
+ goto jump_to_p2;
7259472758
}
7259572759
}
7259672760
break;
7259772761
}
7259872762
}else{
@@ -72639,10 +72803,16 @@
7263972803
case OP_Lt: res = res<0; break;
7264072804
case OP_Le: res = res<=0; break;
7264172805
case OP_Gt: res = res>0; break;
7264272806
default: res = res>=0; break;
7264372807
}
72808
+
72809
+ /* Undo any changes made by applyAffinity() to the input registers. */
72810
+ assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72811
+ pIn1->flags = flags1;
72812
+ assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72813
+ pIn3->flags = flags3;
7264472814
7264572815
if( pOp->p5 & SQLITE_STOREP2 ){
7264672816
pOut = &aMem[pOp->p2];
7264772817
memAboutToChange(p, pOut);
7264872818
MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72819,13 @@
7264972819
pOut->u.i = res;
7265072820
REGISTER_TRACE(pOp->p2, pOut);
7265172821
}else{
7265272822
VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
7265372823
if( res ){
72654
- pc = pOp->p2-1;
72824
+ goto jump_to_p2;
7265572825
}
7265672826
}
72657
- /* Undo any changes made by applyAffinity() to the input registers. */
72658
- assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72659
- pIn1->flags = flags1;
72660
- assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72661
- pIn3->flags = flags3;
7266272827
break;
7266372828
}
7266472829
7266572830
/* Opcode: Permutation * * * P4 *
7266672831
**
@@ -72751,15 +72916,15 @@
7275172916
** in the most recent OP_Compare instruction the P1 vector was less than
7275272917
** equal to, or greater than the P2 vector, respectively.
7275372918
*/
7275472919
case OP_Jump: { /* jump */
7275572920
if( iCompare<0 ){
72756
- pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
72921
+ VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1];
7275772922
}else if( iCompare==0 ){
72758
- pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
72923
+ VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1];
7275972924
}else{
72760
- pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
72925
+ VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1];
7276172926
}
7276272927
break;
7276372928
}
7276472929
7276572930
/* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73030,11 @@
7286573030
*/
7286673031
case OP_Once: { /* jump */
7286773032
assert( pOp->p1<p->nOnceFlag );
7286873033
VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
7286973034
if( p->aOnceFlag[pOp->p1] ){
72870
- pc = pOp->p2-1;
73035
+ goto jump_to_p2;
7287173036
}else{
7287273037
p->aOnceFlag[pOp->p1] = 1;
7287373038
}
7287473039
break;
7287573040
}
@@ -72900,11 +73065,11 @@
7290073065
#endif
7290173066
if( pOp->opcode==OP_IfNot ) c = !c;
7290273067
}
7290373068
VdbeBranchTaken(c!=0, 2);
7290473069
if( c ){
72905
- pc = pOp->p2-1;
73070
+ goto jump_to_p2;
7290673071
}
7290773072
break;
7290873073
}
7290973074
7291073075
/* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73079,11 @@
7291473079
*/
7291573080
case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
7291673081
pIn1 = &aMem[pOp->p1];
7291773082
VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
7291873083
if( (pIn1->flags & MEM_Null)!=0 ){
72919
- pc = pOp->p2 - 1;
73084
+ goto jump_to_p2;
7292073085
}
7292173086
break;
7292273087
}
7292373088
7292473089
/* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73093,11 @@
7292873093
*/
7292973094
case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
7293073095
pIn1 = &aMem[pOp->p1];
7293173096
VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
7293273097
if( (pIn1->flags & MEM_Null)==0 ){
72933
- pc = pOp->p2 - 1;
73098
+ goto jump_to_p2;
7293473099
}
7293573100
break;
7293673101
}
7293773102
7293873103
/* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73307,11 @@
7314273307
rc = SQLITE_CORRUPT_BKPT;
7314373308
goto op_column_error;
7314473309
}
7314573310
}
7314673311
73147
- /* If after trying to extra new entries from the header, nHdrParsed is
73312
+ /* If after trying to extract new entries from the header, nHdrParsed is
7314873313
** still not up to p2, that means that the record has fewer than p2
7314973314
** columns. So the result will be either the default value or a NULL.
7315073315
*/
7315173316
if( pC->nHdrParsed<=p2 ){
7315273317
if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73431,11 @@
7326673431
u8 *zNewRecord; /* A buffer to hold the data for the new record */
7326773432
Mem *pRec; /* The new record */
7326873433
u64 nData; /* Number of bytes of data space */
7326973434
int nHdr; /* Number of bytes of header space */
7327073435
i64 nByte; /* Data space required for this record */
73271
- int nZero; /* Number of zero bytes at the end of the record */
73436
+ i64 nZero; /* Number of zero bytes at the end of the record */
7327273437
int nVarint; /* Number of bytes in a varint */
7327373438
u32 serial_type; /* Type field */
7327473439
Mem *pData0; /* First field to be combined into the record */
7327573440
Mem *pLast; /* Last field of the record */
7327673441
int nField; /* Number of fields in the record */
@@ -73358,11 +73523,11 @@
7335873523
nVarint = sqlite3VarintLen(nHdr);
7335973524
nHdr += nVarint;
7336073525
if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
7336173526
}
7336273527
nByte = nHdr+nData;
73363
- if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73528
+ if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
7336473529
goto too_big;
7336573530
}
7336673531
7336773532
/* Make sure the output register has a buffer large enough to store
7336873533
** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73574,19 @@
7340973574
**
7341073575
** Store the number of entries (an integer value) in the table or index
7341173576
** opened by cursor P1 in register P2
7341273577
*/
7341373578
#ifndef SQLITE_OMIT_BTREECOUNT
73414
-case OP_Count: { /* out2-prerelease */
73579
+case OP_Count: { /* out2 */
7341573580
i64 nEntry;
7341673581
BtCursor *pCrsr;
7341773582
7341873583
pCrsr = p->apCsr[pOp->p1]->pCursor;
7341973584
assert( pCrsr );
7342073585
nEntry = 0; /* Not needed. Only used to silence a warning. */
7342173586
rc = sqlite3BtreeCount(pCrsr, &nEntry);
73587
+ pOut = out2Prerelease(p, pOp);
7342273588
pOut->u.i = nEntry;
7342373589
break;
7342473590
}
7342573591
#endif
7342673592
@@ -73530,11 +73696,11 @@
7353073696
if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
7353173697
goto vdbe_return;
7353273698
}
7353373699
db->autoCommit = 1;
7353473700
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73535
- p->pc = pc;
73701
+ p->pc = (int)(pOp - aOp);
7353673702
db->autoCommit = 0;
7353773703
p->rc = rc = SQLITE_BUSY;
7353873704
goto vdbe_return;
7353973705
}
7354073706
db->isTransactionSavepoint = 0;
@@ -73589,11 +73755,11 @@
7358973755
}else{
7359073756
db->nDeferredCons = pSavepoint->nDeferredCons;
7359173757
db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
7359273758
}
7359373759
73594
- if( !isTransaction ){
73760
+ if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){
7359573761
rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
7359673762
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7359773763
}
7359873764
}
7359973765
}
@@ -73649,11 +73815,11 @@
7364973815
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
7365073816
goto vdbe_return;
7365173817
}else{
7365273818
db->autoCommit = (u8)desiredAutoCommit;
7365373819
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73654
- p->pc = pc;
73820
+ p->pc = (int)(pOp - aOp);
7365573821
db->autoCommit = (u8)(1-desiredAutoCommit);
7365673822
p->rc = rc = SQLITE_BUSY;
7365773823
goto vdbe_return;
7365873824
}
7365973825
}
@@ -73726,11 +73892,11 @@
7372673892
pBt = db->aDb[pOp->p1].pBt;
7372773893
7372873894
if( pBt ){
7372973895
rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
7373073896
if( rc==SQLITE_BUSY ){
73731
- p->pc = pc;
73897
+ p->pc = (int)(pOp - aOp);
7373273898
p->rc = rc = SQLITE_BUSY;
7373373899
goto vdbe_return;
7373473900
}
7373573901
if( rc!=SQLITE_OK ){
7373673902
goto abort_due_to_error;
@@ -73805,11 +73971,11 @@
7380573971
**
7380673972
** There must be a read-lock on the database (either a transaction
7380773973
** must be started or there must be an open cursor) before
7380873974
** executing this instruction.
7380973975
*/
73810
-case OP_ReadCookie: { /* out2-prerelease */
73976
+case OP_ReadCookie: { /* out2 */
7381173977
int iMeta;
7381273978
int iDb;
7381373979
int iCookie;
7381473980
7381573981
assert( p->bIsReader );
@@ -73819,10 +73985,11 @@
7381973985
assert( iDb>=0 && iDb<db->nDb );
7382073986
assert( db->aDb[iDb].pBt!=0 );
7382173987
assert( DbMaskTest(p->btreeMask, iDb) );
7382273988
7382373989
sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
73990
+ pOut = out2Prerelease(p, pOp);
7382473991
pOut->u.i = iMeta;
7382573992
break;
7382673993
}
7382773994
7382873995
/* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74307,11 @@
7414074307
VdbeCursor *pC;
7414174308
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7414274309
pC = p->apCsr[pOp->p1];
7414374310
assert( pC->pSorter );
7414474311
if( (pC->seqCount++)==0 ){
74145
- pc = pOp->p2 - 1;
74312
+ goto jump_to_p2;
7414674313
}
7414774314
break;
7414874315
}
7414974316
7415074317
/* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74484,11 @@
7431774484
** loss of information, then special processing is required... */
7431874485
if( (pIn3->flags & MEM_Int)==0 ){
7431974486
if( (pIn3->flags & MEM_Real)==0 ){
7432074487
/* If the P3 value cannot be converted into any kind of a number,
7432174488
** then the seek is not possible, so jump to P2 */
74322
- pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74489
+ VdbeBranchTaken(1,2); goto jump_to_p2;
7432374490
break;
7432474491
}
7432574492
7432674493
/* If the approximation iKey is larger than the actual real search
7432774494
** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74575,11 @@
7440874575
}
7440974576
}
7441074577
assert( pOp->p2>0 );
7441174578
VdbeBranchTaken(res!=0,2);
7441274579
if( res ){
74413
- pc = pOp->p2 - 1;
74580
+ goto jump_to_p2;
7441474581
}
7441574582
break;
7441674583
}
7441774584
7441874585
/* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74669,11 @@
7450274669
*/
7450374670
case OP_NoConflict: /* jump, in3 */
7450474671
case OP_NotFound: /* jump, in3 */
7450574672
case OP_Found: { /* jump, in3 */
7450674673
int alreadyExists;
74674
+ int takeJump;
7450774675
int ii;
7450874676
VdbeCursor *pC;
7450974677
int res;
7451074678
char *pFree;
7451174679
UnpackedRecord *pIdxKey;
@@ -74524,11 +74692,11 @@
7452474692
pC->seekOp = pOp->opcode;
7452574693
#endif
7452674694
pIn3 = &aMem[pOp->p3];
7452774695
assert( pC->pCursor!=0 );
7452874696
assert( pC->isTable==0 );
74529
- pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
74697
+ pFree = 0;
7453074698
if( pOp->p4.i>0 ){
7453174699
r.pKeyInfo = pC->pKeyInfo;
7453274700
r.nField = (u16)pOp->p4.i;
7453374701
r.aMem = pIn3;
7453474702
for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74715,24 @@
7454774715
assert( pIn3->flags & MEM_Blob );
7454874716
ExpandBlob(pIn3);
7454974717
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
7455074718
}
7455174719
pIdxKey->default_rc = 0;
74720
+ takeJump = 0;
7455274721
if( pOp->opcode==OP_NoConflict ){
7455374722
/* For the OP_NoConflict opcode, take the jump if any of the
7455474723
** input fields are NULL, since any key with a NULL will not
7455574724
** conflict */
7455674725
for(ii=0; ii<pIdxKey->nField; ii++){
7455774726
if( pIdxKey->aMem[ii].flags & MEM_Null ){
74558
- pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74727
+ takeJump = 1;
7455974728
break;
7456074729
}
7456174730
}
7456274731
}
7456374732
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74564
- if( pOp->p4.i==0 ){
74565
- sqlite3DbFree(db, pFree);
74566
- }
74733
+ sqlite3DbFree(db, pFree);
7456774734
if( rc!=SQLITE_OK ){
7456874735
break;
7456974736
}
7457074737
pC->seekResult = res;
7457174738
alreadyExists = (res==0);
@@ -74572,14 +74739,14 @@
7457274739
pC->nullRow = 1-alreadyExists;
7457374740
pC->deferredMoveto = 0;
7457474741
pC->cacheStatus = CACHE_STALE;
7457574742
if( pOp->opcode==OP_Found ){
7457674743
VdbeBranchTaken(alreadyExists!=0,2);
74577
- if( alreadyExists ) pc = pOp->p2 - 1;
74744
+ if( alreadyExists ) goto jump_to_p2;
7457874745
}else{
74579
- VdbeBranchTaken(alreadyExists==0,2);
74580
- if( !alreadyExists ) pc = pOp->p2 - 1;
74746
+ VdbeBranchTaken(takeJump||alreadyExists==0,2);
74747
+ if( takeJump || !alreadyExists ) goto jump_to_p2;
7458174748
}
7458274749
break;
7458374750
}
7458474751
7458574752
/* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74791,12 @@
7462474791
pC->movetoTarget = iKey; /* Used by OP_Delete */
7462574792
pC->nullRow = 0;
7462674793
pC->cacheStatus = CACHE_STALE;
7462774794
pC->deferredMoveto = 0;
7462874795
VdbeBranchTaken(res!=0,2);
74629
- if( res!=0 ){
74630
- pc = pOp->p2 - 1;
74631
- }
7463274796
pC->seekResult = res;
74797
+ if( res!=0 ) goto jump_to_p2;
7463374798
break;
7463474799
}
7463574800
7463674801
/* Opcode: Sequence P1 P2 * * *
7463774802
** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74804,14 @@
7463974804
** Find the next available sequence number for cursor P1.
7464074805
** Write the sequence number into register P2.
7464174806
** The sequence number on the cursor is incremented after this
7464274807
** instruction.
7464374808
*/
74644
-case OP_Sequence: { /* out2-prerelease */
74809
+case OP_Sequence: { /* out2 */
7464574810
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7464674811
assert( p->apCsr[pOp->p1]!=0 );
74812
+ pOut = out2Prerelease(p, pOp);
7464774813
pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
7464874814
break;
7464974815
}
7465074816
7465174817
@@ -74662,20 +74828,21 @@
7466274828
** allowed to be less than this value. When this value reaches its maximum,
7466374829
** an SQLITE_FULL error is generated. The P3 register is updated with the '
7466474830
** generated record number. This P3 mechanism is used to help implement the
7466574831
** AUTOINCREMENT feature.
7466674832
*/
74667
-case OP_NewRowid: { /* out2-prerelease */
74833
+case OP_NewRowid: { /* out2 */
7466874834
i64 v; /* The new rowid */
7466974835
VdbeCursor *pC; /* Cursor of table to get the new rowid */
7467074836
int res; /* Result of an sqlite3BtreeLast() */
7467174837
int cnt; /* Counter to limit the number of searches */
7467274838
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
7467374839
VdbeFrame *pFrame; /* Root frame of VDBE */
7467474840
7467574841
v = 0;
7467674842
res = 0;
74843
+ pOut = out2Prerelease(p, pOp);
7467774844
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7467874845
pC = p->apCsr[pOp->p1];
7467974846
assert( pC!=0 );
7468074847
if( NEVER(pC->pCursor==0) ){
7468174848
/* The zero initialization above is all that is needed */
@@ -74985,13 +75152,11 @@
7498575152
pIn3 = &aMem[pOp->p3];
7498675153
nKeyCol = pOp->p4.i;
7498775154
res = 0;
7498875155
rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
7498975156
VdbeBranchTaken(res!=0,2);
74990
- if( res ){
74991
- pc = pOp->p2-1;
74992
- }
75157
+ if( res ) goto jump_to_p2;
7499375158
break;
7499475159
};
7499575160
7499675161
/* Opcode: SorterData P1 P2 P3 * *
7499775162
** Synopsis: r[P2]=data
@@ -75116,16 +75281,17 @@
7511675281
**
7511775282
** P1 can be either an ordinary table or a virtual table. There used to
7511875283
** be a separate OP_VRowid opcode for use with virtual tables, but this
7511975284
** one opcode now works for both table types.
7512075285
*/
75121
-case OP_Rowid: { /* out2-prerelease */
75286
+case OP_Rowid: { /* out2 */
7512275287
VdbeCursor *pC;
7512375288
i64 v;
7512475289
sqlite3_vtab *pVtab;
7512575290
const sqlite3_module *pModule;
7512675291
75292
+ pOut = out2Prerelease(p, pOp);
7512775293
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7512875294
pC = p->apCsr[pOp->p1];
7512975295
assert( pC!=0 );
7513075296
assert( pC->pseudoTableReg==0 || pC->nullRow );
7513175297
if( pC->nullRow ){
@@ -75174,11 +75340,11 @@
7517475340
sqlite3BtreeClearCursor(pC->pCursor);
7517575341
}
7517675342
break;
7517775343
}
7517875344
75179
-/* Opcode: Last P1 P2 * * *
75345
+/* Opcode: Last P1 P2 P3 * *
7518075346
**
7518175347
** The next use of the Rowid or Column or Prev instruction for P1
7518275348
** will refer to the last entry in the database table or index.
7518375349
** If the table or index is empty and P2>0, then jump immediately to P2.
7518475350
** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75367,17 @@
7520175367
assert( pCrsr!=0 );
7520275368
rc = sqlite3BtreeLast(pCrsr, &res);
7520375369
pC->nullRow = (u8)res;
7520475370
pC->deferredMoveto = 0;
7520575371
pC->cacheStatus = CACHE_STALE;
75372
+ pC->seekResult = pOp->p3;
7520675373
#ifdef SQLITE_DEBUG
7520775374
pC->seekOp = OP_Last;
7520875375
#endif
7520975376
if( pOp->p2>0 ){
7521075377
VdbeBranchTaken(res!=0,2);
75211
- if( res ) pc = pOp->p2 - 1;
75378
+ if( res ) goto jump_to_p2;
7521275379
}
7521375380
break;
7521475381
}
7521575382
7521675383
@@ -75270,13 +75437,11 @@
7527075437
pC->cacheStatus = CACHE_STALE;
7527175438
}
7527275439
pC->nullRow = (u8)res;
7527375440
assert( pOp->p2>0 && pOp->p2<p->nOp );
7527475441
VdbeBranchTaken(res!=0,2);
75275
- if( res ){
75276
- pc = pOp->p2 - 1;
75277
- }
75442
+ if( res ) goto jump_to_p2;
7527875443
break;
7527975444
}
7528075445
7528175446
/* Opcode: Next P1 P2 P3 P4 P5
7528275447
**
@@ -75383,15 +75548,15 @@
7538375548
next_tail:
7538475549
pC->cacheStatus = CACHE_STALE;
7538575550
VdbeBranchTaken(res==0,2);
7538675551
if( res==0 ){
7538775552
pC->nullRow = 0;
75388
- pc = pOp->p2 - 1;
7538975553
p->aCounter[pOp->p5]++;
7539075554
#ifdef SQLITE_TEST
7539175555
sqlite3_search_count++;
7539275556
#endif
75557
+ goto jump_to_p2_and_check_for_interrupt;
7539375558
}else{
7539475559
pC->nullRow = 1;
7539575560
}
7539675561
goto check_for_interrupt;
7539775562
}
@@ -75495,15 +75660,16 @@
7549575660
** the end of the index key pointed to by cursor P1. This integer should be
7549675661
** the rowid of the table entry to which this index entry points.
7549775662
**
7549875663
** See also: Rowid, MakeRecord.
7549975664
*/
75500
-case OP_IdxRowid: { /* out2-prerelease */
75665
+case OP_IdxRowid: { /* out2 */
7550175666
BtCursor *pCrsr;
7550275667
VdbeCursor *pC;
7550375668
i64 rowid;
7550475669
75670
+ pOut = out2Prerelease(p, pOp);
7550575671
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7550675672
pC = p->apCsr[pOp->p1];
7550775673
assert( pC!=0 );
7550875674
pCrsr = pC->pCursor;
7550975675
assert( pCrsr!=0 );
@@ -75612,13 +75778,11 @@
7561275778
}else{
7561375779
assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
7561475780
res++;
7561575781
}
7561675782
VdbeBranchTaken(res>0,2);
75617
- if( res>0 ){
75618
- pc = pOp->p2 - 1 ;
75619
- }
75783
+ if( res>0 ) goto jump_to_p2;
7562075784
break;
7562175785
}
7562275786
7562375787
/* Opcode: Destroy P1 P2 P3 * *
7562475788
**
@@ -75638,15 +75802,16 @@
7563875802
** the last one in the database) then a zero is stored in register P2.
7563975803
** If AUTOVACUUM is disabled then a zero is stored in register P2.
7564075804
**
7564175805
** See also: Clear
7564275806
*/
75643
-case OP_Destroy: { /* out2-prerelease */
75807
+case OP_Destroy: { /* out2 */
7564475808
int iMoved;
7564575809
int iDb;
7564675810
7564775811
assert( p->readOnly==0 );
75812
+ pOut = out2Prerelease(p, pOp);
7564875813
pOut->flags = MEM_Null;
7564975814
if( db->nVdbeRead > db->nVDestroy+1 ){
7565075815
rc = SQLITE_LOCKED;
7565175816
p->errorAction = OE_Abort;
7565275817
}else{
@@ -75751,16 +75916,17 @@
7575175916
** P1>1. Write the root page number of the new table into
7575275917
** register P2.
7575375918
**
7575475919
** See documentation on OP_CreateTable for additional information.
7575575920
*/
75756
-case OP_CreateIndex: /* out2-prerelease */
75757
-case OP_CreateTable: { /* out2-prerelease */
75921
+case OP_CreateIndex: /* out2 */
75922
+case OP_CreateTable: { /* out2 */
7575875923
int pgno;
7575975924
int flags;
7576075925
Db *pDb;
7576175926
75927
+ pOut = out2Prerelease(p, pOp);
7576275928
pgno = 0;
7576375929
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7576475930
assert( DbMaskTest(p->btreeMask, pOp->p1) );
7576575931
assert( p->readOnly==0 );
7576675932
pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76148,16 @@
7598276148
if( (pIn1->flags & MEM_RowSet)==0
7598376149
|| sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
7598476150
){
7598576151
/* The boolean index is empty */
7598676152
sqlite3VdbeMemSetNull(pIn1);
75987
- pc = pOp->p2 - 1;
7598876153
VdbeBranchTaken(1,2);
76154
+ goto jump_to_p2_and_check_for_interrupt;
7598976155
}else{
7599076156
/* A value was pulled from the index */
75991
- sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7599276157
VdbeBranchTaken(0,2);
76158
+ sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7599376159
}
7599476160
goto check_for_interrupt;
7599576161
}
7599676162
7599776163
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76204,11 @@
7603876204
assert( pOp->p4type==P4_INT32 );
7603976205
assert( iSet==-1 || iSet>=0 );
7604076206
if( iSet ){
7604176207
exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
7604276208
VdbeBranchTaken(exists!=0,2);
76043
- if( exists ){
76044
- pc = pOp->p2 - 1;
76045
- break;
76046
- }
76209
+ if( exists ) goto jump_to_p2;
7604776210
}
7604876211
if( iSet>=0 ){
7604976212
sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
7605076213
}
7605176214
break;
@@ -76130,11 +76293,11 @@
7613076293
pRt->u.pFrame = pFrame;
7613176294
7613276295
pFrame->v = p;
7613376296
pFrame->nChildMem = nMem;
7613476297
pFrame->nChildCsr = pProgram->nCsr;
76135
- pFrame->pc = pc;
76298
+ pFrame->pc = (int)(pOp - aOp);
7613676299
pFrame->aMem = p->aMem;
7613776300
pFrame->nMem = p->nMem;
7613876301
pFrame->apCsr = p->apCsr;
7613976302
pFrame->nCursor = p->nCursor;
7614076303
pFrame->aOp = p->aOp;
@@ -76153,11 +76316,11 @@
7615376316
}
7615476317
}else{
7615576318
pFrame = pRt->u.pFrame;
7615676319
assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
7615776320
assert( pProgram->nCsr==pFrame->nChildCsr );
76158
- assert( pc==pFrame->pc );
76321
+ assert( (int)(pOp - aOp)==pFrame->pc );
7615976322
}
7616076323
7616176324
p->nFrame++;
7616276325
pFrame->pParent = p->pFrame;
7616376326
pFrame->lastRowid = lastRowid;
@@ -76174,11 +76337,11 @@
7617476337
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
7617576338
p->nOnceFlag = pProgram->nOnce;
7617676339
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
7617776340
p->anExec = 0;
7617876341
#endif
76179
- pc = -1;
76342
+ pOp = &aOp[-1];
7618076343
memset(p->aOnceFlag, 0, p->nOnceFlag);
7618176344
7618276345
break;
7618376346
}
7618476347
@@ -76192,13 +76355,14 @@
7619276355
**
7619376356
** The address of the cell in the parent frame is determined by adding
7619476357
** the value of the P1 argument to the value of the P1 argument to the
7619576358
** calling OP_Program instruction.
7619676359
*/
76197
-case OP_Param: { /* out2-prerelease */
76360
+case OP_Param: { /* out2 */
7619876361
VdbeFrame *pFrame;
7619976362
Mem *pIn;
76363
+ pOut = out2Prerelease(p, pOp);
7620076364
pFrame = p->pFrame;
7620176365
pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
7620276366
sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
7620376367
break;
7620476368
}
@@ -76238,14 +76402,14 @@
7623876402
** (immediate foreign key constraint violations).
7623976403
*/
7624076404
case OP_FkIfZero: { /* jump */
7624176405
if( pOp->p1 ){
7624276406
VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76243
- if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76407
+ if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
7624476408
}else{
7624576409
VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76246
- if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76410
+ if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
7624776411
}
7624876412
break;
7624976413
}
7625076414
#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
7625176415
@@ -76292,13 +76456,11 @@
7629276456
*/
7629376457
case OP_IfPos: { /* jump, in1 */
7629476458
pIn1 = &aMem[pOp->p1];
7629576459
assert( pIn1->flags&MEM_Int );
7629676460
VdbeBranchTaken( pIn1->u.i>0, 2);
76297
- if( pIn1->u.i>0 ){
76298
- pc = pOp->p2 - 1;
76299
- }
76461
+ if( pIn1->u.i>0 ) goto jump_to_p2;
7630076462
break;
7630176463
}
7630276464
7630376465
/* Opcode: IfNeg P1 P2 P3 * *
7630476466
** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76471,11 @@
7630976471
case OP_IfNeg: { /* jump, in1 */
7631076472
pIn1 = &aMem[pOp->p1];
7631176473
assert( pIn1->flags&MEM_Int );
7631276474
pIn1->u.i += pOp->p3;
7631376475
VdbeBranchTaken(pIn1->u.i<0, 2);
76314
- if( pIn1->u.i<0 ){
76315
- pc = pOp->p2 - 1;
76316
- }
76476
+ if( pIn1->u.i<0 ) goto jump_to_p2;
7631776477
break;
7631876478
}
7631976479
7632076480
/* Opcode: IfNotZero P1 P2 P3 * *
7632176481
** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76488,11 @@
7632876488
pIn1 = &aMem[pOp->p1];
7632976489
assert( pIn1->flags&MEM_Int );
7633076490
VdbeBranchTaken(pIn1->u.i<0, 2);
7633176491
if( pIn1->u.i ){
7633276492
pIn1->u.i += pOp->p3;
76333
- pc = pOp->p2 - 1;
76493
+ goto jump_to_p2;
7633476494
}
7633576495
break;
7633676496
}
7633776497
7633876498
/* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76504,11 @@
7634476504
case OP_DecrJumpZero: { /* jump, in1 */
7634576505
pIn1 = &aMem[pOp->p1];
7634676506
assert( pIn1->flags&MEM_Int );
7634776507
pIn1->u.i--;
7634876508
VdbeBranchTaken(pIn1->u.i==0, 2);
76349
- if( pIn1->u.i==0 ){
76350
- pc = pOp->p2 - 1;
76351
- }
76509
+ if( pIn1->u.i==0 ) goto jump_to_p2;
7635276510
break;
7635376511
}
7635476512
7635576513
7635676514
/* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76520,11 @@
7636276520
*/
7636376521
case OP_JumpZeroIncr: { /* jump, in1 */
7636476522
pIn1 = &aMem[pOp->p1];
7636576523
assert( pIn1->flags&MEM_Int );
7636676524
VdbeBranchTaken(pIn1->u.i==0, 2);
76367
- if( (pIn1->u.i++)==0 ){
76368
- pc = pOp->p2 - 1;
76369
- }
76525
+ if( (pIn1->u.i++)==0 ) goto jump_to_p2;
7637076526
break;
7637176527
}
7637276528
7637376529
/* Opcode: AggStep * P2 P3 P4 P5
7637476530
** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76562,11 @@
7640676562
pMem->n++;
7640776563
sqlite3VdbeMemInit(&t, db, MEM_Null);
7640876564
ctx.pOut = &t;
7640976565
ctx.isError = 0;
7641076566
ctx.pVdbe = p;
76411
- ctx.iOp = pc;
76567
+ ctx.iOp = (int)(pOp - aOp);
7641276568
ctx.skipFlag = 0;
7641376569
(ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
7641476570
if( ctx.isError ){
7641576571
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
7641676572
rc = ctx.isError;
@@ -76501,19 +76657,20 @@
7650176657
**
7650276658
** If changing into or out of WAL mode the procedure is more complicated.
7650376659
**
7650476660
** Write a string containing the final journal-mode to register P2.
7650576661
*/
76506
-case OP_JournalMode: { /* out2-prerelease */
76662
+case OP_JournalMode: { /* out2 */
7650776663
Btree *pBt; /* Btree to change journal mode of */
7650876664
Pager *pPager; /* Pager associated with pBt */
7650976665
int eNew; /* New journal mode */
7651076666
int eOld; /* The old journal mode */
7651176667
#ifndef SQLITE_OMIT_WAL
7651276668
const char *zFilename; /* Name of database file for pPager */
7651376669
#endif
7651476670
76671
+ pOut = out2Prerelease(p, pOp);
7651576672
eNew = pOp->p3;
7651676673
assert( eNew==PAGER_JOURNALMODE_DELETE
7651776674
|| eNew==PAGER_JOURNALMODE_TRUNCATE
7651876675
|| eNew==PAGER_JOURNALMODE_PERSIST
7651976676
|| eNew==PAGER_JOURNALMODE_OFF
@@ -76626,12 +76783,12 @@
7662676783
assert( p->readOnly==0 );
7662776784
pBt = db->aDb[pOp->p1].pBt;
7662876785
rc = sqlite3BtreeIncrVacuum(pBt);
7662976786
VdbeBranchTaken(rc==SQLITE_DONE,2);
7663076787
if( rc==SQLITE_DONE ){
76631
- pc = pOp->p2 - 1;
7663276788
rc = SQLITE_OK;
76789
+ goto jump_to_p2;
7663376790
}
7663476791
break;
7663576792
}
7663676793
#endif
7663776794
@@ -76780,12 +76937,13 @@
7678076937
pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
7678176938
if( pCur ){
7678276939
pCur->pVtabCursor = pVtabCursor;
7678376940
pVtab->nRef++;
7678476941
}else{
76785
- db->mallocFailed = 1;
76942
+ assert( db->mallocFailed );
7678676943
pModule->xClose(pVtabCursor);
76944
+ goto no_mem;
7678776945
}
7678876946
}
7678976947
break;
7679076948
}
7679176949
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76995,23 @@
7683776995
assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
7683876996
nArg = (int)pArgc->u.i;
7683976997
iQuery = (int)pQuery->u.i;
7684076998
7684176999
/* Invoke the xFilter method */
76842
- {
76843
- res = 0;
76844
- apArg = p->apArg;
76845
- for(i = 0; i<nArg; i++){
76846
- apArg[i] = &pArgc[i+1];
76847
- }
76848
-
76849
- rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76850
- sqlite3VtabImportErrmsg(p, pVtab);
76851
- if( rc==SQLITE_OK ){
76852
- res = pModule->xEof(pVtabCursor);
76853
- }
76854
- VdbeBranchTaken(res!=0,2);
76855
- if( res ){
76856
- pc = pOp->p2 - 1;
76857
- }
77000
+ res = 0;
77001
+ apArg = p->apArg;
77002
+ for(i = 0; i<nArg; i++){
77003
+ apArg[i] = &pArgc[i+1];
77004
+ }
77005
+ rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
77006
+ sqlite3VtabImportErrmsg(p, pVtab);
77007
+ if( rc==SQLITE_OK ){
77008
+ res = pModule->xEof(pVtabCursor);
7685877009
}
7685977010
pCur->nullRow = 0;
76860
-
77011
+ VdbeBranchTaken(res!=0,2);
77012
+ if( res ) goto jump_to_p2;
7686177013
break;
7686277014
}
7686377015
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7686477016
7686577017
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77094,11 @@
7694277094
res = pModule->xEof(pCur->pVtabCursor);
7694377095
}
7694477096
VdbeBranchTaken(!res,2);
7694577097
if( !res ){
7694677098
/* If there is data, jump to P2 */
76947
- pc = pOp->p2 - 1;
77099
+ goto jump_to_p2_and_check_for_interrupt;
7694877100
}
7694977101
goto check_for_interrupt;
7695077102
}
7695177103
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7695277104
@@ -77065,11 +77217,12 @@
7706577217
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
7706677218
/* Opcode: Pagecount P1 P2 * * *
7706777219
**
7706877220
** Write the current number of pages in database P1 to memory cell P2.
7706977221
*/
77070
-case OP_Pagecount: { /* out2-prerelease */
77222
+case OP_Pagecount: { /* out2 */
77223
+ pOut = out2Prerelease(p, pOp);
7707177224
pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
7707277225
break;
7707377226
}
7707477227
#endif
7707577228
@@ -77081,14 +77234,15 @@
7708177234
** Do not let the maximum page count fall below the current page count and
7708277235
** do not change the maximum page count value if P3==0.
7708377236
**
7708477237
** Store the maximum page count after the change in register P2.
7708577238
*/
77086
-case OP_MaxPgcnt: { /* out2-prerelease */
77239
+case OP_MaxPgcnt: { /* out2 */
7708777240
unsigned int newMax;
7708877241
Btree *pBt;
7708977242
77243
+ pOut = out2Prerelease(p, pOp);
7709077244
pBt = db->aDb[pOp->p1].pBt;
7709177245
newMax = 0;
7709277246
if( pOp->p3 ){
7709377247
newMax = sqlite3BtreeLastPage(pBt);
7709477248
if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77267,10 @@
7711377267
*/
7711477268
case OP_Init: { /* jump */
7711577269
char *zTrace;
7711677270
char *z;
7711777271
77118
- if( pOp->p2 ){
77119
- pc = pOp->p2 - 1;
77120
- }
7712177272
#ifndef SQLITE_OMIT_TRACE
7712277273
if( db->xTrace
7712377274
&& !p->doingRerun
7712477275
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7712577276
){
@@ -77143,10 +77294,11 @@
7714377294
){
7714477295
sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
7714577296
}
7714677297
#endif /* SQLITE_DEBUG */
7714777298
#endif /* SQLITE_OMIT_TRACE */
77299
+ if( pOp->p2 ) goto jump_to_p2;
7714877300
break;
7714977301
}
7715077302
7715177303
7715277304
/* Opcode: Noop * * * * *
@@ -77174,31 +77326,31 @@
7717477326
}
7717577327
7717677328
#ifdef VDBE_PROFILE
7717777329
{
7717877330
u64 endTime = sqlite3Hwtime();
77179
- if( endTime>start ) pOp->cycles += endTime - start;
77180
- pOp->cnt++;
77331
+ if( endTime>start ) pOrigOp->cycles += endTime - start;
77332
+ pOrigOp->cnt++;
7718177333
}
7718277334
#endif
7718377335
7718477336
/* The following code adds nothing to the actual functionality
7718577337
** of the program. It is only here for testing and debugging.
7718677338
** On the other hand, it does burn CPU cycles every time through
7718777339
** the evaluator loop. So we can leave it out when NDEBUG is defined.
7718877340
*/
7718977341
#ifndef NDEBUG
77190
- assert( pc>=-1 && pc<p->nOp );
77342
+ assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
7719177343
7719277344
#ifdef SQLITE_DEBUG
7719377345
if( db->flags & SQLITE_VdbeTrace ){
7719477346
if( rc!=0 ) printf("rc=%d\n",rc);
77195
- if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
77196
- registerTrace(pOp->p2, &aMem[pOp->p2]);
77347
+ if( pOrigOp->opflags & (OPFLG_OUT2) ){
77348
+ registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
7719777349
}
77198
- if( pOp->opflags & OPFLG_OUT3 ){
77199
- registerTrace(pOp->p3, &aMem[pOp->p3]);
77350
+ if( pOrigOp->opflags & OPFLG_OUT3 ){
77351
+ registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
7720077352
}
7720177353
}
7720277354
#endif /* SQLITE_DEBUG */
7720377355
#endif /* NDEBUG */
7720477356
} /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77361,11 @@
7720977361
vdbe_error_halt:
7721077362
assert( rc );
7721177363
p->rc = rc;
7721277364
testcase( sqlite3GlobalConfig.xLog!=0 );
7721377365
sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77214
- pc, p->zSql, p->zErrMsg);
77366
+ (int)(pOp - aOp), p->zSql, p->zErrMsg);
7721577367
sqlite3VdbeHalt(p);
7721677368
if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
7721777369
rc = SQLITE_ERROR;
7721877370
if( resetSchemaOnFault>0 ){
7721977371
sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78187,23 @@
7803578187
**
7803678188
** In both cases, the effects of the main thread seeing (bDone==0) even
7803778189
** after the thread has finished are not dire. So we don't worry about
7803878190
** memory barriers and such here.
7803978191
*/
78192
+typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int);
7804078193
struct SortSubtask {
7804178194
SQLiteThread *pThread; /* Background thread, if any */
7804278195
int bDone; /* Set if thread is finished but not joined */
7804378196
VdbeSorter *pSorter; /* Sorter that owns this sub-task */
7804478197
UnpackedRecord *pUnpacked; /* Space to unpack a record */
7804578198
SorterList list; /* List for thread to write to a PMA */
7804678199
int nPMA; /* Number of PMAs currently in file */
78200
+ SorterCompare xCompare; /* Compare function to use */
7804778201
SorterFile file; /* Temp file for level-0 PMAs */
7804878202
SorterFile file2; /* Space for other PMAs */
7804978203
};
78204
+
7805078205
7805178206
/*
7805278207
** Main sorter structure. A single instance of this is allocated for each
7805378208
** sorter cursor created by the VDBE.
7805478209
**
@@ -78072,12 +78227,16 @@
7807278227
int nMemory; /* Size of list.aMemory allocation in bytes */
7807378228
u8 bUsePMA; /* True if one or more PMAs created */
7807478229
u8 bUseThreads; /* True to use background threads */
7807578230
u8 iPrev; /* Previous thread used to flush PMA */
7807678231
u8 nTask; /* Size of aTask[] array */
78232
+ u8 typeMask;
7807778233
SortSubtask aTask[1]; /* One or more subtasks */
7807878234
};
78235
+
78236
+#define SORTER_TYPE_INTEGER 0x01
78237
+#define SORTER_TYPE_TEXT 0x02
7807978238
7808078239
/*
7808178240
** An instance of the following object is used to read records out of a
7808278241
** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
7808378242
** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78645,165 @@
7848678645
rc = vdbePmaReaderNext(pReadr);
7848778646
}
7848878647
return rc;
7848978648
}
7849078649
78650
+/*
78651
+** A version of vdbeSorterCompare() that assumes that it has already been
78652
+** determined that the first field of key1 is equal to the first field of
78653
+** key2.
78654
+*/
78655
+static int vdbeSorterCompareTail(
78656
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78657
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78658
+ const void *pKey1, int nKey1, /* Left side of comparison */
78659
+ const void *pKey2, int nKey2 /* Right side of comparison */
78660
+){
78661
+ UnpackedRecord *r2 = pTask->pUnpacked;
78662
+ if( *pbKey2Cached==0 ){
78663
+ sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78664
+ *pbKey2Cached = 1;
78665
+ }
78666
+ return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
78667
+}
7849178668
7849278669
/*
7849378670
** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
7849478671
** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
7849578672
** used by the comparison. Return the result of the comparison.
7849678673
**
78497
-** Before returning, object (pTask->pUnpacked) is populated with the
78498
-** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it
78499
-** is assumed that the (pTask->pUnpacked) structure already contains the
78500
-** unpacked key to use as key2.
78674
+** If IN/OUT parameter *pbKey2Cached is true when this function is called,
78675
+** it is assumed that (pTask->pUnpacked) contains the unpacked version
78676
+** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
78677
+** version of key2 and *pbKey2Cached set to true before returning.
7850178678
**
7850278679
** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
7850378680
** to SQLITE_NOMEM.
7850478681
*/
7850578682
static int vdbeSorterCompare(
7850678683
SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78684
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
7850778685
const void *pKey1, int nKey1, /* Left side of comparison */
7850878686
const void *pKey2, int nKey2 /* Right side of comparison */
7850978687
){
7851078688
UnpackedRecord *r2 = pTask->pUnpacked;
78511
- if( pKey2 ){
78689
+ if( !*pbKey2Cached ){
7851278690
sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78691
+ *pbKey2Cached = 1;
7851378692
}
7851478693
return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
7851578694
}
78695
+
78696
+/*
78697
+** A specially optimized version of vdbeSorterCompare() that assumes that
78698
+** the first field of each key is a TEXT value and that the collation
78699
+** sequence to compare them with is BINARY.
78700
+*/
78701
+static int vdbeSorterCompareText(
78702
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78703
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78704
+ const void *pKey1, int nKey1, /* Left side of comparison */
78705
+ const void *pKey2, int nKey2 /* Right side of comparison */
78706
+){
78707
+ const u8 * const p1 = (const u8 * const)pKey1;
78708
+ const u8 * const p2 = (const u8 * const)pKey2;
78709
+ const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78710
+ const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78711
+
78712
+ int n1;
78713
+ int n2;
78714
+ int res;
78715
+
78716
+ getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2;
78717
+ getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2;
78718
+ res = memcmp(v1, v2, MIN(n1, n2));
78719
+ if( res==0 ){
78720
+ res = n1 - n2;
78721
+ }
78722
+
78723
+ if( res==0 ){
78724
+ if( pTask->pSorter->pKeyInfo->nField>1 ){
78725
+ res = vdbeSorterCompareTail(
78726
+ pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78727
+ );
78728
+ }
78729
+ }else{
78730
+ if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78731
+ res = res * -1;
78732
+ }
78733
+ }
78734
+
78735
+ return res;
78736
+}
78737
+
78738
+/*
78739
+** A specially optimized version of vdbeSorterCompare() that assumes that
78740
+** the first field of each key is an INTEGER value.
78741
+*/
78742
+static int vdbeSorterCompareInt(
78743
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78744
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78745
+ const void *pKey1, int nKey1, /* Left side of comparison */
78746
+ const void *pKey2, int nKey2 /* Right side of comparison */
78747
+){
78748
+ const u8 * const p1 = (const u8 * const)pKey1;
78749
+ const u8 * const p2 = (const u8 * const)pKey2;
78750
+ const int s1 = p1[1]; /* Left hand serial type */
78751
+ const int s2 = p2[1]; /* Right hand serial type */
78752
+ const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78753
+ const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78754
+ int res; /* Return value */
78755
+
78756
+ assert( (s1>0 && s1<7) || s1==8 || s1==9 );
78757
+ assert( (s2>0 && s2<7) || s2==8 || s2==9 );
78758
+
78759
+ if( s1>7 && s2>7 ){
78760
+ res = s1 - s2;
78761
+ }else{
78762
+ if( s1==s2 ){
78763
+ if( (*v1 ^ *v2) & 0x80 ){
78764
+ /* The two values have different signs */
78765
+ res = (*v1 & 0x80) ? -1 : +1;
78766
+ }else{
78767
+ /* The two values have the same sign. Compare using memcmp(). */
78768
+ static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
78769
+ int i;
78770
+ res = 0;
78771
+ for(i=0; i<aLen[s1]; i++){
78772
+ if( (res = v1[i] - v2[i]) ) break;
78773
+ }
78774
+ }
78775
+ }else{
78776
+ if( s2>7 ){
78777
+ res = +1;
78778
+ }else if( s1>7 ){
78779
+ res = -1;
78780
+ }else{
78781
+ res = s1 - s2;
78782
+ }
78783
+ assert( res!=0 );
78784
+
78785
+ if( res>0 ){
78786
+ if( *v1 & 0x80 ) res = -1;
78787
+ }else{
78788
+ if( *v2 & 0x80 ) res = +1;
78789
+ }
78790
+ }
78791
+ }
78792
+
78793
+ if( res==0 ){
78794
+ if( pTask->pSorter->pKeyInfo->nField>1 ){
78795
+ res = vdbeSorterCompareTail(
78796
+ pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78797
+ );
78798
+ }
78799
+ }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78800
+ res = res * -1;
78801
+ }
78802
+
78803
+ return res;
78804
+}
7851678805
7851778806
/*
7851878807
** Initialize the temporary index cursor just opened as a sorter cursor.
7851978808
**
7852078809
** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78868,17 @@
7857978868
rc = SQLITE_NOMEM;
7858078869
}else{
7858178870
pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
7858278871
memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
7858378872
pKeyInfo->db = 0;
78584
- if( nField && nWorker==0 ) pKeyInfo->nField = nField;
78873
+ if( nField && nWorker==0 ){
78874
+ pKeyInfo->nXField += (pKeyInfo->nField - nField);
78875
+ pKeyInfo->nField = nField;
78876
+ }
7858578877
pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
7858678878
pSorter->nTask = nWorker + 1;
78879
+ pSorter->iPrev = nWorker-1;
7858778880
pSorter->bUseThreads = (pSorter->nTask>1);
7858878881
pSorter->db = db;
7858978882
for(i=0; i<pSorter->nTask; i++){
7859078883
SortSubtask *pTask = &pSorter->aTask[i];
7859178884
pTask->pSorter = pSorter;
@@ -78607,10 +78900,16 @@
7860778900
pSorter->nMemory = pgsz;
7860878901
pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
7860978902
if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
7861078903
}
7861178904
}
78905
+
78906
+ if( (pKeyInfo->nField+pKeyInfo->nXField)<13
78907
+ && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
78908
+ ){
78909
+ pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
78910
+ }
7861278911
}
7861378912
7861478913
return rc;
7861578914
}
7861678915
#undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78930,28 @@
7863178930
** Free all resources owned by the object indicated by argument pTask. All
7863278931
** fields of *pTask are zeroed before returning.
7863378932
*/
7863478933
static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
7863578934
sqlite3DbFree(db, pTask->pUnpacked);
78636
- pTask->pUnpacked = 0;
7863778935
#if SQLITE_MAX_WORKER_THREADS>0
7863878936
/* pTask->list.aMemory can only be non-zero if it was handed memory
7863978937
** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
7864078938
if( pTask->list.aMemory ){
7864178939
sqlite3_free(pTask->list.aMemory);
78642
- pTask->list.aMemory = 0;
7864378940
}else
7864478941
#endif
7864578942
{
7864678943
assert( pTask->list.aMemory==0 );
7864778944
vdbeSorterRecordFree(0, pTask->list.pList);
7864878945
}
78649
- pTask->list.pList = 0;
7865078946
if( pTask->file.pFd ){
7865178947
sqlite3OsCloseFree(pTask->file.pFd);
78652
- pTask->file.pFd = 0;
78653
- pTask->file.iEof = 0;
7865478948
}
7865578949
if( pTask->file2.pFd ){
7865678950
sqlite3OsCloseFree(pTask->file2.pFd);
78657
- pTask->file2.pFd = 0;
78658
- pTask->file2.iEof = 0;
7865978951
}
78952
+ memset(pTask, 0, sizeof(SortSubtask));
7866078953
}
7866178954
7866278955
#ifdef SQLITE_DEBUG_SORTER_THREADS
7866378956
static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
7866478957
i64 t;
@@ -78834,10 +79127,11 @@
7883479127
vdbeMergeEngineFree(pSorter->pMerger);
7883579128
pSorter->pMerger = 0;
7883679129
for(i=0; i<pSorter->nTask; i++){
7883779130
SortSubtask *pTask = &pSorter->aTask[i];
7883879131
vdbeSortSubtaskCleanup(db, pTask);
79132
+ pTask->pSorter = pSorter;
7883979133
}
7884079134
if( pSorter->list.aMemory==0 ){
7884179135
vdbeSorterRecordFree(0, pSorter->list.pList);
7884279136
}
7884379137
pSorter->list.pList = 0;
@@ -78943,31 +79237,45 @@
7894379237
SorterRecord *p2, /* Second list to merge */
7894479238
SorterRecord **ppOut /* OUT: Head of merged list */
7894579239
){
7894679240
SorterRecord *pFinal = 0;
7894779241
SorterRecord **pp = &pFinal;
78948
- void *pVal2 = p2 ? SRVAL(p2) : 0;
79242
+ int bCached = 0;
7894979243
7895079244
while( p1 && p2 ){
7895179245
int res;
78952
- res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal);
79246
+ res = pTask->xCompare(
79247
+ pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
79248
+ );
79249
+
7895379250
if( res<=0 ){
7895479251
*pp = p1;
7895579252
pp = &p1->u.pNext;
7895679253
p1 = p1->u.pNext;
78957
- pVal2 = 0;
7895879254
}else{
7895979255
*pp = p2;
78960
- pp = &p2->u.pNext;
79256
+ pp = &p2->u.pNext;
7896179257
p2 = p2->u.pNext;
78962
- if( p2==0 ) break;
78963
- pVal2 = SRVAL(p2);
79258
+ bCached = 0;
7896479259
}
7896579260
}
7896679261
*pp = p1 ? p1 : p2;
7896779262
*ppOut = pFinal;
7896879263
}
79264
+
79265
+/*
79266
+** Return the SorterCompare function to compare values collected by the
79267
+** sorter object passed as the only argument.
79268
+*/
79269
+static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){
79270
+ if( p->typeMask==SORTER_TYPE_INTEGER ){
79271
+ return vdbeSorterCompareInt;
79272
+ }else if( p->typeMask==SORTER_TYPE_TEXT ){
79273
+ return vdbeSorterCompareText;
79274
+ }
79275
+ return vdbeSorterCompare;
79276
+}
7896979277
7897079278
/*
7897179279
** Sort the linked list of records headed at pTask->pList. Return
7897279280
** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
7897379281
** an error occurs.
@@ -78979,16 +79287,18 @@
7897979287
int rc;
7898079288
7898179289
rc = vdbeSortAllocUnpacked(pTask);
7898279290
if( rc!=SQLITE_OK ) return rc;
7898379291
79292
+ p = pList->pList;
79293
+ pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
79294
+
7898479295
aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
7898579296
if( !aSlot ){
7898679297
return SQLITE_NOMEM;
7898779298
}
7898879299
78989
- p = pList->pList;
7899079300
while( p ){
7899179301
SorterRecord *pNext;
7899279302
if( pList->aMemory ){
7899379303
if( (u8*)p==pList->aMemory ){
7899479304
pNext = 0;
@@ -79198,28 +79508,27 @@
7919879508
/* Update contents of aTree[] */
7919979509
if( rc==SQLITE_OK ){
7920079510
int i; /* Index of aTree[] to recalculate */
7920179511
PmaReader *pReadr1; /* First PmaReader to compare */
7920279512
PmaReader *pReadr2; /* Second PmaReader to compare */
79203
- u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */
79513
+ int bCached = 0;
7920479514
7920579515
/* Find the first two PmaReaders to compare. The one that was just
7920679516
** advanced (iPrev) and the one next to it in the array. */
7920779517
pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
7920879518
pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
79209
- pKey2 = pReadr2->aKey;
7921079519
7921179520
for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
7921279521
/* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
7921379522
int iRes;
7921479523
if( pReadr1->pFd==0 ){
7921579524
iRes = +1;
7921679525
}else if( pReadr2->pFd==0 ){
7921779526
iRes = -1;
7921879527
}else{
79219
- iRes = vdbeSorterCompare(pTask,
79220
- pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey
79528
+ iRes = pTask->xCompare(pTask, &bCached,
79529
+ pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
7922179530
);
7922279531
}
7922379532
7922479533
/* If pReadr1 contained the smaller value, set aTree[i] to its index.
7922579534
** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79546,13 @@
7923779546
** is sorted from oldest to newest, so pReadr1 contains older values
7923879547
** than pReadr2 iff (pReadr1<pReadr2). */
7923979548
if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
7924079549
pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
7924179550
pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79242
- pKey2 = pReadr2->aKey;
79551
+ bCached = 0;
7924379552
}else{
79244
- if( pReadr1->pFd ) pKey2 = 0;
79553
+ if( pReadr1->pFd ) bCached = 0;
7924579554
pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
7924679555
pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
7924779556
}
7924879557
}
7924979558
*pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79655,20 @@
7934679655
SorterRecord *pNew; /* New list element */
7934779656
7934879657
int bFlush; /* True to flush contents of memory to PMA */
7934979658
int nReq; /* Bytes of memory required */
7935079659
int nPMA; /* Bytes of PMA space required */
79660
+ int t; /* serial type of first record field */
79661
+
79662
+ getVarint32((const u8*)&pVal->z[1], t);
79663
+ if( t>0 && t<10 && t!=7 ){
79664
+ pSorter->typeMask &= SORTER_TYPE_INTEGER;
79665
+ }else if( t>10 && (t & 0x01) ){
79666
+ pSorter->typeMask &= SORTER_TYPE_TEXT;
79667
+ }else{
79668
+ pSorter->typeMask = 0;
79669
+ }
7935179670
7935279671
assert( pSorter );
7935379672
7935479673
/* Figure out whether or not the current contents of memory should be
7935579674
** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79930,16 @@
7961179930
if( p1->pFd==0 ){
7961279931
iRes = i2;
7961379932
}else if( p2->pFd==0 ){
7961479933
iRes = i1;
7961579934
}else{
79935
+ SortSubtask *pTask = pMerger->pTask;
79936
+ int bCached = 0;
7961679937
int res;
79617
- assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79618
- res = vdbeSorterCompare(
79619
- pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79938
+ assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79939
+ res = pTask->xCompare(
79940
+ pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey
7962079941
);
7962179942
if( res<=0 ){
7962279943
iRes = i1;
7962379944
}else{
7962479945
iRes = i2;
@@ -79638,15 +79959,16 @@
7963879959
*/
7963979960
#define INCRINIT_NORMAL 0
7964079961
#define INCRINIT_TASK 1
7964179962
#define INCRINIT_ROOT 2
7964279963
79643
-/* Forward reference.
79644
-** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each
79645
-** other (when building a merge tree).
79964
+/*
79965
+** Forward reference required as the vdbeIncrMergeInit() and
79966
+** vdbePmaReaderIncrInit() routines are called mutually recursively when
79967
+** building a merge tree.
7964679968
*/
79647
-static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode);
79969
+static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode);
7964879970
7964979971
/*
7965079972
** Initialize the MergeEngine object passed as the second argument. Once this
7965179973
** function returns, the first key of merged data may be read from the
7965279974
** MergeEngine object in the usual fashion.
@@ -79689,11 +80011,11 @@
7968980011
** the main thread to fill its buffer. So calling PmaReaderNext()
7969080012
** on this PmaReader before any of the multi-threaded PmaReaders takes
7969180013
** better advantage of multi-processor hardware. */
7969280014
rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
7969380015
}else{
79694
- rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
80016
+ rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
7969580017
}
7969680018
if( rc!=SQLITE_OK ) return rc;
7969780019
}
7969880020
7969980021
for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80023,19 @@
7970180023
}
7970280024
return pTask->pUnpacked->errCode;
7970380025
}
7970480026
7970580027
/*
79706
-** Initialize the IncrMerge field of a PmaReader.
79707
-**
79708
-** If the PmaReader passed as the first argument is not an incremental-reader
79709
-** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves
79710
-** to open and/or initialize the temp file related fields of the IncrMerge
80028
+** The PmaReader passed as the first argument is guaranteed to be an
80029
+** incremental-reader (pReadr->pIncr!=0). This function serves to open
80030
+** and/or initialize the temp file related fields of the IncrMerge
7971180031
** object at (pReadr->pIncr).
7971280032
**
7971380033
** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
79714
-** in the sub-tree headed by pReadr are also initialized. Data is then loaded
79715
-** into the buffers belonging to pReadr and it is set to
79716
-** point to the first key in its range.
80034
+** in the sub-tree headed by pReadr are also initialized. Data is then
80035
+** loaded into the buffers belonging to pReadr and it is set to point to
80036
+** the first key in its range.
7971780037
**
7971880038
** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
7971980039
** to be a multi-threaded PmaReader and this function is being called in a
7972080040
** background thread. In this case all PmaReaders in the sub-tree are
7972180041
** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80058,112 @@
7973880058
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
7973980059
*/
7974080060
static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
7974180061
int rc = SQLITE_OK;
7974280062
IncrMerger *pIncr = pReadr->pIncr;
80063
+ SortSubtask *pTask = pIncr->pTask;
80064
+ sqlite3 *db = pTask->pSorter->db;
7974380065
7974480066
/* eMode is always INCRINIT_NORMAL in single-threaded mode */
7974580067
assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
7974680068
79747
- if( pIncr ){
79748
- SortSubtask *pTask = pIncr->pTask;
79749
- sqlite3 *db = pTask->pSorter->db;
79750
-
79751
- rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
79752
-
79753
- /* Set up the required files for pIncr. A multi-theaded IncrMerge object
79754
- ** requires two temp files to itself, whereas a single-threaded object
79755
- ** only requires a region of pTask->file2. */
79756
- if( rc==SQLITE_OK ){
79757
- int mxSz = pIncr->mxSz;
79758
-#if SQLITE_MAX_WORKER_THREADS>0
79759
- if( pIncr->bUseThread ){
79760
- rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
79761
- if( rc==SQLITE_OK ){
79762
- rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
79763
- }
79764
- }else
79765
-#endif
79766
- /*if( !pIncr->bUseThread )*/{
79767
- if( pTask->file2.pFd==0 ){
79768
- assert( pTask->file2.iEof>0 );
79769
- rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
79770
- pTask->file2.iEof = 0;
79771
- }
79772
- if( rc==SQLITE_OK ){
79773
- pIncr->aFile[1].pFd = pTask->file2.pFd;
79774
- pIncr->iStartOff = pTask->file2.iEof;
79775
- pTask->file2.iEof += mxSz;
79776
- }
79777
- }
79778
- }
79779
-
79780
-#if SQLITE_MAX_WORKER_THREADS>0
79781
- if( rc==SQLITE_OK && pIncr->bUseThread ){
79782
- /* Use the current thread to populate aFile[1], even though this
79783
- ** PmaReader is multi-threaded. The reason being that this function
79784
- ** is already running in background thread pIncr->pTask->thread. */
79785
- assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
79786
- rc = vdbeIncrPopulate(pIncr);
79787
- }
79788
-#endif
79789
-
79790
- if( rc==SQLITE_OK
79791
- && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK)
79792
- ){
79793
- rc = vdbePmaReaderNext(pReadr);
79794
- }
79795
- }
80069
+ rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
80070
+
80071
+ /* Set up the required files for pIncr. A multi-theaded IncrMerge object
80072
+ ** requires two temp files to itself, whereas a single-threaded object
80073
+ ** only requires a region of pTask->file2. */
80074
+ if( rc==SQLITE_OK ){
80075
+ int mxSz = pIncr->mxSz;
80076
+#if SQLITE_MAX_WORKER_THREADS>0
80077
+ if( pIncr->bUseThread ){
80078
+ rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
80079
+ if( rc==SQLITE_OK ){
80080
+ rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
80081
+ }
80082
+ }else
80083
+#endif
80084
+ /*if( !pIncr->bUseThread )*/{
80085
+ if( pTask->file2.pFd==0 ){
80086
+ assert( pTask->file2.iEof>0 );
80087
+ rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
80088
+ pTask->file2.iEof = 0;
80089
+ }
80090
+ if( rc==SQLITE_OK ){
80091
+ pIncr->aFile[1].pFd = pTask->file2.pFd;
80092
+ pIncr->iStartOff = pTask->file2.iEof;
80093
+ pTask->file2.iEof += mxSz;
80094
+ }
80095
+ }
80096
+ }
80097
+
80098
+#if SQLITE_MAX_WORKER_THREADS>0
80099
+ if( rc==SQLITE_OK && pIncr->bUseThread ){
80100
+ /* Use the current thread to populate aFile[1], even though this
80101
+ ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
80102
+ ** then this function is already running in background thread
80103
+ ** pIncr->pTask->thread.
80104
+ **
80105
+ ** If this is the INCRINIT_ROOT object, then it is running in the
80106
+ ** main VDBE thread. But that is Ok, as that thread cannot return
80107
+ ** control to the VDBE or proceed with anything useful until the
80108
+ ** first results are ready from this merger object anyway.
80109
+ */
80110
+ assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
80111
+ rc = vdbeIncrPopulate(pIncr);
80112
+ }
80113
+#endif
80114
+
80115
+ if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
80116
+ rc = vdbePmaReaderNext(pReadr);
80117
+ }
80118
+
7979680119
return rc;
7979780120
}
7979880121
7979980122
#if SQLITE_MAX_WORKER_THREADS>0
7980080123
/*
7980180124
** The main routine for vdbePmaReaderIncrMergeInit() operations run in
7980280125
** background threads.
7980380126
*/
79804
-static void *vdbePmaReaderBgInit(void *pCtx){
80127
+static void *vdbePmaReaderBgIncrInit(void *pCtx){
7980580128
PmaReader *pReader = (PmaReader*)pCtx;
7980680129
void *pRet = SQLITE_INT_TO_PTR(
7980780130
vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
7980880131
);
7980980132
pReader->pIncr->pTask->bDone = 1;
7981080133
return pRet;
7981180134
}
80135
+#endif
7981280136
7981380137
/*
79814
-** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
79815
-** on the PmaReader object passed as the first argument.
79816
-**
79817
-** This call will initialize the various fields of the pReadr->pIncr
79818
-** structure and, if it is a multi-threaded IncrMerger, launch a
79819
-** background thread to populate aFile[1].
80138
+** If the PmaReader passed as the first argument is not an incremental-reader
80139
+** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
80140
+** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
80141
+** this routine to initialize the incremental merge.
80142
+**
80143
+** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
80144
+** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
80145
+** Or, if the IncrMerger is single threaded, the same function is called
80146
+** using the current thread.
7982080147
*/
79821
-static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){
79822
- void *pCtx = (void*)pReadr;
79823
- return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx);
80148
+static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){
80149
+ IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */
80150
+ int rc = SQLITE_OK; /* Return code */
80151
+ if( pIncr ){
80152
+#if SQLITE_MAX_WORKER_THREADS>0
80153
+ assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
80154
+ if( pIncr->bUseThread ){
80155
+ void *pCtx = (void*)pReadr;
80156
+ rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx);
80157
+ }else
80158
+#endif
80159
+ {
80160
+ rc = vdbePmaReaderIncrMergeInit(pReadr, eMode);
80161
+ }
80162
+ }
80163
+ return rc;
7982480164
}
79825
-#endif
7982680165
7982780166
/*
7982880167
** Allocate a new MergeEngine object to merge the contents of nPMA level-0
7982980168
** PMAs from pTask->file. If no error occurs, set *ppOut to point to
7983080169
** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80371,15 @@
8003280371
int rc; /* Return code */
8003380372
SortSubtask *pTask0 = &pSorter->aTask[0];
8003480373
MergeEngine *pMain = 0;
8003580374
#if SQLITE_MAX_WORKER_THREADS
8003680375
sqlite3 *db = pTask0->pSorter->db;
80376
+ int i;
80377
+ SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
80378
+ for(i=0; i<pSorter->nTask; i++){
80379
+ pSorter->aTask[i].xCompare = xCompare;
80380
+ }
8003780381
#endif
8003880382
8003980383
rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
8004080384
if( rc==SQLITE_OK ){
8004180385
#if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80404,25 @@
8006080404
vdbeIncrMergerSetThreads(pIncr);
8006180405
assert( pIncr->pTask!=pLast );
8006280406
}
8006380407
}
8006480408
for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
80409
+ /* Check that:
80410
+ **
80411
+ ** a) The incremental merge object is configured to use the
80412
+ ** right task, and
80413
+ ** b) If it is using task (nTask-1), it is configured to run
80414
+ ** in single-threaded mode. This is important, as the
80415
+ ** root merge (INCRINIT_ROOT) will be using the same task
80416
+ ** object.
80417
+ */
8006580418
PmaReader *p = &pMain->aReadr[iTask];
80066
- assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
80067
- if( p->pIncr ){
80068
- if( iTask==pSorter->nTask-1 ){
80069
- rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK);
80070
- }else{
80071
- rc = vdbePmaReaderBgIncrInit(p);
80072
- }
80073
- }
80419
+ assert( p->pIncr==0 || (
80420
+ (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */
80421
+ && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
80422
+ ));
80423
+ rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
8007480424
}
8007580425
}
8007680426
pMain = 0;
8007780427
}
8007880428
if( rc==SQLITE_OK ){
@@ -81023,11 +81373,11 @@
8102381373
** Should be transformed into:
8102481374
**
8102581375
** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
8102681376
**
8102781377
** The nSubquery parameter specifies how many levels of subquery the
81028
-** alias is removed from the original expression. The usually value is
81378
+** alias is removed from the original expression. The usual value is
8102981379
** zero but it might be more if the alias is contained within a subquery
8103081380
** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
8103181381
** structures must be increased by the nSubquery amount.
8103281382
*/
8103381383
static void resolveAlias(
@@ -81043,11 +81393,11 @@
8104381393
sqlite3 *db; /* The database connection */
8104481394
8104581395
assert( iCol>=0 && iCol<pEList->nExpr );
8104681396
pOrig = pEList->a[iCol].pExpr;
8104781397
assert( pOrig!=0 );
81048
- assert( pOrig->flags & EP_Resolved );
81398
+ assert( (pOrig->flags & EP_Resolved)!=0 || zType[0]==0 );
8104981399
db = pParse->db;
8105081400
pDup = sqlite3ExprDup(db, pOrig, 0);
8105181401
if( pDup==0 ) return;
8105281402
if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
8105381403
incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82287,15 @@
8193782287
pNew->flags |= EP_IntValue;
8193882288
pNew->u.iValue = iCol;
8193982289
if( pItem->pExpr==pE ){
8194082290
pItem->pExpr = pNew;
8194182291
}else{
81942
- assert( pItem->pExpr->op==TK_COLLATE );
81943
- assert( pItem->pExpr->pLeft==pE );
81944
- pItem->pExpr->pLeft = pNew;
82292
+ Expr *pParent = pItem->pExpr;
82293
+ assert( pParent->op==TK_COLLATE );
82294
+ while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
82295
+ assert( pParent->pLeft==pE );
82296
+ pParent->pLeft = pNew;
8194582297
}
8194682298
sqlite3ExprDelete(db, pE);
8194782299
pItem->u.x.iOrderByCol = (u16)iCol;
8194882300
pItem->done = 1;
8194982301
}else{
@@ -82139,11 +82491,11 @@
8213982491
** as if it were part of the sub-query, not the parent. This block
8214082492
** moves the pOrderBy down to the sub-query. It will be moved back
8214182493
** after the names have been resolved. */
8214282494
if( p->selFlags & SF_Converted ){
8214382495
Select *pSub = p->pSrc->a[0].pSelect;
82144
- assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82496
+ assert( p->pSrc->nSrc==1 && p->pOrderBy );
8214582497
assert( pSub->pPrior && pSub->pOrderBy==0 );
8214682498
pSub->pOrderBy = p->pOrderBy;
8214782499
p->pOrderBy = 0;
8214882500
}
8214982501
@@ -82241,12 +82593,19 @@
8224182593
8224282594
/* Process the ORDER BY clause for singleton SELECT statements.
8224382595
** The ORDER BY clause for compounds SELECT statements is handled
8224482596
** below, after all of the result-sets for all of the elements of
8224582597
** the compound have been resolved.
82598
+ **
82599
+ ** If there is an ORDER BY clause on a term of a compound-select other
82600
+ ** than the right-most term, then that is a syntax error. But the error
82601
+ ** is not detected until much later, and so we need to go ahead and
82602
+ ** resolve those symbols on the incorrect ORDER BY for consistency.
8224682603
*/
82247
- if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){
82604
+ if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
82605
+ && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
82606
+ ){
8224882607
return WRC_Abort;
8224982608
}
8225082609
if( db->mallocFailed ){
8225182610
return WRC_Abort;
8225282611
}
@@ -83694,11 +84053,12 @@
8369484053
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
8369584054
int i;
8369684055
u32 m = 0;
8369784056
if( pList ){
8369884057
for(i=0; i<pList->nExpr; i++){
83699
- m |= pList->a[i].pExpr->flags;
84058
+ Expr *pExpr = pList->a[i].pExpr;
84059
+ if( ALWAYS(pExpr) ) m |= pList->a[i].pExpr->flags;
8370084060
}
8370184061
}
8370284062
return m;
8370384063
}
8370484064
@@ -84134,11 +84494,11 @@
8413484494
/* Check to see if an existing table or index can be used to
8413584495
** satisfy the query. This is preferable to generating a new
8413684496
** ephemeral table.
8413784497
*/
8413884498
p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84139
- if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
84499
+ if( pParse->nErr==0 && isCandidateForInOpt(p) ){
8414084500
sqlite3 *db = pParse->db; /* Database connection */
8414184501
Table *pTab; /* Table <table>. */
8414284502
Expr *pExpr; /* Expression <column> */
8414384503
i16 iCol; /* Index of column <column> */
8414484504
i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84819,11 @@
8445984819
}
8446084820
sqlite3ExprDelete(pParse->db, pSel->pLimit);
8446184821
pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
8446284822
&sqlite3IntTokens[1]);
8446384823
pSel->iLimit = 0;
84824
+ pSel->selFlags &= ~SF_MultiValue;
8446484825
if( sqlite3Select(pParse, pSel, &dest) ){
8446584826
return 0;
8446684827
}
8446784828
rReg = dest.iSDParm;
8446884829
ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86185,11 @@
8582486185
sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
8582586186
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
8582686187
break;
8582786188
}
8582886189
case TK_ID: {
85829
- sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
86190
+ sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
8583086191
break;
8583186192
}
8583286193
#ifndef SQLITE_OMIT_CAST
8583386194
case TK_CAST: {
8583486195
/* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86820,11 @@
8645986820
if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
8646086821
if( combinedFlags & EP_xIsSelect ) return 2;
8646186822
if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
8646286823
if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
8646386824
if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86464
- if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
86825
+ if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){
8646586826
if( pA->iColumn!=pB->iColumn ) return 2;
8646686827
if( pA->iTable!=pB->iTable
8646786828
&& (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
8646886829
}
8646986830
}
@@ -86991,10 +87352,11 @@
8699187352
do {
8699287353
z += n;
8699387354
n = sqlite3GetToken(z, &token);
8699487355
}while( token==TK_SPACE );
8699587356
87357
+ if( token==TK_ILLEGAL ) break;
8699687358
zParent = sqlite3DbStrNDup(db, (const char *)z, n);
8699787359
if( zParent==0 ) break;
8699887360
sqlite3Dequote(zParent);
8699987361
if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
8700087362
char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89579,21 @@
8921789579
pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8921889580
}
8921989581
z = argv[2];
8922089582
8922189583
if( pIndex ){
89584
+ tRowcnt *aiRowEst = 0;
8922289585
int nCol = pIndex->nKeyCol+1;
8922389586
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89224
- tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
89225
- sizeof(tRowcnt) * nCol
89226
- );
89227
- if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89228
-#else
89229
- tRowcnt * const aiRowEst = 0;
89587
+ /* Index.aiRowEst may already be set here if there are duplicate
89588
+ ** sqlite_stat1 entries for this index. In that case just clobber
89589
+ ** the old data with the new instead of allocating a new array. */
89590
+ if( pIndex->aiRowEst==0 ){
89591
+ pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol);
89592
+ if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89593
+ }
89594
+ aiRowEst = pIndex->aiRowEst;
8923089595
#endif
8923189596
pIndex->bUnordered = 0;
8923289597
decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
8923389598
if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
8923489599
}else{
@@ -89887,11 +90252,11 @@
8988790252
}
8988890253
8988990254
sqlite3BtreeClose(pDb->pBt);
8989090255
pDb->pBt = 0;
8989190256
pDb->pSchema = 0;
89892
- sqlite3ResetAllSchemasOfConnection(db);
90257
+ sqlite3CollapseDatabaseArray(db);
8989390258
return;
8989490259
8989590260
detach_error:
8989690261
sqlite3_result_error(context, zErr, -1);
8989790262
}
@@ -89921,11 +90286,10 @@
8992190286
if(
8992290287
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
8992390288
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
8992490289
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
8992590290
){
89926
- pParse->nErr++;
8992790291
goto attach_end;
8992890292
}
8992990293
8993090294
#ifndef SQLITE_OMIT_AUTHORIZATION
8993190295
if( pAuthArg ){
@@ -90580,13 +90944,15 @@
9058090944
sqlite3 *db;
9058190945
Vdbe *v;
9058290946
9058390947
assert( pParse->pToplevel==0 );
9058490948
db = pParse->db;
90585
- if( db->mallocFailed ) return;
9058690949
if( pParse->nested ) return;
90587
- if( pParse->nErr ) return;
90950
+ if( db->mallocFailed || pParse->nErr ){
90951
+ if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
90952
+ return;
90953
+ }
9058890954
9058990955
/* Begin by generating some termination code at the end of the
9059090956
** vdbe program
9059190957
*/
9059290958
v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91030,11 @@
9066491030
}
9066591031
9066691032
9066791033
/* Get the VDBE program ready for execution
9066891034
*/
90669
- if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
91035
+ if( v && pParse->nErr==0 && !db->mallocFailed ){
9067091036
assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
9067191037
/* A minimum of one cursor is required if autoincrement is used
9067291038
* See ticket [a696379c1f08866] */
9067391039
if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
9067491040
sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91565,16 @@
9119991565
sqlite3 *db = pParse->db;
9120091566
9120191567
if( ALWAYS(pName2!=0) && pName2->n>0 ){
9120291568
if( db->init.busy ) {
9120391569
sqlite3ErrorMsg(pParse, "corrupt database");
91204
- pParse->nErr++;
9120591570
return -1;
9120691571
}
9120791572
*pUnqual = pName2;
9120891573
iDb = sqlite3FindDb(db, pName1);
9120991574
if( iDb<0 ){
9121091575
sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
91211
- pParse->nErr++;
9121291576
return -1;
9121391577
}
9121491578
}else{
9121591579
assert( db->init.iDb==0 || db->init.busy );
9121691580
iDb = db->init.iDb;
@@ -91365,11 +91729,11 @@
9136591729
pTable = sqlite3FindTable(db, zName, zDb);
9136691730
if( pTable ){
9136791731
if( !noErr ){
9136891732
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
9136991733
}else{
91370
- assert( !db->init.busy );
91734
+ assert( !db->init.busy || CORRUPT_DB );
9137191735
sqlite3CodeVerifySchema(pParse, iDb);
9137291736
}
9137391737
goto begin_table_error;
9137491738
}
9137591739
if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92018,12 @@
9165492018
Column *pCol;
9165592019
9165692020
p = pParse->pNewTable;
9165792021
if( p==0 || NEVER(p->nCol<1) ) return;
9165892022
pCol = &p->aCol[p->nCol-1];
91659
- assert( pCol->zType==0 );
92023
+ assert( pCol->zType==0 || CORRUPT_DB );
92024
+ sqlite3DbFree(pParse->db, pCol->zType);
9166092025
pCol->zType = sqlite3NameFromToken(pParse->db, pType);
9166192026
pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
9166292027
}
9166392028
9166492029
/*
@@ -92888,10 +93253,11 @@
9288893253
if( db->mallocFailed ){
9288993254
goto exit_drop_table;
9289093255
}
9289193256
assert( pParse->nErr==0 );
9289293257
assert( pName->nSrc==1 );
93258
+ if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
9289393259
if( noErr ) db->suppressErr++;
9289493260
pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
9289593261
if( noErr ) db->suppressErr--;
9289693262
9289793263
if( pTab==0 ){
@@ -93201,11 +93567,12 @@
9320193567
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
9320293568
}else{
9320393569
addr2 = sqlite3VdbeCurrentAddr(v);
9320493570
}
9320593571
sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93206
- sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
93572
+ sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
93573
+ sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
9320793574
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
9320893575
sqlite3ReleaseTempReg(pParse, regRecord);
9320993576
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
9321093577
sqlite3VdbeJumpHere(v, addr1);
9321193578
@@ -93294,12 +93661,11 @@
9329493661
int nExtra = 0; /* Space allocated for zExtra[] */
9329593662
int nExtraCol; /* Number of extra columns needed */
9329693663
char *zExtra = 0; /* Extra space after the Index object */
9329793664
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
9329893665
93299
- assert( pParse->nErr==0 ); /* Never called with prior errors */
93300
- if( db->mallocFailed || IN_DECLARE_VTAB ){
93666
+ if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
9330193667
goto exit_create_index;
9330293668
}
9330393669
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
9330493670
goto exit_create_index;
9330593671
}
@@ -94214,11 +94580,10 @@
9421494580
** operator with A. This routine shifts that operator over to B.
9421594581
*/
9421694582
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
9421794583
if( p ){
9421894584
int i;
94219
- assert( p->a || p->nSrc==0 );
9422094585
for(i=p->nSrc-1; i>0; i--){
9422194586
p->a[i].jointype = p->a[i-1].jointype;
9422294587
}
9422394588
p->a[0].jointype = 0;
9422494589
}
@@ -94461,12 +94826,11 @@
9446194826
char *zErr;
9446294827
int j;
9446394828
StrAccum errMsg;
9446494829
Table *pTab = pIdx->pTable;
9446594830
94466
- sqlite3StrAccumInit(&errMsg, 0, 0, 200);
94467
- errMsg.db = pParse->db;
94831
+ sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
9446894832
for(j=0; j<pIdx->nKeyCol; j++){
9446994833
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
9447094834
if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
9447194835
sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
9447294836
sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96655,17 @@
9629196655
){
9629296656
PrintfArguments x;
9629396657
StrAccum str;
9629496658
const char *zFormat;
9629596659
int n;
96660
+ sqlite3 *db = sqlite3_context_db_handle(context);
9629696661
9629796662
if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
9629896663
x.nArg = argc-1;
9629996664
x.nUsed = 0;
9630096665
x.apArg = argv+1;
96301
- sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
96302
- str.db = sqlite3_context_db_handle(context);
96666
+ sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
9630396667
sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
9630496668
n = str.nChar;
9630596669
sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
9630696670
SQLITE_DYNAMIC);
9630796671
}
@@ -96447,11 +96811,11 @@
9644796811
sqlite3_result_double(context, r);
9644896812
}
9644996813
#endif
9645096814
9645196815
/*
96452
-** Allocate nByte bytes of space using sqlite3_malloc(). If the
96816
+** Allocate nByte bytes of space using sqlite3Malloc(). If the
9645396817
** allocation fails, call sqlite3_result_error_nomem() to notify
9645496818
** the database handle that malloc() has failed and return NULL.
9645596819
** If nByte is larger than the maximum string or blob length, then
9645696820
** raise an SQLITE_TOOBIG exception and return NULL.
9645796821
*/
@@ -97116,11 +97480,11 @@
9711697480
int argc,
9711797481
sqlite3_value **argv
9711897482
){
9711997483
unsigned char *z, *zOut;
9712097484
int i;
97121
- zOut = z = sqlite3_malloc( argc*4+1 );
97485
+ zOut = z = sqlite3_malloc64( argc*4+1 );
9712297486
if( z==0 ){
9712397487
sqlite3_result_error_nomem(context);
9712497488
return;
9712597489
}
9712697490
for(i=0; i<argc; i++){
@@ -97264,11 +97628,11 @@
9726497628
sqlite3_result_error_toobig(context);
9726597629
sqlite3_free(zOut);
9726697630
return;
9726797631
}
9726897632
zOld = zOut;
97269
- zOut = sqlite3_realloc(zOut, (int)nOut);
97633
+ zOut = sqlite3_realloc64(zOut, (int)nOut);
9727097634
if( zOut==0 ){
9727197635
sqlite3_result_error_nomem(context);
9727297636
sqlite3_free(zOld);
9727397637
return;
9727497638
}
@@ -97626,12 +97990,11 @@
9762697990
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
9762797991
pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
9762897992
9762997993
if( pAccum ){
9763097994
sqlite3 *db = sqlite3_context_db_handle(context);
97631
- int firstTerm = pAccum->useMalloc==0;
97632
- pAccum->useMalloc = 2;
97995
+ int firstTerm = pAccum->mxAlloc==0;
9763397996
pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
9763497997
if( !firstTerm ){
9763597998
if( argc==2 ){
9763697999
zSep = (char*)sqlite3_value_text(argv[1]);
9763798000
nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99410,12 @@
9904799410
int iFromCol; /* Idx of column in child table */
9904899411
Expr *pEq; /* tFromCol = OLD.tToCol */
9904999412
9905099413
iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
9905199414
assert( iFromCol>=0 );
99052
- tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid";
99415
+ assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
99416
+ tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName;
9905399417
tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
9905499418
9905599419
tToCol.n = sqlite3Strlen30(tToCol.z);
9905699420
tFromCol.n = sqlite3Strlen30(tFromCol.z);
9905799421
@@ -99059,14 +99423,14 @@
9905999423
** that the "OLD.zToCol" term is on the LHS of the = operator, so
9906099424
** that the affinity and collation sequence associated with the
9906199425
** parent table are used for the comparison. */
9906299426
pEq = sqlite3PExpr(pParse, TK_EQ,
9906399427
sqlite3PExpr(pParse, TK_DOT,
99064
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99065
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99428
+ sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99429
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
9906699430
, 0),
99067
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol)
99431
+ sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
9906899432
, 0);
9906999433
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
9907099434
9907199435
/* For ON UPDATE, construct the next term of the WHEN clause.
9907299436
** The final WHEN clause will be like this:
@@ -99074,27 +99438,27 @@
9907499438
** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
9907599439
*/
9907699440
if( pChanges ){
9907799441
pEq = sqlite3PExpr(pParse, TK_IS,
9907899442
sqlite3PExpr(pParse, TK_DOT,
99079
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99080
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99443
+ sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99444
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
9908199445
0),
9908299446
sqlite3PExpr(pParse, TK_DOT,
99083
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99084
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99447
+ sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99448
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
9908599449
0),
9908699450
0);
9908799451
pWhen = sqlite3ExprAnd(db, pWhen, pEq);
9908899452
}
9908999453
9909099454
if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
9909199455
Expr *pNew;
9909299456
if( action==OE_Cascade ){
9909399457
pNew = sqlite3PExpr(pParse, TK_DOT,
99094
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99095
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99458
+ sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99459
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
9909699460
, 0);
9909799461
}else if( action==OE_SetDflt ){
9909899462
Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
9909999463
if( pDflt ){
9910099464
pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99501,16 @@
9913799501
db->lookaside.bEnabled = 0;
9913899502
9913999503
pTrigger = (Trigger *)sqlite3DbMallocZero(db,
9914099504
sizeof(Trigger) + /* struct Trigger */
9914199505
sizeof(TriggerStep) + /* Single step in trigger program */
99142
- nFrom + 1 /* Space for pStep->target.z */
99506
+ nFrom + 1 /* Space for pStep->zTarget */
9914399507
);
9914499508
if( pTrigger ){
9914599509
pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99146
- pStep->target.z = (char *)&pStep[1];
99147
- pStep->target.n = nFrom;
99148
- memcpy((char *)pStep->target.z, zFrom, nFrom);
99510
+ pStep->zTarget = (char *)&pStep[1];
99511
+ memcpy((char *)pStep->zTarget, zFrom, nFrom);
9914999512
9915099513
pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
9915199514
pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
9915299515
pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
9915399516
if( pWhen ){
@@ -99608,24 +99971,27 @@
9960899971
);
9960999972
9961099973
/*
9961199974
** This routine is called to handle SQL of the following forms:
9961299975
**
99613
-** insert into TABLE (IDLIST) values(EXPRLIST)
99976
+** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
9961499977
** insert into TABLE (IDLIST) select
99978
+** insert into TABLE (IDLIST) default values
9961599979
**
9961699980
** The IDLIST following the table name is always optional. If omitted,
99617
-** then a list of all columns for the table is substituted. The IDLIST
99618
-** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
99981
+** then a list of all (non-hidden) columns for the table is substituted.
99982
+** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
99983
+** is omitted.
9961999984
**
99620
-** The pList parameter holds EXPRLIST in the first form of the INSERT
99621
-** statement above, and pSelect is NULL. For the second form, pList is
99622
-** NULL and pSelect is a pointer to the select statement used to generate
99623
-** data for the insert.
99985
+** For the pSelect parameter holds the values to be inserted for the
99986
+** first two forms shown above. A VALUES clause is really just short-hand
99987
+** for a SELECT statement that omits the FROM clause and everything else
99988
+** that follows. If the pSelect parameter is NULL, that means that the
99989
+** DEFAULT VALUES form of the INSERT statement is intended.
9962499990
**
9962599991
** The code generated follows one of four templates. For a simple
99626
-** insert with data coming from a VALUES clause, the code executes
99992
+** insert with data coming from a single-row VALUES clause, the code executes
9962799993
** once straight down through. Pseudo-code follows (we call this
9962899994
** the "1st template"):
9962999995
**
9963099996
** open write cursor to <table> and its indices
9963199997
** put VALUES clause expressions into registers
@@ -99728,11 +100094,11 @@
99728100094
int iDb; /* Index of database holding TABLE */
99729100095
Db *pDb; /* The database containing table being inserted into */
99730100096
u8 useTempTable = 0; /* Store SELECT results in intermediate table */
99731100097
u8 appendFlag = 0; /* True if the insert is likely to be an append */
99732100098
u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
99733
- u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
100099
+ u8 bIdListInOrder; /* True if IDLIST is in table order */
99734100100
ExprList *pList = 0; /* List of VALUES() to be inserted */
99735100101
99736100102
/* Register allocations */
99737100103
int regFromSelect = 0;/* Base register for data coming from SELECT */
99738100104
int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100119,12 @@
99753100119
if( pParse->nErr || db->mallocFailed ){
99754100120
goto insert_cleanup;
99755100121
}
99756100122
99757100123
/* If the Select object is really just a simple VALUES() list with a
99758
- ** single row values (the common case) then keep that one row of values
99759
- ** and go ahead and discard the Select object
100124
+ ** single row (the common case) then keep that one row of values
100125
+ ** and discard the other (unused) parts of the pSelect object
99760100126
*/
99761100127
if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
99762100128
pList = pSelect->pEList;
99763100129
pSelect->pEList = 0;
99764100130
sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100228,11 @@
99862100228
** the index into IDLIST of the primary key column. ipkColumn is
99863100229
** the index of the primary key as it appears in IDLIST, not as
99864100230
** is appears in the original table. (The index of the INTEGER
99865100231
** PRIMARY KEY in the original table is pTab->iPKey.)
99866100232
*/
100233
+ bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0;
99867100234
if( pColumn ){
99868100235
for(i=0; i<pColumn->nId; i++){
99869100236
pColumn->a[i].idx = -1;
99870100237
}
99871100238
for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100264,12 @@
99897100264
** is coming from a SELECT statement, then generate a co-routine that
99898100265
** produces a single row of the SELECT on each invocation. The
99899100266
** co-routine is the common header to the 3rd and 4th templates.
99900100267
*/
99901100268
if( pSelect ){
99902
- /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
100269
+ /* Data is coming from a SELECT or from a multi-row VALUES clause.
100270
+ ** Generate a co-routine to run the SELECT. */
99903100271
int regYield; /* Register holding co-routine entry-point */
99904100272
int addrTop; /* Top of the co-routine */
99905100273
int rc; /* Result code */
99906100274
99907100275
regYield = ++pParse->nMem;
@@ -99910,12 +100278,11 @@
99910100278
sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
99911100279
dest.iSdst = bIdListInOrder ? regData : 0;
99912100280
dest.nSdst = pTab->nCol;
99913100281
rc = sqlite3Select(pParse, pSelect, &dest);
99914100282
regFromSelect = dest.iSdst;
99915
- assert( pParse->nErr==0 || rc );
99916
- if( rc || db->mallocFailed ) goto insert_cleanup;
100283
+ if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
99917100284
sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
99918100285
sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
99919100286
assert( pSelect->pEList );
99920100287
nColumn = pSelect->pEList->nExpr;
99921100288
@@ -99959,12 +100326,12 @@
99959100326
sqlite3VdbeJumpHere(v, addrL);
99960100327
sqlite3ReleaseTempReg(pParse, regRec);
99961100328
sqlite3ReleaseTempReg(pParse, regTempRowid);
99962100329
}
99963100330
}else{
99964
- /* This is the case if the data for the INSERT is coming from a VALUES
99965
- ** clause
100331
+ /* This is the case if the data for the INSERT is coming from a
100332
+ ** single-row VALUES clause
99966100333
*/
99967100334
NameContext sNC;
99968100335
memset(&sNC, 0, sizeof(sNC));
99969100336
sNC.pParse = pParse;
99970100337
srcTab = -1;
@@ -101031,10 +101398,11 @@
101031101398
Table *pDest, /* The table we are inserting into */
101032101399
Select *pSelect, /* A SELECT statement to use as the data source */
101033101400
int onError, /* How to handle constraint errors */
101034101401
int iDbDest /* The database of pDest */
101035101402
){
101403
+ sqlite3 *db = pParse->db;
101036101404
ExprList *pEList; /* The result set of the SELECT */
101037101405
Table *pSrc; /* The table in the FROM clause of SELECT */
101038101406
Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101039101407
struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101040101408
int i; /* Loop counter */
@@ -101178,15 +101546,15 @@
101178101546
** But the main beneficiary of the transfer optimization is the VACUUM
101179101547
** command, and the VACUUM command disables foreign key constraints. So
101180101548
** the extra complication to make this rule less restrictive is probably
101181101549
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101182101550
*/
101183
- if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101551
+ if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101184101552
return 0;
101185101553
}
101186101554
#endif
101187
- if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
101555
+ if( (db->flags & SQLITE_CountRows)!=0 ){
101188101556
return 0; /* xfer opt does not play well with PRAGMA count_changes */
101189101557
}
101190101558
101191101559
/* If we get this far, it means that the xfer optimization is at
101192101560
** least a possibility, though it might only work if the destination
@@ -101193,28 +101561,32 @@
101193101561
** table (tab1) is initially empty.
101194101562
*/
101195101563
#ifdef SQLITE_TEST
101196101564
sqlite3_xferopt_count++;
101197101565
#endif
101198
- iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
101566
+ iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
101199101567
v = sqlite3GetVdbe(pParse);
101200101568
sqlite3CodeVerifySchema(pParse, iDbSrc);
101201101569
iSrc = pParse->nTab++;
101202101570
iDest = pParse->nTab++;
101203101571
regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101204101572
regData = sqlite3GetTempReg(pParse);
101205101573
regRowid = sqlite3GetTempReg(pParse);
101206101574
sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101207101575
assert( HasRowid(pDest) || destHasUniqueIdx );
101208
- if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101576
+ if( (db->flags & SQLITE_Vacuum)==0 && (
101577
+ (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101209101578
|| destHasUniqueIdx /* (2) */
101210101579
|| (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101211
- ){
101580
+ )){
101212101581
/* In some circumstances, we are able to run the xfer optimization
101213
- ** only if the destination table is initially empty. This code makes
101214
- ** that determination. Conditions under which the destination must
101215
- ** be empty:
101582
+ ** only if the destination table is initially empty. Unless the
101583
+ ** SQLITE_Vacuum flag is set, this block generates code to make
101584
+ ** that determination. If SQLITE_Vacuum is set, then the destination
101585
+ ** table is always empty.
101586
+ **
101587
+ ** Conditions under which the destination must be empty:
101216101588
**
101217101589
** (1) There is no INTEGER PRIMARY KEY but there are indices.
101218101590
** (If the destination is not initially empty, the rowid fields
101219101591
** of index entries might need to change.)
101220101592
**
@@ -101253,10 +101625,11 @@
101253101625
}else{
101254101626
sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101255101627
sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101256101628
}
101257101629
for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
101630
+ u8 useSeekResult = 0;
101258101631
for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101259101632
if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101260101633
}
101261101634
assert( pSrcIdx );
101262101635
sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101639,37 @@
101266101639
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101267101640
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101268101641
VdbeComment((v, "%s", pDestIdx->zName));
101269101642
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101270101643
sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
101644
+ if( db->flags & SQLITE_Vacuum ){
101645
+ /* This INSERT command is part of a VACUUM operation, which guarantees
101646
+ ** that the destination table is empty. If all indexed columns use
101647
+ ** collation sequence BINARY, then it can also be assumed that the
101648
+ ** index will be populated by inserting keys in strictly sorted
101649
+ ** order. In this case, instead of seeking within the b-tree as part
101650
+ ** of every OP_IdxInsert opcode, an OP_Last is added before the
101651
+ ** OP_IdxInsert to seek to the point within the b-tree where each key
101652
+ ** should be inserted. This is faster.
101653
+ **
101654
+ ** If any of the indexed columns use a collation sequence other than
101655
+ ** BINARY, this optimization is disabled. This is because the user
101656
+ ** might change the definition of a collation sequence and then run
101657
+ ** a VACUUM command. In that case keys may not be written in strictly
101658
+ ** sorted order. */
101659
+ for(i=0; i<pSrcIdx->nColumn; i++){
101660
+ char *zColl = pSrcIdx->azColl[i];
101661
+ assert( zColl!=0 );
101662
+ if( sqlite3_stricmp("BINARY", zColl) ) break;
101663
+ }
101664
+ if( i==pSrcIdx->nColumn ){
101665
+ useSeekResult = OPFLAG_USESEEKRESULT;
101666
+ sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
101667
+ }
101668
+ }
101271101669
sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
101670
+ sqlite3VdbeChangeP5(v, useSeekResult);
101272101671
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101273101672
sqlite3VdbeJumpHere(v, addr1);
101274101673
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101275101674
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101276101675
}
@@ -102385,11 +102784,11 @@
102385102784
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102386102785
char *zErrmsg = 0;
102387102786
const char *zEntry;
102388102787
char *zAltEntry = 0;
102389102788
void **aHandle;
102390
- int nMsg = 300 + sqlite3Strlen30(zFile);
102789
+ u64 nMsg = 300 + sqlite3Strlen30(zFile);
102391102790
int ii;
102392102791
102393102792
/* Shared library endings to try if zFile cannot be loaded as written */
102394102793
static const char *azEndings[] = {
102395102794
#if SQLITE_OS_WIN
@@ -102428,11 +102827,11 @@
102428102827
sqlite3_free(zAltFile);
102429102828
}
102430102829
#endif
102431102830
if( handle==0 ){
102432102831
if( pzErrMsg ){
102433
- *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102832
+ *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102434102833
if( zErrmsg ){
102435102834
sqlite3_snprintf(nMsg, zErrmsg,
102436102835
"unable to open shared library [%s]", zFile);
102437102836
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102438102837
}
@@ -102454,11 +102853,11 @@
102454102853
** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102455102854
*/
102456102855
if( xInit==0 && zProc==0 ){
102457102856
int iFile, iEntry, c;
102458102857
int ncFile = sqlite3Strlen30(zFile);
102459
- zAltEntry = sqlite3_malloc(ncFile+30);
102858
+ zAltEntry = sqlite3_malloc64(ncFile+30);
102460102859
if( zAltEntry==0 ){
102461102860
sqlite3OsDlClose(pVfs, handle);
102462102861
return SQLITE_NOMEM;
102463102862
}
102464102863
memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102875,11 @@
102476102875
sqlite3OsDlSym(pVfs, handle, zEntry);
102477102876
}
102478102877
if( xInit==0 ){
102479102878
if( pzErrMsg ){
102480102879
nMsg += sqlite3Strlen30(zEntry);
102481
- *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102880
+ *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102482102881
if( zErrmsg ){
102483102882
sqlite3_snprintf(nMsg, zErrmsg,
102484102883
"no entry point [%s] in shared library [%s]", zEntry, zFile);
102485102884
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102486102885
}
@@ -102575,11 +102974,11 @@
102575102974
** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102576102975
** mutex must be held while accessing this list.
102577102976
*/
102578102977
typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102579102978
static SQLITE_WSD struct sqlite3AutoExtList {
102580
- int nExt; /* Number of entries in aExt[] */
102979
+ u32 nExt; /* Number of entries in aExt[] */
102581102980
void (**aExt)(void); /* Pointers to the extension init functions */
102582102981
} sqlite3Autoext = { 0, 0 };
102583102982
102584102983
/* The "wsdAutoext" macro will resolve to the autoextension
102585102984
** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103007,23 @@
102608103007
if( rc ){
102609103008
return rc;
102610103009
}else
102611103010
#endif
102612103011
{
102613
- int i;
103012
+ u32 i;
102614103013
#if SQLITE_THREADSAFE
102615103014
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
102616103015
#endif
102617103016
wsdAutoextInit;
102618103017
sqlite3_mutex_enter(mutex);
102619103018
for(i=0; i<wsdAutoext.nExt; i++){
102620103019
if( wsdAutoext.aExt[i]==xInit ) break;
102621103020
}
102622103021
if( i==wsdAutoext.nExt ){
102623
- int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
103022
+ u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
102624103023
void (**aNew)(void);
102625
- aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
103024
+ aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
102626103025
if( aNew==0 ){
102627103026
rc = SQLITE_NOMEM;
102628103027
}else{
102629103028
wsdAutoext.aExt = aNew;
102630103029
wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103051,11 @@
102652103051
#endif
102653103052
int i;
102654103053
int n = 0;
102655103054
wsdAutoextInit;
102656103055
sqlite3_mutex_enter(mutex);
102657
- for(i=wsdAutoext.nExt-1; i>=0; i--){
103056
+ for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
102658103057
if( wsdAutoext.aExt[i]==xInit ){
102659103058
wsdAutoext.nExt--;
102660103059
wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
102661103060
n++;
102662103061
break;
@@ -102690,11 +103089,11 @@
102690103089
** Load all automatic extensions.
102691103090
**
102692103091
** If anything goes wrong, set an error in the database connection.
102693103092
*/
102694103093
SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
102695
- int i;
103094
+ u32 i;
102696103095
int go = 1;
102697103096
int rc;
102698103097
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102699103098
102700103099
wsdAutoextInit;
@@ -103354,19 +103753,19 @@
103354103753
/*
103355103754
** Generate code to return a single integer value.
103356103755
*/
103357103756
static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103358103757
Vdbe *v = sqlite3GetVdbe(pParse);
103359
- int mem = ++pParse->nMem;
103758
+ int nMem = ++pParse->nMem;
103360103759
i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103361103760
if( pI64 ){
103362103761
memcpy(pI64, &value, sizeof(value));
103363103762
}
103364
- sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
103763
+ sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
103365103764
sqlite3VdbeSetNumCols(v, 1);
103366103765
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103367
- sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103766
+ sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103368103767
}
103369103768
103370103769
103371103770
/*
103372103771
** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103926,15 @@
103527103926
aFcntl[3] = 0;
103528103927
db->busyHandler.nBusy = 0;
103529103928
rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103530103929
if( rc==SQLITE_OK ){
103531103930
if( aFcntl[0] ){
103532
- int mem = ++pParse->nMem;
103533
- sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
103931
+ int nMem = ++pParse->nMem;
103932
+ sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
103534103933
sqlite3VdbeSetNumCols(v, 1);
103535103934
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103536
- sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103935
+ sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103537103936
sqlite3_free(aFcntl[0]);
103538103937
}
103539103938
goto pragma_out;
103540103939
}
103541103940
if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104535,13 @@
104136104535
}else{
104137104536
if( !db->autoCommit ){
104138104537
sqlite3ErrorMsg(pParse,
104139104538
"Safety level may not be changed inside a transaction");
104140104539
}else{
104141
- pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
104540
+ int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
104541
+ if( iLevel==0 ) iLevel = 1;
104542
+ pDb->safety_level = iLevel;
104142104543
setAllPagerFlags(db);
104143104544
}
104144104545
}
104145104546
break;
104146104547
}
@@ -104231,11 +104632,11 @@
104231104632
if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104232104633
k = 0;
104233104634
}else if( pPk==0 ){
104234104635
k = 1;
104235104636
}else{
104236
- for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
104637
+ for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
104237104638
}
104238104639
sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104239104640
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104240104641
}
104241104642
}
@@ -105237,11 +105638,11 @@
105237105638
105238105639
assert( iDb>=0 && iDb<db->nDb );
105239105640
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105240105641
if( argv[1]==0 ){
105241105642
corruptSchema(pData, argv[0], 0);
105242
- }else if( argv[2] && argv[2][0] ){
105643
+ }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){
105243105644
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105244105645
** But because db->init.busy is set to 1, no VDBE code is generated
105245105646
** or executed. All the parser does is build the internal data
105246105647
** structures that describe the table, index, or view.
105247105648
*/
@@ -105268,12 +105669,12 @@
105268105669
corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105269105670
}
105270105671
}
105271105672
}
105272105673
sqlite3_finalize(pStmt);
105273
- }else if( argv[0]==0 ){
105274
- corruptSchema(pData, 0, 0);
105674
+ }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
105675
+ corruptSchema(pData, argv[0], 0);
105275105676
}else{
105276105677
/* If the SQL column is blank it means this is an index that
105277105678
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105278105679
** constraint for a CREATE TABLE. The index should have already
105279105680
** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106577,10 @@
106176106577
){
106177106578
Select *pNew;
106178106579
Select standin;
106179106580
sqlite3 *db = pParse->db;
106180106581
pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
106181
- assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
106182106582
if( pNew==0 ){
106183106583
assert( db->mallocFailed );
106184106584
pNew = &standin;
106185106585
memset(pNew, 0, sizeof(*pNew));
106186106586
}
@@ -106196,11 +106596,11 @@
106196106596
pNew->pOrderBy = pOrderBy;
106197106597
pNew->selFlags = selFlags;
106198106598
pNew->op = TK_SELECT;
106199106599
pNew->pLimit = pLimit;
106200106600
pNew->pOffset = pOffset;
106201
- assert( pOffset==0 || pLimit!=0 );
106601
+ assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
106202106602
pNew->addrOpenEphm[0] = -1;
106203106603
pNew->addrOpenEphm[1] = -1;
106204106604
if( db->mallocFailed ) {
106205106605
clearSelect(db, pNew, pNew!=&standin);
106206106606
pNew = 0;
@@ -107446,11 +107846,11 @@
107446107846
if( pS ){
107447107847
/* The "table" is actually a sub-select or a view in the FROM clause
107448107848
** of the SELECT statement. Return the declaration type and origin
107449107849
** data for the result-set column of the sub-select.
107450107850
*/
107451
- if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
107851
+ if( iCol>=0 && iCol<pS->pEList->nExpr ){
107452107852
/* If iCol is less than zero, then the expression requests the
107453107853
** rowid of the sub-select or view. This expression is legal (see
107454107854
** test case misc2.2.2) - it always evaluates to NULL.
107455107855
*/
107456107856
NameContext sNC;
@@ -107766,16 +108166,18 @@
107766108166
memset(&sNC, 0, sizeof(sNC));
107767108167
sNC.pSrcList = pSelect->pSrc;
107768108168
a = pSelect->pEList->a;
107769108169
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
107770108170
p = a[i].pExpr;
107771
- pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108171
+ if( pCol->zType==0 ){
108172
+ pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108173
+ }
107772108174
szAll += pCol->szEst;
107773108175
pCol->affinity = sqlite3ExprAffinity(p);
107774108176
if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
107775108177
pColl = sqlite3ExprCollSeq(pParse, p);
107776
- if( pColl ){
108178
+ if( pColl && pCol->zColl==0 ){
107777108179
pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
107778108180
}
107779108181
}
107780108182
pTab->szTabRow = sqlite3LogEst(szAll*4);
107781108183
}
@@ -108173,12 +108575,11 @@
108173108575
){
108174108576
Select *pPrior;
108175108577
int nExpr = p->pEList->nExpr;
108176108578
int nRow = 1;
108177108579
int rc = 0;
108178
- assert( p->pNext==0 );
108179
- assert( p->selFlags & SF_AllValues );
108580
+ assert( p->selFlags & SF_MultiValue );
108180108581
do{
108181108582
assert( p->selFlags & SF_Values );
108182108583
assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108183108584
assert( p->pLimit==0 );
108184108585
assert( p->pOffset==0 );
@@ -108283,11 +108684,11 @@
108283108684
dest.eDest = SRT_Table;
108284108685
}
108285108686
108286108687
/* Special handling for a compound-select that originates as a VALUES clause.
108287108688
*/
108288
- if( p->selFlags & SF_AllValues ){
108689
+ if( p->selFlags & SF_MultiValue ){
108289108690
rc = multiSelectValues(pParse, p, &dest);
108290108691
goto multi_select_end;
108291108692
}
108292108693
108293108694
/* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109069,11 @@
108668109069
** then there should be a single item on the stack. Write this
108669109070
** item into the set table with bogus data.
108670109071
*/
108671109072
case SRT_Set: {
108672109073
int r1;
108673
- assert( pIn->nSdst==1 );
109074
+ assert( pIn->nSdst==1 || pParse->nErr>0 );
108674109075
pDest->affSdst =
108675109076
sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
108676109077
r1 = sqlite3GetTempReg(pParse);
108677109078
sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
108678109079
sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109095,11 @@
108694109095
/* If this is a scalar select that is part of an expression, then
108695109096
** store the results in the appropriate memory cell and break out
108696109097
** of the scan loop.
108697109098
*/
108698109099
case SRT_Mem: {
108699
- assert( pIn->nSdst==1 );
109100
+ assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 );
108700109101
sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
108701109102
/* The LIMIT clause will jump out of the loop for us */
108702109103
break;
108703109104
}
108704109105
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109110,11 @@
108709109110
case SRT_Coroutine: {
108710109111
if( pDest->iSdst==0 ){
108711109112
pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
108712109113
pDest->nSdst = pIn->nSdst;
108713109114
}
108714
- sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
109115
+ sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
108715109116
sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108716109117
break;
108717109118
}
108718109119
108719109120
/* If none of the above, then the result destination must be
@@ -108925,12 +109326,14 @@
108925109326
*/
108926109327
aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
108927109328
if( aPermute ){
108928109329
struct ExprList_item *pItem;
108929109330
for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
108930
- assert( pItem->u.x.iOrderByCol>0
108931
- && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
109331
+ assert( pItem->u.x.iOrderByCol>0 );
109332
+ /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true
109333
+ ** but only for well-formed SELECT statements. */
109334
+ testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr );
108932109335
aPermute[i] = pItem->u.x.iOrderByCol - 1;
108933109336
}
108934109337
pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
108935109338
}else{
108936109339
pKeyMerge = 0;
@@ -109136,11 +109539,11 @@
109136109539
pPrior->pNext = p;
109137109540
109138109541
/*** TBD: Insert subroutine calls to close cursors on incomplete
109139109542
**** subqueries ****/
109140109543
explainComposite(pParse, p->op, iSub1, iSub2, 0);
109141
- return SQLITE_OK;
109544
+ return pParse->nErr!=0;
109142109545
}
109143109546
#endif
109144109547
109145109548
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109146109549
/* Forward Declarations */
@@ -109948,10 +110351,11 @@
109948110351
pNew->pGroupBy = 0;
109949110352
pNew->pHaving = 0;
109950110353
pNew->pOrderBy = 0;
109951110354
p->pPrior = 0;
109952110355
p->pNext = 0;
110356
+ p->pWith = 0;
109953110357
p->selFlags &= ~SF_Compound;
109954110358
assert( (p->selFlags & SF_Converted)==0 );
109955110359
p->selFlags |= SF_Converted;
109956110360
assert( pNew->pPrior!=0 );
109957110361
pNew->pPrior->pNext = pNew;
@@ -110486,11 +110890,11 @@
110486110890
if( pParse->hasCompound ){
110487110891
w.xSelectCallback = convertCompoundSelectToSubquery;
110488110892
sqlite3WalkSelect(&w, pSelect);
110489110893
}
110490110894
w.xSelectCallback = selectExpander;
110491
- if( (pSelect->selFlags & SF_AllValues)==0 ){
110895
+ if( (pSelect->selFlags & SF_MultiValue)==0 ){
110492110896
w.xSelectCallback2 = selectPopWith;
110493110897
}
110494110898
sqlite3WalkSelect(&w, pSelect);
110495110899
}
110496110900
@@ -110672,11 +111076,12 @@
110672111076
nArg = 0;
110673111077
regAgg = 0;
110674111078
}
110675111079
if( pF->iDistinct>=0 ){
110676111080
addrNext = sqlite3VdbeMakeLabel(v);
110677
- assert( nArg==1 );
111081
+ testcase( nArg==0 ); /* Error condition */
111082
+ testcase( nArg>1 ); /* Also an error */
110678111083
codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
110679111084
}
110680111085
if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
110681111086
CollSeq *pColl = 0;
110682111087
struct ExprList_item *pItem;
@@ -111547,14 +111952,13 @@
111547111952
111548111953
/* Jump here to skip this query
111549111954
*/
111550111955
sqlite3VdbeResolveLabel(v, iEnd);
111551111956
111552
- /* The SELECT was successfully coded. Set the return code to 0
111553
- ** to indicate no errors.
111554
- */
111555
- rc = 0;
111957
+ /* The SELECT has been coded. If there is an error in the Parse structure,
111958
+ ** set the return code to 1. Otherwise 0. */
111959
+ rc = (pParse->nErr>0);
111556111960
111557111961
/* Control jumps to here if an error is encountered above, or upon
111558111962
** successful coding of the SELECT.
111559111963
*/
111560111964
select_end:
@@ -111601,11 +112005,11 @@
111601112005
sqlite3TreeViewLine(pView, "FROM");
111602112006
for(i=0; i<p->pSrc->nSrc; i++){
111603112007
struct SrcList_item *pItem = &p->pSrc->a[i];
111604112008
StrAccum x;
111605112009
char zLine[100];
111606
- sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
112010
+ sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
111607112011
sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
111608112012
if( pItem->zDatabase ){
111609112013
sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
111610112014
}else if( pItem->zName ){
111611112015
sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112164,11 @@
111760112164
for(i=0; i<nCol; i++){
111761112165
if( argv[i]==0 ){
111762112166
z = 0;
111763112167
}else{
111764112168
int n = sqlite3Strlen30(argv[i])+1;
111765
- z = sqlite3_malloc( n );
112169
+ z = sqlite3_malloc64( n );
111766112170
if( z==0 ) goto malloc_failed;
111767112171
memcpy(z, argv[i], n);
111768112172
}
111769112173
p->azResult[p->nData++] = z;
111770112174
}
@@ -111809,11 +112213,11 @@
111809112213
res.nRow = 0;
111810112214
res.nColumn = 0;
111811112215
res.nData = 1;
111812112216
res.nAlloc = 20;
111813112217
res.rc = SQLITE_OK;
111814
- res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc );
112218
+ res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
111815112219
if( res.azResult==0 ){
111816112220
db->errCode = SQLITE_NOMEM;
111817112221
return SQLITE_NOMEM;
111818112222
}
111819112223
res.azResult[0] = 0;
@@ -111837,11 +112241,11 @@
111837112241
sqlite3_free_table(&res.azResult[1]);
111838112242
return rc;
111839112243
}
111840112244
if( res.nAlloc>res.nData ){
111841112245
char **azNew;
111842
- azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData );
112246
+ azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData );
111843112247
if( azNew==0 ){
111844112248
sqlite3_free_table(&res.azResult[1]);
111845112249
db->errCode = SQLITE_NOMEM;
111846112250
return SQLITE_NOMEM;
111847112251
}
@@ -112065,11 +112469,10 @@
112065112469
}
112066112470
112067112471
/* Do not create a trigger on a system table */
112068112472
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112069112473
sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
112070
- pParse->nErr++;
112071112474
goto trigger_cleanup;
112072112475
}
112073112476
112074112477
/* INSTEAD of triggers are only for views and views only support INSTEAD
112075112478
** of triggers.
@@ -112245,16 +112648,16 @@
112245112648
u8 op, /* Trigger opcode */
112246112649
Token *pName /* The target name */
112247112650
){
112248112651
TriggerStep *pTriggerStep;
112249112652
112250
- pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
112653
+ pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
112251112654
if( pTriggerStep ){
112252112655
char *z = (char*)&pTriggerStep[1];
112253112656
memcpy(z, pName->z, pName->n);
112254
- pTriggerStep->target.z = z;
112255
- pTriggerStep->target.n = pName->n;
112657
+ sqlite3Dequote(z);
112658
+ pTriggerStep->zTarget = z;
112256112659
pTriggerStep->op = op;
112257112660
}
112258112661
return pTriggerStep;
112259112662
}
112260112663
@@ -112533,11 +112936,11 @@
112533112936
}
112534112937
return (mask ? pList : 0);
112535112938
}
112536112939
112537112940
/*
112538
-** Convert the pStep->target token into a SrcList and return a pointer
112941
+** Convert the pStep->zTarget string into a SrcList and return a pointer
112539112942
** to that SrcList.
112540112943
**
112541112944
** This routine adds a specific database name, if needed, to the target when
112542112945
** forming the SrcList. This prevents a trigger in one database from
112543112946
** referring to a target in another database. An exception is when the
@@ -112546,21 +112949,21 @@
112546112949
*/
112547112950
static SrcList *targetSrcList(
112548112951
Parse *pParse, /* The parsing context */
112549112952
TriggerStep *pStep /* The trigger containing the target token */
112550112953
){
112954
+ sqlite3 *db = pParse->db;
112551112955
int iDb; /* Index of the database to use */
112552112956
SrcList *pSrc; /* SrcList to be returned */
112553112957
112554
- pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
112958
+ pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112555112959
if( pSrc ){
112556112960
assert( pSrc->nSrc>0 );
112557
- assert( pSrc->a!=0 );
112558
- iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
112961
+ pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
112962
+ iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
112559112963
if( iDb==0 || iDb>=2 ){
112560
- sqlite3 *db = pParse->db;
112561
- assert( iDb<pParse->db->nDb );
112964
+ assert( iDb<db->nDb );
112562112965
pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112563112966
}
112564112967
}
112565112968
return pSrc;
112566112969
}
@@ -112668,10 +113071,11 @@
112668113071
assert( pFrom->zErrMsg==0 || pFrom->nErr );
112669113072
assert( pTo->zErrMsg==0 || pTo->nErr );
112670113073
if( pTo->nErr==0 ){
112671113074
pTo->zErrMsg = pFrom->zErrMsg;
112672113075
pTo->nErr = pFrom->nErr;
113076
+ pTo->rc = pFrom->rc;
112673113077
}else{
112674113078
sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
112675113079
}
112676113080
}
112677113081
@@ -114018,17 +114422,21 @@
114018114422
114019114423
/* Loop through the tables in the main database. For each, do
114020114424
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114021114425
** the contents to the temporary database.
114022114426
*/
114427
+ assert( (db->flags & SQLITE_Vacuum)==0 );
114428
+ db->flags |= SQLITE_Vacuum;
114023114429
rc = execExecSql(db, pzErrMsg,
114024114430
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114025114431
"|| ' SELECT * FROM main.' || quote(name) || ';'"
114026114432
"FROM main.sqlite_master "
114027114433
"WHERE type = 'table' AND name!='sqlite_sequence' "
114028114434
" AND coalesce(rootpage,1)>0"
114029114435
);
114436
+ assert( (db->flags & SQLITE_Vacuum)!=0 );
114437
+ db->flags &= ~SQLITE_Vacuum;
114030114438
if( rc!=SQLITE_OK ) goto end_of_vacuum;
114031114439
114032114440
/* Copy over the sequence table
114033114441
*/
114034114442
rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114571,12 @@
114163114571
** are invoked only from within xCreate and xConnect methods.
114164114572
*/
114165114573
struct VtabCtx {
114166114574
VTable *pVTable; /* The virtual table being constructed */
114167114575
Table *pTab; /* The Table object to which the virtual table belongs */
114576
+ VtabCtx *pPrior; /* Parent context (if any) */
114577
+ int bDeclared; /* True after sqlite3_declare_vtab() is called */
114168114578
};
114169114579
114170114580
/*
114171114581
** The actual function that does the work of creating a new module.
114172114582
** This function implements the sqlite3_create_module() and
@@ -114609,11 +115019,11 @@
114609115019
Token *pArg = &pParse->sArg;
114610115020
if( pArg->z==0 ){
114611115021
pArg->z = p->z;
114612115022
pArg->n = p->n;
114613115023
}else{
114614
- assert(pArg->z < p->z);
115024
+ assert(pArg->z <= p->z);
114615115025
pArg->n = (int)(&p->z[p->n] - pArg->z);
114616115026
}
114617115027
}
114618115028
114619115029
/*
@@ -114626,19 +115036,31 @@
114626115036
Table *pTab,
114627115037
Module *pMod,
114628115038
int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
114629115039
char **pzErr
114630115040
){
114631
- VtabCtx sCtx, *pPriorCtx;
115041
+ VtabCtx sCtx;
114632115042
VTable *pVTable;
114633115043
int rc;
114634115044
const char *const*azArg = (const char *const*)pTab->azModuleArg;
114635115045
int nArg = pTab->nModuleArg;
114636115046
char *zErr = 0;
114637
- char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
115047
+ char *zModuleName;
114638115048
int iDb;
115049
+ VtabCtx *pCtx;
114639115050
115051
+ /* Check that the virtual-table is not already being initialized */
115052
+ for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
115053
+ if( pCtx->pTab==pTab ){
115054
+ *pzErr = sqlite3MPrintf(db,
115055
+ "vtable constructor called recursively: %s", pTab->zName
115056
+ );
115057
+ return SQLITE_LOCKED;
115058
+ }
115059
+ }
115060
+
115061
+ zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
114640115062
if( !zModuleName ){
114641115063
return SQLITE_NOMEM;
114642115064
}
114643115065
114644115066
pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115077,17 @@
114655115077
/* Invoke the virtual table constructor */
114656115078
assert( &db->pVtabCtx );
114657115079
assert( xConstruct );
114658115080
sCtx.pTab = pTab;
114659115081
sCtx.pVTable = pVTable;
114660
- pPriorCtx = db->pVtabCtx;
115082
+ sCtx.pPrior = db->pVtabCtx;
115083
+ sCtx.bDeclared = 0;
114661115084
db->pVtabCtx = &sCtx;
114662115085
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
114663
- db->pVtabCtx = pPriorCtx;
115086
+ db->pVtabCtx = sCtx.pPrior;
114664115087
if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
115088
+ assert( sCtx.pTab==pTab );
114665115089
114666115090
if( SQLITE_OK!=rc ){
114667115091
if( zErr==0 ){
114668115092
*pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
114669115093
}else {
@@ -114675,17 +115099,18 @@
114675115099
/* Justification of ALWAYS(): A correct vtab constructor must allocate
114676115100
** the sqlite3_vtab object if successful. */
114677115101
memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
114678115102
pVTable->pVtab->pModule = pMod->pModule;
114679115103
pVTable->nRef = 1;
114680
- if( sCtx.pTab ){
115104
+ if( sCtx.bDeclared==0 ){
114681115105
const char *zFormat = "vtable constructor did not declare schema: %s";
114682115106
*pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
114683115107
sqlite3VtabUnlock(pVTable);
114684115108
rc = SQLITE_ERROR;
114685115109
}else{
114686115110
int iCol;
115111
+ u8 oooHidden = 0;
114687115112
/* If everything went according to plan, link the new VTable structure
114688115113
** into the linked list headed by pTab->pVTable. Then loop through the
114689115114
** columns of the table to see if any of them contain the token "hidden".
114690115115
** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
114691115116
** the type string. */
@@ -114694,11 +115119,14 @@
114694115119
114695115120
for(iCol=0; iCol<pTab->nCol; iCol++){
114696115121
char *zType = pTab->aCol[iCol].zType;
114697115122
int nType;
114698115123
int i = 0;
114699
- if( !zType ) continue;
115124
+ if( !zType ){
115125
+ pTab->tabFlags |= oooHidden;
115126
+ continue;
115127
+ }
114700115128
nType = sqlite3Strlen30(zType);
114701115129
if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
114702115130
for(i=0; i<nType; i++){
114703115131
if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
114704115132
&& (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115145,13 @@
114717115145
if( zType[i]=='\0' && i>0 ){
114718115146
assert(zType[i-1]==' ');
114719115147
zType[i-1] = '\0';
114720115148
}
114721115149
pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
115150
+ oooHidden = TF_OOOHidden;
115151
+ }else{
115152
+ pTab->tabFlags |= oooHidden;
114722115153
}
114723115154
}
114724115155
}
114725115156
}
114726115157
@@ -114845,12 +115276,12 @@
114845115276
** This function is used to set the schema of a virtual table. It is only
114846115277
** valid to call this function from within the xCreate() or xConnect() of a
114847115278
** virtual table module.
114848115279
*/
114849115280
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
115281
+ VtabCtx *pCtx;
114850115282
Parse *pParse;
114851
-
114852115283
int rc = SQLITE_OK;
114853115284
Table *pTab;
114854115285
char *zErr = 0;
114855115286
114856115287
#ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115288,17 @@
114857115288
if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114858115289
return SQLITE_MISUSE_BKPT;
114859115290
}
114860115291
#endif
114861115292
sqlite3_mutex_enter(db->mutex);
114862
- if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
115293
+ pCtx = db->pVtabCtx;
115294
+ if( !pCtx || pCtx->bDeclared ){
114863115295
sqlite3Error(db, SQLITE_MISUSE);
114864115296
sqlite3_mutex_leave(db->mutex);
114865115297
return SQLITE_MISUSE_BKPT;
114866115298
}
115299
+ pTab = pCtx->pTab;
114867115300
assert( (pTab->tabFlags & TF_Virtual)!=0 );
114868115301
114869115302
pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
114870115303
if( pParse==0 ){
114871115304
rc = SQLITE_NOMEM;
@@ -114884,11 +115317,11 @@
114884115317
pTab->aCol = pParse->pNewTable->aCol;
114885115318
pTab->nCol = pParse->pNewTable->nCol;
114886115319
pParse->pNewTable->nCol = 0;
114887115320
pParse->pNewTable->aCol = 0;
114888115321
}
114889
- db->pVtabCtx->pTab = 0;
115322
+ pCtx->bDeclared = 1;
114890115323
}else{
114891115324
sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
114892115325
sqlite3DbFree(db, zErr);
114893115326
rc = SQLITE_ERROR;
114894115327
}
@@ -115078,11 +115511,11 @@
115078115511
*/
115079115512
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115080115513
int rc = SQLITE_OK;
115081115514
115082115515
assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115083
- assert( iSavepoint>=0 );
115516
+ assert( iSavepoint>=-1 );
115084115517
if( db->aVTrans ){
115085115518
int i;
115086115519
for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115087115520
VTable *pVTab = db->aVTrans[i];
115088115521
const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115629,11 @@
115196115629
assert( IsVirtual(pTab) );
115197115630
for(i=0; i<pToplevel->nVtabLock; i++){
115198115631
if( pTab==pToplevel->apVtabLock[i] ) return;
115199115632
}
115200115633
n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115201
- apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n);
115634
+ apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n);
115202115635
if( apVtabLock ){
115203115636
pToplevel->apVtabLock = apVtabLock;
115204115637
pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115205115638
}else{
115206115639
pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116428,18 @@
115995116428
** In the previous sentence and in the diagram, "slot[]" refers to
115996116429
** the WhereClause.a[] array. The slot[] array grows as needed to contain
115997116430
** all terms of the WHERE clause.
115998116431
*/
115999116432
static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
116433
+ Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
116000116434
pWC->op = op;
116001
- if( pExpr==0 ) return;
116002
- if( pExpr->op!=op ){
116435
+ if( pE2==0 ) return;
116436
+ if( pE2->op!=op ){
116003116437
whereClauseInsert(pWC, pExpr, 0);
116004116438
}else{
116005
- whereSplit(pWC, pExpr->pLeft, op);
116006
- whereSplit(pWC, pExpr->pRight, op);
116439
+ whereSplit(pWC, pE2->pLeft, op);
116440
+ whereSplit(pWC, pE2->pRight, op);
116007116441
}
116008116442
}
116009116443
116010116444
/*
116011116445
** Initialize a WhereMaskSet object
@@ -117272,11 +117706,11 @@
117272117706
if( p->op==TK_COLUMN
117273117707
&& p->iColumn==pIdx->aiColumn[iCol]
117274117708
&& p->iTable==iBase
117275117709
){
117276117710
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117277
- if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117711
+ if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117278117712
return i;
117279117713
}
117280117714
}
117281117715
}
117282117716
@@ -117546,11 +117980,11 @@
117546117980
if( (idxCols & cMask)==0 ){
117547117981
Expr *pX = pTerm->pExpr;
117548117982
idxCols |= cMask;
117549117983
pIdx->aiColumn[n] = pTerm->u.leftColumn;
117550117984
pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117551
- pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY";
117985
+ pIdx->azColl[n] = pColl ? pColl->zName : "BINARY";
117552117986
n++;
117553117987
}
117554117988
}
117555117989
}
117556117990
assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119276,11 @@
118842119276
118843119277
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
118844119278
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
118845119279
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
118846119280
118847
- sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118848
- str.db = db;
119281
+ sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118849119282
sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
118850119283
if( pItem->pSelect ){
118851119284
sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
118852119285
}else{
118853119286
sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120475,17 @@
120042120475
/*
120043120476
** Free a WhereInfo structure
120044120477
*/
120045120478
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120046120479
if( ALWAYS(pWInfo) ){
120480
+ int i;
120481
+ for(i=0; i<pWInfo->nLevel; i++){
120482
+ WhereLevel *pLevel = &pWInfo->a[i];
120483
+ if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
120484
+ sqlite3DbFree(db, pLevel->u.in.aInLoop);
120485
+ }
120486
+ }
120047120487
whereClauseClear(&pWInfo->sWC);
120048120488
while( pWInfo->pLoops ){
120049120489
WhereLoop *p = pWInfo->pLoops;
120050120490
pWInfo->pLoops = p->pNextLoop;
120051120491
whereLoopDelete(db, p);
@@ -120521,11 +120961,11 @@
120521120961
** changes "x IN (?)" into "x=?". */
120522120962
120523120963
}else if( eOp & (WO_EQ) ){
120524120964
pNew->wsFlags |= WHERE_COLUMN_EQ;
120525120965
if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120526
- if( iCol>=0 && !IsUniqueIndex(pProbe) ){
120966
+ if( iCol>=0 && pProbe->uniqNotNull==0 ){
120527120967
pNew->wsFlags |= WHERE_UNQ_WANTED;
120528120968
}else{
120529120969
pNew->wsFlags |= WHERE_ONEROW;
120530120970
}
120531120971
}
@@ -121981,11 +122421,11 @@
121981122421
pWInfo->nOBSat = pFrom->isOrdered;
121982122422
if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
121983122423
pWInfo->revMask = pFrom->revLoop;
121984122424
}
121985122425
if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
121986
- && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
122426
+ && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
121987122427
){
121988122428
Bitmask revMask = 0;
121989122429
int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
121990122430
pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
121991122431
);
@@ -122386,11 +122826,10 @@
122386122826
if( pParse->nErr || NEVER(db->mallocFailed) ){
122387122827
goto whereBeginError;
122388122828
}
122389122829
#ifdef WHERETRACE_ENABLED /* !=0 */
122390122830
if( sqlite3WhereTrace ){
122391
- int ii;
122392122831
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122393122832
if( pWInfo->nOBSat>0 ){
122394122833
sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122395122834
}
122396122835
switch( pWInfo->eDistinct ){
@@ -122639,11 +123078,10 @@
122639123078
VdbeCoverage(v);
122640123079
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
122641123080
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
122642123081
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
122643123082
}
122644
- sqlite3DbFree(db, pLevel->u.in.aInLoop);
122645123083
}
122646123084
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
122647123085
if( pLevel->addrSkip ){
122648123086
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
122649123087
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123288,32 @@
122850123288
/*
122851123289
** An instance of this structure holds the ATTACH key and the key type.
122852123290
*/
122853123291
struct AttachKey { int type; Token key; };
122854123292
123293
+
123294
+ /*
123295
+ ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
123296
+ ** all elements in the list. And make sure list length does not exceed
123297
+ ** SQLITE_LIMIT_COMPOUND_SELECT.
123298
+ */
123299
+ static void parserDoubleLinkSelect(Parse *pParse, Select *p){
123300
+ if( p->pPrior ){
123301
+ Select *pNext = 0, *pLoop;
123302
+ int mxSelect, cnt = 0;
123303
+ for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123304
+ pLoop->pNext = pNext;
123305
+ pLoop->selFlags |= SF_Compound;
123306
+ }
123307
+ if( (p->selFlags & SF_MultiValue)==0 &&
123308
+ (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
123309
+ cnt>mxSelect
123310
+ ){
123311
+ sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123312
+ }
123313
+ }
123314
+ }
122855123315
122856123316
/* This is a utility routine used to set the ExprSpan.zStart and
122857123317
** ExprSpan.zEnd values of pOut so that the span covers the complete
122858123318
** range of text beginning with pStart and going to the end of pEnd.
122859123319
*/
@@ -125167,31 +125627,14 @@
125167125627
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125168125628
}
125169125629
break;
125170125630
case 112: /* select ::= with selectnowith */
125171125631
{
125172
- Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
125632
+ Select *p = yymsp[0].minor.yy3;
125173125633
if( p ){
125174
- int cnt = 0, mxSelect;
125175125634
p->pWith = yymsp[-1].minor.yy59;
125176
- if( p->pPrior ){
125177
- u16 allValues = SF_Values;
125178
- pNext = 0;
125179
- for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
125180
- pLoop->pNext = pNext;
125181
- pLoop->selFlags |= SF_Compound;
125182
- allValues &= pLoop->selFlags;
125183
- }
125184
- if( allValues ){
125185
- p->selFlags |= SF_AllValues;
125186
- }else if(
125187
- (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
125188
- && cnt>mxSelect
125189
- ){
125190
- sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
125191
- }
125192
- }
125635
+ parserDoubleLinkSelect(pParse, p);
125193125636
}else{
125194125637
sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125195125638
}
125196125639
yygotominor.yy3 = p;
125197125640
}
@@ -125205,16 +125648,18 @@
125205125648
Select *pRhs = yymsp[0].minor.yy3;
125206125649
if( pRhs && pRhs->pPrior ){
125207125650
SrcList *pFrom;
125208125651
Token x;
125209125652
x.n = 0;
125653
+ parserDoubleLinkSelect(pParse, pRhs);
125210125654
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125211125655
pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125212125656
}
125213125657
if( pRhs ){
125214125658
pRhs->op = (u8)yymsp[-1].minor.yy328;
125215125659
pRhs->pPrior = yymsp[-2].minor.yy3;
125660
+ pRhs->selFlags &= ~SF_MultiValue;
125216125661
if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125217125662
}else{
125218125663
sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125219125664
}
125220125665
yygotominor.yy3 = pRhs;
@@ -125257,17 +125702,20 @@
125257125702
yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125258125703
}
125259125704
break;
125260125705
case 121: /* values ::= values COMMA LP exprlist RP */
125261125706
{
125262
- Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125707
+ Select *pRight, *pLeft = yymsp[-4].minor.yy3;
125708
+ pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
125709
+ if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
125263125710
if( pRight ){
125264125711
pRight->op = TK_ALL;
125265
- pRight->pPrior = yymsp[-4].minor.yy3;
125712
+ pLeft = yymsp[-4].minor.yy3;
125713
+ pRight->pPrior = pLeft;
125266125714
yygotominor.yy3 = pRight;
125267125715
}else{
125268
- yygotominor.yy3 = yymsp[-4].minor.yy3;
125716
+ yygotominor.yy3 = pLeft;
125269125717
}
125270125718
}
125271125719
break;
125272125720
case 122: /* distinct ::= DISTINCT */
125273125721
{yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127515,12 @@
127067127515
goto abort_parse;
127068127516
}
127069127517
break;
127070127518
}
127071127519
case TK_ILLEGAL: {
127072
- sqlite3DbFree(db, *pzErrMsg);
127073
- *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
127520
+ sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
127074127521
&pParse->sLastToken);
127075
- nErr++;
127076127522
goto abort_parse;
127077127523
}
127078127524
case TK_SEMI: {
127079127525
pParse->zTail = &zSql[i];
127080127526
/* Fall thru into the default case */
@@ -127088,16 +127534,19 @@
127088127534
break;
127089127535
}
127090127536
}
127091127537
}
127092127538
abort_parse:
127093
- if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
127539
+ assert( nErr==0 );
127540
+ if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127094127541
if( lastTokenParsed!=TK_SEMI ){
127095127542
sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127096127543
pParse->zTail = &zSql[i];
127097127544
}
127098
- sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127545
+ if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127546
+ sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127547
+ }
127099127548
}
127100127549
#ifdef YYTRACKMAXSTACKDEPTH
127101127550
sqlite3_mutex_enter(sqlite3MallocMutex());
127102127551
sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127103127552
sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127603,11 @@
127154127603
while( pParse->pZombieTab ){
127155127604
Table *p = pParse->pZombieTab;
127156127605
pParse->pZombieTab = p->pNextZombie;
127157127606
sqlite3DeleteTable(db, p);
127158127607
}
127159
- if( nErr>0 && pParse->rc==SQLITE_OK ){
127160
- pParse->rc = SQLITE_ERROR;
127161
- }
127608
+ assert( nErr==0 || pParse->rc!=SQLITE_OK );
127162127609
return nErr;
127163127610
}
127164127611
127165127612
/************** End of tokenize.c ********************************************/
127166127613
/************** Begin file complete.c ****************************************/
@@ -127432,11 +127879,11 @@
127432127879
** UTF-8.
127433127880
*/
127434127881
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127435127882
sqlite3_value *pVal;
127436127883
char const *zSql8;
127437
- int rc = SQLITE_NOMEM;
127884
+ int rc;
127438127885
127439127886
#ifndef SQLITE_OMIT_AUTOINIT
127440127887
rc = sqlite3_initialize();
127441127888
if( rc ) return rc;
127442127889
#endif
@@ -127598,10 +128045,22 @@
127598128045
** zero if and only if SQLite was compiled with mutexing code omitted due to
127599128046
** the SQLITE_THREADSAFE compile-time option being set to 0.
127600128047
*/
127601128048
SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
127602128049
128050
+/*
128051
+** When compiling the test fixture or with debugging enabled (on Win32),
128052
+** this variable being set to non-zero will cause OSTRACE macros to emit
128053
+** extra diagnostic information.
128054
+*/
128055
+#ifdef SQLITE_HAVE_OS_TRACE
128056
+# ifndef SQLITE_DEBUG_OS_TRACE
128057
+# define SQLITE_DEBUG_OS_TRACE 0
128058
+# endif
128059
+ int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
128060
+#endif
128061
+
127603128062
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
127604128063
/*
127605128064
** If the following function pointer is not NULL and if
127606128065
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
127607128066
** I/O active are written using this function. These messages
@@ -128737,11 +129196,11 @@
128737129196
128738129197
/*
128739129198
** Return a static string containing the name corresponding to the error code
128740129199
** specified in the argument.
128741129200
*/
128742
-#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST)
129201
+#if defined(SQLITE_NEED_ERR_NAME)
128743129202
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
128744129203
const char *zName = 0;
128745129204
int i, origRc = rc;
128746129205
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
128747129206
switch( rc ){
@@ -129962,18 +130421,18 @@
129962130421
){
129963130422
char *zOpt;
129964130423
int eState; /* Parser state when parsing URI */
129965130424
int iIn; /* Input character index */
129966130425
int iOut = 0; /* Output character index */
129967
- int nByte = nUri+2; /* Bytes of space to allocate */
130426
+ u64 nByte = nUri+2; /* Bytes of space to allocate */
129968130427
129969130428
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
129970130429
** method that there may be extra parameters following the file-name. */
129971130430
flags |= SQLITE_OPEN_URI;
129972130431
129973130432
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129974
- zFile = sqlite3_malloc(nByte);
130433
+ zFile = sqlite3_malloc64(nByte);
129975130434
if( !zFile ) return SQLITE_NOMEM;
129976130435
129977130436
iIn = 5;
129978130437
#ifdef SQLITE_ALLOW_URI_AUTHORITY
129979130438
if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130594,11 @@
130135130594
130136130595
zOpt = &zVal[nVal+1];
130137130596
}
130138130597
130139130598
}else{
130140
- zFile = sqlite3_malloc(nUri+2);
130599
+ zFile = sqlite3_malloc64(nUri+2);
130141130600
if( !zFile ) return SQLITE_NOMEM;
130142130601
memcpy(zFile, zUri, nUri);
130143130602
zFile[nUri] = '\0';
130144130603
zFile[nUri+1] = '\0';
130145130604
flags &= ~SQLITE_OPEN_URI;
@@ -132344,10 +132803,15 @@
132344132803
** false.
132345132804
*/
132346132805
#ifdef SQLITE_COVERAGE_TEST
132347132806
# define ALWAYS(x) (1)
132348132807
# define NEVER(X) (0)
132808
+#elif defined(SQLITE_DEBUG)
132809
+# define ALWAYS(x) sqlite3Fts3Always((x)!=0)
132810
+# define NEVER(x) sqlite3Fts3Never((x)!=0)
132811
+SQLITE_PRIVATE int sqlite3Fts3Always(int b);
132812
+SQLITE_PRIVATE int sqlite3Fts3Never(int b);
132349132813
#else
132350132814
# define ALWAYS(x) (x)
132351132815
# define NEVER(x) (x)
132352132816
#endif
132353132817
@@ -132744,10 +133208,11 @@
132744133208
#define fts3GetVarint32(p, piVal) ( \
132745133209
(*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
132746133210
)
132747133211
132748133212
/* fts3.c */
133213
+SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
132749133214
SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
132750133215
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
132751133216
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
132752133217
SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
132753133218
SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133297,17 @@
132832133297
132833133298
static int fts3EvalNext(Fts3Cursor *pCsr);
132834133299
static int fts3EvalStart(Fts3Cursor *pCsr);
132835133300
static int fts3TermSegReaderCursor(
132836133301
Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
133302
+
133303
+#ifndef SQLITE_AMALGAMATION
133304
+# if defined(SQLITE_DEBUG)
133305
+SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
133306
+SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
133307
+# endif
133308
+#endif
132837133309
132838133310
/*
132839133311
** Write a 64-bit variable-length integer to memory starting at p[0].
132840133312
** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
132841133313
** The number of bytes written is returned.
@@ -132942,11 +133414,11 @@
132942133414
int iOut = 0; /* Index of next byte to write to output */
132943133415
132944133416
/* If the first byte was a '[', then the close-quote character is a ']' */
132945133417
if( quote=='[' ) quote = ']';
132946133418
132947
- while( ALWAYS(z[iIn]) ){
133419
+ while( z[iIn] ){
132948133420
if( z[iIn]==quote ){
132949133421
if( z[iIn+1]!=quote ) break;
132950133422
z[iOut++] = quote;
132951133423
iIn += 2;
132952133424
}else{
@@ -133020,10 +133492,21 @@
133020133492
p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133021133493
133022133494
sqlite3_free(p);
133023133495
return SQLITE_OK;
133024133496
}
133497
+
133498
+/*
133499
+** Write an error message into *pzErr
133500
+*/
133501
+SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){
133502
+ va_list ap;
133503
+ sqlite3_free(*pzErr);
133504
+ va_start(ap, zFormat);
133505
+ *pzErr = sqlite3_vmprintf(zFormat, ap);
133506
+ va_end(ap);
133507
+}
133025133508
133026133509
/*
133027133510
** Construct one or more SQL statements from the format string given
133028133511
** and then evaluate those statements. The success code is written
133029133512
** into *pRc.
@@ -133539,11 +134022,12 @@
133539134022
sqlite3 *db, /* Database handle */
133540134023
const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
133541134024
const char *zTbl, /* Name of content table */
133542134025
const char ***pazCol, /* OUT: Malloc'd array of column names */
133543134026
int *pnCol, /* OUT: Size of array *pazCol */
133544
- int *pnStr /* OUT: Bytes of string content */
134027
+ int *pnStr, /* OUT: Bytes of string content */
134028
+ char **pzErr /* OUT: error message */
133545134029
){
133546134030
int rc = SQLITE_OK; /* Return code */
133547134031
char *zSql; /* "SELECT *" statement on zTbl */
133548134032
sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
133549134033
@@ -133550,10 +134034,13 @@
133550134034
zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
133551134035
if( !zSql ){
133552134036
rc = SQLITE_NOMEM;
133553134037
}else{
133554134038
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
134039
+ if( rc!=SQLITE_OK ){
134040
+ sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
134041
+ }
133555134042
}
133556134043
sqlite3_free(zSql);
133557134044
133558134045
if( rc==SQLITE_OK ){
133559134046
const char **azCol; /* Output array */
@@ -133716,17 +134203,17 @@
133716134203
if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
133717134204
break;
133718134205
}
133719134206
}
133720134207
if( iOpt==SizeofArray(aFts4Opt) ){
133721
- *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z);
134208
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
133722134209
rc = SQLITE_ERROR;
133723134210
}else{
133724134211
switch( iOpt ){
133725134212
case 0: /* MATCHINFO */
133726134213
if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
133727
- *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal);
134214
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
133728134215
rc = SQLITE_ERROR;
133729134216
}
133730134217
bNoDocsize = 1;
133731134218
break;
133732134219
@@ -133750,11 +134237,11 @@
133750134237
133751134238
case 4: /* ORDER */
133752134239
if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
133753134240
&& (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
133754134241
){
133755
- *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
134242
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
133756134243
rc = SQLITE_ERROR;
133757134244
}
133758134245
bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
133759134246
break;
133760134247
@@ -133801,11 +134288,11 @@
133801134288
zCompress = 0;
133802134289
zUncompress = 0;
133803134290
if( nCol==0 ){
133804134291
sqlite3_free((void*)aCol);
133805134292
aCol = 0;
133806
- rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
134293
+ rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
133807134294
133808134295
/* If a languageid= option was specified, remove the language id
133809134296
** column from the aCol[] array. */
133810134297
if( rc==SQLITE_OK && zLanguageid ){
133811134298
int j;
@@ -133836,11 +134323,11 @@
133836134323
assert( pTokenizer );
133837134324
133838134325
rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
133839134326
if( rc==SQLITE_ERROR ){
133840134327
assert( zPrefix );
133841
- *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix);
134328
+ sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix);
133842134329
}
133843134330
if( rc!=SQLITE_OK ) goto fts3_init_out;
133844134331
133845134332
/* Allocate and populate the Fts3Table structure. */
133846134333
nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134405,19 @@
133918134405
}
133919134406
}
133920134407
}
133921134408
for(i=0; i<nNotindexed; i++){
133922134409
if( azNotindexed[i] ){
133923
- *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
134410
+ sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]);
133924134411
rc = SQLITE_ERROR;
133925134412
}
133926134413
}
133927134414
133928134415
if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
133929134416
char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
133930134417
rc = SQLITE_ERROR;
133931
- *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
134418
+ sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss);
133932134419
}
133933134420
p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
133934134421
p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
133935134422
if( rc!=SQLITE_OK ) goto fts3_init_out;
133936134423
@@ -135319,11 +135806,11 @@
135319135806
** Fts3SegReaderPending might segfault, as the data structures used by
135320135807
** fts4aux are not completely populated. So it's easiest to filter these
135321135808
** calls out here. */
135322135809
if( iLevel<0 && p->aIndex ){
135323135810
Fts3SegReader *pSeg = 0;
135324
- rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg);
135811
+ rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
135325135812
if( rc==SQLITE_OK && pSeg ){
135326135813
rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135327135814
}
135328135815
}
135329135816
@@ -135968,15 +136455,35 @@
135968136455
*/
135969136456
static void fts3ReversePoslist(char *pStart, char **ppPoslist){
135970136457
char *p = &(*ppPoslist)[-2];
135971136458
char c = 0;
135972136459
136460
+ /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
135973136461
while( p>pStart && (c=*p--)==0 );
136462
+
136463
+ /* Search backwards for a varint with value zero (the end of the previous
136464
+ ** poslist). This is an 0x00 byte preceded by some byte that does not
136465
+ ** have the 0x80 bit set. */
135974136466
while( p>pStart && (*p & 0x80) | c ){
135975136467
c = *p--;
135976136468
}
135977
- if( p>pStart ){ p = &p[2]; }
136469
+ assert( p==pStart || c==0 );
136470
+
136471
+ /* At this point p points to that preceding byte without the 0x80 bit
136472
+ ** set. So to find the start of the poslist, skip forward 2 bytes then
136473
+ ** over a varint.
136474
+ **
136475
+ ** Normally. The other case is that p==pStart and the poslist to return
136476
+ ** is the first in the doclist. In this case do not skip forward 2 bytes.
136477
+ ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
136478
+ ** is required for cases where the first byte of a doclist and the
136479
+ ** doclist is empty. For example, if the first docid is 10, a doclist
136480
+ ** that begins with:
136481
+ **
136482
+ ** 0x0A 0x00 <next docid delta varint>
136483
+ */
136484
+ if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
135978136485
while( *p++&0x80 );
135979136486
*ppPoslist = p;
135980136487
}
135981136488
135982136489
/*
@@ -136043,10 +136550,12 @@
136043136550
case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136044136551
case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136045136552
}
136046136553
if( !zEllipsis || !zEnd || !zStart ){
136047136554
sqlite3_result_error_nomem(pContext);
136555
+ }else if( nToken==0 ){
136556
+ sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
136048136557
}else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136049136558
sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136050136559
}
136051136560
}
136052136561
@@ -137104,16 +137613,18 @@
137104137613
Fts3Expr *pExpr, /* Expression to initialize phrases in */
137105137614
int *pRc /* IN/OUT: Error code */
137106137615
){
137107137616
if( pExpr && SQLITE_OK==*pRc ){
137108137617
if( pExpr->eType==FTSQUERY_PHRASE ){
137109
- int i;
137110137618
int nToken = pExpr->pPhrase->nToken;
137111
- for(i=0; i<nToken; i++){
137112
- if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137619
+ if( nToken ){
137620
+ int i;
137621
+ for(i=0; i<nToken; i++){
137622
+ if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137623
+ }
137624
+ pExpr->bDeferred = (i==nToken);
137113137625
}
137114
- pExpr->bDeferred = (i==nToken);
137115137626
*pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137116137627
}else{
137117137628
fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137118137629
fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137119137630
pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138783,12 @@
138272138783
if( rc!=SQLITE_OK ) return rc;
138273138784
138274138785
pIter = pPhrase->pOrPoslist;
138275138786
iDocid = pPhrase->iOrDocid;
138276138787
if( pCsr->bDesc==bDescDoclist ){
138277
- bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138788
+ bEof = !pPhrase->doclist.nAll ||
138789
+ (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138278138790
while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138279138791
sqlite3Fts3DoclistNext(
138280138792
bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138281138793
&pIter, &iDocid, &bEof
138282138794
);
@@ -138484,11 +138996,11 @@
138484138996
138485138997
*ppVtab = (sqlite3_vtab *)p;
138486138998
return SQLITE_OK;
138487138999
138488139000
bad_args:
138489
- *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor");
139001
+ sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor");
138490139002
return SQLITE_ERROR;
138491139003
}
138492139004
138493139005
/*
138494139006
** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140454,17 @@
139942140454
139943140455
if( rc!=SQLITE_OK ){
139944140456
sqlite3Fts3ExprFree(*ppExpr);
139945140457
*ppExpr = 0;
139946140458
if( rc==SQLITE_TOOBIG ){
139947
- *pzErr = sqlite3_mprintf(
140459
+ sqlite3Fts3ErrMsg(pzErr,
139948140460
"FTS expression tree is too large (maximum depth %d)",
139949140461
SQLITE_FTS3_MAX_EXPR_DEPTH
139950140462
);
139951140463
rc = SQLITE_ERROR;
139952140464
}else if( rc==SQLITE_ERROR ){
139953
- *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
140465
+ sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z);
139954140466
}
139955140467
}
139956140468
139957140469
return rc;
139958140470
}
@@ -141424,11 +141936,11 @@
141424141936
z[n] = '\0';
141425141937
sqlite3Fts3Dequote(z);
141426141938
141427141939
m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141428141940
if( !m ){
141429
- *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z);
141941
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
141430141942
rc = SQLITE_ERROR;
141431141943
}else{
141432141944
char const **aArg = 0;
141433141945
int iArg = 0;
141434141946
z = &z[n+1];
@@ -141447,11 +141959,11 @@
141447141959
z = &z[n+1];
141448141960
}
141449141961
rc = m->xCreate(iArg, aArg, ppTok);
141450141962
assert( rc!=SQLITE_OK || *ppTok );
141451141963
if( rc!=SQLITE_OK ){
141452
- *pzErr = sqlite3_mprintf("unknown tokenizer");
141964
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer");
141453141965
}else{
141454141966
(*ppTok)->pModule = m;
141455141967
}
141456141968
sqlite3_free((void *)aArg);
141457141969
}
@@ -141531,13 +142043,13 @@
141531142043
141532142044
pHash = (Fts3Hash *)sqlite3_user_data(context);
141533142045
p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
141534142046
141535142047
if( !p ){
141536
- char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
141537
- sqlite3_result_error(context, zErr, -1);
141538
- sqlite3_free(zErr);
142048
+ char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName);
142049
+ sqlite3_result_error(context, zErr2, -1);
142050
+ sqlite3_free(zErr2);
141539142051
return;
141540142052
}
141541142053
141542142054
pRet = Tcl_NewObj();
141543142055
Tcl_IncrRefCount(pRet);
@@ -142068,11 +142580,11 @@
142068142580
sqlite3_tokenizer_module *p;
142069142581
int nName = (int)strlen(zName);
142070142582
142071142583
p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142072142584
if( !p ){
142073
- *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
142585
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName);
142074142586
return SQLITE_ERROR;
142075142587
}
142076142588
142077142589
*pp = p;
142078142590
return SQLITE_OK;
@@ -142765,11 +143277,11 @@
142765143277
/* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
142766143278
/* 24 */ "",
142767143279
/* 25 */ "",
142768143280
142769143281
/* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
142770
-/* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'",
143282
+/* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'",
142771143283
142772143284
/* This statement is used to determine which level to read the input from
142773143285
** when performing an incremental merge. It returns the absolute level number
142774143286
** of the oldest level in the db that contains at least ? segments. Or,
142775143287
** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146395,12 @@
145883146395
sqlite3_stmt *pAllLangid = 0;
145884146396
145885146397
rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
145886146398
if( rc==SQLITE_OK ){
145887146399
int rc2;
145888
- sqlite3_bind_int(pAllLangid, 1, p->nIndex);
146400
+ sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
146401
+ sqlite3_bind_int(pAllLangid, 2, p->nIndex);
145889146402
while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
145890146403
int i;
145891146404
int iLangid = sqlite3_column_int(pAllLangid, 0);
145892146405
for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
145893146406
rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147728,11 @@
147215147728
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147216147729
147217147730
pHint->n = i;
147218147731
i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147219147732
i += fts3GetVarint32(&pHint->a[i], pnInput);
147220
- if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
147733
+ if( i!=nHint ) return FTS_CORRUPT_VTAB;
147221147734
147222147735
return SQLITE_OK;
147223147736
}
147224147737
147225147738
@@ -147583,11 +148096,12 @@
147583148096
147584148097
/* This block calculates the checksum according to the FTS index. */
147585148098
rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147586148099
if( rc==SQLITE_OK ){
147587148100
int rc2;
147588
- sqlite3_bind_int(pAllLangid, 1, p->nIndex);
148101
+ sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
148102
+ sqlite3_bind_int(pAllLangid, 2, p->nIndex);
147589148103
while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
147590148104
int iLangid = sqlite3_column_int(pAllLangid, 0);
147591148105
int i;
147592148106
for(i=0; i<p->nIndex; i++){
147593148107
cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148110,10 @@
147596148110
rc2 = sqlite3_reset(pAllLangid);
147597148111
if( rc==SQLITE_OK ) rc = rc2;
147598148112
}
147599148113
147600148114
/* This block calculates the checksum according to the %_content table */
147601
- rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147602148115
if( rc==SQLITE_OK ){
147603148116
sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
147604148117
sqlite3_stmt *pStmt = 0;
147605148118
char *zSql;
147606148119
@@ -147693,11 +148206,11 @@
147693148206
Fts3Table *p /* FTS3 table handle */
147694148207
){
147695148208
int rc;
147696148209
int bOk = 0;
147697148210
rc = fts3IntegrityCheck(p, &bOk);
147698
- if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB;
148211
+ if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
147699148212
return rc;
147700148213
}
147701148214
147702148215
/*
147703148216
** Handle a 'special' INSERT of the form:
@@ -148131,10 +148644,11 @@
148131148644
#define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148132148645
#define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148133148646
#define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148134148647
#define FTS3_MATCHINFO_LCS 's' /* nCol values */
148135148648
#define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
148649
+#define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */
148136148650
148137148651
/*
148138148652
** The default value for the second argument to matchinfo().
148139148653
*/
148140148654
#define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149426,55 @@
148912149426
}
148913149427
}
148914149428
148915149429
return rc;
148916149430
}
149431
+
149432
+/*
149433
+** fts3ExprIterate() callback used to gather information for the matchinfo
149434
+** directive 'y'.
149435
+*/
149436
+static int fts3ExprLHitsCb(
149437
+ Fts3Expr *pExpr, /* Phrase expression node */
149438
+ int iPhrase, /* Phrase number */
149439
+ void *pCtx /* Pointer to MatchInfo structure */
149440
+){
149441
+ MatchInfo *p = (MatchInfo *)pCtx;
149442
+ Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
149443
+ int rc = SQLITE_OK;
149444
+ int iStart = iPhrase * p->nCol;
149445
+ Fts3Expr *pEof; /* Ancestor node already at EOF */
149446
+
149447
+ /* This must be a phrase */
149448
+ assert( pExpr->pPhrase );
149449
+
149450
+ /* Initialize all output integers to zero. */
149451
+ memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
149452
+
149453
+ /* Check if this or any parent node is at EOF. If so, then all output
149454
+ ** values are zero. */
149455
+ for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
149456
+
149457
+ if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
149458
+ Fts3Phrase *pPhrase = pExpr->pPhrase;
149459
+ char *pIter = pPhrase->doclist.pList;
149460
+ int iCol = 0;
149461
+
149462
+ while( 1 ){
149463
+ int nHit = fts3ColumnlistCount(&pIter);
149464
+ if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
149465
+ p->aMatchinfo[iStart + iCol] = (u32)nHit;
149466
+ }
149467
+ assert( *pIter==0x00 || *pIter==0x01 );
149468
+ if( *pIter!=0x01 ) break;
149469
+ pIter++;
149470
+ pIter += fts3GetVarint32(pIter, &iCol);
149471
+ }
149472
+ }
149473
+
149474
+ return rc;
149475
+}
148917149476
148918149477
static int fts3MatchinfoCheck(
148919149478
Fts3Table *pTab,
148920149479
char cArg,
148921149480
char **pzErr
@@ -148925,14 +149484,15 @@
148925149484
|| (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
148926149485
|| (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
148927149486
|| (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
148928149487
|| (cArg==FTS3_MATCHINFO_LCS)
148929149488
|| (cArg==FTS3_MATCHINFO_HITS)
149489
+ || (cArg==FTS3_MATCHINFO_LHITS)
148930149490
){
148931149491
return SQLITE_OK;
148932149492
}
148933
- *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);
149493
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
148934149494
return SQLITE_ERROR;
148935149495
}
148936149496
148937149497
static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
148938149498
int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149507,14 @@
148947149507
case FTS3_MATCHINFO_AVGLENGTH:
148948149508
case FTS3_MATCHINFO_LENGTH:
148949149509
case FTS3_MATCHINFO_LCS:
148950149510
nVal = pInfo->nCol;
148951149511
break;
149512
+
149513
+ case FTS3_MATCHINFO_LHITS:
149514
+ nVal = pInfo->nCol * pInfo->nPhrase;
149515
+ break;
148952149516
148953149517
default:
148954149518
assert( cArg==FTS3_MATCHINFO_HITS );
148955149519
nVal = pInfo->nCol * pInfo->nPhrase * 3;
148956149520
break;
@@ -149201,10 +149765,14 @@
149201149765
rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149202149766
if( rc==SQLITE_OK ){
149203149767
rc = fts3MatchinfoLcs(pCsr, pInfo);
149204149768
}
149205149769
break;
149770
+
149771
+ case FTS3_MATCHINFO_LHITS:
149772
+ (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
149773
+ break;
149206149774
149207149775
default: {
149208149776
Fts3Expr *pExpr;
149209149777
assert( zArg[i]==FTS3_MATCHINFO_HITS );
149210149778
pExpr = pCsr->pExpr;
@@ -153214,15 +153782,23 @@
153214153782
** conflict-handling mode specified by the user.
153215153783
*/
153216153784
if( nData>1 ){
153217153785
int ii;
153218153786
153219
- /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
153220
- assert( nData==(pRtree->nDim*2 + 3) );
153787
+ /* Populate the cell.aCoord[] array. The first coordinate is azData[3].
153788
+ **
153789
+ ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
153790
+ ** with "column" that are interpreted as table constraints.
153791
+ ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
153792
+ ** This problem was discovered after years of use, so we silently ignore
153793
+ ** these kinds of misdeclared tables to avoid breaking any legacy.
153794
+ */
153795
+ assert( nData<=(pRtree->nDim*2 + 3) );
153796
+
153221153797
#ifndef SQLITE_RTREE_INT_ONLY
153222153798
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153223
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153799
+ for(ii=0; ii<nData-4; ii+=2){
153224153800
cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153225153801
cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153226153802
if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153227153803
rc = SQLITE_CONSTRAINT;
153228153804
goto constraint;
@@ -153229,11 +153805,11 @@
153229153805
}
153230153806
}
153231153807
}else
153232153808
#endif
153233153809
{
153234
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153810
+ for(ii=0; ii<nData-4; ii+=2){
153235153811
cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153236153812
cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153237153813
if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153238153814
rc = SQLITE_CONSTRAINT;
153239153815
goto constraint;
@@ -154629,5 +155205,633 @@
154629155205
154630155206
#endif /* defined(SQLITE_ENABLE_ICU) */
154631155207
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
154632155208
154633155209
/************** End of fts3_icu.c ********************************************/
155210
+/************** Begin file dbstat.c ******************************************/
155211
+/*
155212
+** 2010 July 12
155213
+**
155214
+** The author disclaims copyright to this source code. In place of
155215
+** a legal notice, here is a blessing:
155216
+**
155217
+** May you do good and not evil.
155218
+** May you find forgiveness for yourself and forgive others.
155219
+** May you share freely, never taking more than you give.
155220
+**
155221
+******************************************************************************
155222
+**
155223
+** This file contains an implementation of the "dbstat" virtual table.
155224
+**
155225
+** The dbstat virtual table is used to extract low-level formatting
155226
+** information from an SQLite database in order to implement the
155227
+** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
155228
+** for an example implementation.
155229
+*/
155230
+
155231
+#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
155232
+ && !defined(SQLITE_OMIT_VIRTUAL_TABLE)
155233
+
155234
+/*
155235
+** Page paths:
155236
+**
155237
+** The value of the 'path' column describes the path taken from the
155238
+** root-node of the b-tree structure to each page. The value of the
155239
+** root-node path is '/'.
155240
+**
155241
+** The value of the path for the left-most child page of the root of
155242
+** a b-tree is '/000/'. (Btrees store content ordered from left to right
155243
+** so the pages to the left have smaller keys than the pages to the right.)
155244
+** The next to left-most child of the root page is
155245
+** '/001', and so on, each sibling page identified by a 3-digit hex
155246
+** value. The children of the 451st left-most sibling have paths such
155247
+** as '/1c2/000/, '/1c2/001/' etc.
155248
+**
155249
+** Overflow pages are specified by appending a '+' character and a
155250
+** six-digit hexadecimal value to the path to the cell they are linked
155251
+** from. For example, the three overflow pages in a chain linked from
155252
+** the left-most cell of the 450th child of the root page are identified
155253
+** by the paths:
155254
+**
155255
+** '/1c2/000+000000' // First page in overflow chain
155256
+** '/1c2/000+000001' // Second page in overflow chain
155257
+** '/1c2/000+000002' // Third page in overflow chain
155258
+**
155259
+** If the paths are sorted using the BINARY collation sequence, then
155260
+** the overflow pages associated with a cell will appear earlier in the
155261
+** sort-order than its child page:
155262
+**
155263
+** '/1c2/000/' // Left-most child of 451st child of root
155264
+*/
155265
+#define VTAB_SCHEMA \
155266
+ "CREATE TABLE xx( " \
155267
+ " name STRING, /* Name of table or index */" \
155268
+ " path INTEGER, /* Path to page from root */" \
155269
+ " pageno INTEGER, /* Page number */" \
155270
+ " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \
155271
+ " ncell INTEGER, /* Cells on page (0 for overflow) */" \
155272
+ " payload INTEGER, /* Bytes of payload on this page */" \
155273
+ " unused INTEGER, /* Bytes of unused space on this page */" \
155274
+ " mx_payload INTEGER, /* Largest payload size of all cells */" \
155275
+ " pgoffset INTEGER, /* Offset of page in file */" \
155276
+ " pgsize INTEGER /* Size of the page */" \
155277
+ ");"
155278
+
155279
+
155280
+typedef struct StatTable StatTable;
155281
+typedef struct StatCursor StatCursor;
155282
+typedef struct StatPage StatPage;
155283
+typedef struct StatCell StatCell;
155284
+
155285
+struct StatCell {
155286
+ int nLocal; /* Bytes of local payload */
155287
+ u32 iChildPg; /* Child node (or 0 if this is a leaf) */
155288
+ int nOvfl; /* Entries in aOvfl[] */
155289
+ u32 *aOvfl; /* Array of overflow page numbers */
155290
+ int nLastOvfl; /* Bytes of payload on final overflow page */
155291
+ int iOvfl; /* Iterates through aOvfl[] */
155292
+};
155293
+
155294
+struct StatPage {
155295
+ u32 iPgno;
155296
+ DbPage *pPg;
155297
+ int iCell;
155298
+
155299
+ char *zPath; /* Path to this page */
155300
+
155301
+ /* Variables populated by statDecodePage(): */
155302
+ u8 flags; /* Copy of flags byte */
155303
+ int nCell; /* Number of cells on page */
155304
+ int nUnused; /* Number of unused bytes on page */
155305
+ StatCell *aCell; /* Array of parsed cells */
155306
+ u32 iRightChildPg; /* Right-child page number (or 0) */
155307
+ int nMxPayload; /* Largest payload of any cell on this page */
155308
+};
155309
+
155310
+struct StatCursor {
155311
+ sqlite3_vtab_cursor base;
155312
+ sqlite3_stmt *pStmt; /* Iterates through set of root pages */
155313
+ int isEof; /* After pStmt has returned SQLITE_DONE */
155314
+
155315
+ StatPage aPage[32];
155316
+ int iPage; /* Current entry in aPage[] */
155317
+
155318
+ /* Values to return. */
155319
+ char *zName; /* Value of 'name' column */
155320
+ char *zPath; /* Value of 'path' column */
155321
+ u32 iPageno; /* Value of 'pageno' column */
155322
+ char *zPagetype; /* Value of 'pagetype' column */
155323
+ int nCell; /* Value of 'ncell' column */
155324
+ int nPayload; /* Value of 'payload' column */
155325
+ int nUnused; /* Value of 'unused' column */
155326
+ int nMxPayload; /* Value of 'mx_payload' column */
155327
+ i64 iOffset; /* Value of 'pgOffset' column */
155328
+ int szPage; /* Value of 'pgSize' column */
155329
+};
155330
+
155331
+struct StatTable {
155332
+ sqlite3_vtab base;
155333
+ sqlite3 *db;
155334
+};
155335
+
155336
+#ifndef get2byte
155337
+# define get2byte(x) ((x)[0]<<8 | (x)[1])
155338
+#endif
155339
+
155340
+/*
155341
+** Connect to or create a statvfs virtual table.
155342
+*/
155343
+static int statConnect(
155344
+ sqlite3 *db,
155345
+ void *pAux,
155346
+ int argc, const char *const*argv,
155347
+ sqlite3_vtab **ppVtab,
155348
+ char **pzErr
155349
+){
155350
+ StatTable *pTab = 0;
155351
+ int rc = SQLITE_OK;
155352
+
155353
+ rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
155354
+ if( rc==SQLITE_OK ){
155355
+ pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
155356
+ if( pTab==0 ) rc = SQLITE_NOMEM;
155357
+ }
155358
+
155359
+ assert( rc==SQLITE_OK || pTab==0 );
155360
+ if( rc==SQLITE_OK ){
155361
+ memset(pTab, 0, sizeof(StatTable));
155362
+ pTab->db = db;
155363
+ }
155364
+
155365
+ *ppVtab = (sqlite3_vtab*)pTab;
155366
+ return rc;
155367
+}
155368
+
155369
+/*
155370
+** Disconnect from or destroy a statvfs virtual table.
155371
+*/
155372
+static int statDisconnect(sqlite3_vtab *pVtab){
155373
+ sqlite3_free(pVtab);
155374
+ return SQLITE_OK;
155375
+}
155376
+
155377
+/*
155378
+** There is no "best-index". This virtual table always does a linear
155379
+** scan of the binary VFS log file.
155380
+*/
155381
+static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
155382
+
155383
+ /* Records are always returned in ascending order of (name, path).
155384
+ ** If this will satisfy the client, set the orderByConsumed flag so that
155385
+ ** SQLite does not do an external sort.
155386
+ */
155387
+ if( ( pIdxInfo->nOrderBy==1
155388
+ && pIdxInfo->aOrderBy[0].iColumn==0
155389
+ && pIdxInfo->aOrderBy[0].desc==0
155390
+ ) ||
155391
+ ( pIdxInfo->nOrderBy==2
155392
+ && pIdxInfo->aOrderBy[0].iColumn==0
155393
+ && pIdxInfo->aOrderBy[0].desc==0
155394
+ && pIdxInfo->aOrderBy[1].iColumn==1
155395
+ && pIdxInfo->aOrderBy[1].desc==0
155396
+ )
155397
+ ){
155398
+ pIdxInfo->orderByConsumed = 1;
155399
+ }
155400
+
155401
+ pIdxInfo->estimatedCost = 10.0;
155402
+ return SQLITE_OK;
155403
+}
155404
+
155405
+/*
155406
+** Open a new statvfs cursor.
155407
+*/
155408
+static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
155409
+ StatTable *pTab = (StatTable *)pVTab;
155410
+ StatCursor *pCsr;
155411
+ int rc;
155412
+
155413
+ pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
155414
+ if( pCsr==0 ){
155415
+ rc = SQLITE_NOMEM;
155416
+ }else{
155417
+ memset(pCsr, 0, sizeof(StatCursor));
155418
+ pCsr->base.pVtab = pVTab;
155419
+
155420
+ rc = sqlite3_prepare_v2(pTab->db,
155421
+ "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
155422
+ " UNION ALL "
155423
+ "SELECT name, rootpage, type FROM sqlite_master WHERE rootpage!=0"
155424
+ " ORDER BY name", -1,
155425
+ &pCsr->pStmt, 0
155426
+ );
155427
+ if( rc!=SQLITE_OK ){
155428
+ sqlite3_free(pCsr);
155429
+ pCsr = 0;
155430
+ }
155431
+ }
155432
+
155433
+ *ppCursor = (sqlite3_vtab_cursor *)pCsr;
155434
+ return rc;
155435
+}
155436
+
155437
+static void statClearPage(StatPage *p){
155438
+ int i;
155439
+ if( p->aCell ){
155440
+ for(i=0; i<p->nCell; i++){
155441
+ sqlite3_free(p->aCell[i].aOvfl);
155442
+ }
155443
+ sqlite3_free(p->aCell);
155444
+ }
155445
+ sqlite3PagerUnref(p->pPg);
155446
+ sqlite3_free(p->zPath);
155447
+ memset(p, 0, sizeof(StatPage));
155448
+}
155449
+
155450
+static void statResetCsr(StatCursor *pCsr){
155451
+ int i;
155452
+ sqlite3_reset(pCsr->pStmt);
155453
+ for(i=0; i<ArraySize(pCsr->aPage); i++){
155454
+ statClearPage(&pCsr->aPage[i]);
155455
+ }
155456
+ pCsr->iPage = 0;
155457
+ sqlite3_free(pCsr->zPath);
155458
+ pCsr->zPath = 0;
155459
+}
155460
+
155461
+/*
155462
+** Close a statvfs cursor.
155463
+*/
155464
+static int statClose(sqlite3_vtab_cursor *pCursor){
155465
+ StatCursor *pCsr = (StatCursor *)pCursor;
155466
+ statResetCsr(pCsr);
155467
+ sqlite3_finalize(pCsr->pStmt);
155468
+ sqlite3_free(pCsr);
155469
+ return SQLITE_OK;
155470
+}
155471
+
155472
+static void getLocalPayload(
155473
+ int nUsable, /* Usable bytes per page */
155474
+ u8 flags, /* Page flags */
155475
+ int nTotal, /* Total record (payload) size */
155476
+ int *pnLocal /* OUT: Bytes stored locally */
155477
+){
155478
+ int nLocal;
155479
+ int nMinLocal;
155480
+ int nMaxLocal;
155481
+
155482
+ if( flags==0x0D ){ /* Table leaf node */
155483
+ nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155484
+ nMaxLocal = nUsable - 35;
155485
+ }else{ /* Index interior and leaf nodes */
155486
+ nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155487
+ nMaxLocal = (nUsable - 12) * 64 / 255 - 23;
155488
+ }
155489
+
155490
+ nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4);
155491
+ if( nLocal>nMaxLocal ) nLocal = nMinLocal;
155492
+ *pnLocal = nLocal;
155493
+}
155494
+
155495
+static int statDecodePage(Btree *pBt, StatPage *p){
155496
+ int nUnused;
155497
+ int iOff;
155498
+ int nHdr;
155499
+ int isLeaf;
155500
+ int szPage;
155501
+
155502
+ u8 *aData = sqlite3PagerGetData(p->pPg);
155503
+ u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
155504
+
155505
+ p->flags = aHdr[0];
155506
+ p->nCell = get2byte(&aHdr[3]);
155507
+ p->nMxPayload = 0;
155508
+
155509
+ isLeaf = (p->flags==0x0A || p->flags==0x0D);
155510
+ nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100;
155511
+
155512
+ nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell;
155513
+ nUnused += (int)aHdr[7];
155514
+ iOff = get2byte(&aHdr[1]);
155515
+ while( iOff ){
155516
+ nUnused += get2byte(&aData[iOff+2]);
155517
+ iOff = get2byte(&aData[iOff]);
155518
+ }
155519
+ p->nUnused = nUnused;
155520
+ p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
155521
+ szPage = sqlite3BtreeGetPageSize(pBt);
155522
+
155523
+ if( p->nCell ){
155524
+ int i; /* Used to iterate through cells */
155525
+ int nUsable; /* Usable bytes per page */
155526
+
155527
+ sqlite3BtreeEnter(pBt);
155528
+ nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt);
155529
+ sqlite3BtreeLeave(pBt);
155530
+ p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell));
155531
+ if( p->aCell==0 ) return SQLITE_NOMEM;
155532
+ memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
155533
+
155534
+ for(i=0; i<p->nCell; i++){
155535
+ StatCell *pCell = &p->aCell[i];
155536
+
155537
+ iOff = get2byte(&aData[nHdr+i*2]);
155538
+ if( !isLeaf ){
155539
+ pCell->iChildPg = sqlite3Get4byte(&aData[iOff]);
155540
+ iOff += 4;
155541
+ }
155542
+ if( p->flags==0x05 ){
155543
+ /* A table interior node. nPayload==0. */
155544
+ }else{
155545
+ u32 nPayload; /* Bytes of payload total (local+overflow) */
155546
+ int nLocal; /* Bytes of payload stored locally */
155547
+ iOff += getVarint32(&aData[iOff], nPayload);
155548
+ if( p->flags==0x0D ){
155549
+ u64 dummy;
155550
+ iOff += sqlite3GetVarint(&aData[iOff], &dummy);
155551
+ }
155552
+ if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload;
155553
+ getLocalPayload(nUsable, p->flags, nPayload, &nLocal);
155554
+ pCell->nLocal = nLocal;
155555
+ assert( nLocal>=0 );
155556
+ assert( nPayload>=(u32)nLocal );
155557
+ assert( nLocal<=(nUsable-35) );
155558
+ if( nPayload>(u32)nLocal ){
155559
+ int j;
155560
+ int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
155561
+ pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
155562
+ pCell->nOvfl = nOvfl;
155563
+ pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
155564
+ if( pCell->aOvfl==0 ) return SQLITE_NOMEM;
155565
+ pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
155566
+ for(j=1; j<nOvfl; j++){
155567
+ int rc;
155568
+ u32 iPrev = pCell->aOvfl[j-1];
155569
+ DbPage *pPg = 0;
155570
+ rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg);
155571
+ if( rc!=SQLITE_OK ){
155572
+ assert( pPg==0 );
155573
+ return rc;
155574
+ }
155575
+ pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
155576
+ sqlite3PagerUnref(pPg);
155577
+ }
155578
+ }
155579
+ }
155580
+ }
155581
+ }
155582
+
155583
+ return SQLITE_OK;
155584
+}
155585
+
155586
+/*
155587
+** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
155588
+** the current value of pCsr->iPageno.
155589
+*/
155590
+static void statSizeAndOffset(StatCursor *pCsr){
155591
+ StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab;
155592
+ Btree *pBt = pTab->db->aDb[0].pBt;
155593
+ Pager *pPager = sqlite3BtreePager(pBt);
155594
+ sqlite3_file *fd;
155595
+ sqlite3_int64 x[2];
155596
+
155597
+ /* The default page size and offset */
155598
+ pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
155599
+ pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1);
155600
+
155601
+ /* If connected to a ZIPVFS backend, override the page size and
155602
+ ** offset with actual values obtained from ZIPVFS.
155603
+ */
155604
+ fd = sqlite3PagerFile(pPager);
155605
+ x[0] = pCsr->iPageno;
155606
+ if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
155607
+ pCsr->iOffset = x[0];
155608
+ pCsr->szPage = (int)x[1];
155609
+ }
155610
+}
155611
+
155612
+/*
155613
+** Move a statvfs cursor to the next entry in the file.
155614
+*/
155615
+static int statNext(sqlite3_vtab_cursor *pCursor){
155616
+ int rc;
155617
+ int nPayload;
155618
+ StatCursor *pCsr = (StatCursor *)pCursor;
155619
+ StatTable *pTab = (StatTable *)pCursor->pVtab;
155620
+ Btree *pBt = pTab->db->aDb[0].pBt;
155621
+ Pager *pPager = sqlite3BtreePager(pBt);
155622
+
155623
+ sqlite3_free(pCsr->zPath);
155624
+ pCsr->zPath = 0;
155625
+
155626
+statNextRestart:
155627
+ if( pCsr->aPage[0].pPg==0 ){
155628
+ rc = sqlite3_step(pCsr->pStmt);
155629
+ if( rc==SQLITE_ROW ){
155630
+ int nPage;
155631
+ u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1);
155632
+ sqlite3PagerPagecount(pPager, &nPage);
155633
+ if( nPage==0 ){
155634
+ pCsr->isEof = 1;
155635
+ return sqlite3_reset(pCsr->pStmt);
155636
+ }
155637
+ rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
155638
+ pCsr->aPage[0].iPgno = iRoot;
155639
+ pCsr->aPage[0].iCell = 0;
155640
+ pCsr->aPage[0].zPath = sqlite3_mprintf("/");
155641
+ pCsr->iPage = 0;
155642
+ }else{
155643
+ pCsr->isEof = 1;
155644
+ return sqlite3_reset(pCsr->pStmt);
155645
+ }
155646
+ }else{
155647
+
155648
+ /* Page p itself has already been visited. */
155649
+ StatPage *p = &pCsr->aPage[pCsr->iPage];
155650
+
155651
+ while( p->iCell<p->nCell ){
155652
+ StatCell *pCell = &p->aCell[p->iCell];
155653
+ if( pCell->iOvfl<pCell->nOvfl ){
155654
+ int nUsable;
155655
+ sqlite3BtreeEnter(pBt);
155656
+ nUsable = sqlite3BtreeGetPageSize(pBt) -
155657
+ sqlite3BtreeGetReserveNoMutex(pBt);
155658
+ sqlite3BtreeLeave(pBt);
155659
+ pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155660
+ pCsr->iPageno = pCell->aOvfl[pCell->iOvfl];
155661
+ pCsr->zPagetype = "overflow";
155662
+ pCsr->nCell = 0;
155663
+ pCsr->nMxPayload = 0;
155664
+ pCsr->zPath = sqlite3_mprintf(
155665
+ "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl
155666
+ );
155667
+ if( pCell->iOvfl<pCell->nOvfl-1 ){
155668
+ pCsr->nUnused = 0;
155669
+ pCsr->nPayload = nUsable - 4;
155670
+ }else{
155671
+ pCsr->nPayload = pCell->nLastOvfl;
155672
+ pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
155673
+ }
155674
+ pCell->iOvfl++;
155675
+ statSizeAndOffset(pCsr);
155676
+ return SQLITE_OK;
155677
+ }
155678
+ if( p->iRightChildPg ) break;
155679
+ p->iCell++;
155680
+ }
155681
+
155682
+ if( !p->iRightChildPg || p->iCell>p->nCell ){
155683
+ statClearPage(p);
155684
+ if( pCsr->iPage==0 ) return statNext(pCursor);
155685
+ pCsr->iPage--;
155686
+ goto statNextRestart; /* Tail recursion */
155687
+ }
155688
+ pCsr->iPage++;
155689
+ assert( p==&pCsr->aPage[pCsr->iPage-1] );
155690
+
155691
+ if( p->iCell==p->nCell ){
155692
+ p[1].iPgno = p->iRightChildPg;
155693
+ }else{
155694
+ p[1].iPgno = p->aCell[p->iCell].iChildPg;
155695
+ }
155696
+ rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);
155697
+ p[1].iCell = 0;
155698
+ p[1].zPath = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
155699
+ p->iCell++;
155700
+ }
155701
+
155702
+
155703
+ /* Populate the StatCursor fields with the values to be returned
155704
+ ** by the xColumn() and xRowid() methods.
155705
+ */
155706
+ if( rc==SQLITE_OK ){
155707
+ int i;
155708
+ StatPage *p = &pCsr->aPage[pCsr->iPage];
155709
+ pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155710
+ pCsr->iPageno = p->iPgno;
155711
+
155712
+ rc = statDecodePage(pBt, p);
155713
+ if( rc==SQLITE_OK ){
155714
+ statSizeAndOffset(pCsr);
155715
+
155716
+ switch( p->flags ){
155717
+ case 0x05: /* table internal */
155718
+ case 0x02: /* index internal */
155719
+ pCsr->zPagetype = "internal";
155720
+ break;
155721
+ case 0x0D: /* table leaf */
155722
+ case 0x0A: /* index leaf */
155723
+ pCsr->zPagetype = "leaf";
155724
+ break;
155725
+ default:
155726
+ pCsr->zPagetype = "corrupted";
155727
+ break;
155728
+ }
155729
+ pCsr->nCell = p->nCell;
155730
+ pCsr->nUnused = p->nUnused;
155731
+ pCsr->nMxPayload = p->nMxPayload;
155732
+ pCsr->zPath = sqlite3_mprintf("%s", p->zPath);
155733
+ nPayload = 0;
155734
+ for(i=0; i<p->nCell; i++){
155735
+ nPayload += p->aCell[i].nLocal;
155736
+ }
155737
+ pCsr->nPayload = nPayload;
155738
+ }
155739
+ }
155740
+
155741
+ return rc;
155742
+}
155743
+
155744
+static int statEof(sqlite3_vtab_cursor *pCursor){
155745
+ StatCursor *pCsr = (StatCursor *)pCursor;
155746
+ return pCsr->isEof;
155747
+}
155748
+
155749
+static int statFilter(
155750
+ sqlite3_vtab_cursor *pCursor,
155751
+ int idxNum, const char *idxStr,
155752
+ int argc, sqlite3_value **argv
155753
+){
155754
+ StatCursor *pCsr = (StatCursor *)pCursor;
155755
+
155756
+ statResetCsr(pCsr);
155757
+ return statNext(pCursor);
155758
+}
155759
+
155760
+static int statColumn(
155761
+ sqlite3_vtab_cursor *pCursor,
155762
+ sqlite3_context *ctx,
155763
+ int i
155764
+){
155765
+ StatCursor *pCsr = (StatCursor *)pCursor;
155766
+ switch( i ){
155767
+ case 0: /* name */
155768
+ sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_STATIC);
155769
+ break;
155770
+ case 1: /* path */
155771
+ sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
155772
+ break;
155773
+ case 2: /* pageno */
155774
+ sqlite3_result_int64(ctx, pCsr->iPageno);
155775
+ break;
155776
+ case 3: /* pagetype */
155777
+ sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC);
155778
+ break;
155779
+ case 4: /* ncell */
155780
+ sqlite3_result_int(ctx, pCsr->nCell);
155781
+ break;
155782
+ case 5: /* payload */
155783
+ sqlite3_result_int(ctx, pCsr->nPayload);
155784
+ break;
155785
+ case 6: /* unused */
155786
+ sqlite3_result_int(ctx, pCsr->nUnused);
155787
+ break;
155788
+ case 7: /* mx_payload */
155789
+ sqlite3_result_int(ctx, pCsr->nMxPayload);
155790
+ break;
155791
+ case 8: /* pgoffset */
155792
+ sqlite3_result_int64(ctx, pCsr->iOffset);
155793
+ break;
155794
+ case 9: /* pgsize */
155795
+ sqlite3_result_int(ctx, pCsr->szPage);
155796
+ break;
155797
+ }
155798
+ return SQLITE_OK;
155799
+}
155800
+
155801
+static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
155802
+ StatCursor *pCsr = (StatCursor *)pCursor;
155803
+ *pRowid = pCsr->iPageno;
155804
+ return SQLITE_OK;
155805
+}
155806
+
155807
+/*
155808
+** Invoke this routine to register the "dbstat" virtual table module
155809
+*/
155810
+SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){
155811
+ static sqlite3_module dbstat_module = {
155812
+ 0, /* iVersion */
155813
+ statConnect, /* xCreate */
155814
+ statConnect, /* xConnect */
155815
+ statBestIndex, /* xBestIndex */
155816
+ statDisconnect, /* xDisconnect */
155817
+ statDisconnect, /* xDestroy */
155818
+ statOpen, /* xOpen - open a cursor */
155819
+ statClose, /* xClose - close a cursor */
155820
+ statFilter, /* xFilter - configure scan constraints */
155821
+ statNext, /* xNext - advance a cursor */
155822
+ statEof, /* xEof - check for end of scan */
155823
+ statColumn, /* xColumn - read data */
155824
+ statRowid, /* xRowid - read data */
155825
+ 0, /* xUpdate */
155826
+ 0, /* xBegin */
155827
+ 0, /* xSync */
155828
+ 0, /* xCommit */
155829
+ 0, /* xRollback */
155830
+ 0, /* xFindMethod */
155831
+ 0, /* xRename */
155832
+ };
155833
+ return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
155834
+}
155835
+#endif /* SQLITE_ENABLE_DBSTAT_VTAB */
155836
+
155837
+/************** End of dbstat.c **********************************************/
154634155838
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.9. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -68,10 +68,11 @@
68 #if defined(_MSC_VER)
69 #pragma warning(disable : 4054)
70 #pragma warning(disable : 4055)
71 #pragma warning(disable : 4100)
72 #pragma warning(disable : 4127)
 
73 #pragma warning(disable : 4152)
74 #pragma warning(disable : 4189)
75 #pragma warning(disable : 4206)
76 #pragma warning(disable : 4210)
77 #pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
315 **
316 ** See also: [sqlite3_libversion()],
317 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318 ** [sqlite_version()] and [sqlite_source_id()].
319 */
320 #define SQLITE_VERSION "3.8.9"
321 #define SQLITE_VERSION_NUMBER 3008009
322 #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
323
324 /*
325 ** CAPI3REF: Run-Time Library Version Numbers
326 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
327 **
@@ -474,10 +475,11 @@
474 # define double sqlite3_int64
475 #endif
476
477 /*
478 ** CAPI3REF: Closing A Database Connection
 
479 **
480 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
481 ** for the [sqlite3] object.
482 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
483 ** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
525 */
526 typedef int (*sqlite3_callback)(void*,int,char**, char**);
527
528 /*
529 ** CAPI3REF: One-Step Query Execution Interface
 
530 **
531 ** The sqlite3_exec() interface is a convenience wrapper around
532 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
533 ** that allows an application to run multiple statements of SQL
534 ** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
1582 */
1583 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1584
1585 /*
1586 ** CAPI3REF: Configure database connections
 
1587 **
1588 ** The sqlite3_db_config() interface is used to make configuration
1589 ** changes to a [database connection]. The interface is similar to
1590 ** [sqlite3_config()] except that the changes apply to a single
1591 ** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
2079 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2080
2081
2082 /*
2083 ** CAPI3REF: Enable Or Disable Extended Result Codes
 
2084 **
2085 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2086 ** [extended result codes] feature of SQLite. ^The extended result
2087 ** codes are disabled by default for historical compatibility.
2088 */
2089 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
2090
2091 /*
2092 ** CAPI3REF: Last Insert Rowid
 
2093 **
2094 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2095 ** has a unique 64-bit signed
2096 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2097 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
2139 */
2140 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
2141
2142 /*
2143 ** CAPI3REF: Count The Number Of Rows Modified
 
2144 **
2145 ** ^This function returns the number of rows modified, inserted or
2146 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2147 ** statement on the database connection specified by the only parameter.
2148 ** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
2191 */
2192 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
2193
2194 /*
2195 ** CAPI3REF: Total Number Of Rows Modified
 
2196 **
2197 ** ^This function returns the total number of rows inserted, modified or
2198 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2199 ** since the database connection was opened, including those executed as
2200 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
2214 */
2215 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2216
2217 /*
2218 ** CAPI3REF: Interrupt A Long-Running Query
 
2219 **
2220 ** ^This function causes any pending database operation to abort and
2221 ** return at its earliest opportunity. This routine is typically
2222 ** called in response to a user action such as pressing "Cancel"
2223 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
2290 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2291
2292 /*
2293 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2294 ** KEYWORDS: {busy-handler callback} {busy handler}
 
2295 **
2296 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2297 ** that might be invoked with argument P whenever
2298 ** an attempt is made to access a database table associated with
2299 ** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
2349 */
2350 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2351
2352 /*
2353 ** CAPI3REF: Set A Busy Timeout
 
2354 **
2355 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2356 ** for a specified amount of time when a table is locked. ^The handler
2357 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2358 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
2371 */
2372 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2373
2374 /*
2375 ** CAPI3REF: Convenience Routines For Running Queries
 
2376 **
2377 ** This is a legacy interface that is preserved for backwards compatibility.
2378 ** Use of this interface is not recommended.
2379 **
2380 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
2706 */
2707 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2708
2709 /*
2710 ** CAPI3REF: Compile-Time Authorization Callbacks
 
2711 **
2712 ** ^This routine registers an authorizer callback with a particular
2713 ** [database connection], supplied in the first argument.
2714 ** ^The authorizer callback is invoked as SQL statements are being compiled
2715 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
2862 #define SQLITE_COPY 0 /* No longer used */
2863 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2864
2865 /*
2866 ** CAPI3REF: Tracing And Profiling Functions
 
2867 **
2868 ** These routines register callback functions that can be used for
2869 ** tracing and profiling the execution of SQL statements.
2870 **
2871 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
2894 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2895 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2896
2897 /*
2898 ** CAPI3REF: Query Progress Callbacks
 
2899 **
2900 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2901 ** function X to be invoked periodically during long running calls to
2902 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2903 ** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
2927 */
2928 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2929
2930 /*
2931 ** CAPI3REF: Opening A New Database Connection
 
2932 **
2933 ** ^These routines open an SQLite database file as specified by the
2934 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2935 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2936 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
3212 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3213
3214
3215 /*
3216 ** CAPI3REF: Error Codes And Messages
 
3217 **
3218 ** ^If the most recent sqlite3_* API call associated with
3219 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3220 ** returns the numeric [result code] or [extended result code] for that
3221 ** API call.
@@ -3257,37 +3274,38 @@
3257 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3258 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3259 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3260
3261 /*
3262 ** CAPI3REF: SQL Statement Object
3263 ** KEYWORDS: {prepared statement} {prepared statements}
3264 **
3265 ** An instance of this object represents a single SQL statement.
3266 ** This object is variously known as a "prepared statement" or a
3267 ** "compiled SQL statement" or simply as a "statement".
3268 **
3269 ** The life of a statement object goes something like this:
 
 
 
 
 
3270 **
3271 ** <ol>
3272 ** <li> Create the object using [sqlite3_prepare_v2()] or a related
3273 ** function.
3274 ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3275 ** interfaces.
3276 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3277 ** <li> Reset the statement using [sqlite3_reset()] then go back
3278 ** to step 2. Do this zero or more times.
3279 ** <li> Destroy the object using [sqlite3_finalize()].
3280 ** </ol>
3281 **
3282 ** Refer to documentation on individual methods above for additional
3283 ** information.
3284 */
3285 typedef struct sqlite3_stmt sqlite3_stmt;
3286
3287 /*
3288 ** CAPI3REF: Run-time Limits
 
3289 **
3290 ** ^(This interface allows the size of various constructs to be limited
3291 ** on a connection by connection basis. The first parameter is the
3292 ** [database connection] whose limit is to be set or queried. The
3293 ** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
3395 #define SQLITE_LIMIT_WORKER_THREADS 11
3396
3397 /*
3398 ** CAPI3REF: Compiling An SQL Statement
3399 ** KEYWORDS: {SQL statement compiler}
 
 
3400 **
3401 ** To execute an SQL query, it must first be compiled into a byte-code
3402 ** program using one of these routines.
3403 **
3404 ** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
3502 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3503 );
3504
3505 /*
3506 ** CAPI3REF: Retrieving Statement SQL
 
3507 **
3508 ** ^This interface can be used to retrieve a saved copy of the original
3509 ** SQL text used to create a [prepared statement] if that statement was
3510 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3511 */
3512 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3513
3514 /*
3515 ** CAPI3REF: Determine If An SQL Statement Writes The Database
 
3516 **
3517 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3518 ** and only if the [prepared statement] X makes no direct changes to
3519 ** the content of the database file.
3520 **
@@ -3542,10 +3564,11 @@
3542 */
3543 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3544
3545 /*
3546 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
 
3547 **
3548 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3549 ** [prepared statement] S has been stepped at least once using
3550 ** [sqlite3_step(S)] but has not run to completion and/or has not
3551 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
3616
3617 /*
3618 ** CAPI3REF: Binding Values To Prepared Statements
3619 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3620 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 
3621 **
3622 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3623 ** literals may be replaced by a [parameter] that matches one of following
3624 ** templates:
3625 **
@@ -3734,10 +3758,11 @@
3734 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3735 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3736
3737 /*
3738 ** CAPI3REF: Number Of SQL Parameters
 
3739 **
3740 ** ^This routine can be used to find the number of [SQL parameters]
3741 ** in a [prepared statement]. SQL parameters are tokens of the
3742 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3743 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
3754 */
3755 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3756
3757 /*
3758 ** CAPI3REF: Name Of A Host Parameter
 
3759 **
3760 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3761 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3762 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3763 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
3781 */
3782 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3783
3784 /*
3785 ** CAPI3REF: Index Of A Parameter With A Given Name
 
3786 **
3787 ** ^Return the index of an SQL parameter given its name. ^The
3788 ** index value returned is suitable for use as the second
3789 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3790 ** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
3797 */
3798 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3799
3800 /*
3801 ** CAPI3REF: Reset All Bindings On A Prepared Statement
 
3802 **
3803 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3804 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3805 ** ^Use this routine to reset all host parameters to NULL.
3806 */
3807 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3808
3809 /*
3810 ** CAPI3REF: Number Of Columns In A Result Set
 
3811 **
3812 ** ^Return the number of columns in the result set returned by the
3813 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3814 ** statement that does not return data (for example an [UPDATE]).
3815 **
@@ -3817,10 +3846,11 @@
3817 */
3818 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3819
3820 /*
3821 ** CAPI3REF: Column Names In A Result Set
 
3822 **
3823 ** ^These routines return the name assigned to a particular column
3824 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3825 ** interface returns a pointer to a zero-terminated UTF-8 string
3826 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
3846 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3847 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3848
3849 /*
3850 ** CAPI3REF: Source Of Data In A Query Result
 
3851 **
3852 ** ^These routines provide a means to determine the database, table, and
3853 ** table column that is the origin of a particular result column in
3854 ** [SELECT] statement.
3855 ** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
3898 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3899 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3900
3901 /*
3902 ** CAPI3REF: Declared Datatype Of A Query Result
 
3903 **
3904 ** ^(The first parameter is a [prepared statement].
3905 ** If this statement is a [SELECT] statement and the Nth column of the
3906 ** returned result set of that [SELECT] is a table column (not an
3907 ** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
3930 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3931 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3932
3933 /*
3934 ** CAPI3REF: Evaluate An SQL Statement
 
3935 **
3936 ** After a [prepared statement] has been prepared using either
3937 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3938 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3939 ** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
4009 */
4010 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
4011
4012 /*
4013 ** CAPI3REF: Number of columns in a result set
 
4014 **
4015 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4016 ** current row of the result set of [prepared statement] P.
4017 ** ^If prepared statement P does not have results ready to return
4018 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
4062 #define SQLITE3_TEXT 3
4063
4064 /*
4065 ** CAPI3REF: Result Values From A Query
4066 ** KEYWORDS: {column access functions}
 
4067 **
4068 ** These routines form the "result set" interface.
4069 **
4070 ** ^These routines return information about a single column of the current
4071 ** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
4234 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4235 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4236
4237 /*
4238 ** CAPI3REF: Destroy A Prepared Statement Object
 
4239 **
4240 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4241 ** ^If the most recent evaluation of the statement encountered no errors
4242 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4243 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
4261 */
4262 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4263
4264 /*
4265 ** CAPI3REF: Reset A Prepared Statement Object
 
4266 **
4267 ** The sqlite3_reset() function is called to reset a [prepared statement]
4268 ** object back to its initial state, ready to be re-executed.
4269 ** ^Any SQL statement variables that had values bound to them using
4270 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
4290 /*
4291 ** CAPI3REF: Create Or Redefine SQL Functions
4292 ** KEYWORDS: {function creation routines}
4293 ** KEYWORDS: {application-defined SQL function}
4294 ** KEYWORDS: {application-defined SQL functions}
 
4295 **
4296 ** ^These functions (collectively known as "function creation routines")
4297 ** are used to add SQL functions or aggregates or to redefine the behavior
4298 ** of existing SQL functions or aggregates. The only differences between
4299 ** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
4459 void*,sqlite3_int64);
4460 #endif
4461
4462 /*
4463 ** CAPI3REF: Obtaining SQL Function Parameter Values
 
4464 **
4465 ** The C-language implementation of SQL functions and aggregates uses
4466 ** this set of interface routines to access the parameter values on
4467 ** the function or aggregate.
4468 **
@@ -4517,10 +4556,11 @@
4517 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4518 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4519
4520 /*
4521 ** CAPI3REF: Obtain Aggregate Function Context
 
4522 **
4523 ** Implementations of aggregate SQL functions use this
4524 ** routine to allocate memory for storing their state.
4525 **
4526 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
4561 */
4562 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4563
4564 /*
4565 ** CAPI3REF: User Data For Functions
 
4566 **
4567 ** ^The sqlite3_user_data() interface returns a copy of
4568 ** the pointer that was the pUserData parameter (the 5th parameter)
4569 ** of the [sqlite3_create_function()]
4570 ** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
4575 */
4576 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4577
4578 /*
4579 ** CAPI3REF: Database Connection For Functions
 
4580 **
4581 ** ^The sqlite3_context_db_handle() interface returns a copy of
4582 ** the pointer to the [database connection] (the 1st parameter)
4583 ** of the [sqlite3_create_function()]
4584 ** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
4586 */
4587 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4588
4589 /*
4590 ** CAPI3REF: Function Auxiliary Data
 
4591 **
4592 ** These functions may be used by (non-aggregate) SQL functions to
4593 ** associate metadata with argument values. If the same value is passed to
4594 ** multiple invocations of the same SQL function during query execution, under
4595 ** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
4658 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4659 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4660
4661 /*
4662 ** CAPI3REF: Setting The Result Of An SQL Function
 
4663 **
4664 ** These routines are used by the xFunc or xFinal callbacks that
4665 ** implement SQL functions and aggregates. See
4666 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4667 ** for additional information.
@@ -4793,10 +4837,11 @@
4793 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4794 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4795
4796 /*
4797 ** CAPI3REF: Define New Collating Sequences
 
4798 **
4799 ** ^These functions add, remove, or modify a [collation] associated
4800 ** with the [database connection] specified as the first argument.
4801 **
4802 ** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
4895 int(*xCompare)(void*,int,const void*,int,const void*)
4896 );
4897
4898 /*
4899 ** CAPI3REF: Collation Needed Callbacks
 
4900 **
4901 ** ^To avoid having to register all collation sequences before a database
4902 ** can be used, a single callback function may be registered with the
4903 ** [database connection] to be invoked whenever an undefined collation
4904 ** sequence is required.
@@ -5102,10 +5148,11 @@
5102 SQLITE_API char *sqlite3_data_directory;
5103
5104 /*
5105 ** CAPI3REF: Test For Auto-Commit Mode
5106 ** KEYWORDS: {autocommit mode}
 
5107 **
5108 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5109 ** zero if the given database connection is or is not in autocommit mode,
5110 ** respectively. ^Autocommit mode is on by default.
5111 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
5124 */
5125 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
5126
5127 /*
5128 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 
5129 **
5130 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5131 ** to which a [prepared statement] belongs. ^The [database connection]
5132 ** returned by sqlite3_db_handle is the same [database connection]
5133 ** that was the first argument
@@ -5136,10 +5184,11 @@
5136 */
5137 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
5138
5139 /*
5140 ** CAPI3REF: Return The Filename For A Database Connection
 
5141 **
5142 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5143 ** associated with database N of connection D. ^The main database file
5144 ** has the name "main". If there is no attached database N on the database
5145 ** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
5152 */
5153 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5154
5155 /*
5156 ** CAPI3REF: Determine if a database is read-only
 
5157 **
5158 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5159 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5160 ** the name of a database on connection D.
5161 */
5162 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5163
5164 /*
5165 ** CAPI3REF: Find the next prepared statement
 
5166 **
5167 ** ^This interface returns a pointer to the next [prepared statement] after
5168 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5169 ** then this interface returns a pointer to the first prepared statement
5170 ** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
5176 */
5177 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5178
5179 /*
5180 ** CAPI3REF: Commit And Rollback Notification Callbacks
 
5181 **
5182 ** ^The sqlite3_commit_hook() interface registers a callback
5183 ** function to be invoked whenever a transaction is [COMMIT | committed].
5184 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5185 ** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
5225 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5226 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5227
5228 /*
5229 ** CAPI3REF: Data Change Notification Callbacks
 
5230 **
5231 ** ^The sqlite3_update_hook() interface registers a callback function
5232 ** with the [database connection] identified by the first argument
5233 ** to be invoked whenever a row is updated, inserted or deleted in
5234 ** a rowid table.
@@ -5331,10 +5384,11 @@
5331 */
5332 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5333
5334 /*
5335 ** CAPI3REF: Free Memory Used By A Database Connection
 
5336 **
5337 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5338 ** memory as possible from database connection D. Unlike the
5339 ** [sqlite3_release_memory()] interface, this interface is in effect even
5340 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
5408 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5409
5410
5411 /*
5412 ** CAPI3REF: Extract Metadata About A Column Of A Table
 
5413 **
5414 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5415 ** information about column C of table T in database D
5416 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5417 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
5486 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5487 );
5488
5489 /*
5490 ** CAPI3REF: Load An Extension
 
5491 **
5492 ** ^This interface loads an SQLite extension library from the named file.
5493 **
5494 ** ^The sqlite3_load_extension() interface attempts to load an
5495 ** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
5527 char **pzErrMsg /* Put error message here if not 0 */
5528 );
5529
5530 /*
5531 ** CAPI3REF: Enable Or Disable Extension Loading
 
5532 **
5533 ** ^So as not to open security holes in older applications that are
5534 ** unprepared to deal with [extension loading], and as a means of disabling
5535 ** [extension loading] while evaluating user-entered SQL, the following API
5536 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
5776 #define SQLITE_INDEX_CONSTRAINT_GE 32
5777 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5778
5779 /*
5780 ** CAPI3REF: Register A Virtual Table Implementation
 
5781 **
5782 ** ^These routines are used to register a new [virtual table module] name.
5783 ** ^Module names must be registered before
5784 ** creating a new [virtual table] using the module and before using a
5785 ** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
5872 */
5873 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5874
5875 /*
5876 ** CAPI3REF: Overload A Function For A Virtual Table
 
5877 **
5878 ** ^(Virtual tables can provide alternative implementations of functions
5879 ** using the [xFindFunction] method of the [virtual table module].
5880 ** But global versions of those functions
5881 ** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
5914 */
5915 typedef struct sqlite3_blob sqlite3_blob;
5916
5917 /*
5918 ** CAPI3REF: Open A BLOB For Incremental I/O
 
 
5919 **
5920 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5921 ** in row iRow, column zColumn, table zTable in database zDb;
5922 ** in other words, the same BLOB that would be selected by:
5923 **
@@ -5995,10 +6056,11 @@
5995 sqlite3_blob **ppBlob
5996 );
5997
5998 /*
5999 ** CAPI3REF: Move a BLOB Handle to a New Row
 
6000 **
6001 ** ^This function is used to move an existing blob handle so that it points
6002 ** to a different row of the same database table. ^The new row is identified
6003 ** by the rowid value passed as the second argument. Only the row can be
6004 ** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
6019 */
6020 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
6021
6022 /*
6023 ** CAPI3REF: Close A BLOB Handle
 
6024 **
6025 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
6026 ** unconditionally. Even if this routine returns an error code, the
6027 ** handle is still closed.)^
6028 **
@@ -6041,10 +6104,11 @@
6041 */
6042 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
6043
6044 /*
6045 ** CAPI3REF: Return The Size Of An Open BLOB
 
6046 **
6047 ** ^Returns the size in bytes of the BLOB accessible via the
6048 ** successfully opened [BLOB handle] in its only argument. ^The
6049 ** incremental blob I/O routines can only read or overwriting existing
6050 ** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
6056 */
6057 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
6058
6059 /*
6060 ** CAPI3REF: Read Data From A BLOB Incrementally
 
6061 **
6062 ** ^(This function is used to read data from an open [BLOB handle] into a
6063 ** caller-supplied buffer. N bytes of data are copied into buffer Z
6064 ** from the open BLOB, starting at offset iOffset.)^
6065 **
@@ -6084,10 +6149,11 @@
6084 */
6085 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
6086
6087 /*
6088 ** CAPI3REF: Write Data Into A BLOB Incrementally
 
6089 **
6090 ** ^(This function is used to write data into an open [BLOB handle] from a
6091 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
6092 ** into the open BLOB, starting at offset iOffset.)^
6093 **
@@ -6411,10 +6477,11 @@
6411 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6412 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6413
6414 /*
6415 ** CAPI3REF: Retrieve the mutex for a database connection
 
6416 **
6417 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6418 ** serializes access to the [database connection] given in the argument
6419 ** when the [threading mode] is Serialized.
6420 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
6422 */
6423 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6424
6425 /*
6426 ** CAPI3REF: Low-Level Control Of Database Files
 
6427 **
6428 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6429 ** xFileControl method for the [sqlite3_io_methods] object associated
6430 ** with a particular database identified by the second argument. ^The
6431 ** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
6638 #define SQLITE_STATUS_SCRATCH_SIZE 8
6639 #define SQLITE_STATUS_MALLOC_COUNT 9
6640
6641 /*
6642 ** CAPI3REF: Database Connection Status
 
6643 **
6644 ** ^This interface is used to retrieve runtime status information
6645 ** about a single [database connection]. ^The first argument is the
6646 ** database connection object to be interrogated. ^The second argument
6647 ** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
6766 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6767
6768
6769 /*
6770 ** CAPI3REF: Prepared Statement Status
 
6771 **
6772 ** ^(Each prepared statement maintains various
6773 ** [SQLITE_STMTSTATUS counters] that measure the number
6774 ** of times it has performed specific operations.)^ These counters can
6775 ** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
7269 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7270 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7271
7272 /*
7273 ** CAPI3REF: Unlock Notification
 
7274 **
7275 ** ^When running in shared-cache mode, a database operation may fail with
7276 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7277 ** individual tables within the shared-cache cannot be obtained. See
7278 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
7439 */
7440 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7441
7442 /*
7443 ** CAPI3REF: Write-Ahead Log Commit Hook
 
7444 **
7445 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7446 ** is invoked each time data is committed to a database in wal mode.
7447 **
7448 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
7478 void*
7479 );
7480
7481 /*
7482 ** CAPI3REF: Configure an auto-checkpoint
 
7483 **
7484 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7485 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7486 ** to automatically [checkpoint]
7487 ** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
7508 */
7509 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7510
7511 /*
7512 ** CAPI3REF: Checkpoint a database
 
7513 **
7514 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7515 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7516 **
7517 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
7529 */
7530 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7531
7532 /*
7533 ** CAPI3REF: Checkpoint a database
 
7534 **
7535 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7536 ** operation on database X of [database connection] D in mode M. Status
7537 ** information is written back into integers pointed to by L and C.)^
7538 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
7783 #define SQLITE_SCANSTAT_EXPLAIN 4
7784 #define SQLITE_SCANSTAT_SELECTID 5
7785
7786 /*
7787 ** CAPI3REF: Prepared Statement Scan Status
 
7788 **
7789 ** This interface returns information about the predicted and measured
7790 ** performance for pStmt. Advanced applications can use this
7791 ** interface to compare the predicted and the measured performance and
7792 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
7820 void *pOut /* Result written here */
7821 );
7822
7823 /*
7824 ** CAPI3REF: Zero Scan-Status Counters
 
7825 **
7826 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7827 **
7828 ** This API is only available if the library is built with pre-processor
7829 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
8430 #else
8431 # define ALWAYS(X) (X)
8432 # define NEVER(X) (X)
8433 #endif
8434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8435 /*
8436 ** Return true (non-zero) if the input is an integer that is too large
8437 ** to fit in 32-bits. This macro is used inside of various testcase()
8438 ** macros to verify that we have tested SQLite for large-file support.
8439 */
@@ -9841,37 +9944,36 @@
9841 /* Properties such as "out2" or "jump" that are specified in
9842 ** comments following the "case" for each opcode in the vdbe.c
9843 ** are encoded into bitvectors as follows:
9844 */
9845 #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9846 #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
9847 #define OPFLG_IN1 0x0004 /* in1: P1 is an input */
9848 #define OPFLG_IN2 0x0008 /* in2: P2 is an input */
9849 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9850 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9851 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9852 #define OPFLG_INITIALIZER {\
9853 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9854 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9855 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9856 /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9857 /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9858 /* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\
9859 /* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\
9860 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\
9861 /* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\
9862 /* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\
9863 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9864 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9865 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9866 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9867 /* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9868 /* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9869 /* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9870 /* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9871 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9872 /* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9873
9874 /************** End of opcodes.h *********************************************/
9875 /************** Continuing where we left off in vdbe.h ***********************/
9876
9877 /*
@@ -9926,10 +10028,11 @@
9926 #endif
9927 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
9928
9929 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9930 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
 
9931 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9932
9933 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
9934 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
9935
@@ -11063,10 +11166,11 @@
11063 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
11064 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
11065 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
11066 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
11067 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
 
11068
11069
11070 /*
11071 ** Bits of the sqlite3.dbOptFlags field that are used by the
11072 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
11393 int iSavepoint; /* Depth of the SAVEPOINT stack */
11394 VTable *pNext; /* Next in linked list (see above) */
11395 };
11396
11397 /*
11398 ** Each SQL table is represented in memory by an instance of the
11399 ** following structure.
11400 **
11401 ** Table.zName is the name of the table. The case of the original
11402 ** CREATE TABLE statement is stored, but case is not significant for
11403 ** comparisons.
11404 **
11405 ** Table.nCol is the number of columns in this table. Table.aCol is a
11406 ** pointer to an array of Column structures, one for each column.
11407 **
11408 ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
11409 ** the column that is that key. Otherwise Table.iPKey is negative. Note
11410 ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
11411 ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
11412 ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
11413 ** is generated for each row of the table. TF_HasPrimaryKey is set if
11414 ** the table has any PRIMARY KEY, INTEGER or otherwise.
11415 **
11416 ** Table.tnum is the page number for the root BTree page of the table in the
11417 ** database file. If Table.iDb is the index of the database table backend
11418 ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
11419 ** holds temporary tables and indices. If TF_Ephemeral is set
11420 ** then the table is stored in a file that is automatically deleted
11421 ** when the VDBE cursor to the table is closed. In this case Table.tnum
11422 ** refers VDBE cursor number that holds the table open, not to the root
11423 ** page number. Transient tables are used to hold the results of a
11424 ** sub-query that appears instead of a real table name in the FROM clause
11425 ** of a SELECT statement.
11426 */
11427 struct Table {
11428 char *zName; /* Name of the table or view */
11429 Column *aCol; /* Information about each column */
11430 Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
11432 FKey *pFKey; /* Linked list of all foreign keys in this table */
11433 char *zColAff; /* String defining the affinity of each column */
11434 #ifndef SQLITE_OMIT_CHECK
11435 ExprList *pCheck; /* All CHECK constraints */
11436 #endif
11437 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11438 int tnum; /* Root BTree node for this table (see note above) */
11439 i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
11440 i16 nCol; /* Number of columns in this table */
11441 u16 nRef; /* Number of pointers to this Table */
 
11442 LogEst szTabRow; /* Estimated size of each table row in bytes */
11443 #ifdef SQLITE_ENABLE_COSTMULT
11444 LogEst costMult; /* Cost multiplier for using this table */
11445 #endif
11446 u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
11458 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
11459 };
11460
11461 /*
11462 ** Allowed values for Table.tabFlags.
 
 
 
 
 
 
11463 */
11464 #define TF_Readonly 0x01 /* Read-only system table */
11465 #define TF_Ephemeral 0x02 /* An ephemeral table */
11466 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
11467 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
11468 #define TF_Virtual 0x10 /* Is a virtual table */
11469 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
 
11470
11471
11472 /*
11473 ** Test to see whether or not a table is a virtual table. This is
11474 ** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
12221 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12222 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12223 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12224 #define SF_Compound 0x0040 /* Part of a compound query */
12225 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12226 #define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12227 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12228 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12229 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12230 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12231 #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
12605 *
12606 * (op == TK_INSERT)
12607 * orconf -> stores the ON CONFLICT algorithm
12608 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
12609 * this stores a pointer to the SELECT statement. Otherwise NULL.
12610 * target -> A token holding the quoted name of the table to insert into.
12611 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
12612 * this stores values to be inserted. Otherwise NULL.
12613 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
12614 * statement, then this stores the column-names to be
12615 * inserted into.
12616 *
12617 * (op == TK_DELETE)
12618 * target -> A token holding the quoted name of the table to delete from.
12619 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
12620 * Otherwise NULL.
12621 *
12622 * (op == TK_UPDATE)
12623 * target -> A token holding the quoted name of the table to update rows of.
12624 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
12625 * Otherwise NULL.
12626 * pExprList -> A list of the columns to update and the expressions to update
12627 * them to. See sqlite3Update() documentation of "pChanges"
12628 * argument.
@@ -12630,12 +12715,12 @@
12630 */
12631 struct TriggerStep {
12632 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
12633 u8 orconf; /* OE_Rollback etc. */
12634 Trigger *pTrig; /* The trigger that this step is a part of */
12635 Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
12636 Token target; /* Target table for DELETE, UPDATE, INSERT */
12637 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
12638 ExprList *pExprList; /* SET clause for UPDATE. */
12639 IdList *pIdList; /* Column names for INSERT */
12640 TriggerStep *pNext; /* Next in the link-list */
12641 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
12664 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
12665 char *zBase; /* A base allocation. Not from malloc. */
12666 char *zText; /* The string collected so far */
12667 int nChar; /* Length of the string so far */
12668 int nAlloc; /* Amount of space allocated in zText */
12669 int mxAlloc; /* Maximum allowed string length */
12670 u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
12671 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
12672 };
12673 #define STRACCUM_NOMEM 1
12674 #define STRACCUM_TOOBIG 2
12675
@@ -12982,11 +13066,11 @@
12982 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
12983 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
12984 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
12985 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
12986 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12987 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
12988 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
12989 #endif
12990 #if defined(SQLITE_TEST)
12991 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
12992 #endif
@@ -13329,11 +13413,11 @@
13329 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
13330 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
13331 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
13332 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
13333
13334 #if defined(SQLITE_TEST)
13335 SQLITE_PRIVATE const char *sqlite3ErrName(int);
13336 #endif
13337
13338 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13339 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
13423 FuncDestructor *pDestructor
13424 );
13425 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
13426 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13427
13428 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13429 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13430 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13431 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
13432 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13433 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -19807,20 +19891,10 @@
19807 */
19808 #ifdef MEMORY_DEBUG
19809 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19810 #endif
19811
19812 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19813 # ifndef SQLITE_DEBUG_OS_TRACE
19814 # define SQLITE_DEBUG_OS_TRACE 0
19815 # endif
19816 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19817 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19818 #else
19819 # define OSTRACE(X)
19820 #endif
19821
19822 /*
19823 ** Macros for performance tracing. Normally turned off. Only works
19824 ** on i486 hardware.
19825 */
19826 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21475,11 @@
21401
21402 /*
21403 ** Set the StrAccum object to an error mode.
21404 */
21405 static void setStrAccumError(StrAccum *p, u8 eError){
 
21406 p->accError = eError;
21407 p->nAlloc = 0;
21408 }
21409
21410 /*
@@ -22018,11 +22093,11 @@
22018 if( p->accError ){
22019 testcase(p->accError==STRACCUM_TOOBIG);
22020 testcase(p->accError==STRACCUM_NOMEM);
22021 return 0;
22022 }
22023 if( !p->useMalloc ){
22024 N = p->nAlloc - p->nChar - 1;
22025 setStrAccumError(p, STRACCUM_TOOBIG);
22026 return N;
22027 }else{
22028 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22113,14 @@
22038 setStrAccumError(p, STRACCUM_TOOBIG);
22039 return 0;
22040 }else{
22041 p->nAlloc = (int)szNew;
22042 }
22043 if( p->useMalloc==1 ){
22044 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22045 }else{
22046 zNew = sqlite3_realloc(zOld, p->nAlloc);
22047 }
22048 if( zNew ){
22049 assert( p->zText!=0 || p->nChar==0 );
22050 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
22051 p->zText = zNew;
@@ -22089,11 +22164,11 @@
22089 /*
22090 ** Append N bytes of text from z to the StrAccum object. Increase the
22091 ** size of the memory allocation for StrAccum if necessary.
22092 */
22093 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22094 assert( z!=0 );
22095 assert( p->zText!=0 || p->nChar==0 || p->accError );
22096 assert( N>=0 );
22097 assert( p->accError==0 || p->nAlloc==0 );
22098 if( p->nChar+N >= p->nAlloc ){
22099 enlargeAndAppend(p,z,N);
@@ -22118,16 +22193,12 @@
22118 ** pointer if any kind of error was encountered.
22119 */
22120 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
22121 if( p->zText ){
22122 p->zText[p->nChar] = 0;
22123 if( p->useMalloc && p->zText==p->zBase ){
22124 if( p->useMalloc==1 ){
22125 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22126 }else{
22127 p->zText = sqlite3_malloc(p->nChar+1);
22128 }
22129 if( p->zText ){
22130 memcpy(p->zText, p->zBase, p->nChar+1);
22131 }else{
22132 setStrAccumError(p, STRACCUM_NOMEM);
22133 }
@@ -22139,29 +22210,35 @@
22139 /*
22140 ** Reset an StrAccum string. Reclaim all malloced memory.
22141 */
22142 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
22143 if( p->zText!=p->zBase ){
22144 if( p->useMalloc==1 ){
22145 sqlite3DbFree(p->db, p->zText);
22146 }else{
22147 sqlite3_free(p->zText);
22148 }
22149 }
22150 p->zText = 0;
22151 }
22152
22153 /*
22154 ** Initialize a string accumulator
 
 
 
 
 
 
 
 
 
 
 
22155 */
22156 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
22157 p->zText = p->zBase = zBase;
22158 p->db = 0;
22159 p->nChar = 0;
22160 p->nAlloc = n;
22161 p->mxAlloc = mx;
22162 p->useMalloc = 1;
22163 p->accError = 0;
22164 }
22165
22166 /*
22167 ** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22247,12 @@
22170 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
22171 char *z;
22172 char zBase[SQLITE_PRINT_BUF_SIZE];
22173 StrAccum acc;
22174 assert( db!=0 );
22175 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
22176 db->aLimit[SQLITE_LIMIT_LENGTH]);
22177 acc.db = db;
22178 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
22179 z = sqlite3StrAccumFinish(&acc);
22180 if( acc.accError==STRACCUM_NOMEM ){
22181 db->mallocFailed = 1;
22182 }
@@ -22230,12 +22306,11 @@
22230 }
22231 #endif
22232 #ifndef SQLITE_OMIT_AUTOINIT
22233 if( sqlite3_initialize() ) return 0;
22234 #endif
22235 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
22236 acc.useMalloc = 2;
22237 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22238 z = sqlite3StrAccumFinish(&acc);
22239 return z;
22240 }
22241
@@ -22276,12 +22351,11 @@
22276 (void)SQLITE_MISUSE_BKPT;
22277 if( zBuf ) zBuf[0] = 0;
22278 return zBuf;
22279 }
22280 #endif
22281 sqlite3StrAccumInit(&acc, zBuf, n, 0);
22282 acc.useMalloc = 0;
22283 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22284 return sqlite3StrAccumFinish(&acc);
22285 }
22286 SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
22287 char *z;
@@ -22303,12 +22377,11 @@
22303 */
22304 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22305 StrAccum acc; /* String accumulator */
22306 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22307
22308 sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
22309 acc.useMalloc = 0;
22310 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22311 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
22312 sqlite3StrAccumFinish(&acc));
22313 }
22314
@@ -22322,22 +22395,21 @@
22322 renderLogMsg(iErrCode, zFormat, ap);
22323 va_end(ap);
22324 }
22325 }
22326
22327 #if defined(SQLITE_DEBUG)
22328 /*
22329 ** A version of printf() that understands %lld. Used for debugging.
22330 ** The printf() built into some versions of windows does not understand %lld
22331 ** and segfaults if you give it a long long int.
22332 */
22333 SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
22334 va_list ap;
22335 StrAccum acc;
22336 char zBuf[500];
22337 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22338 acc.useMalloc = 0;
22339 va_start(ap,zFormat);
22340 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22341 va_end(ap);
22342 sqlite3StrAccumFinish(&acc);
22343 fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22432,11 @@
22360 */
22361 /* Add a new subitem to the tree. The moreToFollow flag indicates that this
22362 ** is not the last item in the tree. */
22363 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
22364 if( p==0 ){
22365 p = sqlite3_malloc( sizeof(*p) );
22366 if( p==0 ) return 0;
22367 memset(p, 0, sizeof(*p));
22368 }else{
22369 p->iLevel++;
22370 }
@@ -22383,12 +22455,11 @@
22383 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
22384 va_list ap;
22385 int i;
22386 StrAccum acc;
22387 char zBuf[500];
22388 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22389 acc.useMalloc = 0;
22390 if( p ){
22391 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
22392 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
22393 }
22394 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24078,11 @@
24007 }else{
24008 return 0;
24009 }
24010 }
24011 #endif
 
24012 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
24013 v = v*10 + c;
24014 }
24015
24016 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25333,21 @@
25261 #if SQLITE_ENABLE_LOCKING_STYLE
25262 # include <sys/ioctl.h>
25263 # include <sys/file.h>
25264 # include <sys/param.h>
25265 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
 
 
 
 
 
 
 
 
 
 
 
25266
25267 #if OS_VXWORKS
25268 /* # include <sys/ioctl.h> */
25269 # include <semaphore.h>
25270 # include <limits.h>
@@ -25457,20 +25540,10 @@
25457 */
25458 #ifdef MEMORY_DEBUG
25459 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
25460 #endif
25461
25462 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25463 # ifndef SQLITE_DEBUG_OS_TRACE
25464 # define SQLITE_DEBUG_OS_TRACE 0
25465 # endif
25466 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
25467 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
25468 #else
25469 # define OSTRACE(X)
25470 #endif
25471
25472 /*
25473 ** Macros for performance tracing. Normally turned off. Only works
25474 ** on i486 hardware.
25475 */
25476 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26082,11 @@
26009 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26010 }
26011 #endif
26012
26013
26014 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
26015 /*
26016 ** Helper function for printing out trace information from debugging
26017 ** binaries. This returns the string representation of the supplied
26018 ** integer lock-type.
26019 */
@@ -26272,11 +26345,11 @@
26272 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
26273 int n; /* Length of zAbsoluteName string */
26274
26275 assert( zAbsoluteName[0]=='/' );
26276 n = (int)strlen(zAbsoluteName);
26277 pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) );
26278 if( pNew==0 ) return 0;
26279 pNew->zCanonicalName = (char*)&pNew[1];
26280 memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
26281 n = vxworksSimplifyName(pNew->zCanonicalName, n);
26282
@@ -26676,11 +26749,11 @@
26676 pInode = inodeList;
26677 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
26678 pInode = pInode->pNext;
26679 }
26680 if( pInode==0 ){
26681 pInode = sqlite3_malloc( sizeof(*pInode) );
26682 if( pInode==0 ){
26683 return SQLITE_NOMEM;
26684 }
26685 memset(pInode, 0, sizeof(*pInode));
26686 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29270,11 @@
29197 case SQLITE_FCNTL_VFSNAME: {
29198 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
29199 return SQLITE_OK;
29200 }
29201 case SQLITE_FCNTL_TEMPFILENAME: {
29202 char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
29203 if( zTFile ){
29204 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
29205 *(char**)pArg = zTFile;
29206 }
29207 return SQLITE_OK;
@@ -29638,11 +29711,11 @@
29638 unixInodeInfo *pInode; /* The inode of fd */
29639 char *zShmFilename; /* Name of the file used for SHM */
29640 int nShmFilename; /* Size of the SHM filename in bytes */
29641
29642 /* Allocate space for the new unixShm object. */
29643 p = sqlite3_malloc( sizeof(*p) );
29644 if( p==0 ) return SQLITE_NOMEM;
29645 memset(p, 0, sizeof(*p));
29646 assert( pDbFd->pShm==0 );
29647
29648 /* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29742,11 @@
29669 #ifdef SQLITE_SHM_DIRECTORY
29670 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29671 #else
29672 nShmFilename = 6 + (int)strlen(zBasePath);
29673 #endif
29674 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29675 if( pShmNode==0 ){
29676 rc = SQLITE_NOMEM;
29677 goto shm_open_err;
29678 }
29679 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29952,11 @@
29879 if( pMem==MAP_FAILED ){
29880 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
29881 goto shmpage_out;
29882 }
29883 }else{
29884 pMem = sqlite3_malloc(szRegion);
29885 if( pMem==0 ){
29886 rc = SQLITE_NOMEM;
29887 goto shmpage_out;
29888 }
29889 memset(pMem, 0, szRegion);
@@ -30716,11 +30789,11 @@
30716 else if( pLockingStyle == &afpIoMethods ){
30717 /* AFP locking uses the file path so it needs to be included in
30718 ** the afpLockingContext.
30719 */
30720 afpLockingContext *pCtx;
30721 pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) );
30722 if( pCtx==0 ){
30723 rc = SQLITE_NOMEM;
30724 }else{
30725 /* NB: zFilename exists and remains valid until the file is closed
30726 ** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30819,11 @@
30746 */
30747 char *zLockFile;
30748 int nFilename;
30749 assert( zFilename!=0 );
30750 nFilename = (int)strlen(zFilename) + 6;
30751 zLockFile = (char *)sqlite3_malloc(nFilename);
30752 if( zLockFile==0 ){
30753 rc = SQLITE_NOMEM;
30754 }else{
30755 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
30756 }
@@ -31123,11 +31196,11 @@
31123 UnixUnusedFd *pUnused;
31124 pUnused = findReusableFd(zName, flags);
31125 if( pUnused ){
31126 fd = pUnused->fd;
31127 }else{
31128 pUnused = sqlite3_malloc(sizeof(*pUnused));
31129 if( !pUnused ){
31130 return SQLITE_NOMEM;
31131 }
31132 }
31133 p->pUnused = pUnused;
@@ -31503,11 +31576,11 @@
31503 ** that we always use the same random number sequence. This makes the
31504 ** tests repeatable.
31505 */
31506 memset(zBuf, 0, nBuf);
31507 randomnessPid = osGetpid(0);
31508 #if !defined(SQLITE_TEST)
31509 {
31510 int fd, got;
31511 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31512 if( fd<0 ){
31513 time_t t;
@@ -31915,11 +31988,11 @@
31915 */
31916 pUnused = findReusableFd(path, openFlags);
31917 if( pUnused ){
31918 fd = pUnused->fd;
31919 }else{
31920 pUnused = sqlite3_malloc(sizeof(*pUnused));
31921 if( !pUnused ){
31922 return SQLITE_NOMEM;
31923 }
31924 }
31925 if( fd<0 ){
@@ -31948,11 +32021,11 @@
31948 default:
31949 return SQLITE_CANTOPEN_BKPT;
31950 }
31951 }
31952
31953 pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew));
31954 if( pNew==NULL ){
31955 rc = SQLITE_NOMEM;
31956 goto end_create_proxy;
31957 }
31958 memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32054,22 @@
31981 SQLITE_API int sqlite3_hostid_num = 0;
31982 #endif
31983
31984 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
31985
 
31986 /* Not always defined in the headers as it ought to be */
31987 extern int gethostuuid(uuid_t id, const struct timespec *wait);
 
31988
31989 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
31990 ** bytes of writable memory.
31991 */
31992 static int proxyGetHostID(unsigned char *pHostID, int *pError){
31993 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
31994 memset(pHostID, 0, PROXY_HOSTIDLEN);
31995 # if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31996 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
31997 {
31998 struct timespec timeout = {1, 0}; /* 1 sec timeout */
31999 if( gethostuuid(pHostID, &timeout) ){
32000 int err = errno;
32001 if( pError ){
@@ -32409,11 +32483,11 @@
32409 return rc;
32410 }
32411
32412 /*
32413 ** Given the name of a database file, compute the name of its conch file.
32414 ** Store the conch filename in memory obtained from sqlite3_malloc().
32415 ** Make *pConchPath point to the new name. Return SQLITE_OK on success
32416 ** or SQLITE_NOMEM if unable to obtain memory.
32417 **
32418 ** The caller is responsible for ensuring that the allocated memory
32419 ** space is eventually freed.
@@ -32425,11 +32499,11 @@
32425 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
32426 char *conchPath; /* buffer in which to construct conch name */
32427
32428 /* Allocate space for the conch filename and initialize the name to
32429 ** the name of the original database file. */
32430 *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8);
32431 if( conchPath==0 ){
32432 return SQLITE_NOMEM;
32433 }
32434 memcpy(conchPath, dbPath, len+1);
32435
@@ -32541,11 +32615,11 @@
32541 }
32542
32543 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32544 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
32545
32546 pCtx = sqlite3_malloc( sizeof(*pCtx) );
32547 if( pCtx==0 ){
32548 return SQLITE_NOMEM;
32549 }
32550 memset(pCtx, 0, sizeof(*pCtx));
32551
@@ -32985,20 +33059,10 @@
32985 */
32986 #ifdef MEMORY_DEBUG
32987 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
32988 #endif
32989
32990 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
32991 # ifndef SQLITE_DEBUG_OS_TRACE
32992 # define SQLITE_DEBUG_OS_TRACE 0
32993 # endif
32994 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
32995 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
32996 #else
32997 # define OSTRACE(X)
32998 #endif
32999
33000 /*
33001 ** Macros for performance tracing. Normally turned off. Only works
33002 ** on i486 hardware.
33003 */
33004 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35962,11 @@
35898 ** Used only when SQLITE_NO_SYNC is not defined.
35899 */
35900 BOOL rc;
35901 #endif
35902 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35903 (defined(SQLITE_TEST) && defined(SQLITE_DEBUG))
35904 /*
35905 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
35906 ** OSTRACE() macros.
35907 */
35908 winFile *pFile = (winFile*)id;
@@ -36575,11 +36639,11 @@
36575 DWORD lastErrno; /* The Windows errno from the last I/O error */
36576
36577 int nRef; /* Number of winShm objects pointing to this */
36578 winShm *pFirst; /* All winShm objects pointing to this */
36579 winShmNode *pNext; /* Next in list of all winShmNode objects */
36580 #ifdef SQLITE_DEBUG
36581 u8 nextShmId; /* Next available winShm.id value */
36582 #endif
36583 };
36584
36585 /*
@@ -36606,11 +36670,11 @@
36606 winShmNode *pShmNode; /* The underlying winShmNode object */
36607 winShm *pNext; /* Next winShm with the same winShmNode */
36608 u8 hasMutex; /* True if holding the winShmNode mutex */
36609 u16 sharedMask; /* Mask of shared locks held */
36610 u16 exclMask; /* Mask of exclusive locks held */
36611 #ifdef SQLITE_DEBUG
36612 u8 id; /* Id of this connection with its winShmNode */
36613 #endif
36614 };
36615
36616 /*
@@ -36797,11 +36861,11 @@
36797 if( rc ) goto shm_open_err;
36798 }
36799
36800 /* Make the new connection a child of the winShmNode */
36801 p->pShmNode = pShmNode;
36802 #ifdef SQLITE_DEBUG
36803 p->id = pShmNode->nextShmId++;
36804 #endif
36805 pShmNode->nRef++;
36806 pDbFd->pShm = p;
36807 winShmLeaveMutex();
@@ -37066,11 +37130,11 @@
37066 goto shmpage_out;
37067 }
37068 }
37069
37070 /* Map the requested memory region into this processes address space. */
37071 apNew = (struct ShmRegion *)sqlite3_realloc(
37072 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
37073 );
37074 if( !apNew ){
37075 rc = SQLITE_IOERR_NOMEM;
37076 goto shmpage_out;
@@ -38513,11 +38577,11 @@
38513 ** Write up to nBuf bytes of randomness into zBuf.
38514 */
38515 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
38516 int n = 0;
38517 UNUSED_PARAMETER(pVfs);
38518 #if defined(SQLITE_TEST)
38519 n = nBuf;
38520 memset(zBuf, 0, nBuf);
38521 #else
38522 if( sizeof(SYSTEMTIME)<=nBuf-n ){
38523 SYSTEMTIME x;
@@ -38547,11 +38611,10 @@
38547 LARGE_INTEGER i;
38548 osQueryPerformanceCounter(&i);
38549 memcpy(&zBuf[n], &i, sizeof(i));
38550 n += sizeof(i);
38551 }
38552 #endif
38553 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38554 if( sizeof(UUID)<=nBuf-n ){
38555 UUID id;
38556 memset(&id, 0, sizeof(UUID));
38557 osUuidCreate(&id);
@@ -38564,10 +38627,11 @@
38564 osUuidCreateSequential(&id);
38565 memcpy(zBuf, &id, sizeof(UUID));
38566 n += sizeof(UUID);
38567 }
38568 #endif
 
38569 return n;
38570 }
38571
38572
38573 /*
@@ -39118,11 +39182,11 @@
39118
39119 /* Allocate the Bitvec to be tested and a linear array of
39120 ** bits to act as the reference */
39121 pBitvec = sqlite3BitvecCreate( sz );
39122 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39123 pTmpSpace = sqlite3_malloc(BITVEC_SZ);
39124 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
39125
39126 /* NULL pBitvec tests */
39127 sqlite3BitvecSet(0, 1);
39128 sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44671,11 @@
44607 Pgno nTruncate, /* Database size after this commit */
44608 int isCommit /* True if this is a commit */
44609 ){
44610 int rc; /* Return code */
44611 int nList; /* Number of pages in pList */
44612 #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
44613 PgHdr *p; /* For looping over pages */
44614 #endif
44615
44616 assert( pPager->pWal );
44617 assert( pList );
44618 #ifdef SQLITE_DEBUG
44619 /* Verify that the page list is in accending order */
@@ -44626,11 +44688,10 @@
44626 if( isCommit ){
44627 /* If a WAL transaction is being committed, there is no point in writing
44628 ** any pages with page numbers greater than nTruncate into the WAL file.
44629 ** They will never be read by any client. So remove them from the pDirty
44630 ** list here. */
44631 PgHdr *p;
44632 PgHdr **ppNext = &pList;
44633 nList = 0;
44634 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
44635 if( p->pgno<=nTruncate ){
44636 ppNext = &p->pDirty;
@@ -44646,11 +44707,10 @@
44646 if( pList->pgno==1 ) pager_write_changecounter(pList);
44647 rc = sqlite3WalFrames(pPager->pWal,
44648 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
44649 );
44650 if( rc==SQLITE_OK && pPager->pBackup ){
44651 PgHdr *p;
44652 for(p=pList; p; p=p->pDirty){
44653 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
44654 }
44655 }
44656
@@ -48577,10 +48637,12 @@
48577 }else if( state==PAGER_OPEN ){
48578 pager_unlock(pPager);
48579 }
48580 assert( state==pPager->eState );
48581 }
 
 
48582 }
48583 }
48584
48585 /* Return the new journal mode */
48586 return (int)pPager->journalMode;
@@ -49359,11 +49421,11 @@
49359
49360 /* Enlarge the pWal->apWiData[] array if required */
49361 if( pWal->nWiData<=iPage ){
49362 int nByte = sizeof(u32*)*(iPage+1);
49363 volatile u32 **apNew;
49364 apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte);
49365 if( !apNew ){
49366 *ppPage = 0;
49367 return SQLITE_NOMEM;
49368 }
49369 memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50046,11 @@
49984 goto finished;
49985 }
49986
49987 /* Malloc a buffer to read frames into. */
49988 szFrame = szPage + WAL_FRAME_HDRSIZE;
49989 aFrame = (u8 *)sqlite3_malloc(szFrame);
49990 if( !aFrame ){
49991 rc = SQLITE_NOMEM;
49992 goto recovery_error;
49993 }
49994 aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50439,21 @@
50377 /* Allocate space for the WalIterator object. */
50378 nSegment = walFramePage(iLast) + 1;
50379 nByte = sizeof(WalIterator)
50380 + (nSegment-1)*sizeof(struct WalSegment)
50381 + iLast*sizeof(ht_slot);
50382 p = (WalIterator *)sqlite3_malloc(nByte);
50383 if( !p ){
50384 return SQLITE_NOMEM;
50385 }
50386 memset(p, 0, nByte);
50387 p->nSegment = nSegment;
50388
50389 /* Allocate temporary space used by the merge-sort routine. This block
50390 ** of memory will be freed before this function returns.
50391 */
50392 aTmp = (ht_slot *)sqlite3_malloc(
50393 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
50394 );
50395 if( !aTmp ){
50396 rc = SQLITE_NOMEM;
50397 }
@@ -50567,10 +50629,18 @@
50567 ** cannot be backfilled from the WAL.
50568 */
50569 mxSafeFrame = pWal->hdr.mxFrame;
50570 mxPage = pWal->hdr.nPage;
50571 for(i=1; i<WAL_NREADER; i++){
 
 
 
 
 
 
 
 
50572 u32 y = pInfo->aReadMark[i];
50573 if( mxSafeFrame>y ){
50574 assert( y<=pWal->hdr.mxFrame );
50575 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
50576 if( rc==SQLITE_OK ){
@@ -57429,17 +57499,22 @@
57429 */
57430 static const void *fetchPayload(
57431 BtCursor *pCur, /* Cursor pointing to entry to read from */
57432 u32 *pAmt /* Write the number of available bytes here */
57433 ){
 
57434 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
57435 assert( pCur->eState==CURSOR_VALID );
57436 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57437 assert( cursorHoldsMutex(pCur) );
57438 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57439 assert( pCur->info.nSize>0 );
57440 *pAmt = pCur->info.nLocal;
 
 
 
 
57441 return (void*)pCur->info.pPayload;
57442 }
57443
57444
57445 /*
@@ -59713,11 +59788,10 @@
59713 if( iParentIdx==0 ){
59714 nxDiv = 0;
59715 }else if( iParentIdx==i ){
59716 nxDiv = i-2+bBulk;
59717 }else{
59718 assert( bBulk==0 );
59719 nxDiv = iParentIdx-1;
59720 }
59721 i = 2-bBulk;
59722 }
59723 nOld = i+1;
@@ -61501,10 +61575,61 @@
61501 iPage = get4byte(pOvflData);
61502 sqlite3PagerUnref(pOvflPage);
61503 }
61504 }
61505 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61506
61507 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
61508 /*
61509 ** Do various sanity checks on a single page of a tree. Return
61510 ** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61659,12 @@
61534 int hdr, cellStart;
61535 int nCell;
61536 u8 *data;
61537 BtShared *pBt;
61538 int usableSize;
61539 char *hit = 0;
 
61540 i64 nMinKey = 0;
61541 i64 nMaxKey = 0;
61542 const char *saved_zPfx = pCheck->zPfx;
61543 int saved_v1 = pCheck->v1;
61544 int saved_v2 = pCheck->v2;
@@ -61679,19 +61805,19 @@
61679
61680 /* Check for complete coverage of the page
61681 */
61682 data = pPage->aData;
61683 hdr = pPage->hdrOffset;
61684 hit = sqlite3PageMalloc( pBt->pageSize );
61685 pCheck->zPfx = 0;
61686 if( hit==0 ){
61687 pCheck->mallocFailed = 1;
61688 }else{
61689 int contentOffset = get2byteNotZero(&data[hdr+5]);
61690 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61691 memset(hit+contentOffset, 0, usableSize-contentOffset);
61692 memset(hit, 1, contentOffset);
61693 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61694 ** number of cells on the page. */
61695 nCell = get2byte(&data[hdr+3]);
61696 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61697 ** immediately follows the b-tree page header. */
@@ -61699,20 +61825,19 @@
61699 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61700 ** integer offsets to the cell contents. */
61701 for(i=0; i<nCell; i++){
61702 int pc = get2byte(&data[cellStart+i*2]);
61703 u32 size = 65536;
61704 int j;
61705 if( pc<=usableSize-4 ){
61706 size = cellSizePtr(pPage, &data[pc]);
61707 }
61708 if( (int)(pc+size-1)>=usableSize ){
61709 pCheck->zPfx = 0;
61710 checkAppendMsg(pCheck,
61711 "Corruption detected in cell %d on page %d",i,iPage);
61712 }else{
61713 for(j=pc+size-1; j>=pc; j--) hit[j]++;
61714 }
61715 }
61716 /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61717 ** is the offset of the first freeblock, or zero if there are no
61718 ** freeblocks on the page. */
@@ -61720,11 +61845,11 @@
61720 while( i>0 ){
61721 int size, j;
61722 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
61723 size = get2byte(&data[i+2]);
61724 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61725 for(j=i+size-1; j>=i; j--) hit[j]++;
61726 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61727 ** big-endian integer which is the offset in the b-tree page of the next
61728 ** freeblock in the chain, or zero if the freeblock is the last on the
61729 ** chain. */
61730 j = get2byte(&data[i]);
@@ -61732,31 +61857,37 @@
61732 ** increasing offset. */
61733 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
61734 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
61735 i = j;
61736 }
61737 for(i=cnt=0; i<usableSize; i++){
61738 if( hit[i]==0 ){
61739 cnt++;
61740 }else if( hit[i]>1 ){
 
 
61741 checkAppendMsg(pCheck,
61742 "Multiple uses for byte %d of page %d", i, iPage);
61743 break;
 
 
 
61744 }
61745 }
 
61746 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61747 ** is stored in the fifth field of the b-tree page header.
61748 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61749 ** number of fragmented free bytes within the cell content area.
61750 */
61751 if( cnt!=data[hdr+7] ){
61752 checkAppendMsg(pCheck,
61753 "Fragmentation of %d bytes reported as %d on page %d",
61754 cnt, data[hdr+7], iPage);
61755 }
61756 }
61757 sqlite3PageFree(hit);
61758 releasePage(pPage);
61759
61760 end_of_check:
61761 pCheck->zPfx = saved_zPfx;
61762 pCheck->v1 = saved_v1;
@@ -61816,12 +61947,11 @@
61816 sqlite3BtreeLeave(p);
61817 return 0;
61818 }
61819 i = PENDING_BYTE_PAGE(pBt);
61820 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61821 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
61822 sCheck.errMsg.useMalloc = 2;
61823
61824 /* Check the integrity of the freelist
61825 */
61826 sCheck.zPfx = "Main freelist: ";
61827 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63283,15 @@
63153 return SQLITE_NOMEM;
63154 }
63155 pMem->z[pMem->n] = 0;
63156 pMem->z[pMem->n+1] = 0;
63157 pMem->flags |= MEM_Term;
 
 
63158 #ifdef SQLITE_DEBUG
63159 pMem->pScopyFrom = 0;
63160 #endif
63161 }
63162
63163 return SQLITE_OK;
63164 }
63165
63166 /*
@@ -64600,11 +64731,11 @@
64600 int i;
64601 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
64602 Mem *aMem = pRec->aMem;
64603 sqlite3 *db = aMem[0].db;
64604 for(i=0; i<nCol; i++){
64605 if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
64606 }
64607 sqlite3KeyInfoUnref(pRec->pKeyInfo);
64608 sqlite3DbFree(db, pRec);
64609 }
64610 }
@@ -66436,18 +66567,35 @@
66436 pVtabCursor->pVtab->nRef--;
66437 pModule->xClose(pVtabCursor);
66438 }
66439 #endif
66440 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66441
66442 /*
66443 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
66444 ** is used, for example, when a trigger sub-program is halted to restore
66445 ** control to the main program.
66446 */
66447 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
66448 Vdbe *v = pFrame->v;
 
66449 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66450 v->anExec = pFrame->anExec;
66451 #endif
66452 v->aOnceFlag = pFrame->aOnceFlag;
66453 v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66626,11 @@
66478 sqlite3VdbeFrameRestore(pFrame);
66479 p->pFrame = 0;
66480 p->nFrame = 0;
66481 }
66482 assert( p->nFrame==0 );
66483
66484 if( p->apCsr ){
66485 int i;
66486 for(i=0; i<p->nCursor; i++){
66487 VdbeCursor *pC = p->apCsr[i];
66488 if( pC ){
66489 sqlite3VdbeFreeCursor(p, pC);
66490 p->apCsr[i] = 0;
66491 }
66492 }
66493 }
66494 if( p->aMem ){
66495 releaseMemArray(&p->aMem[1], p->nMem);
66496 }
66497 while( p->pDelFrame ){
66498 VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68371,11 @@
68233 ** If database corruption is discovered, set pPKey2->errCode to
68234 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
68235 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
68236 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
68237 */
68238 static int vdbeRecordCompareWithSkip(
68239 int nKey1, const void *pKey1, /* Left key */
68240 UnpackedRecord *pPKey2, /* Right key */
68241 int bSkip /* If true, skip the first field */
68242 ){
68243 u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68557,11 @@
68419 }
68420 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
68421 int nKey1, const void *pKey1, /* Left key */
68422 UnpackedRecord *pPKey2 /* Right key */
68423 ){
68424 return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68425 }
68426
68427
68428 /*
68429 ** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68645,11 @@
68507 }else if( v<lhs ){
68508 res = pPKey2->r2;
68509 }else if( pPKey2->nField>1 ){
68510 /* The first fields of the two keys are equal. Compare the trailing
68511 ** fields. */
68512 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68513 }else{
68514 /* The first fields of the two keys are equal and there are no trailing
68515 ** fields. Return pPKey2->default_rc in this case. */
68516 res = pPKey2->default_rc;
68517 }
@@ -68555,11 +68693,11 @@
68555
68556 if( res==0 ){
68557 res = nStr - pPKey2->aMem[0].n;
68558 if( res==0 ){
68559 if( pPKey2->nField>1 ){
68560 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68561 }else{
68562 res = pPKey2->default_rc;
68563 }
68564 }else if( res>0 ){
68565 res = pPKey2->r2;
@@ -70497,21 +70635,22 @@
70497 Mem *pVar; /* Value of a host parameter */
70498 StrAccum out; /* Accumulate the output here */
70499 char zBase[100]; /* Initial working space */
70500
70501 db = p->db;
70502 sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
70503 db->aLimit[SQLITE_LIMIT_LENGTH]);
70504 out.db = db;
70505 if( db->nVdbeExec>1 ){
70506 while( *zRawSql ){
70507 const char *zStart = zRawSql;
70508 while( *(zRawSql++)!='\n' && *zRawSql );
70509 sqlite3StrAccumAppend(&out, "-- ", 3);
70510 assert( (zRawSql - zStart) > 0 );
70511 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
70512 }
 
 
70513 }else{
70514 while( zRawSql[0] ){
70515 n = findNextHostParameter(zRawSql, &nToken);
70516 assert( n>0 );
70517 sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70663,16 @@
70524 sqlite3GetInt32(&zRawSql[1], &idx);
70525 }else{
70526 idx = nextIndex;
70527 }
70528 }else{
70529 assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
 
70530 testcase( zRawSql[0]==':' );
70531 testcase( zRawSql[0]=='$' );
70532 testcase( zRawSql[0]=='@' );
 
70533 idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
70534 assert( idx>0 );
70535 }
70536 zRawSql += nToken;
70537 nextIndex = idx + 1;
@@ -71202,21 +71343,38 @@
71202 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
71203 return 1;
71204 }
71205 #endif
71206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71207
71208 /*
71209 ** Execute as much of a VDBE program as we can.
71210 ** This is the core of sqlite3_step().
71211 */
71212 SQLITE_PRIVATE int sqlite3VdbeExec(
71213 Vdbe *p /* The VDBE */
71214 ){
71215 int pc=0; /* The program counter */
71216 Op *aOp = p->aOp; /* Copy of p->aOp */
71217 Op *pOp; /* Current operation */
 
 
 
71218 int rc = SQLITE_OK; /* Value to return */
71219 sqlite3 *db = p->db; /* The database */
71220 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
71221 u8 encoding = ENC(db); /* The database encoding */
71222 int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71446,26 @@
71288 }
71289 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
71290 }
71291 sqlite3EndBenignMalloc();
71292 #endif
71293 for(pc=p->pc; rc==SQLITE_OK; pc++){
71294 assert( pc>=0 && pc<p->nOp );
71295 if( db->mallocFailed ) goto no_mem;
71296 #ifdef VDBE_PROFILE
71297 start = sqlite3Hwtime();
71298 #endif
71299 nVmStep++;
71300 pOp = &aOp[pc];
71301 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71302 if( p->anExec ) p->anExec[pc]++;
71303 #endif
71304
71305 /* Only allow tracing if SQLITE_DEBUG is defined.
71306 */
71307 #ifdef SQLITE_DEBUG
71308 if( db->flags & SQLITE_VdbeTrace ){
71309 sqlite3VdbePrintOp(stdout, pc, pOp);
71310 }
71311 #endif
71312
71313
71314 /* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71478,13 @@
71321 sqlite3_interrupt(db);
71322 }
71323 }
71324 #endif
71325
71326 /* On any opcode with the "out2-prerelease" tag, free any
71327 ** external allocations out of mem[p2] and set mem[p2] to be
71328 ** an undefined integer. Opcodes will either fill in the integer
71329 ** value or convert mem[p2] to a different type.
71330 */
71331 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71332 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
71333 assert( pOp->p2>0 );
71334 assert( pOp->p2<=(p->nMem-p->nCursor) );
71335 pOut = &aMem[pOp->p2];
71336 memAboutToChange(p, pOut);
71337 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71338 pOut->flags = MEM_Int;
71339 }
71340
71341 /* Sanity checking on other operands */
71342 #ifdef SQLITE_DEBUG
 
71343 if( (pOp->opflags & OPFLG_IN1)!=0 ){
71344 assert( pOp->p1>0 );
71345 assert( pOp->p1<=(p->nMem-p->nCursor) );
71346 assert( memIsValid(&aMem[pOp->p1]) );
71347 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71513,13 @@
71370 assert( pOp->p3>0 );
71371 assert( pOp->p3<=(p->nMem-p->nCursor) );
71372 memAboutToChange(p, &aMem[pOp->p3]);
71373 }
71374 #endif
 
 
 
71375
71376 switch( pOp->opcode ){
71377
71378 /*****************************************************************************
71379 ** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71539,11 @@
71393 ** case statement is followed by a comment of the form "/# same as ... #/"
71394 ** that comment is used to determine the particular value of the opcode.
71395 **
71396 ** Other keywords in the comment that follows each case are used to
71397 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71398 ** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See
71399 ** the mkopcodeh.awk script for additional information.
71400 **
71401 ** Documentation about VDBE opcodes is generated by scanning this file
71402 ** for lines of that contain "Opcode:". That line and all subsequent
71403 ** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71567,12 @@
71421 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
71422 ** that this Goto is the bottom of a loop and that the lines from P2 down
71423 ** to the current line should be indented for EXPLAIN output.
71424 */
71425 case OP_Goto: { /* jump */
71426 pc = pOp->p2 - 1;
 
71427
71428 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
71429 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
71430 ** completion. Check to see if sqlite3_interrupt() has been called
71431 ** or if the progress callback needs to be invoked.
@@ -71466,13 +71613,17 @@
71466 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71467 pIn1 = &aMem[pOp->p1];
71468 assert( VdbeMemDynamic(pIn1)==0 );
71469 memAboutToChange(p, pIn1);
71470 pIn1->flags = MEM_Int;
71471 pIn1->u.i = pc;
71472 REGISTER_TRACE(pOp->p1, pIn1);
71473 pc = pOp->p2 - 1;
 
 
 
 
71474 break;
71475 }
71476
71477 /* Opcode: Return P1 * * * *
71478 **
@@ -71480,11 +71631,11 @@
71480 ** the jump, register P1 becomes undefined.
71481 */
71482 case OP_Return: { /* in1 */
71483 pIn1 = &aMem[pOp->p1];
71484 assert( pIn1->flags==MEM_Int );
71485 pc = (int)pIn1->u.i;
71486 pIn1->flags = MEM_Undefined;
71487 break;
71488 }
71489
71490 /* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71655,11 @@
71504 assert( pOp->p3>=0 && pOp->p3<p->nOp );
71505 pOut = &aMem[pOp->p1];
71506 assert( !VdbeMemDynamic(pOut) );
71507 pOut->u.i = pOp->p3 - 1;
71508 pOut->flags = MEM_Int;
71509 if( pOp->p2 ) pc = pOp->p2 - 1;
71510 break;
71511 }
71512
71513 /* Opcode: EndCoroutine P1 * * * *
71514 **
@@ -71524,11 +71675,11 @@
71524 assert( pIn1->flags==MEM_Int );
71525 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
71526 pCaller = &aOp[pIn1->u.i];
71527 assert( pCaller->opcode==OP_Yield );
71528 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71529 pc = pCaller->p2 - 1;
71530 pIn1->flags = MEM_Undefined;
71531 break;
71532 }
71533
71534 /* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71699,13 @@
71548 int pcDest;
71549 pIn1 = &aMem[pOp->p1];
71550 assert( VdbeMemDynamic(pIn1)==0 );
71551 pIn1->flags = MEM_Int;
71552 pcDest = (int)pIn1->u.i;
71553 pIn1->u.i = pc;
71554 REGISTER_TRACE(pOp->p1, pIn1);
71555 pc = pcDest;
71556 break;
71557 }
71558
71559 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
71560 ** Synopsis: if r[P3]=null halt
@@ -71601,34 +71752,38 @@
71601 ** is the same as executing Halt.
71602 */
71603 case OP_Halt: {
71604 const char *zType;
71605 const char *zLogFmt;
 
 
71606
 
71607 if( pOp->p1==SQLITE_OK && p->pFrame ){
71608 /* Halt the sub-program. Return control to the parent frame. */
71609 VdbeFrame *pFrame = p->pFrame;
71610 p->pFrame = pFrame->pParent;
71611 p->nFrame--;
71612 sqlite3VdbeSetChanges(db, p->nChange);
71613 pc = sqlite3VdbeFrameRestore(pFrame);
71614 lastRowid = db->lastRowid;
71615 if( pOp->p2==OE_Ignore ){
71616 /* Instruction pc is the OP_Program that invoked the sub-program
71617 ** currently being halted. If the p2 instruction of this OP_Halt
71618 ** instruction is set to OE_Ignore, then the sub-program is throwing
71619 ** an IGNORE exception. In this case jump to the address specified
71620 ** as the p2 of the calling OP_Program. */
71621 pc = p->aOp[pc].p2-1;
71622 }
71623 aOp = p->aOp;
71624 aMem = p->aMem;
 
71625 break;
71626 }
71627 p->rc = pOp->p1;
71628 p->errorAction = (u8)pOp->p2;
71629 p->pc = pc;
71630 if( p->rc ){
71631 if( pOp->p5 ){
71632 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
71633 "FOREIGN KEY" };
71634 assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71803,11 @@
71648 }else if( pOp->p4.z ){
71649 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
71650 }else{
71651 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
71652 }
71653 sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
71654 }
71655 rc = sqlite3VdbeHalt(p);
71656 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
71657 if( rc==SQLITE_BUSY ){
71658 p->rc = rc = SQLITE_BUSY;
@@ -71659,19 +71814,21 @@
71659 }else{
71660 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
71661 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
71662 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
71663 }
 
71664 goto vdbe_return;
71665 }
71666
71667 /* Opcode: Integer P1 P2 * * *
71668 ** Synopsis: r[P2]=P1
71669 **
71670 ** The 32-bit integer value P1 is written into register P2.
71671 */
71672 case OP_Integer: { /* out2-prerelease */
 
71673 pOut->u.i = pOp->p1;
71674 break;
71675 }
71676
71677 /* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71835,12 @@
71678 ** Synopsis: r[P2]=P4
71679 **
71680 ** P4 is a pointer to a 64-bit integer value.
71681 ** Write that value into register P2.
71682 */
71683 case OP_Int64: { /* out2-prerelease */
 
71684 assert( pOp->p4.pI64!=0 );
71685 pOut->u.i = *pOp->p4.pI64;
71686 break;
71687 }
71688
@@ -71691,11 +71849,12 @@
71691 ** Synopsis: r[P2]=P4
71692 **
71693 ** P4 is a pointer to a 64-bit floating point value.
71694 ** Write that value into register P2.
71695 */
71696 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
 
71697 pOut->flags = MEM_Real;
71698 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
71699 pOut->u.r = *pOp->p4.pReal;
71700 break;
71701 }
@@ -71707,12 +71866,13 @@
71707 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71708 ** into a String opcode before it is executed for the first time. During
71709 ** this transformation, the length of string P4 is computed and stored
71710 ** as the P1 parameter.
71711 */
71712 case OP_String8: { /* same as TK_STRING, out2-prerelease */
71713 assert( pOp->p4.z!=0 );
 
71714 pOp->opcode = OP_String;
71715 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
71716
71717 #ifndef SQLITE_OMIT_UTF16
71718 if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71905,13 @@
71745 ** If P5!=0 and the content of register P3 is greater than zero, then
71746 ** the datatype of the register P2 is converted to BLOB. The content is
71747 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
71748 ** of a string, as if it had been CAST.
71749 */
71750 case OP_String: { /* out2-prerelease */
71751 assert( pOp->p4.z!=0 );
 
71752 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71753 pOut->z = pOp->p4.z;
71754 pOut->n = pOp->p1;
71755 pOut->enc = encoding;
71756 UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71935,14 @@
71774 **
71775 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
71776 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
71777 ** OP_Ne or OP_Eq.
71778 */
71779 case OP_Null: { /* out2-prerelease */
71780 int cnt;
71781 u16 nullFlag;
 
71782 cnt = pOp->p3-pOp->p2;
71783 assert( pOp->p3<=(p->nMem-p->nCursor) );
71784 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
71785 while( cnt>0 ){
71786 pOut++;
@@ -71811,12 +71973,13 @@
71811 ** Synopsis: r[P2]=P4 (len=P1)
71812 **
71813 ** P4 points to a blob of data P1 bytes long. Store this
71814 ** blob in register P2.
71815 */
71816 case OP_Blob: { /* out2-prerelease */
71817 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
 
71818 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
71819 pOut->enc = encoding;
71820 UPDATE_MAX_BLOBSIZE(pOut);
71821 break;
71822 }
@@ -71827,19 +71990,20 @@
71827 ** Transfer the values of bound parameter P1 into register P2
71828 **
71829 ** If the parameter is named, then its name appears in P4.
71830 ** The P4 value is used by sqlite3_bind_parameter_name().
71831 */
71832 case OP_Variable: { /* out2-prerelease */
71833 Mem *pVar; /* Value being transferred */
71834
71835 assert( pOp->p1>0 && pOp->p1<=p->nVar );
71836 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
71837 pVar = &p->aVar[pOp->p1 - 1];
71838 if( sqlite3VdbeMemTooBig(pVar) ){
71839 goto too_big;
71840 }
 
71841 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
71842 UPDATE_MAX_BLOBSIZE(pOut);
71843 break;
71844 }
71845
@@ -71870,14 +72034,15 @@
71870 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
71871 assert( memIsValid(pIn1) );
71872 memAboutToChange(p, pOut);
71873 sqlite3VdbeMemMove(pOut, pIn1);
71874 #ifdef SQLITE_DEBUG
71875 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
71876 pOut->pScopyFrom += p1 - pOp->p2;
71877 }
71878 #endif
 
71879 REGISTER_TRACE(p2++, pOut);
71880 pIn1++;
71881 pOut++;
71882 }while( --n );
71883 break;
@@ -72012,11 +72177,11 @@
72012 }
72013 if( db->mallocFailed ) goto no_mem;
72014
72015 /* Return SQLITE_ROW
72016 */
72017 p->pc = pc + 1;
72018 rc = SQLITE_ROW;
72019 goto vdbe_return;
72020 }
72021
72022 /* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72423,11 @@
72258 REGISTER_TRACE(pOp->p2+i, pArg);
72259 }
72260
72261 assert( pOp->p4type==P4_FUNCDEF );
72262 ctx.pFunc = pOp->p4.pFunc;
72263 ctx.iOp = pc;
72264 ctx.pVdbe = p;
72265 MemSetTypeFlag(ctx.pOut, MEM_Null);
72266 ctx.fErrorOrAux = 0;
72267 db->lastRowid = lastRowid;
72268 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72437,11 @@
72272 if( ctx.fErrorOrAux ){
72273 if( ctx.isError ){
72274 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
72275 rc = ctx.isError;
72276 }
72277 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
72278 }
72279
72280 /* Copy the result of the function into register P3 */
72281 sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
72282 if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72566,11 @@
72401 if( (pIn1->flags & MEM_Int)==0 ){
72402 if( pOp->p2==0 ){
72403 rc = SQLITE_MISMATCH;
72404 goto abort_due_to_error;
72405 }else{
72406 pc = pOp->p2 - 1;
72407 break;
72408 }
72409 }
72410 }
72411 MemSetTypeFlag(pIn1, MEM_Int);
72412 break;
@@ -72588,11 +72752,11 @@
72588 MemSetTypeFlag(pOut, MEM_Null);
72589 REGISTER_TRACE(pOp->p2, pOut);
72590 }else{
72591 VdbeBranchTaken(2,3);
72592 if( pOp->p5 & SQLITE_JUMPIFNULL ){
72593 pc = pOp->p2-1;
72594 }
72595 }
72596 break;
72597 }
72598 }else{
@@ -72639,10 +72803,16 @@
72639 case OP_Lt: res = res<0; break;
72640 case OP_Le: res = res<=0; break;
72641 case OP_Gt: res = res>0; break;
72642 default: res = res>=0; break;
72643 }
 
 
 
 
 
 
72644
72645 if( pOp->p5 & SQLITE_STOREP2 ){
72646 pOut = &aMem[pOp->p2];
72647 memAboutToChange(p, pOut);
72648 MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72819,13 @@
72649 pOut->u.i = res;
72650 REGISTER_TRACE(pOp->p2, pOut);
72651 }else{
72652 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
72653 if( res ){
72654 pc = pOp->p2-1;
72655 }
72656 }
72657 /* Undo any changes made by applyAffinity() to the input registers. */
72658 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72659 pIn1->flags = flags1;
72660 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72661 pIn3->flags = flags3;
72662 break;
72663 }
72664
72665 /* Opcode: Permutation * * * P4 *
72666 **
@@ -72751,15 +72916,15 @@
72751 ** in the most recent OP_Compare instruction the P1 vector was less than
72752 ** equal to, or greater than the P2 vector, respectively.
72753 */
72754 case OP_Jump: { /* jump */
72755 if( iCompare<0 ){
72756 pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
72757 }else if( iCompare==0 ){
72758 pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
72759 }else{
72760 pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
72761 }
72762 break;
72763 }
72764
72765 /* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73030,11 @@
72865 */
72866 case OP_Once: { /* jump */
72867 assert( pOp->p1<p->nOnceFlag );
72868 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
72869 if( p->aOnceFlag[pOp->p1] ){
72870 pc = pOp->p2-1;
72871 }else{
72872 p->aOnceFlag[pOp->p1] = 1;
72873 }
72874 break;
72875 }
@@ -72900,11 +73065,11 @@
72900 #endif
72901 if( pOp->opcode==OP_IfNot ) c = !c;
72902 }
72903 VdbeBranchTaken(c!=0, 2);
72904 if( c ){
72905 pc = pOp->p2-1;
72906 }
72907 break;
72908 }
72909
72910 /* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73079,11 @@
72914 */
72915 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
72916 pIn1 = &aMem[pOp->p1];
72917 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
72918 if( (pIn1->flags & MEM_Null)!=0 ){
72919 pc = pOp->p2 - 1;
72920 }
72921 break;
72922 }
72923
72924 /* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73093,11 @@
72928 */
72929 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
72930 pIn1 = &aMem[pOp->p1];
72931 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
72932 if( (pIn1->flags & MEM_Null)==0 ){
72933 pc = pOp->p2 - 1;
72934 }
72935 break;
72936 }
72937
72938 /* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73307,11 @@
73142 rc = SQLITE_CORRUPT_BKPT;
73143 goto op_column_error;
73144 }
73145 }
73146
73147 /* If after trying to extra new entries from the header, nHdrParsed is
73148 ** still not up to p2, that means that the record has fewer than p2
73149 ** columns. So the result will be either the default value or a NULL.
73150 */
73151 if( pC->nHdrParsed<=p2 ){
73152 if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73431,11 @@
73266 u8 *zNewRecord; /* A buffer to hold the data for the new record */
73267 Mem *pRec; /* The new record */
73268 u64 nData; /* Number of bytes of data space */
73269 int nHdr; /* Number of bytes of header space */
73270 i64 nByte; /* Data space required for this record */
73271 int nZero; /* Number of zero bytes at the end of the record */
73272 int nVarint; /* Number of bytes in a varint */
73273 u32 serial_type; /* Type field */
73274 Mem *pData0; /* First field to be combined into the record */
73275 Mem *pLast; /* Last field of the record */
73276 int nField; /* Number of fields in the record */
@@ -73358,11 +73523,11 @@
73358 nVarint = sqlite3VarintLen(nHdr);
73359 nHdr += nVarint;
73360 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
73361 }
73362 nByte = nHdr+nData;
73363 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73364 goto too_big;
73365 }
73366
73367 /* Make sure the output register has a buffer large enough to store
73368 ** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73574,19 @@
73409 **
73410 ** Store the number of entries (an integer value) in the table or index
73411 ** opened by cursor P1 in register P2
73412 */
73413 #ifndef SQLITE_OMIT_BTREECOUNT
73414 case OP_Count: { /* out2-prerelease */
73415 i64 nEntry;
73416 BtCursor *pCrsr;
73417
73418 pCrsr = p->apCsr[pOp->p1]->pCursor;
73419 assert( pCrsr );
73420 nEntry = 0; /* Not needed. Only used to silence a warning. */
73421 rc = sqlite3BtreeCount(pCrsr, &nEntry);
 
73422 pOut->u.i = nEntry;
73423 break;
73424 }
73425 #endif
73426
@@ -73530,11 +73696,11 @@
73530 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73531 goto vdbe_return;
73532 }
73533 db->autoCommit = 1;
73534 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73535 p->pc = pc;
73536 db->autoCommit = 0;
73537 p->rc = rc = SQLITE_BUSY;
73538 goto vdbe_return;
73539 }
73540 db->isTransactionSavepoint = 0;
@@ -73589,11 +73755,11 @@
73589 }else{
73590 db->nDeferredCons = pSavepoint->nDeferredCons;
73591 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
73592 }
73593
73594 if( !isTransaction ){
73595 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
73596 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73597 }
73598 }
73599 }
@@ -73649,11 +73815,11 @@
73649 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73650 goto vdbe_return;
73651 }else{
73652 db->autoCommit = (u8)desiredAutoCommit;
73653 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73654 p->pc = pc;
73655 db->autoCommit = (u8)(1-desiredAutoCommit);
73656 p->rc = rc = SQLITE_BUSY;
73657 goto vdbe_return;
73658 }
73659 }
@@ -73726,11 +73892,11 @@
73726 pBt = db->aDb[pOp->p1].pBt;
73727
73728 if( pBt ){
73729 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
73730 if( rc==SQLITE_BUSY ){
73731 p->pc = pc;
73732 p->rc = rc = SQLITE_BUSY;
73733 goto vdbe_return;
73734 }
73735 if( rc!=SQLITE_OK ){
73736 goto abort_due_to_error;
@@ -73805,11 +73971,11 @@
73805 **
73806 ** There must be a read-lock on the database (either a transaction
73807 ** must be started or there must be an open cursor) before
73808 ** executing this instruction.
73809 */
73810 case OP_ReadCookie: { /* out2-prerelease */
73811 int iMeta;
73812 int iDb;
73813 int iCookie;
73814
73815 assert( p->bIsReader );
@@ -73819,10 +73985,11 @@
73819 assert( iDb>=0 && iDb<db->nDb );
73820 assert( db->aDb[iDb].pBt!=0 );
73821 assert( DbMaskTest(p->btreeMask, iDb) );
73822
73823 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
 
73824 pOut->u.i = iMeta;
73825 break;
73826 }
73827
73828 /* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74307,11 @@
74140 VdbeCursor *pC;
74141 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74142 pC = p->apCsr[pOp->p1];
74143 assert( pC->pSorter );
74144 if( (pC->seqCount++)==0 ){
74145 pc = pOp->p2 - 1;
74146 }
74147 break;
74148 }
74149
74150 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74484,11 @@
74317 ** loss of information, then special processing is required... */
74318 if( (pIn3->flags & MEM_Int)==0 ){
74319 if( (pIn3->flags & MEM_Real)==0 ){
74320 /* If the P3 value cannot be converted into any kind of a number,
74321 ** then the seek is not possible, so jump to P2 */
74322 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74323 break;
74324 }
74325
74326 /* If the approximation iKey is larger than the actual real search
74327 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74575,11 @@
74408 }
74409 }
74410 assert( pOp->p2>0 );
74411 VdbeBranchTaken(res!=0,2);
74412 if( res ){
74413 pc = pOp->p2 - 1;
74414 }
74415 break;
74416 }
74417
74418 /* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74669,11 @@
74502 */
74503 case OP_NoConflict: /* jump, in3 */
74504 case OP_NotFound: /* jump, in3 */
74505 case OP_Found: { /* jump, in3 */
74506 int alreadyExists;
 
74507 int ii;
74508 VdbeCursor *pC;
74509 int res;
74510 char *pFree;
74511 UnpackedRecord *pIdxKey;
@@ -74524,11 +74692,11 @@
74524 pC->seekOp = pOp->opcode;
74525 #endif
74526 pIn3 = &aMem[pOp->p3];
74527 assert( pC->pCursor!=0 );
74528 assert( pC->isTable==0 );
74529 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
74530 if( pOp->p4.i>0 ){
74531 r.pKeyInfo = pC->pKeyInfo;
74532 r.nField = (u16)pOp->p4.i;
74533 r.aMem = pIn3;
74534 for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74715,24 @@
74547 assert( pIn3->flags & MEM_Blob );
74548 ExpandBlob(pIn3);
74549 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
74550 }
74551 pIdxKey->default_rc = 0;
 
74552 if( pOp->opcode==OP_NoConflict ){
74553 /* For the OP_NoConflict opcode, take the jump if any of the
74554 ** input fields are NULL, since any key with a NULL will not
74555 ** conflict */
74556 for(ii=0; ii<pIdxKey->nField; ii++){
74557 if( pIdxKey->aMem[ii].flags & MEM_Null ){
74558 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74559 break;
74560 }
74561 }
74562 }
74563 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74564 if( pOp->p4.i==0 ){
74565 sqlite3DbFree(db, pFree);
74566 }
74567 if( rc!=SQLITE_OK ){
74568 break;
74569 }
74570 pC->seekResult = res;
74571 alreadyExists = (res==0);
@@ -74572,14 +74739,14 @@
74572 pC->nullRow = 1-alreadyExists;
74573 pC->deferredMoveto = 0;
74574 pC->cacheStatus = CACHE_STALE;
74575 if( pOp->opcode==OP_Found ){
74576 VdbeBranchTaken(alreadyExists!=0,2);
74577 if( alreadyExists ) pc = pOp->p2 - 1;
74578 }else{
74579 VdbeBranchTaken(alreadyExists==0,2);
74580 if( !alreadyExists ) pc = pOp->p2 - 1;
74581 }
74582 break;
74583 }
74584
74585 /* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74791,12 @@
74624 pC->movetoTarget = iKey; /* Used by OP_Delete */
74625 pC->nullRow = 0;
74626 pC->cacheStatus = CACHE_STALE;
74627 pC->deferredMoveto = 0;
74628 VdbeBranchTaken(res!=0,2);
74629 if( res!=0 ){
74630 pc = pOp->p2 - 1;
74631 }
74632 pC->seekResult = res;
 
74633 break;
74634 }
74635
74636 /* Opcode: Sequence P1 P2 * * *
74637 ** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74804,14 @@
74639 ** Find the next available sequence number for cursor P1.
74640 ** Write the sequence number into register P2.
74641 ** The sequence number on the cursor is incremented after this
74642 ** instruction.
74643 */
74644 case OP_Sequence: { /* out2-prerelease */
74645 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74646 assert( p->apCsr[pOp->p1]!=0 );
 
74647 pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
74648 break;
74649 }
74650
74651
@@ -74662,20 +74828,21 @@
74662 ** allowed to be less than this value. When this value reaches its maximum,
74663 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
74664 ** generated record number. This P3 mechanism is used to help implement the
74665 ** AUTOINCREMENT feature.
74666 */
74667 case OP_NewRowid: { /* out2-prerelease */
74668 i64 v; /* The new rowid */
74669 VdbeCursor *pC; /* Cursor of table to get the new rowid */
74670 int res; /* Result of an sqlite3BtreeLast() */
74671 int cnt; /* Counter to limit the number of searches */
74672 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
74673 VdbeFrame *pFrame; /* Root frame of VDBE */
74674
74675 v = 0;
74676 res = 0;
 
74677 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74678 pC = p->apCsr[pOp->p1];
74679 assert( pC!=0 );
74680 if( NEVER(pC->pCursor==0) ){
74681 /* The zero initialization above is all that is needed */
@@ -74985,13 +75152,11 @@
74985 pIn3 = &aMem[pOp->p3];
74986 nKeyCol = pOp->p4.i;
74987 res = 0;
74988 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
74989 VdbeBranchTaken(res!=0,2);
74990 if( res ){
74991 pc = pOp->p2-1;
74992 }
74993 break;
74994 };
74995
74996 /* Opcode: SorterData P1 P2 P3 * *
74997 ** Synopsis: r[P2]=data
@@ -75116,16 +75281,17 @@
75116 **
75117 ** P1 can be either an ordinary table or a virtual table. There used to
75118 ** be a separate OP_VRowid opcode for use with virtual tables, but this
75119 ** one opcode now works for both table types.
75120 */
75121 case OP_Rowid: { /* out2-prerelease */
75122 VdbeCursor *pC;
75123 i64 v;
75124 sqlite3_vtab *pVtab;
75125 const sqlite3_module *pModule;
75126
 
75127 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75128 pC = p->apCsr[pOp->p1];
75129 assert( pC!=0 );
75130 assert( pC->pseudoTableReg==0 || pC->nullRow );
75131 if( pC->nullRow ){
@@ -75174,11 +75340,11 @@
75174 sqlite3BtreeClearCursor(pC->pCursor);
75175 }
75176 break;
75177 }
75178
75179 /* Opcode: Last P1 P2 * * *
75180 **
75181 ** The next use of the Rowid or Column or Prev instruction for P1
75182 ** will refer to the last entry in the database table or index.
75183 ** If the table or index is empty and P2>0, then jump immediately to P2.
75184 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75367,17 @@
75201 assert( pCrsr!=0 );
75202 rc = sqlite3BtreeLast(pCrsr, &res);
75203 pC->nullRow = (u8)res;
75204 pC->deferredMoveto = 0;
75205 pC->cacheStatus = CACHE_STALE;
 
75206 #ifdef SQLITE_DEBUG
75207 pC->seekOp = OP_Last;
75208 #endif
75209 if( pOp->p2>0 ){
75210 VdbeBranchTaken(res!=0,2);
75211 if( res ) pc = pOp->p2 - 1;
75212 }
75213 break;
75214 }
75215
75216
@@ -75270,13 +75437,11 @@
75270 pC->cacheStatus = CACHE_STALE;
75271 }
75272 pC->nullRow = (u8)res;
75273 assert( pOp->p2>0 && pOp->p2<p->nOp );
75274 VdbeBranchTaken(res!=0,2);
75275 if( res ){
75276 pc = pOp->p2 - 1;
75277 }
75278 break;
75279 }
75280
75281 /* Opcode: Next P1 P2 P3 P4 P5
75282 **
@@ -75383,15 +75548,15 @@
75383 next_tail:
75384 pC->cacheStatus = CACHE_STALE;
75385 VdbeBranchTaken(res==0,2);
75386 if( res==0 ){
75387 pC->nullRow = 0;
75388 pc = pOp->p2 - 1;
75389 p->aCounter[pOp->p5]++;
75390 #ifdef SQLITE_TEST
75391 sqlite3_search_count++;
75392 #endif
 
75393 }else{
75394 pC->nullRow = 1;
75395 }
75396 goto check_for_interrupt;
75397 }
@@ -75495,15 +75660,16 @@
75495 ** the end of the index key pointed to by cursor P1. This integer should be
75496 ** the rowid of the table entry to which this index entry points.
75497 **
75498 ** See also: Rowid, MakeRecord.
75499 */
75500 case OP_IdxRowid: { /* out2-prerelease */
75501 BtCursor *pCrsr;
75502 VdbeCursor *pC;
75503 i64 rowid;
75504
 
75505 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75506 pC = p->apCsr[pOp->p1];
75507 assert( pC!=0 );
75508 pCrsr = pC->pCursor;
75509 assert( pCrsr!=0 );
@@ -75612,13 +75778,11 @@
75612 }else{
75613 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
75614 res++;
75615 }
75616 VdbeBranchTaken(res>0,2);
75617 if( res>0 ){
75618 pc = pOp->p2 - 1 ;
75619 }
75620 break;
75621 }
75622
75623 /* Opcode: Destroy P1 P2 P3 * *
75624 **
@@ -75638,15 +75802,16 @@
75638 ** the last one in the database) then a zero is stored in register P2.
75639 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
75640 **
75641 ** See also: Clear
75642 */
75643 case OP_Destroy: { /* out2-prerelease */
75644 int iMoved;
75645 int iDb;
75646
75647 assert( p->readOnly==0 );
 
75648 pOut->flags = MEM_Null;
75649 if( db->nVdbeRead > db->nVDestroy+1 ){
75650 rc = SQLITE_LOCKED;
75651 p->errorAction = OE_Abort;
75652 }else{
@@ -75751,16 +75916,17 @@
75751 ** P1>1. Write the root page number of the new table into
75752 ** register P2.
75753 **
75754 ** See documentation on OP_CreateTable for additional information.
75755 */
75756 case OP_CreateIndex: /* out2-prerelease */
75757 case OP_CreateTable: { /* out2-prerelease */
75758 int pgno;
75759 int flags;
75760 Db *pDb;
75761
 
75762 pgno = 0;
75763 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75764 assert( DbMaskTest(p->btreeMask, pOp->p1) );
75765 assert( p->readOnly==0 );
75766 pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76148,16 @@
75982 if( (pIn1->flags & MEM_RowSet)==0
75983 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
75984 ){
75985 /* The boolean index is empty */
75986 sqlite3VdbeMemSetNull(pIn1);
75987 pc = pOp->p2 - 1;
75988 VdbeBranchTaken(1,2);
 
75989 }else{
75990 /* A value was pulled from the index */
75991 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
75992 VdbeBranchTaken(0,2);
 
75993 }
75994 goto check_for_interrupt;
75995 }
75996
75997 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76204,11 @@
76038 assert( pOp->p4type==P4_INT32 );
76039 assert( iSet==-1 || iSet>=0 );
76040 if( iSet ){
76041 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
76042 VdbeBranchTaken(exists!=0,2);
76043 if( exists ){
76044 pc = pOp->p2 - 1;
76045 break;
76046 }
76047 }
76048 if( iSet>=0 ){
76049 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
76050 }
76051 break;
@@ -76130,11 +76293,11 @@
76130 pRt->u.pFrame = pFrame;
76131
76132 pFrame->v = p;
76133 pFrame->nChildMem = nMem;
76134 pFrame->nChildCsr = pProgram->nCsr;
76135 pFrame->pc = pc;
76136 pFrame->aMem = p->aMem;
76137 pFrame->nMem = p->nMem;
76138 pFrame->apCsr = p->apCsr;
76139 pFrame->nCursor = p->nCursor;
76140 pFrame->aOp = p->aOp;
@@ -76153,11 +76316,11 @@
76153 }
76154 }else{
76155 pFrame = pRt->u.pFrame;
76156 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
76157 assert( pProgram->nCsr==pFrame->nChildCsr );
76158 assert( pc==pFrame->pc );
76159 }
76160
76161 p->nFrame++;
76162 pFrame->pParent = p->pFrame;
76163 pFrame->lastRowid = lastRowid;
@@ -76174,11 +76337,11 @@
76174 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
76175 p->nOnceFlag = pProgram->nOnce;
76176 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
76177 p->anExec = 0;
76178 #endif
76179 pc = -1;
76180 memset(p->aOnceFlag, 0, p->nOnceFlag);
76181
76182 break;
76183 }
76184
@@ -76192,13 +76355,14 @@
76192 **
76193 ** The address of the cell in the parent frame is determined by adding
76194 ** the value of the P1 argument to the value of the P1 argument to the
76195 ** calling OP_Program instruction.
76196 */
76197 case OP_Param: { /* out2-prerelease */
76198 VdbeFrame *pFrame;
76199 Mem *pIn;
 
76200 pFrame = p->pFrame;
76201 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
76202 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
76203 break;
76204 }
@@ -76238,14 +76402,14 @@
76238 ** (immediate foreign key constraint violations).
76239 */
76240 case OP_FkIfZero: { /* jump */
76241 if( pOp->p1 ){
76242 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76243 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76244 }else{
76245 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76246 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76247 }
76248 break;
76249 }
76250 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
76251
@@ -76292,13 +76456,11 @@
76292 */
76293 case OP_IfPos: { /* jump, in1 */
76294 pIn1 = &aMem[pOp->p1];
76295 assert( pIn1->flags&MEM_Int );
76296 VdbeBranchTaken( pIn1->u.i>0, 2);
76297 if( pIn1->u.i>0 ){
76298 pc = pOp->p2 - 1;
76299 }
76300 break;
76301 }
76302
76303 /* Opcode: IfNeg P1 P2 P3 * *
76304 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76471,11 @@
76309 case OP_IfNeg: { /* jump, in1 */
76310 pIn1 = &aMem[pOp->p1];
76311 assert( pIn1->flags&MEM_Int );
76312 pIn1->u.i += pOp->p3;
76313 VdbeBranchTaken(pIn1->u.i<0, 2);
76314 if( pIn1->u.i<0 ){
76315 pc = pOp->p2 - 1;
76316 }
76317 break;
76318 }
76319
76320 /* Opcode: IfNotZero P1 P2 P3 * *
76321 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76488,11 @@
76328 pIn1 = &aMem[pOp->p1];
76329 assert( pIn1->flags&MEM_Int );
76330 VdbeBranchTaken(pIn1->u.i<0, 2);
76331 if( pIn1->u.i ){
76332 pIn1->u.i += pOp->p3;
76333 pc = pOp->p2 - 1;
76334 }
76335 break;
76336 }
76337
76338 /* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76504,11 @@
76344 case OP_DecrJumpZero: { /* jump, in1 */
76345 pIn1 = &aMem[pOp->p1];
76346 assert( pIn1->flags&MEM_Int );
76347 pIn1->u.i--;
76348 VdbeBranchTaken(pIn1->u.i==0, 2);
76349 if( pIn1->u.i==0 ){
76350 pc = pOp->p2 - 1;
76351 }
76352 break;
76353 }
76354
76355
76356 /* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76520,11 @@
76362 */
76363 case OP_JumpZeroIncr: { /* jump, in1 */
76364 pIn1 = &aMem[pOp->p1];
76365 assert( pIn1->flags&MEM_Int );
76366 VdbeBranchTaken(pIn1->u.i==0, 2);
76367 if( (pIn1->u.i++)==0 ){
76368 pc = pOp->p2 - 1;
76369 }
76370 break;
76371 }
76372
76373 /* Opcode: AggStep * P2 P3 P4 P5
76374 ** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76562,11 @@
76406 pMem->n++;
76407 sqlite3VdbeMemInit(&t, db, MEM_Null);
76408 ctx.pOut = &t;
76409 ctx.isError = 0;
76410 ctx.pVdbe = p;
76411 ctx.iOp = pc;
76412 ctx.skipFlag = 0;
76413 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
76414 if( ctx.isError ){
76415 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
76416 rc = ctx.isError;
@@ -76501,19 +76657,20 @@
76501 **
76502 ** If changing into or out of WAL mode the procedure is more complicated.
76503 **
76504 ** Write a string containing the final journal-mode to register P2.
76505 */
76506 case OP_JournalMode: { /* out2-prerelease */
76507 Btree *pBt; /* Btree to change journal mode of */
76508 Pager *pPager; /* Pager associated with pBt */
76509 int eNew; /* New journal mode */
76510 int eOld; /* The old journal mode */
76511 #ifndef SQLITE_OMIT_WAL
76512 const char *zFilename; /* Name of database file for pPager */
76513 #endif
76514
 
76515 eNew = pOp->p3;
76516 assert( eNew==PAGER_JOURNALMODE_DELETE
76517 || eNew==PAGER_JOURNALMODE_TRUNCATE
76518 || eNew==PAGER_JOURNALMODE_PERSIST
76519 || eNew==PAGER_JOURNALMODE_OFF
@@ -76626,12 +76783,12 @@
76626 assert( p->readOnly==0 );
76627 pBt = db->aDb[pOp->p1].pBt;
76628 rc = sqlite3BtreeIncrVacuum(pBt);
76629 VdbeBranchTaken(rc==SQLITE_DONE,2);
76630 if( rc==SQLITE_DONE ){
76631 pc = pOp->p2 - 1;
76632 rc = SQLITE_OK;
 
76633 }
76634 break;
76635 }
76636 #endif
76637
@@ -76780,12 +76937,13 @@
76780 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76781 if( pCur ){
76782 pCur->pVtabCursor = pVtabCursor;
76783 pVtab->nRef++;
76784 }else{
76785 db->mallocFailed = 1;
76786 pModule->xClose(pVtabCursor);
 
76787 }
76788 }
76789 break;
76790 }
76791 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76995,23 @@
76837 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
76838 nArg = (int)pArgc->u.i;
76839 iQuery = (int)pQuery->u.i;
76840
76841 /* Invoke the xFilter method */
76842 {
76843 res = 0;
76844 apArg = p->apArg;
76845 for(i = 0; i<nArg; i++){
76846 apArg[i] = &pArgc[i+1];
76847 }
76848
76849 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76850 sqlite3VtabImportErrmsg(p, pVtab);
76851 if( rc==SQLITE_OK ){
76852 res = pModule->xEof(pVtabCursor);
76853 }
76854 VdbeBranchTaken(res!=0,2);
76855 if( res ){
76856 pc = pOp->p2 - 1;
76857 }
76858 }
76859 pCur->nullRow = 0;
76860
 
76861 break;
76862 }
76863 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76864
76865 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77094,11 @@
76942 res = pModule->xEof(pCur->pVtabCursor);
76943 }
76944 VdbeBranchTaken(!res,2);
76945 if( !res ){
76946 /* If there is data, jump to P2 */
76947 pc = pOp->p2 - 1;
76948 }
76949 goto check_for_interrupt;
76950 }
76951 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76952
@@ -77065,11 +77217,12 @@
77065 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
77066 /* Opcode: Pagecount P1 P2 * * *
77067 **
77068 ** Write the current number of pages in database P1 to memory cell P2.
77069 */
77070 case OP_Pagecount: { /* out2-prerelease */
 
77071 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
77072 break;
77073 }
77074 #endif
77075
@@ -77081,14 +77234,15 @@
77081 ** Do not let the maximum page count fall below the current page count and
77082 ** do not change the maximum page count value if P3==0.
77083 **
77084 ** Store the maximum page count after the change in register P2.
77085 */
77086 case OP_MaxPgcnt: { /* out2-prerelease */
77087 unsigned int newMax;
77088 Btree *pBt;
77089
 
77090 pBt = db->aDb[pOp->p1].pBt;
77091 newMax = 0;
77092 if( pOp->p3 ){
77093 newMax = sqlite3BtreeLastPage(pBt);
77094 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77267,10 @@
77113 */
77114 case OP_Init: { /* jump */
77115 char *zTrace;
77116 char *z;
77117
77118 if( pOp->p2 ){
77119 pc = pOp->p2 - 1;
77120 }
77121 #ifndef SQLITE_OMIT_TRACE
77122 if( db->xTrace
77123 && !p->doingRerun
77124 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
77125 ){
@@ -77143,10 +77294,11 @@
77143 ){
77144 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
77145 }
77146 #endif /* SQLITE_DEBUG */
77147 #endif /* SQLITE_OMIT_TRACE */
 
77148 break;
77149 }
77150
77151
77152 /* Opcode: Noop * * * * *
@@ -77174,31 +77326,31 @@
77174 }
77175
77176 #ifdef VDBE_PROFILE
77177 {
77178 u64 endTime = sqlite3Hwtime();
77179 if( endTime>start ) pOp->cycles += endTime - start;
77180 pOp->cnt++;
77181 }
77182 #endif
77183
77184 /* The following code adds nothing to the actual functionality
77185 ** of the program. It is only here for testing and debugging.
77186 ** On the other hand, it does burn CPU cycles every time through
77187 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
77188 */
77189 #ifndef NDEBUG
77190 assert( pc>=-1 && pc<p->nOp );
77191
77192 #ifdef SQLITE_DEBUG
77193 if( db->flags & SQLITE_VdbeTrace ){
77194 if( rc!=0 ) printf("rc=%d\n",rc);
77195 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
77196 registerTrace(pOp->p2, &aMem[pOp->p2]);
77197 }
77198 if( pOp->opflags & OPFLG_OUT3 ){
77199 registerTrace(pOp->p3, &aMem[pOp->p3]);
77200 }
77201 }
77202 #endif /* SQLITE_DEBUG */
77203 #endif /* NDEBUG */
77204 } /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77361,11 @@
77209 vdbe_error_halt:
77210 assert( rc );
77211 p->rc = rc;
77212 testcase( sqlite3GlobalConfig.xLog!=0 );
77213 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77214 pc, p->zSql, p->zErrMsg);
77215 sqlite3VdbeHalt(p);
77216 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
77217 rc = SQLITE_ERROR;
77218 if( resetSchemaOnFault>0 ){
77219 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78187,23 @@
78035 **
78036 ** In both cases, the effects of the main thread seeing (bDone==0) even
78037 ** after the thread has finished are not dire. So we don't worry about
78038 ** memory barriers and such here.
78039 */
 
78040 struct SortSubtask {
78041 SQLiteThread *pThread; /* Background thread, if any */
78042 int bDone; /* Set if thread is finished but not joined */
78043 VdbeSorter *pSorter; /* Sorter that owns this sub-task */
78044 UnpackedRecord *pUnpacked; /* Space to unpack a record */
78045 SorterList list; /* List for thread to write to a PMA */
78046 int nPMA; /* Number of PMAs currently in file */
 
78047 SorterFile file; /* Temp file for level-0 PMAs */
78048 SorterFile file2; /* Space for other PMAs */
78049 };
 
78050
78051 /*
78052 ** Main sorter structure. A single instance of this is allocated for each
78053 ** sorter cursor created by the VDBE.
78054 **
@@ -78072,12 +78227,16 @@
78072 int nMemory; /* Size of list.aMemory allocation in bytes */
78073 u8 bUsePMA; /* True if one or more PMAs created */
78074 u8 bUseThreads; /* True to use background threads */
78075 u8 iPrev; /* Previous thread used to flush PMA */
78076 u8 nTask; /* Size of aTask[] array */
 
78077 SortSubtask aTask[1]; /* One or more subtasks */
78078 };
 
 
 
78079
78080 /*
78081 ** An instance of the following object is used to read records out of a
78082 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
78083 ** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78645,165 @@
78486 rc = vdbePmaReaderNext(pReadr);
78487 }
78488 return rc;
78489 }
78490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78491
78492 /*
78493 ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
78494 ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
78495 ** used by the comparison. Return the result of the comparison.
78496 **
78497 ** Before returning, object (pTask->pUnpacked) is populated with the
78498 ** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it
78499 ** is assumed that the (pTask->pUnpacked) structure already contains the
78500 ** unpacked key to use as key2.
78501 **
78502 ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
78503 ** to SQLITE_NOMEM.
78504 */
78505 static int vdbeSorterCompare(
78506 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
 
78507 const void *pKey1, int nKey1, /* Left side of comparison */
78508 const void *pKey2, int nKey2 /* Right side of comparison */
78509 ){
78510 UnpackedRecord *r2 = pTask->pUnpacked;
78511 if( pKey2 ){
78512 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
 
78513 }
78514 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
78515 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78516
78517 /*
78518 ** Initialize the temporary index cursor just opened as a sorter cursor.
78519 **
78520 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78868,17 @@
78579 rc = SQLITE_NOMEM;
78580 }else{
78581 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
78582 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
78583 pKeyInfo->db = 0;
78584 if( nField && nWorker==0 ) pKeyInfo->nField = nField;
 
 
 
78585 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
78586 pSorter->nTask = nWorker + 1;
 
78587 pSorter->bUseThreads = (pSorter->nTask>1);
78588 pSorter->db = db;
78589 for(i=0; i<pSorter->nTask; i++){
78590 SortSubtask *pTask = &pSorter->aTask[i];
78591 pTask->pSorter = pSorter;
@@ -78607,10 +78900,16 @@
78607 pSorter->nMemory = pgsz;
78608 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
78609 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
78610 }
78611 }
 
 
 
 
 
 
78612 }
78613
78614 return rc;
78615 }
78616 #undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78930,28 @@
78631 ** Free all resources owned by the object indicated by argument pTask. All
78632 ** fields of *pTask are zeroed before returning.
78633 */
78634 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
78635 sqlite3DbFree(db, pTask->pUnpacked);
78636 pTask->pUnpacked = 0;
78637 #if SQLITE_MAX_WORKER_THREADS>0
78638 /* pTask->list.aMemory can only be non-zero if it was handed memory
78639 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
78640 if( pTask->list.aMemory ){
78641 sqlite3_free(pTask->list.aMemory);
78642 pTask->list.aMemory = 0;
78643 }else
78644 #endif
78645 {
78646 assert( pTask->list.aMemory==0 );
78647 vdbeSorterRecordFree(0, pTask->list.pList);
78648 }
78649 pTask->list.pList = 0;
78650 if( pTask->file.pFd ){
78651 sqlite3OsCloseFree(pTask->file.pFd);
78652 pTask->file.pFd = 0;
78653 pTask->file.iEof = 0;
78654 }
78655 if( pTask->file2.pFd ){
78656 sqlite3OsCloseFree(pTask->file2.pFd);
78657 pTask->file2.pFd = 0;
78658 pTask->file2.iEof = 0;
78659 }
 
78660 }
78661
78662 #ifdef SQLITE_DEBUG_SORTER_THREADS
78663 static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
78664 i64 t;
@@ -78834,10 +79127,11 @@
78834 vdbeMergeEngineFree(pSorter->pMerger);
78835 pSorter->pMerger = 0;
78836 for(i=0; i<pSorter->nTask; i++){
78837 SortSubtask *pTask = &pSorter->aTask[i];
78838 vdbeSortSubtaskCleanup(db, pTask);
 
78839 }
78840 if( pSorter->list.aMemory==0 ){
78841 vdbeSorterRecordFree(0, pSorter->list.pList);
78842 }
78843 pSorter->list.pList = 0;
@@ -78943,31 +79237,45 @@
78943 SorterRecord *p2, /* Second list to merge */
78944 SorterRecord **ppOut /* OUT: Head of merged list */
78945 ){
78946 SorterRecord *pFinal = 0;
78947 SorterRecord **pp = &pFinal;
78948 void *pVal2 = p2 ? SRVAL(p2) : 0;
78949
78950 while( p1 && p2 ){
78951 int res;
78952 res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal);
 
 
 
78953 if( res<=0 ){
78954 *pp = p1;
78955 pp = &p1->u.pNext;
78956 p1 = p1->u.pNext;
78957 pVal2 = 0;
78958 }else{
78959 *pp = p2;
78960 pp = &p2->u.pNext;
78961 p2 = p2->u.pNext;
78962 if( p2==0 ) break;
78963 pVal2 = SRVAL(p2);
78964 }
78965 }
78966 *pp = p1 ? p1 : p2;
78967 *ppOut = pFinal;
78968 }
 
 
 
 
 
 
 
 
 
 
 
 
 
78969
78970 /*
78971 ** Sort the linked list of records headed at pTask->pList. Return
78972 ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
78973 ** an error occurs.
@@ -78979,16 +79287,18 @@
78979 int rc;
78980
78981 rc = vdbeSortAllocUnpacked(pTask);
78982 if( rc!=SQLITE_OK ) return rc;
78983
 
 
 
78984 aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
78985 if( !aSlot ){
78986 return SQLITE_NOMEM;
78987 }
78988
78989 p = pList->pList;
78990 while( p ){
78991 SorterRecord *pNext;
78992 if( pList->aMemory ){
78993 if( (u8*)p==pList->aMemory ){
78994 pNext = 0;
@@ -79198,28 +79508,27 @@
79198 /* Update contents of aTree[] */
79199 if( rc==SQLITE_OK ){
79200 int i; /* Index of aTree[] to recalculate */
79201 PmaReader *pReadr1; /* First PmaReader to compare */
79202 PmaReader *pReadr2; /* Second PmaReader to compare */
79203 u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */
79204
79205 /* Find the first two PmaReaders to compare. The one that was just
79206 ** advanced (iPrev) and the one next to it in the array. */
79207 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
79208 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
79209 pKey2 = pReadr2->aKey;
79210
79211 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
79212 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
79213 int iRes;
79214 if( pReadr1->pFd==0 ){
79215 iRes = +1;
79216 }else if( pReadr2->pFd==0 ){
79217 iRes = -1;
79218 }else{
79219 iRes = vdbeSorterCompare(pTask,
79220 pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey
79221 );
79222 }
79223
79224 /* If pReadr1 contained the smaller value, set aTree[i] to its index.
79225 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79546,13 @@
79237 ** is sorted from oldest to newest, so pReadr1 contains older values
79238 ** than pReadr2 iff (pReadr1<pReadr2). */
79239 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
79240 pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
79241 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79242 pKey2 = pReadr2->aKey;
79243 }else{
79244 if( pReadr1->pFd ) pKey2 = 0;
79245 pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
79246 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79247 }
79248 }
79249 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79655,20 @@
79346 SorterRecord *pNew; /* New list element */
79347
79348 int bFlush; /* True to flush contents of memory to PMA */
79349 int nReq; /* Bytes of memory required */
79350 int nPMA; /* Bytes of PMA space required */
 
 
 
 
 
 
 
 
 
 
79351
79352 assert( pSorter );
79353
79354 /* Figure out whether or not the current contents of memory should be
79355 ** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79930,16 @@
79611 if( p1->pFd==0 ){
79612 iRes = i2;
79613 }else if( p2->pFd==0 ){
79614 iRes = i1;
79615 }else{
 
 
79616 int res;
79617 assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79618 res = vdbeSorterCompare(
79619 pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79620 );
79621 if( res<=0 ){
79622 iRes = i1;
79623 }else{
79624 iRes = i2;
@@ -79638,15 +79959,16 @@
79638 */
79639 #define INCRINIT_NORMAL 0
79640 #define INCRINIT_TASK 1
79641 #define INCRINIT_ROOT 2
79642
79643 /* Forward reference.
79644 ** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each
79645 ** other (when building a merge tree).
 
79646 */
79647 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode);
79648
79649 /*
79650 ** Initialize the MergeEngine object passed as the second argument. Once this
79651 ** function returns, the first key of merged data may be read from the
79652 ** MergeEngine object in the usual fashion.
@@ -79689,11 +80011,11 @@
79689 ** the main thread to fill its buffer. So calling PmaReaderNext()
79690 ** on this PmaReader before any of the multi-threaded PmaReaders takes
79691 ** better advantage of multi-processor hardware. */
79692 rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
79693 }else{
79694 rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
79695 }
79696 if( rc!=SQLITE_OK ) return rc;
79697 }
79698
79699 for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80023,19 @@
79701 }
79702 return pTask->pUnpacked->errCode;
79703 }
79704
79705 /*
79706 ** Initialize the IncrMerge field of a PmaReader.
79707 **
79708 ** If the PmaReader passed as the first argument is not an incremental-reader
79709 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves
79710 ** to open and/or initialize the temp file related fields of the IncrMerge
79711 ** object at (pReadr->pIncr).
79712 **
79713 ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
79714 ** in the sub-tree headed by pReadr are also initialized. Data is then loaded
79715 ** into the buffers belonging to pReadr and it is set to
79716 ** point to the first key in its range.
79717 **
79718 ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
79719 ** to be a multi-threaded PmaReader and this function is being called in a
79720 ** background thread. In this case all PmaReaders in the sub-tree are
79721 ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80058,112 @@
79738 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
79739 */
79740 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
79741 int rc = SQLITE_OK;
79742 IncrMerger *pIncr = pReadr->pIncr;
 
 
79743
79744 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
79745 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
79746
79747 if( pIncr ){
79748 SortSubtask *pTask = pIncr->pTask;
79749 sqlite3 *db = pTask->pSorter->db;
79750
79751 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
79752
79753 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
79754 ** requires two temp files to itself, whereas a single-threaded object
79755 ** only requires a region of pTask->file2. */
79756 if( rc==SQLITE_OK ){
79757 int mxSz = pIncr->mxSz;
79758 #if SQLITE_MAX_WORKER_THREADS>0
79759 if( pIncr->bUseThread ){
79760 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
79761 if( rc==SQLITE_OK ){
79762 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
79763 }
79764 }else
79765 #endif
79766 /*if( !pIncr->bUseThread )*/{
79767 if( pTask->file2.pFd==0 ){
79768 assert( pTask->file2.iEof>0 );
79769 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
79770 pTask->file2.iEof = 0;
79771 }
79772 if( rc==SQLITE_OK ){
79773 pIncr->aFile[1].pFd = pTask->file2.pFd;
79774 pIncr->iStartOff = pTask->file2.iEof;
79775 pTask->file2.iEof += mxSz;
79776 }
79777 }
79778 }
79779
79780 #if SQLITE_MAX_WORKER_THREADS>0
79781 if( rc==SQLITE_OK && pIncr->bUseThread ){
79782 /* Use the current thread to populate aFile[1], even though this
79783 ** PmaReader is multi-threaded. The reason being that this function
79784 ** is already running in background thread pIncr->pTask->thread. */
79785 assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
79786 rc = vdbeIncrPopulate(pIncr);
79787 }
79788 #endif
79789
79790 if( rc==SQLITE_OK
79791 && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK)
79792 ){
79793 rc = vdbePmaReaderNext(pReadr);
79794 }
79795 }
 
79796 return rc;
79797 }
79798
79799 #if SQLITE_MAX_WORKER_THREADS>0
79800 /*
79801 ** The main routine for vdbePmaReaderIncrMergeInit() operations run in
79802 ** background threads.
79803 */
79804 static void *vdbePmaReaderBgInit(void *pCtx){
79805 PmaReader *pReader = (PmaReader*)pCtx;
79806 void *pRet = SQLITE_INT_TO_PTR(
79807 vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
79808 );
79809 pReader->pIncr->pTask->bDone = 1;
79810 return pRet;
79811 }
 
79812
79813 /*
79814 ** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
79815 ** on the PmaReader object passed as the first argument.
79816 **
79817 ** This call will initialize the various fields of the pReadr->pIncr
79818 ** structure and, if it is a multi-threaded IncrMerger, launch a
79819 ** background thread to populate aFile[1].
 
 
 
79820 */
79821 static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){
79822 void *pCtx = (void*)pReadr;
79823 return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx);
 
 
 
 
 
 
 
 
 
 
 
 
 
79824 }
79825 #endif
79826
79827 /*
79828 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
79829 ** PMAs from pTask->file. If no error occurs, set *ppOut to point to
79830 ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80371,15 @@
80032 int rc; /* Return code */
80033 SortSubtask *pTask0 = &pSorter->aTask[0];
80034 MergeEngine *pMain = 0;
80035 #if SQLITE_MAX_WORKER_THREADS
80036 sqlite3 *db = pTask0->pSorter->db;
 
 
 
 
 
80037 #endif
80038
80039 rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
80040 if( rc==SQLITE_OK ){
80041 #if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80404,25 @@
80060 vdbeIncrMergerSetThreads(pIncr);
80061 assert( pIncr->pTask!=pLast );
80062 }
80063 }
80064 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
 
 
 
 
 
 
 
 
 
80065 PmaReader *p = &pMain->aReadr[iTask];
80066 assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
80067 if( p->pIncr ){
80068 if( iTask==pSorter->nTask-1 ){
80069 rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK);
80070 }else{
80071 rc = vdbePmaReaderBgIncrInit(p);
80072 }
80073 }
80074 }
80075 }
80076 pMain = 0;
80077 }
80078 if( rc==SQLITE_OK ){
@@ -81023,11 +81373,11 @@
81023 ** Should be transformed into:
81024 **
81025 ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
81026 **
81027 ** The nSubquery parameter specifies how many levels of subquery the
81028 ** alias is removed from the original expression. The usually value is
81029 ** zero but it might be more if the alias is contained within a subquery
81030 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
81031 ** structures must be increased by the nSubquery amount.
81032 */
81033 static void resolveAlias(
@@ -81043,11 +81393,11 @@
81043 sqlite3 *db; /* The database connection */
81044
81045 assert( iCol>=0 && iCol<pEList->nExpr );
81046 pOrig = pEList->a[iCol].pExpr;
81047 assert( pOrig!=0 );
81048 assert( pOrig->flags & EP_Resolved );
81049 db = pParse->db;
81050 pDup = sqlite3ExprDup(db, pOrig, 0);
81051 if( pDup==0 ) return;
81052 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
81053 incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82287,15 @@
81937 pNew->flags |= EP_IntValue;
81938 pNew->u.iValue = iCol;
81939 if( pItem->pExpr==pE ){
81940 pItem->pExpr = pNew;
81941 }else{
81942 assert( pItem->pExpr->op==TK_COLLATE );
81943 assert( pItem->pExpr->pLeft==pE );
81944 pItem->pExpr->pLeft = pNew;
 
 
81945 }
81946 sqlite3ExprDelete(db, pE);
81947 pItem->u.x.iOrderByCol = (u16)iCol;
81948 pItem->done = 1;
81949 }else{
@@ -82139,11 +82491,11 @@
82139 ** as if it were part of the sub-query, not the parent. This block
82140 ** moves the pOrderBy down to the sub-query. It will be moved back
82141 ** after the names have been resolved. */
82142 if( p->selFlags & SF_Converted ){
82143 Select *pSub = p->pSrc->a[0].pSelect;
82144 assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82145 assert( pSub->pPrior && pSub->pOrderBy==0 );
82146 pSub->pOrderBy = p->pOrderBy;
82147 p->pOrderBy = 0;
82148 }
82149
@@ -82241,12 +82593,19 @@
82241
82242 /* Process the ORDER BY clause for singleton SELECT statements.
82243 ** The ORDER BY clause for compounds SELECT statements is handled
82244 ** below, after all of the result-sets for all of the elements of
82245 ** the compound have been resolved.
 
 
 
 
 
82246 */
82247 if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){
 
 
82248 return WRC_Abort;
82249 }
82250 if( db->mallocFailed ){
82251 return WRC_Abort;
82252 }
@@ -83694,11 +84053,12 @@
83694 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
83695 int i;
83696 u32 m = 0;
83697 if( pList ){
83698 for(i=0; i<pList->nExpr; i++){
83699 m |= pList->a[i].pExpr->flags;
 
83700 }
83701 }
83702 return m;
83703 }
83704
@@ -84134,11 +84494,11 @@
84134 /* Check to see if an existing table or index can be used to
84135 ** satisfy the query. This is preferable to generating a new
84136 ** ephemeral table.
84137 */
84138 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84139 if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
84140 sqlite3 *db = pParse->db; /* Database connection */
84141 Table *pTab; /* Table <table>. */
84142 Expr *pExpr; /* Expression <column> */
84143 i16 iCol; /* Index of column <column> */
84144 i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84819,11 @@
84459 }
84460 sqlite3ExprDelete(pParse->db, pSel->pLimit);
84461 pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
84462 &sqlite3IntTokens[1]);
84463 pSel->iLimit = 0;
 
84464 if( sqlite3Select(pParse, pSel, &dest) ){
84465 return 0;
84466 }
84467 rReg = dest.iSDParm;
84468 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86185,11 @@
85824 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
85825 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
85826 break;
85827 }
85828 case TK_ID: {
85829 sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
85830 break;
85831 }
85832 #ifndef SQLITE_OMIT_CAST
85833 case TK_CAST: {
85834 /* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86820,11 @@
86459 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
86460 if( combinedFlags & EP_xIsSelect ) return 2;
86461 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
86462 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
86463 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86464 if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
86465 if( pA->iColumn!=pB->iColumn ) return 2;
86466 if( pA->iTable!=pB->iTable
86467 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
86468 }
86469 }
@@ -86991,10 +87352,11 @@
86991 do {
86992 z += n;
86993 n = sqlite3GetToken(z, &token);
86994 }while( token==TK_SPACE );
86995
 
86996 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
86997 if( zParent==0 ) break;
86998 sqlite3Dequote(zParent);
86999 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
87000 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89579,21 @@
89217 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
89218 }
89219 z = argv[2];
89220
89221 if( pIndex ){
 
89222 int nCol = pIndex->nKeyCol+1;
89223 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89224 tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
89225 sizeof(tRowcnt) * nCol
89226 );
89227 if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89228 #else
89229 tRowcnt * const aiRowEst = 0;
 
 
89230 #endif
89231 pIndex->bUnordered = 0;
89232 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
89233 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
89234 }else{
@@ -89887,11 +90252,11 @@
89887 }
89888
89889 sqlite3BtreeClose(pDb->pBt);
89890 pDb->pBt = 0;
89891 pDb->pSchema = 0;
89892 sqlite3ResetAllSchemasOfConnection(db);
89893 return;
89894
89895 detach_error:
89896 sqlite3_result_error(context, zErr, -1);
89897 }
@@ -89921,11 +90286,10 @@
89921 if(
89922 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
89923 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
89924 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
89925 ){
89926 pParse->nErr++;
89927 goto attach_end;
89928 }
89929
89930 #ifndef SQLITE_OMIT_AUTHORIZATION
89931 if( pAuthArg ){
@@ -90580,13 +90944,15 @@
90580 sqlite3 *db;
90581 Vdbe *v;
90582
90583 assert( pParse->pToplevel==0 );
90584 db = pParse->db;
90585 if( db->mallocFailed ) return;
90586 if( pParse->nested ) return;
90587 if( pParse->nErr ) return;
 
 
 
90588
90589 /* Begin by generating some termination code at the end of the
90590 ** vdbe program
90591 */
90592 v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91030,11 @@
90664 }
90665
90666
90667 /* Get the VDBE program ready for execution
90668 */
90669 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
90670 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
90671 /* A minimum of one cursor is required if autoincrement is used
90672 * See ticket [a696379c1f08866] */
90673 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
90674 sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91565,16 @@
91199 sqlite3 *db = pParse->db;
91200
91201 if( ALWAYS(pName2!=0) && pName2->n>0 ){
91202 if( db->init.busy ) {
91203 sqlite3ErrorMsg(pParse, "corrupt database");
91204 pParse->nErr++;
91205 return -1;
91206 }
91207 *pUnqual = pName2;
91208 iDb = sqlite3FindDb(db, pName1);
91209 if( iDb<0 ){
91210 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
91211 pParse->nErr++;
91212 return -1;
91213 }
91214 }else{
91215 assert( db->init.iDb==0 || db->init.busy );
91216 iDb = db->init.iDb;
@@ -91365,11 +91729,11 @@
91365 pTable = sqlite3FindTable(db, zName, zDb);
91366 if( pTable ){
91367 if( !noErr ){
91368 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
91369 }else{
91370 assert( !db->init.busy );
91371 sqlite3CodeVerifySchema(pParse, iDb);
91372 }
91373 goto begin_table_error;
91374 }
91375 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92018,12 @@
91654 Column *pCol;
91655
91656 p = pParse->pNewTable;
91657 if( p==0 || NEVER(p->nCol<1) ) return;
91658 pCol = &p->aCol[p->nCol-1];
91659 assert( pCol->zType==0 );
 
91660 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
91661 pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
91662 }
91663
91664 /*
@@ -92888,10 +93253,11 @@
92888 if( db->mallocFailed ){
92889 goto exit_drop_table;
92890 }
92891 assert( pParse->nErr==0 );
92892 assert( pName->nSrc==1 );
 
92893 if( noErr ) db->suppressErr++;
92894 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
92895 if( noErr ) db->suppressErr--;
92896
92897 if( pTab==0 ){
@@ -93201,11 +93567,12 @@
93201 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
93202 }else{
93203 addr2 = sqlite3VdbeCurrentAddr(v);
93204 }
93205 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93206 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
 
93207 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
93208 sqlite3ReleaseTempReg(pParse, regRecord);
93209 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
93210 sqlite3VdbeJumpHere(v, addr1);
93211
@@ -93294,12 +93661,11 @@
93294 int nExtra = 0; /* Space allocated for zExtra[] */
93295 int nExtraCol; /* Number of extra columns needed */
93296 char *zExtra = 0; /* Extra space after the Index object */
93297 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
93298
93299 assert( pParse->nErr==0 ); /* Never called with prior errors */
93300 if( db->mallocFailed || IN_DECLARE_VTAB ){
93301 goto exit_create_index;
93302 }
93303 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
93304 goto exit_create_index;
93305 }
@@ -94214,11 +94580,10 @@
94214 ** operator with A. This routine shifts that operator over to B.
94215 */
94216 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
94217 if( p ){
94218 int i;
94219 assert( p->a || p->nSrc==0 );
94220 for(i=p->nSrc-1; i>0; i--){
94221 p->a[i].jointype = p->a[i-1].jointype;
94222 }
94223 p->a[0].jointype = 0;
94224 }
@@ -94461,12 +94826,11 @@
94461 char *zErr;
94462 int j;
94463 StrAccum errMsg;
94464 Table *pTab = pIdx->pTable;
94465
94466 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
94467 errMsg.db = pParse->db;
94468 for(j=0; j<pIdx->nKeyCol; j++){
94469 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
94470 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
94471 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
94472 sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96655,17 @@
96291 ){
96292 PrintfArguments x;
96293 StrAccum str;
96294 const char *zFormat;
96295 int n;
 
96296
96297 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
96298 x.nArg = argc-1;
96299 x.nUsed = 0;
96300 x.apArg = argv+1;
96301 sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
96302 str.db = sqlite3_context_db_handle(context);
96303 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
96304 n = str.nChar;
96305 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
96306 SQLITE_DYNAMIC);
96307 }
@@ -96447,11 +96811,11 @@
96447 sqlite3_result_double(context, r);
96448 }
96449 #endif
96450
96451 /*
96452 ** Allocate nByte bytes of space using sqlite3_malloc(). If the
96453 ** allocation fails, call sqlite3_result_error_nomem() to notify
96454 ** the database handle that malloc() has failed and return NULL.
96455 ** If nByte is larger than the maximum string or blob length, then
96456 ** raise an SQLITE_TOOBIG exception and return NULL.
96457 */
@@ -97116,11 +97480,11 @@
97116 int argc,
97117 sqlite3_value **argv
97118 ){
97119 unsigned char *z, *zOut;
97120 int i;
97121 zOut = z = sqlite3_malloc( argc*4+1 );
97122 if( z==0 ){
97123 sqlite3_result_error_nomem(context);
97124 return;
97125 }
97126 for(i=0; i<argc; i++){
@@ -97264,11 +97628,11 @@
97264 sqlite3_result_error_toobig(context);
97265 sqlite3_free(zOut);
97266 return;
97267 }
97268 zOld = zOut;
97269 zOut = sqlite3_realloc(zOut, (int)nOut);
97270 if( zOut==0 ){
97271 sqlite3_result_error_nomem(context);
97272 sqlite3_free(zOld);
97273 return;
97274 }
@@ -97626,12 +97990,11 @@
97626 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
97627 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
97628
97629 if( pAccum ){
97630 sqlite3 *db = sqlite3_context_db_handle(context);
97631 int firstTerm = pAccum->useMalloc==0;
97632 pAccum->useMalloc = 2;
97633 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
97634 if( !firstTerm ){
97635 if( argc==2 ){
97636 zSep = (char*)sqlite3_value_text(argv[1]);
97637 nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99410,12 @@
99047 int iFromCol; /* Idx of column in child table */
99048 Expr *pEq; /* tFromCol = OLD.tToCol */
99049
99050 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
99051 assert( iFromCol>=0 );
99052 tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid";
 
99053 tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
99054
99055 tToCol.n = sqlite3Strlen30(tToCol.z);
99056 tFromCol.n = sqlite3Strlen30(tFromCol.z);
99057
@@ -99059,14 +99423,14 @@
99059 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
99060 ** that the affinity and collation sequence associated with the
99061 ** parent table are used for the comparison. */
99062 pEq = sqlite3PExpr(pParse, TK_EQ,
99063 sqlite3PExpr(pParse, TK_DOT,
99064 sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99065 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99066 , 0),
99067 sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol)
99068 , 0);
99069 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
99070
99071 /* For ON UPDATE, construct the next term of the WHEN clause.
99072 ** The final WHEN clause will be like this:
@@ -99074,27 +99438,27 @@
99074 ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
99075 */
99076 if( pChanges ){
99077 pEq = sqlite3PExpr(pParse, TK_IS,
99078 sqlite3PExpr(pParse, TK_DOT,
99079 sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99080 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99081 0),
99082 sqlite3PExpr(pParse, TK_DOT,
99083 sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99084 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99085 0),
99086 0);
99087 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
99088 }
99089
99090 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
99091 Expr *pNew;
99092 if( action==OE_Cascade ){
99093 pNew = sqlite3PExpr(pParse, TK_DOT,
99094 sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99095 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99096 , 0);
99097 }else if( action==OE_SetDflt ){
99098 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
99099 if( pDflt ){
99100 pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99501,16 @@
99137 db->lookaside.bEnabled = 0;
99138
99139 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
99140 sizeof(Trigger) + /* struct Trigger */
99141 sizeof(TriggerStep) + /* Single step in trigger program */
99142 nFrom + 1 /* Space for pStep->target.z */
99143 );
99144 if( pTrigger ){
99145 pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99146 pStep->target.z = (char *)&pStep[1];
99147 pStep->target.n = nFrom;
99148 memcpy((char *)pStep->target.z, zFrom, nFrom);
99149
99150 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99151 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
99152 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99153 if( pWhen ){
@@ -99608,24 +99971,27 @@
99608 );
99609
99610 /*
99611 ** This routine is called to handle SQL of the following forms:
99612 **
99613 ** insert into TABLE (IDLIST) values(EXPRLIST)
99614 ** insert into TABLE (IDLIST) select
 
99615 **
99616 ** The IDLIST following the table name is always optional. If omitted,
99617 ** then a list of all columns for the table is substituted. The IDLIST
99618 ** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
 
99619 **
99620 ** The pList parameter holds EXPRLIST in the first form of the INSERT
99621 ** statement above, and pSelect is NULL. For the second form, pList is
99622 ** NULL and pSelect is a pointer to the select statement used to generate
99623 ** data for the insert.
 
99624 **
99625 ** The code generated follows one of four templates. For a simple
99626 ** insert with data coming from a VALUES clause, the code executes
99627 ** once straight down through. Pseudo-code follows (we call this
99628 ** the "1st template"):
99629 **
99630 ** open write cursor to <table> and its indices
99631 ** put VALUES clause expressions into registers
@@ -99728,11 +100094,11 @@
99728 int iDb; /* Index of database holding TABLE */
99729 Db *pDb; /* The database containing table being inserted into */
99730 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
99731 u8 appendFlag = 0; /* True if the insert is likely to be an append */
99732 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
99733 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
99734 ExprList *pList = 0; /* List of VALUES() to be inserted */
99735
99736 /* Register allocations */
99737 int regFromSelect = 0;/* Base register for data coming from SELECT */
99738 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100119,12 @@
99753 if( pParse->nErr || db->mallocFailed ){
99754 goto insert_cleanup;
99755 }
99756
99757 /* If the Select object is really just a simple VALUES() list with a
99758 ** single row values (the common case) then keep that one row of values
99759 ** and go ahead and discard the Select object
99760 */
99761 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
99762 pList = pSelect->pEList;
99763 pSelect->pEList = 0;
99764 sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100228,11 @@
99862 ** the index into IDLIST of the primary key column. ipkColumn is
99863 ** the index of the primary key as it appears in IDLIST, not as
99864 ** is appears in the original table. (The index of the INTEGER
99865 ** PRIMARY KEY in the original table is pTab->iPKey.)
99866 */
 
99867 if( pColumn ){
99868 for(i=0; i<pColumn->nId; i++){
99869 pColumn->a[i].idx = -1;
99870 }
99871 for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100264,12 @@
99897 ** is coming from a SELECT statement, then generate a co-routine that
99898 ** produces a single row of the SELECT on each invocation. The
99899 ** co-routine is the common header to the 3rd and 4th templates.
99900 */
99901 if( pSelect ){
99902 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
 
99903 int regYield; /* Register holding co-routine entry-point */
99904 int addrTop; /* Top of the co-routine */
99905 int rc; /* Result code */
99906
99907 regYield = ++pParse->nMem;
@@ -99910,12 +100278,11 @@
99910 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
99911 dest.iSdst = bIdListInOrder ? regData : 0;
99912 dest.nSdst = pTab->nCol;
99913 rc = sqlite3Select(pParse, pSelect, &dest);
99914 regFromSelect = dest.iSdst;
99915 assert( pParse->nErr==0 || rc );
99916 if( rc || db->mallocFailed ) goto insert_cleanup;
99917 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
99918 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
99919 assert( pSelect->pEList );
99920 nColumn = pSelect->pEList->nExpr;
99921
@@ -99959,12 +100326,12 @@
99959 sqlite3VdbeJumpHere(v, addrL);
99960 sqlite3ReleaseTempReg(pParse, regRec);
99961 sqlite3ReleaseTempReg(pParse, regTempRowid);
99962 }
99963 }else{
99964 /* This is the case if the data for the INSERT is coming from a VALUES
99965 ** clause
99966 */
99967 NameContext sNC;
99968 memset(&sNC, 0, sizeof(sNC));
99969 sNC.pParse = pParse;
99970 srcTab = -1;
@@ -101031,10 +101398,11 @@
101031 Table *pDest, /* The table we are inserting into */
101032 Select *pSelect, /* A SELECT statement to use as the data source */
101033 int onError, /* How to handle constraint errors */
101034 int iDbDest /* The database of pDest */
101035 ){
 
101036 ExprList *pEList; /* The result set of the SELECT */
101037 Table *pSrc; /* The table in the FROM clause of SELECT */
101038 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101039 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101040 int i; /* Loop counter */
@@ -101178,15 +101546,15 @@
101178 ** But the main beneficiary of the transfer optimization is the VACUUM
101179 ** command, and the VACUUM command disables foreign key constraints. So
101180 ** the extra complication to make this rule less restrictive is probably
101181 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101182 */
101183 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101184 return 0;
101185 }
101186 #endif
101187 if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
101188 return 0; /* xfer opt does not play well with PRAGMA count_changes */
101189 }
101190
101191 /* If we get this far, it means that the xfer optimization is at
101192 ** least a possibility, though it might only work if the destination
@@ -101193,28 +101561,32 @@
101193 ** table (tab1) is initially empty.
101194 */
101195 #ifdef SQLITE_TEST
101196 sqlite3_xferopt_count++;
101197 #endif
101198 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
101199 v = sqlite3GetVdbe(pParse);
101200 sqlite3CodeVerifySchema(pParse, iDbSrc);
101201 iSrc = pParse->nTab++;
101202 iDest = pParse->nTab++;
101203 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101204 regData = sqlite3GetTempReg(pParse);
101205 regRowid = sqlite3GetTempReg(pParse);
101206 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101207 assert( HasRowid(pDest) || destHasUniqueIdx );
101208 if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
 
101209 || destHasUniqueIdx /* (2) */
101210 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101211 ){
101212 /* In some circumstances, we are able to run the xfer optimization
101213 ** only if the destination table is initially empty. This code makes
101214 ** that determination. Conditions under which the destination must
101215 ** be empty:
 
 
 
101216 **
101217 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
101218 ** (If the destination is not initially empty, the rowid fields
101219 ** of index entries might need to change.)
101220 **
@@ -101253,10 +101625,11 @@
101253 }else{
101254 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101255 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101256 }
101257 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
 
101258 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101259 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101260 }
101261 assert( pSrcIdx );
101262 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101639,37 @@
101266 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101267 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101268 VdbeComment((v, "%s", pDestIdx->zName));
101269 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101270 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101271 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
 
101272 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101273 sqlite3VdbeJumpHere(v, addr1);
101274 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101275 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101276 }
@@ -102385,11 +102784,11 @@
102385 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102386 char *zErrmsg = 0;
102387 const char *zEntry;
102388 char *zAltEntry = 0;
102389 void **aHandle;
102390 int nMsg = 300 + sqlite3Strlen30(zFile);
102391 int ii;
102392
102393 /* Shared library endings to try if zFile cannot be loaded as written */
102394 static const char *azEndings[] = {
102395 #if SQLITE_OS_WIN
@@ -102428,11 +102827,11 @@
102428 sqlite3_free(zAltFile);
102429 }
102430 #endif
102431 if( handle==0 ){
102432 if( pzErrMsg ){
102433 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102434 if( zErrmsg ){
102435 sqlite3_snprintf(nMsg, zErrmsg,
102436 "unable to open shared library [%s]", zFile);
102437 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102438 }
@@ -102454,11 +102853,11 @@
102454 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102455 */
102456 if( xInit==0 && zProc==0 ){
102457 int iFile, iEntry, c;
102458 int ncFile = sqlite3Strlen30(zFile);
102459 zAltEntry = sqlite3_malloc(ncFile+30);
102460 if( zAltEntry==0 ){
102461 sqlite3OsDlClose(pVfs, handle);
102462 return SQLITE_NOMEM;
102463 }
102464 memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102875,11 @@
102476 sqlite3OsDlSym(pVfs, handle, zEntry);
102477 }
102478 if( xInit==0 ){
102479 if( pzErrMsg ){
102480 nMsg += sqlite3Strlen30(zEntry);
102481 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102482 if( zErrmsg ){
102483 sqlite3_snprintf(nMsg, zErrmsg,
102484 "no entry point [%s] in shared library [%s]", zEntry, zFile);
102485 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102486 }
@@ -102575,11 +102974,11 @@
102575 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102576 ** mutex must be held while accessing this list.
102577 */
102578 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102579 static SQLITE_WSD struct sqlite3AutoExtList {
102580 int nExt; /* Number of entries in aExt[] */
102581 void (**aExt)(void); /* Pointers to the extension init functions */
102582 } sqlite3Autoext = { 0, 0 };
102583
102584 /* The "wsdAutoext" macro will resolve to the autoextension
102585 ** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103007,23 @@
102608 if( rc ){
102609 return rc;
102610 }else
102611 #endif
102612 {
102613 int i;
102614 #if SQLITE_THREADSAFE
102615 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
102616 #endif
102617 wsdAutoextInit;
102618 sqlite3_mutex_enter(mutex);
102619 for(i=0; i<wsdAutoext.nExt; i++){
102620 if( wsdAutoext.aExt[i]==xInit ) break;
102621 }
102622 if( i==wsdAutoext.nExt ){
102623 int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
102624 void (**aNew)(void);
102625 aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
102626 if( aNew==0 ){
102627 rc = SQLITE_NOMEM;
102628 }else{
102629 wsdAutoext.aExt = aNew;
102630 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103051,11 @@
102652 #endif
102653 int i;
102654 int n = 0;
102655 wsdAutoextInit;
102656 sqlite3_mutex_enter(mutex);
102657 for(i=wsdAutoext.nExt-1; i>=0; i--){
102658 if( wsdAutoext.aExt[i]==xInit ){
102659 wsdAutoext.nExt--;
102660 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
102661 n++;
102662 break;
@@ -102690,11 +103089,11 @@
102690 ** Load all automatic extensions.
102691 **
102692 ** If anything goes wrong, set an error in the database connection.
102693 */
102694 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
102695 int i;
102696 int go = 1;
102697 int rc;
102698 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102699
102700 wsdAutoextInit;
@@ -103354,19 +103753,19 @@
103354 /*
103355 ** Generate code to return a single integer value.
103356 */
103357 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103358 Vdbe *v = sqlite3GetVdbe(pParse);
103359 int mem = ++pParse->nMem;
103360 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103361 if( pI64 ){
103362 memcpy(pI64, &value, sizeof(value));
103363 }
103364 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
103365 sqlite3VdbeSetNumCols(v, 1);
103366 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103367 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103368 }
103369
103370
103371 /*
103372 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103926,15 @@
103527 aFcntl[3] = 0;
103528 db->busyHandler.nBusy = 0;
103529 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103530 if( rc==SQLITE_OK ){
103531 if( aFcntl[0] ){
103532 int mem = ++pParse->nMem;
103533 sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
103534 sqlite3VdbeSetNumCols(v, 1);
103535 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103536 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103537 sqlite3_free(aFcntl[0]);
103538 }
103539 goto pragma_out;
103540 }
103541 if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104535,13 @@
104136 }else{
104137 if( !db->autoCommit ){
104138 sqlite3ErrorMsg(pParse,
104139 "Safety level may not be changed inside a transaction");
104140 }else{
104141 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
 
 
104142 setAllPagerFlags(db);
104143 }
104144 }
104145 break;
104146 }
@@ -104231,11 +104632,11 @@
104231 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104232 k = 0;
104233 }else if( pPk==0 ){
104234 k = 1;
104235 }else{
104236 for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
104237 }
104238 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104239 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104240 }
104241 }
@@ -105237,11 +105638,11 @@
105237
105238 assert( iDb>=0 && iDb<db->nDb );
105239 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105240 if( argv[1]==0 ){
105241 corruptSchema(pData, argv[0], 0);
105242 }else if( argv[2] && argv[2][0] ){
105243 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105244 ** But because db->init.busy is set to 1, no VDBE code is generated
105245 ** or executed. All the parser does is build the internal data
105246 ** structures that describe the table, index, or view.
105247 */
@@ -105268,12 +105669,12 @@
105268 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105269 }
105270 }
105271 }
105272 sqlite3_finalize(pStmt);
105273 }else if( argv[0]==0 ){
105274 corruptSchema(pData, 0, 0);
105275 }else{
105276 /* If the SQL column is blank it means this is an index that
105277 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105278 ** constraint for a CREATE TABLE. The index should have already
105279 ** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106577,10 @@
106176 ){
106177 Select *pNew;
106178 Select standin;
106179 sqlite3 *db = pParse->db;
106180 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
106181 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
106182 if( pNew==0 ){
106183 assert( db->mallocFailed );
106184 pNew = &standin;
106185 memset(pNew, 0, sizeof(*pNew));
106186 }
@@ -106196,11 +106596,11 @@
106196 pNew->pOrderBy = pOrderBy;
106197 pNew->selFlags = selFlags;
106198 pNew->op = TK_SELECT;
106199 pNew->pLimit = pLimit;
106200 pNew->pOffset = pOffset;
106201 assert( pOffset==0 || pLimit!=0 );
106202 pNew->addrOpenEphm[0] = -1;
106203 pNew->addrOpenEphm[1] = -1;
106204 if( db->mallocFailed ) {
106205 clearSelect(db, pNew, pNew!=&standin);
106206 pNew = 0;
@@ -107446,11 +107846,11 @@
107446 if( pS ){
107447 /* The "table" is actually a sub-select or a view in the FROM clause
107448 ** of the SELECT statement. Return the declaration type and origin
107449 ** data for the result-set column of the sub-select.
107450 */
107451 if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
107452 /* If iCol is less than zero, then the expression requests the
107453 ** rowid of the sub-select or view. This expression is legal (see
107454 ** test case misc2.2.2) - it always evaluates to NULL.
107455 */
107456 NameContext sNC;
@@ -107766,16 +108166,18 @@
107766 memset(&sNC, 0, sizeof(sNC));
107767 sNC.pSrcList = pSelect->pSrc;
107768 a = pSelect->pEList->a;
107769 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
107770 p = a[i].pExpr;
107771 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
 
 
107772 szAll += pCol->szEst;
107773 pCol->affinity = sqlite3ExprAffinity(p);
107774 if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
107775 pColl = sqlite3ExprCollSeq(pParse, p);
107776 if( pColl ){
107777 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
107778 }
107779 }
107780 pTab->szTabRow = sqlite3LogEst(szAll*4);
107781 }
@@ -108173,12 +108575,11 @@
108173 ){
108174 Select *pPrior;
108175 int nExpr = p->pEList->nExpr;
108176 int nRow = 1;
108177 int rc = 0;
108178 assert( p->pNext==0 );
108179 assert( p->selFlags & SF_AllValues );
108180 do{
108181 assert( p->selFlags & SF_Values );
108182 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108183 assert( p->pLimit==0 );
108184 assert( p->pOffset==0 );
@@ -108283,11 +108684,11 @@
108283 dest.eDest = SRT_Table;
108284 }
108285
108286 /* Special handling for a compound-select that originates as a VALUES clause.
108287 */
108288 if( p->selFlags & SF_AllValues ){
108289 rc = multiSelectValues(pParse, p, &dest);
108290 goto multi_select_end;
108291 }
108292
108293 /* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109069,11 @@
108668 ** then there should be a single item on the stack. Write this
108669 ** item into the set table with bogus data.
108670 */
108671 case SRT_Set: {
108672 int r1;
108673 assert( pIn->nSdst==1 );
108674 pDest->affSdst =
108675 sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
108676 r1 = sqlite3GetTempReg(pParse);
108677 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
108678 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109095,11 @@
108694 /* If this is a scalar select that is part of an expression, then
108695 ** store the results in the appropriate memory cell and break out
108696 ** of the scan loop.
108697 */
108698 case SRT_Mem: {
108699 assert( pIn->nSdst==1 );
108700 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
108701 /* The LIMIT clause will jump out of the loop for us */
108702 break;
108703 }
108704 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109110,11 @@
108709 case SRT_Coroutine: {
108710 if( pDest->iSdst==0 ){
108711 pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
108712 pDest->nSdst = pIn->nSdst;
108713 }
108714 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
108715 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108716 break;
108717 }
108718
108719 /* If none of the above, then the result destination must be
@@ -108925,12 +109326,14 @@
108925 */
108926 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
108927 if( aPermute ){
108928 struct ExprList_item *pItem;
108929 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
108930 assert( pItem->u.x.iOrderByCol>0
108931 && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
 
 
108932 aPermute[i] = pItem->u.x.iOrderByCol - 1;
108933 }
108934 pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
108935 }else{
108936 pKeyMerge = 0;
@@ -109136,11 +109539,11 @@
109136 pPrior->pNext = p;
109137
109138 /*** TBD: Insert subroutine calls to close cursors on incomplete
109139 **** subqueries ****/
109140 explainComposite(pParse, p->op, iSub1, iSub2, 0);
109141 return SQLITE_OK;
109142 }
109143 #endif
109144
109145 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109146 /* Forward Declarations */
@@ -109948,10 +110351,11 @@
109948 pNew->pGroupBy = 0;
109949 pNew->pHaving = 0;
109950 pNew->pOrderBy = 0;
109951 p->pPrior = 0;
109952 p->pNext = 0;
 
109953 p->selFlags &= ~SF_Compound;
109954 assert( (p->selFlags & SF_Converted)==0 );
109955 p->selFlags |= SF_Converted;
109956 assert( pNew->pPrior!=0 );
109957 pNew->pPrior->pNext = pNew;
@@ -110486,11 +110890,11 @@
110486 if( pParse->hasCompound ){
110487 w.xSelectCallback = convertCompoundSelectToSubquery;
110488 sqlite3WalkSelect(&w, pSelect);
110489 }
110490 w.xSelectCallback = selectExpander;
110491 if( (pSelect->selFlags & SF_AllValues)==0 ){
110492 w.xSelectCallback2 = selectPopWith;
110493 }
110494 sqlite3WalkSelect(&w, pSelect);
110495 }
110496
@@ -110672,11 +111076,12 @@
110672 nArg = 0;
110673 regAgg = 0;
110674 }
110675 if( pF->iDistinct>=0 ){
110676 addrNext = sqlite3VdbeMakeLabel(v);
110677 assert( nArg==1 );
 
110678 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
110679 }
110680 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
110681 CollSeq *pColl = 0;
110682 struct ExprList_item *pItem;
@@ -111547,14 +111952,13 @@
111547
111548 /* Jump here to skip this query
111549 */
111550 sqlite3VdbeResolveLabel(v, iEnd);
111551
111552 /* The SELECT was successfully coded. Set the return code to 0
111553 ** to indicate no errors.
111554 */
111555 rc = 0;
111556
111557 /* Control jumps to here if an error is encountered above, or upon
111558 ** successful coding of the SELECT.
111559 */
111560 select_end:
@@ -111601,11 +112005,11 @@
111601 sqlite3TreeViewLine(pView, "FROM");
111602 for(i=0; i<p->pSrc->nSrc; i++){
111603 struct SrcList_item *pItem = &p->pSrc->a[i];
111604 StrAccum x;
111605 char zLine[100];
111606 sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
111607 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
111608 if( pItem->zDatabase ){
111609 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
111610 }else if( pItem->zName ){
111611 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112164,11 @@
111760 for(i=0; i<nCol; i++){
111761 if( argv[i]==0 ){
111762 z = 0;
111763 }else{
111764 int n = sqlite3Strlen30(argv[i])+1;
111765 z = sqlite3_malloc( n );
111766 if( z==0 ) goto malloc_failed;
111767 memcpy(z, argv[i], n);
111768 }
111769 p->azResult[p->nData++] = z;
111770 }
@@ -111809,11 +112213,11 @@
111809 res.nRow = 0;
111810 res.nColumn = 0;
111811 res.nData = 1;
111812 res.nAlloc = 20;
111813 res.rc = SQLITE_OK;
111814 res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc );
111815 if( res.azResult==0 ){
111816 db->errCode = SQLITE_NOMEM;
111817 return SQLITE_NOMEM;
111818 }
111819 res.azResult[0] = 0;
@@ -111837,11 +112241,11 @@
111837 sqlite3_free_table(&res.azResult[1]);
111838 return rc;
111839 }
111840 if( res.nAlloc>res.nData ){
111841 char **azNew;
111842 azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData );
111843 if( azNew==0 ){
111844 sqlite3_free_table(&res.azResult[1]);
111845 db->errCode = SQLITE_NOMEM;
111846 return SQLITE_NOMEM;
111847 }
@@ -112065,11 +112469,10 @@
112065 }
112066
112067 /* Do not create a trigger on a system table */
112068 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112069 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
112070 pParse->nErr++;
112071 goto trigger_cleanup;
112072 }
112073
112074 /* INSTEAD of triggers are only for views and views only support INSTEAD
112075 ** of triggers.
@@ -112245,16 +112648,16 @@
112245 u8 op, /* Trigger opcode */
112246 Token *pName /* The target name */
112247 ){
112248 TriggerStep *pTriggerStep;
112249
112250 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
112251 if( pTriggerStep ){
112252 char *z = (char*)&pTriggerStep[1];
112253 memcpy(z, pName->z, pName->n);
112254 pTriggerStep->target.z = z;
112255 pTriggerStep->target.n = pName->n;
112256 pTriggerStep->op = op;
112257 }
112258 return pTriggerStep;
112259 }
112260
@@ -112533,11 +112936,11 @@
112533 }
112534 return (mask ? pList : 0);
112535 }
112536
112537 /*
112538 ** Convert the pStep->target token into a SrcList and return a pointer
112539 ** to that SrcList.
112540 **
112541 ** This routine adds a specific database name, if needed, to the target when
112542 ** forming the SrcList. This prevents a trigger in one database from
112543 ** referring to a target in another database. An exception is when the
@@ -112546,21 +112949,21 @@
112546 */
112547 static SrcList *targetSrcList(
112548 Parse *pParse, /* The parsing context */
112549 TriggerStep *pStep /* The trigger containing the target token */
112550 ){
 
112551 int iDb; /* Index of the database to use */
112552 SrcList *pSrc; /* SrcList to be returned */
112553
112554 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
112555 if( pSrc ){
112556 assert( pSrc->nSrc>0 );
112557 assert( pSrc->a!=0 );
112558 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
112559 if( iDb==0 || iDb>=2 ){
112560 sqlite3 *db = pParse->db;
112561 assert( iDb<pParse->db->nDb );
112562 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112563 }
112564 }
112565 return pSrc;
112566 }
@@ -112668,10 +113071,11 @@
112668 assert( pFrom->zErrMsg==0 || pFrom->nErr );
112669 assert( pTo->zErrMsg==0 || pTo->nErr );
112670 if( pTo->nErr==0 ){
112671 pTo->zErrMsg = pFrom->zErrMsg;
112672 pTo->nErr = pFrom->nErr;
 
112673 }else{
112674 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
112675 }
112676 }
112677
@@ -114018,17 +114422,21 @@
114018
114019 /* Loop through the tables in the main database. For each, do
114020 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114021 ** the contents to the temporary database.
114022 */
 
 
114023 rc = execExecSql(db, pzErrMsg,
114024 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114025 "|| ' SELECT * FROM main.' || quote(name) || ';'"
114026 "FROM main.sqlite_master "
114027 "WHERE type = 'table' AND name!='sqlite_sequence' "
114028 " AND coalesce(rootpage,1)>0"
114029 );
 
 
114030 if( rc!=SQLITE_OK ) goto end_of_vacuum;
114031
114032 /* Copy over the sequence table
114033 */
114034 rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114571,12 @@
114163 ** are invoked only from within xCreate and xConnect methods.
114164 */
114165 struct VtabCtx {
114166 VTable *pVTable; /* The virtual table being constructed */
114167 Table *pTab; /* The Table object to which the virtual table belongs */
 
 
114168 };
114169
114170 /*
114171 ** The actual function that does the work of creating a new module.
114172 ** This function implements the sqlite3_create_module() and
@@ -114609,11 +115019,11 @@
114609 Token *pArg = &pParse->sArg;
114610 if( pArg->z==0 ){
114611 pArg->z = p->z;
114612 pArg->n = p->n;
114613 }else{
114614 assert(pArg->z < p->z);
114615 pArg->n = (int)(&p->z[p->n] - pArg->z);
114616 }
114617 }
114618
114619 /*
@@ -114626,19 +115036,31 @@
114626 Table *pTab,
114627 Module *pMod,
114628 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
114629 char **pzErr
114630 ){
114631 VtabCtx sCtx, *pPriorCtx;
114632 VTable *pVTable;
114633 int rc;
114634 const char *const*azArg = (const char *const*)pTab->azModuleArg;
114635 int nArg = pTab->nModuleArg;
114636 char *zErr = 0;
114637 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
114638 int iDb;
 
114639
 
 
 
 
 
 
 
 
 
 
 
114640 if( !zModuleName ){
114641 return SQLITE_NOMEM;
114642 }
114643
114644 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115077,17 @@
114655 /* Invoke the virtual table constructor */
114656 assert( &db->pVtabCtx );
114657 assert( xConstruct );
114658 sCtx.pTab = pTab;
114659 sCtx.pVTable = pVTable;
114660 pPriorCtx = db->pVtabCtx;
 
114661 db->pVtabCtx = &sCtx;
114662 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
114663 db->pVtabCtx = pPriorCtx;
114664 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
 
114665
114666 if( SQLITE_OK!=rc ){
114667 if( zErr==0 ){
114668 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
114669 }else {
@@ -114675,17 +115099,18 @@
114675 /* Justification of ALWAYS(): A correct vtab constructor must allocate
114676 ** the sqlite3_vtab object if successful. */
114677 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
114678 pVTable->pVtab->pModule = pMod->pModule;
114679 pVTable->nRef = 1;
114680 if( sCtx.pTab ){
114681 const char *zFormat = "vtable constructor did not declare schema: %s";
114682 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
114683 sqlite3VtabUnlock(pVTable);
114684 rc = SQLITE_ERROR;
114685 }else{
114686 int iCol;
 
114687 /* If everything went according to plan, link the new VTable structure
114688 ** into the linked list headed by pTab->pVTable. Then loop through the
114689 ** columns of the table to see if any of them contain the token "hidden".
114690 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
114691 ** the type string. */
@@ -114694,11 +115119,14 @@
114694
114695 for(iCol=0; iCol<pTab->nCol; iCol++){
114696 char *zType = pTab->aCol[iCol].zType;
114697 int nType;
114698 int i = 0;
114699 if( !zType ) continue;
 
 
 
114700 nType = sqlite3Strlen30(zType);
114701 if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
114702 for(i=0; i<nType; i++){
114703 if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
114704 && (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115145,13 @@
114717 if( zType[i]=='\0' && i>0 ){
114718 assert(zType[i-1]==' ');
114719 zType[i-1] = '\0';
114720 }
114721 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
 
 
 
114722 }
114723 }
114724 }
114725 }
114726
@@ -114845,12 +115276,12 @@
114845 ** This function is used to set the schema of a virtual table. It is only
114846 ** valid to call this function from within the xCreate() or xConnect() of a
114847 ** virtual table module.
114848 */
114849 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
 
114850 Parse *pParse;
114851
114852 int rc = SQLITE_OK;
114853 Table *pTab;
114854 char *zErr = 0;
114855
114856 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115288,17 @@
114857 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114858 return SQLITE_MISUSE_BKPT;
114859 }
114860 #endif
114861 sqlite3_mutex_enter(db->mutex);
114862 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
 
114863 sqlite3Error(db, SQLITE_MISUSE);
114864 sqlite3_mutex_leave(db->mutex);
114865 return SQLITE_MISUSE_BKPT;
114866 }
 
114867 assert( (pTab->tabFlags & TF_Virtual)!=0 );
114868
114869 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
114870 if( pParse==0 ){
114871 rc = SQLITE_NOMEM;
@@ -114884,11 +115317,11 @@
114884 pTab->aCol = pParse->pNewTable->aCol;
114885 pTab->nCol = pParse->pNewTable->nCol;
114886 pParse->pNewTable->nCol = 0;
114887 pParse->pNewTable->aCol = 0;
114888 }
114889 db->pVtabCtx->pTab = 0;
114890 }else{
114891 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
114892 sqlite3DbFree(db, zErr);
114893 rc = SQLITE_ERROR;
114894 }
@@ -115078,11 +115511,11 @@
115078 */
115079 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115080 int rc = SQLITE_OK;
115081
115082 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115083 assert( iSavepoint>=0 );
115084 if( db->aVTrans ){
115085 int i;
115086 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115087 VTable *pVTab = db->aVTrans[i];
115088 const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115629,11 @@
115196 assert( IsVirtual(pTab) );
115197 for(i=0; i<pToplevel->nVtabLock; i++){
115198 if( pTab==pToplevel->apVtabLock[i] ) return;
115199 }
115200 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115201 apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n);
115202 if( apVtabLock ){
115203 pToplevel->apVtabLock = apVtabLock;
115204 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115205 }else{
115206 pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116428,18 @@
115995 ** In the previous sentence and in the diagram, "slot[]" refers to
115996 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
115997 ** all terms of the WHERE clause.
115998 */
115999 static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
 
116000 pWC->op = op;
116001 if( pExpr==0 ) return;
116002 if( pExpr->op!=op ){
116003 whereClauseInsert(pWC, pExpr, 0);
116004 }else{
116005 whereSplit(pWC, pExpr->pLeft, op);
116006 whereSplit(pWC, pExpr->pRight, op);
116007 }
116008 }
116009
116010 /*
116011 ** Initialize a WhereMaskSet object
@@ -117272,11 +117706,11 @@
117272 if( p->op==TK_COLUMN
117273 && p->iColumn==pIdx->aiColumn[iCol]
117274 && p->iTable==iBase
117275 ){
117276 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117277 if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117278 return i;
117279 }
117280 }
117281 }
117282
@@ -117546,11 +117980,11 @@
117546 if( (idxCols & cMask)==0 ){
117547 Expr *pX = pTerm->pExpr;
117548 idxCols |= cMask;
117549 pIdx->aiColumn[n] = pTerm->u.leftColumn;
117550 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117551 pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY";
117552 n++;
117553 }
117554 }
117555 }
117556 assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119276,11 @@
118842
118843 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
118844 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
118845 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
118846
118847 sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118848 str.db = db;
118849 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
118850 if( pItem->pSelect ){
118851 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
118852 }else{
118853 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120475,17 @@
120042 /*
120043 ** Free a WhereInfo structure
120044 */
120045 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120046 if( ALWAYS(pWInfo) ){
 
 
 
 
 
 
 
120047 whereClauseClear(&pWInfo->sWC);
120048 while( pWInfo->pLoops ){
120049 WhereLoop *p = pWInfo->pLoops;
120050 pWInfo->pLoops = p->pNextLoop;
120051 whereLoopDelete(db, p);
@@ -120521,11 +120961,11 @@
120521 ** changes "x IN (?)" into "x=?". */
120522
120523 }else if( eOp & (WO_EQ) ){
120524 pNew->wsFlags |= WHERE_COLUMN_EQ;
120525 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120526 if( iCol>=0 && !IsUniqueIndex(pProbe) ){
120527 pNew->wsFlags |= WHERE_UNQ_WANTED;
120528 }else{
120529 pNew->wsFlags |= WHERE_ONEROW;
120530 }
120531 }
@@ -121981,11 +122421,11 @@
121981 pWInfo->nOBSat = pFrom->isOrdered;
121982 if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
121983 pWInfo->revMask = pFrom->revLoop;
121984 }
121985 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
121986 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
121987 ){
121988 Bitmask revMask = 0;
121989 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
121990 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
121991 );
@@ -122386,11 +122826,10 @@
122386 if( pParse->nErr || NEVER(db->mallocFailed) ){
122387 goto whereBeginError;
122388 }
122389 #ifdef WHERETRACE_ENABLED /* !=0 */
122390 if( sqlite3WhereTrace ){
122391 int ii;
122392 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122393 if( pWInfo->nOBSat>0 ){
122394 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122395 }
122396 switch( pWInfo->eDistinct ){
@@ -122639,11 +123078,10 @@
122639 VdbeCoverage(v);
122640 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
122641 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
122642 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
122643 }
122644 sqlite3DbFree(db, pLevel->u.in.aInLoop);
122645 }
122646 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
122647 if( pLevel->addrSkip ){
122648 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
122649 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123288,32 @@
122850 /*
122851 ** An instance of this structure holds the ATTACH key and the key type.
122852 */
122853 struct AttachKey { int type; Token key; };
122854
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122855
122856 /* This is a utility routine used to set the ExprSpan.zStart and
122857 ** ExprSpan.zEnd values of pOut so that the span covers the complete
122858 ** range of text beginning with pStart and going to the end of pEnd.
122859 */
@@ -125167,31 +125627,14 @@
125167 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125168 }
125169 break;
125170 case 112: /* select ::= with selectnowith */
125171 {
125172 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
125173 if( p ){
125174 int cnt = 0, mxSelect;
125175 p->pWith = yymsp[-1].minor.yy59;
125176 if( p->pPrior ){
125177 u16 allValues = SF_Values;
125178 pNext = 0;
125179 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
125180 pLoop->pNext = pNext;
125181 pLoop->selFlags |= SF_Compound;
125182 allValues &= pLoop->selFlags;
125183 }
125184 if( allValues ){
125185 p->selFlags |= SF_AllValues;
125186 }else if(
125187 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
125188 && cnt>mxSelect
125189 ){
125190 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
125191 }
125192 }
125193 }else{
125194 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125195 }
125196 yygotominor.yy3 = p;
125197 }
@@ -125205,16 +125648,18 @@
125205 Select *pRhs = yymsp[0].minor.yy3;
125206 if( pRhs && pRhs->pPrior ){
125207 SrcList *pFrom;
125208 Token x;
125209 x.n = 0;
 
125210 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125211 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125212 }
125213 if( pRhs ){
125214 pRhs->op = (u8)yymsp[-1].minor.yy328;
125215 pRhs->pPrior = yymsp[-2].minor.yy3;
 
125216 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125217 }else{
125218 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125219 }
125220 yygotominor.yy3 = pRhs;
@@ -125257,17 +125702,20 @@
125257 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125258 }
125259 break;
125260 case 121: /* values ::= values COMMA LP exprlist RP */
125261 {
125262 Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
 
 
125263 if( pRight ){
125264 pRight->op = TK_ALL;
125265 pRight->pPrior = yymsp[-4].minor.yy3;
 
125266 yygotominor.yy3 = pRight;
125267 }else{
125268 yygotominor.yy3 = yymsp[-4].minor.yy3;
125269 }
125270 }
125271 break;
125272 case 122: /* distinct ::= DISTINCT */
125273 {yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127515,12 @@
127067 goto abort_parse;
127068 }
127069 break;
127070 }
127071 case TK_ILLEGAL: {
127072 sqlite3DbFree(db, *pzErrMsg);
127073 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
127074 &pParse->sLastToken);
127075 nErr++;
127076 goto abort_parse;
127077 }
127078 case TK_SEMI: {
127079 pParse->zTail = &zSql[i];
127080 /* Fall thru into the default case */
@@ -127088,16 +127534,19 @@
127088 break;
127089 }
127090 }
127091 }
127092 abort_parse:
127093 if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
 
127094 if( lastTokenParsed!=TK_SEMI ){
127095 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127096 pParse->zTail = &zSql[i];
127097 }
127098 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
 
 
127099 }
127100 #ifdef YYTRACKMAXSTACKDEPTH
127101 sqlite3_mutex_enter(sqlite3MallocMutex());
127102 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127103 sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127603,11 @@
127154 while( pParse->pZombieTab ){
127155 Table *p = pParse->pZombieTab;
127156 pParse->pZombieTab = p->pNextZombie;
127157 sqlite3DeleteTable(db, p);
127158 }
127159 if( nErr>0 && pParse->rc==SQLITE_OK ){
127160 pParse->rc = SQLITE_ERROR;
127161 }
127162 return nErr;
127163 }
127164
127165 /************** End of tokenize.c ********************************************/
127166 /************** Begin file complete.c ****************************************/
@@ -127432,11 +127879,11 @@
127432 ** UTF-8.
127433 */
127434 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127435 sqlite3_value *pVal;
127436 char const *zSql8;
127437 int rc = SQLITE_NOMEM;
127438
127439 #ifndef SQLITE_OMIT_AUTOINIT
127440 rc = sqlite3_initialize();
127441 if( rc ) return rc;
127442 #endif
@@ -127598,10 +128045,22 @@
127598 ** zero if and only if SQLite was compiled with mutexing code omitted due to
127599 ** the SQLITE_THREADSAFE compile-time option being set to 0.
127600 */
127601 SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
127602
 
 
 
 
 
 
 
 
 
 
 
 
127603 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
127604 /*
127605 ** If the following function pointer is not NULL and if
127606 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
127607 ** I/O active are written using this function. These messages
@@ -128737,11 +129196,11 @@
128737
128738 /*
128739 ** Return a static string containing the name corresponding to the error code
128740 ** specified in the argument.
128741 */
128742 #if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST)
128743 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
128744 const char *zName = 0;
128745 int i, origRc = rc;
128746 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
128747 switch( rc ){
@@ -129962,18 +130421,18 @@
129962 ){
129963 char *zOpt;
129964 int eState; /* Parser state when parsing URI */
129965 int iIn; /* Input character index */
129966 int iOut = 0; /* Output character index */
129967 int nByte = nUri+2; /* Bytes of space to allocate */
129968
129969 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
129970 ** method that there may be extra parameters following the file-name. */
129971 flags |= SQLITE_OPEN_URI;
129972
129973 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129974 zFile = sqlite3_malloc(nByte);
129975 if( !zFile ) return SQLITE_NOMEM;
129976
129977 iIn = 5;
129978 #ifdef SQLITE_ALLOW_URI_AUTHORITY
129979 if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130594,11 @@
130135
130136 zOpt = &zVal[nVal+1];
130137 }
130138
130139 }else{
130140 zFile = sqlite3_malloc(nUri+2);
130141 if( !zFile ) return SQLITE_NOMEM;
130142 memcpy(zFile, zUri, nUri);
130143 zFile[nUri] = '\0';
130144 zFile[nUri+1] = '\0';
130145 flags &= ~SQLITE_OPEN_URI;
@@ -132344,10 +132803,15 @@
132344 ** false.
132345 */
132346 #ifdef SQLITE_COVERAGE_TEST
132347 # define ALWAYS(x) (1)
132348 # define NEVER(X) (0)
 
 
 
 
 
132349 #else
132350 # define ALWAYS(x) (x)
132351 # define NEVER(x) (x)
132352 #endif
132353
@@ -132744,10 +133208,11 @@
132744 #define fts3GetVarint32(p, piVal) ( \
132745 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
132746 )
132747
132748 /* fts3.c */
 
132749 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
132750 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
132751 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
132752 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
132753 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133297,17 @@
132832
132833 static int fts3EvalNext(Fts3Cursor *pCsr);
132834 static int fts3EvalStart(Fts3Cursor *pCsr);
132835 static int fts3TermSegReaderCursor(
132836 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
 
 
 
 
 
 
 
132837
132838 /*
132839 ** Write a 64-bit variable-length integer to memory starting at p[0].
132840 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
132841 ** The number of bytes written is returned.
@@ -132942,11 +133414,11 @@
132942 int iOut = 0; /* Index of next byte to write to output */
132943
132944 /* If the first byte was a '[', then the close-quote character is a ']' */
132945 if( quote=='[' ) quote = ']';
132946
132947 while( ALWAYS(z[iIn]) ){
132948 if( z[iIn]==quote ){
132949 if( z[iIn+1]!=quote ) break;
132950 z[iOut++] = quote;
132951 iIn += 2;
132952 }else{
@@ -133020,10 +133492,21 @@
133020 p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133021
133022 sqlite3_free(p);
133023 return SQLITE_OK;
133024 }
 
 
 
 
 
 
 
 
 
 
 
133025
133026 /*
133027 ** Construct one or more SQL statements from the format string given
133028 ** and then evaluate those statements. The success code is written
133029 ** into *pRc.
@@ -133539,11 +134022,12 @@
133539 sqlite3 *db, /* Database handle */
133540 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
133541 const char *zTbl, /* Name of content table */
133542 const char ***pazCol, /* OUT: Malloc'd array of column names */
133543 int *pnCol, /* OUT: Size of array *pazCol */
133544 int *pnStr /* OUT: Bytes of string content */
 
133545 ){
133546 int rc = SQLITE_OK; /* Return code */
133547 char *zSql; /* "SELECT *" statement on zTbl */
133548 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
133549
@@ -133550,10 +134034,13 @@
133550 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
133551 if( !zSql ){
133552 rc = SQLITE_NOMEM;
133553 }else{
133554 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
 
 
 
133555 }
133556 sqlite3_free(zSql);
133557
133558 if( rc==SQLITE_OK ){
133559 const char **azCol; /* Output array */
@@ -133716,17 +134203,17 @@
133716 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
133717 break;
133718 }
133719 }
133720 if( iOpt==SizeofArray(aFts4Opt) ){
133721 *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z);
133722 rc = SQLITE_ERROR;
133723 }else{
133724 switch( iOpt ){
133725 case 0: /* MATCHINFO */
133726 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
133727 *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal);
133728 rc = SQLITE_ERROR;
133729 }
133730 bNoDocsize = 1;
133731 break;
133732
@@ -133750,11 +134237,11 @@
133750
133751 case 4: /* ORDER */
133752 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
133753 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
133754 ){
133755 *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
133756 rc = SQLITE_ERROR;
133757 }
133758 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
133759 break;
133760
@@ -133801,11 +134288,11 @@
133801 zCompress = 0;
133802 zUncompress = 0;
133803 if( nCol==0 ){
133804 sqlite3_free((void*)aCol);
133805 aCol = 0;
133806 rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
133807
133808 /* If a languageid= option was specified, remove the language id
133809 ** column from the aCol[] array. */
133810 if( rc==SQLITE_OK && zLanguageid ){
133811 int j;
@@ -133836,11 +134323,11 @@
133836 assert( pTokenizer );
133837
133838 rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
133839 if( rc==SQLITE_ERROR ){
133840 assert( zPrefix );
133841 *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix);
133842 }
133843 if( rc!=SQLITE_OK ) goto fts3_init_out;
133844
133845 /* Allocate and populate the Fts3Table structure. */
133846 nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134405,19 @@
133918 }
133919 }
133920 }
133921 for(i=0; i<nNotindexed; i++){
133922 if( azNotindexed[i] ){
133923 *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
133924 rc = SQLITE_ERROR;
133925 }
133926 }
133927
133928 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
133929 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
133930 rc = SQLITE_ERROR;
133931 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
133932 }
133933 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
133934 p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
133935 if( rc!=SQLITE_OK ) goto fts3_init_out;
133936
@@ -135319,11 +135806,11 @@
135319 ** Fts3SegReaderPending might segfault, as the data structures used by
135320 ** fts4aux are not completely populated. So it's easiest to filter these
135321 ** calls out here. */
135322 if( iLevel<0 && p->aIndex ){
135323 Fts3SegReader *pSeg = 0;
135324 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg);
135325 if( rc==SQLITE_OK && pSeg ){
135326 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135327 }
135328 }
135329
@@ -135968,15 +136455,35 @@
135968 */
135969 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
135970 char *p = &(*ppPoslist)[-2];
135971 char c = 0;
135972
 
135973 while( p>pStart && (c=*p--)==0 );
 
 
 
 
135974 while( p>pStart && (*p & 0x80) | c ){
135975 c = *p--;
135976 }
135977 if( p>pStart ){ p = &p[2]; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135978 while( *p++&0x80 );
135979 *ppPoslist = p;
135980 }
135981
135982 /*
@@ -136043,10 +136550,12 @@
136043 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136044 case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136045 }
136046 if( !zEllipsis || !zEnd || !zStart ){
136047 sqlite3_result_error_nomem(pContext);
 
 
136048 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136049 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136050 }
136051 }
136052
@@ -137104,16 +137613,18 @@
137104 Fts3Expr *pExpr, /* Expression to initialize phrases in */
137105 int *pRc /* IN/OUT: Error code */
137106 ){
137107 if( pExpr && SQLITE_OK==*pRc ){
137108 if( pExpr->eType==FTSQUERY_PHRASE ){
137109 int i;
137110 int nToken = pExpr->pPhrase->nToken;
137111 for(i=0; i<nToken; i++){
137112 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
 
 
 
 
137113 }
137114 pExpr->bDeferred = (i==nToken);
137115 *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137116 }else{
137117 fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137118 fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137119 pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138783,12 @@
138272 if( rc!=SQLITE_OK ) return rc;
138273
138274 pIter = pPhrase->pOrPoslist;
138275 iDocid = pPhrase->iOrDocid;
138276 if( pCsr->bDesc==bDescDoclist ){
138277 bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
 
138278 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138279 sqlite3Fts3DoclistNext(
138280 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138281 &pIter, &iDocid, &bEof
138282 );
@@ -138484,11 +138996,11 @@
138484
138485 *ppVtab = (sqlite3_vtab *)p;
138486 return SQLITE_OK;
138487
138488 bad_args:
138489 *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor");
138490 return SQLITE_ERROR;
138491 }
138492
138493 /*
138494 ** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140454,17 @@
139942
139943 if( rc!=SQLITE_OK ){
139944 sqlite3Fts3ExprFree(*ppExpr);
139945 *ppExpr = 0;
139946 if( rc==SQLITE_TOOBIG ){
139947 *pzErr = sqlite3_mprintf(
139948 "FTS expression tree is too large (maximum depth %d)",
139949 SQLITE_FTS3_MAX_EXPR_DEPTH
139950 );
139951 rc = SQLITE_ERROR;
139952 }else if( rc==SQLITE_ERROR ){
139953 *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
139954 }
139955 }
139956
139957 return rc;
139958 }
@@ -141424,11 +141936,11 @@
141424 z[n] = '\0';
141425 sqlite3Fts3Dequote(z);
141426
141427 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141428 if( !m ){
141429 *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z);
141430 rc = SQLITE_ERROR;
141431 }else{
141432 char const **aArg = 0;
141433 int iArg = 0;
141434 z = &z[n+1];
@@ -141447,11 +141959,11 @@
141447 z = &z[n+1];
141448 }
141449 rc = m->xCreate(iArg, aArg, ppTok);
141450 assert( rc!=SQLITE_OK || *ppTok );
141451 if( rc!=SQLITE_OK ){
141452 *pzErr = sqlite3_mprintf("unknown tokenizer");
141453 }else{
141454 (*ppTok)->pModule = m;
141455 }
141456 sqlite3_free((void *)aArg);
141457 }
@@ -141531,13 +142043,13 @@
141531
141532 pHash = (Fts3Hash *)sqlite3_user_data(context);
141533 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
141534
141535 if( !p ){
141536 char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
141537 sqlite3_result_error(context, zErr, -1);
141538 sqlite3_free(zErr);
141539 return;
141540 }
141541
141542 pRet = Tcl_NewObj();
141543 Tcl_IncrRefCount(pRet);
@@ -142068,11 +142580,11 @@
142068 sqlite3_tokenizer_module *p;
142069 int nName = (int)strlen(zName);
142070
142071 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142072 if( !p ){
142073 *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
142074 return SQLITE_ERROR;
142075 }
142076
142077 *pp = p;
142078 return SQLITE_OK;
@@ -142765,11 +143277,11 @@
142765 /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
142766 /* 24 */ "",
142767 /* 25 */ "",
142768
142769 /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
142770 /* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'",
142771
142772 /* This statement is used to determine which level to read the input from
142773 ** when performing an incremental merge. It returns the absolute level number
142774 ** of the oldest level in the db that contains at least ? segments. Or,
142775 ** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146395,12 @@
145883 sqlite3_stmt *pAllLangid = 0;
145884
145885 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
145886 if( rc==SQLITE_OK ){
145887 int rc2;
145888 sqlite3_bind_int(pAllLangid, 1, p->nIndex);
 
145889 while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
145890 int i;
145891 int iLangid = sqlite3_column_int(pAllLangid, 0);
145892 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
145893 rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147728,11 @@
147215 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147216
147217 pHint->n = i;
147218 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147219 i += fts3GetVarint32(&pHint->a[i], pnInput);
147220 if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
147221
147222 return SQLITE_OK;
147223 }
147224
147225
@@ -147583,11 +148096,12 @@
147583
147584 /* This block calculates the checksum according to the FTS index. */
147585 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147586 if( rc==SQLITE_OK ){
147587 int rc2;
147588 sqlite3_bind_int(pAllLangid, 1, p->nIndex);
 
147589 while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
147590 int iLangid = sqlite3_column_int(pAllLangid, 0);
147591 int i;
147592 for(i=0; i<p->nIndex; i++){
147593 cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148110,10 @@
147596 rc2 = sqlite3_reset(pAllLangid);
147597 if( rc==SQLITE_OK ) rc = rc2;
147598 }
147599
147600 /* This block calculates the checksum according to the %_content table */
147601 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147602 if( rc==SQLITE_OK ){
147603 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
147604 sqlite3_stmt *pStmt = 0;
147605 char *zSql;
147606
@@ -147693,11 +148206,11 @@
147693 Fts3Table *p /* FTS3 table handle */
147694 ){
147695 int rc;
147696 int bOk = 0;
147697 rc = fts3IntegrityCheck(p, &bOk);
147698 if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB;
147699 return rc;
147700 }
147701
147702 /*
147703 ** Handle a 'special' INSERT of the form:
@@ -148131,10 +148644,11 @@
148131 #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148132 #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148133 #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148134 #define FTS3_MATCHINFO_LCS 's' /* nCol values */
148135 #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
 
148136
148137 /*
148138 ** The default value for the second argument to matchinfo().
148139 */
148140 #define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149426,55 @@
148912 }
148913 }
148914
148915 return rc;
148916 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148917
148918 static int fts3MatchinfoCheck(
148919 Fts3Table *pTab,
148920 char cArg,
148921 char **pzErr
@@ -148925,14 +149484,15 @@
148925 || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
148926 || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
148927 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
148928 || (cArg==FTS3_MATCHINFO_LCS)
148929 || (cArg==FTS3_MATCHINFO_HITS)
 
148930 ){
148931 return SQLITE_OK;
148932 }
148933 *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);
148934 return SQLITE_ERROR;
148935 }
148936
148937 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
148938 int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149507,14 @@
148947 case FTS3_MATCHINFO_AVGLENGTH:
148948 case FTS3_MATCHINFO_LENGTH:
148949 case FTS3_MATCHINFO_LCS:
148950 nVal = pInfo->nCol;
148951 break;
 
 
 
 
148952
148953 default:
148954 assert( cArg==FTS3_MATCHINFO_HITS );
148955 nVal = pInfo->nCol * pInfo->nPhrase * 3;
148956 break;
@@ -149201,10 +149765,14 @@
149201 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149202 if( rc==SQLITE_OK ){
149203 rc = fts3MatchinfoLcs(pCsr, pInfo);
149204 }
149205 break;
 
 
 
 
149206
149207 default: {
149208 Fts3Expr *pExpr;
149209 assert( zArg[i]==FTS3_MATCHINFO_HITS );
149210 pExpr = pCsr->pExpr;
@@ -153214,15 +153782,23 @@
153214 ** conflict-handling mode specified by the user.
153215 */
153216 if( nData>1 ){
153217 int ii;
153218
153219 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
153220 assert( nData==(pRtree->nDim*2 + 3) );
 
 
 
 
 
 
 
 
153221 #ifndef SQLITE_RTREE_INT_ONLY
153222 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153223 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153224 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153225 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153226 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153227 rc = SQLITE_CONSTRAINT;
153228 goto constraint;
@@ -153229,11 +153805,11 @@
153229 }
153230 }
153231 }else
153232 #endif
153233 {
153234 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153235 cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153236 cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153237 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153238 rc = SQLITE_CONSTRAINT;
153239 goto constraint;
@@ -154629,5 +155205,633 @@
154629
154630 #endif /* defined(SQLITE_ENABLE_ICU) */
154631 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
154632
154633 /************** End of fts3_icu.c ********************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154634
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.10. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -68,10 +68,11 @@
68 #if defined(_MSC_VER)
69 #pragma warning(disable : 4054)
70 #pragma warning(disable : 4055)
71 #pragma warning(disable : 4100)
72 #pragma warning(disable : 4127)
73 #pragma warning(disable : 4130)
74 #pragma warning(disable : 4152)
75 #pragma warning(disable : 4189)
76 #pragma warning(disable : 4206)
77 #pragma warning(disable : 4210)
78 #pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
316 **
317 ** See also: [sqlite3_libversion()],
318 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
319 ** [sqlite_version()] and [sqlite_source_id()].
320 */
321 #define SQLITE_VERSION "3.8.10"
322 #define SQLITE_VERSION_NUMBER 3008010
323 #define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e"
324
325 /*
326 ** CAPI3REF: Run-Time Library Version Numbers
327 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
328 **
@@ -474,10 +475,11 @@
475 # define double sqlite3_int64
476 #endif
477
478 /*
479 ** CAPI3REF: Closing A Database Connection
480 ** DESTRUCTOR: sqlite3
481 **
482 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
483 ** for the [sqlite3] object.
484 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
485 ** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
527 */
528 typedef int (*sqlite3_callback)(void*,int,char**, char**);
529
530 /*
531 ** CAPI3REF: One-Step Query Execution Interface
532 ** METHOD: sqlite3
533 **
534 ** The sqlite3_exec() interface is a convenience wrapper around
535 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
536 ** that allows an application to run multiple statements of SQL
537 ** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
1585 */
1586 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1587
1588 /*
1589 ** CAPI3REF: Configure database connections
1590 ** METHOD: sqlite3
1591 **
1592 ** The sqlite3_db_config() interface is used to make configuration
1593 ** changes to a [database connection]. The interface is similar to
1594 ** [sqlite3_config()] except that the changes apply to a single
1595 ** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
2083 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2084
2085
2086 /*
2087 ** CAPI3REF: Enable Or Disable Extended Result Codes
2088 ** METHOD: sqlite3
2089 **
2090 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2091 ** [extended result codes] feature of SQLite. ^The extended result
2092 ** codes are disabled by default for historical compatibility.
2093 */
2094 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
2095
2096 /*
2097 ** CAPI3REF: Last Insert Rowid
2098 ** METHOD: sqlite3
2099 **
2100 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2101 ** has a unique 64-bit signed
2102 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2103 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
2145 */
2146 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
2147
2148 /*
2149 ** CAPI3REF: Count The Number Of Rows Modified
2150 ** METHOD: sqlite3
2151 **
2152 ** ^This function returns the number of rows modified, inserted or
2153 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2154 ** statement on the database connection specified by the only parameter.
2155 ** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
2198 */
2199 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
2200
2201 /*
2202 ** CAPI3REF: Total Number Of Rows Modified
2203 ** METHOD: sqlite3
2204 **
2205 ** ^This function returns the total number of rows inserted, modified or
2206 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2207 ** since the database connection was opened, including those executed as
2208 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
2222 */
2223 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2224
2225 /*
2226 ** CAPI3REF: Interrupt A Long-Running Query
2227 ** METHOD: sqlite3
2228 **
2229 ** ^This function causes any pending database operation to abort and
2230 ** return at its earliest opportunity. This routine is typically
2231 ** called in response to a user action such as pressing "Cancel"
2232 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
2299 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2300
2301 /*
2302 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2303 ** KEYWORDS: {busy-handler callback} {busy handler}
2304 ** METHOD: sqlite3
2305 **
2306 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2307 ** that might be invoked with argument P whenever
2308 ** an attempt is made to access a database table associated with
2309 ** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
2359 */
2360 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2361
2362 /*
2363 ** CAPI3REF: Set A Busy Timeout
2364 ** METHOD: sqlite3
2365 **
2366 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2367 ** for a specified amount of time when a table is locked. ^The handler
2368 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2369 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
2382 */
2383 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2384
2385 /*
2386 ** CAPI3REF: Convenience Routines For Running Queries
2387 ** METHOD: sqlite3
2388 **
2389 ** This is a legacy interface that is preserved for backwards compatibility.
2390 ** Use of this interface is not recommended.
2391 **
2392 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
2718 */
2719 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2720
2721 /*
2722 ** CAPI3REF: Compile-Time Authorization Callbacks
2723 ** METHOD: sqlite3
2724 **
2725 ** ^This routine registers an authorizer callback with a particular
2726 ** [database connection], supplied in the first argument.
2727 ** ^The authorizer callback is invoked as SQL statements are being compiled
2728 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
2875 #define SQLITE_COPY 0 /* No longer used */
2876 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2877
2878 /*
2879 ** CAPI3REF: Tracing And Profiling Functions
2880 ** METHOD: sqlite3
2881 **
2882 ** These routines register callback functions that can be used for
2883 ** tracing and profiling the execution of SQL statements.
2884 **
2885 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
2908 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2909 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2910
2911 /*
2912 ** CAPI3REF: Query Progress Callbacks
2913 ** METHOD: sqlite3
2914 **
2915 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2916 ** function X to be invoked periodically during long running calls to
2917 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2918 ** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
2942 */
2943 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2944
2945 /*
2946 ** CAPI3REF: Opening A New Database Connection
2947 ** CONSTRUCTOR: sqlite3
2948 **
2949 ** ^These routines open an SQLite database file as specified by the
2950 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2951 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2952 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
3228 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3229
3230
3231 /*
3232 ** CAPI3REF: Error Codes And Messages
3233 ** METHOD: sqlite3
3234 **
3235 ** ^If the most recent sqlite3_* API call associated with
3236 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3237 ** returns the numeric [result code] or [extended result code] for that
3238 ** API call.
@@ -3257,37 +3274,38 @@
3274 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3275 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3276 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3277
3278 /*
3279 ** CAPI3REF: Prepared Statement Object
3280 ** KEYWORDS: {prepared statement} {prepared statements}
3281 **
3282 ** An instance of this object represents a single SQL statement that
3283 ** has been compiled into binary form and is ready to be evaluated.
 
3284 **
3285 ** Think of each SQL statement as a separate computer program. The
3286 ** original SQL text is source code. A prepared statement object
3287 ** is the compiled object code. All SQL must be converted into a
3288 ** prepared statement before it can be run.
3289 **
3290 ** The life-cycle of a prepared statement object usually goes like this:
3291 **
3292 ** <ol>
3293 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3294 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
 
3295 ** interfaces.
3296 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3297 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3298 ** to step 2. Do this zero or more times.
3299 ** <li> Destroy the object using [sqlite3_finalize()].
3300 ** </ol>
 
 
 
3301 */
3302 typedef struct sqlite3_stmt sqlite3_stmt;
3303
3304 /*
3305 ** CAPI3REF: Run-time Limits
3306 ** METHOD: sqlite3
3307 **
3308 ** ^(This interface allows the size of various constructs to be limited
3309 ** on a connection by connection basis. The first parameter is the
3310 ** [database connection] whose limit is to be set or queried. The
3311 ** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
3413 #define SQLITE_LIMIT_WORKER_THREADS 11
3414
3415 /*
3416 ** CAPI3REF: Compiling An SQL Statement
3417 ** KEYWORDS: {SQL statement compiler}
3418 ** METHOD: sqlite3
3419 ** CONSTRUCTOR: sqlite3_stmt
3420 **
3421 ** To execute an SQL query, it must first be compiled into a byte-code
3422 ** program using one of these routines.
3423 **
3424 ** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
3522 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3523 );
3524
3525 /*
3526 ** CAPI3REF: Retrieving Statement SQL
3527 ** METHOD: sqlite3_stmt
3528 **
3529 ** ^This interface can be used to retrieve a saved copy of the original
3530 ** SQL text used to create a [prepared statement] if that statement was
3531 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3532 */
3533 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3534
3535 /*
3536 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3537 ** METHOD: sqlite3_stmt
3538 **
3539 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3540 ** and only if the [prepared statement] X makes no direct changes to
3541 ** the content of the database file.
3542 **
@@ -3542,10 +3564,11 @@
3564 */
3565 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3566
3567 /*
3568 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3569 ** METHOD: sqlite3_stmt
3570 **
3571 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3572 ** [prepared statement] S has been stepped at least once using
3573 ** [sqlite3_step(S)] but has not run to completion and/or has not
3574 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
3639
3640 /*
3641 ** CAPI3REF: Binding Values To Prepared Statements
3642 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3643 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3644 ** METHOD: sqlite3_stmt
3645 **
3646 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3647 ** literals may be replaced by a [parameter] that matches one of following
3648 ** templates:
3649 **
@@ -3734,10 +3758,11 @@
3758 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3759 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3760
3761 /*
3762 ** CAPI3REF: Number Of SQL Parameters
3763 ** METHOD: sqlite3_stmt
3764 **
3765 ** ^This routine can be used to find the number of [SQL parameters]
3766 ** in a [prepared statement]. SQL parameters are tokens of the
3767 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3768 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
3779 */
3780 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3781
3782 /*
3783 ** CAPI3REF: Name Of A Host Parameter
3784 ** METHOD: sqlite3_stmt
3785 **
3786 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3787 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3788 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3789 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
3807 */
3808 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3809
3810 /*
3811 ** CAPI3REF: Index Of A Parameter With A Given Name
3812 ** METHOD: sqlite3_stmt
3813 **
3814 ** ^Return the index of an SQL parameter given its name. ^The
3815 ** index value returned is suitable for use as the second
3816 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3817 ** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
3824 */
3825 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3826
3827 /*
3828 ** CAPI3REF: Reset All Bindings On A Prepared Statement
3829 ** METHOD: sqlite3_stmt
3830 **
3831 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3832 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3833 ** ^Use this routine to reset all host parameters to NULL.
3834 */
3835 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3836
3837 /*
3838 ** CAPI3REF: Number Of Columns In A Result Set
3839 ** METHOD: sqlite3_stmt
3840 **
3841 ** ^Return the number of columns in the result set returned by the
3842 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3843 ** statement that does not return data (for example an [UPDATE]).
3844 **
@@ -3817,10 +3846,11 @@
3846 */
3847 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3848
3849 /*
3850 ** CAPI3REF: Column Names In A Result Set
3851 ** METHOD: sqlite3_stmt
3852 **
3853 ** ^These routines return the name assigned to a particular column
3854 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3855 ** interface returns a pointer to a zero-terminated UTF-8 string
3856 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
3876 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3877 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3878
3879 /*
3880 ** CAPI3REF: Source Of Data In A Query Result
3881 ** METHOD: sqlite3_stmt
3882 **
3883 ** ^These routines provide a means to determine the database, table, and
3884 ** table column that is the origin of a particular result column in
3885 ** [SELECT] statement.
3886 ** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
3929 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3930 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3931
3932 /*
3933 ** CAPI3REF: Declared Datatype Of A Query Result
3934 ** METHOD: sqlite3_stmt
3935 **
3936 ** ^(The first parameter is a [prepared statement].
3937 ** If this statement is a [SELECT] statement and the Nth column of the
3938 ** returned result set of that [SELECT] is a table column (not an
3939 ** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
3962 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3963 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3964
3965 /*
3966 ** CAPI3REF: Evaluate An SQL Statement
3967 ** METHOD: sqlite3_stmt
3968 **
3969 ** After a [prepared statement] has been prepared using either
3970 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3971 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3972 ** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
4042 */
4043 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
4044
4045 /*
4046 ** CAPI3REF: Number of columns in a result set
4047 ** METHOD: sqlite3_stmt
4048 **
4049 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4050 ** current row of the result set of [prepared statement] P.
4051 ** ^If prepared statement P does not have results ready to return
4052 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
4096 #define SQLITE3_TEXT 3
4097
4098 /*
4099 ** CAPI3REF: Result Values From A Query
4100 ** KEYWORDS: {column access functions}
4101 ** METHOD: sqlite3_stmt
4102 **
4103 ** These routines form the "result set" interface.
4104 **
4105 ** ^These routines return information about a single column of the current
4106 ** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
4269 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4270 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4271
4272 /*
4273 ** CAPI3REF: Destroy A Prepared Statement Object
4274 ** DESTRUCTOR: sqlite3_stmt
4275 **
4276 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4277 ** ^If the most recent evaluation of the statement encountered no errors
4278 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4279 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
4297 */
4298 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4299
4300 /*
4301 ** CAPI3REF: Reset A Prepared Statement Object
4302 ** METHOD: sqlite3_stmt
4303 **
4304 ** The sqlite3_reset() function is called to reset a [prepared statement]
4305 ** object back to its initial state, ready to be re-executed.
4306 ** ^Any SQL statement variables that had values bound to them using
4307 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
4327 /*
4328 ** CAPI3REF: Create Or Redefine SQL Functions
4329 ** KEYWORDS: {function creation routines}
4330 ** KEYWORDS: {application-defined SQL function}
4331 ** KEYWORDS: {application-defined SQL functions}
4332 ** METHOD: sqlite3
4333 **
4334 ** ^These functions (collectively known as "function creation routines")
4335 ** are used to add SQL functions or aggregates or to redefine the behavior
4336 ** of existing SQL functions or aggregates. The only differences between
4337 ** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
4497 void*,sqlite3_int64);
4498 #endif
4499
4500 /*
4501 ** CAPI3REF: Obtaining SQL Function Parameter Values
4502 ** METHOD: sqlite3_value
4503 **
4504 ** The C-language implementation of SQL functions and aggregates uses
4505 ** this set of interface routines to access the parameter values on
4506 ** the function or aggregate.
4507 **
@@ -4517,10 +4556,11 @@
4556 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4557 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4558
4559 /*
4560 ** CAPI3REF: Obtain Aggregate Function Context
4561 ** METHOD: sqlite3_context
4562 **
4563 ** Implementations of aggregate SQL functions use this
4564 ** routine to allocate memory for storing their state.
4565 **
4566 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
4601 */
4602 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4603
4604 /*
4605 ** CAPI3REF: User Data For Functions
4606 ** METHOD: sqlite3_context
4607 **
4608 ** ^The sqlite3_user_data() interface returns a copy of
4609 ** the pointer that was the pUserData parameter (the 5th parameter)
4610 ** of the [sqlite3_create_function()]
4611 ** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
4616 */
4617 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4618
4619 /*
4620 ** CAPI3REF: Database Connection For Functions
4621 ** METHOD: sqlite3_context
4622 **
4623 ** ^The sqlite3_context_db_handle() interface returns a copy of
4624 ** the pointer to the [database connection] (the 1st parameter)
4625 ** of the [sqlite3_create_function()]
4626 ** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
4628 */
4629 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4630
4631 /*
4632 ** CAPI3REF: Function Auxiliary Data
4633 ** METHOD: sqlite3_context
4634 **
4635 ** These functions may be used by (non-aggregate) SQL functions to
4636 ** associate metadata with argument values. If the same value is passed to
4637 ** multiple invocations of the same SQL function during query execution, under
4638 ** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
4701 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4702 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4703
4704 /*
4705 ** CAPI3REF: Setting The Result Of An SQL Function
4706 ** METHOD: sqlite3_context
4707 **
4708 ** These routines are used by the xFunc or xFinal callbacks that
4709 ** implement SQL functions and aggregates. See
4710 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4711 ** for additional information.
@@ -4793,10 +4837,11 @@
4837 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4838 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4839
4840 /*
4841 ** CAPI3REF: Define New Collating Sequences
4842 ** METHOD: sqlite3
4843 **
4844 ** ^These functions add, remove, or modify a [collation] associated
4845 ** with the [database connection] specified as the first argument.
4846 **
4847 ** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
4940 int(*xCompare)(void*,int,const void*,int,const void*)
4941 );
4942
4943 /*
4944 ** CAPI3REF: Collation Needed Callbacks
4945 ** METHOD: sqlite3
4946 **
4947 ** ^To avoid having to register all collation sequences before a database
4948 ** can be used, a single callback function may be registered with the
4949 ** [database connection] to be invoked whenever an undefined collation
4950 ** sequence is required.
@@ -5102,10 +5148,11 @@
5148 SQLITE_API char *sqlite3_data_directory;
5149
5150 /*
5151 ** CAPI3REF: Test For Auto-Commit Mode
5152 ** KEYWORDS: {autocommit mode}
5153 ** METHOD: sqlite3
5154 **
5155 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5156 ** zero if the given database connection is or is not in autocommit mode,
5157 ** respectively. ^Autocommit mode is on by default.
5158 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
5171 */
5172 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
5173
5174 /*
5175 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
5176 ** METHOD: sqlite3_stmt
5177 **
5178 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5179 ** to which a [prepared statement] belongs. ^The [database connection]
5180 ** returned by sqlite3_db_handle is the same [database connection]
5181 ** that was the first argument
@@ -5136,10 +5184,11 @@
5184 */
5185 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
5186
5187 /*
5188 ** CAPI3REF: Return The Filename For A Database Connection
5189 ** METHOD: sqlite3
5190 **
5191 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5192 ** associated with database N of connection D. ^The main database file
5193 ** has the name "main". If there is no attached database N on the database
5194 ** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
5201 */
5202 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5203
5204 /*
5205 ** CAPI3REF: Determine if a database is read-only
5206 ** METHOD: sqlite3
5207 **
5208 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5209 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5210 ** the name of a database on connection D.
5211 */
5212 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5213
5214 /*
5215 ** CAPI3REF: Find the next prepared statement
5216 ** METHOD: sqlite3
5217 **
5218 ** ^This interface returns a pointer to the next [prepared statement] after
5219 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5220 ** then this interface returns a pointer to the first prepared statement
5221 ** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
5227 */
5228 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5229
5230 /*
5231 ** CAPI3REF: Commit And Rollback Notification Callbacks
5232 ** METHOD: sqlite3
5233 **
5234 ** ^The sqlite3_commit_hook() interface registers a callback
5235 ** function to be invoked whenever a transaction is [COMMIT | committed].
5236 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5237 ** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
5277 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5278 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5279
5280 /*
5281 ** CAPI3REF: Data Change Notification Callbacks
5282 ** METHOD: sqlite3
5283 **
5284 ** ^The sqlite3_update_hook() interface registers a callback function
5285 ** with the [database connection] identified by the first argument
5286 ** to be invoked whenever a row is updated, inserted or deleted in
5287 ** a rowid table.
@@ -5331,10 +5384,11 @@
5384 */
5385 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5386
5387 /*
5388 ** CAPI3REF: Free Memory Used By A Database Connection
5389 ** METHOD: sqlite3
5390 **
5391 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5392 ** memory as possible from database connection D. Unlike the
5393 ** [sqlite3_release_memory()] interface, this interface is in effect even
5394 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
5462 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5463
5464
5465 /*
5466 ** CAPI3REF: Extract Metadata About A Column Of A Table
5467 ** METHOD: sqlite3
5468 **
5469 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5470 ** information about column C of table T in database D
5471 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5472 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
5541 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5542 );
5543
5544 /*
5545 ** CAPI3REF: Load An Extension
5546 ** METHOD: sqlite3
5547 **
5548 ** ^This interface loads an SQLite extension library from the named file.
5549 **
5550 ** ^The sqlite3_load_extension() interface attempts to load an
5551 ** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
5583 char **pzErrMsg /* Put error message here if not 0 */
5584 );
5585
5586 /*
5587 ** CAPI3REF: Enable Or Disable Extension Loading
5588 ** METHOD: sqlite3
5589 **
5590 ** ^So as not to open security holes in older applications that are
5591 ** unprepared to deal with [extension loading], and as a means of disabling
5592 ** [extension loading] while evaluating user-entered SQL, the following API
5593 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
5833 #define SQLITE_INDEX_CONSTRAINT_GE 32
5834 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5835
5836 /*
5837 ** CAPI3REF: Register A Virtual Table Implementation
5838 ** METHOD: sqlite3
5839 **
5840 ** ^These routines are used to register a new [virtual table module] name.
5841 ** ^Module names must be registered before
5842 ** creating a new [virtual table] using the module and before using a
5843 ** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
5930 */
5931 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5932
5933 /*
5934 ** CAPI3REF: Overload A Function For A Virtual Table
5935 ** METHOD: sqlite3
5936 **
5937 ** ^(Virtual tables can provide alternative implementations of functions
5938 ** using the [xFindFunction] method of the [virtual table module].
5939 ** But global versions of those functions
5940 ** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
5973 */
5974 typedef struct sqlite3_blob sqlite3_blob;
5975
5976 /*
5977 ** CAPI3REF: Open A BLOB For Incremental I/O
5978 ** METHOD: sqlite3
5979 ** CONSTRUCTOR: sqlite3_blob
5980 **
5981 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5982 ** in row iRow, column zColumn, table zTable in database zDb;
5983 ** in other words, the same BLOB that would be selected by:
5984 **
@@ -5995,10 +6056,11 @@
6056 sqlite3_blob **ppBlob
6057 );
6058
6059 /*
6060 ** CAPI3REF: Move a BLOB Handle to a New Row
6061 ** METHOD: sqlite3_blob
6062 **
6063 ** ^This function is used to move an existing blob handle so that it points
6064 ** to a different row of the same database table. ^The new row is identified
6065 ** by the rowid value passed as the second argument. Only the row can be
6066 ** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
6081 */
6082 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
6083
6084 /*
6085 ** CAPI3REF: Close A BLOB Handle
6086 ** DESTRUCTOR: sqlite3_blob
6087 **
6088 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
6089 ** unconditionally. Even if this routine returns an error code, the
6090 ** handle is still closed.)^
6091 **
@@ -6041,10 +6104,11 @@
6104 */
6105 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
6106
6107 /*
6108 ** CAPI3REF: Return The Size Of An Open BLOB
6109 ** METHOD: sqlite3_blob
6110 **
6111 ** ^Returns the size in bytes of the BLOB accessible via the
6112 ** successfully opened [BLOB handle] in its only argument. ^The
6113 ** incremental blob I/O routines can only read or overwriting existing
6114 ** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
6120 */
6121 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
6122
6123 /*
6124 ** CAPI3REF: Read Data From A BLOB Incrementally
6125 ** METHOD: sqlite3_blob
6126 **
6127 ** ^(This function is used to read data from an open [BLOB handle] into a
6128 ** caller-supplied buffer. N bytes of data are copied into buffer Z
6129 ** from the open BLOB, starting at offset iOffset.)^
6130 **
@@ -6084,10 +6149,11 @@
6149 */
6150 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
6151
6152 /*
6153 ** CAPI3REF: Write Data Into A BLOB Incrementally
6154 ** METHOD: sqlite3_blob
6155 **
6156 ** ^(This function is used to write data into an open [BLOB handle] from a
6157 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
6158 ** into the open BLOB, starting at offset iOffset.)^
6159 **
@@ -6411,10 +6477,11 @@
6477 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6478 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6479
6480 /*
6481 ** CAPI3REF: Retrieve the mutex for a database connection
6482 ** METHOD: sqlite3
6483 **
6484 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6485 ** serializes access to the [database connection] given in the argument
6486 ** when the [threading mode] is Serialized.
6487 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
6489 */
6490 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6491
6492 /*
6493 ** CAPI3REF: Low-Level Control Of Database Files
6494 ** METHOD: sqlite3
6495 **
6496 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6497 ** xFileControl method for the [sqlite3_io_methods] object associated
6498 ** with a particular database identified by the second argument. ^The
6499 ** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
6706 #define SQLITE_STATUS_SCRATCH_SIZE 8
6707 #define SQLITE_STATUS_MALLOC_COUNT 9
6708
6709 /*
6710 ** CAPI3REF: Database Connection Status
6711 ** METHOD: sqlite3
6712 **
6713 ** ^This interface is used to retrieve runtime status information
6714 ** about a single [database connection]. ^The first argument is the
6715 ** database connection object to be interrogated. ^The second argument
6716 ** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
6835 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6836
6837
6838 /*
6839 ** CAPI3REF: Prepared Statement Status
6840 ** METHOD: sqlite3_stmt
6841 **
6842 ** ^(Each prepared statement maintains various
6843 ** [SQLITE_STMTSTATUS counters] that measure the number
6844 ** of times it has performed specific operations.)^ These counters can
6845 ** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
7339 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7340 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7341
7342 /*
7343 ** CAPI3REF: Unlock Notification
7344 ** METHOD: sqlite3
7345 **
7346 ** ^When running in shared-cache mode, a database operation may fail with
7347 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7348 ** individual tables within the shared-cache cannot be obtained. See
7349 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
7510 */
7511 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7512
7513 /*
7514 ** CAPI3REF: Write-Ahead Log Commit Hook
7515 ** METHOD: sqlite3
7516 **
7517 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7518 ** is invoked each time data is committed to a database in wal mode.
7519 **
7520 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
7550 void*
7551 );
7552
7553 /*
7554 ** CAPI3REF: Configure an auto-checkpoint
7555 ** METHOD: sqlite3
7556 **
7557 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7558 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7559 ** to automatically [checkpoint]
7560 ** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
7581 */
7582 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7583
7584 /*
7585 ** CAPI3REF: Checkpoint a database
7586 ** METHOD: sqlite3
7587 **
7588 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7589 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7590 **
7591 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
7603 */
7604 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7605
7606 /*
7607 ** CAPI3REF: Checkpoint a database
7608 ** METHOD: sqlite3
7609 **
7610 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7611 ** operation on database X of [database connection] D in mode M. Status
7612 ** information is written back into integers pointed to by L and C.)^
7613 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
7858 #define SQLITE_SCANSTAT_EXPLAIN 4
7859 #define SQLITE_SCANSTAT_SELECTID 5
7860
7861 /*
7862 ** CAPI3REF: Prepared Statement Scan Status
7863 ** METHOD: sqlite3_stmt
7864 **
7865 ** This interface returns information about the predicted and measured
7866 ** performance for pStmt. Advanced applications can use this
7867 ** interface to compare the predicted and the measured performance and
7868 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
7896 void *pOut /* Result written here */
7897 );
7898
7899 /*
7900 ** CAPI3REF: Zero Scan-Status Counters
7901 ** METHOD: sqlite3_stmt
7902 **
7903 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7904 **
7905 ** This API is only available if the library is built with pre-processor
7906 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
8507 #else
8508 # define ALWAYS(X) (X)
8509 # define NEVER(X) (X)
8510 #endif
8511
8512 /*
8513 ** Declarations used for tracing the operating system interfaces.
8514 */
8515 #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
8516 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8517 extern int sqlite3OSTrace;
8518 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
8519 # define SQLITE_HAVE_OS_TRACE
8520 #else
8521 # define OSTRACE(X)
8522 # undef SQLITE_HAVE_OS_TRACE
8523 #endif
8524
8525 /*
8526 ** Is the sqlite3ErrName() function needed in the build? Currently,
8527 ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
8528 ** OSTRACE is enabled), and by several "test*.c" files (which are
8529 ** compiled using SQLITE_TEST).
8530 */
8531 #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \
8532 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8533 # define SQLITE_NEED_ERR_NAME
8534 #else
8535 # undef SQLITE_NEED_ERR_NAME
8536 #endif
8537
8538 /*
8539 ** Return true (non-zero) if the input is an integer that is too large
8540 ** to fit in 32-bits. This macro is used inside of various testcase()
8541 ** macros to verify that we have tested SQLite for large-file support.
8542 */
@@ -9841,37 +9944,36 @@
9944 /* Properties such as "out2" or "jump" that are specified in
9945 ** comments following the "case" for each opcode in the vdbe.c
9946 ** are encoded into bitvectors as follows:
9947 */
9948 #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9949 #define OPFLG_IN1 0x0002 /* in1: P1 is an input */
9950 #define OPFLG_IN2 0x0004 /* in2: P2 is an input */
9951 #define OPFLG_IN3 0x0008 /* in3: P3 is an input */
9952 #define OPFLG_OUT2 0x0010 /* out2: P2 is an output */
9953 #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
 
9954 #define OPFLG_INITIALIZER {\
9955 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9956 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
9957 /* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\
9958 /* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\
9959 /* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\
9960 /* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
9961 /* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\
9962 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\
9963 /* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\
9964 /* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
9965 /* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
9966 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
9967 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
9968 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
9969 /* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\
9970 /* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9971 /* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\
9972 /* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\
9973 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9974 /* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,}
9975
9976 /************** End of opcodes.h *********************************************/
9977 /************** Continuing where we left off in vdbe.h ***********************/
9978
9979 /*
@@ -9926,10 +10028,11 @@
10028 #endif
10029 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
10030
10031 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
10032 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
10033 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
10034 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
10035
10036 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
10037 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
10038
@@ -11063,10 +11166,11 @@
11166 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
11167 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
11168 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
11169 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
11170 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
11171 #define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
11172
11173
11174 /*
11175 ** Bits of the sqlite3.dbOptFlags field that are used by the
11176 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
11497 int iSavepoint; /* Depth of the SAVEPOINT stack */
11498 VTable *pNext; /* Next in linked list (see above) */
11499 };
11500
11501 /*
11502 ** The schema for each SQL table and view is represented in memory
11503 ** by an instance of the following structure.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11504 */
11505 struct Table {
11506 char *zName; /* Name of the table or view */
11507 Column *aCol; /* Information about each column */
11508 Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
11510 FKey *pFKey; /* Linked list of all foreign keys in this table */
11511 char *zColAff; /* String defining the affinity of each column */
11512 #ifndef SQLITE_OMIT_CHECK
11513 ExprList *pCheck; /* All CHECK constraints */
11514 #endif
11515 int tnum; /* Root BTree page for this table */
11516 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
 
11517 i16 nCol; /* Number of columns in this table */
11518 u16 nRef; /* Number of pointers to this Table */
11519 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11520 LogEst szTabRow; /* Estimated size of each table row in bytes */
11521 #ifdef SQLITE_ENABLE_COSTMULT
11522 LogEst costMult; /* Cost multiplier for using this table */
11523 #endif
11524 u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
11536 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
11537 };
11538
11539 /*
11540 ** Allowed values for Table.tabFlags.
11541 **
11542 ** TF_OOOHidden applies to virtual tables that have hidden columns that are
11543 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
11544 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
11545 ** the TF_OOOHidden attribute would apply in this case. Such tables require
11546 ** special handling during INSERT processing.
11547 */
11548 #define TF_Readonly 0x01 /* Read-only system table */
11549 #define TF_Ephemeral 0x02 /* An ephemeral table */
11550 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
11551 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
11552 #define TF_Virtual 0x10 /* Is a virtual table */
11553 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
11554 #define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */
11555
11556
11557 /*
11558 ** Test to see whether or not a table is a virtual table. This is
11559 ** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
12306 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12307 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12308 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12309 #define SF_Compound 0x0040 /* Part of a compound query */
12310 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12311 #define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */
12312 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12313 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12314 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12315 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12316 #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
12690 *
12691 * (op == TK_INSERT)
12692 * orconf -> stores the ON CONFLICT algorithm
12693 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
12694 * this stores a pointer to the SELECT statement. Otherwise NULL.
12695 * zTarget -> Dequoted name of the table to insert into.
12696 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
12697 * this stores values to be inserted. Otherwise NULL.
12698 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
12699 * statement, then this stores the column-names to be
12700 * inserted into.
12701 *
12702 * (op == TK_DELETE)
12703 * zTarget -> Dequoted name of the table to delete from.
12704 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
12705 * Otherwise NULL.
12706 *
12707 * (op == TK_UPDATE)
12708 * zTarget -> Dequoted name of the table to update.
12709 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
12710 * Otherwise NULL.
12711 * pExprList -> A list of the columns to update and the expressions to update
12712 * them to. See sqlite3Update() documentation of "pChanges"
12713 * argument.
@@ -12630,12 +12715,12 @@
12715 */
12716 struct TriggerStep {
12717 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
12718 u8 orconf; /* OE_Rollback etc. */
12719 Trigger *pTrig; /* The trigger that this step is a part of */
12720 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
12721 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
12722 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
12723 ExprList *pExprList; /* SET clause for UPDATE. */
12724 IdList *pIdList; /* Column names for INSERT */
12725 TriggerStep *pNext; /* Next in the link-list */
12726 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
12749 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
12750 char *zBase; /* A base allocation. Not from malloc. */
12751 char *zText; /* The string collected so far */
12752 int nChar; /* Length of the string so far */
12753 int nAlloc; /* Amount of space allocated in zText */
12754 int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
 
12755 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
12756 };
12757 #define STRACCUM_NOMEM 1
12758 #define STRACCUM_TOOBIG 2
12759
@@ -12982,11 +13066,11 @@
13066 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
13067 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
13068 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
13069 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
13070 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
13071 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
13072 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
13073 #endif
13074 #if defined(SQLITE_TEST)
13075 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
13076 #endif
@@ -13329,11 +13413,11 @@
13413 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
13414 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
13415 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
13416 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
13417
13418 #if defined(SQLITE_NEED_ERR_NAME)
13419 SQLITE_PRIVATE const char *sqlite3ErrName(int);
13420 #endif
13421
13422 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13423 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
13507 FuncDestructor *pDestructor
13508 );
13509 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
13510 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13511
13512 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
13513 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13514 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13515 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
13516 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13517 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -19807,20 +19891,10 @@
19891 */
19892 #ifdef MEMORY_DEBUG
19893 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19894 #endif
19895
 
 
 
 
 
 
 
 
 
 
19896 /*
19897 ** Macros for performance tracing. Normally turned off. Only works
19898 ** on i486 hardware.
19899 */
19900 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21475,11 @@
21475
21476 /*
21477 ** Set the StrAccum object to an error mode.
21478 */
21479 static void setStrAccumError(StrAccum *p, u8 eError){
21480 assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
21481 p->accError = eError;
21482 p->nAlloc = 0;
21483 }
21484
21485 /*
@@ -22018,11 +22093,11 @@
22093 if( p->accError ){
22094 testcase(p->accError==STRACCUM_TOOBIG);
22095 testcase(p->accError==STRACCUM_NOMEM);
22096 return 0;
22097 }
22098 if( p->mxAlloc==0 ){
22099 N = p->nAlloc - p->nChar - 1;
22100 setStrAccumError(p, STRACCUM_TOOBIG);
22101 return N;
22102 }else{
22103 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22113,14 @@
22113 setStrAccumError(p, STRACCUM_TOOBIG);
22114 return 0;
22115 }else{
22116 p->nAlloc = (int)szNew;
22117 }
22118 if( p->db ){
22119 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22120 }else{
22121 zNew = sqlite3_realloc64(zOld, p->nAlloc);
22122 }
22123 if( zNew ){
22124 assert( p->zText!=0 || p->nChar==0 );
22125 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
22126 p->zText = zNew;
@@ -22089,11 +22164,11 @@
22164 /*
22165 ** Append N bytes of text from z to the StrAccum object. Increase the
22166 ** size of the memory allocation for StrAccum if necessary.
22167 */
22168 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22169 assert( z!=0 || N==0 );
22170 assert( p->zText!=0 || p->nChar==0 || p->accError );
22171 assert( N>=0 );
22172 assert( p->accError==0 || p->nAlloc==0 );
22173 if( p->nChar+N >= p->nAlloc ){
22174 enlargeAndAppend(p,z,N);
@@ -22118,16 +22193,12 @@
22193 ** pointer if any kind of error was encountered.
22194 */
22195 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
22196 if( p->zText ){
22197 p->zText[p->nChar] = 0;
22198 if( p->mxAlloc>0 && p->zText==p->zBase ){
22199 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 
 
 
 
22200 if( p->zText ){
22201 memcpy(p->zText, p->zBase, p->nChar+1);
22202 }else{
22203 setStrAccumError(p, STRACCUM_NOMEM);
22204 }
@@ -22139,29 +22210,35 @@
22210 /*
22211 ** Reset an StrAccum string. Reclaim all malloced memory.
22212 */
22213 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
22214 if( p->zText!=p->zBase ){
22215 sqlite3DbFree(p->db, p->zText);
 
 
 
 
22216 }
22217 p->zText = 0;
22218 }
22219
22220 /*
22221 ** Initialize a string accumulator.
22222 **
22223 ** p: The accumulator to be initialized.
22224 ** db: Pointer to a database connection. May be NULL. Lookaside
22225 ** memory is used if not NULL. db->mallocFailed is set appropriately
22226 ** when not NULL.
22227 ** zBase: An initial buffer. May be NULL in which case the initial buffer
22228 ** is malloced.
22229 ** n: Size of zBase in bytes. If total space requirements never exceed
22230 ** n then no memory allocations ever occur.
22231 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
22232 ** allocations will ever occur.
22233 */
22234 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
22235 p->zText = p->zBase = zBase;
22236 p->db = db;
22237 p->nChar = 0;
22238 p->nAlloc = n;
22239 p->mxAlloc = mx;
 
22240 p->accError = 0;
22241 }
22242
22243 /*
22244 ** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22247,12 @@
22247 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
22248 char *z;
22249 char zBase[SQLITE_PRINT_BUF_SIZE];
22250 StrAccum acc;
22251 assert( db!=0 );
22252 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
22253 db->aLimit[SQLITE_LIMIT_LENGTH]);
 
22254 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
22255 z = sqlite3StrAccumFinish(&acc);
22256 if( acc.accError==STRACCUM_NOMEM ){
22257 db->mallocFailed = 1;
22258 }
@@ -22230,12 +22306,11 @@
22306 }
22307 #endif
22308 #ifndef SQLITE_OMIT_AUTOINIT
22309 if( sqlite3_initialize() ) return 0;
22310 #endif
22311 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
 
22312 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22313 z = sqlite3StrAccumFinish(&acc);
22314 return z;
22315 }
22316
@@ -22276,12 +22351,11 @@
22351 (void)SQLITE_MISUSE_BKPT;
22352 if( zBuf ) zBuf[0] = 0;
22353 return zBuf;
22354 }
22355 #endif
22356 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
 
22357 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22358 return sqlite3StrAccumFinish(&acc);
22359 }
22360 SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
22361 char *z;
@@ -22303,12 +22377,11 @@
22377 */
22378 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22379 StrAccum acc; /* String accumulator */
22380 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22381
22382 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
 
22383 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22384 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
22385 sqlite3StrAccumFinish(&acc));
22386 }
22387
@@ -22322,22 +22395,21 @@
22395 renderLogMsg(iErrCode, zFormat, ap);
22396 va_end(ap);
22397 }
22398 }
22399
22400 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
22401 /*
22402 ** A version of printf() that understands %lld. Used for debugging.
22403 ** The printf() built into some versions of windows does not understand %lld
22404 ** and segfaults if you give it a long long int.
22405 */
22406 SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
22407 va_list ap;
22408 StrAccum acc;
22409 char zBuf[500];
22410 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
 
22411 va_start(ap,zFormat);
22412 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22413 va_end(ap);
22414 sqlite3StrAccumFinish(&acc);
22415 fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22432,11 @@
22432 */
22433 /* Add a new subitem to the tree. The moreToFollow flag indicates that this
22434 ** is not the last item in the tree. */
22435 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
22436 if( p==0 ){
22437 p = sqlite3_malloc64( sizeof(*p) );
22438 if( p==0 ) return 0;
22439 memset(p, 0, sizeof(*p));
22440 }else{
22441 p->iLevel++;
22442 }
@@ -22383,12 +22455,11 @@
22455 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
22456 va_list ap;
22457 int i;
22458 StrAccum acc;
22459 char zBuf[500];
22460 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
 
22461 if( p ){
22462 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
22463 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
22464 }
22465 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24078,11 @@
24078 }else{
24079 return 0;
24080 }
24081 }
24082 #endif
24083 while( zNum[0]=='0' ) zNum++;
24084 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
24085 v = v*10 + c;
24086 }
24087
24088 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25333,21 @@
25333 #if SQLITE_ENABLE_LOCKING_STYLE
25334 # include <sys/ioctl.h>
25335 # include <sys/file.h>
25336 # include <sys/param.h>
25337 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
25338
25339 #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
25340 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
25341 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
25342 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
25343 # define HAVE_GETHOSTUUID 1
25344 # else
25345 # warning "gethostuuid() is disabled."
25346 # endif
25347 #endif
25348
25349
25350 #if OS_VXWORKS
25351 /* # include <sys/ioctl.h> */
25352 # include <semaphore.h>
25353 # include <limits.h>
@@ -25457,20 +25540,10 @@
25540 */
25541 #ifdef MEMORY_DEBUG
25542 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
25543 #endif
25544
 
 
 
 
 
 
 
 
 
 
25545 /*
25546 ** Macros for performance tracing. Normally turned off. Only works
25547 ** on i486 hardware.
25548 */
25549 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26082,11 @@
26082 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26083 }
26084 #endif
26085
26086
26087 #ifdef SQLITE_HAVE_OS_TRACE
26088 /*
26089 ** Helper function for printing out trace information from debugging
26090 ** binaries. This returns the string representation of the supplied
26091 ** integer lock-type.
26092 */
@@ -26272,11 +26345,11 @@
26345 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
26346 int n; /* Length of zAbsoluteName string */
26347
26348 assert( zAbsoluteName[0]=='/' );
26349 n = (int)strlen(zAbsoluteName);
26350 pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) );
26351 if( pNew==0 ) return 0;
26352 pNew->zCanonicalName = (char*)&pNew[1];
26353 memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
26354 n = vxworksSimplifyName(pNew->zCanonicalName, n);
26355
@@ -26676,11 +26749,11 @@
26749 pInode = inodeList;
26750 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
26751 pInode = pInode->pNext;
26752 }
26753 if( pInode==0 ){
26754 pInode = sqlite3_malloc64( sizeof(*pInode) );
26755 if( pInode==0 ){
26756 return SQLITE_NOMEM;
26757 }
26758 memset(pInode, 0, sizeof(*pInode));
26759 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29270,11 @@
29270 case SQLITE_FCNTL_VFSNAME: {
29271 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
29272 return SQLITE_OK;
29273 }
29274 case SQLITE_FCNTL_TEMPFILENAME: {
29275 char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
29276 if( zTFile ){
29277 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
29278 *(char**)pArg = zTFile;
29279 }
29280 return SQLITE_OK;
@@ -29638,11 +29711,11 @@
29711 unixInodeInfo *pInode; /* The inode of fd */
29712 char *zShmFilename; /* Name of the file used for SHM */
29713 int nShmFilename; /* Size of the SHM filename in bytes */
29714
29715 /* Allocate space for the new unixShm object. */
29716 p = sqlite3_malloc64( sizeof(*p) );
29717 if( p==0 ) return SQLITE_NOMEM;
29718 memset(p, 0, sizeof(*p));
29719 assert( pDbFd->pShm==0 );
29720
29721 /* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29742,11 @@
29742 #ifdef SQLITE_SHM_DIRECTORY
29743 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29744 #else
29745 nShmFilename = 6 + (int)strlen(zBasePath);
29746 #endif
29747 pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
29748 if( pShmNode==0 ){
29749 rc = SQLITE_NOMEM;
29750 goto shm_open_err;
29751 }
29752 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29952,11 @@
29952 if( pMem==MAP_FAILED ){
29953 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
29954 goto shmpage_out;
29955 }
29956 }else{
29957 pMem = sqlite3_malloc64(szRegion);
29958 if( pMem==0 ){
29959 rc = SQLITE_NOMEM;
29960 goto shmpage_out;
29961 }
29962 memset(pMem, 0, szRegion);
@@ -30716,11 +30789,11 @@
30789 else if( pLockingStyle == &afpIoMethods ){
30790 /* AFP locking uses the file path so it needs to be included in
30791 ** the afpLockingContext.
30792 */
30793 afpLockingContext *pCtx;
30794 pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
30795 if( pCtx==0 ){
30796 rc = SQLITE_NOMEM;
30797 }else{
30798 /* NB: zFilename exists and remains valid until the file is closed
30799 ** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30819,11 @@
30819 */
30820 char *zLockFile;
30821 int nFilename;
30822 assert( zFilename!=0 );
30823 nFilename = (int)strlen(zFilename) + 6;
30824 zLockFile = (char *)sqlite3_malloc64(nFilename);
30825 if( zLockFile==0 ){
30826 rc = SQLITE_NOMEM;
30827 }else{
30828 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
30829 }
@@ -31123,11 +31196,11 @@
31196 UnixUnusedFd *pUnused;
31197 pUnused = findReusableFd(zName, flags);
31198 if( pUnused ){
31199 fd = pUnused->fd;
31200 }else{
31201 pUnused = sqlite3_malloc64(sizeof(*pUnused));
31202 if( !pUnused ){
31203 return SQLITE_NOMEM;
31204 }
31205 }
31206 p->pUnused = pUnused;
@@ -31503,11 +31576,11 @@
31576 ** that we always use the same random number sequence. This makes the
31577 ** tests repeatable.
31578 */
31579 memset(zBuf, 0, nBuf);
31580 randomnessPid = osGetpid(0);
31581 #if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
31582 {
31583 int fd, got;
31584 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31585 if( fd<0 ){
31586 time_t t;
@@ -31915,11 +31988,11 @@
31988 */
31989 pUnused = findReusableFd(path, openFlags);
31990 if( pUnused ){
31991 fd = pUnused->fd;
31992 }else{
31993 pUnused = sqlite3_malloc64(sizeof(*pUnused));
31994 if( !pUnused ){
31995 return SQLITE_NOMEM;
31996 }
31997 }
31998 if( fd<0 ){
@@ -31948,11 +32021,11 @@
32021 default:
32022 return SQLITE_CANTOPEN_BKPT;
32023 }
32024 }
32025
32026 pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
32027 if( pNew==NULL ){
32028 rc = SQLITE_NOMEM;
32029 goto end_create_proxy;
32030 }
32031 memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32054,22 @@
32054 SQLITE_API int sqlite3_hostid_num = 0;
32055 #endif
32056
32057 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
32058
32059 #ifdef HAVE_GETHOSTUUID
32060 /* Not always defined in the headers as it ought to be */
32061 extern int gethostuuid(uuid_t id, const struct timespec *wait);
32062 #endif
32063
32064 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
32065 ** bytes of writable memory.
32066 */
32067 static int proxyGetHostID(unsigned char *pHostID, int *pError){
32068 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
32069 memset(pHostID, 0, PROXY_HOSTIDLEN);
32070 #ifdef HAVE_GETHOSTUUID
 
32071 {
32072 struct timespec timeout = {1, 0}; /* 1 sec timeout */
32073 if( gethostuuid(pHostID, &timeout) ){
32074 int err = errno;
32075 if( pError ){
@@ -32409,11 +32483,11 @@
32483 return rc;
32484 }
32485
32486 /*
32487 ** Given the name of a database file, compute the name of its conch file.
32488 ** Store the conch filename in memory obtained from sqlite3_malloc64().
32489 ** Make *pConchPath point to the new name. Return SQLITE_OK on success
32490 ** or SQLITE_NOMEM if unable to obtain memory.
32491 **
32492 ** The caller is responsible for ensuring that the allocated memory
32493 ** space is eventually freed.
@@ -32425,11 +32499,11 @@
32499 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
32500 char *conchPath; /* buffer in which to construct conch name */
32501
32502 /* Allocate space for the conch filename and initialize the name to
32503 ** the name of the original database file. */
32504 *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
32505 if( conchPath==0 ){
32506 return SQLITE_NOMEM;
32507 }
32508 memcpy(conchPath, dbPath, len+1);
32509
@@ -32541,11 +32615,11 @@
32615 }
32616
32617 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32618 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
32619
32620 pCtx = sqlite3_malloc64( sizeof(*pCtx) );
32621 if( pCtx==0 ){
32622 return SQLITE_NOMEM;
32623 }
32624 memset(pCtx, 0, sizeof(*pCtx));
32625
@@ -32985,20 +33059,10 @@
33059 */
33060 #ifdef MEMORY_DEBUG
33061 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
33062 #endif
33063
 
 
 
 
 
 
 
 
 
 
33064 /*
33065 ** Macros for performance tracing. Normally turned off. Only works
33066 ** on i486 hardware.
33067 */
33068 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35962,11 @@
35962 ** Used only when SQLITE_NO_SYNC is not defined.
35963 */
35964 BOOL rc;
35965 #endif
35966 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35967 defined(SQLITE_HAVE_OS_TRACE)
35968 /*
35969 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
35970 ** OSTRACE() macros.
35971 */
35972 winFile *pFile = (winFile*)id;
@@ -36575,11 +36639,11 @@
36639 DWORD lastErrno; /* The Windows errno from the last I/O error */
36640
36641 int nRef; /* Number of winShm objects pointing to this */
36642 winShm *pFirst; /* All winShm objects pointing to this */
36643 winShmNode *pNext; /* Next in list of all winShmNode objects */
36644 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36645 u8 nextShmId; /* Next available winShm.id value */
36646 #endif
36647 };
36648
36649 /*
@@ -36606,11 +36670,11 @@
36670 winShmNode *pShmNode; /* The underlying winShmNode object */
36671 winShm *pNext; /* Next winShm with the same winShmNode */
36672 u8 hasMutex; /* True if holding the winShmNode mutex */
36673 u16 sharedMask; /* Mask of shared locks held */
36674 u16 exclMask; /* Mask of exclusive locks held */
36675 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36676 u8 id; /* Id of this connection with its winShmNode */
36677 #endif
36678 };
36679
36680 /*
@@ -36797,11 +36861,11 @@
36861 if( rc ) goto shm_open_err;
36862 }
36863
36864 /* Make the new connection a child of the winShmNode */
36865 p->pShmNode = pShmNode;
36866 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36867 p->id = pShmNode->nextShmId++;
36868 #endif
36869 pShmNode->nRef++;
36870 pDbFd->pShm = p;
36871 winShmLeaveMutex();
@@ -37066,11 +37130,11 @@
37130 goto shmpage_out;
37131 }
37132 }
37133
37134 /* Map the requested memory region into this processes address space. */
37135 apNew = (struct ShmRegion *)sqlite3_realloc64(
37136 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
37137 );
37138 if( !apNew ){
37139 rc = SQLITE_IOERR_NOMEM;
37140 goto shmpage_out;
@@ -38513,11 +38577,11 @@
38577 ** Write up to nBuf bytes of randomness into zBuf.
38578 */
38579 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
38580 int n = 0;
38581 UNUSED_PARAMETER(pVfs);
38582 #if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
38583 n = nBuf;
38584 memset(zBuf, 0, nBuf);
38585 #else
38586 if( sizeof(SYSTEMTIME)<=nBuf-n ){
38587 SYSTEMTIME x;
@@ -38547,11 +38611,10 @@
38611 LARGE_INTEGER i;
38612 osQueryPerformanceCounter(&i);
38613 memcpy(&zBuf[n], &i, sizeof(i));
38614 n += sizeof(i);
38615 }
 
38616 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38617 if( sizeof(UUID)<=nBuf-n ){
38618 UUID id;
38619 memset(&id, 0, sizeof(UUID));
38620 osUuidCreate(&id);
@@ -38564,10 +38627,11 @@
38627 osUuidCreateSequential(&id);
38628 memcpy(zBuf, &id, sizeof(UUID));
38629 n += sizeof(UUID);
38630 }
38631 #endif
38632 #endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
38633 return n;
38634 }
38635
38636
38637 /*
@@ -39118,11 +39182,11 @@
39182
39183 /* Allocate the Bitvec to be tested and a linear array of
39184 ** bits to act as the reference */
39185 pBitvec = sqlite3BitvecCreate( sz );
39186 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39187 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
39188 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
39189
39190 /* NULL pBitvec tests */
39191 sqlite3BitvecSet(0, 1);
39192 sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44671,11 @@
44671 Pgno nTruncate, /* Database size after this commit */
44672 int isCommit /* True if this is a commit */
44673 ){
44674 int rc; /* Return code */
44675 int nList; /* Number of pages in pList */
 
44676 PgHdr *p; /* For looping over pages */
 
44677
44678 assert( pPager->pWal );
44679 assert( pList );
44680 #ifdef SQLITE_DEBUG
44681 /* Verify that the page list is in accending order */
@@ -44626,11 +44688,10 @@
44688 if( isCommit ){
44689 /* If a WAL transaction is being committed, there is no point in writing
44690 ** any pages with page numbers greater than nTruncate into the WAL file.
44691 ** They will never be read by any client. So remove them from the pDirty
44692 ** list here. */
 
44693 PgHdr **ppNext = &pList;
44694 nList = 0;
44695 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
44696 if( p->pgno<=nTruncate ){
44697 ppNext = &p->pDirty;
@@ -44646,11 +44707,10 @@
44707 if( pList->pgno==1 ) pager_write_changecounter(pList);
44708 rc = sqlite3WalFrames(pPager->pWal,
44709 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
44710 );
44711 if( rc==SQLITE_OK && pPager->pBackup ){
 
44712 for(p=pList; p; p=p->pDirty){
44713 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
44714 }
44715 }
44716
@@ -48577,10 +48637,12 @@
48637 }else if( state==PAGER_OPEN ){
48638 pager_unlock(pPager);
48639 }
48640 assert( state==pPager->eState );
48641 }
48642 }else if( eMode==PAGER_JOURNALMODE_OFF ){
48643 sqlite3OsClose(pPager->jfd);
48644 }
48645 }
48646
48647 /* Return the new journal mode */
48648 return (int)pPager->journalMode;
@@ -49359,11 +49421,11 @@
49421
49422 /* Enlarge the pWal->apWiData[] array if required */
49423 if( pWal->nWiData<=iPage ){
49424 int nByte = sizeof(u32*)*(iPage+1);
49425 volatile u32 **apNew;
49426 apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
49427 if( !apNew ){
49428 *ppPage = 0;
49429 return SQLITE_NOMEM;
49430 }
49431 memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50046,11 @@
50046 goto finished;
50047 }
50048
50049 /* Malloc a buffer to read frames into. */
50050 szFrame = szPage + WAL_FRAME_HDRSIZE;
50051 aFrame = (u8 *)sqlite3_malloc64(szFrame);
50052 if( !aFrame ){
50053 rc = SQLITE_NOMEM;
50054 goto recovery_error;
50055 }
50056 aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50439,21 @@
50439 /* Allocate space for the WalIterator object. */
50440 nSegment = walFramePage(iLast) + 1;
50441 nByte = sizeof(WalIterator)
50442 + (nSegment-1)*sizeof(struct WalSegment)
50443 + iLast*sizeof(ht_slot);
50444 p = (WalIterator *)sqlite3_malloc64(nByte);
50445 if( !p ){
50446 return SQLITE_NOMEM;
50447 }
50448 memset(p, 0, nByte);
50449 p->nSegment = nSegment;
50450
50451 /* Allocate temporary space used by the merge-sort routine. This block
50452 ** of memory will be freed before this function returns.
50453 */
50454 aTmp = (ht_slot *)sqlite3_malloc64(
50455 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
50456 );
50457 if( !aTmp ){
50458 rc = SQLITE_NOMEM;
50459 }
@@ -50567,10 +50629,18 @@
50629 ** cannot be backfilled from the WAL.
50630 */
50631 mxSafeFrame = pWal->hdr.mxFrame;
50632 mxPage = pWal->hdr.nPage;
50633 for(i=1; i<WAL_NREADER; i++){
50634 /* Thread-sanitizer reports that the following is an unsafe read,
50635 ** as some other thread may be in the process of updating the value
50636 ** of the aReadMark[] slot. The assumption here is that if that is
50637 ** happening, the other client may only be increasing the value,
50638 ** not decreasing it. So assuming either that either the "old" or
50639 ** "new" version of the value is read, and not some arbitrary value
50640 ** that would never be written by a real client, things are still
50641 ** safe. */
50642 u32 y = pInfo->aReadMark[i];
50643 if( mxSafeFrame>y ){
50644 assert( y<=pWal->hdr.mxFrame );
50645 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
50646 if( rc==SQLITE_OK ){
@@ -57429,17 +57499,22 @@
57499 */
57500 static const void *fetchPayload(
57501 BtCursor *pCur, /* Cursor pointing to entry to read from */
57502 u32 *pAmt /* Write the number of available bytes here */
57503 ){
57504 u32 amt;
57505 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
57506 assert( pCur->eState==CURSOR_VALID );
57507 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57508 assert( cursorHoldsMutex(pCur) );
57509 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57510 assert( pCur->info.nSize>0 );
57511 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
57512 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
57513 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
57514 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
57515 *pAmt = amt;
57516 return (void*)pCur->info.pPayload;
57517 }
57518
57519
57520 /*
@@ -59713,11 +59788,10 @@
59788 if( iParentIdx==0 ){
59789 nxDiv = 0;
59790 }else if( iParentIdx==i ){
59791 nxDiv = i-2+bBulk;
59792 }else{
 
59793 nxDiv = iParentIdx-1;
59794 }
59795 i = 2-bBulk;
59796 }
59797 nOld = i+1;
@@ -61501,10 +61575,61 @@
61575 iPage = get4byte(pOvflData);
61576 sqlite3PagerUnref(pOvflPage);
61577 }
61578 }
61579 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
61580
61581 /*
61582 ** An implementation of a min-heap.
61583 **
61584 ** aHeap[0] is the number of elements on the heap. aHeap[1] is the
61585 ** root element. The daughter nodes of aHeap[N] are aHeap[N*2]
61586 ** and aHeap[N*2+1].
61587 **
61588 ** The heap property is this: Every node is less than or equal to both
61589 ** of its daughter nodes. A consequence of the heap property is that the
61590 ** root node aHeap[1] is always the minimum value currently in the heap.
61591 **
61592 ** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
61593 ** the heap, preserving the heap property. The btreeHeapPull() routine
61594 ** removes the root element from the heap (the minimum value in the heap)
61595 ** and then moves other nodes around as necessary to preserve the heap
61596 ** property.
61597 **
61598 ** This heap is used for cell overlap and coverage testing. Each u32
61599 ** entry represents the span of a cell or freeblock on a btree page.
61600 ** The upper 16 bits are the index of the first byte of a range and the
61601 ** lower 16 bits are the index of the last byte of that range.
61602 */
61603 static void btreeHeapInsert(u32 *aHeap, u32 x){
61604 u32 j, i = ++aHeap[0];
61605 aHeap[i] = x;
61606 while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
61607 x = aHeap[j];
61608 aHeap[j] = aHeap[i];
61609 aHeap[i] = x;
61610 i = j;
61611 }
61612 }
61613 static int btreeHeapPull(u32 *aHeap, u32 *pOut){
61614 u32 j, i, x;
61615 if( (x = aHeap[0])==0 ) return 0;
61616 *pOut = aHeap[1];
61617 aHeap[1] = aHeap[x];
61618 aHeap[x] = 0xffffffff;
61619 aHeap[0]--;
61620 i = 1;
61621 while( (j = i*2)<=aHeap[0] ){
61622 if( aHeap[j]>aHeap[j+1] ) j++;
61623 if( aHeap[i]<aHeap[j] ) break;
61624 x = aHeap[i];
61625 aHeap[i] = aHeap[j];
61626 aHeap[j] = x;
61627 i = j;
61628 }
61629 return 1;
61630 }
61631
61632 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
61633 /*
61634 ** Do various sanity checks on a single page of a tree. Return
61635 ** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61659,12 @@
61659 int hdr, cellStart;
61660 int nCell;
61661 u8 *data;
61662 BtShared *pBt;
61663 int usableSize;
61664 u32 *heap = 0;
61665 u32 x, prev = 0;
61666 i64 nMinKey = 0;
61667 i64 nMaxKey = 0;
61668 const char *saved_zPfx = pCheck->zPfx;
61669 int saved_v1 = pCheck->v1;
61670 int saved_v2 = pCheck->v2;
@@ -61679,19 +61805,19 @@
61805
61806 /* Check for complete coverage of the page
61807 */
61808 data = pPage->aData;
61809 hdr = pPage->hdrOffset;
61810 heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
61811 pCheck->zPfx = 0;
61812 if( heap==0 ){
61813 pCheck->mallocFailed = 1;
61814 }else{
61815 int contentOffset = get2byteNotZero(&data[hdr+5]);
61816 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61817 heap[0] = 0;
61818 btreeHeapInsert(heap, contentOffset-1);
61819 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61820 ** number of cells on the page. */
61821 nCell = get2byte(&data[hdr+3]);
61822 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61823 ** immediately follows the b-tree page header. */
@@ -61699,20 +61825,19 @@
61825 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61826 ** integer offsets to the cell contents. */
61827 for(i=0; i<nCell; i++){
61828 int pc = get2byte(&data[cellStart+i*2]);
61829 u32 size = 65536;
 
61830 if( pc<=usableSize-4 ){
61831 size = cellSizePtr(pPage, &data[pc]);
61832 }
61833 if( (int)(pc+size-1)>=usableSize ){
61834 pCheck->zPfx = 0;
61835 checkAppendMsg(pCheck,
61836 "Corruption detected in cell %d on page %d",i,iPage);
61837 }else{
61838 btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
61839 }
61840 }
61841 /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61842 ** is the offset of the first freeblock, or zero if there are no
61843 ** freeblocks on the page. */
@@ -61720,11 +61845,11 @@
61845 while( i>0 ){
61846 int size, j;
61847 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
61848 size = get2byte(&data[i+2]);
61849 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61850 btreeHeapInsert(heap, (i<<16)|(i+size-1));
61851 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61852 ** big-endian integer which is the offset in the b-tree page of the next
61853 ** freeblock in the chain, or zero if the freeblock is the last on the
61854 ** chain. */
61855 j = get2byte(&data[i]);
@@ -61732,31 +61857,37 @@
61857 ** increasing offset. */
61858 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
61859 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
61860 i = j;
61861 }
61862 cnt = 0;
61863 assert( heap[0]>0 );
61864 assert( (heap[1]>>16)==0 );
61865 btreeHeapPull(heap,&prev);
61866 while( btreeHeapPull(heap,&x) ){
61867 if( (prev&0xffff)+1>(x>>16) ){
61868 checkAppendMsg(pCheck,
61869 "Multiple uses for byte %u of page %d", x>>16, iPage);
61870 break;
61871 }else{
61872 cnt += (x>>16) - (prev&0xffff) - 1;
61873 prev = x;
61874 }
61875 }
61876 cnt += usableSize - (prev&0xffff) - 1;
61877 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61878 ** is stored in the fifth field of the b-tree page header.
61879 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61880 ** number of fragmented free bytes within the cell content area.
61881 */
61882 if( heap[0]==0 && cnt!=data[hdr+7] ){
61883 checkAppendMsg(pCheck,
61884 "Fragmentation of %d bytes reported as %d on page %d",
61885 cnt, data[hdr+7], iPage);
61886 }
61887 }
61888 sqlite3PageFree(heap);
61889 releasePage(pPage);
61890
61891 end_of_check:
61892 pCheck->zPfx = saved_zPfx;
61893 pCheck->v1 = saved_v1;
@@ -61816,12 +61947,11 @@
61947 sqlite3BtreeLeave(p);
61948 return 0;
61949 }
61950 i = PENDING_BYTE_PAGE(pBt);
61951 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61952 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
 
61953
61954 /* Check the integrity of the freelist
61955 */
61956 sCheck.zPfx = "Main freelist: ";
61957 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63283,15 @@
63283 return SQLITE_NOMEM;
63284 }
63285 pMem->z[pMem->n] = 0;
63286 pMem->z[pMem->n+1] = 0;
63287 pMem->flags |= MEM_Term;
63288 }
63289 pMem->flags &= ~MEM_Ephem;
63290 #ifdef SQLITE_DEBUG
63291 pMem->pScopyFrom = 0;
63292 #endif
 
63293
63294 return SQLITE_OK;
63295 }
63296
63297 /*
@@ -64600,11 +64731,11 @@
64731 int i;
64732 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
64733 Mem *aMem = pRec->aMem;
64734 sqlite3 *db = aMem[0].db;
64735 for(i=0; i<nCol; i++){
64736 sqlite3VdbeMemRelease(&aMem[i]);
64737 }
64738 sqlite3KeyInfoUnref(pRec->pKeyInfo);
64739 sqlite3DbFree(db, pRec);
64740 }
64741 }
@@ -66436,18 +66567,35 @@
66567 pVtabCursor->pVtab->nRef--;
66568 pModule->xClose(pVtabCursor);
66569 }
66570 #endif
66571 }
66572
66573 /*
66574 ** Close all cursors in the current frame.
66575 */
66576 static void closeCursorsInFrame(Vdbe *p){
66577 if( p->apCsr ){
66578 int i;
66579 for(i=0; i<p->nCursor; i++){
66580 VdbeCursor *pC = p->apCsr[i];
66581 if( pC ){
66582 sqlite3VdbeFreeCursor(p, pC);
66583 p->apCsr[i] = 0;
66584 }
66585 }
66586 }
66587 }
66588
66589 /*
66590 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
66591 ** is used, for example, when a trigger sub-program is halted to restore
66592 ** control to the main program.
66593 */
66594 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
66595 Vdbe *v = pFrame->v;
66596 closeCursorsInFrame(v);
66597 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66598 v->anExec = pFrame->anExec;
66599 #endif
66600 v->aOnceFlag = pFrame->aOnceFlag;
66601 v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66626,11 @@
66626 sqlite3VdbeFrameRestore(pFrame);
66627 p->pFrame = 0;
66628 p->nFrame = 0;
66629 }
66630 assert( p->nFrame==0 );
66631 closeCursorsInFrame(p);
 
 
 
 
 
 
 
 
 
 
66632 if( p->aMem ){
66633 releaseMemArray(&p->aMem[1], p->nMem);
66634 }
66635 while( p->pDelFrame ){
66636 VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68371,11 @@
68371 ** If database corruption is discovered, set pPKey2->errCode to
68372 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
68373 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
68374 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
68375 */
68376 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
68377 int nKey1, const void *pKey1, /* Left key */
68378 UnpackedRecord *pPKey2, /* Right key */
68379 int bSkip /* If true, skip the first field */
68380 ){
68381 u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68557,11 @@
68557 }
68558 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
68559 int nKey1, const void *pKey1, /* Left key */
68560 UnpackedRecord *pPKey2 /* Right key */
68561 ){
68562 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68563 }
68564
68565
68566 /*
68567 ** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68645,11 @@
68645 }else if( v<lhs ){
68646 res = pPKey2->r2;
68647 }else if( pPKey2->nField>1 ){
68648 /* The first fields of the two keys are equal. Compare the trailing
68649 ** fields. */
68650 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68651 }else{
68652 /* The first fields of the two keys are equal and there are no trailing
68653 ** fields. Return pPKey2->default_rc in this case. */
68654 res = pPKey2->default_rc;
68655 }
@@ -68555,11 +68693,11 @@
68693
68694 if( res==0 ){
68695 res = nStr - pPKey2->aMem[0].n;
68696 if( res==0 ){
68697 if( pPKey2->nField>1 ){
68698 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68699 }else{
68700 res = pPKey2->default_rc;
68701 }
68702 }else if( res>0 ){
68703 res = pPKey2->r2;
@@ -70497,21 +70635,22 @@
70635 Mem *pVar; /* Value of a host parameter */
70636 StrAccum out; /* Accumulate the output here */
70637 char zBase[100]; /* Initial working space */
70638
70639 db = p->db;
70640 sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
70641 db->aLimit[SQLITE_LIMIT_LENGTH]);
 
70642 if( db->nVdbeExec>1 ){
70643 while( *zRawSql ){
70644 const char *zStart = zRawSql;
70645 while( *(zRawSql++)!='\n' && *zRawSql );
70646 sqlite3StrAccumAppend(&out, "-- ", 3);
70647 assert( (zRawSql - zStart) > 0 );
70648 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
70649 }
70650 }else if( p->nVar==0 ){
70651 sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
70652 }else{
70653 while( zRawSql[0] ){
70654 n = findNextHostParameter(zRawSql, &nToken);
70655 assert( n>0 );
70656 sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70663,16 @@
70663 sqlite3GetInt32(&zRawSql[1], &idx);
70664 }else{
70665 idx = nextIndex;
70666 }
70667 }else{
70668 assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
70669 zRawSql[0]=='@' || zRawSql[0]=='#' );
70670 testcase( zRawSql[0]==':' );
70671 testcase( zRawSql[0]=='$' );
70672 testcase( zRawSql[0]=='@' );
70673 testcase( zRawSql[0]=='#' );
70674 idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
70675 assert( idx>0 );
70676 }
70677 zRawSql += nToken;
70678 nextIndex = idx + 1;
@@ -71202,21 +71343,38 @@
71343 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
71344 return 1;
71345 }
71346 #endif
71347
71348 /*
71349 ** Return the register of pOp->p2 after first preparing it to be
71350 ** overwritten with an integer value.
71351 */
71352 static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
71353 Mem *pOut;
71354 assert( pOp->p2>0 );
71355 assert( pOp->p2<=(p->nMem-p->nCursor) );
71356 pOut = &p->aMem[pOp->p2];
71357 memAboutToChange(p, pOut);
71358 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71359 pOut->flags = MEM_Int;
71360 return pOut;
71361 }
71362
71363
71364 /*
71365 ** Execute as much of a VDBE program as we can.
71366 ** This is the core of sqlite3_step().
71367 */
71368 SQLITE_PRIVATE int sqlite3VdbeExec(
71369 Vdbe *p /* The VDBE */
71370 ){
 
71371 Op *aOp = p->aOp; /* Copy of p->aOp */
71372 Op *pOp = aOp; /* Current operation */
71373 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71374 Op *pOrigOp; /* Value of pOp at the top of the loop */
71375 #endif
71376 int rc = SQLITE_OK; /* Value to return */
71377 sqlite3 *db = p->db; /* The database */
71378 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
71379 u8 encoding = ENC(db); /* The database encoding */
71380 int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71446,26 @@
71446 }
71447 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
71448 }
71449 sqlite3EndBenignMalloc();
71450 #endif
71451 for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){
71452 assert( pOp>=aOp && pOp<&aOp[p->nOp]);
71453 if( db->mallocFailed ) goto no_mem;
71454 #ifdef VDBE_PROFILE
71455 start = sqlite3Hwtime();
71456 #endif
71457 nVmStep++;
 
71458 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71459 if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
71460 #endif
71461
71462 /* Only allow tracing if SQLITE_DEBUG is defined.
71463 */
71464 #ifdef SQLITE_DEBUG
71465 if( db->flags & SQLITE_VdbeTrace ){
71466 sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
71467 }
71468 #endif
71469
71470
71471 /* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71478,13 @@
71478 sqlite3_interrupt(db);
71479 }
71480 }
71481 #endif
71482
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71483 /* Sanity checking on other operands */
71484 #ifdef SQLITE_DEBUG
71485 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71486 if( (pOp->opflags & OPFLG_IN1)!=0 ){
71487 assert( pOp->p1>0 );
71488 assert( pOp->p1<=(p->nMem-p->nCursor) );
71489 assert( memIsValid(&aMem[pOp->p1]) );
71490 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71513,13 @@
71513 assert( pOp->p3>0 );
71514 assert( pOp->p3<=(p->nMem-p->nCursor) );
71515 memAboutToChange(p, &aMem[pOp->p3]);
71516 }
71517 #endif
71518 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71519 pOrigOp = pOp;
71520 #endif
71521
71522 switch( pOp->opcode ){
71523
71524 /*****************************************************************************
71525 ** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71539,11 @@
71539 ** case statement is followed by a comment of the form "/# same as ... #/"
71540 ** that comment is used to determine the particular value of the opcode.
71541 **
71542 ** Other keywords in the comment that follows each case are used to
71543 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71544 ** Keywords include: in1, in2, in3, out2, out3. See
71545 ** the mkopcodeh.awk script for additional information.
71546 **
71547 ** Documentation about VDBE opcodes is generated by scanning this file
71548 ** for lines of that contain "Opcode:". That line and all subsequent
71549 ** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71567,12 @@
71567 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
71568 ** that this Goto is the bottom of a loop and that the lines from P2 down
71569 ** to the current line should be indented for EXPLAIN output.
71570 */
71571 case OP_Goto: { /* jump */
71572 jump_to_p2_and_check_for_interrupt:
71573 pOp = &aOp[pOp->p2 - 1];
71574
71575 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
71576 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
71577 ** completion. Check to see if sqlite3_interrupt() has been called
71578 ** or if the progress callback needs to be invoked.
@@ -71466,13 +71613,17 @@
71613 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71614 pIn1 = &aMem[pOp->p1];
71615 assert( VdbeMemDynamic(pIn1)==0 );
71616 memAboutToChange(p, pIn1);
71617 pIn1->flags = MEM_Int;
71618 pIn1->u.i = (int)(pOp-aOp);
71619 REGISTER_TRACE(pOp->p1, pIn1);
71620
71621 /* Most jump operations do a goto to this spot in order to update
71622 ** the pOp pointer. */
71623 jump_to_p2:
71624 pOp = &aOp[pOp->p2 - 1];
71625 break;
71626 }
71627
71628 /* Opcode: Return P1 * * * *
71629 **
@@ -71480,11 +71631,11 @@
71631 ** the jump, register P1 becomes undefined.
71632 */
71633 case OP_Return: { /* in1 */
71634 pIn1 = &aMem[pOp->p1];
71635 assert( pIn1->flags==MEM_Int );
71636 pOp = &aOp[pIn1->u.i];
71637 pIn1->flags = MEM_Undefined;
71638 break;
71639 }
71640
71641 /* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71655,11 @@
71655 assert( pOp->p3>=0 && pOp->p3<p->nOp );
71656 pOut = &aMem[pOp->p1];
71657 assert( !VdbeMemDynamic(pOut) );
71658 pOut->u.i = pOp->p3 - 1;
71659 pOut->flags = MEM_Int;
71660 if( pOp->p2 ) goto jump_to_p2;
71661 break;
71662 }
71663
71664 /* Opcode: EndCoroutine P1 * * * *
71665 **
@@ -71524,11 +71675,11 @@
71675 assert( pIn1->flags==MEM_Int );
71676 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
71677 pCaller = &aOp[pIn1->u.i];
71678 assert( pCaller->opcode==OP_Yield );
71679 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71680 pOp = &aOp[pCaller->p2 - 1];
71681 pIn1->flags = MEM_Undefined;
71682 break;
71683 }
71684
71685 /* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71699,13 @@
71699 int pcDest;
71700 pIn1 = &aMem[pOp->p1];
71701 assert( VdbeMemDynamic(pIn1)==0 );
71702 pIn1->flags = MEM_Int;
71703 pcDest = (int)pIn1->u.i;
71704 pIn1->u.i = (int)(pOp - aOp);
71705 REGISTER_TRACE(pOp->p1, pIn1);
71706 pOp = &aOp[pcDest];
71707 break;
71708 }
71709
71710 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
71711 ** Synopsis: if r[P3]=null halt
@@ -71601,34 +71752,38 @@
71752 ** is the same as executing Halt.
71753 */
71754 case OP_Halt: {
71755 const char *zType;
71756 const char *zLogFmt;
71757 VdbeFrame *pFrame;
71758 int pcx;
71759
71760 pcx = (int)(pOp - aOp);
71761 if( pOp->p1==SQLITE_OK && p->pFrame ){
71762 /* Halt the sub-program. Return control to the parent frame. */
71763 pFrame = p->pFrame;
71764 p->pFrame = pFrame->pParent;
71765 p->nFrame--;
71766 sqlite3VdbeSetChanges(db, p->nChange);
71767 pcx = sqlite3VdbeFrameRestore(pFrame);
71768 lastRowid = db->lastRowid;
71769 if( pOp->p2==OE_Ignore ){
71770 /* Instruction pcx is the OP_Program that invoked the sub-program
71771 ** currently being halted. If the p2 instruction of this OP_Halt
71772 ** instruction is set to OE_Ignore, then the sub-program is throwing
71773 ** an IGNORE exception. In this case jump to the address specified
71774 ** as the p2 of the calling OP_Program. */
71775 pcx = p->aOp[pcx].p2-1;
71776 }
71777 aOp = p->aOp;
71778 aMem = p->aMem;
71779 pOp = &aOp[pcx];
71780 break;
71781 }
71782 p->rc = pOp->p1;
71783 p->errorAction = (u8)pOp->p2;
71784 p->pc = pcx;
71785 if( p->rc ){
71786 if( pOp->p5 ){
71787 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
71788 "FOREIGN KEY" };
71789 assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71803,11 @@
71803 }else if( pOp->p4.z ){
71804 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
71805 }else{
71806 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
71807 }
71808 sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
71809 }
71810 rc = sqlite3VdbeHalt(p);
71811 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
71812 if( rc==SQLITE_BUSY ){
71813 p->rc = rc = SQLITE_BUSY;
@@ -71659,19 +71814,21 @@
71814 }else{
71815 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
71816 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
71817 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
71818 }
71819 pOp = &aOp[pcx];
71820 goto vdbe_return;
71821 }
71822
71823 /* Opcode: Integer P1 P2 * * *
71824 ** Synopsis: r[P2]=P1
71825 **
71826 ** The 32-bit integer value P1 is written into register P2.
71827 */
71828 case OP_Integer: { /* out2 */
71829 pOut = out2Prerelease(p, pOp);
71830 pOut->u.i = pOp->p1;
71831 break;
71832 }
71833
71834 /* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71835,12 @@
71835 ** Synopsis: r[P2]=P4
71836 **
71837 ** P4 is a pointer to a 64-bit integer value.
71838 ** Write that value into register P2.
71839 */
71840 case OP_Int64: { /* out2 */
71841 pOut = out2Prerelease(p, pOp);
71842 assert( pOp->p4.pI64!=0 );
71843 pOut->u.i = *pOp->p4.pI64;
71844 break;
71845 }
71846
@@ -71691,11 +71849,12 @@
71849 ** Synopsis: r[P2]=P4
71850 **
71851 ** P4 is a pointer to a 64-bit floating point value.
71852 ** Write that value into register P2.
71853 */
71854 case OP_Real: { /* same as TK_FLOAT, out2 */
71855 pOut = out2Prerelease(p, pOp);
71856 pOut->flags = MEM_Real;
71857 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
71858 pOut->u.r = *pOp->p4.pReal;
71859 break;
71860 }
@@ -71707,12 +71866,13 @@
71866 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71867 ** into a String opcode before it is executed for the first time. During
71868 ** this transformation, the length of string P4 is computed and stored
71869 ** as the P1 parameter.
71870 */
71871 case OP_String8: { /* same as TK_STRING, out2 */
71872 assert( pOp->p4.z!=0 );
71873 pOut = out2Prerelease(p, pOp);
71874 pOp->opcode = OP_String;
71875 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
71876
71877 #ifndef SQLITE_OMIT_UTF16
71878 if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71905,13 @@
71905 ** If P5!=0 and the content of register P3 is greater than zero, then
71906 ** the datatype of the register P2 is converted to BLOB. The content is
71907 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
71908 ** of a string, as if it had been CAST.
71909 */
71910 case OP_String: { /* out2 */
71911 assert( pOp->p4.z!=0 );
71912 pOut = out2Prerelease(p, pOp);
71913 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71914 pOut->z = pOp->p4.z;
71915 pOut->n = pOp->p1;
71916 pOut->enc = encoding;
71917 UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71935,14 @@
71935 **
71936 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
71937 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
71938 ** OP_Ne or OP_Eq.
71939 */
71940 case OP_Null: { /* out2 */
71941 int cnt;
71942 u16 nullFlag;
71943 pOut = out2Prerelease(p, pOp);
71944 cnt = pOp->p3-pOp->p2;
71945 assert( pOp->p3<=(p->nMem-p->nCursor) );
71946 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
71947 while( cnt>0 ){
71948 pOut++;
@@ -71811,12 +71973,13 @@
71973 ** Synopsis: r[P2]=P4 (len=P1)
71974 **
71975 ** P4 points to a blob of data P1 bytes long. Store this
71976 ** blob in register P2.
71977 */
71978 case OP_Blob: { /* out2 */
71979 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
71980 pOut = out2Prerelease(p, pOp);
71981 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
71982 pOut->enc = encoding;
71983 UPDATE_MAX_BLOBSIZE(pOut);
71984 break;
71985 }
@@ -71827,19 +71990,20 @@
71990 ** Transfer the values of bound parameter P1 into register P2
71991 **
71992 ** If the parameter is named, then its name appears in P4.
71993 ** The P4 value is used by sqlite3_bind_parameter_name().
71994 */
71995 case OP_Variable: { /* out2 */
71996 Mem *pVar; /* Value being transferred */
71997
71998 assert( pOp->p1>0 && pOp->p1<=p->nVar );
71999 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
72000 pVar = &p->aVar[pOp->p1 - 1];
72001 if( sqlite3VdbeMemTooBig(pVar) ){
72002 goto too_big;
72003 }
72004 pOut = out2Prerelease(p, pOp);
72005 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
72006 UPDATE_MAX_BLOBSIZE(pOut);
72007 break;
72008 }
72009
@@ -71870,14 +72034,15 @@
72034 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
72035 assert( memIsValid(pIn1) );
72036 memAboutToChange(p, pOut);
72037 sqlite3VdbeMemMove(pOut, pIn1);
72038 #ifdef SQLITE_DEBUG
72039 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
72040 pOut->pScopyFrom += pOp->p2 - p1;
72041 }
72042 #endif
72043 Deephemeralize(pOut);
72044 REGISTER_TRACE(p2++, pOut);
72045 pIn1++;
72046 pOut++;
72047 }while( --n );
72048 break;
@@ -72012,11 +72177,11 @@
72177 }
72178 if( db->mallocFailed ) goto no_mem;
72179
72180 /* Return SQLITE_ROW
72181 */
72182 p->pc = (int)(pOp - aOp) + 1;
72183 rc = SQLITE_ROW;
72184 goto vdbe_return;
72185 }
72186
72187 /* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72423,11 @@
72423 REGISTER_TRACE(pOp->p2+i, pArg);
72424 }
72425
72426 assert( pOp->p4type==P4_FUNCDEF );
72427 ctx.pFunc = pOp->p4.pFunc;
72428 ctx.iOp = (int)(pOp - aOp);
72429 ctx.pVdbe = p;
72430 MemSetTypeFlag(ctx.pOut, MEM_Null);
72431 ctx.fErrorOrAux = 0;
72432 db->lastRowid = lastRowid;
72433 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72437,11 @@
72437 if( ctx.fErrorOrAux ){
72438 if( ctx.isError ){
72439 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
72440 rc = ctx.isError;
72441 }
72442 sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1);
72443 }
72444
72445 /* Copy the result of the function into register P3 */
72446 sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
72447 if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72566,11 @@
72566 if( (pIn1->flags & MEM_Int)==0 ){
72567 if( pOp->p2==0 ){
72568 rc = SQLITE_MISMATCH;
72569 goto abort_due_to_error;
72570 }else{
72571 goto jump_to_p2;
 
72572 }
72573 }
72574 }
72575 MemSetTypeFlag(pIn1, MEM_Int);
72576 break;
@@ -72588,11 +72752,11 @@
72752 MemSetTypeFlag(pOut, MEM_Null);
72753 REGISTER_TRACE(pOp->p2, pOut);
72754 }else{
72755 VdbeBranchTaken(2,3);
72756 if( pOp->p5 & SQLITE_JUMPIFNULL ){
72757 goto jump_to_p2;
72758 }
72759 }
72760 break;
72761 }
72762 }else{
@@ -72639,10 +72803,16 @@
72803 case OP_Lt: res = res<0; break;
72804 case OP_Le: res = res<=0; break;
72805 case OP_Gt: res = res>0; break;
72806 default: res = res>=0; break;
72807 }
72808
72809 /* Undo any changes made by applyAffinity() to the input registers. */
72810 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72811 pIn1->flags = flags1;
72812 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72813 pIn3->flags = flags3;
72814
72815 if( pOp->p5 & SQLITE_STOREP2 ){
72816 pOut = &aMem[pOp->p2];
72817 memAboutToChange(p, pOut);
72818 MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72819,13 @@
72819 pOut->u.i = res;
72820 REGISTER_TRACE(pOp->p2, pOut);
72821 }else{
72822 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
72823 if( res ){
72824 goto jump_to_p2;
72825 }
72826 }
 
 
 
 
 
72827 break;
72828 }
72829
72830 /* Opcode: Permutation * * * P4 *
72831 **
@@ -72751,15 +72916,15 @@
72916 ** in the most recent OP_Compare instruction the P1 vector was less than
72917 ** equal to, or greater than the P2 vector, respectively.
72918 */
72919 case OP_Jump: { /* jump */
72920 if( iCompare<0 ){
72921 VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1];
72922 }else if( iCompare==0 ){
72923 VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1];
72924 }else{
72925 VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1];
72926 }
72927 break;
72928 }
72929
72930 /* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73030,11 @@
73030 */
73031 case OP_Once: { /* jump */
73032 assert( pOp->p1<p->nOnceFlag );
73033 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
73034 if( p->aOnceFlag[pOp->p1] ){
73035 goto jump_to_p2;
73036 }else{
73037 p->aOnceFlag[pOp->p1] = 1;
73038 }
73039 break;
73040 }
@@ -72900,11 +73065,11 @@
73065 #endif
73066 if( pOp->opcode==OP_IfNot ) c = !c;
73067 }
73068 VdbeBranchTaken(c!=0, 2);
73069 if( c ){
73070 goto jump_to_p2;
73071 }
73072 break;
73073 }
73074
73075 /* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73079,11 @@
73079 */
73080 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
73081 pIn1 = &aMem[pOp->p1];
73082 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
73083 if( (pIn1->flags & MEM_Null)!=0 ){
73084 goto jump_to_p2;
73085 }
73086 break;
73087 }
73088
73089 /* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73093,11 @@
73093 */
73094 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
73095 pIn1 = &aMem[pOp->p1];
73096 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
73097 if( (pIn1->flags & MEM_Null)==0 ){
73098 goto jump_to_p2;
73099 }
73100 break;
73101 }
73102
73103 /* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73307,11 @@
73307 rc = SQLITE_CORRUPT_BKPT;
73308 goto op_column_error;
73309 }
73310 }
73311
73312 /* If after trying to extract new entries from the header, nHdrParsed is
73313 ** still not up to p2, that means that the record has fewer than p2
73314 ** columns. So the result will be either the default value or a NULL.
73315 */
73316 if( pC->nHdrParsed<=p2 ){
73317 if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73431,11 @@
73431 u8 *zNewRecord; /* A buffer to hold the data for the new record */
73432 Mem *pRec; /* The new record */
73433 u64 nData; /* Number of bytes of data space */
73434 int nHdr; /* Number of bytes of header space */
73435 i64 nByte; /* Data space required for this record */
73436 i64 nZero; /* Number of zero bytes at the end of the record */
73437 int nVarint; /* Number of bytes in a varint */
73438 u32 serial_type; /* Type field */
73439 Mem *pData0; /* First field to be combined into the record */
73440 Mem *pLast; /* Last field of the record */
73441 int nField; /* Number of fields in the record */
@@ -73358,11 +73523,11 @@
73523 nVarint = sqlite3VarintLen(nHdr);
73524 nHdr += nVarint;
73525 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
73526 }
73527 nByte = nHdr+nData;
73528 if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73529 goto too_big;
73530 }
73531
73532 /* Make sure the output register has a buffer large enough to store
73533 ** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73574,19 @@
73574 **
73575 ** Store the number of entries (an integer value) in the table or index
73576 ** opened by cursor P1 in register P2
73577 */
73578 #ifndef SQLITE_OMIT_BTREECOUNT
73579 case OP_Count: { /* out2 */
73580 i64 nEntry;
73581 BtCursor *pCrsr;
73582
73583 pCrsr = p->apCsr[pOp->p1]->pCursor;
73584 assert( pCrsr );
73585 nEntry = 0; /* Not needed. Only used to silence a warning. */
73586 rc = sqlite3BtreeCount(pCrsr, &nEntry);
73587 pOut = out2Prerelease(p, pOp);
73588 pOut->u.i = nEntry;
73589 break;
73590 }
73591 #endif
73592
@@ -73530,11 +73696,11 @@
73696 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73697 goto vdbe_return;
73698 }
73699 db->autoCommit = 1;
73700 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73701 p->pc = (int)(pOp - aOp);
73702 db->autoCommit = 0;
73703 p->rc = rc = SQLITE_BUSY;
73704 goto vdbe_return;
73705 }
73706 db->isTransactionSavepoint = 0;
@@ -73589,11 +73755,11 @@
73755 }else{
73756 db->nDeferredCons = pSavepoint->nDeferredCons;
73757 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
73758 }
73759
73760 if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){
73761 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
73762 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73763 }
73764 }
73765 }
@@ -73649,11 +73815,11 @@
73815 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73816 goto vdbe_return;
73817 }else{
73818 db->autoCommit = (u8)desiredAutoCommit;
73819 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73820 p->pc = (int)(pOp - aOp);
73821 db->autoCommit = (u8)(1-desiredAutoCommit);
73822 p->rc = rc = SQLITE_BUSY;
73823 goto vdbe_return;
73824 }
73825 }
@@ -73726,11 +73892,11 @@
73892 pBt = db->aDb[pOp->p1].pBt;
73893
73894 if( pBt ){
73895 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
73896 if( rc==SQLITE_BUSY ){
73897 p->pc = (int)(pOp - aOp);
73898 p->rc = rc = SQLITE_BUSY;
73899 goto vdbe_return;
73900 }
73901 if( rc!=SQLITE_OK ){
73902 goto abort_due_to_error;
@@ -73805,11 +73971,11 @@
73971 **
73972 ** There must be a read-lock on the database (either a transaction
73973 ** must be started or there must be an open cursor) before
73974 ** executing this instruction.
73975 */
73976 case OP_ReadCookie: { /* out2 */
73977 int iMeta;
73978 int iDb;
73979 int iCookie;
73980
73981 assert( p->bIsReader );
@@ -73819,10 +73985,11 @@
73985 assert( iDb>=0 && iDb<db->nDb );
73986 assert( db->aDb[iDb].pBt!=0 );
73987 assert( DbMaskTest(p->btreeMask, iDb) );
73988
73989 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
73990 pOut = out2Prerelease(p, pOp);
73991 pOut->u.i = iMeta;
73992 break;
73993 }
73994
73995 /* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74307,11 @@
74307 VdbeCursor *pC;
74308 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74309 pC = p->apCsr[pOp->p1];
74310 assert( pC->pSorter );
74311 if( (pC->seqCount++)==0 ){
74312 goto jump_to_p2;
74313 }
74314 break;
74315 }
74316
74317 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74484,11 @@
74484 ** loss of information, then special processing is required... */
74485 if( (pIn3->flags & MEM_Int)==0 ){
74486 if( (pIn3->flags & MEM_Real)==0 ){
74487 /* If the P3 value cannot be converted into any kind of a number,
74488 ** then the seek is not possible, so jump to P2 */
74489 VdbeBranchTaken(1,2); goto jump_to_p2;
74490 break;
74491 }
74492
74493 /* If the approximation iKey is larger than the actual real search
74494 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74575,11 @@
74575 }
74576 }
74577 assert( pOp->p2>0 );
74578 VdbeBranchTaken(res!=0,2);
74579 if( res ){
74580 goto jump_to_p2;
74581 }
74582 break;
74583 }
74584
74585 /* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74669,11 @@
74669 */
74670 case OP_NoConflict: /* jump, in3 */
74671 case OP_NotFound: /* jump, in3 */
74672 case OP_Found: { /* jump, in3 */
74673 int alreadyExists;
74674 int takeJump;
74675 int ii;
74676 VdbeCursor *pC;
74677 int res;
74678 char *pFree;
74679 UnpackedRecord *pIdxKey;
@@ -74524,11 +74692,11 @@
74692 pC->seekOp = pOp->opcode;
74693 #endif
74694 pIn3 = &aMem[pOp->p3];
74695 assert( pC->pCursor!=0 );
74696 assert( pC->isTable==0 );
74697 pFree = 0;
74698 if( pOp->p4.i>0 ){
74699 r.pKeyInfo = pC->pKeyInfo;
74700 r.nField = (u16)pOp->p4.i;
74701 r.aMem = pIn3;
74702 for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74715,24 @@
74715 assert( pIn3->flags & MEM_Blob );
74716 ExpandBlob(pIn3);
74717 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
74718 }
74719 pIdxKey->default_rc = 0;
74720 takeJump = 0;
74721 if( pOp->opcode==OP_NoConflict ){
74722 /* For the OP_NoConflict opcode, take the jump if any of the
74723 ** input fields are NULL, since any key with a NULL will not
74724 ** conflict */
74725 for(ii=0; ii<pIdxKey->nField; ii++){
74726 if( pIdxKey->aMem[ii].flags & MEM_Null ){
74727 takeJump = 1;
74728 break;
74729 }
74730 }
74731 }
74732 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74733 sqlite3DbFree(db, pFree);
 
 
74734 if( rc!=SQLITE_OK ){
74735 break;
74736 }
74737 pC->seekResult = res;
74738 alreadyExists = (res==0);
@@ -74572,14 +74739,14 @@
74739 pC->nullRow = 1-alreadyExists;
74740 pC->deferredMoveto = 0;
74741 pC->cacheStatus = CACHE_STALE;
74742 if( pOp->opcode==OP_Found ){
74743 VdbeBranchTaken(alreadyExists!=0,2);
74744 if( alreadyExists ) goto jump_to_p2;
74745 }else{
74746 VdbeBranchTaken(takeJump||alreadyExists==0,2);
74747 if( takeJump || !alreadyExists ) goto jump_to_p2;
74748 }
74749 break;
74750 }
74751
74752 /* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74791,12 @@
74791 pC->movetoTarget = iKey; /* Used by OP_Delete */
74792 pC->nullRow = 0;
74793 pC->cacheStatus = CACHE_STALE;
74794 pC->deferredMoveto = 0;
74795 VdbeBranchTaken(res!=0,2);
 
 
 
74796 pC->seekResult = res;
74797 if( res!=0 ) goto jump_to_p2;
74798 break;
74799 }
74800
74801 /* Opcode: Sequence P1 P2 * * *
74802 ** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74804,14 @@
74804 ** Find the next available sequence number for cursor P1.
74805 ** Write the sequence number into register P2.
74806 ** The sequence number on the cursor is incremented after this
74807 ** instruction.
74808 */
74809 case OP_Sequence: { /* out2 */
74810 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74811 assert( p->apCsr[pOp->p1]!=0 );
74812 pOut = out2Prerelease(p, pOp);
74813 pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
74814 break;
74815 }
74816
74817
@@ -74662,20 +74828,21 @@
74828 ** allowed to be less than this value. When this value reaches its maximum,
74829 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
74830 ** generated record number. This P3 mechanism is used to help implement the
74831 ** AUTOINCREMENT feature.
74832 */
74833 case OP_NewRowid: { /* out2 */
74834 i64 v; /* The new rowid */
74835 VdbeCursor *pC; /* Cursor of table to get the new rowid */
74836 int res; /* Result of an sqlite3BtreeLast() */
74837 int cnt; /* Counter to limit the number of searches */
74838 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
74839 VdbeFrame *pFrame; /* Root frame of VDBE */
74840
74841 v = 0;
74842 res = 0;
74843 pOut = out2Prerelease(p, pOp);
74844 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74845 pC = p->apCsr[pOp->p1];
74846 assert( pC!=0 );
74847 if( NEVER(pC->pCursor==0) ){
74848 /* The zero initialization above is all that is needed */
@@ -74985,13 +75152,11 @@
75152 pIn3 = &aMem[pOp->p3];
75153 nKeyCol = pOp->p4.i;
75154 res = 0;
75155 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
75156 VdbeBranchTaken(res!=0,2);
75157 if( res ) goto jump_to_p2;
 
 
75158 break;
75159 };
75160
75161 /* Opcode: SorterData P1 P2 P3 * *
75162 ** Synopsis: r[P2]=data
@@ -75116,16 +75281,17 @@
75281 **
75282 ** P1 can be either an ordinary table or a virtual table. There used to
75283 ** be a separate OP_VRowid opcode for use with virtual tables, but this
75284 ** one opcode now works for both table types.
75285 */
75286 case OP_Rowid: { /* out2 */
75287 VdbeCursor *pC;
75288 i64 v;
75289 sqlite3_vtab *pVtab;
75290 const sqlite3_module *pModule;
75291
75292 pOut = out2Prerelease(p, pOp);
75293 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75294 pC = p->apCsr[pOp->p1];
75295 assert( pC!=0 );
75296 assert( pC->pseudoTableReg==0 || pC->nullRow );
75297 if( pC->nullRow ){
@@ -75174,11 +75340,11 @@
75340 sqlite3BtreeClearCursor(pC->pCursor);
75341 }
75342 break;
75343 }
75344
75345 /* Opcode: Last P1 P2 P3 * *
75346 **
75347 ** The next use of the Rowid or Column or Prev instruction for P1
75348 ** will refer to the last entry in the database table or index.
75349 ** If the table or index is empty and P2>0, then jump immediately to P2.
75350 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75367,17 @@
75367 assert( pCrsr!=0 );
75368 rc = sqlite3BtreeLast(pCrsr, &res);
75369 pC->nullRow = (u8)res;
75370 pC->deferredMoveto = 0;
75371 pC->cacheStatus = CACHE_STALE;
75372 pC->seekResult = pOp->p3;
75373 #ifdef SQLITE_DEBUG
75374 pC->seekOp = OP_Last;
75375 #endif
75376 if( pOp->p2>0 ){
75377 VdbeBranchTaken(res!=0,2);
75378 if( res ) goto jump_to_p2;
75379 }
75380 break;
75381 }
75382
75383
@@ -75270,13 +75437,11 @@
75437 pC->cacheStatus = CACHE_STALE;
75438 }
75439 pC->nullRow = (u8)res;
75440 assert( pOp->p2>0 && pOp->p2<p->nOp );
75441 VdbeBranchTaken(res!=0,2);
75442 if( res ) goto jump_to_p2;
 
 
75443 break;
75444 }
75445
75446 /* Opcode: Next P1 P2 P3 P4 P5
75447 **
@@ -75383,15 +75548,15 @@
75548 next_tail:
75549 pC->cacheStatus = CACHE_STALE;
75550 VdbeBranchTaken(res==0,2);
75551 if( res==0 ){
75552 pC->nullRow = 0;
 
75553 p->aCounter[pOp->p5]++;
75554 #ifdef SQLITE_TEST
75555 sqlite3_search_count++;
75556 #endif
75557 goto jump_to_p2_and_check_for_interrupt;
75558 }else{
75559 pC->nullRow = 1;
75560 }
75561 goto check_for_interrupt;
75562 }
@@ -75495,15 +75660,16 @@
75660 ** the end of the index key pointed to by cursor P1. This integer should be
75661 ** the rowid of the table entry to which this index entry points.
75662 **
75663 ** See also: Rowid, MakeRecord.
75664 */
75665 case OP_IdxRowid: { /* out2 */
75666 BtCursor *pCrsr;
75667 VdbeCursor *pC;
75668 i64 rowid;
75669
75670 pOut = out2Prerelease(p, pOp);
75671 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75672 pC = p->apCsr[pOp->p1];
75673 assert( pC!=0 );
75674 pCrsr = pC->pCursor;
75675 assert( pCrsr!=0 );
@@ -75612,13 +75778,11 @@
75778 }else{
75779 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
75780 res++;
75781 }
75782 VdbeBranchTaken(res>0,2);
75783 if( res>0 ) goto jump_to_p2;
 
 
75784 break;
75785 }
75786
75787 /* Opcode: Destroy P1 P2 P3 * *
75788 **
@@ -75638,15 +75802,16 @@
75802 ** the last one in the database) then a zero is stored in register P2.
75803 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
75804 **
75805 ** See also: Clear
75806 */
75807 case OP_Destroy: { /* out2 */
75808 int iMoved;
75809 int iDb;
75810
75811 assert( p->readOnly==0 );
75812 pOut = out2Prerelease(p, pOp);
75813 pOut->flags = MEM_Null;
75814 if( db->nVdbeRead > db->nVDestroy+1 ){
75815 rc = SQLITE_LOCKED;
75816 p->errorAction = OE_Abort;
75817 }else{
@@ -75751,16 +75916,17 @@
75916 ** P1>1. Write the root page number of the new table into
75917 ** register P2.
75918 **
75919 ** See documentation on OP_CreateTable for additional information.
75920 */
75921 case OP_CreateIndex: /* out2 */
75922 case OP_CreateTable: { /* out2 */
75923 int pgno;
75924 int flags;
75925 Db *pDb;
75926
75927 pOut = out2Prerelease(p, pOp);
75928 pgno = 0;
75929 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75930 assert( DbMaskTest(p->btreeMask, pOp->p1) );
75931 assert( p->readOnly==0 );
75932 pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76148,16 @@
76148 if( (pIn1->flags & MEM_RowSet)==0
76149 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
76150 ){
76151 /* The boolean index is empty */
76152 sqlite3VdbeMemSetNull(pIn1);
 
76153 VdbeBranchTaken(1,2);
76154 goto jump_to_p2_and_check_for_interrupt;
76155 }else{
76156 /* A value was pulled from the index */
 
76157 VdbeBranchTaken(0,2);
76158 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
76159 }
76160 goto check_for_interrupt;
76161 }
76162
76163 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76204,11 @@
76204 assert( pOp->p4type==P4_INT32 );
76205 assert( iSet==-1 || iSet>=0 );
76206 if( iSet ){
76207 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
76208 VdbeBranchTaken(exists!=0,2);
76209 if( exists ) goto jump_to_p2;
 
 
 
76210 }
76211 if( iSet>=0 ){
76212 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
76213 }
76214 break;
@@ -76130,11 +76293,11 @@
76293 pRt->u.pFrame = pFrame;
76294
76295 pFrame->v = p;
76296 pFrame->nChildMem = nMem;
76297 pFrame->nChildCsr = pProgram->nCsr;
76298 pFrame->pc = (int)(pOp - aOp);
76299 pFrame->aMem = p->aMem;
76300 pFrame->nMem = p->nMem;
76301 pFrame->apCsr = p->apCsr;
76302 pFrame->nCursor = p->nCursor;
76303 pFrame->aOp = p->aOp;
@@ -76153,11 +76316,11 @@
76316 }
76317 }else{
76318 pFrame = pRt->u.pFrame;
76319 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
76320 assert( pProgram->nCsr==pFrame->nChildCsr );
76321 assert( (int)(pOp - aOp)==pFrame->pc );
76322 }
76323
76324 p->nFrame++;
76325 pFrame->pParent = p->pFrame;
76326 pFrame->lastRowid = lastRowid;
@@ -76174,11 +76337,11 @@
76337 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
76338 p->nOnceFlag = pProgram->nOnce;
76339 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
76340 p->anExec = 0;
76341 #endif
76342 pOp = &aOp[-1];
76343 memset(p->aOnceFlag, 0, p->nOnceFlag);
76344
76345 break;
76346 }
76347
@@ -76192,13 +76355,14 @@
76355 **
76356 ** The address of the cell in the parent frame is determined by adding
76357 ** the value of the P1 argument to the value of the P1 argument to the
76358 ** calling OP_Program instruction.
76359 */
76360 case OP_Param: { /* out2 */
76361 VdbeFrame *pFrame;
76362 Mem *pIn;
76363 pOut = out2Prerelease(p, pOp);
76364 pFrame = p->pFrame;
76365 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
76366 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
76367 break;
76368 }
@@ -76238,14 +76402,14 @@
76402 ** (immediate foreign key constraint violations).
76403 */
76404 case OP_FkIfZero: { /* jump */
76405 if( pOp->p1 ){
76406 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76407 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
76408 }else{
76409 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76410 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
76411 }
76412 break;
76413 }
76414 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
76415
@@ -76292,13 +76456,11 @@
76456 */
76457 case OP_IfPos: { /* jump, in1 */
76458 pIn1 = &aMem[pOp->p1];
76459 assert( pIn1->flags&MEM_Int );
76460 VdbeBranchTaken( pIn1->u.i>0, 2);
76461 if( pIn1->u.i>0 ) goto jump_to_p2;
 
 
76462 break;
76463 }
76464
76465 /* Opcode: IfNeg P1 P2 P3 * *
76466 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76471,11 @@
76471 case OP_IfNeg: { /* jump, in1 */
76472 pIn1 = &aMem[pOp->p1];
76473 assert( pIn1->flags&MEM_Int );
76474 pIn1->u.i += pOp->p3;
76475 VdbeBranchTaken(pIn1->u.i<0, 2);
76476 if( pIn1->u.i<0 ) goto jump_to_p2;
 
 
76477 break;
76478 }
76479
76480 /* Opcode: IfNotZero P1 P2 P3 * *
76481 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76488,11 @@
76488 pIn1 = &aMem[pOp->p1];
76489 assert( pIn1->flags&MEM_Int );
76490 VdbeBranchTaken(pIn1->u.i<0, 2);
76491 if( pIn1->u.i ){
76492 pIn1->u.i += pOp->p3;
76493 goto jump_to_p2;
76494 }
76495 break;
76496 }
76497
76498 /* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76504,11 @@
76504 case OP_DecrJumpZero: { /* jump, in1 */
76505 pIn1 = &aMem[pOp->p1];
76506 assert( pIn1->flags&MEM_Int );
76507 pIn1->u.i--;
76508 VdbeBranchTaken(pIn1->u.i==0, 2);
76509 if( pIn1->u.i==0 ) goto jump_to_p2;
 
 
76510 break;
76511 }
76512
76513
76514 /* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76520,11 @@
76520 */
76521 case OP_JumpZeroIncr: { /* jump, in1 */
76522 pIn1 = &aMem[pOp->p1];
76523 assert( pIn1->flags&MEM_Int );
76524 VdbeBranchTaken(pIn1->u.i==0, 2);
76525 if( (pIn1->u.i++)==0 ) goto jump_to_p2;
 
 
76526 break;
76527 }
76528
76529 /* Opcode: AggStep * P2 P3 P4 P5
76530 ** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76562,11 @@
76562 pMem->n++;
76563 sqlite3VdbeMemInit(&t, db, MEM_Null);
76564 ctx.pOut = &t;
76565 ctx.isError = 0;
76566 ctx.pVdbe = p;
76567 ctx.iOp = (int)(pOp - aOp);
76568 ctx.skipFlag = 0;
76569 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
76570 if( ctx.isError ){
76571 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
76572 rc = ctx.isError;
@@ -76501,19 +76657,20 @@
76657 **
76658 ** If changing into or out of WAL mode the procedure is more complicated.
76659 **
76660 ** Write a string containing the final journal-mode to register P2.
76661 */
76662 case OP_JournalMode: { /* out2 */
76663 Btree *pBt; /* Btree to change journal mode of */
76664 Pager *pPager; /* Pager associated with pBt */
76665 int eNew; /* New journal mode */
76666 int eOld; /* The old journal mode */
76667 #ifndef SQLITE_OMIT_WAL
76668 const char *zFilename; /* Name of database file for pPager */
76669 #endif
76670
76671 pOut = out2Prerelease(p, pOp);
76672 eNew = pOp->p3;
76673 assert( eNew==PAGER_JOURNALMODE_DELETE
76674 || eNew==PAGER_JOURNALMODE_TRUNCATE
76675 || eNew==PAGER_JOURNALMODE_PERSIST
76676 || eNew==PAGER_JOURNALMODE_OFF
@@ -76626,12 +76783,12 @@
76783 assert( p->readOnly==0 );
76784 pBt = db->aDb[pOp->p1].pBt;
76785 rc = sqlite3BtreeIncrVacuum(pBt);
76786 VdbeBranchTaken(rc==SQLITE_DONE,2);
76787 if( rc==SQLITE_DONE ){
 
76788 rc = SQLITE_OK;
76789 goto jump_to_p2;
76790 }
76791 break;
76792 }
76793 #endif
76794
@@ -76780,12 +76937,13 @@
76937 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76938 if( pCur ){
76939 pCur->pVtabCursor = pVtabCursor;
76940 pVtab->nRef++;
76941 }else{
76942 assert( db->mallocFailed );
76943 pModule->xClose(pVtabCursor);
76944 goto no_mem;
76945 }
76946 }
76947 break;
76948 }
76949 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76995,23 @@
76995 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
76996 nArg = (int)pArgc->u.i;
76997 iQuery = (int)pQuery->u.i;
76998
76999 /* Invoke the xFilter method */
77000 res = 0;
77001 apArg = p->apArg;
77002 for(i = 0; i<nArg; i++){
77003 apArg[i] = &pArgc[i+1];
77004 }
77005 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
77006 sqlite3VtabImportErrmsg(p, pVtab);
77007 if( rc==SQLITE_OK ){
77008 res = pModule->xEof(pVtabCursor);
 
 
 
 
 
 
 
77009 }
77010 pCur->nullRow = 0;
77011 VdbeBranchTaken(res!=0,2);
77012 if( res ) goto jump_to_p2;
77013 break;
77014 }
77015 #endif /* SQLITE_OMIT_VIRTUALTABLE */
77016
77017 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77094,11 @@
77094 res = pModule->xEof(pCur->pVtabCursor);
77095 }
77096 VdbeBranchTaken(!res,2);
77097 if( !res ){
77098 /* If there is data, jump to P2 */
77099 goto jump_to_p2_and_check_for_interrupt;
77100 }
77101 goto check_for_interrupt;
77102 }
77103 #endif /* SQLITE_OMIT_VIRTUALTABLE */
77104
@@ -77065,11 +77217,12 @@
77217 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
77218 /* Opcode: Pagecount P1 P2 * * *
77219 **
77220 ** Write the current number of pages in database P1 to memory cell P2.
77221 */
77222 case OP_Pagecount: { /* out2 */
77223 pOut = out2Prerelease(p, pOp);
77224 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
77225 break;
77226 }
77227 #endif
77228
@@ -77081,14 +77234,15 @@
77234 ** Do not let the maximum page count fall below the current page count and
77235 ** do not change the maximum page count value if P3==0.
77236 **
77237 ** Store the maximum page count after the change in register P2.
77238 */
77239 case OP_MaxPgcnt: { /* out2 */
77240 unsigned int newMax;
77241 Btree *pBt;
77242
77243 pOut = out2Prerelease(p, pOp);
77244 pBt = db->aDb[pOp->p1].pBt;
77245 newMax = 0;
77246 if( pOp->p3 ){
77247 newMax = sqlite3BtreeLastPage(pBt);
77248 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77267,10 @@
77267 */
77268 case OP_Init: { /* jump */
77269 char *zTrace;
77270 char *z;
77271
 
 
 
77272 #ifndef SQLITE_OMIT_TRACE
77273 if( db->xTrace
77274 && !p->doingRerun
77275 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
77276 ){
@@ -77143,10 +77294,11 @@
77294 ){
77295 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
77296 }
77297 #endif /* SQLITE_DEBUG */
77298 #endif /* SQLITE_OMIT_TRACE */
77299 if( pOp->p2 ) goto jump_to_p2;
77300 break;
77301 }
77302
77303
77304 /* Opcode: Noop * * * * *
@@ -77174,31 +77326,31 @@
77326 }
77327
77328 #ifdef VDBE_PROFILE
77329 {
77330 u64 endTime = sqlite3Hwtime();
77331 if( endTime>start ) pOrigOp->cycles += endTime - start;
77332 pOrigOp->cnt++;
77333 }
77334 #endif
77335
77336 /* The following code adds nothing to the actual functionality
77337 ** of the program. It is only here for testing and debugging.
77338 ** On the other hand, it does burn CPU cycles every time through
77339 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
77340 */
77341 #ifndef NDEBUG
77342 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
77343
77344 #ifdef SQLITE_DEBUG
77345 if( db->flags & SQLITE_VdbeTrace ){
77346 if( rc!=0 ) printf("rc=%d\n",rc);
77347 if( pOrigOp->opflags & (OPFLG_OUT2) ){
77348 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
77349 }
77350 if( pOrigOp->opflags & OPFLG_OUT3 ){
77351 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
77352 }
77353 }
77354 #endif /* SQLITE_DEBUG */
77355 #endif /* NDEBUG */
77356 } /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77361,11 @@
77361 vdbe_error_halt:
77362 assert( rc );
77363 p->rc = rc;
77364 testcase( sqlite3GlobalConfig.xLog!=0 );
77365 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77366 (int)(pOp - aOp), p->zSql, p->zErrMsg);
77367 sqlite3VdbeHalt(p);
77368 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
77369 rc = SQLITE_ERROR;
77370 if( resetSchemaOnFault>0 ){
77371 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78187,23 @@
78187 **
78188 ** In both cases, the effects of the main thread seeing (bDone==0) even
78189 ** after the thread has finished are not dire. So we don't worry about
78190 ** memory barriers and such here.
78191 */
78192 typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int);
78193 struct SortSubtask {
78194 SQLiteThread *pThread; /* Background thread, if any */
78195 int bDone; /* Set if thread is finished but not joined */
78196 VdbeSorter *pSorter; /* Sorter that owns this sub-task */
78197 UnpackedRecord *pUnpacked; /* Space to unpack a record */
78198 SorterList list; /* List for thread to write to a PMA */
78199 int nPMA; /* Number of PMAs currently in file */
78200 SorterCompare xCompare; /* Compare function to use */
78201 SorterFile file; /* Temp file for level-0 PMAs */
78202 SorterFile file2; /* Space for other PMAs */
78203 };
78204
78205
78206 /*
78207 ** Main sorter structure. A single instance of this is allocated for each
78208 ** sorter cursor created by the VDBE.
78209 **
@@ -78072,12 +78227,16 @@
78227 int nMemory; /* Size of list.aMemory allocation in bytes */
78228 u8 bUsePMA; /* True if one or more PMAs created */
78229 u8 bUseThreads; /* True to use background threads */
78230 u8 iPrev; /* Previous thread used to flush PMA */
78231 u8 nTask; /* Size of aTask[] array */
78232 u8 typeMask;
78233 SortSubtask aTask[1]; /* One or more subtasks */
78234 };
78235
78236 #define SORTER_TYPE_INTEGER 0x01
78237 #define SORTER_TYPE_TEXT 0x02
78238
78239 /*
78240 ** An instance of the following object is used to read records out of a
78241 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
78242 ** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78645,165 @@
78645 rc = vdbePmaReaderNext(pReadr);
78646 }
78647 return rc;
78648 }
78649
78650 /*
78651 ** A version of vdbeSorterCompare() that assumes that it has already been
78652 ** determined that the first field of key1 is equal to the first field of
78653 ** key2.
78654 */
78655 static int vdbeSorterCompareTail(
78656 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78657 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78658 const void *pKey1, int nKey1, /* Left side of comparison */
78659 const void *pKey2, int nKey2 /* Right side of comparison */
78660 ){
78661 UnpackedRecord *r2 = pTask->pUnpacked;
78662 if( *pbKey2Cached==0 ){
78663 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78664 *pbKey2Cached = 1;
78665 }
78666 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
78667 }
78668
78669 /*
78670 ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
78671 ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
78672 ** used by the comparison. Return the result of the comparison.
78673 **
78674 ** If IN/OUT parameter *pbKey2Cached is true when this function is called,
78675 ** it is assumed that (pTask->pUnpacked) contains the unpacked version
78676 ** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
78677 ** version of key2 and *pbKey2Cached set to true before returning.
78678 **
78679 ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
78680 ** to SQLITE_NOMEM.
78681 */
78682 static int vdbeSorterCompare(
78683 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78684 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78685 const void *pKey1, int nKey1, /* Left side of comparison */
78686 const void *pKey2, int nKey2 /* Right side of comparison */
78687 ){
78688 UnpackedRecord *r2 = pTask->pUnpacked;
78689 if( !*pbKey2Cached ){
78690 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78691 *pbKey2Cached = 1;
78692 }
78693 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
78694 }
78695
78696 /*
78697 ** A specially optimized version of vdbeSorterCompare() that assumes that
78698 ** the first field of each key is a TEXT value and that the collation
78699 ** sequence to compare them with is BINARY.
78700 */
78701 static int vdbeSorterCompareText(
78702 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78703 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78704 const void *pKey1, int nKey1, /* Left side of comparison */
78705 const void *pKey2, int nKey2 /* Right side of comparison */
78706 ){
78707 const u8 * const p1 = (const u8 * const)pKey1;
78708 const u8 * const p2 = (const u8 * const)pKey2;
78709 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78710 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78711
78712 int n1;
78713 int n2;
78714 int res;
78715
78716 getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2;
78717 getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2;
78718 res = memcmp(v1, v2, MIN(n1, n2));
78719 if( res==0 ){
78720 res = n1 - n2;
78721 }
78722
78723 if( res==0 ){
78724 if( pTask->pSorter->pKeyInfo->nField>1 ){
78725 res = vdbeSorterCompareTail(
78726 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78727 );
78728 }
78729 }else{
78730 if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78731 res = res * -1;
78732 }
78733 }
78734
78735 return res;
78736 }
78737
78738 /*
78739 ** A specially optimized version of vdbeSorterCompare() that assumes that
78740 ** the first field of each key is an INTEGER value.
78741 */
78742 static int vdbeSorterCompareInt(
78743 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78744 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78745 const void *pKey1, int nKey1, /* Left side of comparison */
78746 const void *pKey2, int nKey2 /* Right side of comparison */
78747 ){
78748 const u8 * const p1 = (const u8 * const)pKey1;
78749 const u8 * const p2 = (const u8 * const)pKey2;
78750 const int s1 = p1[1]; /* Left hand serial type */
78751 const int s2 = p2[1]; /* Right hand serial type */
78752 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78753 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78754 int res; /* Return value */
78755
78756 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
78757 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
78758
78759 if( s1>7 && s2>7 ){
78760 res = s1 - s2;
78761 }else{
78762 if( s1==s2 ){
78763 if( (*v1 ^ *v2) & 0x80 ){
78764 /* The two values have different signs */
78765 res = (*v1 & 0x80) ? -1 : +1;
78766 }else{
78767 /* The two values have the same sign. Compare using memcmp(). */
78768 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
78769 int i;
78770 res = 0;
78771 for(i=0; i<aLen[s1]; i++){
78772 if( (res = v1[i] - v2[i]) ) break;
78773 }
78774 }
78775 }else{
78776 if( s2>7 ){
78777 res = +1;
78778 }else if( s1>7 ){
78779 res = -1;
78780 }else{
78781 res = s1 - s2;
78782 }
78783 assert( res!=0 );
78784
78785 if( res>0 ){
78786 if( *v1 & 0x80 ) res = -1;
78787 }else{
78788 if( *v2 & 0x80 ) res = +1;
78789 }
78790 }
78791 }
78792
78793 if( res==0 ){
78794 if( pTask->pSorter->pKeyInfo->nField>1 ){
78795 res = vdbeSorterCompareTail(
78796 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78797 );
78798 }
78799 }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78800 res = res * -1;
78801 }
78802
78803 return res;
78804 }
78805
78806 /*
78807 ** Initialize the temporary index cursor just opened as a sorter cursor.
78808 **
78809 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78868,17 @@
78868 rc = SQLITE_NOMEM;
78869 }else{
78870 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
78871 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
78872 pKeyInfo->db = 0;
78873 if( nField && nWorker==0 ){
78874 pKeyInfo->nXField += (pKeyInfo->nField - nField);
78875 pKeyInfo->nField = nField;
78876 }
78877 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
78878 pSorter->nTask = nWorker + 1;
78879 pSorter->iPrev = nWorker-1;
78880 pSorter->bUseThreads = (pSorter->nTask>1);
78881 pSorter->db = db;
78882 for(i=0; i<pSorter->nTask; i++){
78883 SortSubtask *pTask = &pSorter->aTask[i];
78884 pTask->pSorter = pSorter;
@@ -78607,10 +78900,16 @@
78900 pSorter->nMemory = pgsz;
78901 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
78902 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
78903 }
78904 }
78905
78906 if( (pKeyInfo->nField+pKeyInfo->nXField)<13
78907 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
78908 ){
78909 pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
78910 }
78911 }
78912
78913 return rc;
78914 }
78915 #undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78930,28 @@
78930 ** Free all resources owned by the object indicated by argument pTask. All
78931 ** fields of *pTask are zeroed before returning.
78932 */
78933 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
78934 sqlite3DbFree(db, pTask->pUnpacked);
 
78935 #if SQLITE_MAX_WORKER_THREADS>0
78936 /* pTask->list.aMemory can only be non-zero if it was handed memory
78937 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
78938 if( pTask->list.aMemory ){
78939 sqlite3_free(pTask->list.aMemory);
 
78940 }else
78941 #endif
78942 {
78943 assert( pTask->list.aMemory==0 );
78944 vdbeSorterRecordFree(0, pTask->list.pList);
78945 }
 
78946 if( pTask->file.pFd ){
78947 sqlite3OsCloseFree(pTask->file.pFd);
 
 
78948 }
78949 if( pTask->file2.pFd ){
78950 sqlite3OsCloseFree(pTask->file2.pFd);
 
 
78951 }
78952 memset(pTask, 0, sizeof(SortSubtask));
78953 }
78954
78955 #ifdef SQLITE_DEBUG_SORTER_THREADS
78956 static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
78957 i64 t;
@@ -78834,10 +79127,11 @@
79127 vdbeMergeEngineFree(pSorter->pMerger);
79128 pSorter->pMerger = 0;
79129 for(i=0; i<pSorter->nTask; i++){
79130 SortSubtask *pTask = &pSorter->aTask[i];
79131 vdbeSortSubtaskCleanup(db, pTask);
79132 pTask->pSorter = pSorter;
79133 }
79134 if( pSorter->list.aMemory==0 ){
79135 vdbeSorterRecordFree(0, pSorter->list.pList);
79136 }
79137 pSorter->list.pList = 0;
@@ -78943,31 +79237,45 @@
79237 SorterRecord *p2, /* Second list to merge */
79238 SorterRecord **ppOut /* OUT: Head of merged list */
79239 ){
79240 SorterRecord *pFinal = 0;
79241 SorterRecord **pp = &pFinal;
79242 int bCached = 0;
79243
79244 while( p1 && p2 ){
79245 int res;
79246 res = pTask->xCompare(
79247 pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
79248 );
79249
79250 if( res<=0 ){
79251 *pp = p1;
79252 pp = &p1->u.pNext;
79253 p1 = p1->u.pNext;
 
79254 }else{
79255 *pp = p2;
79256 pp = &p2->u.pNext;
79257 p2 = p2->u.pNext;
79258 bCached = 0;
 
79259 }
79260 }
79261 *pp = p1 ? p1 : p2;
79262 *ppOut = pFinal;
79263 }
79264
79265 /*
79266 ** Return the SorterCompare function to compare values collected by the
79267 ** sorter object passed as the only argument.
79268 */
79269 static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){
79270 if( p->typeMask==SORTER_TYPE_INTEGER ){
79271 return vdbeSorterCompareInt;
79272 }else if( p->typeMask==SORTER_TYPE_TEXT ){
79273 return vdbeSorterCompareText;
79274 }
79275 return vdbeSorterCompare;
79276 }
79277
79278 /*
79279 ** Sort the linked list of records headed at pTask->pList. Return
79280 ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
79281 ** an error occurs.
@@ -78979,16 +79287,18 @@
79287 int rc;
79288
79289 rc = vdbeSortAllocUnpacked(pTask);
79290 if( rc!=SQLITE_OK ) return rc;
79291
79292 p = pList->pList;
79293 pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
79294
79295 aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
79296 if( !aSlot ){
79297 return SQLITE_NOMEM;
79298 }
79299
 
79300 while( p ){
79301 SorterRecord *pNext;
79302 if( pList->aMemory ){
79303 if( (u8*)p==pList->aMemory ){
79304 pNext = 0;
@@ -79198,28 +79508,27 @@
79508 /* Update contents of aTree[] */
79509 if( rc==SQLITE_OK ){
79510 int i; /* Index of aTree[] to recalculate */
79511 PmaReader *pReadr1; /* First PmaReader to compare */
79512 PmaReader *pReadr2; /* Second PmaReader to compare */
79513 int bCached = 0;
79514
79515 /* Find the first two PmaReaders to compare. The one that was just
79516 ** advanced (iPrev) and the one next to it in the array. */
79517 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
79518 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
 
79519
79520 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
79521 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
79522 int iRes;
79523 if( pReadr1->pFd==0 ){
79524 iRes = +1;
79525 }else if( pReadr2->pFd==0 ){
79526 iRes = -1;
79527 }else{
79528 iRes = pTask->xCompare(pTask, &bCached,
79529 pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
79530 );
79531 }
79532
79533 /* If pReadr1 contained the smaller value, set aTree[i] to its index.
79534 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79546,13 @@
79546 ** is sorted from oldest to newest, so pReadr1 contains older values
79547 ** than pReadr2 iff (pReadr1<pReadr2). */
79548 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
79549 pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
79550 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79551 bCached = 0;
79552 }else{
79553 if( pReadr1->pFd ) bCached = 0;
79554 pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
79555 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79556 }
79557 }
79558 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79655,20 @@
79655 SorterRecord *pNew; /* New list element */
79656
79657 int bFlush; /* True to flush contents of memory to PMA */
79658 int nReq; /* Bytes of memory required */
79659 int nPMA; /* Bytes of PMA space required */
79660 int t; /* serial type of first record field */
79661
79662 getVarint32((const u8*)&pVal->z[1], t);
79663 if( t>0 && t<10 && t!=7 ){
79664 pSorter->typeMask &= SORTER_TYPE_INTEGER;
79665 }else if( t>10 && (t & 0x01) ){
79666 pSorter->typeMask &= SORTER_TYPE_TEXT;
79667 }else{
79668 pSorter->typeMask = 0;
79669 }
79670
79671 assert( pSorter );
79672
79673 /* Figure out whether or not the current contents of memory should be
79674 ** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79930,16 @@
79930 if( p1->pFd==0 ){
79931 iRes = i2;
79932 }else if( p2->pFd==0 ){
79933 iRes = i1;
79934 }else{
79935 SortSubtask *pTask = pMerger->pTask;
79936 int bCached = 0;
79937 int res;
79938 assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79939 res = pTask->xCompare(
79940 pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79941 );
79942 if( res<=0 ){
79943 iRes = i1;
79944 }else{
79945 iRes = i2;
@@ -79638,15 +79959,16 @@
79959 */
79960 #define INCRINIT_NORMAL 0
79961 #define INCRINIT_TASK 1
79962 #define INCRINIT_ROOT 2
79963
79964 /*
79965 ** Forward reference required as the vdbeIncrMergeInit() and
79966 ** vdbePmaReaderIncrInit() routines are called mutually recursively when
79967 ** building a merge tree.
79968 */
79969 static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode);
79970
79971 /*
79972 ** Initialize the MergeEngine object passed as the second argument. Once this
79973 ** function returns, the first key of merged data may be read from the
79974 ** MergeEngine object in the usual fashion.
@@ -79689,11 +80011,11 @@
80011 ** the main thread to fill its buffer. So calling PmaReaderNext()
80012 ** on this PmaReader before any of the multi-threaded PmaReaders takes
80013 ** better advantage of multi-processor hardware. */
80014 rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
80015 }else{
80016 rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
80017 }
80018 if( rc!=SQLITE_OK ) return rc;
80019 }
80020
80021 for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80023,19 @@
80023 }
80024 return pTask->pUnpacked->errCode;
80025 }
80026
80027 /*
80028 ** The PmaReader passed as the first argument is guaranteed to be an
80029 ** incremental-reader (pReadr->pIncr!=0). This function serves to open
80030 ** and/or initialize the temp file related fields of the IncrMerge
 
 
80031 ** object at (pReadr->pIncr).
80032 **
80033 ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
80034 ** in the sub-tree headed by pReadr are also initialized. Data is then
80035 ** loaded into the buffers belonging to pReadr and it is set to point to
80036 ** the first key in its range.
80037 **
80038 ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
80039 ** to be a multi-threaded PmaReader and this function is being called in a
80040 ** background thread. In this case all PmaReaders in the sub-tree are
80041 ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80058,112 @@
80058 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
80059 */
80060 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
80061 int rc = SQLITE_OK;
80062 IncrMerger *pIncr = pReadr->pIncr;
80063 SortSubtask *pTask = pIncr->pTask;
80064 sqlite3 *db = pTask->pSorter->db;
80065
80066 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
80067 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
80068
80069 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
80070
80071 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
80072 ** requires two temp files to itself, whereas a single-threaded object
80073 ** only requires a region of pTask->file2. */
80074 if( rc==SQLITE_OK ){
80075 int mxSz = pIncr->mxSz;
80076 #if SQLITE_MAX_WORKER_THREADS>0
80077 if( pIncr->bUseThread ){
80078 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
80079 if( rc==SQLITE_OK ){
80080 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
80081 }
80082 }else
80083 #endif
80084 /*if( !pIncr->bUseThread )*/{
80085 if( pTask->file2.pFd==0 ){
80086 assert( pTask->file2.iEof>0 );
80087 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
80088 pTask->file2.iEof = 0;
80089 }
80090 if( rc==SQLITE_OK ){
80091 pIncr->aFile[1].pFd = pTask->file2.pFd;
80092 pIncr->iStartOff = pTask->file2.iEof;
80093 pTask->file2.iEof += mxSz;
80094 }
80095 }
80096 }
80097
80098 #if SQLITE_MAX_WORKER_THREADS>0
80099 if( rc==SQLITE_OK && pIncr->bUseThread ){
80100 /* Use the current thread to populate aFile[1], even though this
80101 ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
80102 ** then this function is already running in background thread
80103 ** pIncr->pTask->thread.
80104 **
80105 ** If this is the INCRINIT_ROOT object, then it is running in the
80106 ** main VDBE thread. But that is Ok, as that thread cannot return
80107 ** control to the VDBE or proceed with anything useful until the
80108 ** first results are ready from this merger object anyway.
80109 */
80110 assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
80111 rc = vdbeIncrPopulate(pIncr);
80112 }
80113 #endif
80114
80115 if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
80116 rc = vdbePmaReaderNext(pReadr);
80117 }
80118
80119 return rc;
80120 }
80121
80122 #if SQLITE_MAX_WORKER_THREADS>0
80123 /*
80124 ** The main routine for vdbePmaReaderIncrMergeInit() operations run in
80125 ** background threads.
80126 */
80127 static void *vdbePmaReaderBgIncrInit(void *pCtx){
80128 PmaReader *pReader = (PmaReader*)pCtx;
80129 void *pRet = SQLITE_INT_TO_PTR(
80130 vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
80131 );
80132 pReader->pIncr->pTask->bDone = 1;
80133 return pRet;
80134 }
80135 #endif
80136
80137 /*
80138 ** If the PmaReader passed as the first argument is not an incremental-reader
80139 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
80140 ** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
80141 ** this routine to initialize the incremental merge.
80142 **
80143 ** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
80144 ** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
80145 ** Or, if the IncrMerger is single threaded, the same function is called
80146 ** using the current thread.
80147 */
80148 static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){
80149 IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */
80150 int rc = SQLITE_OK; /* Return code */
80151 if( pIncr ){
80152 #if SQLITE_MAX_WORKER_THREADS>0
80153 assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
80154 if( pIncr->bUseThread ){
80155 void *pCtx = (void*)pReadr;
80156 rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx);
80157 }else
80158 #endif
80159 {
80160 rc = vdbePmaReaderIncrMergeInit(pReadr, eMode);
80161 }
80162 }
80163 return rc;
80164 }
 
80165
80166 /*
80167 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
80168 ** PMAs from pTask->file. If no error occurs, set *ppOut to point to
80169 ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80371,15 @@
80371 int rc; /* Return code */
80372 SortSubtask *pTask0 = &pSorter->aTask[0];
80373 MergeEngine *pMain = 0;
80374 #if SQLITE_MAX_WORKER_THREADS
80375 sqlite3 *db = pTask0->pSorter->db;
80376 int i;
80377 SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
80378 for(i=0; i<pSorter->nTask; i++){
80379 pSorter->aTask[i].xCompare = xCompare;
80380 }
80381 #endif
80382
80383 rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
80384 if( rc==SQLITE_OK ){
80385 #if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80404,25 @@
80404 vdbeIncrMergerSetThreads(pIncr);
80405 assert( pIncr->pTask!=pLast );
80406 }
80407 }
80408 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
80409 /* Check that:
80410 **
80411 ** a) The incremental merge object is configured to use the
80412 ** right task, and
80413 ** b) If it is using task (nTask-1), it is configured to run
80414 ** in single-threaded mode. This is important, as the
80415 ** root merge (INCRINIT_ROOT) will be using the same task
80416 ** object.
80417 */
80418 PmaReader *p = &pMain->aReadr[iTask];
80419 assert( p->pIncr==0 || (
80420 (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */
80421 && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
80422 ));
80423 rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
 
 
 
80424 }
80425 }
80426 pMain = 0;
80427 }
80428 if( rc==SQLITE_OK ){
@@ -81023,11 +81373,11 @@
81373 ** Should be transformed into:
81374 **
81375 ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
81376 **
81377 ** The nSubquery parameter specifies how many levels of subquery the
81378 ** alias is removed from the original expression. The usual value is
81379 ** zero but it might be more if the alias is contained within a subquery
81380 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
81381 ** structures must be increased by the nSubquery amount.
81382 */
81383 static void resolveAlias(
@@ -81043,11 +81393,11 @@
81393 sqlite3 *db; /* The database connection */
81394
81395 assert( iCol>=0 && iCol<pEList->nExpr );
81396 pOrig = pEList->a[iCol].pExpr;
81397 assert( pOrig!=0 );
81398 assert( (pOrig->flags & EP_Resolved)!=0 || zType[0]==0 );
81399 db = pParse->db;
81400 pDup = sqlite3ExprDup(db, pOrig, 0);
81401 if( pDup==0 ) return;
81402 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
81403 incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82287,15 @@
82287 pNew->flags |= EP_IntValue;
82288 pNew->u.iValue = iCol;
82289 if( pItem->pExpr==pE ){
82290 pItem->pExpr = pNew;
82291 }else{
82292 Expr *pParent = pItem->pExpr;
82293 assert( pParent->op==TK_COLLATE );
82294 while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
82295 assert( pParent->pLeft==pE );
82296 pParent->pLeft = pNew;
82297 }
82298 sqlite3ExprDelete(db, pE);
82299 pItem->u.x.iOrderByCol = (u16)iCol;
82300 pItem->done = 1;
82301 }else{
@@ -82139,11 +82491,11 @@
82491 ** as if it were part of the sub-query, not the parent. This block
82492 ** moves the pOrderBy down to the sub-query. It will be moved back
82493 ** after the names have been resolved. */
82494 if( p->selFlags & SF_Converted ){
82495 Select *pSub = p->pSrc->a[0].pSelect;
82496 assert( p->pSrc->nSrc==1 && p->pOrderBy );
82497 assert( pSub->pPrior && pSub->pOrderBy==0 );
82498 pSub->pOrderBy = p->pOrderBy;
82499 p->pOrderBy = 0;
82500 }
82501
@@ -82241,12 +82593,19 @@
82593
82594 /* Process the ORDER BY clause for singleton SELECT statements.
82595 ** The ORDER BY clause for compounds SELECT statements is handled
82596 ** below, after all of the result-sets for all of the elements of
82597 ** the compound have been resolved.
82598 **
82599 ** If there is an ORDER BY clause on a term of a compound-select other
82600 ** than the right-most term, then that is a syntax error. But the error
82601 ** is not detected until much later, and so we need to go ahead and
82602 ** resolve those symbols on the incorrect ORDER BY for consistency.
82603 */
82604 if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
82605 && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
82606 ){
82607 return WRC_Abort;
82608 }
82609 if( db->mallocFailed ){
82610 return WRC_Abort;
82611 }
@@ -83694,11 +84053,12 @@
84053 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
84054 int i;
84055 u32 m = 0;
84056 if( pList ){
84057 for(i=0; i<pList->nExpr; i++){
84058 Expr *pExpr = pList->a[i].pExpr;
84059 if( ALWAYS(pExpr) ) m |= pList->a[i].pExpr->flags;
84060 }
84061 }
84062 return m;
84063 }
84064
@@ -84134,11 +84494,11 @@
84494 /* Check to see if an existing table or index can be used to
84495 ** satisfy the query. This is preferable to generating a new
84496 ** ephemeral table.
84497 */
84498 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84499 if( pParse->nErr==0 && isCandidateForInOpt(p) ){
84500 sqlite3 *db = pParse->db; /* Database connection */
84501 Table *pTab; /* Table <table>. */
84502 Expr *pExpr; /* Expression <column> */
84503 i16 iCol; /* Index of column <column> */
84504 i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84819,11 @@
84819 }
84820 sqlite3ExprDelete(pParse->db, pSel->pLimit);
84821 pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
84822 &sqlite3IntTokens[1]);
84823 pSel->iLimit = 0;
84824 pSel->selFlags &= ~SF_MultiValue;
84825 if( sqlite3Select(pParse, pSel, &dest) ){
84826 return 0;
84827 }
84828 rReg = dest.iSDParm;
84829 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86185,11 @@
86185 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
86186 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
86187 break;
86188 }
86189 case TK_ID: {
86190 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
86191 break;
86192 }
86193 #ifndef SQLITE_OMIT_CAST
86194 case TK_CAST: {
86195 /* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86820,11 @@
86820 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
86821 if( combinedFlags & EP_xIsSelect ) return 2;
86822 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
86823 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
86824 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86825 if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){
86826 if( pA->iColumn!=pB->iColumn ) return 2;
86827 if( pA->iTable!=pB->iTable
86828 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
86829 }
86830 }
@@ -86991,10 +87352,11 @@
87352 do {
87353 z += n;
87354 n = sqlite3GetToken(z, &token);
87355 }while( token==TK_SPACE );
87356
87357 if( token==TK_ILLEGAL ) break;
87358 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
87359 if( zParent==0 ) break;
87360 sqlite3Dequote(zParent);
87361 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
87362 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89579,21 @@
89579 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
89580 }
89581 z = argv[2];
89582
89583 if( pIndex ){
89584 tRowcnt *aiRowEst = 0;
89585 int nCol = pIndex->nKeyCol+1;
89586 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89587 /* Index.aiRowEst may already be set here if there are duplicate
89588 ** sqlite_stat1 entries for this index. In that case just clobber
89589 ** the old data with the new instead of allocating a new array. */
89590 if( pIndex->aiRowEst==0 ){
89591 pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol);
89592 if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89593 }
89594 aiRowEst = pIndex->aiRowEst;
89595 #endif
89596 pIndex->bUnordered = 0;
89597 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
89598 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
89599 }else{
@@ -89887,11 +90252,11 @@
90252 }
90253
90254 sqlite3BtreeClose(pDb->pBt);
90255 pDb->pBt = 0;
90256 pDb->pSchema = 0;
90257 sqlite3CollapseDatabaseArray(db);
90258 return;
90259
90260 detach_error:
90261 sqlite3_result_error(context, zErr, -1);
90262 }
@@ -89921,11 +90286,10 @@
90286 if(
90287 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
90288 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
90289 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
90290 ){
 
90291 goto attach_end;
90292 }
90293
90294 #ifndef SQLITE_OMIT_AUTHORIZATION
90295 if( pAuthArg ){
@@ -90580,13 +90944,15 @@
90944 sqlite3 *db;
90945 Vdbe *v;
90946
90947 assert( pParse->pToplevel==0 );
90948 db = pParse->db;
 
90949 if( pParse->nested ) return;
90950 if( db->mallocFailed || pParse->nErr ){
90951 if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
90952 return;
90953 }
90954
90955 /* Begin by generating some termination code at the end of the
90956 ** vdbe program
90957 */
90958 v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91030,11 @@
91030 }
91031
91032
91033 /* Get the VDBE program ready for execution
91034 */
91035 if( v && pParse->nErr==0 && !db->mallocFailed ){
91036 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
91037 /* A minimum of one cursor is required if autoincrement is used
91038 * See ticket [a696379c1f08866] */
91039 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
91040 sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91565,16 @@
91565 sqlite3 *db = pParse->db;
91566
91567 if( ALWAYS(pName2!=0) && pName2->n>0 ){
91568 if( db->init.busy ) {
91569 sqlite3ErrorMsg(pParse, "corrupt database");
 
91570 return -1;
91571 }
91572 *pUnqual = pName2;
91573 iDb = sqlite3FindDb(db, pName1);
91574 if( iDb<0 ){
91575 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
 
91576 return -1;
91577 }
91578 }else{
91579 assert( db->init.iDb==0 || db->init.busy );
91580 iDb = db->init.iDb;
@@ -91365,11 +91729,11 @@
91729 pTable = sqlite3FindTable(db, zName, zDb);
91730 if( pTable ){
91731 if( !noErr ){
91732 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
91733 }else{
91734 assert( !db->init.busy || CORRUPT_DB );
91735 sqlite3CodeVerifySchema(pParse, iDb);
91736 }
91737 goto begin_table_error;
91738 }
91739 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92018,12 @@
92018 Column *pCol;
92019
92020 p = pParse->pNewTable;
92021 if( p==0 || NEVER(p->nCol<1) ) return;
92022 pCol = &p->aCol[p->nCol-1];
92023 assert( pCol->zType==0 || CORRUPT_DB );
92024 sqlite3DbFree(pParse->db, pCol->zType);
92025 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
92026 pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
92027 }
92028
92029 /*
@@ -92888,10 +93253,11 @@
93253 if( db->mallocFailed ){
93254 goto exit_drop_table;
93255 }
93256 assert( pParse->nErr==0 );
93257 assert( pName->nSrc==1 );
93258 if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
93259 if( noErr ) db->suppressErr++;
93260 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
93261 if( noErr ) db->suppressErr--;
93262
93263 if( pTab==0 ){
@@ -93201,11 +93567,12 @@
93567 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
93568 }else{
93569 addr2 = sqlite3VdbeCurrentAddr(v);
93570 }
93571 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93572 sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
93573 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
93574 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
93575 sqlite3ReleaseTempReg(pParse, regRecord);
93576 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
93577 sqlite3VdbeJumpHere(v, addr1);
93578
@@ -93294,12 +93661,11 @@
93661 int nExtra = 0; /* Space allocated for zExtra[] */
93662 int nExtraCol; /* Number of extra columns needed */
93663 char *zExtra = 0; /* Extra space after the Index object */
93664 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
93665
93666 if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
 
93667 goto exit_create_index;
93668 }
93669 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
93670 goto exit_create_index;
93671 }
@@ -94214,11 +94580,10 @@
94580 ** operator with A. This routine shifts that operator over to B.
94581 */
94582 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
94583 if( p ){
94584 int i;
 
94585 for(i=p->nSrc-1; i>0; i--){
94586 p->a[i].jointype = p->a[i-1].jointype;
94587 }
94588 p->a[0].jointype = 0;
94589 }
@@ -94461,12 +94826,11 @@
94826 char *zErr;
94827 int j;
94828 StrAccum errMsg;
94829 Table *pTab = pIdx->pTable;
94830
94831 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
 
94832 for(j=0; j<pIdx->nKeyCol; j++){
94833 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
94834 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
94835 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
94836 sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96655,17 @@
96655 ){
96656 PrintfArguments x;
96657 StrAccum str;
96658 const char *zFormat;
96659 int n;
96660 sqlite3 *db = sqlite3_context_db_handle(context);
96661
96662 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
96663 x.nArg = argc-1;
96664 x.nUsed = 0;
96665 x.apArg = argv+1;
96666 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
 
96667 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
96668 n = str.nChar;
96669 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
96670 SQLITE_DYNAMIC);
96671 }
@@ -96447,11 +96811,11 @@
96811 sqlite3_result_double(context, r);
96812 }
96813 #endif
96814
96815 /*
96816 ** Allocate nByte bytes of space using sqlite3Malloc(). If the
96817 ** allocation fails, call sqlite3_result_error_nomem() to notify
96818 ** the database handle that malloc() has failed and return NULL.
96819 ** If nByte is larger than the maximum string or blob length, then
96820 ** raise an SQLITE_TOOBIG exception and return NULL.
96821 */
@@ -97116,11 +97480,11 @@
97480 int argc,
97481 sqlite3_value **argv
97482 ){
97483 unsigned char *z, *zOut;
97484 int i;
97485 zOut = z = sqlite3_malloc64( argc*4+1 );
97486 if( z==0 ){
97487 sqlite3_result_error_nomem(context);
97488 return;
97489 }
97490 for(i=0; i<argc; i++){
@@ -97264,11 +97628,11 @@
97628 sqlite3_result_error_toobig(context);
97629 sqlite3_free(zOut);
97630 return;
97631 }
97632 zOld = zOut;
97633 zOut = sqlite3_realloc64(zOut, (int)nOut);
97634 if( zOut==0 ){
97635 sqlite3_result_error_nomem(context);
97636 sqlite3_free(zOld);
97637 return;
97638 }
@@ -97626,12 +97990,11 @@
97990 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
97991 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
97992
97993 if( pAccum ){
97994 sqlite3 *db = sqlite3_context_db_handle(context);
97995 int firstTerm = pAccum->mxAlloc==0;
 
97996 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
97997 if( !firstTerm ){
97998 if( argc==2 ){
97999 zSep = (char*)sqlite3_value_text(argv[1]);
98000 nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99410,12 @@
99410 int iFromCol; /* Idx of column in child table */
99411 Expr *pEq; /* tFromCol = OLD.tToCol */
99412
99413 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
99414 assert( iFromCol>=0 );
99415 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
99416 tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName;
99417 tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
99418
99419 tToCol.n = sqlite3Strlen30(tToCol.z);
99420 tFromCol.n = sqlite3Strlen30(tFromCol.z);
99421
@@ -99059,14 +99423,14 @@
99423 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
99424 ** that the affinity and collation sequence associated with the
99425 ** parent table are used for the comparison. */
99426 pEq = sqlite3PExpr(pParse, TK_EQ,
99427 sqlite3PExpr(pParse, TK_DOT,
99428 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99429 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
99430 , 0),
99431 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
99432 , 0);
99433 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
99434
99435 /* For ON UPDATE, construct the next term of the WHEN clause.
99436 ** The final WHEN clause will be like this:
@@ -99074,27 +99438,27 @@
99438 ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
99439 */
99440 if( pChanges ){
99441 pEq = sqlite3PExpr(pParse, TK_IS,
99442 sqlite3PExpr(pParse, TK_DOT,
99443 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99444 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
99445 0),
99446 sqlite3PExpr(pParse, TK_DOT,
99447 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99448 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
99449 0),
99450 0);
99451 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
99452 }
99453
99454 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
99455 Expr *pNew;
99456 if( action==OE_Cascade ){
99457 pNew = sqlite3PExpr(pParse, TK_DOT,
99458 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99459 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
99460 , 0);
99461 }else if( action==OE_SetDflt ){
99462 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
99463 if( pDflt ){
99464 pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99501,16 @@
99501 db->lookaside.bEnabled = 0;
99502
99503 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
99504 sizeof(Trigger) + /* struct Trigger */
99505 sizeof(TriggerStep) + /* Single step in trigger program */
99506 nFrom + 1 /* Space for pStep->zTarget */
99507 );
99508 if( pTrigger ){
99509 pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99510 pStep->zTarget = (char *)&pStep[1];
99511 memcpy((char *)pStep->zTarget, zFrom, nFrom);
 
99512
99513 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99514 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
99515 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99516 if( pWhen ){
@@ -99608,24 +99971,27 @@
99971 );
99972
99973 /*
99974 ** This routine is called to handle SQL of the following forms:
99975 **
99976 ** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
99977 ** insert into TABLE (IDLIST) select
99978 ** insert into TABLE (IDLIST) default values
99979 **
99980 ** The IDLIST following the table name is always optional. If omitted,
99981 ** then a list of all (non-hidden) columns for the table is substituted.
99982 ** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
99983 ** is omitted.
99984 **
99985 ** For the pSelect parameter holds the values to be inserted for the
99986 ** first two forms shown above. A VALUES clause is really just short-hand
99987 ** for a SELECT statement that omits the FROM clause and everything else
99988 ** that follows. If the pSelect parameter is NULL, that means that the
99989 ** DEFAULT VALUES form of the INSERT statement is intended.
99990 **
99991 ** The code generated follows one of four templates. For a simple
99992 ** insert with data coming from a single-row VALUES clause, the code executes
99993 ** once straight down through. Pseudo-code follows (we call this
99994 ** the "1st template"):
99995 **
99996 ** open write cursor to <table> and its indices
99997 ** put VALUES clause expressions into registers
@@ -99728,11 +100094,11 @@
100094 int iDb; /* Index of database holding TABLE */
100095 Db *pDb; /* The database containing table being inserted into */
100096 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
100097 u8 appendFlag = 0; /* True if the insert is likely to be an append */
100098 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
100099 u8 bIdListInOrder; /* True if IDLIST is in table order */
100100 ExprList *pList = 0; /* List of VALUES() to be inserted */
100101
100102 /* Register allocations */
100103 int regFromSelect = 0;/* Base register for data coming from SELECT */
100104 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100119,12 @@
100119 if( pParse->nErr || db->mallocFailed ){
100120 goto insert_cleanup;
100121 }
100122
100123 /* If the Select object is really just a simple VALUES() list with a
100124 ** single row (the common case) then keep that one row of values
100125 ** and discard the other (unused) parts of the pSelect object
100126 */
100127 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
100128 pList = pSelect->pEList;
100129 pSelect->pEList = 0;
100130 sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100228,11 @@
100228 ** the index into IDLIST of the primary key column. ipkColumn is
100229 ** the index of the primary key as it appears in IDLIST, not as
100230 ** is appears in the original table. (The index of the INTEGER
100231 ** PRIMARY KEY in the original table is pTab->iPKey.)
100232 */
100233 bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0;
100234 if( pColumn ){
100235 for(i=0; i<pColumn->nId; i++){
100236 pColumn->a[i].idx = -1;
100237 }
100238 for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100264,12 @@
100264 ** is coming from a SELECT statement, then generate a co-routine that
100265 ** produces a single row of the SELECT on each invocation. The
100266 ** co-routine is the common header to the 3rd and 4th templates.
100267 */
100268 if( pSelect ){
100269 /* Data is coming from a SELECT or from a multi-row VALUES clause.
100270 ** Generate a co-routine to run the SELECT. */
100271 int regYield; /* Register holding co-routine entry-point */
100272 int addrTop; /* Top of the co-routine */
100273 int rc; /* Result code */
100274
100275 regYield = ++pParse->nMem;
@@ -99910,12 +100278,11 @@
100278 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
100279 dest.iSdst = bIdListInOrder ? regData : 0;
100280 dest.nSdst = pTab->nCol;
100281 rc = sqlite3Select(pParse, pSelect, &dest);
100282 regFromSelect = dest.iSdst;
100283 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
 
100284 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
100285 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
100286 assert( pSelect->pEList );
100287 nColumn = pSelect->pEList->nExpr;
100288
@@ -99959,12 +100326,12 @@
100326 sqlite3VdbeJumpHere(v, addrL);
100327 sqlite3ReleaseTempReg(pParse, regRec);
100328 sqlite3ReleaseTempReg(pParse, regTempRowid);
100329 }
100330 }else{
100331 /* This is the case if the data for the INSERT is coming from a
100332 ** single-row VALUES clause
100333 */
100334 NameContext sNC;
100335 memset(&sNC, 0, sizeof(sNC));
100336 sNC.pParse = pParse;
100337 srcTab = -1;
@@ -101031,10 +101398,11 @@
101398 Table *pDest, /* The table we are inserting into */
101399 Select *pSelect, /* A SELECT statement to use as the data source */
101400 int onError, /* How to handle constraint errors */
101401 int iDbDest /* The database of pDest */
101402 ){
101403 sqlite3 *db = pParse->db;
101404 ExprList *pEList; /* The result set of the SELECT */
101405 Table *pSrc; /* The table in the FROM clause of SELECT */
101406 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101407 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101408 int i; /* Loop counter */
@@ -101178,15 +101546,15 @@
101546 ** But the main beneficiary of the transfer optimization is the VACUUM
101547 ** command, and the VACUUM command disables foreign key constraints. So
101548 ** the extra complication to make this rule less restrictive is probably
101549 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101550 */
101551 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101552 return 0;
101553 }
101554 #endif
101555 if( (db->flags & SQLITE_CountRows)!=0 ){
101556 return 0; /* xfer opt does not play well with PRAGMA count_changes */
101557 }
101558
101559 /* If we get this far, it means that the xfer optimization is at
101560 ** least a possibility, though it might only work if the destination
@@ -101193,28 +101561,32 @@
101561 ** table (tab1) is initially empty.
101562 */
101563 #ifdef SQLITE_TEST
101564 sqlite3_xferopt_count++;
101565 #endif
101566 iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
101567 v = sqlite3GetVdbe(pParse);
101568 sqlite3CodeVerifySchema(pParse, iDbSrc);
101569 iSrc = pParse->nTab++;
101570 iDest = pParse->nTab++;
101571 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101572 regData = sqlite3GetTempReg(pParse);
101573 regRowid = sqlite3GetTempReg(pParse);
101574 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101575 assert( HasRowid(pDest) || destHasUniqueIdx );
101576 if( (db->flags & SQLITE_Vacuum)==0 && (
101577 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101578 || destHasUniqueIdx /* (2) */
101579 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101580 )){
101581 /* In some circumstances, we are able to run the xfer optimization
101582 ** only if the destination table is initially empty. Unless the
101583 ** SQLITE_Vacuum flag is set, this block generates code to make
101584 ** that determination. If SQLITE_Vacuum is set, then the destination
101585 ** table is always empty.
101586 **
101587 ** Conditions under which the destination must be empty:
101588 **
101589 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
101590 ** (If the destination is not initially empty, the rowid fields
101591 ** of index entries might need to change.)
101592 **
@@ -101253,10 +101625,11 @@
101625 }else{
101626 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101627 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101628 }
101629 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
101630 u8 useSeekResult = 0;
101631 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101632 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101633 }
101634 assert( pSrcIdx );
101635 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101639,37 @@
101639 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101640 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101641 VdbeComment((v, "%s", pDestIdx->zName));
101642 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101643 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
101644 if( db->flags & SQLITE_Vacuum ){
101645 /* This INSERT command is part of a VACUUM operation, which guarantees
101646 ** that the destination table is empty. If all indexed columns use
101647 ** collation sequence BINARY, then it can also be assumed that the
101648 ** index will be populated by inserting keys in strictly sorted
101649 ** order. In this case, instead of seeking within the b-tree as part
101650 ** of every OP_IdxInsert opcode, an OP_Last is added before the
101651 ** OP_IdxInsert to seek to the point within the b-tree where each key
101652 ** should be inserted. This is faster.
101653 **
101654 ** If any of the indexed columns use a collation sequence other than
101655 ** BINARY, this optimization is disabled. This is because the user
101656 ** might change the definition of a collation sequence and then run
101657 ** a VACUUM command. In that case keys may not be written in strictly
101658 ** sorted order. */
101659 for(i=0; i<pSrcIdx->nColumn; i++){
101660 char *zColl = pSrcIdx->azColl[i];
101661 assert( zColl!=0 );
101662 if( sqlite3_stricmp("BINARY", zColl) ) break;
101663 }
101664 if( i==pSrcIdx->nColumn ){
101665 useSeekResult = OPFLAG_USESEEKRESULT;
101666 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
101667 }
101668 }
101669 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
101670 sqlite3VdbeChangeP5(v, useSeekResult);
101671 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101672 sqlite3VdbeJumpHere(v, addr1);
101673 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101674 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101675 }
@@ -102385,11 +102784,11 @@
102784 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102785 char *zErrmsg = 0;
102786 const char *zEntry;
102787 char *zAltEntry = 0;
102788 void **aHandle;
102789 u64 nMsg = 300 + sqlite3Strlen30(zFile);
102790 int ii;
102791
102792 /* Shared library endings to try if zFile cannot be loaded as written */
102793 static const char *azEndings[] = {
102794 #if SQLITE_OS_WIN
@@ -102428,11 +102827,11 @@
102827 sqlite3_free(zAltFile);
102828 }
102829 #endif
102830 if( handle==0 ){
102831 if( pzErrMsg ){
102832 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102833 if( zErrmsg ){
102834 sqlite3_snprintf(nMsg, zErrmsg,
102835 "unable to open shared library [%s]", zFile);
102836 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102837 }
@@ -102454,11 +102853,11 @@
102853 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102854 */
102855 if( xInit==0 && zProc==0 ){
102856 int iFile, iEntry, c;
102857 int ncFile = sqlite3Strlen30(zFile);
102858 zAltEntry = sqlite3_malloc64(ncFile+30);
102859 if( zAltEntry==0 ){
102860 sqlite3OsDlClose(pVfs, handle);
102861 return SQLITE_NOMEM;
102862 }
102863 memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102875,11 @@
102875 sqlite3OsDlSym(pVfs, handle, zEntry);
102876 }
102877 if( xInit==0 ){
102878 if( pzErrMsg ){
102879 nMsg += sqlite3Strlen30(zEntry);
102880 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102881 if( zErrmsg ){
102882 sqlite3_snprintf(nMsg, zErrmsg,
102883 "no entry point [%s] in shared library [%s]", zEntry, zFile);
102884 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102885 }
@@ -102575,11 +102974,11 @@
102974 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102975 ** mutex must be held while accessing this list.
102976 */
102977 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102978 static SQLITE_WSD struct sqlite3AutoExtList {
102979 u32 nExt; /* Number of entries in aExt[] */
102980 void (**aExt)(void); /* Pointers to the extension init functions */
102981 } sqlite3Autoext = { 0, 0 };
102982
102983 /* The "wsdAutoext" macro will resolve to the autoextension
102984 ** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103007,23 @@
103007 if( rc ){
103008 return rc;
103009 }else
103010 #endif
103011 {
103012 u32 i;
103013 #if SQLITE_THREADSAFE
103014 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
103015 #endif
103016 wsdAutoextInit;
103017 sqlite3_mutex_enter(mutex);
103018 for(i=0; i<wsdAutoext.nExt; i++){
103019 if( wsdAutoext.aExt[i]==xInit ) break;
103020 }
103021 if( i==wsdAutoext.nExt ){
103022 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
103023 void (**aNew)(void);
103024 aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
103025 if( aNew==0 ){
103026 rc = SQLITE_NOMEM;
103027 }else{
103028 wsdAutoext.aExt = aNew;
103029 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103051,11 @@
103051 #endif
103052 int i;
103053 int n = 0;
103054 wsdAutoextInit;
103055 sqlite3_mutex_enter(mutex);
103056 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
103057 if( wsdAutoext.aExt[i]==xInit ){
103058 wsdAutoext.nExt--;
103059 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
103060 n++;
103061 break;
@@ -102690,11 +103089,11 @@
103089 ** Load all automatic extensions.
103090 **
103091 ** If anything goes wrong, set an error in the database connection.
103092 */
103093 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
103094 u32 i;
103095 int go = 1;
103096 int rc;
103097 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
103098
103099 wsdAutoextInit;
@@ -103354,19 +103753,19 @@
103753 /*
103754 ** Generate code to return a single integer value.
103755 */
103756 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103757 Vdbe *v = sqlite3GetVdbe(pParse);
103758 int nMem = ++pParse->nMem;
103759 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103760 if( pI64 ){
103761 memcpy(pI64, &value, sizeof(value));
103762 }
103763 sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
103764 sqlite3VdbeSetNumCols(v, 1);
103765 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103766 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103767 }
103768
103769
103770 /*
103771 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103926,15 @@
103926 aFcntl[3] = 0;
103927 db->busyHandler.nBusy = 0;
103928 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103929 if( rc==SQLITE_OK ){
103930 if( aFcntl[0] ){
103931 int nMem = ++pParse->nMem;
103932 sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
103933 sqlite3VdbeSetNumCols(v, 1);
103934 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103935 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103936 sqlite3_free(aFcntl[0]);
103937 }
103938 goto pragma_out;
103939 }
103940 if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104535,13 @@
104535 }else{
104536 if( !db->autoCommit ){
104537 sqlite3ErrorMsg(pParse,
104538 "Safety level may not be changed inside a transaction");
104539 }else{
104540 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
104541 if( iLevel==0 ) iLevel = 1;
104542 pDb->safety_level = iLevel;
104543 setAllPagerFlags(db);
104544 }
104545 }
104546 break;
104547 }
@@ -104231,11 +104632,11 @@
104632 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104633 k = 0;
104634 }else if( pPk==0 ){
104635 k = 1;
104636 }else{
104637 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
104638 }
104639 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104640 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104641 }
104642 }
@@ -105237,11 +105638,11 @@
105638
105639 assert( iDb>=0 && iDb<db->nDb );
105640 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105641 if( argv[1]==0 ){
105642 corruptSchema(pData, argv[0], 0);
105643 }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){
105644 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105645 ** But because db->init.busy is set to 1, no VDBE code is generated
105646 ** or executed. All the parser does is build the internal data
105647 ** structures that describe the table, index, or view.
105648 */
@@ -105268,12 +105669,12 @@
105669 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105670 }
105671 }
105672 }
105673 sqlite3_finalize(pStmt);
105674 }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
105675 corruptSchema(pData, argv[0], 0);
105676 }else{
105677 /* If the SQL column is blank it means this is an index that
105678 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105679 ** constraint for a CREATE TABLE. The index should have already
105680 ** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106577,10 @@
106577 ){
106578 Select *pNew;
106579 Select standin;
106580 sqlite3 *db = pParse->db;
106581 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
 
106582 if( pNew==0 ){
106583 assert( db->mallocFailed );
106584 pNew = &standin;
106585 memset(pNew, 0, sizeof(*pNew));
106586 }
@@ -106196,11 +106596,11 @@
106596 pNew->pOrderBy = pOrderBy;
106597 pNew->selFlags = selFlags;
106598 pNew->op = TK_SELECT;
106599 pNew->pLimit = pLimit;
106600 pNew->pOffset = pOffset;
106601 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
106602 pNew->addrOpenEphm[0] = -1;
106603 pNew->addrOpenEphm[1] = -1;
106604 if( db->mallocFailed ) {
106605 clearSelect(db, pNew, pNew!=&standin);
106606 pNew = 0;
@@ -107446,11 +107846,11 @@
107846 if( pS ){
107847 /* The "table" is actually a sub-select or a view in the FROM clause
107848 ** of the SELECT statement. Return the declaration type and origin
107849 ** data for the result-set column of the sub-select.
107850 */
107851 if( iCol>=0 && iCol<pS->pEList->nExpr ){
107852 /* If iCol is less than zero, then the expression requests the
107853 ** rowid of the sub-select or view. This expression is legal (see
107854 ** test case misc2.2.2) - it always evaluates to NULL.
107855 */
107856 NameContext sNC;
@@ -107766,16 +108166,18 @@
108166 memset(&sNC, 0, sizeof(sNC));
108167 sNC.pSrcList = pSelect->pSrc;
108168 a = pSelect->pEList->a;
108169 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
108170 p = a[i].pExpr;
108171 if( pCol->zType==0 ){
108172 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108173 }
108174 szAll += pCol->szEst;
108175 pCol->affinity = sqlite3ExprAffinity(p);
108176 if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
108177 pColl = sqlite3ExprCollSeq(pParse, p);
108178 if( pColl && pCol->zColl==0 ){
108179 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
108180 }
108181 }
108182 pTab->szTabRow = sqlite3LogEst(szAll*4);
108183 }
@@ -108173,12 +108575,11 @@
108575 ){
108576 Select *pPrior;
108577 int nExpr = p->pEList->nExpr;
108578 int nRow = 1;
108579 int rc = 0;
108580 assert( p->selFlags & SF_MultiValue );
 
108581 do{
108582 assert( p->selFlags & SF_Values );
108583 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108584 assert( p->pLimit==0 );
108585 assert( p->pOffset==0 );
@@ -108283,11 +108684,11 @@
108684 dest.eDest = SRT_Table;
108685 }
108686
108687 /* Special handling for a compound-select that originates as a VALUES clause.
108688 */
108689 if( p->selFlags & SF_MultiValue ){
108690 rc = multiSelectValues(pParse, p, &dest);
108691 goto multi_select_end;
108692 }
108693
108694 /* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109069,11 @@
109069 ** then there should be a single item on the stack. Write this
109070 ** item into the set table with bogus data.
109071 */
109072 case SRT_Set: {
109073 int r1;
109074 assert( pIn->nSdst==1 || pParse->nErr>0 );
109075 pDest->affSdst =
109076 sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
109077 r1 = sqlite3GetTempReg(pParse);
109078 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
109079 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109095,11 @@
109095 /* If this is a scalar select that is part of an expression, then
109096 ** store the results in the appropriate memory cell and break out
109097 ** of the scan loop.
109098 */
109099 case SRT_Mem: {
109100 assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 );
109101 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
109102 /* The LIMIT clause will jump out of the loop for us */
109103 break;
109104 }
109105 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109110,11 @@
109110 case SRT_Coroutine: {
109111 if( pDest->iSdst==0 ){
109112 pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
109113 pDest->nSdst = pIn->nSdst;
109114 }
109115 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
109116 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
109117 break;
109118 }
109119
109120 /* If none of the above, then the result destination must be
@@ -108925,12 +109326,14 @@
109326 */
109327 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
109328 if( aPermute ){
109329 struct ExprList_item *pItem;
109330 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
109331 assert( pItem->u.x.iOrderByCol>0 );
109332 /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true
109333 ** but only for well-formed SELECT statements. */
109334 testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr );
109335 aPermute[i] = pItem->u.x.iOrderByCol - 1;
109336 }
109337 pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
109338 }else{
109339 pKeyMerge = 0;
@@ -109136,11 +109539,11 @@
109539 pPrior->pNext = p;
109540
109541 /*** TBD: Insert subroutine calls to close cursors on incomplete
109542 **** subqueries ****/
109543 explainComposite(pParse, p->op, iSub1, iSub2, 0);
109544 return pParse->nErr!=0;
109545 }
109546 #endif
109547
109548 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109549 /* Forward Declarations */
@@ -109948,10 +110351,11 @@
110351 pNew->pGroupBy = 0;
110352 pNew->pHaving = 0;
110353 pNew->pOrderBy = 0;
110354 p->pPrior = 0;
110355 p->pNext = 0;
110356 p->pWith = 0;
110357 p->selFlags &= ~SF_Compound;
110358 assert( (p->selFlags & SF_Converted)==0 );
110359 p->selFlags |= SF_Converted;
110360 assert( pNew->pPrior!=0 );
110361 pNew->pPrior->pNext = pNew;
@@ -110486,11 +110890,11 @@
110890 if( pParse->hasCompound ){
110891 w.xSelectCallback = convertCompoundSelectToSubquery;
110892 sqlite3WalkSelect(&w, pSelect);
110893 }
110894 w.xSelectCallback = selectExpander;
110895 if( (pSelect->selFlags & SF_MultiValue)==0 ){
110896 w.xSelectCallback2 = selectPopWith;
110897 }
110898 sqlite3WalkSelect(&w, pSelect);
110899 }
110900
@@ -110672,11 +111076,12 @@
111076 nArg = 0;
111077 regAgg = 0;
111078 }
111079 if( pF->iDistinct>=0 ){
111080 addrNext = sqlite3VdbeMakeLabel(v);
111081 testcase( nArg==0 ); /* Error condition */
111082 testcase( nArg>1 ); /* Also an error */
111083 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
111084 }
111085 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
111086 CollSeq *pColl = 0;
111087 struct ExprList_item *pItem;
@@ -111547,14 +111952,13 @@
111952
111953 /* Jump here to skip this query
111954 */
111955 sqlite3VdbeResolveLabel(v, iEnd);
111956
111957 /* The SELECT has been coded. If there is an error in the Parse structure,
111958 ** set the return code to 1. Otherwise 0. */
111959 rc = (pParse->nErr>0);
 
111960
111961 /* Control jumps to here if an error is encountered above, or upon
111962 ** successful coding of the SELECT.
111963 */
111964 select_end:
@@ -111601,11 +112005,11 @@
112005 sqlite3TreeViewLine(pView, "FROM");
112006 for(i=0; i<p->pSrc->nSrc; i++){
112007 struct SrcList_item *pItem = &p->pSrc->a[i];
112008 StrAccum x;
112009 char zLine[100];
112010 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
112011 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
112012 if( pItem->zDatabase ){
112013 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
112014 }else if( pItem->zName ){
112015 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112164,11 @@
112164 for(i=0; i<nCol; i++){
112165 if( argv[i]==0 ){
112166 z = 0;
112167 }else{
112168 int n = sqlite3Strlen30(argv[i])+1;
112169 z = sqlite3_malloc64( n );
112170 if( z==0 ) goto malloc_failed;
112171 memcpy(z, argv[i], n);
112172 }
112173 p->azResult[p->nData++] = z;
112174 }
@@ -111809,11 +112213,11 @@
112213 res.nRow = 0;
112214 res.nColumn = 0;
112215 res.nData = 1;
112216 res.nAlloc = 20;
112217 res.rc = SQLITE_OK;
112218 res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
112219 if( res.azResult==0 ){
112220 db->errCode = SQLITE_NOMEM;
112221 return SQLITE_NOMEM;
112222 }
112223 res.azResult[0] = 0;
@@ -111837,11 +112241,11 @@
112241 sqlite3_free_table(&res.azResult[1]);
112242 return rc;
112243 }
112244 if( res.nAlloc>res.nData ){
112245 char **azNew;
112246 azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData );
112247 if( azNew==0 ){
112248 sqlite3_free_table(&res.azResult[1]);
112249 db->errCode = SQLITE_NOMEM;
112250 return SQLITE_NOMEM;
112251 }
@@ -112065,11 +112469,10 @@
112469 }
112470
112471 /* Do not create a trigger on a system table */
112472 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112473 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
 
112474 goto trigger_cleanup;
112475 }
112476
112477 /* INSTEAD of triggers are only for views and views only support INSTEAD
112478 ** of triggers.
@@ -112245,16 +112648,16 @@
112648 u8 op, /* Trigger opcode */
112649 Token *pName /* The target name */
112650 ){
112651 TriggerStep *pTriggerStep;
112652
112653 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
112654 if( pTriggerStep ){
112655 char *z = (char*)&pTriggerStep[1];
112656 memcpy(z, pName->z, pName->n);
112657 sqlite3Dequote(z);
112658 pTriggerStep->zTarget = z;
112659 pTriggerStep->op = op;
112660 }
112661 return pTriggerStep;
112662 }
112663
@@ -112533,11 +112936,11 @@
112936 }
112937 return (mask ? pList : 0);
112938 }
112939
112940 /*
112941 ** Convert the pStep->zTarget string into a SrcList and return a pointer
112942 ** to that SrcList.
112943 **
112944 ** This routine adds a specific database name, if needed, to the target when
112945 ** forming the SrcList. This prevents a trigger in one database from
112946 ** referring to a target in another database. An exception is when the
@@ -112546,21 +112949,21 @@
112949 */
112950 static SrcList *targetSrcList(
112951 Parse *pParse, /* The parsing context */
112952 TriggerStep *pStep /* The trigger containing the target token */
112953 ){
112954 sqlite3 *db = pParse->db;
112955 int iDb; /* Index of the database to use */
112956 SrcList *pSrc; /* SrcList to be returned */
112957
112958 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112959 if( pSrc ){
112960 assert( pSrc->nSrc>0 );
112961 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
112962 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
112963 if( iDb==0 || iDb>=2 ){
112964 assert( iDb<db->nDb );
 
112965 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112966 }
112967 }
112968 return pSrc;
112969 }
@@ -112668,10 +113071,11 @@
113071 assert( pFrom->zErrMsg==0 || pFrom->nErr );
113072 assert( pTo->zErrMsg==0 || pTo->nErr );
113073 if( pTo->nErr==0 ){
113074 pTo->zErrMsg = pFrom->zErrMsg;
113075 pTo->nErr = pFrom->nErr;
113076 pTo->rc = pFrom->rc;
113077 }else{
113078 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
113079 }
113080 }
113081
@@ -114018,17 +114422,21 @@
114422
114423 /* Loop through the tables in the main database. For each, do
114424 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114425 ** the contents to the temporary database.
114426 */
114427 assert( (db->flags & SQLITE_Vacuum)==0 );
114428 db->flags |= SQLITE_Vacuum;
114429 rc = execExecSql(db, pzErrMsg,
114430 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114431 "|| ' SELECT * FROM main.' || quote(name) || ';'"
114432 "FROM main.sqlite_master "
114433 "WHERE type = 'table' AND name!='sqlite_sequence' "
114434 " AND coalesce(rootpage,1)>0"
114435 );
114436 assert( (db->flags & SQLITE_Vacuum)!=0 );
114437 db->flags &= ~SQLITE_Vacuum;
114438 if( rc!=SQLITE_OK ) goto end_of_vacuum;
114439
114440 /* Copy over the sequence table
114441 */
114442 rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114571,12 @@
114571 ** are invoked only from within xCreate and xConnect methods.
114572 */
114573 struct VtabCtx {
114574 VTable *pVTable; /* The virtual table being constructed */
114575 Table *pTab; /* The Table object to which the virtual table belongs */
114576 VtabCtx *pPrior; /* Parent context (if any) */
114577 int bDeclared; /* True after sqlite3_declare_vtab() is called */
114578 };
114579
114580 /*
114581 ** The actual function that does the work of creating a new module.
114582 ** This function implements the sqlite3_create_module() and
@@ -114609,11 +115019,11 @@
115019 Token *pArg = &pParse->sArg;
115020 if( pArg->z==0 ){
115021 pArg->z = p->z;
115022 pArg->n = p->n;
115023 }else{
115024 assert(pArg->z <= p->z);
115025 pArg->n = (int)(&p->z[p->n] - pArg->z);
115026 }
115027 }
115028
115029 /*
@@ -114626,19 +115036,31 @@
115036 Table *pTab,
115037 Module *pMod,
115038 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
115039 char **pzErr
115040 ){
115041 VtabCtx sCtx;
115042 VTable *pVTable;
115043 int rc;
115044 const char *const*azArg = (const char *const*)pTab->azModuleArg;
115045 int nArg = pTab->nModuleArg;
115046 char *zErr = 0;
115047 char *zModuleName;
115048 int iDb;
115049 VtabCtx *pCtx;
115050
115051 /* Check that the virtual-table is not already being initialized */
115052 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
115053 if( pCtx->pTab==pTab ){
115054 *pzErr = sqlite3MPrintf(db,
115055 "vtable constructor called recursively: %s", pTab->zName
115056 );
115057 return SQLITE_LOCKED;
115058 }
115059 }
115060
115061 zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
115062 if( !zModuleName ){
115063 return SQLITE_NOMEM;
115064 }
115065
115066 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115077,17 @@
115077 /* Invoke the virtual table constructor */
115078 assert( &db->pVtabCtx );
115079 assert( xConstruct );
115080 sCtx.pTab = pTab;
115081 sCtx.pVTable = pVTable;
115082 sCtx.pPrior = db->pVtabCtx;
115083 sCtx.bDeclared = 0;
115084 db->pVtabCtx = &sCtx;
115085 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
115086 db->pVtabCtx = sCtx.pPrior;
115087 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
115088 assert( sCtx.pTab==pTab );
115089
115090 if( SQLITE_OK!=rc ){
115091 if( zErr==0 ){
115092 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
115093 }else {
@@ -114675,17 +115099,18 @@
115099 /* Justification of ALWAYS(): A correct vtab constructor must allocate
115100 ** the sqlite3_vtab object if successful. */
115101 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
115102 pVTable->pVtab->pModule = pMod->pModule;
115103 pVTable->nRef = 1;
115104 if( sCtx.bDeclared==0 ){
115105 const char *zFormat = "vtable constructor did not declare schema: %s";
115106 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
115107 sqlite3VtabUnlock(pVTable);
115108 rc = SQLITE_ERROR;
115109 }else{
115110 int iCol;
115111 u8 oooHidden = 0;
115112 /* If everything went according to plan, link the new VTable structure
115113 ** into the linked list headed by pTab->pVTable. Then loop through the
115114 ** columns of the table to see if any of them contain the token "hidden".
115115 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
115116 ** the type string. */
@@ -114694,11 +115119,14 @@
115119
115120 for(iCol=0; iCol<pTab->nCol; iCol++){
115121 char *zType = pTab->aCol[iCol].zType;
115122 int nType;
115123 int i = 0;
115124 if( !zType ){
115125 pTab->tabFlags |= oooHidden;
115126 continue;
115127 }
115128 nType = sqlite3Strlen30(zType);
115129 if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
115130 for(i=0; i<nType; i++){
115131 if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
115132 && (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115145,13 @@
115145 if( zType[i]=='\0' && i>0 ){
115146 assert(zType[i-1]==' ');
115147 zType[i-1] = '\0';
115148 }
115149 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
115150 oooHidden = TF_OOOHidden;
115151 }else{
115152 pTab->tabFlags |= oooHidden;
115153 }
115154 }
115155 }
115156 }
115157
@@ -114845,12 +115276,12 @@
115276 ** This function is used to set the schema of a virtual table. It is only
115277 ** valid to call this function from within the xCreate() or xConnect() of a
115278 ** virtual table module.
115279 */
115280 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
115281 VtabCtx *pCtx;
115282 Parse *pParse;
 
115283 int rc = SQLITE_OK;
115284 Table *pTab;
115285 char *zErr = 0;
115286
115287 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115288,17 @@
115288 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
115289 return SQLITE_MISUSE_BKPT;
115290 }
115291 #endif
115292 sqlite3_mutex_enter(db->mutex);
115293 pCtx = db->pVtabCtx;
115294 if( !pCtx || pCtx->bDeclared ){
115295 sqlite3Error(db, SQLITE_MISUSE);
115296 sqlite3_mutex_leave(db->mutex);
115297 return SQLITE_MISUSE_BKPT;
115298 }
115299 pTab = pCtx->pTab;
115300 assert( (pTab->tabFlags & TF_Virtual)!=0 );
115301
115302 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
115303 if( pParse==0 ){
115304 rc = SQLITE_NOMEM;
@@ -114884,11 +115317,11 @@
115317 pTab->aCol = pParse->pNewTable->aCol;
115318 pTab->nCol = pParse->pNewTable->nCol;
115319 pParse->pNewTable->nCol = 0;
115320 pParse->pNewTable->aCol = 0;
115321 }
115322 pCtx->bDeclared = 1;
115323 }else{
115324 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
115325 sqlite3DbFree(db, zErr);
115326 rc = SQLITE_ERROR;
115327 }
@@ -115078,11 +115511,11 @@
115511 */
115512 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115513 int rc = SQLITE_OK;
115514
115515 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115516 assert( iSavepoint>=-1 );
115517 if( db->aVTrans ){
115518 int i;
115519 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115520 VTable *pVTab = db->aVTrans[i];
115521 const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115629,11 @@
115629 assert( IsVirtual(pTab) );
115630 for(i=0; i<pToplevel->nVtabLock; i++){
115631 if( pTab==pToplevel->apVtabLock[i] ) return;
115632 }
115633 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115634 apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n);
115635 if( apVtabLock ){
115636 pToplevel->apVtabLock = apVtabLock;
115637 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115638 }else{
115639 pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116428,18 @@
116428 ** In the previous sentence and in the diagram, "slot[]" refers to
116429 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
116430 ** all terms of the WHERE clause.
116431 */
116432 static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
116433 Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
116434 pWC->op = op;
116435 if( pE2==0 ) return;
116436 if( pE2->op!=op ){
116437 whereClauseInsert(pWC, pExpr, 0);
116438 }else{
116439 whereSplit(pWC, pE2->pLeft, op);
116440 whereSplit(pWC, pE2->pRight, op);
116441 }
116442 }
116443
116444 /*
116445 ** Initialize a WhereMaskSet object
@@ -117272,11 +117706,11 @@
117706 if( p->op==TK_COLUMN
117707 && p->iColumn==pIdx->aiColumn[iCol]
117708 && p->iTable==iBase
117709 ){
117710 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117711 if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117712 return i;
117713 }
117714 }
117715 }
117716
@@ -117546,11 +117980,11 @@
117980 if( (idxCols & cMask)==0 ){
117981 Expr *pX = pTerm->pExpr;
117982 idxCols |= cMask;
117983 pIdx->aiColumn[n] = pTerm->u.leftColumn;
117984 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117985 pIdx->azColl[n] = pColl ? pColl->zName : "BINARY";
117986 n++;
117987 }
117988 }
117989 }
117990 assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119276,11 @@
119276
119277 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
119278 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
119279 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
119280
119281 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
 
119282 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
119283 if( pItem->pSelect ){
119284 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
119285 }else{
119286 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120475,17 @@
120475 /*
120476 ** Free a WhereInfo structure
120477 */
120478 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120479 if( ALWAYS(pWInfo) ){
120480 int i;
120481 for(i=0; i<pWInfo->nLevel; i++){
120482 WhereLevel *pLevel = &pWInfo->a[i];
120483 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
120484 sqlite3DbFree(db, pLevel->u.in.aInLoop);
120485 }
120486 }
120487 whereClauseClear(&pWInfo->sWC);
120488 while( pWInfo->pLoops ){
120489 WhereLoop *p = pWInfo->pLoops;
120490 pWInfo->pLoops = p->pNextLoop;
120491 whereLoopDelete(db, p);
@@ -120521,11 +120961,11 @@
120961 ** changes "x IN (?)" into "x=?". */
120962
120963 }else if( eOp & (WO_EQ) ){
120964 pNew->wsFlags |= WHERE_COLUMN_EQ;
120965 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120966 if( iCol>=0 && pProbe->uniqNotNull==0 ){
120967 pNew->wsFlags |= WHERE_UNQ_WANTED;
120968 }else{
120969 pNew->wsFlags |= WHERE_ONEROW;
120970 }
120971 }
@@ -121981,11 +122421,11 @@
122421 pWInfo->nOBSat = pFrom->isOrdered;
122422 if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
122423 pWInfo->revMask = pFrom->revLoop;
122424 }
122425 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
122426 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
122427 ){
122428 Bitmask revMask = 0;
122429 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
122430 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
122431 );
@@ -122386,11 +122826,10 @@
122826 if( pParse->nErr || NEVER(db->mallocFailed) ){
122827 goto whereBeginError;
122828 }
122829 #ifdef WHERETRACE_ENABLED /* !=0 */
122830 if( sqlite3WhereTrace ){
 
122831 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122832 if( pWInfo->nOBSat>0 ){
122833 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122834 }
122835 switch( pWInfo->eDistinct ){
@@ -122639,11 +123078,10 @@
123078 VdbeCoverage(v);
123079 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
123080 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
123081 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
123082 }
 
123083 }
123084 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
123085 if( pLevel->addrSkip ){
123086 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
123087 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123288,32 @@
123288 /*
123289 ** An instance of this structure holds the ATTACH key and the key type.
123290 */
123291 struct AttachKey { int type; Token key; };
123292
123293
123294 /*
123295 ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
123296 ** all elements in the list. And make sure list length does not exceed
123297 ** SQLITE_LIMIT_COMPOUND_SELECT.
123298 */
123299 static void parserDoubleLinkSelect(Parse *pParse, Select *p){
123300 if( p->pPrior ){
123301 Select *pNext = 0, *pLoop;
123302 int mxSelect, cnt = 0;
123303 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123304 pLoop->pNext = pNext;
123305 pLoop->selFlags |= SF_Compound;
123306 }
123307 if( (p->selFlags & SF_MultiValue)==0 &&
123308 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
123309 cnt>mxSelect
123310 ){
123311 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123312 }
123313 }
123314 }
123315
123316 /* This is a utility routine used to set the ExprSpan.zStart and
123317 ** ExprSpan.zEnd values of pOut so that the span covers the complete
123318 ** range of text beginning with pStart and going to the end of pEnd.
123319 */
@@ -125167,31 +125627,14 @@
125627 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125628 }
125629 break;
125630 case 112: /* select ::= with selectnowith */
125631 {
125632 Select *p = yymsp[0].minor.yy3;
125633 if( p ){
 
125634 p->pWith = yymsp[-1].minor.yy59;
125635 parserDoubleLinkSelect(pParse, p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125636 }else{
125637 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125638 }
125639 yygotominor.yy3 = p;
125640 }
@@ -125205,16 +125648,18 @@
125648 Select *pRhs = yymsp[0].minor.yy3;
125649 if( pRhs && pRhs->pPrior ){
125650 SrcList *pFrom;
125651 Token x;
125652 x.n = 0;
125653 parserDoubleLinkSelect(pParse, pRhs);
125654 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125655 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125656 }
125657 if( pRhs ){
125658 pRhs->op = (u8)yymsp[-1].minor.yy328;
125659 pRhs->pPrior = yymsp[-2].minor.yy3;
125660 pRhs->selFlags &= ~SF_MultiValue;
125661 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125662 }else{
125663 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125664 }
125665 yygotominor.yy3 = pRhs;
@@ -125257,17 +125702,20 @@
125702 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125703 }
125704 break;
125705 case 121: /* values ::= values COMMA LP exprlist RP */
125706 {
125707 Select *pRight, *pLeft = yymsp[-4].minor.yy3;
125708 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
125709 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
125710 if( pRight ){
125711 pRight->op = TK_ALL;
125712 pLeft = yymsp[-4].minor.yy3;
125713 pRight->pPrior = pLeft;
125714 yygotominor.yy3 = pRight;
125715 }else{
125716 yygotominor.yy3 = pLeft;
125717 }
125718 }
125719 break;
125720 case 122: /* distinct ::= DISTINCT */
125721 {yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127515,12 @@
127515 goto abort_parse;
127516 }
127517 break;
127518 }
127519 case TK_ILLEGAL: {
127520 sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
 
127521 &pParse->sLastToken);
 
127522 goto abort_parse;
127523 }
127524 case TK_SEMI: {
127525 pParse->zTail = &zSql[i];
127526 /* Fall thru into the default case */
@@ -127088,16 +127534,19 @@
127534 break;
127535 }
127536 }
127537 }
127538 abort_parse:
127539 assert( nErr==0 );
127540 if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127541 if( lastTokenParsed!=TK_SEMI ){
127542 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127543 pParse->zTail = &zSql[i];
127544 }
127545 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127546 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127547 }
127548 }
127549 #ifdef YYTRACKMAXSTACKDEPTH
127550 sqlite3_mutex_enter(sqlite3MallocMutex());
127551 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127552 sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127603,11 @@
127603 while( pParse->pZombieTab ){
127604 Table *p = pParse->pZombieTab;
127605 pParse->pZombieTab = p->pNextZombie;
127606 sqlite3DeleteTable(db, p);
127607 }
127608 assert( nErr==0 || pParse->rc!=SQLITE_OK );
 
 
127609 return nErr;
127610 }
127611
127612 /************** End of tokenize.c ********************************************/
127613 /************** Begin file complete.c ****************************************/
@@ -127432,11 +127879,11 @@
127879 ** UTF-8.
127880 */
127881 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127882 sqlite3_value *pVal;
127883 char const *zSql8;
127884 int rc;
127885
127886 #ifndef SQLITE_OMIT_AUTOINIT
127887 rc = sqlite3_initialize();
127888 if( rc ) return rc;
127889 #endif
@@ -127598,10 +128045,22 @@
128045 ** zero if and only if SQLite was compiled with mutexing code omitted due to
128046 ** the SQLITE_THREADSAFE compile-time option being set to 0.
128047 */
128048 SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
128049
128050 /*
128051 ** When compiling the test fixture or with debugging enabled (on Win32),
128052 ** this variable being set to non-zero will cause OSTRACE macros to emit
128053 ** extra diagnostic information.
128054 */
128055 #ifdef SQLITE_HAVE_OS_TRACE
128056 # ifndef SQLITE_DEBUG_OS_TRACE
128057 # define SQLITE_DEBUG_OS_TRACE 0
128058 # endif
128059 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
128060 #endif
128061
128062 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
128063 /*
128064 ** If the following function pointer is not NULL and if
128065 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
128066 ** I/O active are written using this function. These messages
@@ -128737,11 +129196,11 @@
129196
129197 /*
129198 ** Return a static string containing the name corresponding to the error code
129199 ** specified in the argument.
129200 */
129201 #if defined(SQLITE_NEED_ERR_NAME)
129202 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
129203 const char *zName = 0;
129204 int i, origRc = rc;
129205 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
129206 switch( rc ){
@@ -129962,18 +130421,18 @@
130421 ){
130422 char *zOpt;
130423 int eState; /* Parser state when parsing URI */
130424 int iIn; /* Input character index */
130425 int iOut = 0; /* Output character index */
130426 u64 nByte = nUri+2; /* Bytes of space to allocate */
130427
130428 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
130429 ** method that there may be extra parameters following the file-name. */
130430 flags |= SQLITE_OPEN_URI;
130431
130432 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
130433 zFile = sqlite3_malloc64(nByte);
130434 if( !zFile ) return SQLITE_NOMEM;
130435
130436 iIn = 5;
130437 #ifdef SQLITE_ALLOW_URI_AUTHORITY
130438 if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130594,11 @@
130594
130595 zOpt = &zVal[nVal+1];
130596 }
130597
130598 }else{
130599 zFile = sqlite3_malloc64(nUri+2);
130600 if( !zFile ) return SQLITE_NOMEM;
130601 memcpy(zFile, zUri, nUri);
130602 zFile[nUri] = '\0';
130603 zFile[nUri+1] = '\0';
130604 flags &= ~SQLITE_OPEN_URI;
@@ -132344,10 +132803,15 @@
132803 ** false.
132804 */
132805 #ifdef SQLITE_COVERAGE_TEST
132806 # define ALWAYS(x) (1)
132807 # define NEVER(X) (0)
132808 #elif defined(SQLITE_DEBUG)
132809 # define ALWAYS(x) sqlite3Fts3Always((x)!=0)
132810 # define NEVER(x) sqlite3Fts3Never((x)!=0)
132811 SQLITE_PRIVATE int sqlite3Fts3Always(int b);
132812 SQLITE_PRIVATE int sqlite3Fts3Never(int b);
132813 #else
132814 # define ALWAYS(x) (x)
132815 # define NEVER(x) (x)
132816 #endif
132817
@@ -132744,10 +133208,11 @@
133208 #define fts3GetVarint32(p, piVal) ( \
133209 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
133210 )
133211
133212 /* fts3.c */
133213 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
133214 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
133215 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
133216 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
133217 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
133218 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133297,17 @@
133297
133298 static int fts3EvalNext(Fts3Cursor *pCsr);
133299 static int fts3EvalStart(Fts3Cursor *pCsr);
133300 static int fts3TermSegReaderCursor(
133301 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
133302
133303 #ifndef SQLITE_AMALGAMATION
133304 # if defined(SQLITE_DEBUG)
133305 SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
133306 SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
133307 # endif
133308 #endif
133309
133310 /*
133311 ** Write a 64-bit variable-length integer to memory starting at p[0].
133312 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
133313 ** The number of bytes written is returned.
@@ -132942,11 +133414,11 @@
133414 int iOut = 0; /* Index of next byte to write to output */
133415
133416 /* If the first byte was a '[', then the close-quote character is a ']' */
133417 if( quote=='[' ) quote = ']';
133418
133419 while( z[iIn] ){
133420 if( z[iIn]==quote ){
133421 if( z[iIn+1]!=quote ) break;
133422 z[iOut++] = quote;
133423 iIn += 2;
133424 }else{
@@ -133020,10 +133492,21 @@
133492 p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133493
133494 sqlite3_free(p);
133495 return SQLITE_OK;
133496 }
133497
133498 /*
133499 ** Write an error message into *pzErr
133500 */
133501 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){
133502 va_list ap;
133503 sqlite3_free(*pzErr);
133504 va_start(ap, zFormat);
133505 *pzErr = sqlite3_vmprintf(zFormat, ap);
133506 va_end(ap);
133507 }
133508
133509 /*
133510 ** Construct one or more SQL statements from the format string given
133511 ** and then evaluate those statements. The success code is written
133512 ** into *pRc.
@@ -133539,11 +134022,12 @@
134022 sqlite3 *db, /* Database handle */
134023 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
134024 const char *zTbl, /* Name of content table */
134025 const char ***pazCol, /* OUT: Malloc'd array of column names */
134026 int *pnCol, /* OUT: Size of array *pazCol */
134027 int *pnStr, /* OUT: Bytes of string content */
134028 char **pzErr /* OUT: error message */
134029 ){
134030 int rc = SQLITE_OK; /* Return code */
134031 char *zSql; /* "SELECT *" statement on zTbl */
134032 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
134033
@@ -133550,10 +134034,13 @@
134034 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
134035 if( !zSql ){
134036 rc = SQLITE_NOMEM;
134037 }else{
134038 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
134039 if( rc!=SQLITE_OK ){
134040 sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
134041 }
134042 }
134043 sqlite3_free(zSql);
134044
134045 if( rc==SQLITE_OK ){
134046 const char **azCol; /* Output array */
@@ -133716,17 +134203,17 @@
134203 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
134204 break;
134205 }
134206 }
134207 if( iOpt==SizeofArray(aFts4Opt) ){
134208 sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
134209 rc = SQLITE_ERROR;
134210 }else{
134211 switch( iOpt ){
134212 case 0: /* MATCHINFO */
134213 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
134214 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
134215 rc = SQLITE_ERROR;
134216 }
134217 bNoDocsize = 1;
134218 break;
134219
@@ -133750,11 +134237,11 @@
134237
134238 case 4: /* ORDER */
134239 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
134240 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
134241 ){
134242 sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
134243 rc = SQLITE_ERROR;
134244 }
134245 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
134246 break;
134247
@@ -133801,11 +134288,11 @@
134288 zCompress = 0;
134289 zUncompress = 0;
134290 if( nCol==0 ){
134291 sqlite3_free((void*)aCol);
134292 aCol = 0;
134293 rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
134294
134295 /* If a languageid= option was specified, remove the language id
134296 ** column from the aCol[] array. */
134297 if( rc==SQLITE_OK && zLanguageid ){
134298 int j;
@@ -133836,11 +134323,11 @@
134323 assert( pTokenizer );
134324
134325 rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
134326 if( rc==SQLITE_ERROR ){
134327 assert( zPrefix );
134328 sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix);
134329 }
134330 if( rc!=SQLITE_OK ) goto fts3_init_out;
134331
134332 /* Allocate and populate the Fts3Table structure. */
134333 nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134405,19 @@
134405 }
134406 }
134407 }
134408 for(i=0; i<nNotindexed; i++){
134409 if( azNotindexed[i] ){
134410 sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]);
134411 rc = SQLITE_ERROR;
134412 }
134413 }
134414
134415 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
134416 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
134417 rc = SQLITE_ERROR;
134418 sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss);
134419 }
134420 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
134421 p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
134422 if( rc!=SQLITE_OK ) goto fts3_init_out;
134423
@@ -135319,11 +135806,11 @@
135806 ** Fts3SegReaderPending might segfault, as the data structures used by
135807 ** fts4aux are not completely populated. So it's easiest to filter these
135808 ** calls out here. */
135809 if( iLevel<0 && p->aIndex ){
135810 Fts3SegReader *pSeg = 0;
135811 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
135812 if( rc==SQLITE_OK && pSeg ){
135813 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135814 }
135815 }
135816
@@ -135968,15 +136455,35 @@
136455 */
136456 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
136457 char *p = &(*ppPoslist)[-2];
136458 char c = 0;
136459
136460 /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
136461 while( p>pStart && (c=*p--)==0 );
136462
136463 /* Search backwards for a varint with value zero (the end of the previous
136464 ** poslist). This is an 0x00 byte preceded by some byte that does not
136465 ** have the 0x80 bit set. */
136466 while( p>pStart && (*p & 0x80) | c ){
136467 c = *p--;
136468 }
136469 assert( p==pStart || c==0 );
136470
136471 /* At this point p points to that preceding byte without the 0x80 bit
136472 ** set. So to find the start of the poslist, skip forward 2 bytes then
136473 ** over a varint.
136474 **
136475 ** Normally. The other case is that p==pStart and the poslist to return
136476 ** is the first in the doclist. In this case do not skip forward 2 bytes.
136477 ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
136478 ** is required for cases where the first byte of a doclist and the
136479 ** doclist is empty. For example, if the first docid is 10, a doclist
136480 ** that begins with:
136481 **
136482 ** 0x0A 0x00 <next docid delta varint>
136483 */
136484 if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
136485 while( *p++&0x80 );
136486 *ppPoslist = p;
136487 }
136488
136489 /*
@@ -136043,10 +136550,12 @@
136550 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136551 case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136552 }
136553 if( !zEllipsis || !zEnd || !zStart ){
136554 sqlite3_result_error_nomem(pContext);
136555 }else if( nToken==0 ){
136556 sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
136557 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136558 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136559 }
136560 }
136561
@@ -137104,16 +137613,18 @@
137613 Fts3Expr *pExpr, /* Expression to initialize phrases in */
137614 int *pRc /* IN/OUT: Error code */
137615 ){
137616 if( pExpr && SQLITE_OK==*pRc ){
137617 if( pExpr->eType==FTSQUERY_PHRASE ){
 
137618 int nToken = pExpr->pPhrase->nToken;
137619 if( nToken ){
137620 int i;
137621 for(i=0; i<nToken; i++){
137622 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137623 }
137624 pExpr->bDeferred = (i==nToken);
137625 }
 
137626 *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137627 }else{
137628 fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137629 fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137630 pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138783,12 @@
138783 if( rc!=SQLITE_OK ) return rc;
138784
138785 pIter = pPhrase->pOrPoslist;
138786 iDocid = pPhrase->iOrDocid;
138787 if( pCsr->bDesc==bDescDoclist ){
138788 bEof = !pPhrase->doclist.nAll ||
138789 (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138790 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138791 sqlite3Fts3DoclistNext(
138792 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138793 &pIter, &iDocid, &bEof
138794 );
@@ -138484,11 +138996,11 @@
138996
138997 *ppVtab = (sqlite3_vtab *)p;
138998 return SQLITE_OK;
138999
139000 bad_args:
139001 sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor");
139002 return SQLITE_ERROR;
139003 }
139004
139005 /*
139006 ** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140454,17 @@
140454
140455 if( rc!=SQLITE_OK ){
140456 sqlite3Fts3ExprFree(*ppExpr);
140457 *ppExpr = 0;
140458 if( rc==SQLITE_TOOBIG ){
140459 sqlite3Fts3ErrMsg(pzErr,
140460 "FTS expression tree is too large (maximum depth %d)",
140461 SQLITE_FTS3_MAX_EXPR_DEPTH
140462 );
140463 rc = SQLITE_ERROR;
140464 }else if( rc==SQLITE_ERROR ){
140465 sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z);
140466 }
140467 }
140468
140469 return rc;
140470 }
@@ -141424,11 +141936,11 @@
141936 z[n] = '\0';
141937 sqlite3Fts3Dequote(z);
141938
141939 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141940 if( !m ){
141941 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
141942 rc = SQLITE_ERROR;
141943 }else{
141944 char const **aArg = 0;
141945 int iArg = 0;
141946 z = &z[n+1];
@@ -141447,11 +141959,11 @@
141959 z = &z[n+1];
141960 }
141961 rc = m->xCreate(iArg, aArg, ppTok);
141962 assert( rc!=SQLITE_OK || *ppTok );
141963 if( rc!=SQLITE_OK ){
141964 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer");
141965 }else{
141966 (*ppTok)->pModule = m;
141967 }
141968 sqlite3_free((void *)aArg);
141969 }
@@ -141531,13 +142043,13 @@
142043
142044 pHash = (Fts3Hash *)sqlite3_user_data(context);
142045 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142046
142047 if( !p ){
142048 char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName);
142049 sqlite3_result_error(context, zErr2, -1);
142050 sqlite3_free(zErr2);
142051 return;
142052 }
142053
142054 pRet = Tcl_NewObj();
142055 Tcl_IncrRefCount(pRet);
@@ -142068,11 +142580,11 @@
142580 sqlite3_tokenizer_module *p;
142581 int nName = (int)strlen(zName);
142582
142583 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142584 if( !p ){
142585 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName);
142586 return SQLITE_ERROR;
142587 }
142588
142589 *pp = p;
142590 return SQLITE_OK;
@@ -142765,11 +143277,11 @@
143277 /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
143278 /* 24 */ "",
143279 /* 25 */ "",
143280
143281 /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
143282 /* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'",
143283
143284 /* This statement is used to determine which level to read the input from
143285 ** when performing an incremental merge. It returns the absolute level number
143286 ** of the oldest level in the db that contains at least ? segments. Or,
143287 ** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146395,12 @@
146395 sqlite3_stmt *pAllLangid = 0;
146396
146397 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
146398 if( rc==SQLITE_OK ){
146399 int rc2;
146400 sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
146401 sqlite3_bind_int(pAllLangid, 2, p->nIndex);
146402 while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
146403 int i;
146404 int iLangid = sqlite3_column_int(pAllLangid, 0);
146405 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
146406 rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147728,11 @@
147728 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147729
147730 pHint->n = i;
147731 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147732 i += fts3GetVarint32(&pHint->a[i], pnInput);
147733 if( i!=nHint ) return FTS_CORRUPT_VTAB;
147734
147735 return SQLITE_OK;
147736 }
147737
147738
@@ -147583,11 +148096,12 @@
148096
148097 /* This block calculates the checksum according to the FTS index. */
148098 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
148099 if( rc==SQLITE_OK ){
148100 int rc2;
148101 sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
148102 sqlite3_bind_int(pAllLangid, 2, p->nIndex);
148103 while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
148104 int iLangid = sqlite3_column_int(pAllLangid, 0);
148105 int i;
148106 for(i=0; i<p->nIndex; i++){
148107 cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148110,10 @@
148110 rc2 = sqlite3_reset(pAllLangid);
148111 if( rc==SQLITE_OK ) rc = rc2;
148112 }
148113
148114 /* This block calculates the checksum according to the %_content table */
 
148115 if( rc==SQLITE_OK ){
148116 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
148117 sqlite3_stmt *pStmt = 0;
148118 char *zSql;
148119
@@ -147693,11 +148206,11 @@
148206 Fts3Table *p /* FTS3 table handle */
148207 ){
148208 int rc;
148209 int bOk = 0;
148210 rc = fts3IntegrityCheck(p, &bOk);
148211 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
148212 return rc;
148213 }
148214
148215 /*
148216 ** Handle a 'special' INSERT of the form:
@@ -148131,10 +148644,11 @@
148644 #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148645 #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148646 #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148647 #define FTS3_MATCHINFO_LCS 's' /* nCol values */
148648 #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
148649 #define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */
148650
148651 /*
148652 ** The default value for the second argument to matchinfo().
148653 */
148654 #define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149426,55 @@
149426 }
149427 }
149428
149429 return rc;
149430 }
149431
149432 /*
149433 ** fts3ExprIterate() callback used to gather information for the matchinfo
149434 ** directive 'y'.
149435 */
149436 static int fts3ExprLHitsCb(
149437 Fts3Expr *pExpr, /* Phrase expression node */
149438 int iPhrase, /* Phrase number */
149439 void *pCtx /* Pointer to MatchInfo structure */
149440 ){
149441 MatchInfo *p = (MatchInfo *)pCtx;
149442 Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
149443 int rc = SQLITE_OK;
149444 int iStart = iPhrase * p->nCol;
149445 Fts3Expr *pEof; /* Ancestor node already at EOF */
149446
149447 /* This must be a phrase */
149448 assert( pExpr->pPhrase );
149449
149450 /* Initialize all output integers to zero. */
149451 memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
149452
149453 /* Check if this or any parent node is at EOF. If so, then all output
149454 ** values are zero. */
149455 for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
149456
149457 if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
149458 Fts3Phrase *pPhrase = pExpr->pPhrase;
149459 char *pIter = pPhrase->doclist.pList;
149460 int iCol = 0;
149461
149462 while( 1 ){
149463 int nHit = fts3ColumnlistCount(&pIter);
149464 if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
149465 p->aMatchinfo[iStart + iCol] = (u32)nHit;
149466 }
149467 assert( *pIter==0x00 || *pIter==0x01 );
149468 if( *pIter!=0x01 ) break;
149469 pIter++;
149470 pIter += fts3GetVarint32(pIter, &iCol);
149471 }
149472 }
149473
149474 return rc;
149475 }
149476
149477 static int fts3MatchinfoCheck(
149478 Fts3Table *pTab,
149479 char cArg,
149480 char **pzErr
@@ -148925,14 +149484,15 @@
149484 || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
149485 || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
149486 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
149487 || (cArg==FTS3_MATCHINFO_LCS)
149488 || (cArg==FTS3_MATCHINFO_HITS)
149489 || (cArg==FTS3_MATCHINFO_LHITS)
149490 ){
149491 return SQLITE_OK;
149492 }
149493 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
149494 return SQLITE_ERROR;
149495 }
149496
149497 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
149498 int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149507,14 @@
149507 case FTS3_MATCHINFO_AVGLENGTH:
149508 case FTS3_MATCHINFO_LENGTH:
149509 case FTS3_MATCHINFO_LCS:
149510 nVal = pInfo->nCol;
149511 break;
149512
149513 case FTS3_MATCHINFO_LHITS:
149514 nVal = pInfo->nCol * pInfo->nPhrase;
149515 break;
149516
149517 default:
149518 assert( cArg==FTS3_MATCHINFO_HITS );
149519 nVal = pInfo->nCol * pInfo->nPhrase * 3;
149520 break;
@@ -149201,10 +149765,14 @@
149765 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149766 if( rc==SQLITE_OK ){
149767 rc = fts3MatchinfoLcs(pCsr, pInfo);
149768 }
149769 break;
149770
149771 case FTS3_MATCHINFO_LHITS:
149772 (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
149773 break;
149774
149775 default: {
149776 Fts3Expr *pExpr;
149777 assert( zArg[i]==FTS3_MATCHINFO_HITS );
149778 pExpr = pCsr->pExpr;
@@ -153214,15 +153782,23 @@
153782 ** conflict-handling mode specified by the user.
153783 */
153784 if( nData>1 ){
153785 int ii;
153786
153787 /* Populate the cell.aCoord[] array. The first coordinate is azData[3].
153788 **
153789 ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
153790 ** with "column" that are interpreted as table constraints.
153791 ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
153792 ** This problem was discovered after years of use, so we silently ignore
153793 ** these kinds of misdeclared tables to avoid breaking any legacy.
153794 */
153795 assert( nData<=(pRtree->nDim*2 + 3) );
153796
153797 #ifndef SQLITE_RTREE_INT_ONLY
153798 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153799 for(ii=0; ii<nData-4; ii+=2){
153800 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153801 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153802 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153803 rc = SQLITE_CONSTRAINT;
153804 goto constraint;
@@ -153229,11 +153805,11 @@
153805 }
153806 }
153807 }else
153808 #endif
153809 {
153810 for(ii=0; ii<nData-4; ii+=2){
153811 cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153812 cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153813 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153814 rc = SQLITE_CONSTRAINT;
153815 goto constraint;
@@ -154629,5 +155205,633 @@
155205
155206 #endif /* defined(SQLITE_ENABLE_ICU) */
155207 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
155208
155209 /************** End of fts3_icu.c ********************************************/
155210 /************** Begin file dbstat.c ******************************************/
155211 /*
155212 ** 2010 July 12
155213 **
155214 ** The author disclaims copyright to this source code. In place of
155215 ** a legal notice, here is a blessing:
155216 **
155217 ** May you do good and not evil.
155218 ** May you find forgiveness for yourself and forgive others.
155219 ** May you share freely, never taking more than you give.
155220 **
155221 ******************************************************************************
155222 **
155223 ** This file contains an implementation of the "dbstat" virtual table.
155224 **
155225 ** The dbstat virtual table is used to extract low-level formatting
155226 ** information from an SQLite database in order to implement the
155227 ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
155228 ** for an example implementation.
155229 */
155230
155231 #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
155232 && !defined(SQLITE_OMIT_VIRTUAL_TABLE)
155233
155234 /*
155235 ** Page paths:
155236 **
155237 ** The value of the 'path' column describes the path taken from the
155238 ** root-node of the b-tree structure to each page. The value of the
155239 ** root-node path is '/'.
155240 **
155241 ** The value of the path for the left-most child page of the root of
155242 ** a b-tree is '/000/'. (Btrees store content ordered from left to right
155243 ** so the pages to the left have smaller keys than the pages to the right.)
155244 ** The next to left-most child of the root page is
155245 ** '/001', and so on, each sibling page identified by a 3-digit hex
155246 ** value. The children of the 451st left-most sibling have paths such
155247 ** as '/1c2/000/, '/1c2/001/' etc.
155248 **
155249 ** Overflow pages are specified by appending a '+' character and a
155250 ** six-digit hexadecimal value to the path to the cell they are linked
155251 ** from. For example, the three overflow pages in a chain linked from
155252 ** the left-most cell of the 450th child of the root page are identified
155253 ** by the paths:
155254 **
155255 ** '/1c2/000+000000' // First page in overflow chain
155256 ** '/1c2/000+000001' // Second page in overflow chain
155257 ** '/1c2/000+000002' // Third page in overflow chain
155258 **
155259 ** If the paths are sorted using the BINARY collation sequence, then
155260 ** the overflow pages associated with a cell will appear earlier in the
155261 ** sort-order than its child page:
155262 **
155263 ** '/1c2/000/' // Left-most child of 451st child of root
155264 */
155265 #define VTAB_SCHEMA \
155266 "CREATE TABLE xx( " \
155267 " name STRING, /* Name of table or index */" \
155268 " path INTEGER, /* Path to page from root */" \
155269 " pageno INTEGER, /* Page number */" \
155270 " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \
155271 " ncell INTEGER, /* Cells on page (0 for overflow) */" \
155272 " payload INTEGER, /* Bytes of payload on this page */" \
155273 " unused INTEGER, /* Bytes of unused space on this page */" \
155274 " mx_payload INTEGER, /* Largest payload size of all cells */" \
155275 " pgoffset INTEGER, /* Offset of page in file */" \
155276 " pgsize INTEGER /* Size of the page */" \
155277 ");"
155278
155279
155280 typedef struct StatTable StatTable;
155281 typedef struct StatCursor StatCursor;
155282 typedef struct StatPage StatPage;
155283 typedef struct StatCell StatCell;
155284
155285 struct StatCell {
155286 int nLocal; /* Bytes of local payload */
155287 u32 iChildPg; /* Child node (or 0 if this is a leaf) */
155288 int nOvfl; /* Entries in aOvfl[] */
155289 u32 *aOvfl; /* Array of overflow page numbers */
155290 int nLastOvfl; /* Bytes of payload on final overflow page */
155291 int iOvfl; /* Iterates through aOvfl[] */
155292 };
155293
155294 struct StatPage {
155295 u32 iPgno;
155296 DbPage *pPg;
155297 int iCell;
155298
155299 char *zPath; /* Path to this page */
155300
155301 /* Variables populated by statDecodePage(): */
155302 u8 flags; /* Copy of flags byte */
155303 int nCell; /* Number of cells on page */
155304 int nUnused; /* Number of unused bytes on page */
155305 StatCell *aCell; /* Array of parsed cells */
155306 u32 iRightChildPg; /* Right-child page number (or 0) */
155307 int nMxPayload; /* Largest payload of any cell on this page */
155308 };
155309
155310 struct StatCursor {
155311 sqlite3_vtab_cursor base;
155312 sqlite3_stmt *pStmt; /* Iterates through set of root pages */
155313 int isEof; /* After pStmt has returned SQLITE_DONE */
155314
155315 StatPage aPage[32];
155316 int iPage; /* Current entry in aPage[] */
155317
155318 /* Values to return. */
155319 char *zName; /* Value of 'name' column */
155320 char *zPath; /* Value of 'path' column */
155321 u32 iPageno; /* Value of 'pageno' column */
155322 char *zPagetype; /* Value of 'pagetype' column */
155323 int nCell; /* Value of 'ncell' column */
155324 int nPayload; /* Value of 'payload' column */
155325 int nUnused; /* Value of 'unused' column */
155326 int nMxPayload; /* Value of 'mx_payload' column */
155327 i64 iOffset; /* Value of 'pgOffset' column */
155328 int szPage; /* Value of 'pgSize' column */
155329 };
155330
155331 struct StatTable {
155332 sqlite3_vtab base;
155333 sqlite3 *db;
155334 };
155335
155336 #ifndef get2byte
155337 # define get2byte(x) ((x)[0]<<8 | (x)[1])
155338 #endif
155339
155340 /*
155341 ** Connect to or create a statvfs virtual table.
155342 */
155343 static int statConnect(
155344 sqlite3 *db,
155345 void *pAux,
155346 int argc, const char *const*argv,
155347 sqlite3_vtab **ppVtab,
155348 char **pzErr
155349 ){
155350 StatTable *pTab = 0;
155351 int rc = SQLITE_OK;
155352
155353 rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
155354 if( rc==SQLITE_OK ){
155355 pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
155356 if( pTab==0 ) rc = SQLITE_NOMEM;
155357 }
155358
155359 assert( rc==SQLITE_OK || pTab==0 );
155360 if( rc==SQLITE_OK ){
155361 memset(pTab, 0, sizeof(StatTable));
155362 pTab->db = db;
155363 }
155364
155365 *ppVtab = (sqlite3_vtab*)pTab;
155366 return rc;
155367 }
155368
155369 /*
155370 ** Disconnect from or destroy a statvfs virtual table.
155371 */
155372 static int statDisconnect(sqlite3_vtab *pVtab){
155373 sqlite3_free(pVtab);
155374 return SQLITE_OK;
155375 }
155376
155377 /*
155378 ** There is no "best-index". This virtual table always does a linear
155379 ** scan of the binary VFS log file.
155380 */
155381 static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
155382
155383 /* Records are always returned in ascending order of (name, path).
155384 ** If this will satisfy the client, set the orderByConsumed flag so that
155385 ** SQLite does not do an external sort.
155386 */
155387 if( ( pIdxInfo->nOrderBy==1
155388 && pIdxInfo->aOrderBy[0].iColumn==0
155389 && pIdxInfo->aOrderBy[0].desc==0
155390 ) ||
155391 ( pIdxInfo->nOrderBy==2
155392 && pIdxInfo->aOrderBy[0].iColumn==0
155393 && pIdxInfo->aOrderBy[0].desc==0
155394 && pIdxInfo->aOrderBy[1].iColumn==1
155395 && pIdxInfo->aOrderBy[1].desc==0
155396 )
155397 ){
155398 pIdxInfo->orderByConsumed = 1;
155399 }
155400
155401 pIdxInfo->estimatedCost = 10.0;
155402 return SQLITE_OK;
155403 }
155404
155405 /*
155406 ** Open a new statvfs cursor.
155407 */
155408 static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
155409 StatTable *pTab = (StatTable *)pVTab;
155410 StatCursor *pCsr;
155411 int rc;
155412
155413 pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
155414 if( pCsr==0 ){
155415 rc = SQLITE_NOMEM;
155416 }else{
155417 memset(pCsr, 0, sizeof(StatCursor));
155418 pCsr->base.pVtab = pVTab;
155419
155420 rc = sqlite3_prepare_v2(pTab->db,
155421 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
155422 " UNION ALL "
155423 "SELECT name, rootpage, type FROM sqlite_master WHERE rootpage!=0"
155424 " ORDER BY name", -1,
155425 &pCsr->pStmt, 0
155426 );
155427 if( rc!=SQLITE_OK ){
155428 sqlite3_free(pCsr);
155429 pCsr = 0;
155430 }
155431 }
155432
155433 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
155434 return rc;
155435 }
155436
155437 static void statClearPage(StatPage *p){
155438 int i;
155439 if( p->aCell ){
155440 for(i=0; i<p->nCell; i++){
155441 sqlite3_free(p->aCell[i].aOvfl);
155442 }
155443 sqlite3_free(p->aCell);
155444 }
155445 sqlite3PagerUnref(p->pPg);
155446 sqlite3_free(p->zPath);
155447 memset(p, 0, sizeof(StatPage));
155448 }
155449
155450 static void statResetCsr(StatCursor *pCsr){
155451 int i;
155452 sqlite3_reset(pCsr->pStmt);
155453 for(i=0; i<ArraySize(pCsr->aPage); i++){
155454 statClearPage(&pCsr->aPage[i]);
155455 }
155456 pCsr->iPage = 0;
155457 sqlite3_free(pCsr->zPath);
155458 pCsr->zPath = 0;
155459 }
155460
155461 /*
155462 ** Close a statvfs cursor.
155463 */
155464 static int statClose(sqlite3_vtab_cursor *pCursor){
155465 StatCursor *pCsr = (StatCursor *)pCursor;
155466 statResetCsr(pCsr);
155467 sqlite3_finalize(pCsr->pStmt);
155468 sqlite3_free(pCsr);
155469 return SQLITE_OK;
155470 }
155471
155472 static void getLocalPayload(
155473 int nUsable, /* Usable bytes per page */
155474 u8 flags, /* Page flags */
155475 int nTotal, /* Total record (payload) size */
155476 int *pnLocal /* OUT: Bytes stored locally */
155477 ){
155478 int nLocal;
155479 int nMinLocal;
155480 int nMaxLocal;
155481
155482 if( flags==0x0D ){ /* Table leaf node */
155483 nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155484 nMaxLocal = nUsable - 35;
155485 }else{ /* Index interior and leaf nodes */
155486 nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155487 nMaxLocal = (nUsable - 12) * 64 / 255 - 23;
155488 }
155489
155490 nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4);
155491 if( nLocal>nMaxLocal ) nLocal = nMinLocal;
155492 *pnLocal = nLocal;
155493 }
155494
155495 static int statDecodePage(Btree *pBt, StatPage *p){
155496 int nUnused;
155497 int iOff;
155498 int nHdr;
155499 int isLeaf;
155500 int szPage;
155501
155502 u8 *aData = sqlite3PagerGetData(p->pPg);
155503 u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
155504
155505 p->flags = aHdr[0];
155506 p->nCell = get2byte(&aHdr[3]);
155507 p->nMxPayload = 0;
155508
155509 isLeaf = (p->flags==0x0A || p->flags==0x0D);
155510 nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100;
155511
155512 nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell;
155513 nUnused += (int)aHdr[7];
155514 iOff = get2byte(&aHdr[1]);
155515 while( iOff ){
155516 nUnused += get2byte(&aData[iOff+2]);
155517 iOff = get2byte(&aData[iOff]);
155518 }
155519 p->nUnused = nUnused;
155520 p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
155521 szPage = sqlite3BtreeGetPageSize(pBt);
155522
155523 if( p->nCell ){
155524 int i; /* Used to iterate through cells */
155525 int nUsable; /* Usable bytes per page */
155526
155527 sqlite3BtreeEnter(pBt);
155528 nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt);
155529 sqlite3BtreeLeave(pBt);
155530 p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell));
155531 if( p->aCell==0 ) return SQLITE_NOMEM;
155532 memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
155533
155534 for(i=0; i<p->nCell; i++){
155535 StatCell *pCell = &p->aCell[i];
155536
155537 iOff = get2byte(&aData[nHdr+i*2]);
155538 if( !isLeaf ){
155539 pCell->iChildPg = sqlite3Get4byte(&aData[iOff]);
155540 iOff += 4;
155541 }
155542 if( p->flags==0x05 ){
155543 /* A table interior node. nPayload==0. */
155544 }else{
155545 u32 nPayload; /* Bytes of payload total (local+overflow) */
155546 int nLocal; /* Bytes of payload stored locally */
155547 iOff += getVarint32(&aData[iOff], nPayload);
155548 if( p->flags==0x0D ){
155549 u64 dummy;
155550 iOff += sqlite3GetVarint(&aData[iOff], &dummy);
155551 }
155552 if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload;
155553 getLocalPayload(nUsable, p->flags, nPayload, &nLocal);
155554 pCell->nLocal = nLocal;
155555 assert( nLocal>=0 );
155556 assert( nPayload>=(u32)nLocal );
155557 assert( nLocal<=(nUsable-35) );
155558 if( nPayload>(u32)nLocal ){
155559 int j;
155560 int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
155561 pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
155562 pCell->nOvfl = nOvfl;
155563 pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
155564 if( pCell->aOvfl==0 ) return SQLITE_NOMEM;
155565 pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
155566 for(j=1; j<nOvfl; j++){
155567 int rc;
155568 u32 iPrev = pCell->aOvfl[j-1];
155569 DbPage *pPg = 0;
155570 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg);
155571 if( rc!=SQLITE_OK ){
155572 assert( pPg==0 );
155573 return rc;
155574 }
155575 pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
155576 sqlite3PagerUnref(pPg);
155577 }
155578 }
155579 }
155580 }
155581 }
155582
155583 return SQLITE_OK;
155584 }
155585
155586 /*
155587 ** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
155588 ** the current value of pCsr->iPageno.
155589 */
155590 static void statSizeAndOffset(StatCursor *pCsr){
155591 StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab;
155592 Btree *pBt = pTab->db->aDb[0].pBt;
155593 Pager *pPager = sqlite3BtreePager(pBt);
155594 sqlite3_file *fd;
155595 sqlite3_int64 x[2];
155596
155597 /* The default page size and offset */
155598 pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
155599 pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1);
155600
155601 /* If connected to a ZIPVFS backend, override the page size and
155602 ** offset with actual values obtained from ZIPVFS.
155603 */
155604 fd = sqlite3PagerFile(pPager);
155605 x[0] = pCsr->iPageno;
155606 if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
155607 pCsr->iOffset = x[0];
155608 pCsr->szPage = (int)x[1];
155609 }
155610 }
155611
155612 /*
155613 ** Move a statvfs cursor to the next entry in the file.
155614 */
155615 static int statNext(sqlite3_vtab_cursor *pCursor){
155616 int rc;
155617 int nPayload;
155618 StatCursor *pCsr = (StatCursor *)pCursor;
155619 StatTable *pTab = (StatTable *)pCursor->pVtab;
155620 Btree *pBt = pTab->db->aDb[0].pBt;
155621 Pager *pPager = sqlite3BtreePager(pBt);
155622
155623 sqlite3_free(pCsr->zPath);
155624 pCsr->zPath = 0;
155625
155626 statNextRestart:
155627 if( pCsr->aPage[0].pPg==0 ){
155628 rc = sqlite3_step(pCsr->pStmt);
155629 if( rc==SQLITE_ROW ){
155630 int nPage;
155631 u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1);
155632 sqlite3PagerPagecount(pPager, &nPage);
155633 if( nPage==0 ){
155634 pCsr->isEof = 1;
155635 return sqlite3_reset(pCsr->pStmt);
155636 }
155637 rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
155638 pCsr->aPage[0].iPgno = iRoot;
155639 pCsr->aPage[0].iCell = 0;
155640 pCsr->aPage[0].zPath = sqlite3_mprintf("/");
155641 pCsr->iPage = 0;
155642 }else{
155643 pCsr->isEof = 1;
155644 return sqlite3_reset(pCsr->pStmt);
155645 }
155646 }else{
155647
155648 /* Page p itself has already been visited. */
155649 StatPage *p = &pCsr->aPage[pCsr->iPage];
155650
155651 while( p->iCell<p->nCell ){
155652 StatCell *pCell = &p->aCell[p->iCell];
155653 if( pCell->iOvfl<pCell->nOvfl ){
155654 int nUsable;
155655 sqlite3BtreeEnter(pBt);
155656 nUsable = sqlite3BtreeGetPageSize(pBt) -
155657 sqlite3BtreeGetReserveNoMutex(pBt);
155658 sqlite3BtreeLeave(pBt);
155659 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155660 pCsr->iPageno = pCell->aOvfl[pCell->iOvfl];
155661 pCsr->zPagetype = "overflow";
155662 pCsr->nCell = 0;
155663 pCsr->nMxPayload = 0;
155664 pCsr->zPath = sqlite3_mprintf(
155665 "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl
155666 );
155667 if( pCell->iOvfl<pCell->nOvfl-1 ){
155668 pCsr->nUnused = 0;
155669 pCsr->nPayload = nUsable - 4;
155670 }else{
155671 pCsr->nPayload = pCell->nLastOvfl;
155672 pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
155673 }
155674 pCell->iOvfl++;
155675 statSizeAndOffset(pCsr);
155676 return SQLITE_OK;
155677 }
155678 if( p->iRightChildPg ) break;
155679 p->iCell++;
155680 }
155681
155682 if( !p->iRightChildPg || p->iCell>p->nCell ){
155683 statClearPage(p);
155684 if( pCsr->iPage==0 ) return statNext(pCursor);
155685 pCsr->iPage--;
155686 goto statNextRestart; /* Tail recursion */
155687 }
155688 pCsr->iPage++;
155689 assert( p==&pCsr->aPage[pCsr->iPage-1] );
155690
155691 if( p->iCell==p->nCell ){
155692 p[1].iPgno = p->iRightChildPg;
155693 }else{
155694 p[1].iPgno = p->aCell[p->iCell].iChildPg;
155695 }
155696 rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);
155697 p[1].iCell = 0;
155698 p[1].zPath = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
155699 p->iCell++;
155700 }
155701
155702
155703 /* Populate the StatCursor fields with the values to be returned
155704 ** by the xColumn() and xRowid() methods.
155705 */
155706 if( rc==SQLITE_OK ){
155707 int i;
155708 StatPage *p = &pCsr->aPage[pCsr->iPage];
155709 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155710 pCsr->iPageno = p->iPgno;
155711
155712 rc = statDecodePage(pBt, p);
155713 if( rc==SQLITE_OK ){
155714 statSizeAndOffset(pCsr);
155715
155716 switch( p->flags ){
155717 case 0x05: /* table internal */
155718 case 0x02: /* index internal */
155719 pCsr->zPagetype = "internal";
155720 break;
155721 case 0x0D: /* table leaf */
155722 case 0x0A: /* index leaf */
155723 pCsr->zPagetype = "leaf";
155724 break;
155725 default:
155726 pCsr->zPagetype = "corrupted";
155727 break;
155728 }
155729 pCsr->nCell = p->nCell;
155730 pCsr->nUnused = p->nUnused;
155731 pCsr->nMxPayload = p->nMxPayload;
155732 pCsr->zPath = sqlite3_mprintf("%s", p->zPath);
155733 nPayload = 0;
155734 for(i=0; i<p->nCell; i++){
155735 nPayload += p->aCell[i].nLocal;
155736 }
155737 pCsr->nPayload = nPayload;
155738 }
155739 }
155740
155741 return rc;
155742 }
155743
155744 static int statEof(sqlite3_vtab_cursor *pCursor){
155745 StatCursor *pCsr = (StatCursor *)pCursor;
155746 return pCsr->isEof;
155747 }
155748
155749 static int statFilter(
155750 sqlite3_vtab_cursor *pCursor,
155751 int idxNum, const char *idxStr,
155752 int argc, sqlite3_value **argv
155753 ){
155754 StatCursor *pCsr = (StatCursor *)pCursor;
155755
155756 statResetCsr(pCsr);
155757 return statNext(pCursor);
155758 }
155759
155760 static int statColumn(
155761 sqlite3_vtab_cursor *pCursor,
155762 sqlite3_context *ctx,
155763 int i
155764 ){
155765 StatCursor *pCsr = (StatCursor *)pCursor;
155766 switch( i ){
155767 case 0: /* name */
155768 sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_STATIC);
155769 break;
155770 case 1: /* path */
155771 sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
155772 break;
155773 case 2: /* pageno */
155774 sqlite3_result_int64(ctx, pCsr->iPageno);
155775 break;
155776 case 3: /* pagetype */
155777 sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC);
155778 break;
155779 case 4: /* ncell */
155780 sqlite3_result_int(ctx, pCsr->nCell);
155781 break;
155782 case 5: /* payload */
155783 sqlite3_result_int(ctx, pCsr->nPayload);
155784 break;
155785 case 6: /* unused */
155786 sqlite3_result_int(ctx, pCsr->nUnused);
155787 break;
155788 case 7: /* mx_payload */
155789 sqlite3_result_int(ctx, pCsr->nMxPayload);
155790 break;
155791 case 8: /* pgoffset */
155792 sqlite3_result_int64(ctx, pCsr->iOffset);
155793 break;
155794 case 9: /* pgsize */
155795 sqlite3_result_int(ctx, pCsr->szPage);
155796 break;
155797 }
155798 return SQLITE_OK;
155799 }
155800
155801 static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
155802 StatCursor *pCsr = (StatCursor *)pCursor;
155803 *pRowid = pCsr->iPageno;
155804 return SQLITE_OK;
155805 }
155806
155807 /*
155808 ** Invoke this routine to register the "dbstat" virtual table module
155809 */
155810 SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){
155811 static sqlite3_module dbstat_module = {
155812 0, /* iVersion */
155813 statConnect, /* xCreate */
155814 statConnect, /* xConnect */
155815 statBestIndex, /* xBestIndex */
155816 statDisconnect, /* xDisconnect */
155817 statDisconnect, /* xDestroy */
155818 statOpen, /* xOpen - open a cursor */
155819 statClose, /* xClose - close a cursor */
155820 statFilter, /* xFilter - configure scan constraints */
155821 statNext, /* xNext - advance a cursor */
155822 statEof, /* xEof - check for end of scan */
155823 statColumn, /* xColumn - read data */
155824 statRowid, /* xRowid - read data */
155825 0, /* xUpdate */
155826 0, /* xBegin */
155827 0, /* xSync */
155828 0, /* xCommit */
155829 0, /* xRollback */
155830 0, /* xFindMethod */
155831 0, /* xRename */
155832 };
155833 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
155834 }
155835 #endif /* SQLITE_ENABLE_DBSTAT_VTAB */
155836
155837 /************** End of dbstat.c **********************************************/
155838
+91 -15
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109109
**
110110
** See also: [sqlite3_libversion()],
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114
-#define SQLITE_VERSION "3.8.9"
115
-#define SQLITE_VERSION_NUMBER 3008009
116
-#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
114
+#define SQLITE_VERSION "3.8.10"
115
+#define SQLITE_VERSION_NUMBER 3008010
116
+#define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -268,10 +268,11 @@
268268
# define double sqlite3_int64
269269
#endif
270270
271271
/*
272272
** CAPI3REF: Closing A Database Connection
273
+** DESTRUCTOR: sqlite3
273274
**
274275
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
275276
** for the [sqlite3] object.
276277
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
277278
** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
319320
*/
320321
typedef int (*sqlite3_callback)(void*,int,char**, char**);
321322
322323
/*
323324
** CAPI3REF: One-Step Query Execution Interface
325
+** METHOD: sqlite3
324326
**
325327
** The sqlite3_exec() interface is a convenience wrapper around
326328
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
327329
** that allows an application to run multiple statements of SQL
328330
** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
13761378
*/
13771379
SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
13781380
13791381
/*
13801382
** CAPI3REF: Configure database connections
1383
+** METHOD: sqlite3
13811384
**
13821385
** The sqlite3_db_config() interface is used to make configuration
13831386
** changes to a [database connection]. The interface is similar to
13841387
** [sqlite3_config()] except that the changes apply to a single
13851388
** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
18731876
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
18741877
18751878
18761879
/*
18771880
** CAPI3REF: Enable Or Disable Extended Result Codes
1881
+** METHOD: sqlite3
18781882
**
18791883
** ^The sqlite3_extended_result_codes() routine enables or disables the
18801884
** [extended result codes] feature of SQLite. ^The extended result
18811885
** codes are disabled by default for historical compatibility.
18821886
*/
18831887
SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
18841888
18851889
/*
18861890
** CAPI3REF: Last Insert Rowid
1891
+** METHOD: sqlite3
18871892
**
18881893
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
18891894
** has a unique 64-bit signed
18901895
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
18911896
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
19331938
*/
19341939
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
19351940
19361941
/*
19371942
** CAPI3REF: Count The Number Of Rows Modified
1943
+** METHOD: sqlite3
19381944
**
19391945
** ^This function returns the number of rows modified, inserted or
19401946
** deleted by the most recently completed INSERT, UPDATE or DELETE
19411947
** statement on the database connection specified by the only parameter.
19421948
** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
19851991
*/
19861992
SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
19871993
19881994
/*
19891995
** CAPI3REF: Total Number Of Rows Modified
1996
+** METHOD: sqlite3
19901997
**
19911998
** ^This function returns the total number of rows inserted, modified or
19921999
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
19932000
** since the database connection was opened, including those executed as
19942001
** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
20082015
*/
20092016
SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
20102017
20112018
/*
20122019
** CAPI3REF: Interrupt A Long-Running Query
2020
+** METHOD: sqlite3
20132021
**
20142022
** ^This function causes any pending database operation to abort and
20152023
** return at its earliest opportunity. This routine is typically
20162024
** called in response to a user action such as pressing "Cancel"
20172025
** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
20842092
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
20852093
20862094
/*
20872095
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
20882096
** KEYWORDS: {busy-handler callback} {busy handler}
2097
+** METHOD: sqlite3
20892098
**
20902099
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
20912100
** that might be invoked with argument P whenever
20922101
** an attempt is made to access a database table associated with
20932102
** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
21432152
*/
21442153
SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
21452154
21462155
/*
21472156
** CAPI3REF: Set A Busy Timeout
2157
+** METHOD: sqlite3
21482158
**
21492159
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
21502160
** for a specified amount of time when a table is locked. ^The handler
21512161
** will sleep multiple times until at least "ms" milliseconds of sleeping
21522162
** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
21652175
*/
21662176
SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
21672177
21682178
/*
21692179
** CAPI3REF: Convenience Routines For Running Queries
2180
+** METHOD: sqlite3
21702181
**
21712182
** This is a legacy interface that is preserved for backwards compatibility.
21722183
** Use of this interface is not recommended.
21732184
**
21742185
** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
25002511
*/
25012512
SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
25022513
25032514
/*
25042515
** CAPI3REF: Compile-Time Authorization Callbacks
2516
+** METHOD: sqlite3
25052517
**
25062518
** ^This routine registers an authorizer callback with a particular
25072519
** [database connection], supplied in the first argument.
25082520
** ^The authorizer callback is invoked as SQL statements are being compiled
25092521
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
26562668
#define SQLITE_COPY 0 /* No longer used */
26572669
#define SQLITE_RECURSIVE 33 /* NULL NULL */
26582670
26592671
/*
26602672
** CAPI3REF: Tracing And Profiling Functions
2673
+** METHOD: sqlite3
26612674
**
26622675
** These routines register callback functions that can be used for
26632676
** tracing and profiling the execution of SQL statements.
26642677
**
26652678
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
26882701
SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
26892702
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
26902703
26912704
/*
26922705
** CAPI3REF: Query Progress Callbacks
2706
+** METHOD: sqlite3
26932707
**
26942708
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
26952709
** function X to be invoked periodically during long running calls to
26962710
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
26972711
** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
27212735
*/
27222736
SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
27232737
27242738
/*
27252739
** CAPI3REF: Opening A New Database Connection
2740
+** CONSTRUCTOR: sqlite3
27262741
**
27272742
** ^These routines open an SQLite database file as specified by the
27282743
** filename argument. ^The filename argument is interpreted as UTF-8 for
27292744
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
27302745
** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
30063021
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
30073022
30083023
30093024
/*
30103025
** CAPI3REF: Error Codes And Messages
3026
+** METHOD: sqlite3
30113027
**
30123028
** ^If the most recent sqlite3_* API call associated with
30133029
** [database connection] D failed, then the sqlite3_errcode(D) interface
30143030
** returns the numeric [result code] or [extended result code] for that
30153031
** API call.
@@ -3051,37 +3067,38 @@
30513067
SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
30523068
SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
30533069
SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
30543070
30553071
/*
3056
-** CAPI3REF: SQL Statement Object
3072
+** CAPI3REF: Prepared Statement Object
30573073
** KEYWORDS: {prepared statement} {prepared statements}
30583074
**
3059
-** An instance of this object represents a single SQL statement.
3060
-** This object is variously known as a "prepared statement" or a
3061
-** "compiled SQL statement" or simply as a "statement".
3075
+** An instance of this object represents a single SQL statement that
3076
+** has been compiled into binary form and is ready to be evaluated.
30623077
**
3063
-** The life of a statement object goes something like this:
3078
+** Think of each SQL statement as a separate computer program. The
3079
+** original SQL text is source code. A prepared statement object
3080
+** is the compiled object code. All SQL must be converted into a
3081
+** prepared statement before it can be run.
3082
+**
3083
+** The life-cycle of a prepared statement object usually goes like this:
30643084
**
30653085
** <ol>
3066
-** <li> Create the object using [sqlite3_prepare_v2()] or a related
3067
-** function.
3068
-** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3086
+** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3087
+** <li> Bind values to [parameters] using the sqlite3_bind_*()
30693088
** interfaces.
30703089
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3071
-** <li> Reset the statement using [sqlite3_reset()] then go back
3090
+** <li> Reset the prepared statement using [sqlite3_reset()] then go back
30723091
** to step 2. Do this zero or more times.
30733092
** <li> Destroy the object using [sqlite3_finalize()].
30743093
** </ol>
3075
-**
3076
-** Refer to documentation on individual methods above for additional
3077
-** information.
30783094
*/
30793095
typedef struct sqlite3_stmt sqlite3_stmt;
30803096
30813097
/*
30823098
** CAPI3REF: Run-time Limits
3099
+** METHOD: sqlite3
30833100
**
30843101
** ^(This interface allows the size of various constructs to be limited
30853102
** on a connection by connection basis. The first parameter is the
30863103
** [database connection] whose limit is to be set or queried. The
30873104
** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
31893206
#define SQLITE_LIMIT_WORKER_THREADS 11
31903207
31913208
/*
31923209
** CAPI3REF: Compiling An SQL Statement
31933210
** KEYWORDS: {SQL statement compiler}
3211
+** METHOD: sqlite3
3212
+** CONSTRUCTOR: sqlite3_stmt
31943213
**
31953214
** To execute an SQL query, it must first be compiled into a byte-code
31963215
** program using one of these routines.
31973216
**
31983217
** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
32963315
const void **pzTail /* OUT: Pointer to unused portion of zSql */
32973316
);
32983317
32993318
/*
33003319
** CAPI3REF: Retrieving Statement SQL
3320
+** METHOD: sqlite3_stmt
33013321
**
33023322
** ^This interface can be used to retrieve a saved copy of the original
33033323
** SQL text used to create a [prepared statement] if that statement was
33043324
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
33053325
*/
33063326
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
33073327
33083328
/*
33093329
** CAPI3REF: Determine If An SQL Statement Writes The Database
3330
+** METHOD: sqlite3_stmt
33103331
**
33113332
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
33123333
** and only if the [prepared statement] X makes no direct changes to
33133334
** the content of the database file.
33143335
**
@@ -3336,10 +3357,11 @@
33363357
*/
33373358
SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
33383359
33393360
/*
33403361
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3362
+** METHOD: sqlite3_stmt
33413363
**
33423364
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
33433365
** [prepared statement] S has been stepped at least once using
33443366
** [sqlite3_step(S)] but has not run to completion and/or has not
33453367
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
34103432
34113433
/*
34123434
** CAPI3REF: Binding Values To Prepared Statements
34133435
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
34143436
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3437
+** METHOD: sqlite3_stmt
34153438
**
34163439
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
34173440
** literals may be replaced by a [parameter] that matches one of following
34183441
** templates:
34193442
**
@@ -3528,10 +3551,11 @@
35283551
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
35293552
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
35303553
35313554
/*
35323555
** CAPI3REF: Number Of SQL Parameters
3556
+** METHOD: sqlite3_stmt
35333557
**
35343558
** ^This routine can be used to find the number of [SQL parameters]
35353559
** in a [prepared statement]. SQL parameters are tokens of the
35363560
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
35373561
** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
35483572
*/
35493573
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
35503574
35513575
/*
35523576
** CAPI3REF: Name Of A Host Parameter
3577
+** METHOD: sqlite3_stmt
35533578
**
35543579
** ^The sqlite3_bind_parameter_name(P,N) interface returns
35553580
** the name of the N-th [SQL parameter] in the [prepared statement] P.
35563581
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
35573582
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
35753600
*/
35763601
SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
35773602
35783603
/*
35793604
** CAPI3REF: Index Of A Parameter With A Given Name
3605
+** METHOD: sqlite3_stmt
35803606
**
35813607
** ^Return the index of an SQL parameter given its name. ^The
35823608
** index value returned is suitable for use as the second
35833609
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
35843610
** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
35913617
*/
35923618
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
35933619
35943620
/*
35953621
** CAPI3REF: Reset All Bindings On A Prepared Statement
3622
+** METHOD: sqlite3_stmt
35963623
**
35973624
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
35983625
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
35993626
** ^Use this routine to reset all host parameters to NULL.
36003627
*/
36013628
SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
36023629
36033630
/*
36043631
** CAPI3REF: Number Of Columns In A Result Set
3632
+** METHOD: sqlite3_stmt
36053633
**
36063634
** ^Return the number of columns in the result set returned by the
36073635
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
36083636
** statement that does not return data (for example an [UPDATE]).
36093637
**
@@ -3611,10 +3639,11 @@
36113639
*/
36123640
SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
36133641
36143642
/*
36153643
** CAPI3REF: Column Names In A Result Set
3644
+** METHOD: sqlite3_stmt
36163645
**
36173646
** ^These routines return the name assigned to a particular column
36183647
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
36193648
** interface returns a pointer to a zero-terminated UTF-8 string
36203649
** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
36403669
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
36413670
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
36423671
36433672
/*
36443673
** CAPI3REF: Source Of Data In A Query Result
3674
+** METHOD: sqlite3_stmt
36453675
**
36463676
** ^These routines provide a means to determine the database, table, and
36473677
** table column that is the origin of a particular result column in
36483678
** [SELECT] statement.
36493679
** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
36923722
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
36933723
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
36943724
36953725
/*
36963726
** CAPI3REF: Declared Datatype Of A Query Result
3727
+** METHOD: sqlite3_stmt
36973728
**
36983729
** ^(The first parameter is a [prepared statement].
36993730
** If this statement is a [SELECT] statement and the Nth column of the
37003731
** returned result set of that [SELECT] is a table column (not an
37013732
** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
37243755
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
37253756
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
37263757
37273758
/*
37283759
** CAPI3REF: Evaluate An SQL Statement
3760
+** METHOD: sqlite3_stmt
37293761
**
37303762
** After a [prepared statement] has been prepared using either
37313763
** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
37323764
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
37333765
** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
38033835
*/
38043836
SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
38053837
38063838
/*
38073839
** CAPI3REF: Number of columns in a result set
3840
+** METHOD: sqlite3_stmt
38083841
**
38093842
** ^The sqlite3_data_count(P) interface returns the number of columns in the
38103843
** current row of the result set of [prepared statement] P.
38113844
** ^If prepared statement P does not have results ready to return
38123845
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
38563889
#define SQLITE3_TEXT 3
38573890
38583891
/*
38593892
** CAPI3REF: Result Values From A Query
38603893
** KEYWORDS: {column access functions}
3894
+** METHOD: sqlite3_stmt
38613895
**
38623896
** These routines form the "result set" interface.
38633897
**
38643898
** ^These routines return information about a single column of the current
38653899
** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
40284062
SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
40294063
SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
40304064
40314065
/*
40324066
** CAPI3REF: Destroy A Prepared Statement Object
4067
+** DESTRUCTOR: sqlite3_stmt
40334068
**
40344069
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
40354070
** ^If the most recent evaluation of the statement encountered no errors
40364071
** or if the statement is never been evaluated, then sqlite3_finalize() returns
40374072
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
40554090
*/
40564091
SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
40574092
40584093
/*
40594094
** CAPI3REF: Reset A Prepared Statement Object
4095
+** METHOD: sqlite3_stmt
40604096
**
40614097
** The sqlite3_reset() function is called to reset a [prepared statement]
40624098
** object back to its initial state, ready to be re-executed.
40634099
** ^Any SQL statement variables that had values bound to them using
40644100
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
40844120
/*
40854121
** CAPI3REF: Create Or Redefine SQL Functions
40864122
** KEYWORDS: {function creation routines}
40874123
** KEYWORDS: {application-defined SQL function}
40884124
** KEYWORDS: {application-defined SQL functions}
4125
+** METHOD: sqlite3
40894126
**
40904127
** ^These functions (collectively known as "function creation routines")
40914128
** are used to add SQL functions or aggregates or to redefine the behavior
40924129
** of existing SQL functions or aggregates. The only differences between
40934130
** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
42534290
void*,sqlite3_int64);
42544291
#endif
42554292
42564293
/*
42574294
** CAPI3REF: Obtaining SQL Function Parameter Values
4295
+** METHOD: sqlite3_value
42584296
**
42594297
** The C-language implementation of SQL functions and aggregates uses
42604298
** this set of interface routines to access the parameter values on
42614299
** the function or aggregate.
42624300
**
@@ -4311,10 +4349,11 @@
43114349
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
43124350
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
43134351
43144352
/*
43154353
** CAPI3REF: Obtain Aggregate Function Context
4354
+** METHOD: sqlite3_context
43164355
**
43174356
** Implementations of aggregate SQL functions use this
43184357
** routine to allocate memory for storing their state.
43194358
**
43204359
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
43554394
*/
43564395
SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
43574396
43584397
/*
43594398
** CAPI3REF: User Data For Functions
4399
+** METHOD: sqlite3_context
43604400
**
43614401
** ^The sqlite3_user_data() interface returns a copy of
43624402
** the pointer that was the pUserData parameter (the 5th parameter)
43634403
** of the [sqlite3_create_function()]
43644404
** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
43694409
*/
43704410
SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
43714411
43724412
/*
43734413
** CAPI3REF: Database Connection For Functions
4414
+** METHOD: sqlite3_context
43744415
**
43754416
** ^The sqlite3_context_db_handle() interface returns a copy of
43764417
** the pointer to the [database connection] (the 1st parameter)
43774418
** of the [sqlite3_create_function()]
43784419
** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
43804421
*/
43814422
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
43824423
43834424
/*
43844425
** CAPI3REF: Function Auxiliary Data
4426
+** METHOD: sqlite3_context
43854427
**
43864428
** These functions may be used by (non-aggregate) SQL functions to
43874429
** associate metadata with argument values. If the same value is passed to
43884430
** multiple invocations of the same SQL function during query execution, under
43894431
** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
44524494
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
44534495
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
44544496
44554497
/*
44564498
** CAPI3REF: Setting The Result Of An SQL Function
4499
+** METHOD: sqlite3_context
44574500
**
44584501
** These routines are used by the xFunc or xFinal callbacks that
44594502
** implement SQL functions and aggregates. See
44604503
** [sqlite3_create_function()] and [sqlite3_create_function16()]
44614504
** for additional information.
@@ -4587,10 +4630,11 @@
45874630
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
45884631
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
45894632
45904633
/*
45914634
** CAPI3REF: Define New Collating Sequences
4635
+** METHOD: sqlite3
45924636
**
45934637
** ^These functions add, remove, or modify a [collation] associated
45944638
** with the [database connection] specified as the first argument.
45954639
**
45964640
** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
46894733
int(*xCompare)(void*,int,const void*,int,const void*)
46904734
);
46914735
46924736
/*
46934737
** CAPI3REF: Collation Needed Callbacks
4738
+** METHOD: sqlite3
46944739
**
46954740
** ^To avoid having to register all collation sequences before a database
46964741
** can be used, a single callback function may be registered with the
46974742
** [database connection] to be invoked whenever an undefined collation
46984743
** sequence is required.
@@ -4896,10 +4941,11 @@
48964941
SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
48974942
48984943
/*
48994944
** CAPI3REF: Test For Auto-Commit Mode
49004945
** KEYWORDS: {autocommit mode}
4946
+** METHOD: sqlite3
49014947
**
49024948
** ^The sqlite3_get_autocommit() interface returns non-zero or
49034949
** zero if the given database connection is or is not in autocommit mode,
49044950
** respectively. ^Autocommit mode is on by default.
49054951
** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
49184964
*/
49194965
SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
49204966
49214967
/*
49224968
** CAPI3REF: Find The Database Handle Of A Prepared Statement
4969
+** METHOD: sqlite3_stmt
49234970
**
49244971
** ^The sqlite3_db_handle interface returns the [database connection] handle
49254972
** to which a [prepared statement] belongs. ^The [database connection]
49264973
** returned by sqlite3_db_handle is the same [database connection]
49274974
** that was the first argument
@@ -4930,10 +4977,11 @@
49304977
*/
49314978
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
49324979
49334980
/*
49344981
** CAPI3REF: Return The Filename For A Database Connection
4982
+** METHOD: sqlite3
49354983
**
49364984
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
49374985
** associated with database N of connection D. ^The main database file
49384986
** has the name "main". If there is no attached database N on the database
49394987
** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
49464994
*/
49474995
SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
49484996
49494997
/*
49504998
** CAPI3REF: Determine if a database is read-only
4999
+** METHOD: sqlite3
49515000
**
49525001
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
49535002
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
49545003
** the name of a database on connection D.
49555004
*/
49565005
SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
49575006
49585007
/*
49595008
** CAPI3REF: Find the next prepared statement
5009
+** METHOD: sqlite3
49605010
**
49615011
** ^This interface returns a pointer to the next [prepared statement] after
49625012
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
49635013
** then this interface returns a pointer to the first prepared statement
49645014
** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
49705020
*/
49715021
SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
49725022
49735023
/*
49745024
** CAPI3REF: Commit And Rollback Notification Callbacks
5025
+** METHOD: sqlite3
49755026
**
49765027
** ^The sqlite3_commit_hook() interface registers a callback
49775028
** function to be invoked whenever a transaction is [COMMIT | committed].
49785029
** ^Any callback set by a previous call to sqlite3_commit_hook()
49795030
** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
50195070
SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
50205071
SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
50215072
50225073
/*
50235074
** CAPI3REF: Data Change Notification Callbacks
5075
+** METHOD: sqlite3
50245076
**
50255077
** ^The sqlite3_update_hook() interface registers a callback function
50265078
** with the [database connection] identified by the first argument
50275079
** to be invoked whenever a row is updated, inserted or deleted in
50285080
** a rowid table.
@@ -5125,10 +5177,11 @@
51255177
*/
51265178
SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
51275179
51285180
/*
51295181
** CAPI3REF: Free Memory Used By A Database Connection
5182
+** METHOD: sqlite3
51305183
**
51315184
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
51325185
** memory as possible from database connection D. Unlike the
51335186
** [sqlite3_release_memory()] interface, this interface is in effect even
51345187
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
52025255
SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
52035256
52045257
52055258
/*
52065259
** CAPI3REF: Extract Metadata About A Column Of A Table
5260
+** METHOD: sqlite3
52075261
**
52085262
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
52095263
** information about column C of table T in database D
52105264
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
52115265
** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
52805334
int *pAutoinc /* OUTPUT: True if column is auto-increment */
52815335
);
52825336
52835337
/*
52845338
** CAPI3REF: Load An Extension
5339
+** METHOD: sqlite3
52855340
**
52865341
** ^This interface loads an SQLite extension library from the named file.
52875342
**
52885343
** ^The sqlite3_load_extension() interface attempts to load an
52895344
** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
53215376
char **pzErrMsg /* Put error message here if not 0 */
53225377
);
53235378
53245379
/*
53255380
** CAPI3REF: Enable Or Disable Extension Loading
5381
+** METHOD: sqlite3
53265382
**
53275383
** ^So as not to open security holes in older applications that are
53285384
** unprepared to deal with [extension loading], and as a means of disabling
53295385
** [extension loading] while evaluating user-entered SQL, the following API
53305386
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
55705626
#define SQLITE_INDEX_CONSTRAINT_GE 32
55715627
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
55725628
55735629
/*
55745630
** CAPI3REF: Register A Virtual Table Implementation
5631
+** METHOD: sqlite3
55755632
**
55765633
** ^These routines are used to register a new [virtual table module] name.
55775634
** ^Module names must be registered before
55785635
** creating a new [virtual table] using the module and before using a
55795636
** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
56665723
*/
56675724
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
56685725
56695726
/*
56705727
** CAPI3REF: Overload A Function For A Virtual Table
5728
+** METHOD: sqlite3
56715729
**
56725730
** ^(Virtual tables can provide alternative implementations of functions
56735731
** using the [xFindFunction] method of the [virtual table module].
56745732
** But global versions of those functions
56755733
** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
57085766
*/
57095767
typedef struct sqlite3_blob sqlite3_blob;
57105768
57115769
/*
57125770
** CAPI3REF: Open A BLOB For Incremental I/O
5771
+** METHOD: sqlite3
5772
+** CONSTRUCTOR: sqlite3_blob
57135773
**
57145774
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
57155775
** in row iRow, column zColumn, table zTable in database zDb;
57165776
** in other words, the same BLOB that would be selected by:
57175777
**
@@ -5789,10 +5849,11 @@
57895849
sqlite3_blob **ppBlob
57905850
);
57915851
57925852
/*
57935853
** CAPI3REF: Move a BLOB Handle to a New Row
5854
+** METHOD: sqlite3_blob
57945855
**
57955856
** ^This function is used to move an existing blob handle so that it points
57965857
** to a different row of the same database table. ^The new row is identified
57975858
** by the rowid value passed as the second argument. Only the row can be
57985859
** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
58135874
*/
58145875
SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
58155876
58165877
/*
58175878
** CAPI3REF: Close A BLOB Handle
5879
+** DESTRUCTOR: sqlite3_blob
58185880
**
58195881
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
58205882
** unconditionally. Even if this routine returns an error code, the
58215883
** handle is still closed.)^
58225884
**
@@ -5835,10 +5897,11 @@
58355897
*/
58365898
SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
58375899
58385900
/*
58395901
** CAPI3REF: Return The Size Of An Open BLOB
5902
+** METHOD: sqlite3_blob
58405903
**
58415904
** ^Returns the size in bytes of the BLOB accessible via the
58425905
** successfully opened [BLOB handle] in its only argument. ^The
58435906
** incremental blob I/O routines can only read or overwriting existing
58445907
** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
58505913
*/
58515914
SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
58525915
58535916
/*
58545917
** CAPI3REF: Read Data From A BLOB Incrementally
5918
+** METHOD: sqlite3_blob
58555919
**
58565920
** ^(This function is used to read data from an open [BLOB handle] into a
58575921
** caller-supplied buffer. N bytes of data are copied into buffer Z
58585922
** from the open BLOB, starting at offset iOffset.)^
58595923
**
@@ -5878,10 +5942,11 @@
58785942
*/
58795943
SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
58805944
58815945
/*
58825946
** CAPI3REF: Write Data Into A BLOB Incrementally
5947
+** METHOD: sqlite3_blob
58835948
**
58845949
** ^(This function is used to write data into an open [BLOB handle] from a
58855950
** caller-supplied buffer. N bytes of data are copied from the buffer Z
58865951
** into the open BLOB, starting at offset iOffset.)^
58875952
**
@@ -6205,10 +6270,11 @@
62056270
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
62066271
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
62076272
62086273
/*
62096274
** CAPI3REF: Retrieve the mutex for a database connection
6275
+** METHOD: sqlite3
62106276
**
62116277
** ^This interface returns a pointer the [sqlite3_mutex] object that
62126278
** serializes access to the [database connection] given in the argument
62136279
** when the [threading mode] is Serialized.
62146280
** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
62166282
*/
62176283
SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
62186284
62196285
/*
62206286
** CAPI3REF: Low-Level Control Of Database Files
6287
+** METHOD: sqlite3
62216288
**
62226289
** ^The [sqlite3_file_control()] interface makes a direct call to the
62236290
** xFileControl method for the [sqlite3_io_methods] object associated
62246291
** with a particular database identified by the second argument. ^The
62256292
** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
64326499
#define SQLITE_STATUS_SCRATCH_SIZE 8
64336500
#define SQLITE_STATUS_MALLOC_COUNT 9
64346501
64356502
/*
64366503
** CAPI3REF: Database Connection Status
6504
+** METHOD: sqlite3
64376505
**
64386506
** ^This interface is used to retrieve runtime status information
64396507
** about a single [database connection]. ^The first argument is the
64406508
** database connection object to be interrogated. ^The second argument
64416509
** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
65606628
#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
65616629
65626630
65636631
/*
65646632
** CAPI3REF: Prepared Statement Status
6633
+** METHOD: sqlite3_stmt
65656634
**
65666635
** ^(Each prepared statement maintains various
65676636
** [SQLITE_STMTSTATUS counters] that measure the number
65686637
** of times it has performed specific operations.)^ These counters can
65696638
** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
70637132
SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
70647133
SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
70657134
70667135
/*
70677136
** CAPI3REF: Unlock Notification
7137
+** METHOD: sqlite3
70687138
**
70697139
** ^When running in shared-cache mode, a database operation may fail with
70707140
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
70717141
** individual tables within the shared-cache cannot be obtained. See
70727142
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
72337303
*/
72347304
SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
72357305
72367306
/*
72377307
** CAPI3REF: Write-Ahead Log Commit Hook
7308
+** METHOD: sqlite3
72387309
**
72397310
** ^The [sqlite3_wal_hook()] function is used to register a callback that
72407311
** is invoked each time data is committed to a database in wal mode.
72417312
**
72427313
** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
72727343
void*
72737344
);
72747345
72757346
/*
72767347
** CAPI3REF: Configure an auto-checkpoint
7348
+** METHOD: sqlite3
72777349
**
72787350
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
72797351
** [sqlite3_wal_hook()] that causes any database on [database connection] D
72807352
** to automatically [checkpoint]
72817353
** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
73027374
*/
73037375
SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
73047376
73057377
/*
73067378
** CAPI3REF: Checkpoint a database
7379
+** METHOD: sqlite3
73077380
**
73087381
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
73097382
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
73107383
**
73117384
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
73237396
*/
73247397
SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
73257398
73267399
/*
73277400
** CAPI3REF: Checkpoint a database
7401
+** METHOD: sqlite3
73287402
**
73297403
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
73307404
** operation on database X of [database connection] D in mode M. Status
73317405
** information is written back into integers pointed to by L and C.)^
73327406
** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
75777651
#define SQLITE_SCANSTAT_EXPLAIN 4
75787652
#define SQLITE_SCANSTAT_SELECTID 5
75797653
75807654
/*
75817655
** CAPI3REF: Prepared Statement Scan Status
7656
+** METHOD: sqlite3_stmt
75827657
**
75837658
** This interface returns information about the predicted and measured
75847659
** performance for pStmt. Advanced applications can use this
75857660
** interface to compare the predicted and the measured performance and
75867661
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
76147689
void *pOut /* Result written here */
76157690
);
76167691
76177692
/*
76187693
** CAPI3REF: Zero Scan-Status Counters
7694
+** METHOD: sqlite3_stmt
76197695
**
76207696
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
76217697
**
76227698
** This API is only available if the library is built with pre-processor
76237699
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
76247700
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.9"
115 #define SQLITE_VERSION_NUMBER 3008009
116 #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -268,10 +268,11 @@
268 # define double sqlite3_int64
269 #endif
270
271 /*
272 ** CAPI3REF: Closing A Database Connection
 
273 **
274 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
275 ** for the [sqlite3] object.
276 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
277 ** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
319 */
320 typedef int (*sqlite3_callback)(void*,int,char**, char**);
321
322 /*
323 ** CAPI3REF: One-Step Query Execution Interface
 
324 **
325 ** The sqlite3_exec() interface is a convenience wrapper around
326 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
327 ** that allows an application to run multiple statements of SQL
328 ** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
1376 */
1377 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1378
1379 /*
1380 ** CAPI3REF: Configure database connections
 
1381 **
1382 ** The sqlite3_db_config() interface is used to make configuration
1383 ** changes to a [database connection]. The interface is similar to
1384 ** [sqlite3_config()] except that the changes apply to a single
1385 ** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
1873 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1874
1875
1876 /*
1877 ** CAPI3REF: Enable Or Disable Extended Result Codes
 
1878 **
1879 ** ^The sqlite3_extended_result_codes() routine enables or disables the
1880 ** [extended result codes] feature of SQLite. ^The extended result
1881 ** codes are disabled by default for historical compatibility.
1882 */
1883 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
1884
1885 /*
1886 ** CAPI3REF: Last Insert Rowid
 
1887 **
1888 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1889 ** has a unique 64-bit signed
1890 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1891 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
1933 */
1934 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
1935
1936 /*
1937 ** CAPI3REF: Count The Number Of Rows Modified
 
1938 **
1939 ** ^This function returns the number of rows modified, inserted or
1940 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1941 ** statement on the database connection specified by the only parameter.
1942 ** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
1985 */
1986 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
1987
1988 /*
1989 ** CAPI3REF: Total Number Of Rows Modified
 
1990 **
1991 ** ^This function returns the total number of rows inserted, modified or
1992 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
1993 ** since the database connection was opened, including those executed as
1994 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
2008 */
2009 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2010
2011 /*
2012 ** CAPI3REF: Interrupt A Long-Running Query
 
2013 **
2014 ** ^This function causes any pending database operation to abort and
2015 ** return at its earliest opportunity. This routine is typically
2016 ** called in response to a user action such as pressing "Cancel"
2017 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
2084 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2085
2086 /*
2087 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2088 ** KEYWORDS: {busy-handler callback} {busy handler}
 
2089 **
2090 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2091 ** that might be invoked with argument P whenever
2092 ** an attempt is made to access a database table associated with
2093 ** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
2143 */
2144 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2145
2146 /*
2147 ** CAPI3REF: Set A Busy Timeout
 
2148 **
2149 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2150 ** for a specified amount of time when a table is locked. ^The handler
2151 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2152 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
2165 */
2166 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2167
2168 /*
2169 ** CAPI3REF: Convenience Routines For Running Queries
 
2170 **
2171 ** This is a legacy interface that is preserved for backwards compatibility.
2172 ** Use of this interface is not recommended.
2173 **
2174 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
2500 */
2501 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2502
2503 /*
2504 ** CAPI3REF: Compile-Time Authorization Callbacks
 
2505 **
2506 ** ^This routine registers an authorizer callback with a particular
2507 ** [database connection], supplied in the first argument.
2508 ** ^The authorizer callback is invoked as SQL statements are being compiled
2509 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
2656 #define SQLITE_COPY 0 /* No longer used */
2657 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2658
2659 /*
2660 ** CAPI3REF: Tracing And Profiling Functions
 
2661 **
2662 ** These routines register callback functions that can be used for
2663 ** tracing and profiling the execution of SQL statements.
2664 **
2665 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
2688 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2689 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2690
2691 /*
2692 ** CAPI3REF: Query Progress Callbacks
 
2693 **
2694 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2695 ** function X to be invoked periodically during long running calls to
2696 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2697 ** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
2721 */
2722 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2723
2724 /*
2725 ** CAPI3REF: Opening A New Database Connection
 
2726 **
2727 ** ^These routines open an SQLite database file as specified by the
2728 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2729 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2730 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
3006 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3007
3008
3009 /*
3010 ** CAPI3REF: Error Codes And Messages
 
3011 **
3012 ** ^If the most recent sqlite3_* API call associated with
3013 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3014 ** returns the numeric [result code] or [extended result code] for that
3015 ** API call.
@@ -3051,37 +3067,38 @@
3051 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3052 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3053 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3054
3055 /*
3056 ** CAPI3REF: SQL Statement Object
3057 ** KEYWORDS: {prepared statement} {prepared statements}
3058 **
3059 ** An instance of this object represents a single SQL statement.
3060 ** This object is variously known as a "prepared statement" or a
3061 ** "compiled SQL statement" or simply as a "statement".
3062 **
3063 ** The life of a statement object goes something like this:
 
 
 
 
 
3064 **
3065 ** <ol>
3066 ** <li> Create the object using [sqlite3_prepare_v2()] or a related
3067 ** function.
3068 ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3069 ** interfaces.
3070 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3071 ** <li> Reset the statement using [sqlite3_reset()] then go back
3072 ** to step 2. Do this zero or more times.
3073 ** <li> Destroy the object using [sqlite3_finalize()].
3074 ** </ol>
3075 **
3076 ** Refer to documentation on individual methods above for additional
3077 ** information.
3078 */
3079 typedef struct sqlite3_stmt sqlite3_stmt;
3080
3081 /*
3082 ** CAPI3REF: Run-time Limits
 
3083 **
3084 ** ^(This interface allows the size of various constructs to be limited
3085 ** on a connection by connection basis. The first parameter is the
3086 ** [database connection] whose limit is to be set or queried. The
3087 ** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
3189 #define SQLITE_LIMIT_WORKER_THREADS 11
3190
3191 /*
3192 ** CAPI3REF: Compiling An SQL Statement
3193 ** KEYWORDS: {SQL statement compiler}
 
 
3194 **
3195 ** To execute an SQL query, it must first be compiled into a byte-code
3196 ** program using one of these routines.
3197 **
3198 ** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
3296 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3297 );
3298
3299 /*
3300 ** CAPI3REF: Retrieving Statement SQL
 
3301 **
3302 ** ^This interface can be used to retrieve a saved copy of the original
3303 ** SQL text used to create a [prepared statement] if that statement was
3304 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3305 */
3306 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3307
3308 /*
3309 ** CAPI3REF: Determine If An SQL Statement Writes The Database
 
3310 **
3311 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3312 ** and only if the [prepared statement] X makes no direct changes to
3313 ** the content of the database file.
3314 **
@@ -3336,10 +3357,11 @@
3336 */
3337 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3338
3339 /*
3340 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
 
3341 **
3342 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3343 ** [prepared statement] S has been stepped at least once using
3344 ** [sqlite3_step(S)] but has not run to completion and/or has not
3345 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
3410
3411 /*
3412 ** CAPI3REF: Binding Values To Prepared Statements
3413 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3414 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 
3415 **
3416 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3417 ** literals may be replaced by a [parameter] that matches one of following
3418 ** templates:
3419 **
@@ -3528,10 +3551,11 @@
3528 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3529 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3530
3531 /*
3532 ** CAPI3REF: Number Of SQL Parameters
 
3533 **
3534 ** ^This routine can be used to find the number of [SQL parameters]
3535 ** in a [prepared statement]. SQL parameters are tokens of the
3536 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3537 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
3548 */
3549 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3550
3551 /*
3552 ** CAPI3REF: Name Of A Host Parameter
 
3553 **
3554 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3555 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3556 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3557 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
3575 */
3576 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3577
3578 /*
3579 ** CAPI3REF: Index Of A Parameter With A Given Name
 
3580 **
3581 ** ^Return the index of an SQL parameter given its name. ^The
3582 ** index value returned is suitable for use as the second
3583 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3584 ** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
3591 */
3592 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3593
3594 /*
3595 ** CAPI3REF: Reset All Bindings On A Prepared Statement
 
3596 **
3597 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3598 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3599 ** ^Use this routine to reset all host parameters to NULL.
3600 */
3601 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3602
3603 /*
3604 ** CAPI3REF: Number Of Columns In A Result Set
 
3605 **
3606 ** ^Return the number of columns in the result set returned by the
3607 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3608 ** statement that does not return data (for example an [UPDATE]).
3609 **
@@ -3611,10 +3639,11 @@
3611 */
3612 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3613
3614 /*
3615 ** CAPI3REF: Column Names In A Result Set
 
3616 **
3617 ** ^These routines return the name assigned to a particular column
3618 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3619 ** interface returns a pointer to a zero-terminated UTF-8 string
3620 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
3640 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3641 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3642
3643 /*
3644 ** CAPI3REF: Source Of Data In A Query Result
 
3645 **
3646 ** ^These routines provide a means to determine the database, table, and
3647 ** table column that is the origin of a particular result column in
3648 ** [SELECT] statement.
3649 ** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
3692 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3693 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3694
3695 /*
3696 ** CAPI3REF: Declared Datatype Of A Query Result
 
3697 **
3698 ** ^(The first parameter is a [prepared statement].
3699 ** If this statement is a [SELECT] statement and the Nth column of the
3700 ** returned result set of that [SELECT] is a table column (not an
3701 ** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
3724 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3725 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3726
3727 /*
3728 ** CAPI3REF: Evaluate An SQL Statement
 
3729 **
3730 ** After a [prepared statement] has been prepared using either
3731 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3732 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3733 ** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
3803 */
3804 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
3805
3806 /*
3807 ** CAPI3REF: Number of columns in a result set
 
3808 **
3809 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3810 ** current row of the result set of [prepared statement] P.
3811 ** ^If prepared statement P does not have results ready to return
3812 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
3856 #define SQLITE3_TEXT 3
3857
3858 /*
3859 ** CAPI3REF: Result Values From A Query
3860 ** KEYWORDS: {column access functions}
 
3861 **
3862 ** These routines form the "result set" interface.
3863 **
3864 ** ^These routines return information about a single column of the current
3865 ** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
4028 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4029 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4030
4031 /*
4032 ** CAPI3REF: Destroy A Prepared Statement Object
 
4033 **
4034 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4035 ** ^If the most recent evaluation of the statement encountered no errors
4036 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4037 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
4055 */
4056 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4057
4058 /*
4059 ** CAPI3REF: Reset A Prepared Statement Object
 
4060 **
4061 ** The sqlite3_reset() function is called to reset a [prepared statement]
4062 ** object back to its initial state, ready to be re-executed.
4063 ** ^Any SQL statement variables that had values bound to them using
4064 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
4084 /*
4085 ** CAPI3REF: Create Or Redefine SQL Functions
4086 ** KEYWORDS: {function creation routines}
4087 ** KEYWORDS: {application-defined SQL function}
4088 ** KEYWORDS: {application-defined SQL functions}
 
4089 **
4090 ** ^These functions (collectively known as "function creation routines")
4091 ** are used to add SQL functions or aggregates or to redefine the behavior
4092 ** of existing SQL functions or aggregates. The only differences between
4093 ** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
4253 void*,sqlite3_int64);
4254 #endif
4255
4256 /*
4257 ** CAPI3REF: Obtaining SQL Function Parameter Values
 
4258 **
4259 ** The C-language implementation of SQL functions and aggregates uses
4260 ** this set of interface routines to access the parameter values on
4261 ** the function or aggregate.
4262 **
@@ -4311,10 +4349,11 @@
4311 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4312 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4313
4314 /*
4315 ** CAPI3REF: Obtain Aggregate Function Context
 
4316 **
4317 ** Implementations of aggregate SQL functions use this
4318 ** routine to allocate memory for storing their state.
4319 **
4320 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
4355 */
4356 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4357
4358 /*
4359 ** CAPI3REF: User Data For Functions
 
4360 **
4361 ** ^The sqlite3_user_data() interface returns a copy of
4362 ** the pointer that was the pUserData parameter (the 5th parameter)
4363 ** of the [sqlite3_create_function()]
4364 ** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
4369 */
4370 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4371
4372 /*
4373 ** CAPI3REF: Database Connection For Functions
 
4374 **
4375 ** ^The sqlite3_context_db_handle() interface returns a copy of
4376 ** the pointer to the [database connection] (the 1st parameter)
4377 ** of the [sqlite3_create_function()]
4378 ** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
4380 */
4381 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4382
4383 /*
4384 ** CAPI3REF: Function Auxiliary Data
 
4385 **
4386 ** These functions may be used by (non-aggregate) SQL functions to
4387 ** associate metadata with argument values. If the same value is passed to
4388 ** multiple invocations of the same SQL function during query execution, under
4389 ** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
4452 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4453 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4454
4455 /*
4456 ** CAPI3REF: Setting The Result Of An SQL Function
 
4457 **
4458 ** These routines are used by the xFunc or xFinal callbacks that
4459 ** implement SQL functions and aggregates. See
4460 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4461 ** for additional information.
@@ -4587,10 +4630,11 @@
4587 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4588 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4589
4590 /*
4591 ** CAPI3REF: Define New Collating Sequences
 
4592 **
4593 ** ^These functions add, remove, or modify a [collation] associated
4594 ** with the [database connection] specified as the first argument.
4595 **
4596 ** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
4689 int(*xCompare)(void*,int,const void*,int,const void*)
4690 );
4691
4692 /*
4693 ** CAPI3REF: Collation Needed Callbacks
 
4694 **
4695 ** ^To avoid having to register all collation sequences before a database
4696 ** can be used, a single callback function may be registered with the
4697 ** [database connection] to be invoked whenever an undefined collation
4698 ** sequence is required.
@@ -4896,10 +4941,11 @@
4896 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
4897
4898 /*
4899 ** CAPI3REF: Test For Auto-Commit Mode
4900 ** KEYWORDS: {autocommit mode}
 
4901 **
4902 ** ^The sqlite3_get_autocommit() interface returns non-zero or
4903 ** zero if the given database connection is or is not in autocommit mode,
4904 ** respectively. ^Autocommit mode is on by default.
4905 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
4918 */
4919 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
4920
4921 /*
4922 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 
4923 **
4924 ** ^The sqlite3_db_handle interface returns the [database connection] handle
4925 ** to which a [prepared statement] belongs. ^The [database connection]
4926 ** returned by sqlite3_db_handle is the same [database connection]
4927 ** that was the first argument
@@ -4930,10 +4977,11 @@
4930 */
4931 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
4932
4933 /*
4934 ** CAPI3REF: Return The Filename For A Database Connection
 
4935 **
4936 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
4937 ** associated with database N of connection D. ^The main database file
4938 ** has the name "main". If there is no attached database N on the database
4939 ** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
4946 */
4947 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4948
4949 /*
4950 ** CAPI3REF: Determine if a database is read-only
 
4951 **
4952 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
4953 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
4954 ** the name of a database on connection D.
4955 */
4956 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
4957
4958 /*
4959 ** CAPI3REF: Find the next prepared statement
 
4960 **
4961 ** ^This interface returns a pointer to the next [prepared statement] after
4962 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
4963 ** then this interface returns a pointer to the first prepared statement
4964 ** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
4970 */
4971 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
4972
4973 /*
4974 ** CAPI3REF: Commit And Rollback Notification Callbacks
 
4975 **
4976 ** ^The sqlite3_commit_hook() interface registers a callback
4977 ** function to be invoked whenever a transaction is [COMMIT | committed].
4978 ** ^Any callback set by a previous call to sqlite3_commit_hook()
4979 ** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
5019 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5020 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5021
5022 /*
5023 ** CAPI3REF: Data Change Notification Callbacks
 
5024 **
5025 ** ^The sqlite3_update_hook() interface registers a callback function
5026 ** with the [database connection] identified by the first argument
5027 ** to be invoked whenever a row is updated, inserted or deleted in
5028 ** a rowid table.
@@ -5125,10 +5177,11 @@
5125 */
5126 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5127
5128 /*
5129 ** CAPI3REF: Free Memory Used By A Database Connection
 
5130 **
5131 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5132 ** memory as possible from database connection D. Unlike the
5133 ** [sqlite3_release_memory()] interface, this interface is in effect even
5134 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
5202 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5203
5204
5205 /*
5206 ** CAPI3REF: Extract Metadata About A Column Of A Table
 
5207 **
5208 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5209 ** information about column C of table T in database D
5210 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5211 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
5280 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5281 );
5282
5283 /*
5284 ** CAPI3REF: Load An Extension
 
5285 **
5286 ** ^This interface loads an SQLite extension library from the named file.
5287 **
5288 ** ^The sqlite3_load_extension() interface attempts to load an
5289 ** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
5321 char **pzErrMsg /* Put error message here if not 0 */
5322 );
5323
5324 /*
5325 ** CAPI3REF: Enable Or Disable Extension Loading
 
5326 **
5327 ** ^So as not to open security holes in older applications that are
5328 ** unprepared to deal with [extension loading], and as a means of disabling
5329 ** [extension loading] while evaluating user-entered SQL, the following API
5330 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
5570 #define SQLITE_INDEX_CONSTRAINT_GE 32
5571 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5572
5573 /*
5574 ** CAPI3REF: Register A Virtual Table Implementation
 
5575 **
5576 ** ^These routines are used to register a new [virtual table module] name.
5577 ** ^Module names must be registered before
5578 ** creating a new [virtual table] using the module and before using a
5579 ** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
5666 */
5667 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5668
5669 /*
5670 ** CAPI3REF: Overload A Function For A Virtual Table
 
5671 **
5672 ** ^(Virtual tables can provide alternative implementations of functions
5673 ** using the [xFindFunction] method of the [virtual table module].
5674 ** But global versions of those functions
5675 ** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
5708 */
5709 typedef struct sqlite3_blob sqlite3_blob;
5710
5711 /*
5712 ** CAPI3REF: Open A BLOB For Incremental I/O
 
 
5713 **
5714 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5715 ** in row iRow, column zColumn, table zTable in database zDb;
5716 ** in other words, the same BLOB that would be selected by:
5717 **
@@ -5789,10 +5849,11 @@
5789 sqlite3_blob **ppBlob
5790 );
5791
5792 /*
5793 ** CAPI3REF: Move a BLOB Handle to a New Row
 
5794 **
5795 ** ^This function is used to move an existing blob handle so that it points
5796 ** to a different row of the same database table. ^The new row is identified
5797 ** by the rowid value passed as the second argument. Only the row can be
5798 ** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
5813 */
5814 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5815
5816 /*
5817 ** CAPI3REF: Close A BLOB Handle
 
5818 **
5819 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5820 ** unconditionally. Even if this routine returns an error code, the
5821 ** handle is still closed.)^
5822 **
@@ -5835,10 +5897,11 @@
5835 */
5836 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
5837
5838 /*
5839 ** CAPI3REF: Return The Size Of An Open BLOB
 
5840 **
5841 ** ^Returns the size in bytes of the BLOB accessible via the
5842 ** successfully opened [BLOB handle] in its only argument. ^The
5843 ** incremental blob I/O routines can only read or overwriting existing
5844 ** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
5850 */
5851 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
5852
5853 /*
5854 ** CAPI3REF: Read Data From A BLOB Incrementally
 
5855 **
5856 ** ^(This function is used to read data from an open [BLOB handle] into a
5857 ** caller-supplied buffer. N bytes of data are copied into buffer Z
5858 ** from the open BLOB, starting at offset iOffset.)^
5859 **
@@ -5878,10 +5942,11 @@
5878 */
5879 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5880
5881 /*
5882 ** CAPI3REF: Write Data Into A BLOB Incrementally
 
5883 **
5884 ** ^(This function is used to write data into an open [BLOB handle] from a
5885 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5886 ** into the open BLOB, starting at offset iOffset.)^
5887 **
@@ -6205,10 +6270,11 @@
6205 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6206 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6207
6208 /*
6209 ** CAPI3REF: Retrieve the mutex for a database connection
 
6210 **
6211 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6212 ** serializes access to the [database connection] given in the argument
6213 ** when the [threading mode] is Serialized.
6214 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
6216 */
6217 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6218
6219 /*
6220 ** CAPI3REF: Low-Level Control Of Database Files
 
6221 **
6222 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6223 ** xFileControl method for the [sqlite3_io_methods] object associated
6224 ** with a particular database identified by the second argument. ^The
6225 ** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
6432 #define SQLITE_STATUS_SCRATCH_SIZE 8
6433 #define SQLITE_STATUS_MALLOC_COUNT 9
6434
6435 /*
6436 ** CAPI3REF: Database Connection Status
 
6437 **
6438 ** ^This interface is used to retrieve runtime status information
6439 ** about a single [database connection]. ^The first argument is the
6440 ** database connection object to be interrogated. ^The second argument
6441 ** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
6560 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6561
6562
6563 /*
6564 ** CAPI3REF: Prepared Statement Status
 
6565 **
6566 ** ^(Each prepared statement maintains various
6567 ** [SQLITE_STMTSTATUS counters] that measure the number
6568 ** of times it has performed specific operations.)^ These counters can
6569 ** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
7063 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7064 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7065
7066 /*
7067 ** CAPI3REF: Unlock Notification
 
7068 **
7069 ** ^When running in shared-cache mode, a database operation may fail with
7070 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7071 ** individual tables within the shared-cache cannot be obtained. See
7072 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
7233 */
7234 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7235
7236 /*
7237 ** CAPI3REF: Write-Ahead Log Commit Hook
 
7238 **
7239 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7240 ** is invoked each time data is committed to a database in wal mode.
7241 **
7242 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
7272 void*
7273 );
7274
7275 /*
7276 ** CAPI3REF: Configure an auto-checkpoint
 
7277 **
7278 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7279 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7280 ** to automatically [checkpoint]
7281 ** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
7302 */
7303 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7304
7305 /*
7306 ** CAPI3REF: Checkpoint a database
 
7307 **
7308 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7309 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7310 **
7311 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
7323 */
7324 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7325
7326 /*
7327 ** CAPI3REF: Checkpoint a database
 
7328 **
7329 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7330 ** operation on database X of [database connection] D in mode M. Status
7331 ** information is written back into integers pointed to by L and C.)^
7332 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
7577 #define SQLITE_SCANSTAT_EXPLAIN 4
7578 #define SQLITE_SCANSTAT_SELECTID 5
7579
7580 /*
7581 ** CAPI3REF: Prepared Statement Scan Status
 
7582 **
7583 ** This interface returns information about the predicted and measured
7584 ** performance for pStmt. Advanced applications can use this
7585 ** interface to compare the predicted and the measured performance and
7586 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
7614 void *pOut /* Result written here */
7615 );
7616
7617 /*
7618 ** CAPI3REF: Zero Scan-Status Counters
 
7619 **
7620 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7621 **
7622 ** This API is only available if the library is built with pre-processor
7623 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7624
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.10"
115 #define SQLITE_VERSION_NUMBER 3008010
116 #define SQLITE_SOURCE_ID "2015-05-04 19:13:25 850c11866686a7b39d7b163fb60898c11283688e"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -268,10 +268,11 @@
268 # define double sqlite3_int64
269 #endif
270
271 /*
272 ** CAPI3REF: Closing A Database Connection
273 ** DESTRUCTOR: sqlite3
274 **
275 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
276 ** for the [sqlite3] object.
277 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
278 ** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
320 */
321 typedef int (*sqlite3_callback)(void*,int,char**, char**);
322
323 /*
324 ** CAPI3REF: One-Step Query Execution Interface
325 ** METHOD: sqlite3
326 **
327 ** The sqlite3_exec() interface is a convenience wrapper around
328 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
329 ** that allows an application to run multiple statements of SQL
330 ** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
1378 */
1379 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1380
1381 /*
1382 ** CAPI3REF: Configure database connections
1383 ** METHOD: sqlite3
1384 **
1385 ** The sqlite3_db_config() interface is used to make configuration
1386 ** changes to a [database connection]. The interface is similar to
1387 ** [sqlite3_config()] except that the changes apply to a single
1388 ** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
1876 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1877
1878
1879 /*
1880 ** CAPI3REF: Enable Or Disable Extended Result Codes
1881 ** METHOD: sqlite3
1882 **
1883 ** ^The sqlite3_extended_result_codes() routine enables or disables the
1884 ** [extended result codes] feature of SQLite. ^The extended result
1885 ** codes are disabled by default for historical compatibility.
1886 */
1887 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
1888
1889 /*
1890 ** CAPI3REF: Last Insert Rowid
1891 ** METHOD: sqlite3
1892 **
1893 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1894 ** has a unique 64-bit signed
1895 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1896 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
1938 */
1939 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
1940
1941 /*
1942 ** CAPI3REF: Count The Number Of Rows Modified
1943 ** METHOD: sqlite3
1944 **
1945 ** ^This function returns the number of rows modified, inserted or
1946 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1947 ** statement on the database connection specified by the only parameter.
1948 ** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
1991 */
1992 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
1993
1994 /*
1995 ** CAPI3REF: Total Number Of Rows Modified
1996 ** METHOD: sqlite3
1997 **
1998 ** ^This function returns the total number of rows inserted, modified or
1999 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2000 ** since the database connection was opened, including those executed as
2001 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
2015 */
2016 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2017
2018 /*
2019 ** CAPI3REF: Interrupt A Long-Running Query
2020 ** METHOD: sqlite3
2021 **
2022 ** ^This function causes any pending database operation to abort and
2023 ** return at its earliest opportunity. This routine is typically
2024 ** called in response to a user action such as pressing "Cancel"
2025 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
2092 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2093
2094 /*
2095 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2096 ** KEYWORDS: {busy-handler callback} {busy handler}
2097 ** METHOD: sqlite3
2098 **
2099 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2100 ** that might be invoked with argument P whenever
2101 ** an attempt is made to access a database table associated with
2102 ** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
2152 */
2153 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2154
2155 /*
2156 ** CAPI3REF: Set A Busy Timeout
2157 ** METHOD: sqlite3
2158 **
2159 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2160 ** for a specified amount of time when a table is locked. ^The handler
2161 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2162 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
2175 */
2176 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2177
2178 /*
2179 ** CAPI3REF: Convenience Routines For Running Queries
2180 ** METHOD: sqlite3
2181 **
2182 ** This is a legacy interface that is preserved for backwards compatibility.
2183 ** Use of this interface is not recommended.
2184 **
2185 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
2511 */
2512 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2513
2514 /*
2515 ** CAPI3REF: Compile-Time Authorization Callbacks
2516 ** METHOD: sqlite3
2517 **
2518 ** ^This routine registers an authorizer callback with a particular
2519 ** [database connection], supplied in the first argument.
2520 ** ^The authorizer callback is invoked as SQL statements are being compiled
2521 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
2668 #define SQLITE_COPY 0 /* No longer used */
2669 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2670
2671 /*
2672 ** CAPI3REF: Tracing And Profiling Functions
2673 ** METHOD: sqlite3
2674 **
2675 ** These routines register callback functions that can be used for
2676 ** tracing and profiling the execution of SQL statements.
2677 **
2678 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
2701 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2702 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2703
2704 /*
2705 ** CAPI3REF: Query Progress Callbacks
2706 ** METHOD: sqlite3
2707 **
2708 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2709 ** function X to be invoked periodically during long running calls to
2710 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2711 ** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
2735 */
2736 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2737
2738 /*
2739 ** CAPI3REF: Opening A New Database Connection
2740 ** CONSTRUCTOR: sqlite3
2741 **
2742 ** ^These routines open an SQLite database file as specified by the
2743 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2744 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2745 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
3021 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3022
3023
3024 /*
3025 ** CAPI3REF: Error Codes And Messages
3026 ** METHOD: sqlite3
3027 **
3028 ** ^If the most recent sqlite3_* API call associated with
3029 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3030 ** returns the numeric [result code] or [extended result code] for that
3031 ** API call.
@@ -3051,37 +3067,38 @@
3067 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3068 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3069 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3070
3071 /*
3072 ** CAPI3REF: Prepared Statement Object
3073 ** KEYWORDS: {prepared statement} {prepared statements}
3074 **
3075 ** An instance of this object represents a single SQL statement that
3076 ** has been compiled into binary form and is ready to be evaluated.
 
3077 **
3078 ** Think of each SQL statement as a separate computer program. The
3079 ** original SQL text is source code. A prepared statement object
3080 ** is the compiled object code. All SQL must be converted into a
3081 ** prepared statement before it can be run.
3082 **
3083 ** The life-cycle of a prepared statement object usually goes like this:
3084 **
3085 ** <ol>
3086 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3087 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
 
3088 ** interfaces.
3089 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3090 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3091 ** to step 2. Do this zero or more times.
3092 ** <li> Destroy the object using [sqlite3_finalize()].
3093 ** </ol>
 
 
 
3094 */
3095 typedef struct sqlite3_stmt sqlite3_stmt;
3096
3097 /*
3098 ** CAPI3REF: Run-time Limits
3099 ** METHOD: sqlite3
3100 **
3101 ** ^(This interface allows the size of various constructs to be limited
3102 ** on a connection by connection basis. The first parameter is the
3103 ** [database connection] whose limit is to be set or queried. The
3104 ** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
3206 #define SQLITE_LIMIT_WORKER_THREADS 11
3207
3208 /*
3209 ** CAPI3REF: Compiling An SQL Statement
3210 ** KEYWORDS: {SQL statement compiler}
3211 ** METHOD: sqlite3
3212 ** CONSTRUCTOR: sqlite3_stmt
3213 **
3214 ** To execute an SQL query, it must first be compiled into a byte-code
3215 ** program using one of these routines.
3216 **
3217 ** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
3315 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3316 );
3317
3318 /*
3319 ** CAPI3REF: Retrieving Statement SQL
3320 ** METHOD: sqlite3_stmt
3321 **
3322 ** ^This interface can be used to retrieve a saved copy of the original
3323 ** SQL text used to create a [prepared statement] if that statement was
3324 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3325 */
3326 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3327
3328 /*
3329 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3330 ** METHOD: sqlite3_stmt
3331 **
3332 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3333 ** and only if the [prepared statement] X makes no direct changes to
3334 ** the content of the database file.
3335 **
@@ -3336,10 +3357,11 @@
3357 */
3358 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3359
3360 /*
3361 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3362 ** METHOD: sqlite3_stmt
3363 **
3364 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3365 ** [prepared statement] S has been stepped at least once using
3366 ** [sqlite3_step(S)] but has not run to completion and/or has not
3367 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
3432
3433 /*
3434 ** CAPI3REF: Binding Values To Prepared Statements
3435 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3436 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3437 ** METHOD: sqlite3_stmt
3438 **
3439 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3440 ** literals may be replaced by a [parameter] that matches one of following
3441 ** templates:
3442 **
@@ -3528,10 +3551,11 @@
3551 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3552 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3553
3554 /*
3555 ** CAPI3REF: Number Of SQL Parameters
3556 ** METHOD: sqlite3_stmt
3557 **
3558 ** ^This routine can be used to find the number of [SQL parameters]
3559 ** in a [prepared statement]. SQL parameters are tokens of the
3560 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3561 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
3572 */
3573 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3574
3575 /*
3576 ** CAPI3REF: Name Of A Host Parameter
3577 ** METHOD: sqlite3_stmt
3578 **
3579 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3580 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3581 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3582 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
3600 */
3601 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3602
3603 /*
3604 ** CAPI3REF: Index Of A Parameter With A Given Name
3605 ** METHOD: sqlite3_stmt
3606 **
3607 ** ^Return the index of an SQL parameter given its name. ^The
3608 ** index value returned is suitable for use as the second
3609 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3610 ** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
3617 */
3618 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3619
3620 /*
3621 ** CAPI3REF: Reset All Bindings On A Prepared Statement
3622 ** METHOD: sqlite3_stmt
3623 **
3624 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3625 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3626 ** ^Use this routine to reset all host parameters to NULL.
3627 */
3628 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3629
3630 /*
3631 ** CAPI3REF: Number Of Columns In A Result Set
3632 ** METHOD: sqlite3_stmt
3633 **
3634 ** ^Return the number of columns in the result set returned by the
3635 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3636 ** statement that does not return data (for example an [UPDATE]).
3637 **
@@ -3611,10 +3639,11 @@
3639 */
3640 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3641
3642 /*
3643 ** CAPI3REF: Column Names In A Result Set
3644 ** METHOD: sqlite3_stmt
3645 **
3646 ** ^These routines return the name assigned to a particular column
3647 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3648 ** interface returns a pointer to a zero-terminated UTF-8 string
3649 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
3669 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3670 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3671
3672 /*
3673 ** CAPI3REF: Source Of Data In A Query Result
3674 ** METHOD: sqlite3_stmt
3675 **
3676 ** ^These routines provide a means to determine the database, table, and
3677 ** table column that is the origin of a particular result column in
3678 ** [SELECT] statement.
3679 ** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
3722 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3723 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3724
3725 /*
3726 ** CAPI3REF: Declared Datatype Of A Query Result
3727 ** METHOD: sqlite3_stmt
3728 **
3729 ** ^(The first parameter is a [prepared statement].
3730 ** If this statement is a [SELECT] statement and the Nth column of the
3731 ** returned result set of that [SELECT] is a table column (not an
3732 ** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
3755 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3756 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3757
3758 /*
3759 ** CAPI3REF: Evaluate An SQL Statement
3760 ** METHOD: sqlite3_stmt
3761 **
3762 ** After a [prepared statement] has been prepared using either
3763 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3764 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3765 ** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
3835 */
3836 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
3837
3838 /*
3839 ** CAPI3REF: Number of columns in a result set
3840 ** METHOD: sqlite3_stmt
3841 **
3842 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3843 ** current row of the result set of [prepared statement] P.
3844 ** ^If prepared statement P does not have results ready to return
3845 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
3889 #define SQLITE3_TEXT 3
3890
3891 /*
3892 ** CAPI3REF: Result Values From A Query
3893 ** KEYWORDS: {column access functions}
3894 ** METHOD: sqlite3_stmt
3895 **
3896 ** These routines form the "result set" interface.
3897 **
3898 ** ^These routines return information about a single column of the current
3899 ** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
4062 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4063 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4064
4065 /*
4066 ** CAPI3REF: Destroy A Prepared Statement Object
4067 ** DESTRUCTOR: sqlite3_stmt
4068 **
4069 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4070 ** ^If the most recent evaluation of the statement encountered no errors
4071 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4072 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
4090 */
4091 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4092
4093 /*
4094 ** CAPI3REF: Reset A Prepared Statement Object
4095 ** METHOD: sqlite3_stmt
4096 **
4097 ** The sqlite3_reset() function is called to reset a [prepared statement]
4098 ** object back to its initial state, ready to be re-executed.
4099 ** ^Any SQL statement variables that had values bound to them using
4100 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
4120 /*
4121 ** CAPI3REF: Create Or Redefine SQL Functions
4122 ** KEYWORDS: {function creation routines}
4123 ** KEYWORDS: {application-defined SQL function}
4124 ** KEYWORDS: {application-defined SQL functions}
4125 ** METHOD: sqlite3
4126 **
4127 ** ^These functions (collectively known as "function creation routines")
4128 ** are used to add SQL functions or aggregates or to redefine the behavior
4129 ** of existing SQL functions or aggregates. The only differences between
4130 ** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
4290 void*,sqlite3_int64);
4291 #endif
4292
4293 /*
4294 ** CAPI3REF: Obtaining SQL Function Parameter Values
4295 ** METHOD: sqlite3_value
4296 **
4297 ** The C-language implementation of SQL functions and aggregates uses
4298 ** this set of interface routines to access the parameter values on
4299 ** the function or aggregate.
4300 **
@@ -4311,10 +4349,11 @@
4349 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4350 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4351
4352 /*
4353 ** CAPI3REF: Obtain Aggregate Function Context
4354 ** METHOD: sqlite3_context
4355 **
4356 ** Implementations of aggregate SQL functions use this
4357 ** routine to allocate memory for storing their state.
4358 **
4359 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
4394 */
4395 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4396
4397 /*
4398 ** CAPI3REF: User Data For Functions
4399 ** METHOD: sqlite3_context
4400 **
4401 ** ^The sqlite3_user_data() interface returns a copy of
4402 ** the pointer that was the pUserData parameter (the 5th parameter)
4403 ** of the [sqlite3_create_function()]
4404 ** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
4409 */
4410 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4411
4412 /*
4413 ** CAPI3REF: Database Connection For Functions
4414 ** METHOD: sqlite3_context
4415 **
4416 ** ^The sqlite3_context_db_handle() interface returns a copy of
4417 ** the pointer to the [database connection] (the 1st parameter)
4418 ** of the [sqlite3_create_function()]
4419 ** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
4421 */
4422 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4423
4424 /*
4425 ** CAPI3REF: Function Auxiliary Data
4426 ** METHOD: sqlite3_context
4427 **
4428 ** These functions may be used by (non-aggregate) SQL functions to
4429 ** associate metadata with argument values. If the same value is passed to
4430 ** multiple invocations of the same SQL function during query execution, under
4431 ** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
4494 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4495 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4496
4497 /*
4498 ** CAPI3REF: Setting The Result Of An SQL Function
4499 ** METHOD: sqlite3_context
4500 **
4501 ** These routines are used by the xFunc or xFinal callbacks that
4502 ** implement SQL functions and aggregates. See
4503 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4504 ** for additional information.
@@ -4587,10 +4630,11 @@
4630 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4631 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4632
4633 /*
4634 ** CAPI3REF: Define New Collating Sequences
4635 ** METHOD: sqlite3
4636 **
4637 ** ^These functions add, remove, or modify a [collation] associated
4638 ** with the [database connection] specified as the first argument.
4639 **
4640 ** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
4733 int(*xCompare)(void*,int,const void*,int,const void*)
4734 );
4735
4736 /*
4737 ** CAPI3REF: Collation Needed Callbacks
4738 ** METHOD: sqlite3
4739 **
4740 ** ^To avoid having to register all collation sequences before a database
4741 ** can be used, a single callback function may be registered with the
4742 ** [database connection] to be invoked whenever an undefined collation
4743 ** sequence is required.
@@ -4896,10 +4941,11 @@
4941 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
4942
4943 /*
4944 ** CAPI3REF: Test For Auto-Commit Mode
4945 ** KEYWORDS: {autocommit mode}
4946 ** METHOD: sqlite3
4947 **
4948 ** ^The sqlite3_get_autocommit() interface returns non-zero or
4949 ** zero if the given database connection is or is not in autocommit mode,
4950 ** respectively. ^Autocommit mode is on by default.
4951 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
4964 */
4965 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
4966
4967 /*
4968 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
4969 ** METHOD: sqlite3_stmt
4970 **
4971 ** ^The sqlite3_db_handle interface returns the [database connection] handle
4972 ** to which a [prepared statement] belongs. ^The [database connection]
4973 ** returned by sqlite3_db_handle is the same [database connection]
4974 ** that was the first argument
@@ -4930,10 +4977,11 @@
4977 */
4978 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
4979
4980 /*
4981 ** CAPI3REF: Return The Filename For A Database Connection
4982 ** METHOD: sqlite3
4983 **
4984 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
4985 ** associated with database N of connection D. ^The main database file
4986 ** has the name "main". If there is no attached database N on the database
4987 ** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
4994 */
4995 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4996
4997 /*
4998 ** CAPI3REF: Determine if a database is read-only
4999 ** METHOD: sqlite3
5000 **
5001 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5002 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5003 ** the name of a database on connection D.
5004 */
5005 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5006
5007 /*
5008 ** CAPI3REF: Find the next prepared statement
5009 ** METHOD: sqlite3
5010 **
5011 ** ^This interface returns a pointer to the next [prepared statement] after
5012 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5013 ** then this interface returns a pointer to the first prepared statement
5014 ** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
5020 */
5021 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5022
5023 /*
5024 ** CAPI3REF: Commit And Rollback Notification Callbacks
5025 ** METHOD: sqlite3
5026 **
5027 ** ^The sqlite3_commit_hook() interface registers a callback
5028 ** function to be invoked whenever a transaction is [COMMIT | committed].
5029 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5030 ** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
5070 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5071 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5072
5073 /*
5074 ** CAPI3REF: Data Change Notification Callbacks
5075 ** METHOD: sqlite3
5076 **
5077 ** ^The sqlite3_update_hook() interface registers a callback function
5078 ** with the [database connection] identified by the first argument
5079 ** to be invoked whenever a row is updated, inserted or deleted in
5080 ** a rowid table.
@@ -5125,10 +5177,11 @@
5177 */
5178 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5179
5180 /*
5181 ** CAPI3REF: Free Memory Used By A Database Connection
5182 ** METHOD: sqlite3
5183 **
5184 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5185 ** memory as possible from database connection D. Unlike the
5186 ** [sqlite3_release_memory()] interface, this interface is in effect even
5187 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
5255 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5256
5257
5258 /*
5259 ** CAPI3REF: Extract Metadata About A Column Of A Table
5260 ** METHOD: sqlite3
5261 **
5262 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5263 ** information about column C of table T in database D
5264 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5265 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
5334 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5335 );
5336
5337 /*
5338 ** CAPI3REF: Load An Extension
5339 ** METHOD: sqlite3
5340 **
5341 ** ^This interface loads an SQLite extension library from the named file.
5342 **
5343 ** ^The sqlite3_load_extension() interface attempts to load an
5344 ** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
5376 char **pzErrMsg /* Put error message here if not 0 */
5377 );
5378
5379 /*
5380 ** CAPI3REF: Enable Or Disable Extension Loading
5381 ** METHOD: sqlite3
5382 **
5383 ** ^So as not to open security holes in older applications that are
5384 ** unprepared to deal with [extension loading], and as a means of disabling
5385 ** [extension loading] while evaluating user-entered SQL, the following API
5386 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
5626 #define SQLITE_INDEX_CONSTRAINT_GE 32
5627 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5628
5629 /*
5630 ** CAPI3REF: Register A Virtual Table Implementation
5631 ** METHOD: sqlite3
5632 **
5633 ** ^These routines are used to register a new [virtual table module] name.
5634 ** ^Module names must be registered before
5635 ** creating a new [virtual table] using the module and before using a
5636 ** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
5723 */
5724 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5725
5726 /*
5727 ** CAPI3REF: Overload A Function For A Virtual Table
5728 ** METHOD: sqlite3
5729 **
5730 ** ^(Virtual tables can provide alternative implementations of functions
5731 ** using the [xFindFunction] method of the [virtual table module].
5732 ** But global versions of those functions
5733 ** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
5766 */
5767 typedef struct sqlite3_blob sqlite3_blob;
5768
5769 /*
5770 ** CAPI3REF: Open A BLOB For Incremental I/O
5771 ** METHOD: sqlite3
5772 ** CONSTRUCTOR: sqlite3_blob
5773 **
5774 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5775 ** in row iRow, column zColumn, table zTable in database zDb;
5776 ** in other words, the same BLOB that would be selected by:
5777 **
@@ -5789,10 +5849,11 @@
5849 sqlite3_blob **ppBlob
5850 );
5851
5852 /*
5853 ** CAPI3REF: Move a BLOB Handle to a New Row
5854 ** METHOD: sqlite3_blob
5855 **
5856 ** ^This function is used to move an existing blob handle so that it points
5857 ** to a different row of the same database table. ^The new row is identified
5858 ** by the rowid value passed as the second argument. Only the row can be
5859 ** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
5874 */
5875 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5876
5877 /*
5878 ** CAPI3REF: Close A BLOB Handle
5879 ** DESTRUCTOR: sqlite3_blob
5880 **
5881 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5882 ** unconditionally. Even if this routine returns an error code, the
5883 ** handle is still closed.)^
5884 **
@@ -5835,10 +5897,11 @@
5897 */
5898 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
5899
5900 /*
5901 ** CAPI3REF: Return The Size Of An Open BLOB
5902 ** METHOD: sqlite3_blob
5903 **
5904 ** ^Returns the size in bytes of the BLOB accessible via the
5905 ** successfully opened [BLOB handle] in its only argument. ^The
5906 ** incremental blob I/O routines can only read or overwriting existing
5907 ** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
5913 */
5914 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
5915
5916 /*
5917 ** CAPI3REF: Read Data From A BLOB Incrementally
5918 ** METHOD: sqlite3_blob
5919 **
5920 ** ^(This function is used to read data from an open [BLOB handle] into a
5921 ** caller-supplied buffer. N bytes of data are copied into buffer Z
5922 ** from the open BLOB, starting at offset iOffset.)^
5923 **
@@ -5878,10 +5942,11 @@
5942 */
5943 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5944
5945 /*
5946 ** CAPI3REF: Write Data Into A BLOB Incrementally
5947 ** METHOD: sqlite3_blob
5948 **
5949 ** ^(This function is used to write data into an open [BLOB handle] from a
5950 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5951 ** into the open BLOB, starting at offset iOffset.)^
5952 **
@@ -6205,10 +6270,11 @@
6270 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6271 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6272
6273 /*
6274 ** CAPI3REF: Retrieve the mutex for a database connection
6275 ** METHOD: sqlite3
6276 **
6277 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6278 ** serializes access to the [database connection] given in the argument
6279 ** when the [threading mode] is Serialized.
6280 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
6282 */
6283 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6284
6285 /*
6286 ** CAPI3REF: Low-Level Control Of Database Files
6287 ** METHOD: sqlite3
6288 **
6289 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6290 ** xFileControl method for the [sqlite3_io_methods] object associated
6291 ** with a particular database identified by the second argument. ^The
6292 ** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
6499 #define SQLITE_STATUS_SCRATCH_SIZE 8
6500 #define SQLITE_STATUS_MALLOC_COUNT 9
6501
6502 /*
6503 ** CAPI3REF: Database Connection Status
6504 ** METHOD: sqlite3
6505 **
6506 ** ^This interface is used to retrieve runtime status information
6507 ** about a single [database connection]. ^The first argument is the
6508 ** database connection object to be interrogated. ^The second argument
6509 ** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
6628 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6629
6630
6631 /*
6632 ** CAPI3REF: Prepared Statement Status
6633 ** METHOD: sqlite3_stmt
6634 **
6635 ** ^(Each prepared statement maintains various
6636 ** [SQLITE_STMTSTATUS counters] that measure the number
6637 ** of times it has performed specific operations.)^ These counters can
6638 ** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
7132 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7133 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7134
7135 /*
7136 ** CAPI3REF: Unlock Notification
7137 ** METHOD: sqlite3
7138 **
7139 ** ^When running in shared-cache mode, a database operation may fail with
7140 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7141 ** individual tables within the shared-cache cannot be obtained. See
7142 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
7303 */
7304 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7305
7306 /*
7307 ** CAPI3REF: Write-Ahead Log Commit Hook
7308 ** METHOD: sqlite3
7309 **
7310 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7311 ** is invoked each time data is committed to a database in wal mode.
7312 **
7313 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
7343 void*
7344 );
7345
7346 /*
7347 ** CAPI3REF: Configure an auto-checkpoint
7348 ** METHOD: sqlite3
7349 **
7350 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7351 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7352 ** to automatically [checkpoint]
7353 ** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
7374 */
7375 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7376
7377 /*
7378 ** CAPI3REF: Checkpoint a database
7379 ** METHOD: sqlite3
7380 **
7381 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7382 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7383 **
7384 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
7396 */
7397 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7398
7399 /*
7400 ** CAPI3REF: Checkpoint a database
7401 ** METHOD: sqlite3
7402 **
7403 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7404 ** operation on database X of [database connection] D in mode M. Status
7405 ** information is written back into integers pointed to by L and C.)^
7406 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
7651 #define SQLITE_SCANSTAT_EXPLAIN 4
7652 #define SQLITE_SCANSTAT_SELECTID 5
7653
7654 /*
7655 ** CAPI3REF: Prepared Statement Scan Status
7656 ** METHOD: sqlite3_stmt
7657 **
7658 ** This interface returns information about the predicted and measured
7659 ** performance for pStmt. Advanced applications can use this
7660 ** interface to compare the predicted and the measured performance and
7661 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
7689 void *pOut /* Result written here */
7690 );
7691
7692 /*
7693 ** CAPI3REF: Zero Scan-Status Counters
7694 ** METHOD: sqlite3_stmt
7695 **
7696 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7697 **
7698 ** This API is only available if the library is built with pre-processor
7699 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7700

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button