ruby-mysql 2.9.14 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 113de8c9b46c75bf18b833a65205517938daf47d
4
- data.tar.gz: 675d64d8cc1185e7f394c4f201aa18f427b18f11
2
+ SHA256:
3
+ metadata.gz: '03296aa0e624e599242e8efc5d3011b4337e161c3b7bf1c9cc81e98fa99f5052'
4
+ data.tar.gz: c7391d48dab125e86b97b8130556e69ceadf503e11884744b7fdf19af3b58cf1
5
5
  SHA512:
6
- metadata.gz: 47b396bc40fa36e588d01899569f8b0cca6b256bb2d290fe2ce5ab44dc66a566c2b47d67f64cb8f4d2a8a0a62c352e878da681f88b89bc0a6811b12205754214
7
- data.tar.gz: 2aa55a288ce9c5ca4f22be8b8a2c6750be23592a0e030b0077f622b43195691f81de20831a359098ce8a270050e3ffa4ab794439b039c267d803f0d23ad2330e
6
+ metadata.gz: ba1a7bad362dc1523de97aa487ee8c571649854a2bb8a9342ecd525dbda0441c9562639556dcd933f7e7c643373907144329e97c2600af30a5ae6b1cc5fb5606
7
+ data.tar.gz: bdea4b3d97980fea097d59525b327c275374d006ddb699efda0c359608d8588a8beba742f713f0b2721433ea5efbf9eac5db8d7f4e6d7ddbe9eeb050220e6a3d
data/README.rdoc CHANGED
@@ -20,6 +20,8 @@ MySQL connector for Ruby.
20
20
 
21
21
  * MySQL/Ruby 2.8.x とほぼ互換があります。
22
22
 
23
+ * MySQL 8.0 には対応していません。
24
+
23
25
  == Synopsis
24
26
 
25
27
  使用例:
@@ -42,7 +44,8 @@ MySQL connector for Ruby.
42
44
  * Mysql#options でサポートしているオプションは次のものだけです:
43
45
  Mysql::INIT_COMMAND, Mysql::OPT_CONNECT_TIMEOUT,
44
46
  Mysql::OPT_LOCAL_INFILE, Mysql::OPT_READ_TIMEOUT,
45
- Mysql::OPT_WRITE_TIMEOUT, Mysql::SET_CHARSET_NAME.
47
+ Mysql::OPT_WRITE_TIMEOUT, Mysql::SET_CHARSET_NAME,
48
+ Mysql::OPT_LOAD_DATA_LOCAL_DIR.
46
49
  これら以外を指定すると "option not implementted" という warning が標準エラー出力に出力されます。
47
50
 
48
51
  * Mysql#use_result は Mysql#store_result と同じです。つまりサーバーから一気に結果セットを読み込みます。
@@ -64,5 +67,5 @@ MySQL connector for Ruby.
64
67
  == Copyright
65
68
 
66
69
  Author :: TOMITA Masahiro <tommy@tmtm.org>
67
- Copyright :: Copyright (c) 2009-2012 TOMITA Masahiro
70
+ Copyright :: Copyright (c) 2008 TOMITA Masahiro
68
71
  License :: Ruby's
data/lib/mysql/charset.rb CHANGED
@@ -296,7 +296,7 @@ class Mysql
296
296
  if defined? Encoding
297
297
 
298
298
  # @private
299
- # MySQL Charset -> Ruby's Encodeing
299
+ # MySQL Charset -> Ruby's Encoding
300
300
  CHARSET_ENCODING = {
301
301
  "armscii8" => nil,
302
302
  "ascii" => Encoding::US_ASCII,
@@ -1,5 +1,5 @@
1
1
  # coding: ascii-8bit
2
- # Copyright (C) 2003-2008 TOMITA Masahiro
2
+ # Copyright (C) 2003 TOMITA Masahiro
3
3
  # mailto:tommy@tmtm.org
4
4
 
5
5
  class Mysql
@@ -36,6 +36,7 @@ class Mysql
36
36
  COM_DAEMON = 29
37
37
  COM_BINLOG_DUMP_GTID = 30
38
38
  COM_RESET_CONNECTION = 31
39
+ COM_CLONE = 32
39
40
 
40
41
  # Client flag
41
42
  CLIENT_LONG_PASSWORD = 1 # new more secure passwords
@@ -63,32 +64,57 @@ class Mysql
63
64
  CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = 1 << 22 # Don't close the connection for a connection with expired password.
64
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.
65
66
  CLIENT_DEPRECATE_EOF = 1 << 24 # Client no longer needs EOF packet
66
- CLIENT_SSL_VERIFY_SERVER_CERT = 1 << 30
67
- CLIENT_REMEMBER_OPTIONS = 1 << 31
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
68
72
 
69
73
  # Connection Option
70
- OPT_CONNECT_TIMEOUT = 0
71
- OPT_COMPRESS = 1
72
- OPT_NAMED_PIPE = 2
73
- INIT_COMMAND = 3
74
- READ_DEFAULT_FILE = 4
75
- READ_DEFAULT_GROUP = 5
76
- SET_CHARSET_DIR = 6
77
- SET_CHARSET_NAME = 7
78
- OPT_LOCAL_INFILE = 8
79
- OPT_PROTOCOL = 9
80
- SHARED_MEMORY_BASE_NAME = 10
81
- OPT_READ_TIMEOUT = 11
82
- OPT_WRITE_TIMEOUT = 12
83
- OPT_USE_RESULT = 13
84
- OPT_USE_REMOTE_CONNECTION = 14
85
- OPT_USE_EMBEDDED_CONNECTION = 15
86
- OPT_GUESS_CONNECTION = 16
87
- SET_CLIENT_IP = 17
88
- SECURE_AUTH = 18
89
- REPORT_DATA_TRUNCATION = 19
90
- OPT_RECONNECT = 20
91
- OPT_SSL_VERIFY_SERVER_CERT = 21
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
92
118
 
93
119
  # Server Option
94
120
  OPTION_MULTI_STATEMENTS_ON = 0
@@ -133,6 +159,7 @@ class Mysql
133
159
  REFRESH_USER_RESOURCES = 1 << 19
134
160
  REFRESH_FOR_EXPORT = 1 << 20
135
161
  REFRESH_OPTIMIZER_COSTS = 1 << 21
162
+ REFRESH_PERSIST = 1 << 22
136
163
 
137
164
  class Field
138
165
  # Field type
@@ -156,6 +183,9 @@ class Mysql
156
183
  TYPE_TIMESTAMP2 = 17
157
184
  TYPE_DATETIME2 = 18
158
185
  TYPE_TIME2 = 19
186
+ TYPE_TYPED_ARRAY = 20
187
+ TYPE_INVALID = 243
188
+ TYPE_BOOL = 244
159
189
  TYPE_JSON = 245
160
190
  TYPE_NEWDECIMAL = 246
161
191
  TYPE_ENUM = 247
@@ -171,25 +201,35 @@ class Mysql
171
201
  TYPE_INTERVAL = TYPE_ENUM
172
202
 
173
203
  # Flag
174
- NOT_NULL_FLAG = 1
175
- PRI_KEY_FLAG = 2
176
- UNIQUE_KEY_FLAG = 4
177
- MULTIPLE_KEY_FLAG = 8
178
- BLOB_FLAG = 16
179
- UNSIGNED_FLAG = 32
180
- ZEROFILL_FLAG = 64
181
- BINARY_FLAG = 128
182
- ENUM_FLAG = 256
183
- AUTO_INCREMENT_FLAG = 512
184
- TIMESTAMP_FLAG = 1024
185
- SET_FLAG = 2048
186
- NO_DEFAULT_VALUE_FLAG = 4096
187
- ON_UPDATE_NOW_FLAG = 8192
188
- NUM_FLAG = 32768
189
- PART_KEY_FLAG = 16384
190
- GROUP_FLAG = 32768
191
- UNIQUE_FLAG = 65536
192
- BINCMP_FLAG = 131072
204
+ NOT_NULL_FLAG = 1
205
+ PRI_KEY_FLAG = 2
206
+ UNIQUE_KEY_FLAG = 4
207
+ MULTIPLE_KEY_FLAG = 8
208
+ BLOB_FLAG = 16
209
+ UNSIGNED_FLAG = 32
210
+ ZEROFILL_FLAG = 64
211
+ BINARY_FLAG = 128
212
+ ENUM_FLAG = 256
213
+ AUTO_INCREMENT_FLAG = 512
214
+ TIMESTAMP_FLAG = 1024
215
+ SET_FLAG = 2048
216
+ NO_DEFAULT_VALUE_FLAG = 4096
217
+ ON_UPDATE_NOW_FLAG = 8192
218
+ NUM_FLAG = 32768
219
+ PART_KEY_FLAG = 16384
220
+ GROUP_FLAG = 32768
221
+ UNIQUE_FLAG = 65536
222
+ BINCMP_FLAG = 131072
223
+ GET_FIXED_FIELDS_FLAG = 1 << 18
224
+ FIELD_IN_PART_FUNC_FLAG = 1 << 19
225
+ FIELD_IN_ADD_INDEX = 1 << 20
226
+ FIELD_IS_RENAMED = 1 << 21
227
+ FIELD_FLAGS_STORAGE_MEDIA_MASK = 3 << 22
228
+ FIELD_FLAGS_COLUMN_FORMAT_MASK = 3 << 24
229
+ FIELD_IS_DROPPED = 1 << 26
230
+ EXPLICIT_NULL_FLAG = 1 << 27
231
+ FIELD_IS_MARKED = 1 << 28
232
+ NOT_SECONDARY_FLAG = 1 << 29
193
233
  end
194
234
 
195
235
  class Stmt
data/lib/mysql/error.rb CHANGED
@@ -977,7 +977,16 @@ class Mysql
977
977
  CR_AUTH_PLUGIN_CANNOT_LOAD = 2059
978
978
  CR_DUPLICATE_CONNECTION_ATTR = 2060
979
979
  CR_AUTH_PLUGIN_ERR = 2061
980
- CR_ERROR_LAST = 2061
980
+ CR_INSECURE_API_ERR = 2062
981
+ CR_FILE_NAME_TOO_LONG = 2063
982
+ CR_SSL_FIPS_MODE_ERR = 2064
983
+ CR_DEPRECATED_COMPRESSION_NOT_SUPPORTED = 2065
984
+ CR_COMPRESSION_WRONGLY_CONFIGURED = 2066
985
+ CR_KERBEROS_USER_NOT_FOUND = 2067
986
+ CR_LOAD_DATA_LOCAL_INFILE_REJECTED = 2068
987
+ CR_LOAD_DATA_LOCAL_INFILE_REALPATH_FAIL = 2069
988
+ CR_DNS_SRV_LOOKUP_FAILED = 2070
989
+ CR_ERROR_LAST = 2070
981
990
  end
982
991
 
983
992
  ClientError.define_error_class(/\ACR_/)
@@ -1,5 +1,5 @@
1
1
  # coding: ascii-8bit
2
- # Copyright (C) 2008-2012 TOMITA Masahiro
2
+ # Copyright (C) 2008 TOMITA Masahiro
3
3
  # mailto:tommy@tmtm.org
4
4
 
5
5
  require "socket"
@@ -134,15 +134,17 @@ class Mysql
134
134
  # conn_timeout :: [Integer] connect timeout (sec).
135
135
  # read_timeout :: [Integer] read timeout (sec).
136
136
  # write_timeout :: [Integer] write timeout (sec).
137
+ # local_infile :: [String] local infile path
137
138
  # === Exception
138
139
  # [ClientError] :: connection timeout
139
- def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout)
140
+ def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout, local_infile)
140
141
  @insert_id = 0
141
142
  @warning_count = 0
142
143
  @gc_stmt_queue = [] # stmt id list which GC destroy.
143
144
  set_state :INIT
144
145
  @read_timeout = read_timeout
145
146
  @write_timeout = write_timeout
147
+ @local_infile = local_infile
146
148
  begin
147
149
  Timeout.timeout conn_timeout do
148
150
  if host.nil? or host.empty? or host == "localhost"
@@ -180,6 +182,7 @@ class Mysql
180
182
  @server_version = init_packet.server_version.split(/\D/)[0,3].inject{|a,b|a.to_i*100+b.to_i}
181
183
  @thread_id = init_packet.thread_id
182
184
  client_flags = CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_TRANSACTIONS | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION
185
+ client_flags |= CLIENT_LOCAL_FILES if @local_infile
183
186
  client_flags |= CLIENT_CONNECT_WITH_DB if db
184
187
  client_flags |= flag
185
188
  @charset = charset
@@ -230,10 +233,7 @@ class Mysql
230
233
  return res_packet.field_count
231
234
  end
232
235
  if res_packet.field_count.nil? # LOAD DATA LOCAL INFILE
233
- filename = res_packet.message
234
- File.open(filename){|f| write f}
235
- write nil # EOF mark
236
- read
236
+ send_local_file(res_packet.message)
237
237
  end
238
238
  @affected_rows, @insert_id, @server_status, @warning_count, @message =
239
239
  res_packet.affected_rows, res_packet.insert_id, res_packet.server_status, res_packet.warning_count, res_packet.message
@@ -245,6 +245,19 @@ class Mysql
245
245
  end
246
246
  end
247
247
 
248
+ # send local file to server
249
+ def send_local_file(filename)
250
+ filename = File.absolute_path(filename)
251
+ if filename.start_with? @local_infile
252
+ File.open(filename){|f| write f}
253
+ else
254
+ raise ClientError::LoadDataLocalInfileRejected, 'LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.'
255
+ end
256
+ ensure
257
+ write nil # EOF mark
258
+ read
259
+ end
260
+
248
261
  # Retrieve n fields
249
262
  # === Argument
250
263
  # n :: [Integer] number of fields
data/lib/mysql.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: ascii-8bit
2
- # Copyright (C) 2008-2012 TOMITA Masahiro
2
+ # Copyright (C) 2008 TOMITA Masahiro
3
3
  # mailto:tommy@tmtm.org
4
4
 
5
5
  # MySQL connection class.
@@ -21,7 +21,7 @@ class Mysql
21
21
  rescue LoadError
22
22
  end
23
23
 
24
- VERSION = 20913 # Version number of this library
24
+ VERSION = 21000 # Version number of this library
25
25
  MYSQL_UNIX_PORT = "/tmp/mysql.sock" # UNIX domain socket filename
26
26
  MYSQL_TCP_PORT = 3306 # TCP socket port number
27
27
 
@@ -112,8 +112,8 @@ class Mysql
112
112
  warn 'unsupported flag: CLIENT_COMPRESS' if $VERBOSE
113
113
  flag &= ~CLIENT_COMPRESS
114
114
  end
115
- @protocol = Protocol.new host, port, socket, @connect_timeout, @read_timeout, @write_timeout
116
- @protocol.authenticate user, passwd, db, (@local_infile ? CLIENT_LOCAL_FILES : 0) | flag, @charset
115
+ @protocol = Protocol.new host, port, socket, @connect_timeout, @read_timeout, @write_timeout, @local_infile
116
+ @protocol.authenticate user, passwd, db, flag, @charset
117
117
  @charset ||= @protocol.charset
118
118
  @host_info = (host.nil? || host == "localhost") ? 'Localhost via UNIX socket' : "#{host} via TCP/IP"
119
119
  query @init_command if @init_command
@@ -158,6 +158,8 @@ class Mysql
158
158
  @connect_timeout = value
159
159
  # when Mysql::GUESS_CONNECTION
160
160
  when Mysql::OPT_LOCAL_INFILE
161
+ @local_infile = value ? '' : nil
162
+ when Mysql::OPT_LOAD_DATA_LOCAL_DIR
161
163
  @local_infile = value
162
164
  # when Mysql::OPT_NAMED_PIPE
163
165
  # when Mysql::OPT_PROTOCOL
data/test/test_mysql.rb CHANGED
@@ -20,7 +20,7 @@ MYSQL_SOCKET = ENV['MYSQL_SOCKET']
20
20
  class TestMysql < Test::Unit::TestCase
21
21
  sub_test_case 'Mysql::VERSION' do
22
22
  test 'returns client version' do
23
- assert{ Mysql::VERSION == 20913 }
23
+ assert{ Mysql::VERSION == 21000 }
24
24
  end
25
25
  end
26
26
 
@@ -160,6 +160,40 @@ class TestMysql < Test::Unit::TestCase
160
160
  @m.query("load data local infile '#{tmpf.path}' into table t")
161
161
  assert{ @m.query('select * from t').fetch_row == ['123','abc'] }
162
162
  end
163
+ test 'OPT_LOAD_DATA_LOCAL_DIR: client can execute LOAD DATA LOCAL INFILE query with specified directory' do
164
+ require 'tempfile'
165
+ tmpf = Tempfile.new 'mysql_spec'
166
+ tmpf.puts "123\tabc\n"
167
+ tmpf.close
168
+ assert{ @m.options(Mysql::OPT_LOAD_DATA_LOCAL_DIR, File.dirname(tmpf.path)) == @m }
169
+ @m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
170
+ @m.query('create temporary table t (i int, c char(10))')
171
+ @m.query("load data local infile '#{tmpf.path}' into table t")
172
+ assert{ @m.query('select * from t').fetch_row == ['123','abc'] }
173
+ end
174
+ test 'OPT_LOAD_DATA_LOCAL_DIR: client cannot execute LOAD DATA LOCAL INFILE query without specified directory' do
175
+ require 'tempfile'
176
+ tmpf = Tempfile.new 'mysql_spec'
177
+ tmpf.puts "123\tabc\n"
178
+ tmpf.close
179
+ assert{ @m.options(Mysql::OPT_LOAD_DATA_LOCAL_DIR, '/hoge') == @m }
180
+ @m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
181
+ @m.query('create temporary table t (i int, c char(10))')
182
+ assert_raise Mysql::ClientError::LoadDataLocalInfileRejected, 'LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.' do
183
+ @m.query("load data local infile '#{tmpf.path}' into table t")
184
+ end
185
+ end
186
+ test 'without OPT_LOCAL_INFILE and OPT_LOAD_DATA_LOCAL_DIR: client cannot execute LOAD DATA LOCAL INFILE query' do
187
+ require 'tempfile'
188
+ tmpf = Tempfile.new 'mysql_spec'
189
+ tmpf.puts "123\tabc\n"
190
+ tmpf.close
191
+ @m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
192
+ @m.query('create temporary table t (i int, c char(10))')
193
+ assert_raise Mysql::ServerError::NotAllowedCommand, 'The used command is not allowed with this MySQL version' do
194
+ @m.query("load data local infile '#{tmpf.path}' into table t")
195
+ end
196
+ end
163
197
  test 'OPT_READ_TIMEOUT: set timeout for reading packet' do
164
198
  assert{ @m.options(Mysql::OPT_READ_TIMEOUT, 10) == @m }
165
199
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.14
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomita Masahiro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-30 00:00:00.000000000 Z
11
+ date: 2021-10-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is MySQL connector. pure Ruby version
14
14
  email: tommy@tmtm.org
@@ -30,7 +30,7 @@ homepage: http://github.com/tmtm/ruby-mysql
30
30
  licenses:
31
31
  - Ruby
32
32
  metadata: {}
33
- post_install_message:
33
+ post_install_message:
34
34
  rdoc_options: []
35
35
  require_paths:
36
36
  - lib
@@ -45,11 +45,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
- rubyforge_project:
49
- rubygems_version: 2.5.1
50
- signing_key:
48
+ rubygems_version: 3.2.22
49
+ signing_key:
51
50
  specification_version: 4
52
51
  summary: MySQL connector
53
52
  test_files:
54
- - test/test_mysql_packet.rb
55
53
  - test/test_mysql.rb
54
+ - test/test_mysql_packet.rb