diff options
| author | Daniel Theophanes <kardianos@gmail.com> | 2016-10-03 09:49:25 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-10-17 07:56:35 +0000 |
| commit | 707a83341b8c7973f4e0fce731fa279c618f233b (patch) | |
| tree | 3436b372be1d863a3e5f2f2e837fbabe577252c8 /src/database/sql/driver/driver.go | |
| parent | 99df54f19696e26bea8d6a052d8d91ddb1e4ea65 (diff) | |
| download | go-707a83341b8c7973f4e0fce731fa279c618f233b.tar.xz | |
database/sql: add option to use named parameter in query arguments
Modify the new Context methods to take a name-value driver struct.
This will require more modifications to drivers to use, but will
reduce the overall number of structures that need to be maintained
over time.
Fixes #12381
Change-Id: I30747533ce418a1be5991a0c8767a26e8451adbd
Reviewed-on: https://go-review.googlesource.com/30166
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/driver/driver.go')
| -rw-r--r-- | src/database/sql/driver/driver.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go index b3d83f3ff4..6cc970f688 100644 --- a/src/database/sql/driver/driver.go +++ b/src/database/sql/driver/driver.go @@ -24,6 +24,16 @@ import ( // time.Time type Value interface{} +// NamedValue holds both the value name and value. +// The Ordinal is the position of the parameter starting from one and is always set. +// If the Name is not empty it should be used for the parameter identifier and +// not the ordinal position. +type NamedValue struct { + Name string + Ordinal int + Value Value +} + // Driver is the interface that must be implemented by a database // driver. type Driver interface { @@ -71,7 +81,7 @@ type Execer interface { // ExecerContext is like execer, but must honor the context timeout and return // when the context is cancelled. type ExecerContext interface { - ExecContext(ctx context.Context, query string, args []Value) (Result, error) + ExecContext(ctx context.Context, query string, args []NamedValue) (Result, error) } // Queryer is an optional interface that may be implemented by a Conn. @@ -88,7 +98,7 @@ type Queryer interface { // QueryerContext is like Queryer, but most honor the context timeout and return // when the context is cancelled. type QueryerContext interface { - QueryContext(ctx context.Context, query string, args []Value) (Rows, error) + QueryContext(ctx context.Context, query string, args []NamedValue) (Rows, error) } // Conn is a connection to a database. It is not used concurrently @@ -174,13 +184,13 @@ type Stmt interface { // StmtExecContext enhances the Stmt interface by providing Exec with context. type StmtExecContext interface { // ExecContext must honor the context timeout and return when it is cancelled. - ExecContext(ctx context.Context, args []Value) (Result, error) + ExecContext(ctx context.Context, args []NamedValue) (Result, error) } // StmtQueryContext enhances the Stmt interface by providing Query with context. type StmtQueryContext interface { // QueryContext must honor the context timeout and return when it is cancelled. - QueryContext(ctx context.Context, args []Value) (Rows, error) + QueryContext(ctx context.Context, args []NamedValue) (Rows, error) } // ColumnConverter may be optionally implemented by Stmt if the |
