Browse Source

Added support for custom string types in ConvertValue. (#623)

* Added support for custom string types.

* Add author name

* Added license header

* Added a newline to force a commit.

* Remove newline.
Daniel Montoya 8 years ago
parent
commit
0aa39ff15f
3 changed files with 24 additions and 0 deletions
  1. 1 0
      AUTHORS
  2. 2 0
      statement.go
  3. 21 0
      statement_test.go

+ 1 - 0
AUTHORS

@@ -18,6 +18,7 @@ Asta Xie <xiemengjun at gmail.com>
 Bulat Gaifullin <gaifullinbf at gmail.com>
 Carlos Nieto <jose.carlos at menteslibres.net>
 Chris Moos <chris at tech9computers.com>
+Daniel Montoya <dsmontoyam at gmail.com>
 Daniel Nichter <nil at codenode.com>
 Daniël van Eeden <git at myname.nl>
 Dave Protasowski <dprotaso at gmail.com>

+ 2 - 0
statement.go

@@ -157,6 +157,8 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
 		return int64(u64), nil
 	case reflect.Float32, reflect.Float64:
 		return rv.Float(), nil
+	case reflect.String:
+		return rv.String(), nil
 	}
 	return nil, fmt.Errorf("unsupported type %T, a %s", v, rv.Kind())
 }

+ 21 - 0
statement_test.go

@@ -0,0 +1,21 @@
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
+//
+// Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved.
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// You can obtain one at http://mozilla.org/MPL/2.0/.
+
+package mysql
+
+import "testing"
+
+type customString string
+
+func TestConvertValueCustomTypes(t *testing.T) {
+	var cstr customString = "string"
+	c := converter{}
+	if _, err := c.ConvertValue(cstr); err != nil {
+		t.Errorf("custom string type should be valid")
+	}
+}