diff options
| author | 2023-12-19 13:16:28 +0100 | |
|---|---|---|
| committer | 2023-12-19 13:16:28 +0100 | |
| commit | 8fe779aeb6eb365f404c3fa5c9415eb8b9ee245a (patch) | |
| tree | c536a3ca0dcc3f36afdd93d45dc3867a5be9f253 /sqlite.zig | |
| parent | Merge pull request #148 from Cloudef/master (diff) | |
| parent | Add distinct EmptyQuery error (diff) | |
| download | zig-sqlite-8fe779aeb6eb365f404c3fa5c9415eb8b9ee245a.tar.gz zig-sqlite-8fe779aeb6eb365f404c3fa5c9415eb8b9ee245a.tar.xz zig-sqlite-8fe779aeb6eb365f404c3fa5c9415eb8b9ee245a.zip | |
Merge pull request #149 from Cloudef/master
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 19 |
1 files changed, 14 insertions, 5 deletions
| @@ -821,9 +821,15 @@ pub const Db = struct { | |||
| 821 | if (sql_tail_ptr != null) { | 821 | if (sql_tail_ptr != null) { |
| 822 | const new_query = std.mem.span(sql_tail_ptr.?); | 822 | const new_query = std.mem.span(sql_tail_ptr.?); |
| 823 | if (new_query.len == 0) break; | 823 | if (new_query.len == 0) break; |
| 824 | stmt = try self.prepareDynamicWithDiags(new_query, new_options); | 824 | stmt = self.prepareDynamicWithDiags(new_query, new_options) catch |err| switch (err) { |
| 825 | error.EmptyQuery => break, | ||
| 826 | else => return err, | ||
| 827 | }; | ||
| 825 | } else { | 828 | } else { |
| 826 | stmt = try self.prepareDynamicWithDiags(query, new_options); | 829 | stmt = self.prepareDynamicWithDiags(query, new_options) catch |err| switch (err) { |
| 830 | error.EmptyQuery => break, | ||
| 831 | else => return err, | ||
| 832 | }; | ||
| 827 | } | 833 | } |
| 828 | 834 | ||
| 829 | defer stmt.deinit(); | 835 | defer stmt.deinit(); |
| @@ -960,6 +966,9 @@ pub const Savepoint = struct { | |||
| 960 | 966 | ||
| 961 | // From execDynamic | 967 | // From execDynamic |
| 962 | ExecReturnedData, | 968 | ExecReturnedData, |
| 969 | |||
| 970 | // From DynamiStatement | ||
| 971 | EmptyQuery, | ||
| 963 | } || std.fmt.AllocPrintError || Error; | 972 | } || std.fmt.AllocPrintError || Error; |
| 964 | 973 | ||
| 965 | fn init(db: *Db, name: []const u8) InitError!Self { | 974 | fn init(db: *Db, name: []const u8) InitError!Self { |
| @@ -1549,7 +1558,7 @@ pub const DynamicStatement = struct { | |||
| 1549 | 1558 | ||
| 1550 | const Self = @This(); | 1559 | const Self = @This(); |
| 1551 | 1560 | ||
| 1552 | pub const PrepareError = error{} || Error; | 1561 | pub const PrepareError = error{EmptyQuery} || Error; |
| 1553 | 1562 | ||
| 1554 | fn prepare(db: *Db, query: []const u8, options: QueryOptions, flags: c_uint) PrepareError!Self { | 1563 | fn prepare(db: *Db, query: []const u8, options: QueryOptions, flags: c_uint) PrepareError!Self { |
| 1555 | var dummy_diags = Diagnostics{}; | 1564 | var dummy_diags = Diagnostics{}; |
| @@ -1574,7 +1583,7 @@ pub const DynamicStatement = struct { | |||
| 1574 | .near = -1, | 1583 | .near = -1, |
| 1575 | .message = "the input query is not valid SQL (empty string or a comment)", | 1584 | .message = "the input query is not valid SQL (empty string or a comment)", |
| 1576 | }; | 1585 | }; |
| 1577 | return error.SQLiteError; | 1586 | return error.EmptyQuery; |
| 1578 | } | 1587 | } |
| 1579 | break :blk tmp.?; | 1588 | break :blk tmp.?; |
| 1580 | }; | 1589 | }; |
| @@ -3924,7 +3933,7 @@ test "sqlite: fuzzer found crashes" { | |||
| 3924 | }{ | 3933 | }{ |
| 3925 | .{ | 3934 | .{ |
| 3926 | .input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00CREATE TABLE \x80\x00\x00\x00ar(Wb)\x01", | 3935 | .input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00CREATE TABLE \x80\x00\x00\x00ar(Wb)\x01", |
| 3927 | .exp_error = error.SQLiteError, | 3936 | .exp_error = error.EmptyQuery, |
| 3928 | }, | 3937 | }, |
| 3929 | .{ | 3938 | .{ |
| 3930 | .input = "SELECT?", | 3939 | .input = "SELECT?", |