Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Update the built-in SQLite to the latest 3.47.0 beta for testing. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
753bf7d57a679e8ff5db5ddcc30fca74 |
User & Date: | drh 2024-10-12 11:10:25 |
Context
2024-10-14
| ||
01:10 | Cherry-pick the show-in-pikchrview feature that was added to the omit-cr branch. ... (check-in: 521da5cd user: drh tags: trunk) | |
2024-10-12
| ||
12:03 | Emit only \n, not \r\n, even in places where protocols technically require a full \r\n. Provide a compile-time option -DSEND_CR=1 that includes the CRs when necessary. ... (check-in: 0dcce257 user: drh tags: omit-cr) | |
11:10 | Update the built-in SQLite to the latest 3.47.0 beta for testing. ... (check-in: 753bf7d5 user: drh tags: trunk) | |
07:16 | A cleaner solution to the Clear Glob link fix in [e576ce7b5598710a5]. ... (check-in: 7f288c6d user: stephan tags: trunk) | |
Changes
Changes to extsrc/shell.c.
︙ | ︙ | |||
341 342 343 344 345 346 347 | /* #include "sqlite3.h" */ #include <ctype.h> #include <stdarg.h> #include <io.h> #include <fcntl.h> /* | | < < | > | | > | | | < < | < > | < < < < < > > > > > > > > > > > > > > > > > > > > > > > > > > | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | /* #include "sqlite3.h" */ #include <ctype.h> #include <stdarg.h> #include <io.h> #include <fcntl.h> /* ** If the SQLITE_U8TEXT_ONLY option is defined, then use O_U8TEXT ** when appropriate on all output. (Sometimes use O_BINARY when ** rendering ASCII text in cases where NL-to-CRLF expansion would ** not be correct.) ** ** If the SQLITE_U8TEXT_STDIO option is defined, then use O_U8TEXT ** when appropriate when writing to stdout or stderr. Use O_BINARY ** or O_TEXT (depending on things like the .mode and the .crnl setting ** in the CLI, or other context clues in other applications) for all ** other output channels. ** ** The default behavior, if neither of the above is defined is to ** use O_U8TEXT when writing to the Windows console (or anything ** else for which _isatty() returns true) and to use O_BINARY or O_TEXT ** for all other output channels. */ #if defined(SQLITE_U8TEXT_ONLY) # define UseWtextForOutput(fd) 1 # define UseWtextForInput(fd) 1 # define IsConsole(fd) _isatty(_fileno(fd)) #elif defined(SQLITE_U8TEXT_STDIO) # define UseWtextForOutput(fd) ((fd)==stdout || (fd)==stderr) # define UseWtextForInput(fd) ((fd)==stdin) # define IsConsole(fd) _isatty(_fileno(fd)) #else # define UseWtextForOutput(fd) _isatty(_fileno(fd)) # define UseWtextForInput(fd) _isatty(_fileno(fd)) # define IsConsole(fd) 1 #endif /* ** Global variables determine if simulated O_BINARY mode is to be ** used for stdout or other, respectively. Simulated O_BINARY mode ** means the mode is usually O_BINARY, but switches to O_U8TEXT for ** unicode characters U+0080 or greater (any character that has a ** multi-byte representation in UTF-8). This is the only way we ** have found to render Unicode characters on a Windows console while ** at the same time avoiding undesirable \n to \r\n translation. */ static int simBinaryStdout = 0; static int simBinaryOther = 0; /* ** Determine if simulated binary mode should be used for output to fd */ static int UseBinaryWText(FILE *fd){ if( fd==stdout || fd==stderr ){ return simBinaryStdout; }else{ return simBinaryOther; } } /* ** Work-alike for the fopen() routine from the standard C library. */ FILE *sqlite3_fopen(const char *zFilename, const char *zMode){ FILE *fp = 0; wchar_t *b1, *b2; |
︙ | ︙ | |||
398 399 400 401 402 403 404 405 406 407 408 409 410 411 | b1[sz1] = 0; sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); b2[sz2] = 0; fp = _wfopen(b1, b2); } free(b1); free(b2); return fp; } /* ** Work-alike for the popen() routine from the standard C library. */ | > | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | b1[sz1] = 0; sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); b2[sz2] = 0; fp = _wfopen(b1, b2); } free(b1); free(b2); simBinaryOther = 0; return fp; } /* ** Work-alike for the popen() routine from the standard C library. */ |
︙ | ︙ | |||
452 453 454 455 456 457 458 459 460 461 462 463 | return buf; }else{ /* Reading from a file or other input source, just read bytes without ** any translation. */ return fgets(buf, sz, in); } } /* ** Work-alike for fputs() from the standard C library. */ int sqlite3_fputs(const char *z, FILE *out){ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > | > > > > | > < < < < | 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | return buf; }else{ /* Reading from a file or other input source, just read bytes without ** any translation. */ return fgets(buf, sz, in); } } /* ** Send ASCII text as O_BINARY. But for Unicode characters U+0080 and ** greater, switch to O_U8TEXT. */ static void piecemealOutput(wchar_t *b1, int sz, FILE *out){ int i; wchar_t c; while( sz>0 ){ for(i=0; i<sz && b1[i]>=0x80; i++){} if( i>0 ){ c = b1[i]; b1[i] = 0; fflush(out); _setmode(_fileno(out), _O_U8TEXT); fputws(b1, out); fflush(out); b1 += i; b1[0] = c; sz -= i; }else{ fflush(out); _setmode(_fileno(out), _O_TEXT); _setmode(_fileno(out), _O_BINARY); fwrite(&b1[0], 1, 1, out); for(i=1; i<sz && b1[i]<0x80; i++){ fwrite(&b1[i], 1, 1, out); } fflush(out); _setmode(_fileno(out), _O_U8TEXT); b1 += i; sz -= i; } } } /* ** Work-alike for fputs() from the standard C library. */ int sqlite3_fputs(const char *z, FILE *out){ if( !UseWtextForOutput(out) ){ /* Writing to a file or other destination, just write bytes without ** any translation. */ return fputs(z, out); }else{ /* When writing to the command-prompt in Windows, it is necessary ** to use O_U8TEXT to render Unicode U+0080 and greater. Go ahead ** use O_U8TEXT for everything in text mode. */ int sz = (int)strlen(z); wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) ); if( b1==0 ) return 0; sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz); b1[sz] = 0; _setmode(_fileno(out), _O_U8TEXT); if( UseBinaryWText(out) ){ piecemealOutput(b1, sz, out); }else{ fputws(b1, out); } sqlite3_free(b1); return 0; } } /* ** Work-alike for fprintf() from the standard C library. */ |
︙ | ︙ | |||
515 516 517 518 519 520 521 522 523 524 525 526 527 528 | ** Set the mode for an output stream. mode argument is typically _O_BINARY or ** _O_TEXT. */ void sqlite3_fsetmode(FILE *fp, int mode){ if( !UseWtextForOutput(fp) ){ fflush(fp); _setmode(_fileno(fp), mode); } } #endif /* defined(_WIN32) */ /************************* End ../ext/misc/sqlite3_stdio.c ********************/ | > > > > | 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | ** Set the mode for an output stream. mode argument is typically _O_BINARY or ** _O_TEXT. */ void sqlite3_fsetmode(FILE *fp, int mode){ if( !UseWtextForOutput(fp) ){ fflush(fp); _setmode(_fileno(fp), mode); }else if( fp==stdout || fp==stderr ){ simBinaryStdout = (mode==_O_BINARY); }else{ simBinaryOther = (mode==_O_BINARY); } } #endif /* defined(_WIN32) */ /************************* End ../ext/misc/sqlite3_stdio.c ********************/ |
︙ | ︙ | |||
6764 6765 6766 6767 6768 6769 6770 | }else{ assert( op==SQLITE_INDEX_CONSTRAINT_OFFSET ); aIdx[4] = i; idxNum |= 0x40; } continue; } | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 | }else{ assert( op==SQLITE_INDEX_CONSTRAINT_OFFSET ); aIdx[4] = i; idxNum |= 0x40; } continue; } if( pConstraint->iColumn<SERIES_COLUMN_START ){ if( pConstraint->iColumn==SERIES_COLUMN_VALUE ){ switch( op ){ case SQLITE_INDEX_CONSTRAINT_EQ: case SQLITE_INDEX_CONSTRAINT_IS: { idxNum |= 0x0080; idxNum &= ~0x3300; aIdx[5] = i; aIdx[6] = -1; bStartSeen = 1; break; } case SQLITE_INDEX_CONSTRAINT_GE: { if( idxNum & 0x0080 ) break; idxNum |= 0x0100; idxNum &= ~0x0200; aIdx[5] = i; bStartSeen = 1; break; } case SQLITE_INDEX_CONSTRAINT_GT: { if( idxNum & 0x0080 ) break; idxNum |= 0x0200; idxNum &= ~0x0100; aIdx[5] = i; bStartSeen = 1; break; } case SQLITE_INDEX_CONSTRAINT_LE: { if( idxNum & 0x0080 ) break; idxNum |= 0x1000; idxNum &= ~0x2000; aIdx[6] = i; break; } case SQLITE_INDEX_CONSTRAINT_LT: { if( idxNum & 0x0080 ) break; idxNum |= 0x2000; idxNum &= ~0x1000; aIdx[6] = i; break; } } } continue; } iCol = pConstraint->iColumn - SERIES_COLUMN_START; assert( iCol>=0 && iCol<=2 ); iMask = 1 << iCol; |
︙ | ︙ | |||
21200 21201 21202 21203 21204 21205 21206 21207 21208 21209 21210 21211 21212 21213 | u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */ u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */ u8 nEqpLevel; /* Depth of the EQP output graph */ u8 eTraceType; /* SHELL_TRACE_* value for type of trace */ u8 bSafeMode; /* True to prohibit unsafe operations */ u8 bSafeModePersist; /* The long-term value of bSafeMode */ u8 eRestoreState; /* See comments above doAutoDetectRestore() */ ColModeOpts cmOpts; /* Option values affecting columnar mode output */ unsigned statsOn; /* True to display memory stats before each finalize */ unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */ int inputNesting; /* Track nesting level of .read and other redirects */ int outCount; /* Revert to stdout when reaching zero */ int cnt; /* Number of records displayed so far */ int lineno; /* Line number of last line read from in */ | > | 21266 21267 21268 21269 21270 21271 21272 21273 21274 21275 21276 21277 21278 21279 21280 | u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */ u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */ u8 nEqpLevel; /* Depth of the EQP output graph */ u8 eTraceType; /* SHELL_TRACE_* value for type of trace */ u8 bSafeMode; /* True to prohibit unsafe operations */ u8 bSafeModePersist; /* The long-term value of bSafeMode */ u8 eRestoreState; /* See comments above doAutoDetectRestore() */ u8 crnlMode; /* Do NL-to-CRLF translations when enabled (maybe) */ ColModeOpts cmOpts; /* Option values affecting columnar mode output */ unsigned statsOn; /* True to display memory stats before each finalize */ unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */ int inputNesting; /* Track nesting level of .read and other redirects */ int outCount; /* Revert to stdout when reaching zero */ int cnt; /* Number of records displayed so far */ int lineno; /* Line number of last line read from in */ |
︙ | ︙ | |||
21380 21381 21382 21383 21384 21385 21386 | ** import/export modes. */ #define SEP_Column "|" #define SEP_Row "\n" #define SEP_Tab "\t" #define SEP_Space " " #define SEP_Comma "," | < < < | < < < | 21447 21448 21449 21450 21451 21452 21453 21454 21455 21456 21457 21458 21459 21460 21461 | ** import/export modes. */ #define SEP_Column "|" #define SEP_Row "\n" #define SEP_Tab "\t" #define SEP_Space " " #define SEP_Comma "," #define SEP_CrLf "\n" /* Use ".crnl on" to get \r\n line endings */ #define SEP_Unit "\x1F" #define SEP_Record "\x1E" /* ** Limit input nesting via .read or any other input redirect. ** It's not too expensive, so a generous allowance can be made. */ |
︙ | ︙ | |||
21602 21603 21604 21605 21606 21607 21608 21609 21610 21611 21612 21613 21614 21615 | } static void outputModePop(ShellState *p){ p->mode = p->modePrior; p->shellFlgs = p->priorShFlgs; memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator)); memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator)); } /* ** Output the given string as a hex-encoded blob (eg. X'1234' ) */ static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){ int i; unsigned char *aBlob = (unsigned char*)pBlob; | > > > > > > > > > > > > > | 21663 21664 21665 21666 21667 21668 21669 21670 21671 21672 21673 21674 21675 21676 21677 21678 21679 21680 21681 21682 21683 21684 21685 21686 21687 21688 21689 | } static void outputModePop(ShellState *p){ p->mode = p->modePrior; p->shellFlgs = p->priorShFlgs; memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator)); memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator)); } /* ** Set output mode to text or binary for Windows. */ static void setCrnlMode(ShellState *p){ #ifdef _WIN32 if( p->crnlMode ){ sqlite3_fsetmode(p->out, _O_TEXT); }else{ sqlite3_fsetmode(p->out, _O_BINARY); } #endif } /* ** Output the given string as a hex-encoded blob (eg. X'1234' ) */ static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){ int i; unsigned char *aBlob = (unsigned char*)pBlob; |
︙ | ︙ | |||
21653 21654 21655 21656 21657 21658 21659 | } /* ** Output the given string as a quoted string using SQL quoting conventions. ** ** See also: output_quoted_escaped_string() */ | | > | 21727 21728 21729 21730 21731 21732 21733 21734 21735 21736 21737 21738 21739 21740 21741 21742 21743 21744 | } /* ** Output the given string as a quoted string using SQL quoting conventions. ** ** See also: output_quoted_escaped_string() */ static void output_quoted_string(ShellState *p, const char *z){ int i; char c; FILE *out = p->out; sqlite3_fsetmode(out, _O_BINARY); if( z==0 ) return; for(i=0; (c = z[i])!=0 && c!='\''; i++){} if( c==0 ){ sqlite3_fprintf(out, "'%s'",z); }else{ sqlite3_fputs("'", out); |
︙ | ︙ | |||
21681 21682 21683 21684 21685 21686 21687 | if( c==0 ){ break; } z++; } sqlite3_fputs("'", out); } | | | > | 21756 21757 21758 21759 21760 21761 21762 21763 21764 21765 21766 21767 21768 21769 21770 21771 21772 21773 21774 21775 21776 21777 21778 21779 21780 21781 21782 21783 21784 21785 | if( c==0 ){ break; } z++; } sqlite3_fputs("'", out); } setCrnlMode(p); } /* ** Output the given string as a quoted string using SQL quoting conventions. ** Additionallly , escape the "\n" and "\r" characters so that they do not ** get corrupted by end-of-line translation facilities in some operating ** systems. ** ** This is like output_quoted_string() but with the addition of the \r\n ** escape mechanism. */ static void output_quoted_escaped_string(ShellState *p, const char *z){ int i; char c; FILE *out = p->out; sqlite3_fsetmode(out, _O_BINARY); for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){} if( c==0 ){ sqlite3_fprintf(out, "'%s'",z); }else{ const char *zNL = 0; const char *zCR = 0; |
︙ | ︙ | |||
21748 21749 21750 21751 21752 21753 21754 | if( nCR ){ sqlite3_fprintf(out, ",'%s',char(13))", zCR); } if( nNL ){ sqlite3_fprintf(out, ",'%s',char(10))", zNL); } } | | | 21824 21825 21826 21827 21828 21829 21830 21831 21832 21833 21834 21835 21836 21837 21838 | if( nCR ){ sqlite3_fprintf(out, ",'%s',char(13))", zCR); } if( nNL ){ sqlite3_fprintf(out, ",'%s',char(10))", zNL); } } setCrnlMode(p); } /* ** Find earliest of chars within s specified in zAny. ** With ns == ~0, is like strpbrk(s,zAny) and s must be 0-terminated. */ static const char *anyOfInStr(const char *s, const char *zAny, size_t ns){ |
︙ | ︙ | |||
22537 22538 22539 22540 22541 22542 22543 | } case MODE_Csv: { sqlite3_fsetmode(p->out, _O_BINARY); if( p->cnt++==0 && p->showHeader ){ for(i=0; i<nArg; i++){ output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1); } | > > > | > > > > | | > | | 22613 22614 22615 22616 22617 22618 22619 22620 22621 22622 22623 22624 22625 22626 22627 22628 22629 22630 22631 22632 22633 22634 22635 22636 22637 22638 22639 22640 22641 22642 22643 | } case MODE_Csv: { sqlite3_fsetmode(p->out, _O_BINARY); if( p->cnt++==0 && p->showHeader ){ for(i=0; i<nArg; i++){ output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1); } if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){ sqlite3_fputs("\r\n", p->out); }else{ sqlite3_fputs(p->rowSeparator, p->out); } } if( nArg>0 ){ for(i=0; i<nArg; i++){ output_csv(p, azArg[i], i<nArg-1); } if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){ sqlite3_fputs("\r\n", p->out); }else{ sqlite3_fputs(p->rowSeparator, p->out); } } setCrnlMode(p); break; } case MODE_Insert: { if( azArg==0 ) break; sqlite3_fprintf(p->out, "INSERT INTO %s",p->zDestTable); if( p->showHeader ){ sqlite3_fputs("(", p->out); |
︙ | ︙ | |||
22573 22574 22575 22576 22577 22578 22579 | p->cnt++; for(i=0; i<nArg; i++){ sqlite3_fputs(i>0 ? "," : " VALUES(", p->out); if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ sqlite3_fputs("NULL", p->out); }else if( aiType && aiType[i]==SQLITE_TEXT ){ if( ShellHasFlag(p, SHFLG_Newlines) ){ | | | | 22657 22658 22659 22660 22661 22662 22663 22664 22665 22666 22667 22668 22669 22670 22671 22672 22673 | p->cnt++; for(i=0; i<nArg; i++){ sqlite3_fputs(i>0 ? "," : " VALUES(", p->out); if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ sqlite3_fputs("NULL", p->out); }else if( aiType && aiType[i]==SQLITE_TEXT ){ if( ShellHasFlag(p, SHFLG_Newlines) ){ output_quoted_string(p, azArg[i]); }else{ output_quoted_escaped_string(p, azArg[i]); } }else if( aiType && aiType[i]==SQLITE_INTEGER ){ sqlite3_fputs(azArg[i], p->out); }else if( aiType && aiType[i]==SQLITE_FLOAT ){ char z[50]; double r = sqlite3_column_double(p->pStmt, i); sqlite3_uint64 ur; |
︙ | ︙ | |||
22604 22605 22606 22607 22608 22609 22610 | }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ const void *pBlob = sqlite3_column_blob(p->pStmt, i); int nBlob = sqlite3_column_bytes(p->pStmt, i); output_hex_blob(p->out, pBlob, nBlob); }else if( isNumber(azArg[i], 0) ){ sqlite3_fputs(azArg[i], p->out); }else if( ShellHasFlag(p, SHFLG_Newlines) ){ | | | | 22688 22689 22690 22691 22692 22693 22694 22695 22696 22697 22698 22699 22700 22701 22702 22703 22704 | }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ const void *pBlob = sqlite3_column_blob(p->pStmt, i); int nBlob = sqlite3_column_bytes(p->pStmt, i); output_hex_blob(p->out, pBlob, nBlob); }else if( isNumber(azArg[i], 0) ){ sqlite3_fputs(azArg[i], p->out); }else if( ShellHasFlag(p, SHFLG_Newlines) ){ output_quoted_string(p, azArg[i]); }else{ output_quoted_escaped_string(p, azArg[i]); } } sqlite3_fputs(");\n", p->out); break; } case MODE_Json: { if( azArg==0 ) break; |
︙ | ︙ | |||
22659 22660 22661 22662 22663 22664 22665 | break; } case MODE_Quote: { if( azArg==0 ) break; if( p->cnt==0 && p->showHeader ){ for(i=0; i<nArg; i++){ if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); | | | | | 22743 22744 22745 22746 22747 22748 22749 22750 22751 22752 22753 22754 22755 22756 22757 22758 22759 22760 22761 22762 22763 22764 22765 22766 22767 22768 22769 22770 22771 22772 22773 22774 22775 22776 22777 22778 22779 22780 22781 22782 | break; } case MODE_Quote: { if( azArg==0 ) break; if( p->cnt==0 && p->showHeader ){ for(i=0; i<nArg; i++){ if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); output_quoted_string(p, azCol[i]); } sqlite3_fputs(p->rowSeparator, p->out); } p->cnt++; for(i=0; i<nArg; i++){ if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ sqlite3_fputs("NULL", p->out); }else if( aiType && aiType[i]==SQLITE_TEXT ){ output_quoted_string(p, azArg[i]); }else if( aiType && aiType[i]==SQLITE_INTEGER ){ sqlite3_fputs(azArg[i], p->out); }else if( aiType && aiType[i]==SQLITE_FLOAT ){ char z[50]; double r = sqlite3_column_double(p->pStmt, i); sqlite3_snprintf(50,z,"%!.20g", r); sqlite3_fputs(z, p->out); }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ const void *pBlob = sqlite3_column_blob(p->pStmt, i); int nBlob = sqlite3_column_bytes(p->pStmt, i); output_hex_blob(p->out, pBlob, nBlob); }else if( isNumber(azArg[i], 0) ){ sqlite3_fputs(azArg[i], p->out); }else{ output_quoted_string(p, azArg[i]); } } sqlite3_fputs(p->rowSeparator, p->out); break; } case MODE_Ascii: { if( p->cnt++==0 && p->showHeader ){ |
︙ | ︙ | |||
24688 24689 24690 24691 24692 24693 24694 | #endif ".changes on|off Show number of rows changed by SQL", #ifndef SQLITE_SHELL_FIDDLE ".check GLOB Fail if output since .testcase does not match", ".clone NEWDB Clone data into NEWDB from the existing database", #endif ".connection [close] [#] Open or close an auxiliary database connection", | < < | < | 24772 24773 24774 24775 24776 24777 24778 24779 24780 24781 24782 24783 24784 24785 24786 | #endif ".changes on|off Show number of rows changed by SQL", #ifndef SQLITE_SHELL_FIDDLE ".check GLOB Fail if output since .testcase does not match", ".clone NEWDB Clone data into NEWDB from the existing database", #endif ".connection [close] [#] Open or close an auxiliary database connection", ".crnl on|off Translate \\n to \\r\\n sometimes. Default OFF", ".databases List names and files of attached databases", ".dbconfig ?op? ?val? List or change sqlite3_db_config() options", #if SQLITE_SHELL_HAVE_RECOVER ".dbinfo ?DB? Show status information about the database", #endif ".dump ?OBJECTS? Render database content as SQL", " Options:", |
︙ | ︙ | |||
25690 25691 25692 25693 25694 25695 25696 | } /* ** Try to open an output file. The names "stdout" and "stderr" are ** recognized and do the right thing. NULL is returned if the output ** filename is "off". */ | | | | 25771 25772 25773 25774 25775 25776 25777 25778 25779 25780 25781 25782 25783 25784 25785 25786 25787 25788 25789 25790 25791 25792 25793 25794 | } /* ** Try to open an output file. The names "stdout" and "stderr" are ** recognized and do the right thing. NULL is returned if the output ** filename is "off". */ static FILE *output_file_open(const char *zFile){ FILE *f; if( cli_strcmp(zFile,"stdout")==0 ){ f = stdout; }else if( cli_strcmp(zFile, "stderr")==0 ){ f = stderr; }else if( cli_strcmp(zFile, "off")==0 ){ f = 0; }else{ f = sqlite3_fopen(zFile, "w"); if( f==0 ){ sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile); } } return f; } |
︙ | ︙ | |||
26172 26173 26174 26175 26176 26177 26178 26179 26180 26181 26182 26183 26184 26185 | ** Change the output stream (file or pipe or console) to something else. */ static void output_redir(ShellState *p, FILE *pfNew){ if( p->out != stdout ){ sqlite3_fputs("Output already redirected.\n", stderr); }else{ p->out = pfNew; if( p->mode==MODE_Www ){ sqlite3_fputs( "<!DOCTYPE html>\n" "<HTML><BODY><PRE>\n", p->out ); } | > | 26253 26254 26255 26256 26257 26258 26259 26260 26261 26262 26263 26264 26265 26266 26267 | ** Change the output stream (file or pipe or console) to something else. */ static void output_redir(ShellState *p, FILE *pfNew){ if( p->out != stdout ){ sqlite3_fputs("Output already redirected.\n", stderr); }else{ p->out = pfNew; setCrnlMode(p); if( p->mode==MODE_Www ){ sqlite3_fputs( "<!DOCTYPE html>\n" "<HTML><BODY><PRE>\n", p->out ); } |
︙ | ︙ | |||
26227 26228 26229 26230 26231 26232 26233 26234 26235 26236 26237 26238 26239 26240 | outputModePop(p); p->doXdgOpen = 0; } #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */ } p->outfile[0] = 0; p->out = stdout; } #else # define output_redir(SS,pfO) # define output_reset(SS) #endif /* | > | 26309 26310 26311 26312 26313 26314 26315 26316 26317 26318 26319 26320 26321 26322 26323 | outputModePop(p); p->doXdgOpen = 0; } #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */ } p->outfile[0] = 0; p->out = stdout; setCrnlMode(p); } #else # define output_redir(SS,pfO) # define output_reset(SS) #endif /* |
︙ | ︙ | |||
28181 28182 28183 28184 28185 28186 28187 | eputz("Usage: .bail on|off\n"); rc = 1; } }else /* Undocumented. Legacy only. See "crnl" below */ if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){ | | | 28264 28265 28266 28267 28268 28269 28270 28271 28272 28273 28274 28275 28276 28277 28278 | eputz("Usage: .bail on|off\n"); rc = 1; } }else /* Undocumented. Legacy only. See "crnl" below */ if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){ eputz("The \".binary\" command is deprecated.\n"); rc = 1; }else /* The undocumented ".breakpoint" command causes a call to the no-op ** routine named test_breakpoint(). */ if( c=='b' && n>=3 && cli_strncmp(azArg[0], "breakpoint", n)==0 ){ |
︙ | ︙ | |||
28308 28309 28310 28311 28312 28313 28314 | }else{ eputz("Usage: .connection [close] [CONNECTION-NUMBER]\n"); rc = 1; } }else if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){ | < < < < | | | | < < | < < | 28391 28392 28393 28394 28395 28396 28397 28398 28399 28400 28401 28402 28403 28404 28405 28406 28407 28408 28409 28410 28411 | }else{ eputz("Usage: .connection [close] [CONNECTION-NUMBER]\n"); rc = 1; } }else if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){ if( nArg==2 ){ p->crnlMode = booleanValue(azArg[1]); setCrnlMode(p); }else{ sqlite3_fprintf(stderr, "crnl is currently %s\n", p->crnlMode ? "ON" : "OFF"); } }else if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){ char **azName = 0; int nName = 0; sqlite3_stmt *pStmt; int i; |
︙ | ︙ | |||
29402 29403 29404 29405 29406 29407 29408 | ){ sputz(stdout, "cannot set .log to anything other" " than \"on\" or \"off\"\n"); zFile = "off"; } output_file_close(p->pLog); if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout"; | | | 29477 29478 29479 29480 29481 29482 29483 29484 29485 29486 29487 29488 29489 29490 29491 | ){ sputz(stdout, "cannot set .log to anything other" " than \"on\" or \"off\"\n"); zFile = "off"; } output_file_close(p->pLog); if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout"; p->pLog = output_file_open(zFile); } }else if( c=='m' && cli_strncmp(azArg[0], "mode", n)==0 ){ const char *zMode = 0; const char *zTabname = 0; int i, n2; |
︙ | ︙ | |||
29657 29658 29659 29660 29661 29662 29663 | if( (c=='o' && (cli_strncmp(azArg[0], "output", n)==0 || cli_strncmp(azArg[0], "once", n)==0)) || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0) || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0) ){ char *zFile = 0; | < | 29732 29733 29734 29735 29736 29737 29738 29739 29740 29741 29742 29743 29744 29745 | if( (c=='o' && (cli_strncmp(azArg[0], "output", n)==0 || cli_strncmp(azArg[0], "once", n)==0)) || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0) || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0) ){ char *zFile = 0; int i; int eMode = 0; int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */ int bPlain = 0; /* --plain option */ static const char *zBomUtf8 = "\357\273\277"; const char *zBom = 0; |
︙ | ︙ | |||
29739 29740 29741 29742 29743 29744 29745 | zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does ** not work without it. */ #endif }else if( eMode=='w' ){ /* web-browser mode. */ newTempFile(p, "html"); if( !bPlain ) p->mode = MODE_Www; | < < | 29813 29814 29815 29816 29817 29818 29819 29820 29821 29822 29823 29824 29825 29826 29827 29828 29829 | zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does ** not work without it. */ #endif }else if( eMode=='w' ){ /* web-browser mode. */ newTempFile(p, "html"); if( !bPlain ) p->mode = MODE_Www; }else{ /* text editor mode */ newTempFile(p, "txt"); } sqlite3_free(zFile); zFile = sqlite3_mprintf("%s", p->zTempFile); } #endif /* SQLITE_NOHAVE_SYSTEM */ shell_check_oom(zFile); if( zFile[0]=='|' ){ |
︙ | ︙ | |||
29767 29768 29769 29770 29771 29772 29773 | }else{ output_redir(p, pfPipe); if( zBom ) sqlite3_fputs(zBom, pfPipe); sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); } #endif }else{ | | > < | 29839 29840 29841 29842 29843 29844 29845 29846 29847 29848 29849 29850 29851 29852 29853 29854 29855 29856 29857 29858 29859 29860 29861 29862 29863 29864 29865 29866 29867 | }else{ output_redir(p, pfPipe); if( zBom ) sqlite3_fputs(zBom, pfPipe); sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); } #endif }else{ FILE *pfFile = output_file_open(zFile); if( pfFile==0 ){ if( cli_strcmp(zFile,"off")!=0 ){ sqlite3_fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile); } rc = 1; } else { output_redir(p, pfFile); if( zBom ) sqlite3_fputs(zBom, pfFile); if( bPlain && eMode=='w' ){ sqlite3_fputs( "<!DOCTYPE html>\n<BODY>\n<PLAINTEXT>\n", pfFile ); } sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); } } sqlite3_free(zFile); }else #endif /* !defined(SQLITE_SHELL_FIDDLE) */ |
︙ | ︙ | |||
29978 29979 29980 29981 29982 29983 29984 | rc = 1; goto meta_command_exit; } if( azArg[1][0]=='|' ){ #ifdef SQLITE_OMIT_POPEN eputz("Error: pipes are not supported in this OS\n"); rc = 1; | < | 30050 30051 30052 30053 30054 30055 30056 30057 30058 30059 30060 30061 30062 30063 | rc = 1; goto meta_command_exit; } if( azArg[1][0]=='|' ){ #ifdef SQLITE_OMIT_POPEN eputz("Error: pipes are not supported in this OS\n"); rc = 1; #else p->in = sqlite3_popen(azArg[1]+1, "r"); if( p->in==0 ){ sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); rc = 1; }else{ rc = process_input(p); |
︙ | ︙ | |||
30965 30966 30967 30968 30969 30970 30971 | sqlite3_free(azResult); }else #ifndef SQLITE_SHELL_FIDDLE /* Begin redirecting output to the file "testcase-out.txt" */ if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){ output_reset(p); | | | 31036 31037 31038 31039 31040 31041 31042 31043 31044 31045 31046 31047 31048 31049 31050 | sqlite3_free(azResult); }else #ifndef SQLITE_SHELL_FIDDLE /* Begin redirecting output to the file "testcase-out.txt" */ if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){ output_reset(p); p->out = output_file_open("testcase-out.txt"); if( p->out==0 ){ eputz("Error: cannot open 'testcase-out.txt'\n"); } if( nArg>=2 ){ sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]); }else{ sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?"); |
︙ | ︙ | |||
31469 31470 31471 31472 31473 31474 31475 | else { sqlite3_fprintf(stderr,"Unknown option \"%s\" on \".trace\"\n", z); rc = 1; goto meta_command_exit; } }else{ output_file_close(p->traceOut); | | | 31540 31541 31542 31543 31544 31545 31546 31547 31548 31549 31550 31551 31552 31553 31554 | else { sqlite3_fprintf(stderr,"Unknown option \"%s\" on \".trace\"\n", z); rc = 1; goto meta_command_exit; } }else{ output_file_close(p->traceOut); p->traceOut = output_file_open(z); } } if( p->traceOut==0 ){ sqlite3_trace_v2(p->db, 0, 0, 0); }else{ if( mType==0 ) mType = SQLITE_TRACE_STMT; sqlite3_trace_v2(p->db, mType, sql_trace_callback, p); |
︙ | ︙ | |||
32359 32360 32361 32362 32363 32364 32365 32366 32367 32368 32369 32370 32371 32372 | #if !defined(SQLITE_SHELL_FIDDLE) verify_uninitialized(); #endif sqlite3_config(SQLITE_CONFIG_URI, 1); sqlite3_config(SQLITE_CONFIG_MULTITHREAD); sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> "); sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> "); } /* ** Output text to the console in a font that attracts extra attention. */ #if defined(_WIN32) || defined(WIN32) static void printBold(const char *zText){ | > > > > > > > > > > | 32430 32431 32432 32433 32434 32435 32436 32437 32438 32439 32440 32441 32442 32443 32444 32445 32446 32447 32448 32449 32450 32451 32452 32453 | #if !defined(SQLITE_SHELL_FIDDLE) verify_uninitialized(); #endif sqlite3_config(SQLITE_CONFIG_URI, 1); sqlite3_config(SQLITE_CONFIG_MULTITHREAD); sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> "); sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> "); /* By default, come up in O_BINARY mode. That way, the default output is ** the same for Windows and non-Windows systems. Use the ".crnl on" ** command to change into O_TEXT mode to do automatic NL-to-CRLF ** conversions on output for Windows. ** ** End-of-line marks on CVS output is CRLF when in .crnl is on and ** NL when .crnl is off. */ data->crnlMode = 0; } /* ** Output text to the console in a font that attracts extra attention. */ #if defined(_WIN32) || defined(WIN32) static void printBold(const char *zText){ |
︙ | ︙ |
Changes to extsrc/sqlite3.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ** the text of this file. Search for "Begin file sqlite3.h" to find the start ** of the embedded sqlite3.h header file.) Additional code files may be needed ** if you want a wrapper to interface SQLite with your choice of programming ** language. The code for the "sqlite3" command-line shell is also in a ** separate file. This file contains only code for the core SQLite library. ** ** The content in this amalgamation comes from Fossil check-in | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** the text of this file. Search for "Begin file sqlite3.h" to find the start ** of the embedded sqlite3.h header file.) Additional code files may be needed ** if you want a wrapper to interface SQLite with your choice of programming ** language. The code for the "sqlite3" command-line shell is also in a ** separate file. This file contains only code for the core SQLite library. ** ** The content in this amalgamation comes from Fossil check-in ** 2db24c5364808008fa503f37ca8ccf5d135e. */ #define SQLITE_CORE 1 #define SQLITE_AMALGAMATION 1 #ifndef SQLITE_PRIVATE # define SQLITE_PRIVATE static #endif /************** Begin file sqliteInt.h ***************************************/ |
︙ | ︙ | |||
460 461 462 463 464 465 466 | ** ** See also: [sqlite3_libversion()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ #define SQLITE_VERSION "3.47.0" #define SQLITE_VERSION_NUMBER 3047000 | | | 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | ** ** See also: [sqlite3_libversion()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ #define SQLITE_VERSION "3.47.0" #define SQLITE_VERSION_NUMBER 3047000 #define SQLITE_SOURCE_ID "2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470" /* ** CAPI3REF: Run-Time Library Version Numbers ** KEYWORDS: sqlite3_version sqlite3_sourceid ** ** These interfaces provide the same information as the [SQLITE_VERSION], ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
︙ | ︙ | |||
19228 19229 19230 19231 19232 19233 19234 | #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */ | | | 19228 19229 19230 19231 19232 19233 19234 19235 19236 19237 19238 19239 19240 19241 19242 | #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */ #define EP_SubtArg 0x80000000 /* Is argument to SQLITE_SUBTYPE function */ /* The EP_Propagate mask is a set of properties that automatically propagate ** upwards into parent nodes. */ #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc) /* Macros can be used to test, set, or clear bits in the |
︙ | ︙ | |||
41009 41010 41011 41012 41013 41014 41015 | /* ** This routine checks if there is a RESERVED lock held on the specified ** file by this or any other process. If such a lock is held, set *pResOut ** to a non-zero value otherwise *pResOut is set to zero. The return value ** is set to SQLITE_OK unless an I/O error occurs during lock checking. */ static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){ | < < < < | < | | < > > | > > | < < < < < < < > | < < < < < < < < < < < < < < < | < < > > > | < | < < | | 41009 41010 41011 41012 41013 41014 41015 41016 41017 41018 41019 41020 41021 41022 41023 41024 41025 41026 41027 41028 41029 41030 41031 41032 41033 41034 41035 41036 41037 41038 41039 41040 41041 41042 41043 41044 41045 | /* ** This routine checks if there is a RESERVED lock held on the specified ** file by this or any other process. If such a lock is held, set *pResOut ** to a non-zero value otherwise *pResOut is set to zero. The return value ** is set to SQLITE_OK unless an I/O error occurs during lock checking. */ static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){ unixFile *pFile = (unixFile*)id; SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); assert( pFile ); assert( pFile->eFileLock<=SHARED_LOCK ); /* The flock VFS only ever takes exclusive locks (see function flockLock). ** Therefore, if this connection is holding any lock at all, no other ** connection may be holding a RESERVED lock. So set *pResOut to 0 ** in this case. ** ** Or, this connection may be holding no lock. In that case, set *pResOut to ** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the ** db in order to roll the hot journal back. If there is another connection ** holding a lock, that attempt will fail and an SQLITE_BUSY returned to ** the user. With other VFS, we try to avoid this, in order to allow a reader ** to proceed while a writer is preparing its transaction. But that won't ** work with the flock VFS - as it always takes EXCLUSIVE locks - so it is ** not a problem in this case. */ *pResOut = 0; return SQLITE_OK; } /* ** Lock the file with the lock specified by parameter eFileLock - one ** of the following: ** ** (1) SHARED_LOCK |
︙ | ︙ | |||
108213 108214 108215 108216 108217 108218 108219 108220 108221 108222 108223 108224 108225 108226 | pNC->nNcErr++; } pExpr->op = TK_NULL; return WRC_Prune; } } #endif if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){ /* For the purposes of the EP_ConstFunc flag, date and time ** functions and other functions that change slowly are considered ** constant because they are constant for the duration of one query. ** This allows them to be factored out of inner loops. */ ExprSetProperty(pExpr,EP_ConstFunc); } | > > > > > > > > > > > > > > > > > > | 108188 108189 108190 108191 108192 108193 108194 108195 108196 108197 108198 108199 108200 108201 108202 108203 108204 108205 108206 108207 108208 108209 108210 108211 108212 108213 108214 108215 108216 108217 108218 108219 | pNC->nNcErr++; } pExpr->op = TK_NULL; return WRC_Prune; } } #endif /* If the function may call sqlite3_value_subtype(), then set the ** EP_SubtArg flag on all of its argument expressions. This prevents ** where.c from replacing the expression with a value read from an ** index on the same expression, which will not have the correct ** subtype. Also set the flag if the function expression itself is ** an EP_SubtArg expression. In this case subtypes are required as ** the function may return a value with a subtype back to its ** caller using sqlite3_result_value(). */ if( (pDef->funcFlags & SQLITE_SUBTYPE) || ExprHasProperty(pExpr, EP_SubtArg) ){ int ii; for(ii=0; ii<n; ii++){ ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg); } } if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){ /* For the purposes of the EP_ConstFunc flag, date and time ** functions and other functions that change slowly are considered ** constant because they are constant for the duration of one query. ** This allows them to be factored out of inner loops. */ ExprSetProperty(pExpr,EP_ConstFunc); } |
︙ | ︙ | |||
113886 113887 113888 113889 113890 113891 113892 113893 113894 113895 113896 113897 113898 113899 | (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]); break; } #endif /* !defined(SQLITE_UNTESTABLE) */ } return target; } /* ** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr. ** If it is, then resolve the expression by reading from the index and ** return the register into which the value has been read. If pExpr is ** not an indexed expression, then return negative. */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 113879 113880 113881 113882 113883 113884 113885 113886 113887 113888 113889 113890 113891 113892 113893 113894 113895 113896 113897 113898 113899 113900 113901 113902 113903 113904 113905 113906 113907 113908 113909 113910 113911 113912 113913 113914 113915 113916 113917 113918 113919 113920 113921 113922 113923 113924 113925 113926 113927 113928 113929 113930 113931 113932 113933 113934 113935 113936 113937 113938 113939 113940 113941 113942 113943 113944 113945 | (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]); break; } #endif /* !defined(SQLITE_UNTESTABLE) */ } return target; } /* ** Expression Node callback for sqlite3ExprCanReturnSubtype(). ** ** Only a function call is able to return a subtype. So if the node ** is not a function call, return WRC_Prune immediately. ** ** A function call is able to return a subtype if it has the ** SQLITE_RESULT_SUBTYPE property. ** ** Assume that every function is able to pass-through a subtype from ** one of its argument (using sqlite3_result_value()). Most functions ** are not this way, but we don't have a mechanism to distinguish those ** that are from those that are not, so assume they all work this way. ** That means that if one of its arguments is another function and that ** other function is able to return a subtype, then this function is ** able to return a subtype. */ static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){ int n; FuncDef *pDef; sqlite3 *db; if( pExpr->op!=TK_FUNCTION ){ return WRC_Prune; } assert( ExprUseXList(pExpr) ); db = pWalker->pParse->db; n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0; pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){ pWalker->eCode = 1; return WRC_Prune; } return WRC_Continue; } /* ** Return TRUE if expression pExpr is able to return a subtype. ** ** A TRUE return does not guarantee that a subtype will be returned. ** It only indicates that a subtype return is possible. False positives ** are acceptable as they only disable an optimization. False negatives, ** on the other hand, can lead to incorrect answers. */ static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){ Walker w; memset(&w, 0, sizeof(w)); w.pParse = pParse; w.xExprCallback = exprNodeCanReturnSubtype; sqlite3WalkExpr(&w, pExpr); return w.eCode; } /* ** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr. ** If it is, then resolve the expression by reading from the index and ** return the register into which the value has been read. If pExpr is ** not an indexed expression, then return negative. */ |
︙ | ︙ | |||
113919 113920 113921 113922 113923 113924 113925 113926 113927 113928 113929 113930 113931 113932 | || (exprAff==SQLITE_AFF_TEXT && p->aff!=SQLITE_AFF_TEXT) || (exprAff>=SQLITE_AFF_NUMERIC && p->aff!=SQLITE_AFF_NUMERIC) ){ /* Affinity mismatch on a generated column */ continue; } v = pParse->pVdbe; assert( v!=0 ); if( p->bMaybeNullRow ){ /* If the index is on a NULL row due to an outer join, then we ** cannot extract the value from the index. The value must be ** computed using the original expression. */ int addr = sqlite3VdbeCurrentAddr(v); | > > > > > > > > > > > | 113965 113966 113967 113968 113969 113970 113971 113972 113973 113974 113975 113976 113977 113978 113979 113980 113981 113982 113983 113984 113985 113986 113987 113988 113989 | || (exprAff==SQLITE_AFF_TEXT && p->aff!=SQLITE_AFF_TEXT) || (exprAff>=SQLITE_AFF_NUMERIC && p->aff!=SQLITE_AFF_NUMERIC) ){ /* Affinity mismatch on a generated column */ continue; } /* Functions that might set a subtype should not be replaced by the ** value taken from an expression index if they are themselves an ** argument to another scalar function or aggregate. ** https://sqlite.org/forum/forumpost/68d284c86b082c3e */ if( ExprHasProperty(pExpr, EP_SubtArg) && sqlite3ExprCanReturnSubtype(pParse, pExpr) ){ continue; } v = pParse->pVdbe; assert( v!=0 ); if( p->bMaybeNullRow ){ /* If the index is on a NULL row due to an outer join, then we ** cannot extract the value from the index. The value must be ** computed using the original expression. */ int addr = sqlite3VdbeCurrentAddr(v); |
︙ | ︙ | |||
131916 131917 131918 131919 131920 131921 131922 | WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), FUNCTION(max, -1, 1, 1, minmaxFunc ), FUNCTION(max, 0, 1, 1, 0 ), WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), | | > | 131973 131974 131975 131976 131977 131978 131979 131980 131981 131982 131983 131984 131985 131986 131987 131988 | WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), FUNCTION(max, -1, 1, 1, minmaxFunc ), FUNCTION(max, 0, 1, 1, 0 ), WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), FUNCTION2(subtype, 1, 0, 0, subtypeFunc, SQLITE_FUNC_TYPEOF|SQLITE_SUBTYPE), FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), FUNCTION2(octet_length, 1, 0, 0, bytelengthFunc,SQLITE_FUNC_BYTELEN), FUNCTION(instr, 2, 0, 0, instrFunc ), FUNCTION(printf, -1, 0, 0, printfFunc ), FUNCTION(format, -1, 0, 0, printfFunc ), FUNCTION(unicode, 1, 0, 0, unicodeFunc ), FUNCTION(char, -1, 0, 0, charFunc ), |
︙ | ︙ | |||
132022 132023 132024 132025 132026 132027 132028 | MFUNCTION(acosh, 1, acosh, math1Func ), MFUNCTION(asinh, 1, asinh, math1Func ), MFUNCTION(atanh, 1, atanh, math1Func ), #endif MFUNCTION(sqrt, 1, sqrt, math1Func ), MFUNCTION(radians, 1, degToRad, math1Func ), MFUNCTION(degrees, 1, radToDeg, math1Func ), | | | 132080 132081 132082 132083 132084 132085 132086 132087 132088 132089 132090 132091 132092 132093 132094 | MFUNCTION(acosh, 1, acosh, math1Func ), MFUNCTION(asinh, 1, asinh, math1Func ), MFUNCTION(atanh, 1, atanh, math1Func ), #endif MFUNCTION(sqrt, 1, sqrt, math1Func ), MFUNCTION(radians, 1, degToRad, math1Func ), MFUNCTION(degrees, 1, radToDeg, math1Func ), MFUNCTION(pi, 0, 0, piFunc ), #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */ FUNCTION(sign, 1, 0, 0, signFunc ), INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ), INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ), }; #ifndef SQLITE_OMIT_ALTERTABLE sqlite3AlterFunctions(); |
︙ | ︙ | |||
161395 161396 161397 161398 161399 161400 161401 | ** encoding, then only consider ASCII characters. Note that the ** encoding of z[] is UTF8 - we are dealing with only UTF8 here in ** this code, but the database engine itself might be processing ** content using a different encoding. */ cnt = 0; while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ cnt++; | | | 161453 161454 161455 161456 161457 161458 161459 161460 161461 161462 161463 161464 161465 161466 161467 | ** encoding, then only consider ASCII characters. Note that the ** encoding of z[] is UTF8 - we are dealing with only UTF8 here in ** this code, but the database engine itself might be processing ** content using a different encoding. */ cnt = 0; while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ cnt++; if( c==wc[3] && z[cnt]>0 && z[cnt]<0x80 ){ cnt++; }else if( c>=0x80 ){ const u8 *z2 = z+cnt-1; if( sqlite3Utf8Read(&z2)==0xfffd || ENC(db)==SQLITE_UTF16LE ){ cnt--; break; }else{ |
︙ | ︙ | |||
169374 169375 169376 169377 169378 169379 169380 | } } nSearch += pLoop->nOut; if( pWInfo->nOutStarDelta ) nSearch += pLoop->rStarDelta; } } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 169432 169433 169434 169435 169436 169437 169438 169439 169440 169441 169442 169443 169444 169445 | } } nSearch += pLoop->nOut; if( pWInfo->nOutStarDelta ) nSearch += pLoop->rStarDelta; } } /* ** The index pIdx is used by a query and contains one or more expressions. ** In other words pIdx is an index on an expression. iIdxCur is the cursor ** number for the index and iDataCur is the cursor number for the corresponding ** table. ** ** This routine adds IndexedExpr entries to the Parse->pIdxEpr field for |
︙ | ︙ | |||
169459 169460 169461 169462 169463 169464 169465 | pExpr = pIdx->aColExpr->a[i].pExpr; }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); }else{ continue; } if( sqlite3ExprIsConstant(0,pExpr) ) continue; | < < < < < < | 169465 169466 169467 169468 169469 169470 169471 169472 169473 169474 169475 169476 169477 169478 | pExpr = pIdx->aColExpr->a[i].pExpr; }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); }else{ continue; } if( sqlite3ExprIsConstant(0,pExpr) ) continue; p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr)); if( p==0 ) break; p->pIENext = pParse->pIdxEpr; #ifdef WHERETRACE_ENABLED if( sqlite3WhereTrace & 0x200 ){ sqlite3DebugPrintf("New pParse->pIdxEpr term {%d,%d}\n", iIdxCur, i); if( sqlite3WhereTrace & 0x5000 ) sqlite3ShowExpr(pExpr); |
︙ | ︙ | |||
254847 254848 254849 254850 254851 254852 254853 | static void fts5SourceIdFunc( sqlite3_context *pCtx, /* Function call context */ int nArg, /* Number of args */ sqlite3_value **apUnused /* Function arguments */ ){ assert( nArg==0 ); UNUSED_PARAM2(nArg, apUnused); | | | 254847 254848 254849 254850 254851 254852 254853 254854 254855 254856 254857 254858 254859 254860 254861 | static void fts5SourceIdFunc( sqlite3_context *pCtx, /* Function call context */ int nArg, /* Number of args */ sqlite3_value **apUnused /* Function arguments */ ){ assert( nArg==0 ); UNUSED_PARAM2(nArg, apUnused); sqlite3_result_text(pCtx, "fts5: 2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470", -1, SQLITE_TRANSIENT); } /* ** Implementation of fts5_locale(LOCALE, TEXT) function. ** ** If parameter LOCALE is NULL, or a zero-length string, then a copy of ** TEXT is returned. Otherwise, both LOCALE and TEXT are interpreted as |
︙ | ︙ |
Changes to extsrc/sqlite3.h.
︙ | ︙ | |||
144 145 146 147 148 149 150 | ** ** See also: [sqlite3_libversion()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ #define SQLITE_VERSION "3.47.0" #define SQLITE_VERSION_NUMBER 3047000 | | | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | ** ** See also: [sqlite3_libversion()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ #define SQLITE_VERSION "3.47.0" #define SQLITE_VERSION_NUMBER 3047000 #define SQLITE_SOURCE_ID "2024-10-11 23:31:37 2db24c5364808008fa503f37ca8ccf5d135e8f6bfac2efb29e509e26f7190470" /* ** CAPI3REF: Run-Time Library Version Numbers ** KEYWORDS: sqlite3_version sqlite3_sourceid ** ** These interfaces provide the same information as the [SQLITE_VERSION], ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
︙ | ︙ |