Commit cc56fa03 authored by gwenn's avatar gwenn

Activate Stmt cache by default.

parent e2ff8991
...@@ -6,6 +6,7 @@ This binding implements the "database/sql/driver" interface. ...@@ -6,6 +6,7 @@ This binding implements the "database/sql/driver" interface.
Open supports flags. Open supports flags.
Conn#Exec handles multiple statements (separated by semicolons) properly. Conn#Exec handles multiple statements (separated by semicolons) properly.
Conn#Prepare can optionnaly #Bind as well. Conn#Prepare can optionnaly #Bind as well.
Conn#CacheOrPrepare can reused already prepared Stmt.
Conn#Close ensures that all dangling statements are finalized. Conn#Close ensures that all dangling statements are finalized.
Stmt#Exec is renamed in Stmt#Bind and a new Stmt#Exec method is introduced to #Bind and #Step. Stmt#Exec is renamed in Stmt#Bind and a new Stmt#Exec method is introduced to #Bind and #Step.
Stmt#Bind uses native sqlite3_bind_x methods and failed if unsupported type. Stmt#Bind uses native sqlite3_bind_x methods and failed if unsupported type.
...@@ -81,11 +82,16 @@ Conn#CreateScalarFunction ...@@ -81,11 +82,16 @@ Conn#CreateScalarFunction
Conn#CreateAggregateFunction Conn#CreateAggregateFunction
$ go test -test.bench '.*' $ go test -test.bench '.*'
BenchmarkValuesScan 500000 4658 ns/op BenchmarkValuesScan 500000 4658 ns/op
BenchmarkScan 500000 4324 ns/op BenchmarkScan 500000 324 ns/op
BenchmarkNamedScan 200000 9221 ns/op BenchmarkNamedScan 200000 9221 ns/op
BenchmarkInsert 500000 6088 ns/op
BenchmarkNamedInsert 500000 6726 ns/op BenchmarkInsert 500000 6088 ns/op
BenchmarkLike 1000000 2508 ns/op BenchmarkNamedInsert 500000 6726 ns/op
BenchmarkHalf 500000 4811 ns/op
BenchmarkRegexp 500000 6170 ns/op BenchmarkDisabledCache 100000 19235 ns/op
\ No newline at end of file BenchmarkEnabledCache 1000000 1133 ns/op
BenchmarkLike 1000000 2508 ns/op
BenchmarkHalf 500000 4811 ns/op
BenchmarkRegexp 500000 6170 ns/op
\ No newline at end of file
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
) )
const ( const (
defaultCacheSize = 0 defaultCacheSize = 10
) )
// Like http://www.sqlite.org/tclsqlite.html#cache // Like http://www.sqlite.org/tclsqlite.html#cache
......
...@@ -56,7 +56,7 @@ func (c *connImpl) RowsAffected() (int64, error) { ...@@ -56,7 +56,7 @@ func (c *connImpl) RowsAffected() (int64, error) {
} }
func (c *connImpl) Prepare(query string) (driver.Stmt, error) { func (c *connImpl) Prepare(query string) (driver.Stmt, error) {
s, err := c.c.Prepare(query) s, err := c.c.CacheOrPrepare(query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -345,22 +345,28 @@ func (c *Conn) Exec(cmd string, args ...interface{}) error { ...@@ -345,22 +345,28 @@ func (c *Conn) Exec(cmd string, args ...interface{}) error {
// Return true if the specified query returns at least one row. // Return true if the specified query returns at least one row.
func (c *Conn) Exists(query string, args ...interface{}) (bool, error) { func (c *Conn) Exists(query string, args ...interface{}) (bool, error) {
s, err := c.Prepare(query, args...) s, err := c.CacheOrPrepare(query, args...)
if err != nil { if err != nil {
return false, err return false, err
} }
defer s.finalize() defer func() {
s.Reset()
s.Finalize()
}()
return s.Next() return s.Next()
} }
// Use it with SELECT that returns only one row with only one column. // Use it with SELECT that returns only one row with only one column.
// Returns io.EOF when there is no row. // Returns io.EOF when there is no row.
func (c *Conn) OneValue(query string, value interface{}, args ...interface{}) error { func (c *Conn) OneValue(query string, value interface{}, args ...interface{}) error {
s, err := c.Prepare(query, args...) s, err := c.CacheOrPrepare(query, args...)
if err != nil { if err != nil {
return err return err
} }
defer s.finalize() defer func() {
s.Reset()
s.Finalize()
}()
b, err := s.Next() b, err := s.Next()
if err != nil { if err != nil {
return err return err
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment