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
d7fe5817
Commit
d7fe5817
authored
Nov 10, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests pass with minimalist vtab impl.
parent
690673ed
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
32 deletions
+48
-32
vtab_test.go
vtab_test.go
+48
-32
No files found.
vtab_test.go
View file @
d7fe5817
...
...
@@ -5,7 +5,9 @@
package
sqlite_test
import
(
"fmt"
.
"github.com/gwenn/gosqlite"
"strconv"
"testing"
)
...
...
@@ -14,9 +16,12 @@ type testModule struct {
}
type
testVTab
struct
{
eof
bool
}
type
testVTabCursor
struct
{
vTab
*
testVTab
pos
int64
}
func
(
m
testModule
)
Create
(
c
*
Conn
,
args
[]
string
)
(
VTab
,
error
)
{
...
...
@@ -29,10 +34,10 @@ func (m testModule) Create(c *Conn, args []string) (VTab, error) {
assertEquals
(
m
.
t
,
"Expected '%s' but got '%s' as first arg"
,
"2"
,
args
[
4
])
assertEquals
(
m
.
t
,
"Expected '%s' but got '%s' as first arg"
,
"three"
,
args
[
5
])
c
.
DeclareVTab
(
"CREATE TABLE x(test TEXT)"
)
return
testVTab
{},
nil
return
&
testVTab
{},
nil
}
func
(
m
testModule
)
Connect
(
c
*
Conn
,
args
[]
string
)
(
VTab
,
error
)
{
println
(
"testVTab.Connect"
)
//
println("testVTab.Connect")
return
m
.
Create
(
c
,
args
)
}
...
...
@@ -40,46 +45,58 @@ func (m testModule) Destroy() {
//println("testModule.Destroy")
}
func
(
v
testVTab
)
BestIndex
()
error
{
println
(
"testVTab.BestIndex"
)
func
(
v
*
testVTab
)
BestIndex
()
error
{
//fmt.Printf("testVTab.BestIndex: %v\n", v
)
return
nil
}
func
(
v
testVTab
)
Disconnect
()
error
{
//
println("testVTab.Disconnect"
)
func
(
v
*
testVTab
)
Disconnect
()
error
{
//
fmt.Printf("testVTab.Disconnect: %v\n", v
)
return
nil
}
func
(
v
testVTab
)
Destroy
()
error
{
//
println("testVTab.Destroy"
)
func
(
v
*
testVTab
)
Destroy
()
error
{
//
fmt.Printf("testVTab.Destroy: %v\n", v
)
return
nil
}
func
(
v
testVTab
)
Open
()
(
VTabCursor
,
error
)
{
//
println("testVTab.Open"
)
return
testVTabCursor
{
},
nil
func
(
v
*
testVTab
)
Open
()
(
VTabCursor
,
error
)
{
//
fmt.Printf("testVTab.Open: %v\n", v
)
return
&
testVTabCursor
{
v
,
0
},
nil
}
func
(
v
testVTabCursor
)
Close
()
error
{
//
println("testVTabCursor.Close"
)
func
(
v
c
*
testVTabCursor
)
Close
()
error
{
//
fmt.Printf("testVTabCursor.Close: %v\n", vc
)
return
nil
}
func
(
v
testVTabCursor
)
Filter
(
/*idxNum int, idxStr string, int argc, sqlite3_value **argv*/
)
error
{
println
(
"testVTabCursor.Filter"
)
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
()
}
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
++
return
nil
}
func
(
v
testVTabCursor
)
Next
()
error
{
println
(
"testVTabCursor.Next"
)
return
nil
}
func
(
v
testVTabCursor
)
Eof
()
bool
{
println
(
"testVTabCursor.Eof"
)
return
true
func
(
vc
*
testVTabCursor
)
Eof
()
bool
{
//fmt.Printf("testVTabCursor.Eof: %v\n", vc)
return
vc
.
vTab
.
eof
}
func
(
v
testVTabCursor
)
Column
(
c
*
Context
,
col
int
)
error
{
println
(
"testVTabCursor.Column"
)
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
.
ResultText
(
strconv
.
FormatInt
(
vc
.
pos
,
10
))
return
nil
}
func
(
v
testVTabCursor
)
Rowid
()
(
int64
,
error
)
{
println
(
"testVTabCursor.Rowid"
)
return
1
,
nil
func
(
v
c
*
testVTabCursor
)
Rowid
()
(
int64
,
error
)
{
//fmt.Printf("testVTabCursor.Rowid: %v\n", vc
)
return
vc
.
pos
,
nil
}
func
TestCreateModule
(
t
*
testing
.
T
)
{
...
...
@@ -89,11 +106,10 @@ func TestCreateModule(t *testing.T) {
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)
//checkNoError(t, err, "couldn't select from virtual table: %s")
//assert(t, "Not null value expected", value != nil)
//assertEquals(t, "Expected '%s' but got '%s'", "test", *value)
var
value
string
err
=
db
.
OneValue
(
"SELECT * from vtab"
,
&
value
)
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