MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / shell_dbinfo_command

Function shell_dbinfo_command

modules/dasSQLITE/sqlite/shell.c:21308–21398  ·  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

21306** Return 1 on error, 2 to exit, and 0 otherwise.
21307*/
21308static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
21309 static const struct { const char *zName; int ofst; } aField[] = {
21310 { "file change counter:", 24 },
21311 { "database page count:", 28 },
21312 { "freelist page count:", 36 },
21313 { "schema cookie:", 40 },
21314 { "schema format:", 44 },
21315 { "default cache size:", 48 },
21316 { "autovacuum top root:", 52 },
21317 { "incremental vacuum:", 64 },
21318 { "text encoding:", 56 },
21319 { "user version:", 60 },
21320 { "application id:", 68 },
21321 { "software version:", 96 },
21322 };
21323 static const struct { const char *zName; const char *zSql; } aQuery[] = {
21324 { "number of tables:",
21325 "SELECT count(*) FROM %s WHERE type='table'" },
21326 { "number of indexes:",
21327 "SELECT count(*) FROM %s WHERE type='index'" },
21328 { "number of triggers:",
21329 "SELECT count(*) FROM %s WHERE type='trigger'" },
21330 { "number of views:",
21331 "SELECT count(*) FROM %s WHERE type='view'" },
21332 { "schema size:",
21333 "SELECT total(length(sql)) FROM %s" },
21334 };
21335 int i, rc;
21336 unsigned iDataVersion;
21337 char *zSchemaTab;
21338 char *zDb = nArg>=2 ? azArg[1] : "main";
21339 sqlite3_stmt *pStmt = 0;
21340 unsigned char aHdr[100];
21341 open_db(p, 0);
21342 if( p->db==0 ) return 1;
21343 rc = sqlite3_prepare_v2(p->db,
21344 "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
21345 -1, &pStmt, 0);
21346 if( rc ){
21347 utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
21348 sqlite3_finalize(pStmt);
21349 return 1;
21350 }
21351 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
21352 if( sqlite3_step(pStmt)==SQLITE_ROW
21353 && sqlite3_column_bytes(pStmt,0)>100
21354 ){
21355 memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
21356 sqlite3_finalize(pStmt);
21357 }else{
21358 raw_printf(stderr, "unable to read database header\n");
21359 sqlite3_finalize(pStmt);
21360 return 1;
21361 }
21362 i = get2byteInt(aHdr+16);
21363 if( i==1 ) i = 65536;
21364 utf8_printf(p->out, "%-20s %d\n", "database page size:", i);
21365 utf8_printf(p->out, "%-20s %d\n", "write format:", aHdr[18]);

Callers 1

do_meta_commandFunction · 0.85

Calls 6

open_dbFunction · 0.85
utf8_printfFunction · 0.85
get2byteIntFunction · 0.85
get4byteIntFunction · 0.85
cli_strcmpFunction · 0.85
db_intFunction · 0.85

Tested by

no test coverage detected