This code would fail, because it contains multiple statements, separated by semicolons.
import db_postgres
let db = open("localhost", "postgres", "", "nim_test")
let schema = """
begin;
drop table if exists users;
create table users(
id serial not null,
name varchar(100) not null,
primary key (id)
);
commit;
"""
db.exec(sql(schema))
db.close()
Error:
Error: unhandled exception: ERROR: cannot insert multiple commands into a prepared statement
[DbError]
It seems that instead of executing it as SQL it tries to process it as prepared query, and fail, sources.
When prepared statement code commented out and replaced with plain execution it works, seems like a bug?
proc exec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
tags: [ReadDbEffect, WriteDbEffect].} =
## executes the query and raises EDB if not successful.
# var res = pqexecParams(db, dbFormat(query, args), 0, nil, nil,
# nil, nil, 0)
var res = pqexec(db, query.string)
if pqresultStatus(res) != PGRES_COMMAND_OK: dbError(db)
pqclear(res)