Start work on introducing machine-readable error codes.

This commit introduces a new type 'ErrNo', implementing the error
interface.  Constants for all sqlite3 error codes are provided
in the new source file "error.go".
This commit is contained in:
Jochen Voss
2013-06-20 21:52:38 +01:00
committed by mattn
parent ad95f5fd3d
commit ff8e6729ce
6 changed files with 93 additions and 14 deletions

34
error_test.go Normal file
View File

@@ -0,0 +1,34 @@
package sqlite3
import (
"database/sql"
"io/ioutil"
"os"
"path"
"testing"
)
func TestFailures(t *testing.T) {
dirName, err := ioutil.TempDir("", "sqlite3")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dirName)
dbFileName := path.Join(dirName, "test.db")
f, err := os.Create(dbFileName)
if err != nil {
t.Error(err)
}
f.Write([]byte{1, 2, 3, 4, 5})
f.Close()
db, err := sql.Open("sqlite3", dbFileName)
if err == nil {
_, err = db.Exec("drop table foo")
}
if err != ErrNotADB {
t.Error("wrong error code for corrupted DB")
}
db.Close()
}