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
0750ff30
Commit
0750ff30
authored
Mar 02, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce Stmt.ExplainQueryPlan.
parent
ed327e64
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
trace.go
trace.go
+26
-0
trace_test.go
trace_test.go
+15
-1
No files found.
trace.go
View file @
0750ff30
...
@@ -27,6 +27,7 @@ import "C"
...
@@ -27,6 +27,7 @@ import "C"
import
(
import
(
"fmt"
"fmt"
"io"
"time"
"time"
"unsafe"
"unsafe"
)
)
...
@@ -431,3 +432,28 @@ func ConfigUri(b bool) error {
...
@@ -431,3 +432,28 @@ func ConfigUri(b bool) error {
}
}
return
Errno
(
rv
)
return
Errno
(
rv
)
}
}
func
(
s
*
Stmt
)
ExplainQueryPlan
(
w
io
.
Writer
)
error
{
sql
:=
s
.
SQL
()
if
len
(
sql
)
==
0
{
return
s
.
specificError
(
"empty statement"
)
}
explain
:=
Mprintf
(
"EXPLAIN QUERY PLAN %s"
,
s
.
SQL
())
sExplain
,
err
:=
s
.
Conn
()
.
prepare
(
explain
)
if
err
!=
nil
{
return
err
}
defer
sExplain
.
finalize
()
var
selectid
,
order
,
from
int
var
detail
string
err
=
sExplain
.
Select
(
func
(
s
*
Stmt
)
error
{
if
err
:=
s
.
Scan
(
&
selectid
,
&
order
,
&
from
,
&
detail
);
err
!=
nil
{
return
err
}
fmt
.
Fprintf
(
w
,
"%d
\t
%d
\t
%d
\t
%s
\n
"
,
selectid
,
order
,
from
,
detail
)
return
nil
})
return
err
}
trace_test.go
View file @
0750ff30
...
@@ -6,6 +6,7 @@ package sqlite_test
...
@@ -6,6 +6,7 @@ package sqlite_test
import
(
import
(
"fmt"
"fmt"
"os"
"testing"
"testing"
"time"
"time"
...
@@ -119,7 +120,7 @@ func TestTrace(t *testing.T) {
...
@@ -119,7 +120,7 @@ func TestTrace(t *testing.T) {
defer
checkClose
(
db
,
t
)
defer
checkClose
(
db
,
t
)
db
.
Trace
(
trace
,
t
)
db
.
Trace
(
trace
,
t
)
err
:=
db
.
SetAuthorizer
(
authorizer
,
t
)
err
:=
db
.
SetAuthorizer
(
authorizer
,
t
)
checkNoError
(
t
,
err
,
"couldn't set an authorizer"
)
checkNoError
(
t
,
err
,
"couldn't set an authorizer
: %s
"
)
db
.
Profile
(
profile
,
t
)
db
.
Profile
(
profile
,
t
)
db
.
ProgressHandler
(
progressHandler
,
1
,
t
)
db
.
ProgressHandler
(
progressHandler
,
1
,
t
)
db
.
CommitHook
(
commitHook
,
t
)
db
.
CommitHook
(
commitHook
,
t
)
...
@@ -140,3 +141,16 @@ func TestMemory(t *testing.T) {
...
@@ -140,3 +141,16 @@ func TestMemory(t *testing.T) {
limit
:=
SoftHeapLimit
()
limit
:=
SoftHeapLimit
()
assert
.
T
(
t
,
limit
>=
0
,
"soft heap limit positive"
)
assert
.
T
(
t
,
limit
>=
0
,
"soft heap limit positive"
)
}
}
func
TestExplainQueryPlan
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
createTable
(
db
,
t
)
s
,
err
:=
db
.
Prepare
(
"SELECT * FROM test WHERE a_string like ?"
)
checkNoError
(
t
,
err
,
"error while preparing stmt: %s"
)
defer
checkFinalize
(
s
,
t
)
w
,
err
:=
os
.
Open
(
os
.
DevNull
)
checkNoError
(
t
,
err
,
"couldn't open /dev/null: %s"
)
err
=
s
.
ExplainQueryPlan
(
w
)
checkNoError
(
t
,
err
,
"error while explaining query plan: %s"
)
}
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