Skip to content

Commit ac2e7d7

Browse files
authored
db.sqlite: fix orm f32 field retrieval for sqlite (fix #25583) (#25592)
1 parent 32ad8de commit ac2e7d7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

cmd/tools/vtest-self.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ const skip_with_fsanitize_memory = [
162162
'vlib/db/sqlite/sqlite_comptime_field_test.v',
163163
'vlib/db/sqlite/parent_child_test.v',
164164
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
165+
'vlib/db/sqlite/sqlite_f32_test.v',
165166
'vlib/v/tests/orm_enum_test.v',
166167
'vlib/v/tests/orm_sub_struct_test.v',
167168
'vlib/v/tests/orm_sub_array_struct_test.v',
@@ -225,6 +226,7 @@ const skip_on_ubuntu_musl = [
225226
'vlib/db/sqlite/sqlite_comptime_field_test.v',
226227
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
227228
'vlib/db/sqlite/parent_child_test.v',
229+
'vlib/db/sqlite/sqlite_f32_test.v',
228230
'vlib/orm/orm_test.v',
229231
'vlib/orm/orm_sql_or_blocks_test.v',
230232
'vlib/orm/orm_create_and_drop_test.v',

vlib/db/sqlite/orm.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ fn (stmt Stmt) sqlite_select_column(idx int, typ int) !orm.Primitive {
167167
return stmt.get_int(idx) or { return orm.Null{} }
168168
} else if typ in orm.num64 {
169169
return stmt.get_i64(idx) or { return orm.Null{} }
170-
} else if typ in orm.float {
170+
} else if typ == typeof[f32]().idx {
171+
return f32(stmt.get_f64(idx) or { return orm.Null{} })
172+
} else if typ == typeof[f64]().idx {
171173
return stmt.get_f64(idx) or { return orm.Null{} }
172174
} else if typ == orm.type_string {
173175
if v := stmt.get_text(idx) {

vlib/db/sqlite/sqlite_f32_test.v

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// vtest build: present_sqlite3? && !sanitize-memory-clang
2+
import db.sqlite
3+
4+
struct Test {
5+
value f32
6+
value2 f64
7+
}
8+
9+
fn test_main() {
10+
conn := sqlite.connect(':memory:')!
11+
12+
data := Test{32.32, 64.64}
13+
14+
sql conn {
15+
create table Test
16+
insert data into Test
17+
}!
18+
19+
s := sql conn {
20+
select from Test
21+
}!
22+
23+
assert s[0].value == 32.32
24+
assert s[0].value2 == 64.64
25+
}

0 commit comments

Comments
 (0)