Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
7321b68b
Commit
7321b68b
authored
Mar 04, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test Blob misuse.
parent
07b37a71
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
42 deletions
+62
-42
backup.go
backup.go
+0
-3
backup_test.go
backup_test.go
+0
-1
blob.go
blob.go
+3
-0
blob_test.go
blob_test.go
+59
-0
sqlite_test.go
sqlite_test.go
+0
-38
No files found.
backup.go
View file @
7321b68b
...
...
@@ -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
))}
}
...
...
backup_test.go
View file @
7321b68b
...
...
@@ -41,5 +41,4 @@ func TestBackupMisuse(t *testing.T) {
if
err
==
nil
{
t
.
Error
(
"Misuse expected"
)
}
bck
.
Status
()
}
blob.go
View file @
7321b68b
...
...
@@ -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
)
...
...
blob_test.go
0 → 100644
View file @
7321b68b
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"
)
}
}
sqlite_test.go
View file @
7321b68b
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment