Commit 0b0ed9e5 authored by gwenn's avatar gwenn

Improve Conn.Exec.

parent e67326dc
......@@ -322,21 +322,23 @@ func (c *Conn) Exec(cmd string, args ...interface{}) error {
cmd = s.tail
continue
}
err = s.Exec(args...)
var subargs []interface{}
count := s.BindParameterCount()
if len(s.tail) > 0 && len(args) >= count {
subargs = args[:count]
args = args[count:]
} else {
subargs = args
}
err = s.Exec(subargs...)
if err != nil {
s.finalize()
return err
}
if len(s.tail) > 0 {
if len(args) > 0 {
s.finalize()
return c.specificError("cannot execute multiple statements when args are specified: %q", cmd)
}
}
cmd = s.tail
if err = s.finalize(); err != nil {
return err
}
cmd = s.tail
}
return nil
}
......
......@@ -247,6 +247,16 @@ func TestExecMisuse(t *testing.T) {
//println(err.Error())
}
func TestExecTwice(t *testing.T) {
db := open(t)
defer checkClose(db, t)
createTable(db, t)
err := db.Exec("INSERT INTO test VALUES (?, ?, ?, ?); INSERT INTO test VALUES (?, ?, ?, ?)",
0, 273.1, 1, "test",
1, 2257, 2, nil)
checkNoError(t, err, "Exec error: %s")
}
func TestTransaction(t *testing.T) {
db := open(t)
defer checkClose(db, t)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment