ruby-mysql 4.1.0 → 4.2.0

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: fd37c2f40ef7277952c0be41848abc338e29d3a4e9da3f3eed1d1d8f61407c76
4
- data.tar.gz: 754994f1cb1f5e4cb007d5f1a3d81238e626ce8d224aef23c58c8af3d5fd351f
3
+ metadata.gz: b0fae682668684b92f92ebf353cc0bcfaaeffc5afc922a82f6203fce60fc21ce
4
+ data.tar.gz: d289a2371c8cf2e60188ee6c0364640297116629c15a825b24048914b7470bc4
5
5
  SHA512:
6
- metadata.gz: c31c8170682621713905f820a2816377a045b3ba489adc39d3575543483475411bdd7ecead30f806494533dd91819e8e53dad1bd3c090164b80d7600666ea1a4
7
- data.tar.gz: 6f59d7638d0f09bd3c21cd34e32cae9e995f26219efc5594b3982b94562a0c3726a1258ebfff5e3b0afbe53764135d96eff0250d57d6d75289f65e3b9957e720
6
+ metadata.gz: 6581d6cc73e910bbce33bb6024eda12971a0757a8d53ffa79b7c2fee983c19007821250af2a717217f6213b0a8a7b34285731988fba77f67b66496a03342e035
7
+ data.tar.gz: 8be3f83e953ea70aa80da335f8f2b4dbb7bd23bdb463b1abf3d6625e16f73558ff485112a958ffa737c10febb115c7de7538c8994b420fdd56525052e22c440b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [4.2.0] - 2024-12-23
2
+
3
+ - Skip storing records if auto_store_result is false <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/6>
4
+ - Ruby 3.3 & MySQL 8.4 <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/7>
5
+ - COM_KILL and COM_REFRESH are not supported by MySQL 8.4 <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/8>
6
+ - add Mysql#use_result and fix Mysql::Result#size <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/9>
7
+ - avoid warning for Ruby 3.4 <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/10>
8
+ - bundle update and rubocop <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/11>
9
+
1
10
  ## [4.1.0] - 2023-10-08
2
11
 
3
12
  - Support geometry column <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/1>
data/lib/mysql/error.rb CHANGED
@@ -14,7 +14,7 @@ class Mysql
14
14
  errname = errname.to_s
15
15
  next unless errname =~ prefix_re
16
16
  errno = self.const_get errname
17
- excname = errname.sub(prefix_re, '').gsub(/(\A.|_.)([A-Z]+)/){$1+$2.downcase}.gsub(/_/, '')
17
+ excname = errname.sub(prefix_re, '').gsub(/(\A.|_.)([A-Z]+)/){$1+$2.downcase}.gsub('_', '')
18
18
  klass = Class.new self
19
19
  klass.const_set 'ERRNO', errno
20
20
  self.const_set excname, klass
@@ -908,7 +908,7 @@ class Mysql
908
908
  end
909
909
 
910
910
  ServerError.define_error_class(/\AER_/)
911
- ServerError::ERROR_MAP.each_value{|v| Mysql.const_set v.name.split(/::/).last, v} # for compatibility
911
+ ServerError::ERROR_MAP.each_value{|v| Mysql.const_set v.name.split('::').last, v} # for compatibility
912
912
 
913
913
  # client side error
914
914
  class ClientError < Error
@@ -513,7 +513,7 @@ class Mysql
513
513
  # @return [Packet] packet data
514
514
  # @rails [ProtocolError] invalid packet sequence number
515
515
  def read
516
- data = ''
516
+ data = +''
517
517
  len = nil
518
518
  begin
519
519
  timeout = @state == :INIT ? @opts[:connect_timeout] : @opts[:read_timeout]
@@ -554,7 +554,7 @@ class Mysql
554
554
 
555
555
  def read_timeout(len, timeout)
556
556
  return @socket.read(len) if timeout.nil? || timeout == 0
557
- result = ''
557
+ result = +''
558
558
  e = Time.now + timeout
559
559
  while result.size < len
560
560
  now = Time.now
@@ -789,7 +789,7 @@ class Mysql
789
789
  username,
790
790
  Packet.lcs(scrambled_password),
791
791
  ]
792
- pack = "VVCa23Z*A*"
792
+ pack = +"VVCa23Z*A*"
793
793
  if databasename
794
794
  data.push databasename
795
795
  pack.concat "Z*"
@@ -817,7 +817,7 @@ class Mysql
817
817
  class ExecutePacket
818
818
  def self.serialize(statement_id, cursor_type, values)
819
819
  nbm = null_bitmap values
820
- netvalues = ""
820
+ netvalues = +""
821
821
  types = values.map do |v|
822
822
  t, n = Protocol.value2net v
823
823
  netvalues.concat n unless v.nil?
data/lib/mysql/result.rb CHANGED
@@ -15,8 +15,9 @@ class Mysql
15
15
  def initialize(fields, protocol, record_class, **opts)
16
16
  @fields = fields
17
17
  @field_index = 0 # index of field
18
- @records = [] # all records
18
+ @records = nil # all records
19
19
  @index = 0 # index of record
20
+ @size = 0 # retrieved record count
20
21
  @fieldname_with_table = nil
21
22
  @protocol = protocol
22
23
  @record_class = record_class
@@ -25,6 +26,7 @@ class Mysql
25
26
 
26
27
  def retrieve
27
28
  @records = @protocol.retr_all_records(@record_class)
29
+ @size = @records.size
28
30
  end
29
31
 
30
32
  # ignore
@@ -34,22 +36,22 @@ class Mysql
34
36
  end
35
37
 
36
38
  # @return [Integer] number of record
37
- def size
38
- @records.size
39
- end
39
+ attr_reader :size
40
40
  alias num_rows size
41
+ alias count size
41
42
 
42
43
  # @return [Array] current record data
43
44
  def fetch(**)
44
- if @index < @records.size
45
+ if @records && @index < @records.size
45
46
  @records[@index] = @records[@index].to_a unless @records[@index].is_a? Array
46
47
  @index += 1
47
48
  return @records[@index-1]
48
49
  end
49
50
  rec = @protocol.retr_record(@record_class)&.to_a
50
51
  return nil unless rec
51
- @records[@index] = rec
52
+ @records[@index] = rec if @records
52
53
  @index += 1
54
+ @size += 1
53
55
  return rec
54
56
  end
55
57
  alias fetch_row fetch
@@ -133,7 +135,6 @@ class Mysql
133
135
  # @private
134
136
  # @param [Array<Mysql::Field>] fields
135
137
  # @param [Mysql::Protocol] protocol
136
- # @param [Boolean] auto_store_result
137
138
  def initialize(fields, protocol=nil, **opts)
138
139
  super fields, protocol, RawRecord, **opts
139
140
  return unless protocol
@@ -182,7 +183,7 @@ class Mysql
182
183
  when Field::TYPE_DATETIME, Field::TYPE_TIMESTAMP
183
184
  Time.parse(s) rescue nil
184
185
  when Field::TYPE_TIME
185
- h, m, sec = s.split(/:/)
186
+ h, m, sec = s.split(':')
186
187
  if s =~ /\A-/
187
188
  h.to_i*3600 - m.to_i*60 - sec.to_f
188
189
  else
data/lib/mysql.rb CHANGED
@@ -22,7 +22,7 @@ class Mysql
22
22
  require_relative "mysql/protocol"
23
23
  require_relative "mysql/packet"
24
24
 
25
- VERSION = -'4.1.0' # Version number of this library
25
+ VERSION = -'4.2.0' # Version number of this library
26
26
  MYSQL_UNIX_PORT = -"/tmp/mysql.sock" # UNIX domain socket filename
27
27
  MYSQL_TCP_PORT = 3306 # TCP socket port number
28
28
 
@@ -105,9 +105,6 @@ class Mysql
105
105
  # @return [Array<Mysql::Field>] fields of result set
106
106
  attr_reader :fields
107
107
 
108
- # @return [Mysql::Result]
109
- attr_reader :result
110
-
111
108
  class << self
112
109
  # Make Mysql object and connect to mysqld.
113
110
  # parameter is same as arguments for {#initialize}.
@@ -359,8 +356,7 @@ class Mysql
359
356
  # @param [Integer] pid thread id
360
357
  # @return [Mysql] self
361
358
  def kill(pid)
362
- check_connection
363
- @protocol.kill_command pid
359
+ query "KILL #{pid}"
364
360
  self
365
361
  end
366
362
 
@@ -379,11 +375,13 @@ class Mysql
379
375
  check_connection
380
376
  @fields = nil
381
377
  begin
378
+ @result = nil
382
379
  @protocol.query_command str
383
380
  if block
384
381
  while true
382
+ @result = nil
385
383
  @protocol.get_result
386
- res = store_result(**opts)
384
+ res = result(**opts)
387
385
  block.call res if res || opts[:yield_null_result]
388
386
  break unless more_results?
389
387
  end
@@ -391,7 +389,7 @@ class Mysql
391
389
  end
392
390
  @protocol.get_result
393
391
  return self unless opts[:return_result]
394
- return store_result(**opts)
392
+ return result(**opts)
395
393
  rescue ServerError => e
396
394
  @last_error = e
397
395
  @sqlstate = e.sqlstate
@@ -399,16 +397,32 @@ class Mysql
399
397
  end
400
398
  end
401
399
 
402
- # Get all data for last query.
400
+ # return Mysql::Result for last query.
403
401
  # @return [Mysql::Result]
404
402
  # @return [nil] if no results
405
- def store_result(**opts)
403
+ def result(**opts)
406
404
  return nil if @protocol.field_count.nil? || @protocol.field_count == 0
405
+ return @result if @result
407
406
  @fields = @protocol.retr_fields
408
407
  opts = @opts.merge(opts)
409
408
  @result = Result.new(@fields, @protocol, **opts)
410
409
  end
411
410
 
411
+ # return Mysql::Result for last query with all data.
412
+ # @return [Mysql::Result]
413
+ # @return [nil] if no results
414
+ def store_result(**opts)
415
+ result(auto_store_result: true, **opts.merge)
416
+ end
417
+
418
+ # return Mysql::Result for last query without data.
419
+ # Mysql::Result#data_seek, row_tell, row_seek cannot be used.
420
+ # @return [Mysql::Result]
421
+ # @return [nil] if no results
422
+ def use_result(**opts)
423
+ result(auto_store_result: false, **opts.merge)
424
+ end
425
+
412
426
  # @return [Integer] Thread ID
413
427
  def thread_id
414
428
  check_connection
@@ -437,8 +451,8 @@ class Mysql
437
451
  return nil unless more_results?
438
452
  opts = @opts.merge(opts)
439
453
  @protocol.get_result
440
- @fields = nil
441
- return store_result(**opts) if opts[:return_result]
454
+ @result = @fields = nil
455
+ return result(**opts) if opts[:return_result]
442
456
  true
443
457
  end
444
458
 
@@ -472,8 +486,30 @@ class Mysql
472
486
  # @param [Integer] op operation. Use Mysql::REFRESH_* value.
473
487
  # @return [Mysql] self
474
488
  def refresh(op)
475
- check_connection
476
- @protocol.refresh_command op
489
+ if server_version < 80400
490
+ check_connection
491
+ @protocol.refresh_command op
492
+ else
493
+ q = case op
494
+ when REFRESH_GRANT
495
+ "FLUSH PRIVILEGES"
496
+ when REFRESH_LOG
497
+ "FLUSH LOGS"
498
+ when REFRESH_TABLES
499
+ "FLUSH TABLES"
500
+ when REFRESH_HOSTS
501
+ "TRUNCATE TABLE performance_schema.host_cache"
502
+ when REFRESH_STATUS
503
+ "FLUSH STATUS"
504
+ when REFRESH_SLAVE
505
+ "RESET REPLICA"
506
+ when REFRESH_MASTER
507
+ "RESET BINARY LOGS AND GTIDS"
508
+ else
509
+ raise "unsupported operation for #{server_version}"
510
+ end
511
+ query q
512
+ end
477
513
  self
478
514
  end
479
515
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomita Masahiro
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-10-08 00:00:00.000000000 Z
10
+ date: 2024-12-23 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: This is MySQL connector. pure Ruby version
14
13
  email: tommy@tmtm.org
@@ -39,7 +38,6 @@ metadata:
39
38
  documentation_uri: https://www.rubydoc.info/gems/ruby-mysql
40
39
  source_code_uri: http://gitlab.com/tmtms/ruby-mysql
41
40
  rubygems_mfa_required: 'true'
42
- post_install_message:
43
41
  rdoc_options: []
44
42
  require_paths:
45
43
  - lib
@@ -47,15 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
45
  requirements:
48
46
  - - ">="
49
47
  - !ruby/object:Gem::Version
50
- version: 2.6.0
48
+ version: 3.0.0
51
49
  required_rubygems_version: !ruby/object:Gem::Requirement
52
50
  requirements:
53
51
  - - ">="
54
52
  - !ruby/object:Gem::Version
55
53
  version: '0'
56
54
  requirements: []
57
- rubygems_version: 3.5.0.dev
58
- signing_key:
55
+ rubygems_version: 3.6.0.dev
59
56
  specification_version: 4
60
57
  summary: MySQL connector
61
58
  test_files: []