summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <jani@ua141d10.elisa.omakaista.fi>2007-04-10 16:28:47 +0300
committerunknown <jani@ua141d10.elisa.omakaista.fi>2007-04-10 16:28:47 +0300
commita2989a35f51ce3481317759f23da4e663c37ac15 (patch)
treecae620a49c973ba2cfe8c707254295e28815efcc /sql
parent37feda2596128fec33ac0e4fe8ff0cd35efd1dec (diff)
parent64e13b05e794e50777442a4c163e41793685833f (diff)
downloadmariadb-git-a2989a35f51ce3481317759f23da4e663c37ac15.tar.gz
Merge jamppa@bk-internal.mysql.com:/home/bk/mysql-5.1
into ua141d10.elisa.omakaista.fi:/home/my/bk/mysql-5.1-marvel client/mysqlcheck.c: Auto merged client/mysqldump.c: Auto merged include/my_time.h: Auto merged mysql-test/r/date_formats.result: Auto merged mysql-test/r/grant.result: Auto merged mysql-test/r/sp.result: Auto merged mysql-test/r/type_date.result: Auto merged mysql-test/r/type_datetime.result: Auto merged mysql-test/t/grant.test: Auto merged mysql-test/t/sp.test: Auto merged mysys/my_malloc.c: Auto merged mysys/my_static.c: Auto merged mysys/safemalloc.c: Auto merged sql/event_queue.cc: Auto merged sql/field.cc: Auto merged sql/field.h: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/handler.cc: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_func.h: Auto merged sql/log.cc: Auto merged sql/log_event.cc: Auto merged sql/mysql_priv.h: Auto merged sql/set_var.cc: Auto merged sql/slave.cc: Auto merged sql/sp.cc: Auto merged sql/sp_head.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_db.cc: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_update.cc: Auto merged sql/table.cc: Auto merged sql-common/client.c: Auto merged sql-common/my_time.c: Auto merged sql/time.cc: Auto merged storage/archive/ha_archive.cc: Auto merged storage/innobase/handler/ha_innodb.cc: Auto merged storage/ndb/src/mgmclient/CommandInterpreter.cpp: Auto merged tests/mysql_client_test.c: Auto merged client/client_priv.h: Manual merge with main 5.1 source. sql/event_data_objects.cc: Manual merge with main 5.1 source. sql/event_db_repository.cc: Manual merge with main 5.1 source. sql/mysqld.cc: Manual merge with main 5.1 source. sql/sql_load.cc: Manual merge with main 5.1 source. sql/sql_parse.cc: Manual merge with main 5.1 source.
Diffstat (limited to 'sql')
-rw-r--r--sql/CMakeLists.txt2
-rw-r--r--sql/event_data_objects.cc20
-rw-r--r--sql/event_db_repository.cc6
-rw-r--r--sql/event_queue.cc2
-rw-r--r--sql/field.cc121
-rw-r--r--sql/field.h30
-rw-r--r--sql/ha_ndbcluster.cc5
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/item.cc73
-rw-r--r--sql/item.h26
-rw-r--r--sql/item_cmpfunc.cc5
-rw-r--r--sql/item_func.h8
-rw-r--r--sql/item_timefunc.cc217
-rw-r--r--sql/item_timefunc.h48
-rw-r--r--sql/log.cc6
-rw-r--r--sql/my_decimal.cc2
-rw-r--r--sql/my_decimal.h2
-rw-r--r--sql/mysql_priv.h39
-rw-r--r--sql/mysqld.cc131
-rw-r--r--sql/net_serv.cc4
-rw-r--r--sql/protocol.cc12
-rw-r--r--sql/protocol.h18
-rw-r--r--sql/set_var.cc7
-rw-r--r--sql/sp.cc8
-rw-r--r--sql/sp_head.cc8
-rw-r--r--sql/sql_acl.cc31
-rw-r--r--sql/sql_base.cc29
-rw-r--r--sql/sql_cache.cc6
-rw-r--r--sql/sql_class.cc9
-rw-r--r--sql/sql_class.h10
-rw-r--r--sql/sql_connect.cc5
-rw-r--r--sql/sql_db.cc332
-rw-r--r--sql/sql_delete.cc4
-rw-r--r--sql/sql_error.cc10
-rw-r--r--sql/sql_insert.cc18
-rw-r--r--sql/sql_load.cc16
-rw-r--r--sql/sql_parse.cc58
-rw-r--r--sql/sql_prepare.cc2
-rw-r--r--sql/sql_show.cc30
-rw-r--r--sql/sql_table.cc2
-rw-r--r--sql/sql_update.cc56
-rw-r--r--sql/sql_view.cc42
-rw-r--r--sql/structs.h3
-rw-r--r--sql/table.cc5
-rw-r--r--sql/time.cc48
-rw-r--r--sql/tztime.cc92
-rw-r--r--sql/tztime.h12
-rw-r--r--sql/unireg.cc4
48 files changed, 924 insertions, 702 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 002aabb91b0..6569d06743e 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -79,7 +79,7 @@ ADD_EXECUTABLE(mysqld ../sql-common/client.c derror.cc des_key_file.cc
${PROJECT_SOURCE_DIR}/sql/sql_builtin.cc
${PROJECT_SOURCE_DIR}/sql/lex_hash.h)
TARGET_LINK_LIBRARIES(mysqld heap myisam myisammrg mysys yassl zlib dbug yassl
- taocrypt strings vio regex wsock32)
+ taocrypt strings vio regex wsock32 ws2_32)
IF(WITH_ARCHIVE_STORAGE_ENGINE)
TARGET_LINK_LIBRARIES(mysqld archive)
ENDIF(WITH_ARCHIVE_STORAGE_ENGINE)
diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc
index 3d2a5b277fe..56ac7c1a88d 100644
--- a/sql/event_data_objects.cc
+++ b/sql/event_data_objects.cc
@@ -286,7 +286,7 @@ int
Event_parse_data::init_execute_at(THD *thd)
{
my_bool not_used;
- TIME ltime;
+ MYSQL_TIME ltime;
my_time_t ltime_utc;
DBUG_ENTER("Event_parse_data::init_execute_at");
@@ -455,7 +455,7 @@ int
Event_parse_data::init_starts(THD *thd)
{
my_bool not_used;
- TIME ltime;
+ MYSQL_TIME ltime;
my_time_t ltime_utc;
DBUG_ENTER("Event_parse_data::init_starts");
@@ -509,7 +509,7 @@ int
Event_parse_data::init_ends(THD *thd)
{
my_bool not_used;
- TIME ltime;
+ MYSQL_TIME ltime;
my_time_t ltime_utc;
DBUG_ENTER("Event_parse_data::init_ends");
@@ -941,7 +941,7 @@ int
Event_queue_element::load_from_row(THD *thd, TABLE *table)
{
char *ptr;
- TIME time;
+ MYSQL_TIME time;
LEX_STRING tz_name;
DBUG_ENTER("Event_queue_element::load_from_row");
@@ -1136,7 +1136,7 @@ error:
*/
static
my_time_t
-add_interval(TIME *ltime, const Time_zone *time_zone,
+add_interval(MYSQL_TIME *ltime, const Time_zone *time_zone,
interval_type scale, INTERVAL interval)
{
if (date_add_interval(ltime, scale, interval))
@@ -1229,8 +1229,8 @@ bool get_next_time(const Time_zone *time_zone, my_time_t *next,
}
DBUG_PRINT("info", ("seconds: %ld months: %ld", (long) seconds, (long) months));
- TIME local_start;
- TIME local_now;
+ MYSQL_TIME local_start;
+ MYSQL_TIME local_now;
/* Convert times from UTC to local. */
{
@@ -1473,7 +1473,7 @@ Event_queue_element::compute_next_execution_time()
{
/*
Both starts and m_ends are set and time_now is between them (incl.)
- If last_executed is set then increase with m_expression. The new TIME is
+ If last_executed is set then increase with m_expression. The new MYSQL_TIME is
after m_ends set execute_at to 0. And check for on_completion
If not set then schedule for now.
*/
@@ -1615,7 +1615,7 @@ err:
/*
- Set the internal last_executed TIME struct to now. NOW is the
+ Set the internal last_executed MYSQL_TIME struct to now. NOW is the
time according to thd->query_start(), so the THD's clock.
SYNOPSIS
@@ -1686,7 +1686,7 @@ append_datetime(String *buf, Time_zone *time_zone, my_time_t secs,
Pass the buffer and the second param tells fills the buffer and
returns the number of chars to copy.
*/
- TIME time;
+ MYSQL_TIME time;
time_zone->gmt_sec_to_TIME(&time, secs);
buf->append(dtime_buff, my_datetime_to_str(&time, dtime_buff));
buf->append(STRING_WITH_LEN("'"));
diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc
index e3b45d5e0b2..864fa094190 100644
--- a/sql/event_db_repository.cc
+++ b/sql/event_db_repository.cc
@@ -218,7 +218,7 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et,
if (!et->starts_null)
{
- TIME time;
+ MYSQL_TIME time;
my_tz_UTC->gmt_sec_to_TIME(&time, et->starts);
fields[ET_FIELD_STARTS]->set_notnull();
@@ -227,7 +227,7 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et,
if (!et->ends_null)
{
- TIME time;
+ MYSQL_TIME time;
my_tz_UTC->gmt_sec_to_TIME(&time, et->ends);
fields[ET_FIELD_ENDS]->set_notnull();
@@ -246,7 +246,7 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et,
fields[ET_FIELD_STARTS]->set_null();
fields[ET_FIELD_ENDS]->set_null();
- TIME time;
+ MYSQL_TIME time;
my_tz_UTC->gmt_sec_to_TIME(&time, et->execute_at);
fields[ET_FIELD_EXECUTE_AT]->set_notnull();
diff --git a/sql/event_queue.cc b/sql/event_queue.cc
index 9b14d3cda7e..a7c31429cb3 100644
--- a/sql/event_queue.cc
+++ b/sql/event_queue.cc
@@ -737,7 +737,7 @@ Event_queue::dump_internal_status()
mutex_last_attempted_lock_at_line);
printf("WOC : %s\n", waiting_on_cond? "YES":"NO");
- TIME time;
+ MYSQL_TIME time;
my_tz_UTC->gmt_sec_to_TIME(&time, next_activation_at);
printf("Next activation : %04d-%02d-%02d %02d:%02d:%02d\n",
time.year, time.month, time.day, time.hour, time.minute, time.second);
diff --git a/sql/field.cc b/sql/field.cc
index a48a3ff7bcd..82f8283ba56 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1574,7 +1574,7 @@ uint Field::fill_cache_field(CACHE_FIELD *copy)
}
-bool Field::get_date(TIME *ltime,uint fuzzydate)
+bool Field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
{
char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
@@ -1585,7 +1585,7 @@ bool Field::get_date(TIME *ltime,uint fuzzydate)
return 0;
}
-bool Field::get_time(TIME *ltime)
+bool Field::get_time(MYSQL_TIME *ltime)
{
char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
@@ -1602,7 +1602,7 @@ bool Field::get_time(TIME *ltime)
Needs to be changed if/when we want to support different time formats
*/
-int Field::store_time(TIME *ltime, timestamp_type type_arg)
+int Field::store_time(MYSQL_TIME *ltime, timestamp_type type_arg)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
char buff[MAX_DATE_STRING_REP_LENGTH];
@@ -2550,7 +2550,7 @@ int Field_new_decimal::store_decimal(const my_decimal *decimal_value)
}
-int Field_new_decimal::store_time(TIME *ltime, timestamp_type t_type)
+int Field_new_decimal::store_time(MYSQL_TIME *ltime, timestamp_type t_type)
{
my_decimal decimal_value;
return store_value(date2my_decimal(ltime, &decimal_value));
@@ -4457,7 +4457,7 @@ timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME l_time;
+ MYSQL_TIME l_time;
my_time_t tmp= 0;
int error;
bool have_smth_to_conv;
@@ -4528,7 +4528,7 @@ int Field_timestamp::store(double nr)
int Field_timestamp::store(longlong nr, bool unsigned_val)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME l_time;
+ MYSQL_TIME l_time;
my_time_t timestamp= 0;
int error;
my_bool in_dst_time_gap;
@@ -4587,7 +4587,7 @@ longlong Field_timestamp::val_int(void)
{
ASSERT_COLUMN_MARKED_FOR_READ;
uint32 temp;
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
THD *thd= table ? table->in_use : current_thd;
#ifdef WORDS_BIGENDIAN
@@ -4613,7 +4613,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
{
ASSERT_COLUMN_MARKED_FOR_READ;
uint32 temp, temp2;
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
THD *thd= table ? table->in_use : current_thd;
char *to;
@@ -4682,7 +4682,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
}
-bool Field_timestamp::get_date(TIME *ltime, uint fuzzydate)
+bool Field_timestamp::get_date(MYSQL_TIME *ltime, uint fuzzydate)
{
long temp;
THD *thd= table ? table->in_use : current_thd;
@@ -4706,7 +4706,7 @@ bool Field_timestamp::get_date(TIME *ltime, uint fuzzydate)
return 0;
}
-bool Field_timestamp::get_time(TIME *ltime)
+bool Field_timestamp::get_time(MYSQL_TIME *ltime)
{
return Field_timestamp::get_date(ltime,0);
}
@@ -4714,7 +4714,7 @@ bool Field_timestamp::get_time(TIME *ltime)
bool Field_timestamp::send_binary(Protocol *protocol)
{
- TIME tm;
+ MYSQL_TIME tm;
Field_timestamp::get_date(&tm, 0);
return protocol->store(&tm);
}
@@ -4790,7 +4790,7 @@ void Field_timestamp::set_time()
int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
{
- TIME ltime;
+ MYSQL_TIME ltime;
long tmp;
int error= 0;
int warning;
@@ -4805,9 +4805,12 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
else
{
if (warning & MYSQL_TIME_WARN_TRUNCATED)
- set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
+ {
+ set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
WARN_DATA_TRUNCATED,
from, len, MYSQL_TIMESTAMP_TIME, 1);
+ error= 1;
+ }
if (warning & MYSQL_TIME_WARN_OUT_OF_RANGE)
{
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
@@ -4818,8 +4821,6 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
if (ltime.month)
ltime.day=0;
tmp=(ltime.day*24L+ltime.hour)*10000L+(ltime.minute*100+ltime.second);
- if (error > 1)
- error= 2;
}
if (ltime.neg)
@@ -4829,7 +4830,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
}
-int Field_time::store_time(TIME *ltime, timestamp_type time_type)
+int Field_time::store_time(MYSQL_TIME *ltime, timestamp_type time_type)
{
long tmp= ((ltime->month ? 0 : ltime->day * 24L) + ltime->hour) * 10000L +
(ltime->minute * 100 + ltime->second);
@@ -4938,7 +4939,7 @@ String *Field_time::val_str(String *val_buffer,
String *val_ptr __attribute__((unused)))
{
ASSERT_COLUMN_MARKED_FOR_READ;
- TIME ltime;
+ MYSQL_TIME ltime;
val_buffer->alloc(19);
long tmp=(long) sint3korr(ptr);
ltime.neg= 0;
@@ -4962,7 +4963,7 @@ String *Field_time::val_str(String *val_buffer,
DATE_FORMAT(time, "%l.%i %p")
*/
-bool Field_time::get_date(TIME *ltime, uint fuzzydate)
+bool Field_time::get_date(MYSQL_TIME *ltime, uint fuzzydate)
{
long tmp;
THD *thd= table ? table->in_use : current_thd;
@@ -4990,7 +4991,7 @@ bool Field_time::get_date(TIME *ltime, uint fuzzydate)
}
-bool Field_time::get_time(TIME *ltime)
+bool Field_time::get_time(MYSQL_TIME *ltime)
{
long tmp=(long) sint3korr(ptr);
ltime->neg=0;
@@ -5012,7 +5013,7 @@ bool Field_time::get_time(TIME *ltime)
bool Field_time::send_binary(Protocol *protocol)
{
- TIME tm;
+ MYSQL_TIME tm;
Field_time::get_time(&tm);
tm.day= tm.hour/24; // Move hours to days
tm.hour-= tm.day*24;
@@ -5170,7 +5171,7 @@ void Field_year::sql_type(String &res) const
int Field_date::store(const char *from, uint len,CHARSET_INFO *cs)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME l_time;
+ MYSQL_TIME l_time;
uint32 tmp;
int error;
THD *thd= table ? table->in_use : current_thd;
@@ -5227,7 +5228,7 @@ int Field_date::store(double nr)
int Field_date::store(longlong nr, bool unsigned_val)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME not_used;
+ MYSQL_TIME not_used;
int error;
longlong initial_nr= nr;
THD *thd= table ? table->in_use : current_thd;
@@ -5268,7 +5269,7 @@ int Field_date::store(longlong nr, bool unsigned_val)
bool Field_date::send_binary(Protocol *protocol)
{
longlong tmp= Field_date::val_int();
- TIME tm;
+ MYSQL_TIME tm;
tm.year= (uint32) tmp/10000L % 10000;
tm.month= (uint32) tmp/100 % 100;
tm.day= (uint32) tmp % 100;
@@ -5308,7 +5309,7 @@ String *Field_date::val_str(String *val_buffer,
String *val_ptr __attribute__((unused)))
{
ASSERT_COLUMN_MARKED_FOR_READ;
- TIME ltime;
+ MYSQL_TIME ltime;
val_buffer->alloc(field_length);
int32 tmp;
#ifdef WORDS_BIGENDIAN
@@ -5377,10 +5378,27 @@ void Field_date::sql_type(String &res) const
** In number context: YYYYMMDD
****************************************************************************/
+/*
+ Store string into a date field
+
+ SYNOPSIS
+ Field_newdate::store()
+ from Date string
+ len Length of date field
+ cs Character set (not used)
+
+ RETURN
+ 0 ok
+ 1 Value was cut during conversion
+ 2 Wrong date string
+ 3 Datetime value that was cut (warning level NOTE)
+*/
+
int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME l_time;
+ long tmp;
+ MYSQL_TIME l_time;
int error;
THD *thd= table ? table->in_use : current_thd;
enum enum_mysql_timestamp_type ret;
@@ -5391,20 +5409,23 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs)
MODE_INVALID_DATES))),
&error)) <= MYSQL_TIMESTAMP_ERROR)
{
- int3store(ptr,0L);
+ tmp= 0;
error= 2;
}
else
{
- int3store(ptr, l_time.day + l_time.month*32 + l_time.year*16*32);
- if(!error && (ret != MYSQL_TIMESTAMP_DATE))
- return 2;
+ tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
+ if (!error && (ret != MYSQL_TIMESTAMP_DATE))
+ error= 3; // Datetime was cut (note)
}
if (error)
- set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
+ set_datetime_warning(error == 3 ? MYSQL_ERROR::WARN_LEVEL_NOTE :
+ MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_DATA_TRUNCATED,
from, len, MYSQL_TIMESTAMP_DATE, 1);
+ int3store(ptr, tmp);
return error;
}
@@ -5425,7 +5446,7 @@ int Field_newdate::store(double nr)
int Field_newdate::store(longlong nr, bool unsigned_val)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME l_time;
+ MYSQL_TIME l_time;
longlong tmp;
int error;
THD *thd= table ? table->in_use : current_thd;
@@ -5452,7 +5473,7 @@ int Field_newdate::store(longlong nr, bool unsigned_val)
}
-int Field_newdate::store_time(TIME *ltime,timestamp_type time_type)
+int Field_newdate::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
long tmp;
@@ -5487,7 +5508,7 @@ int Field_newdate::store_time(TIME *ltime,timestamp_type time_type)
bool Field_newdate::send_binary(Protocol *protocol)
{
- TIME tm;
+ MYSQL_TIME tm;
Field_newdate::get_date(&tm,0);
return protocol->store_date(&tm);
}
@@ -5538,7 +5559,7 @@ String *Field_newdate::val_str(String *val_buffer,
}
-bool Field_newdate::get_date(TIME *ltime,uint fuzzydate)
+bool Field_newdate::get_date(MYSQL_TIME *ltime,uint fuzzydate)
{
uint32 tmp=(uint32) uint3korr(ptr);
ltime->day= tmp & 31;
@@ -5551,7 +5572,7 @@ bool Field_newdate::get_date(TIME *ltime,uint fuzzydate)
}
-bool Field_newdate::get_time(TIME *ltime)
+bool Field_newdate::get_time(MYSQL_TIME *ltime)
{
return Field_newdate::get_date(ltime,0);
}
@@ -5590,7 +5611,7 @@ void Field_newdate::sql_type(String &res) const
int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
int error;
ulonglong tmp= 0;
enum enum_mysql_timestamp_type func_res;
@@ -5643,7 +5664,7 @@ int Field_datetime::store(double nr)
int Field_datetime::store(longlong nr, bool unsigned_val)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
- TIME not_used;
+ MYSQL_TIME not_used;
int error;
longlong initial_nr= nr;
THD *thd= table ? table->in_use : current_thd;
@@ -5678,7 +5699,7 @@ int Field_datetime::store(longlong nr, bool unsigned_val)
}
-int Field_datetime::store_time(TIME *ltime,timestamp_type time_type)
+int Field_datetime::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
{
ASSERT_COLUMN_MARKED_FOR_WRITE;
longlong tmp;
@@ -5724,7 +5745,7 @@ int Field_datetime::store_time(TIME *ltime,timestamp_type time_type)
bool Field_datetime::send_binary(Protocol *protocol)
{
- TIME tm;
+ MYSQL_TIME tm;
Field_datetime::get_date(&tm, TIME_FUZZY_DATE);
return protocol->store(&tm);
}
@@ -5798,7 +5819,7 @@ String *Field_datetime::val_str(String *val_buffer,
return val_buffer;
}
-bool Field_datetime::get_date(TIME *ltime, uint fuzzydate)
+bool Field_datetime::get_date(MYSQL_TIME *ltime, uint fuzzydate)
{
longlong tmp=Field_datetime::val_int();
uint32 part1,part2;
@@ -5817,7 +5838,7 @@ bool Field_datetime::get_date(TIME *ltime, uint fuzzydate)
return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0;
}
-bool Field_datetime::get_time(TIME *ltime)
+bool Field_datetime::get_time(MYSQL_TIME *ltime)
{
return Field_datetime::get_date(ltime,0);
}
@@ -9354,10 +9375,13 @@ uint32 Field_blob::max_display_length()
NOTE
This function won't produce warning and increase cut fields counter
- if count_cuted_fields == FIELD_CHECK_IGNORE for current thread.
+ if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
+
+ if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
+ This allows us to avoid notes in optimisation, like convert_constant_item().
RETURN VALUE
- 1 if count_cuted_fields == FIELD_CHECK_IGNORE
+ 1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
0 otherwise
*/
@@ -9377,7 +9401,7 @@ Field::set_warning(MYSQL_ERROR::enum_warning_level level, uint code,
thd->row_count);
return 0;
}
- return 1;
+ return level >= MYSQL_ERROR::WARN_LEVEL_WARN;
}
@@ -9405,9 +9429,10 @@ Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code,
timestamp_type ts_type, int cuted_increment)
{
THD *thd= table ? table->in_use : current_thd;
- if (thd->really_abort_on_warning() ||
+ if ((thd->really_abort_on_warning() &&
+ level >= MYSQL_ERROR::WARN_LEVEL_WARN) ||
set_warning(level, code, cuted_increment))
- make_truncated_value_warning(thd, str, str_length, ts_type,
+ make_truncated_value_warning(thd, level, str, str_length, ts_type,
field_name);
}
@@ -9440,7 +9465,7 @@ Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code,
{
char str_nr[22];
char *str_end= longlong10_to_str(nr, str_nr, -10);
- make_truncated_value_warning(thd, str_nr, (uint) (str_end - str_nr),
+ make_truncated_value_warning(thd, level, str_nr, (uint) (str_end - str_nr),
ts_type, field_name);
}
}
@@ -9473,7 +9498,7 @@ Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code,
/* DBL_DIG is enough to print '-[digits].E+###' */
char str_nr[DBL_DIG + 8];
uint str_len= my_sprintf(str_nr, (str_nr, "%g", nr));
- make_truncated_value_warning(thd, str_nr, str_len, ts_type,
+ make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
field_name);
}
}
diff --git a/sql/field.h b/sql/field.h
index 3d1ac7528c1..441ff9079c1 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -98,7 +98,7 @@ public:
virtual int store(double nr)=0;
virtual int store(longlong nr, bool unsigned_val)=0;
virtual int store_decimal(const my_decimal *d)=0;
- virtual int store_time(TIME *ltime, timestamp_type t_type);
+ virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
virtual double val_real(void)=0;
virtual longlong val_int(void)=0;
virtual my_decimal *val_decimal(my_decimal *);
@@ -347,8 +347,8 @@ public:
}
void copy_from_tmp(int offset);
uint fill_cache_field(struct st_cache_field *copy);
- virtual bool get_date(TIME *ltime,uint fuzzydate);
- virtual bool get_time(TIME *ltime);
+ virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
+ virtual bool get_time(MYSQL_TIME *ltime);
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
virtual bool has_charset(void) const { return FALSE; }
@@ -567,7 +567,7 @@ public:
int store(const char *to, uint length, CHARSET_INFO *charset);
int store(double nr);
int store(longlong nr, bool unsigned_val);
- int store_time(TIME *ltime, timestamp_type t_type);
+ int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
int store_decimal(const my_decimal *);
double val_real(void);
longlong val_int(void);
@@ -910,8 +910,8 @@ public:
longget(tmp,ptr);
return tmp;
}
- bool get_date(TIME *ltime,uint fuzzydate);
- bool get_time(TIME *ltime);
+ bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
+ bool get_time(MYSQL_TIME *ltime);
timestamp_auto_set_type get_auto_set_type() const;
};
@@ -984,7 +984,7 @@ public:
int store(const char *to,uint length,CHARSET_INFO *charset);
int store(double nr);
int store(longlong nr, bool unsigned_val);
- int store_time(TIME *ltime, timestamp_type type);
+ int store_time(MYSQL_TIME *ltime, timestamp_type type);
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
double val_real(void);
longlong val_int(void);
@@ -996,8 +996,8 @@ public:
void sql_type(String &str) const;
bool can_be_compared_as_longlong() const { return TRUE; }
bool zero_pack() const { return 1; }
- bool get_date(TIME *ltime,uint fuzzydate);
- bool get_time(TIME *ltime);
+ bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
+ bool get_time(MYSQL_TIME *ltime);
};
@@ -1016,7 +1016,7 @@ public:
enum_field_types type() const { return MYSQL_TYPE_TIME;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
enum Item_result cmp_type () const { return INT_RESULT; }
- int store_time(TIME *ltime, timestamp_type type);
+ int store_time(MYSQL_TIME *ltime, timestamp_type type);
int store(const char *to,uint length,CHARSET_INFO *charset);
int store(double nr);
int store(longlong nr, bool unsigned_val);
@@ -1024,9 +1024,9 @@ public:
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
- bool get_date(TIME *ltime, uint fuzzydate);
+ bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
bool send_binary(Protocol *protocol);
- bool get_time(TIME *ltime);
+ bool get_time(MYSQL_TIME *ltime);
int cmp(const char *,const char*);
void sort_string(char *buff,uint length);
uint32 pack_length() const { return 3; }
@@ -1057,7 +1057,7 @@ public:
int store(const char *to,uint length,CHARSET_INFO *charset);
int store(double nr);
int store(longlong nr, bool unsigned_val);
- int store_time(TIME *ltime, timestamp_type type);
+ int store_time(MYSQL_TIME *ltime, timestamp_type type);
int reset(void)
{
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
@@ -1073,8 +1073,8 @@ public:
void sql_type(String &str) const;
bool can_be_compared_as_longlong() const { return TRUE; }
bool zero_pack() const { return 1; }
- bool get_date(TIME *ltime,uint fuzzydate);
- bool get_time(TIME *ltime);
+ bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
+ bool get_time(MYSQL_TIME *ltime);
};
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index d12f94c6967..9721b877e01 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -4244,8 +4244,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
{
m_transaction_on= FALSE;
/* Would be simpler if has_transactions() didn't always say "yes" */
- thd->options|= OPTION_STATUS_NO_TRANS_UPDATE;
- thd->no_trans_update= TRUE;
+ thd->no_trans_update.all= thd->no_trans_update.stmt= TRUE;
}
else if (!thd->transaction.on)
m_transaction_on= FALSE;
@@ -4943,7 +4942,7 @@ int ha_ndbcluster::create(const char *name,
for (i= 0; i < form->s->fields; i++)
{
Field *field= form->field[i];
- DBUG_PRINT("info", ("name: %s, type: %u, pack_length: %d",
+ DBUG_PRINT("info", ("name: %s type: %u pack_length: %d",
field->field_name, field->real_type(),
field->pack_length()));
if ((my_errno= create_ndb_column(col, field, create_info)))
diff --git a/sql/handler.cc b/sql/handler.cc
index 617bf9ee378..e0018a66400 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -844,7 +844,7 @@ int ha_rollback_trans(THD *thd, bool all)
the error log; but we don't want users to wonder why they have this
message in the error log, so we don't send it.
*/
- if (is_real_trans && (thd->options & OPTION_STATUS_NO_TRANS_UPDATE) &&
+ if (is_real_trans && thd->no_trans_update.all &&
!thd->slave_thread && thd->killed != THD::KILL_CONNECTION)
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARNING_NOT_COMPLETE_ROLLBACK,
diff --git a/sql/item.cc b/sql/item.cc
index 613b72ad05e..3f4a121b6af 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -267,7 +267,7 @@ my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE))
{
my_decimal_set_zero(decimal_value);
@@ -280,7 +280,7 @@ my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_time(&ltime))
{
my_decimal_set_zero(decimal_value);
@@ -315,7 +315,7 @@ longlong Item::val_int_from_decimal()
int Item::save_time_in_field(Field *field)
{
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_time(&ltime))
return set_field_to_null(field);
field->set_notnull();
@@ -325,7 +325,7 @@ int Item::save_time_in_field(Field *field)
int Item::save_date_in_field(Field *field)
{
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE))
return set_field_to_null(field);
field->set_notnull();
@@ -853,22 +853,40 @@ bool Item_string::eq(const Item *item, bool binary_cmp) const
/*
- Get the value of the function as a TIME structure.
+ Get the value of the function as a MYSQL_TIME structure.
As a extra convenience the time structure is reset on error!
*/
-bool Item::get_date(TIME *ltime,uint fuzzydate)
+bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate)
{
- char buff[40];
- String tmp(buff,sizeof(buff), &my_charset_bin),*res;
- if (!(res=val_str(&tmp)) ||
- str_to_datetime_with_warn(res->ptr(), res->length(),
- ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
+ if (result_type() == STRING_RESULT)
{
- bzero((char*) ltime,sizeof(*ltime));
- return 1;
+ char buff[40];
+ String tmp(buff,sizeof(buff), &my_charset_bin),*res;
+ if (!(res=val_str(&tmp)) ||
+ str_to_datetime_with_warn(res->ptr(), res->length(),
+ ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
+ goto err;
+ }
+ else
+ {
+ longlong value= val_int();
+ int was_cut;
+ if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == LL(-1))
+ {
+ char buff[22], *end;
+ end= longlong10_to_str(value, buff, -10);
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
+ NullS);
+ goto err;
+ }
}
return 0;
+
+err:
+ bzero((char*) ltime,sizeof(*ltime));
+ return 1;
}
/*
@@ -876,7 +894,7 @@ bool Item::get_date(TIME *ltime,uint fuzzydate)
As a extra convenience the time structure is reset on error!
*/
-bool Item::get_time(TIME *ltime)
+bool Item::get_time(MYSQL_TIME *ltime)
{
char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
@@ -1873,7 +1891,7 @@ String *Item_field::str_result(String *str)
return result_field->val_str(str,&str_value);
}
-bool Item_field::get_date(TIME *ltime,uint fuzzydate)
+bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
{
if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
{
@@ -1883,7 +1901,7 @@ bool Item_field::get_date(TIME *ltime,uint fuzzydate)
return 0;
}
-bool Item_field::get_date_result(TIME *ltime,uint fuzzydate)
+bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
{
if ((null_value=result_field->is_null()) ||
result_field->get_date(ltime,fuzzydate))
@@ -1894,7 +1912,7 @@ bool Item_field::get_date_result(TIME *ltime,uint fuzzydate)
return 0;
}
-bool Item_field::get_time(TIME *ltime)
+bool Item_field::get_time(MYSQL_TIME *ltime)
{
if ((null_value=field->is_null()) || field->get_time(ltime))
{
@@ -2421,7 +2439,7 @@ void Item_param::set_decimal(const char *str, ulong length)
/*
- Set parameter value from TIME value.
+ Set parameter value from MYSQL_TIME value.
SYNOPSIS
set_time()
@@ -2435,7 +2453,7 @@ void Item_param::set_decimal(const char *str, ulong length)
the fact that even wrong value sent over binary protocol fits into
MAX_DATE_STRING_REP_LENGTH buffer.
*/
-void Item_param::set_time(TIME *tm, timestamp_type time_type,
+void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
uint32 max_length_arg)
{
DBUG_ENTER("Item_param::set_time");
@@ -2450,7 +2468,8 @@ void Item_param::set_time(TIME *tm, timestamp_type time_type,
{
char buff[MAX_DATE_STRING_REP_LENGTH];
uint length= my_TIME_to_str(&value.time, buff);
- make_truncated_value_warning(current_thd, buff, length, time_type, 0);
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ buff, length, time_type, 0);
set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
}
@@ -2652,7 +2671,7 @@ int Item_param::save_in_field(Field *field, bool no_conversions)
}
-bool Item_param::get_time(TIME *res)
+bool Item_param::get_time(MYSQL_TIME *res)
{
if (state == TIME_VALUE)
{
@@ -2667,7 +2686,7 @@ bool Item_param::get_time(TIME *res)
}
-bool Item_param::get_date(TIME *res, uint fuzzydate)
+bool Item_param::get_date(MYSQL_TIME *res, uint fuzzydate)
{
if (state == TIME_VALUE)
{
@@ -3093,7 +3112,7 @@ String* Item_ref_null_helper::val_str(String* s)
}
-bool Item_ref_null_helper::get_date(TIME *ltime, uint fuzzydate)
+bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, uint fuzzydate)
{
return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
}
@@ -4931,7 +4950,7 @@ bool Item::send(Protocol *protocol, String *buffer)
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_TIMESTAMP:
{
- TIME tm;
+ MYSQL_TIME tm;
get_date(&tm, TIME_FUZZY_DATE);
if (!null_value)
{
@@ -4944,7 +4963,7 @@ bool Item::send(Protocol *protocol, String *buffer)
}
case MYSQL_TYPE_TIME:
{
- TIME tm;
+ MYSQL_TIME tm;
get_time(&tm);
if (!null_value)
result= protocol->store_time(&tm);
@@ -5496,7 +5515,7 @@ bool Item_ref::is_null()
}
-bool Item_ref::get_date(TIME *ltime,uint fuzzydate)
+bool Item_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
{
return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
}
@@ -5595,7 +5614,7 @@ bool Item_direct_ref::is_null()
}
-bool Item_direct_ref::get_date(TIME *ltime,uint fuzzydate)
+bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
{
return (null_value=(*ref)->get_date(ltime,fuzzydate));
}
diff --git a/sql/item.h b/sql/item.h
index 429a1d33041..c46b90935f6 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -730,9 +730,9 @@ public:
/* Called for items that really have to be split */
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
Item **ref, bool skip_registered);
- virtual bool get_date(TIME *ltime,uint fuzzydate);
- virtual bool get_time(TIME *ltime);
- virtual bool get_date_result(TIME *ltime,uint fuzzydate)
+ virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
+ virtual bool get_time(MYSQL_TIME *ltime);
+ virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
{ return get_date(ltime,fuzzydate); }
/*
The method allows to determine nullness of a complex expression
@@ -1372,9 +1372,9 @@ public:
}
Field *get_tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
- bool get_date(TIME *ltime,uint fuzzydate);
- bool get_date_result(TIME *ltime,uint fuzzydate);
- bool get_time(TIME *ltime);
+ bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
+ bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
+ bool get_time(MYSQL_TIME *ltime);
bool is_null() { return field->is_null(); }
void update_null_value();
Item *get_tmp_table_item(THD *thd);
@@ -1498,7 +1498,7 @@ public:
*/
CHARSET_INFO *final_character_set_of_str_value;
} cs_info;
- TIME time;
+ MYSQL_TIME time;
} value;
/* Cached values for virtual methods to save us one switch. */
@@ -1530,8 +1530,8 @@ public:
longlong val_int();
my_decimal *val_decimal(my_decimal*);
String *val_str(String*);
- bool get_time(TIME *tm);
- bool get_date(TIME *tm, uint fuzzydate);
+ bool get_time(MYSQL_TIME *tm);
+ bool get_date(MYSQL_TIME *tm, uint fuzzydate);
int save_in_field(Field *field, bool no_conversions);
void set_null();
@@ -1540,7 +1540,7 @@ public:
void set_decimal(const char *str, ulong length);
bool set_str(const char *str, ulong length);
bool set_longdata(const char *str, ulong length);
- void set_time(TIME *tm, timestamp_type type, uint32 max_length_arg);
+ void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
bool set_from_user_var(THD *thd, const user_var_entry *entry);
void reset();
/*
@@ -1979,7 +1979,7 @@ public:
bool val_bool();
String *val_str(String* tmp);
bool is_null();
- bool get_date(TIME *ltime,uint fuzzydate);
+ bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
double val_result();
longlong val_int_result();
String *str_result(String* tmp);
@@ -2056,7 +2056,7 @@ public:
my_decimal *val_decimal(my_decimal *);
bool val_bool();
bool is_null();
- bool get_date(TIME *ltime,uint fuzzydate);
+ bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
virtual Ref_Type ref_type() { return DIRECT_REF; }
};
@@ -2142,7 +2142,7 @@ public:
String* val_str(String* s);
my_decimal *val_decimal(my_decimal *);
bool val_bool();
- bool get_date(TIME *ltime, uint fuzzydate);
+ bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
void print(String *str);
/*
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 36326b46be6..451fb1bea7e 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -293,6 +293,7 @@ static bool convert_constant_item(THD *thd, Field *field, Item **item)
{
TABLE *table= field->table;
ulong orig_sql_mode= thd->variables.sql_mode;
+ enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
my_bitmap_map *old_write_map;
my_bitmap_map *old_read_map;
@@ -306,6 +307,7 @@ static bool convert_constant_item(THD *thd, Field *field, Item **item)
}
/* For comparison purposes allow invalid dates like 2000-01-32 */
thd->variables.sql_mode|= MODE_INVALID_DATES;
+ thd->count_cuted_fields= CHECK_FIELD_IGNORE;
if (!(*item)->save_in_field(field, 1) && !((*item)->null_value))
{
Item *tmp= new Item_int_with_ref(field->val_int(), *item,
@@ -315,6 +317,7 @@ static bool convert_constant_item(THD *thd, Field *field, Item **item)
result= 1; // Item was replaced
}
thd->variables.sql_mode= orig_sql_mode;
+ thd->count_cuted_fields= orig_count_cuted_fields;
if (table)
{
dbug_tmp_restore_column_map(table->write_set, old_write_map);
@@ -2422,7 +2425,7 @@ byte *in_row::get_value(Item *item)
void in_row::set(uint pos, Item *item)
{
DBUG_ENTER("in_row::set");
- DBUG_PRINT("enter", ("pos %u item 0x%lx", pos, (ulong) item));
+ DBUG_PRINT("enter", ("pos: %u item: 0x%lx", pos, (ulong) item));
((cmp_item_row*) base)[pos].store_value_by_template(&tmp, item);
DBUG_VOID_RETURN;
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 610b47d4fca..28f11e27306 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -147,11 +147,11 @@ public:
void count_only_length();
void count_real_length();
void count_decimal_length();
- inline bool get_arg0_date(TIME *ltime, uint fuzzy_date)
+ inline bool get_arg0_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
return (null_value=args[0]->get_date(ltime, fuzzy_date));
}
- inline bool get_arg0_time(TIME *ltime)
+ inline bool get_arg0_time(MYSQL_TIME *ltime)
{
return (null_value=args[0]->get_time(ltime));
}
@@ -1443,7 +1443,7 @@ private:
bool execute();
bool execute_impl(THD *thd);
bool init_result_field(THD *thd);
-
+
public:
Item_func_sp(Name_resolution_context *context_arg, sp_name *name);
@@ -1454,6 +1454,8 @@ public:
virtual ~Item_func_sp()
{}
+ table_map used_tables() const { return RAND_TABLE_BIT; }
+
void cleanup();
const char *func_name() const;
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 7636deab782..4d6ca2a9b3e 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -46,7 +46,7 @@
the microseconds twice.
*/
-static bool make_datetime(date_time_format_types format, TIME *ltime,
+static bool make_datetime(date_time_format_types format, MYSQL_TIME *ltime,
String *str)
{
char *buff;
@@ -95,7 +95,7 @@ static bool make_datetime(date_time_format_types format, TIME *ltime,
/*
- Wrapper over make_datetime() with validation of the input TIME value
+ Wrapper over make_datetime() with validation of the input MYSQL_TIME value
NOTE
see make_datetime() for more information
@@ -105,7 +105,7 @@ static bool make_datetime(date_time_format_types format, TIME *ltime,
0 otherwise
*/
-static bool make_datetime_with_warn(date_time_format_types format, TIME *ltime,
+static bool make_datetime_with_warn(date_time_format_types format, MYSQL_TIME *ltime,
String *str)
{
int warning= 0;
@@ -117,14 +117,15 @@ static bool make_datetime_with_warn(date_time_format_types format, TIME *ltime,
if (!warning)
return 0;
- make_truncated_value_warning(current_thd, str->ptr(), str->length(),
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ str->ptr(), str->length(),
MYSQL_TIMESTAMP_TIME, NullS);
return make_datetime(format, ltime, str);
}
/*
- Wrapper over make_time() with validation of the input TIME value
+ Wrapper over make_time() with validation of the input MYSQL_TIME value
NOTE
see make_time() for more info
@@ -135,7 +136,7 @@ static bool make_datetime_with_warn(date_time_format_types format, TIME *ltime,
*/
static bool make_time_with_warn(const DATE_TIME_FORMAT *format,
- TIME *l_time, String *str)
+ MYSQL_TIME *l_time, String *str)
{
int warning= 0;
make_time(format, l_time, str);
@@ -143,7 +144,8 @@ static bool make_time_with_warn(const DATE_TIME_FORMAT *format,
return 1;
if (warning)
{
- make_truncated_value_warning(current_thd, str->ptr(), str->length(),
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ str->ptr(), str->length(),
MYSQL_TIMESTAMP_TIME, NullS);
make_time(format, l_time, str);
}
@@ -153,16 +155,16 @@ static bool make_time_with_warn(const DATE_TIME_FORMAT *format,
/*
- Convert seconds to TIME value with overflow checking
+ Convert seconds to MYSQL_TIME value with overflow checking
SYNOPSIS:
sec_to_time()
seconds number of seconds
unsigned_flag 1, if 'seconds' is unsigned, 0, otherwise
- ltime output TIME value
+ ltime output MYSQL_TIME value
DESCRIPTION
- If the 'seconds' argument is inside TIME data range, convert it to a
+ If the 'seconds' argument is inside MYSQL_TIME data range, convert it to a
corresponding value.
Otherwise, truncate the resulting value to the nearest endpoint, and
produce a warning message.
@@ -172,7 +174,7 @@ static bool make_time_with_warn(const DATE_TIME_FORMAT *format,
0 otherwise
*/
-static bool sec_to_time(longlong seconds, bool unsigned_flag, TIME *ltime)
+static bool sec_to_time(longlong seconds, bool unsigned_flag, MYSQL_TIME *ltime)
{
uint sec;
@@ -205,7 +207,8 @@ overflow:
char buf[22];
int len= (int)(longlong10_to_str(seconds, buf, unsigned_flag ? 10 : -10)
- buf);
- make_truncated_value_warning(current_thd, buf, len, MYSQL_TIMESTAMP_TIME,
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ buf, len, MYSQL_TIMESTAMP_TIME,
NullS);
return 1;
@@ -224,7 +227,7 @@ static DATE_TIME_FORMAT time_24hrs_format= {{0}, '\0', 0,
{(char *)"%H:%i:%S", 8}};
/*
- Extract datetime value to TIME struct from string value
+ Extract datetime value to MYSQL_TIME struct from string value
according to format string.
SYNOPSIS
@@ -257,7 +260,7 @@ static DATE_TIME_FORMAT time_24hrs_format= {{0}, '\0', 0,
*/
static bool extract_date_time(DATE_TIME_FORMAT *format,
- const char *val, uint length, TIME *l_time,
+ const char *val, uint length, MYSQL_TIME *l_time,
timestamp_type cached_timestamp_type,
const char **sub_pattern_end,
const char *date_time_type)
@@ -305,13 +308,15 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
case 'Y':
tmp= (char*) val + min(4, val_len);
l_time->year= (int) my_strtoll10(val, &tmp, &error);
+ if ((int) (tmp-val) <= 2)
+ l_time->year= year_2000_handling(l_time->year);
val= tmp;
break;
case 'y':
tmp= (char*) val + min(2, val_len);
l_time->year= (int) my_strtoll10(val, &tmp, &error);
val= tmp;
- l_time->year+= (l_time->year < YY_PART_YEAR ? 2000 : 1900);
+ l_time->year= year_2000_handling(l_time->year);
break;
/* Month */
@@ -514,7 +519,8 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
if (yearday > 0)
{
- uint days= calc_daynr(l_time->year,1,1) + yearday - 1;
+ uint days;
+ days= calc_daynr(l_time->year,1,1) + yearday - 1;
if (days <= 0 || days > MAX_DAY_NUMBER)
goto err;
get_date_from_daynr(days,&l_time->year,&l_time->month,&l_time->day);
@@ -576,7 +582,8 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
{
if (!my_isspace(&my_charset_latin1,*val))
{
- make_truncated_value_warning(current_thd, val_begin, length,
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ val_begin, length,
cached_timestamp_type, NullS);
break;
}
@@ -600,7 +607,7 @@ err:
Create a formated date/time value in a string
*/
-bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time,
+bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
timestamp_type type, String *str)
{
char intbuff[15];
@@ -921,7 +928,7 @@ longlong Item_func_period_diff::val_int()
longlong Item_func_to_days::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
return 0;
return (longlong) calc_daynr(ltime.year,ltime.month,ltime.day);
@@ -958,7 +965,7 @@ enum_monotonicity_info Item_func_to_days::get_monotonicity_info() const
longlong Item_func_dayofyear::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_arg0_date(&ltime,TIME_NO_ZERO_DATE))
return 0;
return (longlong) calc_daynr(ltime.year,ltime.month,ltime.day) -
@@ -968,7 +975,7 @@ longlong Item_func_dayofyear::val_int()
longlong Item_func_dayofmonth::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
(void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
return (longlong) ltime.day;
}
@@ -976,7 +983,7 @@ longlong Item_func_dayofmonth::val_int()
longlong Item_func_month::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
(void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
return (longlong) ltime.month;
}
@@ -1006,7 +1013,7 @@ String* Item_func_monthname::val_str(String* str)
longlong Item_func_quarter::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
return 0;
return (longlong) ((ltime.month+2)/3);
@@ -1015,7 +1022,7 @@ longlong Item_func_quarter::val_int()
longlong Item_func_hour::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
(void) get_arg0_time(&ltime);
return ltime.hour;
}
@@ -1023,7 +1030,7 @@ longlong Item_func_hour::val_int()
longlong Item_func_minute::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
(void) get_arg0_time(&ltime);
return ltime.minute;
}
@@ -1032,7 +1039,7 @@ longlong Item_func_minute::val_int()
longlong Item_func_second::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
(void) get_arg0_time(&ltime);
return ltime.second;
}
@@ -1079,7 +1086,7 @@ longlong Item_func_week::val_int()
{
DBUG_ASSERT(fixed == 1);
uint year;
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
return 0;
return (longlong) calc_week(&ltime,
@@ -1092,7 +1099,7 @@ longlong Item_func_yearweek::val_int()
{
DBUG_ASSERT(fixed == 1);
uint year,week;
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
return 0;
week= calc_week(&ltime,
@@ -1105,7 +1112,7 @@ longlong Item_func_yearweek::val_int()
longlong Item_func_weekday::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
return 0;
@@ -1135,7 +1142,7 @@ String* Item_func_dayname::val_str(String* str)
longlong Item_func_year::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
(void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
return (longlong) ltime.year;
}
@@ -1166,7 +1173,7 @@ enum_monotonicity_info Item_func_year::get_monotonicity_info() const
longlong Item_func_unix_timestamp::val_int()
{
- TIME ltime;
+ MYSQL_TIME ltime;
my_bool not_used;
DBUG_ASSERT(fixed == 1);
@@ -1197,7 +1204,7 @@ longlong Item_func_unix_timestamp::val_int()
longlong Item_func_time_to_sec::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
longlong seconds;
(void) get_arg0_time(&ltime);
seconds=ltime.hour*3600L+ltime.minute*60+ltime.second;
@@ -1369,7 +1376,7 @@ bool get_interval_value(Item *args,interval_type int_type,
String *Item_date::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE))
return (String *) 0;
if (str->alloc(11))
@@ -1385,19 +1392,19 @@ String *Item_date::val_str(String *str)
longlong Item_date::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE))
return 0;
return (longlong) (ltime.year*10000L+ltime.month*100+ltime.day);
}
-bool Item_func_from_days::get_date(TIME *ltime, uint fuzzy_date)
+bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
longlong value=args[0]->val_int();
if ((null_value=args[0]->null_value))
return 1;
- bzero(ltime, sizeof(TIME));
+ bzero(ltime, sizeof(MYSQL_TIME));
get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day);
ltime->time_type= MYSQL_TIMESTAMP_DATE;
return 0;
@@ -1431,10 +1438,10 @@ String *Item_func_curdate::val_str(String *str)
}
/*
- Converts current time in my_time_t to TIME represenatation for local
+ Converts current time in my_time_t to MYSQL_TIME represenatation for local
time zone. Defines time zone (local) used for whole CURDATE function.
*/
-void Item_func_curdate_local::store_now_in_TIME(TIME *now_time)
+void Item_func_curdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
{
THD *thd= current_thd;
thd->variables.time_zone->gmt_sec_to_TIME(now_time,
@@ -1444,10 +1451,10 @@ void Item_func_curdate_local::store_now_in_TIME(TIME *now_time)
/*
- Converts current time in my_time_t to TIME represenatation for UTC
+ Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
time zone. Defines time zone (UTC) used for whole UTC_DATE function.
*/
-void Item_func_curdate_utc::store_now_in_TIME(TIME *now_time)
+void Item_func_curdate_utc::store_now_in_TIME(MYSQL_TIME *now_time)
{
my_tz_UTC->gmt_sec_to_TIME(now_time,
(my_time_t)(current_thd->query_start()));
@@ -1458,7 +1465,7 @@ void Item_func_curdate_utc::store_now_in_TIME(TIME *now_time)
}
-bool Item_func_curdate::get_date(TIME *res,
+bool Item_func_curdate::get_date(MYSQL_TIME *res,
uint fuzzy_date __attribute__((unused)))
{
*res=ltime;
@@ -1476,7 +1483,7 @@ String *Item_func_curtime::val_str(String *str)
void Item_func_curtime::fix_length_and_dec()
{
- TIME ltime;
+ MYSQL_TIME ltime;
decimals= DATETIME_DEC;
collation.set(&my_charset_bin);
@@ -1488,10 +1495,10 @@ void Item_func_curtime::fix_length_and_dec()
/*
- Converts current time in my_time_t to TIME represenatation for local
+ Converts current time in my_time_t to MYSQL_TIME represenatation for local
time zone. Defines time zone (local) used for whole CURTIME function.
*/
-void Item_func_curtime_local::store_now_in_TIME(TIME *now_time)
+void Item_func_curtime_local::store_now_in_TIME(MYSQL_TIME *now_time)
{
THD *thd= current_thd;
thd->variables.time_zone->gmt_sec_to_TIME(now_time,
@@ -1501,10 +1508,10 @@ void Item_func_curtime_local::store_now_in_TIME(TIME *now_time)
/*
- Converts current time in my_time_t to TIME represenatation for UTC
+ Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
time zone. Defines time zone (UTC) used for whole UTC_TIME function.
*/
-void Item_func_curtime_utc::store_now_in_TIME(TIME *now_time)
+void Item_func_curtime_utc::store_now_in_TIME(MYSQL_TIME *now_time)
{
my_tz_UTC->gmt_sec_to_TIME(now_time,
(my_time_t)(current_thd->query_start()));
@@ -1537,10 +1544,10 @@ void Item_func_now::fix_length_and_dec()
/*
- Converts current time in my_time_t to TIME represenatation for local
+ Converts current time in my_time_t to MYSQL_TIME represenatation for local
time zone. Defines time zone (local) used for whole NOW function.
*/
-void Item_func_now_local::store_now_in_TIME(TIME *now_time)
+void Item_func_now_local::store_now_in_TIME(MYSQL_TIME *now_time)
{
THD *thd= current_thd;
thd->variables.time_zone->gmt_sec_to_TIME(now_time,
@@ -1550,10 +1557,10 @@ void Item_func_now_local::store_now_in_TIME(TIME *now_time)
/*
- Converts current time in my_time_t to TIME represenatation for UTC
+ Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
*/
-void Item_func_now_utc::store_now_in_TIME(TIME *now_time)
+void Item_func_now_utc::store_now_in_TIME(MYSQL_TIME *now_time)
{
my_tz_UTC->gmt_sec_to_TIME(now_time,
(my_time_t)(current_thd->query_start()));
@@ -1564,7 +1571,7 @@ void Item_func_now_utc::store_now_in_TIME(TIME *now_time)
}
-bool Item_func_now::get_date(TIME *res,
+bool Item_func_now::get_date(MYSQL_TIME *res,
uint fuzzy_date __attribute__((unused)))
{
*res= ltime;
@@ -1581,10 +1588,10 @@ int Item_func_now::save_in_field(Field *to, bool no_conversions)
/*
- Converts current time in my_time_t to TIME represenatation for local
+ Converts current time in my_time_t to MYSQL_TIME represenatation for local
time zone. Defines time zone (local) used for whole SYSDATE function.
*/
-void Item_func_sysdate_local::store_now_in_TIME(TIME *now_time)
+void Item_func_sysdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
{
THD *thd= current_thd;
thd->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) time(NULL));
@@ -1626,7 +1633,7 @@ void Item_func_sysdate_local::fix_length_and_dec()
}
-bool Item_func_sysdate_local::get_date(TIME *res,
+bool Item_func_sysdate_local::get_date(MYSQL_TIME *res,
uint fuzzy_date __attribute__((unused)))
{
store_now_in_TIME(&ltime);
@@ -1647,7 +1654,7 @@ int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions)
String *Item_func_sec_to_time::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
longlong arg_val= args[0]->val_int();
if ((null_value=args[0]->null_value) || str->alloc(19))
@@ -1666,7 +1673,7 @@ String *Item_func_sec_to_time::val_str(String *str)
longlong Item_func_sec_to_time::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
longlong arg_val= args[0]->val_int();
if ((null_value=args[0]->null_value))
@@ -1808,7 +1815,7 @@ uint Item_func_date_format::format_length(const String *format)
String *Item_func_date_format::val_str(String *str)
{
String *format;
- TIME l_time;
+ MYSQL_TIME l_time;
uint size;
DBUG_ASSERT(fixed == 1);
@@ -1871,7 +1878,7 @@ void Item_func_from_unixtime::fix_length_and_dec()
String *Item_func_from_unixtime::val_str(String *str)
{
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
DBUG_ASSERT(fixed == 1);
@@ -1891,7 +1898,7 @@ String *Item_func_from_unixtime::val_str(String *str)
longlong Item_func_from_unixtime::val_int()
{
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
DBUG_ASSERT(fixed == 1);
@@ -1901,7 +1908,7 @@ longlong Item_func_from_unixtime::val_int()
return (longlong) TIME_to_ulonglong_datetime(&time_tmp);
}
-bool Item_func_from_unixtime::get_date(TIME *ltime,
+bool Item_func_from_unixtime::get_date(MYSQL_TIME *ltime,
uint fuzzy_date __attribute__((unused)))
{
ulonglong tmp= (ulonglong)(args[0]->val_int());
@@ -1929,7 +1936,7 @@ void Item_func_convert_tz::fix_length_and_dec()
String *Item_func_convert_tz::val_str(String *str)
{
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
if (get_date(&time_tmp, 0))
return 0;
@@ -1947,7 +1954,7 @@ String *Item_func_convert_tz::val_str(String *str)
longlong Item_func_convert_tz::val_int()
{
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
if (get_date(&time_tmp, 0))
return 0;
@@ -1956,7 +1963,7 @@ longlong Item_func_convert_tz::val_int()
}
-bool Item_func_convert_tz::get_date(TIME *ltime,
+bool Item_func_convert_tz::get_date(MYSQL_TIME *ltime,
uint fuzzy_date __attribute__((unused)))
{
my_time_t my_time_tmp;
@@ -2018,7 +2025,7 @@ void Item_date_add_interval::fix_length_and_dec()
- If first arg is a MYSQL_TYPE_DATE and the interval type uses hours,
minutes or seconds then type is MYSQL_TYPE_DATETIME.
- Otherwise the result is MYSQL_TYPE_STRING
- (This is because you can't know if the string contains a DATE, TIME or
+ (This is because you can't know if the string contains a DATE, MYSQL_TIME or
DATETIME argument)
*/
cached_field_type= MYSQL_TYPE_STRING;
@@ -2038,7 +2045,7 @@ void Item_date_add_interval::fix_length_and_dec()
/* Here arg[1] is a Item_interval object */
-bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date)
+bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
INTERVAL interval;
@@ -2048,8 +2055,6 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date)
if (date_sub_interval)
interval.neg = !interval.neg;
- if (ltime->year < YY_MAGIC_BELOW)
- return (null_value=1);
return (null_value= date_add_interval(ltime, int_type, interval));
}
@@ -2058,7 +2063,7 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date)
String *Item_date_add_interval::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
enum date_time_format_types format;
if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
@@ -2082,7 +2087,7 @@ String *Item_date_add_interval::val_str(String *str)
longlong Item_date_add_interval::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
longlong date;
if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
return (longlong) 0;
@@ -2172,7 +2177,7 @@ void Item_extract::fix_length_and_dec()
longlong Item_extract::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
uint year;
ulong week_format;
long neg;
@@ -2425,7 +2430,7 @@ void Item_char_typecast::fix_length_and_dec()
String *Item_datetime_typecast::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
!make_datetime(ltime.second_part ? DATE_TIME_MICROSECOND : DATE_TIME,
&ltime, str))
@@ -2439,7 +2444,7 @@ String *Item_datetime_typecast::val_str(String *str)
longlong Item_datetime_typecast::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_arg0_date(&ltime,1))
{
null_value= 1;
@@ -2450,7 +2455,7 @@ longlong Item_datetime_typecast::val_int()
}
-bool Item_time_typecast::get_time(TIME *ltime)
+bool Item_time_typecast::get_time(MYSQL_TIME *ltime)
{
bool res= get_arg0_time(ltime);
/*
@@ -2466,7 +2471,7 @@ bool Item_time_typecast::get_time(TIME *ltime)
longlong Item_time_typecast::val_int()
{
- TIME ltime;
+ MYSQL_TIME ltime;
if (get_time(&ltime))
{
null_value= 1;
@@ -2478,7 +2483,7 @@ longlong Item_time_typecast::val_int()
String *Item_time_typecast::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (!get_arg0_time(&ltime) &&
!make_datetime(ltime.second_part ? TIME_MICROSECOND : TIME_ONLY,
@@ -2490,7 +2495,7 @@ String *Item_time_typecast::val_str(String *str)
}
-bool Item_date_typecast::get_date(TIME *ltime, uint fuzzy_date)
+bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
@@ -2502,7 +2507,7 @@ bool Item_date_typecast::get_date(TIME *ltime, uint fuzzy_date)
String *Item_date_typecast::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) && !str->alloc(11))
{
@@ -2517,7 +2522,7 @@ String *Item_date_typecast::val_str(String *str)
longlong Item_date_typecast::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (args[0]->get_date(&ltime, TIME_FUZZY_DATE))
{
null_value= 1;
@@ -2529,21 +2534,29 @@ longlong Item_date_typecast::val_int()
/*
MAKEDATE(a,b) is a date function that creates a date value
from a year and day value.
+
+ NOTES:
+ As arguments are integers, we can't know if the year is a 2 digit or 4 digit year.
+ In this case we treat all years < 100 as 2 digit years. Ie, this is not safe
+ for dates between 0000-01-01 and 0099-12-31
*/
String *Item_func_makedate::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME l_time;
+ MYSQL_TIME l_time;
long daynr= (long) args[1]->val_int();
- long yearnr= (long) args[0]->val_int();
+ long year= (long) args[0]->val_int();
long days;
if (args[0]->null_value || args[1]->null_value ||
- yearnr < 0 || daynr <= 0)
+ year < 0 || daynr <= 0)
goto err;
- days= calc_daynr(yearnr,1,1) + daynr - 1;
+ if (year < 100)
+ year= year_2000_handling(year);
+
+ days= calc_daynr(year,1,1) + daynr - 1;
/* Day number from year 0 to 9999-12-31 */
if (days >= 0 && days <= MAX_DAY_NUMBER)
{
@@ -2561,19 +2574,32 @@ err:
}
+/*
+ MAKEDATE(a,b) is a date function that creates a date value
+ from a year and day value.
+
+ NOTES:
+ As arguments are integers, we can't know if the year is a 2 digit or 4 digit year.
+ In this case we treat all years < 100 as 2 digit years. Ie, this is not safe
+ for dates between 0000-01-01 and 0099-12-31
+*/
+
longlong Item_func_makedate::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME l_time;
+ MYSQL_TIME l_time;
long daynr= (long) args[1]->val_int();
- long yearnr= (long) args[0]->val_int();
+ long year= (long) args[0]->val_int();
long days;
if (args[0]->null_value || args[1]->null_value ||
- yearnr < 0 || daynr <= 0)
+ year < 0 || daynr <= 0)
goto err;
- days= calc_daynr(yearnr,1,1) + daynr - 1;
+ if (year < 100)
+ year= year_2000_handling(year);
+
+ days= calc_daynr(year,1,1) + daynr - 1;
/* Day number from year 0 to 9999-12-31 */
if (days >= 0 && days < MAX_DAY_NUMBER)
{
@@ -2628,7 +2654,7 @@ void Item_func_add_time::fix_length_and_dec()
String *Item_func_add_time::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME l_time1, l_time2, l_time3;
+ MYSQL_TIME l_time1, l_time2, l_time3;
bool is_time= 0;
long days, microseconds;
longlong seconds;
@@ -2730,7 +2756,7 @@ String *Item_func_timediff::val_str(String *str)
longlong seconds;
long microseconds;
int l_sign= 1;
- TIME l_time1 ,l_time2, l_time3;
+ MYSQL_TIME l_time1 ,l_time2, l_time3;
null_value= 0;
if (args[0]->get_time(&l_time1) ||
@@ -2775,7 +2801,7 @@ null_date:
String *Item_func_maketime::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
bool overflow= 0;
longlong hour= args[0]->val_int();
@@ -2819,7 +2845,8 @@ String *Item_func_maketime::val_str(String *str)
char *ptr= longlong10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
int len = (int)(ptr - buf) +
my_sprintf(ptr, (ptr, ":%02u:%02u", (uint)minute, (uint)second));
- make_truncated_value_warning(current_thd, buf, len, MYSQL_TIMESTAMP_TIME,
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ buf, len, MYSQL_TIMESTAMP_TIME,
NullS);
}
@@ -2843,7 +2870,7 @@ String *Item_func_maketime::val_str(String *str)
longlong Item_func_microsecond::val_int()
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (!get_arg0_time(&ltime))
return ltime.second_part;
return 0;
@@ -2852,7 +2879,7 @@ longlong Item_func_microsecond::val_int()
longlong Item_func_timestamp_diff::val_int()
{
- TIME ltime1, ltime2;
+ MYSQL_TIME ltime1, ltime2;
longlong seconds;
long microseconds;
long months= 0;
@@ -3158,7 +3185,7 @@ void Item_func_str_to_date::fix_length_and_dec()
}
}
-bool Item_func_str_to_date::get_date(TIME *ltime, uint fuzzy_date)
+bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
DATE_TIME_FORMAT date_time_format;
char val_buff[64], format_buff[64];
@@ -3199,7 +3226,7 @@ null_date:
String *Item_func_str_to_date::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- TIME ltime;
+ MYSQL_TIME ltime;
if (Item_func_str_to_date::get_date(&ltime, TIME_FUZZY_DATE))
return 0;
@@ -3212,7 +3239,7 @@ String *Item_func_str_to_date::val_str(String *str)
}
-bool Item_func_last_day::get_date(TIME *ltime, uint fuzzy_date)
+bool Item_func_last_day::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) ||
(ltime->month == 0))
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index ea93619e59a..992b79753ca 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -449,9 +449,9 @@ public:
/*
Abstract method that defines which time zone is used for conversion.
Converts time current time in my_time_t representation to broken-down
- TIME representation using UTC-SYSTEM or per-thread time zone.
+ MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
*/
- virtual void store_now_in_TIME(TIME *now_time)=0;
+ virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
bool result_as_longlong() { return TRUE; }
};
@@ -462,7 +462,7 @@ public:
Item_func_curtime_local() :Item_func_curtime() {}
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
const char *func_name() const { return "curtime"; }
- virtual void store_now_in_TIME(TIME *now_time);
+ virtual void store_now_in_TIME(MYSQL_TIME *now_time);
};
@@ -472,7 +472,7 @@ public:
Item_func_curtime_utc() :Item_func_curtime() {}
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
const char *func_name() const { return "utc_time"; }
- virtual void store_now_in_TIME(TIME *now_time);
+ virtual void store_now_in_TIME(MYSQL_TIME *now_time);
};
@@ -481,14 +481,14 @@ public:
class Item_func_curdate :public Item_date
{
longlong value;
- TIME ltime;
+ MYSQL_TIME ltime;
public:
Item_func_curdate() :Item_date() {}
longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; }
String *val_str(String *str);
void fix_length_and_dec();
- bool get_date(TIME *res, uint fuzzy_date);
- virtual void store_now_in_TIME(TIME *now_time)=0;
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
+ virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
};
@@ -497,7 +497,7 @@ class Item_func_curdate_local :public Item_func_curdate
public:
Item_func_curdate_local() :Item_func_curdate() {}
const char *func_name() const { return "curdate"; }
- void store_now_in_TIME(TIME *now_time);
+ void store_now_in_TIME(MYSQL_TIME *now_time);
};
@@ -506,7 +506,7 @@ class Item_func_curdate_utc :public Item_func_curdate
public:
Item_func_curdate_utc() :Item_func_curdate() {}
const char *func_name() const { return "utc_date"; }
- void store_now_in_TIME(TIME *now_time);
+ void store_now_in_TIME(MYSQL_TIME *now_time);
};
@@ -518,7 +518,7 @@ protected:
longlong value;
char buff[20*2+32]; // +32 to make my_snprintf_{8bit|ucs2} happy
uint buff_length;
- TIME ltime;
+ MYSQL_TIME ltime;
public:
Item_func_now() :Item_date_func() {}
Item_func_now(Item *a) :Item_date_func(a) {}
@@ -527,8 +527,8 @@ public:
int save_in_field(Field *to, bool no_conversions);
String *val_str(String *str);
void fix_length_and_dec();
- bool get_date(TIME *res, uint fuzzy_date);
- virtual void store_now_in_TIME(TIME *now_time)=0;
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
+ virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
};
@@ -538,7 +538,7 @@ public:
Item_func_now_local() :Item_func_now() {}
Item_func_now_local(Item *a) :Item_func_now(a) {}
const char *func_name() const { return "now"; }
- virtual void store_now_in_TIME(TIME *now_time);
+ virtual void store_now_in_TIME(MYSQL_TIME *now_time);
virtual enum Functype functype() const { return NOW_FUNC; }
};
@@ -549,7 +549,7 @@ public:
Item_func_now_utc() :Item_func_now() {}
Item_func_now_utc(Item *a) :Item_func_now(a) {}
const char *func_name() const { return "utc_timestamp"; }
- virtual void store_now_in_TIME(TIME *now_time);
+ virtual void store_now_in_TIME(MYSQL_TIME *now_time);
};
@@ -564,13 +564,13 @@ public:
Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
bool const_item() const { return 0; }
const char *func_name() const { return "sysdate"; }
- void store_now_in_TIME(TIME *now_time);
+ void store_now_in_TIME(MYSQL_TIME *now_time);
double val_real();
longlong val_int();
int save_in_field(Field *to, bool no_conversions);
String *val_str(String *str);
void fix_length_and_dec();
- bool get_date(TIME *res, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
void update_used_tables()
{
Item_func_now::update_used_tables();
@@ -584,7 +584,7 @@ class Item_func_from_days :public Item_date
public:
Item_func_from_days(Item *a) :Item_date(a) {}
const char *func_name() const { return "from_days"; }
- bool get_date(TIME *res, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
bool check_partition_func_processor(byte *int_arg) {return FALSE;}
};
@@ -616,7 +616,7 @@ class Item_func_from_unixtime :public Item_date_func
String *val_str(String *str);
const char *func_name() const { return "from_unixtime"; }
void fix_length_and_dec();
- bool get_date(TIME *res, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
bool check_partition_func_processor(byte *int_arg) {return FALSE;}
};
@@ -652,7 +652,7 @@ class Item_func_convert_tz :public Item_date_func
String *val_str(String *str);
const char *func_name() const { return "convert_tz"; }
void fix_length_and_dec();
- bool get_date(TIME *res, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
void cleanup();
};
@@ -695,7 +695,7 @@ public:
void fix_length_and_dec();
enum_field_types field_type() const { return cached_field_type; }
longlong val_int();
- bool get_date(TIME *res, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
bool eq(const Item *item, bool binary_cmp) const;
void print(String *str);
bool check_partition_func_processor(byte *int_arg) {return FALSE;}
@@ -783,7 +783,7 @@ public:
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
const char *func_name() const { return "cast_as_date"; }
String *val_str(String *str);
- bool get_date(TIME *ltime, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
const char *cast_type() const { return "date"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
Field *tmp_table_field(TABLE *table)
@@ -817,7 +817,7 @@ public:
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
const char *func_name() const { return "cast_as_time"; }
String *val_str(String *str);
- bool get_time(TIME *ltime);
+ bool get_time(MYSQL_TIME *ltime);
const char *cast_type() const { return "time"; }
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
Field *tmp_table_field(TABLE *table)
@@ -1020,7 +1020,7 @@ public:
:Item_str_func(a, b)
{}
String *val_str(String *str);
- bool get_date(TIME *ltime, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
const char *func_name() const { return "str_to_date"; }
enum_field_types field_type() const { return cached_field_type; }
void fix_length_and_dec();
@@ -1037,5 +1037,5 @@ class Item_func_last_day :public Item_date
public:
Item_func_last_day(Item *a) :Item_date(a) {}
const char *func_name() const { return "last_day"; }
- bool get_date(TIME *res, uint fuzzy_date);
+ bool get_date(MYSQL_TIME *res, uint fuzzy_date);
};
diff --git a/sql/log.cc b/sql/log.cc
index 3cfcabd8363..694a80ba57b 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1597,8 +1597,7 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
table. Such cases should be rare (updating a
non-transactional table inside a transaction...)
*/
- if (unlikely(thd->options & (OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG)))
+ if (unlikely(thd->no_trans_update.all || (thd->options & OPTION_KEEP_LOG)))
{
Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE);
qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
@@ -1653,8 +1652,7 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
non-transactional table. Otherwise, truncate the binlog cache starting
from the SAVEPOINT command.
*/
- if (unlikely(thd->options &
- (OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG)))
+ if (unlikely(thd->no_trans_update.all || (thd->options & OPTION_KEEP_LOG)))
{
int error=
thd->binlog_query(THD::STMT_QUERY_TYPE,
diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc
index 511942e9a5d..7b2d271639f 100644
--- a/sql/my_decimal.cc
+++ b/sql/my_decimal.cc
@@ -191,7 +191,7 @@ int str2my_decimal(uint mask, const char *from, uint length,
}
-my_decimal *date2my_decimal(TIME *ltime, my_decimal *dec)
+my_decimal *date2my_decimal(MYSQL_TIME *ltime, my_decimal *dec)
{
longlong date;
date = (ltime->year*100L + ltime->month)*100L + ltime->day;
diff --git a/sql/my_decimal.h b/sql/my_decimal.h
index cefc5ee00fd..eade029677f 100644
--- a/sql/my_decimal.h
+++ b/sql/my_decimal.h
@@ -296,7 +296,7 @@ int string2my_decimal(uint mask, const String *str, my_decimal *d)
}
-my_decimal *date2my_decimal(TIME *ltime, my_decimal *dec);
+my_decimal *date2my_decimal(MYSQL_TIME *ltime, my_decimal *dec);
#endif /*defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY) */
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 9b7b17cc498..fe7a567365e 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -340,9 +340,6 @@ MY_LOCALE *my_locale_by_number(uint number);
/* The following is used to detect a conflict with DISTINCT */
#define SELECT_ALL (ULL(1) << 24) // SELECT, user, parser
-/* Set if we are updating a non-transaction safe table */
-#define OPTION_STATUS_NO_TRANS_UPDATE (ULL(1) << 25) // THD, intern
-
/* The following can be set when importing tables in a 'wrong order'
to suppress foreign key checks */
#define OPTION_NO_FOREIGN_KEY_CHECKS (ULL(1) << 26) // THD, user, binlog
@@ -838,7 +835,8 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
char *new_table_name, char *new_table_alias,
bool skip_error);
-bool mysql_change_db(THD *thd,const char *name,bool no_access_check);
+bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
+ bool force_switch);
void mysql_parse(THD *thd,char *inBuf,uint length);
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
bool is_update_query(enum enum_sql_command command);
@@ -1118,7 +1116,7 @@ void init_status_vars();
void free_status_vars();
/* information schema */
-extern LEX_STRING information_schema_name;
+extern LEX_STRING INFORMATION_SCHEMA_NAME;
extern const LEX_STRING partition_keywords[];
LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str,
const char* str, uint length,
@@ -1137,7 +1135,7 @@ int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
bool get_schema_tables_result(JOIN *join,
enum enum_schema_table_state executed_place);
#define is_schema_db(X) \
- !my_strcasecmp(system_charset_info, information_schema_name.str, (X))
+ !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
/* sql_prepare.cc */
@@ -1842,19 +1840,20 @@ ulong convert_period_to_month(ulong period);
ulong convert_month_to_period(ulong month);
void get_date_from_daynr(long daynr,uint *year, uint *month,
uint *day);
-my_time_t TIME_to_timestamp(THD *thd, const TIME *t, my_bool *not_exist);
-bool str_to_time_with_warn(const char *str,uint length,TIME *l_time);
+my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *not_exist);
+bool str_to_time_with_warn(const char *str,uint length,MYSQL_TIME *l_time);
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
- TIME *l_time, uint flags);
-void localtime_to_TIME(TIME *to, struct tm *from);
-void calc_time_from_sec(TIME *to, long seconds, long microseconds);
+ MYSQL_TIME *l_time, uint flags);
+void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
+void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
-void make_truncated_value_warning(THD *thd, const char *str_val,
+void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
+ const char *str_val,
uint str_length, timestamp_type time_type,
const char *field_name);
-bool date_add_interval(TIME *ltime, interval_type int_type, INTERVAL interval);
-bool calc_time_diff(TIME *l_time1, TIME *l_time2, int l_sign,
+bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval);
+bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign,
longlong *seconds_out, long *microseconds_out);
extern LEX_STRING interval_type_to_name[];
@@ -1866,15 +1865,15 @@ extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
DATE_TIME_FORMAT *format);
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
timestamp_type type);
-extern bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time,
+extern bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
timestamp_type type, String *str);
-void make_datetime(const DATE_TIME_FORMAT *format, const TIME *l_time,
+void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
String *str);
-void make_date(const DATE_TIME_FORMAT *format, const TIME *l_time,
+void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
String *str);
-void make_time(const DATE_TIME_FORMAT *format, const TIME *l_time,
+void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
String *str);
-int my_time_compare(TIME *a, TIME *b);
+int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
int test_if_number(char *str,int *res,bool allow_wildcards);
void change_byte(byte *,uint,char,char);
@@ -1894,7 +1893,7 @@ double my_double_round(double value, int dec, bool truncate);
int get_quick_record(SQL_SELECT *select);
int calc_weekday(long daynr,bool sunday_first_day_of_week);
-uint calc_week(TIME *l_time, uint week_behaviour, uint *year);
+uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
void find_date(char *pos,uint *vek,uint flag);
TYPELIB *convert_strings_to_array_type(my_string *typelibs, my_string *end);
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index b70cf226803..ec85192348d 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -274,7 +274,11 @@ static TYPELIB tc_heuristic_recover_typelib=
};
static const char *thread_handling_names[]=
-{ "one-thread-per-connection", "no-threads", "pool-of-threads", NullS};
+{ "one-thread-per-connection", "no-threads",
+#if HAVE_POOL_OF_THREADS == 1
+ "pool-of-threads",
+#endif
+ NullS};
TYPELIB thread_handling_typelib=
{
@@ -732,6 +736,8 @@ pthread_handler_t handle_connections_shared_memory(void *arg);
#endif
pthread_handler_t handle_slave(void *arg);
static ulong find_bit_type(const char *x, TYPELIB *bit_lib);
+static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
+ const char *option);
static void clean_up(bool print_message);
static int test_if_case_insensitive(const char *dir_name);
@@ -783,7 +789,6 @@ static void close_connections(void)
DBUG_PRINT("info",("Waiting for select thread"));
#ifndef DONT_USE_THR_ALARM
- if (pthread_kill(select_thread, thr_client_alarm))
break; // allready dead
#endif
set_timespec(abstime, 2);
@@ -7451,11 +7456,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case (int) OPT_INIT_RPL_ROLE:
{
int role;
- if ((role=find_type(argument, &rpl_role_typelib, 2)) <= 0)
- {
- fprintf(stderr, "Unknown replication role: %s\n", argument);
- exit(1);
- }
+ role= find_type_or_exit(argument, &rpl_role_typelib, opt->name);
rpl_status = (role == 1) ? RPL_AUTH_MASTER : RPL_IDLE_SLAVE;
break;
}
@@ -7511,17 +7512,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case OPT_BINLOG_FORMAT:
{
int id;
- if ((id= find_type(argument, &binlog_format_typelib, 2)) <= 0)
- {
- fprintf(stderr,
- "Unknown binary log format: '%s' "
- "(should be one of '%s', '%s', '%s')\n",
- argument,
- binlog_format_names[BINLOG_FORMAT_STMT],
- binlog_format_names[BINLOG_FORMAT_ROW],
- binlog_format_names[BINLOG_FORMAT_MIXED]);
- exit(1);
- }
+ id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
break;
}
@@ -7581,13 +7572,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
{
log_output_str= argument;
- if ((log_output_options=
- find_bit_type(argument, &log_output_typelib)) == ~(ulong) 0)
- {
- fprintf(stderr, "Unknown option to log-output: %s\n", argument);
- exit(1);
- }
- }
+ log_output_options=
+ find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
+ }
break;
}
#endif
@@ -7730,11 +7717,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
{
int type;
- if ((type=find_type(argument, &delay_key_write_typelib, 2)) <= 0)
- {
- fprintf(stderr,"Unknown delay_key_write type: %s\n",argument);
- exit(1);
- }
+ type= find_type_or_exit(argument, &delay_key_write_typelib, opt->name);
delay_key_write_options= (uint) type-1;
}
break;
@@ -7745,11 +7728,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case OPT_TX_ISOLATION:
{
int type;
- if ((type=find_type(argument, &tx_isolation_typelib, 2)) <= 0)
- {
- fprintf(stderr,"Unknown transaction isolation type: %s\n",argument);
- exit(1);
- }
+ type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
global_system_variables.tx_isolation= (type-1);
break;
}
@@ -7790,16 +7769,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break;
case OPT_NDB_DISTRIBUTION:
int id;
- if ((id= find_type(argument, &ndb_distribution_typelib, 2)) <= 0)
- {
- fprintf(stderr,
- "Unknown ndb distribution type: '%s' "
- "(should be '%s' or '%s')\n",
- argument,
- ndb_distribution_names[ND_KEYHASH],
- ndb_distribution_names[ND_LINHASH]);
- exit(1);
- }
+ id= find_type_or_exit(argument, &ndb_distribution_typelib, opt->name);
opt_ndb_distribution_id= (enum ndb_distribution)(id-1);
break;
case OPT_NDB_EXTRA_LOGGING:
@@ -7839,12 +7809,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
{
myisam_recover_options_str=argument;
- if ((myisam_recover_options=
- find_bit_type(argument, &myisam_recover_typelib)) == ~(ulong) 0)
- {
- fprintf(stderr, "Unknown option to myisam-recover: %s\n",argument);
- exit(1);
- }
+ myisam_recover_options=
+ find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
}
ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
break;
@@ -7857,14 +7823,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
myisam_concurrent_insert= 0; /* --skip-concurrent-insert */
break;
case OPT_TC_HEURISTIC_RECOVER:
- {
- if ((tc_heuristic_recover=find_type(argument,
- &tc_heuristic_recover_typelib, 2)) <=0)
- {
- fprintf(stderr, "Unknown option to tc-heuristic-recover: %s\n",argument);
- exit(1);
- }
- }
+ tc_heuristic_recover= find_type_or_exit(argument,
+ &tc_heuristic_recover_typelib,
+ opt->name);
+ break;
case OPT_MYISAM_STATS_METHOD:
{
ulong method_conv;
@@ -7872,11 +7834,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
LINT_INIT(method_conv);
myisam_stats_method_str= argument;
- if ((method=find_type(argument, &myisam_stats_method_typelib, 2)) <= 0)
- {
- fprintf(stderr, "Invalid value of myisam_stats_method: %s.\n", argument);
- exit(1);
- }
+ method= find_type_or_exit(argument, &myisam_stats_method_typelib,
+ opt->name);
switch (method-1) {
case 2:
method_conv= MI_STATS_METHOD_IGNORE_NULLS;
@@ -7895,12 +7854,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case OPT_SQL_MODE:
{
sql_mode_str= argument;
- if ((global_system_variables.sql_mode=
- find_bit_type(argument, &sql_mode_typelib)) == ~(ulong) 0)
- {
- fprintf(stderr, "Unknown option to sql-mode: %s\n", argument);
- exit(1);
- }
+ global_system_variables.sql_mode=
+ find_bit_type_or_exit(argument, &sql_mode_typelib, opt->name);
global_system_variables.sql_mode= fix_sql_mode(global_system_variables.
sql_mode);
break;
@@ -7910,16 +7865,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break;
case OPT_THREAD_HANDLING:
{
- if ((global_system_variables.thread_handling=
- find_type(argument, &thread_handling_typelib, 2)) <= 0 ||
- (global_system_variables.thread_handling == SCHEDULER_POOL_OF_THREADS
- && !HAVE_POOL_OF_THREADS))
- {
- /* purecov: begin tested */
- fprintf(stderr,"Unknown/unsupported thread-handling: %s\n",argument);
- exit(1);
- /* purecov: end */
- }
+ global_system_variables.thread_handling=
+ find_type_or_exit(argument, &thread_handling_typelib, opt->name);
break;
}
case OPT_FT_BOOLEAN_SYNTAX:
@@ -8208,6 +8155,30 @@ static void fix_paths(void)
}
+static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
+ const char *option)
+{
+ ulong res;
+
+ const char **ptr;
+
+ if ((res= find_bit_type(x, bit_lib)) == ~(ulong) 0)
+ {
+ ptr= bit_lib->type_names;
+ if (!*x)
+ fprintf(stderr, "No option given to %s\n", option);
+ else
+ fprintf(stderr, "Wrong option to %s. Option(s) given: %s\n", option, x);
+ fprintf(stderr, "Alternatives are: '%s'", *ptr);
+ while (*++ptr)
+ fprintf(stderr, ",'%s'", *ptr);
+ fprintf(stderr, "\n");
+ exit(1);
+ }
+ return res;
+}
+
+
/*
Return a bitfield from a string of substrings separated by ','
returns ~(ulong) 0 on error.
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index 2156888b8cf..f4b940af898 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -298,7 +298,7 @@ void net_clear(NET *net, my_bool clear_buffer)
{
DBUG_PRINT("info",("skipped %d bytes from file: %s",
count, vio_description(net->vio)));
-#if defined(EXTRA_DEBUG) && (MYSQL_VERSION_ID < 51000)
+#if defined(EXTRA_DEBUG) && (MYSQL_VERSION_ID < 50100)
fprintf(stderr,"Error: net_clear() skipped %d bytes from file: %s\n",
count, vio_description(net->vio));
#endif
@@ -818,7 +818,7 @@ my_real_read(NET *net, ulong *complen)
{
my_bool interrupted = vio_should_retry(net->vio);
- DBUG_PRINT("info",("vio_read returned %ld, errno: %d",
+ DBUG_PRINT("info",("vio_read returned %ld errno: %d",
length, vio_errno(net->vio)));
#if !defined(__WIN__) || defined(MYSQL_SERVER)
/*
diff --git a/sql/protocol.cc b/sql/protocol.cc
index 5aa3b7b5055..d537fd346f9 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -961,7 +961,7 @@ bool Protocol_text::store(Field *field)
*/
-bool Protocol_text::store(TIME *tm)
+bool Protocol_text::store(MYSQL_TIME *tm)
{
#ifndef DBUG_OFF
DBUG_ASSERT(field_types == 0 ||
@@ -984,7 +984,7 @@ bool Protocol_text::store(TIME *tm)
}
-bool Protocol_text::store_date(TIME *tm)
+bool Protocol_text::store_date(MYSQL_TIME *tm)
{
#ifndef DBUG_OFF
DBUG_ASSERT(field_types == 0 ||
@@ -1003,7 +1003,7 @@ bool Protocol_text::store_date(TIME *tm)
we support 0-6 decimals for time.
*/
-bool Protocol_text::store_time(TIME *tm)
+bool Protocol_text::store_time(MYSQL_TIME *tm)
{
#ifndef DBUG_OFF
DBUG_ASSERT(field_types == 0 ||
@@ -1176,7 +1176,7 @@ bool Protocol_binary::store(Field *field)
}
-bool Protocol_binary::store(TIME *tm)
+bool Protocol_binary::store(MYSQL_TIME *tm)
{
char buff[12],*pos;
uint length;
@@ -1202,7 +1202,7 @@ bool Protocol_binary::store(TIME *tm)
return packet->append(buff, length+1, PACKET_BUFFER_EXTRA_ALLOC);
}
-bool Protocol_binary::store_date(TIME *tm)
+bool Protocol_binary::store_date(MYSQL_TIME *tm)
{
tm->hour= tm->minute= tm->second=0;
tm->second_part= 0;
@@ -1210,7 +1210,7 @@ bool Protocol_binary::store_date(TIME *tm)
}
-bool Protocol_binary::store_time(TIME *tm)
+bool Protocol_binary::store_time(MYSQL_TIME *tm)
{
char buff[13], *pos;
uint length;
diff --git a/sql/protocol.h b/sql/protocol.h
index da49cf769ae..e0672240e0e 100644
--- a/sql/protocol.h
+++ b/sql/protocol.h
@@ -88,9 +88,9 @@ public:
CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0;
virtual bool store(float from, uint32 decimals, String *buffer)=0;
virtual bool store(double from, uint32 decimals, String *buffer)=0;
- virtual bool store(TIME *time)=0;
- virtual bool store_date(TIME *time)=0;
- virtual bool store_time(TIME *time)=0;
+ virtual bool store(MYSQL_TIME *time)=0;
+ virtual bool store_date(MYSQL_TIME *time)=0;
+ virtual bool store_time(MYSQL_TIME *time)=0;
virtual bool store(Field *field)=0;
#ifdef EMBEDDED_LIBRARY
int begin_dataset();
@@ -127,9 +127,9 @@ public:
virtual bool store(const char *from, uint length, CHARSET_INFO *cs);
virtual bool store(const char *from, uint length,
CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
- virtual bool store(TIME *time);
- virtual bool store_date(TIME *time);
- virtual bool store_time(TIME *time);
+ virtual bool store(MYSQL_TIME *time);
+ virtual bool store_date(MYSQL_TIME *time);
+ virtual bool store_time(MYSQL_TIME *time);
virtual bool store(float nr, uint32 decimals, String *buffer);
virtual bool store(double from, uint32 decimals, String *buffer);
virtual bool store(Field *field);
@@ -162,9 +162,9 @@ public:
virtual bool store(const char *from,uint length, CHARSET_INFO *cs);
virtual bool store(const char *from, uint length,
CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
- virtual bool store(TIME *time);
- virtual bool store_date(TIME *time);
- virtual bool store_time(TIME *time);
+ virtual bool store(MYSQL_TIME *time);
+ virtual bool store_date(MYSQL_TIME *time);
+ virtual bool store_time(MYSQL_TIME *time);
virtual bool store(float nr, uint32 decimals, String *buffer);
virtual bool store(double from, uint32 decimals, String *buffer);
virtual bool store(Field *field);
diff --git a/sql/set_var.cc b/sql/set_var.cc
index ea2888aec56..ec74ce45b6b 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -3086,16 +3086,15 @@ static bool set_option_autocommit(THD *thd, set_var *var)
if ((org_options & OPTION_NOT_AUTOCOMMIT))
{
/* We changed to auto_commit mode */
- thd->options&= ~(ulonglong) (OPTION_BEGIN |
- OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG);
+ thd->options&= ~(ulonglong) (OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->no_trans_update.all= FALSE;
thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
if (ha_commit(thd))
return 1;
}
else
{
- thd->options&= ~(ulonglong) (OPTION_STATUS_NO_TRANS_UPDATE);
+ thd->no_trans_update.all= FALSE;
thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
}
}
diff --git a/sql/sp.cc b/sql/sp.cc
index a59e3507eac..49b8b304e76 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -391,14 +391,14 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
{
sp_head *sp= newlex.sphead;
- if (dbchanged && (ret= mysql_change_db(thd, old_db.str, 1)))
+ if (dbchanged && (ret= mysql_change_db(thd, &old_db, TRUE)))
goto end;
delete sp;
ret= SP_PARSE_ERROR;
}
else
{
- if (dbchanged && (ret= mysql_change_db(thd, old_db.str, 1)))
+ if (dbchanged && (ret= mysql_change_db(thd, &old_db, TRUE)))
goto end;
*sphp= newlex.sphead;
(*sphp)->set_definer(&definer_user_name, &definer_host_name);
@@ -724,7 +724,7 @@ print_field_values(THD *thd, TABLE *table,
switch (used_field->field_type) {
case MYSQL_TYPE_TIMESTAMP:
{
- TIME tmp_time;
+ MYSQL_TIME tmp_time;
bzero((char *)&tmp_time, sizeof(tmp_time));
((Field_timestamp *) used_field->field)->get_time(&tmp_time);
@@ -1861,7 +1861,7 @@ sp_use_new_db(THD *thd, LEX_STRING new_db, LEX_STRING *old_db,
DBUG_RETURN(0);
}
- ret= mysql_change_db(thd, new_db.str, no_access_check);
+ ret= mysql_change_db(thd, &new_db, no_access_check);
*dbchangedp= ret == 0;
DBUG_RETURN(ret);
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index e3138d02ca5..a2ce5111a25 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -349,13 +349,13 @@ sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr)
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
bool save_abort_on_warning= thd->abort_on_warning;
- bool save_no_trans_update= thd->no_trans_update;
+ bool save_no_trans_update_stmt= thd->no_trans_update.stmt;
thd->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
thd->abort_on_warning=
thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES);
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
/* Save the value in the field. Convert the value if needed. */
@@ -363,7 +363,7 @@ sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr)
thd->count_cuted_fields= save_count_cuted_fields;
thd->abort_on_warning= save_abort_on_warning;
- thd->no_trans_update= save_no_trans_update;
+ thd->no_trans_update.stmt= save_no_trans_update_stmt;
if (thd->net.report_error)
{
@@ -1189,7 +1189,7 @@ sp_head::execute(THD *thd)
(It would generate an error from mysql_change_db() when old_db=="")
*/
if (! thd->killed)
- err_status|= mysql_change_db(thd, old_db.str, 1);
+ err_status|= mysql_change_db(thd, &old_db, TRUE);
}
m_flags&= ~IS_INVOKED;
DBUG_PRINT("info",
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index aaa88071173..ba1ec66fb02 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -4052,6 +4052,26 @@ err2:
}
+static bool check_grant_db_routine(THD *thd, const char *db, HASH *hash)
+{
+ Security_context *sctx= thd->security_ctx;
+
+ for (uint idx= 0; idx < hash->records; ++idx)
+ {
+ GRANT_NAME *item= (GRANT_NAME*) hash_element(hash, idx);
+
+ if (strcmp(item->user, sctx->priv_user) == 0 &&
+ strcmp(item->db, db) == 0 &&
+ compare_hostname(&item->host, sctx->host, sctx->ip))
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
/*
Check if a user has the right to access a database
Access is accepted if he has a grant for any table/routine in the database
@@ -4063,9 +4083,10 @@ bool check_grant_db(THD *thd,const char *db)
Security_context *sctx= thd->security_ctx;
char helping [NAME_LEN+USERNAME_LENGTH+2];
uint len;
- bool error= 1;
+ bool error= TRUE;
len= (uint) (strmov(strmov(helping, sctx->priv_user) + 1, db) - helping) + 1;
+
rw_rdlock(&LOCK_grant);
for (uint idx=0 ; idx < column_priv_hash.records ; idx++)
@@ -4076,11 +4097,17 @@ bool check_grant_db(THD *thd,const char *db)
!memcmp(grant_table->hash_key,helping,len) &&
compare_hostname(&grant_table->host, sctx->host, sctx->ip))
{
- error=0; // Found match
+ error= FALSE; /* Found match. */
break;
}
}
+
+ if (error)
+ error= check_grant_db_routine(thd, db, &proc_priv_hash) &&
+ check_grant_db_routine(thd, db, &func_priv_hash);
+
rw_unlock(&LOCK_grant);
+
return error;
}
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 8cc54aa3c8c..0f428da1fdb 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -4559,14 +4559,35 @@ find_field_in_tables(THD *thd, Item_ident *item,
{
Field *cur_field= find_field_in_table_ref(thd, cur_table, name, length,
item->name, db, table_name, ref,
- check_privileges, allow_rowid,
+ check_privileges,
+ allow_rowid,
&(item->cached_field_index),
register_tree_change,
&actual_table);
if (cur_field)
{
if (cur_field == WRONG_GRANT)
- return (Field*) 0;
+ {
+ if (thd->lex->sql_command != SQLCOM_SHOW_FIELDS)
+ return (Field*) 0;
+
+ thd->clear_error();
+ cur_field= find_field_in_table_ref(thd, cur_table, name, length,
+ item->name, db, table_name, ref,
+ false,
+ allow_rowid,
+ &(item->cached_field_index),
+ register_tree_change,
+ &actual_table);
+ if (cur_field)
+ {
+ Field *nf=new Field_null(NULL,0,Field::NONE,
+ cur_field->field_name,
+ &my_charset_bin);
+ nf->init(cur_table->table);
+ cur_field= nf;
+ }
+ }
/*
Store the original table of the field, which may be different from
@@ -4589,7 +4610,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
report_error == IGNORE_EXCEPT_NON_UNIQUE)
my_error(ER_NON_UNIQ_ERROR, MYF(0),
table_name ? item->full_name() : name, thd->where);
- return (Field*) 0;
+ return (Field*) 0;
}
found= cur_field;
}
@@ -6390,7 +6411,7 @@ fill_record(THD *thd, Field **ptr, List<Item> &values, bool ignore_errors)
table= field->table;
if (field == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
- if (value->save_in_field(field, 0) == -1)
+ if (value->save_in_field(field, 0) < 0)
goto err;
}
DBUG_RETURN(thd->net.report_error);
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 89b7a25033f..8d8838d4585 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -377,7 +377,7 @@ inline Query_cache_block * Query_cache_block_table::block()
void Query_cache_block::init(ulong block_length)
{
DBUG_ENTER("Query_cache_block::init");
- DBUG_PRINT("qcache", ("init block 0x%lx length: %lu", (ulong) this,
+ DBUG_PRINT("qcache", ("init block: 0x%lx length: %lu", (ulong) this,
block_length));
length = block_length;
used = 0;
@@ -3685,7 +3685,7 @@ void Query_cache::queries_dump()
Query_cache_query_flags flags;
memcpy(&flags, str+len, QUERY_CACHE_FLAGS_SIZE);
str[len]= 0; // make zero ending DB name
- DBUG_PRINT("qcache", ("F:%u C:%u L:%lu T:'%s' (%u) '%s' '%s'",
+ DBUG_PRINT("qcache", ("F: %u C: %u L: %lu T: '%s' (%u) '%s' '%s'",
flags.client_long_flag,
flags.character_set_client_num,
(ulong)flags.limit,
@@ -4008,7 +4008,7 @@ my_bool Query_cache::check_integrity(bool locked)
} while (block != bins[i].free_blocks);
if (count != bins[i].number)
{
- DBUG_PRINT("error", ("bins[%d].number = %d, but bin have %d blocks",
+ DBUG_PRINT("error", ("bins[%d].number= %d, but bin have %d blocks",
i, bins[i].number, count));
result = 1;
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 0abda16ea6a..43f534d5404 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -367,6 +367,7 @@ void THD::init(void)
if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
options= thd_startup_options;
+ no_trans_update.stmt= no_trans_update.all= FALSE;
open_options=ha_open_options;
update_lock_default= (variables.low_priority_updates ?
TL_WRITE_LOW_PRIORITY :
@@ -437,6 +438,7 @@ void THD::cleanup(void)
DBUG_ENTER("THD::cleanup");
DBUG_ASSERT(cleanup_done == 0);
+ killed= KILL_CONNECTION;
#ifdef ENABLE_WHEN_BINLOG_WILL_BE_ABLE_TO_PREPARE
if (transaction.xid_state.xa_state == XA_PREPARED)
{
@@ -841,7 +843,8 @@ void THD::add_changed_table(const char *key, long key_length)
{
list_include(prev_changed, curr, changed_table_dup(key, key_length));
DBUG_PRINT("info",
- ("key_length %ld %u", key_length, (*prev_changed)->key_length));
+ ("key_length: %ld %u", key_length,
+ (*prev_changed)->key_length));
DBUG_VOID_RETURN;
}
else if (cmp == 0)
@@ -851,7 +854,7 @@ void THD::add_changed_table(const char *key, long key_length)
{
list_include(prev_changed, curr, changed_table_dup(key, key_length));
DBUG_PRINT("info",
- ("key_length %ld %u", key_length,
+ ("key_length: %ld %u", key_length,
(*prev_changed)->key_length));
DBUG_VOID_RETURN;
}
@@ -863,7 +866,7 @@ void THD::add_changed_table(const char *key, long key_length)
}
}
*prev_changed = changed_table_dup(key, key_length);
- DBUG_PRINT("info", ("key_length %ld %u", key_length,
+ DBUG_PRINT("info", ("key_length: %ld %u", key_length,
(*prev_changed)->key_length));
DBUG_VOID_RETURN;
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 66914bdf908..da49dcd9955 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -278,7 +278,7 @@ struct system_variables
Time_zone *time_zone;
- /* DATE, DATETIME and TIME formats */
+ /* DATE, DATETIME and MYSQL_TIME formats */
DATE_TIME_FORMAT *date_format;
DATE_TIME_FORMAT *datetime_format;
DATE_TIME_FORMAT *time_format;
@@ -1356,7 +1356,11 @@ public:
bool charset_is_system_charset, charset_is_collation_connection;
bool charset_is_character_set_filesystem;
bool enable_slow_log; /* enable slow log for current statement */
- bool no_trans_update, abort_on_warning;
+ struct {
+ bool all:1;
+ bool stmt:1;
+ } no_trans_update;
+ bool abort_on_warning;
bool got_warning; /* Set on call to push_warning() */
bool no_warnings_for_error; /* no warnings on call to my_error() */
/* set during loop of derived table processing */
@@ -1584,7 +1588,7 @@ public:
inline bool really_abort_on_warning()
{
return (abort_on_warning &&
- (!no_trans_update ||
+ (!no_trans_update.stmt ||
(variables.sql_mode & MODE_STRICT_ALL_TABLES)));
}
void set_status_var_init();
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index 09ee4962235..d03a17079d8 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -315,6 +315,7 @@ int check_user(THD *thd, enum enum_server_command command,
bool check_count)
{
DBUG_ENTER("check_user");
+ LEX_STRING db_str= { (char *) db, db ? strlen(db) : 0 };
#ifdef NO_EMBEDDED_ACCESS_CHECKS
thd->main_security_ctx.master_access= GLOBAL_ACLS; // Full rights
@@ -326,7 +327,7 @@ int check_user(THD *thd, enum enum_server_command command,
function returns 0
*/
thd->reset_db(NULL, 0);
- if (mysql_change_db(thd, db, FALSE))
+ if (mysql_change_db(thd, &db_str, FALSE))
{
/* Send the error to the client */
net_send_error(thd);
@@ -472,7 +473,7 @@ int check_user(THD *thd, enum enum_server_command command,
/* Change database if necessary */
if (db && db[0])
{
- if (mysql_change_db(thd, db, FALSE))
+ if (mysql_change_db(thd, &db_str, FALSE))
{
/* Send error to the client */
net_send_error(thd);
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index cc9dc4c1fec..618b9d515bb 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -22,6 +22,7 @@
#include "events.h"
#include <my_dir.h>
#include <m_ctype.h>
+#include "log.h"
#ifdef __WIN__
#include <direct.h>
#endif
@@ -577,7 +578,7 @@ bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
DBUG_ENTER("mysql_create_db");
/* do not create 'information_schema' db */
- if (!my_strcasecmp(system_charset_info, db, information_schema_name.str))
+ if (!my_strcasecmp(system_charset_info, db, INFORMATION_SCHEMA_NAME.str))
{
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
DBUG_RETURN(-1);
@@ -1256,155 +1257,254 @@ err:
}
-/*
- Change the current database.
+/**
+ @brief Internal implementation: switch current database to a valid one.
- SYNOPSIS
- mysql_change_db()
- thd thread handle
- name database name
- no_access_check if TRUE, don't do access check. In this
- case name may be ""
+ @param thd Thread context.
+ @param new_db_name Name of the database to switch to. The function will
+ take ownership of the name (the caller must not free
+ the allocated memory). If the name is NULL, we're
+ going to switch to NULL db.
+ @param new_db_access Privileges of the new database.
+ @param new_db_charset Character set of the new database.
+*/
- DESCRIPTION
- Check that the database name corresponds to a valid and
- existent database, check access rights (unless called with
- no_access_check), and set the current database. This function
- is called to change the current database upon user request
- (COM_CHANGE_DB command) or temporarily, to execute a stored
- routine.
+static void mysql_change_db_impl(THD *thd,
+ LEX_STRING *new_db_name,
+ ulong new_db_access,
+ CHARSET_INFO *new_db_charset)
+{
+ /* 1. Change current database in THD. */
- NOTES
- This function is not the only way to switch the database that
- is currently employed. When the replication slave thread
- switches the database before executing a query, it calls
- thd->set_db directly. However, if the query, in turn, uses
- a stored routine, the stored routine will use this function,
- even if it's run on the slave.
-
- This function allocates the name of the database on the system
- heap: this is necessary to be able to uniformly change the
- database from any module of the server. Up to 5.0 different
- modules were using different memory to store the name of the
- database, and this led to memory corruption: a stack pointer
- set by Stored Procedures was used by replication after the
- stack address was long gone.
-
- This function does not send anything, including error
- messages, to the client. If that should be sent to the client,
- call net_send_error after this function.
+ if (new_db_name == NULL)
+ {
+ /*
+ THD::set_db() does all the job -- it frees previous database name and
+ sets the new one.
+ */
- RETURN VALUES
- 0 OK
- 1 error
+ thd->set_db(NULL, 0);
+ }
+ else if (new_db_name == &INFORMATION_SCHEMA_NAME)
+ {
+ /*
+ Here we must use THD::set_db(), because we want to copy
+ INFORMATION_SCHEMA_NAME constant.
+ */
+
+ thd->set_db(INFORMATION_SCHEMA_NAME.str, INFORMATION_SCHEMA_NAME.length);
+ }
+ else
+ {
+ /*
+ Here we already have a copy of database name to be used in THD. So,
+ we just call THD::reset_db(). Since THD::reset_db() does not releases
+ the previous database name, we should do it explicitly.
+ */
+
+ x_free(thd->db);
+
+ thd->reset_db(new_db_name->str, new_db_name->length);
+ }
+
+ /* 2. Update security context. */
+
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ thd->security_ctx->db_access= new_db_access;
+#endif
+
+ /* 3. Update db-charset environment variables. */
+
+ thd->db_charset= new_db_charset;
+ thd->variables.collation_database= new_db_charset;
+}
+
+
+/**
+ @brief Change the current database.
+
+ @param thd thread handle
+ @param name database name
+ @param force_switch if this flag is set (TRUE), mysql_change_db() will
+ switch to NULL db if the specified database is not
+ available anymore. Corresponding warning will be
+ thrown in this case. This flag is used to change
+ database in stored-routine-execution code.
+
+ @details Check that the database name corresponds to a valid and existent
+ database, check access rights (unless called with no_access_check), and
+ set the current database. This function is called to change the current
+ database upon user request (COM_CHANGE_DB command) or temporarily, to
+ execute a stored routine.
+
+ This function is not the only way to switch the database that is
+ currently employed. When the replication slave thread switches the
+ database before executing a query, it calls thd->set_db directly.
+ However, if the query, in turn, uses a stored routine, the stored routine
+ will use this function, even if it's run on the slave.
+
+ This function allocates the name of the database on the system heap: this
+ is necessary to be able to uniformly change the database from any module
+ of the server. Up to 5.0 different modules were using different memory to
+ store the name of the database, and this led to memory corruption:
+ a stack pointer set by Stored Procedures was used by replication after
+ the stack address was long gone.
+
+ @return Operation status
+ @retval FALSE Success
+ @retval TRUE Error
*/
-bool mysql_change_db(THD *thd, const char *name, bool no_access_check)
+bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch)
{
- LEX_STRING db_name;
- bool system_db= 0;
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- ulong db_access;
+ LEX_STRING new_db_file_name;
+
Security_context *sctx= thd->security_ctx;
- LINT_INIT(db_access);
-#endif
+ ulong db_access= sctx->db_access;
+
DBUG_ENTER("mysql_change_db");
- DBUG_PRINT("enter",("name: '%s'",name));
+ DBUG_PRINT("enter",("name: '%s'", new_db_name->str));
- if (name == NULL || name[0] == '\0' && no_access_check == FALSE)
+ if (new_db_name == NULL ||
+ new_db_name->length == 0)
{
- my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
- DBUG_RETURN(1); /* purecov: inspected */
+ if (force_switch)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR));
+
+ /* Change db to NULL. */
+
+ mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);
+
+ DBUG_RETURN(FALSE);
+ }
+ else
+ {
+ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
+
+ DBUG_RETURN(TRUE);
+ }
}
- else if (name[0] == '\0')
+
+ if (my_strcasecmp(system_charset_info, new_db_name->str,
+ INFORMATION_SCHEMA_NAME.str) == 0)
{
- /* Called from SP to restore the original database, which was NULL */
- DBUG_ASSERT(no_access_check);
- system_db= 1;
- db_name.str= NULL;
- db_name.length= 0;
- goto end;
+ /* Switch database to INFORMATION_SCHEMA. */
+
+ mysql_change_db_impl(thd, &INFORMATION_SCHEMA_NAME, SELECT_ACL,
+ system_charset_info);
+
+ DBUG_RETURN(FALSE);
}
+
/*
Now we need to make a copy because check_db_name requires a
- non-constant argument. TODO: fix check_db_name.
+ non-constant argument. Actually, it takes database file name.
+
+ TODO: fix check_db_name().
*/
- if ((db_name.str= my_strdup(name, MYF(MY_WME))) == NULL)
- DBUG_RETURN(1); /* the error is set */
- db_name.length= strlen(db_name.str);
- if (check_db_name(&db_name))
- {
- my_error(ER_WRONG_DB_NAME, MYF(0), db_name.str);
- my_free(db_name.str, MYF(0));
- DBUG_RETURN(1);
- }
- DBUG_PRINT("info",("Use database: %s", db_name.str));
- if (!my_strcasecmp(system_charset_info, db_name.str,
- information_schema_name.str))
+
+ new_db_file_name.str= my_strndup(new_db_name->str, new_db_name->length,
+ MYF(MY_WME));
+ new_db_file_name.length= new_db_name->length;
+
+ if (new_db_file_name.str == NULL)
+ DBUG_RETURN(TRUE); /* the error is set */
+
+ /*
+ NOTE: if check_db_name() fails, we should throw an error in any case,
+ even if we are called from sp_head::execute().
+
+ It's next to impossible however to get this error when we are called
+ from sp_head::execute(). But let's switch database to NULL in this case
+ to be sure.
+ */
+
+ if (check_db_name(&new_db_file_name))
{
- system_db= 1;
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- db_access= SELECT_ACL;
-#endif
- goto end;
+ my_error(ER_WRONG_DB_NAME, MYF(0), new_db_file_name.str);
+ my_free(new_db_file_name.str, MYF(0));
+
+ if (force_switch)
+ {
+ /* Change db to NULL. */
+ mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);
+ }
+ DBUG_RETURN(TRUE);
}
+ DBUG_PRINT("info",("Use database: %s", new_db_file_name.str));
+
#ifndef NO_EMBEDDED_ACCESS_CHECKS
- if (!no_access_check)
+ if (!force_switch) /* FIXME: this is BUG#27337. */
{
- if (test_all_bits(sctx->master_access, DB_ACLS))
- db_access=DB_ACLS;
- else
- db_access= (acl_get(sctx->host, sctx->ip, sctx->priv_user,
- db_name.str, 0) |
- sctx->master_access);
- if (!(db_access & DB_ACLS) && (!grant_option ||
- check_grant_db(thd, db_name.str)))
+ db_access= (test_all_bits(sctx->master_access, DB_ACLS) ?
+ DB_ACLS :
+ acl_get(sctx->host,
+ sctx->ip,
+ sctx->priv_user,
+ new_db_file_name.str,
+ FALSE) | sctx->master_access);
+
+ if (!force_switch &&
+ !(db_access & DB_ACLS) &&
+ (!grant_option || check_grant_db(thd, new_db_file_name.str)))
{
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
sctx->priv_user,
sctx->priv_host,
- db_name.str);
+ new_db_file_name.str);
general_log_print(thd, COM_INIT_DB, ER(ER_DBACCESS_DENIED_ERROR),
- sctx->priv_user, sctx->priv_host, db_name.str);
- my_free(db_name.str, MYF(0));
- DBUG_RETURN(1);
+ sctx->priv_user, sctx->priv_host,
+ new_db_file_name.str);
+ my_free(new_db_file_name.str, MYF(0));
+ DBUG_RETURN(TRUE);
}
}
#endif
- if (check_db_dir_existence(db_name.str))
+ if (check_db_dir_existence(new_db_file_name.str))
{
- my_error(ER_BAD_DB_ERROR, MYF(0), db_name.str);
- my_free(db_name.str, MYF(0));
- DBUG_RETURN(1);
- }
+ if (force_switch)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR),
+ new_db_file_name.str);
-end:
- x_free(thd->db);
- DBUG_ASSERT(db_name.str == NULL || db_name.str[0] != '\0');
- thd->reset_db(db_name.str, db_name.length); // THD::~THD will free this
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- if (!no_access_check)
- sctx->db_access= db_access;
-#endif
- if (system_db)
- {
- thd->db_charset= system_charset_info;
- thd->variables.collation_database= system_charset_info;
+ my_free(new_db_file_name.str, MYF(0));
+
+ /* Change db to NULL. */
+
+ mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);
+
+ DBUG_RETURN(FALSE);
+ }
+ else
+ {
+ my_error(ER_BAD_DB_ERROR, MYF(0), new_db_file_name.str);
+ my_free(new_db_file_name.str, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
}
- else
+
+ /*
+ NOTE: in mysql_change_db_impl() new_db_file_name is assigned to THD
+ attributes and will be freed in THD::~THD().
+ */
+
{
- HA_CREATE_INFO create;
+ HA_CREATE_INFO db_options;
- load_db_opt_by_name(thd, db_name.str, &create);
+ load_db_opt_by_name(thd, new_db_name->str, &db_options);
- thd->db_charset= create.default_table_charset ?
- create.default_table_charset :
- thd->variables.collation_server;
- thd->variables.collation_database= thd->db_charset;
+ mysql_change_db_impl(thd, &new_db_file_name, db_access,
+ db_options.default_table_charset ?
+ db_options.default_table_charset :
+ thd->variables.collation_server);
}
- DBUG_RETURN(0);
+
+ DBUG_RETURN(FALSE);
}
@@ -1581,8 +1681,8 @@ bool mysql_rename_db(THD *thd, LEX_STRING *old_db, LEX_STRING *new_db)
Failed to move all tables from the old database to the new one.
In the best case mysql_rename_tables() moved all tables back to the old
database. In the worst case mysql_rename_tables() moved some tables
- to the new database, then failed, then started to move the tables back, and
- then failed again. In this situation we have some tables in the
+ to the new database, then failed, then started to move the tables back,
+ and then failed again. In this situation we have some tables in the
old database and some tables in the new database.
Let's delete the option file, and then the new database directory.
If some tables were left in the new directory, rmdir() will fail.
@@ -1703,7 +1803,7 @@ bool mysql_rename_db(THD *thd, LEX_STRING *old_db, LEX_STRING *new_db)
/* Step9: Let's do "use newdb" if we renamed the current database */
if (change_to_newdb)
- error|= mysql_change_db(thd, new_db->str, 0);
+ error|= mysql_change_db(thd, new_db, 0);
exit:
pthread_mutex_lock(&LOCK_lock_db);
@@ -1718,6 +1818,8 @@ exit:
DBUG_RETURN(error);
}
+
+
/*
Check if there is directory for the database name.
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 4e865a12b66..26c12dea081 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -353,7 +353,7 @@ cleanup:
}
}
if (!transactional_table)
- thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
}
free_underlaid_joins(thd, select_lex);
if (transactional_table)
@@ -856,7 +856,7 @@ bool multi_delete::send_eof()
}
}
if (!transactional_tables)
- thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
}
/* Commit or rollback the current SQL statement */
if (transactional_tables)
diff --git a/sql/sql_error.cc b/sql/sql_error.cc
index 70882d8f4e8..f551a7ef4b2 100644
--- a/sql/sql_error.cc
+++ b/sql/sql_error.cc
@@ -147,15 +147,9 @@ MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
if (thd->warn_list.elements < thd->variables.max_error_count)
{
- /*
- The following code is here to change the allocation to not
- use the thd->mem_root, which is freed after each query
- */
- MEM_ROOT *old_root= thd->mem_root;
- thd->mem_root= &thd->warn_root;
- if ((err= new MYSQL_ERROR(thd, code, level, msg)))
+ /* We have to use warn_root, as mem_root is freed after each query */
+ if ((err= new (&thd->warn_root) MYSQL_ERROR(thd, code, level, msg)))
thd->warn_list.push_back(err);
- thd->mem_root= old_root;
}
thd->warn_count[(uint) level]++;
thd->total_warn_count++;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 9852c71e2b4..c1dd947c639 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -611,7 +611,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
if (lock_type != TL_WRITE_DELAYED && !thd->prelocked_mode)
table->file->ha_start_bulk_insert(values_list.elements);
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
thd->abort_on_warning= (!ignore && (thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
@@ -754,7 +754,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
}
}
if (!transactional_table)
- thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
}
}
if (transactional_table)
@@ -1162,7 +1162,7 @@ static int last_uniq_key(TABLE *table,uint keynr)
then both on update triggers will work instead. Similarly both on
delete triggers will be invoked if we will delete conflicting records.
- Sets thd->no_trans_update if table which is updated didn't have
+ Sets thd->no_trans_update.stmt to TRUE if table which is updated didn't have
transactions.
RETURN VALUE
@@ -1365,7 +1365,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
goto err;
info->deleted++;
if (!table->file->has_transactions())
- thd->no_trans_update= 1;
+ thd->no_trans_update.stmt= TRUE;
if (table->triggers &&
table->triggers->process_triggers(thd, TRG_EVENT_DELETE,
TRG_ACTION_AFTER, TRUE))
@@ -1406,7 +1406,7 @@ ok_or_after_trg_err:
if (key)
my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH);
if (!table->file->has_transactions())
- thd->no_trans_update= 1;
+ thd->no_trans_update.stmt= TRUE;
DBUG_RETURN(trg_error);
err:
@@ -2679,7 +2679,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (info.handle_duplicates == DUP_REPLACE &&
(!table->triggers || !table->triggers->has_delete_triggers()))
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
thd->abort_on_warning= (!info.ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
@@ -2860,7 +2860,7 @@ void select_insert::send_error(uint errcode,const char *err)
table->file->has_transactions(), FALSE);
if (!thd->current_stmt_binlog_row_based && !table->s->tmp_table &&
!can_rollback_data())
- thd->options|= OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
query_cache_invalidate3(thd, table, 1);
}
}
@@ -2901,7 +2901,7 @@ bool select_insert::send_eof()
*/
if (!trans_table &&
(!table->s->tmp_table || !thd->current_stmt_binlog_row_based))
- thd->options|= OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
}
/*
@@ -3208,7 +3208,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
if (!thd->prelocked_mode)
table->file->ha_start_bulk_insert((ha_rows) 0);
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
thd->abort_on_warning= (!info.ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 41de2c86740..71cc4c0507c 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -376,7 +376,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
table->file->ha_start_bulk_insert((ha_rows) 0);
table->copy_blobs=1;
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
thd->abort_on_warning= (!ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
@@ -470,7 +470,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
if (!transactional_table)
- thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
#ifndef EMBEDDED_LIBRARY
if (mysql_bin_log.is_open())
{
@@ -552,7 +552,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
Item_field *sql_field;
TABLE *table= table_list->table;
ulonglong id;
- bool no_trans_update, err;
+ bool no_trans_update_stmt, err;
DBUG_ENTER("read_fixed_length");
id= 0;
@@ -580,7 +580,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
#ifdef HAVE_purify
read_info.row_end[0]=0;
#endif
- no_trans_update= !table->file->has_transactions();
+ no_trans_update_stmt= !table->file->has_transactions();
restore_record(table, s->default_values);
/*
@@ -648,7 +648,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
table->auto_increment_field_not_null= FALSE;
if (err)
DBUG_RETURN(1);
- thd->no_trans_update= no_trans_update;
+ thd->no_trans_update.stmt= no_trans_update_stmt;
/*
We don't need to reset auto-increment field since we are restoring
@@ -683,12 +683,12 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
TABLE *table= table_list->table;
uint enclosed_length;
ulonglong id;
- bool no_trans_update, err;
+ bool no_trans_update_stmt, err;
DBUG_ENTER("read_sep_field");
enclosed_length=enclosed.length();
id= 0;
- no_trans_update= !table->file->has_transactions();
+ no_trans_update_stmt= !table->file->has_transactions();
for (;;it.rewind())
{
@@ -823,7 +823,7 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
We don't need to reset auto-increment field since we are restoring
its default value at the beginning of each loop iteration.
*/
- thd->no_trans_update= no_trans_update;
+ thd->no_trans_update.stmt= no_trans_update_stmt;
if (read_info.next_line()) // Skip to next line
break;
if (read_info.line_cuted)
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 9d02053ec00..0c50a6212ad 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -118,8 +118,8 @@ bool end_active_trans(THD *thd)
if (ha_commit(thd))
error=1;
}
- thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG);
+ thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->no_trans_update.all= FALSE;
DBUG_RETURN(error);
}
@@ -545,8 +545,8 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion)
*/
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
res= ha_commit(thd);
- thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG);
+ thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->no_trans_update.all= FALSE;
break;
case COMMIT_RELEASE:
do_release= 1; /* fall through */
@@ -563,8 +563,8 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion)
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
if (ha_rollback(thd))
res= -1;
- thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG);
+ thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->no_trans_update.all= FALSE;
if (!res && (completion == ROLLBACK_AND_CHAIN))
res= begin_trans(thd);
break;
@@ -719,7 +719,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
&LOCK_status);
thd->convert_string(&tmp, system_charset_info,
packet, packet_length-1, thd->charset());
- if (!mysql_change_db(thd, tmp.str, FALSE))
+ if (!mysql_change_db(thd, &tmp, FALSE))
{
general_log_print(thd, command, "%s",thd->db);
send_ok(thd);
@@ -960,7 +960,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
packet= arg_end + 1;
if (!my_strcasecmp(system_charset_info, table_list.db,
- information_schema_name.str))
+ INFORMATION_SCHEMA_NAME.str))
{
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, table_list.alias);
if (schema_table)
@@ -2843,7 +2843,7 @@ end_with_restore_list:
we silently add IF EXISTS if TEMPORARY was used.
*/
if (thd->slave_thread)
- lex->drop_if_exists= 1;
+ lex->drop_if_exists= 1;
/* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
thd->options|= OPTION_KEEP_LOG;
@@ -2900,9 +2900,14 @@ end_with_restore_list:
}
#endif
case SQLCOM_CHANGE_DB:
- if (!mysql_change_db(thd,select_lex->db,FALSE))
+ {
+ LEX_STRING db_str= { (char *) select_lex->db, strlen(select_lex->db) };
+
+ if (!mysql_change_db(thd, &db_str, FALSE))
send_ok(thd);
+
break;
+ }
case SQLCOM_LOAD:
{
@@ -3545,8 +3550,7 @@ end_with_restore_list:
res= TRUE; // cannot happen
else
{
- if ((thd->options &
- (OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG)) &&
+ if (((thd->options & OPTION_KEEP_LOG) || thd->no_trans_update.all) &&
!thd->slave_thread)
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARNING_NOT_COMPLETE_ROLLBACK,
@@ -4103,9 +4107,8 @@ create_sp_error:
thd->transaction.xid_state.xa_state=XA_ACTIVE;
thd->transaction.xid_state.xid.set(thd->lex->xid);
xid_cache_insert(&thd->transaction.xid_state);
- thd->options= ((thd->options & ~(OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG)) |
- OPTION_BEGIN);
+ thd->options= ((thd->options & ~(OPTION_KEEP_LOG)) | OPTION_BEGIN);
+ thd->no_trans_update.all= FALSE;
thd->server_status|= SERVER_STATUS_IN_TRANS;
send_ok(thd);
break;
@@ -4198,8 +4201,8 @@ create_sp_error:
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
- thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG);
+ thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->no_trans_update.all= FALSE;
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
xid_cache_delete(&thd->transaction.xid_state);
thd->transaction.xid_state.xa_state=XA_NOTR;
@@ -4229,8 +4232,8 @@ create_sp_error:
my_error(ER_XAER_RMERR, MYF(0));
else
send_ok(thd);
- thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE |
- OPTION_KEEP_LOG);
+ thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
+ thd->no_trans_update.all= FALSE;
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
xid_cache_delete(&thd->transaction.xid_state);
thd->transaction.xid_state.xa_state=XA_NOTR;
@@ -4467,7 +4470,10 @@ bool check_single_table_access(THD *thd, ulong privilege,
goto deny;
/* Show only 1 table for check_grant */
- if (grant_option && check_grant(thd, privilege, all_tables, 0, 1, no_errors))
+ if (grant_option &&
+ !(all_tables->belong_to_view &&
+ (thd->lex->sql_command == SQLCOM_SHOW_FIELDS)) &&
+ check_grant(thd, privilege, all_tables, 0, 1, no_errors))
goto deny;
thd->security_ctx= backup_ctx;
@@ -4736,7 +4742,7 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables,
if (!no_errors)
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
sctx->priv_user, sctx->priv_host,
- information_schema_name.str);
+ INFORMATION_SCHEMA_NAME.str);
return TRUE;
}
/*
@@ -5024,8 +5030,10 @@ void mysql_reset_thd_for_next_command(THD *thd)
in ha_rollback_trans() about some tables couldn't be rolled back.
*/
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
- thd->options&= ~(OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG);
-
+ {
+ thd->options&= ~OPTION_KEEP_LOG;
+ thd->no_trans_update.all= FALSE;
+ }
DBUG_ASSERT(thd->security_ctx== &thd->main_security_ctx);
thd->tmp_table_used= 0;
if (!thd->in_sub_stmt)
@@ -5526,7 +5534,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES);
ptr->derived= table->sel;
if (!ptr->derived && !my_strcasecmp(system_charset_info, ptr->db,
- information_schema_name.str))
+ INFORMATION_SCHEMA_NAME.str))
{
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->table_name);
if (!schema_table ||
@@ -5534,7 +5542,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
(sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0))
{
my_error(ER_UNKNOWN_TABLE, MYF(0),
- ptr->table_name, information_schema_name.str);
+ ptr->table_name, INFORMATION_SCHEMA_NAME.str);
DBUG_RETURN(0);
}
ptr->schema_table_name= ptr->table_name;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index e97670ab2b1..31a6c7af04a 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1670,7 +1670,7 @@ static bool check_prepared_statement(Prepared_statement *stmt,
enum enum_sql_command sql_command= lex->sql_command;
int res= 0;
DBUG_ENTER("check_prepared_statement");
- DBUG_PRINT("enter",("command: %d, param_count: %u",
+ DBUG_PRINT("enter",("command: %d param_count: %u",
sql_command, stmt->param_count));
lex->first_lists_tables_same();
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 0d620d33dbb..19cabb874b9 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -715,9 +715,9 @@ bool mysqld_show_create_db(THD *thd, char *dbname,
}
#endif
if (!my_strcasecmp(system_charset_info, dbname,
- information_schema_name.str))
+ INFORMATION_SCHEMA_NAME.str))
{
- dbname= information_schema_name.str;
+ dbname= INFORMATION_SCHEMA_NAME.str;
create.default_table_charset= system_charset_info;
}
else
@@ -1800,7 +1800,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
else
table->field[4]->store(command_name[tmp->command].str,
command_name[tmp->command].length, cs);
- /* TIME */
+ /* MYSQL_TIME */
table->field[5]->store((uint32)(tmp->start_time ?
now - tmp->start_time : 0), TRUE);
/* STATE */
@@ -2197,7 +2197,7 @@ LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str,
/* INFORMATION_SCHEMA name */
-LEX_STRING information_schema_name= { C_STRING_WITH_LEN("information_schema")};
+LEX_STRING INFORMATION_SCHEMA_NAME= { C_STRING_WITH_LEN("information_schema")};
/* This is only used internally, but we need it here as a forward reference */
extern ST_SCHEMA_TABLE schema_tables[];
@@ -2413,11 +2413,11 @@ int make_db_list(THD *thd, List<char> *files,
*/
if (!idx_field_vals->db_value ||
!wild_case_compare(system_charset_info,
- information_schema_name.str,
+ INFORMATION_SCHEMA_NAME.str,
idx_field_vals->db_value))
{
*with_i_schema= 1;
- if (files->push_back(thd->strdup(information_schema_name.str)))
+ if (files->push_back(thd->strdup(INFORMATION_SCHEMA_NAME.str)))
return 1;
}
return (find_files(thd, files, NullS, mysql_data_home,
@@ -2431,11 +2431,11 @@ int make_db_list(THD *thd, List<char> *files,
*/
if (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND)
{
- if (!my_strcasecmp(system_charset_info, information_schema_name.str,
+ if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
idx_field_vals->db_value))
{
*with_i_schema= 1;
- return files->push_back(thd->strdup(information_schema_name.str));
+ return files->push_back(thd->strdup(INFORMATION_SCHEMA_NAME.str));
}
return files->push_back(thd->strdup(idx_field_vals->db_value));
}
@@ -2444,7 +2444,7 @@ int make_db_list(THD *thd, List<char> *files,
Create list of existing databases. It is used in case
of select from information schema table
*/
- if (files->push_back(thd->strdup(information_schema_name.str)))
+ if (files->push_back(thd->strdup(INFORMATION_SCHEMA_NAME.str)))
return 1;
*with_i_schema= 1;
return (find_files(thd, files, NullS,
@@ -2837,7 +2837,7 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
const char *file_name)
{
const char *tmp_buff;
- TIME time;
+ MYSQL_TIME time;
CHARSET_INFO *cs= system_charset_info;
DBUG_ENTER("get_schema_tables_record");
@@ -3396,7 +3396,7 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table,
{
String tmp_string;
String sp_db, sp_name, definer;
- TIME time;
+ MYSQL_TIME time;
LEX *lex= thd->lex;
CHARSET_INFO *cs= system_charset_info;
get_field(thd->mem_root, proc_table->field[0], &sp_db);
@@ -3965,7 +3965,7 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table,
TABLE* table= schema_table;
CHARSET_INFO *cs= system_charset_info;
PARTITION_INFO stat_info;
- TIME time;
+ MYSQL_TIME time;
file->get_dynamic_partition_info(&stat_info, part_id);
table->field[12]->store((longlong) stat_info.records, TRUE);
table->field[13]->store((longlong) stat_info.mean_rec_length, TRUE);
@@ -4303,7 +4303,7 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table)
{
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
CHARSET_INFO *scs= system_charset_info;
- TIME time;
+ MYSQL_TIME time;
Event_timed et;
DBUG_ENTER("copy_event_to_schema_table");
@@ -5052,8 +5052,8 @@ int make_schema_select(THD *thd, SELECT_LEX *sel,
We have to make non const db_name & table_name
because of lower_case_table_names
*/
- make_lex_string(thd, &db, information_schema_name.str,
- information_schema_name.length, 0);
+ make_lex_string(thd, &db, INFORMATION_SCHEMA_NAME.str,
+ INFORMATION_SCHEMA_NAME.length, 0);
make_lex_string(thd, &table, schema_table->table_name,
strlen(schema_table->table_name), 0);
if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 0ec0a8e0f86..b6bc78b216f 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -6782,7 +6782,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
alter_table_manage_keys(to, from->file->indexes_are_disabled(), keys_onoff);
/* We can abort alter table for any table type */
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
thd->abort_on_warning= !ignore && test(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES));
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 56c952f34ce..d0da52827e0 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -449,7 +449,7 @@ int mysql_update(THD *thd,
thd->proc_info="Updating";
transactional_table= table->file->has_transactions();
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
thd->abort_on_warning= test(!ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
@@ -489,7 +489,7 @@ int mysql_update(THD *thd,
if (fill_record_n_invoke_before_triggers(thd, fields, values, 0,
table->triggers,
TRG_EVENT_UPDATE))
- break; /* purecov: inspected */
+ break; /* purecov: inspected */
found++;
@@ -550,7 +550,7 @@ int mysql_update(THD *thd,
if (!error)
{
updated++;
- thd->no_trans_update= !transactional_table;
+ thd->no_trans_update.stmt= !transactional_table;
if (table->triggers &&
table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
@@ -676,11 +676,11 @@ int mysql_update(THD *thd,
transactional_table, FALSE) &&
transactional_table)
{
- error=1; // Rollback update
+ error=1; // Rollback update
}
}
if (!transactional_table)
- thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
}
free_underlaid_joins(thd, select_lex);
if (transactional_table)
@@ -1045,7 +1045,7 @@ bool mysql_multi_update(THD *thd,
handle_duplicates, ignore)))
DBUG_RETURN(TRUE);
- thd->no_trans_update= 0;
+ thd->no_trans_update.stmt= FALSE;
thd->abort_on_warning= test(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES));
@@ -1370,7 +1370,7 @@ multi_update::~multi_update()
delete [] copy_field;
thd->count_cuted_fields= CHECK_FIELD_IGNORE; // Restore this setting
if (!trans_safe)
- thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
}
@@ -1431,40 +1431,40 @@ bool multi_update::send_data(List<Item> &not_used_values)
else if (error == VIEW_CHECK_ERROR)
DBUG_RETURN(1);
}
- if (!updated++)
- {
- /*
- Inform the main table that we are going to update the table even
- while we may be scanning it. This will flush the read cache
- if it's used.
- */
- main_table->file->extra(HA_EXTRA_PREPARE_FOR_UPDATE);
- }
- if ((error=table->file->ha_update_row(table->record[1],
- table->record[0])))
- {
- updated--;
+ if (!updated++)
+ {
+ /*
+ Inform the main table that we are going to update the table even
+ while we may be scanning it. This will flush the read cache
+ if it's used.
+ */
+ main_table->file->extra(HA_EXTRA_PREPARE_FOR_UPDATE);
+ }
+ if ((error=table->file->ha_update_row(table->record[1],
+ table->record[0])))
+ {
+ updated--;
if (!ignore ||
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
- {
+ {
/*
If (ignore && error == is ignorable) we don't have to
do anything; otherwise...
*/
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
thd->fatal_error(); /* Other handler errors are fatal */
- table->file->print_error(error,MYF(0));
- DBUG_RETURN(1);
- }
- }
+ table->file->print_error(error,MYF(0));
+ DBUG_RETURN(1);
+ }
+ }
else
{
if (!table->file->has_transactions())
- thd->no_trans_update= 1;
+ thd->no_trans_update.stmt= TRUE;
if (table->triggers &&
table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
TRG_ACTION_AFTER, TRUE))
- DBUG_RETURN(1);
+ DBUG_RETURN(1);
}
}
}
@@ -1700,7 +1700,7 @@ bool multi_update::send_eof()
}
}
if (!transactional_tables)
- thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
+ thd->no_trans_update.all= TRUE;
}
if (transactional_tables)
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index f84847f2f9c..c02fb7bcdc0 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -496,35 +496,46 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
/*
Compare/check grants on view with grants of underlying tables
*/
+
+ fill_effective_table_privileges(thd, &view->grant, view->db,
+ view->table_name);
+
+ {
+ Item *report_item= NULL;
+ uint final_priv= VIEW_ANY_ACL;
+
for (sl= select_lex; sl; sl= sl->next_select())
{
DBUG_ASSERT(view->db); /* Must be set in the parser */
List_iterator_fast<Item> it(sl->item_list);
Item *item;
- fill_effective_table_privileges(thd, &view->grant, view->db,
- view->table_name);
while ((item= it++))
{
- Item_field *fld;
+ Item_field *fld= item->filed_for_view_update();
uint priv= (get_column_grant(thd, &view->grant, view->db,
view->table_name, item->name) &
VIEW_ANY_ACL);
- if ((fld= item->filed_for_view_update()))
+
+ if (fld && !fld->field->table->s->tmp_table)
{
- /*
- Do we have more privileges on view field then underlying table field?
- */
- if (!fld->field->table->s->tmp_table && (~fld->have_privileges & priv))
+ final_priv&= fld->have_privileges;
+
+ if (~fld->have_privileges & priv)
+ report_item= item;
+ }
+ }
+ }
+
+ if (!final_priv)
{
- /* VIEW column has more privileges */
+ DBUG_ASSERT(report_item);
+
my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
"create view", thd->security_ctx->priv_user,
- thd->security_ctx->priv_host, item->name,
+ thd->security_ctx->priv_host, report_item->name,
view->table_name);
res= TRUE;
goto err;
- }
- }
}
}
#endif
@@ -1008,6 +1019,11 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
CHARSET_INFO *save_cs= thd->variables.character_set_client;
thd->variables.character_set_client= system_charset_info;
res= MYSQLparse((void *)thd);
+
+ if ((old_lex->sql_command == SQLCOM_SHOW_FIELDS) ||
+ (old_lex->sql_command == SQLCOM_SHOW_CREATE))
+ lex->sql_command= old_lex->sql_command;
+
thd->variables.character_set_client= save_cs;
thd->variables.sql_mode= save_mode;
}
@@ -1033,7 +1049,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
}
}
else if (!table->prelocking_placeholder &&
- old_lex->sql_command == SQLCOM_SHOW_CREATE &&
+ (old_lex->sql_command == SQLCOM_SHOW_CREATE) &&
!table->belong_to_view)
{
if (check_table_access(thd, SHOW_VIEW_ACL, table, 0))
diff --git a/sql/structs.h b/sql/structs.h
index 377d337dcfa..4cf9379d2bb 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -136,12 +136,11 @@ typedef struct st_read_record { /* Parameter to read_record */
/*
- Originally MySQL used TIME structure inside server only, but since
+ Originally MySQL used MYSQL_TIME structure inside server only, but since
4.1 it's exported to user in the new client API. Define aliases for
new names to keep existing code simple.
*/
-typedef struct st_mysql_time TIME;
typedef enum enum_mysql_timestamp_type timestamp_type;
diff --git a/sql/table.cc b/sql/table.cc
index c0b04093f36..39bdbb4cbb9 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2967,7 +2967,7 @@ void st_table_list::hide_view_error(THD *thd)
thd->net.last_errno == ER_NO_SUCH_TABLE)
{
TABLE_LIST *top= top_table();
- thd->clear_error();
+ thd->clear_error();
my_error(ER_VIEW_INVALID, MYF(0), top->view_db.str, top->view_name.str);
}
else if (thd->net.last_errno == ER_NO_DEFAULT_FOR_FIELD)
@@ -3323,7 +3323,8 @@ bool st_table_list::prepare_view_securety_context(THD *thd)
definer.host.str,
thd->db))
{
- if (thd->lex->sql_command == SQLCOM_SHOW_CREATE)
+ if ((thd->lex->sql_command == SQLCOM_SHOW_CREATE) ||
+ (thd->lex->sql_command == SQLCOM_SHOW_FIELDS))
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_NO_SUCH_USER,
diff --git a/sql/time.cc b/sql/time.cc
index ef2c87673d5..249de3b879b 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -96,7 +96,7 @@ int calc_weekday(long daynr,bool sunday_first_day_of_week)
next week is week 1.
*/
-uint calc_week(TIME *l_time, uint week_behaviour, uint *year)
+uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year)
{
uint days;
ulong daynr=calc_daynr(l_time->year,l_time->month,l_time->day);
@@ -214,7 +214,7 @@ ulong convert_month_to_period(ulong month)
/*
- Convert a timestamp string to a TIME value and produce a warning
+ Convert a timestamp string to a MYSQL_TIME value and produce a warning
if string was truncated during conversion.
NOTE
@@ -222,7 +222,7 @@ ulong convert_month_to_period(ulong month)
*/
timestamp_type
-str_to_datetime_with_warn(const char *str, uint length, TIME *l_time,
+str_to_datetime_with_warn(const char *str, uint length, MYSQL_TIME *l_time,
uint flags)
{
int was_cut;
@@ -235,13 +235,14 @@ str_to_datetime_with_warn(const char *str, uint length, TIME *l_time,
MODE_NO_ZERO_DATE))),
&was_cut);
if (was_cut || ts_type <= MYSQL_TIMESTAMP_ERROR)
- make_truncated_value_warning(current_thd, str, length, ts_type, NullS);
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ str, length, ts_type, NullS);
return ts_type;
}
/*
- Convert a datetime from broken-down TIME representation to corresponding
+ Convert a datetime from broken-down MYSQL_TIME representation to corresponding
TIMESTAMP value.
SYNOPSIS
@@ -257,7 +258,7 @@ str_to_datetime_with_warn(const char *str, uint length, TIME *l_time,
0 - t contains datetime value which is out of TIMESTAMP range.
*/
-my_time_t TIME_to_timestamp(THD *thd, const TIME *t, my_bool *in_dst_time_gap)
+my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *in_dst_time_gap)
{
my_time_t timestamp;
@@ -276,20 +277,20 @@ my_time_t TIME_to_timestamp(THD *thd, const TIME *t, my_bool *in_dst_time_gap)
/*
- Convert a time string to a TIME struct and produce a warning
+ Convert a time string to a MYSQL_TIME struct and produce a warning
if string was cut during conversion.
NOTE
See str_to_time() for more info.
*/
bool
-str_to_time_with_warn(const char *str, uint length, TIME *l_time)
+str_to_time_with_warn(const char *str, uint length, MYSQL_TIME *l_time)
{
int warning;
bool ret_val= str_to_time(str, length, l_time, &warning);
if (ret_val || warning)
- make_truncated_value_warning(current_thd, str, length,
- MYSQL_TIMESTAMP_TIME, NullS);
+ make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ str, length, MYSQL_TIMESTAMP_TIME, NullS);
return ret_val;
}
@@ -298,7 +299,7 @@ str_to_time_with_warn(const char *str, uint length, TIME *l_time)
Convert a system time structure to TIME
*/
-void localtime_to_TIME(TIME *to, struct tm *from)
+void localtime_to_TIME(MYSQL_TIME *to, struct tm *from)
{
to->neg=0;
to->second_part=0;
@@ -310,7 +311,7 @@ void localtime_to_TIME(TIME *to, struct tm *from)
to->second= (int) from->tm_sec;
}
-void calc_time_from_sec(TIME *to, long seconds, long microseconds)
+void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds)
{
long t_seconds;
// to->neg is not cleared, it may already be set to a useful value
@@ -684,7 +685,7 @@ const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
MySQL doesn't support comparing of date/time/datetime strings that
are not in arbutary order as dates are compared as strings in some
context)
- This functions don't check that given TIME structure members are
+ This functions don't check that given MYSQL_TIME structure members are
in valid range. If they are not, return value won't reflect any
valid date either. Additionally, make_time doesn't take into
account time->day member: it's assumed that days have been converted
@@ -692,7 +693,7 @@ const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
****************************************************************************/
void make_time(const DATE_TIME_FORMAT *format __attribute__((unused)),
- const TIME *l_time, String *str)
+ const MYSQL_TIME *l_time, String *str)
{
uint length= (uint) my_time_to_str(l_time, (char*) str->ptr());
str->length(length);
@@ -701,7 +702,7 @@ void make_time(const DATE_TIME_FORMAT *format __attribute__((unused)),
void make_date(const DATE_TIME_FORMAT *format __attribute__((unused)),
- const TIME *l_time, String *str)
+ const MYSQL_TIME *l_time, String *str)
{
uint length= (uint) my_date_to_str(l_time, (char*) str->ptr());
str->length(length);
@@ -710,7 +711,7 @@ void make_date(const DATE_TIME_FORMAT *format __attribute__((unused)),
void make_datetime(const DATE_TIME_FORMAT *format __attribute__((unused)),
- const TIME *l_time, String *str)
+ const MYSQL_TIME *l_time, String *str)
{
uint length= (uint) my_datetime_to_str(l_time, (char*) str->ptr());
str->length(length);
@@ -718,7 +719,8 @@ void make_datetime(const DATE_TIME_FORMAT *format __attribute__((unused)),
}
-void make_truncated_value_warning(THD *thd, const char *str_val,
+void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
+ const char *str_val,
uint str_length, timestamp_type time_type,
const char *field_name)
{
@@ -757,14 +759,14 @@ void make_truncated_value_warning(THD *thd, const char *str_val,
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
ER(ER_WRONG_VALUE), type_str, str.c_ptr());
}
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ push_warning(thd, level,
ER_TRUNCATED_WRONG_VALUE, warn_buff);
}
/* Daynumber from year 0 to 9999-12-31 */
#define MAX_DAY_NUMBER 3652424L
-bool date_add_interval(TIME *ltime, interval_type int_type, INTERVAL interval)
+bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval)
{
long period, sign;
@@ -888,7 +890,7 @@ invalid_date:
NOTE
This function calculates difference between l_time1 and l_time2 absolute
values. So one should set l_sign and correct result if he want to take
- signs into account (i.e. for TIME values).
+ signs into account (i.e. for MYSQL_TIME values).
RETURN VALUES
Returns sign of difference.
@@ -898,7 +900,7 @@ invalid_date:
*/
bool
-calc_time_diff(TIME *l_time1, TIME *l_time2, int l_sign, longlong *seconds_out,
+calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, longlong *seconds_out,
long *microseconds_out)
{
long days;
@@ -948,7 +950,7 @@ calc_time_diff(TIME *l_time1, TIME *l_time2, int l_sign, longlong *seconds_out,
/*
- Compares 2 TIME structures
+ Compares 2 MYSQL_TIME structures
SYNOPSIS
my_time_compare()
@@ -966,7 +968,7 @@ calc_time_diff(TIME *l_time1, TIME *l_time2, int l_sign, longlong *seconds_out,
*/
int
-my_time_compare(TIME *a, TIME *b)
+my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b)
{
my_ulonglong a_t= TIME_to_ulonglong_datetime(a);
my_ulonglong b_t= TIME_to_ulonglong_datetime(b);
diff --git a/sql/tztime.cc b/sql/tztime.cc
index 65a1a59a5d0..08b93cfd203 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -77,7 +77,7 @@ typedef struct lsinfo
/*
Structure with information describing ranges of my_time_t shifted to local
- time (my_time_t + offset). Used for local TIME -> my_time_t conversion.
+ time (my_time_t + offset). Used for local MYSQL_TIME -> my_time_t conversion.
See comments for TIME_to_gmt_sec() for more info.
*/
typedef struct revtinfo
@@ -292,9 +292,9 @@ tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage)
be used if there are no transitions or we have moment in time before
any transitions.
Second task is to build "shifted my_time_t" -> my_time_t map used in
- TIME -> my_time_t conversion.
+ MYSQL_TIME -> my_time_t conversion.
Note: See description of TIME_to_gmt_sec() function first.
- In order to perform TIME -> my_time_t conversion we need to build table
+ In order to perform MYSQL_TIME -> my_time_t conversion we need to build table
which defines "shifted by tz offset and leap seconds my_time_t" ->
my_time_t function wich is almost the same (except ranges of ambiguity)
as reverse function to piecewise linear function used for my_time_t ->
@@ -531,14 +531,14 @@ static const uint year_lengths[2]=
offset - local time zone offset
DESCRIPTION
- Convert my_time_t with offset to TIME struct. Differs from timesub
+ Convert my_time_t with offset to MYSQL_TIME struct. Differs from timesub
(from elsie code) because doesn't contain any leap correction and
TM_GMTOFF and is_dst setting and contains some MySQL specific
initialization. Funny but with removing of these we almost have
glibc's offtime function.
*/
static void
-sec_to_TIME(TIME * tmp, my_time_t t, long offset)
+sec_to_TIME(MYSQL_TIME * tmp, my_time_t t, long offset)
{
long days;
long rem;
@@ -594,7 +594,7 @@ sec_to_TIME(TIME * tmp, my_time_t t, long offset)
tmp->month++;
tmp->day= (uint)(days + 1);
- /* filling MySQL specific TIME members */
+ /* filling MySQL specific MYSQL_TIME members */
tmp->neg= 0; tmp->second_part= 0;
tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
}
@@ -686,7 +686,7 @@ find_transition_type(my_time_t t, const TIME_ZONE_INFO *sp)
/*
Converts time in my_time_t representation (seconds in UTC since Epoch) to
- broken down TIME representation in local time zone.
+ broken down MYSQL_TIME representation in local time zone.
SYNOPSIS
gmt_sec_to_TIME()
@@ -701,12 +701,12 @@ find_transition_type(my_time_t t, const TIME_ZONE_INFO *sp)
(60th and 61st second, look how we calculate them as "hit" in this
function).
Under realistic assumptions about frequency of transitions the same array
- can be used fot TIME -> my_time_t conversion. For this we need to
+ can be used fot MYSQL_TIME -> my_time_t conversion. For this we need to
implement tweaked binary search which will take into account that some
- TIME has two matching my_time_t ranges and some of them have none.
+ MYSQL_TIME has two matching my_time_t ranges and some of them have none.
*/
static void
-gmt_sec_to_TIME(TIME *tmp, my_time_t sec_in_utc, const TIME_ZONE_INFO *sp)
+gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t sec_in_utc, const TIME_ZONE_INFO *sp)
{
const TRAN_TYPE_INFO *ttisp;
const LS_INFO *lp;
@@ -809,11 +809,11 @@ sec_since_epoch(int year, int mon, int mday, int hour, int min ,int sec)
/*
- Works like sec_since_epoch but expects TIME structure as parameter.
+ Works like sec_since_epoch but expects MYSQL_TIME structure as parameter.
*/
my_time_t
-sec_since_epoch_TIME(TIME *t)
+sec_since_epoch_TIME(MYSQL_TIME *t)
{
return sec_since_epoch(t->year, t->month, t->day,
t->hour, t->minute, t->second);
@@ -821,7 +821,7 @@ sec_since_epoch_TIME(TIME *t)
/*
- Converts local time in broken down TIME representation to my_time_t
+ Converts local time in broken down MYSQL_TIME representation to my_time_t
representation.
SYNOPSIS
@@ -863,7 +863,7 @@ sec_since_epoch_TIME(TIME *t)
We use completely different approach. It is better since it is both
faster than iterative implementations and fully determenistic. If you
- look at my_time_t to TIME conversion then you'll find that it consist
+ look at my_time_t to MYSQL_TIME conversion then you'll find that it consist
of two steps:
The first is calculating shifted my_time_t value and the second - TIME
calculation from shifted my_time_t value (well it is a bit simplified
@@ -893,7 +893,7 @@ sec_since_epoch_TIME(TIME *t)
0 in case of error.
*/
static my_time_t
-TIME_to_gmt_sec(const TIME *t, const TIME_ZONE_INFO *sp,
+TIME_to_gmt_sec(const MYSQL_TIME *t, const TIME_ZONE_INFO *sp,
my_bool *in_dst_time_gap)
{
my_time_t local_t;
@@ -1020,20 +1020,20 @@ class Time_zone_system : public Time_zone
{
public:
Time_zone_system() {} /* Remove gcc warning */
- virtual my_time_t TIME_to_gmt_sec(const TIME *t,
+ virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
my_bool *in_dst_time_gap) const;
- virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const;
+ virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
virtual const String * get_name() const;
};
/*
- Converts local time in system time zone in TIME representation
+ Converts local time in system time zone in MYSQL_TIME representation
to its my_time_t representation.
SYNOPSIS
TIME_to_gmt_sec()
- t - pointer to TIME structure with local time in
+ t - pointer to MYSQL_TIME structure with local time in
broken-down representation.
in_dst_time_gap - pointer to bool which is set to true if datetime
value passed doesn't really exist (i.e. falls into
@@ -1041,7 +1041,7 @@ public:
DESCRIPTION
This method uses system function (localtime_r()) for conversion
- local time in system time zone in TIME structure to its my_time_t
+ local time in system time zone in MYSQL_TIME structure to its my_time_t
representation. Unlike the same function for Time_zone_db class
it it won't handle unnormalized input properly. Still it will
return lowest possible my_time_t in case of ambiguity or if we
@@ -1053,7 +1053,7 @@ public:
Corresponding my_time_t value or 0 in case of error
*/
my_time_t
-Time_zone_system::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
+Time_zone_system::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
{
long not_used;
return my_system_gmt_sec(t, &not_used, in_dst_time_gap);
@@ -1066,7 +1066,7 @@ Time_zone_system::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
SYNOPSIS
gmt_sec_to_TIME()
- tmp - pointer to TIME structure to fill-in
+ tmp - pointer to MYSQL_TIME structure to fill-in
t - my_time_t value to be converted
NOTE
@@ -1077,7 +1077,7 @@ Time_zone_system::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
the 1902 easily.
*/
void
-Time_zone_system::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const
+Time_zone_system::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
{
struct tm tmp_tm;
time_t tmp_t= (time_t)t;
@@ -1107,26 +1107,26 @@ Time_zone_system::get_name() const
/*
Instance of this class represents UTC time zone. It uses system gmtime_r
function for conversions and is always available. It is used only for
- my_time_t -> TIME conversions in various UTC_... functions, it is not
- intended for TIME -> my_time_t conversions and shouldn't be exposed to user.
+ my_time_t -> MYSQL_TIME conversions in various UTC_... functions, it is not
+ intended for MYSQL_TIME -> my_time_t conversions and shouldn't be exposed to user.
*/
class Time_zone_utc : public Time_zone
{
public:
Time_zone_utc() {} /* Remove gcc warning */
- virtual my_time_t TIME_to_gmt_sec(const TIME *t,
+ virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
my_bool *in_dst_time_gap) const;
- virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const;
+ virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
virtual const String * get_name() const;
};
/*
- Convert UTC time from TIME representation to its my_time_t representation.
+ Convert UTC time from MYSQL_TIME representation to its my_time_t representation.
SYNOPSIS
TIME_to_gmt_sec()
- t - pointer to TIME structure with local time
+ t - pointer to MYSQL_TIME structure with local time
in broken-down representation.
in_dst_time_gap - pointer to bool which is set to true if datetime
value passed doesn't really exist (i.e. falls into
@@ -1141,7 +1141,7 @@ public:
0
*/
my_time_t
-Time_zone_utc::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
+Time_zone_utc::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
{
/* Should be never called */
DBUG_ASSERT(0);
@@ -1155,14 +1155,14 @@ Time_zone_utc::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
SYNOPSIS
gmt_sec_to_TIME()
- tmp - pointer to TIME structure to fill-in
+ tmp - pointer to MYSQL_TIME structure to fill-in
t - my_time_t value to be converted
NOTE
See note for apropriate Time_zone_system method.
*/
void
-Time_zone_utc::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const
+Time_zone_utc::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
{
struct tm tmp_tm;
time_t tmp_t= (time_t)t;
@@ -1203,9 +1203,9 @@ class Time_zone_db : public Time_zone
{
public:
Time_zone_db(TIME_ZONE_INFO *tz_info_arg, const String * tz_name_arg);
- virtual my_time_t TIME_to_gmt_sec(const TIME *t,
+ virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
my_bool *in_dst_time_gap) const;
- virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const;
+ virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
virtual const String * get_name() const;
private:
TIME_ZONE_INFO *tz_info;
@@ -1239,7 +1239,7 @@ Time_zone_db::Time_zone_db(TIME_ZONE_INFO *tz_info_arg,
SYNOPSIS
TIME_to_gmt_sec()
- t - pointer to TIME structure with local time
+ t - pointer to MYSQL_TIME structure with local time
in broken-down representation.
in_dst_time_gap - pointer to bool which is set to true if datetime
value passed doesn't really exist (i.e. falls into
@@ -1253,7 +1253,7 @@ Time_zone_db::Time_zone_db(TIME_ZONE_INFO *tz_info_arg,
Corresponding my_time_t value or 0 in case of error
*/
my_time_t
-Time_zone_db::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
+Time_zone_db::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
{
return ::TIME_to_gmt_sec(t, tz_info, in_dst_time_gap);
}
@@ -1265,11 +1265,11 @@ Time_zone_db::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
SYNOPSIS
gmt_sec_to_TIME()
- tmp - pointer to TIME structure to fill-in
+ tmp - pointer to MYSQL_TIME structure to fill-in
t - my_time_t value to be converted
*/
void
-Time_zone_db::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const
+Time_zone_db::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
{
::gmt_sec_to_TIME(tmp, t, tz_info);
}
@@ -1299,9 +1299,9 @@ class Time_zone_offset : public Time_zone
{
public:
Time_zone_offset(long tz_offset_arg);
- virtual my_time_t TIME_to_gmt_sec(const TIME *t,
+ virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
my_bool *in_dst_time_gap) const;
- virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const;
+ virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
virtual const String * get_name() const;
/*
This have to be public because we want to be able to access it from
@@ -1336,11 +1336,11 @@ Time_zone_offset::Time_zone_offset(long tz_offset_arg):
/*
Converts local time in time zone described as offset from UTC
- from TIME representation to its my_time_t representation.
+ from MYSQL_TIME representation to its my_time_t representation.
SYNOPSIS
TIME_to_gmt_sec()
- t - pointer to TIME structure with local time
+ t - pointer to MYSQL_TIME structure with local time
in broken-down representation.
in_dst_time_gap - pointer to bool which should be set to true if
datetime value passed doesn't really exist
@@ -1352,7 +1352,7 @@ Time_zone_offset::Time_zone_offset(long tz_offset_arg):
Corresponding my_time_t value or 0 in case of error
*/
my_time_t
-Time_zone_offset::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
+Time_zone_offset::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
{
my_time_t local_t;
int shift= 0;
@@ -1397,11 +1397,11 @@ Time_zone_offset::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const
SYNOPSIS
gmt_sec_to_TIME()
- tmp - pointer to TIME structure to fill-in
+ tmp - pointer to MYSQL_TIME structure to fill-in
t - my_time_t value to be converted
*/
void
-Time_zone_offset::gmt_sec_to_TIME(TIME *tmp, my_time_t t) const
+Time_zone_offset::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
{
sec_to_TIME(tmp, t, offset);
}
@@ -2564,7 +2564,7 @@ main(int argc, char **argv)
my_bool localtime_negative;
TIME_ZONE_INFO tz_info;
struct tm tmp;
- TIME time_tmp;
+ MYSQL_TIME time_tmp;
time_t t, t1, t2;
char fullname[FN_REFLEN+1];
char *str_end;
diff --git a/sql/tztime.h b/sql/tztime.h
index b6af4b37468..f7cc7042d79 100644
--- a/sql/tztime.h
+++ b/sql/tztime.h
@@ -22,7 +22,7 @@
/*
This class represents abstract time zone and provides
- basic interface for TIME <-> my_time_t conversion.
+ basic interface for MYSQL_TIME <-> my_time_t conversion.
Actual time zones which are specified by DB, or via offset
or use system functions are its descendants.
*/
@@ -31,18 +31,18 @@ class Time_zone: public Sql_alloc
public:
Time_zone() {} /* Remove gcc warning */
/*
- Converts local time in broken down TIME representation to
+ Converts local time in broken down MYSQL_TIME representation to
my_time_t (UTC seconds since Epoch) represenation.
Returns 0 in case of error. Sets in_dst_time_gap to true if date provided
falls into spring time-gap (or lefts it untouched otherwise).
*/
- virtual my_time_t TIME_to_gmt_sec(const TIME *t,
+ virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
my_bool *in_dst_time_gap) const = 0;
/*
Converts time in my_time_t representation to local time in
- broken down TIME representation.
+ broken down MYSQL_TIME representation.
*/
- virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const = 0;
+ virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const = 0;
/*
Because of constness of String returned by get_name() time zone name
have to be already zeroended to be able to use String::ptr() instead
@@ -62,7 +62,7 @@ extern Time_zone * my_tz_SYSTEM;
extern Time_zone * my_tz_find(THD *thd, const String *name);
extern my_bool my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap);
extern void my_tz_free();
-extern my_time_t sec_since_epoch_TIME(TIME *t);
+extern my_time_t sec_since_epoch_TIME(MYSQL_TIME *t);
/*
Number of elements in table list produced by my_tz_get_table_list()
diff --git a/sql/unireg.cc b/sql/unireg.cc
index d90420313a6..a69a9be6a43 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -936,7 +936,9 @@ static bool make_empty_rec(THD *thd, File file,enum legacy_db_type table_type,
(regfield->real_type() != MYSQL_TYPE_YEAR ||
field->def->val_int() != 0))
{
- if (field->def->save_in_field(regfield, 1))
+ int res= field->def->save_in_field(regfield, 1);
+ /* If not ok or warning of level 'note' */
+ if (res != 0 && res != 3)
{
my_error(ER_INVALID_DEFAULT, MYF(0), regfield->field_name);
error= 1;