Implements Queryer

This commit is contained in:
mattn 2013-09-09 10:56:45 +09:00
parent 132e6e9898
commit 3f20cb1697
1 changed files with 24 additions and 1 deletions

View File

@ -137,7 +137,6 @@ func (c *SQLiteConn) AutoCommit() bool {
// Implements Execer
func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
for {
println(query)
ds, err := c.Prepare(query)
if err != nil {
return nil, err
@ -158,6 +157,30 @@ func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, err
}
}
// Implements Queryer
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
for {
ds, err := c.Prepare(query)
if err != nil {
return nil, err
}
s := ds.(*SQLiteStmt)
na := s.NumInput()
rows, err := s.Query(args[:na])
args = args[na:]
s.Close()
if err != nil {
return nil, err
}
if s.t == "" {
return rows, nil
}
rows.Close()
s.Close()
query = s.t
}
}
func (c *SQLiteConn) exec(cmd string) error {
pcmd := C.CString(cmd)
defer C.free(unsafe.Pointer(pcmd))