Disable Execer/Queryer until database/sql/driver implement QueryRow: #82

This commit is contained in:
mattn
2013-09-12 10:46:35 +09:00
parent 1c16dbe609
commit 1ca536cf83
2 changed files with 126 additions and 122 deletions

View File

@@ -134,65 +134,67 @@ func (c *SQLiteConn) AutoCommit() bool {
return int(C.sqlite3_get_autocommit(c.db)) != 0
}
// Implements Execer
func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
tx, err := c.Begin()
if err != nil {
return nil, err
}
for {
s, err := c.Prepare(query)
if err != nil {
tx.Rollback()
return nil, err
}
na := s.NumInput()
res, err := s.Exec(args[:na])
if err != nil && err != driver.ErrSkip {
tx.Rollback()
s.Close()
return nil, err
}
args = args[na:]
tail := s.(*SQLiteStmt).t
if tail == "" {
tx.Commit()
return res, nil
}
s.Close()
query = tail
}
}
// Implements Queryer
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
tx, err := c.Begin()
if err != nil {
return nil, err
}
for {
s, err := c.Prepare(query)
if err != nil {
tx.Rollback()
return nil, err
}
na := s.NumInput()
rows, err := s.Query(args[:na])
if err != nil && err != driver.ErrSkip {
tx.Rollback()
s.Close()
return nil, err
}
args = args[na:]
tail := s.(*SQLiteStmt).t
if tail == "" {
tx.Commit()
return rows, nil
}
s.Close()
query = tail
}
}
// TODO: Execer & Queryer currently disabled
// https://github.com/mattn/go-sqlite3/issues/82
//// Implements Execer
//func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
// tx, err := c.Begin()
// if err != nil {
// return nil, err
// }
// for {
// s, err := c.Prepare(query)
// if err != nil {
// tx.Rollback()
// return nil, err
// }
// na := s.NumInput()
// res, err := s.Exec(args[:na])
// if err != nil && err != driver.ErrSkip {
// tx.Rollback()
// s.Close()
// return nil, err
// }
// args = args[na:]
// tail := s.(*SQLiteStmt).t
// if tail == "" {
// tx.Commit()
// return res, nil
// }
// s.Close()
// query = tail
// }
//}
//
//// Implements Queryer
//func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
// tx, err := c.Begin()
// if err != nil {
// return nil, err
// }
// for {
// s, err := c.Prepare(query)
// if err != nil {
// tx.Rollback()
// return nil, err
// }
// na := s.NumInput()
// rows, err := s.Query(args[:na])
// if err != nil && err != driver.ErrSkip {
// tx.Rollback()
// s.Close()
// return nil, err
// }
// args = args[na:]
// tail := s.(*SQLiteStmt).t
// if tail == "" {
// tx.Commit()
// return rows, nil
// }
// s.Close()
// query = tail
// }
//}
func (c *SQLiteConn) exec(cmd string) error {
pcmd := C.CString(cmd)