mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-06 15:49:35 +03:00
In the command-line shell: importments to the "help" message and better
error checking in the new .import command. (CVS 1877) FossilOrigin-Name: ed489f776aed2de2f16e5c4b93ec6bc872118fb2
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Separate\sP4\stiming\sasm\scode\sout\sof\sthe\sSQLITE_DEBUG\smacro\sso\sthat\sSQLITE_DEBUG\ncan\sbe\sused\son\snon-x86\smachines\sand\swith\scompilers\sother\sthan\sGCC.\nTicket\s#838.\s(CVS\s1876)
|
C In\sthe\scommand-line\sshell:\simportments\sto\sthe\s"help"\smessage\sand\sbetter\nerror\schecking\sin\sthe\snew\s.import\scommand.\s(CVS\s1877)
|
||||||
D 2004-08-04T14:44:34
|
D 2004-08-04T15:16:55
|
||||||
F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b
|
F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b
|
||||||
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
||||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||||
@@ -58,7 +58,7 @@ F src/pragma.c c8be18093f0492f9983406647808781ca0073d8b
|
|||||||
F src/printf.c 17b28a1eedfe8129b05de981719306c18c3f1327
|
F src/printf.c 17b28a1eedfe8129b05de981719306c18c3f1327
|
||||||
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
||||||
F src/select.c cbed45f4af76ad7fdfc0a0df6878b2b3827ae1d4
|
F src/select.c cbed45f4af76ad7fdfc0a0df6878b2b3827ae1d4
|
||||||
F src/shell.c 7371f0a4b1c1aaed336176dfcc6e6742c138b263
|
F src/shell.c 4b40fac1a07512d6b8dbdf8abe0b4660d777c9ce
|
||||||
F src/sqlite.h.in c340a12b4d0521efb474dd000fba3bdfb18d76da
|
F src/sqlite.h.in c340a12b4d0521efb474dd000fba3bdfb18d76da
|
||||||
F src/sqliteInt.h 7a8dec83364d940372507ca4d4ff0c96bce05300
|
F src/sqliteInt.h 7a8dec83364d940372507ca4d4ff0c96bce05300
|
||||||
F src/table.c 4521c278892f60e4d630788c0ea5cf4db1e75c49
|
F src/table.c 4521c278892f60e4d630788c0ea5cf4db1e75c49
|
||||||
@@ -240,7 +240,7 @@ F www/tclsqlite.tcl 06a86cba4d7fc88e2bcd633b57702d3d16abebb5
|
|||||||
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
||||||
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
||||||
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
||||||
P 4e7953c13fd2cb32e5c97737c4b2f99b1b1edc9b
|
P add266ccc3146fa56572d109e84c8a79dc3df2ca
|
||||||
R 32ad53e3950d031bf8dd62a53bdface5
|
R 674b4df64dead6e35bf0c60489ccd67c
|
||||||
U drh
|
U drh
|
||||||
Z 06402d986b3876ed10b4e307c21b4abe
|
Z 8d01172e36dc4738ad87459856f6ce34
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
add266ccc3146fa56572d109e84c8a79dc3df2ca
|
ed489f776aed2de2f16e5c4b93ec6bc872118fb2
|
||||||
40
src/shell.c
40
src/shell.c
@@ -12,7 +12,7 @@
|
|||||||
** This file contains code to implement the "sqlite" command line
|
** This file contains code to implement the "sqlite" command line
|
||||||
** utility for accessing SQLite databases.
|
** utility for accessing SQLite databases.
|
||||||
**
|
**
|
||||||
** $Id: shell.c,v 1.108 2004/08/01 00:10:45 drh Exp $
|
** $Id: shell.c,v 1.109 2004/08/04 15:16:55 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -643,18 +643,24 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
|||||||
*/
|
*/
|
||||||
static char zHelp[] =
|
static char zHelp[] =
|
||||||
".databases List names and files of attached databases\n"
|
".databases List names and files of attached databases\n"
|
||||||
".dump ?TABLE? ... Dump the database in a text format\n"
|
".dump ?TABLE? ... Dump the database in an SQL text format\n"
|
||||||
".echo ON|OFF Turn command echo on or off\n"
|
".echo ON|OFF Turn command echo on or off\n"
|
||||||
".exit Exit this program\n"
|
".exit Exit this program\n"
|
||||||
".explain ON|OFF Turn output mode suitable for EXPLAIN on or off.\n"
|
".explain ON|OFF Turn output mode suitable for EXPLAIN on or off.\n"
|
||||||
".header(s) ON|OFF Turn display of headers on or off\n"
|
".header(s) ON|OFF Turn display of headers on or off\n"
|
||||||
".help Show this message\n"
|
".help Show this message\n"
|
||||||
".import FILE TABLE Import data from FILE\n"
|
".import FILE TABLE Import data from FILE into TABLE\n"
|
||||||
".indices TABLE Show names of all indices on TABLE\n"
|
".indices TABLE Show names of all indices on TABLE\n"
|
||||||
".mode MODE Set mode to one of: cvs column html insert line\n"
|
".mode MODE ?TABLE? Set output mode where MODE is on of:\n"
|
||||||
" list tabs tcl\n"
|
" cvs Comma-separated values\n"
|
||||||
".mode insert TABLE Generate SQL insert statements for TABLE\n"
|
" column Left-aligned columns. (See .width)\n"
|
||||||
".nullvalue STRING Print STRING instead of nothing for NULL data\n"
|
" html HTML <table> code\n"
|
||||||
|
" insert SQL insert statements for TABLE\n"
|
||||||
|
" line One value per line\n"
|
||||||
|
" list Values delimited by .separator string\n"
|
||||||
|
" tabs Tab-separated values\n"
|
||||||
|
" tcl TCL list elements\n"
|
||||||
|
".nullvalue STRING Print STRING in place of NULL values\n"
|
||||||
".output FILENAME Send output to FILENAME\n"
|
".output FILENAME Send output to FILENAME\n"
|
||||||
".output stdout Send output to the screen\n"
|
".output stdout Send output to the screen\n"
|
||||||
".prompt MAIN CONTINUE Replace the standard prompts\n"
|
".prompt MAIN CONTINUE Replace the standard prompts\n"
|
||||||
@@ -664,7 +670,7 @@ static char zHelp[] =
|
|||||||
".rekey OLD NEW NEW Change the encryption key\n"
|
".rekey OLD NEW NEW Change the encryption key\n"
|
||||||
#endif
|
#endif
|
||||||
".schema ?TABLE? Show the CREATE statements\n"
|
".schema ?TABLE? Show the CREATE statements\n"
|
||||||
".separator STRING Change separator string\n"
|
".separator STRING Change separator used by output mode and .import\n"
|
||||||
".show Show the current values for various settings\n"
|
".show Show the current values for various settings\n"
|
||||||
".tables ?PATTERN? List names of tables matching a LIKE pattern\n"
|
".tables ?PATTERN? List names of tables matching a LIKE pattern\n"
|
||||||
".timeout MS Try opening locked tables for MS milliseconds\n"
|
".timeout MS Try opening locked tables for MS milliseconds\n"
|
||||||
@@ -916,6 +922,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
|||||||
char **azCol; /* zLine[] broken up into columns */
|
char **azCol; /* zLine[] broken up into columns */
|
||||||
char *zCommit; /* How to commit changes */
|
char *zCommit; /* How to commit changes */
|
||||||
FILE *in; /* The input file */
|
FILE *in; /* The input file */
|
||||||
|
int lineno = 0; /* Line number of input file */
|
||||||
|
|
||||||
nSep = strlen(p->separator);
|
nSep = strlen(p->separator);
|
||||||
if( nSep==0 ){
|
if( nSep==0 ){
|
||||||
@@ -965,17 +972,24 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
|||||||
while( (zLine = local_getline(0, in))!=0 ){
|
while( (zLine = local_getline(0, in))!=0 ){
|
||||||
char *z;
|
char *z;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
lineno++;
|
||||||
azCol[0] = zLine;
|
azCol[0] = zLine;
|
||||||
for(i=0, z=zLine; *z; z++){
|
for(i=0, z=zLine; *z; z++){
|
||||||
if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
|
if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
|
||||||
*z = 0;
|
*z = 0;
|
||||||
i++;
|
i++;
|
||||||
if( i>=nCol ) break;
|
if( i<nCol ){
|
||||||
azCol[i] = &z[nSep];
|
azCol[i] = &z[nSep];
|
||||||
z += nSep-1;
|
z += nSep-1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while( i<nCol ) azCol[i++] = 0;
|
if( i+1!=nCol ){
|
||||||
|
fprintf(stderr,"%s line %d: expected %d columns of data but found %d\n",
|
||||||
|
zFile, lineno, nCol, i+1);
|
||||||
|
zCommit = "ROLLBACK";
|
||||||
|
break;
|
||||||
|
}
|
||||||
for(i=0; i<nCol; i++){
|
for(i=0; i<nCol; i++){
|
||||||
sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
|
sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
|
||||||
}
|
}
|
||||||
@@ -991,7 +1005,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
|||||||
free(azCol);
|
free(azCol);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
sqlite3_finalize(pStmt);
|
sqlite3_finalize(pStmt);
|
||||||
sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
|
sqlite3_exec(p->db, zCommit, 0, 0, 0);
|
||||||
}else
|
}else
|
||||||
|
|
||||||
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg>1 ){
|
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg>1 ){
|
||||||
|
|||||||
Reference in New Issue
Block a user