Permalink
Browse files

Add Stmt#SelectOneRow method.

  • Loading branch information...
1 parent 3074696 commit ca2fb6749204d03f7f34e6bd0b9b0390dfbf0fc6 @gwenn committed Apr 20, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −0 sqlite.go
  2. +13 −1 stmt.go
View
@@ -461,6 +461,7 @@ func (c *Conn) Close() error {
rv := C.sqlite3_close(c.db)
if rv != C.SQLITE_OK {
+ Log(int(rv), "error while closing Conn")
return c.error(rv)
}
c.db = nil
View
14 stmt.go
@@ -78,7 +78,7 @@ type Stmt struct {
params map[string]int // cached parameter index by name
// Enable type check in Scan methods (default true)
CheckTypeMismatch bool
- // Tell if the stmt should be cached (default false)
+ // Tell if the stmt should be cached (default true)
Cacheable bool
}
@@ -205,6 +205,17 @@ func (s *Stmt) Select(rowCallbackHandler func(s *Stmt) error, args ...interface{
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
// (See http://sqlite.org/c3ref/bind_parameter_count.html)
func (s *Stmt) BindParameterCount() int {
@@ -881,6 +892,7 @@ func (s *Stmt) finalize() error {
}
rv := C.sqlite3_finalize(s.stmt)
if rv != C.SQLITE_OK {
+ Log(int(rv), "error while finalizing Stmt")
return s.error(rv)
}
s.stmt = nil

0 comments on commit ca2fb67

Please sign in to comment.