Commit e8891f64 authored by gwenn's avatar gwenn

Fix error type.

parent ecae65ef
...@@ -19,7 +19,7 @@ import ( ...@@ -19,7 +19,7 @@ import (
) )
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit // Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit
func NewBackup(dst *Conn, dstTable string, src *Conn, srcTable string) (*Backup, os.Error) { func NewBackup(dst *Conn, dstTable string, src *Conn, srcTable string) (*Backup, error) {
dname := C.CString(dstTable) dname := C.CString(dstTable)
sname := C.CString(srcTable) sname := C.CString(srcTable)
defer C.free(unsafe.Pointer(dname)) defer C.free(unsafe.Pointer(dname))
...@@ -38,7 +38,7 @@ type Backup struct { ...@@ -38,7 +38,7 @@ type Backup struct {
} }
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep // Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep
func (b *Backup) Step(npage int) os.Error { func (b *Backup) Step(npage int) error {
rv := C.sqlite3_backup_step(b.sb, C.int(npage)) rv := C.sqlite3_backup_step(b.sb, C.int(npage))
if rv == C.SQLITE_OK || Errno(rv) == ErrBusy || Errno(rv) == ErrLocked { if rv == C.SQLITE_OK || Errno(rv) == ErrBusy || Errno(rv) == ErrLocked {
return nil return nil
...@@ -57,8 +57,8 @@ func (b *Backup) Status() BackupStatus { ...@@ -57,8 +57,8 @@ func (b *Backup) Status() BackupStatus {
} }
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep, sqlite3_backup_remaining and sqlite3_backup_pagecount // Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep, sqlite3_backup_remaining and sqlite3_backup_pagecount
func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) os.Error { func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) error {
var err os.Error var err error
for { for {
err = b.Step(npage) err = b.Step(npage)
if err != nil { if err != nil {
...@@ -73,7 +73,7 @@ func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) os.Error { ...@@ -73,7 +73,7 @@ func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) os.Error {
} }
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish // Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish
func (b *Backup) Close() os.Error { func (b *Backup) Close() error {
if b.sb == nil { if b.sb == nil {
return os.EINVAL return os.EINVAL
} }
......
...@@ -13,7 +13,7 @@ package sqlite ...@@ -13,7 +13,7 @@ package sqlite
import "C" import "C"
import ( import (
"os" "errors"
"unsafe" "unsafe"
) )
...@@ -29,7 +29,7 @@ type BlobReadWriter struct { ...@@ -29,7 +29,7 @@ type BlobReadWriter struct {
type ZeroBlobLength int type ZeroBlobLength int
// Calls http://sqlite.org/c3ref/blob_open.html // Calls http://sqlite.org/c3ref/blob_open.html
func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, os.Error) { func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, error) {
bl, err := c.blob_open(db, table, column, row, false) bl, err := c.blob_open(db, table, column, row, false)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -38,7 +38,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, ...@@ -38,7 +38,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
} }
// Calls http://sqlite.org/c3ref/blob_open.html // Calls http://sqlite.org/c3ref/blob_open.html
func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobReadWriter, os.Error) { func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobReadWriter, error) {
bl, err := c.blob_open(db, table, column, row, true) bl, err := c.blob_open(db, table, column, row, true)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -46,7 +46,7 @@ func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobRead ...@@ -46,7 +46,7 @@ func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobRead
return &BlobReadWriter{BlobReader{c, bl}}, nil return &BlobReadWriter{BlobReader{c, bl}}, nil
} }
func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sqlite3_blob, os.Error) { func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sqlite3_blob, error) {
zDb := C.CString(db) zDb := C.CString(db)
defer C.free(unsafe.Pointer(zDb)) defer C.free(unsafe.Pointer(zDb))
zTable := C.CString(table) zTable := C.CString(table)
...@@ -62,13 +62,13 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq ...@@ -62,13 +62,13 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
return nil, c.error(rv) return nil, c.error(rv)
} }
if bl == nil { if bl == nil {
return nil, os.NewError("sqlite succeeded without returning a blob") return nil, errors.New("sqlite succeeded without returning a blob")
} }
return bl, nil return bl, nil
} }
// Calls http://sqlite.org/c3ref/blob_close.html // Calls http://sqlite.org/c3ref/blob_close.html
func (r *BlobReader) Close() os.Error { func (r *BlobReader) Close() error {
rv := C.sqlite3_blob_close(r.bl) rv := C.sqlite3_blob_close(r.bl)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return r.c.error(rv) return r.c.error(rv)
...@@ -78,7 +78,7 @@ func (r *BlobReader) Close() os.Error { ...@@ -78,7 +78,7 @@ func (r *BlobReader) Close() os.Error {
} }
// Calls http://sqlite.org/c3ref/blob_read.html // Calls http://sqlite.org/c3ref/blob_read.html
func (r *BlobReader) Read(v []byte) (int, os.Error) { func (r *BlobReader) Read(v []byte) (int, error) {
var p *byte var p *byte
if len(v) > 0 { if len(v) > 0 {
p = &v[0] p = &v[0]
...@@ -91,13 +91,13 @@ func (r *BlobReader) Read(v []byte) (int, os.Error) { ...@@ -91,13 +91,13 @@ func (r *BlobReader) Read(v []byte) (int, os.Error) {
} }
// Calls http://sqlite.org/c3ref/blob_bytes.html // Calls http://sqlite.org/c3ref/blob_bytes.html
func (r *BlobReader) Size() (int, os.Error) { func (r *BlobReader) Size() (int, error) {
s := C.sqlite3_blob_bytes(r.bl) s := C.sqlite3_blob_bytes(r.bl)
return int(s), nil return int(s), nil
} }
// Calls http://sqlite.org/c3ref/blob_write.html // Calls http://sqlite.org/c3ref/blob_write.html
func (w *BlobReadWriter) Write(v []byte) (int, os.Error) { func (w *BlobReadWriter) Write(v []byte) (int, error) {
var p *byte var p *byte
if len(v) > 0 { if len(v) > 0 {
p = &v[0] p = &v[0]
...@@ -110,7 +110,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, os.Error) { ...@@ -110,7 +110,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, os.Error) {
} }
// Calls http://sqlite.org/c3ref/blob_reopen.html // Calls http://sqlite.org/c3ref/blob_reopen.html
func (r *BlobReader) Reopen(rowid int64) os.Error { func (r *BlobReader) Reopen(rowid int64) error {
rv := C.sqlite3_blob_reopen(r.bl, C.sqlite3_int64(rowid)) rv := C.sqlite3_blob_reopen(r.bl, C.sqlite3_int64(rowid))
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return r.c.error(rv) return r.c.error(rv)
......
...@@ -17,13 +17,10 @@ static char *my_mprintf(char *zFormat, char *arg) { ...@@ -17,13 +17,10 @@ static char *my_mprintf(char *zFormat, char *arg) {
*/ */
import "C" import "C"
import ( import "unsafe"
"os"
"unsafe"
)
// Executes pragma 'database_list' // Executes pragma 'database_list'
func (c *Conn) Databases() (map[string]string, os.Error) { func (c *Conn) Databases() (map[string]string, error) {
s, err := c.Prepare("PRAGMA database_list") s, err := c.Prepare("PRAGMA database_list")
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -46,7 +43,7 @@ func (c *Conn) Databases() (map[string]string, os.Error) { ...@@ -46,7 +43,7 @@ func (c *Conn) Databases() (map[string]string, os.Error) {
} }
// Selects tables (no view) from 'sqlite_master' and filters system tables out. // Selects tables (no view) from 'sqlite_master' and filters system tables out.
func (c *Conn) Tables() ([]string, os.Error) { func (c *Conn) Tables() ([]string, error) {
s, err := c.Prepare("SELECT name FROM sqlite_master WHERE type IN ('table') AND name NOT LIKE 'sqlite_%'") s, err := c.Prepare("SELECT name FROM sqlite_master WHERE type IN ('table') AND name NOT LIKE 'sqlite_%'")
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -77,7 +74,7 @@ type Column struct { ...@@ -77,7 +74,7 @@ type Column struct {
// Executes pragma 'table_info' // Executes pragma 'table_info'
// TODO How to specify a database-name? // TODO How to specify a database-name?
// TODO sqlite3_table_column_metadata? // TODO sqlite3_table_column_metadata?
func (c *Conn) Columns(table string) ([]Column, os.Error) { func (c *Conn) Columns(table string) ([]Column, error) {
s, err := c.Prepare(Mprintf("PRAGMA table_info(%Q)", table)) s, err := c.Prepare(Mprintf("PRAGMA table_info(%Q)", table))
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -107,7 +104,7 @@ type ForeignKey struct { ...@@ -107,7 +104,7 @@ type ForeignKey struct {
// Executes pragma 'foreign_key_list' // Executes pragma 'foreign_key_list'
// TODO How to specify a database-name? // TODO How to specify a database-name?
func (c *Conn) ForeignKeys(table string) (map[int]*ForeignKey, os.Error) { func (c *Conn) ForeignKeys(table string) (map[int]*ForeignKey, error) {
s, err := c.Prepare(Mprintf("PRAGMA foreign_key_list(%Q)", table)) s, err := c.Prepare(Mprintf("PRAGMA foreign_key_list(%Q)", table))
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -144,7 +141,7 @@ type Index struct { ...@@ -144,7 +141,7 @@ type Index struct {
// Executes pragma 'index_list' // Executes pragma 'index_list'
// TODO How to specify a database-name? // TODO How to specify a database-name?
func (c *Conn) Indexes(table string) ([]Index, os.Error) { func (c *Conn) Indexes(table string) ([]Index, error) {
s, err := c.Prepare(Mprintf("PRAGMA index_list(%Q)", table)) s, err := c.Prepare(Mprintf("PRAGMA index_list(%Q)", table))
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -168,7 +165,7 @@ func (c *Conn) Indexes(table string) ([]Index, os.Error) { ...@@ -168,7 +165,7 @@ func (c *Conn) Indexes(table string) ([]Index, os.Error) {
// Executes pragma 'index_info' // Executes pragma 'index_info'
// Only Column.Cid and Column.Name are specified. All other fields are unspecifed. // Only Column.Cid and Column.Name are specified. All other fields are unspecifed.
func (c *Conn) IndexColumns(index string) ([]Column, os.Error) { func (c *Conn) IndexColumns(index string) ([]Column, error) {
s, err := c.Prepare(Mprintf("PRAGMA index_info(%Q)", index)) s, err := c.Prepare(Mprintf("PRAGMA index_info(%Q)", index))
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -35,15 +35,15 @@ static int my_db_config(sqlite3 *db, int op, int v, int *ok) { ...@@ -35,15 +35,15 @@ static int my_db_config(sqlite3 *db, int op, int v, int *ok) {
import "C" import "C"
import ( import (
"errors"
"fmt" "fmt"
"os"
"reflect" "reflect"
"unsafe" "unsafe"
) )
type Errno int type Errno int
func (e Errno) String() string { func (e Errno) Error() string {
s := errText[e] s := errText[e]
if s == "" { if s == "" {
return fmt.Sprintf("errno %d", int(e)) return fmt.Sprintf("errno %d", int(e))
...@@ -52,30 +52,30 @@ func (e Errno) String() string { ...@@ -52,30 +52,30 @@ func (e Errno) String() string {
} }
var ( var (
ErrError os.Error = Errno(1) // /* SQL error or missing database */ ErrError error = Errno(1) // /* SQL error or missing database */
ErrInternal os.Error = Errno(2) // /* Internal logic error in SQLite */ ErrInternal error = Errno(2) // /* Internal logic error in SQLite */
ErrPerm os.Error = Errno(3) // /* Access permission denied */ ErrPerm error = Errno(3) // /* Access permission denied */
ErrAbort os.Error = Errno(4) // /* Callback routine requested an abort */ ErrAbort error = Errno(4) // /* Callback routine requested an abort */
ErrBusy os.Error = Errno(5) // /* The database file is locked */ ErrBusy error = Errno(5) // /* The database file is locked */
ErrLocked os.Error = Errno(6) // /* A table in the database is locked */ ErrLocked error = Errno(6) // /* A table in the database is locked */
ErrNoMem os.Error = Errno(7) // /* A malloc() failed */ ErrNoMem error = Errno(7) // /* A malloc() failed */
ErrReadOnly os.Error = Errno(8) // /* Attempt to write a readonly database */ ErrReadOnly error = Errno(8) // /* Attempt to write a readonly database */
ErrInterrupt os.Error = Errno(9) // /* Operation terminated by sqlite3_interrupt()*/ ErrInterrupt error = Errno(9) // /* Operation terminated by sqlite3_interrupt()*/
ErrIOErr os.Error = Errno(10) // /* Some kind of disk I/O error occurred */ ErrIOErr error = Errno(10) // /* Some kind of disk I/O error occurred */
ErrCorrupt os.Error = Errno(11) // /* The database disk image is malformed */ ErrCorrupt error = Errno(11) // /* The database disk image is malformed */
ErrFull os.Error = Errno(13) // /* Insertion failed because database is full */ ErrFull error = Errno(13) // /* Insertion failed because database is full */
ErrCantOpen os.Error = Errno(14) // /* Unable to open the database file */ ErrCantOpen error = Errno(14) // /* Unable to open the database file */
ErrEmpty os.Error = Errno(16) // /* Database is empty */ ErrEmpty error = Errno(16) // /* Database is empty */
ErrSchema os.Error = Errno(17) // /* The database schema changed */ ErrSchema error = Errno(17) // /* The database schema changed */
ErrTooBig os.Error = Errno(18) // /* String or BLOB exceeds size limit */ ErrTooBig error = Errno(18) // /* String or BLOB exceeds size limit */
ErrConstraint os.Error = Errno(19) // /* Abort due to constraint violation */ ErrConstraint error = Errno(19) // /* Abort due to constraint violation */
ErrMismatch os.Error = Errno(20) // /* Data type mismatch */ ErrMismatch error = Errno(20) // /* Data type mismatch */
ErrMisuse os.Error = Errno(21) // /* Library used incorrectly */ ErrMisuse error = Errno(21) // /* Library used incorrectly */
ErrNolfs os.Error = Errno(22) // /* Uses OS features not supported on host */ ErrNolfs error = Errno(22) // /* Uses OS features not supported on host */
ErrAuth os.Error = Errno(23) // /* Authorization denied */ ErrAuth error = Errno(23) // /* Authorization denied */
ErrFormat os.Error = Errno(24) // /* Auxiliary database format error */ ErrFormat error = Errno(24) // /* Auxiliary database format error */
ErrRange os.Error = Errno(25) // /* 2nd parameter to sqlite3_bind out of range */ ErrRange error = Errno(25) // /* 2nd parameter to sqlite3_bind out of range */
ErrNotDB os.Error = Errno(26) // /* File opened that is not a database file */ ErrNotDB error = Errno(26) // /* File opened that is not a database file */
Row = Errno(100) // /* sqlite3_step() has another row ready */ Row = Errno(100) // /* sqlite3_step() has another row ready */
Done = Errno(101) // /* sqlite3_step() has finished executing */ Done = Errno(101) // /* sqlite3_step() has finished executing */
) )
...@@ -111,9 +111,9 @@ var errText = map[Errno]string{ ...@@ -111,9 +111,9 @@ var errText = map[Errno]string{
101: "sqlite3_step() has finished executing", 101: "sqlite3_step() has finished executing",
} }
func (c *Conn) error(rv C.int) os.Error { func (c *Conn) error(rv C.int) error {
if c == nil || c.db == nil { if c == nil || c.db == nil {
return os.NewError("nil sqlite database") return errors.New("nil sqlite database")
} }
if rv == C.SQLITE_OK { if rv == C.SQLITE_OK {
return nil return nil
...@@ -121,13 +121,13 @@ func (c *Conn) error(rv C.int) os.Error { ...@@ -121,13 +121,13 @@ func (c *Conn) error(rv C.int) os.Error {
if rv == 21 { // misuse if rv == 21 { // misuse
return Errno(rv) return Errno(rv)
} }
return os.NewError(Errno(rv).String() + ": " + C.GoString(C.sqlite3_errmsg(c.db))) return errors.New(Errno(rv).Error() + ": " + C.GoString(C.sqlite3_errmsg(c.db)))
} }
// Calls http://sqlite.org/c3ref/errcode.html // Calls http://sqlite.org/c3ref/errcode.html
func (c *Conn) Error() os.Error { func (c *Conn) Error() error {
if c == nil || c.db == nil { if c == nil || c.db == nil {
return os.NewError("nil sqlite database") return errors.New("nil sqlite database")
} }
return c.error(C.sqlite3_errcode(c.db)) return c.error(C.sqlite3_errcode(c.db))
} }
...@@ -167,9 +167,9 @@ const ( ...@@ -167,9 +167,9 @@ const (
// ":memory:" for memory db // ":memory:" for memory db
// "" for temp file db // "" for temp file db
// Calls sqlite3_open_v2: http://sqlite.org/c3ref/open.html // Calls sqlite3_open_v2: http://sqlite.org/c3ref/open.html
func Open(filename string, flags ...OpenFlag) (*Conn, os.Error) { func Open(filename string, flags ...OpenFlag) (*Conn, error) {
if C.sqlite3_threadsafe() == 0 { if C.sqlite3_threadsafe() == 0 {
return nil, os.NewError("sqlite library was not compiled for thread-safe operation") return nil, errors.New("sqlite library was not compiled for thread-safe operation")
} }
var openFlags int var openFlags int
if len(flags) > 0 { if len(flags) > 0 {
...@@ -191,13 +191,13 @@ func Open(filename string, flags ...OpenFlag) (*Conn, os.Error) { ...@@ -191,13 +191,13 @@ func Open(filename string, flags ...OpenFlag) (*Conn, os.Error) {
return nil, Errno(rv) return nil, Errno(rv)
} }
if db == nil { if db == nil {
return nil, os.NewError("sqlite succeeded without returning a database") return nil, errors.New("sqlite succeeded without returning a database")
} }
return &Conn{db: db}, nil return &Conn{db: db}, nil
} }
// Calls http://sqlite.org/c3ref/busy_timeout.html // Calls http://sqlite.org/c3ref/busy_timeout.html
func (c *Conn) BusyTimeout(ms int) os.Error { func (c *Conn) BusyTimeout(ms int) error {
rv := C.sqlite3_busy_timeout(c.db, C.int(ms)) rv := C.sqlite3_busy_timeout(c.db, C.int(ms))
if rv == C.SQLITE_OK { if rv == C.SQLITE_OK {
return nil return nil
...@@ -208,16 +208,16 @@ func (c *Conn) BusyTimeout(ms int) os.Error { ...@@ -208,16 +208,16 @@ func (c *Conn) BusyTimeout(ms int) os.Error {
// Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, b) // Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, b)
// Another way is PRAGMA foreign_keys = boolean; // Another way is PRAGMA foreign_keys = boolean;
// http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html // http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html
func (c *Conn) EnableFKey(b bool) (bool, os.Error) { func (c *Conn) EnableFKey(b bool) (bool, error) {
return c.queryOrSetEnableFKey(btocint(b)) return c.queryOrSetEnableFKey(btocint(b))
} }
// Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, -1) // Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, -1)
// Another way is PRAGMA foreign_keys; // Another way is PRAGMA foreign_keys;
// http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html // http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html
func (c *Conn) IsFKeyEnabled() (bool, os.Error) { func (c *Conn) IsFKeyEnabled() (bool, error) {
return c.queryOrSetEnableFKey(-1) return c.queryOrSetEnableFKey(-1)
} }
func (c *Conn) queryOrSetEnableFKey(i C.int) (bool, os.Error) { func (c *Conn) queryOrSetEnableFKey(i C.int) (bool, error) {
var ok C.int var ok C.int
rv := C.my_db_config(c.db, C.SQLITE_DBCONFIG_ENABLE_FKEY, i, &ok) rv := C.my_db_config(c.db, C.SQLITE_DBCONFIG_ENABLE_FKEY, i, &ok)
if rv == C.SQLITE_OK { if rv == C.SQLITE_OK {
...@@ -230,7 +230,7 @@ func (c *Conn) queryOrSetEnableFKey(i C.int) (bool, os.Error) { ...@@ -230,7 +230,7 @@ func (c *Conn) queryOrSetEnableFKey(i C.int) (bool, os.Error) {
// Calls sqlite3_prepare_v2, sqlite3_bind_*, sqlite3_step and sqlite3_finalize // Calls sqlite3_prepare_v2, sqlite3_bind_*, sqlite3_step and sqlite3_finalize
// http://sqlite.org/c3ref/prepare.html, http://sqlite.org/c3ref/bind_blob.html, // http://sqlite.org/c3ref/prepare.html, http://sqlite.org/c3ref/bind_blob.html,
// http://sqlite.org/c3ref/step.html and http://sqlite.org/c3ref/finalize.html // http://sqlite.org/c3ref/step.html and http://sqlite.org/c3ref/finalize.html
func (c *Conn) Exec(cmd string, args ...interface{}) os.Error { func (c *Conn) Exec(cmd string, args ...interface{}) error {
for len(cmd) > 0 { for len(cmd) > 0 {
s, err := c.Prepare(cmd) s, err := c.Prepare(cmd)
if err != nil { if err != nil {
...@@ -251,7 +251,7 @@ func (c *Conn) Exec(cmd string, args ...interface{}) os.Error { ...@@ -251,7 +251,7 @@ func (c *Conn) Exec(cmd string, args ...interface{}) os.Error {
if len(s.tail) > 0 { if len(s.tail) > 0 {
if len(args) > 0 { if len(args) > 0 {
s.Finalize() s.Finalize()
return os.NewError("Cannot execute multiple statements when args are specified") return errors.New("Cannot execute multiple statements when args are specified")
} }
} }
cmd = s.tail cmd = s.tail
...@@ -263,7 +263,7 @@ func (c *Conn) Exec(cmd string, args ...interface{}) os.Error { ...@@ -263,7 +263,7 @@ func (c *Conn) Exec(cmd string, args ...interface{}) os.Error {
} }
// Returns true if the specified query returns at least one row. // Returns true if the specified query returns at least one row.
func (c *Conn) Exists(query string, args ...interface{}) (bool, os.Error) { func (c *Conn) Exists(query string, args ...interface{}) (bool, error) {
s, err := c.Prepare(query, args...) s, err := c.Prepare(query, args...)
if err != nil { if err != nil {
return false, err return false, err
...@@ -304,11 +304,11 @@ const ( ...@@ -304,11 +304,11 @@ const (
EXCLUSIVE TransactionType = 2 EXCLUSIVE TransactionType = 2
) )
func (c *Conn) Begin() os.Error { func (c *Conn) Begin() error {
return c.BeginTransaction(DEFERRED) return c.BeginTransaction(DEFERRED)
} }
func (c *Conn) BeginTransaction(t TransactionType) os.Error { func (c *Conn) BeginTransaction(t TransactionType) error {
if t == DEFERRED { if t == DEFERRED {
return c.exec("BEGIN") return c.exec("BEGIN")
} else if t == IMMEDIATE { } else if t == IMMEDIATE {
...@@ -320,16 +320,16 @@ func (c *Conn) BeginTransaction(t TransactionType) os.Error { ...@@ -320,16 +320,16 @@ func (c *Conn) BeginTransaction(t TransactionType) os.Error {
return nil return nil
} }
func (c *Conn) Commit() os.Error { func (c *Conn) Commit() error {
// TODO Check autocommit? // TODO Check autocommit?
return c.exec("COMMIT") return c.exec("COMMIT")
} }
func (c *Conn) Rollback() os.Error { func (c *Conn) Rollback() error {
// TODO Check autocommit? // TODO Check autocommit?
return c.exec("ROLLBACK") return c.exec("ROLLBACK")
} }
func (c *Conn) exec(cmd string) os.Error { func (c *Conn) exec(cmd string) error {
cmdstr := C.CString(cmd) cmdstr := C.CString(cmd)
defer C.free(unsafe.Pointer(cmdstr)) defer C.free(unsafe.Pointer(cmdstr))
rv := C.sqlite3_exec(c.db, cmdstr, nil, nil, nil) rv := C.sqlite3_exec(c.db, cmdstr, nil, nil, nil)
...@@ -353,9 +353,9 @@ type Stmt struct { ...@@ -353,9 +353,9 @@ type Stmt struct {
// Calls sqlite3_prepare_v2 and sqlite3_bind_* // Calls sqlite3_prepare_v2 and sqlite3_bind_*
// http://sqlite.org/c3ref/prepare.html, http://sqlite.org/c3ref/bind_blob.html, // http://sqlite.org/c3ref/prepare.html, http://sqlite.org/c3ref/bind_blob.html,
func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, os.Error) { func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, error) {
if c == nil || c.db == nil { if c == nil || c.db == nil {
return nil, os.NewError("nil sqlite database") return nil, errors.New("nil sqlite database")
} }
cmdstr := C.CString(cmd) cmdstr := C.CString(cmd)
defer C.free(unsafe.Pointer(cmdstr)) defer C.free(unsafe.Pointer(cmdstr))
...@@ -382,7 +382,7 @@ func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, os.Error) { ...@@ -382,7 +382,7 @@ func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, os.Error) {
// Don't use it with SELECT or anything that returns data. // Don't use it with SELECT or anything that returns data.
// Calls sqlite3_bind_* and sqlite3_step // Calls sqlite3_bind_* and sqlite3_step
// http://sqlite.org/c3ref/bind_blob.html, http://sqlite.org/c3ref/step.html // http://sqlite.org/c3ref/bind_blob.html, http://sqlite.org/c3ref/step.html
func (s *Stmt) Exec(args ...interface{}) os.Error { func (s *Stmt) Exec(args ...interface{}) error {
err := s.Bind(args...) err := s.Bind(args...)
if err != nil { if err != nil {
return err return err
...@@ -396,7 +396,7 @@ func (s *Stmt) Exec(args ...interface{}) os.Error { ...@@ -396,7 +396,7 @@ func (s *Stmt) Exec(args ...interface{}) os.Error {
// Don't use it with SELECT or anything that returns data. // Don't use it with SELECT or anything that returns data.
// Like Exec but returns the number of rows that were changed or inserted or deleted. // Like Exec but returns the number of rows that were changed or inserted or deleted.
func (s *Stmt) ExecUpdate(args ...interface{}) (int, os.Error) { func (s *Stmt) ExecUpdate(args ...interface{}) (int, error) {
err := s.Exec(args...) err := s.Exec(args...)
if err != nil { if err != nil {
return -1, err return -1, err
...@@ -424,7 +424,7 @@ func (s *Stmt) BindParameterName(i int) string { ...@@ -424,7 +424,7 @@ func (s *Stmt) BindParameterName(i int) string {
// Calls sqlite3_bind_parameter_count and sqlite3_bind_(blob|double|int|int64|null|text) depending on args type. // Calls sqlite3_bind_parameter_count and sqlite3_bind_(blob|double|int|int64|null|text) depending on args type.
// http://sqlite.org/c3ref/bind_blob.html // http://sqlite.org/c3ref/bind_blob.html
func (s *Stmt) Bind(args ...interface{}) os.Error { func (s *Stmt) Bind(args ...interface{}) error {
err := s.Reset() // TODO sqlite3_clear_bindings? err := s.Reset() // TODO sqlite3_clear_bindings?
if err != nil { if err != nil {
return err return err
...@@ -432,7 +432,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error { ...@@ -432,7 +432,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error {
n := s.BindParameterCount() n := s.BindParameterCount()
if n != len(args) { // What happens when the number of arguments is less than the number of parameters? if n != len(args) { // What happens when the number of arguments is less than the number of parameters?
return os.NewError(fmt.Sprintf("incorrect argument count for Stmt.Bind: have %d want %d", len(args), n)) return errors.New(fmt.Sprintf("incorrect argument count for Stmt.Bind: have %d want %d", len(args), n))
} }
for i, v := range args { for i, v := range args {
...@@ -466,7 +466,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error { ...@@ -466,7 +466,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error {
case ZeroBlobLength: case ZeroBlobLength:
rv = C.sqlite3_bind_zeroblob(s.stmt, index, C.int(v)) rv = C.sqlite3_bind_zeroblob(s.stmt, index, C.int(v))
default: default:
return os.NewError("unsupported type in Bind: " + reflect.TypeOf(v).String()) return errors.New("unsupported type in Bind: " + reflect.TypeOf(v).String())
} }
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return s.c.error(rv) return s.c.error(rv)
...@@ -490,7 +490,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error { ...@@ -490,7 +490,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error {
// } // }
// Calls sqlite3_step // Calls sqlite3_step
// http://sqlite.org/c3ref/step.html // http://sqlite.org/c3ref/step.html
func (s *Stmt) Next() (bool, os.Error) { func (s *Stmt) Next() (bool, error) {
rv := C.sqlite3_step(s.stmt) rv := C.sqlite3_step(s.stmt)
err := Errno(rv) err := Errno(rv)
if err == Row { if err == Row {
...@@ -503,7 +503,7 @@ func (s *Stmt) Next() (bool, os.Error) { ...@@ -503,7 +503,7 @@ func (s *Stmt) Next() (bool, os.Error) {
} }
// Calls http://sqlite.org/c3ref/reset.html // Calls http://sqlite.org/c3ref/reset.html
func (s *Stmt) Reset() os.Error { func (s *Stmt) Reset() error {
rv := C.sqlite3_reset(s.stmt) rv := C.sqlite3_reset(s.stmt)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return s.c.error(rv) return s.c.error(rv)
...@@ -512,7 +512,7 @@ func (s *Stmt) Reset() os.Error { ...@@ -512,7 +512,7 @@ func (s *Stmt) Reset() os.Error {
} }
// Calls http://sqlite.org/c3ref/clear_bindings.html // Calls http://sqlite.org/c3ref/clear_bindings.html
func (s *Stmt) ClearBindings() os.Error { func (s *Stmt) ClearBindings() error {
rv := C.sqlite3_clear_bindings(s.stmt) rv := C.sqlite3_clear_bindings(s.stmt)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return s.c.error(rv) return s.c.error(rv)
...@@ -569,14 +569,14 @@ func (s *Stmt) ColumnType(index int) Type { ...@@ -569,14 +569,14 @@ func (s *Stmt) ColumnType(index int) Type {
// NULL value is converted to 0 if arg type is *int,*int64,*float,*float64, to "" for *string, to []byte{} for *[]byte and to false for *bool. // NULL value is converted to 0 if arg type is *int,*int64,*float,*float64, to "" for *string, to []byte{} for *[]byte and to false for *bool.
// Calls sqlite3_column_count, sqlite3_column_name and sqlite3_column_(blob|double|int|int64|text) depending on args type. // Calls sqlite3_column_count, sqlite3_column_name and sqlite3_column_(blob|double|int|int64|text) depending on args type.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) NamedScan(args ...interface{}) os.Error { func (s *Stmt) NamedScan(args ...interface{}) error {
if len(args)%2 != 0 { if len(args)%2 != 0 {
return os.NewError("Expected an even number of arguments") return errors.New("Expected an even number of arguments")
} }
for i := 0; i < len(args); i += 2 { for i := 0; i < len(args); i += 2 {
name, ok := args[i].(string) name, ok := args[i].(string)
if !ok { if !ok {
return os.NewError("non-string field name field") return errors.New("non-string field name field")
} }
index, err := s.ColumnIndex(name) // How to look up only once for one statement ? index, err := s.ColumnIndex(name) // How to look up only once for one statement ?
if err != nil { if err != nil {
...@@ -595,10 +595,10 @@ func (s *Stmt) NamedScan(args ...interface{}) os.Error { ...@@ -595,10 +595,10 @@ func (s *Stmt) NamedScan(args ...interface{}) os.Error {
// TODO How to avoid NULL conversion? // TODO How to avoid NULL conversion?
// Calls sqlite3_column_count and sqlite3_column_(blob|double|int|int64|text) depending on args type. // Calls sqlite3_column_count and sqlite3_column_(blob|double|int|int64|text) depending on args type.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) Scan(args ...interface{}) os.Error { func (s *Stmt) Scan(args ...interface{}) error {
n := s.ColumnCount() n := s.ColumnCount()
if n != len(args) { // What happens when the number of arguments is less than the number of columns? if n != len(args) { // What happens when the number of arguments is less than the number of columns?
return os.NewError(fmt.Sprintf("incorrect argument count for Stmt.Scan: have %d want %d", len(args), n)) return errors.New(fmt.Sprintf("incorrect argument count for Stmt.Scan: have %d want %d", len(args), n))
} }
for i, v := range args { for i, v := range args {
...@@ -618,7 +618,7 @@ func (s *Stmt) SQL() string { ...@@ -618,7 +618,7 @@ func (s *Stmt) SQL() string {
// Must scan all columns (but result is cached). // Must scan all columns (but result is cached).
// Calls sqlite3_column_count, sqlite3_column_name // Calls sqlite3_column_count, sqlite3_column_name
// http://sqlite.org/c3ref/column_name.html // http://sqlite.org/c3ref/column_name.html
func (s *Stmt) ColumnIndex(name string) (int, os.Error) { func (s *Stmt) ColumnIndex(name string) (int, error) {
if s.cols == nil { if s.cols == nil {
count := s.ColumnCount() count := s.ColumnCount()
s.cols = make(map[string]int, count) s.cols = make(map[string]int, count)
...@@ -630,14 +630,14 @@ func (s *Stmt) ColumnIndex(name string) (int, os.Error) { ...@@ -630,14 +630,14 @@ func (s *Stmt) ColumnIndex(name string) (int, os.Error) {
if ok { if ok {
return index, nil return index, nil
} }
return 0, os.NewError("invalid column name: " + name) return 0, errors.New("invalid column name: " + name)
} }
// Set nullable to false to skip NULL type test. // Set nullable to false to skip NULL type test.
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_count, sqlite3_column_name and sqlite3_column_(blob|double|int|int64|text) depending on args type. // Calls sqlite3_column_count, sqlite3_column_name and sqlite3_column_(blob|double|int|int64|text) depending on args type.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) NamedScanColumn(name string, value interface{}) (bool, os.Error) { func (s *Stmt) NamedScanColumn(name string, value interface{}) (bool, error) {
index, err := s.ColumnIndex(name) index, err := s.ColumnIndex(name)
if err != nil { if err != nil {
return false, err return false, err
...@@ -649,9 +649,9 @@ func (s *Stmt) NamedScanColumn(name string, value interface{}) (bool, os.Error) ...@@ -649,9 +649,9 @@ func (s *Stmt) NamedScanColumn(name string, value interface{}) (bool, os.Error)
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_(blob|double|int|int64|text) depending on args type. // Calls sqlite3_column_(blob|double|int|int64|text) depending on args type.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanColumn(index int, value interface{}) (bool, os.Error) { func (s *Stmt) ScanColumn(index int, value interface{}) (bool, error) {
var isNull bool var isNull bool
var err os.Error var err error
switch value := value.(type) { switch value := value.(type) {
case nil: case nil:
case *string: case *string:
...@@ -669,7 +669,7 @@ func (s *Stmt) ScanColumn(index int, value interface{}) (bool, os.Error) { ...@@ -669,7 +669,7 @@ func (s *Stmt) ScanColumn(index int, value interface{}) (bool, os.Error) {
case *[]byte: case *[]byte:
*value, isNull, err = s.ScanBlob(index) *value, isNull, err = s.ScanBlob(index)
default: default:
return false, os.NewError("unsupported type in Scan: " + reflect.TypeOf(value).String()) return false, errors.New("unsupported type in Scan: " + reflect.TypeOf(value).String())
} }
return isNull, err return isNull, err
} }
...@@ -703,7 +703,7 @@ func (s *Stmt) ScanValue(index int) (value interface{}) { ...@@ -703,7 +703,7 @@ func (s *Stmt) ScanValue(index int) (value interface{}) {
// Returns true when column is null. // Returns true when column is null.
// Calls sqlite3_column_text. // Calls sqlite3_column_text.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanText(index int) (value string, isNull bool, err os.Error) { func (s *Stmt) ScanText(index int) (value string, isNull bool, err error) {
p := C.sqlite3_column_text(s.stmt, C.int(index)) p := C.sqlite3_column_text(s.stmt, C.int(index))
if p == nil { if p == nil {
isNull = true isNull = true
...@@ -718,7 +718,7 @@ func (s *Stmt) ScanText(index int) (value string, isNull bool, err os.Error) { ...@@ -718,7 +718,7 @@ func (s *Stmt) ScanText(index int) (value string, isNull bool, err os.Error) {
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_int. // Calls sqlite3_column_int.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanInt(index int) (value int, isNull bool, err os.Error) { func (s *Stmt) ScanInt(index int) (value int, isNull bool, err error) {
var ctype Type var ctype Type
if s.CheckNull || s.CheckTypeMismatch { if s.CheckNull || s.CheckTypeMismatch {
ctype = s.ColumnType(index) ctype = s.ColumnType(index)
...@@ -738,7 +738,7 @@ func (s *Stmt) ScanInt(index int) (value int, isNull bool, err os.Error) { ...@@ -738,7 +738,7 @@ func (s *Stmt) ScanInt(index int) (value int, isNull bool, err os.Error) {
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_int64. // Calls sqlite3_column_int64.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanInt64(index int) (value int64, isNull bool, err os.Error) { func (s *Stmt) ScanInt64(index int) (value int64, isNull bool, err error) {
var ctype Type var ctype Type
if s.CheckNull || s.CheckTypeMismatch { if s.CheckNull || s.CheckTypeMismatch {
ctype = s.ColumnType(index) ctype = s.ColumnType(index)
...@@ -758,7 +758,7 @@ func (s *Stmt) ScanInt64(index int) (value int64, isNull bool, err os.Error) { ...@@ -758,7 +758,7 @@ func (s *Stmt) ScanInt64(index int) (value int64, isNull bool, err os.Error) {
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_int. // Calls sqlite3_column_int.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanByte(index int) (value byte, isNull bool, err os.Error) { func (s *Stmt) ScanByte(index int) (value byte, isNull bool, err error) {
var ctype Type var ctype Type
if s.CheckNull || s.CheckTypeMismatch { if s.CheckNull || s.CheckTypeMismatch {
ctype = s.ColumnType(index) ctype = s.ColumnType(index)
...@@ -778,7 +778,7 @@ func (s *Stmt) ScanByte(index int) (value byte, isNull bool, err os.Error) { ...@@ -778,7 +778,7 @@ func (s *Stmt) ScanByte(index int) (value byte, isNull bool, err os.Error) {
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_int. // Calls sqlite3_column_int.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanBool(index int) (value bool, isNull bool, err os.Error) { func (s *Stmt) ScanBool(index int) (value bool, isNull bool, err error) {
var ctype Type var ctype Type
if s.CheckNull || s.CheckTypeMismatch { if s.CheckNull || s.CheckTypeMismatch {
ctype = s.ColumnType(index) ctype = s.ColumnType(index)
...@@ -798,7 +798,7 @@ func (s *Stmt) ScanBool(index int) (value bool, isNull bool, err os.Error) { ...@@ -798,7 +798,7 @@ func (s *Stmt) ScanBool(index int) (value bool, isNull bool, err os.Error) {
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_double. // Calls sqlite3_column_double.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanFloat64(index int) (value float64, isNull bool, err os.Error) { func (s *Stmt) ScanFloat64(index int) (value float64, isNull bool, err error) {
var ctype Type var ctype Type
if s.CheckNull || s.CheckTypeMismatch { if s.CheckNull || s.CheckTypeMismatch {
ctype = s.ColumnType(index) ctype = s.ColumnType(index)
...@@ -818,7 +818,7 @@ func (s *Stmt) ScanFloat64(index int) (value float64, isNull bool, err os.Error) ...@@ -818,7 +818,7 @@ func (s *Stmt) ScanFloat64(index int) (value float64, isNull bool, err os.Error)
// Returns true when column is null. // Returns true when column is null.
// Calls sqlite3_column_bytes. // Calls sqlite3_column_bytes.
// http://sqlite.org/c3ref/column_blob.html // http://sqlite.org/c3ref/column_blob.html
func (s *Stmt) ScanBlob(index int) (value []byte, isNull bool, err os.Error) { func (s *Stmt) ScanBlob(index int) (value []byte, isNull bool, err error) {
p := C.sqlite3_column_blob(s.stmt, C.int(index)) p := C.sqlite3_column_blob(s.stmt, C.int(index))
if p == nil { if p == nil {
isNull = true isNull = true
...@@ -830,7 +830,7 @@ func (s *Stmt) ScanBlob(index int) (value []byte, isNull bool, err os.Error) { ...@@ -830,7 +830,7 @@ func (s *Stmt) ScanBlob(index int) (value []byte, isNull bool, err os.Error) {
} }
// Only lossy conversion is reported as error. // Only lossy conversion is reported as error.
func (s *Stmt) checkTypeMismatch(source, target Type) os.Error { func (s *Stmt) checkTypeMismatch(source, target Type) error {
switch target { switch target {
case Integer: case Integer:
switch source { switch source {
...@@ -853,7 +853,7 @@ func (s *Stmt) checkTypeMismatch(source, target Type) os.Error { ...@@ -853,7 +853,7 @@ func (s *Stmt) checkTypeMismatch(source, target Type) os.Error {
} }
// Calls http://sqlite.org/c3ref/finalize.html // Calls http://sqlite.org/c3ref/finalize.html
func (s *Stmt) Finalize() os.Error { 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 {
return s.c.error(rv) return s.c.error(rv)
...@@ -868,9 +868,9 @@ func (s *Stmt) Conn() *Conn { ...@@ -868,9 +868,9 @@ func (s *Stmt) Conn() *Conn {
} }
// Calls http://sqlite.org/c3ref/close.html // Calls http://sqlite.org/c3ref/close.html
func (c *Conn) Close() os.Error { func (c *Conn) Close() error {
if c == nil { if c == nil {
return os.NewError("nil sqlite database") return errors.New("nil sqlite database")
} }
// Dangling statements // Dangling statements
stmt := C.sqlite3_next_stmt(c.db, nil) stmt := C.sqlite3_next_stmt(c.db, nil)
...@@ -898,7 +898,7 @@ func (c *Conn) EnableLoadExtension(b bool) { ...@@ -898,7 +898,7 @@ func (c *Conn) EnableLoadExtension(b bool) {
C.sqlite3_enable_load_extension(c.db, btocint(b)) C.sqlite3_enable_load_extension(c.db, btocint(b))
} }
// Calls http://sqlite.org/c3ref/load_extension.html // Calls http://sqlite.org/c3ref/load_extension.html
func (c *Conn) LoadExtension(file string, proc ...string) os.Error { func (c *Conn) LoadExtension(file string, proc ...string) error {
cfile := C.CString(file) cfile := C.CString(file)
defer C.free(unsafe.Pointer(cfile)) defer C.free(unsafe.Pointer(cfile))
var cproc *C.char var cproc *C.char
...@@ -910,7 +910,7 @@ func (c *Conn) LoadExtension(file string, proc ...string) os.Error { ...@@ -910,7 +910,7 @@ func (c *Conn) LoadExtension(file string, proc ...string) os.Error {
rv := C.sqlite3_load_extension(c.db, cfile, cproc, &errMsg) rv := C.sqlite3_load_extension(c.db, cfile, cproc, &errMsg)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
defer C.sqlite3_free(unsafe.Pointer(errMsg)) defer C.sqlite3_free(unsafe.Pointer(errMsg))
return os.NewError(Errno(rv).String() + ": " + C.GoString(errMsg)) return errors.New(Errno(rv).Error() + ": " + C.GoString(errMsg))
} }
return nil return nil
} }
...@@ -922,7 +922,7 @@ func EnableSharedCache(b bool) { ...@@ -922,7 +922,7 @@ func EnableSharedCache(b bool) {
// Must is a helper that wraps a call to a function returning (bool, os.Error) // Must is a helper that wraps a call to a function returning (bool, os.Error)
// and panics if the error is non-nil. // and panics if the error is non-nil.
func Must(b bool, err os.Error) bool { func Must(b bool, err error) bool {
if err != nil { if err != nil {
panic(err) panic(err)
} }
......
...@@ -46,10 +46,7 @@ static void my_log(int iErrCode, char *msg) { ...@@ -46,10 +46,7 @@ static void my_log(int iErrCode, char *msg) {
*/ */
import "C" import "C"
import ( import "unsafe"
"os"
"unsafe"
)
type Tracer func(udp interface{}, sql string) type Tracer func(udp interface{}, sql string)
...@@ -162,7 +159,7 @@ func goXAuth(udp unsafe.Pointer, action C.int, arg1, arg2, dbName, triggerName * ...@@ -162,7 +159,7 @@ func goXAuth(udp unsafe.Pointer, action C.int, arg1, arg2, dbName, triggerName *
} }
// Calls http://sqlite.org/c3ref/set_authorizer.html // Calls http://sqlite.org/c3ref/set_authorizer.html
func (c *Conn) SetAuthorizer(f Authorizer, udp interface{}) os.Error { func (c *Conn) SetAuthorizer(f Authorizer, udp interface{}) error {
if f == nil { if f == nil {
c.authorizer = nil c.authorizer = nil
return c.error(C.sqlite3_set_authorizer(c.db, nil, nil)) return c.error(C.sqlite3_set_authorizer(c.db, nil, nil))
...@@ -188,7 +185,7 @@ func goXBusy(udp unsafe.Pointer, count C.int) C.int { ...@@ -188,7 +185,7 @@ func goXBusy(udp unsafe.Pointer, count C.int) C.int {
// TODO NOT TESTED // TODO NOT TESTED
// Calls http://sqlite.org/c3ref/busy_handler.html // Calls http://sqlite.org/c3ref/busy_handler.html
func (c *Conn) BusyHandler(f BusyHandler, udp interface{}) os.Error { func (c *Conn) BusyHandler(f BusyHandler, udp interface{}) error {
if f == nil { if f == nil {
c.busyHandler = nil c.busyHandler = nil
return c.error(C.sqlite3_busy_handler(c.db, nil, nil)) return c.error(C.sqlite3_busy_handler(c.db, nil, 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