Namespace: go.std.database.sql.driver
v1.0Contents
Summary
Provides a low-level interface to the database/sql/driver package.
Package driver defines interfaces to be implemented by database
drivers as used by package sql.
Most code should use package sql.
The driver interface has evolved over time. Drivers should implement
Connector and DriverContext interfaces.
The Connector.Connect and Driver.Open methods should never return ErrBadConn.
ErrBadConn should only be returned from Validator, SessionResetter, or
a query method if the connection is already in an invalid (e.g. closed) state.
All Conn implementations should implement the following interfaces:
Pinger, SessionResetter, and Validator.
If named parameters or context are supported, the driver's Conn should implement:
ExecerContext, QueryerContext, ConnPrepareContext, and ConnBeginTx.
To support custom data types, implement NamedValueChecker. NamedValueChecker
also allows queries to accept per-query options as a parameter by returning
ErrRemoveArgument from CheckNamedValue.
If multiple result sets are supported, Rows should implement RowsNextResultSet.
If the driver knows how to describe the types present in the returned result
it should implement the following interfaces: RowsColumnTypeScanType,
RowsColumnTypeDatabaseTypeName, RowsColumnTypeLength, RowsColumnTypeNullable,
and RowsColumnTypePrecisionScale. A given row value may also return a Rows
type, which may represent a database cursor value.
Before a connection is returned to the connection pool after use, IsValid is
called if implemented. Before a connection is reused for another query,
ResetSession is called if implemented. If a connection is never returned to the
connection pool but immediately reused, then ResetSession is called prior to
reuse but IsValid is not called.
Index
- *IsolationLevel
- *NamedValue
- *NotNull
- *Null
- *RowsAffected
- *TxOptions
- Bool
- ColumnConverter
- Conn
- ConnBeginTx
- ConnPrepareContext
- Connector
- DefaultParameterConverter
- Driver
- DriverContext
- ErrBadConn
- ErrRemoveArgument
- ErrSkip
- Execer
- ExecerContext
- Int32
- IsScanValue
- IsValue
- IsolationLevel
- NamedValue
- NamedValueChecker
- NotNull
- Null
- Pinger
- Queryer
- QueryerContext
- Result
- ResultNoRows
- Rows
- RowsAffected
- RowsColumnTypeDatabaseTypeName
- RowsColumnTypeLength
- RowsColumnTypeNullable
- RowsColumnTypePrecisionScale
- RowsColumnTypeScanType
- RowsNextResultSet
- SessionResetter
- Stmt
- StmtExecContext
- StmtQueryContext
- String
- Tx
- TxOptions
- Validator
- Value
- ValueConverter
- Valuer
- arrayOfColumnConverter
- arrayOfConn
- arrayOfConnBeginTx
- arrayOfConnPrepareContext
- arrayOfConnector
- arrayOfDriver
- arrayOfDriverContext
- arrayOfExecer
- arrayOfExecerContext
- arrayOfIsolationLevel
- arrayOfNamedValue
- arrayOfNamedValueChecker
- arrayOfNotNull
- arrayOfNull
- arrayOfPinger
- arrayOfQueryer
- arrayOfQueryerContext
- arrayOfResult
- arrayOfRows
- arrayOfRowsAffected
- arrayOfRowsColumnTypeDatabaseTypeName
- arrayOfRowsColumnTypeLength
- arrayOfRowsColumnTypeNullable
- arrayOfRowsColumnTypePrecisionScale
- arrayOfRowsColumnTypeScanType
- arrayOfRowsNextResultSet
- arrayOfSessionResetter
- arrayOfStmt
- arrayOfStmtExecContext
- arrayOfStmtQueryContext
- arrayOfTx
- arrayOfTxOptions
- arrayOfValidator
- arrayOfValue
- arrayOfValueConverter
- arrayOfValuer
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
Bool
Var v1.0Bool is a ValueConverter that converts input values to bools.
The conversion rules are:
- booleans are returned unchanged
- for integer types,
1 is true
0 is false,
other integers are an error
- for strings and []byte, same rules as strconv.ParseBool
- all other types are an error
-
DefaultParameterConverter
Var v1.0DefaultParameterConverter is the default implementation of
ValueConverter that's used when a Stmt doesn't implement
ColumnConverter.
DefaultParameterConverter returns its argument directly if
IsValue(arg). Otherwise, if the argument implements Valuer, its
Value method is used to return a Value. As a fallback, the provided
argument's underlying type is used to convert it to a Value:
underlying integer types are converted to int64, floats to float64,
bool, string, and []byte to themselves. If the argument is a nil
pointer, ConvertValue returns a nil Value. If the argument is a
non-nil pointer, it is dereferenced and ConvertValue is called
recursively. Other types are an error.
-
ErrBadConn
Var v1.0ErrBadConn should be returned by a driver to signal to the sql
package that a driver.Conn is in a bad state (such as the server
having earlier closed the connection) and the sql package should
retry on a new connection.
To prevent duplicate operations, ErrBadConn should NOT be returned
if there's a possibility that the database server might have
performed the operation. Even if the server sends back an error,
you shouldn't return ErrBadConn.
Errors will be checked using errors.Is. An error may
wrap ErrBadConn or implement the Is(error) bool method.
-
ErrRemoveArgument
Var v1.0ErrRemoveArgument may be returned from NamedValueChecker to instruct the
sql package to not pass the argument to the driver query interface.
Return when accepting query specific options or structures that aren't
SQL query arguments.
-
ErrSkip
Var v1.0ErrSkip may be returned by some optional interfaces' methods to
indicate at runtime that the fast path is unavailable and the sql
package should continue as if the optional interface was not
implemented. ErrSkip is only supported where explicitly
documented.
-
Int32
Var v1.0Int32 is a ValueConverter that converts input values to int64,
respecting the limits of an int32 value.
-
ResultNoRows
Var v1.0ResultNoRows is a pre-defined Result for drivers to return when a DDL
command (such as a CREATE TABLE) succeeds. It returns an error for both
LastInsertId and RowsAffected.
-
String
Var v1.0String is a ValueConverter that converts its input to a string.
If the value is already a string or []byte, it's unchanged.
If the value is of another type, conversion to string is done
with fmt.Sprintf("%v", v).
Functions, Macros, and Special Forms
-
IsScanValue
Function v1.0(IsScanValue v)
IsScanValue is equivalent to IsValue.
It exists for compatibility.
Go input arguments: (v any)
Go returns: bool
Joker input arguments: [^GoObject v]
Joker returns: ^Boolean -
IsValue
Function v1.0(IsValue v)
IsValue reports whether v is a valid Value parameter type.
Go input arguments: (v any)
Go returns: bool
Joker input arguments: [^GoObject v]
Joker returns: ^Boolean
Types
-
*IsolationLevel
Concrete Type v1.0IsolationLevel is the transaction isolation level stored in TxOptions.
This type should be considered identical to sql.IsolationLevel along
with any values defined on it.
-
*NamedValue
Concrete Type v1.0NamedValue holds both the value name and value.
-
*NotNull
Concrete Type v1.0NotNull is a type that implements ValueConverter by disallowing nil
values but otherwise delegating to another ValueConverter.
-
*Null
Concrete Type v1.0Null is a type that implements ValueConverter by allowing nil
values but otherwise delegating to another ValueConverter.
-
*RowsAffected
Concrete Type v1.0RowsAffected implements Result for an INSERT or UPDATE operation
which mutates a number of rows.
-
*TxOptions
Concrete Type v1.0TxOptions holds the transaction options.
This type should be considered identical to sql.TxOptions.
-
ColumnConverter
Abstract Type v1.0ColumnConverter may be optionally implemented by Stmt if the
statement is aware of its own columns' types and can convert from
any type to a driver Value.
Deprecated: Drivers should implement NamedValueChecker.
-
ColumnConverter
Method for ColumnConverter v1.0([idx])
-
Conn
Abstract Type v1.0Conn is a connection to a database. It is not used concurrently
by multiple goroutines.
Conn is assumed to be stateful.
-
Begin
Method for Conn v1.0([])
-
Close
Method for Conn v1.0([])
-
Prepare
Method for Conn v1.0([query])
-
ConnBeginTx
Abstract Type v1.0ConnBeginTx enhances the Conn interface with context and TxOptions.
-
BeginTx
Method for ConnBeginTx v1.0([ctx opts])
-
ConnPrepareContext
Abstract Type v1.0ConnPrepareContext enhances the Conn interface with context.
-
PrepareContext
Method for ConnPrepareContext v1.0([ctx query])
-
Connector
Abstract Type v1.0A Connector represents a driver in a fixed configuration
and can create any number of equivalent Conns for use
by multiple goroutines.
A Connector can be passed to sql.OpenDB, to allow drivers
to implement their own sql.DB constructors, or returned by
DriverContext's OpenConnector method, to allow drivers
access to context and to avoid repeated parsing of driver
configuration.
If a Connector implements io.Closer, the sql package's DB.Close
method will call Close and return error (if any).
-
Connect
Method for Connector v1.0([arg1])
-
Driver
Method for Connector v1.0([])
-
Driver
Abstract Type v1.0Driver is the interface that must be implemented by a database
driver.
Database drivers may implement DriverContext for access
to contexts and to parse the name only once for a pool of connections,
instead of once per connection.
-
Open
Method for Driver v1.0([name])
-
DriverContext
Abstract Type v1.0If a Driver implements DriverContext, then sql.DB will call
OpenConnector to obtain a Connector and then invoke
that Connector's Connect method to obtain each needed connection,
instead of invoking the Driver's Open method for each connection.
The two-step sequence allows drivers to parse the name just once
and also provides access to per-Conn contexts.
-
OpenConnector
Method for DriverContext v1.0([name])
-
Execer
Abstract Type v1.0Execer is an optional interface that may be implemented by a Conn.
If a Conn implements neither ExecerContext nor Execer,
the sql package's DB.Exec will first prepare a query, execute the statement,
and then close the statement.
Exec may return ErrSkip.
Deprecated: Drivers should implement ExecerContext instead.
-
Exec
Method for Execer v1.0([query args])
-
ExecerContext
Abstract Type v1.0ExecerContext is an optional interface that may be implemented by a Conn.
If a Conn does not implement ExecerContext, the sql package's DB.Exec
will fall back to Execer; if the Conn does not implement Execer either,
DB.Exec will first prepare a query, execute the statement, and then
close the statement.
ExecContext may return ErrSkip.
ExecContext must honor the context timeout and return when the context is canceled.
-
ExecContext
Method for ExecerContext v1.0([ctx query args])
-
IsolationLevel
Concrete Type v1.0IsolationLevel is the transaction isolation level stored in TxOptions.
This type should be considered identical to sql.IsolationLevel along
with any values defined on it.
-
NamedValue
Concrete Type v1.0NamedValue holds both the value name and value.
-
NamedValueChecker
Abstract Type v1.0NamedValueChecker may be optionally implemented by Conn or Stmt. It provides
the driver more control to handle Go and database types beyond the default
Values types allowed.
The sql package checks for value checkers in the following order,
stopping at the first found match: Stmt.NamedValueChecker, Conn.NamedValueChecker,
Stmt.ColumnConverter, DefaultParameterConverter.
If CheckNamedValue returns ErrRemoveArgument, the NamedValue will not be included in
the final query arguments. This may be used to pass special options to
the query itself.
If ErrSkip is returned the column converter error checking
path is used for the argument. Drivers may wish to return ErrSkip after
they have exhausted their own special cases.
-
CheckNamedValue
Method for NamedValueChecker v1.0([arg1])
-
NotNull
Concrete Type v1.0NotNull is a type that implements ValueConverter by disallowing nil
values but otherwise delegating to another ValueConverter.
-
ConvertValue
Receiver for NotNull v1.0([v])
-
Null
Concrete Type v1.0Null is a type that implements ValueConverter by allowing nil
values but otherwise delegating to another ValueConverter.
-
ConvertValue
Receiver for Null v1.0([v])
-
Pinger
Abstract Type v1.0Pinger is an optional interface that may be implemented by a Conn.
If a Conn does not implement Pinger, the sql package's DB.Ping and
DB.PingContext will check if there is at least one Conn available.
If Conn.Ping returns ErrBadConn, DB.Ping and DB.PingContext will remove
the Conn from pool.
-
Ping
Method for Pinger v1.0([ctx])
-
Queryer
Abstract Type v1.0Queryer is an optional interface that may be implemented by a Conn.
If a Conn implements neither QueryerContext nor Queryer,
the sql package's DB.Query will first prepare a query, execute the statement,
and then close the statement.
Query may return ErrSkip.
Deprecated: Drivers should implement QueryerContext instead.
-
Query
Method for Queryer v1.0([query args])
-
QueryerContext
Abstract Type v1.0QueryerContext is an optional interface that may be implemented by a Conn.
If a Conn does not implement QueryerContext, the sql package's DB.Query
will fall back to Queryer; if the Conn does not implement Queryer either,
DB.Query will first prepare a query, execute the statement, and then
close the statement.
QueryContext may return ErrSkip.
QueryContext must honor the context timeout and return when the context is canceled.
-
QueryContext
Method for QueryerContext v1.0([ctx query args])
-
Result
Abstract Type v1.0Result is the result of a query execution.
-
LastInsertId
Method for Result v1.0([])
-
RowsAffected
Method for Result v1.0([])
-
Rows
Abstract Type v1.0Rows is an iterator over an executed query's results.
-
Close
Method for Rows v1.0([])
-
Columns
Method for Rows v1.0([])
-
Next
Method for Rows v1.0([dest])
-
RowsAffected
Concrete Type v1.0RowsAffected implements Result for an INSERT or UPDATE operation
which mutates a number of rows.
-
LastInsertId
Receiver for RowsAffected v1.0([])
-
RowsAffected
Receiver for RowsAffected v1.0([])
-
RowsColumnTypeDatabaseTypeName
Abstract Type v1.0RowsColumnTypeDatabaseTypeName may be implemented by Rows. It should return the
database system type name without the length. Type names should be uppercase.
Examples of returned types: "VARCHAR", "NVARCHAR", "VARCHAR2", "CHAR", "TEXT",
"DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT", "JSONB", "XML",
"TIMESTAMP".
-
Close
Method for RowsColumnTypeDatabaseTypeName v1.0([])
-
ColumnTypeDatabaseTypeName
Method for RowsColumnTypeDatabaseTypeName v1.0([index])
-
Columns
Method for RowsColumnTypeDatabaseTypeName v1.0([])
-
Next
Method for RowsColumnTypeDatabaseTypeName v1.0([dest])
-
RowsColumnTypeLength
Abstract Type v1.0RowsColumnTypeLength may be implemented by Rows. It should return the length
of the column type if the column is a variable length type. If the column is
not a variable length type ok should return false.
If length is not limited other than system limits, it should return math.MaxInt64.
The following are examples of returned values for various types:
TEXT (math.MaxInt64, true)
varchar(10) (10, true)
nvarchar(10) (10, true)
decimal (0, false)
int (0, false)
bytea(30) (30, true)
-
Close
Method for RowsColumnTypeLength v1.0([])
-
ColumnTypeLength
Method for RowsColumnTypeLength v1.0([index])
-
Columns
Method for RowsColumnTypeLength v1.0([])
-
Next
Method for RowsColumnTypeLength v1.0([dest])
-
RowsColumnTypeNullable
Abstract Type v1.0RowsColumnTypeNullable may be implemented by Rows. The nullable value should
be true if it is known the column may be null, or false if the column is known
to be not nullable.
If the column nullability is unknown, ok should be false.
-
Close
Method for RowsColumnTypeNullable v1.0([])
-
ColumnTypeNullable
Method for RowsColumnTypeNullable v1.0([index])
-
Columns
Method for RowsColumnTypeNullable v1.0([])
-
Next
Method for RowsColumnTypeNullable v1.0([dest])
-
RowsColumnTypePrecisionScale
Abstract Type v1.0RowsColumnTypePrecisionScale may be implemented by Rows. It should return
the precision and scale for decimal types. If not applicable, ok should be false.
The following are examples of returned values for various types:
decimal(38, 4) (38, 4, true)
int (0, 0, false)
decimal (math.MaxInt64, math.MaxInt64, true)
-
Close
Method for RowsColumnTypePrecisionScale v1.0([])
-
ColumnTypePrecisionScale
Method for RowsColumnTypePrecisionScale v1.0([index])
-
Columns
Method for RowsColumnTypePrecisionScale v1.0([])
-
Next
Method for RowsColumnTypePrecisionScale v1.0([dest])
-
RowsColumnTypeScanType
Abstract Type v1.0RowsColumnTypeScanType may be implemented by Rows. It should return
the value type that can be used to scan types into. For example, the database
column type "bigint" this should return "reflect.TypeOf(int64(0))".
-
Close
Method for RowsColumnTypeScanType v1.0([])
-
ColumnTypeScanType
Method for RowsColumnTypeScanType v1.0([index])
-
Columns
Method for RowsColumnTypeScanType v1.0([])
-
Next
Method for RowsColumnTypeScanType v1.0([dest])
-
RowsNextResultSet
Abstract Type v1.0RowsNextResultSet extends the Rows interface by providing a way to signal
the driver to advance to the next result set.
-
Close
Method for RowsNextResultSet v1.0([])
-
Columns
Method for RowsNextResultSet v1.0([])
-
HasNextResultSet
Method for RowsNextResultSet v1.0([])
-
Next
Method for RowsNextResultSet v1.0([dest])
-
NextResultSet
Method for RowsNextResultSet v1.0([])
-
SessionResetter
Abstract Type v1.0SessionResetter may be implemented by Conn to allow drivers to reset the
session state associated with the connection and to signal a bad connection.
-
ResetSession
Method for SessionResetter v1.0([ctx])
-
Stmt
Abstract Type v1.0Stmt is a prepared statement. It is bound to a Conn and not
used by multiple goroutines concurrently.
-
Close
Method for Stmt v1.0([])
-
Exec
Method for Stmt v1.0([args])
-
NumInput
Method for Stmt v1.0([])
-
Query
Method for Stmt v1.0([args])
-
StmtExecContext
Abstract Type v1.0StmtExecContext enhances the Stmt interface by providing Exec with context.
-
ExecContext
Method for StmtExecContext v1.0([ctx args])
-
StmtQueryContext
Abstract Type v1.0StmtQueryContext enhances the Stmt interface by providing Query with context.
-
QueryContext
Method for StmtQueryContext v1.0([ctx args])
-
Tx
Abstract Type v1.0Tx is a transaction.
-
Commit
Method for Tx v1.0([])
-
Rollback
Method for Tx v1.0([])
-
TxOptions
Concrete Type v1.0TxOptions holds the transaction options.
This type should be considered identical to sql.TxOptions.
-
Validator
Abstract Type v1.0Validator may be implemented by Conn to allow drivers to
signal if a connection is valid or if it should be discarded.
If implemented, drivers may return the underlying error from queries,
even if the connection should be discarded by the connection pool.
-
IsValid
Method for Validator v1.0([])
-
Value
Abstract Type v1.0Value is a value that drivers must be able to handle.
It is either nil, a type handled by a database driver's NamedValueChecker
interface, or an instance of one of these types:
int64
float64
bool
[]byte
string
time.Time
If the driver supports cursors, a returned Value may also implement the Rows interface
in this package. This is used, for example, when a user selects a cursor
such as "select cursor(select * from my_table) from dual". If the Rows
from the select is closed, the cursor Rows will also be closed.
-
ValueConverter
Abstract Type v1.0ValueConverter is the interface providing the ConvertValue method.
Various implementations of ValueConverter are provided by the
driver package to provide consistent implementations of conversions
between drivers. The ValueConverters have several uses:
- converting from the Value types as provided by the sql package
into a database table's specific column type and making sure it
fits, such as making sure a particular int64 fits in a
table's uint16 column.
- converting a value as given from the database into one of the
driver Value types.
- by the sql package, for converting from a driver's Value type
to a user's type in a scan.
-
ConvertValue
Method for ValueConverter v1.0([v])
-
Valuer
Abstract Type v1.0Valuer is the interface providing the Value method.
Types implementing Valuer interface are able to convert
themselves to a driver Value.
-
Value
Method for Valuer v1.0([])
-
arrayOfColumnConverter
Concrete Type v1.0ColumnConverter may be optionally implemented by Stmt if the
statement is aware of its own columns' types and can convert from
any type to a driver Value.
Deprecated: Drivers should implement NamedValueChecker.
-
arrayOfConn
Concrete Type v1.0Conn is a connection to a database. It is not used concurrently
by multiple goroutines.
Conn is assumed to be stateful.
-
arrayOfConnBeginTx
Concrete Type v1.0ConnBeginTx enhances the Conn interface with context and TxOptions.
-
arrayOfConnPrepareContext
Concrete Type v1.0ConnPrepareContext enhances the Conn interface with context.
-
arrayOfConnector
Concrete Type v1.0A Connector represents a driver in a fixed configuration
and can create any number of equivalent Conns for use
by multiple goroutines.
A Connector can be passed to sql.OpenDB, to allow drivers
to implement their own sql.DB constructors, or returned by
DriverContext's OpenConnector method, to allow drivers
access to context and to avoid repeated parsing of driver
configuration.
If a Connector implements io.Closer, the sql package's DB.Close
method will call Close and return error (if any).
-
arrayOfDriver
Concrete Type v1.0Driver is the interface that must be implemented by a database
driver.
Database drivers may implement DriverContext for access
to contexts and to parse the name only once for a pool of connections,
instead of once per connection.
-
arrayOfDriverContext
Concrete Type v1.0If a Driver implements DriverContext, then sql.DB will call
OpenConnector to obtain a Connector and then invoke
that Connector's Connect method to obtain each needed connection,
instead of invoking the Driver's Open method for each connection.
The two-step sequence allows drivers to parse the name just once
and also provides access to per-Conn contexts.
-
arrayOfExecer
Concrete Type v1.0Execer is an optional interface that may be implemented by a Conn.
If a Conn implements neither ExecerContext nor Execer,
the sql package's DB.Exec will first prepare a query, execute the statement,
and then close the statement.
Exec may return ErrSkip.
Deprecated: Drivers should implement ExecerContext instead.
-
arrayOfExecerContext
Concrete Type v1.0ExecerContext is an optional interface that may be implemented by a Conn.
If a Conn does not implement ExecerContext, the sql package's DB.Exec
will fall back to Execer; if the Conn does not implement Execer either,
DB.Exec will first prepare a query, execute the statement, and then
close the statement.
ExecContext may return ErrSkip.
ExecContext must honor the context timeout and return when the context is canceled.
-
arrayOfIsolationLevel
Concrete Type v1.0IsolationLevel is the transaction isolation level stored in TxOptions.
This type should be considered identical to sql.IsolationLevel along
with any values defined on it.
-
arrayOfNamedValue
Concrete Type v1.0NamedValue holds both the value name and value.
-
arrayOfNamedValueChecker
Concrete Type v1.0NamedValueChecker may be optionally implemented by Conn or Stmt. It provides
the driver more control to handle Go and database types beyond the default
Values types allowed.
The sql package checks for value checkers in the following order,
stopping at the first found match: Stmt.NamedValueChecker, Conn.NamedValueChecker,
Stmt.ColumnConverter, DefaultParameterConverter.
If CheckNamedValue returns ErrRemoveArgument, the NamedValue will not be included in
the final query arguments. This may be used to pass special options to
the query itself.
If ErrSkip is returned the column converter error checking
path is used for the argument. Drivers may wish to return ErrSkip after
they have exhausted their own special cases.
-
arrayOfNotNull
Concrete Type v1.0NotNull is a type that implements ValueConverter by disallowing nil
values but otherwise delegating to another ValueConverter.
-
arrayOfNull
Concrete Type v1.0Null is a type that implements ValueConverter by allowing nil
values but otherwise delegating to another ValueConverter.
-
arrayOfPinger
Concrete Type v1.0Pinger is an optional interface that may be implemented by a Conn.
If a Conn does not implement Pinger, the sql package's DB.Ping and
DB.PingContext will check if there is at least one Conn available.
If Conn.Ping returns ErrBadConn, DB.Ping and DB.PingContext will remove
the Conn from pool.
-
arrayOfQueryer
Concrete Type v1.0Queryer is an optional interface that may be implemented by a Conn.
If a Conn implements neither QueryerContext nor Queryer,
the sql package's DB.Query will first prepare a query, execute the statement,
and then close the statement.
Query may return ErrSkip.
Deprecated: Drivers should implement QueryerContext instead.
-
arrayOfQueryerContext
Concrete Type v1.0QueryerContext is an optional interface that may be implemented by a Conn.
If a Conn does not implement QueryerContext, the sql package's DB.Query
will fall back to Queryer; if the Conn does not implement Queryer either,
DB.Query will first prepare a query, execute the statement, and then
close the statement.
QueryContext may return ErrSkip.
QueryContext must honor the context timeout and return when the context is canceled.
-
arrayOfResult
Concrete Type v1.0Result is the result of a query execution.
-
arrayOfRows
Concrete Type v1.0Rows is an iterator over an executed query's results.
-
arrayOfRowsAffected
Concrete Type v1.0RowsAffected implements Result for an INSERT or UPDATE operation
which mutates a number of rows.
-
arrayOfRowsColumnTypeDatabaseTypeName
Concrete Type v1.0RowsColumnTypeDatabaseTypeName may be implemented by Rows. It should return the
database system type name without the length. Type names should be uppercase.
Examples of returned types: "VARCHAR", "NVARCHAR", "VARCHAR2", "CHAR", "TEXT",
"DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT", "JSONB", "XML",
"TIMESTAMP".
-
arrayOfRowsColumnTypeLength
Concrete Type v1.0RowsColumnTypeLength may be implemented by Rows. It should return the length
of the column type if the column is a variable length type. If the column is
not a variable length type ok should return false.
If length is not limited other than system limits, it should return math.MaxInt64.
The following are examples of returned values for various types:
TEXT (math.MaxInt64, true)
varchar(10) (10, true)
nvarchar(10) (10, true)
decimal (0, false)
int (0, false)
bytea(30) (30, true)
-
arrayOfRowsColumnTypeNullable
Concrete Type v1.0RowsColumnTypeNullable may be implemented by Rows. The nullable value should
be true if it is known the column may be null, or false if the column is known
to be not nullable.
If the column nullability is unknown, ok should be false.
-
arrayOfRowsColumnTypePrecisionScale
Concrete Type v1.0RowsColumnTypePrecisionScale may be implemented by Rows. It should return
the precision and scale for decimal types. If not applicable, ok should be false.
The following are examples of returned values for various types:
decimal(38, 4) (38, 4, true)
int (0, 0, false)
decimal (math.MaxInt64, math.MaxInt64, true)
-
arrayOfRowsColumnTypeScanType
Concrete Type v1.0RowsColumnTypeScanType may be implemented by Rows. It should return
the value type that can be used to scan types into. For example, the database
column type "bigint" this should return "reflect.TypeOf(int64(0))".
-
arrayOfRowsNextResultSet
Concrete Type v1.0RowsNextResultSet extends the Rows interface by providing a way to signal
the driver to advance to the next result set.
-
arrayOfSessionResetter
Concrete Type v1.0SessionResetter may be implemented by Conn to allow drivers to reset the
session state associated with the connection and to signal a bad connection.
-
arrayOfStmt
Concrete Type v1.0Stmt is a prepared statement. It is bound to a Conn and not
used by multiple goroutines concurrently.
-
arrayOfStmtExecContext
Concrete Type v1.0StmtExecContext enhances the Stmt interface by providing Exec with context.
-
arrayOfStmtQueryContext
Concrete Type v1.0StmtQueryContext enhances the Stmt interface by providing Query with context.
-
arrayOfTx
Concrete Type v1.0Tx is a transaction.
-
arrayOfTxOptions
Concrete Type v1.0TxOptions holds the transaction options.
This type should be considered identical to sql.TxOptions.
-
arrayOfValidator
Concrete Type v1.0Validator may be implemented by Conn to allow drivers to
signal if a connection is valid or if it should be discarded.
If implemented, drivers may return the underlying error from queries,
even if the connection should be discarded by the connection pool.
-
arrayOfValue
Concrete Type v1.0Value is a value that drivers must be able to handle.
It is either nil, a type handled by a database driver's NamedValueChecker
interface, or an instance of one of these types:
int64
float64
bool
[]byte
string
time.Time
If the driver supports cursors, a returned Value may also implement the Rows interface
in this package. This is used, for example, when a user selects a cursor
such as "select cursor(select * from my_table) from dual". If the Rows
from the select is closed, the cursor Rows will also be closed.
-
arrayOfValueConverter
Concrete Type v1.0ValueConverter is the interface providing the ConvertValue method.
Various implementations of ValueConverter are provided by the
driver package to provide consistent implementations of conversions
between drivers. The ValueConverters have several uses:
- converting from the Value types as provided by the sql package
into a database table's specific column type and making sure it
fits, such as making sure a particular int64 fits in a
table's uint16 column.
- converting a value as given from the database into one of the
driver Value types.
- by the sql package, for converting from a driver's Value type
to a user's type in a scan.
-
arrayOfValuer
Concrete Type v1.0Valuer is the interface providing the Value method.
Types implementing Valuer interface are able to convert
themselves to a driver Value.