1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix error for sql statement inside fn call (fix #13330) (#13346)

This commit is contained in:
yuyi 2022-02-03 00:05:31 +08:00 committed by GitHub
parent 9344c27021
commit be1e40dac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -45,6 +45,7 @@ const (
'vlib/sqlite/sqlite_orm_test.v',
'vlib/v/tests/orm_sub_struct_test.v',
'vlib/v/tests/orm_sub_array_struct_test.v',
'vlib/v/tests/sql_statement_inside_fn_call_test.v',
'vlib/vweb/tests/vweb_test.v',
'vlib/vweb/request_test.v',
'vlib/net/http/request_test.v',
@ -83,6 +84,7 @@ const (
'vlib/orm/orm_test.v',
'vlib/v/tests/orm_sub_struct_test.v',
'vlib/v/tests/orm_sub_array_struct_test.v',
'vlib/v/tests/sql_statement_inside_fn_call_test.v',
'vlib/clipboard/clipboard_test.v',
'vlib/vweb/tests/vweb_test.v',
'vlib/vweb/request_test.v',

View File

@ -759,7 +759,9 @@ fn (mut g Gen) sql_select(node ast.SqlExpr, expr string, left string) {
if node.is_array {
g.write('_array')
}
g.writeln(';')
if !g.inside_call {
g.writeln(';')
}
}
}

View File

@ -0,0 +1,24 @@
import sqlite
struct Movie {
id int [primary]
name string
}
fn x(m Movie) int {
return m.id
}
fn test_sql_statement_inside_fn_call() {
db := sqlite.connect(':memory:') or { panic('failed') }
sql db {
create table Movie
}
m := Movie{1, 'Maria'}
sql db {
insert m into Movie
}
dump(x(sql db {
select from Movie where id == 1
}))
}