| | @@ -988,11 +988,20 @@ |
| 988 | 988 | break; |
| 989 | 989 | } |
| 990 | 990 | case MODE_Insert: { |
| 991 | 991 | p->cnt++; |
| 992 | 992 | if( azArg==0 ) break; |
| 993 | | - fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable); |
| 993 | + fprintf(p->out,"INSERT INTO %s",p->zDestTable); |
| 994 | + if( p->showHeader ){ |
| 995 | + fprintf(p->out,"("); |
| 996 | + for(i=0; i<nArg; i++){ |
| 997 | + char *zSep = i>0 ? ",": ""; |
| 998 | + fprintf(p->out, "%s%s", zSep, azCol[i]); |
| 999 | + } |
| 1000 | + fprintf(p->out,")"); |
| 1001 | + } |
| 1002 | + fprintf(p->out," VALUES("); |
| 994 | 1003 | for(i=0; i<nArg; i++){ |
| 995 | 1004 | char *zSep = i>0 ? ",": ""; |
| 996 | 1005 | if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ |
| 997 | 1006 | fprintf(p->out,"%sNULL",zSep); |
| 998 | 1007 | }else if( aiType && aiType[i]==SQLITE_TEXT ){ |
| | @@ -1189,11 +1198,11 @@ |
| 1189 | 1198 | */ |
| 1190 | 1199 | static char *save_err_msg( |
| 1191 | 1200 | sqlite3 *db /* Database to query */ |
| 1192 | 1201 | ){ |
| 1193 | 1202 | int nErrMsg = 1+strlen30(sqlite3_errmsg(db)); |
| 1194 | | - char *zErrMsg = sqlite3_malloc(nErrMsg); |
| 1203 | + char *zErrMsg = sqlite3_malloc64(nErrMsg); |
| 1195 | 1204 | if( zErrMsg ){ |
| 1196 | 1205 | memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg); |
| 1197 | 1206 | } |
| 1198 | 1207 | return zErrMsg; |
| 1199 | 1208 | } |
| | @@ -1426,12 +1435,12 @@ |
| 1426 | 1435 | int p2op = (p2 + (iOp-iAddr)); |
| 1427 | 1436 | |
| 1428 | 1437 | /* Grow the p->aiIndent array as required */ |
| 1429 | 1438 | if( iOp>=nAlloc ){ |
| 1430 | 1439 | nAlloc += 100; |
| 1431 | | - p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int)); |
| 1432 | | - abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int)); |
| 1440 | + p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int)); |
| 1441 | + abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int)); |
| 1433 | 1442 | } |
| 1434 | 1443 | abYield[iOp] = str_in_array(zOp, azYield); |
| 1435 | 1444 | p->aiIndent[iOp] = 0; |
| 1436 | 1445 | p->nIndent = iOp+1; |
| 1437 | 1446 | |
| | @@ -1544,11 +1553,11 @@ |
| 1544 | 1553 | if( SQLITE_ROW == rc ){ |
| 1545 | 1554 | /* if we have a callback... */ |
| 1546 | 1555 | if( xCallback ){ |
| 1547 | 1556 | /* allocate space for col name ptr, value ptr, and type */ |
| 1548 | 1557 | int nCol = sqlite3_column_count(pStmt); |
| 1549 | | - void *pData = sqlite3_malloc(3*nCol*sizeof(const char*) + 1); |
| 1558 | + void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1); |
| 1550 | 1559 | if( !pData ){ |
| 1551 | 1560 | rc = SQLITE_NOMEM; |
| 1552 | 1561 | }else{ |
| 1553 | 1562 | char **azCols = (char **)pData; /* Names of result columns */ |
| 1554 | 1563 | char **azVals = &azCols[nCol]; /* Results */ |
| | @@ -1770,10 +1779,11 @@ |
| 1770 | 1779 | ** Text of a help message |
| 1771 | 1780 | */ |
| 1772 | 1781 | static char zHelp[] = |
| 1773 | 1782 | ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n" |
| 1774 | 1783 | ".bail on|off Stop after hitting an error. Default OFF\n" |
| 1784 | + ".binary on|off Turn binary output on or off. Default OFF\n" |
| 1775 | 1785 | ".clone NEWDB Clone data into NEWDB from the existing database\n" |
| 1776 | 1786 | ".databases List names and files of attached databases\n" |
| 1777 | 1787 | ".dbinfo ?DB? Show status information about the database\n" |
| 1778 | 1788 | ".dump ?TABLE? ... Dump the database in an SQL text format\n" |
| 1779 | 1789 | " If TABLE specified, only dump tables matching\n" |
| | @@ -1791,10 +1801,11 @@ |
| 1791 | 1801 | " If TABLE specified, only show indexes for tables\n" |
| 1792 | 1802 | " matching LIKE pattern TABLE.\n" |
| 1793 | 1803 | #ifdef SQLITE_ENABLE_IOTRACE |
| 1794 | 1804 | ".iotrace FILE Enable I/O diagnostic logging to FILE\n" |
| 1795 | 1805 | #endif |
| 1806 | + ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n" |
| 1796 | 1807 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 1797 | 1808 | ".load FILE ?ENTRY? Load an extension library\n" |
| 1798 | 1809 | #endif |
| 1799 | 1810 | ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n" |
| 1800 | 1811 | ".mode MODE ?TABLE? Set output mode where MODE is one of:\n" |
| | @@ -1860,11 +1871,11 @@ |
| 1860 | 1871 | in = fopen(zName, "rb"); |
| 1861 | 1872 | if( in==0 ) return; |
| 1862 | 1873 | fseek(in, 0, SEEK_END); |
| 1863 | 1874 | nIn = ftell(in); |
| 1864 | 1875 | rewind(in); |
| 1865 | | - pBuf = sqlite3_malloc( nIn ); |
| 1876 | + pBuf = sqlite3_malloc64( nIn ); |
| 1866 | 1877 | if( pBuf && 1==fread(pBuf, nIn, 1, in) ){ |
| 1867 | 1878 | sqlite3_result_blob(context, pBuf, nIn, sqlite3_free); |
| 1868 | 1879 | }else{ |
| 1869 | 1880 | sqlite3_free(pBuf); |
| 1870 | 1881 | } |
| | @@ -1907,10 +1918,16 @@ |
| 1907 | 1918 | */ |
| 1908 | 1919 | static void open_db(ShellState *p, int keepAlive){ |
| 1909 | 1920 | if( p->db==0 ){ |
| 1910 | 1921 | sqlite3_initialize(); |
| 1911 | 1922 | sqlite3_open(p->zDbFilename, &p->db); |
| 1923 | +#ifdef SQLITE_ENABLE_DBSTAT_VTAB |
| 1924 | + if( p->db ){ |
| 1925 | + int sqlite3_dbstat_register(sqlite3*); |
| 1926 | + sqlite3_dbstat_register(p->db); |
| 1927 | + } |
| 1928 | +#endif |
| 1912 | 1929 | globalDb = p->db; |
| 1913 | 1930 | if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){ |
| 1914 | 1931 | sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0, |
| 1915 | 1932 | shellstaticFunc, 0, 0); |
| 1916 | 1933 | } |
| | @@ -1931,30 +1948,48 @@ |
| 1931 | 1948 | } |
| 1932 | 1949 | |
| 1933 | 1950 | /* |
| 1934 | 1951 | ** Do C-language style dequoting. |
| 1935 | 1952 | ** |
| 1953 | +** \a -> alarm |
| 1954 | +** \b -> backspace |
| 1936 | 1955 | ** \t -> tab |
| 1937 | 1956 | ** \n -> newline |
| 1957 | +** \v -> vertical tab |
| 1958 | +** \f -> form feed |
| 1938 | 1959 | ** \r -> carriage return |
| 1960 | +** \s -> space |
| 1939 | 1961 | ** \" -> " |
| 1940 | | -** \NNN -> ascii character NNN in octal |
| 1962 | +** \' -> ' |
| 1941 | 1963 | ** \\ -> backslash |
| 1964 | +** \NNN -> ascii character NNN in octal |
| 1942 | 1965 | */ |
| 1943 | 1966 | static void resolve_backslashes(char *z){ |
| 1944 | 1967 | int i, j; |
| 1945 | 1968 | char c; |
| 1946 | 1969 | while( *z && *z!='\\' ) z++; |
| 1947 | 1970 | for(i=j=0; (c = z[i])!=0; i++, j++){ |
| 1948 | 1971 | if( c=='\\' && z[i+1]!=0 ){ |
| 1949 | 1972 | c = z[++i]; |
| 1950 | | - if( c=='n' ){ |
| 1951 | | - c = '\n'; |
| 1973 | + if( c=='a' ){ |
| 1974 | + c = '\a'; |
| 1975 | + }else if( c=='b' ){ |
| 1976 | + c = '\b'; |
| 1952 | 1977 | }else if( c=='t' ){ |
| 1953 | 1978 | c = '\t'; |
| 1979 | + }else if( c=='n' ){ |
| 1980 | + c = '\n'; |
| 1981 | + }else if( c=='v' ){ |
| 1982 | + c = '\v'; |
| 1983 | + }else if( c=='f' ){ |
| 1984 | + c = '\f'; |
| 1954 | 1985 | }else if( c=='r' ){ |
| 1955 | 1986 | c = '\r'; |
| 1987 | + }else if( c=='"' ){ |
| 1988 | + c = '"'; |
| 1989 | + }else if( c=='\'' ){ |
| 1990 | + c = '\''; |
| 1956 | 1991 | }else if( c=='\\' ){ |
| 1957 | 1992 | c = '\\'; |
| 1958 | 1993 | }else if( c>='0' && c<='7' ){ |
| 1959 | 1994 | c -= '0'; |
| 1960 | 1995 | if( z[i+1]>='0' && z[i+1]<='7' ){ |
| | @@ -2120,11 +2155,11 @@ |
| 2120 | 2155 | |
| 2121 | 2156 | /* Append a single byte to z[] */ |
| 2122 | 2157 | static void import_append_char(ImportCtx *p, int c){ |
| 2123 | 2158 | if( p->n+1>=p->nAlloc ){ |
| 2124 | 2159 | p->nAlloc += p->nAlloc + 100; |
| 2125 | | - p->z = sqlite3_realloc(p->z, p->nAlloc); |
| 2160 | + p->z = sqlite3_realloc64(p->z, p->nAlloc); |
| 2126 | 2161 | if( p->z==0 ){ |
| 2127 | 2162 | fprintf(stderr, "out of memory\n"); |
| 2128 | 2163 | exit(1); |
| 2129 | 2164 | } |
| 2130 | 2165 | } |
| | @@ -2134,11 +2169,11 @@ |
| 2134 | 2169 | /* Read a single field of CSV text. Compatible with rfc4180 and extended |
| 2135 | 2170 | ** with the option of having a separator other than ",". |
| 2136 | 2171 | ** |
| 2137 | 2172 | ** + Input comes from p->in. |
| 2138 | 2173 | ** + Store results in p->z of length p->n. Space to hold p->z comes |
| 2139 | | -** from sqlite3_malloc(). |
| 2174 | +** from sqlite3_malloc64(). |
| 2140 | 2175 | ** + Use p->cSep as the column separator. The default is ",". |
| 2141 | 2176 | ** + Use p->rSep as the row separator. The default is "\n". |
| 2142 | 2177 | ** + Keep track of the line number in p->nLine. |
| 2143 | 2178 | ** + Store the character that terminates the field in p->cTerm. Store |
| 2144 | 2179 | ** EOF on end-of-file. |
| | @@ -2208,11 +2243,11 @@ |
| 2208 | 2243 | |
| 2209 | 2244 | /* Read a single field of ASCII delimited text. |
| 2210 | 2245 | ** |
| 2211 | 2246 | ** + Input comes from p->in. |
| 2212 | 2247 | ** + Store results in p->z of length p->n. Space to hold p->z comes |
| 2213 | | -** from sqlite3_malloc(). |
| 2248 | +** from sqlite3_malloc64(). |
| 2214 | 2249 | ** + Use p->cSep as the column separator. The default is "\x1F". |
| 2215 | 2250 | ** + Use p->rSep as the row separator. The default is "\x1E". |
| 2216 | 2251 | ** + Keep track of the row number in p->nLine. |
| 2217 | 2252 | ** + Store the character that terminates the field in p->cTerm. Store |
| 2218 | 2253 | ** EOF on end-of-file. |
| | @@ -2268,11 +2303,11 @@ |
| 2268 | 2303 | sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), |
| 2269 | 2304 | zQuery); |
| 2270 | 2305 | goto end_data_xfer; |
| 2271 | 2306 | } |
| 2272 | 2307 | n = sqlite3_column_count(pQuery); |
| 2273 | | - zInsert = sqlite3_malloc(200 + nTable + n*3); |
| 2308 | + zInsert = sqlite3_malloc64(200 + nTable + n*3); |
| 2274 | 2309 | if( zInsert==0 ){ |
| 2275 | 2310 | fprintf(stderr, "out of memory\n"); |
| 2276 | 2311 | goto end_data_xfer; |
| 2277 | 2312 | } |
| 2278 | 2313 | sqlite3_snprintf(200+nTable,zInsert, |
| | @@ -2683,10 +2718,23 @@ |
| 2683 | 2718 | }else{ |
| 2684 | 2719 | fprintf(stderr, "Usage: .bail on|off\n"); |
| 2685 | 2720 | rc = 1; |
| 2686 | 2721 | } |
| 2687 | 2722 | }else |
| 2723 | + |
| 2724 | + if( c=='b' && n>=3 && strncmp(azArg[0], "binary", n)==0 ){ |
| 2725 | + if( nArg==2 ){ |
| 2726 | + if( booleanValue(azArg[1]) ){ |
| 2727 | + setBinaryMode(p->out); |
| 2728 | + }else{ |
| 2729 | + setTextMode(p->out); |
| 2730 | + } |
| 2731 | + }else{ |
| 2732 | + fprintf(stderr, "Usage: .binary on|off\n"); |
| 2733 | + rc = 1; |
| 2734 | + } |
| 2735 | + }else |
| 2688 | 2736 | |
| 2689 | 2737 | /* The undocumented ".breakpoint" command causes a call to the no-op |
| 2690 | 2738 | ** routine named test_breakpoint(). |
| 2691 | 2739 | */ |
| 2692 | 2740 | if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){ |
| | @@ -3023,11 +3071,11 @@ |
| 3023 | 3071 | } |
| 3024 | 3072 | nCol = sqlite3_column_count(pStmt); |
| 3025 | 3073 | sqlite3_finalize(pStmt); |
| 3026 | 3074 | pStmt = 0; |
| 3027 | 3075 | if( nCol==0 ) return 0; /* no columns, no error */ |
| 3028 | | - zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 ); |
| 3076 | + zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 ); |
| 3029 | 3077 | if( zSql==0 ){ |
| 3030 | 3078 | fprintf(stderr, "Error: out of memory\n"); |
| 3031 | 3079 | xCloser(sCtx.in); |
| 3032 | 3080 | return 1; |
| 3033 | 3081 | } |
| | @@ -3163,10 +3211,67 @@ |
| 3163 | 3211 | sqlite3IoTrace = iotracePrintf; |
| 3164 | 3212 | } |
| 3165 | 3213 | } |
| 3166 | 3214 | }else |
| 3167 | 3215 | #endif |
| 3216 | + if( c=='l' && n>=5 && strncmp(azArg[0], "limits", n)==0 ){ |
| 3217 | + static const struct { |
| 3218 | + const char *zLimitName; /* Name of a limit */ |
| 3219 | + int limitCode; /* Integer code for that limit */ |
| 3220 | + } aLimit[] = { |
| 3221 | + { "length", SQLITE_LIMIT_LENGTH }, |
| 3222 | + { "sql_length", SQLITE_LIMIT_SQL_LENGTH }, |
| 3223 | + { "column", SQLITE_LIMIT_COLUMN }, |
| 3224 | + { "expr_depth", SQLITE_LIMIT_EXPR_DEPTH }, |
| 3225 | + { "compound_select", SQLITE_LIMIT_COMPOUND_SELECT }, |
| 3226 | + { "vdbe_op", SQLITE_LIMIT_VDBE_OP }, |
| 3227 | + { "function_arg", SQLITE_LIMIT_FUNCTION_ARG }, |
| 3228 | + { "attached", SQLITE_LIMIT_ATTACHED }, |
| 3229 | + { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH }, |
| 3230 | + { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER }, |
| 3231 | + { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH }, |
| 3232 | + { "worker_threads", SQLITE_LIMIT_WORKER_THREADS }, |
| 3233 | + }; |
| 3234 | + int i, n2; |
| 3235 | + open_db(p, 0); |
| 3236 | + if( nArg==1 ){ |
| 3237 | + for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){ |
| 3238 | + printf("%20s %d\n", aLimit[i].zLimitName, |
| 3239 | + sqlite3_limit(p->db, aLimit[i].limitCode, -1)); |
| 3240 | + } |
| 3241 | + }else if( nArg>3 ){ |
| 3242 | + fprintf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n"); |
| 3243 | + rc = 1; |
| 3244 | + goto meta_command_exit; |
| 3245 | + }else{ |
| 3246 | + int iLimit = -1; |
| 3247 | + n2 = strlen30(azArg[1]); |
| 3248 | + for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){ |
| 3249 | + if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){ |
| 3250 | + if( iLimit<0 ){ |
| 3251 | + iLimit = i; |
| 3252 | + }else{ |
| 3253 | + fprintf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]); |
| 3254 | + rc = 1; |
| 3255 | + goto meta_command_exit; |
| 3256 | + } |
| 3257 | + } |
| 3258 | + } |
| 3259 | + if( iLimit<0 ){ |
| 3260 | + fprintf(stderr, "unknown limit: \"%s\"\n" |
| 3261 | + "enter \".limits\" with no arguments for a list.\n", |
| 3262 | + azArg[1]); |
| 3263 | + rc = 1; |
| 3264 | + goto meta_command_exit; |
| 3265 | + } |
| 3266 | + if( nArg==3 ){ |
| 3267 | + sqlite3_limit(p->db, aLimit[iLimit].limitCode, integerValue(azArg[2])); |
| 3268 | + } |
| 3269 | + printf("%20s %d\n", aLimit[iLimit].zLimitName, |
| 3270 | + sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1)); |
| 3271 | + } |
| 3272 | + }else |
| 3168 | 3273 | |
| 3169 | 3274 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 3170 | 3275 | if( c=='l' && strncmp(azArg[0], "load", n)==0 ){ |
| 3171 | 3276 | const char *zFile, *zProc; |
| 3172 | 3277 | char *zErrMsg = 0; |
| | @@ -3648,11 +3753,11 @@ |
| 3648 | 3753 | } |
| 3649 | 3754 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 3650 | 3755 | if( nRow>=nAlloc ){ |
| 3651 | 3756 | char **azNew; |
| 3652 | 3757 | int n2 = nAlloc*2 + 10; |
| 3653 | | - azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2); |
| 3758 | + azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2); |
| 3654 | 3759 | if( azNew==0 ){ |
| 3655 | 3760 | fprintf(stderr, "Error: out of memory\n"); |
| 3656 | 3761 | break; |
| 3657 | 3762 | } |
| 3658 | 3763 | nAlloc = n2; |
| 3659 | 3764 | |