summaryrefslogtreecommitdiff
path: root/sql/item_create.cc
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2011-05-28 05:11:32 +0300
committerMichael Widenius <monty@askmonty.org>2011-05-28 05:11:32 +0300
commitf197991f4102ed8ac66b7b57071f24f1d3b86aea (patch)
treeb4590b80e7d50b664d8e6ff6a62978cb2402f0a6 /sql/item_create.cc
parentde44b51e151a00a00d0e396dc57ced3682d24d78 (diff)
parent306ed65302e14f303fdc33cfa9d19016fb319440 (diff)
downloadmariadb-git-f197991f4102ed8ac66b7b57071f24f1d3b86aea.tar.gz
Merge with 5.1-microseconds
A lot of small fixes and new test cases. client/mysqlbinlog.cc: Cast removed client/mysqltest.cc: Added missing DBUG_RETURN include/my_pthread.h: set_timespec_time_nsec() now only takes one argument mysql-test/t/date_formats.test: Remove --disable_ps_protocl as now also ps supports microseconds mysys/my_uuid.c: Changed to use my_interval_timer() instead of my_getsystime() mysys/waiting_threads.c: Changed to use my_hrtime() sql/field.h: Added bool special_const_compare() for fields that may convert values before compare (like year) sql/field_conv.cc: Added test to get optimal copying of identical temporal values. sql/item.cc: Return that item_int is equal if it's positive, even if unsigned flag is different. Fixed Item_cache_str::save_in_field() to have identical null check as other similar functions Added proper NULL check to Item_cache_int::save_in_field() sql/item_cmpfunc.cc: Don't call convert_constant_item() if there is nothing that is worth converting. Simplified test when years should be converted sql/item_sum.cc: Mark cache values in Item_sum_hybrid as not constants to ensure they are not replaced by other cache values in compare_datetime() sql/item_timefunc.cc: Changed sec_to_time() to take a my_decimal argument to ensure we don't loose any sub seconds. Added Item_temporal_func::get_time() (This simplifies some things) sql/mysql_priv.h: Added Lazy_string_decimal() sql/mysqld.cc: Added my_decimal constants max_seconds_for_time_type, time_second_part_factor sql/table.cc: Changed expr_arena to be of type CONVENTIONAL_EXECUTION to ensure that we don't loose any items that are created by fix_fields() sql/tztime.cc: TIME_to_gmt_sec() now sets *in_dst_time_gap in case of errors This is needed to be able to detect if timestamp is 0 storage/maria/lockman.c: Changed from my_getsystime() to set_timespec_time_nsec() storage/maria/ma_loghandler.c: Changed from my_getsystime() to my_hrtime() storage/maria/ma_recovery.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/maria/unittest/trnman-t.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/xtradb/handler/ha_innodb.cc: Added support for new time,datetime and timestamp unittest/mysys/thr_template.c: my_getsystime() -> my_interval_timer() unittest/mysys/waiting_threads-t.c: my_getsystime() -> my_interval_timer()
Diffstat (limited to 'sql/item_create.cc')
-rw-r--r--sql/item_create.cc55
1 files changed, 44 insertions, 11 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 9c66c94382d..519599bbde0 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -31,7 +31,28 @@
=============================================================================
*/
-/*
+static const char* item_name(Item *a, String *str)
+{
+ if (a->name)
+ return a->name;
+ str->length(0);
+ a->print(str, QT_ORDINARY);
+ return str->c_ptr_safe();
+}
+
+
+static void wrong_precision_error(uint errcode, Item *a,
+ ulonglong number, ulong maximum)
+{
+ char buff[1024];
+ String buf(buff, sizeof(buff), system_charset_info);
+
+ my_error(errcode, MYF(0), (uint) min(number, UINT_MAX32),
+ item_name(a, &buf), maximum);
+}
+
+
+/**
Get precision and scale for a declaration
return
@@ -42,18 +63,16 @@
bool get_length_and_scale(ulonglong length, ulonglong decimals,
ulong *out_length, uint *out_decimals,
uint max_precision, uint max_scale,
- const char *name)
+ Item *a)
{
if (length > (ulonglong) max_precision)
{
- my_error(ER_TOO_BIG_PRECISION, MYF(0), (int) length, name,
- max_precision);
+ wrong_precision_error(ER_TOO_BIG_PRECISION, a, length, max_precision);
return 1;
}
if (decimals > (ulonglong) max_scale)
{
- my_error(ER_TOO_BIG_SCALE, MYF(0), (int) decimals, name,
- DECIMAL_MAX_SCALE);
+ wrong_precision_error(ER_TOO_BIG_SCALE, a, decimals, max_scale);
return 1;
}
@@ -5124,10 +5143,22 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type,
res= new (thd->mem_root) Item_date_typecast(a);
break;
case ITEM_CAST_TIME:
- res= new (thd->mem_root) Item_time_typecast(a);
+ if (decimals > MAX_DATETIME_PRECISION)
+ {
+ wrong_precision_error(ER_TOO_BIG_PRECISION, a, decimals,
+ MAX_DATETIME_PRECISION);
+ return 0;
+ }
+ res= new (thd->mem_root) Item_time_typecast(a, (uint) decimals);
break;
case ITEM_CAST_DATETIME:
- res= new (thd->mem_root) Item_datetime_typecast(a);
+ if (decimals > MAX_DATETIME_PRECISION)
+ {
+ wrong_precision_error(ER_TOO_BIG_PRECISION, a, decimals,
+ MAX_DATETIME_PRECISION);
+ return 0;
+ }
+ res= new (thd->mem_root) Item_datetime_typecast(a, (uint) decimals);
break;
case ITEM_CAST_DECIMAL:
{
@@ -5135,7 +5166,7 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type,
uint dec;
if (get_length_and_scale(length, decimals, &len, &dec,
DECIMAL_MAX_PRECISION, DECIMAL_MAX_SCALE,
- a->name))
+ a))
return NULL;
res= new (thd->mem_root) Item_decimal_typecast(a, len, dec);
break;
@@ -5152,7 +5183,7 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type,
}
else if (get_length_and_scale(length, decimals, &len, &dec,
DECIMAL_MAX_PRECISION, NOT_FIXED_DEC-1,
- a->name))
+ a))
return NULL;
res= new (thd->mem_root) Item_double_typecast(a, (uint) length,
(uint) decimals);
@@ -5166,7 +5197,9 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type,
{
if (length > MAX_FIELD_BLOBLENGTH)
{
- my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), "cast as char",
+ char buff[1024];
+ String buf(buff, sizeof(buff), system_charset_info);
+ my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), item_name(a, &buf),
MAX_FIELD_BLOBLENGTH);
return NULL;
}