From: shane Date: Fri, 23 Oct 2009 00:37:15 +0000 (+0000) Subject: In shell, modified "import" handling to ensure error code returned correctly on exit. X-Git-Tag: fts3-refactor~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=916f961b9e5508a7db80c90c307a14dd8fb992da;p=thirdparty%2Fsqlite.git In shell, modified "import" handling to ensure error code returned correctly on exit. Ticket [bd770b2c52]. FossilOrigin-Name: 009efad0f4293dd08a6f2f16d8eb9e94e2f962ca --- diff --git a/manifest b/manifest index 12177790e1..ff36b082a1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -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]. -D 2009-10-22T21:23:35 +C In\sshell,\smodified\s"import"\shandling\sto\sensure\serror\scode\sreturned\scorrectly\son\sexit.\nTicket\s[bd770b2c52]. +D 2009-10-23T00:37:16 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a77dfde96ad86aafd3f71651a4333a104debe86a F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -161,7 +161,7 @@ F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628 F src/resolve.c 3ac31c7181fab03732125fdedf7c2091a5c07f1b F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f F src/select.c cbe366a0ce114856e66f5daf0f848d7c48a88298 -F src/shell.c 3a2b0649426d75b5cd2937ed90d06b25951a91e4 +F src/shell.c 4b1d54c6deae0b9a9e477a5dbed1e9853f958f91 F src/sqlite.h.in 5853e42a4066a6c9c3bf6592a9d57d0012bfdb90 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 F src/sqliteInt.h 3b00a3ce79e60c5a47c342b738c8b75013f3ec84 @@ -760,7 +760,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P a024c0a85b6f2288c455a7192f6ca7a8493b621a -R 3ab26891a50ecbe8d9dce9e787f45010 +P 790402c150e2026cd0c147a4cadbe9b9ab97b688 +R ca40506625a393ee29409c8b893be283 U shane -Z 313314dc4aa5889bc53b3806bff86b7f +Z 5f0f64058678a5e5ac4bd6553c1be92d diff --git a/manifest.uuid b/manifest.uuid index d6cf4ce994..b7d0685d94 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -790402c150e2026cd0c147a4cadbe9b9ab97b688 \ No newline at end of file +009efad0f4293dd08a6f2f16d8eb9e94e2f962ca \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index d3eb330c73..6320015ca9 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2485,7 +2485,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg>=3 ){ char *zTable = azArg[2]; /* Insert data into this table */ char *zFile = azArg[1]; /* The file from which to extract data */ - sqlite3_stmt *pStmt; /* A statement */ + sqlite3_stmt *pStmt = NULL; /* A statement */ int rc; /* Result code */ int nCol; /* Number of columns in the table */ int nByte; /* Number of bytes in an SQL string */ @@ -2501,25 +2501,31 @@ static int do_meta_command(char *zLine, struct callback_data *p){ open_db(p); nSep = strlen30(p->separator); if( nSep==0 ){ - fprintf(stderr, "non-null separator required for import\n"); - return 0; + fprintf(stderr, "Error: non-null separator required for import\n"); + return 1; } zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable); - if( zSql==0 ) return 0; + if( zSql==0 ){ + fprintf(stderr, "Error: out of memory\n"); + return 1; + } nByte = strlen30(zSql); rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); if( rc ){ + if (pStmt) sqlite3_finalize(pStmt); fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db)); - nCol = 0; - rc = 1; - }else{ - nCol = sqlite3_column_count(pStmt); + return 1; } + nCol = sqlite3_column_count(pStmt); sqlite3_finalize(pStmt); + pStmt = 0; if( nCol==0 ) return 0; zSql = malloc( nByte + 20 + nCol*2 ); - if( zSql==0 ) return 0; + if( zSql==0 ){ + fprintf(stderr, "Error: out of memory\n"); + return 1; + } sqlite3_snprintf(nByte+20, zSql, "INSERT INTO '%q' VALUES(?", zTable); j = strlen30(zSql); for(i=1; idb, "BEGIN", 0, 0, 0); zCommit = "COMMIT"; @@ -2562,14 +2570,16 @@ static int do_meta_command(char *zLine, struct callback_data *p){ z += nSep-1; } } - } + } /* end for */ *z = 0; if( i+1!=nCol ){ - fprintf(stderr,"%s line %d: expected %d columns of data but found %d\n", - zFile, lineno, nCol, i+1); + fprintf(stderr, + "Error: %s line %d: expected %d columns of data but found %d\n", + zFile, lineno, nCol, i+1); zCommit = "ROLLBACK"; free(zLine); - break; + rc = 1; + break; /* from while */ } for(i=0; iechoOn ) printf("%s\n", zLine); rc = do_meta_command(zLine, p); - if( rc==2 ){ + if( rc==2 ){ /* exit requested */ break; }else if( rc ){ errCnt++; @@ -3405,8 +3415,8 @@ int main(int argc, char **argv){ /* Run just the command that follows the database name */ if( zFirstCmd[0]=='.' ){ - do_meta_command(zFirstCmd, &data); - exit(0); + rc = do_meta_command(zFirstCmd, &data); + exit(rc); }else{ int rc; open_db(&data);