ruby-mysql 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f95fb29b93c207b23bbc1378ce78b10ab297269f0cf24409116a69502cdf9ae8
4
- data.tar.gz: 7979ccfd21194e81a4c98f90920b7dc3cdb1165201bdf7bc0d640d16fbe8ebea
3
+ metadata.gz: 37cc4956fc000b612b24fe104acf96abf27e0a7016cbd05c2c5e7b4ae5e0bade
4
+ data.tar.gz: b2c4ded73325a5c4aadce1d81af507e2a7d4144764150fde183f0e541e25e8b8
5
5
  SHA512:
6
- metadata.gz: '068b6f6008f4b77dc6d34b660c8f06b73db2c06e63fc98d69d5455ceb6ab61c3924d158de4398d6b897cc2fa44d460a879b60355dbb16ac90f0af666f750467d'
7
- data.tar.gz: 769105fbd5f16a4b8ab9c55c4a1243c962db3a238f05baa16d970cb2cbaadba0f0487c2daf194b53ce0bfa48639aac37cb79527da02518607a4a0a861cdd6caf
6
+ metadata.gz: c81163849e312cb8cb861a1c5add93fba0973d1fbf01b9296513914931134230dbf7d2d6437e72097c8426d24daab316c2756621d3302d5ee91efb72ab951cc3
7
+ data.tar.gz: c4e13cea550e4659db986772663b04364c8c18f51abc9442516058cbe5ebc420dd19a95e324e149ae0966edefa1259fff9274677295849834029f827667547c2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [3.0.1] - 2022-06-18
2
+
3
+ - LICENSE: correct author
4
+ - FIX: correct LOAD DATA LOCAL INFILE result information.
5
+ - FIX: reset SERVER_MORE_RESULTS_EXISTS when error packet is received.
6
+ - FIX: close the socket when the connection is disconnected.
7
+ - FIX: allow multiple results by default.
8
+
1
9
  ## [3.0.0] - 2021-11-16
2
10
 
3
11
  - `Mysql.new` no longer connect. use `Mysql.connect` or `Mysql#connect`.
@@ -175,7 +175,7 @@ class Mysql
175
175
  @server_version = init_packet.server_version.split(/\D/)[0,3].inject{|a,b|a.to_i*100+b.to_i}
176
176
  @server_capabilities = init_packet.server_capabilities
177
177
  @thread_id = init_packet.thread_id
178
- @client_flags = CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_TRANSACTIONS | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION | CLIENT_PLUGIN_AUTH
178
+ @client_flags = CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_TRANSACTIONS | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION | CLIENT_MULTI_RESULTS | CLIENT_PS_MULTI_RESULTS | CLIENT_PLUGIN_AUTH
179
179
  @client_flags |= CLIENT_LOCAL_FILES if @opts[:local_infile] || @opts[:load_data_local_dir]
180
180
  @client_flags |= CLIENT_CONNECT_WITH_DB if @opts[:database]
181
181
  @client_flags |= @opts[:flags]
@@ -252,6 +252,7 @@ class Mysql
252
252
  end
253
253
  if res_packet.field_count.nil? # LOAD DATA LOCAL INFILE
254
254
  send_local_file(res_packet.message)
255
+ res_packet = ResultPacket.parse read
255
256
  end
256
257
  @affected_rows, @insert_id, @server_status, @warning_count, @message =
257
258
  res_packet.affected_rows, res_packet.insert_id, res_packet.server_status, res_packet.warning_count, res_packet.message
@@ -273,7 +274,6 @@ class Mysql
273
274
  end
274
275
  ensure
275
276
  write nil # EOF mark
276
- read
277
277
  end
278
278
 
279
279
  # Retrieve n fields
@@ -460,6 +460,7 @@ class Mysql
460
460
  raise EOFError unless ret && ret.length == len
461
461
  data.concat ret
462
462
  rescue EOFError
463
+ @socket.close rescue nil
463
464
  raise ClientError::ServerGoneError, 'MySQL server has gone away'
464
465
  rescue Errno::ETIMEDOUT
465
466
  raise ClientError, "read timeout"
@@ -474,6 +475,7 @@ class Mysql
474
475
  _, errno, message = data.unpack("Cva*") # Version 4.0 Error
475
476
  @sqlstate = ""
476
477
  end
478
+ @server_status &= ~SERVER_MORE_RESULTS_EXISTS
477
479
  message.force_encoding(@charset.encoding)
478
480
  if Mysql::ServerError::ERROR_MAP.key? errno
479
481
  raise Mysql::ServerError::ERROR_MAP[errno].new(message, @sqlstate)
@@ -523,6 +525,7 @@ class Mysql
523
525
  @socket.sync = true
524
526
  @socket.flush
525
527
  rescue Errno::EPIPE
528
+ @socket.close rescue nil
526
529
  raise ClientError::ServerGoneError, 'MySQL server has gone away'
527
530
  rescue Errno::ETIMEDOUT
528
531
  raise ClientError, "write timeout"
data/lib/mysql.rb CHANGED
@@ -19,7 +19,7 @@ class Mysql
19
19
  require_relative "mysql/protocol"
20
20
  require_relative "mysql/packet.rb"
21
21
 
22
- VERSION = '3.0.0' # Version number of this library
22
+ VERSION = '3.0.1' # Version number of this library
23
23
  MYSQL_UNIX_PORT = "/tmp/mysql.sock" # UNIX domain socket filename
24
24
  MYSQL_TCP_PORT = 3306 # TCP socket port number
25
25
 
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 == '3.0.0' }
23
+ assert{ Mysql::VERSION == '3.0.1' }
24
24
  end
25
25
  end
26
26
 
@@ -174,8 +174,12 @@ class TestMysql < Test::Unit::TestCase
174
174
  tmpf.close
175
175
  @m.local_infile = true
176
176
  @m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
177
+ if @m.query('select @@local_infile').fetch[0] == '0'
178
+ omit 'skip because local_infile variable is false'
179
+ end
177
180
  @m.query('create temporary table t (i int, c char(10))')
178
181
  @m.query("load data local infile '#{tmpf.path}' into table t")
182
+ assert{ @m.info == 'Records: 1 Deleted: 0 Skipped: 0 Warnings: 0' }
179
183
  assert{ @m.query('select * from t').fetch_row == ['123','abc'] }
180
184
  end
181
185
  test 'load_data_local_dir: client can execute LOAD DATA LOCAL INFILE query with specified directory' do
@@ -185,6 +189,9 @@ class TestMysql < Test::Unit::TestCase
185
189
  tmpf.close
186
190
  @m.load_data_local_dir = File.dirname(tmpf.path)
187
191
  @m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
192
+ if @m.query('select @@local_infile').fetch[0] == '0'
193
+ omit 'skip because local_infile variable is false'
194
+ end
188
195
  @m.query('create temporary table t (i int, c char(10))')
189
196
  @m.query("load data local infile '#{tmpf.path}' into table t")
190
197
  assert{ @m.query('select * from t').fetch_row == ['123','abc'] }
@@ -196,6 +203,9 @@ class TestMysql < Test::Unit::TestCase
196
203
  tmpf.close
197
204
  @m.load_data_local_dir = '/hoge'
198
205
  @m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
206
+ if @m.query('select @@local_infile').fetch[0] == '0'
207
+ omit 'skip because local_infile variable is false'
208
+ end
199
209
  @m.query('create temporary table t (i int, c char(10))')
200
210
  assert_raise Mysql::ClientError::LoadDataLocalInfileRejected, 'LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.' do
201
211
  @m.query("load data local infile '#{tmpf.path}' into table t")
@@ -207,6 +217,9 @@ class TestMysql < Test::Unit::TestCase
207
217
  tmpf.puts "123\tabc\n"
208
218
  tmpf.close
209
219
  @m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
220
+ if @m.query('select @@local_infile').fetch[0] == '0'
221
+ omit 'skip because local_infile variable is false'
222
+ end
210
223
  @m.query('create temporary table t (i int, c char(10))')
211
224
  if @m.server_version >= 80000
212
225
  assert_raise Mysql::ServerError, 'Loading local data is disabled; this must be enabled on both the client and server sides' do
@@ -550,6 +563,30 @@ class TestMysql < Test::Unit::TestCase
550
563
  end
551
564
  end
552
565
 
566
+ test 'multiple statement error' do
567
+ m = Mysql.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
568
+ m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON)
569
+ res = m.query 'select 1; select hoge; select 2'
570
+ assert{ res.entries == [['1']] }
571
+ assert{ m.more_results? == true }
572
+ assert_raise(Mysql::ServerError::BadFieldError){ m.next_result }
573
+ assert{ m.more_results? == false }
574
+ end
575
+
576
+ test 'procedure returns multiple results' do
577
+ m = Mysql.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
578
+ m.query 'drop procedure if exists test_proc'
579
+ m.query 'create procedure test_proc() begin select 1 as a; select 2 as b; end'
580
+ res = m.query 'call test_proc()'
581
+ assert{ res.entries == [['1']] }
582
+ assert{ m.more_results? == true }
583
+ assert{ m.next_result == true }
584
+ assert{ m.store_result.entries == [['2']] }
585
+ assert{ m.more_results? == true }
586
+ assert{ m.next_result == true }
587
+ assert{ m.more_results? == false }
588
+ end
589
+
553
590
  sub_test_case 'Mysql::Result' do
554
591
  setup do
555
592
  @m = Mysql.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
@@ -828,7 +865,7 @@ class TestMysql < Test::Unit::TestCase
828
865
 
829
866
  teardown do
830
867
  @s.close if @s rescue nil
831
- @m.close if @m
868
+ @m.close if @m rescue nil
832
869
  end
833
870
 
834
871
  test '#affected_rows returns number of affected records' do
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: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomita Masahiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2022-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is MySQL connector. pure Ruby version
14
14
  email: tommy@tmtm.org
@@ -35,7 +35,7 @@ licenses:
35
35
  - Ruby
36
36
  metadata:
37
37
  homepage_uri: http://github.com/tmtm/ruby-mysql
38
- documentation_uri: https://www.rubydoc.info/github/tmtm/ruby-mysql/
38
+ documentation_uri: https://www.rubydoc.info/gems/ruby-mysql
39
39
  source_code_uri: http://github.com/tmtm/ruby-mysql
40
40
  post_install_message:
41
41
  rdoc_options: []
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.3.0.dev
55
+ rubygems_version: 3.3.7
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: MySQL connector