summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sqlite.zig30
1 files changed, 27 insertions, 3 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 2f7db93..3335309 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -722,9 +722,6 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t
722 const column = i + 1; 722 const column = i + 1;
723 723
724 switch (FieldType) { 724 switch (FieldType) {
725 []const u8, []u8 => {
726 _ = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(c_int, field.len), null);
727 },
728 Text => _ = c.sqlite3_bind_text(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null), 725 Text => _ = c.sqlite3_bind_text(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null),
729 Blob => _ = c.sqlite3_bind_blob(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null), 726 Blob => _ = c.sqlite3_bind_blob(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null),
730 else => switch (field_type_info) { 727 else => switch (field_type_info) {
@@ -732,6 +729,13 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t
732 .Float, .ComptimeFloat => _ = c.sqlite3_bind_double(self.stmt, column, field), 729 .Float, .ComptimeFloat => _ = c.sqlite3_bind_double(self.stmt, column, field),
733 .Bool => _ = c.sqlite3_bind_int64(self.stmt, column, @boolToInt(field)), 730 .Bool => _ = c.sqlite3_bind_int64(self.stmt, column, @boolToInt(field)),
734 .Pointer => |ptr| switch (ptr.size) { 731 .Pointer => |ptr| switch (ptr.size) {
732 .One => self.bindField(ptr.child, field_name, i, field.*),
733 .Slice => switch (ptr.child) {
734 u8 => {
735 _ = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(c_int, field.len), null);
736 },
737 else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)),
738 },
735 else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)), 739 else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)),
736 }, 740 },
737 .Array => |arr| { 741 .Array => |arr| {
@@ -1289,6 +1293,26 @@ test "sqlite: insert bool and bind bool" {
1289 testing.expect(b.?); 1293 testing.expect(b.?);
1290} 1294}
1291 1295
1296test "sqlite: bind string literal" {
1297 var db: Db = undefined;
1298 try db.init(initOptions());
1299 try addTestData(&db);
1300
1301 try db.exec("INSERT INTO article(id, data) VALUES(?, ?)", .{
1302 @as(usize, 10),
1303 "foobar",
1304 });
1305
1306 const query = "SELECT id FROM article WHERE data = ?";
1307
1308 var stmt = try db.prepare(query);
1309 defer stmt.deinit();
1310
1311 const b = try stmt.one(usize, .{}, .{"foobar"});
1312 testing.expect(b != null);
1313 testing.expectEqual(@as(usize, 10), b.?);
1314}
1315
1292test "sqlite: statement reset" { 1316test "sqlite: statement reset" {
1293 var db: Db = undefined; 1317 var db: Db = undefined;
1294 try db.init(initOptions()); 1318 try db.init(initOptions());