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
5ec57d10
Commit
5ec57d10
authored
Oct 27, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split FunctionContext and Context to prepare VTab support.
parent
4aca652e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
19 deletions
+24
-19
function.go
function.go
+24
-19
No files found.
function.go
View file @
5ec57d10
...
@@ -66,26 +66,31 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
...
@@ -66,26 +66,31 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
*/
*/
// Context common to scalar and aggregate function
// Context common to scalar and aggregate function
// (See http://sqlite.org/c3ref/context.html)
type
Context
struct
{
type
Context
struct
{
sc
*
C
.
sqlite3_context
sc
*
C
.
sqlite3_context
}
type
FunctionContext
struct
{
Context
argv
**
C
.
sqlite3_value
argv
**
C
.
sqlite3_value
}
}
// Context associated to scalar function
// Context associated to scalar function
type
ScalarContext
struct
{
type
ScalarContext
struct
{
Context
Function
Context
ad
map
[
int
]
interface
{}
// Function Auxiliary Data
ad
map
[
int
]
interface
{}
// Function Auxiliary Data
udf
*
sqliteFunction
udf
*
sqliteFunction
}
}
// Context associated to aggregate function
// Context associated to aggregate function
type
AggregateContext
struct
{
type
AggregateContext
struct
{
Context
Function
Context
Aggregate
interface
{}
Aggregate
interface
{}
}
}
// Result sets the result of an SQL function.
// Result sets the result of an SQL function.
func
(
c
*
Context
)
Result
(
r
interface
{})
{
func
(
c
*
Function
Context
)
Result
(
r
interface
{})
{
switch
r
:=
r
.
(
type
)
{
switch
r
:=
r
.
(
type
)
{
case
nil
:
case
nil
:
c
.
ResultNull
()
c
.
ResultNull
()
...
@@ -143,7 +148,7 @@ func (c *Context) ResultDouble(d float64) {
...
@@ -143,7 +148,7 @@ func (c *Context) ResultDouble(d float64) {
// ResultError sets the result of an SQL function.
// ResultError sets the result of an SQL function.
// (See sqlite3_result_error, http://sqlite.org/c3ref/result_blob.html)
// (See sqlite3_result_error, http://sqlite.org/c3ref/result_blob.html)
func
(
c
*
Context
)
ResultError
(
msg
string
)
{
func
(
c
*
Function
Context
)
ResultError
(
msg
string
)
{
cs
:=
C
.
CString
(
msg
)
cs
:=
C
.
CString
(
msg
)
defer
C
.
free
(
unsafe
.
Pointer
(
cs
))
defer
C
.
free
(
unsafe
.
Pointer
(
cs
))
C
.
sqlite3_result_error
(
c
.
sc
,
cs
,
-
1
)
C
.
sqlite3_result_error
(
c
.
sc
,
cs
,
-
1
)
...
@@ -151,19 +156,19 @@ func (c *Context) ResultError(msg string) {
...
@@ -151,19 +156,19 @@ func (c *Context) ResultError(msg string) {
// ResultErrorTooBig sets the result of an SQL function.
// ResultErrorTooBig sets the result of an SQL function.
// (See sqlite3_result_error_toobig, http://sqlite.org/c3ref/result_blob.html)
// (See sqlite3_result_error_toobig, http://sqlite.org/c3ref/result_blob.html)
func
(
c
*
Context
)
ResultErrorTooBig
()
{
func
(
c
*
Function
Context
)
ResultErrorTooBig
()
{
C
.
sqlite3_result_error_toobig
(
c
.
sc
)
C
.
sqlite3_result_error_toobig
(
c
.
sc
)
}
}
// ResultErrorNoMem sets the result of an SQL function.
// ResultErrorNoMem sets the result of an SQL function.
// (See sqlite3_result_error_nomem, http://sqlite.org/c3ref/result_blob.html)
// (See sqlite3_result_error_nomem, http://sqlite.org/c3ref/result_blob.html)
func
(
c
*
Context
)
ResultErrorNoMem
()
{
func
(
c
*
Function
Context
)
ResultErrorNoMem
()
{
C
.
sqlite3_result_error_nomem
(
c
.
sc
)
C
.
sqlite3_result_error_nomem
(
c
.
sc
)
}
}
// ResultErrorCode sets the result of an SQL function.
// ResultErrorCode sets the result of an SQL function.
// (See sqlite3_result_error_code, http://sqlite.org/c3ref/result_blob.html)
// (See sqlite3_result_error_code, http://sqlite.org/c3ref/result_blob.html)
func
(
c
*
Context
)
ResultErrorCode
(
e
Errno
)
{
func
(
c
*
Function
Context
)
ResultErrorCode
(
e
Errno
)
{
C
.
sqlite3_result_error_code
(
c
.
sc
,
C
.
int
(
e
))
C
.
sqlite3_result_error_code
(
c
.
sc
,
C
.
int
(
e
))
}
}
...
@@ -196,7 +201,7 @@ func (c *Context) ResultText(s string) {
...
@@ -196,7 +201,7 @@ func (c *Context) ResultText(s string) {
// ResultValue sets the result of an SQL function.
// ResultValue sets the result of an SQL function.
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_result_value, http://sqlite.org/c3ref/result_blob.html)
// (See sqlite3_result_value, http://sqlite.org/c3ref/result_blob.html)
func
(
c
*
Context
)
ResultValue
(
i
int
)
{
func
(
c
*
Function
Context
)
ResultValue
(
i
int
)
{
C
.
my_result_value
(
c
.
sc
,
c
.
argv
,
C
.
int
(
i
))
C
.
my_result_value
(
c
.
sc
,
c
.
argv
,
C
.
int
(
i
))
}
}
...
@@ -208,7 +213,7 @@ func (c *Context) ResultZeroblob(n ZeroBlobLength) {
...
@@ -208,7 +213,7 @@ func (c *Context) ResultZeroblob(n ZeroBlobLength) {
// UserData returns the user data for functions.
// UserData returns the user data for functions.
// (See http://sqlite.org/c3ref/user_data.html)
// (See http://sqlite.org/c3ref/user_data.html)
func
(
c
*
Context
)
UserData
()
interface
{}
{
func
(
c
*
Function
Context
)
UserData
()
interface
{}
{
udf
:=
(
*
sqliteFunction
)(
C
.
sqlite3_user_data
(
c
.
sc
))
udf
:=
(
*
sqliteFunction
)(
C
.
sqlite3_user_data
(
c
.
sc
))
return
udf
.
pApp
return
udf
.
pApp
}
}
...
@@ -234,14 +239,14 @@ func (c *ScalarContext) SetAuxData(n int, ad interface{}) {
...
@@ -234,14 +239,14 @@ func (c *ScalarContext) SetAuxData(n int, ad interface{}) {
// Bool obtains a SQL function parameter value.
// Bool obtains a SQL function parameter value.
// The leftmost value is number 0.
// The leftmost value is number 0.
func
(
c
*
Context
)
Bool
(
i
int
)
bool
{
func
(
c
*
Function
Context
)
Bool
(
i
int
)
bool
{
return
c
.
Int
(
i
)
==
1
return
c
.
Int
(
i
)
==
1
}
}
// Blob obtains a SQL function parameter value.
// Blob obtains a SQL function parameter value.
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_value_blob and sqlite3_value_bytes, http://sqlite.org/c3ref/value_blob.html)
// (See sqlite3_value_blob and sqlite3_value_bytes, http://sqlite.org/c3ref/value_blob.html)
func
(
c
*
Context
)
Blob
(
i
int
)
(
value
[]
byte
)
{
func
(
c
*
Function
Context
)
Blob
(
i
int
)
(
value
[]
byte
)
{
p
:=
C
.
my_value_blob
(
c
.
argv
,
C
.
int
(
i
))
p
:=
C
.
my_value_blob
(
c
.
argv
,
C
.
int
(
i
))
if
p
!=
nil
{
if
p
!=
nil
{
n
:=
C
.
my_value_bytes
(
c
.
argv
,
C
.
int
(
i
))
n
:=
C
.
my_value_bytes
(
c
.
argv
,
C
.
int
(
i
))
...
@@ -253,28 +258,28 @@ func (c *Context) Blob(i int) (value []byte) {
...
@@ -253,28 +258,28 @@ func (c *Context) Blob(i int) (value []byte) {
// Double obtains a SQL function parameter value.
// Double obtains a SQL function parameter value.
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_value_double, http://sqlite.org/c3ref/value_blob.html)
// (See sqlite3_value_double, http://sqlite.org/c3ref/value_blob.html)
func
(
c
*
Context
)
Double
(
i
int
)
float64
{
func
(
c
*
Function
Context
)
Double
(
i
int
)
float64
{
return
float64
(
C
.
my_value_double
(
c
.
argv
,
C
.
int
(
i
)))
return
float64
(
C
.
my_value_double
(
c
.
argv
,
C
.
int
(
i
)))
}
}
// Int obtains a SQL function parameter value.
// Int obtains a SQL function parameter value.
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_value_int, http://sqlite.org/c3ref/value_blob.html)
// (See sqlite3_value_int, http://sqlite.org/c3ref/value_blob.html)
func
(
c
*
Context
)
Int
(
i
int
)
int
{
func
(
c
*
Function
Context
)
Int
(
i
int
)
int
{
return
int
(
C
.
my_value_int
(
c
.
argv
,
C
.
int
(
i
)))
return
int
(
C
.
my_value_int
(
c
.
argv
,
C
.
int
(
i
)))
}
}
// Int64 obtains a SQL function parameter value.
// Int64 obtains a SQL function parameter value.
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_value_int64, http://sqlite.org/c3ref/value_blob.html)
// (See sqlite3_value_int64, http://sqlite.org/c3ref/value_blob.html)
func
(
c
*
Context
)
Int64
(
i
int
)
int64
{
func
(
c
*
Function
Context
)
Int64
(
i
int
)
int64
{
return
int64
(
C
.
my_value_int64
(
c
.
argv
,
C
.
int
(
i
)))
return
int64
(
C
.
my_value_int64
(
c
.
argv
,
C
.
int
(
i
)))
}
}
// Text obtains a SQL function parameter value.
// Text obtains a SQL function parameter value.
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_value_text, http://sqlite.org/c3ref/value_blob.html)
// (See sqlite3_value_text, http://sqlite.org/c3ref/value_blob.html)
func
(
c
*
Context
)
Text
(
i
int
)
string
{
func
(
c
*
Function
Context
)
Text
(
i
int
)
string
{
p
:=
C
.
my_value_text
(
c
.
argv
,
C
.
int
(
i
))
p
:=
C
.
my_value_text
(
c
.
argv
,
C
.
int
(
i
))
if
p
==
nil
{
if
p
==
nil
{
return
""
return
""
...
@@ -286,19 +291,19 @@ func (c *Context) Text(i int) string {
...
@@ -286,19 +291,19 @@ func (c *Context) Text(i int) string {
// Type obtains a SQL function parameter value type.
// Type obtains a SQL function parameter value type.
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_value_type, http://sqlite.org/c3ref/value_blob.html)
// (See sqlite3_value_type, http://sqlite.org/c3ref/value_blob.html)
func
(
c
*
Context
)
Type
(
i
int
)
Type
{
func
(
c
*
Function
Context
)
Type
(
i
int
)
Type
{
return
Type
(
C
.
my_value_type
(
c
.
argv
,
C
.
int
(
i
)))
return
Type
(
C
.
my_value_type
(
c
.
argv
,
C
.
int
(
i
)))
}
}
// NumericType obtains a SQL function parameter value numeric type (with possible conversion).
// NumericType obtains a SQL function parameter value numeric type (with possible conversion).
// The leftmost value is number 0.
// The leftmost value is number 0.
// (See sqlite3_value_numeric_type, http://sqlite.org/c3ref/value_blob.html)
// (See sqlite3_value_numeric_type, http://sqlite.org/c3ref/value_blob.html)
func
(
c
*
Context
)
NumericType
(
i
int
)
Type
{
func
(
c
*
Function
Context
)
NumericType
(
i
int
)
Type
{
return
Type
(
C
.
my_value_numeric_type
(
c
.
argv
,
C
.
int
(
i
)))
return
Type
(
C
.
my_value_numeric_type
(
c
.
argv
,
C
.
int
(
i
)))
}
}
// Value obtains a SQL function parameter value depending on its type.
// Value obtains a SQL function parameter value depending on its type.
func
(
c
*
Context
)
Value
(
i
int
)
(
value
interface
{})
{
func
(
c
*
Function
Context
)
Value
(
i
int
)
(
value
interface
{})
{
switch
c
.
Type
(
i
)
{
switch
c
.
Type
(
i
)
{
case
Null
:
case
Null
:
value
=
nil
value
=
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