mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: remove Into from ScannerInto/ScanInto
Also fix a doc error. Fixes #2843 R=golang-dev, r, rsc CC=golang-dev https://golang.org/cl/5653050
This commit is contained in:
parent
44fa114dc6
commit
6bdd791dec
2 changed files with 22 additions and 20 deletions
|
|
@ -90,8 +90,8 @@ func convertAssign(dest, src interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if scanner, ok := dest.(ScannerInto); ok {
|
if scanner, ok := dest.(Scanner); ok {
|
||||||
return scanner.ScanInto(src)
|
return scanner.Scan(src)
|
||||||
}
|
}
|
||||||
|
|
||||||
dpv := reflect.ValueOf(dest)
|
dpv := reflect.ValueOf(dest)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func Register(name string, driver driver.Driver) {
|
||||||
type RawBytes []byte
|
type RawBytes []byte
|
||||||
|
|
||||||
// NullString represents a string that may be null.
|
// NullString represents a string that may be null.
|
||||||
// NullString implements the ScannerInto interface so
|
// NullString implements the Scanner interface so
|
||||||
// it can be used as a scan destination:
|
// it can be used as a scan destination:
|
||||||
//
|
//
|
||||||
// var s NullString
|
// var s NullString
|
||||||
|
|
@ -52,8 +52,8 @@ type NullString struct {
|
||||||
Valid bool // Valid is true if String is not NULL
|
Valid bool // Valid is true if String is not NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanInto implements the ScannerInto interface.
|
// Scan implements the Scanner interface.
|
||||||
func (ns *NullString) ScanInto(value interface{}) error {
|
func (ns *NullString) Scan(value interface{}) error {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
ns.String, ns.Valid = "", false
|
ns.String, ns.Valid = "", false
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -71,15 +71,15 @@ func (ns NullString) SubsetValue() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NullInt64 represents an int64 that may be null.
|
// NullInt64 represents an int64 that may be null.
|
||||||
// NullInt64 implements the ScannerInto interface so
|
// NullInt64 implements the Scanner interface so
|
||||||
// it can be used as a scan destination, similar to NullString.
|
// it can be used as a scan destination, similar to NullString.
|
||||||
type NullInt64 struct {
|
type NullInt64 struct {
|
||||||
Int64 int64
|
Int64 int64
|
||||||
Valid bool // Valid is true if Int64 is not NULL
|
Valid bool // Valid is true if Int64 is not NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanInto implements the ScannerInto interface.
|
// Scan implements the Scanner interface.
|
||||||
func (n *NullInt64) ScanInto(value interface{}) error {
|
func (n *NullInt64) Scan(value interface{}) error {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
n.Int64, n.Valid = 0, false
|
n.Int64, n.Valid = 0, false
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -97,15 +97,15 @@ func (n NullInt64) SubsetValue() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NullFloat64 represents a float64 that may be null.
|
// NullFloat64 represents a float64 that may be null.
|
||||||
// NullFloat64 implements the ScannerInto interface so
|
// NullFloat64 implements the Scanner interface so
|
||||||
// it can be used as a scan destination, similar to NullString.
|
// it can be used as a scan destination, similar to NullString.
|
||||||
type NullFloat64 struct {
|
type NullFloat64 struct {
|
||||||
Float64 float64
|
Float64 float64
|
||||||
Valid bool // Valid is true if Float64 is not NULL
|
Valid bool // Valid is true if Float64 is not NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanInto implements the ScannerInto interface.
|
// Scan implements the Scanner interface.
|
||||||
func (n *NullFloat64) ScanInto(value interface{}) error {
|
func (n *NullFloat64) Scan(value interface{}) error {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
n.Float64, n.Valid = 0, false
|
n.Float64, n.Valid = 0, false
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -123,15 +123,15 @@ func (n NullFloat64) SubsetValue() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NullBool represents a bool that may be null.
|
// NullBool represents a bool that may be null.
|
||||||
// NullBool implements the ScannerInto interface so
|
// NullBool implements the Scanner interface so
|
||||||
// it can be used as a scan destination, similar to NullString.
|
// it can be used as a scan destination, similar to NullString.
|
||||||
type NullBool struct {
|
type NullBool struct {
|
||||||
Bool bool
|
Bool bool
|
||||||
Valid bool // Valid is true if Bool is not NULL
|
Valid bool // Valid is true if Bool is not NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanInto implements the ScannerInto interface.
|
// Scan implements the Scanner interface.
|
||||||
func (n *NullBool) ScanInto(value interface{}) error {
|
func (n *NullBool) Scan(value interface{}) error {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
n.Bool, n.Valid = false, false
|
n.Bool, n.Valid = false, false
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -148,22 +148,24 @@ func (n NullBool) SubsetValue() (interface{}, error) {
|
||||||
return n.Bool, nil
|
return n.Bool, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScannerInto is an interface used by Scan.
|
// Scanner is an interface used by Scan.
|
||||||
type ScannerInto interface {
|
type Scanner interface {
|
||||||
// ScanInto assigns a value from a database driver.
|
// Scan assigns a value from a database driver.
|
||||||
//
|
//
|
||||||
// The value will be of one of the following restricted
|
// The src value will be of one of the following restricted
|
||||||
// set of types:
|
// set of types:
|
||||||
//
|
//
|
||||||
// int64
|
// int64
|
||||||
// float64
|
// float64
|
||||||
// bool
|
// bool
|
||||||
// []byte
|
// []byte
|
||||||
|
// string
|
||||||
|
// time.Time
|
||||||
// nil - for NULL values
|
// nil - for NULL values
|
||||||
//
|
//
|
||||||
// An error should be returned if the value can not be stored
|
// An error should be returned if the value can not be stored
|
||||||
// without loss of information.
|
// without loss of information.
|
||||||
ScanInto(value interface{}) error
|
Scan(src interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrNoRows is returned by Scan when QueryRow doesn't return a
|
// ErrNoRows is returned by Scan when QueryRow doesn't return a
|
||||||
|
|
@ -769,7 +771,7 @@ func (s *Stmt) Query(args ...interface{}) (*Rows, error) {
|
||||||
// Example usage:
|
// Example usage:
|
||||||
//
|
//
|
||||||
// var name string
|
// var name string
|
||||||
// err := nameByUseridStmt.QueryRow(id).Scan(&s)
|
// err := nameByUseridStmt.QueryRow(id).Scan(&name)
|
||||||
func (s *Stmt) QueryRow(args ...interface{}) *Row {
|
func (s *Stmt) QueryRow(args ...interface{}) *Row {
|
||||||
rows, err := s.Query(args...)
|
rows, err := s.Query(args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue