Commit 5fd7e5e3 authored by unknown's avatar unknown

BUG#20839 Illegal error code: 155 returned downgrading from 5.1.12-> 5.1.11

post-review fixes.

Magnus suggested use of DYNAMIC_STRING instead of futzing with c strings.
also making usage of TABLEs clearer in store_schema_partitions_record.


client/mysqldump.c:
  Use DYNAMIC_STRING in code for dumping tablespaces
sql/sql_show.cc:
  Make use of schema_table versus the table we're showing info about in
  store_schema_partitions_record clearer
parent 9da02f68
...@@ -2759,86 +2759,66 @@ static int dump_all_tablespaces() ...@@ -2759,86 +2759,66 @@ static int dump_all_tablespaces()
static int dump_tablespaces_for_tables(char *db, char **table_names, int tables) static int dump_tablespaces_for_tables(char *db, char **table_names, int tables)
{ {
char *where; DYNAMIC_STRING where;
int r; int r;
int i; int i;
size_t sz= 200+tables*(NAME_LEN*2+3);
where= my_malloc(sz, MYF(MY_WME));
if (!where)
return 1;
char name_buff[NAME_LEN*2+3]; char name_buff[NAME_LEN*2+3];
mysql_real_escape_string(mysql, name_buff, db, strlen(db)); mysql_real_escape_string(mysql, name_buff, db, strlen(db));
snprintf(where,sz-1, init_dynamic_string(&where, " AND TABLESPACE_NAME IN ("
" AND TABLESPACE_NAME IN ("
"SELECT DISTINCT TABLESPACE_NAME FROM" "SELECT DISTINCT TABLESPACE_NAME FROM"
" INFORMATION_SCHEMA.PARTITIONS" " INFORMATION_SCHEMA.PARTITIONS"
" WHERE" " WHERE"
" TABLE_SCHEMA='%s'" " TABLE_SCHEMA='", 256, 1024);
" AND TABLE_NAME IN (", name_buff); dynstr_append(&where, name_buff);
dynstr_append(&where, "' AND TABLE_NAME IN (");
for (i=0 ; i<tables ; i++) for (i=0 ; i<tables ; i++)
{ {
mysql_real_escape_string(mysql, name_buff, mysql_real_escape_string(mysql, name_buff,
table_names[i], strlen(table_names[i])); table_names[i], strlen(table_names[i]));
strncat(where,"'",sz-3);
strncat(where,name_buff,sz-3); dynstr_append(&where, "'");
strncat(where,"'",sz-3); dynstr_append(&where, name_buff);
strncat(where,",",sz-3); dynstr_append(&where, "',");
} }
sz= strlen(where); where.str[--where.length]= '\0';
where[sz-1]= ')'; dynstr_append(&where,"))");
where[sz]= ')';
where[sz+1]= '\0';
DBUG_PRINT("info",("Dump TS for Tables where: %s",where)); DBUG_PRINT("info",("Dump TS for Tables where: %s",where));
r= dump_tablespaces(where); r= dump_tablespaces(where.str);
my_free(where, MYF(0)); dynstr_free(&where);
return r; return r;
} }
static int dump_tablespaces_for_databases(char** databases) static int dump_tablespaces_for_databases(char** databases)
{ {
char *where; DYNAMIC_STRING where;
int r; int r;
int i; int i;
size_t sz= 150; init_dynamic_string(&where, " AND TABLESPACE_NAME IN ("
for (i=0 ; databases[i]!=NULL ; i++)
sz+=(strlen(databases[i])*2)+3+1;
where= my_malloc(sz, MYF(MY_WME));
if(!where)
return 1;
strncpy(where,
" AND TABLESPACE_NAME IN ("
"SELECT DISTINCT TABLESPACE_NAME FROM" "SELECT DISTINCT TABLESPACE_NAME FROM"
" INFORMATION_SCHEMA.PARTITIONS" " INFORMATION_SCHEMA.PARTITIONS"
" WHERE" " WHERE"
" TABLE_SCHEMA IN (", sz-1); " TABLE_SCHEMA IN (", 256, 1024);
for (i=0 ; databases[i]!=NULL ; i++) for (i=0 ; databases[i]!=NULL ; i++)
{ {
char db_name_buff[NAME_LEN*2+3]; char db_name_buff[NAME_LEN*2+3];
mysql_real_escape_string(mysql, db_name_buff, mysql_real_escape_string(mysql, db_name_buff,
databases[i], strlen(databases[i])); databases[i], strlen(databases[i]));
strncat(where,"'",sz-3); dynstr_append(&where, "'");
strncat(where,db_name_buff,sz-3); dynstr_append(&where, db_name_buff);
strncat(where,"'",sz-3); dynstr_append(&where, "',");
strncat(where,",",sz-3);
} }
sz= strlen(where); where.str[--where.length]='\0';
where[sz-1]= ')'; dynstr_append(&where,"))");
where[sz]= ')';
where[sz+1]= '\0';
DBUG_PRINT("info",("Dump TS for DBs where: %s",where)); DBUG_PRINT("info",("Dump TS for DBs where: %s",where));
r= dump_tablespaces(where); r= dump_tablespaces(where.str);
my_free(where, MYF(0)); dynstr_free(&where);
return r; return r;
} }
...@@ -2847,7 +2827,7 @@ static int dump_tablespaces(char* ts_where) ...@@ -2847,7 +2827,7 @@ static int dump_tablespaces(char* ts_where)
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *tableres; MYSQL_RES *tableres;
char buf[FN_REFLEN]; char buf[FN_REFLEN];
char sqlbuf[1024]; DYNAMIC_STRING sqlbuf;
int first; int first;
/* /*
The following are used for parsing the EXTRA field The following are used for parsing the EXTRA field
...@@ -2856,7 +2836,7 @@ static int dump_tablespaces(char* ts_where) ...@@ -2856,7 +2836,7 @@ static int dump_tablespaces(char* ts_where)
char *ubs; char *ubs;
char *endsemi; char *endsemi;
snprintf(sqlbuf,sizeof(sqlbuf),"%s%s%s%s%s", init_dynamic_string(&sqlbuf,
"SELECT LOGFILE_GROUP_NAME," "SELECT LOGFILE_GROUP_NAME,"
" FILE_NAME," " FILE_NAME,"
" TOTAL_EXTENTS," " TOTAL_EXTENTS,"
...@@ -2866,18 +2846,24 @@ static int dump_tablespaces(char* ts_where) ...@@ -2866,18 +2846,24 @@ static int dump_tablespaces(char* ts_where)
" FROM INFORMATION_SCHEMA.FILES" " FROM INFORMATION_SCHEMA.FILES"
" WHERE FILE_TYPE = 'UNDO LOG'" " WHERE FILE_TYPE = 'UNDO LOG'"
" AND FILE_NAME IS NOT NULL", " AND FILE_NAME IS NOT NULL",
(ts_where)? 256, 1024);
if(ts_where)
{
dynstr_append(&sqlbuf,
" AND LOGFILE_GROUP_NAME IN (" " AND LOGFILE_GROUP_NAME IN ("
"SELECT DISTINCT LOGFILE_GROUP_NAME" "SELECT DISTINCT LOGFILE_GROUP_NAME"
" FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE'" " FROM INFORMATION_SCHEMA.FILES"
:"", " WHERE FILE_TYPE = 'DATAFILE'"
(ts_where)?ts_where:"", );
(ts_where)?")":"", dynstr_append(&sqlbuf, ts_where);
dynstr_append(&sqlbuf, ")");
}
dynstr_append(&sqlbuf,
" GROUP BY LOGFILE_GROUP_NAME, FILE_NAME" " GROUP BY LOGFILE_GROUP_NAME, FILE_NAME"
", ENGINE" ", ENGINE"
" ORDER BY LOGFILE_GROUP_NAME"); " ORDER BY LOGFILE_GROUP_NAME");
if (mysql_query(mysql, sqlbuf) || if (mysql_query(mysql, sqlbuf.str) ||
!(tableres = mysql_store_result(mysql))) !(tableres = mysql_store_result(mysql)))
{ {
if (mysql_errno(mysql) == ER_BAD_TABLE_ERROR || if (mysql_errno(mysql) == ER_BAD_TABLE_ERROR ||
...@@ -2944,8 +2930,8 @@ static int dump_tablespaces(char* ts_where) ...@@ -2944,8 +2930,8 @@ static int dump_tablespaces(char* ts_where)
strxmov(buf, row[0], NullS); strxmov(buf, row[0], NullS);
} }
} }
dynstr_free(&sqlbuf);
snprintf(sqlbuf,sizeof(sqlbuf),"%s%s%s", init_dynamic_string(&sqlbuf,
"SELECT DISTINCT TABLESPACE_NAME," "SELECT DISTINCT TABLESPACE_NAME,"
" FILE_NAME," " FILE_NAME,"
" LOGFILE_GROUP_NAME," " LOGFILE_GROUP_NAME,"
...@@ -2954,10 +2940,14 @@ static int dump_tablespaces(char* ts_where) ...@@ -2954,10 +2940,14 @@ static int dump_tablespaces(char* ts_where)
" ENGINE" " ENGINE"
" FROM INFORMATION_SCHEMA.FILES" " FROM INFORMATION_SCHEMA.FILES"
" WHERE FILE_TYPE = 'DATAFILE'", " WHERE FILE_TYPE = 'DATAFILE'",
(ts_where)?ts_where:"", 256, 1024);
" ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME");
if(ts_where)
dynstr_append(&sqlbuf, ts_where);
if (mysql_query_with_error_report(mysql, &tableres,sqlbuf)) dynstr_append(&sqlbuf, " ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME");
if (mysql_query_with_error_report(mysql, &tableres, sqlbuf.str))
return 1; return 1;
buf[0]= 0; buf[0]= 0;
...@@ -3003,6 +2993,8 @@ static int dump_tablespaces(char* ts_where) ...@@ -3003,6 +2993,8 @@ static int dump_tablespaces(char* ts_where)
strxmov(buf, row[0], NullS); strxmov(buf, row[0], NullS);
} }
} }
dynstr_free(&sqlbuf);
return 0; return 0;
} }
......
...@@ -3888,11 +3888,12 @@ static void collect_partition_expr(List<char> &field_list, String *str) ...@@ -3888,11 +3888,12 @@ static void collect_partition_expr(List<char> &field_list, String *str)
} }
static void store_schema_partitions_record(THD *thd, TABLE *table, static void store_schema_partitions_record(THD *thd, TABLE *schema_table,
TABLE *show_table, TABLE *showing_table,
partition_element *part_elem, partition_element *part_elem,
handler *file, uint part_id) handler *file, uint part_id)
{ {
TABLE* table= schema_table;
CHARSET_INFO *cs= system_charset_info; CHARSET_INFO *cs= system_charset_info;
PARTITION_INFO stat_info; PARTITION_INFO stat_info;
TIME time; TIME time;
...@@ -3950,8 +3951,7 @@ static void store_schema_partitions_record(THD *thd, TABLE *table, ...@@ -3950,8 +3951,7 @@ static void store_schema_partitions_record(THD *thd, TABLE *table,
strlen(part_elem->tablespace_name), cs); strlen(part_elem->tablespace_name), cs);
else else
{ {
DBUG_PRINT("info",("FOO")); char *ts= showing_table->file->get_tablespace_name(thd);
char *ts= show_table->file->get_tablespace_name(thd);
if(ts) if(ts)
table->field[24]->store(ts, strlen(ts), cs); table->field[24]->store(ts, strlen(ts), cs);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment