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
85cfd686
Commit
85cfd686
authored
Dec 08, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests virtual table with an intarray Go impl.
parent
e10dbb7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
22 deletions
+28
-22
vtab_test.go
vtab_test.go
+28
-22
No files found.
vtab_test.go
View file @
85cfd686
...
...
@@ -7,21 +7,21 @@ package sqlite_test
import
(
"fmt"
.
"github.com/gwenn/gosqlite"
"strconv"
"testing"
)
type
testModule
struct
{
t
*
testing
.
T
t
*
testing
.
T
intarray
[]
int
}
type
testVTab
struct
{
eof
bool
intarray
[]
int
}
type
testVTabCursor
struct
{
vTab
*
testVTab
pos
int64
vTab
*
testVTab
index
int
/* Current cursor position */
}
func
(
m
testModule
)
Create
(
c
*
Conn
,
args
[]
string
)
(
VTab
,
error
)
{
...
...
@@ -37,7 +37,7 @@ func (m testModule) Create(c *Conn, args []string) (VTab, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
&
testVTab
{},
nil
return
&
testVTab
{
m
.
intarray
},
nil
}
func
(
m
testModule
)
Connect
(
c
*
Conn
,
args
[]
string
)
(
VTab
,
error
)
{
//println("testVTab.Connect")
...
...
@@ -71,48 +71,54 @@ func (vc *testVTabCursor) Close() error {
}
func
(
vc
*
testVTabCursor
)
Filter
(
/*idxNum int, idxStr string, int argc, sqlite3_value **argv*/
)
error
{
//fmt.Printf("testVTabCursor.Filter: %v\n", vc)
vc
.
vTab
.
eof
=
false
return
vc
.
Next
()
vc
.
index
=
0
return
nil
}
func
(
vc
*
testVTabCursor
)
Next
()
error
{
//fmt.Printf("testVTabCursor.Next: %v\n", vc)
if
vc
.
vTab
.
eof
{
return
fmt
.
Errorf
(
"Next() called after EOF!"
)
}
if
vc
.
pos
==
1
{
vc
.
vTab
.
eof
=
true
}
vc
.
pos
++
vc
.
index
++
return
nil
}
func
(
vc
*
testVTabCursor
)
Eof
()
bool
{
//fmt.Printf("testVTabCursor.Eof: %v\n", vc)
return
vc
.
vTab
.
eof
return
vc
.
index
>=
len
(
vc
.
vTab
.
intarray
)
}
func
(
vc
*
testVTabCursor
)
Column
(
c
*
Context
,
col
int
)
error
{
//fmt.Printf("testVTabCursor.Column(%d): %v\n", col, vc)
if
col
!=
0
{
return
fmt
.
Errorf
(
"Column index out of bounds: %d"
,
col
)
}
c
.
Result
Text
(
strconv
.
FormatInt
(
vc
.
pos
,
10
)
)
c
.
Result
Int
(
vc
.
vTab
.
intarray
[
vc
.
index
]
)
return
nil
}
func
(
vc
*
testVTabCursor
)
Rowid
()
(
int64
,
error
)
{
//fmt.Printf("testVTabCursor.Rowid: %v\n", vc)
return
vc
.
pos
,
nil
return
int64
(
vc
.
index
)
,
nil
}
func
TestCreateModule
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
err
:=
db
.
CreateModule
(
"test"
,
testModule
{
t
})
intarray
:=
[]
int
{
1
,
2
,
3
}
err
:=
db
.
CreateModule
(
"test"
,
testModule
{
t
,
intarray
})
checkNoError
(
t
,
err
,
"couldn't create module: %s"
)
err
=
db
.
Exec
(
"CREATE VIRTUAL TABLE vtab USING test('1', 2, three)"
)
checkNoError
(
t
,
err
,
"couldn't create virtual table: %s"
)
var
value
string
err
=
db
.
OneValue
(
"SELECT * from vtab"
,
&
value
)
s
,
err
:=
db
.
Prepare
(
"SELECT * from vtab"
)
checkNoError
(
t
,
err
,
"couldn't select from virtual table: %s"
)
defer
s
.
Finalize
()
var
i
,
value
int
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
if
err
=
s
.
Scan
(
&
value
);
err
!=
nil
{
return
}
assertEquals
(
t
,
"Expected '%d' but got '%d'"
,
intarray
[
i
],
value
)
i
++
return
})
checkNoError
(
t
,
err
,
"couldn't select from virtual table: %s"
)
assertEquals
(
t
,
"Expected '%s' but got '%s'"
,
"1"
,
value
)
err
=
db
.
Exec
(
"DROP TABLE vtab"
)
checkNoError
(
t
,
err
,
"couldn't drop virtual table: %s"
)
}
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