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
dd971ca9
Commit
dd971ca9
authored
Apr 20, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improves tests coverage.
parent
eb69bb64
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
6 deletions
+70
-6
blob_test.go
blob_test.go
+7
-0
function_test.go
function_test.go
+3
-0
meta_test.go
meta_test.go
+6
-0
sqlite.go
sqlite.go
+12
-4
sqlite_test.go
sqlite_test.go
+24
-2
trace_test.go
trace_test.go
+18
-0
No files found.
blob_test.go
View file @
dd971ca9
...
...
@@ -32,6 +32,10 @@ func TestBlob(t *testing.T) {
content
:=
[]
byte
(
"Clob"
)
n
,
err
:=
bw
.
Write
(
content
)
checkNoError
(
t
,
err
,
"blob write error: %s"
)
//bw.Close()
err
=
bw
.
Reopen
(
rowid
)
checkNoError
(
t
,
err
,
"blob reopen error: %s"
)
bw
.
Close
()
br
,
err
:=
db
.
NewBlobReader
(
"main"
,
"test"
,
"content"
,
rowid
)
...
...
@@ -52,6 +56,9 @@ func TestBlob(t *testing.T) {
n
,
err
=
br
.
Read
(
content
[
10
:
])
assert
(
t
,
"error expected"
,
n
==
0
&&
err
==
io
.
EOF
)
err
=
br
.
Reopen
(
rowid
)
checkNoError
(
t
,
err
,
"blob reopen error: %s"
)
br
.
Close
()
}
...
...
function_test.go
View file @
dd971ca9
...
...
@@ -145,6 +145,9 @@ func TestSumFunction(t *testing.T) {
err
=
db
.
OneValue
(
"select mysum(i) from (select 2 as i union all select 2)"
,
&
i
)
checkNoError
(
t
,
err
,
"couldn't execute statement: %s"
)
assertEquals
(
t
,
"expected %d but got %v"
,
4
,
i
)
err
=
db
.
CreateAggregateFunction
(
"mysum"
,
1
,
nil
,
nil
,
nil
,
nil
)
checkNoError
(
t
,
err
,
"couldn't unregister function: %s"
)
}
func
randomFill
(
db
*
Conn
,
n
int
)
{
...
...
meta_test.go
View file @
dd971ca9
...
...
@@ -55,6 +55,9 @@ func TestColumns(t *testing.T) {
}
column
:=
columns
[
2
]
assertEquals
(
t
,
"wrong column name: %q <> %q"
,
"int_num"
,
column
.
Name
)
columns
,
err
=
db
.
Columns
(
"main"
,
"test"
)
checkNoError
(
t
,
err
,
"error listing columns: %s"
)
}
func
TestColumn
(
t
*
testing
.
T
)
{
...
...
@@ -67,6 +70,9 @@ func TestColumn(t *testing.T) {
assertEquals
(
t
,
"wrong column name: %q <> %q"
,
"id"
,
column
.
Name
)
assert
(
t
,
"expecting primary key flag to be true"
,
column
.
Pk
)
assert
(
t
,
"expecting autoinc flag to be false"
,
!
column
.
Autoinc
)
column
,
err
=
db
.
Column
(
"main"
,
"test"
,
"id"
)
checkNoError
(
t
,
err
,
"error getting column metadata: %s"
)
}
func
TestForeignKeys
(
t
*
testing
.
T
)
{
...
...
sqlite.go
View file @
dd971ca9
...
...
@@ -535,8 +535,12 @@ func (c *Conn) Close() error {
// EnableLoadExtension enables or disables extension loading.
// (See http://sqlite.org/c3ref/enable_load_extension.html)
func
(
c
*
Conn
)
EnableLoadExtension
(
b
bool
)
{
C
.
sqlite3_enable_load_extension
(
c
.
db
,
btocint
(
b
))
func
(
c
*
Conn
)
EnableLoadExtension
(
b
bool
)
error
{
rv
:=
C
.
sqlite3_enable_load_extension
(
c
.
db
,
btocint
(
b
))
if
rv
==
C
.
SQLITE_OK
{
return
nil
}
return
c
.
error
(
rv
,
"Conn.EnableLoadExtension"
)
}
// LoadExtension loads an extension
...
...
@@ -560,8 +564,12 @@ func (c *Conn) LoadExtension(file string, proc ...string) error {
// EnableSharedCache enables or disables shared pager cache
// (See http://sqlite.org/c3ref/enable_shared_cache.html)
func
EnableSharedCache
(
b
bool
)
{
C
.
sqlite3_enable_shared_cache
(
btocint
(
b
))
func
EnableSharedCache
(
b
bool
)
error
{
rv
:=
C
.
sqlite3_enable_shared_cache
(
btocint
(
b
))
if
rv
==
C
.
SQLITE_OK
{
return
nil
}
return
Errno
(
rv
)
}
// Must is a helper that wraps a call to a function returning (bool, os.Error)
...
...
sqlite_test.go
View file @
dd971ca9
...
...
@@ -56,6 +56,11 @@ func TestOpen(t *testing.T) {
checkNoError
(
t
,
db
.
Close
(),
"Error closing database: %s"
)
}
func
TestOpenFailure
(
t
*
testing
.
T
)
{
db
,
err
:=
Open
(
"doesnotexist.sqlite"
,
OpenReadOnly
)
assert
(
t
,
"open failure expected"
,
db
==
nil
&&
err
!=
nil
)
}
func
TestEnableFKey
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
...
...
@@ -96,6 +101,10 @@ func TestTransaction(t *testing.T) {
t
.
Fatalf
(
"Error expected (transaction cannot be nested)"
)
}
checkNoError
(
t
,
db
.
Commit
(),
"Error while commiting transaction: %s"
)
checkNoError
(
t
,
db
.
BeginTransaction
(
Immediate
),
"Error while beginning immediate transaction: %s"
)
checkNoError
(
t
,
db
.
Commit
(),
"Error while commiting transaction: %s"
)
checkNoError
(
t
,
db
.
BeginTransaction
(
Exclusive
),
"Error while beginning immediate transaction: %s"
)
checkNoError
(
t
,
db
.
Commit
(),
"Error while commiting transaction: %s"
)
}
func
TestSavepoint
(
t
*
testing
.
T
)
{
...
...
@@ -205,14 +214,27 @@ func TestConnInitialState(t *testing.T) {
assert
(
t
,
"readonly expected to be unset by default"
,
!
readonly
)
}
func
TestReadonlyMisuse
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
_
,
err
:=
db
.
Readonly
(
"doesnotexist"
)
assert
(
t
,
"error expected"
,
err
!=
nil
)
err
.
Error
()
}
func
TestConnSettings
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
db
.
EnableLoadExtension
(
false
)
err
:=
db
.
SetRecursiveTriggers
(
"main"
,
true
)
err
:=
db
.
EnableLoadExtension
(
false
)
checkNoError
(
t
,
err
,
"EnableLoadExtension error: %s"
)
err
=
db
.
SetRecursiveTriggers
(
"main"
,
true
)
checkNoError
(
t
,
err
,
"SetRecursiveTriggers error: %s"
)
}
func
TestComplete
(
t
*
testing
.
T
)
{
assert
(
t
,
"expected complete statement"
,
Complete
(
"select 1;"
))
}
func
assertEquals
(
t
*
testing
.
T
,
format
string
,
expected
,
actual
interface
{})
{
if
expected
!=
actual
{
t
.
Errorf
(
format
,
expected
,
actual
)
...
...
trace_test.go
View file @
dd971ca9
...
...
@@ -19,6 +19,24 @@ func init() {
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"cannot activate mem status: '%s'"
,
err
))
}
err
=
ConfigUri
(
true
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"cannot activate uri handling: '%s'"
,
err
))
}
err
=
ConfigLog
(
func
(
d
interface
{},
err
error
,
msg
string
)
{
fmt
.
Printf
(
"%s: %s, %s
\n
"
,
d
,
err
,
msg
)
},
"SQLITE"
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"couldn't config log: '%s'"
,
err
))
}
err
=
ConfigLog
(
nil
,
""
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"couldn't unset logger: '%s'"
,
err
))
}
err
=
EnableSharedCache
(
false
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"couldn't disable shared cache: '%s'"
,
err
))
}
}
func
trace
(
d
interface
{},
sql
string
)
{
...
...
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