diff options
| author | 2024-12-19 01:09:41 +0100 | |
|---|---|---|
| committer | 2024-12-19 01:09:41 +0100 | |
| commit | c355f614e82743770b891ed295cb0198ae62f55e (patch) | |
| tree | ca3be165114f929da14dc0bd87679c0ccdbe89f2 /sqlite.zig | |
| parent | Merge pull request #172 from JudsenAtFlexgen/Documentation-update (diff) | |
| parent | rework execMulti (diff) | |
| download | zig-sqlite-c355f614e82743770b891ed295cb0198ae62f55e.tar.gz zig-sqlite-c355f614e82743770b891ed295cb0198ae62f55e.tar.xz zig-sqlite-c355f614e82743770b891ed295cb0198ae62f55e.zip | |
Merge pull request #173 from vrischmann/fix-latest-zig
Fix latest zig
Diffstat (limited to '')
| -rw-r--r-- | sqlite.zig | 37 |
1 files changed, 11 insertions, 26 deletions
| @@ -810,30 +810,16 @@ pub const Db = struct { | |||
| 810 | /// | 810 | /// |
| 811 | /// Exmaple: 'create table a(); create table b();' | 811 | /// Exmaple: 'create table a(); create table b();' |
| 812 | pub fn execMulti(self: *Self, query: []const u8, options: QueryOptions) !void { | 812 | pub fn execMulti(self: *Self, query: []const u8, options: QueryOptions) !void { |
| 813 | var new_options = options; | 813 | var sql_tail: [*c]const u8 = query.ptr; |
| 814 | var sql_tail_ptr: ?[*:0]const u8 = null; | ||
| 815 | new_options.sql_tail_ptr = &sql_tail_ptr; | ||
| 816 | 814 | ||
| 817 | while (true) { | 815 | while (true) { |
| 818 | // continuously prepare and execute (dynamically as there's no | 816 | const new_query = std.mem.span(sql_tail); |
| 819 | // values to bind in this case) | 817 | if (new_query.len == 0) return; |
| 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 | } | ||
| 834 | 818 | ||
| 819 | var stmt = try DynamicStatement.prepareWithTail(self, new_query, options, 0, &sql_tail); | ||
| 835 | defer stmt.deinit(); | 820 | defer stmt.deinit(); |
| 836 | try stmt.exec(new_options, .{}); | 821 | |
| 822 | try stmt.exec(options, .{}); | ||
| 837 | } | 823 | } |
| 838 | } | 824 | } |
| 839 | 825 | ||
| @@ -1030,11 +1016,6 @@ pub const Savepoint = struct { | |||
| 1030 | pub const QueryOptions = struct { | 1016 | pub const QueryOptions = struct { |
| 1031 | /// if provided, diags will be populated in case of failures. | 1017 | /// if provided, diags will be populated in case of failures. |
| 1032 | diags: ?*Diagnostics = null, | 1018 | 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, | ||
| 1038 | }; | 1019 | }; |
| 1039 | 1020 | ||
| 1040 | /// Iterator allows iterating over a result set. | 1021 | /// Iterator allows iterating over a result set. |
| @@ -1568,6 +1549,10 @@ pub const DynamicStatement = struct { | |||
| 1568 | pub const PrepareError = error{EmptyQuery} || Error; | 1549 | pub const PrepareError = error{EmptyQuery} || Error; |
| 1569 | 1550 | ||
| 1570 | fn prepare(db: *Db, query: []const u8, options: QueryOptions, flags: c_uint) PrepareError!Self { | 1551 | 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 { | ||
| 1571 | var dummy_diags = Diagnostics{}; | 1556 | var dummy_diags = Diagnostics{}; |
| 1572 | var diags = options.diags orelse &dummy_diags; | 1557 | var diags = options.diags orelse &dummy_diags; |
| 1573 | const stmt = blk: { | 1558 | const stmt = blk: { |
| @@ -1578,7 +1563,7 @@ pub const DynamicStatement = struct { | |||
| 1578 | @intCast(query.len), | 1563 | @intCast(query.len), |
| 1579 | flags, | 1564 | flags, |
| 1580 | &tmp, | 1565 | &tmp, |
| 1581 | options.sql_tail_ptr, | 1566 | tail, |
| 1582 | ); | 1567 | ); |
| 1583 | if (result != c.SQLITE_OK) { | 1568 | if (result != c.SQLITE_OK) { |
| 1584 | diags.err = getLastDetailedErrorFromDb(db.db); | 1569 | diags.err = getLastDetailedErrorFromDb(db.db); |