mysql-pr 3.0.0 → 3.0.2
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/.rubocop.yml +33 -17
- data/CHANGELOG.md +14 -1
- data/lib/mysql-pr/charset.rb +132 -134
- data/lib/mysql-pr/constants.rb +5 -5
- data/lib/mysql-pr/error.rb +10 -10
- data/lib/mysql-pr/packet.rb +21 -17
- data/lib/mysql-pr/protocol.rb +219 -199
- data/lib/mysql-pr/version.rb +1 -1
- data/lib/mysql-pr.rb +20 -30
- data/mysql-pr.gemspec +0 -1
- metadata +1 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1227fb0fe7b291eb7437e53f5a991b32dc8ecdca6d6839b2b2579d445de20220
|
|
4
|
+
data.tar.gz: 0effb4c0ffe7767c4f10268233f3451f737a8437718b8742390ef79756ad5be3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db52b63cbdf3846e379ffd5359f18cb866eeb2548ecf8daaac6ace83dfc028697c0c215bf5ff52241ecd21fa25b757e478977c5652eed08f8db3d6a01d7cd153
|
|
7
|
+
data.tar.gz: 418692e181b1a4558f5ad67911d72094bac45c5c08700803066b215b3247fd35367d8eb972a358b65d9e42bc788d463625d6d556fdedb1d4325032d761a1ff4d
|
data/.rubocop.yml
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
|
-
require:
|
|
2
|
-
- rubocop-rspec
|
|
3
|
-
|
|
4
1
|
AllCops:
|
|
5
2
|
TargetRubyVersion: 3.0
|
|
6
|
-
NewCops:
|
|
3
|
+
NewCops: disable
|
|
7
4
|
SuggestExtensions: false
|
|
8
5
|
Exclude:
|
|
9
6
|
- "vendor/**/*"
|
|
10
7
|
- "bin/**/*"
|
|
8
|
+
- "spec/**/*"
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
Gemspec/DevelopmentDependencies:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
Gemspec/RequireMFA:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
# Metrics - Relaxed for protocol parsing code
|
|
13
17
|
Metrics/AbcSize:
|
|
14
|
-
Max:
|
|
18
|
+
Max: 60
|
|
19
|
+
Exclude:
|
|
20
|
+
- "lib/mysql-pr/protocol.rb"
|
|
15
21
|
|
|
16
22
|
Metrics/BlockLength:
|
|
17
23
|
Exclude:
|
|
18
|
-
- "spec/**/*"
|
|
19
24
|
- "*.gemspec"
|
|
20
25
|
|
|
21
26
|
Metrics/ClassLength:
|
|
22
|
-
Max:
|
|
27
|
+
Max: 750
|
|
23
28
|
|
|
24
29
|
Metrics/CyclomaticComplexity:
|
|
25
|
-
Max:
|
|
30
|
+
Max: 25
|
|
26
31
|
|
|
27
32
|
Metrics/MethodLength:
|
|
28
|
-
Max:
|
|
33
|
+
Max: 60
|
|
29
34
|
|
|
30
35
|
Metrics/PerceivedComplexity:
|
|
31
|
-
Max:
|
|
36
|
+
Max: 25
|
|
32
37
|
|
|
33
38
|
# Layout
|
|
34
39
|
Layout/LineLength:
|
|
@@ -51,7 +56,7 @@ Style/StringLiteralsInInterpolation:
|
|
|
51
56
|
EnforcedStyle: double_quotes
|
|
52
57
|
|
|
53
58
|
# Naming
|
|
54
|
-
Naming/
|
|
59
|
+
Naming/PredicatePrefix:
|
|
55
60
|
AllowedMethods:
|
|
56
61
|
- is_num?
|
|
57
62
|
- is_not_null?
|
|
@@ -60,9 +65,20 @@ Naming/PredicateName:
|
|
|
60
65
|
Naming/AccessorMethodName:
|
|
61
66
|
Enabled: false
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Max: 20
|
|
68
|
+
Naming/FileName:
|
|
69
|
+
Enabled: false
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
|
|
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
CHANGED
|
@@ -5,7 +5,20 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [3.0.
|
|
8
|
+
## [3.0.2] - 2025-11-25
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Consolidated duplicate VERSION tests into single regex-based test
|
|
13
|
+
|
|
14
|
+
## [3.0.1] - 2025-11-25
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Fixed RuboCop style issues across codebase
|
|
19
|
+
- Fixed CI configuration for GitHub Actions
|
|
20
|
+
|
|
21
|
+
## [3.0.0] - 2025-11-25
|
|
9
22
|
|
|
10
23
|
### Changed
|
|
11
24
|
|
data/lib/mysql-pr/charset.rb
CHANGED
|
@@ -27,98 +27,98 @@ class MysqlPR
|
|
|
27
27
|
|
|
28
28
|
# [[charset_number, charset_name, collation_name, default], ...]
|
|
29
29
|
CHARSETS = [
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
43
|
-
[
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
82
|
-
[
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
96
|
-
[
|
|
97
|
-
[
|
|
98
|
-
[
|
|
99
|
-
[
|
|
100
|
-
[
|
|
101
|
-
[
|
|
102
|
-
[
|
|
103
|
-
[
|
|
104
|
-
[
|
|
105
|
-
[
|
|
106
|
-
[
|
|
107
|
-
[
|
|
108
|
-
[
|
|
109
|
-
[
|
|
110
|
-
[
|
|
111
|
-
[
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[
|
|
115
|
-
[
|
|
116
|
-
[
|
|
117
|
-
[
|
|
118
|
-
[
|
|
119
|
-
[
|
|
120
|
-
[
|
|
121
|
-
[
|
|
30
|
+
[1, "big5", "big5_chinese_ci", true],
|
|
31
|
+
[2, "latin2", "latin2_czech_cs", false],
|
|
32
|
+
[3, "dec8", "dec8_swedish_ci", true],
|
|
33
|
+
[4, "cp850", "cp850_general_ci", true],
|
|
34
|
+
[5, "latin1", "latin1_german1_ci", false],
|
|
35
|
+
[6, "hp8", "hp8_english_ci", true],
|
|
36
|
+
[7, "koi8r", "koi8r_general_ci", true],
|
|
37
|
+
[8, "latin1", "latin1_swedish_ci", true],
|
|
38
|
+
[9, "latin2", "latin2_general_ci", true],
|
|
39
|
+
[10, "swe7", "swe7_swedish_ci", true],
|
|
40
|
+
[11, "ascii", "ascii_general_ci", true],
|
|
41
|
+
[12, "ujis", "ujis_japanese_ci", true],
|
|
42
|
+
[13, "sjis", "sjis_japanese_ci", true],
|
|
43
|
+
[14, "cp1251", "cp1251_bulgarian_ci", false],
|
|
44
|
+
[15, "latin1", "latin1_danish_ci", false],
|
|
45
|
+
[16, "hebrew", "hebrew_general_ci", true],
|
|
46
|
+
[17, "filename", "filename", true],
|
|
47
|
+
[18, "tis620", "tis620_thai_ci", true],
|
|
48
|
+
[19, "euckr", "euckr_korean_ci", true],
|
|
49
|
+
[20, "latin7", "latin7_estonian_cs", false],
|
|
50
|
+
[21, "latin2", "latin2_hungarian_ci", false],
|
|
51
|
+
[22, "koi8u", "koi8u_general_ci", true],
|
|
52
|
+
[23, "cp1251", "cp1251_ukrainian_ci", false],
|
|
53
|
+
[24, "gb2312", "gb2312_chinese_ci", true],
|
|
54
|
+
[25, "greek", "greek_general_ci", true],
|
|
55
|
+
[26, "cp1250", "cp1250_general_ci", true],
|
|
56
|
+
[27, "latin2", "latin2_croatian_ci", false],
|
|
57
|
+
[28, "gbk", "gbk_chinese_ci", true],
|
|
58
|
+
[29, "cp1257", "cp1257_lithuanian_ci", false],
|
|
59
|
+
[30, "latin5", "latin5_turkish_ci", true],
|
|
60
|
+
[31, "latin1", "latin1_german2_ci", false],
|
|
61
|
+
[32, "armscii8", "armscii8_general_ci", true],
|
|
62
|
+
[33, "utf8", "utf8_general_ci", true],
|
|
63
|
+
[34, "cp1250", "cp1250_czech_cs", false],
|
|
64
|
+
[35, "ucs2", "ucs2_general_ci", true],
|
|
65
|
+
[36, "cp866", "cp866_general_ci", true],
|
|
66
|
+
[37, "keybcs2", "keybcs2_general_ci", true],
|
|
67
|
+
[38, "macce", "macce_general_ci", true],
|
|
68
|
+
[39, "macroman", "macroman_general_ci", true],
|
|
69
|
+
[40, "cp852", "cp852_general_ci", true],
|
|
70
|
+
[41, "latin7", "latin7_general_ci", true],
|
|
71
|
+
[42, "latin7", "latin7_general_cs", false],
|
|
72
|
+
[43, "macce", "macce_bin", false],
|
|
73
|
+
[44, "cp1250", "cp1250_croatian_ci", false],
|
|
74
|
+
[45, "utf8mb4", "utf8mb4_general_ci", true],
|
|
75
|
+
[46, "utf8mb4", "utf8mb4_bin", false],
|
|
76
|
+
[47, "latin1", "latin1_bin", false],
|
|
77
|
+
[48, "latin1", "latin1_general_ci", false],
|
|
78
|
+
[49, "latin1", "latin1_general_cs", false],
|
|
79
|
+
[50, "cp1251", "cp1251_bin", false],
|
|
80
|
+
[51, "cp1251", "cp1251_general_ci", true],
|
|
81
|
+
[52, "cp1251", "cp1251_general_cs", false],
|
|
82
|
+
[53, "macroman", "macroman_bin", false],
|
|
83
|
+
[57, "cp1256", "cp1256_general_ci", true],
|
|
84
|
+
[58, "cp1257", "cp1257_bin", false],
|
|
85
|
+
[59, "cp1257", "cp1257_general_ci", true],
|
|
86
|
+
[63, "binary", "binary", true],
|
|
87
|
+
[64, "armscii8", "armscii8_bin", false],
|
|
88
|
+
[65, "ascii", "ascii_bin", false],
|
|
89
|
+
[66, "cp1250", "cp1250_bin", false],
|
|
90
|
+
[67, "cp1256", "cp1256_bin", false],
|
|
91
|
+
[68, "cp866", "cp866_bin", false],
|
|
92
|
+
[69, "dec8", "dec8_bin", false],
|
|
93
|
+
[70, "greek", "greek_bin", false],
|
|
94
|
+
[71, "hebrew", "hebrew_bin", false],
|
|
95
|
+
[72, "hp8", "hp8_bin", false],
|
|
96
|
+
[73, "keybcs2", "keybcs2_bin", false],
|
|
97
|
+
[74, "koi8r", "koi8r_bin", false],
|
|
98
|
+
[75, "koi8u", "koi8u_bin", false],
|
|
99
|
+
[77, "latin2", "latin2_bin", false],
|
|
100
|
+
[78, "latin5", "latin5_bin", false],
|
|
101
|
+
[79, "latin7", "latin7_bin", false],
|
|
102
|
+
[80, "cp850", "cp850_bin", false],
|
|
103
|
+
[81, "cp852", "cp852_bin", false],
|
|
104
|
+
[82, "swe7", "swe7_bin", false],
|
|
105
|
+
[83, "utf8", "utf8_bin", false],
|
|
106
|
+
[84, "big5", "big5_bin", false],
|
|
107
|
+
[85, "euckr", "euckr_bin", false],
|
|
108
|
+
[86, "gb2312", "gb2312_bin", false],
|
|
109
|
+
[87, "gbk", "gbk_bin", false],
|
|
110
|
+
[88, "sjis", "sjis_bin", false],
|
|
111
|
+
[89, "tis620", "tis620_bin", false],
|
|
112
|
+
[90, "ucs2", "ucs2_bin", false],
|
|
113
|
+
[91, "ujis", "ujis_bin", false],
|
|
114
|
+
[92, "geostd8", "geostd8_general_ci", true],
|
|
115
|
+
[93, "geostd8", "geostd8_bin", false],
|
|
116
|
+
[94, "latin1", "latin1_spanish_ci", false],
|
|
117
|
+
[95, "cp932", "cp932_japanese_ci", true],
|
|
118
|
+
[96, "cp932", "cp932_bin", false],
|
|
119
|
+
[97, "eucjpms", "eucjpms_japanese_ci", true],
|
|
120
|
+
[98, "eucjpms", "eucjpms_bin", false],
|
|
121
|
+
[99, "cp1250", "cp1250_polish_ci", false],
|
|
122
122
|
[128, "ucs2", "ucs2_unicode_ci", false],
|
|
123
123
|
[129, "ucs2", "ucs2_icelandic_ci", false],
|
|
124
124
|
[130, "ucs2", "ucs2_latvian_ci", false],
|
|
@@ -179,14 +179,14 @@ class MysqlPR
|
|
|
179
179
|
[242, "utf8mb4", "utf8mb4_hungarian_ci", false],
|
|
180
180
|
[243, "utf8mb4", "utf8mb4_sinhala_ci", false],
|
|
181
181
|
[254, "utf8", "utf8_general_cs", false],
|
|
182
|
-
[255, "utf8mb4", "utf8mb4_0900_ai_ci", false]
|
|
182
|
+
[255, "utf8mb4", "utf8mb4_0900_ai_ci", false]
|
|
183
183
|
].freeze
|
|
184
184
|
|
|
185
185
|
UNSAFE_CHARSET = %w[big5 sjis filename gbk ucs2 cp932].freeze
|
|
186
186
|
|
|
187
|
-
NUMBER_TO_CHARSET = {}
|
|
188
|
-
COLLATION_TO_CHARSET = {}
|
|
189
|
-
CHARSET_DEFAULT = {}
|
|
187
|
+
NUMBER_TO_CHARSET = {} # rubocop:disable Style/MutableConstant
|
|
188
|
+
COLLATION_TO_CHARSET = {} # rubocop:disable Style/MutableConstant
|
|
189
|
+
CHARSET_DEFAULT = {} # rubocop:disable Style/MutableConstant
|
|
190
190
|
|
|
191
191
|
CHARSETS.each do |number, csname, clname, default|
|
|
192
192
|
cs = Charset.new(number, csname, clname)
|
|
@@ -205,42 +205,42 @@ class MysqlPR
|
|
|
205
205
|
# MySQL Charset -> Ruby Encoding mapping
|
|
206
206
|
CHARSET_ENCODING = {
|
|
207
207
|
"armscii8" => nil,
|
|
208
|
-
"ascii"
|
|
209
|
-
"big5"
|
|
210
|
-
"binary"
|
|
211
|
-
"cp1250"
|
|
212
|
-
"cp1251"
|
|
213
|
-
"cp1256"
|
|
214
|
-
"cp1257"
|
|
215
|
-
"cp850"
|
|
216
|
-
"cp852"
|
|
217
|
-
"cp866"
|
|
218
|
-
"cp932"
|
|
219
|
-
"dec8"
|
|
220
|
-
"eucjpms"
|
|
221
|
-
"euckr"
|
|
222
|
-
"gb2312"
|
|
223
|
-
"gbk"
|
|
224
|
-
"geostd8"
|
|
225
|
-
"greek"
|
|
226
|
-
"hebrew"
|
|
227
|
-
"hp8"
|
|
228
|
-
"keybcs2"
|
|
229
|
-
"koi8r"
|
|
230
|
-
"koi8u"
|
|
231
|
-
"latin1"
|
|
232
|
-
"latin2"
|
|
233
|
-
"latin5"
|
|
234
|
-
"latin7"
|
|
235
|
-
"macce"
|
|
208
|
+
"ascii" => Encoding::US_ASCII,
|
|
209
|
+
"big5" => Encoding::Big5,
|
|
210
|
+
"binary" => Encoding::ASCII_8BIT,
|
|
211
|
+
"cp1250" => Encoding::Windows_1250,
|
|
212
|
+
"cp1251" => Encoding::Windows_1251,
|
|
213
|
+
"cp1256" => Encoding::Windows_1256,
|
|
214
|
+
"cp1257" => Encoding::Windows_1257,
|
|
215
|
+
"cp850" => Encoding::CP850,
|
|
216
|
+
"cp852" => Encoding::CP852,
|
|
217
|
+
"cp866" => Encoding::IBM866,
|
|
218
|
+
"cp932" => Encoding::Windows_31J,
|
|
219
|
+
"dec8" => nil,
|
|
220
|
+
"eucjpms" => Encoding::EucJP_ms,
|
|
221
|
+
"euckr" => Encoding::EUC_KR,
|
|
222
|
+
"gb2312" => Encoding::EUC_CN,
|
|
223
|
+
"gbk" => Encoding::GBK,
|
|
224
|
+
"geostd8" => nil,
|
|
225
|
+
"greek" => Encoding::ISO_8859_7,
|
|
226
|
+
"hebrew" => Encoding::ISO_8859_8,
|
|
227
|
+
"hp8" => nil,
|
|
228
|
+
"keybcs2" => nil,
|
|
229
|
+
"koi8r" => Encoding::KOI8_R,
|
|
230
|
+
"koi8u" => Encoding::KOI8_U,
|
|
231
|
+
"latin1" => Encoding::ISO_8859_1,
|
|
232
|
+
"latin2" => Encoding::ISO_8859_2,
|
|
233
|
+
"latin5" => Encoding::ISO_8859_9,
|
|
234
|
+
"latin7" => Encoding::ISO_8859_13,
|
|
235
|
+
"macce" => Encoding::MacCentEuro,
|
|
236
236
|
"macroman" => Encoding::MacRoman,
|
|
237
|
-
"sjis"
|
|
238
|
-
"swe7"
|
|
239
|
-
"tis620"
|
|
240
|
-
"ucs2"
|
|
241
|
-
"ujis"
|
|
242
|
-
"utf8"
|
|
243
|
-
"utf8mb4"
|
|
237
|
+
"sjis" => Encoding::SHIFT_JIS,
|
|
238
|
+
"swe7" => nil,
|
|
239
|
+
"tis620" => Encoding::TIS_620,
|
|
240
|
+
"ucs2" => Encoding::UTF_16BE,
|
|
241
|
+
"ujis" => Encoding::EucJP_ms,
|
|
242
|
+
"utf8" => Encoding::UTF_8,
|
|
243
|
+
"utf8mb4" => Encoding::UTF_8
|
|
244
244
|
}.freeze
|
|
245
245
|
|
|
246
246
|
# @param [Integer] n charset number
|
|
@@ -286,9 +286,7 @@ class MysqlPR
|
|
|
286
286
|
# @param [String] value
|
|
287
287
|
# @return [String]
|
|
288
288
|
def convert(value)
|
|
289
|
-
if value.is_a?(String) && value.encoding != Encoding::ASCII_8BIT
|
|
290
|
-
value = value.encode(encoding)
|
|
291
|
-
end
|
|
289
|
+
value = value.encode(encoding) if value.is_a?(String) && value.encoding != Encoding::ASCII_8BIT
|
|
292
290
|
value
|
|
293
291
|
end
|
|
294
292
|
end
|
data/lib/mysql-pr/constants.rb
CHANGED
|
@@ -153,11 +153,11 @@ class MysqlPR
|
|
|
153
153
|
AUTO_INCREMENT_FLAG = 512
|
|
154
154
|
TIMESTAMP_FLAG = 1024
|
|
155
155
|
SET_FLAG = 2048
|
|
156
|
-
NUM_FLAG =
|
|
157
|
-
PART_KEY_FLAG =
|
|
158
|
-
GROUP_FLAG =
|
|
159
|
-
UNIQUE_FLAG =
|
|
160
|
-
BINCMP_FLAG =
|
|
156
|
+
NUM_FLAG = 32_768
|
|
157
|
+
PART_KEY_FLAG = 16_384
|
|
158
|
+
GROUP_FLAG = 32_768
|
|
159
|
+
UNIQUE_FLAG = 65_536
|
|
160
|
+
BINCMP_FLAG = 131_072
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
class Stmt
|
data/lib/mysql-pr/error.rb
CHANGED
|
@@ -8,14 +8,15 @@ class MysqlPR
|
|
|
8
8
|
ERRNO = 0
|
|
9
9
|
|
|
10
10
|
def self.define_error_class(prefix_re)
|
|
11
|
-
|
|
11
|
+
constants.each do |errname|
|
|
12
12
|
errname = errname.to_s
|
|
13
13
|
next unless errname =~ prefix_re
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
errno = const_get errname
|
|
16
|
+
excname = errname.sub(prefix_re, "").gsub(/(\A.|_.)([A-Z]+)/) { ::Regexp.last_match(1) + ::Regexp.last_match(2).downcase }.gsub(/_/, "")
|
|
16
17
|
klass = Class.new self
|
|
17
|
-
klass.const_set
|
|
18
|
-
|
|
18
|
+
klass.const_set "ERRNO", errno
|
|
19
|
+
const_set excname, klass
|
|
19
20
|
self::ERROR_MAP[errno] = klass
|
|
20
21
|
MysqlPR::Error.const_set errname, errno
|
|
21
22
|
end
|
|
@@ -23,7 +24,7 @@ class MysqlPR
|
|
|
23
24
|
|
|
24
25
|
attr_reader :sqlstate, :error
|
|
25
26
|
|
|
26
|
-
def initialize(message, sqlstate=
|
|
27
|
+
def initialize(message, sqlstate = "HY000")
|
|
27
28
|
@sqlstate = sqlstate
|
|
28
29
|
@error = message
|
|
29
30
|
super message
|
|
@@ -36,7 +37,7 @@ class MysqlPR
|
|
|
36
37
|
|
|
37
38
|
# server side error
|
|
38
39
|
class ServerError < Error
|
|
39
|
-
ERROR_MAP = {}
|
|
40
|
+
ERROR_MAP = {} # rubocop:disable Style/MutableConstant
|
|
40
41
|
|
|
41
42
|
ER_HASHCHK = 1000
|
|
42
43
|
ER_NISAMCHK = 1001
|
|
@@ -747,11 +748,11 @@ class MysqlPR
|
|
|
747
748
|
end
|
|
748
749
|
|
|
749
750
|
ServerError.define_error_class(/\AER_/)
|
|
750
|
-
ServerError::ERROR_MAP.
|
|
751
|
+
ServerError::ERROR_MAP.each_value { |v| MysqlPR.const_set v.name.split(/::/).last, v } # for compatibility
|
|
751
752
|
|
|
752
753
|
# client side error
|
|
753
754
|
class ClientError < Error
|
|
754
|
-
ERROR_MAP = {}
|
|
755
|
+
ERROR_MAP = {} # rubocop:disable Style/MutableConstant
|
|
755
756
|
|
|
756
757
|
CR_UNKNOWN_ERROR = 2000
|
|
757
758
|
CR_SOCKET_CREATE_ERROR = 2001
|
|
@@ -820,5 +821,4 @@ class MysqlPR
|
|
|
820
821
|
# protocol error
|
|
821
822
|
class ProtocolError < ClientError
|
|
822
823
|
end
|
|
823
|
-
|
|
824
824
|
end
|
data/lib/mysql-pr/packet.rb
CHANGED
|
@@ -7,15 +7,16 @@ class MysqlPR
|
|
|
7
7
|
def self.lcb(num)
|
|
8
8
|
return "\xfb".b if num.nil?
|
|
9
9
|
return [num].pack("C") if num < 251
|
|
10
|
-
return [252, num].pack("Cv") if num <
|
|
10
|
+
return [252, num].pack("Cv") if num < 65_536
|
|
11
11
|
return [253, num & 0xffff, num >> 16].pack("CvC") if num < 16_777_216
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
[254, num & 0xffffffff, num >> 32].pack("CVV")
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
# convert String to LengthCodedString
|
|
16
17
|
def self.lcs(str)
|
|
17
18
|
str = Charset.to_binary str
|
|
18
|
-
lcb(str.length)+str
|
|
19
|
+
lcb(str.length) + str
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def initialize(data)
|
|
@@ -24,25 +25,29 @@ class MysqlPR
|
|
|
24
25
|
|
|
25
26
|
def lcb
|
|
26
27
|
return nil if @data.empty?
|
|
28
|
+
|
|
27
29
|
case v = utiny
|
|
28
30
|
when 0xfb
|
|
29
|
-
|
|
31
|
+
nil
|
|
30
32
|
when 0xfc
|
|
31
|
-
|
|
33
|
+
ushort
|
|
32
34
|
when 0xfd
|
|
33
|
-
c
|
|
34
|
-
|
|
35
|
+
c = utiny
|
|
36
|
+
v = ushort
|
|
37
|
+
(v << 8) + c
|
|
35
38
|
when 0xfe
|
|
36
|
-
v1
|
|
37
|
-
|
|
39
|
+
v1 = ulong
|
|
40
|
+
v2 = ulong
|
|
41
|
+
(v2 << 32) + v1
|
|
38
42
|
else
|
|
39
|
-
|
|
43
|
+
v
|
|
40
44
|
end
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def lcs
|
|
44
|
-
len =
|
|
48
|
+
len = lcb
|
|
45
49
|
return nil unless len
|
|
50
|
+
|
|
46
51
|
@data.slice!(0, len)
|
|
47
52
|
end
|
|
48
53
|
|
|
@@ -51,21 +56,21 @@ class MysqlPR
|
|
|
51
56
|
end
|
|
52
57
|
|
|
53
58
|
def string
|
|
54
|
-
str = @data.
|
|
55
|
-
@data.slice!(0, str.length+1)
|
|
59
|
+
str = @data.unpack1("Z*")
|
|
60
|
+
@data.slice!(0, str.length + 1)
|
|
56
61
|
str
|
|
57
62
|
end
|
|
58
63
|
|
|
59
64
|
def utiny
|
|
60
|
-
@data.slice!(0, 1).
|
|
65
|
+
@data.slice!(0, 1).unpack1("C")
|
|
61
66
|
end
|
|
62
67
|
|
|
63
68
|
def ushort
|
|
64
|
-
@data.slice!(0, 2).
|
|
69
|
+
@data.slice!(0, 2).unpack1("v")
|
|
65
70
|
end
|
|
66
71
|
|
|
67
72
|
def ulong
|
|
68
|
-
@data.slice!(0, 4).
|
|
73
|
+
@data.slice!(0, 4).unpack1("V")
|
|
69
74
|
end
|
|
70
75
|
|
|
71
76
|
def eof?
|
|
@@ -75,6 +80,5 @@ class MysqlPR
|
|
|
75
80
|
def to_s
|
|
76
81
|
@data
|
|
77
82
|
end
|
|
78
|
-
|
|
79
83
|
end
|
|
80
84
|
end
|