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
412216e2
Commit
412216e2
authored
Nov 22, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests to the exp/sql driver implementation.
parent
a13f41c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
4 deletions
+170
-4
driver.go
driver.go
+5
-4
driver_test.go
driver_test.go
+161
-0
trace.go
trace.go
+4
-0
No files found.
driver.go
View file @
412216e2
...
...
@@ -32,7 +32,6 @@ func (d *Driver) Open(name string) (driver.Conn, error) {
return
&
connImpl
{
c
},
nil
}
/*
func
(
c
*
connImpl
)
Exec
(
query
string
,
args
[]
interface
{})
(
driver
.
Result
,
error
)
{
if
err
:=
c
.
c
.
Exec
(
query
,
args
...
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -49,7 +48,6 @@ func (c *connImpl) LastInsertId() (int64, error) {
func
(
c
*
connImpl
)
RowsAffected
()
(
int64
,
error
)
{
return
int64
(
c
.
c
.
Changes
()),
nil
}
*/
func
(
c
*
connImpl
)
Prepare
(
query
string
)
(
driver
.
Stmt
,
error
)
{
s
,
err
:=
c
.
c
.
Prepare
(
query
)
...
...
@@ -60,7 +58,7 @@ func (c *connImpl) Prepare(query string) (driver.Stmt, error) {
}
func
(
c
*
connImpl
)
Close
()
error
{
return
c
.
c
.
Close
()
// TODO c.c = nil ?
return
c
.
c
.
Close
()
}
func
(
c
*
connImpl
)
Begin
()
(
driver
.
Tx
,
error
)
{
...
...
@@ -128,5 +126,8 @@ func (s *stmtImpl) Next(dest []interface{}) error {
if
!
ok
{
return
io
.
EOF
}
return
s
.
s
.
Scan
(
dest
...
)
for
i
:=
range
dest
{
dest
[
i
]
=
s
.
s
.
ScanValue
(
i
)
}
return
nil
}
driver_test.go
0 → 100644
View file @
412216e2
package
sqlite_test
import
(
"exp/sql"
"testing"
)
const
(
ddl
=
"DROP TABLE IF EXISTS test;"
+
"CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT,"
+
" name TEXT);"
dml
=
"INSERT INTO test (name) values ('Bart');"
+
"INSERT INTO test (name) values ('Lisa');"
+
"UPDATE test set name = 'El Barto' where name = 'Bart';"
+
"DELETE from test where name = 'Bart';"
insert
=
"INSERT into test (name) values (?)"
query
=
"SELECT * FROM test where name like ?"
)
func
sqlOpen
(
t
*
testing
.
T
)
*
sql
.
DB
{
db
,
err
:=
sql
.
Open
(
"sqlite3"
,
""
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error opening database: %s"
,
err
)
}
return
db
}
func
sqlCreate
(
ddl
string
,
t
*
testing
.
T
)
*
sql
.
DB
{
db
:=
sqlOpen
(
t
)
_
,
err
:=
db
.
Exec
(
ddl
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error creating table: %s"
,
err
)
}
return
db
}
func
TestSqlOpen
(
t
*
testing
.
T
)
{
db
:=
sqlOpen
(
t
)
if
err
:=
db
.
Close
();
err
!=
nil
{
t
.
Fatalf
(
"Error closing database: %s"
,
err
)
}
}
func
TestSqlDdl
(
t
*
testing
.
T
)
{
db
:=
sqlOpen
(
t
)
defer
db
.
Close
()
result
,
err
:=
db
.
Exec
(
ddl
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error creating table: %s"
,
err
)
}
_
,
err
=
result
.
LastInsertId
()
// FIXME Error expected
if
err
==
nil
{
t
.
Logf
(
"Error expected when calling LastInsertId after DDL"
)
}
_
,
err
=
result
.
RowsAffected
()
// FIXME Error expected
if
err
==
nil
{
t
.
Logf
(
"Error expected when calling RowsAffected after DDL"
)
}
}
func
TestSqlDml
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
,
t
)
defer
db
.
Close
()
result
,
err
:=
db
.
Exec
(
dml
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error updating data: %s"
,
err
)
}
id
,
err
:=
result
.
LastInsertId
()
if
err
!=
nil
{
t
.
Errorf
(
"Error while calling LastInsertId: %s"
,
err
)
}
if
id
!=
2
{
t
.
Errorf
(
"Expected %d got %d LastInsertId"
,
2
,
id
)
}
changes
,
err
:=
result
.
RowsAffected
()
if
err
!=
nil
{
t
.
Errorf
(
"Error while calling RowsAffected: %s"
,
err
)
}
if
changes
!=
0
{
t
.
Errorf
(
"Expected %d got %d RowsAffected"
,
0
,
changes
)
}
}
func
TestSqlInsert
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
,
t
)
defer
db
.
Close
()
result
,
err
:=
db
.
Exec
(
insert
,
"Bart"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error updating data: %s"
,
err
)
}
id
,
err
:=
result
.
LastInsertId
()
if
err
!=
nil
{
t
.
Errorf
(
"Error while calling LastInsertId: %s"
,
err
)
}
if
id
!=
1
{
t
.
Errorf
(
"Expected %d got %d LastInsertId"
,
2
,
id
)
}
changes
,
err
:=
result
.
RowsAffected
()
if
err
!=
nil
{
t
.
Errorf
(
"Error while calling RowsAffected: %s"
,
err
)
}
if
changes
!=
1
{
t
.
Errorf
(
"Expected %d got %d RowsAffected"
,
0
,
changes
)
}
}
func
TestSqlExecWithIllegalCmd
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
defer
db
.
Close
()
_
,
err
:=
db
.
Exec
(
query
,
"%"
)
if
err
==
nil
{
t
.
Fatalf
(
"Error expected when calling Exec with a SELECT"
)
}
}
func
TestSqlQuery
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
defer
db
.
Close
()
rows
,
err
:=
db
.
Query
(
query
,
"%"
)
defer
rows
.
Close
()
var
id
int
var
name
string
for
rows
.
Next
()
{
err
=
rows
.
Scan
(
&
id
,
&
name
)
if
err
!=
nil
{
t
.
Errorf
(
"Error while scanning: %s"
,
err
)
}
}
// FIXME Dangling statement
}
func
TestSqlTx
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
,
t
)
defer
db
.
Close
()
tx
,
err
:=
db
.
Begin
()
if
err
!=
nil
{
t
.
Errorf
(
"Error while begining tx: %s"
,
err
)
}
err
=
tx
.
Rollback
()
if
err
!=
nil
{
t
.
Errorf
(
"Error while rollbacking tx: %s"
,
err
)
}
}
func
TestSqlPrepare
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
defer
db
.
Close
()
stmt
,
err
:=
db
.
Prepare
(
insert
)
if
err
!=
nil
{
t
.
Errorf
(
"Error while preparing stmt: %s"
,
err
)
}
defer
stmt
.
Close
()
_
,
err
=
stmt
.
Exec
(
"Bart"
)
if
err
!=
nil
{
t
.
Errorf
(
"Error while executing stmt: %s"
,
err
)
}
}
trace.go
View file @
412216e2
...
...
@@ -266,3 +266,7 @@ func Log(err /*Errno*/ int, msg string) {
defer
C
.
free
(
unsafe
.
Pointer
(
cs
))
C
.
my_log
(
C
.
int
(
err
),
cs
)
}
// TODO sqlite3_config(SQLITE_CONFIG_LOG,...)
// #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
// The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a function with a call signature of void(*)(void*,int,const char*), and a pointer to void.
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