Commit 7321b68b authored by gwenn's avatar gwenn

Test Blob misuse.

parent 07b37a71
......@@ -76,9 +76,6 @@ type BackupStatus struct {
// Return the number of pages still to be backed up and the total number of pages in the source database file.
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupremaining)
func (b *Backup) Status() BackupStatus {
if b == nil {
return BackupStatus{}
}
return BackupStatus{int(C.sqlite3_backup_remaining(b.sb)), int(C.sqlite3_backup_pagecount(b.sb))}
}
......
......@@ -41,5 +41,4 @@ func TestBackupMisuse(t *testing.T) {
if err == nil {
t.Error("Misuse expected")
}
bck.Status()
}
......@@ -93,6 +93,9 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
// Close a BLOB handle
// (See http://sqlite.org/c3ref/blob_close.html)
func (r *BlobReader) Close() error {
if r == nil {
return errors.New("nil sqlite blob reader")
}
rv := C.sqlite3_blob_close(r.bl)
if rv != C.SQLITE_OK {
return r.c.error(rv)
......
package sqlite_test
import (
. "github.com/gwenn/gosqlite"
"testing"
)
func TestBlob(t *testing.T) {
db := open(t)
defer db.Close()
err := db.Exec("CREATE TABLE test (content BLOB);")
checkNoError(t, err, "error creating table: %s")
s, err := db.Prepare("INSERT INTO test VALUES (?)")
checkNoError(t, err, "prepare error: %s")
if s == nil {
t.Fatal("statement is nil")
}
defer s.Finalize()
err = s.Exec(ZeroBlobLength(10))
checkNoError(t, err, "insert error: %s")
rowid := db.LastInsertRowid()
bw, err := db.NewBlobReadWriter("main", "test", "content", rowid)
checkNoError(t, err, "blob open error: %s")
defer bw.Close()
content := []byte("Clob")
n, err := bw.Write(content)
checkNoError(t, err, "blob write error: %s")
br, err := db.NewBlobReader("main", "test", "content", rowid)
checkNoError(t, err, "blob open error: %s")
defer br.Close()
size, err := br.Size()
checkNoError(t, err, "blob size error: %s")
content = make([]byte, size)
n, err = br.Read(content)
checkNoError(t, err, "blob read error: %s")
if n != 10 {
t.Fatalf("Expected 10 bytes but got %d", n)
}
//fmt.Printf("%#v\n", content)
br.Close()
}
func TestBlobMisuse(t *testing.T) {
db := open(t)
defer db.Close()
bw, err := db.NewBlobReadWriter("main", "test", "content", 0)
//t.Logf("%#v", err)
if bw != nil || err == nil {
t.Errorf("error expected")
}
err = bw.Close()
if err == nil {
t.Errorf("error expected")
}
}
......@@ -245,44 +245,6 @@ func TestInsertWithStatement(t *testing.T) {
}
}
func TestBlob(t *testing.T) {
db := open(t)
defer db.Close()
err := db.Exec("CREATE TABLE test (content BLOB);")
checkNoError(t, err, "error creating table: %s")
s, err := db.Prepare("INSERT INTO test VALUES (?)")
checkNoError(t, err, "prepare error: %s")
if s == nil {
t.Fatal("statement is nil")
}
defer s.Finalize()
err = s.Exec(ZeroBlobLength(10))
checkNoError(t, err, "insert error: %s")
rowid := db.LastInsertRowid()
bw, err := db.NewBlobReadWriter("main", "test", "content", rowid)
checkNoError(t, err, "blob open error: %s")
defer bw.Close()
content := []byte("Clob")
n, err := bw.Write(content)
checkNoError(t, err, "blob write error: %s")
br, err := db.NewBlobReader("main", "test", "content", rowid)
checkNoError(t, err, "blob open error: %s")
defer br.Close()
size, err := br.Size()
checkNoError(t, err, "blob size error: %s")
content = make([]byte, size)
n, err = br.Read(content)
checkNoError(t, err, "blob read error: %s")
if n != 10 {
t.Fatalf("Expected 10 bytes but got %d", n)
}
//fmt.Printf("%#v\n", content)
br.Close()
}
func TestScanColumn(t *testing.T) {
db := open(t)
defer db.Close()
......
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