mirror of
https://github.com/vlang/v.git
synced 2025-09-12 00:46:55 -04:00
parent
31ce668c7a
commit
ebeef84be9
@ -181,6 +181,7 @@ const skip_with_fsanitize_memory = [
|
|||||||
'vlib/v/tests/orm_array_field_test.v',
|
'vlib/v/tests/orm_array_field_test.v',
|
||||||
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
||||||
'vlib/v/tests/orm_create_several_tables_test.v',
|
'vlib/v/tests/orm_create_several_tables_test.v',
|
||||||
|
'vlib/v/tests/orm_update_test.v',
|
||||||
'vlib/vweb/tests/vweb_test.v',
|
'vlib/vweb/tests/vweb_test.v',
|
||||||
'vlib/vweb/csrf/csrf_test.v',
|
'vlib/vweb/csrf/csrf_test.v',
|
||||||
'vlib/net/http/request_test.v',
|
'vlib/net/http/request_test.v',
|
||||||
@ -204,6 +205,7 @@ const skip_with_fsanitize_address = [
|
|||||||
'vlib/v/tests/orm_sub_array_struct_test.v',
|
'vlib/v/tests/orm_sub_array_struct_test.v',
|
||||||
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
||||||
'vlib/v/tests/orm_create_several_tables_test.v',
|
'vlib/v/tests/orm_create_several_tables_test.v',
|
||||||
|
'vlib/v/tests/orm_update_test.v',
|
||||||
]
|
]
|
||||||
const skip_with_fsanitize_undefined = [
|
const skip_with_fsanitize_undefined = [
|
||||||
'do_not_remove',
|
'do_not_remove',
|
||||||
@ -215,6 +217,7 @@ const skip_with_fsanitize_undefined = [
|
|||||||
'vlib/v/tests/orm_sub_array_struct_test.v',
|
'vlib/v/tests/orm_sub_array_struct_test.v',
|
||||||
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
||||||
'vlib/v/tests/orm_create_several_tables_test.v',
|
'vlib/v/tests/orm_create_several_tables_test.v',
|
||||||
|
'vlib/v/tests/orm_update_test.v',
|
||||||
'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.c.v', // fails compilation with: undefined reference to vtable for __cxxabiv1::__function_type_info'
|
'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.c.v', // fails compilation with: undefined reference to vtable for __cxxabiv1::__function_type_info'
|
||||||
]
|
]
|
||||||
const skip_with_werror = [
|
const skip_with_werror = [
|
||||||
@ -274,6 +277,7 @@ const skip_on_ubuntu_musl = [
|
|||||||
'vlib/v/tests/orm_array_field_test.v',
|
'vlib/v/tests/orm_array_field_test.v',
|
||||||
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
|
||||||
'vlib/v/tests/orm_create_several_tables_test.v',
|
'vlib/v/tests/orm_create_several_tables_test.v',
|
||||||
|
'vlib/v/tests/orm_update_test.v',
|
||||||
'vlib/v/tests/sql_statement_inside_fn_call_test.v',
|
'vlib/v/tests/sql_statement_inside_fn_call_test.v',
|
||||||
'vlib/clipboard/clipboard_test.v',
|
'vlib/clipboard/clipboard_test.v',
|
||||||
'vlib/vweb/tests/vweb_test.v',
|
'vlib/vweb/tests/vweb_test.v',
|
||||||
|
@ -413,7 +413,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
|||||||
ctyp = 'time__Time'
|
ctyp = 'time__Time'
|
||||||
typ = 'time'
|
typ = 'time'
|
||||||
} else if sym.kind == .enum {
|
} else if sym.kind == .enum {
|
||||||
typ = 'i64'
|
typ = g.table.sym(g.table.final_type(field.typ)).cname
|
||||||
}
|
}
|
||||||
var := '${node.object_var}${member_access_type}${c_name(field.name)}'
|
var := '${node.object_var}${member_access_type}${c_name(field.name)}'
|
||||||
if field.typ.has_flag(.option) {
|
if field.typ.has_flag(.option) {
|
||||||
@ -604,6 +604,8 @@ fn (mut g Gen) write_orm_primitive(t ast.Type, expr ast.Expr) {
|
|||||||
|
|
||||||
if t.has_flag(.option) {
|
if t.has_flag(.option) {
|
||||||
typ = 'option_${typ}'
|
typ = 'option_${typ}'
|
||||||
|
} else if g.table.final_sym(t).kind == .enum {
|
||||||
|
typ = g.table.sym(g.table.final_type(t)).cname
|
||||||
}
|
}
|
||||||
g.write('orm__${typ}_to_primitive(')
|
g.write('orm__${typ}_to_primitive(')
|
||||||
if expr is ast.CallExpr {
|
if expr is ast.CallExpr {
|
||||||
|
41
vlib/v/tests/orm_update_test.v
Normal file
41
vlib/v/tests/orm_update_test.v
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import db.sqlite
|
||||||
|
|
||||||
|
struct Person {
|
||||||
|
name string
|
||||||
|
height Height
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Height as u8 {
|
||||||
|
tall
|
||||||
|
small
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
db := sqlite.connect(':memory:')!
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
create table Person
|
||||||
|
}!
|
||||||
|
|
||||||
|
a := Person{'A', Height.small}
|
||||||
|
b := Person{'A', Height.tall}
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
insert a into Person
|
||||||
|
}!
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
insert b into Person
|
||||||
|
}!
|
||||||
|
|
||||||
|
new_height := Height.small
|
||||||
|
sql db {
|
||||||
|
update Person set height = new_height where height == Height.tall
|
||||||
|
}!
|
||||||
|
|
||||||
|
rows := sql db {
|
||||||
|
select from Person where height == Height.small
|
||||||
|
}!
|
||||||
|
|
||||||
|
assert rows.len == 2
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user