summaryrefslogtreecommitdiff
path: root/libgo/go/database/sql/driver
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-03-02 20:01:37 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-03-02 20:01:37 +0000
commit501699af1603287b1b47ac450fd6eeb826aa76b1 (patch)
tree3eeb8918d39d675108073c8b76d6dd10586a608c /libgo/go/database/sql/driver
parent34c5f21a387dc461042bafc3052ce6e1af786a77 (diff)
downloadgcc-501699af1603287b1b47ac450fd6eeb826aa76b1.tar.gz
libgo: Update to weekly.2012-02-22 release.
From-SVN: r184819
Diffstat (limited to 'libgo/go/database/sql/driver')
-rw-r--r--libgo/go/database/sql/driver/driver.go51
-rw-r--r--libgo/go/database/sql/driver/types.go80
2 files changed, 54 insertions, 77 deletions
diff --git a/libgo/go/database/sql/driver/driver.go b/libgo/go/database/sql/driver/driver.go
index b9300776050..7f986b80f2c 100644
--- a/libgo/go/database/sql/driver/driver.go
+++ b/libgo/go/database/sql/driver/driver.go
@@ -6,21 +6,20 @@
// drivers as used by package sql.
//
// Most code should use package sql.
-//
-// Drivers only need to be aware of a subset of Go's types. The sql package
-// will convert all types into one of the following:
+package driver
+
+import "errors"
+
+// A driver Value is a value that drivers must be able to handle.
+// A Value is either nil or an instance of one of these types:
//
// int64
// float64
// bool
-// nil
// []byte
// string [*] everywhere except from Rows.Next.
// time.Time
-//
-package driver
-
-import "errors"
+type Value interface{}
// Driver is the interface that must be implemented by a database
// driver.
@@ -50,11 +49,9 @@ var ErrSkip = errors.New("driver: skip fast-path; continue as if unimplemented")
// first prepare a query, execute the statement, and then close the
// statement.
//
-// All arguments are of a subset type as defined in the package docs.
-//
// Exec may return ErrSkip.
type Execer interface {
- Exec(query string, args []interface{}) (Result, error)
+ Exec(query string, args []Value) (Result, error)
}
// Conn is a connection to a database. It is not used concurrently
@@ -127,18 +124,17 @@ type Stmt interface {
NumInput() int
// Exec executes a query that doesn't return rows, such
- // as an INSERT or UPDATE. The args are all of a subset
- // type as defined above.
- Exec(args []interface{}) (Result, error)
+ // as an INSERT or UPDATE.
+ Exec(args []Value) (Result, error)
// Exec executes a query that may return rows, such as a
- // SELECT. The args of all of a subset type as defined above.
- Query(args []interface{}) (Rows, error)
+ // SELECT.
+ Query(args []Value) (Rows, error)
}
// ColumnConverter may be optionally implemented by Stmt if the
// the statement is aware of its own columns' types and can
-// convert from any type to a driver subset type.
+// convert from any type to a driver Value.
type ColumnConverter interface {
// ColumnConverter returns a ValueConverter for the provided
// column index. If the type of a specific column isn't known
@@ -162,12 +158,12 @@ type Rows interface {
// the provided slice. The provided slice will be the same
// size as the Columns() are wide.
//
- // The dest slice may be populated with only with values
- // of subset types defined above, but excluding string.
+ // The dest slice may be populated only with
+ // a driver Value type, but excluding string.
// All string values must be converted to []byte.
//
// Next should return io.EOF when there are no more rows.
- Next(dest []interface{}) error
+ Next(dest []Value) error
}
// Tx is a transaction.
@@ -190,18 +186,19 @@ func (v RowsAffected) RowsAffected() (int64, error) {
return int64(v), nil
}
-// DDLSuccess is a pre-defined Result for drivers to return when a DDL
-// command succeeds.
-var DDLSuccess ddlSuccess
+// ResultNoRows 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.
+var ResultNoRows noRows
-type ddlSuccess struct{}
+type noRows struct{}
-var _ Result = ddlSuccess{}
+var _ Result = noRows{}
-func (ddlSuccess) LastInsertId() (int64, error) {
+func (noRows) LastInsertId() (int64, error) {
return 0, errors.New("no LastInsertId available after DDL statement")
}
-func (ddlSuccess) RowsAffected() (int64, error) {
+func (noRows) RowsAffected() (int64, error) {
return 0, errors.New("no RowsAffected available after DDL statement")
}
diff --git a/libgo/go/database/sql/driver/types.go b/libgo/go/database/sql/driver/types.go
index ce3c943ead2..3305354dfd0 100644
--- a/libgo/go/database/sql/driver/types.go
+++ b/libgo/go/database/sql/driver/types.go
@@ -17,28 +17,28 @@ import (
// driver package to provide consistent implementations of conversions
// between drivers. The ValueConverters have several uses:
//
-// * converting from the subset types as provided by the sql package
+// * 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
-// subset types.
+// driver Value types.
//
-// * by the sql package, for converting from a driver's subset type
+// * by the sql package, for converting from a driver's Value type
// to a user's type in a scan.
type ValueConverter interface {
- // ConvertValue converts a value to a restricted subset type.
- ConvertValue(v interface{}) (interface{}, error)
+ // ConvertValue converts a value to a driver Value.
+ ConvertValue(v interface{}) (Value, error)
}
-// SubsetValuer is the interface providing the SubsetValue method.
+// Valuer is the interface providing the Value method.
//
-// Types implementing SubsetValuer interface are able to convert
-// themselves to one of the driver's allowed subset values.
-type SubsetValuer interface {
- // SubsetValue returns a driver parameter subset value.
- SubsetValue() (interface{}, error)
+// Types implementing Valuer interface are able to convert
+// themselves to a driver Value.
+type Valuer interface {
+ // Value returns a driver Value.
+ Value() (Value, error)
}
// Bool is a ValueConverter that converts input values to bools.
@@ -59,7 +59,7 @@ var _ ValueConverter = boolType{}
func (boolType) String() string { return "Bool" }
-func (boolType) ConvertValue(src interface{}) (interface{}, error) {
+func (boolType) ConvertValue(src interface{}) (Value, error) {
switch s := src.(type) {
case bool:
return s, nil
@@ -104,7 +104,7 @@ type int32Type struct{}
var _ ValueConverter = int32Type{}
-func (int32Type) ConvertValue(v interface{}) (interface{}, error) {
+func (int32Type) ConvertValue(v interface{}) (Value, error) {
rv := reflect.ValueOf(v)
switch rv.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
@@ -137,7 +137,7 @@ var String stringType
type stringType struct{}
-func (stringType) ConvertValue(v interface{}) (interface{}, error) {
+func (stringType) ConvertValue(v interface{}) (Value, error) {
switch v.(type) {
case string, []byte:
return v, nil
@@ -151,7 +151,7 @@ type Null struct {
Converter ValueConverter
}
-func (n Null) ConvertValue(v interface{}) (interface{}, error) {
+func (n Null) ConvertValue(v interface{}) (Value, error) {
if v == nil {
return nil, nil
}
@@ -164,28 +164,17 @@ type NotNull struct {
Converter ValueConverter
}
-func (n NotNull) ConvertValue(v interface{}) (interface{}, error) {
+func (n NotNull) ConvertValue(v interface{}) (Value, error) {
if v == nil {
return nil, fmt.Errorf("nil value not allowed")
}
return n.Converter.ConvertValue(v)
}
-// IsParameterSubsetType reports whether v is of a valid type for a
-// parameter. These types are:
-//
-// int64
-// float64
-// bool
-// nil
-// []byte
-// time.Time
-// string
-//
-// This is the same list as IsScanSubsetType, with the addition of
-// string.
-func IsParameterSubsetType(v interface{}) bool {
- if IsScanSubsetType(v) {
+// IsValue reports whether v is a valid Value parameter type.
+// Unlike IsScanValue, IsValue permits the string type.
+func IsValue(v interface{}) bool {
+ if IsScanValue(v) {
return true
}
if _, ok := v.(string); ok {
@@ -194,18 +183,9 @@ func IsParameterSubsetType(v interface{}) bool {
return false
}
-// IsScanSubsetType reports whether v is of a valid type for a
-// value populated by Rows.Next. These types are:
-//
-// int64
-// float64
-// bool
-// nil
-// []byte
-// time.Time
-//
-// This is the same list as IsParameterSubsetType, without string.
-func IsScanSubsetType(v interface{}) bool {
+// IsScanValue reports whether v is a valid Value scan type.
+// Unlike IsValue, IsScanValue does not permit the string type.
+func IsScanValue(v interface{}) bool {
if v == nil {
return true
}
@@ -221,7 +201,7 @@ func IsScanSubsetType(v interface{}) bool {
// ColumnConverter.
//
// DefaultParameterConverter returns the given value directly if
-// IsSubsetType(value). Otherwise integer type are converted to
+// IsValue(value). Otherwise integer type are converted to
// int64, floats to float64, and strings to []byte. Other types are
// an error.
var DefaultParameterConverter defaultConverter
@@ -230,18 +210,18 @@ type defaultConverter struct{}
var _ ValueConverter = defaultConverter{}
-func (defaultConverter) ConvertValue(v interface{}) (interface{}, error) {
- if IsParameterSubsetType(v) {
+func (defaultConverter) ConvertValue(v interface{}) (Value, error) {
+ if IsValue(v) {
return v, nil
}
- if svi, ok := v.(SubsetValuer); ok {
- sv, err := svi.SubsetValue()
+ if svi, ok := v.(Valuer); ok {
+ sv, err := svi.Value()
if err != nil {
return nil, err
}
- if !IsParameterSubsetType(sv) {
- return nil, fmt.Errorf("non-subset type %T returned from SubsetValue", sv)
+ if !IsValue(sv) {
+ return nil, fmt.Errorf("non-Value type %T returned from Value", sv)
}
return sv, nil
}