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) {
switch whence {
case 0: // SEEK_SET
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)
case 1: // SEEK_CUR
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)
case 2: // SEEK_END
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)
default:
return 0, r.c.specificError("Bad seekMode: %d", whence)
return 0, r.c.specificError("bad seekMode: %d", whence)
}
return int64(r.offset), nil
}
......
......@@ -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
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
var iargs []interface{}
if len(args) > 0 {
h := (*reflect.SliceHeader)(unsafe.Pointer(&iargs))
h.Data = uintptr(unsafe.Pointer(&args[0]))
h.Len = len(args)
h.Cap = cap(args)
}
h := (*reflect.SliceHeader)(unsafe.Pointer(&iargs))
h.Data = uintptr(unsafe.Pointer(&args[0]))
h.Len = len(args)
h.Cap = cap(args)
if err := c.c.Exec(query, iargs...); err != nil {
return nil, err
}
......@@ -83,6 +90,9 @@ func (c *conn) RowsAffected() (int64, error) {
}
func (c *conn) Prepare(query string) (driver.Stmt, error) {
if c.c.IsClosed() {
return nil, driver.ErrBadConn
}
s, err := c.c.Prepare(query)
if err != nil {
return nil, err
......@@ -95,6 +105,9 @@ func (c *conn) Close() error {
}
func (c *conn) Begin() (driver.Tx, error) {
if c.c.IsClosed() {
return nil, driver.ErrBadConn
}
if err := c.c.Begin(); err != nil {
return nil, err
}
......
......@@ -32,7 +32,7 @@ func (c *Conn) IntegrityCheck(dbName string, max int, quick bool) error {
return err
}
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
}
......
......@@ -64,7 +64,7 @@ type Errno int
func (e Errno) Error() string {
var s string
if e == ErrSpecific {
s = "Wrapper specific error"
s = "wrapper specific error"
} else {
s = C.GoString(C.sqlite3_errstr(C.int(e))) // thread safe
}
......
......@@ -159,7 +159,7 @@ func (s *Stmt) exec() error {
err := Errno(rv)
if err != Done {
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")
}
......
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