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
2a5b9ead
Commit
2a5b9ead
authored
Mar 03, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another step toward Stmt cache support.
parent
a61a41f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
21 deletions
+29
-21
cache.go
cache.go
+6
-6
meta.go
meta.go
+6
-6
sqlite.go
sqlite.go
+7
-7
stmt.go
stmt.go
+10
-2
No files found.
cache.go
View file @
2a5b9ead
...
...
@@ -49,11 +49,10 @@ func (c *Cache) find(sql string) *Stmt {
return
nil
}
// T
ODO To be called instead of
Stmt#Finalize
func
(
c
*
Cache
)
release
(
s
*
Stmt
)
{
// T
o be called in
Stmt#Finalize
func
(
c
*
Cache
)
release
(
s
*
Stmt
)
error
{
if
c
.
maxSize
<=
0
||
len
(
s
.
tail
)
>
0
{
s
.
Finalize
()
return
return
s
.
finalize
()
}
c
.
m
.
Lock
()
defer
c
.
m
.
Unlock
()
...
...
@@ -61,9 +60,10 @@ func (c *Cache) release(s *Stmt) {
for
c
.
l
.
Len
()
>
c
.
maxSize
{
v
:=
c
.
l
.
Remove
(
c
.
l
.
Back
())
if
s
,
ok
:=
v
.
(
*
Stmt
);
ok
{
s
.
F
inalize
()
s
.
f
inalize
()
}
}
return
nil
}
// Finalize and free the cached prepared statements
...
...
@@ -79,7 +79,7 @@ func (c *Cache) flush() {
next
=
e
.
Next
()
v
:=
c
.
l
.
Remove
(
e
)
if
s
,
ok
:=
v
.
(
*
Stmt
);
ok
{
s
.
F
inalize
()
s
.
f
inalize
()
}
else
{
panic
(
fmt
.
Sprintf
(
"unexpected element in Stmt cache: %#v"
,
v
))
}
...
...
meta.go
View file @
2a5b9ead
...
...
@@ -40,7 +40,7 @@ func (c *Conn) Databases() (map[string]string, error) {
if
err
!=
nil
{
return
nil
,
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
var
databases
map
[
string
]
string
=
make
(
map
[
string
]
string
)
var
name
,
file
string
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
...
...
@@ -63,7 +63,7 @@ func (c *Conn) Tables() ([]string, error) {
if
err
!=
nil
{
return
nil
,
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
var
tables
[]
string
=
make
([]
string
,
0
,
20
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
name
,
_
:=
s
.
ScanText
(
0
)
...
...
@@ -95,7 +95,7 @@ func (c *Conn) Columns(table string) ([]Column, error) {
if
err
!=
nil
{
return
nil
,
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
var
columns
[]
Column
=
make
([]
Column
,
0
,
20
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
c
:=
Column
{}
...
...
@@ -148,7 +148,7 @@ func (c *Conn) ForeignKeys(table string) (map[int]*ForeignKey, error) {
if
err
!=
nil
{
return
nil
,
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
var
fks
=
make
(
map
[
int
]
*
ForeignKey
)
var
id
,
seq
int
var
ref
,
from
,
to
string
...
...
@@ -185,7 +185,7 @@ func (c *Conn) Indexes(table string) ([]Index, error) {
if
err
!=
nil
{
return
nil
,
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
var
indexes
[]
Index
=
make
([]
Index
,
0
,
5
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
i
:=
Index
{}
...
...
@@ -208,7 +208,7 @@ func (c *Conn) IndexColumns(index string) ([]Column, error) {
if
err
!=
nil
{
return
nil
,
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
var
columns
[]
Column
=
make
([]
Column
,
0
,
5
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
c
:=
Column
{}
...
...
sqlite.go
View file @
2a5b9ead
...
...
@@ -319,24 +319,24 @@ func (c *Conn) Exec(cmd string, args ...interface{}) error {
}
else
if
s
.
stmt
==
nil
{
// this happens for a comment or white-space
cmd
=
s
.
tail
if
err
=
s
.
F
inalize
();
err
!=
nil
{
if
err
=
s
.
f
inalize
();
err
!=
nil
{
return
err
}
continue
}
err
=
s
.
Exec
(
args
...
)
if
err
!=
nil
{
s
.
F
inalize
()
s
.
f
inalize
()
return
err
}
if
len
(
s
.
tail
)
>
0
{
if
len
(
args
)
>
0
{
s
.
F
inalize
()
s
.
f
inalize
()
return
c
.
specificError
(
"Cannot execute multiple statements when args are specified"
)
}
}
cmd
=
s
.
tail
if
err
=
s
.
F
inalize
();
err
!=
nil
{
if
err
=
s
.
f
inalize
();
err
!=
nil
{
return
err
}
}
...
...
@@ -349,7 +349,7 @@ func (c *Conn) Exists(query string, args ...interface{}) (bool, error) {
if
err
!=
nil
{
return
false
,
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
return
s
.
Next
()
}
...
...
@@ -360,7 +360,7 @@ func (c *Conn) OneValue(query string, value interface{}, args ...interface{}) er
if
err
!=
nil
{
return
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
b
,
err
:=
s
.
Next
()
if
err
!=
nil
{
return
err
...
...
@@ -445,7 +445,7 @@ func (c *Conn) exec(cmd string) error {
if
err
!=
nil
{
return
err
}
defer
s
.
F
inalize
()
defer
s
.
f
inalize
()
rv
:=
C
.
sqlite3_step
(
s
.
stmt
)
if
Errno
(
rv
)
!=
Done
{
return
s
.
error
(
rv
)
...
...
stmt.go
View file @
2a5b9ead
...
...
@@ -76,8 +76,10 @@ type Stmt struct {
cols
map
[
string
]
int
// cached columns index by name
bindParameterCount
int
params
map
[
string
]
int
// cached parameter index by name
// Enable type check in Scan methods
// Enable type check in Scan methods
(default true)
CheckTypeMismatch
bool
// Tell if the stmt should be cached (default false)
Cacheable
bool
}
// Compile an SQL statement and optionally bind values.
...
...
@@ -109,7 +111,7 @@ func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, error) {
if
len
(
args
)
>
0
{
err
:=
s
.
Bind
(
args
...
)
if
err
!=
nil
{
s
.
F
inalize
()
s
.
f
inalize
()
return
nil
,
err
}
}
...
...
@@ -880,6 +882,12 @@ func (s *Stmt) Busy() bool {
// Destroy a prepared statement
// (See http://sqlite.org/c3ref/finalize.html)
func
(
s
*
Stmt
)
Finalize
()
error
{
if
s
.
Cacheable
{
return
s
.
c
.
stmtCache
.
release
(
s
)
}
return
s
.
finalize
()
}
func
(
s
*
Stmt
)
finalize
()
error
{
rv
:=
C
.
sqlite3_finalize
(
s
.
stmt
)
if
rv
!=
C
.
SQLITE_OK
{
return
s
.
error
(
rv
)
...
...
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