Commit bf209594 authored by gwenn's avatar gwenn

Fix some error messages.

parent fa8e3f86
...@@ -127,21 +127,21 @@ func (r *BlobReader) Seek(offset int64, whence int) (int64, error) { ...@@ -127,21 +127,21 @@ func (r *BlobReader) Seek(offset int64, whence int) (int64, error) {
switch whence { switch whence {
case 0: // SEEK_SET case 0: // SEEK_SET
if offset < 0 || offset > int64(size) { if offset < 0 || offset > int64(size) {
return 0, r.c.specificError("Invalid offset: %d", offset) return 0, r.c.specificError("invalid offset: %d", offset)
} }
r.offset = int32(offset) r.offset = int32(offset)
case 1: // SEEK_CUR case 1: // SEEK_CUR
if (int64(r.offset)+offset) < 0 || (int64(r.offset)+offset) > int64(size) { if (int64(r.offset)+offset) < 0 || (int64(r.offset)+offset) > int64(size) {
return 0, r.c.specificError("Invalid offset: %d", offset) return 0, r.c.specificError("invalid offset: %d", offset)
} }
r.offset += int32(offset) r.offset += int32(offset)
case 2: // SEEK_END case 2: // SEEK_END
if (int64(size)+offset) < 0 || offset > 0 { if (int64(size)+offset) < 0 || offset > 0 {
return 0, r.c.specificError("Invalid offset: %d", offset) return 0, r.c.specificError("invalid offset: %d", offset)
} }
r.offset = size + int32(offset) r.offset = size + int32(offset)
default: default:
return 0, r.c.specificError("Bad seekMode: %d", whence) return 0, r.c.specificError("bad seekMode: %d", whence)
} }
return int64(r.offset), nil return int64(r.offset), nil
} }
......
...@@ -58,14 +58,21 @@ func (d *impl) Open(name string) (driver.Conn, error) { ...@@ -58,14 +58,21 @@ func (d *impl) Open(name string) (driver.Conn, error) {
// PRAGMA schema_version may be used to detect when the database schema is altered // PRAGMA schema_version may be used to detect when the database schema is altered
func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) { func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
if c.c.IsClosed() {
return nil, driver.ErrBadConn
}
if len(args) == 0 {
if err := c.c.FastExec(query); err != nil {
return nil, err
}
return c, nil
}
// https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices // https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices
var iargs []interface{} var iargs []interface{}
if len(args) > 0 {
h := (*reflect.SliceHeader)(unsafe.Pointer(&iargs)) h := (*reflect.SliceHeader)(unsafe.Pointer(&iargs))
h.Data = uintptr(unsafe.Pointer(&args[0])) h.Data = uintptr(unsafe.Pointer(&args[0]))
h.Len = len(args) h.Len = len(args)
h.Cap = cap(args) h.Cap = cap(args)
}
if err := c.c.Exec(query, iargs...); err != nil { if err := c.c.Exec(query, iargs...); err != nil {
return nil, err return nil, err
} }
...@@ -83,6 +90,9 @@ func (c *conn) RowsAffected() (int64, error) { ...@@ -83,6 +90,9 @@ func (c *conn) RowsAffected() (int64, error) {
} }
func (c *conn) Prepare(query string) (driver.Stmt, error) { func (c *conn) Prepare(query string) (driver.Stmt, error) {
if c.c.IsClosed() {
return nil, driver.ErrBadConn
}
s, err := c.c.Prepare(query) s, err := c.c.Prepare(query)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -95,6 +105,9 @@ func (c *conn) Close() error { ...@@ -95,6 +105,9 @@ func (c *conn) Close() error {
} }
func (c *conn) Begin() (driver.Tx, error) { func (c *conn) Begin() (driver.Tx, error) {
if c.c.IsClosed() {
return nil, driver.ErrBadConn
}
if err := c.c.Begin(); err != nil { if err := c.c.Begin(); err != nil {
return nil, err return nil, err
} }
......
...@@ -32,7 +32,7 @@ func (c *Conn) IntegrityCheck(dbName string, max int, quick bool) error { ...@@ -32,7 +32,7 @@ func (c *Conn) IntegrityCheck(dbName string, max int, quick bool) error {
return err return err
} }
if msg != "ok" { if msg != "ok" {
return c.specificError("Integrity check failed on %q (%s)", dbName, msg) return c.specificError("integrity check failed on %q (%s)", dbName, msg)
} }
return nil return nil
} }
......
...@@ -64,7 +64,7 @@ type Errno int ...@@ -64,7 +64,7 @@ type Errno int
func (e Errno) Error() string { func (e Errno) Error() string {
var s string var s string
if e == ErrSpecific { if e == ErrSpecific {
s = "Wrapper specific error" s = "wrapper specific error"
} else { } else {
s = C.GoString(C.sqlite3_errstr(C.int(e))) // thread safe s = C.GoString(C.sqlite3_errstr(C.int(e))) // thread safe
} }
......
...@@ -159,7 +159,7 @@ func (s *Stmt) exec() error { ...@@ -159,7 +159,7 @@ func (s *Stmt) exec() error {
err := Errno(rv) err := Errno(rv)
if err != Done { if err != Done {
if err == Row { if err == Row {
return s.specificError("Don't use exec with anything that returns data such as SELECT") return s.specificError("don't use exec with anything that returns data such as %q", s.SQL())
} }
return s.error(rv, "Stmt.exec") return s.error(rv, "Stmt.exec")
} }
......
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