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

orm: don't panic for a psql query with no results. (#10511)

This commit is contained in:
Ryan Roden-Corrent 2021-06-19 02:10:49 -04:00 committed by GitHub
parent 22214c73e3
commit 6171e12f9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -994,6 +994,7 @@ fn (mut g Gen) psql_select_expr(node ast.SqlExpr, sub bool, line string, typ Sql
g.writeln('};')
}
fields := g.new_tmp_var()
g.writeln('if (${rows}.len > 0) {')
g.writeln('Array_string $fields = (*(pg__Row*) array_get($rows, $tmp_i)).vals;')
fld := g.new_tmp_var()
g.writeln('string $fld;')
@ -1050,6 +1051,7 @@ fn (mut g Gen) psql_select_expr(node ast.SqlExpr, sub bool, line string, typ Sql
g.writeln('\t array_push((array*)&${tmp}_array, _MOV(($elem_type_str[]) { $tmp }));\n')
g.writeln('}')
}
g.writeln('}')
g.writeln('string_free(&$g.sql_stmt_name);')
if node.is_array {
g.writeln('$cur_line ${tmp}_array; ')