summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorunknown <anozdrin@mysql.com>2006-01-11 02:07:40 +0300
committerunknown <anozdrin@mysql.com>2006-01-11 02:07:40 +0300
commitd4d29edb836c697d744bb75496b58b76554fcb68 (patch)
tree2d2fbf7237a87334eb708a2f4af55c8b443046df /client
parentffc206d9be17b67f1daed509e5939c63519960f0 (diff)
downloadmariadb-git-d4d29edb836c697d744bb75496b58b76554fcb68.tar.gz
Fix for BUG#15110: mysqldump --triggers: does not include DEFINER clause
There are two main idea of this fix: - introduce a common function for server and client to split user value (<user name>@<host name>) into user name and host name parts; - dump DEFINER clause in correct format in mysqldump. BitKeeper/etc/ignore: added client/my_user.c libmysqld/my_user.c sql/my_user.c client/Makefile.am: Use my_user.c in linking of mysqldump executable. client/mysqldump.c: Fix for BUG#15110(mysqldump --triggers: does not include DEFINER clause) include/Makefile.am: Add my_user.c include/mysql_com.h: Introduce a constant for max user length. libmysqld/Makefile.am: Add my_user.c mysql-test/r/mysqldump.result: Update result file. sql-common/Makefile.am: Add my_user.c sql/Makefile.am: Add my_user.c sql/sp.cc: Use constant for max user length. sql/sp_head.cc: Use common function to parse user value. sql/sql_acl.cc: Use constant for max user length. sql/sql_parse.cc: Use constant for max user length. sql/sql_show.cc: Use constant for max user length. sql/sql_trigger.cc: Use constant for max user length. include/my_user.h: A header file for parse_user(). sql-common/my_user.c: A new file for parse_user() implementation.
Diffstat (limited to 'client')
-rw-r--r--client/Makefile.am7
-rw-r--r--client/mysqldump.c35
2 files changed, 37 insertions, 5 deletions
diff --git a/client/Makefile.am b/client/Makefile.am
index 804f194085f..2c513d3d7c7 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -46,7 +46,7 @@ mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c
mysqltestmanagerc_SOURCES= mysqlmanagerc.c $(yassl_dummy_link_fix)
mysqlcheck_SOURCES= mysqlcheck.c $(yassl_dummy_link_fix)
mysqlshow_SOURCES= mysqlshow.c $(yassl_dummy_link_fix)
-mysqldump_SOURCES= mysqldump.c $(yassl_dummy_link_fix)
+mysqldump_SOURCES= mysqldump.c my_user.c $(yassl_dummy_link_fix)
mysqlimport_SOURCES= mysqlimport.c $(yassl_dummy_link_fix)
sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc
strings_src=decimal.c
@@ -62,7 +62,10 @@ link_sources:
for f in $(strings_src) ; do \
rm -f $(srcdir)/$$f; \
@LN_CP_F@ $(top_srcdir)/strings/$$f $$f; \
- done;
+ done; \
+ rm -f $(srcdir)/my_user.c; \
+ @LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c;
+
# Don't update the files from bitkeeper
%::SCCS/s.%
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 454fc0df84e..b24d67ec302 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -41,6 +41,7 @@
#include <my_global.h>
#include <my_sys.h>
+#include <my_user.h>
#include <m_string.h>
#include <m_ctype.h>
#include <hash.h>
@@ -1840,9 +1841,37 @@ static void dump_triggers_for_table (char *table, char *db)
DELIMITER ;;\n");
while ((row= mysql_fetch_row(result)))
{
- fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n\
-/*!50003 CREATE TRIGGER %s %s %s ON %s FOR EACH ROW%s%s */;;\n\n",
- row[6], /* sql_mode */
+ fprintf(sql_file,
+ "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n"
+ "/*!50003 CREATE */ ",
+ row[6] /* sql_mode */);
+
+ if (mysql_num_fields(result) > 7)
+ {
+ /*
+ mysqldump can be run against the server, that does not support definer
+ in triggers (there is no DEFINER column in SHOW TRIGGERS output). So,
+ we should check if we have this column before accessing it.
+ */
+
+ uint user_name_len;
+ char user_name_str[USERNAME_LENGTH + 1];
+ char quoted_user_name_str[USERNAME_LENGTH * 2 + 3];
+ uint host_name_len;
+ char host_name_str[HOSTNAME_LENGTH + 1];
+ char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3];
+
+ parse_user(row[7], strlen(row[7]), user_name_str, &user_name_len,
+ host_name_str, &host_name_len);
+
+ fprintf(sql_file,
+ "/*!50017 DEFINER=%s@%s */ ",
+ quote_name(user_name_str, quoted_user_name_str, FALSE),
+ quote_name(host_name_str, quoted_host_name_str, FALSE));
+ }
+
+ fprintf(sql_file,
+ "/*!50003 TRIGGER %s %s %s ON %s FOR EACH ROW%s%s */;;\n\n",
quote_name(row[0], name_buff, 0), /* Trigger */
row[4], /* Timing */
row[1], /* Event */