ruby-mysql 2.9.13 → 2.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.rdoc +4 -3
- data/lib/mysql/authenticator/caching_sha2_password.rb +62 -0
- data/lib/mysql/authenticator/mysql_native_password.rb +37 -0
- data/lib/mysql/authenticator/sha256_password.rb +40 -0
- data/lib/mysql/authenticator.rb +84 -0
- data/lib/mysql/charset.rb +379 -256
- data/lib/mysql/constants.rb +154 -70
- data/lib/mysql/error.rb +13 -7
- data/lib/mysql/protocol.rb +191 -92
- data/lib/mysql.rb +55 -33
- data/test/test_mysql.rb +78 -16
- metadata +12 -9
data/lib/mysql/constants.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: ascii-8bit
|
2
|
-
# Copyright (C) 2003
|
2
|
+
# Copyright (C) 2003 TOMITA Masahiro
|
3
3
|
# mailto:tommy@tmtm.org
|
4
4
|
|
5
5
|
class Mysql
|
@@ -33,50 +33,95 @@ class Mysql
|
|
33
33
|
COM_STMT_RESET = 26
|
34
34
|
COM_SET_OPTION = 27
|
35
35
|
COM_STMT_FETCH = 28
|
36
|
+
COM_DAEMON = 29
|
37
|
+
COM_BINLOG_DUMP_GTID = 30
|
38
|
+
COM_RESET_CONNECTION = 31
|
39
|
+
COM_CLONE = 32
|
36
40
|
|
37
41
|
# Client flag
|
38
|
-
CLIENT_LONG_PASSWORD
|
39
|
-
CLIENT_FOUND_ROWS
|
40
|
-
CLIENT_LONG_FLAG
|
41
|
-
CLIENT_CONNECT_WITH_DB
|
42
|
-
CLIENT_NO_SCHEMA
|
43
|
-
CLIENT_COMPRESS
|
44
|
-
CLIENT_ODBC
|
45
|
-
CLIENT_LOCAL_FILES
|
46
|
-
CLIENT_IGNORE_SPACE
|
47
|
-
CLIENT_PROTOCOL_41
|
48
|
-
CLIENT_INTERACTIVE
|
49
|
-
CLIENT_SSL
|
50
|
-
CLIENT_IGNORE_SIGPIPE
|
51
|
-
CLIENT_TRANSACTIONS
|
52
|
-
CLIENT_RESERVED
|
53
|
-
CLIENT_SECURE_CONNECTION
|
54
|
-
CLIENT_MULTI_STATEMENTS
|
55
|
-
CLIENT_MULTI_RESULTS
|
42
|
+
CLIENT_LONG_PASSWORD = 1 # new more secure passwords
|
43
|
+
CLIENT_FOUND_ROWS = 1 << 1 # Found instead of affected rows
|
44
|
+
CLIENT_LONG_FLAG = 1 << 2 # Get all column flags
|
45
|
+
CLIENT_CONNECT_WITH_DB = 1 << 3 # One can specify db on connect
|
46
|
+
CLIENT_NO_SCHEMA = 1 << 4 # Don't allow database.table.column
|
47
|
+
CLIENT_COMPRESS = 1 << 5 # Can use compression protocol
|
48
|
+
CLIENT_ODBC = 1 << 6 # Odbc client
|
49
|
+
CLIENT_LOCAL_FILES = 1 << 7 # Can use LOAD DATA LOCAL
|
50
|
+
CLIENT_IGNORE_SPACE = 1 << 8 # Ignore spaces before '('
|
51
|
+
CLIENT_PROTOCOL_41 = 1 << 9 # New 4.1 protocol
|
52
|
+
CLIENT_INTERACTIVE = 1 << 10 # This is an interactive client
|
53
|
+
CLIENT_SSL = 1 << 11 # Switch to SSL after handshake
|
54
|
+
CLIENT_IGNORE_SIGPIPE = 1 << 12 # IGNORE sigpipes
|
55
|
+
CLIENT_TRANSACTIONS = 1 << 13 # Client knows about transactions
|
56
|
+
CLIENT_RESERVED = 1 << 14 # Old flag for 4.1 protocol
|
57
|
+
CLIENT_SECURE_CONNECTION = 1 << 15 # New 4.1 authentication
|
58
|
+
CLIENT_MULTI_STATEMENTS = 1 << 16 # Enable/disable multi-stmt support
|
59
|
+
CLIENT_MULTI_RESULTS = 1 << 17 # Enable/disable multi-results
|
60
|
+
CLIENT_PS_MULTI_RESULTS = 1 << 18 # Multi-results in PS-protocol
|
61
|
+
CLIENT_PLUGIN_AUTH = 1 << 19 # Client supports plugin authentication
|
62
|
+
CLIENT_CONNECT_ATTRS = 1 << 20 # Client supports connection attribute
|
63
|
+
CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = 1 << 21 # Enable authentication response packet to be larger than 255 bytes.
|
64
|
+
CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = 1 << 22 # Don't close the connection for a connection with expired password.
|
65
|
+
CLIENT_SESSION_TRACK = 1 << 23 # Capable of handling server state change information. Its a hint to the server to include the state change information in Ok packet.
|
66
|
+
CLIENT_DEPRECATE_EOF = 1 << 24 # Client no longer needs EOF packet
|
67
|
+
CLIENT_OPTIONAL_RESULTSET_METADATA = 1 << 25 # The client can handle optional metadata information in the resultset.
|
68
|
+
CLIENT_ZSTD_COMPRESSION_ALGORITHM = 1 << 26 # Compression protocol extended to support zstd compression method
|
69
|
+
CLIENT_CAPABILITY_EXTENSION = 1 << 29 # This flag will be reserved to extend the 32bit capabilities structure to 64bits.
|
70
|
+
CLIENT_SSL_VERIFY_SERVER_CERT = 1 << 30 # Verify server certificate.
|
71
|
+
CLIENT_REMEMBER_OPTIONS = 1 << 31 # Don't reset the options after an unsuccessful connect
|
56
72
|
|
57
73
|
# Connection Option
|
58
|
-
OPT_CONNECT_TIMEOUT
|
59
|
-
OPT_COMPRESS
|
60
|
-
OPT_NAMED_PIPE
|
61
|
-
INIT_COMMAND
|
62
|
-
READ_DEFAULT_FILE
|
63
|
-
READ_DEFAULT_GROUP
|
64
|
-
SET_CHARSET_DIR
|
65
|
-
SET_CHARSET_NAME
|
66
|
-
OPT_LOCAL_INFILE
|
67
|
-
OPT_PROTOCOL
|
68
|
-
SHARED_MEMORY_BASE_NAME
|
69
|
-
OPT_READ_TIMEOUT
|
70
|
-
OPT_WRITE_TIMEOUT
|
71
|
-
OPT_USE_RESULT
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
OPT_CONNECT_TIMEOUT = 0
|
75
|
+
OPT_COMPRESS = 1
|
76
|
+
OPT_NAMED_PIPE = 2
|
77
|
+
INIT_COMMAND = 3
|
78
|
+
READ_DEFAULT_FILE = 4
|
79
|
+
READ_DEFAULT_GROUP = 5
|
80
|
+
SET_CHARSET_DIR = 6
|
81
|
+
SET_CHARSET_NAME = 7
|
82
|
+
OPT_LOCAL_INFILE = 8
|
83
|
+
OPT_PROTOCOL = 9
|
84
|
+
SHARED_MEMORY_BASE_NAME = 10
|
85
|
+
OPT_READ_TIMEOUT = 11
|
86
|
+
OPT_WRITE_TIMEOUT = 12
|
87
|
+
OPT_USE_RESULT = 13
|
88
|
+
REPORT_DATA_TRUNCATION = 14
|
89
|
+
OPT_RECONNECT = 15
|
90
|
+
PLUGIN_DIR = 16
|
91
|
+
DEFAULT_AUTH = 17
|
92
|
+
OPT_BIND = 18
|
93
|
+
OPT_SSL_KEY = 19
|
94
|
+
OPT_SSL_CERT = 20
|
95
|
+
OPT_SSL_CA = 21
|
96
|
+
OPT_SSL_CAPATH = 22
|
97
|
+
OPT_SSL_CIPHER = 23
|
98
|
+
OPT_SSL_CRL = 24
|
99
|
+
OPT_SSL_CRLPATH = 25
|
100
|
+
OPT_CONNECT_ATTR_RESET = 26
|
101
|
+
OPT_CONNECT_ATTR_ADD = 27
|
102
|
+
OPT_CONNECT_ATTR_DELETE = 28
|
103
|
+
SERVER_PUBLIC_KEY = 29
|
104
|
+
ENABLE_CLEARTEXT_PLUGIN = 30
|
105
|
+
OPT_CAN_HANDLE_EXPIRED_PASSWORDS = 31
|
106
|
+
OPT_MAX_ALLOWED_PACKET = 32
|
107
|
+
OPT_NET_BUFFER_LENGTH = 33
|
108
|
+
OPT_TLS_VERSION = 34
|
109
|
+
OPT_SSL_MODE = 35
|
110
|
+
OPT_GET_SERVER_PUBLIC_KEY = 36
|
111
|
+
OPT_RETRY_COUNT = 37
|
112
|
+
OPT_OPTIONAL_RESULTSET_METADATA = 38
|
113
|
+
OPT_SSL_FIPS_MODE = 39
|
114
|
+
OPT_TLS_CIPHERSUITES = 40
|
115
|
+
OPT_COMPRESSION_ALGORITHMS = 41
|
116
|
+
OPT_ZSTD_COMPRESSION_LEVEL = 42
|
117
|
+
OPT_LOAD_DATA_LOCAL_DIR = 43
|
118
|
+
|
119
|
+
# SSL Mode
|
120
|
+
SSL_MODE_DISABLED = 1
|
121
|
+
SSL_MODE_PREFERRED = 2
|
122
|
+
SSL_MODE_REQUIRED = 3
|
123
|
+
SSL_MODE_VERIFY_CA = 4
|
124
|
+
SSL_MODE_VERIFY_IDENTITY = 5
|
80
125
|
|
81
126
|
# Server Option
|
82
127
|
OPTION_MULTI_STATEMENTS_ON = 0
|
@@ -92,18 +137,36 @@ class Mysql
|
|
92
137
|
SERVER_STATUS_LAST_ROW_SENT = 1 << 7
|
93
138
|
SERVER_STATUS_DB_DROPPED = 1 << 8
|
94
139
|
SERVER_STATUS_NO_BACKSLASH_ESCAPES = 1 << 9
|
140
|
+
SERVER_STATUS_METADATA_CHANGED = 1 << 10
|
141
|
+
SERVER_QUERY_WAS_SLOW = 1 << 11
|
142
|
+
SERVER_PS_OUT_PARAMS = 1 << 12
|
143
|
+
SERVER_STATUS_IN_TRANS_READONLY = 1 << 13
|
144
|
+
SERVER_SESSION_STATE_CHANGED = 1 << 14
|
95
145
|
|
96
146
|
# Refresh parameter
|
97
|
-
REFRESH_GRANT
|
98
|
-
REFRESH_LOG
|
99
|
-
REFRESH_TABLES
|
100
|
-
REFRESH_HOSTS
|
101
|
-
REFRESH_STATUS
|
102
|
-
REFRESH_THREADS
|
103
|
-
REFRESH_SLAVE
|
104
|
-
REFRESH_MASTER
|
105
|
-
|
106
|
-
|
147
|
+
REFRESH_GRANT = 1
|
148
|
+
REFRESH_LOG = 1 << 1
|
149
|
+
REFRESH_TABLES = 1 << 2
|
150
|
+
REFRESH_HOSTS = 1 << 3
|
151
|
+
REFRESH_STATUS = 1 << 4
|
152
|
+
REFRESH_THREADS = 1 << 5
|
153
|
+
REFRESH_SLAVE = 1 << 6
|
154
|
+
REFRESH_MASTER = 1 << 7
|
155
|
+
REFRESH_ERROR_LOG = 1 << 8
|
156
|
+
REFRESH_ENGINE_LOG = 1 << 9
|
157
|
+
REFRESH_BINARY_LOG = 1 << 10
|
158
|
+
REFRESH_RELAY_LOG = 1 << 11
|
159
|
+
REFRESH_GENERAL_LOG = 1 << 12
|
160
|
+
REFRESH_SLOW_LOG = 1 << 13
|
161
|
+
REFRESH_READ_LOCK = 1 << 14
|
162
|
+
REFRESH_FAST = 1 << 15
|
163
|
+
REFRESH_QUERY_CACHE = 1 << 16
|
164
|
+
REFRESH_QUERY_CACHE_FREE = 1 << 17
|
165
|
+
REFRESH_DES_KEY_FILE = 1 << 18
|
166
|
+
REFRESH_USER_RESOURCES = 1 << 19
|
167
|
+
REFRESH_FOR_EXPORT = 1 << 20
|
168
|
+
REFRESH_OPTIMIZER_COSTS = 1 << 21
|
169
|
+
REFRESH_PERSIST = 1 << 22
|
107
170
|
|
108
171
|
class Field
|
109
172
|
# Field type
|
@@ -124,6 +187,13 @@ class Mysql
|
|
124
187
|
TYPE_NEWDATE = 14
|
125
188
|
TYPE_VARCHAR = 15
|
126
189
|
TYPE_BIT = 16
|
190
|
+
TYPE_TIMESTAMP2 = 17
|
191
|
+
TYPE_DATETIME2 = 18
|
192
|
+
TYPE_TIME2 = 19
|
193
|
+
TYPE_TYPED_ARRAY = 20
|
194
|
+
TYPE_INVALID = 243
|
195
|
+
TYPE_BOOL = 244
|
196
|
+
TYPE_JSON = 245
|
127
197
|
TYPE_NEWDECIMAL = 246
|
128
198
|
TYPE_ENUM = 247
|
129
199
|
TYPE_SET = 248
|
@@ -138,28 +208,42 @@ class Mysql
|
|
138
208
|
TYPE_INTERVAL = TYPE_ENUM
|
139
209
|
|
140
210
|
# Flag
|
141
|
-
NOT_NULL_FLAG
|
142
|
-
PRI_KEY_FLAG
|
143
|
-
UNIQUE_KEY_FLAG
|
144
|
-
MULTIPLE_KEY_FLAG
|
145
|
-
BLOB_FLAG
|
146
|
-
UNSIGNED_FLAG
|
147
|
-
ZEROFILL_FLAG
|
148
|
-
BINARY_FLAG
|
149
|
-
ENUM_FLAG
|
150
|
-
AUTO_INCREMENT_FLAG
|
151
|
-
TIMESTAMP_FLAG
|
152
|
-
SET_FLAG
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
211
|
+
NOT_NULL_FLAG = 1
|
212
|
+
PRI_KEY_FLAG = 2
|
213
|
+
UNIQUE_KEY_FLAG = 4
|
214
|
+
MULTIPLE_KEY_FLAG = 8
|
215
|
+
BLOB_FLAG = 16
|
216
|
+
UNSIGNED_FLAG = 32
|
217
|
+
ZEROFILL_FLAG = 64
|
218
|
+
BINARY_FLAG = 128
|
219
|
+
ENUM_FLAG = 256
|
220
|
+
AUTO_INCREMENT_FLAG = 512
|
221
|
+
TIMESTAMP_FLAG = 1024
|
222
|
+
SET_FLAG = 2048
|
223
|
+
NO_DEFAULT_VALUE_FLAG = 4096
|
224
|
+
ON_UPDATE_NOW_FLAG = 8192
|
225
|
+
NUM_FLAG = 32768
|
226
|
+
PART_KEY_FLAG = 16384
|
227
|
+
GROUP_FLAG = 32768
|
228
|
+
UNIQUE_FLAG = 65536
|
229
|
+
BINCMP_FLAG = 131072
|
230
|
+
GET_FIXED_FIELDS_FLAG = 1 << 18
|
231
|
+
FIELD_IN_PART_FUNC_FLAG = 1 << 19
|
232
|
+
FIELD_IN_ADD_INDEX = 1 << 20
|
233
|
+
FIELD_IS_RENAMED = 1 << 21
|
234
|
+
FIELD_FLAGS_STORAGE_MEDIA_MASK = 3 << 22
|
235
|
+
FIELD_FLAGS_COLUMN_FORMAT_MASK = 3 << 24
|
236
|
+
FIELD_IS_DROPPED = 1 << 26
|
237
|
+
EXPLICIT_NULL_FLAG = 1 << 27
|
238
|
+
FIELD_IS_MARKED = 1 << 28
|
239
|
+
NOT_SECONDARY_FLAG = 1 << 29
|
158
240
|
end
|
159
241
|
|
160
242
|
class Stmt
|
161
243
|
# Cursor type
|
162
|
-
CURSOR_TYPE_NO_CURSOR
|
163
|
-
CURSOR_TYPE_READ_ONLY
|
244
|
+
CURSOR_TYPE_NO_CURSOR = 0
|
245
|
+
CURSOR_TYPE_READ_ONLY = 1
|
246
|
+
CURSOR_TYPE_FOR_UPDATE = 2
|
247
|
+
CURSOR_TYPE_SCROLLABLE = 4
|
164
248
|
end
|
165
249
|
end
|
data/lib/mysql/error.rb
CHANGED
@@ -20,17 +20,14 @@ class Mysql
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
attr_reader :sqlstate, :error
|
23
|
+
attr_reader :sqlstate, :error, :errno
|
24
24
|
|
25
|
-
def initialize(message, sqlstate='HY000')
|
25
|
+
def initialize(message, sqlstate='HY000', errno=nil)
|
26
26
|
@sqlstate = sqlstate
|
27
27
|
@error = message
|
28
|
+
@errno = errno || self.class::ERRNO
|
28
29
|
super message
|
29
30
|
end
|
30
|
-
|
31
|
-
def errno
|
32
|
-
self.class::ERRNO
|
33
|
-
end
|
34
31
|
end
|
35
32
|
|
36
33
|
# server side error
|
@@ -977,7 +974,16 @@ class Mysql
|
|
977
974
|
CR_AUTH_PLUGIN_CANNOT_LOAD = 2059
|
978
975
|
CR_DUPLICATE_CONNECTION_ATTR = 2060
|
979
976
|
CR_AUTH_PLUGIN_ERR = 2061
|
980
|
-
|
977
|
+
CR_INSECURE_API_ERR = 2062
|
978
|
+
CR_FILE_NAME_TOO_LONG = 2063
|
979
|
+
CR_SSL_FIPS_MODE_ERR = 2064
|
980
|
+
CR_DEPRECATED_COMPRESSION_NOT_SUPPORTED = 2065
|
981
|
+
CR_COMPRESSION_WRONGLY_CONFIGURED = 2066
|
982
|
+
CR_KERBEROS_USER_NOT_FOUND = 2067
|
983
|
+
CR_LOAD_DATA_LOCAL_INFILE_REJECTED = 2068
|
984
|
+
CR_LOAD_DATA_LOCAL_INFILE_REALPATH_FAIL = 2069
|
985
|
+
CR_DNS_SRV_LOOKUP_FAILED = 2070
|
986
|
+
CR_ERROR_LAST = 2070
|
981
987
|
end
|
982
988
|
|
983
989
|
ClientError.define_error_class(/\ACR_/)
|