diff options
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 12 |
1 files changed, 5 insertions, 7 deletions
| @@ -391,11 +391,11 @@ pub const Db = struct { | |||
| 391 | return getLastDetailedErrorFromDb(self.db); | 391 | return getLastDetailedErrorFromDb(self.db); |
| 392 | } | 392 | } |
| 393 | 393 | ||
| 394 | fn getPragmaQuery(comptime buf: []u8, comptime name: []const u8, comptime arg: ?[]const u8) []const u8 { | 394 | fn getPragmaQuery(comptime name: []const u8, comptime arg: ?[]const u8) []const u8 { |
| 395 | if (arg) |a| { | 395 | if (arg) |a| { |
| 396 | return try std.fmt.bufPrint(buf, "PRAGMA {s} = {s}", .{ name, a }); | 396 | return std.fmt.comptimePrint("PRAGMA {s} = {s}", .{ name, a }); |
| 397 | } | 397 | } |
| 398 | return try std.fmt.bufPrint(buf, "PRAGMA {s}", .{name}); | 398 | return std.fmt.comptimePrint("PRAGMA {s}", .{name}); |
| 399 | } | 399 | } |
| 400 | 400 | ||
| 401 | /// getLastInsertRowID returns the last inserted rowid. | 401 | /// getLastInsertRowID returns the last inserted rowid. |
| @@ -411,8 +411,7 @@ pub const Db = struct { | |||
| 411 | /// const journal_mode = try db.pragma([]const u8, allocator, .{}, "journal_mode", null); | 411 | /// const journal_mode = try db.pragma([]const u8, allocator, .{}, "journal_mode", null); |
| 412 | /// | 412 | /// |
| 413 | pub fn pragmaAlloc(self: *Self, comptime Type: type, allocator: *mem.Allocator, options: QueryOptions, comptime name: []const u8, comptime arg: ?[]const u8) !?Type { | 413 | pub fn pragmaAlloc(self: *Self, comptime Type: type, allocator: *mem.Allocator, options: QueryOptions, comptime name: []const u8, comptime arg: ?[]const u8) !?Type { |
| 414 | comptime var buf: [1024]u8 = undefined; | 414 | comptime var query = getPragmaQuery(name, arg); |
| 415 | comptime var query = getPragmaQuery(&buf, name, arg); | ||
| 416 | 415 | ||
| 417 | var stmt = try self.prepare(query); | 416 | var stmt = try self.prepare(query); |
| 418 | defer stmt.deinit(); | 417 | defer stmt.deinit(); |
| @@ -434,8 +433,7 @@ pub const Db = struct { | |||
| 434 | /// | 433 | /// |
| 435 | /// This cannot allocate memory. If your pragma command returns text you must use an array or call `pragmaAlloc`. | 434 | /// This cannot allocate memory. If your pragma command returns text you must use an array or call `pragmaAlloc`. |
| 436 | pub fn pragma(self: *Self, comptime Type: type, options: QueryOptions, comptime name: []const u8, comptime arg: ?[]const u8) !?Type { | 435 | pub fn pragma(self: *Self, comptime Type: type, options: QueryOptions, comptime name: []const u8, comptime arg: ?[]const u8) !?Type { |
| 437 | comptime var buf: [1024]u8 = undefined; | 436 | comptime var query = getPragmaQuery(name, arg); |
| 438 | comptime var query = getPragmaQuery(&buf, name, arg); | ||
| 439 | 437 | ||
| 440 | var stmt = try self.prepareWithDiags(query, options); | 438 | var stmt = try self.prepareWithDiags(query, options); |
| 441 | defer stmt.deinit(); | 439 | defer stmt.deinit(); |