mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-05 04:30:38 +03:00
In shell, reworked .header and .echo handling.
Updated shell_exec() to (really) handle multiple statements. Tickets [72adc99de9], [7b61b6c6ce], and [eb620916be]. FossilOrigin-Name: 790402c150e2026cd0c147a4cadbe9b9ab97b688
This commit is contained in:
24
manifest
24
manifest
@@ -1,8 +1,5 @@
|
|||||||
-----BEGIN PGP SIGNED MESSAGE-----
|
C In\sshell,\sreworked\s.header\sand\s.echo\shandling.\s\s\s\nUpdated\sshell_exec()\sto\s(really)\shandle\smultiple\sstatements.\nTickets\s[72adc99de9],\s[7b61b6c6ce],\sand\s[eb620916be].
|
||||||
Hash: SHA1
|
D 2009-10-22T21:23:35
|
||||||
|
|
||||||
C Merge\sthe\sMD5\schecksum\slogic\sinto\sthe\sTCL\sinterface.\s\sThis\sfacilitates\sbuilding\na\stclsh\sthat\scontains\sboth\sSQLite\sand\sMD5.\s\sThe\splan\sis\sto\suse\sthis\naugmented\stclsh\sto\shelp\sbuild\sthe\sdocumentation.
|
|
||||||
D 2009-10-22T20:52:05
|
|
||||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||||
F Makefile.in a77dfde96ad86aafd3f71651a4333a104debe86a
|
F Makefile.in a77dfde96ad86aafd3f71651a4333a104debe86a
|
||||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||||
@@ -164,7 +161,7 @@ F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
|
|||||||
F src/resolve.c 3ac31c7181fab03732125fdedf7c2091a5c07f1b
|
F src/resolve.c 3ac31c7181fab03732125fdedf7c2091a5c07f1b
|
||||||
F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f
|
F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f
|
||||||
F src/select.c cbe366a0ce114856e66f5daf0f848d7c48a88298
|
F src/select.c cbe366a0ce114856e66f5daf0f848d7c48a88298
|
||||||
F src/shell.c 5d875ff501a361459fb3b7750af7818298acb515
|
F src/shell.c 3a2b0649426d75b5cd2937ed90d06b25951a91e4
|
||||||
F src/sqlite.h.in 5853e42a4066a6c9c3bf6592a9d57d0012bfdb90
|
F src/sqlite.h.in 5853e42a4066a6c9c3bf6592a9d57d0012bfdb90
|
||||||
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
||||||
F src/sqliteInt.h 3b00a3ce79e60c5a47c342b738c8b75013f3ec84
|
F src/sqliteInt.h 3b00a3ce79e60c5a47c342b738c8b75013f3ec84
|
||||||
@@ -763,14 +760,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
P 9854ad00aed08793ae7ba3c2cfbab7a2dba4dcb8
|
P a024c0a85b6f2288c455a7192f6ca7a8493b621a
|
||||||
R ff5c7263b704c24b2617ea3d38e8b0a4
|
R 3ab26891a50ecbe8d9dce9e787f45010
|
||||||
U drh
|
U shane
|
||||||
Z beec7ddcfaa2c60bb6e07c180674b0ac
|
Z 313314dc4aa5889bc53b3806bff86b7f
|
||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
|
||||||
|
|
||||||
iD8DBQFK4MX4oxKgR168RlERArbdAJ90lkW1Q+8Lz1nMdSvuEiSBFrB0vgCgh6mI
|
|
||||||
NrvEz/WTtlUC3GfFZQ78MLs=
|
|
||||||
=xACK
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
a024c0a85b6f2288c455a7192f6ca7a8493b621a
|
790402c150e2026cd0c147a4cadbe9b9ab97b688
|
||||||
35
src/shell.c
35
src/shell.c
@@ -1501,6 +1501,11 @@ static void interrupt_handler(int NotUsed){
|
|||||||
static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType){
|
static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType){
|
||||||
int i;
|
int i;
|
||||||
struct callback_data *p = (struct callback_data*)pArg;
|
struct callback_data *p = (struct callback_data*)pArg;
|
||||||
|
|
||||||
|
if( p->echoOn && p->cnt==0 && p->pStmt){
|
||||||
|
printf("%s\n", sqlite3_sql(p->pStmt));
|
||||||
|
}
|
||||||
|
|
||||||
switch( p->mode ){
|
switch( p->mode ){
|
||||||
case MODE_Line: {
|
case MODE_Line: {
|
||||||
int w = 5;
|
int w = 5;
|
||||||
@@ -1643,6 +1648,7 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MODE_Insert: {
|
case MODE_Insert: {
|
||||||
|
p->cnt++;
|
||||||
if( azArg==0 ) break;
|
if( azArg==0 ) break;
|
||||||
fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
|
fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
|
||||||
for(i=0; i<nArg; i++){
|
for(i=0; i<nArg; i++){
|
||||||
@@ -1829,25 +1835,35 @@ static int shell_exec(
|
|||||||
char **pzErrMsg /* Error msg written here */
|
char **pzErrMsg /* Error msg written here */
|
||||||
){
|
){
|
||||||
sqlite3_stmt *pStmt = NULL;
|
sqlite3_stmt *pStmt = NULL;
|
||||||
int rc, rc2;
|
int rc = SQLITE_OK;
|
||||||
|
int rc2;
|
||||||
|
const char *zLeftover; /* Tail of unprocessed SQL */
|
||||||
|
|
||||||
if( pzErrMsg ){
|
if( pzErrMsg ){
|
||||||
*pzErrMsg = NULL;
|
*pzErrMsg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
|
while( zSql[0] && (SQLITE_OK == rc) ){
|
||||||
if( (SQLITE_OK != rc) || !pStmt ){
|
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
|
||||||
|
if( SQLITE_OK != rc ){
|
||||||
if( pzErrMsg ){
|
if( pzErrMsg ){
|
||||||
*pzErrMsg = save_err_msg(db);
|
*pzErrMsg = save_err_msg(db);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
if( !pStmt ){
|
||||||
|
/* this happens for a comment or white-space */
|
||||||
|
zSql = zLeftover;
|
||||||
|
while( isspace(zSql[0]) ) zSql++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* perform the first step. this will tell us if we
|
/* perform the first step. this will tell us if we
|
||||||
** have a result set or not and how wide it is.
|
** have a result set or not and how wide it is.
|
||||||
*/
|
*/
|
||||||
rc = sqlite3_step(pStmt);
|
rc = sqlite3_step(pStmt);
|
||||||
/* if we have a result set... */
|
/* if we have a result set... */
|
||||||
if( SQLITE_ROW == rc ){
|
if( SQLITE_ROW == rc ){
|
||||||
/* if callback... */
|
/* if we have a callback... */
|
||||||
if( xCallback ){
|
if( xCallback ){
|
||||||
/* allocate space for col name ptr, value ptr, and type */
|
/* allocate space for col name ptr, value ptr, and type */
|
||||||
int nCol = sqlite3_column_count(pStmt);
|
int nCol = sqlite3_column_count(pStmt);
|
||||||
@@ -1864,9 +1880,10 @@ static int shell_exec(
|
|||||||
for(i=0; i<nCol; i++){
|
for(i=0; i<nCol; i++){
|
||||||
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
|
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
|
||||||
}
|
}
|
||||||
/* save off the prepared statment handle */
|
/* save off the prepared statment handle and reset row count */
|
||||||
if( pArg ){
|
if( pArg ){
|
||||||
pArg->pStmt = pStmt;
|
pArg->pStmt = pStmt;
|
||||||
|
pArg->cnt = 0;
|
||||||
}
|
}
|
||||||
do{
|
do{
|
||||||
/* extract the data and data types */
|
/* extract the data and data types */
|
||||||
@@ -1919,7 +1936,13 @@ static int shell_exec(
|
|||||||
*pzErrMsg = save_err_msg(db);
|
*pzErrMsg = save_err_msg(db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( SQLITE_OK == rc ){
|
||||||
|
zSql = zLeftover;
|
||||||
|
while( isspace(zSql[0]) ) zSql++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} /* end while */
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -3024,9 +3047,9 @@ static int process_input(struct callback_data *p, FILE *in){
|
|||||||
seenInterrupt = 0;
|
seenInterrupt = 0;
|
||||||
}
|
}
|
||||||
lineno++;
|
lineno++;
|
||||||
if( p->echoOn ) printf("%s\n", zLine);
|
|
||||||
if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
|
if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
|
||||||
if( zLine && zLine[0]=='.' && nSql==0 ){
|
if( zLine && zLine[0]=='.' && nSql==0 ){
|
||||||
|
if( p->echoOn ) printf("%s\n", zLine);
|
||||||
rc = do_meta_command(zLine, p);
|
rc = do_meta_command(zLine, p);
|
||||||
if( rc==2 ){
|
if( rc==2 ){
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user