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
bc59e46a
Commit
bc59e46a
authored
Jan 01, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a simple test with a user's defined function in Go.
parent
dee9b21f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
3 deletions
+55
-3
function_test.go
function_test.go
+48
-0
sqlite.go
sqlite.go
+2
-2
trace_test.go
trace_test.go
+5
-1
No files found.
function_test.go
0 → 100644
View file @
bc59e46a
package
sqlite_test
import
(
.
"github.com/gwenn/gosqlite"
"testing"
)
func
half
(
ctx
*
Context
,
nArg
int
)
{
ctx
.
ResultDouble
(
ctx
.
Double
(
0
)
/
2
)
}
func
TestScalarFunction
(
t
*
testing
.
T
)
{
db
,
err
:=
Open
(
""
)
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
}
defer
db
.
Close
()
err
=
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
half
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't create function: %s"
,
err
)
}
s
,
err
:=
db
.
Prepare
(
"select half(6)"
)
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't prepare statement: %s"
,
err
)
}
b
,
err
:=
s
.
Next
()
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't step statement: %s"
,
err
)
}
if
!
b
{
t
.
Fatalf
(
"No result"
)
}
d
,
_
,
err
:=
s
.
ScanDouble
(
0
)
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't scan result: %s"
,
err
)
}
if
d
!=
3
{
t
.
Errorf
(
"Expected %f but got %f"
,
3
,
d
)
}
err
=
s
.
Finalize
()
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't finalize statement: %s"
,
err
)
}
err
=
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
nil
,
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"couldn't destroy function: %s"
,
err
)
}
}
\ No newline at end of file
sqlite.go
View file @
bc59e46a
...
@@ -899,7 +899,7 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
...
@@ -899,7 +899,7 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
case
*
bool
:
case
*
bool
:
*
value
,
isNull
,
err
=
s
.
ScanBool
(
index
)
*
value
,
isNull
,
err
=
s
.
ScanBool
(
index
)
case
*
float64
:
case
*
float64
:
*
value
,
isNull
,
err
=
s
.
Scan
Float64
(
index
)
*
value
,
isNull
,
err
=
s
.
Scan
Double
(
index
)
case
*
[]
byte
:
case
*
[]
byte
:
*
value
,
isNull
=
s
.
ScanBlob
(
index
)
*
value
,
isNull
=
s
.
ScanBlob
(
index
)
case
*
interface
{}
:
case
*
interface
{}
:
...
@@ -1050,7 +1050,7 @@ func (s *Stmt) ScanBool(index int) (value bool, isNull bool, err error) {
...
@@ -1050,7 +1050,7 @@ func (s *Stmt) ScanBool(index int) (value bool, isNull bool, err error) {
// Returns true when column is null and Stmt.CheckNull is activated.
// Returns true when column is null and Stmt.CheckNull is activated.
// Calls sqlite3_column_double.
// Calls sqlite3_column_double.
// http://sqlite.org/c3ref/column_blob.html
// http://sqlite.org/c3ref/column_blob.html
func
(
s
*
Stmt
)
Scan
Float64
(
index
int
)
(
value
float64
,
isNull
bool
,
err
error
)
{
// TODO Rename in ScanDouble
func
(
s
*
Stmt
)
Scan
Double
(
index
int
)
(
value
float64
,
isNull
bool
,
err
error
)
{
var
ctype
Type
var
ctype
Type
if
s
.
CheckNull
||
s
.
CheckTypeMismatch
{
if
s
.
CheckNull
||
s
.
CheckTypeMismatch
{
ctype
=
s
.
ColumnType
(
index
)
ctype
=
s
.
ColumnType
(
index
)
...
...
trace_test.go
View file @
bc59e46a
...
@@ -50,6 +50,7 @@ func TestNoTrace(t *testing.T) {
...
@@ -50,6 +50,7 @@ func TestNoTrace(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
}
}
defer
db
.
Close
()
db
.
Trace
(
nil
,
nil
)
db
.
Trace
(
nil
,
nil
)
db
.
SetAuthorizer
(
nil
,
nil
)
db
.
SetAuthorizer
(
nil
,
nil
)
db
.
Profile
(
nil
,
nil
)
db
.
Profile
(
nil
,
nil
)
...
@@ -58,11 +59,14 @@ func TestNoTrace(t *testing.T) {
...
@@ -58,11 +59,14 @@ func TestNoTrace(t *testing.T) {
db
.
CommitHook
(
nil
,
nil
)
db
.
CommitHook
(
nil
,
nil
)
db
.
RollbackHook
(
nil
,
nil
)
db
.
RollbackHook
(
nil
,
nil
)
db
.
UpdateHook
(
nil
,
nil
)
db
.
UpdateHook
(
nil
,
nil
)
db
.
Close
()
}
}
func
TestTrace
(
t
*
testing
.
T
)
{
func
TestTrace
(
t
*
testing
.
T
)
{
db
,
err
:=
Open
(
""
)
db
,
err
:=
Open
(
""
)
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
}
defer
db
.
Close
()
db
.
Trace
(
trace
,
"TRACE"
)
db
.
Trace
(
trace
,
"TRACE"
)
err
=
db
.
SetAuthorizer
(
authorizer
,
"AUTH"
)
err
=
db
.
SetAuthorizer
(
authorizer
,
"AUTH"
)
if
err
!=
nil
{
if
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