| 1 | /* |
| 2 | Copyright (c) 2013, Spaempresarial - Brazil, Roberto Spadim |
| 3 | http://www.spadim.com.br/ |
| 4 | roberto@spadim.com.br |
| 5 | |
| 6 | Redistribution and use in source and binary forms, with or without |
| 7 | modification, are permitted provided that the following conditions are met: |
| 8 | * Redistributions of source code must retain the above copyright |
| 9 | notice, this list of conditions and the following disclaimer. |
| 10 | * Redistributions in binary form must reproduce the above copyright |
| 11 | notice, this list of conditions and the following disclaimer in the |
| 12 | documentation and/or other materials provided with the distribution. |
| 13 | * Neither the name of the Roberto Spadim nor the |
| 14 | names of the contributors may be used to endorse or promote products |
| 15 | derived from this software without specific prior written permission. |
| 16 | |
| 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | DISCLAIMED. IN NO EVENT SHALL ROBERTO SPADIM BE LIABLE FOR ANY |
| 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <my_global.h> |
| 30 | #include <sql_class.h> // THD |
| 31 | #include <table.h> // ST_SCHEMA_TABLE |
| 32 | #include <mysql/plugin.h> |
| 33 | #include <m_ctype.h> |
| 34 | #include "sql_locale.h" |
| 35 | |
| 36 | bool schema_table_store_record(THD *thd, TABLE *table); |
| 37 | static MY_LOCALE **locale_list; |
| 38 | |
| 39 | /* LOCALES */ |
| 40 | static ST_FIELD_INFO locale_info_locale_fields_info[]= |
| 41 | { |
| 42 | {"ID" , 4, MYSQL_TYPE_LONGLONG, 0, 0, "Id" , 0}, |
| 43 | {"NAME" , 255, MYSQL_TYPE_STRING, 0, 0, "Name" , 0}, |
| 44 | {"DESCRIPTION" , 255, MYSQL_TYPE_STRING, 0, 0, "Description" , 0}, |
| 45 | {"MAX_MONTH_NAME_LENGTH" , 4, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, |
| 46 | {"MAX_DAY_NAME_LENGTH" , 4, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, |
| 47 | {"DECIMAL_POINT" , 2, MYSQL_TYPE_STRING, 0, 0, 0, 0}, |
| 48 | {"THOUSAND_SEP" , 2, MYSQL_TYPE_STRING, 0, 0, 0, 0}, |
| 49 | {"ERROR_MESSAGE_LANGUAGE" , 64, MYSQL_TYPE_STRING, 0, 0, "Error_Message_Language" , 0}, |
| 50 | {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} |
| 51 | }; |
| 52 | static int locale_info_fill_table_locale(THD* thd, TABLE_LIST* tables, COND* cond) |
| 53 | { |
| 54 | TABLE *table= tables->table; |
| 55 | CHARSET_INFO *cs= system_charset_info; |
| 56 | |
| 57 | for (MY_LOCALE **loc= locale_list; *loc; loc++) |
| 58 | { |
| 59 | /* ID */ |
| 60 | table->field[0]->store((longlong) (*loc)->number, TRUE); |
| 61 | /* NAME */ |
| 62 | table->field[1]->store((*loc)->name, strlen((*loc)->name), cs); |
| 63 | /* DESCRIPTION */ |
| 64 | table->field[2]->store((*loc)->description, strlen((*loc)->description), cs); |
| 65 | /* MAX_MONTH_NAME_LENGTH */ |
| 66 | table->field[3]->store((longlong) (*loc)->max_month_name_length, TRUE); |
| 67 | /* MAX_DAY_NAME_LENGTH */ |
| 68 | table->field[4]->store((longlong) (*loc)->max_day_name_length, TRUE); |
| 69 | /* DECIMAL_POINT */ |
| 70 | char decimal= (*loc)->decimal_point; |
| 71 | table->field[5]->store(&decimal, decimal ? 1 : 0, cs); |
| 72 | /* THOUSAND_SEP */ |
| 73 | char thousand= (*loc)->thousand_sep; |
| 74 | table->field[6]->store(&thousand, thousand ? 1 : 0, cs); |
| 75 | /* ERROR_MESSAGE_LANGUAGE */ |
| 76 | table->field[7]->store((*loc)->errmsgs->language, |
| 77 | strlen((*loc)->errmsgs->language), cs); |
| 78 | if (schema_table_store_record(thd, table)) |
| 79 | return 1; |
| 80 | } |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int locale_info_plugin_init_locales(void *p) |
| 85 | { |
| 86 | ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; |
| 87 | schema->fields_info= locale_info_locale_fields_info; |
| 88 | schema->fill_table= locale_info_fill_table_locale; |
| 89 | |
| 90 | #if defined(_WIN64) |
| 91 | locale_list = (MY_LOCALE **)GetProcAddress(GetModuleHandle(NULL), "?my_locales@@3PAPEAVMY_LOCALE@@A" ); |
| 92 | #elif defined(_WIN32) |
| 93 | locale_list = (MY_LOCALE **)GetProcAddress(GetModuleHandle(NULL), "?my_locales@@3PAPAVMY_LOCALE@@A" ); |
| 94 | #else |
| 95 | locale_list = my_locales; |
| 96 | #endif |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | static struct st_mysql_information_schema locale_info_plugin= |
| 101 | { MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; |
| 102 | |
| 103 | /* |
| 104 | Plugin library descriptor |
| 105 | */ |
| 106 | |
| 107 | maria_declare_plugin(locales) |
| 108 | { |
| 109 | MYSQL_INFORMATION_SCHEMA_PLUGIN, /* the plugin type (see include/mysql/plugin.h) */ |
| 110 | &locale_info_plugin, /* pointer to type-specific plugin descriptor */ |
| 111 | "LOCALES" , /* plugin name */ |
| 112 | "Roberto Spadim, Spaempresarial - Brazil" , /* plugin author */ |
| 113 | "Lists all locales from server." , /* the plugin description */ |
| 114 | PLUGIN_LICENSE_BSD, /* the plugin license (see include/mysql/plugin.h) */ |
| 115 | locale_info_plugin_init_locales, /* Pointer to plugin initialization function */ |
| 116 | 0, /* Pointer to plugin deinitialization function */ |
| 117 | 0x0100, /* Numeric version 0xAABB means AA.BB veriosn */ |
| 118 | NULL, /* Status variables */ |
| 119 | NULL, /* System variables */ |
| 120 | "1.0" , /* String version representation */ |
| 121 | MariaDB_PLUGIN_MATURITY_STABLE /* Maturity (see include/mysql/plugin.h)*/ |
| 122 | } |
| 123 | maria_declare_plugin_end; |
| 124 | |