Fossil SCM

Back out the use of sqlite3_atof(), as that interface has been removed from the 3.53.0 release. Update the built-in SQLite to the latest 3.53.0 beta for testing.

drh 2026-03-26 23:08 trunk
Commit a10f931ba1f9a90add133a00849ece100986554956da0ba88a609fe36669a745
+774 -771
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -59,10 +59,26 @@
5959
#define _CRT_SECURE_NO_WARNINGS
6060
#endif
6161
typedef unsigned int u32;
6262
typedef unsigned short int u16;
6363
64
+/*
65
+** Limit input nesting via .read or any other input redirect.
66
+** It's not too expensive, so a generous allowance can be made.
67
+*/
68
+#define MAX_INPUT_NESTING 25
69
+
70
+/*
71
+** Used to prevent warnings about unused parameters
72
+*/
73
+#define UNUSED_PARAMETER(x) (void)(x)
74
+
75
+/*
76
+** Number of elements in an array
77
+*/
78
+#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
79
+
6480
/*
6581
** Optionally #include a user-defined header, whereby compilation options
6682
** may be set prior to where they take effect, but after platform setup.
6783
** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
6884
** file. Note that this macro has a like effect on sqlite3.c compilation.
@@ -3879,774 +3895,10 @@
38793895
# define SQLITE_CIO_NO_TRANSLATE
38803896
# define SQLITE_CIO_NO_SETMODE
38813897
# define SQLITE_CIO_NO_FLUSH
38823898
#endif
38833899
3884
-/*
3885
-** Output routines that are able to redirect to memory rather than
3886
-** doing actually I/O.
3887
-** Works like.
3888
-** --------------
3889
-** cli_printf(FILE*, const char*, ...); fprintf()
3890
-** cli_puts(const char*, FILE*); fputs()
3891
-** cli_vprintf(FILE*, const char*, va_list); vfprintf()
3892
-**
3893
-** These are just thin wrappers with the following added semantics:
3894
-** If the file-scope variable cli_output_capture is not NULL, and
3895
-** if the FILE* argument is stdout or stderr, then rather than
3896
-** writing to stdout/stdout, append the text to the cli_output_capture
3897
-** variable.
3898
-**
3899
-** The cli_exit(int) routine works like exit() except that it
3900
-** first dumps any capture output to stdout.
3901
-*/
3902
-static sqlite3_str *cli_output_capture = 0;
3903
-static int cli_printf(FILE *out, const char *zFormat, ...){
3904
- va_list ap;
3905
- int rc;
3906
- va_start(ap,zFormat);
3907
- if( cli_output_capture && (out==stdout || out==stderr) ){
3908
- sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
3909
- rc = 1;
3910
- }else{
3911
- rc = sqlite3_vfprintf(out, zFormat, ap);
3912
- }
3913
- va_end(ap);
3914
- return rc;
3915
-}
3916
-static int cli_puts(const char *zText, FILE *out){
3917
- if( cli_output_capture && (out==stdout || out==stderr) ){
3918
- sqlite3_str_appendall(cli_output_capture, zText);
3919
- return 1;
3920
- }
3921
- return sqlite3_fputs(zText, out);
3922
-}
3923
-#if 0 /* Not currently used - available if we need it later */
3924
-static int cli_vprintf(FILE *out, const char *zFormat, va_list ap){
3925
- if( cli_output_capture && (out==stdout || out==stderr) ){
3926
- sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
3927
- return 1;
3928
- }else{
3929
- return sqlite3_vfprintf(out, zFormat, ap);
3930
- }
3931
-}
3932
-#endif
3933
-static void cli_exit(int rc){
3934
- if( cli_output_capture ){
3935
- char *z = sqlite3_str_finish(cli_output_capture);
3936
- sqlite3_fputs(z, stdout);
3937
- fflush(stdout);
3938
- }
3939
- exit(rc);
3940
-}
3941
-
3942
-
3943
-#define eputz(z) cli_puts(z,stderr)
3944
-#define sputz(fp,z) cli_puts(z,fp)
3945
-
3946
-/* A version of strcmp() that works with NULL values */
3947
-static int cli_strcmp(const char *a, const char *b){
3948
- if( a==0 ) a = "";
3949
- if( b==0 ) b = "";
3950
- return strcmp(a,b);
3951
-}
3952
-static int cli_strncmp(const char *a, const char *b, size_t n){
3953
- if( a==0 ) a = "";
3954
- if( b==0 ) b = "";
3955
- return strncmp(a,b,n);
3956
-}
3957
-
3958
-/* Return the current wall-clock time in microseconds since the
3959
-** Unix epoch (1970-01-01T00:00:00Z)
3960
-*/
3961
-static sqlite3_int64 timeOfDay(void){
3962
-#if defined(_WIN64) && _WIN32_WINNT >= _WIN32_WINNT_WIN8
3963
- sqlite3_uint64 t;
3964
- FILETIME tm;
3965
- GetSystemTimePreciseAsFileTime(&tm);
3966
- t = ((u64)tm.dwHighDateTime<<32) | (u64)tm.dwLowDateTime;
3967
- t += 116444736000000000LL;
3968
- t /= 10;
3969
- return t;
3970
-#elif defined(_WIN32)
3971
- static sqlite3_vfs *clockVfs = 0;
3972
- sqlite3_int64 t;
3973
- if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
3974
- if( clockVfs==0 ) return 0; /* Never actually happens */
3975
- if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
3976
- clockVfs->xCurrentTimeInt64(clockVfs, &t);
3977
- }else{
3978
- double r;
3979
- clockVfs->xCurrentTime(clockVfs, &r);
3980
- t = (sqlite3_int64)(r*86400000.0);
3981
- }
3982
- return t*1000;
3983
-#else
3984
- struct timeval sNow;
3985
- (void)gettimeofday(&sNow,0);
3986
- return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
3987
-#endif
3988
-}
3989
-
3990
-
3991
-/*
3992
-** Used to prevent warnings about unused parameters
3993
-*/
3994
-#define UNUSED_PARAMETER(x) (void)(x)
3995
-
3996
-/*
3997
-** Number of elements in an array
3998
-*/
3999
-#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
4000
-
4001
-/*
4002
-** If the following flag is set, then command execution stops
4003
-** at an error if we are not interactive.
4004
-*/
4005
-static int bail_on_error = 0;
4006
-
4007
-/*
4008
-** Treat stdin as an interactive input if the following variable
4009
-** is true. Otherwise, assume stdin is connected to a file or pipe.
4010
-*/
4011
-static int stdin_is_interactive = 1;
4012
-
4013
-/*
4014
-** Treat stdout like a TTY if true.
4015
-*/
4016
-static int stdout_is_console = 1;
4017
-
4018
-/*
4019
-** Use this value as the width of the output device. Or, figure it
4020
-** out at runtime if the value is negative. Or use a default width
4021
-** if this value is zero.
4022
-*/
4023
-static int stdout_tty_width = -1;
4024
-
4025
-/*
4026
-** The following is the open SQLite database. We make a pointer
4027
-** to this database a static variable so that it can be accessed
4028
-** by the SIGINT handler to interrupt database processing.
4029
-*/
4030
-static sqlite3 *globalDb = 0;
4031
-
4032
-/*
4033
-** True if an interrupt (Control-C) has been received.
4034
-*/
4035
-static volatile int seenInterrupt = 0;
4036
-
4037
-/*
4038
-** This is the name of our program. It is set in main(), used
4039
-** in a number of other places, mostly for error messages.
4040
-*/
4041
-static char *Argv0;
4042
-
4043
-/*
4044
-** Prompt strings. Initialized in main. Settable with
4045
-** .prompt main continue
4046
-*/
4047
-#define PROMPT_LEN_MAX 128
4048
-/* First line prompt. default: "sqlite> " */
4049
-static char mainPrompt[PROMPT_LEN_MAX];
4050
-/* Continuation prompt. default: " ...> " */
4051
-static char continuePrompt[PROMPT_LEN_MAX];
4052
-
4053
-/*
4054
-** Write I/O traces to the following stream.
4055
-*/
4056
-#ifdef SQLITE_ENABLE_IOTRACE
4057
-static FILE *iotrace = 0;
4058
-#endif
4059
-
4060
-
4061
-/* This is variant of the standard-library strncpy() routine with the
4062
-** one change that the destination string is always zero-terminated, even
4063
-** if there is no zero-terminator in the first n-1 characters of the source
4064
-** string.
4065
-*/
4066
-static char *shell_strncpy(char *dest, const char *src, size_t n){
4067
- size_t i;
4068
- for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
4069
- dest[i] = 0;
4070
- return dest;
4071
-}
4072
-
4073
-/*
4074
-** strcpy() workalike to squelch an unwarranted link-time warning
4075
-** from OpenBSD.
4076
-*/
4077
-static void shell_strcpy(char *dest, const char *src){
4078
- while( (*(dest++) = *(src++))!=0 ){}
4079
-}
4080
-
4081
-/*
4082
-** Optionally disable dynamic continuation prompt.
4083
-** Unless disabled, the continuation prompt shows open SQL lexemes if any,
4084
-** or open parentheses level if non-zero, or continuation prompt as set.
4085
-** This facility interacts with the scanner and process_input() where the
4086
-** below 5 macros are used.
4087
-*/
4088
-#ifdef SQLITE_OMIT_DYNAPROMPT
4089
-# define CONTINUATION_PROMPT continuePrompt
4090
-# define CONTINUE_PROMPT_RESET
4091
-# define CONTINUE_PROMPT_AWAITS(p,s)
4092
-# define CONTINUE_PROMPT_AWAITC(p,c)
4093
-# define CONTINUE_PAREN_INCR(p,n)
4094
-# define CONTINUE_PROMPT_PSTATE 0
4095
-typedef void *t_NoDynaPrompt;
4096
-# define SCAN_TRACKER_REFTYPE t_NoDynaPrompt
4097
-#else
4098
-# define CONTINUATION_PROMPT dynamicContinuePrompt()
4099
-# define CONTINUE_PROMPT_RESET \
4100
- do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
4101
-# define CONTINUE_PROMPT_AWAITS(p,s) \
4102
- if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)
4103
-# define CONTINUE_PROMPT_AWAITC(p,c) \
4104
- if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)
4105
-# define CONTINUE_PAREN_INCR(p,n) \
4106
- if(p && stdin_is_interactive) (trackParenLevel(p,n))
4107
-# define CONTINUE_PROMPT_PSTATE (&dynPrompt)
4108
-typedef struct DynaPrompt *t_DynaPromptRef;
4109
-# define SCAN_TRACKER_REFTYPE t_DynaPromptRef
4110
-
4111
-static struct DynaPrompt {
4112
- char dynamicPrompt[PROMPT_LEN_MAX];
4113
- char acAwait[2];
4114
- int inParenLevel;
4115
- char *zScannerAwaits;
4116
-} dynPrompt = { {0}, {0}, 0, 0 };
4117
-
4118
-/* Record parenthesis nesting level change, or force level to 0. */
4119
-static void trackParenLevel(struct DynaPrompt *p, int ni){
4120
- p->inParenLevel += ni;
4121
- if( ni==0 ) p->inParenLevel = 0;
4122
- p->zScannerAwaits = 0;
4123
-}
4124
-
4125
-/* Record that a lexeme is opened, or closed with args==0. */
4126
-static void setLexemeOpen(struct DynaPrompt *p, char *s, char c){
4127
- if( s!=0 || c==0 ){
4128
- p->zScannerAwaits = s;
4129
- p->acAwait[0] = 0;
4130
- }else{
4131
- p->acAwait[0] = c;
4132
- p->zScannerAwaits = p->acAwait;
4133
- }
4134
-}
4135
-
4136
-/* Upon demand, derive the continuation prompt to display. */
4137
-static char *dynamicContinuePrompt(void){
4138
- if( continuePrompt[0]==0
4139
- || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
4140
- return continuePrompt;
4141
- }else{
4142
- if( dynPrompt.zScannerAwaits ){
4143
- size_t ncp = strlen(continuePrompt);
4144
- size_t ndp = strlen(dynPrompt.zScannerAwaits);
4145
- if( ndp > ncp-3 ) return continuePrompt;
4146
- shell_strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
4147
- while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
4148
- shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
4149
- PROMPT_LEN_MAX-4);
4150
- }else{
4151
- if( dynPrompt.inParenLevel>9 ){
4152
- shell_strncpy(dynPrompt.dynamicPrompt, "(..", 4);
4153
- }else if( dynPrompt.inParenLevel<0 ){
4154
- shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
4155
- }else{
4156
- shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
4157
- dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
4158
- }
4159
- shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
4160
- PROMPT_LEN_MAX-4);
4161
- }
4162
- }
4163
- return dynPrompt.dynamicPrompt;
4164
-}
4165
-#endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
4166
-
4167
-/* Indicate out-of-memory and exit. */
4168
-static void shell_out_of_memory(void){
4169
- eputz("Error: out of memory\n");
4170
- cli_exit(1);
4171
-}
4172
-
4173
-/* Check a pointer to see if it is NULL. If it is NULL, exit with an
4174
-** out-of-memory error.
4175
-*/
4176
-static void shell_check_oom(const void *p){
4177
- if( p==0 ) shell_out_of_memory();
4178
-}
4179
-
4180
-/*
4181
-** This routine works like printf in that its first argument is a
4182
-** format string and subsequent arguments are values to be substituted
4183
-** in place of % fields. The result of formatting this string
4184
-** is written to iotrace.
4185
-*/
4186
-#ifdef SQLITE_ENABLE_IOTRACE
4187
-static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){
4188
- va_list ap;
4189
- char *z;
4190
- if( iotrace==0 ) return;
4191
- va_start(ap, zFormat);
4192
- z = sqlite3_vmprintf(zFormat, ap);
4193
- va_end(ap);
4194
- cli_printf(iotrace, "%s", z);
4195
- sqlite3_free(z);
4196
-}
4197
-#endif
4198
-
4199
-/*
4200
-** Compute a string length that is limited to what can be stored in
4201
-** lower 30 bits of a 32-bit signed integer.
4202
-*/
4203
-static int strlen30(const char *z){
4204
- size_t n;
4205
- if( z==0 ) return 0;
4206
- n = strlen(z);
4207
- return n>0x3fffffff ? 0x3fffffff : (int)n;
4208
-}
4209
-
4210
-/*
4211
-** Return open FILE * if zFile exists, can be opened for read
4212
-** and is an ordinary file or a character stream source.
4213
-** Otherwise return 0.
4214
-*/
4215
-static FILE * openChrSource(const char *zFile){
4216
-#if defined(_WIN32) || defined(WIN32)
4217
- struct __stat64 x = {0};
4218
-# define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0)
4219
- /* On Windows, open first, then check the stream nature. This order
4220
- ** is necessary because _stat() and sibs, when checking a named pipe,
4221
- ** effectively break the pipe as its supplier sees it. */
4222
- FILE *rv = sqlite3_fopen(zFile, "rb");
4223
- if( rv==0 ) return 0;
4224
- if( _fstat64(_fileno(rv), &x) != 0
4225
- || !STAT_CHR_SRC(x.st_mode)){
4226
- fclose(rv);
4227
- rv = 0;
4228
- }
4229
- return rv;
4230
-#else
4231
- struct stat x = {0};
4232
- int rc = stat(zFile, &x);
4233
-# define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
4234
- if( rc!=0 ) return 0;
4235
- if( STAT_CHR_SRC(x.st_mode) ){
4236
- return sqlite3_fopen(zFile, "rb");
4237
- }else{
4238
- return 0;
4239
- }
4240
-#endif
4241
-#undef STAT_CHR_SRC
4242
-}
4243
-
4244
-/*
4245
-** This routine reads a line of text from FILE in, stores
4246
-** the text in memory obtained from malloc() and returns a pointer
4247
-** to the text. NULL is returned at end of file, or if malloc()
4248
-** fails, or if the length of the line is longer than about a gigabyte.
4249
-**
4250
-** If zLine is not NULL then it is a malloced buffer returned from
4251
-** a previous call to this routine that may be reused.
4252
-*/
4253
-static char *local_getline(char *zLine, FILE *in){
4254
- int nLine = zLine==0 ? 0 : 100;
4255
- int n = 0;
4256
-
4257
- while( 1 ){
4258
- if( n+100>nLine ){
4259
- if( nLine>=1073741773 ){
4260
- free(zLine);
4261
- return 0;
4262
- }
4263
- nLine = nLine*2 + 100;
4264
- zLine = realloc(zLine, nLine);
4265
- shell_check_oom(zLine);
4266
- }
4267
- if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
4268
- if( n==0 ){
4269
- free(zLine);
4270
- return 0;
4271
- }
4272
- zLine[n] = 0;
4273
- break;
4274
- }
4275
- while( zLine[n] ) n++;
4276
- if( n>0 && zLine[n-1]=='\n' ){
4277
- n--;
4278
- if( n>0 && zLine[n-1]=='\r' ) n--;
4279
- zLine[n] = 0;
4280
- break;
4281
- }
4282
- }
4283
- return zLine;
4284
-}
4285
-
4286
-/*
4287
-** Retrieve a single line of input text.
4288
-**
4289
-** If in==0 then read from standard input and prompt before each line.
4290
-** If isContinuation is true, then a continuation prompt is appropriate.
4291
-** If isContinuation is zero, then the main prompt should be used.
4292
-**
4293
-** If zPrior is not NULL then it is a buffer from a prior call to this
4294
-** routine that can be reused.
4295
-**
4296
-** The result is stored in space obtained from malloc() and must either
4297
-** be freed by the caller or else passed back into this routine via the
4298
-** zPrior argument for reuse.
4299
-*/
4300
-#ifndef SQLITE_SHELL_FIDDLE
4301
-static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
4302
- char *zPrompt;
4303
- char *zResult;
4304
- if( in!=0 ){
4305
- zResult = local_getline(zPrior, in);
4306
- }else{
4307
- zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
4308
-#if SHELL_USE_LOCAL_GETLINE
4309
- sputz(stdout, zPrompt);
4310
- fflush(stdout);
4311
- do{
4312
- zResult = local_getline(zPrior, stdin);
4313
- zPrior = 0;
4314
- /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
4315
- if( zResult==0 ) sqlite3_sleep(50);
4316
- }while( zResult==0 && seenInterrupt>0 );
4317
-#else
4318
- free(zPrior);
4319
- zResult = shell_readline(zPrompt);
4320
- while( zResult==0 ){
4321
- /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
4322
- sqlite3_sleep(50);
4323
- if( seenInterrupt==0 ) break;
4324
- zResult = shell_readline("");
4325
- }
4326
- if( zResult && *zResult ) shell_add_history(zResult);
4327
-#endif
4328
- }
4329
- return zResult;
4330
-}
4331
-#endif /* !SQLITE_SHELL_FIDDLE */
4332
-
4333
-/*
4334
-** Return the value of a hexadecimal digit. Return -1 if the input
4335
-** is not a hex digit.
4336
-*/
4337
-static int hexDigitValue(char c){
4338
- if( c>='0' && c<='9' ) return c - '0';
4339
- if( c>='a' && c<='f' ) return c - 'a' + 10;
4340
- if( c>='A' && c<='F' ) return c - 'A' + 10;
4341
- return -1;
4342
-}
4343
-
4344
-/*
4345
-** Interpret zArg as an integer value, possibly with suffixes.
4346
-**
4347
-** If the value specified by zArg is outside the range of values that
4348
-** can be represented using a 64-bit twos-complement integer, then return
4349
-** the nearest representable value.
4350
-*/
4351
-static sqlite3_int64 integerValue(const char *zArg){
4352
- sqlite3_uint64 v = 0;
4353
- static const struct { char *zSuffix; unsigned int iMult; } aMult[] = {
4354
- { "KiB", 1024 },
4355
- { "MiB", 1024*1024 },
4356
- { "GiB", 1024*1024*1024 },
4357
- { "KB", 1000 },
4358
- { "MB", 1000000 },
4359
- { "GB", 1000000000 },
4360
- { "K", 1000 },
4361
- { "M", 1000000 },
4362
- { "G", 1000000000 },
4363
- };
4364
- int i;
4365
- int isNeg = 0;
4366
- if( zArg[0]=='-' ){
4367
- isNeg = 1;
4368
- zArg++;
4369
- }else if( zArg[0]=='+' ){
4370
- zArg++;
4371
- }
4372
- if( zArg[0]=='0' && zArg[1]=='x' ){
4373
- int x;
4374
- zArg += 2;
4375
- while( (x = hexDigitValue(zArg[0]))>=0 ){
4376
- if( v > 0x0fffffffffffffffULL ) goto integer_overflow;
4377
- v = (v<<4) + x;
4378
- zArg++;
4379
- }
4380
- }else{
4381
- while( IsDigit(zArg[0]) ){
4382
- if( v>=922337203685477580LL ){
4383
- if( v>922337203685477580LL || zArg[0]>='8' ) goto integer_overflow;
4384
- }
4385
- v = v*10 + (zArg[0] - '0');
4386
- zArg++;
4387
- }
4388
- }
4389
- for(i=0; i<ArraySize(aMult); i++){
4390
- if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
4391
- if( 0x7fffffffffffffffULL/aMult[i].iMult < v ) goto integer_overflow;
4392
- v *= aMult[i].iMult;
4393
- break;
4394
- }
4395
- }
4396
- if( isNeg && v>0x7fffffffffffffffULL ) goto integer_overflow;
4397
- return isNeg? -(sqlite3_int64)v : (sqlite3_int64)v;
4398
-integer_overflow:
4399
- return isNeg ? (i64)0x8000000000000000LL : 0x7fffffffffffffffLL;
4400
-}
4401
-
4402
-/*
4403
-** A variable length string to which one can append text.
4404
-*/
4405
-typedef struct ShellText ShellText;
4406
-struct ShellText {
4407
- char *zTxt; /* The text */
4408
- i64 n; /* Number of bytes of zTxt[] actually used */
4409
- i64 nAlloc; /* Number of bytes allocated for zTxt[] */
4410
-};
4411
-
4412
-/*
4413
-** Initialize and destroy a ShellText object
4414
-*/
4415
-static void initText(ShellText *p){
4416
- memset(p, 0, sizeof(*p));
4417
-}
4418
-static void freeText(ShellText *p){
4419
- sqlite3_free(p->zTxt);
4420
- initText(p);
4421
-}
4422
-
4423
-/* zIn is either a pointer to a NULL-terminated string in memory obtained
4424
-** from malloc(), or a NULL pointer. The string pointed to by zAppend is
4425
-** added to zIn, and the result returned in memory obtained from malloc().
4426
-** zIn, if it was not NULL, is freed.
4427
-**
4428
-** If the third argument, quote, is not '\0', then it is used as a
4429
-** quote character for zAppend.
4430
-*/
4431
-static void appendText(ShellText *p, const char *zAppend, char quote){
4432
- i64 len;
4433
- i64 i;
4434
- i64 nAppend = strlen30(zAppend);
4435
-
4436
- len = nAppend+p->n+1;
4437
- if( quote ){
4438
- len += 2;
4439
- for(i=0; i<nAppend; i++){
4440
- if( zAppend[i]==quote ) len++;
4441
- }
4442
- }
4443
-
4444
- if( p->zTxt==0 || p->n+len>=p->nAlloc ){
4445
- p->nAlloc = p->nAlloc*2 + len + 20;
4446
- p->zTxt = sqlite3_realloc64(p->zTxt, p->nAlloc);
4447
- shell_check_oom(p->zTxt);
4448
- }
4449
-
4450
- if( quote ){
4451
- char *zCsr = p->zTxt+p->n;
4452
- *zCsr++ = quote;
4453
- for(i=0; i<nAppend; i++){
4454
- *zCsr++ = zAppend[i];
4455
- if( zAppend[i]==quote ) *zCsr++ = quote;
4456
- }
4457
- *zCsr++ = quote;
4458
- p->n = (i64)(zCsr - p->zTxt);
4459
- *zCsr = '\0';
4460
- }else{
4461
- memcpy(p->zTxt+p->n, zAppend, nAppend);
4462
- p->n += nAppend;
4463
- p->zTxt[p->n] = '\0';
4464
- }
4465
-}
4466
-
4467
-/*
4468
-** Attempt to determine if identifier zName needs to be quoted, either
4469
-** because it contains non-alphanumeric characters, or because it is an
4470
-** SQLite keyword. Be conservative in this estimate: When in doubt assume
4471
-** that quoting is required.
4472
-**
4473
-** Return '"' if quoting is required. Return 0 if no quoting is required.
4474
-*/
4475
-static char quoteChar(const char *zName){
4476
- int i;
4477
- if( zName==0 ) return '"';
4478
- if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"';
4479
- for(i=0; zName[i]; i++){
4480
- if( !IsAlnum(zName[i]) && zName[i]!='_' ) return '"';
4481
- }
4482
- return sqlite3_keyword_check(zName, i) ? '"' : 0;
4483
-}
4484
-
4485
-/*
4486
-** Construct a fake object name and column list to describe the structure
4487
-** of the view, virtual table, or table valued function zSchema.zName.
4488
-**
4489
-** The returned string comes from sqlite3_mprintf() and should be freed
4490
-** by the caller using sqlite3_free().
4491
-*/
4492
-static char *shellFakeSchema(
4493
- sqlite3 *db, /* The database connection containing the vtab */
4494
- const char *zSchema, /* Schema of the database holding the vtab */
4495
- const char *zName /* The name of the virtual table */
4496
-){
4497
- sqlite3_stmt *pStmt = 0;
4498
- char *zSql;
4499
- ShellText s;
4500
- char cQuote;
4501
- char *zDiv = "(";
4502
- int nRow = 0;
4503
-
4504
- zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
4505
- zSchema ? zSchema : "main", zName);
4506
- shell_check_oom(zSql);
4507
- sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
4508
- sqlite3_free(zSql);
4509
- initText(&s);
4510
- if( zSchema ){
4511
- cQuote = quoteChar(zSchema);
4512
- if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
4513
- appendText(&s, zSchema, cQuote);
4514
- appendText(&s, ".", 0);
4515
- }
4516
- cQuote = quoteChar(zName);
4517
- appendText(&s, zName, cQuote);
4518
- while( sqlite3_step(pStmt)==SQLITE_ROW ){
4519
- const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
4520
- nRow++;
4521
- appendText(&s, zDiv, 0);
4522
- zDiv = ",";
4523
- if( zCol==0 ) zCol = "";
4524
- cQuote = quoteChar(zCol);
4525
- appendText(&s, zCol, cQuote);
4526
- }
4527
- appendText(&s, ")", 0);
4528
- sqlite3_finalize(pStmt);
4529
- if( nRow==0 ){
4530
- freeText(&s);
4531
- s.zTxt = 0;
4532
- }
4533
- return s.zTxt;
4534
-}
4535
-
4536
-/*
4537
-** SQL function: strtod(X)
4538
-**
4539
-** Use the C-library strtod() function to convert string X into a double.
4540
-** Used for comparing the accuracy of SQLite's internal text-to-float conversion
4541
-** routines against the C-library.
4542
-*/
4543
-static void shellStrtod(
4544
- sqlite3_context *pCtx,
4545
- int nVal,
4546
- sqlite3_value **apVal
4547
-){
4548
- char *z = (char*)sqlite3_value_text(apVal[0]);
4549
- UNUSED_PARAMETER(nVal);
4550
- if( z==0 ) return;
4551
- sqlite3_result_double(pCtx, strtod(z,0));
4552
-}
4553
-
4554
-/*
4555
-** SQL function: dtostr(X)
4556
-**
4557
-** Use the C-library printf() function to convert real value X into a string.
4558
-** Used for comparing the accuracy of SQLite's internal float-to-text conversion
4559
-** routines against the C-library.
4560
-*/
4561
-static void shellDtostr(
4562
- sqlite3_context *pCtx,
4563
- int nVal,
4564
- sqlite3_value **apVal
4565
-){
4566
- double r = sqlite3_value_double(apVal[0]);
4567
- int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
4568
- char z[400];
4569
- if( n<1 ) n = 1;
4570
- if( n>350 ) n = 350;
4571
- sprintf(z, "%#+.*e", n, r);
4572
- sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
4573
-}
4574
-
4575
-/*
4576
-** SQL function: shell_add_schema(S,X)
4577
-**
4578
-** Add the schema name X to the CREATE statement in S and return the result.
4579
-** Examples:
4580
-**
4581
-** CREATE TABLE t1(x) -> CREATE TABLE xyz.t1(x);
4582
-**
4583
-** Also works on
4584
-**
4585
-** CREATE INDEX
4586
-** CREATE UNIQUE INDEX
4587
-** CREATE VIEW
4588
-** CREATE TRIGGER
4589
-** CREATE VIRTUAL TABLE
4590
-**
4591
-** This UDF is used by the .schema command to insert the schema name of
4592
-** attached databases into the middle of the sqlite_schema.sql field.
4593
-*/
4594
-static void shellAddSchemaName(
4595
- sqlite3_context *pCtx,
4596
- int nVal,
4597
- sqlite3_value **apVal
4598
-){
4599
- static const char *aPrefix[] = {
4600
- "TABLE",
4601
- "INDEX",
4602
- "UNIQUE INDEX",
4603
- "VIEW",
4604
- "TRIGGER",
4605
- "VIRTUAL TABLE"
4606
- };
4607
- int i = 0;
4608
- const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
4609
- const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
4610
- const char *zName = (const char*)sqlite3_value_text(apVal[2]);
4611
- sqlite3 *db = sqlite3_context_db_handle(pCtx);
4612
- UNUSED_PARAMETER(nVal);
4613
- if( zIn!=0 && cli_strncmp(zIn, "CREATE ", 7)==0 ){
4614
- for(i=0; i<ArraySize(aPrefix); i++){
4615
- int n = strlen30(aPrefix[i]);
4616
- if( cli_strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
4617
- char *z = 0;
4618
- char *zFake = 0;
4619
- if( zSchema ){
4620
- char cQuote = quoteChar(zSchema);
4621
- if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){
4622
- z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
4623
- }else{
4624
- z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
4625
- }
4626
- }
4627
- if( zName
4628
- && aPrefix[i][0]=='V'
4629
- && (zFake = shellFakeSchema(db, zSchema, zName))!=0
4630
- ){
4631
- if( z==0 ){
4632
- z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
4633
- }else{
4634
- z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
4635
- }
4636
- sqlite3_free(zFake);
4637
- }
4638
- if( z ){
4639
- sqlite3_result_text(pCtx, z, -1, sqlite3_free);
4640
- return;
4641
- }
4642
- }
4643
- }
4644
- }
4645
- sqlite3_result_value(pCtx, apVal[0]);
4646
-}
4647
-
46483900
/*
46493901
** The source code for several run-time loadable extensions is inserted
46503902
** below by the ../tool/mkshellc.tcl script. Before processing that included
46513903
** code, we need to override some macros to make the included program code
46523904
** work here in the middle of this regular program.
@@ -24654,14 +23906,764 @@
2465423906
#ifndef DFLT_MULTI_INSERT
2465523907
# define DFLT_MULTI_INSERT 3000
2465623908
#endif
2465723909
2465823910
/*
24659
-** Limit input nesting via .read or any other input redirect.
24660
-** It's not too expensive, so a generous allowance can be made.
24661
-*/
24662
-#define MAX_INPUT_NESTING 25
23911
+** If the following flag is set, then command execution stops
23912
+** at an error if we are not interactive.
23913
+*/
23914
+static int bail_on_error = 0;
23915
+
23916
+/*
23917
+** Treat stdin as an interactive input if the following variable
23918
+** is true. Otherwise, assume stdin is connected to a file or pipe.
23919
+*/
23920
+static int stdin_is_interactive = 1;
23921
+
23922
+/*
23923
+** Treat stdout like a TTY if true.
23924
+*/
23925
+static int stdout_is_console = 1;
23926
+
23927
+/*
23928
+** Use this value as the width of the output device. Or, figure it
23929
+** out at runtime if the value is negative. Or use a default width
23930
+** if this value is zero.
23931
+*/
23932
+static int stdout_tty_width = -1;
23933
+
23934
+/*
23935
+** The following is the open SQLite database. We make a pointer
23936
+** to this database a static variable so that it can be accessed
23937
+** by the SIGINT handler to interrupt database processing.
23938
+*/
23939
+static sqlite3 *globalDb = 0;
23940
+
23941
+/*
23942
+** True if an interrupt (Control-C) has been received.
23943
+*/
23944
+static volatile int seenInterrupt = 0;
23945
+
23946
+/*
23947
+** This is the name of our program. It is set in main(), used
23948
+** in a number of other places, mostly for error messages.
23949
+*/
23950
+static char *Argv0;
23951
+
23952
+/*
23953
+** Prompt strings. Initialized in main. Settable with
23954
+** .prompt main continue
23955
+*/
23956
+#define PROMPT_LEN_MAX 128
23957
+/* First line prompt. default: "sqlite> " */
23958
+static char mainPrompt[PROMPT_LEN_MAX];
23959
+/* Continuation prompt. default: " ...> " */
23960
+static char continuePrompt[PROMPT_LEN_MAX];
23961
+
23962
+/*
23963
+** Write I/O traces to the following stream.
23964
+*/
23965
+#ifdef SQLITE_ENABLE_IOTRACE
23966
+static FILE *iotrace = 0;
23967
+#endif
23968
+
23969
+/*
23970
+** Output routines that are able to redirect to memory rather than
23971
+** doing actually I/O.
23972
+** Works like.
23973
+** --------------
23974
+** cli_printf(FILE*, const char*, ...); fprintf()
23975
+** cli_puts(const char*, FILE*); fputs()
23976
+** cli_vprintf(FILE*, const char*, va_list); vfprintf()
23977
+**
23978
+** These are just thin wrappers with the following added semantics:
23979
+** If the file-scope variable cli_output_capture is not NULL, and
23980
+** if the FILE* argument is stdout or stderr, then rather than
23981
+** writing to stdout/stdout, append the text to the cli_output_capture
23982
+** variable.
23983
+**
23984
+** The cli_exit(int) routine works like exit() except that it
23985
+** first dumps any capture output to stdout.
23986
+*/
23987
+static sqlite3_str *cli_output_capture = 0;
23988
+static int cli_printf(FILE *out, const char *zFormat, ...){
23989
+ va_list ap;
23990
+ int rc;
23991
+ va_start(ap,zFormat);
23992
+ if( cli_output_capture && (out==stdout || out==stderr) ){
23993
+ sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
23994
+ rc = 1;
23995
+ }else{
23996
+ rc = sqlite3_vfprintf(out, zFormat, ap);
23997
+ }
23998
+ va_end(ap);
23999
+ return rc;
24000
+}
24001
+static int cli_puts(const char *zText, FILE *out){
24002
+ if( cli_output_capture && (out==stdout || out==stderr) ){
24003
+ sqlite3_str_appendall(cli_output_capture, zText);
24004
+ return 1;
24005
+ }
24006
+ return sqlite3_fputs(zText, out);
24007
+}
24008
+#if 0 /* Not currently used - available if we need it later */
24009
+static int cli_vprintf(FILE *out, const char *zFormat, va_list ap){
24010
+ if( cli_output_capture && (out==stdout || out==stderr) ){
24011
+ sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
24012
+ return 1;
24013
+ }else{
24014
+ return sqlite3_vfprintf(out, zFormat, ap);
24015
+ }
24016
+}
24017
+#endif
24018
+static void cli_exit(int rc){
24019
+ if( cli_output_capture ){
24020
+ char *z = sqlite3_str_finish(cli_output_capture);
24021
+ sqlite3_fputs(z, stdout);
24022
+ fflush(stdout);
24023
+ }
24024
+ exit(rc);
24025
+}
24026
+
24027
+
24028
+#define eputz(z) cli_puts(z,stderr)
24029
+#define sputz(fp,z) cli_puts(z,fp)
24030
+
24031
+/* A version of strcmp() that works with NULL values */
24032
+static int cli_strcmp(const char *a, const char *b){
24033
+ if( a==0 ) a = "";
24034
+ if( b==0 ) b = "";
24035
+ return strcmp(a,b);
24036
+}
24037
+static int cli_strncmp(const char *a, const char *b, size_t n){
24038
+ if( a==0 ) a = "";
24039
+ if( b==0 ) b = "";
24040
+ return strncmp(a,b,n);
24041
+}
24042
+
24043
+/* Return the current wall-clock time in microseconds since the
24044
+** Unix epoch (1970-01-01T00:00:00Z)
24045
+*/
24046
+static sqlite3_int64 timeOfDay(void){
24047
+#if defined(_WIN64) && _WIN32_WINNT >= _WIN32_WINNT_WIN8
24048
+ sqlite3_uint64 t;
24049
+ FILETIME tm;
24050
+ GetSystemTimePreciseAsFileTime(&tm);
24051
+ t = ((u64)tm.dwHighDateTime<<32) | (u64)tm.dwLowDateTime;
24052
+ t += 116444736000000000LL;
24053
+ t /= 10;
24054
+ return t;
24055
+#elif defined(_WIN32)
24056
+ static sqlite3_vfs *clockVfs = 0;
24057
+ sqlite3_int64 t;
24058
+ if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
24059
+ if( clockVfs==0 ) return 0; /* Never actually happens */
24060
+ if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
24061
+ clockVfs->xCurrentTimeInt64(clockVfs, &t);
24062
+ }else{
24063
+ double r;
24064
+ clockVfs->xCurrentTime(clockVfs, &r);
24065
+ t = (sqlite3_int64)(r*86400000.0);
24066
+ }
24067
+ return t*1000;
24068
+#else
24069
+ struct timeval sNow;
24070
+ (void)gettimeofday(&sNow,0);
24071
+ return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
24072
+#endif
24073
+}
24074
+
24075
+
24076
+
24077
+/* This is variant of the standard-library strncpy() routine with the
24078
+** one change that the destination string is always zero-terminated, even
24079
+** if there is no zero-terminator in the first n-1 characters of the source
24080
+** string.
24081
+*/
24082
+static char *shell_strncpy(char *dest, const char *src, size_t n){
24083
+ size_t i;
24084
+ for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
24085
+ dest[i] = 0;
24086
+ return dest;
24087
+}
24088
+
24089
+/*
24090
+** strcpy() workalike to squelch an unwarranted link-time warning
24091
+** from OpenBSD.
24092
+*/
24093
+static void shell_strcpy(char *dest, const char *src){
24094
+ while( (*(dest++) = *(src++))!=0 ){}
24095
+}
24096
+
24097
+/*
24098
+** Optionally disable dynamic continuation prompt.
24099
+** Unless disabled, the continuation prompt shows open SQL lexemes if any,
24100
+** or open parentheses level if non-zero, or continuation prompt as set.
24101
+** This facility interacts with the scanner and process_input() where the
24102
+** below 5 macros are used.
24103
+*/
24104
+#ifdef SQLITE_OMIT_DYNAPROMPT
24105
+# define CONTINUATION_PROMPT continuePrompt
24106
+# define CONTINUE_PROMPT_RESET
24107
+# define CONTINUE_PROMPT_AWAITS(p,s)
24108
+# define CONTINUE_PROMPT_AWAITC(p,c)
24109
+# define CONTINUE_PAREN_INCR(p,n)
24110
+# define CONTINUE_PROMPT_PSTATE 0
24111
+typedef void *t_NoDynaPrompt;
24112
+# define SCAN_TRACKER_REFTYPE t_NoDynaPrompt
24113
+#else
24114
+# define CONTINUATION_PROMPT dynamicContinuePrompt()
24115
+# define CONTINUE_PROMPT_RESET \
24116
+ do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
24117
+# define CONTINUE_PROMPT_AWAITS(p,s) \
24118
+ if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)
24119
+# define CONTINUE_PROMPT_AWAITC(p,c) \
24120
+ if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)
24121
+# define CONTINUE_PAREN_INCR(p,n) \
24122
+ if(p && stdin_is_interactive) (trackParenLevel(p,n))
24123
+# define CONTINUE_PROMPT_PSTATE (&dynPrompt)
24124
+typedef struct DynaPrompt *t_DynaPromptRef;
24125
+# define SCAN_TRACKER_REFTYPE t_DynaPromptRef
24126
+
24127
+static struct DynaPrompt {
24128
+ char dynamicPrompt[PROMPT_LEN_MAX];
24129
+ char acAwait[2];
24130
+ int inParenLevel;
24131
+ char *zScannerAwaits;
24132
+} dynPrompt = { {0}, {0}, 0, 0 };
24133
+
24134
+/* Record parenthesis nesting level change, or force level to 0. */
24135
+static void trackParenLevel(struct DynaPrompt *p, int ni){
24136
+ p->inParenLevel += ni;
24137
+ if( ni==0 ) p->inParenLevel = 0;
24138
+ p->zScannerAwaits = 0;
24139
+}
24140
+
24141
+/* Record that a lexeme is opened, or closed with args==0. */
24142
+static void setLexemeOpen(struct DynaPrompt *p, char *s, char c){
24143
+ if( s!=0 || c==0 ){
24144
+ p->zScannerAwaits = s;
24145
+ p->acAwait[0] = 0;
24146
+ }else{
24147
+ p->acAwait[0] = c;
24148
+ p->zScannerAwaits = p->acAwait;
24149
+ }
24150
+}
24151
+
24152
+/* Upon demand, derive the continuation prompt to display. */
24153
+static char *dynamicContinuePrompt(void){
24154
+ if( continuePrompt[0]==0
24155
+ || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
24156
+ return continuePrompt;
24157
+ }else{
24158
+ if( dynPrompt.zScannerAwaits ){
24159
+ size_t ncp = strlen(continuePrompt);
24160
+ size_t ndp = strlen(dynPrompt.zScannerAwaits);
24161
+ if( ndp > ncp-3 ) return continuePrompt;
24162
+ shell_strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
24163
+ while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
24164
+ shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
24165
+ PROMPT_LEN_MAX-4);
24166
+ }else{
24167
+ if( dynPrompt.inParenLevel>9 ){
24168
+ shell_strncpy(dynPrompt.dynamicPrompt, "(..", 4);
24169
+ }else if( dynPrompt.inParenLevel<0 ){
24170
+ shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
24171
+ }else{
24172
+ shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
24173
+ dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
24174
+ }
24175
+ shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
24176
+ PROMPT_LEN_MAX-4);
24177
+ }
24178
+ }
24179
+ return dynPrompt.dynamicPrompt;
24180
+}
24181
+#endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
24182
+
24183
+/* Indicate out-of-memory and exit. */
24184
+static void shell_out_of_memory(void){
24185
+ eputz("Error: out of memory\n");
24186
+ cli_exit(1);
24187
+}
24188
+
24189
+/* Check a pointer to see if it is NULL. If it is NULL, exit with an
24190
+** out-of-memory error.
24191
+*/
24192
+static void shell_check_oom(const void *p){
24193
+ if( p==0 ) shell_out_of_memory();
24194
+}
24195
+
24196
+/*
24197
+** This routine works like printf in that its first argument is a
24198
+** format string and subsequent arguments are values to be substituted
24199
+** in place of % fields. The result of formatting this string
24200
+** is written to iotrace.
24201
+*/
24202
+#ifdef SQLITE_ENABLE_IOTRACE
24203
+static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){
24204
+ va_list ap;
24205
+ char *z;
24206
+ if( iotrace==0 ) return;
24207
+ va_start(ap, zFormat);
24208
+ z = sqlite3_vmprintf(zFormat, ap);
24209
+ va_end(ap);
24210
+ cli_printf(iotrace, "%s", z);
24211
+ sqlite3_free(z);
24212
+}
24213
+#endif
24214
+
24215
+/*
24216
+** Compute a string length that is limited to what can be stored in
24217
+** lower 30 bits of a 32-bit signed integer.
24218
+*/
24219
+static int strlen30(const char *z){
24220
+ size_t n;
24221
+ if( z==0 ) return 0;
24222
+ n = strlen(z);
24223
+ return n>0x3fffffff ? 0x3fffffff : (int)n;
24224
+}
24225
+
24226
+/*
24227
+** Return open FILE * if zFile exists, can be opened for read
24228
+** and is an ordinary file or a character stream source.
24229
+** Otherwise return 0.
24230
+*/
24231
+static FILE * openChrSource(const char *zFile){
24232
+#if defined(_WIN32) || defined(WIN32)
24233
+ struct __stat64 x = {0};
24234
+# define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0)
24235
+ /* On Windows, open first, then check the stream nature. This order
24236
+ ** is necessary because _stat() and sibs, when checking a named pipe,
24237
+ ** effectively break the pipe as its supplier sees it. */
24238
+ FILE *rv = sqlite3_fopen(zFile, "rb");
24239
+ if( rv==0 ) return 0;
24240
+ if( _fstat64(_fileno(rv), &x) != 0
24241
+ || !STAT_CHR_SRC(x.st_mode)){
24242
+ fclose(rv);
24243
+ rv = 0;
24244
+ }
24245
+ return rv;
24246
+#else
24247
+ struct stat x = {0};
24248
+ int rc = stat(zFile, &x);
24249
+# define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
24250
+ if( rc!=0 ) return 0;
24251
+ if( STAT_CHR_SRC(x.st_mode) ){
24252
+ return sqlite3_fopen(zFile, "rb");
24253
+ }else{
24254
+ return 0;
24255
+ }
24256
+#endif
24257
+#undef STAT_CHR_SRC
24258
+}
24259
+
24260
+/*
24261
+** This routine reads a line of text from FILE in, stores
24262
+** the text in memory obtained from malloc() and returns a pointer
24263
+** to the text. NULL is returned at end of file, or if malloc()
24264
+** fails, or if the length of the line is longer than about a gigabyte.
24265
+**
24266
+** If zLine is not NULL then it is a malloced buffer returned from
24267
+** a previous call to this routine that may be reused.
24268
+*/
24269
+static char *local_getline(char *zLine, FILE *in){
24270
+ int nLine = zLine==0 ? 0 : 100;
24271
+ int n = 0;
24272
+
24273
+ while( 1 ){
24274
+ if( n+100>nLine ){
24275
+ if( nLine>=1073741773 ){
24276
+ free(zLine);
24277
+ return 0;
24278
+ }
24279
+ nLine = nLine*2 + 100;
24280
+ zLine = realloc(zLine, nLine);
24281
+ shell_check_oom(zLine);
24282
+ }
24283
+ if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
24284
+ if( n==0 ){
24285
+ free(zLine);
24286
+ return 0;
24287
+ }
24288
+ zLine[n] = 0;
24289
+ break;
24290
+ }
24291
+ while( zLine[n] ) n++;
24292
+ if( n>0 && zLine[n-1]=='\n' ){
24293
+ n--;
24294
+ if( n>0 && zLine[n-1]=='\r' ) n--;
24295
+ zLine[n] = 0;
24296
+ break;
24297
+ }
24298
+ }
24299
+ return zLine;
24300
+}
24301
+
24302
+/*
24303
+** Retrieve a single line of input text.
24304
+**
24305
+** If in==0 then read from standard input and prompt before each line.
24306
+** If isContinuation is true, then a continuation prompt is appropriate.
24307
+** If isContinuation is zero, then the main prompt should be used.
24308
+**
24309
+** If zPrior is not NULL then it is a buffer from a prior call to this
24310
+** routine that can be reused.
24311
+**
24312
+** The result is stored in space obtained from malloc() and must either
24313
+** be freed by the caller or else passed back into this routine via the
24314
+** zPrior argument for reuse.
24315
+*/
24316
+#ifndef SQLITE_SHELL_FIDDLE
24317
+static char *one_input_line(ShellState *p, char *zPrior, int isContinuation){
24318
+ char *zPrompt;
24319
+ char *zResult;
24320
+ FILE *in = p->in;
24321
+ if( in!=0 ){
24322
+ zResult = local_getline(zPrior, in);
24323
+ }else{
24324
+ zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
24325
+#if SHELL_USE_LOCAL_GETLINE
24326
+ sputz(stdout, zPrompt);
24327
+ fflush(stdout);
24328
+ do{
24329
+ zResult = local_getline(zPrior, stdin);
24330
+ zPrior = 0;
24331
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
24332
+ if( zResult==0 ) sqlite3_sleep(50);
24333
+ }while( zResult==0 && seenInterrupt>0 );
24334
+#else
24335
+ free(zPrior);
24336
+ zResult = shell_readline(zPrompt);
24337
+ while( zResult==0 ){
24338
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
24339
+ sqlite3_sleep(50);
24340
+ if( seenInterrupt==0 ) break;
24341
+ zResult = shell_readline("");
24342
+ }
24343
+ if( zResult && *zResult ) shell_add_history(zResult);
24344
+#endif
24345
+ }
24346
+ return zResult;
24347
+}
24348
+#endif /* !SQLITE_SHELL_FIDDLE */
24349
+
24350
+/*
24351
+** Return the value of a hexadecimal digit. Return -1 if the input
24352
+** is not a hex digit.
24353
+*/
24354
+static int hexDigitValue(char c){
24355
+ if( c>='0' && c<='9' ) return c - '0';
24356
+ if( c>='a' && c<='f' ) return c - 'a' + 10;
24357
+ if( c>='A' && c<='F' ) return c - 'A' + 10;
24358
+ return -1;
24359
+}
24360
+
24361
+/*
24362
+** Interpret zArg as an integer value, possibly with suffixes.
24363
+**
24364
+** If the value specified by zArg is outside the range of values that
24365
+** can be represented using a 64-bit twos-complement integer, then return
24366
+** the nearest representable value.
24367
+*/
24368
+static sqlite3_int64 integerValue(const char *zArg){
24369
+ sqlite3_uint64 v = 0;
24370
+ static const struct { char *zSuffix; unsigned int iMult; } aMult[] = {
24371
+ { "KiB", 1024 },
24372
+ { "MiB", 1024*1024 },
24373
+ { "GiB", 1024*1024*1024 },
24374
+ { "KB", 1000 },
24375
+ { "MB", 1000000 },
24376
+ { "GB", 1000000000 },
24377
+ { "K", 1000 },
24378
+ { "M", 1000000 },
24379
+ { "G", 1000000000 },
24380
+ };
24381
+ int i;
24382
+ int isNeg = 0;
24383
+ if( zArg[0]=='-' ){
24384
+ isNeg = 1;
24385
+ zArg++;
24386
+ }else if( zArg[0]=='+' ){
24387
+ zArg++;
24388
+ }
24389
+ if( zArg[0]=='0' && zArg[1]=='x' ){
24390
+ int x;
24391
+ zArg += 2;
24392
+ while( (x = hexDigitValue(zArg[0]))>=0 ){
24393
+ if( v > 0x0fffffffffffffffULL ) goto integer_overflow;
24394
+ v = (v<<4) + x;
24395
+ zArg++;
24396
+ }
24397
+ }else{
24398
+ while( IsDigit(zArg[0]) ){
24399
+ if( v>=922337203685477580LL ){
24400
+ if( v>922337203685477580LL || zArg[0]>='8' ) goto integer_overflow;
24401
+ }
24402
+ v = v*10 + (zArg[0] - '0');
24403
+ zArg++;
24404
+ }
24405
+ }
24406
+ for(i=0; i<ArraySize(aMult); i++){
24407
+ if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
24408
+ if( 0x7fffffffffffffffULL/aMult[i].iMult < v ) goto integer_overflow;
24409
+ v *= aMult[i].iMult;
24410
+ break;
24411
+ }
24412
+ }
24413
+ if( isNeg && v>0x7fffffffffffffffULL ) goto integer_overflow;
24414
+ return isNeg? -(sqlite3_int64)v : (sqlite3_int64)v;
24415
+integer_overflow:
24416
+ return isNeg ? (i64)0x8000000000000000LL : 0x7fffffffffffffffLL;
24417
+}
24418
+
24419
+/*
24420
+** A variable length string to which one can append text.
24421
+*/
24422
+typedef struct ShellText ShellText;
24423
+struct ShellText {
24424
+ char *zTxt; /* The text */
24425
+ i64 n; /* Number of bytes of zTxt[] actually used */
24426
+ i64 nAlloc; /* Number of bytes allocated for zTxt[] */
24427
+};
24428
+
24429
+/*
24430
+** Initialize and destroy a ShellText object
24431
+*/
24432
+static void initText(ShellText *p){
24433
+ memset(p, 0, sizeof(*p));
24434
+}
24435
+static void freeText(ShellText *p){
24436
+ sqlite3_free(p->zTxt);
24437
+ initText(p);
24438
+}
24439
+
24440
+/* zIn is either a pointer to a NULL-terminated string in memory obtained
24441
+** from malloc(), or a NULL pointer. The string pointed to by zAppend is
24442
+** added to zIn, and the result returned in memory obtained from malloc().
24443
+** zIn, if it was not NULL, is freed.
24444
+**
24445
+** If the third argument, quote, is not '\0', then it is used as a
24446
+** quote character for zAppend.
24447
+*/
24448
+static void appendText(ShellText *p, const char *zAppend, char quote){
24449
+ i64 len;
24450
+ i64 i;
24451
+ i64 nAppend = strlen30(zAppend);
24452
+
24453
+ len = nAppend+p->n+1;
24454
+ if( quote ){
24455
+ len += 2;
24456
+ for(i=0; i<nAppend; i++){
24457
+ if( zAppend[i]==quote ) len++;
24458
+ }
24459
+ }
24460
+
24461
+ if( p->zTxt==0 || p->n+len>=p->nAlloc ){
24462
+ p->nAlloc = p->nAlloc*2 + len + 20;
24463
+ p->zTxt = sqlite3_realloc64(p->zTxt, p->nAlloc);
24464
+ shell_check_oom(p->zTxt);
24465
+ }
24466
+
24467
+ if( quote ){
24468
+ char *zCsr = p->zTxt+p->n;
24469
+ *zCsr++ = quote;
24470
+ for(i=0; i<nAppend; i++){
24471
+ *zCsr++ = zAppend[i];
24472
+ if( zAppend[i]==quote ) *zCsr++ = quote;
24473
+ }
24474
+ *zCsr++ = quote;
24475
+ p->n = (i64)(zCsr - p->zTxt);
24476
+ *zCsr = '\0';
24477
+ }else{
24478
+ memcpy(p->zTxt+p->n, zAppend, nAppend);
24479
+ p->n += nAppend;
24480
+ p->zTxt[p->n] = '\0';
24481
+ }
24482
+}
24483
+
24484
+/*
24485
+** Attempt to determine if identifier zName needs to be quoted, either
24486
+** because it contains non-alphanumeric characters, or because it is an
24487
+** SQLite keyword. Be conservative in this estimate: When in doubt assume
24488
+** that quoting is required.
24489
+**
24490
+** Return '"' if quoting is required. Return 0 if no quoting is required.
24491
+*/
24492
+static char quoteChar(const char *zName){
24493
+ int i;
24494
+ if( zName==0 ) return '"';
24495
+ if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"';
24496
+ for(i=0; zName[i]; i++){
24497
+ if( !IsAlnum(zName[i]) && zName[i]!='_' ) return '"';
24498
+ }
24499
+ return sqlite3_keyword_check(zName, i) ? '"' : 0;
24500
+}
24501
+
24502
+/*
24503
+** Construct a fake object name and column list to describe the structure
24504
+** of the view, virtual table, or table valued function zSchema.zName.
24505
+**
24506
+** The returned string comes from sqlite3_mprintf() and should be freed
24507
+** by the caller using sqlite3_free().
24508
+*/
24509
+static char *shellFakeSchema(
24510
+ sqlite3 *db, /* The database connection containing the vtab */
24511
+ const char *zSchema, /* Schema of the database holding the vtab */
24512
+ const char *zName /* The name of the virtual table */
24513
+){
24514
+ sqlite3_stmt *pStmt = 0;
24515
+ char *zSql;
24516
+ ShellText s;
24517
+ char cQuote;
24518
+ char *zDiv = "(";
24519
+ int nRow = 0;
24520
+
24521
+ zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
24522
+ zSchema ? zSchema : "main", zName);
24523
+ shell_check_oom(zSql);
24524
+ sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
24525
+ sqlite3_free(zSql);
24526
+ initText(&s);
24527
+ if( zSchema ){
24528
+ cQuote = quoteChar(zSchema);
24529
+ if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
24530
+ appendText(&s, zSchema, cQuote);
24531
+ appendText(&s, ".", 0);
24532
+ }
24533
+ cQuote = quoteChar(zName);
24534
+ appendText(&s, zName, cQuote);
24535
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
24536
+ const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
24537
+ nRow++;
24538
+ appendText(&s, zDiv, 0);
24539
+ zDiv = ",";
24540
+ if( zCol==0 ) zCol = "";
24541
+ cQuote = quoteChar(zCol);
24542
+ appendText(&s, zCol, cQuote);
24543
+ }
24544
+ appendText(&s, ")", 0);
24545
+ sqlite3_finalize(pStmt);
24546
+ if( nRow==0 ){
24547
+ freeText(&s);
24548
+ s.zTxt = 0;
24549
+ }
24550
+ return s.zTxt;
24551
+}
24552
+
24553
+/*
24554
+** SQL function: strtod(X)
24555
+**
24556
+** Use the C-library strtod() function to convert string X into a double.
24557
+** Used for comparing the accuracy of SQLite's internal text-to-float conversion
24558
+** routines against the C-library.
24559
+*/
24560
+static void shellStrtod(
24561
+ sqlite3_context *pCtx,
24562
+ int nVal,
24563
+ sqlite3_value **apVal
24564
+){
24565
+ char *z = (char*)sqlite3_value_text(apVal[0]);
24566
+ UNUSED_PARAMETER(nVal);
24567
+ if( z==0 ) return;
24568
+ sqlite3_result_double(pCtx, strtod(z,0));
24569
+}
24570
+
24571
+/*
24572
+** SQL function: dtostr(X)
24573
+**
24574
+** Use the C-library printf() function to convert real value X into a string.
24575
+** Used for comparing the accuracy of SQLite's internal float-to-text conversion
24576
+** routines against the C-library.
24577
+*/
24578
+static void shellDtostr(
24579
+ sqlite3_context *pCtx,
24580
+ int nVal,
24581
+ sqlite3_value **apVal
24582
+){
24583
+ double r = sqlite3_value_double(apVal[0]);
24584
+ int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
24585
+ char z[400];
24586
+ if( n<1 ) n = 1;
24587
+ if( n>350 ) n = 350;
24588
+ sprintf(z, "%#+.*e", n, r);
24589
+ sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
24590
+}
24591
+
24592
+/*
24593
+** SQL function: shell_add_schema(S,X)
24594
+**
24595
+** Add the schema name X to the CREATE statement in S and return the result.
24596
+** Examples:
24597
+**
24598
+** CREATE TABLE t1(x) -> CREATE TABLE xyz.t1(x);
24599
+**
24600
+** Also works on
24601
+**
24602
+** CREATE INDEX
24603
+** CREATE UNIQUE INDEX
24604
+** CREATE VIEW
24605
+** CREATE TRIGGER
24606
+** CREATE VIRTUAL TABLE
24607
+**
24608
+** This UDF is used by the .schema command to insert the schema name of
24609
+** attached databases into the middle of the sqlite_schema.sql field.
24610
+*/
24611
+static void shellAddSchemaName(
24612
+ sqlite3_context *pCtx,
24613
+ int nVal,
24614
+ sqlite3_value **apVal
24615
+){
24616
+ static const char *aPrefix[] = {
24617
+ "TABLE",
24618
+ "INDEX",
24619
+ "UNIQUE INDEX",
24620
+ "VIEW",
24621
+ "TRIGGER",
24622
+ "VIRTUAL TABLE"
24623
+ };
24624
+ int i = 0;
24625
+ const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
24626
+ const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
24627
+ const char *zName = (const char*)sqlite3_value_text(apVal[2]);
24628
+ sqlite3 *db = sqlite3_context_db_handle(pCtx);
24629
+ UNUSED_PARAMETER(nVal);
24630
+ if( zIn!=0 && cli_strncmp(zIn, "CREATE ", 7)==0 ){
24631
+ for(i=0; i<ArraySize(aPrefix); i++){
24632
+ int n = strlen30(aPrefix[i]);
24633
+ if( cli_strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
24634
+ char *z = 0;
24635
+ char *zFake = 0;
24636
+ if( zSchema ){
24637
+ char cQuote = quoteChar(zSchema);
24638
+ if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){
24639
+ z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
24640
+ }else{
24641
+ z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
24642
+ }
24643
+ }
24644
+ if( zName
24645
+ && aPrefix[i][0]=='V'
24646
+ && (zFake = shellFakeSchema(db, zSchema, zName))!=0
24647
+ ){
24648
+ if( z==0 ){
24649
+ z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
24650
+ }else{
24651
+ z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
24652
+ }
24653
+ sqlite3_free(zFake);
24654
+ }
24655
+ if( z ){
24656
+ sqlite3_result_text(pCtx, z, -1, sqlite3_free);
24657
+ return;
24658
+ }
24659
+ }
24660
+ }
24661
+ }
24662
+ sqlite3_result_value(pCtx, apVal[0]);
24663
+}
24664
+
2466324665
2466424666
/************************* BEGIN PERFORMANCE TIMER *****************************/
2466524667
#if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
2466624668
#include <sys/time.h>
2466724669
#include <sys/resource.h>
@@ -33862,11 +33864,11 @@
3386233864
if( i==nArg-1 ){
3386333865
dotCmdError(p, i, "missing argument", 0);
3386433866
return 1;
3386533867
}
3386633868
i++;
33867
- p->tmProgress = sqlite3_atof(azArg[i]);
33869
+ p->tmProgress = atof(azArg[i]);
3386833870
if( p->tmProgress>0.0 ){
3386933871
p->flgProgress = SHELL_PROGRESS_QUIET|SHELL_PROGRESS_TMOUT;
3387033872
if( nn==0 ) nn = 100;
3387133873
}
3387233874
continue;
@@ -35831,16 +35833,17 @@
3583135833
/*
3583235834
** Alternate one_input_line() impl for wasm mode. This is not in the primary
3583335835
** impl because we need the global shellState and cannot access it from that
3583435836
** function without moving lots of code around (creating a larger/messier diff).
3583535837
*/
35836
-static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
35838
+static char *one_input_line(ShellState *p, char *zPrior, int isContinuation){
3583735839
/* Parse the next line from shellState.wasm.zInput. */
3583835840
const char *zBegin = shellState.wasm.zPos;
3583935841
const char *z = zBegin;
3584035842
char *zLine = 0;
3584135843
i64 nZ = 0;
35844
+ FILE *in = p->in;
3584235845
3584335846
UNUSED_PARAMETER(in);
3584435847
UNUSED_PARAMETER(isContinuation);
3584535848
if(!z || !*z){
3584635849
return 0;
@@ -35894,11 +35897,11 @@
3589435897
saved_lineno = p->lineno;
3589535898
p->lineno = 0;
3589635899
CONTINUE_PROMPT_RESET;
3589735900
while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
3589835901
fflush(p->out);
35899
- zLine = one_input_line(p->in, zLine, nSql>0);
35902
+ zLine = one_input_line(p, zLine, nSql>0);
3590035903
if( zLine==0 ){
3590135904
/* End of input */
3590235905
if( p->in==0 && stdin_is_interactive ) cli_puts("\n", p->out);
3590335906
break;
3590435907
}
3590535908
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -59,10 +59,26 @@
59 #define _CRT_SECURE_NO_WARNINGS
60 #endif
61 typedef unsigned int u32;
62 typedef unsigned short int u16;
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64 /*
65 ** Optionally #include a user-defined header, whereby compilation options
66 ** may be set prior to where they take effect, but after platform setup.
67 ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
68 ** file. Note that this macro has a like effect on sqlite3.c compilation.
@@ -3879,774 +3895,10 @@
3879 # define SQLITE_CIO_NO_TRANSLATE
3880 # define SQLITE_CIO_NO_SETMODE
3881 # define SQLITE_CIO_NO_FLUSH
3882 #endif
3883
3884 /*
3885 ** Output routines that are able to redirect to memory rather than
3886 ** doing actually I/O.
3887 ** Works like.
3888 ** --------------
3889 ** cli_printf(FILE*, const char*, ...); fprintf()
3890 ** cli_puts(const char*, FILE*); fputs()
3891 ** cli_vprintf(FILE*, const char*, va_list); vfprintf()
3892 **
3893 ** These are just thin wrappers with the following added semantics:
3894 ** If the file-scope variable cli_output_capture is not NULL, and
3895 ** if the FILE* argument is stdout or stderr, then rather than
3896 ** writing to stdout/stdout, append the text to the cli_output_capture
3897 ** variable.
3898 **
3899 ** The cli_exit(int) routine works like exit() except that it
3900 ** first dumps any capture output to stdout.
3901 */
3902 static sqlite3_str *cli_output_capture = 0;
3903 static int cli_printf(FILE *out, const char *zFormat, ...){
3904 va_list ap;
3905 int rc;
3906 va_start(ap,zFormat);
3907 if( cli_output_capture && (out==stdout || out==stderr) ){
3908 sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
3909 rc = 1;
3910 }else{
3911 rc = sqlite3_vfprintf(out, zFormat, ap);
3912 }
3913 va_end(ap);
3914 return rc;
3915 }
3916 static int cli_puts(const char *zText, FILE *out){
3917 if( cli_output_capture && (out==stdout || out==stderr) ){
3918 sqlite3_str_appendall(cli_output_capture, zText);
3919 return 1;
3920 }
3921 return sqlite3_fputs(zText, out);
3922 }
3923 #if 0 /* Not currently used - available if we need it later */
3924 static int cli_vprintf(FILE *out, const char *zFormat, va_list ap){
3925 if( cli_output_capture && (out==stdout || out==stderr) ){
3926 sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
3927 return 1;
3928 }else{
3929 return sqlite3_vfprintf(out, zFormat, ap);
3930 }
3931 }
3932 #endif
3933 static void cli_exit(int rc){
3934 if( cli_output_capture ){
3935 char *z = sqlite3_str_finish(cli_output_capture);
3936 sqlite3_fputs(z, stdout);
3937 fflush(stdout);
3938 }
3939 exit(rc);
3940 }
3941
3942
3943 #define eputz(z) cli_puts(z,stderr)
3944 #define sputz(fp,z) cli_puts(z,fp)
3945
3946 /* A version of strcmp() that works with NULL values */
3947 static int cli_strcmp(const char *a, const char *b){
3948 if( a==0 ) a = "";
3949 if( b==0 ) b = "";
3950 return strcmp(a,b);
3951 }
3952 static int cli_strncmp(const char *a, const char *b, size_t n){
3953 if( a==0 ) a = "";
3954 if( b==0 ) b = "";
3955 return strncmp(a,b,n);
3956 }
3957
3958 /* Return the current wall-clock time in microseconds since the
3959 ** Unix epoch (1970-01-01T00:00:00Z)
3960 */
3961 static sqlite3_int64 timeOfDay(void){
3962 #if defined(_WIN64) && _WIN32_WINNT >= _WIN32_WINNT_WIN8
3963 sqlite3_uint64 t;
3964 FILETIME tm;
3965 GetSystemTimePreciseAsFileTime(&tm);
3966 t = ((u64)tm.dwHighDateTime<<32) | (u64)tm.dwLowDateTime;
3967 t += 116444736000000000LL;
3968 t /= 10;
3969 return t;
3970 #elif defined(_WIN32)
3971 static sqlite3_vfs *clockVfs = 0;
3972 sqlite3_int64 t;
3973 if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
3974 if( clockVfs==0 ) return 0; /* Never actually happens */
3975 if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
3976 clockVfs->xCurrentTimeInt64(clockVfs, &t);
3977 }else{
3978 double r;
3979 clockVfs->xCurrentTime(clockVfs, &r);
3980 t = (sqlite3_int64)(r*86400000.0);
3981 }
3982 return t*1000;
3983 #else
3984 struct timeval sNow;
3985 (void)gettimeofday(&sNow,0);
3986 return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
3987 #endif
3988 }
3989
3990
3991 /*
3992 ** Used to prevent warnings about unused parameters
3993 */
3994 #define UNUSED_PARAMETER(x) (void)(x)
3995
3996 /*
3997 ** Number of elements in an array
3998 */
3999 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
4000
4001 /*
4002 ** If the following flag is set, then command execution stops
4003 ** at an error if we are not interactive.
4004 */
4005 static int bail_on_error = 0;
4006
4007 /*
4008 ** Treat stdin as an interactive input if the following variable
4009 ** is true. Otherwise, assume stdin is connected to a file or pipe.
4010 */
4011 static int stdin_is_interactive = 1;
4012
4013 /*
4014 ** Treat stdout like a TTY if true.
4015 */
4016 static int stdout_is_console = 1;
4017
4018 /*
4019 ** Use this value as the width of the output device. Or, figure it
4020 ** out at runtime if the value is negative. Or use a default width
4021 ** if this value is zero.
4022 */
4023 static int stdout_tty_width = -1;
4024
4025 /*
4026 ** The following is the open SQLite database. We make a pointer
4027 ** to this database a static variable so that it can be accessed
4028 ** by the SIGINT handler to interrupt database processing.
4029 */
4030 static sqlite3 *globalDb = 0;
4031
4032 /*
4033 ** True if an interrupt (Control-C) has been received.
4034 */
4035 static volatile int seenInterrupt = 0;
4036
4037 /*
4038 ** This is the name of our program. It is set in main(), used
4039 ** in a number of other places, mostly for error messages.
4040 */
4041 static char *Argv0;
4042
4043 /*
4044 ** Prompt strings. Initialized in main. Settable with
4045 ** .prompt main continue
4046 */
4047 #define PROMPT_LEN_MAX 128
4048 /* First line prompt. default: "sqlite> " */
4049 static char mainPrompt[PROMPT_LEN_MAX];
4050 /* Continuation prompt. default: " ...> " */
4051 static char continuePrompt[PROMPT_LEN_MAX];
4052
4053 /*
4054 ** Write I/O traces to the following stream.
4055 */
4056 #ifdef SQLITE_ENABLE_IOTRACE
4057 static FILE *iotrace = 0;
4058 #endif
4059
4060
4061 /* This is variant of the standard-library strncpy() routine with the
4062 ** one change that the destination string is always zero-terminated, even
4063 ** if there is no zero-terminator in the first n-1 characters of the source
4064 ** string.
4065 */
4066 static char *shell_strncpy(char *dest, const char *src, size_t n){
4067 size_t i;
4068 for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
4069 dest[i] = 0;
4070 return dest;
4071 }
4072
4073 /*
4074 ** strcpy() workalike to squelch an unwarranted link-time warning
4075 ** from OpenBSD.
4076 */
4077 static void shell_strcpy(char *dest, const char *src){
4078 while( (*(dest++) = *(src++))!=0 ){}
4079 }
4080
4081 /*
4082 ** Optionally disable dynamic continuation prompt.
4083 ** Unless disabled, the continuation prompt shows open SQL lexemes if any,
4084 ** or open parentheses level if non-zero, or continuation prompt as set.
4085 ** This facility interacts with the scanner and process_input() where the
4086 ** below 5 macros are used.
4087 */
4088 #ifdef SQLITE_OMIT_DYNAPROMPT
4089 # define CONTINUATION_PROMPT continuePrompt
4090 # define CONTINUE_PROMPT_RESET
4091 # define CONTINUE_PROMPT_AWAITS(p,s)
4092 # define CONTINUE_PROMPT_AWAITC(p,c)
4093 # define CONTINUE_PAREN_INCR(p,n)
4094 # define CONTINUE_PROMPT_PSTATE 0
4095 typedef void *t_NoDynaPrompt;
4096 # define SCAN_TRACKER_REFTYPE t_NoDynaPrompt
4097 #else
4098 # define CONTINUATION_PROMPT dynamicContinuePrompt()
4099 # define CONTINUE_PROMPT_RESET \
4100 do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
4101 # define CONTINUE_PROMPT_AWAITS(p,s) \
4102 if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)
4103 # define CONTINUE_PROMPT_AWAITC(p,c) \
4104 if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)
4105 # define CONTINUE_PAREN_INCR(p,n) \
4106 if(p && stdin_is_interactive) (trackParenLevel(p,n))
4107 # define CONTINUE_PROMPT_PSTATE (&dynPrompt)
4108 typedef struct DynaPrompt *t_DynaPromptRef;
4109 # define SCAN_TRACKER_REFTYPE t_DynaPromptRef
4110
4111 static struct DynaPrompt {
4112 char dynamicPrompt[PROMPT_LEN_MAX];
4113 char acAwait[2];
4114 int inParenLevel;
4115 char *zScannerAwaits;
4116 } dynPrompt = { {0}, {0}, 0, 0 };
4117
4118 /* Record parenthesis nesting level change, or force level to 0. */
4119 static void trackParenLevel(struct DynaPrompt *p, int ni){
4120 p->inParenLevel += ni;
4121 if( ni==0 ) p->inParenLevel = 0;
4122 p->zScannerAwaits = 0;
4123 }
4124
4125 /* Record that a lexeme is opened, or closed with args==0. */
4126 static void setLexemeOpen(struct DynaPrompt *p, char *s, char c){
4127 if( s!=0 || c==0 ){
4128 p->zScannerAwaits = s;
4129 p->acAwait[0] = 0;
4130 }else{
4131 p->acAwait[0] = c;
4132 p->zScannerAwaits = p->acAwait;
4133 }
4134 }
4135
4136 /* Upon demand, derive the continuation prompt to display. */
4137 static char *dynamicContinuePrompt(void){
4138 if( continuePrompt[0]==0
4139 || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
4140 return continuePrompt;
4141 }else{
4142 if( dynPrompt.zScannerAwaits ){
4143 size_t ncp = strlen(continuePrompt);
4144 size_t ndp = strlen(dynPrompt.zScannerAwaits);
4145 if( ndp > ncp-3 ) return continuePrompt;
4146 shell_strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
4147 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
4148 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
4149 PROMPT_LEN_MAX-4);
4150 }else{
4151 if( dynPrompt.inParenLevel>9 ){
4152 shell_strncpy(dynPrompt.dynamicPrompt, "(..", 4);
4153 }else if( dynPrompt.inParenLevel<0 ){
4154 shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
4155 }else{
4156 shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
4157 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
4158 }
4159 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
4160 PROMPT_LEN_MAX-4);
4161 }
4162 }
4163 return dynPrompt.dynamicPrompt;
4164 }
4165 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
4166
4167 /* Indicate out-of-memory and exit. */
4168 static void shell_out_of_memory(void){
4169 eputz("Error: out of memory\n");
4170 cli_exit(1);
4171 }
4172
4173 /* Check a pointer to see if it is NULL. If it is NULL, exit with an
4174 ** out-of-memory error.
4175 */
4176 static void shell_check_oom(const void *p){
4177 if( p==0 ) shell_out_of_memory();
4178 }
4179
4180 /*
4181 ** This routine works like printf in that its first argument is a
4182 ** format string and subsequent arguments are values to be substituted
4183 ** in place of % fields. The result of formatting this string
4184 ** is written to iotrace.
4185 */
4186 #ifdef SQLITE_ENABLE_IOTRACE
4187 static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){
4188 va_list ap;
4189 char *z;
4190 if( iotrace==0 ) return;
4191 va_start(ap, zFormat);
4192 z = sqlite3_vmprintf(zFormat, ap);
4193 va_end(ap);
4194 cli_printf(iotrace, "%s", z);
4195 sqlite3_free(z);
4196 }
4197 #endif
4198
4199 /*
4200 ** Compute a string length that is limited to what can be stored in
4201 ** lower 30 bits of a 32-bit signed integer.
4202 */
4203 static int strlen30(const char *z){
4204 size_t n;
4205 if( z==0 ) return 0;
4206 n = strlen(z);
4207 return n>0x3fffffff ? 0x3fffffff : (int)n;
4208 }
4209
4210 /*
4211 ** Return open FILE * if zFile exists, can be opened for read
4212 ** and is an ordinary file or a character stream source.
4213 ** Otherwise return 0.
4214 */
4215 static FILE * openChrSource(const char *zFile){
4216 #if defined(_WIN32) || defined(WIN32)
4217 struct __stat64 x = {0};
4218 # define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0)
4219 /* On Windows, open first, then check the stream nature. This order
4220 ** is necessary because _stat() and sibs, when checking a named pipe,
4221 ** effectively break the pipe as its supplier sees it. */
4222 FILE *rv = sqlite3_fopen(zFile, "rb");
4223 if( rv==0 ) return 0;
4224 if( _fstat64(_fileno(rv), &x) != 0
4225 || !STAT_CHR_SRC(x.st_mode)){
4226 fclose(rv);
4227 rv = 0;
4228 }
4229 return rv;
4230 #else
4231 struct stat x = {0};
4232 int rc = stat(zFile, &x);
4233 # define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
4234 if( rc!=0 ) return 0;
4235 if( STAT_CHR_SRC(x.st_mode) ){
4236 return sqlite3_fopen(zFile, "rb");
4237 }else{
4238 return 0;
4239 }
4240 #endif
4241 #undef STAT_CHR_SRC
4242 }
4243
4244 /*
4245 ** This routine reads a line of text from FILE in, stores
4246 ** the text in memory obtained from malloc() and returns a pointer
4247 ** to the text. NULL is returned at end of file, or if malloc()
4248 ** fails, or if the length of the line is longer than about a gigabyte.
4249 **
4250 ** If zLine is not NULL then it is a malloced buffer returned from
4251 ** a previous call to this routine that may be reused.
4252 */
4253 static char *local_getline(char *zLine, FILE *in){
4254 int nLine = zLine==0 ? 0 : 100;
4255 int n = 0;
4256
4257 while( 1 ){
4258 if( n+100>nLine ){
4259 if( nLine>=1073741773 ){
4260 free(zLine);
4261 return 0;
4262 }
4263 nLine = nLine*2 + 100;
4264 zLine = realloc(zLine, nLine);
4265 shell_check_oom(zLine);
4266 }
4267 if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
4268 if( n==0 ){
4269 free(zLine);
4270 return 0;
4271 }
4272 zLine[n] = 0;
4273 break;
4274 }
4275 while( zLine[n] ) n++;
4276 if( n>0 && zLine[n-1]=='\n' ){
4277 n--;
4278 if( n>0 && zLine[n-1]=='\r' ) n--;
4279 zLine[n] = 0;
4280 break;
4281 }
4282 }
4283 return zLine;
4284 }
4285
4286 /*
4287 ** Retrieve a single line of input text.
4288 **
4289 ** If in==0 then read from standard input and prompt before each line.
4290 ** If isContinuation is true, then a continuation prompt is appropriate.
4291 ** If isContinuation is zero, then the main prompt should be used.
4292 **
4293 ** If zPrior is not NULL then it is a buffer from a prior call to this
4294 ** routine that can be reused.
4295 **
4296 ** The result is stored in space obtained from malloc() and must either
4297 ** be freed by the caller or else passed back into this routine via the
4298 ** zPrior argument for reuse.
4299 */
4300 #ifndef SQLITE_SHELL_FIDDLE
4301 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
4302 char *zPrompt;
4303 char *zResult;
4304 if( in!=0 ){
4305 zResult = local_getline(zPrior, in);
4306 }else{
4307 zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
4308 #if SHELL_USE_LOCAL_GETLINE
4309 sputz(stdout, zPrompt);
4310 fflush(stdout);
4311 do{
4312 zResult = local_getline(zPrior, stdin);
4313 zPrior = 0;
4314 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
4315 if( zResult==0 ) sqlite3_sleep(50);
4316 }while( zResult==0 && seenInterrupt>0 );
4317 #else
4318 free(zPrior);
4319 zResult = shell_readline(zPrompt);
4320 while( zResult==0 ){
4321 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
4322 sqlite3_sleep(50);
4323 if( seenInterrupt==0 ) break;
4324 zResult = shell_readline("");
4325 }
4326 if( zResult && *zResult ) shell_add_history(zResult);
4327 #endif
4328 }
4329 return zResult;
4330 }
4331 #endif /* !SQLITE_SHELL_FIDDLE */
4332
4333 /*
4334 ** Return the value of a hexadecimal digit. Return -1 if the input
4335 ** is not a hex digit.
4336 */
4337 static int hexDigitValue(char c){
4338 if( c>='0' && c<='9' ) return c - '0';
4339 if( c>='a' && c<='f' ) return c - 'a' + 10;
4340 if( c>='A' && c<='F' ) return c - 'A' + 10;
4341 return -1;
4342 }
4343
4344 /*
4345 ** Interpret zArg as an integer value, possibly with suffixes.
4346 **
4347 ** If the value specified by zArg is outside the range of values that
4348 ** can be represented using a 64-bit twos-complement integer, then return
4349 ** the nearest representable value.
4350 */
4351 static sqlite3_int64 integerValue(const char *zArg){
4352 sqlite3_uint64 v = 0;
4353 static const struct { char *zSuffix; unsigned int iMult; } aMult[] = {
4354 { "KiB", 1024 },
4355 { "MiB", 1024*1024 },
4356 { "GiB", 1024*1024*1024 },
4357 { "KB", 1000 },
4358 { "MB", 1000000 },
4359 { "GB", 1000000000 },
4360 { "K", 1000 },
4361 { "M", 1000000 },
4362 { "G", 1000000000 },
4363 };
4364 int i;
4365 int isNeg = 0;
4366 if( zArg[0]=='-' ){
4367 isNeg = 1;
4368 zArg++;
4369 }else if( zArg[0]=='+' ){
4370 zArg++;
4371 }
4372 if( zArg[0]=='0' && zArg[1]=='x' ){
4373 int x;
4374 zArg += 2;
4375 while( (x = hexDigitValue(zArg[0]))>=0 ){
4376 if( v > 0x0fffffffffffffffULL ) goto integer_overflow;
4377 v = (v<<4) + x;
4378 zArg++;
4379 }
4380 }else{
4381 while( IsDigit(zArg[0]) ){
4382 if( v>=922337203685477580LL ){
4383 if( v>922337203685477580LL || zArg[0]>='8' ) goto integer_overflow;
4384 }
4385 v = v*10 + (zArg[0] - '0');
4386 zArg++;
4387 }
4388 }
4389 for(i=0; i<ArraySize(aMult); i++){
4390 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
4391 if( 0x7fffffffffffffffULL/aMult[i].iMult < v ) goto integer_overflow;
4392 v *= aMult[i].iMult;
4393 break;
4394 }
4395 }
4396 if( isNeg && v>0x7fffffffffffffffULL ) goto integer_overflow;
4397 return isNeg? -(sqlite3_int64)v : (sqlite3_int64)v;
4398 integer_overflow:
4399 return isNeg ? (i64)0x8000000000000000LL : 0x7fffffffffffffffLL;
4400 }
4401
4402 /*
4403 ** A variable length string to which one can append text.
4404 */
4405 typedef struct ShellText ShellText;
4406 struct ShellText {
4407 char *zTxt; /* The text */
4408 i64 n; /* Number of bytes of zTxt[] actually used */
4409 i64 nAlloc; /* Number of bytes allocated for zTxt[] */
4410 };
4411
4412 /*
4413 ** Initialize and destroy a ShellText object
4414 */
4415 static void initText(ShellText *p){
4416 memset(p, 0, sizeof(*p));
4417 }
4418 static void freeText(ShellText *p){
4419 sqlite3_free(p->zTxt);
4420 initText(p);
4421 }
4422
4423 /* zIn is either a pointer to a NULL-terminated string in memory obtained
4424 ** from malloc(), or a NULL pointer. The string pointed to by zAppend is
4425 ** added to zIn, and the result returned in memory obtained from malloc().
4426 ** zIn, if it was not NULL, is freed.
4427 **
4428 ** If the third argument, quote, is not '\0', then it is used as a
4429 ** quote character for zAppend.
4430 */
4431 static void appendText(ShellText *p, const char *zAppend, char quote){
4432 i64 len;
4433 i64 i;
4434 i64 nAppend = strlen30(zAppend);
4435
4436 len = nAppend+p->n+1;
4437 if( quote ){
4438 len += 2;
4439 for(i=0; i<nAppend; i++){
4440 if( zAppend[i]==quote ) len++;
4441 }
4442 }
4443
4444 if( p->zTxt==0 || p->n+len>=p->nAlloc ){
4445 p->nAlloc = p->nAlloc*2 + len + 20;
4446 p->zTxt = sqlite3_realloc64(p->zTxt, p->nAlloc);
4447 shell_check_oom(p->zTxt);
4448 }
4449
4450 if( quote ){
4451 char *zCsr = p->zTxt+p->n;
4452 *zCsr++ = quote;
4453 for(i=0; i<nAppend; i++){
4454 *zCsr++ = zAppend[i];
4455 if( zAppend[i]==quote ) *zCsr++ = quote;
4456 }
4457 *zCsr++ = quote;
4458 p->n = (i64)(zCsr - p->zTxt);
4459 *zCsr = '\0';
4460 }else{
4461 memcpy(p->zTxt+p->n, zAppend, nAppend);
4462 p->n += nAppend;
4463 p->zTxt[p->n] = '\0';
4464 }
4465 }
4466
4467 /*
4468 ** Attempt to determine if identifier zName needs to be quoted, either
4469 ** because it contains non-alphanumeric characters, or because it is an
4470 ** SQLite keyword. Be conservative in this estimate: When in doubt assume
4471 ** that quoting is required.
4472 **
4473 ** Return '"' if quoting is required. Return 0 if no quoting is required.
4474 */
4475 static char quoteChar(const char *zName){
4476 int i;
4477 if( zName==0 ) return '"';
4478 if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"';
4479 for(i=0; zName[i]; i++){
4480 if( !IsAlnum(zName[i]) && zName[i]!='_' ) return '"';
4481 }
4482 return sqlite3_keyword_check(zName, i) ? '"' : 0;
4483 }
4484
4485 /*
4486 ** Construct a fake object name and column list to describe the structure
4487 ** of the view, virtual table, or table valued function zSchema.zName.
4488 **
4489 ** The returned string comes from sqlite3_mprintf() and should be freed
4490 ** by the caller using sqlite3_free().
4491 */
4492 static char *shellFakeSchema(
4493 sqlite3 *db, /* The database connection containing the vtab */
4494 const char *zSchema, /* Schema of the database holding the vtab */
4495 const char *zName /* The name of the virtual table */
4496 ){
4497 sqlite3_stmt *pStmt = 0;
4498 char *zSql;
4499 ShellText s;
4500 char cQuote;
4501 char *zDiv = "(";
4502 int nRow = 0;
4503
4504 zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
4505 zSchema ? zSchema : "main", zName);
4506 shell_check_oom(zSql);
4507 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
4508 sqlite3_free(zSql);
4509 initText(&s);
4510 if( zSchema ){
4511 cQuote = quoteChar(zSchema);
4512 if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
4513 appendText(&s, zSchema, cQuote);
4514 appendText(&s, ".", 0);
4515 }
4516 cQuote = quoteChar(zName);
4517 appendText(&s, zName, cQuote);
4518 while( sqlite3_step(pStmt)==SQLITE_ROW ){
4519 const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
4520 nRow++;
4521 appendText(&s, zDiv, 0);
4522 zDiv = ",";
4523 if( zCol==0 ) zCol = "";
4524 cQuote = quoteChar(zCol);
4525 appendText(&s, zCol, cQuote);
4526 }
4527 appendText(&s, ")", 0);
4528 sqlite3_finalize(pStmt);
4529 if( nRow==0 ){
4530 freeText(&s);
4531 s.zTxt = 0;
4532 }
4533 return s.zTxt;
4534 }
4535
4536 /*
4537 ** SQL function: strtod(X)
4538 **
4539 ** Use the C-library strtod() function to convert string X into a double.
4540 ** Used for comparing the accuracy of SQLite's internal text-to-float conversion
4541 ** routines against the C-library.
4542 */
4543 static void shellStrtod(
4544 sqlite3_context *pCtx,
4545 int nVal,
4546 sqlite3_value **apVal
4547 ){
4548 char *z = (char*)sqlite3_value_text(apVal[0]);
4549 UNUSED_PARAMETER(nVal);
4550 if( z==0 ) return;
4551 sqlite3_result_double(pCtx, strtod(z,0));
4552 }
4553
4554 /*
4555 ** SQL function: dtostr(X)
4556 **
4557 ** Use the C-library printf() function to convert real value X into a string.
4558 ** Used for comparing the accuracy of SQLite's internal float-to-text conversion
4559 ** routines against the C-library.
4560 */
4561 static void shellDtostr(
4562 sqlite3_context *pCtx,
4563 int nVal,
4564 sqlite3_value **apVal
4565 ){
4566 double r = sqlite3_value_double(apVal[0]);
4567 int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
4568 char z[400];
4569 if( n<1 ) n = 1;
4570 if( n>350 ) n = 350;
4571 sprintf(z, "%#+.*e", n, r);
4572 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
4573 }
4574
4575 /*
4576 ** SQL function: shell_add_schema(S,X)
4577 **
4578 ** Add the schema name X to the CREATE statement in S and return the result.
4579 ** Examples:
4580 **
4581 ** CREATE TABLE t1(x) -> CREATE TABLE xyz.t1(x);
4582 **
4583 ** Also works on
4584 **
4585 ** CREATE INDEX
4586 ** CREATE UNIQUE INDEX
4587 ** CREATE VIEW
4588 ** CREATE TRIGGER
4589 ** CREATE VIRTUAL TABLE
4590 **
4591 ** This UDF is used by the .schema command to insert the schema name of
4592 ** attached databases into the middle of the sqlite_schema.sql field.
4593 */
4594 static void shellAddSchemaName(
4595 sqlite3_context *pCtx,
4596 int nVal,
4597 sqlite3_value **apVal
4598 ){
4599 static const char *aPrefix[] = {
4600 "TABLE",
4601 "INDEX",
4602 "UNIQUE INDEX",
4603 "VIEW",
4604 "TRIGGER",
4605 "VIRTUAL TABLE"
4606 };
4607 int i = 0;
4608 const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
4609 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
4610 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
4611 sqlite3 *db = sqlite3_context_db_handle(pCtx);
4612 UNUSED_PARAMETER(nVal);
4613 if( zIn!=0 && cli_strncmp(zIn, "CREATE ", 7)==0 ){
4614 for(i=0; i<ArraySize(aPrefix); i++){
4615 int n = strlen30(aPrefix[i]);
4616 if( cli_strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
4617 char *z = 0;
4618 char *zFake = 0;
4619 if( zSchema ){
4620 char cQuote = quoteChar(zSchema);
4621 if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){
4622 z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
4623 }else{
4624 z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
4625 }
4626 }
4627 if( zName
4628 && aPrefix[i][0]=='V'
4629 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
4630 ){
4631 if( z==0 ){
4632 z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
4633 }else{
4634 z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
4635 }
4636 sqlite3_free(zFake);
4637 }
4638 if( z ){
4639 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
4640 return;
4641 }
4642 }
4643 }
4644 }
4645 sqlite3_result_value(pCtx, apVal[0]);
4646 }
4647
4648 /*
4649 ** The source code for several run-time loadable extensions is inserted
4650 ** below by the ../tool/mkshellc.tcl script. Before processing that included
4651 ** code, we need to override some macros to make the included program code
4652 ** work here in the middle of this regular program.
@@ -24654,14 +23906,764 @@
24654 #ifndef DFLT_MULTI_INSERT
24655 # define DFLT_MULTI_INSERT 3000
24656 #endif
24657
24658 /*
24659 ** Limit input nesting via .read or any other input redirect.
24660 ** It's not too expensive, so a generous allowance can be made.
24661 */
24662 #define MAX_INPUT_NESTING 25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24663
24664 /************************* BEGIN PERFORMANCE TIMER *****************************/
24665 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
24666 #include <sys/time.h>
24667 #include <sys/resource.h>
@@ -33862,11 +33864,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;
@@ -35831,16 +35833,17 @@
35831 /*
35832 ** Alternate one_input_line() impl for wasm mode. This is not in the primary
35833 ** impl because we need the global shellState and cannot access it from that
35834 ** function without moving lots of code around (creating a larger/messier diff).
35835 */
35836 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
35837 /* Parse the next line from shellState.wasm.zInput. */
35838 const char *zBegin = shellState.wasm.zPos;
35839 const char *z = zBegin;
35840 char *zLine = 0;
35841 i64 nZ = 0;
 
35842
35843 UNUSED_PARAMETER(in);
35844 UNUSED_PARAMETER(isContinuation);
35845 if(!z || !*z){
35846 return 0;
@@ -35894,11 +35897,11 @@
35894 saved_lineno = p->lineno;
35895 p->lineno = 0;
35896 CONTINUE_PROMPT_RESET;
35897 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
35898 fflush(p->out);
35899 zLine = one_input_line(p->in, zLine, nSql>0);
35900 if( zLine==0 ){
35901 /* End of input */
35902 if( p->in==0 && stdin_is_interactive ) cli_puts("\n", p->out);
35903 break;
35904 }
35905
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -59,10 +59,26 @@
59 #define _CRT_SECURE_NO_WARNINGS
60 #endif
61 typedef unsigned int u32;
62 typedef unsigned short int u16;
63
64 /*
65 ** Limit input nesting via .read or any other input redirect.
66 ** It's not too expensive, so a generous allowance can be made.
67 */
68 #define MAX_INPUT_NESTING 25
69
70 /*
71 ** Used to prevent warnings about unused parameters
72 */
73 #define UNUSED_PARAMETER(x) (void)(x)
74
75 /*
76 ** Number of elements in an array
77 */
78 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
79
80 /*
81 ** Optionally #include a user-defined header, whereby compilation options
82 ** may be set prior to where they take effect, but after platform setup.
83 ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
84 ** file. Note that this macro has a like effect on sqlite3.c compilation.
@@ -3879,774 +3895,10 @@
3895 # define SQLITE_CIO_NO_TRANSLATE
3896 # define SQLITE_CIO_NO_SETMODE
3897 # define SQLITE_CIO_NO_FLUSH
3898 #endif
3899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3900 /*
3901 ** The source code for several run-time loadable extensions is inserted
3902 ** below by the ../tool/mkshellc.tcl script. Before processing that included
3903 ** code, we need to override some macros to make the included program code
3904 ** work here in the middle of this regular program.
@@ -24654,14 +23906,764 @@
23906 #ifndef DFLT_MULTI_INSERT
23907 # define DFLT_MULTI_INSERT 3000
23908 #endif
23909
23910 /*
23911 ** If the following flag is set, then command execution stops
23912 ** at an error if we are not interactive.
23913 */
23914 static int bail_on_error = 0;
23915
23916 /*
23917 ** Treat stdin as an interactive input if the following variable
23918 ** is true. Otherwise, assume stdin is connected to a file or pipe.
23919 */
23920 static int stdin_is_interactive = 1;
23921
23922 /*
23923 ** Treat stdout like a TTY if true.
23924 */
23925 static int stdout_is_console = 1;
23926
23927 /*
23928 ** Use this value as the width of the output device. Or, figure it
23929 ** out at runtime if the value is negative. Or use a default width
23930 ** if this value is zero.
23931 */
23932 static int stdout_tty_width = -1;
23933
23934 /*
23935 ** The following is the open SQLite database. We make a pointer
23936 ** to this database a static variable so that it can be accessed
23937 ** by the SIGINT handler to interrupt database processing.
23938 */
23939 static sqlite3 *globalDb = 0;
23940
23941 /*
23942 ** True if an interrupt (Control-C) has been received.
23943 */
23944 static volatile int seenInterrupt = 0;
23945
23946 /*
23947 ** This is the name of our program. It is set in main(), used
23948 ** in a number of other places, mostly for error messages.
23949 */
23950 static char *Argv0;
23951
23952 /*
23953 ** Prompt strings. Initialized in main. Settable with
23954 ** .prompt main continue
23955 */
23956 #define PROMPT_LEN_MAX 128
23957 /* First line prompt. default: "sqlite> " */
23958 static char mainPrompt[PROMPT_LEN_MAX];
23959 /* Continuation prompt. default: " ...> " */
23960 static char continuePrompt[PROMPT_LEN_MAX];
23961
23962 /*
23963 ** Write I/O traces to the following stream.
23964 */
23965 #ifdef SQLITE_ENABLE_IOTRACE
23966 static FILE *iotrace = 0;
23967 #endif
23968
23969 /*
23970 ** Output routines that are able to redirect to memory rather than
23971 ** doing actually I/O.
23972 ** Works like.
23973 ** --------------
23974 ** cli_printf(FILE*, const char*, ...); fprintf()
23975 ** cli_puts(const char*, FILE*); fputs()
23976 ** cli_vprintf(FILE*, const char*, va_list); vfprintf()
23977 **
23978 ** These are just thin wrappers with the following added semantics:
23979 ** If the file-scope variable cli_output_capture is not NULL, and
23980 ** if the FILE* argument is stdout or stderr, then rather than
23981 ** writing to stdout/stdout, append the text to the cli_output_capture
23982 ** variable.
23983 **
23984 ** The cli_exit(int) routine works like exit() except that it
23985 ** first dumps any capture output to stdout.
23986 */
23987 static sqlite3_str *cli_output_capture = 0;
23988 static int cli_printf(FILE *out, const char *zFormat, ...){
23989 va_list ap;
23990 int rc;
23991 va_start(ap,zFormat);
23992 if( cli_output_capture && (out==stdout || out==stderr) ){
23993 sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
23994 rc = 1;
23995 }else{
23996 rc = sqlite3_vfprintf(out, zFormat, ap);
23997 }
23998 va_end(ap);
23999 return rc;
24000 }
24001 static int cli_puts(const char *zText, FILE *out){
24002 if( cli_output_capture && (out==stdout || out==stderr) ){
24003 sqlite3_str_appendall(cli_output_capture, zText);
24004 return 1;
24005 }
24006 return sqlite3_fputs(zText, out);
24007 }
24008 #if 0 /* Not currently used - available if we need it later */
24009 static int cli_vprintf(FILE *out, const char *zFormat, va_list ap){
24010 if( cli_output_capture && (out==stdout || out==stderr) ){
24011 sqlite3_str_vappendf(cli_output_capture, zFormat, ap);
24012 return 1;
24013 }else{
24014 return sqlite3_vfprintf(out, zFormat, ap);
24015 }
24016 }
24017 #endif
24018 static void cli_exit(int rc){
24019 if( cli_output_capture ){
24020 char *z = sqlite3_str_finish(cli_output_capture);
24021 sqlite3_fputs(z, stdout);
24022 fflush(stdout);
24023 }
24024 exit(rc);
24025 }
24026
24027
24028 #define eputz(z) cli_puts(z,stderr)
24029 #define sputz(fp,z) cli_puts(z,fp)
24030
24031 /* A version of strcmp() that works with NULL values */
24032 static int cli_strcmp(const char *a, const char *b){
24033 if( a==0 ) a = "";
24034 if( b==0 ) b = "";
24035 return strcmp(a,b);
24036 }
24037 static int cli_strncmp(const char *a, const char *b, size_t n){
24038 if( a==0 ) a = "";
24039 if( b==0 ) b = "";
24040 return strncmp(a,b,n);
24041 }
24042
24043 /* Return the current wall-clock time in microseconds since the
24044 ** Unix epoch (1970-01-01T00:00:00Z)
24045 */
24046 static sqlite3_int64 timeOfDay(void){
24047 #if defined(_WIN64) && _WIN32_WINNT >= _WIN32_WINNT_WIN8
24048 sqlite3_uint64 t;
24049 FILETIME tm;
24050 GetSystemTimePreciseAsFileTime(&tm);
24051 t = ((u64)tm.dwHighDateTime<<32) | (u64)tm.dwLowDateTime;
24052 t += 116444736000000000LL;
24053 t /= 10;
24054 return t;
24055 #elif defined(_WIN32)
24056 static sqlite3_vfs *clockVfs = 0;
24057 sqlite3_int64 t;
24058 if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
24059 if( clockVfs==0 ) return 0; /* Never actually happens */
24060 if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
24061 clockVfs->xCurrentTimeInt64(clockVfs, &t);
24062 }else{
24063 double r;
24064 clockVfs->xCurrentTime(clockVfs, &r);
24065 t = (sqlite3_int64)(r*86400000.0);
24066 }
24067 return t*1000;
24068 #else
24069 struct timeval sNow;
24070 (void)gettimeofday(&sNow,0);
24071 return ((i64)sNow.tv_sec)*1000000 + sNow.tv_usec;
24072 #endif
24073 }
24074
24075
24076
24077 /* This is variant of the standard-library strncpy() routine with the
24078 ** one change that the destination string is always zero-terminated, even
24079 ** if there is no zero-terminator in the first n-1 characters of the source
24080 ** string.
24081 */
24082 static char *shell_strncpy(char *dest, const char *src, size_t n){
24083 size_t i;
24084 for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
24085 dest[i] = 0;
24086 return dest;
24087 }
24088
24089 /*
24090 ** strcpy() workalike to squelch an unwarranted link-time warning
24091 ** from OpenBSD.
24092 */
24093 static void shell_strcpy(char *dest, const char *src){
24094 while( (*(dest++) = *(src++))!=0 ){}
24095 }
24096
24097 /*
24098 ** Optionally disable dynamic continuation prompt.
24099 ** Unless disabled, the continuation prompt shows open SQL lexemes if any,
24100 ** or open parentheses level if non-zero, or continuation prompt as set.
24101 ** This facility interacts with the scanner and process_input() where the
24102 ** below 5 macros are used.
24103 */
24104 #ifdef SQLITE_OMIT_DYNAPROMPT
24105 # define CONTINUATION_PROMPT continuePrompt
24106 # define CONTINUE_PROMPT_RESET
24107 # define CONTINUE_PROMPT_AWAITS(p,s)
24108 # define CONTINUE_PROMPT_AWAITC(p,c)
24109 # define CONTINUE_PAREN_INCR(p,n)
24110 # define CONTINUE_PROMPT_PSTATE 0
24111 typedef void *t_NoDynaPrompt;
24112 # define SCAN_TRACKER_REFTYPE t_NoDynaPrompt
24113 #else
24114 # define CONTINUATION_PROMPT dynamicContinuePrompt()
24115 # define CONTINUE_PROMPT_RESET \
24116 do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
24117 # define CONTINUE_PROMPT_AWAITS(p,s) \
24118 if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)
24119 # define CONTINUE_PROMPT_AWAITC(p,c) \
24120 if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)
24121 # define CONTINUE_PAREN_INCR(p,n) \
24122 if(p && stdin_is_interactive) (trackParenLevel(p,n))
24123 # define CONTINUE_PROMPT_PSTATE (&dynPrompt)
24124 typedef struct DynaPrompt *t_DynaPromptRef;
24125 # define SCAN_TRACKER_REFTYPE t_DynaPromptRef
24126
24127 static struct DynaPrompt {
24128 char dynamicPrompt[PROMPT_LEN_MAX];
24129 char acAwait[2];
24130 int inParenLevel;
24131 char *zScannerAwaits;
24132 } dynPrompt = { {0}, {0}, 0, 0 };
24133
24134 /* Record parenthesis nesting level change, or force level to 0. */
24135 static void trackParenLevel(struct DynaPrompt *p, int ni){
24136 p->inParenLevel += ni;
24137 if( ni==0 ) p->inParenLevel = 0;
24138 p->zScannerAwaits = 0;
24139 }
24140
24141 /* Record that a lexeme is opened, or closed with args==0. */
24142 static void setLexemeOpen(struct DynaPrompt *p, char *s, char c){
24143 if( s!=0 || c==0 ){
24144 p->zScannerAwaits = s;
24145 p->acAwait[0] = 0;
24146 }else{
24147 p->acAwait[0] = c;
24148 p->zScannerAwaits = p->acAwait;
24149 }
24150 }
24151
24152 /* Upon demand, derive the continuation prompt to display. */
24153 static char *dynamicContinuePrompt(void){
24154 if( continuePrompt[0]==0
24155 || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
24156 return continuePrompt;
24157 }else{
24158 if( dynPrompt.zScannerAwaits ){
24159 size_t ncp = strlen(continuePrompt);
24160 size_t ndp = strlen(dynPrompt.zScannerAwaits);
24161 if( ndp > ncp-3 ) return continuePrompt;
24162 shell_strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
24163 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
24164 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
24165 PROMPT_LEN_MAX-4);
24166 }else{
24167 if( dynPrompt.inParenLevel>9 ){
24168 shell_strncpy(dynPrompt.dynamicPrompt, "(..", 4);
24169 }else if( dynPrompt.inParenLevel<0 ){
24170 shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
24171 }else{
24172 shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
24173 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
24174 }
24175 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
24176 PROMPT_LEN_MAX-4);
24177 }
24178 }
24179 return dynPrompt.dynamicPrompt;
24180 }
24181 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
24182
24183 /* Indicate out-of-memory and exit. */
24184 static void shell_out_of_memory(void){
24185 eputz("Error: out of memory\n");
24186 cli_exit(1);
24187 }
24188
24189 /* Check a pointer to see if it is NULL. If it is NULL, exit with an
24190 ** out-of-memory error.
24191 */
24192 static void shell_check_oom(const void *p){
24193 if( p==0 ) shell_out_of_memory();
24194 }
24195
24196 /*
24197 ** This routine works like printf in that its first argument is a
24198 ** format string and subsequent arguments are values to be substituted
24199 ** in place of % fields. The result of formatting this string
24200 ** is written to iotrace.
24201 */
24202 #ifdef SQLITE_ENABLE_IOTRACE
24203 static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){
24204 va_list ap;
24205 char *z;
24206 if( iotrace==0 ) return;
24207 va_start(ap, zFormat);
24208 z = sqlite3_vmprintf(zFormat, ap);
24209 va_end(ap);
24210 cli_printf(iotrace, "%s", z);
24211 sqlite3_free(z);
24212 }
24213 #endif
24214
24215 /*
24216 ** Compute a string length that is limited to what can be stored in
24217 ** lower 30 bits of a 32-bit signed integer.
24218 */
24219 static int strlen30(const char *z){
24220 size_t n;
24221 if( z==0 ) return 0;
24222 n = strlen(z);
24223 return n>0x3fffffff ? 0x3fffffff : (int)n;
24224 }
24225
24226 /*
24227 ** Return open FILE * if zFile exists, can be opened for read
24228 ** and is an ordinary file or a character stream source.
24229 ** Otherwise return 0.
24230 */
24231 static FILE * openChrSource(const char *zFile){
24232 #if defined(_WIN32) || defined(WIN32)
24233 struct __stat64 x = {0};
24234 # define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0)
24235 /* On Windows, open first, then check the stream nature. This order
24236 ** is necessary because _stat() and sibs, when checking a named pipe,
24237 ** effectively break the pipe as its supplier sees it. */
24238 FILE *rv = sqlite3_fopen(zFile, "rb");
24239 if( rv==0 ) return 0;
24240 if( _fstat64(_fileno(rv), &x) != 0
24241 || !STAT_CHR_SRC(x.st_mode)){
24242 fclose(rv);
24243 rv = 0;
24244 }
24245 return rv;
24246 #else
24247 struct stat x = {0};
24248 int rc = stat(zFile, &x);
24249 # define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
24250 if( rc!=0 ) return 0;
24251 if( STAT_CHR_SRC(x.st_mode) ){
24252 return sqlite3_fopen(zFile, "rb");
24253 }else{
24254 return 0;
24255 }
24256 #endif
24257 #undef STAT_CHR_SRC
24258 }
24259
24260 /*
24261 ** This routine reads a line of text from FILE in, stores
24262 ** the text in memory obtained from malloc() and returns a pointer
24263 ** to the text. NULL is returned at end of file, or if malloc()
24264 ** fails, or if the length of the line is longer than about a gigabyte.
24265 **
24266 ** If zLine is not NULL then it is a malloced buffer returned from
24267 ** a previous call to this routine that may be reused.
24268 */
24269 static char *local_getline(char *zLine, FILE *in){
24270 int nLine = zLine==0 ? 0 : 100;
24271 int n = 0;
24272
24273 while( 1 ){
24274 if( n+100>nLine ){
24275 if( nLine>=1073741773 ){
24276 free(zLine);
24277 return 0;
24278 }
24279 nLine = nLine*2 + 100;
24280 zLine = realloc(zLine, nLine);
24281 shell_check_oom(zLine);
24282 }
24283 if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
24284 if( n==0 ){
24285 free(zLine);
24286 return 0;
24287 }
24288 zLine[n] = 0;
24289 break;
24290 }
24291 while( zLine[n] ) n++;
24292 if( n>0 && zLine[n-1]=='\n' ){
24293 n--;
24294 if( n>0 && zLine[n-1]=='\r' ) n--;
24295 zLine[n] = 0;
24296 break;
24297 }
24298 }
24299 return zLine;
24300 }
24301
24302 /*
24303 ** Retrieve a single line of input text.
24304 **
24305 ** If in==0 then read from standard input and prompt before each line.
24306 ** If isContinuation is true, then a continuation prompt is appropriate.
24307 ** If isContinuation is zero, then the main prompt should be used.
24308 **
24309 ** If zPrior is not NULL then it is a buffer from a prior call to this
24310 ** routine that can be reused.
24311 **
24312 ** The result is stored in space obtained from malloc() and must either
24313 ** be freed by the caller or else passed back into this routine via the
24314 ** zPrior argument for reuse.
24315 */
24316 #ifndef SQLITE_SHELL_FIDDLE
24317 static char *one_input_line(ShellState *p, char *zPrior, int isContinuation){
24318 char *zPrompt;
24319 char *zResult;
24320 FILE *in = p->in;
24321 if( in!=0 ){
24322 zResult = local_getline(zPrior, in);
24323 }else{
24324 zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
24325 #if SHELL_USE_LOCAL_GETLINE
24326 sputz(stdout, zPrompt);
24327 fflush(stdout);
24328 do{
24329 zResult = local_getline(zPrior, stdin);
24330 zPrior = 0;
24331 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
24332 if( zResult==0 ) sqlite3_sleep(50);
24333 }while( zResult==0 && seenInterrupt>0 );
24334 #else
24335 free(zPrior);
24336 zResult = shell_readline(zPrompt);
24337 while( zResult==0 ){
24338 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
24339 sqlite3_sleep(50);
24340 if( seenInterrupt==0 ) break;
24341 zResult = shell_readline("");
24342 }
24343 if( zResult && *zResult ) shell_add_history(zResult);
24344 #endif
24345 }
24346 return zResult;
24347 }
24348 #endif /* !SQLITE_SHELL_FIDDLE */
24349
24350 /*
24351 ** Return the value of a hexadecimal digit. Return -1 if the input
24352 ** is not a hex digit.
24353 */
24354 static int hexDigitValue(char c){
24355 if( c>='0' && c<='9' ) return c - '0';
24356 if( c>='a' && c<='f' ) return c - 'a' + 10;
24357 if( c>='A' && c<='F' ) return c - 'A' + 10;
24358 return -1;
24359 }
24360
24361 /*
24362 ** Interpret zArg as an integer value, possibly with suffixes.
24363 **
24364 ** If the value specified by zArg is outside the range of values that
24365 ** can be represented using a 64-bit twos-complement integer, then return
24366 ** the nearest representable value.
24367 */
24368 static sqlite3_int64 integerValue(const char *zArg){
24369 sqlite3_uint64 v = 0;
24370 static const struct { char *zSuffix; unsigned int iMult; } aMult[] = {
24371 { "KiB", 1024 },
24372 { "MiB", 1024*1024 },
24373 { "GiB", 1024*1024*1024 },
24374 { "KB", 1000 },
24375 { "MB", 1000000 },
24376 { "GB", 1000000000 },
24377 { "K", 1000 },
24378 { "M", 1000000 },
24379 { "G", 1000000000 },
24380 };
24381 int i;
24382 int isNeg = 0;
24383 if( zArg[0]=='-' ){
24384 isNeg = 1;
24385 zArg++;
24386 }else if( zArg[0]=='+' ){
24387 zArg++;
24388 }
24389 if( zArg[0]=='0' && zArg[1]=='x' ){
24390 int x;
24391 zArg += 2;
24392 while( (x = hexDigitValue(zArg[0]))>=0 ){
24393 if( v > 0x0fffffffffffffffULL ) goto integer_overflow;
24394 v = (v<<4) + x;
24395 zArg++;
24396 }
24397 }else{
24398 while( IsDigit(zArg[0]) ){
24399 if( v>=922337203685477580LL ){
24400 if( v>922337203685477580LL || zArg[0]>='8' ) goto integer_overflow;
24401 }
24402 v = v*10 + (zArg[0] - '0');
24403 zArg++;
24404 }
24405 }
24406 for(i=0; i<ArraySize(aMult); i++){
24407 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
24408 if( 0x7fffffffffffffffULL/aMult[i].iMult < v ) goto integer_overflow;
24409 v *= aMult[i].iMult;
24410 break;
24411 }
24412 }
24413 if( isNeg && v>0x7fffffffffffffffULL ) goto integer_overflow;
24414 return isNeg? -(sqlite3_int64)v : (sqlite3_int64)v;
24415 integer_overflow:
24416 return isNeg ? (i64)0x8000000000000000LL : 0x7fffffffffffffffLL;
24417 }
24418
24419 /*
24420 ** A variable length string to which one can append text.
24421 */
24422 typedef struct ShellText ShellText;
24423 struct ShellText {
24424 char *zTxt; /* The text */
24425 i64 n; /* Number of bytes of zTxt[] actually used */
24426 i64 nAlloc; /* Number of bytes allocated for zTxt[] */
24427 };
24428
24429 /*
24430 ** Initialize and destroy a ShellText object
24431 */
24432 static void initText(ShellText *p){
24433 memset(p, 0, sizeof(*p));
24434 }
24435 static void freeText(ShellText *p){
24436 sqlite3_free(p->zTxt);
24437 initText(p);
24438 }
24439
24440 /* zIn is either a pointer to a NULL-terminated string in memory obtained
24441 ** from malloc(), or a NULL pointer. The string pointed to by zAppend is
24442 ** added to zIn, and the result returned in memory obtained from malloc().
24443 ** zIn, if it was not NULL, is freed.
24444 **
24445 ** If the third argument, quote, is not '\0', then it is used as a
24446 ** quote character for zAppend.
24447 */
24448 static void appendText(ShellText *p, const char *zAppend, char quote){
24449 i64 len;
24450 i64 i;
24451 i64 nAppend = strlen30(zAppend);
24452
24453 len = nAppend+p->n+1;
24454 if( quote ){
24455 len += 2;
24456 for(i=0; i<nAppend; i++){
24457 if( zAppend[i]==quote ) len++;
24458 }
24459 }
24460
24461 if( p->zTxt==0 || p->n+len>=p->nAlloc ){
24462 p->nAlloc = p->nAlloc*2 + len + 20;
24463 p->zTxt = sqlite3_realloc64(p->zTxt, p->nAlloc);
24464 shell_check_oom(p->zTxt);
24465 }
24466
24467 if( quote ){
24468 char *zCsr = p->zTxt+p->n;
24469 *zCsr++ = quote;
24470 for(i=0; i<nAppend; i++){
24471 *zCsr++ = zAppend[i];
24472 if( zAppend[i]==quote ) *zCsr++ = quote;
24473 }
24474 *zCsr++ = quote;
24475 p->n = (i64)(zCsr - p->zTxt);
24476 *zCsr = '\0';
24477 }else{
24478 memcpy(p->zTxt+p->n, zAppend, nAppend);
24479 p->n += nAppend;
24480 p->zTxt[p->n] = '\0';
24481 }
24482 }
24483
24484 /*
24485 ** Attempt to determine if identifier zName needs to be quoted, either
24486 ** because it contains non-alphanumeric characters, or because it is an
24487 ** SQLite keyword. Be conservative in this estimate: When in doubt assume
24488 ** that quoting is required.
24489 **
24490 ** Return '"' if quoting is required. Return 0 if no quoting is required.
24491 */
24492 static char quoteChar(const char *zName){
24493 int i;
24494 if( zName==0 ) return '"';
24495 if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"';
24496 for(i=0; zName[i]; i++){
24497 if( !IsAlnum(zName[i]) && zName[i]!='_' ) return '"';
24498 }
24499 return sqlite3_keyword_check(zName, i) ? '"' : 0;
24500 }
24501
24502 /*
24503 ** Construct a fake object name and column list to describe the structure
24504 ** of the view, virtual table, or table valued function zSchema.zName.
24505 **
24506 ** The returned string comes from sqlite3_mprintf() and should be freed
24507 ** by the caller using sqlite3_free().
24508 */
24509 static char *shellFakeSchema(
24510 sqlite3 *db, /* The database connection containing the vtab */
24511 const char *zSchema, /* Schema of the database holding the vtab */
24512 const char *zName /* The name of the virtual table */
24513 ){
24514 sqlite3_stmt *pStmt = 0;
24515 char *zSql;
24516 ShellText s;
24517 char cQuote;
24518 char *zDiv = "(";
24519 int nRow = 0;
24520
24521 zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
24522 zSchema ? zSchema : "main", zName);
24523 shell_check_oom(zSql);
24524 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
24525 sqlite3_free(zSql);
24526 initText(&s);
24527 if( zSchema ){
24528 cQuote = quoteChar(zSchema);
24529 if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
24530 appendText(&s, zSchema, cQuote);
24531 appendText(&s, ".", 0);
24532 }
24533 cQuote = quoteChar(zName);
24534 appendText(&s, zName, cQuote);
24535 while( sqlite3_step(pStmt)==SQLITE_ROW ){
24536 const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
24537 nRow++;
24538 appendText(&s, zDiv, 0);
24539 zDiv = ",";
24540 if( zCol==0 ) zCol = "";
24541 cQuote = quoteChar(zCol);
24542 appendText(&s, zCol, cQuote);
24543 }
24544 appendText(&s, ")", 0);
24545 sqlite3_finalize(pStmt);
24546 if( nRow==0 ){
24547 freeText(&s);
24548 s.zTxt = 0;
24549 }
24550 return s.zTxt;
24551 }
24552
24553 /*
24554 ** SQL function: strtod(X)
24555 **
24556 ** Use the C-library strtod() function to convert string X into a double.
24557 ** Used for comparing the accuracy of SQLite's internal text-to-float conversion
24558 ** routines against the C-library.
24559 */
24560 static void shellStrtod(
24561 sqlite3_context *pCtx,
24562 int nVal,
24563 sqlite3_value **apVal
24564 ){
24565 char *z = (char*)sqlite3_value_text(apVal[0]);
24566 UNUSED_PARAMETER(nVal);
24567 if( z==0 ) return;
24568 sqlite3_result_double(pCtx, strtod(z,0));
24569 }
24570
24571 /*
24572 ** SQL function: dtostr(X)
24573 **
24574 ** Use the C-library printf() function to convert real value X into a string.
24575 ** Used for comparing the accuracy of SQLite's internal float-to-text conversion
24576 ** routines against the C-library.
24577 */
24578 static void shellDtostr(
24579 sqlite3_context *pCtx,
24580 int nVal,
24581 sqlite3_value **apVal
24582 ){
24583 double r = sqlite3_value_double(apVal[0]);
24584 int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
24585 char z[400];
24586 if( n<1 ) n = 1;
24587 if( n>350 ) n = 350;
24588 sprintf(z, "%#+.*e", n, r);
24589 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
24590 }
24591
24592 /*
24593 ** SQL function: shell_add_schema(S,X)
24594 **
24595 ** Add the schema name X to the CREATE statement in S and return the result.
24596 ** Examples:
24597 **
24598 ** CREATE TABLE t1(x) -> CREATE TABLE xyz.t1(x);
24599 **
24600 ** Also works on
24601 **
24602 ** CREATE INDEX
24603 ** CREATE UNIQUE INDEX
24604 ** CREATE VIEW
24605 ** CREATE TRIGGER
24606 ** CREATE VIRTUAL TABLE
24607 **
24608 ** This UDF is used by the .schema command to insert the schema name of
24609 ** attached databases into the middle of the sqlite_schema.sql field.
24610 */
24611 static void shellAddSchemaName(
24612 sqlite3_context *pCtx,
24613 int nVal,
24614 sqlite3_value **apVal
24615 ){
24616 static const char *aPrefix[] = {
24617 "TABLE",
24618 "INDEX",
24619 "UNIQUE INDEX",
24620 "VIEW",
24621 "TRIGGER",
24622 "VIRTUAL TABLE"
24623 };
24624 int i = 0;
24625 const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
24626 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
24627 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
24628 sqlite3 *db = sqlite3_context_db_handle(pCtx);
24629 UNUSED_PARAMETER(nVal);
24630 if( zIn!=0 && cli_strncmp(zIn, "CREATE ", 7)==0 ){
24631 for(i=0; i<ArraySize(aPrefix); i++){
24632 int n = strlen30(aPrefix[i]);
24633 if( cli_strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
24634 char *z = 0;
24635 char *zFake = 0;
24636 if( zSchema ){
24637 char cQuote = quoteChar(zSchema);
24638 if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){
24639 z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
24640 }else{
24641 z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
24642 }
24643 }
24644 if( zName
24645 && aPrefix[i][0]=='V'
24646 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
24647 ){
24648 if( z==0 ){
24649 z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
24650 }else{
24651 z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
24652 }
24653 sqlite3_free(zFake);
24654 }
24655 if( z ){
24656 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
24657 return;
24658 }
24659 }
24660 }
24661 }
24662 sqlite3_result_value(pCtx, apVal[0]);
24663 }
24664
24665
24666 /************************* BEGIN PERFORMANCE TIMER *****************************/
24667 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
24668 #include <sys/time.h>
24669 #include <sys/resource.h>
@@ -33862,11 +33864,11 @@
33864 if( i==nArg-1 ){
33865 dotCmdError(p, i, "missing argument", 0);
33866 return 1;
33867 }
33868 i++;
33869 p->tmProgress = atof(azArg[i]);
33870 if( p->tmProgress>0.0 ){
33871 p->flgProgress = SHELL_PROGRESS_QUIET|SHELL_PROGRESS_TMOUT;
33872 if( nn==0 ) nn = 100;
33873 }
33874 continue;
@@ -35831,16 +35833,17 @@
35833 /*
35834 ** Alternate one_input_line() impl for wasm mode. This is not in the primary
35835 ** impl because we need the global shellState and cannot access it from that
35836 ** function without moving lots of code around (creating a larger/messier diff).
35837 */
35838 static char *one_input_line(ShellState *p, char *zPrior, int isContinuation){
35839 /* Parse the next line from shellState.wasm.zInput. */
35840 const char *zBegin = shellState.wasm.zPos;
35841 const char *z = zBegin;
35842 char *zLine = 0;
35843 i64 nZ = 0;
35844 FILE *in = p->in;
35845
35846 UNUSED_PARAMETER(in);
35847 UNUSED_PARAMETER(isContinuation);
35848 if(!z || !*z){
35849 return 0;
@@ -35894,11 +35897,11 @@
35897 saved_lineno = p->lineno;
35898 p->lineno = 0;
35899 CONTINUE_PROMPT_RESET;
35900 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
35901 fflush(p->out);
35902 zLine = one_input_line(p, zLine, nSql>0);
35903 if( zLine==0 ){
35904 /* End of input */
35905 if( p->in==0 && stdin_is_interactive ) cli_puts("\n", p->out);
35906 break;
35907 }
35908
+229 -144
--- 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
-** 276c350313a1ac2ebc70c1e8e50ed4baecd4 with changes in files:
21
+** c5af6a10245b6b847d30002806c1577b020c 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-23 13:00:56 276c350313a1ac2ebc70c1e8e50ed4baecd4be4d4c93ba04cf5e0078da18700e"
472
+#define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-03-23T13:00:56.709Z"
475
+#define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -3549,32 +3549,10 @@
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
-
35763554
/*
35773555
** CAPI3REF: Memory Allocation Subsystem
35783556
**
35793557
** The SQLite core uses these three routines for all of its own
35803558
** internal memory allocation needs. "Core" in the previous sentence
@@ -8698,17 +8676,10 @@
86988676
** that does no real locking and is appropriate for use in
86998677
** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
87008678
** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
87018679
** and Windows.
87028680
**
8703
-** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
8704
-** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
8705
-** implementation is included with the library. In this case the
8706
-** application must supply a custom mutex implementation using the
8707
-** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
8708
-** before calling sqlite3_initialize() or any other public sqlite3_
8709
-** function that calls sqlite3_initialize().
87108681
**
87118682
** ^The sqlite3_mutex_alloc() routine allocates a new
87128683
** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
87138684
** routine returns NULL if it is unable to allocate the requested
87148685
** mutex. The argument to sqlite3_mutex_alloc() must be one of these
@@ -9059,10 +9030,11 @@
90599030
#define SQLITE_TESTCTRL_SEEK_COUNT 30
90609031
#define SQLITE_TESTCTRL_TRACEFLAGS 31
90619032
#define SQLITE_TESTCTRL_TUNE 32
90629033
#define SQLITE_TESTCTRL_LOGEST 33
90639034
#define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
9035
+#define SQLITE_TESTCTRL_ATOF 34
90649036
#define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
90659037
90669038
/*
90679039
** CAPI3REF: SQL Keyword Checking
90689040
**
@@ -14698,10 +14670,14 @@
1469814670
#endif
1469914671
#if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
1470014672
# undef SQLITE_MAX_DEFAULT_PAGE_SIZE
1470114673
# define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
1470214674
#endif
14675
+#if SQLITE_MAX_DEFAULT_PAGE_SIZE<SQLITE_DEFAULT_PAGE_SIZE
14676
+# undef SQLITE_MAX_DEFAULT_PAGE_SIZE
14677
+# define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_DEFAULT_PAGE_SIZE
14678
+#endif
1470314679
1470414680
1470514681
/*
1470614682
** Maximum number of pages in one database file.
1470714683
**
@@ -23533,10 +23509,13 @@
2353323509
#ifdef SQLITE_STAT4_SAMPLES
2353423510
"STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES),
2353523511
#endif
2353623512
#ifdef SQLITE_STMTJRNL_SPILL
2353723513
"STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL),
23514
+#endif
23515
+#ifdef SQLITE_STRICT_SUBTYPE
23516
+ "STRICT_SUBTYPE",
2353823517
#endif
2353923518
#ifdef SQLITE_SUBSTR_COMPATIBILITY
2354023519
"SUBSTR_COMPATIBILITY",
2354123520
#endif
2354223521
#if (!defined(SQLITE_WIN32_MALLOC) \
@@ -32621,13 +32600,15 @@
3262132600
*(--bufpt) = cset[longvalue%base];
3262232601
longvalue = longvalue/base;
3262332602
}while( longvalue>0 );
3262432603
}
3262532604
length = (int)(&zOut[nOut-1]-bufpt);
32626
- while( precision>length ){
32627
- *(--bufpt) = '0'; /* Zero pad */
32628
- length++;
32605
+ if( precision>length ){ /* zero pad */
32606
+ int nn = precision-length;
32607
+ bufpt -= nn;
32608
+ memset(bufpt,'0',nn);
32609
+ length = precision;
3262932610
}
3263032611
if( cThousand ){
3263132612
int nn = (length - 1)/3; /* Number of "," to insert */
3263232613
int ix = (length - 1)%3 + 1;
3263332614
bufpt -= nn;
@@ -32760,30 +32741,58 @@
3276032741
if( prefix ){
3276132742
*(bufpt++) = prefix;
3276232743
}
3276332744
/* Digits prior to the decimal point */
3276432745
j = 0;
32746
+ assert( s.n>0 );
3276532747
if( e2<0 ){
3276632748
*(bufpt++) = '0';
32767
- }else{
32749
+ }else if( cThousand ){
3276832750
for(; e2>=0; e2--){
3276932751
*(bufpt++) = j<s.n ? s.z[j++] : '0';
32770
- if( cThousand && (e2%3)==0 && e2>1 ) *(bufpt++) = ',';
32752
+ if( (e2%3)==0 && e2>1 ) *(bufpt++) = ',';
32753
+ }
32754
+ }else{
32755
+ j = e2+1;
32756
+ if( j>s.n ) j = s.n;
32757
+ memcpy(bufpt, s.z, j);
32758
+ bufpt += j;
32759
+ e2 -= j;
32760
+ if( e2>=0 ){
32761
+ memset(bufpt, '0', e2+1);
32762
+ bufpt += e2+1;
32763
+ e2 = -1;
3277132764
}
3277232765
}
3277332766
/* The decimal point */
3277432767
if( flag_dp ){
3277532768
*(bufpt++) = '.';
3277632769
}
3277732770
/* "0" digits after the decimal point but before the first
3277832771
** significant digit of the number */
32779
- for(e2++; e2<0 && precision>0; precision--, e2++){
32780
- *(bufpt++) = '0';
32772
+ if( e2<(-1) && precision>0 ){
32773
+ int nn = -1-e2;
32774
+ if( nn>precision ) nn = precision;
32775
+ memset(bufpt, '0', nn);
32776
+ bufpt += nn;
32777
+ precision -= nn;
3278132778
}
3278232779
/* Significant digits after the decimal point */
32783
- while( (precision--)>0 ){
32784
- *(bufpt++) = j<s.n ? s.z[j++] : '0';
32780
+ if( precision>0 ){
32781
+ int nn = s.n - j;
32782
+ if( NEVER(nn>precision) ) nn = precision;
32783
+ if( nn>0 ){
32784
+ memcpy(bufpt, s.z+j, nn);
32785
+ bufpt += nn;
32786
+ j += nn;
32787
+ precision -= nn;
32788
+ }
32789
+ if( precision>0 && !flag_rtz ){
32790
+ memset(bufpt, '0', precision);
32791
+ bufpt += precision;
32792
+ precision = 0;
32793
+ }
3278532794
}
3278632795
/* Remove trailing zeros and the "." if no digits follow the "." */
3278732796
if( flag_rtz && flag_dp ){
3278832797
while( bufpt[-1]=='0' ) *(--bufpt) = 0;
3278932798
assert( bufpt>zOut );
@@ -36894,29 +36903,32 @@
3689436903
**
3689536904
** z[] must be UTF-8 and zero-terminated.
3689636905
**
3689736906
** Return positive if the result is a valid real number (or integer) and
3689836907
** 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:
36908
+** Lower bits of the return value contain addition information about the
36909
+** parse:
36910
+**
36911
+** bit 0 => Set for any valid input
36912
+** bit 1 => Input contains a decimal point or eNNN clause
36913
+** This bit is zero if the input is an integer
36914
+** bit 2 => The input is exactly 0.0, not an underflow from
36915
+** some value near zero
36916
+** bit 3 => More than 19 significant digits in the input
36917
+**
36918
+** If the input contains a syntax error but begins with text that might
36919
+** be a valid number of some kind, then the result is negative. The
36920
+** result is only zero if no prefix of the input could be interpreted as
36921
+** a number.
36922
+**
36923
+** Leading and trailing whitespace is ignored. Valid numbers are in
36924
+** one of the formats below:
3691036925
**
3691136926
** [+-]digits[E[+-]digits]
3691236927
** [+-]digits.[digits][E[+-]digits]
3691336928
** [+-].digits[E[+-]digits]
3691436929
**
36915
-** Leading and trailing whitespace is ignored for the purpose of determining
36916
-** validity.
36917
-**
3691836930
** Algorithm sketch: Compute an unsigned 64-bit integer s and a base-10
3691936931
** exponent d such that the value encoding by the input is s*pow(10,d).
3692036932
** Then invoke sqlite3Fp10Convert2() to calculated the closest possible
3692136933
** IEEE754 double. The sign is added back afterwards, if the input string
3692236934
** starts with a "-". The use of an unsigned 64-bit s mantissa means that
@@ -36933,24 +36945,24 @@
3693336945
#ifndef SQLITE_OMIT_FLOATING_POINT
3693436946
const unsigned char *z = (const unsigned char*)zIn;
3693536947
int neg = 0; /* True for a negative value */
3693636948
u64 s = 0; /* mantissa */
3693736949
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" */
36950
+ int mState = 0; /* 1: digit seen 2: fp 4: hard-zero */
3694036951
unsigned v; /* Value of a single digit */
3694136952
3694236953
start_of_text:
3694336954
if( (v = (unsigned)z[0] - '0')<10 ){
3694436955
parse_integer_part:
36945
- seenDigit = 1;
36956
+ mState = 1;
3694636957
s = v;
3694736958
z++;
3694836959
while( (v = (unsigned)z[0] - '0')<10 ){
3694936960
s = s*10 + v;
3695036961
z++;
36951
- if( s>=(LARGEST_INT64-9)/10 ){
36962
+ if( s>=(LARGEST_UINT64-9)/10 ){
36963
+ mState = 9;
3695236964
while( sqlite3Isdigit(z[0]) ){ z++; d++; }
3695336965
break;
3695436966
}
3695536967
}
3695636968
}else if( z[0]=='-' ){
@@ -36968,24 +36980,26 @@
3696836980
}
3696936981
3697036982
/* if decimal point is present */
3697136983
if( *z=='.' ){
3697236984
z++;
36973
- seenFP = 1;
3697436985
if( sqlite3Isdigit(z[0]) ){
36975
- seenDigit = 1;
36986
+ mState |= 1;
3697636987
do{
36977
- if( s<((LARGEST_INT64-9)/10) ){
36988
+ if( s<(LARGEST_UINT64-9)/10 ){
3697836989
s = s*10 + z[0] - '0';
3697936990
d--;
36991
+ }else{
36992
+ mState = 11;
3698036993
}
36981
- z++;
36982
- }while( sqlite3Isdigit(z[0]) );
36994
+ }while( sqlite3Isdigit(*++z) );
36995
+ }else if( mState==0 ){
36996
+ *pResult = 0.0;
36997
+ return 0;
3698336998
}
36984
- }
36985
-
36986
- if( !seenDigit ){
36999
+ mState |= 2;
37000
+ }else if( mState==0 ){
3698737001
*pResult = 0.0;
3698837002
return 0;
3698937003
}
3699037004
3699137005
/* if exponent is present */
@@ -37005,11 +37019,11 @@
3700537019
}
3700637020
/* copy digits to exponent */
3700737021
if( (v = (unsigned)z[0] - '0')<10 ){
3700837022
int exp = v;
3700937023
z++;
37010
- seenFP = 1;
37024
+ mState |= 2;
3701137025
while( (v = (unsigned)z[0] - '0')<10 ){
3701237026
exp = exp<10000 ? (exp*10 + v) : 10000;
3701337027
z++;
3701437028
}
3701537029
d += esign*exp;
@@ -37017,37 +37031,34 @@
3701737031
z--; /* Leave z[0] at 'e' or '+' or '-',
3701837032
** so that the return is 0 or -1 */
3701937033
}
3702037034
}
3702137035
37022
- /* skip trailing spaces */
37023
- while( sqlite3Isspace(*z) ) z++;
37024
-
3702537036
/* Convert s*pow(10,d) into real */
37026
- *pResult = s ? sqlite3Fp10Convert2(s,d) : 0.0;
37037
+ if( s==0 ){
37038
+ *pResult = 0.0;
37039
+ mState |= 4;
37040
+ }else{
37041
+ *pResult = sqlite3Fp10Convert2(s,d);
37042
+ }
3702737043
if( neg ) *pResult = -*pResult;
3702837044
assert( !sqlite3IsNaN(*pResult) );
3702937045
3703037046
/* return true if number and no extra non-whitespace characters after */
3703137047
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;
37048
+ return mState;
37049
+ }
37050
+ if( sqlite3Isspace(z[0]) ){
37051
+ do{ z++; }while( sqlite3Isspace(*z) );
37052
+ if( z[0]==0 ){
37053
+ return mState;
37054
+ }
37055
+ }
37056
+ return 0xfffffff0 | mState;
37057
+#else
37058
+ return sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8)==0;
37059
+#endif /* SQLITE_OMIT_FLOATING_POINT */
3704937060
}
3705037061
3705137062
/*
3705237063
** Digit pairs used to convert a U64 or I64 into text, two digits
3705337064
** at a time.
@@ -37160,12 +37171,12 @@
3716037171
*/
3716137172
SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
3716237173
int incr;
3716337174
u64 u = 0;
3716437175
int neg = 0; /* assume positive */
37165
- int i;
37166
- int c = 0;
37176
+ int i, j;
37177
+ unsigned int c = 0;
3716737178
int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
3716837179
int rc; /* Baseline return code */
3716937180
const char *zStart;
3717037181
const char *zEnd = zNum + length;
3717137182
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
@@ -37189,12 +37200,12 @@
3718937200
zNum+=incr;
3719037201
}
3719137202
}
3719237203
zStart = zNum;
3719337204
while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
37194
- for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
37195
- u = u*10 + c - '0';
37205
+ for(i=0; &zNum[i]<zEnd && (c=(unsigned)zNum[i]-'0')<=9; i+=incr){
37206
+ u = u*10 + c;
3719637207
}
3719737208
testcase( i==18*incr );
3719837209
testcase( i==19*incr );
3719937210
testcase( i==20*incr );
3720037211
if( u>LARGEST_INT64 ){
@@ -37227,18 +37238,18 @@
3722737238
/* Less than 19 digits, so we know that it fits in 64 bits */
3722837239
assert( u<=LARGEST_INT64 );
3722937240
return rc;
3723037241
}else{
3723137242
/* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
37232
- c = i>19*incr ? 1 : compare2pow63(zNum, incr);
37233
- if( c<0 ){
37243
+ j = i>19*incr ? 1 : compare2pow63(zNum, incr);
37244
+ if( j<0 ){
3723437245
/* zNum is less than 9223372036854775808 so it fits */
3723537246
assert( u<=LARGEST_INT64 );
3723637247
return rc;
3723737248
}else{
3723837249
*pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
37239
- if( c>0 ){
37250
+ if( j>0 ){
3724037251
/* zNum is greater than 9223372036854775808 so it overflows */
3724137252
return 2;
3724237253
}else{
3724337254
/* zNum is exactly 9223372036854775808. Fits if negative. The
3724437255
** special case 2 overflow if positive */
@@ -37480,11 +37491,11 @@
3748037491
}
3748137492
}else if( p->iDP>=n || (z[15]=='0' && z[14]=='0' && z[13]=='0') ){
3748237493
int jj, kk;
3748337494
u64 v2;
3748437495
assert( z[0]!='0' );
37485
- for(jj=14; z[jj-1]=='0'; jj--){}
37496
+ for(jj=13; z[jj-1]=='0'; jj--){}
3748637497
v2 = z[0] - '0';
3748737498
for(kk=1; kk<jj; kk++) v2 = (v2*10) + z[kk] - '0';
3748837499
if( r==sqlite3Fp10Convert2(v2, exp + n - jj) ){
3748937500
iRound = jj+1;
3749037501
}
@@ -85747,13 +85758,25 @@
8574785758
}
8574885759
}
8574985760
8575085761
/*
8575185762
** 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
85763
+** sqlite3MemRealValueRC() that has to deal with input strings
85764
+** that are not UTF8 or that are not zero-terminated. It is
85765
+** broken out into a separate no-inline routine so that the
85766
+** main sqlite3MemRealValueRC() routine can avoid unnecessary
8575485767
** stack pushes.
85768
+**
85769
+** A text->float translation of pMem->z is written into *pValue.
85770
+**
85771
+** Result code invariants:
85772
+**
85773
+** rc==0 => ERROR: Input string not well-formed, or OOM
85774
+** rc<0 => Some prefix of the input is well-formed
85775
+** rc>0 => All of the input is well-formed
85776
+** (rc&2)==0 => The number is expressed as an integer, with no
85777
+** decimal point or eNNN suffix.
8575585778
*/
8575685779
static SQLITE_NOINLINE int sqlite3MemRealValueRCSlowPath(
8575785780
Mem *pMem,
8575885781
double *pValue
8575985782
){
@@ -85795,16 +85818,23 @@
8579585818
return rc;
8579685819
}
8579785820
}
8579885821
8579985822
/*
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.
85823
+** Invoke sqlite3AtoF() on the text value of pMem. Write the
85824
+** translation of the text input into *pValue.
8580385825
**
8580485826
** The caller must ensure that pMem->db!=0 and that pMem is in
8580585827
** mode MEM_Str or MEM_Blob.
85828
+**
85829
+** Result code invariants:
85830
+**
85831
+** rc==0 => ERROR: Input string not well-formed, or OOM
85832
+** rc<0 => Some prefix of the input is well-formed
85833
+** rc>0 => All of the input is well-formed
85834
+** (rc&2)==0 => The number is expressed as an integer, with no
85835
+** decimal point or eNNN suffix.
8580685836
*/
8580785837
SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem *pMem, double *pValue){
8580885838
assert( pMem->db!=0 );
8580985839
assert( pMem->flags & (MEM_Str|MEM_Blob) );
8581085840
if( pMem->z==0 ){
@@ -85972,11 +86002,11 @@
8597286002
int rc;
8597386003
sqlite3_int64 ix;
8597486004
assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
8597586005
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
8597686006
rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
85977
- if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
86007
+ if( ((rc&2)==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<2)
8597886008
|| sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
8597986009
){
8598086010
pMem->u.i = ix;
8598186011
MemSetTypeFlag(pMem, MEM_Int);
8598286012
}else{
@@ -96413,11 +96443,11 @@
9641396443
double rValue;
9641496444
int rc;
9641596445
assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
9641696446
rc = sqlite3MemRealValueRC(pRec, &rValue);
9641796447
if( rc<=0 ) return;
96418
- if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
96448
+ if( (rc&2)==0 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
9641996449
pRec->flags |= MEM_Int;
9642096450
}else{
9642196451
pRec->u.r = rValue;
9642296452
pRec->flags |= MEM_Real;
9642396453
if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
@@ -96531,17 +96561,17 @@
9653196561
pMem->u.i = 0;
9653296562
return MEM_Int;
9653396563
}
9653496564
rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
9653596565
if( rc<=0 ){
96536
- if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
96566
+ if( (rc&2)==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
9653796567
pMem->u.i = ix;
9653896568
return MEM_Int;
9653996569
}else{
9654096570
return MEM_Real;
9654196571
}
96542
- }else if( rc==1 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
96572
+ }else if( (rc&2)==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
9654396573
pMem->u.i = ix;
9654496574
return MEM_Int;
9654596575
}
9654696576
return MEM_Real;
9654796577
}
@@ -110869,11 +110899,11 @@
110869110899
*/
110870110900
static int exprProbability(Expr *p){
110871110901
double r = -1.0;
110872110902
if( p->op!=TK_FLOAT ) return -1;
110873110903
assert( !ExprHasProperty(p, EP_IntValue) );
110874
- r = sqlite3_atof(p->u.zToken);
110904
+ sqlite3AtoF(p->u.zToken, &r);
110875110905
assert( r>=0.0 );
110876110906
if( r>1.0 ) return -1;
110877110907
return (int)(r*134217728.0);
110878110908
}
110879110909
@@ -116557,11 +116587,12 @@
116557116587
** z[n] character is guaranteed to be something that does not look
116558116588
** like the continuation of the number.
116559116589
*/
116560116590
static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
116561116591
if( ALWAYS(z!=0) ){
116562
- double value = sqlite3_atof(z);
116592
+ double value;
116593
+ sqlite3AtoF(z, &value);
116563116594
assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116564116595
if( negateFlag ) value = -value;
116565116596
sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
116566116597
}
116567116598
}
@@ -142213,12 +142244,10 @@
142213142244
/* Version 3.52.0 and later */
142214142245
void (*str_truncate)(sqlite3_str*,int);
142215142246
void (*str_free)(sqlite3_str*);
142216142247
int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142217142248
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*);
142220142249
};
142221142250
142222142251
/*
142223142252
** This is the function signature used for all extension entry points. It
142224142253
** is also defined in the file "loadext.c".
@@ -142558,12 +142587,10 @@
142558142587
/* Version 3.52.0 and later */
142559142588
#define sqlite3_str_truncate sqlite3_api->str_truncate
142560142589
#define sqlite3_str_free sqlite3_api->str_free
142561142590
#define sqlite3_carray_bind sqlite3_api->carray_bind
142562142591
#define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
142563
-/* Version 3.53.0 and later */
142564
-#define sqlite3_atof sqlite3_api->atof
142565142592
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142566142593
142567142594
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142568142595
/* This case when the file really is being compiled as a loadable
142569142596
** extension */
@@ -143092,16 +143119,15 @@
143092143119
/* Version 3.52.0 and later */
143093143120
sqlite3_str_truncate,
143094143121
sqlite3_str_free,
143095143122
#ifdef SQLITE_ENABLE_CARRAY
143096143123
sqlite3_carray_bind,
143097
- sqlite3_carray_bind_v2,
143124
+ sqlite3_carray_bind_v2
143098143125
#else
143099143126
0,
143100
- 0,
143127
+ 0
143101143128
#endif
143102
- sqlite3_atof
143103143129
};
143104143130
143105143131
/* True if x is the directory separator character
143106143132
*/
143107143133
#if SQLITE_OS_WIN
@@ -191439,10 +191465,21 @@
191439191465
*pI1 = rLogEst;
191440191466
*pU64 = sqlite3LogEstToInt(rLogEst);
191441191467
*pI2 = sqlite3LogEst(*pU64);
191442191468
break;
191443191469
}
191470
+
191471
+ /* sqlite3_test_control(SQLITE_TESTCTRL_ATOF, const char *z, double *p);
191472
+ **
191473
+ ** Test access to the sqlite3AtoF() routine.
191474
+ */
191475
+ case SQLITE_TESTCTRL_ATOF: {
191476
+ const char *z = va_arg(ap,const char*);
191477
+ double *pR = va_arg(ap,double*);
191478
+ rc = sqlite3AtoF(z,pR);
191479
+ break;
191480
+ }
191444191481
191445191482
#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD)
191446191483
/* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue)
191447191484
**
191448191485
** If "id" is an integer between 1 and SQLITE_NTUNE then set the value
@@ -212330,11 +212367,12 @@
212330212367
};
212331212368
212332212369
/* Allowed values for JsonString.eErr */
212333212370
#define JSTRING_OOM 0x01 /* Out of memory */
212334212371
#define JSTRING_MALFORMED 0x02 /* Malformed JSONB */
212335
-#define JSTRING_ERR 0x04 /* Error already sent to sqlite3_result */
212372
+#define JSTRING_TOODEEP 0x04 /* JSON nested too deep */
212373
+#define JSTRING_ERR 0x08 /* Error already sent to sqlite3_result */
212336212374
212337212375
/* The "subtype" set for text JSON values passed through using
212338212376
** sqlite3_result_subtype() and sqlite3_value_subtype().
212339212377
*/
212340212378
#define JSON_SUBTYPE 74 /* Ascii for "J" */
@@ -212420,11 +212458,11 @@
212420212458
/**************************************************************************
212421212459
** Forward references
212422212460
**************************************************************************/
212423212461
static void jsonReturnStringAsBlob(JsonString*);
212424212462
static int jsonArgIsJsonb(sqlite3_value *pJson, JsonParse *p);
212425
-static u32 jsonTranslateBlobToText(const JsonParse*,u32,JsonString*);
212463
+static u32 jsonTranslateBlobToText(JsonParse*,u32,JsonString*);
212426212464
static void jsonReturnParse(sqlite3_context*,JsonParse*);
212427212465
static JsonParse *jsonParseFuncArg(sqlite3_context*,sqlite3_value*,u32);
212428212466
static void jsonParseFree(JsonParse*);
212429212467
static u32 jsonbPayloadSize(const JsonParse*, u32, u32*);
212430212468
static u32 jsonUnescapeOneChar(const char*, u32, u32*);
@@ -212577,10 +212615,19 @@
212577212615
static void jsonStringOom(JsonString *p){
212578212616
p->eErr |= JSTRING_OOM;
212579212617
if( p->pCtx ) sqlite3_result_error_nomem(p->pCtx);
212580212618
jsonStringReset(p);
212581212619
}
212620
+
212621
+/* Report JSON nested too deep
212622
+*/
212623
+static void jsonStringTooDeep(JsonString *p){
212624
+ p->eErr |= JSTRING_TOODEEP;
212625
+ assert( p->pCtx!=0 );
212626
+ sqlite3_result_error(p->pCtx, "JSON nested too deep", -1);
212627
+ jsonStringReset(p);
212628
+}
212582212629
212583212630
/* Enlarge pJson->zBuf so that it can hold at least N more bytes.
212584212631
** Return zero on success. Return non-zero on an OOM error
212585212632
*/
212586212633
static int jsonStringGrow(JsonString *p, u32 N){
@@ -212894,10 +212941,12 @@
212894212941
sqlite3RCStrUnref,
212895212942
SQLITE_UTF8);
212896212943
}
212897212944
}else if( p->eErr & JSTRING_OOM ){
212898212945
sqlite3_result_error_nomem(p->pCtx);
212946
+ }else if( p->eErr & JSTRING_TOODEEP ){
212947
+ /* error already in p->pCtx */
212899212948
}else if( p->eErr & JSTRING_MALFORMED ){
212900212949
sqlite3_result_error(p->pCtx, "malformed JSON", -1);
212901212950
}
212902212951
jsonStringReset(p);
212903212952
}
@@ -214195,11 +214244,11 @@
214195214244
** in an error, or in incorrect JSON.
214196214245
**
214197214246
** The pOut->eErr JSTRING_OOM flag is set on a OOM.
214198214247
*/
214199214248
static u32 jsonTranslateBlobToText(
214200
- const JsonParse *pParse, /* the complete parse of the JSON */
214249
+ JsonParse *pParse, /* the complete parse of the JSON */
214201214250
u32 i, /* Start rendering at this index */
214202214251
JsonString *pOut /* Write JSON here */
214203214252
){
214204214253
u32 sz, n, j, iEnd;
214205214254
@@ -214377,14 +214426,18 @@
214377214426
}
214378214427
case JSONB_ARRAY: {
214379214428
jsonAppendChar(pOut, '[');
214380214429
j = i+n;
214381214430
iEnd = j+sz;
214431
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ){
214432
+ jsonStringTooDeep(pOut);
214433
+ }
214382214434
while( j<iEnd && pOut->eErr==0 ){
214383214435
j = jsonTranslateBlobToText(pParse, j, pOut);
214384214436
jsonAppendChar(pOut, ',');
214385214437
}
214438
+ pParse->iDepth--;
214386214439
if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
214387214440
if( sz>0 ) jsonStringTrimOneChar(pOut);
214388214441
jsonAppendChar(pOut, ']');
214389214442
break;
214390214443
}
@@ -214391,14 +214444,18 @@
214391214444
case JSONB_OBJECT: {
214392214445
int x = 0;
214393214446
jsonAppendChar(pOut, '{');
214394214447
j = i+n;
214395214448
iEnd = j+sz;
214449
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ){
214450
+ jsonStringTooDeep(pOut);
214451
+ }
214396214452
while( j<iEnd && pOut->eErr==0 ){
214397214453
j = jsonTranslateBlobToText(pParse, j, pOut);
214398214454
jsonAppendChar(pOut, (x++ & 1) ? ',' : ':');
214399214455
}
214456
+ pParse->iDepth--;
214400214457
if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
214401214458
if( sz>0 ) jsonStringTrimOneChar(pOut);
214402214459
jsonAppendChar(pOut, '}');
214403214460
break;
214404214461
}
@@ -214451,11 +214508,11 @@
214451214508
static u32 jsonTranslateBlobToPrettyText(
214452214509
JsonPretty *pPretty, /* Pretty-printing context */
214453214510
u32 i /* Start rendering at this index */
214454214511
){
214455214512
u32 sz, n, j, iEnd;
214456
- const JsonParse *pParse = pPretty->pParse;
214513
+ JsonParse *pParse = pPretty->pParse;
214457214514
JsonString *pOut = pPretty->pOut;
214458214515
n = jsonbPayloadSize(pParse, i, &sz);
214459214516
if( n==0 ){
214460214517
pOut->eErr |= JSTRING_MALFORMED;
214461214518
return pParse->nBlob+1;
@@ -214466,10 +214523,13 @@
214466214523
iEnd = j+sz;
214467214524
jsonAppendChar(pOut, '[');
214468214525
if( j<iEnd ){
214469214526
jsonAppendChar(pOut, '\n');
214470214527
pPretty->nIndent++;
214528
+ if( pPretty->nIndent >= JSON_MAX_DEPTH ){
214529
+ jsonStringTooDeep(pOut);
214530
+ }
214471214531
while( pOut->eErr==0 ){
214472214532
jsonPrettyIndent(pPretty);
214473214533
j = jsonTranslateBlobToPrettyText(pPretty, j);
214474214534
if( j>=iEnd ) break;
214475214535
jsonAppendRawNZ(pOut, ",\n", 2);
@@ -214487,10 +214547,14 @@
214487214547
iEnd = j+sz;
214488214548
jsonAppendChar(pOut, '{');
214489214549
if( j<iEnd ){
214490214550
jsonAppendChar(pOut, '\n');
214491214551
pPretty->nIndent++;
214552
+ if( pPretty->nIndent >= JSON_MAX_DEPTH ){
214553
+ jsonStringTooDeep(pOut);
214554
+ }
214555
+ pParse->iDepth = pPretty->nIndent;
214492214556
while( pOut->eErr==0 ){
214493214557
jsonPrettyIndent(pPretty);
214494214558
j = jsonTranslateBlobToText(pParse, j, pOut);
214495214559
if( j>iEnd ){
214496214560
pOut->eErr |= JSTRING_MALFORMED;
@@ -214888,11 +214952,12 @@
214888214952
** Error returns from jsonLookupStep()
214889214953
*/
214890214954
#define JSON_LOOKUP_ERROR 0xffffffff
214891214955
#define JSON_LOOKUP_NOTFOUND 0xfffffffe
214892214956
#define JSON_LOOKUP_NOTARRAY 0xfffffffd
214893
-#define JSON_LOOKUP_PATHERROR 0xfffffffc
214957
+#define JSON_LOOKUP_TOODEEP 0xfffffffc
214958
+#define JSON_LOOKUP_PATHERROR 0xfffffffb
214894214959
#define JSON_LOOKUP_ISERROR(x) ((x)>=JSON_LOOKUP_PATHERROR)
214895214960
214896214961
/* Forward declaration */
214897214962
static u32 jsonLookupStep(JsonParse*,u32,const char*,u32);
214898214963
@@ -214935,11 +215000,16 @@
214935215000
pIns->nBlob = 1;
214936215001
pIns->aBlob = (u8*)&emptyObject[zTail[0]=='.'];
214937215002
pIns->eEdit = pParse->eEdit;
214938215003
pIns->nIns = pParse->nIns;
214939215004
pIns->aIns = pParse->aIns;
215005
+ pIns->iDepth = pParse->iDepth+1;
215006
+ if( pIns->iDepth >= JSON_MAX_DEPTH ){
215007
+ return JSON_LOOKUP_TOODEEP;
215008
+ }
214940215009
rc = jsonLookupStep(pIns, 0, zTail, 0);
215010
+ pParse->iDepth--;
214941215011
pParse->oom |= pIns->oom;
214942215012
}
214943215013
return rc; /* Error code only */
214944215014
}
214945215015
@@ -215041,11 +215111,15 @@
215041215111
u32 v = k+sz; /* v is the index of the value */
215042215112
if( ((pParse->aBlob[v])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
215043215113
n = jsonbPayloadSize(pParse, v, &sz);
215044215114
if( n==0 || v+n+sz>iEnd ) return JSON_LOOKUP_ERROR;
215045215115
assert( j>0 );
215116
+ if( ++pParse->iDepth >= JSON_MAX_DEPTH ){
215117
+ return JSON_LOOKUP_TOODEEP;
215118
+ }
215046215119
rc = jsonLookupStep(pParse, v, &zPath[i], j);
215120
+ pParse->iDepth--;
215047215121
if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
215048215122
return rc;
215049215123
}
215050215124
j = k+sz;
215051215125
if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
@@ -215127,11 +215201,15 @@
215127215201
}
215128215202
j = iRoot+n;
215129215203
iEnd = j+sz;
215130215204
while( j<iEnd ){
215131215205
if( kk==0 ){
215206
+ if( ++pParse->iDepth >= JSON_MAX_DEPTH ){
215207
+ return JSON_LOOKUP_TOODEEP;
215208
+ }
215132215209
rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
215210
+ pParse->iDepth--;
215133215211
if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
215134215212
return rc;
215135215213
}
215136215214
kk--;
215137215215
n = jsonbPayloadSize(pParse, j, &sz);
@@ -215459,11 +215537,20 @@
215459215537
return 0;
215460215538
}
215461215539
}
215462215540
215463215541
/*
215464
-** Generate a bad path error.
215542
+** Generate a path error.
215543
+**
215544
+** The specifics of the error are determined by the rc argument.
215545
+**
215546
+** rc error
215547
+** ----------------- ----------------------
215548
+** JSON_LOOKUP_ARRAY "not an array"
215549
+** JSON_LOOKUP_TOODEEP "JSON nested too deep"
215550
+** JSON_LOOKUP_ERROR "malformed JSON"
215551
+** otherwise... "bad JSON path"
215465215552
**
215466215553
** If ctx is not NULL then push the error message into ctx and return NULL.
215467215554
** If ctx is NULL, then return the text of the error message.
215468215555
*/
215469215556
static char *jsonBadPathError(
@@ -215472,10 +215559,14 @@
215472215559
int rc /* Maybe JSON_LOOKUP_NOTARRAY */
215473215560
){
215474215561
char *zMsg;
215475215562
if( rc==(int)JSON_LOOKUP_NOTARRAY ){
215476215563
zMsg = sqlite3_mprintf("not an array element: %Q", zPath);
215564
+ }else if( rc==(int)JSON_LOOKUP_ERROR ){
215565
+ zMsg = sqlite3_mprintf("malformed JSON");
215566
+ }else if( rc==(int)JSON_LOOKUP_TOODEEP ){
215567
+ zMsg = sqlite3_mprintf("JSON path too deep");
215477215568
}else{
215478215569
zMsg = sqlite3_mprintf("bad JSON path: %Q", zPath);
215479215570
}
215480215571
if( ctx==0 ) return zMsg;
215481215572
if( zMsg ){
@@ -215534,10 +215625,11 @@
215534215625
}else{
215535215626
p->eEdit = eEdit;
215536215627
p->nIns = ax.nBlob;
215537215628
p->aIns = ax.aBlob;
215538215629
p->delta = 0;
215630
+ p->iDepth = 0;
215539215631
rc = jsonLookupStep(p, 0, zPath+1, 0);
215540215632
}
215541215633
jsonParseReset(&ax);
215542215634
if( rc==JSON_LOOKUP_NOTFOUND ) continue;
215543215635
if( JSON_LOOKUP_ISERROR(rc) ) goto jsonInsertIntoBlob_patherror;
@@ -215546,15 +215638,11 @@
215546215638
jsonParseFree(p);
215547215639
return;
215548215640
215549215641
jsonInsertIntoBlob_patherror:
215550215642
jsonParseFree(p);
215551
- if( rc==JSON_LOOKUP_ERROR ){
215552
- sqlite3_result_error(ctx, "malformed JSON", -1);
215553
- }else{
215554
- jsonBadPathError(ctx, zPath, rc);
215555
- }
215643
+ jsonBadPathError(ctx, zPath, rc);
215556215644
return;
215557215645
}
215558215646
215559215647
/*
215560215648
** If pArg is a blob that seems like a JSONB blob, then initialize
@@ -215990,14 +216078,12 @@
215990216078
}
215991216079
i = jsonLookupStep(p, 0, zPath[0]=='$' ? zPath+1 : "@", 0);
215992216080
if( JSON_LOOKUP_ISERROR(i) ){
215993216081
if( i==JSON_LOOKUP_NOTFOUND ){
215994216082
/* no-op */
215995
- }else if( i==JSON_LOOKUP_PATHERROR ){
215996
- jsonBadPathError(ctx, zPath, 0);
215997216083
}else{
215998
- sqlite3_result_error(ctx, "malformed JSON", -1);
216084
+ jsonBadPathError(ctx, zPath, i);
215999216085
}
216000216086
eErr = 1;
216001216087
i = 0;
216002216088
}
216003216089
}else{
@@ -216127,15 +216213,12 @@
216127216213
goto json_extract_error; /* Return NULL if not found */
216128216214
}else{
216129216215
jsonAppendSeparator(&jx);
216130216216
jsonAppendRawNZ(&jx, "null", 4);
216131216217
}
216132
- }else if( j==JSON_LOOKUP_ERROR ){
216133
- sqlite3_result_error(ctx, "malformed JSON", -1);
216134
- goto json_extract_error;
216135216218
}else{
216136
- jsonBadPathError(ctx, zPath, 0);
216219
+ jsonBadPathError(ctx, zPath, j);
216137216220
goto json_extract_error;
216138216221
}
216139216222
}
216140216223
if( argc>2 ){
216141216224
jsonAppendChar(&jx, ']');
@@ -216155,10 +216238,11 @@
216155216238
*/
216156216239
#define JSON_MERGE_OK 0 /* Success */
216157216240
#define JSON_MERGE_BADTARGET 1 /* Malformed TARGET blob */
216158216241
#define JSON_MERGE_BADPATCH 2 /* Malformed PATCH blob */
216159216242
#define JSON_MERGE_OOM 3 /* Out-of-memory condition */
216243
+#define JSON_MERGE_TOODEEP 4 /* Nested too deep */
216160216244
216161216245
/*
216162216246
** RFC-7396 MergePatch for two JSONB blobs.
216163216247
**
216164216248
** pTarget is the target. pPatch is the patch. The target is updated
@@ -216206,11 +216290,12 @@
216206216290
*/
216207216291
static int jsonMergePatch(
216208216292
JsonParse *pTarget, /* The JSON parser that contains the TARGET */
216209216293
u32 iTarget, /* Index of TARGET in pTarget->aBlob[] */
216210216294
const JsonParse *pPatch, /* The PATCH */
216211
- u32 iPatch /* Index of PATCH in pPatch->aBlob[] */
216295
+ u32 iPatch, /* Index of PATCH in pPatch->aBlob[] */
216296
+ u32 iDepth /* Nesting depth */
216212216297
){
216213216298
u8 x; /* Type of a single node */
216214216299
u32 n, sz=0; /* Return values from jsonbPayloadSize() */
216215216300
u32 iTCursor; /* Cursor position while scanning the target object */
216216216301
u32 iTStart; /* First label in the target object */
@@ -216315,11 +216400,12 @@
216315216400
if( NEVER(pTarget->oom) ) return JSON_MERGE_OOM;
216316216401
}else{
216317216402
/* Algorithm line 12 */
216318216403
int rc, savedDelta = pTarget->delta;
216319216404
pTarget->delta = 0;
216320
- rc = jsonMergePatch(pTarget, iTValue, pPatch, iPValue);
216405
+ if( iDepth>=JSON_MAX_DEPTH ) return JSON_MERGE_TOODEEP;
216406
+ rc = jsonMergePatch(pTarget, iTValue, pPatch, iPValue, iDepth+1);
216321216407
if( rc ) return rc;
216322216408
pTarget->delta += savedDelta;
216323216409
}
216324216410
}else if( x>0 ){ /* Algorithm line 13 */
216325216411
/* No match and patch value is not NULL */
@@ -216336,11 +216422,12 @@
216336216422
if( pTarget->oom ) return JSON_MERGE_OOM;
216337216423
memcpy(&pTarget->aBlob[iTEnd], &pPatch->aBlob[iPLabel], szNew);
216338216424
pTarget->aBlob[iTEnd+szNew] = 0x00;
216339216425
savedDelta = pTarget->delta;
216340216426
pTarget->delta = 0;
216341
- rc = jsonMergePatch(pTarget, iTEnd+szNew,pPatch,iPValue);
216427
+ if( iDepth>=JSON_MAX_DEPTH ) return JSON_MERGE_TOODEEP;
216428
+ rc = jsonMergePatch(pTarget, iTEnd+szNew,pPatch,iPValue,iDepth+1);
216342216429
if( rc ) return rc;
216343216430
pTarget->delta += savedDelta;
216344216431
}
216345216432
}
216346216433
}
@@ -216367,15 +216454,17 @@
216367216454
assert( argc==2 );
216368216455
pTarget = jsonParseFuncArg(ctx, argv[0], JSON_EDITABLE);
216369216456
if( pTarget==0 ) return;
216370216457
pPatch = jsonParseFuncArg(ctx, argv[1], 0);
216371216458
if( pPatch ){
216372
- rc = jsonMergePatch(pTarget, 0, pPatch, 0);
216459
+ rc = jsonMergePatch(pTarget, 0, pPatch, 0, 0);
216373216460
if( rc==JSON_MERGE_OK ){
216374216461
jsonReturnParse(ctx, pTarget);
216375216462
}else if( rc==JSON_MERGE_OOM ){
216376216463
sqlite3_result_error_nomem(ctx);
216464
+ }else if( rc==JSON_MERGE_TOODEEP ){
216465
+ sqlite3_result_error(ctx, "JSON nested too deep", -1);
216377216466
}else{
216378216467
sqlite3_result_error(ctx, "malformed JSON", -1);
216379216468
}
216380216469
jsonParseFree(pPatch);
216381216470
}
@@ -216459,14 +216548,12 @@
216459216548
p->delta = 0;
216460216549
rc = jsonLookupStep(p, 0, zPath+1, 0);
216461216550
if( JSON_LOOKUP_ISERROR(rc) ){
216462216551
if( rc==JSON_LOOKUP_NOTFOUND ){
216463216552
continue; /* No-op */
216464
- }else if( rc==JSON_LOOKUP_PATHERROR ){
216553
+ }else{
216465216554
jsonBadPathError(ctx, zPath, rc);
216466
- }else{
216467
- sqlite3_result_error(ctx, "malformed JSON", -1);
216468216555
}
216469216556
goto json_remove_done;
216470216557
}
216471216558
}
216472216559
jsonReturnParse(ctx, p);
@@ -216559,14 +216646,12 @@
216559216646
}
216560216647
i = jsonLookupStep(p, 0, zPath+1, 0);
216561216648
if( JSON_LOOKUP_ISERROR(i) ){
216562216649
if( i==JSON_LOOKUP_NOTFOUND ){
216563216650
/* no-op */
216564
- }else if( i==JSON_LOOKUP_PATHERROR ){
216565
- jsonBadPathError(ctx, zPath, 0);
216566216651
}else{
216567
- sqlite3_result_error(ctx, "malformed JSON", -1);
216652
+ jsonBadPathError(ctx, zPath, i);
216568216653
}
216569216654
goto json_type_done;
216570216655
}
216571216656
}else{
216572216657
i = 0;
@@ -262393,11 +262478,11 @@
262393262478
int nArg, /* Number of args */
262394262479
sqlite3_value **apUnused /* Function arguments */
262395262480
){
262396262481
assert( nArg==0 );
262397262482
UNUSED_PARAM2(nArg, apUnused);
262398
- sqlite3_result_text(pCtx, "fts5: 2026-03-23 12:25:52 1553a60506fa29b5f00535ae0f7aeb8cc94ebe84015386b3248fd8491108fc60", -1, SQLITE_TRANSIENT);
262483
+ sqlite3_result_text(pCtx, "fts5: 2026-03-26 14:19:34 97ee48b6ef65fb55633196282c9e75b3b0a3b81ba9755f63493a38e3f1a5610c", -1, SQLITE_TRANSIENT);
262399262484
}
262400262485
262401262486
/*
262402262487
** Implementation of fts5_locale(LOCALE, TEXT) function.
262403262488
**
262404262489
--- 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,32 +3549,10 @@
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
@@ -8698,17 +8676,10 @@
8698 ** that does no real locking and is appropriate for use in
8699 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
8700 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
8701 ** and Windows.
8702 **
8703 ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
8704 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
8705 ** implementation is included with the library. In this case the
8706 ** application must supply a custom mutex implementation using the
8707 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
8708 ** before calling sqlite3_initialize() or any other public sqlite3_
8709 ** function that calls sqlite3_initialize().
8710 **
8711 ** ^The sqlite3_mutex_alloc() routine allocates a new
8712 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8713 ** routine returns NULL if it is unable to allocate the requested
8714 ** mutex. The argument to sqlite3_mutex_alloc() must be one of these
@@ -9059,10 +9030,11 @@
9059 #define SQLITE_TESTCTRL_SEEK_COUNT 30
9060 #define SQLITE_TESTCTRL_TRACEFLAGS 31
9061 #define SQLITE_TESTCTRL_TUNE 32
9062 #define SQLITE_TESTCTRL_LOGEST 33
9063 #define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
 
9064 #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
9065
9066 /*
9067 ** CAPI3REF: SQL Keyword Checking
9068 **
@@ -14698,10 +14670,14 @@
14698 #endif
14699 #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
14700 # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
14701 # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
14702 #endif
 
 
 
 
14703
14704
14705 /*
14706 ** Maximum number of pages in one database file.
14707 **
@@ -23533,10 +23509,13 @@
23533 #ifdef SQLITE_STAT4_SAMPLES
23534 "STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES),
23535 #endif
23536 #ifdef SQLITE_STMTJRNL_SPILL
23537 "STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL),
 
 
 
23538 #endif
23539 #ifdef SQLITE_SUBSTR_COMPATIBILITY
23540 "SUBSTR_COMPATIBILITY",
23541 #endif
23542 #if (!defined(SQLITE_WIN32_MALLOC) \
@@ -32621,13 +32600,15 @@
32621 *(--bufpt) = cset[longvalue%base];
32622 longvalue = longvalue/base;
32623 }while( longvalue>0 );
32624 }
32625 length = (int)(&zOut[nOut-1]-bufpt);
32626 while( precision>length ){
32627 *(--bufpt) = '0'; /* Zero pad */
32628 length++;
 
 
32629 }
32630 if( cThousand ){
32631 int nn = (length - 1)/3; /* Number of "," to insert */
32632 int ix = (length - 1)%3 + 1;
32633 bufpt -= nn;
@@ -32760,30 +32741,58 @@
32760 if( prefix ){
32761 *(bufpt++) = prefix;
32762 }
32763 /* Digits prior to the decimal point */
32764 j = 0;
 
32765 if( e2<0 ){
32766 *(bufpt++) = '0';
32767 }else{
32768 for(; e2>=0; e2--){
32769 *(bufpt++) = j<s.n ? s.z[j++] : '0';
32770 if( cThousand && (e2%3)==0 && e2>1 ) *(bufpt++) = ',';
 
 
 
 
 
 
 
 
 
 
 
32771 }
32772 }
32773 /* The decimal point */
32774 if( flag_dp ){
32775 *(bufpt++) = '.';
32776 }
32777 /* "0" digits after the decimal point but before the first
32778 ** significant digit of the number */
32779 for(e2++; e2<0 && precision>0; precision--, e2++){
32780 *(bufpt++) = '0';
 
 
 
 
32781 }
32782 /* Significant digits after the decimal point */
32783 while( (precision--)>0 ){
32784 *(bufpt++) = j<s.n ? s.z[j++] : '0';
 
 
 
 
 
 
 
 
 
 
 
 
32785 }
32786 /* Remove trailing zeros and the "." if no digits follow the "." */
32787 if( flag_rtz && flag_dp ){
32788 while( bufpt[-1]=='0' ) *(--bufpt) = 0;
32789 assert( bufpt>zOut );
@@ -36894,29 +36903,32 @@
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]
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
@@ -36933,24 +36945,24 @@
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]=='-' ){
@@ -36968,24 +36980,26 @@
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 */
@@ -37005,11 +37019,11 @@
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;
@@ -37017,37 +37031,34 @@
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.
@@ -37160,12 +37171,12 @@
37160 */
37161 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
37162 int incr;
37163 u64 u = 0;
37164 int neg = 0; /* assume positive */
37165 int i;
37166 int c = 0;
37167 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
37168 int rc; /* Baseline return code */
37169 const char *zStart;
37170 const char *zEnd = zNum + length;
37171 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
@@ -37189,12 +37200,12 @@
37189 zNum+=incr;
37190 }
37191 }
37192 zStart = zNum;
37193 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
37194 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
37195 u = u*10 + c - '0';
37196 }
37197 testcase( i==18*incr );
37198 testcase( i==19*incr );
37199 testcase( i==20*incr );
37200 if( u>LARGEST_INT64 ){
@@ -37227,18 +37238,18 @@
37227 /* Less than 19 digits, so we know that it fits in 64 bits */
37228 assert( u<=LARGEST_INT64 );
37229 return rc;
37230 }else{
37231 /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
37232 c = i>19*incr ? 1 : compare2pow63(zNum, incr);
37233 if( c<0 ){
37234 /* zNum is less than 9223372036854775808 so it fits */
37235 assert( u<=LARGEST_INT64 );
37236 return rc;
37237 }else{
37238 *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
37239 if( c>0 ){
37240 /* zNum is greater than 9223372036854775808 so it overflows */
37241 return 2;
37242 }else{
37243 /* zNum is exactly 9223372036854775808. Fits if negative. The
37244 ** special case 2 overflow if positive */
@@ -37480,11 +37491,11 @@
37480 }
37481 }else if( p->iDP>=n || (z[15]=='0' && z[14]=='0' && z[13]=='0') ){
37482 int jj, kk;
37483 u64 v2;
37484 assert( z[0]!='0' );
37485 for(jj=14; z[jj-1]=='0'; jj--){}
37486 v2 = z[0] - '0';
37487 for(kk=1; kk<jj; kk++) v2 = (v2*10) + z[kk] - '0';
37488 if( r==sqlite3Fp10Convert2(v2, exp + n - jj) ){
37489 iRound = jj+1;
37490 }
@@ -85747,13 +85758,25 @@
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 ){
@@ -85795,16 +85818,23 @@
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 ){
@@ -85972,11 +86002,11 @@
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);
85982 }else{
@@ -96413,11 +96443,11 @@
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;
96422 pRec->flags |= MEM_Real;
96423 if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
@@ -96531,17 +96561,17 @@
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{
96540 return MEM_Real;
96541 }
96542 }else if( rc==1 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
96543 pMem->u.i = ix;
96544 return MEM_Int;
96545 }
96546 return MEM_Real;
96547 }
@@ -110869,11 +110899,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
@@ -116557,11 +116587,12 @@
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 }
@@ -142213,12 +142244,10 @@
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".
@@ -142558,12 +142587,10 @@
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 */
@@ -143092,16 +143119,15 @@
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
@@ -191439,10 +191465,21 @@
191439 *pI1 = rLogEst;
191440 *pU64 = sqlite3LogEstToInt(rLogEst);
191441 *pI2 = sqlite3LogEst(*pU64);
191442 break;
191443 }
 
 
 
 
 
 
 
 
 
 
 
191444
191445 #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD)
191446 /* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue)
191447 **
191448 ** If "id" is an integer between 1 and SQLITE_NTUNE then set the value
@@ -212330,11 +212367,12 @@
212330 };
212331
212332 /* Allowed values for JsonString.eErr */
212333 #define JSTRING_OOM 0x01 /* Out of memory */
212334 #define JSTRING_MALFORMED 0x02 /* Malformed JSONB */
212335 #define JSTRING_ERR 0x04 /* Error already sent to sqlite3_result */
 
212336
212337 /* The "subtype" set for text JSON values passed through using
212338 ** sqlite3_result_subtype() and sqlite3_value_subtype().
212339 */
212340 #define JSON_SUBTYPE 74 /* Ascii for "J" */
@@ -212420,11 +212458,11 @@
212420 /**************************************************************************
212421 ** Forward references
212422 **************************************************************************/
212423 static void jsonReturnStringAsBlob(JsonString*);
212424 static int jsonArgIsJsonb(sqlite3_value *pJson, JsonParse *p);
212425 static u32 jsonTranslateBlobToText(const JsonParse*,u32,JsonString*);
212426 static void jsonReturnParse(sqlite3_context*,JsonParse*);
212427 static JsonParse *jsonParseFuncArg(sqlite3_context*,sqlite3_value*,u32);
212428 static void jsonParseFree(JsonParse*);
212429 static u32 jsonbPayloadSize(const JsonParse*, u32, u32*);
212430 static u32 jsonUnescapeOneChar(const char*, u32, u32*);
@@ -212577,10 +212615,19 @@
212577 static void jsonStringOom(JsonString *p){
212578 p->eErr |= JSTRING_OOM;
212579 if( p->pCtx ) sqlite3_result_error_nomem(p->pCtx);
212580 jsonStringReset(p);
212581 }
 
 
 
 
 
 
 
 
 
212582
212583 /* Enlarge pJson->zBuf so that it can hold at least N more bytes.
212584 ** Return zero on success. Return non-zero on an OOM error
212585 */
212586 static int jsonStringGrow(JsonString *p, u32 N){
@@ -212894,10 +212941,12 @@
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);
212901 }
212902 jsonStringReset(p);
212903 }
@@ -214195,11 +214244,11 @@
214195 ** in an error, or in incorrect JSON.
214196 **
214197 ** The pOut->eErr JSTRING_OOM flag is set on a OOM.
214198 */
214199 static u32 jsonTranslateBlobToText(
214200 const JsonParse *pParse, /* the complete parse of the JSON */
214201 u32 i, /* Start rendering at this index */
214202 JsonString *pOut /* Write JSON here */
214203 ){
214204 u32 sz, n, j, iEnd;
214205
@@ -214377,14 +214426,18 @@
214377 }
214378 case JSONB_ARRAY: {
214379 jsonAppendChar(pOut, '[');
214380 j = i+n;
214381 iEnd = j+sz;
 
 
 
214382 while( j<iEnd && pOut->eErr==0 ){
214383 j = jsonTranslateBlobToText(pParse, j, pOut);
214384 jsonAppendChar(pOut, ',');
214385 }
 
214386 if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
214387 if( sz>0 ) jsonStringTrimOneChar(pOut);
214388 jsonAppendChar(pOut, ']');
214389 break;
214390 }
@@ -214391,14 +214444,18 @@
214391 case JSONB_OBJECT: {
214392 int x = 0;
214393 jsonAppendChar(pOut, '{');
214394 j = i+n;
214395 iEnd = j+sz;
 
 
 
214396 while( j<iEnd && pOut->eErr==0 ){
214397 j = jsonTranslateBlobToText(pParse, j, pOut);
214398 jsonAppendChar(pOut, (x++ & 1) ? ',' : ':');
214399 }
 
214400 if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
214401 if( sz>0 ) jsonStringTrimOneChar(pOut);
214402 jsonAppendChar(pOut, '}');
214403 break;
214404 }
@@ -214451,11 +214508,11 @@
214451 static u32 jsonTranslateBlobToPrettyText(
214452 JsonPretty *pPretty, /* Pretty-printing context */
214453 u32 i /* Start rendering at this index */
214454 ){
214455 u32 sz, n, j, iEnd;
214456 const JsonParse *pParse = pPretty->pParse;
214457 JsonString *pOut = pPretty->pOut;
214458 n = jsonbPayloadSize(pParse, i, &sz);
214459 if( n==0 ){
214460 pOut->eErr |= JSTRING_MALFORMED;
214461 return pParse->nBlob+1;
@@ -214466,10 +214523,13 @@
214466 iEnd = j+sz;
214467 jsonAppendChar(pOut, '[');
214468 if( j<iEnd ){
214469 jsonAppendChar(pOut, '\n');
214470 pPretty->nIndent++;
 
 
 
214471 while( pOut->eErr==0 ){
214472 jsonPrettyIndent(pPretty);
214473 j = jsonTranslateBlobToPrettyText(pPretty, j);
214474 if( j>=iEnd ) break;
214475 jsonAppendRawNZ(pOut, ",\n", 2);
@@ -214487,10 +214547,14 @@
214487 iEnd = j+sz;
214488 jsonAppendChar(pOut, '{');
214489 if( j<iEnd ){
214490 jsonAppendChar(pOut, '\n');
214491 pPretty->nIndent++;
 
 
 
 
214492 while( pOut->eErr==0 ){
214493 jsonPrettyIndent(pPretty);
214494 j = jsonTranslateBlobToText(pParse, j, pOut);
214495 if( j>iEnd ){
214496 pOut->eErr |= JSTRING_MALFORMED;
@@ -214888,11 +214952,12 @@
214888 ** Error returns from jsonLookupStep()
214889 */
214890 #define JSON_LOOKUP_ERROR 0xffffffff
214891 #define JSON_LOOKUP_NOTFOUND 0xfffffffe
214892 #define JSON_LOOKUP_NOTARRAY 0xfffffffd
214893 #define JSON_LOOKUP_PATHERROR 0xfffffffc
 
214894 #define JSON_LOOKUP_ISERROR(x) ((x)>=JSON_LOOKUP_PATHERROR)
214895
214896 /* Forward declaration */
214897 static u32 jsonLookupStep(JsonParse*,u32,const char*,u32);
214898
@@ -214935,11 +215000,16 @@
214935 pIns->nBlob = 1;
214936 pIns->aBlob = (u8*)&emptyObject[zTail[0]=='.'];
214937 pIns->eEdit = pParse->eEdit;
214938 pIns->nIns = pParse->nIns;
214939 pIns->aIns = pParse->aIns;
 
 
 
 
214940 rc = jsonLookupStep(pIns, 0, zTail, 0);
 
214941 pParse->oom |= pIns->oom;
214942 }
214943 return rc; /* Error code only */
214944 }
214945
@@ -215041,11 +215111,15 @@
215041 u32 v = k+sz; /* v is the index of the value */
215042 if( ((pParse->aBlob[v])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
215043 n = jsonbPayloadSize(pParse, v, &sz);
215044 if( n==0 || v+n+sz>iEnd ) return JSON_LOOKUP_ERROR;
215045 assert( j>0 );
 
 
 
215046 rc = jsonLookupStep(pParse, v, &zPath[i], j);
 
215047 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
215048 return rc;
215049 }
215050 j = k+sz;
215051 if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
@@ -215127,11 +215201,15 @@
215127 }
215128 j = iRoot+n;
215129 iEnd = j+sz;
215130 while( j<iEnd ){
215131 if( kk==0 ){
 
 
 
215132 rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
 
215133 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
215134 return rc;
215135 }
215136 kk--;
215137 n = jsonbPayloadSize(pParse, j, &sz);
@@ -215459,11 +215537,20 @@
215459 return 0;
215460 }
215461 }
215462
215463 /*
215464 ** Generate a bad path error.
 
 
 
 
 
 
 
 
 
215465 **
215466 ** If ctx is not NULL then push the error message into ctx and return NULL.
215467 ** If ctx is NULL, then return the text of the error message.
215468 */
215469 static char *jsonBadPathError(
@@ -215472,10 +215559,14 @@
215472 int rc /* Maybe JSON_LOOKUP_NOTARRAY */
215473 ){
215474 char *zMsg;
215475 if( rc==(int)JSON_LOOKUP_NOTARRAY ){
215476 zMsg = sqlite3_mprintf("not an array element: %Q", zPath);
 
 
 
 
215477 }else{
215478 zMsg = sqlite3_mprintf("bad JSON path: %Q", zPath);
215479 }
215480 if( ctx==0 ) return zMsg;
215481 if( zMsg ){
@@ -215534,10 +215625,11 @@
215534 }else{
215535 p->eEdit = eEdit;
215536 p->nIns = ax.nBlob;
215537 p->aIns = ax.aBlob;
215538 p->delta = 0;
 
215539 rc = jsonLookupStep(p, 0, zPath+1, 0);
215540 }
215541 jsonParseReset(&ax);
215542 if( rc==JSON_LOOKUP_NOTFOUND ) continue;
215543 if( JSON_LOOKUP_ISERROR(rc) ) goto jsonInsertIntoBlob_patherror;
@@ -215546,15 +215638,11 @@
215546 jsonParseFree(p);
215547 return;
215548
215549 jsonInsertIntoBlob_patherror:
215550 jsonParseFree(p);
215551 if( rc==JSON_LOOKUP_ERROR ){
215552 sqlite3_result_error(ctx, "malformed JSON", -1);
215553 }else{
215554 jsonBadPathError(ctx, zPath, rc);
215555 }
215556 return;
215557 }
215558
215559 /*
215560 ** If pArg is a blob that seems like a JSONB blob, then initialize
@@ -215990,14 +216078,12 @@
215990 }
215991 i = jsonLookupStep(p, 0, zPath[0]=='$' ? zPath+1 : "@", 0);
215992 if( JSON_LOOKUP_ISERROR(i) ){
215993 if( i==JSON_LOOKUP_NOTFOUND ){
215994 /* no-op */
215995 }else if( i==JSON_LOOKUP_PATHERROR ){
215996 jsonBadPathError(ctx, zPath, 0);
215997 }else{
215998 sqlite3_result_error(ctx, "malformed JSON", -1);
215999 }
216000 eErr = 1;
216001 i = 0;
216002 }
216003 }else{
@@ -216127,15 +216213,12 @@
216127 goto json_extract_error; /* Return NULL if not found */
216128 }else{
216129 jsonAppendSeparator(&jx);
216130 jsonAppendRawNZ(&jx, "null", 4);
216131 }
216132 }else if( j==JSON_LOOKUP_ERROR ){
216133 sqlite3_result_error(ctx, "malformed JSON", -1);
216134 goto json_extract_error;
216135 }else{
216136 jsonBadPathError(ctx, zPath, 0);
216137 goto json_extract_error;
216138 }
216139 }
216140 if( argc>2 ){
216141 jsonAppendChar(&jx, ']');
@@ -216155,10 +216238,11 @@
216155 */
216156 #define JSON_MERGE_OK 0 /* Success */
216157 #define JSON_MERGE_BADTARGET 1 /* Malformed TARGET blob */
216158 #define JSON_MERGE_BADPATCH 2 /* Malformed PATCH blob */
216159 #define JSON_MERGE_OOM 3 /* Out-of-memory condition */
 
216160
216161 /*
216162 ** RFC-7396 MergePatch for two JSONB blobs.
216163 **
216164 ** pTarget is the target. pPatch is the patch. The target is updated
@@ -216206,11 +216290,12 @@
216206 */
216207 static int jsonMergePatch(
216208 JsonParse *pTarget, /* The JSON parser that contains the TARGET */
216209 u32 iTarget, /* Index of TARGET in pTarget->aBlob[] */
216210 const JsonParse *pPatch, /* The PATCH */
216211 u32 iPatch /* Index of PATCH in pPatch->aBlob[] */
 
216212 ){
216213 u8 x; /* Type of a single node */
216214 u32 n, sz=0; /* Return values from jsonbPayloadSize() */
216215 u32 iTCursor; /* Cursor position while scanning the target object */
216216 u32 iTStart; /* First label in the target object */
@@ -216315,11 +216400,12 @@
216315 if( NEVER(pTarget->oom) ) return JSON_MERGE_OOM;
216316 }else{
216317 /* Algorithm line 12 */
216318 int rc, savedDelta = pTarget->delta;
216319 pTarget->delta = 0;
216320 rc = jsonMergePatch(pTarget, iTValue, pPatch, iPValue);
 
216321 if( rc ) return rc;
216322 pTarget->delta += savedDelta;
216323 }
216324 }else if( x>0 ){ /* Algorithm line 13 */
216325 /* No match and patch value is not NULL */
@@ -216336,11 +216422,12 @@
216336 if( pTarget->oom ) return JSON_MERGE_OOM;
216337 memcpy(&pTarget->aBlob[iTEnd], &pPatch->aBlob[iPLabel], szNew);
216338 pTarget->aBlob[iTEnd+szNew] = 0x00;
216339 savedDelta = pTarget->delta;
216340 pTarget->delta = 0;
216341 rc = jsonMergePatch(pTarget, iTEnd+szNew,pPatch,iPValue);
 
216342 if( rc ) return rc;
216343 pTarget->delta += savedDelta;
216344 }
216345 }
216346 }
@@ -216367,15 +216454,17 @@
216367 assert( argc==2 );
216368 pTarget = jsonParseFuncArg(ctx, argv[0], JSON_EDITABLE);
216369 if( pTarget==0 ) return;
216370 pPatch = jsonParseFuncArg(ctx, argv[1], 0);
216371 if( pPatch ){
216372 rc = jsonMergePatch(pTarget, 0, pPatch, 0);
216373 if( rc==JSON_MERGE_OK ){
216374 jsonReturnParse(ctx, pTarget);
216375 }else if( rc==JSON_MERGE_OOM ){
216376 sqlite3_result_error_nomem(ctx);
 
 
216377 }else{
216378 sqlite3_result_error(ctx, "malformed JSON", -1);
216379 }
216380 jsonParseFree(pPatch);
216381 }
@@ -216459,14 +216548,12 @@
216459 p->delta = 0;
216460 rc = jsonLookupStep(p, 0, zPath+1, 0);
216461 if( JSON_LOOKUP_ISERROR(rc) ){
216462 if( rc==JSON_LOOKUP_NOTFOUND ){
216463 continue; /* No-op */
216464 }else if( rc==JSON_LOOKUP_PATHERROR ){
216465 jsonBadPathError(ctx, zPath, rc);
216466 }else{
216467 sqlite3_result_error(ctx, "malformed JSON", -1);
216468 }
216469 goto json_remove_done;
216470 }
216471 }
216472 jsonReturnParse(ctx, p);
@@ -216559,14 +216646,12 @@
216559 }
216560 i = jsonLookupStep(p, 0, zPath+1, 0);
216561 if( JSON_LOOKUP_ISERROR(i) ){
216562 if( i==JSON_LOOKUP_NOTFOUND ){
216563 /* no-op */
216564 }else if( i==JSON_LOOKUP_PATHERROR ){
216565 jsonBadPathError(ctx, zPath, 0);
216566 }else{
216567 sqlite3_result_error(ctx, "malformed JSON", -1);
216568 }
216569 goto json_type_done;
216570 }
216571 }else{
216572 i = 0;
@@ -262393,11 +262478,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
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** c5af6a10245b6b847d30002806c1577b020c with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.53.0"
471 #define SQLITE_VERSION_NUMBER 3053000
472 #define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -3549,32 +3549,10 @@
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
@@ -8698,17 +8676,10 @@
8676 ** that does no real locking and is appropriate for use in
8677 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
8678 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
8679 ** and Windows.
8680 **
 
 
 
 
 
 
 
8681 **
8682 ** ^The sqlite3_mutex_alloc() routine allocates a new
8683 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8684 ** routine returns NULL if it is unable to allocate the requested
8685 ** mutex. The argument to sqlite3_mutex_alloc() must be one of these
@@ -9059,10 +9030,11 @@
9030 #define SQLITE_TESTCTRL_SEEK_COUNT 30
9031 #define SQLITE_TESTCTRL_TRACEFLAGS 31
9032 #define SQLITE_TESTCTRL_TUNE 32
9033 #define SQLITE_TESTCTRL_LOGEST 33
9034 #define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
9035 #define SQLITE_TESTCTRL_ATOF 34
9036 #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
9037
9038 /*
9039 ** CAPI3REF: SQL Keyword Checking
9040 **
@@ -14698,10 +14670,14 @@
14670 #endif
14671 #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
14672 # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
14673 # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
14674 #endif
14675 #if SQLITE_MAX_DEFAULT_PAGE_SIZE<SQLITE_DEFAULT_PAGE_SIZE
14676 # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
14677 # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_DEFAULT_PAGE_SIZE
14678 #endif
14679
14680
14681 /*
14682 ** Maximum number of pages in one database file.
14683 **
@@ -23533,10 +23509,13 @@
23509 #ifdef SQLITE_STAT4_SAMPLES
23510 "STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES),
23511 #endif
23512 #ifdef SQLITE_STMTJRNL_SPILL
23513 "STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL),
23514 #endif
23515 #ifdef SQLITE_STRICT_SUBTYPE
23516 "STRICT_SUBTYPE",
23517 #endif
23518 #ifdef SQLITE_SUBSTR_COMPATIBILITY
23519 "SUBSTR_COMPATIBILITY",
23520 #endif
23521 #if (!defined(SQLITE_WIN32_MALLOC) \
@@ -32621,13 +32600,15 @@
32600 *(--bufpt) = cset[longvalue%base];
32601 longvalue = longvalue/base;
32602 }while( longvalue>0 );
32603 }
32604 length = (int)(&zOut[nOut-1]-bufpt);
32605 if( precision>length ){ /* zero pad */
32606 int nn = precision-length;
32607 bufpt -= nn;
32608 memset(bufpt,'0',nn);
32609 length = precision;
32610 }
32611 if( cThousand ){
32612 int nn = (length - 1)/3; /* Number of "," to insert */
32613 int ix = (length - 1)%3 + 1;
32614 bufpt -= nn;
@@ -32760,30 +32741,58 @@
32741 if( prefix ){
32742 *(bufpt++) = prefix;
32743 }
32744 /* Digits prior to the decimal point */
32745 j = 0;
32746 assert( s.n>0 );
32747 if( e2<0 ){
32748 *(bufpt++) = '0';
32749 }else if( cThousand ){
32750 for(; e2>=0; e2--){
32751 *(bufpt++) = j<s.n ? s.z[j++] : '0';
32752 if( (e2%3)==0 && e2>1 ) *(bufpt++) = ',';
32753 }
32754 }else{
32755 j = e2+1;
32756 if( j>s.n ) j = s.n;
32757 memcpy(bufpt, s.z, j);
32758 bufpt += j;
32759 e2 -= j;
32760 if( e2>=0 ){
32761 memset(bufpt, '0', e2+1);
32762 bufpt += e2+1;
32763 e2 = -1;
32764 }
32765 }
32766 /* The decimal point */
32767 if( flag_dp ){
32768 *(bufpt++) = '.';
32769 }
32770 /* "0" digits after the decimal point but before the first
32771 ** significant digit of the number */
32772 if( e2<(-1) && precision>0 ){
32773 int nn = -1-e2;
32774 if( nn>precision ) nn = precision;
32775 memset(bufpt, '0', nn);
32776 bufpt += nn;
32777 precision -= nn;
32778 }
32779 /* Significant digits after the decimal point */
32780 if( precision>0 ){
32781 int nn = s.n - j;
32782 if( NEVER(nn>precision) ) nn = precision;
32783 if( nn>0 ){
32784 memcpy(bufpt, s.z+j, nn);
32785 bufpt += nn;
32786 j += nn;
32787 precision -= nn;
32788 }
32789 if( precision>0 && !flag_rtz ){
32790 memset(bufpt, '0', precision);
32791 bufpt += precision;
32792 precision = 0;
32793 }
32794 }
32795 /* Remove trailing zeros and the "." if no digits follow the "." */
32796 if( flag_rtz && flag_dp ){
32797 while( bufpt[-1]=='0' ) *(--bufpt) = 0;
32798 assert( bufpt>zOut );
@@ -36894,29 +36903,32 @@
36903 **
36904 ** z[] must be UTF-8 and zero-terminated.
36905 **
36906 ** Return positive if the result is a valid real number (or integer) and
36907 ** zero or negative if the string is empty or contains extraneous text.
36908 ** Lower bits of the return value contain addition information about the
36909 ** parse:
36910 **
36911 ** bit 0 => Set for any valid input
36912 ** bit 1 => Input contains a decimal point or eNNN clause
36913 ** This bit is zero if the input is an integer
36914 ** bit 2 => The input is exactly 0.0, not an underflow from
36915 ** some value near zero
36916 ** bit 3 => More than 19 significant digits in the input
36917 **
36918 ** If the input contains a syntax error but begins with text that might
36919 ** be a valid number of some kind, then the result is negative. The
36920 ** result is only zero if no prefix of the input could be interpreted as
36921 ** a number.
36922 **
36923 ** Leading and trailing whitespace is ignored. Valid numbers are in
36924 ** one of the formats below:
36925 **
36926 ** [+-]digits[E[+-]digits]
36927 ** [+-]digits.[digits][E[+-]digits]
36928 ** [+-].digits[E[+-]digits]
36929 **
 
 
 
36930 ** Algorithm sketch: Compute an unsigned 64-bit integer s and a base-10
36931 ** exponent d such that the value encoding by the input is s*pow(10,d).
36932 ** Then invoke sqlite3Fp10Convert2() to calculated the closest possible
36933 ** IEEE754 double. The sign is added back afterwards, if the input string
36934 ** starts with a "-". The use of an unsigned 64-bit s mantissa means that
@@ -36933,24 +36945,24 @@
36945 #ifndef SQLITE_OMIT_FLOATING_POINT
36946 const unsigned char *z = (const unsigned char*)zIn;
36947 int neg = 0; /* True for a negative value */
36948 u64 s = 0; /* mantissa */
36949 int d = 0; /* Value is s * pow(10,d) */
36950 int mState = 0; /* 1: digit seen 2: fp 4: hard-zero */
 
36951 unsigned v; /* Value of a single digit */
36952
36953 start_of_text:
36954 if( (v = (unsigned)z[0] - '0')<10 ){
36955 parse_integer_part:
36956 mState = 1;
36957 s = v;
36958 z++;
36959 while( (v = (unsigned)z[0] - '0')<10 ){
36960 s = s*10 + v;
36961 z++;
36962 if( s>=(LARGEST_UINT64-9)/10 ){
36963 mState = 9;
36964 while( sqlite3Isdigit(z[0]) ){ z++; d++; }
36965 break;
36966 }
36967 }
36968 }else if( z[0]=='-' ){
@@ -36968,24 +36980,26 @@
36980 }
36981
36982 /* if decimal point is present */
36983 if( *z=='.' ){
36984 z++;
 
36985 if( sqlite3Isdigit(z[0]) ){
36986 mState |= 1;
36987 do{
36988 if( s<(LARGEST_UINT64-9)/10 ){
36989 s = s*10 + z[0] - '0';
36990 d--;
36991 }else{
36992 mState = 11;
36993 }
36994 }while( sqlite3Isdigit(*++z) );
36995 }else if( mState==0 ){
36996 *pResult = 0.0;
36997 return 0;
36998 }
36999 mState |= 2;
37000 }else if( mState==0 ){
 
37001 *pResult = 0.0;
37002 return 0;
37003 }
37004
37005 /* if exponent is present */
@@ -37005,11 +37019,11 @@
37019 }
37020 /* copy digits to exponent */
37021 if( (v = (unsigned)z[0] - '0')<10 ){
37022 int exp = v;
37023 z++;
37024 mState |= 2;
37025 while( (v = (unsigned)z[0] - '0')<10 ){
37026 exp = exp<10000 ? (exp*10 + v) : 10000;
37027 z++;
37028 }
37029 d += esign*exp;
@@ -37017,37 +37031,34 @@
37031 z--; /* Leave z[0] at 'e' or '+' or '-',
37032 ** so that the return is 0 or -1 */
37033 }
37034 }
37035
 
 
 
37036 /* Convert s*pow(10,d) into real */
37037 if( s==0 ){
37038 *pResult = 0.0;
37039 mState |= 4;
37040 }else{
37041 *pResult = sqlite3Fp10Convert2(s,d);
37042 }
37043 if( neg ) *pResult = -*pResult;
37044 assert( !sqlite3IsNaN(*pResult) );
37045
37046 /* return true if number and no extra non-whitespace characters after */
37047 if( z[0]==0 ){
37048 return mState;
37049 }
37050 if( sqlite3Isspace(z[0]) ){
37051 do{ z++; }while( sqlite3Isspace(*z) );
37052 if( z[0]==0 ){
37053 return mState;
37054 }
37055 }
37056 return 0xfffffff0 | mState;
37057 #else
37058 return sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8)==0;
37059 #endif /* SQLITE_OMIT_FLOATING_POINT */
 
 
 
 
 
37060 }
37061
37062 /*
37063 ** Digit pairs used to convert a U64 or I64 into text, two digits
37064 ** at a time.
@@ -37160,12 +37171,12 @@
37171 */
37172 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
37173 int incr;
37174 u64 u = 0;
37175 int neg = 0; /* assume positive */
37176 int i, j;
37177 unsigned int c = 0;
37178 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
37179 int rc; /* Baseline return code */
37180 const char *zStart;
37181 const char *zEnd = zNum + length;
37182 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
@@ -37189,12 +37200,12 @@
37200 zNum+=incr;
37201 }
37202 }
37203 zStart = zNum;
37204 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
37205 for(i=0; &zNum[i]<zEnd && (c=(unsigned)zNum[i]-'0')<=9; i+=incr){
37206 u = u*10 + c;
37207 }
37208 testcase( i==18*incr );
37209 testcase( i==19*incr );
37210 testcase( i==20*incr );
37211 if( u>LARGEST_INT64 ){
@@ -37227,18 +37238,18 @@
37238 /* Less than 19 digits, so we know that it fits in 64 bits */
37239 assert( u<=LARGEST_INT64 );
37240 return rc;
37241 }else{
37242 /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
37243 j = i>19*incr ? 1 : compare2pow63(zNum, incr);
37244 if( j<0 ){
37245 /* zNum is less than 9223372036854775808 so it fits */
37246 assert( u<=LARGEST_INT64 );
37247 return rc;
37248 }else{
37249 *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
37250 if( j>0 ){
37251 /* zNum is greater than 9223372036854775808 so it overflows */
37252 return 2;
37253 }else{
37254 /* zNum is exactly 9223372036854775808. Fits if negative. The
37255 ** special case 2 overflow if positive */
@@ -37480,11 +37491,11 @@
37491 }
37492 }else if( p->iDP>=n || (z[15]=='0' && z[14]=='0' && z[13]=='0') ){
37493 int jj, kk;
37494 u64 v2;
37495 assert( z[0]!='0' );
37496 for(jj=13; z[jj-1]=='0'; jj--){}
37497 v2 = z[0] - '0';
37498 for(kk=1; kk<jj; kk++) v2 = (v2*10) + z[kk] - '0';
37499 if( r==sqlite3Fp10Convert2(v2, exp + n - jj) ){
37500 iRound = jj+1;
37501 }
@@ -85747,13 +85758,25 @@
85758 }
85759 }
85760
85761 /*
85762 ** This routine implements the uncommon and slower path for
85763 ** sqlite3MemRealValueRC() that has to deal with input strings
85764 ** that are not UTF8 or that are not zero-terminated. It is
85765 ** broken out into a separate no-inline routine so that the
85766 ** main sqlite3MemRealValueRC() routine can avoid unnecessary
85767 ** stack pushes.
85768 **
85769 ** A text->float translation of pMem->z is written into *pValue.
85770 **
85771 ** Result code invariants:
85772 **
85773 ** rc==0 => ERROR: Input string not well-formed, or OOM
85774 ** rc<0 => Some prefix of the input is well-formed
85775 ** rc>0 => All of the input is well-formed
85776 ** (rc&2)==0 => The number is expressed as an integer, with no
85777 ** decimal point or eNNN suffix.
85778 */
85779 static SQLITE_NOINLINE int sqlite3MemRealValueRCSlowPath(
85780 Mem *pMem,
85781 double *pValue
85782 ){
@@ -85795,16 +85818,23 @@
85818 return rc;
85819 }
85820 }
85821
85822 /*
85823 ** Invoke sqlite3AtoF() on the text value of pMem. Write the
85824 ** translation of the text input into *pValue.
 
85825 **
85826 ** The caller must ensure that pMem->db!=0 and that pMem is in
85827 ** mode MEM_Str or MEM_Blob.
85828 **
85829 ** Result code invariants:
85830 **
85831 ** rc==0 => ERROR: Input string not well-formed, or OOM
85832 ** rc<0 => Some prefix of the input is well-formed
85833 ** rc>0 => All of the input is well-formed
85834 ** (rc&2)==0 => The number is expressed as an integer, with no
85835 ** decimal point or eNNN suffix.
85836 */
85837 SQLITE_PRIVATE int sqlite3MemRealValueRC(Mem *pMem, double *pValue){
85838 assert( pMem->db!=0 );
85839 assert( pMem->flags & (MEM_Str|MEM_Blob) );
85840 if( pMem->z==0 ){
@@ -85972,11 +86002,11 @@
86002 int rc;
86003 sqlite3_int64 ix;
86004 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
86005 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
86006 rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
86007 if( ((rc&2)==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<2)
86008 || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
86009 ){
86010 pMem->u.i = ix;
86011 MemSetTypeFlag(pMem, MEM_Int);
86012 }else{
@@ -96413,11 +96443,11 @@
96443 double rValue;
96444 int rc;
96445 assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str );
96446 rc = sqlite3MemRealValueRC(pRec, &rValue);
96447 if( rc<=0 ) return;
96448 if( (rc&2)==0 && alsoAnInt(pRec, rValue, &pRec->u.i) ){
96449 pRec->flags |= MEM_Int;
96450 }else{
96451 pRec->u.r = rValue;
96452 pRec->flags |= MEM_Real;
96453 if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
@@ -96531,17 +96561,17 @@
96561 pMem->u.i = 0;
96562 return MEM_Int;
96563 }
96564 rc = sqlite3MemRealValueRC(pMem, &pMem->u.r);
96565 if( rc<=0 ){
96566 if( (rc&2)==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
96567 pMem->u.i = ix;
96568 return MEM_Int;
96569 }else{
96570 return MEM_Real;
96571 }
96572 }else if( (rc&2)==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
96573 pMem->u.i = ix;
96574 return MEM_Int;
96575 }
96576 return MEM_Real;
96577 }
@@ -110869,11 +110899,11 @@
110899 */
110900 static int exprProbability(Expr *p){
110901 double r = -1.0;
110902 if( p->op!=TK_FLOAT ) return -1;
110903 assert( !ExprHasProperty(p, EP_IntValue) );
110904 sqlite3AtoF(p->u.zToken, &r);
110905 assert( r>=0.0 );
110906 if( r>1.0 ) return -1;
110907 return (int)(r*134217728.0);
110908 }
110909
@@ -116557,11 +116587,12 @@
116587 ** z[n] character is guaranteed to be something that does not look
116588 ** like the continuation of the number.
116589 */
116590 static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
116591 if( ALWAYS(z!=0) ){
116592 double value;
116593 sqlite3AtoF(z, &value);
116594 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116595 if( negateFlag ) value = -value;
116596 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
116597 }
116598 }
@@ -142213,12 +142244,10 @@
142244 /* Version 3.52.0 and later */
142245 void (*str_truncate)(sqlite3_str*,int);
142246 void (*str_free)(sqlite3_str*);
142247 int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142248 int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
 
 
142249 };
142250
142251 /*
142252 ** This is the function signature used for all extension entry points. It
142253 ** is also defined in the file "loadext.c".
@@ -142558,12 +142587,10 @@
142587 /* Version 3.52.0 and later */
142588 #define sqlite3_str_truncate sqlite3_api->str_truncate
142589 #define sqlite3_str_free sqlite3_api->str_free
142590 #define sqlite3_carray_bind sqlite3_api->carray_bind
142591 #define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
 
 
142592 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142593
142594 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142595 /* This case when the file really is being compiled as a loadable
142596 ** extension */
@@ -143092,16 +143119,15 @@
143119 /* Version 3.52.0 and later */
143120 sqlite3_str_truncate,
143121 sqlite3_str_free,
143122 #ifdef SQLITE_ENABLE_CARRAY
143123 sqlite3_carray_bind,
143124 sqlite3_carray_bind_v2
143125 #else
143126 0,
143127 0
143128 #endif
 
143129 };
143130
143131 /* True if x is the directory separator character
143132 */
143133 #if SQLITE_OS_WIN
@@ -191439,10 +191465,21 @@
191465 *pI1 = rLogEst;
191466 *pU64 = sqlite3LogEstToInt(rLogEst);
191467 *pI2 = sqlite3LogEst(*pU64);
191468 break;
191469 }
191470
191471 /* sqlite3_test_control(SQLITE_TESTCTRL_ATOF, const char *z, double *p);
191472 **
191473 ** Test access to the sqlite3AtoF() routine.
191474 */
191475 case SQLITE_TESTCTRL_ATOF: {
191476 const char *z = va_arg(ap,const char*);
191477 double *pR = va_arg(ap,double*);
191478 rc = sqlite3AtoF(z,pR);
191479 break;
191480 }
191481
191482 #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD)
191483 /* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue)
191484 **
191485 ** If "id" is an integer between 1 and SQLITE_NTUNE then set the value
@@ -212330,11 +212367,12 @@
212367 };
212368
212369 /* Allowed values for JsonString.eErr */
212370 #define JSTRING_OOM 0x01 /* Out of memory */
212371 #define JSTRING_MALFORMED 0x02 /* Malformed JSONB */
212372 #define JSTRING_TOODEEP 0x04 /* JSON nested too deep */
212373 #define JSTRING_ERR 0x08 /* Error already sent to sqlite3_result */
212374
212375 /* The "subtype" set for text JSON values passed through using
212376 ** sqlite3_result_subtype() and sqlite3_value_subtype().
212377 */
212378 #define JSON_SUBTYPE 74 /* Ascii for "J" */
@@ -212420,11 +212458,11 @@
212458 /**************************************************************************
212459 ** Forward references
212460 **************************************************************************/
212461 static void jsonReturnStringAsBlob(JsonString*);
212462 static int jsonArgIsJsonb(sqlite3_value *pJson, JsonParse *p);
212463 static u32 jsonTranslateBlobToText(JsonParse*,u32,JsonString*);
212464 static void jsonReturnParse(sqlite3_context*,JsonParse*);
212465 static JsonParse *jsonParseFuncArg(sqlite3_context*,sqlite3_value*,u32);
212466 static void jsonParseFree(JsonParse*);
212467 static u32 jsonbPayloadSize(const JsonParse*, u32, u32*);
212468 static u32 jsonUnescapeOneChar(const char*, u32, u32*);
@@ -212577,10 +212615,19 @@
212615 static void jsonStringOom(JsonString *p){
212616 p->eErr |= JSTRING_OOM;
212617 if( p->pCtx ) sqlite3_result_error_nomem(p->pCtx);
212618 jsonStringReset(p);
212619 }
212620
212621 /* Report JSON nested too deep
212622 */
212623 static void jsonStringTooDeep(JsonString *p){
212624 p->eErr |= JSTRING_TOODEEP;
212625 assert( p->pCtx!=0 );
212626 sqlite3_result_error(p->pCtx, "JSON nested too deep", -1);
212627 jsonStringReset(p);
212628 }
212629
212630 /* Enlarge pJson->zBuf so that it can hold at least N more bytes.
212631 ** Return zero on success. Return non-zero on an OOM error
212632 */
212633 static int jsonStringGrow(JsonString *p, u32 N){
@@ -212894,10 +212941,12 @@
212941 sqlite3RCStrUnref,
212942 SQLITE_UTF8);
212943 }
212944 }else if( p->eErr & JSTRING_OOM ){
212945 sqlite3_result_error_nomem(p->pCtx);
212946 }else if( p->eErr & JSTRING_TOODEEP ){
212947 /* error already in p->pCtx */
212948 }else if( p->eErr & JSTRING_MALFORMED ){
212949 sqlite3_result_error(p->pCtx, "malformed JSON", -1);
212950 }
212951 jsonStringReset(p);
212952 }
@@ -214195,11 +214244,11 @@
214244 ** in an error, or in incorrect JSON.
214245 **
214246 ** The pOut->eErr JSTRING_OOM flag is set on a OOM.
214247 */
214248 static u32 jsonTranslateBlobToText(
214249 JsonParse *pParse, /* the complete parse of the JSON */
214250 u32 i, /* Start rendering at this index */
214251 JsonString *pOut /* Write JSON here */
214252 ){
214253 u32 sz, n, j, iEnd;
214254
@@ -214377,14 +214426,18 @@
214426 }
214427 case JSONB_ARRAY: {
214428 jsonAppendChar(pOut, '[');
214429 j = i+n;
214430 iEnd = j+sz;
214431 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
214432 jsonStringTooDeep(pOut);
214433 }
214434 while( j<iEnd && pOut->eErr==0 ){
214435 j = jsonTranslateBlobToText(pParse, j, pOut);
214436 jsonAppendChar(pOut, ',');
214437 }
214438 pParse->iDepth--;
214439 if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
214440 if( sz>0 ) jsonStringTrimOneChar(pOut);
214441 jsonAppendChar(pOut, ']');
214442 break;
214443 }
@@ -214391,14 +214444,18 @@
214444 case JSONB_OBJECT: {
214445 int x = 0;
214446 jsonAppendChar(pOut, '{');
214447 j = i+n;
214448 iEnd = j+sz;
214449 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
214450 jsonStringTooDeep(pOut);
214451 }
214452 while( j<iEnd && pOut->eErr==0 ){
214453 j = jsonTranslateBlobToText(pParse, j, pOut);
214454 jsonAppendChar(pOut, (x++ & 1) ? ',' : ':');
214455 }
214456 pParse->iDepth--;
214457 if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
214458 if( sz>0 ) jsonStringTrimOneChar(pOut);
214459 jsonAppendChar(pOut, '}');
214460 break;
214461 }
@@ -214451,11 +214508,11 @@
214508 static u32 jsonTranslateBlobToPrettyText(
214509 JsonPretty *pPretty, /* Pretty-printing context */
214510 u32 i /* Start rendering at this index */
214511 ){
214512 u32 sz, n, j, iEnd;
214513 JsonParse *pParse = pPretty->pParse;
214514 JsonString *pOut = pPretty->pOut;
214515 n = jsonbPayloadSize(pParse, i, &sz);
214516 if( n==0 ){
214517 pOut->eErr |= JSTRING_MALFORMED;
214518 return pParse->nBlob+1;
@@ -214466,10 +214523,13 @@
214523 iEnd = j+sz;
214524 jsonAppendChar(pOut, '[');
214525 if( j<iEnd ){
214526 jsonAppendChar(pOut, '\n');
214527 pPretty->nIndent++;
214528 if( pPretty->nIndent >= JSON_MAX_DEPTH ){
214529 jsonStringTooDeep(pOut);
214530 }
214531 while( pOut->eErr==0 ){
214532 jsonPrettyIndent(pPretty);
214533 j = jsonTranslateBlobToPrettyText(pPretty, j);
214534 if( j>=iEnd ) break;
214535 jsonAppendRawNZ(pOut, ",\n", 2);
@@ -214487,10 +214547,14 @@
214547 iEnd = j+sz;
214548 jsonAppendChar(pOut, '{');
214549 if( j<iEnd ){
214550 jsonAppendChar(pOut, '\n');
214551 pPretty->nIndent++;
214552 if( pPretty->nIndent >= JSON_MAX_DEPTH ){
214553 jsonStringTooDeep(pOut);
214554 }
214555 pParse->iDepth = pPretty->nIndent;
214556 while( pOut->eErr==0 ){
214557 jsonPrettyIndent(pPretty);
214558 j = jsonTranslateBlobToText(pParse, j, pOut);
214559 if( j>iEnd ){
214560 pOut->eErr |= JSTRING_MALFORMED;
@@ -214888,11 +214952,12 @@
214952 ** Error returns from jsonLookupStep()
214953 */
214954 #define JSON_LOOKUP_ERROR 0xffffffff
214955 #define JSON_LOOKUP_NOTFOUND 0xfffffffe
214956 #define JSON_LOOKUP_NOTARRAY 0xfffffffd
214957 #define JSON_LOOKUP_TOODEEP 0xfffffffc
214958 #define JSON_LOOKUP_PATHERROR 0xfffffffb
214959 #define JSON_LOOKUP_ISERROR(x) ((x)>=JSON_LOOKUP_PATHERROR)
214960
214961 /* Forward declaration */
214962 static u32 jsonLookupStep(JsonParse*,u32,const char*,u32);
214963
@@ -214935,11 +215000,16 @@
215000 pIns->nBlob = 1;
215001 pIns->aBlob = (u8*)&emptyObject[zTail[0]=='.'];
215002 pIns->eEdit = pParse->eEdit;
215003 pIns->nIns = pParse->nIns;
215004 pIns->aIns = pParse->aIns;
215005 pIns->iDepth = pParse->iDepth+1;
215006 if( pIns->iDepth >= JSON_MAX_DEPTH ){
215007 return JSON_LOOKUP_TOODEEP;
215008 }
215009 rc = jsonLookupStep(pIns, 0, zTail, 0);
215010 pParse->iDepth--;
215011 pParse->oom |= pIns->oom;
215012 }
215013 return rc; /* Error code only */
215014 }
215015
@@ -215041,11 +215111,15 @@
215111 u32 v = k+sz; /* v is the index of the value */
215112 if( ((pParse->aBlob[v])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
215113 n = jsonbPayloadSize(pParse, v, &sz);
215114 if( n==0 || v+n+sz>iEnd ) return JSON_LOOKUP_ERROR;
215115 assert( j>0 );
215116 if( ++pParse->iDepth >= JSON_MAX_DEPTH ){
215117 return JSON_LOOKUP_TOODEEP;
215118 }
215119 rc = jsonLookupStep(pParse, v, &zPath[i], j);
215120 pParse->iDepth--;
215121 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
215122 return rc;
215123 }
215124 j = k+sz;
215125 if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
@@ -215127,11 +215201,15 @@
215201 }
215202 j = iRoot+n;
215203 iEnd = j+sz;
215204 while( j<iEnd ){
215205 if( kk==0 ){
215206 if( ++pParse->iDepth >= JSON_MAX_DEPTH ){
215207 return JSON_LOOKUP_TOODEEP;
215208 }
215209 rc = jsonLookupStep(pParse, j, &zPath[i+1], 0);
215210 pParse->iDepth--;
215211 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
215212 return rc;
215213 }
215214 kk--;
215215 n = jsonbPayloadSize(pParse, j, &sz);
@@ -215459,11 +215537,20 @@
215537 return 0;
215538 }
215539 }
215540
215541 /*
215542 ** Generate a path error.
215543 **
215544 ** The specifics of the error are determined by the rc argument.
215545 **
215546 ** rc error
215547 ** ----------------- ----------------------
215548 ** JSON_LOOKUP_ARRAY "not an array"
215549 ** JSON_LOOKUP_TOODEEP "JSON nested too deep"
215550 ** JSON_LOOKUP_ERROR "malformed JSON"
215551 ** otherwise... "bad JSON path"
215552 **
215553 ** If ctx is not NULL then push the error message into ctx and return NULL.
215554 ** If ctx is NULL, then return the text of the error message.
215555 */
215556 static char *jsonBadPathError(
@@ -215472,10 +215559,14 @@
215559 int rc /* Maybe JSON_LOOKUP_NOTARRAY */
215560 ){
215561 char *zMsg;
215562 if( rc==(int)JSON_LOOKUP_NOTARRAY ){
215563 zMsg = sqlite3_mprintf("not an array element: %Q", zPath);
215564 }else if( rc==(int)JSON_LOOKUP_ERROR ){
215565 zMsg = sqlite3_mprintf("malformed JSON");
215566 }else if( rc==(int)JSON_LOOKUP_TOODEEP ){
215567 zMsg = sqlite3_mprintf("JSON path too deep");
215568 }else{
215569 zMsg = sqlite3_mprintf("bad JSON path: %Q", zPath);
215570 }
215571 if( ctx==0 ) return zMsg;
215572 if( zMsg ){
@@ -215534,10 +215625,11 @@
215625 }else{
215626 p->eEdit = eEdit;
215627 p->nIns = ax.nBlob;
215628 p->aIns = ax.aBlob;
215629 p->delta = 0;
215630 p->iDepth = 0;
215631 rc = jsonLookupStep(p, 0, zPath+1, 0);
215632 }
215633 jsonParseReset(&ax);
215634 if( rc==JSON_LOOKUP_NOTFOUND ) continue;
215635 if( JSON_LOOKUP_ISERROR(rc) ) goto jsonInsertIntoBlob_patherror;
@@ -215546,15 +215638,11 @@
215638 jsonParseFree(p);
215639 return;
215640
215641 jsonInsertIntoBlob_patherror:
215642 jsonParseFree(p);
215643 jsonBadPathError(ctx, zPath, rc);
 
 
 
 
215644 return;
215645 }
215646
215647 /*
215648 ** If pArg is a blob that seems like a JSONB blob, then initialize
@@ -215990,14 +216078,12 @@
216078 }
216079 i = jsonLookupStep(p, 0, zPath[0]=='$' ? zPath+1 : "@", 0);
216080 if( JSON_LOOKUP_ISERROR(i) ){
216081 if( i==JSON_LOOKUP_NOTFOUND ){
216082 /* no-op */
 
 
216083 }else{
216084 jsonBadPathError(ctx, zPath, i);
216085 }
216086 eErr = 1;
216087 i = 0;
216088 }
216089 }else{
@@ -216127,15 +216213,12 @@
216213 goto json_extract_error; /* Return NULL if not found */
216214 }else{
216215 jsonAppendSeparator(&jx);
216216 jsonAppendRawNZ(&jx, "null", 4);
216217 }
 
 
 
216218 }else{
216219 jsonBadPathError(ctx, zPath, j);
216220 goto json_extract_error;
216221 }
216222 }
216223 if( argc>2 ){
216224 jsonAppendChar(&jx, ']');
@@ -216155,10 +216238,11 @@
216238 */
216239 #define JSON_MERGE_OK 0 /* Success */
216240 #define JSON_MERGE_BADTARGET 1 /* Malformed TARGET blob */
216241 #define JSON_MERGE_BADPATCH 2 /* Malformed PATCH blob */
216242 #define JSON_MERGE_OOM 3 /* Out-of-memory condition */
216243 #define JSON_MERGE_TOODEEP 4 /* Nested too deep */
216244
216245 /*
216246 ** RFC-7396 MergePatch for two JSONB blobs.
216247 **
216248 ** pTarget is the target. pPatch is the patch. The target is updated
@@ -216206,11 +216290,12 @@
216290 */
216291 static int jsonMergePatch(
216292 JsonParse *pTarget, /* The JSON parser that contains the TARGET */
216293 u32 iTarget, /* Index of TARGET in pTarget->aBlob[] */
216294 const JsonParse *pPatch, /* The PATCH */
216295 u32 iPatch, /* Index of PATCH in pPatch->aBlob[] */
216296 u32 iDepth /* Nesting depth */
216297 ){
216298 u8 x; /* Type of a single node */
216299 u32 n, sz=0; /* Return values from jsonbPayloadSize() */
216300 u32 iTCursor; /* Cursor position while scanning the target object */
216301 u32 iTStart; /* First label in the target object */
@@ -216315,11 +216400,12 @@
216400 if( NEVER(pTarget->oom) ) return JSON_MERGE_OOM;
216401 }else{
216402 /* Algorithm line 12 */
216403 int rc, savedDelta = pTarget->delta;
216404 pTarget->delta = 0;
216405 if( iDepth>=JSON_MAX_DEPTH ) return JSON_MERGE_TOODEEP;
216406 rc = jsonMergePatch(pTarget, iTValue, pPatch, iPValue, iDepth+1);
216407 if( rc ) return rc;
216408 pTarget->delta += savedDelta;
216409 }
216410 }else if( x>0 ){ /* Algorithm line 13 */
216411 /* No match and patch value is not NULL */
@@ -216336,11 +216422,12 @@
216422 if( pTarget->oom ) return JSON_MERGE_OOM;
216423 memcpy(&pTarget->aBlob[iTEnd], &pPatch->aBlob[iPLabel], szNew);
216424 pTarget->aBlob[iTEnd+szNew] = 0x00;
216425 savedDelta = pTarget->delta;
216426 pTarget->delta = 0;
216427 if( iDepth>=JSON_MAX_DEPTH ) return JSON_MERGE_TOODEEP;
216428 rc = jsonMergePatch(pTarget, iTEnd+szNew,pPatch,iPValue,iDepth+1);
216429 if( rc ) return rc;
216430 pTarget->delta += savedDelta;
216431 }
216432 }
216433 }
@@ -216367,15 +216454,17 @@
216454 assert( argc==2 );
216455 pTarget = jsonParseFuncArg(ctx, argv[0], JSON_EDITABLE);
216456 if( pTarget==0 ) return;
216457 pPatch = jsonParseFuncArg(ctx, argv[1], 0);
216458 if( pPatch ){
216459 rc = jsonMergePatch(pTarget, 0, pPatch, 0, 0);
216460 if( rc==JSON_MERGE_OK ){
216461 jsonReturnParse(ctx, pTarget);
216462 }else if( rc==JSON_MERGE_OOM ){
216463 sqlite3_result_error_nomem(ctx);
216464 }else if( rc==JSON_MERGE_TOODEEP ){
216465 sqlite3_result_error(ctx, "JSON nested too deep", -1);
216466 }else{
216467 sqlite3_result_error(ctx, "malformed JSON", -1);
216468 }
216469 jsonParseFree(pPatch);
216470 }
@@ -216459,14 +216548,12 @@
216548 p->delta = 0;
216549 rc = jsonLookupStep(p, 0, zPath+1, 0);
216550 if( JSON_LOOKUP_ISERROR(rc) ){
216551 if( rc==JSON_LOOKUP_NOTFOUND ){
216552 continue; /* No-op */
216553 }else{
216554 jsonBadPathError(ctx, zPath, rc);
 
 
216555 }
216556 goto json_remove_done;
216557 }
216558 }
216559 jsonReturnParse(ctx, p);
@@ -216559,14 +216646,12 @@
216646 }
216647 i = jsonLookupStep(p, 0, zPath+1, 0);
216648 if( JSON_LOOKUP_ISERROR(i) ){
216649 if( i==JSON_LOOKUP_NOTFOUND ){
216650 /* no-op */
 
 
216651 }else{
216652 jsonBadPathError(ctx, zPath, i);
216653 }
216654 goto json_type_done;
216655 }
216656 }else{
216657 i = 0;
@@ -262393,11 +262478,11 @@
262478 int nArg, /* Number of args */
262479 sqlite3_value **apUnused /* Function arguments */
262480 ){
262481 assert( nArg==0 );
262482 UNUSED_PARAM2(nArg, apUnused);
262483 sqlite3_result_text(pCtx, "fts5: 2026-03-26 14:19:34 97ee48b6ef65fb55633196282c9e75b3b0a3b81ba9755f63493a38e3f1a5610c", -1, SQLITE_TRANSIENT);
262484 }
262485
262486 /*
262487 ** Implementation of fts5_locale(LOCALE, TEXT) function.
262488 **
262489
+3 -31
--- 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-23 13:00:56 276c350313a1ac2ebc70c1e8e50ed4baecd4be4d4c93ba04cf5e0078da18700e"
151
+#define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-03-23T13:00:56.709Z"
154
+#define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -3228,32 +3228,10 @@
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
-
32553233
/*
32563234
** CAPI3REF: Memory Allocation Subsystem
32573235
**
32583236
** The SQLite core uses these three routines for all of its own
32593237
** internal memory allocation needs. "Core" in the previous sentence
@@ -8377,17 +8355,10 @@
83778355
** that does no real locking and is appropriate for use in
83788356
** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
83798357
** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
83808358
** and Windows.
83818359
**
8382
-** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
8383
-** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
8384
-** implementation is included with the library. In this case the
8385
-** application must supply a custom mutex implementation using the
8386
-** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
8387
-** before calling sqlite3_initialize() or any other public sqlite3_
8388
-** function that calls sqlite3_initialize().
83898360
**
83908361
** ^The sqlite3_mutex_alloc() routine allocates a new
83918362
** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
83928363
** routine returns NULL if it is unable to allocate the requested
83938364
** mutex. The argument to sqlite3_mutex_alloc() must be one of these
@@ -8738,10 +8709,11 @@
87388709
#define SQLITE_TESTCTRL_SEEK_COUNT 30
87398710
#define SQLITE_TESTCTRL_TRACEFLAGS 31
87408711
#define SQLITE_TESTCTRL_TUNE 32
87418712
#define SQLITE_TESTCTRL_LOGEST 33
87428713
#define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
8714
+#define SQLITE_TESTCTRL_ATOF 34
87438715
#define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
87448716
87458717
/*
87468718
** CAPI3REF: SQL Keyword Checking
87478719
**
87488720
--- 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,32 +3228,10 @@
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
@@ -8377,17 +8355,10 @@
8377 ** that does no real locking and is appropriate for use in
8378 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
8379 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
8380 ** and Windows.
8381 **
8382 ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
8383 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
8384 ** implementation is included with the library. In this case the
8385 ** application must supply a custom mutex implementation using the
8386 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
8387 ** before calling sqlite3_initialize() or any other public sqlite3_
8388 ** function that calls sqlite3_initialize().
8389 **
8390 ** ^The sqlite3_mutex_alloc() routine allocates a new
8391 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8392 ** routine returns NULL if it is unable to allocate the requested
8393 ** mutex. The argument to sqlite3_mutex_alloc() must be one of these
@@ -8738,10 +8709,11 @@
8738 #define SQLITE_TESTCTRL_SEEK_COUNT 30
8739 #define SQLITE_TESTCTRL_TRACEFLAGS 31
8740 #define SQLITE_TESTCTRL_TUNE 32
8741 #define SQLITE_TESTCTRL_LOGEST 33
8742 #define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
 
8743 #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
8744
8745 /*
8746 ** CAPI3REF: SQL Keyword Checking
8747 **
8748
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.53.0"
150 #define SQLITE_VERSION_NUMBER 3053000
151 #define SQLITE_SOURCE_ID "2026-03-26 19:11:57 c5af6a10245b6b847d30002806c1577b020c36ab27f7b1cf202ade136aa4779c"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-03-26T19:11:57.079Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -3228,32 +3228,10 @@
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
@@ -8377,17 +8355,10 @@
8355 ** that does no real locking and is appropriate for use in
8356 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
8357 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
8358 ** and Windows.
8359 **
 
 
 
 
 
 
 
8360 **
8361 ** ^The sqlite3_mutex_alloc() routine allocates a new
8362 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8363 ** routine returns NULL if it is unable to allocate the requested
8364 ** mutex. The argument to sqlite3_mutex_alloc() must be one of these
@@ -8738,10 +8709,11 @@
8709 #define SQLITE_TESTCTRL_SEEK_COUNT 30
8710 #define SQLITE_TESTCTRL_TRACEFLAGS 31
8711 #define SQLITE_TESTCTRL_TUNE 32
8712 #define SQLITE_TESTCTRL_LOGEST 33
8713 #define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */
8714 #define SQLITE_TESTCTRL_ATOF 34
8715 #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */
8716
8717 /*
8718 ** CAPI3REF: SQL Keyword Checking
8719 **
8720
+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 = fossil_atof(db_get("chat-keep-days","7"));
354
+ double mxDays = 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 = 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/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/config.h
+++ src/config.h
@@ -56,11 +56,10 @@
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"
6261
6362
#endif
6463
6564
#if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
6665
# if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
6766
--- src/config.h
+++ src/config.h
@@ -56,11 +56,10 @@
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
--- src/config.h
+++ src/config.h
@@ -56,11 +56,10 @@
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
+1 -2
--- src/diff.c
+++ src/diff.c
@@ -3609,12 +3609,11 @@
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() +
3615
- 1000.0*fossil_atof(zLimit));
3614
+ (sqlite3_int64)(current_time_in_milliseconds() + 1000.0*atof(zLimit));
36163615
}else{
36173616
iLimit = atoi(zLimit);
36183617
if( iLimit<=0 ) iLimit = 30;
36193618
mxTime = 0;
36203619
}
36213620
--- src/diff.c
+++ src/diff.c
@@ -3609,12 +3609,11 @@
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
--- src/diff.c
+++ src/diff.c
@@ -3609,12 +3609,11 @@
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
+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 = fossil_atof(db_get("max-loadavg", "0.0"));
57
+ double mxLoad = 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 = fossil_atof(db_get("max-loadavg", "0.0"));
75
+ double mxLoad = 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 = 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
--- 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
+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 = fossil_atof(zArg);
1454
+ double rTime = 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 = 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/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/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 = fossil_atof(zPikVar))>=0.1
728
+ && (rPikVar = 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 = fossil_atof(zPikVar))>=0.1
735
+ && (rPikVar = 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 = 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
--- 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
+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 = fossil_atof(&zData[i]);
301
+ rAmt = 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 = 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
--- 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
+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 = fossil_atof(zArg);
218
+ double r = 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 = 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
--- 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
-11
--- src/printf.c
+++ src/printf.c
@@ -1302,21 +1302,10 @@
13021302
}
13031303
}
13041304
free(z);
13051305
}
13061306
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
-
13181307
/*
13191308
** Turn off any LF to CRLF translation on the stream given as an
13201309
** argument. This is a no-op on unix but is necessary on windows.
13211310
*/
13221311
void fossil_binary_mode(FILE *p){
13231312
--- src/printf.c
+++ src/printf.c
@@ -1302,21 +1302,10 @@
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 void fossil_binary_mode(FILE *p){
1323
--- src/printf.c
+++ src/printf.c
@@ -1302,21 +1302,10 @@
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 void fossil_binary_mode(FILE *p){
1312
--- 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 = fossil_atof(db_get("max-loadavg", "0.0"));
594
+ double r = 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 && fossil_atof(z)>0.0 ){
731
+ if( z && 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 = 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
--- 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
+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 = fossil_atof(zMax);
1187
+ double r = 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 = 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
--- 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
+69 -3
--- src/th.c
+++ src/th.c
@@ -12,11 +12,10 @@
1212
/*
1313
** External routines
1414
*/
1515
void fossil_panic(const char*,...);
1616
void fossil_errorlog(const char*,...);
17
-double fossil_atof(const char*);
1817
1918
/*
2019
** Values used for element values in the tcl_platform array.
2120
*/
2221
@@ -2749,10 +2748,76 @@
27492748
while( th_isdigit(*(u8*)z) ){ z += incr; }
27502749
if( realnum ) *realnum = 1;
27512750
}
27522751
return *z==0;
27532752
}
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
+}
27542819
27552820
/*
27562821
** Try to convert the string passed as arguments (z, n) to an integer.
27572822
** If successful, store the result in *piOut and return TH_OK.
27582823
**
@@ -2826,15 +2891,16 @@
28262891
Th_Interp *interp,
28272892
const char *z,
28282893
int n,
28292894
double *pfOut
28302895
){
2831
- *pfOut = fossil_atof(z);
2832
- if( 0.0==(*pfOut) && !sqlite3IsNumber((const char *)z, 0) ){
2896
+ if( !sqlite3IsNumber((const char *)z, 0) ){
28332897
Th_ErrorMessage(interp, "expected number, got: \"", z, TH1_LEN(n));
28342898
return TH_ERROR;
28352899
}
2900
+
2901
+ sqlite3AtoF((const char *)z, pfOut);
28362902
return TH_OK;
28372903
}
28382904
28392905
/*
28402906
** Set the result of the interpreter to the th1 representation of
28412907
--- src/th.c
+++ src/th.c
@@ -12,11 +12,10 @@
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,10 +2748,76 @@
2749 while( th_isdigit(*(u8*)z) ){ z += incr; }
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 **
@@ -2826,15 +2891,16 @@
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
--- src/th.c
+++ src/th.c
@@ -12,11 +12,10 @@
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,10 +2748,76 @@
2748 while( th_isdigit(*(u8*)z) ){ z += incr; }
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 **
@@ -2826,15 +2891,16 @@
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

Keyboard Shortcuts

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