-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.go
88 lines (79 loc) · 1.57 KB
/
field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package mconn
import (
"fmt"
"time"
)
const (
fieldTypeHeaderNull = 0xfb
timeFormat = "2006-01-02 15:04:05.999999"
)
// FieldType is type of mysql field
const (
FieldTypeDecimal = iota
FieldTypeTiny
FieldTypeShort
FieldTypeLong
FieldTypeFloat
FieldTypeDouble
FieldTypeNull
FieldTypeTimestamp
FieldTypeLongLong
FieldTypeInt24
FieldTypeDate
FieldTypeTime
FieldTypeDateTime
FieldTypeYear
FieldTypeNewDate
FieldTypeVarChar
FieldTypeBit
FieldTypeTimestamp2
FieldTypeDateTime2
FieldTypeTime2
)
// FieldType is type of mysql field
const (
FieldTypeJSON = 0xf5 + iota
FieldTypeNewDecimal
FieldTypeEnum
FieldTypeSet
FieldTypeTinyBlob
FieldTypeMediumBlob
FieldTypeLongBlob
FieldTypeBlob
FieldTypeVarString
FieldTypeString
FieldTypeGeometry
)
// Field is a mysql field
type Field struct {
schemaName string
tableName string
fieldName string
characterSet uint16
columnLength uint32
fieldType byte
flags uint16
demicals byte
}
func parseDateTime(str string, loc *time.Location) (time.Time, error) {
var t time.Time
var err error
base := "0000-00-00 00:00:00.0000000"
switch len(str) {
case 10, 19, 21, 22, 23, 24, 25, 26: // up to "YYYY-MM-DD HH:MM:SS.MMMMMM"
if str == base[:len(str)] {
return t, err
}
t, err = time.Parse(timeFormat[:len(str)], str)
default:
err = fmt.Errorf("invalid time string: %s", str)
return t, err
}
// Adjust location
if err == nil && loc != time.UTC {
y, mo, d := t.Date()
h, mi, s := t.Clock()
t, err = time.Date(y, mo, d, h, mi, s, t.Nanosecond(), loc), nil
}
return t, err
}