From 1c4aab8a0c466922e5c5a3863289ecfd82b2c5d7 Mon Sep 17 00:00:00 2001 From: zhoutao Date: Wed, 23 May 2018 16:31:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 4 ++-- README.md | 36 ++++++++++++++++++------------------ connection.go | 12 +++++------- connection_test.go | 2 +- driver.go | 16 ++++++++-------- driver_go18_test.go | 4 ++-- driver_test.go | 12 ++++++------ dsn.go | 20 ++++++++++---------- errors.go | 12 ++++++------ packets.go | 4 ++-- packets_test.go | 2 +- result.go | 4 ++-- statement.go | 7 +++---- 13 files changed, 66 insertions(+), 69 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fe16bcb4..c577282de 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## Reporting Issues -Before creating a new Issue, please check first if a similar Issue [already exists](https://github.com/go-sql-driver/mysql/issues?state=open) or was [recently closed](https://github.com/go-sql-driver/mysql/issues?direction=desc&page=1&sort=updated&state=closed). +Before creating a new Issue, please check first if a similar Issue [already exists](https://github.com/jslyzt/mysql/issues?state=open) or was [recently closed](https://github.com/jslyzt/mysql/issues?direction=desc&page=1&sort=updated&state=closed). ## Contributing Code @@ -20,4 +20,4 @@ Before merging the Pull Request, at least one [team member](https://github.com/g ## Development Ideas -If you are looking for ideas for code contributions, please check our [Development Ideas](https://github.com/go-sql-driver/mysql/wiki/Development-Ideas) Wiki page. +If you are looking for ideas for code contributions, please check our [Development Ideas](https://github.com/jslyzt/mysql/wiki/Development-Ideas) Wiki page. diff --git a/README.md b/README.md index 299198d53..856bb0273 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) package -![Go-MySQL-Driver logo](https://raw.github.com/wiki/go-sql-driver/mysql/gomysql_m.png "Golang Gopher holding the MySQL Dolphin") +![Go-MySQL-Driver logo](https://raw.github.com/wiki/jslyzt/mysql/gomysql_m.png "Golang Gopher holding the MySQL Dolphin") --------------------------------------- * [Features](#features) @@ -29,7 +29,7 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac ## Features * Lightweight and [fast](https://github.com/go-sql-driver/sql-benchmark "golang MySQL-Driver performance") * Native Go implementation. No C-bindings, just pure Go - * Connections over TCP/IPv4, TCP/IPv6, Unix domain sockets or [custom protocols](https://godoc.org/github.com/go-sql-driver/mysql#DialFunc) + * Connections over TCP/IPv4, TCP/IPv6, Unix domain sockets or [custom protocols](https://godoc.org/github.com/jslyzt/mysql#DialFunc) * Automatic handling of broken connections * Automatic Connection Pooling *(by database/sql package)* * Supports queries larger than 16MB @@ -48,7 +48,7 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac ## Installation Simple install the package to your [$GOPATH](https://github.com/golang/go/wiki/GOPATH "GOPATH") with the [go tool](https://golang.org/cmd/go/ "go command") from shell: ```bash -$ go get -u github.com/go-sql-driver/mysql +$ go get -u github.com/jslyzt/mysql ``` Make sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`. @@ -58,12 +58,12 @@ _Go MySQL Driver_ is an implementation of Go's `database/sql/driver` interface. Use `mysql` as `driverName` and a valid [DSN](#dsn-data-source-name) as `dataSourceName`: ```go import "database/sql" -import _ "github.com/go-sql-driver/mysql" +import _ "github.com/jslyzt/mysql" db, err := sql.Open("mysql", "user:password@/dbname") ``` -[Examples are available in our Wiki](https://github.com/go-sql-driver/mysql/wiki/Examples "Go-MySQL-Driver Examples"). +[Examples are available in our Wiki](https://github.com/jslyzt/mysql/wiki/Examples "Go-MySQL-Driver Examples"). ### DSN (Data Source Name) @@ -92,7 +92,7 @@ This has the same effect as an empty DSN string: ``` -Alternatively, [Config.FormatDSN](https://godoc.org/github.com/go-sql-driver/mysql#Config.FormatDSN) can be used to create a DSN string by filling a struct. +Alternatively, [Config.FormatDSN](https://godoc.org/github.com/jslyzt/mysql#Config.FormatDSN) can be used to create a DSN string by filling a struct. #### Password Passwords can consist of any character. Escaping is **not** necessary. @@ -151,7 +151,7 @@ Type: bool Valid Values: true, false Default: false ``` -`allowOldPasswords=true` allows the usage of the insecure old password method. This should be avoided, but is necessary in some cases. See also [the old_passwords wiki page](https://github.com/go-sql-driver/mysql/wiki/old_passwords). +`allowOldPasswords=true` allows the usage of the insecure old password method. This should be avoided, but is necessary in some cases. See also [the old_passwords wiki page](https://github.com/jslyzt/mysql/wiki/old_passwords). ##### `charset` @@ -318,7 +318,7 @@ Valid Values: true, false, skip-verify, Default: false ``` -`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side). Use a custom value registered with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig). +`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side). Use a custom value registered with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/jslyzt/mysql#RegisterTLSConfig). ##### `writeTimeout` @@ -417,14 +417,14 @@ See [context support in the database/sql package](https://golang.org/doc/go1.8#d ### `LOAD DATA LOCAL INFILE` support For this feature you need direct access to the package. Therefore you must change the import path (no `_`): ```go -import "github.com/go-sql-driver/mysql" +import "github.com/jslyzt/mysql" ``` Files must be whitelisted by registering them with `mysql.RegisterLocalFile(filepath)` (recommended) or the Whitelist check must be deactivated by using the DSN parameter `allowAllFiles=true` ([*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)). To use a `io.Reader` a handler function must be registered with `mysql.RegisterReaderHandler(name, handler)` which returns a `io.Reader` or `io.ReadCloser`. The Reader is available with the filepath `Reader::` then. Choose different names for different handlers and `DeregisterReaderHandler` when you don't need it anymore. -See the [godoc of Go-MySQL-Driver](https://godoc.org/github.com/go-sql-driver/mysql "golang mysql driver documentation") for details. +See the [godoc of Go-MySQL-Driver](https://godoc.org/github.com/jslyzt/mysql "golang mysql driver documentation") for details. ### `time.Time` support @@ -432,9 +432,9 @@ The default internal output type of MySQL `DATE` and `DATETIME` values is `[]byt However, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` variables, which is the logical opposite in Go to `DATE` and `DATETIME` in MySQL. You can do that by changing the internal output type from `[]byte` to `time.Time` with the DSN parameter `parseTime=true`. You can set the default [`time.Time` location](https://golang.org/pkg/time/#Location) with the `loc` DSN parameter. -**Caution:** As of Go 1.1, this makes `time.Time` the only variable type you can scan `DATE` and `DATETIME` values into. This breaks for example [`sql.RawBytes` support](https://github.com/go-sql-driver/mysql/wiki/Examples#rawbytes). +**Caution:** As of Go 1.1, this makes `time.Time` the only variable type you can scan `DATE` and `DATETIME` values into. This breaks for example [`sql.RawBytes` support](https://github.com/jslyzt/mysql/wiki/Examples#rawbytes). -Alternatively you can use the [`NullTime`](https://godoc.org/github.com/go-sql-driver/mysql#NullTime) type as the scan destination, which works with both `time.Time` and `string` / `[]byte`. +Alternatively you can use the [`NullTime`](https://godoc.org/github.com/jslyzt/mysql#NullTime) type as the scan destination, which works with both `time.Time` and `string` / `[]byte`. ### Unicode support @@ -447,17 +447,17 @@ Version 1.0 of the driver recommended adding `&charset=utf8` (alias for `SET NAM See http://dev.mysql.com/doc/refman/5.7/en/charset-unicode.html for more details on MySQL's Unicode support. ## Testing / Development -To run the driver tests you may need to adjust the configuration. See the [Testing Wiki-Page](https://github.com/go-sql-driver/mysql/wiki/Testing "Testing") for details. +To run the driver tests you may need to adjust the configuration. See the [Testing Wiki-Page](https://github.com/jslyzt/mysql/wiki/Testing "Testing") for details. Go-MySQL-Driver is not feature-complete yet. Your help is very appreciated. -If you want to contribute, you can work on an [open issue](https://github.com/go-sql-driver/mysql/issues?state=open) or review a [pull request](https://github.com/go-sql-driver/mysql/pulls). +If you want to contribute, you can work on an [open issue](https://github.com/jslyzt/mysql/issues?state=open) or review a [pull request](https://github.com/jslyzt/mysql/pulls). -See the [Contribution Guidelines](https://github.com/go-sql-driver/mysql/blob/master/CONTRIBUTING.md) for details. +See the [Contribution Guidelines](https://github.com/jslyzt/mysql/blob/master/CONTRIBUTING.md) for details. --------------------------------------- ## License -Go-MySQL-Driver is licensed under the [Mozilla Public License Version 2.0](https://raw.github.com/go-sql-driver/mysql/master/LICENSE) +Go-MySQL-Driver is licensed under the [Mozilla Public License Version 2.0](https://raw.github.com/jslyzt/mysql/master/LICENSE) Mozilla summarizes the license scope as follows: > MPL: The copyleft applies to any files containing MPLed code. @@ -470,7 +470,7 @@ That means: Please read the [MPL 2.0 FAQ](https://www.mozilla.org/en-US/MPL/2.0/FAQ/) if you have further questions regarding the license. -You can read the full terms here: [LICENSE](https://raw.github.com/go-sql-driver/mysql/master/LICENSE). +You can read the full terms here: [LICENSE](https://raw.github.com/jslyzt/mysql/master/LICENSE). -![Go Gopher and MySQL Dolphin](https://raw.github.com/wiki/go-sql-driver/mysql/go-mysql-driver_m.jpg "Golang Gopher transporting the MySQL Dolphin in a wheelbarrow") +![Go Gopher and MySQL Dolphin](https://raw.github.com/wiki/jslyzt/mysql/go-mysql-driver_m.jpg "Golang Gopher transporting the MySQL Dolphin in a wheelbarrow") diff --git a/connection.go b/connection.go index e57061412..d64516de3 100644 --- a/connection.go +++ b/connection.go @@ -31,7 +31,7 @@ type mysqlConn struct { buf buffer netConn net.Conn affectedRows uint64 - insertId uint64 + insertID uint64 cfg *Config maxAllowedPacket int maxWriteSize int @@ -76,7 +76,6 @@ func (mc *mysqlConn) handleParams() (err error) { } } } - return } @@ -87,6 +86,7 @@ func (mc *mysqlConn) markBadConn(err error) error { if err != errBadConnNoWrite { return err } + errLog.Print("markBadConn error: ", err) return driver.ErrBadConn } @@ -117,9 +117,7 @@ func (mc *mysqlConn) Close() (err error) { if !mc.closed.IsSet() { err = mc.writeCommandPacket(comQuit) } - mc.cleanup() - return } @@ -147,6 +145,7 @@ func (mc *mysqlConn) error() error { if err := mc.canceled.Value(); err != nil { return err } + errLog.Print("mysqlConn error is nil") return ErrInvalidConn } return nil @@ -175,7 +174,6 @@ func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) { return nil, err } } - if columnCount > 0 { err = mc.readUntilEOF() } @@ -323,13 +321,13 @@ func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, err query = prepared } mc.affectedRows = 0 - mc.insertId = 0 + mc.insertID = 0 err := mc.exec(query) if err == nil { return &mysqlResult{ affectedRows: int64(mc.affectedRows), - insertId: int64(mc.insertId), + insertID: int64(mc.insertID), }, err } return nil, mc.markBadConn(err) diff --git a/connection_test.go b/connection_test.go index 65325f101..fcc54e205 100644 --- a/connection_test.go +++ b/connection_test.go @@ -49,7 +49,7 @@ func TestInterpolateParamsTooManyPlaceholders(t *testing.T) { } // We don't support placeholder in string literal for now. -// https://github.com/go-sql-driver/mysql/pull/490 +// https://github.com/jslyzt/mysql/pull/490 func TestInterpolateParamsPlaceholderInString(t *testing.T) { mc := &mysqlConn{ buf: newBuffer(nil), diff --git a/driver.go b/driver.go index f77b917a8..a3b5333d5 100644 --- a/driver.go +++ b/driver.go @@ -9,11 +9,11 @@ // The driver should be used via the database/sql package: // // import "database/sql" -// import _ "github.com/go-sql-driver/mysql" +// import _ "github.com/jslyzt/mysql" // // db, err := sql.Open("mysql", "user:password@/dbname") // -// See https://github.com/go-sql-driver/mysql#usage for details +// See https://github.com/jslyzt/mysql#usage for details package mysql import ( @@ -28,9 +28,9 @@ type watcher interface { startWatcher() } -// MySQLDriver is exported to make the driver directly accessible. +// MSQLDriver is exported to make the driver directly accessible. // In general the driver is used via the database/sql package. -type MySQLDriver struct{} +type MSQLDriver struct{} // DialFunc is a function which can be used to establish the network connection. // Custom dial functions must be registered with RegisterDial @@ -54,9 +54,9 @@ func RegisterDial(net string, dial DialFunc) { } // Open new Connection. -// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how +// See https://github.com/jslyzt/mysql#dsn-data-source-name for how // the DSN string is formated -func (d MySQLDriver) Open(dsn string) (driver.Conn, error) { +func (d MSQLDriver) Open(dsn string) (driver.Conn, error) { var err error // New mysqlConn @@ -188,7 +188,7 @@ func handleAuthResult(mc *mysqlConn, oldCipher []byte, pluginName string) error if mc.cfg.AllowOldPasswords && err == ErrOldPassword { // Retry with old authentication method. Note: there are edge cases // where this should work but doesn't; this is currently "wontfix": - // https://github.com/go-sql-driver/mysql/issues/184 + // https://github.com/jslyzt/mysql/issues/184 // If CLIENT_PLUGIN_AUTH capability is not supported, no new cipher is // sent and we have to keep using the cipher sent in the init packet. @@ -218,5 +218,5 @@ func handleAuthResult(mc *mysqlConn, oldCipher []byte, pluginName string) error } func init() { - sql.Register("mysql", &MySQLDriver{}) + sql.Register("mysql", &MSQLDriver{}) } diff --git a/driver_go18_test.go b/driver_go18_test.go index afd5694ec..f508f895a 100644 --- a/driver_go18_test.go +++ b/driver_go18_test.go @@ -547,7 +547,7 @@ func TestContextBeginReadOnly(t *testing.T) { tx, err := dbt.db.BeginTx(ctx, &sql.TxOptions{ ReadOnly: true, }) - if _, ok := err.(*MySQLError); ok { + if _, ok := err.(*MSQLError); ok { dbt.Skip("It seems that your MySQL does not support READ ONLY transactions") return } else if err != nil { @@ -556,7 +556,7 @@ func TestContextBeginReadOnly(t *testing.T) { // INSERT queries fail in a READ ONLY transaction. _, err = tx.ExecContext(ctx, "INSERT INTO test VALUES (1)") - if _, ok := err.(*MySQLError); !ok { + if _, ok := err.(*MSQLError); !ok { dbt.Errorf("expected MySQLError, got %v", err) } diff --git a/driver_test.go b/driver_test.go index 8904b6587..066b0ed87 100644 --- a/driver_test.go +++ b/driver_test.go @@ -54,7 +54,7 @@ var ( sDateTime0 = "0000-00-00 00:00:00" ) -// See https://github.com/go-sql-driver/mysql/wiki/Testing +// See https://github.com/jslyzt/mysql/wiki/Testing func init() { // get environment variables env := func(key, defaultValue string) string { @@ -178,7 +178,7 @@ func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows) } func maybeSkip(t *testing.T, err error, skipErrno uint16) { - mySQLErr, ok := err.(*MySQLError) + mySQLErr, ok := err.(*MSQLError) if !ok { return } @@ -408,7 +408,7 @@ func TestFloat32(t *testing.T) { func TestFloat64(t *testing.T) { runTests(t, dsn, func(dbt *DBTest) { types := [2]string{"FLOAT", "DOUBLE"} - var expected float64 = 42.23 + expected := 42.23 var out float64 var rows *sql.Rows for _, v := range types { @@ -431,7 +431,7 @@ func TestFloat64(t *testing.T) { func TestFloat64Placeholder(t *testing.T) { runTests(t, dsn, func(dbt *DBTest) { types := [2]string{"FLOAT", "DOUBLE"} - var expected float64 = 42.23 + expected := 42.23 var out float64 var rows *sql.Rows for _, v := range types { @@ -515,7 +515,7 @@ func TestRawBytes(t *testing.T) { if !bytes.Equal(v2, o2) { dbt.Errorf("expected %v, got %v", v2, o2) } - // https://github.com/go-sql-driver/mysql/issues/765 + // https://github.com/jslyzt/mysql/issues/765 // Appending to RawBytes shouldn't overwrite next RawBytes. o1 = append(o1, "xyzzy"...) if !bytes.Equal(v2, o2) { @@ -1322,7 +1322,7 @@ func TestReuseClosedConnection(t *testing.T) { t.Skipf("MySQL server not running on %s", netAddr) } - md := &MySQLDriver{} + md := &MSQLDriver{} conn, err := md.Open(dsn) if err != nil { t.Fatalf("error connecting: %s", err.Error()) diff --git a/dsn.go b/dsn.go index 47eab6945..dccc68fa8 100644 --- a/dsn.go +++ b/dsn.go @@ -99,6 +99,8 @@ func (cfg *Config) normalize() error { host, _, err := net.SplitHostPort(cfg.Addr) if err == nil { cfg.tls.ServerName = host + } else { + return err } } } @@ -347,7 +349,6 @@ func ParseDSN(dsn string) (cfg *Config, err error) { } } cfg.User = dsn[:k] - break } } @@ -381,7 +382,6 @@ func ParseDSN(dsn string) (cfg *Config, err error) { } } cfg.DBName = dsn[i+1 : j] - break } } @@ -474,11 +474,11 @@ func parseDSNParams(cfg *Config, params string) (err error) { // Time Location case "loc": if value, err = url.QueryUnescape(value); err != nil { - return + return err } cfg.Loc, err = time.LoadLocation(value) if err != nil { - return + return err } // multiple statements in one query @@ -501,7 +501,7 @@ func parseDSNParams(cfg *Config, params string) (err error) { case "readTimeout": cfg.ReadTimeout, err = time.ParseDuration(value) if err != nil { - return + return err } // Reject read-only connections @@ -514,13 +514,13 @@ func parseDSNParams(cfg *Config, params string) (err error) { // Strict mode case "strict": - panic("strict mode has been removed. See https://github.com/go-sql-driver/mysql/wiki/strict-mode") + panic("strict mode has been removed. See https://github.com/jslyzt/mysql/wiki/strict-mode") // Dial Timeout case "timeout": cfg.Timeout, err = time.ParseDuration(value) if err != nil { - return + return err } // TLS-Encryption @@ -554,12 +554,12 @@ func parseDSNParams(cfg *Config, params string) (err error) { case "writeTimeout": cfg.WriteTimeout, err = time.ParseDuration(value) if err != nil { - return + return err } case "maxAllowedPacket": cfg.MaxAllowedPacket, err = strconv.Atoi(value) if err != nil { - return + return err } default: // lazy init @@ -568,7 +568,7 @@ func parseDSNParams(cfg *Config, params string) (err error) { } if cfg.Params[param[0]], err = url.QueryUnescape(value); err != nil { - return + return err } } } diff --git a/errors.go b/errors.go index 760782ff2..67c5532cd 100644 --- a/errors.go +++ b/errors.go @@ -21,8 +21,8 @@ var ( ErrMalformPkt = errors.New("malformed packet") ErrNoTLS = errors.New("TLS requested but server does not support TLS") ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN") - ErrNativePassword = errors.New("this user requires mysql native password authentication.") - ErrOldPassword = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords") + ErrNativePassword = errors.New("this user requires mysql native password authentication") + ErrOldPassword = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/jslyzt/mysql/wiki/old_passwords") ErrUnknownPlugin = errors.New("this authentication plugin is not supported") ErrOldProtocol = errors.New("MySQL server does not support required protocol 41+") ErrPktSync = errors.New("commands out of sync. You can't run this command now") @@ -33,7 +33,7 @@ var ( // errBadConnNoWrite is used for connection errors where nothing was sent to the database yet. // If this happens first in a function starting a database interaction, it should be replaced by driver.ErrBadConn // to trigger a resend. - // See https://github.com/go-sql-driver/mysql/pull/302 + // See https://github.com/jslyzt/mysql/pull/302 errBadConnNoWrite = errors.New("bad connection") ) @@ -54,12 +54,12 @@ func SetLogger(logger Logger) error { return nil } -// MySQLError is an error type which represents a single MySQL error -type MySQLError struct { +// MSQLError is an error type which represents a single MySQL error +type MSQLError struct { Number uint16 Message string } -func (me *MySQLError) Error() string { +func (me *MSQLError) Error() string { return fmt.Sprintf("Error %d: %s", me.Number, me.Message) } diff --git a/packets.go b/packets.go index 9b76fb040..3580dd0af 100644 --- a/packets.go +++ b/packets.go @@ -658,7 +658,7 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error { } // Error Message [string] - return &MySQLError{ + return &MSQLError{ Number: errno, Message: string(data[pos:]), } @@ -679,7 +679,7 @@ func (mc *mysqlConn) handleOkPacket(data []byte) error { mc.affectedRows, _, n = readLengthEncodedInteger(data[1:]) // Insert id [Length Coded Binary] - mc.insertId, _, m = readLengthEncodedInteger(data[1+n:]) + mc.insertID, _, m = readLengthEncodedInteger(data[1+n:]) // server_status [2 bytes] mc.status = readStatus(data[1+n+m : 1+n+m+2]) diff --git a/packets_test.go b/packets_test.go index c9cfd9001..5ce4ce9ea 100644 --- a/packets_test.go +++ b/packets_test.go @@ -282,7 +282,7 @@ func TestReadPacketFail(t *testing.T) { } } -// https://github.com/go-sql-driver/mysql/pull/801 +// https://github.com/jslyzt/mysql/pull/801 // not-NUL terminated plugin_name in init packet func TestRegression801(t *testing.T) { conn := new(mockConn) diff --git a/result.go b/result.go index c6438d034..9094f05a0 100644 --- a/result.go +++ b/result.go @@ -10,11 +10,11 @@ package mysql type mysqlResult struct { affectedRows int64 - insertId int64 + insertID int64 } func (res *mysqlResult) LastInsertId() (int64, error) { - return res.insertId, nil + return res.insertID, nil } func (res *mysqlResult) RowsAffected() (int64, error) { diff --git a/statement.go b/statement.go index ce7fe4cd0..7500f3a77 100644 --- a/statement.go +++ b/statement.go @@ -58,7 +58,7 @@ func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) { mc := stmt.mc mc.affectedRows = 0 - mc.insertId = 0 + mc.insertID = 0 // Read Result resLen, err := mc.readResultSetHeaderPacket() @@ -84,7 +84,7 @@ func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) { return &mysqlResult{ affectedRows: int64(mc.affectedRows), - insertId: int64(mc.insertId), + insertID: int64(mc.insertID), }, nil } @@ -159,9 +159,8 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) { // indirect pointers if rv.IsNil() { return nil, nil - } else { - return c.ConvertValue(rv.Elem().Interface()) } + return c.ConvertValue(rv.Elem().Interface()) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return rv.Int(), nil case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32: