--- /tmp/mysqldump.c 2010-09-23 09:41:47.000000000 +0100 +++ client/mysqldump.c 2010-09-22 16:05:11.000000000 +0100 @@ -483,7 +483,7 @@ static int dump_databases(char **); static int dump_all_databases(); static char *quote_name(const char *name, char *buff, my_bool force); -char check_if_ignore_table(const char *table_name, char *table_type); +char check_if_ignore_table(const char *database, const char *table_name, char *table_type); static char *primary_key_fields(const char *table_name); static my_bool get_view_structure(char *table, char* db); static my_bool dump_all_views_in_db(char *database); @@ -2240,7 +2240,7 @@ DBUG_ENTER("get_table_structure"); DBUG_PRINT("enter", ("db: %s table: %s", db, table)); - *ignore_flag= check_if_ignore_table(table, table_type); + *ignore_flag= check_if_ignore_table(db, table, table_type); delayed= opt_delayed; if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED)) @@ -2675,11 +2675,15 @@ /* Get MySQL specific create options */ if (create_options) { - char show_name_buff[NAME_LEN*2+2+24]; + char show_name_buff1[NAME_LEN*2+2+24]; + char show_name_buff2[NAME_LEN*2+2+24]; + mysql_real_escape_string(mysql, show_name_buff1, db, strlen(db)); + mysql_real_escape_string(mysql, show_name_buff2, table, strlen(table)); /* Check memory for quote_for_like() */ - my_snprintf(buff, sizeof(buff), "show table status like %s", - quote_for_like(table, show_name_buff)); + my_snprintf(buff, sizeof(buff), "SELECT ENGINE, CREATE_OPTIONS, TABLE_COMMENT WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'", + show_name_buff1, + show_name_buff2); if (mysql_query_with_error_report(mysql, &result, buff)) { @@ -2702,9 +2706,11 @@ else { fputs("/*!",sql_file); - print_value(sql_file,result,row,"engine=","Engine",0); - print_value(sql_file,result,row,"","Create_options",0); - print_value(sql_file,result,row,"comment=","Comment",1); + fprintf(sql_file, " ENGINE=%s %s)",row[0], row[1]); + if (strcmp(row[2], "") != 0) { + mysql_real_escape_string(mysql, show_name_buff1, row[2], strlen(row[2])); + fprintf(sql_file, " COMMENT='%s')", show_name_buff1); + } fputs(" */",sql_file); check_io(sql_file); } @@ -2866,6 +2872,7 @@ static int dump_triggers_for_table(char *table_name, char *db_name) { char name_buff[NAME_LEN*4+3]; + char db_buff[NAME_LEN*4+3]; char query_buff[QUERY_LENGTH]; uint old_opt_compatible_mode= opt_compatible_mode; MYSQL_RES *show_triggers_rs; @@ -2895,9 +2902,11 @@ /* Get list of triggers. */ + mysql_real_escape_string(mysql, db_buff, db_name, strlen(db_name)); + mysql_real_escape_string(mysql, name_buff, table_name, strlen(db_name)); my_snprintf(query_buff, sizeof(query_buff), - "SHOW TRIGGERS LIKE %s", - quote_for_like(table_name, name_buff)); + "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA = '%s' AND EVENT_OBJECT_TABLE = '%s'", + db_buff, name_buff); if (mysql_query_with_error_report(mysql, &show_triggers_rs, query_buff)) goto done; @@ -4554,6 +4563,7 @@ ARGS check_if_ignore_table() + database Database table_name Table name to check table_type Type of table @@ -4565,18 +4575,23 @@ char (bit value) See IGNORE_ values at top */ -char check_if_ignore_table(const char *table_name, char *table_type) +char check_if_ignore_table(const char *database, const char *table_name, char *table_type) { char result= IGNORE_NONE; - char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN]; + char buff[FN_REFLEN+80], show_name_buff1[FN_REFLEN], show_name_buff2[FN_REFLEN]; MYSQL_RES *res= NULL; MYSQL_ROW row; DBUG_ENTER("check_if_ignore_table"); /* Check memory for quote_for_like() */ - DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff)); - my_snprintf(buff, sizeof(buff), "show table status like %s", - quote_for_like(table_name, show_name_buff)); + DBUG_ASSERT(2*sizeof(database) < sizeof(show_name_buff1)); + DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff2)); + mysql_real_escape_string(mysql, show_name_buff1, database, + strlen(database)); + mysql_real_escape_string(mysql, show_name_buff2, table_name, + strlen(table_name)); + my_snprintf(buff, sizeof(buff), "SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'", + show_name_buff1, show_name_buff2); if (mysql_query_with_error_report(mysql, &res, buff)) { if (mysql_errno(mysql) != ER_PARSE_ERROR) @@ -4594,7 +4609,7 @@ mysql_free_result(res); DBUG_RETURN(result); /* assume table is ok */ } - if (!(row[1])) + if (!(row[0])) strmake(table_type, "VIEW", NAME_LEN-1); else { @@ -4604,7 +4619,7 @@ these types, but we do want to use delayed inserts in the dump if the table type is _NOT_ one of these types */ - strmake(table_type, row[1], NAME_LEN-1); + strmake(table_type, row[0], NAME_LEN-1); if (opt_delayed) { if (strcmp(table_type,"MyISAM") &&