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 "my_global.h"
27 #include "handler.h"                            // enum_schema_tables
28 #include "table.h"                              // enum_schema_table_state
29 #include "set_var.h"                            // enum_var_type
30 
31 /* Forward declarations */
32 class JOIN;
33 class sp_name;
34 typedef class st_select_lex SELECT_LEX;
35 typedef struct system_status_var STATUS_VAR;
36 // TODO: allocator based on my_malloc.
37 typedef std::vector<st_mysql_show_var> Status_var_array;
38 
39 enum find_files_result {
40   FIND_FILES_OK,
41   FIND_FILES_OOM,
42   FIND_FILES_DIR
43 };
44 
45 /* Define fields' indexes for COLUMNS table of I_S tables */
46 #define IS_COLUMNS_TABLE_CATALOG                0
47 #define IS_COLUMNS_TABLE_SCHEMA                 1
48 #define IS_COLUMNS_TABLE_NAME                   2
49 #define IS_COLUMNS_COLUMN_NAME                  3
50 #define IS_COLUMNS_ORDINAL_POSITION             4
51 #define IS_COLUMNS_COLUMN_DEFAULT               5
52 #define IS_COLUMNS_IS_NULLABLE                  6
53 #define IS_COLUMNS_DATA_TYPE                    7
54 #define IS_COLUMNS_CHARACTER_MAXIMUM_LENGTH     8
55 #define IS_COLUMNS_CHARACTER_OCTET_LENGTH       9
56 #define IS_COLUMNS_NUMERIC_PRECISION           10
57 #define IS_COLUMNS_NUMERIC_SCALE               11
58 #define IS_COLUMNS_DATETIME_PRECISION          12
59 #define IS_COLUMNS_CHARACTER_SET_NAME          13
60 #define IS_COLUMNS_COLLATION_NAME              14
61 #define IS_COLUMNS_COLUMN_TYPE                 15
62 #define IS_COLUMNS_COLUMN_KEY                  16
63 #define IS_COLUMNS_EXTRA                       17
64 #define IS_COLUMNS_PRIVILEGES                  18
65 #define IS_COLUMNS_COLUMN_COMMENT              19
66 #define IS_COLUMNS_GENERATION_EXPRESSION       20
67 
68 /* Define fields' indexes for ROUTINES table of I_S tables */
69 #define IS_ROUTINES_SPECIFIC_NAME               0
70 #define IS_ROUTINES_ROUTINE_CATALOG             1
71 #define IS_ROUTINES_ROUTINE_SCHEMA              2
72 #define IS_ROUTINES_ROUTINE_NAME                3
73 #define IS_ROUTINES_ROUTINE_TYPE                4
74 #define IS_ROUTINES_DATA_TYPE                   5
75 #define IS_ROUTINES_CHARACTER_MAXIMUM_LENGTH    6
76 #define IS_ROUTINES_CHARACTER_OCTET_LENGTH      7
77 #define IS_ROUTINES_NUMERIC_PRECISION           8
78 #define IS_ROUTINES_NUMERIC_SCALE               9
79 #define IS_ROUTINES_DATETIME_PRECISION         10
80 #define IS_ROUTINES_CHARACTER_SET_NAME         11
81 #define IS_ROUTINES_COLLATION_NAME             12
82 #define IS_ROUTINES_DTD_IDENTIFIER             13
83 #define IS_ROUTINES_ROUTINE_BODY               14
84 #define IS_ROUTINES_ROUTINE_DEFINITION         15
85 #define IS_ROUTINES_EXTERNAL_NAME              16
86 #define IS_ROUTINES_EXTERNAL_LANGUAGE          17
87 #define IS_ROUTINES_PARAMETER_STYLE            18
88 #define IS_ROUTINES_IS_DETERMINISTIC           19
89 #define IS_ROUTINES_SQL_DATA_ACCESS            20
90 #define IS_ROUTINES_SQL_PATH                   21
91 #define IS_ROUTINES_SECURITY_TYPE              22
92 #define IS_ROUTINES_CREATED                    23
93 #define IS_ROUTINES_LAST_ALTERED               24
94 #define IS_ROUTINES_SQL_MODE                   25
95 #define IS_ROUTINES_ROUTINE_COMMENT            26
96 #define IS_ROUTINES_DEFINER                    27
97 #define IS_ROUTINES_CHARACTER_SET_CLIENT       28
98 #define IS_ROUTINES_COLLATION_CONNECTION       29
99 #define IS_ROUTINES_DATABASE_COLLATION         30
100 
101 
102 /* Define fields' indexes for PARAMETERS table of I_S tables */
103 #define IS_PARAMETERS_SPECIFIC_CATALOG          0
104 #define IS_PARAMETERS_SPECIFIC_SCHEMA           1
105 #define IS_PARAMETERS_SPECIFIC_NAME             2
106 #define IS_PARAMETERS_ORDINAL_POSITION          3
107 #define IS_PARAMETERS_PARAMETER_MODE            4
108 #define IS_PARAMETERS_PARAMETER_NAME            5
109 #define IS_PARAMETERS_DATA_TYPE                 6
110 #define IS_PARAMETERS_CHARACTER_MAXIMUM_LENGTH  7
111 #define IS_PARAMETERS_CHARACTER_OCTET_LENGTH    8
112 #define IS_PARAMETERS_NUMERIC_PRECISION         9
113 #define IS_PARAMETERS_NUMERIC_SCALE            10
114 #define IS_PARAMETERS_DATETIME_PRECISION       11
115 #define IS_PARAMETERS_CHARACTER_SET_NAME       12
116 #define IS_PARAMETERS_COLLATION_NAME           13
117 #define IS_PARAMETERS_DTD_IDENTIFIER           14
118 #define IS_PARAMETERS_ROUTINE_TYPE             15
119 
120 /* Used by handlers to store things in schema tables */
121 #define IS_FILES_FILE_ID              0
122 #define IS_FILES_FILE_NAME            1
123 #define IS_FILES_FILE_TYPE            2
124 #define IS_FILES_TABLESPACE_NAME      3
125 #define IS_FILES_TABLE_CATALOG        4
126 #define IS_FILES_TABLE_SCHEMA         5
127 #define IS_FILES_TABLE_NAME           6
128 #define IS_FILES_LOGFILE_GROUP_NAME   7
129 #define IS_FILES_LOGFILE_GROUP_NUMBER 8
130 #define IS_FILES_ENGINE               9
131 #define IS_FILES_FULLTEXT_KEYS       10
132 #define IS_FILES_DELETED_ROWS        11
133 #define IS_FILES_UPDATE_COUNT        12
134 #define IS_FILES_FREE_EXTENTS        13
135 #define IS_FILES_TOTAL_EXTENTS       14
136 #define IS_FILES_EXTENT_SIZE         15
137 #define IS_FILES_INITIAL_SIZE        16
138 #define IS_FILES_MAXIMUM_SIZE        17
139 #define IS_FILES_AUTOEXTEND_SIZE     18
140 #define IS_FILES_CREATION_TIME       19
141 #define IS_FILES_LAST_UPDATE_TIME    20
142 #define IS_FILES_LAST_ACCESS_TIME    21
143 #define IS_FILES_RECOVER_TIME        22
144 #define IS_FILES_TRANSACTION_COUNTER 23
145 #define IS_FILES_VERSION             24
146 #define IS_FILES_ROW_FORMAT          25
147 #define IS_FILES_TABLE_ROWS          26
148 #define IS_FILES_AVG_ROW_LENGTH      27
149 #define IS_FILES_DATA_LENGTH         28
150 #define IS_FILES_MAX_DATA_LENGTH     29
151 #define IS_FILES_INDEX_LENGTH        30
152 #define IS_FILES_DATA_FREE           31
153 #define IS_FILES_CREATE_TIME         32
154 #define IS_FILES_UPDATE_TIME         33
155 #define IS_FILES_CHECK_TIME          34
156 #define IS_FILES_CHECKSUM            35
157 #define IS_FILES_STATUS              36
158 #define IS_FILES_EXTRA               37
159 
160 find_files_result find_files(THD *thd, List<LEX_STRING> *files, const char *db,
161                              const char *path, const char *wild, bool dir,
162                              MEM_ROOT *tmp_mem_root);
163 
164 int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
165                       HA_CREATE_INFO  *create_info_arg, bool show_database);
166 int view_store_create_info(THD *thd, TABLE_LIST *table, String *buff);
167 
168 int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
169 
170 void append_identifier(THD *thd, String *packet, const char *name, size_t length,
171                        const CHARSET_INFO *from_cs, const CHARSET_INFO *to_cs);
172 
append_identifier(THD * thd,String * packet,const char * name,size_t length)173 inline void append_identifier(THD *thd, String *packet, const char *name, size_t length)
174 {
175   append_identifier(thd, packet, name, length, NULL, NULL);
176 }
append_identifier(THD * thd,String * packet,Simple_cstring str)177 inline void append_identifier(THD *thd, String *packet, Simple_cstring str)
178 {
179   append_identifier(thd, packet, str.ptr(), str.length());
180 }
181 void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
182 bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
183 bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
184 
185 void mysqld_list_processes(THD *thd,const char *user,bool verbose);
186 int mysqld_show_status(THD *thd);
187 int mysqld_show_variables(THD *thd,const char *wild);
188 bool mysqld_show_storage_engines(THD *thd);
189 bool mysqld_show_privileges(THD *thd);
190 char *make_backup_log_name(char *buff, const char *name, const char* log_ext);
191 void calc_sum_of_all_status(STATUS_VAR *to);
192 void append_definer(THD *thd, String *buffer, const LEX_CSTRING &definer_user,
193                     const LEX_CSTRING &definer_host);
194 int add_status_vars(const SHOW_VAR *list);
195 DYNAMIC_ARRAY *get_status_vars();
196 
197 void remove_status_vars(SHOW_VAR *list);
198 void init_status_vars();
199 void free_status_vars();
200 bool get_status_var(THD *thd, SHOW_VAR *list, const char *name,
201                     char * const buff, enum_var_type var_type, size_t *length);
202 void reset_status_vars();
203 ulonglong get_status_vars_version(void);
204 bool show_create_trigger(THD *thd, const sp_name *trg_name);
205 void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
206 
207 void init_fill_schema_files_row(TABLE* table);
208 bool schema_table_store_record(THD *thd, TABLE *table);
209 
210 /**
211   Store record to I_S table, convert HEAP table to InnoDB table if necessary.
212 
213   @param[in]  thd            thread handler
214   @param[in]  table          Information schema table to be updated
215   @param[in]  make_ondisk    if true, convert heap table to on disk table.
216                              default value is true.
217   @return 0 on success
218   @return error code on failure.
219 */
220 int schema_table_store_record2(THD *thd, TABLE *table, bool make_ondisk);
221 
222 /**
223   Convert HEAP table to InnoDB table if necessary
224 
225   @param[in] thd     thread handler
226   @param[in] table   Information schema table to be converted.
227   @param[in] error   the error code returned previously.
228   @return false on success, true on error.
229 */
230 bool convert_heap_table_to_ondisk(THD *thd, TABLE *table, int error);
231 void initialize_information_schema_acl();
232 
233 ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
234 ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
235 int make_schema_select(THD *thd,  SELECT_LEX *sel,
236                        enum enum_schema_tables schema_table_idx);
237 int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
238 bool get_schema_tables_result(JOIN *join,
239                               enum enum_schema_table_state executed_place);
240 enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
241 
242 const char* get_one_variable(THD *thd, const SHOW_VAR *variable,
243                              enum_var_type value_type, SHOW_TYPE show_type,
244                              system_status_var *status_var,
245                              const CHARSET_INFO **charset, char *buff,
246                              size_t *length);
247 
248 const char* get_one_variable_ext(THD *running_thd, THD *target_thd,
249                                  const SHOW_VAR *variable,
250                                  enum_var_type value_type, SHOW_TYPE show_type,
251                                  system_status_var *status_var,
252                                  const CHARSET_INFO **charset, char *buff,
253                                  size_t *length);
254 
255 /* These functions were under INNODB_COMPATIBILITY_HOOKS */
256 int get_quote_char_for_identifier(THD *thd, const char *name, size_t length);
257 
258 /* Handle the ignored database directories list for SHOW/I_S/initialize. */
259 void ignore_db_dirs_init();
260 void ignore_db_dirs_free();
261 void ignore_db_dirs_reset();
262 bool ignore_db_dirs_process_additions();
263 bool push_ignored_db_dir(char *path);
264 extern char *opt_ignore_db_dirs;
265 bool is_in_ignore_db_dirs_list(const char *directory);
266 
267 #endif /* SQL_SHOW_H */
268