mirror of
https://github.com/sqlite/sqlite.git
synced 2026-01-06 08:01:16 +03:00
Back out the "--raw" option on ".read" in the command-line shell. Instead,
fix the command-line shell so that if EOF is reached without seeing a final semicolon, it goes ahead and passes the accumulated SQL text to SQLite. FossilOrigin-Name: f98c8ac8c485098f163400d3a92d6afb4008adbe
This commit is contained in:
16
manifest
16
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Add\sextra\stests\sfor\sthe\sxBestIndex()\svirtual\stable\smethod.
|
C Back\sout\sthe\s"--raw"\soption\son\s".read"\sin\sthe\scommand-line\sshell.\s\sInstead,\nfix\sthe\scommand-line\sshell\sso\sthat\sif\sEOF\sis\sreached\swithout\sseeing\sa\nfinal\ssemicolon,\sit\sgoes\sahead\sand\spasses\sthe\saccumulated\sSQL\stext\sto\nSQLite.
|
||||||
D 2016-11-11T09:51:46.009
|
D 2016-11-11T14:54:22.386
|
||||||
F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
|
F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
|
||||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||||
F Makefile.msc e0217f2d35a0448abbe4b066132ae20136e8b408
|
F Makefile.msc e0217f2d35a0448abbe4b066132ae20136e8b408
|
||||||
@@ -388,7 +388,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
|
|||||||
F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b
|
F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b
|
||||||
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
|
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
|
||||||
F src/select.c ea3af83e2d0f245fef81ea4cf04cb730ce67f722
|
F src/select.c ea3af83e2d0f245fef81ea4cf04cb730ce67f722
|
||||||
F src/shell.c dd8dbdcfbbac328c9011ce70d516c6872f9bae6e
|
F src/shell.c f04e4af75c5517735397d060ed0b4a874104bb41
|
||||||
F src/sqlite.h.in 803f7050f69b2eea573fac219f3c92582c096027
|
F src/sqlite.h.in 803f7050f69b2eea573fac219f3c92582c096027
|
||||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||||
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
|
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
|
||||||
@@ -1087,7 +1087,7 @@ F test/shared_err.test 2f2aee20db294b9924e81f6ccbe60f19e21e8506
|
|||||||
F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
|
F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
|
||||||
F test/shell1.test 65b10cd8a90cda9b5af9100a45689a57dcc01a31
|
F test/shell1.test 65b10cd8a90cda9b5af9100a45689a57dcc01a31
|
||||||
F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b
|
F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b
|
||||||
F test/shell3.test da513d522ef6f01cee8475dcf8332bff8982b3dd
|
F test/shell3.test 9b95ba643eaa228376f06a898fb410ee9b6e57c1
|
||||||
F test/shell4.test 89ad573879a745974ff2df20ff97c5d6ffffbd5d
|
F test/shell4.test 89ad573879a745974ff2df20ff97c5d6ffffbd5d
|
||||||
F test/shell5.test 50a732c1c2158b1cd62cf53975ce1ea7ce6b9dc9
|
F test/shell5.test 50a732c1c2158b1cd62cf53975ce1ea7ce6b9dc9
|
||||||
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
|
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
|
||||||
@@ -1531,7 +1531,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P 6311a8bdb1f2e1813516a32d171aae030bd73fd3
|
P 642a8fba91d2bf61b494b845cb499714363209b1
|
||||||
R 3e019704b19690d86a1b7d773d983727
|
R 8f6e4afb0238a1c423a3400150605c04
|
||||||
U dan
|
U drh
|
||||||
Z f0d6f5c148a8f8096f5f4aa2078863db
|
Z 821b86c08ecda9d420b23c0425e87f9f
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
642a8fba91d2bf61b494b845cb499714363209b1
|
f98c8ac8c485098f163400d3a92d6afb4008adbe
|
||||||
119
src/shell.c
119
src/shell.c
@@ -4205,50 +4205,18 @@ static int do_meta_command(char *zLine, ShellState *p){
|
|||||||
|
|
||||||
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
|
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
|
||||||
FILE *alt;
|
FILE *alt;
|
||||||
char *zFile;
|
if( nArg!=2 ){
|
||||||
int rawMode = 0;
|
raw_printf(stderr, "Usage: .read FILE\n");
|
||||||
if( nArg!=2 && nArg!=3 ){
|
|
||||||
raw_printf(stderr, "Usage: .read [--raw] FILE\n");
|
|
||||||
rc = 1;
|
rc = 1;
|
||||||
goto meta_command_exit;
|
goto meta_command_exit;
|
||||||
}
|
}
|
||||||
if( nArg==3 ){
|
alt = fopen(azArg[1], "rb");
|
||||||
const char *z = azArg[1];
|
if( alt==0 ){
|
||||||
while( z[0]=='-' ) z++;
|
utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
|
||||||
if( strcmp(z,"raw")==0 ){
|
rc = 1;
|
||||||
rawMode = 1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
raw_printf(stderr, "unknown option: \"%s\"\n", azArg[1]);
|
|
||||||
rc = 1;
|
|
||||||
goto meta_command_exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zFile = azArg[nArg-1];
|
|
||||||
if( rawMode ){
|
|
||||||
char *z = readFile(zFile);
|
|
||||||
if( z==0 ){
|
|
||||||
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
|
|
||||||
rc = 1;
|
|
||||||
}else{
|
|
||||||
char *zErr = 0;
|
|
||||||
open_db(p, 1);
|
|
||||||
rc = sqlite3_exec(p->db, z, callback, p, &zErr);
|
|
||||||
sqlite3_free(z);
|
|
||||||
if( zErr ){
|
|
||||||
utf8_printf(stdout, "%s", zErr);
|
|
||||||
sqlite3_free(zErr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
alt = fopen(zFile, "rb");
|
rc = process_input(p, alt);
|
||||||
if( alt==0 ){
|
fclose(alt);
|
||||||
utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
|
|
||||||
rc = 1;
|
|
||||||
}else{
|
|
||||||
rc = process_input(p, alt);
|
|
||||||
fclose(alt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
|
|
||||||
@@ -5208,6 +5176,42 @@ static int line_is_complete(char *zSql, int nSql){
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Run a single line of SQL
|
||||||
|
*/
|
||||||
|
static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
|
||||||
|
int rc;
|
||||||
|
char *zErrMsg = 0;
|
||||||
|
|
||||||
|
open_db(p, 0);
|
||||||
|
if( p->backslashOn ) resolve_backslashes(zSql);
|
||||||
|
BEGIN_TIMER;
|
||||||
|
rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
|
||||||
|
END_TIMER;
|
||||||
|
if( rc || zErrMsg ){
|
||||||
|
char zPrefix[100];
|
||||||
|
if( in!=0 || !stdin_is_interactive ){
|
||||||
|
sqlite3_snprintf(sizeof(zPrefix), zPrefix,
|
||||||
|
"Error: near line %d:", startline);
|
||||||
|
}else{
|
||||||
|
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
|
||||||
|
}
|
||||||
|
if( zErrMsg!=0 ){
|
||||||
|
utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
|
||||||
|
sqlite3_free(zErrMsg);
|
||||||
|
zErrMsg = 0;
|
||||||
|
}else{
|
||||||
|
utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}else if( p->countChanges ){
|
||||||
|
raw_printf(p->out, "changes: %3d total_changes: %d\n",
|
||||||
|
sqlite3_changes(p->db), sqlite3_total_changes(p->db));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Read input from *in and process it. If *in==0 then input
|
** Read input from *in and process it. If *in==0 then input
|
||||||
** is interactive - the user is typing it it. Otherwise, input
|
** is interactive - the user is typing it it. Otherwise, input
|
||||||
@@ -5224,7 +5228,6 @@ static int process_input(ShellState *p, FILE *in){
|
|||||||
int nSql = 0; /* Bytes of zSql[] used */
|
int nSql = 0; /* Bytes of zSql[] used */
|
||||||
int nAlloc = 0; /* Allocated zSql[] space */
|
int nAlloc = 0; /* Allocated zSql[] space */
|
||||||
int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
|
int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
|
||||||
char *zErrMsg; /* Error message returned */
|
|
||||||
int rc; /* Error code */
|
int rc; /* Error code */
|
||||||
int errCnt = 0; /* Number of errors seen */
|
int errCnt = 0; /* Number of errors seen */
|
||||||
int lineno = 0; /* Current line number */
|
int lineno = 0; /* Current line number */
|
||||||
@@ -5284,32 +5287,7 @@ static int process_input(ShellState *p, FILE *in){
|
|||||||
}
|
}
|
||||||
if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
|
if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
|
||||||
&& sqlite3_complete(zSql) ){
|
&& sqlite3_complete(zSql) ){
|
||||||
p->cnt = 0;
|
errCnt += runOneSqlLine(p, zSql, in, startline);
|
||||||
open_db(p, 0);
|
|
||||||
if( p->backslashOn ) resolve_backslashes(zSql);
|
|
||||||
BEGIN_TIMER;
|
|
||||||
rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
|
|
||||||
END_TIMER;
|
|
||||||
if( rc || zErrMsg ){
|
|
||||||
char zPrefix[100];
|
|
||||||
if( in!=0 || !stdin_is_interactive ){
|
|
||||||
sqlite3_snprintf(sizeof(zPrefix), zPrefix,
|
|
||||||
"Error: near line %d:", startline);
|
|
||||||
}else{
|
|
||||||
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
|
|
||||||
}
|
|
||||||
if( zErrMsg!=0 ){
|
|
||||||
utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
|
|
||||||
sqlite3_free(zErrMsg);
|
|
||||||
zErrMsg = 0;
|
|
||||||
}else{
|
|
||||||
utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
|
|
||||||
}
|
|
||||||
errCnt++;
|
|
||||||
}else if( p->countChanges ){
|
|
||||||
raw_printf(p->out, "changes: %3d total_changes: %d\n",
|
|
||||||
sqlite3_changes(p->db), sqlite3_total_changes(p->db));
|
|
||||||
}
|
|
||||||
nSql = 0;
|
nSql = 0;
|
||||||
if( p->outCount ){
|
if( p->outCount ){
|
||||||
output_reset(p);
|
output_reset(p);
|
||||||
@@ -5320,11 +5298,8 @@ static int process_input(ShellState *p, FILE *in){
|
|||||||
nSql = 0;
|
nSql = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( nSql ){
|
if( nSql && !_all_whitespace(zSql) ){
|
||||||
if( !_all_whitespace(zSql) ){
|
runOneSqlLine(p, zSql, in, startline);
|
||||||
utf8_printf(stderr, "Error: incomplete SQL: %s\n", zSql);
|
|
||||||
errCnt++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free(zSql);
|
free(zSql);
|
||||||
free(zLine);
|
free(zLine);
|
||||||
|
|||||||
@@ -96,6 +96,6 @@ do_test shell3-2.6 {
|
|||||||
} {0 {}}
|
} {0 {}}
|
||||||
do_test shell3-2.7 {
|
do_test shell3-2.7 {
|
||||||
catchcmd "foo.db" "CREATE TABLE"
|
catchcmd "foo.db" "CREATE TABLE"
|
||||||
} {1 {Error: incomplete SQL: CREATE TABLE}}
|
} {1 {Error: near line 1: near "TABLE": syntax error}}
|
||||||
|
|
||||||
finish_test
|
finish_test
|
||||||
|
|||||||
Reference in New Issue
Block a user