Skip to content

Commit c355f61

Browse files
authored
Merge pull request #173 from vrischmann/fix-latest-zig
Fix latest zig
2 parents 97811f2 + 5fb342c commit c355f61

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

sqlite.zig

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -810,30 +810,16 @@ pub const Db = struct {
810810
///
811811
/// Exmaple: 'create table a(); create table b();'
812812
pub fn execMulti(self: *Self, query: []const u8, options: QueryOptions) !void {
813-
var new_options = options;
814-
var sql_tail_ptr: ?[*:0]const u8 = null;
815-
new_options.sql_tail_ptr = &sql_tail_ptr;
813+
var sql_tail: [*c]const u8 = query.ptr;
816814

817815
while (true) {
818-
// continuously prepare and execute (dynamically as there's no
819-
// values to bind in this case)
820-
var stmt: DynamicStatement = undefined;
821-
if (sql_tail_ptr != null) {
822-
const new_query = std.mem.span(sql_tail_ptr.?);
823-
if (new_query.len == 0) break;
824-
stmt = self.prepareDynamicWithDiags(new_query, new_options) catch |err| switch (err) {
825-
error.EmptyQuery => break,
826-
else => return err,
827-
};
828-
} else {
829-
stmt = self.prepareDynamicWithDiags(query, new_options) catch |err| switch (err) {
830-
error.EmptyQuery => break,
831-
else => return err,
832-
};
833-
}
816+
const new_query = std.mem.span(sql_tail);
817+
if (new_query.len == 0) return;
834818

819+
var stmt = try DynamicStatement.prepareWithTail(self, new_query, options, 0, &sql_tail);
835820
defer stmt.deinit();
836-
try stmt.exec(new_options, .{});
821+
822+
try stmt.exec(options, .{});
837823
}
838824
}
839825

@@ -1030,11 +1016,6 @@ pub const Savepoint = struct {
10301016
pub const QueryOptions = struct {
10311017
/// if provided, diags will be populated in case of failures.
10321018
diags: ?*Diagnostics = null,
1033-
1034-
/// if provided, sql_tail_ptr will point to the last uncompiled statement
1035-
/// in the prepare() call. this is useful for multiple-statements being
1036-
/// processed.
1037-
sql_tail_ptr: ?*?[*:0]const u8 = null,
10381019
};
10391020

10401021
/// Iterator allows iterating over a result set.
@@ -1568,6 +1549,10 @@ pub const DynamicStatement = struct {
15681549
pub const PrepareError = error{EmptyQuery} || Error;
15691550

15701551
fn prepare(db: *Db, query: []const u8, options: QueryOptions, flags: c_uint) PrepareError!Self {
1552+
return prepareWithTail(db, query, options, flags, null);
1553+
}
1554+
1555+
fn prepareWithTail(db: *Db, query: []const u8, options: QueryOptions, flags: c_uint, tail: ?*[*c]const u8) PrepareError!Self {
15711556
var dummy_diags = Diagnostics{};
15721557
var diags = options.diags orelse &dummy_diags;
15731558
const stmt = blk: {
@@ -1578,7 +1563,7 @@ pub const DynamicStatement = struct {
15781563
@intCast(query.len),
15791564
flags,
15801565
&tmp,
1581-
options.sql_tail_ptr,
1566+
tail,
15821567
);
15831568
if (result != c.SQLITE_OK) {
15841569
diags.err = getLastDetailedErrorFromDb(db.db);

vtab.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub const ModuleContext = struct {
3232
allocator: mem.Allocator,
3333
};
3434

35-
fn dupeToSQLiteString(s: []const u8) [*c]const u8 {
35+
fn dupeToSQLiteString(s: []const u8) [*c]u8 {
3636
var buffer: [*c]u8 = @ptrCast(c.sqlite3_malloc(@intCast(s.len + 1)));
3737

3838
mem.copyForwards(u8, buffer[0..s.len], s);
@@ -730,7 +730,7 @@ pub fn VirtualTable(
730730
return c.SQLITE_ERROR;
731731
}
732732

733-
fn xConnect(db: ?*c.sqlite3, module_context_ptr: ?*anyopaque, argc: c_int, argv: [*c]const [*c]const u8, vtab: [*c][*c]c.sqlite3_vtab, err_str: [*c][*c]const u8) callconv(.C) c_int {
733+
fn xConnect(db: ?*c.sqlite3, module_context_ptr: ?*anyopaque, argc: c_int, argv: [*c]const [*c]const u8, vtab: [*c][*c]c.sqlite3_vtab, err_str: [*c][*c]u8) callconv(.C) c_int {
734734
const module_context = getModuleContext(module_context_ptr);
735735

736736
var arena = heap.ArenaAllocator.init(module_context.allocator);

0 commit comments

Comments
 (0)