/
consts.go
200 lines (187 loc) · 6.56 KB
/
consts.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
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
package mymy
import "strconv"
// Client caps - borrowed from GoMySQL
const (
_CLIENT_LONG_PASSWORD = 1 << iota
_CLIENT_FOUND_ROWS
_CLIENT_LONG_FLAG
_CLIENT_CONNECT_WITH_DB
_CLIENT_NO_SCHEMA
_CLIENT_COMPRESS
_CLIENT_ODBC
_CLIENT_LOCAL_FILES
_CLIENT_IGNORE_SPACE
_CLIENT_PROTOCOL_41
_CLIENT_INTERACTIVE
_CLIENT_SSL
_CLIENT_IGNORE_SIGPIPE
_CLIENT_TRANSACTIONS
_CLIENT_RESERVED
_CLIENT_SECURE_CONN
_CLIENT_MULTI_STATEMENTS
_CLIENT_MULTI_RESULTS
)
// Commands - borrowed from GoMySQL
const (
_COM_QUIT = 0x01
_COM_INIT_DB = 0x02
_COM_QUERY = 0x03
_COM_FIELD_LIST = 0x04
_COM_CREATE_DB = 0x05
_COM_DROP_DB = 0x06
_COM_REFRESH = 0x07
_COM_SHUTDOWN = 0x08
_COM_STATISTICS = 0x09
_COM_PROCESS_INFO = 0x0a
_COM_CONNECT = 0x0b
_COM_PROCESS_KILL = 0x0c
_COM_DEBUG = 0x0d
_COM_PING = 0x0e
_COM_TIME = 0x0f
_COM_DELAYED_INSERT = 0x10
_COM_CHANGE_USER = 0x11
_COM_BINLOG_DUMP = 0x12
_COM_TABLE_DUMP = 0x13
_COM_CONNECT_OUT = 0x14
_COM_REGISTER_SLAVE = 0x15
_COM_STMT_PREPARE = 0x16
_COM_STMT_EXECUTE = 0x17
_COM_STMT_SEND_LONG_DATA = 0x18
_COM_STMT_CLOSE = 0x19
_COM_STMT_RESET = 0x1a
_COM_SET_OPTION = 0x1b
_COM_STMT_FETCH = 0x1c
)
// Server status
const (
_SERVER_STATUS_IN_TRANS = 0x01 // Transaction has started
_SERVER_STATUS_AUTOCOMMIT = 0x02 // Server in auto_commit mode
_SERVER_MORE_RESULTS_EXISTS = 0x08 // Multi query - next query exists
_SERVER_QUERY_NO_GOOD_INDEX_USED = 0x10 //
_SERVER_QUERY_NO_INDEX_USED = 0x20
// Server opened a read-only non-scrollable cursor for a query
_SERVER_STATUS_CURSOR_EXISTS = 0x40
_SERVER_STATUS_LAST_ROW_SENT = 0x80
)
// MySQL protocol types.
//
// mymysql uses only some of them for send data to the MySQL server. Used
// MySQL types are marked with a comment contains mymysql type that uses it.
const (
MYSQL_TYPE_DECIMAL = 0x00
MYSQL_TYPE_TINY = 0x01 // int8, uint8
MYSQL_TYPE_SHORT = 0x02 // int16, uint16
MYSQL_TYPE_LONG = 0x03 // int32, uint32
MYSQL_TYPE_FLOAT = 0x04 // float32
MYSQL_TYPE_DOUBLE = 0x05 // float64
MYSQL_TYPE_NULL = 0x06 // nil
MYSQL_TYPE_TIMESTAMP = 0x07 // *Timestamp
MYSQL_TYPE_LONGLONG = 0x08 // int64, uint64
MYSQL_TYPE_INT24 = 0x09
MYSQL_TYPE_DATE = 0x0a
MYSQL_TYPE_TIME = 0x0b
MYSQL_TYPE_DATETIME = 0x0c // *Datetime
MYSQL_TYPE_YEAR = 0x0d
MYSQL_TYPE_NEWDATE = 0x0e
MYSQL_TYPE_VARCHAR = 0x0f
MYSQL_TYPE_BIT = 0x10
MYSQL_TYPE_NEWDECIMAL = 0xf6
MYSQL_TYPE_ENUM = 0xf7
MYSQL_TYPE_SET = 0xf8
MYSQL_TYPE_TINY_BLOB = 0xf9
MYSQL_TYPE_MEDIUM_BLOB = 0xfa
MYSQL_TYPE_LONG_BLOB = 0xfb
MYSQL_TYPE_BLOB = 0xfc // Blob
MYSQL_TYPE_VAR_STRING = 0xfd // []byte
MYSQL_TYPE_STRING = 0xfe // string
MYSQL_TYPE_GEOMETRY = 0xff
MYSQL_UNSIGNED_MASK = uint16(1 << 15)
)
// Mapping of MySQL types to (prefered) protocol types. Use it if you create
// your own Raw value.
//
// Comments contains corresponding types used by mymysql. string type may be
// replaced by []byte type and vice versa. []byte type is native for sending
// on a network, so any string is converted to it before sending. Than for
// better preformance use []byte.
const (
// Client send and receive, mymysql representation for send / receive
TINYINT = MYSQL_TYPE_TINY // int8 / int8
SMALLINT = MYSQL_TYPE_SHORT // int16 / int16
INT = MYSQL_TYPE_LONG // int32 / int32
BIGINT = MYSQL_TYPE_LONGLONG // int64 / int64
FLOAT = MYSQL_TYPE_FLOAT // float32 / float32
DOUBLE = MYSQL_TYPE_DOUBLE // float64 / float32
TIME = MYSQL_TYPE_TIME // *Datetime / *Datetime
DATE = MYSQL_TYPE_DATE // *Datetime / *Datetime
DATETIME = MYSQL_TYPE_DATETIME // *Datetime / *Datetime
TIMESTAMP = MYSQL_TYPE_TIMESTAMP // *Timestamp / *Datetime
CHAR = MYSQL_TYPE_STRING // string / []byte
BLOB = MYSQL_TYPE_BLOB // Blob / []byte
NULL = MYSQL_TYPE_NULL // nil
// Client send only, mymysql representation for send
OUT_TEXT = MYSQL_TYPE_STRING // string
OUT_VARCHAR = MYSQL_TYPE_STRING // string
OUT_BINARY = MYSQL_TYPE_BLOB // Blob
OUT_VARBINARY = MYSQL_TYPE_BLOB // Blob
// Client receive only, mymysql representation for receive
IN_MEDIUMINT = MYSQL_TYPE_INT24 // int32
IN_YEAR = MYSQL_TYPE_SHORT // int16
IN_BINARY = MYSQL_TYPE_STRING // []byte
IN_VARCHAR = MYSQL_TYPE_VAR_STRING // []byte
IN_VARBINARY = MYSQL_TYPE_VAR_STRING // []byte
IN_TINYBLOB = MYSQL_TYPE_TINY_BLOB // []byte
IN_TINYTEXT = MYSQL_TYPE_TINY_BLOB // []byte
IN_TEXT = MYSQL_TYPE_BLOB // []byte
IN_MEDIUMBLOB = MYSQL_TYPE_MEDIUM_BLOB // []byte
IN_MEDIUMTEXT = MYSQL_TYPE_MEDIUM_BLOB // []byte
IN_LONGBLOB = MYSQL_TYPE_LONG_BLOB // []byte
IN_LONGTEXT = MYSQL_TYPE_LONG_BLOB // []byte
// MySQL 5.x specific
IN_DECIMAL = MYSQL_TYPE_NEWDECIMAL // TODO
IN_BIT = MYSQL_TYPE_BIT // []byte
)
// Flags - borrowed from GoMySQL
const (
_FLAG_NOT_NULL = 1 << iota
_FLAG_PRI_KEY
_FLAG_UNIQUE_KEY
_FLAG_MULTIPLE_KEY
_FLAG_BLOB
_FLAG_UNSIGNED
_FLAG_ZEROFILL
_FLAG_BINARY
_FLAG_ENUM
_FLAG_AUTO_INCREMENT
_FLAG_TIMESTAMP
_FLAG_SET
_FLAG_NO_DEFAULT_VALUE
)
var (
_SIZE_OF_INT int
_SIZE_OF_FLOAT int
_INT_TYPE uint16
_FLOAT_TYPE uint16
)
func init() {
switch strconv.IntSize {
case 32:
_INT_TYPE = MYSQL_TYPE_LONG
_SIZE_OF_INT = 4
case 64:
_INT_TYPE = MYSQL_TYPE_LONGLONG
_SIZE_OF_INT = 8
default:
panic("bad int size")
}
switch strconv.FloatSize {
case 32:
_FLOAT_TYPE = MYSQL_TYPE_FLOAT
_SIZE_OF_FLOAT = 4
case 64:
_FLOAT_TYPE = MYSQL_TYPE_DOUBLE
_SIZE_OF_FLOAT = 8
default:
panic("bad float size")
}
}