From: drh Date: Fri, 6 Feb 2015 14:51:13 +0000 (+0000) Subject: Change the name of ".info" to ".dbinfo" and add an optional second argument X-Git-Tag: version-3.8.9~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0e55db1cd8748942e3284eb94e774d825ff223fb;p=thirdparty%2Fsqlite.git Change the name of ".info" to ".dbinfo" and add an optional second argument which is the ATTACH-ed DB about which information is provided. Provide ".indexes" as an alternative name to the legacy ".indices" command. FossilOrigin-Name: 0f65a7e2e09f801b66897479d501607caeae4abf --- diff --git a/manifest b/manifest index fe39ae0018..b31e5b6454 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s".info"\scommand\sto\sthe\sshell. -D 2015-02-06T14:19:44.541 +C Change\sthe\sname\sof\s".info"\sto\s".dbinfo"\sand\sadd\san\soptional\ssecond\sargument\nwhich\sis\sthe\sATTACH-ed\sDB\sabout\swhich\sinformation\sis\sprovided.\s\sProvide\n".indexes"\sas\san\salternative\sname\sto\sthe\slegacy\s".indices"\scommand. +D 2015-02-06T14:51:13.355 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc -F src/shell.c bb60212d7dc9698e97128b9599db31a946f9b09e +F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -858,7 +858,7 @@ F test/sharedA.test 0cdf1a76dfa00e6beee66af5b534b1e8df2720f5 F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e F test/shared_err.test 2f2aee20db294b9924e81f6ccbe60f19e21e8506 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test cdeb849acc2c37aada70d084564b0cc0a2c7df08 +F test/shell1.test ca88b14a8fc8b1f3543a24e519d019585ac9c903 F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 F test/shell4.test 8a9c08976291e6c6c808b4d718f4a8b299f339f5 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2743846cdba572f616f56d310633703b8b50959e -R d4e7fe78c9cdff1cd20452301eb37621 +P 0a3100a7f264ffce6078c35e341f2f0af6c09fbb +R a582dddcff23f4b3aa0ab625ed7ba566 U drh -Z c6460a2ceed946b50a764986e8bd6e0e +Z 91c27780af6a4d5e0c7b8a8aa90c189d diff --git a/manifest.uuid b/manifest.uuid index e0dfaca80e..408d77792f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a3100a7f264ffce6078c35e341f2f0af6c09fbb \ No newline at end of file +0f65a7e2e09f801b66897479d501607caeae4abf \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index f0e9743bc3..77c9ab9e05 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1733,6 +1733,7 @@ static char zHelp[] = ".bail on|off Stop after hitting an error. Default OFF\n" ".clone NEWDB Clone data into NEWDB from the existing database\n" ".databases List names and files of attached databases\n" + ".dbinfo ?DB? Show status information about the database\n" ".dump ?TABLE? ... Dump the database in an SQL text format\n" " If TABLE specified, only dump tables matching\n" " LIKE pattern TABLE.\n" @@ -1745,10 +1746,9 @@ static char zHelp[] = ".headers on|off Turn display of headers on or off\n" ".help Show this message\n" ".import FILE TABLE Import data from FILE into TABLE\n" - ".indices ?TABLE? Show names of all indices\n" - " If TABLE specified, only show indices for tables\n" + ".indexes ?TABLE? Show names of all indexes\n" + " If TABLE specified, only show indexes for tables\n" " matching LIKE pattern TABLE.\n" - ".info Show status information about the database\n" #ifdef SQLITE_ENABLE_IOTRACE ".iotrace FILE Enable I/O diagnostic logging to FILE\n" #endif @@ -2456,10 +2456,7 @@ unsigned int get4byteInt(unsigned char *a){ ** ** Return 1 on error, 2 to exit, and 0 otherwise. */ -static int shell_info_command(ShellState *p){ - sqlite3_file *pFile; - int i; - unsigned char aHdr[100]; +static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ static const struct { const char *zName; int ofst; } aField[] = { { "file change counter:", 24 }, { "database page count:", 28 }, @@ -2474,9 +2471,26 @@ static int shell_info_command(ShellState *p){ { "application id:", 68 }, { "software version:", 96 }, }; + static const struct { const char *zName; const char *zSql; } aQuery[] = { + { "number of tables:", + "SELECT count(*) FROM %s WHERE type='table'" }, + { "number of indexes:", + "SELECT count(*) FROM %s WHERE type='index'" }, + { "number of triggers:", + "SELECT count(*) FROM %s WHERE type='trigger'" }, + { "number of views:", + "SELECT count(*) FROM %s WHERE type='view'" }, + { "schema size:", + "SELECT total(length(sql)) FROM %s" }, + }; + sqlite3_file *pFile; + int i; + char *zSchemaTab; + char *zDb = nArg>=2 ? azArg[1] : "main"; + unsigned char aHdr[100]; open_db(p, 0); if( p->db==0 ) return 1; - sqlite3_file_control(p->db, "main", SQLITE_FCNTL_FILE_POINTER, &pFile); + sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_FILE_POINTER, &pFile); if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){ return 1; } @@ -2504,16 +2518,20 @@ static int shell_info_command(ShellState *p){ } fprintf(p->out, "\n"); } - fprintf(p->out, "%-20s %d\n", "number of tables:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='table'")); - fprintf(p->out, "%-20s %d\n", "number of indexes:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='index'")); - fprintf(p->out, "%-20s %d\n", "number of triggers:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='trigger'")); - fprintf(p->out, "%-20s %d\n", "number of views:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='view'")); - fprintf(p->out, "%-20s %d\n", "schema size:", - db_int(p, "SELECT total(length(sql)) FROM sqlite_master")); + if( zDb==0 ){ + zSchemaTab = sqlite3_mprintf("main.sqlite_master"); + }else if( strcmp(zDb,"temp")==0 ){ + zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_master"); + }else{ + zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_master", zDb); + } + for(i=0; iout, "%-20s %d\n", aQuery[i].zName, val); + } + sqlite3_free(zSchemaTab); return 0; } @@ -2660,6 +2678,10 @@ static int do_meta_command(char *zLine, ShellState *p){ } }else + if( c=='d' && strncmp(azArg[0], "dbinfo", n)==0 ){ + rc = shell_dbinfo_command(p, nArg, azArg); + }else + if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){ open_db(p, 0); /* When playing back a "dump", the content might appear in an order @@ -3028,7 +3050,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0); }else - if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){ + if( c=='i' && (strncmp(azArg[0], "indices", n)==0 + || strncmp(azArg[0], "indexes", n)==0) ){ ShellState data; char *zErrMsg = 0; open_db(p, 0); @@ -3058,7 +3081,7 @@ static int do_meta_command(char *zLine, ShellState *p){ ); zShellStatic = 0; }else{ - fprintf(stderr, "Usage: .indices ?LIKE-PATTERN?\n"); + fprintf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); rc = 1; goto meta_command_exit; } @@ -3072,10 +3095,6 @@ static int do_meta_command(char *zLine, ShellState *p){ } }else - if( c=='i' && strncmp(azArg[0], "info", n)==0 ){ - rc = shell_info_command(p); - }else - #ifdef SQLITE_ENABLE_IOTRACE if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ extern void (*sqlite3IoTrace)(const char*, ...); diff --git a/test/shell1.test b/test/shell1.test index f24b00d494..874718447c 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -406,19 +406,22 @@ do_test shell1-3.11.3 { catchcmd "test.db" ".import FOO BAR BAD" } {1 {Usage: .import FILE TABLE}} -# .indices ?TABLE? Show names of all indices -# If TABLE specified, only show indices for tables +# .indexes ?TABLE? Show names of all indexes +# If TABLE specified, only show indexes for tables # matching LIKE pattern TABLE. do_test shell1-3.12.1 { - catchcmd "test.db" ".indices" + catchcmd "test.db" ".indexes" } {0 {}} do_test shell1-3.12.2 { + catchcmd "test.db" ".indexes FOO" +} {0 {}} +do_test shell1-3.12.2-legacy { catchcmd "test.db" ".indices FOO" } {0 {}} do_test shell1-3.12.3 { # too many arguments - catchcmd "test.db" ".indices FOO BAD" -} {1 {Usage: .indices ?LIKE-PATTERN?}} + catchcmd "test.db" ".indexes FOO BAD" +} {1 {Usage: .indexes ?LIKE-PATTERN?}} # .mode MODE ?TABLE? Set output mode where MODE is one of: # ascii Columns/rows delimited by 0x1F and 0x1E