Fossil SCM

Update to the latest SQLite and rig Fossil to use sqlite3_atof() if that interface is available. When compiling with an older SQLite, it falls back to using atof().

drh 2026-03-23 13:49 trunk
Commit cb89386af5d1b9278ca589802d1b0fd93b00363646d4e885cce4095fee2e2a55
+1 -2
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -40,10 +40,11 @@
4040
unsigned char bBorder; /* Show outer border in Box and Table styles */
4141
short int nWrap; /* Wrap columns wider than this */
4242
short int nScreenWidth; /* Maximum overall table width */
4343
short int nLineLimit; /* Maximum number of lines for any row */
4444
short int nTitleLimit; /* Maximum number of characters in a title */
45
+ unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
4546
int nCharLimit; /* Maximum number of characters in a cell */
4647
int nWidth; /* Number of entries in aWidth[] */
4748
int nAlign; /* Number of entries in aAlignment[] */
4849
short int *aWidth; /* Column widths */
4950
unsigned char *aAlign; /* Column alignments */
@@ -54,12 +55,10 @@
5455
char *(*xRender)(void*,sqlite3_value*); /* Render a value */
5556
int (*xWrite)(void*,const char*,sqlite3_int64); /* Write output */
5657
void *pRenderArg; /* First argument to the xRender callback */
5758
void *pWriteArg; /* First argument to the xWrite callback */
5859
char **pzOutput; /* Storage location for output string */
59
- /* Fields below are only available if iVersion>=2 */
60
- unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
6160
/* Additional fields may be added in the future */
6261
};
6362
6463
/*
6564
** Interfaces
6665
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -40,10 +40,11 @@
40 unsigned char bBorder; /* Show outer border in Box and Table styles */
41 short int nWrap; /* Wrap columns wider than this */
42 short int nScreenWidth; /* Maximum overall table width */
43 short int nLineLimit; /* Maximum number of lines for any row */
44 short int nTitleLimit; /* Maximum number of characters in a title */
 
45 int nCharLimit; /* Maximum number of characters in a cell */
46 int nWidth; /* Number of entries in aWidth[] */
47 int nAlign; /* Number of entries in aAlignment[] */
48 short int *aWidth; /* Column widths */
49 unsigned char *aAlign; /* Column alignments */
@@ -54,12 +55,10 @@
54 char *(*xRender)(void*,sqlite3_value*); /* Render a value */
55 int (*xWrite)(void*,const char*,sqlite3_int64); /* Write output */
56 void *pRenderArg; /* First argument to the xRender callback */
57 void *pWriteArg; /* First argument to the xWrite callback */
58 char **pzOutput; /* Storage location for output string */
59 /* Fields below are only available if iVersion>=2 */
60 unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
61 /* Additional fields may be added in the future */
62 };
63
64 /*
65 ** Interfaces
66
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -40,10 +40,11 @@
40 unsigned char bBorder; /* Show outer border in Box and Table styles */
41 short int nWrap; /* Wrap columns wider than this */
42 short int nScreenWidth; /* Maximum overall table width */
43 short int nLineLimit; /* Maximum number of lines for any row */
44 short int nTitleLimit; /* Maximum number of characters in a title */
45 unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
46 int nCharLimit; /* Maximum number of characters in a cell */
47 int nWidth; /* Number of entries in aWidth[] */
48 int nAlign; /* Number of entries in aAlignment[] */
49 short int *aWidth; /* Column widths */
50 unsigned char *aAlign; /* Column alignments */
@@ -54,12 +55,10 @@
55 char *(*xRender)(void*,sqlite3_value*); /* Render a value */
56 int (*xWrite)(void*,const char*,sqlite3_int64); /* Write output */
57 void *pRenderArg; /* First argument to the xRender callback */
58 void *pWriteArg; /* First argument to the xWrite callback */
59 char **pzOutput; /* Storage location for output string */
 
 
60 /* Additional fields may be added in the future */
61 };
62
63 /*
64 ** Interfaces
65
+14 -12
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -136,10 +136,11 @@
136136
#include <stdlib.h>
137137
#include <string.h>
138138
#include <stdio.h>
139139
#include <assert.h>
140140
#include <math.h>
141
+#include <stdint.h>
141142
#include "sqlite3.h"
142143
typedef sqlite3_int64 i64;
143144
typedef sqlite3_uint64 u64;
144145
typedef unsigned char u8;
145146
#include <ctype.h>
@@ -698,10 +699,11 @@
698699
unsigned char bBorder; /* Show outer border in Box and Table styles */
699700
short int nWrap; /* Wrap columns wider than this */
700701
short int nScreenWidth; /* Maximum overall table width */
701702
short int nLineLimit; /* Maximum number of lines for any row */
702703
short int nTitleLimit; /* Maximum number of characters in a title */
704
+ unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
703705
int nCharLimit; /* Maximum number of characters in a cell */
704706
int nWidth; /* Number of entries in aWidth[] */
705707
int nAlign; /* Number of entries in aAlignment[] */
706708
short int *aWidth; /* Column widths */
707709
unsigned char *aAlign; /* Column alignments */
@@ -712,12 +714,10 @@
712714
char *(*xRender)(void*,sqlite3_value*); /* Render a value */
713715
int (*xWrite)(void*,const char*,sqlite3_int64); /* Write output */
714716
void *pRenderArg; /* First argument to the xRender callback */
715717
void *pWriteArg; /* First argument to the xWrite callback */
716718
char **pzOutput; /* Storage location for output string */
717
- /* Fields below are only available if iVersion>=2 */
718
- unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
719719
/* Additional fields may be added in the future */
720720
};
721721
722722
/*
723723
** Interfaces
@@ -3425,11 +3425,11 @@
34253425
sqlite3_str_append(p->pOut, "\n</TR>\n", 7);
34263426
qrfWrite(p);
34273427
break;
34283428
}
34293429
case QRF_STYLE_Insert: {
3430
- unsigned int mxIns = p->spec.iVersion>=2 ? p->spec.nMultiInsert : 0;
3430
+ unsigned int mxIns = p->spec.nMultiInsert;
34313431
int szStart = sqlite3_str_length(p->pOut);
34323432
if( p->u.nIns==0 || p->u.nIns>=mxIns ){
34333433
if( p->u.nIns ){
34343434
sqlite3_str_append(p->pOut, ";\n", 2);
34353435
p->u.nIns = 0;
@@ -3573,11 +3573,11 @@
35733573
char **pzErr /* Write errors here */
35743574
){
35753575
size_t sz; /* Size of pSpec[], based on pSpec->iVersion */
35763576
memset(p, 0, sizeof(*p));
35773577
p->pzErr = pzErr;
3578
- if( pSpec->iVersion>2 ){
3578
+ if( pSpec->iVersion>1 ){
35793579
qrfError(p, SQLITE_ERROR,
35803580
"unusable sqlite3_qrf_spec.iVersion (%d)",
35813581
pSpec->iVersion);
35823582
return;
35833583
}
@@ -24848,11 +24848,11 @@
2484824848
free(p->spec.zColumnSep);
2484924849
free(p->spec.zRowSep);
2485024850
free(p->spec.zTableName);
2485124851
free(p->spec.zNull);
2485224852
memset(p, 0, sizeof(*p));
24853
- p->spec.iVersion = 2;
24853
+ p->spec.iVersion = 1;
2485424854
p->autoExplain = autoExplain;
2485524855
}
2485624856
2485724857
/*
2485824858
** Duplicate Mode pSrc into pDest. pDest is assumed to be
@@ -24964,11 +24964,11 @@
2496424964
/*
2496524965
** Set the mode to the default. It assumed that the mode has
2496624966
** already been freed and zeroed prior to calling this routine.
2496724967
*/
2496824968
static void modeDefault(ShellState *p){
24969
- p->mode.spec.iVersion = 2;
24969
+ p->mode.spec.iVersion = 1;
2497024970
p->mode.autoExplain = 1;
2497124971
if( stdin_is_interactive || stdout_is_console ){
2497224972
modeChange(p, MODE_TTY);
2497324973
}else{
2497424974
modeChange(p, MODE_BATCH);
@@ -26516,14 +26516,16 @@
2651626516
*pzErrMsg = NULL;
2651726517
}
2651826518
memcpy(&spec, &pArg->mode.spec, sizeof(spec));
2651926519
spec.xWrite = shellWriteQR;
2652026520
spec.pWriteArg = (void*)pArg;
26521
- if( pArg->mode.eMode==MODE_Insert && ShellHasFlag(pArg, SHFLG_PreserveRowid) ){
26521
+ if( pArg->mode.eMode==MODE_Insert && ShellHasFlag(pArg,SHFLG_PreserveRowid) ){
2652226522
spec.bTitles = QRF_SW_On;
2652326523
}
26524
- assert( pArg->mode.eMode>=0 && pArg->mode.eMode<ArraySize(aModeInfo) );
26524
+ /* ,- This is true, but it is omitted
26525
+ ** vvvvvvvvvvvvvvvvvvv ----- to avoid compiler warnings. */
26526
+ assert( /*pArg->mode.eMode>=0 &&*/ pArg->mode.eMode<ArraySize(aModeInfo) );
2652526527
eStyle = aModeInfo[pArg->mode.eMode].eStyle;
2652626528
if( pArg->mode.bAutoScreenWidth ){
2652726529
spec.nScreenWidth = shellScreenWidth();
2652826530
}
2652926531
if( spec.eBlob==QRF_BLOB_Auto ){
@@ -31331,13 +31333,13 @@
3133131333
int eH = pI->eHdr;
3133231334
3133331335
/* Variable "v" is the truth table that will determine the answer
3133431336
**
3133531337
** Actual encoding is different from default
31336
- ** vvvvvvvv */
31337
- sqlite3_uint64 v = 0x0133013311220102;
31338
- /* ^^^^ ^^^^
31338
+ ** vvvvvvvv */
31339
+ sqlite3_uint64 v = UINT64_C(0x0133013311220102);
31340
+ /* ^^^^ ^^^^
3133931341
** Upper 2-byte groups for when ON/OFF disagrees with
3134031342
** the default. */
3134131343
3134231344
if( bH==0 ) return 0; /* Header not appliable. Ex: off, count */
3134331345
@@ -33860,11 +33862,11 @@
3386033862
if( i==nArg-1 ){
3386133863
dotCmdError(p, i, "missing argument", 0);
3386233864
return 1;
3386333865
}
3386433866
i++;
33865
- p->tmProgress = atof(azArg[i]);
33867
+ p->tmProgress = sqlite3_atof(azArg[i]);
3386633868
if( p->tmProgress>0.0 ){
3386733869
p->flgProgress = SHELL_PROGRESS_QUIET|SHELL_PROGRESS_TMOUT;
3386833870
if( nn==0 ) nn = 100;
3386933871
}
3387033872
continue;
3387133873
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -136,10 +136,11 @@
136 #include <stdlib.h>
137 #include <string.h>
138 #include <stdio.h>
139 #include <assert.h>
140 #include <math.h>
 
141 #include "sqlite3.h"
142 typedef sqlite3_int64 i64;
143 typedef sqlite3_uint64 u64;
144 typedef unsigned char u8;
145 #include <ctype.h>
@@ -698,10 +699,11 @@
698 unsigned char bBorder; /* Show outer border in Box and Table styles */
699 short int nWrap; /* Wrap columns wider than this */
700 short int nScreenWidth; /* Maximum overall table width */
701 short int nLineLimit; /* Maximum number of lines for any row */
702 short int nTitleLimit; /* Maximum number of characters in a title */
 
703 int nCharLimit; /* Maximum number of characters in a cell */
704 int nWidth; /* Number of entries in aWidth[] */
705 int nAlign; /* Number of entries in aAlignment[] */
706 short int *aWidth; /* Column widths */
707 unsigned char *aAlign; /* Column alignments */
@@ -712,12 +714,10 @@
712 char *(*xRender)(void*,sqlite3_value*); /* Render a value */
713 int (*xWrite)(void*,const char*,sqlite3_int64); /* Write output */
714 void *pRenderArg; /* First argument to the xRender callback */
715 void *pWriteArg; /* First argument to the xWrite callback */
716 char **pzOutput; /* Storage location for output string */
717 /* Fields below are only available if iVersion>=2 */
718 unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
719 /* Additional fields may be added in the future */
720 };
721
722 /*
723 ** Interfaces
@@ -3425,11 +3425,11 @@
3425 sqlite3_str_append(p->pOut, "\n</TR>\n", 7);
3426 qrfWrite(p);
3427 break;
3428 }
3429 case QRF_STYLE_Insert: {
3430 unsigned int mxIns = p->spec.iVersion>=2 ? p->spec.nMultiInsert : 0;
3431 int szStart = sqlite3_str_length(p->pOut);
3432 if( p->u.nIns==0 || p->u.nIns>=mxIns ){
3433 if( p->u.nIns ){
3434 sqlite3_str_append(p->pOut, ";\n", 2);
3435 p->u.nIns = 0;
@@ -3573,11 +3573,11 @@
3573 char **pzErr /* Write errors here */
3574 ){
3575 size_t sz; /* Size of pSpec[], based on pSpec->iVersion */
3576 memset(p, 0, sizeof(*p));
3577 p->pzErr = pzErr;
3578 if( pSpec->iVersion>2 ){
3579 qrfError(p, SQLITE_ERROR,
3580 "unusable sqlite3_qrf_spec.iVersion (%d)",
3581 pSpec->iVersion);
3582 return;
3583 }
@@ -24848,11 +24848,11 @@
24848 free(p->spec.zColumnSep);
24849 free(p->spec.zRowSep);
24850 free(p->spec.zTableName);
24851 free(p->spec.zNull);
24852 memset(p, 0, sizeof(*p));
24853 p->spec.iVersion = 2;
24854 p->autoExplain = autoExplain;
24855 }
24856
24857 /*
24858 ** Duplicate Mode pSrc into pDest. pDest is assumed to be
@@ -24964,11 +24964,11 @@
24964 /*
24965 ** Set the mode to the default. It assumed that the mode has
24966 ** already been freed and zeroed prior to calling this routine.
24967 */
24968 static void modeDefault(ShellState *p){
24969 p->mode.spec.iVersion = 2;
24970 p->mode.autoExplain = 1;
24971 if( stdin_is_interactive || stdout_is_console ){
24972 modeChange(p, MODE_TTY);
24973 }else{
24974 modeChange(p, MODE_BATCH);
@@ -26516,14 +26516,16 @@
26516 *pzErrMsg = NULL;
26517 }
26518 memcpy(&spec, &pArg->mode.spec, sizeof(spec));
26519 spec.xWrite = shellWriteQR;
26520 spec.pWriteArg = (void*)pArg;
26521 if( pArg->mode.eMode==MODE_Insert && ShellHasFlag(pArg, SHFLG_PreserveRowid) ){
26522 spec.bTitles = QRF_SW_On;
26523 }
26524 assert( pArg->mode.eMode>=0 && pArg->mode.eMode<ArraySize(aModeInfo) );
 
 
26525 eStyle = aModeInfo[pArg->mode.eMode].eStyle;
26526 if( pArg->mode.bAutoScreenWidth ){
26527 spec.nScreenWidth = shellScreenWidth();
26528 }
26529 if( spec.eBlob==QRF_BLOB_Auto ){
@@ -31331,13 +31333,13 @@
31331 int eH = pI->eHdr;
31332
31333 /* Variable "v" is the truth table that will determine the answer
31334 **
31335 ** Actual encoding is different from default
31336 ** vvvvvvvv */
31337 sqlite3_uint64 v = 0x0133013311220102;
31338 /* ^^^^ ^^^^
31339 ** Upper 2-byte groups for when ON/OFF disagrees with
31340 ** the default. */
31341
31342 if( bH==0 ) return 0; /* Header not appliable. Ex: off, count */
31343
@@ -33860,11 +33862,11 @@
33860 if( i==nArg-1 ){
33861 dotCmdError(p, i, "missing argument", 0);
33862 return 1;
33863 }
33864 i++;
33865 p->tmProgress = atof(azArg[i]);
33866 if( p->tmProgress>0.0 ){
33867 p->flgProgress = SHELL_PROGRESS_QUIET|SHELL_PROGRESS_TMOUT;
33868 if( nn==0 ) nn = 100;
33869 }
33870 continue;
33871
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -136,10 +136,11 @@
136 #include <stdlib.h>
137 #include <string.h>
138 #include <stdio.h>
139 #include <assert.h>
140 #include <math.h>
141 #include <stdint.h>
142 #include "sqlite3.h"
143 typedef sqlite3_int64 i64;
144 typedef sqlite3_uint64 u64;
145 typedef unsigned char u8;
146 #include <ctype.h>
@@ -698,10 +699,11 @@
699 unsigned char bBorder; /* Show outer border in Box and Table styles */
700 short int nWrap; /* Wrap columns wider than this */
701 short int nScreenWidth; /* Maximum overall table width */
702 short int nLineLimit; /* Maximum number of lines for any row */
703 short int nTitleLimit; /* Maximum number of characters in a title */
704 unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
705 int nCharLimit; /* Maximum number of characters in a cell */
706 int nWidth; /* Number of entries in aWidth[] */
707 int nAlign; /* Number of entries in aAlignment[] */
708 short int *aWidth; /* Column widths */
709 unsigned char *aAlign; /* Column alignments */
@@ -712,12 +714,10 @@
714 char *(*xRender)(void*,sqlite3_value*); /* Render a value */
715 int (*xWrite)(void*,const char*,sqlite3_int64); /* Write output */
716 void *pRenderArg; /* First argument to the xRender callback */
717 void *pWriteArg; /* First argument to the xWrite callback */
718 char **pzOutput; /* Storage location for output string */
 
 
719 /* Additional fields may be added in the future */
720 };
721
722 /*
723 ** Interfaces
@@ -3425,11 +3425,11 @@
3425 sqlite3_str_append(p->pOut, "\n</TR>\n", 7);
3426 qrfWrite(p);
3427 break;
3428 }
3429 case QRF_STYLE_Insert: {
3430 unsigned int mxIns = p->spec.nMultiInsert;
3431 int szStart = sqlite3_str_length(p->pOut);
3432 if( p->u.nIns==0 || p->u.nIns>=mxIns ){
3433 if( p->u.nIns ){
3434 sqlite3_str_append(p->pOut, ";\n", 2);
3435 p->u.nIns = 0;
@@ -3573,11 +3573,11 @@
3573 char **pzErr /* Write errors here */
3574 ){
3575 size_t sz; /* Size of pSpec[], based on pSpec->iVersion */
3576 memset(p, 0, sizeof(*p));
3577 p->pzErr = pzErr;
3578 if( pSpec->iVersion>1 ){
3579 qrfError(p, SQLITE_ERROR,
3580 "unusable sqlite3_qrf_spec.iVersion (%d)",
3581 pSpec->iVersion);
3582 return;
3583 }
@@ -24848,11 +24848,11 @@
24848 free(p->spec.zColumnSep);
24849 free(p->spec.zRowSep);
24850 free(p->spec.zTableName);
24851 free(p->spec.zNull);
24852 memset(p, 0, sizeof(*p));
24853 p->spec.iVersion = 1;
24854 p->autoExplain = autoExplain;
24855 }
24856
24857 /*
24858 ** Duplicate Mode pSrc into pDest. pDest is assumed to be
@@ -24964,11 +24964,11 @@
24964 /*
24965 ** Set the mode to the default. It assumed that the mode has
24966 ** already been freed and zeroed prior to calling this routine.
24967 */
24968 static void modeDefault(ShellState *p){
24969 p->mode.spec.iVersion = 1;
24970 p->mode.autoExplain = 1;
24971 if( stdin_is_interactive || stdout_is_console ){
24972 modeChange(p, MODE_TTY);
24973 }else{
24974 modeChange(p, MODE_BATCH);
@@ -26516,14 +26516,16 @@
26516 *pzErrMsg = NULL;
26517 }
26518 memcpy(&spec, &pArg->mode.spec, sizeof(spec));
26519 spec.xWrite = shellWriteQR;
26520 spec.pWriteArg = (void*)pArg;
26521 if( pArg->mode.eMode==MODE_Insert && ShellHasFlag(pArg,SHFLG_PreserveRowid) ){
26522 spec.bTitles = QRF_SW_On;
26523 }
26524 /* ,- This is true, but it is omitted
26525 ** vvvvvvvvvvvvvvvvvvv ----- to avoid compiler warnings. */
26526 assert( /*pArg->mode.eMode>=0 &&*/ pArg->mode.eMode<ArraySize(aModeInfo) );
26527 eStyle = aModeInfo[pArg->mode.eMode].eStyle;
26528 if( pArg->mode.bAutoScreenWidth ){
26529 spec.nScreenWidth = shellScreenWidth();
26530 }
26531 if( spec.eBlob==QRF_BLOB_Auto ){
@@ -31331,13 +31333,13 @@
31333 int eH = pI->eHdr;
31334
31335 /* Variable "v" is the truth table that will determine the answer
31336 **
31337 ** Actual encoding is different from default
31338 ** vvvvvvvv */
31339 sqlite3_uint64 v = UINT64_C(0x0133013311220102);
31340 /* ^^^^ ^^^^
31341 ** Upper 2-byte groups for when ON/OFF disagrees with
31342 ** the default. */
31343
31344 if( bH==0 ) return 0; /* Header not appliable. Ex: off, count */
31345
@@ -33860,11 +33862,11 @@
33862 if( i==nArg-1 ){
33863 dotCmdError(p, i, "missing argument", 0);
33864 return 1;
33865 }
33866 i++;
33867 p->tmProgress = sqlite3_atof(azArg[i]);
33868 if( p->tmProgress>0.0 ){
33869 p->flgProgress = SHELL_PROGRESS_QUIET|SHELL_PROGRESS_TMOUT;
33870 if( nn==0 ) nn = 100;
33871 }
33872 continue;
33873
+355 -239
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 5c237f1f863a32cf229010d2024d0d1e76a0 with changes in files:
21
+** 276c350313a1ac2ebc70c1e8e50ed4baecd4 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.53.0"
471471
#define SQLITE_VERSION_NUMBER 3053000
472
-#define SQLITE_SOURCE_ID "2026-03-18 22:31:56 5c237f1f863a32cf229010d2024d0d1e76a07a4d8b9492b26503b959f1c32485"
472
+#define SQLITE_SOURCE_ID "2026-03-23 13:00:56 276c350313a1ac2ebc70c1e8e50ed4baecd4be4d4c93ba04cf5e0078da18700e"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-03-18T22:31:56.220Z"
475
+#define SQLITE_SCM_DATETIME "2026-03-23T13:00:56.709Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -3549,10 +3549,32 @@
35493549
SQLITE_API char *sqlite3_mprintf(const char*,...);
35503550
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
35513551
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
35523552
SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
35533553
3554
+/*
3555
+** CAPI3REF: Text-to-float conversion
3556
+**
3557
+** The sqlite3_atof(X) interface returns a "double" derived from the
3558
+** text representation of a floating point value in X.
3559
+** This interface provides applications with access to the
3560
+** same text&rarr;float conversion routine used by SQLite for SQL parsing
3561
+** and type coercion. The sqlite3_atof(X) routine works like the standard
3562
+** C-library atof(X) routine with the following exceptions:
3563
+**
3564
+** <ul>
3565
+** <li> Parsing of the input X is strict. If anything about X
3566
+** is not well-formed, 0.0 is returned.
3567
+** <li> Special values such like "INF", "INFINITY", and "NAN" are not
3568
+** recognized.
3569
+** <li> Hexadecimal floating point literals are not recognized.
3570
+** <li> The current locale is ignored. The radix character is always ".".
3571
+** <li> The sqlite3_atof() interface does not set errno.
3572
+** </ul>
3573
+*/
3574
+SQLITE_API double sqlite3_atof(const char*);
3575
+
35543576
/*
35553577
** CAPI3REF: Memory Allocation Subsystem
35563578
**
35573579
** The SQLite core uses these three routines for all of its own
35583580
** internal memory allocation needs. "Core" in the previous sentence
@@ -24653,11 +24675,11 @@
2465324675
SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
2465424676
SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double);
2465524677
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*);
2465624678
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
2465724679
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
24658
-SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem*, int*);
24680
+SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem*, double*);
2465924681
SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
2466024682
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
2466124683
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
2466224684
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
2466324685
SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
@@ -36551,10 +36573,24 @@
3655136573
** into *pLo. Return the upper 64 bits of A*B.
3655236574
**
3655336575
** The lower 64 bits of A*B are discarded.
3655436576
*/
3655536577
static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){
36578
+#if (defined(__GNUC__) || defined(__clang__)) \
36579
+ && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv))
36580
+ __uint128_t r = (__uint128_t)a * b;
36581
+ r += ((__uint128_t)aLo * b) >> 32;
36582
+ *pLo = (r>>32)&0xffffffff;
36583
+ return r>>64;
36584
+#elif defined(_MSC_VER) && defined(_M_X64)
36585
+ u64 r1_hi = __umulh(a,b);
36586
+ u64 r1_lo = a*b;
36587
+ u64 r2 = (__umulh((u64)aLo,b)<<32) + ((aLo*b)>>32);
36588
+ r1_hi += _addcarry_u64(0, r1_lo, r2, &r1_lo);
36589
+ *pLo = r1_lo>>32;
36590
+ return r1_hi;
36591
+#else
3655636592
u64 x2 = a>>32;
3655736593
u64 x1 = a&0xffffffff;
3655836594
u64 x0 = aLo;
3655936595
u64 y1 = b>>32;
3656036596
u64 y0 = b&0xffffffff;
@@ -36572,10 +36608,11 @@
3657236608
(x0y0 >>32);
3657336609
r2 += r1>>32;
3657436610
r3 += r2>>32;
3657536611
*pLo = r2&0xffffffff;
3657636612
return (r4<<32) + r3;
36613
+#endif
3657736614
}
3657836615
3657936616
/*
3658036617
** Return a u64 with the N-th bit set.
3658136618
*/
@@ -36801,10 +36838,13 @@
3680136838
*pP = -p;
3680236839
}
3680336840
3680436841
/*
3680536842
** Return an IEEE754 floating point value that approximates d*pow(10,p).
36843
+**
36844
+** The (current) algorithm is adapted from the work of Ross Cox at
36845
+** https://github.com/rsc/fpfmt
3680636846
*/
3680736847
static double sqlite3Fp10Convert2(u64 d, int p){
3680836848
int b, lp, e, adj, s;
3680936849
u32 pwr10l, mid1;
3681036850
u64 pwr10h, x, hi, lo, sticky, u, m;
@@ -36852,18 +36892,21 @@
3685236892
** The string z[] is an text representation of a real number.
3685336893
** Convert this string to a double and write it into *pResult.
3685436894
**
3685536895
** z[] must be UTF-8 and zero-terminated.
3685636896
**
36857
-** Return TRUE if the result is a valid real number (or integer) and FALSE
36858
-** if the string is empty or contains extraneous text. More specifically
36859
-** return
36897
+** Return positive if the result is a valid real number (or integer) and
36898
+** zero or negative if the string is empty or contains extraneous text.
36899
+** More specifically:
36900
+**
3686036901
** 1 => The input string is a pure integer
3686136902
** 2 or more => The input has a decimal point or eNNN clause
36862
-** 0 or less => The input string is not a valid number
36863
-** -1 => Not a valid number, but has a valid prefix which
36864
-** includes a decimal point and/or an eNNN clause
36903
+** 0 or less => The input string is not well-formed
36904
+** -1 => The input is not well-formed, but it does begin
36905
+** with a well-formed floating-point literal (with
36906
+** a "." or a "eNNN" suffix or both) followed by
36907
+** other extraneous text.
3686536908
**
3686636909
** Valid numbers are in one of these formats:
3686736910
**
3686836911
** [+-]digits[E[+-]digits]
3686936912
** [+-]digits.[digits][E[+-]digits]
@@ -36870,120 +36913,142 @@
3687036913
** [+-].digits[E[+-]digits]
3687136914
**
3687236915
** Leading and trailing whitespace is ignored for the purpose of determining
3687336916
** validity.
3687436917
**
36875
-** If some prefix of the input string is a valid number, this routine
36876
-** returns FALSE but it still converts the prefix and writes the result
36877
-** into *pResult.
36918
+** Algorithm sketch: Compute an unsigned 64-bit integer s and a base-10
36919
+** exponent d such that the value encoding by the input is s*pow(10,d).
36920
+** Then invoke sqlite3Fp10Convert2() to calculated the closest possible
36921
+** IEEE754 double. The sign is added back afterwards, if the input string
36922
+** starts with a "-". The use of an unsigned 64-bit s mantissa means that
36923
+** only about the first 19 significant digits of the input can contribute
36924
+** to the result. This can result in suboptimal rounding decisions when
36925
+** correct rounding requires more than 19 input digits. For example,
36926
+** this routine renders "3500000000000000.2500001" as
36927
+** 3500000000000000.0 instead of 3500000000000000.5 because the decision
36928
+** to round up instead of using banker's rounding to round down is determined
36929
+** by the 23rd significant digit, which this routine ignores. It is not
36930
+** possible to do better without some kind of BigNum.
3687836931
*/
36879
-#if defined(_MSC_VER)
36880
-#pragma warning(disable : 4756)
36881
-#endif
36882
-SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
36932
+SQLITE_PRIVATE int sqlite3AtoF(const char *zIn, double *pResult){
3688336933
#ifndef SQLITE_OMIT_FLOATING_POINT
36884
- /* sign * significand * (10 ^ (esign * exponent)) */
36885
- int neg = 0; /* True for a negative value */
36886
- u64 s = 0; /* mantissa */
36887
- int d = 0; /* Value is s * pow(10,d) */
36888
- int nDigit = 0; /* Number of digits processed */
36889
- int eType = 1; /* 1: pure integer, 2+: fractional */
36890
-
36891
- *pResult = 0.0; /* Default return value, in case of an error */
36892
-
36893
- /* skip leading spaces */
36894
- while( sqlite3Isspace(*z) ) z++;
36895
-
36896
- /* get sign of significand */
36897
- if( *z=='-' ){
36934
+ const unsigned char *z = (const unsigned char*)zIn;
36935
+ int neg = 0; /* True for a negative value */
36936
+ u64 s = 0; /* mantissa */
36937
+ int d = 0; /* Value is s * pow(10,d) */
36938
+ int seenDigit = 0; /* true if any digits seen */
36939
+ int seenFP = 0; /* True if we've seen a "." or a "e" */
36940
+ unsigned v; /* Value of a single digit */
36941
+
36942
+ start_of_text:
36943
+ if( (v = (unsigned)z[0] - '0')<10 ){
36944
+ parse_integer_part:
36945
+ seenDigit = 1;
36946
+ s = v;
36947
+ z++;
36948
+ while( (v = (unsigned)z[0] - '0')<10 ){
36949
+ s = s*10 + v;
36950
+ z++;
36951
+ if( s>=(LARGEST_INT64-9)/10 ){
36952
+ while( sqlite3Isdigit(z[0]) ){ z++; d++; }
36953
+ break;
36954
+ }
36955
+ }
36956
+ }else if( z[0]=='-' ){
3689836957
neg = 1;
3689936958
z++;
36900
- }else if( *z=='+' ){
36959
+ if( (v = (unsigned)z[0] - '0')<10 ) goto parse_integer_part;
36960
+ }else if( z[0]=='+' ){
3690136961
z++;
36902
- }
36903
-
36904
- /* copy max significant digits to significand */
36905
- while( sqlite3Isdigit(*z) ){
36906
- s = s*10 + (*z - '0');
36907
- z++; nDigit++;
36908
- if( s>=((LARGEST_INT64-9)/10) ){
36909
- /* skip non-significant significand digits
36910
- ** (increase exponent by d to shift decimal left) */
36911
- while( sqlite3Isdigit(*z) ){ z++; d++; }
36912
- }
36962
+ if( (v = (unsigned)z[0] - '0')<10 ) goto parse_integer_part;
36963
+ }else if( sqlite3Isspace(z[0]) ){
36964
+ do{ z++; }while( sqlite3Isspace(z[0]) );
36965
+ goto start_of_text;
36966
+ }else{
36967
+ s = 0;
3691336968
}
3691436969
3691536970
/* if decimal point is present */
3691636971
if( *z=='.' ){
3691736972
z++;
36918
- eType++;
36919
- /* copy digits from after decimal to significand
36920
- ** (decrease exponent by d to shift decimal right) */
36921
- while( sqlite3Isdigit(*z) ){
36922
- if( s<((LARGEST_INT64-9)/10) ){
36923
- s = s*10 + (*z - '0');
36924
- d--;
36925
- nDigit++;
36926
- }
36927
- z++;
36928
- }
36973
+ seenFP = 1;
36974
+ if( sqlite3Isdigit(z[0]) ){
36975
+ seenDigit = 1;
36976
+ do{
36977
+ if( s<((LARGEST_INT64-9)/10) ){
36978
+ s = s*10 + z[0] - '0';
36979
+ d--;
36980
+ }
36981
+ z++;
36982
+ }while( sqlite3Isdigit(z[0]) );
36983
+ }
36984
+ }
36985
+
36986
+ if( !seenDigit ){
36987
+ *pResult = 0.0;
36988
+ return 0;
3692936989
}
3693036990
3693136991
/* if exponent is present */
3693236992
if( *z=='e' || *z=='E' ){
36933
- int esign = 1; /* sign of exponent */
36993
+ int esign;
3693436994
z++;
36935
- eType++;
3693636995
3693736996
/* get sign of exponent */
3693836997
if( *z=='-' ){
3693936998
esign = -1;
3694036999
z++;
36941
- }else if( *z=='+' ){
36942
- z++;
37000
+ }else{
37001
+ esign = +1;
37002
+ if( *z=='+' ){
37003
+ z++;
37004
+ }
3694337005
}
3694437006
/* copy digits to exponent */
36945
- if( sqlite3Isdigit(*z) ){
36946
- int exp = *z - '0';
37007
+ if( (v = (unsigned)z[0] - '0')<10 ){
37008
+ int exp = v;
3694737009
z++;
36948
- while( sqlite3Isdigit(*z) ){
36949
- exp = exp<10000 ? (exp*10 + (*z - '0')) : 10000;
37010
+ seenFP = 1;
37011
+ while( (v = (unsigned)z[0] - '0')<10 ){
37012
+ exp = exp<10000 ? (exp*10 + v) : 10000;
3695037013
z++;
3695137014
}
3695237015
d += esign*exp;
3695337016
}else{
36954
- eType = -1;
37017
+ z--; /* Leave z[0] at 'e' or '+' or '-',
37018
+ ** so that the return is 0 or -1 */
3695537019
}
3695637020
}
3695737021
3695837022
/* skip trailing spaces */
3695937023
while( sqlite3Isspace(*z) ) z++;
3696037024
36961
- /* Zero is a special case */
36962
- if( s==0 ){
36963
- *pResult = neg ? -0.0 : +0.0;
36964
- }else{
36965
- *pResult = sqlite3Fp10Convert2(s,d);
36966
- if( neg ) *pResult = -*pResult;
36967
- assert( !sqlite3IsNaN(*pResult) );
36968
- }
37025
+ /* Convert s*pow(10,d) into real */
37026
+ *pResult = s ? sqlite3Fp10Convert2(s,d) : 0.0;
37027
+ if( neg ) *pResult = -*pResult;
37028
+ assert( !sqlite3IsNaN(*pResult) );
3696937029
3697037030
/* return true if number and no extra non-whitespace characters after */
36971
- if( z[0]==0 && nDigit>0 ){
36972
- return eType;
36973
- }else if( eType>=2 && nDigit>0 ){
36974
- return -1;
37031
+ if( z[0]==0 ){
37032
+ return seenFP+1;
37033
+ }else if( seenFP ){
37034
+ return -1; /* Prefix is a floating point number */
3697537035
}else{
36976
- return 0;
37036
+ return 0; /* Prefix is just an integer */
3697737037
}
3697837038
#else
3697937039
return !sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8);
3698037040
#endif /* SQLITE_OMIT_FLOATING_POINT */
3698137041
}
36982
-#if defined(_MSC_VER)
36983
-#pragma warning(default : 4756)
36984
-#endif
37042
+
37043
+/*
37044
+** Access to sqlite3AtoF()
37045
+*/
37046
+SQLITE_API double sqlite3_atof(const char *z){
37047
+ double r;
37048
+ return sqlite3AtoF(z,&r)>0 ? r : 0.0;
37049
+}
3698537050
3698637051
/*
3698737052
** Digit pairs used to convert a U64 or I64 into text, two digits
3698837053
** at a time.
3698937054
*/
@@ -85681,36 +85746,28 @@
8568185746
return 0;
8568285747
}
8568385748
}
8568485749
8568585750
/*
85686
-** Invoke sqlite3AtoF() on the text value of pMem and return the
85687
-** double result. If sqlite3AtoF() returns an error code, write
85688
-** that code into *pRC if (*pRC)!=NULL.
85689
-**
85690
-** The caller must ensure that pMem->db!=0 and that pMem is in
85691
-** mode MEM_Str or MEM_Blob.
85751
+** This routine implements the uncommon and slower path for
85752
+** sqlite3MemValueRC(). It is broken out into a separate
85753
+** no-inline routine so that the main routine can avoid unnecessary
85754
+** stack pushes.
8569285755
*/
85693
-SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem *pMem, int *pRC){
85694
- double val = (double)0;
85695
- int rc = 0;
85696
- assert( pMem->db!=0 );
85697
- assert( pMem->flags & (MEM_Str|MEM_Blob) );
85698
- if( pMem->z==0 ){
85699
- /* no-op */
85700
- }else if( pMem->enc==SQLITE_UTF8
85701
- && ((pMem->flags & MEM_Term)!=0 || sqlite3VdbeMemZeroTerminateIfAble(pMem))
85702
- ){
85703
- rc = sqlite3AtoF(pMem->z, &val);
85704
- }else if( pMem->n==0 ){
85705
- /* no-op */
85706
- }else if( pMem->enc==SQLITE_UTF8 ){
85756
+static SQLITE_NOINLINE int sqlite3MemRealValueRCSlowPath(
85757
+ Mem *pMem,
85758
+ double *pValue
85759
+){
85760
+ int rc = SQLITE_OK;
85761
+ *pValue = 0.0;
85762
+ if( pMem->enc==SQLITE_UTF8 ){
8570785763
char *zCopy = sqlite3DbStrNDup(pMem->db, pMem->z, pMem->n);
8570885764
if( zCopy ){
85709
- rc = sqlite3AtoF(zCopy, &val);
85765
+ rc = sqlite3AtoF(zCopy, pValue);
8571085766
sqlite3DbFree(pMem->db, zCopy);
8571185767
}
85768
+ return rc;
8571285769
}else{
8571385770
int n, i, j;
8571485771
char *zCopy;
8571585772
const char *z;
8571685773
@@ -85729,17 +85786,53 @@
8572985786
zCopy[j] = z[i+1];
8573085787
}
8573185788
}
8573285789
assert( j<=n/2 );
8573385790
zCopy[j] = 0;
85734
- rc = sqlite3AtoF(zCopy, &val);
85791
+ rc = sqlite3AtoF(zCopy, pValue);
8573585792
if( i<n ) rc = -100;
8573685793
sqlite3DbFree(pMem->db, zCopy);
8573785794
}
85795
+ return rc;
8573885796
}
85739
- if( pRC ) *pRC = rc;
85740
- return val;
85797
+}
85798
+
85799
+/*
85800
+** Invoke sqlite3AtoF() on the text value of pMem and return the
85801
+** double result. If sqlite3AtoF() returns an error code, write
85802
+** that code into *pRC if (*pRC)!=NULL.
85803
+**
85804
+** The caller must ensure that pMem->db!=0 and that pMem is in
85805
+** mode MEM_Str or MEM_Blob.
85806
+*/
85807
+SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem *pMem, double *pValue){
85808
+ assert( pMem->db!=0 );
85809
+ assert( pMem->flags & (MEM_Str|MEM_Blob) );
85810
+ if( pMem->z==0 ){
85811
+ *pValue = 0.0;
85812
+ return 0;
85813
+ }else if( pMem->enc==SQLITE_UTF8
85814
+ && ((pMem->flags & MEM_Term)!=0 || sqlite3VdbeMemZeroTerminateIfAble(pMem))
85815
+ ){
85816
+ return sqlite3AtoF(pMem->z, pValue);
85817
+ }else if( pMem->n==0 ){
85818
+ *pValue = 0.0;
85819
+ return 0;
85820
+ }else{
85821
+ return sqlite3MemRealValueRCSlowPath(pMem, pValue);
85822
+ }
85823
+}
85824
+
85825
+/*
85826
+** This routine acts as a bridge from sqlite3VdbeRealValue() to
85827
+** sqlite3VdbeRealValueRC, allowing sqlite3VdbeRealValue() to avoid
85828
+** stuffing values onto the stack.
85829
+*/
85830
+static SQLITE_NOINLINE double sqlite3MemRealValueNoRC(Mem *pMem){
85831
+ double r;
85832
+ (void)sqlite3MemRealValueRC(pMem, &r);
85833
+ return r;
8574185834
}
8574285835
8574385836
/*
8574485837
** Return the best representation of pMem that we can get into a
8574585838
** double. If pMem is already a double or an integer, return its
@@ -85754,11 +85847,11 @@
8575485847
return pMem->u.r;
8575585848
}else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
8575685849
testcase( pMem->flags & MEM_IntReal );
8575785850
return (double)pMem->u.i;
8575885851
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
85759
- return sqlite3MemRealValueRC(pMem, 0);
85852
+ return sqlite3MemRealValueNoRC(pMem);
8576085853
}else{
8576185854
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
8576285855
return (double)0;
8576385856
}
8576485857
}
@@ -85878,11 +85971,11 @@
8587885971
if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
8587985972
int rc;
8588085973
sqlite3_int64 ix;
8588185974
assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
8588285975
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85883
- pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
85976
+ rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
8588485977
if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
8588585978
|| sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
8588685979
){
8588785980
pMem->u.i = ix;
8588885981
MemSetTypeFlag(pMem, MEM_Int);
@@ -96318,11 +96411,11 @@
9631896411
*/
9631996412
static void applyNumericAffinity(Mem *pRec, int bTryForInt){
9632096413
double rValue;
9632196414
int rc;
9632296415
assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
96323
- rValue = sqlite3MemRealValueRC(pRec, &rc);
96416
+ rc = sqlite3MemRealValueRC(pRec, &rValue);
9632496417
if( rc<=0 ) return;
9632596418
if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
9632696419
pRec->flags |= MEM_Int;
9632796420
}else{
9632896421
pRec->u.r = rValue;
@@ -96436,11 +96529,11 @@
9643696529
assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
9643796530
if( ExpandBlob(pMem) ){
9643896531
pMem->u.i = 0;
9643996532
return MEM_Int;
9644096533
}
96441
- pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
96534
+ rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
9644296535
if( rc<=0 ){
9644396536
if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
9644496537
pMem->u.i = ix;
9644596538
return MEM_Int;
9644696539
}else{
@@ -110776,11 +110869,11 @@
110776110869
*/
110777110870
static int exprProbability(Expr *p){
110778110871
double r = -1.0;
110779110872
if( p->op!=TK_FLOAT ) return -1;
110780110873
assert( !ExprHasProperty(p, EP_IntValue) );
110781
- sqlite3AtoF(p->u.zToken, &r);
110874
+ r = sqlite3_atof(p->u.zToken);
110782110875
assert( r>=0.0 );
110783110876
if( r>1.0 ) return -1;
110784110877
return (int)(r*134217728.0);
110785110878
}
110786110879
@@ -116464,12 +116557,11 @@
116464116557
** z[n] character is guaranteed to be something that does not look
116465116558
** like the continuation of the number.
116466116559
*/
116467116560
static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
116468116561
if( ALWAYS(z!=0) ){
116469
- double value;
116470
- sqlite3AtoF(z, &value);
116562
+ double value = sqlite3_atof(z);
116471116563
assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116472116564
if( negateFlag ) value = -value;
116473116565
sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
116474116566
}
116475116567
}
@@ -128323,13 +128415,14 @@
128323128415
if( resizeIndexObject(pParse, pPk, nPk+nExtra) ) return;
128324128416
for(i=0, j=nPk; i<pTab->nCol; i++){
128325128417
if( !hasColumn(pPk->aiColumn, j, i)
128326128418
&& (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0
128327128419
){
128420
+ const char *zColl = sqlite3ColumnColl(&pTab->aCol[i]);
128328128421
assert( j<pPk->nColumn );
128329128422
pPk->aiColumn[j] = i;
128330
- pPk->azColl[j] = sqlite3StrBINARY;
128423
+ pPk->azColl[j] = zColl ? zColl : sqlite3StrBINARY;
128331128424
j++;
128332128425
}
128333128426
}
128334128427
assert( pPk->nColumn==j );
128335128428
assert( pTab->nNVCol<=j );
@@ -131351,138 +131444,129 @@
131351131444
sqlite3HaltConstraint(pParse, rc, onError, zMsg, P4_DYNAMIC,
131352131445
P5_ConstraintUnique);
131353131446
}
131354131447
131355131448
/*
131356
-** Check to see if pIndex uses the collating sequence pColl. Return
131357
-** true if it does and false if it does not.
131449
+** Return true if any column of pIndex uses the zColl collation
131358131450
*/
131359131451
#ifndef SQLITE_OMIT_REINDEX
131360131452
static int collationMatch(const char *zColl, Index *pIndex){
131361131453
int i;
131362131454
assert( zColl!=0 );
131363131455
for(i=0; i<pIndex->nColumn; i++){
131364131456
const char *z = pIndex->azColl[i];
131365
- assert( z!=0 || pIndex->aiColumn[i]<0 );
131366
- if( pIndex->aiColumn[i]>=0 && 0==sqlite3StrICmp(z, zColl) ){
131457
+ assert( z!=0 );
131458
+ if( 0==sqlite3StrICmp(z, zColl) ){
131367131459
return 1;
131368131460
}
131369131461
}
131370131462
return 0;
131371131463
}
131372
-#endif
131373
-
131374
-/*
131375
-** Recompute all indices of pTab that use the collating sequence pColl.
131376
-** If pColl==0 then recompute all indices of pTab.
131377
-*/
131378
-#ifndef SQLITE_OMIT_REINDEX
131379
-static void reindexTable(Parse *pParse, Table *pTab, char const *zColl){
131380
- if( !IsVirtual(pTab) ){
131381
- Index *pIndex; /* An index associated with pTab */
131382
-
131383
- for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
131384
- if( zColl==0 || collationMatch(zColl, pIndex) ){
131385
- int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
131386
- sqlite3BeginWriteOperation(pParse, 0, iDb);
131387
- sqlite3RefillIndex(pParse, pIndex, -1);
131388
- }
131389
- }
131390
- }
131391
-}
131392
-#endif
131393
-
131394
-/*
131395
-** Recompute all indices of all tables in all databases where the
131396
-** indices use the collating sequence pColl. If pColl==0 then recompute
131397
-** all indices everywhere.
131398
-*/
131399
-#ifndef SQLITE_OMIT_REINDEX
131400
-static void reindexDatabases(Parse *pParse, char const *zColl){
131401
- Db *pDb; /* A single database */
131402
- int iDb; /* The database index number */
131403
- sqlite3 *db = pParse->db; /* The database connection */
131404
- HashElem *k; /* For looping over tables in pDb */
131405
- Table *pTab; /* A table in the database */
131406
-
131407
- assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
131408
- for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
131409
- assert( pDb!=0 );
131410
- for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
131411
- pTab = (Table*)sqliteHashData(k);
131412
- reindexTable(pParse, pTab, zColl);
131413
- }
131414
- }
131415
-}
131416131464
#endif
131417131465
131418131466
/*
131419131467
** Generate code for the REINDEX command.
131420131468
**
131421131469
** REINDEX -- 1
131422131470
** REINDEX <collation> -- 2
131423
-** REINDEX ?<database>.?<tablename> -- 3
131424
-** REINDEX ?<database>.?<indexname> -- 4
131471
+** REINDEX ?<database>.?<indexname> -- 3
131472
+** REINDEX ?<database>.?<tablename> -- 4
131473
+** REINDEX EXPRESSIONS -- 5
131425131474
**
131426
-** Form 1 causes all indices in all attached databases to be rebuilt.
131427
-** Form 2 rebuilds all indices in all databases that use the named
131475
+** Form 1 causes all indexes in all attached databases to be rebuilt.
131476
+** Form 2 rebuilds all indexes in all databases that use the named
131428131477
** collating function. Forms 3 and 4 rebuild the named index or all
131429
-** indices associated with the named table.
131478
+** indexes associated with the named table, respectively. Form 5
131479
+** rebuilds all expression indexes in addition to all collations,
131480
+** indexes, or tables named "EXPRESSIONS".
131481
+**
131482
+** If the name is ambiguous such that it matches two or more of
131483
+** forms 2 through 5, then rebuild the union of all matching indexes,
131484
+** taken care to avoid rebuilding the same index more than once.
131430131485
*/
131431131486
#ifndef SQLITE_OMIT_REINDEX
131432131487
SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){
131433131488
CollSeq *pColl; /* Collating sequence to be reindexed, or NULL */
131434
- char *z; /* Name of a table or index */
131435
- const char *zDb; /* Name of the database */
131436
- Table *pTab; /* A table in the database */
131437
- Index *pIndex; /* An index associated with pTab */
131438
- int iDb; /* The database index number */
131489
+ char *z = 0; /* Name of a table or index or collation */
131490
+ const char *zDb = 0; /* Name of the database */
131491
+ int iReDb = -1; /* The database index number */
131439131492
sqlite3 *db = pParse->db; /* The database connection */
131440131493
Token *pObjName; /* Name of the table or index to be reindexed */
131494
+ int bMatch = 0; /* At least one name match */
131495
+ const char *zColl = 0; /* Rebuild indexes using this collation */
131496
+ Table *pReTab = 0; /* Rebuild all indexes of this table */
131497
+ Index *pReIndex = 0; /* Rebuild this index */
131498
+ int isExprIdx = 0; /* Rebuild all expression indexes */
131499
+ int bAll = 0; /* Rebuild all indexes */
131441131500
131442131501
/* Read the database schema. If an error occurs, leave an error message
131443131502
** and code in pParse and return NULL. */
131444131503
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
131445131504
return;
131446131505
}
131447131506
131448131507
if( pName1==0 ){
131449
- reindexDatabases(pParse, 0);
131450
- return;
131508
+ /* rebuild all indexes */
131509
+ bMatch = 1;
131510
+ bAll = 1;
131451131511
}else if( NEVER(pName2==0) || pName2->z==0 ){
131452
- char *zColl;
131453131512
assert( pName1->z );
131454
- zColl = sqlite3NameFromToken(pParse->db, pName1);
131455
- if( !zColl ) return;
131456
- pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
131457
- if( pColl ){
131458
- reindexDatabases(pParse, zColl);
131459
- sqlite3DbFree(db, zColl);
131460
- return;
131461
- }
131462
- sqlite3DbFree(db, zColl);
131463
- }
131464
- iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
131465
- if( iDb<0 ) return;
131466
- z = sqlite3NameFromToken(db, pObjName);
131467
- if( z==0 ) return;
131468
- zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
131469
- pTab = sqlite3FindTable(db, z, zDb);
131470
- if( pTab ){
131471
- reindexTable(pParse, pTab, 0);
131472
- sqlite3DbFree(db, z);
131473
- return;
131474
- }
131475
- pIndex = sqlite3FindIndex(db, z, zDb);
131476
- sqlite3DbFree(db, z);
131477
- if( pIndex ){
131478
- iDb = sqlite3SchemaToIndex(db, pIndex->pTable->pSchema);
131479
- sqlite3BeginWriteOperation(pParse, 0, iDb);
131480
- sqlite3RefillIndex(pParse, pIndex, -1);
131481
- return;
131482
- }
131483
- sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
131513
+ z = sqlite3NameFromToken(pParse->db, pName1);
131514
+ if( z==0 ) return;
131515
+ }else{
131516
+ iReDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
131517
+ if( iReDb<0 ) return;
131518
+ z = sqlite3NameFromToken(db, pObjName);
131519
+ if( z==0 ) return;
131520
+ zDb = db->aDb[iReDb].zDbSName;
131521
+ }
131522
+ if( !bAll ){
131523
+ if( zDb==0 && sqlite3StrICmp(z, "expressions")==0 ){
131524
+ isExprIdx = 1;
131525
+ bMatch = 1;
131526
+ }
131527
+ if( zDb==0 && (pColl = sqlite3FindCollSeq(db, ENC(db), z, 0))!=0 ){
131528
+ zColl = z;
131529
+ bMatch = 1;
131530
+ }
131531
+ if( zColl==0 && (pReTab = sqlite3FindTable(db, z, zDb))!=0 ){
131532
+ bMatch = 1;
131533
+ }
131534
+ if( zColl==0 && (pReIndex = sqlite3FindIndex(db, z, zDb))!=0 ){
131535
+ bMatch = 1;
131536
+ }
131537
+ }
131538
+ if( bMatch ){
131539
+ int iDb;
131540
+ HashElem *k;
131541
+ Table *pTab;
131542
+ Index *pIdx;
131543
+ Db *pDb;
131544
+ for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
131545
+ assert( pDb!=0 );
131546
+ if( iReDb>=0 && iReDb!=iDb ) continue;
131547
+ for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
131548
+ pTab = (Table*)sqliteHashData(k);
131549
+ if( IsVirtual(pTab) ) continue;
131550
+ for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
131551
+ if( bAll
131552
+ || pTab==pReTab
131553
+ || pIdx==pReIndex
131554
+ || (isExprIdx && pIdx->bHasExpr)
131555
+ || (zColl!=0 && collationMatch(zColl,pIdx))
131556
+ ){
131557
+ sqlite3BeginWriteOperation(pParse, 0, iDb);
131558
+ sqlite3RefillIndex(pParse, pIdx, -1);
131559
+ }
131560
+ } /* End loop over indexes of pTab */
131561
+ } /* End loop over tables of iDb */
131562
+ } /* End loop over databases */
131563
+ }else{
131564
+ sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
131565
+ }
131566
+ sqlite3DbFree(db, z);
131567
+ return;
131484131568
}
131485131569
#endif
131486131570
131487131571
/*
131488131572
** Return a KeyInfo structure that is appropriate for the given Index.
@@ -142129,10 +142213,12 @@
142129142213
/* Version 3.52.0 and later */
142130142214
void (*str_truncate)(sqlite3_str*,int);
142131142215
void (*str_free)(sqlite3_str*);
142132142216
int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142133142217
int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
142218
+ /* Version 3.53.0 and later */
142219
+ double (*atof)(const char*);
142134142220
};
142135142221
142136142222
/*
142137142223
** This is the function signature used for all extension entry points. It
142138142224
** is also defined in the file "loadext.c".
@@ -142472,10 +142558,12 @@
142472142558
/* Version 3.52.0 and later */
142473142559
#define sqlite3_str_truncate sqlite3_api->str_truncate
142474142560
#define sqlite3_str_free sqlite3_api->str_free
142475142561
#define sqlite3_carray_bind sqlite3_api->carray_bind
142476142562
#define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
142563
+/* Version 3.53.0 and later */
142564
+#define sqlite3_atof sqlite3_api->atof
142477142565
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142478142566
142479142567
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142480142568
/* This case when the file really is being compiled as a loadable
142481142569
** extension */
@@ -143004,15 +143092,16 @@
143004143092
/* Version 3.52.0 and later */
143005143093
sqlite3_str_truncate,
143006143094
sqlite3_str_free,
143007143095
#ifdef SQLITE_ENABLE_CARRAY
143008143096
sqlite3_carray_bind,
143009
- sqlite3_carray_bind_v2
143097
+ sqlite3_carray_bind_v2,
143010143098
#else
143099
+ 0,
143011143100
0,
143012
- 0
143013143101
#endif
143102
+ sqlite3_atof
143014143103
};
143015143104
143016143105
/* True if x is the directory separator character
143017143106
*/
143018143107
#if SQLITE_OS_WIN
@@ -172275,11 +172364,16 @@
172275172364
#endif
172276172365
ApplyCostMultiplier(pNew->rRun, pTab->costMult);
172277172366
whereLoopOutputAdjust(pWC, pNew, rSize);
172278172367
if( pSrc->fg.isSubquery ){
172279172368
if( pSrc->fg.viaCoroutine ) pNew->wsFlags |= WHERE_COROUTINE;
172280
- pNew->u.btree.pOrderBy = pSrc->u4.pSubq->pSelect->pOrderBy;
172369
+ /* Do not set btree.pOrderBy for a recursive CTE. In this case
172370
+ ** the ORDER BY clause does not determine the overall order that
172371
+ ** rows are emitted from the CTE in. */
172372
+ if( (pSrc->u4.pSubq->pSelect->selFlags & SF_Recursive)==0 ){
172373
+ pNew->u.btree.pOrderBy = pSrc->u4.pSubq->pSelect->pOrderBy;
172374
+ }
172281172375
}else if( pSrc->fg.fromExists ){
172282172376
pNew->nOut = 0;
172283172377
}
172284172378
rc = whereLoopInsert(pBuilder, pNew);
172285172379
pNew->nOut = rSize;
@@ -212773,18 +212867,19 @@
212773212867
JsonParse *pParse, /* JSONB source or NULL */
212774212868
sqlite3_context *ctx /* Where to cache */
212775212869
){
212776212870
assert( (pParse!=0)==(ctx!=0) );
212777212871
assert( ctx==0 || ctx==p->pCtx );
212872
+ jsonStringTerminate(p);
212778212873
if( p->eErr==0 ){
212779212874
int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(p->pCtx));
212780212875
if( flags & JSON_BLOB ){
212781212876
jsonReturnStringAsBlob(p);
212782212877
}else if( p->bStatic ){
212783212878
sqlite3_result_text64(p->pCtx, p->zBuf, p->nUsed,
212784212879
SQLITE_TRANSIENT, SQLITE_UTF8);
212785
- }else if( jsonStringTerminate(p) ){
212880
+ }else{
212786212881
if( pParse && pParse->bJsonIsRCStr==0 && pParse->nBlobAlloc>0 ){
212787212882
int rc;
212788212883
pParse->zJson = sqlite3RCStrRef(p->zBuf);
212789212884
pParse->nJson = p->nUsed;
212790212885
pParse->bJsonIsRCStr = 1;
@@ -212796,12 +212891,10 @@
212796212891
}
212797212892
}
212798212893
sqlite3_result_text64(p->pCtx, sqlite3RCStrRef(p->zBuf), p->nUsed,
212799212894
sqlite3RCStrUnref,
212800212895
SQLITE_UTF8);
212801
- }else{
212802
- sqlite3_result_error_nomem(p->pCtx);
212803212896
}
212804212897
}else if( p->eErr & JSTRING_OOM ){
212805212898
sqlite3_result_error_nomem(p->pCtx);
212806212899
}else if( p->eErr & JSTRING_MALFORMED ){
212807212900
sqlite3_result_error(p->pCtx, "malformed JSON", -1);
@@ -214011,16 +214104,12 @@
214011214104
** this into the JSONB format and make it the return value of the
214012214105
** SQL function.
214013214106
*/
214014214107
static void jsonReturnStringAsBlob(JsonString *pStr){
214015214108
JsonParse px;
214109
+ assert( pStr->eErr==0 );
214016214110
memset(&px, 0, sizeof(px));
214017
- jsonStringTerminate(pStr);
214018
- if( pStr->eErr ){
214019
- sqlite3_result_error_nomem(pStr->pCtx);
214020
- return;
214021
- }
214022214111
px.zJson = pStr->zBuf;
214023214112
px.nJson = pStr->nUsed;
214024214113
px.db = sqlite3_context_db_handle(pStr->pCtx);
214025214114
(void)jsonTranslateTextToBlob(&px, 0);
214026214115
if( px.oom ){
@@ -216731,11 +216820,12 @@
216731216820
JsonString *pStr;
216732216821
int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216733216822
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216734216823
if( pStr ){
216735216824
pStr->pCtx = ctx;
216736
- jsonAppendChar(pStr, ']');
216825
+ jsonAppendRawNZ(pStr, "]", 2);
216826
+ jsonStringTrimOneChar(pStr);
216737216827
if( pStr->eErr ){
216738216828
jsonReturnString(pStr, 0, 0);
216739216829
return;
216740216830
}else if( flags & JSON_BLOB ){
216741216831
jsonReturnStringAsBlob(pStr);
@@ -216854,11 +216944,12 @@
216854216944
static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
216855216945
JsonString *pStr;
216856216946
int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216857216947
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216858216948
if( pStr ){
216859
- jsonAppendChar(pStr, '}');
216949
+ jsonAppendRawNZ(pStr, "}", 2);
216950
+ jsonStringTrimOneChar(pStr);
216860216951
pStr->pCtx = ctx;
216861216952
if( pStr->eErr ){
216862216953
jsonReturnString(pStr, 0, 0);
216863216954
return;
216864216955
}else if( flags & JSON_BLOB ){
@@ -259195,11 +259286,11 @@
259195259286
#if SQLITE_VERSION_NUMBER>=3008002
259196259287
#ifndef SQLITE_CORE
259197259288
if( sqlite3_libversion_number()>=3008002 )
259198259289
#endif
259199259290
{
259200
- pIdxInfo->estimatedRows = nRow;
259291
+ pIdxInfo->estimatedRows = MAX(1, nRow);
259201259292
}
259202259293
#endif
259203259294
}
259204259295
259205259296
static int fts5UsePatternMatch(
@@ -259264,23 +259355,34 @@
259264259355
** Costs are assigned as follows:
259265259356
**
259266259357
** a) If a MATCH operator is present, the cost depends on the other
259267259358
** constraints also present. As follows:
259268259359
**
259269
-** * No other constraints: cost=1000.0
259270
-** * One rowid range constraint: cost=750.0
259271
-** * Both rowid range constraints: cost=500.0
259272
-** * An == rowid constraint: cost=100.0
259360
+** * No other constraints: cost=50000.0
259361
+** * One rowid range constraint: cost=37500.0
259362
+** * Both rowid range constraints: cost=30000.0
259363
+** * An == rowid constraint: cost=25000.0
259273259364
**
259274259365
** b) Otherwise, if there is no MATCH:
259275259366
**
259276
-** * No other constraints: cost=1000000.0
259277
-** * One rowid range constraint: cost=750000.0
259278
-** * Both rowid range constraints: cost=250000.0
259279
-** * An == rowid constraint: cost=10.0
259367
+** * No other constraints: cost=3000000.0
259368
+** * One rowid range constraints: cost=2250000.0
259369
+** * Both rowid range constraint: cost=750000.0
259370
+** * An == rowid constraint: cost=25.0
259280259371
**
259281259372
** Costs are not modified by the ORDER BY clause.
259373
+**
259374
+** The ratios used in case (a) are based on informal results obtained from
259375
+** the tool/fts5cost.tcl script. The "MATCH and ==" combination has the
259376
+** cost set quite high because the query may be a prefix query. Unless
259377
+** there is a prefix index, prefix queries with rowid constraints are much
259378
+** more expensive than non-prefix queries with rowid constraints.
259379
+**
259380
+** The estimated rows returned is set to the cost/40. For simple queries,
259381
+** experimental results show that cost/4 might be about right. But for
259382
+** more complex queries that use multiple terms the number of rows might
259383
+** be far fewer than this. So we compromise and use cost/40.
259282259384
*/
259283259385
static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
259284259386
Fts5Table *pTab = (Fts5Table*)pVTab;
259285259387
Fts5Config *pConfig = pTab->pConfig;
259286259388
const int nCol = pConfig->nCol;
@@ -259402,25 +259504,39 @@
259402259504
}
259403259505
}
259404259506
259405259507
/* Calculate the estimated cost based on the flags set in idxFlags. */
259406259508
if( bSeenEq ){
259407
- pInfo->estimatedCost = nSeenMatch ? 1000.0 : 25.0;
259408
- fts5SetUniqueFlag(pInfo);
259509
+ pInfo->estimatedCost = nSeenMatch ? 25000.0 : 25.0;
259409259510
fts5SetEstimatedRows(pInfo, 1);
259410
- }else{
259411
- if( bSeenLt && bSeenGt ){
259412
- pInfo->estimatedCost = nSeenMatch ? 5000.0 : 750000.0;
259413
- }else if( bSeenLt || bSeenGt ){
259414
- pInfo->estimatedCost = nSeenMatch ? 7500.0 : 2250000.0;
259415
- }else{
259416
- pInfo->estimatedCost = nSeenMatch ? 10000.0 : 3000000.0;
259417
- }
259418
- for(i=1; i<nSeenMatch; i++){
259419
- pInfo->estimatedCost *= 0.4;
259420
- }
259421
- fts5SetEstimatedRows(pInfo, (i64)(pInfo->estimatedCost / 4.0));
259511
+ fts5SetUniqueFlag(pInfo);
259512
+ }else{
259513
+ i64 nEstRows;
259514
+ if( nSeenMatch ){
259515
+ if( bSeenLt && bSeenGt ){
259516
+ pInfo->estimatedCost = 50000.0;
259517
+ }else if( bSeenLt || bSeenGt ){
259518
+ pInfo->estimatedCost = 37500.0;
259519
+ }else{
259520
+ pInfo->estimatedCost = 50000.0;
259521
+ }
259522
+ nEstRows = (i64)(pInfo->estimatedCost / 40.0);
259523
+ for(i=1; i<nSeenMatch; i++){
259524
+ pInfo->estimatedCost *= 2.5;
259525
+ nEstRows = nEstRows / 2;
259526
+ }
259527
+ }else{
259528
+ if( bSeenLt && bSeenGt ){
259529
+ pInfo->estimatedCost = 750000.0;
259530
+ }else if( bSeenLt || bSeenGt ){
259531
+ pInfo->estimatedCost = 2250000.0;
259532
+ }else{
259533
+ pInfo->estimatedCost = 3000000.0;
259534
+ }
259535
+ nEstRows = (i64)(pInfo->estimatedCost / 4.0);
259536
+ }
259537
+ fts5SetEstimatedRows(pInfo, nEstRows);
259422259538
}
259423259539
259424259540
pInfo->idxNum = idxFlags;
259425259541
return SQLITE_OK;
259426259542
}
@@ -262277,11 +262393,11 @@
262277262393
int nArg, /* Number of args */
262278262394
sqlite3_value **apUnused /* Function arguments */
262279262395
){
262280262396
assert( nArg==0 );
262281262397
UNUSED_PARAM2(nArg, apUnused);
262282
- sqlite3_result_text(pCtx, "fts5: 2026-03-18 15:40:26 971aa34b3fd86ba30fe170886d9f83c17159b1638c4bd4fb6cdef79b1c9a88e2", -1, SQLITE_TRANSIENT);
262398
+ sqlite3_result_text(pCtx, "fts5: 2026-03-23 12:25:52 1553a60506fa29b5f00535ae0f7aeb8cc94ebe84015386b3248fd8491108fc60", -1, SQLITE_TRANSIENT);
262283262399
}
262284262400
262285262401
/*
262286262402
** Implementation of fts5_locale(LOCALE, TEXT) function.
262287262403
**
262288262404
--- 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 ** 5c237f1f863a32cf229010d2024d0d1e76a0 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-18 22:31:56 5c237f1f863a32cf229010d2024d0d1e76a07a4d8b9492b26503b959f1c32485"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-03-18T22:31:56.220Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -3549,10 +3549,32 @@
3549 SQLITE_API char *sqlite3_mprintf(const char*,...);
3550 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3551 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3552 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3554 /*
3555 ** CAPI3REF: Memory Allocation Subsystem
3556 **
3557 ** The SQLite core uses these three routines for all of its own
3558 ** internal memory allocation needs. "Core" in the previous sentence
@@ -24653,11 +24675,11 @@
24653 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
24654 SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double);
24655 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*);
24656 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
24657 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
24658 SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem*, int*);
24659 SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
24660 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
24661 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
24662 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
24663 SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
@@ -36551,10 +36573,24 @@
36551 ** into *pLo. Return the upper 64 bits of A*B.
36552 **
36553 ** The lower 64 bits of A*B are discarded.
36554 */
36555 static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36556 u64 x2 = a>>32;
36557 u64 x1 = a&0xffffffff;
36558 u64 x0 = aLo;
36559 u64 y1 = b>>32;
36560 u64 y0 = b&0xffffffff;
@@ -36572,10 +36608,11 @@
36572 (x0y0 >>32);
36573 r2 += r1>>32;
36574 r3 += r2>>32;
36575 *pLo = r2&0xffffffff;
36576 return (r4<<32) + r3;
 
36577 }
36578
36579 /*
36580 ** Return a u64 with the N-th bit set.
36581 */
@@ -36801,10 +36838,13 @@
36801 *pP = -p;
36802 }
36803
36804 /*
36805 ** Return an IEEE754 floating point value that approximates d*pow(10,p).
 
 
 
36806 */
36807 static double sqlite3Fp10Convert2(u64 d, int p){
36808 int b, lp, e, adj, s;
36809 u32 pwr10l, mid1;
36810 u64 pwr10h, x, hi, lo, sticky, u, m;
@@ -36852,18 +36892,21 @@
36852 ** The string z[] is an text representation of a real number.
36853 ** Convert this string to a double and write it into *pResult.
36854 **
36855 ** z[] must be UTF-8 and zero-terminated.
36856 **
36857 ** Return TRUE if the result is a valid real number (or integer) and FALSE
36858 ** if the string is empty or contains extraneous text. More specifically
36859 ** return
 
36860 ** 1 => The input string is a pure integer
36861 ** 2 or more => The input has a decimal point or eNNN clause
36862 ** 0 or less => The input string is not a valid number
36863 ** -1 => Not a valid number, but has a valid prefix which
36864 ** includes a decimal point and/or an eNNN clause
 
 
36865 **
36866 ** Valid numbers are in one of these formats:
36867 **
36868 ** [+-]digits[E[+-]digits]
36869 ** [+-]digits.[digits][E[+-]digits]
@@ -36870,120 +36913,142 @@
36870 ** [+-].digits[E[+-]digits]
36871 **
36872 ** Leading and trailing whitespace is ignored for the purpose of determining
36873 ** validity.
36874 **
36875 ** If some prefix of the input string is a valid number, this routine
36876 ** returns FALSE but it still converts the prefix and writes the result
36877 ** into *pResult.
 
 
 
 
 
 
 
 
 
 
36878 */
36879 #if defined(_MSC_VER)
36880 #pragma warning(disable : 4756)
36881 #endif
36882 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
36883 #ifndef SQLITE_OMIT_FLOATING_POINT
36884 /* sign * significand * (10 ^ (esign * exponent)) */
36885 int neg = 0; /* True for a negative value */
36886 u64 s = 0; /* mantissa */
36887 int d = 0; /* Value is s * pow(10,d) */
36888 int nDigit = 0; /* Number of digits processed */
36889 int eType = 1; /* 1: pure integer, 2+: fractional */
36890
36891 *pResult = 0.0; /* Default return value, in case of an error */
36892
36893 /* skip leading spaces */
36894 while( sqlite3Isspace(*z) ) z++;
36895
36896 /* get sign of significand */
36897 if( *z=='-' ){
 
 
 
 
 
 
 
 
 
36898 neg = 1;
36899 z++;
36900 }else if( *z=='+' ){
 
36901 z++;
36902 }
36903
36904 /* copy max significant digits to significand */
36905 while( sqlite3Isdigit(*z) ){
36906 s = s*10 + (*z - '0');
36907 z++; nDigit++;
36908 if( s>=((LARGEST_INT64-9)/10) ){
36909 /* skip non-significant significand digits
36910 ** (increase exponent by d to shift decimal left) */
36911 while( sqlite3Isdigit(*z) ){ z++; d++; }
36912 }
36913 }
36914
36915 /* if decimal point is present */
36916 if( *z=='.' ){
36917 z++;
36918 eType++;
36919 /* copy digits from after decimal to significand
36920 ** (decrease exponent by d to shift decimal right) */
36921 while( sqlite3Isdigit(*z) ){
36922 if( s<((LARGEST_INT64-9)/10) ){
36923 s = s*10 + (*z - '0');
36924 d--;
36925 nDigit++;
36926 }
36927 z++;
36928 }
 
 
 
 
 
36929 }
36930
36931 /* if exponent is present */
36932 if( *z=='e' || *z=='E' ){
36933 int esign = 1; /* sign of exponent */
36934 z++;
36935 eType++;
36936
36937 /* get sign of exponent */
36938 if( *z=='-' ){
36939 esign = -1;
36940 z++;
36941 }else if( *z=='+' ){
36942 z++;
 
 
 
36943 }
36944 /* copy digits to exponent */
36945 if( sqlite3Isdigit(*z) ){
36946 int exp = *z - '0';
36947 z++;
36948 while( sqlite3Isdigit(*z) ){
36949 exp = exp<10000 ? (exp*10 + (*z - '0')) : 10000;
 
36950 z++;
36951 }
36952 d += esign*exp;
36953 }else{
36954 eType = -1;
 
36955 }
36956 }
36957
36958 /* skip trailing spaces */
36959 while( sqlite3Isspace(*z) ) z++;
36960
36961 /* Zero is a special case */
36962 if( s==0 ){
36963 *pResult = neg ? -0.0 : +0.0;
36964 }else{
36965 *pResult = sqlite3Fp10Convert2(s,d);
36966 if( neg ) *pResult = -*pResult;
36967 assert( !sqlite3IsNaN(*pResult) );
36968 }
36969
36970 /* return true if number and no extra non-whitespace characters after */
36971 if( z[0]==0 && nDigit>0 ){
36972 return eType;
36973 }else if( eType>=2 && nDigit>0 ){
36974 return -1;
36975 }else{
36976 return 0;
36977 }
36978 #else
36979 return !sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8);
36980 #endif /* SQLITE_OMIT_FLOATING_POINT */
36981 }
36982 #if defined(_MSC_VER)
36983 #pragma warning(default : 4756)
36984 #endif
 
 
 
 
 
36985
36986 /*
36987 ** Digit pairs used to convert a U64 or I64 into text, two digits
36988 ** at a time.
36989 */
@@ -85681,36 +85746,28 @@
85681 return 0;
85682 }
85683 }
85684
85685 /*
85686 ** Invoke sqlite3AtoF() on the text value of pMem and return the
85687 ** double result. If sqlite3AtoF() returns an error code, write
85688 ** that code into *pRC if (*pRC)!=NULL.
85689 **
85690 ** The caller must ensure that pMem->db!=0 and that pMem is in
85691 ** mode MEM_Str or MEM_Blob.
85692 */
85693 SQLITE_PRIVATE SQLITE_NOINLINE double sqlite3MemRealValueRC(Mem *pMem, int *pRC){
85694 double val = (double)0;
85695 int rc = 0;
85696 assert( pMem->db!=0 );
85697 assert( pMem->flags & (MEM_Str|MEM_Blob) );
85698 if( pMem->z==0 ){
85699 /* no-op */
85700 }else if( pMem->enc==SQLITE_UTF8
85701 && ((pMem->flags & MEM_Term)!=0 || sqlite3VdbeMemZeroTerminateIfAble(pMem))
85702 ){
85703 rc = sqlite3AtoF(pMem->z, &val);
85704 }else if( pMem->n==0 ){
85705 /* no-op */
85706 }else if( pMem->enc==SQLITE_UTF8 ){
85707 char *zCopy = sqlite3DbStrNDup(pMem->db, pMem->z, pMem->n);
85708 if( zCopy ){
85709 rc = sqlite3AtoF(zCopy, &val);
85710 sqlite3DbFree(pMem->db, zCopy);
85711 }
 
85712 }else{
85713 int n, i, j;
85714 char *zCopy;
85715 const char *z;
85716
@@ -85729,17 +85786,53 @@
85729 zCopy[j] = z[i+1];
85730 }
85731 }
85732 assert( j<=n/2 );
85733 zCopy[j] = 0;
85734 rc = sqlite3AtoF(zCopy, &val);
85735 if( i<n ) rc = -100;
85736 sqlite3DbFree(pMem->db, zCopy);
85737 }
 
85738 }
85739 if( pRC ) *pRC = rc;
85740 return val;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85741 }
85742
85743 /*
85744 ** Return the best representation of pMem that we can get into a
85745 ** double. If pMem is already a double or an integer, return its
@@ -85754,11 +85847,11 @@
85754 return pMem->u.r;
85755 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
85756 testcase( pMem->flags & MEM_IntReal );
85757 return (double)pMem->u.i;
85758 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
85759 return sqlite3MemRealValueRC(pMem, 0);
85760 }else{
85761 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
85762 return (double)0;
85763 }
85764 }
@@ -85878,11 +85971,11 @@
85878 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
85879 int rc;
85880 sqlite3_int64 ix;
85881 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
85882 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85883 pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
85884 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
85885 || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
85886 ){
85887 pMem->u.i = ix;
85888 MemSetTypeFlag(pMem, MEM_Int);
@@ -96318,11 +96411,11 @@
96318 */
96319 static void applyNumericAffinity(Mem *pRec, int bTryForInt){
96320 double rValue;
96321 int rc;
96322 assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
96323 rValue = sqlite3MemRealValueRC(pRec, &rc);
96324 if( rc<=0 ) return;
96325 if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
96326 pRec->flags |= MEM_Int;
96327 }else{
96328 pRec->u.r = rValue;
@@ -96436,11 +96529,11 @@
96436 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
96437 if( ExpandBlob(pMem) ){
96438 pMem->u.i = 0;
96439 return MEM_Int;
96440 }
96441 pMem->u.r = sqlite3MemRealValueRC(pMem, &rc);
96442 if( rc<=0 ){
96443 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
96444 pMem->u.i = ix;
96445 return MEM_Int;
96446 }else{
@@ -110776,11 +110869,11 @@
110776 */
110777 static int exprProbability(Expr *p){
110778 double r = -1.0;
110779 if( p->op!=TK_FLOAT ) return -1;
110780 assert( !ExprHasProperty(p, EP_IntValue) );
110781 sqlite3AtoF(p->u.zToken, &r);
110782 assert( r>=0.0 );
110783 if( r>1.0 ) return -1;
110784 return (int)(r*134217728.0);
110785 }
110786
@@ -116464,12 +116557,11 @@
116464 ** z[n] character is guaranteed to be something that does not look
116465 ** like the continuation of the number.
116466 */
116467 static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
116468 if( ALWAYS(z!=0) ){
116469 double value;
116470 sqlite3AtoF(z, &value);
116471 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116472 if( negateFlag ) value = -value;
116473 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
116474 }
116475 }
@@ -128323,13 +128415,14 @@
128323 if( resizeIndexObject(pParse, pPk, nPk+nExtra) ) return;
128324 for(i=0, j=nPk; i<pTab->nCol; i++){
128325 if( !hasColumn(pPk->aiColumn, j, i)
128326 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0
128327 ){
 
128328 assert( j<pPk->nColumn );
128329 pPk->aiColumn[j] = i;
128330 pPk->azColl[j] = sqlite3StrBINARY;
128331 j++;
128332 }
128333 }
128334 assert( pPk->nColumn==j );
128335 assert( pTab->nNVCol<=j );
@@ -131351,138 +131444,129 @@
131351 sqlite3HaltConstraint(pParse, rc, onError, zMsg, P4_DYNAMIC,
131352 P5_ConstraintUnique);
131353 }
131354
131355 /*
131356 ** Check to see if pIndex uses the collating sequence pColl. Return
131357 ** true if it does and false if it does not.
131358 */
131359 #ifndef SQLITE_OMIT_REINDEX
131360 static int collationMatch(const char *zColl, Index *pIndex){
131361 int i;
131362 assert( zColl!=0 );
131363 for(i=0; i<pIndex->nColumn; i++){
131364 const char *z = pIndex->azColl[i];
131365 assert( z!=0 || pIndex->aiColumn[i]<0 );
131366 if( pIndex->aiColumn[i]>=0 && 0==sqlite3StrICmp(z, zColl) ){
131367 return 1;
131368 }
131369 }
131370 return 0;
131371 }
131372 #endif
131373
131374 /*
131375 ** Recompute all indices of pTab that use the collating sequence pColl.
131376 ** If pColl==0 then recompute all indices of pTab.
131377 */
131378 #ifndef SQLITE_OMIT_REINDEX
131379 static void reindexTable(Parse *pParse, Table *pTab, char const *zColl){
131380 if( !IsVirtual(pTab) ){
131381 Index *pIndex; /* An index associated with pTab */
131382
131383 for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
131384 if( zColl==0 || collationMatch(zColl, pIndex) ){
131385 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
131386 sqlite3BeginWriteOperation(pParse, 0, iDb);
131387 sqlite3RefillIndex(pParse, pIndex, -1);
131388 }
131389 }
131390 }
131391 }
131392 #endif
131393
131394 /*
131395 ** Recompute all indices of all tables in all databases where the
131396 ** indices use the collating sequence pColl. If pColl==0 then recompute
131397 ** all indices everywhere.
131398 */
131399 #ifndef SQLITE_OMIT_REINDEX
131400 static void reindexDatabases(Parse *pParse, char const *zColl){
131401 Db *pDb; /* A single database */
131402 int iDb; /* The database index number */
131403 sqlite3 *db = pParse->db; /* The database connection */
131404 HashElem *k; /* For looping over tables in pDb */
131405 Table *pTab; /* A table in the database */
131406
131407 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
131408 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
131409 assert( pDb!=0 );
131410 for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
131411 pTab = (Table*)sqliteHashData(k);
131412 reindexTable(pParse, pTab, zColl);
131413 }
131414 }
131415 }
131416 #endif
131417
131418 /*
131419 ** Generate code for the REINDEX command.
131420 **
131421 ** REINDEX -- 1
131422 ** REINDEX <collation> -- 2
131423 ** REINDEX ?<database>.?<tablename> -- 3
131424 ** REINDEX ?<database>.?<indexname> -- 4
 
131425 **
131426 ** Form 1 causes all indices in all attached databases to be rebuilt.
131427 ** Form 2 rebuilds all indices in all databases that use the named
131428 ** collating function. Forms 3 and 4 rebuild the named index or all
131429 ** indices associated with the named table.
 
 
 
 
 
 
131430 */
131431 #ifndef SQLITE_OMIT_REINDEX
131432 SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){
131433 CollSeq *pColl; /* Collating sequence to be reindexed, or NULL */
131434 char *z; /* Name of a table or index */
131435 const char *zDb; /* Name of the database */
131436 Table *pTab; /* A table in the database */
131437 Index *pIndex; /* An index associated with pTab */
131438 int iDb; /* The database index number */
131439 sqlite3 *db = pParse->db; /* The database connection */
131440 Token *pObjName; /* Name of the table or index to be reindexed */
 
 
 
 
 
 
131441
131442 /* Read the database schema. If an error occurs, leave an error message
131443 ** and code in pParse and return NULL. */
131444 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
131445 return;
131446 }
131447
131448 if( pName1==0 ){
131449 reindexDatabases(pParse, 0);
131450 return;
 
131451 }else if( NEVER(pName2==0) || pName2->z==0 ){
131452 char *zColl;
131453 assert( pName1->z );
131454 zColl = sqlite3NameFromToken(pParse->db, pName1);
131455 if( !zColl ) return;
131456 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
131457 if( pColl ){
131458 reindexDatabases(pParse, zColl);
131459 sqlite3DbFree(db, zColl);
131460 return;
131461 }
131462 sqlite3DbFree(db, zColl);
131463 }
131464 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
131465 if( iDb<0 ) return;
131466 z = sqlite3NameFromToken(db, pObjName);
131467 if( z==0 ) return;
131468 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
131469 pTab = sqlite3FindTable(db, z, zDb);
131470 if( pTab ){
131471 reindexTable(pParse, pTab, 0);
131472 sqlite3DbFree(db, z);
131473 return;
131474 }
131475 pIndex = sqlite3FindIndex(db, z, zDb);
131476 sqlite3DbFree(db, z);
131477 if( pIndex ){
131478 iDb = sqlite3SchemaToIndex(db, pIndex->pTable->pSchema);
131479 sqlite3BeginWriteOperation(pParse, 0, iDb);
131480 sqlite3RefillIndex(pParse, pIndex, -1);
131481 return;
131482 }
131483 sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131484 }
131485 #endif
131486
131487 /*
131488 ** Return a KeyInfo structure that is appropriate for the given Index.
@@ -142129,10 +142213,12 @@
142129 /* Version 3.52.0 and later */
142130 void (*str_truncate)(sqlite3_str*,int);
142131 void (*str_free)(sqlite3_str*);
142132 int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142133 int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
 
 
142134 };
142135
142136 /*
142137 ** This is the function signature used for all extension entry points. It
142138 ** is also defined in the file "loadext.c".
@@ -142472,10 +142558,12 @@
142472 /* Version 3.52.0 and later */
142473 #define sqlite3_str_truncate sqlite3_api->str_truncate
142474 #define sqlite3_str_free sqlite3_api->str_free
142475 #define sqlite3_carray_bind sqlite3_api->carray_bind
142476 #define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
 
 
142477 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142478
142479 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142480 /* This case when the file really is being compiled as a loadable
142481 ** extension */
@@ -143004,15 +143092,16 @@
143004 /* Version 3.52.0 and later */
143005 sqlite3_str_truncate,
143006 sqlite3_str_free,
143007 #ifdef SQLITE_ENABLE_CARRAY
143008 sqlite3_carray_bind,
143009 sqlite3_carray_bind_v2
143010 #else
 
143011 0,
143012 0
143013 #endif
 
143014 };
143015
143016 /* True if x is the directory separator character
143017 */
143018 #if SQLITE_OS_WIN
@@ -172275,11 +172364,16 @@
172275 #endif
172276 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
172277 whereLoopOutputAdjust(pWC, pNew, rSize);
172278 if( pSrc->fg.isSubquery ){
172279 if( pSrc->fg.viaCoroutine ) pNew->wsFlags |= WHERE_COROUTINE;
172280 pNew->u.btree.pOrderBy = pSrc->u4.pSubq->pSelect->pOrderBy;
 
 
 
 
 
172281 }else if( pSrc->fg.fromExists ){
172282 pNew->nOut = 0;
172283 }
172284 rc = whereLoopInsert(pBuilder, pNew);
172285 pNew->nOut = rSize;
@@ -212773,18 +212867,19 @@
212773 JsonParse *pParse, /* JSONB source or NULL */
212774 sqlite3_context *ctx /* Where to cache */
212775 ){
212776 assert( (pParse!=0)==(ctx!=0) );
212777 assert( ctx==0 || ctx==p->pCtx );
 
212778 if( p->eErr==0 ){
212779 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(p->pCtx));
212780 if( flags & JSON_BLOB ){
212781 jsonReturnStringAsBlob(p);
212782 }else if( p->bStatic ){
212783 sqlite3_result_text64(p->pCtx, p->zBuf, p->nUsed,
212784 SQLITE_TRANSIENT, SQLITE_UTF8);
212785 }else if( jsonStringTerminate(p) ){
212786 if( pParse && pParse->bJsonIsRCStr==0 && pParse->nBlobAlloc>0 ){
212787 int rc;
212788 pParse->zJson = sqlite3RCStrRef(p->zBuf);
212789 pParse->nJson = p->nUsed;
212790 pParse->bJsonIsRCStr = 1;
@@ -212796,12 +212891,10 @@
212796 }
212797 }
212798 sqlite3_result_text64(p->pCtx, sqlite3RCStrRef(p->zBuf), p->nUsed,
212799 sqlite3RCStrUnref,
212800 SQLITE_UTF8);
212801 }else{
212802 sqlite3_result_error_nomem(p->pCtx);
212803 }
212804 }else if( p->eErr & JSTRING_OOM ){
212805 sqlite3_result_error_nomem(p->pCtx);
212806 }else if( p->eErr & JSTRING_MALFORMED ){
212807 sqlite3_result_error(p->pCtx, "malformed JSON", -1);
@@ -214011,16 +214104,12 @@
214011 ** this into the JSONB format and make it the return value of the
214012 ** SQL function.
214013 */
214014 static void jsonReturnStringAsBlob(JsonString *pStr){
214015 JsonParse px;
 
214016 memset(&px, 0, sizeof(px));
214017 jsonStringTerminate(pStr);
214018 if( pStr->eErr ){
214019 sqlite3_result_error_nomem(pStr->pCtx);
214020 return;
214021 }
214022 px.zJson = pStr->zBuf;
214023 px.nJson = pStr->nUsed;
214024 px.db = sqlite3_context_db_handle(pStr->pCtx);
214025 (void)jsonTranslateTextToBlob(&px, 0);
214026 if( px.oom ){
@@ -216731,11 +216820,12 @@
216731 JsonString *pStr;
216732 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216733 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216734 if( pStr ){
216735 pStr->pCtx = ctx;
216736 jsonAppendChar(pStr, ']');
 
216737 if( pStr->eErr ){
216738 jsonReturnString(pStr, 0, 0);
216739 return;
216740 }else if( flags & JSON_BLOB ){
216741 jsonReturnStringAsBlob(pStr);
@@ -216854,11 +216944,12 @@
216854 static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
216855 JsonString *pStr;
216856 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216857 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216858 if( pStr ){
216859 jsonAppendChar(pStr, '}');
 
216860 pStr->pCtx = ctx;
216861 if( pStr->eErr ){
216862 jsonReturnString(pStr, 0, 0);
216863 return;
216864 }else if( flags & JSON_BLOB ){
@@ -259195,11 +259286,11 @@
259195 #if SQLITE_VERSION_NUMBER>=3008002
259196 #ifndef SQLITE_CORE
259197 if( sqlite3_libversion_number()>=3008002 )
259198 #endif
259199 {
259200 pIdxInfo->estimatedRows = nRow;
259201 }
259202 #endif
259203 }
259204
259205 static int fts5UsePatternMatch(
@@ -259264,23 +259355,34 @@
259264 ** Costs are assigned as follows:
259265 **
259266 ** a) If a MATCH operator is present, the cost depends on the other
259267 ** constraints also present. As follows:
259268 **
259269 ** * No other constraints: cost=1000.0
259270 ** * One rowid range constraint: cost=750.0
259271 ** * Both rowid range constraints: cost=500.0
259272 ** * An == rowid constraint: cost=100.0
259273 **
259274 ** b) Otherwise, if there is no MATCH:
259275 **
259276 ** * No other constraints: cost=1000000.0
259277 ** * One rowid range constraint: cost=750000.0
259278 ** * Both rowid range constraints: cost=250000.0
259279 ** * An == rowid constraint: cost=10.0
259280 **
259281 ** Costs are not modified by the ORDER BY clause.
 
 
 
 
 
 
 
 
 
 
 
259282 */
259283 static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
259284 Fts5Table *pTab = (Fts5Table*)pVTab;
259285 Fts5Config *pConfig = pTab->pConfig;
259286 const int nCol = pConfig->nCol;
@@ -259402,25 +259504,39 @@
259402 }
259403 }
259404
259405 /* Calculate the estimated cost based on the flags set in idxFlags. */
259406 if( bSeenEq ){
259407 pInfo->estimatedCost = nSeenMatch ? 1000.0 : 25.0;
259408 fts5SetUniqueFlag(pInfo);
259409 fts5SetEstimatedRows(pInfo, 1);
259410 }else{
259411 if( bSeenLt && bSeenGt ){
259412 pInfo->estimatedCost = nSeenMatch ? 5000.0 : 750000.0;
259413 }else if( bSeenLt || bSeenGt ){
259414 pInfo->estimatedCost = nSeenMatch ? 7500.0 : 2250000.0;
259415 }else{
259416 pInfo->estimatedCost = nSeenMatch ? 10000.0 : 3000000.0;
259417 }
259418 for(i=1; i<nSeenMatch; i++){
259419 pInfo->estimatedCost *= 0.4;
259420 }
259421 fts5SetEstimatedRows(pInfo, (i64)(pInfo->estimatedCost / 4.0));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259422 }
259423
259424 pInfo->idxNum = idxFlags;
259425 return SQLITE_OK;
259426 }
@@ -262277,11 +262393,11 @@
262277 int nArg, /* Number of args */
262278 sqlite3_value **apUnused /* Function arguments */
262279 ){
262280 assert( nArg==0 );
262281 UNUSED_PARAM2(nArg, apUnused);
262282 sqlite3_result_text(pCtx, "fts5: 2026-03-18 15:40:26 971aa34b3fd86ba30fe170886d9f83c17159b1638c4bd4fb6cdef79b1c9a88e2", -1, SQLITE_TRANSIENT);
262283 }
262284
262285 /*
262286 ** Implementation of fts5_locale(LOCALE, TEXT) function.
262287 **
262288
--- 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 ** 276c350313a1ac2ebc70c1e8e50ed4baecd4 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-23 13:00:56 276c350313a1ac2ebc70c1e8e50ed4baecd4be4d4c93ba04cf5e0078da18700e"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-03-23T13:00:56.709Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -3549,10 +3549,32 @@
3549 SQLITE_API char *sqlite3_mprintf(const char*,...);
3550 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3551 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3552 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3553
3554 /*
3555 ** CAPI3REF: Text-to-float conversion
3556 **
3557 ** The sqlite3_atof(X) interface returns a "double" derived from the
3558 ** text representation of a floating point value in X.
3559 ** This interface provides applications with access to the
3560 ** same text&rarr;float conversion routine used by SQLite for SQL parsing
3561 ** and type coercion. The sqlite3_atof(X) routine works like the standard
3562 ** C-library atof(X) routine with the following exceptions:
3563 **
3564 ** <ul>
3565 ** <li> Parsing of the input X is strict. If anything about X
3566 ** is not well-formed, 0.0 is returned.
3567 ** <li> Special values such like "INF", "INFINITY", and "NAN" are not
3568 ** recognized.
3569 ** <li> Hexadecimal floating point literals are not recognized.
3570 ** <li> The current locale is ignored. The radix character is always ".".
3571 ** <li> The sqlite3_atof() interface does not set errno.
3572 ** </ul>
3573 */
3574 SQLITE_API double sqlite3_atof(const char*);
3575
3576 /*
3577 ** CAPI3REF: Memory Allocation Subsystem
3578 **
3579 ** The SQLite core uses these three routines for all of its own
3580 ** internal memory allocation needs. "Core" in the previous sentence
@@ -24653,11 +24675,11 @@
24675 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
24676 SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double);
24677 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*);
24678 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
24679 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
24680 SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem*, double*);
24681 SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
24682 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
24683 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
24684 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
24685 SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
@@ -36551,10 +36573,24 @@
36573 ** into *pLo. Return the upper 64 bits of A*B.
36574 **
36575 ** The lower 64 bits of A*B are discarded.
36576 */
36577 static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){
36578 #if (defined(__GNUC__) || defined(__clang__)) \
36579 && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv))
36580 __uint128_t r = (__uint128_t)a * b;
36581 r += ((__uint128_t)aLo * b) >> 32;
36582 *pLo = (r>>32)&0xffffffff;
36583 return r>>64;
36584 #elif defined(_MSC_VER) && defined(_M_X64)
36585 u64 r1_hi = __umulh(a,b);
36586 u64 r1_lo = a*b;
36587 u64 r2 = (__umulh((u64)aLo,b)<<32) + ((aLo*b)>>32);
36588 r1_hi += _addcarry_u64(0, r1_lo, r2, &r1_lo);
36589 *pLo = r1_lo>>32;
36590 return r1_hi;
36591 #else
36592 u64 x2 = a>>32;
36593 u64 x1 = a&0xffffffff;
36594 u64 x0 = aLo;
36595 u64 y1 = b>>32;
36596 u64 y0 = b&0xffffffff;
@@ -36572,10 +36608,11 @@
36608 (x0y0 >>32);
36609 r2 += r1>>32;
36610 r3 += r2>>32;
36611 *pLo = r2&0xffffffff;
36612 return (r4<<32) + r3;
36613 #endif
36614 }
36615
36616 /*
36617 ** Return a u64 with the N-th bit set.
36618 */
@@ -36801,10 +36838,13 @@
36838 *pP = -p;
36839 }
36840
36841 /*
36842 ** Return an IEEE754 floating point value that approximates d*pow(10,p).
36843 **
36844 ** The (current) algorithm is adapted from the work of Ross Cox at
36845 ** https://github.com/rsc/fpfmt
36846 */
36847 static double sqlite3Fp10Convert2(u64 d, int p){
36848 int b, lp, e, adj, s;
36849 u32 pwr10l, mid1;
36850 u64 pwr10h, x, hi, lo, sticky, u, m;
@@ -36852,18 +36892,21 @@
36892 ** The string z[] is an text representation of a real number.
36893 ** Convert this string to a double and write it into *pResult.
36894 **
36895 ** z[] must be UTF-8 and zero-terminated.
36896 **
36897 ** Return positive if the result is a valid real number (or integer) and
36898 ** zero or negative if the string is empty or contains extraneous text.
36899 ** More specifically:
36900 **
36901 ** 1 => The input string is a pure integer
36902 ** 2 or more => The input has a decimal point or eNNN clause
36903 ** 0 or less => The input string is not well-formed
36904 ** -1 => The input is not well-formed, but it does begin
36905 ** with a well-formed floating-point literal (with
36906 ** a "." or a "eNNN" suffix or both) followed by
36907 ** other extraneous text.
36908 **
36909 ** Valid numbers are in one of these formats:
36910 **
36911 ** [+-]digits[E[+-]digits]
36912 ** [+-]digits.[digits][E[+-]digits]
@@ -36870,120 +36913,142 @@
36913 ** [+-].digits[E[+-]digits]
36914 **
36915 ** Leading and trailing whitespace is ignored for the purpose of determining
36916 ** validity.
36917 **
36918 ** Algorithm sketch: Compute an unsigned 64-bit integer s and a base-10
36919 ** exponent d such that the value encoding by the input is s*pow(10,d).
36920 ** Then invoke sqlite3Fp10Convert2() to calculated the closest possible
36921 ** IEEE754 double. The sign is added back afterwards, if the input string
36922 ** starts with a "-". The use of an unsigned 64-bit s mantissa means that
36923 ** only about the first 19 significant digits of the input can contribute
36924 ** to the result. This can result in suboptimal rounding decisions when
36925 ** correct rounding requires more than 19 input digits. For example,
36926 ** this routine renders "3500000000000000.2500001" as
36927 ** 3500000000000000.0 instead of 3500000000000000.5 because the decision
36928 ** to round up instead of using banker's rounding to round down is determined
36929 ** by the 23rd significant digit, which this routine ignores. It is not
36930 ** possible to do better without some kind of BigNum.
36931 */
36932 SQLITE_PRIVATE int sqlite3AtoF(const char *zIn, double *pResult){
 
 
 
36933 #ifndef SQLITE_OMIT_FLOATING_POINT
36934 const unsigned char *z = (const unsigned char*)zIn;
36935 int neg = 0; /* True for a negative value */
36936 u64 s = 0; /* mantissa */
36937 int d = 0; /* Value is s * pow(10,d) */
36938 int seenDigit = 0; /* true if any digits seen */
36939 int seenFP = 0; /* True if we've seen a "." or a "e" */
36940 unsigned v; /* Value of a single digit */
36941
36942 start_of_text:
36943 if( (v = (unsigned)z[0] - '0')<10 ){
36944 parse_integer_part:
36945 seenDigit = 1;
36946 s = v;
36947 z++;
36948 while( (v = (unsigned)z[0] - '0')<10 ){
36949 s = s*10 + v;
36950 z++;
36951 if( s>=(LARGEST_INT64-9)/10 ){
36952 while( sqlite3Isdigit(z[0]) ){ z++; d++; }
36953 break;
36954 }
36955 }
36956 }else if( z[0]=='-' ){
36957 neg = 1;
36958 z++;
36959 if( (v = (unsigned)z[0] - '0')<10 ) goto parse_integer_part;
36960 }else if( z[0]=='+' ){
36961 z++;
36962 if( (v = (unsigned)z[0] - '0')<10 ) goto parse_integer_part;
36963 }else if( sqlite3Isspace(z[0]) ){
36964 do{ z++; }while( sqlite3Isspace(z[0]) );
36965 goto start_of_text;
36966 }else{
36967 s = 0;
 
 
 
 
 
36968 }
36969
36970 /* if decimal point is present */
36971 if( *z=='.' ){
36972 z++;
36973 seenFP = 1;
36974 if( sqlite3Isdigit(z[0]) ){
36975 seenDigit = 1;
36976 do{
36977 if( s<((LARGEST_INT64-9)/10) ){
36978 s = s*10 + z[0] - '0';
36979 d--;
36980 }
36981 z++;
36982 }while( sqlite3Isdigit(z[0]) );
36983 }
36984 }
36985
36986 if( !seenDigit ){
36987 *pResult = 0.0;
36988 return 0;
36989 }
36990
36991 /* if exponent is present */
36992 if( *z=='e' || *z=='E' ){
36993 int esign;
36994 z++;
 
36995
36996 /* get sign of exponent */
36997 if( *z=='-' ){
36998 esign = -1;
36999 z++;
37000 }else{
37001 esign = +1;
37002 if( *z=='+' ){
37003 z++;
37004 }
37005 }
37006 /* copy digits to exponent */
37007 if( (v = (unsigned)z[0] - '0')<10 ){
37008 int exp = v;
37009 z++;
37010 seenFP = 1;
37011 while( (v = (unsigned)z[0] - '0')<10 ){
37012 exp = exp<10000 ? (exp*10 + v) : 10000;
37013 z++;
37014 }
37015 d += esign*exp;
37016 }else{
37017 z--; /* Leave z[0] at 'e' or '+' or '-',
37018 ** so that the return is 0 or -1 */
37019 }
37020 }
37021
37022 /* skip trailing spaces */
37023 while( sqlite3Isspace(*z) ) z++;
37024
37025 /* Convert s*pow(10,d) into real */
37026 *pResult = s ? sqlite3Fp10Convert2(s,d) : 0.0;
37027 if( neg ) *pResult = -*pResult;
37028 assert( !sqlite3IsNaN(*pResult) );
 
 
 
 
37029
37030 /* return true if number and no extra non-whitespace characters after */
37031 if( z[0]==0 ){
37032 return seenFP+1;
37033 }else if( seenFP ){
37034 return -1; /* Prefix is a floating point number */
37035 }else{
37036 return 0; /* Prefix is just an integer */
37037 }
37038 #else
37039 return !sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8);
37040 #endif /* SQLITE_OMIT_FLOATING_POINT */
37041 }
37042
37043 /*
37044 ** Access to sqlite3AtoF()
37045 */
37046 SQLITE_API double sqlite3_atof(const char *z){
37047 double r;
37048 return sqlite3AtoF(z,&r)>0 ? r : 0.0;
37049 }
37050
37051 /*
37052 ** Digit pairs used to convert a U64 or I64 into text, two digits
37053 ** at a time.
37054 */
@@ -85681,36 +85746,28 @@
85746 return 0;
85747 }
85748 }
85749
85750 /*
85751 ** This routine implements the uncommon and slower path for
85752 ** sqlite3MemValueRC(). It is broken out into a separate
85753 ** no-inline routine so that the main routine can avoid unnecessary
85754 ** stack pushes.
 
 
85755 */
85756 static SQLITE_NOINLINE int sqlite3MemRealValueRCSlowPath(
85757 Mem *pMem,
85758 double *pValue
85759 ){
85760 int rc = SQLITE_OK;
85761 *pValue = 0.0;
85762 if( pMem->enc==SQLITE_UTF8 ){
 
 
 
 
 
 
 
85763 char *zCopy = sqlite3DbStrNDup(pMem->db, pMem->z, pMem->n);
85764 if( zCopy ){
85765 rc = sqlite3AtoF(zCopy, pValue);
85766 sqlite3DbFree(pMem->db, zCopy);
85767 }
85768 return rc;
85769 }else{
85770 int n, i, j;
85771 char *zCopy;
85772 const char *z;
85773
@@ -85729,17 +85786,53 @@
85786 zCopy[j] = z[i+1];
85787 }
85788 }
85789 assert( j<=n/2 );
85790 zCopy[j] = 0;
85791 rc = sqlite3AtoF(zCopy, pValue);
85792 if( i<n ) rc = -100;
85793 sqlite3DbFree(pMem->db, zCopy);
85794 }
85795 return rc;
85796 }
85797 }
85798
85799 /*
85800 ** Invoke sqlite3AtoF() on the text value of pMem and return the
85801 ** double result. If sqlite3AtoF() returns an error code, write
85802 ** that code into *pRC if (*pRC)!=NULL.
85803 **
85804 ** The caller must ensure that pMem->db!=0 and that pMem is in
85805 ** mode MEM_Str or MEM_Blob.
85806 */
85807 SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem *pMem, double *pValue){
85808 assert( pMem->db!=0 );
85809 assert( pMem->flags & (MEM_Str|MEM_Blob) );
85810 if( pMem->z==0 ){
85811 *pValue = 0.0;
85812 return 0;
85813 }else if( pMem->enc==SQLITE_UTF8
85814 && ((pMem->flags & MEM_Term)!=0 || sqlite3VdbeMemZeroTerminateIfAble(pMem))
85815 ){
85816 return sqlite3AtoF(pMem->z, pValue);
85817 }else if( pMem->n==0 ){
85818 *pValue = 0.0;
85819 return 0;
85820 }else{
85821 return sqlite3MemRealValueRCSlowPath(pMem, pValue);
85822 }
85823 }
85824
85825 /*
85826 ** This routine acts as a bridge from sqlite3VdbeRealValue() to
85827 ** sqlite3VdbeRealValueRC, allowing sqlite3VdbeRealValue() to avoid
85828 ** stuffing values onto the stack.
85829 */
85830 static SQLITE_NOINLINE double sqlite3MemRealValueNoRC(Mem *pMem){
85831 double r;
85832 (void)sqlite3MemRealValueRC(pMem, &r);
85833 return r;
85834 }
85835
85836 /*
85837 ** Return the best representation of pMem that we can get into a
85838 ** double. If pMem is already a double or an integer, return its
@@ -85754,11 +85847,11 @@
85847 return pMem->u.r;
85848 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
85849 testcase( pMem->flags & MEM_IntReal );
85850 return (double)pMem->u.i;
85851 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
85852 return sqlite3MemRealValueNoRC(pMem);
85853 }else{
85854 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
85855 return (double)0;
85856 }
85857 }
@@ -85878,11 +85971,11 @@
85971 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
85972 int rc;
85973 sqlite3_int64 ix;
85974 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
85975 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
85976 rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
85977 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
85978 || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
85979 ){
85980 pMem->u.i = ix;
85981 MemSetTypeFlag(pMem, MEM_Int);
@@ -96318,11 +96411,11 @@
96411 */
96412 static void applyNumericAffinity(Mem *pRec, int bTryForInt){
96413 double rValue;
96414 int rc;
96415 assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
96416 rc = sqlite3MemRealValueRC(pRec, &rValue);
96417 if( rc<=0 ) return;
96418 if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
96419 pRec->flags |= MEM_Int;
96420 }else{
96421 pRec->u.r = rValue;
@@ -96436,11 +96529,11 @@
96529 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
96530 if( ExpandBlob(pMem) ){
96531 pMem->u.i = 0;
96532 return MEM_Int;
96533 }
96534 rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
96535 if( rc<=0 ){
96536 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
96537 pMem->u.i = ix;
96538 return MEM_Int;
96539 }else{
@@ -110776,11 +110869,11 @@
110869 */
110870 static int exprProbability(Expr *p){
110871 double r = -1.0;
110872 if( p->op!=TK_FLOAT ) return -1;
110873 assert( !ExprHasProperty(p, EP_IntValue) );
110874 r = sqlite3_atof(p->u.zToken);
110875 assert( r>=0.0 );
110876 if( r>1.0 ) return -1;
110877 return (int)(r*134217728.0);
110878 }
110879
@@ -116464,12 +116557,11 @@
116557 ** z[n] character is guaranteed to be something that does not look
116558 ** like the continuation of the number.
116559 */
116560 static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
116561 if( ALWAYS(z!=0) ){
116562 double value = sqlite3_atof(z);
 
116563 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116564 if( negateFlag ) value = -value;
116565 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
116566 }
116567 }
@@ -128323,13 +128415,14 @@
128415 if( resizeIndexObject(pParse, pPk, nPk+nExtra) ) return;
128416 for(i=0, j=nPk; i<pTab->nCol; i++){
128417 if( !hasColumn(pPk->aiColumn, j, i)
128418 && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0
128419 ){
128420 const char *zColl = sqlite3ColumnColl(&pTab->aCol[i]);
128421 assert( j<pPk->nColumn );
128422 pPk->aiColumn[j] = i;
128423 pPk->azColl[j] = zColl ? zColl : sqlite3StrBINARY;
128424 j++;
128425 }
128426 }
128427 assert( pPk->nColumn==j );
128428 assert( pTab->nNVCol<=j );
@@ -131351,138 +131444,129 @@
131444 sqlite3HaltConstraint(pParse, rc, onError, zMsg, P4_DYNAMIC,
131445 P5_ConstraintUnique);
131446 }
131447
131448 /*
131449 ** Return true if any column of pIndex uses the zColl collation
 
131450 */
131451 #ifndef SQLITE_OMIT_REINDEX
131452 static int collationMatch(const char *zColl, Index *pIndex){
131453 int i;
131454 assert( zColl!=0 );
131455 for(i=0; i<pIndex->nColumn; i++){
131456 const char *z = pIndex->azColl[i];
131457 assert( z!=0 );
131458 if( 0==sqlite3StrICmp(z, zColl) ){
131459 return 1;
131460 }
131461 }
131462 return 0;
131463 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131464 #endif
131465
131466 /*
131467 ** Generate code for the REINDEX command.
131468 **
131469 ** REINDEX -- 1
131470 ** REINDEX <collation> -- 2
131471 ** REINDEX ?<database>.?<indexname> -- 3
131472 ** REINDEX ?<database>.?<tablename> -- 4
131473 ** REINDEX EXPRESSIONS -- 5
131474 **
131475 ** Form 1 causes all indexes in all attached databases to be rebuilt.
131476 ** Form 2 rebuilds all indexes in all databases that use the named
131477 ** collating function. Forms 3 and 4 rebuild the named index or all
131478 ** indexes associated with the named table, respectively. Form 5
131479 ** rebuilds all expression indexes in addition to all collations,
131480 ** indexes, or tables named "EXPRESSIONS".
131481 **
131482 ** If the name is ambiguous such that it matches two or more of
131483 ** forms 2 through 5, then rebuild the union of all matching indexes,
131484 ** taken care to avoid rebuilding the same index more than once.
131485 */
131486 #ifndef SQLITE_OMIT_REINDEX
131487 SQLITE_PRIVATE void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){
131488 CollSeq *pColl; /* Collating sequence to be reindexed, or NULL */
131489 char *z = 0; /* Name of a table or index or collation */
131490 const char *zDb = 0; /* Name of the database */
131491 int iReDb = -1; /* The database index number */
 
 
131492 sqlite3 *db = pParse->db; /* The database connection */
131493 Token *pObjName; /* Name of the table or index to be reindexed */
131494 int bMatch = 0; /* At least one name match */
131495 const char *zColl = 0; /* Rebuild indexes using this collation */
131496 Table *pReTab = 0; /* Rebuild all indexes of this table */
131497 Index *pReIndex = 0; /* Rebuild this index */
131498 int isExprIdx = 0; /* Rebuild all expression indexes */
131499 int bAll = 0; /* Rebuild all indexes */
131500
131501 /* Read the database schema. If an error occurs, leave an error message
131502 ** and code in pParse and return NULL. */
131503 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
131504 return;
131505 }
131506
131507 if( pName1==0 ){
131508 /* rebuild all indexes */
131509 bMatch = 1;
131510 bAll = 1;
131511 }else if( NEVER(pName2==0) || pName2->z==0 ){
 
131512 assert( pName1->z );
131513 z = sqlite3NameFromToken(pParse->db, pName1);
131514 if( z==0 ) return;
131515 }else{
131516 iReDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName);
131517 if( iReDb<0 ) return;
131518 z = sqlite3NameFromToken(db, pObjName);
131519 if( z==0 ) return;
131520 zDb = db->aDb[iReDb].zDbSName;
131521 }
131522 if( !bAll ){
131523 if( zDb==0 && sqlite3StrICmp(z, "expressions")==0 ){
131524 isExprIdx = 1;
131525 bMatch = 1;
131526 }
131527 if( zDb==0 && (pColl = sqlite3FindCollSeq(db, ENC(db), z, 0))!=0 ){
131528 zColl = z;
131529 bMatch = 1;
131530 }
131531 if( zColl==0 && (pReTab = sqlite3FindTable(db, z, zDb))!=0 ){
131532 bMatch = 1;
131533 }
131534 if( zColl==0 && (pReIndex = sqlite3FindIndex(db, z, zDb))!=0 ){
131535 bMatch = 1;
131536 }
131537 }
131538 if( bMatch ){
131539 int iDb;
131540 HashElem *k;
131541 Table *pTab;
131542 Index *pIdx;
131543 Db *pDb;
131544 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
131545 assert( pDb!=0 );
131546 if( iReDb>=0 && iReDb!=iDb ) continue;
131547 for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
131548 pTab = (Table*)sqliteHashData(k);
131549 if( IsVirtual(pTab) ) continue;
131550 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
131551 if( bAll
131552 || pTab==pReTab
131553 || pIdx==pReIndex
131554 || (isExprIdx && pIdx->bHasExpr)
131555 || (zColl!=0 && collationMatch(zColl,pIdx))
131556 ){
131557 sqlite3BeginWriteOperation(pParse, 0, iDb);
131558 sqlite3RefillIndex(pParse, pIdx, -1);
131559 }
131560 } /* End loop over indexes of pTab */
131561 } /* End loop over tables of iDb */
131562 } /* End loop over databases */
131563 }else{
131564 sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
131565 }
131566 sqlite3DbFree(db, z);
131567 return;
131568 }
131569 #endif
131570
131571 /*
131572 ** Return a KeyInfo structure that is appropriate for the given Index.
@@ -142129,10 +142213,12 @@
142213 /* Version 3.52.0 and later */
142214 void (*str_truncate)(sqlite3_str*,int);
142215 void (*str_free)(sqlite3_str*);
142216 int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142217 int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
142218 /* Version 3.53.0 and later */
142219 double (*atof)(const char*);
142220 };
142221
142222 /*
142223 ** This is the function signature used for all extension entry points. It
142224 ** is also defined in the file "loadext.c".
@@ -142472,10 +142558,12 @@
142558 /* Version 3.52.0 and later */
142559 #define sqlite3_str_truncate sqlite3_api->str_truncate
142560 #define sqlite3_str_free sqlite3_api->str_free
142561 #define sqlite3_carray_bind sqlite3_api->carray_bind
142562 #define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
142563 /* Version 3.53.0 and later */
142564 #define sqlite3_atof sqlite3_api->atof
142565 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142566
142567 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142568 /* This case when the file really is being compiled as a loadable
142569 ** extension */
@@ -143004,15 +143092,16 @@
143092 /* Version 3.52.0 and later */
143093 sqlite3_str_truncate,
143094 sqlite3_str_free,
143095 #ifdef SQLITE_ENABLE_CARRAY
143096 sqlite3_carray_bind,
143097 sqlite3_carray_bind_v2,
143098 #else
143099 0,
143100 0,
 
143101 #endif
143102 sqlite3_atof
143103 };
143104
143105 /* True if x is the directory separator character
143106 */
143107 #if SQLITE_OS_WIN
@@ -172275,11 +172364,16 @@
172364 #endif
172365 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
172366 whereLoopOutputAdjust(pWC, pNew, rSize);
172367 if( pSrc->fg.isSubquery ){
172368 if( pSrc->fg.viaCoroutine ) pNew->wsFlags |= WHERE_COROUTINE;
172369 /* Do not set btree.pOrderBy for a recursive CTE. In this case
172370 ** the ORDER BY clause does not determine the overall order that
172371 ** rows are emitted from the CTE in. */
172372 if( (pSrc->u4.pSubq->pSelect->selFlags & SF_Recursive)==0 ){
172373 pNew->u.btree.pOrderBy = pSrc->u4.pSubq->pSelect->pOrderBy;
172374 }
172375 }else if( pSrc->fg.fromExists ){
172376 pNew->nOut = 0;
172377 }
172378 rc = whereLoopInsert(pBuilder, pNew);
172379 pNew->nOut = rSize;
@@ -212773,18 +212867,19 @@
212867 JsonParse *pParse, /* JSONB source or NULL */
212868 sqlite3_context *ctx /* Where to cache */
212869 ){
212870 assert( (pParse!=0)==(ctx!=0) );
212871 assert( ctx==0 || ctx==p->pCtx );
212872 jsonStringTerminate(p);
212873 if( p->eErr==0 ){
212874 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(p->pCtx));
212875 if( flags & JSON_BLOB ){
212876 jsonReturnStringAsBlob(p);
212877 }else if( p->bStatic ){
212878 sqlite3_result_text64(p->pCtx, p->zBuf, p->nUsed,
212879 SQLITE_TRANSIENT, SQLITE_UTF8);
212880 }else{
212881 if( pParse && pParse->bJsonIsRCStr==0 && pParse->nBlobAlloc>0 ){
212882 int rc;
212883 pParse->zJson = sqlite3RCStrRef(p->zBuf);
212884 pParse->nJson = p->nUsed;
212885 pParse->bJsonIsRCStr = 1;
@@ -212796,12 +212891,10 @@
212891 }
212892 }
212893 sqlite3_result_text64(p->pCtx, sqlite3RCStrRef(p->zBuf), p->nUsed,
212894 sqlite3RCStrUnref,
212895 SQLITE_UTF8);
 
 
212896 }
212897 }else if( p->eErr & JSTRING_OOM ){
212898 sqlite3_result_error_nomem(p->pCtx);
212899 }else if( p->eErr & JSTRING_MALFORMED ){
212900 sqlite3_result_error(p->pCtx, "malformed JSON", -1);
@@ -214011,16 +214104,12 @@
214104 ** this into the JSONB format and make it the return value of the
214105 ** SQL function.
214106 */
214107 static void jsonReturnStringAsBlob(JsonString *pStr){
214108 JsonParse px;
214109 assert( pStr->eErr==0 );
214110 memset(&px, 0, sizeof(px));
 
 
 
 
 
214111 px.zJson = pStr->zBuf;
214112 px.nJson = pStr->nUsed;
214113 px.db = sqlite3_context_db_handle(pStr->pCtx);
214114 (void)jsonTranslateTextToBlob(&px, 0);
214115 if( px.oom ){
@@ -216731,11 +216820,12 @@
216820 JsonString *pStr;
216821 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216822 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216823 if( pStr ){
216824 pStr->pCtx = ctx;
216825 jsonAppendRawNZ(pStr, "]", 2);
216826 jsonStringTrimOneChar(pStr);
216827 if( pStr->eErr ){
216828 jsonReturnString(pStr, 0, 0);
216829 return;
216830 }else if( flags & JSON_BLOB ){
216831 jsonReturnStringAsBlob(pStr);
@@ -216854,11 +216944,12 @@
216944 static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
216945 JsonString *pStr;
216946 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216947 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216948 if( pStr ){
216949 jsonAppendRawNZ(pStr, "}", 2);
216950 jsonStringTrimOneChar(pStr);
216951 pStr->pCtx = ctx;
216952 if( pStr->eErr ){
216953 jsonReturnString(pStr, 0, 0);
216954 return;
216955 }else if( flags & JSON_BLOB ){
@@ -259195,11 +259286,11 @@
259286 #if SQLITE_VERSION_NUMBER>=3008002
259287 #ifndef SQLITE_CORE
259288 if( sqlite3_libversion_number()>=3008002 )
259289 #endif
259290 {
259291 pIdxInfo->estimatedRows = MAX(1, nRow);
259292 }
259293 #endif
259294 }
259295
259296 static int fts5UsePatternMatch(
@@ -259264,23 +259355,34 @@
259355 ** Costs are assigned as follows:
259356 **
259357 ** a) If a MATCH operator is present, the cost depends on the other
259358 ** constraints also present. As follows:
259359 **
259360 ** * No other constraints: cost=50000.0
259361 ** * One rowid range constraint: cost=37500.0
259362 ** * Both rowid range constraints: cost=30000.0
259363 ** * An == rowid constraint: cost=25000.0
259364 **
259365 ** b) Otherwise, if there is no MATCH:
259366 **
259367 ** * No other constraints: cost=3000000.0
259368 ** * One rowid range constraints: cost=2250000.0
259369 ** * Both rowid range constraint: cost=750000.0
259370 ** * An == rowid constraint: cost=25.0
259371 **
259372 ** Costs are not modified by the ORDER BY clause.
259373 **
259374 ** The ratios used in case (a) are based on informal results obtained from
259375 ** the tool/fts5cost.tcl script. The "MATCH and ==" combination has the
259376 ** cost set quite high because the query may be a prefix query. Unless
259377 ** there is a prefix index, prefix queries with rowid constraints are much
259378 ** more expensive than non-prefix queries with rowid constraints.
259379 **
259380 ** The estimated rows returned is set to the cost/40. For simple queries,
259381 ** experimental results show that cost/4 might be about right. But for
259382 ** more complex queries that use multiple terms the number of rows might
259383 ** be far fewer than this. So we compromise and use cost/40.
259384 */
259385 static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
259386 Fts5Table *pTab = (Fts5Table*)pVTab;
259387 Fts5Config *pConfig = pTab->pConfig;
259388 const int nCol = pConfig->nCol;
@@ -259402,25 +259504,39 @@
259504 }
259505 }
259506
259507 /* Calculate the estimated cost based on the flags set in idxFlags. */
259508 if( bSeenEq ){
259509 pInfo->estimatedCost = nSeenMatch ? 25000.0 : 25.0;
 
259510 fts5SetEstimatedRows(pInfo, 1);
259511 fts5SetUniqueFlag(pInfo);
259512 }else{
259513 i64 nEstRows;
259514 if( nSeenMatch ){
259515 if( bSeenLt && bSeenGt ){
259516 pInfo->estimatedCost = 50000.0;
259517 }else if( bSeenLt || bSeenGt ){
259518 pInfo->estimatedCost = 37500.0;
259519 }else{
259520 pInfo->estimatedCost = 50000.0;
259521 }
259522 nEstRows = (i64)(pInfo->estimatedCost / 40.0);
259523 for(i=1; i<nSeenMatch; i++){
259524 pInfo->estimatedCost *= 2.5;
259525 nEstRows = nEstRows / 2;
259526 }
259527 }else{
259528 if( bSeenLt && bSeenGt ){
259529 pInfo->estimatedCost = 750000.0;
259530 }else if( bSeenLt || bSeenGt ){
259531 pInfo->estimatedCost = 2250000.0;
259532 }else{
259533 pInfo->estimatedCost = 3000000.0;
259534 }
259535 nEstRows = (i64)(pInfo->estimatedCost / 4.0);
259536 }
259537 fts5SetEstimatedRows(pInfo, nEstRows);
259538 }
259539
259540 pInfo->idxNum = idxFlags;
259541 return SQLITE_OK;
259542 }
@@ -262277,11 +262393,11 @@
262393 int nArg, /* Number of args */
262394 sqlite3_value **apUnused /* Function arguments */
262395 ){
262396 assert( nArg==0 );
262397 UNUSED_PARAM2(nArg, apUnused);
262398 sqlite3_result_text(pCtx, "fts5: 2026-03-23 12:25:52 1553a60506fa29b5f00535ae0f7aeb8cc94ebe84015386b3248fd8491108fc60", -1, SQLITE_TRANSIENT);
262399 }
262400
262401 /*
262402 ** Implementation of fts5_locale(LOCALE, TEXT) function.
262403 **
262404
+24 -2
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.53.0"
150150
#define SQLITE_VERSION_NUMBER 3053000
151
-#define SQLITE_SOURCE_ID "2026-03-18 22:31:56 5c237f1f863a32cf229010d2024d0d1e76a07a4d8b9492b26503b959f1c32485"
151
+#define SQLITE_SOURCE_ID "2026-03-23 13:00:56 276c350313a1ac2ebc70c1e8e50ed4baecd4be4d4c93ba04cf5e0078da18700e"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-03-18T22:31:56.220Z"
154
+#define SQLITE_SCM_DATETIME "2026-03-23T13:00:56.709Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -3228,10 +3228,32 @@
32283228
SQLITE_API char *sqlite3_mprintf(const char*,...);
32293229
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
32303230
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
32313231
SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
32323232
3233
+/*
3234
+** CAPI3REF: Text-to-float conversion
3235
+**
3236
+** The sqlite3_atof(X) interface returns a "double" derived from the
3237
+** text representation of a floating point value in X.
3238
+** This interface provides applications with access to the
3239
+** same text&rarr;float conversion routine used by SQLite for SQL parsing
3240
+** and type coercion. The sqlite3_atof(X) routine works like the standard
3241
+** C-library atof(X) routine with the following exceptions:
3242
+**
3243
+** <ul>
3244
+** <li> Parsing of the input X is strict. If anything about X
3245
+** is not well-formed, 0.0 is returned.
3246
+** <li> Special values such like "INF", "INFINITY", and "NAN" are not
3247
+** recognized.
3248
+** <li> Hexadecimal floating point literals are not recognized.
3249
+** <li> The current locale is ignored. The radix character is always ".".
3250
+** <li> The sqlite3_atof() interface does not set errno.
3251
+** </ul>
3252
+*/
3253
+SQLITE_API double sqlite3_atof(const char*);
3254
+
32333255
/*
32343256
** CAPI3REF: Memory Allocation Subsystem
32353257
**
32363258
** The SQLite core uses these three routines for all of its own
32373259
** internal memory allocation needs. "Core" in the previous sentence
32383260
--- 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-18 22:31:56 5c237f1f863a32cf229010d2024d0d1e76a07a4d8b9492b26503b959f1c32485"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-03-18T22:31:56.220Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -3228,10 +3228,32 @@
3228 SQLITE_API char *sqlite3_mprintf(const char*,...);
3229 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3230 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3231 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3233 /*
3234 ** CAPI3REF: Memory Allocation Subsystem
3235 **
3236 ** The SQLite core uses these three routines for all of its own
3237 ** internal memory allocation needs. "Core" in the previous sentence
3238
--- 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-23 13:00:56 276c350313a1ac2ebc70c1e8e50ed4baecd4be4d4c93ba04cf5e0078da18700e"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-03-23T13:00:56.709Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -3228,10 +3228,32 @@
3228 SQLITE_API char *sqlite3_mprintf(const char*,...);
3229 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3230 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3231 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3232
3233 /*
3234 ** CAPI3REF: Text-to-float conversion
3235 **
3236 ** The sqlite3_atof(X) interface returns a "double" derived from the
3237 ** text representation of a floating point value in X.
3238 ** This interface provides applications with access to the
3239 ** same text&rarr;float conversion routine used by SQLite for SQL parsing
3240 ** and type coercion. The sqlite3_atof(X) routine works like the standard
3241 ** C-library atof(X) routine with the following exceptions:
3242 **
3243 ** <ul>
3244 ** <li> Parsing of the input X is strict. If anything about X
3245 ** is not well-formed, 0.0 is returned.
3246 ** <li> Special values such like "INF", "INFINITY", and "NAN" are not
3247 ** recognized.
3248 ** <li> Hexadecimal floating point literals are not recognized.
3249 ** <li> The current locale is ignored. The radix character is always ".".
3250 ** <li> The sqlite3_atof() interface does not set errno.
3251 ** </ul>
3252 */
3253 SQLITE_API double sqlite3_atof(const char*);
3254
3255 /*
3256 ** CAPI3REF: Memory Allocation Subsystem
3257 **
3258 ** The SQLite core uses these three routines for all of its own
3259 ** internal memory allocation needs. "Core" in the previous sentence
3260
+1 -1
--- src/chat.c
+++ src/chat.c
@@ -349,11 +349,11 @@
349349
/*
350350
** Delete old content from the chat table.
351351
*/
352352
static void chat_purge(void){
353353
int mxCnt = db_get_int("chat-keep-count",50);
354
- double mxDays = atof(db_get("chat-keep-days","7"));
354
+ double mxDays = fossil_atof(db_get("chat-keep-days","7"));
355355
double rAge;
356356
int msgid;
357357
rAge = db_double(0.0, "SELECT julianday('now')-mtime FROM chat"
358358
" ORDER BY msgid LIMIT 1");
359359
if( rAge>mxDays ){
360360
--- src/chat.c
+++ src/chat.c
@@ -349,11 +349,11 @@
349 /*
350 ** Delete old content from the chat table.
351 */
352 static void chat_purge(void){
353 int mxCnt = db_get_int("chat-keep-count",50);
354 double mxDays = atof(db_get("chat-keep-days","7"));
355 double rAge;
356 int msgid;
357 rAge = db_double(0.0, "SELECT julianday('now')-mtime FROM chat"
358 " ORDER BY msgid LIMIT 1");
359 if( rAge>mxDays ){
360
--- src/chat.c
+++ src/chat.c
@@ -349,11 +349,11 @@
349 /*
350 ** Delete old content from the chat table.
351 */
352 static void chat_purge(void){
353 int mxCnt = db_get_int("chat-keep-count",50);
354 double mxDays = fossil_atof(db_get("chat-keep-days","7"));
355 double rAge;
356 int msgid;
357 rAge = db_double(0.0, "SELECT julianday('now')-mtime FROM chat"
358 " ORDER BY msgid LIMIT 1");
359 if( rAge>mxDays ){
360
--- src/config.h
+++ src/config.h
@@ -56,10 +56,11 @@
5656
#include <stdlib.h>
5757
/* #include <ctype.h> // do not use - causes problems */
5858
#include <string.h>
5959
#include <stdarg.h>
6060
#include <assert.h>
61
+#include "sqlite3.h"
6162
6263
#endif
6364
6465
#if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
6566
# if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
6667
--- src/config.h
+++ src/config.h
@@ -56,10 +56,11 @@
56 #include <stdlib.h>
57 /* #include <ctype.h> // do not use - causes problems */
58 #include <string.h>
59 #include <stdarg.h>
60 #include <assert.h>
 
61
62 #endif
63
64 #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
65 # if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
66
--- src/config.h
+++ src/config.h
@@ -56,10 +56,11 @@
56 #include <stdlib.h>
57 /* #include <ctype.h> // do not use - causes problems */
58 #include <string.h>
59 #include <stdarg.h>
60 #include <assert.h>
61 #include "sqlite3.h"
62
63 #endif
64
65 #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
66 # if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
67
+2 -1
--- src/diff.c
+++ src/diff.c
@@ -3609,11 +3609,12 @@
36093609
iLimit = 0;
36103610
mxTime = 0;
36113611
}else if( sqlite3_strglob("*[0-9]s", zLimit)==0 ){
36123612
iLimit = 0;
36133613
mxTime =
3614
- (sqlite3_int64)(current_time_in_milliseconds() + 1000.0*atof(zLimit));
3614
+ (sqlite3_int64)(current_time_in_milliseconds() +
3615
+ 1000.0*fossil_atof(zLimit));
36153616
}else{
36163617
iLimit = atoi(zLimit);
36173618
if( iLimit<=0 ) iLimit = 30;
36183619
mxTime = 0;
36193620
}
36203621
--- src/diff.c
+++ src/diff.c
@@ -3609,11 +3609,12 @@
3609 iLimit = 0;
3610 mxTime = 0;
3611 }else if( sqlite3_strglob("*[0-9]s", zLimit)==0 ){
3612 iLimit = 0;
3613 mxTime =
3614 (sqlite3_int64)(current_time_in_milliseconds() + 1000.0*atof(zLimit));
 
3615 }else{
3616 iLimit = atoi(zLimit);
3617 if( iLimit<=0 ) iLimit = 30;
3618 mxTime = 0;
3619 }
3620
--- src/diff.c
+++ src/diff.c
@@ -3609,11 +3609,12 @@
3609 iLimit = 0;
3610 mxTime = 0;
3611 }else if( sqlite3_strglob("*[0-9]s", zLimit)==0 ){
3612 iLimit = 0;
3613 mxTime =
3614 (sqlite3_int64)(current_time_in_milliseconds() +
3615 1000.0*fossil_atof(zLimit));
3616 }else{
3617 iLimit = atoi(zLimit);
3618 if( iLimit<=0 ) iLimit = 30;
3619 mxTime = 0;
3620 }
3621
+2 -2
--- src/loadctrl.c
+++ src/loadctrl.c
@@ -52,11 +52,11 @@
5252
** Generate the response that would normally be shown only when
5353
** service is denied due to an overload condition. This is for
5454
** testing of the overload warning page.
5555
*/
5656
void overload_page(void){
57
- double mxLoad = atof(db_get("max-loadavg", "0.0"));
57
+ double mxLoad = fossil_atof(db_get("max-loadavg", "0.0"));
5858
style_set_current_feature("test");
5959
style_header("Server Overload");
6060
@ <h2>The server load is currently too high.
6161
@ Please try again later.</h2>
6262
@ <p>Current load average: %f(load_average())<br>
@@ -70,11 +70,11 @@
7070
** Abort the current page request if the load average of the host
7171
** computer is too high. Admin and Setup users are exempt from this
7272
** restriction.
7373
*/
7474
void load_control(void){
75
- double mxLoad = atof(db_get("max-loadavg", "0.0"));
75
+ double mxLoad = fossil_atof(db_get("max-loadavg", "0.0"));
7676
#if 1
7777
/* Disable this block only to test load restrictions */
7878
if( mxLoad<=0.0 || mxLoad>=load_average() ) return;
7979
8080
login_check_credentials();
8181
--- src/loadctrl.c
+++ src/loadctrl.c
@@ -52,11 +52,11 @@
52 ** Generate the response that would normally be shown only when
53 ** service is denied due to an overload condition. This is for
54 ** testing of the overload warning page.
55 */
56 void overload_page(void){
57 double mxLoad = atof(db_get("max-loadavg", "0.0"));
58 style_set_current_feature("test");
59 style_header("Server Overload");
60 @ <h2>The server load is currently too high.
61 @ Please try again later.</h2>
62 @ <p>Current load average: %f(load_average())<br>
@@ -70,11 +70,11 @@
70 ** Abort the current page request if the load average of the host
71 ** computer is too high. Admin and Setup users are exempt from this
72 ** restriction.
73 */
74 void load_control(void){
75 double mxLoad = atof(db_get("max-loadavg", "0.0"));
76 #if 1
77 /* Disable this block only to test load restrictions */
78 if( mxLoad<=0.0 || mxLoad>=load_average() ) return;
79
80 login_check_credentials();
81
--- src/loadctrl.c
+++ src/loadctrl.c
@@ -52,11 +52,11 @@
52 ** Generate the response that would normally be shown only when
53 ** service is denied due to an overload condition. This is for
54 ** testing of the overload warning page.
55 */
56 void overload_page(void){
57 double mxLoad = fossil_atof(db_get("max-loadavg", "0.0"));
58 style_set_current_feature("test");
59 style_header("Server Overload");
60 @ <h2>The server load is currently too high.
61 @ Please try again later.</h2>
62 @ <p>Current load average: %f(load_average())<br>
@@ -70,11 +70,11 @@
70 ** Abort the current page request if the load average of the host
71 ** computer is too high. Admin and Setup users are exempt from this
72 ** restriction.
73 */
74 void load_control(void){
75 double mxLoad = fossil_atof(db_get("max-loadavg", "0.0"));
76 #if 1
77 /* Disable this block only to test load restrictions */
78 if( mxLoad<=0.0 || mxLoad>=load_average() ) return;
79
80 login_check_credentials();
81
+1 -1
--- src/login.c
+++ src/login.c
@@ -1449,11 +1449,11 @@
14491449
** the sha1 hash of TIME/USERAGENT/SECRET must match HASH. USERAGENT
14501450
** is the HTTP_USER_AGENT of the client and SECRET is the
14511451
** "captcha-secret" value in the repository. See tag-20250817a
14521452
** for the code the creates this cookie.
14531453
*/
1454
- double rTime = atof(zArg);
1454
+ double rTime = fossil_atof(zArg);
14551455
const char *zUserAgent = PD("HTTP_USER_AGENT","nil");
14561456
Blob b;
14571457
char *zSecret;
14581458
int n = 0;
14591459
14601460
--- src/login.c
+++ src/login.c
@@ -1449,11 +1449,11 @@
1449 ** the sha1 hash of TIME/USERAGENT/SECRET must match HASH. USERAGENT
1450 ** is the HTTP_USER_AGENT of the client and SECRET is the
1451 ** "captcha-secret" value in the repository. See tag-20250817a
1452 ** for the code the creates this cookie.
1453 */
1454 double rTime = atof(zArg);
1455 const char *zUserAgent = PD("HTTP_USER_AGENT","nil");
1456 Blob b;
1457 char *zSecret;
1458 int n = 0;
1459
1460
--- src/login.c
+++ src/login.c
@@ -1449,11 +1449,11 @@
1449 ** the sha1 hash of TIME/USERAGENT/SECRET must match HASH. USERAGENT
1450 ** is the HTTP_USER_AGENT of the client and SECRET is the
1451 ** "captcha-secret" value in the repository. See tag-20250817a
1452 ** for the code the creates this cookie.
1453 */
1454 double rTime = fossil_atof(zArg);
1455 const char *zUserAgent = PD("HTTP_USER_AGENT","nil");
1456 Blob b;
1457 char *zSecret;
1458 int n = 0;
1459
1460
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -723,18 +723,18 @@
723723
if( zPikVar && zPikVar[0] ){
724724
blob_appendf(&bSrc, "bgcolor = %s\n", zPikVar);
725725
}
726726
zPikVar = skin_detail("pikchr-scale");
727727
if( zPikVar
728
- && (rPikVar = atof(zPikVar))>=0.1
728
+ && (rPikVar = fossil_atof(zPikVar))>=0.1
729729
&& rPikVar<10.0
730730
){
731731
blob_appendf(&bSrc, "scale = %.13g\n", rPikVar);
732732
}
733733
zPikVar = skin_detail("pikchr-fontscale");
734734
if( zPikVar
735
- && (rPikVar = atof(zPikVar))>=0.1
735
+ && (rPikVar = fossil_atof(zPikVar))>=0.1
736736
&& rPikVar<10.0
737737
){
738738
blob_appendf(&bSrc, "fontscale = %.13g\n", rPikVar);
739739
}
740740
blob_append(&bSrc, zSrc, nSrc)
741741
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -723,18 +723,18 @@
723 if( zPikVar && zPikVar[0] ){
724 blob_appendf(&bSrc, "bgcolor = %s\n", zPikVar);
725 }
726 zPikVar = skin_detail("pikchr-scale");
727 if( zPikVar
728 && (rPikVar = atof(zPikVar))>=0.1
729 && rPikVar<10.0
730 ){
731 blob_appendf(&bSrc, "scale = %.13g\n", rPikVar);
732 }
733 zPikVar = skin_detail("pikchr-fontscale");
734 if( zPikVar
735 && (rPikVar = atof(zPikVar))>=0.1
736 && rPikVar<10.0
737 ){
738 blob_appendf(&bSrc, "fontscale = %.13g\n", rPikVar);
739 }
740 blob_append(&bSrc, zSrc, nSrc)
741
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -723,18 +723,18 @@
723 if( zPikVar && zPikVar[0] ){
724 blob_appendf(&bSrc, "bgcolor = %s\n", zPikVar);
725 }
726 zPikVar = skin_detail("pikchr-scale");
727 if( zPikVar
728 && (rPikVar = fossil_atof(zPikVar))>=0.1
729 && rPikVar<10.0
730 ){
731 blob_appendf(&bSrc, "scale = %.13g\n", rPikVar);
732 }
733 zPikVar = skin_detail("pikchr-fontscale");
734 if( zPikVar
735 && (rPikVar = fossil_atof(zPikVar))>=0.1
736 && rPikVar<10.0
737 ){
738 blob_appendf(&bSrc, "fontscale = %.13g\n", rPikVar);
739 }
740 blob_append(&bSrc, zSrc, nSrc)
741
+1 -1
--- src/piechart.c
+++ src/piechart.c
@@ -296,11 +296,11 @@
296296
if( zData[j]=='.' ){
297297
j++;
298298
while( fossil_isdigit(zData[j]) ){ j++; }
299299
}
300300
if( i==j ) break;
301
- rAmt = atof(&zData[i]);
301
+ rAmt = fossil_atof(&zData[i]);
302302
i = j;
303303
while( zData[i]==',' || fossil_isspace(zData[i]) ){ i++; }
304304
n++;
305305
zLabel = mprintf("label%02d-%g", n, rAmt);
306306
db_bind_double(&ins, ":amt", rAmt);
307307
--- src/piechart.c
+++ src/piechart.c
@@ -296,11 +296,11 @@
296 if( zData[j]=='.' ){
297 j++;
298 while( fossil_isdigit(zData[j]) ){ j++; }
299 }
300 if( i==j ) break;
301 rAmt = atof(&zData[i]);
302 i = j;
303 while( zData[i]==',' || fossil_isspace(zData[i]) ){ i++; }
304 n++;
305 zLabel = mprintf("label%02d-%g", n, rAmt);
306 db_bind_double(&ins, ":amt", rAmt);
307
--- src/piechart.c
+++ src/piechart.c
@@ -296,11 +296,11 @@
296 if( zData[j]=='.' ){
297 j++;
298 while( fossil_isdigit(zData[j]) ){ j++; }
299 }
300 if( i==j ) break;
301 rAmt = fossil_atof(&zData[i]);
302 i = j;
303 while( zData[i]==',' || fossil_isspace(zData[i]) ){ i++; }
304 n++;
305 zLabel = mprintf("label%02d-%g", n, rAmt);
306 db_bind_double(&ins, ":amt", rAmt);
307
+1 -1
--- src/pqueue.c
+++ src/pqueue.c
@@ -213,11 +213,11 @@
213213
}else{
214214
fossil_print("%2d: POP \"%s\"\n", i, zId);
215215
}
216216
if( bDebug) pqueuex_test_print(&x);
217217
}else{
218
- double r = atof(zArg);
218
+ double r = fossil_atof(zArg);
219219
zId = strchr(zArg,'/');
220220
if( zId==0 ) zId = zArg;
221221
if( zId[0]=='/' ) zId++;
222222
pqueuex_insert_ptr(&x, (void*)zId, r);
223223
fossil_print("%2d: INSERT \"%s\"\n", i, zId);
224224
--- src/pqueue.c
+++ src/pqueue.c
@@ -213,11 +213,11 @@
213 }else{
214 fossil_print("%2d: POP \"%s\"\n", i, zId);
215 }
216 if( bDebug) pqueuex_test_print(&x);
217 }else{
218 double r = atof(zArg);
219 zId = strchr(zArg,'/');
220 if( zId==0 ) zId = zArg;
221 if( zId[0]=='/' ) zId++;
222 pqueuex_insert_ptr(&x, (void*)zId, r);
223 fossil_print("%2d: INSERT \"%s\"\n", i, zId);
224
--- src/pqueue.c
+++ src/pqueue.c
@@ -213,11 +213,11 @@
213 }else{
214 fossil_print("%2d: POP \"%s\"\n", i, zId);
215 }
216 if( bDebug) pqueuex_test_print(&x);
217 }else{
218 double r = fossil_atof(zArg);
219 zId = strchr(zArg,'/');
220 if( zId==0 ) zId = zArg;
221 if( zId[0]=='/' ) zId++;
222 pqueuex_insert_ptr(&x, (void*)zId, r);
223 fossil_print("%2d: INSERT \"%s\"\n", i, zId);
224
+11
--- src/printf.c
+++ src/printf.c
@@ -1301,10 +1301,21 @@
13011301
fossil_trace("%s\n", z);
13021302
}
13031303
}
13041304
free(z);
13051305
}
1306
+
1307
+/*
1308
+** Convert text floating-point literals into double.
1309
+*/
1310
+double fossil_atof(const char *z){
1311
+#if SQLITE_VERSION_NUMBER>=3053000
1312
+ return sqlite3_atof(z);
1313
+#else
1314
+ return atof(z);
1315
+#endif
1316
+}
13061317
13071318
/*
13081319
** Turn off any LF to CRLF translation on the stream given as an
13091320
** argument. This is a no-op on unix but is necessary on windows.
13101321
*/
13111322
--- src/printf.c
+++ src/printf.c
@@ -1301,10 +1301,21 @@
1301 fossil_trace("%s\n", z);
1302 }
1303 }
1304 free(z);
1305 }
 
 
 
 
 
 
 
 
 
 
 
1306
1307 /*
1308 ** Turn off any LF to CRLF translation on the stream given as an
1309 ** argument. This is a no-op on unix but is necessary on windows.
1310 */
1311
--- src/printf.c
+++ src/printf.c
@@ -1301,10 +1301,21 @@
1301 fossil_trace("%s\n", z);
1302 }
1303 }
1304 free(z);
1305 }
1306
1307 /*
1308 ** Convert text floating-point literals into double.
1309 */
1310 double fossil_atof(const char *z){
1311 #if SQLITE_VERSION_NUMBER>=3053000
1312 return sqlite3_atof(z);
1313 #else
1314 return atof(z);
1315 #endif
1316 }
1317
1318 /*
1319 ** Turn off any LF to CRLF translation on the stream given as an
1320 ** argument. This is a no-op on unix but is necessary on windows.
1321 */
1322
--- src/security_audit.c
+++ src/security_audit.c
@@ -589,11 +589,11 @@
589589
@ from throttling expensive operations during peak demand.
590590
@ If running in a chroot jail on Linux, verify that the /proc
591591
@ filesystem is mounted within the jail, so that the load average
592592
@ can be obtained from the /proc/loadavg file.
593593
}else {
594
- double r = atof(db_get("max-loadavg", "0.0"));
594
+ double r = fossil_atof(db_get("max-loadavg", "0.0"));
595595
if( r<=0.0 ){
596596
@ <li><p>
597597
@ Load average limiting is turned off. This can cause the server
598598
@ to bog down if many requests for expensive services (such as
599599
@ large diffs or tarballs) arrive at about the same time.
@@ -726,11 +726,11 @@
726726
case 2:
727727
@ <li> Hyperlinks auto-enabled based on UserAgent only.
728728
break;
729729
}
730730
z = db_get("max-loadavg",0);
731
- if( z && atof(z)>0.0 ){
731
+ if( z && fossil_atof(z)>0.0 ){
732732
@ <li> Maximum load average for expensive requests: %h(z);
733733
}else{
734734
@ <li> No limits on the load average
735735
}
736736
z = db_get("robot-restrict",0);
737737
--- src/security_audit.c
+++ src/security_audit.c
@@ -589,11 +589,11 @@
589 @ from throttling expensive operations during peak demand.
590 @ If running in a chroot jail on Linux, verify that the /proc
591 @ filesystem is mounted within the jail, so that the load average
592 @ can be obtained from the /proc/loadavg file.
593 }else {
594 double r = atof(db_get("max-loadavg", "0.0"));
595 if( r<=0.0 ){
596 @ <li><p>
597 @ Load average limiting is turned off. This can cause the server
598 @ to bog down if many requests for expensive services (such as
599 @ large diffs or tarballs) arrive at about the same time.
@@ -726,11 +726,11 @@
726 case 2:
727 @ <li> Hyperlinks auto-enabled based on UserAgent only.
728 break;
729 }
730 z = db_get("max-loadavg",0);
731 if( z && atof(z)>0.0 ){
732 @ <li> Maximum load average for expensive requests: %h(z);
733 }else{
734 @ <li> No limits on the load average
735 }
736 z = db_get("robot-restrict",0);
737
--- src/security_audit.c
+++ src/security_audit.c
@@ -589,11 +589,11 @@
589 @ from throttling expensive operations during peak demand.
590 @ If running in a chroot jail on Linux, verify that the /proc
591 @ filesystem is mounted within the jail, so that the load average
592 @ can be obtained from the /proc/loadavg file.
593 }else {
594 double r = fossil_atof(db_get("max-loadavg", "0.0"));
595 if( r<=0.0 ){
596 @ <li><p>
597 @ Load average limiting is turned off. This can cause the server
598 @ to bog down if many requests for expensive services (such as
599 @ large diffs or tarballs) arrive at about the same time.
@@ -726,11 +726,11 @@
726 case 2:
727 @ <li> Hyperlinks auto-enabled based on UserAgent only.
728 break;
729 }
730 z = db_get("max-loadavg",0);
731 if( z && fossil_atof(z)>0.0 ){
732 @ <li> Maximum load average for expensive requests: %h(z);
733 }else{
734 @ <li> No limits on the load average
735 }
736 z = db_get("robot-restrict",0);
737
+1 -1
--- src/tar.c
+++ src/tar.c
@@ -1182,11 +1182,11 @@
11821182
zLabel = fossil_strndup(azItem[i+1],anItem[i+1]);
11831183
if( anItem[i+2]==0 ){
11841184
rStart = 0.0;
11851185
}else{
11861186
char *zMax = fossil_strndup(azItem[i+2], anItem[i+2]);
1187
- double r = atof(zMax);
1187
+ double r = fossil_atof(zMax);
11881188
if( strstr(zMax,"sec") ){
11891189
rStart = rNow - r/86400.0;
11901190
}else
11911191
if( strstr(zMax,"hou") ){
11921192
rStart = rNow - r/24.0;
11931193
--- src/tar.c
+++ src/tar.c
@@ -1182,11 +1182,11 @@
1182 zLabel = fossil_strndup(azItem[i+1],anItem[i+1]);
1183 if( anItem[i+2]==0 ){
1184 rStart = 0.0;
1185 }else{
1186 char *zMax = fossil_strndup(azItem[i+2], anItem[i+2]);
1187 double r = atof(zMax);
1188 if( strstr(zMax,"sec") ){
1189 rStart = rNow - r/86400.0;
1190 }else
1191 if( strstr(zMax,"hou") ){
1192 rStart = rNow - r/24.0;
1193
--- src/tar.c
+++ src/tar.c
@@ -1182,11 +1182,11 @@
1182 zLabel = fossil_strndup(azItem[i+1],anItem[i+1]);
1183 if( anItem[i+2]==0 ){
1184 rStart = 0.0;
1185 }else{
1186 char *zMax = fossil_strndup(azItem[i+2], anItem[i+2]);
1187 double r = fossil_atof(zMax);
1188 if( strstr(zMax,"sec") ){
1189 rStart = rNow - r/86400.0;
1190 }else
1191 if( strstr(zMax,"hou") ){
1192 rStart = rNow - r/24.0;
1193
+3 -69
--- src/th.c
+++ src/th.c
@@ -12,10 +12,11 @@
1212
/*
1313
** External routines
1414
*/
1515
void fossil_panic(const char*,...);
1616
void fossil_errorlog(const char*,...);
17
+double fossil_atof(const char*);
1718
1819
/*
1920
** Values used for element values in the tcl_platform array.
2021
*/
2122
@@ -2749,76 +2750,10 @@
27492750
if( realnum ) *realnum = 1;
27502751
}
27512752
return *z==0;
27522753
}
27532754
2754
-/*
2755
-** The string z[] is an ascii representation of a real number.
2756
-** Convert this string to a double.
2757
-**
2758
-** This routine assumes that z[] really is a valid number. If it
2759
-** is not, the result is undefined.
2760
-**
2761
-** This routine is used instead of the library atof() function because
2762
-** the library atof() might want to use "," as the decimal point instead
2763
-** of "." depending on how locale is set. But that would cause problems
2764
-** for SQL. So this routine always uses "." regardless of locale.
2765
-*/
2766
-static int sqlite3AtoF(const char *z, double *pResult){
2767
- int sign = 1;
2768
- const char *zBegin = z;
2769
- LONGDOUBLE_TYPE v1 = 0.0;
2770
- while( th_isspace(*(u8*)z) ) z++;
2771
- if( *z=='-' ){
2772
- sign = -1;
2773
- z++;
2774
- }else if( *z=='+' ){
2775
- z++;
2776
- }
2777
- while( th_isdigit(*(u8*)z) ){
2778
- v1 = v1*10.0 + (*z - '0');
2779
- z++;
2780
- }
2781
- if( *z=='.' ){
2782
- LONGDOUBLE_TYPE divisor = 1.0;
2783
- z++;
2784
- while( th_isdigit(*(u8*)z) ){
2785
- v1 = v1*10.0 + (*z - '0');
2786
- divisor *= 10.0;
2787
- z++;
2788
- }
2789
- v1 /= divisor;
2790
- }
2791
- if( *z=='e' || *z=='E' ){
2792
- int esign = 1;
2793
- int eval = 0;
2794
- LONGDOUBLE_TYPE scale = 1.0;
2795
- z++;
2796
- if( *z=='-' ){
2797
- esign = -1;
2798
- z++;
2799
- }else if( *z=='+' ){
2800
- z++;
2801
- }
2802
- while( th_isdigit(*(u8*)z) ){
2803
- eval = eval*10 + *z - '0';
2804
- z++;
2805
- }
2806
- while( eval>=64 ){ scale *= 1.0e+64; eval -= 64; }
2807
- while( eval>=16 ){ scale *= 1.0e+16; eval -= 16; }
2808
- while( eval>=4 ){ scale *= 1.0e+4; eval -= 4; }
2809
- while( eval>=1 ){ scale *= 1.0e+1; eval -= 1; }
2810
- if( esign<0 ){
2811
- v1 /= scale;
2812
- }else{
2813
- v1 *= scale;
2814
- }
2815
- }
2816
- *pResult = sign<0 ? -v1 : v1;
2817
- return z - zBegin;
2818
-}
2819
-
28202755
/*
28212756
** Try to convert the string passed as arguments (z, n) to an integer.
28222757
** If successful, store the result in *piOut and return TH_OK.
28232758
**
28242759
** If the string cannot be converted to an integer, return TH_ERROR.
@@ -2891,16 +2826,15 @@
28912826
Th_Interp *interp,
28922827
const char *z,
28932828
int n,
28942829
double *pfOut
28952830
){
2896
- if( !sqlite3IsNumber((const char *)z, 0) ){
2831
+ *pfOut = fossil_atof(z);
2832
+ if( 0.0==(*pfOut) && !sqlite3IsNumber((const char *)z, 0) ){
28972833
Th_ErrorMessage(interp, "expected number, got: \"", z, TH1_LEN(n));
28982834
return TH_ERROR;
28992835
}
2900
-
2901
- sqlite3AtoF((const char *)z, pfOut);
29022836
return TH_OK;
29032837
}
29042838
29052839
/*
29062840
** Set the result of the interpreter to the th1 representation of
29072841
--- src/th.c
+++ src/th.c
@@ -12,10 +12,11 @@
12 /*
13 ** External routines
14 */
15 void fossil_panic(const char*,...);
16 void fossil_errorlog(const char*,...);
 
17
18 /*
19 ** Values used for element values in the tcl_platform array.
20 */
21
@@ -2749,76 +2750,10 @@
2749 if( realnum ) *realnum = 1;
2750 }
2751 return *z==0;
2752 }
2753
2754 /*
2755 ** The string z[] is an ascii representation of a real number.
2756 ** Convert this string to a double.
2757 **
2758 ** This routine assumes that z[] really is a valid number. If it
2759 ** is not, the result is undefined.
2760 **
2761 ** This routine is used instead of the library atof() function because
2762 ** the library atof() might want to use "," as the decimal point instead
2763 ** of "." depending on how locale is set. But that would cause problems
2764 ** for SQL. So this routine always uses "." regardless of locale.
2765 */
2766 static int sqlite3AtoF(const char *z, double *pResult){
2767 int sign = 1;
2768 const char *zBegin = z;
2769 LONGDOUBLE_TYPE v1 = 0.0;
2770 while( th_isspace(*(u8*)z) ) z++;
2771 if( *z=='-' ){
2772 sign = -1;
2773 z++;
2774 }else if( *z=='+' ){
2775 z++;
2776 }
2777 while( th_isdigit(*(u8*)z) ){
2778 v1 = v1*10.0 + (*z - '0');
2779 z++;
2780 }
2781 if( *z=='.' ){
2782 LONGDOUBLE_TYPE divisor = 1.0;
2783 z++;
2784 while( th_isdigit(*(u8*)z) ){
2785 v1 = v1*10.0 + (*z - '0');
2786 divisor *= 10.0;
2787 z++;
2788 }
2789 v1 /= divisor;
2790 }
2791 if( *z=='e' || *z=='E' ){
2792 int esign = 1;
2793 int eval = 0;
2794 LONGDOUBLE_TYPE scale = 1.0;
2795 z++;
2796 if( *z=='-' ){
2797 esign = -1;
2798 z++;
2799 }else if( *z=='+' ){
2800 z++;
2801 }
2802 while( th_isdigit(*(u8*)z) ){
2803 eval = eval*10 + *z - '0';
2804 z++;
2805 }
2806 while( eval>=64 ){ scale *= 1.0e+64; eval -= 64; }
2807 while( eval>=16 ){ scale *= 1.0e+16; eval -= 16; }
2808 while( eval>=4 ){ scale *= 1.0e+4; eval -= 4; }
2809 while( eval>=1 ){ scale *= 1.0e+1; eval -= 1; }
2810 if( esign<0 ){
2811 v1 /= scale;
2812 }else{
2813 v1 *= scale;
2814 }
2815 }
2816 *pResult = sign<0 ? -v1 : v1;
2817 return z - zBegin;
2818 }
2819
2820 /*
2821 ** Try to convert the string passed as arguments (z, n) to an integer.
2822 ** If successful, store the result in *piOut and return TH_OK.
2823 **
2824 ** If the string cannot be converted to an integer, return TH_ERROR.
@@ -2891,16 +2826,15 @@
2891 Th_Interp *interp,
2892 const char *z,
2893 int n,
2894 double *pfOut
2895 ){
2896 if( !sqlite3IsNumber((const char *)z, 0) ){
 
2897 Th_ErrorMessage(interp, "expected number, got: \"", z, TH1_LEN(n));
2898 return TH_ERROR;
2899 }
2900
2901 sqlite3AtoF((const char *)z, pfOut);
2902 return TH_OK;
2903 }
2904
2905 /*
2906 ** Set the result of the interpreter to the th1 representation of
2907
--- src/th.c
+++ src/th.c
@@ -12,10 +12,11 @@
12 /*
13 ** External routines
14 */
15 void fossil_panic(const char*,...);
16 void fossil_errorlog(const char*,...);
17 double fossil_atof(const char*);
18
19 /*
20 ** Values used for element values in the tcl_platform array.
21 */
22
@@ -2749,76 +2750,10 @@
2750 if( realnum ) *realnum = 1;
2751 }
2752 return *z==0;
2753 }
2754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2755 /*
2756 ** Try to convert the string passed as arguments (z, n) to an integer.
2757 ** If successful, store the result in *piOut and return TH_OK.
2758 **
2759 ** If the string cannot be converted to an integer, return TH_ERROR.
@@ -2891,16 +2826,15 @@
2826 Th_Interp *interp,
2827 const char *z,
2828 int n,
2829 double *pfOut
2830 ){
2831 *pfOut = fossil_atof(z);
2832 if( 0.0==(*pfOut) && !sqlite3IsNumber((const char *)z, 0) ){
2833 Th_ErrorMessage(interp, "expected number, got: \"", z, TH1_LEN(n));
2834 return TH_ERROR;
2835 }
 
 
2836 return TH_OK;
2837 }
2838
2839 /*
2840 ** Set the result of the interpreter to the th1 representation of
2841

Keyboard Shortcuts

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