-
An db, err := sql.Open("sqlite3", "data.db")
// works fine
_, err = db.Exec(`
drop table if exists t1;
drop table if exists t2;
create table t1(id integer primary key, name1 text);
create table t2(id integer primary key, name2 text);
`)
// fails with error: sqlite3: multiple statements
args := []any{"alice", "alice"}
_, err = db.Exec(`
insert into t1(name1) values(?);
insert into t2(name2) values(?);
`, args...) This behavior is not consistent with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I wouldn't consider this a bug. I actually believe it's a misfeature of other drivers. I don't see how this can be correctly implemented in the face of numbered ( The problem is that SQLite doesn't allow to bind parameters to To see what I mean, consider this example: _, err = db.Exec(`
insert into t1(name1) values(?, ?3);
insert into t2(name2) values(?, ?1);
`, 1, 2, 3, 4) SQLite would see But for the next statement, The only sane solution I would see to this (and still accept multiple parametrized statements), would be to completely reject numbered ( Still it's a lot of complication, for a feature that brings little benefits, and where other drivers offer confusing and inconsistent behaviour. |
Beta Was this translation helpful? Give feedback.
I wouldn't consider this a bug. I actually believe it's a misfeature of other drivers.
I don't see how this can be correctly implemented in the face of numbered (
?NNN
) parameters, and especially numbered (?NNN
) and positional (?
) parameters mixed together.The problem is that SQLite doesn't allow to bind parameters to
sqlite3_exec
, andsqlite3_prepare_v3
does not accept multiple statements. So, suddenly, which parameters go to which statement is up to interpretation, and IMO there is no correct answer.To see what I mean, consider this example:
SQLite would see
insert into t1(name…