Skip to content

Commit 5e55648

Browse files
committed
Bug #57035 'ulonglong sql_mode' stored into ulong, is risky
and causes compiler warning In 5.5 THD::variables::sql_mode was changed from ulong to ulonglong. The problem was that several variables used to store sql_mode were still declared as ulong. This patch updates these declarations to sql_mode_t which is typedef'ed to ulonglong. The patch also adds a test case designed to break once someone adds a new SQL mode. This is done to serve as an indication that current tests which use "SET @@sql_mode= cast(pow(2,32)-1" to activate all SQL modes will then have to be updated.
1 parent f2ffc84 commit 5e55648

30 files changed

Lines changed: 104 additions & 74 deletions

mysql-test/r/variables.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,3 +1722,9 @@ set @@session.autocommit=t1_min(), @@session.autocommit=t1_max(),
17221722
drop table t1;
17231723
drop function t1_min;
17241724
drop function t1_max;
1725+
#
1726+
# Bug#57035 'ulonglong sql_mode' stored into ulong, is risky and causes
1727+
# compiler warning
1728+
#
1729+
SET @@sql_mode= 4294967296;
1730+
ERROR 42000: Variable 'sql_mode' can't be set to the value of '4294967296'

mysql-test/t/variables.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,3 +1464,23 @@ drop function t1_max;
14641464

14651465

14661466
###########################################################################
1467+
1468+
1469+
--echo #
1470+
--echo # Bug#57035 'ulonglong sql_mode' stored into ulong, is risky and causes
1471+
--echo # compiler warning
1472+
--echo #
1473+
1474+
# Several tests currently use "@@sql_mode= cast(pow(2,32)-1"
1475+
# to activate all SQL modes. This will stop working once
1476+
# someone adds a new flag. The test below is designed to break
1477+
# once this happens to indicate that other tests will have to
1478+
# be updated.
1479+
#
1480+
# The test does this by trying to set sql_mode to the next
1481+
# currently unused flag value and check that this currently fails.
1482+
# Once a new flag is added, this value will become valid and
1483+
# the statement below will succeed.
1484+
1485+
--error ER_WRONG_VALUE_FOR_VAR
1486+
SET @@sql_mode= 4294967296;

sql/event_data_objects.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ Event_job_data::load_from_row(THD *thd, TABLE *table)
430430
definer_host.str= strmake_root(&mem_root, ptr + 1, len);
431431
definer_host.length= len;
432432

433-
sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int();
433+
sql_mode= (sql_mode_t) table->field[ET_FIELD_SQL_MODE]->val_int();
434434

435435
DBUG_RETURN(FALSE);
436436
}
@@ -636,7 +636,7 @@ Event_timed::load_from_row(THD *thd, TABLE *table)
636636
else
637637
comment.length= 0;
638638

639-
sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int();
639+
sql_mode= (sql_mode_t) table->field[ET_FIELD_SQL_MODE]->val_int();
640640

641641
DBUG_RETURN(FALSE);
642642
}

sql/event_data_objects.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Event_timed : public Event_queue_element
132132
ulonglong created;
133133
ulonglong modified;
134134

135-
ulong sql_mode;
135+
sql_mode_t sql_mode;
136136

137137
class Stored_program_creation_ctx *creation_ctx;
138138
LEX_STRING body_utf8;
@@ -158,7 +158,7 @@ class Event_job_data : public Event_basic
158158
LEX_STRING definer_user;
159159
LEX_STRING definer_host;
160160

161-
ulong sql_mode;
161+
sql_mode_t sql_mode;
162162

163163
class Stored_program_creation_ctx *creation_ctx;
164164

sql/event_db_repository.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ mysql_event_fill_row(THD *thd,
199199
TABLE *table,
200200
Event_parse_data *et,
201201
sp_head *sp,
202-
ulong sql_mode,
202+
sql_mode_t sql_mode,
203203
my_bool is_update)
204204
{
205205
CHARSET_INFO *scs= system_charset_info;
@@ -622,7 +622,7 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data,
622622
int ret= 1;
623623
TABLE *table= NULL;
624624
sp_head *sp= thd->lex->sphead;
625-
ulong saved_mode= thd->variables.sql_mode;
625+
sql_mode_t saved_mode= thd->variables.sql_mode;
626626
/*
627627
Take a savepoint to release only the lock on mysql.event
628628
table at the end but keep the global read lock and
@@ -740,7 +740,7 @@ Event_db_repository::update_event(THD *thd, Event_parse_data *parse_data,
740740
CHARSET_INFO *scs= system_charset_info;
741741
TABLE *table= NULL;
742742
sp_head *sp= thd->lex->sphead;
743-
ulong saved_mode= thd->variables.sql_mode;
743+
sql_mode_t saved_mode= thd->variables.sql_mode;
744744
/*
745745
Take a savepoint to release only the lock on mysql.event
746746
table at the end but keep the global read lock and
@@ -1015,7 +1015,7 @@ Event_db_repository::load_named_event(THD *thd, LEX_STRING dbname,
10151015
LEX_STRING name, Event_basic *etn)
10161016
{
10171017
bool ret;
1018-
ulong saved_mode= thd->variables.sql_mode;
1018+
sql_mode_t saved_mode= thd->variables.sql_mode;
10191019
Open_tables_backup open_tables_backup;
10201020
TABLE_LIST event_table;
10211021

sql/ha_partition.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3095,7 +3095,7 @@ int ha_partition::write_row(uchar * buf)
30953095
my_bitmap_map *old_map;
30963096
THD *thd= ha_thd();
30973097
timestamp_auto_set_type saved_timestamp_type= table->timestamp_field_type;
3098-
ulong saved_sql_mode= thd->variables.sql_mode;
3098+
sql_mode_t saved_sql_mode= thd->variables.sql_mode;
30993099
bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null;
31003100
#ifdef NOT_NEEDED
31013101
uchar *rec0= m_rec0;

sql/item.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
10681068
THD *thd= table->in_use;
10691069
enum_check_fields tmp= thd->count_cuted_fields;
10701070
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
1071-
ulonglong sql_mode= thd->variables.sql_mode;
1071+
sql_mode_t sql_mode= thd->variables.sql_mode;
10721072
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
10731073
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
10741074
res= save_in_field(field, no_conversions);

sql/item_cmpfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
406406
if (!(*item)->with_subselect && (*item)->const_item())
407407
{
408408
TABLE *table= field->table;
409-
ulonglong orig_sql_mode= thd->variables.sql_mode;
409+
sql_mode_t orig_sql_mode= thd->variables.sql_mode;
410410
enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
411411
my_bitmap_map *old_maps[2];
412412
ulonglong UNINIT_VAR(orig_field_val); /* original field value if valid */

sql/item_timefunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ class Item_func_str_to_date :public Item_str_func
10411041
date_time_format_types cached_format_type;
10421042
timestamp_type cached_timestamp_type;
10431043
bool const_item;
1044-
ulonglong sql_mode;
1044+
sql_mode_t sql_mode;
10451045
public:
10461046
Item_func_str_to_date(Item *a, Item *b)
10471047
:Item_str_func(a, b), const_item(false)

sql/log_event.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ bool Query_log_event::write(IO_CACHE* file)
24982498
if (sql_mode_inited)
24992499
{
25002500
*start++= Q_SQL_MODE_CODE;
2501-
int8store(start, (ulonglong)sql_mode);
2501+
int8store(start, sql_mode);
25022502
start+= 8;
25032503
}
25042504
if (catalog_len) // i.e. this var is inited (false for 4.0 events)
@@ -2827,7 +2827,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
28272827
else
28282828
cache_type= Log_event::EVENT_STMT_CACHE;
28292829
DBUG_ASSERT(cache_type != Log_event::EVENT_INVALID_CACHE);
2830-
DBUG_PRINT("info",("Query_log_event has flags2: %lu sql_mode: %lu",
2830+
DBUG_PRINT("info",("Query_log_event has flags2: %lu sql_mode: %llu",
28312831
(ulong) flags2, sql_mode));
28322832
}
28332833
#endif /* MYSQL_CLIENT */
@@ -3042,7 +3042,7 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
30423042
#endif
30433043
CHECK_SPACE(pos, end, 8);
30443044
sql_mode_inited= 1;
3045-
sql_mode= (ulong) uint8korr(pos); // QQ: Fix when sql_mode is ulonglong
3045+
sql_mode= uint8korr(pos);
30463046
DBUG_PRINT("info",("In Query_log_event, read sql_mode: %s",
30473047
llstr(sql_mode, buff)));
30483048
pos+= 8;
@@ -3515,8 +3515,8 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
35153515
*/
35163516
if (sql_mode_inited)
35173517
thd->variables.sql_mode=
3518-
(ulong) ((thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE) |
3519-
(sql_mode & ~(ulong) MODE_NO_DIR_IN_CREATE));
3518+
(sql_mode_t) ((thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE) |
3519+
(sql_mode & ~(ulonglong) MODE_NO_DIR_IN_CREATE));
35203520
if (charset_inited)
35213521
{
35223522
if (rli->cached_charset_compare(charset))

0 commit comments

Comments
 (0)