Commit dc90e249 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

Define a helper class to allow for saving sql_mode using RAII

On construction the Sql_mode_save class stores the current THD's
sql_mode. On destruction, the THD's mode is restored.
parent bdca350f
......@@ -1198,11 +1198,10 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
{
TABLE *table;
READ_RECORD read_record_info;
bool return_val= TRUE;
bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE;
char tmp_name[SAFE_NAME_LEN+1];
int password_length;
sql_mode_t old_sql_mode= thd->variables.sql_mode;
Sql_mode_save old_mode_save(thd);
DBUG_ENTER("acl_load");
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
......@@ -1214,7 +1213,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
{
if (init_read_record(&read_record_info, thd, table, NULL, NULL,
1, 1, FALSE))
goto end;
DBUG_RETURN(TRUE);
table->use_all_columns();
while (!(read_record_info.read_record(&read_record_info)))
{
......@@ -1269,7 +1268,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
if (init_read_record(&read_record_info, thd, table=tables[USER_TABLE].table,
NULL, NULL, 1, 1, FALSE))
goto end;
DBUG_RETURN(TRUE);
table->use_all_columns();
username_char_length= MY_MIN(table->field[1]->char_length(),
......@@ -1280,7 +1279,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
{
sql_print_error("Fatal error: mysql.user table is damaged or in "
"unsupported 3.20 format.");
goto end;
DBUG_RETURN(TRUE);
}
DBUG_PRINT("info",("user table fields: %d, password length: %d",
......@@ -1294,7 +1293,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
mysql_mutex_unlock(&LOCK_global_system_variables);
sql_print_error("Fatal error: mysql.user table is in old format, "
"but server started with --secure-auth option.");
goto end;
DBUG_RETURN(TRUE);
}
mysql_user_table_is_in_short_password_format= true;
if (global_system_variables.old_passwords)
......@@ -1527,7 +1526,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
if (init_read_record(&read_record_info, thd, table=tables[DB_TABLE].table,
NULL, NULL, 1, 1, FALSE))
goto end;
DBUG_RETURN(TRUE);
table->use_all_columns();
while (!(read_record_info.read_record(&read_record_info)))
{
......@@ -1594,7 +1593,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
{
if (init_read_record(&read_record_info, thd, table,
NULL, NULL, 1, 1, FALSE))
goto end;
DBUG_RETURN(TRUE);
table->use_all_columns();
while (!(read_record_info.read_record(&read_record_info)))
{
......@@ -1603,10 +1602,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
if (proxy.check_validity(check_no_resolve))
continue;
if (push_dynamic(&acl_proxy_users, (uchar*) &proxy))
{
end_read_record(&read_record_info);
goto end;
}
DBUG_RETURN(TRUE);
}
my_qsort((uchar*) dynamic_element(&acl_proxy_users, 0, ACL_PROXY_USER*),
acl_proxy_users.elements,
......@@ -1624,7 +1620,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
{
if (init_read_record(&read_record_info, thd, table, NULL, NULL, 1, 1,
FALSE))
goto end;
DBUG_RETURN(TRUE);
table->use_all_columns();
MEM_ROOT temp_root;
......@@ -1662,12 +1658,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables)
init_check_host();
initialized=1;
return_val= FALSE;
end:
end_read_record(&read_record_info);
thd->variables.sql_mode= old_sql_mode;
DBUG_RETURN(return_val);
DBUG_RETURN(FALSE);
}
......
......@@ -5712,6 +5712,22 @@ inline bool binlog_should_compress(ulong len)
len >= opt_bin_log_compress_min_len;
}
/**
Save thd sql_mode on instantiation.
On destruction it resets the mode to the previously stored value.
*/
class Sql_mode_save
{
public:
Sql_mode_save(THD *thd) : thd(thd), old_mode(thd->variables.sql_mode) {}
~Sql_mode_save() { thd->variables.sql_mode = old_mode; }
private:
THD *thd;
sql_mode_t old_mode; // SQL mode saved at construction time.
};
#endif /* MYSQL_SERVER */
#endif /* SQL_CLASS_INCLUDED */
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