From cf9e4fa274474f38c22610412cde44f76ba98743 Mon Sep 17 00:00:00 2001 From: ketmar Date: Mon, 8 Nov 2021 08:29:17 +0000 Subject: [PATCH] sq3: added `getDataVersion()` database method FossilOrigin-Name: 72d1de040041401b934967c2bcca6360a96bdc9de0f04e953f09b131fcd24844 --- sq3.d | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/sq3.d b/sq3.d index f99681c..775d8b0 100644 --- a/sq3.d +++ b/sq3.d @@ -293,6 +293,38 @@ public: void setBusyTimeout (int msecs) nothrow @trusted @nogc { if (isOpen) sqlite3_busy_timeout(dbi.db, msecs); } void setMaxBusyTimeout () nothrow @trusted @nogc { if (isOpen) sqlite3_busy_timeout(dbi.db, 0x1fffffff); } + // will change if any change to the database occured, either with this connection, or with any other connection + uint getDataVersion () nothrow @trusted @nogc { + pragma(inline, true); + if (!isOpen) return 0; + uint res; + if (sqlite3_file_control(dbi.db, "main", SQLITE_FCNTL_DATA_VERSION, &res) != SQLITE_OK) res = 0; + return res; + } + + // will change if any change to the database occured, either with this connection, or with any other connection + uint getTempDataVersion () nothrow @trusted @nogc { + pragma(inline, true); + if (!isOpen) return 0; + uint res; + if (sqlite3_file_control(dbi.db, "temp", SQLITE_FCNTL_DATA_VERSION, &res) != SQLITE_OK) res = 0; + return res; + } + + // will change if any change to the database occured, either with this connection, or with any other connection + uint getDBDataVersion (const(char)[] dbname) nothrow @trusted @nogc { + import core.stdc.stdlib : malloc, free; + if (!isOpen || dbname.length == 0) return 0; + char* ts = cast(char*)malloc(dbname.length+1); + if (ts is null) return 0; + scope(exit) free(ts); + ts[0..dbname.length] = dbname[]; + ts[dbname.length] = 0; + uint res; + if (sqlite3_file_control(dbi.db, ts, SQLITE_FCNTL_DATA_VERSION, &res) != SQLITE_OK) res = 0; + return res; + } + // execute one or more SQL statements // SQLite will take care of splitting void execute (const(char)[] ops) { -- 2.11.4.GIT