aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/database
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2016-07-22 18:15:38 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-07-22 18:15:38 +0000
commit22b955cca564a9a3a5b8c9d9dd1e295b7943c128 (patch)
treeabdbd898676e1f853fca2d7e031d105d7ebcf676 /libgo/go/database
parent9d04a3af4c6491536badf6bde9707c907e4d196b (diff)
downloadgcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.zip
gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.tar.gz
gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.tar.bz2
libgo: update to go1.7rc3
Reviewed-on: https://go-review.googlesource.com/25150 From-SVN: r238662
Diffstat (limited to 'libgo/go/database')
-rw-r--r--libgo/go/database/sql/convert.go9
-rw-r--r--libgo/go/database/sql/convert_test.go12
-rw-r--r--libgo/go/database/sql/driver/driver.go10
-rw-r--r--libgo/go/database/sql/driver/types.go21
-rw-r--r--libgo/go/database/sql/fakedb_test.go11
-rw-r--r--libgo/go/database/sql/sql.go33
-rw-r--r--libgo/go/database/sql/sql_test.go10
7 files changed, 54 insertions, 52 deletions
diff --git a/libgo/go/database/sql/convert.go b/libgo/go/database/sql/convert.go
index 740fd9d..99aed23 100644
--- a/libgo/go/database/sql/convert.go
+++ b/libgo/go/database/sql/convert.go
@@ -44,7 +44,7 @@ func driverArgs(ds *driverStmt, args []interface{}) ([]driver.Value, error) {
// Let the Stmt convert its own arguments.
for n, arg := range args {
// First, see if the value itself knows how to convert
- // itself to a driver type. For example, a NullString
+ // itself to a driver type. For example, a NullString
// struct changing into a string or nil.
if svi, ok := arg.(driver.Valuer); ok {
sv, err := svi.Value()
@@ -217,7 +217,12 @@ func convertAssign(dest, src interface{}) error {
dv := reflect.Indirect(dpv)
if sv.IsValid() && sv.Type().AssignableTo(dv.Type()) {
- dv.Set(sv)
+ switch b := src.(type) {
+ case []byte:
+ dv.Set(reflect.ValueOf(cloneBytes(b)))
+ default:
+ dv.Set(sv)
+ }
return nil
}
diff --git a/libgo/go/database/sql/convert_test.go b/libgo/go/database/sql/convert_test.go
index 342875e..ab81f2f 100644
--- a/libgo/go/database/sql/convert_test.go
+++ b/libgo/go/database/sql/convert_test.go
@@ -377,3 +377,15 @@ func TestRawBytesAllocs(t *testing.T) {
t.Fatalf("allocs = %v; want max 1", n)
}
}
+
+// https://github.com/golang/go/issues/13905
+func TestUserDefinedBytes(t *testing.T) {
+ type userDefinedBytes []byte
+ var u userDefinedBytes
+ v := []byte("foo")
+
+ convertAssign(&u, v)
+ if &u[0] == &v[0] {
+ t.Fatal("userDefinedBytes got potentially dirty driver memory")
+ }
+}
diff --git a/libgo/go/database/sql/driver/driver.go b/libgo/go/database/sql/driver/driver.go
index eca25f2..4dba85a 100644
--- a/libgo/go/database/sql/driver/driver.go
+++ b/libgo/go/database/sql/driver/driver.go
@@ -17,7 +17,7 @@ import "errors"
// float64
// bool
// []byte
-// string [*] everywhere except from Rows.Next.
+// string
// time.Time
type Value interface{}
@@ -144,7 +144,7 @@ type Stmt interface {
// 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
+ // column index. If the type of a specific column isn't known
// or shouldn't be handled specially, DefaultValueConverter
// can be returned.
ColumnConverter(idx int) ValueConverter
@@ -154,7 +154,7 @@ type ColumnConverter interface {
type Rows interface {
// Columns returns the names of the columns. The number of
// columns of the result is inferred from the length of the
- // slice. If a particular column name isn't known, an empty
+ // slice. If a particular column name isn't known, an empty
// string should be returned for that entry.
Columns() []string
@@ -165,10 +165,6 @@ 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 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 []Value) error
}
diff --git a/libgo/go/database/sql/driver/types.go b/libgo/go/database/sql/driver/types.go
index bc54784..e480e70 100644
--- a/libgo/go/database/sql/driver/types.go
+++ b/libgo/go/database/sql/driver/types.go
@@ -15,7 +15,7 @@ import (
//
// Various implementations of ValueConverter are provided by the
// driver package to provide consistent implementations of conversions
-// between drivers. The ValueConverters have several uses:
+// 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
@@ -172,28 +172,21 @@ func (n NotNull) ConvertValue(v interface{}) (Value, error) {
}
// 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) {
+ if v == nil {
return true
}
- if _, ok := v.(string); ok {
+ switch v.(type) {
+ case []byte, bool, float64, int64, string, time.Time:
return true
}
return false
}
-// IsScanValue reports whether v is a valid Value scan type.
-// Unlike IsValue, IsScanValue does not permit the string type.
+// IsScanValue is equivalent to IsValue.
+// It exists for compatibility.
func IsScanValue(v interface{}) bool {
- if v == nil {
- return true
- }
- switch v.(type) {
- case int64, float64, []byte, bool, time.Time:
- return true
- }
- return false
+ return IsValue(v)
}
// DefaultParameterConverter is the default implementation of
diff --git a/libgo/go/database/sql/fakedb_test.go b/libgo/go/database/sql/fakedb_test.go
index b5ff121..5b238bf 100644
--- a/libgo/go/database/sql/fakedb_test.go
+++ b/libgo/go/database/sql/fakedb_test.go
@@ -37,7 +37,7 @@ var _ = log.Printf
// named method on fakeStmt to panic.
//
// When opening a fakeDriver's database, it starts empty with no
-// tables. All tables and data are stored in memory only.
+// tables. All tables and data are stored in memory only.
type fakeDriver struct {
mu sync.Mutex // guards 3 following fields
openCount int // conn opens
@@ -51,7 +51,6 @@ type fakeDB struct {
name string
mu sync.Mutex
- free []*fakeConn
tables map[string]*table
badConn bool
}
@@ -76,12 +75,6 @@ type row struct {
cols []interface{} // must be same size as its table colname + coltype
}
-func (r *row) clone() *row {
- nrow := &row{cols: make([]interface{}, len(r.cols))}
- copy(nrow.cols, r.cols)
- return nrow
-}
-
type fakeConn struct {
db *fakeDB // where to return ourselves to
@@ -705,7 +698,7 @@ func (s *fakeStmt) Query(args []driver.Value) (driver.Rows, error) {
rows:
for _, trow := range t.rows {
// Process the where clause, skipping non-match rows. This is lazy
- // and just uses fmt.Sprintf("%v") to test equality. Good enough
+ // and just uses fmt.Sprintf("%v") to test equality. Good enough
// for test code.
for widx, wcol := range s.whereCol {
idx := t.columnIndex(wcol)
diff --git a/libgo/go/database/sql/sql.go b/libgo/go/database/sql/sql.go
index d8e7cb7..09de1c3 100644
--- a/libgo/go/database/sql/sql.go
+++ b/libgo/go/database/sql/sql.go
@@ -199,7 +199,7 @@ type Scanner interface {
// time.Time
// nil - for NULL values
//
- // An error should be returned if the value can not be stored
+ // An error should be returned if the value cannot be stored
// without loss of information.
Scan(src interface{}) error
}
@@ -718,6 +718,9 @@ func (db *DB) maybeOpenNewConnections() {
for numRequests > 0 {
db.numOpen++ // optimistically
numRequests--
+ if db.closed {
+ return
+ }
db.openerCh <- struct{}{}
}
}
@@ -797,7 +800,7 @@ func (db *DB) conn(strategy connReuseStrategy) (*driverConn, error) {
return conn, nil
}
- // Out of free connections or we were asked not to use one. If we're not
+ // Out of free connections or we were asked not to use one. If we're not
// allowed to open any more connections, make a request and wait.
if db.maxOpen > 0 && db.numOpen >= db.maxOpen {
// Make the connRequest channel. It's buffered so that the
@@ -838,11 +841,6 @@ func (db *DB) conn(strategy connReuseStrategy) (*driverConn, error) {
return dc, nil
}
-var (
- errConnClosed = errors.New("database/sql: internal sentinel error: conn is closed")
- errConnBusy = errors.New("database/sql: internal sentinel error: conn is busy")
-)
-
// putConnHook is a hook for testing.
var putConnHook func(*DB, *driverConn)
@@ -920,6 +918,9 @@ func (db *DB) putConn(dc *driverConn, err error) {
// If a connRequest was fulfilled or the *driverConn was placed in the
// freeConn list, then true is returned, otherwise false is returned.
func (db *DB) putConnDBLocked(dc *driverConn, err error) bool {
+ if db.closed {
+ return false
+ }
if db.maxOpen > 0 && db.numOpen > db.maxOpen {
return false
}
@@ -1207,7 +1208,7 @@ type Tx struct {
// ErrTxDone.
done bool
- // All Stmts prepared for this transaction. These will be closed after the
+ // All Stmts prepared for this transaction. These will be closed after the
// transaction has been committed or rolled back.
stmts struct {
sync.Mutex
@@ -1286,7 +1287,7 @@ func (tx *Tx) Prepare(query string) (*Stmt, error) {
// necessary. Or, better: keep a map in DB of query string to
// Stmts, and have Stmt.Execute do the right thing and
// re-prepare if the Conn in use doesn't have that prepared
- // statement. But we'll want to avoid caching the statement
+ // statement. But we'll want to avoid caching the statement
// in the case where we only call conn.Prepare implicitly
// (such as in db.Exec or tx.Exec), but the caller package
// can't be holding a reference to the returned statement.
@@ -1334,7 +1335,7 @@ func (tx *Tx) Prepare(query string) (*Stmt, error) {
// be used once the transaction has been committed or rolled back.
func (tx *Tx) Stmt(stmt *Stmt) *Stmt {
// TODO(bradfitz): optimize this. Currently this re-prepares
- // each time. This is fine for now to illustrate the API but
+ // each time. This is fine for now to illustrate the API but
// we should really cache already-prepared statements
// per-Conn. See also the big comment in Tx.Prepare.
@@ -1441,9 +1442,9 @@ type Stmt struct {
closed bool
// css is a list of underlying driver statement interfaces
- // that are valid on particular connections. This is only
+ // that are valid on particular connections. This is only
// used if tx == nil and one is found that has idle
- // connections. If tx != nil, txsi is always used.
+ // connections. If tx != nil, txsi is always used.
css []connStmt
// lastNumClosed is copied from db.numClosed when Stmt is created
@@ -1741,9 +1742,9 @@ type Rows struct {
closeStmt driver.Stmt // if non-nil, statement to Close on close
}
-// Next prepares the next result row for reading with the Scan method. It
+// Next prepares the next result row for reading with the Scan method. It
// returns true on success, or false if there is no next result row or an error
-// happened while preparing it. Err should be consulted to distinguish between
+// happened while preparing it. Err should be consulted to distinguish between
// the two cases.
//
// Every call to Scan, even the first one, must be preceded by a call to Next.
@@ -1898,8 +1899,8 @@ func (r *Row) Scan(dest ...interface{}) error {
// the Rows in our defer, when we return from this function.
// the contract with the driver.Next(...) interface is that it
// can return slices into read-only temporary memory that's
- // only valid until the next Scan/Close. But the TODO is that
- // for a lot of drivers, this copy will be unnecessary. We
+ // only valid until the next Scan/Close. But the TODO is that
+ // for a lot of drivers, this copy will be unnecessary. We
// should provide an optional interface for drivers to
// implement to say, "don't worry, the []bytes that I return
// from Next will not be modified again." (for instance, if
diff --git a/libgo/go/database/sql/sql_test.go b/libgo/go/database/sql/sql_test.go
index 8ec70d9..08df0c7 100644
--- a/libgo/go/database/sql/sql_test.go
+++ b/libgo/go/database/sql/sql_test.go
@@ -144,7 +144,7 @@ func closeDB(t testing.TB, db *DB) {
count := db.numOpen
db.mu.Unlock()
if count != 0 {
- t.Fatalf("%d connections still open after closing DB", db.numOpen)
+ t.Fatalf("%d connections still open after closing DB", count)
}
}
@@ -911,7 +911,7 @@ func nullTestRun(t *testing.T, spec nullTestSpec) {
if err == nil {
// TODO: this test fails, but it's just because
// fakeConn implements the optional Execer interface,
- // so arguably this is the correct behavior. But
+ // so arguably this is the correct behavior. But
// maybe I should flesh out the fakeConn.Exec
// implementation so this properly fails.
// t.Errorf("expected error inserting nil name with Exec")
@@ -1239,7 +1239,7 @@ func TestPendingConnsAfterErr(t *testing.T) {
time.Sleep(10 * time.Millisecond) // make extra sure all workers are blocked
close(unblock) // let all workers proceed
- const timeout = 100 * time.Millisecond
+ const timeout = 5 * time.Second
to := time.NewTimer(timeout)
defer to.Stop()
@@ -1591,7 +1591,7 @@ func TestStmtCloseOrder(t *testing.T) {
_, err := db.Query("SELECT|non_existent|name|")
if err == nil {
- t.Fatal("Quering non-existent table should fail")
+ t.Fatal("Querying non-existent table should fail")
}
}
@@ -1615,6 +1615,8 @@ func TestManyErrBadConn(t *testing.T) {
}
}()
+ db.mu.Lock()
+ defer db.mu.Unlock()
if db.numOpen != nconn {
t.Fatalf("unexpected numOpen %d (was expecting %d)", db.numOpen, nconn)
} else if len(db.freeConn) != nconn {