mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
parent
124927ba96
commit
7078a2e185
@ -167,6 +167,7 @@ const skip_with_fsanitize_memory = [
|
||||
'vlib/orm/orm_option_time_test.v',
|
||||
'vlib/orm/orm_order_by_custom_field_test.v',
|
||||
'vlib/orm/orm_serial_attribute_test.v',
|
||||
'vlib/orm/orm_option_subselect_test.v',
|
||||
'vlib/db/sqlite/sqlite_test.v',
|
||||
'vlib/db/sqlite/sqlite_orm_test.v',
|
||||
'vlib/db/sqlite/sqlite_comptime_field_test.v',
|
||||
@ -272,6 +273,7 @@ const skip_on_ubuntu_musl = [
|
||||
'vlib/orm/orm_option_time_test.v',
|
||||
'vlib/orm/orm_order_by_custom_field_test.v',
|
||||
'vlib/orm/orm_serial_attribute_test.v',
|
||||
'vlib/orm/orm_option_subselect_test.v',
|
||||
'vlib/v/tests/orm_enum_test.v',
|
||||
'vlib/v/tests/orm_sub_struct_test.v',
|
||||
'vlib/v/tests/orm_sub_array_struct_test.v',
|
||||
|
49
vlib/orm/orm_option_subselect_test.v
Normal file
49
vlib/orm/orm_option_subselect_test.v
Normal file
@ -0,0 +1,49 @@
|
||||
import db.sqlite
|
||||
|
||||
fn test_main() {
|
||||
db := sqlite.connect(':memory:')!
|
||||
|
||||
sql db {
|
||||
create table Commit
|
||||
create table Measurement
|
||||
}!
|
||||
|
||||
c := Commit{
|
||||
commit_hash: 'hash'
|
||||
}
|
||||
sql db {
|
||||
insert c into Commit
|
||||
}!
|
||||
|
||||
c2 := sql db {
|
||||
select from Commit
|
||||
}!
|
||||
assert c2[0].v_self_default == none
|
||||
|
||||
c3 := Commit{
|
||||
commit_hash: 'hash1'
|
||||
v_self_default: Measurement{
|
||||
id: 123
|
||||
}
|
||||
}
|
||||
sql db {
|
||||
insert c3 into Commit
|
||||
}!
|
||||
|
||||
c4 := sql db {
|
||||
select from Commit
|
||||
}!
|
||||
assert c4[0].v_self_default == none
|
||||
assert c4[1].v_self_default != none
|
||||
}
|
||||
|
||||
@[table: 'commits']
|
||||
struct Commit {
|
||||
commit_hash string @[primary]
|
||||
v_self_default ?Measurement
|
||||
}
|
||||
|
||||
@[table: 'measurements']
|
||||
struct Measurement {
|
||||
id int @[primary; serial]
|
||||
}
|
@ -1071,7 +1071,6 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
||||
sub_result_c_typ := g.styp(sub.typ)
|
||||
g.writeln('${sub_result_c_typ} ${sub_result_var};')
|
||||
g.write_orm_select(sub, connection_var_name, sub_result_var)
|
||||
|
||||
if field.typ.has_flag(.option) {
|
||||
unwrapped_field_c_typ := g.styp(field.typ.clear_flag(.option))
|
||||
g.writeln('if (!${sub_result_var}.is_error)')
|
||||
@ -1172,6 +1171,10 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
||||
}
|
||||
|
||||
g.indent--
|
||||
if !node.is_array {
|
||||
g.writeln('} else {')
|
||||
g.writeln('\t${result_var}.is_error = true;')
|
||||
}
|
||||
g.writeln('}')
|
||||
|
||||
if node.is_array {
|
||||
|
Loading…
x
Reference in New Issue
Block a user