Fossil SCM
Update the built-in SQLite to the latest 3.53.0 beta for SQLite testing.
Commit
ad59a046cb820c51b0fa85bd86a515c69eba32118a5587ba8d578e8ba8df997c
Parent
adb68404e610682…
2 files changed
+918
-190
+284
-48
+918
-190
| --- extsrc/sqlite3.c | ||
| +++ extsrc/sqlite3.c | ||
| @@ -16,11 +16,11 @@ | ||
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | -** c5af6a10245b6b847d30002806c1577b020c with changes in files: | |
| 21 | +** 7bc1d0c4572f126cfe68fa51fe992d2bd46b with changes in files: | |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| @@ -467,14 +467,14 @@ | ||
| 467 | 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | 469 | */ |
| 470 | 470 | #define SQLITE_VERSION "3.53.0" |
| 471 | 471 | #define SQLITE_VERSION_NUMBER 3053000 |
| 472 | -#define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c" | |
| 472 | +#define SQLITE_SOURCE_ID "2026-04-01 11:54:20 7bc1d0c4572f126cfe68fa51fe992d2bd46b1e57c04721991bd5fad36dd795c5" | |
| 473 | 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | 474 | #define SQLITE_SCM_TAGS "" |
| 475 | -#define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z" | |
| 475 | +#define SQLITE_SCM_DATETIME "2026-04-01T11:54:20.065Z" | |
| 476 | 476 | |
| 477 | 477 | /* |
| 478 | 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | 480 | ** |
| @@ -897,11 +897,11 @@ | ||
| 897 | 897 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 898 | 898 | #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) |
| 899 | 899 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 900 | 900 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 901 | 901 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 902 | -#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ | |
| 902 | +#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal only */ | |
| 903 | 903 | |
| 904 | 904 | /* |
| 905 | 905 | ** CAPI3REF: Flags For File Open Operations |
| 906 | 906 | ** |
| 907 | 907 | ** These bit values are intended for use in the |
| @@ -1609,10 +1609,16 @@ | ||
| 1609 | 1609 | /* deprecated names */ |
| 1610 | 1610 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1611 | 1611 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1612 | 1612 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| 1613 | 1613 | |
| 1614 | +/* reserved file-control numbers: | |
| 1615 | +** 101 | |
| 1616 | +** 102 | |
| 1617 | +** 103 | |
| 1618 | +*/ | |
| 1619 | + | |
| 1614 | 1620 | |
| 1615 | 1621 | /* |
| 1616 | 1622 | ** CAPI3REF: Mutex Handle |
| 1617 | 1623 | ** |
| 1618 | 1624 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2030,11 +2036,12 @@ | ||
| 2030 | 2036 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 2031 | 2037 | ** The exceptional configuration options that may be invoked at any time |
| 2032 | 2038 | ** are called "anytime configuration options". |
| 2033 | 2039 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 2034 | 2040 | ** [sqlite3_shutdown()] with a first argument that is not an anytime |
| 2035 | -** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE. | |
| 2041 | +** configuration option, then the sqlite3_config() call will | |
| 2042 | +** return SQLITE_MISUSE. | |
| 2036 | 2043 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 2037 | 2044 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 2038 | 2045 | ** |
| 2039 | 2046 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 2040 | 2047 | ** ^If the option is unknown or SQLite is unable to set the option |
| @@ -2596,13 +2603,14 @@ | ||
| 2596 | 2603 | ** <li><P>The second argument ("sz") is the |
| 2597 | 2604 | ** size of each lookaside buffer slot. Lookaside is disabled if "sz" |
| 2598 | 2605 | ** is less than 8. The "sz" argument should be a multiple of 8 less than |
| 2599 | 2606 | ** 65536. If "sz" does not meet this constraint, it is reduced in size until |
| 2600 | 2607 | ** it does. |
| 2601 | -** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled | |
| 2602 | -** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so | |
| 2603 | -** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" | |
| 2608 | +** <li><p>The third argument ("cnt") is the number of slots. | |
| 2609 | +** Lookaside is disabled if "cnt"is less than 1. | |
| 2610 | +* The "cnt" value will be reduced, if necessary, so | |
| 2611 | +** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" | |
| 2604 | 2612 | ** parameter is usually chosen so that the product of "sz" and "cnt" is less |
| 2605 | 2613 | ** than 1,000,000. |
| 2606 | 2614 | ** </ol> |
| 2607 | 2615 | ** <p>If the "buf" argument is not NULL, then it must |
| 2608 | 2616 | ** point to a memory buffer with a size that is greater than |
| @@ -2977,11 +2985,11 @@ | ||
| 2977 | 2985 | ** default value 17, as of SQLite version 3.52.0. The value was 15 in all |
| 2978 | 2986 | ** prior versions.<p> |
| 2979 | 2987 | ** This option takes two arguments which are an integer and a pointer |
| 2980 | 2988 | ** to an integer. The first argument is a small integer, between 3 and 23, or |
| 2981 | 2989 | ** zero. The FP_DIGITS setting is changed to that small integer, or left |
| 2982 | -** unaltered if the first argument is zero or out of range. The second argument | |
| 2990 | +** unaltered if the first argument is zero or out of range. The second argument | |
| 2983 | 2991 | ** is a pointer to an integer. If the pointer is not NULL, then the value of |
| 2984 | 2992 | ** the FP_DIGITS setting, after possibly being modified by the first |
| 2985 | 2993 | ** arguments, is written into the integer to which the second argument points. |
| 2986 | 2994 | ** </dd> |
| 2987 | 2995 | ** |
| @@ -2989,14 +2997,16 @@ | ||
| 2989 | 2997 | ** |
| 2990 | 2998 | ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3> |
| 2991 | 2999 | ** |
| 2992 | 3000 | ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the |
| 2993 | 3001 | ** overall call to [sqlite3_db_config()] has a total of four parameters. |
| 2994 | -** The first argument (the third parameter to sqlite3_db_config()) is an integer. | |
| 2995 | -** The second argument is a pointer to an integer. If the first argument is 1, | |
| 2996 | -** then the option becomes enabled. If the first integer argument is 0, then the | |
| 2997 | -** option is disabled. If the first argument is -1, then the option setting | |
| 3002 | +** The first argument (the third parameter to sqlite3_db_config()) is | |
| 3003 | +** an integer. | |
| 3004 | +** The second argument is a pointer to an integer. If the first argument is 1, | |
| 3005 | +** then the option becomes enabled. If the first integer argument is 0, | |
| 3006 | +** then the option is disabled. | |
| 3007 | +** If the first argument is -1, then the option setting | |
| 2998 | 3008 | ** is unchanged. The second argument, the pointer to an integer, may be NULL. |
| 2999 | 3009 | ** If the second argument is not NULL, then a value of 0 or 1 is written into |
| 3000 | 3010 | ** the integer to which the second argument points, depending on whether the |
| 3001 | 3011 | ** setting is disabled or enabled after applying any changes specified by |
| 3002 | 3012 | ** the first argument. |
| @@ -6169,12 +6179,13 @@ | ||
| 6169 | 6179 | ** that the application-defined collating sequence created expects its |
| 6170 | 6180 | ** input strings to be in UTF16 in native byte order, and that the start |
| 6171 | 6181 | ** of the strings must be aligned to a 2-byte boundary. |
| 6172 | 6182 | ** |
| 6173 | 6183 | ** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be |
| 6174 | -** used to specify the text encoding to strings input to [sqlite3_result_text64()] | |
| 6175 | -** and [sqlite3_bind_text64()]. It means that the input string (call it "z") | |
| 6184 | +** used to specify the text encoding to strings input to | |
| 6185 | +** [sqlite3_result_text64()] and [sqlite3_bind_text64()]. | |
| 6186 | +** The SQLITE_UTF8_ZT encoding means that the input string (call it "z") | |
| 6176 | 6187 | ** is UTF-8 encoded and that it is zero-terminated. If the length parameter |
| 6177 | 6188 | ** (call it "n") is non-negative, this encoding option means that the caller |
| 6178 | 6189 | ** guarantees that z array contains at least n+1 bytes and that the z[n] |
| 6179 | 6190 | ** byte has a value of zero. |
| 6180 | 6191 | ** This option gives the same output as SQLITE_UTF8, but can be more efficient |
| @@ -6422,30 +6433,26 @@ | ||
| 6422 | 6433 | ** |
| 6423 | 6434 | ** These routines must be called from the same thread as |
| 6424 | 6435 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 6425 | 6436 | ** |
| 6426 | 6437 | ** As long as the input parameter is correct, these routines can only |
| 6427 | -** fail if an out-of-memory error occurs during a format conversion. | |
| 6428 | -** Only the following subset of interfaces are subject to out-of-memory | |
| 6429 | -** errors: | |
| 6430 | -** | |
| 6431 | -** <ul> | |
| 6432 | -** <li> sqlite3_value_blob() | |
| 6433 | -** <li> sqlite3_value_text() | |
| 6434 | -** <li> sqlite3_value_text16() | |
| 6435 | -** <li> sqlite3_value_text16le() | |
| 6436 | -** <li> sqlite3_value_text16be() | |
| 6437 | -** <li> sqlite3_value_bytes() | |
| 6438 | -** <li> sqlite3_value_bytes16() | |
| 6439 | -** </ul> | |
| 6440 | -** | |
| 6438 | +** fail if an out-of-memory error occurs while trying to do a | |
| 6439 | +** UTF8→UTF16 or UTF16→UTF8 conversion. | |
| 6441 | 6440 | ** If an out-of-memory error occurs, then the return value from these |
| 6442 | 6441 | ** routines is the same as if the column had contained an SQL NULL value. |
| 6443 | -** Valid SQL NULL returns can be distinguished from out-of-memory errors | |
| 6444 | -** by invoking the [sqlite3_errcode()] immediately after the suspect | |
| 6442 | +** If the input sqlite3_value was not obtained from [sqlite3_value_dup()], | |
| 6443 | +** then valid SQL NULL returns can also be distinguished from | |
| 6444 | +** out-of-memory errors after extracting the value | |
| 6445 | +** by invoking the [sqlite3_errcode()] immediately after the suspicious | |
| 6445 | 6446 | ** return value is obtained and before any |
| 6446 | 6447 | ** other SQLite interface is called on the same [database connection]. |
| 6448 | +** If the input sqlite3_value was obtained from sqlite3_value_dup() then | |
| 6449 | +** it is disconnected from the database connection and so sqlite3_errcode() | |
| 6450 | +** will not work. | |
| 6451 | +** In that case, the only way to distinguish an out-of-memory | |
| 6452 | +** condition from a true SQL NULL is to invoke sqlite3_value_type() on the | |
| 6453 | +** input to see if it is NULL prior to trying to extract the value. | |
| 6447 | 6454 | */ |
| 6448 | 6455 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 6449 | 6456 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 6450 | 6457 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 6451 | 6458 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| @@ -6468,11 +6475,12 @@ | ||
| 6468 | 6475 | ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
| 6469 | 6476 | ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding |
| 6470 | 6477 | ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
| 6471 | 6478 | ** returns something other than SQLITE_TEXT, then the return value from |
| 6472 | 6479 | ** sqlite3_value_encoding(X) is meaningless. ^Calls to |
| 6473 | -** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)], | |
| 6480 | +** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], | |
| 6481 | +** [sqlite3_value_text16be(X)], | |
| 6474 | 6482 | ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or |
| 6475 | 6483 | ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and |
| 6476 | 6484 | ** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
| 6477 | 6485 | ** |
| 6478 | 6486 | ** This routine is intended for used by applications that test and validate |
| @@ -6599,21 +6607,21 @@ | ||
| 6599 | 6607 | ** associate auxiliary data with argument values. If the same argument |
| 6600 | 6608 | ** value is passed to multiple invocations of the same SQL function during |
| 6601 | 6609 | ** query execution, under some circumstances the associated auxiliary data |
| 6602 | 6610 | ** might be preserved. An example of where this might be useful is in a |
| 6603 | 6611 | ** regular-expression matching function. The compiled version of the regular |
| 6604 | -** expression can be stored as auxiliary data associated with the pattern string. | |
| 6605 | -** Then as long as the pattern string remains the same, | |
| 6612 | +** expression can be stored as auxiliary data associated with the pattern | |
| 6613 | +** string. Then as long as the pattern string remains the same, | |
| 6606 | 6614 | ** the compiled regular expression can be reused on multiple |
| 6607 | 6615 | ** invocations of the same function. |
| 6608 | 6616 | ** |
| 6609 | -** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data | |
| 6610 | -** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument | |
| 6611 | -** value to the application-defined function. ^N is zero for the left-most | |
| 6612 | -** function argument. ^If there is no auxiliary data | |
| 6613 | -** associated with the function argument, the sqlite3_get_auxdata(C,N) interface | |
| 6614 | -** returns a NULL pointer. | |
| 6617 | +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary | |
| 6618 | +** data associated by the sqlite3_set_auxdata(C,N,P,X) function with the | |
| 6619 | +** Nth argument value to the application-defined function. ^N is zero | |
| 6620 | +** for the left-most function argument. ^If there is no auxiliary data | |
| 6621 | +** associated with the function argument, the sqlite3_get_auxdata(C,N) | |
| 6622 | +** interface returns a NULL pointer. | |
| 6615 | 6623 | ** |
| 6616 | 6624 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the |
| 6617 | 6625 | ** N-th argument of the application-defined function. ^Subsequent |
| 6618 | 6626 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| 6619 | 6627 | ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or |
| @@ -10722,21 +10730,22 @@ | ||
| 10722 | 10730 | ** |
| 10723 | 10731 | ** <table border=1 cellspacing=0 cellpadding=10 width="90%"> |
| 10724 | 10732 | ** <tr> |
| 10725 | 10733 | ** <td valign="top">sqlite3_vtab_distinct() return value |
| 10726 | 10734 | ** <td valign="top">Rows are returned in aOrderBy order |
| 10727 | -** <td valign="top">Rows with the same value in all aOrderBy columns are adjacent | |
| 10735 | +** <td valign="top">Rows with the same value in all aOrderBy columns are | |
| 10736 | +** adjacent | |
| 10728 | 10737 | ** <td valign="top">Duplicates over all colUsed columns may be omitted |
| 10729 | 10738 | ** <tr><td>0<td>yes<td>yes<td>no |
| 10730 | 10739 | ** <tr><td>1<td>no<td>yes<td>no |
| 10731 | 10740 | ** <tr><td>2<td>no<td>yes<td>yes |
| 10732 | 10741 | ** <tr><td>3<td>yes<td>yes<td>yes |
| 10733 | 10742 | ** </table> |
| 10734 | 10743 | ** |
| 10735 | 10744 | ** ^For the purposes of comparing virtual table output values to see if the |
| 10736 | -** values are the same value for sorting purposes, two NULL values are considered | |
| 10737 | -** to be the same. In other words, the comparison operator is "IS" | |
| 10745 | +** values are the same value for sorting purposes, two NULL values are | |
| 10746 | +** considered to be the same. In other words, the comparison operator is "IS" | |
| 10738 | 10747 | ** (or "IS NOT DISTINCT FROM") and not "==". |
| 10739 | 10748 | ** |
| 10740 | 10749 | ** If a virtual table implementation is unable to meet the requirements |
| 10741 | 10750 | ** specified above, then it must not set the "orderByConsumed" flag in the |
| 10742 | 10751 | ** [sqlite3_index_info] object or an incorrect answer may result. |
| @@ -11586,16 +11595,17 @@ | ||
| 11586 | 11595 | /* |
| 11587 | 11596 | ** CAPI3REF: Bind array values to the CARRAY table-valued function |
| 11588 | 11597 | ** |
| 11589 | 11598 | ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to |
| 11590 | 11599 | ** parameter that is the first argument of the [carray() table-valued function]. |
| 11591 | -** The S parameter is a pointer to the [prepared statement] that uses the carray() | |
| 11592 | -** functions. I is the parameter index to be bound. I must be the index of the | |
| 11593 | -** parameter that is the first argument to the carray() table-valued function. | |
| 11594 | -** P is a pointer to the array to be bound, and N is the number of elements in | |
| 11595 | -** the array. The F argument is one of constants [SQLITE_CARRAY_INT32], | |
| 11596 | -** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], | |
| 11600 | +** The S parameter is a pointer to the [prepared statement] that uses the | |
| 11601 | +** carray() functions. I is the parameter index to be bound. I must be the | |
| 11602 | +** index of the parameter that is the first argument to the carray() | |
| 11603 | +** table-valued function. P is a pointer to the array to be bound, and N | |
| 11604 | +** is the number of elements in the array. The F argument is one of | |
| 11605 | +** constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64], | |
| 11606 | +** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], | |
| 11597 | 11607 | ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P. |
| 11598 | 11608 | ** |
| 11599 | 11609 | ** If the X argument is not a NULL pointer or one of the special |
| 11600 | 11610 | ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke |
| 11601 | 11611 | ** the function X with argument D when it is finished using the data in P. |
| @@ -13648,10 +13658,236 @@ | ||
| 13648 | 13658 | |
| 13649 | 13659 | /* |
| 13650 | 13660 | ** CAPI3REF: Values for sqlite3session_config(). |
| 13651 | 13661 | */ |
| 13652 | 13662 | #define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 13663 | + | |
| 13664 | +/* | |
| 13665 | +** CAPI3REF: Configure a changegroup object | |
| 13666 | +** | |
| 13667 | +** Configure the changegroup object passed as the first argument. | |
| 13668 | +** At present the only valid value for the second parameter is | |
| 13669 | +** [SQLITE_CHANGEGROUP_CONFIG_PATCHSET]. | |
| 13670 | +*/ | |
| 13671 | +SQLITE_API int sqlite3changegroup_config(sqlite3_changegroup*, int, void *pArg); | |
| 13672 | + | |
| 13673 | +/* | |
| 13674 | +** CAPI3REF: Options for sqlite3changegroup_config(). | |
| 13675 | +** | |
| 13676 | +** The following values may be passed as the 2nd parameter to | |
| 13677 | +** sqlite3changegroup_config(). | |
| 13678 | +** | |
| 13679 | +** <dt>SQLITE_CHANGEGROUP_CONFIG_PATCHSET <dd> | |
| 13680 | +** A changegroup object generates either a changeset or patchset. Usually, | |
| 13681 | +** this is determined by whether the first call to sqlite3changegroup_add() | |
| 13682 | +** is passed a changeset or a patchset. Or, if the first changes are added | |
| 13683 | +** to the changegroup object using the sqlite3changegroup_change_xxx() | |
| 13684 | +** APIs, then this option may be used to configure whether the changegroup | |
| 13685 | +** object generates a changeset or patchset. | |
| 13686 | +** | |
| 13687 | +** When this option is invoked, parameter pArg must point to a value of | |
| 13688 | +** type int. If the changegroup currently contains zero changes, and the | |
| 13689 | +** value of the int variable is zero or greater than zero, then the | |
| 13690 | +** changegroup is configured to generate a changeset or patchset, | |
| 13691 | +** respectively. It is a no-op, not an error, if the changegroup is not | |
| 13692 | +** configured because it has already started accumulating changes. | |
| 13693 | +** | |
| 13694 | +** Before returning, the int variable is set to 0 if the changegroup is | |
| 13695 | +** configured to generate a changeset, or 1 if it is configured to generate | |
| 13696 | +** a patchset. | |
| 13697 | +*/ | |
| 13698 | +#define SQLITE_CHANGEGROUP_CONFIG_PATCHSET 1 | |
| 13699 | + | |
| 13700 | + | |
| 13701 | +/* | |
| 13702 | +** CAPI3REF: Begin adding a change to a changegroup | |
| 13703 | +** | |
| 13704 | +** This API is used, in concert with other sqlite3changegroup_change_xxx() | |
| 13705 | +** APIs, to add changes to a changegroup object one at a time. To add a | |
| 13706 | +** single change, the caller must: | |
| 13707 | +** | |
| 13708 | +** 1. Invoke sqlite3changegroup_change_begin() to indicate the type of | |
| 13709 | +** change (INSERT, UPDATE or DELETE), the affected table and whether | |
| 13710 | +** or not the change should be marked as indirect. | |
| 13711 | +** | |
| 13712 | +** 2. Invoke sqlite3changegroup_change_int64() or one of the other four | |
| 13713 | +** value functions - _null(), _double(), _text() or _blob() - one or | |
| 13714 | +** more times to specify old.* and new.* values for the change being | |
| 13715 | +** constructed. | |
| 13716 | +** | |
| 13717 | +** 3. Invoke sqlite3changegroup_change_finish() to either finish adding | |
| 13718 | +** the change to the group, or to discard the change altogether. | |
| 13719 | +** | |
| 13720 | +** The first argument to this function must be a pointer to the existing | |
| 13721 | +** changegroup object that the change will be added to. The second argument | |
| 13722 | +** must be SQLITE_INSERT, SQLITE_UPDATE or SQLITE_DELETE. The third is the | |
| 13723 | +** name of the table that the change affects, and the fourth is a boolean | |
| 13724 | +** flag specifying whether the change should be marked as "indirect" (if | |
| 13725 | +** bIndirect is non-zero) or not indirect (if bIndirect is zero). | |
| 13726 | +** | |
| 13727 | +** Following a successful call to this function, this function may not be | |
| 13728 | +** called again on the same changegroup object until after | |
| 13729 | +** sqlite3changegroup_change_finish() has been called. Doing so is an | |
| 13730 | +** SQLITE_MISUSE error. | |
| 13731 | +** | |
| 13732 | +** The changegroup object passed as the first argument must be already | |
| 13733 | +** configured with schema data for the specified table. It may be configured | |
| 13734 | +** either by calling sqlite3changegroup_schema() with a database that contains | |
| 13735 | +** the table, or sqlite3changegroup_add() with a changeset that contains the | |
| 13736 | +** table. If the changegroup object has not been configured with a schema for | |
| 13737 | +** the specified table when this function is called, SQLITE_ERROR is returned. | |
| 13738 | +** | |
| 13739 | +** If successful, SQLITE_OK is returned. Otherwise, if an error occurs, an | |
| 13740 | +** SQLite error code is returned. In this case, if argument pzErr is non-NULL, | |
| 13741 | +** then (*pzErr) may be set to point to a buffer containing a utf-8 formated, | |
| 13742 | +** nul-terminated, English language error message. It is the responsibility | |
| 13743 | +** of the caller to eventually free this buffer using sqlite3_free(). | |
| 13744 | +*/ | |
| 13745 | +SQLITE_API int sqlite3changegroup_change_begin( | |
| 13746 | + sqlite3_changegroup*, | |
| 13747 | + int eOp, | |
| 13748 | + const char *zTab, | |
| 13749 | + int bIndirect, | |
| 13750 | + char **pzErr | |
| 13751 | +); | |
| 13752 | + | |
| 13753 | +/* | |
| 13754 | +** CAPI3REF: Add a 64-bit integer to a changegroup | |
| 13755 | +** | |
| 13756 | +** This function may only be called between a successful call to | |
| 13757 | +** sqlite3changegroup_change_begin() and its matching | |
| 13758 | +** sqlite3changegroup_change_finish() call. If it is called at any | |
| 13759 | +** other time, it is an SQLITE_MISUSE error. Calling this function | |
| 13760 | +** specifies a 64-bit integer value to be used in the change currently being | |
| 13761 | +** added to the changegroup object passed as the first argument. | |
| 13762 | +** | |
| 13763 | +** The second parameter, bNew, specifies whether the value is to be part of | |
| 13764 | +** the new.* (if bNew is non-zero) or old.* (if bNew is zero) record of | |
| 13765 | +** the change under construction. If this does not match the type of change | |
| 13766 | +** specified by the preceding call to sqlite3changegroup_change_begin() (i.e. | |
| 13767 | +** an old.* value for an SQLITE_INSERT change, or a new.* value for an | |
| 13768 | +** SQLITE_DELETE), then SQLITE_ERROR is returned. | |
| 13769 | +** | |
| 13770 | +** The third parameter specifies the column of the old.* or new.* record that | |
| 13771 | +** the value will be a part of. If the specified table has an explicit primary | |
| 13772 | +** key, then this is the index of the table column, numbered from 0 in the order | |
| 13773 | +** specified within the CREATE TABLE statement. Or, if the table uses an | |
| 13774 | +** implicit rowid key, then the column 0 is the rowid and the explicit columns | |
| 13775 | +** are numbered starting from 1. If the iCol parameter is less than 0 or greater | |
| 13776 | +** than the index of the last column in the table, SQLITE_RANGE is returned. | |
| 13777 | +** | |
| 13778 | +** The fourth parameter is the integer value to use as part of the old.* or | |
| 13779 | +** new.* record. | |
| 13780 | +** | |
| 13781 | +** If this call is successful, SQLITE_OK is returned. Otherwise, if an | |
| 13782 | +** error occurs, an SQLite error code is returned. | |
| 13783 | +*/ | |
| 13784 | +SQLITE_API int sqlite3changegroup_change_int64( | |
| 13785 | + sqlite3_changegroup*, | |
| 13786 | + int bNew, | |
| 13787 | + int iCol, | |
| 13788 | + sqlite3_int64 iVal | |
| 13789 | +); | |
| 13790 | + | |
| 13791 | +/* | |
| 13792 | +** CAPI3REF: Add a NULL to a changegroup | |
| 13793 | +** | |
| 13794 | +** This function is similar to sqlite3changegroup_change_int64(). Except that | |
| 13795 | +** it configures the change currently under construction with a NULL value | |
| 13796 | +** instead of a 64-bit integer. | |
| 13797 | +*/ | |
| 13798 | +SQLITE_API int sqlite3changegroup_change_null(sqlite3_changegroup*, int, int); | |
| 13799 | + | |
| 13800 | +/* | |
| 13801 | +** CAPI3REF: Add an double to a changegroup | |
| 13802 | +** | |
| 13803 | +** This function is similar to sqlite3changegroup_change_int64(). Except that | |
| 13804 | +** it configures the change currently being constructed with a real value | |
| 13805 | +** instead of a 64-bit integer. | |
| 13806 | +*/ | |
| 13807 | +SQLITE_API int sqlite3changegroup_change_double(sqlite3_changegroup*, int, int, double); | |
| 13808 | + | |
| 13809 | +/* | |
| 13810 | +** CAPI3REF: Add a text value to a changegroup | |
| 13811 | +** | |
| 13812 | +** This function is similar to sqlite3changegroup_change_int64(). It configures | |
| 13813 | +** the currently accumulated change with a text value instead of a 64-bit | |
| 13814 | +** integer. Parameter pVal points to a buffer containing the text encoded using | |
| 13815 | +** utf-8. Parameter nVal may either be the size of the text value in bytes, or | |
| 13816 | +** else a negative value, in which case the buffer pVal points to is assumed to | |
| 13817 | +** be nul-terminated. | |
| 13818 | +*/ | |
| 13819 | +SQLITE_API int sqlite3changegroup_change_text( | |
| 13820 | + sqlite3_changegroup*, int, int, const char *pVal, int nVal | |
| 13821 | +); | |
| 13822 | + | |
| 13823 | +/* | |
| 13824 | +** CAPI3REF: Add a blob to a changegroup | |
| 13825 | +** | |
| 13826 | +** This function is similar to sqlite3changegroup_change_int64(). It configures | |
| 13827 | +** the currently accumulated change with a blob value instead of a 64-bit | |
| 13828 | +** integer. Parameter pVal points to a buffer containing the blob. Parameter | |
| 13829 | +** nVal is the size of the blob in bytes. | |
| 13830 | +*/ | |
| 13831 | +SQLITE_API int sqlite3changegroup_change_blob( | |
| 13832 | + sqlite3_changegroup*, int, int, const void *pVal, int nVal | |
| 13833 | +); | |
| 13834 | + | |
| 13835 | +/* | |
| 13836 | +** CAPI3REF: Finish adding one-at-at-time changes to a changegroup | |
| 13837 | +** | |
| 13838 | +** This function may only be called following a successful call to | |
| 13839 | +** sqlite3changegroup_change_begin(). Otherwise, it is an SQLITE_MISUSE error. | |
| 13840 | +** | |
| 13841 | +** If parameter bDiscard is non-zero, then the current change is simply | |
| 13842 | +** discarded. In this case this function is always successful and SQLITE_OK | |
| 13843 | +** returned. | |
| 13844 | +** | |
| 13845 | +** If parameter bDiscard is zero, then an attempt is made to add the current | |
| 13846 | +** change to the changegroup. Assuming the changegroup is configured to | |
| 13847 | +** produce a changeset (not a patchset), this requires that: | |
| 13848 | +** | |
| 13849 | +** * If the change is an INSERT or DELETE, then a value must be specified | |
| 13850 | +** for all columns of the new.* or old.* record, respectively. | |
| 13851 | +** | |
| 13852 | +** * If the change is an UPDATE record, then values must be provided for | |
| 13853 | +** the PRIMARY KEY columns of the old.* record, but must not be provided | |
| 13854 | +** for PRIMARY KEY columns of the new.* record. | |
| 13855 | +** | |
| 13856 | +** * If the change is an UPDATE record, then for each non-PRIMARY KEY | |
| 13857 | +** column in the old.* record for which a value has been provided, a | |
| 13858 | +** value must also be provided for the same column in the new.* record. | |
| 13859 | +** Similarly, for each non-PK column in the old.* record for which | |
| 13860 | +** a value is not provided, a value must not be provided for the same | |
| 13861 | +** column in the new.* record. | |
| 13862 | +** | |
| 13863 | +** * All values specified for PRIMARY KEY columns must be non-NULL. | |
| 13864 | +** | |
| 13865 | +** Otherwise, it is an error. | |
| 13866 | +** | |
| 13867 | +** If the changegroup already contains a change for the same row (identified | |
| 13868 | +** by PRIMARY KEY columns), then the current change is combined with the | |
| 13869 | +** existing change in the same way as for sqlite3changegroup_add(). | |
| 13870 | +** | |
| 13871 | +** For a patchset, all of the above rules apply except that it doesn't matter | |
| 13872 | +** whether or not values are provided for the non-PK old.* record columns | |
| 13873 | +** for an UPDATE or DELETE change. This means that code used to produce | |
| 13874 | +** a changeset using the sqlite3changegroup_change_xxx() APIs may also | |
| 13875 | +** be used to produce patchsets. | |
| 13876 | +** | |
| 13877 | +** If the call is successful, SQLITE_OK is returned. Otherwise, if an error | |
| 13878 | +** occurs, an SQLite error code is returned. If an error is returned and | |
| 13879 | +** parameter pzErr is not NULL, then (*pzErr) may be set to point to a buffer | |
| 13880 | +** containing a nul-terminated, utf-8 encoded, English language error message. | |
| 13881 | +** It is the responsibility of the caller to eventually free any such error | |
| 13882 | +** message buffer using sqlite3_free(). | |
| 13883 | +*/ | |
| 13884 | +SQLITE_API int sqlite3changegroup_change_finish( | |
| 13885 | + sqlite3_changegroup*, | |
| 13886 | + int bDiscard, | |
| 13887 | + char **pzErr | |
| 13888 | +); | |
| 13653 | 13889 | |
| 13654 | 13890 | /* |
| 13655 | 13891 | ** Make sure we can call this stuff from C++. |
| 13656 | 13892 | */ |
| 13657 | 13893 | #if 0 |
| @@ -21585,21 +21821,26 @@ | ||
| 21585 | 21821 | int nArg; /* Total number of arguments */ |
| 21586 | 21822 | int nUsed; /* Number of arguments used so far */ |
| 21587 | 21823 | sqlite3_value **apArg; /* The argument values */ |
| 21588 | 21824 | }; |
| 21589 | 21825 | |
| 21826 | +/* | |
| 21827 | +** Maxium number of base-10 digits in an unsigned 64-bit integer | |
| 21828 | +*/ | |
| 21829 | +#define SQLITE_U64_DIGITS 20 | |
| 21830 | + | |
| 21590 | 21831 | /* |
| 21591 | 21832 | ** An instance of this object receives the decoding of a floating point |
| 21592 | 21833 | ** value into an approximate decimal representation. |
| 21593 | 21834 | */ |
| 21594 | 21835 | struct FpDecode { |
| 21595 | - int n; /* Significant digits in the decode */ | |
| 21596 | - int iDP; /* Location of the decimal point */ | |
| 21597 | - char *z; /* Start of significant digits */ | |
| 21598 | - char zBuf[20]; /* Storage for significant digits */ | |
| 21599 | - char sign; /* '+' or '-' */ | |
| 21600 | - char isSpecial; /* 1: Infinity 2: NaN */ | |
| 21836 | + int n; /* Significant digits in the decode */ | |
| 21837 | + int iDP; /* Location of the decimal point */ | |
| 21838 | + char *z; /* Start of significant digits */ | |
| 21839 | + char zBuf[SQLITE_U64_DIGITS+1]; /* Storage for significant digits */ | |
| 21840 | + char sign; /* '+' or '-' */ | |
| 21841 | + char isSpecial; /* 1: Infinity 2: NaN */ | |
| 21601 | 21842 | }; |
| 21602 | 21843 | |
| 21603 | 21844 | SQLITE_PRIVATE void sqlite3FpDecode(FpDecode*,double,int,int); |
| 21604 | 21845 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 21605 | 21846 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| @@ -22283,10 +22524,11 @@ | ||
| 22283 | 22524 | SQLITE_PRIVATE char *sqlite3RCStrNew(u64); |
| 22284 | 22525 | SQLITE_PRIVATE char *sqlite3RCStrResize(char*,u64); |
| 22285 | 22526 | |
| 22286 | 22527 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| 22287 | 22528 | SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64); |
| 22529 | +SQLITE_PRIVATE int sqlite3StrAccumEnlargeIfNeeded(StrAccum*, i64); | |
| 22288 | 22530 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 22289 | 22531 | SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8); |
| 22290 | 22532 | SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); |
| 22291 | 22533 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 22292 | 22534 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| @@ -32635,10 +32877,11 @@ | ||
| 32635 | 32877 | case etEXP: |
| 32636 | 32878 | case etGENERIC: { |
| 32637 | 32879 | FpDecode s; |
| 32638 | 32880 | int iRound; |
| 32639 | 32881 | int j; |
| 32882 | + i64 szBufNeeded; /* Size needed to hold the output */ | |
| 32640 | 32883 | |
| 32641 | 32884 | if( bArgList ){ |
| 32642 | 32885 | realvalue = getDoubleArg(pArgList); |
| 32643 | 32886 | }else{ |
| 32644 | 32887 | realvalue = va_arg(ap,double); |
| @@ -32723,21 +32966,19 @@ | ||
| 32723 | 32966 | if( xtype==etEXP ){ |
| 32724 | 32967 | e2 = 0; |
| 32725 | 32968 | }else{ |
| 32726 | 32969 | e2 = s.iDP - 1; |
| 32727 | 32970 | } |
| 32728 | - bufpt = buf; | |
| 32729 | - { | |
| 32730 | - i64 szBufNeeded; /* Size of a temporary buffer needed */ | |
| 32731 | - szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; | |
| 32732 | - if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; | |
| 32733 | - if( szBufNeeded > etBUFSIZE ){ | |
| 32734 | - bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded); | |
| 32735 | - if( bufpt==0 ) return; | |
| 32736 | - } | |
| 32737 | - } | |
| 32738 | - zOut = bufpt; | |
| 32971 | + | |
| 32972 | + szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+8; | |
| 32973 | + if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; | |
| 32974 | + if( sqlite3StrAccumEnlargeIfNeeded(pAccum, szBufNeeded) ){ | |
| 32975 | + width = length = 0; | |
| 32976 | + break; | |
| 32977 | + } | |
| 32978 | + bufpt = zOut = pAccum->zText + pAccum->nChar; | |
| 32979 | + | |
| 32739 | 32980 | flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; |
| 32740 | 32981 | /* The sign in front of the number */ |
| 32741 | 32982 | if( prefix ){ |
| 32742 | 32983 | *(bufpt++) = prefix; |
| 32743 | 32984 | } |
| @@ -32781,17 +33022,15 @@ | ||
| 32781 | 33022 | int nn = s.n - j; |
| 32782 | 33023 | if( NEVER(nn>precision) ) nn = precision; |
| 32783 | 33024 | if( nn>0 ){ |
| 32784 | 33025 | memcpy(bufpt, s.z+j, nn); |
| 32785 | 33026 | bufpt += nn; |
| 32786 | - j += nn; | |
| 32787 | 33027 | precision -= nn; |
| 32788 | 33028 | } |
| 32789 | 33029 | if( precision>0 && !flag_rtz ){ |
| 32790 | 33030 | memset(bufpt, '0', precision); |
| 32791 | 33031 | bufpt += precision; |
| 32792 | - precision = 0; | |
| 32793 | 33032 | } |
| 32794 | 33033 | } |
| 32795 | 33034 | /* Remove trailing zeros and the "." if no digits follow the "." */ |
| 32796 | 33035 | if( flag_rtz && flag_dp ){ |
| 32797 | 33036 | while( bufpt[-1]=='0' ) *(--bufpt) = 0; |
| @@ -32818,31 +33057,35 @@ | ||
| 32818 | 33057 | exp %= 100; |
| 32819 | 33058 | } |
| 32820 | 33059 | *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */ |
| 32821 | 33060 | *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */ |
| 32822 | 33061 | } |
| 32823 | - *bufpt = 0; | |
| 32824 | 33062 | |
| 32825 | - /* The converted number is in buf[] and zero terminated. Output it. | |
| 32826 | - ** Note that the number is in the usual order, not reversed as with | |
| 32827 | - ** integer conversions. */ | |
| 32828 | 33063 | length = (int)(bufpt-zOut); |
| 32829 | - bufpt = zOut; | |
| 32830 | - | |
| 32831 | - /* Special case: Add leading zeros if the flag_zeropad flag is | |
| 32832 | - ** set and we are not left justified */ | |
| 32833 | - if( flag_zeropad && !flag_leftjustify && length < width){ | |
| 32834 | - int i; | |
| 32835 | - int nPad = width - length; | |
| 32836 | - for(i=width; i>=nPad; i--){ | |
| 32837 | - bufpt[i] = bufpt[i-nPad]; | |
| 32838 | - } | |
| 32839 | - i = prefix!=0; | |
| 32840 | - while( nPad-- ) bufpt[i++] = '0'; | |
| 33064 | + assert( length <= szBufNeeded ); | |
| 33065 | + if( length<width ){ | |
| 33066 | + i64 nPad = width - length; | |
| 33067 | + if( flag_leftjustify ){ | |
| 33068 | + memset(bufpt, ' ', nPad); | |
| 33069 | + }else if( !flag_zeropad ){ | |
| 33070 | + memmove(zOut+nPad, zOut, length); | |
| 33071 | + memset(zOut, ' ', nPad); | |
| 33072 | + }else{ | |
| 33073 | + int adj = prefix!=0; | |
| 33074 | + memmove(zOut+nPad+adj, zOut+adj, length-adj); | |
| 33075 | + memset(zOut+adj, '0', nPad); | |
| 33076 | + } | |
| 32841 | 33077 | length = width; |
| 32842 | 33078 | } |
| 32843 | - break; | |
| 33079 | + pAccum->nChar += length; | |
| 33080 | + zOut[length] = 0; | |
| 33081 | + | |
| 33082 | + /* Floating point conversions render directly into the output | |
| 33083 | + ** buffer. Hence, don't just break out of the switch(). Bypass the | |
| 33084 | + ** output buffer writing that occurs after the switch() by continuing | |
| 33085 | + ** to the next character in the format string. */ | |
| 33086 | + continue; | |
| 32844 | 33087 | } |
| 32845 | 33088 | case etSIZE: |
| 32846 | 33089 | if( !bArgList ){ |
| 32847 | 33090 | *(va_arg(ap,int*)) = pAccum->nChar; |
| 32848 | 33091 | } |
| @@ -32882,15 +33125,14 @@ | ||
| 32882 | 33125 | precision--; |
| 32883 | 33126 | while( precision > 1 ){ |
| 32884 | 33127 | i64 nCopyBytes; |
| 32885 | 33128 | if( nPrior > precision-1 ) nPrior = precision - 1; |
| 32886 | 33129 | nCopyBytes = length*nPrior; |
| 32887 | - if( nCopyBytes + pAccum->nChar >= pAccum->nAlloc ){ | |
| 32888 | - sqlite3StrAccumEnlarge(pAccum, nCopyBytes); | |
| 33130 | + if( sqlite3StrAccumEnlargeIfNeeded(pAccum, nCopyBytes) ){ | |
| 33131 | + break; | |
| 32889 | 33132 | } |
| 32890 | - if( pAccum->accError ) break; | |
| 32891 | - sqlite3_str_append(pAccum, | |
| 33133 | + sqlite3_str_append(pAccum, | |
| 32892 | 33134 | &pAccum->zText[pAccum->nChar-nCopyBytes], nCopyBytes); |
| 32893 | 33135 | precision -= nPrior; |
| 32894 | 33136 | nPrior *= 2; |
| 32895 | 33137 | } |
| 32896 | 33138 | } |
| @@ -33231,10 +33473,17 @@ | ||
| 33231 | 33473 | } |
| 33232 | 33474 | } |
| 33233 | 33475 | assert( N>=0 && N<=0x7fffffff ); |
| 33234 | 33476 | return (int)N; |
| 33235 | 33477 | } |
| 33478 | + | |
| 33479 | +SQLITE_PRIVATE int sqlite3StrAccumEnlargeIfNeeded(StrAccum *p, i64 N){ | |
| 33480 | + if( N + p->nChar >= p->nAlloc ){ | |
| 33481 | + sqlite3StrAccumEnlarge(p, N); | |
| 33482 | + } | |
| 33483 | + return p->accError; | |
| 33484 | +} | |
| 33236 | 33485 | |
| 33237 | 33486 | /* |
| 33238 | 33487 | ** Append N copies of character c to the given string buffer. |
| 33239 | 33488 | */ |
| 33240 | 33489 | SQLITE_API void sqlite3_str_appendchar(sqlite3_str *p, int N, char c){ |
| @@ -36548,15 +36797,16 @@ | ||
| 36548 | 36797 | ** lower 64-bits of the result into *pLo, and return the high-order |
| 36549 | 36798 | ** 64 bits. |
| 36550 | 36799 | */ |
| 36551 | 36800 | static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){ |
| 36552 | 36801 | #if (defined(__GNUC__) || defined(__clang__)) \ |
| 36553 | - && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) | |
| 36802 | + && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \ | |
| 36803 | + && !defined(SQLITE_DISABLE_INTRINSIC) | |
| 36554 | 36804 | __uint128_t r = (__uint128_t)a * b; |
| 36555 | 36805 | *pLo = (u64)r; |
| 36556 | 36806 | return (u64)(r>>64); |
| 36557 | -#elif defined(_MSC_VER) && defined(_M_X64) | |
| 36807 | +#elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC) | |
| 36558 | 36808 | *pLo = a*b; |
| 36559 | 36809 | return __umulh(a, b); |
| 36560 | 36810 | #else |
| 36561 | 36811 | u64 a0 = (u32)a; |
| 36562 | 36812 | u64 a1 = a >> 32; |
| @@ -36583,21 +36833,23 @@ | ||
| 36583 | 36833 | ** |
| 36584 | 36834 | ** The lower 64 bits of A*B are discarded. |
| 36585 | 36835 | */ |
| 36586 | 36836 | static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){ |
| 36587 | 36837 | #if (defined(__GNUC__) || defined(__clang__)) \ |
| 36588 | - && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) | |
| 36838 | + && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \ | |
| 36839 | + && !defined(SQLITE_DISABLE_INTRINSIC) | |
| 36589 | 36840 | __uint128_t r = (__uint128_t)a * b; |
| 36590 | 36841 | r += ((__uint128_t)aLo * b) >> 32; |
| 36591 | 36842 | *pLo = (r>>32)&0xffffffff; |
| 36592 | 36843 | return r>>64; |
| 36593 | -#elif defined(_MSC_VER) && defined(_M_X64) | |
| 36844 | +#elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC) | |
| 36594 | 36845 | u64 r1_hi = __umulh(a,b); |
| 36595 | 36846 | u64 r1_lo = a*b; |
| 36596 | 36847 | u64 r2 = (__umulh((u64)aLo,b)<<32) + ((aLo*b)>>32); |
| 36597 | - r1_hi += _addcarry_u64(0, r1_lo, r2, &r1_lo); | |
| 36598 | - *pLo = r1_lo>>32; | |
| 36848 | + u64 t = r1_lo + r2; | |
| 36849 | + if( t<r1_lo ) r1_hi++; | |
| 36850 | + *pLo = t>>32; | |
| 36599 | 36851 | return r1_hi; |
| 36600 | 36852 | #else |
| 36601 | 36853 | u64 x2 = a>>32; |
| 36602 | 36854 | u64 x1 = a&0xffffffff; |
| 36603 | 36855 | u64 x0 = aLo; |
| @@ -36805,11 +37057,12 @@ | ||
| 36805 | 37057 | |
| 36806 | 37058 | /* |
| 36807 | 37059 | ** Count leading zeros for a 64-bit unsigned integer. |
| 36808 | 37060 | */ |
| 36809 | 37061 | static int countLeadingZeros(u64 m){ |
| 36810 | -#if defined(__GNUC__) || defined(__clang__) | |
| 37062 | +#if (defined(__GNUC__) || defined(__clang__)) \ | |
| 37063 | + && !defined(SQLITE_DISABLE_INTRINSIC) | |
| 36811 | 37064 | return __builtin_clzll(m); |
| 36812 | 37065 | #else |
| 36813 | 37066 | int n = 0; |
| 36814 | 37067 | if( m <= 0x00000000ffffffffULL) { n += 32; m <<= 32; } |
| 36815 | 37068 | if( m <= 0x0000ffffffffffffULL) { n += 16; m <<= 16; } |
| @@ -36906,16 +37159,19 @@ | ||
| 36906 | 37159 | ** Return positive if the result is a valid real number (or integer) and |
| 36907 | 37160 | ** zero or negative if the string is empty or contains extraneous text. |
| 36908 | 37161 | ** Lower bits of the return value contain addition information about the |
| 36909 | 37162 | ** parse: |
| 36910 | 37163 | ** |
| 36911 | -** bit 0 => Set for any valid input | |
| 36912 | -** bit 1 => Input contains a decimal point or eNNN clause | |
| 36913 | -** This bit is zero if the input is an integer | |
| 37164 | +** bit 0 => Set if any prefix of the input is valid. Clear if | |
| 37165 | +** there is no prefix of the input that can be seen as | |
| 37166 | +** a valid floating point number. | |
| 37167 | +** bit 1 => Set if the input contains a decimal point or eNNN | |
| 37168 | +** clause. Zero if the input is an integer. | |
| 36914 | 37169 | ** bit 2 => The input is exactly 0.0, not an underflow from |
| 36915 | -** some value near zero | |
| 36916 | -** bit 3 => More than 19 significant digits in the input | |
| 37170 | +** some value near zero. | |
| 37171 | +** bit 3 => Set if there are more than about 19 significant | |
| 37172 | +** digits in the input. | |
| 36917 | 37173 | ** |
| 36918 | 37174 | ** If the input contains a syntax error but begins with text that might |
| 36919 | 37175 | ** be a valid number of some kind, then the result is negative. The |
| 36920 | 37176 | ** result is only zero if no prefix of the input could be interpreted as |
| 36921 | 37177 | ** a number. |
| @@ -37077,10 +37333,73 @@ | ||
| 37077 | 37333 | "70717273747576777879" |
| 37078 | 37334 | "80818283848586878889" |
| 37079 | 37335 | "90919293949596979899" |
| 37080 | 37336 | }; |
| 37081 | 37337 | |
| 37338 | +/* | |
| 37339 | +** ARMv6, ARMv7, PPC32 are known to not support hardware u64 division. | |
| 37340 | +*/ | |
| 37341 | +#if (defined(__arm__) && !defined(__aarch64__)) || \ | |
| 37342 | + (defined(__ppc__) && !defined(__ppc64__)) | |
| 37343 | +# define SQLITE_AVOID_U64_DIVIDE 1 | |
| 37344 | +#endif | |
| 37345 | + | |
| 37346 | +#ifdef SQLITE_AVOID_U64_DIVIDE | |
| 37347 | +/* | |
| 37348 | +** Render an unsigned 64-bit integer as text onto the end of a 2-byte | |
| 37349 | +** aligned buffer that is SQLITE_U64_DIGIT+1 bytes long. The last byte | |
| 37350 | +** of the buffer will be filled with a \000 byte. | |
| 37351 | +** | |
| 37352 | +** Return the index into the buffer of the first byte. | |
| 37353 | +** | |
| 37354 | +** This routine is used on platforms where u64-division is slow because | |
| 37355 | +** it is not available in hardware and has to be emulated in software. | |
| 37356 | +** It seeks to minimize the number of u64 divisions and use u32 divisions | |
| 37357 | +** instead. It is slower on platforms that have hardware u64 division, | |
| 37358 | +** but much faster on platforms that do not. | |
| 37359 | +*/ | |
| 37360 | +static int sqlite3UInt64ToText(u64 v, char *zOut){ | |
| 37361 | + u32 x32, kk; | |
| 37362 | + int i; | |
| 37363 | + zOut[SQLITE_U64_DIGITS] = 0; | |
| 37364 | + i = SQLITE_U64_DIGITS; | |
| 37365 | + assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[0]) ); | |
| 37366 | + assert( TWO_BYTE_ALIGNMENT(zOut) ); | |
| 37367 | + while( (v>>32)!=0 ){ | |
| 37368 | + u32 y, x0, x1, y0, y1; | |
| 37369 | + x32 = v % 100000000; | |
| 37370 | + v = v / 100000000; | |
| 37371 | + y = x32 % 10000; | |
| 37372 | + x32 /= 10000; | |
| 37373 | + x1 = x32 / 100; | |
| 37374 | + x0 = x32 % 100; | |
| 37375 | + y1 = y / 100; | |
| 37376 | + y0 = y % 100; | |
| 37377 | + assert( i>=8 ); | |
| 37378 | + i -= 8; | |
| 37379 | + *(u16*)(&zOut[i]) = *(u16*)&sqlite3DigitPairs.a[x1*2]; | |
| 37380 | + *(u16*)(&zOut[i+2]) = *(u16*)&sqlite3DigitPairs.a[x0*2]; | |
| 37381 | + *(u16*)(&zOut[i+4]) = *(u16*)&sqlite3DigitPairs.a[y1*2]; | |
| 37382 | + *(u16*)(&zOut[i+6]) = *(u16*)&sqlite3DigitPairs.a[y0*2]; | |
| 37383 | + } | |
| 37384 | + x32 = v; | |
| 37385 | + while( x32>=10 ){ | |
| 37386 | + kk = x32 % 100; | |
| 37387 | + x32 = x32 / 100; | |
| 37388 | + assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk*2]) ); | |
| 37389 | + assert( i>=2 ); | |
| 37390 | + i -= 2; | |
| 37391 | + assert( TWO_BYTE_ALIGNMENT(&zOut[i]) ); | |
| 37392 | + *(u16*)(&zOut[i]) = *(u16*)&sqlite3DigitPairs.a[kk*2]; | |
| 37393 | + } | |
| 37394 | + if( x32 ){ | |
| 37395 | + assert( i>0 ); | |
| 37396 | + zOut[--i] = x32 + '0'; | |
| 37397 | + } | |
| 37398 | + return i; | |
| 37399 | +} | |
| 37400 | +#endif /* defined(SQLITE_AVOID_U64_DIVIDE) */ | |
| 37082 | 37401 | |
| 37083 | 37402 | /* |
| 37084 | 37403 | ** Render an signed 64-bit integer as text. Store the result in zOut[] and |
| 37085 | 37404 | ** return the length of the string that was stored, in bytes. The value |
| 37086 | 37405 | ** returned does not include the zero terminator at the end of the output |
| @@ -37090,11 +37409,11 @@ | ||
| 37090 | 37409 | */ |
| 37091 | 37410 | SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){ |
| 37092 | 37411 | int i; |
| 37093 | 37412 | u64 x; |
| 37094 | 37413 | union { |
| 37095 | - char a[23]; | |
| 37414 | + char a[SQLITE_U64_DIGITS+1]; | |
| 37096 | 37415 | u16 forceAlignment; |
| 37097 | 37416 | } u; |
| 37098 | 37417 | if( v>0 ){ |
| 37099 | 37418 | x = v; |
| 37100 | 37419 | }else if( v==0 ){ |
| @@ -37102,10 +37421,13 @@ | ||
| 37102 | 37421 | zOut[1] = 0; |
| 37103 | 37422 | return 1; |
| 37104 | 37423 | }else{ |
| 37105 | 37424 | x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v; |
| 37106 | 37425 | } |
| 37426 | +#ifdef SQLITE_AVOID_U64_DIVIDE | |
| 37427 | + i = sqlite3UInt64ToText(x, u.a); | |
| 37428 | +#else | |
| 37107 | 37429 | i = sizeof(u.a)-1; |
| 37108 | 37430 | u.a[i] = 0; |
| 37109 | 37431 | while( x>=10 ){ |
| 37110 | 37432 | int kk = (x%100)*2; |
| 37111 | 37433 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) ); |
| @@ -37115,10 +37437,11 @@ | ||
| 37115 | 37437 | x /= 100; |
| 37116 | 37438 | } |
| 37117 | 37439 | if( x ){ |
| 37118 | 37440 | u.a[--i] = x + '0'; |
| 37119 | 37441 | } |
| 37442 | +#endif /* SQLITE_AVOID_U64_DIVIDE */ | |
| 37120 | 37443 | if( v<0 ) u.a[--i] = '-'; |
| 37121 | 37444 | memcpy(zOut, &u.a[i], sizeof(u.a)-i); |
| 37122 | 37445 | return sizeof(u.a)-1-i; |
| 37123 | 37446 | } |
| 37124 | 37447 | |
| @@ -37434,41 +37757,47 @@ | ||
| 37434 | 37757 | sqlite3Fp2Convert10(v, e, (iRound<=0||iRound>=18)?18:iRound+1, &v, &exp); |
| 37435 | 37758 | |
| 37436 | 37759 | /* Extract significant digits, start at the right-most slot in p->zBuf |
| 37437 | 37760 | ** and working back to the right. "i" keeps track of the next slot in |
| 37438 | 37761 | ** which to store a digit. */ |
| 37439 | - i = sizeof(p->zBuf)-1; | |
| 37762 | + assert( sizeof(p->zBuf)==SQLITE_U64_DIGITS+1 ); | |
| 37763 | + assert( v>0 ); | |
| 37440 | 37764 | zBuf = p->zBuf; |
| 37441 | - assert( v>0 ); | |
| 37765 | +#ifdef SQLITE_AVOID_U64_DIVIDE | |
| 37766 | + i = sqlite3UInt64ToText(v, zBuf); | |
| 37767 | +#else | |
| 37768 | + i = SQLITE_U64_DIGITS; | |
| 37442 | 37769 | while( v>=10 ){ |
| 37443 | 37770 | int kk = (v%100)*2; |
| 37444 | 37771 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) ); |
| 37445 | - assert( TWO_BYTE_ALIGNMENT(&zBuf[i-1]) ); | |
| 37446 | - *(u16*)(&zBuf[i-1]) = *(u16*)&sqlite3DigitPairs.a[kk]; | |
| 37772 | + assert( TWO_BYTE_ALIGNMENT(&zBuf[i]) ); | |
| 37773 | + assert( i-2>=0 ); | |
| 37774 | + *(u16*)(&zBuf[i-2]) = *(u16*)&sqlite3DigitPairs.a[kk]; | |
| 37447 | 37775 | i -= 2; |
| 37448 | 37776 | v /= 100; |
| 37449 | 37777 | } |
| 37450 | 37778 | if( v ){ |
| 37451 | 37779 | assert( v<10 ); |
| 37452 | - zBuf[i--] = v + '0'; | |
| 37780 | + assert( i>0 ); | |
| 37781 | + zBuf[--i] = v + '0'; | |
| 37453 | 37782 | } |
| 37454 | - assert( i>=0 && i<sizeof(p->zBuf)-1 ); | |
| 37455 | - n = sizeof(p->zBuf) - 1 - i; /* Total number of digits extracted */ | |
| 37783 | +#endif /* SQLITE_AVOID_U64_DIVIDE */ | |
| 37784 | + assert( i>=0 && i<SQLITE_U64_DIGITS ); | |
| 37785 | + n = SQLITE_U64_DIGITS - i; /* Total number of digits extracted */ | |
| 37456 | 37786 | assert( n>0 ); |
| 37457 | - assert( n<sizeof(p->zBuf) ); | |
| 37458 | - testcase( n==sizeof(p->zBuf)-1 ); | |
| 37787 | + assert( n<=SQLITE_U64_DIGITS ); | |
| 37459 | 37788 | p->iDP = n + exp; |
| 37460 | 37789 | if( iRound<=0 ){ |
| 37461 | 37790 | iRound = p->iDP - iRound; |
| 37462 | - if( iRound==0 && zBuf[i+1]>='5' ){ | |
| 37791 | + if( iRound==0 && zBuf[i]>='5' ){ | |
| 37463 | 37792 | iRound = 1; |
| 37464 | - zBuf[i--] = '0'; | |
| 37793 | + zBuf[--i] = '0'; | |
| 37465 | 37794 | n++; |
| 37466 | 37795 | p->iDP++; |
| 37467 | 37796 | } |
| 37468 | 37797 | } |
| 37469 | - z = &zBuf[i+1]; /* z points to the first digit */ | |
| 37798 | + z = &zBuf[i]; /* z points to the first digit */ | |
| 37470 | 37799 | if( iRound>0 && (iRound<n || n>mxRound) ){ |
| 37471 | 37800 | if( iRound>mxRound ) iRound = mxRound; |
| 37472 | 37801 | if( iRound==17 ){ |
| 37473 | 37802 | /* If the precision is exactly 17, which only happens with the "!" |
| 37474 | 37803 | ** flag (ex: "%!.17g") then try to reduce the precision if that |
| @@ -85833,11 +86162,11 @@ | ||
| 85833 | 86162 | ** rc>0 => All of the input is well-formed |
| 85834 | 86163 | ** (rc&2)==0 => The number is expressed as an integer, with no |
| 85835 | 86164 | ** decimal point or eNNN suffix. |
| 85836 | 86165 | */ |
| 85837 | 86166 | SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem *pMem, double *pValue){ |
| 85838 | - assert( pMem->db!=0 ); | |
| 86167 | + testcase( pMem->db==0 ); | |
| 85839 | 86168 | assert( pMem->flags & (MEM_Str|MEM_Blob) ); |
| 85840 | 86169 | if( pMem->z==0 ){ |
| 85841 | 86170 | *pValue = 0.0; |
| 85842 | 86171 | return 0; |
| 85843 | 86172 | }else if( pMem->enc==SQLITE_UTF8 |
| @@ -131514,11 +131843,10 @@ | ||
| 131514 | 131843 | ** forms 2 through 5, then rebuild the union of all matching indexes, |
| 131515 | 131844 | ** taken care to avoid rebuilding the same index more than once. |
| 131516 | 131845 | */ |
| 131517 | 131846 | #ifndef SQLITE_OMIT_REINDEX |
| 131518 | 131847 | SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){ |
| 131519 | - CollSeq *pColl; /* Collating sequence to be reindexed, or NULL */ | |
| 131520 | 131848 | char *z = 0; /* Name of a table or index or collation */ |
| 131521 | 131849 | const char *zDb = 0; /* Name of the database */ |
| 131522 | 131850 | int iReDb = -1; /* The database index number */ |
| 131523 | 131851 | sqlite3 *db = pParse->db; /* The database connection */ |
| 131524 | 131852 | Token *pObjName; /* Name of the table or index to be reindexed */ |
| @@ -131553,11 +131881,11 @@ | ||
| 131553 | 131881 | if( !bAll ){ |
| 131554 | 131882 | if( zDb==0 && sqlite3StrICmp(z, "expressions")==0 ){ |
| 131555 | 131883 | isExprIdx = 1; |
| 131556 | 131884 | bMatch = 1; |
| 131557 | 131885 | } |
| 131558 | - if( zDb==0 && (pColl = sqlite3FindCollSeq(db, ENC(db), z, 0))!=0 ){ | |
| 131886 | + if( zDb==0 && sqlite3FindCollSeq(db, ENC(db), z, 0)!=0 ){ | |
| 131559 | 131887 | zColl = z; |
| 131560 | 131888 | bMatch = 1; |
| 131561 | 131889 | } |
| 131562 | 131890 | if( zColl==0 && (pReTab = sqlite3FindTable(db, z, zDb))!=0 ){ |
| 131563 | 131891 | bMatch = 1; |
| @@ -134449,22 +134777,15 @@ | ||
| 134449 | 134777 | ** require enhancements to the implementation. */ |
| 134450 | 134778 | assert( pStr!=0 && pStr->nChar==0 ); |
| 134451 | 134779 | |
| 134452 | 134780 | switch( sqlite3_value_type(pValue) ){ |
| 134453 | 134781 | case SQLITE_FLOAT: { |
| 134454 | - double r1, r2; | |
| 134455 | - const char *zVal; | |
| 134456 | - r1 = sqlite3_value_double(pValue); | |
| 134457 | - sqlite3_str_appendf(pStr, "%!0.15g", r1); | |
| 134458 | - zVal = sqlite3_str_value(pStr); | |
| 134459 | - if( zVal ){ | |
| 134460 | - sqlite3AtoF(zVal, &r2); | |
| 134461 | - if( r1!=r2 ){ | |
| 134462 | - sqlite3_str_reset(pStr); | |
| 134463 | - sqlite3_str_appendf(pStr, "%!0.20e", r1); | |
| 134464 | - } | |
| 134465 | - } | |
| 134782 | + /* ,--- Show infinity as 9.0e+999 | |
| 134783 | + ** | | |
| 134784 | + ** | ,--- 17 precision guarantees round-trip | |
| 134785 | + ** v v */ | |
| 134786 | + sqlite3_str_appendf(pStr, "%!0.17g", sqlite3_value_double(pValue)); | |
| 134466 | 134787 | break; |
| 134467 | 134788 | } |
| 134468 | 134789 | case SQLITE_INTEGER: { |
| 134469 | 134790 | sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue)); |
| 134470 | 134791 | break; |
| @@ -186195,11 +186516,11 @@ | ||
| 186195 | 186516 | if( db->mallocFailed ){ |
| 186196 | 186517 | pParse->rc = SQLITE_NOMEM_BKPT; |
| 186197 | 186518 | } |
| 186198 | 186519 | if( pParse->zErrMsg || (pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE) ){ |
| 186199 | 186520 | if( pParse->zErrMsg==0 ){ |
| 186200 | - pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc)); | |
| 186521 | + pParse->zErrMsg = sqlite3DbStrDup(db, sqlite3ErrStr(pParse->rc)); | |
| 186201 | 186522 | } |
| 186202 | 186523 | if( (pParse->prepFlags & SQLITE_PREPARE_DONT_LOG)==0 ){ |
| 186203 | 186524 | sqlite3_log(pParse->rc, "%s in \"%s\"", pParse->zErrMsg, pParse->zTail); |
| 186204 | 186525 | } |
| 186205 | 186526 | nErr++; |
| @@ -233377,10 +233698,23 @@ | ||
| 233377 | 233698 | aBuf[4] = (i>>24) & 0xFF; |
| 233378 | 233699 | aBuf[5] = (i>>16) & 0xFF; |
| 233379 | 233700 | aBuf[6] = (i>> 8) & 0xFF; |
| 233380 | 233701 | aBuf[7] = (i>> 0) & 0xFF; |
| 233381 | 233702 | } |
| 233703 | + | |
| 233704 | +/* | |
| 233705 | +** Write a double value to the buffer aBuf[]. | |
| 233706 | +*/ | |
| 233707 | +static void sessionPutDouble(u8 *aBuf, double r){ | |
| 233708 | + /* TODO: SQLite does something special to deal with mixed-endian | |
| 233709 | + ** floating point values (e.g. ARM7). This code probably should | |
| 233710 | + ** too. */ | |
| 233711 | + u64 i; | |
| 233712 | + assert( sizeof(double)==8 && sizeof(u64)==8 ); | |
| 233713 | + memcpy(&i, &r, 8); | |
| 233714 | + sessionPutI64(aBuf, i); | |
| 233715 | +} | |
| 233382 | 233716 | |
| 233383 | 233717 | /* |
| 233384 | 233718 | ** This function is used to serialize the contents of value pValue (see |
| 233385 | 233719 | ** comment titled "RECORD FORMAT" above). |
| 233386 | 233720 | ** |
| @@ -233415,20 +233749,17 @@ | ||
| 233415 | 233749 | case SQLITE_FLOAT: |
| 233416 | 233750 | if( aBuf ){ |
| 233417 | 233751 | /* TODO: SQLite does something special to deal with mixed-endian |
| 233418 | 233752 | ** floating point values (e.g. ARM7). This code probably should |
| 233419 | 233753 | ** too. */ |
| 233420 | - u64 i; | |
| 233421 | 233754 | if( eType==SQLITE_INTEGER ){ |
| 233422 | - i = (u64)sqlite3_value_int64(pValue); | |
| 233755 | + u64 i = (u64)sqlite3_value_int64(pValue); | |
| 233756 | + sessionPutI64(&aBuf[1], i); | |
| 233423 | 233757 | }else{ |
| 233424 | - double r; | |
| 233425 | - assert( sizeof(double)==8 && sizeof(u64)==8 ); | |
| 233426 | - r = sqlite3_value_double(pValue); | |
| 233427 | - memcpy(&i, &r, 8); | |
| 233758 | + double r = sqlite3_value_double(pValue); | |
| 233759 | + sessionPutDouble(&aBuf[1], r); | |
| 233428 | 233760 | } |
| 233429 | - sessionPutI64(&aBuf[1], i); | |
| 233430 | 233761 | } |
| 233431 | 233762 | nByte = 9; |
| 233432 | 233763 | break; |
| 233433 | 233764 | |
| 233434 | 233765 | default: { |
| @@ -234356,13 +234687,11 @@ | ||
| 234356 | 234687 | break; |
| 234357 | 234688 | } |
| 234358 | 234689 | |
| 234359 | 234690 | case SQLITE_FLOAT: { |
| 234360 | 234691 | double rVal = sqlite3_column_double(pDflt, iField); |
| 234361 | - i64 iVal = 0; | |
| 234362 | - memcpy(&iVal, &rVal, sizeof(rVal)); | |
| 234363 | - sessionPutI64(&pNew->aRecord[pNew->nRecord], iVal); | |
| 234692 | + sessionPutDouble(&pNew->aRecord[pNew->nRecord], rVal); | |
| 234364 | 234693 | pNew->nRecord += 8; |
| 234365 | 234694 | break; |
| 234366 | 234695 | } |
| 234367 | 234696 | |
| 234368 | 234697 | case SQLITE_TEXT: { |
| @@ -235615,19 +235944,18 @@ | ||
| 235615 | 235944 | ){ |
| 235616 | 235945 | if( *pRc==SQLITE_OK ){ |
| 235617 | 235946 | int eType = sqlite3_column_type(pStmt, iCol); |
| 235618 | 235947 | sessionAppendByte(p, (u8)eType, pRc); |
| 235619 | 235948 | if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 235620 | - sqlite3_int64 i; | |
| 235621 | 235949 | u8 aBuf[8]; |
| 235622 | 235950 | if( eType==SQLITE_INTEGER ){ |
| 235623 | - i = sqlite3_column_int64(pStmt, iCol); | |
| 235951 | + sqlite3_int64 i = sqlite3_column_int64(pStmt, iCol); | |
| 235952 | + sessionPutI64(aBuf, i); | |
| 235624 | 235953 | }else{ |
| 235625 | 235954 | double r = sqlite3_column_double(pStmt, iCol); |
| 235626 | - memcpy(&i, &r, 8); | |
| 235955 | + sessionPutDouble(aBuf, r); | |
| 235627 | 235956 | } |
| 235628 | - sessionPutI64(aBuf, i); | |
| 235629 | 235957 | sessionAppendBlob(p, aBuf, 8, pRc); |
| 235630 | 235958 | } |
| 235631 | 235959 | if( eType==SQLITE_BLOB || eType==SQLITE_TEXT ){ |
| 235632 | 235960 | u8 *z; |
| 235633 | 235961 | int nByte; |
| @@ -238664,10 +238992,25 @@ | ||
| 238664 | 238992 | xFilter, 0, xConflict, pCtx, |
| 238665 | 238993 | 0, 0, 0 |
| 238666 | 238994 | ); |
| 238667 | 238995 | } |
| 238668 | 238996 | |
| 238997 | +/* | |
| 238998 | +** The parts of the sqlite3_changegroup structure used by the | |
| 238999 | +** sqlite3changegroup_change_xxx() APIs. | |
| 239000 | +*/ | |
| 239001 | +typedef struct ChangeData ChangeData; | |
| 239002 | +struct ChangeData { | |
| 239003 | + SessionTable *pTab; | |
| 239004 | + int bIndirect; | |
| 239005 | + int eOp; | |
| 239006 | + | |
| 239007 | + int nBufAlloc; | |
| 239008 | + SessionBuffer *aBuf; | |
| 239009 | + SessionBuffer record; | |
| 239010 | +}; | |
| 239011 | + | |
| 238669 | 239012 | /* |
| 238670 | 239013 | ** sqlite3_changegroup handle. |
| 238671 | 239014 | */ |
| 238672 | 239015 | struct sqlite3_changegroup { |
| 238673 | 239016 | int rc; /* Error code */ |
| @@ -238675,10 +239018,11 @@ | ||
| 238675 | 239018 | SessionTable *pList; /* List of tables in current patch */ |
| 238676 | 239019 | SessionBuffer rec; |
| 238677 | 239020 | |
| 238678 | 239021 | sqlite3 *db; /* Configured by changegroup_schema() */ |
| 238679 | 239022 | char *zDb; /* Configured by changegroup_schema() */ |
| 239023 | + ChangeData cd; /* Used by changegroup_change_xxx() APIs. */ | |
| 238680 | 239024 | }; |
| 238681 | 239025 | |
| 238682 | 239026 | /* |
| 238683 | 239027 | ** This function is called to merge two changes to the same row together as |
| 238684 | 239028 | ** part of an sqlite3changeset_concat() operation. A new change object is |
| @@ -238914,19 +239258,18 @@ | ||
| 238914 | 239258 | int eType = sqlite3_column_type(pTab->pDfltStmt, ii); |
| 238915 | 239259 | sessionAppendByte(pOut, eType, &rc); |
| 238916 | 239260 | switch( eType ){ |
| 238917 | 239261 | case SQLITE_FLOAT: |
| 238918 | 239262 | case SQLITE_INTEGER: { |
| 238919 | - i64 iVal; | |
| 238920 | - if( eType==SQLITE_INTEGER ){ | |
| 238921 | - iVal = sqlite3_column_int64(pTab->pDfltStmt, ii); | |
| 238922 | - }else{ | |
| 238923 | - double rVal = sqlite3_column_int64(pTab->pDfltStmt, ii); | |
| 238924 | - memcpy(&iVal, &rVal, sizeof(i64)); | |
| 238925 | - } | |
| 238926 | 239263 | if( SQLITE_OK==sessionBufferGrow(pOut, 8, &rc) ){ |
| 238927 | - sessionPutI64(&pOut->aBuf[pOut->nBuf], iVal); | |
| 239264 | + if( eType==SQLITE_INTEGER ){ | |
| 239265 | + sqlite3_int64 iVal = sqlite3_column_int64(pTab->pDfltStmt, ii); | |
| 239266 | + sessionPutI64(&pOut->aBuf[pOut->nBuf], iVal); | |
| 239267 | + }else{ | |
| 239268 | + double rVal = sqlite3_column_double(pTab->pDfltStmt, ii); | |
| 239269 | + sessionPutDouble(&pOut->aBuf[pOut->nBuf], rVal); | |
| 239270 | + } | |
| 238928 | 239271 | pOut->nBuf += 8; |
| 238929 | 239272 | } |
| 238930 | 239273 | break; |
| 238931 | 239274 | } |
| 238932 | 239275 | |
| @@ -238993,17 +239336,23 @@ | ||
| 238993 | 239336 | int nTab = (int)strlen(zTab); |
| 238994 | 239337 | u8 *abPK = 0; |
| 238995 | 239338 | int nCol = 0; |
| 238996 | 239339 | |
| 238997 | 239340 | *ppTab = 0; |
| 238998 | - sqlite3changeset_pk(pIter, &abPK, &nCol); | |
| 238999 | 239341 | |
| 239000 | 239342 | /* Search the list for an existing table */ |
| 239001 | 239343 | for(pTab = pGrp->pList; pTab; pTab=pTab->pNext){ |
| 239002 | 239344 | if( 0==sqlite3_strnicmp(pTab->zName, zTab, nTab+1) ) break; |
| 239003 | 239345 | } |
| 239004 | 239346 | |
| 239347 | + | |
| 239348 | + if( pIter ){ | |
| 239349 | + sqlite3changeset_pk(pIter, &abPK, &nCol); | |
| 239350 | + }else if( !pTab && !pGrp->db ){ | |
| 239351 | + return SQLITE_OK; | |
| 239352 | + } | |
| 239353 | + | |
| 239005 | 239354 | /* If one was not found above, create a new table now */ |
| 239006 | 239355 | if( !pTab ){ |
| 239007 | 239356 | SessionTable **ppNew; |
| 239008 | 239357 | |
| 239009 | 239358 | pTab = sqlite3_malloc64(sizeof(SessionTable) + nCol + nTab+1); |
| @@ -239018,12 +239367,12 @@ | ||
| 239018 | 239367 | memcpy(pTab->zName, zTab, nTab+1); |
| 239019 | 239368 | |
| 239020 | 239369 | if( pGrp->db ){ |
| 239021 | 239370 | pTab->nCol = 0; |
| 239022 | 239371 | rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb); |
| 239023 | - if( rc ){ | |
| 239024 | - assert( pTab->azCol==0 ); | |
| 239372 | + if( rc || pTab->nCol==0 ){ | |
| 239373 | + sqlite3_free(pTab->azCol); | |
| 239025 | 239374 | sqlite3_free(pTab); |
| 239026 | 239375 | return rc; |
| 239027 | 239376 | } |
| 239028 | 239377 | } |
| 239029 | 239378 | |
| @@ -239034,78 +239383,61 @@ | ||
| 239034 | 239383 | for(ppNew=&pGrp->pList; *ppNew; ppNew=&(*ppNew)->pNext); |
| 239035 | 239384 | *ppNew = pTab; |
| 239036 | 239385 | } |
| 239037 | 239386 | |
| 239038 | 239387 | /* Check that the table is compatible. */ |
| 239039 | - if( !sessionChangesetCheckCompat(pTab, nCol, abPK) ){ | |
| 239388 | + if( pIter && !sessionChangesetCheckCompat(pTab, nCol, abPK) ){ | |
| 239040 | 239389 | rc = SQLITE_SCHEMA; |
| 239041 | 239390 | } |
| 239042 | 239391 | |
| 239043 | 239392 | *ppTab = pTab; |
| 239044 | 239393 | return rc; |
| 239045 | 239394 | } |
| 239046 | 239395 | |
| 239047 | 239396 | /* |
| 239048 | -** Add the change currently indicated by iterator pIter to the hash table | |
| 239049 | -** belonging to changegroup pGrp. | |
| 239397 | +** Add a single change to the changegroup pGrp. | |
| 239050 | 239398 | */ |
| 239051 | 239399 | static int sessionOneChangeToHash( |
| 239052 | - sqlite3_changegroup *pGrp, | |
| 239053 | - sqlite3_changeset_iter *pIter, | |
| 239054 | - int bRebase | |
| 239400 | + sqlite3_changegroup *pGrp, /* Changegroup to update */ | |
| 239401 | + SessionTable *pTab, /* Table change pertains to */ | |
| 239402 | + int op, /* One of SQLITE_INSERT, UPDATE, DELETE */ | |
| 239403 | + int bIndirect, /* True to flag change as "indirect" */ | |
| 239404 | + int nCol, /* Number of columns in record(s) */ | |
| 239405 | + u8 *aRec, /* Serialized change record(s) */ | |
| 239406 | + int nRec, /* Size of aRec[] in bytes */ | |
| 239407 | + int bRebase /* True if this is a rebase blob */ | |
| 239055 | 239408 | ){ |
| 239056 | 239409 | int rc = SQLITE_OK; |
| 239057 | - int nCol = 0; | |
| 239058 | - int op = 0; | |
| 239059 | 239410 | int iHash = 0; |
| 239060 | - int bIndirect = 0; | |
| 239061 | 239411 | SessionChange *pChange = 0; |
| 239062 | 239412 | SessionChange *pExist = 0; |
| 239063 | 239413 | SessionChange **pp = 0; |
| 239064 | - SessionTable *pTab = 0; | |
| 239065 | - u8 *aRec = &pIter->in.aData[pIter->in.iCurrent + 2]; | |
| 239066 | - int nRec = (pIter->in.iNext - pIter->in.iCurrent) - 2; | |
| 239067 | 239414 | |
| 239068 | 239415 | assert( nRec>0 ); |
| 239069 | 239416 | |
| 239070 | - /* Ensure that only changesets, or only patchsets, but not a mixture | |
| 239071 | - ** of both, are being combined. It is an error to try to combine a | |
| 239072 | - ** changeset and a patchset. */ | |
| 239073 | - if( pGrp->pList==0 ){ | |
| 239074 | - pGrp->bPatch = pIter->bPatchset; | |
| 239075 | - }else if( pIter->bPatchset!=pGrp->bPatch ){ | |
| 239076 | - rc = SQLITE_ERROR; | |
| 239077 | - } | |
| 239078 | - | |
| 239079 | - if( rc==SQLITE_OK ){ | |
| 239080 | - const char *zTab = 0; | |
| 239081 | - sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect); | |
| 239082 | - rc = sessionChangesetFindTable(pGrp, zTab, pIter, &pTab); | |
| 239083 | - } | |
| 239084 | - | |
| 239085 | - if( rc==SQLITE_OK && nCol<pTab->nCol ){ | |
| 239417 | + if( nCol<pTab->nCol ){ | |
| 239086 | 239418 | SessionBuffer *pBuf = &pGrp->rec; |
| 239087 | 239419 | rc = sessionChangesetExtendRecord(pGrp, pTab, nCol, op, aRec, nRec, pBuf); |
| 239088 | 239420 | aRec = pBuf->aBuf; |
| 239089 | 239421 | nRec = pBuf->nBuf; |
| 239090 | 239422 | assert( pGrp->db ); |
| 239091 | 239423 | } |
| 239092 | 239424 | |
| 239093 | - if( rc==SQLITE_OK && sessionGrowHash(0, pIter->bPatchset, pTab) ){ | |
| 239425 | + if( rc==SQLITE_OK && sessionGrowHash(0, pGrp->bPatch, pTab) ){ | |
| 239094 | 239426 | rc = SQLITE_NOMEM; |
| 239095 | 239427 | } |
| 239096 | 239428 | |
| 239097 | 239429 | if( rc==SQLITE_OK ){ |
| 239098 | 239430 | /* Search for existing entry. If found, remove it from the hash table. |
| 239099 | 239431 | ** Code below may link it back in. */ |
| 239100 | 239432 | iHash = sessionChangeHash( |
| 239101 | - pTab, (pIter->bPatchset && op==SQLITE_DELETE), aRec, pTab->nChange | |
| 239433 | + pTab, (pGrp->bPatch && op==SQLITE_DELETE), aRec, pTab->nChange | |
| 239102 | 239434 | ); |
| 239103 | 239435 | for(pp=&pTab->apChange[iHash]; *pp; pp=&(*pp)->pNext){ |
| 239104 | 239436 | int bPkOnly1 = 0; |
| 239105 | 239437 | int bPkOnly2 = 0; |
| 239106 | - if( pIter->bPatchset ){ | |
| 239438 | + if( pGrp->bPatch ){ | |
| 239107 | 239439 | bPkOnly1 = (*pp)->op==SQLITE_DELETE; |
| 239108 | 239440 | bPkOnly2 = op==SQLITE_DELETE; |
| 239109 | 239441 | } |
| 239110 | 239442 | if( sessionChangeEqual(pTab, bPkOnly1, (*pp)->aRecord, bPkOnly2, aRec) ){ |
| 239111 | 239443 | pExist = *pp; |
| @@ -239116,18 +239448,59 @@ | ||
| 239116 | 239448 | } |
| 239117 | 239449 | } |
| 239118 | 239450 | |
| 239119 | 239451 | if( rc==SQLITE_OK ){ |
| 239120 | 239452 | rc = sessionChangeMerge(pTab, bRebase, |
| 239121 | - pIter->bPatchset, pExist, op, bIndirect, aRec, nRec, &pChange | |
| 239453 | + pGrp->bPatch, pExist, op, bIndirect, aRec, nRec, &pChange | |
| 239122 | 239454 | ); |
| 239123 | 239455 | } |
| 239124 | 239456 | if( rc==SQLITE_OK && pChange ){ |
| 239125 | 239457 | pChange->pNext = pTab->apChange[iHash]; |
| 239126 | 239458 | pTab->apChange[iHash] = pChange; |
| 239127 | 239459 | pTab->nEntry++; |
| 239128 | 239460 | } |
| 239461 | + | |
| 239462 | + return rc; | |
| 239463 | +} | |
| 239464 | + | |
| 239465 | +/* | |
| 239466 | +** Add the change currently indicated by iterator pIter to the hash table | |
| 239467 | +** belonging to changegroup pGrp. | |
| 239468 | +*/ | |
| 239469 | +static int sessionOneChangeIterToHash( | |
| 239470 | + sqlite3_changegroup *pGrp, | |
| 239471 | + sqlite3_changeset_iter *pIter, | |
| 239472 | + int bRebase | |
| 239473 | +){ | |
| 239474 | + u8 *aRec = &pIter->in.aData[pIter->in.iCurrent + 2]; | |
| 239475 | + int nRec = (pIter->in.iNext - pIter->in.iCurrent) - 2; | |
| 239476 | + const char *zTab = 0; | |
| 239477 | + int nCol = 0; | |
| 239478 | + int op = 0; | |
| 239479 | + int bIndirect = 0; | |
| 239480 | + int rc = SQLITE_OK; | |
| 239481 | + SessionTable *pTab = 0; | |
| 239482 | + | |
| 239483 | + /* Ensure that only changesets, or only patchsets, but not a mixture | |
| 239484 | + ** of both, are being combined. It is an error to try to combine a | |
| 239485 | + ** changeset and a patchset. */ | |
| 239486 | + if( pGrp->pList==0 ){ | |
| 239487 | + pGrp->bPatch = pIter->bPatchset; | |
| 239488 | + }else if( pIter->bPatchset!=pGrp->bPatch ){ | |
| 239489 | + rc = SQLITE_ERROR; | |
| 239490 | + } | |
| 239491 | + | |
| 239492 | + if( rc==SQLITE_OK ){ | |
| 239493 | + sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect); | |
| 239494 | + rc = sessionChangesetFindTable(pGrp, zTab, pIter, &pTab); | |
| 239495 | + } | |
| 239496 | + | |
| 239497 | + if( rc==SQLITE_OK ){ | |
| 239498 | + rc = sessionOneChangeToHash( | |
| 239499 | + pGrp, pTab, op, bIndirect, nCol, aRec, nRec, bRebase | |
| 239500 | + ); | |
| 239501 | + } | |
| 239129 | 239502 | |
| 239130 | 239503 | if( rc==SQLITE_OK ) rc = pIter->rc; |
| 239131 | 239504 | return rc; |
| 239132 | 239505 | } |
| 239133 | 239506 | |
| @@ -239144,11 +239517,11 @@ | ||
| 239144 | 239517 | int nRec; |
| 239145 | 239518 | int rc = SQLITE_OK; |
| 239146 | 239519 | |
| 239147 | 239520 | pIter->in.bNoDiscard = 1; |
| 239148 | 239521 | while( SQLITE_ROW==(sessionChangesetNext(pIter, &aRec, &nRec, 0)) ){ |
| 239149 | - rc = sessionOneChangeToHash(pGrp, pIter, bRebase); | |
| 239522 | + rc = sessionOneChangeIterToHash(pGrp, pIter, bRebase); | |
| 239150 | 239523 | if( rc!=SQLITE_OK ) break; |
| 239151 | 239524 | } |
| 239152 | 239525 | |
| 239153 | 239526 | if( rc==SQLITE_OK ) rc = pIter->rc; |
| 239154 | 239527 | return rc; |
| @@ -239233,10 +239606,37 @@ | ||
| 239233 | 239606 | memset(p, 0, sizeof(sqlite3_changegroup)); |
| 239234 | 239607 | } |
| 239235 | 239608 | *pp = p; |
| 239236 | 239609 | return rc; |
| 239237 | 239610 | } |
| 239611 | + | |
| 239612 | +/* | |
| 239613 | +** Configure a changegroup object. | |
| 239614 | +*/ | |
| 239615 | +SQLITE_API int sqlite3changegroup_config( | |
| 239616 | + sqlite3_changegroup *pGrp, | |
| 239617 | + int op, | |
| 239618 | + void *pArg | |
| 239619 | +){ | |
| 239620 | + int rc = SQLITE_OK; | |
| 239621 | + | |
| 239622 | + switch( op ){ | |
| 239623 | + case SQLITE_CHANGEGROUP_CONFIG_PATCHSET: { | |
| 239624 | + int arg = *(int*)pArg; | |
| 239625 | + if( pGrp->pList==0 && arg>=0 ){ | |
| 239626 | + pGrp->bPatch = (arg>0); | |
| 239627 | + } | |
| 239628 | + *(int*)pArg = pGrp->bPatch; | |
| 239629 | + break; | |
| 239630 | + } | |
| 239631 | + default: | |
| 239632 | + rc = SQLITE_MISUSE; | |
| 239633 | + break; | |
| 239634 | + } | |
| 239635 | + | |
| 239636 | + return rc; | |
| 239637 | +} | |
| 239238 | 239638 | |
| 239239 | 239639 | /* |
| 239240 | 239640 | ** Provide a database schema to the changegroup object. |
| 239241 | 239641 | */ |
| 239242 | 239642 | SQLITE_API int sqlite3changegroup_schema( |
| @@ -239292,11 +239692,11 @@ | ||
| 239292 | 239692 | ){ |
| 239293 | 239693 | /* Iterator does not point to any valid entry or is an INVERT iterator. */ |
| 239294 | 239694 | rc = SQLITE_ERROR; |
| 239295 | 239695 | }else{ |
| 239296 | 239696 | pIter->in.bNoDiscard = 1; |
| 239297 | - rc = sessionOneChangeToHash(pGrp, pIter, 0); | |
| 239697 | + rc = sessionOneChangeIterToHash(pGrp, pIter, 0); | |
| 239298 | 239698 | } |
| 239299 | 239699 | return rc; |
| 239300 | 239700 | } |
| 239301 | 239701 | |
| 239302 | 239702 | /* |
| @@ -239344,10 +239744,16 @@ | ||
| 239344 | 239744 | /* |
| 239345 | 239745 | ** Delete a changegroup object. |
| 239346 | 239746 | */ |
| 239347 | 239747 | SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup *pGrp){ |
| 239348 | 239748 | if( pGrp ){ |
| 239749 | + int ii; | |
| 239750 | + for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){ | |
| 239751 | + sqlite3_free(pGrp->cd.aBuf[ii].aBuf); | |
| 239752 | + } | |
| 239753 | + sqlite3_free(pGrp->cd.record.aBuf); | |
| 239754 | + sqlite3_free(pGrp->cd.aBuf); | |
| 239349 | 239755 | sqlite3_free(pGrp->zDb); |
| 239350 | 239756 | sessionDeleteTable(0, pGrp->pList); |
| 239351 | 239757 | sqlite3_free(pGrp->rec.aBuf); |
| 239352 | 239758 | sqlite3_free(pGrp); |
| 239353 | 239759 | } |
| @@ -239771,10 +240177,332 @@ | ||
| 239771 | 240177 | } |
| 239772 | 240178 | default: |
| 239773 | 240179 | rc = SQLITE_MISUSE; |
| 239774 | 240180 | break; |
| 239775 | 240181 | } |
| 240182 | + return rc; | |
| 240183 | +} | |
| 240184 | + | |
| 240185 | +/* | |
| 240186 | +** Begin adding a change to a changegroup object. | |
| 240187 | +*/ | |
| 240188 | +SQLITE_API int sqlite3changegroup_change_begin( | |
| 240189 | + sqlite3_changegroup *pGrp, | |
| 240190 | + int eOp, | |
| 240191 | + const char *zTab, | |
| 240192 | + int bIndirect, | |
| 240193 | + char **pzErr | |
| 240194 | +){ | |
| 240195 | + SessionTable *pTab = 0; | |
| 240196 | + int rc = SQLITE_OK; | |
| 240197 | + | |
| 240198 | + if( pGrp->cd.pTab ){ | |
| 240199 | + rc = SQLITE_MISUSE; | |
| 240200 | + }else if( eOp!=SQLITE_INSERT && eOp!=SQLITE_UPDATE && eOp!=SQLITE_DELETE ){ | |
| 240201 | + rc = SQLITE_ERROR; | |
| 240202 | + }else{ | |
| 240203 | + rc = sessionChangesetFindTable(pGrp, zTab, 0, &pTab); | |
| 240204 | + } | |
| 240205 | + if( rc==SQLITE_OK ){ | |
| 240206 | + if( pTab==0 ){ | |
| 240207 | + if( pzErr ){ | |
| 240208 | + *pzErr = sqlite3_mprintf("no such table: %s", zTab); | |
| 240209 | + } | |
| 240210 | + rc = SQLITE_ERROR; | |
| 240211 | + }else{ | |
| 240212 | + int nReq = pTab->nCol * (eOp==SQLITE_UPDATE ? 2 : 1); | |
| 240213 | + pGrp->cd.pTab = pTab; | |
| 240214 | + pGrp->cd.eOp = eOp; | |
| 240215 | + pGrp->cd.bIndirect = bIndirect; | |
| 240216 | + | |
| 240217 | + if( pGrp->cd.nBufAlloc<nReq ){ | |
| 240218 | + SessionBuffer *aBuf = (SessionBuffer*)sqlite3_realloc( | |
| 240219 | + pGrp->cd.aBuf, nReq * sizeof(SessionBuffer) | |
| 240220 | + ); | |
| 240221 | + if( aBuf==0 ){ | |
| 240222 | + rc = SQLITE_NOMEM; | |
| 240223 | + }else{ | |
| 240224 | + memset(&aBuf[pGrp->cd.nBufAlloc], 0, | |
| 240225 | + sizeof(SessionBuffer) * (nReq - pGrp->cd.nBufAlloc) | |
| 240226 | + ); | |
| 240227 | + pGrp->cd.aBuf = aBuf; | |
| 240228 | + pGrp->cd.nBufAlloc = nReq; | |
| 240229 | + } | |
| 240230 | + } | |
| 240231 | + | |
| 240232 | +#ifdef SQLITE_DEBUG | |
| 240233 | + { | |
| 240234 | + /* Assert that all column values are currently undefined */ | |
| 240235 | + int ii; | |
| 240236 | + for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){ | |
| 240237 | + assert( pGrp->cd.aBuf[ii].nBuf==0 ); | |
| 240238 | + } | |
| 240239 | + } | |
| 240240 | +#endif | |
| 240241 | + } | |
| 240242 | + } | |
| 240243 | + | |
| 240244 | + return rc; | |
| 240245 | +} | |
| 240246 | + | |
| 240247 | +/* | |
| 240248 | +** This function does processing common to the _change_int64(), _change_text() | |
| 240249 | +** and other similar APIs. | |
| 240250 | +*/ | |
| 240251 | +static int checkChangeParams( | |
| 240252 | + sqlite3_changegroup *pGrp, | |
| 240253 | + int bNew, | |
| 240254 | + int iCol, | |
| 240255 | + sqlite3_int64 nReq, | |
| 240256 | + SessionBuffer **ppBuf | |
| 240257 | +){ | |
| 240258 | + int rc = SQLITE_OK; | |
| 240259 | + if( pGrp->cd.pTab==0 ){ | |
| 240260 | + rc = SQLITE_MISUSE; | |
| 240261 | + }else if( iCol<0 || iCol>=pGrp->cd.pTab->nCol ){ | |
| 240262 | + rc = SQLITE_RANGE; | |
| 240263 | + }else if( | |
| 240264 | + (bNew && pGrp->cd.eOp==SQLITE_DELETE) | |
| 240265 | + || (!bNew && pGrp->cd.eOp==SQLITE_INSERT) | |
| 240266 | + ){ | |
| 240267 | + rc = SQLITE_ERROR; | |
| 240268 | + }else{ | |
| 240269 | + SessionBuffer *pBuf = &pGrp->cd.aBuf[iCol]; | |
| 240270 | + if( pGrp->cd.eOp==SQLITE_UPDATE && bNew ){ | |
| 240271 | + pBuf += pGrp->cd.pTab->nCol; | |
| 240272 | + } | |
| 240273 | + pBuf->nBuf = 0; | |
| 240274 | + sessionBufferGrow(pBuf, nReq, &rc); | |
| 240275 | + pBuf->nBuf = nReq; | |
| 240276 | + *ppBuf = pBuf; | |
| 240277 | + } | |
| 240278 | + return rc; | |
| 240279 | +} | |
| 240280 | + | |
| 240281 | +/* | |
| 240282 | +** Configure the change currently under construction with an integer value. | |
| 240283 | +*/ | |
| 240284 | +SQLITE_API int sqlite3changegroup_change_int64( | |
| 240285 | + sqlite3_changegroup *pGrp, | |
| 240286 | + int bNew, | |
| 240287 | + int iCol, | |
| 240288 | + sqlite3_int64 iVal | |
| 240289 | +){ | |
| 240290 | + int rc = SQLITE_OK; | |
| 240291 | + SessionBuffer *pBuf = 0; | |
| 240292 | + | |
| 240293 | + if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, 9, &pBuf)) ){ | |
| 240294 | + return rc; | |
| 240295 | + } | |
| 240296 | + | |
| 240297 | + pBuf->aBuf[0] = SQLITE_INTEGER; | |
| 240298 | + sessionPutI64(&pBuf->aBuf[1], iVal); | |
| 240299 | + return SQLITE_OK; | |
| 240300 | +} | |
| 240301 | + | |
| 240302 | +/* | |
| 240303 | +** Configure the change currently under construction with a null value. | |
| 240304 | +*/ | |
| 240305 | +SQLITE_API int sqlite3changegroup_change_null( | |
| 240306 | + sqlite3_changegroup *pGrp, | |
| 240307 | + int bNew, | |
| 240308 | + int iCol | |
| 240309 | +){ | |
| 240310 | + int rc = SQLITE_OK; | |
| 240311 | + SessionBuffer *pBuf = 0; | |
| 240312 | + | |
| 240313 | + if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, 1, &pBuf)) ){ | |
| 240314 | + return rc; | |
| 240315 | + } | |
| 240316 | + | |
| 240317 | + pBuf->aBuf[0] = SQLITE_NULL; | |
| 240318 | + return SQLITE_OK; | |
| 240319 | +} | |
| 240320 | + | |
| 240321 | +/* | |
| 240322 | +** Configure the change currently under construction with a real value. | |
| 240323 | +*/ | |
| 240324 | +SQLITE_API int sqlite3changegroup_change_double( | |
| 240325 | + sqlite3_changegroup *pGrp, | |
| 240326 | + int bNew, | |
| 240327 | + int iCol, | |
| 240328 | + double fVal | |
| 240329 | +){ | |
| 240330 | + int rc = SQLITE_OK; | |
| 240331 | + SessionBuffer *pBuf = 0; | |
| 240332 | + | |
| 240333 | + if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, 9, &pBuf)) ){ | |
| 240334 | + return rc; | |
| 240335 | + } | |
| 240336 | + | |
| 240337 | + pBuf->aBuf[0] = SQLITE_FLOAT; | |
| 240338 | + sessionPutDouble(&pBuf->aBuf[1], fVal); | |
| 240339 | + return SQLITE_OK; | |
| 240340 | +} | |
| 240341 | + | |
| 240342 | +/* | |
| 240343 | +** Configure the change currently under construction with a text value. | |
| 240344 | +*/ | |
| 240345 | +SQLITE_API int sqlite3changegroup_change_text( | |
| 240346 | + sqlite3_changegroup *pGrp, | |
| 240347 | + int bNew, | |
| 240348 | + int iCol, | |
| 240349 | + const char *pVal, | |
| 240350 | + int nVal | |
| 240351 | +){ | |
| 240352 | + int nText = nVal>=0 ? nVal : strlen(pVal); | |
| 240353 | + sqlite3_int64 nByte = 1 + sessionVarintLen(nText) + nText; | |
| 240354 | + int rc = SQLITE_OK; | |
| 240355 | + SessionBuffer *pBuf = 0; | |
| 240356 | + | |
| 240357 | + if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, nByte, &pBuf)) ){ | |
| 240358 | + return rc; | |
| 240359 | + } | |
| 240360 | + | |
| 240361 | + pBuf->aBuf[0] = SQLITE_TEXT; | |
| 240362 | + pBuf->nBuf = (1 + sessionVarintPut(&pBuf->aBuf[1], nText)); | |
| 240363 | + memcpy(&pBuf->aBuf[pBuf->nBuf], pVal, nText); | |
| 240364 | + pBuf->nBuf += nText; | |
| 240365 | + | |
| 240366 | + return SQLITE_OK; | |
| 240367 | +} | |
| 240368 | + | |
| 240369 | +/* | |
| 240370 | +** Configure the change currently under construction with a blob value. | |
| 240371 | +*/ | |
| 240372 | +SQLITE_API int sqlite3changegroup_change_blob( | |
| 240373 | + sqlite3_changegroup *pGrp, | |
| 240374 | + int bNew, | |
| 240375 | + int iCol, | |
| 240376 | + const void *pVal, | |
| 240377 | + int nVal | |
| 240378 | +){ | |
| 240379 | + sqlite3_int64 nByte = 1 + sessionVarintLen(nVal) + nVal; | |
| 240380 | + int rc = SQLITE_OK; | |
| 240381 | + SessionBuffer *pBuf = 0; | |
| 240382 | + | |
| 240383 | + if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, nByte, &pBuf)) ){ | |
| 240384 | + return rc; | |
| 240385 | + } | |
| 240386 | + | |
| 240387 | + pBuf->aBuf[0] = SQLITE_BLOB; | |
| 240388 | + pBuf->nBuf = (1 + sessionVarintPut(&pBuf->aBuf[1], nVal)); | |
| 240389 | + memcpy(&pBuf->aBuf[pBuf->nBuf], pVal, nVal); | |
| 240390 | + pBuf->nBuf += nVal; | |
| 240391 | + | |
| 240392 | + return SQLITE_OK; | |
| 240393 | +} | |
| 240394 | + | |
| 240395 | +/* | |
| 240396 | +** Finish any change currently being constructed by the changegroup object. | |
| 240397 | +*/ | |
| 240398 | +SQLITE_API int sqlite3changegroup_change_finish( | |
| 240399 | + sqlite3_changegroup *pGrp, | |
| 240400 | + int bDiscard, | |
| 240401 | + char **pzErr | |
| 240402 | +){ | |
| 240403 | + int rc = SQLITE_OK; | |
| 240404 | + if( pGrp->cd.pTab ){ | |
| 240405 | + SessionBuffer *aBuf = pGrp->cd.aBuf; | |
| 240406 | + int ii; | |
| 240407 | + | |
| 240408 | + if( bDiscard==0 ){ | |
| 240409 | + int nBuf = pGrp->cd.pTab->nCol; | |
| 240410 | + u8 eUndef = SQLITE_NULL; | |
| 240411 | + if( pGrp->cd.eOp==SQLITE_UPDATE ){ | |
| 240412 | + for(ii=0; ii<nBuf; ii++){ | |
| 240413 | + if( pGrp->cd.pTab->abPK[ii] ){ | |
| 240414 | + if( aBuf[ii].nBuf<=1 ){ | |
| 240415 | + *pzErr = sqlite3_mprintf( | |
| 240416 | + "invalid change: %s value in PK of old.* record", | |
| 240417 | + aBuf[ii].nBuf==1 ? "null" : "undefined" | |
| 240418 | + ); | |
| 240419 | + rc = SQLITE_ERROR; | |
| 240420 | + break; | |
| 240421 | + }else if( aBuf[ii + nBuf].nBuf>0 ){ | |
| 240422 | + *pzErr = sqlite3_mprintf( | |
| 240423 | + "invalid change: defined value in PK of new.* record" | |
| 240424 | + ); | |
| 240425 | + rc = SQLITE_ERROR; | |
| 240426 | + break; | |
| 240427 | + } | |
| 240428 | + }else | |
| 240429 | + if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){ | |
| 240430 | + *pzErr = sqlite3_mprintf( | |
| 240431 | + "invalid change: column %d " | |
| 240432 | + "- old.* value is %sdefined but new.* is %sdefined", | |
| 240433 | + ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un" | |
| 240434 | + ); | |
| 240435 | + rc = SQLITE_ERROR; | |
| 240436 | + break; | |
| 240437 | + } | |
| 240438 | + } | |
| 240439 | + eUndef = 0x00; | |
| 240440 | + if( pGrp->bPatch==0 ) nBuf = nBuf * 2; | |
| 240441 | + }else{ | |
| 240442 | + for(ii=0; ii<nBuf; ii++){ | |
| 240443 | + int isPK = pGrp->cd.pTab->abPK[ii]; | |
| 240444 | + if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK) | |
| 240445 | + && aBuf[ii].nBuf==0 | |
| 240446 | + ){ | |
| 240447 | + *pzErr = sqlite3_mprintf( | |
| 240448 | + "invalid change: column %d is undefined", ii | |
| 240449 | + ); | |
| 240450 | + rc = SQLITE_ERROR; | |
| 240451 | + break; | |
| 240452 | + } | |
| 240453 | + if( aBuf[ii].nBuf==1 && isPK ){ | |
| 240454 | + *pzErr = sqlite3_mprintf( | |
| 240455 | + "invalid change: null value in PK" | |
| 240456 | + ); | |
| 240457 | + rc = SQLITE_ERROR; | |
| 240458 | + break; | |
| 240459 | + } | |
| 240460 | + } | |
| 240461 | + } | |
| 240462 | + | |
| 240463 | + pGrp->cd.record.nBuf = 0; | |
| 240464 | + for(ii=0; ii<nBuf; ii++){ | |
| 240465 | + SessionBuffer *p = &pGrp->cd.aBuf[ii]; | |
| 240466 | + if( pGrp->bPatch ){ | |
| 240467 | + if( pGrp->cd.pTab->abPK[ii]==0 ){ | |
| 240468 | + if( pGrp->cd.eOp==SQLITE_UPDATE ){ | |
| 240469 | + p += pGrp->cd.pTab->nCol; | |
| 240470 | + }else if( pGrp->cd.eOp==SQLITE_DELETE ){ | |
| 240471 | + continue; | |
| 240472 | + } | |
| 240473 | + } | |
| 240474 | + } | |
| 240475 | + if( 0==sessionBufferGrow(&pGrp->cd.record, p->nBuf?p->nBuf:1, &rc) ){ | |
| 240476 | + if( p->nBuf ){ | |
| 240477 | + memcpy(&pGrp->cd.record.aBuf[pGrp->cd.record.nBuf],p->aBuf,p->nBuf); | |
| 240478 | + pGrp->cd.record.nBuf += p->nBuf; | |
| 240479 | + }else{ | |
| 240480 | + pGrp->cd.record.aBuf[pGrp->cd.record.nBuf++] = eUndef; | |
| 240481 | + } | |
| 240482 | + } | |
| 240483 | + } | |
| 240484 | + if( rc==SQLITE_OK ){ | |
| 240485 | + rc = sessionOneChangeToHash( | |
| 240486 | + pGrp, pGrp->cd.pTab, | |
| 240487 | + pGrp->cd.eOp, pGrp->cd.bIndirect, pGrp->cd.pTab->nCol, | |
| 240488 | + pGrp->cd.record.aBuf, pGrp->cd.record.nBuf, 0 | |
| 240489 | + ); | |
| 240490 | + } | |
| 240491 | + } | |
| 240492 | + | |
| 240493 | + /* Reset all aBuf[] entries to "undefined". */ | |
| 240494 | + { | |
| 240495 | + int nZero = pGrp->cd.pTab->nCol; | |
| 240496 | + if( pGrp->cd.eOp==SQLITE_UPDATE ) nZero += nZero; | |
| 240497 | + for(ii=0; ii<nZero; ii++){ | |
| 240498 | + pGrp->cd.aBuf[ii].nBuf = 0; | |
| 240499 | + } | |
| 240500 | + } | |
| 240501 | + pGrp->cd.pTab = 0; | |
| 240502 | + } | |
| 240503 | + | |
| 239776 | 240504 | return rc; |
| 239777 | 240505 | } |
| 239778 | 240506 | |
| 239779 | 240507 | #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 239780 | 240508 | |
| @@ -262478,11 +263206,11 @@ | ||
| 262478 | 263206 | int nArg, /* Number of args */ |
| 262479 | 263207 | sqlite3_value **apUnused /* Function arguments */ |
| 262480 | 263208 | ){ |
| 262481 | 263209 | assert( nArg==0 ); |
| 262482 | 263210 | UNUSED_PARAM2(nArg, apUnused); |
| 262483 | - sqlite3_result_text(pCtx, "fts5: 2026-03-26 14:19:34 97ee48b6ef65fb55633196282c9e75b3b0a3b81ba9755f63493a38e3f1a5610c", -1, SQLITE_TRANSIENT); | |
| 263211 | + sqlite3_result_text(pCtx, "fts5: 2026-04-01 11:39:13 009b576dcd5fccaaa52459dbfaa1b2a6fcf6d372e4b8d63553dfa88aab9a759c", -1, SQLITE_TRANSIENT); | |
| 262484 | 263212 | } |
| 262485 | 263213 | |
| 262486 | 263214 | /* |
| 262487 | 263215 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 262488 | 263216 | ** |
| 262489 | 263217 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -16,11 +16,11 @@ | |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | ** |
| 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | ** c5af6a10245b6b847d30002806c1577b020c with changes in files: |
| 22 | ** |
| 23 | ** |
| 24 | */ |
| 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | #define SQLITE_CORE 1 |
| @@ -467,14 +467,14 @@ | |
| 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | */ |
| 470 | #define SQLITE_VERSION "3.53.0" |
| 471 | #define SQLITE_VERSION_NUMBER 3053000 |
| 472 | #define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c" |
| 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | #define SQLITE_SCM_TAGS "" |
| 475 | #define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z" |
| 476 | |
| 477 | /* |
| 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | ** |
| @@ -897,11 +897,11 @@ | |
| 897 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 898 | #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) |
| 899 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 900 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 901 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 902 | #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ |
| 903 | |
| 904 | /* |
| 905 | ** CAPI3REF: Flags For File Open Operations |
| 906 | ** |
| 907 | ** These bit values are intended for use in the |
| @@ -1609,10 +1609,16 @@ | |
| 1609 | /* deprecated names */ |
| 1610 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1611 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1612 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| 1613 | |
| 1614 | |
| 1615 | /* |
| 1616 | ** CAPI3REF: Mutex Handle |
| 1617 | ** |
| 1618 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2030,11 +2036,12 @@ | |
| 2030 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 2031 | ** The exceptional configuration options that may be invoked at any time |
| 2032 | ** are called "anytime configuration options". |
| 2033 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 2034 | ** [sqlite3_shutdown()] with a first argument that is not an anytime |
| 2035 | ** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE. |
| 2036 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 2037 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 2038 | ** |
| 2039 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 2040 | ** ^If the option is unknown or SQLite is unable to set the option |
| @@ -2596,13 +2603,14 @@ | |
| 2596 | ** <li><P>The second argument ("sz") is the |
| 2597 | ** size of each lookaside buffer slot. Lookaside is disabled if "sz" |
| 2598 | ** is less than 8. The "sz" argument should be a multiple of 8 less than |
| 2599 | ** 65536. If "sz" does not meet this constraint, it is reduced in size until |
| 2600 | ** it does. |
| 2601 | ** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled |
| 2602 | ** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so |
| 2603 | ** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" |
| 2604 | ** parameter is usually chosen so that the product of "sz" and "cnt" is less |
| 2605 | ** than 1,000,000. |
| 2606 | ** </ol> |
| 2607 | ** <p>If the "buf" argument is not NULL, then it must |
| 2608 | ** point to a memory buffer with a size that is greater than |
| @@ -2977,11 +2985,11 @@ | |
| 2977 | ** default value 17, as of SQLite version 3.52.0. The value was 15 in all |
| 2978 | ** prior versions.<p> |
| 2979 | ** This option takes two arguments which are an integer and a pointer |
| 2980 | ** to an integer. The first argument is a small integer, between 3 and 23, or |
| 2981 | ** zero. The FP_DIGITS setting is changed to that small integer, or left |
| 2982 | ** unaltered if the first argument is zero or out of range. The second argument |
| 2983 | ** is a pointer to an integer. If the pointer is not NULL, then the value of |
| 2984 | ** the FP_DIGITS setting, after possibly being modified by the first |
| 2985 | ** arguments, is written into the integer to which the second argument points. |
| 2986 | ** </dd> |
| 2987 | ** |
| @@ -2989,14 +2997,16 @@ | |
| 2989 | ** |
| 2990 | ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3> |
| 2991 | ** |
| 2992 | ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the |
| 2993 | ** overall call to [sqlite3_db_config()] has a total of four parameters. |
| 2994 | ** The first argument (the third parameter to sqlite3_db_config()) is an integer. |
| 2995 | ** The second argument is a pointer to an integer. If the first argument is 1, |
| 2996 | ** then the option becomes enabled. If the first integer argument is 0, then the |
| 2997 | ** option is disabled. If the first argument is -1, then the option setting |
| 2998 | ** is unchanged. The second argument, the pointer to an integer, may be NULL. |
| 2999 | ** If the second argument is not NULL, then a value of 0 or 1 is written into |
| 3000 | ** the integer to which the second argument points, depending on whether the |
| 3001 | ** setting is disabled or enabled after applying any changes specified by |
| 3002 | ** the first argument. |
| @@ -6169,12 +6179,13 @@ | |
| 6169 | ** that the application-defined collating sequence created expects its |
| 6170 | ** input strings to be in UTF16 in native byte order, and that the start |
| 6171 | ** of the strings must be aligned to a 2-byte boundary. |
| 6172 | ** |
| 6173 | ** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be |
| 6174 | ** used to specify the text encoding to strings input to [sqlite3_result_text64()] |
| 6175 | ** and [sqlite3_bind_text64()]. It means that the input string (call it "z") |
| 6176 | ** is UTF-8 encoded and that it is zero-terminated. If the length parameter |
| 6177 | ** (call it "n") is non-negative, this encoding option means that the caller |
| 6178 | ** guarantees that z array contains at least n+1 bytes and that the z[n] |
| 6179 | ** byte has a value of zero. |
| 6180 | ** This option gives the same output as SQLITE_UTF8, but can be more efficient |
| @@ -6422,30 +6433,26 @@ | |
| 6422 | ** |
| 6423 | ** These routines must be called from the same thread as |
| 6424 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 6425 | ** |
| 6426 | ** As long as the input parameter is correct, these routines can only |
| 6427 | ** fail if an out-of-memory error occurs during a format conversion. |
| 6428 | ** Only the following subset of interfaces are subject to out-of-memory |
| 6429 | ** errors: |
| 6430 | ** |
| 6431 | ** <ul> |
| 6432 | ** <li> sqlite3_value_blob() |
| 6433 | ** <li> sqlite3_value_text() |
| 6434 | ** <li> sqlite3_value_text16() |
| 6435 | ** <li> sqlite3_value_text16le() |
| 6436 | ** <li> sqlite3_value_text16be() |
| 6437 | ** <li> sqlite3_value_bytes() |
| 6438 | ** <li> sqlite3_value_bytes16() |
| 6439 | ** </ul> |
| 6440 | ** |
| 6441 | ** If an out-of-memory error occurs, then the return value from these |
| 6442 | ** routines is the same as if the column had contained an SQL NULL value. |
| 6443 | ** Valid SQL NULL returns can be distinguished from out-of-memory errors |
| 6444 | ** by invoking the [sqlite3_errcode()] immediately after the suspect |
| 6445 | ** return value is obtained and before any |
| 6446 | ** other SQLite interface is called on the same [database connection]. |
| 6447 | */ |
| 6448 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 6449 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 6450 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 6451 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| @@ -6468,11 +6475,12 @@ | |
| 6468 | ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
| 6469 | ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding |
| 6470 | ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
| 6471 | ** returns something other than SQLITE_TEXT, then the return value from |
| 6472 | ** sqlite3_value_encoding(X) is meaningless. ^Calls to |
| 6473 | ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)], |
| 6474 | ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or |
| 6475 | ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and |
| 6476 | ** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
| 6477 | ** |
| 6478 | ** This routine is intended for used by applications that test and validate |
| @@ -6599,21 +6607,21 @@ | |
| 6599 | ** associate auxiliary data with argument values. If the same argument |
| 6600 | ** value is passed to multiple invocations of the same SQL function during |
| 6601 | ** query execution, under some circumstances the associated auxiliary data |
| 6602 | ** might be preserved. An example of where this might be useful is in a |
| 6603 | ** regular-expression matching function. The compiled version of the regular |
| 6604 | ** expression can be stored as auxiliary data associated with the pattern string. |
| 6605 | ** Then as long as the pattern string remains the same, |
| 6606 | ** the compiled regular expression can be reused on multiple |
| 6607 | ** invocations of the same function. |
| 6608 | ** |
| 6609 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data |
| 6610 | ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument |
| 6611 | ** value to the application-defined function. ^N is zero for the left-most |
| 6612 | ** function argument. ^If there is no auxiliary data |
| 6613 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface |
| 6614 | ** returns a NULL pointer. |
| 6615 | ** |
| 6616 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the |
| 6617 | ** N-th argument of the application-defined function. ^Subsequent |
| 6618 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| 6619 | ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or |
| @@ -10722,21 +10730,22 @@ | |
| 10722 | ** |
| 10723 | ** <table border=1 cellspacing=0 cellpadding=10 width="90%"> |
| 10724 | ** <tr> |
| 10725 | ** <td valign="top">sqlite3_vtab_distinct() return value |
| 10726 | ** <td valign="top">Rows are returned in aOrderBy order |
| 10727 | ** <td valign="top">Rows with the same value in all aOrderBy columns are adjacent |
| 10728 | ** <td valign="top">Duplicates over all colUsed columns may be omitted |
| 10729 | ** <tr><td>0<td>yes<td>yes<td>no |
| 10730 | ** <tr><td>1<td>no<td>yes<td>no |
| 10731 | ** <tr><td>2<td>no<td>yes<td>yes |
| 10732 | ** <tr><td>3<td>yes<td>yes<td>yes |
| 10733 | ** </table> |
| 10734 | ** |
| 10735 | ** ^For the purposes of comparing virtual table output values to see if the |
| 10736 | ** values are the same value for sorting purposes, two NULL values are considered |
| 10737 | ** to be the same. In other words, the comparison operator is "IS" |
| 10738 | ** (or "IS NOT DISTINCT FROM") and not "==". |
| 10739 | ** |
| 10740 | ** If a virtual table implementation is unable to meet the requirements |
| 10741 | ** specified above, then it must not set the "orderByConsumed" flag in the |
| 10742 | ** [sqlite3_index_info] object or an incorrect answer may result. |
| @@ -11586,16 +11595,17 @@ | |
| 11586 | /* |
| 11587 | ** CAPI3REF: Bind array values to the CARRAY table-valued function |
| 11588 | ** |
| 11589 | ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to |
| 11590 | ** parameter that is the first argument of the [carray() table-valued function]. |
| 11591 | ** The S parameter is a pointer to the [prepared statement] that uses the carray() |
| 11592 | ** functions. I is the parameter index to be bound. I must be the index of the |
| 11593 | ** parameter that is the first argument to the carray() table-valued function. |
| 11594 | ** P is a pointer to the array to be bound, and N is the number of elements in |
| 11595 | ** the array. The F argument is one of constants [SQLITE_CARRAY_INT32], |
| 11596 | ** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], |
| 11597 | ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P. |
| 11598 | ** |
| 11599 | ** If the X argument is not a NULL pointer or one of the special |
| 11600 | ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke |
| 11601 | ** the function X with argument D when it is finished using the data in P. |
| @@ -13648,10 +13658,236 @@ | |
| 13648 | |
| 13649 | /* |
| 13650 | ** CAPI3REF: Values for sqlite3session_config(). |
| 13651 | */ |
| 13652 | #define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 13653 | |
| 13654 | /* |
| 13655 | ** Make sure we can call this stuff from C++. |
| 13656 | */ |
| 13657 | #if 0 |
| @@ -21585,21 +21821,26 @@ | |
| 21585 | int nArg; /* Total number of arguments */ |
| 21586 | int nUsed; /* Number of arguments used so far */ |
| 21587 | sqlite3_value **apArg; /* The argument values */ |
| 21588 | }; |
| 21589 | |
| 21590 | /* |
| 21591 | ** An instance of this object receives the decoding of a floating point |
| 21592 | ** value into an approximate decimal representation. |
| 21593 | */ |
| 21594 | struct FpDecode { |
| 21595 | int n; /* Significant digits in the decode */ |
| 21596 | int iDP; /* Location of the decimal point */ |
| 21597 | char *z; /* Start of significant digits */ |
| 21598 | char zBuf[20]; /* Storage for significant digits */ |
| 21599 | char sign; /* '+' or '-' */ |
| 21600 | char isSpecial; /* 1: Infinity 2: NaN */ |
| 21601 | }; |
| 21602 | |
| 21603 | SQLITE_PRIVATE void sqlite3FpDecode(FpDecode*,double,int,int); |
| 21604 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 21605 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| @@ -22283,10 +22524,11 @@ | |
| 22283 | SQLITE_PRIVATE char *sqlite3RCStrNew(u64); |
| 22284 | SQLITE_PRIVATE char *sqlite3RCStrResize(char*,u64); |
| 22285 | |
| 22286 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| 22287 | SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64); |
| 22288 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 22289 | SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8); |
| 22290 | SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); |
| 22291 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 22292 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| @@ -32635,10 +32877,11 @@ | |
| 32635 | case etEXP: |
| 32636 | case etGENERIC: { |
| 32637 | FpDecode s; |
| 32638 | int iRound; |
| 32639 | int j; |
| 32640 | |
| 32641 | if( bArgList ){ |
| 32642 | realvalue = getDoubleArg(pArgList); |
| 32643 | }else{ |
| 32644 | realvalue = va_arg(ap,double); |
| @@ -32723,21 +32966,19 @@ | |
| 32723 | if( xtype==etEXP ){ |
| 32724 | e2 = 0; |
| 32725 | }else{ |
| 32726 | e2 = s.iDP - 1; |
| 32727 | } |
| 32728 | bufpt = buf; |
| 32729 | { |
| 32730 | i64 szBufNeeded; /* Size of a temporary buffer needed */ |
| 32731 | szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; |
| 32732 | if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; |
| 32733 | if( szBufNeeded > etBUFSIZE ){ |
| 32734 | bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded); |
| 32735 | if( bufpt==0 ) return; |
| 32736 | } |
| 32737 | } |
| 32738 | zOut = bufpt; |
| 32739 | flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; |
| 32740 | /* The sign in front of the number */ |
| 32741 | if( prefix ){ |
| 32742 | *(bufpt++) = prefix; |
| 32743 | } |
| @@ -32781,17 +33022,15 @@ | |
| 32781 | int nn = s.n - j; |
| 32782 | if( NEVER(nn>precision) ) nn = precision; |
| 32783 | if( nn>0 ){ |
| 32784 | memcpy(bufpt, s.z+j, nn); |
| 32785 | bufpt += nn; |
| 32786 | j += nn; |
| 32787 | precision -= nn; |
| 32788 | } |
| 32789 | if( precision>0 && !flag_rtz ){ |
| 32790 | memset(bufpt, '0', precision); |
| 32791 | bufpt += precision; |
| 32792 | precision = 0; |
| 32793 | } |
| 32794 | } |
| 32795 | /* Remove trailing zeros and the "." if no digits follow the "." */ |
| 32796 | if( flag_rtz && flag_dp ){ |
| 32797 | while( bufpt[-1]=='0' ) *(--bufpt) = 0; |
| @@ -32818,31 +33057,35 @@ | |
| 32818 | exp %= 100; |
| 32819 | } |
| 32820 | *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */ |
| 32821 | *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */ |
| 32822 | } |
| 32823 | *bufpt = 0; |
| 32824 | |
| 32825 | /* The converted number is in buf[] and zero terminated. Output it. |
| 32826 | ** Note that the number is in the usual order, not reversed as with |
| 32827 | ** integer conversions. */ |
| 32828 | length = (int)(bufpt-zOut); |
| 32829 | bufpt = zOut; |
| 32830 | |
| 32831 | /* Special case: Add leading zeros if the flag_zeropad flag is |
| 32832 | ** set and we are not left justified */ |
| 32833 | if( flag_zeropad && !flag_leftjustify && length < width){ |
| 32834 | int i; |
| 32835 | int nPad = width - length; |
| 32836 | for(i=width; i>=nPad; i--){ |
| 32837 | bufpt[i] = bufpt[i-nPad]; |
| 32838 | } |
| 32839 | i = prefix!=0; |
| 32840 | while( nPad-- ) bufpt[i++] = '0'; |
| 32841 | length = width; |
| 32842 | } |
| 32843 | break; |
| 32844 | } |
| 32845 | case etSIZE: |
| 32846 | if( !bArgList ){ |
| 32847 | *(va_arg(ap,int*)) = pAccum->nChar; |
| 32848 | } |
| @@ -32882,15 +33125,14 @@ | |
| 32882 | precision--; |
| 32883 | while( precision > 1 ){ |
| 32884 | i64 nCopyBytes; |
| 32885 | if( nPrior > precision-1 ) nPrior = precision - 1; |
| 32886 | nCopyBytes = length*nPrior; |
| 32887 | if( nCopyBytes + pAccum->nChar >= pAccum->nAlloc ){ |
| 32888 | sqlite3StrAccumEnlarge(pAccum, nCopyBytes); |
| 32889 | } |
| 32890 | if( pAccum->accError ) break; |
| 32891 | sqlite3_str_append(pAccum, |
| 32892 | &pAccum->zText[pAccum->nChar-nCopyBytes], nCopyBytes); |
| 32893 | precision -= nPrior; |
| 32894 | nPrior *= 2; |
| 32895 | } |
| 32896 | } |
| @@ -33231,10 +33473,17 @@ | |
| 33231 | } |
| 33232 | } |
| 33233 | assert( N>=0 && N<=0x7fffffff ); |
| 33234 | return (int)N; |
| 33235 | } |
| 33236 | |
| 33237 | /* |
| 33238 | ** Append N copies of character c to the given string buffer. |
| 33239 | */ |
| 33240 | SQLITE_API void sqlite3_str_appendchar(sqlite3_str *p, int N, char c){ |
| @@ -36548,15 +36797,16 @@ | |
| 36548 | ** lower 64-bits of the result into *pLo, and return the high-order |
| 36549 | ** 64 bits. |
| 36550 | */ |
| 36551 | static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){ |
| 36552 | #if (defined(__GNUC__) || defined(__clang__)) \ |
| 36553 | && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) |
| 36554 | __uint128_t r = (__uint128_t)a * b; |
| 36555 | *pLo = (u64)r; |
| 36556 | return (u64)(r>>64); |
| 36557 | #elif defined(_MSC_VER) && defined(_M_X64) |
| 36558 | *pLo = a*b; |
| 36559 | return __umulh(a, b); |
| 36560 | #else |
| 36561 | u64 a0 = (u32)a; |
| 36562 | u64 a1 = a >> 32; |
| @@ -36583,21 +36833,23 @@ | |
| 36583 | ** |
| 36584 | ** The lower 64 bits of A*B are discarded. |
| 36585 | */ |
| 36586 | static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){ |
| 36587 | #if (defined(__GNUC__) || defined(__clang__)) \ |
| 36588 | && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) |
| 36589 | __uint128_t r = (__uint128_t)a * b; |
| 36590 | r += ((__uint128_t)aLo * b) >> 32; |
| 36591 | *pLo = (r>>32)&0xffffffff; |
| 36592 | return r>>64; |
| 36593 | #elif defined(_MSC_VER) && defined(_M_X64) |
| 36594 | u64 r1_hi = __umulh(a,b); |
| 36595 | u64 r1_lo = a*b; |
| 36596 | u64 r2 = (__umulh((u64)aLo,b)<<32) + ((aLo*b)>>32); |
| 36597 | r1_hi += _addcarry_u64(0, r1_lo, r2, &r1_lo); |
| 36598 | *pLo = r1_lo>>32; |
| 36599 | return r1_hi; |
| 36600 | #else |
| 36601 | u64 x2 = a>>32; |
| 36602 | u64 x1 = a&0xffffffff; |
| 36603 | u64 x0 = aLo; |
| @@ -36805,11 +37057,12 @@ | |
| 36805 | |
| 36806 | /* |
| 36807 | ** Count leading zeros for a 64-bit unsigned integer. |
| 36808 | */ |
| 36809 | static int countLeadingZeros(u64 m){ |
| 36810 | #if defined(__GNUC__) || defined(__clang__) |
| 36811 | return __builtin_clzll(m); |
| 36812 | #else |
| 36813 | int n = 0; |
| 36814 | if( m <= 0x00000000ffffffffULL) { n += 32; m <<= 32; } |
| 36815 | if( m <= 0x0000ffffffffffffULL) { n += 16; m <<= 16; } |
| @@ -36906,16 +37159,19 @@ | |
| 36906 | ** Return positive if the result is a valid real number (or integer) and |
| 36907 | ** zero or negative if the string is empty or contains extraneous text. |
| 36908 | ** Lower bits of the return value contain addition information about the |
| 36909 | ** parse: |
| 36910 | ** |
| 36911 | ** bit 0 => Set for any valid input |
| 36912 | ** bit 1 => Input contains a decimal point or eNNN clause |
| 36913 | ** This bit is zero if the input is an integer |
| 36914 | ** bit 2 => The input is exactly 0.0, not an underflow from |
| 36915 | ** some value near zero |
| 36916 | ** bit 3 => More than 19 significant digits in the input |
| 36917 | ** |
| 36918 | ** If the input contains a syntax error but begins with text that might |
| 36919 | ** be a valid number of some kind, then the result is negative. The |
| 36920 | ** result is only zero if no prefix of the input could be interpreted as |
| 36921 | ** a number. |
| @@ -37077,10 +37333,73 @@ | |
| 37077 | "70717273747576777879" |
| 37078 | "80818283848586878889" |
| 37079 | "90919293949596979899" |
| 37080 | }; |
| 37081 | |
| 37082 | |
| 37083 | /* |
| 37084 | ** Render an signed 64-bit integer as text. Store the result in zOut[] and |
| 37085 | ** return the length of the string that was stored, in bytes. The value |
| 37086 | ** returned does not include the zero terminator at the end of the output |
| @@ -37090,11 +37409,11 @@ | |
| 37090 | */ |
| 37091 | SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){ |
| 37092 | int i; |
| 37093 | u64 x; |
| 37094 | union { |
| 37095 | char a[23]; |
| 37096 | u16 forceAlignment; |
| 37097 | } u; |
| 37098 | if( v>0 ){ |
| 37099 | x = v; |
| 37100 | }else if( v==0 ){ |
| @@ -37102,10 +37421,13 @@ | |
| 37102 | zOut[1] = 0; |
| 37103 | return 1; |
| 37104 | }else{ |
| 37105 | x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v; |
| 37106 | } |
| 37107 | i = sizeof(u.a)-1; |
| 37108 | u.a[i] = 0; |
| 37109 | while( x>=10 ){ |
| 37110 | int kk = (x%100)*2; |
| 37111 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) ); |
| @@ -37115,10 +37437,11 @@ | |
| 37115 | x /= 100; |
| 37116 | } |
| 37117 | if( x ){ |
| 37118 | u.a[--i] = x + '0'; |
| 37119 | } |
| 37120 | if( v<0 ) u.a[--i] = '-'; |
| 37121 | memcpy(zOut, &u.a[i], sizeof(u.a)-i); |
| 37122 | return sizeof(u.a)-1-i; |
| 37123 | } |
| 37124 | |
| @@ -37434,41 +37757,47 @@ | |
| 37434 | sqlite3Fp2Convert10(v, e, (iRound<=0||iRound>=18)?18:iRound+1, &v, &exp); |
| 37435 | |
| 37436 | /* Extract significant digits, start at the right-most slot in p->zBuf |
| 37437 | ** and working back to the right. "i" keeps track of the next slot in |
| 37438 | ** which to store a digit. */ |
| 37439 | i = sizeof(p->zBuf)-1; |
| 37440 | zBuf = p->zBuf; |
| 37441 | assert( v>0 ); |
| 37442 | while( v>=10 ){ |
| 37443 | int kk = (v%100)*2; |
| 37444 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) ); |
| 37445 | assert( TWO_BYTE_ALIGNMENT(&zBuf[i-1]) ); |
| 37446 | *(u16*)(&zBuf[i-1]) = *(u16*)&sqlite3DigitPairs.a[kk]; |
| 37447 | i -= 2; |
| 37448 | v /= 100; |
| 37449 | } |
| 37450 | if( v ){ |
| 37451 | assert( v<10 ); |
| 37452 | zBuf[i--] = v + '0'; |
| 37453 | } |
| 37454 | assert( i>=0 && i<sizeof(p->zBuf)-1 ); |
| 37455 | n = sizeof(p->zBuf) - 1 - i; /* Total number of digits extracted */ |
| 37456 | assert( n>0 ); |
| 37457 | assert( n<sizeof(p->zBuf) ); |
| 37458 | testcase( n==sizeof(p->zBuf)-1 ); |
| 37459 | p->iDP = n + exp; |
| 37460 | if( iRound<=0 ){ |
| 37461 | iRound = p->iDP - iRound; |
| 37462 | if( iRound==0 && zBuf[i+1]>='5' ){ |
| 37463 | iRound = 1; |
| 37464 | zBuf[i--] = '0'; |
| 37465 | n++; |
| 37466 | p->iDP++; |
| 37467 | } |
| 37468 | } |
| 37469 | z = &zBuf[i+1]; /* z points to the first digit */ |
| 37470 | if( iRound>0 && (iRound<n || n>mxRound) ){ |
| 37471 | if( iRound>mxRound ) iRound = mxRound; |
| 37472 | if( iRound==17 ){ |
| 37473 | /* If the precision is exactly 17, which only happens with the "!" |
| 37474 | ** flag (ex: "%!.17g") then try to reduce the precision if that |
| @@ -85833,11 +86162,11 @@ | |
| 85833 | ** rc>0 => All of the input is well-formed |
| 85834 | ** (rc&2)==0 => The number is expressed as an integer, with no |
| 85835 | ** decimal point or eNNN suffix. |
| 85836 | */ |
| 85837 | SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem *pMem, double *pValue){ |
| 85838 | assert( pMem->db!=0 ); |
| 85839 | assert( pMem->flags & (MEM_Str|MEM_Blob) ); |
| 85840 | if( pMem->z==0 ){ |
| 85841 | *pValue = 0.0; |
| 85842 | return 0; |
| 85843 | }else if( pMem->enc==SQLITE_UTF8 |
| @@ -131514,11 +131843,10 @@ | |
| 131514 | ** forms 2 through 5, then rebuild the union of all matching indexes, |
| 131515 | ** taken care to avoid rebuilding the same index more than once. |
| 131516 | */ |
| 131517 | #ifndef SQLITE_OMIT_REINDEX |
| 131518 | SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){ |
| 131519 | CollSeq *pColl; /* Collating sequence to be reindexed, or NULL */ |
| 131520 | char *z = 0; /* Name of a table or index or collation */ |
| 131521 | const char *zDb = 0; /* Name of the database */ |
| 131522 | int iReDb = -1; /* The database index number */ |
| 131523 | sqlite3 *db = pParse->db; /* The database connection */ |
| 131524 | Token *pObjName; /* Name of the table or index to be reindexed */ |
| @@ -131553,11 +131881,11 @@ | |
| 131553 | if( !bAll ){ |
| 131554 | if( zDb==0 && sqlite3StrICmp(z, "expressions")==0 ){ |
| 131555 | isExprIdx = 1; |
| 131556 | bMatch = 1; |
| 131557 | } |
| 131558 | if( zDb==0 && (pColl = sqlite3FindCollSeq(db, ENC(db), z, 0))!=0 ){ |
| 131559 | zColl = z; |
| 131560 | bMatch = 1; |
| 131561 | } |
| 131562 | if( zColl==0 && (pReTab = sqlite3FindTable(db, z, zDb))!=0 ){ |
| 131563 | bMatch = 1; |
| @@ -134449,22 +134777,15 @@ | |
| 134449 | ** require enhancements to the implementation. */ |
| 134450 | assert( pStr!=0 && pStr->nChar==0 ); |
| 134451 | |
| 134452 | switch( sqlite3_value_type(pValue) ){ |
| 134453 | case SQLITE_FLOAT: { |
| 134454 | double r1, r2; |
| 134455 | const char *zVal; |
| 134456 | r1 = sqlite3_value_double(pValue); |
| 134457 | sqlite3_str_appendf(pStr, "%!0.15g", r1); |
| 134458 | zVal = sqlite3_str_value(pStr); |
| 134459 | if( zVal ){ |
| 134460 | sqlite3AtoF(zVal, &r2); |
| 134461 | if( r1!=r2 ){ |
| 134462 | sqlite3_str_reset(pStr); |
| 134463 | sqlite3_str_appendf(pStr, "%!0.20e", r1); |
| 134464 | } |
| 134465 | } |
| 134466 | break; |
| 134467 | } |
| 134468 | case SQLITE_INTEGER: { |
| 134469 | sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue)); |
| 134470 | break; |
| @@ -186195,11 +186516,11 @@ | |
| 186195 | if( db->mallocFailed ){ |
| 186196 | pParse->rc = SQLITE_NOMEM_BKPT; |
| 186197 | } |
| 186198 | if( pParse->zErrMsg || (pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE) ){ |
| 186199 | if( pParse->zErrMsg==0 ){ |
| 186200 | pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc)); |
| 186201 | } |
| 186202 | if( (pParse->prepFlags & SQLITE_PREPARE_DONT_LOG)==0 ){ |
| 186203 | sqlite3_log(pParse->rc, "%s in \"%s\"", pParse->zErrMsg, pParse->zTail); |
| 186204 | } |
| 186205 | nErr++; |
| @@ -233377,10 +233698,23 @@ | |
| 233377 | aBuf[4] = (i>>24) & 0xFF; |
| 233378 | aBuf[5] = (i>>16) & 0xFF; |
| 233379 | aBuf[6] = (i>> 8) & 0xFF; |
| 233380 | aBuf[7] = (i>> 0) & 0xFF; |
| 233381 | } |
| 233382 | |
| 233383 | /* |
| 233384 | ** This function is used to serialize the contents of value pValue (see |
| 233385 | ** comment titled "RECORD FORMAT" above). |
| 233386 | ** |
| @@ -233415,20 +233749,17 @@ | |
| 233415 | case SQLITE_FLOAT: |
| 233416 | if( aBuf ){ |
| 233417 | /* TODO: SQLite does something special to deal with mixed-endian |
| 233418 | ** floating point values (e.g. ARM7). This code probably should |
| 233419 | ** too. */ |
| 233420 | u64 i; |
| 233421 | if( eType==SQLITE_INTEGER ){ |
| 233422 | i = (u64)sqlite3_value_int64(pValue); |
| 233423 | }else{ |
| 233424 | double r; |
| 233425 | assert( sizeof(double)==8 && sizeof(u64)==8 ); |
| 233426 | r = sqlite3_value_double(pValue); |
| 233427 | memcpy(&i, &r, 8); |
| 233428 | } |
| 233429 | sessionPutI64(&aBuf[1], i); |
| 233430 | } |
| 233431 | nByte = 9; |
| 233432 | break; |
| 233433 | |
| 233434 | default: { |
| @@ -234356,13 +234687,11 @@ | |
| 234356 | break; |
| 234357 | } |
| 234358 | |
| 234359 | case SQLITE_FLOAT: { |
| 234360 | double rVal = sqlite3_column_double(pDflt, iField); |
| 234361 | i64 iVal = 0; |
| 234362 | memcpy(&iVal, &rVal, sizeof(rVal)); |
| 234363 | sessionPutI64(&pNew->aRecord[pNew->nRecord], iVal); |
| 234364 | pNew->nRecord += 8; |
| 234365 | break; |
| 234366 | } |
| 234367 | |
| 234368 | case SQLITE_TEXT: { |
| @@ -235615,19 +235944,18 @@ | |
| 235615 | ){ |
| 235616 | if( *pRc==SQLITE_OK ){ |
| 235617 | int eType = sqlite3_column_type(pStmt, iCol); |
| 235618 | sessionAppendByte(p, (u8)eType, pRc); |
| 235619 | if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 235620 | sqlite3_int64 i; |
| 235621 | u8 aBuf[8]; |
| 235622 | if( eType==SQLITE_INTEGER ){ |
| 235623 | i = sqlite3_column_int64(pStmt, iCol); |
| 235624 | }else{ |
| 235625 | double r = sqlite3_column_double(pStmt, iCol); |
| 235626 | memcpy(&i, &r, 8); |
| 235627 | } |
| 235628 | sessionPutI64(aBuf, i); |
| 235629 | sessionAppendBlob(p, aBuf, 8, pRc); |
| 235630 | } |
| 235631 | if( eType==SQLITE_BLOB || eType==SQLITE_TEXT ){ |
| 235632 | u8 *z; |
| 235633 | int nByte; |
| @@ -238664,10 +238992,25 @@ | |
| 238664 | xFilter, 0, xConflict, pCtx, |
| 238665 | 0, 0, 0 |
| 238666 | ); |
| 238667 | } |
| 238668 | |
| 238669 | /* |
| 238670 | ** sqlite3_changegroup handle. |
| 238671 | */ |
| 238672 | struct sqlite3_changegroup { |
| 238673 | int rc; /* Error code */ |
| @@ -238675,10 +239018,11 @@ | |
| 238675 | SessionTable *pList; /* List of tables in current patch */ |
| 238676 | SessionBuffer rec; |
| 238677 | |
| 238678 | sqlite3 *db; /* Configured by changegroup_schema() */ |
| 238679 | char *zDb; /* Configured by changegroup_schema() */ |
| 238680 | }; |
| 238681 | |
| 238682 | /* |
| 238683 | ** This function is called to merge two changes to the same row together as |
| 238684 | ** part of an sqlite3changeset_concat() operation. A new change object is |
| @@ -238914,19 +239258,18 @@ | |
| 238914 | int eType = sqlite3_column_type(pTab->pDfltStmt, ii); |
| 238915 | sessionAppendByte(pOut, eType, &rc); |
| 238916 | switch( eType ){ |
| 238917 | case SQLITE_FLOAT: |
| 238918 | case SQLITE_INTEGER: { |
| 238919 | i64 iVal; |
| 238920 | if( eType==SQLITE_INTEGER ){ |
| 238921 | iVal = sqlite3_column_int64(pTab->pDfltStmt, ii); |
| 238922 | }else{ |
| 238923 | double rVal = sqlite3_column_int64(pTab->pDfltStmt, ii); |
| 238924 | memcpy(&iVal, &rVal, sizeof(i64)); |
| 238925 | } |
| 238926 | if( SQLITE_OK==sessionBufferGrow(pOut, 8, &rc) ){ |
| 238927 | sessionPutI64(&pOut->aBuf[pOut->nBuf], iVal); |
| 238928 | pOut->nBuf += 8; |
| 238929 | } |
| 238930 | break; |
| 238931 | } |
| 238932 | |
| @@ -238993,17 +239336,23 @@ | |
| 238993 | int nTab = (int)strlen(zTab); |
| 238994 | u8 *abPK = 0; |
| 238995 | int nCol = 0; |
| 238996 | |
| 238997 | *ppTab = 0; |
| 238998 | sqlite3changeset_pk(pIter, &abPK, &nCol); |
| 238999 | |
| 239000 | /* Search the list for an existing table */ |
| 239001 | for(pTab = pGrp->pList; pTab; pTab=pTab->pNext){ |
| 239002 | if( 0==sqlite3_strnicmp(pTab->zName, zTab, nTab+1) ) break; |
| 239003 | } |
| 239004 | |
| 239005 | /* If one was not found above, create a new table now */ |
| 239006 | if( !pTab ){ |
| 239007 | SessionTable **ppNew; |
| 239008 | |
| 239009 | pTab = sqlite3_malloc64(sizeof(SessionTable) + nCol + nTab+1); |
| @@ -239018,12 +239367,12 @@ | |
| 239018 | memcpy(pTab->zName, zTab, nTab+1); |
| 239019 | |
| 239020 | if( pGrp->db ){ |
| 239021 | pTab->nCol = 0; |
| 239022 | rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb); |
| 239023 | if( rc ){ |
| 239024 | assert( pTab->azCol==0 ); |
| 239025 | sqlite3_free(pTab); |
| 239026 | return rc; |
| 239027 | } |
| 239028 | } |
| 239029 | |
| @@ -239034,78 +239383,61 @@ | |
| 239034 | for(ppNew=&pGrp->pList; *ppNew; ppNew=&(*ppNew)->pNext); |
| 239035 | *ppNew = pTab; |
| 239036 | } |
| 239037 | |
| 239038 | /* Check that the table is compatible. */ |
| 239039 | if( !sessionChangesetCheckCompat(pTab, nCol, abPK) ){ |
| 239040 | rc = SQLITE_SCHEMA; |
| 239041 | } |
| 239042 | |
| 239043 | *ppTab = pTab; |
| 239044 | return rc; |
| 239045 | } |
| 239046 | |
| 239047 | /* |
| 239048 | ** Add the change currently indicated by iterator pIter to the hash table |
| 239049 | ** belonging to changegroup pGrp. |
| 239050 | */ |
| 239051 | static int sessionOneChangeToHash( |
| 239052 | sqlite3_changegroup *pGrp, |
| 239053 | sqlite3_changeset_iter *pIter, |
| 239054 | int bRebase |
| 239055 | ){ |
| 239056 | int rc = SQLITE_OK; |
| 239057 | int nCol = 0; |
| 239058 | int op = 0; |
| 239059 | int iHash = 0; |
| 239060 | int bIndirect = 0; |
| 239061 | SessionChange *pChange = 0; |
| 239062 | SessionChange *pExist = 0; |
| 239063 | SessionChange **pp = 0; |
| 239064 | SessionTable *pTab = 0; |
| 239065 | u8 *aRec = &pIter->in.aData[pIter->in.iCurrent + 2]; |
| 239066 | int nRec = (pIter->in.iNext - pIter->in.iCurrent) - 2; |
| 239067 | |
| 239068 | assert( nRec>0 ); |
| 239069 | |
| 239070 | /* Ensure that only changesets, or only patchsets, but not a mixture |
| 239071 | ** of both, are being combined. It is an error to try to combine a |
| 239072 | ** changeset and a patchset. */ |
| 239073 | if( pGrp->pList==0 ){ |
| 239074 | pGrp->bPatch = pIter->bPatchset; |
| 239075 | }else if( pIter->bPatchset!=pGrp->bPatch ){ |
| 239076 | rc = SQLITE_ERROR; |
| 239077 | } |
| 239078 | |
| 239079 | if( rc==SQLITE_OK ){ |
| 239080 | const char *zTab = 0; |
| 239081 | sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect); |
| 239082 | rc = sessionChangesetFindTable(pGrp, zTab, pIter, &pTab); |
| 239083 | } |
| 239084 | |
| 239085 | if( rc==SQLITE_OK && nCol<pTab->nCol ){ |
| 239086 | SessionBuffer *pBuf = &pGrp->rec; |
| 239087 | rc = sessionChangesetExtendRecord(pGrp, pTab, nCol, op, aRec, nRec, pBuf); |
| 239088 | aRec = pBuf->aBuf; |
| 239089 | nRec = pBuf->nBuf; |
| 239090 | assert( pGrp->db ); |
| 239091 | } |
| 239092 | |
| 239093 | if( rc==SQLITE_OK && sessionGrowHash(0, pIter->bPatchset, pTab) ){ |
| 239094 | rc = SQLITE_NOMEM; |
| 239095 | } |
| 239096 | |
| 239097 | if( rc==SQLITE_OK ){ |
| 239098 | /* Search for existing entry. If found, remove it from the hash table. |
| 239099 | ** Code below may link it back in. */ |
| 239100 | iHash = sessionChangeHash( |
| 239101 | pTab, (pIter->bPatchset && op==SQLITE_DELETE), aRec, pTab->nChange |
| 239102 | ); |
| 239103 | for(pp=&pTab->apChange[iHash]; *pp; pp=&(*pp)->pNext){ |
| 239104 | int bPkOnly1 = 0; |
| 239105 | int bPkOnly2 = 0; |
| 239106 | if( pIter->bPatchset ){ |
| 239107 | bPkOnly1 = (*pp)->op==SQLITE_DELETE; |
| 239108 | bPkOnly2 = op==SQLITE_DELETE; |
| 239109 | } |
| 239110 | if( sessionChangeEqual(pTab, bPkOnly1, (*pp)->aRecord, bPkOnly2, aRec) ){ |
| 239111 | pExist = *pp; |
| @@ -239116,18 +239448,59 @@ | |
| 239116 | } |
| 239117 | } |
| 239118 | |
| 239119 | if( rc==SQLITE_OK ){ |
| 239120 | rc = sessionChangeMerge(pTab, bRebase, |
| 239121 | pIter->bPatchset, pExist, op, bIndirect, aRec, nRec, &pChange |
| 239122 | ); |
| 239123 | } |
| 239124 | if( rc==SQLITE_OK && pChange ){ |
| 239125 | pChange->pNext = pTab->apChange[iHash]; |
| 239126 | pTab->apChange[iHash] = pChange; |
| 239127 | pTab->nEntry++; |
| 239128 | } |
| 239129 | |
| 239130 | if( rc==SQLITE_OK ) rc = pIter->rc; |
| 239131 | return rc; |
| 239132 | } |
| 239133 | |
| @@ -239144,11 +239517,11 @@ | |
| 239144 | int nRec; |
| 239145 | int rc = SQLITE_OK; |
| 239146 | |
| 239147 | pIter->in.bNoDiscard = 1; |
| 239148 | while( SQLITE_ROW==(sessionChangesetNext(pIter, &aRec, &nRec, 0)) ){ |
| 239149 | rc = sessionOneChangeToHash(pGrp, pIter, bRebase); |
| 239150 | if( rc!=SQLITE_OK ) break; |
| 239151 | } |
| 239152 | |
| 239153 | if( rc==SQLITE_OK ) rc = pIter->rc; |
| 239154 | return rc; |
| @@ -239233,10 +239606,37 @@ | |
| 239233 | memset(p, 0, sizeof(sqlite3_changegroup)); |
| 239234 | } |
| 239235 | *pp = p; |
| 239236 | return rc; |
| 239237 | } |
| 239238 | |
| 239239 | /* |
| 239240 | ** Provide a database schema to the changegroup object. |
| 239241 | */ |
| 239242 | SQLITE_API int sqlite3changegroup_schema( |
| @@ -239292,11 +239692,11 @@ | |
| 239292 | ){ |
| 239293 | /* Iterator does not point to any valid entry or is an INVERT iterator. */ |
| 239294 | rc = SQLITE_ERROR; |
| 239295 | }else{ |
| 239296 | pIter->in.bNoDiscard = 1; |
| 239297 | rc = sessionOneChangeToHash(pGrp, pIter, 0); |
| 239298 | } |
| 239299 | return rc; |
| 239300 | } |
| 239301 | |
| 239302 | /* |
| @@ -239344,10 +239744,16 @@ | |
| 239344 | /* |
| 239345 | ** Delete a changegroup object. |
| 239346 | */ |
| 239347 | SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup *pGrp){ |
| 239348 | if( pGrp ){ |
| 239349 | sqlite3_free(pGrp->zDb); |
| 239350 | sessionDeleteTable(0, pGrp->pList); |
| 239351 | sqlite3_free(pGrp->rec.aBuf); |
| 239352 | sqlite3_free(pGrp); |
| 239353 | } |
| @@ -239771,10 +240177,332 @@ | |
| 239771 | } |
| 239772 | default: |
| 239773 | rc = SQLITE_MISUSE; |
| 239774 | break; |
| 239775 | } |
| 239776 | return rc; |
| 239777 | } |
| 239778 | |
| 239779 | #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 239780 | |
| @@ -262478,11 +263206,11 @@ | |
| 262478 | int nArg, /* Number of args */ |
| 262479 | sqlite3_value **apUnused /* Function arguments */ |
| 262480 | ){ |
| 262481 | assert( nArg==0 ); |
| 262482 | UNUSED_PARAM2(nArg, apUnused); |
| 262483 | sqlite3_result_text(pCtx, "fts5: 2026-03-26 14:19:34 97ee48b6ef65fb55633196282c9e75b3b0a3b81ba9755f63493a38e3f1a5610c", -1, SQLITE_TRANSIENT); |
| 262484 | } |
| 262485 | |
| 262486 | /* |
| 262487 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 262488 | ** |
| 262489 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -16,11 +16,11 @@ | |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | ** |
| 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | ** 7bc1d0c4572f126cfe68fa51fe992d2bd46b with changes in files: |
| 22 | ** |
| 23 | ** |
| 24 | */ |
| 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | #define SQLITE_CORE 1 |
| @@ -467,14 +467,14 @@ | |
| 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | */ |
| 470 | #define SQLITE_VERSION "3.53.0" |
| 471 | #define SQLITE_VERSION_NUMBER 3053000 |
| 472 | #define SQLITE_SOURCE_ID "2026-04-01 11:54:20 7bc1d0c4572f126cfe68fa51fe992d2bd46b1e57c04721991bd5fad36dd795c5" |
| 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | #define SQLITE_SCM_TAGS "" |
| 475 | #define SQLITE_SCM_DATETIME "2026-04-01T11:54:20.065Z" |
| 476 | |
| 477 | /* |
| 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | ** |
| @@ -897,11 +897,11 @@ | |
| 897 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 898 | #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) |
| 899 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 900 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 901 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 902 | #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal only */ |
| 903 | |
| 904 | /* |
| 905 | ** CAPI3REF: Flags For File Open Operations |
| 906 | ** |
| 907 | ** These bit values are intended for use in the |
| @@ -1609,10 +1609,16 @@ | |
| 1609 | /* deprecated names */ |
| 1610 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1611 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1612 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| 1613 | |
| 1614 | /* reserved file-control numbers: |
| 1615 | ** 101 |
| 1616 | ** 102 |
| 1617 | ** 103 |
| 1618 | */ |
| 1619 | |
| 1620 | |
| 1621 | /* |
| 1622 | ** CAPI3REF: Mutex Handle |
| 1623 | ** |
| 1624 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2030,11 +2036,12 @@ | |
| 2036 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 2037 | ** The exceptional configuration options that may be invoked at any time |
| 2038 | ** are called "anytime configuration options". |
| 2039 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 2040 | ** [sqlite3_shutdown()] with a first argument that is not an anytime |
| 2041 | ** configuration option, then the sqlite3_config() call will |
| 2042 | ** return SQLITE_MISUSE. |
| 2043 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 2044 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 2045 | ** |
| 2046 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 2047 | ** ^If the option is unknown or SQLite is unable to set the option |
| @@ -2596,13 +2603,14 @@ | |
| 2603 | ** <li><P>The second argument ("sz") is the |
| 2604 | ** size of each lookaside buffer slot. Lookaside is disabled if "sz" |
| 2605 | ** is less than 8. The "sz" argument should be a multiple of 8 less than |
| 2606 | ** 65536. If "sz" does not meet this constraint, it is reduced in size until |
| 2607 | ** it does. |
| 2608 | ** <li><p>The third argument ("cnt") is the number of slots. |
| 2609 | ** Lookaside is disabled if "cnt"is less than 1. |
| 2610 | * The "cnt" value will be reduced, if necessary, so |
| 2611 | ** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" |
| 2612 | ** parameter is usually chosen so that the product of "sz" and "cnt" is less |
| 2613 | ** than 1,000,000. |
| 2614 | ** </ol> |
| 2615 | ** <p>If the "buf" argument is not NULL, then it must |
| 2616 | ** point to a memory buffer with a size that is greater than |
| @@ -2977,11 +2985,11 @@ | |
| 2985 | ** default value 17, as of SQLite version 3.52.0. The value was 15 in all |
| 2986 | ** prior versions.<p> |
| 2987 | ** This option takes two arguments which are an integer and a pointer |
| 2988 | ** to an integer. The first argument is a small integer, between 3 and 23, or |
| 2989 | ** zero. The FP_DIGITS setting is changed to that small integer, or left |
| 2990 | ** unaltered if the first argument is zero or out of range. The second argument |
| 2991 | ** is a pointer to an integer. If the pointer is not NULL, then the value of |
| 2992 | ** the FP_DIGITS setting, after possibly being modified by the first |
| 2993 | ** arguments, is written into the integer to which the second argument points. |
| 2994 | ** </dd> |
| 2995 | ** |
| @@ -2989,14 +2997,16 @@ | |
| 2997 | ** |
| 2998 | ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3> |
| 2999 | ** |
| 3000 | ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the |
| 3001 | ** overall call to [sqlite3_db_config()] has a total of four parameters. |
| 3002 | ** The first argument (the third parameter to sqlite3_db_config()) is |
| 3003 | ** an integer. |
| 3004 | ** The second argument is a pointer to an integer. If the first argument is 1, |
| 3005 | ** then the option becomes enabled. If the first integer argument is 0, |
| 3006 | ** then the option is disabled. |
| 3007 | ** If the first argument is -1, then the option setting |
| 3008 | ** is unchanged. The second argument, the pointer to an integer, may be NULL. |
| 3009 | ** If the second argument is not NULL, then a value of 0 or 1 is written into |
| 3010 | ** the integer to which the second argument points, depending on whether the |
| 3011 | ** setting is disabled or enabled after applying any changes specified by |
| 3012 | ** the first argument. |
| @@ -6169,12 +6179,13 @@ | |
| 6179 | ** that the application-defined collating sequence created expects its |
| 6180 | ** input strings to be in UTF16 in native byte order, and that the start |
| 6181 | ** of the strings must be aligned to a 2-byte boundary. |
| 6182 | ** |
| 6183 | ** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be |
| 6184 | ** used to specify the text encoding to strings input to |
| 6185 | ** [sqlite3_result_text64()] and [sqlite3_bind_text64()]. |
| 6186 | ** The SQLITE_UTF8_ZT encoding means that the input string (call it "z") |
| 6187 | ** is UTF-8 encoded and that it is zero-terminated. If the length parameter |
| 6188 | ** (call it "n") is non-negative, this encoding option means that the caller |
| 6189 | ** guarantees that z array contains at least n+1 bytes and that the z[n] |
| 6190 | ** byte has a value of zero. |
| 6191 | ** This option gives the same output as SQLITE_UTF8, but can be more efficient |
| @@ -6422,30 +6433,26 @@ | |
| 6433 | ** |
| 6434 | ** These routines must be called from the same thread as |
| 6435 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 6436 | ** |
| 6437 | ** As long as the input parameter is correct, these routines can only |
| 6438 | ** fail if an out-of-memory error occurs while trying to do a |
| 6439 | ** UTF8→UTF16 or UTF16→UTF8 conversion. |
| 6440 | ** If an out-of-memory error occurs, then the return value from these |
| 6441 | ** routines is the same as if the column had contained an SQL NULL value. |
| 6442 | ** If the input sqlite3_value was not obtained from [sqlite3_value_dup()], |
| 6443 | ** then valid SQL NULL returns can also be distinguished from |
| 6444 | ** out-of-memory errors after extracting the value |
| 6445 | ** by invoking the [sqlite3_errcode()] immediately after the suspicious |
| 6446 | ** return value is obtained and before any |
| 6447 | ** other SQLite interface is called on the same [database connection]. |
| 6448 | ** If the input sqlite3_value was obtained from sqlite3_value_dup() then |
| 6449 | ** it is disconnected from the database connection and so sqlite3_errcode() |
| 6450 | ** will not work. |
| 6451 | ** In that case, the only way to distinguish an out-of-memory |
| 6452 | ** condition from a true SQL NULL is to invoke sqlite3_value_type() on the |
| 6453 | ** input to see if it is NULL prior to trying to extract the value. |
| 6454 | */ |
| 6455 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 6456 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 6457 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 6458 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| @@ -6468,11 +6475,12 @@ | |
| 6475 | ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
| 6476 | ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding |
| 6477 | ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
| 6478 | ** returns something other than SQLITE_TEXT, then the return value from |
| 6479 | ** sqlite3_value_encoding(X) is meaningless. ^Calls to |
| 6480 | ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], |
| 6481 | ** [sqlite3_value_text16be(X)], |
| 6482 | ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or |
| 6483 | ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and |
| 6484 | ** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
| 6485 | ** |
| 6486 | ** This routine is intended for used by applications that test and validate |
| @@ -6599,21 +6607,21 @@ | |
| 6607 | ** associate auxiliary data with argument values. If the same argument |
| 6608 | ** value is passed to multiple invocations of the same SQL function during |
| 6609 | ** query execution, under some circumstances the associated auxiliary data |
| 6610 | ** might be preserved. An example of where this might be useful is in a |
| 6611 | ** regular-expression matching function. The compiled version of the regular |
| 6612 | ** expression can be stored as auxiliary data associated with the pattern |
| 6613 | ** string. Then as long as the pattern string remains the same, |
| 6614 | ** the compiled regular expression can be reused on multiple |
| 6615 | ** invocations of the same function. |
| 6616 | ** |
| 6617 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary |
| 6618 | ** data associated by the sqlite3_set_auxdata(C,N,P,X) function with the |
| 6619 | ** Nth argument value to the application-defined function. ^N is zero |
| 6620 | ** for the left-most function argument. ^If there is no auxiliary data |
| 6621 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) |
| 6622 | ** interface returns a NULL pointer. |
| 6623 | ** |
| 6624 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the |
| 6625 | ** N-th argument of the application-defined function. ^Subsequent |
| 6626 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| 6627 | ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or |
| @@ -10722,21 +10730,22 @@ | |
| 10730 | ** |
| 10731 | ** <table border=1 cellspacing=0 cellpadding=10 width="90%"> |
| 10732 | ** <tr> |
| 10733 | ** <td valign="top">sqlite3_vtab_distinct() return value |
| 10734 | ** <td valign="top">Rows are returned in aOrderBy order |
| 10735 | ** <td valign="top">Rows with the same value in all aOrderBy columns are |
| 10736 | ** adjacent |
| 10737 | ** <td valign="top">Duplicates over all colUsed columns may be omitted |
| 10738 | ** <tr><td>0<td>yes<td>yes<td>no |
| 10739 | ** <tr><td>1<td>no<td>yes<td>no |
| 10740 | ** <tr><td>2<td>no<td>yes<td>yes |
| 10741 | ** <tr><td>3<td>yes<td>yes<td>yes |
| 10742 | ** </table> |
| 10743 | ** |
| 10744 | ** ^For the purposes of comparing virtual table output values to see if the |
| 10745 | ** values are the same value for sorting purposes, two NULL values are |
| 10746 | ** considered to be the same. In other words, the comparison operator is "IS" |
| 10747 | ** (or "IS NOT DISTINCT FROM") and not "==". |
| 10748 | ** |
| 10749 | ** If a virtual table implementation is unable to meet the requirements |
| 10750 | ** specified above, then it must not set the "orderByConsumed" flag in the |
| 10751 | ** [sqlite3_index_info] object or an incorrect answer may result. |
| @@ -11586,16 +11595,17 @@ | |
| 11595 | /* |
| 11596 | ** CAPI3REF: Bind array values to the CARRAY table-valued function |
| 11597 | ** |
| 11598 | ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to |
| 11599 | ** parameter that is the first argument of the [carray() table-valued function]. |
| 11600 | ** The S parameter is a pointer to the [prepared statement] that uses the |
| 11601 | ** carray() functions. I is the parameter index to be bound. I must be the |
| 11602 | ** index of the parameter that is the first argument to the carray() |
| 11603 | ** table-valued function. P is a pointer to the array to be bound, and N |
| 11604 | ** is the number of elements in the array. The F argument is one of |
| 11605 | ** constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64], |
| 11606 | ** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], |
| 11607 | ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P. |
| 11608 | ** |
| 11609 | ** If the X argument is not a NULL pointer or one of the special |
| 11610 | ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke |
| 11611 | ** the function X with argument D when it is finished using the data in P. |
| @@ -13648,10 +13658,236 @@ | |
| 13658 | |
| 13659 | /* |
| 13660 | ** CAPI3REF: Values for sqlite3session_config(). |
| 13661 | */ |
| 13662 | #define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 13663 | |
| 13664 | /* |
| 13665 | ** CAPI3REF: Configure a changegroup object |
| 13666 | ** |
| 13667 | ** Configure the changegroup object passed as the first argument. |
| 13668 | ** At present the only valid value for the second parameter is |
| 13669 | ** [SQLITE_CHANGEGROUP_CONFIG_PATCHSET]. |
| 13670 | */ |
| 13671 | SQLITE_API int sqlite3changegroup_config(sqlite3_changegroup*, int, void *pArg); |
| 13672 | |
| 13673 | /* |
| 13674 | ** CAPI3REF: Options for sqlite3changegroup_config(). |
| 13675 | ** |
| 13676 | ** The following values may be passed as the 2nd parameter to |
| 13677 | ** sqlite3changegroup_config(). |
| 13678 | ** |
| 13679 | ** <dt>SQLITE_CHANGEGROUP_CONFIG_PATCHSET <dd> |
| 13680 | ** A changegroup object generates either a changeset or patchset. Usually, |
| 13681 | ** this is determined by whether the first call to sqlite3changegroup_add() |
| 13682 | ** is passed a changeset or a patchset. Or, if the first changes are added |
| 13683 | ** to the changegroup object using the sqlite3changegroup_change_xxx() |
| 13684 | ** APIs, then this option may be used to configure whether the changegroup |
| 13685 | ** object generates a changeset or patchset. |
| 13686 | ** |
| 13687 | ** When this option is invoked, parameter pArg must point to a value of |
| 13688 | ** type int. If the changegroup currently contains zero changes, and the |
| 13689 | ** value of the int variable is zero or greater than zero, then the |
| 13690 | ** changegroup is configured to generate a changeset or patchset, |
| 13691 | ** respectively. It is a no-op, not an error, if the changegroup is not |
| 13692 | ** configured because it has already started accumulating changes. |
| 13693 | ** |
| 13694 | ** Before returning, the int variable is set to 0 if the changegroup is |
| 13695 | ** configured to generate a changeset, or 1 if it is configured to generate |
| 13696 | ** a patchset. |
| 13697 | */ |
| 13698 | #define SQLITE_CHANGEGROUP_CONFIG_PATCHSET 1 |
| 13699 | |
| 13700 | |
| 13701 | /* |
| 13702 | ** CAPI3REF: Begin adding a change to a changegroup |
| 13703 | ** |
| 13704 | ** This API is used, in concert with other sqlite3changegroup_change_xxx() |
| 13705 | ** APIs, to add changes to a changegroup object one at a time. To add a |
| 13706 | ** single change, the caller must: |
| 13707 | ** |
| 13708 | ** 1. Invoke sqlite3changegroup_change_begin() to indicate the type of |
| 13709 | ** change (INSERT, UPDATE or DELETE), the affected table and whether |
| 13710 | ** or not the change should be marked as indirect. |
| 13711 | ** |
| 13712 | ** 2. Invoke sqlite3changegroup_change_int64() or one of the other four |
| 13713 | ** value functions - _null(), _double(), _text() or _blob() - one or |
| 13714 | ** more times to specify old.* and new.* values for the change being |
| 13715 | ** constructed. |
| 13716 | ** |
| 13717 | ** 3. Invoke sqlite3changegroup_change_finish() to either finish adding |
| 13718 | ** the change to the group, or to discard the change altogether. |
| 13719 | ** |
| 13720 | ** The first argument to this function must be a pointer to the existing |
| 13721 | ** changegroup object that the change will be added to. The second argument |
| 13722 | ** must be SQLITE_INSERT, SQLITE_UPDATE or SQLITE_DELETE. The third is the |
| 13723 | ** name of the table that the change affects, and the fourth is a boolean |
| 13724 | ** flag specifying whether the change should be marked as "indirect" (if |
| 13725 | ** bIndirect is non-zero) or not indirect (if bIndirect is zero). |
| 13726 | ** |
| 13727 | ** Following a successful call to this function, this function may not be |
| 13728 | ** called again on the same changegroup object until after |
| 13729 | ** sqlite3changegroup_change_finish() has been called. Doing so is an |
| 13730 | ** SQLITE_MISUSE error. |
| 13731 | ** |
| 13732 | ** The changegroup object passed as the first argument must be already |
| 13733 | ** configured with schema data for the specified table. It may be configured |
| 13734 | ** either by calling sqlite3changegroup_schema() with a database that contains |
| 13735 | ** the table, or sqlite3changegroup_add() with a changeset that contains the |
| 13736 | ** table. If the changegroup object has not been configured with a schema for |
| 13737 | ** the specified table when this function is called, SQLITE_ERROR is returned. |
| 13738 | ** |
| 13739 | ** If successful, SQLITE_OK is returned. Otherwise, if an error occurs, an |
| 13740 | ** SQLite error code is returned. In this case, if argument pzErr is non-NULL, |
| 13741 | ** then (*pzErr) may be set to point to a buffer containing a utf-8 formated, |
| 13742 | ** nul-terminated, English language error message. It is the responsibility |
| 13743 | ** of the caller to eventually free this buffer using sqlite3_free(). |
| 13744 | */ |
| 13745 | SQLITE_API int sqlite3changegroup_change_begin( |
| 13746 | sqlite3_changegroup*, |
| 13747 | int eOp, |
| 13748 | const char *zTab, |
| 13749 | int bIndirect, |
| 13750 | char **pzErr |
| 13751 | ); |
| 13752 | |
| 13753 | /* |
| 13754 | ** CAPI3REF: Add a 64-bit integer to a changegroup |
| 13755 | ** |
| 13756 | ** This function may only be called between a successful call to |
| 13757 | ** sqlite3changegroup_change_begin() and its matching |
| 13758 | ** sqlite3changegroup_change_finish() call. If it is called at any |
| 13759 | ** other time, it is an SQLITE_MISUSE error. Calling this function |
| 13760 | ** specifies a 64-bit integer value to be used in the change currently being |
| 13761 | ** added to the changegroup object passed as the first argument. |
| 13762 | ** |
| 13763 | ** The second parameter, bNew, specifies whether the value is to be part of |
| 13764 | ** the new.* (if bNew is non-zero) or old.* (if bNew is zero) record of |
| 13765 | ** the change under construction. If this does not match the type of change |
| 13766 | ** specified by the preceding call to sqlite3changegroup_change_begin() (i.e. |
| 13767 | ** an old.* value for an SQLITE_INSERT change, or a new.* value for an |
| 13768 | ** SQLITE_DELETE), then SQLITE_ERROR is returned. |
| 13769 | ** |
| 13770 | ** The third parameter specifies the column of the old.* or new.* record that |
| 13771 | ** the value will be a part of. If the specified table has an explicit primary |
| 13772 | ** key, then this is the index of the table column, numbered from 0 in the order |
| 13773 | ** specified within the CREATE TABLE statement. Or, if the table uses an |
| 13774 | ** implicit rowid key, then the column 0 is the rowid and the explicit columns |
| 13775 | ** are numbered starting from 1. If the iCol parameter is less than 0 or greater |
| 13776 | ** than the index of the last column in the table, SQLITE_RANGE is returned. |
| 13777 | ** |
| 13778 | ** The fourth parameter is the integer value to use as part of the old.* or |
| 13779 | ** new.* record. |
| 13780 | ** |
| 13781 | ** If this call is successful, SQLITE_OK is returned. Otherwise, if an |
| 13782 | ** error occurs, an SQLite error code is returned. |
| 13783 | */ |
| 13784 | SQLITE_API int sqlite3changegroup_change_int64( |
| 13785 | sqlite3_changegroup*, |
| 13786 | int bNew, |
| 13787 | int iCol, |
| 13788 | sqlite3_int64 iVal |
| 13789 | ); |
| 13790 | |
| 13791 | /* |
| 13792 | ** CAPI3REF: Add a NULL to a changegroup |
| 13793 | ** |
| 13794 | ** This function is similar to sqlite3changegroup_change_int64(). Except that |
| 13795 | ** it configures the change currently under construction with a NULL value |
| 13796 | ** instead of a 64-bit integer. |
| 13797 | */ |
| 13798 | SQLITE_API int sqlite3changegroup_change_null(sqlite3_changegroup*, int, int); |
| 13799 | |
| 13800 | /* |
| 13801 | ** CAPI3REF: Add an double to a changegroup |
| 13802 | ** |
| 13803 | ** This function is similar to sqlite3changegroup_change_int64(). Except that |
| 13804 | ** it configures the change currently being constructed with a real value |
| 13805 | ** instead of a 64-bit integer. |
| 13806 | */ |
| 13807 | SQLITE_API int sqlite3changegroup_change_double(sqlite3_changegroup*, int, int, double); |
| 13808 | |
| 13809 | /* |
| 13810 | ** CAPI3REF: Add a text value to a changegroup |
| 13811 | ** |
| 13812 | ** This function is similar to sqlite3changegroup_change_int64(). It configures |
| 13813 | ** the currently accumulated change with a text value instead of a 64-bit |
| 13814 | ** integer. Parameter pVal points to a buffer containing the text encoded using |
| 13815 | ** utf-8. Parameter nVal may either be the size of the text value in bytes, or |
| 13816 | ** else a negative value, in which case the buffer pVal points to is assumed to |
| 13817 | ** be nul-terminated. |
| 13818 | */ |
| 13819 | SQLITE_API int sqlite3changegroup_change_text( |
| 13820 | sqlite3_changegroup*, int, int, const char *pVal, int nVal |
| 13821 | ); |
| 13822 | |
| 13823 | /* |
| 13824 | ** CAPI3REF: Add a blob to a changegroup |
| 13825 | ** |
| 13826 | ** This function is similar to sqlite3changegroup_change_int64(). It configures |
| 13827 | ** the currently accumulated change with a blob value instead of a 64-bit |
| 13828 | ** integer. Parameter pVal points to a buffer containing the blob. Parameter |
| 13829 | ** nVal is the size of the blob in bytes. |
| 13830 | */ |
| 13831 | SQLITE_API int sqlite3changegroup_change_blob( |
| 13832 | sqlite3_changegroup*, int, int, const void *pVal, int nVal |
| 13833 | ); |
| 13834 | |
| 13835 | /* |
| 13836 | ** CAPI3REF: Finish adding one-at-at-time changes to a changegroup |
| 13837 | ** |
| 13838 | ** This function may only be called following a successful call to |
| 13839 | ** sqlite3changegroup_change_begin(). Otherwise, it is an SQLITE_MISUSE error. |
| 13840 | ** |
| 13841 | ** If parameter bDiscard is non-zero, then the current change is simply |
| 13842 | ** discarded. In this case this function is always successful and SQLITE_OK |
| 13843 | ** returned. |
| 13844 | ** |
| 13845 | ** If parameter bDiscard is zero, then an attempt is made to add the current |
| 13846 | ** change to the changegroup. Assuming the changegroup is configured to |
| 13847 | ** produce a changeset (not a patchset), this requires that: |
| 13848 | ** |
| 13849 | ** * If the change is an INSERT or DELETE, then a value must be specified |
| 13850 | ** for all columns of the new.* or old.* record, respectively. |
| 13851 | ** |
| 13852 | ** * If the change is an UPDATE record, then values must be provided for |
| 13853 | ** the PRIMARY KEY columns of the old.* record, but must not be provided |
| 13854 | ** for PRIMARY KEY columns of the new.* record. |
| 13855 | ** |
| 13856 | ** * If the change is an UPDATE record, then for each non-PRIMARY KEY |
| 13857 | ** column in the old.* record for which a value has been provided, a |
| 13858 | ** value must also be provided for the same column in the new.* record. |
| 13859 | ** Similarly, for each non-PK column in the old.* record for which |
| 13860 | ** a value is not provided, a value must not be provided for the same |
| 13861 | ** column in the new.* record. |
| 13862 | ** |
| 13863 | ** * All values specified for PRIMARY KEY columns must be non-NULL. |
| 13864 | ** |
| 13865 | ** Otherwise, it is an error. |
| 13866 | ** |
| 13867 | ** If the changegroup already contains a change for the same row (identified |
| 13868 | ** by PRIMARY KEY columns), then the current change is combined with the |
| 13869 | ** existing change in the same way as for sqlite3changegroup_add(). |
| 13870 | ** |
| 13871 | ** For a patchset, all of the above rules apply except that it doesn't matter |
| 13872 | ** whether or not values are provided for the non-PK old.* record columns |
| 13873 | ** for an UPDATE or DELETE change. This means that code used to produce |
| 13874 | ** a changeset using the sqlite3changegroup_change_xxx() APIs may also |
| 13875 | ** be used to produce patchsets. |
| 13876 | ** |
| 13877 | ** If the call is successful, SQLITE_OK is returned. Otherwise, if an error |
| 13878 | ** occurs, an SQLite error code is returned. If an error is returned and |
| 13879 | ** parameter pzErr is not NULL, then (*pzErr) may be set to point to a buffer |
| 13880 | ** containing a nul-terminated, utf-8 encoded, English language error message. |
| 13881 | ** It is the responsibility of the caller to eventually free any such error |
| 13882 | ** message buffer using sqlite3_free(). |
| 13883 | */ |
| 13884 | SQLITE_API int sqlite3changegroup_change_finish( |
| 13885 | sqlite3_changegroup*, |
| 13886 | int bDiscard, |
| 13887 | char **pzErr |
| 13888 | ); |
| 13889 | |
| 13890 | /* |
| 13891 | ** Make sure we can call this stuff from C++. |
| 13892 | */ |
| 13893 | #if 0 |
| @@ -21585,21 +21821,26 @@ | |
| 21821 | int nArg; /* Total number of arguments */ |
| 21822 | int nUsed; /* Number of arguments used so far */ |
| 21823 | sqlite3_value **apArg; /* The argument values */ |
| 21824 | }; |
| 21825 | |
| 21826 | /* |
| 21827 | ** Maxium number of base-10 digits in an unsigned 64-bit integer |
| 21828 | */ |
| 21829 | #define SQLITE_U64_DIGITS 20 |
| 21830 | |
| 21831 | /* |
| 21832 | ** An instance of this object receives the decoding of a floating point |
| 21833 | ** value into an approximate decimal representation. |
| 21834 | */ |
| 21835 | struct FpDecode { |
| 21836 | int n; /* Significant digits in the decode */ |
| 21837 | int iDP; /* Location of the decimal point */ |
| 21838 | char *z; /* Start of significant digits */ |
| 21839 | char zBuf[SQLITE_U64_DIGITS+1]; /* Storage for significant digits */ |
| 21840 | char sign; /* '+' or '-' */ |
| 21841 | char isSpecial; /* 1: Infinity 2: NaN */ |
| 21842 | }; |
| 21843 | |
| 21844 | SQLITE_PRIVATE void sqlite3FpDecode(FpDecode*,double,int,int); |
| 21845 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 21846 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| @@ -22283,10 +22524,11 @@ | |
| 22524 | SQLITE_PRIVATE char *sqlite3RCStrNew(u64); |
| 22525 | SQLITE_PRIVATE char *sqlite3RCStrResize(char*,u64); |
| 22526 | |
| 22527 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| 22528 | SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64); |
| 22529 | SQLITE_PRIVATE int sqlite3StrAccumEnlargeIfNeeded(StrAccum*, i64); |
| 22530 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 22531 | SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8); |
| 22532 | SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); |
| 22533 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 22534 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| @@ -32635,10 +32877,11 @@ | |
| 32877 | case etEXP: |
| 32878 | case etGENERIC: { |
| 32879 | FpDecode s; |
| 32880 | int iRound; |
| 32881 | int j; |
| 32882 | i64 szBufNeeded; /* Size needed to hold the output */ |
| 32883 | |
| 32884 | if( bArgList ){ |
| 32885 | realvalue = getDoubleArg(pArgList); |
| 32886 | }else{ |
| 32887 | realvalue = va_arg(ap,double); |
| @@ -32723,21 +32966,19 @@ | |
| 32966 | if( xtype==etEXP ){ |
| 32967 | e2 = 0; |
| 32968 | }else{ |
| 32969 | e2 = s.iDP - 1; |
| 32970 | } |
| 32971 | |
| 32972 | szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+8; |
| 32973 | if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; |
| 32974 | if( sqlite3StrAccumEnlargeIfNeeded(pAccum, szBufNeeded) ){ |
| 32975 | width = length = 0; |
| 32976 | break; |
| 32977 | } |
| 32978 | bufpt = zOut = pAccum->zText + pAccum->nChar; |
| 32979 | |
| 32980 | flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; |
| 32981 | /* The sign in front of the number */ |
| 32982 | if( prefix ){ |
| 32983 | *(bufpt++) = prefix; |
| 32984 | } |
| @@ -32781,17 +33022,15 @@ | |
| 33022 | int nn = s.n - j; |
| 33023 | if( NEVER(nn>precision) ) nn = precision; |
| 33024 | if( nn>0 ){ |
| 33025 | memcpy(bufpt, s.z+j, nn); |
| 33026 | bufpt += nn; |
| 33027 | precision -= nn; |
| 33028 | } |
| 33029 | if( precision>0 && !flag_rtz ){ |
| 33030 | memset(bufpt, '0', precision); |
| 33031 | bufpt += precision; |
| 33032 | } |
| 33033 | } |
| 33034 | /* Remove trailing zeros and the "." if no digits follow the "." */ |
| 33035 | if( flag_rtz && flag_dp ){ |
| 33036 | while( bufpt[-1]=='0' ) *(--bufpt) = 0; |
| @@ -32818,31 +33057,35 @@ | |
| 33057 | exp %= 100; |
| 33058 | } |
| 33059 | *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */ |
| 33060 | *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */ |
| 33061 | } |
| 33062 | |
| 33063 | length = (int)(bufpt-zOut); |
| 33064 | assert( length <= szBufNeeded ); |
| 33065 | if( length<width ){ |
| 33066 | i64 nPad = width - length; |
| 33067 | if( flag_leftjustify ){ |
| 33068 | memset(bufpt, ' ', nPad); |
| 33069 | }else if( !flag_zeropad ){ |
| 33070 | memmove(zOut+nPad, zOut, length); |
| 33071 | memset(zOut, ' ', nPad); |
| 33072 | }else{ |
| 33073 | int adj = prefix!=0; |
| 33074 | memmove(zOut+nPad+adj, zOut+adj, length-adj); |
| 33075 | memset(zOut+adj, '0', nPad); |
| 33076 | } |
| 33077 | length = width; |
| 33078 | } |
| 33079 | pAccum->nChar += length; |
| 33080 | zOut[length] = 0; |
| 33081 | |
| 33082 | /* Floating point conversions render directly into the output |
| 33083 | ** buffer. Hence, don't just break out of the switch(). Bypass the |
| 33084 | ** output buffer writing that occurs after the switch() by continuing |
| 33085 | ** to the next character in the format string. */ |
| 33086 | continue; |
| 33087 | } |
| 33088 | case etSIZE: |
| 33089 | if( !bArgList ){ |
| 33090 | *(va_arg(ap,int*)) = pAccum->nChar; |
| 33091 | } |
| @@ -32882,15 +33125,14 @@ | |
| 33125 | precision--; |
| 33126 | while( precision > 1 ){ |
| 33127 | i64 nCopyBytes; |
| 33128 | if( nPrior > precision-1 ) nPrior = precision - 1; |
| 33129 | nCopyBytes = length*nPrior; |
| 33130 | if( sqlite3StrAccumEnlargeIfNeeded(pAccum, nCopyBytes) ){ |
| 33131 | break; |
| 33132 | } |
| 33133 | sqlite3_str_append(pAccum, |
| 33134 | &pAccum->zText[pAccum->nChar-nCopyBytes], nCopyBytes); |
| 33135 | precision -= nPrior; |
| 33136 | nPrior *= 2; |
| 33137 | } |
| 33138 | } |
| @@ -33231,10 +33473,17 @@ | |
| 33473 | } |
| 33474 | } |
| 33475 | assert( N>=0 && N<=0x7fffffff ); |
| 33476 | return (int)N; |
| 33477 | } |
| 33478 | |
| 33479 | SQLITE_PRIVATE int sqlite3StrAccumEnlargeIfNeeded(StrAccum *p, i64 N){ |
| 33480 | if( N + p->nChar >= p->nAlloc ){ |
| 33481 | sqlite3StrAccumEnlarge(p, N); |
| 33482 | } |
| 33483 | return p->accError; |
| 33484 | } |
| 33485 | |
| 33486 | /* |
| 33487 | ** Append N copies of character c to the given string buffer. |
| 33488 | */ |
| 33489 | SQLITE_API void sqlite3_str_appendchar(sqlite3_str *p, int N, char c){ |
| @@ -36548,15 +36797,16 @@ | |
| 36797 | ** lower 64-bits of the result into *pLo, and return the high-order |
| 36798 | ** 64 bits. |
| 36799 | */ |
| 36800 | static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){ |
| 36801 | #if (defined(__GNUC__) || defined(__clang__)) \ |
| 36802 | && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \ |
| 36803 | && !defined(SQLITE_DISABLE_INTRINSIC) |
| 36804 | __uint128_t r = (__uint128_t)a * b; |
| 36805 | *pLo = (u64)r; |
| 36806 | return (u64)(r>>64); |
| 36807 | #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 36808 | *pLo = a*b; |
| 36809 | return __umulh(a, b); |
| 36810 | #else |
| 36811 | u64 a0 = (u32)a; |
| 36812 | u64 a1 = a >> 32; |
| @@ -36583,21 +36833,23 @@ | |
| 36833 | ** |
| 36834 | ** The lower 64 bits of A*B are discarded. |
| 36835 | */ |
| 36836 | static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){ |
| 36837 | #if (defined(__GNUC__) || defined(__clang__)) \ |
| 36838 | && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \ |
| 36839 | && !defined(SQLITE_DISABLE_INTRINSIC) |
| 36840 | __uint128_t r = (__uint128_t)a * b; |
| 36841 | r += ((__uint128_t)aLo * b) >> 32; |
| 36842 | *pLo = (r>>32)&0xffffffff; |
| 36843 | return r>>64; |
| 36844 | #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 36845 | u64 r1_hi = __umulh(a,b); |
| 36846 | u64 r1_lo = a*b; |
| 36847 | u64 r2 = (__umulh((u64)aLo,b)<<32) + ((aLo*b)>>32); |
| 36848 | u64 t = r1_lo + r2; |
| 36849 | if( t<r1_lo ) r1_hi++; |
| 36850 | *pLo = t>>32; |
| 36851 | return r1_hi; |
| 36852 | #else |
| 36853 | u64 x2 = a>>32; |
| 36854 | u64 x1 = a&0xffffffff; |
| 36855 | u64 x0 = aLo; |
| @@ -36805,11 +37057,12 @@ | |
| 37057 | |
| 37058 | /* |
| 37059 | ** Count leading zeros for a 64-bit unsigned integer. |
| 37060 | */ |
| 37061 | static int countLeadingZeros(u64 m){ |
| 37062 | #if (defined(__GNUC__) || defined(__clang__)) \ |
| 37063 | && !defined(SQLITE_DISABLE_INTRINSIC) |
| 37064 | return __builtin_clzll(m); |
| 37065 | #else |
| 37066 | int n = 0; |
| 37067 | if( m <= 0x00000000ffffffffULL) { n += 32; m <<= 32; } |
| 37068 | if( m <= 0x0000ffffffffffffULL) { n += 16; m <<= 16; } |
| @@ -36906,16 +37159,19 @@ | |
| 37159 | ** Return positive if the result is a valid real number (or integer) and |
| 37160 | ** zero or negative if the string is empty or contains extraneous text. |
| 37161 | ** Lower bits of the return value contain addition information about the |
| 37162 | ** parse: |
| 37163 | ** |
| 37164 | ** bit 0 => Set if any prefix of the input is valid. Clear if |
| 37165 | ** there is no prefix of the input that can be seen as |
| 37166 | ** a valid floating point number. |
| 37167 | ** bit 1 => Set if the input contains a decimal point or eNNN |
| 37168 | ** clause. Zero if the input is an integer. |
| 37169 | ** bit 2 => The input is exactly 0.0, not an underflow from |
| 37170 | ** some value near zero. |
| 37171 | ** bit 3 => Set if there are more than about 19 significant |
| 37172 | ** digits in the input. |
| 37173 | ** |
| 37174 | ** If the input contains a syntax error but begins with text that might |
| 37175 | ** be a valid number of some kind, then the result is negative. The |
| 37176 | ** result is only zero if no prefix of the input could be interpreted as |
| 37177 | ** a number. |
| @@ -37077,10 +37333,73 @@ | |
| 37333 | "70717273747576777879" |
| 37334 | "80818283848586878889" |
| 37335 | "90919293949596979899" |
| 37336 | }; |
| 37337 | |
| 37338 | /* |
| 37339 | ** ARMv6, ARMv7, PPC32 are known to not support hardware u64 division. |
| 37340 | */ |
| 37341 | #if (defined(__arm__) && !defined(__aarch64__)) || \ |
| 37342 | (defined(__ppc__) && !defined(__ppc64__)) |
| 37343 | # define SQLITE_AVOID_U64_DIVIDE 1 |
| 37344 | #endif |
| 37345 | |
| 37346 | #ifdef SQLITE_AVOID_U64_DIVIDE |
| 37347 | /* |
| 37348 | ** Render an unsigned 64-bit integer as text onto the end of a 2-byte |
| 37349 | ** aligned buffer that is SQLITE_U64_DIGIT+1 bytes long. The last byte |
| 37350 | ** of the buffer will be filled with a \000 byte. |
| 37351 | ** |
| 37352 | ** Return the index into the buffer of the first byte. |
| 37353 | ** |
| 37354 | ** This routine is used on platforms where u64-division is slow because |
| 37355 | ** it is not available in hardware and has to be emulated in software. |
| 37356 | ** It seeks to minimize the number of u64 divisions and use u32 divisions |
| 37357 | ** instead. It is slower on platforms that have hardware u64 division, |
| 37358 | ** but much faster on platforms that do not. |
| 37359 | */ |
| 37360 | static int sqlite3UInt64ToText(u64 v, char *zOut){ |
| 37361 | u32 x32, kk; |
| 37362 | int i; |
| 37363 | zOut[SQLITE_U64_DIGITS] = 0; |
| 37364 | i = SQLITE_U64_DIGITS; |
| 37365 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[0]) ); |
| 37366 | assert( TWO_BYTE_ALIGNMENT(zOut) ); |
| 37367 | while( (v>>32)!=0 ){ |
| 37368 | u32 y, x0, x1, y0, y1; |
| 37369 | x32 = v % 100000000; |
| 37370 | v = v / 100000000; |
| 37371 | y = x32 % 10000; |
| 37372 | x32 /= 10000; |
| 37373 | x1 = x32 / 100; |
| 37374 | x0 = x32 % 100; |
| 37375 | y1 = y / 100; |
| 37376 | y0 = y % 100; |
| 37377 | assert( i>=8 ); |
| 37378 | i -= 8; |
| 37379 | *(u16*)(&zOut[i]) = *(u16*)&sqlite3DigitPairs.a[x1*2]; |
| 37380 | *(u16*)(&zOut[i+2]) = *(u16*)&sqlite3DigitPairs.a[x0*2]; |
| 37381 | *(u16*)(&zOut[i+4]) = *(u16*)&sqlite3DigitPairs.a[y1*2]; |
| 37382 | *(u16*)(&zOut[i+6]) = *(u16*)&sqlite3DigitPairs.a[y0*2]; |
| 37383 | } |
| 37384 | x32 = v; |
| 37385 | while( x32>=10 ){ |
| 37386 | kk = x32 % 100; |
| 37387 | x32 = x32 / 100; |
| 37388 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk*2]) ); |
| 37389 | assert( i>=2 ); |
| 37390 | i -= 2; |
| 37391 | assert( TWO_BYTE_ALIGNMENT(&zOut[i]) ); |
| 37392 | *(u16*)(&zOut[i]) = *(u16*)&sqlite3DigitPairs.a[kk*2]; |
| 37393 | } |
| 37394 | if( x32 ){ |
| 37395 | assert( i>0 ); |
| 37396 | zOut[--i] = x32 + '0'; |
| 37397 | } |
| 37398 | return i; |
| 37399 | } |
| 37400 | #endif /* defined(SQLITE_AVOID_U64_DIVIDE) */ |
| 37401 | |
| 37402 | /* |
| 37403 | ** Render an signed 64-bit integer as text. Store the result in zOut[] and |
| 37404 | ** return the length of the string that was stored, in bytes. The value |
| 37405 | ** returned does not include the zero terminator at the end of the output |
| @@ -37090,11 +37409,11 @@ | |
| 37409 | */ |
| 37410 | SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){ |
| 37411 | int i; |
| 37412 | u64 x; |
| 37413 | union { |
| 37414 | char a[SQLITE_U64_DIGITS+1]; |
| 37415 | u16 forceAlignment; |
| 37416 | } u; |
| 37417 | if( v>0 ){ |
| 37418 | x = v; |
| 37419 | }else if( v==0 ){ |
| @@ -37102,10 +37421,13 @@ | |
| 37421 | zOut[1] = 0; |
| 37422 | return 1; |
| 37423 | }else{ |
| 37424 | x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v; |
| 37425 | } |
| 37426 | #ifdef SQLITE_AVOID_U64_DIVIDE |
| 37427 | i = sqlite3UInt64ToText(x, u.a); |
| 37428 | #else |
| 37429 | i = sizeof(u.a)-1; |
| 37430 | u.a[i] = 0; |
| 37431 | while( x>=10 ){ |
| 37432 | int kk = (x%100)*2; |
| 37433 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) ); |
| @@ -37115,10 +37437,11 @@ | |
| 37437 | x /= 100; |
| 37438 | } |
| 37439 | if( x ){ |
| 37440 | u.a[--i] = x + '0'; |
| 37441 | } |
| 37442 | #endif /* SQLITE_AVOID_U64_DIVIDE */ |
| 37443 | if( v<0 ) u.a[--i] = '-'; |
| 37444 | memcpy(zOut, &u.a[i], sizeof(u.a)-i); |
| 37445 | return sizeof(u.a)-1-i; |
| 37446 | } |
| 37447 | |
| @@ -37434,41 +37757,47 @@ | |
| 37757 | sqlite3Fp2Convert10(v, e, (iRound<=0||iRound>=18)?18:iRound+1, &v, &exp); |
| 37758 | |
| 37759 | /* Extract significant digits, start at the right-most slot in p->zBuf |
| 37760 | ** and working back to the right. "i" keeps track of the next slot in |
| 37761 | ** which to store a digit. */ |
| 37762 | assert( sizeof(p->zBuf)==SQLITE_U64_DIGITS+1 ); |
| 37763 | assert( v>0 ); |
| 37764 | zBuf = p->zBuf; |
| 37765 | #ifdef SQLITE_AVOID_U64_DIVIDE |
| 37766 | i = sqlite3UInt64ToText(v, zBuf); |
| 37767 | #else |
| 37768 | i = SQLITE_U64_DIGITS; |
| 37769 | while( v>=10 ){ |
| 37770 | int kk = (v%100)*2; |
| 37771 | assert( TWO_BYTE_ALIGNMENT(&sqlite3DigitPairs.a[kk]) ); |
| 37772 | assert( TWO_BYTE_ALIGNMENT(&zBuf[i]) ); |
| 37773 | assert( i-2>=0 ); |
| 37774 | *(u16*)(&zBuf[i-2]) = *(u16*)&sqlite3DigitPairs.a[kk]; |
| 37775 | i -= 2; |
| 37776 | v /= 100; |
| 37777 | } |
| 37778 | if( v ){ |
| 37779 | assert( v<10 ); |
| 37780 | assert( i>0 ); |
| 37781 | zBuf[--i] = v + '0'; |
| 37782 | } |
| 37783 | #endif /* SQLITE_AVOID_U64_DIVIDE */ |
| 37784 | assert( i>=0 && i<SQLITE_U64_DIGITS ); |
| 37785 | n = SQLITE_U64_DIGITS - i; /* Total number of digits extracted */ |
| 37786 | assert( n>0 ); |
| 37787 | assert( n<=SQLITE_U64_DIGITS ); |
| 37788 | p->iDP = n + exp; |
| 37789 | if( iRound<=0 ){ |
| 37790 | iRound = p->iDP - iRound; |
| 37791 | if( iRound==0 && zBuf[i]>='5' ){ |
| 37792 | iRound = 1; |
| 37793 | zBuf[--i] = '0'; |
| 37794 | n++; |
| 37795 | p->iDP++; |
| 37796 | } |
| 37797 | } |
| 37798 | z = &zBuf[i]; /* z points to the first digit */ |
| 37799 | if( iRound>0 && (iRound<n || n>mxRound) ){ |
| 37800 | if( iRound>mxRound ) iRound = mxRound; |
| 37801 | if( iRound==17 ){ |
| 37802 | /* If the precision is exactly 17, which only happens with the "!" |
| 37803 | ** flag (ex: "%!.17g") then try to reduce the precision if that |
| @@ -85833,11 +86162,11 @@ | |
| 86162 | ** rc>0 => All of the input is well-formed |
| 86163 | ** (rc&2)==0 => The number is expressed as an integer, with no |
| 86164 | ** decimal point or eNNN suffix. |
| 86165 | */ |
| 86166 | SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem *pMem, double *pValue){ |
| 86167 | testcase( pMem->db==0 ); |
| 86168 | assert( pMem->flags & (MEM_Str|MEM_Blob) ); |
| 86169 | if( pMem->z==0 ){ |
| 86170 | *pValue = 0.0; |
| 86171 | return 0; |
| 86172 | }else if( pMem->enc==SQLITE_UTF8 |
| @@ -131514,11 +131843,10 @@ | |
| 131843 | ** forms 2 through 5, then rebuild the union of all matching indexes, |
| 131844 | ** taken care to avoid rebuilding the same index more than once. |
| 131845 | */ |
| 131846 | #ifndef SQLITE_OMIT_REINDEX |
| 131847 | SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){ |
| 131848 | char *z = 0; /* Name of a table or index or collation */ |
| 131849 | const char *zDb = 0; /* Name of the database */ |
| 131850 | int iReDb = -1; /* The database index number */ |
| 131851 | sqlite3 *db = pParse->db; /* The database connection */ |
| 131852 | Token *pObjName; /* Name of the table or index to be reindexed */ |
| @@ -131553,11 +131881,11 @@ | |
| 131881 | if( !bAll ){ |
| 131882 | if( zDb==0 && sqlite3StrICmp(z, "expressions")==0 ){ |
| 131883 | isExprIdx = 1; |
| 131884 | bMatch = 1; |
| 131885 | } |
| 131886 | if( zDb==0 && sqlite3FindCollSeq(db, ENC(db), z, 0)!=0 ){ |
| 131887 | zColl = z; |
| 131888 | bMatch = 1; |
| 131889 | } |
| 131890 | if( zColl==0 && (pReTab = sqlite3FindTable(db, z, zDb))!=0 ){ |
| 131891 | bMatch = 1; |
| @@ -134449,22 +134777,15 @@ | |
| 134777 | ** require enhancements to the implementation. */ |
| 134778 | assert( pStr!=0 && pStr->nChar==0 ); |
| 134779 | |
| 134780 | switch( sqlite3_value_type(pValue) ){ |
| 134781 | case SQLITE_FLOAT: { |
| 134782 | /* ,--- Show infinity as 9.0e+999 |
| 134783 | ** | |
| 134784 | ** | ,--- 17 precision guarantees round-trip |
| 134785 | ** v v */ |
| 134786 | sqlite3_str_appendf(pStr, "%!0.17g", sqlite3_value_double(pValue)); |
| 134787 | break; |
| 134788 | } |
| 134789 | case SQLITE_INTEGER: { |
| 134790 | sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue)); |
| 134791 | break; |
| @@ -186195,11 +186516,11 @@ | |
| 186516 | if( db->mallocFailed ){ |
| 186517 | pParse->rc = SQLITE_NOMEM_BKPT; |
| 186518 | } |
| 186519 | if( pParse->zErrMsg || (pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE) ){ |
| 186520 | if( pParse->zErrMsg==0 ){ |
| 186521 | pParse->zErrMsg = sqlite3DbStrDup(db, sqlite3ErrStr(pParse->rc)); |
| 186522 | } |
| 186523 | if( (pParse->prepFlags & SQLITE_PREPARE_DONT_LOG)==0 ){ |
| 186524 | sqlite3_log(pParse->rc, "%s in \"%s\"", pParse->zErrMsg, pParse->zTail); |
| 186525 | } |
| 186526 | nErr++; |
| @@ -233377,10 +233698,23 @@ | |
| 233698 | aBuf[4] = (i>>24) & 0xFF; |
| 233699 | aBuf[5] = (i>>16) & 0xFF; |
| 233700 | aBuf[6] = (i>> 8) & 0xFF; |
| 233701 | aBuf[7] = (i>> 0) & 0xFF; |
| 233702 | } |
| 233703 | |
| 233704 | /* |
| 233705 | ** Write a double value to the buffer aBuf[]. |
| 233706 | */ |
| 233707 | static void sessionPutDouble(u8 *aBuf, double r){ |
| 233708 | /* TODO: SQLite does something special to deal with mixed-endian |
| 233709 | ** floating point values (e.g. ARM7). This code probably should |
| 233710 | ** too. */ |
| 233711 | u64 i; |
| 233712 | assert( sizeof(double)==8 && sizeof(u64)==8 ); |
| 233713 | memcpy(&i, &r, 8); |
| 233714 | sessionPutI64(aBuf, i); |
| 233715 | } |
| 233716 | |
| 233717 | /* |
| 233718 | ** This function is used to serialize the contents of value pValue (see |
| 233719 | ** comment titled "RECORD FORMAT" above). |
| 233720 | ** |
| @@ -233415,20 +233749,17 @@ | |
| 233749 | case SQLITE_FLOAT: |
| 233750 | if( aBuf ){ |
| 233751 | /* TODO: SQLite does something special to deal with mixed-endian |
| 233752 | ** floating point values (e.g. ARM7). This code probably should |
| 233753 | ** too. */ |
| 233754 | if( eType==SQLITE_INTEGER ){ |
| 233755 | u64 i = (u64)sqlite3_value_int64(pValue); |
| 233756 | sessionPutI64(&aBuf[1], i); |
| 233757 | }else{ |
| 233758 | double r = sqlite3_value_double(pValue); |
| 233759 | sessionPutDouble(&aBuf[1], r); |
| 233760 | } |
| 233761 | } |
| 233762 | nByte = 9; |
| 233763 | break; |
| 233764 | |
| 233765 | default: { |
| @@ -234356,13 +234687,11 @@ | |
| 234687 | break; |
| 234688 | } |
| 234689 | |
| 234690 | case SQLITE_FLOAT: { |
| 234691 | double rVal = sqlite3_column_double(pDflt, iField); |
| 234692 | sessionPutDouble(&pNew->aRecord[pNew->nRecord], rVal); |
| 234693 | pNew->nRecord += 8; |
| 234694 | break; |
| 234695 | } |
| 234696 | |
| 234697 | case SQLITE_TEXT: { |
| @@ -235615,19 +235944,18 @@ | |
| 235944 | ){ |
| 235945 | if( *pRc==SQLITE_OK ){ |
| 235946 | int eType = sqlite3_column_type(pStmt, iCol); |
| 235947 | sessionAppendByte(p, (u8)eType, pRc); |
| 235948 | if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 235949 | u8 aBuf[8]; |
| 235950 | if( eType==SQLITE_INTEGER ){ |
| 235951 | sqlite3_int64 i = sqlite3_column_int64(pStmt, iCol); |
| 235952 | sessionPutI64(aBuf, i); |
| 235953 | }else{ |
| 235954 | double r = sqlite3_column_double(pStmt, iCol); |
| 235955 | sessionPutDouble(aBuf, r); |
| 235956 | } |
| 235957 | sessionAppendBlob(p, aBuf, 8, pRc); |
| 235958 | } |
| 235959 | if( eType==SQLITE_BLOB || eType==SQLITE_TEXT ){ |
| 235960 | u8 *z; |
| 235961 | int nByte; |
| @@ -238664,10 +238992,25 @@ | |
| 238992 | xFilter, 0, xConflict, pCtx, |
| 238993 | 0, 0, 0 |
| 238994 | ); |
| 238995 | } |
| 238996 | |
| 238997 | /* |
| 238998 | ** The parts of the sqlite3_changegroup structure used by the |
| 238999 | ** sqlite3changegroup_change_xxx() APIs. |
| 239000 | */ |
| 239001 | typedef struct ChangeData ChangeData; |
| 239002 | struct ChangeData { |
| 239003 | SessionTable *pTab; |
| 239004 | int bIndirect; |
| 239005 | int eOp; |
| 239006 | |
| 239007 | int nBufAlloc; |
| 239008 | SessionBuffer *aBuf; |
| 239009 | SessionBuffer record; |
| 239010 | }; |
| 239011 | |
| 239012 | /* |
| 239013 | ** sqlite3_changegroup handle. |
| 239014 | */ |
| 239015 | struct sqlite3_changegroup { |
| 239016 | int rc; /* Error code */ |
| @@ -238675,10 +239018,11 @@ | |
| 239018 | SessionTable *pList; /* List of tables in current patch */ |
| 239019 | SessionBuffer rec; |
| 239020 | |
| 239021 | sqlite3 *db; /* Configured by changegroup_schema() */ |
| 239022 | char *zDb; /* Configured by changegroup_schema() */ |
| 239023 | ChangeData cd; /* Used by changegroup_change_xxx() APIs. */ |
| 239024 | }; |
| 239025 | |
| 239026 | /* |
| 239027 | ** This function is called to merge two changes to the same row together as |
| 239028 | ** part of an sqlite3changeset_concat() operation. A new change object is |
| @@ -238914,19 +239258,18 @@ | |
| 239258 | int eType = sqlite3_column_type(pTab->pDfltStmt, ii); |
| 239259 | sessionAppendByte(pOut, eType, &rc); |
| 239260 | switch( eType ){ |
| 239261 | case SQLITE_FLOAT: |
| 239262 | case SQLITE_INTEGER: { |
| 239263 | if( SQLITE_OK==sessionBufferGrow(pOut, 8, &rc) ){ |
| 239264 | if( eType==SQLITE_INTEGER ){ |
| 239265 | sqlite3_int64 iVal = sqlite3_column_int64(pTab->pDfltStmt, ii); |
| 239266 | sessionPutI64(&pOut->aBuf[pOut->nBuf], iVal); |
| 239267 | }else{ |
| 239268 | double rVal = sqlite3_column_double(pTab->pDfltStmt, ii); |
| 239269 | sessionPutDouble(&pOut->aBuf[pOut->nBuf], rVal); |
| 239270 | } |
| 239271 | pOut->nBuf += 8; |
| 239272 | } |
| 239273 | break; |
| 239274 | } |
| 239275 | |
| @@ -238993,17 +239336,23 @@ | |
| 239336 | int nTab = (int)strlen(zTab); |
| 239337 | u8 *abPK = 0; |
| 239338 | int nCol = 0; |
| 239339 | |
| 239340 | *ppTab = 0; |
| 239341 | |
| 239342 | /* Search the list for an existing table */ |
| 239343 | for(pTab = pGrp->pList; pTab; pTab=pTab->pNext){ |
| 239344 | if( 0==sqlite3_strnicmp(pTab->zName, zTab, nTab+1) ) break; |
| 239345 | } |
| 239346 | |
| 239347 | |
| 239348 | if( pIter ){ |
| 239349 | sqlite3changeset_pk(pIter, &abPK, &nCol); |
| 239350 | }else if( !pTab && !pGrp->db ){ |
| 239351 | return SQLITE_OK; |
| 239352 | } |
| 239353 | |
| 239354 | /* If one was not found above, create a new table now */ |
| 239355 | if( !pTab ){ |
| 239356 | SessionTable **ppNew; |
| 239357 | |
| 239358 | pTab = sqlite3_malloc64(sizeof(SessionTable) + nCol + nTab+1); |
| @@ -239018,12 +239367,12 @@ | |
| 239367 | memcpy(pTab->zName, zTab, nTab+1); |
| 239368 | |
| 239369 | if( pGrp->db ){ |
| 239370 | pTab->nCol = 0; |
| 239371 | rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb); |
| 239372 | if( rc || pTab->nCol==0 ){ |
| 239373 | sqlite3_free(pTab->azCol); |
| 239374 | sqlite3_free(pTab); |
| 239375 | return rc; |
| 239376 | } |
| 239377 | } |
| 239378 | |
| @@ -239034,78 +239383,61 @@ | |
| 239383 | for(ppNew=&pGrp->pList; *ppNew; ppNew=&(*ppNew)->pNext); |
| 239384 | *ppNew = pTab; |
| 239385 | } |
| 239386 | |
| 239387 | /* Check that the table is compatible. */ |
| 239388 | if( pIter && !sessionChangesetCheckCompat(pTab, nCol, abPK) ){ |
| 239389 | rc = SQLITE_SCHEMA; |
| 239390 | } |
| 239391 | |
| 239392 | *ppTab = pTab; |
| 239393 | return rc; |
| 239394 | } |
| 239395 | |
| 239396 | /* |
| 239397 | ** Add a single change to the changegroup pGrp. |
| 239398 | */ |
| 239399 | static int sessionOneChangeToHash( |
| 239400 | sqlite3_changegroup *pGrp, /* Changegroup to update */ |
| 239401 | SessionTable *pTab, /* Table change pertains to */ |
| 239402 | int op, /* One of SQLITE_INSERT, UPDATE, DELETE */ |
| 239403 | int bIndirect, /* True to flag change as "indirect" */ |
| 239404 | int nCol, /* Number of columns in record(s) */ |
| 239405 | u8 *aRec, /* Serialized change record(s) */ |
| 239406 | int nRec, /* Size of aRec[] in bytes */ |
| 239407 | int bRebase /* True if this is a rebase blob */ |
| 239408 | ){ |
| 239409 | int rc = SQLITE_OK; |
| 239410 | int iHash = 0; |
| 239411 | SessionChange *pChange = 0; |
| 239412 | SessionChange *pExist = 0; |
| 239413 | SessionChange **pp = 0; |
| 239414 | |
| 239415 | assert( nRec>0 ); |
| 239416 | |
| 239417 | if( nCol<pTab->nCol ){ |
| 239418 | SessionBuffer *pBuf = &pGrp->rec; |
| 239419 | rc = sessionChangesetExtendRecord(pGrp, pTab, nCol, op, aRec, nRec, pBuf); |
| 239420 | aRec = pBuf->aBuf; |
| 239421 | nRec = pBuf->nBuf; |
| 239422 | assert( pGrp->db ); |
| 239423 | } |
| 239424 | |
| 239425 | if( rc==SQLITE_OK && sessionGrowHash(0, pGrp->bPatch, pTab) ){ |
| 239426 | rc = SQLITE_NOMEM; |
| 239427 | } |
| 239428 | |
| 239429 | if( rc==SQLITE_OK ){ |
| 239430 | /* Search for existing entry. If found, remove it from the hash table. |
| 239431 | ** Code below may link it back in. */ |
| 239432 | iHash = sessionChangeHash( |
| 239433 | pTab, (pGrp->bPatch && op==SQLITE_DELETE), aRec, pTab->nChange |
| 239434 | ); |
| 239435 | for(pp=&pTab->apChange[iHash]; *pp; pp=&(*pp)->pNext){ |
| 239436 | int bPkOnly1 = 0; |
| 239437 | int bPkOnly2 = 0; |
| 239438 | if( pGrp->bPatch ){ |
| 239439 | bPkOnly1 = (*pp)->op==SQLITE_DELETE; |
| 239440 | bPkOnly2 = op==SQLITE_DELETE; |
| 239441 | } |
| 239442 | if( sessionChangeEqual(pTab, bPkOnly1, (*pp)->aRecord, bPkOnly2, aRec) ){ |
| 239443 | pExist = *pp; |
| @@ -239116,18 +239448,59 @@ | |
| 239448 | } |
| 239449 | } |
| 239450 | |
| 239451 | if( rc==SQLITE_OK ){ |
| 239452 | rc = sessionChangeMerge(pTab, bRebase, |
| 239453 | pGrp->bPatch, pExist, op, bIndirect, aRec, nRec, &pChange |
| 239454 | ); |
| 239455 | } |
| 239456 | if( rc==SQLITE_OK && pChange ){ |
| 239457 | pChange->pNext = pTab->apChange[iHash]; |
| 239458 | pTab->apChange[iHash] = pChange; |
| 239459 | pTab->nEntry++; |
| 239460 | } |
| 239461 | |
| 239462 | return rc; |
| 239463 | } |
| 239464 | |
| 239465 | /* |
| 239466 | ** Add the change currently indicated by iterator pIter to the hash table |
| 239467 | ** belonging to changegroup pGrp. |
| 239468 | */ |
| 239469 | static int sessionOneChangeIterToHash( |
| 239470 | sqlite3_changegroup *pGrp, |
| 239471 | sqlite3_changeset_iter *pIter, |
| 239472 | int bRebase |
| 239473 | ){ |
| 239474 | u8 *aRec = &pIter->in.aData[pIter->in.iCurrent + 2]; |
| 239475 | int nRec = (pIter->in.iNext - pIter->in.iCurrent) - 2; |
| 239476 | const char *zTab = 0; |
| 239477 | int nCol = 0; |
| 239478 | int op = 0; |
| 239479 | int bIndirect = 0; |
| 239480 | int rc = SQLITE_OK; |
| 239481 | SessionTable *pTab = 0; |
| 239482 | |
| 239483 | /* Ensure that only changesets, or only patchsets, but not a mixture |
| 239484 | ** of both, are being combined. It is an error to try to combine a |
| 239485 | ** changeset and a patchset. */ |
| 239486 | if( pGrp->pList==0 ){ |
| 239487 | pGrp->bPatch = pIter->bPatchset; |
| 239488 | }else if( pIter->bPatchset!=pGrp->bPatch ){ |
| 239489 | rc = SQLITE_ERROR; |
| 239490 | } |
| 239491 | |
| 239492 | if( rc==SQLITE_OK ){ |
| 239493 | sqlite3changeset_op(pIter, &zTab, &nCol, &op, &bIndirect); |
| 239494 | rc = sessionChangesetFindTable(pGrp, zTab, pIter, &pTab); |
| 239495 | } |
| 239496 | |
| 239497 | if( rc==SQLITE_OK ){ |
| 239498 | rc = sessionOneChangeToHash( |
| 239499 | pGrp, pTab, op, bIndirect, nCol, aRec, nRec, bRebase |
| 239500 | ); |
| 239501 | } |
| 239502 | |
| 239503 | if( rc==SQLITE_OK ) rc = pIter->rc; |
| 239504 | return rc; |
| 239505 | } |
| 239506 | |
| @@ -239144,11 +239517,11 @@ | |
| 239517 | int nRec; |
| 239518 | int rc = SQLITE_OK; |
| 239519 | |
| 239520 | pIter->in.bNoDiscard = 1; |
| 239521 | while( SQLITE_ROW==(sessionChangesetNext(pIter, &aRec, &nRec, 0)) ){ |
| 239522 | rc = sessionOneChangeIterToHash(pGrp, pIter, bRebase); |
| 239523 | if( rc!=SQLITE_OK ) break; |
| 239524 | } |
| 239525 | |
| 239526 | if( rc==SQLITE_OK ) rc = pIter->rc; |
| 239527 | return rc; |
| @@ -239233,10 +239606,37 @@ | |
| 239606 | memset(p, 0, sizeof(sqlite3_changegroup)); |
| 239607 | } |
| 239608 | *pp = p; |
| 239609 | return rc; |
| 239610 | } |
| 239611 | |
| 239612 | /* |
| 239613 | ** Configure a changegroup object. |
| 239614 | */ |
| 239615 | SQLITE_API int sqlite3changegroup_config( |
| 239616 | sqlite3_changegroup *pGrp, |
| 239617 | int op, |
| 239618 | void *pArg |
| 239619 | ){ |
| 239620 | int rc = SQLITE_OK; |
| 239621 | |
| 239622 | switch( op ){ |
| 239623 | case SQLITE_CHANGEGROUP_CONFIG_PATCHSET: { |
| 239624 | int arg = *(int*)pArg; |
| 239625 | if( pGrp->pList==0 && arg>=0 ){ |
| 239626 | pGrp->bPatch = (arg>0); |
| 239627 | } |
| 239628 | *(int*)pArg = pGrp->bPatch; |
| 239629 | break; |
| 239630 | } |
| 239631 | default: |
| 239632 | rc = SQLITE_MISUSE; |
| 239633 | break; |
| 239634 | } |
| 239635 | |
| 239636 | return rc; |
| 239637 | } |
| 239638 | |
| 239639 | /* |
| 239640 | ** Provide a database schema to the changegroup object. |
| 239641 | */ |
| 239642 | SQLITE_API int sqlite3changegroup_schema( |
| @@ -239292,11 +239692,11 @@ | |
| 239692 | ){ |
| 239693 | /* Iterator does not point to any valid entry or is an INVERT iterator. */ |
| 239694 | rc = SQLITE_ERROR; |
| 239695 | }else{ |
| 239696 | pIter->in.bNoDiscard = 1; |
| 239697 | rc = sessionOneChangeIterToHash(pGrp, pIter, 0); |
| 239698 | } |
| 239699 | return rc; |
| 239700 | } |
| 239701 | |
| 239702 | /* |
| @@ -239344,10 +239744,16 @@ | |
| 239744 | /* |
| 239745 | ** Delete a changegroup object. |
| 239746 | */ |
| 239747 | SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup *pGrp){ |
| 239748 | if( pGrp ){ |
| 239749 | int ii; |
| 239750 | for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){ |
| 239751 | sqlite3_free(pGrp->cd.aBuf[ii].aBuf); |
| 239752 | } |
| 239753 | sqlite3_free(pGrp->cd.record.aBuf); |
| 239754 | sqlite3_free(pGrp->cd.aBuf); |
| 239755 | sqlite3_free(pGrp->zDb); |
| 239756 | sessionDeleteTable(0, pGrp->pList); |
| 239757 | sqlite3_free(pGrp->rec.aBuf); |
| 239758 | sqlite3_free(pGrp); |
| 239759 | } |
| @@ -239771,10 +240177,332 @@ | |
| 240177 | } |
| 240178 | default: |
| 240179 | rc = SQLITE_MISUSE; |
| 240180 | break; |
| 240181 | } |
| 240182 | return rc; |
| 240183 | } |
| 240184 | |
| 240185 | /* |
| 240186 | ** Begin adding a change to a changegroup object. |
| 240187 | */ |
| 240188 | SQLITE_API int sqlite3changegroup_change_begin( |
| 240189 | sqlite3_changegroup *pGrp, |
| 240190 | int eOp, |
| 240191 | const char *zTab, |
| 240192 | int bIndirect, |
| 240193 | char **pzErr |
| 240194 | ){ |
| 240195 | SessionTable *pTab = 0; |
| 240196 | int rc = SQLITE_OK; |
| 240197 | |
| 240198 | if( pGrp->cd.pTab ){ |
| 240199 | rc = SQLITE_MISUSE; |
| 240200 | }else if( eOp!=SQLITE_INSERT && eOp!=SQLITE_UPDATE && eOp!=SQLITE_DELETE ){ |
| 240201 | rc = SQLITE_ERROR; |
| 240202 | }else{ |
| 240203 | rc = sessionChangesetFindTable(pGrp, zTab, 0, &pTab); |
| 240204 | } |
| 240205 | if( rc==SQLITE_OK ){ |
| 240206 | if( pTab==0 ){ |
| 240207 | if( pzErr ){ |
| 240208 | *pzErr = sqlite3_mprintf("no such table: %s", zTab); |
| 240209 | } |
| 240210 | rc = SQLITE_ERROR; |
| 240211 | }else{ |
| 240212 | int nReq = pTab->nCol * (eOp==SQLITE_UPDATE ? 2 : 1); |
| 240213 | pGrp->cd.pTab = pTab; |
| 240214 | pGrp->cd.eOp = eOp; |
| 240215 | pGrp->cd.bIndirect = bIndirect; |
| 240216 | |
| 240217 | if( pGrp->cd.nBufAlloc<nReq ){ |
| 240218 | SessionBuffer *aBuf = (SessionBuffer*)sqlite3_realloc( |
| 240219 | pGrp->cd.aBuf, nReq * sizeof(SessionBuffer) |
| 240220 | ); |
| 240221 | if( aBuf==0 ){ |
| 240222 | rc = SQLITE_NOMEM; |
| 240223 | }else{ |
| 240224 | memset(&aBuf[pGrp->cd.nBufAlloc], 0, |
| 240225 | sizeof(SessionBuffer) * (nReq - pGrp->cd.nBufAlloc) |
| 240226 | ); |
| 240227 | pGrp->cd.aBuf = aBuf; |
| 240228 | pGrp->cd.nBufAlloc = nReq; |
| 240229 | } |
| 240230 | } |
| 240231 | |
| 240232 | #ifdef SQLITE_DEBUG |
| 240233 | { |
| 240234 | /* Assert that all column values are currently undefined */ |
| 240235 | int ii; |
| 240236 | for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){ |
| 240237 | assert( pGrp->cd.aBuf[ii].nBuf==0 ); |
| 240238 | } |
| 240239 | } |
| 240240 | #endif |
| 240241 | } |
| 240242 | } |
| 240243 | |
| 240244 | return rc; |
| 240245 | } |
| 240246 | |
| 240247 | /* |
| 240248 | ** This function does processing common to the _change_int64(), _change_text() |
| 240249 | ** and other similar APIs. |
| 240250 | */ |
| 240251 | static int checkChangeParams( |
| 240252 | sqlite3_changegroup *pGrp, |
| 240253 | int bNew, |
| 240254 | int iCol, |
| 240255 | sqlite3_int64 nReq, |
| 240256 | SessionBuffer **ppBuf |
| 240257 | ){ |
| 240258 | int rc = SQLITE_OK; |
| 240259 | if( pGrp->cd.pTab==0 ){ |
| 240260 | rc = SQLITE_MISUSE; |
| 240261 | }else if( iCol<0 || iCol>=pGrp->cd.pTab->nCol ){ |
| 240262 | rc = SQLITE_RANGE; |
| 240263 | }else if( |
| 240264 | (bNew && pGrp->cd.eOp==SQLITE_DELETE) |
| 240265 | || (!bNew && pGrp->cd.eOp==SQLITE_INSERT) |
| 240266 | ){ |
| 240267 | rc = SQLITE_ERROR; |
| 240268 | }else{ |
| 240269 | SessionBuffer *pBuf = &pGrp->cd.aBuf[iCol]; |
| 240270 | if( pGrp->cd.eOp==SQLITE_UPDATE && bNew ){ |
| 240271 | pBuf += pGrp->cd.pTab->nCol; |
| 240272 | } |
| 240273 | pBuf->nBuf = 0; |
| 240274 | sessionBufferGrow(pBuf, nReq, &rc); |
| 240275 | pBuf->nBuf = nReq; |
| 240276 | *ppBuf = pBuf; |
| 240277 | } |
| 240278 | return rc; |
| 240279 | } |
| 240280 | |
| 240281 | /* |
| 240282 | ** Configure the change currently under construction with an integer value. |
| 240283 | */ |
| 240284 | SQLITE_API int sqlite3changegroup_change_int64( |
| 240285 | sqlite3_changegroup *pGrp, |
| 240286 | int bNew, |
| 240287 | int iCol, |
| 240288 | sqlite3_int64 iVal |
| 240289 | ){ |
| 240290 | int rc = SQLITE_OK; |
| 240291 | SessionBuffer *pBuf = 0; |
| 240292 | |
| 240293 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, 9, &pBuf)) ){ |
| 240294 | return rc; |
| 240295 | } |
| 240296 | |
| 240297 | pBuf->aBuf[0] = SQLITE_INTEGER; |
| 240298 | sessionPutI64(&pBuf->aBuf[1], iVal); |
| 240299 | return SQLITE_OK; |
| 240300 | } |
| 240301 | |
| 240302 | /* |
| 240303 | ** Configure the change currently under construction with a null value. |
| 240304 | */ |
| 240305 | SQLITE_API int sqlite3changegroup_change_null( |
| 240306 | sqlite3_changegroup *pGrp, |
| 240307 | int bNew, |
| 240308 | int iCol |
| 240309 | ){ |
| 240310 | int rc = SQLITE_OK; |
| 240311 | SessionBuffer *pBuf = 0; |
| 240312 | |
| 240313 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, 1, &pBuf)) ){ |
| 240314 | return rc; |
| 240315 | } |
| 240316 | |
| 240317 | pBuf->aBuf[0] = SQLITE_NULL; |
| 240318 | return SQLITE_OK; |
| 240319 | } |
| 240320 | |
| 240321 | /* |
| 240322 | ** Configure the change currently under construction with a real value. |
| 240323 | */ |
| 240324 | SQLITE_API int sqlite3changegroup_change_double( |
| 240325 | sqlite3_changegroup *pGrp, |
| 240326 | int bNew, |
| 240327 | int iCol, |
| 240328 | double fVal |
| 240329 | ){ |
| 240330 | int rc = SQLITE_OK; |
| 240331 | SessionBuffer *pBuf = 0; |
| 240332 | |
| 240333 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, 9, &pBuf)) ){ |
| 240334 | return rc; |
| 240335 | } |
| 240336 | |
| 240337 | pBuf->aBuf[0] = SQLITE_FLOAT; |
| 240338 | sessionPutDouble(&pBuf->aBuf[1], fVal); |
| 240339 | return SQLITE_OK; |
| 240340 | } |
| 240341 | |
| 240342 | /* |
| 240343 | ** Configure the change currently under construction with a text value. |
| 240344 | */ |
| 240345 | SQLITE_API int sqlite3changegroup_change_text( |
| 240346 | sqlite3_changegroup *pGrp, |
| 240347 | int bNew, |
| 240348 | int iCol, |
| 240349 | const char *pVal, |
| 240350 | int nVal |
| 240351 | ){ |
| 240352 | int nText = nVal>=0 ? nVal : strlen(pVal); |
| 240353 | sqlite3_int64 nByte = 1 + sessionVarintLen(nText) + nText; |
| 240354 | int rc = SQLITE_OK; |
| 240355 | SessionBuffer *pBuf = 0; |
| 240356 | |
| 240357 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, nByte, &pBuf)) ){ |
| 240358 | return rc; |
| 240359 | } |
| 240360 | |
| 240361 | pBuf->aBuf[0] = SQLITE_TEXT; |
| 240362 | pBuf->nBuf = (1 + sessionVarintPut(&pBuf->aBuf[1], nText)); |
| 240363 | memcpy(&pBuf->aBuf[pBuf->nBuf], pVal, nText); |
| 240364 | pBuf->nBuf += nText; |
| 240365 | |
| 240366 | return SQLITE_OK; |
| 240367 | } |
| 240368 | |
| 240369 | /* |
| 240370 | ** Configure the change currently under construction with a blob value. |
| 240371 | */ |
| 240372 | SQLITE_API int sqlite3changegroup_change_blob( |
| 240373 | sqlite3_changegroup *pGrp, |
| 240374 | int bNew, |
| 240375 | int iCol, |
| 240376 | const void *pVal, |
| 240377 | int nVal |
| 240378 | ){ |
| 240379 | sqlite3_int64 nByte = 1 + sessionVarintLen(nVal) + nVal; |
| 240380 | int rc = SQLITE_OK; |
| 240381 | SessionBuffer *pBuf = 0; |
| 240382 | |
| 240383 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, nByte, &pBuf)) ){ |
| 240384 | return rc; |
| 240385 | } |
| 240386 | |
| 240387 | pBuf->aBuf[0] = SQLITE_BLOB; |
| 240388 | pBuf->nBuf = (1 + sessionVarintPut(&pBuf->aBuf[1], nVal)); |
| 240389 | memcpy(&pBuf->aBuf[pBuf->nBuf], pVal, nVal); |
| 240390 | pBuf->nBuf += nVal; |
| 240391 | |
| 240392 | return SQLITE_OK; |
| 240393 | } |
| 240394 | |
| 240395 | /* |
| 240396 | ** Finish any change currently being constructed by the changegroup object. |
| 240397 | */ |
| 240398 | SQLITE_API int sqlite3changegroup_change_finish( |
| 240399 | sqlite3_changegroup *pGrp, |
| 240400 | int bDiscard, |
| 240401 | char **pzErr |
| 240402 | ){ |
| 240403 | int rc = SQLITE_OK; |
| 240404 | if( pGrp->cd.pTab ){ |
| 240405 | SessionBuffer *aBuf = pGrp->cd.aBuf; |
| 240406 | int ii; |
| 240407 | |
| 240408 | if( bDiscard==0 ){ |
| 240409 | int nBuf = pGrp->cd.pTab->nCol; |
| 240410 | u8 eUndef = SQLITE_NULL; |
| 240411 | if( pGrp->cd.eOp==SQLITE_UPDATE ){ |
| 240412 | for(ii=0; ii<nBuf; ii++){ |
| 240413 | if( pGrp->cd.pTab->abPK[ii] ){ |
| 240414 | if( aBuf[ii].nBuf<=1 ){ |
| 240415 | *pzErr = sqlite3_mprintf( |
| 240416 | "invalid change: %s value in PK of old.* record", |
| 240417 | aBuf[ii].nBuf==1 ? "null" : "undefined" |
| 240418 | ); |
| 240419 | rc = SQLITE_ERROR; |
| 240420 | break; |
| 240421 | }else if( aBuf[ii + nBuf].nBuf>0 ){ |
| 240422 | *pzErr = sqlite3_mprintf( |
| 240423 | "invalid change: defined value in PK of new.* record" |
| 240424 | ); |
| 240425 | rc = SQLITE_ERROR; |
| 240426 | break; |
| 240427 | } |
| 240428 | }else |
| 240429 | if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){ |
| 240430 | *pzErr = sqlite3_mprintf( |
| 240431 | "invalid change: column %d " |
| 240432 | "- old.* value is %sdefined but new.* is %sdefined", |
| 240433 | ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un" |
| 240434 | ); |
| 240435 | rc = SQLITE_ERROR; |
| 240436 | break; |
| 240437 | } |
| 240438 | } |
| 240439 | eUndef = 0x00; |
| 240440 | if( pGrp->bPatch==0 ) nBuf = nBuf * 2; |
| 240441 | }else{ |
| 240442 | for(ii=0; ii<nBuf; ii++){ |
| 240443 | int isPK = pGrp->cd.pTab->abPK[ii]; |
| 240444 | if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK) |
| 240445 | && aBuf[ii].nBuf==0 |
| 240446 | ){ |
| 240447 | *pzErr = sqlite3_mprintf( |
| 240448 | "invalid change: column %d is undefined", ii |
| 240449 | ); |
| 240450 | rc = SQLITE_ERROR; |
| 240451 | break; |
| 240452 | } |
| 240453 | if( aBuf[ii].nBuf==1 && isPK ){ |
| 240454 | *pzErr = sqlite3_mprintf( |
| 240455 | "invalid change: null value in PK" |
| 240456 | ); |
| 240457 | rc = SQLITE_ERROR; |
| 240458 | break; |
| 240459 | } |
| 240460 | } |
| 240461 | } |
| 240462 | |
| 240463 | pGrp->cd.record.nBuf = 0; |
| 240464 | for(ii=0; ii<nBuf; ii++){ |
| 240465 | SessionBuffer *p = &pGrp->cd.aBuf[ii]; |
| 240466 | if( pGrp->bPatch ){ |
| 240467 | if( pGrp->cd.pTab->abPK[ii]==0 ){ |
| 240468 | if( pGrp->cd.eOp==SQLITE_UPDATE ){ |
| 240469 | p += pGrp->cd.pTab->nCol; |
| 240470 | }else if( pGrp->cd.eOp==SQLITE_DELETE ){ |
| 240471 | continue; |
| 240472 | } |
| 240473 | } |
| 240474 | } |
| 240475 | if( 0==sessionBufferGrow(&pGrp->cd.record, p->nBuf?p->nBuf:1, &rc) ){ |
| 240476 | if( p->nBuf ){ |
| 240477 | memcpy(&pGrp->cd.record.aBuf[pGrp->cd.record.nBuf],p->aBuf,p->nBuf); |
| 240478 | pGrp->cd.record.nBuf += p->nBuf; |
| 240479 | }else{ |
| 240480 | pGrp->cd.record.aBuf[pGrp->cd.record.nBuf++] = eUndef; |
| 240481 | } |
| 240482 | } |
| 240483 | } |
| 240484 | if( rc==SQLITE_OK ){ |
| 240485 | rc = sessionOneChangeToHash( |
| 240486 | pGrp, pGrp->cd.pTab, |
| 240487 | pGrp->cd.eOp, pGrp->cd.bIndirect, pGrp->cd.pTab->nCol, |
| 240488 | pGrp->cd.record.aBuf, pGrp->cd.record.nBuf, 0 |
| 240489 | ); |
| 240490 | } |
| 240491 | } |
| 240492 | |
| 240493 | /* Reset all aBuf[] entries to "undefined". */ |
| 240494 | { |
| 240495 | int nZero = pGrp->cd.pTab->nCol; |
| 240496 | if( pGrp->cd.eOp==SQLITE_UPDATE ) nZero += nZero; |
| 240497 | for(ii=0; ii<nZero; ii++){ |
| 240498 | pGrp->cd.aBuf[ii].nBuf = 0; |
| 240499 | } |
| 240500 | } |
| 240501 | pGrp->cd.pTab = 0; |
| 240502 | } |
| 240503 | |
| 240504 | return rc; |
| 240505 | } |
| 240506 | |
| 240507 | #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 240508 | |
| @@ -262478,11 +263206,11 @@ | |
| 263206 | int nArg, /* Number of args */ |
| 263207 | sqlite3_value **apUnused /* Function arguments */ |
| 263208 | ){ |
| 263209 | assert( nArg==0 ); |
| 263210 | UNUSED_PARAM2(nArg, apUnused); |
| 263211 | sqlite3_result_text(pCtx, "fts5: 2026-04-01 11:39:13 009b576dcd5fccaaa52459dbfaa1b2a6fcf6d372e4b8d63553dfa88aab9a759c", -1, SQLITE_TRANSIENT); |
| 263212 | } |
| 263213 | |
| 263214 | /* |
| 263215 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 263216 | ** |
| 263217 |
+284
-48
| --- extsrc/sqlite3.h | ||
| +++ extsrc/sqlite3.h | ||
| @@ -146,14 +146,14 @@ | ||
| 146 | 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | 148 | */ |
| 149 | 149 | #define SQLITE_VERSION "3.53.0" |
| 150 | 150 | #define SQLITE_VERSION_NUMBER 3053000 |
| 151 | -#define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c" | |
| 151 | +#define SQLITE_SOURCE_ID "2026-04-01 11:54:20 7bc1d0c4572f126cfe68fa51fe992d2bd46b1e57c04721991bd5fad36dd795c5" | |
| 152 | 152 | #define SQLITE_SCM_BRANCH "trunk" |
| 153 | 153 | #define SQLITE_SCM_TAGS "" |
| 154 | -#define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z" | |
| 154 | +#define SQLITE_SCM_DATETIME "2026-04-01T11:54:20.065Z" | |
| 155 | 155 | |
| 156 | 156 | /* |
| 157 | 157 | ** CAPI3REF: Run-Time Library Version Numbers |
| 158 | 158 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 159 | 159 | ** |
| @@ -576,11 +576,11 @@ | ||
| 576 | 576 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 577 | 577 | #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) |
| 578 | 578 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 579 | 579 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 580 | 580 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 581 | -#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ | |
| 581 | +#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal only */ | |
| 582 | 582 | |
| 583 | 583 | /* |
| 584 | 584 | ** CAPI3REF: Flags For File Open Operations |
| 585 | 585 | ** |
| 586 | 586 | ** These bit values are intended for use in the |
| @@ -1288,10 +1288,16 @@ | ||
| 1288 | 1288 | /* deprecated names */ |
| 1289 | 1289 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1290 | 1290 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1291 | 1291 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| 1292 | 1292 | |
| 1293 | +/* reserved file-control numbers: | |
| 1294 | +** 101 | |
| 1295 | +** 102 | |
| 1296 | +** 103 | |
| 1297 | +*/ | |
| 1298 | + | |
| 1293 | 1299 | |
| 1294 | 1300 | /* |
| 1295 | 1301 | ** CAPI3REF: Mutex Handle |
| 1296 | 1302 | ** |
| 1297 | 1303 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -1709,11 +1715,12 @@ | ||
| 1709 | 1715 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1710 | 1716 | ** The exceptional configuration options that may be invoked at any time |
| 1711 | 1717 | ** are called "anytime configuration options". |
| 1712 | 1718 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1713 | 1719 | ** [sqlite3_shutdown()] with a first argument that is not an anytime |
| 1714 | -** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE. | |
| 1720 | +** configuration option, then the sqlite3_config() call will | |
| 1721 | +** return SQLITE_MISUSE. | |
| 1715 | 1722 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1716 | 1723 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1717 | 1724 | ** |
| 1718 | 1725 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1719 | 1726 | ** ^If the option is unknown or SQLite is unable to set the option |
| @@ -2275,13 +2282,14 @@ | ||
| 2275 | 2282 | ** <li><P>The second argument ("sz") is the |
| 2276 | 2283 | ** size of each lookaside buffer slot. Lookaside is disabled if "sz" |
| 2277 | 2284 | ** is less than 8. The "sz" argument should be a multiple of 8 less than |
| 2278 | 2285 | ** 65536. If "sz" does not meet this constraint, it is reduced in size until |
| 2279 | 2286 | ** it does. |
| 2280 | -** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled | |
| 2281 | -** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so | |
| 2282 | -** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" | |
| 2287 | +** <li><p>The third argument ("cnt") is the number of slots. | |
| 2288 | +** Lookaside is disabled if "cnt"is less than 1. | |
| 2289 | +* The "cnt" value will be reduced, if necessary, so | |
| 2290 | +** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" | |
| 2283 | 2291 | ** parameter is usually chosen so that the product of "sz" and "cnt" is less |
| 2284 | 2292 | ** than 1,000,000. |
| 2285 | 2293 | ** </ol> |
| 2286 | 2294 | ** <p>If the "buf" argument is not NULL, then it must |
| 2287 | 2295 | ** point to a memory buffer with a size that is greater than |
| @@ -2656,11 +2664,11 @@ | ||
| 2656 | 2664 | ** default value 17, as of SQLite version 3.52.0. The value was 15 in all |
| 2657 | 2665 | ** prior versions.<p> |
| 2658 | 2666 | ** This option takes two arguments which are an integer and a pointer |
| 2659 | 2667 | ** to an integer. The first argument is a small integer, between 3 and 23, or |
| 2660 | 2668 | ** zero. The FP_DIGITS setting is changed to that small integer, or left |
| 2661 | -** unaltered if the first argument is zero or out of range. The second argument | |
| 2669 | +** unaltered if the first argument is zero or out of range. The second argument | |
| 2662 | 2670 | ** is a pointer to an integer. If the pointer is not NULL, then the value of |
| 2663 | 2671 | ** the FP_DIGITS setting, after possibly being modified by the first |
| 2664 | 2672 | ** arguments, is written into the integer to which the second argument points. |
| 2665 | 2673 | ** </dd> |
| 2666 | 2674 | ** |
| @@ -2668,14 +2676,16 @@ | ||
| 2668 | 2676 | ** |
| 2669 | 2677 | ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3> |
| 2670 | 2678 | ** |
| 2671 | 2679 | ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the |
| 2672 | 2680 | ** overall call to [sqlite3_db_config()] has a total of four parameters. |
| 2673 | -** The first argument (the third parameter to sqlite3_db_config()) is an integer. | |
| 2674 | -** The second argument is a pointer to an integer. If the first argument is 1, | |
| 2675 | -** then the option becomes enabled. If the first integer argument is 0, then the | |
| 2676 | -** option is disabled. If the first argument is -1, then the option setting | |
| 2681 | +** The first argument (the third parameter to sqlite3_db_config()) is | |
| 2682 | +** an integer. | |
| 2683 | +** The second argument is a pointer to an integer. If the first argument is 1, | |
| 2684 | +** then the option becomes enabled. If the first integer argument is 0, | |
| 2685 | +** then the option is disabled. | |
| 2686 | +** If the first argument is -1, then the option setting | |
| 2677 | 2687 | ** is unchanged. The second argument, the pointer to an integer, may be NULL. |
| 2678 | 2688 | ** If the second argument is not NULL, then a value of 0 or 1 is written into |
| 2679 | 2689 | ** the integer to which the second argument points, depending on whether the |
| 2680 | 2690 | ** setting is disabled or enabled after applying any changes specified by |
| 2681 | 2691 | ** the first argument. |
| @@ -5848,12 +5858,13 @@ | ||
| 5848 | 5858 | ** that the application-defined collating sequence created expects its |
| 5849 | 5859 | ** input strings to be in UTF16 in native byte order, and that the start |
| 5850 | 5860 | ** of the strings must be aligned to a 2-byte boundary. |
| 5851 | 5861 | ** |
| 5852 | 5862 | ** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be |
| 5853 | -** used to specify the text encoding to strings input to [sqlite3_result_text64()] | |
| 5854 | -** and [sqlite3_bind_text64()]. It means that the input string (call it "z") | |
| 5863 | +** used to specify the text encoding to strings input to | |
| 5864 | +** [sqlite3_result_text64()] and [sqlite3_bind_text64()]. | |
| 5865 | +** The SQLITE_UTF8_ZT encoding means that the input string (call it "z") | |
| 5855 | 5866 | ** is UTF-8 encoded and that it is zero-terminated. If the length parameter |
| 5856 | 5867 | ** (call it "n") is non-negative, this encoding option means that the caller |
| 5857 | 5868 | ** guarantees that z array contains at least n+1 bytes and that the z[n] |
| 5858 | 5869 | ** byte has a value of zero. |
| 5859 | 5870 | ** This option gives the same output as SQLITE_UTF8, but can be more efficient |
| @@ -6101,30 +6112,26 @@ | ||
| 6101 | 6112 | ** |
| 6102 | 6113 | ** These routines must be called from the same thread as |
| 6103 | 6114 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 6104 | 6115 | ** |
| 6105 | 6116 | ** As long as the input parameter is correct, these routines can only |
| 6106 | -** fail if an out-of-memory error occurs during a format conversion. | |
| 6107 | -** Only the following subset of interfaces are subject to out-of-memory | |
| 6108 | -** errors: | |
| 6109 | -** | |
| 6110 | -** <ul> | |
| 6111 | -** <li> sqlite3_value_blob() | |
| 6112 | -** <li> sqlite3_value_text() | |
| 6113 | -** <li> sqlite3_value_text16() | |
| 6114 | -** <li> sqlite3_value_text16le() | |
| 6115 | -** <li> sqlite3_value_text16be() | |
| 6116 | -** <li> sqlite3_value_bytes() | |
| 6117 | -** <li> sqlite3_value_bytes16() | |
| 6118 | -** </ul> | |
| 6119 | -** | |
| 6117 | +** fail if an out-of-memory error occurs while trying to do a | |
| 6118 | +** UTF8→UTF16 or UTF16→UTF8 conversion. | |
| 6120 | 6119 | ** If an out-of-memory error occurs, then the return value from these |
| 6121 | 6120 | ** routines is the same as if the column had contained an SQL NULL value. |
| 6122 | -** Valid SQL NULL returns can be distinguished from out-of-memory errors | |
| 6123 | -** by invoking the [sqlite3_errcode()] immediately after the suspect | |
| 6121 | +** If the input sqlite3_value was not obtained from [sqlite3_value_dup()], | |
| 6122 | +** then valid SQL NULL returns can also be distinguished from | |
| 6123 | +** out-of-memory errors after extracting the value | |
| 6124 | +** by invoking the [sqlite3_errcode()] immediately after the suspicious | |
| 6124 | 6125 | ** return value is obtained and before any |
| 6125 | 6126 | ** other SQLite interface is called on the same [database connection]. |
| 6127 | +** If the input sqlite3_value was obtained from sqlite3_value_dup() then | |
| 6128 | +** it is disconnected from the database connection and so sqlite3_errcode() | |
| 6129 | +** will not work. | |
| 6130 | +** In that case, the only way to distinguish an out-of-memory | |
| 6131 | +** condition from a true SQL NULL is to invoke sqlite3_value_type() on the | |
| 6132 | +** input to see if it is NULL prior to trying to extract the value. | |
| 6126 | 6133 | */ |
| 6127 | 6134 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 6128 | 6135 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 6129 | 6136 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 6130 | 6137 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| @@ -6147,11 +6154,12 @@ | ||
| 6147 | 6154 | ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
| 6148 | 6155 | ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding |
| 6149 | 6156 | ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
| 6150 | 6157 | ** returns something other than SQLITE_TEXT, then the return value from |
| 6151 | 6158 | ** sqlite3_value_encoding(X) is meaningless. ^Calls to |
| 6152 | -** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)], | |
| 6159 | +** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], | |
| 6160 | +** [sqlite3_value_text16be(X)], | |
| 6153 | 6161 | ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or |
| 6154 | 6162 | ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and |
| 6155 | 6163 | ** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
| 6156 | 6164 | ** |
| 6157 | 6165 | ** This routine is intended for used by applications that test and validate |
| @@ -6278,21 +6286,21 @@ | ||
| 6278 | 6286 | ** associate auxiliary data with argument values. If the same argument |
| 6279 | 6287 | ** value is passed to multiple invocations of the same SQL function during |
| 6280 | 6288 | ** query execution, under some circumstances the associated auxiliary data |
| 6281 | 6289 | ** might be preserved. An example of where this might be useful is in a |
| 6282 | 6290 | ** regular-expression matching function. The compiled version of the regular |
| 6283 | -** expression can be stored as auxiliary data associated with the pattern string. | |
| 6284 | -** Then as long as the pattern string remains the same, | |
| 6291 | +** expression can be stored as auxiliary data associated with the pattern | |
| 6292 | +** string. Then as long as the pattern string remains the same, | |
| 6285 | 6293 | ** the compiled regular expression can be reused on multiple |
| 6286 | 6294 | ** invocations of the same function. |
| 6287 | 6295 | ** |
| 6288 | -** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data | |
| 6289 | -** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument | |
| 6290 | -** value to the application-defined function. ^N is zero for the left-most | |
| 6291 | -** function argument. ^If there is no auxiliary data | |
| 6292 | -** associated with the function argument, the sqlite3_get_auxdata(C,N) interface | |
| 6293 | -** returns a NULL pointer. | |
| 6296 | +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary | |
| 6297 | +** data associated by the sqlite3_set_auxdata(C,N,P,X) function with the | |
| 6298 | +** Nth argument value to the application-defined function. ^N is zero | |
| 6299 | +** for the left-most function argument. ^If there is no auxiliary data | |
| 6300 | +** associated with the function argument, the sqlite3_get_auxdata(C,N) | |
| 6301 | +** interface returns a NULL pointer. | |
| 6294 | 6302 | ** |
| 6295 | 6303 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the |
| 6296 | 6304 | ** N-th argument of the application-defined function. ^Subsequent |
| 6297 | 6305 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| 6298 | 6306 | ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or |
| @@ -10401,21 +10409,22 @@ | ||
| 10401 | 10409 | ** |
| 10402 | 10410 | ** <table border=1 cellspacing=0 cellpadding=10 width="90%"> |
| 10403 | 10411 | ** <tr> |
| 10404 | 10412 | ** <td valign="top">sqlite3_vtab_distinct() return value |
| 10405 | 10413 | ** <td valign="top">Rows are returned in aOrderBy order |
| 10406 | -** <td valign="top">Rows with the same value in all aOrderBy columns are adjacent | |
| 10414 | +** <td valign="top">Rows with the same value in all aOrderBy columns are | |
| 10415 | +** adjacent | |
| 10407 | 10416 | ** <td valign="top">Duplicates over all colUsed columns may be omitted |
| 10408 | 10417 | ** <tr><td>0<td>yes<td>yes<td>no |
| 10409 | 10418 | ** <tr><td>1<td>no<td>yes<td>no |
| 10410 | 10419 | ** <tr><td>2<td>no<td>yes<td>yes |
| 10411 | 10420 | ** <tr><td>3<td>yes<td>yes<td>yes |
| 10412 | 10421 | ** </table> |
| 10413 | 10422 | ** |
| 10414 | 10423 | ** ^For the purposes of comparing virtual table output values to see if the |
| 10415 | -** values are the same value for sorting purposes, two NULL values are considered | |
| 10416 | -** to be the same. In other words, the comparison operator is "IS" | |
| 10424 | +** values are the same value for sorting purposes, two NULL values are | |
| 10425 | +** considered to be the same. In other words, the comparison operator is "IS" | |
| 10417 | 10426 | ** (or "IS NOT DISTINCT FROM") and not "==". |
| 10418 | 10427 | ** |
| 10419 | 10428 | ** If a virtual table implementation is unable to meet the requirements |
| 10420 | 10429 | ** specified above, then it must not set the "orderByConsumed" flag in the |
| 10421 | 10430 | ** [sqlite3_index_info] object or an incorrect answer may result. |
| @@ -11265,16 +11274,17 @@ | ||
| 11265 | 11274 | /* |
| 11266 | 11275 | ** CAPI3REF: Bind array values to the CARRAY table-valued function |
| 11267 | 11276 | ** |
| 11268 | 11277 | ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to |
| 11269 | 11278 | ** parameter that is the first argument of the [carray() table-valued function]. |
| 11270 | -** The S parameter is a pointer to the [prepared statement] that uses the carray() | |
| 11271 | -** functions. I is the parameter index to be bound. I must be the index of the | |
| 11272 | -** parameter that is the first argument to the carray() table-valued function. | |
| 11273 | -** P is a pointer to the array to be bound, and N is the number of elements in | |
| 11274 | -** the array. The F argument is one of constants [SQLITE_CARRAY_INT32], | |
| 11275 | -** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], | |
| 11279 | +** The S parameter is a pointer to the [prepared statement] that uses the | |
| 11280 | +** carray() functions. I is the parameter index to be bound. I must be the | |
| 11281 | +** index of the parameter that is the first argument to the carray() | |
| 11282 | +** table-valued function. P is a pointer to the array to be bound, and N | |
| 11283 | +** is the number of elements in the array. The F argument is one of | |
| 11284 | +** constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64], | |
| 11285 | +** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], | |
| 11276 | 11286 | ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P. |
| 11277 | 11287 | ** |
| 11278 | 11288 | ** If the X argument is not a NULL pointer or one of the special |
| 11279 | 11289 | ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke |
| 11280 | 11290 | ** the function X with argument D when it is finished using the data in P. |
| @@ -13327,10 +13337,236 @@ | ||
| 13327 | 13337 | |
| 13328 | 13338 | /* |
| 13329 | 13339 | ** CAPI3REF: Values for sqlite3session_config(). |
| 13330 | 13340 | */ |
| 13331 | 13341 | #define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 13342 | + | |
| 13343 | +/* | |
| 13344 | +** CAPI3REF: Configure a changegroup object | |
| 13345 | +** | |
| 13346 | +** Configure the changegroup object passed as the first argument. | |
| 13347 | +** At present the only valid value for the second parameter is | |
| 13348 | +** [SQLITE_CHANGEGROUP_CONFIG_PATCHSET]. | |
| 13349 | +*/ | |
| 13350 | +SQLITE_API int sqlite3changegroup_config(sqlite3_changegroup*, int, void *pArg); | |
| 13351 | + | |
| 13352 | +/* | |
| 13353 | +** CAPI3REF: Options for sqlite3changegroup_config(). | |
| 13354 | +** | |
| 13355 | +** The following values may be passed as the 2nd parameter to | |
| 13356 | +** sqlite3changegroup_config(). | |
| 13357 | +** | |
| 13358 | +** <dt>SQLITE_CHANGEGROUP_CONFIG_PATCHSET <dd> | |
| 13359 | +** A changegroup object generates either a changeset or patchset. Usually, | |
| 13360 | +** this is determined by whether the first call to sqlite3changegroup_add() | |
| 13361 | +** is passed a changeset or a patchset. Or, if the first changes are added | |
| 13362 | +** to the changegroup object using the sqlite3changegroup_change_xxx() | |
| 13363 | +** APIs, then this option may be used to configure whether the changegroup | |
| 13364 | +** object generates a changeset or patchset. | |
| 13365 | +** | |
| 13366 | +** When this option is invoked, parameter pArg must point to a value of | |
| 13367 | +** type int. If the changegroup currently contains zero changes, and the | |
| 13368 | +** value of the int variable is zero or greater than zero, then the | |
| 13369 | +** changegroup is configured to generate a changeset or patchset, | |
| 13370 | +** respectively. It is a no-op, not an error, if the changegroup is not | |
| 13371 | +** configured because it has already started accumulating changes. | |
| 13372 | +** | |
| 13373 | +** Before returning, the int variable is set to 0 if the changegroup is | |
| 13374 | +** configured to generate a changeset, or 1 if it is configured to generate | |
| 13375 | +** a patchset. | |
| 13376 | +*/ | |
| 13377 | +#define SQLITE_CHANGEGROUP_CONFIG_PATCHSET 1 | |
| 13378 | + | |
| 13379 | + | |
| 13380 | +/* | |
| 13381 | +** CAPI3REF: Begin adding a change to a changegroup | |
| 13382 | +** | |
| 13383 | +** This API is used, in concert with other sqlite3changegroup_change_xxx() | |
| 13384 | +** APIs, to add changes to a changegroup object one at a time. To add a | |
| 13385 | +** single change, the caller must: | |
| 13386 | +** | |
| 13387 | +** 1. Invoke sqlite3changegroup_change_begin() to indicate the type of | |
| 13388 | +** change (INSERT, UPDATE or DELETE), the affected table and whether | |
| 13389 | +** or not the change should be marked as indirect. | |
| 13390 | +** | |
| 13391 | +** 2. Invoke sqlite3changegroup_change_int64() or one of the other four | |
| 13392 | +** value functions - _null(), _double(), _text() or _blob() - one or | |
| 13393 | +** more times to specify old.* and new.* values for the change being | |
| 13394 | +** constructed. | |
| 13395 | +** | |
| 13396 | +** 3. Invoke sqlite3changegroup_change_finish() to either finish adding | |
| 13397 | +** the change to the group, or to discard the change altogether. | |
| 13398 | +** | |
| 13399 | +** The first argument to this function must be a pointer to the existing | |
| 13400 | +** changegroup object that the change will be added to. The second argument | |
| 13401 | +** must be SQLITE_INSERT, SQLITE_UPDATE or SQLITE_DELETE. The third is the | |
| 13402 | +** name of the table that the change affects, and the fourth is a boolean | |
| 13403 | +** flag specifying whether the change should be marked as "indirect" (if | |
| 13404 | +** bIndirect is non-zero) or not indirect (if bIndirect is zero). | |
| 13405 | +** | |
| 13406 | +** Following a successful call to this function, this function may not be | |
| 13407 | +** called again on the same changegroup object until after | |
| 13408 | +** sqlite3changegroup_change_finish() has been called. Doing so is an | |
| 13409 | +** SQLITE_MISUSE error. | |
| 13410 | +** | |
| 13411 | +** The changegroup object passed as the first argument must be already | |
| 13412 | +** configured with schema data for the specified table. It may be configured | |
| 13413 | +** either by calling sqlite3changegroup_schema() with a database that contains | |
| 13414 | +** the table, or sqlite3changegroup_add() with a changeset that contains the | |
| 13415 | +** table. If the changegroup object has not been configured with a schema for | |
| 13416 | +** the specified table when this function is called, SQLITE_ERROR is returned. | |
| 13417 | +** | |
| 13418 | +** If successful, SQLITE_OK is returned. Otherwise, if an error occurs, an | |
| 13419 | +** SQLite error code is returned. In this case, if argument pzErr is non-NULL, | |
| 13420 | +** then (*pzErr) may be set to point to a buffer containing a utf-8 formated, | |
| 13421 | +** nul-terminated, English language error message. It is the responsibility | |
| 13422 | +** of the caller to eventually free this buffer using sqlite3_free(). | |
| 13423 | +*/ | |
| 13424 | +SQLITE_API int sqlite3changegroup_change_begin( | |
| 13425 | + sqlite3_changegroup*, | |
| 13426 | + int eOp, | |
| 13427 | + const char *zTab, | |
| 13428 | + int bIndirect, | |
| 13429 | + char **pzErr | |
| 13430 | +); | |
| 13431 | + | |
| 13432 | +/* | |
| 13433 | +** CAPI3REF: Add a 64-bit integer to a changegroup | |
| 13434 | +** | |
| 13435 | +** This function may only be called between a successful call to | |
| 13436 | +** sqlite3changegroup_change_begin() and its matching | |
| 13437 | +** sqlite3changegroup_change_finish() call. If it is called at any | |
| 13438 | +** other time, it is an SQLITE_MISUSE error. Calling this function | |
| 13439 | +** specifies a 64-bit integer value to be used in the change currently being | |
| 13440 | +** added to the changegroup object passed as the first argument. | |
| 13441 | +** | |
| 13442 | +** The second parameter, bNew, specifies whether the value is to be part of | |
| 13443 | +** the new.* (if bNew is non-zero) or old.* (if bNew is zero) record of | |
| 13444 | +** the change under construction. If this does not match the type of change | |
| 13445 | +** specified by the preceding call to sqlite3changegroup_change_begin() (i.e. | |
| 13446 | +** an old.* value for an SQLITE_INSERT change, or a new.* value for an | |
| 13447 | +** SQLITE_DELETE), then SQLITE_ERROR is returned. | |
| 13448 | +** | |
| 13449 | +** The third parameter specifies the column of the old.* or new.* record that | |
| 13450 | +** the value will be a part of. If the specified table has an explicit primary | |
| 13451 | +** key, then this is the index of the table column, numbered from 0 in the order | |
| 13452 | +** specified within the CREATE TABLE statement. Or, if the table uses an | |
| 13453 | +** implicit rowid key, then the column 0 is the rowid and the explicit columns | |
| 13454 | +** are numbered starting from 1. If the iCol parameter is less than 0 or greater | |
| 13455 | +** than the index of the last column in the table, SQLITE_RANGE is returned. | |
| 13456 | +** | |
| 13457 | +** The fourth parameter is the integer value to use as part of the old.* or | |
| 13458 | +** new.* record. | |
| 13459 | +** | |
| 13460 | +** If this call is successful, SQLITE_OK is returned. Otherwise, if an | |
| 13461 | +** error occurs, an SQLite error code is returned. | |
| 13462 | +*/ | |
| 13463 | +SQLITE_API int sqlite3changegroup_change_int64( | |
| 13464 | + sqlite3_changegroup*, | |
| 13465 | + int bNew, | |
| 13466 | + int iCol, | |
| 13467 | + sqlite3_int64 iVal | |
| 13468 | +); | |
| 13469 | + | |
| 13470 | +/* | |
| 13471 | +** CAPI3REF: Add a NULL to a changegroup | |
| 13472 | +** | |
| 13473 | +** This function is similar to sqlite3changegroup_change_int64(). Except that | |
| 13474 | +** it configures the change currently under construction with a NULL value | |
| 13475 | +** instead of a 64-bit integer. | |
| 13476 | +*/ | |
| 13477 | +SQLITE_API int sqlite3changegroup_change_null(sqlite3_changegroup*, int, int); | |
| 13478 | + | |
| 13479 | +/* | |
| 13480 | +** CAPI3REF: Add an double to a changegroup | |
| 13481 | +** | |
| 13482 | +** This function is similar to sqlite3changegroup_change_int64(). Except that | |
| 13483 | +** it configures the change currently being constructed with a real value | |
| 13484 | +** instead of a 64-bit integer. | |
| 13485 | +*/ | |
| 13486 | +SQLITE_API int sqlite3changegroup_change_double(sqlite3_changegroup*, int, int, double); | |
| 13487 | + | |
| 13488 | +/* | |
| 13489 | +** CAPI3REF: Add a text value to a changegroup | |
| 13490 | +** | |
| 13491 | +** This function is similar to sqlite3changegroup_change_int64(). It configures | |
| 13492 | +** the currently accumulated change with a text value instead of a 64-bit | |
| 13493 | +** integer. Parameter pVal points to a buffer containing the text encoded using | |
| 13494 | +** utf-8. Parameter nVal may either be the size of the text value in bytes, or | |
| 13495 | +** else a negative value, in which case the buffer pVal points to is assumed to | |
| 13496 | +** be nul-terminated. | |
| 13497 | +*/ | |
| 13498 | +SQLITE_API int sqlite3changegroup_change_text( | |
| 13499 | + sqlite3_changegroup*, int, int, const char *pVal, int nVal | |
| 13500 | +); | |
| 13501 | + | |
| 13502 | +/* | |
| 13503 | +** CAPI3REF: Add a blob to a changegroup | |
| 13504 | +** | |
| 13505 | +** This function is similar to sqlite3changegroup_change_int64(). It configures | |
| 13506 | +** the currently accumulated change with a blob value instead of a 64-bit | |
| 13507 | +** integer. Parameter pVal points to a buffer containing the blob. Parameter | |
| 13508 | +** nVal is the size of the blob in bytes. | |
| 13509 | +*/ | |
| 13510 | +SQLITE_API int sqlite3changegroup_change_blob( | |
| 13511 | + sqlite3_changegroup*, int, int, const void *pVal, int nVal | |
| 13512 | +); | |
| 13513 | + | |
| 13514 | +/* | |
| 13515 | +** CAPI3REF: Finish adding one-at-at-time changes to a changegroup | |
| 13516 | +** | |
| 13517 | +** This function may only be called following a successful call to | |
| 13518 | +** sqlite3changegroup_change_begin(). Otherwise, it is an SQLITE_MISUSE error. | |
| 13519 | +** | |
| 13520 | +** If parameter bDiscard is non-zero, then the current change is simply | |
| 13521 | +** discarded. In this case this function is always successful and SQLITE_OK | |
| 13522 | +** returned. | |
| 13523 | +** | |
| 13524 | +** If parameter bDiscard is zero, then an attempt is made to add the current | |
| 13525 | +** change to the changegroup. Assuming the changegroup is configured to | |
| 13526 | +** produce a changeset (not a patchset), this requires that: | |
| 13527 | +** | |
| 13528 | +** * If the change is an INSERT or DELETE, then a value must be specified | |
| 13529 | +** for all columns of the new.* or old.* record, respectively. | |
| 13530 | +** | |
| 13531 | +** * If the change is an UPDATE record, then values must be provided for | |
| 13532 | +** the PRIMARY KEY columns of the old.* record, but must not be provided | |
| 13533 | +** for PRIMARY KEY columns of the new.* record. | |
| 13534 | +** | |
| 13535 | +** * If the change is an UPDATE record, then for each non-PRIMARY KEY | |
| 13536 | +** column in the old.* record for which a value has been provided, a | |
| 13537 | +** value must also be provided for the same column in the new.* record. | |
| 13538 | +** Similarly, for each non-PK column in the old.* record for which | |
| 13539 | +** a value is not provided, a value must not be provided for the same | |
| 13540 | +** column in the new.* record. | |
| 13541 | +** | |
| 13542 | +** * All values specified for PRIMARY KEY columns must be non-NULL. | |
| 13543 | +** | |
| 13544 | +** Otherwise, it is an error. | |
| 13545 | +** | |
| 13546 | +** If the changegroup already contains a change for the same row (identified | |
| 13547 | +** by PRIMARY KEY columns), then the current change is combined with the | |
| 13548 | +** existing change in the same way as for sqlite3changegroup_add(). | |
| 13549 | +** | |
| 13550 | +** For a patchset, all of the above rules apply except that it doesn't matter | |
| 13551 | +** whether or not values are provided for the non-PK old.* record columns | |
| 13552 | +** for an UPDATE or DELETE change. This means that code used to produce | |
| 13553 | +** a changeset using the sqlite3changegroup_change_xxx() APIs may also | |
| 13554 | +** be used to produce patchsets. | |
| 13555 | +** | |
| 13556 | +** If the call is successful, SQLITE_OK is returned. Otherwise, if an error | |
| 13557 | +** occurs, an SQLite error code is returned. If an error is returned and | |
| 13558 | +** parameter pzErr is not NULL, then (*pzErr) may be set to point to a buffer | |
| 13559 | +** containing a nul-terminated, utf-8 encoded, English language error message. | |
| 13560 | +** It is the responsibility of the caller to eventually free any such error | |
| 13561 | +** message buffer using sqlite3_free(). | |
| 13562 | +*/ | |
| 13563 | +SQLITE_API int sqlite3changegroup_change_finish( | |
| 13564 | + sqlite3_changegroup*, | |
| 13565 | + int bDiscard, | |
| 13566 | + char **pzErr | |
| 13567 | +); | |
| 13332 | 13568 | |
| 13333 | 13569 | /* |
| 13334 | 13570 | ** Make sure we can call this stuff from C++. |
| 13335 | 13571 | */ |
| 13336 | 13572 | #ifdef __cplusplus |
| 13337 | 13573 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -146,14 +146,14 @@ | |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.53.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3053000 |
| 151 | #define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c" |
| 152 | #define SQLITE_SCM_BRANCH "trunk" |
| 153 | #define SQLITE_SCM_TAGS "" |
| 154 | #define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z" |
| 155 | |
| 156 | /* |
| 157 | ** CAPI3REF: Run-Time Library Version Numbers |
| 158 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 159 | ** |
| @@ -576,11 +576,11 @@ | |
| 576 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 577 | #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) |
| 578 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 579 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 580 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 581 | #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ |
| 582 | |
| 583 | /* |
| 584 | ** CAPI3REF: Flags For File Open Operations |
| 585 | ** |
| 586 | ** These bit values are intended for use in the |
| @@ -1288,10 +1288,16 @@ | |
| 1288 | /* deprecated names */ |
| 1289 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1290 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1291 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| 1292 | |
| 1293 | |
| 1294 | /* |
| 1295 | ** CAPI3REF: Mutex Handle |
| 1296 | ** |
| 1297 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -1709,11 +1715,12 @@ | |
| 1709 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1710 | ** The exceptional configuration options that may be invoked at any time |
| 1711 | ** are called "anytime configuration options". |
| 1712 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1713 | ** [sqlite3_shutdown()] with a first argument that is not an anytime |
| 1714 | ** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE. |
| 1715 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1716 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1717 | ** |
| 1718 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1719 | ** ^If the option is unknown or SQLite is unable to set the option |
| @@ -2275,13 +2282,14 @@ | |
| 2275 | ** <li><P>The second argument ("sz") is the |
| 2276 | ** size of each lookaside buffer slot. Lookaside is disabled if "sz" |
| 2277 | ** is less than 8. The "sz" argument should be a multiple of 8 less than |
| 2278 | ** 65536. If "sz" does not meet this constraint, it is reduced in size until |
| 2279 | ** it does. |
| 2280 | ** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled |
| 2281 | ** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so |
| 2282 | ** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" |
| 2283 | ** parameter is usually chosen so that the product of "sz" and "cnt" is less |
| 2284 | ** than 1,000,000. |
| 2285 | ** </ol> |
| 2286 | ** <p>If the "buf" argument is not NULL, then it must |
| 2287 | ** point to a memory buffer with a size that is greater than |
| @@ -2656,11 +2664,11 @@ | |
| 2656 | ** default value 17, as of SQLite version 3.52.0. The value was 15 in all |
| 2657 | ** prior versions.<p> |
| 2658 | ** This option takes two arguments which are an integer and a pointer |
| 2659 | ** to an integer. The first argument is a small integer, between 3 and 23, or |
| 2660 | ** zero. The FP_DIGITS setting is changed to that small integer, or left |
| 2661 | ** unaltered if the first argument is zero or out of range. The second argument |
| 2662 | ** is a pointer to an integer. If the pointer is not NULL, then the value of |
| 2663 | ** the FP_DIGITS setting, after possibly being modified by the first |
| 2664 | ** arguments, is written into the integer to which the second argument points. |
| 2665 | ** </dd> |
| 2666 | ** |
| @@ -2668,14 +2676,16 @@ | |
| 2668 | ** |
| 2669 | ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3> |
| 2670 | ** |
| 2671 | ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the |
| 2672 | ** overall call to [sqlite3_db_config()] has a total of four parameters. |
| 2673 | ** The first argument (the third parameter to sqlite3_db_config()) is an integer. |
| 2674 | ** The second argument is a pointer to an integer. If the first argument is 1, |
| 2675 | ** then the option becomes enabled. If the first integer argument is 0, then the |
| 2676 | ** option is disabled. If the first argument is -1, then the option setting |
| 2677 | ** is unchanged. The second argument, the pointer to an integer, may be NULL. |
| 2678 | ** If the second argument is not NULL, then a value of 0 or 1 is written into |
| 2679 | ** the integer to which the second argument points, depending on whether the |
| 2680 | ** setting is disabled or enabled after applying any changes specified by |
| 2681 | ** the first argument. |
| @@ -5848,12 +5858,13 @@ | |
| 5848 | ** that the application-defined collating sequence created expects its |
| 5849 | ** input strings to be in UTF16 in native byte order, and that the start |
| 5850 | ** of the strings must be aligned to a 2-byte boundary. |
| 5851 | ** |
| 5852 | ** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be |
| 5853 | ** used to specify the text encoding to strings input to [sqlite3_result_text64()] |
| 5854 | ** and [sqlite3_bind_text64()]. It means that the input string (call it "z") |
| 5855 | ** is UTF-8 encoded and that it is zero-terminated. If the length parameter |
| 5856 | ** (call it "n") is non-negative, this encoding option means that the caller |
| 5857 | ** guarantees that z array contains at least n+1 bytes and that the z[n] |
| 5858 | ** byte has a value of zero. |
| 5859 | ** This option gives the same output as SQLITE_UTF8, but can be more efficient |
| @@ -6101,30 +6112,26 @@ | |
| 6101 | ** |
| 6102 | ** These routines must be called from the same thread as |
| 6103 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 6104 | ** |
| 6105 | ** As long as the input parameter is correct, these routines can only |
| 6106 | ** fail if an out-of-memory error occurs during a format conversion. |
| 6107 | ** Only the following subset of interfaces are subject to out-of-memory |
| 6108 | ** errors: |
| 6109 | ** |
| 6110 | ** <ul> |
| 6111 | ** <li> sqlite3_value_blob() |
| 6112 | ** <li> sqlite3_value_text() |
| 6113 | ** <li> sqlite3_value_text16() |
| 6114 | ** <li> sqlite3_value_text16le() |
| 6115 | ** <li> sqlite3_value_text16be() |
| 6116 | ** <li> sqlite3_value_bytes() |
| 6117 | ** <li> sqlite3_value_bytes16() |
| 6118 | ** </ul> |
| 6119 | ** |
| 6120 | ** If an out-of-memory error occurs, then the return value from these |
| 6121 | ** routines is the same as if the column had contained an SQL NULL value. |
| 6122 | ** Valid SQL NULL returns can be distinguished from out-of-memory errors |
| 6123 | ** by invoking the [sqlite3_errcode()] immediately after the suspect |
| 6124 | ** return value is obtained and before any |
| 6125 | ** other SQLite interface is called on the same [database connection]. |
| 6126 | */ |
| 6127 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 6128 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 6129 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 6130 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| @@ -6147,11 +6154,12 @@ | |
| 6147 | ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
| 6148 | ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding |
| 6149 | ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
| 6150 | ** returns something other than SQLITE_TEXT, then the return value from |
| 6151 | ** sqlite3_value_encoding(X) is meaningless. ^Calls to |
| 6152 | ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)], |
| 6153 | ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or |
| 6154 | ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and |
| 6155 | ** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
| 6156 | ** |
| 6157 | ** This routine is intended for used by applications that test and validate |
| @@ -6278,21 +6286,21 @@ | |
| 6278 | ** associate auxiliary data with argument values. If the same argument |
| 6279 | ** value is passed to multiple invocations of the same SQL function during |
| 6280 | ** query execution, under some circumstances the associated auxiliary data |
| 6281 | ** might be preserved. An example of where this might be useful is in a |
| 6282 | ** regular-expression matching function. The compiled version of the regular |
| 6283 | ** expression can be stored as auxiliary data associated with the pattern string. |
| 6284 | ** Then as long as the pattern string remains the same, |
| 6285 | ** the compiled regular expression can be reused on multiple |
| 6286 | ** invocations of the same function. |
| 6287 | ** |
| 6288 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data |
| 6289 | ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument |
| 6290 | ** value to the application-defined function. ^N is zero for the left-most |
| 6291 | ** function argument. ^If there is no auxiliary data |
| 6292 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface |
| 6293 | ** returns a NULL pointer. |
| 6294 | ** |
| 6295 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the |
| 6296 | ** N-th argument of the application-defined function. ^Subsequent |
| 6297 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| 6298 | ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or |
| @@ -10401,21 +10409,22 @@ | |
| 10401 | ** |
| 10402 | ** <table border=1 cellspacing=0 cellpadding=10 width="90%"> |
| 10403 | ** <tr> |
| 10404 | ** <td valign="top">sqlite3_vtab_distinct() return value |
| 10405 | ** <td valign="top">Rows are returned in aOrderBy order |
| 10406 | ** <td valign="top">Rows with the same value in all aOrderBy columns are adjacent |
| 10407 | ** <td valign="top">Duplicates over all colUsed columns may be omitted |
| 10408 | ** <tr><td>0<td>yes<td>yes<td>no |
| 10409 | ** <tr><td>1<td>no<td>yes<td>no |
| 10410 | ** <tr><td>2<td>no<td>yes<td>yes |
| 10411 | ** <tr><td>3<td>yes<td>yes<td>yes |
| 10412 | ** </table> |
| 10413 | ** |
| 10414 | ** ^For the purposes of comparing virtual table output values to see if the |
| 10415 | ** values are the same value for sorting purposes, two NULL values are considered |
| 10416 | ** to be the same. In other words, the comparison operator is "IS" |
| 10417 | ** (or "IS NOT DISTINCT FROM") and not "==". |
| 10418 | ** |
| 10419 | ** If a virtual table implementation is unable to meet the requirements |
| 10420 | ** specified above, then it must not set the "orderByConsumed" flag in the |
| 10421 | ** [sqlite3_index_info] object or an incorrect answer may result. |
| @@ -11265,16 +11274,17 @@ | |
| 11265 | /* |
| 11266 | ** CAPI3REF: Bind array values to the CARRAY table-valued function |
| 11267 | ** |
| 11268 | ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to |
| 11269 | ** parameter that is the first argument of the [carray() table-valued function]. |
| 11270 | ** The S parameter is a pointer to the [prepared statement] that uses the carray() |
| 11271 | ** functions. I is the parameter index to be bound. I must be the index of the |
| 11272 | ** parameter that is the first argument to the carray() table-valued function. |
| 11273 | ** P is a pointer to the array to be bound, and N is the number of elements in |
| 11274 | ** the array. The F argument is one of constants [SQLITE_CARRAY_INT32], |
| 11275 | ** [SQLITE_CARRAY_INT64], [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], |
| 11276 | ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P. |
| 11277 | ** |
| 11278 | ** If the X argument is not a NULL pointer or one of the special |
| 11279 | ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke |
| 11280 | ** the function X with argument D when it is finished using the data in P. |
| @@ -13327,10 +13337,236 @@ | |
| 13327 | |
| 13328 | /* |
| 13329 | ** CAPI3REF: Values for sqlite3session_config(). |
| 13330 | */ |
| 13331 | #define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 13332 | |
| 13333 | /* |
| 13334 | ** Make sure we can call this stuff from C++. |
| 13335 | */ |
| 13336 | #ifdef __cplusplus |
| 13337 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -146,14 +146,14 @@ | |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.53.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3053000 |
| 151 | #define SQLITE_SOURCE_ID "2026-04-01 11:54:20 7bc1d0c4572f126cfe68fa51fe992d2bd46b1e57c04721991bd5fad36dd795c5" |
| 152 | #define SQLITE_SCM_BRANCH "trunk" |
| 153 | #define SQLITE_SCM_TAGS "" |
| 154 | #define SQLITE_SCM_DATETIME "2026-04-01T11:54:20.065Z" |
| 155 | |
| 156 | /* |
| 157 | ** CAPI3REF: Run-Time Library Version Numbers |
| 158 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 159 | ** |
| @@ -576,11 +576,11 @@ | |
| 576 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 577 | #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) |
| 578 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 579 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 580 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 581 | #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal only */ |
| 582 | |
| 583 | /* |
| 584 | ** CAPI3REF: Flags For File Open Operations |
| 585 | ** |
| 586 | ** These bit values are intended for use in the |
| @@ -1288,10 +1288,16 @@ | |
| 1288 | /* deprecated names */ |
| 1289 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1290 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1291 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| 1292 | |
| 1293 | /* reserved file-control numbers: |
| 1294 | ** 101 |
| 1295 | ** 102 |
| 1296 | ** 103 |
| 1297 | */ |
| 1298 | |
| 1299 | |
| 1300 | /* |
| 1301 | ** CAPI3REF: Mutex Handle |
| 1302 | ** |
| 1303 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -1709,11 +1715,12 @@ | |
| 1715 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1716 | ** The exceptional configuration options that may be invoked at any time |
| 1717 | ** are called "anytime configuration options". |
| 1718 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1719 | ** [sqlite3_shutdown()] with a first argument that is not an anytime |
| 1720 | ** configuration option, then the sqlite3_config() call will |
| 1721 | ** return SQLITE_MISUSE. |
| 1722 | ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1723 | ** implementation of an application-defined [sqlite3_os_init()]. |
| 1724 | ** |
| 1725 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1726 | ** ^If the option is unknown or SQLite is unable to set the option |
| @@ -2275,13 +2282,14 @@ | |
| 2282 | ** <li><P>The second argument ("sz") is the |
| 2283 | ** size of each lookaside buffer slot. Lookaside is disabled if "sz" |
| 2284 | ** is less than 8. The "sz" argument should be a multiple of 8 less than |
| 2285 | ** 65536. If "sz" does not meet this constraint, it is reduced in size until |
| 2286 | ** it does. |
| 2287 | ** <li><p>The third argument ("cnt") is the number of slots. |
| 2288 | ** Lookaside is disabled if "cnt"is less than 1. |
| 2289 | * The "cnt" value will be reduced, if necessary, so |
| 2290 | ** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" |
| 2291 | ** parameter is usually chosen so that the product of "sz" and "cnt" is less |
| 2292 | ** than 1,000,000. |
| 2293 | ** </ol> |
| 2294 | ** <p>If the "buf" argument is not NULL, then it must |
| 2295 | ** point to a memory buffer with a size that is greater than |
| @@ -2656,11 +2664,11 @@ | |
| 2664 | ** default value 17, as of SQLite version 3.52.0. The value was 15 in all |
| 2665 | ** prior versions.<p> |
| 2666 | ** This option takes two arguments which are an integer and a pointer |
| 2667 | ** to an integer. The first argument is a small integer, between 3 and 23, or |
| 2668 | ** zero. The FP_DIGITS setting is changed to that small integer, or left |
| 2669 | ** unaltered if the first argument is zero or out of range. The second argument |
| 2670 | ** is a pointer to an integer. If the pointer is not NULL, then the value of |
| 2671 | ** the FP_DIGITS setting, after possibly being modified by the first |
| 2672 | ** arguments, is written into the integer to which the second argument points. |
| 2673 | ** </dd> |
| 2674 | ** |
| @@ -2668,14 +2676,16 @@ | |
| 2676 | ** |
| 2677 | ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3> |
| 2678 | ** |
| 2679 | ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the |
| 2680 | ** overall call to [sqlite3_db_config()] has a total of four parameters. |
| 2681 | ** The first argument (the third parameter to sqlite3_db_config()) is |
| 2682 | ** an integer. |
| 2683 | ** The second argument is a pointer to an integer. If the first argument is 1, |
| 2684 | ** then the option becomes enabled. If the first integer argument is 0, |
| 2685 | ** then the option is disabled. |
| 2686 | ** If the first argument is -1, then the option setting |
| 2687 | ** is unchanged. The second argument, the pointer to an integer, may be NULL. |
| 2688 | ** If the second argument is not NULL, then a value of 0 or 1 is written into |
| 2689 | ** the integer to which the second argument points, depending on whether the |
| 2690 | ** setting is disabled or enabled after applying any changes specified by |
| 2691 | ** the first argument. |
| @@ -5848,12 +5858,13 @@ | |
| 5858 | ** that the application-defined collating sequence created expects its |
| 5859 | ** input strings to be in UTF16 in native byte order, and that the start |
| 5860 | ** of the strings must be aligned to a 2-byte boundary. |
| 5861 | ** |
| 5862 | ** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be |
| 5863 | ** used to specify the text encoding to strings input to |
| 5864 | ** [sqlite3_result_text64()] and [sqlite3_bind_text64()]. |
| 5865 | ** The SQLITE_UTF8_ZT encoding means that the input string (call it "z") |
| 5866 | ** is UTF-8 encoded and that it is zero-terminated. If the length parameter |
| 5867 | ** (call it "n") is non-negative, this encoding option means that the caller |
| 5868 | ** guarantees that z array contains at least n+1 bytes and that the z[n] |
| 5869 | ** byte has a value of zero. |
| 5870 | ** This option gives the same output as SQLITE_UTF8, but can be more efficient |
| @@ -6101,30 +6112,26 @@ | |
| 6112 | ** |
| 6113 | ** These routines must be called from the same thread as |
| 6114 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 6115 | ** |
| 6116 | ** As long as the input parameter is correct, these routines can only |
| 6117 | ** fail if an out-of-memory error occurs while trying to do a |
| 6118 | ** UTF8→UTF16 or UTF16→UTF8 conversion. |
| 6119 | ** If an out-of-memory error occurs, then the return value from these |
| 6120 | ** routines is the same as if the column had contained an SQL NULL value. |
| 6121 | ** If the input sqlite3_value was not obtained from [sqlite3_value_dup()], |
| 6122 | ** then valid SQL NULL returns can also be distinguished from |
| 6123 | ** out-of-memory errors after extracting the value |
| 6124 | ** by invoking the [sqlite3_errcode()] immediately after the suspicious |
| 6125 | ** return value is obtained and before any |
| 6126 | ** other SQLite interface is called on the same [database connection]. |
| 6127 | ** If the input sqlite3_value was obtained from sqlite3_value_dup() then |
| 6128 | ** it is disconnected from the database connection and so sqlite3_errcode() |
| 6129 | ** will not work. |
| 6130 | ** In that case, the only way to distinguish an out-of-memory |
| 6131 | ** condition from a true SQL NULL is to invoke sqlite3_value_type() on the |
| 6132 | ** input to see if it is NULL prior to trying to extract the value. |
| 6133 | */ |
| 6134 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 6135 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 6136 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 6137 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| @@ -6147,11 +6154,12 @@ | |
| 6154 | ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
| 6155 | ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding |
| 6156 | ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
| 6157 | ** returns something other than SQLITE_TEXT, then the return value from |
| 6158 | ** sqlite3_value_encoding(X) is meaningless. ^Calls to |
| 6159 | ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], |
| 6160 | ** [sqlite3_value_text16be(X)], |
| 6161 | ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or |
| 6162 | ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and |
| 6163 | ** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
| 6164 | ** |
| 6165 | ** This routine is intended for used by applications that test and validate |
| @@ -6278,21 +6286,21 @@ | |
| 6286 | ** associate auxiliary data with argument values. If the same argument |
| 6287 | ** value is passed to multiple invocations of the same SQL function during |
| 6288 | ** query execution, under some circumstances the associated auxiliary data |
| 6289 | ** might be preserved. An example of where this might be useful is in a |
| 6290 | ** regular-expression matching function. The compiled version of the regular |
| 6291 | ** expression can be stored as auxiliary data associated with the pattern |
| 6292 | ** string. Then as long as the pattern string remains the same, |
| 6293 | ** the compiled regular expression can be reused on multiple |
| 6294 | ** invocations of the same function. |
| 6295 | ** |
| 6296 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary |
| 6297 | ** data associated by the sqlite3_set_auxdata(C,N,P,X) function with the |
| 6298 | ** Nth argument value to the application-defined function. ^N is zero |
| 6299 | ** for the left-most function argument. ^If there is no auxiliary data |
| 6300 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) |
| 6301 | ** interface returns a NULL pointer. |
| 6302 | ** |
| 6303 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the |
| 6304 | ** N-th argument of the application-defined function. ^Subsequent |
| 6305 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| 6306 | ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or |
| @@ -10401,21 +10409,22 @@ | |
| 10409 | ** |
| 10410 | ** <table border=1 cellspacing=0 cellpadding=10 width="90%"> |
| 10411 | ** <tr> |
| 10412 | ** <td valign="top">sqlite3_vtab_distinct() return value |
| 10413 | ** <td valign="top">Rows are returned in aOrderBy order |
| 10414 | ** <td valign="top">Rows with the same value in all aOrderBy columns are |
| 10415 | ** adjacent |
| 10416 | ** <td valign="top">Duplicates over all colUsed columns may be omitted |
| 10417 | ** <tr><td>0<td>yes<td>yes<td>no |
| 10418 | ** <tr><td>1<td>no<td>yes<td>no |
| 10419 | ** <tr><td>2<td>no<td>yes<td>yes |
| 10420 | ** <tr><td>3<td>yes<td>yes<td>yes |
| 10421 | ** </table> |
| 10422 | ** |
| 10423 | ** ^For the purposes of comparing virtual table output values to see if the |
| 10424 | ** values are the same value for sorting purposes, two NULL values are |
| 10425 | ** considered to be the same. In other words, the comparison operator is "IS" |
| 10426 | ** (or "IS NOT DISTINCT FROM") and not "==". |
| 10427 | ** |
| 10428 | ** If a virtual table implementation is unable to meet the requirements |
| 10429 | ** specified above, then it must not set the "orderByConsumed" flag in the |
| 10430 | ** [sqlite3_index_info] object or an incorrect answer may result. |
| @@ -11265,16 +11274,17 @@ | |
| 11274 | /* |
| 11275 | ** CAPI3REF: Bind array values to the CARRAY table-valued function |
| 11276 | ** |
| 11277 | ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to |
| 11278 | ** parameter that is the first argument of the [carray() table-valued function]. |
| 11279 | ** The S parameter is a pointer to the [prepared statement] that uses the |
| 11280 | ** carray() functions. I is the parameter index to be bound. I must be the |
| 11281 | ** index of the parameter that is the first argument to the carray() |
| 11282 | ** table-valued function. P is a pointer to the array to be bound, and N |
| 11283 | ** is the number of elements in the array. The F argument is one of |
| 11284 | ** constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64], |
| 11285 | ** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], |
| 11286 | ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P. |
| 11287 | ** |
| 11288 | ** If the X argument is not a NULL pointer or one of the special |
| 11289 | ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke |
| 11290 | ** the function X with argument D when it is finished using the data in P. |
| @@ -13327,10 +13337,236 @@ | |
| 13337 | |
| 13338 | /* |
| 13339 | ** CAPI3REF: Values for sqlite3session_config(). |
| 13340 | */ |
| 13341 | #define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 13342 | |
| 13343 | /* |
| 13344 | ** CAPI3REF: Configure a changegroup object |
| 13345 | ** |
| 13346 | ** Configure the changegroup object passed as the first argument. |
| 13347 | ** At present the only valid value for the second parameter is |
| 13348 | ** [SQLITE_CHANGEGROUP_CONFIG_PATCHSET]. |
| 13349 | */ |
| 13350 | SQLITE_API int sqlite3changegroup_config(sqlite3_changegroup*, int, void *pArg); |
| 13351 | |
| 13352 | /* |
| 13353 | ** CAPI3REF: Options for sqlite3changegroup_config(). |
| 13354 | ** |
| 13355 | ** The following values may be passed as the 2nd parameter to |
| 13356 | ** sqlite3changegroup_config(). |
| 13357 | ** |
| 13358 | ** <dt>SQLITE_CHANGEGROUP_CONFIG_PATCHSET <dd> |
| 13359 | ** A changegroup object generates either a changeset or patchset. Usually, |
| 13360 | ** this is determined by whether the first call to sqlite3changegroup_add() |
| 13361 | ** is passed a changeset or a patchset. Or, if the first changes are added |
| 13362 | ** to the changegroup object using the sqlite3changegroup_change_xxx() |
| 13363 | ** APIs, then this option may be used to configure whether the changegroup |
| 13364 | ** object generates a changeset or patchset. |
| 13365 | ** |
| 13366 | ** When this option is invoked, parameter pArg must point to a value of |
| 13367 | ** type int. If the changegroup currently contains zero changes, and the |
| 13368 | ** value of the int variable is zero or greater than zero, then the |
| 13369 | ** changegroup is configured to generate a changeset or patchset, |
| 13370 | ** respectively. It is a no-op, not an error, if the changegroup is not |
| 13371 | ** configured because it has already started accumulating changes. |
| 13372 | ** |
| 13373 | ** Before returning, the int variable is set to 0 if the changegroup is |
| 13374 | ** configured to generate a changeset, or 1 if it is configured to generate |
| 13375 | ** a patchset. |
| 13376 | */ |
| 13377 | #define SQLITE_CHANGEGROUP_CONFIG_PATCHSET 1 |
| 13378 | |
| 13379 | |
| 13380 | /* |
| 13381 | ** CAPI3REF: Begin adding a change to a changegroup |
| 13382 | ** |
| 13383 | ** This API is used, in concert with other sqlite3changegroup_change_xxx() |
| 13384 | ** APIs, to add changes to a changegroup object one at a time. To add a |
| 13385 | ** single change, the caller must: |
| 13386 | ** |
| 13387 | ** 1. Invoke sqlite3changegroup_change_begin() to indicate the type of |
| 13388 | ** change (INSERT, UPDATE or DELETE), the affected table and whether |
| 13389 | ** or not the change should be marked as indirect. |
| 13390 | ** |
| 13391 | ** 2. Invoke sqlite3changegroup_change_int64() or one of the other four |
| 13392 | ** value functions - _null(), _double(), _text() or _blob() - one or |
| 13393 | ** more times to specify old.* and new.* values for the change being |
| 13394 | ** constructed. |
| 13395 | ** |
| 13396 | ** 3. Invoke sqlite3changegroup_change_finish() to either finish adding |
| 13397 | ** the change to the group, or to discard the change altogether. |
| 13398 | ** |
| 13399 | ** The first argument to this function must be a pointer to the existing |
| 13400 | ** changegroup object that the change will be added to. The second argument |
| 13401 | ** must be SQLITE_INSERT, SQLITE_UPDATE or SQLITE_DELETE. The third is the |
| 13402 | ** name of the table that the change affects, and the fourth is a boolean |
| 13403 | ** flag specifying whether the change should be marked as "indirect" (if |
| 13404 | ** bIndirect is non-zero) or not indirect (if bIndirect is zero). |
| 13405 | ** |
| 13406 | ** Following a successful call to this function, this function may not be |
| 13407 | ** called again on the same changegroup object until after |
| 13408 | ** sqlite3changegroup_change_finish() has been called. Doing so is an |
| 13409 | ** SQLITE_MISUSE error. |
| 13410 | ** |
| 13411 | ** The changegroup object passed as the first argument must be already |
| 13412 | ** configured with schema data for the specified table. It may be configured |
| 13413 | ** either by calling sqlite3changegroup_schema() with a database that contains |
| 13414 | ** the table, or sqlite3changegroup_add() with a changeset that contains the |
| 13415 | ** table. If the changegroup object has not been configured with a schema for |
| 13416 | ** the specified table when this function is called, SQLITE_ERROR is returned. |
| 13417 | ** |
| 13418 | ** If successful, SQLITE_OK is returned. Otherwise, if an error occurs, an |
| 13419 | ** SQLite error code is returned. In this case, if argument pzErr is non-NULL, |
| 13420 | ** then (*pzErr) may be set to point to a buffer containing a utf-8 formated, |
| 13421 | ** nul-terminated, English language error message. It is the responsibility |
| 13422 | ** of the caller to eventually free this buffer using sqlite3_free(). |
| 13423 | */ |
| 13424 | SQLITE_API int sqlite3changegroup_change_begin( |
| 13425 | sqlite3_changegroup*, |
| 13426 | int eOp, |
| 13427 | const char *zTab, |
| 13428 | int bIndirect, |
| 13429 | char **pzErr |
| 13430 | ); |
| 13431 | |
| 13432 | /* |
| 13433 | ** CAPI3REF: Add a 64-bit integer to a changegroup |
| 13434 | ** |
| 13435 | ** This function may only be called between a successful call to |
| 13436 | ** sqlite3changegroup_change_begin() and its matching |
| 13437 | ** sqlite3changegroup_change_finish() call. If it is called at any |
| 13438 | ** other time, it is an SQLITE_MISUSE error. Calling this function |
| 13439 | ** specifies a 64-bit integer value to be used in the change currently being |
| 13440 | ** added to the changegroup object passed as the first argument. |
| 13441 | ** |
| 13442 | ** The second parameter, bNew, specifies whether the value is to be part of |
| 13443 | ** the new.* (if bNew is non-zero) or old.* (if bNew is zero) record of |
| 13444 | ** the change under construction. If this does not match the type of change |
| 13445 | ** specified by the preceding call to sqlite3changegroup_change_begin() (i.e. |
| 13446 | ** an old.* value for an SQLITE_INSERT change, or a new.* value for an |
| 13447 | ** SQLITE_DELETE), then SQLITE_ERROR is returned. |
| 13448 | ** |
| 13449 | ** The third parameter specifies the column of the old.* or new.* record that |
| 13450 | ** the value will be a part of. If the specified table has an explicit primary |
| 13451 | ** key, then this is the index of the table column, numbered from 0 in the order |
| 13452 | ** specified within the CREATE TABLE statement. Or, if the table uses an |
| 13453 | ** implicit rowid key, then the column 0 is the rowid and the explicit columns |
| 13454 | ** are numbered starting from 1. If the iCol parameter is less than 0 or greater |
| 13455 | ** than the index of the last column in the table, SQLITE_RANGE is returned. |
| 13456 | ** |
| 13457 | ** The fourth parameter is the integer value to use as part of the old.* or |
| 13458 | ** new.* record. |
| 13459 | ** |
| 13460 | ** If this call is successful, SQLITE_OK is returned. Otherwise, if an |
| 13461 | ** error occurs, an SQLite error code is returned. |
| 13462 | */ |
| 13463 | SQLITE_API int sqlite3changegroup_change_int64( |
| 13464 | sqlite3_changegroup*, |
| 13465 | int bNew, |
| 13466 | int iCol, |
| 13467 | sqlite3_int64 iVal |
| 13468 | ); |
| 13469 | |
| 13470 | /* |
| 13471 | ** CAPI3REF: Add a NULL to a changegroup |
| 13472 | ** |
| 13473 | ** This function is similar to sqlite3changegroup_change_int64(). Except that |
| 13474 | ** it configures the change currently under construction with a NULL value |
| 13475 | ** instead of a 64-bit integer. |
| 13476 | */ |
| 13477 | SQLITE_API int sqlite3changegroup_change_null(sqlite3_changegroup*, int, int); |
| 13478 | |
| 13479 | /* |
| 13480 | ** CAPI3REF: Add an double to a changegroup |
| 13481 | ** |
| 13482 | ** This function is similar to sqlite3changegroup_change_int64(). Except that |
| 13483 | ** it configures the change currently being constructed with a real value |
| 13484 | ** instead of a 64-bit integer. |
| 13485 | */ |
| 13486 | SQLITE_API int sqlite3changegroup_change_double(sqlite3_changegroup*, int, int, double); |
| 13487 | |
| 13488 | /* |
| 13489 | ** CAPI3REF: Add a text value to a changegroup |
| 13490 | ** |
| 13491 | ** This function is similar to sqlite3changegroup_change_int64(). It configures |
| 13492 | ** the currently accumulated change with a text value instead of a 64-bit |
| 13493 | ** integer. Parameter pVal points to a buffer containing the text encoded using |
| 13494 | ** utf-8. Parameter nVal may either be the size of the text value in bytes, or |
| 13495 | ** else a negative value, in which case the buffer pVal points to is assumed to |
| 13496 | ** be nul-terminated. |
| 13497 | */ |
| 13498 | SQLITE_API int sqlite3changegroup_change_text( |
| 13499 | sqlite3_changegroup*, int, int, const char *pVal, int nVal |
| 13500 | ); |
| 13501 | |
| 13502 | /* |
| 13503 | ** CAPI3REF: Add a blob to a changegroup |
| 13504 | ** |
| 13505 | ** This function is similar to sqlite3changegroup_change_int64(). It configures |
| 13506 | ** the currently accumulated change with a blob value instead of a 64-bit |
| 13507 | ** integer. Parameter pVal points to a buffer containing the blob. Parameter |
| 13508 | ** nVal is the size of the blob in bytes. |
| 13509 | */ |
| 13510 | SQLITE_API int sqlite3changegroup_change_blob( |
| 13511 | sqlite3_changegroup*, int, int, const void *pVal, int nVal |
| 13512 | ); |
| 13513 | |
| 13514 | /* |
| 13515 | ** CAPI3REF: Finish adding one-at-at-time changes to a changegroup |
| 13516 | ** |
| 13517 | ** This function may only be called following a successful call to |
| 13518 | ** sqlite3changegroup_change_begin(). Otherwise, it is an SQLITE_MISUSE error. |
| 13519 | ** |
| 13520 | ** If parameter bDiscard is non-zero, then the current change is simply |
| 13521 | ** discarded. In this case this function is always successful and SQLITE_OK |
| 13522 | ** returned. |
| 13523 | ** |
| 13524 | ** If parameter bDiscard is zero, then an attempt is made to add the current |
| 13525 | ** change to the changegroup. Assuming the changegroup is configured to |
| 13526 | ** produce a changeset (not a patchset), this requires that: |
| 13527 | ** |
| 13528 | ** * If the change is an INSERT or DELETE, then a value must be specified |
| 13529 | ** for all columns of the new.* or old.* record, respectively. |
| 13530 | ** |
| 13531 | ** * If the change is an UPDATE record, then values must be provided for |
| 13532 | ** the PRIMARY KEY columns of the old.* record, but must not be provided |
| 13533 | ** for PRIMARY KEY columns of the new.* record. |
| 13534 | ** |
| 13535 | ** * If the change is an UPDATE record, then for each non-PRIMARY KEY |
| 13536 | ** column in the old.* record for which a value has been provided, a |
| 13537 | ** value must also be provided for the same column in the new.* record. |
| 13538 | ** Similarly, for each non-PK column in the old.* record for which |
| 13539 | ** a value is not provided, a value must not be provided for the same |
| 13540 | ** column in the new.* record. |
| 13541 | ** |
| 13542 | ** * All values specified for PRIMARY KEY columns must be non-NULL. |
| 13543 | ** |
| 13544 | ** Otherwise, it is an error. |
| 13545 | ** |
| 13546 | ** If the changegroup already contains a change for the same row (identified |
| 13547 | ** by PRIMARY KEY columns), then the current change is combined with the |
| 13548 | ** existing change in the same way as for sqlite3changegroup_add(). |
| 13549 | ** |
| 13550 | ** For a patchset, all of the above rules apply except that it doesn't matter |
| 13551 | ** whether or not values are provided for the non-PK old.* record columns |
| 13552 | ** for an UPDATE or DELETE change. This means that code used to produce |
| 13553 | ** a changeset using the sqlite3changegroup_change_xxx() APIs may also |
| 13554 | ** be used to produce patchsets. |
| 13555 | ** |
| 13556 | ** If the call is successful, SQLITE_OK is returned. Otherwise, if an error |
| 13557 | ** occurs, an SQLite error code is returned. If an error is returned and |
| 13558 | ** parameter pzErr is not NULL, then (*pzErr) may be set to point to a buffer |
| 13559 | ** containing a nul-terminated, utf-8 encoded, English language error message. |
| 13560 | ** It is the responsibility of the caller to eventually free any such error |
| 13561 | ** message buffer using sqlite3_free(). |
| 13562 | */ |
| 13563 | SQLITE_API int sqlite3changegroup_change_finish( |
| 13564 | sqlite3_changegroup*, |
| 13565 | int bDiscard, |
| 13566 | char **pzErr |
| 13567 | ); |
| 13568 | |
| 13569 | /* |
| 13570 | ** Make sure we can call this stuff from C++. |
| 13571 | */ |
| 13572 | #ifdef __cplusplus |
| 13573 |