Commit c688b7b8 authored by unknown's avatar unknown

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)


mysql-test/r/view.result:
  test of functions in VIEW which is converted to constants internally
mysql-test/t/view.test:
  test of functions in VIEW which is converted to constants internally
sql/item.h:
  items for functions which is converted to constants internally to support its correct printing
sql/item_create.cc:
  items for functions which is converted to constants internally to support its correct printing
parent 46a0c8a7
...@@ -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 @@ public: ...@@ -669,6 +669,17 @@ public:
}; };
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 @@ public: ...@@ -724,6 +735,18 @@ public:
}; };
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 @@ public: ...@@ -803,6 +826,20 @@ public:
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,7 +73,8 @@ Item *create_func_connection_id(void) ...@@ -73,7 +73,8 @@ 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()",
(longlong)
((thd->slave_thread) ? ((thd->slave_thread) ?
thd->variables.pseudo_thread_id : thd->variables.pseudo_thread_id :
thd->thread_id), thd->thread_id),
...@@ -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,7 +310,8 @@ Item *create_func_current_user() ...@@ -309,7 +310,8 @@ 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()",
thd->memdup(buff, length), length,
system_charset_info); system_charset_info);
} }
...@@ -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