Sqlite upgrade to version 3.49.1 (#19933)
* Update sqlite version to 3.49.1 * Enable sqlite3_release_memory
Stelios Fragkakis committed
Apr 15, 2025 at 09:02 UTC
05ea48e5761a983b02021fb8b121bd839c60ec69
2 files changed
+8861
-4796
src/database/sqlite/vendored/sqlite3.c
+8518
-4743
@@ -1,6 +1,6 @@
1
/******************************************************************************
2
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.46.1. By combining all the individual C code files into this
3
+** version 3.49.1. 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
@@ -18,11 +18,13 @@
18
** separate file. This file contains only code for the core SQLite library.
19
**
20
** The content in this amalgamation comes from Fossil check-in
21
-** c9c2ab54ba1f5f46360f1b4f35d849cd3f08.
21
+** 873d4e274b4988d260ba8354a9718324a1c2 with changes in files:
22
+**
23
+**
24
*/
25
#pragma GCC diagnostic push
24
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
26
#pragma GCC diagnostic ignored "-Wunused-parameter"
27
+#ifndef SQLITE_AMALGAMATION
28
#define SQLITE_CORE 1
29
#define SQLITE_AMALGAMATION 1
30
#ifndef SQLITE_PRIVATE
@@ -265,10 +267,13 @@
267
/*
268
** Macro to disable warnings about missing "break" at the end of a "case".
269
*/
268
-#if GCC_VERSION>=7000000
269
-# define deliberate_fall_through __attribute__((fallthrough));
270
-#else
271
-# define deliberate_fall_through
270
+#if defined(__has_attribute)
271
+# if __has_attribute(fallthrough)
272
+# define deliberate_fall_through __attribute__((fallthrough));
273
+# endif
274
+#endif
275
+#if !defined(deliberate_fall_through)
276
+# define deliberate_fall_through
277
#endif
278
279
/*
@@ -468,9 +473,9 @@ extern "C" {
473
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
474
** [sqlite_version()] and [sqlite_source_id()].
475
*/
471
-#define SQLITE_VERSION "3.46.1"
472
-#define SQLITE_VERSION_NUMBER 3046001
473
-#define SQLITE_SOURCE_ID "2024-08-13 09:16:08 c9c2ab54ba1f5f46360f1b4f35d849cd3f080e6fc2b6c60e91b16c63f69a1e33"
476
+#define SQLITE_VERSION "3.49.1"
477
+#define SQLITE_VERSION_NUMBER 3049001
478
+#define SQLITE_SOURCE_ID "2025-02-18 13:38:58 873d4e274b4988d260ba8354a9718324a1c26187a4ab4c1cc0227c03d0f10e70"
479
480
/*
481
** CAPI3REF: Run-Time Library Version Numbers
@@ -974,6 +979,13 @@ SQLITE_API int sqlite3_exec(
979
** filesystem supports doing multiple write operations atomically when those
980
** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
981
** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
982
+**
983
+** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read
984
+** from the database file in amounts that are not a multiple of the
985
+** page size and that do not begin at a page boundary. Without this
986
+** property, SQLite is careful to only do full-page reads and write
987
+** on aligned pages, with the one exception that it will do a sub-page
988
+** read of the first page to access the database header.
989
*/
990
#define SQLITE_IOCAP_ATOMIC 0x00000001
991
#define SQLITE_IOCAP_ATOMIC512 0x00000002
@@ -990,6 +1002,7 @@ SQLITE_API int sqlite3_exec(
1002
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
1003
#define SQLITE_IOCAP_IMMUTABLE 0x00002000
1004
#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
1005
+#define SQLITE_IOCAP_SUBPAGE_READ 0x00008000
1006
1007
/*
1008
** CAPI3REF: File Locking Levels
@@ -1094,8 +1107,8 @@ struct sqlite3_file {
1107
** to xUnlock() is a no-op.
1108
** The xCheckReservedLock() method checks whether any database connection,
1109
** either in this process or in some other process, is holding a RESERVED,
1097
-** PENDING, or EXCLUSIVE lock on the file. It returns true
1098
-** if such a lock exists and false otherwise.
1110
+** PENDING, or EXCLUSIVE lock on the file. It returns, via its output
1111
+** pointer parameter, true if such a lock exists and false otherwise.
1112
**
1113
** The xFileControl() method is a generic interface that allows custom
1114
** VFS implementations to directly control an open file using the
@@ -1136,6 +1149,7 @@ struct sqlite3_file {
1149
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
1150
** <li> [SQLITE_IOCAP_IMMUTABLE]
1151
** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
1152
+** <li> [SQLITE_IOCAP_SUBPAGE_READ]
1153
** </ul>
1154
**
1155
** The SQLITE_IOCAP_ATOMIC property means that all writes of
@@ -1413,6 +1427,11 @@ struct sqlite3_io_methods {
1427
** pointed to by the pArg argument. This capability is used during testing
1428
** and only needs to be supported when SQLITE_TEST is defined.
1429
**
1430
+** <li>[[SQLITE_FCNTL_NULL_IO]]
1431
+** The [SQLITE_FCNTL_NULL_IO] opcode sets the low-level file descriptor
1432
+** or file handle for the [sqlite3_file] object such that it will no longer
1433
+** read or write to the database file.
1434
+**
1435
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1436
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1437
** be advantageous to block on the next WAL lock if the lock is not immediately
@@ -1566,6 +1585,7 @@ struct sqlite3_io_methods {
1585
#define SQLITE_FCNTL_EXTERNAL_READER 40
1586
#define SQLITE_FCNTL_CKSM_FILE 41
1587
#define SQLITE_FCNTL_RESET_CACHE 42
1588
+#define SQLITE_FCNTL_NULL_IO 43
1589
1590
/* deprecated names */
1591
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
@@ -2518,7 +2538,15 @@ struct sqlite3_mem_methods {
2538
** CAPI3REF: Database Connection Configuration Options
2539
**
2540
** These constants are the available integer configuration options that
2521
-** can be passed as the second argument to the [sqlite3_db_config()] interface.
2541
+** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2542
+**
2543
+** The [sqlite3_db_config()] interface is a var-args functions. It takes a
2544
+** variable number of parameters, though always at least two. The number of
2545
+** parameters passed into sqlite3_db_config() depends on which of these
2546
+** constants is given as the second parameter. This documentation page
2547
+** refers to parameters beyond the second as "arguments". Thus, when this
2548
+** page says "the N-th argument" it means "the N-th parameter past the
2549
+** configuration option" or "the (N+2)-th parameter to sqlite3_db_config()".
2550
**
2551
** New configuration options may be added in future releases of SQLite.
2552
** Existing configuration options might be discontinued. Applications
@@ -2530,8 +2558,14 @@ struct sqlite3_mem_methods {
2558
** <dl>
2559
** [[SQLITE_DBCONFIG_LOOKASIDE]]
2560
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2533
-** <dd> ^This option takes three additional arguments that determine the
2534
-** [lookaside memory allocator] configuration for the [database connection].
2561
+** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2562
+** configuration of the lookaside memory allocator within a database
2563
+** connection.
2564
+** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2565
+** in the [DBCONFIG arguments|usual format].
2566
+** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2567
+** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2568
+** should have a total of five parameters.
2569
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2570
** pointer to a memory buffer to use for lookaside memory.
2571
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
@@ -2554,7 +2588,8 @@ struct sqlite3_mem_methods {
2588
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2589
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2590
** <dd> ^This option is used to enable or disable the enforcement of
2557
-** [foreign key constraints]. There should be two additional arguments.
2591
+** [foreign key constraints]. This is the same setting that is
2592
+** enabled or disabled by the [PRAGMA foreign_keys] statement.
2593
** The first argument is an integer which is 0 to disable FK enforcement,
2594
** positive to enable FK enforcement or negative to leave FK enforcement
2595
** unchanged. The second parameter is a pointer to an integer into which
@@ -2576,13 +2611,13 @@ struct sqlite3_mem_methods {
2611
** <p>Originally this option disabled all triggers. ^(However, since
2612
** SQLite version 3.35.0, TEMP triggers are still allowed even if
2613
** this option is off. So, in other words, this option now only disables
2579
-** triggers in the main database schema or in the schemas of ATTACH-ed
2614
+** triggers in the main database schema or in the schemas of [ATTACH]-ed
2615
** databases.)^ </dd>
2616
**
2617
** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
2618
** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
2619
** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
2585
-** There should be two additional arguments.
2620
+** There must be two additional arguments.
2621
** The first argument is an integer which is 0 to disable views,
2622
** positive to enable views or negative to leave the setting unchanged.
2623
** The second parameter is a pointer to an integer into which
@@ -2601,7 +2636,7 @@ struct sqlite3_mem_methods {
2636
** <dd> ^This option is used to enable or disable the
2637
** [fts3_tokenizer()] function which is part of the
2638
** [FTS3] full-text search engine extension.
2604
-** There should be two additional arguments.
2639
+** There must be two additional arguments.
2640
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2641
** positive to enable fts3_tokenizer() or negative to leave the setting
2642
** unchanged.
@@ -2616,7 +2651,7 @@ struct sqlite3_mem_methods {
2651
** interface independently of the [load_extension()] SQL function.
2652
** The [sqlite3_enable_load_extension()] API enables or disables both the
2653
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2619
-** There should be two additional arguments.
2654
+** There must be two additional arguments.
2655
** When the first argument to this interface is 1, then only the C-API is
2656
** enabled and the SQL function remains disabled. If the first argument to
2657
** this interface is 0, then both the C-API and the SQL function are disabled.
@@ -2630,23 +2665,30 @@ struct sqlite3_mem_methods {
2665
**
2666
** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2667
** <dd> ^This option is used to change the name of the "main" database
2633
-** schema. ^The sole argument is a pointer to a constant UTF8 string
2634
-** which will become the new schema name in place of "main". ^SQLite
2635
-** does not make a copy of the new main schema name string, so the application
2636
-** must ensure that the argument passed into this DBCONFIG option is unchanged
2637
-** until after the database connection closes.
2668
+** schema. This option does not follow the
2669
+** [DBCONFIG arguments|usual SQLITE_DBCONFIG argument format].
2670
+** This option takes exactly one additional argument so that the
2671
+** [sqlite3_db_config()] call has a total of three parameters. The
2672
+** extra argument must be a pointer to a constant UTF8 string which
2673
+** will become the new schema name in place of "main". ^SQLite does
2674
+** not make a copy of the new main schema name string, so the application
2675
+** must ensure that the argument passed into SQLITE_DBCONFIG MAINDBNAME
2676
+** is unchanged until after the database connection closes.
2677
** </dd>
2678
**
2679
** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
2680
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2642
-** <dd> Usually, when a database in wal mode is closed or detached from a
2643
-** database handle, SQLite checks if this will mean that there are now no
2644
-** connections at all to the database. If so, it performs a checkpoint
2645
-** operation before closing the connection. This option may be used to
2646
-** override this behavior. The first parameter passed to this operation
2647
-** is an integer - positive to disable checkpoints-on-close, or zero (the
2648
-** default) to enable them, and negative to leave the setting unchanged.
2649
-** The second parameter is a pointer to an integer
2681
+** <dd> Usually, when a database in [WAL mode] is closed or detached from a
2682
+** database handle, SQLite checks if if there are other connections to the
2683
+** same database, and if there are no other database connection (if the
2684
+** connection being closed is the last open connection to the database),
2685
+** then SQLite performs a [checkpoint] before closing the connection and
2686
+** deletes the WAL file. The SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE option can
2687
+** be used to override that behavior. The first argument passed to this
2688
+** operation (the third parameter to [sqlite3_db_config()]) is an integer
2689
+** which is positive to disable checkpoints-on-close, or zero (the default)
2690
+** to enable them, and negative to leave the setting unchanged.
2691
+** The second argument (the fourth parameter) is a pointer to an integer
2692
** into which is written 0 or 1 to indicate whether checkpoints-on-close
2693
** have been disabled - 0 if they are not disabled, 1 if they are.
2694
** </dd>
@@ -2807,7 +2849,7 @@ struct sqlite3_mem_methods {
2849
** statistics. For statistics to be collected, the flag must be set on
2850
** the database handle both when the SQL statement is prepared and when it
2851
** is stepped. The flag is set (collection of statistics is enabled)
2810
-** by default. This option takes two arguments: an integer and a pointer to
2852
+** by default. <p>This option takes two arguments: an integer and a pointer to
2853
** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2854
** leave unchanged the statement scanstatus option. If the second argument
2855
** is not NULL, then the value of the statement scanstatus setting after
@@ -2821,7 +2863,7 @@ struct sqlite3_mem_methods {
2863
** in which tables and indexes are scanned so that the scans start at the end
2864
** and work toward the beginning rather than starting at the beginning and
2865
** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2824
-** same as setting [PRAGMA reverse_unordered_selects]. This option takes
2866
+** same as setting [PRAGMA reverse_unordered_selects]. <p>This option takes
2867
** two arguments which are an integer and a pointer to an integer. The first
2868
** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2869
** reverse scan order flag, respectively. If the second argument is not NULL,
@@ -2830,7 +2872,76 @@ struct sqlite3_mem_methods {
2872
** first argument.
2873
** </dd>
2874
**
2875
+** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]]
2876
+** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt>
2877
+** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables or disables
2878
+** the ability of the [ATTACH DATABASE] SQL command to create a new database
2879
+** file if the database filed named in the ATTACH command does not already
2880
+** exist. This ability of ATTACH to create a new database is enabled by
2881
+** default. Applications can disable or reenable the ability for ATTACH to
2882
+** create new database files using this DBCONFIG option.<p>
2883
+** This option takes two arguments which are an integer and a pointer
2884
+** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2885
+** leave unchanged the attach-create flag, respectively. If the second
2886
+** argument is not NULL, then 0 or 1 is written into the integer that the
2887
+** second argument points to depending on if the attach-create flag is set
2888
+** after processing the first argument.
2889
+** </dd>
2890
+**
2891
+** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2892
+** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2893
+** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2894
+** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2895
+** This capability is enabled by default. Applications can disable or
2896
+** reenable this capability using the current DBCONFIG option. If the
2897
+** the this capability is disabled, the [ATTACH] command will still work,
2898
+** but the database will be opened read-only. If this option is disabled,
2899
+** then the ability to create a new database using [ATTACH] is also disabled,
2900
+** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2901
+** option.<p>
2902
+** This option takes two arguments which are an integer and a pointer
2903
+** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2904
+** leave unchanged the ability to ATTACH another database for writing,
2905
+** respectively. If the second argument is not NULL, then 0 or 1 is written
2906
+** into the integer to which the second argument points, depending on whether
2907
+** the ability to ATTACH a read/write database is enabled or disabled
2908
+** after processing the first argument.
2909
+** </dd>
2910
+**
2911
+** [[SQLITE_DBCONFIG_ENABLE_COMMENTS]]
2912
+** <dt>SQLITE_DBCONFIG_ENABLE_COMMENTS</dt>
2913
+** <dd>The SQLITE_DBCONFIG_ENABLE_COMMENTS option enables or disables the
2914
+** ability to include comments in SQL text. Comments are enabled by default.
2915
+** An application can disable or reenable comments in SQL text using this
2916
+** DBCONFIG option.<p>
2917
+** This option takes two arguments which are an integer and a pointer
2918
+** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2919
+** leave unchanged the ability to use comments in SQL text,
2920
+** respectively. If the second argument is not NULL, then 0 or 1 is written
2921
+** into the integer that the second argument points to depending on if
2922
+** comments are allowed in SQL text after processing the first argument.
2923
+** </dd>
2924
+**
2925
** </dl>
2926
+**
2927
+** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2928
+**
2929
+** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2930
+** overall call to [sqlite3_db_config()] has a total of four parameters.
2931
+** The first argument (the third parameter to sqlite3_db_config()) is a integer.
2932
+** The second argument is a pointer to an integer. If the first argument is 1,
2933
+** then the option becomes enabled. If the first integer argument is 0, then the
2934
+** option is disabled. If the first argument is -1, then the option setting
2935
+** is unchanged. The second argument, the pointer to an integer, may be NULL.
2936
+** If the second argument is not NULL, then a value of 0 or 1 is written into
2937
+** the integer to which the second argument points, depending on whether the
2938
+** setting is disabled or enabled after applying any changes specified by
2939
+** the first argument.
2940
+**
2941
+** <p>While most SQLITE_DBCONFIG options use the argument format
2942
+** described in the previous paragraph, the [SQLITE_DBCONFIG_MAINDBNAME]
2943
+** and [SQLITE_DBCONFIG_LOOKASIDE] options are different. See the
2944
+** documentation of those exceptional options for details.
2945
*/
2946
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2947
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2852,7 +2963,10 @@ struct sqlite3_mem_methods {
2963
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2964
#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2965
#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
2855
-#define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
2966
+#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE 1020 /* int int* */
2967
+#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE 1021 /* int int* */
2968
+#define SQLITE_DBCONFIG_ENABLE_COMMENTS 1022 /* int int* */
2969
+#define SQLITE_DBCONFIG_MAX 1022 /* Largest DBCONFIG */
2970
2971
/*
2972
** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -2944,10 +3058,14 @@ SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
3058
** deleted by the most recently completed INSERT, UPDATE or DELETE
3059
** statement on the database connection specified by the only parameter.
3060
** The two functions are identical except for the type of the return value
2947
-** and that if the number of rows modified by the most recent INSERT, UPDATE
3061
+** and that if the number of rows modified by the most recent INSERT, UPDATE,
3062
** or DELETE is greater than the maximum value supported by type "int", then
3063
** the return value of sqlite3_changes() is undefined. ^Executing any other
3064
** type of SQL statement does not modify the value returned by these functions.
3065
+** For the purposes of this interface, a CREATE TABLE AS SELECT statement
3066
+** does not count as an INSERT, UPDATE or DELETE statement and hence the rows
3067
+** added to the new table by the CREATE TABLE AS SELECT statement are not
3068
+** counted.
3069
**
3070
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
3071
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
@@ -3892,8 +4010,8 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
4010
**
4011
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
4012
** <dd>The database connection comes up in "extended result code mode".
3895
-** In other words, the database behaves has if
3896
-** [sqlite3_extended_result_codes(db,1)] where called on the database
4013
+** In other words, the database behaves as if
4014
+** [sqlite3_extended_result_codes(db,1)] were called on the database
4015
** connection as soon as the connection is created. In addition to setting
4016
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
4017
** to return an extended result code.</dd>
@@ -4507,11 +4625,22 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4625
** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
4626
** to return an error (error code SQLITE_ERROR) if the statement uses
4627
** any virtual tables.
4628
+**
4629
+** [[SQLITE_PREPARE_DONT_LOG]] <dt>SQLITE_PREPARE_DONT_LOG</dt>
4630
+** <dd>The SQLITE_PREPARE_DONT_LOG flag prevents SQL compiler
4631
+** errors from being sent to the error log defined by
4632
+** [SQLITE_CONFIG_LOG]. This can be used, for example, to do test
4633
+** compiles to see if some SQL syntax is well-formed, without generating
4634
+** messages on the global error log when it is not. If the test compile
4635
+** fails, the sqlite3_prepare_v3() call returns the same error indications
4636
+** with or without this flag; it just omits the call to [sqlite3_log()] that
4637
+** logs the error.
4638
** </dl>
4639
*/
4640
#define SQLITE_PREPARE_PERSISTENT 0x01
4641
#define SQLITE_PREPARE_NORMALIZE 0x02
4642
#define SQLITE_PREPARE_NO_VTAB 0x04
4643
+#define SQLITE_PREPARE_DONT_LOG 0x10
4644
4645
/*
4646
** CAPI3REF: Compiling An SQL Statement
@@ -4544,13 +4673,17 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4673
** and sqlite3_prepare16_v3() use UTF-16.
4674
**
4675
** ^If the nByte argument is negative, then zSql is read up to the
4547
-** first zero terminator. ^If nByte is positive, then it is the
4548
-** number of bytes read from zSql. ^If nByte is zero, then no prepared
4676
+** first zero terminator. ^If nByte is positive, then it is the maximum
4677
+** number of bytes read from zSql. When nByte is positive, zSql is read
4678
+** up to the first zero terminator or until the nByte bytes have been read,
4679
+** whichever comes first. ^If nByte is zero, then no prepared
4680
** statement is generated.
4681
** If the caller knows that the supplied string is nul-terminated, then
4682
** there is a small performance advantage to passing an nByte parameter that
4683
** is the number of bytes in the input string <i>including</i>
4684
** the nul-terminator.
4685
+** Note that nByte measure the length of the input in bytes, not
4686
+** characters, even for the UTF-16 interfaces.
4687
**
4688
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4689
** past the end of the first SQL statement in zSql. These routines only
@@ -5921,7 +6054,7 @@ SQLITE_API int sqlite3_create_window_function(
6054
** This flag instructs SQLite to omit some corner-case optimizations that
6055
** might disrupt the operation of the [sqlite3_value_subtype()] function,
6056
** causing it to return zero rather than the correct subtype().
5924
-** SQL functions that invokes [sqlite3_value_subtype()] should have this
6057
+** All SQL functions that invoke [sqlite3_value_subtype()] should have this
6058
** property. If the SQLITE_SUBTYPE property is omitted, then the return
6059
** value from [sqlite3_value_subtype()] might sometimes be zero even though
6060
** a non-zero subtype was specified by the function argument expression.
@@ -5937,6 +6070,15 @@ SQLITE_API int sqlite3_create_window_function(
6070
** [sqlite3_result_subtype()] should avoid setting this property, as the
6071
** purpose of this property is to disable certain optimizations that are
6072
** incompatible with subtypes.
6073
+**
6074
+** [[SQLITE_SELFORDER1]] <dt>SQLITE_SELFORDER1</dt><dd>
6075
+** The SQLITE_SELFORDER1 flag indicates that the function is an aggregate
6076
+** that internally orders the values provided to the first argument. The
6077
+** ordered-set aggregate SQL notation with a single ORDER BY term can be
6078
+** used to invoke this function. If the ordered-set aggregate notation is
6079
+** used on a function that lacks this flag, then an error is raised. Note
6080
+** that the ordered-set aggregate syntax is only available if SQLite is
6081
+** built using the -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES compile-time option.
6082
** </dd>
6083
** </dl>
6084
*/
@@ -5945,6 +6087,7 @@ SQLITE_API int sqlite3_create_window_function(
6087
#define SQLITE_SUBTYPE 0x000100000
6088
#define SQLITE_INNOCUOUS 0x000200000
6089
#define SQLITE_RESULT_SUBTYPE 0x001000000
6090
+#define SQLITE_SELFORDER1 0x002000000
6091
6092
/*
6093
** CAPI3REF: Deprecated Functions
@@ -6142,7 +6285,7 @@ SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
6285
** one SQL function to another. Use the [sqlite3_result_subtype()]
6286
** routine to set the subtype for the return value of an SQL function.
6287
**
6145
-** Every [application-defined SQL function] that invoke this interface
6288
+** Every [application-defined SQL function] that invokes this interface
6289
** should include the [SQLITE_SUBTYPE] property in the text
6290
** encoding argument when the function is [sqlite3_create_function|registered].
6291
** If the [SQLITE_SUBTYPE] property is omitted, then sqlite3_value_subtype()
@@ -7749,9 +7892,11 @@ struct sqlite3_module {
7892
** will be returned by the strategy.
7893
**
7894
** The xBestIndex method may optionally populate the idxFlags field with a
7752
-** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
7753
-** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
7754
-** assumes that the strategy may visit at most one row.
7895
+** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
7896
+** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7897
+** output to show the idxNum has hex instead of as decimal. Another flag is
7898
+** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
7899
+** return at most one row.
7900
**
7901
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
7902
** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -7815,7 +7960,9 @@ struct sqlite3_index_info {
7960
** [sqlite3_index_info].idxFlags field to some combination of
7961
** these bits.
7962
*/
7818
-#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
7963
+#define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */
7964
+#define SQLITE_INDEX_SCAN_HEX 0x00000002 /* Display idxNum as hex */
7965
+ /* in EXPLAIN QUERY PLAN */
7966
7967
/*
7968
** CAPI3REF: Virtual Table Constraint Operator Codes
@@ -8652,6 +8799,7 @@ SQLITE_API int sqlite3_test_control(int op, ...);
8799
#define SQLITE_TESTCTRL_JSON_SELFCHECK 14
8800
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
8801
#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */
8802
+#define SQLITE_TESTCTRL_GETOPT 16
8803
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
8804
#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17
8805
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
@@ -8671,7 +8819,7 @@ SQLITE_API int sqlite3_test_control(int op, ...);
8819
#define SQLITE_TESTCTRL_TRACEFLAGS 31
8820
#define SQLITE_TESTCTRL_TUNE 32
8821
#define SQLITE_TESTCTRL_LOGEST 33
8674
-#define SQLITE_TESTCTRL_USELONGDOUBLE 34
8822
+#define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
8823
#define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
8824
8825
/*
@@ -9647,6 +9795,16 @@ typedef struct sqlite3_backup sqlite3_backup;
9795
** APIs are not strictly speaking threadsafe. If they are invoked at the
9796
** same time as another thread is invoking sqlite3_backup_step() it is
9797
** possible that they return invalid values.
9798
+**
9799
+** <b>Alternatives To Using The Backup API</b>
9800
+**
9801
+** Other techniques for safely creating a consistent backup of an SQLite
9802
+** database include:
9803
+**
9804
+** <ul>
9805
+** <li> The [VACUUM INTO] command.
9806
+** <li> The [sqlite3_rsync] utility program.
9807
+** </ul>
9808
*/
9809
SQLITE_API sqlite3_backup *sqlite3_backup_init(
9810
sqlite3 *pDest, /* Destination database handle */
@@ -10846,6 +11004,14 @@ typedef struct sqlite3_snapshot {
11004
** If there is not already a read-transaction open on schema S when
11005
** this function is called, one is opened automatically.
11006
**
11007
+** If a read-transaction is opened by this function, then it is guaranteed
11008
+** that the returned snapshot object may not be invalidated by a database
11009
+** writer or checkpointer until after the read-transaction is closed. This
11010
+** is not guaranteed if a read-transaction is already open when this
11011
+** function is called. In that case, any subsequent write or checkpoint
11012
+** operation on the database may invalidate the returned snapshot handle,
11013
+** even while the read-transaction remains open.
11014
+**
11015
** The following must be true for this function to succeed. If any of
11016
** the following statements are false when sqlite3_snapshot_get() is
11017
** called, SQLITE_ERROR is returned. The final value of *P is undefined
@@ -11003,8 +11169,9 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const c
11169
/*
11170
** CAPI3REF: Serialize a database
11171
**
11006
-** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
11007
-** that is a serialization of the S database on [database connection] D.
11172
+** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
11173
+** memory that is a serialization of the S database on
11174
+** [database connection] D. If S is a NULL pointer, the main database is used.
11175
** If P is not a NULL pointer, then the size of the database in bytes
11176
** is written into *P.
11177
**
@@ -11154,8 +11321,6 @@ SQLITE_API int sqlite3_deserialize(
11321
#if defined(__wasi__)
11322
# undef SQLITE_WASI
11323
# define SQLITE_WASI 1
11157
-# undef SQLITE_OMIT_WAL
11158
-# define SQLITE_OMIT_WAL 1/* because it requires shared memory APIs */
11324
# ifndef SQLITE_OMIT_LOAD_EXTENSION
11325
# define SQLITE_OMIT_LOAD_EXTENSION
11326
# endif
@@ -11167,7 +11332,7 @@ SQLITE_API int sqlite3_deserialize(
11332
#if 0
11333
} /* End of the 'extern "C"' block */
11334
#endif
11170
-#endif /* SQLITE3_H */
11335
+/* #endif for SQLITE3_H will be added by mksqlite3.tcl */
11336
11337
/******** Begin file sqlite3rtree.h *********/
11338
/*
@@ -13358,6 +13523,10 @@ struct Fts5PhraseIter {
13523
** (i.e. if it is a contentless table), then this API always iterates
13524
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
13525
**
13526
+** In all cases, matches are visited in (column ASC, offset ASC) order.
13527
+** i.e. all those in column 0, sorted by offset, followed by those in
13528
+** column 1, etc.
13529
+**
13530
** xPhraseNext()
13531
** See xPhraseFirst above.
13532
**
@@ -13414,19 +13583,57 @@ struct Fts5PhraseIter {
13583
** value returned by xInstCount(), SQLITE_RANGE is returned. Otherwise,
13584
** output variable (*ppToken) is set to point to a buffer containing the
13585
** matching document token, and (*pnToken) to the size of that buffer in
13417
-** bytes. This API is not available if the specified token matches a
13418
-** prefix query term. In that case both output variables are always set
13419
-** to 0.
13586
+** bytes.
13587
**
13588
** The output text is not a copy of the document text that was tokenized.
13589
** It is the output of the tokenizer module. For tokendata=1 tables, this
13590
** includes any embedded 0x00 and trailing data.
13591
**
13592
+** This API may be slow in some cases if the token identified by parameters
13593
+** iIdx and iToken matched a prefix token in the query. In most cases, the
13594
+** first call to this API for each prefix token in the query is forced
13595
+** to scan the portion of the full-text index that matches the prefix
13596
+** token to collect the extra data required by this API. If the prefix
13597
+** token matches a large number of token instances in the document set,
13598
+** this may be a performance problem.
13599
+**
13600
+** If the user knows in advance that a query may use this API for a
13601
+** prefix token, FTS5 may be configured to collect all required data as part
13602
+** of the initial querying of the full-text index, avoiding the second scan
13603
+** entirely. This also causes prefix queries that do not use this API to
13604
+** run more slowly and use more memory. FTS5 may be configured in this way
13605
+** either on a per-table basis using the [FTS5 insttoken | 'insttoken']
13606
+** option, or on a per-query basis using the
13607
+** [fts5_insttoken | fts5_insttoken()] user function.
13608
+**
13609
** This API can be quite slow if used with an FTS5 table created with the
13610
** "detail=none" or "detail=column" option.
13611
+**
13612
+** xColumnLocale(pFts5, iIdx, pzLocale, pnLocale)
13613
+** If parameter iCol is less than zero, or greater than or equal to the
13614
+** number of columns in the table, SQLITE_RANGE is returned.
13615
+**
13616
+** Otherwise, this function attempts to retrieve the locale associated
13617
+** with column iCol of the current row. Usually, there is no associated
13618
+** locale, and output parameters (*pzLocale) and (*pnLocale) are set
13619
+** to NULL and 0, respectively. However, if the fts5_locale() function
13620
+** was used to associate a locale with the value when it was inserted
13621
+** into the fts5 table, then (*pzLocale) is set to point to a nul-terminated
13622
+** buffer containing the name of the locale in utf-8 encoding. (*pnLocale)
13623
+** is set to the size in bytes of the buffer, not including the
13624
+** nul-terminator.
13625
+**
13626
+** If successful, SQLITE_OK is returned. Or, if an error occurs, an
13627
+** SQLite error code is returned. The final value of the output parameters
13628
+** is undefined in this case.
13629
+**
13630
+** xTokenize_v2:
13631
+** Tokenize text using the tokenizer belonging to the FTS5 table. This
13632
+** API is the same as the xTokenize() API, except that it allows a tokenizer
13633
+** locale to be specified.
13634
*/
13635
struct Fts5ExtensionApi {
13429
- int iVersion; /* Currently always set to 3 */
13636
+ int iVersion; /* Currently always set to 4 */
13637
13638
void *(*xUserData)(Fts5Context*);
13639
@@ -13468,6 +13675,15 @@ struct Fts5ExtensionApi {
13675
const char **ppToken, int *pnToken
13676
);
13677
int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*);
13678
+
13679
+ /* Below this point are iVersion>=4 only */
13680
+ int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn);
13681
+ int (*xTokenize_v2)(Fts5Context*,
13682
+ const char *pText, int nText, /* Text to tokenize */
13683
+ const char *pLocale, int nLocale, /* Locale to pass to tokenizer */
13684
+ void *pCtx, /* Context passed to xToken() */
13685
+ int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
13686
+ );
13687
};
13688
13689
/*
@@ -13488,7 +13704,7 @@ struct Fts5ExtensionApi {
13704
** A tokenizer instance is required to actually tokenize text.
13705
**
13706
** The first argument passed to this function is a copy of the (void*)
13491
-** pointer provided by the application when the fts5_tokenizer object
13707
+** pointer provided by the application when the fts5_tokenizer_v2 object
13708
** was registered with FTS5 (the third argument to xCreateTokenizer()).
13709
** The second and third arguments are an array of nul-terminated strings
13710
** containing the tokenizer arguments, if any, specified following the
@@ -13512,7 +13728,7 @@ struct Fts5ExtensionApi {
13728
** argument passed to this function is a pointer to an Fts5Tokenizer object
13729
** returned by an earlier call to xCreate().
13730
**
13515
-** The second argument indicates the reason that FTS5 is requesting
13731
+** The third argument indicates the reason that FTS5 is requesting
13732
** tokenization of the supplied text. This is always one of the following
13733
** four values:
13734
**
@@ -13536,6 +13752,13 @@ struct Fts5ExtensionApi {
13752
** on a columnsize=0 database.
13753
** </ul>
13754
**
13755
+** The sixth and seventh arguments passed to xTokenize() - pLocale and
13756
+** nLocale - are a pointer to a buffer containing the locale to use for
13757
+** tokenization (e.g. "en_US") and its size in bytes, respectively. The
13758
+** pLocale buffer is not nul-terminated. pLocale may be passed NULL (in
13759
+** which case nLocale is always 0) to indicate that the tokenizer should
13760
+** use its default locale.
13761
+**
13762
** For each token in the input string, the supplied callback xToken() must
13763
** be invoked. The first argument to it should be a copy of the pointer
13764
** passed as the second argument to xTokenize(). The third and fourth
@@ -13559,6 +13782,30 @@ struct Fts5ExtensionApi {
13782
** may abandon the tokenization and return any error code other than
13783
** SQLITE_OK or SQLITE_DONE.
13784
**
13785
+** If the tokenizer is registered using an fts5_tokenizer_v2 object,
13786
+** then the xTokenize() method has two additional arguments - pLocale
13787
+** and nLocale. These specify the locale that the tokenizer should use
13788
+** for the current request. If pLocale and nLocale are both 0, then the
13789
+** tokenizer should use its default locale. Otherwise, pLocale points to
13790
+** an nLocale byte buffer containing the name of the locale to use as utf-8
13791
+** text. pLocale is not nul-terminated.
13792
+**
13793
+** FTS5_TOKENIZER
13794
+**
13795
+** There is also an fts5_tokenizer object. This is an older, deprecated,
13796
+** version of fts5_tokenizer_v2. It is similar except that:
13797
+**
13798
+** <ul>
13799
+** <li> There is no "iVersion" field, and
13800
+** <li> The xTokenize() method does not take a locale argument.
13801
+** </ul>
13802
+**
13803
+** Legacy fts5_tokenizer tokenizers must be registered using the
13804
+** legacy xCreateTokenizer() function, instead of xCreateTokenizer_v2().
13805
+**
13806
+** Tokenizer implementations registered using either API may be retrieved
13807
+** using both xFindTokenizer() and xFindTokenizer_v2().
13808
+**
13809
** SYNONYM SUPPORT
13810
**
13811
** Custom tokenizers may also support synonyms. Consider a case in which a
@@ -13667,6 +13914,33 @@ struct Fts5ExtensionApi {
13914
** inefficient.
13915
*/
13916
typedef struct Fts5Tokenizer Fts5Tokenizer;
13917
+typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2;
13918
+struct fts5_tokenizer_v2 {
13919
+ int iVersion; /* Currently always 2 */
13920
+
13921
+ int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
13922
+ void (*xDelete)(Fts5Tokenizer*);
13923
+ int (*xTokenize)(Fts5Tokenizer*,
13924
+ void *pCtx,
13925
+ int flags, /* Mask of FTS5_TOKENIZE_* flags */
13926
+ const char *pText, int nText,
13927
+ const char *pLocale, int nLocale,
13928
+ int (*xToken)(
13929
+ void *pCtx, /* Copy of 2nd argument to xTokenize() */
13930
+ int tflags, /* Mask of FTS5_TOKEN_* flags */
13931
+ const char *pToken, /* Pointer to buffer containing token */
13932
+ int nToken, /* Size of token in bytes */
13933
+ int iStart, /* Byte offset of token within input text */
13934
+ int iEnd /* Byte offset of end of token within input text */
13935
+ )
13936
+ );
13937
+};
13938
+
13939
+/*
13940
+** New code should use the fts5_tokenizer_v2 type to define tokenizer
13941
+** implementations. The following type is included for legacy applications
13942
+** that still use it.
13943
+*/
13944
typedef struct fts5_tokenizer fts5_tokenizer;
13945
struct fts5_tokenizer {
13946
int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
@@ -13686,6 +13960,7 @@ struct fts5_tokenizer {
13960
);
13961
};
13962
13963
+
13964
/* Flags that may be passed as the third argument to xTokenize() */
13965
#define FTS5_TOKENIZE_QUERY 0x0001
13966
#define FTS5_TOKENIZE_PREFIX 0x0002
@@ -13705,7 +13980,7 @@ struct fts5_tokenizer {
13980
*/
13981
typedef struct fts5_api fts5_api;
13982
struct fts5_api {
13708
- int iVersion; /* Currently always set to 2 */
13983
+ int iVersion; /* Currently always set to 3 */
13984
13985
/* Create a new tokenizer */
13986
int (*xCreateTokenizer)(
@@ -13732,6 +14007,25 @@ struct fts5_api {
14007
fts5_extension_function xFunction,
14008
void (*xDestroy)(void*)
14009
);
14010
+
14011
+ /* APIs below this point are only available if iVersion>=3 */
14012
+
14013
+ /* Create a new tokenizer */
14014
+ int (*xCreateTokenizer_v2)(
14015
+ fts5_api *pApi,
14016
+ const char *zName,
14017
+ void *pUserData,
14018
+ fts5_tokenizer_v2 *pTokenizer,
14019
+ void (*xDestroy)(void*)
14020
+ );
14021
+
14022
+ /* Find an existing tokenizer */
14023
+ int (*xFindTokenizer_v2)(
14024
+ fts5_api *pApi,
14025
+ const char *zName,
14026
+ void **ppUserData,
14027
+ fts5_tokenizer_v2 **ppTokenizer
14028
+ );
14029
};
14030
14031
/*
@@ -13745,6 +14039,7 @@ struct fts5_api {
14039
#endif /* _FTS5_H */
14040
14041
/******** End of fts5.h *********/
14042
+#endif /* SQLITE3_H */
14043
14044
/************** End of sqlite3.h *********************************************/
14045
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -13790,6 +14085,7 @@ struct fts5_api {
14085
#ifndef SQLITE_MAX_LENGTH
14086
# define SQLITE_MAX_LENGTH 1000000000
14087
#endif
14088
+#define SQLITE_MIN_LENGTH 30 /* Minimum value for the length limit */
14089
14090
/*
14091
** This is the maximum number of
@@ -13855,9 +14151,13 @@ struct fts5_api {
14151
14152
/*
14153
** The maximum number of arguments to an SQL function.
14154
+**
14155
+** This value has a hard upper limit of 32767 due to storage
14156
+** constraints (it needs to fit inside a i16). We keep it
14157
+** lower than that to prevent abuse.
14158
*/
14159
#ifndef SQLITE_MAX_FUNCTION_ARG
13860
-# define SQLITE_MAX_FUNCTION_ARG 127
14160
+# define SQLITE_MAX_FUNCTION_ARG 1000
14161
#endif
14162
14163
/*
@@ -14541,132 +14841,132 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
14841
#define TK_OR 43
14842
#define TK_AND 44
14843
#define TK_IS 45
14544
-#define TK_MATCH 46
14545
-#define TK_LIKE_KW 47
14546
-#define TK_BETWEEN 48
14547
-#define TK_IN 49
14548
-#define TK_ISNULL 50
14549
-#define TK_NOTNULL 51
14550
-#define TK_NE 52
14551
-#define TK_EQ 53
14552
-#define TK_GT 54
14553
-#define TK_LE 55
14554
-#define TK_LT 56
14555
-#define TK_GE 57
14556
-#define TK_ESCAPE 58
14557
-#define TK_ID 59
14558
-#define TK_COLUMNKW 60
14559
-#define TK_DO 61
14560
-#define TK_FOR 62
14561
-#define TK_IGNORE 63
14562
-#define TK_INITIALLY 64
14563
-#define TK_INSTEAD 65
14564
-#define TK_NO 66
14565
-#define TK_KEY 67
14566
-#define TK_OF 68
14567
-#define TK_OFFSET 69
14568
-#define TK_PRAGMA 70
14569
-#define TK_RAISE 71
14570
-#define TK_RECURSIVE 72
14571
-#define TK_REPLACE 73
14572
-#define TK_RESTRICT 74
14573
-#define TK_ROW 75
14574
-#define TK_ROWS 76
14575
-#define TK_TRIGGER 77
14576
-#define TK_VACUUM 78
14577
-#define TK_VIEW 79
14578
-#define TK_VIRTUAL 80
14579
-#define TK_WITH 81
14580
-#define TK_NULLS 82
14581
-#define TK_FIRST 83
14582
-#define TK_LAST 84
14583
-#define TK_CURRENT 85
14584
-#define TK_FOLLOWING 86
14585
-#define TK_PARTITION 87
14586
-#define TK_PRECEDING 88
14587
-#define TK_RANGE 89
14588
-#define TK_UNBOUNDED 90
14589
-#define TK_EXCLUDE 91
14590
-#define TK_GROUPS 92
14591
-#define TK_OTHERS 93
14592
-#define TK_TIES 94
14593
-#define TK_GENERATED 95
14594
-#define TK_ALWAYS 96
14595
-#define TK_MATERIALIZED 97
14596
-#define TK_REINDEX 98
14597
-#define TK_RENAME 99
14598
-#define TK_CTIME_KW 100
14599
-#define TK_ANY 101
14600
-#define TK_BITAND 102
14601
-#define TK_BITOR 103
14602
-#define TK_LSHIFT 104
14603
-#define TK_RSHIFT 105
14604
-#define TK_PLUS 106
14605
-#define TK_MINUS 107
14606
-#define TK_STAR 108
14607
-#define TK_SLASH 109
14608
-#define TK_REM 110
14609
-#define TK_CONCAT 111
14610
-#define TK_PTR 112
14611
-#define TK_COLLATE 113
14612
-#define TK_BITNOT 114
14613
-#define TK_ON 115
14614
-#define TK_INDEXED 116
14615
-#define TK_STRING 117
14616
-#define TK_JOIN_KW 118
14617
-#define TK_CONSTRAINT 119
14618
-#define TK_DEFAULT 120
14619
-#define TK_NULL 121
14620
-#define TK_PRIMARY 122
14621
-#define TK_UNIQUE 123
14622
-#define TK_CHECK 124
14623
-#define TK_REFERENCES 125
14624
-#define TK_AUTOINCR 126
14625
-#define TK_INSERT 127
14626
-#define TK_DELETE 128
14627
-#define TK_UPDATE 129
14628
-#define TK_SET 130
14629
-#define TK_DEFERRABLE 131
14630
-#define TK_FOREIGN 132
14631
-#define TK_DROP 133
14632
-#define TK_UNION 134
14633
-#define TK_ALL 135
14634
-#define TK_EXCEPT 136
14635
-#define TK_INTERSECT 137
14636
-#define TK_SELECT 138
14637
-#define TK_VALUES 139
14638
-#define TK_DISTINCT 140
14639
-#define TK_DOT 141
14640
-#define TK_FROM 142
14641
-#define TK_JOIN 143
14642
-#define TK_USING 144
14643
-#define TK_ORDER 145
14644
-#define TK_GROUP 146
14645
-#define TK_HAVING 147
14646
-#define TK_LIMIT 148
14647
-#define TK_WHERE 149
14648
-#define TK_RETURNING 150
14649
-#define TK_INTO 151
14650
-#define TK_NOTHING 152
14651
-#define TK_FLOAT 153
14652
-#define TK_BLOB 154
14653
-#define TK_INTEGER 155
14654
-#define TK_VARIABLE 156
14655
-#define TK_CASE 157
14656
-#define TK_WHEN 158
14657
-#define TK_THEN 159
14658
-#define TK_ELSE 160
14659
-#define TK_INDEX 161
14660
-#define TK_ALTER 162
14661
-#define TK_ADD 163
14662
-#define TK_WINDOW 164
14663
-#define TK_OVER 165
14664
-#define TK_FILTER 166
14665
-#define TK_COLUMN 167
14666
-#define TK_AGG_FUNCTION 168
14667
-#define TK_AGG_COLUMN 169
14668
-#define TK_TRUEFALSE 170
14669
-#define TK_ISNOT 171
14844
+#define TK_ISNOT 46
14845
+#define TK_MATCH 47
14846
+#define TK_LIKE_KW 48
14847
+#define TK_BETWEEN 49
14848
+#define TK_IN 50
14849
+#define TK_ISNULL 51
14850
+#define TK_NOTNULL 52
14851
+#define TK_NE 53
14852
+#define TK_EQ 54
14853
+#define TK_GT 55
14854
+#define TK_LE 56
14855
+#define TK_LT 57
14856
+#define TK_GE 58
14857
+#define TK_ESCAPE 59
14858
+#define TK_ID 60
14859
+#define TK_COLUMNKW 61
14860
+#define TK_DO 62
14861
+#define TK_FOR 63
14862
+#define TK_IGNORE 64
14863
+#define TK_INITIALLY 65
14864
+#define TK_INSTEAD 66
14865
+#define TK_NO 67
14866
+#define TK_KEY 68
14867
+#define TK_OF 69
14868
+#define TK_OFFSET 70
14869
+#define TK_PRAGMA 71
14870
+#define TK_RAISE 72
14871
+#define TK_RECURSIVE 73
14872
+#define TK_REPLACE 74
14873
+#define TK_RESTRICT 75
14874
+#define TK_ROW 76
14875
+#define TK_ROWS 77
14876
+#define TK_TRIGGER 78
14877
+#define TK_VACUUM 79
14878
+#define TK_VIEW 80
14879
+#define TK_VIRTUAL 81
14880
+#define TK_WITH 82
14881
+#define TK_NULLS 83
14882
+#define TK_FIRST 84
14883
+#define TK_LAST 85
14884
+#define TK_CURRENT 86
14885
+#define TK_FOLLOWING 87
14886
+#define TK_PARTITION 88
14887
+#define TK_PRECEDING 89
14888
+#define TK_RANGE 90
14889
+#define TK_UNBOUNDED 91
14890
+#define TK_EXCLUDE 92
14891
+#define TK_GROUPS 93
14892
+#define TK_OTHERS 94
14893
+#define TK_TIES 95
14894
+#define TK_GENERATED 96
14895
+#define TK_ALWAYS 97
14896
+#define TK_MATERIALIZED 98
14897
+#define TK_REINDEX 99
14898
+#define TK_RENAME 100
14899
+#define TK_CTIME_KW 101
14900
+#define TK_ANY 102
14901
+#define TK_BITAND 103
14902
+#define TK_BITOR 104
14903
+#define TK_LSHIFT 105
14904
+#define TK_RSHIFT 106
14905
+#define TK_PLUS 107
14906
+#define TK_MINUS 108
14907
+#define TK_STAR 109
14908
+#define TK_SLASH 110
14909
+#define TK_REM 111
14910
+#define TK_CONCAT 112
14911
+#define TK_PTR 113
14912
+#define TK_COLLATE 114
14913
+#define TK_BITNOT 115
14914
+#define TK_ON 116
14915
+#define TK_INDEXED 117
14916
+#define TK_STRING 118
14917
+#define TK_JOIN_KW 119
14918
+#define TK_CONSTRAINT 120
14919
+#define TK_DEFAULT 121
14920
+#define TK_NULL 122
14921
+#define TK_PRIMARY 123
14922
+#define TK_UNIQUE 124
14923
+#define TK_CHECK 125
14924
+#define TK_REFERENCES 126
14925
+#define TK_AUTOINCR 127
14926
+#define TK_INSERT 128
14927
+#define TK_DELETE 129
14928
+#define TK_UPDATE 130
14929
+#define TK_SET 131
14930
+#define TK_DEFERRABLE 132
14931
+#define TK_FOREIGN 133
14932
+#define TK_DROP 134
14933
+#define TK_UNION 135
14934
+#define TK_ALL 136
14935
+#define TK_EXCEPT 137
14936
+#define TK_INTERSECT 138
14937
+#define TK_SELECT 139
14938
+#define TK_VALUES 140
14939
+#define TK_DISTINCT 141
14940
+#define TK_DOT 142
14941
+#define TK_FROM 143
14942
+#define TK_JOIN 144
14943
+#define TK_USING 145
14944
+#define TK_ORDER 146
14945
+#define TK_GROUP 147
14946
+#define TK_HAVING 148
14947
+#define TK_LIMIT 149
14948
+#define TK_WHERE 150
14949
+#define TK_RETURNING 151
14950
+#define TK_INTO 152
14951
+#define TK_NOTHING 153
14952
+#define TK_FLOAT 154
14953
+#define TK_BLOB 155
14954
+#define TK_INTEGER 156
14955
+#define TK_VARIABLE 157
14956
+#define TK_CASE 158
14957
+#define TK_WHEN 159
14958
+#define TK_THEN 160
14959
+#define TK_ELSE 161
14960
+#define TK_INDEX 162
14961
+#define TK_ALTER 163
14962
+#define TK_ADD 164
14963
+#define TK_WINDOW 165
14964
+#define TK_OVER 166
14965
+#define TK_FILTER 167
14966
+#define TK_COLUMN 168
14967
+#define TK_AGG_FUNCTION 169
14968
+#define TK_AGG_COLUMN 170
14969
+#define TK_TRUEFALSE 171
14970
#define TK_FUNCTION 172
14971
#define TK_UPLUS 173
14972
#define TK_UMINUS 174
@@ -14680,7 +14980,8 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
14980
#define TK_ERROR 182
14981
#define TK_QNUMBER 183
14982
#define TK_SPACE 184
14683
-#define TK_ILLEGAL 185
14983
+#define TK_COMMENT 185
14984
+#define TK_ILLEGAL 186
14985
14986
/************** End of parse.h ***********************************************/
14987
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -14689,6 +14990,7 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
14990
#include <string.h>
14991
#include <assert.h>
14992
#include <stddef.h>
14993
+#include <ctype.h>
14994
14995
/*
14996
** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
@@ -14709,7 +15011,8 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
15011
#ifdef SQLITE_OMIT_FLOATING_POINT
15012
# define double sqlite_int64
15013
# define float sqlite_int64
14712
-# define LONGDOUBLE_TYPE sqlite_int64
15014
+# define fabs(X) ((X)<0?-(X):(X))
15015
+# define sqlite3IsOverflow(X) 0
15016
# ifndef SQLITE_BIG_DBL
15017
# define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
15018
# endif
@@ -14884,9 +15187,6 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
15187
# define INT8_TYPE signed char
15188
# endif
15189
#endif
14887
-#ifndef LONGDOUBLE_TYPE
14888
-# define LONGDOUBLE_TYPE long double
14889
-#endif
15190
typedef sqlite_int64 i64; /* 8-byte signed integer */
15191
typedef sqlite_uint64 u64; /* 8-byte unsigned integer */
15192
typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
@@ -14933,6 +15233,8 @@ typedef u64 tRowcnt;
15233
** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
15234
*/
15235
typedef INT16_TYPE LogEst;
15236
+#define LOGEST_MIN (-32768)
15237
+#define LOGEST_MAX (32767)
15238
15239
/*
15240
** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
@@ -15203,7 +15505,7 @@ SQLITE_PRIVATE u32 sqlite3WhereTrace;
15505
** 0xFFFF---- Low-level debug messages
15506
**
15507
** 0x00000001 Code generation
15206
-** 0x00000002 Solver
15508
+** 0x00000002 Solver (Use 0x40000 for less detail)
15509
** 0x00000004 Solver costs
15510
** 0x00000008 WhereLoop inserts
15511
**
@@ -15222,6 +15524,8 @@ SQLITE_PRIVATE u32 sqlite3WhereTrace;
15524
**
15525
** 0x00010000 Show more detail when printing WHERE terms
15526
** 0x00020000 Show WHERE terms returned from whereScanNext()
15527
+** 0x00040000 Solver overview messages
15528
+** 0x00080000 Star-query heuristic
15529
*/
15530
15531
@@ -15386,6 +15690,7 @@ typedef struct Savepoint Savepoint;
15690
typedef struct Select Select;
15691
typedef struct SQLiteThread SQLiteThread;
15692
typedef struct SelectDest SelectDest;
15693
+typedef struct Subquery Subquery;
15694
typedef struct SrcItem SrcItem;
15695
typedef struct SrcList SrcList;
15696
typedef struct sqlite3_str StrAccum; /* Internal alias for sqlite3_str */
@@ -15859,6 +16164,22 @@ typedef struct PgHdr DbPage;
16164
#define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
16165
#define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
16166
16167
+#define isWalMode(x) ((x)==PAGER_JOURNALMODE_WAL)
16168
+
16169
+/*
16170
+** The argument to this macro is a file descriptor (type sqlite3_file*).
16171
+** Return 0 if it is not open, or non-zero (but not 1) if it is.
16172
+**
16173
+** This is so that expressions can be written as:
16174
+**
16175
+** if( isOpen(pPager->jfd) ){ ...
16176
+**
16177
+** instead of
16178
+**
16179
+** if( pPager->jfd->pMethods ){ ...
16180
+*/
16181
+#define isOpen(pFd) ((pFd)->pMethods!=0)
16182
+
16183
/*
16184
** Flags that make up the mask passed to sqlite3PagerGet().
16185
*/
@@ -16268,6 +16589,9 @@ SQLITE_PRIVATE int sqlite3BtreeCursor(
16589
);
16590
SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void);
16591
SQLITE_PRIVATE int sqlite3BtreeCursorSize(void);
16592
+#ifdef SQLITE_DEBUG
16593
+SQLITE_PRIVATE int sqlite3BtreeClosesWithCursor(Btree*,BtCursor*);
16594
+#endif
16595
SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
16596
SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
16597
#ifdef SQLITE_ENABLE_CURSOR_HINTS
@@ -16486,6 +16810,20 @@ typedef struct Vdbe Vdbe;
16810
*/
16811
typedef struct sqlite3_value Mem;
16812
typedef struct SubProgram SubProgram;
16813
+typedef struct SubrtnSig SubrtnSig;
16814
+
16815
+/*
16816
+** A signature for a reusable subroutine that materializes the RHS of
16817
+** an IN operator.
16818
+*/
16819
+struct SubrtnSig {
16820
+ int selId; /* SELECT-id for the SELECT statement on the RHS */
16821
+ u8 bComplete; /* True if fully coded and available for reusable */
16822
+ char *zAff; /* Affinity of the overall IN expression */
16823
+ int iTable; /* Ephemeral table generated by the subroutine */
16824
+ int iAddr; /* Subroutine entry address */
16825
+ int regReturn; /* Register used to hold return address */
16826
+};
16827
16828
/*
16829
** A single instruction of the virtual machine has an opcode
@@ -16514,6 +16852,7 @@ struct VdbeOp {
16852
u32 *ai; /* Used when p4type is P4_INTARRAY */
16853
SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
16854
Table *pTab; /* Used when p4type is P4_TABLE */
16855
+ SubrtnSig *pSubrtnSig; /* Used when p4type is P4_SUBRTNSIG */
16856
#ifdef SQLITE_ENABLE_CURSOR_HINTS
16857
Expr *pExpr; /* Used when p4type is P4_EXPR */
16858
#endif
@@ -16581,6 +16920,7 @@ typedef struct VdbeOpList VdbeOpList;
16920
#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */
16921
#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */
16922
#define P4_TABLEREF (-16) /* Like P4_TABLE, but reference counted */
16923
+#define P4_SUBRTNSIG (-17) /* P4 is a SubrtnSig pointer */
16924
16925
/* Error message codes for OP_Halt */
16926
#define P5_ConstraintNotNull 1
@@ -16672,16 +17012,16 @@ typedef struct VdbeOpList VdbeOpList;
17012
#define OP_RowSetTest 47 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
17013
#define OP_Program 48 /* jump0 */
17014
#define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
16675
-#define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
16676
-#define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
16677
-#define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
16678
-#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
16679
-#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
16680
-#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
16681
-#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
16682
-#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
16683
-#define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
16684
-#define OP_IfPos 59 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
17015
+#define OP_IfPos 50 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
17016
+#define OP_IsNull 51 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
17017
+#define OP_NotNull 52 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
17018
+#define OP_Ne 53 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
17019
+#define OP_Eq 54 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
17020
+#define OP_Gt 55 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
17021
+#define OP_Le 56 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
17022
+#define OP_Lt 57 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
17023
+#define OP_Ge 58 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
17024
+#define OP_ElseEq 59 /* jump, same as TK_ESCAPE */
17025
#define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
17026
#define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
17027
#define OP_IncrVacuum 62 /* jump */
@@ -16724,23 +17064,23 @@ typedef struct VdbeOpList VdbeOpList;
17064
#define OP_ReadCookie 99
17065
#define OP_SetCookie 100
17066
#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
16727
-#define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
16728
-#define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
16729
-#define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
16730
-#define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
16731
-#define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
16732
-#define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
16733
-#define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
16734
-#define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
16735
-#define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
16736
-#define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
16737
-#define OP_OpenRead 112 /* synopsis: root=P2 iDb=P3 */
17067
+#define OP_OpenRead 102 /* synopsis: root=P2 iDb=P3 */
17068
+#define OP_BitAnd 103 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
17069
+#define OP_BitOr 104 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
17070
+#define OP_ShiftLeft 105 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
17071
+#define OP_ShiftRight 106 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
17072
+#define OP_Add 107 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
17073
+#define OP_Subtract 108 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
17074
+#define OP_Multiply 109 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
17075
+#define OP_Divide 110 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
17076
+#define OP_Remainder 111 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
17077
+#define OP_Concat 112 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
17078
#define OP_OpenWrite 113 /* synopsis: root=P2 iDb=P3 */
16739
-#define OP_BitNot 114 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
16740
-#define OP_OpenDup 115
17079
+#define OP_OpenDup 114
17080
+#define OP_BitNot 115 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
17081
#define OP_OpenAutoindex 116 /* synopsis: nColumn=P2 */
16742
-#define OP_String8 117 /* same as TK_STRING, synopsis: r[P2]='P4' */
16743
-#define OP_OpenEphemeral 118 /* synopsis: nColumn=P2 */
17082
+#define OP_OpenEphemeral 117 /* synopsis: nColumn=P2 */
17083
+#define OP_String8 118 /* same as TK_STRING, synopsis: r[P2]='P4' */
17084
#define OP_SorterOpen 119
17085
#define OP_SequenceTest 120 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
17086
#define OP_OpenPseudo 121 /* synopsis: P3 columns in r[P2] */
@@ -16775,8 +17115,8 @@ typedef struct VdbeOpList VdbeOpList;
17115
#define OP_LoadAnalysis 150
17116
#define OP_DropTable 151
17117
#define OP_DropIndex 152
16778
-#define OP_Real 153 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
16779
-#define OP_DropTrigger 154
17118
+#define OP_DropTrigger 153
17119
+#define OP_Real 154 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
17120
#define OP_IntegrityCk 155
17121
#define OP_RowSetAdd 156 /* synopsis: rowset(P1)=r[P2] */
17122
#define OP_Param 157
@@ -16832,20 +17172,20 @@ typedef struct VdbeOpList VdbeOpList;
17172
/* 24 */ 0xc9, 0x01, 0x49, 0x49, 0x49, 0x49, 0xc9, 0x49,\
17173
/* 32 */ 0xc1, 0x01, 0x41, 0x41, 0xc1, 0x01, 0x41, 0x41,\
17174
/* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x23, 0x0b,\
16835
-/* 48 */ 0x81, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
16836
-/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x41,\
17175
+/* 48 */ 0x81, 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
17176
+/* 56 */ 0x0b, 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x41,\
17177
/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
17178
/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
17179
/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
17180
/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40, 0x00,\
16841
-/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x26, 0x26,\
17181
+/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x40, 0x26,\
17182
/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16843
-/* 112 */ 0x40, 0x00, 0x12, 0x40, 0x40, 0x10, 0x40, 0x00,\
17183
+/* 112 */ 0x26, 0x00, 0x40, 0x12, 0x40, 0x40, 0x10, 0x00,\
17184
/* 120 */ 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10, 0x10,\
17185
/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x50,\
17186
/* 136 */ 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50, 0x40,\
17187
/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
16848
-/* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
17188
+/* 152 */ 0x00, 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04,\
17189
/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
17190
/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x50,\
17191
/* 176 */ 0x40, 0x00, 0x10, 0x10, 0x02, 0x12, 0x12, 0x00,\
@@ -16866,7 +17206,7 @@ typedef struct VdbeOpList VdbeOpList;
17206
** Additional non-public SQLITE_PREPARE_* flags
17207
*/
17208
#define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
16869
-#define SQLITE_PREPARE_MASK 0x0f /* Mask of public flags */
17209
+#define SQLITE_PREPARE_MASK 0x1f /* Mask of public flags */
17210
17211
/*
17212
** Prototypes for the VDBE interface. See comments on the implementation
@@ -17581,47 +17921,11 @@ struct FuncDefHash {
17921
};
17922
#define SQLITE_FUNC_HASH(C,L) (((C)+(L))%SQLITE_FUNC_HASH_SZ)
17923
17584
-#if defined(SQLITE_USER_AUTHENTICATION)
17585
-# warning "The SQLITE_USER_AUTHENTICATION extension is deprecated. \
17586
- See ext/userauth/user-auth.txt for details."
17587
-#endif
17588
-#ifdef SQLITE_USER_AUTHENTICATION
17589
-/*
17590
-** Information held in the "sqlite3" database connection object and used
17591
-** to manage user authentication.
17592
-*/
17593
-typedef struct sqlite3_userauth sqlite3_userauth;
17594
-struct sqlite3_userauth {
17595
- u8 authLevel; /* Current authentication level */
17596
- int nAuthPW; /* Size of the zAuthPW in bytes */
17597
- char *zAuthPW; /* Password used to authenticate */
17598
- char *zAuthUser; /* User name used to authenticate */
17599
-};
17600
-
17601
-/* Allowed values for sqlite3_userauth.authLevel */
17602
-#define UAUTH_Unknown 0 /* Authentication not yet checked */
17603
-#define UAUTH_Fail 1 /* User authentication failed */
17604
-#define UAUTH_User 2 /* Authenticated as a normal user */
17605
-#define UAUTH_Admin 3 /* Authenticated as an administrator */
17606
-
17607
-/* Functions used only by user authorization logic */
17608
-SQLITE_PRIVATE int sqlite3UserAuthTable(const char*);
17609
-SQLITE_PRIVATE int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*);
17610
-SQLITE_PRIVATE void sqlite3UserAuthInit(sqlite3*);
17611
-SQLITE_PRIVATE void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**);
17612
-
17613
-#endif /* SQLITE_USER_AUTHENTICATION */
17614
-
17924
/*
17925
** typedef for the authorization callback function.
17926
*/
17618
-#ifdef SQLITE_USER_AUTHENTICATION
17619
- typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
17620
- const char*, const char*);
17621
-#else
17622
- typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
17623
- const char*);
17624
-#endif
17927
+typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
17928
+ const char*);
17929
17930
#ifndef SQLITE_OMIT_DEPRECATED
17931
/* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
@@ -17782,9 +18086,6 @@ struct sqlite3 {
18086
void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
18087
sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
18088
#endif
17785
-#ifdef SQLITE_USER_AUTHENTICATION
17786
- sqlite3_userauth auth; /* User authentication information */
17787
-#endif
18089
};
18090
18091
/*
@@ -17848,6 +18149,9 @@ struct sqlite3 {
18149
#define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */
18150
#define SQLITE_ReadUncommit HI(0x00004) /* READ UNCOMMITTED in shared-cache */
18151
#define SQLITE_FkNoAction HI(0x00008) /* Treat all FK as NO ACTION */
18152
+#define SQLITE_AttachCreate HI(0x00010) /* ATTACH allowed to create new dbs */
18153
+#define SQLITE_AttachWrite HI(0x00020) /* ATTACH allowed to open for write */
18154
+#define SQLITE_Comments HI(0x00040) /* Enable SQL comments */
18155
18156
/* Flags used only if debugging */
18157
#ifdef SQLITE_DEBUG
@@ -17906,6 +18210,8 @@ struct sqlite3 {
18210
#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
18211
#define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
18212
#define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
18213
+#define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
18214
+#define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
18215
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
18216
18217
/*
@@ -17942,7 +18248,7 @@ struct sqlite3 {
18248
** field is used by per-connection app-def functions.
18249
*/
18250
struct FuncDef {
17945
- i8 nArg; /* Number of arguments. -1 means unlimited */
18251
+ i16 nArg; /* Number of arguments. -1 means unlimited */
18252
u32 funcFlags; /* Some combination of SQLITE_FUNC_* */
18253
void *pUserData; /* User data parameter */
18254
FuncDef *pNext; /* Next function with same name */
@@ -18893,9 +19199,15 @@ struct AggInfo {
19199
** assignAggregateRegisters() that computes the value of pAggInfo->iFirstReg.
19200
** The assert()s that are part of this macro verify that constraint.
19201
*/
19202
+#ifndef NDEBUG
19203
#define AggInfoColumnReg(A,I) (assert((A)->iFirstReg),(A)->iFirstReg+(I))
19204
#define AggInfoFuncReg(A,I) \
19205
(assert((A)->iFirstReg),(A)->iFirstReg+(A)->nColumn+(I))
19206
+#else
19207
+#define AggInfoColumnReg(A,I) ((A)->iFirstReg+(I))
19208
+#define AggInfoFuncReg(A,I) \
19209
+ ((A)->iFirstReg+(A)->nColumn+(I))
19210
+#endif
19211
19212
/*
19213
** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
@@ -19076,7 +19388,7 @@ struct Expr {
19388
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
19389
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
19390
#define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
19079
- /* 0x80000000 // Available */
19391
+#define EP_SubtArg 0x80000000 /* Is argument to SQLITE_SUBTYPE function */
19392
19393
/* The EP_Propagate mask is a set of properties that automatically propagate
19394
** upwards into parent nodes.
@@ -19229,13 +19541,8 @@ struct ExprList {
19541
*/
19542
struct IdList {
19543
int nId; /* Number of identifiers on the list */
19232
- u8 eU4; /* Which element of a.u4 is valid */
19544
struct IdList_item {
19545
char *zName; /* Name of the identifier */
19235
- union {
19236
- int idx; /* Index in some Table.aCol[] of a column named zName */
19237
- Expr *pExpr; /* Expr to implement a USING variable -- NOT USED */
19238
- } u4;
19546
} a[1];
19547
};
19548
@@ -19247,6 +19554,16 @@ struct IdList {
19554
#define EU4_IDX 1 /* Uses IdList.a.u4.idx */
19555
#define EU4_EXPR 2 /* Uses IdList.a.u4.pExpr -- NOT CURRENTLY USED */
19556
19557
+/*
19558
+** Details of the implementation of a subquery.
19559
+*/
19560
+struct Subquery {
19561
+ Select *pSelect; /* A SELECT statement used in place of a table name */
19562
+ int addrFillSub; /* Address of subroutine to initialize a subquery */
19563
+ int regReturn; /* Register holding return address of addrFillSub */
19564
+ int regResult; /* Registers holding results of a co-routine */
19565
+};
19566
+
19567
/*
19568
** The SrcItem object represents a single term in the FROM clause of a query.
19569
** The SrcList object is mostly an array of SrcItems.
@@ -19259,29 +19576,40 @@ struct IdList {
19576
** In the colUsed field, the high-order bit (bit 63) is set if the table
19577
** contains more than 63 columns and the 64-th or later column is used.
19578
**
19262
-** Union member validity:
19579
+** Aggressive use of "union" helps keep the size of the object small. This
19580
+** has been shown to boost performance, in addition to saving memory.
19581
+** Access to union elements is gated by the following rules which should
19582
+** always be checked, either by an if-statement or by an assert().
19583
**
19264
-** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc
19265
-** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy
19584
+** Field Only access if this is true
19585
+** --------------- -----------------------------------
19586
+** u1.zIndexedBy fg.isIndexedBy
19587
+** u1.pFuncArg fg.isTabFunc
19588
** u1.nRow !fg.isTabFunc && !fg.isIndexedBy
19589
**
19268
-** u2.pIBIndex fg.isIndexedBy && !fg.isCte
19269
-** u2.pCteUse fg.isCte && !fg.isIndexedBy
19590
+** u2.pIBIndex fg.isIndexedBy
19591
+** u2.pCteUse fg.isCte
19592
+**
19593
+** u3.pOn !fg.isUsing
19594
+** u3.pUsing fg.isUsing
19595
+**
19596
+** u4.zDatabase !fg.fixedSchema && !fg.isSubquery
19597
+** u4.pSchema fg.fixedSchema
19598
+** u4.pSubq fg.isSubquery
19599
+**
19600
+** See also the sqlite3SrcListDelete() routine for assert() statements that
19601
+** check invariants on the fields of this object, especially the flags
19602
+** inside the fg struct.
19603
*/
19604
struct SrcItem {
19272
- Schema *pSchema; /* Schema to which this item is fixed */
19273
- char *zDatabase; /* Name of database holding this table */
19605
char *zName; /* Name of the table */
19606
char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
19276
- Table *pTab; /* An SQL table corresponding to zName */
19277
- Select *pSelect; /* A SELECT statement used in place of a table name */
19278
- int addrFillSub; /* Address of subroutine to manifest a subquery */
19279
- int regReturn; /* Register holding return address of addrFillSub */
19280
- int regResult; /* Registers holding results of a co-routine */
19607
+ Table *pSTab; /* Table object for zName. Mnemonic: Srcitem-TABle */
19608
struct {
19609
u8 jointype; /* Type of join between this table and the previous */
19610
unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
19611
unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
19612
+ unsigned isSubquery :1; /* True if this term is a subquery */
19613
unsigned isTabFunc :1; /* True if table-valued-function syntax */
19614
unsigned isCorrelated :1; /* True if sub-query is correlated */
19615
unsigned isMaterialized:1; /* This is a materialized view */
@@ -19295,12 +19623,10 @@ struct SrcItem {
19623
unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */
19624
unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
19625
unsigned rowidUsed :1; /* The ROWID of this table is referenced */
19626
+ unsigned fixedSchema :1; /* Uses u4.pSchema, not u4.zDatabase */
19627
+ unsigned hadSchema :1; /* Had u4.zDatabase before u4.pSchema */
19628
} fg;
19629
int iCursor; /* The VDBE cursor number used to access this table */
19300
- union {
19301
- Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
19302
- IdList *pUsing; /* fg.isUsing==1 => The USING clause of a join */
19303
- } u3;
19630
Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */
19631
union {
19632
char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
@@ -19311,6 +19637,15 @@ struct SrcItem {
19637
Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */
19638
CteUse *pCteUse; /* CTE Usage info when fg.isCte is true */
19639
} u2;
19640
+ union {
19641
+ Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
19642
+ IdList *pUsing; /* fg.isUsing==1 => The USING clause of a join */
19643
+ } u3;
19644
+ union {
19645
+ Schema *pSchema; /* Schema to which this item is fixed */
19646
+ char *zDatabase; /* Name of database holding this table */
19647
+ Subquery *pSubq; /* Description of a subquery */
19648
+ } u4;
19649
};
19650
19651
/*
@@ -19442,7 +19777,7 @@ struct NameContext {
19777
#define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */
19778
#define NC_UBaseReg 0x000400 /* True if uNC.iBaseReg is used */
19779
#define NC_MinMaxAgg 0x001000 /* min/max aggregates seen. See note above */
19445
-#define NC_Complex 0x002000 /* True if a function or subquery seen */
19780
+/* 0x002000 // available for reuse */
19781
#define NC_AllowWin 0x004000 /* Window functions are allowed here */
19782
#define NC_HasWin 0x008000 /* One or more window functions seen */
19783
#define NC_IsDDL 0x010000 /* Resolving names in a CREATE statement */
@@ -19570,8 +19905,10 @@ struct Select {
19905
#define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
19906
#define SF_Correlated 0x20000000 /* True if references the outer context */
19907
19573
-/* True if S exists and has SF_NestedFrom */
19574
-#define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
19908
+/* True if SrcItem X is a subquery that has SF_NestedFrom */
19909
+#define IsNestedFrom(X) \
19910
+ ((X)->fg.isSubquery && \
19911
+ ((X)->u4.pSubq->pSelect->selFlags&SF_NestedFrom)!=0)
19912
19913
/*
19914
** The results of a SELECT can be distributed in several ways, as defined
@@ -19601,7 +19938,11 @@ struct Select {
19938
** SRT_Set The result must be a single column. Store each
19939
** row of result as the key in table pDest->iSDParm.
19940
** Apply the affinity pDest->affSdst before storing
19604
-** results. Used to implement "IN (SELECT ...)".
19941
+** results. if pDest->iSDParm2 is positive, then it is
19942
+** a register holding a Bloom filter for the IN operator
19943
+** that should be populated in addition to the
19944
+** pDest->iSDParm table. This SRT is used to
19945
+** implement "IN (SELECT ...)".
19946
**
19947
** SRT_EphemTab Create an temporary table pDest->iSDParm and store
19948
** the result there. The cursor is left open after
@@ -19809,6 +20150,7 @@ struct Parse {
20150
u8 prepFlags; /* SQLITE_PREPARE_* flags */
20151
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20152
u8 bHasWith; /* True if statement contains WITH */
20153
+ u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20154
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
20155
u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
20156
#endif
@@ -19887,9 +20229,7 @@ struct Parse {
20229
int nVtabLock; /* Number of virtual tables to lock */
20230
#endif
20231
int nHeight; /* Expression tree height of current sub-select */
19890
-#ifndef SQLITE_OMIT_EXPLAIN
20232
int addrExplain; /* Address of current OP_Explain opcode */
19892
-#endif
20233
VList *pVList; /* Mapping between variable names and numbers */
20234
Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
20235
const char *zTail; /* All SQL text past the last semicolon parsed */
@@ -20104,7 +20444,7 @@ struct Returning {
20444
};
20445
20446
/*
20107
-** An objected used to accumulate the text of a string where we
20447
+** An object used to accumulate the text of a string where we
20448
** do not necessarily know how big the string will be in the end.
20449
*/
20450
struct sqlite3_str {
@@ -20118,7 +20458,7 @@ struct sqlite3_str {
20458
};
20459
#define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
20460
#define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
20121
-#define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
20461
+#define SQLITE_PRINTF_MALLOCED 0x04 /* True if zText is allocated space */
20462
20463
#define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
20464
@@ -20196,7 +20536,6 @@ struct Sqlite3Config {
20536
u8 bUseCis; /* Use covering indices for full-scans */
20537
u8 bSmallMalloc; /* Avoid large memory allocations if true */
20538
u8 bExtraSchemaChecks; /* Verify type,name,tbl_name in schema */
20199
- u8 bUseLongDouble; /* Make use of long double */
20539
#ifdef SQLITE_DEBUG
20540
u8 bJsonSelfcheck; /* Double-check JSON parsing */
20541
#endif
@@ -20571,15 +20910,6 @@ SQLITE_PRIVATE int sqlite3CorruptPgnoError(int,Pgno);
20910
# define SQLITE_ENABLE_FTS3 1
20911
#endif
20912
20574
-/*
20575
-** The ctype.h header is needed for non-ASCII systems. It is also
20576
-** needed by FTS3 when FTS3 is included in the amalgamation.
20577
-*/
20578
-#if !defined(SQLITE_ASCII) || \
20579
- (defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_AMALGAMATION))
20580
-# include <ctype.h>
20581
-#endif
20582
-
20913
/*
20914
** The following macros mimic the standard library functions toupper(),
20915
** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The
@@ -20958,6 +21288,9 @@ SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
21288
SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(Parse*, SrcList*, int, int);
21289
SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2);
21290
SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(Parse*, SrcList*, Token*, Token*);
21291
+SQLITE_PRIVATE void sqlite3SubqueryDelete(sqlite3*,Subquery*);
21292
+SQLITE_PRIVATE Select *sqlite3SubqueryDetach(sqlite3*,SrcItem*);
21293
+SQLITE_PRIVATE int sqlite3SrcItemAttachSubquery(Parse*, SrcItem*, Select*, int);
21294
SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
21295
Token*, Select*, OnOrUsing*);
21296
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
@@ -21007,6 +21340,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int
21340
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
21341
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
21342
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
21343
+SQLITE_PRIVATE void sqlite3ExprToRegister(Expr *pExpr, int iReg);
21344
SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
21345
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
21346
SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Table*, Column*, int);
@@ -21069,7 +21403,7 @@ SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,i
21403
#ifdef SQLITE_ENABLE_CURSOR_HINTS
21404
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
21405
#endif
21072
-SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
21406
+SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*);
21407
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
21408
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
21409
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
@@ -21197,7 +21531,7 @@ SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
21531
SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
21532
SQLITE_PRIVATE int sqlite3Atoi(const char*);
21533
#ifndef SQLITE_OMIT_UTF16
21200
-SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
21534
+SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nByte, int nChar);
21535
#endif
21536
SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
21537
SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**);
@@ -22183,6 +22517,9 @@ static const char * const sqlite3azCompileOpt[] = {
22517
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
22518
"ENABLE_OFFSET_SQL_FUNC",
22519
#endif
22520
+#ifdef SQLITE_ENABLE_ORDERED_SET_AGGREGATES
22521
+ "ENABLE_ORDERED_SET_AGGREGATES",
22522
+#endif
22523
#ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK
22524
"ENABLE_OVERSIZE_CELL_CHECK",
22525
#endif
@@ -22652,9 +22989,6 @@ static const char * const sqlite3azCompileOpt[] = {
22989
#ifdef SQLITE_UNTESTABLE
22990
"UNTESTABLE",
22991
#endif
22655
-#ifdef SQLITE_USER_AUTHENTICATION
22656
- "USER_AUTHENTICATION",
22657
-#endif
22992
#ifdef SQLITE_USE_ALLOCA
22993
"USE_ALLOCA",
22994
#endif
@@ -22930,7 +23264,6 @@ SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
23264
SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
23265
0, /* bSmallMalloc */
23266
1, /* bExtraSchemaChecks */
22933
- sizeof(LONGDOUBLE_TYPE)>8, /* bUseLongDouble */
23267
#ifdef SQLITE_DEBUG
23268
0, /* bJsonSelfcheck */
23269
#endif
@@ -23354,6 +23687,7 @@ struct sqlite3_value {
23687
#ifdef SQLITE_DEBUG
23688
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
23689
u16 mScopyFlags; /* flags value immediately after the shallow copy */
23690
+ u8 bScopy; /* The pScopyFrom of some other Mem *might* point here */
23691
#endif
23692
};
23693
@@ -23503,7 +23837,7 @@ struct sqlite3_context {
23837
int isError; /* Error code returned by the function. */
23838
u8 enc; /* Encoding to use for results */
23839
u8 skipFlag; /* Skip accumulator loading if true */
23506
- u8 argc; /* Number of arguments */
23840
+ u16 argc; /* Number of arguments */
23841
sqlite3_value *argv[1]; /* Argument set */
23842
};
23843
@@ -23650,9 +23984,11 @@ struct PreUpdate {
23984
int iBlobWrite; /* Value returned by preupdate_blobwrite() */
23985
i64 iKey1; /* First key value passed to hook */
23986
i64 iKey2; /* Second key value passed to hook */
23987
+ Mem oldipk; /* Memory cell holding "old" IPK value */
23988
Mem *aNew; /* Array of new.* values */
23989
Table *pTab; /* Schema object being updated */
23990
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
23991
+ sqlite3_value **apDflt; /* Array of default values, if required */
23992
};
23993
23994
/*
@@ -24450,6 +24786,9 @@ static int parseHhMmSs(const char *zDate, DateTime *p){
24786
zDate++;
24787
}
24788
ms /= rScale;
24789
+ /* Truncate to avoid problems with sub-milliseconds
24790
+ ** rounding. https://sqlite.org/forum/forumpost/766a2c9231 */
24791
+ if( ms>0.999 ) ms = 0.999;
24792
}
24793
}else{
24794
s = 0;
@@ -24499,8 +24838,8 @@ static void computeJD(DateTime *p){
24838
Y--;
24839
M += 12;
24840
}
24502
- A = Y/100;
24503
- B = 2 - A + (A/4);
24841
+ A = (Y+4800)/100;
24842
+ B = 38 - A + (A/4);
24843
X1 = 36525*(Y+4716)/100;
24844
X2 = 306001*(M+1)/10000;
24845
p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000);
@@ -24684,7 +25023,7 @@ static int validJulianDay(sqlite3_int64 iJD){
25023
** Compute the Year, Month, and Day from the julian day number.
25024
*/
25025
static void computeYMD(DateTime *p){
24687
- int Z, A, B, C, D, E, X1;
25026
+ int Z, alpha, A, B, C, D, E, X1;
25027
if( p->validYMD ) return;
25028
if( !p->validJD ){
25029
p->Y = 2000;
@@ -24695,8 +25034,8 @@ static void computeYMD(DateTime *p){
25034
return;
25035
}else{
25036
Z = (int)((p->iJD + 43200000)/86400000);
24698
- A = (int)((Z - 1867216.25)/36524.25);
24699
- A = Z + 1 + A - (A/4);
25037
+ alpha = (int)((Z + 32044.75)/36524.25) - 52;
25038
+ A = Z + 1 + alpha - ((alpha+100)/4) + 25;
25039
B = A + 1524;
25040
C = (int)((B - 122.1)/365.25);
25041
D = (36525*(C&32767))/100;
@@ -24895,8 +25234,8 @@ static const struct {
25234
/* 1 */ { 6, "minute", 7.7379e+12, 60.0 },
25235
/* 2 */ { 4, "hour", 1.2897e+11, 3600.0 },
25236
/* 3 */ { 3, "day", 5373485.0, 86400.0 },
24898
- /* 4 */ { 5, "month", 176546.0, 30.0*86400.0 },
24899
- /* 5 */ { 4, "year", 14713.0, 365.0*86400.0 },
25237
+ /* 4 */ { 5, "month", 176546.0, 2592000.0 },
25238
+ /* 5 */ { 4, "year", 14713.0, 31536000.0 },
25239
};
25240
25241
/*
@@ -25657,7 +25996,7 @@ static void strftimeFunc(
25996
}
25997
case 'f': { /* Fractional seconds. (Non-standard) */
25998
double s = x.s;
25660
- if( s>59.999 ) s = 59.999;
25999
+ if( NEVER(s>59.999) ) s = 59.999;
26000
sqlite3_str_appendf(&sRes, "%06.3f", s);
26001
break;
26002
}
@@ -29098,16 +29437,29 @@ SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex *p){
29437
/*
29438
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
29439
** intended for use inside assert() statements.
29440
+**
29441
+** Because these routines raise false-positive alerts in TSAN, disable
29442
+** them (make them always return 1) when compiling with TSAN.
29443
*/
29444
SQLITE_API int sqlite3_mutex_held(sqlite3_mutex *p){
29445
+# if defined(__has_feature)
29446
+# if __has_feature(thread_sanitizer)
29447
+ p = 0;
29448
+# endif
29449
+# endif
29450
assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
29451
return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
29452
}
29453
SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){
29454
+# if defined(__has_feature)
29455
+# if __has_feature(thread_sanitizer)
29456
+ p = 0;
29457
+# endif
29458
+# endif
29459
assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
29460
return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
29461
}
29110
-#endif
29462
+#endif /* NDEBUG */
29463
29464
#endif /* !defined(SQLITE_MUTEX_OMIT) */
29465
@@ -31995,16 +32347,19 @@ SQLITE_API void sqlite3_str_vappendf(
32347
if( pItem->zAlias && !flag_altform2 ){
32348
sqlite3_str_appendall(pAccum, pItem->zAlias);
32349
}else if( pItem->zName ){
31998
- if( pItem->zDatabase ){
31999
- sqlite3_str_appendall(pAccum, pItem->zDatabase);
32350
+ if( pItem->fg.fixedSchema==0
32351
+ && pItem->fg.isSubquery==0
32352
+ && pItem->u4.zDatabase!=0
32353
+ ){
32354
+ sqlite3_str_appendall(pAccum, pItem->u4.zDatabase);
32355
sqlite3_str_append(pAccum, ".", 1);
32356
}
32357
sqlite3_str_appendall(pAccum, pItem->zName);
32358
}else if( pItem->zAlias ){
32359
sqlite3_str_appendall(pAccum, pItem->zAlias);
32005
- }else{
32006
- Select *pSel = pItem->pSelect;
32007
- assert( pSel!=0 ); /* Because of tag-20240424-1 */
32360
+ }else if( ALWAYS(pItem->fg.isSubquery) ){/* Because of tag-20240424-1 */
32361
+ Select *pSel = pItem->u4.pSubq->pSelect;
32362
+ assert( pSel!=0 );
32363
if( pSel->selFlags & SF_NestedFrom ){
32364
sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId);
32365
}else if( pSel->selFlags & SF_MultiValue ){
@@ -32082,6 +32437,7 @@ SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExp
32437
pExpr = pExpr->pLeft;
32438
}
32439
if( pExpr==0 ) return;
32440
+ if( ExprHasProperty(pExpr, EP_FromDDL) ) return;
32441
db->errByteOffset = pExpr->w.iOfst;
32442
}
32443
@@ -32786,9 +33142,9 @@ SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc)
33142
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
33143
x.printfFlags |= SQLITE_PRINTF_INTERNAL;
33144
sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
32789
- if( pItem->pTab ){
33145
+ if( pItem->pSTab ){
33146
sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx%s",
32791
- pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab,
33147
+ pItem->pSTab->zName, pItem->pSTab->nCol, pItem->pSTab,
33148
pItem->colUsed,
33149
pItem->fg.rowidUsed ? "+rowid" : "");
33150
}
@@ -32808,10 +33164,13 @@ SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc)
33164
sqlite3_str_appendf(&x, " DDL");
33165
}
33166
if( pItem->fg.isCte ){
32811
- sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
33167
+ static const char *aMat[] = {",MAT", "", ",NO-MAT"};
33168
+ sqlite3_str_appendf(&x, " CteUse=%d%s",
33169
+ pItem->u2.pCteUse->nUse,
33170
+ aMat[pItem->u2.pCteUse->eM10d]);
33171
}
33172
if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
32814
- sqlite3_str_appendf(&x, " ON");
33173
+ sqlite3_str_appendf(&x, " isOn");
33174
}
33175
if( pItem->fg.isTabFunc ) sqlite3_str_appendf(&x, " isTabFunc");
33176
if( pItem->fg.isCorrelated ) sqlite3_str_appendf(&x, " isCorrelated");
@@ -32819,25 +33178,27 @@ SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc)
33178
if( pItem->fg.viaCoroutine ) sqlite3_str_appendf(&x, " viaCoroutine");
33179
if( pItem->fg.notCte ) sqlite3_str_appendf(&x, " notCte");
33180
if( pItem->fg.isNestedFrom ) sqlite3_str_appendf(&x, " isNestedFrom");
33181
+ if( pItem->fg.fixedSchema ) sqlite3_str_appendf(&x, " fixedSchema");
33182
+ if( pItem->fg.hadSchema ) sqlite3_str_appendf(&x, " hadSchema");
33183
+ if( pItem->fg.isSubquery ) sqlite3_str_appendf(&x, " isSubquery");
33184
33185
sqlite3StrAccumFinish(&x);
33186
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
33187
n = 0;
32826
- if( pItem->pSelect ) n++;
33188
+ if( pItem->fg.isSubquery ) n++;
33189
if( pItem->fg.isTabFunc ) n++;
33190
if( pItem->fg.isUsing ) n++;
33191
if( pItem->fg.isUsing ){
33192
sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
33193
}
32832
- if( pItem->pSelect ){
32833
- sqlite3TreeViewPush(&pView, i+1<pSrc->nSrc);
32834
- if( pItem->pTab ){
32835
- Table *pTab = pItem->pTab;
33194
+ if( pItem->fg.isSubquery ){
33195
+ assert( n==1 );
33196
+ if( pItem->pSTab ){
33197
+ Table *pTab = pItem->pSTab;
33198
sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
33199
}
32838
- assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
32839
- sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
32840
- sqlite3TreeViewPop(&pView);
33200
+ assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem) );
33201
+ sqlite3TreeViewSelect(pView, pItem->u4.pSubq->pSelect, 0);
33202
}
33203
if( pItem->fg.isTabFunc ){
33204
sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
@@ -32879,7 +33240,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
33240
n = 1000;
33241
}else{
33242
n = 0;
32882
- if( p->pSrc && p->pSrc->nSrc ) n++;
33243
+ if( p->pSrc && p->pSrc->nSrc && p->pSrc->nAlloc ) n++;
33244
if( p->pWhere ) n++;
33245
if( p->pGroupBy ) n++;
33246
if( p->pHaving ) n++;
@@ -32905,7 +33266,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
33266
sqlite3TreeViewPop(&pView);
33267
}
33268
#endif
32908
- if( p->pSrc && p->pSrc->nSrc ){
33269
+ if( p->pSrc && p->pSrc->nSrc && p->pSrc->nAlloc ){
33270
sqlite3TreeViewPush(&pView, (n--)>0);
33271
sqlite3TreeViewLine(pView, "FROM");
33272
sqlite3TreeViewSrcList(pView, p->pSrc);
@@ -33413,7 +33774,8 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
33774
case OE_Ignore: zType = "ignore"; break;
33775
}
33776
assert( !ExprHasProperty(pExpr, EP_IntValue) );
33416
- sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
33777
+ sqlite3TreeViewLine(pView, "RAISE %s", zType);
33778
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
33779
break;
33780
}
33781
#endif
@@ -33493,9 +33855,10 @@ SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
33855
sqlite3TreeViewLine(pView, "%s", zLabel);
33856
for(i=0; i<pList->nExpr; i++){
33857
int j = pList->a[i].u.x.iOrderByCol;
33858
+ u8 sortFlags = pList->a[i].fg.sortFlags;
33859
char *zName = pList->a[i].zEName;
33860
int moreToFollow = i<pList->nExpr - 1;
33498
- if( j || zName ){
33861
+ if( j || zName || sortFlags ){
33862
sqlite3TreeViewPush(&pView, moreToFollow);
33863
moreToFollow = 0;
33864
sqlite3TreeViewLine(pView, 0);
@@ -33516,13 +33879,18 @@ SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
33879
}
33880
}
33881
if( j ){
33519
- fprintf(stdout, "iOrderByCol=%d", j);
33882
+ fprintf(stdout, "iOrderByCol=%d ", j);
33883
+ }
33884
+ if( sortFlags & KEYINFO_ORDER_DESC ){
33885
+ fprintf(stdout, "DESC ");
33886
+ }else if( sortFlags & KEYINFO_ORDER_BIGNULL ){
33887
+ fprintf(stdout, "NULLS-LAST");
33888
}
33889
fprintf(stdout, "\n");
33890
fflush(stdout);
33891
}
33892
sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
33525
- if( j || zName ){
33893
+ if( j || zName || sortFlags ){
33894
sqlite3TreeViewPop(&pView);
33895
}
33896
}
@@ -33559,21 +33927,7 @@ SQLITE_PRIVATE void sqlite3TreeViewBareIdList(
33927
if( zName==0 ) zName = "(null)";
33928
sqlite3TreeViewPush(&pView, moreToFollow);
33929
sqlite3TreeViewLine(pView, 0);
33562
- if( pList->eU4==EU4_NONE ){
33563
- fprintf(stdout, "%s\n", zName);
33564
- }else if( pList->eU4==EU4_IDX ){
33565
- fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx);
33566
- }else{
33567
- assert( pList->eU4==EU4_EXPR );
33568
- if( pList->a[i].u4.pExpr==0 ){
33569
- fprintf(stdout, "%s (pExpr=NULL)\n", zName);
33570
- }else{
33571
- fprintf(stdout, "%s\n", zName);
33572
- sqlite3TreeViewPush(&pView, i<pList->nId-1);
33573
- sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0);
33574
- sqlite3TreeViewPop(&pView);
33575
- }
33576
- }
33930
+ fprintf(stdout, "%s\n", zName);
33931
sqlite3TreeViewPop(&pView);
33932
}
33933
}
@@ -33883,6 +34237,10 @@ SQLITE_PRIVATE void sqlite3TreeViewTrigger(
34237
** accessible to the debugging, and to avoid warnings about unused
34238
** functions. But these routines only exist in debugging builds, so they
34239
** do not contaminate the interface.
34240
+**
34241
+** See Also:
34242
+**
34243
+** sqlite3ShowWhereTerm() in where.c
34244
*/
34245
SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
34246
SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
@@ -34485,7 +34843,7 @@ static const unsigned char sqlite3Utf8Trans1[] = {
34843
c = *(zIn++); \
34844
if( c>=0xc0 ){ \
34845
c = sqlite3Utf8Trans1[c-0xc0]; \
34488
- while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
34846
+ while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
34847
c = (c<<6) + (0x3f & *(zIn++)); \
34848
} \
34849
if( c<0x80 \
@@ -34863,20 +35221,22 @@ SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 e
35221
}
35222
35223
/*
34866
-** zIn is a UTF-16 encoded unicode string at least nChar characters long.
35224
+** zIn is a UTF-16 encoded unicode string at least nByte bytes long.
35225
** Return the number of bytes in the first nChar unicode characters
34868
-** in pZ. nChar must be non-negative.
35226
+** in pZ. nChar must be non-negative. Surrogate pairs count as a single
35227
+** character.
35228
*/
34870
-SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *zIn, int nChar){
35229
+SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *zIn, int nByte, int nChar){
35230
int c;
35231
unsigned char const *z = zIn;
35232
+ unsigned char const *zEnd = &z[nByte-1];
35233
int n = 0;
35234
35235
if( SQLITE_UTF16NATIVE==SQLITE_UTF16LE ) z++;
34876
- while( n<nChar ){
35236
+ while( n<nChar && ALWAYS(z<=zEnd) ){
35237
c = z[0];
35238
z += 2;
34879
- if( c>=0xd8 && c<0xdc && z[0]>=0xdc && z[0]<0xe0 ) z += 2;
35239
+ if( c>=0xd8 && c<0xdc && z<=zEnd && z[0]>=0xdc && z[0]<0xe0 ) z += 2;
35240
n++;
35241
}
35242
return (int)(z-(unsigned char const *)zIn)
@@ -35457,6 +35817,8 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 en
35817
int eValid = 1; /* True exponent is either not used or is well-formed */
35818
int nDigit = 0; /* Number of digits processed */
35819
int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
35820
+ u64 s2; /* round-tripped significand */
35821
+ double rr[2];
35822
35823
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
35824
*pResult = 0.0; /* Default return value, in case of an error */
@@ -35559,7 +35921,7 @@ do_atof_calc:
35921
e = (e*esign) + d;
35922
35923
/* Try to adjust the exponent to make it smaller */
35562
- while( e>0 && s<(LARGEST_UINT64/10) ){
35924
+ while( e>0 && s<((LARGEST_UINT64-0x7ff)/10) ){
35925
s *= 10;
35926
e--;
35927
}
@@ -35568,68 +35930,52 @@ do_atof_calc:
35930
e++;
35931
}
35932
35571
- if( e==0 ){
35572
- *pResult = s;
35573
- }else if( sqlite3Config.bUseLongDouble ){
35574
- LONGDOUBLE_TYPE r = (LONGDOUBLE_TYPE)s;
35575
- if( e>0 ){
35576
- while( e>=100 ){ e-=100; r *= 1.0e+100L; }
35577
- while( e>=10 ){ e-=10; r *= 1.0e+10L; }
35578
- while( e>=1 ){ e-=1; r *= 1.0e+01L; }
35579
- }else{
35580
- while( e<=-100 ){ e+=100; r *= 1.0e-100L; }
35581
- while( e<=-10 ){ e+=10; r *= 1.0e-10L; }
35582
- while( e<=-1 ){ e+=1; r *= 1.0e-01L; }
35583
- }
35584
- assert( r>=0.0 );
35585
- if( r>+1.7976931348623157081452742373e+308L ){
35586
-#ifdef INFINITY
35587
- *pResult = +INFINITY;
35588
-#else
35589
- *pResult = 1.0e308*10.0;
35933
+ rr[0] = (double)s;
35934
+ assert( sizeof(s2)==sizeof(rr[0]) );
35935
+#ifdef SQLITE_DEBUG
35936
+ rr[1] = 18446744073709549568.0;
35937
+ memcpy(&s2, &rr[1], sizeof(s2));
35938
+ assert( s2==0x43efffffffffffffLL );
35939
#endif
35591
- }else{
35592
- *pResult = (double)r;
35593
- }
35594
- }else{
35595
- double rr[2];
35596
- u64 s2;
35597
- rr[0] = (double)s;
35940
+ /* Largest double that can be safely converted to u64
35941
+ ** vvvvvvvvvvvvvvvvvvvvvv */
35942
+ if( rr[0]<=18446744073709549568.0 ){
35943
s2 = (u64)rr[0];
35599
-#if defined(_MSC_VER) && _MSC_VER<1700
35600
- if( s2==0x8000000000000000LL ){ s2 = 2*(u64)(0.5*rr[0]); }
35601
-#endif
35944
rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s);
35603
- if( e>0 ){
35604
- while( e>=100 ){
35605
- e -= 100;
35606
- dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
35607
- }
35608
- while( e>=10 ){
35609
- e -= 10;
35610
- dekkerMul2(rr, 1.0e+10, 0.0);
35611
- }
35612
- while( e>=1 ){
35613
- e -= 1;
35614
- dekkerMul2(rr, 1.0e+01, 0.0);
35615
- }
35616
- }else{
35617
- while( e<=-100 ){
35618
- e += 100;
35619
- dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
35620
- }
35621
- while( e<=-10 ){
35622
- e += 10;
35623
- dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
35624
- }
35625
- while( e<=-1 ){
35626
- e += 1;
35627
- dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
35628
- }
35945
+ }else{
35946
+ rr[1] = 0.0;
35947
+ }
35948
+ assert( rr[1]<=1.0e-10*rr[0] ); /* Equal only when rr[0]==0.0 */
35949
+
35950
+ if( e>0 ){
35951
+ while( e>=100 ){
35952
+ e -= 100;
35953
+ dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
35954
+ }
35955
+ while( e>=10 ){
35956
+ e -= 10;
35957
+ dekkerMul2(rr, 1.0e+10, 0.0);
35958
+ }
35959
+ while( e>=1 ){
35960
+ e -= 1;
35961
+ dekkerMul2(rr, 1.0e+01, 0.0);
35962
+ }
35963
+ }else{
35964
+ while( e<=-100 ){
35965
+ e += 100;
35966
+ dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
35967
+ }
35968
+ while( e<=-10 ){
35969
+ e += 10;
35970
+ dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
35971
+ }
35972
+ while( e<=-1 ){
35973
+ e += 1;
35974
+ dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
35975
}
35630
- *pResult = rr[0]+rr[1];
35631
- if( sqlite3IsNaN(*pResult) ) *pResult = 1e300*1e300;
35976
}
35977
+ *pResult = rr[0]+rr[1];
35978
+ if( sqlite3IsNaN(*pResult) ) *pResult = 1e300*1e300;
35979
if( sign<0 ) *pResult = -*pResult;
35980
assert( !sqlite3IsNaN(*pResult) );
35981
@@ -35933,10 +36279,13 @@ SQLITE_PRIVATE int sqlite3Atoi(const char *z){
36279
** Decode a floating-point value into an approximate decimal
36280
** representation.
36281
**
35936
-** Round the decimal representation to n significant digits if
35937
-** n is positive. Or round to -n signficant digits after the
35938
-** decimal point if n is negative. No rounding is performed if
35939
-** n is zero.
36282
+** If iRound<=0 then round to -iRound significant digits to the
36283
+** the left of the decimal point, or to a maximum of mxRound total
36284
+** significant digits.
36285
+**
36286
+** If iRound>0 round to min(iRound,mxRound) significant digits total.
36287
+**
36288
+** mxRound must be positive.
36289
**
36290
** The significant digits of the decimal representation are
36291
** stored in p->z[] which is a often (but not always) a pointer
@@ -35947,8 +36296,11 @@ SQLITE_PRIVATE void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRou
36296
int i;
36297
u64 v;
36298
int e, exp = 0;
36299
+ double rr[2];
36300
+
36301
p->isSpecial = 0;
36302
p->z = p->zBuf;
36303
+ assert( mxRound>0 );
36304
36305
/* Convert negative numbers to positive. Deal with Infinity, 0.0, and
36306
** NaN. */
@@ -35975,62 +36327,45 @@ SQLITE_PRIVATE void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRou
36327
36328
/* Multiply r by powers of ten until it lands somewhere in between
36329
** 1.0e+19 and 1.0e+17.
36330
+ **
36331
+ ** Use Dekker-style double-double computation to increase the
36332
+ ** precision.
36333
+ **
36334
+ ** The error terms on constants like 1.0e+100 computed using the
36335
+ ** decimal extension, for example as follows:
36336
+ **
36337
+ ** SELECT decimal_exp(decimal_sub('1.0e+100',decimal(1.0e+100)));
36338
*/
35979
- if( sqlite3Config.bUseLongDouble ){
35980
- LONGDOUBLE_TYPE rr = r;
35981
- if( rr>=1.0e+19 ){
35982
- while( rr>=1.0e+119L ){ exp+=100; rr *= 1.0e-100L; }
35983
- while( rr>=1.0e+29L ){ exp+=10; rr *= 1.0e-10L; }
35984
- while( rr>=1.0e+19L ){ exp++; rr *= 1.0e-1L; }
35985
- }else{
35986
- while( rr<1.0e-97L ){ exp-=100; rr *= 1.0e+100L; }
35987
- while( rr<1.0e+07L ){ exp-=10; rr *= 1.0e+10L; }
35988
- while( rr<1.0e+17L ){ exp--; rr *= 1.0e+1L; }
36339
+ rr[0] = r;
36340
+ rr[1] = 0.0;
36341
+ if( rr[0]>9.223372036854774784e+18 ){
36342
+ while( rr[0]>9.223372036854774784e+118 ){
36343
+ exp += 100;
36344
+ dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
36345
+ }
36346
+ while( rr[0]>9.223372036854774784e+28 ){
36347
+ exp += 10;
36348
+ dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
36349
+ }
36350
+ while( rr[0]>9.223372036854774784e+18 ){
36351
+ exp += 1;
36352
+ dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
36353
}
35990
- v = (u64)rr;
36354
}else{
35992
- /* If high-precision floating point is not available using "long double",
35993
- ** then use Dekker-style double-double computation to increase the
35994
- ** precision.
35995
- **
35996
- ** The error terms on constants like 1.0e+100 computed using the
35997
- ** decimal extension, for example as follows:
35998
- **
35999
- ** SELECT decimal_exp(decimal_sub('1.0e+100',decimal(1.0e+100)));
36000
- */
36001
- double rr[2];
36002
- rr[0] = r;
36003
- rr[1] = 0.0;
36004
- if( rr[0]>9.223372036854774784e+18 ){
36005
- while( rr[0]>9.223372036854774784e+118 ){
36006
- exp += 100;
36007
- dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117);
36008
- }
36009
- while( rr[0]>9.223372036854774784e+28 ){
36010
- exp += 10;
36011
- dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27);
36012
- }
36013
- while( rr[0]>9.223372036854774784e+18 ){
36014
- exp += 1;
36015
- dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18);
36016
- }
36017
- }else{
36018
- while( rr[0]<9.223372036854774784e-83 ){
36019
- exp -= 100;
36020
- dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
36021
- }
36022
- while( rr[0]<9.223372036854774784e+07 ){
36023
- exp -= 10;
36024
- dekkerMul2(rr, 1.0e+10, 0.0);
36025
- }
36026
- while( rr[0]<9.22337203685477478e+17 ){
36027
- exp -= 1;
36028
- dekkerMul2(rr, 1.0e+01, 0.0);
36029
- }
36355
+ while( rr[0]<9.223372036854774784e-83 ){
36356
+ exp -= 100;
36357
+ dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83);
36358
+ }
36359
+ while( rr[0]<9.223372036854774784e+07 ){
36360
+ exp -= 10;
36361
+ dekkerMul2(rr, 1.0e+10, 0.0);
36362
+ }
36363
+ while( rr[0]<9.22337203685477478e+17 ){
36364
+ exp -= 1;
36365
+ dekkerMul2(rr, 1.0e+01, 0.0);
36366
}
36031
- v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1];
36367
}
36033
-
36368
+ v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1];
36369
36370
/* Extract significant digits. */
36371
i = sizeof(p->zBuf)-1;
@@ -36801,104 +37136,6 @@ SQLITE_PRIVATE int sqlite3VListNameToNum(VList *pIn, const char *zName, int nNam
37136
return 0;
37137
}
37138
36804
-/*
36805
-** High-resolution hardware timer used for debugging and testing only.
36806
-*/
36807
-#if defined(VDBE_PROFILE) \
36808
- || defined(SQLITE_PERFORMANCE_TRACE) \
36809
- || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
36810
-/************** Include hwtime.h in the middle of util.c *********************/
36811
-/************** Begin file hwtime.h ******************************************/
36812
-/*
36813
-** 2008 May 27
36814
-**
36815
-** The author disclaims copyright to this source code. In place of
36816
-** a legal notice, here is a blessing:
36817
-**
36818
-** May you do good and not evil.
36819
-** May you find forgiveness for yourself and forgive others.
36820
-** May you share freely, never taking more than you give.
36821
-**
36822
-******************************************************************************
36823
-**
36824
-** This file contains inline asm code for retrieving "high-performance"
36825
-** counters for x86 and x86_64 class CPUs.
36826
-*/
36827
-#ifndef SQLITE_HWTIME_H
36828
-#define SQLITE_HWTIME_H
36829
-
36830
-/*
36831
-** The following routine only works on Pentium-class (or newer) processors.
36832
-** It uses the RDTSC opcode to read the cycle count value out of the
36833
-** processor and returns that value. This can be used for high-res
36834
-** profiling.
36835
-*/
36836
-#if !defined(__STRICT_ANSI__) && \
36837
- (defined(__GNUC__) || defined(_MSC_VER)) && \
36838
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
36839
-
36840
- #if defined(__GNUC__)
36841
-
36842
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
36843
- unsigned int lo, hi;
36844
- __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
36845
- return (sqlite_uint64)hi << 32 | lo;
36846
- }
36847
-
36848
- #elif defined(_MSC_VER)
36849
-
36850
- __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
36851
- __asm {
36852
- rdtsc
36853
- ret ; return value at EDX:EAX
36854
- }
36855
- }
36856
-
36857
- #endif
36858
-
36859
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
36860
-
36861
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
36862
- unsigned int lo, hi;
36863
- __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
36864
- return (sqlite_uint64)hi << 32 | lo;
36865
- }
36866
-
36867
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
36868
-
36869
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
36870
- unsigned long long retval;
36871
- unsigned long junk;
36872
- __asm__ __volatile__ ("\n\
36873
- 1: mftbu %1\n\
36874
- mftb %L0\n\
36875
- mftbu %0\n\
36876
- cmpw %0,%1\n\
36877
- bne 1b"
36878
- : "=r" (retval), "=r" (junk));
36879
- return retval;
36880
- }
36881
-
36882
-#else
36883
-
36884
- /*
36885
- ** asm() is needed for hardware timing support. Without asm(),
36886
- ** disable the sqlite3Hwtime() routine.
36887
- **
36888
- ** sqlite3Hwtime() is only used for some obscure debugging
36889
- ** and analysis configurations, not in any deliverable, so this
36890
- ** should not be a great loss.
36891
- */
36892
-SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
36893
-
36894
-#endif
36895
-
36896
-#endif /* !defined(SQLITE_HWTIME_H) */
36897
-
36898
-/************** End of hwtime.h **********************************************/
36899
-/************** Continuing where we left off in util.c ***********************/
36900
-#endif
36901
-
37139
/************** End of util.c ************************************************/
37140
/************** Begin file hash.c ********************************************/
37141
/*
@@ -37236,16 +37473,16 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
37473
/* 47 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
37474
/* 48 */ "Program" OpHelp(""),
37475
/* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
37239
- /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
37240
- /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
37241
- /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
37242
- /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
37243
- /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
37244
- /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
37245
- /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
37246
- /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
37247
- /* 58 */ "ElseEq" OpHelp(""),
37248
- /* 59 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
37476
+ /* 50 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
37477
+ /* 51 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
37478
+ /* 52 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
37479
+ /* 53 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
37480
+ /* 54 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
37481
+ /* 55 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
37482
+ /* 56 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
37483
+ /* 57 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
37484
+ /* 58 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
37485
+ /* 59 */ "ElseEq" OpHelp(""),
37486
/* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
37487
/* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
37488
/* 62 */ "IncrVacuum" OpHelp(""),
@@ -37288,23 +37525,23 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
37525
/* 99 */ "ReadCookie" OpHelp(""),
37526
/* 100 */ "SetCookie" OpHelp(""),
37527
/* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
37291
- /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
37292
- /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
37293
- /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
37294
- /* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
37295
- /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
37296
- /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
37297
- /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
37298
- /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
37299
- /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
37300
- /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
37301
- /* 112 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
37528
+ /* 102 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
37529
+ /* 103 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
37530
+ /* 104 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
37531
+ /* 105 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
37532
+ /* 106 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
37533
+ /* 107 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
37534
+ /* 108 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
37535
+ /* 109 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
37536
+ /* 110 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
37537
+ /* 111 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
37538
+ /* 112 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
37539
/* 113 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
37303
- /* 114 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
37304
- /* 115 */ "OpenDup" OpHelp(""),
37540
+ /* 114 */ "OpenDup" OpHelp(""),
37541
+ /* 115 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
37542
/* 116 */ "OpenAutoindex" OpHelp("nColumn=P2"),
37306
- /* 117 */ "String8" OpHelp("r[P2]='P4'"),
37307
- /* 118 */ "OpenEphemeral" OpHelp("nColumn=P2"),
37543
+ /* 117 */ "OpenEphemeral" OpHelp("nColumn=P2"),
37544
+ /* 118 */ "String8" OpHelp("r[P2]='P4'"),
37545
/* 119 */ "SorterOpen" OpHelp(""),
37546
/* 120 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
37547
/* 121 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
@@ -37339,8 +37576,8 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
37576
/* 150 */ "LoadAnalysis" OpHelp(""),
37577
/* 151 */ "DropTable" OpHelp(""),
37578
/* 152 */ "DropIndex" OpHelp(""),
37342
- /* 153 */ "Real" OpHelp("r[P2]=P4"),
37343
- /* 154 */ "DropTrigger" OpHelp(""),
37579
+ /* 153 */ "DropTrigger" OpHelp(""),
37580
+ /* 154 */ "Real" OpHelp("r[P2]=P4"),
37581
/* 155 */ "IntegrityCk" OpHelp(""),
37582
/* 156 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
37583
/* 157 */ "Param" OpHelp(""),
@@ -38580,7 +38817,7 @@ SQLITE_PRIVATE int sqlite3KvvfsInit(void){
38817
# endif
38818
#else /* !SQLITE_WASI */
38819
# ifndef HAVE_FCHMOD
38583
-# define HAVE_FCHMOD
38820
+# define HAVE_FCHMOD 1
38821
# endif
38822
#endif /* SQLITE_WASI */
38823
@@ -38689,7 +38926,7 @@ static pid_t randomnessPid = 0;
38926
#define UNIXFILE_EXCL 0x01 /* Connections from one process only */
38927
#define UNIXFILE_RDONLY 0x02 /* Connection is read only */
38928
#define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
38692
-#ifndef SQLITE_DISABLE_DIRSYNC
38929
+#if !defined(SQLITE_DISABLE_DIRSYNC) && !defined(_AIX)
38930
# define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
38931
#else
38932
# define UNIXFILE_DIRSYNC 0x00
@@ -40031,7 +40268,7 @@ static int unixFileLock(unixFile *pFile, struct flock *pLock){
40268
if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
40269
if( pInode->bProcessLock==0 ){
40270
struct flock lock;
40034
- assert( pInode->nLock==0 );
40271
+ /* assert( pInode->nLock==0 ); <-- Not true if unix-excl READONLY used */
40272
lock.l_whence = SEEK_SET;
40273
lock.l_start = SHARED_FIRST;
40274
lock.l_len = SHARED_SIZE;
@@ -40646,26 +40883,22 @@ static int nolockClose(sqlite3_file *id) {
40883
40884
/*
40885
** This routine checks if there is a RESERVED lock held on the specified
40649
-** file by this or any other process. If such a lock is held, set *pResOut
40650
-** to a non-zero value otherwise *pResOut is set to zero. The return value
40651
-** is set to SQLITE_OK unless an I/O error occurs during lock checking.
40652
-**
40653
-** In dotfile locking, either a lock exists or it does not. So in this
40654
-** variation of CheckReservedLock(), *pResOut is set to true if any lock
40655
-** is held on the file and false if the file is unlocked.
40886
+** file by this or any other process. If the caller holds a SHARED
40887
+** or greater lock when it is called, then it is assumed that no other
40888
+** client may hold RESERVED. Or, if the caller holds no lock, then it
40889
+** is assumed another client holds RESERVED if the lock-file exists.
40890
*/
40891
static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) {
40658
- int rc = SQLITE_OK;
40659
- int reserved = 0;
40892
unixFile *pFile = (unixFile*)id;
40661
-
40893
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
40894
40664
- assert( pFile );
40665
- reserved = osAccess((const char*)pFile->lockingContext, 0)==0;
40666
- OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
40667
- *pResOut = reserved;
40668
- return rc;
40895
+ if( pFile->eFileLock>=SHARED_LOCK ){
40896
+ *pResOut = 0;
40897
+ }else{
40898
+ *pResOut = osAccess((const char*)pFile->lockingContext, 0)==0;
40899
+ }
40900
+ OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, 0, *pResOut));
40901
+ return SQLITE_OK;
40902
}
40903
40904
/*
@@ -40835,54 +41068,33 @@ static int robust_flock(int fd, int op){
41068
** is set to SQLITE_OK unless an I/O error occurs during lock checking.
41069
*/
41070
static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){
40838
- int rc = SQLITE_OK;
40839
- int reserved = 0;
41071
+#ifdef SQLITE_DEBUG
41072
unixFile *pFile = (unixFile*)id;
41073
+#else
41074
+ UNUSED_PARAMETER(id);
41075
+#endif
41076
41077
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
41078
41079
assert( pFile );
41080
+ assert( pFile->eFileLock<=SHARED_LOCK );
41081
40846
- /* Check if a thread in this process holds such a lock */
40847
- if( pFile->eFileLock>SHARED_LOCK ){
40848
- reserved = 1;
40849
- }
40850
-
40851
- /* Otherwise see if some other process holds it. */
40852
- if( !reserved ){
40853
- /* attempt to get the lock */
40854
- int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
40855
- if( !lrc ){
40856
- /* got the lock, unlock it */
40857
- lrc = robust_flock(pFile->h, LOCK_UN);
40858
- if ( lrc ) {
40859
- int tErrno = errno;
40860
- /* unlock failed with an error */
40861
- lrc = SQLITE_IOERR_UNLOCK;
40862
- storeLastErrno(pFile, tErrno);
40863
- rc = lrc;
40864
- }
40865
- } else {
40866
- int tErrno = errno;
40867
- reserved = 1;
40868
- /* someone else might have it reserved */
40869
- lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
40870
- if( IS_LOCK_ERROR(lrc) ){
40871
- storeLastErrno(pFile, tErrno);
40872
- rc = lrc;
40873
- }
40874
- }
40875
- }
40876
- OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
41082
+ /* The flock VFS only ever takes exclusive locks (see function flockLock).
41083
+ ** Therefore, if this connection is holding any lock at all, no other
41084
+ ** connection may be holding a RESERVED lock. So set *pResOut to 0
41085
+ ** in this case.
41086
+ **
41087
+ ** Or, this connection may be holding no lock. In that case, set *pResOut to
41088
+ ** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the
41089
+ ** db in order to roll the hot journal back. If there is another connection
41090
+ ** holding a lock, that attempt will fail and an SQLITE_BUSY returned to
41091
+ ** the user. With other VFS, we try to avoid this, in order to allow a reader
41092
+ ** to proceed while a writer is preparing its transaction. But that won't
41093
+ ** work with the flock VFS - as it always takes EXCLUSIVE locks - so it is
41094
+ ** not a problem in this case. */
41095
+ *pResOut = 0;
41096
40878
-#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
40879
- if( (rc & 0xff) == SQLITE_IOERR ){
40880
- rc = SQLITE_OK;
40881
- reserved=1;
40882
- }
40883
-#endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
40884
- *pResOut = reserved;
40885
- return rc;
41097
+ return SQLITE_OK;
41098
}
41099
41100
/*
@@ -42354,7 +42566,7 @@ static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
42566
42567
/* Forward declaration */
42568
static int unixGetTempname(int nBuf, char *zBuf);
42357
-#ifndef SQLITE_OMIT_WAL
42569
+#if !defined(SQLITE_WASI) && !defined(SQLITE_OMIT_WAL)
42570
static int unixFcntlExternalReader(unixFile*, int*);
42571
#endif
42572
@@ -42379,6 +42591,11 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
42591
}
42592
#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
42593
42594
+ case SQLITE_FCNTL_NULL_IO: {
42595
+ osClose(pFile->h);
42596
+ pFile->h = -1;
42597
+ return SQLITE_OK;
42598
+ }
42599
case SQLITE_FCNTL_LOCKSTATE: {
42600
*(int*)pArg = pFile->eFileLock;
42601
return SQLITE_OK;
@@ -42481,7 +42698,7 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
42698
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
42699
42700
case SQLITE_FCNTL_EXTERNAL_READER: {
42484
-#ifndef SQLITE_OMIT_WAL
42701
+#if !defined(SQLITE_WASI) && !defined(SQLITE_OMIT_WAL)
42702
return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
42703
#else
42704
*(int*)pArg = 0;
@@ -42520,6 +42737,7 @@ static void setDeviceCharacteristics(unixFile *pFd){
42737
if( pFd->ctrlFlags & UNIXFILE_PSOW ){
42738
pFd->deviceCharacteristics |= SQLITE_IOCAP_POWERSAFE_OVERWRITE;
42739
}
42740
+ pFd->deviceCharacteristics |= SQLITE_IOCAP_SUBPAGE_READ;
42741
42742
pFd->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
42743
}
@@ -42570,7 +42788,7 @@ static void setDeviceCharacteristics(unixFile *pFile){
42788
pFile->sectorSize = fsInfo.f_bsize;
42789
pFile->deviceCharacteristics =
42790
/* full bitset of atomics from max sector size and smaller */
42573
- ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
42791
+ (((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2) |
42792
SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind
42793
** so it is ordered */
42794
0;
@@ -42578,7 +42796,7 @@ static void setDeviceCharacteristics(unixFile *pFile){
42796
pFile->sectorSize = fsInfo.f_bsize;
42797
pFile->deviceCharacteristics =
42798
/* full bitset of atomics from max sector size and smaller */
42581
- ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
42799
+ (((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2) |
42800
SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind
42801
** so it is ordered */
42802
0;
@@ -42654,7 +42872,7 @@ static int unixGetpagesize(void){
42872
42873
#endif /* !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 */
42874
42657
-#ifndef SQLITE_OMIT_WAL
42875
+#if !defined(SQLITE_WASI) && !defined(SQLITE_OMIT_WAL)
42876
42877
/*
42878
** Object used to represent an shared memory buffer.
@@ -50259,6 +50477,11 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
50477
return SQLITE_OK;
50478
}
50479
#endif
50480
+ case SQLITE_FCNTL_NULL_IO: {
50481
+ (void)osCloseHandle(pFile->h);
50482
+ pFile->h = NULL;
50483
+ return SQLITE_OK;
50484
+ }
50485
case SQLITE_FCNTL_TEMPFILENAME: {
50486
char *zTFile = 0;
50487
int rc = winGetTempname(pFile->pVfs, &zTFile);
@@ -50320,7 +50543,7 @@ static int winSectorSize(sqlite3_file *id){
50543
*/
50544
static int winDeviceCharacteristics(sqlite3_file *id){
50545
winFile *p = (winFile*)id;
50323
- return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
50546
+ return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | SQLITE_IOCAP_SUBPAGE_READ |
50547
((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0);
50548
}
50549
@@ -51708,7 +51931,7 @@ static int winOpen(
51931
51932
int rc = SQLITE_OK; /* Function Return Code */
51933
#if !defined(NDEBUG) || SQLITE_OS_WINCE
51711
- int eType = flags&0xFFFFFF00; /* Type of file to open */
51934
+ int eType = flags&0x0FFF00; /* Type of file to open */
51935
#endif
51936
51937
int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
@@ -54739,6 +54962,7 @@ static SQLITE_NOINLINE PgHdr *pcacheFetchFinishWithInit(
54962
pPgHdr->pData = pPage->pBuf;
54963
pPgHdr->pExtra = (void *)&pPgHdr[1];
54964
memset(pPgHdr->pExtra, 0, 8);
54965
+ assert( EIGHT_BYTE_ALIGNMENT( pPgHdr->pExtra ) );
54966
pPgHdr->pCache = pCache;
54967
pPgHdr->pgno = pgno;
54968
pPgHdr->flags = PGHDR_CLEAN;
@@ -55485,7 +55709,8 @@ static int pcache1InitBulk(PCache1 *pCache){
55709
do{
55710
PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
55711
pX->page.pBuf = zBulk;
55488
- pX->page.pExtra = &pX[1];
55712
+ pX->page.pExtra = (u8*)pX + ROUND8(sizeof(*pX));
55713
+ assert( EIGHT_BYTE_ALIGNMENT( pX->page.pExtra ) );
55714
pX->isBulkLocal = 1;
55715
pX->isAnchor = 0;
55716
pX->pNext = pCache->pFree;
@@ -55622,7 +55847,8 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
55847
if( pPg==0 ) return 0;
55848
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
55849
p->page.pBuf = pPg;
55625
- p->page.pExtra = &p[1];
55850
+ p->page.pExtra = (u8*)p + ROUND8(sizeof(*p));
55851
+ assert( EIGHT_BYTE_ALIGNMENT( p->page.pExtra ) );
55852
p->isBulkLocal = 0;
55853
p->isAnchor = 0;
55854
p->pLruPrev = 0; /* Initializing this saves a valgrind error */
@@ -57906,39 +58132,33 @@ static const unsigned char aJournalMagic[] = {
58132
# define USEFETCH(x) 0
58133
#endif
58134
57909
-/*
57910
-** The argument to this macro is a file descriptor (type sqlite3_file*).
57911
-** Return 0 if it is not open, or non-zero (but not 1) if it is.
57912
-**
57913
-** This is so that expressions can be written as:
57914
-**
57915
-** if( isOpen(pPager->jfd) ){ ...
57916
-**
57917
-** instead of
57918
-**
57919
-** if( pPager->jfd->pMethods ){ ...
57920
-*/
57921
-#define isOpen(pFd) ((pFd)->pMethods!=0)
57922
-
58135
#ifdef SQLITE_DIRECT_OVERFLOW_READ
58136
/*
58137
** Return true if page pgno can be read directly from the database file
58138
** by the b-tree layer. This is the case if:
58139
**
57928
-** * the database file is open,
57929
-** * there are no dirty pages in the cache, and
57930
-** * the desired page is not currently in the wal file.
58140
+** (1) the database file is open
58141
+** (2) the VFS for the database is able to do unaligned sub-page reads
58142
+** (3) there are no dirty pages in the cache, and
58143
+** (4) the desired page is not currently in the wal file.
58144
*/
58145
SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
57933
- if( pPager->fd->pMethods==0 ) return 0;
57934
- if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
58146
+ assert( pPager!=0 );
58147
+ assert( pPager->fd!=0 );
58148
+ if( pPager->fd->pMethods==0 ) return 0; /* Case (1) */
58149
+ if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; /* Failed (3) */
58150
#ifndef SQLITE_OMIT_WAL
58151
if( pPager->pWal ){
58152
u32 iRead = 0;
58153
(void)sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
57939
- return iRead==0;
58154
+ if( iRead ) return 0; /* Case (4) */
58155
}
58156
#endif
58157
+ assert( pPager->fd->pMethods->xDeviceCharacteristics!=0 );
58158
+ if( (pPager->fd->pMethods->xDeviceCharacteristics(pPager->fd)
58159
+ & SQLITE_IOCAP_SUBPAGE_READ)==0 ){
58160
+ return 0; /* Case (2) */
58161
+ }
58162
return 1;
58163
}
58164
#endif
@@ -59197,7 +59417,7 @@ static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){
59417
}
59418
pPager->journalOff = 0;
59419
}else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
59200
- || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
59420
+ || (pPager->exclusiveMode && pPager->journalMode<PAGER_JOURNALMODE_WAL)
59421
){
59422
rc = zeroJournalHdr(pPager, hasSuper||pPager->tempFile);
59423
pPager->journalOff = 0;
@@ -61181,6 +61401,7 @@ static int pagerAcquireMapPage(
61401
return SQLITE_NOMEM_BKPT;
61402
}
61403
p->pExtra = (void *)&p[1];
61404
+ assert( EIGHT_BYTE_ALIGNMENT( p->pExtra ) );
61405
p->flags = PGHDR_MMAP;
61406
p->nRef = 1;
61407
p->pPager = pPager;
@@ -64964,7 +65185,7 @@ SQLITE_PRIVATE int sqlite3PagerWalSystemErrno(Pager *pPager){
65185
** 28: Checksum-2 (second part of checksum for first 24 bytes of header).
65186
**
65187
** Immediately following the wal-header are zero or more frames. Each
64967
-** frame consists of a 24-byte frame-header followed by a <page-size> bytes
65188
+** frame consists of a 24-byte frame-header followed by <page-size> bytes
65189
** of page data. The frame-header is six big-endian 32-bit unsigned
65190
** integer values, as follows:
65191
**
@@ -65461,6 +65682,7 @@ struct Wal {
65682
#endif
65683
#ifdef SQLITE_ENABLE_SNAPSHOT
65684
WalIndexHdr *pSnapshot; /* Start transaction here if not NULL */
65685
+ int bGetSnapshot; /* Transaction opened for sqlite3_get_snapshot() */
65686
#endif
65687
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
65688
sqlite3 *db;
@@ -67353,7 +67575,7 @@ static int walHandleException(Wal *pWal){
67575
67576
/*
67577
** Assert that the Wal.lockMask mask, which indicates the locks held
67356
-** by the connenction, is consistent with the Wal.readLock, Wal.writeLock
67578
+** by the connection, is consistent with the Wal.readLock, Wal.writeLock
67579
** and Wal.ckptLock variables. To be used as:
67580
**
67581
** assert( walAssertLockmask(pWal) );
@@ -67905,11 +68127,7 @@ static int walBeginShmUnreliable(Wal *pWal, int *pChanged){
68127
*/
68128
static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
68129
volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
67908
- u32 mxReadMark; /* Largest aReadMark[] value */
67909
- int mxI; /* Index of largest aReadMark[] value */
67910
- int i; /* Loop counter */
68130
int rc = SQLITE_OK; /* Return code */
67912
- u32 mxFrame; /* Wal frame to lock to */
68131
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
68132
int nBlockTmout = 0;
68133
#endif
@@ -68015,141 +68233,147 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
68233
assert( pWal->apWiData[0]!=0 );
68234
pInfo = walCkptInfo(pWal);
68235
SEH_INJECT_FAULT;
68018
- if( !useWal && AtomicLoad(&pInfo->nBackfill)==pWal->hdr.mxFrame
68236
+ {
68237
+ u32 mxReadMark; /* Largest aReadMark[] value */
68238
+ int mxI; /* Index of largest aReadMark[] value */
68239
+ int i; /* Loop counter */
68240
+ u32 mxFrame; /* Wal frame to lock to */
68241
+ if( !useWal && AtomicLoad(&pInfo->nBackfill)==pWal->hdr.mxFrame
68242
#ifdef SQLITE_ENABLE_SNAPSHOT
68020
- && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)
68243
+ && ((pWal->bGetSnapshot==0 && pWal->pSnapshot==0) || pWal->hdr.mxFrame==0)
68244
#endif
68022
- ){
68023
- /* The WAL has been completely backfilled (or it is empty).
68024
- ** and can be safely ignored.
68025
- */
68026
- rc = walLockShared(pWal, WAL_READ_LOCK(0));
68027
- walShmBarrier(pWal);
68028
- if( rc==SQLITE_OK ){
68029
- if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){
68030
- /* It is not safe to allow the reader to continue here if frames
68031
- ** may have been appended to the log before READ_LOCK(0) was obtained.
68032
- ** When holding READ_LOCK(0), the reader ignores the entire log file,
68033
- ** which implies that the database file contains a trustworthy
68034
- ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
68035
- ** happening, this is usually correct.
68036
- **
68037
- ** However, if frames have been appended to the log (or if the log
68038
- ** is wrapped and written for that matter) before the READ_LOCK(0)
68039
- ** is obtained, that is not necessarily true. A checkpointer may
68040
- ** have started to backfill the appended frames but crashed before
68041
- ** it finished. Leaving a corrupt image in the database file.
68042
- */
68043
- walUnlockShared(pWal, WAL_READ_LOCK(0));
68044
- return WAL_RETRY;
68245
+ ){
68246
+ /* The WAL has been completely backfilled (or it is empty).
68247
+ ** and can be safely ignored.
68248
+ */
68249
+ rc = walLockShared(pWal, WAL_READ_LOCK(0));
68250
+ walShmBarrier(pWal);
68251
+ if( rc==SQLITE_OK ){
68252
+ if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr,sizeof(WalIndexHdr)) ){
68253
+ /* It is not safe to allow the reader to continue here if frames
68254
+ ** may have been appended to the log before READ_LOCK(0) was obtained.
68255
+ ** When holding READ_LOCK(0), the reader ignores the entire log file,
68256
+ ** which implies that the database file contains a trustworthy
68257
+ ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
68258
+ ** happening, this is usually correct.
68259
+ **
68260
+ ** However, if frames have been appended to the log (or if the log
68261
+ ** is wrapped and written for that matter) before the READ_LOCK(0)
68262
+ ** is obtained, that is not necessarily true. A checkpointer may
68263
+ ** have started to backfill the appended frames but crashed before
68264
+ ** it finished. Leaving a corrupt image in the database file.
68265
+ */
68266
+ walUnlockShared(pWal, WAL_READ_LOCK(0));
68267
+ return WAL_RETRY;
68268
+ }
68269
+ pWal->readLock = 0;
68270
+ return SQLITE_OK;
68271
+ }else if( rc!=SQLITE_BUSY ){
68272
+ return rc;
68273
}
68046
- pWal->readLock = 0;
68047
- return SQLITE_OK;
68048
- }else if( rc!=SQLITE_BUSY ){
68049
- return rc;
68274
}
68051
- }
68275
68053
- /* If we get this far, it means that the reader will want to use
68054
- ** the WAL to get at content from recent commits. The job now is
68055
- ** to select one of the aReadMark[] entries that is closest to
68056
- ** but not exceeding pWal->hdr.mxFrame and lock that entry.
68057
- */
68058
- mxReadMark = 0;
68059
- mxI = 0;
68060
- mxFrame = pWal->hdr.mxFrame;
68276
+ /* If we get this far, it means that the reader will want to use
68277
+ ** the WAL to get at content from recent commits. The job now is
68278
+ ** to select one of the aReadMark[] entries that is closest to
68279
+ ** but not exceeding pWal->hdr.mxFrame and lock that entry.
68280
+ */
68281
+ mxReadMark = 0;
68282
+ mxI = 0;
68283
+ mxFrame = pWal->hdr.mxFrame;
68284
#ifdef SQLITE_ENABLE_SNAPSHOT
68062
- if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){
68063
- mxFrame = pWal->pSnapshot->mxFrame;
68064
- }
68065
-#endif
68066
- for(i=1; i<WAL_NREADER; i++){
68067
- u32 thisMark = AtomicLoad(pInfo->aReadMark+i); SEH_INJECT_FAULT;
68068
- if( mxReadMark<=thisMark && thisMark<=mxFrame ){
68069
- assert( thisMark!=READMARK_NOT_USED );
68070
- mxReadMark = thisMark;
68071
- mxI = i;
68285
+ if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){
68286
+ mxFrame = pWal->pSnapshot->mxFrame;
68287
}
68073
- }
68074
- if( (pWal->readOnly & WAL_SHM_RDONLY)==0
68075
- && (mxReadMark<mxFrame || mxI==0)
68076
- ){
68288
+#endif
68289
for(i=1; i<WAL_NREADER; i++){
68078
- rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
68079
- if( rc==SQLITE_OK ){
68080
- AtomicStore(pInfo->aReadMark+i,mxFrame);
68081
- mxReadMark = mxFrame;
68290
+ u32 thisMark = AtomicLoad(pInfo->aReadMark+i); SEH_INJECT_FAULT;
68291
+ if( mxReadMark<=thisMark && thisMark<=mxFrame ){
68292
+ assert( thisMark!=READMARK_NOT_USED );
68293
+ mxReadMark = thisMark;
68294
mxI = i;
68083
- walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
68084
- break;
68085
- }else if( rc!=SQLITE_BUSY ){
68086
- return rc;
68295
}
68296
}
68089
- }
68090
- if( mxI==0 ){
68091
- assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
68092
- return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTINIT;
68093
- }
68297
+ if( (pWal->readOnly & WAL_SHM_RDONLY)==0
68298
+ && (mxReadMark<mxFrame || mxI==0)
68299
+ ){
68300
+ for(i=1; i<WAL_NREADER; i++){
68301
+ rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
68302
+ if( rc==SQLITE_OK ){
68303
+ AtomicStore(pInfo->aReadMark+i,mxFrame);
68304
+ mxReadMark = mxFrame;
68305
+ mxI = i;
68306
+ walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
68307
+ break;
68308
+ }else if( rc!=SQLITE_BUSY ){
68309
+ return rc;
68310
+ }
68311
+ }
68312
+ }
68313
+ if( mxI==0 ){
68314
+ assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
68315
+ return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTINIT;
68316
+ }
68317
68095
- (void)walEnableBlockingMs(pWal, nBlockTmout);
68096
- rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
68097
- walDisableBlocking(pWal);
68098
- if( rc ){
68318
+ (void)walEnableBlockingMs(pWal, nBlockTmout);
68319
+ rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
68320
+ walDisableBlocking(pWal);
68321
+ if( rc ){
68322
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
68100
- if( rc==SQLITE_BUSY_TIMEOUT ){
68101
- *pCnt |= WAL_RETRY_BLOCKED_MASK;
68102
- }
68323
+ if( rc==SQLITE_BUSY_TIMEOUT ){
68324
+ *pCnt |= WAL_RETRY_BLOCKED_MASK;
68325
+ }
68326
#else
68104
- assert( rc!=SQLITE_BUSY_TIMEOUT );
68327
+ assert( rc!=SQLITE_BUSY_TIMEOUT );
68328
#endif
68106
- assert( (rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT );
68107
- return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
68108
- }
68109
- /* Now that the read-lock has been obtained, check that neither the
68110
- ** value in the aReadMark[] array or the contents of the wal-index
68111
- ** header have changed.
68112
- **
68113
- ** It is necessary to check that the wal-index header did not change
68114
- ** between the time it was read and when the shared-lock was obtained
68115
- ** on WAL_READ_LOCK(mxI) was obtained to account for the possibility
68116
- ** that the log file may have been wrapped by a writer, or that frames
68117
- ** that occur later in the log than pWal->hdr.mxFrame may have been
68118
- ** copied into the database by a checkpointer. If either of these things
68119
- ** happened, then reading the database with the current value of
68120
- ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
68121
- ** instead.
68122
- **
68123
- ** Before checking that the live wal-index header has not changed
68124
- ** since it was read, set Wal.minFrame to the first frame in the wal
68125
- ** file that has not yet been checkpointed. This client will not need
68126
- ** to read any frames earlier than minFrame from the wal file - they
68127
- ** can be safely read directly from the database file.
68128
- **
68129
- ** Because a ShmBarrier() call is made between taking the copy of
68130
- ** nBackfill and checking that the wal-header in shared-memory still
68131
- ** matches the one cached in pWal->hdr, it is guaranteed that the
68132
- ** checkpointer that set nBackfill was not working with a wal-index
68133
- ** header newer than that cached in pWal->hdr. If it were, that could
68134
- ** cause a problem. The checkpointer could omit to checkpoint
68135
- ** a version of page X that lies before pWal->minFrame (call that version
68136
- ** A) on the basis that there is a newer version (version B) of the same
68137
- ** page later in the wal file. But if version B happens to like past
68138
- ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
68139
- ** that it can read version A from the database file. However, since
68140
- ** we can guarantee that the checkpointer that set nBackfill could not
68141
- ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
68142
- */
68143
- pWal->minFrame = AtomicLoad(&pInfo->nBackfill)+1; SEH_INJECT_FAULT;
68144
- walShmBarrier(pWal);
68145
- if( AtomicLoad(pInfo->aReadMark+mxI)!=mxReadMark
68146
- || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
68147
- ){
68148
- walUnlockShared(pWal, WAL_READ_LOCK(mxI));
68149
- return WAL_RETRY;
68150
- }else{
68151
- assert( mxReadMark<=pWal->hdr.mxFrame );
68152
- pWal->readLock = (i16)mxI;
68329
+ assert((rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT);
68330
+ return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
68331
+ }
68332
+ /* Now that the read-lock has been obtained, check that neither the
68333
+ ** value in the aReadMark[] array or the contents of the wal-index
68334
+ ** header have changed.
68335
+ **
68336
+ ** It is necessary to check that the wal-index header did not change
68337
+ ** between the time it was read and when the shared-lock was obtained
68338
+ ** on WAL_READ_LOCK(mxI) was obtained to account for the possibility
68339
+ ** that the log file may have been wrapped by a writer, or that frames
68340
+ ** that occur later in the log than pWal->hdr.mxFrame may have been
68341
+ ** copied into the database by a checkpointer. If either of these things
68342
+ ** happened, then reading the database with the current value of
68343
+ ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
68344
+ ** instead.
68345
+ **
68346
+ ** Before checking that the live wal-index header has not changed
68347
+ ** since it was read, set Wal.minFrame to the first frame in the wal
68348
+ ** file that has not yet been checkpointed. This client will not need
68349
+ ** to read any frames earlier than minFrame from the wal file - they
68350
+ ** can be safely read directly from the database file.
68351
+ **
68352
+ ** Because a ShmBarrier() call is made between taking the copy of
68353
+ ** nBackfill and checking that the wal-header in shared-memory still
68354
+ ** matches the one cached in pWal->hdr, it is guaranteed that the
68355
+ ** checkpointer that set nBackfill was not working with a wal-index
68356
+ ** header newer than that cached in pWal->hdr. If it were, that could
68357
+ ** cause a problem. The checkpointer could omit to checkpoint
68358
+ ** a version of page X that lies before pWal->minFrame (call that version
68359
+ ** A) on the basis that there is a newer version (version B) of the same
68360
+ ** page later in the wal file. But if version B happens to like past
68361
+ ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
68362
+ ** that it can read version A from the database file. However, since
68363
+ ** we can guarantee that the checkpointer that set nBackfill could not
68364
+ ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
68365
+ */
68366
+ pWal->minFrame = AtomicLoad(&pInfo->nBackfill)+1; SEH_INJECT_FAULT;
68367
+ walShmBarrier(pWal);
68368
+ if( AtomicLoad(pInfo->aReadMark+mxI)!=mxReadMark
68369
+ || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
68370
+ ){
68371
+ walUnlockShared(pWal, WAL_READ_LOCK(mxI));
68372
+ return WAL_RETRY;
68373
+ }else{
68374
+ assert( mxReadMark<=pWal->hdr.mxFrame );
68375
+ pWal->readLock = (i16)mxI;
68376
+ }
68377
}
68378
return rc;
68379
}
@@ -69417,7 +69641,20 @@ SQLITE_PRIVATE void sqlite3WalSnapshotOpen(
69641
Wal *pWal,
69642
sqlite3_snapshot *pSnapshot
69643
){
69420
- pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
69644
+ if( pSnapshot && ((WalIndexHdr*)pSnapshot)->iVersion==0 ){
69645
+ /* iVersion==0 means that this is a call to sqlite3_snapshot_get(). In
69646
+ ** this case set the bGetSnapshot flag so that if the call to
69647
+ ** sqlite3_snapshot_get() is about to read transaction on this wal
69648
+ ** file, it does not take read-lock 0 if the wal file has been completely
69649
+ ** checkpointed. Taking read-lock 0 would work, but then it would be
69650
+ ** possible for a subsequent writer to destroy the snapshot even while
69651
+ ** this connection is holding its read-transaction open. This is contrary
69652
+ ** to user expectations, so we avoid it by not taking read-lock 0. */
69653
+ pWal->bGetSnapshot = 1;
69654
+ }else{
69655
+ pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
69656
+ pWal->bGetSnapshot = 0;
69657
+ }
69658
}
69659
69660
/*
@@ -75298,6 +75535,25 @@ SQLITE_PRIVATE int sqlite3BtreeCursorSize(void){
75535
return ROUND8(sizeof(BtCursor));
75536
}
75537
75538
+#ifdef SQLITE_DEBUG
75539
+/*
75540
+** Return true if and only if the Btree object will be automatically
75541
+** closed with the BtCursor closes. This is used within assert() statements
75542
+** only.
75543
+*/
75544
+SQLITE_PRIVATE int sqlite3BtreeClosesWithCursor(
75545
+ Btree *pBtree, /* the btree object */
75546
+ BtCursor *pCur /* Corresponding cursor */
75547
+){
75548
+ BtShared *pBt = pBtree->pBt;
75549
+ if( (pBt->openFlags & BTREE_SINGLE)==0 ) return 0;
75550
+ if( pBt->pCursor!=pCur ) return 0;
75551
+ if( pCur->pNext!=0 ) return 0;
75552
+ if( pCur->pBtree!=pBtree ) return 0;
75553
+ return 1;
75554
+}
75555
+#endif
75556
+
75557
/*
75558
** Initialize memory that will be converted into a BtCursor object.
75559
**
@@ -76541,7 +76797,7 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
76797
&& indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
76798
&& pIdxKey->errCode==SQLITE_OK
76799
){
76544
- pCur->curFlags &= ~BTCF_ValidOvfl;
76800
+ pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast);
76801
if( !pCur->pPage->isInit ){
76802
return SQLITE_CORRUPT_BKPT;
76803
}
@@ -78119,7 +78375,8 @@ static int rebuildPage(
78375
if( j>(u32)usableSize ){ j = 0; }
78376
memcpy(&pTmp[j], &aData[j], usableSize - j);
78377
78122
- for(k=0; ALWAYS(k<NB*2) && pCArray->ixNx[k]<=i; k++){}
78378
+ assert( pCArray->ixNx[NB*2-1]>i );
78379
+ for(k=0; pCArray->ixNx[k]<=i; k++){}
78380
pSrcEnd = pCArray->apEnd[k];
78381
78382
pData = pEnd;
@@ -78202,7 +78459,8 @@ static int pageInsertArray(
78459
u8 *pEnd; /* Maximum extent of cell data */
78460
assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
78461
if( iEnd<=iFirst ) return 0;
78205
- for(k=0; ALWAYS(k<NB*2) && pCArray->ixNx[k]<=i ; k++){}
78462
+ assert( pCArray->ixNx[NB*2-1]>i );
78463
+ for(k=0; pCArray->ixNx[k]<=i ; k++){}
78464
pEnd = pCArray->apEnd[k];
78465
while( 1 /*Exit by break*/ ){
78466
int sz, rc;
@@ -78487,6 +78745,7 @@ static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){
78745
b.szCell = &szCell;
78746
b.apEnd[0] = pPage->aDataEnd;
78747
b.ixNx[0] = 2;
78748
+ b.ixNx[NB*2-1] = 0x7fffffff;
78749
rc = rebuildPage(&b, 0, 1, pNew);
78750
if( NEVER(rc) ){
78751
releasePage(pNew);
@@ -78722,7 +78981,9 @@ static int balance_nonroot(
78981
CellArray b; /* Parsed information on cells being balanced */
78982
78983
memset(abDone, 0, sizeof(abDone));
78725
- memset(&b, 0, sizeof(b));
78984
+ assert( sizeof(b) - sizeof(b.ixNx) == offsetof(CellArray,ixNx) );
78985
+ memset(&b, 0, sizeof(b)-sizeof(b.ixNx[0]));
78986
+ b.ixNx[NB*2-1] = 0x7fffffff;
78987
pBt = pParent->pBt;
78988
assert( sqlite3_mutex_held(pBt->mutex) );
78989
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
@@ -79313,7 +79574,8 @@ static int balance_nonroot(
79574
iOvflSpace += sz;
79575
assert( sz<=pBt->maxLocal+23 );
79576
assert( iOvflSpace <= (int)pBt->pageSize );
79316
- for(k=0; ALWAYS(k<NB*2) && b.ixNx[k]<=j; k++){}
79577
+ assert( b.ixNx[NB*2-1]>j );
79578
+ for(k=0; b.ixNx[k]<=j; k++){}
79579
pSrcEnd = b.apEnd[k];
79580
if( SQLITE_OVERFLOW(pSrcEnd, pCell, pCell+sz) ){
79581
rc = SQLITE_CORRUPT_BKPT;
@@ -83837,27 +84099,30 @@ SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem *p){
84099
SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
84100
int i;
84101
Mem *pX;
83840
- for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
83841
- if( pX->pScopyFrom==pMem ){
83842
- u16 mFlags;
83843
- if( pVdbe->db->flags & SQLITE_VdbeTrace ){
83844
- sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
83845
- (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
83846
- }
83847
- /* If pX is marked as a shallow copy of pMem, then try to verify that
83848
- ** no significant changes have been made to pX since the OP_SCopy.
83849
- ** A significant change would indicated a missed call to this
83850
- ** function for pX. Minor changes, such as adding or removing a
83851
- ** dual type, are allowed, as long as the underlying value is the
83852
- ** same. */
83853
- mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
83854
- assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
83855
-
83856
- /* pMem is the register that is changing. But also mark pX as
83857
- ** undefined so that we can quickly detect the shallow-copy error */
83858
- pX->flags = MEM_Undefined;
83859
- pX->pScopyFrom = 0;
83860
- }
84102
+ if( pMem->bScopy ){
84103
+ for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
84104
+ if( pX->pScopyFrom==pMem ){
84105
+ u16 mFlags;
84106
+ if( pVdbe->db->flags & SQLITE_VdbeTrace ){
84107
+ sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
84108
+ (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
84109
+ }
84110
+ /* If pX is marked as a shallow copy of pMem, then try to verify that
84111
+ ** no significant changes have been made to pX since the OP_SCopy.
84112
+ ** A significant change would indicated a missed call to this
84113
+ ** function for pX. Minor changes, such as adding or removing a
84114
+ ** dual type, are allowed, as long as the underlying value is the
84115
+ ** same. */
84116
+ mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
84117
+ assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
84118
+
84119
+ /* pMem is the register that is changing. But also mark pX as
84120
+ ** undefined so that we can quickly detect the shallow-copy error */
84121
+ pX->flags = MEM_Undefined;
84122
+ pX->pScopyFrom = 0;
84123
+ }
84124
+ }
84125
+ pMem->bScopy = 0;
84126
}
84127
pMem->pScopyFrom = 0;
84128
}
@@ -84325,7 +84590,8 @@ static int valueFromFunction(
84590
goto value_from_function_out;
84591
}
84592
for(i=0; i<nVal; i++){
84328
- rc = sqlite3ValueFromExpr(db, pList->a[i].pExpr, enc, aff, &apVal[i]);
84593
+ rc = sqlite3Stat4ValueFromExpr(pCtx->pParse, pList->a[i].pExpr, aff,
84594
+ &apVal[i]);
84595
if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out;
84596
}
84597
}
@@ -86259,6 +86525,12 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){
86525
if( db->pnBytesFreed==0 ) sqlite3DeleteTable(db, (Table*)p4);
86526
break;
86527
}
86528
+ case P4_SUBRTNSIG: {
86529
+ SubrtnSig *pSig = (SubrtnSig*)p4;
86530
+ sqlite3DbFree(db, pSig->zAff);
86531
+ sqlite3DbFree(db, pSig);
86532
+ break;
86533
+ }
86534
}
86535
}
86536
@@ -86838,6 +87110,11 @@ SQLITE_PRIVATE char *sqlite3VdbeDisplayP4(sqlite3 *db, Op *pOp){
87110
zP4 = pOp->p4.pTab->zName;
87111
break;
87112
}
87113
+ case P4_SUBRTNSIG: {
87114
+ SubrtnSig *pSig = pOp->p4.pSubrtnSig;
87115
+ sqlite3_str_appendf(&x, "subrtnsig:%d,%s", pSig->selId, pSig->zAff);
87116
+ break;
87117
+ }
87118
default: {
87119
zP4 = pOp->p4.z;
87120
}
@@ -86979,6 +87256,7 @@ SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, VdbeOp *pOp){
87256
** will be initialized before use.
87257
*/
87258
static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){
87259
+ assert( db!=0 );
87260
if( N>0 ){
87261
do{
87262
p->flags = flags;
@@ -86986,6 +87264,7 @@ static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){
87264
p->szMalloc = 0;
87265
#ifdef SQLITE_DEBUG
87266
p->pScopyFrom = 0;
87267
+ p->bScopy = 0;
87268
#endif
87269
p++;
87270
}while( (--N)>0 );
@@ -87004,6 +87283,7 @@ static void releaseMemArray(Mem *p, int N){
87283
if( p && N ){
87284
Mem *pEnd = &p[N];
87285
sqlite3 *db = p->db;
87286
+ assert( db!=0 );
87287
if( db->pnBytesFreed ){
87288
do{
87289
if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
@@ -87484,6 +87764,7 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
87764
assert( pParse!=0 );
87765
assert( p->eVdbeState==VDBE_INIT_STATE );
87766
assert( pParse==p->pParse );
87767
+ assert( pParse->db==p->db );
87768
p->pVList = pParse->pVList;
87769
pParse->pVList = 0;
87770
db = p->db;
@@ -89347,7 +89628,7 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem
89628
** We must use separate SQLITE_NOINLINE functions here, since otherwise
89629
** optimizer code movement causes gcov to become very confused.
89630
*/
89350
-#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
89631
+#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
89632
static int SQLITE_NOINLINE doubleLt(double a, double b){ return a<b; }
89633
static int SQLITE_NOINLINE doubleEq(double a, double b){ return a==b; }
89634
#endif
@@ -89362,13 +89643,6 @@ SQLITE_PRIVATE int sqlite3IntFloatCompare(i64 i, double r){
89643
/* SQLite considers NaN to be a NULL. And all integer values are greater
89644
** than NULL */
89645
return 1;
89365
- }
89366
- if( sqlite3Config.bUseLongDouble ){
89367
- LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
89368
- testcase( x<r );
89369
- testcase( x>r );
89370
- testcase( x==r );
89371
- return (x<r) ? -1 : (x>r);
89646
}else{
89647
i64 y;
89648
if( r<-9223372036854775808.0 ) return +1;
@@ -90371,6 +90645,7 @@ SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(
90645
sqlite3DbFree(db, preupdate.aRecord);
90646
vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pUnpacked);
90647
vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pNewUnpacked);
90648
+ sqlite3VdbeMemRelease(&preupdate.oldipk);
90649
if( preupdate.aNew ){
90650
int i;
90651
for(i=0; i<pCsr->nField; i++){
@@ -90378,6 +90653,13 @@ SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(
90653
}
90654
sqlite3DbNNFreeNN(db, preupdate.aNew);
90655
}
90656
+ if( preupdate.apDflt ){
90657
+ int i;
90658
+ for(i=0; i<pTab->nCol; i++){
90659
+ sqlite3ValueFree(preupdate.apDflt[i]);
90660
+ }
90661
+ sqlite3DbFree(db, preupdate.apDflt);
90662
+ }
90663
}
90664
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
90665
@@ -90448,7 +90730,6 @@ static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){
90730
sqlite3_int64 iNow;
90731
sqlite3_int64 iElapse;
90732
assert( p->startTime>0 );
90451
- assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
90733
assert( db->init.busy==0 );
90734
assert( p->zSql!=0 );
90735
sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
@@ -91168,7 +91449,7 @@ static int sqlite3Step(Vdbe *p){
91449
}
91450
91451
assert( db->nVdbeWrite>0 || db->autoCommit==0
91171
- || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
91452
+ || ((db->nDeferredCons + db->nDeferredImmCons)==0)
91453
);
91454
91455
#ifndef SQLITE_OMIT_TRACE
@@ -91679,6 +91960,7 @@ static const Mem *columnNullValue(void){
91960
#ifdef SQLITE_DEBUG
91961
/* .pScopyFrom = */ (Mem*)0,
91962
/* .mScopyFlags= */ 0,
91963
+ /* .bScopy = */ 0,
91964
#endif
91965
};
91966
return &nullMem;
@@ -91720,7 +92002,7 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){
92002
** sqlite3_column_int64()
92003
** sqlite3_column_text()
92004
** sqlite3_column_text16()
91723
-** sqlite3_column_real()
92005
+** sqlite3_column_double()
92006
** sqlite3_column_bytes()
92007
** sqlite3_column_bytes16()
92008
** sqlite3_column_blob()
@@ -92006,6 +92288,17 @@ SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
92288
**
92289
** The error code stored in database p->db is overwritten with the return
92290
** value in any case.
92291
+**
92292
+** (tag-20240917-01) If vdbeUnbind(p,(u32)(i-1)) returns SQLITE_OK,
92293
+** that means all of the the following will be true:
92294
+**
92295
+** p!=0
92296
+** p->pVar!=0
92297
+** i>0
92298
+** i<=p->nVar
92299
+**
92300
+** An assert() is normally added after vdbeUnbind() to help static analyzers
92301
+** realize this.
92302
*/
92303
static int vdbeUnbind(Vdbe *p, unsigned int i){
92304
Mem *pVar;
@@ -92063,6 +92356,7 @@ static int bindText(
92356
92357
rc = vdbeUnbind(p, (u32)(i-1));
92358
if( rc==SQLITE_OK ){
92359
+ assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
92360
if( zData!=0 ){
92361
pVar = &p->aVar[i-1];
92362
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
@@ -92112,6 +92406,7 @@ SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
92406
Vdbe *p = (Vdbe *)pStmt;
92407
rc = vdbeUnbind(p, (u32)(i-1));
92408
if( rc==SQLITE_OK ){
92409
+ assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
92410
sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
92411
sqlite3_mutex_leave(p->db->mutex);
92412
}
@@ -92125,6 +92420,7 @@ SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValu
92420
Vdbe *p = (Vdbe *)pStmt;
92421
rc = vdbeUnbind(p, (u32)(i-1));
92422
if( rc==SQLITE_OK ){
92423
+ assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
92424
sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
92425
sqlite3_mutex_leave(p->db->mutex);
92426
}
@@ -92135,6 +92431,7 @@ SQLITE_API int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
92431
Vdbe *p = (Vdbe*)pStmt;
92432
rc = vdbeUnbind(p, (u32)(i-1));
92433
if( rc==SQLITE_OK ){
92434
+ assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
92435
sqlite3_mutex_leave(p->db->mutex);
92436
}
92437
return rc;
@@ -92150,6 +92447,7 @@ SQLITE_API int sqlite3_bind_pointer(
92447
Vdbe *p = (Vdbe*)pStmt;
92448
rc = vdbeUnbind(p, (u32)(i-1));
92449
if( rc==SQLITE_OK ){
92450
+ assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
92451
sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr, zPTtype, xDestructor);
92452
sqlite3_mutex_leave(p->db->mutex);
92453
}else if( xDestructor ){
@@ -92231,6 +92529,7 @@ SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
92529
Vdbe *p = (Vdbe *)pStmt;
92530
rc = vdbeUnbind(p, (u32)(i-1));
92531
if( rc==SQLITE_OK ){
92532
+ assert( p!=0 && p->aVar!=0 && i>0 && i<=p->nVar ); /* tag-20240917-01 */
92533
#ifndef SQLITE_OMIT_INCRBLOB
92534
sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
92535
#else
@@ -92544,6 +92843,7 @@ SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppVa
92843
PreUpdate *p;
92844
Mem *pMem;
92845
int rc = SQLITE_OK;
92846
+ int iStore = 0;
92847
92848
#ifdef SQLITE_ENABLE_API_ARMOR
92849
if( db==0 || ppValue==0 ){
@@ -92558,44 +92858,73 @@ SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppVa
92858
goto preupdate_old_out;
92859
}
92860
if( p->pPk ){
92561
- iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx);
92861
+ iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
92862
+ }else{
92863
+ iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
92864
}
92563
- if( iIdx>=p->pCsr->nField || iIdx<0 ){
92865
+ if( iStore>=p->pCsr->nField || iStore<0 ){
92866
rc = SQLITE_RANGE;
92867
goto preupdate_old_out;
92868
}
92869
92568
- /* If the old.* record has not yet been loaded into memory, do so now. */
92569
- if( p->pUnpacked==0 ){
92570
- u32 nRec;
92571
- u8 *aRec;
92870
+ if( iIdx==p->pTab->iPKey ){
92871
+ *ppValue = pMem = &p->oldipk;
92872
+ sqlite3VdbeMemSetInt64(pMem, p->iKey1);
92873
+ }else{
92874
+
92875
+ /* If the old.* record has not yet been loaded into memory, do so now. */
92876
+ if( p->pUnpacked==0 ){
92877
+ u32 nRec;
92878
+ u8 *aRec;
92879
92573
- assert( p->pCsr->eCurType==CURTYPE_BTREE );
92574
- nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor);
92575
- aRec = sqlite3DbMallocRaw(db, nRec);
92576
- if( !aRec ) goto preupdate_old_out;
92577
- rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec);
92578
- if( rc==SQLITE_OK ){
92579
- p->pUnpacked = vdbeUnpackRecord(&p->keyinfo, nRec, aRec);
92580
- if( !p->pUnpacked ) rc = SQLITE_NOMEM;
92581
- }
92582
- if( rc!=SQLITE_OK ){
92583
- sqlite3DbFree(db, aRec);
92584
- goto preupdate_old_out;
92880
+ assert( p->pCsr->eCurType==CURTYPE_BTREE );
92881
+ nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor);
92882
+ aRec = sqlite3DbMallocRaw(db, nRec);
92883
+ if( !aRec ) goto preupdate_old_out;
92884
+ rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec);
92885
+ if( rc==SQLITE_OK ){
92886
+ p->pUnpacked = vdbeUnpackRecord(&p->keyinfo, nRec, aRec);
92887
+ if( !p->pUnpacked ) rc = SQLITE_NOMEM;
92888
+ }
92889
+ if( rc!=SQLITE_OK ){
92890
+ sqlite3DbFree(db, aRec);
92891
+ goto preupdate_old_out;
92892
+ }
92893
+ p->aRecord = aRec;
92894
}
92586
- p->aRecord = aRec;
92587
- }
92895
92589
- pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
92590
- if( iIdx==p->pTab->iPKey ){
92591
- sqlite3VdbeMemSetInt64(pMem, p->iKey1);
92592
- }else if( iIdx>=p->pUnpacked->nField ){
92593
- *ppValue = (sqlite3_value *)columnNullValue();
92594
- }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){
92595
- if( pMem->flags & (MEM_Int|MEM_IntReal) ){
92596
- testcase( pMem->flags & MEM_Int );
92597
- testcase( pMem->flags & MEM_IntReal );
92598
- sqlite3VdbeMemRealify(pMem);
92896
+ pMem = *ppValue = &p->pUnpacked->aMem[iStore];
92897
+ if( iStore>=p->pUnpacked->nField ){
92898
+ /* This occurs when the table has been extended using ALTER TABLE
92899
+ ** ADD COLUMN. The value to return is the default value of the column. */
92900
+ Column *pCol = &p->pTab->aCol[iIdx];
92901
+ if( pCol->iDflt>0 ){
92902
+ if( p->apDflt==0 ){
92903
+ int nByte = sizeof(sqlite3_value*)*p->pTab->nCol;
92904
+ p->apDflt = (sqlite3_value**)sqlite3DbMallocZero(db, nByte);
92905
+ if( p->apDflt==0 ) goto preupdate_old_out;
92906
+ }
92907
+ if( p->apDflt[iIdx]==0 ){
92908
+ sqlite3_value *pVal = 0;
92909
+ Expr *pDflt;
92910
+ assert( p->pTab!=0 && IsOrdinaryTable(p->pTab) );
92911
+ pDflt = p->pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
92912
+ rc = sqlite3ValueFromExpr(db, pDflt, ENC(db), pCol->affinity, &pVal);
92913
+ if( rc==SQLITE_OK && pVal==0 ){
92914
+ rc = SQLITE_CORRUPT_BKPT;
92915
+ }
92916
+ p->apDflt[iIdx] = pVal;
92917
+ }
92918
+ *ppValue = p->apDflt[iIdx];
92919
+ }else{
92920
+ *ppValue = (sqlite3_value *)columnNullValue();
92921
+ }
92922
+ }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){
92923
+ if( pMem->flags & (MEM_Int|MEM_IntReal) ){
92924
+ testcase( pMem->flags & MEM_Int );
92925
+ testcase( pMem->flags & MEM_IntReal );
92926
+ sqlite3VdbeMemRealify(pMem);
92927
+ }
92928
}
92929
}
92930
@@ -92669,6 +92998,7 @@ SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppVa
92998
PreUpdate *p;
92999
int rc = SQLITE_OK;
93000
Mem *pMem;
93001
+ int iStore = 0;
93002
93003
#ifdef SQLITE_ENABLE_API_ARMOR
93004
if( db==0 || ppValue==0 ){
@@ -92681,9 +93011,12 @@ SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppVa
93011
goto preupdate_new_out;
93012
}
93013
if( p->pPk && p->op!=SQLITE_UPDATE ){
92684
- iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx);
93014
+ iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
93015
+ }else{
93016
+ iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
93017
}
92686
- if( iIdx>=p->pCsr->nField || iIdx<0 ){
93018
+
93019
+ if( iStore>=p->pCsr->nField || iStore<0 ){
93020
rc = SQLITE_RANGE;
93021
goto preupdate_new_out;
93022
}
@@ -92703,14 +93036,14 @@ SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppVa
93036
}
93037
p->pNewUnpacked = pUnpack;
93038
}
92706
- pMem = &pUnpack->aMem[iIdx];
93039
+ pMem = &pUnpack->aMem[iStore];
93040
if( iIdx==p->pTab->iPKey ){
93041
sqlite3VdbeMemSetInt64(pMem, p->iKey2);
92709
- }else if( iIdx>=pUnpack->nField ){
93042
+ }else if( iStore>=pUnpack->nField ){
93043
pMem = (sqlite3_value *)columnNullValue();
93044
}
93045
}else{
92713
- /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
93046
+ /* For an UPDATE, memory cell (p->iNewReg+1+iStore) contains the required
93047
** value. Make a copy of the cell contents and return a pointer to it.
93048
** It is not safe to return a pointer to the memory cell itself as the
93049
** caller may modify the value text encoding.
@@ -92723,13 +93056,13 @@ SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppVa
93056
goto preupdate_new_out;
93057
}
93058
}
92726
- assert( iIdx>=0 && iIdx<p->pCsr->nField );
92727
- pMem = &p->aNew[iIdx];
93059
+ assert( iStore>=0 && iStore<p->pCsr->nField );
93060
+ pMem = &p->aNew[iStore];
93061
if( pMem->flags==0 ){
93062
if( iIdx==p->pTab->iPKey ){
93063
sqlite3VdbeMemSetInt64(pMem, p->iKey2);
93064
}else{
92732
- rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iIdx]);
93065
+ rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iStore]);
93066
if( rc!=SQLITE_OK ) goto preupdate_new_out;
93067
}
93068
}
@@ -93143,6 +93476,104 @@ SQLITE_PRIVATE char *sqlite3VdbeExpandSql(
93476
/* #include "sqliteInt.h" */
93477
/* #include "vdbeInt.h" */
93478
93479
+/*
93480
+** High-resolution hardware timer used for debugging and testing only.
93481
+*/
93482
+#if defined(VDBE_PROFILE) \
93483
+ || defined(SQLITE_PERFORMANCE_TRACE) \
93484
+ || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
93485
+/************** Include hwtime.h in the middle of vdbe.c *********************/
93486
+/************** Begin file hwtime.h ******************************************/
93487
+/*
93488
+** 2008 May 27
93489
+**
93490
+** The author disclaims copyright to this source code. In place of
93491
+** a legal notice, here is a blessing:
93492
+**
93493
+** May you do good and not evil.
93494
+** May you find forgiveness for yourself and forgive others.
93495
+** May you share freely, never taking more than you give.
93496
+**
93497
+******************************************************************************
93498
+**
93499
+** This file contains inline asm code for retrieving "high-performance"
93500
+** counters for x86 and x86_64 class CPUs.
93501
+*/
93502
+#ifndef SQLITE_HWTIME_H
93503
+#define SQLITE_HWTIME_H
93504
+
93505
+/*
93506
+** The following routine only works on Pentium-class (or newer) processors.
93507
+** It uses the RDTSC opcode to read the cycle count value out of the
93508
+** processor and returns that value. This can be used for high-res
93509
+** profiling.
93510
+*/
93511
+#if !defined(__STRICT_ANSI__) && \
93512
+ (defined(__GNUC__) || defined(_MSC_VER)) && \
93513
+ (defined(i386) || defined(__i386__) || defined(_M_IX86))
93514
+
93515
+ #if defined(__GNUC__)
93516
+
93517
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
93518
+ unsigned int lo, hi;
93519
+ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
93520
+ return (sqlite_uint64)hi << 32 | lo;
93521
+ }
93522
+
93523
+ #elif defined(_MSC_VER)
93524
+
93525
+ __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
93526
+ __asm {
93527
+ rdtsc
93528
+ ret ; return value at EDX:EAX
93529
+ }
93530
+ }
93531
+
93532
+ #endif
93533
+
93534
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
93535
+
93536
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
93537
+ unsigned int lo, hi;
93538
+ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
93539
+ return (sqlite_uint64)hi << 32 | lo;
93540
+ }
93541
+
93542
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
93543
+
93544
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
93545
+ unsigned long long retval;
93546
+ unsigned long junk;
93547
+ __asm__ __volatile__ ("\n\
93548
+ 1: mftbu %1\n\
93549
+ mftb %L0\n\
93550
+ mftbu %0\n\
93551
+ cmpw %0,%1\n\
93552
+ bne 1b"
93553
+ : "=r" (retval), "=r" (junk));
93554
+ return retval;
93555
+ }
93556
+
93557
+#else
93558
+
93559
+ /*
93560
+ ** asm() is needed for hardware timing support. Without asm(),
93561
+ ** disable the sqlite3Hwtime() routine.
93562
+ **
93563
+ ** sqlite3Hwtime() is only used for some obscure debugging
93564
+ ** and analysis configurations, not in any deliverable, so this
93565
+ ** should not be a great loss.
93566
+ */
93567
+SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
93568
+
93569
+#endif
93570
+
93571
+#endif /* !defined(SQLITE_HWTIME_H) */
93572
+
93573
+/************** End of hwtime.h **********************************************/
93574
+/************** Continuing where we left off in vdbe.c ***********************/
93575
+#endif
93576
+
93577
/*
93578
** Invoke this macro on memory cells just prior to changing the
93579
** value of the cell. This macro verifies that shallow copies are
@@ -93720,6 +94151,7 @@ static void registerTrace(int iReg, Mem *p){
94151
printf("R[%d] = ", iReg);
94152
memTracePrint(p);
94153
if( p->pScopyFrom ){
94154
+ assert( p->pScopyFrom->bScopy );
94155
printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
94156
}
94157
printf("\n");
@@ -94336,7 +94768,7 @@ case OP_HaltIfNull: { /* in3 */
94768
/* no break */ deliberate_fall_through
94769
}
94770
94339
-/* Opcode: Halt P1 P2 * P4 P5
94771
+/* Opcode: Halt P1 P2 P3 P4 P5
94772
**
94773
** Exit immediately. All open cursors, etc are closed
94774
** automatically.
@@ -94349,18 +94781,22 @@ case OP_HaltIfNull: { /* in3 */
94781
** then back out all changes that have occurred during this execution of the
94782
** VDBE, but do not rollback the transaction.
94783
**
94352
-** If P4 is not null then it is an error message string.
94784
+** If P3 is not zero and P4 is NULL, then P3 is a register that holds the
94785
+** text of an error message.
94786
+**
94787
+** If P3 is zero and P4 is not null then the error message string is held
94788
+** in P4.
94789
**
94354
-** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
94790
+** P5 is a value between 1 and 4, inclusive, then the P4 error message
94791
+** string is modified as follows:
94792
**
94356
-** 0: (no change)
94793
** 1: NOT NULL constraint failed: P4
94794
** 2: UNIQUE constraint failed: P4
94795
** 3: CHECK constraint failed: P4
94796
** 4: FOREIGN KEY constraint failed: P4
94797
**
94362
-** If P5 is not zero and P4 is NULL, then everything after the ":" is
94363
-** omitted.
94798
+** If P3 is zero and P5 is not zero and P4 is NULL, then everything after
94799
+** the ":" is omitted.
94800
**
94801
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
94802
** every program. So a jump past the last instruction of the program
@@ -94373,6 +94809,9 @@ case OP_Halt: {
94809
#ifdef SQLITE_DEBUG
94810
if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
94811
#endif
94812
+ assert( pOp->p4type==P4_NOTUSED
94813
+ || pOp->p4type==P4_STATIC
94814
+ || pOp->p4type==P4_DYNAMIC );
94815
94816
/* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
94817
** something is wrong with the code generator. Raise an assertion in order
@@ -94403,7 +94842,12 @@ case OP_Halt: {
94842
p->errorAction = (u8)pOp->p2;
94843
assert( pOp->p5<=4 );
94844
if( p->rc ){
94406
- if( pOp->p5 ){
94845
+ if( pOp->p3>0 && pOp->p4type==P4_NOTUSED ){
94846
+ const char *zErr;
94847
+ assert( pOp->p3<=(p->nMem + 1 - p->nCursor) );
94848
+ zErr = sqlite3ValueText(&aMem[pOp->p3], SQLITE_UTF8);
94849
+ sqlite3VdbeError(p, "%s", zErr);
94850
+ }else if( pOp->p5 ){
94851
static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
94852
"FOREIGN KEY" };
94853
testcase( pOp->p5==1 );
@@ -94691,6 +95135,7 @@ case OP_Move: {
95135
{ int i;
95136
for(i=1; i<p->nMem; i++){
95137
if( aMem[i].pScopyFrom==pIn1 ){
95138
+ assert( aMem[i].bScopy );
95139
aMem[i].pScopyFrom = pOut;
95140
}
95141
}
@@ -94763,6 +95208,7 @@ case OP_SCopy: { /* out2 */
95208
#ifdef SQLITE_DEBUG
95209
pOut->pScopyFrom = pIn1;
95210
pOut->mScopyFlags = pIn1->flags;
95211
+ pIn1->bScopy = 1;
95212
#endif
95213
break;
95214
}
@@ -95206,7 +95652,7 @@ case OP_RealAffinity: { /* in1 */
95652
}
95653
#endif
95654
95209
-#if !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_ANALYZE)
95655
+#if !defined(SQLITE_OMIT_CAST) || !defined(SQLITE_OMIT_ANALYZE)
95656
/* Opcode: Cast P1 P2 * * *
95657
** Synopsis: affinity(r[P1])
95658
**
@@ -97446,23 +97892,23 @@ case OP_OpenWrite:
97892
if( pDb->pSchema->file_format < p->minWriteFileFormat ){
97893
p->minWriteFileFormat = pDb->pSchema->file_format;
97894
}
97895
+ if( pOp->p5 & OPFLAG_P2ISREG ){
97896
+ assert( p2>0 );
97897
+ assert( p2<=(u32)(p->nMem+1 - p->nCursor) );
97898
+ pIn2 = &aMem[p2];
97899
+ assert( memIsValid(pIn2) );
97900
+ assert( (pIn2->flags & MEM_Int)!=0 );
97901
+ sqlite3VdbeMemIntegerify(pIn2);
97902
+ p2 = (int)pIn2->u.i;
97903
+ /* The p2 value always comes from a prior OP_CreateBtree opcode and
97904
+ ** that opcode will always set the p2 value to 2 or more or else fail.
97905
+ ** If there were a failure, the prepared statement would have halted
97906
+ ** before reaching this instruction. */
97907
+ assert( p2>=2 );
97908
+ }
97909
}else{
97910
wrFlag = 0;
97451
- }
97452
- if( pOp->p5 & OPFLAG_P2ISREG ){
97453
- assert( p2>0 );
97454
- assert( p2<=(u32)(p->nMem+1 - p->nCursor) );
97455
- assert( pOp->opcode==OP_OpenWrite );
97456
- pIn2 = &aMem[p2];
97457
- assert( memIsValid(pIn2) );
97458
- assert( (pIn2->flags & MEM_Int)!=0 );
97459
- sqlite3VdbeMemIntegerify(pIn2);
97460
- p2 = (int)pIn2->u.i;
97461
- /* The p2 value always comes from a prior OP_CreateBtree opcode and
97462
- ** that opcode will always set the p2 value to 2 or more or else fail.
97463
- ** If there were a failure, the prepared statement would have halted
97464
- ** before reaching this instruction. */
97465
- assert( p2>=2 );
97911
+ assert( (pOp->p5 & OPFLAG_P2ISREG)==0 );
97912
}
97913
if( pOp->p4type==P4_KEYINFO ){
97914
pKeyInfo = pOp->p4.pKeyInfo;
@@ -97639,8 +98085,13 @@ case OP_OpenEphemeral: { /* ncycle */
98085
}
98086
}
98087
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
98088
+ assert( p->apCsr[pOp->p1]==pCx );
98089
if( rc ){
98090
+ assert( !sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
98091
sqlite3BtreeClose(pCx->ub.pBtx);
98092
+ p->apCsr[pOp->p1] = 0; /* Not required; helps with static analysis */
98093
+ }else{
98094
+ assert( sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
98095
}
98096
}
98097
}
@@ -98418,6 +98869,7 @@ case OP_Found: { /* jump, in3, ncycle */
98869
r.pKeyInfo = pC->pKeyInfo;
98870
r.default_rc = 0;
98871
#ifdef SQLITE_DEBUG
98872
+ (void)sqlite3FaultSim(50); /* For use by --counter in TH3 */
98873
for(ii=0; ii<r.nField; ii++){
98874
assert( memIsValid(&r.aMem[ii]) );
98875
assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
@@ -100780,18 +101232,29 @@ case OP_AggInverse:
101232
case OP_AggStep: {
101233
int n;
101234
sqlite3_context *pCtx;
101235
+ u64 nAlloc;
101236
101237
assert( pOp->p4type==P4_FUNCDEF );
101238
n = pOp->p5;
101239
assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
101240
assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
101241
assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
100789
- pCtx = sqlite3DbMallocRawNN(db, n*sizeof(sqlite3_value*) +
100790
- (sizeof(pCtx[0]) + sizeof(Mem) - sizeof(sqlite3_value*)));
101242
+
101243
+ /* Allocate space for (a) the context object and (n-1) extra pointers
101244
+ ** to append to the sqlite3_context.argv[1] array, and (b) a memory
101245
+ ** cell in which to store the accumulation. Be careful that the memory
101246
+ ** cell is 8-byte aligned, even on platforms where a pointer is 32-bits.
101247
+ **
101248
+ ** Note: We could avoid this by using a regular memory cell from aMem[] for
101249
+ ** the accumulator, instead of allocating one here. */
101250
+ nAlloc = ROUND8P( sizeof(pCtx[0]) + (n-1)*sizeof(sqlite3_value*) );
101251
+ pCtx = sqlite3DbMallocRawNN(db, nAlloc + sizeof(Mem));
101252
if( pCtx==0 ) goto no_mem;
100792
- pCtx->pMem = 0;
100793
- pCtx->pOut = (Mem*)&(pCtx->argv[n]);
101253
+ pCtx->pOut = (Mem*)((u8*)pCtx + nAlloc);
101254
+ assert( EIGHT_BYTE_ALIGNMENT(pCtx->pOut) );
101255
+
101256
sqlite3VdbeMemInit(pCtx->pOut, db, MEM_Null);
101257
+ pCtx->pMem = 0;
101258
pCtx->pFunc = pOp->p4.pFunc;
101259
pCtx->iOp = (int)(pOp - aOp);
101260
pCtx->pVdbe = p;
@@ -102125,14 +102588,29 @@ case OP_ReleaseReg: {
102588
102589
/* Opcode: Noop * * * * *
102590
**
102128
-** Do nothing. This instruction is often useful as a jump
102129
-** destination.
102591
+** Do nothing. Continue downward to the next opcode.
102592
*/
102131
-/*
102132
-** The magic Explain opcode are only inserted when explain==2 (which
102133
-** is to say when the EXPLAIN QUERY PLAN syntax is used.)
102134
-** This opcode records information from the optimizer. It is the
102135
-** the same as a no-op. This opcodesnever appears in a real VM program.
102593
+/* Opcode: Explain P1 P2 P3 P4 *
102594
+**
102595
+** This is the same as OP_Noop during normal query execution. The
102596
+** purpose of this opcode is to hold information about the query
102597
+** plan for the purpose of EXPLAIN QUERY PLAN output.
102598
+**
102599
+** The P4 value is human-readable text that describes the query plan
102600
+** element. Something like "SCAN t1" or "SEARCH t2 USING INDEX t2x1".
102601
+**
102602
+** The P1 value is the ID of the current element and P2 is the parent
102603
+** element for the case of nested query plan elements. If P2 is zero
102604
+** then this element is a top-level element.
102605
+**
102606
+** For loop elements, P3 is the estimated code of each invocation of this
102607
+** element.
102608
+**
102609
+** As with all opcodes, the meanings of the parameters for OP_Explain
102610
+** are subject to change from one release to the next. Applications
102611
+** should not attempt to interpret or use any of the information
102612
+** contained in the OP_Explain opcode. The information provided by this
102613
+** opcode is intended for testing and debugging use only.
102614
*/
102615
default: { /* This is really OP_Noop, OP_Explain */
102616
assert( pOp->opcode==OP_Noop || pOp->opcode==OP_Explain );
@@ -102459,6 +102937,11 @@ SQLITE_API int sqlite3_blob_open(
102937
pTab = 0;
102938
sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable);
102939
}
102940
+ if( pTab && (pTab->tabFlags&TF_HasGenerated)!=0 ){
102941
+ pTab = 0;
102942
+ sqlite3ErrorMsg(&sParse, "cannot open table with generated columns: %s",
102943
+ zTable);
102944
+ }
102945
#ifndef SQLITE_OMIT_VIEW
102946
if( pTab && IsView(pTab) ){
102947
pTab = 0;
@@ -103366,13 +103849,14 @@ static int vdbePmaReadBlob(
103849
while( nRem>0 ){
103850
int rc; /* vdbePmaReadBlob() return code */
103851
int nCopy; /* Number of bytes to copy */
103369
- u8 *aNext; /* Pointer to buffer to copy data from */
103852
+ u8 *aNext = 0; /* Pointer to buffer to copy data from */
103853
103854
nCopy = nRem;
103855
if( nRem>p->nBuffer ) nCopy = p->nBuffer;
103856
rc = vdbePmaReadBlob(p, nCopy, &aNext);
103857
if( rc!=SQLITE_OK ) return rc;
103858
assert( aNext!=p->aAlloc );
103859
+ assert( aNext!=0 );
103860
memcpy(&p->aAlloc[nByte - nRem], aNext, nCopy);
103861
nRem -= nCopy;
103862
}
@@ -106642,7 +107126,9 @@ SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker *pWalker, Select *p){
107126
pSrc = p->pSrc;
107127
if( ALWAYS(pSrc) ){
107128
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
106645
- if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){
107129
+ if( pItem->fg.isSubquery
107130
+ && sqlite3WalkSelect(pWalker, pItem->u4.pSubq->pSelect)
107131
+ ){
107132
return WRC_Abort;
107133
}
107134
if( pItem->fg.isTabFunc
@@ -106948,7 +107434,7 @@ static void extendFJMatch(
107434
if( pNew ){
107435
pNew->iTable = pMatch->iCursor;
107436
pNew->iColumn = iColumn;
106951
- pNew->y.pTab = pMatch->pTab;
107437
+ pNew->y.pTab = pMatch->pSTab;
107438
assert( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 );
107439
ExprSetProperty(pNew, EP_CanBeNull);
107440
*ppList = sqlite3ExprListAppend(pParse, *ppList, pNew);
@@ -107079,10 +107565,10 @@ static int lookupName(
107565
if( pSrcList ){
107566
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
107567
u8 hCol;
107082
- pTab = pItem->pTab;
107568
+ pTab = pItem->pSTab;
107569
assert( pTab!=0 && pTab->zName!=0 );
107570
assert( pTab->nCol>0 || pParse->nErr );
107085
- assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
107571
+ assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem));
107572
if( pItem->fg.isNestedFrom ){
107573
/* In this case, pItem is a subquery that has been formed from a
107574
** parenthesized subset of the FROM clause terms. Example:
@@ -107091,8 +107577,12 @@ static int lookupName(
107577
** This pItem -------------^
107578
*/
107579
int hit = 0;
107094
- assert( pItem->pSelect!=0 );
107095
- pEList = pItem->pSelect->pEList;
107580
+ Select *pSel;
107581
+ assert( pItem->fg.isSubquery );
107582
+ assert( pItem->u4.pSubq!=0 );
107583
+ pSel = pItem->u4.pSubq->pSelect;
107584
+ assert( pSel!=0 );
107585
+ pEList = pSel->pEList;
107586
assert( pEList!=0 );
107587
assert( pEList->nExpr==pTab->nCol );
107588
for(j=0; j<pEList->nExpr; j++){
@@ -107215,9 +107705,9 @@ static int lookupName(
107705
*/
107706
if( cntTab==0
107707
|| (cntTab==1
107218
- && ALWAYS(pMatch!=0)
107219
- && ALWAYS(pMatch->pTab!=0)
107220
- && (pMatch->pTab->tabFlags & TF_Ephemeral)!=0
107708
+ && pMatch!=0
107709
+ && ALWAYS(pMatch->pSTab!=0)
107710
+ && (pMatch->pSTab->tabFlags & TF_Ephemeral)!=0
107711
&& (pTab->tabFlags & TF_Ephemeral)==0)
107712
){
107713
cntTab = 1;
@@ -107238,7 +107728,7 @@ static int lookupName(
107728
if( pMatch ){
107729
pExpr->iTable = pMatch->iCursor;
107730
assert( ExprUseYTab(pExpr) );
107241
- pExpr->y.pTab = pMatch->pTab;
107731
+ pExpr->y.pTab = pMatch->pSTab;
107732
if( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 ){
107733
ExprSetProperty(pExpr, EP_CanBeNull);
107734
}
@@ -107280,7 +107770,7 @@ static int lookupName(
107770
if( (pNC->ncFlags & NC_UUpsert)!=0 && zTab!=0 ){
107771
Upsert *pUpsert = pNC->uNC.pUpsert;
107772
if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){
107283
- pTab = pUpsert->pUpsertSrc->a[0].pTab;
107773
+ pTab = pUpsert->pUpsertSrc->a[0].pSTab;
107774
pExpr->iTable = EXCLUDED_TABLE_NUMBER;
107775
}
107776
}
@@ -107363,11 +107853,11 @@ static int lookupName(
107853
&& pMatch
107854
&& (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
107855
&& sqlite3IsRowid(zCol)
107366
- && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom)
107856
+ && ALWAYS(VisibleRowid(pMatch->pSTab) || pMatch->fg.isNestedFrom)
107857
){
107858
cnt = cntTab;
107859
#if SQLITE_ALLOW_ROWID_IN_VIEW+0==2
107370
- if( pMatch->pTab!=0 && IsView(pMatch->pTab) ){
107860
+ if( pMatch->pSTab!=0 && IsView(pMatch->pSTab) ){
107861
eNewExprOp = TK_NULL;
107862
}
107863
#endif
@@ -107604,7 +108094,7 @@ SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSr
108094
SrcItem *pItem = &pSrc->a[iSrc];
108095
Table *pTab;
108096
assert( ExprUseYTab(p) );
107607
- pTab = p->y.pTab = pItem->pTab;
108097
+ pTab = p->y.pTab = pItem->pSTab;
108098
p->iTable = pItem->iCursor;
108099
if( p->y.pTab->iPKey==iCol ){
108100
p->iColumn = -1;
@@ -107723,7 +108213,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
108213
pItem = pSrcList->a;
108214
pExpr->op = TK_COLUMN;
108215
assert( ExprUseYTab(pExpr) );
107726
- pExpr->y.pTab = pItem->pTab;
108216
+ pExpr->y.pTab = pItem->pSTab;
108217
pExpr->iTable = pItem->iCursor;
108218
pExpr->iColumn--;
108219
pExpr->affExpr = SQLITE_AFF_INTEGER;
@@ -107848,8 +108338,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
108338
/* Resolve function names
108339
*/
108340
case TK_FUNCTION: {
107851
- ExprList *pList = pExpr->x.pList; /* The argument list */
107852
- int n = pList ? pList->nExpr : 0; /* Number of arguments */
108341
+ ExprList *pList; /* The argument list */
108342
+ int n; /* Number of arguments */
108343
int no_such_func = 0; /* True if no such function exists */
108344
int wrong_num_args = 0; /* True if wrong number of arguments */
108345
int is_agg = 0; /* True if is an aggregate function */
@@ -107862,6 +108352,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
108352
#endif
108353
assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
108354
assert( pExpr->pLeft==0 || pExpr->pLeft->op==TK_ORDER );
108355
+ pList = pExpr->x.pList;
108356
+ n = pList ? pList->nExpr : 0;
108357
zId = pExpr->u.zToken;
108358
pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
108359
if( pDef==0 ){
@@ -107910,6 +108402,24 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
108402
}
108403
}
108404
#endif
108405
+
108406
+ /* If the function may call sqlite3_value_subtype(), then set the
108407
+ ** EP_SubtArg flag on all of its argument expressions. This prevents
108408
+ ** where.c from replacing the expression with a value read from an
108409
+ ** index on the same expression, which will not have the correct
108410
+ ** subtype. Also set the flag if the function expression itself is
108411
+ ** an EP_SubtArg expression. In this case subtypes are required as
108412
+ ** the function may return a value with a subtype back to its
108413
+ ** caller using sqlite3_result_value(). */
108414
+ if( (pDef->funcFlags & SQLITE_SUBTYPE)
108415
+ || ExprHasProperty(pExpr, EP_SubtArg)
108416
+ ){
108417
+ int ii;
108418
+ for(ii=0; ii<n; ii++){
108419
+ ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg);
108420
+ }
108421
+ }
108422
+
108423
if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
108424
/* For the purposes of the EP_ConstFunc flag, date and time
108425
** functions and other functions that change slowly are considered
@@ -108029,9 +108539,9 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
108539
sqlite3WalkExprList(pWalker, pExpr->pLeft->x.pList);
108540
}
108541
#ifndef SQLITE_OMIT_WINDOWFUNC
108032
- if( pWin ){
108542
+ if( pWin && pParse->nErr==0 ){
108543
Select *pSel = pNC->pWinSelect;
108034
- assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) );
108544
+ assert( ExprUseYWin(pExpr) && pWin==pExpr->y.pWin );
108545
if( IN_RENAME_OBJECT==0 ){
108546
sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
108547
if( pParse->db->mallocFailed ) break;
@@ -108238,7 +108748,7 @@ static int resolveOrderByTermToExprList(
108748
int rc; /* Return code from subprocedures */
108749
u8 savedSuppErr; /* Saved value of db->suppressErr */
108750
108241
- assert( sqlite3ExprIsInteger(pE, &i)==0 );
108751
+ assert( sqlite3ExprIsInteger(pE, &i, 0)==0 );
108752
pEList = pSelect->pEList;
108753
108754
/* Resolve all names in the ORDER BY term expression
@@ -108337,7 +108847,7 @@ static int resolveCompoundOrderBy(
108847
if( pItem->fg.done ) continue;
108848
pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
108849
if( NEVER(pE==0) ) continue;
108340
- if( sqlite3ExprIsInteger(pE, &iCol) ){
108850
+ if( sqlite3ExprIsInteger(pE, &iCol, 0) ){
108851
if( iCol<=0 || iCol>pEList->nExpr ){
108852
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
108853
return 1;
@@ -108522,7 +109032,7 @@ static int resolveOrderGroupBy(
109032
continue;
109033
}
109034
}
108525
- if( sqlite3ExprIsInteger(pE2, &iCol) ){
109035
+ if( sqlite3ExprIsInteger(pE2, &iCol, 0) ){
109036
/* The ORDER BY term is an integer constant. Again, set the column
109037
** number so that sqlite3ResolveOrderGroupBy() will convert the
109038
** order-by term to a copy of the result-set expression */
@@ -108613,7 +109123,11 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
109123
** moves the pOrderBy down to the sub-query. It will be moved back
109124
** after the names have been resolved. */
109125
if( p->selFlags & SF_Converted ){
108616
- Select *pSub = p->pSrc->a[0].pSelect;
109126
+ Select *pSub;
109127
+ assert( p->pSrc->a[0].fg.isSubquery );
109128
+ assert( p->pSrc->a[0].u4.pSubq!=0 );
109129
+ pSub = p->pSrc->a[0].u4.pSubq->pSelect;
109130
+ assert( pSub!=0 );
109131
assert( p->pSrc->nSrc==1 && p->pOrderBy );
109132
assert( pSub->pPrior && pSub->pOrderBy==0 );
109133
pSub->pOrderBy = p->pOrderBy;
@@ -108625,13 +109139,16 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
109139
if( pOuterNC ) pOuterNC->nNestedSelect++;
109140
for(i=0; i<p->pSrc->nSrc; i++){
109141
SrcItem *pItem = &p->pSrc->a[i];
108628
- assert( pItem->zName!=0 || pItem->pSelect!=0 );/* Test of tag-20240424-1*/
108629
- if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
109142
+ assert( pItem->zName!=0
109143
+ || pItem->fg.isSubquery ); /* Test of tag-20240424-1*/
109144
+ if( pItem->fg.isSubquery
109145
+ && (pItem->u4.pSubq->pSelect->selFlags & SF_Resolved)==0
109146
+ ){
109147
int nRef = pOuterNC ? pOuterNC->nRef : 0;
109148
const char *zSavedContext = pParse->zAuthContext;
109149
109150
if( pItem->zName ) pParse->zAuthContext = pItem->zName;
108634
- sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
109151
+ sqlite3ResolveSelectNames(pParse, pItem->u4.pSubq->pSelect, pOuterNC);
109152
pParse->zAuthContext = zSavedContext;
109153
if( pParse->nErr ) return WRC_Abort;
109154
assert( db->mallocFailed==0 );
@@ -108733,7 +109250,10 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
109250
** These integers will be replaced by copies of the corresponding result
109251
** set expressions by the call to resolveOrderGroupBy() below. */
109252
if( p->selFlags & SF_Converted ){
108736
- Select *pSub = p->pSrc->a[0].pSelect;
109253
+ Select *pSub;
109254
+ assert( p->pSrc->a[0].fg.isSubquery );
109255
+ pSub = p->pSrc->a[0].u4.pSubq->pSelect;
109256
+ assert( pSub!=0 );
109257
p->pOrderBy = pSub->pOrderBy;
109258
pSub->pOrderBy = 0;
109259
}
@@ -109000,7 +109520,7 @@ SQLITE_PRIVATE int sqlite3ResolveSelfReference(
109520
if( pTab ){
109521
sSrc.nSrc = 1;
109522
sSrc.a[0].zName = pTab->zName;
109003
- sSrc.a[0].pTab = pTab;
109523
+ sSrc.a[0].pSTab = pTab;
109524
sSrc.a[0].iCursor = -1;
109525
if( pTab->pSchema!=pParse->db->aDb[1].pSchema ){
109526
/* Cause EP_FromDDL to be set on TK_FUNCTION nodes of non-TEMP
@@ -109105,7 +109625,9 @@ SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
109625
op = pExpr->op;
109626
continue;
109627
}
109108
- if( op!=TK_REGISTER || (op = pExpr->op2)==TK_REGISTER ) break;
109628
+ if( op!=TK_REGISTER ) break;
109629
+ op = pExpr->op2;
109630
+ if( NEVER( op==TK_REGISTER ) ) break;
109631
}
109632
return pExpr->affExpr;
109633
}
@@ -109497,7 +110019,7 @@ static int codeCompare(
110019
p5 = binaryCompareP5(pLeft, pRight, jumpIfNull);
110020
addr = sqlite3VdbeAddOp4(pParse->pVdbe, opcode, in2, dest, in1,
110021
(void*)p4, P4_COLLSEQ);
109500
- sqlite3VdbeChangeP5(pParse->pVdbe, (u8)p5);
110022
+ sqlite3VdbeChangeP5(pParse->pVdbe, (u16)p5);
110023
return addr;
110024
}
110025
@@ -110895,15 +111417,30 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int fla
111417
SrcItem *pNewItem = &pNew->a[i];
111418
const SrcItem *pOldItem = &p->a[i];
111419
Table *pTab;
110898
- pNewItem->pSchema = pOldItem->pSchema;
110899
- pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
111420
+ pNewItem->fg = pOldItem->fg;
111421
+ if( pOldItem->fg.isSubquery ){
111422
+ Subquery *pNewSubq = sqlite3DbMallocRaw(db, sizeof(Subquery));
111423
+ if( pNewSubq==0 ){
111424
+ assert( db->mallocFailed );
111425
+ pNewItem->fg.isSubquery = 0;
111426
+ }else{
111427
+ memcpy(pNewSubq, pOldItem->u4.pSubq, sizeof(*pNewSubq));
111428
+ pNewSubq->pSelect = sqlite3SelectDup(db, pNewSubq->pSelect, flags);
111429
+ if( pNewSubq->pSelect==0 ){
111430
+ sqlite3DbFree(db, pNewSubq);
111431
+ pNewSubq = 0;
111432
+ pNewItem->fg.isSubquery = 0;
111433
+ }
111434
+ }
111435
+ pNewItem->u4.pSubq = pNewSubq;
111436
+ }else if( pOldItem->fg.fixedSchema ){
111437
+ pNewItem->u4.pSchema = pOldItem->u4.pSchema;
111438
+ }else{
111439
+ pNewItem->u4.zDatabase = sqlite3DbStrDup(db, pOldItem->u4.zDatabase);
111440
+ }
111441
pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
111442
pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
110902
- pNewItem->fg = pOldItem->fg;
111443
pNewItem->iCursor = pOldItem->iCursor;
110904
- pNewItem->addrFillSub = pOldItem->addrFillSub;
110905
- pNewItem->regReturn = pOldItem->regReturn;
110906
- pNewItem->regResult = pOldItem->regResult;
111444
if( pNewItem->fg.isIndexedBy ){
111445
pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
111446
}else if( pNewItem->fg.isTabFunc ){
@@ -110916,11 +111453,10 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int fla
111453
if( pNewItem->fg.isCte ){
111454
pNewItem->u2.pCteUse->nUse++;
111455
}
110919
- pTab = pNewItem->pTab = pOldItem->pTab;
111456
+ pTab = pNewItem->pSTab = pOldItem->pSTab;
111457
if( pTab ){
111458
pTab->nTabRef++;
111459
}
110923
- pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
111460
if( pOldItem->fg.isUsing ){
111461
assert( pNewItem->fg.isUsing );
111462
pNewItem->u3.pUsing = sqlite3IdListDup(db, pOldItem->u3.pUsing);
@@ -110936,16 +111472,13 @@ SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, const IdList *p){
111472
int i;
111473
assert( db!=0 );
111474
if( p==0 ) return 0;
110939
- assert( p->eU4!=EU4_EXPR );
111475
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew)+(p->nId-1)*sizeof(p->a[0]) );
111476
if( pNew==0 ) return 0;
111477
pNew->nId = p->nId;
110943
- pNew->eU4 = p->eU4;
111478
for(i=0; i<p->nId; i++){
111479
struct IdList_item *pNewItem = &pNew->a[i];
111480
const struct IdList_item *pOldItem = &p->a[i];
111481
pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
110948
- pNewItem->u4 = pOldItem->u4;
111482
}
111483
return pNew;
111484
}
@@ -110994,7 +111527,6 @@ SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *pDup, int fla
111527
pp = &pNew->pPrior;
111528
pNext = pNew;
111529
}
110997
-
111530
return pRet;
111531
}
111532
#else
@@ -111651,7 +112183,7 @@ static int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){
112183
** (4a) pExpr must come from an ON clause..
112184
** (4b) and specifically the ON clause associated with the LEFT JOIN.
112185
**
111654
-** (5) If pSrc is not the right operand of a LEFT JOIN or the left
112186
+** (5) If pSrc is the right operand of a LEFT JOIN or the left
112187
** operand of a RIGHT JOIN, then pExpr must be from the WHERE
112188
** clause, not an ON clause.
112189
**
@@ -111809,8 +112341,12 @@ SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){
112341
** to fit in a 32-bit integer, return 1 and put the value of the integer
112342
** in *pValue. If the expression is not an integer or if it is too big
112343
** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
112344
+**
112345
+** If the pParse pointer is provided, then allow the expression p to be
112346
+** a parameter (TK_VARIABLE) that is bound to an integer.
112347
+** But if pParse is NULL, then p must be a pure integer literal.
112348
*/
111813
-SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr *p, int *pValue){
112349
+SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr *p, int *pValue, Parse *pParse){
112350
int rc = 0;
112351
if( NEVER(p==0) ) return 0; /* Used to only happen following on OOM */
112352
@@ -111825,18 +112361,38 @@ SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr *p, int *pValue){
112361
}
112362
switch( p->op ){
112363
case TK_UPLUS: {
111828
- rc = sqlite3ExprIsInteger(p->pLeft, pValue);
112364
+ rc = sqlite3ExprIsInteger(p->pLeft, pValue, 0);
112365
break;
112366
}
112367
case TK_UMINUS: {
112368
int v = 0;
111833
- if( sqlite3ExprIsInteger(p->pLeft, &v) ){
112369
+ if( sqlite3ExprIsInteger(p->pLeft, &v, 0) ){
112370
assert( ((unsigned int)v)!=0x80000000 );
112371
*pValue = -v;
112372
rc = 1;
112373
}
112374
break;
112375
}
112376
+ case TK_VARIABLE: {
112377
+ sqlite3_value *pVal;
112378
+ if( pParse==0 ) break;
112379
+ if( NEVER(pParse->pVdbe==0) ) break;
112380
+ if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) break;
112381
+ sqlite3VdbeSetVarmask(pParse->pVdbe, p->iColumn);
112382
+ pVal = sqlite3VdbeGetBoundValue(pParse->pReprepare, p->iColumn,
112383
+ SQLITE_AFF_BLOB);
112384
+ if( pVal ){
112385
+ if( sqlite3_value_type(pVal)==SQLITE_INTEGER ){
112386
+ sqlite3_int64 vv = sqlite3_value_int64(pVal);
112387
+ if( vv == (vv & 0x7fffffff) ){ /* non-negative numbers only */
112388
+ *pValue = (int)vv;
112389
+ rc = 1;
112390
+ }
112391
+ }
112392
+ sqlite3ValueFree(pVal);
112393
+ }
112394
+ break;
112395
+ }
112396
default: break;
112397
}
112398
return rc;
@@ -111990,8 +112546,8 @@ static Select *isCandidateForInOpt(const Expr *pX){
112546
pSrc = p->pSrc;
112547
assert( pSrc!=0 );
112548
if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
111993
- if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */
111994
- pTab = pSrc->a[0].pTab;
112549
+ if( pSrc->a[0].fg.isSubquery) return 0;/* FROM is not a subquery or view */
112550
+ pTab = pSrc->a[0].pSTab;
112551
assert( pTab!=0 );
112552
assert( !IsView(pTab) ); /* FROM clause is not a view */
112553
if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
@@ -112174,7 +112730,7 @@ SQLITE_PRIVATE int sqlite3FindInIndex(
112730
assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
112731
assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
112732
assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
112177
- pTab = p->pSrc->a[0].pTab;
112733
+ pTab = p->pSrc->a[0].pSTab;
112734
112735
/* Code an OP_Transaction and OP_TableLock for <table>. */
112736
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -112266,6 +112822,7 @@ SQLITE_PRIVATE int sqlite3FindInIndex(
112822
if( aiMap ) aiMap[i] = j;
112823
}
112824
112825
+ assert( nExpr>0 && nExpr<BMS );
112826
assert( i==nExpr || colUsed!=(MASKBIT(nExpr)-1) );
112827
if( colUsed==(MASKBIT(nExpr)-1) ){
112828
/* If we reach this point, that means the index pIdx is usable */
@@ -112414,6 +112971,50 @@ SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
112971
}
112972
}
112973
112974
+#ifndef SQLITE_OMIT_SUBQUERY
112975
+/*
112976
+** Scan all previously generated bytecode looking for an OP_BeginSubrtn
112977
+** that is compatible with pExpr. If found, add the y.sub values
112978
+** to pExpr and return true. If not found, return false.
112979
+*/
112980
+static int findCompatibleInRhsSubrtn(
112981
+ Parse *pParse, /* Parsing context */
112982
+ Expr *pExpr, /* IN operator with RHS that we want to reuse */
112983
+ SubrtnSig *pNewSig /* Signature for the IN operator */
112984
+){
112985
+ VdbeOp *pOp, *pEnd;
112986
+ SubrtnSig *pSig;
112987
+ Vdbe *v;
112988
+
112989
+ if( pNewSig==0 ) return 0;
112990
+ if( (pParse->mSubrtnSig & (1<<(pNewSig->selId&7)))==0 ) return 0;
112991
+ assert( pExpr->op==TK_IN );
112992
+ assert( !ExprUseYSub(pExpr) );
112993
+ assert( ExprUseXSelect(pExpr) );
112994
+ assert( pExpr->x.pSelect!=0 );
112995
+ assert( (pExpr->x.pSelect->selFlags & SF_All)==0 );
112996
+ v = pParse->pVdbe;
112997
+ assert( v!=0 );
112998
+ pOp = sqlite3VdbeGetOp(v, 1);
112999
+ pEnd = sqlite3VdbeGetLastOp(v);
113000
+ for(; pOp<pEnd; pOp++){
113001
+ if( pOp->p4type!=P4_SUBRTNSIG ) continue;
113002
+ assert( pOp->opcode==OP_BeginSubrtn );
113003
+ pSig = pOp->p4.pSubrtnSig;
113004
+ assert( pSig!=0 );
113005
+ if( !pSig->bComplete ) continue;
113006
+ if( pNewSig->selId!=pSig->selId ) continue;
113007
+ if( strcmp(pNewSig->zAff,pSig->zAff)!=0 ) continue;
113008
+ pExpr->y.sub.iAddr = pSig->iAddr;
113009
+ pExpr->y.sub.regReturn = pSig->regReturn;
113010
+ pExpr->iTable = pSig->iTable;
113011
+ ExprSetProperty(pExpr, EP_Subrtn);
113012
+ return 1;
113013
+ }
113014
+ return 0;
113015
+}
113016
+#endif /* SQLITE_OMIT_SUBQUERY */
113017
+
113018
#ifndef SQLITE_OMIT_SUBQUERY
113019
/*
113020
** Generate code that will construct an ephemeral table containing all terms
@@ -112448,6 +113049,7 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
113049
KeyInfo *pKeyInfo = 0; /* Key information */
113050
int nVal; /* Size of vector pLeft */
113051
Vdbe *v; /* The prepared statement under construction */
113052
+ SubrtnSig *pSig = 0; /* Signature for this subroutine */
113053
113054
v = pParse->pVdbe;
113055
assert( v!=0 );
@@ -112463,11 +113065,27 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
113065
** and reuse it many names.
113066
*/
113067
if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
112466
- /* Reuse of the RHS is allowed */
112467
- /* If this routine has already been coded, but the previous code
112468
- ** might not have been invoked yet, so invoke it now as a subroutine.
113068
+ /* Reuse of the RHS is allowed
113069
+ **
113070
+ ** Compute a signature for the RHS of the IN operator to facility
113071
+ ** finding and reusing prior instances of the same IN operator.
113072
*/
112470
- if( ExprHasProperty(pExpr, EP_Subrtn) ){
113073
+ assert( !ExprUseXSelect(pExpr) || pExpr->x.pSelect!=0 );
113074
+ if( ExprUseXSelect(pExpr) && (pExpr->x.pSelect->selFlags & SF_All)==0 ){
113075
+ pSig = sqlite3DbMallocRawNN(pParse->db, sizeof(pSig[0]));
113076
+ if( pSig ){
113077
+ pSig->selId = pExpr->x.pSelect->selId;
113078
+ pSig->zAff = exprINAffinity(pParse, pExpr);
113079
+ }
113080
+ }
113081
+
113082
+ /* Check to see if there is a prior materialization of the RHS of
113083
+ ** this IN operator. If there is, then make use of that prior
113084
+ ** materialization rather than recomputing it.
113085
+ */
113086
+ if( ExprHasProperty(pExpr, EP_Subrtn)
113087
+ || findCompatibleInRhsSubrtn(pParse, pExpr, pSig)
113088
+ ){
113089
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
113090
if( ExprUseXSelect(pExpr) ){
113091
ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
@@ -112479,6 +113097,10 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
113097
assert( iTab!=pExpr->iTable );
113098
sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
113099
sqlite3VdbeJumpHere(v, addrOnce);
113100
+ if( pSig ){
113101
+ sqlite3DbFree(pParse->db, pSig->zAff);
113102
+ sqlite3DbFree(pParse->db, pSig);
113103
+ }
113104
return;
113105
}
113106
@@ -112489,7 +113111,14 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
113111
pExpr->y.sub.regReturn = ++pParse->nMem;
113112
pExpr->y.sub.iAddr =
113113
sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
112492
-
113114
+ if( pSig ){
113115
+ pSig->bComplete = 0;
113116
+ pSig->iAddr = pExpr->y.sub.iAddr;
113117
+ pSig->regReturn = pExpr->y.sub.regReturn;
113118
+ pSig->iTable = iTab;
113119
+ pParse->mSubrtnSig = 1 << (pSig->selId&7);
113120
+ sqlite3VdbeChangeP4(v, -1, (const char*)pSig, P4_SUBRTNSIG);
113121
+ }
113122
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
113123
}
113124
@@ -112530,15 +113159,30 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
113159
SelectDest dest;
113160
int i;
113161
int rc;
113162
+ int addrBloom = 0;
113163
sqlite3SelectDestInit(&dest, SRT_Set, iTab);
113164
dest.zAffSdst = exprINAffinity(pParse, pExpr);
113165
pSelect->iLimit = 0;
113166
+ if( addrOnce && OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){
113167
+ int regBloom = ++pParse->nMem;
113168
+ addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
113169
+ VdbeComment((v, "Bloom filter"));
113170
+ dest.iSDParm2 = regBloom;
113171
+ }
113172
testcase( pSelect->selFlags & SF_Distinct );
113173
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
113174
pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
113175
rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
113176
sqlite3SelectDelete(pParse->db, pCopy);
113177
sqlite3DbFree(pParse->db, dest.zAffSdst);
113178
+ if( addrBloom ){
113179
+ sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
113180
+ if( dest.iSDParm2==0 ){
113181
+ sqlite3VdbeChangeToNoop(v, addrBloom);
113182
+ }else{
113183
+ sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
113184
+ }
113185
+ }
113186
if( rc ){
113187
sqlite3KeyInfoUnref(pKeyInfo);
113188
return;
@@ -112604,6 +113248,7 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
113248
sqlite3ReleaseTempReg(pParse, r1);
113249
sqlite3ReleaseTempReg(pParse, r2);
113250
}
113251
+ if( pSig ) pSig->bComplete = 1;
113252
if( pKeyInfo ){
113253
sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
113254
}
@@ -112836,9 +113481,7 @@ static void sqlite3ExprCodeIN(
113481
if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
113482
zAff = exprINAffinity(pParse, pExpr);
113483
nVector = sqlite3ExprVectorSize(pExpr->pLeft);
112839
- aiMap = (int*)sqlite3DbMallocZero(
112840
- pParse->db, nVector*(sizeof(int) + sizeof(char)) + 1
112841
- );
113484
+ aiMap = (int*)sqlite3DbMallocZero(pParse->db, nVector*sizeof(int));
113485
if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
113486
113487
/* Attempt to compute the RHS. After this step, if anything other than
@@ -112981,6 +113624,15 @@ static void sqlite3ExprCodeIN(
113624
sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
113625
if( destIfFalse==destIfNull ){
113626
/* Combine Step 3 and Step 5 into a single opcode */
113627
+ if( ExprHasProperty(pExpr, EP_Subrtn) ){
113628
+ const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr);
113629
+ assert( pOp->opcode==OP_Once || pParse->nErr );
113630
+ if( pOp->opcode==OP_Once && pOp->p3>0 ){
113631
+ assert( OptimizationEnabled(pParse->db, SQLITE_BloomFilter) );
113632
+ sqlite3VdbeAddOp4Int(v, OP_Filter, pOp->p3, destIfFalse,
113633
+ rLhs, nVector); VdbeCoverage(v);
113634
+ }
113635
+ }
113636
sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
113637
rLhs, nVector); VdbeCoverage(v);
113638
goto sqlite3ExprCodeIN_finished;
@@ -113263,13 +113915,17 @@ SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int n
113915
** register iReg. The caller must ensure that iReg already contains
113916
** the correct value for the expression.
113917
*/
113266
-static void exprToRegister(Expr *pExpr, int iReg){
113918
+SQLITE_PRIVATE void sqlite3ExprToRegister(Expr *pExpr, int iReg){
113919
Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
113920
if( NEVER(p==0) ) return;
113269
- p->op2 = p->op;
113270
- p->op = TK_REGISTER;
113271
- p->iTable = iReg;
113272
- ExprClearProperty(p, EP_Skip);
113921
+ if( p->op==TK_REGISTER ){
113922
+ assert( p->iTable==iReg );
113923
+ }else{
113924
+ p->op2 = p->op;
113925
+ p->op = TK_REGISTER;
113926
+ p->iTable = iReg;
113927
+ ExprClearProperty(p, EP_Skip);
113928
+ }
113929
}
113930
113931
/*
@@ -113439,6 +114095,59 @@ static int exprCodeInlineFunction(
114095
return target;
114096
}
114097
114098
+/*
114099
+** Expression Node callback for sqlite3ExprCanReturnSubtype().
114100
+**
114101
+** Only a function call is able to return a subtype. So if the node
114102
+** is not a function call, return WRC_Prune immediately.
114103
+**
114104
+** A function call is able to return a subtype if it has the
114105
+** SQLITE_RESULT_SUBTYPE property.
114106
+**
114107
+** Assume that every function is able to pass-through a subtype from
114108
+** one of its argument (using sqlite3_result_value()). Most functions
114109
+** are not this way, but we don't have a mechanism to distinguish those
114110
+** that are from those that are not, so assume they all work this way.
114111
+** That means that if one of its arguments is another function and that
114112
+** other function is able to return a subtype, then this function is
114113
+** able to return a subtype.
114114
+*/
114115
+static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
114116
+ int n;
114117
+ FuncDef *pDef;
114118
+ sqlite3 *db;
114119
+ if( pExpr->op!=TK_FUNCTION ){
114120
+ return WRC_Prune;
114121
+ }
114122
+ assert( ExprUseXList(pExpr) );
114123
+ db = pWalker->pParse->db;
114124
+ n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
114125
+ pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
114126
+ if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
114127
+ pWalker->eCode = 1;
114128
+ return WRC_Prune;
114129
+ }
114130
+ return WRC_Continue;
114131
+}
114132
+
114133
+/*
114134
+** Return TRUE if expression pExpr is able to return a subtype.
114135
+**
114136
+** A TRUE return does not guarantee that a subtype will be returned.
114137
+** It only indicates that a subtype return is possible. False positives
114138
+** are acceptable as they only disable an optimization. False negatives,
114139
+** on the other hand, can lead to incorrect answers.
114140
+*/
114141
+static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
114142
+ Walker w;
114143
+ memset(&w, 0, sizeof(w));
114144
+ w.pParse = pParse;
114145
+ w.xExprCallback = exprNodeCanReturnSubtype;
114146
+ sqlite3WalkExpr(&w, pExpr);
114147
+ return w.eCode;
114148
+}
114149
+
114150
+
114151
/*
114152
** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr.
114153
** If it is, then resolve the expression by reading from the index and
@@ -113471,6 +114180,17 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup(
114180
continue;
114181
}
114182
114183
+
114184
+ /* Functions that might set a subtype should not be replaced by the
114185
+ ** value taken from an expression index if they are themselves an
114186
+ ** argument to another scalar function or aggregate.
114187
+ ** https://sqlite.org/forum/forumpost/68d284c86b082c3e */
114188
+ if( ExprHasProperty(pExpr, EP_SubtArg)
114189
+ && sqlite3ExprCanReturnSubtype(pParse, pExpr)
114190
+ ){
114191
+ continue;
114192
+ }
114193
+
114194
v = pParse->pVdbe;
114195
assert( v!=0 );
114196
if( p->bMaybeNullRow ){
@@ -114272,7 +114992,7 @@ expr_code_doover:
114992
break;
114993
}
114994
testcase( pX->op==TK_COLUMN );
114275
- exprToRegister(pDel, exprCodeVector(pParse, pDel, ®Free1));
114995
+ sqlite3ExprToRegister(pDel, exprCodeVector(pParse, pDel, ®Free1));
114996
testcase( regFree1==0 );
114997
memset(&opCompare, 0, sizeof(opCompare));
114998
opCompare.op = TK_EQ;
@@ -114326,15 +115046,14 @@ expr_code_doover:
115046
}
115047
assert( !ExprHasProperty(pExpr, EP_IntValue) );
115048
if( pExpr->affExpr==OE_Ignore ){
114329
- sqlite3VdbeAddOp4(
114330
- v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
115049
+ sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, OE_Ignore);
115050
VdbeCoverage(v);
115051
}else{
114333
- sqlite3HaltConstraint(pParse,
115052
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1);
115053
+ sqlite3VdbeAddOp3(v, OP_Halt,
115054
pParse->pTriggerTab ? SQLITE_CONSTRAINT_TRIGGER : SQLITE_ERROR,
114335
- pExpr->affExpr, pExpr->u.zToken, 0, 0);
115055
+ pExpr->affExpr, r1);
115056
}
114337
-
115057
break;
115058
}
115059
#endif
@@ -114623,7 +115342,7 @@ static void exprCodeBetween(
115342
compRight.op = TK_LE;
115343
compRight.pLeft = pDel;
115344
compRight.pRight = pExpr->x.pList->a[1].pExpr;
114626
- exprToRegister(pDel, exprCodeVector(pParse, pDel, ®Free1));
115345
+ sqlite3ExprToRegister(pDel, exprCodeVector(pParse, pDel, ®Free1));
115346
if( xJump ){
115347
xJump(pParse, &exprAnd, dest, jumpIfNull);
115348
}else{
@@ -115002,16 +115721,23 @@ SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse *pParse, Expr *pExpr, int dest,i
115721
** same as that currently bound to variable pVar, non-zero is returned.
115722
** Otherwise, if the values are not the same or if pExpr is not a simple
115723
** SQL value, zero is returned.
115724
+**
115725
+** If the SQLITE_EnableQPSG flag is set on the database connection, then
115726
+** this routine always returns false.
115727
*/
115006
-static int exprCompareVariable(
115728
+static SQLITE_NOINLINE int exprCompareVariable(
115729
const Parse *pParse,
115730
const Expr *pVar,
115731
const Expr *pExpr
115732
){
115011
- int res = 0;
115733
+ int res = 2;
115734
int iVar;
115735
sqlite3_value *pL, *pR = 0;
115736
115737
+ if( pExpr->op==TK_VARIABLE && pVar->iColumn==pExpr->iColumn ){
115738
+ return 0;
115739
+ }
115740
+ if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) return 2;
115741
sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, SQLITE_AFF_BLOB, &pR);
115742
if( pR ){
115743
iVar = pVar->iColumn;
@@ -115021,12 +115747,11 @@ static int exprCompareVariable(
115747
if( sqlite3_value_type(pL)==SQLITE_TEXT ){
115748
sqlite3_value_text(pL); /* Make sure the encoding is UTF-8 */
115749
}
115024
- res = 0==sqlite3MemCompare(pL, pR, 0);
115750
+ res = sqlite3MemCompare(pL, pR, 0) ? 2 : 0;
115751
}
115752
sqlite3ValueFree(pR);
115753
sqlite3ValueFree(pL);
115754
}
115029
-
115755
return res;
115756
}
115757
@@ -115052,12 +115777,10 @@ static int exprCompareVariable(
115777
** just might result in some slightly slower code. But returning
115778
** an incorrect 0 or 1 could lead to a malfunction.
115779
**
115055
-** If pParse is not NULL then TK_VARIABLE terms in pA with bindings in
115056
-** pParse->pReprepare can be matched against literals in pB. The
115057
-** pParse->pVdbe->expmask bitmask is updated for each variable referenced.
115058
-** If pParse is NULL (the normal case) then any TK_VARIABLE term in
115059
-** Argument pParse should normally be NULL. If it is not NULL and pA or
115060
-** pB causes a return value of 2.
115780
+** If pParse is not NULL and SQLITE_EnableQPSG is off then TK_VARIABLE
115781
+** terms in pA with bindings in pParse->pReprepare can be matched against
115782
+** literals in pB. The pParse->pVdbe->expmask bitmask is updated for
115783
+** each variable referenced.
115784
*/
115785
SQLITE_PRIVATE int sqlite3ExprCompare(
115786
const Parse *pParse,
@@ -115069,8 +115792,8 @@ SQLITE_PRIVATE int sqlite3ExprCompare(
115792
if( pA==0 || pB==0 ){
115793
return pB==pA ? 0 : 2;
115794
}
115072
- if( pParse && pA->op==TK_VARIABLE && exprCompareVariable(pParse, pA, pB) ){
115073
- return 0;
115795
+ if( pParse && pA->op==TK_VARIABLE ){
115796
+ return exprCompareVariable(pParse, pA, pB);
115797
}
115798
combinedFlags = pA->flags | pB->flags;
115799
if( combinedFlags & EP_IntValue ){
@@ -115265,18 +115988,70 @@ static int exprImpliesNotNull(
115988
return 0;
115989
}
115990
115991
+/*
115992
+** Return true if the boolean value of the expression is always either
115993
+** FALSE or NULL.
115994
+*/
115995
+static int sqlite3ExprIsNotTrue(Expr *pExpr){
115996
+ int v;
115997
+ if( pExpr->op==TK_NULL ) return 1;
115998
+ if( pExpr->op==TK_TRUEFALSE && sqlite3ExprTruthValue(pExpr)==0 ) return 1;
115999
+ v = 1;
116000
+ if( sqlite3ExprIsInteger(pExpr, &v, 0) && v==0 ) return 1;
116001
+ return 0;
116002
+}
116003
+
116004
+/*
116005
+** Return true if the expression is one of the following:
116006
+**
116007
+** CASE WHEN x THEN y END
116008
+** CASE WHEN x THEN y ELSE NULL END
116009
+** CASE WHEN x THEN y ELSE false END
116010
+** iif(x,y)
116011
+** iif(x,y,NULL)
116012
+** iif(x,y,false)
116013
+*/
116014
+static int sqlite3ExprIsIIF(sqlite3 *db, const Expr *pExpr){
116015
+ ExprList *pList;
116016
+ if( pExpr->op==TK_FUNCTION ){
116017
+ const char *z = pExpr->u.zToken;
116018
+ FuncDef *pDef;
116019
+ if( (z[0]!='i' && z[0]!='I') ) return 0;
116020
+ if( pExpr->x.pList==0 ) return 0;
116021
+ pDef = sqlite3FindFunction(db, z, pExpr->x.pList->nExpr, ENC(db), 0);
116022
+#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
116023
+ if( pDef==0 ) return 0;
116024
+#else
116025
+ if( NEVER(pDef==0) ) return 0;
116026
+#endif
116027
+ if( (pDef->funcFlags & SQLITE_FUNC_INLINE)==0 ) return 0;
116028
+ if( SQLITE_PTR_TO_INT(pDef->pUserData)!=INLINEFUNC_iif ) return 0;
116029
+ }else if( pExpr->op==TK_CASE ){
116030
+ if( pExpr->pLeft!=0 ) return 0;
116031
+ }else{
116032
+ return 0;
116033
+ }
116034
+ pList = pExpr->x.pList;
116035
+ assert( pList!=0 );
116036
+ if( pList->nExpr==2 ) return 1;
116037
+ if( pList->nExpr==3 && sqlite3ExprIsNotTrue(pList->a[2].pExpr) ) return 1;
116038
+ return 0;
116039
+}
116040
+
116041
/*
116042
** Return true if we can prove the pE2 will always be true if pE1 is
116043
** true. Return false if we cannot complete the proof or if pE2 might
116044
** be false. Examples:
116045
**
115273
-** pE1: x==5 pE2: x==5 Result: true
115274
-** pE1: x>0 pE2: x==5 Result: false
115275
-** pE1: x=21 pE2: x=21 OR y=43 Result: true
115276
-** pE1: x!=123 pE2: x IS NOT NULL Result: true
115277
-** pE1: x!=?1 pE2: x IS NOT NULL Result: true
115278
-** pE1: x IS NULL pE2: x IS NOT NULL Result: false
115279
-** pE1: x IS ?2 pE2: x IS NOT NULL Result: false
116046
+** pE1: x==5 pE2: x==5 Result: true
116047
+** pE1: x>0 pE2: x==5 Result: false
116048
+** pE1: x=21 pE2: x=21 OR y=43 Result: true
116049
+** pE1: x!=123 pE2: x IS NOT NULL Result: true
116050
+** pE1: x!=?1 pE2: x IS NOT NULL Result: true
116051
+** pE1: x IS NULL pE2: x IS NOT NULL Result: false
116052
+** pE1: x IS ?2 pE2: x IS NOT NULL Result: false
116053
+** pE1: iif(x,y) pE2: x Result: true
116054
+** PE1: iif(x,y,0) pE2: x Result: true
116055
**
116056
** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has
116057
** Expr.iTable<0 then assume a table number given by iTab.
@@ -115310,6 +116085,9 @@ SQLITE_PRIVATE int sqlite3ExprImpliesExpr(
116085
){
116086
return 1;
116087
}
116088
+ if( sqlite3ExprIsIIF(pParse->db, pE1) ){
116089
+ return sqlite3ExprImpliesExpr(pParse,pE1->x.pList->a[0].pExpr,pE2,iTab);
116090
+ }
116091
return 0;
116092
}
116093
@@ -117517,8 +118295,9 @@ static int renameResolveTrigger(Parse *pParse){
118295
int i;
118296
for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
118297
SrcItem *p = &pStep->pFrom->a[i];
117520
- if( p->pSelect ){
117521
- sqlite3SelectPrep(pParse, p->pSelect, 0);
118298
+ if( p->fg.isSubquery ){
118299
+ assert( p->u4.pSubq!=0 );
118300
+ sqlite3SelectPrep(pParse, p->u4.pSubq->pSelect, 0);
118301
}
118302
}
118303
}
@@ -117586,8 +118365,12 @@ static void renameWalkTrigger(Walker *pWalker, Trigger *pTrigger){
118365
}
118366
if( pStep->pFrom ){
118367
int i;
117589
- for(i=0; i<pStep->pFrom->nSrc; i++){
117590
- sqlite3WalkSelect(pWalker, pStep->pFrom->a[i].pSelect);
118368
+ SrcList *pFrom = pStep->pFrom;
118369
+ for(i=0; i<pFrom->nSrc; i++){
118370
+ if( pFrom->a[i].fg.isSubquery ){
118371
+ assert( pFrom->a[i].u4.pSubq!=0 );
118372
+ sqlite3WalkSelect(pWalker, pFrom->a[i].u4.pSubq->pSelect);
118373
+ }
118374
}
118375
}
118376
}
@@ -117834,7 +118617,7 @@ static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
118617
}
118618
for(i=0; i<pSrc->nSrc; i++){
118619
SrcItem *pItem = &pSrc->a[i];
117837
- if( pItem->pTab==p->pTab ){
118620
+ if( pItem->pSTab==p->pTab ){
118621
renameTokenFind(pWalker->pParse, p, pItem->zName);
118622
}
118623
}
This file is too large to show in full.
src/database/sqlite/vendored/sqlite3.h
+343
-53
@@ -146,9 +146,9 @@ extern "C" {
146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147
** [sqlite_version()] and [sqlite_source_id()].
148
*/
149
-#define SQLITE_VERSION "3.46.1"
150
-#define SQLITE_VERSION_NUMBER 3046001
151
-#define SQLITE_SOURCE_ID "2024-08-13 09:16:08 c9c2ab54ba1f5f46360f1b4f35d849cd3f080e6fc2b6c60e91b16c63f69a1e33"
149
+#define SQLITE_VERSION "3.49.1"
150
+#define SQLITE_VERSION_NUMBER 3049001
151
+#define SQLITE_SOURCE_ID "2025-02-18 13:38:58 873d4e274b4988d260ba8354a9718324a1c26187a4ab4c1cc0227c03d0f10e70"
152
153
/*
154
** CAPI3REF: Run-Time Library Version Numbers
@@ -652,6 +652,13 @@ SQLITE_API int sqlite3_exec(
652
** filesystem supports doing multiple write operations atomically when those
653
** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
654
** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
655
+**
656
+** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read
657
+** from the database file in amounts that are not a multiple of the
658
+** page size and that do not begin at a page boundary. Without this
659
+** property, SQLite is careful to only do full-page reads and write
660
+** on aligned pages, with the one exception that it will do a sub-page
661
+** read of the first page to access the database header.
662
*/
663
#define SQLITE_IOCAP_ATOMIC 0x00000001
664
#define SQLITE_IOCAP_ATOMIC512 0x00000002
@@ -668,6 +675,7 @@ SQLITE_API int sqlite3_exec(
675
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
676
#define SQLITE_IOCAP_IMMUTABLE 0x00002000
677
#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
678
+#define SQLITE_IOCAP_SUBPAGE_READ 0x00008000
679
680
/*
681
** CAPI3REF: File Locking Levels
@@ -772,8 +780,8 @@ struct sqlite3_file {
780
** to xUnlock() is a no-op.
781
** The xCheckReservedLock() method checks whether any database connection,
782
** either in this process or in some other process, is holding a RESERVED,
775
-** PENDING, or EXCLUSIVE lock on the file. It returns true
776
-** if such a lock exists and false otherwise.
783
+** PENDING, or EXCLUSIVE lock on the file. It returns, via its output
784
+** pointer parameter, true if such a lock exists and false otherwise.
785
**
786
** The xFileControl() method is a generic interface that allows custom
787
** VFS implementations to directly control an open file using the
@@ -814,6 +822,7 @@ struct sqlite3_file {
822
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
823
** <li> [SQLITE_IOCAP_IMMUTABLE]
824
** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
825
+** <li> [SQLITE_IOCAP_SUBPAGE_READ]
826
** </ul>
827
**
828
** The SQLITE_IOCAP_ATOMIC property means that all writes of
@@ -1091,6 +1100,11 @@ struct sqlite3_io_methods {
1100
** pointed to by the pArg argument. This capability is used during testing
1101
** and only needs to be supported when SQLITE_TEST is defined.
1102
**
1103
+** <li>[[SQLITE_FCNTL_NULL_IO]]
1104
+** The [SQLITE_FCNTL_NULL_IO] opcode sets the low-level file descriptor
1105
+** or file handle for the [sqlite3_file] object such that it will no longer
1106
+** read or write to the database file.
1107
+**
1108
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1109
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1110
** be advantageous to block on the next WAL lock if the lock is not immediately
@@ -1244,6 +1258,7 @@ struct sqlite3_io_methods {
1258
#define SQLITE_FCNTL_EXTERNAL_READER 40
1259
#define SQLITE_FCNTL_CKSM_FILE 41
1260
#define SQLITE_FCNTL_RESET_CACHE 42
1261
+#define SQLITE_FCNTL_NULL_IO 43
1262
1263
/* deprecated names */
1264
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
@@ -2196,7 +2211,15 @@ struct sqlite3_mem_methods {
2211
** CAPI3REF: Database Connection Configuration Options
2212
**
2213
** These constants are the available integer configuration options that
2199
-** can be passed as the second argument to the [sqlite3_db_config()] interface.
2214
+** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2215
+**
2216
+** The [sqlite3_db_config()] interface is a var-args functions. It takes a
2217
+** variable number of parameters, though always at least two. The number of
2218
+** parameters passed into sqlite3_db_config() depends on which of these
2219
+** constants is given as the second parameter. This documentation page
2220
+** refers to parameters beyond the second as "arguments". Thus, when this
2221
+** page says "the N-th argument" it means "the N-th parameter past the
2222
+** configuration option" or "the (N+2)-th parameter to sqlite3_db_config()".
2223
**
2224
** New configuration options may be added in future releases of SQLite.
2225
** Existing configuration options might be discontinued. Applications
@@ -2208,8 +2231,14 @@ struct sqlite3_mem_methods {
2231
** <dl>
2232
** [[SQLITE_DBCONFIG_LOOKASIDE]]
2233
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2211
-** <dd> ^This option takes three additional arguments that determine the
2212
-** [lookaside memory allocator] configuration for the [database connection].
2234
+** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2235
+** configuration of the lookaside memory allocator within a database
2236
+** connection.
2237
+** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2238
+** in the [DBCONFIG arguments|usual format].
2239
+** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2240
+** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2241
+** should have a total of five parameters.
2242
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2243
** pointer to a memory buffer to use for lookaside memory.
2244
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
@@ -2232,7 +2261,8 @@ struct sqlite3_mem_methods {
2261
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2262
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2263
** <dd> ^This option is used to enable or disable the enforcement of
2235
-** [foreign key constraints]. There should be two additional arguments.
2264
+** [foreign key constraints]. This is the same setting that is
2265
+** enabled or disabled by the [PRAGMA foreign_keys] statement.
2266
** The first argument is an integer which is 0 to disable FK enforcement,
2267
** positive to enable FK enforcement or negative to leave FK enforcement
2268
** unchanged. The second parameter is a pointer to an integer into which
@@ -2254,13 +2284,13 @@ struct sqlite3_mem_methods {
2284
** <p>Originally this option disabled all triggers. ^(However, since
2285
** SQLite version 3.35.0, TEMP triggers are still allowed even if
2286
** this option is off. So, in other words, this option now only disables
2257
-** triggers in the main database schema or in the schemas of ATTACH-ed
2287
+** triggers in the main database schema or in the schemas of [ATTACH]-ed
2288
** databases.)^ </dd>
2289
**
2290
** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
2291
** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
2292
** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
2263
-** There should be two additional arguments.
2293
+** There must be two additional arguments.
2294
** The first argument is an integer which is 0 to disable views,
2295
** positive to enable views or negative to leave the setting unchanged.
2296
** The second parameter is a pointer to an integer into which
@@ -2279,7 +2309,7 @@ struct sqlite3_mem_methods {
2309
** <dd> ^This option is used to enable or disable the
2310
** [fts3_tokenizer()] function which is part of the
2311
** [FTS3] full-text search engine extension.
2282
-** There should be two additional arguments.
2312
+** There must be two additional arguments.
2313
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2314
** positive to enable fts3_tokenizer() or negative to leave the setting
2315
** unchanged.
@@ -2294,7 +2324,7 @@ struct sqlite3_mem_methods {
2324
** interface independently of the [load_extension()] SQL function.
2325
** The [sqlite3_enable_load_extension()] API enables or disables both the
2326
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2297
-** There should be two additional arguments.
2327
+** There must be two additional arguments.
2328
** When the first argument to this interface is 1, then only the C-API is
2329
** enabled and the SQL function remains disabled. If the first argument to
2330
** this interface is 0, then both the C-API and the SQL function are disabled.
@@ -2308,23 +2338,30 @@ struct sqlite3_mem_methods {
2338
**
2339
** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2340
** <dd> ^This option is used to change the name of the "main" database
2311
-** schema. ^The sole argument is a pointer to a constant UTF8 string
2312
-** which will become the new schema name in place of "main". ^SQLite
2313
-** does not make a copy of the new main schema name string, so the application
2314
-** must ensure that the argument passed into this DBCONFIG option is unchanged
2315
-** until after the database connection closes.
2341
+** schema. This option does not follow the
2342
+** [DBCONFIG arguments|usual SQLITE_DBCONFIG argument format].
2343
+** This option takes exactly one additional argument so that the
2344
+** [sqlite3_db_config()] call has a total of three parameters. The
2345
+** extra argument must be a pointer to a constant UTF8 string which
2346
+** will become the new schema name in place of "main". ^SQLite does
2347
+** not make a copy of the new main schema name string, so the application
2348
+** must ensure that the argument passed into SQLITE_DBCONFIG MAINDBNAME
2349
+** is unchanged until after the database connection closes.
2350
** </dd>
2351
**
2352
** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
2353
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2320
-** <dd> Usually, when a database in wal mode is closed or detached from a
2321
-** database handle, SQLite checks if this will mean that there are now no
2322
-** connections at all to the database. If so, it performs a checkpoint
2323
-** operation before closing the connection. This option may be used to
2324
-** override this behavior. The first parameter passed to this operation
2325
-** is an integer - positive to disable checkpoints-on-close, or zero (the
2326
-** default) to enable them, and negative to leave the setting unchanged.
2327
-** The second parameter is a pointer to an integer
2354
+** <dd> Usually, when a database in [WAL mode] is closed or detached from a
2355
+** database handle, SQLite checks if if there are other connections to the
2356
+** same database, and if there are no other database connection (if the
2357
+** connection being closed is the last open connection to the database),
2358
+** then SQLite performs a [checkpoint] before closing the connection and
2359
+** deletes the WAL file. The SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE option can
2360
+** be used to override that behavior. The first argument passed to this
2361
+** operation (the third parameter to [sqlite3_db_config()]) is an integer
2362
+** which is positive to disable checkpoints-on-close, or zero (the default)
2363
+** to enable them, and negative to leave the setting unchanged.
2364
+** The second argument (the fourth parameter) is a pointer to an integer
2365
** into which is written 0 or 1 to indicate whether checkpoints-on-close
2366
** have been disabled - 0 if they are not disabled, 1 if they are.
2367
** </dd>
@@ -2485,7 +2522,7 @@ struct sqlite3_mem_methods {
2522
** statistics. For statistics to be collected, the flag must be set on
2523
** the database handle both when the SQL statement is prepared and when it
2524
** is stepped. The flag is set (collection of statistics is enabled)
2488
-** by default. This option takes two arguments: an integer and a pointer to
2525
+** by default. <p>This option takes two arguments: an integer and a pointer to
2526
** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2527
** leave unchanged the statement scanstatus option. If the second argument
2528
** is not NULL, then the value of the statement scanstatus setting after
@@ -2499,7 +2536,7 @@ struct sqlite3_mem_methods {
2536
** in which tables and indexes are scanned so that the scans start at the end
2537
** and work toward the beginning rather than starting at the beginning and
2538
** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2502
-** same as setting [PRAGMA reverse_unordered_selects]. This option takes
2539
+** same as setting [PRAGMA reverse_unordered_selects]. <p>This option takes
2540
** two arguments which are an integer and a pointer to an integer. The first
2541
** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2542
** reverse scan order flag, respectively. If the second argument is not NULL,
@@ -2508,7 +2545,76 @@ struct sqlite3_mem_methods {
2545
** first argument.
2546
** </dd>
2547
**
2548
+** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]]
2549
+** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt>
2550
+** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables or disables
2551
+** the ability of the [ATTACH DATABASE] SQL command to create a new database
2552
+** file if the database filed named in the ATTACH command does not already
2553
+** exist. This ability of ATTACH to create a new database is enabled by
2554
+** default. Applications can disable or reenable the ability for ATTACH to
2555
+** create new database files using this DBCONFIG option.<p>
2556
+** This option takes two arguments which are an integer and a pointer
2557
+** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2558
+** leave unchanged the attach-create flag, respectively. If the second
2559
+** argument is not NULL, then 0 or 1 is written into the integer that the
2560
+** second argument points to depending on if the attach-create flag is set
2561
+** after processing the first argument.
2562
+** </dd>
2563
+**
2564
+** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2565
+** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2566
+** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2567
+** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2568
+** This capability is enabled by default. Applications can disable or
2569
+** reenable this capability using the current DBCONFIG option. If the
2570
+** the this capability is disabled, the [ATTACH] command will still work,
2571
+** but the database will be opened read-only. If this option is disabled,
2572
+** then the ability to create a new database using [ATTACH] is also disabled,
2573
+** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2574
+** option.<p>
2575
+** This option takes two arguments which are an integer and a pointer
2576
+** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2577
+** leave unchanged the ability to ATTACH another database for writing,
2578
+** respectively. If the second argument is not NULL, then 0 or 1 is written
2579
+** into the integer to which the second argument points, depending on whether
2580
+** the ability to ATTACH a read/write database is enabled or disabled
2581
+** after processing the first argument.
2582
+** </dd>
2583
+**
2584
+** [[SQLITE_DBCONFIG_ENABLE_COMMENTS]]
2585
+** <dt>SQLITE_DBCONFIG_ENABLE_COMMENTS</dt>
2586
+** <dd>The SQLITE_DBCONFIG_ENABLE_COMMENTS option enables or disables the
2587
+** ability to include comments in SQL text. Comments are enabled by default.
2588
+** An application can disable or reenable comments in SQL text using this
2589
+** DBCONFIG option.<p>
2590
+** This option takes two arguments which are an integer and a pointer
2591
+** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2592
+** leave unchanged the ability to use comments in SQL text,
2593
+** respectively. If the second argument is not NULL, then 0 or 1 is written
2594
+** into the integer that the second argument points to depending on if
2595
+** comments are allowed in SQL text after processing the first argument.
2596
+** </dd>
2597
+**
2598
** </dl>
2599
+**
2600
+** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2601
+**
2602
+** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2603
+** overall call to [sqlite3_db_config()] has a total of four parameters.
2604
+** The first argument (the third parameter to sqlite3_db_config()) is a integer.
2605
+** The second argument is a pointer to an integer. If the first argument is 1,
2606
+** then the option becomes enabled. If the first integer argument is 0, then the
2607
+** option is disabled. If the first argument is -1, then the option setting
2608
+** is unchanged. The second argument, the pointer to an integer, may be NULL.
2609
+** If the second argument is not NULL, then a value of 0 or 1 is written into
2610
+** the integer to which the second argument points, depending on whether the
2611
+** setting is disabled or enabled after applying any changes specified by
2612
+** the first argument.
2613
+**
2614
+** <p>While most SQLITE_DBCONFIG options use the argument format
2615
+** described in the previous paragraph, the [SQLITE_DBCONFIG_MAINDBNAME]
2616
+** and [SQLITE_DBCONFIG_LOOKASIDE] options are different. See the
2617
+** documentation of those exceptional options for details.
2618
*/
2619
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2620
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2530,7 +2636,10 @@ struct sqlite3_mem_methods {
2636
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2637
#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2638
#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
2533
-#define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
2639
+#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE 1020 /* int int* */
2640
+#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE 1021 /* int int* */
2641
+#define SQLITE_DBCONFIG_ENABLE_COMMENTS 1022 /* int int* */
2642
+#define SQLITE_DBCONFIG_MAX 1022 /* Largest DBCONFIG */
2643
2644
/*
2645
** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -2622,10 +2731,14 @@ SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2731
** deleted by the most recently completed INSERT, UPDATE or DELETE
2732
** statement on the database connection specified by the only parameter.
2733
** The two functions are identical except for the type of the return value
2625
-** and that if the number of rows modified by the most recent INSERT, UPDATE
2734
+** and that if the number of rows modified by the most recent INSERT, UPDATE,
2735
** or DELETE is greater than the maximum value supported by type "int", then
2736
** the return value of sqlite3_changes() is undefined. ^Executing any other
2737
** type of SQL statement does not modify the value returned by these functions.
2738
+** For the purposes of this interface, a CREATE TABLE AS SELECT statement
2739
+** does not count as an INSERT, UPDATE or DELETE statement and hence the rows
2740
+** added to the new table by the CREATE TABLE AS SELECT statement are not
2741
+** counted.
2742
**
2743
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2744
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
@@ -3570,8 +3683,8 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3683
**
3684
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
3685
** <dd>The database connection comes up in "extended result code mode".
3573
-** In other words, the database behaves has if
3574
-** [sqlite3_extended_result_codes(db,1)] where called on the database
3686
+** In other words, the database behaves as if
3687
+** [sqlite3_extended_result_codes(db,1)] were called on the database
3688
** connection as soon as the connection is created. In addition to setting
3689
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3690
** to return an extended result code.</dd>
@@ -4185,11 +4298,22 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4298
** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
4299
** to return an error (error code SQLITE_ERROR) if the statement uses
4300
** any virtual tables.
4301
+**
4302
+** [[SQLITE_PREPARE_DONT_LOG]] <dt>SQLITE_PREPARE_DONT_LOG</dt>
4303
+** <dd>The SQLITE_PREPARE_DONT_LOG flag prevents SQL compiler
4304
+** errors from being sent to the error log defined by
4305
+** [SQLITE_CONFIG_LOG]. This can be used, for example, to do test
4306
+** compiles to see if some SQL syntax is well-formed, without generating
4307
+** messages on the global error log when it is not. If the test compile
4308
+** fails, the sqlite3_prepare_v3() call returns the same error indications
4309
+** with or without this flag; it just omits the call to [sqlite3_log()] that
4310
+** logs the error.
4311
** </dl>
4312
*/
4313
#define SQLITE_PREPARE_PERSISTENT 0x01
4314
#define SQLITE_PREPARE_NORMALIZE 0x02
4315
#define SQLITE_PREPARE_NO_VTAB 0x04
4316
+#define SQLITE_PREPARE_DONT_LOG 0x10
4317
4318
/*
4319
** CAPI3REF: Compiling An SQL Statement
@@ -4222,13 +4346,17 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4346
** and sqlite3_prepare16_v3() use UTF-16.
4347
**
4348
** ^If the nByte argument is negative, then zSql is read up to the
4225
-** first zero terminator. ^If nByte is positive, then it is the
4226
-** number of bytes read from zSql. ^If nByte is zero, then no prepared
4349
+** first zero terminator. ^If nByte is positive, then it is the maximum
4350
+** number of bytes read from zSql. When nByte is positive, zSql is read
4351
+** up to the first zero terminator or until the nByte bytes have been read,
4352
+** whichever comes first. ^If nByte is zero, then no prepared
4353
** statement is generated.
4354
** If the caller knows that the supplied string is nul-terminated, then
4355
** there is a small performance advantage to passing an nByte parameter that
4356
** is the number of bytes in the input string <i>including</i>
4357
** the nul-terminator.
4358
+** Note that nByte measure the length of the input in bytes, not
4359
+** characters, even for the UTF-16 interfaces.
4360
**
4361
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4362
** past the end of the first SQL statement in zSql. These routines only
@@ -5599,7 +5727,7 @@ SQLITE_API int sqlite3_create_window_function(
5727
** This flag instructs SQLite to omit some corner-case optimizations that
5728
** might disrupt the operation of the [sqlite3_value_subtype()] function,
5729
** causing it to return zero rather than the correct subtype().
5602
-** SQL functions that invokes [sqlite3_value_subtype()] should have this
5730
+** All SQL functions that invoke [sqlite3_value_subtype()] should have this
5731
** property. If the SQLITE_SUBTYPE property is omitted, then the return
5732
** value from [sqlite3_value_subtype()] might sometimes be zero even though
5733
** a non-zero subtype was specified by the function argument expression.
@@ -5615,6 +5743,15 @@ SQLITE_API int sqlite3_create_window_function(
5743
** [sqlite3_result_subtype()] should avoid setting this property, as the
5744
** purpose of this property is to disable certain optimizations that are
5745
** incompatible with subtypes.
5746
+**
5747
+** [[SQLITE_SELFORDER1]] <dt>SQLITE_SELFORDER1</dt><dd>
5748
+** The SQLITE_SELFORDER1 flag indicates that the function is an aggregate
5749
+** that internally orders the values provided to the first argument. The
5750
+** ordered-set aggregate SQL notation with a single ORDER BY term can be
5751
+** used to invoke this function. If the ordered-set aggregate notation is
5752
+** used on a function that lacks this flag, then an error is raised. Note
5753
+** that the ordered-set aggregate syntax is only available if SQLite is
5754
+** built using the -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES compile-time option.
5755
** </dd>
5756
** </dl>
5757
*/
@@ -5623,6 +5760,7 @@ SQLITE_API int sqlite3_create_window_function(
5760
#define SQLITE_SUBTYPE 0x000100000
5761
#define SQLITE_INNOCUOUS 0x000200000
5762
#define SQLITE_RESULT_SUBTYPE 0x001000000
5763
+#define SQLITE_SELFORDER1 0x002000000
5764
5765
/*
5766
** CAPI3REF: Deprecated Functions
@@ -5820,7 +5958,7 @@ SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
5958
** one SQL function to another. Use the [sqlite3_result_subtype()]
5959
** routine to set the subtype for the return value of an SQL function.
5960
**
5823
-** Every [application-defined SQL function] that invoke this interface
5961
+** Every [application-defined SQL function] that invokes this interface
5962
** should include the [SQLITE_SUBTYPE] property in the text
5963
** encoding argument when the function is [sqlite3_create_function|registered].
5964
** If the [SQLITE_SUBTYPE] property is omitted, then sqlite3_value_subtype()
@@ -7427,9 +7565,11 @@ struct sqlite3_module {
7565
** will be returned by the strategy.
7566
**
7567
** The xBestIndex method may optionally populate the idxFlags field with a
7430
-** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
7431
-** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
7432
-** assumes that the strategy may visit at most one row.
7568
+** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
7569
+** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7570
+** output to show the idxNum has hex instead of as decimal. Another flag is
7571
+** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
7572
+** return at most one row.
7573
**
7574
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
7575
** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -7493,7 +7633,9 @@ struct sqlite3_index_info {
7633
** [sqlite3_index_info].idxFlags field to some combination of
7634
** these bits.
7635
*/
7496
-#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
7636
+#define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */
7637
+#define SQLITE_INDEX_SCAN_HEX 0x00000002 /* Display idxNum as hex */
7638
+ /* in EXPLAIN QUERY PLAN */
7639
7640
/*
7641
** CAPI3REF: Virtual Table Constraint Operator Codes
@@ -8330,6 +8472,7 @@ SQLITE_API int sqlite3_test_control(int op, ...);
8472
#define SQLITE_TESTCTRL_JSON_SELFCHECK 14
8473
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
8474
#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */
8475
+#define SQLITE_TESTCTRL_GETOPT 16
8476
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
8477
#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17
8478
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
@@ -8349,7 +8492,7 @@ SQLITE_API int sqlite3_test_control(int op, ...);
8492
#define SQLITE_TESTCTRL_TRACEFLAGS 31
8493
#define SQLITE_TESTCTRL_TUNE 32
8494
#define SQLITE_TESTCTRL_LOGEST 33
8352
-#define SQLITE_TESTCTRL_USELONGDOUBLE 34
8495
+#define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
8496
#define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
8497
8498
/*
@@ -9325,6 +9468,16 @@ typedef struct sqlite3_backup sqlite3_backup;
9468
** APIs are not strictly speaking threadsafe. If they are invoked at the
9469
** same time as another thread is invoking sqlite3_backup_step() it is
9470
** possible that they return invalid values.
9471
+**
9472
+** <b>Alternatives To Using The Backup API</b>
9473
+**
9474
+** Other techniques for safely creating a consistent backup of an SQLite
9475
+** database include:
9476
+**
9477
+** <ul>
9478
+** <li> The [VACUUM INTO] command.
9479
+** <li> The [sqlite3_rsync] utility program.
9480
+** </ul>
9481
*/
9482
SQLITE_API sqlite3_backup *sqlite3_backup_init(
9483
sqlite3 *pDest, /* Destination database handle */
@@ -10524,6 +10677,14 @@ typedef struct sqlite3_snapshot {
10677
** If there is not already a read-transaction open on schema S when
10678
** this function is called, one is opened automatically.
10679
**
10680
+** If a read-transaction is opened by this function, then it is guaranteed
10681
+** that the returned snapshot object may not be invalidated by a database
10682
+** writer or checkpointer until after the read-transaction is closed. This
10683
+** is not guaranteed if a read-transaction is already open when this
10684
+** function is called. In that case, any subsequent write or checkpoint
10685
+** operation on the database may invalidate the returned snapshot handle,
10686
+** even while the read-transaction remains open.
10687
+**
10688
** The following must be true for this function to succeed. If any of
10689
** the following statements are false when sqlite3_snapshot_get() is
10690
** called, SQLITE_ERROR is returned. The final value of *P is undefined
@@ -10681,8 +10842,9 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const c
10842
/*
10843
** CAPI3REF: Serialize a database
10844
**
10684
-** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
10685
-** that is a serialization of the S database on [database connection] D.
10845
+** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
10846
+** memory that is a serialization of the S database on
10847
+** [database connection] D. If S is a NULL pointer, the main database is used.
10848
** If P is not a NULL pointer, then the size of the database in bytes
10849
** is written into *P.
10850
**
@@ -10832,8 +10994,6 @@ SQLITE_API int sqlite3_deserialize(
10994
#if defined(__wasi__)
10995
# undef SQLITE_WASI
10996
# define SQLITE_WASI 1
10835
-# undef SQLITE_OMIT_WAL
10836
-# define SQLITE_OMIT_WAL 1/* because it requires shared memory APIs */
10997
# ifndef SQLITE_OMIT_LOAD_EXTENSION
10998
# define SQLITE_OMIT_LOAD_EXTENSION
10999
# endif
@@ -10845,7 +11005,7 @@ SQLITE_API int sqlite3_deserialize(
11005
#ifdef __cplusplus
11006
} /* End of the 'extern "C"' block */
11007
#endif
10848
-#endif /* SQLITE3_H */
11008
+/* #endif for SQLITE3_H will be added by mksqlite3.tcl */
11009
11010
/******** Begin file sqlite3rtree.h *********/
11011
/*
@@ -13036,6 +13196,10 @@ struct Fts5PhraseIter {
13196
** (i.e. if it is a contentless table), then this API always iterates
13197
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
13198
**
13199
+** In all cases, matches are visited in (column ASC, offset ASC) order.
13200
+** i.e. all those in column 0, sorted by offset, followed by those in
13201
+** column 1, etc.
13202
+**
13203
** xPhraseNext()
13204
** See xPhraseFirst above.
13205
**
@@ -13092,19 +13256,57 @@ struct Fts5PhraseIter {
13256
** value returned by xInstCount(), SQLITE_RANGE is returned. Otherwise,
13257
** output variable (*ppToken) is set to point to a buffer containing the
13258
** matching document token, and (*pnToken) to the size of that buffer in
13095
-** bytes. This API is not available if the specified token matches a
13096
-** prefix query term. In that case both output variables are always set
13097
-** to 0.
13259
+** bytes.
13260
**
13261
** The output text is not a copy of the document text that was tokenized.
13262
** It is the output of the tokenizer module. For tokendata=1 tables, this
13263
** includes any embedded 0x00 and trailing data.
13264
**
13265
+** This API may be slow in some cases if the token identified by parameters
13266
+** iIdx and iToken matched a prefix token in the query. In most cases, the
13267
+** first call to this API for each prefix token in the query is forced
13268
+** to scan the portion of the full-text index that matches the prefix
13269
+** token to collect the extra data required by this API. If the prefix
13270
+** token matches a large number of token instances in the document set,
13271
+** this may be a performance problem.
13272
+**
13273
+** If the user knows in advance that a query may use this API for a
13274
+** prefix token, FTS5 may be configured to collect all required data as part
13275
+** of the initial querying of the full-text index, avoiding the second scan
13276
+** entirely. This also causes prefix queries that do not use this API to
13277
+** run more slowly and use more memory. FTS5 may be configured in this way
13278
+** either on a per-table basis using the [FTS5 insttoken | 'insttoken']
13279
+** option, or on a per-query basis using the
13280
+** [fts5_insttoken | fts5_insttoken()] user function.
13281
+**
13282
** This API can be quite slow if used with an FTS5 table created with the
13283
** "detail=none" or "detail=column" option.
13284
+**
13285
+** xColumnLocale(pFts5, iIdx, pzLocale, pnLocale)
13286
+** If parameter iCol is less than zero, or greater than or equal to the
13287
+** number of columns in the table, SQLITE_RANGE is returned.
13288
+**
13289
+** Otherwise, this function attempts to retrieve the locale associated
13290
+** with column iCol of the current row. Usually, there is no associated
13291
+** locale, and output parameters (*pzLocale) and (*pnLocale) are set
13292
+** to NULL and 0, respectively. However, if the fts5_locale() function
13293
+** was used to associate a locale with the value when it was inserted
13294
+** into the fts5 table, then (*pzLocale) is set to point to a nul-terminated
13295
+** buffer containing the name of the locale in utf-8 encoding. (*pnLocale)
13296
+** is set to the size in bytes of the buffer, not including the
13297
+** nul-terminator.
13298
+**
13299
+** If successful, SQLITE_OK is returned. Or, if an error occurs, an
13300
+** SQLite error code is returned. The final value of the output parameters
13301
+** is undefined in this case.
13302
+**
13303
+** xTokenize_v2:
13304
+** Tokenize text using the tokenizer belonging to the FTS5 table. This
13305
+** API is the same as the xTokenize() API, except that it allows a tokenizer
13306
+** locale to be specified.
13307
*/
13308
struct Fts5ExtensionApi {
13107
- int iVersion; /* Currently always set to 3 */
13309
+ int iVersion; /* Currently always set to 4 */
13310
13311
void *(*xUserData)(Fts5Context*);
13312
@@ -13146,6 +13348,15 @@ struct Fts5ExtensionApi {
13348
const char **ppToken, int *pnToken
13349
);
13350
int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*);
13351
+
13352
+ /* Below this point are iVersion>=4 only */
13353
+ int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn);
13354
+ int (*xTokenize_v2)(Fts5Context*,
13355
+ const char *pText, int nText, /* Text to tokenize */
13356
+ const char *pLocale, int nLocale, /* Locale to pass to tokenizer */
13357
+ void *pCtx, /* Context passed to xToken() */
13358
+ int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
13359
+ );
13360
};
13361
13362
/*
@@ -13166,7 +13377,7 @@ struct Fts5ExtensionApi {
13377
** A tokenizer instance is required to actually tokenize text.
13378
**
13379
** The first argument passed to this function is a copy of the (void*)
13169
-** pointer provided by the application when the fts5_tokenizer object
13380
+** pointer provided by the application when the fts5_tokenizer_v2 object
13381
** was registered with FTS5 (the third argument to xCreateTokenizer()).
13382
** The second and third arguments are an array of nul-terminated strings
13383
** containing the tokenizer arguments, if any, specified following the
@@ -13190,7 +13401,7 @@ struct Fts5ExtensionApi {
13401
** argument passed to this function is a pointer to an Fts5Tokenizer object
13402
** returned by an earlier call to xCreate().
13403
**
13193
-** The second argument indicates the reason that FTS5 is requesting
13404
+** The third argument indicates the reason that FTS5 is requesting
13405
** tokenization of the supplied text. This is always one of the following
13406
** four values:
13407
**
@@ -13214,6 +13425,13 @@ struct Fts5ExtensionApi {
13425
** on a columnsize=0 database.
13426
** </ul>
13427
**
13428
+** The sixth and seventh arguments passed to xTokenize() - pLocale and
13429
+** nLocale - are a pointer to a buffer containing the locale to use for
13430
+** tokenization (e.g. "en_US") and its size in bytes, respectively. The
13431
+** pLocale buffer is not nul-terminated. pLocale may be passed NULL (in
13432
+** which case nLocale is always 0) to indicate that the tokenizer should
13433
+** use its default locale.
13434
+**
13435
** For each token in the input string, the supplied callback xToken() must
13436
** be invoked. The first argument to it should be a copy of the pointer
13437
** passed as the second argument to xTokenize(). The third and fourth
@@ -13237,6 +13455,30 @@ struct Fts5ExtensionApi {
13455
** may abandon the tokenization and return any error code other than
13456
** SQLITE_OK or SQLITE_DONE.
13457
**
13458
+** If the tokenizer is registered using an fts5_tokenizer_v2 object,
13459
+** then the xTokenize() method has two additional arguments - pLocale
13460
+** and nLocale. These specify the locale that the tokenizer should use
13461
+** for the current request. If pLocale and nLocale are both 0, then the
13462
+** tokenizer should use its default locale. Otherwise, pLocale points to
13463
+** an nLocale byte buffer containing the name of the locale to use as utf-8
13464
+** text. pLocale is not nul-terminated.
13465
+**
13466
+** FTS5_TOKENIZER
13467
+**
13468
+** There is also an fts5_tokenizer object. This is an older, deprecated,
13469
+** version of fts5_tokenizer_v2. It is similar except that:
13470
+**
13471
+** <ul>
13472
+** <li> There is no "iVersion" field, and
13473
+** <li> The xTokenize() method does not take a locale argument.
13474
+** </ul>
13475
+**
13476
+** Legacy fts5_tokenizer tokenizers must be registered using the
13477
+** legacy xCreateTokenizer() function, instead of xCreateTokenizer_v2().
13478
+**
13479
+** Tokenizer implementations registered using either API may be retrieved
13480
+** using both xFindTokenizer() and xFindTokenizer_v2().
13481
+**
13482
** SYNONYM SUPPORT
13483
**
13484
** Custom tokenizers may also support synonyms. Consider a case in which a
@@ -13345,6 +13587,33 @@ struct Fts5ExtensionApi {
13587
** inefficient.
13588
*/
13589
typedef struct Fts5Tokenizer Fts5Tokenizer;
13590
+typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2;
13591
+struct fts5_tokenizer_v2 {
13592
+ int iVersion; /* Currently always 2 */
13593
+
13594
+ int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
13595
+ void (*xDelete)(Fts5Tokenizer*);
13596
+ int (*xTokenize)(Fts5Tokenizer*,
13597
+ void *pCtx,
13598
+ int flags, /* Mask of FTS5_TOKENIZE_* flags */
13599
+ const char *pText, int nText,
13600
+ const char *pLocale, int nLocale,
13601
+ int (*xToken)(
13602
+ void *pCtx, /* Copy of 2nd argument to xTokenize() */
13603
+ int tflags, /* Mask of FTS5_TOKEN_* flags */
13604
+ const char *pToken, /* Pointer to buffer containing token */
13605
+ int nToken, /* Size of token in bytes */
13606
+ int iStart, /* Byte offset of token within input text */
13607
+ int iEnd /* Byte offset of end of token within input text */
13608
+ )
13609
+ );
13610
+};
13611
+
13612
+/*
13613
+** New code should use the fts5_tokenizer_v2 type to define tokenizer
13614
+** implementations. The following type is included for legacy applications
13615
+** that still use it.
13616
+*/
13617
typedef struct fts5_tokenizer fts5_tokenizer;
13618
struct fts5_tokenizer {
13619
int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
@@ -13364,6 +13633,7 @@ struct fts5_tokenizer {
13633
);
13634
};
13635
13636
+
13637
/* Flags that may be passed as the third argument to xTokenize() */
13638
#define FTS5_TOKENIZE_QUERY 0x0001
13639
#define FTS5_TOKENIZE_PREFIX 0x0002
@@ -13383,7 +13653,7 @@ struct fts5_tokenizer {
13653
*/
13654
typedef struct fts5_api fts5_api;
13655
struct fts5_api {
13386
- int iVersion; /* Currently always set to 2 */
13656
+ int iVersion; /* Currently always set to 3 */
13657
13658
/* Create a new tokenizer */
13659
int (*xCreateTokenizer)(
@@ -13410,6 +13680,25 @@ struct fts5_api {
13680
fts5_extension_function xFunction,
13681
void (*xDestroy)(void*)
13682
);
13683
+
13684
+ /* APIs below this point are only available if iVersion>=3 */
13685
+
13686
+ /* Create a new tokenizer */
13687
+ int (*xCreateTokenizer_v2)(
13688
+ fts5_api *pApi,
13689
+ const char *zName,
13690
+ void *pUserData,
13691
+ fts5_tokenizer_v2 *pTokenizer,
13692
+ void (*xDestroy)(void*)
13693
+ );
13694
+
13695
+ /* Find an existing tokenizer */
13696
+ int (*xFindTokenizer_v2)(
13697
+ fts5_api *pApi,
13698
+ const char *zName,
13699
+ void **ppUserData,
13700
+ fts5_tokenizer_v2 **ppTokenizer
13701
+ );
13702
};
13703
13704
/*
@@ -13423,3 +13712,4 @@ struct fts5_api {
13712
#endif /* _FTS5_H */
13713
13714
/******** End of fts5.h *********/
13715
+#endif /* SQLITE3_H */