Skip to content

Commit 17bc4c4

Browse files
committed
Update support scripts
Port new mappings from latest master and rebuild mysql_enc_to_ruby.h using Mysql8.
1 parent 4dd1348 commit 17bc4c4

File tree

3 files changed

+115
-28
lines changed

3 files changed

+115
-28
lines changed

ext/mysql2/mysql_enc_to_ruby.h

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const char *mysql2_mysql_enc_to_rb[] = {
3131
"ISO-8859-9",
3232
"UTF-8",
3333
NULL,
34-
"UTF-8",
34+
NULL,
3535
"Windows-1250",
3636
"UTF-16BE",
3737
"IBM866",
@@ -54,13 +54,13 @@ const char *mysql2_mysql_enc_to_rb[] = {
5454
"macRoman",
5555
"UTF-16",
5656
"UTF-16",
57-
NULL,
57+
"UTF-16LE",
5858
"Windows-1256",
5959
"Windows-1257",
6060
"Windows-1257",
6161
"UTF-32",
6262
"UTF-32",
63-
NULL,
63+
"UTF-16LE",
6464
"ASCII-8BIT",
6565
NULL,
6666
"US-ASCII",
@@ -81,7 +81,7 @@ const char *mysql2_mysql_enc_to_rb[] = {
8181
"CP850",
8282
"CP852",
8383
NULL,
84-
"UTF-8",
84+
NULL,
8585
"Big5",
8686
"EUC-KR",
8787
"GB2312",
@@ -119,10 +119,10 @@ const char *mysql2_mysql_enc_to_rb[] = {
119119
"UTF-16",
120120
"UTF-16",
121121
"UTF-16",
122-
NULL,
123-
NULL,
124-
NULL,
125-
NULL,
122+
"UTF-16",
123+
"UTF-16",
124+
"UTF-16",
125+
"UTF-16",
126126
NULL,
127127
NULL,
128128
NULL,
@@ -146,18 +146,21 @@ const char *mysql2_mysql_enc_to_rb[] = {
146146
"UTF-16BE",
147147
"UTF-16BE",
148148
"UTF-16BE",
149+
"UTF-16BE",
150+
"UTF-16BE",
151+
"UTF-16BE",
152+
"UTF-16BE",
149153
NULL,
150154
NULL,
151155
NULL,
152156
NULL,
153157
NULL,
154158
NULL,
155159
NULL,
156-
NULL,
157-
NULL,
158-
NULL,
159-
NULL,
160-
NULL,
160+
"UTF-16BE",
161+
"UTF-32",
162+
"UTF-32",
163+
"UTF-32",
161164
"UTF-32",
162165
"UTF-32",
163166
"UTF-32",
@@ -178,6 +181,35 @@ const char *mysql2_mysql_enc_to_rb[] = {
178181
"UTF-32",
179182
"UTF-32",
180183
"UTF-32",
184+
"UTF-32",
185+
NULL,
186+
NULL,
187+
NULL,
188+
NULL,
189+
NULL,
190+
NULL,
191+
NULL,
192+
NULL,
193+
NULL,
194+
NULL,
195+
NULL,
196+
NULL,
197+
NULL,
198+
NULL,
199+
NULL,
200+
NULL,
201+
NULL,
202+
NULL,
203+
NULL,
204+
NULL,
205+
NULL,
206+
NULL,
207+
NULL,
208+
NULL,
209+
NULL,
210+
NULL,
211+
NULL,
212+
NULL,
181213
NULL,
182214
NULL,
183215
NULL,
@@ -210,18 +242,66 @@ const char *mysql2_mysql_enc_to_rb[] = {
210242
"UTF-8",
211243
"UTF-8",
212244
"UTF-8",
245+
"UTF-8",
246+
"UTF-8",
247+
"UTF-8",
248+
"UTF-8",
249+
"GB18030",
250+
"GB18030",
251+
"GB18030",
213252
NULL,
214253
NULL,
215254
NULL,
216255
NULL,
256+
"UTF-8",
257+
"UTF-8",
258+
"UTF-8",
259+
"UTF-8",
260+
"UTF-8",
261+
"UTF-8",
262+
"UTF-8",
263+
"UTF-8",
264+
"UTF-8",
265+
"UTF-8",
266+
"UTF-8",
267+
"UTF-8",
268+
"UTF-8",
269+
"UTF-8",
270+
"UTF-8",
271+
"UTF-8",
272+
"UTF-8",
217273
NULL,
274+
"UTF-8",
275+
"UTF-8",
276+
"UTF-8",
218277
NULL,
278+
"UTF-8",
279+
"UTF-8",
280+
"UTF-8",
281+
"UTF-8",
282+
"UTF-8",
283+
"UTF-8",
284+
"UTF-8",
285+
"UTF-8",
286+
"UTF-8",
287+
"UTF-8",
288+
"UTF-8",
289+
"UTF-8",
290+
"UTF-8",
291+
"UTF-8",
292+
"UTF-8",
293+
"UTF-8",
294+
"UTF-8",
295+
"UTF-8",
219296
NULL,
297+
"UTF-8",
298+
"UTF-8",
299+
"UTF-8",
220300
NULL,
301+
"UTF-8",
221302
NULL,
222303
NULL,
223-
NULL,
224-
NULL,
304+
"UTF-8",
225305
"UTF-8",
226306
"UTF-8",
227307
"UTF-8",

support/mysql_enc_to_ruby.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"binary" => "ASCII-8BIT",
4343
"geostd8" => "NULL",
4444
"cp932" => "Windows-31J",
45-
"eucjpms" => "eucJP-ms"
45+
"eucjpms" => "eucJP-ms",
46+
"utf16le" => "UTF-16LE",
47+
"gb18030" => "GB18030",
4648
}
4749

4850
client = Mysql2::Client.new(:username => user, :password => pass, :host => host, :port => port.to_i)
@@ -52,8 +54,11 @@
5254

5355
collations.each do |collation|
5456
mysql_col_idx = collation[2].to_i
55-
rb_enc = mysql_to_rb[collation[1]]
56-
encodings[mysql_col_idx-1] = [mysql_col_idx, rb_enc]
57+
rb_enc = mysql_to_rb.fetch(collation[1]) do |mysql_enc|
58+
warn "WARNING: Missing mapping for collation \"#{collation[0]}\" with encoding \"#{mysql_enc}\" and id #{mysql_col_idx}, assuming NULL"
59+
"NULL"
60+
end
61+
encodings[mysql_col_idx - 1] = [mysql_col_idx, rb_enc]
5762
end
5863

5964
encodings.each_with_index do |encoding, idx|
@@ -65,10 +70,10 @@
6570
end
6671

6772
encodings_with_nil = encodings_with_nil.map do |encoding|
68-
name = "NULL"
69-
70-
if !encoding.nil? && encoding[1] != "NULL"
71-
name = "\"#{encoding[1]}\""
73+
name = if encoding.nil? || encoding[1] == 'NULL'
74+
'NULL'
75+
else
76+
"\"#{encoding[1]}\""
7277
end
7378

7479
" #{name}"

support/ruby_enc_to_mysql.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,26 @@
3737
"binary" => "ASCII-8BIT",
3838
"geostd8" => nil,
3939
"cp932" => "Windows-31J",
40-
"eucjpms" => "eucJP-ms"
40+
"eucjpms" => "eucJP-ms",
41+
"utf16le" => "UTF-16LE",
42+
"gb18030" => "GB18030",
4143
}
4244

43-
puts <<-header
45+
puts <<-HEADER
4446
%readonly-tables
4547
%enum
4648
%define lookup-function-name mysql2_mysql_enc_name_to_rb
4749
%define hash-function-name mysql2_mysql_enc_name_to_rb_hash
4850
%struct-type
4951
struct mysql2_mysql_enc_name_to_rb_map { const char *name; const char *rb_name; }
5052
%%
51-
header
53+
HEADER
5254

5355
mysql_to_rb.each do |mysql, ruby|
54-
if ruby.nil?
55-
name = "NULL"
56+
name = if ruby.nil?
57+
"NULL"
5658
else
57-
name = "\"#{ruby}\""
59+
"\"#{ruby}\""
5860
end
5961

6062
puts "#{mysql}, #{name}"

0 commit comments

Comments
 (0)