From 228558f3970c70c90f15cf9ee6e22e07f7190bfb Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Tue, 19 Dec 2023 11:28:38 +0900 Subject: query: fix zig fmt errors --- query.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query.zig b/query.zig index 647dc3e..2f33188 100644 --- a/query.zig +++ b/query.zig @@ -106,7 +106,7 @@ pub fn ParsedQuery(comptime query: []const u8) ParsedQueryState(query.len) { if (!isNamedIdentifierChar(c)) { // This marks the end of the named bind marker. state = .start; - const name = buf[hold_pos..pos - 1]; + const name = buf[hold_pos .. pos - 1]; if (bindMarkerForName(bind_markers[0..nb_bind_markers], name) == null) { bind_markers[nb_bind_markers].name = name; nb_bind_markers += 1; -- cgit v1.2.3 From 8c3a5444712ccdfcba13d83a80a4773c1fd59306 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 18 Dec 2023 10:03:48 +0900 Subject: Add distinct EmptyQuery error The execMulti will otherwise fail if there's whitespace and comments. Which is common if for example using @embedFile("some-schema.sql"); --- sqlite.zig | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sqlite.zig b/sqlite.zig index 7aceac9..e19f83b 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -821,9 +821,15 @@ pub const Db = struct { if (sql_tail_ptr != null) { const new_query = std.mem.span(sql_tail_ptr.?); if (new_query.len == 0) break; - stmt = try self.prepareDynamicWithDiags(new_query, new_options); + stmt = self.prepareDynamicWithDiags(new_query, new_options) catch |err| switch (err) { + error.EmptyQuery => break, + else => return err, + }; } else { - stmt = try self.prepareDynamicWithDiags(query, new_options); + stmt = self.prepareDynamicWithDiags(query, new_options) catch |err| switch (err) { + error.EmptyQuery => break, + else => return err, + }; } defer stmt.deinit(); @@ -960,6 +966,9 @@ pub const Savepoint = struct { // From execDynamic ExecReturnedData, + + // From DynamiStatement + EmptyQuery, } || std.fmt.AllocPrintError || Error; fn init(db: *Db, name: []const u8) InitError!Self { @@ -1549,7 +1558,7 @@ pub const DynamicStatement = struct { const Self = @This(); - pub const PrepareError = error{} || Error; + pub const PrepareError = error{EmptyQuery} || Error; fn prepare(db: *Db, query: []const u8, options: QueryOptions, flags: c_uint) PrepareError!Self { var dummy_diags = Diagnostics{}; @@ -1574,7 +1583,7 @@ pub const DynamicStatement = struct { .near = -1, .message = "the input query is not valid SQL (empty string or a comment)", }; - return error.SQLiteError; + return error.EmptyQuery; } break :blk tmp.?; }; @@ -3924,7 +3933,7 @@ test "sqlite: fuzzer found crashes" { }{ .{ .input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00CREATE TABLE \x80\x00\x00\x00ar(Wb)\x01", - .exp_error = error.SQLiteError, + .exp_error = error.EmptyQuery, }, .{ .input = "SELECT?", -- cgit v1.2.3