Commit 2e131839 authored by gwenn's avatar gwenn

Improve Conn#exec and Conn#Close error/log message.

parent 7e10f97b
......@@ -34,6 +34,7 @@ func (d *Driver) Open(name string) (driver.Conn, error) {
// PRAGMA schema_version may be used to detect when the database schema is altered
func (c *connImpl) Exec(query string, args []driver.Value) (driver.Result, error) {
// http://code.google.com/p/go-wiki/wiki/InterfaceSlice
tmp := make([]interface{}, len(args))
for i, arg := range args {
tmp[i] = arg
......
......@@ -440,9 +440,16 @@ func (c *Conn) Rollback() error {
}
func (c *Conn) exec(cmd string) error {
cmdstr := C.CString(cmd)
defer C.free(unsafe.Pointer(cmdstr))
return c.error(C.sqlite3_exec(c.db, cmdstr, nil, nil, nil))
s, err := c.Prepare(cmd)
if err != nil {
return err
}
defer s.Finalize()
rv := C.sqlite3_step(s.stmt)
if Errno(rv) != Done {
return s.error(rv)
}
return nil
}
// Close a database connection and any dangling statements.
......@@ -458,9 +465,9 @@ func (c *Conn) Close() error {
stmt := C.sqlite3_next_stmt(c.db, nil)
for stmt != nil {
if C.sqlite3_stmt_busy(stmt) != 0 {
Log(C.SQLITE_MISUSE, "Dangling statement (not reset)")
Log(C.SQLITE_MISUSE, "Dangling statement (not reset): \""+C.GoString(C.sqlite3_sql(stmt))+"\"")
} else {
Log(C.SQLITE_MISUSE, "Dangling statement (not finalize)")
Log(C.SQLITE_MISUSE, "Dangling statement (not finalize): \""+C.GoString(C.sqlite3_sql(stmt))+"\"")
}
C.sqlite3_finalize(stmt)
stmt = C.sqlite3_next_stmt(c.db, stmt)
......
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