ruby-mysql 4.0.0 → 4.1.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
2
  SHA256:
3
- metadata.gz: 13656e5ef8a79113c2dce1fac6f1a47e510c2cd6bfb9958518a966b349bdbb13
4
- data.tar.gz: 55a2f5e70d73add2e6d71eb0bb02e19d0d498cacd46c78f0415f8f31620c76ab
3
+ metadata.gz: fd37c2f40ef7277952c0be41848abc338e29d3a4e9da3f3eed1d1d8f61407c76
4
+ data.tar.gz: 754994f1cb1f5e4cb007d5f1a3d81238e626ce8d224aef23c58c8af3d5fd351f
5
5
  SHA512:
6
- metadata.gz: a01515533387aaa8280be8c5244b80d4b245052e2750732f03c6198827dd5975a32f8f472481ba44b14f731135b31aa3744180475444388c7e1158d49bf95556
7
- data.tar.gz: 53fe3127e8c358f77a3874e26ae1de91dcd72af11fcd45f40b18875c21a884d21105eccce4808b308bde1e938970316cf6d7f54ac21f9bf94cebb9fc2b8dcbd5
6
+ metadata.gz: c31c8170682621713905f820a2816377a045b3ba489adc39d3575543483475411bdd7ecead30f806494533dd91819e8e53dad1bd3c090164b80d7600666ea1a4
7
+ data.tar.gz: 6f59d7638d0f09bd3c21cd34e32cae9e995f26219efc5594b3982b94562a0c3726a1258ebfff5e3b0afbe53764135d96eff0250d57d6d75289f65e3b9957e720
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [4.1.0] - 2023-10-08
2
+
3
+ - Support geometry column <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/1>
4
+ - FIX: If the server is localhost and disconnect the connection, Errno::EPIPE is raised <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/3> <https://gitlab.com/tmtms/ruby-mysql/-/issues/1>
5
+ - Allow for existing socket when connecting <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/2> <https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/5>
6
+ - add `io` keyword parameter
7
+
1
8
  ## [4.0.0] - 2022-11-09
2
9
 
3
10
  ### Incompatible changes
data/README.md CHANGED
@@ -2,17 +2,21 @@
2
2
 
3
3
  ## Description
4
4
 
5
- MySQL connector for Ruby.
5
+ ruby-mysql is a MySQL client library.
6
+ It is written entirely in Ruby.
7
+ Therefore libmysqlclient is not required and no compilation is required during installation.
6
8
 
7
9
  ## Installation
8
10
 
9
- ```
11
+ ```ruby
10
12
  gem install ruby-mysql
11
13
  ```
12
14
 
13
15
  ## Synopsis
14
16
 
15
17
  ```ruby
18
+ require 'mysql'
19
+
16
20
  my = Mysql.connect('mysql://username:password@hostname:port/dbname?charset=utf8mb4')
17
21
  my.query("select col1, col2 from tblname").each do |col1, col2|
18
22
  p col1, col2
@@ -21,6 +25,95 @@ stmt = my.prepare('insert into tblname (col1,col2) values (?,?)')
21
25
  stmt.execute 123, 'abc'
22
26
  ```
23
27
 
28
+ ## Major incompatibility with 3.0
29
+
30
+ ### Result values are now converted by default
31
+
32
+ | MySQL type | Ruby class |
33
+ |---------------------|--------------------|
34
+ | NULL | NilClass |
35
+ | INT | Integer |
36
+ | DECIMAL | BigDecimal |
37
+ | FLOAT, DOUBLE | Float |
38
+ | DATE | Date |
39
+ | DATETIME, TIMESTAMP | Time |
40
+ | TIME | Float (as seconds) |
41
+ | YEAR | Integer |
42
+ | CHAR, VARCHAR | String |
43
+ | BIT | String |
44
+ | TEXT, BLOB, JSON | String |
45
+
46
+ 3.0:
47
+ ```ruby
48
+ pp my.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
49
+ #=> [["123", String],
50
+ # ["123.45", String],
51
+ # ["2022-11-15 00:17:11", String],
52
+ # ["2022-11-15", String]]
53
+ ```
54
+
55
+ 4.0:
56
+ ```ruby
57
+ pp my.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
58
+ #=> [[123, Integer],
59
+ # [0.12345e3, BigDecimal],
60
+ # [2022-11-15 00:17:17 +0900, Time],
61
+ # [#<Date: 2022-11-15 ((2459899j,0s,0n),+0s,2299161j)>, Date]]
62
+ ```
63
+
64
+ To specify `cast: false`, you get the same behavior as in 3.0.
65
+ ```ruby
66
+ my.query('select 123,123.45,now(),cast(now() as date)', cast: false).fetch.map{[_1, _1.class]}
67
+ #=> [["123", String],
68
+ # ["123.45", String],
69
+ # ["2022-11-15 00:19:18", String],
70
+ # ["2022-11-15", String]]
71
+ ```
72
+
73
+ It can also be specified during Mysql.new and Mysql.connect.
74
+
75
+ ```ruby
76
+ my = Mysql.connect('mysql://user:pass@localhost/', cast: false)
77
+ ```
78
+
79
+ Changing mysql.default_options will affect the behavior of subsequently created instances.
80
+
81
+ ```ruby
82
+ my1 = Mysql.connect('mysql://user:pass@localhost/')
83
+ Mysql.default_options[:cast] = false
84
+ my2 = Mysql.connect('mysql://user:pass@localhost/')
85
+ pp my1.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
86
+ #=> [[123, Integer],
87
+ # [0.12345e3, BigDecimal],
88
+ # [2022-11-15 00:26:09 +0900, Time],
89
+ # [#<Date: 2022-11-15 ((2459899j,0s,0n),+0s,2299161j)>, Date]]
90
+ pp my2.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
91
+ #=> [["123", String],
92
+ # ["123.45", String],
93
+ # ["2022-11-15 00:26:09", String],
94
+ # ["2022-11-15", String]]
95
+ ```
96
+
97
+ ### Mysql::Result#each now always return records from the beginning
98
+
99
+ 3.0:
100
+ ```ruby
101
+ res = my.query('select 123 union select 456')
102
+ res.entries
103
+ #=> [["123"], ["456"]]
104
+ res.entries
105
+ #=> []
106
+ ```
107
+
108
+ 4.0:
109
+ ```ruby
110
+ res = my.query('select 123 union select 456')
111
+ res.entries
112
+ #=> [[123], [456]]
113
+ res.entries
114
+ #=> [[123], [456]]
115
+ ```
116
+
24
117
  ## Copyright
25
118
 
26
119
  * Author: TOMITA Masahiro <tommy@tmtm.org>
@@ -24,7 +24,7 @@ class Mysql
24
24
  # @return [Object] converted value.
25
25
  def self.net2value(pkt, type, unsigned)
26
26
  case type
27
- when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_BLOB, Field::TYPE_JSON
27
+ when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_BLOB, Field::TYPE_JSON, Field::TYPE_GEOMETRY
28
28
  return pkt.lcs
29
29
  when Field::TYPE_NEWDECIMAL
30
30
  s = pkt.lcs
@@ -160,6 +160,7 @@ class Mysql
160
160
  # @option :ssl_mode [Integer]
161
161
  # @option :ssl_context_params [Hash<:Symbol, String>]
162
162
  # @option :get_server_public_key [Boolean]
163
+ # @option :io [BasicSocket, OpenSSL::SSL::SSLSocket] Existing socket instance that will be used instead of creating a new socket
163
164
  # @raise [ClientError] connection timeout
164
165
  def initialize(opts)
165
166
  @mutex = Mutex.new
@@ -172,7 +173,9 @@ class Mysql
172
173
  set_state :INIT
173
174
  @get_server_public_key = @opts[:get_server_public_key]
174
175
  begin
175
- if @opts[:host].nil? or @opts[:host].empty? or @opts[:host] == "localhost"
176
+ if @opts[:io]
177
+ @socket = @opts[:io]
178
+ elsif @opts[:host].nil? or @opts[:host].empty? or @opts[:host] == "localhost"
176
179
  socket = @opts[:socket] || ENV["MYSQL_UNIX_PORT"] || MYSQL_UNIX_PORT
177
180
  @socket = Socket.unix(socket)
178
181
  else
@@ -185,7 +188,7 @@ class Mysql
185
188
  end
186
189
 
187
190
  def close
188
- @socket.close
191
+ @socket.close rescue nil
189
192
  end
190
193
 
191
194
  # initial negotiate and authenticate.
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.0.0' # Version number of this library
25
+ VERSION = -'4.1.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
 
@@ -40,6 +40,8 @@ class Mysql
40
40
  # @return [String, nil] socket filename
41
41
  # @!attribute [rw] flags
42
42
  # @return [Integer, nil]
43
+ # @!attribute [rw] io
44
+ # @return [[BasicSocket, OpenSSL::SSL::SSLSocket], nil]
43
45
  # @!attribute [rw] connect_timeout
44
46
  # @return [Numeric, nil]
45
47
  # @!attribute [rw] read_timeout
@@ -78,6 +80,7 @@ class Mysql
78
80
  port: nil,
79
81
  socket: nil,
80
82
  flags: 0,
83
+ io: nil,
81
84
  charset: nil,
82
85
  connect_timeout: nil,
83
86
  read_timeout: nil,
@@ -172,6 +175,7 @@ class Mysql
172
175
  # @option opts :ssl_context_params [Hash<Symbol, String>]
173
176
  # @option opts :get_server_public_key [Boolean]
174
177
  # @option opts :connect_attrs [Hash]
178
+ # @option opts :io [BasicSocket, OpenSSL::SSL::SSLSocket] Existing socket instance that will be used instead of creating a new socket
175
179
  def initialize(*args, **opts)
176
180
  @fields = nil
177
181
  @result = nil
metadata CHANGED
@@ -1,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomita Masahiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-13 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: power_assert
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
11
+ date: 2023-10-08 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description: This is MySQL connector. pure Ruby version
56
14
  email: tommy@tmtm.org
57
15
  executables: []
@@ -96,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
54
  - !ruby/object:Gem::Version
97
55
  version: '0'
98
56
  requirements: []
99
- rubygems_version: 3.4.0.dev
57
+ rubygems_version: 3.5.0.dev
100
58
  signing_key:
101
59
  specification_version: 4
102
60
  summary: MySQL connector