Skip to content

Commit 5d37dd1

Browse files
authored
cgen: fix orm shared conn on sql expr (fixes #26479) (#26610)
1 parent 1d6c465 commit 5d37dd1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎vlib/v/gen/c/orm.v‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn (mut g Gen) sql_stmt_line(stmt_line ast.SqlStmtLine, connection_var_name stri
153153
fn (mut g Gen) write_orm_connection_init(connection_var_name string, db_expr &ast.Expr) {
154154
db_expr_type := g.get_db_expr_type(db_expr) or { verror('ORM: unknown db type for ${db_expr}') }
155155

156-
mut db_ctype_name := g.styp(db_expr_type)
156+
mut db_ctype_name := g.styp(db_expr_type.clear_flag(.shared_f))
157157
is_pointer := db_ctype_name.ends_with('*')
158158
reference_sign := if is_pointer { '' } else { '&' }
159159
db_ctype_name = db_ctype_name.trim_right('*')
@@ -166,7 +166,13 @@ fn (mut g Gen) write_orm_connection_init(connection_var_name string, db_expr &as
166166
g.writeln(';')
167167
} else {
168168
g.write('(orm__Connection){._${db_ctype_name} = ${reference_sign}')
169+
if db_expr_type.has_flag(.shared_f) {
170+
g.write('&')
171+
}
169172
g.expr(db_expr)
173+
if db_expr_type.has_flag(.shared_f) {
174+
g.write('->val')
175+
}
170176
g.writeln(', ._typ = _orm__Connection_${db_ctype_name}_index};')
171177
}
172178
}

0 commit comments

Comments
 (0)