From e8ab897fcab3018641935c9923fb7b0be4594f2c Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 24 Jun 2013 20:56:30 +0200 Subject: [PATCH] MDEV-4617 PLUGINS - Show internal Locales in I_S INFORMATION_SCHEMA.LOCALES plugin. Contribution by Roberto Spadim --- mysql-test/suite/plugins/r/locales.result | 112 ++++++++++++++++++++ mysql-test/suite/plugins/t/locales.opt | 3 + mysql-test/suite/plugins/t/locales.test | 7 ++ mysql-test/t/mysqld--help.test | 2 +- plugin/locale_info/CMakeLists.txt | 5 + plugin/locale_info/locale_info.cc | 122 ++++++++++++++++++++++ 6 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/plugins/r/locales.result create mode 100644 mysql-test/suite/plugins/t/locales.opt create mode 100644 mysql-test/suite/plugins/t/locales.test create mode 100644 plugin/locale_info/CMakeLists.txt create mode 100644 plugin/locale_info/locale_info.cc diff --git a/mysql-test/suite/plugins/r/locales.result b/mysql-test/suite/plugins/r/locales.result new file mode 100644 index 00000000000..45f80353697 --- /dev/null +++ b/mysql-test/suite/plugins/r/locales.result @@ -0,0 +1,112 @@ +select * from information_schema.locales; +ID NAME DESCRIPTION MAX_MONTH_NAME_LENGTH MAX_DAY_NAME_LENGTH DECIMAL_POINT THOUSAND_SEP ERROR_MESSAGE_LANGUAGE +0 en_US English - United States 9 9 . , english +1 en_GB English - United Kingdom 9 9 . , english +2 ja_JP Japanese - Japan 3 3 . , japanese +3 sv_SE Swedish - Sweden 9 7 , swedish +4 de_DE German - Germany 9 10 , . german +5 fr_FR French - France 9 8 , french +6 ar_AE Arabic - United Arab Emirates 6 8 . , english +7 ar_BH Arabic - Bahrain 6 8 . , english +8 ar_JO Arabic - Jordan 12 8 . , english +9 ar_SA Arabic - Saudi Arabia 12 8 . english +10 ar_SY Arabic - Syria 12 8 . , english +11 be_BY Belarusian - Belarus 10 10 , . english +12 bg_BG Bulgarian - Bulgaria 9 10 , english +13 ca_ES Catalan - Catalan 8 9 , english +14 cs_CZ Czech - Czech Republic 8 7 , czech +15 da_DK Danish - Denmark 9 7 , . danish +16 de_AT German - Austria 9 10 , german +17 es_ES Spanish - Spain 10 9 , spanish +18 et_EE Estonian - Estonia 9 9 , estonian +19 eu_ES Basque - Basque 9 10 , english +20 fi_FI Finnish - Finland 9 11 , english +21 fo_FO Faroese - Faroe Islands 9 12 , . english +22 gl_ES Galician - Galician 8 8 , english +23 gu_IN Gujarati - India 10 8 . , english +24 he_IL Hebrew - Israel 7 5 . , english +25 hi_IN Hindi - India 7 9 . , english +26 hr_HR Croatian - Croatia 8 11 , english +27 hu_HU Hungarian - Hungary 10 9 , . hungarian +28 id_ID Indonesian - Indonesia 9 6 , . english +29 is_IS Icelandic - Iceland 9 12 , . english +30 it_CH Italian - Switzerland 9 9 , ' italian +31 ko_KR Korean - Korea 3 3 . , korean +32 lt_LT Lithuanian - Lithuania 9 14 , . english +33 lv_LV Latvian - Latvia 10 11 , english +34 mk_MK Macedonian - FYROM 9 10 , english +35 mn_MN Mongolia - Mongolian 18 6 , . english +36 ms_MY Malay - Malaysia 9 6 . , english +37 nb_NO Norwegian(Bokml) - Norway 9 7 , . norwegian +38 nl_NL Dutch - The Netherlands 9 9 , dutch +39 pl_PL Polish - Poland 11 12 , polish +40 pt_BR Portugese - Brazil 9 7 , portuguese +41 pt_PT Portugese - Portugal 9 7 , portuguese +42 ro_RO Romanian - Romania 10 8 , . romanian +43 ru_RU Russian - Russia 8 11 , russian +44 ru_UA Russian - Ukraine 8 11 , . russian +45 sk_SK Slovak - Slovakia 9 8 , slovak +46 sl_SI Slovenian - Slovenia 9 10 , english +47 sq_AL Albanian - Albania 7 10 , . english +48 sr_RS Serbian - Serbia 9 10 . serbian +49 ta_IN Tamil - India 10 8 . , english +50 te_IN Telugu - India 10 9 . , english +51 th_TH Thai - Thailand 10 8 . , english +52 tr_TR Turkish - Turkey 7 9 , . english +53 uk_UA Ukrainian - Ukraine 8 9 , . ukrainian +54 ur_PK Urdu - Pakistan 6 6 . , english +55 vi_VN Vietnamese - Vietnam 16 11 , . english +56 zh_CN Chinese - Peoples Republic of China 3 3 . , english +57 zh_TW Chinese - Taiwan 3 2 . , english +58 ar_DZ Arabic - Algeria 6 8 . , english +59 ar_EG Arabic - Egypt 6 8 . , english +60 ar_IN Arabic - Iran 6 8 . , english +61 ar_IQ Arabic - Iraq 6 8 . , english +62 ar_KW Arabic - Kuwait 6 8 . , english +63 ar_LB Arabic - Lebanon 12 8 . , english +64 ar_LY Arabic - Libya 6 8 . , english +65 ar_MA Arabic - Morocco 6 8 . , english +66 ar_OM Arabic - Oman 6 8 . , english +67 ar_QA Arabic - Qatar 6 8 . , english +68 ar_SD Arabic - Sudan 6 8 . , english +69 ar_TN Arabic - Tunisia 6 8 . , english +70 ar_YE Arabic - Yemen 6 8 . , english +71 de_BE German - Belgium 9 10 , . german +72 de_CH German - Switzerland 9 10 . ' german +73 de_LU German - Luxembourg 9 10 , . german +74 en_AU English - Australia 9 9 . , english +75 en_CA English - Canada 9 9 . , english +76 en_IN English - India 9 9 . , english +77 en_NZ English - New Zealand 9 9 . , english +78 en_PH English - Philippines 9 9 . , english +79 en_ZA English - South Africa 9 9 . , english +80 en_ZW English - Zimbabwe 9 9 . , english +81 es_AR Spanish - Argentina 10 9 , . spanish +82 es_BO Spanish - Bolivia 10 9 , spanish +83 es_CL Spanish - Chile 10 9 , spanish +84 es_CO Spanish - Columbia 10 9 , spanish +85 es_CR Spanish - Costa Rica 10 9 . spanish +86 es_DO Spanish - Dominican Republic 10 9 . spanish +87 es_EC Spanish - Ecuador 10 9 , spanish +88 es_GT Spanish - Guatemala 10 9 . spanish +89 es_HN Spanish - Honduras 10 9 . spanish +90 es_MX Spanish - Mexico 10 9 . spanish +91 es_NI Spanish - Nicaragua 10 9 . spanish +92 es_PA Spanish - Panama 10 9 . spanish +93 es_PE Spanish - Peru 10 9 . spanish +94 es_PR Spanish - Puerto Rico 10 9 . spanish +95 es_PY Spanish - Paraguay 10 9 , spanish +96 es_SV Spanish - El Salvador 10 9 . spanish +97 es_US Spanish - United States 10 9 . , spanish +98 es_UY Spanish - Uruguay 10 9 , spanish +99 es_VE Spanish - Venezuela 10 9 , spanish +100 fr_BE French - Belgium 9 8 , . french +101 fr_CA French - Canada 9 8 , french +102 fr_CH French - Switzerland 9 8 , french +103 fr_LU French - Luxembourg 9 8 , french +104 it_IT Italian - Italy 9 9 , italian +105 nl_BE Dutch - Belgium 9 9 , . dutch +106 no_NO Norwegian - Norway 9 7 , . norwegian +107 sv_FI Swedish - Finland 9 7 , swedish +108 zh_HK Chinese - Hong Kong SAR 3 3 . , english +109 el_GR Greek - Greece 11 9 , . greek diff --git a/mysql-test/suite/plugins/t/locales.opt b/mysql-test/suite/plugins/t/locales.opt new file mode 100644 index 00000000000..594283f8c65 --- /dev/null +++ b/mysql-test/suite/plugins/t/locales.opt @@ -0,0 +1,3 @@ +--loose-locale +--plugin-load=$LOCALES_SO + diff --git a/mysql-test/suite/plugins/t/locales.test b/mysql-test/suite/plugins/t/locales.test new file mode 100644 index 00000000000..5cfbe697384 --- /dev/null +++ b/mysql-test/suite/plugins/t/locales.test @@ -0,0 +1,7 @@ +if (`select count(*) = 0 from information_schema.plugins where plugin_name = 'locales' and plugin_status='active'`) +{ + --skip LOCALES plugin is not active +} + +select * from information_schema.locales; + diff --git a/mysql-test/t/mysqld--help.test b/mysql-test/t/mysqld--help.test index 9e24443151d..571a097c3f7 100644 --- a/mysql-test/t/mysqld--help.test +++ b/mysql-test/t/mysqld--help.test @@ -28,7 +28,7 @@ perl; thread-concurrency super-large-pages mutex-deadlock-detector null-audit aria pbxt oqgraph sphinx thread-handling test-sql-discovery rpl-semi-sync query-cache-info - query-response-time/; + query-response-time locales/; # And substitute the content some environment variables with their # names: diff --git a/plugin/locale_info/CMakeLists.txt b/plugin/locale_info/CMakeLists.txt new file mode 100644 index 00000000000..1ace6619041 --- /dev/null +++ b/plugin/locale_info/CMakeLists.txt @@ -0,0 +1,5 @@ +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/regex + ${CMAKE_SOURCE_DIR}/extra/yassl/include) + +MYSQL_ADD_PLUGIN(LOCALES locale_info.cc) + diff --git a/plugin/locale_info/locale_info.cc b/plugin/locale_info/locale_info.cc new file mode 100644 index 00000000000..f88c9eb9f6b --- /dev/null +++ b/plugin/locale_info/locale_info.cc @@ -0,0 +1,122 @@ +/* + Copyright (c) 2013, Spaempresarial - Brazil, Roberto Spadim + http://www.spadim.com.br/ + roberto@spadim.com.br + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Roberto Spadim nor the + names of the contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL ROBERTO SPADIM BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include // THD +#include // ST_SCHEMA_TABLE +#include +#include +#include "sql_locale.h" + +bool schema_table_store_record(THD *thd, TABLE *table); +static MY_LOCALE **locale_list; + +/* LOCALES */ +static ST_FIELD_INFO locale_info_locale_fields_info[]= +{ + {"ID", 4, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, + {"NAME", 255, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"DESCRIPTION", 255, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"MAX_MONTH_NAME_LENGTH", 4, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, + {"MAX_DAY_NAME_LENGTH", 4, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, + {"DECIMAL_POINT", 2, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"THOUSAND_SEP", 2, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"ERROR_MESSAGE_LANGUAGE", 64, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; +static int locale_info_fill_table_locale(THD* thd, TABLE_LIST* tables, COND* cond) +{ + TABLE *table= tables->table; + CHARSET_INFO *cs= system_charset_info; + + for (MY_LOCALE **loc= locale_list; *loc; loc++) + { + /* ID */ + table->field[0]->store((longlong) (*loc)->number, TRUE); + /* NAME */ + table->field[1]->store((*loc)->name, strlen((*loc)->name), cs); + /* DESCRIPTION */ + table->field[2]->store((*loc)->description, strlen((*loc)->description), cs); + /* MAX_MONTH_NAME_LENGTH */ + table->field[3]->store((longlong) (*loc)->max_month_name_length, TRUE); + /* MAX_DAY_NAME_LENGTH */ + table->field[4]->store((longlong) (*loc)->max_day_name_length, TRUE); + /* DECIMAL_POINT */ + char decimal= (*loc)->decimal_point; + table->field[5]->store(&decimal, decimal ? 1 : 0, cs); + /* THOUSAND_SEP */ + char thousand= (*loc)->thousand_sep; + table->field[6]->store(&thousand, thousand ? 1 : 0, cs); + /* ERROR_MESSAGE_LANGUAGE */ + table->field[7]->store((*loc)->errmsgs->language, + strlen((*loc)->errmsgs->language), cs); + if (schema_table_store_record(thd, table)) + return 1; + } + return 0; +} + +static int locale_info_plugin_init_locales(void *p) +{ + ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; + schema->fields_info= locale_info_locale_fields_info; + schema->fill_table= locale_info_fill_table_locale; + +#if defined(_WIN64) + locale_list = (MY_LOCALE **)GetProcAddress(GetModuleHandle(NULL), "?my_locales@@3PAPEAVMY_LOCALE@@A"); +#elif defined(_WIN32) + locale_list = (MY_LOCALE **)GetProcAddress(GetModuleHandle(NULL), "?my_locales@@3PAPAVMY_LOCALE@@A"); +#else + locale_list = my_locales; +#endif + + return 0; +} +static struct st_mysql_information_schema locale_info_plugin= +{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; + +/* + Plugin library descriptor +*/ + +maria_declare_plugin(locales) +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, /* the plugin type (see include/mysql/plugin.h) */ + &locale_info_plugin, /* pointer to type-specific plugin descriptor */ + "LOCALES", /* plugin name */ + "Roberto Spadim, Spaempresarial - Brazil", /* plugin author */ + "Lists all locales from server.", /* the plugin description */ + PLUGIN_LICENSE_BSD, /* the plugin license (see include/mysql/plugin.h) */ + locale_info_plugin_init_locales, /* Pointer to plugin initialization function */ + 0, /* Pointer to plugin deinitialization function */ + 0x0100, /* Numeric version 0xAABB means AA.BB veriosn */ + NULL, /* Status variables */ + NULL, /* System variables */ + "1.0", /* String version representation */ + MariaDB_PLUGIN_MATURITY_ALPHA /* Maturity (see include/mysql/plugin.h)*/ +} +maria_declare_plugin_end;