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
3dd0fe33
Commit
3dd0fe33
authored
Nov 23, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support to SQLITE_CONFIG_LOG.
parent
412216e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
2 deletions
+54
-2
trace.go
trace.go
+42
-2
trace_test.go
trace_test.go
+12
-0
No files found.
trace.go
View file @
3dd0fe33
...
...
@@ -43,6 +43,16 @@ static void goSqlite3ProgressHandler(sqlite3 *db, int numOps, void *udp) {
static void my_log(int iErrCode, char *msg) {
sqlite3_log(iErrCode, msg);
}
extern void goXLog(void *udp, int err, const char *msg);
static int goSqlite3ConfigLog(void *udp) {
if (udp) {
return sqlite3_config(SQLITE_CONFIG_LOG, goXLog, udp);
} else {
return sqlite3_config(SQLITE_CONFIG_LOG, NULL, NULL);
}
}
*/
import
"C"
...
...
@@ -267,6 +277,36 @@ func Log(err /*Errno*/ int, msg string) {
C
.
my_log
(
C
.
int
(
err
),
cs
)
}
// TODO sqlite3_config(SQLITE_CONFIG_LOG,...)
// #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
// The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a function with a call signature of void(*)(void*,int,const char*), and a pointer to void.
type
Logger
func
(
udp
interface
{},
err
error
,
msg
string
)
type
sqliteLogger
struct
{
f
Logger
udp
interface
{}
}
//export goXLog
func
goXLog
(
udp
unsafe
.
Pointer
,
err
C
.
int
,
msg
*
C
.
char
)
{
arg
:=
(
*
sqliteLogger
)(
udp
)
arg
.
f
(
arg
.
udp
,
Errno
(
err
),
C
.
GoString
(
msg
))
return
}
var
logger
*
sqliteLogger
// Calls sqlite3_config(SQLITE_CONFIG_LOG,...)
func
ConfigLog
(
f
Logger
,
udp
interface
{})
error
{
var
rv
C
.
int
if
f
==
nil
{
logger
=
nil
rv
=
C
.
goSqlite3ConfigLog
(
nil
)
}
else
{
// To make sure it is not gced, keep a reference.
logger
=
&
sqliteLogger
{
f
,
udp
}
rv
=
C
.
goSqlite3ConfigLog
(
unsafe
.
Pointer
(
logger
))
}
if
rv
==
C
.
SQLITE_OK
{
return
nil
}
return
Errno
(
rv
)
}
trace_test.go
View file @
3dd0fe33
...
...
@@ -6,6 +6,10 @@ import (
"testing"
)
func
init
()
{
ConfigLog
(
log
,
"LOG"
)
}
func
trace
(
d
interface
{},
sql
string
)
{
//fmt.Printf("%s: %s\n", d, sql)
}
...
...
@@ -37,6 +41,10 @@ func updateHook(d interface{}, a Action, dbName, tableName string, rowId int64)
fmt
.
Printf
(
"%s: %d, %s.%s.%d
\n
"
,
d
,
a
,
dbName
,
tableName
,
rowId
)
}
func
log
(
d
interface
{},
err
error
,
msg
string
)
{
fmt
.
Printf
(
"%s: %s, %s
\n
"
,
d
,
err
,
msg
)
}
func
TestNoTrace
(
t
*
testing
.
T
)
{
db
,
err
:=
Open
(
""
)
if
err
!=
nil
{
...
...
@@ -67,3 +75,7 @@ func TestTrace(t *testing.T) {
db
.
UpdateHook
(
updateHook
,
"UPD"
)
db
.
Exists
(
"SELECT 1 WHERE 1 = ?"
,
1
)
}
func
TestLog
(
t
*
testing
.
T
)
{
Log
(
0
,
"One message"
)
}
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