Commit 7c9d6542 authored by gwenn's avatar gwenn

Improve doc comments.

parent 4a519c95
......@@ -86,7 +86,7 @@ func (c *cache) flush() {
// CacheSize returns (current, max) sizes.
// Prepared statements cache is turned off when max size is 0
func (c *Conn) CacheSize() (int, int) {
func (c *Conn) CacheSize() (current int, max int) {
if c.stmtCache.maxSize <= 0 {
return 0, 0
}
......
......@@ -284,14 +284,14 @@ func (c *FunctionContext) Bool(i int) bool {
// Blob obtains a SQL function parameter value.
// The leftmost value is number 0.
// (See sqlite3_value_blob and sqlite3_value_bytes, http://sqlite.org/c3ref/value_blob.html)
func (c *FunctionContext) Blob(i int) (value []byte) {
func (c *FunctionContext) Blob(i int) []byte {
p := C.my_value_blob(c.argv, C.int(i))
if p != nil {
n := C.my_value_bytes(c.argv, C.int(i))
// value = (*[1 << 30]byte)(unsafe.Pointer(p))[:n]
value = C.GoBytes(p, n) // The memory space used to hold strings and BLOBs is freed automatically.
if p == nil {
return nil
}
return
n := C.my_value_bytes(c.argv, C.int(i))
// value = (*[1 << 30]byte)(unsafe.Pointer(p))[:n]
return C.GoBytes(p, n) // The memory space used to hold strings and BLOBs is freed automatically.
}
// Double obtains a SQL function parameter value.
......@@ -342,7 +342,8 @@ func (c *FunctionContext) NumericType(i int) Type {
}
// Value obtains a SQL function parameter value depending on its type.
func (c *FunctionContext) Value(i int) (value interface{}) {
func (c *FunctionContext) Value(i int) interface{} {
var value interface{}
switch c.Type(i) {
case Null:
value = nil
......@@ -357,7 +358,7 @@ func (c *FunctionContext) Value(i int) (value interface{}) {
default:
panic("The value type is not one of SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL")
}
return
return value
}
// ScalarFunction is the expected signature of scalar function implemented in Go
......
......@@ -20,7 +20,7 @@ import (
// CommitHook is the callback function signature.
// If the callback on a commit hook function returns true, then the commit is converted into a rollback.
type CommitHook func(udp interface{}) bool
type CommitHook func(udp interface{}) (rollback bool)
type sqliteCommitHook struct {
f CommitHook
......
......@@ -472,14 +472,15 @@ func (c *Conn) Rollback() error {
// Two errors may be returned: the first is the one returned by the f function,
// the second is the one returned by begin/commit/rollback.
// (See http://sqlite.org/tclsqlite.html#transaction)
func (c *Conn) Transaction(t TransactionType, f func(c *Conn) error) (err error) {
func (c *Conn) Transaction(t TransactionType, f func(c *Conn) error) error {
var err error
if c.nTransaction == 0 {
err = c.BeginTransaction(t)
} else {
err = c.Savepoint(strconv.Itoa(int(c.nTransaction)))
}
if err != nil {
return
return err
}
c.nTransaction++
defer func() {
......@@ -507,7 +508,7 @@ func (c *Conn) Transaction(t TransactionType, f func(c *Conn) error) (err error)
}
}()
err = f(c)
return
return err
}
// Savepoint starts a new transaction with a name.
......
......@@ -169,8 +169,8 @@ func (s *Stmt) exec() error {
// ExecDml is like Exec but returns the number of rows that were changed or inserted or deleted.
// Don't use it with SELECT or anything that returns data.
// The Stmt is reset at each call.
func (s *Stmt) ExecDml(args ...interface{}) (int, error) {
err := s.Exec(args...)
func (s *Stmt) ExecDml(args ...interface{}) (changes int, err error) {
err = s.Exec(args...)
if err != nil {
return -1, err
}
......@@ -180,7 +180,7 @@ func (s *Stmt) ExecDml(args ...interface{}) (int, error) {
// Insert is like ExecDml but returns the autoincremented rowid.
// Don't use it with SELECT or anything that returns data.
// The Stmt is reset at each call.
func (s *Stmt) Insert(args ...interface{}) (int64, error) {
func (s *Stmt) Insert(args ...interface{}) (rowid int64, err error) {
n, err := s.ExecDml(args...)
if err != nil {
return -1, err
......@@ -232,10 +232,10 @@ func (s *Stmt) Select(rowCallbackHandler func(s *Stmt) error, args ...interface{
// Returns false if there is no matching row.
// No check is done to ensure that no more than one row is returned by the statement.
// TODO Create a SelectUniqueRow that checks that the row is unique.
func (s *Stmt) SelectOneRow(args ...interface{}) (bool, error) {
if ok, err := s.Next(); err != nil {
func (s *Stmt) SelectOneRow(args ...interface{}) (found bool, err error) {
if found, err = s.Next(); err != nil {
return false, err
} else if !ok {
} else if !found {
if s.ColumnCount() == 0 {
return false, s.specificError("don't use SelectOneRow with query that returns no data such as %q", s.SQL())
}
......@@ -628,7 +628,7 @@ func (s *Stmt) ColumnIndex(name string) (int, error) {
// Returns true when column is null.
// Calls sqlite3_column_(blob|double|int|int64|text) depending on arg type/kind.
// (See http://sqlite.org/c3ref/column_blob.html)
func (s *Stmt) ScanByName(name string, value interface{}) (bool, error) {
func (s *Stmt) ScanByName(name string, value interface{}) (isNull bool, err error) {
index, err := s.ColumnIndex(name)
if err != nil {
return false, err
......@@ -654,9 +654,7 @@ func (s *Stmt) ScanByName(name string, value interface{}) (bool, error) {
// Returns true when column is null.
// Calls sqlite3_column_(blob|double|int|int64|text) depending on arg type/kind.
// (See http://sqlite.org/c3ref/column_blob.html)
func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
var isNull bool
var err error
func (s *Stmt) ScanByIndex(index int, value interface{}) (isNull bool, err error) {
switch value := value.(type) {
case nil:
case *string:
......@@ -762,7 +760,7 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
default:
return s.ScanReflect(index, value)
}
return isNull, err
return
}
// ScanReflect scans result value from a query.
......@@ -777,13 +775,11 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
// *float32,float64
//
// Returns true when column is null.
func (s *Stmt) ScanReflect(index int, v interface{}) (bool, error) {
func (s *Stmt) ScanReflect(index int, v interface{}) (isNull bool, err error) {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
return false, s.specificError("ScanReflect unsupported type %T", v)
}
var isNull bool
var err error
dv := reflect.Indirect(rv)
switch dv.Kind() {
case reflect.String:
......@@ -821,7 +817,7 @@ func (s *Stmt) ScanReflect(index int, v interface{}) (bool, error) {
default:
return false, s.specificError("unsupported type in Scan: %T", v)
}
return isNull, err
return
}
// ScanValue scans result value from a query.
......@@ -837,7 +833,7 @@ func (s *Stmt) ScanReflect(index int, v interface{}) (bool, error) {
//
// Calls sqlite3_column_(blob|double|int|int64|text) depending on columns type.
// (See http://sqlite.org/c3ref/column_blob.html)
func (s *Stmt) ScanValue(index int, blob bool) (interface{}, bool) {
func (s *Stmt) ScanValue(index int, blob bool) (value interface{}, isNull bool) {
switch s.ColumnType(index) {
case Null:
return nil, true
......
......@@ -269,7 +269,7 @@ func (c *Conn) BusyHandler(f BusyHandler, udp interface{}) error {
// ProgressHandler is the signature of query progress callback.
// Returns true to interrupt.
// See Conn.ProgressHandler
type ProgressHandler func(udp interface{}) bool
type ProgressHandler func(udp interface{}) (interrupt bool)
type sqliteProgressHandler struct {
f ProgressHandler
......
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