mysql-pr 2.9.11 → 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 740a7c4a533c1dfee294b1fd1d5d71a094c758309157bc1b0366eeaa30417e7f
4
+ data.tar.gz: a50dc6eae35b3c41b166e7532b798b32b414c9753fadc06f9e43aaf413502aee
5
+ SHA512:
6
+ metadata.gz: e5b48f7d27454ee4f21d0bb5d3f785d2edd98d32c3ed5629be97fb2809f7705f0650ae6d460695c95f3e42a36e23f94c15266cb533b99e66b50aae1c0867d0d3
7
+ data.tar.gz: 44ced5a010465b9cee5abb5522401f1429575bc3787f63637d7818776aa4f01ed61a496a8fa4b30820a60734b5a5a33068e29a030bba46d2be52fa3d5443790c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,84 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+ NewCops: disable
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - "vendor/**/*"
7
+ - "bin/**/*"
8
+ - "spec/**/*"
9
+
10
+ Gemspec/DevelopmentDependencies:
11
+ Enabled: false
12
+
13
+ Gemspec/RequireMFA:
14
+ Enabled: false
15
+
16
+ # Metrics - Relaxed for protocol parsing code
17
+ Metrics/AbcSize:
18
+ Max: 60
19
+ Exclude:
20
+ - "lib/mysql-pr/protocol.rb"
21
+
22
+ Metrics/BlockLength:
23
+ Exclude:
24
+ - "*.gemspec"
25
+
26
+ Metrics/ClassLength:
27
+ Max: 750
28
+
29
+ Metrics/CyclomaticComplexity:
30
+ Max: 25
31
+
32
+ Metrics/MethodLength:
33
+ Max: 60
34
+
35
+ Metrics/PerceivedComplexity:
36
+ Max: 25
37
+
38
+ # Layout
39
+ Layout/LineLength:
40
+ Max: 120
41
+ Exclude:
42
+ - "lib/mysql-pr/error.rb"
43
+ - "lib/mysql-pr/charset.rb"
44
+
45
+ # Style
46
+ Style/Documentation:
47
+ Enabled: false
48
+
49
+ Style/FrozenStringLiteralComment:
50
+ Enabled: true
51
+
52
+ Style/StringLiterals:
53
+ EnforcedStyle: double_quotes
54
+
55
+ Style/StringLiteralsInInterpolation:
56
+ EnforcedStyle: double_quotes
57
+
58
+ # Naming
59
+ Naming/PredicatePrefix:
60
+ AllowedMethods:
61
+ - is_num?
62
+ - is_not_null?
63
+ - is_pri_key?
64
+
65
+ Naming/AccessorMethodName:
66
+ Enabled: false
67
+
68
+ Naming/FileName:
69
+ Enabled: false
70
+
71
+ Naming/MethodParameterName:
72
+ MinNameLength: 1
73
+
74
+ Metrics/ParameterLists:
75
+ Enabled: false
76
+
77
+ Style/OptionalBooleanParameter:
78
+ Enabled: false
79
+
80
+ Style/FormatStringToken:
81
+ Enabled: false
82
+
83
+ Lint/UnreachableCode:
84
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [3.0.1] - 2025-11-25
9
+
10
+ ### Fixed
11
+
12
+ - Fixed RuboCop style issues across codebase
13
+ - Fixed CI configuration for GitHub Actions
14
+
15
+ ## [3.0.0] - 2025-11-25
16
+
17
+ ### Changed
18
+
19
+ - **BREAKING**: Minimum Ruby version is now 3.0
20
+ - Modernized codebase with frozen string literals
21
+ - Updated to modern Ruby conventions and style
22
+ - Replaced deprecated `Fixnum` with `Integer`
23
+
24
+ ### Removed
25
+
26
+ - Ruby 1.8.x and 1.9.x support
27
+ - Legacy encoding compatibility code
28
+
29
+ ### Added
30
+
31
+ - **SSL/TLS connection support** - encrypted connections using Ruby's OpenSSL
32
+ - `ssl_set` method for configuring SSL certificates
33
+ - `ssl_options=` method for advanced SSL configuration
34
+ - `ssl_enabled?` and `ssl_cipher` methods to query SSL status
35
+ - Support for TLS 1.2 and TLS 1.3
36
+ - **MySQL 8.0 `caching_sha2_password` authentication** support
37
+ - Full support for MySQL 8.0's default authentication plugin
38
+ - Fast authentication path when password is cached
39
+ - Full authentication via SSL or RSA encryption
40
+ - Automatic auth plugin detection and switching
41
+ - Modern project structure with Bundler
42
+ - RSpec test configuration
43
+ - RuboCop for code style enforcement
44
+ - GitHub Actions CI pipeline
45
+ - Docker Compose configuration for testing
46
+ - Comprehensive README documentation
47
+
48
+ ## [2.9.11] - 2012-06-13
49
+
50
+ ### Added
51
+
52
+ - Initial release as mysql-pr (fork from mysql-ruby)
53
+ - Pure Ruby MySQL client implementation
54
+ - Prepared statements support
55
+ - Character set handling
data/LICENSE ADDED
@@ -0,0 +1,83 @@
1
+ mysql-pr is derived from the original mysql-pr/mysql-ruby by TOMITA Masahiro
2
+ <tommy@tmtm.org>.
3
+
4
+ This version (3.0.0+) is copyright 2025 Alex Jokela <alex@camulus.com>.
5
+
6
+ You can redistribute it and/or modify it under either the terms of the
7
+ 2-clause BSDL (see below), or the Ruby License (see below).
8
+
9
+ --------------------------------------------------------------------------------
10
+
11
+ The 2-clause BSD License:
12
+
13
+ Redistribution and use in source and binary forms, with or without
14
+ modification, are permitted provided that the following conditions are met:
15
+
16
+ 1. Redistributions of source code must retain the above copyright notice, this
17
+ list of conditions and the following disclaimer.
18
+
19
+ 2. Redistributions in binary form must reproduce the above copyright notice,
20
+ this list of conditions and the following disclaimer in the documentation
21
+ and/or other materials provided with the distribution.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+
34
+ --------------------------------------------------------------------------------
35
+
36
+ The Ruby License:
37
+
38
+ 1. You may make and give away verbatim copies of the source form of the
39
+ software without restriction, provided that you duplicate all of the
40
+ original copyright notices and associated disclaimers.
41
+
42
+ 2. You may modify your copy of the software in any way, provided that
43
+ you do at least ONE of the following:
44
+
45
+ a. place your modifications in the Public Domain or otherwise make them
46
+ Freely Available, such as by posting said modifications to Usenet
47
+ or an equivalent medium, or by allowing the author to include your
48
+ modifications in the software.
49
+
50
+ b. use the modified software only within your corporation or organization.
51
+
52
+ c. give non-standard binaries non-standard names, with instructions on
53
+ where to get the original software distribution.
54
+
55
+ d. make other distribution arrangements with the author.
56
+
57
+ 3. You may distribute the software in object code or binary form, provided
58
+ that you do at least ONE of the following:
59
+
60
+ a. distribute the binaries and library files of the software, together
61
+ with instructions (in the manual page or equivalent) on where to get
62
+ the original distribution.
63
+
64
+ b. accompany the distribution with the machine-readable source of the
65
+ software.
66
+
67
+ c. give non-standard binaries non-standard names, with instructions on
68
+ where to get the original software distribution.
69
+
70
+ d. make other distribution arrangements with the author.
71
+
72
+ 4. You may modify and include the part of the software into any other
73
+ software (possibly commercial). But some files in the distribution are
74
+ not written by the author, so that they are not under these terms.
75
+
76
+ 5. The scripts and library files supplied as input to or produced as output
77
+ from the software do not automatically fall under the copyright of the
78
+ software, but belong to whomever generated them, and may be sold
79
+ commercially, and may be aggregated with this software.
80
+
81
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
82
+ WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
83
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
data/README.md ADDED
@@ -0,0 +1,199 @@
1
+ # mysql-pr
2
+
3
+ A pure Ruby MySQL client library. No native extensions required.
4
+
5
+ [![CI](https://github.com/ajokela/mysql-pr/actions/workflows/ci.yml/badge.svg)](https://github.com/ajokela/mysql-pr/actions/workflows/ci.yml)
6
+ [![Gem Version](https://badge.fury.io/rb/mysql-pr.svg)](https://badge.fury.io/rb/mysql-pr)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'mysql-pr'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```bash
19
+ $ bundle install
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```bash
25
+ $ gem install mysql-pr
26
+ ```
27
+
28
+ ## Requirements
29
+
30
+ - Ruby 3.0 or higher
31
+ - MySQL 5.7+ or MySQL 8.0+
32
+
33
+ ## Usage
34
+
35
+ ### Basic Connection
36
+
37
+ ```ruby
38
+ require 'mysql-pr'
39
+
40
+ # Connect to MySQL
41
+ my = MysqlPR.connect('hostname', 'username', 'password', 'database')
42
+
43
+ # Execute a query
44
+ result = my.query("SELECT id, name FROM users WHERE active = 1")
45
+ result.each do |id, name|
46
+ puts "#{id}: #{name}"
47
+ end
48
+
49
+ # Close connection
50
+ my.close
51
+ ```
52
+
53
+ ### Prepared Statements
54
+
55
+ ```ruby
56
+ # Using prepared statements (recommended for user input)
57
+ stmt = my.prepare('INSERT INTO users (name, email) VALUES (?, ?)')
58
+ stmt.execute('John Doe', 'john@example.com')
59
+
60
+ # Select with prepared statement
61
+ stmt = my.prepare('SELECT * FROM users WHERE id = ?')
62
+ stmt.execute(123)
63
+ stmt.each do |row|
64
+ puts row.inspect
65
+ end
66
+ ```
67
+
68
+ ### Transactions
69
+
70
+ ```ruby
71
+ my.autocommit(false)
72
+
73
+ begin
74
+ my.query("INSERT INTO accounts (name) VALUES ('test')")
75
+ my.query("UPDATE balances SET amount = amount - 100 WHERE id = 1")
76
+ my.commit
77
+ rescue => e
78
+ my.rollback
79
+ raise e
80
+ end
81
+ ```
82
+
83
+ ### Connection Options
84
+
85
+ ```ruby
86
+ my = MysqlPR.init
87
+ my.options(MysqlPR::OPT_CONNECT_TIMEOUT, 10)
88
+ my.options(MysqlPR::OPT_READ_TIMEOUT, 30)
89
+ my.options(MysqlPR::SET_CHARSET_NAME, 'utf8mb4')
90
+ my.connect('hostname', 'username', 'password', 'database')
91
+ ```
92
+
93
+ ### Escaping Strings
94
+
95
+ ```ruby
96
+ # Class method (no connection required)
97
+ safe_string = MysqlPR.escape_string("O'Reilly")
98
+
99
+ # Instance method
100
+ safe_string = my.escape_string(user_input)
101
+ ```
102
+
103
+ ### SSL/TLS Connections
104
+
105
+ ```ruby
106
+ my = MysqlPR.init
107
+
108
+ # Simple SSL (no certificate verification - for self-signed certs)
109
+ my.ssl_options = { verify: false }
110
+ my.connect('hostname', 'username', 'password', 'database')
111
+
112
+ # SSL with CA certificate verification
113
+ my.ssl_set(nil, nil, '/path/to/ca-cert.pem')
114
+ my.connect('hostname', 'username', 'password', 'database')
115
+
116
+ # SSL with client certificate
117
+ my.ssl_set(
118
+ '/path/to/client-key.pem',
119
+ '/path/to/client-cert.pem',
120
+ '/path/to/ca-cert.pem'
121
+ )
122
+ my.connect('hostname', 'username', 'password', 'database')
123
+
124
+ # Check SSL status
125
+ puts my.ssl_enabled? # => true
126
+ puts my.ssl_cipher # => ["TLS_AES_256_GCM_SHA384", "TLSv1.3", 256, 256]
127
+ ```
128
+
129
+ ## Features
130
+
131
+ - Pure Ruby implementation - no compilation required
132
+ - MySQL protocol 4.1+ support
133
+ - **Full MySQL 8.0 support** including `caching_sha2_password` authentication
134
+ - **SSL/TLS encrypted connections** (TLS 1.2, 1.3)
135
+ - Prepared statements with parameter binding
136
+ - Multiple result sets
137
+ - Character set support with automatic encoding conversion
138
+ - Thread-safe connections
139
+
140
+ ## Differences from mysql2 gem
141
+
142
+ This gem is a pure Ruby implementation, which means:
143
+
144
+ - **Pros**: No native compilation, works on any Ruby platform, easier to install
145
+ - **Cons**: Generally slower than native extensions for high-throughput applications
146
+
147
+ Choose `mysql-pr` when you need:
148
+ - Easy installation without native dependencies
149
+ - Compatibility with JRuby or other alternative Ruby implementations
150
+ - A lightweight MySQL client for simple applications
151
+
152
+ ## Development
153
+
154
+ ### Running Tests
155
+
156
+ Unit tests can be run without a MySQL server:
157
+
158
+ ```bash
159
+ bundle exec rspec spec/unit spec/mysql
160
+ ```
161
+
162
+ ### Integration Tests with Docker
163
+
164
+ To run integration tests against a real MySQL server:
165
+
166
+ ```bash
167
+ # Start MySQL container
168
+ docker compose up -d
169
+
170
+ # Run integration tests
171
+ ./bin/test-with-docker
172
+
173
+ # Stop MySQL container when done
174
+ docker compose down
175
+ ```
176
+
177
+ Or configure your own MySQL server using environment variables:
178
+
179
+ ```bash
180
+ MYSQL_SERVER=localhost \
181
+ MYSQL_USER=root \
182
+ MYSQL_PASSWORD=secret \
183
+ MYSQL_DATABASE=test_for_mysql_ruby \
184
+ MYSQL_PORT=3306 \
185
+ bundle exec rspec spec/mysql_spec.rb
186
+ ```
187
+
188
+ ## Contributing
189
+
190
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ajokela/mysql-pr.
191
+
192
+ ## License
193
+
194
+ This gem is available under the Ruby License. See the LICENSE file for more details.
195
+
196
+ ## Authors
197
+
198
+ - TOMITA Masahiro (tommy@tmtm.org) - Original author
199
+ - Alex Jokela (alex@camulus.com) - Current maintainer
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
@@ -0,0 +1,25 @@
1
+ version: "3.8"
2
+
3
+ services:
4
+ mysql:
5
+ image: mysql:8.0
6
+ container_name: mysql-pr-test
7
+ environment:
8
+ MYSQL_ROOT_PASSWORD: root
9
+ MYSQL_DATABASE: test_for_mysql_ruby
10
+ ports:
11
+ - "3306:3306"
12
+ command:
13
+ - --default-authentication-plugin=mysql_native_password
14
+ - --character-set-server=utf8mb4
15
+ - --collation-server=utf8mb4_unicode_ci
16
+ healthcheck:
17
+ test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
18
+ interval: 5s
19
+ timeout: 5s
20
+ retries: 10
21
+ volumes:
22
+ - mysql-data:/var/lib/mysql
23
+
24
+ volumes:
25
+ mysql-data: