Skip to content

Commit

Permalink
cgen: improve diagnostic information for ORM queries with invalid types
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Mar 21, 2024
1 parent 39eef1d commit 9d4ec7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/gen/c/cgen.v
Expand Up @@ -198,7 +198,8 @@ mut:
sql_fkey string
sql_parent_id string
sql_side SqlExprSide // left or right, to distinguish idents in `name == name`
strs_to_free0 []string // strings.Builder
sql_last_stmt_out_len int
strs_to_free0 []string // strings.Builder
// strs_to_free []string // strings.Builder
// tmp_arg_vars_to_free []string
// autofree_pregen map[string]string
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/gen/c/orm.v
Expand Up @@ -93,6 +93,7 @@ fn (mut g Gen) sql_stmt(node ast.SqlStmt) {
// as well as inserting and updating objects.
// It is part of a multi-line query. For example, `create table User`
fn (mut g Gen) sql_stmt_line(stmt_line ast.SqlStmtLine, connection_var_name string, or_expr ast.OrExpr) {
g.sql_last_stmt_out_len = g.out.len
mut node := stmt_line
table_name := g.get_table_name_by_struct_type(node.table_expr.typ)
result_var_name := g.new_tmp_var()
Expand Down Expand Up @@ -554,6 +555,9 @@ fn (mut g Gen) write_orm_expr_to_primitive(expr ast.Expr) {
// write_orm_primitive writes C code for casting expressions into a primitive type,
// which will be used in low-level database libs.
fn (mut g Gen) write_orm_primitive(t ast.Type, expr ast.Expr) {
if t == 0 {
verror('${g.file.path}:${expr.pos().line_nr + 1}: ORM: unknown type t == 0\nexpr: ${expr}\nlast SQL stmt:\n${g.out.after(g.sql_last_stmt_out_len)}')
}
mut sym := g.table.sym(t)
mut typ := sym.cname
if typ == 'orm__Primitive' {
Expand Down

0 comments on commit 9d4ec7b

Please sign in to comment.