From 530feae7884ae5942c50cba30a307ddbcd767402 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Tue, 2 Aug 2022 17:51:24 +0200 Subject: create a specific CreateFunctionFlag struct based on the SQLite version --- sqlite.zig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index e4757a2..9308956 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -695,14 +695,17 @@ pub const Db = struct { /// /// The flags SQLITE_UTF16LE, SQLITE_UTF16BE are not supported yet. SQLITE_UTF8 is the default and always on. /// + /// SQLITE_DIRECTONLY is only available on SQLite >= 3.30.0 so we create a different type based on the SQLite version. + /// /// TODO(vincent): allow these flags when we know how to handle UTF16 data. - pub const CreateFunctionFlag = struct { + /// TODO(vincent): can we refactor this somehow to share the common stuff ? + pub const CreateFunctionFlag = if (c.SQLITE_VERSION_NUMBER >= 3030000) struct { /// Equivalent to SQLITE_DETERMINISTIC deterministic: bool = true, /// Equivalent to SQLITE_DIRECTONLY direct_only: bool = true, - fn toCFlags(self: *const CreateFunctionFlag) c_int { + fn toCFlags(self: *const @This()) c_int { var flags: c_int = c.SQLITE_UTF8; if (self.deterministic) { flags |= c.SQLITE_DETERMINISTIC; @@ -712,6 +715,17 @@ pub const Db = struct { } return flags; } + } else struct { + /// Equivalent to SQLITE_DETERMINISTIC + deterministic: bool = true, + + fn toCFlags(self: *const @This()) c_int { + var flags: c_int = c.SQLITE_UTF8; + if (self.deterministic) { + flags |= c.SQLITE_DETERMINISTIC; + } + return flags; + } }; /// Creates an aggregate SQLite function with the given name. -- cgit v1.2.3