mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: fix null strings (#8497)
This commit is contained in:
parent
8bf3fe5d48
commit
969f19daf4
@ -29,6 +29,7 @@ fn test_orm_sqlite() {
|
||||
db.exec("insert into User (name, age) values ('Sam', 29)")
|
||||
db.exec("insert into User (name, age) values ('Peter', 31)")
|
||||
db.exec("insert into User (name, age, is_customer) values ('Kate', 30, 1)")
|
||||
|
||||
nr_all_users := sql db {
|
||||
select count from User
|
||||
}
|
||||
@ -213,6 +214,12 @@ fn test_orm_sqlite() {
|
||||
select from User order by age desc limit 1
|
||||
}
|
||||
assert updated_oldest.age == 31
|
||||
|
||||
db.exec('insert into User (name, age) values (NULL, 31)')
|
||||
null_user := sql db {
|
||||
select from User where id == 5
|
||||
}
|
||||
assert null_user.name == ''
|
||||
}
|
||||
|
||||
fn test_orm_pg() {
|
||||
|
@ -226,7 +226,11 @@ fn (mut g Gen) sql_select_expr(node ast.SqlExpr) {
|
||||
mut func := 'sqlite3_column_int'
|
||||
if field.typ == table.string_type {
|
||||
func = 'sqlite3_column_text'
|
||||
g.writeln('${tmp}.$field.name = tos_clone(${func}($g.sql_stmt_name, $i));')
|
||||
string_data := g.new_tmp_var()
|
||||
g.writeln('byteptr $string_data = ${func}($g.sql_stmt_name, $i);')
|
||||
g.writeln('if ($string_data != NULL) {')
|
||||
g.writeln('\t${tmp}.$field.name = tos_clone($string_data);')
|
||||
g.writeln('}')
|
||||
} else {
|
||||
g.writeln('${tmp}.$field.name = ${func}($g.sql_stmt_name, $i);')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user