]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
New diagnostic SQL function "sqlite_file_info()" and its associated
authordrh <>
Fri, 24 Oct 2025 17:42:03 +0000 (17:42 +0000)
committerdrh <>
Fri, 24 Oct 2025 17:42:03 +0000 (17:42 +0000)
file-control SQLITE_FCNTL_GET_INFO.

FossilOrigin-Name: 56ab9692583d5b64e1ab727e08a01c0a65b4e318b455c94397663ef8d3d7b6b8

manifest
manifest.tags
manifest.uuid
src/func.c
src/os_unix.c
src/os_win.c
src/sqlite.h.in

index 073d286a51152de38019d1d50f87fdf1da0ce1f9..8255cb8cef7aed59a1cf59638199a358c93af013 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sduplicate\sSQLITE_API\son\ssqlite3_carray_bind(),\sas\sreported\sin\s[forum:7499e8a19edc8908|forum\spost\s7499e8a19e].
-D 2025-10-24T17:16:00.748
+C New\sdiagnostic\sSQL\sfunction\s"sqlite_file_info()"\sand\sits\sassociated\nfile-control\sSQLITE_FCNTL_GET_INFO.
+D 2025-10-24T17:42:03.293
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -689,7 +689,7 @@ F src/delete.c 03a77ba20e54f0f42ebd8eddf15411ed6bdb06a2c472ac4b6b336521bf7cea42
 F src/expr.c 4d63c8f6d50fe20637de8bdaf57757a0e424e4ac5e2c3313e621d64727a48a1c
 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
 F src/fkey.c 928ed2517e8732113d2b9821aa37af639688d752f4ea9ac6e0e393d713eeb76f
-F src/func.c 4d945b54a0e931f7454dd9e07d34fd297531355730ec91cb3c06d28a96c7e938
+F src/func.c 16a792b33ae9b64097ca14ab2b7977c909ff207d7813bbbb2684ab9cc181f0b5
 F src/global.c a19e4b1ca1335f560e9560e590fc13081e21f670643367f99cb9e8f9dc7d615b
 F src/hash.c 73934a7f7ab1cb110614a9388cb516893b0cf5b7b69e4fd1a0780ac4ce166be7
 F src/hash.h 46b92795a95bfefb210f52f0c316e9d7cdbcdd7e7fcfb0d8be796d3a5767cddf
@@ -720,8 +720,8 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63
 F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06
 F src/os_kv.c fb7ba8d6204197357f1eb7e1c7450d09c10043bf7e99aba602f4aa46b8fb11a3
 F src/os_setup.h 8efc64eda6a6c2f221387eefc2e7e45fd5a3d5c8337a7a83519ba4fbd2957ae2
-F src/os_unix.c b3da55bc4bb214b2bfb1e430b10e9d3ebcf6b11741921ab044c9b9539c8fcc4f
-F src/os_win.c f81a7cffdfe8c593a840895b3f64290714f0186b06302d2c397012252d830374
+F src/os_unix.c 77431f8598277cec13faa80f2a25efd8e1473dc173fb276a238d2f28a8b91ac7
+F src/os_win.c 898016b346c27cff61ddec30a3c9a9b8df7b6413c1a8e14c784a6806003d912b
 F src/os_win.h 4c247cdb6d407c75186c94a1e84d5a22cbae4adcec93fcae8d2bc1f956fd1f19
 F src/pager.c 113f9149092ccff6cf90e97c2611200e5a237f13d26c394bc9fd933377852764
 F src/pager.h 6137149346e6c8a3ddc1eeb40aee46381e9bc8b0fcc6dda8a1efde993c2275b8
@@ -737,7 +737,7 @@ F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c b95181711d59c36d9789e67f76c4cfec64b99f9629a50be5e6566e117b87d957
 F src/shell.c.in 8d218cb62f8badb58cb6d91302ca8b6ccdc93232dd2ba39a9ace2e41fd8495cb
-F src/sqlite.h.in fcf692ee7d0997efee1e48ac9b533f18ec1eb2243255173134ab7ee0c70bc455
+F src/sqlite.h.in 3285114481f84812b9d8c1dc41a2dcd48ce4e79f610b8392ae398b56d1800e1e
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 7f236ca1b175ffe03316d974ef57df79b3938466c28d2f95caef5e08c57f3a52
 F src/sqliteInt.h 88f7fc9ce1630d9a5f7e0a8e1f3287cdc63882fba985c18e7eee1b9f457f59aa
@@ -2171,8 +2171,11 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P b99233fe3d901714c4369ba25c510050fb7a8a85c1168780108595e9639a6d15
-R b0c7233273321dd487050d6a581b3c9b
-U stephan
-Z 91d928da4fbc8c391d87f78c5eefdd2e
+P 62917cd4297e734477d3201481548ddb7f79ec977b9da7d9313bc7f1c0091187
+R 2dc6b0d73ecbb9f5657ef932a2fcf96a
+T *branch * file-info
+T *sym-file-info *
+T -sym-trunk *
+U drh
+Z be14a1f750cc9c17383cbb1543249676
 # Remove this line to create a well-formed Fossil manifest.
index bec971799ff1b8ee641c166c7aeb22d12c785393..1e3126ab6dd74fd0301f0b858558f52ab46e4ebe 100644 (file)
@@ -1,2 +1,2 @@
-branch trunk
-tag trunk
+branch file-info
+tag file-info
index 8d28d2a610db21e3d56e0cbc9270e8e8ada00217..8fcbafa49cf3c3bf5b27d1c52a896d5a1eb00651 100644 (file)
@@ -1 +1 @@
-62917cd4297e734477d3201481548ddb7f79ec977b9da7d9313bc7f1c0091187
+56ab9692583d5b64e1ab727e08a01c0a65b4e318b455c94397663ef8d3d7b6b8
index 8dd4673b80c32689463cad4c5073fa90bda494cc..be279499c4d33ce0d7433f7244d571edb7c253f8 100644 (file)
@@ -3083,6 +3083,54 @@ static void percentValue(sqlite3_context *pCtx){
 /****** End of percentile family of functions ******/
 #endif /* SQLITE_ENABLE_PERCENTILE */
 
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_FILE_INFO)
+/*
+** Implementation of sqlite_file_info(SCHEMA).
+**
+** Return JSON text that describes low-level debug/diagnostic information
+** about the sqlite3_file object associated with SCHEMA.
+*/
+static void fileInfoFunc(
+  sqlite3_context *context,
+  int argc,
+  sqlite3_value **argv
+){
+  sqlite3 *db = sqlite3_context_db_handle(context);
+  const char *zDbName;
+  sqlite3_str *pStr;
+  Btree *pBtree;
+
+  zDbName = (const char*)sqlite3_value_text(argv[0]);
+  pBtree = sqlite3DbNameToBtree(db, zDbName);
+  if( pBtree ){
+    Pager *pPager;
+    sqlite3_file *fd;
+    int rc;
+    sqlite3BtreeEnter(pBtree);
+    pPager = sqlite3BtreePager(pBtree);
+    assert( pPager!=0 );
+    fd = sqlite3PagerFile(pPager);
+    pStr = sqlite3_str_new(db);
+    if( pStr==0 ){
+      sqlite3_result_error_nomem(context);
+    }else{
+      sqlite3_str_append(pStr, "{\"db\":", 6);
+      rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_GET_INFO, pStr);
+      if( rc ) sqlite3_str_append(pStr, "null", 4);
+      fd = sqlite3PagerJrnlFile(pPager);
+      if( fd && fd->pMethods!=0 ){
+        sqlite3_str_appendall(pStr, ",\"journal\":");
+        rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_GET_INFO, pStr);
+        if( rc ) sqlite3_str_append(pStr, "null", 4);
+      }
+      sqlite3_str_append(pStr, "}", 1);
+      sqlite3_result_text(context, sqlite3_str_finish(pStr), -1,
+                          sqlite3_free);
+    }
+    sqlite3BtreeLeave(pBtree);
+  }
+}
+#endif /* SQLITE_DEBUG || SQLITE_ENABLE_FILE_INFO */
 
 #ifdef SQLITE_DEBUG
 /*
@@ -3241,6 +3289,9 @@ void sqlite3RegisterBuiltinFunctions(void){
     INLINE_FUNC(likely,          1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
     INLINE_FUNC(sqlite_offset,   1, INLINEFUNC_sqlite_offset, 0 ),
+#endif
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_FILE_INFO)
+    FUNCTION(sqlite_file_info,   1, 0, 0, fileInfoFunc     ),
 #endif
     FUNCTION(ltrim,              1, 1, 0, trimFunc         ),
     FUNCTION(ltrim,              2, 1, 0, trimFunc         ),
index b9e10b2c81cd9f4ae12f26b35ef921b3e680be97..f5f99750144d6dad5c13b70e79bc5d5c6e45fce6 100644 (file)
@@ -4144,6 +4144,19 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
       return SQLITE_OK;
 #endif
     }
+
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_FILE_INFO)
+    case SQLITE_FCNTL_GET_INFO: {
+      static const char *azLock[] = { "NONE", "SHARED", "RESERVED",
+                                      "PENDING", "EXCLUSIVE" };
+      sqlite3_str *pStr = (sqlite3_str*)pArg;
+      sqlite3_str_appendf(pStr, "{\"h\":%d,", pFile->h);
+      sqlite3_str_appendf(pStr, "\"vfs\":\"%s\",", pFile->pVfs->zName);
+      sqlite3_str_appendf(pStr, "\"eFileLock\":\"%s\"}", 
+                                azLock[pFile->eFileLock]);
+      return SQLITE_OK;
+    }
+#endif /* SQLITE_DEBUG || SQLITE_ENABLE_FILE_INFO */
   }
   return SQLITE_NOTFOUND;
 }
index 1862124c7bc6f07d31eb57ca28cc927c7b1d92e5..ca58dbd7525f307bb8e73521ed0ed8937f5c455f 100644 (file)
@@ -3953,6 +3953,16 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
     }
 #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
 
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_FILE_INFO)
+    case SQLITE_FCNTL_GET_INFO: {
+      sqlite3_str *pStr = (sqlite3_str*)pArg;
+      sqlite3_str_appendf(pStr, "{\n  \"h\":%llu", (sqlite3_uint64)pFile->h);
+      sqlite3_str_appendf(pStr, ",\n  \"vfs\":\"%s\"", pFile->pVfs->zName);
+      sqlite3_str_append(pStr, ",\n}", 3);
+      return SQLITE_OK;
+    }
+#endif /* SQLITE_DEBUG || SQLITE_ENABLE_FILE_INFO */
+
   }
   OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
   return SQLITE_NOTFOUND;
index 2bbee8e96696a8bb9e8b188710d4652d9e65870e..eee24aeb1cce1c87d2eacdf58b347875b4fb5809 100644 (file)
@@ -932,7 +932,7 @@ struct sqlite3_io_methods {
 ** connection.  See also [SQLITE_FCNTL_FILE_POINTER].
 **
 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
-** No longer in use.
+** The SQLITE_FCNTL_SYNC_OMITTED file-control is no longer used.
 **
 ** <li>[[SQLITE_FCNTL_SYNC]]
 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
@@ -1229,6 +1229,14 @@ struct sqlite3_io_methods {
 ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
 ** purges the contents of the in-memory page cache. If there is an open
 ** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
+**
+** <li>[[SQLITE_FCNTL_GET_INFO]]
+** The [SQLITE_FCNTL_GET_INFO] opcode returns debugging information about
+** the underlying [sqlite3_file].  The fourth parameter to [sqlite3_file_control()]
+** should be an initialized [sqlite3_str] pointer.  JSON text describing
+** various aspects of the sqlite3_file object is appended to the sqlite3_str.
+** The SQLITE_FCNTL_GET_INFO opcode is usually a no-op, unless compile-time
+** options are used to enable it.
 ** </ul>
 */
 #define SQLITE_FCNTL_LOCKSTATE               1
@@ -1274,6 +1282,7 @@ struct sqlite3_io_methods {
 #define SQLITE_FCNTL_RESET_CACHE            42
 #define SQLITE_FCNTL_NULL_IO                43
 #define SQLITE_FCNTL_BLOCK_ON_CONNECT       44
+#define SQLITE_FCNTL_GET_INFO               45
 
 /* deprecated names */
 #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE