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
50898ecf
Commit
50898ecf
authored
Jul 19, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds some tests.
parent
8661f631
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
3 deletions
+42
-3
sqlite.go
sqlite.go
+5
-3
sqlite_test.go
sqlite_test.go
+37
-0
No files found.
sqlite.go
View file @
50898ecf
...
...
@@ -324,9 +324,9 @@ func (s *Stmt) BindParameterIndex(name string) int {
}
func
(
s
*
Stmt
)
Bind
(
args
...
interface
{})
os
.
Error
{
rv
:=
C
.
sqlite3_reset
(
s
.
stmt
)
if
rv
!=
0
{
return
s
.
c
.
error
(
rv
)
err
:=
s
.
Reset
(
)
if
err
!=
nil
{
return
err
}
n
:=
s
.
BindParameterCount
()
...
...
@@ -335,6 +335,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error {
}
for
i
,
v
:=
range
args
{
var
rv
C
.
int
index
:=
C
.
int
(
i
+
1
)
switch
v
:=
v
.
(
type
)
{
case
nil
:
...
...
@@ -393,6 +394,7 @@ func (s *Stmt) ColumnCount() int {
return
int
(
C
.
sqlite3_column_count
(
s
.
stmt
))
}
// The leftmost column is number 0.
func
(
s
*
Stmt
)
ColumnName
(
index
int
)
string
{
return
C
.
GoString
(
C
.
sqlite3_column_name
(
s
.
stmt
,
C
.
int
(
index
)))
}
...
...
sqlite_test.go
View file @
50898ecf
package
sqlite
import
(
"strings"
"testing"
"os"
)
...
...
@@ -25,6 +26,13 @@ func createTable(db *Conn, t *testing.T) {
}
}
func
TestVersion
(
t
*
testing
.
T
)
{
v
:=
Version
()
if
!
strings
.
HasPrefix
(
v
,
"3"
)
{
t
.
Fatalf
(
"unexpected library version: %s"
,
v
)
}
}
func
TestOpen
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
db
.
Close
()
...
...
@@ -51,8 +59,23 @@ func TestInsert(t *testing.T) {
}
}
lastId
:=
db
.
LastInsertRowid
()
if
lastId
!=
1000
{
t
.
Errorf
(
"last insert row id error: %d <> 1000"
,
lastId
)
}
cs
,
_
:=
db
.
Prepare
(
"SELECT COUNT(*) FROM test"
)
defer
cs
.
Finalize
()
paramCount
:=
cs
.
BindParameterCount
()
if
paramCount
!=
0
{
t
.
Errorf
(
"bind parameter count error: %d <> 0"
,
paramCount
)
}
columnCount
:=
cs
.
ColumnCount
()
if
columnCount
!=
1
{
t
.
Errorf
(
"column count error: %d <> 1"
,
columnCount
)
}
if
ok
,
err
:=
cs
.
Next
();
!
ok
{
if
err
!=
nil
{
t
.
Fatalf
(
"error preparing count: %s"
,
err
)
...
...
@@ -82,6 +105,11 @@ func TestInsertWithStatement(t *testing.T) {
}
defer
s
.
Finalize
()
paramCount
:=
s
.
BindParameterCount
()
if
paramCount
!=
3
{
t
.
Errorf
(
"bind parameter count error: %d <> 3"
,
paramCount
)
}
for
i
:=
0
;
i
<
1000
;
i
++
{
ierr
:=
s
.
Exec
(
float64
(
i
)
*
float64
(
3.14
),
i
,
"hello"
)
if
ierr
!=
nil
{
...
...
@@ -108,6 +136,15 @@ func TestInsertWithStatement(t *testing.T) {
}
rs
,
_
:=
db
.
Prepare
(
"SELECT float_num, int_num, a_string FROM test ORDER BY int_num LIMIT 2"
)
columnCount
:=
rs
.
ColumnCount
()
if
columnCount
!=
3
{
t
.
Errorf
(
"column count error: %d <> 3"
,
columnCount
)
}
secondColumnName
:=
rs
.
ColumnName
(
1
)
if
secondColumnName
!=
"int_num"
{
t
.
Errorf
(
"column name error: %s <> 'int_num'"
,
secondColumnName
)
}
var
fnum
float64
var
inum
int64
var
sstr
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