| | @@ -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 | | -** 4966d7a1ce42af8b1c50fdd40e651e80d0ee with changes in files: |
| 21 | +** 5cbccab499bc3983aac1f57355552db607de with changes in files: |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| | @@ -463,18 +463,18 @@ |
| 463 | 463 | ** been edited in any way since it was last checked in, then the last |
| 464 | 464 | ** four hexadecimal digits of the hash may be modified. |
| 465 | 465 | ** |
| 466 | 466 | ** See also: [sqlite3_libversion()], |
| 467 | 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | | -** [sqlite_version()] and [sqlite_sourceid()]. |
| 468 | +** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | 469 | */ |
| 470 | 470 | #define SQLITE_VERSION "3.51.0" |
| 471 | 471 | #define SQLITE_VERSION_NUMBER 3051000 |
| 472 | | -#define SQLITE_SOURCE_ID "2025-10-10 14:31:46 4966d7a1ce42af8b1c50fdd40e651e80d0eeb8cb62dd882950cab275f98aba88" |
| 472 | +#define SQLITE_SOURCE_ID "2025-10-15 10:52:45 5cbccab499bc3983aac1f57355552db607dee6c7ef4eb00d794dbee89c18db70" |
| 473 | 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | 474 | #define SQLITE_SCM_TAGS "" |
| 475 | | -#define SQLITE_SCM_DATETIME "2025-10-10T14:31:46.035Z" |
| 475 | +#define SQLITE_SCM_DATETIME "2025-10-15T10:52:45.276Z" |
| 476 | 476 | |
| 477 | 477 | /* |
| 478 | 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | 480 | ** |
| | @@ -502,11 +502,11 @@ |
| 502 | 502 | ** a pointer to a string constant whose value is the same as the |
| 503 | 503 | ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built |
| 504 | 504 | ** using an edited copy of [the amalgamation], then the last four characters |
| 505 | 505 | ** of the hash might be different from [SQLITE_SOURCE_ID].)^ |
| 506 | 506 | ** |
| 507 | | -** See also: [sqlite_version()] and [sqlite_sourceid()]. |
| 507 | +** See also: [sqlite_version()] and [sqlite_source_id()]. |
| 508 | 508 | */ |
| 509 | 509 | SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; |
| 510 | 510 | SQLITE_API const char *sqlite3_libversion(void); |
| 511 | 511 | SQLITE_API const char *sqlite3_sourceid(void); |
| 512 | 512 | SQLITE_API int sqlite3_libversion_number(void); |
| | @@ -9239,14 +9239,23 @@ |
| 9239 | 9239 | ** the resetFlg is true, then the highest instantaneous value is |
| 9240 | 9240 | ** reset back down to the current value. |
| 9241 | 9241 | ** |
| 9242 | 9242 | ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a |
| 9243 | 9243 | ** non-zero [error code] on failure. |
| 9244 | +** |
| 9245 | +** ^The sqlite3_db_status64(D,O,C,H,R) routine works exactly the same |
| 9246 | +** way as sqlite3_db_status(D,O,C,H,R) routine except that the C and H |
| 9247 | +** parameters are pointer to 64-bit integers (type: sqlite3_int64) instead |
| 9248 | +** of pointers to 32-bit integers, which allows larger status values |
| 9249 | +** to be returned. If a status value exceeds 2,147,483,647 then |
| 9250 | +** sqlite3_db_status() will truncate the value whereas sqlite3_db_status64() |
| 9251 | +** will return the full value. |
| 9244 | 9252 | ** |
| 9245 | 9253 | ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. |
| 9246 | 9254 | */ |
| 9247 | 9255 | SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); |
| 9256 | +SQLITE_API int sqlite3_db_status64(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int); |
| 9248 | 9257 | |
| 9249 | 9258 | /* |
| 9250 | 9259 | ** CAPI3REF: Status Parameters for database connections |
| 9251 | 9260 | ** KEYWORDS: {SQLITE_DBSTATUS options} |
| 9252 | 9261 | ** |
| | @@ -9339,10 +9348,14 @@ |
| 9339 | 9348 | ** database file in rollback mode databases. Any pages written as part of |
| 9340 | 9349 | ** transaction rollback or database recovery operations are not included. |
| 9341 | 9350 | ** If an IO or other error occurs while writing a page to disk, the effect |
| 9342 | 9351 | ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The |
| 9343 | 9352 | ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. |
| 9353 | +** <p> |
| 9354 | +** ^(There is overlap between the quantities measured by this parameter |
| 9355 | +** (SQLITE_DBSTATUS_CACHE_WRITE) and SQLITE_DBSTATUS_TEMPBUF_SPILL. |
| 9356 | +** Resetting one will reduce the other.)^ |
| 9344 | 9357 | ** </dd> |
| 9345 | 9358 | ** |
| 9346 | 9359 | ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt> |
| 9347 | 9360 | ** <dd>This parameter returns the number of dirty cache entries that have |
| 9348 | 9361 | ** been written to disk in the middle of a transaction due to the page |
| | @@ -9354,10 +9367,22 @@ |
| 9354 | 9367 | ** |
| 9355 | 9368 | ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt> |
| 9356 | 9369 | ** <dd>This parameter returns zero for the current value if and only if |
| 9357 | 9370 | ** all foreign key constraints (deferred or immediate) have been |
| 9358 | 9371 | ** resolved.)^ ^The highwater mark is always 0. |
| 9372 | +** |
| 9373 | +** [[SQLITE_DBSTATUS_TEMPBUF_SPILL] ^(<dt>SQLITE_DBSTATUS_TEMPBUF_SPILL</dt> |
| 9374 | +** <dd>^(This parameter returns the number of bytes written to temporary |
| 9375 | +** files on disk that could have been kept in memory had sufficient memory |
| 9376 | +** been available. This value includes writes to intermediate tables that |
| 9377 | +** are part of complex queries, external sorts that spill to disk, and |
| 9378 | +** writes to TEMP tables.)^ |
| 9379 | +** ^The highwater mark is always 0. |
| 9380 | +** <p> |
| 9381 | +** ^(There is overlap between the quantities measured by this parameter |
| 9382 | +** (SQLITE_DBSTATUS_TEMPBUF_SPILL) and SQLITE_DBSTATUS_CACHE_WRITE. |
| 9383 | +** Resetting one will reduce the other.)^ |
| 9359 | 9384 | ** </dd> |
| 9360 | 9385 | ** </dl> |
| 9361 | 9386 | */ |
| 9362 | 9387 | #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 |
| 9363 | 9388 | #define SQLITE_DBSTATUS_CACHE_USED 1 |
| | @@ -9370,11 +9395,12 @@ |
| 9370 | 9395 | #define SQLITE_DBSTATUS_CACHE_MISS 8 |
| 9371 | 9396 | #define SQLITE_DBSTATUS_CACHE_WRITE 9 |
| 9372 | 9397 | #define SQLITE_DBSTATUS_DEFERRED_FKS 10 |
| 9373 | 9398 | #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 |
| 9374 | 9399 | #define SQLITE_DBSTATUS_CACHE_SPILL 12 |
| 9375 | | -#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ |
| 9400 | +#define SQLITE_DBSTATUS_TEMPBUF_SPILL 13 |
| 9401 | +#define SQLITE_DBSTATUS_MAX 13 /* Largest defined DBSTATUS */ |
| 9376 | 9402 | |
| 9377 | 9403 | |
| 9378 | 9404 | /* |
| 9379 | 9405 | ** CAPI3REF: Prepared Statement Status |
| 9380 | 9406 | ** METHOD: sqlite3_stmt |
| | @@ -18320,10 +18346,11 @@ |
| 18320 | 18346 | int nStatement; /* Number of nested statement-transactions */ |
| 18321 | 18347 | i64 nDeferredCons; /* Net deferred constraints this transaction. */ |
| 18322 | 18348 | i64 nDeferredImmCons; /* Net deferred immediate constraints */ |
| 18323 | 18349 | int *pnBytesFreed; /* If not NULL, increment this in DbFree() */ |
| 18324 | 18350 | DbClientData *pDbData; /* sqlite3_set_clientdata() content */ |
| 18351 | + u64 nSpill; /* TEMP content spilled to disk */ |
| 18325 | 18352 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 18326 | 18353 | /* The following variables are all protected by the STATIC_MAIN |
| 18327 | 18354 | ** mutex, not by sqlite3.mutex. They are used by code in notify.c. |
| 18328 | 18355 | ** |
| 18329 | 18356 | ** When X.pUnlockConnection==Y, that means that X is waiting for Y to |
| | @@ -24712,27 +24739,29 @@ |
| 24712 | 24739 | } |
| 24713 | 24740 | |
| 24714 | 24741 | /* |
| 24715 | 24742 | ** Query status information for a single database connection |
| 24716 | 24743 | */ |
| 24717 | | -SQLITE_API int sqlite3_db_status( |
| 24718 | | - sqlite3 *db, /* The database connection whose status is desired */ |
| 24719 | | - int op, /* Status verb */ |
| 24720 | | - int *pCurrent, /* Write current value here */ |
| 24721 | | - int *pHighwater, /* Write high-water mark here */ |
| 24722 | | - int resetFlag /* Reset high-water mark if true */ |
| 24744 | +SQLITE_API int sqlite3_db_status64( |
| 24745 | + sqlite3 *db, /* The database connection whose status is desired */ |
| 24746 | + int op, /* Status verb */ |
| 24747 | + sqlite3_int64 *pCurrent, /* Write current value here */ |
| 24748 | + sqlite3_int64 *pHighwtr, /* Write high-water mark here */ |
| 24749 | + int resetFlag /* Reset high-water mark if true */ |
| 24723 | 24750 | ){ |
| 24724 | 24751 | int rc = SQLITE_OK; /* Return code */ |
| 24725 | 24752 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 24726 | | - if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ |
| 24753 | + if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwtr==0 ){ |
| 24727 | 24754 | return SQLITE_MISUSE_BKPT; |
| 24728 | 24755 | } |
| 24729 | 24756 | #endif |
| 24730 | 24757 | sqlite3_mutex_enter(db->mutex); |
| 24731 | 24758 | switch( op ){ |
| 24732 | 24759 | case SQLITE_DBSTATUS_LOOKASIDE_USED: { |
| 24733 | | - *pCurrent = sqlite3LookasideUsed(db, pHighwater); |
| 24760 | + int H = 0; |
| 24761 | + *pCurrent = sqlite3LookasideUsed(db, &H); |
| 24762 | + *pHighwtr = H; |
| 24734 | 24763 | if( resetFlag ){ |
| 24735 | 24764 | LookasideSlot *p = db->lookaside.pFree; |
| 24736 | 24765 | if( p ){ |
| 24737 | 24766 | while( p->pNext ) p = p->pNext; |
| 24738 | 24767 | p->pNext = db->lookaside.pInit; |
| | @@ -24759,11 +24788,11 @@ |
| 24759 | 24788 | testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE ); |
| 24760 | 24789 | testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL ); |
| 24761 | 24790 | assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 ); |
| 24762 | 24791 | assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 ); |
| 24763 | 24792 | *pCurrent = 0; |
| 24764 | | - *pHighwater = (int)db->lookaside.anStat[op-SQLITE_DBSTATUS_LOOKASIDE_HIT]; |
| 24793 | + *pHighwtr = db->lookaside.anStat[op-SQLITE_DBSTATUS_LOOKASIDE_HIT]; |
| 24765 | 24794 | if( resetFlag ){ |
| 24766 | 24795 | db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0; |
| 24767 | 24796 | } |
| 24768 | 24797 | break; |
| 24769 | 24798 | } |
| | @@ -24773,11 +24802,11 @@ |
| 24773 | 24802 | ** by all pagers associated with the given database connection. The |
| 24774 | 24803 | ** highwater mark is meaningless and is returned as zero. |
| 24775 | 24804 | */ |
| 24776 | 24805 | case SQLITE_DBSTATUS_CACHE_USED_SHARED: |
| 24777 | 24806 | case SQLITE_DBSTATUS_CACHE_USED: { |
| 24778 | | - int totalUsed = 0; |
| 24807 | + sqlite3_int64 totalUsed = 0; |
| 24779 | 24808 | int i; |
| 24780 | 24809 | sqlite3BtreeEnterAll(db); |
| 24781 | 24810 | for(i=0; i<db->nDb; i++){ |
| 24782 | 24811 | Btree *pBt = db->aDb[i].pBt; |
| 24783 | 24812 | if( pBt ){ |
| | @@ -24789,22 +24818,22 @@ |
| 24789 | 24818 | totalUsed += nByte; |
| 24790 | 24819 | } |
| 24791 | 24820 | } |
| 24792 | 24821 | sqlite3BtreeLeaveAll(db); |
| 24793 | 24822 | *pCurrent = totalUsed; |
| 24794 | | - *pHighwater = 0; |
| 24823 | + *pHighwtr = 0; |
| 24795 | 24824 | break; |
| 24796 | 24825 | } |
| 24797 | 24826 | |
| 24798 | 24827 | /* |
| 24799 | 24828 | ** *pCurrent gets an accurate estimate of the amount of memory used |
| 24800 | 24829 | ** to store the schema for all databases (main, temp, and any ATTACHed |
| 24801 | | - ** databases. *pHighwater is set to zero. |
| 24830 | + ** databases. *pHighwtr is set to zero. |
| 24802 | 24831 | */ |
| 24803 | 24832 | case SQLITE_DBSTATUS_SCHEMA_USED: { |
| 24804 | | - int i; /* Used to iterate through schemas */ |
| 24805 | | - int nByte = 0; /* Used to accumulate return value */ |
| 24833 | + int i; /* Used to iterate through schemas */ |
| 24834 | + int nByte = 0; /* Used to accumulate return value */ |
| 24806 | 24835 | |
| 24807 | 24836 | sqlite3BtreeEnterAll(db); |
| 24808 | 24837 | db->pnBytesFreed = &nByte; |
| 24809 | 24838 | assert( db->lookaside.pEnd==db->lookaside.pTrueEnd ); |
| 24810 | 24839 | db->lookaside.pEnd = db->lookaside.pStart; |
| | @@ -24834,19 +24863,19 @@ |
| 24834 | 24863 | } |
| 24835 | 24864 | db->pnBytesFreed = 0; |
| 24836 | 24865 | db->lookaside.pEnd = db->lookaside.pTrueEnd; |
| 24837 | 24866 | sqlite3BtreeLeaveAll(db); |
| 24838 | 24867 | |
| 24839 | | - *pHighwater = 0; |
| 24868 | + *pHighwtr = 0; |
| 24840 | 24869 | *pCurrent = nByte; |
| 24841 | 24870 | break; |
| 24842 | 24871 | } |
| 24843 | 24872 | |
| 24844 | 24873 | /* |
| 24845 | 24874 | ** *pCurrent gets an accurate estimate of the amount of memory used |
| 24846 | 24875 | ** to store all prepared statements. |
| 24847 | | - ** *pHighwater is set to zero. |
| 24876 | + ** *pHighwtr is set to zero. |
| 24848 | 24877 | */ |
| 24849 | 24878 | case SQLITE_DBSTATUS_STMT_USED: { |
| 24850 | 24879 | struct Vdbe *pVdbe; /* Used to iterate through VMs */ |
| 24851 | 24880 | int nByte = 0; /* Used to accumulate return value */ |
| 24852 | 24881 | |
| | @@ -24857,19 +24886,19 @@ |
| 24857 | 24886 | sqlite3VdbeDelete(pVdbe); |
| 24858 | 24887 | } |
| 24859 | 24888 | db->lookaside.pEnd = db->lookaside.pTrueEnd; |
| 24860 | 24889 | db->pnBytesFreed = 0; |
| 24861 | 24890 | |
| 24862 | | - *pHighwater = 0; /* IMP: R-64479-57858 */ |
| 24891 | + *pHighwtr = 0; /* IMP: R-64479-57858 */ |
| 24863 | 24892 | *pCurrent = nByte; |
| 24864 | 24893 | |
| 24865 | 24894 | break; |
| 24866 | 24895 | } |
| 24867 | 24896 | |
| 24868 | 24897 | /* |
| 24869 | 24898 | ** Set *pCurrent to the total cache hits or misses encountered by all |
| 24870 | | - ** pagers the database handle is connected to. *pHighwater is always set |
| 24899 | + ** pagers the database handle is connected to. *pHighwtr is always set |
| 24871 | 24900 | ** to zero. |
| 24872 | 24901 | */ |
| 24873 | 24902 | case SQLITE_DBSTATUS_CACHE_SPILL: |
| 24874 | 24903 | op = SQLITE_DBSTATUS_CACHE_WRITE+1; |
| 24875 | 24904 | /* no break */ deliberate_fall_through |
| | @@ -24885,23 +24914,43 @@ |
| 24885 | 24914 | if( db->aDb[i].pBt ){ |
| 24886 | 24915 | Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt); |
| 24887 | 24916 | sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet); |
| 24888 | 24917 | } |
| 24889 | 24918 | } |
| 24890 | | - *pHighwater = 0; /* IMP: R-42420-56072 */ |
| 24919 | + *pHighwtr = 0; /* IMP: R-42420-56072 */ |
| 24891 | 24920 | /* IMP: R-54100-20147 */ |
| 24892 | 24921 | /* IMP: R-29431-39229 */ |
| 24893 | | - *pCurrent = (int)nRet & 0x7fffffff; |
| 24922 | + *pCurrent = nRet; |
| 24923 | + break; |
| 24924 | + } |
| 24925 | + |
| 24926 | + /* Set *pCurrent to the number of bytes that the db database connection |
| 24927 | + ** has spilled to the filesystem in temporary files that could have been |
| 24928 | + ** stored in memory, had sufficient memory been available. |
| 24929 | + ** The *pHighwater is always set to zero. |
| 24930 | + */ |
| 24931 | + case SQLITE_DBSTATUS_TEMPBUF_SPILL: { |
| 24932 | + u64 nRet = 0; |
| 24933 | + if( db->aDb[1].pBt ){ |
| 24934 | + Pager *pPager = sqlite3BtreePager(db->aDb[1].pBt); |
| 24935 | + sqlite3PagerCacheStat(pPager, SQLITE_DBSTATUS_CACHE_WRITE, |
| 24936 | + resetFlag, &nRet); |
| 24937 | + nRet *= sqlite3BtreeGetPageSize(db->aDb[1].pBt); |
| 24938 | + } |
| 24939 | + nRet += db->nSpill; |
| 24940 | + if( resetFlag ) db->nSpill = 0; |
| 24941 | + *pHighwtr = 0; |
| 24942 | + *pCurrent = nRet; |
| 24894 | 24943 | break; |
| 24895 | 24944 | } |
| 24896 | 24945 | |
| 24897 | 24946 | /* Set *pCurrent to non-zero if there are unresolved deferred foreign |
| 24898 | 24947 | ** key constraints. Set *pCurrent to zero if all foreign key constraints |
| 24899 | | - ** have been satisfied. The *pHighwater is always set to zero. |
| 24948 | + ** have been satisfied. The *pHighwtr is always set to zero. |
| 24900 | 24949 | */ |
| 24901 | 24950 | case SQLITE_DBSTATUS_DEFERRED_FKS: { |
| 24902 | | - *pHighwater = 0; /* IMP: R-11967-56545 */ |
| 24951 | + *pHighwtr = 0; /* IMP: R-11967-56545 */ |
| 24903 | 24952 | *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0; |
| 24904 | 24953 | break; |
| 24905 | 24954 | } |
| 24906 | 24955 | |
| 24907 | 24956 | default: { |
| | @@ -24909,10 +24958,35 @@ |
| 24909 | 24958 | } |
| 24910 | 24959 | } |
| 24911 | 24960 | sqlite3_mutex_leave(db->mutex); |
| 24912 | 24961 | return rc; |
| 24913 | 24962 | } |
| 24963 | + |
| 24964 | +/* |
| 24965 | +** 32-bit variant of sqlite3_db_status64() |
| 24966 | +*/ |
| 24967 | +SQLITE_API int sqlite3_db_status( |
| 24968 | + sqlite3 *db, /* The database connection whose status is desired */ |
| 24969 | + int op, /* Status verb */ |
| 24970 | + int *pCurrent, /* Write current value here */ |
| 24971 | + int *pHighwtr, /* Write high-water mark here */ |
| 24972 | + int resetFlag /* Reset high-water mark if true */ |
| 24973 | +){ |
| 24974 | + sqlite3_int64 C = 0, H = 0; |
| 24975 | + int rc; |
| 24976 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 24977 | + if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwtr==0 ){ |
| 24978 | + return SQLITE_MISUSE_BKPT; |
| 24979 | + } |
| 24980 | +#endif |
| 24981 | + rc = sqlite3_db_status64(db, op, &C, &H, resetFlag); |
| 24982 | + if( rc==0 ){ |
| 24983 | + *pCurrent = C & 0x7fffffff; |
| 24984 | + *pHighwtr = H & 0x7fffffff; |
| 24985 | + } |
| 24986 | + return rc; |
| 24987 | +} |
| 24914 | 24988 | |
| 24915 | 24989 | /************** End of status.c **********************************************/ |
| 24916 | 24990 | /************** Begin file date.c ********************************************/ |
| 24917 | 24991 | /* |
| 24918 | 24992 | ** 2003 October 31 |
| | @@ -95636,11 +95710,11 @@ |
| 95636 | 95710 | ** to run faster. |
| 95637 | 95711 | */ |
| 95638 | 95712 | static SQLITE_NOINLINE int vdbeColumnFromOverflow( |
| 95639 | 95713 | VdbeCursor *pC, /* The BTree cursor from which we are reading */ |
| 95640 | 95714 | int iCol, /* The column to read */ |
| 95641 | | - int t, /* The serial-type code for the column value */ |
| 95715 | + u32 t, /* The serial-type code for the column value */ |
| 95642 | 95716 | i64 iOffset, /* Offset to the start of the content value */ |
| 95643 | 95717 | u32 cacheStatus, /* Current Vdbe.cacheCtr value */ |
| 95644 | 95718 | u32 colCacheCtr, /* Current value of the column cache counter */ |
| 95645 | 95719 | Mem *pDest /* Store the value into this register. */ |
| 95646 | 95720 | ){ |
| | @@ -96737,11 +96811,12 @@ |
| 96737 | 96811 | flags2 = pIn2->flags & ~MEM_Str; |
| 96738 | 96812 | }else if( (flags2 & MEM_Zero)!=0 ){ |
| 96739 | 96813 | if( sqlite3VdbeMemExpandBlob(pIn2) ) goto no_mem; |
| 96740 | 96814 | flags2 = pIn2->flags & ~MEM_Str; |
| 96741 | 96815 | } |
| 96742 | | - nByte = pIn1->n + pIn2->n; |
| 96816 | + nByte = pIn1->n; |
| 96817 | + nByte += pIn2->n; |
| 96743 | 96818 | if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 96744 | 96819 | goto too_big; |
| 96745 | 96820 | } |
| 96746 | 96821 | if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){ |
| 96747 | 96822 | goto no_mem; |
| | @@ -98562,11 +98637,11 @@ |
| 98562 | 98637 | assert( db->mallocFailed || pRec->flags&(MEM_Str|MEM_Blob) ); |
| 98563 | 98638 | assert( pRec->n>=0 ); |
| 98564 | 98639 | len = (u32)pRec->n; |
| 98565 | 98640 | serial_type = (len*2) + 12 + ((pRec->flags & MEM_Str)!=0); |
| 98566 | 98641 | if( pRec->flags & MEM_Zero ){ |
| 98567 | | - serial_type += pRec->u.nZero*2; |
| 98642 | + serial_type += (u32)pRec->u.nZero*2; |
| 98568 | 98643 | if( nData ){ |
| 98569 | 98644 | if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem; |
| 98570 | 98645 | len += pRec->u.nZero; |
| 98571 | 98646 | }else{ |
| 98572 | 98647 | nZero += pRec->u.nZero; |
| | @@ -105079,10 +105154,11 @@ |
| 105079 | 105154 | UnpackedRecord *pUnpacked; /* Space to unpack a record */ |
| 105080 | 105155 | SorterList list; /* List for thread to write to a PMA */ |
| 105081 | 105156 | SorterCompare xCompare; /* Compare function to use */ |
| 105082 | 105157 | SorterFile file; /* Temp file for level-0 PMAs */ |
| 105083 | 105158 | SorterFile file2; /* Space for other PMAs */ |
| 105159 | + u64 nSpill; /* Total bytes written by this task */ |
| 105084 | 105160 | }; |
| 105085 | 105161 | |
| 105086 | 105162 | |
| 105087 | 105163 | /* |
| 105088 | 105164 | ** Main sorter structure. A single instance of this is allocated for each |
| | @@ -105199,10 +105275,11 @@ |
| 105199 | 105275 | int nBuffer; /* Size of write buffer in bytes */ |
| 105200 | 105276 | int iBufStart; /* First byte of buffer to write */ |
| 105201 | 105277 | int iBufEnd; /* Last byte of buffer to write */ |
| 105202 | 105278 | i64 iWriteOff; /* Offset of start of buffer in file */ |
| 105203 | 105279 | sqlite3_file *pFd; /* File handle to write to */ |
| 105280 | + u64 nPmaSpill; /* Total number of bytes written */ |
| 105204 | 105281 | }; |
| 105205 | 105282 | |
| 105206 | 105283 | /* |
| 105207 | 105284 | ** This object is the header on a single record while that record is being |
| 105208 | 105285 | ** held in memory and prior to being written out as part of a PMA. |
| | @@ -106057,10 +106134,16 @@ |
| 106057 | 106134 | SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *db, VdbeCursor *pCsr){ |
| 106058 | 106135 | VdbeSorter *pSorter; |
| 106059 | 106136 | assert( pCsr->eCurType==CURTYPE_SORTER ); |
| 106060 | 106137 | pSorter = pCsr->uc.pSorter; |
| 106061 | 106138 | if( pSorter ){ |
| 106139 | + /* Increment db->nSpill by the total number of bytes of data written |
| 106140 | + ** to temp files by this sort operation. */ |
| 106141 | + int ii; |
| 106142 | + for(ii=0; ii<pSorter->nTask; ii++){ |
| 106143 | + db->nSpill += pSorter->aTask[ii].nSpill; |
| 106144 | + } |
| 106062 | 106145 | sqlite3VdbeSorterReset(db, pSorter); |
| 106063 | 106146 | sqlite3_free(pSorter->list.aMemory); |
| 106064 | 106147 | sqlite3DbFree(db, pSorter); |
| 106065 | 106148 | pCsr->uc.pSorter = 0; |
| 106066 | 106149 | } |
| | @@ -106282,10 +106365,11 @@ |
| 106282 | 106365 | if( p->iBufEnd==p->nBuffer ){ |
| 106283 | 106366 | p->eFWErr = sqlite3OsWrite(p->pFd, |
| 106284 | 106367 | &p->aBuffer[p->iBufStart], p->iBufEnd - p->iBufStart, |
| 106285 | 106368 | p->iWriteOff + p->iBufStart |
| 106286 | 106369 | ); |
| 106370 | + p->nPmaSpill += (p->iBufEnd - p->iBufStart); |
| 106287 | 106371 | p->iBufStart = p->iBufEnd = 0; |
| 106288 | 106372 | p->iWriteOff += p->nBuffer; |
| 106289 | 106373 | } |
| 106290 | 106374 | assert( p->iBufEnd<p->nBuffer ); |
| 106291 | 106375 | |
| | @@ -106298,21 +106382,24 @@ |
| 106298 | 106382 | ** The results of using the PMA-writer after this call are undefined. |
| 106299 | 106383 | ** Return SQLITE_OK if flushing the buffered data succeeds or is not |
| 106300 | 106384 | ** required. Otherwise, return an SQLite error code. |
| 106301 | 106385 | ** |
| 106302 | 106386 | ** Before returning, set *piEof to the offset immediately following the |
| 106303 | | -** last byte written to the file. |
| 106387 | +** last byte written to the file. Also, increment (*pnSpill) by the total |
| 106388 | +** number of bytes written to the file. |
| 106304 | 106389 | */ |
| 106305 | | -static int vdbePmaWriterFinish(PmaWriter *p, i64 *piEof){ |
| 106390 | +static int vdbePmaWriterFinish(PmaWriter *p, i64 *piEof, u64 *pnSpill){ |
| 106306 | 106391 | int rc; |
| 106307 | 106392 | if( p->eFWErr==0 && ALWAYS(p->aBuffer) && p->iBufEnd>p->iBufStart ){ |
| 106308 | 106393 | p->eFWErr = sqlite3OsWrite(p->pFd, |
| 106309 | 106394 | &p->aBuffer[p->iBufStart], p->iBufEnd - p->iBufStart, |
| 106310 | 106395 | p->iWriteOff + p->iBufStart |
| 106311 | 106396 | ); |
| 106397 | + p->nPmaSpill += (p->iBufEnd - p->iBufStart); |
| 106312 | 106398 | } |
| 106313 | 106399 | *piEof = (p->iWriteOff + p->iBufEnd); |
| 106400 | + *pnSpill += p->nPmaSpill; |
| 106314 | 106401 | sqlite3_free(p->aBuffer); |
| 106315 | 106402 | rc = p->eFWErr; |
| 106316 | 106403 | memset(p, 0, sizeof(PmaWriter)); |
| 106317 | 106404 | return rc; |
| 106318 | 106405 | } |
| | @@ -106388,11 +106475,11 @@ |
| 106388 | 106475 | vdbePmaWriteVarint(&writer, p->nVal); |
| 106389 | 106476 | vdbePmaWriteBlob(&writer, SRVAL(p), p->nVal); |
| 106390 | 106477 | if( pList->aMemory==0 ) sqlite3_free(p); |
| 106391 | 106478 | } |
| 106392 | 106479 | pList->pList = p; |
| 106393 | | - rc = vdbePmaWriterFinish(&writer, &pTask->file.iEof); |
| 106480 | + rc = vdbePmaWriterFinish(&writer, &pTask->file.iEof, &pTask->nSpill); |
| 106394 | 106481 | } |
| 106395 | 106482 | |
| 106396 | 106483 | vdbeSorterWorkDebug(pTask, "exit"); |
| 106397 | 106484 | assert( rc!=SQLITE_OK || pList->pList==0 ); |
| 106398 | 106485 | assert( rc!=SQLITE_OK || pTask->file.iEof==iSz ); |
| | @@ -106702,11 +106789,11 @@ |
| 106702 | 106789 | vdbePmaWriteBlob(&writer, pReader->aKey, nKey); |
| 106703 | 106790 | assert( pIncr->pMerger->pTask==pTask ); |
| 106704 | 106791 | rc = vdbeMergeEngineStep(pIncr->pMerger, &dummy); |
| 106705 | 106792 | } |
| 106706 | 106793 | |
| 106707 | | - rc2 = vdbePmaWriterFinish(&writer, &pOut->iEof); |
| 106794 | + rc2 = vdbePmaWriterFinish(&writer, &pOut->iEof, &pTask->nSpill); |
| 106708 | 106795 | if( rc==SQLITE_OK ) rc = rc2; |
| 106709 | 106796 | vdbeSorterPopulateDebug(pTask, "exit"); |
| 106710 | 106797 | return rc; |
| 106711 | 106798 | } |
| 106712 | 106799 | |
| | @@ -133012,10 +133099,11 @@ |
| 133012 | 133099 | int nSep, |
| 133013 | 133100 | const char *zSep |
| 133014 | 133101 | ){ |
| 133015 | 133102 | i64 j, n = 0; |
| 133016 | 133103 | int i; |
| 133104 | + int bNotNull = 0; /* True after at least NOT NULL argument seen */ |
| 133017 | 133105 | char *z; |
| 133018 | 133106 | for(i=0; i<argc; i++){ |
| 133019 | 133107 | n += sqlite3_value_bytes(argv[i]); |
| 133020 | 133108 | } |
| 133021 | 133109 | n += (argc-1)*(i64)nSep; |
| | @@ -133028,16 +133116,17 @@ |
| 133028 | 133116 | for(i=0; i<argc; i++){ |
| 133029 | 133117 | if( sqlite3_value_type(argv[i])!=SQLITE_NULL ){ |
| 133030 | 133118 | int k = sqlite3_value_bytes(argv[i]); |
| 133031 | 133119 | const char *v = (const char*)sqlite3_value_text(argv[i]); |
| 133032 | 133120 | if( v!=0 ){ |
| 133033 | | - if( j>0 && nSep>0 ){ |
| 133121 | + if( bNotNull && nSep>0 ){ |
| 133034 | 133122 | memcpy(&z[j], zSep, nSep); |
| 133035 | 133123 | j += nSep; |
| 133036 | 133124 | } |
| 133037 | 133125 | memcpy(&z[j], v, k); |
| 133038 | 133126 | j += k; |
| 133127 | + bNotNull = 1; |
| 133039 | 133128 | } |
| 133040 | 133129 | } |
| 133041 | 133130 | } |
| 133042 | 133131 | z[j] = 0; |
| 133043 | 133132 | assert( j<=n ); |
| | @@ -140169,10 +140258,12 @@ |
| 140169 | 140258 | int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*)); |
| 140170 | 140259 | /* Version 3.50.0 and later */ |
| 140171 | 140260 | int (*setlk_timeout)(sqlite3*,int,int); |
| 140172 | 140261 | /* Version 3.51.0 and later */ |
| 140173 | 140262 | int (*set_errmsg)(sqlite3*,int,const char*); |
| 140263 | + int (*db_status64)(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int); |
| 140264 | + |
| 140174 | 140265 | }; |
| 140175 | 140266 | |
| 140176 | 140267 | /* |
| 140177 | 140268 | ** This is the function signature used for all extension entry points. It |
| 140178 | 140269 | ** is also defined in the file "loadext.c". |
| | @@ -140506,10 +140597,11 @@ |
| 140506 | 140597 | #define sqlite3_set_clientdata sqlite3_api->set_clientdata |
| 140507 | 140598 | /* Version 3.50.0 and later */ |
| 140508 | 140599 | #define sqlite3_setlk_timeout sqlite3_api->setlk_timeout |
| 140509 | 140600 | /* Version 3.51.0 and later */ |
| 140510 | 140601 | #define sqlite3_set_errmsg sqlite3_api->set_errmsg |
| 140602 | +#define sqlite3_db_status64 sqlite3_api->db_status64 |
| 140511 | 140603 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 140512 | 140604 | |
| 140513 | 140605 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 140514 | 140606 | /* This case when the file really is being compiled as a loadable |
| 140515 | 140607 | ** extension */ |
| | @@ -141031,11 +141123,12 @@ |
| 141031 | 141123 | sqlite3_get_clientdata, |
| 141032 | 141124 | sqlite3_set_clientdata, |
| 141033 | 141125 | /* Version 3.50.0 and later */ |
| 141034 | 141126 | sqlite3_setlk_timeout, |
| 141035 | 141127 | /* Version 3.51.0 and later */ |
| 141036 | | - sqlite3_set_errmsg |
| 141128 | + sqlite3_set_errmsg, |
| 141129 | + sqlite3_db_status64 |
| 141037 | 141130 | }; |
| 141038 | 141131 | |
| 141039 | 141132 | /* True if x is the directory separator character |
| 141040 | 141133 | */ |
| 141041 | 141134 | #if SQLITE_OS_WIN |
| | @@ -247573,13 +247666,13 @@ |
| 247573 | 247666 | ** backing store corruption. */ |
| 247574 | 247667 | if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT_ROWID(p, iRowid); |
| 247575 | 247668 | |
| 247576 | 247669 | if( rc==SQLITE_OK ){ |
| 247577 | 247670 | u8 *aOut = 0; /* Read blob data into this buffer */ |
| 247578 | | - int nByte = sqlite3_blob_bytes(p->pReader); |
| 247579 | | - int szData = (sizeof(Fts5Data) + 7) & ~7; |
| 247580 | | - sqlite3_int64 nAlloc = szData + nByte + FTS5_DATA_PADDING; |
| 247671 | + i64 nByte = sqlite3_blob_bytes(p->pReader); |
| 247672 | + i64 szData = (sizeof(Fts5Data) + 7) & ~7; |
| 247673 | + i64 nAlloc = szData + nByte + FTS5_DATA_PADDING; |
| 247581 | 247674 | pRet = (Fts5Data*)sqlite3_malloc64(nAlloc); |
| 247582 | 247675 | if( pRet ){ |
| 247583 | 247676 | pRet->nn = nByte; |
| 247584 | 247677 | aOut = pRet->p = (u8*)pRet + szData; |
| 247585 | 247678 | }else{ |
| | @@ -259833,11 +259926,11 @@ |
| 259833 | 259926 | int nArg, /* Number of args */ |
| 259834 | 259927 | sqlite3_value **apUnused /* Function arguments */ |
| 259835 | 259928 | ){ |
| 259836 | 259929 | assert( nArg==0 ); |
| 259837 | 259930 | UNUSED_PARAM2(nArg, apUnused); |
| 259838 | | - sqlite3_result_text(pCtx, "fts5: 2025-10-10 14:22:05 fe9cf68b513d1e8cfcde90f1982a7f4123f54e3ebb004d961a99bdf6bec03a32", -1, SQLITE_TRANSIENT); |
| 259931 | + sqlite3_result_text(pCtx, "fts5: 2025-10-15 10:52:45 5cbccab499bc3983aac1f57355552db607dee6c7ef4eb00d794dbee89c18db70", -1, SQLITE_TRANSIENT); |
| 259839 | 259932 | } |
| 259840 | 259933 | |
| 259841 | 259934 | /* |
| 259842 | 259935 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 259843 | 259936 | ** |
| | @@ -260150,20 +260243,20 @@ |
| 260150 | 260243 | ** must be read from the saved row stored in Fts5Storage.pSavedRow. |
| 260151 | 260244 | ** |
| 260152 | 260245 | ** This is necessary - using sqlite3_value_nochange() instead of just having |
| 260153 | 260246 | ** SQLite pass the original value back via xUpdate() - so as not to discard |
| 260154 | 260247 | ** any locale information associated with such values. |
| 260248 | +** |
| 260155 | 260249 | */ |
| 260156 | 260250 | struct Fts5Storage { |
| 260157 | 260251 | Fts5Config *pConfig; |
| 260158 | 260252 | Fts5Index *pIndex; |
| 260159 | | - int db_enc; /* Database encoding */ |
| 260160 | 260253 | int bTotalsValid; /* True if nTotalRow/aTotalSize[] are valid */ |
| 260161 | 260254 | i64 nTotalRow; /* Total number of rows in FTS table */ |
| 260162 | 260255 | i64 *aTotalSize; /* Total sizes of each column */ |
| 260163 | 260256 | sqlite3_stmt *pSavedRow; |
| 260164 | | - sqlite3_stmt *aStmt[13]; |
| 260257 | + sqlite3_stmt *aStmt[12]; |
| 260165 | 260258 | }; |
| 260166 | 260259 | |
| 260167 | 260260 | |
| 260168 | 260261 | #if FTS5_STMT_SCAN_ASC!=0 |
| 260169 | 260262 | # error "FTS5_STMT_SCAN_ASC mismatch" |
| | @@ -260182,11 +260275,10 @@ |
| 260182 | 260275 | #define FTS5_STMT_REPLACE_DOCSIZE 7 |
| 260183 | 260276 | #define FTS5_STMT_DELETE_DOCSIZE 8 |
| 260184 | 260277 | #define FTS5_STMT_LOOKUP_DOCSIZE 9 |
| 260185 | 260278 | #define FTS5_STMT_REPLACE_CONFIG 10 |
| 260186 | 260279 | #define FTS5_STMT_SCAN 11 |
| 260187 | | -#define FTS5_STMT_ENC_CONVERT 12 |
| 260188 | 260280 | |
| 260189 | 260281 | /* |
| 260190 | 260282 | ** Prepare the two insert statements - Fts5Storage.pInsertContent and |
| 260191 | 260283 | ** Fts5Storage.pInsertDocsize - if they have not already been prepared. |
| 260192 | 260284 | ** Return SQLITE_OK if successful, or an SQLite error code if an error |
| | @@ -260224,11 +260316,10 @@ |
| 260224 | 260316 | |
| 260225 | 260317 | "SELECT sz%s FROM %Q.'%q_docsize' WHERE id=?", /* LOOKUP_DOCSIZE */ |
| 260226 | 260318 | |
| 260227 | 260319 | "REPLACE INTO %Q.'%q_config' VALUES(?,?)", /* REPLACE_CONFIG */ |
| 260228 | 260320 | "SELECT %s FROM %s AS T", /* SCAN */ |
| 260229 | | - "SELECT substr(?, 1)", /* ENC_CONVERT */ |
| 260230 | 260321 | }; |
| 260231 | 260322 | Fts5Config *pC = p->pConfig; |
| 260232 | 260323 | char *zSql = 0; |
| 260233 | 260324 | |
| 260234 | 260325 | assert( ArraySize(azStmt)==ArraySize(p->aStmt) ); |
| | @@ -260445,40 +260536,10 @@ |
| 260445 | 260536 | } |
| 260446 | 260537 | |
| 260447 | 260538 | return rc; |
| 260448 | 260539 | } |
| 260449 | 260540 | |
| 260450 | | -/* |
| 260451 | | -** Set the value of Fts5Storage.db_enc to the db encoding. Return SQLITE_OK |
| 260452 | | -** if successful, or an SQLite error code otherwise. |
| 260453 | | -*/ |
| 260454 | | -static int fts5StorageFindDbEnc(Fts5Storage *p){ |
| 260455 | | - const char *zSql = "PRAGMA encoding"; |
| 260456 | | - sqlite3_stmt *pStmt = 0; |
| 260457 | | - int rc = SQLITE_OK; |
| 260458 | | - |
| 260459 | | - rc = sqlite3_prepare(p->pConfig->db, zSql, -1, &pStmt, 0); |
| 260460 | | - if( rc==SQLITE_OK ){ |
| 260461 | | - if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 260462 | | - static const char *aEnc[] = { |
| 260463 | | - "UTF-8", "UTF-16le", "UTF-16be" |
| 260464 | | - }; |
| 260465 | | - const char *zEnc = (const char*)sqlite3_column_text(pStmt, 0); |
| 260466 | | - int ii; |
| 260467 | | - for(ii=0; ii<ArraySize(aEnc); ii++){ |
| 260468 | | - if( sqlite3_stricmp(aEnc[ii], zEnc)==0 ){ |
| 260469 | | - p->db_enc = ii+1; |
| 260470 | | - break; |
| 260471 | | - } |
| 260472 | | - } |
| 260473 | | - } |
| 260474 | | - rc = sqlite3_finalize(pStmt); |
| 260475 | | - } |
| 260476 | | - |
| 260477 | | - return rc; |
| 260478 | | -} |
| 260479 | | - |
| 260480 | 260541 | /* |
| 260481 | 260542 | ** Open a new Fts5Index handle. If the bCreate argument is true, create |
| 260482 | 260543 | ** and initialize the underlying tables |
| 260483 | 260544 | ** |
| 260484 | 260545 | ** If successful, set *pp to point to the new object and return SQLITE_OK. |
| | @@ -260503,13 +260564,11 @@ |
| 260503 | 260564 | memset(p, 0, (size_t)nByte); |
| 260504 | 260565 | p->aTotalSize = (i64*)&p[1]; |
| 260505 | 260566 | p->pConfig = pConfig; |
| 260506 | 260567 | p->pIndex = pIndex; |
| 260507 | 260568 | |
| 260508 | | - rc = fts5StorageFindDbEnc(p); |
| 260509 | | - |
| 260510 | | - if( rc==SQLITE_OK && bCreate ){ |
| 260569 | + if( bCreate ){ |
| 260511 | 260570 | if( pConfig->eContent==FTS5_CONTENT_NORMAL |
| 260512 | 260571 | || pConfig->eContent==FTS5_CONTENT_UNINDEXED |
| 260513 | 260572 | ){ |
| 260514 | 260573 | int nDefn = 32 + pConfig->nCol*10; |
| 260515 | 260574 | char *zDefn = sqlite3_malloc64(32 + (sqlite3_int64)pConfig->nCol * 20); |
| | @@ -261175,63 +261234,10 @@ |
| 261175 | 261234 | } |
| 261176 | 261235 | |
| 261177 | 261236 | return rc; |
| 261178 | 261237 | } |
| 261179 | 261238 | |
| 261180 | | -/* |
| 261181 | | -** Argument pVal is a blob value for which the internal encoding does not |
| 261182 | | -** match the database encoding. This happens when using sqlite3_bind_blob() |
| 261183 | | -** (which always sets encoding=utf8) with a utf-16 database. The problem |
| 261184 | | -** is that fts5 is about to call sqlite3_column_text() on the value to |
| 261185 | | -** obtain text for tokenization. And the conversion between text and blob |
| 261186 | | -** must take place assuming the blob is encoded in database encoding - |
| 261187 | | -** otherwise it won't match the text extracted from the same blob if it |
| 261188 | | -** is read from the db later on. |
| 261189 | | -** |
| 261190 | | -** This function attempts to create a new value containing a copy of |
| 261191 | | -** the blob in pVal, but with the encoding set to the database encoding. |
| 261192 | | -** If successful, it sets (*ppOut) to point to the new value and returns |
| 261193 | | -** SQLITE_OK. It is the responsibility of the caller to eventually free |
| 261194 | | -** this value using sqlite3_value_free(). Or, if an error occurs, (*ppOut) |
| 261195 | | -** is set to NULL and an SQLite error code returned. |
| 261196 | | -*/ |
| 261197 | | -static int fts5EncodingFix( |
| 261198 | | - Fts5Storage *p, |
| 261199 | | - sqlite3_value *pVal, |
| 261200 | | - sqlite3_value **ppOut |
| 261201 | | -){ |
| 261202 | | - sqlite3_stmt *pStmt = 0; |
| 261203 | | - int rc = fts5StorageGetStmt( |
| 261204 | | - p, FTS5_STMT_ENC_CONVERT, &pStmt, p->pConfig->pzErrmsg |
| 261205 | | - ); |
| 261206 | | - if( rc==SQLITE_OK ){ |
| 261207 | | - sqlite3_value *pDup = 0; |
| 261208 | | - const char *pBlob = sqlite3_value_blob(pVal); |
| 261209 | | - int nBlob = sqlite3_value_bytes(pVal); |
| 261210 | | - |
| 261211 | | - sqlite3_bind_blob(pStmt, 1, pBlob, nBlob, SQLITE_STATIC); |
| 261212 | | - |
| 261213 | | - if( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 261214 | | - sqlite3_value *pX = sqlite3_column_value(pStmt, 0); |
| 261215 | | - pDup = sqlite3_value_dup(pX); |
| 261216 | | - if( pDup==0 ){ |
| 261217 | | - rc = SQLITE_NOMEM; |
| 261218 | | - }else{ |
| 261219 | | - *ppOut = pX; |
| 261220 | | - } |
| 261221 | | - } |
| 261222 | | - rc = sqlite3_reset(pStmt); |
| 261223 | | - if( rc!=SQLITE_OK ){ |
| 261224 | | - sqlite3_value_free(pDup); |
| 261225 | | - }else{ |
| 261226 | | - *ppOut = pDup; |
| 261227 | | - } |
| 261228 | | - } |
| 261229 | | - |
| 261230 | | - return rc; |
| 261231 | | -} |
| 261232 | | - |
| 261233 | 261239 | /* |
| 261234 | 261240 | ** Insert new entries into the FTS index and %_docsize table. |
| 261235 | 261241 | */ |
| 261236 | 261242 | static int sqlite3Fts5StorageIndexInsert( |
| 261237 | 261243 | Fts5Storage *p, |
| | @@ -261255,11 +261261,10 @@ |
| 261255 | 261261 | if( pConfig->abUnindexed[ctx.iCol]==0 ){ |
| 261256 | 261262 | int nText = 0; /* Size of pText in bytes */ |
| 261257 | 261263 | const char *pText = 0; /* Pointer to buffer containing text value */ |
| 261258 | 261264 | int nLoc = 0; /* Size of pText in bytes */ |
| 261259 | 261265 | const char *pLoc = 0; /* Pointer to buffer containing text value */ |
| 261260 | | - sqlite3_value *pFree = 0; |
| 261261 | 261266 | |
| 261262 | 261267 | sqlite3_value *pVal = apVal[ctx.iCol+2]; |
| 261263 | 261268 | if( p->pSavedRow && sqlite3_value_nochange(pVal) ){ |
| 261264 | 261269 | pVal = sqlite3_column_value(p->pSavedRow, ctx.iCol+1); |
| 261265 | 261270 | if( pConfig->eContent==FTS5_CONTENT_NORMAL && pConfig->bLocale ){ |
| | @@ -261272,19 +261277,10 @@ |
| 261272 | 261277 | } |
| 261273 | 261278 | |
| 261274 | 261279 | if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){ |
| 261275 | 261280 | rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc); |
| 261276 | 261281 | }else{ |
| 261277 | | - if( sqlite3_value_type(pVal)==SQLITE_BLOB |
| 261278 | | - && sqlite3_value_encoding(pVal)!=p->db_enc |
| 261279 | | - ){ |
| 261280 | | - rc = fts5EncodingFix(p, pVal, &pFree); |
| 261281 | | - if( pFree ){ |
| 261282 | | - assert( rc==SQLITE_OK ); |
| 261283 | | - pVal = pFree; |
| 261284 | | - } |
| 261285 | | - } |
| 261286 | 261282 | pText = (const char*)sqlite3_value_text(pVal); |
| 261287 | 261283 | nText = sqlite3_value_bytes(pVal); |
| 261288 | 261284 | } |
| 261289 | 261285 | |
| 261290 | 261286 | if( rc==SQLITE_OK ){ |
| | @@ -261293,13 +261289,10 @@ |
| 261293 | 261289 | FTS5_TOKENIZE_DOCUMENT, pText, nText, (void*)&ctx, |
| 261294 | 261290 | fts5StorageInsertCallback |
| 261295 | 261291 | ); |
| 261296 | 261292 | sqlite3Fts5ClearLocale(pConfig); |
| 261297 | 261293 | } |
| 261298 | | - if( pFree ){ |
| 261299 | | - sqlite3_value_free(pFree); |
| 261300 | | - } |
| 261301 | 261294 | } |
| 261302 | 261295 | sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol); |
| 261303 | 261296 | p->aTotalSize[ctx.iCol] += (i64)ctx.szCol; |
| 261304 | 261297 | } |
| 261305 | 261298 | p->nTotalRow++; |
| 261306 | 261299 | |