summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/field.h12
-rw-r--r--sql/item.h6
-rw-r--r--sql/item_func.h15
-rw-r--r--sql/item_strfunc.h5
-rw-r--r--sql/item_timefunc.h21
-rw-r--r--sql/sql_table.cc7
6 files changed, 61 insertions, 5 deletions
diff --git a/sql/field.h b/sql/field.h
index 861f2629550..a9b257f0c3a 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -593,6 +593,10 @@ public:
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, table_arg)
{}
+ Field_date(bool maybe_null_arg, const char *field_name_arg,
+ struct st_table *table_arg)
+ :Field_str((char*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
+ NONE, field_name_arg, table_arg) {}
enum_field_types type() const { return FIELD_TYPE_DATE;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
enum Item_result cmp_type () const { return INT_RESULT; }
@@ -650,6 +654,10 @@ public:
:Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, table_arg)
{}
+ Field_time(bool maybe_null_arg, const char *field_name_arg,
+ struct st_table *table_arg)
+ :Field_str((char*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
+ NONE, field_name_arg, table_arg) {}
enum_field_types type() const { return FIELD_TYPE_TIME;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
enum Item_result cmp_type () const { return INT_RESULT; }
@@ -678,6 +686,10 @@ public:
:Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, table_arg)
{}
+ Field_datetime(bool maybe_null_arg, const char *field_name_arg,
+ struct st_table *table_arg)
+ :Field_str((char*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
+ NONE, field_name_arg, table_arg) {}
enum_field_types type() const { return FIELD_TYPE_DATETIME;}
#ifdef HAVE_LONG_LONG
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
diff --git a/sql/item.h b/sql/item.h
index cd752710523..5028f25c6b8 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -64,7 +64,7 @@ public:
virtual longlong val_int()=0;
virtual String *val_str(String*)=0;
virtual void make_field(Send_field *field)=0;
- virtual Field *tmp_table_field() { return 0; }
+ virtual Field *tmp_table_field(TABLE *t_arg=(TABLE *)0) { return 0; }
virtual const char *full_name() const { return name ? name : "???"; }
virtual double val_result() { return val(); }
virtual longlong val_int_result() { return val_int(); }
@@ -128,7 +128,7 @@ public:
{
return field->result_type();
}
- Field *tmp_table_field() { return result_field; }
+ Field *tmp_table_field(TABLE *t_arg=(TABLE *)0) { return result_field; }
bool get_date(TIME *ltime,bool fuzzydate);
bool get_time(TIME *ltime);
bool is_null() { return field->is_null(); }
@@ -308,7 +308,7 @@ public:
Field *result_field; /* Save result here */
Item_result_field() :result_field(0) {}
~Item_result_field() {} /* Required with gcc 2.95 */
- Field *tmp_table_field() { return result_field; }
+ Field *tmp_table_field(TABLE *t_arg=(TABLE *)0) { return result_field; }
table_map used_tables() const { return 1; }
virtual void fix_length_and_dec()=0;
};
diff --git a/sql/item_func.h b/sql/item_func.h
index 23cdf7082cf..d944ef6bc36 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -135,6 +135,11 @@ public:
longlong val_int() { return (longlong) val(); }
enum Item_result result_type () const { return REAL_RESULT; }
void fix_length_and_dec() { decimals=NOT_FIXED_DEC; max_length=float_length(decimals); }
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return new Field_double(max_length, maybe_null, name,t_arg,decimals);
+ }
};
class Item_num_func :public Item_func
@@ -164,6 +169,11 @@ class Item_num_op :public Item_func
void fix_length_and_dec() { fix_num_length_and_dec(); find_num_type(); }
void find_num_type(void);
bool is_null() { (void) val(); return null_value; }
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return args[0]->result_type() == INT_RESULT ? ((max_length > 11) ? (Field *)new Field_longlong(max_length,maybe_null,name, t_arg,unsigned_flag) : (Field *)new Field_long(max_length,maybe_null,name, t_arg,unsigned_flag)) : (Field *) new Field_double(max_length, maybe_null, name,t_arg,decimals);
+ }
};
@@ -179,6 +189,11 @@ public:
String *val_str(String*str);
enum Item_result result_type () const { return INT_RESULT; }
void fix_length_and_dec() { decimals=0; max_length=21; }
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return (max_length > 11) ? (Field *)new Field_longlong(max_length,maybe_null,name, t_arg,unsigned_flag) : (Field *)new Field_long(max_length,maybe_null,name, t_arg,unsigned_flag);
+ }
};
class Item_func_plus :public Item_num_op
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index e92dcf806db..870edffeb7e 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -35,6 +35,11 @@ public:
double val();
enum Item_result result_type () const { return STRING_RESULT; }
void left_right_max_length();
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return (max_length > 255) ? (Field *)new Field_blob(max_length,maybe_null, name,t_arg, binary) : (Field *) new Field_string(max_length,maybe_null, name,t_arg, binary);
+ }
};
class Item_func_md5 :public Item_str_func
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index fbf3b7f05e0..0c42adb2bd2 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -233,6 +233,11 @@ public:
{
init_make_field(tmp_field,FIELD_TYPE_DATE);
}
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return new Field_date(maybe_null, name, t_arg);
+ }
};
@@ -246,6 +251,11 @@ public:
{
init_make_field(tmp_field,FIELD_TYPE_DATETIME);
}
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return new Field_datetime(maybe_null, name, t_arg);
+ }
};
@@ -268,6 +278,11 @@ public:
{
init_make_field(tmp_field,FIELD_TYPE_TIME);
}
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return new Field_time(maybe_null, name, t_arg);
+ }
};
@@ -355,6 +370,12 @@ public:
{
init_make_field(tmp_field,FIELD_TYPE_TIME);
}
+ Field *tmp_table_field(TABLE *t_arg)
+ {
+ if (!t_arg) return result_field;
+ return new Field_time(maybe_null, name, t_arg);
+ }
+
};
enum interval_type { INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY,
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 6ded046ccbf..523358b780e 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -704,8 +704,11 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
my_error(ER_WRONG_COLUMN_NAME,MYF(0),item->name);
DBUG_RETURN(0);
}
-
- Field *field=create_tmp_field(thd, &tmp_table, item, item->type(),
+ Field *field;
+ if (item->type() == Item::FUNC_ITEM)
+ field=item->tmp_table_field(&tmp_table);
+ else
+ field=create_tmp_field(thd, &tmp_table, item, item->type(),
(Item_result_field***) 0, &tmp_field,0,0);
if (!field ||
!(cr_field=new create_field(field,(item->type() == Item::FIELD_ITEM ?