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
757b392d
Commit
757b392d
authored
Mar 17, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve test coverage.
parent
e36e5888
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
125 additions
and
11 deletions
+125
-11
blob_test.go
blob_test.go
+16
-1
date_test.go
date_test.go
+2
-3
driver_test.go
driver_test.go
+9
-2
meta_test.go
meta_test.go
+25
-0
pragma_test.go
pragma_test.go
+22
-0
sqlite.go
sqlite.go
+1
-1
sqlite_test.go
sqlite_test.go
+12
-2
stmt_test.go
stmt_test.go
+38
-2
No files found.
blob_test.go
View file @
757b392d
...
...
@@ -65,7 +65,22 @@ func TestBlob(t *testing.T) {
_
,
err
=
br
.
Seek
(
0
,
os
.
SEEK_SET
)
checkNoError
(
t
,
err
,
"blob seek error: %s"
)
br
.
Close
()
err
=
br
.
Reopen
(
-
1
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
n
,
err
=
br
.
Read
(
nil
)
checkNoError
(
t
,
err
,
"blob read error: %s"
)
assert
.
Equal
(
t
,
0
,
n
)
_
,
err
=
br
.
Read
(
content
)
assert
.
T
(
t
,
err
!=
nil
)
err
=
br
.
Close
()
checkNoError
(
t
,
err
,
"blob close error: %s"
)
_
,
err
=
br
.
Size
()
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestBlobMisuse
(
t
*
testing
.
T
)
{
...
...
date_test.go
View file @
757b392d
...
...
@@ -5,7 +5,6 @@
package
sqlite_test
import
(
"fmt"
"testing"
"time"
...
...
@@ -207,8 +206,8 @@ func TestTimeStamp(t *testing.T) {
var
ts
TimeStamp
err
=
db
.
OneValue
(
"SELECT time FROM test where ROWID = ?"
,
&
ts
,
id
)
checkNoError
(
t
,
err
,
"error selecting TimeStamp: %s"
)
fmt
.
Printf
(
"%v (%d) <=> %v (%d)
\n
"
,
now
,
now
.
Unix
(),
time
.
Time
(
ts
),
time
.
Time
(
ts
)
.
Unix
())
//assert.Equal(t
, now, time.Time(ts))
//
fmt.Printf("%v (%d) <=> %v (%d)\n", now, now.Unix(), time.Time(ts), time.Time(ts).Unix())
assert
.
Tf
(
t
,
now
==
time
.
Time
(
ts
),
"got %s; want %s"
,
now
,
time
.
Time
(
ts
))
err
=
db
.
OneValue
(
"SELECT null"
,
&
ts
)
checkNoError
(
t
,
err
,
"%s"
)
...
...
driver_test.go
View file @
757b392d
...
...
@@ -6,7 +6,6 @@ package sqlite_test
import
(
"database/sql"
"fmt"
"math/rand"
"testing"
"time"
...
...
@@ -55,6 +54,13 @@ func sqlCreate(ddl string, t *testing.T) *sql.DB {
func
TestSqlOpen
(
t
*
testing
.
T
)
{
db
:=
sqlOpen
(
t
)
checkNoError
(
t
,
db
.
Close
(),
"Error closing database: %s"
)
db
,
err
:=
sql
.
Open
(
"sqlite3"
,
"file:data.db?mode=readonly"
)
checkNoError
(
t
,
err
,
"Error opening database: %s"
)
defer
checkSqlDbClose
(
db
,
t
)
err
=
db
.
Ping
()
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
}
func
TestSqlDdl
(
t
*
testing
.
T
)
{
...
...
@@ -243,8 +249,9 @@ func TestScanNumericalAsTime(t *testing.T) {
var
ms
time
.
Time
err
=
row
.
Scan
(
&
ms
)
checkNoError
(
t
,
err
,
"%s"
)
fmt
.
Printf
(
"%v (%d) <=> %v (%d)
\n
"
,
now
,
now
.
Unix
(),
ms
,
ms
.
Unix
())
//
fmt.Printf("%v (%d) <=> %v (%d)\n", now, now.Unix(), ms, ms.Unix())
//assert.Equal(t, now, ms)
assert
.
Tf
(
t
,
now
==
ms
,
"got %s; want %s"
,
now
,
ms
)
_
,
err
=
db
.
Exec
(
"DELETE FROM test; INSERT INTO test VALUES (?)"
,
"bim"
)
checkNoError
(
t
,
err
,
"%s"
)
...
...
meta_test.go
View file @
757b392d
...
...
@@ -70,6 +70,9 @@ func TestViews(t *testing.T) {
views
,
err
=
db
.
Views
(
""
,
true
)
checkNoError
(
t
,
err
,
"error looking for views: %s"
)
assert
.
Equal
(
t
,
0
,
len
(
views
),
"table count"
)
_
,
err
=
db
.
Views
(
"bim"
,
false
)
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestIndexes
(
t
*
testing
.
T
)
{
...
...
@@ -87,6 +90,12 @@ func TestIndexes(t *testing.T) {
indexes
,
err
=
db
.
Indexes
(
"main"
,
false
)
checkNoError
(
t
,
err
,
"error looking for indexes: %s"
)
_
,
err
=
db
.
Indexes
(
""
,
true
)
checkNoError
(
t
,
err
,
"error looking for indexes: %s"
)
_
,
err
=
db
.
Indexes
(
"bim"
,
false
)
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestColumns
(
t
*
testing
.
T
)
{
...
...
@@ -153,6 +162,14 @@ func TestForeignKeys(t *testing.T) {
fks
,
err
=
db
.
ForeignKeys
(
"main"
,
"child"
)
checkNoError
(
t
,
err
,
"error listing FKs: %s"
)
_
,
err
=
db
.
ForeignKeys
(
"bim"
,
"child"
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
_
,
err
=
db
.
ForeignKeys
(
""
,
"bim"
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
}
func
TestTableIndexes
(
t
*
testing
.
T
)
{
...
...
@@ -182,6 +199,14 @@ func TestTableIndexes(t *testing.T) {
checkNoError
(
t
,
err
,
"error listing indexes: %s"
)
columns
,
err
=
db
.
IndexColumns
(
"main"
,
"test_index"
)
checkNoError
(
t
,
err
,
"error listing index columns: %s"
)
_
,
err
=
db
.
TableIndexes
(
"bim"
,
"test"
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
_
,
err
=
db
.
IndexColumns
(
"bim"
,
"test_index"
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
}
func
TestColumnMetadata
(
t
*
testing
.
T
)
{
...
...
pragma_test.go
View file @
757b392d
...
...
@@ -17,6 +17,9 @@ func TestIntegrityCheck(t *testing.T) {
defer
checkClose
(
db
,
t
)
checkNoError
(
t
,
db
.
IntegrityCheck
(
""
,
1
,
true
),
"Error checking integrity of database: %s"
)
checkNoError
(
t
,
db
.
IntegrityCheck
(
""
,
1
,
false
),
"Error checking integrity of database: %s"
)
err
:=
db
.
IntegrityCheck
(
"bim"
,
1
,
true
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
}
func
TestEncoding
(
t
*
testing
.
T
)
{
...
...
@@ -25,6 +28,9 @@ func TestEncoding(t *testing.T) {
encoding
,
err
:=
db
.
Encoding
(
""
)
checkNoError
(
t
,
err
,
"Error reading encoding of database: %s"
)
assert
.
Equal
(
t
,
"UTF-8"
,
encoding
)
_
,
err
=
db
.
Encoding
(
"bim"
)
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestSchemaVersion
(
t
*
testing
.
T
)
{
...
...
@@ -41,6 +47,9 @@ func TestJournalMode(t *testing.T) {
mode
,
err
:=
db
.
JournalMode
(
""
)
checkNoError
(
t
,
err
,
"Error reading journaling mode of database: %s"
)
assert
.
Equal
(
t
,
"memory"
,
mode
)
_
,
err
=
db
.
JournalMode
(
"bim"
)
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestSetJournalMode
(
t
*
testing
.
T
)
{
...
...
@@ -49,6 +58,10 @@ func TestSetJournalMode(t *testing.T) {
mode
,
err
:=
db
.
SetJournalMode
(
""
,
"OFF"
)
checkNoError
(
t
,
err
,
"Error setting journaling mode of database: %s"
)
assert
.
Equal
(
t
,
"off"
,
mode
)
_
,
err
=
db
.
SetJournalMode
(
"bim"
,
"OFF"
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
}
func
TestLockingMode
(
t
*
testing
.
T
)
{
...
...
@@ -73,6 +86,9 @@ func TestSynchronous(t *testing.T) {
mode
,
err
:=
db
.
Synchronous
(
""
)
checkNoError
(
t
,
err
,
"Error reading synchronous flag of database: %s"
)
assert
.
Equal
(
t
,
2
,
mode
)
_
,
err
=
db
.
Synchronous
(
"bim"
)
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestSetSynchronous
(
t
*
testing
.
T
)
{
...
...
@@ -99,6 +115,9 @@ func TestQueryOnly(t *testing.T) {
err
=
db
.
Exec
(
"CREATE TABLE test (data TEXT)"
)
assert
.
T
(
t
,
err
!=
nil
,
"expected error"
)
//println(err.Error())
_
,
err
=
db
.
QueryOnly
(
"bim"
)
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestApplicationId
(
t
*
testing
.
T
)
{
...
...
@@ -119,6 +138,9 @@ func TestApplicationId(t *testing.T) {
appId
,
err
=
db
.
ApplicationId
(
""
)
checkNoError
(
t
,
err
,
"error getting application Id: %s"
)
assert
.
Equalf
(
t
,
123
,
appId
,
"got: %d; want: %d"
,
appId
,
123
)
_
,
err
=
db
.
ApplicationId
(
"bim"
)
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestForeignKeyCheck
(
t
*
testing
.
T
)
{
...
...
sqlite.go
View file @
757b392d
...
...
@@ -293,7 +293,7 @@ func (c *Conn) AreTriggersEnabled() (bool, error) {
func
(
c
*
Conn
)
queryOrSetEnableDbConfig
(
key
,
i
C
.
int
)
(
bool
,
error
)
{
var
ok
C
.
int
rv
:=
C
.
my_db_config
(
c
.
db
,
C
.
SQLITE_DBCONFIG_ENABLE_FKEY
,
i
,
&
ok
)
rv
:=
C
.
my_db_config
(
c
.
db
,
key
,
i
,
&
ok
)
if
rv
==
C
.
SQLITE_OK
{
return
(
ok
==
1
),
nil
}
...
...
sqlite_test.go
View file @
757b392d
...
...
@@ -311,11 +311,21 @@ func TestNilDb(t *testing.T) {
var
db
*
Conn
err
:=
db
.
Exec
(
"DROP TABLE IF EXISTS test"
)
assert
.
T
(
t
,
err
!=
nil
)
//
fmt.P
rintln(err.Error())
//
p
rintln(err.Error())
err
=
db
.
Close
()
assert
.
T
(
t
,
err
!=
nil
)
//fmt.Println(err.Error())
//println(err.Error())
err
=
db
.
LastError
()
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
_
,
err
=
db
.
ForeignKeyCheck
(
""
,
""
)
assert
.
T
(
t
,
err
!=
nil
)
_
,
err
=
db
.
Databases
()
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestError
(
t
*
testing
.
T
)
{
...
...
stmt_test.go
View file @
757b392d
...
...
@@ -468,6 +468,15 @@ func TestInsertMisuse(t *testing.T) {
_
,
err
=
is
.
Insert
()
assert
.
T
(
t
,
err
!=
nil
,
"missing bind parameters expected"
)
//db.Exec("DELETE FROM test") // to reset sqlite3_changes counter
ois
,
err
:=
db
.
Prepare
(
"PRAGMA shrink_memory"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
ois
,
t
)
rowId
,
err
:=
ois
.
Insert
()
checkNoError
(
t
,
err
,
"insert error: %s"
)
assert
.
Equal
(
t
,
int64
(
-
1
),
rowId
)
}
func
TestScanValues
(
t
*
testing
.
T
)
{
...
...
@@ -599,7 +608,7 @@ func TestBlankQuery(t *testing.T) {
_
,
err
=
s
.
SelectOneRow
()
assert
.
T
(
t
,
err
!=
nil
,
"error expected"
)
//
fmt.P
rintln(err.Error())
//
p
rintln(err.Error())
}
func
TestNilStmt
(
t
*
testing
.
T
)
{
...
...
@@ -665,6 +674,15 @@ func TestBindAndScanReflect(t *testing.T) {
assert
.
Equal
(
t
,
Amount
(
1
),
amount
)
checkNoError
(
t
,
is
.
BindReflect
(
1
,
amount
),
"bind error: %s"
)
checkNoError
(
t
,
is
.
BindReflect
(
1
,
-
1
),
"bind error: %s"
)
ok
,
err
=
is
.
Next
()
checkNoError
(
t
,
err
,
"step error: %s"
)
assert
.
T
(
t
,
ok
)
_
,
err
=
is
.
ScanReflect
(
0
,
&
enum
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
}
func
TestSelect
(
t
*
testing
.
T
)
{
...
...
@@ -679,6 +697,16 @@ func TestSelect(t *testing.T) {
return
s
.
Scan
(
nil
)
},
1
)
checkNoError
(
t
,
err
,
"select error: %s"
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
error
{
return
os
.
ErrInvalid
},
os
.
ErrInvalid
)
assert
.
T
(
t
,
err
!=
nil
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
error
{
return
os
.
ErrInvalid
},
1
)
assert
.
Equal
(
t
,
os
.
ErrInvalid
,
err
)
}
func
TestStmtCache
(
t
*
testing
.
T
)
{
...
...
@@ -691,7 +719,11 @@ func TestStmtCache(t *testing.T) {
s
,
err
=
db
.
Prepare
(
"SELECT 1 LIMIT ?"
,
0
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
s
.
Finalize
()
_
,
err
=
db
.
Prepare
(
"SELECT 1 LIMIT ?"
,
os
.
ErrInvalid
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
}
func
TestCheckTypeMismatch
(
t
*
testing
.
T
)
{
...
...
@@ -704,6 +736,10 @@ func TestCheckTypeMismatch(t *testing.T) {
//println(err.Error())
var
f
float64
err
=
db
.
OneValue
(
"SELECT 'bim'"
,
&
f
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
err
=
db
.
OneValue
(
"SELECT X'53514C697465'"
,
&
f
)
assert
.
T
(
t
,
err
!=
nil
)
//println(err.Error())
...
...
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