diff options
| author | 2022-08-02 17:51:24 +0200 | |
|---|---|---|
| committer | 2022-08-02 18:18:51 +0200 | |
| commit | 530feae7884ae5942c50cba30a307ddbcd767402 (patch) | |
| tree | d49560ba8b01355246467d45bfaf03543f7e1d7c /sqlite.zig | |
| parent | some error codes are only available with sqlite >= 3.22.0 (diff) | |
| download | zig-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 '')
| -rw-r--r-- | sqlite.zig | 18 |
1 files changed, 16 insertions, 2 deletions
| @@ -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. |