mirror of https://github.com/mattn/go-sqlite3.git
Test read-only databases
This commit is contained in:
parent
a3efcea001
commit
5674e19d05
|
@ -83,6 +83,27 @@ func TestOpen(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadonly(t *testing.T) {
|
||||||
|
tempFilename := TempFilename(t)
|
||||||
|
defer os.Remove(tempFilename)
|
||||||
|
|
||||||
|
db1, err := sql.Open("sqlite3", "file:" + tempFilename)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
db1.Exec("CREATE TABLE test (x int, y float)")
|
||||||
|
|
||||||
|
db2, err := sql.Open("sqlite3", "file:" + tempFilename + "?mode=ro")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_ = db2
|
||||||
|
_, err = db2.Exec("INSERT INTO test VALUES (1, 3.14)")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("didn't expect INSERT into read-only database to work")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClose(t *testing.T) {
|
func TestClose(t *testing.T) {
|
||||||
tempFilename := TempFilename(t)
|
tempFilename := TempFilename(t)
|
||||||
db, err := sql.Open("sqlite3", tempFilename)
|
db, err := sql.Open("sqlite3", tempFilename)
|
||||||
|
|
Loading…
Reference in New Issue