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
288d5a3f
Commit
288d5a3f
authored
Mar 22, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce checkStep in tests.
parent
d8830656
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
61 deletions
+39
-61
function_test.go
function_test.go
+3
-9
meta.go
meta.go
+4
-0
sqlite_test.go
sqlite_test.go
+2
-4
stmt_test.go
stmt_test.go
+30
-48
No files found.
function_test.go
View file @
288d5a3f
...
...
@@ -79,25 +79,19 @@ func TestRegexpFunction(t *testing.T) {
checkNoError
(
t
,
err
,
"couldn't prepare statement: %s"
)
defer
checkFinalize
(
s
,
t
)
if
b
:=
Must
(
s
.
Next
());
!
b
{
t
.
Fatalf
(
"No result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
i
,
_
,
err
:=
s
.
ScanInt
(
0
)
checkNoError
(
t
,
err
,
"couldn't scan result: %s"
)
assert
.
Equal
(
t
,
1
,
i
)
assert
.
T
(
t
,
!
reused
,
"unexpected reused state"
)
if
b
:=
Must
(
s
.
Next
());
!
b
{
t
.
Fatalf
(
"No result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
i
,
_
,
err
=
s
.
ScanInt
(
0
)
checkNoError
(
t
,
err
,
"couldn't scan result: %s"
)
assert
.
Equal
(
t
,
0
,
i
)
assert
.
T
(
t
,
reused
,
"unexpected reused state"
)
if
b
:=
Must
(
s
.
Next
());
!
b
{
t
.
Fatalf
(
"No result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
i
,
_
,
err
=
s
.
ScanInt
(
0
)
checkNoError
(
t
,
err
,
"couldn't scan result: %s"
)
assert
.
Equal
(
t
,
0
,
i
)
...
...
meta.go
View file @
288d5a3f
...
...
@@ -140,6 +140,7 @@ type Column struct {
// Columns returns a description for each column in the named table/view.
// Column.Autoinc and Column.CollSeq are left unspecified.
// No error is returned if the table does not exist.
// (See http://www.sqlite.org/pragma.html#pragma_table_info)
func
(
c
*
Conn
)
Columns
(
dbName
,
table
string
)
([]
Column
,
error
)
{
var
pragma
string
...
...
@@ -280,6 +281,7 @@ type ForeignKey struct {
}
// ForeignKeys returns one description for each foreign key that references a column in the argument table.
// No error is returned if the table does not exist.
// (See http://www.sqlite.org/pragma.html#pragma_foreign_key_list)
func
(
c
*
Conn
)
ForeignKeys
(
dbName
,
table
string
)
(
map
[
int
]
*
ForeignKey
,
error
)
{
var
pragma
string
...
...
@@ -324,6 +326,7 @@ type Index struct {
}
// TableIndexes returns one description for each index associated with the given table.
// No error is returned if the table does not exist.
// (See http://www.sqlite.org/pragma.html#pragma_index_list)
func
(
c
*
Conn
)
TableIndexes
(
dbName
,
table
string
)
([]
Index
,
error
)
{
var
pragma
string
...
...
@@ -354,6 +357,7 @@ func (c *Conn) TableIndexes(dbName, table string) ([]Index, error) {
// IndexColumns returns one description for each column in the named index.
// Only Column.Cid and Column.Name are specified. All other fields are unspecified.
// No error is returned if the index does not exist.
// (See http://www.sqlite.org/pragma.html#pragma_index_info)
func
(
c
*
Conn
)
IndexColumns
(
dbName
,
index
string
)
([]
Column
,
error
)
{
var
pragma
string
...
...
sqlite_test.go
View file @
288d5a3f
...
...
@@ -149,14 +149,12 @@ func TestInsert(t *testing.T) {
columnCount
:=
cs
.
ColumnCount
()
assert
.
Equal
(
t
,
1
,
columnCount
,
"column count"
)
if
!
Must
(
cs
.
Next
())
{
t
.
Fatal
(
"no result for count"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
cs
))
assert
.
Equal
(
t
,
columnCount
,
cs
.
DataCount
(),
"column & data count expected to be equal"
)
var
i
int
checkNoError
(
t
,
cs
.
Scan
(
&
i
),
"error scanning count: %s"
)
assert
.
Equal
(
t
,
1000
,
i
,
"count"
)
if
Must
(
cs
.
Next
()
)
{
if
checkStep
(
t
,
cs
)
{
t
.
Fatal
(
"Only one row expected"
)
}
assert
.
T
(
t
,
!
cs
.
Busy
(),
"expected statement to be reset"
)
...
...
stmt_test.go
View file @
288d5a3f
...
...
@@ -5,9 +5,12 @@
package
sqlite_test
import
(
"fmt"
"math"
"os"
"path"
"reflect"
"runtime"
"testing"
"time"
"unsafe"
...
...
@@ -20,6 +23,15 @@ func checkFinalize(s *Stmt, t *testing.T) {
checkNoError
(
t
,
s
.
Finalize
(),
"Error finalizing statement: %s"
)
}
func
checkStep
(
t
*
testing
.
T
,
s
*
Stmt
)
bool
{
b
,
err
:=
s
.
Next
()
if
err
!=
nil
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
t
.
Fatalf
(
"
\n
%s:%d: %s"
,
path
.
Base
(
file
),
line
,
fmt
.
Sprintf
(
"step error: %s"
,
err
))
}
return
b
}
func
TestInsertWithStatement
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
...
...
@@ -57,9 +69,7 @@ func TestInsertWithStatement(t *testing.T) {
cs
,
_
:=
db
.
Prepare
(
"SELECT COUNT(*) FROM test"
)
defer
checkFinalize
(
cs
,
t
)
assert
.
T
(
t
,
cs
.
ReadOnly
(),
"SELECT statement should be readonly"
)
if
!
Must
(
cs
.
Next
())
{
t
.
Fatal
(
"no result for count"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
cs
))
var
i
int
checkNoError
(
t
,
cs
.
Scan
(
&
i
),
"error scanning count: %s"
)
assert
.
Equal
(
t
,
1000
,
i
,
"count"
)
...
...
@@ -71,7 +81,7 @@ func TestInsertWithStatement(t *testing.T) {
secondColumnName
:=
rs
.
ColumnName
(
1
)
assert
.
Equal
(
t
,
"int_num"
,
secondColumnName
,
"column name"
)
if
Must
(
rs
.
Next
()
)
{
if
checkStep
(
t
,
rs
)
{
var
fnum
float64
var
inum
int64
var
sstr
string
...
...
@@ -80,7 +90,7 @@ func TestInsertWithStatement(t *testing.T) {
assert
.
Equal
(
t
,
int64
(
0
),
inum
)
assert
.
Equal
(
t
,
"hello"
,
sstr
)
}
if
Must
(
rs
.
Next
()
)
{
if
checkStep
(
t
,
rs
)
{
var
fnum
float64
var
inum
int64
var
sstr
string
...
...
@@ -101,9 +111,7 @@ func TestScanColumn(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 1, null, 0"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
i1
,
i2
,
i3
int
null
:=
Must
(
s
.
ScanByIndex
(
0
,
&
i1
))
assert
.
T
(
t
,
!
null
,
"expected not null value"
)
...
...
@@ -127,9 +135,7 @@ func TestNamedScanColumn(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 1 AS i1, null AS i2, 0 AS i3"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
i1
,
i2
,
i3
int
null
:=
Must
(
s
.
ScanByName
(
"i1"
,
&
i1
))
assert
.
T
(
t
,
!
null
,
"expected not null value"
)
...
...
@@ -161,9 +167,7 @@ func TestScanCheck(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 'hello'"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
i
int
_
,
err
=
s
.
ScanByIndex
(
0
,
&
i
)
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
...
...
@@ -182,9 +186,7 @@ func TestScanNull(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT null"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
pi
=
new
(
int
)
null
:=
Must
(
s
.
ScanByIndex
(
0
,
&
pi
))
assert
.
T
(
t
,
null
,
"expected null value"
)
...
...
@@ -232,9 +234,7 @@ func TestScanNotNull(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 1"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
pi
=
new
(
int
)
null
:=
Must
(
s
.
ScanByIndex
(
0
,
&
pi
))
assert
.
T
(
t
,
!
null
,
"expected not null value"
)
...
...
@@ -263,9 +263,7 @@ func TestScanError(t *testing.T) {
s, err := db.Prepare("SELECT 1")
checkNoError(t, err, "prepare error: %s")
defer checkFinalize(s, t)
if !Must(s.Next()) {
t.Fatal("no result")
}
assert.T(t, checkStep(t, s))
var pi *int
null, err := s.ScanByIndex(0, &pi)
t.Errorf("(%t,%s)", null, err)
...
...
@@ -407,8 +405,7 @@ func TestNamedBind(t *testing.T) {
var
byt
byte
=
'!'
err
=
is
.
NamedBind
(
":b"
,
byt
,
":blob"
,
blob
)
checkNoError
(
t
,
err
,
"named bind error: %s"
)
_
,
err
=
is
.
Next
()
checkNoError
(
t
,
err
,
"named bind step error: %s"
)
checkStep
(
t
,
is
)
err
=
is
.
NamedBind
(
":b"
,
byt
,
":invalid"
,
nil
)
assert
.
T
(
t
,
err
!=
nil
,
"invalid param name expected"
)
...
...
@@ -423,9 +420,7 @@ func TestNamedBind(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT data AS bs, byte AS b FROM test"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
bs
[]
byte
var
b
byte
err
=
s
.
NamedScan
(
"b"
,
&
b
,
"bs"
,
&
bs
)
...
...
@@ -450,8 +445,7 @@ func TestBind(t *testing.T) {
checkNoError
(
t
,
err
,
"prepare error: %s"
)
err
=
is
.
Bind
(
nil
,
true
)
checkNoError
(
t
,
err
,
"bind error: %s"
)
_
,
err
=
is
.
Next
()
checkNoError
(
t
,
err
,
"step error: %s"
)
checkStep
(
t
,
is
)
err
=
is
.
Bind
(
int32
(
1
),
float32
(
273.1
))
checkNoError
(
t
,
err
,
"bind error: %s"
)
...
...
@@ -490,9 +484,7 @@ func TestScanValues(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 1, null, 0"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
values
:=
make
([]
interface
{},
3
)
s
.
ScanValues
(
values
)
assert
.
Equal
(
t
,
int64
(
1
),
values
[
0
])
...
...
@@ -507,9 +499,7 @@ func TestScanBytes(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 'test'"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
blob
,
_
:=
s
.
ScanBlob
(
0
)
assert
.
Equal
(
t
,
"test"
,
string
(
blob
))
}
...
...
@@ -522,9 +512,7 @@ func TestBindEmptyZero(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT ?, ?"
,
""
,
zero
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
ps
*
string
var
zt
time
.
Time
...
...
@@ -552,9 +540,7 @@ func TestBindEmptyZeroNotTransformedToNull(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT ?, ?"
,
""
,
zero
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
st
string
var
zt
time
.
Time
...
...
@@ -628,9 +614,7 @@ func TestBindAndScanReflect(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 1"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
ok
,
err
:=
s
.
Next
()
checkNoError
(
t
,
err
,
"step error: %s"
)
assert
.
T
(
t
,
ok
)
assert
.
T
(
t
,
checkStep
(
t
,
s
))
is
,
err
:=
db
.
Prepare
(
"SELECT ?"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
...
...
@@ -680,9 +664,7 @@ func TestBindAndScanReflect(t *testing.T) {
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
)
assert
.
T
(
t
,
checkStep
(
t
,
is
))
_
,
err
=
is
.
ScanReflect
(
0
,
&
enum
)
assert
.
T
(
t
,
err
!=
nil
)
...
...
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