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
690673ed
Commit
690673ed
authored
Nov 10, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Continue binding Virtual table API.
parent
c699a930
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
18 deletions
+82
-18
vtab.c
vtab.c
+31
-9
vtab.go
vtab.go
+47
-5
vtab_test.go
vtab_test.go
+4
-4
No files found.
vtab.c
View file @
690673ed
...
...
@@ -82,31 +82,53 @@ static int cXOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor) {
*
ppCursor
=
(
sqlite3_vtab_cursor
*
)
pCursor
;
return
SQLITE_OK
;
}
static
int
setErrMsg
(
sqlite3_vtab_cursor
*
pCursor
,
char
*
pzErr
)
{
if
(
pCursor
->
pVtab
->
zErrMsg
)
sqlite3_free
(
pCursor
->
pVtab
->
zErrMsg
);
pCursor
->
pVtab
->
zErrMsg
=
pzErr
;
return
SQLITE_ERROR
;
}
static
int
cXClose
(
sqlite3_vtab_cursor
*
pCursor
)
{
char
*
pzErr
=
goVClose
(((
goVTabCursor
*
)
pCursor
)
->
vTabCursor
);
if
(
pzErr
)
{
if
(
pCursor
->
pVtab
->
zErrMsg
)
sqlite3_free
(
pCursor
->
pVtab
->
zErrMsg
);
pCursor
->
pVtab
->
zErrMsg
=
pzErr
;
return
SQLITE_ERROR
;
return
setErrMsg
(
pCursor
,
pzErr
);
}
sqlite3_free
(
pCursor
);
return
SQLITE_OK
;
}
static
int
cXFilter
(
sqlite3_vtab_cursor
*
pCursor
,
int
idxNum
,
const
char
*
idxStr
,
int
argc
,
sqlite3_value
**
argv
)
{
return
0
;
// TODO idxNum, idxStr, argc, argv are useless when cXBestIndex is empty
char
*
pzErr
=
goVFilter
(((
goVTabCursor
*
)
pCursor
)
->
vTabCursor
);
if
(
pzErr
)
{
return
setErrMsg
(
pCursor
,
pzErr
);
}
return
SQLITE_OK
;
}
static
int
cXNext
(
sqlite3_vtab_cursor
*
pCursor
)
{
return
goXNext
(
pCursor
);
char
*
pzErr
=
goVNext
(((
goVTabCursor
*
)
pCursor
)
->
vTabCursor
);
if
(
pzErr
)
{
return
setErrMsg
(
pCursor
,
pzErr
);
}
return
SQLITE_OK
;
}
static
int
cXEof
(
sqlite3_vtab_cursor
*
pCursor
)
{
return
0
;
return
goVEof
(((
goVTabCursor
*
)
pCursor
)
->
vTabCursor
)
;
}
static
int
cXColumn
(
sqlite3_vtab_cursor
*
pCursor
,
sqlite3_context
*
ctx
,
int
i
)
{
return
0
;
char
*
pzErr
=
goVColumn
(((
goVTabCursor
*
)
pCursor
)
->
vTabCursor
,
ctx
,
i
);
if
(
pzErr
)
{
return
setErrMsg
(
pCursor
,
pzErr
);
}
return
SQLITE_OK
;
}
static
int
cXRowid
(
sqlite3_vtab_cursor
*
pCursor
,
sqlite3_int64
*
pRowid
)
{
return
0
;
char
*
pzErr
=
goVRowid
(((
goVTabCursor
*
)
pCursor
)
->
vTabCursor
,
pRowid
);
if
(
pzErr
)
{
return
setErrMsg
(
pCursor
,
pzErr
);
}
return
SQLITE_OK
;
}
static
sqlite3_module
goModule
=
{
...
...
vtab.go
View file @
690673ed
...
...
@@ -127,10 +127,52 @@ func goMDestroy(pClientData unsafe.Pointer) {
delete
(
m
.
c
.
modules
,
m
.
name
)
}
//export goXNext
func
goXNext
(
pCursor
unsafe
.
Pointer
)
C
.
int
{
//vtc := (*sqliteVTabCursor)(pCursor)
return
0
//export goVFilter
func
goVFilter
(
pCursor
unsafe
.
Pointer
)
*
C
.
char
{
vtc
:=
(
*
sqliteVTabCursor
)(
pCursor
)
err
:=
vtc
.
vTabCursor
.
Filter
()
if
err
!=
nil
{
return
mPrintf
(
"%s"
,
err
.
Error
())
}
return
nil
}
//export goVNext
func
goVNext
(
pCursor
unsafe
.
Pointer
)
*
C
.
char
{
vtc
:=
(
*
sqliteVTabCursor
)(
pCursor
)
err
:=
vtc
.
vTabCursor
.
Next
()
if
err
!=
nil
{
return
mPrintf
(
"%s"
,
err
.
Error
())
}
return
nil
}
//export goVEof
func
goVEof
(
pCursor
unsafe
.
Pointer
)
C
.
int
{
vtc
:=
(
*
sqliteVTabCursor
)(
pCursor
)
return
btocint
(
vtc
.
vTabCursor
.
Eof
())
}
//export goVColumn
func
goVColumn
(
pCursor
,
cp
unsafe
.
Pointer
,
col
int
)
*
C
.
char
{
vtc
:=
(
*
sqliteVTabCursor
)(
pCursor
)
c
:=
&
Context
{(
*
C
.
sqlite3_context
)(
cp
)}
// TODO how to avoid building a Context at each invocation?
err
:=
vtc
.
vTabCursor
.
Column
(
c
,
col
)
if
err
!=
nil
{
return
mPrintf
(
"%s"
,
err
.
Error
())
}
return
nil
}
//export goVRowid
func
goVRowid
(
pCursor
unsafe
.
Pointer
,
pRowid
*
C
.
sqlite3_int64
)
*
C
.
char
{
vtc
:=
(
*
sqliteVTabCursor
)(
pCursor
)
rowid
,
err
:=
vtc
.
vTabCursor
.
Rowid
()
if
err
!=
nil
{
return
mPrintf
(
"%s"
,
err
.
Error
())
}
*
pRowid
=
C
.
sqlite3_int64
(
rowid
)
return
nil
}
type
Module
interface
{
...
...
@@ -168,7 +210,7 @@ type VTabExtended interface {
// (See http://sqlite.org/c3ref/vtab_cursor.html)
type
VTabCursor
interface
{
Close
()
error
// See http://sqlite.org/vtab.html#xclose
Filter
(
idxNum
int
,
idxStr
string
/*
, int argc, sqlite3_value **argv*/
)
error
// See http://sqlite.org/vtab.html#xfilter
Filter
(
/*idxNum int, idxStr string
, int argc, sqlite3_value **argv*/
)
error
// See http://sqlite.org/vtab.html#xfilter
Next
()
error
// See http://sqlite.org/vtab.html#xnext
Eof
()
bool
// See http://sqlite.org/vtab.html#xeof
// col is zero-based so the first column is numbered 0
...
...
vtab_test.go
View file @
690673ed
...
...
@@ -61,7 +61,7 @@ func (v testVTabCursor) Close() error {
//println("testVTabCursor.Close")
return
nil
}
func
(
v
testVTabCursor
)
Filter
(
idxNum
int
,
idxStr
string
/*
, int argc, sqlite3_value **argv*/
)
error
{
func
(
v
testVTabCursor
)
Filter
(
/*idxNum int, idxStr string
, int argc, sqlite3_value **argv*/
)
error
{
println
(
"testVTabCursor.Filter"
)
return
nil
}
...
...
@@ -89,9 +89,9 @@ 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"
)
//
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)
err
=
db
.
Exec
(
"DROP TABLE vtab"
)
...
...
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