Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orm: fix update stmt with enum value #23037

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
felipensp committed Dec 2, 2024
commit 6cc027aa10672f842d1ac6740e4690c7517a3dab
4 changes: 2 additions & 2 deletions vlib/v/gen/c/orm.v
Original file line number Diff line number Diff line change
@@ -413,7 +413,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
ctyp = 'time__Time'
typ = 'time'
} 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)}'
if field.typ.has_flag(.option) {
@@ -605,7 +605,7 @@ fn (mut g Gen) write_orm_primitive(t ast.Type, expr ast.Expr) {
if t.has_flag(.option) {
typ = 'option_${typ}'
} else if g.table.final_sym(t).kind == .enum {
typ = 'i64'
typ = g.table.sym(g.table.final_type(t)).cname
}
g.write('orm__${typ}_to_primitive(')
if expr is ast.CallExpr {
41 changes: 41 additions & 0 deletions vlib/v/tests/orm_update_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import db.sqlite

struct Person {
name string
height Height
}

enum Height {
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