├── README ├── shell.c ├── sqlite3.c ├── sqlite3.h └── sqlite3ext.h /README: -------------------------------------------------------------------------------- 1 | *** ABOUT SQLITE3-DBX *** 2 | 3 | SQLite 3 has database encryption support, but this seems to be not publicly available as explained below: 4 | http://www.sqlite.org/see/doc/trunk/www/readme.wiki 5 | 6 | However a Google search for "7bb07b8d471d642e" magic reveals that part of the source code is available from SQLite Web site: 7 | http://www.sqlite.org/slt/vpatch?from=10318b880cb756b2&to=1d627f5850e271cf (encryption added) 8 | http://www.sqlite.org/slt/vpatch?from=1d627f5850e271cf&to=f85e9769888f9e76 (encryption removed) 9 | http://www.sqlite.org/sqllogictest/ci/f85e9769888f9e762ef3c8d2f18121ea8307b433?sbs=1 10 | 11 | This project is based on the following SQLite version: 12 | VERSION: 3.7.0 13 | SOURCE ID: 2010-07-02 19:04:59 336ce7d29767f76c4a92aa4bbc46d21e19871667 14 | 15 | *** COMPILATION: 16 | 17 | No Makefile is provided. Compilation (in debug mode) is as easy as: 18 | $ gcc -o sqlite3 -I. -DSQLITE_HAS_CODEC -DHAVE_READLINE shell.c sqlite3.c -Wall -ggdb -ldl -lpthread -lreadline -lncurses 19 | 20 | Tested & supported platforms are: 21 | * Linux (Ubuntu 10.04 x86) 22 | * Windows (Cygwin) 23 | * Mac OS X (10.7) 24 | 25 | WARNING: on recent Ubuntu versions, GCC command-line arguments ordering matters. 26 | 27 | "The --as-needed option also makes the linker sensitive to the ordering of libraries on the command-line." 28 | https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition#How_to_Fix_a_Problem 29 | 30 | *** USAGE: 31 | 32 | ./sqlite3 -key 0123456789ABCDEF0123456789ABCDEF file.dbx 33 | 34 | Note: key length is only limited by 'int' implementation size. 35 | 36 | *** KNOWN LIMITATIONS: 37 | 38 | * Encryption key put into ~/.sqliterc file will NOT be taken into account. 39 | 40 | * ".backup" and ".restore" meta commands will NOT encrypt the /other/ database (would be easy to implement anyway). 41 | 42 | * Rekeying is supported by the API, but not implemented (yet). 43 | 44 | *** EOT -------------------------------------------------------------------------------- /shell.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2001 September 15 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This file contains code to implement the "sqlite" command line 13 | ** utility for accessing SQLite databases. 14 | */ 15 | 16 | #if defined(_WIN32) || defined(WIN32) 17 | /* This needs to come before any includes for MSVC compiler */ 18 | #define _CRT_SECURE_NO_WARNINGS 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "sqlite3.h" 26 | #include 27 | #include 28 | 29 | #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) 30 | # include 31 | # if !defined(__RTP__) && !defined(_WRS_KERNEL) 32 | # include 33 | # endif 34 | # include 35 | # include 36 | #endif 37 | 38 | #ifdef __OS2__ 39 | # include 40 | #endif 41 | 42 | #if defined(HAVE_READLINE) && HAVE_READLINE==1 43 | # include 44 | # include 45 | #else 46 | # define readline(p) local_getline(p,stdin) 47 | # define add_history(X) 48 | # define read_history(X) 49 | # define write_history(X) 50 | # define stifle_history(X) 51 | #endif 52 | 53 | #if defined(_WIN32) || defined(WIN32) 54 | # include 55 | #define isatty(h) _isatty(h) 56 | #define access(f,m) _access((f),(m)) 57 | #else 58 | /* Make sure isatty() has a prototype. 59 | */ 60 | extern int isatty(); 61 | #endif 62 | 63 | #if defined(_WIN32_WCE) 64 | /* Windows CE (arm-wince-mingw32ce-gcc) does not provide isatty() 65 | * thus we always assume that we have a console. That can be 66 | * overridden with the -batch command line option. 67 | */ 68 | #define isatty(x) 1 69 | #endif 70 | 71 | #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL) 72 | #include 73 | #include 74 | 75 | /* Saved resource information for the beginning of an operation */ 76 | static struct rusage sBegin; 77 | 78 | /* True if the timer is enabled */ 79 | static int enableTimer = 0; 80 | 81 | #ifdef SQLITE_HAS_CODEC 82 | /* Database encryption support 83 | * Types were defined according to sqlite3_key() prototype. 84 | */ 85 | static void *encryption_key = NULL; 86 | static int encryption_key_length = 0; 87 | #endif 88 | 89 | /* 90 | ** Begin timing an operation 91 | */ 92 | static void beginTimer(void){ 93 | if( enableTimer ){ 94 | getrusage(RUSAGE_SELF, &sBegin); 95 | } 96 | } 97 | 98 | /* Return the difference of two time_structs in seconds */ 99 | static double timeDiff(struct timeval *pStart, struct timeval *pEnd){ 100 | return (pEnd->tv_usec - pStart->tv_usec)*0.000001 + 101 | (double)(pEnd->tv_sec - pStart->tv_sec); 102 | } 103 | 104 | /* 105 | ** Print the timing results. 106 | */ 107 | static void endTimer(void){ 108 | if( enableTimer ){ 109 | struct rusage sEnd; 110 | getrusage(RUSAGE_SELF, &sEnd); 111 | printf("CPU Time: user %f sys %f\n", 112 | timeDiff(&sBegin.ru_utime, &sEnd.ru_utime), 113 | timeDiff(&sBegin.ru_stime, &sEnd.ru_stime)); 114 | } 115 | } 116 | 117 | #define BEGIN_TIMER beginTimer() 118 | #define END_TIMER endTimer() 119 | #define HAS_TIMER 1 120 | 121 | #elif (defined(_WIN32) || defined(WIN32)) 122 | 123 | #include 124 | 125 | /* Saved resource information for the beginning of an operation */ 126 | static HANDLE hProcess; 127 | static FILETIME ftKernelBegin; 128 | static FILETIME ftUserBegin; 129 | typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME); 130 | static GETPROCTIMES getProcessTimesAddr = NULL; 131 | 132 | /* True if the timer is enabled */ 133 | static int enableTimer = 0; 134 | 135 | /* 136 | ** Check to see if we have timer support. Return 1 if necessary 137 | ** support found (or found previously). 138 | */ 139 | static int hasTimer(void){ 140 | if( getProcessTimesAddr ){ 141 | return 1; 142 | } else { 143 | /* GetProcessTimes() isn't supported in WIN95 and some other Windows versions. 144 | ** See if the version we are running on has it, and if it does, save off 145 | ** a pointer to it and the current process handle. 146 | */ 147 | hProcess = GetCurrentProcess(); 148 | if( hProcess ){ 149 | HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll")); 150 | if( NULL != hinstLib ){ 151 | getProcessTimesAddr = (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes"); 152 | if( NULL != getProcessTimesAddr ){ 153 | return 1; 154 | } 155 | FreeLibrary(hinstLib); 156 | } 157 | } 158 | } 159 | return 0; 160 | } 161 | 162 | /* 163 | ** Begin timing an operation 164 | */ 165 | static void beginTimer(void){ 166 | if( enableTimer && getProcessTimesAddr ){ 167 | FILETIME ftCreation, ftExit; 168 | getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin); 169 | } 170 | } 171 | 172 | /* Return the difference of two FILETIME structs in seconds */ 173 | static double timeDiff(FILETIME *pStart, FILETIME *pEnd){ 174 | sqlite_int64 i64Start = *((sqlite_int64 *) pStart); 175 | sqlite_int64 i64End = *((sqlite_int64 *) pEnd); 176 | return (double) ((i64End - i64Start) / 10000000.0); 177 | } 178 | 179 | /* 180 | ** Print the timing results. 181 | */ 182 | static void endTimer(void){ 183 | if( enableTimer && getProcessTimesAddr){ 184 | FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd; 185 | getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd); 186 | printf("CPU Time: user %f sys %f\n", 187 | timeDiff(&ftUserBegin, &ftUserEnd), 188 | timeDiff(&ftKernelBegin, &ftKernelEnd)); 189 | } 190 | } 191 | 192 | #define BEGIN_TIMER beginTimer() 193 | #define END_TIMER endTimer() 194 | #define HAS_TIMER hasTimer() 195 | 196 | #else 197 | #define BEGIN_TIMER 198 | #define END_TIMER 199 | #define HAS_TIMER 0 200 | #endif 201 | 202 | /* 203 | ** Used to prevent warnings about unused parameters 204 | */ 205 | #define UNUSED_PARAMETER(x) (void)(x) 206 | 207 | /* 208 | ** If the following flag is set, then command execution stops 209 | ** at an error if we are not interactive. 210 | */ 211 | static int bail_on_error = 0; 212 | 213 | /* 214 | ** Threat stdin as an interactive input if the following variable 215 | ** is true. Otherwise, assume stdin is connected to a file or pipe. 216 | */ 217 | static int stdin_is_interactive = 1; 218 | 219 | /* 220 | ** The following is the open SQLite database. We make a pointer 221 | ** to this database a static variable so that it can be accessed 222 | ** by the SIGINT handler to interrupt database processing. 223 | */ 224 | static sqlite3 *db = 0; 225 | 226 | /* 227 | ** True if an interrupt (Control-C) has been received. 228 | */ 229 | static volatile int seenInterrupt = 0; 230 | 231 | /* 232 | ** This is the name of our program. It is set in main(), used 233 | ** in a number of other places, mostly for error messages. 234 | */ 235 | static char *Argv0; 236 | 237 | /* 238 | ** Prompt strings. Initialized in main. Settable with 239 | ** .prompt main continue 240 | */ 241 | static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/ 242 | static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */ 243 | 244 | /* 245 | ** Write I/O traces to the following stream. 246 | */ 247 | #ifdef SQLITE_ENABLE_IOTRACE 248 | static FILE *iotrace = 0; 249 | #endif 250 | 251 | /* 252 | ** This routine works like printf in that its first argument is a 253 | ** format string and subsequent arguments are values to be substituted 254 | ** in place of % fields. The result of formatting this string 255 | ** is written to iotrace. 256 | */ 257 | #ifdef SQLITE_ENABLE_IOTRACE 258 | static void iotracePrintf(const char *zFormat, ...){ 259 | va_list ap; 260 | char *z; 261 | if( iotrace==0 ) return; 262 | va_start(ap, zFormat); 263 | z = sqlite3_vmprintf(zFormat, ap); 264 | va_end(ap); 265 | fprintf(iotrace, "%s", z); 266 | sqlite3_free(z); 267 | } 268 | #endif 269 | 270 | 271 | /* 272 | ** Determines if a string is a number of not. 273 | */ 274 | static int isNumber(const char *z, int *realnum){ 275 | if( *z=='-' || *z=='+' ) z++; 276 | if( !isdigit(*z) ){ 277 | return 0; 278 | } 279 | z++; 280 | if( realnum ) *realnum = 0; 281 | while( isdigit(*z) ){ z++; } 282 | if( *z=='.' ){ 283 | z++; 284 | if( !isdigit(*z) ) return 0; 285 | while( isdigit(*z) ){ z++; } 286 | if( realnum ) *realnum = 1; 287 | } 288 | if( *z=='e' || *z=='E' ){ 289 | z++; 290 | if( *z=='+' || *z=='-' ) z++; 291 | if( !isdigit(*z) ) return 0; 292 | while( isdigit(*z) ){ z++; } 293 | if( realnum ) *realnum = 1; 294 | } 295 | return *z==0; 296 | } 297 | 298 | /* 299 | ** A global char* and an SQL function to access its current value 300 | ** from within an SQL statement. This program used to use the 301 | ** sqlite_exec_printf() API to substitue a string into an SQL statement. 302 | ** The correct way to do this with sqlite3 is to use the bind API, but 303 | ** since the shell is built around the callback paradigm it would be a lot 304 | ** of work. Instead just use this hack, which is quite harmless. 305 | */ 306 | static const char *zShellStatic = 0; 307 | static void shellstaticFunc( 308 | sqlite3_context *context, 309 | int argc, 310 | sqlite3_value **argv 311 | ){ 312 | assert( 0==argc ); 313 | assert( zShellStatic ); 314 | UNUSED_PARAMETER(argc); 315 | UNUSED_PARAMETER(argv); 316 | sqlite3_result_text(context, zShellStatic, -1, SQLITE_STATIC); 317 | } 318 | 319 | 320 | /* 321 | ** This routine reads a line of text from FILE in, stores 322 | ** the text in memory obtained from malloc() and returns a pointer 323 | ** to the text. NULL is returned at end of file, or if malloc() 324 | ** fails. 325 | ** 326 | ** The interface is like "readline" but no command-line editing 327 | ** is done. 328 | */ 329 | static char *local_getline(char *zPrompt, FILE *in){ 330 | char *zLine; 331 | int nLine; 332 | int n; 333 | int eol; 334 | 335 | if( zPrompt && *zPrompt ){ 336 | printf("%s",zPrompt); 337 | fflush(stdout); 338 | } 339 | nLine = 100; 340 | zLine = malloc( nLine ); 341 | if( zLine==0 ) return 0; 342 | n = 0; 343 | eol = 0; 344 | while( !eol ){ 345 | if( n+100>nLine ){ 346 | nLine = nLine*2 + 100; 347 | zLine = realloc(zLine, nLine); 348 | if( zLine==0 ) return 0; 349 | } 350 | if( fgets(&zLine[n], nLine - n, in)==0 ){ 351 | if( n==0 ){ 352 | free(zLine); 353 | return 0; 354 | } 355 | zLine[n] = 0; 356 | eol = 1; 357 | break; 358 | } 359 | while( zLine[n] ){ n++; } 360 | if( n>0 && zLine[n-1]=='\n' ){ 361 | n--; 362 | if( n>0 && zLine[n-1]=='\r' ) n--; 363 | zLine[n] = 0; 364 | eol = 1; 365 | } 366 | } 367 | zLine = realloc( zLine, n+1 ); 368 | return zLine; 369 | } 370 | 371 | /* 372 | ** Retrieve a single line of input text. 373 | ** 374 | ** zPrior is a string of prior text retrieved. If not the empty 375 | ** string, then issue a continuation prompt. 376 | */ 377 | static char *one_input_line(const char *zPrior, FILE *in){ 378 | char *zPrompt; 379 | char *zResult; 380 | if( in!=0 ){ 381 | return local_getline(0, in); 382 | } 383 | if( zPrior && zPrior[0] ){ 384 | zPrompt = continuePrompt; 385 | }else{ 386 | zPrompt = mainPrompt; 387 | } 388 | zResult = readline(zPrompt); 389 | #if defined(HAVE_READLINE) && HAVE_READLINE==1 390 | if( zResult && *zResult ) add_history(zResult); 391 | #endif 392 | return zResult; 393 | } 394 | 395 | struct previous_mode_data { 396 | int valid; /* Is there legit data in here? */ 397 | int mode; 398 | int showHeader; 399 | int colWidth[100]; 400 | }; 401 | 402 | /* 403 | ** An pointer to an instance of this structure is passed from 404 | ** the main program to the callback. This is used to communicate 405 | ** state and mode information. 406 | */ 407 | struct callback_data { 408 | sqlite3 *db; /* The database */ 409 | int echoOn; /* True to echo input commands */ 410 | int cnt; /* Number of records displayed so far */ 411 | FILE *out; /* Write results here */ 412 | int mode; /* An output mode setting */ 413 | int writableSchema; /* True if PRAGMA writable_schema=ON */ 414 | int showHeader; /* True to show column names in List or Column mode */ 415 | char *zDestTable; /* Name of destination table when MODE_Insert */ 416 | char separator[20]; /* Separator character for MODE_List */ 417 | int colWidth[100]; /* Requested width of each column when in column mode*/ 418 | int actualWidth[100]; /* Actual width of each column */ 419 | char nullvalue[20]; /* The text to print when a NULL comes back from 420 | ** the database */ 421 | struct previous_mode_data explainPrev; 422 | /* Holds the mode information just before 423 | ** .explain ON */ 424 | char outfile[FILENAME_MAX]; /* Filename for *out */ 425 | const char *zDbFilename; /* name of the database file */ 426 | sqlite3_stmt *pStmt; /* Current statement if any. */ 427 | FILE *pLog; /* Write log output here */ 428 | }; 429 | 430 | /* 431 | ** These are the allowed modes. 432 | */ 433 | #define MODE_Line 0 /* One column per line. Blank line between records */ 434 | #define MODE_Column 1 /* One record per line in neat columns */ 435 | #define MODE_List 2 /* One record per line with a separator */ 436 | #define MODE_Semi 3 /* Same as MODE_List but append ";" to each line */ 437 | #define MODE_Html 4 /* Generate an XHTML table */ 438 | #define MODE_Insert 5 /* Generate SQL "insert" statements */ 439 | #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */ 440 | #define MODE_Csv 7 /* Quote strings, numbers are plain */ 441 | #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */ 442 | 443 | static const char *modeDescr[] = { 444 | "line", 445 | "column", 446 | "list", 447 | "semi", 448 | "html", 449 | "insert", 450 | "tcl", 451 | "csv", 452 | "explain", 453 | }; 454 | 455 | /* 456 | ** Number of elements in an array 457 | */ 458 | #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0])) 459 | 460 | /* 461 | ** Compute a string length that is limited to what can be stored in 462 | ** lower 30 bits of a 32-bit signed integer. 463 | */ 464 | static int strlen30(const char *z){ 465 | const char *z2 = z; 466 | while( *z2 ){ z2++; } 467 | return 0x3fffffff & (int)(z2 - z); 468 | } 469 | 470 | /* 471 | ** A callback for the sqlite3_log() interface. 472 | */ 473 | static void shellLog(void *pArg, int iErrCode, const char *zMsg){ 474 | struct callback_data *p = (struct callback_data*)pArg; 475 | if( p->pLog==0 ) return; 476 | fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg); 477 | fflush(p->pLog); 478 | } 479 | 480 | /* 481 | ** Output the given string as a hex-encoded blob (eg. X'1234' ) 482 | */ 483 | static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){ 484 | int i; 485 | char *zBlob = (char *)pBlob; 486 | fprintf(out,"X'"); 487 | for(i=0; i0 ){ 564 | fprintf(out,"%.*s",i,z); 565 | } 566 | if( z[i]=='<' ){ 567 | fprintf(out,"<"); 568 | }else if( z[i]=='&' ){ 569 | fprintf(out,"&"); 570 | }else if( z[i]=='>' ){ 571 | fprintf(out,">"); 572 | }else if( z[i]=='\"' ){ 573 | fprintf(out,"""); 574 | }else if( z[i]=='\'' ){ 575 | fprintf(out,"'"); 576 | }else{ 577 | break; 578 | } 579 | z += i + 1; 580 | } 581 | } 582 | 583 | /* 584 | ** If a field contains any character identified by a 1 in the following 585 | ** array, then the string must be quoted for CSV. 586 | */ 587 | static const char needCsvQuote[] = { 588 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 589 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 590 | 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 591 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 592 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 593 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 594 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 595 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 596 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 597 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 598 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 599 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 600 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 601 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 602 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 603 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 604 | }; 605 | 606 | /* 607 | ** Output a single term of CSV. Actually, p->separator is used for 608 | ** the separator, which may or may not be a comma. p->nullvalue is 609 | ** the null value. Strings are quoted using ANSI-C rules. Numbers 610 | ** appear outside of quotes. 611 | */ 612 | static void output_csv(struct callback_data *p, const char *z, int bSep){ 613 | FILE *out = p->out; 614 | if( z==0 ){ 615 | fprintf(out,"%s",p->nullvalue); 616 | }else{ 617 | int i; 618 | int nSep = strlen30(p->separator); 619 | for(i=0; z[i]; i++){ 620 | if( needCsvQuote[((unsigned char*)z)[i]] 621 | || (z[i]==p->separator[0] && 622 | (nSep==1 || memcmp(z, p->separator, nSep)==0)) ){ 623 | i = 0; 624 | break; 625 | } 626 | } 627 | if( i==0 ){ 628 | putc('"', out); 629 | for(i=0; z[i]; i++){ 630 | if( z[i]=='"' ) putc('"', out); 631 | putc(z[i], out); 632 | } 633 | putc('"', out); 634 | }else{ 635 | fprintf(out, "%s", z); 636 | } 637 | } 638 | if( bSep ){ 639 | fprintf(p->out, "%s", p->separator); 640 | } 641 | } 642 | 643 | #ifdef SIGINT 644 | /* 645 | ** This routine runs when the user presses Ctrl-C 646 | */ 647 | static void interrupt_handler(int NotUsed){ 648 | UNUSED_PARAMETER(NotUsed); 649 | seenInterrupt = 1; 650 | if( db ) sqlite3_interrupt(db); 651 | } 652 | #endif 653 | 654 | /* 655 | ** This is the callback routine that the shell 656 | ** invokes for each row of a query result. 657 | */ 658 | static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType){ 659 | int i; 660 | struct callback_data *p = (struct callback_data*)pArg; 661 | 662 | switch( p->mode ){ 663 | case MODE_Line: { 664 | int w = 5; 665 | if( azArg==0 ) break; 666 | for(i=0; iw ) w = len; 669 | } 670 | if( p->cnt++>0 ) fprintf(p->out,"\n"); 671 | for(i=0; iout,"%*s = %s\n", w, azCol[i], 673 | azArg[i] ? azArg[i] : p->nullvalue); 674 | } 675 | break; 676 | } 677 | case MODE_Explain: 678 | case MODE_Column: { 679 | if( p->cnt++==0 ){ 680 | for(i=0; icolWidth) ){ 683 | w = p->colWidth[i]; 684 | }else{ 685 | w = 0; 686 | } 687 | if( w<=0 ){ 688 | w = strlen30(azCol[i] ? azCol[i] : ""); 689 | if( w<10 ) w = 10; 690 | n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue); 691 | if( wactualWidth) ){ 694 | p->actualWidth[i] = w; 695 | } 696 | if( p->showHeader ){ 697 | fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " "); 698 | } 699 | } 700 | if( p->showHeader ){ 701 | for(i=0; iactualWidth) ){ 704 | w = p->actualWidth[i]; 705 | }else{ 706 | w = 10; 707 | } 708 | fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------" 709 | "----------------------------------------------------------", 710 | i==nArg-1 ? "\n": " "); 711 | } 712 | } 713 | } 714 | if( azArg==0 ) break; 715 | for(i=0; iactualWidth) ){ 718 | w = p->actualWidth[i]; 719 | }else{ 720 | w = 10; 721 | } 722 | if( p->mode==MODE_Explain && azArg[i] && 723 | strlen30(azArg[i])>w ){ 724 | w = strlen30(azArg[i]); 725 | } 726 | fprintf(p->out,"%-*.*s%s",w,w, 727 | azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " "); 728 | } 729 | break; 730 | } 731 | case MODE_Semi: 732 | case MODE_List: { 733 | if( p->cnt++==0 && p->showHeader ){ 734 | for(i=0; iout,"%s%s",azCol[i], i==nArg-1 ? "\n" : p->separator); 736 | } 737 | } 738 | if( azArg==0 ) break; 739 | for(i=0; inullvalue; 742 | fprintf(p->out, "%s", z); 743 | if( iout, "%s", p->separator); 745 | }else if( p->mode==MODE_Semi ){ 746 | fprintf(p->out, ";\n"); 747 | }else{ 748 | fprintf(p->out, "\n"); 749 | } 750 | } 751 | break; 752 | } 753 | case MODE_Html: { 754 | if( p->cnt++==0 && p->showHeader ){ 755 | fprintf(p->out,""); 756 | for(i=0; iout,""); 758 | output_html_string(p->out, azCol[i]); 759 | fprintf(p->out,"\n"); 760 | } 761 | fprintf(p->out,"\n"); 762 | } 763 | if( azArg==0 ) break; 764 | fprintf(p->out,""); 765 | for(i=0; iout,""); 767 | output_html_string(p->out, azArg[i] ? azArg[i] : p->nullvalue); 768 | fprintf(p->out,"\n"); 769 | } 770 | fprintf(p->out,"\n"); 771 | break; 772 | } 773 | case MODE_Tcl: { 774 | if( p->cnt++==0 && p->showHeader ){ 775 | for(i=0; iout,azCol[i] ? azCol[i] : ""); 777 | fprintf(p->out, "%s", p->separator); 778 | } 779 | fprintf(p->out,"\n"); 780 | } 781 | if( azArg==0 ) break; 782 | for(i=0; iout, azArg[i] ? azArg[i] : p->nullvalue); 784 | fprintf(p->out, "%s", p->separator); 785 | } 786 | fprintf(p->out,"\n"); 787 | break; 788 | } 789 | case MODE_Csv: { 790 | if( p->cnt++==0 && p->showHeader ){ 791 | for(i=0; iout,"\n"); 795 | } 796 | if( azArg==0 ) break; 797 | for(i=0; iout,"\n"); 801 | break; 802 | } 803 | case MODE_Insert: { 804 | p->cnt++; 805 | if( azArg==0 ) break; 806 | fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable); 807 | for(i=0; i0 ? ",": ""; 809 | if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ 810 | fprintf(p->out,"%sNULL",zSep); 811 | }else if( aiType && aiType[i]==SQLITE_TEXT ){ 812 | if( zSep[0] ) fprintf(p->out,"%s",zSep); 813 | output_quoted_string(p->out, azArg[i]); 814 | }else if( aiType && (aiType[i]==SQLITE_INTEGER || aiType[i]==SQLITE_FLOAT) ){ 815 | fprintf(p->out,"%s%s",zSep, azArg[i]); 816 | }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ 817 | const void *pBlob = sqlite3_column_blob(p->pStmt, i); 818 | int nBlob = sqlite3_column_bytes(p->pStmt, i); 819 | if( zSep[0] ) fprintf(p->out,"%s",zSep); 820 | output_hex_blob(p->out, pBlob, nBlob); 821 | }else if( isNumber(azArg[i], 0) ){ 822 | fprintf(p->out,"%s%s",zSep, azArg[i]); 823 | }else{ 824 | if( zSep[0] ) fprintf(p->out,"%s",zSep); 825 | output_quoted_string(p->out, azArg[i]); 826 | } 827 | } 828 | fprintf(p->out,");\n"); 829 | break; 830 | } 831 | } 832 | return 0; 833 | } 834 | 835 | /* 836 | ** This is the callback routine that the SQLite library 837 | ** invokes for each row of a query result. 838 | */ 839 | static int callback(void *pArg, int nArg, char **azArg, char **azCol){ 840 | /* since we don't have type info, call the shell_callback with a NULL value */ 841 | return shell_callback(pArg, nArg, azArg, azCol, NULL); 842 | } 843 | 844 | /* 845 | ** Set the destination table field of the callback_data structure to 846 | ** the name of the table given. Escape any quote characters in the 847 | ** table name. 848 | */ 849 | static void set_table_name(struct callback_data *p, const char *zName){ 850 | int i, n; 851 | int needQuote; 852 | char *z; 853 | 854 | if( p->zDestTable ){ 855 | free(p->zDestTable); 856 | p->zDestTable = 0; 857 | } 858 | if( zName==0 ) return; 859 | needQuote = !isalpha((unsigned char)*zName) && *zName!='_'; 860 | for(i=n=0; zName[i]; i++, n++){ 861 | if( !isalnum((unsigned char)zName[i]) && zName[i]!='_' ){ 862 | needQuote = 1; 863 | if( zName[i]=='\'' ) n++; 864 | } 865 | } 866 | if( needQuote ) n += 2; 867 | z = p->zDestTable = malloc( n+1 ); 868 | if( z==0 ){ 869 | fprintf(stderr,"Error: out of memory\n"); 870 | exit(1); 871 | } 872 | n = 0; 873 | if( needQuote ) z[n++] = '\''; 874 | for(i=0; zName[i]; i++){ 875 | z[n++] = zName[i]; 876 | if( zName[i]=='\'' ) z[n++] = '\''; 877 | } 878 | if( needQuote ) z[n++] = '\''; 879 | z[n] = 0; 880 | } 881 | 882 | /* zIn is either a pointer to a NULL-terminated string in memory obtained 883 | ** from malloc(), or a NULL pointer. The string pointed to by zAppend is 884 | ** added to zIn, and the result returned in memory obtained from malloc(). 885 | ** zIn, if it was not NULL, is freed. 886 | ** 887 | ** If the third argument, quote, is not '\0', then it is used as a 888 | ** quote character for zAppend. 889 | */ 890 | static char *appendText(char *zIn, char const *zAppend, char quote){ 891 | int len; 892 | int i; 893 | int nAppend = strlen30(zAppend); 894 | int nIn = (zIn?strlen30(zIn):0); 895 | 896 | len = nAppend+nIn+1; 897 | if( quote ){ 898 | len += 2; 899 | for(i=0; iechoOn ){ 1014 | const char *zStmtSql = sqlite3_sql(pStmt); 1015 | fprintf(pArg->out,"%s\n", zStmtSql ? zStmtSql : zSql); 1016 | } 1017 | 1018 | /* perform the first step. this will tell us if we 1019 | ** have a result set or not and how wide it is. 1020 | */ 1021 | rc = sqlite3_step(pStmt); 1022 | /* if we have a result set... */ 1023 | if( SQLITE_ROW == rc ){ 1024 | /* if we have a callback... */ 1025 | if( xCallback ){ 1026 | /* allocate space for col name ptr, value ptr, and type */ 1027 | int nCol = sqlite3_column_count(pStmt); 1028 | void *pData = sqlite3_malloc(3*nCol*sizeof(const char*) + 1); 1029 | if( !pData ){ 1030 | rc = SQLITE_NOMEM; 1031 | }else{ 1032 | char **azCols = (char **)pData; /* Names of result columns */ 1033 | char **azVals = &azCols[nCol]; /* Results */ 1034 | int *aiTypes = (int *)&azVals[nCol]; /* Result types */ 1035 | int i; 1036 | assert(sizeof(int) <= sizeof(char *)); 1037 | /* save off ptrs to column names */ 1038 | for(i=0; ipStmt = pStmt; 1044 | pArg->cnt = 0; 1045 | } 1046 | do{ 1047 | /* extract the data and data types */ 1048 | for(i=0; ipStmt = NULL; 1070 | } 1071 | } 1072 | }else{ 1073 | do{ 1074 | rc = sqlite3_step(pStmt); 1075 | } while( rc == SQLITE_ROW ); 1076 | } 1077 | } 1078 | 1079 | /* Finalize the statement just executed. If this fails, save a 1080 | ** copy of the error message. Otherwise, set zSql to point to the 1081 | ** next statement to execute. */ 1082 | rc = sqlite3_finalize(pStmt); 1083 | if( rc==SQLITE_OK ){ 1084 | zSql = zLeftover; 1085 | while( isspace(zSql[0]) ) zSql++; 1086 | }else if( pzErrMsg ){ 1087 | *pzErrMsg = save_err_msg(db); 1088 | } 1089 | } 1090 | } /* end while */ 1091 | 1092 | return rc; 1093 | } 1094 | 1095 | 1096 | /* 1097 | ** This is a different callback routine used for dumping the database. 1098 | ** Each row received by this callback consists of a table name, 1099 | ** the table type ("index" or "table") and SQL to create the table. 1100 | ** This routine should print text sufficient to recreate the table. 1101 | */ 1102 | static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ 1103 | int rc; 1104 | const char *zTable; 1105 | const char *zType; 1106 | const char *zSql; 1107 | const char *zPrepStmt = 0; 1108 | struct callback_data *p = (struct callback_data *)pArg; 1109 | 1110 | UNUSED_PARAMETER(azCol); 1111 | if( nArg!=3 ) return 1; 1112 | zTable = azArg[0]; 1113 | zType = azArg[1]; 1114 | zSql = azArg[2]; 1115 | 1116 | if( strcmp(zTable, "sqlite_sequence")==0 ){ 1117 | zPrepStmt = "DELETE FROM sqlite_sequence;\n"; 1118 | }else if( strcmp(zTable, "sqlite_stat1")==0 ){ 1119 | fprintf(p->out, "ANALYZE sqlite_master;\n"); 1120 | }else if( strncmp(zTable, "sqlite_", 7)==0 ){ 1121 | return 0; 1122 | }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ 1123 | char *zIns; 1124 | if( !p->writableSchema ){ 1125 | fprintf(p->out, "PRAGMA writable_schema=ON;\n"); 1126 | p->writableSchema = 1; 1127 | } 1128 | zIns = sqlite3_mprintf( 1129 | "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)" 1130 | "VALUES('table','%q','%q',0,'%q');", 1131 | zTable, zTable, zSql); 1132 | fprintf(p->out, "%s\n", zIns); 1133 | sqlite3_free(zIns); 1134 | return 0; 1135 | }else{ 1136 | fprintf(p->out, "%s;\n", zSql); 1137 | } 1138 | 1139 | if( strcmp(zType, "table")==0 ){ 1140 | sqlite3_stmt *pTableInfo = 0; 1141 | char *zSelect = 0; 1142 | char *zTableInfo = 0; 1143 | char *zTmp = 0; 1144 | int nRow = 0; 1145 | 1146 | zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0); 1147 | zTableInfo = appendText(zTableInfo, zTable, '"'); 1148 | zTableInfo = appendText(zTableInfo, ");", 0); 1149 | 1150 | rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0); 1151 | free(zTableInfo); 1152 | if( rc!=SQLITE_OK || !pTableInfo ){ 1153 | return 1; 1154 | } 1155 | 1156 | zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0); 1157 | zTmp = appendText(zTmp, zTable, '"'); 1158 | if( zTmp ){ 1159 | zSelect = appendText(zSelect, zTmp, '\''); 1160 | } 1161 | zSelect = appendText(zSelect, " || ' VALUES(' || ", 0); 1162 | rc = sqlite3_step(pTableInfo); 1163 | while( rc==SQLITE_ROW ){ 1164 | const char *zText = (const char *)sqlite3_column_text(pTableInfo, 1); 1165 | zSelect = appendText(zSelect, "quote(", 0); 1166 | zSelect = appendText(zSelect, zText, '"'); 1167 | rc = sqlite3_step(pTableInfo); 1168 | if( rc==SQLITE_ROW ){ 1169 | zSelect = appendText(zSelect, ") || ',' || ", 0); 1170 | }else{ 1171 | zSelect = appendText(zSelect, ") ", 0); 1172 | } 1173 | nRow++; 1174 | } 1175 | rc = sqlite3_finalize(pTableInfo); 1176 | if( rc!=SQLITE_OK || nRow==0 ){ 1177 | free(zSelect); 1178 | return 1; 1179 | } 1180 | zSelect = appendText(zSelect, "|| ')' FROM ", 0); 1181 | zSelect = appendText(zSelect, zTable, '"'); 1182 | 1183 | rc = run_table_dump_query(p->out, p->db, zSelect, zPrepStmt); 1184 | if( rc==SQLITE_CORRUPT ){ 1185 | zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0); 1186 | rc = run_table_dump_query(p->out, p->db, zSelect, 0); 1187 | } 1188 | if( zSelect ) free(zSelect); 1189 | } 1190 | return 0; 1191 | } 1192 | 1193 | /* 1194 | ** Run zQuery. Use dump_callback() as the callback routine so that 1195 | ** the contents of the query are output as SQL statements. 1196 | ** 1197 | ** If we get a SQLITE_CORRUPT error, rerun the query after appending 1198 | ** "ORDER BY rowid DESC" to the end. 1199 | */ 1200 | static int run_schema_dump_query( 1201 | struct callback_data *p, 1202 | const char *zQuery, 1203 | char **pzErrMsg 1204 | ){ 1205 | int rc; 1206 | rc = sqlite3_exec(p->db, zQuery, dump_callback, p, pzErrMsg); 1207 | if( rc==SQLITE_CORRUPT ){ 1208 | char *zQ2; 1209 | int len = strlen30(zQuery); 1210 | if( pzErrMsg ) sqlite3_free(*pzErrMsg); 1211 | zQ2 = malloc( len+100 ); 1212 | if( zQ2==0 ) return rc; 1213 | sqlite3_snprintf(sizeof(zQ2), zQ2, "%s ORDER BY rowid DESC", zQuery); 1214 | rc = sqlite3_exec(p->db, zQ2, dump_callback, p, pzErrMsg); 1215 | free(zQ2); 1216 | } 1217 | return rc; 1218 | } 1219 | 1220 | /* 1221 | ** Text of a help message 1222 | */ 1223 | static char zHelp[] = 1224 | ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n" 1225 | ".bail ON|OFF Stop after hitting an error. Default OFF\n" 1226 | ".databases List names and files of attached databases\n" 1227 | ".dump ?TABLE? ... Dump the database in an SQL text format\n" 1228 | " If TABLE specified, only dump tables matching\n" 1229 | " LIKE pattern TABLE.\n" 1230 | ".echo ON|OFF Turn command echo on or off\n" 1231 | ".exit Exit this program\n" 1232 | ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n" 1233 | " With no args, it turns EXPLAIN on.\n" 1234 | ".header(s) ON|OFF Turn display of headers on or off\n" 1235 | ".help Show this message\n" 1236 | ".import FILE TABLE Import data from FILE into TABLE\n" 1237 | ".indices ?TABLE? Show names of all indices\n" 1238 | " If TABLE specified, only show indices for tables\n" 1239 | " matching LIKE pattern TABLE.\n" 1240 | #ifdef SQLITE_ENABLE_IOTRACE 1241 | ".iotrace FILE Enable I/O diagnostic logging to FILE\n" 1242 | #endif 1243 | #ifndef SQLITE_OMIT_LOAD_EXTENSION 1244 | ".load FILE ?ENTRY? Load an extension library\n" 1245 | #endif 1246 | ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n" 1247 | ".mode MODE ?TABLE? Set output mode where MODE is one of:\n" 1248 | " csv Comma-separated values\n" 1249 | " column Left-aligned columns. (See .width)\n" 1250 | " html HTML code\n" 1251 | " insert SQL insert statements for TABLE\n" 1252 | " line One value per line\n" 1253 | " list Values delimited by .separator string\n" 1254 | " tabs Tab-separated values\n" 1255 | " tcl TCL list elements\n" 1256 | ".nullvalue STRING Print STRING in place of NULL values\n" 1257 | ".output FILENAME Send output to FILENAME\n" 1258 | ".output stdout Send output to the screen\n" 1259 | ".prompt MAIN CONTINUE Replace the standard prompts\n" 1260 | ".quit Exit this program\n" 1261 | ".read FILENAME Execute SQL in FILENAME\n" 1262 | ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n" 1263 | ".schema ?TABLE? Show the CREATE statements\n" 1264 | " If TABLE specified, only show tables matching\n" 1265 | " LIKE pattern TABLE.\n" 1266 | ".separator STRING Change separator used by output mode and .import\n" 1267 | ".show Show the current values for various settings\n" 1268 | ".tables ?TABLE? List names of tables\n" 1269 | " If TABLE specified, only list tables matching\n" 1270 | " LIKE pattern TABLE.\n" 1271 | ".timeout MS Try opening locked tables for MS milliseconds\n" 1272 | ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n" 1273 | ; 1274 | 1275 | static char zTimerHelp[] = 1276 | ".timer ON|OFF Turn the CPU timer measurement on or off\n" 1277 | ; 1278 | 1279 | /* Forward reference */ 1280 | static int process_input(struct callback_data *p, FILE *in); 1281 | 1282 | /* 1283 | ** Make sure the database is open. If it is not, then open it. If 1284 | ** the database fails to open, print an error message and exit. 1285 | */ 1286 | static void open_db(struct callback_data *p){ 1287 | if( p->db==0 ){ 1288 | 1289 | sqlite3_open(p->zDbFilename, &p->db); 1290 | db = p->db; 1291 | 1292 | #ifdef SQLITE_HAS_CODEC 1293 | if (encryption_key != NULL){ 1294 | sqlite3_activate_see("7bb07b8d471d642e"); 1295 | sqlite3_key(db, encryption_key, encryption_key_length); 1296 | } 1297 | #endif 1298 | 1299 | if( db && sqlite3_errcode(db)==SQLITE_OK ){ 1300 | sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0, 1301 | shellstaticFunc, 0, 0); 1302 | } 1303 | if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){ 1304 | fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 1305 | p->zDbFilename, sqlite3_errmsg(db)); 1306 | exit(1); 1307 | } 1308 | 1309 | #ifndef SQLITE_OMIT_LOAD_EXTENSION 1310 | sqlite3_enable_load_extension(p->db, 1); 1311 | #endif 1312 | } 1313 | } 1314 | 1315 | /* 1316 | ** Do C-language style dequoting. 1317 | ** 1318 | ** \t -> tab 1319 | ** \n -> newline 1320 | ** \r -> carriage return 1321 | ** \NNN -> ascii character NNN in octal 1322 | ** \\ -> backslash 1323 | */ 1324 | static void resolve_backslashes(char *z){ 1325 | int i, j; 1326 | char c; 1327 | for(i=j=0; (c = z[i])!=0; i++, j++){ 1328 | if( c=='\\' ){ 1329 | c = z[++i]; 1330 | if( c=='n' ){ 1331 | c = '\n'; 1332 | }else if( c=='t' ){ 1333 | c = '\t'; 1334 | }else if( c=='r' ){ 1335 | c = '\r'; 1336 | }else if( c>='0' && c<='7' ){ 1337 | c -= '0'; 1338 | if( z[i+1]>='0' && z[i+1]<='7' ){ 1339 | i++; 1340 | c = (c<<3) + z[i] - '0'; 1341 | if( z[i+1]>='0' && z[i+1]<='7' ){ 1342 | i++; 1343 | c = (c<<3) + z[i] - '0'; 1344 | } 1345 | } 1346 | } 1347 | } 1348 | z[j] = c; 1349 | } 1350 | z[j] = 0; 1351 | } 1352 | 1353 | /* 1354 | ** Interpret zArg as a boolean value. Return either 0 or 1. 1355 | */ 1356 | static int booleanValue(char *zArg){ 1357 | int val = atoi(zArg); 1358 | int j; 1359 | for(j=0; zArg[j]; j++){ 1360 | zArg[j] = (char)tolower(zArg[j]); 1361 | } 1362 | if( strcmp(zArg,"on")==0 ){ 1363 | val = 1; 1364 | }else if( strcmp(zArg,"yes")==0 ){ 1365 | val = 1; 1366 | } 1367 | return val; 1368 | } 1369 | 1370 | /* 1371 | ** If an input line begins with "." then invoke this routine to 1372 | ** process that line. 1373 | ** 1374 | ** Return 1 on error, 2 to exit, and 0 otherwise. 1375 | */ 1376 | static int do_meta_command(char *zLine, struct callback_data *p){ 1377 | int i = 1; 1378 | int nArg = 0; 1379 | int n, c; 1380 | int rc = 0; 1381 | char *azArg[50]; 1382 | 1383 | /* Parse the input line into tokens. 1384 | */ 1385 | while( zLine[i] && nArg=3 && strncmp(azArg[0], "backup", n)==0 && nArg>1 && nArg<4){ 1410 | const char *zDestFile; 1411 | const char *zDb; 1412 | sqlite3 *pDest; 1413 | sqlite3_backup *pBackup; 1414 | if( nArg==2 ){ 1415 | zDestFile = azArg[1]; 1416 | zDb = "main"; 1417 | }else{ 1418 | zDestFile = azArg[2]; 1419 | zDb = azArg[1]; 1420 | } 1421 | 1422 | rc = sqlite3_open(zDestFile, &pDest); 1423 | 1424 | if( rc!=SQLITE_OK ){ 1425 | fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile); 1426 | sqlite3_close(pDest); 1427 | return 1; 1428 | } 1429 | open_db(p); 1430 | pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb); 1431 | if( pBackup==0 ){ 1432 | fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest)); 1433 | sqlite3_close(pDest); 1434 | return 1; 1435 | } 1436 | while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){} 1437 | sqlite3_backup_finish(pBackup); 1438 | if( rc==SQLITE_DONE ){ 1439 | rc = 0; 1440 | }else{ 1441 | fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest)); 1442 | rc = 1; 1443 | } 1444 | sqlite3_close(pDest); 1445 | }else 1446 | 1447 | if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 && nArg>1 && nArg<3 ){ 1448 | bail_on_error = booleanValue(azArg[1]); 1449 | }else 1450 | 1451 | if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){ 1452 | struct callback_data data; 1453 | char *zErrMsg = 0; 1454 | open_db(p); 1455 | memcpy(&data, p, sizeof(data)); 1456 | data.showHeader = 1; 1457 | data.mode = MODE_Column; 1458 | data.colWidth[0] = 3; 1459 | data.colWidth[1] = 15; 1460 | data.colWidth[2] = 58; 1461 | data.cnt = 0; 1462 | sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg); 1463 | if( zErrMsg ){ 1464 | fprintf(stderr,"Error: %s\n", zErrMsg); 1465 | sqlite3_free(zErrMsg); 1466 | rc = 1; 1467 | } 1468 | }else 1469 | 1470 | if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){ 1471 | char *zErrMsg = 0; 1472 | open_db(p); 1473 | /* When playing back a "dump", the content might appear in an order 1474 | ** which causes immediate foreign key constraints to be violated. 1475 | ** So disable foreign-key constraint enforcement to prevent problems. */ 1476 | fprintf(p->out, "PRAGMA foreign_keys=OFF;\n"); 1477 | fprintf(p->out, "BEGIN TRANSACTION;\n"); 1478 | p->writableSchema = 0; 1479 | sqlite3_exec(p->db, "PRAGMA writable_schema=ON", 0, 0, 0); 1480 | if( nArg==1 ){ 1481 | run_schema_dump_query(p, 1482 | "SELECT name, type, sql FROM sqlite_master " 1483 | "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'", 0 1484 | ); 1485 | run_schema_dump_query(p, 1486 | "SELECT name, type, sql FROM sqlite_master " 1487 | "WHERE name=='sqlite_sequence'", 0 1488 | ); 1489 | run_table_dump_query(p->out, p->db, 1490 | "SELECT sql FROM sqlite_master " 1491 | "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0 1492 | ); 1493 | }else{ 1494 | int i; 1495 | for(i=1; iout, p->db, 1502 | "SELECT sql FROM sqlite_master " 1503 | "WHERE sql NOT NULL" 1504 | " AND type IN ('index','trigger','view')" 1505 | " AND tbl_name LIKE shellstatic()", 0 1506 | ); 1507 | zShellStatic = 0; 1508 | } 1509 | } 1510 | if( p->writableSchema ){ 1511 | fprintf(p->out, "PRAGMA writable_schema=OFF;\n"); 1512 | p->writableSchema = 0; 1513 | } 1514 | sqlite3_exec(p->db, "PRAGMA writable_schema=OFF", 0, 0, 0); 1515 | if( zErrMsg ){ 1516 | fprintf(stderr,"Error: %s\n", zErrMsg); 1517 | sqlite3_free(zErrMsg); 1518 | }else{ 1519 | fprintf(p->out, "COMMIT;\n"); 1520 | } 1521 | }else 1522 | 1523 | if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){ 1524 | p->echoOn = booleanValue(azArg[1]); 1525 | }else 1526 | 1527 | if( c=='e' && strncmp(azArg[0], "exit", n)==0 && nArg==1 ){ 1528 | rc = 2; 1529 | }else 1530 | 1531 | if( c=='e' && strncmp(azArg[0], "explain", n)==0 && nArg<3 ){ 1532 | int val = nArg>=2 ? booleanValue(azArg[1]) : 1; 1533 | if(val == 1) { 1534 | if(!p->explainPrev.valid) { 1535 | p->explainPrev.valid = 1; 1536 | p->explainPrev.mode = p->mode; 1537 | p->explainPrev.showHeader = p->showHeader; 1538 | memcpy(p->explainPrev.colWidth,p->colWidth,sizeof(p->colWidth)); 1539 | } 1540 | /* We could put this code under the !p->explainValid 1541 | ** condition so that it does not execute if we are already in 1542 | ** explain mode. However, always executing it allows us an easy 1543 | ** was to reset to explain mode in case the user previously 1544 | ** did an .explain followed by a .width, .mode or .header 1545 | ** command. 1546 | */ 1547 | p->mode = MODE_Explain; 1548 | p->showHeader = 1; 1549 | memset(p->colWidth,0,ArraySize(p->colWidth)); 1550 | p->colWidth[0] = 4; /* addr */ 1551 | p->colWidth[1] = 13; /* opcode */ 1552 | p->colWidth[2] = 4; /* P1 */ 1553 | p->colWidth[3] = 4; /* P2 */ 1554 | p->colWidth[4] = 4; /* P3 */ 1555 | p->colWidth[5] = 13; /* P4 */ 1556 | p->colWidth[6] = 2; /* P5 */ 1557 | p->colWidth[7] = 13; /* Comment */ 1558 | }else if (p->explainPrev.valid) { 1559 | p->explainPrev.valid = 0; 1560 | p->mode = p->explainPrev.mode; 1561 | p->showHeader = p->explainPrev.showHeader; 1562 | memcpy(p->colWidth,p->explainPrev.colWidth,sizeof(p->colWidth)); 1563 | } 1564 | }else 1565 | 1566 | if( c=='h' && (strncmp(azArg[0], "header", n)==0 || 1567 | strncmp(azArg[0], "headers", n)==0) && nArg>1 && nArg<3 ){ 1568 | p->showHeader = booleanValue(azArg[1]); 1569 | }else 1570 | 1571 | if( c=='h' && strncmp(azArg[0], "help", n)==0 ){ 1572 | fprintf(stderr,"%s",zHelp); 1573 | if( HAS_TIMER ){ 1574 | fprintf(stderr,"%s",zTimerHelp); 1575 | } 1576 | }else 1577 | 1578 | if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){ 1579 | char *zTable = azArg[2]; /* Insert data into this table */ 1580 | char *zFile = azArg[1]; /* The file from which to extract data */ 1581 | sqlite3_stmt *pStmt = NULL; /* A statement */ 1582 | int nCol; /* Number of columns in the table */ 1583 | int nByte; /* Number of bytes in an SQL string */ 1584 | int i, j; /* Loop counters */ 1585 | int nSep; /* Number of bytes in p->separator[] */ 1586 | char *zSql; /* An SQL statement */ 1587 | char *zLine; /* A single line of input from the file */ 1588 | char **azCol; /* zLine[] broken up into columns */ 1589 | char *zCommit; /* How to commit changes */ 1590 | FILE *in; /* The input file */ 1591 | int lineno = 0; /* Line number of input file */ 1592 | 1593 | open_db(p); 1594 | nSep = strlen30(p->separator); 1595 | if( nSep==0 ){ 1596 | fprintf(stderr, "Error: non-null separator required for import\n"); 1597 | return 1; 1598 | } 1599 | zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable); 1600 | if( zSql==0 ){ 1601 | fprintf(stderr, "Error: out of memory\n"); 1602 | return 1; 1603 | } 1604 | nByte = strlen30(zSql); 1605 | rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0); 1606 | sqlite3_free(zSql); 1607 | if( rc ){ 1608 | if (pStmt) sqlite3_finalize(pStmt); 1609 | fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db)); 1610 | return 1; 1611 | } 1612 | nCol = sqlite3_column_count(pStmt); 1613 | sqlite3_finalize(pStmt); 1614 | pStmt = 0; 1615 | if( nCol==0 ) return 0; /* no columns, no error */ 1616 | zSql = malloc( nByte + 20 + nCol*2 ); 1617 | if( zSql==0 ){ 1618 | fprintf(stderr, "Error: out of memory\n"); 1619 | return 1; 1620 | } 1621 | sqlite3_snprintf(nByte+20, zSql, "INSERT INTO '%q' VALUES(?", zTable); 1622 | j = strlen30(zSql); 1623 | for(i=1; idb, zSql, -1, &pStmt, 0); 1630 | free(zSql); 1631 | if( rc ){ 1632 | fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db)); 1633 | if (pStmt) sqlite3_finalize(pStmt); 1634 | return 1; 1635 | } 1636 | in = fopen(zFile, "rb"); 1637 | if( in==0 ){ 1638 | fprintf(stderr, "Error: cannot open \"%s\"\n", zFile); 1639 | sqlite3_finalize(pStmt); 1640 | return 1; 1641 | } 1642 | azCol = malloc( sizeof(azCol[0])*(nCol+1) ); 1643 | if( azCol==0 ){ 1644 | fprintf(stderr, "Error: out of memory\n"); 1645 | fclose(in); 1646 | sqlite3_finalize(pStmt); 1647 | return 1; 1648 | } 1649 | sqlite3_exec(p->db, "BEGIN", 0, 0, 0); 1650 | zCommit = "COMMIT"; 1651 | while( (zLine = local_getline(0, in))!=0 ){ 1652 | char *z; 1653 | i = 0; 1654 | lineno++; 1655 | azCol[0] = zLine; 1656 | for(i=0, z=zLine; *z && *z!='\n' && *z!='\r'; z++){ 1657 | if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){ 1658 | *z = 0; 1659 | i++; 1660 | if( idb, zCommit, 0, 0, 0); 1693 | }else 1694 | 1695 | if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){ 1696 | struct callback_data data; 1697 | char *zErrMsg = 0; 1698 | open_db(p); 1699 | memcpy(&data, p, sizeof(data)); 1700 | data.showHeader = 0; 1701 | data.mode = MODE_List; 1702 | if( nArg==1 ){ 1703 | rc = sqlite3_exec(p->db, 1704 | "SELECT name FROM sqlite_master " 1705 | "WHERE type='index' AND name NOT LIKE 'sqlite_%' " 1706 | "UNION ALL " 1707 | "SELECT name FROM sqlite_temp_master " 1708 | "WHERE type='index' " 1709 | "ORDER BY 1", 1710 | callback, &data, &zErrMsg 1711 | ); 1712 | }else{ 1713 | zShellStatic = azArg[1]; 1714 | rc = sqlite3_exec(p->db, 1715 | "SELECT name FROM sqlite_master " 1716 | "WHERE type='index' AND tbl_name LIKE shellstatic() " 1717 | "UNION ALL " 1718 | "SELECT name FROM sqlite_temp_master " 1719 | "WHERE type='index' AND tbl_name LIKE shellstatic() " 1720 | "ORDER BY 1", 1721 | callback, &data, &zErrMsg 1722 | ); 1723 | zShellStatic = 0; 1724 | } 1725 | if( zErrMsg ){ 1726 | fprintf(stderr,"Error: %s\n", zErrMsg); 1727 | sqlite3_free(zErrMsg); 1728 | rc = 1; 1729 | }else if( rc != SQLITE_OK ){ 1730 | fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n"); 1731 | rc = 1; 1732 | } 1733 | }else 1734 | 1735 | #ifdef SQLITE_ENABLE_IOTRACE 1736 | if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ 1737 | extern void (*sqlite3IoTrace)(const char*, ...); 1738 | if( iotrace && iotrace!=stdout ) fclose(iotrace); 1739 | iotrace = 0; 1740 | if( nArg<2 ){ 1741 | sqlite3IoTrace = 0; 1742 | }else if( strcmp(azArg[1], "-")==0 ){ 1743 | sqlite3IoTrace = iotracePrintf; 1744 | iotrace = stdout; 1745 | }else{ 1746 | iotrace = fopen(azArg[1], "w"); 1747 | if( iotrace==0 ){ 1748 | fprintf(stderr, "Error: cannot open \"%s\"\n", azArg[1]); 1749 | sqlite3IoTrace = 0; 1750 | rc = 1; 1751 | }else{ 1752 | sqlite3IoTrace = iotracePrintf; 1753 | } 1754 | } 1755 | }else 1756 | #endif 1757 | 1758 | #ifndef SQLITE_OMIT_LOAD_EXTENSION 1759 | if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){ 1760 | const char *zFile, *zProc; 1761 | char *zErrMsg = 0; 1762 | zFile = azArg[1]; 1763 | zProc = nArg>=3 ? azArg[2] : 0; 1764 | open_db(p); 1765 | rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg); 1766 | if( rc!=SQLITE_OK ){ 1767 | fprintf(stderr, "Error: %s\n", zErrMsg); 1768 | sqlite3_free(zErrMsg); 1769 | rc = 1; 1770 | } 1771 | }else 1772 | #endif 1773 | 1774 | if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=1 ){ 1775 | const char *zFile = azArg[1]; 1776 | if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){ 1777 | fclose(p->pLog); 1778 | p->pLog = 0; 1779 | } 1780 | if( strcmp(zFile,"stdout")==0 ){ 1781 | p->pLog = stdout; 1782 | }else if( strcmp(zFile, "stderr")==0 ){ 1783 | p->pLog = stderr; 1784 | }else if( strcmp(zFile, "off")==0 ){ 1785 | p->pLog = 0; 1786 | }else{ 1787 | p->pLog = fopen(zFile, "w"); 1788 | if( p->pLog==0 ){ 1789 | fprintf(stderr, "Error: cannot open \"%s\"\n", zFile); 1790 | } 1791 | } 1792 | }else 1793 | 1794 | if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){ 1795 | int n2 = strlen30(azArg[1]); 1796 | if( (n2==4 && strncmp(azArg[1],"line",n2)==0) 1797 | || 1798 | (n2==5 && strncmp(azArg[1],"lines",n2)==0) ){ 1799 | p->mode = MODE_Line; 1800 | }else if( (n2==6 && strncmp(azArg[1],"column",n2)==0) 1801 | || 1802 | (n2==7 && strncmp(azArg[1],"columns",n2)==0) ){ 1803 | p->mode = MODE_Column; 1804 | }else if( n2==4 && strncmp(azArg[1],"list",n2)==0 ){ 1805 | p->mode = MODE_List; 1806 | }else if( n2==4 && strncmp(azArg[1],"html",n2)==0 ){ 1807 | p->mode = MODE_Html; 1808 | }else if( n2==3 && strncmp(azArg[1],"tcl",n2)==0 ){ 1809 | p->mode = MODE_Tcl; 1810 | }else if( n2==3 && strncmp(azArg[1],"csv",n2)==0 ){ 1811 | p->mode = MODE_Csv; 1812 | sqlite3_snprintf(sizeof(p->separator), p->separator, ","); 1813 | }else if( n2==4 && strncmp(azArg[1],"tabs",n2)==0 ){ 1814 | p->mode = MODE_List; 1815 | sqlite3_snprintf(sizeof(p->separator), p->separator, "\t"); 1816 | }else if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){ 1817 | p->mode = MODE_Insert; 1818 | set_table_name(p, "table"); 1819 | }else { 1820 | fprintf(stderr,"Error: mode should be one of: " 1821 | "column csv html insert line list tabs tcl\n"); 1822 | rc = 1; 1823 | } 1824 | }else 1825 | 1826 | if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==3 ){ 1827 | int n2 = strlen30(azArg[1]); 1828 | if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){ 1829 | p->mode = MODE_Insert; 1830 | set_table_name(p, azArg[2]); 1831 | }else { 1832 | fprintf(stderr, "Error: invalid arguments: " 1833 | " \"%s\". Enter \".help\" for help\n", azArg[2]); 1834 | rc = 1; 1835 | } 1836 | }else 1837 | 1838 | if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) { 1839 | sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue, 1840 | "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]); 1841 | }else 1842 | 1843 | if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){ 1844 | if( p->out!=stdout ){ 1845 | fclose(p->out); 1846 | } 1847 | if( strcmp(azArg[1],"stdout")==0 ){ 1848 | p->out = stdout; 1849 | sqlite3_snprintf(sizeof(p->outfile), p->outfile, "stdout"); 1850 | }else{ 1851 | p->out = fopen(azArg[1], "wb"); 1852 | if( p->out==0 ){ 1853 | fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]); 1854 | p->out = stdout; 1855 | rc = 1; 1856 | } else { 1857 | sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]); 1858 | } 1859 | } 1860 | }else 1861 | 1862 | if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){ 1863 | if( nArg >= 2) { 1864 | strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); 1865 | } 1866 | if( nArg >= 3) { 1867 | strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1); 1868 | } 1869 | }else 1870 | 1871 | if( c=='q' && strncmp(azArg[0], "quit", n)==0 && nArg==1 ){ 1872 | rc = 2; 1873 | }else 1874 | 1875 | if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 && nArg==2 ){ 1876 | FILE *alt = fopen(azArg[1], "rb"); 1877 | if( alt==0 ){ 1878 | fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); 1879 | rc = 1; 1880 | }else{ 1881 | rc = process_input(p, alt); 1882 | fclose(alt); 1883 | } 1884 | }else 1885 | 1886 | if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 && nArg>1 && nArg<4){ 1887 | const char *zSrcFile; 1888 | const char *zDb; 1889 | sqlite3 *pSrc; 1890 | sqlite3_backup *pBackup; 1891 | int nTimeout = 0; 1892 | 1893 | if( nArg==2 ){ 1894 | zSrcFile = azArg[1]; 1895 | zDb = "main"; 1896 | }else{ 1897 | zSrcFile = azArg[2]; 1898 | zDb = azArg[1]; 1899 | } 1900 | 1901 | rc = sqlite3_open(zSrcFile, &pSrc); 1902 | 1903 | if( rc!=SQLITE_OK ){ 1904 | fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile); 1905 | sqlite3_close(pSrc); 1906 | return 1; 1907 | } 1908 | open_db(p); 1909 | pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main"); 1910 | if( pBackup==0 ){ 1911 | fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); 1912 | sqlite3_close(pSrc); 1913 | return 1; 1914 | } 1915 | while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK 1916 | || rc==SQLITE_BUSY ){ 1917 | if( rc==SQLITE_BUSY ){ 1918 | if( nTimeout++ >= 3 ) break; 1919 | sqlite3_sleep(100); 1920 | } 1921 | } 1922 | sqlite3_backup_finish(pBackup); 1923 | if( rc==SQLITE_DONE ){ 1924 | rc = 0; 1925 | }else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){ 1926 | fprintf(stderr, "Error: source database is busy\n"); 1927 | rc = 1; 1928 | }else{ 1929 | fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); 1930 | rc = 1; 1931 | } 1932 | sqlite3_close(pSrc); 1933 | }else 1934 | 1935 | if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){ 1936 | struct callback_data data; 1937 | char *zErrMsg = 0; 1938 | open_db(p); 1939 | memcpy(&data, p, sizeof(data)); 1940 | data.showHeader = 0; 1941 | data.mode = MODE_Semi; 1942 | if( nArg>1 ){ 1943 | int i; 1944 | for(i=0; azArg[1][i]; i++) azArg[1][i] = (char)tolower(azArg[1][i]); 1945 | if( strcmp(azArg[1],"sqlite_master")==0 ){ 1946 | char *new_argv[2], *new_colv[2]; 1947 | new_argv[0] = "CREATE TABLE sqlite_master (\n" 1948 | " type text,\n" 1949 | " name text,\n" 1950 | " tbl_name text,\n" 1951 | " rootpage integer,\n" 1952 | " sql text\n" 1953 | ")"; 1954 | new_argv[1] = 0; 1955 | new_colv[0] = "sql"; 1956 | new_colv[1] = 0; 1957 | callback(&data, 1, new_argv, new_colv); 1958 | rc = SQLITE_OK; 1959 | }else if( strcmp(azArg[1],"sqlite_temp_master")==0 ){ 1960 | char *new_argv[2], *new_colv[2]; 1961 | new_argv[0] = "CREATE TEMP TABLE sqlite_temp_master (\n" 1962 | " type text,\n" 1963 | " name text,\n" 1964 | " tbl_name text,\n" 1965 | " rootpage integer,\n" 1966 | " sql text\n" 1967 | ")"; 1968 | new_argv[1] = 0; 1969 | new_colv[0] = "sql"; 1970 | new_colv[1] = 0; 1971 | callback(&data, 1, new_argv, new_colv); 1972 | rc = SQLITE_OK; 1973 | }else{ 1974 | zShellStatic = azArg[1]; 1975 | rc = sqlite3_exec(p->db, 1976 | "SELECT sql FROM " 1977 | " (SELECT sql sql, type type, tbl_name tbl_name, name name" 1978 | " FROM sqlite_master UNION ALL" 1979 | " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) " 1980 | "WHERE tbl_name LIKE shellstatic() AND type!='meta' AND sql NOTNULL " 1981 | "ORDER BY substr(type,2,1), name", 1982 | callback, &data, &zErrMsg); 1983 | zShellStatic = 0; 1984 | } 1985 | }else{ 1986 | rc = sqlite3_exec(p->db, 1987 | "SELECT sql FROM " 1988 | " (SELECT sql sql, type type, tbl_name tbl_name, name name" 1989 | " FROM sqlite_master UNION ALL" 1990 | " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) " 1991 | "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'" 1992 | "ORDER BY substr(type,2,1), name", 1993 | callback, &data, &zErrMsg 1994 | ); 1995 | } 1996 | if( zErrMsg ){ 1997 | fprintf(stderr,"Error: %s\n", zErrMsg); 1998 | sqlite3_free(zErrMsg); 1999 | rc = 1; 2000 | }else if( rc != SQLITE_OK ){ 2001 | fprintf(stderr,"Error: querying schema information\n"); 2002 | rc = 1; 2003 | }else{ 2004 | rc = 0; 2005 | } 2006 | }else 2007 | 2008 | if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){ 2009 | sqlite3_snprintf(sizeof(p->separator), p->separator, 2010 | "%.*s", (int)sizeof(p->separator)-1, azArg[1]); 2011 | }else 2012 | 2013 | if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){ 2014 | int i; 2015 | fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off"); 2016 | fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off"); 2017 | fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off"); 2018 | fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]); 2019 | fprintf(p->out,"%9.9s: ", "nullvalue"); 2020 | output_c_string(p->out, p->nullvalue); 2021 | fprintf(p->out, "\n"); 2022 | fprintf(p->out,"%9.9s: %s\n","output", 2023 | strlen30(p->outfile) ? p->outfile : "stdout"); 2024 | fprintf(p->out,"%9.9s: ", "separator"); 2025 | output_c_string(p->out, p->separator); 2026 | fprintf(p->out, "\n"); 2027 | fprintf(p->out,"%9.9s: ","width"); 2028 | for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) { 2029 | fprintf(p->out,"%d ",p->colWidth[i]); 2030 | } 2031 | fprintf(p->out,"\n"); 2032 | }else 2033 | 2034 | if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){ 2035 | char **azResult; 2036 | int nRow; 2037 | char *zErrMsg; 2038 | open_db(p); 2039 | if( nArg==1 ){ 2040 | rc = sqlite3_get_table(p->db, 2041 | "SELECT name FROM sqlite_master " 2042 | "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' " 2043 | "UNION ALL " 2044 | "SELECT name FROM sqlite_temp_master " 2045 | "WHERE type IN ('table','view') " 2046 | "ORDER BY 1", 2047 | &azResult, &nRow, 0, &zErrMsg 2048 | ); 2049 | }else{ 2050 | zShellStatic = azArg[1]; 2051 | rc = sqlite3_get_table(p->db, 2052 | "SELECT name FROM sqlite_master " 2053 | "WHERE type IN ('table','view') AND name LIKE shellstatic() " 2054 | "UNION ALL " 2055 | "SELECT name FROM sqlite_temp_master " 2056 | "WHERE type IN ('table','view') AND name LIKE shellstatic() " 2057 | "ORDER BY 1", 2058 | &azResult, &nRow, 0, &zErrMsg 2059 | ); 2060 | zShellStatic = 0; 2061 | } 2062 | if( zErrMsg ){ 2063 | fprintf(stderr,"Error: %s\n", zErrMsg); 2064 | sqlite3_free(zErrMsg); 2065 | rc = 1; 2066 | }else if( rc != SQLITE_OK ){ 2067 | fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n"); 2068 | rc = 1; 2069 | }else{ 2070 | int len, maxlen = 0; 2071 | int i, j; 2072 | int nPrintCol, nPrintRow; 2073 | for(i=1; i<=nRow; i++){ 2074 | if( azResult[i]==0 ) continue; 2075 | len = strlen30(azResult[i]); 2076 | if( len>maxlen ) maxlen = len; 2077 | } 2078 | nPrintCol = 80/(maxlen+2); 2079 | if( nPrintCol<1 ) nPrintCol = 1; 2080 | nPrintRow = (nRow + nPrintCol - 1)/nPrintCol; 2081 | for(i=0; i4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){ 2093 | open_db(p); 2094 | sqlite3_busy_timeout(p->db, atoi(azArg[1])); 2095 | }else 2096 | 2097 | if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 && nArg==2 ){ 2098 | enableTimer = booleanValue(azArg[1]); 2099 | }else 2100 | 2101 | if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){ 2102 | int j; 2103 | assert( nArg<=ArraySize(azArg) ); 2104 | for(j=1; jcolWidth); j++){ 2105 | p->colWidth[j-1] = atoi(azArg[j]); 2106 | } 2107 | }else 2108 | 2109 | { 2110 | fprintf(stderr, "Error: unknown command or invalid arguments: " 2111 | " \"%s\". Enter \".help\" for help\n", azArg[0]); 2112 | rc = 1; 2113 | } 2114 | 2115 | return rc; 2116 | } 2117 | 2118 | /* 2119 | ** Return TRUE if a semicolon occurs anywhere in the first N characters 2120 | ** of string z[]. 2121 | */ 2122 | static int _contains_semicolon(const char *z, int N){ 2123 | int i; 2124 | for(i=0; iout); 2205 | free(zLine); 2206 | zLine = one_input_line(zSql, in); 2207 | if( zLine==0 ){ 2208 | break; /* We have reached EOF */ 2209 | } 2210 | if( seenInterrupt ){ 2211 | if( in!=0 ) break; 2212 | seenInterrupt = 0; 2213 | } 2214 | lineno++; 2215 | if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue; 2216 | if( zLine && zLine[0]=='.' && nSql==0 ){ 2217 | if( p->echoOn ) printf("%s\n", zLine); 2218 | rc = do_meta_command(zLine, p); 2219 | if( rc==2 ){ /* exit requested */ 2220 | break; 2221 | }else if( rc ){ 2222 | errCnt++; 2223 | } 2224 | continue; 2225 | } 2226 | if( _is_command_terminator(zLine) && _is_complete(zSql, nSql) ){ 2227 | memcpy(zLine,";",2); 2228 | } 2229 | nSqlPrior = nSql; 2230 | if( zSql==0 ){ 2231 | int i; 2232 | for(i=0; zLine[i] && isspace((unsigned char)zLine[i]); i++){} 2233 | if( zLine[i]!=0 ){ 2234 | nSql = strlen30(zLine); 2235 | zSql = malloc( nSql+3 ); 2236 | if( zSql==0 ){ 2237 | fprintf(stderr, "Error: out of memory\n"); 2238 | exit(1); 2239 | } 2240 | memcpy(zSql, zLine, nSql+1); 2241 | startline = lineno; 2242 | } 2243 | }else{ 2244 | int len = strlen30(zLine); 2245 | zSql = realloc( zSql, nSql + len + 4 ); 2246 | if( zSql==0 ){ 2247 | fprintf(stderr,"Error: out of memory\n"); 2248 | exit(1); 2249 | } 2250 | zSql[nSql++] = '\n'; 2251 | memcpy(&zSql[nSql], zLine, len+1); 2252 | nSql += len; 2253 | } 2254 | if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior) 2255 | && sqlite3_complete(zSql) ){ 2256 | p->cnt = 0; 2257 | open_db(p); 2258 | BEGIN_TIMER; 2259 | rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg); 2260 | END_TIMER; 2261 | if( rc || zErrMsg ){ 2262 | char zPrefix[100]; 2263 | if( in!=0 || !stdin_is_interactive ){ 2264 | sqlite3_snprintf(sizeof(zPrefix), zPrefix, 2265 | "Error: near line %d:", startline); 2266 | }else{ 2267 | sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:"); 2268 | } 2269 | if( zErrMsg!=0 ){ 2270 | fprintf(stderr, "%s %s\n", zPrefix, zErrMsg); 2271 | sqlite3_free(zErrMsg); 2272 | zErrMsg = 0; 2273 | }else{ 2274 | fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db)); 2275 | } 2276 | errCnt++; 2277 | } 2278 | free(zSql); 2279 | zSql = 0; 2280 | nSql = 0; 2281 | } 2282 | } 2283 | if( zSql ){ 2284 | if( !_all_whitespace(zSql) ) fprintf(stderr, "Error: incomplete SQL: %s\n", zSql); 2285 | free(zSql); 2286 | } 2287 | free(zLine); 2288 | return errCnt; 2289 | } 2290 | 2291 | /* 2292 | ** Return a pathname which is the user's home directory. A 2293 | ** 0 return indicates an error of some kind. Space to hold the 2294 | ** resulting string is obtained from malloc(). The calling 2295 | ** function should free the result. 2296 | */ 2297 | static char *find_home_dir(void){ 2298 | char *home_dir = NULL; 2299 | 2300 | #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL) 2301 | struct passwd *pwent; 2302 | uid_t uid = getuid(); 2303 | if( (pwent=getpwuid(uid)) != NULL) { 2304 | home_dir = pwent->pw_dir; 2305 | } 2306 | #endif 2307 | 2308 | #if defined(_WIN32_WCE) 2309 | /* Windows CE (arm-wince-mingw32ce-gcc) does not provide getenv() 2310 | */ 2311 | home_dir = strdup("/"); 2312 | #else 2313 | 2314 | #if defined(_WIN32) || defined(WIN32) || defined(__OS2__) 2315 | if (!home_dir) { 2316 | home_dir = getenv("USERPROFILE"); 2317 | } 2318 | #endif 2319 | 2320 | if (!home_dir) { 2321 | home_dir = getenv("HOME"); 2322 | } 2323 | 2324 | #if defined(_WIN32) || defined(WIN32) || defined(__OS2__) 2325 | if (!home_dir) { 2326 | char *zDrive, *zPath; 2327 | int n; 2328 | zDrive = getenv("HOMEDRIVE"); 2329 | zPath = getenv("HOMEPATH"); 2330 | if( zDrive && zPath ){ 2331 | n = strlen30(zDrive) + strlen30(zPath) + 1; 2332 | home_dir = malloc( n ); 2333 | if( home_dir==0 ) return 0; 2334 | sqlite3_snprintf(n, home_dir, "%s%s", zDrive, zPath); 2335 | return home_dir; 2336 | } 2337 | home_dir = "c:\\"; 2338 | } 2339 | #endif 2340 | 2341 | #endif /* !_WIN32_WCE */ 2342 | 2343 | if( home_dir ){ 2344 | int n = strlen30(home_dir) + 1; 2345 | char *z = malloc( n ); 2346 | if( z ) memcpy(z, home_dir, n); 2347 | home_dir = z; 2348 | } 2349 | 2350 | return home_dir; 2351 | } 2352 | 2353 | /* 2354 | ** Read input from the file given by sqliterc_override. Or if that 2355 | ** parameter is NULL, take input from ~/.sqliterc 2356 | ** 2357 | ** Returns the number of errors. 2358 | */ 2359 | static int process_sqliterc( 2360 | struct callback_data *p, /* Configuration data */ 2361 | const char *sqliterc_override /* Name of config file. NULL to use default */ 2362 | ){ 2363 | char *home_dir = NULL; 2364 | const char *sqliterc = sqliterc_override; 2365 | char *zBuf = 0; 2366 | FILE *in = NULL; 2367 | int nBuf; 2368 | int rc = 0; 2369 | 2370 | if (sqliterc == NULL) { 2371 | home_dir = find_home_dir(); 2372 | if( home_dir==0 ){ 2373 | #if !defined(__RTP__) && !defined(_WRS_KERNEL) 2374 | fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0); 2375 | #endif 2376 | return 1; 2377 | } 2378 | nBuf = strlen30(home_dir) + 16; 2379 | zBuf = malloc( nBuf ); 2380 | if( zBuf==0 ){ 2381 | fprintf(stderr,"%s: Error: out of memory\n",Argv0); 2382 | return 1; 2383 | } 2384 | sqlite3_snprintf(nBuf, zBuf,"%s/.sqliterc",home_dir); 2385 | free(home_dir); 2386 | sqliterc = (const char*)zBuf; 2387 | } 2388 | in = fopen(sqliterc,"rb"); 2389 | if( in ){ 2390 | if( stdin_is_interactive ){ 2391 | fprintf(stderr,"-- Loading resources from %s\n",sqliterc); 2392 | } 2393 | rc = process_input(p,in); 2394 | fclose(in); 2395 | } 2396 | free(zBuf); 2397 | return rc; 2398 | } 2399 | 2400 | /* 2401 | ** Show available command line options 2402 | */ 2403 | static const char zOptions[] = 2404 | " -help show this message\n" 2405 | " -init filename read/process named file\n" 2406 | " -echo print commands before execution\n" 2407 | " -[no]header turn headers on or off\n" 2408 | " -bail stop after hitting an error\n" 2409 | " -interactive force interactive I/O\n" 2410 | " -batch force batch I/O\n" 2411 | " -column set output mode to 'column'\n" 2412 | " -csv set output mode to 'csv'\n" 2413 | " -html set output mode to HTML\n" 2414 | " -line set output mode to 'line'\n" 2415 | " -list set output mode to 'list'\n" 2416 | " -separator 'x' set output field separator (|)\n" 2417 | " -nullvalue 'text' set text string for NULL values\n" 2418 | " -version show SQLite version\n" 2419 | #ifdef SQLITE_HAS_CODEC 2420 | " -key hexvalue set encryption key (hexadecimal, no quotes)\n" 2421 | #endif 2422 | ; 2423 | static void usage(int showDetail){ 2424 | fprintf(stderr, 2425 | "Usage: %s [OPTIONS] FILENAME [SQL]\n" 2426 | "FILENAME is the name of an SQLite database. A new database is created\n" 2427 | "if the file does not previously exist.\n", Argv0); 2428 | if( showDetail ){ 2429 | fprintf(stderr, "OPTIONS include:\n%s", zOptions); 2430 | }else{ 2431 | fprintf(stderr, "Use the -help option for additional information\n"); 2432 | } 2433 | exit(1); 2434 | } 2435 | 2436 | /* 2437 | ** Initialize the state information in data 2438 | */ 2439 | static void main_init(struct callback_data *data) { 2440 | memset(data, 0, sizeof(*data)); 2441 | data->mode = MODE_List; 2442 | memcpy(data->separator,"|", 2); 2443 | data->showHeader = 0; 2444 | sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data); 2445 | sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> "); 2446 | sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> "); 2447 | sqlite3_config(SQLITE_CONFIG_SINGLETHREAD); 2448 | } 2449 | 2450 | int main(int argc, char **argv){ 2451 | char *zErrMsg = 0; 2452 | struct callback_data data; 2453 | const char *zInitFile = 0; 2454 | char *zFirstCmd = 0; 2455 | int i; 2456 | int rc = 0; 2457 | 2458 | Argv0 = argv[0]; 2459 | main_init(&data); 2460 | stdin_is_interactive = isatty(0); 2461 | 2462 | /* Make sure we have a valid signal handler early, before anything 2463 | ** else is done. 2464 | */ 2465 | #ifdef SIGINT 2466 | signal(SIGINT, interrupt_handler); 2467 | #endif 2468 | 2469 | /* Do an initial pass through the command-line argument to locate 2470 | ** the name of the database file, the name of the initialization file, 2471 | ** and the first command to execute. 2472 | */ 2473 | for(i=1; i= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')))){ 2503 | fprintf(stderr, "Expecting hexadecimal values for encryption key!\r\n"); 2504 | return 1; 2505 | } 2506 | idx++; 2507 | } 2508 | tmpLength = idx; 2509 | if ((tmpLength % 2) != 0){ 2510 | fprintf(stderr, "Expecting an even number of characters for encryption key!\r\n"); 2511 | return 1; 2512 | } 2513 | 2514 | /* allocate key memory */ 2515 | encryption_key_length = tmpLength / 2; 2516 | encryption_key = malloc(encryption_key_length); 2517 | if (encryption_key == NULL){ 2518 | fprintf(stderr, "Out of memory!\r\n"); 2519 | return 1; 2520 | } 2521 | 2522 | /* convert hex string into values */ 2523 | idx = 0; 2524 | while ((argv[i][idx] != ' ') && (argv[i][idx] != '\x00')){ 2525 | char hex[3]; 2526 | hex[0] = (argv[i][idx++]); 2527 | hex[1] = (argv[i][idx++]); 2528 | hex[2] = '\x00'; 2529 | 2530 | ((unsigned char*)encryption_key)[(idx-2)/2] = (unsigned char)(0xFF & strtoul(hex, NULL, 16)); 2531 | } 2532 | #else 2533 | fprintf(stderr, "Sorry, encryption support is not available\r\n"); 2534 | fprintf(stderr, "HINT: define 'SQLITE_HAS_CODEC' at compile time\r\n"); 2535 | return 1; 2536 | #endif 2537 | } 2538 | } 2539 | if( i0 ){ 2584 | return rc; 2585 | } 2586 | 2587 | /* Make a second pass through the command-line argument and set 2588 | ** options. This second pass is delayed until after the initialization 2589 | ** file is processed so that the command-line arguments will override 2590 | ** settings in the initialization file. 2591 | */ 2592 | for(i=1; i=argc){ 2611 | fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z); 2612 | fprintf(stderr,"Use -help for a list of options.\n"); 2613 | return 1; 2614 | } 2615 | sqlite3_snprintf(sizeof(data.separator), data.separator, 2616 | "%.*s",(int)sizeof(data.separator)-1,argv[i]); 2617 | }else if( strcmp(z,"-nullvalue")==0 ){ 2618 | i++; 2619 | if(i>=argc){ 2620 | fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z); 2621 | fprintf(stderr,"Use -help for a list of options.\n"); 2622 | return 1; 2623 | } 2624 | sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue, 2625 | "%.*s",(int)sizeof(data.nullvalue)-1,argv[i]); 2626 | }else if( strcmp(z,"-header")==0 ){ 2627 | data.showHeader = 1; 2628 | }else if( strcmp(z,"-noheader")==0 ){ 2629 | data.showHeader = 0; 2630 | }else if( strcmp(z,"-echo")==0 ){ 2631 | data.echoOn = 1; 2632 | }else if( strcmp(z,"-bail")==0 ){ 2633 | bail_on_error = 1; 2634 | }else if( strcmp(z,"-version")==0 ){ 2635 | printf("%s\n", sqlite3_libversion()); 2636 | return 0; 2637 | }else if( strcmp(z,"-interactive")==0 ){ 2638 | stdin_is_interactive = 1; 2639 | }else if( strcmp(z,"-batch")==0 ){ 2640 | stdin_is_interactive = 0; 2641 | }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){ 2642 | usage(1); 2643 | #ifdef SQLITE_HAS_CODEC 2644 | }else if( strcmp(z,"-key")==0 ){ 2645 | /* encryption key has already been set */ 2646 | i++; 2647 | #endif 2648 | }else{ 2649 | fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z); 2650 | fprintf(stderr,"Use -help for a list of options.\n"); 2651 | return 1; 2652 | } 2653 | } 2654 | 2655 | if( zFirstCmd ){ 2656 | /* Run just the command that follows the database name 2657 | */ 2658 | if( zFirstCmd[0]=='.' ){ 2659 | rc = do_meta_command(zFirstCmd, &data); 2660 | }else{ 2661 | open_db(&data); 2662 | rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg); 2663 | if( zErrMsg!=0 ){ 2664 | fprintf(stderr,"Error: %s\n", zErrMsg); 2665 | return rc!=0 ? rc : 1; 2666 | }else if( rc!=0 ){ 2667 | fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd); 2668 | return rc; 2669 | } 2670 | } 2671 | }else{ 2672 | /* Run commands received from standard input 2673 | */ 2674 | if( stdin_is_interactive ){ 2675 | char *zHome; 2676 | char *zHistory = 0; 2677 | int nHistory; 2678 | printf( 2679 | "SQLite version %s\n" 2680 | "Enter \".help\" for instructions\n" 2681 | "Enter SQL statements terminated with a \";\"\n", 2682 | sqlite3_libversion() 2683 | ); 2684 | zHome = find_home_dir(); 2685 | if( zHome ){ 2686 | nHistory = strlen30(zHome) + 20; 2687 | if( (zHistory = malloc(nHistory))!=0 ){ 2688 | sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome); 2689 | } 2690 | } 2691 | #if defined(HAVE_READLINE) && HAVE_READLINE==1 2692 | if( zHistory ) read_history(zHistory); 2693 | #endif 2694 | rc = process_input(&data, 0); 2695 | if( zHistory ){ 2696 | stifle_history(100); 2697 | write_history(zHistory); 2698 | free(zHistory); 2699 | } 2700 | free(zHome); 2701 | }else{ 2702 | rc = process_input(&data, stdin); 2703 | } 2704 | } 2705 | set_table_name(&data, 0); 2706 | if( data.db ){ 2707 | if( sqlite3_close(data.db)!=SQLITE_OK ){ 2708 | fprintf(stderr,"Error: cannot close database \"%s\"\n", 2709 | sqlite3_errmsg(db)); 2710 | rc++; 2711 | } 2712 | } 2713 | 2714 | #ifdef SQLITE_HAS_CODEC 2715 | if (encryption_key != NULL){ 2716 | free(encryption_key); 2717 | encryption_key = NULL; 2718 | } 2719 | #endif 2720 | 2721 | return rc; 2722 | } 2723 | -------------------------------------------------------------------------------- /sqlite3ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 June 7 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This header file defines the SQLite interface for use by 13 | ** shared libraries that want to be imported as extensions into 14 | ** an SQLite instance. Shared libraries that intend to be loaded 15 | ** as extensions by SQLite should #include this file instead of 16 | ** sqlite3.h. 17 | */ 18 | #ifndef _SQLITE3EXT_H_ 19 | #define _SQLITE3EXT_H_ 20 | #include "sqlite3.h" 21 | 22 | typedef struct sqlite3_api_routines sqlite3_api_routines; 23 | 24 | /* 25 | ** The following structure holds pointers to all of the SQLite API 26 | ** routines. 27 | ** 28 | ** WARNING: In order to maintain backwards compatibility, add new 29 | ** interfaces to the end of this structure only. If you insert new 30 | ** interfaces in the middle of this structure, then older different 31 | ** versions of SQLite will not be able to load each others' shared 32 | ** libraries! 33 | */ 34 | struct sqlite3_api_routines { 35 | void * (*aggregate_context)(sqlite3_context*,int nBytes); 36 | int (*aggregate_count)(sqlite3_context*); 37 | int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*)); 38 | int (*bind_double)(sqlite3_stmt*,int,double); 39 | int (*bind_int)(sqlite3_stmt*,int,int); 40 | int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64); 41 | int (*bind_null)(sqlite3_stmt*,int); 42 | int (*bind_parameter_count)(sqlite3_stmt*); 43 | int (*bind_parameter_index)(sqlite3_stmt*,const char*zName); 44 | const char * (*bind_parameter_name)(sqlite3_stmt*,int); 45 | int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*)); 46 | int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*)); 47 | int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*); 48 | int (*busy_handler)(sqlite3*,int(*)(void*,int),void*); 49 | int (*busy_timeout)(sqlite3*,int ms); 50 | int (*changes)(sqlite3*); 51 | int (*close)(sqlite3*); 52 | int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*, 53 | int eTextRep,const char*)); 54 | int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*, 55 | int eTextRep,const void*)); 56 | const void * (*column_blob)(sqlite3_stmt*,int iCol); 57 | int (*column_bytes)(sqlite3_stmt*,int iCol); 58 | int (*column_bytes16)(sqlite3_stmt*,int iCol); 59 | int (*column_count)(sqlite3_stmt*pStmt); 60 | const char * (*column_database_name)(sqlite3_stmt*,int); 61 | const void * (*column_database_name16)(sqlite3_stmt*,int); 62 | const char * (*column_decltype)(sqlite3_stmt*,int i); 63 | const void * (*column_decltype16)(sqlite3_stmt*,int); 64 | double (*column_double)(sqlite3_stmt*,int iCol); 65 | int (*column_int)(sqlite3_stmt*,int iCol); 66 | sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol); 67 | const char * (*column_name)(sqlite3_stmt*,int); 68 | const void * (*column_name16)(sqlite3_stmt*,int); 69 | const char * (*column_origin_name)(sqlite3_stmt*,int); 70 | const void * (*column_origin_name16)(sqlite3_stmt*,int); 71 | const char * (*column_table_name)(sqlite3_stmt*,int); 72 | const void * (*column_table_name16)(sqlite3_stmt*,int); 73 | const unsigned char * (*column_text)(sqlite3_stmt*,int iCol); 74 | const void * (*column_text16)(sqlite3_stmt*,int iCol); 75 | int (*column_type)(sqlite3_stmt*,int iCol); 76 | sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol); 77 | void * (*commit_hook)(sqlite3*,int(*)(void*),void*); 78 | int (*complete)(const char*sql); 79 | int (*complete16)(const void*sql); 80 | int (*create_collation)(sqlite3*,const char*,int,void*, 81 | int(*)(void*,int,const void*,int,const void*)); 82 | int (*create_collation16)(sqlite3*,const void*,int,void*, 83 | int(*)(void*,int,const void*,int,const void*)); 84 | int (*create_function)(sqlite3*,const char*,int,int,void*, 85 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 86 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 87 | void (*xFinal)(sqlite3_context*)); 88 | int (*create_function16)(sqlite3*,const void*,int,int,void*, 89 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 90 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 91 | void (*xFinal)(sqlite3_context*)); 92 | int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); 93 | int (*data_count)(sqlite3_stmt*pStmt); 94 | sqlite3 * (*db_handle)(sqlite3_stmt*); 95 | int (*declare_vtab)(sqlite3*,const char*); 96 | int (*enable_shared_cache)(int); 97 | int (*errcode)(sqlite3*db); 98 | const char * (*errmsg)(sqlite3*); 99 | const void * (*errmsg16)(sqlite3*); 100 | int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**); 101 | int (*expired)(sqlite3_stmt*); 102 | int (*finalize)(sqlite3_stmt*pStmt); 103 | void (*free)(void*); 104 | void (*free_table)(char**result); 105 | int (*get_autocommit)(sqlite3*); 106 | void * (*get_auxdata)(sqlite3_context*,int); 107 | int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**); 108 | int (*global_recover)(void); 109 | void (*interruptx)(sqlite3*); 110 | sqlite_int64 (*last_insert_rowid)(sqlite3*); 111 | const char * (*libversion)(void); 112 | int (*libversion_number)(void); 113 | void *(*malloc)(int); 114 | char * (*mprintf)(const char*,...); 115 | int (*open)(const char*,sqlite3**); 116 | int (*open16)(const void*,sqlite3**); 117 | int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 118 | int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 119 | void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); 120 | void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); 121 | void *(*realloc)(void*,int); 122 | int (*reset)(sqlite3_stmt*pStmt); 123 | void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); 124 | void (*result_double)(sqlite3_context*,double); 125 | void (*result_error)(sqlite3_context*,const char*,int); 126 | void (*result_error16)(sqlite3_context*,const void*,int); 127 | void (*result_int)(sqlite3_context*,int); 128 | void (*result_int64)(sqlite3_context*,sqlite_int64); 129 | void (*result_null)(sqlite3_context*); 130 | void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*)); 131 | void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*)); 132 | void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*)); 133 | void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*)); 134 | void (*result_value)(sqlite3_context*,sqlite3_value*); 135 | void * (*rollback_hook)(sqlite3*,void(*)(void*),void*); 136 | int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*, 137 | const char*,const char*),void*); 138 | void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*)); 139 | char * (*snprintf)(int,char*,const char*,...); 140 | int (*step)(sqlite3_stmt*); 141 | int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*, 142 | char const**,char const**,int*,int*,int*); 143 | void (*thread_cleanup)(void); 144 | int (*total_changes)(sqlite3*); 145 | void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); 146 | int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); 147 | void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*, 148 | sqlite_int64),void*); 149 | void * (*user_data)(sqlite3_context*); 150 | const void * (*value_blob)(sqlite3_value*); 151 | int (*value_bytes)(sqlite3_value*); 152 | int (*value_bytes16)(sqlite3_value*); 153 | double (*value_double)(sqlite3_value*); 154 | int (*value_int)(sqlite3_value*); 155 | sqlite_int64 (*value_int64)(sqlite3_value*); 156 | int (*value_numeric_type)(sqlite3_value*); 157 | const unsigned char * (*value_text)(sqlite3_value*); 158 | const void * (*value_text16)(sqlite3_value*); 159 | const void * (*value_text16be)(sqlite3_value*); 160 | const void * (*value_text16le)(sqlite3_value*); 161 | int (*value_type)(sqlite3_value*); 162 | char *(*vmprintf)(const char*,va_list); 163 | /* Added ??? */ 164 | int (*overload_function)(sqlite3*, const char *zFuncName, int nArg); 165 | /* Added by 3.3.13 */ 166 | int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 167 | int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 168 | int (*clear_bindings)(sqlite3_stmt*); 169 | /* Added by 3.4.1 */ 170 | int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*, 171 | void (*xDestroy)(void *)); 172 | /* Added by 3.5.0 */ 173 | int (*bind_zeroblob)(sqlite3_stmt*,int,int); 174 | int (*blob_bytes)(sqlite3_blob*); 175 | int (*blob_close)(sqlite3_blob*); 176 | int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64, 177 | int,sqlite3_blob**); 178 | int (*blob_read)(sqlite3_blob*,void*,int,int); 179 | int (*blob_write)(sqlite3_blob*,const void*,int,int); 180 | int (*create_collation_v2)(sqlite3*,const char*,int,void*, 181 | int(*)(void*,int,const void*,int,const void*), 182 | void(*)(void*)); 183 | int (*file_control)(sqlite3*,const char*,int,void*); 184 | sqlite3_int64 (*memory_highwater)(int); 185 | sqlite3_int64 (*memory_used)(void); 186 | sqlite3_mutex *(*mutex_alloc)(int); 187 | void (*mutex_enter)(sqlite3_mutex*); 188 | void (*mutex_free)(sqlite3_mutex*); 189 | void (*mutex_leave)(sqlite3_mutex*); 190 | int (*mutex_try)(sqlite3_mutex*); 191 | int (*open_v2)(const char*,sqlite3**,int,const char*); 192 | int (*release_memory)(int); 193 | void (*result_error_nomem)(sqlite3_context*); 194 | void (*result_error_toobig)(sqlite3_context*); 195 | int (*sleep)(int); 196 | void (*soft_heap_limit)(int); 197 | sqlite3_vfs *(*vfs_find)(const char*); 198 | int (*vfs_register)(sqlite3_vfs*,int); 199 | int (*vfs_unregister)(sqlite3_vfs*); 200 | int (*xthreadsafe)(void); 201 | void (*result_zeroblob)(sqlite3_context*,int); 202 | void (*result_error_code)(sqlite3_context*,int); 203 | int (*test_control)(int, ...); 204 | void (*randomness)(int,void*); 205 | sqlite3 *(*context_db_handle)(sqlite3_context*); 206 | int (*extended_result_codes)(sqlite3*,int); 207 | int (*limit)(sqlite3*,int,int); 208 | sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); 209 | const char *(*sql)(sqlite3_stmt*); 210 | int (*status)(int,int*,int*,int); 211 | int (*backup_finish)(sqlite3_backup*); 212 | sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*); 213 | int (*backup_pagecount)(sqlite3_backup*); 214 | int (*backup_remaining)(sqlite3_backup*); 215 | int (*backup_step)(sqlite3_backup*,int); 216 | const char *(*compileoption_get)(int); 217 | int (*compileoption_used)(const char*); 218 | int (*create_function_v2)(sqlite3*,const char*,int,int,void*, 219 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 220 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 221 | void (*xFinal)(sqlite3_context*), 222 | void(*xDestroy)(void*)); 223 | int (*db_config)(sqlite3*,int,...); 224 | sqlite3_mutex *(*db_mutex)(sqlite3*); 225 | int (*db_status)(sqlite3*,int,int*,int*,int); 226 | int (*extended_errcode)(sqlite3*); 227 | void (*log)(int,const char*,...); 228 | sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64); 229 | const char *(*sourceid)(void); 230 | int (*stmt_status)(sqlite3_stmt*,int,int); 231 | int (*strnicmp)(const char*,const char*,int); 232 | int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*); 233 | int (*wal_autocheckpoint)(sqlite3*,int); 234 | int (*wal_checkpoint)(sqlite3*,const char*); 235 | void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*); 236 | int (*blob_reopen)(sqlite3_blob*,sqlite3_int64); 237 | int (*vtab_config)(sqlite3*,int op,...); 238 | int (*vtab_on_conflict)(sqlite3*); 239 | }; 240 | 241 | /* 242 | ** The following macros redefine the API routines so that they are 243 | ** redirected throught the global sqlite3_api structure. 244 | ** 245 | ** This header file is also used by the loadext.c source file 246 | ** (part of the main SQLite library - not an extension) so that 247 | ** it can get access to the sqlite3_api_routines structure 248 | ** definition. But the main library does not want to redefine 249 | ** the API. So the redefinition macros are only valid if the 250 | ** SQLITE_CORE macros is undefined. 251 | */ 252 | #ifndef SQLITE_CORE 253 | #define sqlite3_aggregate_context sqlite3_api->aggregate_context 254 | #ifndef SQLITE_OMIT_DEPRECATED 255 | #define sqlite3_aggregate_count sqlite3_api->aggregate_count 256 | #endif 257 | #define sqlite3_bind_blob sqlite3_api->bind_blob 258 | #define sqlite3_bind_double sqlite3_api->bind_double 259 | #define sqlite3_bind_int sqlite3_api->bind_int 260 | #define sqlite3_bind_int64 sqlite3_api->bind_int64 261 | #define sqlite3_bind_null sqlite3_api->bind_null 262 | #define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count 263 | #define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index 264 | #define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name 265 | #define sqlite3_bind_text sqlite3_api->bind_text 266 | #define sqlite3_bind_text16 sqlite3_api->bind_text16 267 | #define sqlite3_bind_value sqlite3_api->bind_value 268 | #define sqlite3_busy_handler sqlite3_api->busy_handler 269 | #define sqlite3_busy_timeout sqlite3_api->busy_timeout 270 | #define sqlite3_changes sqlite3_api->changes 271 | #define sqlite3_close sqlite3_api->close 272 | #define sqlite3_collation_needed sqlite3_api->collation_needed 273 | #define sqlite3_collation_needed16 sqlite3_api->collation_needed16 274 | #define sqlite3_column_blob sqlite3_api->column_blob 275 | #define sqlite3_column_bytes sqlite3_api->column_bytes 276 | #define sqlite3_column_bytes16 sqlite3_api->column_bytes16 277 | #define sqlite3_column_count sqlite3_api->column_count 278 | #define sqlite3_column_database_name sqlite3_api->column_database_name 279 | #define sqlite3_column_database_name16 sqlite3_api->column_database_name16 280 | #define sqlite3_column_decltype sqlite3_api->column_decltype 281 | #define sqlite3_column_decltype16 sqlite3_api->column_decltype16 282 | #define sqlite3_column_double sqlite3_api->column_double 283 | #define sqlite3_column_int sqlite3_api->column_int 284 | #define sqlite3_column_int64 sqlite3_api->column_int64 285 | #define sqlite3_column_name sqlite3_api->column_name 286 | #define sqlite3_column_name16 sqlite3_api->column_name16 287 | #define sqlite3_column_origin_name sqlite3_api->column_origin_name 288 | #define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16 289 | #define sqlite3_column_table_name sqlite3_api->column_table_name 290 | #define sqlite3_column_table_name16 sqlite3_api->column_table_name16 291 | #define sqlite3_column_text sqlite3_api->column_text 292 | #define sqlite3_column_text16 sqlite3_api->column_text16 293 | #define sqlite3_column_type sqlite3_api->column_type 294 | #define sqlite3_column_value sqlite3_api->column_value 295 | #define sqlite3_commit_hook sqlite3_api->commit_hook 296 | #define sqlite3_complete sqlite3_api->complete 297 | #define sqlite3_complete16 sqlite3_api->complete16 298 | #define sqlite3_create_collation sqlite3_api->create_collation 299 | #define sqlite3_create_collation16 sqlite3_api->create_collation16 300 | #define sqlite3_create_function sqlite3_api->create_function 301 | #define sqlite3_create_function16 sqlite3_api->create_function16 302 | #define sqlite3_create_module sqlite3_api->create_module 303 | #define sqlite3_create_module_v2 sqlite3_api->create_module_v2 304 | #define sqlite3_data_count sqlite3_api->data_count 305 | #define sqlite3_db_handle sqlite3_api->db_handle 306 | #define sqlite3_declare_vtab sqlite3_api->declare_vtab 307 | #define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache 308 | #define sqlite3_errcode sqlite3_api->errcode 309 | #define sqlite3_errmsg sqlite3_api->errmsg 310 | #define sqlite3_errmsg16 sqlite3_api->errmsg16 311 | #define sqlite3_exec sqlite3_api->exec 312 | #ifndef SQLITE_OMIT_DEPRECATED 313 | #define sqlite3_expired sqlite3_api->expired 314 | #endif 315 | #define sqlite3_finalize sqlite3_api->finalize 316 | #define sqlite3_free sqlite3_api->free 317 | #define sqlite3_free_table sqlite3_api->free_table 318 | #define sqlite3_get_autocommit sqlite3_api->get_autocommit 319 | #define sqlite3_get_auxdata sqlite3_api->get_auxdata 320 | #define sqlite3_get_table sqlite3_api->get_table 321 | #ifndef SQLITE_OMIT_DEPRECATED 322 | #define sqlite3_global_recover sqlite3_api->global_recover 323 | #endif 324 | #define sqlite3_interrupt sqlite3_api->interruptx 325 | #define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid 326 | #define sqlite3_libversion sqlite3_api->libversion 327 | #define sqlite3_libversion_number sqlite3_api->libversion_number 328 | #define sqlite3_malloc sqlite3_api->malloc 329 | #define sqlite3_mprintf sqlite3_api->mprintf 330 | #define sqlite3_open sqlite3_api->open 331 | #define sqlite3_open16 sqlite3_api->open16 332 | #define sqlite3_prepare sqlite3_api->prepare 333 | #define sqlite3_prepare16 sqlite3_api->prepare16 334 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 335 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 336 | #define sqlite3_profile sqlite3_api->profile 337 | #define sqlite3_progress_handler sqlite3_api->progress_handler 338 | #define sqlite3_realloc sqlite3_api->realloc 339 | #define sqlite3_reset sqlite3_api->reset 340 | #define sqlite3_result_blob sqlite3_api->result_blob 341 | #define sqlite3_result_double sqlite3_api->result_double 342 | #define sqlite3_result_error sqlite3_api->result_error 343 | #define sqlite3_result_error16 sqlite3_api->result_error16 344 | #define sqlite3_result_int sqlite3_api->result_int 345 | #define sqlite3_result_int64 sqlite3_api->result_int64 346 | #define sqlite3_result_null sqlite3_api->result_null 347 | #define sqlite3_result_text sqlite3_api->result_text 348 | #define sqlite3_result_text16 sqlite3_api->result_text16 349 | #define sqlite3_result_text16be sqlite3_api->result_text16be 350 | #define sqlite3_result_text16le sqlite3_api->result_text16le 351 | #define sqlite3_result_value sqlite3_api->result_value 352 | #define sqlite3_rollback_hook sqlite3_api->rollback_hook 353 | #define sqlite3_set_authorizer sqlite3_api->set_authorizer 354 | #define sqlite3_set_auxdata sqlite3_api->set_auxdata 355 | #define sqlite3_snprintf sqlite3_api->snprintf 356 | #define sqlite3_step sqlite3_api->step 357 | #define sqlite3_table_column_metadata sqlite3_api->table_column_metadata 358 | #define sqlite3_thread_cleanup sqlite3_api->thread_cleanup 359 | #define sqlite3_total_changes sqlite3_api->total_changes 360 | #define sqlite3_trace sqlite3_api->trace 361 | #ifndef SQLITE_OMIT_DEPRECATED 362 | #define sqlite3_transfer_bindings sqlite3_api->transfer_bindings 363 | #endif 364 | #define sqlite3_update_hook sqlite3_api->update_hook 365 | #define sqlite3_user_data sqlite3_api->user_data 366 | #define sqlite3_value_blob sqlite3_api->value_blob 367 | #define sqlite3_value_bytes sqlite3_api->value_bytes 368 | #define sqlite3_value_bytes16 sqlite3_api->value_bytes16 369 | #define sqlite3_value_double sqlite3_api->value_double 370 | #define sqlite3_value_int sqlite3_api->value_int 371 | #define sqlite3_value_int64 sqlite3_api->value_int64 372 | #define sqlite3_value_numeric_type sqlite3_api->value_numeric_type 373 | #define sqlite3_value_text sqlite3_api->value_text 374 | #define sqlite3_value_text16 sqlite3_api->value_text16 375 | #define sqlite3_value_text16be sqlite3_api->value_text16be 376 | #define sqlite3_value_text16le sqlite3_api->value_text16le 377 | #define sqlite3_value_type sqlite3_api->value_type 378 | #define sqlite3_vmprintf sqlite3_api->vmprintf 379 | #define sqlite3_overload_function sqlite3_api->overload_function 380 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 381 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 382 | #define sqlite3_clear_bindings sqlite3_api->clear_bindings 383 | #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob 384 | #define sqlite3_blob_bytes sqlite3_api->blob_bytes 385 | #define sqlite3_blob_close sqlite3_api->blob_close 386 | #define sqlite3_blob_open sqlite3_api->blob_open 387 | #define sqlite3_blob_read sqlite3_api->blob_read 388 | #define sqlite3_blob_write sqlite3_api->blob_write 389 | #define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 390 | #define sqlite3_file_control sqlite3_api->file_control 391 | #define sqlite3_memory_highwater sqlite3_api->memory_highwater 392 | #define sqlite3_memory_used sqlite3_api->memory_used 393 | #define sqlite3_mutex_alloc sqlite3_api->mutex_alloc 394 | #define sqlite3_mutex_enter sqlite3_api->mutex_enter 395 | #define sqlite3_mutex_free sqlite3_api->mutex_free 396 | #define sqlite3_mutex_leave sqlite3_api->mutex_leave 397 | #define sqlite3_mutex_try sqlite3_api->mutex_try 398 | #define sqlite3_open_v2 sqlite3_api->open_v2 399 | #define sqlite3_release_memory sqlite3_api->release_memory 400 | #define sqlite3_result_error_nomem sqlite3_api->result_error_nomem 401 | #define sqlite3_result_error_toobig sqlite3_api->result_error_toobig 402 | #define sqlite3_sleep sqlite3_api->sleep 403 | #define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit 404 | #define sqlite3_vfs_find sqlite3_api->vfs_find 405 | #define sqlite3_vfs_register sqlite3_api->vfs_register 406 | #define sqlite3_vfs_unregister sqlite3_api->vfs_unregister 407 | #define sqlite3_threadsafe sqlite3_api->xthreadsafe 408 | #define sqlite3_result_zeroblob sqlite3_api->result_zeroblob 409 | #define sqlite3_result_error_code sqlite3_api->result_error_code 410 | #define sqlite3_test_control sqlite3_api->test_control 411 | #define sqlite3_randomness sqlite3_api->randomness 412 | #define sqlite3_context_db_handle sqlite3_api->context_db_handle 413 | #define sqlite3_extended_result_codes sqlite3_api->extended_result_codes 414 | #define sqlite3_limit sqlite3_api->limit 415 | #define sqlite3_next_stmt sqlite3_api->next_stmt 416 | #define sqlite3_sql sqlite3_api->sql 417 | #define sqlite3_status sqlite3_api->status 418 | #define sqlite3_backup_finish sqlite3_api->backup_finish 419 | #define sqlite3_backup_init sqlite3_api->backup_init 420 | #define sqlite3_backup_pagecount sqlite3_api->backup_pagecount 421 | #define sqlite3_backup_remaining sqlite3_api->backup_remaining 422 | #define sqlite3_backup_step sqlite3_api->backup_step 423 | #define sqlite3_compileoption_get sqlite3_api->compileoption_get 424 | #define sqlite3_compileoption_used sqlite3_api->compileoption_used 425 | #define sqlite3_create_function_v2 sqlite3_api->create_function_v2 426 | #define sqlite3_db_config sqlite3_api->db_config 427 | #define sqlite3_db_mutex sqlite3_api->db_mutex 428 | #define sqlite3_db_status sqlite3_api->db_status 429 | #define sqlite3_extended_errcode sqlite3_api->extended_errcode 430 | #define sqlite3_log sqlite3_api->log 431 | #define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64 432 | #define sqlite3_sourceid sqlite3_api->sourceid 433 | #define sqlite3_stmt_status sqlite3_api->stmt_status 434 | #define sqlite3_strnicmp sqlite3_api->strnicmp 435 | #define sqlite3_unlock_notify sqlite3_api->unlock_notify 436 | #define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint 437 | #define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint 438 | #define sqlite3_wal_hook sqlite3_api->wal_hook 439 | #define sqlite3_blob_reopen sqlite3_api->blob_reopen 440 | #define sqlite3_vtab_config sqlite3_api->vtab_config 441 | #define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict 442 | #endif /* SQLITE_CORE */ 443 | 444 | #define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0; 445 | #define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v; 446 | 447 | #endif /* _SQLITE3EXT_H_ */ 448 | --------------------------------------------------------------------------------