summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar thisLight2021-09-23 13:15:39 +0800
committerGravatar Vincent Rischmann2021-10-18 13:56:49 +0200
commitab297ad41f161012ef9ea50c50c727aa59df2630 (patch)
treee13d2acfe9026feb461adc42dea331877a26d71b
parentadd the StatementType function (diff)
downloadzig-sqlite-ab297ad41f161012ef9ea50c50c727aa59df2630.tar.gz
zig-sqlite-ab297ad41f161012ef9ea50c50c727aa59df2630.tar.xz
zig-sqlite-ab297ad41f161012ef9ea50c50c727aa59df2630.zip
Db.getPragmaQuery: use comptimePrint instead of bufPrint
-rw-r--r--sqlite.zig12
1 files changed, 5 insertions, 7 deletions
diff --git a/sqlite.zig b/sqlite.zig
index af970a1..af6c2ab 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -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();