memdb WAL.

This commit is contained in:
Nuno Cruces
2023-11-28 09:53:17 +00:00
parent 269306c5c8
commit b81fe284b6
4 changed files with 37 additions and 0 deletions

View File

@@ -93,6 +93,9 @@ func testDB(t testing.TB, name string) {
id := stmt.ColumnInt(0)
name := stmt.ColumnText(1)
if row >= 3 {
continue
}
if id != ids[row] {
t.Errorf("got %d, want %d", id, ids[row])
}

View File

@@ -36,6 +36,12 @@ func Create(name string, data []byte) {
db := new(memDB)
db.size = int64(len(data))
// Convert data from WAL to rollback journal.
if len(data) >= 20 && data[18] == 2 && data[19] == 2 {
data[18] = 1
data[19] = 1
}
sectors := divRoundUp(db.size, sectorSize)
db.data = make([]*[sectorSize]byte, sectors)
for i := range db.data {

28
vfs/memdb/memdb_test.go Normal file
View File

@@ -0,0 +1,28 @@
package memdb
import (
"testing"
_ "embed"
"github.com/ncruces/go-sqlite3"
_ "github.com/ncruces/go-sqlite3/embed"
)
//go:embed testdata/wal.db
var walDB []byte
func Test_wal(t *testing.T) {
Create("test.db", walDB)
db, err := sqlite3.Open("file:/test.db?vfs=memdb")
if err != nil {
t.Fatal(err)
}
defer db.Close()
err = db.Exec(`CREATE TABLE IF NOT EXISTS users (id INT, name VARCHAR(10))`)
if err != nil {
t.Fatal(err)
}
}

BIN
vfs/memdb/testdata/wal.db vendored Normal file

Binary file not shown.