Commit 5abb148d authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

items for functions which is converted to constants internally to support its...

items for functions which is converted to constants internally to support its correct printing added (BUG#4663)
parent 393e41fe
...@@ -1053,3 +1053,8 @@ create index i1 on v1 (col1); ...@@ -1053,3 +1053,8 @@ create index i1 on v1 (col1);
ERROR HY000: 'test.v1' is not BASIC TABLE ERROR HY000: 'test.v1' is not BASIC TABLE
drop view v1; drop view v1;
drop table t1; drop table t1;
CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version();
SHOW CREATE VIEW v1;
Table Create Table
v1 CREATE VIEW test.v1 AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4`
drop view v1;
...@@ -997,3 +997,10 @@ create view v1 as select * from t1; ...@@ -997,3 +997,10 @@ create view v1 as select * from t1;
create index i1 on v1 (col1); create index i1 on v1 (col1);
drop view v1; drop view v1;
drop table t1; drop table t1;
#
# connection_id(), pi(), current_user(), version() representation test
#
CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version();
SHOW CREATE VIEW v1;
drop view v1;
...@@ -669,6 +669,17 @@ class Item_int :public Item_num ...@@ -669,6 +669,17 @@ class Item_int :public Item_num
}; };
class Item_static_int_func :public Item_int
{
const char *func_name;
public:
Item_static_int_func(const char *str_arg, longlong i, uint length)
:Item_int(NullS, i, length), func_name(str_arg)
{}
void print(String *str) { str->append(func_name); }
};
class Item_uint :public Item_int class Item_uint :public Item_int
{ {
public: public:
...@@ -724,6 +735,18 @@ class Item_real :public Item_num ...@@ -724,6 +735,18 @@ class Item_real :public Item_num
}; };
class Item_static_real_func :public Item_real
{
const char *func_name;
public:
Item_static_real_func(const char *str, double val_arg, uint decimal_par,
uint length)
:Item_real(NullS, val_arg, decimal_par, length), func_name(str)
{}
void print(String *str) { str->append(func_name); }
};
class Item_float :public Item_real class Item_float :public Item_real
{ {
public: public:
...@@ -803,6 +826,20 @@ class Item_string :public Item ...@@ -803,6 +826,20 @@ class Item_string :public Item
void cleanup() {} void cleanup() {}
}; };
class Item_static_string_func :public Item_string
{
const char *func_name;
public:
Item_static_string_func(const char *name_par, const char *str, uint length,
CHARSET_INFO *cs,
Derivation dv= DERIVATION_COERCIBLE)
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
{}
void print(String *str) { str->append(func_name); }
};
/* for show tables */ /* for show tables */
class Item_datetime :public Item_string class Item_datetime :public Item_string
......
...@@ -73,12 +73,13 @@ Item *create_func_connection_id(void) ...@@ -73,12 +73,13 @@ Item *create_func_connection_id(void)
{ {
THD *thd=current_thd; THD *thd=current_thd;
thd->lex->safe_to_cache_query= 0; thd->lex->safe_to_cache_query= 0;
return new Item_int(NullS,(longlong) return new Item_static_int_func("connection_id()",
((thd->slave_thread) ? (longlong)
thd->variables.pseudo_thread_id : ((thd->slave_thread) ?
thd->thread_id), thd->variables.pseudo_thread_id :
10); thd->thread_id),
} 10);
}
Item *create_func_conv(Item* a, Item *b, Item *c) Item *create_func_conv(Item* a, Item *b, Item *c)
{ {
...@@ -293,7 +294,7 @@ Item *create_func_period_diff(Item* a, Item *b) ...@@ -293,7 +294,7 @@ Item *create_func_period_diff(Item* a, Item *b)
Item *create_func_pi(void) Item *create_func_pi(void)
{ {
return new Item_real("pi()",M_PI,6,8); return new Item_static_real_func("pi()", M_PI, 6, 8);
} }
Item *create_func_pow(Item* a, Item *b) Item *create_func_pow(Item* a, Item *b)
...@@ -309,8 +310,9 @@ Item *create_func_current_user() ...@@ -309,8 +310,9 @@ Item *create_func_current_user()
length= (uint) (strxmov(buff, thd->priv_user, "@", thd->priv_host, NullS) - length= (uint) (strxmov(buff, thd->priv_user, "@", thd->priv_host, NullS) -
buff); buff);
return new Item_string(NullS, thd->memdup(buff, length), length, return new Item_static_string_func("current_user()",
system_charset_info); thd->memdup(buff, length), length,
system_charset_info);
} }
Item *create_func_radians(Item *a) Item *create_func_radians(Item *a)
...@@ -434,7 +436,7 @@ Item *create_func_uuid(void) ...@@ -434,7 +436,7 @@ Item *create_func_uuid(void)
Item *create_func_version(void) Item *create_func_version(void)
{ {
return new Item_string(NullS,server_version, return new Item_static_string_func("version()", server_version,
(uint) strlen(server_version), (uint) strlen(server_version),
system_charset_info, DERIVATION_IMPLICIT); system_charset_info, DERIVATION_IMPLICIT);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment