diff options
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 6 |
1 files changed, 4 insertions, 2 deletions
| @@ -1618,7 +1618,8 @@ pub const DynamicStatement = struct { | |||
| 1618 | }, | 1618 | }, |
| 1619 | .Slice => switch (ptr.child) { | 1619 | .Slice => switch (ptr.child) { |
| 1620 | u8 => { | 1620 | u8 => { |
| 1621 | const result = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(c_int, field.len), null); | 1621 | // NOTE(vincent): The slice must live until after the prepared statement is finaliuzed, therefore we use SQLITE_STATIC to avoid a copy |
| 1622 | const result = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(c_int, field.len), c.SQLITE_STATIC); | ||
| 1622 | return convertResultToError(result); | 1623 | return convertResultToError(result); |
| 1623 | }, | 1624 | }, |
| 1624 | else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)), | 1625 | else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)), |
| @@ -1629,7 +1630,8 @@ pub const DynamicStatement = struct { | |||
| 1629 | u8 => { | 1630 | u8 => { |
| 1630 | const data: []const u8 = field[0..field.len]; | 1631 | const data: []const u8 = field[0..field.len]; |
| 1631 | 1632 | ||
| 1632 | const result = c.sqlite3_bind_text(self.stmt, column, data.ptr, @intCast(c_int, data.len), null); | 1633 | // NOTE(vincent): The array is temporary and must be copied, therefore we use SQLITE_TRANSIENT |
| 1634 | const result = c.sqlite3_bind_text(self.stmt, column, data.ptr, @intCast(c_int, data.len), c.SQLITE_TRANSIENT); | ||
| 1633 | return convertResultToError(result); | 1635 | return convertResultToError(result); |
| 1634 | }, | 1636 | }, |
| 1635 | else => @compileError("cannot bind field " ++ field_name ++ " of type array of " ++ @typeName(arr.child)), | 1637 | else => @compileError("cannot bind field " ++ field_name ++ " of type array of " ++ @typeName(arr.child)), |