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
1624e5b0
Commit
1624e5b0
authored
Dec 20, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce ScanValues.
parent
4e29d083
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
24 deletions
+49
-24
bench_test.go
bench_test.go
+38
-18
driver.go
driver.go
+1
-3
sqlite.go
sqlite.go
+10
-3
No files found.
bench_test.go
View file @
1624e5b0
...
...
@@ -5,20 +5,42 @@ import (
"testing"
)
func
BenchmarkScan
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
func
fill
(
db
*
Conn
,
n
int
)
{
db
.
Exec
(
"DROP TABLE IF EXISTS test"
)
db
.
Exec
(
"CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, float_num REAL, int_num INTEGER, a_string TEXT)"
)
db
.
Begin
()
s
,
_
:=
db
.
Prepare
(
"INSERT INTO test (float_num, int_num, a_string) VALUES (?, ?, ?)"
)
for
i
:=
0
;
i
<
1000
;
i
++
{
db
.
Begin
()
for
i
:=
0
;
i
<
n
;
i
++
{
s
.
Exec
(
float64
(
i
)
*
float64
(
3.14
),
i
,
"hello"
)
}
s
.
Finalize
()
db
.
Commit
()
}
func
BenchmarkValuesScan
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
fill
(
db
,
1000
)
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
cs
,
_
:=
db
.
Prepare
(
"SELECT float_num, int_num, a_string FROM test"
)
values
:=
make
([]
interface
{},
3
)
for
Must
(
cs
.
Next
())
{
cs
.
ScanValues
(
values
)
}
cs
.
Finalize
()
}
}
func
BenchmarkScan
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
fill
(
db
,
1000
)
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
...
...
@@ -39,16 +61,7 @@ func BenchmarkNamedScan(b *testing.B) {
b
.
StopTimer
()
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
db
.
Exec
(
"DROP TABLE IF EXISTS test"
)
db
.
Exec
(
"CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, float_num REAL, int_num INTEGER, a_string TEXT)"
)
db
.
Begin
()
s
,
_
:=
db
.
Prepare
(
"INSERT INTO test (float_num, int_num, a_string) VALUES (?, ?, ?)"
)
for
i
:=
0
;
i
<
1000
;
i
++
{
s
.
Exec
(
float64
(
i
)
*
float64
(
3.14
),
i
,
"hello"
)
}
s
.
Finalize
()
db
.
Commit
()
fill
(
db
,
1000
)
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
...
...
@@ -66,18 +79,25 @@ func BenchmarkNamedScan(b *testing.B) {
}
func
BenchmarkInsert
(
b
*
testing
.
B
)
{
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
fill
(
db
,
b
.
N
)
}
func
BenchmarkNamedInsert
(
b
*
testing
.
B
)
{
db
,
_
:=
Open
(
""
)
defer
db
.
Close
()
db
.
Exec
(
"DROP TABLE IF EXISTS test"
)
db
.
Exec
(
"CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT,"
+
" float_num REAL, int_num INTEGER, a_string TEXT)"
)
s
,
_
:=
db
.
Prepare
(
"INSERT INTO test (float_num, int_num, a_string)"
+
" VALUES (
?, ?, ?
)"
)
" VALUES (
:f, :i, :s
)"
)
defer
s
.
Finalize
()
db
.
Begin
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
s
.
Exec
(
float64
(
i
)
*
float64
(
3.14
),
i
,
"hello"
)
s
.
NamedBind
(
"f"
,
float64
(
i
)
*
float64
(
3.14
),
"i"
,
i
,
"s"
,
"hello"
)
s
.
Next
()
}
db
.
Commit
()
}
driver.go
View file @
1624e5b0
...
...
@@ -121,8 +121,6 @@ func (s *stmtImpl) Next(dest []interface{}) error {
if
!
ok
{
return
io
.
EOF
}
for
i
:=
range
dest
{
dest
[
i
]
=
s
.
s
.
ScanValue
(
i
)
}
s
.
s
.
ScanValues
(
dest
)
return
nil
}
sqlite.go
View file @
1624e5b0
...
...
@@ -477,7 +477,7 @@ func (s *Stmt) BindParameterCount() int {
return
int
(
C
.
sqlite3_bind_parameter_count
(
s
.
stmt
))
}
// Index of a parameter with a given name
// Index of a parameter with a given name
(cached)
// Calls http://sqlite.org/c3ref/bind_parameter_index.html
func
(
s
*
Stmt
)
BindParameterIndex
(
name
string
)
(
int
,
error
)
{
if
s
.
params
==
nil
{
...
...
@@ -511,7 +511,7 @@ func (s *Stmt) BindParameterName(i int) (string, error) {
// Bind parameters by their name (name1, value1, ...)
func
(
s
*
Stmt
)
NamedBind
(
args
...
interface
{})
error
{
err
:=
s
.
Reset
()
// TODO sqlite3_clear_bindings?
err
:=
s
.
Reset
()
if
err
!=
nil
{
return
err
}
...
...
@@ -539,7 +539,7 @@ func (s *Stmt) NamedBind(args ...interface{}) error {
// Calls sqlite3_bind_parameter_count and sqlite3_bind_(blob|double|int|int64|null|text) depending on args type.
// http://sqlite.org/c3ref/bind_blob.html
func
(
s
*
Stmt
)
Bind
(
args
...
interface
{})
error
{
err
:=
s
.
Reset
()
// TODO sqlite3_clear_bindings?
err
:=
s
.
Reset
()
if
err
!=
nil
{
return
err
}
...
...
@@ -890,6 +890,13 @@ func (s *Stmt) ScanValue(index int) (value interface{}) {
return
}
// Like ScanValue on several columns
func
(
s
*
Stmt
)
ScanValues
(
values
[]
interface
{})
{
for
i
:=
0
;
i
<
len
(
values
);
i
++
{
values
[
i
]
=
s
.
ScanValue
(
i
)
}
}
// The leftmost column/index is number 0.
// Returns true when column is null.
// Calls sqlite3_column_text.
...
...
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