summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
authorunknown <anozdrin/alik@alik.>2006-11-07 16:24:35 +0300
committerunknown <anozdrin/alik@alik.>2006-11-07 16:24:35 +0300
commite50678f1cea5b0888490710f2542568581b198ec (patch)
tree4c085423d9f65d9221f445b2bc03833ed5b266f0 /sql/sql_view.cc
parentda032b99eb7b0621e333dc2b6f423d376017a503 (diff)
parentdd72647032cf157b063fe9a7f02ed2994734b1c0 (diff)
downloadmariadb-git-e50678f1cea5b0888490710f2542568581b198ec.tar.gz
Merge alik.:/mnt/raid/alik/MySQL/devel/5.1
into alik.:/mnt/raid/alik/MySQL/devel/5.1-rt-merged-2 configure.in: Auto merged include/my_time.h: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/kill.result: Auto merged mysql-test/r/ps.result: Auto merged mysql-test/r/rename.result: Auto merged mysql-test/r/view.result: Auto merged mysql-test/t/func_time.test: Auto merged mysql-test/t/ps.test: Auto merged mysql-test/t/rename.test: Auto merged mysql-test/t/view.test: Auto merged sql/Makefile.am: Auto merged sql/handler.cc: Auto merged sql/item_timefunc.cc: Auto merged sql/lex.h: Auto merged sql/log.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_insert.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql-common/my_time.c: Auto merged sql/sql_select.cc: Auto merged sql/sql_view.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/table.cc: Auto merged sql/time.cc: Auto merged tests/mysql_client_test.c: Auto merged mysql-test/mysql-test-run.pl: Manually merged. sql/sql_parse.cc: Manually merged.
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc64
1 files changed, 59 insertions, 5 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 22d9024982f..2b155111e6f 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -212,6 +212,7 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view)
SYNOPSIS
mysql_create_view()
thd - thread handler
+ views - views to create
mode - VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE
RETURN VALUE
@@ -219,7 +220,7 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view)
TRUE Error
*/
-bool mysql_create_view(THD *thd,
+bool mysql_create_view(THD *thd, TABLE_LIST *views,
enum_view_create_mode mode)
{
LEX *lex= thd->lex;
@@ -532,6 +533,49 @@ bool mysql_create_view(THD *thd,
}
VOID(pthread_mutex_lock(&LOCK_open));
res= mysql_register_view(thd, view, mode);
+
+ if (mysql_bin_log.is_open())
+ {
+ String buff;
+ const LEX_STRING command[3]=
+ {{ C_STRING_WITH_LEN("CREATE ") },
+ { C_STRING_WITH_LEN("ALTER ") },
+ { C_STRING_WITH_LEN("CREATE OR REPLACE ") }};
+
+ buff.append(command[thd->lex->create_view_mode].str,
+ command[thd->lex->create_view_mode].length);
+ view_store_options(thd, views, &buff);
+ buff.append(STRING_WITH_LEN("VIEW "));
+ /* Test if user supplied a db (ie: we did not use thd->db) */
+ if (views->db && views->db[0] &&
+ (thd->db == NULL || strcmp(views->db, thd->db)))
+ {
+ append_identifier(thd, &buff, views->db,
+ views->db_length);
+ buff.append('.');
+ }
+ append_identifier(thd, &buff, views->table_name,
+ views->table_name_length);
+ if (lex->view_list.elements)
+ {
+ List_iterator_fast<LEX_STRING> names(lex->view_list);
+ LEX_STRING *name;
+ int i;
+
+ for (i= 0; name= names++; i++)
+ {
+ buff.append(i ? ", " : "(");
+ append_identifier(thd, &buff, name->str, name->length);
+ }
+ buff.append(')');
+ }
+ buff.append(STRING_WITH_LEN(" AS "));
+ buff.append(views->source.str, views->source.length);
+
+ thd->binlog_query(THD::STMT_QUERY_TYPE,
+ buff.ptr(), buff.length(), FALSE, FALSE);
+ }
+
VOID(pthread_mutex_unlock(&LOCK_open));
if (view->revision != 1)
query_cache_invalidate3(thd, view, 0);
@@ -1304,13 +1348,13 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
enum legacy_db_type not_used;
DBUG_ENTER("mysql_drop_view");
+ VOID(pthread_mutex_lock(&LOCK_open));
for (view= views; view; view= view->next_local)
{
TABLE_SHARE *share;
frm_type_enum type= FRMTYPE_ERROR;
build_table_filename(path, sizeof(path),
view->db, view->table_name, reg_ext, 0);
- VOID(pthread_mutex_lock(&LOCK_open));
if (access(path, F_OK) ||
FRMTYPE_VIEW != (type= mysql_frm_type(thd, path, &not_used)))
@@ -1322,7 +1366,6 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
name);
- VOID(pthread_mutex_unlock(&LOCK_open));
continue;
}
if (type == FRMTYPE_TABLE)
@@ -1339,7 +1382,6 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
non_existant_views.append(',');
non_existant_views.append(String(view->table_name,system_charset_info));
}
- VOID(pthread_mutex_unlock(&LOCK_open));
continue;
}
if (my_delete(path, MYF(MY_WME)))
@@ -1360,24 +1402,36 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
}
query_cache_invalidate3(thd, view, 0);
sp_cache_invalidate();
- VOID(pthread_mutex_unlock(&LOCK_open));
}
+
if (error)
{
+ VOID(pthread_mutex_unlock(&LOCK_open));
DBUG_RETURN(TRUE);
}
if (wrong_object_name)
{
+ VOID(pthread_mutex_unlock(&LOCK_open));
my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name,
"VIEW");
DBUG_RETURN(TRUE);
}
if (non_existant_views.length())
{
+ VOID(pthread_mutex_unlock(&LOCK_open));
my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr());
DBUG_RETURN(TRUE);
}
+
+ if (mysql_bin_log.is_open())
+ {
+ thd->clear_error();
+ thd->binlog_query(THD::STMT_QUERY_TYPE,
+ thd->query, thd->query_length, FALSE, FALSE);
+ }
+
send_ok(thd);
+ VOID(pthread_mutex_unlock(&LOCK_open));
DBUG_RETURN(FALSE);
}