summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2022-08-02 17:51:24 +0200
committerGravatar Vincent Rischmann2022-08-02 18:18:51 +0200
commit530feae7884ae5942c50cba30a307ddbcd767402 (patch)
treed49560ba8b01355246467d45bfaf03543f7e1d7c /sqlite.zig
parentsome error codes are only available with sqlite >= 3.22.0 (diff)
downloadzig-sqlite-530feae7884ae5942c50cba30a307ddbcd767402.tar.gz
zig-sqlite-530feae7884ae5942c50cba30a307ddbcd767402.tar.xz
zig-sqlite-530feae7884ae5942c50cba30a307ddbcd767402.zip
create a specific CreateFunctionFlag struct based on the SQLite version
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig18
1 files changed, 16 insertions, 2 deletions
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 {
695 /// 695 ///
696 /// The flags SQLITE_UTF16LE, SQLITE_UTF16BE are not supported yet. SQLITE_UTF8 is the default and always on. 696 /// The flags SQLITE_UTF16LE, SQLITE_UTF16BE are not supported yet. SQLITE_UTF8 is the default and always on.
697 /// 697 ///
698 /// SQLITE_DIRECTONLY is only available on SQLite >= 3.30.0 so we create a different type based on the SQLite version.
699 ///
698 /// TODO(vincent): allow these flags when we know how to handle UTF16 data. 700 /// TODO(vincent): allow these flags when we know how to handle UTF16 data.
699 pub const CreateFunctionFlag = struct { 701 /// TODO(vincent): can we refactor this somehow to share the common stuff ?
702 pub const CreateFunctionFlag = if (c.SQLITE_VERSION_NUMBER >= 3030000) struct {
700 /// Equivalent to SQLITE_DETERMINISTIC 703 /// Equivalent to SQLITE_DETERMINISTIC
701 deterministic: bool = true, 704 deterministic: bool = true,
702 /// Equivalent to SQLITE_DIRECTONLY 705 /// Equivalent to SQLITE_DIRECTONLY
703 direct_only: bool = true, 706 direct_only: bool = true,
704 707
705 fn toCFlags(self: *const CreateFunctionFlag) c_int { 708 fn toCFlags(self: *const @This()) c_int {
706 var flags: c_int = c.SQLITE_UTF8; 709 var flags: c_int = c.SQLITE_UTF8;
707 if (self.deterministic) { 710 if (self.deterministic) {
708 flags |= c.SQLITE_DETERMINISTIC; 711 flags |= c.SQLITE_DETERMINISTIC;
@@ -712,6 +715,17 @@ pub const Db = struct {
712 } 715 }
713 return flags; 716 return flags;
714 } 717 }
718 } else struct {
719 /// Equivalent to SQLITE_DETERMINISTIC
720 deterministic: bool = true,
721
722 fn toCFlags(self: *const @This()) c_int {
723 var flags: c_int = c.SQLITE_UTF8;
724 if (self.deterministic) {
725 flags |= c.SQLITE_DETERMINISTIC;
726 }
727 return flags;
728 }
715 }; 729 };
716 730
717 /// Creates an aggregate SQLite function with the given name. 731 /// Creates an aggregate SQLite function with the given name.