Skip to content

Commit

Permalink
Update support scripts
Browse files Browse the repository at this point in the history
Port new mappings from latest master and rebuild mysql_enc_to_ruby.h
using Mysql8.
  • Loading branch information
intrip committed Aug 1, 2023
1 parent 4dd1348 commit 17bc4c4
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 28 deletions.
110 changes: 95 additions & 15 deletions ext/mysql2/mysql_enc_to_ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const char *mysql2_mysql_enc_to_rb[] = {
"ISO-8859-9",
"UTF-8",
NULL,
"UTF-8",
NULL,
"Windows-1250",
"UTF-16BE",
"IBM866",
Expand All @@ -54,13 +54,13 @@ const char *mysql2_mysql_enc_to_rb[] = {
"macRoman",
"UTF-16",
"UTF-16",
NULL,
"UTF-16LE",
"Windows-1256",
"Windows-1257",
"Windows-1257",
"UTF-32",
"UTF-32",
NULL,
"UTF-16LE",
"ASCII-8BIT",
NULL,
"US-ASCII",
Expand All @@ -81,7 +81,7 @@ const char *mysql2_mysql_enc_to_rb[] = {
"CP850",
"CP852",
NULL,
"UTF-8",
NULL,
"Big5",
"EUC-KR",
"GB2312",
Expand Down Expand Up @@ -119,10 +119,10 @@ const char *mysql2_mysql_enc_to_rb[] = {
"UTF-16",
"UTF-16",
"UTF-16",
NULL,
NULL,
NULL,
NULL,
"UTF-16",
"UTF-16",
"UTF-16",
"UTF-16",
NULL,
NULL,
NULL,
Expand All @@ -146,18 +146,21 @@ const char *mysql2_mysql_enc_to_rb[] = {
"UTF-16BE",
"UTF-16BE",
"UTF-16BE",
"UTF-16BE",
"UTF-16BE",
"UTF-16BE",
"UTF-16BE",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
"UTF-16BE",
"UTF-32",
"UTF-32",
"UTF-32",
"UTF-32",
"UTF-32",
"UTF-32",
Expand All @@ -178,6 +181,35 @@ const char *mysql2_mysql_enc_to_rb[] = {
"UTF-32",
"UTF-32",
"UTF-32",
"UTF-32",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Expand Down Expand Up @@ -210,18 +242,66 @@ const char *mysql2_mysql_enc_to_rb[] = {
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"GB18030",
"GB18030",
"GB18030",
NULL,
NULL,
NULL,
NULL,
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
NULL,
"UTF-8",
"UTF-8",
"UTF-8",
NULL,
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
NULL,
"UTF-8",
"UTF-8",
"UTF-8",
NULL,
"UTF-8",
NULL,
NULL,
NULL,
NULL,
"UTF-8",
"UTF-8",
"UTF-8",
"UTF-8",
Expand Down
19 changes: 12 additions & 7 deletions support/mysql_enc_to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"binary" => "ASCII-8BIT",
"geostd8" => "NULL",
"cp932" => "Windows-31J",
"eucjpms" => "eucJP-ms"
"eucjpms" => "eucJP-ms",
"utf16le" => "UTF-16LE",
"gb18030" => "GB18030",
}

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

collations.each do |collation|
mysql_col_idx = collation[2].to_i
rb_enc = mysql_to_rb[collation[1]]
encodings[mysql_col_idx-1] = [mysql_col_idx, rb_enc]
rb_enc = mysql_to_rb.fetch(collation[1]) do |mysql_enc|
warn "WARNING: Missing mapping for collation \"#{collation[0]}\" with encoding \"#{mysql_enc}\" and id #{mysql_col_idx}, assuming NULL"
"NULL"
end
encodings[mysql_col_idx - 1] = [mysql_col_idx, rb_enc]
end

encodings.each_with_index do |encoding, idx|
Expand All @@ -65,10 +70,10 @@
end

encodings_with_nil = encodings_with_nil.map do |encoding|
name = "NULL"

if !encoding.nil? && encoding[1] != "NULL"
name = "\"#{encoding[1]}\""
name = if encoding.nil? || encoding[1] == 'NULL'
'NULL'
else
"\"#{encoding[1]}\""
end

" #{name}"
Expand Down
14 changes: 8 additions & 6 deletions support/ruby_enc_to_mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,26 @@
"binary" => "ASCII-8BIT",
"geostd8" => nil,
"cp932" => "Windows-31J",
"eucjpms" => "eucJP-ms"
"eucjpms" => "eucJP-ms",
"utf16le" => "UTF-16LE",
"gb18030" => "GB18030",
}

puts <<-header
puts <<-HEADER
%readonly-tables
%enum
%define lookup-function-name mysql2_mysql_enc_name_to_rb
%define hash-function-name mysql2_mysql_enc_name_to_rb_hash
%struct-type
struct mysql2_mysql_enc_name_to_rb_map { const char *name; const char *rb_name; }
%%
header
HEADER

mysql_to_rb.each do |mysql, ruby|
if ruby.nil?
name = "NULL"
name = if ruby.nil?
"NULL"
else
name = "\"#{ruby}\""
"\"#{ruby}\""
end

puts "#{mysql}, #{name}"
Expand Down

0 comments on commit 17bc4c4

Please sign in to comment.