Fossil SCM

Update the built-in SQLite to the first 3.8.10 beta.

drh 2015-05-04 19:25 trunk
Commit 5a87a0314e33b6bace04d6a717d6dbe46e4ef498
1 file changed +120 -15
+120 -15
--- src/shell.c
+++ src/shell.c
@@ -988,11 +988,20 @@
988988
break;
989989
}
990990
case MODE_Insert: {
991991
p->cnt++;
992992
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(");
9941003
for(i=0; i<nArg; i++){
9951004
char *zSep = i>0 ? ",": "";
9961005
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
9971006
fprintf(p->out,"%sNULL",zSep);
9981007
}else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1189,11 +1198,11 @@
11891198
*/
11901199
static char *save_err_msg(
11911200
sqlite3 *db /* Database to query */
11921201
){
11931202
int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
1194
- char *zErrMsg = sqlite3_malloc(nErrMsg);
1203
+ char *zErrMsg = sqlite3_malloc64(nErrMsg);
11951204
if( zErrMsg ){
11961205
memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
11971206
}
11981207
return zErrMsg;
11991208
}
@@ -1426,12 +1435,12 @@
14261435
int p2op = (p2 + (iOp-iAddr));
14271436
14281437
/* Grow the p->aiIndent array as required */
14291438
if( iOp>=nAlloc ){
14301439
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));
14331442
}
14341443
abYield[iOp] = str_in_array(zOp, azYield);
14351444
p->aiIndent[iOp] = 0;
14361445
p->nIndent = iOp+1;
14371446
@@ -1544,11 +1553,11 @@
15441553
if( SQLITE_ROW == rc ){
15451554
/* if we have a callback... */
15461555
if( xCallback ){
15471556
/* allocate space for col name ptr, value ptr, and type */
15481557
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);
15501559
if( !pData ){
15511560
rc = SQLITE_NOMEM;
15521561
}else{
15531562
char **azCols = (char **)pData; /* Names of result columns */
15541563
char **azVals = &azCols[nCol]; /* Results */
@@ -1770,10 +1779,11 @@
17701779
** Text of a help message
17711780
*/
17721781
static char zHelp[] =
17731782
".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
17741783
".bail on|off Stop after hitting an error. Default OFF\n"
1784
+ ".binary on|off Turn binary output on or off. Default OFF\n"
17751785
".clone NEWDB Clone data into NEWDB from the existing database\n"
17761786
".databases List names and files of attached databases\n"
17771787
".dbinfo ?DB? Show status information about the database\n"
17781788
".dump ?TABLE? ... Dump the database in an SQL text format\n"
17791789
" If TABLE specified, only dump tables matching\n"
@@ -1791,10 +1801,11 @@
17911801
" If TABLE specified, only show indexes for tables\n"
17921802
" matching LIKE pattern TABLE.\n"
17931803
#ifdef SQLITE_ENABLE_IOTRACE
17941804
".iotrace FILE Enable I/O diagnostic logging to FILE\n"
17951805
#endif
1806
+ ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n"
17961807
#ifndef SQLITE_OMIT_LOAD_EXTENSION
17971808
".load FILE ?ENTRY? Load an extension library\n"
17981809
#endif
17991810
".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
18001811
".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -1860,11 +1871,11 @@
18601871
in = fopen(zName, "rb");
18611872
if( in==0 ) return;
18621873
fseek(in, 0, SEEK_END);
18631874
nIn = ftell(in);
18641875
rewind(in);
1865
- pBuf = sqlite3_malloc( nIn );
1876
+ pBuf = sqlite3_malloc64( nIn );
18661877
if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
18671878
sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
18681879
}else{
18691880
sqlite3_free(pBuf);
18701881
}
@@ -1907,10 +1918,16 @@
19071918
*/
19081919
static void open_db(ShellState *p, int keepAlive){
19091920
if( p->db==0 ){
19101921
sqlite3_initialize();
19111922
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
19121929
globalDb = p->db;
19131930
if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
19141931
sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
19151932
shellstaticFunc, 0, 0);
19161933
}
@@ -1931,30 +1948,48 @@
19311948
}
19321949
19331950
/*
19341951
** Do C-language style dequoting.
19351952
**
1953
+** \a -> alarm
1954
+** \b -> backspace
19361955
** \t -> tab
19371956
** \n -> newline
1957
+** \v -> vertical tab
1958
+** \f -> form feed
19381959
** \r -> carriage return
1960
+** \s -> space
19391961
** \" -> "
1940
-** \NNN -> ascii character NNN in octal
1962
+** \' -> '
19411963
** \\ -> backslash
1964
+** \NNN -> ascii character NNN in octal
19421965
*/
19431966
static void resolve_backslashes(char *z){
19441967
int i, j;
19451968
char c;
19461969
while( *z && *z!='\\' ) z++;
19471970
for(i=j=0; (c = z[i])!=0; i++, j++){
19481971
if( c=='\\' && z[i+1]!=0 ){
19491972
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';
19521977
}else if( c=='t' ){
19531978
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';
19541985
}else if( c=='r' ){
19551986
c = '\r';
1987
+ }else if( c=='"' ){
1988
+ c = '"';
1989
+ }else if( c=='\'' ){
1990
+ c = '\'';
19561991
}else if( c=='\\' ){
19571992
c = '\\';
19581993
}else if( c>='0' && c<='7' ){
19591994
c -= '0';
19601995
if( z[i+1]>='0' && z[i+1]<='7' ){
@@ -2120,11 +2155,11 @@
21202155
21212156
/* Append a single byte to z[] */
21222157
static void import_append_char(ImportCtx *p, int c){
21232158
if( p->n+1>=p->nAlloc ){
21242159
p->nAlloc += p->nAlloc + 100;
2125
- p->z = sqlite3_realloc(p->z, p->nAlloc);
2160
+ p->z = sqlite3_realloc64(p->z, p->nAlloc);
21262161
if( p->z==0 ){
21272162
fprintf(stderr, "out of memory\n");
21282163
exit(1);
21292164
}
21302165
}
@@ -2134,11 +2169,11 @@
21342169
/* Read a single field of CSV text. Compatible with rfc4180 and extended
21352170
** with the option of having a separator other than ",".
21362171
**
21372172
** + Input comes from p->in.
21382173
** + Store results in p->z of length p->n. Space to hold p->z comes
2139
-** from sqlite3_malloc().
2174
+** from sqlite3_malloc64().
21402175
** + Use p->cSep as the column separator. The default is ",".
21412176
** + Use p->rSep as the row separator. The default is "\n".
21422177
** + Keep track of the line number in p->nLine.
21432178
** + Store the character that terminates the field in p->cTerm. Store
21442179
** EOF on end-of-file.
@@ -2208,11 +2243,11 @@
22082243
22092244
/* Read a single field of ASCII delimited text.
22102245
**
22112246
** + Input comes from p->in.
22122247
** + Store results in p->z of length p->n. Space to hold p->z comes
2213
-** from sqlite3_malloc().
2248
+** from sqlite3_malloc64().
22142249
** + Use p->cSep as the column separator. The default is "\x1F".
22152250
** + Use p->rSep as the row separator. The default is "\x1E".
22162251
** + Keep track of the row number in p->nLine.
22172252
** + Store the character that terminates the field in p->cTerm. Store
22182253
** EOF on end-of-file.
@@ -2268,11 +2303,11 @@
22682303
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
22692304
zQuery);
22702305
goto end_data_xfer;
22712306
}
22722307
n = sqlite3_column_count(pQuery);
2273
- zInsert = sqlite3_malloc(200 + nTable + n*3);
2308
+ zInsert = sqlite3_malloc64(200 + nTable + n*3);
22742309
if( zInsert==0 ){
22752310
fprintf(stderr, "out of memory\n");
22762311
goto end_data_xfer;
22772312
}
22782313
sqlite3_snprintf(200+nTable,zInsert,
@@ -2683,10 +2718,23 @@
26832718
}else{
26842719
fprintf(stderr, "Usage: .bail on|off\n");
26852720
rc = 1;
26862721
}
26872722
}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
26882736
26892737
/* The undocumented ".breakpoint" command causes a call to the no-op
26902738
** routine named test_breakpoint().
26912739
*/
26922740
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
@@ -3023,11 +3071,11 @@
30233071
}
30243072
nCol = sqlite3_column_count(pStmt);
30253073
sqlite3_finalize(pStmt);
30263074
pStmt = 0;
30273075
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 );
30293077
if( zSql==0 ){
30303078
fprintf(stderr, "Error: out of memory\n");
30313079
xCloser(sCtx.in);
30323080
return 1;
30333081
}
@@ -3163,10 +3211,67 @@
31633211
sqlite3IoTrace = iotracePrintf;
31643212
}
31653213
}
31663214
}else
31673215
#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
31683273
31693274
#ifndef SQLITE_OMIT_LOAD_EXTENSION
31703275
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
31713276
const char *zFile, *zProc;
31723277
char *zErrMsg = 0;
@@ -3648,11 +3753,11 @@
36483753
}
36493754
while( sqlite3_step(pStmt)==SQLITE_ROW ){
36503755
if( nRow>=nAlloc ){
36513756
char **azNew;
36523757
int n2 = nAlloc*2 + 10;
3653
- azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2);
3758
+ azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2);
36543759
if( azNew==0 ){
36553760
fprintf(stderr, "Error: out of memory\n");
36563761
break;
36573762
}
36583763
nAlloc = n2;
36593764
--- src/shell.c
+++ src/shell.c
@@ -988,11 +988,20 @@
988 break;
989 }
990 case MODE_Insert: {
991 p->cnt++;
992 if( azArg==0 ) break;
993 fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
 
 
 
 
 
 
 
 
 
994 for(i=0; i<nArg; i++){
995 char *zSep = i>0 ? ",": "";
996 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
997 fprintf(p->out,"%sNULL",zSep);
998 }else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1189,11 +1198,11 @@
1189 */
1190 static char *save_err_msg(
1191 sqlite3 *db /* Database to query */
1192 ){
1193 int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
1194 char *zErrMsg = sqlite3_malloc(nErrMsg);
1195 if( zErrMsg ){
1196 memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
1197 }
1198 return zErrMsg;
1199 }
@@ -1426,12 +1435,12 @@
1426 int p2op = (p2 + (iOp-iAddr));
1427
1428 /* Grow the p->aiIndent array as required */
1429 if( iOp>=nAlloc ){
1430 nAlloc += 100;
1431 p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int));
1432 abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int));
1433 }
1434 abYield[iOp] = str_in_array(zOp, azYield);
1435 p->aiIndent[iOp] = 0;
1436 p->nIndent = iOp+1;
1437
@@ -1544,11 +1553,11 @@
1544 if( SQLITE_ROW == rc ){
1545 /* if we have a callback... */
1546 if( xCallback ){
1547 /* allocate space for col name ptr, value ptr, and type */
1548 int nCol = sqlite3_column_count(pStmt);
1549 void *pData = sqlite3_malloc(3*nCol*sizeof(const char*) + 1);
1550 if( !pData ){
1551 rc = SQLITE_NOMEM;
1552 }else{
1553 char **azCols = (char **)pData; /* Names of result columns */
1554 char **azVals = &azCols[nCol]; /* Results */
@@ -1770,10 +1779,11 @@
1770 ** Text of a help message
1771 */
1772 static char zHelp[] =
1773 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1774 ".bail on|off Stop after hitting an error. Default OFF\n"
 
1775 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1776 ".databases List names and files of attached databases\n"
1777 ".dbinfo ?DB? Show status information about the database\n"
1778 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1779 " If TABLE specified, only dump tables matching\n"
@@ -1791,10 +1801,11 @@
1791 " If TABLE specified, only show indexes for tables\n"
1792 " matching LIKE pattern TABLE.\n"
1793 #ifdef SQLITE_ENABLE_IOTRACE
1794 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
1795 #endif
 
1796 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1797 ".load FILE ?ENTRY? Load an extension library\n"
1798 #endif
1799 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1800 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -1860,11 +1871,11 @@
1860 in = fopen(zName, "rb");
1861 if( in==0 ) return;
1862 fseek(in, 0, SEEK_END);
1863 nIn = ftell(in);
1864 rewind(in);
1865 pBuf = sqlite3_malloc( nIn );
1866 if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1867 sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
1868 }else{
1869 sqlite3_free(pBuf);
1870 }
@@ -1907,10 +1918,16 @@
1907 */
1908 static void open_db(ShellState *p, int keepAlive){
1909 if( p->db==0 ){
1910 sqlite3_initialize();
1911 sqlite3_open(p->zDbFilename, &p->db);
 
 
 
 
 
 
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 shellstaticFunc, 0, 0);
1916 }
@@ -1931,30 +1948,48 @@
1931 }
1932
1933 /*
1934 ** Do C-language style dequoting.
1935 **
 
 
1936 ** \t -> tab
1937 ** \n -> newline
 
 
1938 ** \r -> carriage return
 
1939 ** \" -> "
1940 ** \NNN -> ascii character NNN in octal
1941 ** \\ -> backslash
 
1942 */
1943 static void resolve_backslashes(char *z){
1944 int i, j;
1945 char c;
1946 while( *z && *z!='\\' ) z++;
1947 for(i=j=0; (c = z[i])!=0; i++, j++){
1948 if( c=='\\' && z[i+1]!=0 ){
1949 c = z[++i];
1950 if( c=='n' ){
1951 c = '\n';
 
 
1952 }else if( c=='t' ){
1953 c = '\t';
 
 
 
 
 
 
1954 }else if( c=='r' ){
1955 c = '\r';
 
 
 
 
1956 }else if( c=='\\' ){
1957 c = '\\';
1958 }else if( c>='0' && c<='7' ){
1959 c -= '0';
1960 if( z[i+1]>='0' && z[i+1]<='7' ){
@@ -2120,11 +2155,11 @@
2120
2121 /* Append a single byte to z[] */
2122 static void import_append_char(ImportCtx *p, int c){
2123 if( p->n+1>=p->nAlloc ){
2124 p->nAlloc += p->nAlloc + 100;
2125 p->z = sqlite3_realloc(p->z, p->nAlloc);
2126 if( p->z==0 ){
2127 fprintf(stderr, "out of memory\n");
2128 exit(1);
2129 }
2130 }
@@ -2134,11 +2169,11 @@
2134 /* Read a single field of CSV text. Compatible with rfc4180 and extended
2135 ** with the option of having a separator other than ",".
2136 **
2137 ** + Input comes from p->in.
2138 ** + Store results in p->z of length p->n. Space to hold p->z comes
2139 ** from sqlite3_malloc().
2140 ** + Use p->cSep as the column separator. The default is ",".
2141 ** + Use p->rSep as the row separator. The default is "\n".
2142 ** + Keep track of the line number in p->nLine.
2143 ** + Store the character that terminates the field in p->cTerm. Store
2144 ** EOF on end-of-file.
@@ -2208,11 +2243,11 @@
2208
2209 /* Read a single field of ASCII delimited text.
2210 **
2211 ** + Input comes from p->in.
2212 ** + Store results in p->z of length p->n. Space to hold p->z comes
2213 ** from sqlite3_malloc().
2214 ** + Use p->cSep as the column separator. The default is "\x1F".
2215 ** + Use p->rSep as the row separator. The default is "\x1E".
2216 ** + Keep track of the row number in p->nLine.
2217 ** + Store the character that terminates the field in p->cTerm. Store
2218 ** EOF on end-of-file.
@@ -2268,11 +2303,11 @@
2268 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2269 zQuery);
2270 goto end_data_xfer;
2271 }
2272 n = sqlite3_column_count(pQuery);
2273 zInsert = sqlite3_malloc(200 + nTable + n*3);
2274 if( zInsert==0 ){
2275 fprintf(stderr, "out of memory\n");
2276 goto end_data_xfer;
2277 }
2278 sqlite3_snprintf(200+nTable,zInsert,
@@ -2683,10 +2718,23 @@
2683 }else{
2684 fprintf(stderr, "Usage: .bail on|off\n");
2685 rc = 1;
2686 }
2687 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
2688
2689 /* The undocumented ".breakpoint" command causes a call to the no-op
2690 ** routine named test_breakpoint().
2691 */
2692 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
@@ -3023,11 +3071,11 @@
3023 }
3024 nCol = sqlite3_column_count(pStmt);
3025 sqlite3_finalize(pStmt);
3026 pStmt = 0;
3027 if( nCol==0 ) return 0; /* no columns, no error */
3028 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
3029 if( zSql==0 ){
3030 fprintf(stderr, "Error: out of memory\n");
3031 xCloser(sCtx.in);
3032 return 1;
3033 }
@@ -3163,10 +3211,67 @@
3163 sqlite3IoTrace = iotracePrintf;
3164 }
3165 }
3166 }else
3167 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3168
3169 #ifndef SQLITE_OMIT_LOAD_EXTENSION
3170 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
3171 const char *zFile, *zProc;
3172 char *zErrMsg = 0;
@@ -3648,11 +3753,11 @@
3648 }
3649 while( sqlite3_step(pStmt)==SQLITE_ROW ){
3650 if( nRow>=nAlloc ){
3651 char **azNew;
3652 int n2 = nAlloc*2 + 10;
3653 azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2);
3654 if( azNew==0 ){
3655 fprintf(stderr, "Error: out of memory\n");
3656 break;
3657 }
3658 nAlloc = n2;
3659
--- src/shell.c
+++ src/shell.c
@@ -988,11 +988,20 @@
988 break;
989 }
990 case MODE_Insert: {
991 p->cnt++;
992 if( azArg==0 ) break;
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(");
1003 for(i=0; i<nArg; i++){
1004 char *zSep = i>0 ? ",": "";
1005 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
1006 fprintf(p->out,"%sNULL",zSep);
1007 }else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1189,11 +1198,11 @@
1198 */
1199 static char *save_err_msg(
1200 sqlite3 *db /* Database to query */
1201 ){
1202 int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
1203 char *zErrMsg = sqlite3_malloc64(nErrMsg);
1204 if( zErrMsg ){
1205 memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
1206 }
1207 return zErrMsg;
1208 }
@@ -1426,12 +1435,12 @@
1435 int p2op = (p2 + (iOp-iAddr));
1436
1437 /* Grow the p->aiIndent array as required */
1438 if( iOp>=nAlloc ){
1439 nAlloc += 100;
1440 p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int));
1441 abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int));
1442 }
1443 abYield[iOp] = str_in_array(zOp, azYield);
1444 p->aiIndent[iOp] = 0;
1445 p->nIndent = iOp+1;
1446
@@ -1544,11 +1553,11 @@
1553 if( SQLITE_ROW == rc ){
1554 /* if we have a callback... */
1555 if( xCallback ){
1556 /* allocate space for col name ptr, value ptr, and type */
1557 int nCol = sqlite3_column_count(pStmt);
1558 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1559 if( !pData ){
1560 rc = SQLITE_NOMEM;
1561 }else{
1562 char **azCols = (char **)pData; /* Names of result columns */
1563 char **azVals = &azCols[nCol]; /* Results */
@@ -1770,10 +1779,11 @@
1779 ** Text of a help message
1780 */
1781 static char zHelp[] =
1782 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
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"
1785 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1786 ".databases List names and files of attached databases\n"
1787 ".dbinfo ?DB? Show status information about the database\n"
1788 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1789 " If TABLE specified, only dump tables matching\n"
@@ -1791,10 +1801,11 @@
1801 " If TABLE specified, only show indexes for tables\n"
1802 " matching LIKE pattern TABLE.\n"
1803 #ifdef SQLITE_ENABLE_IOTRACE
1804 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
1805 #endif
1806 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n"
1807 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1808 ".load FILE ?ENTRY? Load an extension library\n"
1809 #endif
1810 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1811 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -1860,11 +1871,11 @@
1871 in = fopen(zName, "rb");
1872 if( in==0 ) return;
1873 fseek(in, 0, SEEK_END);
1874 nIn = ftell(in);
1875 rewind(in);
1876 pBuf = sqlite3_malloc64( nIn );
1877 if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1878 sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
1879 }else{
1880 sqlite3_free(pBuf);
1881 }
@@ -1907,10 +1918,16 @@
1918 */
1919 static void open_db(ShellState *p, int keepAlive){
1920 if( p->db==0 ){
1921 sqlite3_initialize();
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
1929 globalDb = p->db;
1930 if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
1931 sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
1932 shellstaticFunc, 0, 0);
1933 }
@@ -1931,30 +1948,48 @@
1948 }
1949
1950 /*
1951 ** Do C-language style dequoting.
1952 **
1953 ** \a -> alarm
1954 ** \b -> backspace
1955 ** \t -> tab
1956 ** \n -> newline
1957 ** \v -> vertical tab
1958 ** \f -> form feed
1959 ** \r -> carriage return
1960 ** \s -> space
1961 ** \" -> "
1962 ** \' -> '
1963 ** \\ -> backslash
1964 ** \NNN -> ascii character NNN in octal
1965 */
1966 static void resolve_backslashes(char *z){
1967 int i, j;
1968 char c;
1969 while( *z && *z!='\\' ) z++;
1970 for(i=j=0; (c = z[i])!=0; i++, j++){
1971 if( c=='\\' && z[i+1]!=0 ){
1972 c = z[++i];
1973 if( c=='a' ){
1974 c = '\a';
1975 }else if( c=='b' ){
1976 c = '\b';
1977 }else if( c=='t' ){
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';
1985 }else if( c=='r' ){
1986 c = '\r';
1987 }else if( c=='"' ){
1988 c = '"';
1989 }else if( c=='\'' ){
1990 c = '\'';
1991 }else if( c=='\\' ){
1992 c = '\\';
1993 }else if( c>='0' && c<='7' ){
1994 c -= '0';
1995 if( z[i+1]>='0' && z[i+1]<='7' ){
@@ -2120,11 +2155,11 @@
2155
2156 /* Append a single byte to z[] */
2157 static void import_append_char(ImportCtx *p, int c){
2158 if( p->n+1>=p->nAlloc ){
2159 p->nAlloc += p->nAlloc + 100;
2160 p->z = sqlite3_realloc64(p->z, p->nAlloc);
2161 if( p->z==0 ){
2162 fprintf(stderr, "out of memory\n");
2163 exit(1);
2164 }
2165 }
@@ -2134,11 +2169,11 @@
2169 /* Read a single field of CSV text. Compatible with rfc4180 and extended
2170 ** with the option of having a separator other than ",".
2171 **
2172 ** + Input comes from p->in.
2173 ** + Store results in p->z of length p->n. Space to hold p->z comes
2174 ** from sqlite3_malloc64().
2175 ** + Use p->cSep as the column separator. The default is ",".
2176 ** + Use p->rSep as the row separator. The default is "\n".
2177 ** + Keep track of the line number in p->nLine.
2178 ** + Store the character that terminates the field in p->cTerm. Store
2179 ** EOF on end-of-file.
@@ -2208,11 +2243,11 @@
2243
2244 /* Read a single field of ASCII delimited text.
2245 **
2246 ** + Input comes from p->in.
2247 ** + Store results in p->z of length p->n. Space to hold p->z comes
2248 ** from sqlite3_malloc64().
2249 ** + Use p->cSep as the column separator. The default is "\x1F".
2250 ** + Use p->rSep as the row separator. The default is "\x1E".
2251 ** + Keep track of the row number in p->nLine.
2252 ** + Store the character that terminates the field in p->cTerm. Store
2253 ** EOF on end-of-file.
@@ -2268,11 +2303,11 @@
2303 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2304 zQuery);
2305 goto end_data_xfer;
2306 }
2307 n = sqlite3_column_count(pQuery);
2308 zInsert = sqlite3_malloc64(200 + nTable + n*3);
2309 if( zInsert==0 ){
2310 fprintf(stderr, "out of memory\n");
2311 goto end_data_xfer;
2312 }
2313 sqlite3_snprintf(200+nTable,zInsert,
@@ -2683,10 +2718,23 @@
2718 }else{
2719 fprintf(stderr, "Usage: .bail on|off\n");
2720 rc = 1;
2721 }
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
2736
2737 /* The undocumented ".breakpoint" command causes a call to the no-op
2738 ** routine named test_breakpoint().
2739 */
2740 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
@@ -3023,11 +3071,11 @@
3071 }
3072 nCol = sqlite3_column_count(pStmt);
3073 sqlite3_finalize(pStmt);
3074 pStmt = 0;
3075 if( nCol==0 ) return 0; /* no columns, no error */
3076 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
3077 if( zSql==0 ){
3078 fprintf(stderr, "Error: out of memory\n");
3079 xCloser(sCtx.in);
3080 return 1;
3081 }
@@ -3163,10 +3211,67 @@
3211 sqlite3IoTrace = iotracePrintf;
3212 }
3213 }
3214 }else
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
3273
3274 #ifndef SQLITE_OMIT_LOAD_EXTENSION
3275 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
3276 const char *zFile, *zProc;
3277 char *zErrMsg = 0;
@@ -3648,11 +3753,11 @@
3753 }
3754 while( sqlite3_step(pStmt)==SQLITE_ROW ){
3755 if( nRow>=nAlloc ){
3756 char **azNew;
3757 int n2 = nAlloc*2 + 10;
3758 azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2);
3759 if( azNew==0 ){
3760 fprintf(stderr, "Error: out of memory\n");
3761 break;
3762 }
3763 nAlloc = n2;
3764

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button