From d4befc1dca23d4ed535a4eb2f82700b54702375b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 24 Oct 2007 22:36:57 +0500 Subject: Fix for bug #30679: 5.1 name encoding not performed for views during upgrade Problem: we skip views perfoming --fix-table-names. Fix: rename views as well. client/mysqlcheck.c: Fix for bug #30679: 5.1 name encoding not performed for views during upgrade - rename views performing --fix-table-names as well. mysql-test/r/mysqlcheck.result: Fix for bug #30679: 5.1 name encoding not performed for views during upgrade - test result. mysql-test/t/mysqlcheck.test: Fix for bug #30679: 5.1 name encoding not performed for views during upgrade - test case. --- client/mysqlcheck.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'client/mysqlcheck.c') diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index fb2071ce10f..34f09f6ca92 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -533,8 +533,11 @@ static int process_all_tables_in_db(char *database) else { while ((row = mysql_fetch_row(res))) - /* Skip tables with an engine of NULL (probably a view). */ - if (row[1]) + /* + Skip tables with an engine of NULL (probably a view) + if we don't perform renaming. + */ + if (row[1] || what_to_do == DO_UPGRADE) { handle_request_for_tables(row[0], strlen(row[0])); } -- cgit v1.2.1 From 2611e8ec0c3abac191100ab5c8527ff21ba99d81 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Oct 2007 12:51:57 +0400 Subject: Fix for bug #30654: mysqlcheck fails during upgrade of tables whose names include backticks or blank Problem: mysqlcheck doesn't escape backtick characters in the table names. Fix: escape them. client/mysqlcheck.c: Fix for bug #30654: mysqlcheck fails during upgrade of tables whose names include backticks or blank - escape backtick characters in the table names. mysql-test/r/mysqlcheck.result: Fix for bug #30654: mysqlcheck fails during upgrade of tables whose names include backticks or blank - test result. mysql-test/t/mysqlcheck.test: Fix for bug #30654: mysqlcheck fails during upgrade of tables whose names include backticks or blank - test case. --- client/mysqlcheck.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'client/mysqlcheck.c') diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 8205a83fdf4..3b504eb50b0 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -186,6 +186,7 @@ static void dbDisconnect(char *host); static void DBerror(MYSQL *mysql, const char *when); static void safe_exit(int error); static void print_result(); +static uint fixed_name_length(const char *name); static char *fix_table_name(char *dest, char *src); int what_to_do = 0; @@ -409,14 +410,14 @@ static int process_selected_tables(char *db, char **table_names, int tables) { /* We need table list in form `a`, `b`, `c` - that's why we need 4 more chars added to to each table name + that's why we need 2 more chars added to to each table name space is for more readable output in logs and in case of error */ char *table_names_comma_sep, *end; int i, tot_length = 0; for (i = 0; i < tables; i++) - tot_length += strlen(*(table_names + i)) + 4; + tot_length+= fixed_name_length(*(table_names + i)) + 2; if (!(table_names_comma_sep = (char *) my_malloc((sizeof(char) * tot_length) + 4, MYF(MY_WME)))) @@ -434,23 +435,46 @@ static int process_selected_tables(char *db, char **table_names, int tables) } else for (; tables > 0; tables--, table_names++) - handle_request_for_tables(*table_names, strlen(*table_names)); + handle_request_for_tables(*table_names, fixed_name_length(*table_names)); return 0; } /* process_selected_tables */ -static char *fix_table_name(char *dest, char *src) +static uint fixed_name_length(const char *name) { - char *db_sep; + const char *p; + uint extra_length= 2; /* count the first/last backticks */ + + for (p= name; *p; p++) + { + if (*p == '`') + extra_length++; + else if (*p == '.') + extra_length+= 2; + } + return (p - name) + extra_length; +} + +static char *fix_table_name(char *dest, char *src) +{ *dest++= '`'; - if ((db_sep= strchr(src, '.'))) + for (; *src; src++) { - dest= strmake(dest, src, (uint) (db_sep - src)); - dest= strmov(dest, "`.`"); - src= db_sep + 1; + switch (*src) { + case '.': /* add backticks around '.' */ + *dest++= '`'; + *dest++= '.'; + *dest++= '`'; + break; + case '`': /* escape backtick character */ + *dest++= '`'; + /* fall through */ + default: + *dest++= *src; + } } - dest= strxmov(dest, src, "`", NullS); + *dest++= '`'; return dest; } @@ -471,7 +495,7 @@ static int process_all_tables_in_db(char *database) { /* We need table list in form `a`, `b`, `c` - that's why we need 4 more chars added to to each table name + that's why we need 2 more chars added to to each table name space is for more readable output in logs and in case of error */ @@ -479,7 +503,7 @@ static int process_all_tables_in_db(char *database) uint tot_length = 0; while ((row = mysql_fetch_row(res))) - tot_length += strlen(row[0]) + 4; + tot_length+= fixed_name_length(row[0]) + 2; mysql_data_seek(res, 0); if (!(tables=(char *) my_malloc(sizeof(char)*tot_length+4, MYF(MY_WME)))) @@ -507,7 +531,7 @@ static int process_all_tables_in_db(char *database) /* Skip tables with an engine of NULL (probably a view). */ if (row[1]) { - handle_request_for_tables(row[0], strlen(row[0])); + handle_request_for_tables(row[0], fixed_name_length(row[0])); } } mysql_free_result(res); @@ -741,7 +765,7 @@ int main(int argc, char **argv) for (i = 0; i < tables4repair.elements ; i++) { char *name= (char*) dynamic_array_ptr(&tables4repair, i); - handle_request_for_tables(name, strlen(name)); + handle_request_for_tables(name, fixed_name_length(name)); } } end: -- cgit v1.2.1