Skip to content

Commit bab9d5e

Browse files
committed
2 parents 7f692db + a9fa005 commit bab9d5e

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.DS_Store

driver.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"bufio"
1313
"database/sql"
1414
"database/sql/driver"
15-
"errors"
1615
"net"
1716
)
1817

@@ -28,11 +27,6 @@ func (d *mysqlDriver) Open(dsn string) (driver.Conn, error) {
2827
mc := new(mysqlConn)
2928
mc.cfg = parseDSN(dsn)
3029

31-
if mc.cfg.dbname == "" {
32-
e = errors.New("Incomplete or invalid DSN")
33-
return nil, e
34-
}
35-
3630
// Connect to Server
3731
mc.netConn, e = net.Dial(mc.cfg.net, mc.cfg.addr)
3832
if e != nil {

packets.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,19 @@ func (mc *mysqlConn) writeAuthPacket() (e error) {
208208
if mc.server.flags&CLIENT_LONG_FLAG > 0 {
209209
clientFlags |= uint32(CLIENT_LONG_FLAG)
210210
}
211+
212+
// User Password
213+
scrambleBuff := scramblePassword(mc.server.scrambleBuff, []byte(mc.cfg.passwd))
214+
215+
pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.user) + 1 + 1 + len(scrambleBuff)
216+
211217
// To specify a db name
212218
if len(mc.cfg.dbname) > 0 {
213219
clientFlags |= uint32(CLIENT_CONNECT_WITH_DB)
220+
pktLen += len(mc.cfg.dbname) + 1
214221
}
215222

216-
// User Password
217-
scrambleBuff := scramblePassword(mc.server.scrambleBuff, []byte(mc.cfg.passwd))
218-
219223
// Calculate packet length and make buffer with that size
220-
pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.user) + 1 + 1 + len(scrambleBuff) + len(mc.cfg.dbname) + 1
221224
data := make([]byte, 0, pktLen+4)
222225

223226
// Add the packet header
@@ -338,7 +341,7 @@ func (mc *mysqlConn) readResultOK() (e error) {
338341
return mc.handleOkPacket(data)
339342
// EOF, someone is using old_passwords
340343
case 254:
341-
e = errors.New("It seems like you are using old_passwords, which is unsupported. See https://github.com/Go-SQL-Driver/MySQL/wiki/old_passwords")
344+
e = errors.New("It seems like you are using old_passwords, which is unsupported. See http://code.google.com/p/go-mysql-driver/wiki/old_passwords")
342345
return
343346
// ERROR
344347
case 255:

0 commit comments

Comments
 (0)