summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2021-05-30 17:00:45 +0200
committerGravatar Vincent Rischmann2021-05-30 17:04:30 +0200
commitd5ced6bc3fdbb58d19d6633b16b82ede4ee950eb (patch)
tree649a80e00cce1fa931fa316810354379c5f999aa /sqlite.zig
parentMerge branch 'fix-latest-zig' (diff)
downloadzig-sqlite-d5ced6bc3fdbb58d19d6633b16b82ede4ee950eb.tar.gz
zig-sqlite-d5ced6bc3fdbb58d19d6633b16b82ede4ee950eb.tar.xz
zig-sqlite-d5ced6bc3fdbb58d19d6633b16b82ede4ee950eb.zip
set the eval branch quota in the return type block
`prepare` and `prepareWithDiags` parse the query at comptime in the return type definition. This exceeds the branch quota since https://github.com/ziglang/zig/commit/b11ac9c5bfb4048eb4aa561f8b3b058a76787f7e. Use a block and `@setEvalBranchQuota` to work around this. Fixes #30.
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig15
1 files changed, 10 insertions, 5 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 79286e3..143c279 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -443,8 +443,11 @@ pub const Db = struct {
443 } 443 }
444 444
445 /// prepareWithDiags is like `prepare` but takes an additional options argument. 445 /// prepareWithDiags is like `prepare` but takes an additional options argument.
446 pub fn prepareWithDiags(self: *Self, comptime query: []const u8, options: QueryOptions) !Statement(.{}, ParsedQuery.from(query)) { 446 pub fn prepareWithDiags(self: *Self, comptime query: []const u8, options: QueryOptions) !comptime blk: {
447 @setEvalBranchQuota(10000); 447 @setEvalBranchQuota(100000);
448 break :blk Statement(.{}, ParsedQuery.from(query));
449 } {
450 @setEvalBranchQuota(100000);
448 const parsed_query = ParsedQuery.from(query); 451 const parsed_query = ParsedQuery.from(query);
449 return Statement(.{}, comptime parsed_query).prepare(self, options, 0); 452 return Statement(.{}, comptime parsed_query).prepare(self, options, 0);
450 } 453 }
@@ -463,8 +466,11 @@ pub const Db = struct {
463 /// This is done because we type check the bind parameters when executing the statement later. 466 /// This is done because we type check the bind parameters when executing the statement later.
464 /// 467 ///
465 /// If you want additional error information in case of failures, use `prepareWithDiags`. 468 /// If you want additional error information in case of failures, use `prepareWithDiags`.
466 pub fn prepare(self: *Self, comptime query: []const u8) !Statement(.{}, ParsedQuery.from(query)) { 469 pub fn prepare(self: *Self, comptime query: []const u8) !comptime blk: {
467 @setEvalBranchQuota(10000); 470 @setEvalBranchQuota(100000);
471 break :blk Statement(.{}, ParsedQuery.from(query));
472 } {
473 @setEvalBranchQuota(100000);
468 const parsed_query = ParsedQuery.from(query); 474 const parsed_query = ParsedQuery.from(query);
469 return Statement(.{}, comptime parsed_query).prepare(self, .{}, 0); 475 return Statement(.{}, comptime parsed_query).prepare(self, .{}, 0);
470 } 476 }
@@ -1531,7 +1537,6 @@ test "sqlite: read a single integer value" {
1531 inline for (types) |typ| { 1537 inline for (types) |typ| {
1532 const query = "SELECT age FROM user WHERE id = ?{usize}"; 1538 const query = "SELECT age FROM user WHERE id = ?{usize}";
1533 1539
1534 @setEvalBranchQuota(5000);
1535 var stmt: Statement(.{}, ParsedQuery.from(query)) = try db.prepare(query); 1540 var stmt: Statement(.{}, ParsedQuery.from(query)) = try db.prepare(query);
1536 defer stmt.deinit(); 1541 defer stmt.deinit();
1537 1542