summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <holyfoot/hf@deer.(none)>2006-11-17 19:01:35 +0400
committerunknown <holyfoot/hf@deer.(none)>2006-11-17 19:01:35 +0400
commit092b8f9e9e3aee7af19158fc9eaf3402d9f3ca4e (patch)
tree584324c076d2a4506331c1fb96cf95d2c50a85e3 /sql/item.cc
parent45989298eef744019474f830b874a704071810a3 (diff)
parentbbc5d13891e09447d399112dfa9fa1b9da929b64 (diff)
downloadmariadb-git-092b8f9e9e3aee7af19158fc9eaf3402d9f3ca4e.tar.gz
Merge bk@192.168.21.1:mysql-5.1-opt
into mysql.com:/home/hf/work/mysql-5.1-mrg BitKeeper/deleted/.del-bdb-deadlock.test: Auto merged Makefile.am: Auto merged include/mysql.h: Auto merged libmysqld/lib_sql.cc: Auto merged mysql-test/include/deadlock.inc: Auto merged mysql-test/r/order_by.result: Auto merged mysql-test/r/subselect.result: Auto merged mysql-test/r/type_newdecimal.result: Auto merged mysql-test/t/disabled.def: Auto merged mysql-test/t/flush.test: Auto merged mysql-test/t/flush_block_commit.test: Auto merged mysql-test/t/innodb-lock.test: Auto merged mysql-test/t/lock_multi.test: Auto merged mysql-test/t/rename.test: Auto merged mysql-test/t/show_check.test: Auto merged mysql-test/t/status.test: Auto merged mysql-test/t/subselect.test: Auto merged mysql-test/t/type_newdecimal.test: Auto merged sql/field.cc: Auto merged sql/field.h: Auto merged sql/filesort.cc: Auto merged sql/handler.cc: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_func.cc: Auto merged sql/item_func.h: Auto merged sql/item_subselect.cc: Auto merged sql/item_subselect.h: Auto merged sql/item_sum.cc: Auto merged sql/item_sum.h: Auto merged sql/item_timefunc.cc: Auto merged sql/item_timefunc.h: Auto merged sql/mysql_priv.h: Auto merged sql/sql_base.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_select.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql-common/my_time.c: Auto merged sql/table.cc: Auto merged client/mysqltest.c: merging include/my_time.h: merging libmysql/libmysql.c: merging mysql-test/t/order_by.test: merging sql/sql_yacc.yy: merging
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc79
1 files changed, 74 insertions, 5 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 0d9febdfc11..31d28b00c10 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -269,6 +269,34 @@ 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;
+ longlong date;
+ if (get_date(&ltime, TIME_FUZZY_DATE))
+ {
+ my_decimal_set_zero(decimal_value);
+ return 0;
+ }
+ return date2my_decimal(&ltime, decimal_value);
+}
+
+
+my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
+{
+ DBUG_ASSERT(fixed == 1);
+ TIME ltime;
+ longlong date;
+ if (get_time(&ltime))
+ {
+ my_decimal_set_zero(decimal_value);
+ return 0;
+ }
+ return date2my_decimal(&ltime, decimal_value);
+}
+
+
double Item::val_real_from_decimal()
{
/* Note that fix_fields may not be called for Item_avg_field items */
@@ -292,6 +320,25 @@ longlong Item::val_int_from_decimal()
return result;
}
+int Item::save_time_in_field(Field *field)
+{
+ TIME ltime;
+ if (get_time(&ltime))
+ return set_field_to_null(field);
+ field->set_notnull();
+ return field->store_time(&ltime, MYSQL_TIMESTAMP_TIME);
+}
+
+
+int Item::save_date_in_field(Field *field)
+{
+ TIME ltime;
+ if (get_date(&ltime, TIME_FUZZY_DATE))
+ return set_field_to_null(field);
+ field->set_notnull();
+ return field->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
+}
+
Item::Item():
rsize(0), name(0), orig_name(0), name_length(0), fixed(0),
@@ -1176,6 +1223,28 @@ void Item_name_const::print(String *str)
/*
+ need a special class to adjust printing : references to aggregate functions
+ must not be printed as refs because the aggregate functions that are added to
+ the front of select list are not printed as well.
+*/
+class Item_aggregate_ref : public Item_ref
+{
+public:
+ Item_aggregate_ref(Name_resolution_context *context_arg, Item **item,
+ const char *table_name_arg, const char *field_name_arg)
+ :Item_ref(context_arg, item, table_name_arg, field_name_arg) {}
+
+ void print (String *str)
+ {
+ if (ref)
+ (*ref)->print(str);
+ else
+ Item_ident::print(str);
+ }
+};
+
+
+/*
Move SUM items out from item tree and replace with reference
SYNOPSIS
@@ -1228,8 +1297,8 @@ void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
Item *new_item, *real_itm= real_item();
ref_pointer_array[el]= real_itm;
- if (!(new_item= new Item_ref(&thd->lex->current_select->context,
- ref_pointer_array + el, 0, name)))
+ if (!(new_item= new Item_aggregate_ref(&thd->lex->current_select->context,
+ ref_pointer_array + el, 0, name)))
return; // fatal_error is set
fields.push_front(real_itm);
thd->change_item_tree(ref, new_item);
@@ -3692,16 +3761,16 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
Item_ref to point to the Item in the select list and replace the
Item_field created by the parser with the new Item_ref.
*/
- Item_ref *rf= new Item_ref(db_name,table_name,field_name);
+ Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
if (!rf)
return 1;
- thd->change_item_tree(ref, rf);
+ thd->change_item_tree(reference, rf);
/*
Because Item_ref never substitutes itself with other items
in Item_ref::fix_fields(), we can safely use the original
pointer to it even after fix_fields()
*/
- return rf->fix_fields(thd, tables, ref) || rf->check_cols(1);
+ return rf->fix_fields(thd, reference) || rf->check_cols(1);
}
}
}