@@ -1038,11 +1038,12 @@ func (c *conn) CheckNamedValue(value *driver.NamedValue) error {
10381038 if checkIsValidType (value .Value ) {
10391039 return nil
10401040 }
1041- if valuer , ok := value .Value .(driver.Valuer ); ok {
1042- v , err := callValuerValue (valuer )
1043- if err != nil {
1044- return err
1045- }
1041+
1042+ // Convert the value using the default sql driver. This uses driver.Valuer,
1043+ // if implemented, and falls back to reflection. If the converted value is
1044+ // a supported spanner type, use it. Otherwise, ignore any errors and
1045+ // continue checking other supported spanner specific types.
1046+ if v , err := driver .DefaultParameterConverter .ConvertValue (value .Value ); err == nil {
10461047 if checkIsValidType (v ) {
10471048 value .Value = v
10481049 return nil
@@ -1252,27 +1253,6 @@ func (c *conn) createPartitionedDmlQueryOptions() spanner.QueryOptions {
12521253 return spanner.QueryOptions {ExcludeTxnFromChangeStreams : c .excludeTxnFromChangeStreams }
12531254}
12541255
1255- // callValuerValue is from Go's database/sql package to handle a special case,
1256- // in the same way that database/sql does, for nil pointers to types that implement
1257- // driver.Valuer with value receivers.
1258-
1259- var valuerReflectType = reflect .TypeOf ((* driver .Valuer )(nil )).Elem ()
1260-
1261- // callValuerValue returns vr.Value(), with one exception:
1262- // If vr.Value is a value receiver method on a pointer type and the pointer is nil,
1263- // it would panic at runtime. This treats it like nil instead.
1264- //
1265- // This is so people can implement driver.Value on value types and still use nil pointers
1266- // to those types to mean nil/NULL, just like the Go database/sql package.
1267- func callValuerValue (vr driver.Valuer ) (v driver.Value , err error ) {
1268- if rv := reflect .ValueOf (vr ); rv .Kind () == reflect .Ptr &&
1269- rv .IsNil () &&
1270- rv .Type ().Elem ().Implements (valuerReflectType ) {
1271- return nil , nil
1272- }
1273- return vr .Value ()
1274- }
1275-
12761256/* The following is the same implementation as in google-cloud-go/spanner */
12771257
12781258func isStructOrArrayOfStructValue (v interface {}) bool {
0 commit comments