Commit 4b894bab authored by gwenn's avatar gwenn

Change Conn#OneValue method signature.

parent 0c9e9523
......@@ -10,8 +10,8 @@ import (
)
type Cache struct {
m sync.Mutex
l *list.List
m sync.Mutex
l *list.List
MaxSize int // Cache turned off when MaxSize <= 0
}
......
......@@ -22,7 +22,8 @@ func TestScalarFunction(t *testing.T) {
defer db.Close()
err = db.CreateScalarFunction("half", 1, nil, half, nil)
checkNoError(t, err, "couldn't create function: %s")
d, err := db.OneValue("select half(6)")
var d float64
err = db.OneValue("select half(6)", &d)
checkNoError(t, err, "couldn't retrieve result: %s")
if d != 3.0 {
t.Errorf("Expected %f but got %f", 3.0, d)
......@@ -115,9 +116,10 @@ func TestSumFunction(t *testing.T) {
defer db.Close()
err = db.CreateAggregateFunction("mysum", 1, nil, sumStep, sumFinal, nil)
checkNoError(t, err, "couldn't create function: %s")
i, err := db.OneValue("select mysum(i) from (select 2 as i union all select 2)")
var i int
err = db.OneValue("select mysum(i) from (select 2 as i union all select 2)", &i)
checkNoError(t, err, "couldn't execute statement: %s")
if i != int64(4) {
if i != 4 {
t.Errorf("Expected %d but got %v", 4, i)
}
}
......
......@@ -19,7 +19,8 @@ func (c *Conn) IntegrityCheck(max int, quick bool) error {
} else {
pragma = "integrity"
}
msg, err := c.OneValue(fmt.Sprintf("PRAGMA %s_check(%d)", pragma, max))
var msg string
err := c.OneValue(fmt.Sprintf("PRAGMA %s_check(%d)", pragma, max), &msg)
if err != nil {
return err
}
......@@ -33,25 +34,21 @@ func (c *Conn) IntegrityCheck(max int, quick bool) error {
// (See http://sqlite.org/pragma.html#pragma_encoding)
// TODO Make possible to specify the database-name (PRAGMA %Q.encoding)
func (c *Conn) Encoding() (string, error) {
value, err := c.OneValue("PRAGMA encoding")
var encoding string
err := c.OneValue("PRAGMA encoding", &encoding)
if err != nil {
return "", err
}
if encoding, ok := value.(string); ok {
return encoding, nil
}
return "", c.specificError("Unexpected encoding (%v)", value)
return encoding, nil
}
// (See http://sqlite.org/pragma.html#pragma_schema_version)
// TODO Make possible to specify the database-name (PRAGMA %Q.schema_version)
func (c *Conn) SchemaVersion() (int64, error) {
value, err := c.OneValue("PRAGMA schema_version")
func (c *Conn) SchemaVersion() (int, error) {
var version int
err := c.OneValue("PRAGMA schema_version", &version)
if err != nil {
return -1, err
}
if version, ok := value.(int64); ok {
return version, nil
}
return -1, c.specificError("Unexpected version (%v)", value)
}
\ No newline at end of file
return version, nil
}
package sqlite_test
import (
// . "github.com/gwenn/gosqlite"
"testing"
)
......
......@@ -378,19 +378,19 @@ func (c *Conn) Exists(query string, args ...interface{}) (bool, error) {
// Use it with SELECT that returns only one row with only one column.
// Returns io.EOF when there is no row.
func (c *Conn) OneValue(query string, args ...interface{}) (interface{}, error) {
func (c *Conn) OneValue(query string, value interface{}, args ...interface{}) error {
s, err := c.Prepare(query, args...)
if err != nil {
return nil, err
return err
}
defer s.Finalize()
b, err := s.Next()
if err != nil {
return nil, err
return err
} else if !b {
return nil, io.EOF
return io.EOF
}
return s.ScanValue(0), nil
return s.Scan(value)
}
// Count the number of rows modified
......
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