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
8f71d095
Commit
8f71d095
authored
Oct 26, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add UpdateHook method.
parent
cedd3642
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
2 deletions
+57
-2
Makefile
Makefile
+2
-1
hook.go
hook.go
+47
-0
sqlite.go
sqlite.go
+1
-0
trace_test.go
trace_test.go
+7
-1
No files found.
Makefile
View file @
8f71d095
...
...
@@ -11,7 +11,8 @@ CGOFILES=\
backup.go
\
meta.go
\
trace.go
\
blob.go
blob.go
\
hook.go
GOFILES
=
\
date.go
...
...
hook.go
0 → 100644
View file @
8f71d095
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package sqlite provides access to the SQLite library, version 3.
package
sqlite
/*
#include <sqlite3.h>
#include <stdlib.h>
extern void goXUpdateHook(void *pArg, int action, char const *db, char const *table, sqlite3_int64 rowId);
static void goSqlite3UpdateHook(sqlite3 *db, void *pArg) {
sqlite3_update_hook(db, goXUpdateHook, pArg);
}
*/
import
"C"
import
(
"unsafe"
)
type
UpdateHook
func
(
d
interface
{},
a
Action
,
db
,
table
string
,
rowId
int64
)
type
sqliteUpdateHook
struct
{
f
UpdateHook
d
interface
{}
}
//export goXUpdateHook
func
goXUpdateHook
(
pArg
unsafe
.
Pointer
,
action
C
.
int
,
db
,
table
*
C
.
char
,
rowId
C
.
sqlite3_int64
)
{
arg
:=
(
*
sqliteUpdateHook
)(
pArg
)
arg
.
f
(
arg
.
d
,
Action
(
action
),
C
.
GoString
(
db
),
C
.
GoString
(
table
),
int64
(
rowId
))
}
// Calls http://sqlite.org/c3ref/update_hook.html
func
(
c
*
Conn
)
UpdateHook
(
f
UpdateHook
,
arg
interface
{})
{
if
f
==
nil
{
c
.
updateHook
=
nil
C
.
sqlite3_update_hook
(
c
.
db
,
nil
,
nil
)
}
// To make sure it is not gced, keep a reference in the connection.
c
.
updateHook
=
&
sqliteUpdateHook
{
f
,
arg
}
C
.
goSqlite3UpdateHook
(
c
.
db
,
unsafe
.
Pointer
(
c
.
updateHook
))
}
sqlite.go
View file @
8f71d095
...
...
@@ -140,6 +140,7 @@ type Conn struct {
profile
*
sqliteProfile
progressHandler
*
sqliteProgressHandler
trace
*
sqliteTrace
updateHook
*
sqliteUpdateHook
}
// Calls http://sqlite.org/c3ref/libversion.html
...
...
trace_test.go
View file @
8f71d095
package
sqlite_test
import
(
//
"fmt"
"fmt"
.
"github.com/gwenn/gosqlite"
"testing"
)
...
...
@@ -24,6 +24,10 @@ func progressHandler(d interface{}) int {
return
0
}
func
update_hook
(
d
interface
{},
a
Action
,
db
,
table
string
,
rowId
int64
)
{
fmt
.
Printf
(
"%s: %d, %s.%s.%d
\n
"
,
d
,
a
,
db
,
table
,
rowId
)
}
func
TestNoTrace
(
t
*
testing
.
T
)
{
db
,
err
:=
Open
(
""
)
if
err
!=
nil
{
...
...
@@ -34,6 +38,7 @@ func TestNoTrace(t *testing.T) {
db
.
Profile
(
nil
,
nil
)
db
.
ProgressHandler
(
nil
,
0
,
nil
)
db
.
BusyHandler
(
nil
,
nil
)
db
.
UpdateHook
(
nil
,
nil
)
db
.
Close
()
}
...
...
@@ -46,5 +51,6 @@ func TestTrace(t *testing.T) {
}
db
.
Profile
(
profile
,
"PROFILE"
)
db
.
ProgressHandler
(
progressHandler
,
1
,
/*20*/
nil
)
db
.
UpdateHook
(
update_hook
,
"TEST"
)
db
.
Exists
(
"SELECT 1 WHERE 1 = ?"
,
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