mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
orm.pg: fix f32 and f64 endianness (#20412)
This commit is contained in:
parent
3d8425dafd
commit
1303c244e2
5 changed files with 82 additions and 2 deletions
|
@ -143,13 +143,15 @@ fn pg_stmt_match(mut types []u32, mut vals []&char, mut lens []int, mut formats
|
|||
}
|
||||
f32 {
|
||||
types << u32(Oid.t_float4)
|
||||
vals << &char(&data)
|
||||
num := conv.htonf32(f32(data))
|
||||
vals << &char(&num)
|
||||
lens << int(sizeof(f32))
|
||||
formats << 1
|
||||
}
|
||||
f64 {
|
||||
types << u32(Oid.t_float8)
|
||||
vals << &char(&data)
|
||||
num := conv.htonf64(f64(data))
|
||||
vals << &char(&num)
|
||||
lens << int(sizeof(f64))
|
||||
formats << 1
|
||||
}
|
||||
|
|
39
vlib/db/pg/pg_double_test.v
Normal file
39
vlib/db/pg/pg_double_test.v
Normal file
|
@ -0,0 +1,39 @@
|
|||
module main
|
||||
|
||||
import db.pg
|
||||
|
||||
@[table: 'demo']
|
||||
struct Demo {
|
||||
id int @[primary; sql: serial]
|
||||
number f64
|
||||
number2 f32
|
||||
}
|
||||
|
||||
fn test_float_field() {
|
||||
conn := 'host=localhost user=test password=test' // insert own connection string
|
||||
db := pg.connect_with_conninfo(conn)!
|
||||
defer {
|
||||
db.close()
|
||||
}
|
||||
|
||||
sql db {
|
||||
create table Demo
|
||||
}!
|
||||
|
||||
demo := Demo{0, 9.58815, 9.58815}
|
||||
sql db {
|
||||
insert demo into Demo
|
||||
}!
|
||||
rows := sql db {
|
||||
select from Demo
|
||||
}!
|
||||
|
||||
assert rows[0].number == 9.58815
|
||||
assert rows[0].number2 == 9.58815
|
||||
|
||||
sql db {
|
||||
drop table Demo
|
||||
}!
|
||||
|
||||
println(rows)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue