From: drh Date: Wed, 26 Aug 2020 19:07:18 +0000 (+0000) Subject: Enhance the ".databases" command in the CLI so that it shows the result X-Git-Tag: version-3.34.0~129 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=60081a03825a991ad08864f8d57f408a5c4002bb;p=thirdparty%2Fsqlite.git Enhance the ".databases" command in the CLI so that it shows the result of sqlite3_db_readonly() and sqlite3_txn_state() for each database file. FossilOrigin-Name: 0ffd16d23dd3b6467cce31af506c70fde44c3796d386c2a03896e43a6d683e60 --- diff --git a/manifest b/manifest index d029b62809..d50974cfe3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\sargument\sto\sthe\s".read"\scommand\sin\sthe\sCLI\sbegins\swith\s"|"\sthen\nrun\sthe\sremainder\sof\sthe\sargument\sas\sa\scommand\sand\sread\sinput\sfrom\sthe\noutput\sof\sthat\scommand. -D 2020-08-26T10:50:48.952 +C Enhance\sthe\s".databases"\scommand\sin\sthe\sCLI\sso\sthat\sit\sshows\sthe\sresult\nof\ssqlite3_db_readonly()\sand\ssqlite3_txn_state()\sfor\seach\sdatabase\sfile. +D 2020-08-26T19:07:18.179 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -536,7 +536,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 97b91fb25d86881ff20c9ad2ad98412c6c1bb5f7d6c9bb044db250cbc9cfcd4b F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 233e884d7da6601486c7b93aedb97fd29302ae5c03742d0e0eccb4790638bb77 -F src/shell.c.in 13b9ba4db8aa968de52921b86a0404683369577916a8e784d063725a1e1be502 +F src/shell.c.in d9aae37f76cc45b4ef6e8949979dbd124f9e5031789116c85d1aca396a37a403 F src/sqlite.h.in b91e4a5b9b25eb95260be0bf9716d2bdba0da06b72eb439f41592b226f58881d F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 2d1af80082edffd71c6f96f70ad1ce6a4fb46615ad10291fc77fe0dea9ff0197 @@ -1879,7 +1879,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ad195e3dd89d0f33b50070c18fb8f43c4eb24162515dfdd7c04d9e7d96b902a2 -R 2ccdd1b757645c61965446903a6a0fca +P 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492 +R 5c84472adafd40f98e2c21d6cafe8196 U drh -Z 4c5d539d1c5c3691ef762ff2f3c4571e +Z 0b7b01fe50d1610940d1117a5b7f17be diff --git a/manifest.uuid b/manifest.uuid index 6543348b67..17c2a0c1b3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492 \ No newline at end of file +0ffd16d23dd3b6467cce31af506c70fde44c3796d386c2a03896e43a6d683e60 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 61654f994e..d70ee318b9 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7583,21 +7583,42 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){ - ShellState data; - char *zErrMsg = 0; + char **azName = 0; + int nName = 0; + sqlite3_stmt *pStmt; + int rc; + int i; open_db(p, 0); - memcpy(&data, p, sizeof(data)); - data.showHeader = 0; - data.cMode = data.mode = MODE_List; - sqlite3_snprintf(sizeof(data.colSeparator),data.colSeparator,": "); - data.cnt = 0; - sqlite3_exec(p->db, "SELECT name, file FROM pragma_database_list", - callback, &data, &zErrMsg); - if( zErrMsg ){ - utf8_printf(stderr,"Error: %s\n", zErrMsg); - sqlite3_free(zErrMsg); + rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); + if( rc ){ + utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); rc = 1; + }else{ + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + const char *zSchema = (const char *)sqlite3_column_text(pStmt,1); + const char *zFile = (const char*)sqlite3_column_text(pStmt,2); + azName = sqlite3_realloc(azName, (nName+1)*2*sizeof(char*)); + if( azName==0 ){ shell_out_of_memory(); /* Does not return */ } + azName[nName*2] = strdup(zSchema); + azName[nName*2+1] = strdup(zFile); + nName++; + } } + sqlite3_finalize(pStmt); + for(i=0; idb, azName[i*2]); + int bRdonly = sqlite3_db_readonly(p->db, azName[i*2]); + const char *z = azName[i*2+1]; + utf8_printf(p->out, "%s: %s %s%s\n", + azName[i*2], + z && z[0] ? z : "\"\"", + bRdonly ? "r/o" : "r/w", + eTxn==SQLITE_TXN_NONE ? "" : + eTxn==SQLITE_TXN_READ ? " read-txn" : " write-txn"); + free(azName[i*2]); + free(azName[i*2+1]); + } + sqlite3_free(azName); }else if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){