diff options
| author | 2023-07-02 15:28:30 +0200 | |
|---|---|---|
| committer | 2023-07-02 15:28:37 +0200 | |
| commit | ce7a6a7b657e4c8f9514d4181230068bd45823e2 (patch) | |
| tree | ba788b9916d5d879737959d4823af9fbd104b4df /sqlite.zig | |
| parent | fuzz: fix for latest zig (diff) | |
| download | zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.tar.gz zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.tar.xz zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.zip | |
update for latest zig
Diffstat (limited to '')
| -rw-r--r-- | sqlite.zig | 95 |
1 files changed, 45 insertions, 50 deletions
| @@ -107,21 +107,21 @@ pub const Blob = struct { | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | var tmp_buffer = blk: { | 109 | var tmp_buffer = blk: { |
| 110 | const remaining = @intCast(usize, self.size) - @intCast(usize, self.offset); | 110 | const remaining: usize = @as(usize, @intCast(self.size)) - @as(usize, @intCast(self.offset)); |
| 111 | break :blk if (buffer.len > remaining) buffer[0..remaining] else buffer; | 111 | break :blk if (buffer.len > remaining) buffer[0..remaining] else buffer; |
| 112 | }; | 112 | }; |
| 113 | 113 | ||
| 114 | const result = c.sqlite3_blob_read( | 114 | const result = c.sqlite3_blob_read( |
| 115 | self.handle, | 115 | self.handle, |
| 116 | tmp_buffer.ptr, | 116 | tmp_buffer.ptr, |
| 117 | @intCast(c_int, tmp_buffer.len), | 117 | @intCast(tmp_buffer.len), |
| 118 | self.offset, | 118 | self.offset, |
| 119 | ); | 119 | ); |
| 120 | if (result != c.SQLITE_OK) { | 120 | if (result != c.SQLITE_OK) { |
| 121 | return errors.errorFromResultCode(result); | 121 | return errors.errorFromResultCode(result); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | self.offset += @intCast(c_int, tmp_buffer.len); | 124 | self.offset += @intCast(tmp_buffer.len); |
| 125 | 125 | ||
| 126 | return tmp_buffer.len; | 126 | return tmp_buffer.len; |
| 127 | } | 127 | } |
| @@ -137,14 +137,14 @@ pub const Blob = struct { | |||
| 137 | const result = c.sqlite3_blob_write( | 137 | const result = c.sqlite3_blob_write( |
| 138 | self.handle, | 138 | self.handle, |
| 139 | data.ptr, | 139 | data.ptr, |
| 140 | @intCast(c_int, data.len), | 140 | @intCast(data.len), |
| 141 | self.offset, | 141 | self.offset, |
| 142 | ); | 142 | ); |
| 143 | if (result != c.SQLITE_OK) { | 143 | if (result != c.SQLITE_OK) { |
| 144 | return errors.errorFromResultCode(result); | 144 | return errors.errorFromResultCode(result); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | self.offset += @intCast(c_int, data.len); | 147 | self.offset += @intCast(data.len); |
| 148 | 148 | ||
| 149 | return data.len; | 149 | return data.len; |
| 150 | } | 150 | } |
| @@ -191,7 +191,7 @@ pub const Blob = struct { | |||
| 191 | column, | 191 | column, |
| 192 | row, | 192 | row, |
| 193 | open_flags, | 193 | open_flags, |
| 194 | @ptrCast([*c]?*c.sqlite3_blob, &blob.handle), | 194 | @ptrCast(&blob.handle), |
| 195 | ); | 195 | ); |
| 196 | if (result == c.SQLITE_MISUSE) debug.panic("sqlite misuse while opening a blob", .{}); | 196 | if (result == c.SQLITE_MISUSE) debug.panic("sqlite misuse while opening a blob", .{}); |
| 197 | if (result != c.SQLITE_OK) { | 197 | if (result != c.SQLITE_OK) { |
| @@ -528,7 +528,7 @@ pub const Db = struct { | |||
| 528 | 528 | ||
| 529 | /// rowsAffected returns the number of rows affected by the last statement executed. | 529 | /// rowsAffected returns the number of rows affected by the last statement executed. |
| 530 | pub fn rowsAffected(self: *Self) usize { | 530 | pub fn rowsAffected(self: *Self) usize { |
| 531 | return @intCast(usize, c.sqlite3_changes(self.db)); | 531 | return @intCast(c.sqlite3_changes(self.db)); |
| 532 | } | 532 | } |
| 533 | 533 | ||
| 534 | /// openBlob opens a blob for incremental i/o. | 534 | /// openBlob opens a blob for incremental i/o. |
| @@ -825,12 +825,10 @@ pub const FunctionContext = struct { | |||
| 825 | 825 | ||
| 826 | pub fn userContext(self: FunctionContext, comptime Type: type) ?Type { | 826 | pub fn userContext(self: FunctionContext, comptime Type: type) ?Type { |
| 827 | const Types = splitPtrTypes(Type); | 827 | const Types = splitPtrTypes(Type); |
| 828 | _ = Types; | ||
| 828 | 829 | ||
| 829 | if (c.sqlite3_user_data(self.ctx)) |value| { | 830 | if (c.sqlite3_user_data(self.ctx)) |value| { |
| 830 | return @ptrCast( | 831 | return @ptrCast(@alignCast(value)); |
| 831 | Types.PointerType, | ||
| 832 | @alignCast(@alignOf(Types.ValueType), value), | ||
| 833 | ); | ||
| 834 | } | 832 | } |
| 835 | return null; | 833 | return null; |
| 836 | } | 834 | } |
| @@ -839,10 +837,7 @@ pub const FunctionContext = struct { | |||
| 839 | const Types = splitPtrTypes(Type); | 837 | const Types = splitPtrTypes(Type); |
| 840 | 838 | ||
| 841 | if (c.sqlite3_aggregate_context(self.ctx, @sizeOf(Types.ValueType))) |value| { | 839 | if (c.sqlite3_aggregate_context(self.ctx, @sizeOf(Types.ValueType))) |value| { |
| 842 | return @ptrCast( | 840 | return @ptrCast(@alignCast(value)); |
| 843 | Types.PointerType, | ||
| 844 | @alignCast(@alignOf(Types.ValueType), value), | ||
| 845 | ); | ||
| 846 | } | 841 | } |
| 847 | return null; | 842 | return null; |
| 848 | } | 843 | } |
| @@ -1073,7 +1068,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1073 | 1068 | ||
| 1074 | if (@typeInfo(Type.BaseType) == .Int) { | 1069 | if (@typeInfo(Type.BaseType) == .Int) { |
| 1075 | const inner_value = try self.readField(Type.BaseType, options, 0); | 1070 | const inner_value = try self.readField(Type.BaseType, options, 0); |
| 1076 | return @enumFromInt(Type, @intCast(TI.tag_type, inner_value)); | 1071 | return @enumFromInt(@as(TI.tag_type, @intCast(inner_value))); |
| 1077 | } | 1072 | } |
| 1078 | 1073 | ||
| 1079 | @compileError("enum column " ++ @typeName(Type) ++ " must have a BaseType of either string or int"); | 1074 | @compileError("enum column " ++ @typeName(Type) ++ " must have a BaseType of either string or int"); |
| @@ -1157,7 +1152,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1157 | return std.meta.stringToEnum(Type, inner_value) orelse unreachable; | 1152 | return std.meta.stringToEnum(Type, inner_value) orelse unreachable; |
| 1158 | } | 1153 | } |
| 1159 | if (@typeInfo(Type.BaseType) == .Int) { | 1154 | if (@typeInfo(Type.BaseType) == .Int) { |
| 1160 | return @enumFromInt(Type, @intCast(TI.tag_type, inner_value)); | 1155 | return @enumFromInt(@as(TI.tag_type, @intCast(inner_value))); |
| 1161 | } | 1156 | } |
| 1162 | @compileError("enum column " ++ @typeName(Type) ++ " must have a BaseType of either string or int"); | 1157 | @compileError("enum column " ++ @typeName(Type) ++ " must have a BaseType of either string or int"); |
| 1163 | }, | 1158 | }, |
| @@ -1178,7 +1173,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1178 | // | 1173 | // |
| 1179 | // If the array is too small for the data an error will be returned. | 1174 | // If the array is too small for the data an error will be returned. |
| 1180 | fn readArray(self: *Self, comptime ArrayType: type, _i: usize) !ArrayType { | 1175 | fn readArray(self: *Self, comptime ArrayType: type, _i: usize) !ArrayType { |
| 1181 | const i = @intCast(c_int, _i); | 1176 | const i: c_int = @intCast(_i); |
| 1182 | const type_info = @typeInfo(ArrayType); | 1177 | const type_info = @typeInfo(ArrayType); |
| 1183 | 1178 | ||
| 1184 | var ret: ArrayType = undefined; | 1179 | var ret: ArrayType = undefined; |
| @@ -1186,7 +1181,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1186 | .Array => |arr| { | 1181 | .Array => |arr| { |
| 1187 | switch (arr.child) { | 1182 | switch (arr.child) { |
| 1188 | u8 => { | 1183 | u8 => { |
| 1189 | const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i)); | 1184 | const size: usize = @intCast(c.sqlite3_column_bytes(self.stmt, i)); |
| 1190 | 1185 | ||
| 1191 | if (arr.sentinel) |sentinel_ptr| { | 1186 | if (arr.sentinel) |sentinel_ptr| { |
| 1192 | // An array with a sentinel need to be as big as the data, + 1 byte for the sentinel. | 1187 | // An array with a sentinel need to be as big as the data, + 1 byte for the sentinel. |
| @@ -1195,7 +1190,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1195 | } | 1190 | } |
| 1196 | 1191 | ||
| 1197 | // Set the sentinel in the result at the correct position. | 1192 | // Set the sentinel in the result at the correct position. |
| 1198 | const sentinel = @ptrCast(*const arr.child, sentinel_ptr).*; | 1193 | const sentinel = @as(*const arr.child, @ptrCast(sentinel_ptr)).*; |
| 1199 | ret[size] = sentinel; | 1194 | ret[size] = sentinel; |
| 1200 | } else if (size != arr.len) { | 1195 | } else if (size != arr.len) { |
| 1201 | // An array without a sentinel must have the exact same size as the data because we can't | 1196 | // An array without a sentinel must have the exact same size as the data because we can't |
| @@ -1205,7 +1200,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1205 | 1200 | ||
| 1206 | const data = c.sqlite3_column_blob(self.stmt, i); | 1201 | const data = c.sqlite3_column_blob(self.stmt, i); |
| 1207 | if (data != null) { | 1202 | if (data != null) { |
| 1208 | const ptr = @ptrCast([*c]const u8, data)[0..size]; | 1203 | const ptr = @as([*c]const u8, @ptrCast(data))[0..size]; |
| 1209 | 1204 | ||
| 1210 | mem.copy(u8, ret[0..], ptr); | 1205 | mem.copy(u8, ret[0..], ptr); |
| 1211 | } | 1206 | } |
| @@ -1220,19 +1215,19 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1220 | 1215 | ||
| 1221 | // readInt reads a sqlite INTEGER column into an integer. | 1216 | // readInt reads a sqlite INTEGER column into an integer. |
| 1222 | fn readInt(self: *Self, comptime IntType: type, i: usize) error{Workaround}!IntType { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error | 1217 | fn readInt(self: *Self, comptime IntType: type, i: usize) error{Workaround}!IntType { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error |
| 1223 | const n = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); | 1218 | const n = c.sqlite3_column_int64(self.stmt, @intCast(i)); |
| 1224 | return @intCast(IntType, n); | 1219 | return @intCast(n); |
| 1225 | } | 1220 | } |
| 1226 | 1221 | ||
| 1227 | // readFloat reads a sqlite REAL column into a float. | 1222 | // readFloat reads a sqlite REAL column into a float. |
| 1228 | fn readFloat(self: *Self, comptime FloatType: type, i: usize) error{Workaround}!FloatType { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error | 1223 | fn readFloat(self: *Self, comptime FloatType: type, i: usize) error{Workaround}!FloatType { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error |
| 1229 | const d = c.sqlite3_column_double(self.stmt, @intCast(c_int, i)); | 1224 | const d = c.sqlite3_column_double(self.stmt, @intCast(i)); |
| 1230 | return @floatCast(FloatType, d); | 1225 | return @floatCast(d); |
| 1231 | } | 1226 | } |
| 1232 | 1227 | ||
| 1233 | // readFloat reads a sqlite INTEGER column into a bool (true is anything > 0, false is anything <= 0). | 1228 | // readFloat reads a sqlite INTEGER column into a bool (true is anything > 0, false is anything <= 0). |
| 1234 | fn readBool(self: *Self, i: usize) error{Workaround}!bool { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error | 1229 | fn readBool(self: *Self, i: usize) error{Workaround}!bool { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error |
| 1235 | const d = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); | 1230 | const d = c.sqlite3_column_int64(self.stmt, @intCast(i)); |
| 1236 | return d > 0; | 1231 | return d > 0; |
| 1237 | } | 1232 | } |
| 1238 | 1233 | ||
| @@ -1246,7 +1241,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1246 | switch (@typeInfo(SliceType)) { | 1241 | switch (@typeInfo(SliceType)) { |
| 1247 | .Pointer => |ptr_info| { | 1242 | .Pointer => |ptr_info| { |
| 1248 | if (ptr_info.sentinel) |sentinel_ptr| { | 1243 | if (ptr_info.sentinel) |sentinel_ptr| { |
| 1249 | const sentinel = @ptrCast(*const ptr_info.child, sentinel_ptr).*; | 1244 | const sentinel = @as(*const ptr_info.child, @ptrCast(sentinel_ptr)).*; |
| 1250 | 1245 | ||
| 1251 | const slice = try allocator.alloc(u8, data.len + 1); | 1246 | const slice = try allocator.alloc(u8, data.len + 1); |
| 1252 | mem.copy(u8, slice, data); | 1247 | mem.copy(u8, slice, data); |
| @@ -1272,7 +1267,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1272 | // | 1267 | // |
| 1273 | // The options must contain an `allocator` field which will be used to create a copy of the data. | 1268 | // The options must contain an `allocator` field which will be used to create a copy of the data. |
| 1274 | fn readBytes(self: *Self, comptime BytesType: type, allocator: mem.Allocator, _i: usize, comptime mode: ReadBytesMode) !BytesType { | 1269 | fn readBytes(self: *Self, comptime BytesType: type, allocator: mem.Allocator, _i: usize, comptime mode: ReadBytesMode) !BytesType { |
| 1275 | const i = @intCast(c_int, _i); | 1270 | const i: c_int = @intCast(_i); |
| 1276 | 1271 | ||
| 1277 | switch (mode) { | 1272 | switch (mode) { |
| 1278 | .Blob => { | 1273 | .Blob => { |
| @@ -1284,8 +1279,8 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1284 | }; | 1279 | }; |
| 1285 | } | 1280 | } |
| 1286 | 1281 | ||
| 1287 | const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i)); | 1282 | const size: usize = @intCast(c.sqlite3_column_bytes(self.stmt, i)); |
| 1288 | const ptr = @ptrCast([*c]const u8, data)[0..size]; | 1283 | const ptr = @as([*c]const u8, @ptrCast(data))[0..size]; |
| 1289 | 1284 | ||
| 1290 | if (BytesType == Blob) { | 1285 | if (BytesType == Blob) { |
| 1291 | return Blob{ .data = try allocator.dupe(u8, ptr) }; | 1286 | return Blob{ .data = try allocator.dupe(u8, ptr) }; |
| @@ -1301,8 +1296,8 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1301 | }; | 1296 | }; |
| 1302 | } | 1297 | } |
| 1303 | 1298 | ||
| 1304 | const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i)); | 1299 | const size: usize = @intCast(c.sqlite3_column_bytes(self.stmt, i)); |
| 1305 | const ptr = @ptrCast([*c]const u8, data)[0..size]; | 1300 | const ptr = @as([*c]const u8, @ptrCast(data))[0..size]; |
| 1306 | 1301 | ||
| 1307 | if (BytesType == Text) { | 1302 | if (BytesType == Text) { |
| 1308 | return Text{ .data = try allocator.dupe(u8, ptr) }; | 1303 | return Text{ .data = try allocator.dupe(u8, ptr) }; |
| @@ -1352,7 +1347,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1352 | switch (@typeInfo(OptionalType)) { | 1347 | switch (@typeInfo(OptionalType)) { |
| 1353 | .Optional => |opt| { | 1348 | .Optional => |opt| { |
| 1354 | // Easy way to know if the column represents a null value. | 1349 | // Easy way to know if the column represents a null value. |
| 1355 | const value = c.sqlite3_column_value(self.stmt, @intCast(c_int, _i)); | 1350 | const value = c.sqlite3_column_value(self.stmt, @intCast(_i)); |
| 1356 | const datatype = c.sqlite3_value_type(value); | 1351 | const datatype = c.sqlite3_value_type(value); |
| 1357 | 1352 | ||
| 1358 | if (datatype == c.SQLITE_NULL) { | 1353 | if (datatype == c.SQLITE_NULL) { |
| @@ -1445,7 +1440,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1445 | return std.meta.stringToEnum(FieldType, inner_value) orelse unreachable; | 1440 | return std.meta.stringToEnum(FieldType, inner_value) orelse unreachable; |
| 1446 | } | 1441 | } |
| 1447 | if (@typeInfo(FieldType.BaseType) == .Int) { | 1442 | if (@typeInfo(FieldType.BaseType) == .Int) { |
| 1448 | return @enumFromInt(FieldType, @intCast(TI.tag_type, inner_value)); | 1443 | return @enumFromInt(@as(TI.tag_type, @intCast(inner_value))); |
| 1449 | } | 1444 | } |
| 1450 | @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int"); | 1445 | @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int"); |
| 1451 | }, | 1446 | }, |
| @@ -1526,7 +1521,7 @@ pub const DynamicStatement = struct { | |||
| 1526 | const result = c.sqlite3_prepare_v3( | 1521 | const result = c.sqlite3_prepare_v3( |
| 1527 | db.db, | 1522 | db.db, |
| 1528 | query.ptr, | 1523 | query.ptr, |
| 1529 | @intCast(c_int, query.len), | 1524 | @intCast(query.len), |
| 1530 | flags, | 1525 | flags, |
| 1531 | &tmp, | 1526 | &tmp, |
| 1532 | options.sql_tail_ptr, | 1527 | options.sql_tail_ptr, |
| @@ -1588,11 +1583,11 @@ pub const DynamicStatement = struct { | |||
| 1588 | 1583 | ||
| 1589 | switch (FieldType) { | 1584 | switch (FieldType) { |
| 1590 | Text => { | 1585 | Text => { |
| 1591 | const result = c.sqlite3_bind_text(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null); | 1586 | const result = c.sqlite3_bind_text(self.stmt, column, field.data.ptr, @intCast(field.data.len), null); |
| 1592 | return convertResultToError(result); | 1587 | return convertResultToError(result); |
| 1593 | }, | 1588 | }, |
| 1594 | Blob => { | 1589 | Blob => { |
| 1595 | const result = c.sqlite3_bind_blob(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null); | 1590 | const result = c.sqlite3_bind_blob(self.stmt, column, field.data.ptr, @intCast(field.data.len), null); |
| 1596 | return convertResultToError(result); | 1591 | return convertResultToError(result); |
| 1597 | }, | 1592 | }, |
| 1598 | ZeroBlob => { | 1593 | ZeroBlob => { |
| @@ -1601,7 +1596,7 @@ pub const DynamicStatement = struct { | |||
| 1601 | }, | 1596 | }, |
| 1602 | else => switch (field_type_info) { | 1597 | else => switch (field_type_info) { |
| 1603 | .Int, .ComptimeInt => { | 1598 | .Int, .ComptimeInt => { |
| 1604 | const result = c.sqlite3_bind_int64(self.stmt, column, @intCast(c_longlong, field)); | 1599 | const result = c.sqlite3_bind_int64(self.stmt, column, @intCast(field)); |
| 1605 | return convertResultToError(result); | 1600 | return convertResultToError(result); |
| 1606 | }, | 1601 | }, |
| 1607 | .Float, .ComptimeFloat => { | 1602 | .Float, .ComptimeFloat => { |
| @@ -1619,7 +1614,7 @@ pub const DynamicStatement = struct { | |||
| 1619 | .Slice => switch (ptr.child) { | 1614 | .Slice => switch (ptr.child) { |
| 1620 | u8 => { | 1615 | u8 => { |
| 1621 | // NOTE(vincent): The slice must live until after the prepared statement is finaliuzed, therefore we use SQLITE_STATIC to avoid a copy | 1616 | // 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); | 1617 | const result = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(field.len), c.SQLITE_STATIC); |
| 1623 | return convertResultToError(result); | 1618 | return convertResultToError(result); |
| 1624 | }, | 1619 | }, |
| 1625 | else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)), | 1620 | else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)), |
| @@ -1631,7 +1626,7 @@ pub const DynamicStatement = struct { | |||
| 1631 | const data: []const u8 = field[0..field.len]; | 1626 | const data: []const u8 = field[0..field.len]; |
| 1632 | 1627 | ||
| 1633 | // NOTE(vincent): The array is temporary and must be copied, therefore we use SQLITE_TRANSIENT | 1628 | // 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); | 1629 | const result = c.sqlite3_bind_text(self.stmt, column, data.ptr, @intCast(data.len), c.SQLITE_TRANSIENT); |
| 1635 | return convertResultToError(result); | 1630 | return convertResultToError(result); |
| 1636 | }, | 1631 | }, |
| 1637 | else => @compileError("cannot bind field " ++ field_name ++ " of type array of " ++ @typeName(arr.child)), | 1632 | else => @compileError("cannot bind field " ++ field_name ++ " of type array of " ++ @typeName(arr.child)), |
| @@ -1738,7 +1733,7 @@ pub const DynamicStatement = struct { | |||
| 1738 | switch (PointerTypeInfo.size) { | 1733 | switch (PointerTypeInfo.size) { |
| 1739 | .Slice => { | 1734 | .Slice => { |
| 1740 | for (values, 0..) |value_to_bind, index| { | 1735 | for (values, 0..) |value_to_bind, index| { |
| 1741 | try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); | 1736 | try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(index), value_to_bind); |
| 1742 | } | 1737 | } |
| 1743 | }, | 1738 | }, |
| 1744 | else => @compileError("TODO support pointer size " ++ @tagName(PointerTypeInfo.size)), | 1739 | else => @compileError("TODO support pointer size " ++ @tagName(PointerTypeInfo.size)), |
| @@ -1746,7 +1741,7 @@ pub const DynamicStatement = struct { | |||
| 1746 | }, | 1741 | }, |
| 1747 | .Array => |ArrayTypeInfo| { | 1742 | .Array => |ArrayTypeInfo| { |
| 1748 | for (values, 0..) |value_to_bind, index| { | 1743 | for (values, 0..) |value_to_bind, index| { |
| 1749 | try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); | 1744 | try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(index), value_to_bind); |
| 1750 | } | 1745 | } |
| 1751 | }, | 1746 | }, |
| 1752 | else => @compileError("Unsupported type for values: " ++ @typeName(Type)), | 1747 | else => @compileError("Unsupported type for values: " ++ @typeName(Type)), |
| @@ -2541,7 +2536,7 @@ test "sqlite: read in an anonymous struct" { | |||
| 2541 | try testing.expectEqualStrings(exp.name, mem.sliceTo(&row.?.name_2, 0xAD)); | 2536 | try testing.expectEqualStrings(exp.name, mem.sliceTo(&row.?.name_2, 0xAD)); |
| 2542 | try testing.expectEqual(exp.age, row.?.age); | 2537 | try testing.expectEqual(exp.age, row.?.age); |
| 2543 | try testing.expect(row.?.is_id); | 2538 | try testing.expect(row.?.is_id); |
| 2544 | try testing.expectEqual(exp.weight, @floatCast(f32, row.?.weight)); | 2539 | try testing.expectEqual(exp.weight, @as(f32, @floatCast(row.?.weight))); |
| 2545 | } | 2540 | } |
| 2546 | 2541 | ||
| 2547 | test "sqlite: read in a Text struct" { | 2542 | test "sqlite: read in a Text struct" { |
| @@ -2621,7 +2616,7 @@ test "sqlite: read a single text value" { | |||
| 2621 | try testing.expectEqualStrings("Vincent", name.?); | 2616 | try testing.expectEqualStrings("Vincent", name.?); |
| 2622 | }, | 2617 | }, |
| 2623 | .Array => |arr| if (arr.sentinel) |sentinel_ptr| { | 2618 | .Array => |arr| if (arr.sentinel) |sentinel_ptr| { |
| 2624 | const sentinel = @ptrCast(*const arr.child, sentinel_ptr).*; | 2619 | const sentinel = @as(*const arr.child, @ptrCast(sentinel_ptr)).*; |
| 2625 | const res = mem.sliceTo(&name.?, sentinel); | 2620 | const res = mem.sliceTo(&name.?, sentinel); |
| 2626 | try testing.expectEqualStrings("Vincent", res); | 2621 | try testing.expectEqualStrings("Vincent", res); |
| 2627 | } else { | 2622 | } else { |
| @@ -2969,7 +2964,7 @@ test "sqlite: statement iterator" { | |||
| 2969 | var i: usize = 0; | 2964 | var i: usize = 0; |
| 2970 | while (i < 20) : (i += 1) { | 2965 | while (i < 20) : (i += 1) { |
| 2971 | const name = try std.fmt.allocPrint(allocator, "Vincent {d}", .{i}); | 2966 | const name = try std.fmt.allocPrint(allocator, "Vincent {d}", .{i}); |
| 2972 | const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(f32, i + 200), .favorite_color = .indigo }; | 2967 | const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(i + 200), .favorite_color = .indigo }; |
| 2973 | 2968 | ||
| 2974 | try expected_rows.append(user); | 2969 | try expected_rows.append(user); |
| 2975 | 2970 | ||
| @@ -3360,7 +3355,7 @@ test "sqlite: bind custom type" { | |||
| 3360 | var i: usize = 0; | 3355 | var i: usize = 0; |
| 3361 | while (i < 20) : (i += 1) { | 3356 | while (i < 20) : (i += 1) { |
| 3362 | var my_data: MyData = undefined; | 3357 | var my_data: MyData = undefined; |
| 3363 | @memset(&my_data.data, @intCast(u8, i)); | 3358 | @memset(&my_data.data, @as(u8, @intCast(i))); |
| 3364 | 3359 | ||
| 3365 | var arena = heap.ArenaAllocator.init(testing.allocator); | 3360 | var arena = heap.ArenaAllocator.init(testing.allocator); |
| 3366 | defer arena.deinit(); | 3361 | defer arena.deinit(); |
| @@ -3390,7 +3385,7 @@ test "sqlite: bind custom type" { | |||
| 3390 | 3385 | ||
| 3391 | for (rows, 0..) |row, i| { | 3386 | for (rows, 0..) |row, i| { |
| 3392 | var exp_data: MyData = undefined; | 3387 | var exp_data: MyData = undefined; |
| 3393 | @memset(&exp_data.data, @intCast(u8, i)); | 3388 | @memset(&exp_data.data, @as(u8, @intCast(i))); |
| 3394 | 3389 | ||
| 3395 | try testing.expectEqualSlices(u8, &exp_data.data, &row.data.data); | 3390 | try testing.expectEqualSlices(u8, &exp_data.data, &row.data.data); |
| 3396 | } | 3391 | } |
| @@ -3567,7 +3562,7 @@ test "sqlite: create scalar function" { | |||
| 3567 | "myInteger64", | 3562 | "myInteger64", |
| 3568 | struct { | 3563 | struct { |
| 3569 | fn run(input: i64) i64 { | 3564 | fn run(input: i64) i64 { |
| 3570 | return @intCast(i64, input) * 2; | 3565 | return @as(i64, @intCast(input)) * 2; |
| 3571 | } | 3566 | } |
| 3572 | }.run, | 3567 | }.run, |
| 3573 | .{}, | 3568 | .{}, |
| @@ -3693,7 +3688,7 @@ test "sqlite: create aggregate function with no aggregate context" { | |||
| 3693 | var db = try getTestDb(); | 3688 | var db = try getTestDb(); |
| 3694 | defer db.deinit(); | 3689 | defer db.deinit(); |
| 3695 | 3690 | ||
| 3696 | var rand = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp())); | 3691 | var rand = std.rand.DefaultPrng.init(@intCast(std.time.milliTimestamp())); |
| 3697 | 3692 | ||
| 3698 | // Create an aggregate function working with a MyContext | 3693 | // Create an aggregate function working with a MyContext |
| 3699 | 3694 | ||
| @@ -3754,7 +3749,7 @@ test "sqlite: create aggregate function with an aggregate context" { | |||
| 3754 | var db = try getTestDb(); | 3749 | var db = try getTestDb(); |
| 3755 | defer db.deinit(); | 3750 | defer db.deinit(); |
| 3756 | 3751 | ||
| 3757 | var rand = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp())); | 3752 | var rand = std.rand.DefaultPrng.init(@intCast(std.time.milliTimestamp())); |
| 3758 | 3753 | ||
| 3759 | try db.createAggregateFunction( | 3754 | try db.createAggregateFunction( |
| 3760 | "mySum", | 3755 | "mySum", |