| | @@ -334,11 +334,11 @@ |
| 334 | 334 | /* |
| 335 | 335 | ** The following is the open SQLite database. We make a pointer |
| 336 | 336 | ** to this database a static variable so that it can be accessed |
| 337 | 337 | ** by the SIGINT handler to interrupt database processing. |
| 338 | 338 | */ |
| 339 | | -static sqlite3 *db = 0; |
| 339 | +static sqlite3 *globalDb = 0; |
| 340 | 340 | |
| 341 | 341 | /* |
| 342 | 342 | ** True if an interrupt (Control-C) has been received. |
| 343 | 343 | */ |
| 344 | 344 | static volatile int seenInterrupt = 0; |
| | @@ -803,11 +803,11 @@ |
| 803 | 803 | */ |
| 804 | 804 | static void interrupt_handler(int NotUsed){ |
| 805 | 805 | UNUSED_PARAMETER(NotUsed); |
| 806 | 806 | seenInterrupt++; |
| 807 | 807 | if( seenInterrupt>2 ) exit(1); |
| 808 | | - if( db ) sqlite3_interrupt(db); |
| 808 | + if( globalDb ) sqlite3_interrupt(globalDb); |
| 809 | 809 | } |
| 810 | 810 | #endif |
| 811 | 811 | |
| 812 | 812 | /* |
| 813 | 813 | ** This is the callback routine that the shell |
| | @@ -1907,27 +1907,27 @@ |
| 1907 | 1907 | */ |
| 1908 | 1908 | static void open_db(ShellState *p, int keepAlive){ |
| 1909 | 1909 | if( p->db==0 ){ |
| 1910 | 1910 | sqlite3_initialize(); |
| 1911 | 1911 | sqlite3_open(p->zDbFilename, &p->db); |
| 1912 | | - db = p->db; |
| 1913 | | - if( db && sqlite3_errcode(db)==SQLITE_OK ){ |
| 1914 | | - sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0, |
| 1912 | + globalDb = p->db; |
| 1913 | + if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){ |
| 1914 | + sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0, |
| 1915 | 1915 | shellstaticFunc, 0, 0); |
| 1916 | 1916 | } |
| 1917 | | - if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){ |
| 1917 | + if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ |
| 1918 | 1918 | fprintf(stderr,"Error: unable to open database \"%s\": %s\n", |
| 1919 | | - p->zDbFilename, sqlite3_errmsg(db)); |
| 1919 | + p->zDbFilename, sqlite3_errmsg(p->db)); |
| 1920 | 1920 | if( keepAlive ) return; |
| 1921 | 1921 | exit(1); |
| 1922 | 1922 | } |
| 1923 | 1923 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 1924 | 1924 | sqlite3_enable_load_extension(p->db, 1); |
| 1925 | 1925 | #endif |
| 1926 | | - sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0, |
| 1926 | + sqlite3_create_function(p->db, "readfile", 1, SQLITE_UTF8, 0, |
| 1927 | 1927 | readfileFunc, 0, 0); |
| 1928 | | - sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0, |
| 1928 | + sqlite3_create_function(p->db, "writefile", 2, SQLITE_UTF8, 0, |
| 1929 | 1929 | writefileFunc, 0, 0); |
| 1930 | 1930 | } |
| 1931 | 1931 | } |
| 1932 | 1932 | |
| 1933 | 1933 | /* |
| | @@ -2584,36 +2584,36 @@ |
| 2584 | 2584 | ** process that line. |
| 2585 | 2585 | ** |
| 2586 | 2586 | ** Return 1 on error, 2 to exit, and 0 otherwise. |
| 2587 | 2587 | */ |
| 2588 | 2588 | static int do_meta_command(char *zLine, ShellState *p){ |
| 2589 | | - int i = 1; |
| 2589 | + int h = 1; |
| 2590 | 2590 | int nArg = 0; |
| 2591 | 2591 | int n, c; |
| 2592 | 2592 | int rc = 0; |
| 2593 | 2593 | char *azArg[50]; |
| 2594 | 2594 | |
| 2595 | 2595 | /* Parse the input line into tokens. |
| 2596 | 2596 | */ |
| 2597 | | - while( zLine[i] && nArg<ArraySize(azArg) ){ |
| 2598 | | - while( IsSpace(zLine[i]) ){ i++; } |
| 2599 | | - if( zLine[i]==0 ) break; |
| 2600 | | - if( zLine[i]=='\'' || zLine[i]=='"' ){ |
| 2601 | | - int delim = zLine[i++]; |
| 2602 | | - azArg[nArg++] = &zLine[i]; |
| 2603 | | - while( zLine[i] && zLine[i]!=delim ){ |
| 2604 | | - if( zLine[i]=='\\' && delim=='"' && zLine[i+1]!=0 ) i++; |
| 2605 | | - i++; |
| 2606 | | - } |
| 2607 | | - if( zLine[i]==delim ){ |
| 2608 | | - zLine[i++] = 0; |
| 2597 | + while( zLine[h] && nArg<ArraySize(azArg) ){ |
| 2598 | + while( IsSpace(zLine[h]) ){ h++; } |
| 2599 | + if( zLine[h]==0 ) break; |
| 2600 | + if( zLine[h]=='\'' || zLine[h]=='"' ){ |
| 2601 | + int delim = zLine[h++]; |
| 2602 | + azArg[nArg++] = &zLine[h]; |
| 2603 | + while( zLine[h] && zLine[h]!=delim ){ |
| 2604 | + if( zLine[h]=='\\' && delim=='"' && zLine[h+1]!=0 ) h++; |
| 2605 | + h++; |
| 2606 | + } |
| 2607 | + if( zLine[h]==delim ){ |
| 2608 | + zLine[h++] = 0; |
| 2609 | 2609 | } |
| 2610 | 2610 | if( delim=='"' ) resolve_backslashes(azArg[nArg-1]); |
| 2611 | 2611 | }else{ |
| 2612 | | - azArg[nArg++] = &zLine[i]; |
| 2613 | | - while( zLine[i] && !IsSpace(zLine[i]) ){ i++; } |
| 2614 | | - if( zLine[i] ) zLine[i++] = 0; |
| 2612 | + azArg[nArg++] = &zLine[h]; |
| 2613 | + while( zLine[h] && !IsSpace(zLine[h]) ){ h++; } |
| 2614 | + if( zLine[h] ) zLine[h++] = 0; |
| 2615 | 2615 | resolve_backslashes(azArg[nArg-1]); |
| 2616 | 2616 | } |
| 2617 | 2617 | } |
| 2618 | 2618 | |
| 2619 | 2619 | /* Process the input line. |
| | @@ -2985,11 +2985,11 @@ |
| 2985 | 2985 | return 1; |
| 2986 | 2986 | } |
| 2987 | 2987 | nByte = strlen30(zSql); |
| 2988 | 2988 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 2989 | 2989 | import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */ |
| 2990 | | - if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){ |
| 2990 | + if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){ |
| 2991 | 2991 | char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable); |
| 2992 | 2992 | char cSep = '('; |
| 2993 | 2993 | while( xRead(&sCtx) ){ |
| 2994 | 2994 | zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z); |
| 2995 | 2995 | cSep = ','; |
| | @@ -3005,21 +3005,21 @@ |
| 3005 | 3005 | zCreate = sqlite3_mprintf("%z\n)", zCreate); |
| 3006 | 3006 | rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); |
| 3007 | 3007 | sqlite3_free(zCreate); |
| 3008 | 3008 | if( rc ){ |
| 3009 | 3009 | fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable, |
| 3010 | | - sqlite3_errmsg(db)); |
| 3010 | + sqlite3_errmsg(p->db)); |
| 3011 | 3011 | sqlite3_free(sCtx.z); |
| 3012 | 3012 | xCloser(sCtx.in); |
| 3013 | 3013 | return 1; |
| 3014 | 3014 | } |
| 3015 | 3015 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 3016 | 3016 | } |
| 3017 | 3017 | sqlite3_free(zSql); |
| 3018 | 3018 | if( rc ){ |
| 3019 | 3019 | if (pStmt) sqlite3_finalize(pStmt); |
| 3020 | | - fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db)); |
| 3020 | + fprintf(stderr,"Error: %s\n", sqlite3_errmsg(p->db)); |
| 3021 | 3021 | xCloser(sCtx.in); |
| 3022 | 3022 | return 1; |
| 3023 | 3023 | } |
| 3024 | 3024 | nCol = sqlite3_column_count(pStmt); |
| 3025 | 3025 | sqlite3_finalize(pStmt); |
| | @@ -3040,17 +3040,17 @@ |
| 3040 | 3040 | zSql[j++] = ')'; |
| 3041 | 3041 | zSql[j] = 0; |
| 3042 | 3042 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 3043 | 3043 | sqlite3_free(zSql); |
| 3044 | 3044 | if( rc ){ |
| 3045 | | - fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db)); |
| 3045 | + fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); |
| 3046 | 3046 | if (pStmt) sqlite3_finalize(pStmt); |
| 3047 | 3047 | xCloser(sCtx.in); |
| 3048 | 3048 | return 1; |
| 3049 | 3049 | } |
| 3050 | | - needCommit = sqlite3_get_autocommit(db); |
| 3051 | | - if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0); |
| 3050 | + needCommit = sqlite3_get_autocommit(p->db); |
| 3051 | + if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0); |
| 3052 | 3052 | do{ |
| 3053 | 3053 | int startLine = sCtx.nLine; |
| 3054 | 3054 | for(i=0; i<nCol; i++){ |
| 3055 | 3055 | char *z = xRead(&sCtx); |
| 3056 | 3056 | /* |
| | @@ -3085,19 +3085,19 @@ |
| 3085 | 3085 | if( i>=nCol ){ |
| 3086 | 3086 | sqlite3_step(pStmt); |
| 3087 | 3087 | rc = sqlite3_reset(pStmt); |
| 3088 | 3088 | if( rc!=SQLITE_OK ){ |
| 3089 | 3089 | fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine, |
| 3090 | | - sqlite3_errmsg(db)); |
| 3090 | + sqlite3_errmsg(p->db)); |
| 3091 | 3091 | } |
| 3092 | 3092 | } |
| 3093 | 3093 | }while( sCtx.cTerm!=EOF ); |
| 3094 | 3094 | |
| 3095 | 3095 | xCloser(sCtx.in); |
| 3096 | 3096 | sqlite3_free(sCtx.z); |
| 3097 | 3097 | sqlite3_finalize(pStmt); |
| 3098 | | - if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0); |
| 3098 | + if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); |
| 3099 | 3099 | }else |
| 3100 | 3100 | |
| 3101 | 3101 | if( c=='i' && (strncmp(azArg[0], "indices", n)==0 |
| 3102 | 3102 | || strncmp(azArg[0], "indexes", n)==0) ){ |
| 3103 | 3103 | ShellState data; |
| | @@ -3647,17 +3647,17 @@ |
| 3647 | 3647 | sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC); |
| 3648 | 3648 | } |
| 3649 | 3649 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 3650 | 3650 | if( nRow>=nAlloc ){ |
| 3651 | 3651 | char **azNew; |
| 3652 | | - int n = nAlloc*2 + 10; |
| 3653 | | - azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n); |
| 3652 | + int n2 = nAlloc*2 + 10; |
| 3653 | + azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2); |
| 3654 | 3654 | if( azNew==0 ){ |
| 3655 | 3655 | fprintf(stderr, "Error: out of memory\n"); |
| 3656 | 3656 | break; |
| 3657 | 3657 | } |
| 3658 | | - nAlloc = n; |
| 3658 | + nAlloc = n2; |
| 3659 | 3659 | azResult = azNew; |
| 3660 | 3660 | } |
| 3661 | 3661 | azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0)); |
| 3662 | 3662 | if( azResult[nRow] ) nRow++; |
| 3663 | 3663 | } |
| | @@ -3706,19 +3706,19 @@ |
| 3706 | 3706 | { "byteorder", SQLITE_TESTCTRL_BYTEORDER }, |
| 3707 | 3707 | { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT }, |
| 3708 | 3708 | { "imposter", SQLITE_TESTCTRL_IMPOSTER }, |
| 3709 | 3709 | }; |
| 3710 | 3710 | int testctrl = -1; |
| 3711 | | - int rc = 0; |
| 3712 | | - int i, n; |
| 3711 | + int rc2 = 0; |
| 3712 | + int i, n2; |
| 3713 | 3713 | open_db(p, 0); |
| 3714 | 3714 | |
| 3715 | 3715 | /* convert testctrl text option to value. allow any unique prefix |
| 3716 | 3716 | ** of the option name, or a numerical value. */ |
| 3717 | | - n = strlen30(azArg[1]); |
| 3717 | + n2 = strlen30(azArg[1]); |
| 3718 | 3718 | for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){ |
| 3719 | | - if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){ |
| 3719 | + if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){ |
| 3720 | 3720 | if( testctrl<0 ){ |
| 3721 | 3721 | testctrl = aCtrl[i].ctrlCode; |
| 3722 | 3722 | }else{ |
| 3723 | 3723 | fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]); |
| 3724 | 3724 | testctrl = -1; |
| | @@ -3735,12 +3735,12 @@ |
| 3735 | 3735 | /* sqlite3_test_control(int, db, int) */ |
| 3736 | 3736 | case SQLITE_TESTCTRL_OPTIMIZATIONS: |
| 3737 | 3737 | case SQLITE_TESTCTRL_RESERVE: |
| 3738 | 3738 | if( nArg==3 ){ |
| 3739 | 3739 | int opt = (int)strtol(azArg[2], 0, 0); |
| 3740 | | - rc = sqlite3_test_control(testctrl, p->db, opt); |
| 3741 | | - fprintf(p->out, "%d (0x%08x)\n", rc, rc); |
| 3740 | + rc2 = sqlite3_test_control(testctrl, p->db, opt); |
| 3741 | + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); |
| 3742 | 3742 | } else { |
| 3743 | 3743 | fprintf(stderr,"Error: testctrl %s takes a single int option\n", |
| 3744 | 3744 | azArg[1]); |
| 3745 | 3745 | } |
| 3746 | 3746 | break; |
| | @@ -3749,23 +3749,23 @@ |
| 3749 | 3749 | case SQLITE_TESTCTRL_PRNG_SAVE: |
| 3750 | 3750 | case SQLITE_TESTCTRL_PRNG_RESTORE: |
| 3751 | 3751 | case SQLITE_TESTCTRL_PRNG_RESET: |
| 3752 | 3752 | case SQLITE_TESTCTRL_BYTEORDER: |
| 3753 | 3753 | if( nArg==2 ){ |
| 3754 | | - rc = sqlite3_test_control(testctrl); |
| 3755 | | - fprintf(p->out, "%d (0x%08x)\n", rc, rc); |
| 3754 | + rc2 = sqlite3_test_control(testctrl); |
| 3755 | + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); |
| 3756 | 3756 | } else { |
| 3757 | 3757 | fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]); |
| 3758 | 3758 | } |
| 3759 | 3759 | break; |
| 3760 | 3760 | |
| 3761 | 3761 | /* sqlite3_test_control(int, uint) */ |
| 3762 | 3762 | case SQLITE_TESTCTRL_PENDING_BYTE: |
| 3763 | 3763 | if( nArg==3 ){ |
| 3764 | 3764 | unsigned int opt = (unsigned int)integerValue(azArg[2]); |
| 3765 | | - rc = sqlite3_test_control(testctrl, opt); |
| 3766 | | - fprintf(p->out, "%d (0x%08x)\n", rc, rc); |
| 3765 | + rc2 = sqlite3_test_control(testctrl, opt); |
| 3766 | + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); |
| 3767 | 3767 | } else { |
| 3768 | 3768 | fprintf(stderr,"Error: testctrl %s takes a single unsigned" |
| 3769 | 3769 | " int option\n", azArg[1]); |
| 3770 | 3770 | } |
| 3771 | 3771 | break; |
| | @@ -3774,12 +3774,12 @@ |
| 3774 | 3774 | case SQLITE_TESTCTRL_ASSERT: |
| 3775 | 3775 | case SQLITE_TESTCTRL_ALWAYS: |
| 3776 | 3776 | case SQLITE_TESTCTRL_NEVER_CORRUPT: |
| 3777 | 3777 | if( nArg==3 ){ |
| 3778 | 3778 | int opt = booleanValue(azArg[2]); |
| 3779 | | - rc = sqlite3_test_control(testctrl, opt); |
| 3780 | | - fprintf(p->out, "%d (0x%08x)\n", rc, rc); |
| 3779 | + rc2 = sqlite3_test_control(testctrl, opt); |
| 3780 | + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); |
| 3781 | 3781 | } else { |
| 3782 | 3782 | fprintf(stderr,"Error: testctrl %s takes a single int option\n", |
| 3783 | 3783 | azArg[1]); |
| 3784 | 3784 | } |
| 3785 | 3785 | break; |
| | @@ -3787,26 +3787,26 @@ |
| 3787 | 3787 | /* sqlite3_test_control(int, char *) */ |
| 3788 | 3788 | #ifdef SQLITE_N_KEYWORD |
| 3789 | 3789 | case SQLITE_TESTCTRL_ISKEYWORD: |
| 3790 | 3790 | if( nArg==3 ){ |
| 3791 | 3791 | const char *opt = azArg[2]; |
| 3792 | | - rc = sqlite3_test_control(testctrl, opt); |
| 3793 | | - fprintf(p->out, "%d (0x%08x)\n", rc, rc); |
| 3792 | + rc2 = sqlite3_test_control(testctrl, opt); |
| 3793 | + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); |
| 3794 | 3794 | } else { |
| 3795 | 3795 | fprintf(stderr,"Error: testctrl %s takes a single char * option\n", |
| 3796 | 3796 | azArg[1]); |
| 3797 | 3797 | } |
| 3798 | 3798 | break; |
| 3799 | 3799 | #endif |
| 3800 | 3800 | |
| 3801 | 3801 | case SQLITE_TESTCTRL_IMPOSTER: |
| 3802 | 3802 | if( nArg==5 ){ |
| 3803 | | - rc = sqlite3_test_control(testctrl, p->db, |
| 3803 | + rc2 = sqlite3_test_control(testctrl, p->db, |
| 3804 | 3804 | azArg[2], |
| 3805 | 3805 | integerValue(azArg[3]), |
| 3806 | 3806 | integerValue(azArg[4])); |
| 3807 | | - fprintf(p->out, "%d (0x%08x)\n", rc, rc); |
| 3807 | + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); |
| 3808 | 3808 | }else{ |
| 3809 | 3809 | fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n"); |
| 3810 | 3810 | } |
| 3811 | 3811 | break; |
| 3812 | 3812 | |
| 3813 | 3813 | |