From bfab3c6664fab3e6190a2d499ab5a59a30aaa216 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 27 Dec 2020 18:42:12 +0100 Subject: add the threading mode --- sqlite.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index b756fd8..dd4469b 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -12,6 +12,16 @@ usingnamespace @import("query.zig"); const logger = std.log.scoped(.sqlite); +pub const ThreadingMode = enum { + SingleThread, + MultiThread, + Serialized, +}; + +fn isThreadSafe() bool { + return c.sqlite3_threadsafe() > 0; +} + /// Db is a wrapper around a SQLite database, providing high-level functions for executing queries. /// A Db can be opened with a file database or a in-memory database: /// @@ -40,6 +50,10 @@ pub const Db = struct { self.allocator = allocator; const mode: Mode = if (@hasField(@TypeOf(options), "mode")) options.mode else .Memory; + // Validate the threading mode + if (options.threading_mode != .SingleThread and !isThreadSafe()) { + return error.CannotUseSingleThreadedSQLite; + } switch (mode) { .File => |path| { -- cgit v1.2.3