1 /* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
22 
23 #ifndef SQL_SHOW_H
24 #define SQL_SHOW_H
25 
26 #include "sql_list.h"                           /* List */
27 #include "handler.h"                            /* enum_schema_tables */
28 #include "table.h"                              /* enum_schema_table_state */
29 
30 /* Forward declarations */
31 class JOIN;
32 class String;
33 class THD;
34 class sp_name;
35 struct TABLE_LIST;
36 struct st_ha_create_information;
37 typedef class st_select_lex SELECT_LEX;
38 typedef st_ha_create_information HA_CREATE_INFO;
39 struct LEX;
40 typedef struct st_mysql_show_var SHOW_VAR;
41 typedef struct st_schema_table ST_SCHEMA_TABLE;
42 struct TABLE;
43 typedef struct system_status_var STATUS_VAR;
44 
45 enum find_files_result {
46   FIND_FILES_OK,
47   FIND_FILES_OOM,
48   FIND_FILES_DIR
49 };
50 
51 /* Define fields' indexes for COLUMNS table of I_S tables */
52 #define IS_COLUMNS_TABLE_CATALOG                0
53 #define IS_COLUMNS_TABLE_SCHEMA                 1
54 #define IS_COLUMNS_TABLE_NAME                   2
55 #define IS_COLUMNS_COLUMN_NAME                  3
56 #define IS_COLUMNS_ORDINAL_POSITION             4
57 #define IS_COLUMNS_COLUMN_DEFAULT               5
58 #define IS_COLUMNS_IS_NULLABLE                  6
59 #define IS_COLUMNS_DATA_TYPE                    7
60 #define IS_COLUMNS_CHARACTER_MAXIMUM_LENGTH     8
61 #define IS_COLUMNS_CHARACTER_OCTET_LENGTH       9
62 #define IS_COLUMNS_NUMERIC_PRECISION           10
63 #define IS_COLUMNS_NUMERIC_SCALE               11
64 #define IS_COLUMNS_DATETIME_PRECISION          12
65 #define IS_COLUMNS_CHARACTER_SET_NAME          13
66 #define IS_COLUMNS_COLLATION_NAME              14
67 #define IS_COLUMNS_COLUMN_TYPE                 15
68 #define IS_COLUMNS_COLUMN_KEY                  16
69 #define IS_COLUMNS_EXTRA                       17
70 #define IS_COLUMNS_PRIVILEGES                  18
71 #define IS_COLUMNS_COLUMN_COMMENT              19
72 
73 /* Define fields' indexes for ROUTINES table of I_S tables */
74 #define IS_ROUTINES_SPECIFIC_NAME               0
75 #define IS_ROUTINES_ROUTINE_CATALOG             1
76 #define IS_ROUTINES_ROUTINE_SCHEMA              2
77 #define IS_ROUTINES_ROUTINE_NAME                3
78 #define IS_ROUTINES_ROUTINE_TYPE                4
79 #define IS_ROUTINES_DATA_TYPE                   5
80 #define IS_ROUTINES_CHARACTER_MAXIMUM_LENGTH    6
81 #define IS_ROUTINES_CHARACTER_OCTET_LENGTH      7
82 #define IS_ROUTINES_NUMERIC_PRECISION           8
83 #define IS_ROUTINES_NUMERIC_SCALE               9
84 #define IS_ROUTINES_DATETIME_PRECISION         10
85 #define IS_ROUTINES_CHARACTER_SET_NAME         11
86 #define IS_ROUTINES_COLLATION_NAME             12
87 #define IS_ROUTINES_DTD_IDENTIFIER             13
88 #define IS_ROUTINES_ROUTINE_BODY               14
89 #define IS_ROUTINES_ROUTINE_DEFINITION         15
90 #define IS_ROUTINES_EXTERNAL_NAME              16
91 #define IS_ROUTINES_EXTERNAL_LANGUAGE          17
92 #define IS_ROUTINES_PARAMETER_STYLE            18
93 #define IS_ROUTINES_IS_DETERMINISTIC           19
94 #define IS_ROUTINES_SQL_DATA_ACCESS            20
95 #define IS_ROUTINES_SQL_PATH                   21
96 #define IS_ROUTINES_SECURITY_TYPE              22
97 #define IS_ROUTINES_CREATED                    23
98 #define IS_ROUTINES_LAST_ALTERED               24
99 #define IS_ROUTINES_SQL_MODE                   25
100 #define IS_ROUTINES_ROUTINE_COMMENT            26
101 #define IS_ROUTINES_DEFINER                    27
102 #define IS_ROUTINES_CHARACTER_SET_CLIENT       28
103 #define IS_ROUTINES_COLLATION_CONNECTION       29
104 #define IS_ROUTINES_DATABASE_COLLATION         30
105 
106 
107 /* Define fields' indexes for PARAMETERS table of I_S tables */
108 #define IS_PARAMETERS_SPECIFIC_CATALOG          0
109 #define IS_PARAMETERS_SPECIFIC_SCHEMA           1
110 #define IS_PARAMETERS_SPECIFIC_NAME             2
111 #define IS_PARAMETERS_ORDINAL_POSITION          3
112 #define IS_PARAMETERS_PARAMETER_MODE            4
113 #define IS_PARAMETERS_PARAMETER_NAME            5
114 #define IS_PARAMETERS_DATA_TYPE                 6
115 #define IS_PARAMETERS_CHARACTER_MAXIMUM_LENGTH  7
116 #define IS_PARAMETERS_CHARACTER_OCTET_LENGTH    8
117 #define IS_PARAMETERS_NUMERIC_PRECISION         9
118 #define IS_PARAMETERS_NUMERIC_SCALE            10
119 #define IS_PARAMETERS_DATETIME_PRECISION       11
120 #define IS_PARAMETERS_CHARACTER_SET_NAME       12
121 #define IS_PARAMETERS_COLLATION_NAME           13
122 #define IS_PARAMETERS_DTD_IDENTIFIER           14
123 #define IS_PARAMETERS_ROUTINE_TYPE             15
124 
125 /* Used by handlers to store things in schema tables */
126 #define IS_FILES_FILE_ID              0
127 #define IS_FILES_FILE_NAME            1
128 #define IS_FILES_FILE_TYPE            2
129 #define IS_FILES_TABLESPACE_NAME      3
130 #define IS_FILES_TABLE_CATALOG        4
131 #define IS_FILES_TABLE_SCHEMA         5
132 #define IS_FILES_TABLE_NAME           6
133 #define IS_FILES_LOGFILE_GROUP_NAME   7
134 #define IS_FILES_LOGFILE_GROUP_NUMBER 8
135 #define IS_FILES_ENGINE               9
136 #define IS_FILES_FULLTEXT_KEYS       10
137 #define IS_FILES_DELETED_ROWS        11
138 #define IS_FILES_UPDATE_COUNT        12
139 #define IS_FILES_FREE_EXTENTS        13
140 #define IS_FILES_TOTAL_EXTENTS       14
141 #define IS_FILES_EXTENT_SIZE         15
142 #define IS_FILES_INITIAL_SIZE        16
143 #define IS_FILES_MAXIMUM_SIZE        17
144 #define IS_FILES_AUTOEXTEND_SIZE     18
145 #define IS_FILES_CREATION_TIME       19
146 #define IS_FILES_LAST_UPDATE_TIME    20
147 #define IS_FILES_LAST_ACCESS_TIME    21
148 #define IS_FILES_RECOVER_TIME        22
149 #define IS_FILES_TRANSACTION_COUNTER 23
150 #define IS_FILES_VERSION             24
151 #define IS_FILES_ROW_FORMAT          25
152 #define IS_FILES_TABLE_ROWS          26
153 #define IS_FILES_AVG_ROW_LENGTH      27
154 #define IS_FILES_DATA_LENGTH         28
155 #define IS_FILES_MAX_DATA_LENGTH     29
156 #define IS_FILES_INDEX_LENGTH        30
157 #define IS_FILES_DATA_FREE           31
158 #define IS_FILES_CREATE_TIME         32
159 #define IS_FILES_UPDATE_TIME         33
160 #define IS_FILES_CHECK_TIME          34
161 #define IS_FILES_CHECKSUM            35
162 #define IS_FILES_STATUS              36
163 #define IS_FILES_EXTRA               37
164 
165 find_files_result find_files(THD *thd, List<LEX_STRING> *files, const char *db,
166                              const char *path, const char *wild, bool dir,
167                              MEM_ROOT *tmp_mem_root);
168 
169 int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
170                       HA_CREATE_INFO  *create_info_arg, bool show_database);
171 int view_store_create_info(THD *thd, TABLE_LIST *table, String *buff);
172 
173 int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
174 int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
175 
176 void append_identifier(THD *thd, String *packet, const char *name, uint length,
177                        const CHARSET_INFO *from_cs, const CHARSET_INFO *to_cs);
append_identifier(THD * thd,String * packet,const char * name,uint length)178 inline void append_identifier(THD *thd, String *packet, const char *name,
179                               uint length)
180 {
181   append_identifier(thd, packet, name, length, NULL, NULL);
182 }
append_identifier(THD * thd,String * packet,Simple_cstring str)183 inline void append_identifier(THD *thd, String *packet, Simple_cstring str)
184 {
185   append_identifier(thd, packet, str.ptr(), static_cast<uint>(str.length()));
186 }
187 void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
188 bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
189 bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
190 
191 void mysqld_list_processes(THD *thd,const char *user,bool verbose);
192 int mysqld_show_status(THD *thd);
193 int mysqld_show_variables(THD *thd,const char *wild);
194 bool mysqld_show_storage_engines(THD *thd);
195 bool mysqld_show_privileges(THD *thd);
196 char *make_backup_log_name(char *buff, const char *name, const char* log_ext);
197 void calc_sum_of_all_status(STATUS_VAR *to);
198 void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
199                     const LEX_STRING *definer_host);
200 int add_status_vars(SHOW_VAR *list);
201 void remove_status_vars(SHOW_VAR *list);
202 void init_status_vars();
203 void free_status_vars();
204 bool get_status_var(THD* thd, SHOW_VAR *list, const char *name, char * const buff);
205 void reset_status_vars();
206 bool show_create_trigger(THD *thd, const sp_name *trg_name);
207 void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
208 
209 void init_fill_schema_files_row(TABLE* table);
210 bool schema_table_store_record(THD *thd, TABLE *table);
211 void initialize_information_schema_acl();
212 
213 ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
214 ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
215 int make_schema_select(THD *thd,  SELECT_LEX *sel,
216                        enum enum_schema_tables schema_table_idx);
217 int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
218 bool get_schema_tables_result(JOIN *join,
219                               enum enum_schema_table_state executed_place);
220 enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
221 
222 /* These functions were under INNODB_COMPATIBILITY_HOOKS */
223 int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
224 
225 /* Handle the ignored database directories list for SHOW/I_S. */
226 bool ignore_db_dirs_init();
227 void ignore_db_dirs_free();
228 void ignore_db_dirs_reset();
229 bool ignore_db_dirs_process_additions();
230 bool push_ignored_db_dir(char *path);
231 extern char *opt_ignore_db_dirs;
232 
233 #endif /* SQL_SHOW_H */
234