]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the ".info" command to the shell.
authordrh <drh@noemail.net>
Fri, 6 Feb 2015 14:19:44 +0000 (14:19 +0000)
committerdrh <drh@noemail.net>
Fri, 6 Feb 2015 14:19:44 +0000 (14:19 +0000)
FossilOrigin-Name: 0a3100a7f264ffce6078c35e341f2f0af6c09fbb

manifest
manifest.uuid
src/shell.c

index cd3073554943a8d0b138687ce04149c8687ff768..fe39ae0018d1cd06ae352cf9115f95b9eb79c9b8 100644 (file)
--- 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
index 61e3ef24f0b37aabbf45ee9bec96fd1685c38fe8..e0dfaca80e1a3245535bf30cb5577b497f91cc62 100644 (file)
@@ -1 +1 @@
-2743846cdba572f616f56d310633703b8b50959e
\ No newline at end of file
+0a3100a7f264ffce6078c35e341f2f0af6c09fbb
\ No newline at end of file
index 3130f4c6de7e95c0abded9d3c39867c12e3a242c..f0e9743bc36d31922b127272b442bad03e1186a8 100644 (file)
@@ -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
@@ -2426,6 +2427,97 @@ static void output_reset(ShellState *p){
   p->out = stdout;
 }
 
+/*
+** 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*, ...);