cgen: fix static var name used in sqlite orm generation, close #9725 (#9745)

pull/9756/head
Louis Schmieder 2021-04-15 19:57:03 +02:00 committed by GitHub
parent db908e507f
commit 60bc280ad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -150,9 +150,10 @@ fn (mut g Gen) sqlite3_stmt(node ast.SqlStmt, typ SqlType) {
g.sql_stmt_name = tmp_sql_stmt_name
g.sql_table_name = tmp_sql_table_name
// get last inserted id
g.writeln('Array_sqlite__Row rows = sqlite__DB_exec($db_name, _SLIT("SELECT last_insert_rowid()")).arg0;')
res := g.new_tmp_var()
g.writeln('Array_sqlite__Row $res = sqlite__DB_exec($db_name, _SLIT("SELECT last_insert_rowid()")).arg0;')
id_name := g.new_tmp_var()
g.writeln('int $id_name = string_int((*(string*)array_get((*(sqlite__Row*)array_get(rows, 0)).vals, 0)));')
g.writeln('int $id_name = string_int((*(string*)array_get((*(sqlite__Row*)array_get($res, 0)).vals, 0)));')
g.writeln('sqlite3_bind_int($g.sql_stmt_name, ${i + 0} , $id_name); // id')
} else {
g.writeln('sqlite3_bind_int($g.sql_stmt_name, ${i + 0} , $x); // stmt')