@@ -1499,7 +1499,7 @@ static void sha3QueryFunc(
14991499
15001500
15011501#ifdef _WIN32
1502- __declspec( dllexport )
1502+
15031503#endif
15041504int sqlite3_shathree_init (
15051505 sqlite3 * db ,
@@ -1611,7 +1611,7 @@ static void writefileFunc(
16111611
16121612
16131613#ifdef _WIN32
1614- __declspec( dllexport )
1614+
16151615#endif
16161616int sqlite3_fileio_init (
16171617 sqlite3 * db ,
@@ -2139,7 +2139,7 @@ int sqlite3CompletionVtabInit(sqlite3 *db){
21392139}
21402140
21412141#ifdef _WIN32
2142- __declspec( dllexport )
2142+
21432143#endif
21442144int sqlite3_completion_init (
21452145 sqlite3 * db ,
@@ -2231,14 +2231,13 @@ struct ShellState {
22312231/*
22322232** These are the allowed shellFlgs values
22332233*/
2234- #define SHFLG_Scratch 0x00000001 /* The --scratch option is used */
2235- #define SHFLG_Pagecache 0x00000002 /* The --pagecache option is used */
2236- #define SHFLG_Lookaside 0x00000004 /* Lookaside memory is used */
2237- #define SHFLG_Backslash 0x00000008 /* The --backslash option is used */
2238- #define SHFLG_PreserveRowid 0x00000010 /* .dump preserves rowid values */
2239- #define SHFLG_Newlines 0x00000020 /* .dump --newline flag */
2240- #define SHFLG_CountChanges 0x00000040 /* .changes setting */
2241- #define SHFLG_Echo 0x00000080 /* .echo or --echo setting */
2234+ #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
2235+ #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
2236+ #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
2237+ #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
2238+ #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
2239+ #define SHFLG_CountChanges 0x00000020 /* .changes setting */
2240+ #define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
22422241
22432242/*
22442243** Macros for testing and setting shellFlgs
@@ -2659,6 +2658,7 @@ static int shell_callback(
26592658 int i ;
26602659 ShellState * p = (ShellState * )pArg ;
26612660
2661+ if ( azArg == 0 ) return 0 ;
26622662 switch ( p -> cMode ){
26632663 case MODE_Line : {
26642664 int w = 5 ;
@@ -2773,6 +2773,7 @@ static int shell_callback(
27732773 for (i = 0 ; IsSpace (z [i ]); i ++ ){}
27742774 for (; (c = z [i ])!= 0 ; i ++ ){
27752775 if ( IsSpace (c ) ){
2776+ if ( z [j - 1 ]== '\r' ) z [j - 1 ] = '\n' ;
27762777 if ( IsSpace (z [j - 1 ]) || z [j - 1 ]== '(' ) continue ;
27772778 }else if ( (c == '(' || c == ')' ) && j > 0 && IsSpace (z [j - 1 ]) ){
27782779 j -- ;
@@ -3009,6 +3010,7 @@ static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
30093010 ShellText * p = (ShellText * )pArg ;
30103011 int i ;
30113012 UNUSED_PARAMETER (az );
3013+ if ( azArg == 0 ) return 0 ;
30123014 if ( p -> n ) appendText (p , "|" , 0 );
30133015 for (i = 0 ; i < nArg ; i ++ ){
30143016 if ( i ) appendText (p , "," , 0 );
@@ -3073,7 +3075,7 @@ static void createSelftestTable(ShellState *p){
30733075*/
30743076static void set_table_name (ShellState * p , const char * zName ){
30753077 int i , n ;
3076- int cQuote ;
3078+ char cQuote ;
30773079 char * z ;
30783080
30793081 if ( p -> zDestTable ){
@@ -3255,18 +3257,10 @@ static int display_stats(
32553257 }
32563258 displayStatLine (pArg , "Number of Pcache Overflow Bytes:" ,
32573259 "%lld (max %lld) bytes" , SQLITE_STATUS_PAGECACHE_OVERFLOW , bReset );
3258- if ( pArg -> shellFlgs & SHFLG_Scratch ){
3259- displayStatLine (pArg , "Number of Scratch Allocations Used:" ,
3260- "%lld (max %lld)" , SQLITE_STATUS_SCRATCH_USED , bReset );
3261- }
3262- displayStatLine (pArg , "Number of Scratch Overflow Bytes:" ,
3263- "%lld (max %lld) bytes" , SQLITE_STATUS_SCRATCH_OVERFLOW , bReset );
32643260 displayStatLine (pArg , "Largest Allocation:" ,
32653261 "%lld bytes" , SQLITE_STATUS_MALLOC_SIZE , bReset );
32663262 displayStatLine (pArg , "Largest Pcache Allocation:" ,
32673263 "%lld bytes" , SQLITE_STATUS_PAGECACHE_SIZE , bReset );
3268- displayStatLine (pArg , "Largest Scratch Allocation:" ,
3269- "%lld bytes" , SQLITE_STATUS_SCRATCH_SIZE , bReset );
32703264#ifdef YYTRACKMAXSTACKDEPTH
32713265 displayStatLine (pArg , "Deepest Parser Stack:" ,
32723266 "%lld (max %lld)" , SQLITE_STATUS_PARSER_STACK , bReset );
@@ -3807,6 +3801,7 @@ static char **tableColumnList(ShellState *p, const char *zTab){
38073801 }
38083802 }
38093803 sqlite3_finalize (pStmt );
3804+ if ( azCol == 0 ) return 0 ;
38103805 azCol [0 ] = 0 ;
38113806 azCol [nCol + 1 ] = 0 ;
38123807
@@ -3890,7 +3885,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){
38903885 ShellState * p = (ShellState * )pArg ;
38913886
38923887 UNUSED_PARAMETER (azNotUsed );
3893- if ( nArg != 3 ) return 1 ;
3888+ if ( nArg != 3 || azArg == 0 ) return 0 ;
38943889 zTable = azArg [0 ];
38953890 zType = azArg [1 ];
38963891 zSql = azArg [2 ];
@@ -4976,20 +4971,24 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
49764971 { "schema size:" ,
49774972 "SELECT total(length(sql)) FROM %s" },
49784973 };
4979- sqlite3_file * pFile = 0 ;
49804974 int i ;
49814975 char * zSchemaTab ;
49824976 char * zDb = nArg >=2 ? azArg [1 ] : "main" ;
4977+ sqlite3_stmt * pStmt = 0 ;
49834978 unsigned char aHdr [100 ];
49844979 open_db (p , 0 );
49854980 if ( p -> db == 0 ) return 1 ;
4986- sqlite3_file_control (p -> db , zDb , SQLITE_FCNTL_FILE_POINTER , & pFile );
4987- if ( pFile == 0 || pFile -> pMethods == 0 || pFile -> pMethods -> xRead == 0 ){
4988- return 1 ;
4989- }
4990- i = pFile -> pMethods -> xRead (pFile , aHdr , 100 , 0 );
4991- if ( i != SQLITE_OK ){
4981+ sqlite3_prepare_v2 (p -> db ,"SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1" ,
4982+ -1 , & pStmt , 0 );
4983+ sqlite3_bind_text (pStmt , 1 , zDb , -1 , SQLITE_STATIC );
4984+ if ( sqlite3_step (pStmt )== SQLITE_ROW
4985+ && sqlite3_column_bytes (pStmt ,0 )> 100
4986+ ){
4987+ memcpy (aHdr , sqlite3_column_blob (pStmt ,0 ), 100 );
4988+ sqlite3_finalize (pStmt );
4989+ }else {
49924990 raw_printf (stderr , "unable to read database header\n" );
4991+ sqlite3_finalize (pStmt );
49934992 return 1 ;
49944993 }
49954994 i = get2byteInt (aHdr + 16 );
@@ -5609,7 +5608,7 @@ static int do_meta_command(char *zLine, ShellState *p){
56095608 utf8_printf (stderr ,
56105609 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n" ,
56115610 p -> zTestcase , azArg [1 ], zRes );
5612- rc = 2 ;
5611+ rc = 1 ;
56135612 }else {
56145613 utf8_printf (stdout , "testcase-%s ok\n" , p -> zTestcase );
56155614 p -> nCheck ++ ;
@@ -7287,7 +7286,6 @@ static int do_meta_command(char *zLine, ShellState *p){
72877286 { "reserve" , SQLITE_TESTCTRL_RESERVE },
72887287 { "optimizations" , SQLITE_TESTCTRL_OPTIMIZATIONS },
72897288 { "iskeyword" , SQLITE_TESTCTRL_ISKEYWORD },
7290- { "scratchmalloc" , SQLITE_TESTCTRL_SCRATCHMALLOC },
72917289 { "byteorder" , SQLITE_TESTCTRL_BYTEORDER },
72927290 { "never_corrupt" , SQLITE_TESTCTRL_NEVER_CORRUPT },
72937291 { "imposter" , SQLITE_TESTCTRL_IMPOSTER },
@@ -7400,7 +7398,6 @@ static int do_meta_command(char *zLine, ShellState *p){
74007398 case SQLITE_TESTCTRL_BITVEC_TEST :
74017399 case SQLITE_TESTCTRL_FAULT_INSTALL :
74027400 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS :
7403- case SQLITE_TESTCTRL_SCRATCHMALLOC :
74047401 default :
74057402 utf8_printf (stderr ,
74067403 "Error: CLI support for testctrl %s not implemented\n" ,
@@ -7920,7 +7917,6 @@ static const char zOptions[] =
79207917 " -nullvalue TEXT set text string for NULL values. Default ''\n"
79217918 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
79227919 " -quote set output mode to 'quote'\n"
7923- " -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
79247920 " -separator SEP set output column separator. Default: '|'\n"
79257921 " -stats print memory stats before each finalize\n"
79267922 " -version show SQLite version\n"
@@ -8023,7 +8019,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
80238019 stdout_is_console = isatty (1 );
80248020
80258021#if USE_SYSTEM_SQLITE + 0 != 1
8026- if ( strcmp (sqlite3_sourceid (),SQLITE_SOURCE_ID )!= 0 ){
8022+ if ( strncmp (sqlite3_sourceid (),SQLITE_SOURCE_ID , 60 )!= 0 ){
80278023 utf8_printf (stderr , "SQLite header and source version mismatch\n%s\n%s\n" ,
80288024 sqlite3_sourceid (), SQLITE_SOURCE_ID );
80298025 exit (1 );
@@ -8118,16 +8114,6 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
81188114#else
81198115 (void )cmdline_option_value (argc , argv , ++ i );
81208116#endif
8121- }else if ( strcmp (z ,"-scratch" )== 0 ){
8122- int n , sz ;
8123- sz = (int )integerValue (cmdline_option_value (argc ,argv ,++ i ));
8124- if ( sz > 400000 ) sz = 400000 ;
8125- if ( sz < 2500 ) sz = 2500 ;
8126- n = (int )integerValue (cmdline_option_value (argc ,argv ,++ i ));
8127- if ( n > 10 ) n = 10 ;
8128- if ( n < 1 ) n = 1 ;
8129- sqlite3_config (SQLITE_CONFIG_SCRATCH , malloc (n * sz + 1 ), sz , n );
8130- data .shellFlgs |= SHFLG_Scratch ;
81318117 }else if ( strcmp (z ,"-pagecache" )== 0 ){
81328118 int n , sz ;
81338119 sz = (int )integerValue (cmdline_option_value (argc ,argv ,++ i ));
@@ -8271,8 +8257,6 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
82718257 stdin_is_interactive = 0 ;
82728258 }else if ( strcmp (z ,"-heap" )== 0 ){
82738259 i ++ ;
8274- }else if ( strcmp (z ,"-scratch" )== 0 ){
8275- i += 2 ;
82768260 }else if ( strcmp (z ,"-pagecache" )== 0 ){
82778261 i += 2 ;
82788262 }else if ( strcmp (z ,"-lookaside" )== 0 ){
0 commit comments