summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <msvensson@pilot.blaudden>2007-04-02 10:50:39 +0200
committerunknown <msvensson@pilot.blaudden>2007-04-02 10:50:39 +0200
commit3378a48698a311403651fe9bb83d1dfe80a98d78 (patch)
treeda9c4b945967d94e3b16c2fd56a52699aba69b66 /sql
parentf249185b6eead7796f15f880a896a7782222db99 (diff)
parent44d4940fcc001a6606c63e8900d9e2bf41ea4e67 (diff)
downloadmariadb-git-3378a48698a311403651fe9bb83d1dfe80a98d78.tar.gz
Merge pilot.blaudden:/home/msvensson/mysql/mysql-5.0
into pilot.blaudden:/home/msvensson/mysql/mysql-5.0-maint mysql-test/mysql-test-run.pl: Auto merged mysql-test/r/create.result: Auto merged mysql-test/r/type_datetime.result: Auto merged sql/field.h: Auto merged sql/item.h: Auto merged sql/item_func.cc: Auto merged sql/item_strfunc.cc: Auto merged sql/item_sum.cc: Auto merged sql/sql_yacc.yy: Auto merged mysql-test/r/gis.result: SCCS merged mysql-test/t/gis.test: SCCS merged
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc363
-rw-r--r--sql/field.h7
-rw-r--r--sql/ha_innodb.cc9
-rw-r--r--sql/item.h11
-rw-r--r--sql/item_func.cc9
-rw-r--r--sql/item_strfunc.cc2
-rw-r--r--sql/item_sum.cc32
-rw-r--r--sql/log.cc96
-rw-r--r--sql/log_event.cc27
-rw-r--r--sql/sp.cc2
-rw-r--r--sql/sp_head.h6
-rw-r--r--sql/spatial.h43
-rw-r--r--sql/sql_show.cc9
-rw-r--r--sql/sql_yacc.yy11
14 files changed, 292 insertions, 335 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 152c1bdc364..f80bf12db92 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -964,6 +964,31 @@ static Item_result field_types_result_type [FIELDTYPE_NUM]=
/*
+ Test if the given string contains important data:
+ not spaces for character string,
+ or any data for binary string.
+
+ SYNOPSIS
+ test_if_important_data()
+ cs Character set
+ str String to test
+ strend String end
+
+ RETURN
+ FALSE - If string does not have important data
+ TRUE - If string has some important data
+*/
+
+static bool
+test_if_important_data(CHARSET_INFO *cs, const char *str, const char *strend)
+{
+ if (cs != &my_charset_bin)
+ str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
+ return (str < strend);
+}
+
+
+/*
Detect Item_result by given field type of UNION merge result
SYNOPSIS
@@ -1052,64 +1077,113 @@ void Field_num::prepend_zeros(String *value)
}
/*
- Test if given number is a int (or a fixed format float with .000)
+ Test if given number is a int.
SYNOPSIS
- test_if_int()
+ Field_num::check_int
+ cs Character set
str String to test
end Pointer to char after last used digit
- cs Character set
+ length String length
+ error Error returned by strntoull10rnd()
- NOTES
- This is called after one has called my_strntol() or similar function.
- This is only used to give warnings in ALTER TABLE or LOAD DATA...
-
- TODO
- Make this multi-byte-character safe
+ NOTE
+ This is called after one has called strntoull10rnd() function.
RETURN
- 0 OK
- 1 error. A warning is pushed if field_name != 0
+ 0 ok
+ 1 error: empty string or wrong integer.
+ 2 error: garbage at the end of string.
*/
-bool Field::check_int(const char *str, int length, const char *int_end,
- CHARSET_INFO *cs)
+int Field_num::check_int(CHARSET_INFO *cs, const char *str, int length,
+ const char *int_end, int error)
{
- const char *end;
- if (str == int_end)
+ /* Test if we get an empty string or wrong integer */
+ if (str == int_end || error == MY_ERRNO_EDOM)
{
char buff[128];
- String tmp(buff,(uint32) sizeof(buff), system_charset_info);
+ String tmp(buff, (uint32) sizeof(buff), system_charset_info);
tmp.copy(str, length, system_charset_info);
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
"integer", tmp.c_ptr(), field_name,
(ulong) table->in_use->row_count);
- return 1; // Empty string
+ return 1;
}
- end= str+length;
- if ((str= int_end) == end)
- return 0; // OK; All digits was used
+ /* Test if we have garbage at the end of the given string. */
+ if (test_if_important_data(cs, int_end, str + length))
+ {
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
+ return 2;
+ }
+ return 0;
+}
- /* Allow end .0000 */
- if (*str == '.')
+
+/*
+ Conver a string to an integer then check bounds.
+
+ SYNOPSIS
+ Field_num::get_int
+ cs Character set
+ from String to convert
+ len Length of the string
+ rnd OUT longlong value
+ unsigned_max max unsigned value
+ signed_min min signed value
+ signed_max max signed value
+
+ DESCRIPTION
+ The function calls strntoull10rnd() to get an integer value then
+ check bounds and errors returned. In case of any error a warning
+ is raised.
+
+ RETURN
+ 0 ok
+ 1 error
+*/
+
+bool Field_num::get_int(CHARSET_INFO *cs, const char *from, uint len,
+ longlong *rnd, ulonglong unsigned_max,
+ longlong signed_min, longlong signed_max)
+{
+ char *end;
+ int error;
+
+ *rnd= (longlong) cs->cset->strntoull10rnd(cs, from, len, unsigned_flag, &end,
+ &error);
+ if (unsigned_flag)
{
- for (str++ ; str != end && *str == '0'; str++)
- ;
+
+ if (((ulonglong) *rnd > unsigned_max) && (*rnd= (longlong) unsigned_max) ||
+ error == MY_ERRNO_ERANGE)
+ {
+ goto out_of_range;
+ }
}
- /* Allow end space */
- for ( ; str != end ; str++)
+ else
{
- if (!my_isspace(cs,*str))
+ if (*rnd < signed_min)
{
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
- return 1;
+ *rnd= signed_min;
+ goto out_of_range;
+ }
+ else if (*rnd > signed_max)
+ {
+ *rnd= signed_max;
+ goto out_of_range;
}
}
+ if (table->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
+ return 1;
return 0;
-}
+out_of_range:
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+ return 1;
+}
/*
Process decimal library return codes and issue warnings for overflow and
@@ -2506,45 +2580,11 @@ void Field_new_decimal::sql_type(String &str) const
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
{
- char *end;
int error;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > 255)
- {
- set_if_smaller(tmp, 255);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- ptr[0]= (char) tmp;
- }
- else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < -128)
- {
- tmp= -128;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp >= 128)
- {
- tmp= 127;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- ptr[0]= (char) tmp;
- }
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, 255, -128, 127);
+ ptr[0]= unsigned_flag ? (char) (ulonglong) rnd : (char) rnd;
return error;
}
@@ -2709,59 +2749,20 @@ void Field_tiny::sql_type(String &res) const
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
{
- char *end;
+ int store_tmp;
int error;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > UINT_MAX16)
- {
- set_if_smaller(tmp, UINT_MAX16);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, UINT_MAX16, INT_MIN16, INT_MAX16);
+ store_tmp= unsigned_flag ? (int) (ulonglong) rnd : (int) rnd;
#ifdef WORDS_BIGENDIAN
- if (table->s->db_low_byte_first)
- {
- int2store(ptr,tmp);
- }
- else
-#endif
- shortstore(ptr,(short) tmp);
+ if (table->s->db_low_byte_first)
+ {
+ int2store(ptr, store_tmp);
}
else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < INT_MIN16)
- {
- tmp= INT_MIN16;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > INT_MAX16)
- {
- tmp=INT_MAX16;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
-#ifdef WORDS_BIGENDIAN
- if (table->s->db_low_byte_first)
- {
- int2store(ptr,tmp);
- }
- else
#endif
- shortstore(ptr,(short) tmp);
- }
+ shortstore(ptr, (short) store_tmp);
return error;
}
@@ -2989,45 +2990,13 @@ void Field_short::sql_type(String &res) const
int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
{
- char *end;
+ int store_tmp;
int error;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > UINT_MAX24)
- {
- set_if_smaller(tmp, UINT_MAX24);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- int3store(ptr,tmp);
- }
- else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < INT_MIN24)
- {
- tmp= INT_MIN24;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > INT_MAX24)
- {
- tmp=INT_MAX24;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- int3store(ptr,tmp);
- }
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, UINT_MAX24, INT_MIN24, INT_MAX24);
+ store_tmp= unsigned_flag ? (int) (ulonglong) rnd : (int) rnd;
+ int3store(ptr, store_tmp);
return error;
}
@@ -3206,45 +3175,10 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
{
long store_tmp;
int error;
- char *end;
-
- if (unsigned_flag)
- {
- ulonglong tmp= cs->cset->strntoull10rnd(cs, from, len, 1, &end, &error);
- if (error == MY_ERRNO_ERANGE || tmp > (ulonglong) UINT_MAX32)
- {
- set_if_smaller(tmp, (ulonglong) UINT_MAX32);
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- store_tmp= (long) tmp;
- }
- else
- {
- longlong tmp= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (tmp < INT_MIN32)
- {
- tmp= INT_MIN32;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (tmp > INT_MAX32)
- {
- tmp=INT_MAX32;
- set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
- error= 1;
- }
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
- error= 1;
- else
- error= 0;
- store_tmp= (long) tmp;
- }
-
+ longlong rnd;
+
+ error= get_int(cs, from, len, &rnd, UINT_MAX32, INT_MIN32, INT_MAX32);
+ store_tmp= unsigned_flag ? (long) (ulonglong) rnd : (long) rnd;
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
@@ -3490,7 +3424,8 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
error= 1;
}
- else if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
+ else if (table->in_use->count_cuted_fields &&
+ check_int(cs, from, len, end, error))
error= 1;
else
error= 0;
@@ -5008,16 +4943,25 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
{
char *end;
int error;
- long nr= my_strntol(cs, from, len, 10, &end, &error);
+ longlong nr= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
- if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155 || error)
+ if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155 ||
+ error == MY_ERRNO_ERANGE)
{
*ptr=0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
return 1;
}
- if (table->in_use->count_cuted_fields && check_int(from,len,end,cs))
+ if (table->in_use->count_cuted_fields &&
+ (error= check_int(cs, from, len, end, error)))
+ {
+ if (error == 1) /* empty or incorrect string */
+ {
+ *ptr= 0;
+ return 1;
+ }
error= 1;
+ }
if (nr != 0 || len != 4)
{
@@ -5907,31 +5851,6 @@ report_data_too_long(Field_str *field)
}
-/*
- Test if the given string contains important data:
- not spaces for character string,
- or any data for binary string.
-
- SYNOPSIS
- test_if_important_data()
- cs Character set
- str String to test
- strend String end
-
- RETURN
- FALSE - If string does not have important data
- TRUE - If string has some important data
-*/
-
-static bool
-test_if_important_data(CHARSET_INFO *cs, const char *str, const char *strend)
-{
- if (cs != &my_charset_bin)
- str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
- return (str < strend);
-}
-
-
/* Copy a string and fill with space */
int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
diff --git a/sql/field.h b/sql/field.h
index e82e90ce5ab..fc68a4549a9 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -306,8 +306,6 @@ public:
virtual void set_derivation(enum Derivation derivation_arg) { }
bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
int cuted_increment);
- bool check_int(const char *str, int length, const char *int_end,
- CHARSET_INFO *cs);
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code,
const char *str, uint str_len,
timestamp_type ts_type, int cuted_increment);
@@ -369,6 +367,11 @@ public:
bool eq_def(Field *field);
int store_decimal(const my_decimal *);
my_decimal *val_decimal(my_decimal *);
+ int check_int(CHARSET_INFO *cs, const char *str, int length,
+ const char *int_end, int error);
+ bool get_int(CHARSET_INFO *cs, const char *from, uint len,
+ longlong *rnd, ulonglong unsigned_max,
+ longlong signed_min, longlong signed_max);
};
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index cbefa9d3949..217f59d4b7e 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -6066,6 +6066,15 @@ ha_innobase::external_lock(
trx->isolation_level = innobase_map_isolation_level(
(enum_tx_isolation)
thd->variables.tx_isolation);
+
+ if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
+ && trx->global_read_view) {
+
+ /* At low transaction isolation levels we let
+ each consistent read set its own snapshot */
+
+ read_view_close_for_mysql(trx);
+ }
}
if (trx->isolation_level == TRX_ISO_SERIALIZABLE
diff --git a/sql/item.h b/sql/item.h
index 7b0d18e19c5..2c4943bea6e 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -694,12 +694,11 @@ public:
virtual bool get_date_result(TIME *ltime,uint fuzzydate)
{ return get_date(ltime,fuzzydate); }
/*
- This function is used only in Item_func_isnull/Item_func_isnotnull
- (implementations of IS NULL/IS NOT NULL clauses). Item_func_is{not}null
- calls this method instead of one of val/result*() methods, which
- normally will set null_value. This allows to determine nullness of
- a complex expression without fully evaluating it.
- Any new item which can be NULL must implement this call.
+ The method allows to determine nullness of a complex expression
+ without fully evaluating it, instead of calling val/result*() then
+ checking null_value. Used in Item_func_isnull/Item_func_isnotnull
+ and Item_sum_count/Item_sum_count_distinct.
+ Any new item which can be NULL must implement this method.
*/
virtual bool is_null() { return 0; }
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 3d92be5e9d2..76f8433ebe3 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -5035,7 +5035,7 @@ Item_func_sp::func_name() const
{
THD *thd= current_thd;
/* Calculate length to avoid reallocation of string for sure */
- uint len= ((m_name->m_db.length +
+ uint len= ((m_name->m_explicit_name ? m_name->m_db.length : 0 +
m_name->m_name.length)*2 + //characters*quoting
2 + // ` and `
1 + // .
@@ -5045,8 +5045,11 @@ Item_func_sp::func_name() const
system_charset_info);
qname.length(0);
- append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length);
- qname.append('.');
+ if (m_name->m_explicit_name)
+ {
+ append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length);
+ qname.append('.');
+ }
append_identifier(thd, &qname, m_name->m_name.str, m_name->m_name.length);
return qname.ptr();
}
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 03887629519..1991526345c 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2319,7 +2319,7 @@ String *Item_func_repeat::val_str(String *str)
goto err; // string and/or delim are null
null_value= 0;
- if (count == 0 || count < 0 && !args[1]->unsigned_flag)
+ if (count <= 0 && (count == 0 || !args[1]->unsigned_flag))
return &my_empty_string;
/* Assumes that the maximum length of a String is < INT_MAX32. */
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 359b4516c3c..752cefa07d6 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1080,14 +1080,8 @@ void Item_sum_count::clear()
bool Item_sum_count::add()
{
- if (!args[0]->maybe_null)
+ if (!args[0]->maybe_null || !args[0]->is_null())
count++;
- else
- {
- args[0]->update_null_value();
- if (!args[0]->null_value)
- count++;
- }
return 0;
}
@@ -1921,14 +1915,8 @@ void Item_sum_count::reset_field()
char *res=result_field->ptr;
longlong nr=0;
- if (!args[0]->maybe_null)
+ if (!args[0]->maybe_null || !args[0]->is_null())
nr=1;
- else
- {
- args[0]->update_null_value();
- if (!args[0]->null_value)
- nr=1;
- }
int8store(res,nr);
}
@@ -2031,14 +2019,8 @@ void Item_sum_count::update_field()
char *res=result_field->ptr;
nr=sint8korr(res);
- if (!args[0]->maybe_null)
+ if (!args[0]->maybe_null || !args[0]->is_null())
nr++;
- else
- {
- args[0]->update_null_value();
- if (!args[0]->null_value)
- nr++;
- }
int8store(res,nr);
}
@@ -2462,12 +2444,8 @@ bool Item_sum_count_distinct::setup(THD *thd)
Item *item=args[i];
if (list.push_back(item))
return TRUE; // End of memory
- if (item->const_item())
- {
- item->update_null_value();
- if (item->null_value)
- always_null=1;
- }
+ if (item->const_item() && item->is_null())
+ always_null= 1;
}
if (always_null)
return FALSE;
diff --git a/sql/log.cc b/sql/log.cc
index 7d0bef5ca2c..c2b4eb1a441 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -283,7 +283,7 @@ err:
#ifdef __NT__
static int eventSource = 0;
-void setup_windows_event_source()
+static void setup_windows_event_source()
{
HKEY hRegKey= NULL;
DWORD dwError= 0;
@@ -2229,37 +2229,6 @@ static bool test_if_number(register const char *str,
} /* test_if_number */
-void print_buffer_to_file(enum loglevel level, const char *buffer)
-{
- time_t skr;
- struct tm tm_tmp;
- struct tm *start;
- DBUG_ENTER("print_buffer_to_file");
- DBUG_PRINT("enter",("buffer: %s", buffer));
-
- VOID(pthread_mutex_lock(&LOCK_error_log));
-
- skr=time(NULL);
- localtime_r(&skr, &tm_tmp);
- start=&tm_tmp;
- fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n",
- start->tm_year % 100,
- start->tm_mon+1,
- start->tm_mday,
- start->tm_hour,
- start->tm_min,
- start->tm_sec,
- (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
- "Warning" : "Note"),
- buffer);
-
- fflush(stderr);
-
- VOID(pthread_mutex_unlock(&LOCK_error_log));
- DBUG_VOID_RETURN;
-}
-
-
void sql_perror(const char *message)
{
#ifdef HAVE_STRERROR
@@ -2326,23 +2295,15 @@ void MYSQL_LOG::signal_update()
}
#ifdef __NT__
-void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
- uint length, int buffLen)
+static void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
+ size_t length, size_t buffLen)
{
HANDLE event;
- char *buffptr;
- LPCSTR *buffmsgptr;
+ char *buffptr= buff;
DBUG_ENTER("print_buffer_to_nt_eventlog");
- buffptr= buff;
- if (length > (uint)(buffLen-5))
- {
- char *newBuff= new char[length + 5];
- strcpy(newBuff, buff);
- buffptr= newBuff;
- }
- strmov(buffptr+length, "\r\n\r\n");
- buffmsgptr= (LPCSTR*) &buffptr; // Keep windows happy
+ /* Add ending CR/LF's to string, overwrite last chars if necessary */
+ strmov(buffptr+min(length, buffLen-5), "\r\n\r\n");
setup_windows_event_source();
if ((event= RegisterEventSource(NULL,"MySQL")))
@@ -2350,24 +2311,20 @@ void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
switch (level) {
case ERROR_LEVEL:
ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
- buffmsgptr, NULL);
+ (LPCSTR*)&buffptr, NULL);
break;
case WARNING_LEVEL:
ReportEvent(event, EVENTLOG_WARNING_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
- buffmsgptr, NULL);
+ (LPCSTR*) &buffptr, NULL);
break;
case INFORMATION_LEVEL:
ReportEvent(event, EVENTLOG_INFORMATION_TYPE, 0, MSG_DEFAULT, NULL, 1,
- 0, buffmsgptr, NULL);
+ 0, (LPCSTR*) &buffptr, NULL);
break;
}
DeregisterEventSource(event);
}
- /* if we created a string buffer, then delete it */
- if (buffptr != buff)
- delete[] buffptr;
-
DBUG_VOID_RETURN;
}
#endif /* __NT__ */
@@ -2399,13 +2356,44 @@ void vprint_msg_to_log(enum loglevel level __attribute__((unused)),
va_list argsi __attribute__((unused)))
{}
#else /*!EMBEDDED_LIBRARY*/
+static void print_buffer_to_file(enum loglevel level, const char *buffer)
+{
+ time_t skr;
+ struct tm tm_tmp;
+ struct tm *start;
+ DBUG_ENTER("print_buffer_to_file");
+ DBUG_PRINT("enter",("buffer: %s", buffer));
+
+ VOID(pthread_mutex_lock(&LOCK_error_log));
+
+ skr=time(NULL);
+ localtime_r(&skr, &tm_tmp);
+ start=&tm_tmp;
+ fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n",
+ start->tm_year % 100,
+ start->tm_mon+1,
+ start->tm_mday,
+ start->tm_hour,
+ start->tm_min,
+ start->tm_sec,
+ (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
+ "Warning" : "Note"),
+ buffer);
+
+ fflush(stderr);
+
+ VOID(pthread_mutex_unlock(&LOCK_error_log));
+ DBUG_VOID_RETURN;
+}
+
+
void vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
{
char buff[1024];
- uint length;
+ size_t length;
DBUG_ENTER("vprint_msg_to_log");
- length= my_vsnprintf(buff, sizeof(buff)-5, format, args);
+ length= my_vsnprintf(buff, sizeof(buff), format, args);
print_buffer_to_file(level, buff);
#ifdef __NT__
diff --git a/sql/log_event.cc b/sql/log_event.cc
index e272140c080..8bb63e72bde 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -669,19 +669,34 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet,
LOG_READ_TOO_LARGE);
goto end;
}
- packet->append(buf, sizeof(buf));
+
+ /* Append the log event header to packet */
+ if (packet->append(buf, sizeof(buf)))
+ {
+ /* Failed to allocate packet */
+ result= LOG_READ_MEM;
+ goto end;
+ }
data_len-= LOG_EVENT_MINIMAL_HEADER_LEN;
if (data_len)
{
+ /* Append rest of event, read directly from file into packet */
if (packet->append(file, data_len))
{
/*
- Here if we hit EOF it's really an error: as data_len is >=0
- there's supposed to be more bytes available.
- EOF means we are reading the event partially, which should
- never happen: either we read badly or the binlog is truncated.
+ Fatal error occured when appending rest of the event
+ to packet, possible failures:
+ 1. EOF occured when reading from file, it's really an error
+ as data_len is >=0 there's supposed to be more bytes available.
+ file->error will have been set to number of bytes left to read
+ 2. Read was interrupted, file->error would normally be set to -1
+ 3. Failed to allocate memory for packet, my_errno
+ will be ENOMEM(file->error shuold be 0, but since the
+ memory allocation occurs before the call to read it might
+ be uninitialized)
*/
- result= file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO;
+ result= (my_errno == ENOMEM ? LOG_READ_MEM :
+ (file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO));
/* Implicit goto end; */
}
}
diff --git a/sql/sp.cc b/sql/sp.cc
index 2bb13b02e14..c8701aa2c87 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -1068,7 +1068,7 @@ sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error)
lex_name.length= strlen(routine->table_name);
lex_db.str= thd->strmake(routine->db, lex_db.length);
lex_name.str= thd->strmake(routine->table_name, lex_name.length);
- name= new sp_name(lex_db, lex_name);
+ name= new sp_name(lex_db, lex_name, true);
name->init_qname(thd);
sp_object_found= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name,
&thd->sp_proc_cache, FALSE) != NULL ||
diff --git a/sql/sp_head.h b/sql/sp_head.h
index 901b7a19c39..cce400d6a14 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -59,9 +59,10 @@ public:
calling set_routine_type().
*/
LEX_STRING m_sroutines_key;
+ bool m_explicit_name; /**< Prepend the db name? */
- sp_name(LEX_STRING db, LEX_STRING name)
- : m_db(db), m_name(name)
+ sp_name(LEX_STRING db, LEX_STRING name, bool use_explicit_name)
+ : m_db(db), m_name(name), m_explicit_name(use_explicit_name)
{
m_qname.str= m_sroutines_key.str= 0;
m_qname.length= m_sroutines_key.length= 0;
@@ -79,6 +80,7 @@ public:
m_name.length= m_qname.length= key_len - 1;
m_db.str= 0;
m_db.length= 0;
+ m_explicit_name= false;
}
// Init. the qualified name from the db and name.
diff --git a/sql/spatial.h b/sql/spatial.h
index 86232fcd524..837ae153310 100644
--- a/sql/spatial.h
+++ b/sql/spatial.h
@@ -144,15 +144,46 @@ struct MBR
return (xmin<x) && (xmax>x) && (ymin<y) && (ymax>y);
}
+ /**
+ The dimension maps to an integer as:
+ - Polygon -> 2
+ - Horizontal or vertical line -> 1
+ - Point -> 0
+ - Invalid MBR -> -1
+ */
+ int dimension() const
+ {
+ int d= 0;
+
+ if (xmin > xmax)
+ return -1;
+ else if (xmin < xmax)
+ d++;
+
+ if (ymin > ymax)
+ return -1;
+ else if (ymin < ymax)
+ d++;
+
+ return d;
+ }
+
int overlaps(const MBR *mbr)
{
- int lb= mbr->inner_point(xmin, ymin);
- int rb= mbr->inner_point(xmax, ymin);
- int rt= mbr->inner_point(xmax, ymax);
- int lt= mbr->inner_point(xmin, ymax);
+ /*
+ overlaps() requires that some point inside *this is also inside
+ *mbr, and that both geometries and their intersection are of the
+ same dimension.
+ */
+ int d = dimension();
+
+ if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr))
+ return 0;
+
+ MBR intersection(max(xmin, mbr->xmin), max(ymin, mbr->ymin),
+ min(xmax, mbr->xmax), min(ymax, mbr->ymax));
- int a = lb+rb+rt+lt;
- return (a>0) && (a<4) && (!within(mbr));
+ return (d == intersection.dimension());
}
};
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 286799a44f6..0c9ea7b0bbf 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -3602,7 +3602,16 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
DBUG_RETURN(0);
}
break;
+ case MYSQL_TYPE_FLOAT:
+ case MYSQL_TYPE_DOUBLE:
+ if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC,
+ fields_info->field_length)) == NULL)
+ DBUG_RETURN(NULL);
+ break;
default:
+ /* Don't let unimplemented types pass through. Could be a grave error. */
+ DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING);
+
/* this should be changed when Item_empty_string is fixed(in 4.1) */
if (!(item= new Item_empty_string("", 0, cs)))
{
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index bbb0d11b942..4a50a602121 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1577,7 +1577,7 @@ sp_name:
my_error(ER_SP_WRONG_NAME, MYF(0), $3.str);
MYSQL_YYABORT;
}
- $$= new sp_name($1, $3);
+ $$= new sp_name($1, $3, true);
$$->init_qname(YYTHD);
}
| ident
@@ -1591,7 +1591,7 @@ sp_name:
}
if (thd->copy_db_to(&db.str, &db.length))
MYSQL_YYABORT;
- $$= new sp_name(db, $1);
+ $$= new sp_name(db, $1, false);
if ($$)
$$->init_qname(YYTHD);
}
@@ -5041,7 +5041,7 @@ simple_expr:
| ident '.' ident '(' opt_expr_list ')'
{
LEX *lex= Lex;
- sp_name *name= new sp_name($1, $3);
+ sp_name *name= new sp_name($1, $3, true);
name->init_qname(YYTHD);
sp_add_used_routine(lex, YYTHD, name, TYPE_ENUM_FUNCTION);
@@ -5156,7 +5156,7 @@ simple_expr:
LEX_STRING db;
if (thd->copy_db_to(&db.str, &db.length))
MYSQL_YYABORT;
- sp_name *name= new sp_name(db, $1);
+ sp_name *name= new sp_name(db, $1, false);
if (name)
name->init_qname(thd);
@@ -9050,7 +9050,8 @@ grant_ident:
| table_ident
{
LEX *lex=Lex;
- if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
+ if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,
+ TL_OPTION_UPDATING))
MYSQL_YYABORT;
if (lex->grant == GLOBAL_ACLS)
lex->grant = TABLE_ACLS & ~GRANT_ACL;