Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
mysql/fields.go at master · go-sql-driver/mysql · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
go-sql-driver
mysql
Repository navigation
Code
Issues
40
(40)
Pull requests
19
(19)
Discussions
Actions
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
mysql
/
fields.go
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
228 lines (214 loc) · 5.35 KB
master
Breadcrumbs
mysql
/
fields.go
Copy path
Top
File metadata and controls
Code
Blame
228 lines (214 loc) · 5.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// 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
(
"database/sql"
"reflect"
)
func
(
mf
*
mysqlField
)
typeDatabaseName
()
string
{
switch
mf
.
fieldType
{
case
fieldTypeBit
:
return
"BIT"
case
fieldTypeBLOB
:
if
mf
.
charSet
!=
binaryCollationID
{
return
"TEXT"
}
return
"BLOB"
case
fieldTypeDate
:
return
"DATE"
case
fieldTypeDateTime
:
return
"DATETIME"
case
fieldTypeDecimal
:
return
"DECIMAL"
case
fieldTypeDouble
:
return
"DOUBLE"
case
fieldTypeEnum
:
return
"ENUM"
case
fieldTypeFloat
:
return
"FLOAT"
case
fieldTypeGeometry
:
return
"GEOMETRY"
case
fieldTypeInt24
:
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
"UNSIGNED MEDIUMINT"
}
return
"MEDIUMINT"
case
fieldTypeJSON
:
return
"JSON"
case
fieldTypeLong
:
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
"UNSIGNED INT"
}
return
"INT"
case
fieldTypeLongBLOB
:
if
mf
.
charSet
!=
binaryCollationID
{
return
"LONGTEXT"
}
return
"LONGBLOB"
case
fieldTypeLongLong
:
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
"UNSIGNED BIGINT"
}
return
"BIGINT"
case
fieldTypeMediumBLOB
:
if
mf
.
charSet
!=
binaryCollationID
{
return
"MEDIUMTEXT"
}
return
"MEDIUMBLOB"
case
fieldTypeNewDate
:
return
"DATE"
case
fieldTypeNewDecimal
:
return
"DECIMAL"
case
fieldTypeNULL
:
return
"NULL"
case
fieldTypeSet
:
return
"SET"
case
fieldTypeShort
:
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
"UNSIGNED SMALLINT"
}
return
"SMALLINT"
case
fieldTypeString
:
if
mf
.
flags
&
flagEnum
!=
0
{
return
"ENUM"
}
else
if
mf
.
flags
&
flagSet
!=
0
{
return
"SET"
}
if
mf
.
charSet
==
binaryCollationID
{
return
"BINARY"
}
return
"CHAR"
case
fieldTypeTime
:
return
"TIME"
case
fieldTypeTimestamp
:
return
"TIMESTAMP"
case
fieldTypeTiny
:
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
"UNSIGNED TINYINT"
}
return
"TINYINT"
case
fieldTypeTinyBLOB
:
if
mf
.
charSet
!=
binaryCollationID
{
return
"TINYTEXT"
}
return
"TINYBLOB"
case
fieldTypeVarChar
:
if
mf
.
charSet
==
binaryCollationID
{
return
"VARBINARY"
}
return
"VARCHAR"
case
fieldTypeVarString
:
if
mf
.
charSet
==
binaryCollationID
{
return
"VARBINARY"
}
return
"VARCHAR"
case
fieldTypeYear
:
return
"YEAR"
case
fieldTypeVector
:
return
"VECTOR"
default
:
return
""
}
}
var
(
scanTypeFloat32
=
reflect
.
TypeFor
[
float32
]()
scanTypeFloat64
=
reflect
.
TypeFor
[
float64
]()
scanTypeInt8
=
reflect
.
TypeFor
[
int8
]()
scanTypeInt16
=
reflect
.
TypeFor
[
int16
]()
scanTypeInt32
=
reflect
.
TypeFor
[
int32
]()
scanTypeInt64
=
reflect
.
TypeFor
[
int64
]()
scanTypeNullFloat
=
reflect
.
TypeFor
[sql.
NullFloat64
]()
scanTypeNullInt
=
reflect
.
TypeFor
[sql.
NullInt64
]()
scanTypeNullUint
=
reflect
.
TypeFor
[sql.
Null
[
uint64
]]()
scanTypeNullTime
=
reflect
.
TypeFor
[sql.
NullTime
]()
scanTypeUint8
=
reflect
.
TypeFor
[
uint8
]()
scanTypeUint16
=
reflect
.
TypeFor
[
uint16
]()
scanTypeUint32
=
reflect
.
TypeFor
[
uint32
]()
scanTypeUint64
=
reflect
.
TypeFor
[
uint64
]()
scanTypeString
=
reflect
.
TypeFor
[
string
]()
scanTypeNullString
=
reflect
.
TypeFor
[sql.
NullString
]()
scanTypeBytes
=
reflect
.
TypeFor
[[]
byte
]()
scanTypeUnknown
=
reflect
.
TypeFor
[
*
any
]()
)
type
mysqlField
struct
{
tableName
string
name
string
length
uint32
flags
fieldFlag
fieldType
fieldType
decimals
byte
charSet
uint16
}
func
(
mf
*
mysqlField
)
scanType
() reflect.
Type
{
switch
mf
.
fieldType
{
case
fieldTypeTiny
:
if
mf
.
flags
&
flagNotNULL
!=
0
{
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
scanTypeUint8
}
return
scanTypeInt8
}
return
scanTypeNullInt
case
fieldTypeShort
,
fieldTypeYear
:
if
mf
.
flags
&
flagNotNULL
!=
0
{
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
scanTypeUint16
}
return
scanTypeInt16
}
return
scanTypeNullInt
case
fieldTypeInt24
,
fieldTypeLong
:
if
mf
.
flags
&
flagNotNULL
!=
0
{
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
scanTypeUint32
}
return
scanTypeInt32
}
return
scanTypeNullInt
case
fieldTypeLongLong
:
if
mf
.
flags
&
flagNotNULL
!=
0
{
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
scanTypeUint64
}
return
scanTypeInt64
}
if
mf
.
flags
&
flagUnsigned
!=
0
{
return
scanTypeNullUint
}
return
scanTypeNullInt
case
fieldTypeFloat
:
if
mf
.
flags
&
flagNotNULL
!=
0
{
return
scanTypeFloat32
}
return
scanTypeNullFloat
case
fieldTypeDouble
:
if
mf
.
flags
&
flagNotNULL
!=
0
{
return
scanTypeFloat64
}
return
scanTypeNullFloat
case
fieldTypeBit
,
fieldTypeTinyBLOB
,
fieldTypeMediumBLOB
,
fieldTypeLongBLOB
,
fieldTypeBLOB
,
fieldTypeVarString
,
fieldTypeString
,
fieldTypeGeometry
,
fieldTypeVector
:
if
mf
.
charSet
==
binaryCollationID
{
return
scanTypeBytes
}
fallthrough
case
fieldTypeDecimal
,
fieldTypeNewDecimal
,
fieldTypeVarChar
,
fieldTypeEnum
,
fieldTypeSet
,
fieldTypeJSON
,
fieldTypeTime
:
if
mf
.
flags
&
flagNotNULL
!=
0
{
return
scanTypeString
}
return
scanTypeNullString
case
fieldTypeDate
,
fieldTypeNewDate
,
fieldTypeTimestamp
,
fieldTypeDateTime
:
// NullTime is always returned for more consistent behavior as it can
// handle both cases of parseTime regardless if the field is nullable.
return
scanTypeNullTime
default
:
return
scanTypeUnknown
}
}
You can’t perform that action at this time.