From 3f20cb1697bc033aa1eca5d9f0225814e8696006 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 9 Sep 2013 10:56:45 +0900 Subject: [PATCH] Implements Queryer --- sqlite3.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index d645af1..1a93298 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -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))