1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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.
This commit is contained in:
Vicențiu Ciorbaru
2017-02-10 12:46:44 +02:00
parent bdca350f59
commit dc90e24978
2 changed files with 26 additions and 19 deletions

View File

@ -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 */