aboutsummaryrefslogtreecommitdiff
path: root/sqlite3.go
diff options
context:
space:
mode:
authorCharlie Vieth <charlie.vieth@gmail.com>2023-02-11 17:14:42 -0500
committerGitHub <noreply@github.com>2023-02-11 17:14:42 -0500
commit7ce62b2ade0b712c46b1ecc6a0ee179dc417816c (patch)
treefd245337c8854f0f096f36e6cdf7f6b573340fb2 /sqlite3.go
parentAdd Serialize and Deserialize support (#1089) (diff)
downloadgolite-7ce62b2ade0b712c46b1ecc6a0ee179dc417816c.tar.gz
golite-7ce62b2ade0b712c46b1ecc6a0ee179dc417816c.tar.xz
Replace namedValue with driver.NamedValue to avoid copying exec/query args (#1128)
Diffstat (limited to 'sqlite3.go')
-rw-r--r--sqlite3.go38
1 files changed, 16 insertions, 22 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 9c0f4d8..5e4e2ff 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -837,9 +837,9 @@ func lastError(db *C.sqlite3) error {
// Exec implements Execer.
func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
- list := make([]namedValue, len(args))
+ list := make([]driver.NamedValue, len(args))
for i, v := range args {
- list[i] = namedValue{
+ list[i] = driver.NamedValue{
Ordinal: i + 1,
Value: v,
}
@@ -847,7 +847,7 @@ func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, err
return c.exec(context.Background(), query, list)
}
-func (c *SQLiteConn) exec(ctx context.Context, query string, args []namedValue) (driver.Result, error) {
+func (c *SQLiteConn) exec(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
start := 0
for {
s, err := c.prepare(ctx, query)
@@ -856,7 +856,7 @@ func (c *SQLiteConn) exec(ctx context.Context, query string, args []namedValue)
}
var res driver.Result
if s.(*SQLiteStmt).s != nil {
- stmtArgs := make([]namedValue, 0, len(args))
+ stmtArgs := make([]driver.NamedValue, 0, len(args))
na := s.NumInput()
if len(args)-start < na {
s.Close()
@@ -894,17 +894,11 @@ func (c *SQLiteConn) exec(ctx context.Context, query string, args []namedValue)
}
}
-type namedValue struct {
- Name string
- Ordinal int
- Value driver.Value
-}
-
// Query implements Queryer.
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
- list := make([]namedValue, len(args))
+ list := make([]driver.NamedValue, len(args))
for i, v := range args {
- list[i] = namedValue{
+ list[i] = driver.NamedValue{
Ordinal: i + 1,
Value: v,
}
@@ -912,10 +906,10 @@ func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, erro
return c.query(context.Background(), query, list)
}
-func (c *SQLiteConn) query(ctx context.Context, query string, args []namedValue) (driver.Rows, error) {
+func (c *SQLiteConn) query(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
start := 0
for {
- stmtArgs := make([]namedValue, 0, len(args))
+ stmtArgs := make([]driver.NamedValue, 0, len(args))
s, err := c.prepare(ctx, query)
if err != nil {
return nil, err
@@ -1912,7 +1906,7 @@ func (s *SQLiteStmt) NumInput() int {
var placeHolder = []byte{0}
-func (s *SQLiteStmt) bind(args []namedValue) error {
+func (s *SQLiteStmt) bind(args []driver.NamedValue) error {
rv := C.sqlite3_reset(s.s)
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
return s.c.lastError()
@@ -1982,9 +1976,9 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
// Query the statement with arguments. Return records.
func (s *SQLiteStmt) Query(args []driver.Value) (driver.Rows, error) {
- list := make([]namedValue, len(args))
+ list := make([]driver.NamedValue, len(args))
for i, v := range args {
- list[i] = namedValue{
+ list[i] = driver.NamedValue{
Ordinal: i + 1,
Value: v,
}
@@ -1992,7 +1986,7 @@ func (s *SQLiteStmt) Query(args []driver.Value) (driver.Rows, error) {
return s.query(context.Background(), list)
}
-func (s *SQLiteStmt) query(ctx context.Context, args []namedValue) (driver.Rows, error) {
+func (s *SQLiteStmt) query(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
if err := s.bind(args); err != nil {
return nil, err
}
@@ -2022,9 +2016,9 @@ func (r *SQLiteResult) RowsAffected() (int64, error) {
// Exec execute the statement with arguments. Return result object.
func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) {
- list := make([]namedValue, len(args))
+ list := make([]driver.NamedValue, len(args))
for i, v := range args {
- list[i] = namedValue{
+ list[i] = driver.NamedValue{
Ordinal: i + 1,
Value: v,
}
@@ -2041,7 +2035,7 @@ func isInterruptErr(err error) bool {
}
// exec executes a query that doesn't return rows. Attempts to honor context timeout.
-func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result, error) {
+func (s *SQLiteStmt) exec(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
if ctx.Done() == nil {
return s.execSync(args)
}
@@ -2073,7 +2067,7 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result
return rv.r, rv.err
}
-func (s *SQLiteStmt) execSync(args []namedValue) (driver.Result, error) {
+func (s *SQLiteStmt) execSync(args []driver.NamedValue) (driver.Result, error) {
if err := s.bind(args); err != nil {
C.sqlite3_reset(s.s)
C.sqlite3_clear_bindings(s.s)