MCPcopy Create free account
hub / github.com/Kitware/VTK / shell_dbinfo_command

Function shell_dbinfo_command

ThirdParty/sqlite/vtksqlite/shell.c:26428–26520  ·  view source on GitHub ↗

** Implementation of the ".dbinfo" command. ** ** Return 1 on error, 2 to exit, and 0 otherwise. */

Source from the content-addressed store, hash-verified

26426** Return 1 on error, 2 to exit, and 0 otherwise.
26427*/
26428static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
26429 static const struct { const char *zName; int ofst; } aField[] = {
26430 { "file change counter:", 24 },
26431 { "database page count:", 28 },
26432 { "freelist page count:", 36 },
26433 { "schema cookie:", 40 },
26434 { "schema format:", 44 },
26435 { "default cache size:", 48 },
26436 { "autovacuum top root:", 52 },
26437 { "incremental vacuum:", 64 },
26438 { "text encoding:", 56 },
26439 { "user version:", 60 },
26440 { "application id:", 68 },
26441 { "software version:", 96 },
26442 };
26443 static const struct { const char *zName; const char *zSql; } aQuery[] = {
26444 { "number of tables:",
26445 "SELECT count(*) FROM %s WHERE type='table'" },
26446 { "number of indexes:",
26447 "SELECT count(*) FROM %s WHERE type='index'" },
26448 { "number of triggers:",
26449 "SELECT count(*) FROM %s WHERE type='trigger'" },
26450 { "number of views:",
26451 "SELECT count(*) FROM %s WHERE type='view'" },
26452 { "schema size:",
26453 "SELECT total(length(sql)) FROM %s" },
26454 };
26455 int i, rc;
26456 unsigned iDataVersion;
26457 char *zSchemaTab;
26458 char *zDb = nArg>=2 ? azArg[1] : "main";
26459 sqlite3_stmt *pStmt = 0;
26460 unsigned char aHdr[100];
26461 open_db(p, 0);
26462 if( p->db==0 ) return 1;
26463 rc = sqlite3_prepare_v2(p->db,
26464 "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
26465 -1, &pStmt, 0);
26466 if( rc ){
26467 sqlite3_fprintf(stderr,"error: %s\n", sqlite3_errmsg(p->db));
26468 sqlite3_finalize(pStmt);
26469 return 1;
26470 }
26471 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
26472 if( sqlite3_step(pStmt)==SQLITE_ROW
26473 && sqlite3_column_bytes(pStmt,0)>100
26474 ){
26475 const u8 *pb = sqlite3_column_blob(pStmt,0);
26476 shell_check_oom(pb);
26477 memcpy(aHdr, pb, 100);
26478 sqlite3_finalize(pStmt);
26479 }else{
26480 sqlite3_fputs("unable to read database header\n", stderr);
26481 sqlite3_finalize(pStmt);
26482 return 1;
26483 }
26484 i = get2byteInt(aHdr+16);
26485 if( i==1 ) i = 65536;

Callers 1

do_meta_commandFunction · 0.85

Calls 8

open_dbFunction · 0.85
sqlite3_fprintfFunction · 0.85
shell_check_oomFunction · 0.85
sqlite3_fputsFunction · 0.85
get2byteIntFunction · 0.85
get4byteIntFunction · 0.85
cli_strcmpFunction · 0.85
db_intFunction · 0.85

Tested by

no test coverage detected