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
7d923c37
Commit
7d923c37
authored
Sep 14, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improves tracing.
parent
9f08f195
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
4 deletions
+83
-4
sqlite_test.go
sqlite_test.go
+3
-1
trace.go
trace.go
+78
-1
trace_test.go
trace_test.go
+2
-2
No files found.
sqlite_test.go
View file @
7d923c37
...
...
@@ -23,7 +23,9 @@ func open(t *testing.T) *Conn {
if
db
==
nil
{
t
.
Fatal
(
"opened database is nil"
)
}
//db.Profile(profile, "PROFILE")
//db.Profile(profile, t)
//db.Trace(trace, t)
//db.SetAuthorizer(authorizer, t)
return
db
}
...
...
trace.go
View file @
7d923c37
...
...
@@ -25,7 +25,10 @@ int goSqlite3Config(int op, int mode);
*/
import
"C"
import
"unsafe"
import
(
"fmt"
"unsafe"
)
// See Conn.Trace
type
Tracer
func
(
udp
interface
{},
sql
string
)
...
...
@@ -42,6 +45,7 @@ func goXTrace(udp unsafe.Pointer, sql *C.char) {
}
// Trace registers or clears a trace function.
// Prepared statement placeholders are replaced/logged with their assigned values.
// (See sqlite3_trace, http://sqlite.org/c3ref/profile.html)
func
(
c
*
Conn
)
Trace
(
f
Tracer
,
udp
interface
{})
{
if
f
==
nil
{
...
...
@@ -69,6 +73,7 @@ func goXProfile(udp unsafe.Pointer, sql *C.char, nanoseconds C.sqlite3_uint64) {
}
// Profile registers or clears a profile function.
// Prepared statement placeholders are not logged with their assigned values.
// (See sqlite3_profile, http://sqlite.org/c3ref/profile.html)
func
(
c
*
Conn
)
Profile
(
f
Profiler
,
udp
interface
{})
{
if
f
==
nil
{
...
...
@@ -129,6 +134,78 @@ const (
Copy
Action
=
C
.
SQLITE_COPY
)
func
(
a
Action
)
String
()
string
{
switch
a
{
case
CreateIndex
:
return
"CreateIndex"
case
CreateTable
:
return
"CreateTable"
case
CreateTempIndex
:
return
"CreateTempIndex"
case
CreateTempTable
:
return
"CreateTempTable"
case
CreateTempTrigger
:
return
"CreateTempTrigger"
case
CreateTempView
:
return
"CreateTempView"
case
CreateTrigger
:
return
"CreateTrigger"
case
CreateView
:
return
"CreateView"
case
Delete
:
return
"Delete"
case
DropIndex
:
return
"DropIndex"
case
DropTable
:
return
"DropTable"
case
DropTempIndex
:
return
"DropTempIndex"
case
DropTempTable
:
return
"DropTempTable"
case
DropTempTrigger
:
return
"DropTempTrigger"
case
DropTempView
:
return
"DropTempView"
case
DropTrigger
:
return
"DropTrigger"
case
DropView
:
return
"DropView"
case
Insert
:
return
"Insert"
case
Pragma
:
return
"Pragma"
case
Read
:
return
"Read"
case
Select
:
return
"Select"
case
Transaction
:
return
"Transaction"
case
Update
:
return
"Update"
case
Attach
:
return
"Attach"
case
Detach
:
return
"Detach"
case
AlterTable
:
return
"AlterTable"
case
Reindex
:
return
"Reindex"
case
Analyze
:
return
"Analyze"
case
CreateVTable
:
return
"CreateVTable"
case
DropVTable
:
return
"DropVTable"
case
Function
:
return
"Function"
case
Savepoint
:
return
"Savepoint"
case
Copy
:
return
"Copy"
}
return
fmt
.
Sprintf
(
"Unknown Action: %d"
,
a
)
}
// See Conn.SetAuthorizer
type
Authorizer
func
(
udp
interface
{},
action
Action
,
arg1
,
arg2
,
dbName
,
triggerName
string
)
Auth
...
...
trace_test.go
View file @
7d923c37
...
...
@@ -31,9 +31,9 @@ func trace(d interface{}, sql string) {
func
authorizer
(
d
interface
{},
action
Action
,
arg1
,
arg2
,
dbName
,
triggerName
string
)
Auth
{
if
t
,
ok
:=
d
.
(
*
testing
.
T
);
ok
{
t
.
Logf
(
"AUTH: %
d
, %s, %s, %s, %s
\n
"
,
action
,
arg1
,
arg2
,
dbName
,
triggerName
)
t
.
Logf
(
"AUTH: %
s
, %s, %s, %s, %s
\n
"
,
action
,
arg1
,
arg2
,
dbName
,
triggerName
)
}
else
{
fmt
.
Printf
(
"%s: %
d
, %s, %s, %s, %s
\n
"
,
d
,
action
,
arg1
,
arg2
,
dbName
,
triggerName
)
fmt
.
Printf
(
"%s: %
s
, %s, %s, %s, %s
\n
"
,
d
,
action
,
arg1
,
arg2
,
dbName
,
triggerName
)
}
return
AuthOk
}
...
...
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