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 <sql_i_s.h> // ST_SCHEMA_TABLE
32 #include <mysql/plugin.h>
33 #include <m_ctype.h>
34 #include "sql_locale.h"
35
36 static MY_LOCALE **locale_list;
37
38 namespace Show {
39
40 /* LOCALES */
41 static ST_FIELD_INFO locale_info_locale_fields_info[]=
42 {
43 Column("ID", SLonglong(4), NOT_NULL, "Id"),
44 Column("NAME", Varchar(255), NOT_NULL, "Name"),
45 Column("DESCRIPTION", Varchar(255), NOT_NULL, "Description"),
46 Column("MAX_MONTH_NAME_LENGTH", SLonglong(4), NOT_NULL),
47 Column("MAX_DAY_NAME_LENGTH", SLonglong(4), NOT_NULL),
48 Column("DECIMAL_POINT", Varchar(2), NOT_NULL),
49 Column("THOUSAND_SEP", Varchar(2), NOT_NULL),
50 Column("ERROR_MESSAGE_LANGUAGE", Varchar(64), NOT_NULL, "Error_Message_Language"),
51 CEnd()
52 };
53
54 } // namespace Show
55
locale_info_fill_table_locale(THD * thd,TABLE_LIST * tables,COND * cond)56 static int locale_info_fill_table_locale(THD* thd, TABLE_LIST* tables, COND* cond)
57 {
58 TABLE *table= tables->table;
59 CHARSET_INFO *cs= system_charset_info;
60
61 for (MY_LOCALE **loc= locale_list; *loc; loc++)
62 {
63 /* ID */
64 table->field[0]->store((longlong) (*loc)->number, TRUE);
65 /* NAME */
66 table->field[1]->store((*loc)->name, strlen((*loc)->name), cs);
67 /* DESCRIPTION */
68 table->field[2]->store((*loc)->description, strlen((*loc)->description), cs);
69 /* MAX_MONTH_NAME_LENGTH */
70 table->field[3]->store((longlong) (*loc)->max_month_name_length, TRUE);
71 /* MAX_DAY_NAME_LENGTH */
72 table->field[4]->store((longlong) (*loc)->max_day_name_length, TRUE);
73 /* DECIMAL_POINT */
74 char decimal= (*loc)->decimal_point;
75 table->field[5]->store(&decimal, decimal ? 1 : 0, cs);
76 /* THOUSAND_SEP */
77 char thousand= (*loc)->thousand_sep;
78 table->field[6]->store(&thousand, thousand ? 1 : 0, cs);
79 /* ERROR_MESSAGE_LANGUAGE */
80 table->field[7]->store((*loc)->errmsgs->language,
81 strlen((*loc)->errmsgs->language), cs);
82 if (schema_table_store_record(thd, table))
83 return 1;
84 }
85 return 0;
86 }
87
locale_info_plugin_init_locales(void * p)88 static int locale_info_plugin_init_locales(void *p)
89 {
90 ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p;
91 schema->fields_info= Show::locale_info_locale_fields_info;
92 schema->fill_table= locale_info_fill_table_locale;
93
94 locale_list = my_locales;
95
96 return 0;
97 }
98 static struct st_mysql_information_schema locale_info_plugin=
99 { MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
100
101 /*
102 Plugin library descriptor
103 */
104
maria_declare_plugin(locales)105 maria_declare_plugin(locales)
106 {
107 MYSQL_INFORMATION_SCHEMA_PLUGIN, /* the plugin type (see include/mysql/plugin.h) */
108 &locale_info_plugin, /* pointer to type-specific plugin descriptor */
109 "LOCALES", /* plugin name */
110 "Roberto Spadim, Spaempresarial - Brazil", /* plugin author */
111 "Lists all locales from server.", /* the plugin description */
112 PLUGIN_LICENSE_BSD, /* the plugin license (see include/mysql/plugin.h) */
113 locale_info_plugin_init_locales, /* Pointer to plugin initialization function */
114 0, /* Pointer to plugin deinitialization function */
115 0x0100, /* Numeric version 0xAABB means AA.BB version */
116 NULL, /* Status variables */
117 NULL, /* System variables */
118 "1.0", /* String version representation */
119 MariaDB_PLUGIN_MATURITY_STABLE /* Maturity (see include/mysql/plugin.h)*/
120 }
121 maria_declare_plugin_end;
122