ruby-mysql 4.1.0 → 4.2.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/mysql/authenticator/caching_sha2_password.rb +1 -1
- data/lib/mysql/charset.rb +3 -3
- data/lib/mysql/error.rb +4 -4
- data/lib/mysql/protocol.rb +5 -4
- data/lib/mysql/result.rb +9 -8
- data/lib/mysql.rb +50 -14
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f6ecaf21c3afca2e777913291a4e8a15d32cbd7d08f7e3228076fe408e84bbf
|
|
4
|
+
data.tar.gz: dc74d88932d6671d5928677c32fe71837c7c638cbbed3fc6bc7e7330b71dcc23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86170456f509197452cbb1a4d9b8d9767d8403c02f6128769428bbce76a51f108e1e14c12879d8b9baf64285ba2c50864f16fe6d49df81b44f995ae4a6c33ebc
|
|
7
|
+
data.tar.gz: 5e301d87b8483bca8eb43fb72fdec997b49610001b4bf5563fb1e496a77190c7f812945b45a30b01dcf9fe212a529338041c2076fe5bf509d4153f99538310a1
|
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>
|
|
@@ -27,7 +27,7 @@ class Mysql
|
|
|
27
27
|
when "\x03" # fast_auth_success
|
|
28
28
|
# OK
|
|
29
29
|
when "\x04" # perform_full_authentication
|
|
30
|
-
if @protocol.client_flags & CLIENT_SSL != 0
|
|
30
|
+
if @protocol.client_flags & CLIENT_SSL != 0 || @protocol.socket.local_address.unix?
|
|
31
31
|
@protocol.write passwd+"\0"
|
|
32
32
|
elsif !@protocol.get_server_public_key
|
|
33
33
|
raise ClientError::AuthPluginErr, 'Authentication requires secure connection'
|
data/lib/mysql/charset.rb
CHANGED
|
@@ -330,11 +330,11 @@ class Mysql
|
|
|
330
330
|
].freeze
|
|
331
331
|
|
|
332
332
|
# @private
|
|
333
|
-
NUMBER_TO_CHARSET = {}
|
|
333
|
+
NUMBER_TO_CHARSET = {}
|
|
334
334
|
# @private
|
|
335
|
-
COLLATION_TO_CHARSET = {}
|
|
335
|
+
COLLATION_TO_CHARSET = {}
|
|
336
336
|
# @private
|
|
337
|
-
CHARSET_DEFAULT = {}
|
|
337
|
+
CHARSET_DEFAULT = {}
|
|
338
338
|
CHARSETS.each do |number, csname, clname, default|
|
|
339
339
|
cs = Charset.new number, csname, clname
|
|
340
340
|
NUMBER_TO_CHARSET[number] = cs
|
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
|
|
@@ -35,7 +35,7 @@ class Mysql
|
|
|
35
35
|
|
|
36
36
|
# server side error
|
|
37
37
|
class ServerError < Error
|
|
38
|
-
ERROR_MAP = {}
|
|
38
|
+
ERROR_MAP = {}
|
|
39
39
|
|
|
40
40
|
ER_ERROR_FIRST = 1000
|
|
41
41
|
ER_HASHCHK = 1000
|
|
@@ -908,11 +908,11 @@ 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(
|
|
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
|
|
915
|
-
ERROR_MAP = {}
|
|
915
|
+
ERROR_MAP = {}
|
|
916
916
|
|
|
917
917
|
CR_ERROR_FIRST = 2000
|
|
918
918
|
CR_UNKNOWN_ERROR = 2000
|
data/lib/mysql/protocol.rb
CHANGED
|
@@ -119,6 +119,7 @@ class Mysql
|
|
|
119
119
|
return type, val
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
+
attr_reader :socket
|
|
122
123
|
attr_reader :server_info
|
|
123
124
|
attr_reader :server_version
|
|
124
125
|
attr_reader :thread_id
|
|
@@ -513,7 +514,7 @@ class Mysql
|
|
|
513
514
|
# @return [Packet] packet data
|
|
514
515
|
# @rails [ProtocolError] invalid packet sequence number
|
|
515
516
|
def read
|
|
516
|
-
data = ''
|
|
517
|
+
data = +''
|
|
517
518
|
len = nil
|
|
518
519
|
begin
|
|
519
520
|
timeout = @state == :INIT ? @opts[:connect_timeout] : @opts[:read_timeout]
|
|
@@ -554,7 +555,7 @@ class Mysql
|
|
|
554
555
|
|
|
555
556
|
def read_timeout(len, timeout)
|
|
556
557
|
return @socket.read(len) if timeout.nil? || timeout == 0
|
|
557
|
-
result = ''
|
|
558
|
+
result = +''
|
|
558
559
|
e = Time.now + timeout
|
|
559
560
|
while result.size < len
|
|
560
561
|
now = Time.now
|
|
@@ -789,7 +790,7 @@ class Mysql
|
|
|
789
790
|
username,
|
|
790
791
|
Packet.lcs(scrambled_password),
|
|
791
792
|
]
|
|
792
|
-
pack = "VVCa23Z*A*"
|
|
793
|
+
pack = +"VVCa23Z*A*"
|
|
793
794
|
if databasename
|
|
794
795
|
data.push databasename
|
|
795
796
|
pack.concat "Z*"
|
|
@@ -817,7 +818,7 @@ class Mysql
|
|
|
817
818
|
class ExecutePacket
|
|
818
819
|
def self.serialize(statement_id, cursor_type, values)
|
|
819
820
|
nbm = null_bitmap values
|
|
820
|
-
netvalues = ""
|
|
821
|
+
netvalues = +""
|
|
821
822
|
types = values.map do |v|
|
|
822
823
|
t, n = Protocol.value2net v
|
|
823
824
|
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 =
|
|
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
|
-
|
|
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
|
|
25
|
+
VERSION = -'4.2.1' # 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
|
-
|
|
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 =
|
|
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
|
|
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
|
-
#
|
|
400
|
+
# return Mysql::Result for last query.
|
|
403
401
|
# @return [Mysql::Result]
|
|
404
402
|
# @return [nil] if no results
|
|
405
|
-
def
|
|
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
|
|
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
|
-
|
|
476
|
-
|
|
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
|
|
4
|
+
version: 4.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomita Masahiro
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 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:
|
|
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:
|
|
58
|
-
signing_key:
|
|
55
|
+
rubygems_version: 4.0.2
|
|
59
56
|
specification_version: 4
|
|
60
57
|
summary: MySQL connector
|
|
61
58
|
test_files: []
|