Skip to content

Commit a807d31

Browse files
author
Joshua Prunier
committed
updated const.go with master
2 parents 5e84982 + 0cc29e9 commit a807d31

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Luke Scott <luke at webconnex.com>
3232
Michael Woolnough <michael.woolnough at gmail.com>
3333
Nicola Peduzzi <thenikso at gmail.com>
3434
Runrioter Wung <runrioter at gmail.com>
35+
Soroush Pour <me at soroushjp.com>
3536
Xiaobing Jiang <s7v7nislands at gmail.com>
3637
Xiuming Chen <cc at cxm.cc>
3738

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ Default: UTC
214214

215215
Sets the location for time.Time values (when using `parseTime=true`). *"Local"* sets the system's location. See [time.LoadLocation](http://golang.org/pkg/time/#LoadLocation) for details.
216216

217+
Note that this sets the location for time.Time values but does not change MySQL's [time_zone setting](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html). For that see the [time_zone system variable](#system-variables), which can also be set as a DSN parameter.
218+
217219
Please keep in mind, that param values must be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed. Alternatively you can manually replace the `/` with `%2F`. For example `US/Pacific` would be `loc=US%2FPacific`.
218220

219221

@@ -266,7 +268,7 @@ Default: false
266268

267269
All other parameters are interpreted as system variables:
268270
* `autocommit`: `"SET autocommit=<value>"`
269-
* `time_zone`: `"SET time_zone=<value>"`
271+
* [`time_zone`](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html): `"SET time_zone=<value>"`
270272
* [`tx_isolation`](https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_tx_isolation): `"SET tx_isolation=<value>"`
271273
* `param`: `"SET <param>=<value>"`
272274

const.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
iERR byte = 0xff
2525
)
2626

27+
// https://dev.mysql.com/doc/internals/en/capability-flags.html#packet-Protocol::CapabilityFlags
2728
type clientFlag uint32
2829

2930
const (
@@ -47,6 +48,11 @@ const (
4748
clientMultiResults
4849
clientPSMultiResults
4950
clientPluginAuth
51+
clientConnectAttrs
52+
clientPluginAuthLenEncClientData
53+
clientCanHandleExpiredPasswords
54+
clientSessionTrack
55+
clientDeprecateEOF
5056
)
5157

5258
const (
@@ -80,6 +86,7 @@ const (
8086
comStmtFetch
8187
)
8288

89+
// https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType
8390
const (
8491
fieldTypeDecimal byte = iota
8592
fieldTypeTiny
@@ -134,7 +141,6 @@ const (
134141
)
135142

136143
// http://dev.mysql.com/doc/internals/en/status-flags.html
137-
138144
type statusFlag uint16
139145

140146
const (

driver_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,49 @@ func TestNULL(t *testing.T) {
780780
})
781781
}
782782

783+
func TestUint64(t *testing.T) {
784+
const (
785+
u0 = uint64(0)
786+
uall = ^u0
787+
uhigh = uall >> 1
788+
utop = ^uhigh
789+
s0 = int64(0)
790+
sall = ^s0
791+
shigh = int64(uhigh)
792+
stop = ^shigh
793+
)
794+
runTests(t, dsn, func(dbt *DBTest) {
795+
stmt, err := dbt.db.Prepare(`SELECT ?, ?, ? ,?, ?, ?, ?, ?`)
796+
if err != nil {
797+
dbt.Fatal(err)
798+
}
799+
defer stmt.Close()
800+
row := stmt.QueryRow(
801+
u0, uhigh, utop, uall,
802+
s0, shigh, stop, sall,
803+
)
804+
805+
var ua, ub, uc, ud uint64
806+
var sa, sb, sc, sd int64
807+
808+
err = row.Scan(&ua, &ub, &uc, &ud, &sa, &sb, &sc, &sd)
809+
if err != nil {
810+
dbt.Fatal(err)
811+
}
812+
switch {
813+
case ua != u0,
814+
ub != uhigh,
815+
uc != utop,
816+
ud != uall,
817+
sa != s0,
818+
sb != shigh,
819+
sc != stop,
820+
sd != sall:
821+
dbt.Fatal("Unexpected result value")
822+
}
823+
})
824+
}
825+
783826
func TestLongData(t *testing.T) {
784827
runTests(t, dsn, func(dbt *DBTest) {
785828
var maxAllowedPacketSize int

statement.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ package mysql
1010

1111
import (
1212
"database/sql/driver"
13+
"fmt"
14+
"reflect"
1315
)
1416

1517
type mysqlStmt struct {
@@ -34,6 +36,10 @@ func (stmt *mysqlStmt) NumInput() int {
3436
return stmt.paramCount
3537
}
3638

39+
func (stmt *mysqlStmt) ColumnConverter(idx int) driver.ValueConverter {
40+
return converter{}
41+
}
42+
3743
func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) {
3844
if stmt.mc.netConn == nil {
3945
errLog.Print(ErrInvalidConn)
@@ -110,3 +116,34 @@ func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
110116

111117
return rows, err
112118
}
119+
120+
type converter struct{}
121+
122+
func (converter) ConvertValue(v interface{}) (driver.Value, error) {
123+
if driver.IsValue(v) {
124+
return v, nil
125+
}
126+
127+
rv := reflect.ValueOf(v)
128+
switch rv.Kind() {
129+
case reflect.Ptr:
130+
// indirect pointers
131+
if rv.IsNil() {
132+
return nil, nil
133+
}
134+
return driver.DefaultParameterConverter.ConvertValue(rv.Elem().Interface())
135+
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
136+
return rv.Int(), nil
137+
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
138+
return int64(rv.Uint()), nil
139+
case reflect.Uint64:
140+
u64 := rv.Uint()
141+
if u64 >= 1<<63 {
142+
return fmt.Sprintf("%d", u64), nil
143+
}
144+
return int64(u64), nil
145+
case reflect.Float32, reflect.Float64:
146+
return rv.Float(), nil
147+
}
148+
return nil, fmt.Errorf("unsupported type %T, a %s", v, rv.Kind())
149+
}

0 commit comments

Comments
 (0)