Commit ca2fb674 authored by gwenn's avatar gwenn

Add Stmt#SelectOneRow method.

parent 30746961
...@@ -461,6 +461,7 @@ func (c *Conn) Close() error { ...@@ -461,6 +461,7 @@ func (c *Conn) Close() error {
rv := C.sqlite3_close(c.db) rv := C.sqlite3_close(c.db)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
Log(int(rv), "error while closing Conn")
return c.error(rv) return c.error(rv)
} }
c.db = nil c.db = nil
......
...@@ -78,7 +78,7 @@ type Stmt struct { ...@@ -78,7 +78,7 @@ type Stmt struct {
params map[string]int // cached parameter index by name params map[string]int // cached parameter index by name
// Enable type check in Scan methods (default true) // Enable type check in Scan methods (default true)
CheckTypeMismatch bool CheckTypeMismatch bool
// Tell if the stmt should be cached (default false) // Tell if the stmt should be cached (default true)
Cacheable bool Cacheable bool
} }
...@@ -205,6 +205,17 @@ func (s *Stmt) Select(rowCallbackHandler func(s *Stmt) error, args ...interface{ ...@@ -205,6 +205,17 @@ func (s *Stmt) Select(rowCallbackHandler func(s *Stmt) error, args ...interface{
return nil return nil
} }
// Args are for scanning (not binding).
// Returns false if there is no matching row.
func (s *Stmt) SelectOneRow(args ...interface{}) (bool, error) {
if ok, err := s.Next(); err != nil {
return false, err
} else if !ok {
return false, nil
}
return true, s.Scan(args...)
}
// Number of SQL parameters // Number of SQL parameters
// (See http://sqlite.org/c3ref/bind_parameter_count.html) // (See http://sqlite.org/c3ref/bind_parameter_count.html)
func (s *Stmt) BindParameterCount() int { func (s *Stmt) BindParameterCount() int {
...@@ -881,6 +892,7 @@ func (s *Stmt) finalize() error { ...@@ -881,6 +892,7 @@ func (s *Stmt) finalize() error {
} }
rv := C.sqlite3_finalize(s.stmt) rv := C.sqlite3_finalize(s.stmt)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
Log(int(rv), "error while finalizing Stmt")
return s.error(rv) return s.error(rv)
} }
s.stmt = nil s.stmt = nil
......
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