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
ab027b97
Commit
ab027b97
authored
Jan 03, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix garbage collection problem with user defined functions.
parent
d1b8699e
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
182 additions
and
72 deletions
+182
-72
blob.go
blob.go
+1
-1
driver.go
driver.go
+2
-0
function.go
function.go
+111
-64
function_test.go
function_test.go
+63
-2
sqlite.go
sqlite.go
+5
-5
No files found.
blob.go
View file @
ab027b97
...
...
@@ -29,7 +29,7 @@ type BlobReadWriter struct {
}
// Zeroblobs are used to reserve space for a BLOB that is later written.
//
//
// Example:
// s, err := db.Prepare("INSERT INTO test VALUES (?)")
// // check err
...
...
driver.go
View file @
ab027b97
...
...
@@ -31,6 +31,8 @@ func (d *Driver) Open(name string) (driver.Conn, error) {
return
&
connImpl
{
c
},
nil
}
// PRAGMA schema_version may be used to detect when the database schema is altered
func
(
c
*
connImpl
)
Exec
(
query
string
,
args
[]
interface
{})
(
driver
.
Result
,
error
)
{
if
err
:=
c
.
c
.
Exec
(
query
,
args
...
);
err
!=
nil
{
return
nil
,
err
...
...
function.go
View file @
ab027b97
This diff is collapsed.
Click to expand it.
function_test.go
View file @
ab027b97
...
...
@@ -2,6 +2,7 @@ package sqlite_test
import
(
.
"github.com/gwenn/gosqlite"
"math/rand"
"regexp"
"testing"
)
...
...
@@ -47,12 +48,13 @@ func re(ctx *Context, nArg int) {
ctx
.
ResultError
(
err
.
Error
())
return
}
ctx
.
SetAuxData
(
0
,
re
,
nil
)
ctx
.
SetAuxData
(
0
,
re
)
}
else
{
//println("Reuse")
var
ok
bool
if
re
,
ok
=
ad
.
(
*
regexp
.
Regexp
);
!
ok
{
ctx
.
ResultError
(
"AuxData not a regexp "
)
println
(
ad
)
ctx
.
ResultError
(
"AuxData not a regexp"
)
return
}
}
...
...
@@ -102,3 +104,62 @@ func TestRegexpFunction(t *testing.T) {
t
.
Fatalf
(
"couldn't finalize statement: %s"
,
err
)
}
}
func
randomFill
(
db
*
Conn
,
n
int
)
{
db
.
Exec
(
"DROP TABLE IF EXISTS test"
)
db
.
Exec
(
"CREATE TABLE test (name TEXT, rank int)"
)
s
,
_
:=
db
.
Prepare
(
"INSERT INTO test (name, rank) VALUES (?, ?)"
)
names
:=
[]
string
{
"Bart"
,
"Homer"
,
"Lisa"
,
"Maggie"
,
"Marge"
}
db
.
Begin
()
for
i
:=
0
;
i
<
n
;
i
++
{
s
.
Exec
(
names
[
rand
.
Intn
(
len
(
names
))],
rand
.
Intn
(
100
))
}
s
.
Finalize
()
db
.
Commit
()
}
func
BenchmarkLike
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
randomFill
(
db
,
1000
)
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
cs
,
_
:=
db
.
Prepare
(
"SELECT count(1) FROM test where name like 'lisa'"
)
Must
(
cs
.
Next
())
cs
.
Finalize
()
}
}
func
BenchmarkHalf
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
randomFill
(
db
,
1000
)
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
half
,
nil
)
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
cs
,
_
:=
db
.
Prepare
(
"SELECT count(1) FROM test where half(rank) > 20"
)
Must
(
cs
.
Next
())
cs
.
Finalize
()
}
}
func
BenchmarkRegexp
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
randomFill
(
db
,
1000
)
db
.
CreateScalarFunction
(
"regexp"
,
2
,
nil
,
re
,
reDestroy
)
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
cs
,
_
:=
db
.
Prepare
(
"SELECT count(1) FROM test where name regexp '(?i)
\\
blisa
\\
b'"
)
Must
(
cs
.
Next
())
cs
.
Finalize
()
}
}
sqlite.go
View file @
ab027b97
...
...
@@ -53,7 +53,7 @@ func (e *ConnError) Code() Errno {
return
e
.
code
}
// FIXME it might be the case that a second error occurs on a separate thread in between the time of the first error and the call to this method.
// FIXME it might be the case that a second error occurs on a separate thread in between the time of the first error and the call to this method.
func
(
e
*
ConnError
)
ExtendedCode
()
int
{
return
int
(
C
.
sqlite3_extended_errcode
(
e
.
c
.
db
))
}
...
...
@@ -211,7 +211,7 @@ type Conn struct {
commitHook
*
sqliteCommitHook
rollbackHook
*
sqliteRollbackHook
updateHook
*
sqliteUpdateHook
udfs
map
[
string
]
*
sqlite
Scalar
Function
udfs
map
[
string
]
*
sqliteFunction
}
// Run-time library version number
...
...
@@ -238,7 +238,7 @@ const (
// Open a new database connection.
// ":memory:" for memory db
// "" for temp file db
//
//
// Example:
// db, err := sqlite.Open(":memory:")
// if err != nil {
...
...
@@ -302,8 +302,8 @@ func (c *Conn) EnableFKey(b bool) (bool, error) {
}
// Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, -1)
// Another way is PRAGMA foreign_keys;
//
// Another way is PRAGMA foreign_keys;
//
// http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html
func
(
c
*
Conn
)
IsFKeyEnabled
()
(
bool
,
error
)
{
return
c
.
queryOrSetEnableFKey
(
-
1
)
...
...
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