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
220759b9
Commit
220759b9
authored
Jun 21, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Benchmark IntArray module.
parent
e802ee80
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
19 deletions
+111
-19
csv.go
csv.go
+4
-6
csv_test.go
csv_test.go
+0
-2
intarray.go
intarray.go
+25
-5
intarray_test.go
intarray_test.go
+82
-2
limit.go
limit.go
+0
-2
limit_test.go
limit_test.go
+0
-2
No files found.
csv.go
View file @
220759b9
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build all
package
sqlite
import
(
...
...
@@ -287,13 +285,13 @@ func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error
type
ImportConfig
struct
{
Name
string
// the name of the input; used only for error reports
Separator
byte
// CSV separator
Quoted
bool
// CSV field are quoted or not
Quoted
bool
// CSV field
s
are quoted or not
Guess
bool
// guess separator
Trim
bool
// trim spaces
Comment
byte
// comment marker
Trim
bool
//
optional,
trim spaces
Comment
byte
//
optinal,
comment marker
Headers
bool
// skip headers (first line)
Types
[]
Affinity
// optional, when target table does not exist, specify columns type
Log
io
.
Writer
// optional, used to tace lines in error
Log
io
.
Writer
// optional, used to t
r
ace lines in error
}
func
(
ic
ImportConfig
)
getType
(
i
int
)
string
{
...
...
csv_test.go
View file @
220759b9
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build all
package
sqlite_test
import
(
...
...
intarray.go
View file @
220759b9
...
...
@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build all
package
sqlite
import
"fmt"
import
(
"errors"
"fmt"
)
// IntArray is the Go-language interface definition for the "intarray" or
// integer array virtual table for SQLite.
...
...
@@ -69,9 +70,12 @@ import "fmt"
// action to free the intarray objects (except if connections are pooled...).
type
IntArray
interface
{
Bind
(
elements
[]
int64
)
Drop
()
error
}
type
intArray
struct
{
c
*
Conn
name
string
content
[]
int64
}
...
...
@@ -141,12 +145,12 @@ func (vc *intArrayVTabCursor) Rowid() (int64, error) {
// explicitly by the application, the virtual table will be dropped implicitly
// by the system when the database connection is closed.
func
(
c
*
Conn
)
CreateIntArray
(
name
string
)
(
IntArray
,
error
)
{
module
:=
new
(
intArray
)
module
:=
&
intArray
{
c
:
c
,
name
:
name
}
if
err
:=
c
.
CreateModule
(
name
,
module
);
err
!=
nil
{
return
nil
,
err
}
name
=
escapeQuote
(
name
)
if
err
:=
c
.
FastExec
(
fmt
.
Sprintf
(
"CREATE VIRTUAL TABLE temp.%s USING %s"
,
name
,
name
));
err
!=
nil
{
if
err
:=
c
.
FastExec
(
fmt
.
Sprintf
(
`CREATE VIRTUAL TABLE temp."%s" USING "%s"`
,
name
,
name
));
err
!=
nil
{
return
nil
,
err
}
return
module
,
nil
...
...
@@ -160,3 +164,19 @@ func (c *Conn) CreateIntArray(name string) (IntArray, error) {
func
(
m
*
intArray
)
Bind
(
elements
[]
int64
)
{
m
.
content
=
elements
}
// Drop underlying virtual table.
func
(
m
*
intArray
)
Drop
()
error
{
if
m
==
nil
{
return
errors
.
New
(
"nil sqlite intarray"
)
}
if
m
.
c
==
nil
{
return
nil
}
err
:=
m
.
c
.
FastExec
(
fmt
.
Sprintf
(
`DROP TABLE temp."%s"`
,
escapeQuote
(
m
.
name
)))
if
err
!=
nil
{
return
err
}
m
.
c
=
nil
return
nil
}
intarray_test.go
View file @
220759b9
...
...
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build all
package
sqlite_test
import
(
"fmt"
"math/rand"
"strings"
"github.com/bmizerany/assert"
.
"github.com/gwenn/gosqlite"
...
...
@@ -70,4 +72,82 @@ func TestIntArrayModule(t *testing.T) {
p2
.
Bind
([]
int64
{
3
,
4
,
5
})
p3
.
Bind
([]
int64
{
0
,
-
5
})
assert
.
T
(
t
,
!
checkStep
(
t
,
s
))
checkNoError
(
t
,
p1
.
Drop
(),
"%s"
)
checkNoError
(
t
,
p2
.
Drop
(),
"%s"
)
checkNoError
(
t
,
p3
.
Drop
(),
"%s"
)
}
func
BenchmarkNoIntArray
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
err
:=
Open
(
":memory:"
)
panicOnError
(
b
,
err
)
defer
db
.
Close
()
panicOnError
(
b
,
db
.
Exec
(
"CREATE TABLE rand (r INT)"
))
values
:=
rand
.
Perm
(
1000
)
for
_
,
v
:=
range
values
{
panicOnError
(
b
,
db
.
Exec
(
"INSERT INTO rand (r) VALUES (?)"
,
v
))
}
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
l
:=
rand
.
Intn
(
999
)
+
1
// at least one value
sql
:=
fmt
.
Sprintf
(
"SELECT * FROM rand WHERE r IN (?%s)"
,
strings
.
Repeat
(
", ?"
,
l
-
1
))
s
,
err
:=
db
.
Prepare
(
sql
)
panicOnError
(
b
,
err
)
for
j
:=
0
;
j
<
l
;
j
++
{
panicOnError
(
b
,
s
.
BindByIndex
(
j
+
1
,
values
[
j
]))
}
nr
:=
0
err
=
s
.
Select
(
func
(
s
*
Stmt
)
error
{
_
,
_
,
err
=
s
.
ScanInt32
(
0
)
nr
++
return
err
})
panicOnError
(
b
,
err
)
if
nr
!=
l
{
b
.
Fatalf
(
"Only %d values; %d expected"
,
nr
,
l
)
}
panicOnError
(
b
,
s
.
Finalize
())
}
}
func
BenchmarkIntArray
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
db
,
err
:=
Open
(
":memory:"
)
panicOnError
(
b
,
err
)
defer
db
.
Close
()
panicOnError
(
b
,
db
.
Exec
(
"CREATE TABLE rand (r INT)"
))
perms
:=
rand
.
Perm
(
1000
)
values
:=
make
([]
int64
,
len
(
perms
))
for
i
,
v
:=
range
perms
{
panicOnError
(
b
,
db
.
Exec
(
"INSERT INTO rand (r) VALUES (?)"
,
v
))
values
[
i
]
=
int64
(
v
)
}
b
.
StartTimer
()
p
,
err
:=
db
.
CreateIntArray
(
"myia"
)
panicOnError
(
b
,
err
)
defer
p
.
Drop
()
s
,
err
:=
db
.
Prepare
(
"SELECT * FROM rand WHERE r IN myia"
)
panicOnError
(
b
,
err
)
defer
s
.
Finalize
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
l
:=
rand
.
Intn
(
999
)
+
1
// at least one value
p
.
Bind
(
values
[
0
:
l
])
nr
:=
0
err
=
s
.
Select
(
func
(
s
*
Stmt
)
error
{
_
,
_
,
err
=
s
.
ScanInt32
(
0
)
nr
++
return
err
})
panicOnError
(
b
,
err
)
if
nr
!=
l
{
b
.
Fatalf
(
"Only %d values; %d expected"
,
nr
,
l
)
}
}
}
limit.go
View file @
220759b9
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build all
package
sqlite
/*
...
...
limit_test.go
View file @
220759b9
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build all
package
sqlite_test
import
(
...
...
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