aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-02-06 14:19:44 +0000
committerdrh <drh@noemail.net>2015-02-06 14:19:44 +0000
commitf7502f005e2cbf9e4773f18c0c7440580da3b9d5 (patch)
tree6a8ccee81dc30472d8edc007f967447b2bdcde53
parentfe0e84c9487cd6a2521d22ce9b9b3b4824bc8c41 (diff)
downloadsqlite-f7502f005e2cbf9e4773f18c0c7440580da3b9d5.tar.gz
sqlite-f7502f005e2cbf9e4773f18c0c7440580da3b9d5.zip
Add the ".info" command to the shell.
FossilOrigin-Name: 0a3100a7f264ffce6078c35e341f2f0af6c09fbb
-rw-r--r--manifest13
-rw-r--r--manifest.uuid2
-rw-r--r--src/shell.c96
3 files changed, 103 insertions, 8 deletions
diff --git a/manifest b/manifest
index cd3073554..fe39ae001 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\sindex_xinfo\spragma\swhich\sgives\sinformation\sabout\sthe\sfields\sthat\nreference\sthe\stable\sPRIMARY\sKEY\sin\saddition\sto\sthe\sindex\skey\sfields.\nAdd\sextra\scolumns\s"desc",\s"coll",\sand\s"key"\sto\sthe\sindex_info\sand\sindex_xinfo\npragmas.\s\sAdd\sthe\s"origin"\sand\s"partial"\scolumns\sto\sthe\sindex_list\spragma.
-D 2015-02-06T01:07:15.913
+C Add\sthe\s".info"\scommand\sto\sthe\sshell.
+D 2015-02-06T14:19:44.541
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 22b4406b0b59efd14b3b351a5809dda517df6d30
+F src/shell.c bb60212d7dc9698e97128b9599db31a946f9b09e
F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
@@ -1239,8 +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 71691c4be54b9ac6a35e35013f939b7d6fd4e6b8 3af19f84446ba5fc1ed754d0d73f6a6d7fb2f365
-R 378ae50354305236538b7809f97882cb
-T +closed 3af19f84446ba5fc1ed754d0d73f6a6d7fb2f365
+P 2743846cdba572f616f56d310633703b8b50959e
+R d4e7fe78c9cdff1cd20452301eb37621
U drh
-Z 9e4d57322f408f6027b92b8bd8c22512
+Z c6460a2ceed946b50a764986e8bd6e0e
diff --git a/manifest.uuid b/manifest.uuid
index 61e3ef24f..e0dfaca80 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-2743846cdba572f616f56d310633703b8b50959e \ No newline at end of file
+0a3100a7f264ffce6078c35e341f2f0af6c09fbb \ No newline at end of file
diff --git a/src/shell.c b/src/shell.c
index 3130f4c6d..f0e9743bc 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1748,6 +1748,7 @@ static char zHelp[] =
".indices ?TABLE? Show names of all indices\n"
" If TABLE specified, only show indices 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
@@ -2427,6 +2428,97 @@ static void output_reset(ShellState *p){
}
/*
+** Run an SQL command and return the single integer result.
+*/
+static int db_int(ShellState *p, const char *zSql){
+ sqlite3_stmt *pStmt;
+ int res = 0;
+ sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
+ if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
+ res = sqlite3_column_int(pStmt,0);
+ }
+ sqlite3_finalize(pStmt);
+ return res;
+}
+
+/*
+** Convert a 2-byte or 4-byte big-endian integer into a native integer
+*/
+unsigned int get2byteInt(unsigned char *a){
+ return (a[0]<<8) + a[1];
+}
+unsigned int get4byteInt(unsigned char *a){
+ return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
+}
+
+/*
+** Implementation of the ".info" command.
+**
+** 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 const struct { const char *zName; int ofst; } aField[] = {
+ { "file change counter:", 24 },
+ { "database page count:", 28 },
+ { "freelist page count:", 36 },
+ { "schema cookie:", 40 },
+ { "schema format:", 44 },
+ { "default cache size:", 48 },
+ { "autovacuum top root:", 52 },
+ { "incremental vacuum:", 64 },
+ { "text encoding:", 56 },
+ { "user version:", 60 },
+ { "application id:", 68 },
+ { "software version:", 96 },
+ };
+ open_db(p, 0);
+ if( p->db==0 ) return 1;
+ sqlite3_file_control(p->db, "main", SQLITE_FCNTL_FILE_POINTER, &pFile);
+ if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){
+ return 1;
+ }
+ i = pFile->pMethods->xRead(pFile, aHdr, 100, 0);
+ if( i!=SQLITE_OK ){
+ fprintf(stderr, "unable to read database header\n");
+ return 1;
+ }
+ i = get2byteInt(aHdr+16);
+ if( i==1 ) i = 65536;
+ fprintf(p->out, "%-20s %d\n", "database page size:", i);
+ fprintf(p->out, "%-20s %d\n", "write format:", aHdr[18]);
+ fprintf(p->out, "%-20s %d\n", "read format:", aHdr[19]);
+ fprintf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]);
+ for(i=0; i<sizeof(aField)/sizeof(aField[0]); i++){
+ int ofst = aField[i].ofst;
+ unsigned int val = get4byteInt(aHdr + ofst);
+ fprintf(p->out, "%-20s %u", aField[i].zName, val);
+ switch( ofst ){
+ case 56: {
+ if( val==1 ) fprintf(p->out, " (utf8)");
+ if( val==2 ) fprintf(p->out, " (utf16le)");
+ if( val==3 ) fprintf(p->out, " (utf16be)");
+ }
+ }
+ 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"));
+ return 0;
+}
+
+
+/*
** If an input line begins with "." then invoke this routine to
** process that line.
**
@@ -2980,6 +3072,10 @@ 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*, ...);