Skip to content

Commit

Permalink
db.sqlite: fix exec_param_many bug (#21008)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonmowry committed Mar 13, 2024
1 parent b276aac commit 8ec990e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/db/sqlite/sqlite.c.v
Expand Up @@ -315,6 +315,9 @@ pub fn (db &DB) exec_param_many(query string, params []string) ![]Row {
for {
res = C.sqlite3_step(stmt)
if res != sqlite.sqlite_row {
if rows.len == 0 && is_error(res) {
return db.error_message(res, query)
}
break
}
mut row := Row{}
Expand Down
19 changes: 19 additions & 0 deletions vlib/db/sqlite/sqlite_test.v
Expand Up @@ -95,3 +95,22 @@ fn test_alias_db() {
create_host(sqlite.connect(':memory:')!)!
assert true
}

fn test_exec_param_many() {
$if !linux {
return
}
mut db := sqlite.connect(':memory:') or { panic(err) }
assert db.is_open
db.exec('drop table if exists users')!
db.exec("create table users (id integer primary key, name text default '' unique);")!
db.exec("insert into users (name) values ('Sam')")!
db.exec_param_many('insert into users (id, name) values (?, ?)', [
'60',
'Sam',
]) or {
assert err.code() == 19 // constraint failure
return
}
assert false
}

0 comments on commit 8ec990e

Please sign in to comment.