MCPcopy Create free account
hub / github.com/MariaDB/server / mysql_register_view

Function mysql_register_view

sql/sql_view.cc:993–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

991*/
992
993static int mysql_register_view(THD *thd, DDL_LOG_STATE *ddl_log_state,
994 TABLE_LIST *view, enum_view_create_mode mode,
995 char *backup_file_name)
996{
997 LEX *lex= thd->lex;
998
999 /*
1000 Ensure character set number != 17 (character set = filename) and mbminlen=1
1001 because these character sets are not parser friendly, which can give weird
1002 sequence in .frm file of view and later give parsing error.
1003 */
1004 DBUG_ASSERT(thd->charset()->mbminlen == 1 && thd->charset()->number != 17);
1005
1006 /*
1007 View definition query -- a SELECT statement that fully defines view. It
1008 is generated from the Item-tree built from the original (specified by
1009 the user) query. The idea is that generated query should eliminate all
1010 ambiguities.
1011 Item::print() virtual operation is used to generate view definition
1012 query.
1013
1014 The INFORMATION_SCHEMA query is a SQL statement describing a
1015 view as shown in the INFORMATION_SCHEMA database. It is the 'view
1016 definition query' with text literals converted to UTF8 and without
1017 character set introducers.
1018
1019 For example:
1020 Let's suppose we have:
1021 CREATE TABLE t1(a INT, b INT);
1022 User specified query:
1023 CREATE VIEW v1(x, y) AS SELECT * FROM t1;
1024 Generated query:
1025 SELECT a AS x, b AS y FROM t1;
1026 INFORMATION_SCHEMA query:
1027 SELECT a AS x, b AS y FROM t1;
1028
1029 View definition query is stored in the client character set.
1030 */
1031 constexpr const size_t BUFF_4K= 4096;
1032 StringBuffer<BUFF_4K> view_query(thd->charset());
1033 StringBuffer<BUFF_4K> is_query(system_charset_info); // information_schema
1034
1035 char md5[MD5_BUFF_LENGTH];
1036 bool can_be_merged;
1037 char dir_buff[FN_REFLEN + 1], path_buff[FN_REFLEN + 1];
1038 LEX_CSTRING dir, file, path;
1039 int error= 0;
1040 bool old_view_exists= 0;
1041 DBUG_ENTER("mysql_register_view");
1042
1043 /* Generate view definition and IS queries. */
1044 view_query.length(0);
1045 is_query.length(0);
1046 backup_file_name[0]= 0;
1047 {
1048 Sql_mode_save_for_frm_handling sql_mode_save(thd);
1049
1050 lex->unit.print(&view_query, enum_query_type(QT_FOR_FRM |

Callers 1

mysql_create_viewFunction · 0.85

Calls 15

enum_query_typeEnum · 0.85
my_errorFunction · 0.85
push_warningFunction · 0.85
make_view_filenameFunction · 0.85
fn_formatFunction · 0.85
ha_table_existsFunction · 0.85
push_warning_printfFunction · 0.85
sql_parse_prepareFunction · 0.85
is_equalFunction · 0.85
createFunction · 0.85
ddl_log_create_viewFunction · 0.85

Tested by

no test coverage detected