Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Improved shell "dot" command argument handling. Ticket [f12a9eeedc]. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
9fb699193378bf812ef97889adc0b1a9 |
User & Date: | shaneh 2009-11-06 17:20:17.000 |
References
2009-11-06
| ||
17:22 | • Fixed ticket [f12a9eeedc]: Shell command argument parsing is lax plus 2 other changes (artifact: 84f729d1a8 user: shane) | |
Context
2009-11-10
| ||
01:12 | Omit some code that is not used when SQLITE_SECURE_DELETE is defined. (check-in: 5a9e746357 user: drh tags: trunk) | |
2009-11-06
| ||
17:20 | Improved shell "dot" command argument handling. Ticket [f12a9eeedc]. (check-in: 9fb6991933 user: shaneh tags: trunk) | |
04:13 | Fix the backup API so that a backup from an empty database to a non-empty database works. Ticket [0bf974bdf9]. The only changes are in assert() statements. (check-in: ddb71cd9ed user: drh tags: trunk) | |
Changes
Changes to src/shell.c.
︙ | ︙ | |||
2136 2137 2138 2139 2140 2141 2142 | ".bail ON|OFF Stop after hitting an error. Default OFF\n" ".databases List names and files of attached databases\n" ".dump ?TABLE? ... Dump the database in an SQL text format\n" " If TABLE specified, only dump tables matching\n" " LIKE pattern TABLE.\n" ".echo ON|OFF Turn command echo on or off\n" ".exit Exit this program\n" | | > | 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 | ".bail ON|OFF Stop after hitting an error. Default OFF\n" ".databases List names and files of attached databases\n" ".dump ?TABLE? ... Dump the database in an SQL text format\n" " If TABLE specified, only dump tables matching\n" " LIKE pattern TABLE.\n" ".echo ON|OFF Turn command echo on or off\n" ".exit Exit this program\n" ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n" " With no args, it turns EXPLAIN on.\n" #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_SUBQUERY) ".genfkey ?OPTIONS? Options are:\n" " --no-drop: Do not drop old fkey triggers.\n" " --ignore-errors: Ignore tables with fkey errors\n" " --exec: Execute generated SQL immediately\n" " See file tool/genfkey.README in the source \n" " distribution for further information.\n" |
︙ | ︙ | |||
2182 2183 2184 2185 2186 2187 2188 | " LIKE pattern TABLE.\n" ".separator STRING Change separator used by output mode and .import\n" ".show Show the current values for various settings\n" ".tables ?TABLE? List names of tables\n" " If TABLE specified, only list tables matching\n" " LIKE pattern TABLE.\n" ".timeout MS Try opening locked tables for MS milliseconds\n" | | | 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 | " LIKE pattern TABLE.\n" ".separator STRING Change separator used by output mode and .import\n" ".show Show the current values for various settings\n" ".tables ?TABLE? List names of tables\n" " If TABLE specified, only list tables matching\n" " LIKE pattern TABLE.\n" ".timeout MS Try opening locked tables for MS milliseconds\n" ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n" ; static char zTimerHelp[] = ".timer ON|OFF Turn the CPU timer measurement on or off\n" ; /* Forward reference */ |
︙ | ︙ | |||
2309 2310 2311 2312 2313 2314 2315 | } /* Process the input line. */ if( nArg==0 ) return 0; /* no tokens, no error */ n = strlen30(azArg[0]); c = azArg[0][0]; | | | 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 | } /* Process the input line. */ if( nArg==0 ) return 0; /* no tokens, no error */ n = strlen30(azArg[0]); c = azArg[0][0]; if( c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0 && nArg>1 && nArg<4){ const char *zDestFile; const char *zDb; sqlite3 *pDest; sqlite3_backup *pBackup; if( nArg==2 ){ zDestFile = azArg[1]; zDb = "main"; |
︙ | ︙ | |||
2345 2346 2347 2348 2349 2350 2351 | }else{ fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest)); rc = 1; } sqlite3_close(pDest); }else | | | | | 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 | }else{ fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest)); rc = 1; } sqlite3_close(pDest); }else if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 && nArg>1 && nArg<3 ){ bail_on_error = booleanValue(azArg[1]); }else if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){ struct callback_data data; char *zErrMsg = 0; open_db(p); memcpy(&data, p, sizeof(data)); data.showHeader = 1; data.mode = MODE_Column; data.colWidth[0] = 3; data.colWidth[1] = 15; data.colWidth[2] = 58; data.cnt = 0; sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg); if( zErrMsg ){ fprintf(stderr,"Error: %s\n", zErrMsg); sqlite3_free(zErrMsg); rc = 1; } }else if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){ char *zErrMsg = 0; open_db(p); /* When playing back a "dump", the content might appear in an order ** which causes immediate foreign key constraints to be violated. ** So disable foreign-key constraint enforcement to prevent problems. */ fprintf(p->out, "PRAGMA foreign_keys=OFF;\n"); fprintf(p->out, "BEGIN TRANSACTION;\n"); |
︙ | ︙ | |||
2421 2422 2423 2424 2425 2426 2427 | fprintf(stderr,"Error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(p->out, "COMMIT;\n"); } }else | | | | | 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 | fprintf(stderr,"Error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(p->out, "COMMIT;\n"); } }else if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){ p->echoOn = booleanValue(azArg[1]); }else if( c=='e' && strncmp(azArg[0], "exit", n)==0 && nArg==1 ){ rc = 2; }else if( c=='e' && strncmp(azArg[0], "explain", n)==0 && nArg<3 ){ int val = nArg>=2 ? booleanValue(azArg[1]) : 1; if(val == 1) { if(!p->explainPrev.valid) { p->explainPrev.valid = 1; p->explainPrev.mode = p->mode; p->explainPrev.showHeader = p->showHeader; memcpy(p->explainPrev.colWidth,p->colWidth,sizeof(p->colWidth)); |
︙ | ︙ | |||
2476 2477 2478 2479 2480 2481 2482 | cmd.pCb = p; genfkey_create_triggers(p->db, "main", (void *)&cmd, genfkeyCmdCb); } }else #endif if( c=='h' && (strncmp(azArg[0], "header", n)==0 || | | | | 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 | cmd.pCb = p; genfkey_create_triggers(p->db, "main", (void *)&cmd, genfkeyCmdCb); } }else #endif if( c=='h' && (strncmp(azArg[0], "header", n)==0 || strncmp(azArg[0], "headers", n)==0) && nArg>1 && nArg<3 ){ p->showHeader = booleanValue(azArg[1]); }else if( c=='h' && strncmp(azArg[0], "help", n)==0 ){ fprintf(stderr,"%s",zHelp); if( HAS_TIMER ){ fprintf(stderr,"%s",zTimerHelp); } }else if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){ char *zTable = azArg[2]; /* Insert data into this table */ char *zFile = azArg[1]; /* The file from which to extract data */ sqlite3_stmt *pStmt = NULL; /* A statement */ int nCol; /* Number of columns in the table */ int nByte; /* Number of bytes in an SQL string */ int i, j; /* Loop counters */ int nSep; /* Number of bytes in p->separator[] */ |
︙ | ︙ | |||
2604 2605 2606 2607 2608 2609 2610 | } /* end while */ free(azCol); fclose(in); sqlite3_finalize(pStmt); sqlite3_exec(p->db, zCommit, 0, 0, 0); }else | | | 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 | } /* end while */ free(azCol); fclose(in); sqlite3_finalize(pStmt); sqlite3_exec(p->db, zCommit, 0, 0, 0); }else if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){ struct callback_data data; char *zErrMsg = 0; open_db(p); memcpy(&data, p, sizeof(data)); data.showHeader = 0; data.mode = MODE_List; if( nArg==1 ){ |
︙ | ︙ | |||
2683 2684 2685 2686 2687 2688 2689 | fprintf(stderr, "Error: %s\n", zErrMsg); sqlite3_free(zErrMsg); rc = 1; } }else #endif | | | | | | | | | | | | < < < | < > > > > > > > > > > > > | 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 | fprintf(stderr, "Error: %s\n", zErrMsg); sqlite3_free(zErrMsg); rc = 1; } }else #endif if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){ int n2 = strlen30(azArg[1]); if( (n2==4 && strncmp(azArg[1],"line",n2)==0) || (n2==5 && strncmp(azArg[1],"lines",n2)==0) ){ p->mode = MODE_Line; }else if( (n2==6 && strncmp(azArg[1],"column",n2)==0) || (n2==7 && strncmp(azArg[1],"columns",n2)==0) ){ p->mode = MODE_Column; }else if( n2==4 && strncmp(azArg[1],"list",n2)==0 ){ p->mode = MODE_List; }else if( n2==4 && strncmp(azArg[1],"html",n2)==0 ){ p->mode = MODE_Html; }else if( n2==3 && strncmp(azArg[1],"tcl",n2)==0 ){ p->mode = MODE_Tcl; }else if( n2==3 && strncmp(azArg[1],"csv",n2)==0 ){ p->mode = MODE_Csv; sqlite3_snprintf(sizeof(p->separator), p->separator, ","); }else if( n2==4 && strncmp(azArg[1],"tabs",n2)==0 ){ p->mode = MODE_List; sqlite3_snprintf(sizeof(p->separator), p->separator, "\t"); }else if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){ p->mode = MODE_Insert; set_table_name(p, "table"); }else { fprintf(stderr,"Error: mode should be one of: " "column csv html insert line list tabs tcl\n"); rc = 1; } }else if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==3 ){ int n2 = strlen30(azArg[1]); if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){ p->mode = MODE_Insert; set_table_name(p, azArg[2]); }else { fprintf(stderr, "Error: invalid arguments: " " \"%s\". Enter \".help\" for help\n", azArg[2]); rc = 1; } }else if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) { sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue, "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]); }else if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){ |
︙ | ︙ | |||
2752 2753 2754 2755 2756 2757 2758 | strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); } if( nArg >= 3) { strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1); } }else | | | | 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 | strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); } if( nArg >= 3) { strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1); } }else if( c=='q' && strncmp(azArg[0], "quit", n)==0 && nArg==1 ){ rc = 2; }else if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 && nArg==2 ){ FILE *alt = fopen(azArg[1], "rb"); if( alt==0 ){ fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); rc = 1; }else{ rc = process_input(p, alt); fclose(alt); } }else if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 && nArg>1 && nArg<4){ const char *zSrcFile; const char *zDb; sqlite3 *pSrc; sqlite3_backup *pBackup; int nTimeout = 0; if( nArg==2 ){ |
︙ | ︙ | |||
2814 2815 2816 2817 2818 2819 2820 | }else{ fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); rc = 1; } sqlite3_close(pSrc); }else | | | 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 | }else{ fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); rc = 1; } sqlite3_close(pSrc); }else if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){ struct callback_data data; char *zErrMsg = 0; open_db(p); memcpy(&data, p, sizeof(data)); data.showHeader = 0; data.mode = MODE_Semi; if( nArg>1 ){ |
︙ | ︙ | |||
2892 2893 2894 2895 2896 2897 2898 | }else if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){ sqlite3_snprintf(sizeof(p->separator), p->separator, "%.*s", (int)sizeof(p->separator)-1, azArg[1]); }else | | | | 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 | }else if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){ sqlite3_snprintf(sizeof(p->separator), p->separator, "%.*s", (int)sizeof(p->separator)-1, azArg[1]); }else if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){ int i; fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off"); fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]); fprintf(p->out,"%9.9s: ", "nullvalue"); output_c_string(p->out, p->nullvalue); fprintf(p->out, "\n"); fprintf(p->out,"%9.9s: %s\n","output", strlen30(p->outfile) ? p->outfile : "stdout"); fprintf(p->out,"%9.9s: ", "separator"); output_c_string(p->out, p->separator); fprintf(p->out, "\n"); fprintf(p->out,"%9.9s: ","width"); for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) { fprintf(p->out,"%d ",p->colWidth[i]); } fprintf(p->out,"\n"); }else if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){ char **azResult; int nRow; char *zErrMsg; open_db(p); if( nArg==1 ){ rc = sqlite3_get_table(p->db, "SELECT name FROM sqlite_master " |
︙ | ︙ | |||
2971 2972 2973 2974 2975 2976 2977 | } printf("\n"); } } sqlite3_free_table(azResult); }else | | > > | > > | | 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 | } printf("\n"); } } sqlite3_free_table(azResult); }else if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){ open_db(p); sqlite3_busy_timeout(p->db, atoi(azArg[1])); }else if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 && nArg==2 ){ enableTimer = booleanValue(azArg[1]); }else if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){ int j; assert( nArg<=ArraySize(azArg) ); for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){ p->colWidth[j-1] = atoi(azArg[j]); } }else |
︙ | ︙ |
Changes to tool/shell1.test.
︙ | ︙ | |||
12 13 14 15 16 17 18 | # The focus of this file is testing the CLI shell tool. # # $Id: shell1.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ # # Test plan: # | | > > | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > | | | > > > > | > > > > | | > > > > | | | > > > > | > > > > | | < > > | | > > > > | > | > > > | | | | > > > > > | | > > > > | > > > > > > > > | | | > > > > | | > > > > | | | | | | | | | | > > > > > > > > > > > > > > > | | > > > > | | > > > > | > > > > | | | > > > > | > > > > | | > > > > | | > > > > > > > | | > > > > | | > > > > | > > > > | | > > > > | | | | > > > > | < < > | | | | | > | | | > > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | # The focus of this file is testing the CLI shell tool. # # $Id: shell1.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ # # Test plan: # # shell-1.*: Basic "dot" command token parsing. # shell-2.*: Basic test that "dot" command can be called. # package require sqlite3 proc do_test {name cmd expected} { puts -nonewline "$name ..." set res [uplevel $cmd] if {$res eq $expected} { puts Ok } else { puts Error puts " Got: $res" puts " Expected: $expected" exit } } proc execsql {sql} { uplevel [list db eval $sql] } proc catchsql {sql} { set rc [catch {uplevel [list db eval $sql]} msg] list $rc $msg } proc catchcmd {cmd} { set out [open cmds.txt w] puts $out $cmd close $out set rc [catch { exec ./sqlite test.db < cmds.txt } msg] list $rc $msg } file delete -force test.db test.db.journal sqlite3 db test.db #---------------------------------------------------------------------------- # Test cases shell-1.* Basic "dot" command token parsing. # # check first token handling do_test shell-1.1.1 { catchcmd ".foo" } {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}} do_test shell-1.1.2 { catchcmd ".\"foo OFF\"" } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} do_test shell-1.1.3 { catchcmd ".\'foo OFF\'" } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} # unbalanced quotes do_test shell-1.2.1 { catchcmd ".\"foo OFF" } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} do_test shell-1.2.2 { catchcmd ".\'foo OFF" } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} do_test shell-1.2.3 { catchcmd ".explain \"OFF" } {0 {}} do_test shell-1.2.4 { catchcmd ".explain \'OFF" } {0 {}} do_test shell-1.2.5 { catchcmd ".mode \"insert FOO" } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} do_test shell-1.2.6 { catchcmd ".mode \'insert FOO" } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} # check multiple tokens, and quoted tokens do_test shell-1.3.1 { catchcmd ".explain 1" } {0 {}} do_test shell-1.3.2 { catchcmd ".explain on" } {0 {}} do_test shell-1.3.3 { catchcmd ".explain \"1 2 3\"" } {0 {}} do_test shell-1.3.4 { catchcmd ".explain \"OFF\"" } {0 {}} do_test shell-1.3.5 { catchcmd ".\'explain\' \'OFF\'" } {0 {}} do_test shell-1.3.6 { catchcmd ".explain \'OFF\'" } {0 {}} do_test shell-1.3.7 { catchcmd ".\'explain\' \'OFF\'" } {0 {}} # check quoted args are unquoted do_test shell-1.4.1 { catchcmd ".mode FOO" } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} do_test shell-1.4.2 { catchcmd ".mode csv" } {0 {}} do_test shell-1.4.2 { catchcmd ".mode \"csv\"" } {0 {}} #---------------------------------------------------------------------------- # Test cases shell-2.* Basic test that "dot" command can be called. # # .backup ?DB? FILE Backup DB (default "main") to FILE do_test shell-2.1.1 { catchcmd ".backup" } {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for help}} do_test shell-2.1.2 { # catchcmd ".backup FOO" #TBD!!! this asserts currently } {} do_test shell-2.1.3 { catchcmd ".backup FOO BAR" } {1 {Error: unknown database FOO}} do_test shell-2.1.4 { # too many arguments catchcmd ".backup FOO BAR BAD" } {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for help}} # .bail ON|OFF Stop after hitting an error. Default OFF do_test shell-2.2.1 { catchcmd ".bail" } {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}} do_test shell-2.2.2 { catchcmd ".bail ON" } {0 {}} do_test shell-2.2.3 { catchcmd ".bail OFF" } {0 {}} do_test shell-2.2.4 { # too many arguments catchcmd ".bail OFF BAD" } {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}} # .databases List names and files of attached databases do_test shell-2.3.1 { set res [catchcmd ".databases"] regexp {0.*main.*test\.db} $res } {1} do_test shell-2.3.2 { # too many arguments catchcmd ".databases BAD" } {1 {Error: unknown command or invalid arguments: "databases". Enter ".help" for help}} # .dump ?TABLE? ... Dump the database in an SQL text format # If TABLE specified, only dump tables matching # LIKE pattern TABLE. do_test shell-2.4.1 { set res [catchcmd ".dump"] list [regexp {BEGIN TRANSACTION;} $res] \ [regexp {COMMIT;} $res] } {1 1} do_test shell-2.4.2 { set res [catchcmd ".dump FOO"] list [regexp {BEGIN TRANSACTION;} $res] \ [regexp {COMMIT;} $res] } {1 1} do_test shell-2.4.3 { # too many arguments catchcmd ".dump FOO BAD" } {1 {Error: unknown command or invalid arguments: "dump". Enter ".help" for help}} # .echo ON|OFF Turn command echo on or off do_test shell-2.5.1 { catchcmd ".echo" } {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}} do_test shell-2.5.2 { catchcmd ".echo ON" } {0 {}} do_test shell-2.5.3 { catchcmd ".echo OFF" } {0 {}} do_test shell-2.5.4 { # too many arguments catchcmd ".echo OFF BAD" } {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}} # .exit Exit this program do_test shell-2.6.1 { catchcmd ".exit" } {0 {}} do_test shell-2.6.2 { # too many arguments catchcmd ".exit BAD" } {1 {Error: unknown command or invalid arguments: "exit". Enter ".help" for help}} # .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. do_test shell-2.7.1 { catchcmd ".explain" # explain is the exception to the booleans. without an option, it turns it on. } {0 {}} do_test shell-2.7.2 { catchcmd ".explain ON" } {0 {}} do_test shell-2.7.3 { catchcmd ".explain OFF" } {0 {}} do_test shell-2.7.4 { # too many arguments catchcmd ".explain OFF BAD" } {1 {Error: unknown command or invalid arguments: "explain". Enter ".help" for help}} # .genfkey ?OPTIONS? Options are: # --no-drop: Do not drop old fkey triggers. # --ignore-errors: Ignore tables with fkey errors # --exec: Execute generated SQL immediately # See file tool/genfkey.README in the source # distribution for further information. do_test shell-2.8.1 { catchcmd ".genfkey" } {0 {}} do_test shell-2.8.2 { catchcmd ".genfkey FOO" } {1 {unknown option: FOO}} # .header(s) ON|OFF Turn display of headers on or off do_test shell-2.9.1 { catchcmd ".header" } {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}} do_test shell-2.9.2 { catchcmd ".header ON" } {0 {}} do_test shell-2.9.3 { catchcmd ".header OFF" } {0 {}} do_test shell-2.9.4 { # too many arguments catchcmd ".header OFF BAD" } {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}} do_test shell-2.9.5 { catchcmd ".headers" } {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}} do_test shell-2.9.6 { catchcmd ".headers ON" } {0 {}} do_test shell-2.9.7 { catchcmd ".headers OFF" } {0 {}} do_test shell-2.9.8 { # too many arguments catchcmd ".headers OFF BAD" } {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}} # .help Show this message do_test shell-2.10.1 { set res [catchcmd ".help"] # look for a few of the possible help commands list [regexp {.help} $res] \ [regexp {.quit} $res] \ [regexp {.show} $res] } {1 1 1} do_test shell-2.10.2 { # we allow .help to take extra args (it is help after all) set res [catchcmd ".help BAD"] # look for a few of the possible help commands list [regexp {.help} $res] \ [regexp {.quit} $res] \ [regexp {.show} $res] } {1 1 1} # .import FILE TABLE Import data from FILE into TABLE do_test shell-2.11.1 { catchcmd ".import" } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}} do_test shell-2.11.2 { catchcmd ".import FOO" } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}} do_test shell-2.11.2 { catchcmd ".import FOO BAR" } {1 {Error: no such table: BAR}} do_test shell-2.11.3 { # too many arguments catchcmd ".import FOO BAR BAD" } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}} # .indices ?TABLE? Show names of all indices # If TABLE specified, only show indices for tables # matching LIKE pattern TABLE. do_test shell-2.12.1 { catchcmd ".indices" } {0 {}} do_test shell-2.12.2 { catchcmd ".indices FOO" } {0 {}} do_test shell-2.12.3 { # too many arguments catchcmd ".indices FOO BAD" } {1 {Error: unknown command or invalid arguments: "indices". Enter ".help" for help}} # .mode MODE ?TABLE? Set output mode where MODE is one of: # csv Comma-separated values # column Left-aligned columns. (See .width) # html HTML <table> code # insert SQL insert statements for TABLE # line One value per line # list Values delimited by .separator string # tabs Tab-separated values # tcl TCL list elements do_test shell-2.13.1 { catchcmd ".mode" } {1 {Error: unknown command or invalid arguments: "mode". Enter ".help" for help}} do_test shell-2.13.2 { catchcmd ".mode FOO" } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} do_test shell-2.13.3 { catchcmd ".mode csv" } {0 {}} do_test shell-2.13.4 { catchcmd ".mode column" } {0 {}} do_test shell-2.13.5 { catchcmd ".mode html" } {0 {}} do_test shell-2.13.6 { catchcmd ".mode insert" } {0 {}} do_test shell-2.13.7 { catchcmd ".mode line" } {0 {}} do_test shell-2.13.8 { catchcmd ".mode list" } {0 {}} do_test shell-2.13.9 { catchcmd ".mode tabs" } {0 {}} do_test shell-2.13.10 { catchcmd ".mode tcl" } {0 {}} do_test shell-2.13.11 { # too many arguments catchcmd ".mode tcl BAD" } {1 {Error: invalid arguments: "BAD". Enter ".help" for help}} # don't allow partial mode type matches do_test shell-2.13.12 { catchcmd ".mode l" } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} do_test shell-2.13.13 { catchcmd ".mode li" } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} do_test shell-2.13.14 { catchcmd ".mode lin" } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} # .nullvalue STRING Print STRING in place of NULL values do_test shell-2.14.1 { catchcmd ".nullvalue" } {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}} do_test shell-2.14.2 { catchcmd ".nullvalue FOO" } {0 {}} do_test shell-2.14.3 { # too many arguments catchcmd ".nullvalue FOO BAD" } {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}} # .output FILENAME Send output to FILENAME do_test shell-2.15.1 { catchcmd ".output" } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}} do_test shell-2.15.2 { catchcmd ".output FOO" } {0 {}} do_test shell-2.15.3 { # too many arguments catchcmd ".output FOO BAD" } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}} # .output stdout Send output to the screen do_test shell-2.16.1 { catchcmd ".output stdout" } {0 {}} do_test shell-2.16.2 { # too many arguments catchcmd ".output stdout BAD" } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}} # .prompt MAIN CONTINUE Replace the standard prompts do_test shell-2.17.1 { catchcmd ".prompt" } {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}} do_test shell-2.17.2 { catchcmd ".prompt FOO" } {0 {}} do_test shell-2.17.3 { catchcmd ".prompt FOO BAR" } {0 {}} do_test shell-2.17.4 { # too many arguments catchcmd ".prompt FOO BAR BAD" } {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}} # .quit Exit this program do_test shell-2.18.1 { catchcmd ".quit" } {0 {}} do_test shell-2.18.2 { # too many arguments catchcmd ".quit BAD" } {1 {Error: unknown command or invalid arguments: "quit". Enter ".help" for help}} # .read FILENAME Execute SQL in FILENAME do_test shell-2.19.1 { catchcmd ".read" } {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}} do_test shell-2.19.2 { file delete -force FOO catchcmd ".read FOO" } {1 {Error: cannot open "FOO"}} do_test shell-2.19.3 { # too many arguments catchcmd ".read FOO BAD" } {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}} # .restore ?DB? FILE Restore content of DB (default "main") from FILE do_test shell-2.20.1 { catchcmd ".restore" } {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}} do_test shell-2.20.2 { # catchcmd ".restore FOO" #TBD!!! this asserts currently } {} do_test shell-2.20.3 { catchcmd ".restore FOO BAR" } {1 {Error: unknown database FOO}} do_test shell-2.20.4 { # too many arguments catchcmd ".restore FOO BAR BAD" } {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}} # .schema ?TABLE? Show the CREATE statements # If TABLE specified, only show tables matching # LIKE pattern TABLE. do_test shell-2.21.1 { catchcmd ".schema" } {0 {}} do_test shell-2.21.2 { catchcmd ".schema FOO" } {0 {}} do_test shell-2.21.3 { # too many arguments catchcmd ".schema FOO BAD" } {1 {Error: unknown command or invalid arguments: "schema". Enter ".help" for help}} # .separator STRING Change separator used by output mode and .import do_test shell-2.22.1 { catchcmd ".separator" } {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}} do_test shell-2.22.2 { catchcmd ".separator FOO" } {0 {}} do_test shell-2.22.3 { # too many arguments catchcmd ".separator FOO BAD" } {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}} # .show Show the current values for various settings do_test shell-2.23.1 { set res [catchcmd ".show"] list [regexp {echo:} $res] \ [regexp {explain:} $res] \ [regexp {headers:} $res] \ [regexp {mode:} $res] \ [regexp {nullvalue:} $res] \ [regexp {output:} $res] \ [regexp {separator:} $res] \ [regexp {width:} $res] } {1 1 1 1 1 1 1 1} do_test shell-2.23.2 { # too many arguments catchcmd ".show BAD" } {1 {Error: unknown command or invalid arguments: "show". Enter ".help" for help}} # .tables ?TABLE? List names of tables # If TABLE specified, only list tables matching # LIKE pattern TABLE. do_test shell-2.24.1 { catchcmd ".tables" } {0 {}} do_test shell-2.24.2 { catchcmd ".tables FOO" } {0 {}} do_test shell-2.24.3 { # too many arguments catchcmd ".tables FOO BAD" } {1 {Error: unknown command or invalid arguments: "tables". Enter ".help" for help}} # .timeout MS Try opening locked tables for MS milliseconds do_test shell-2.25.1 { catchcmd ".timeout" } {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}} do_test shell-2.25.2 { catchcmd ".timeout zzz" # this should be treated the same as a '0' timeout } {0 {}} do_test shell-2.25.3 { catchcmd ".timeout 1" } {0 {}} do_test shell-2.25.4 { # too many arguments catchcmd ".timeout 1 BAD" } {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}} # .width NUM NUM ... Set column widths for "column" mode do_test shell-2.26.1 { catchcmd ".width" } {1 {Error: unknown command or invalid arguments: "width". Enter ".help" for help}} do_test shell-2.26.2 { catchcmd ".width xxx" # this should be treated the same as a '0' width for col 1 } {0 {}} do_test shell-2.26.3 { catchcmd ".width xxx yyy" # this should be treated the same as a '0' width for col 1 and 2 } {0 {}} do_test shell-2.26.4 { catchcmd ".width 1 1" # this should be treated the same as a '1' width for col 1 and 2 } {0 {}} # .timer ON|OFF Turn the CPU timer measurement on or off do_test shell-2.27.1 { catchcmd ".timer" } {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}} do_test shell-2.27.2 { catchcmd ".timer ON" } {0 {}} do_test shell-2.27.3 { catchcmd ".timer OFF" } {0 {}} do_test shell-2.27.4 { # too many arguments catchcmd ".timer OFF BAD" } {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}} # |