List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:February 22 2008 11:30am
Subject:bk commit into 5.1 tree (anozdrin:1.2567) BUG#30217
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of anozdrin.  When anozdrin does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-22 13:30:33+03:00, anozdrin@quad. +39 -0
  Fix for Bug#30217: Views: changes in metadata behaviour
  between 5.0 and 5.1.
    
  The problem was that in the patch for Bug#11986 it was decided
  to store original query in UTF8 encoding for the INFORMATION_SCHEMA.
  This approach however turned out to be quite difficult to implement
  properly. The main problem is to preserve the same IS-output after
  dump/restore.
    
  So, the fix is to rollback to the previous functionality, but also
  to fix it to support multi-character-set-queries properly. The idea
  is to generate INFORMATION_SCHEMA-query from the item-tree after
  parsing view declaration. The IS-query should:
    - be completely in UTF8;
    - not contain character set introducers.
    
  For more information, see WL4052.

  mysql-test/include/ddl_i18n.check_views.inc@stripped, 2008-02-22 13:30:29+03:00,
anozdrin@quad. +12 -0
    Add a test case for Bug#30217.

  mysql-test/r/ddl_i18n_koi8r.result@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +45 -7
    Update result file.

  mysql-test/r/ddl_i18n_utf8.result@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +45 -7
    Update result file.

  mysql-test/r/information_schema.result@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad.
+10 -15
    Update result file.

  mysql-test/r/information_schema_db.result@stripped, 2008-02-22 13:30:29+03:00,
anozdrin@quad. +1 -1
    Update result file.

  mysql-test/r/mysqldump.result@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +34 -0
    Update result file.

  mysql-test/r/show_check.result@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +2 -2
    Update result file.

  mysql-test/t/ddl_i18n_koi8r.test@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +7 -1
    Add a test case for Bug#30217.

  mysql-test/t/ddl_i18n_utf8.test@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +7 -1
    Add a test case for Bug#30217.

  mysql-test/t/mysqldump.test@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +55 -0
    Add a test case for Bug#30217.

  sql/ha_ndbcluster.cc@stripped, 2008-02-22 13:30:29+03:00, anozdrin@quad. +1 -1
    Add a parameter to print().

  sql/item.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +62 -36
    1. Add a parameter to print().
    2. Item_string::print():
          - Do not append character set introducer to the text literal
            if we're building a query for INFORMATION_SCHEMA;
          - Convert text literal to UTF8 if we're building a query
            for INFORMATION_SCHEMA.

  sql/item.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +53 -35
    Add a parameter to print().

  sql/item_cmpfunc.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +28 -28
    Add a parameter to print().

  sql/item_cmpfunc.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +37 -14
    Add a parameter to print().

  sql/item_func.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +33 -32
    Add a parameter to print().

  sql/item_func.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +36 -18
    Add a parameter to print().

  sql/item_geofunc.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +7 -2
    Add a parameter to print().

  sql/item_row.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +2 -2
    Add a parameter to print().

  sql/item_row.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +1 -1
    Add a parameter to print().

  sql/item_strfunc.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +16 -16
    Add a parameter to print().

  sql/item_strfunc.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +6 -6
    Add a parameter to print().

  sql/item_subselect.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +26 -23
    Add a parameter to print().

  sql/item_subselect.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +10 -10
    Add a parameter to print().

  sql/item_sum.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +7 -7
    Add a parameter to print().

  sql/item_sum.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +3 -3
    Add a parameter to print().

  sql/item_timefunc.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +16 -16
    Add a parameter to print().

  sql/item_timefunc.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +7 -7
    Add a parameter to print().

  sql/mysql_priv.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +14 -1
    Add a parameter to print().

  sql/sp_head.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +6 -6
    Add a parameter to print().

  sql/sql_lex.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +16 -11
    Add a parameter to print().

  sql/sql_lex.h@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +6 -6
    Add a parameter to print().

  sql/sql_parse.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +1 -1
    Add a parameter to print().

  sql/sql_select.cc@stripped, 2008-02-22 13:30:30+03:00, anozdrin@quad. +47 -34
    Add a parameter to print().

  sql/sql_show.cc@stripped, 2008-02-22 13:30:31+03:00, anozdrin@quad. +1 -1
    Add a parameter to print().

  sql/sql_test.cc@stripped, 2008-02-22 13:30:31+03:00, anozdrin@quad. +3 -3
    Add a parameter to print().

  sql/sql_view.cc@stripped, 2008-02-22 13:30:31+03:00, anozdrin@quad. +44 -4
    Build INFORMATION_SCHEMA query from Item-tree.

  sql/sql_yacc.yy@stripped, 2008-02-22 13:30:31+03:00, anozdrin@quad. +1 -21
    Build INFORMATION_SCHEMA query from Item-tree.

  sql/table.h@stripped, 2008-02-22 13:30:31+03:00, anozdrin@quad. +1 -1
    Add a parameter to print().

diff -Nrup a/mysql-test/include/ddl_i18n.check_views.inc
b/mysql-test/include/ddl_i18n.check_views.inc
--- a/mysql-test/include/ddl_i18n.check_views.inc	2007-06-28 21:34:50 +04:00
+++ b/mysql-test/include/ddl_i18n.check_views.inc	2008-02-22 13:30:29 +03:00
@@ -9,6 +9,10 @@ SHOW CREATE VIEW v1|
 
 SHOW CREATE VIEW v2|
 
+--echo
+
+SHOW CREATE VIEW v3|
+
 #   - Check INFORMATION_SCHEMA;
 
 --echo
@@ -20,6 +24,10 @@ SELECT * FROM INFORMATION_SCHEMA.VIEWS W
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
 
+--echo
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+
 #   - Execute the views;
 
 --echo
@@ -30,3 +38,7 @@ SELECT COLLATION(c1), COLLATION(c2) FROM
 --echo
 
 SELECT COLLATION(c1) FROM v2|
+
+--echo
+
+SELECT * FROM v3|
diff -Nrup a/mysql-test/r/ddl_i18n_koi8r.result b/mysql-test/r/ddl_i18n_koi8r.result
--- a/mysql-test/r/ddl_i18n_koi8r.result	2008-02-12 22:09:14 +03:00
+++ b/mysql-test/r/ddl_i18n_koi8r.result	2008-02-22 13:30:29 +03:00
@@ -16,6 +16,8 @@ FROM t1|
 
 CREATE VIEW v2 AS SELECT _utf8'тест' as c1|
 
+CREATE VIEW v3 AS SELECT _utf8'тест'|
+
 
 
 SHOW CREATE VIEW v1|
@@ -26,15 +28,22 @@ SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2`
AS select _utf8'тест' AS `c1`	koi8r	koi8r_general_ci
 
+SHOW CREATE VIEW v3|
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3`
AS select _utf8'тест' AS ``	koi8r	koi8r_general_ci
+
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v1'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v1	SELECT '' AS c1,  AS c2
-FROM t1	NONE	YES	root@localhost	DEFINER	koi8r	koi8r_general_ci
+NULL	mysqltest1	v1	select '' AS `c1`,`mysqltest1`.`t1`.`` AS `c2` from
`mysqltest1`.`t1`	NONE	YES	root@localhost	DEFINER	koi8r	koi8r_general_ci
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v2	SELECT '' as
c1	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
+NULL	mysqltest1	v2	select '' AS
`c1`	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
+NULL	mysqltest1	v3	select '' AS
``	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
 
 
 SELECT COLLATION(c1), COLLATION(c2) FROM v1|
@@ -45,6 +54,10 @@ SELECT COLLATION(c1) FROM v2|
 COLLATION(c1)
 utf8_general_ci
 
+SELECT * FROM v3|
+
+
+
 
 ALTER DATABASE mysqltest1 COLLATE cp866_general_ci|
 
@@ -54,6 +67,7 @@ SET @@character_set_results= cp1251|
 SET @@collation_connection= cp1251_general_ci|
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 use mysqltest1|
 set names koi8r|
 
@@ -66,15 +80,22 @@ SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2`
AS select _utf8'тест' AS `c1`	koi8r	koi8r_general_ci
 
+SHOW CREATE VIEW v3|
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3`
AS select _utf8'тест' AS ``	koi8r	koi8r_general_ci
+
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v1'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v1	SELECT '' AS c1,  AS c2
-FROM t1	NONE	YES	root@localhost	DEFINER	koi8r	koi8r_general_ci
+NULL	mysqltest1	v1	select '' AS `c1`,`mysqltest1`.`t1`.`` AS `c2` from
`mysqltest1`.`t1`	NONE	YES	root@localhost	DEFINER	koi8r	koi8r_general_ci
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v2	SELECT '' as
c1	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
+NULL	mysqltest1	v2	select '' AS
`c1`	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
+NULL	mysqltest1	v3	select '' AS
``	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
 
 
 SELECT COLLATION(c1), COLLATION(c2) FROM v1|
@@ -85,6 +106,10 @@ SELECT COLLATION(c1) FROM v2|
 COLLATION(c1)
 utf8_general_ci
 
+SELECT * FROM v3|
+
+
+
 ---> Dumping mysqltest1 to ddl_i18n_koi8r.views.mysqltest1.sql
 
 
@@ -99,6 +124,7 @@ SET @@character_set_results= cp1251|
 SET @@collation_connection= cp1251_general_ci|
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 use mysqltest1|
 set names koi8r|
 
@@ -111,15 +137,23 @@ SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2`
AS select _utf8'тест' AS `c1`	koi8r	koi8r_general_ci
 
+SHOW CREATE VIEW v3|
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3`
AS select _utf8'тест' AS ``	koi8r	koi8r_general_ci
+
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v1'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v1	select '' AS `c1`,`t1`.`` AS `c2` from
`t1`	NONE	YES	root@localhost	DEFINER	koi8r	koi8r_general_ci
+NULL	mysqltest1	v1	select '' AS `c1`,`mysqltest1`.`t1`.`` AS `c2` from
`mysqltest1`.`t1`	NONE	YES	root@localhost	DEFINER	koi8r	koi8r_general_ci
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
 NULL	mysqltest1	v2	select '' AS
`c1`	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
 
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
+NULL	mysqltest1	v3	select '' AS
``	NONE	NO	root@localhost	DEFINER	koi8r	koi8r_general_ci
+
 
 SELECT COLLATION(c1), COLLATION(c2) FROM v1|
 COLLATION(c1)	COLLATION(c2)
@@ -128,6 +162,10 @@ koi8r_general_ci	binary
 SELECT COLLATION(c1) FROM v2|
 COLLATION(c1)
 utf8_general_ci
+
+SELECT * FROM v3|
+
+
 
 ---> connection: default
 use test|
diff -Nrup a/mysql-test/r/ddl_i18n_utf8.result b/mysql-test/r/ddl_i18n_utf8.result
--- a/mysql-test/r/ddl_i18n_utf8.result	2008-02-12 22:09:14 +03:00
+++ b/mysql-test/r/ddl_i18n_utf8.result	2008-02-22 13:30:29 +03:00
@@ -16,6 +16,8 @@ FROM t1|
 
 CREATE VIEW v2 AS SELECT _koi8r'' as c1|
 
+CREATE VIEW v3 AS SELECT _koi8r''|
+
 
 
 SHOW CREATE VIEW v1|
@@ -26,15 +28,22 @@ SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2`
AS select _koi8r'' AS `c1`	utf8	utf8_general_ci
 
+SHOW CREATE VIEW v3|
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3`
AS select _koi8r'' AS `тест`	utf8	utf8_general_ci
+
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v1'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v1	SELECT 'тест' AS c1, кол AS c2
-FROM t1	NONE	YES	root@localhost	DEFINER	utf8	utf8_general_ci
+NULL	mysqltest1	v1	select 'тест' AS `c1`,`mysqltest1`.`t1`.`кол` AS `c2` from
`mysqltest1`.`t1`	NONE	YES	root@localhost	DEFINER	utf8	utf8_general_ci
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v2	SELECT 'тест' as
c1	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
+NULL	mysqltest1	v2	select 'тест' AS
`c1`	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
+NULL	mysqltest1	v3	select 'тест' AS
`тест`	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
 
 
 SELECT COLLATION(c1), COLLATION(c2) FROM v1|
@@ -45,6 +54,10 @@ SELECT COLLATION(c1) FROM v2|
 COLLATION(c1)
 koi8r_general_ci
 
+SELECT * FROM v3|
+тест
+тест
+
 
 ALTER DATABASE mysqltest1 COLLATE cp866_general_ci|
 
@@ -54,6 +67,7 @@ SET @@character_set_results= cp1251|
 SET @@collation_connection= cp1251_general_ci|
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 use mysqltest1|
 set names utf8|
 
@@ -66,15 +80,22 @@ SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2`
AS select _koi8r'' AS `c1`	utf8	utf8_general_ci
 
+SHOW CREATE VIEW v3|
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3`
AS select _koi8r'' AS `тест`	utf8	utf8_general_ci
+
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v1'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v1	SELECT 'тест' AS c1, кол AS c2
-FROM t1	NONE	YES	root@localhost	DEFINER	utf8	utf8_general_ci
+NULL	mysqltest1	v1	select 'тест' AS `c1`,`mysqltest1`.`t1`.`кол` AS `c2` from
`mysqltest1`.`t1`	NONE	YES	root@localhost	DEFINER	utf8	utf8_general_ci
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v2	SELECT 'тест' as
c1	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
+NULL	mysqltest1	v2	select 'тест' AS
`c1`	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
+NULL	mysqltest1	v3	select 'тест' AS
`тест`	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
 
 
 SELECT COLLATION(c1), COLLATION(c2) FROM v1|
@@ -85,6 +106,10 @@ SELECT COLLATION(c1) FROM v2|
 COLLATION(c1)
 koi8r_general_ci
 
+SELECT * FROM v3|
+тест
+тест
+
 ---> Dumping mysqltest1 to ddl_i18n_utf8views.mysqltest1.sql
 
 
@@ -99,6 +124,7 @@ SET @@character_set_results= cp1251|
 SET @@collation_connection= cp1251_general_ci|
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 use mysqltest1|
 set names utf8|
 
@@ -111,15 +137,23 @@ SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2`
AS select _koi8r'' AS `c1`	utf8	utf8_general_ci
 
+SHOW CREATE VIEW v3|
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3`
AS select _koi8r'' AS `тест`	utf8	utf8_general_ci
+
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v1'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	mysqltest1	v1	select 'тест' AS `c1`,`t1`.`кол` AS `c2` from
`t1`	NONE	YES	root@localhost	DEFINER	utf8	utf8_general_ci
+NULL	mysqltest1	v1	select 'тест' AS `c1`,`mysqltest1`.`t1`.`кол` AS `c2` from
`mysqltest1`.`t1`	NONE	YES	root@localhost	DEFINER	utf8	utf8_general_ci
 
 SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
 NULL	mysqltest1	v2	select 'тест' AS
`c1`	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
 
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
+NULL	mysqltest1	v3	select 'тест' AS
`тест`	NONE	NO	root@localhost	DEFINER	utf8	utf8_general_ci
+
 
 SELECT COLLATION(c1), COLLATION(c2) FROM v1|
 COLLATION(c1)	COLLATION(c2)
@@ -128,6 +162,10 @@ utf8_general_ci	binary
 SELECT COLLATION(c1) FROM v2|
 COLLATION(c1)
 koi8r_general_ci
+
+SELECT * FROM v3|
+тест
+тест
 
 ---> connection: default
 use test|
diff -Nrup a/mysql-test/r/information_schema.result
b/mysql-test/r/information_schema.result
--- a/mysql-test/r/information_schema.result	2008-02-07 13:47:37 +03:00
+++ b/mysql-test/r/information_schema.result	2008-02-22 13:30:29 +03:00
@@ -387,15 +387,11 @@ show keys from v4;
 Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
 select * from information_schema.views where TABLE_NAME like "v%";
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	test	v0	select schema_name from
information_schema.schemata	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
-NULL	test	v1	select table_name from information_schema.tables
-where table_name="v1"	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
-NULL	test	v2	select column_name from information_schema.columns
-where table_name="v2"	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
-NULL	test	v3	select CHARACTER_SET_NAME from information_schema.character_sets
-where CHARACTER_SET_NAME like
"latin1%"	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
-NULL	test	v4	select COLLATION_NAME from information_schema.collations
-where COLLATION_NAME like
"latin1%"	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v0	select `schemata`.`SCHEMA_NAME` AS `c` from
`information_schema`.`schemata`	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v1	select `tables`.`TABLE_NAME` AS `c` from `information_schema`.`tables` where
(`tables`.`TABLE_NAME` = 'v1')	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v2	select `columns`.`COLUMN_NAME` AS `c` from `information_schema`.`columns`
where (`columns`.`TABLE_NAME` =
'v2')	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v3	select `character_sets`.`CHARACTER_SET_NAME` AS `c` from
`information_schema`.`character_sets` where (`character_sets`.`CHARACTER_SET_NAME` like
'latin1%')	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v4	select `collations`.`COLLATION_NAME` AS `c` from
`information_schema`.`collations` where (`collations`.`COLLATION_NAME` like
'latin1%')	NONE	NO	root@localhost	DEFINER	latin1	latin1_swedish_ci
 drop view v0, v1, v2, v3, v4;
 create table t1 (a int);
 grant select,update,insert on t1 to mysqltest_1@localhost;
@@ -488,9 +484,9 @@ create view v2 (c) as select a from t1 W
 create view v3 (c) as select a from t1 WITH CASCADED CHECK OPTION;
 select * from information_schema.views;
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	test	v1	select a from t1 with check
option	CASCADED	YES	root@localhost	DEFINER	latin1	latin1_swedish_ci
-NULL	test	v2	select a from t1 WITH LOCAL CHECK
OPTION	LOCAL	YES	root@localhost	DEFINER	latin1	latin1_swedish_ci
-NULL	test	v3	select a from t1 WITH CASCADED CHECK
OPTION	CASCADED	YES	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v1	select `test`.`t1`.`a` AS `c` from
`test`.`t1`	CASCADED	YES	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v2	select `test`.`t1`.`a` AS `c` from
`test`.`t1`	LOCAL	YES	root@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v3	select `test`.`t1`.`a` AS `c` from
`test`.`t1`	CASCADED	YES	root@localhost	DEFINER	latin1	latin1_swedish_ci
 grant select (a) on test.t1 to joe@localhost with grant option;
 select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES;
 GRANTEE	TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	COLUMN_NAME	PRIVILEGE_TYPE	IS_GRANTABLE
@@ -1175,7 +1171,7 @@ select * from information_schema.views
 where table_name='v1' or table_name='v2';
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
 NULL	test	v1		NONE	YES	root@localhost	DEFINER	latin1	latin1_swedish_ci
-NULL	test	v2	select 1	NONE	NO	mysqltest_1@localhost	DEFINER	latin1	latin1_swedish_ci
+NULL	test	v2	select 1 AS
`1`	NONE	NO	mysqltest_1@localhost	DEFINER	latin1	latin1_swedish_ci
 drop view v1, v2;
 drop table t1;
 drop user mysqltest_1@localhost;
@@ -1559,8 +1555,7 @@ AS SELECT *
 FROM INFORMATION_SCHEMA.TABLES;
 SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS where TABLE_NAME = 'v1';
 VIEW_DEFINITION
-SELECT *
-FROM INFORMATION_SCHEMA.TABLES
+select `TABLES`.`TABLE_CATALOG` AS `TABLE_CATALOG`,`TABLES`.`TABLE_SCHEMA` AS
`TABLE_SCHEMA`,`TABLES`.`TABLE_NAME` AS `TABLE_NAME`,`TABLES`.`TABLE_TYPE` AS
`TABLE_TYPE`,`TABLES`.`ENGINE` AS `ENGINE`,`TABLES`.`VERSION` AS
`VERSION`,`TABLES`.`ROW_FORMAT` AS `ROW_FORMAT`,`TABLES`.`TABLE_ROWS` AS
`TABLE_ROWS`,`TABLES`.`AVG_ROW_LENGTH` AS `AVG_ROW_LENGTH`,`TABLES`.`DATA_LENGTH` AS
`DATA_LENGTH`,`TABLES`.`MAX_DATA_LENGTH` AS `MAX_DATA_LENGTH`,`TABLES`.`INDEX_LENGTH` AS
`INDEX_LENGTH`,`TABLES`.`DATA_FREE` AS `DATA_FREE`,`TABLES`.`AUTO_INCREMENT` AS
`AUTO_INCREMENT`,`TABLES`.`CREATE_TIME` AS `CREATE_TIME`,`TABLES`.`UPDATE_TIME` AS
`UPDATE_TIME`,`TABLES`.`CHECK_TIME` AS `CHECK_TIME`,`TABLES`.`TABLE_COLLATION` AS
`TABLE_COLLATION`,`TABLES`.`CHECKSUM` AS `CHECKSUM`,`TABLES`.`CREATE_OPTIONS` AS
`CREATE_OPTIONS`,`TABLES`.`TABLE_COMMENT` AS `TABLE_COMMENT` from
`INFORMATION_SCHEMA`.`TABLES`
 DROP VIEW v1;
 SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
 WHERE SCHEMA_NAME ='information_schema';
diff -Nrup a/mysql-test/r/information_schema_db.result
b/mysql-test/r/information_schema_db.result
--- a/mysql-test/r/information_schema_db.result	2007-12-14 20:01:38 +03:00
+++ b/mysql-test/r/information_schema_db.result	2008-02-22 13:30:29 +03:00
@@ -210,7 +210,7 @@ v2
 select view_definition from information_schema.views a 
 where a.table_name = 'v2';
 view_definition
-select f1 from testdb_1.v1
+select `v1`.`f1` AS `f1` from `testdb_1`.`v1`
 select view_definition from information_schema.views a 
 where a.table_name = 'testdb_1.v1';
 view_definition
diff -Nrup a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result
--- a/mysql-test/r/mysqldump.result	2008-02-12 22:09:14 +03:00
+++ b/mysql-test/r/mysqldump.result	2008-02-22 13:30:29 +03:00
@@ -4230,6 +4230,40 @@ LOCK TABLES `test` WRITE;
 UNLOCK TABLES;
 drop database `test-database`;
 use test;
+
+# -----------------------------------------------------------------
+# -- Bug#30217: Views: changes in metadata behaviour between 5.0 and 5.1.
+# -----------------------------------------------------------------
+
+DROP DATABASE IF EXISTS mysqldump_test_db;
+CREATE DATABASE mysqldump_test_db;
+use mysqldump_test_db;
+
+CREATE VIEW v1(x, y) AS SELECT 'a', 'a';
+
+SELECT view_definition
+FROM INFORMATION_SCHEMA.VIEWS
+WHERE table_schema = 'mysqldump_test_db' AND table_name = 'v1';
+view_definition
+select 'a' AS `x`,'a' AS `y`
+
+---> Dumping mysqldump_test_db to bug30217.sql
+
+DROP DATABASE mysqldump_test_db;
+use test;
+
+---> Restoring mysqldump_test_db...
+
+SELECT view_definition
+FROM INFORMATION_SCHEMA.VIEWS
+WHERE table_schema = 'mysqldump_test_db' AND table_name = 'v1';
+view_definition
+select 'a' AS `x`,'a' AS `y`
+
+DROP DATABASE mysqldump_test_db;
+
+# -- End of test case for Bug#32538.
+
 #
 # End of 5.1 tests
 #
diff -Nrup a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result
--- a/mysql-test/r/show_check.result	2008-02-12 22:09:14 +03:00
+++ b/mysql-test/r/show_check.result	2008-02-22 13:30:29 +03:00
@@ -1075,7 +1075,7 @@ Catalog	Database	Table	Table_alias	Colum
 def			VIEWS	TABLE_CATALOG	TABLE_CATALOG	253	1536	0	Y	0	0	33
 def			VIEWS	TABLE_SCHEMA	TABLE_SCHEMA	253	192	4	N	1	0	33
 def			VIEWS	TABLE_NAME	TABLE_NAME	253	192	2	N	1	0	33
-def			VIEWS	VIEW_DEFINITION	VIEW_DEFINITION	252	589815	8	N	17	0	33
+def			VIEWS	VIEW_DEFINITION	VIEW_DEFINITION	252	589815	15	N	17	0	33
 def			VIEWS	CHECK_OPTION	CHECK_OPTION	253	24	4	N	1	0	33
 def			VIEWS	IS_UPDATABLE	IS_UPDATABLE	253	9	2	N	1	0	33
 def			VIEWS	DEFINER	DEFINER	253	231	14	N	1	0	33
@@ -1083,7 +1083,7 @@ def			VIEWS	SECURITY_TYPE	SECURITY_TYPE	
 def			VIEWS	CHARACTER_SET_CLIENT	CHARACTER_SET_CLIENT	253	96	6	N	1	0	33
 def			VIEWS	COLLATION_CONNECTION	COLLATION_CONNECTION	253	96	6	N	1	0	33
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	VIEW_DEFINITION	CHECK_OPTION	IS_UPDATABLE	DEFINER	SECURITY_TYPE	CHARACTER_SET_CLIENT	COLLATION_CONNECTION
-NULL	test	v1	SELECT 1	NONE	NO	root@localhost	DEFINER	binary	binary
+NULL	test	v1	select 1 AS `1`	NONE	NO	root@localhost	DEFINER	binary	binary
 ----------------------------------------------------------------
 SHOW CREATE PROCEDURE p1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max
length	Is_null	Flags	Decimals	Charsetnr
diff -Nrup a/mysql-test/t/ddl_i18n_koi8r.test b/mysql-test/t/ddl_i18n_koi8r.test
--- a/mysql-test/t/ddl_i18n_koi8r.test	2007-07-19 01:31:17 +04:00
+++ b/mysql-test/t/ddl_i18n_koi8r.test	2008-02-22 13:30:29 +03:00
@@ -85,6 +85,10 @@ CREATE VIEW v2 AS SELECT _utf8'тест'
 
 --echo
 
+CREATE VIEW v3 AS SELECT _utf8'тест'|
+
+--echo
+
 #
 # First-round checks.
 #
@@ -120,6 +124,7 @@ SET @@collation_connection= cp1251_gener
 --disable_result_log
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 --enable_result_log
 
 use mysqltest1|
@@ -168,7 +173,7 @@ DROP DATABASE mysqltest1|
 --echo
 --echo ---> connection: con3
 
-#   - Switch environment variables and trigger loading stored procedures;
+#   - Switch environment variables and trigger loading views;
 
 SET @@character_set_client= cp1251|
 SET @@character_set_results= cp1251|
@@ -177,6 +182,7 @@ SET @@collation_connection= cp1251_gener
 --disable_result_log
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 --enable_result_log
 
 use mysqltest1|
diff -Nrup a/mysql-test/t/ddl_i18n_utf8.test b/mysql-test/t/ddl_i18n_utf8.test
--- a/mysql-test/t/ddl_i18n_utf8.test	2007-07-19 01:31:17 +04:00
+++ b/mysql-test/t/ddl_i18n_utf8.test	2008-02-22 13:30:29 +03:00
@@ -85,6 +85,10 @@ CREATE VIEW v2 AS SELECT _koi8r'' as
 
 --echo
 
+CREATE VIEW v3 AS SELECT _koi8r''|
+
+--echo
+
 #
 # First-round checks.
 #
@@ -120,6 +124,7 @@ SET @@collation_connection= cp1251_gener
 --disable_result_log
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 --enable_result_log
 
 use mysqltest1|
@@ -168,7 +173,7 @@ DROP DATABASE mysqltest1|
 --echo
 --echo ---> connection: con3
 
-#   - Switch environment variables and trigger loading stored procedures;
+#   - Switch environment variables and trigger loading views;
 
 SET @@character_set_client= cp1251|
 SET @@character_set_results= cp1251|
@@ -177,6 +182,7 @@ SET @@collation_connection= cp1251_gener
 --disable_result_log
 SELECT * FROM mysqltest1.v1|
 SELECT * FROM mysqltest1.v2|
+SELECT * FROM mysqltest1.v3|
 --enable_result_log
 
 use mysqltest1|
diff -Nrup a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test
--- a/mysql-test/t/mysqldump.test	2007-11-19 19:12:41 +03:00
+++ b/mysql-test/t/mysqldump.test	2008-02-22 13:30:29 +03:00
@@ -1799,6 +1799,61 @@ create table test (a int);
 drop database `test-database`;
 use test;
 
+###########################################################################
+
+--echo
+--echo # -----------------------------------------------------------------
+--echo # -- Bug#30217: Views: changes in metadata behaviour between 5.0 and 5.1.
+--echo # -----------------------------------------------------------------
+--echo
+
+--disable_warnings
+DROP DATABASE IF EXISTS mysqldump_test_db;
+--enable_warnings
+
+CREATE DATABASE mysqldump_test_db;
+use mysqldump_test_db;
+
+--echo
+
+CREATE VIEW v1(x, y) AS SELECT 'a', 'a';
+
+--echo
+
+SELECT view_definition
+FROM INFORMATION_SCHEMA.VIEWS
+WHERE table_schema = 'mysqldump_test_db' AND table_name = 'v1';
+
+--echo
+
+--echo ---> Dumping mysqldump_test_db to bug30217.sql
+--exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --databases mysqldump_test_db >
$MYSQLTEST_VARDIR/tmp/bug30217.sql
+
+--echo
+
+DROP DATABASE mysqldump_test_db;
+use test;
+
+--echo
+
+--echo ---> Restoring mysqldump_test_db...
+--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug30217.sql
+
+--echo
+
+SELECT view_definition
+FROM INFORMATION_SCHEMA.VIEWS
+WHERE table_schema = 'mysqldump_test_db' AND table_name = 'v1';
+
+--echo
+
+DROP DATABASE mysqldump_test_db;
+
+--echo
+--echo # -- End of test case for Bug#32538.
+--echo
+
+###########################################################################
 
 --echo #
 --echo # End of 5.1 tests
diff -Nrup a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
--- a/sql/ha_ndbcluster.cc	2007-12-21 00:11:30 +03:00
+++ b/sql/ha_ndbcluster.cc	2008-02-22 13:30:29 +03:00
@@ -9446,7 +9446,7 @@ ha_ndbcluster::cond_push(const COND *con
     my_errno= HA_ERR_OUT_OF_MEM;
     DBUG_RETURN(NULL);
   }
-  DBUG_EXECUTE("where",print_where((COND *)cond, m_tabname););
+  DBUG_EXECUTE("where",print_where((COND *)cond, m_tabname, QT_ORDINARY););
   DBUG_RETURN(m_cond->cond_push(cond, table, (NDBTAB *)m_table));
 }
 
diff -Nrup a/sql/item.cc b/sql/item.cc
--- a/sql/item.cc	2008-02-12 22:09:14 +03:00
+++ b/sql/item.cc	2008-02-22 13:30:30 +03:00
@@ -442,9 +442,10 @@ uint Item::decimal_precision() const
 }
 
 
-void Item::print_item_w_name(String *str)
+void Item::print_item_w_name(String *str, enum_query_type query_type)
 {
-  print(str);
+  print(str, query_type);
+
   if (name)
   {
     THD *thd= current_thd;
@@ -1128,7 +1129,7 @@ Item_splocal::this_item_addr(THD *thd, I
 }
 
 
-void Item_splocal::print(String *str)
+void Item_splocal::print(String *str, enum_query_type)
 {
   str->reserve(m_name.length+8);
   str->append(m_name.str, m_name.length);
@@ -1182,7 +1183,7 @@ Item_case_expr::this_item_addr(THD *thd,
 }
 
 
-void Item_case_expr::print(String *str)
+void Item_case_expr::print(String *str, enum_query_type)
 {
   if (str->reserve(MAX_INT_WIDTH + sizeof("case_expr@")))
     return;                                    /* purecov: inspected */
@@ -1276,12 +1277,12 @@ bool Item_name_const::fix_fields(THD *th
 }
 
 
-void Item_name_const::print(String *str)
+void Item_name_const::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("NAME_CONST("));
-  name_item->print(str);
+  name_item->print(str, query_type);
   str->append(',');
-  value_item->print(str);
+  value_item->print(str, query_type);
   str->append(')');
 }
 
@@ -1298,12 +1299,12 @@ public:
                   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)
+  virtual inline void print (String *str, enum_query_type query_type)
   {
     if (ref)
-      (*ref)->print(str);
+      (*ref)->print(str, query_type);
     else
-      Item_ident::print(str);
+      Item_ident::print(str, query_type);
   }
 };
 
@@ -1455,7 +1456,9 @@ bool DTCollation::aggregate(DTCollation 
         set(dt);
       }
       else
-       ; // Do nothing
+      {
+        // Do nothing
+      }
     }
     else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
              left_is_superset(this, &dt))
@@ -1872,7 +1875,7 @@ const char *Item_ident::full_name() cons
   return tmp;
 }
 
-void Item_ident::print(String *str)
+void Item_ident::print(String *str, enum_query_type query_type)
 {
   THD *thd= current_thd;
   char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
@@ -2134,7 +2137,7 @@ String *Item_int::val_str(String *str)
   return str;
 }
 
-void Item_int::print(String *str)
+void Item_int::print(String *str, enum_query_type query_type)
 {
   // my_charset_bin is good enough for numbers
   str_value.set(value, &my_charset_bin);
@@ -2165,7 +2168,7 @@ String *Item_uint::val_str(String *str)
 }
 
 
-void Item_uint::print(String *str)
+void Item_uint::print(String *str, enum_query_type query_type)
 {
   // latin1 is good enough for numbers
   str_value.set((ulonglong) value, default_charset());
@@ -2257,7 +2260,7 @@ String *Item_decimal::val_str(String *re
   return result;
 }
 
-void Item_decimal::print(String *str)
+void Item_decimal::print(String *str, enum_query_type query_type)
 {
   my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
   str->append(str_value);
@@ -2310,16 +2313,39 @@ my_decimal *Item_float::val_decimal(my_d
 }
 
 
-void Item_string::print(String *str)
+void Item_string::print(String *str, enum_query_type query_type)
 {
-  if (is_cs_specified())
+  if (query_type == QT_ORDINARY && is_cs_specified())
   {
     str->append('_');
     str->append(collation.collation->csname);
   }
 
   str->append('\'');
-  str_value.print(str);
+
+  if (query_type == QT_ORDINARY ||
+      my_charset_same(str_value.charset(), system_charset_info))
+  {
+    str_value.print(str);
+  }
+  else
+  {
+    THD *thd= current_thd;
+    LEX_STRING utf8_lex_str;
+
+    thd->convert_string(&utf8_lex_str,
+                        system_charset_info,
+                        str_value.c_ptr_safe(),
+                        str_value.length(),
+                        str_value.charset());
+
+    String utf8_str(utf8_lex_str.str,
+                    utf8_lex_str.length,
+                    system_charset_info);
+
+    utf8_str.print(str);
+  }
+
   str->append('\'');
 }
 
@@ -3086,7 +3112,7 @@ Item_param::eq(const Item *arg, bool bin
 
 /* End of Item_param related */
 
-void Item_param::print(String *str)
+void Item_param::print(String *str, enum_query_type query_type)
 {
   if (state == NO_VALUE)
   {
@@ -4799,7 +4825,7 @@ int Item_float::save_in_field(Field *fie
 }
 
 
-void Item_float::print(String *str)
+void Item_float::print(String *str, enum_query_type query_type)
 {
   if (presentation)
   {
@@ -4917,7 +4943,7 @@ warn:
 }
 
 
-void Item_hex_string::print(String *str)
+void Item_hex_string::print(String *str, enum_query_type query_type)
 {
   char *end= (char*) str_value.ptr() + str_value.length(),
        *ptr= end - min(str_value.length(), sizeof(longlong));
@@ -5179,7 +5205,7 @@ Item *Item_field::update_value_transform
 }
 
 
-void Item_field::print(String *str)
+void Item_field::print(String *str, enum_query_type query_type)
 {
   if (field && field->table->const_table)
   {
@@ -5191,7 +5217,7 @@ void Item_field::print(String *str)
     str->append('\'');
     return;
   }
-  Item_ident::print(str);
+  Item_ident::print(str, query_type);
 }
 
 
@@ -5531,7 +5557,7 @@ void Item_ref::cleanup()
 }
 
 
-void Item_ref::print(String *str)
+void Item_ref::print(String *str, enum_query_type query_type)
 {
   if (ref)
   {
@@ -5542,10 +5568,10 @@ void Item_ref::print(String *str)
       append_identifier(thd, str, name, (uint) strlen(name));
     }
     else
-      (*ref)->print(str);
+      (*ref)->print(str, query_type);
   }
   else
-    Item_ident::print(str);
+    Item_ident::print(str, query_type);
 }
 
 
@@ -5735,11 +5761,11 @@ Item *Item_ref::get_tmp_table_item(THD *
 }
 
 
-void Item_ref_null_helper::print(String *str)
+void Item_ref_null_helper::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("<ref_null_helper>("));
   if (ref)
-    (*ref)->print(str);
+    (*ref)->print(str, query_type);
   else
     str->append('?');
   str->append(')');
@@ -5931,7 +5957,7 @@ error:
 }
 
 
-void Item_default_value::print(String *str)
+void Item_default_value::print(String *str, enum_query_type query_type)
 {
   if (!arg)
   {
@@ -5939,7 +5965,7 @@ void Item_default_value::print(String *s
     return;
   }
   str->append(STRING_WITH_LEN("default("));
-  arg->print(str);
+  arg->print(str, query_type);
   str->append(')');
 }
 
@@ -6075,10 +6101,10 @@ bool Item_insert_value::fix_fields(THD *
   return FALSE;
 }
 
-void Item_insert_value::print(String *str)
+void Item_insert_value::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("values("));
-  arg->print(str);
+  arg->print(str, query_type);
   str->append(')');
 }
 
@@ -6199,7 +6225,7 @@ bool Item_trigger_field::fix_fields(THD 
 }
 
 
-void Item_trigger_field::print(String *str)
+void Item_trigger_field::print(String *str, enum_query_type query_type)
 {
   str->append((row_version == NEW_ROW) ? "NEW" : "OLD", 3);
   str->append('.');
@@ -6389,13 +6415,13 @@ Item_cache* Item_cache::get_cache(const 
 }
 
 
-void Item_cache::print(String *str)
+void Item_cache::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("<cache>("));
   if (example)
-    example->print(str);
+    example->print(str, query_type);
   else
-    Item::print(str);
+    Item::print(str, query_type);
   str->append(')');
 }
 
diff -Nrup a/sql/item.h b/sql/item.h
--- a/sql/item.h	2008-02-12 22:09:14 +03:00
+++ b/sql/item.h	2008-02-22 13:30:30 +03:00
@@ -113,7 +113,6 @@ public:
   }
 };
 
-
 /*************************************************************************/
 /*
   A framework to easily handle different return types for hybrid items
@@ -769,20 +768,24 @@ public:
   */
   virtual bool const_during_execution() const 
   { return (used_tables() & ~PARAM_TABLE_BIT) == 0; }
-  /*
-    This is an essential method for correct functioning of VIEWS.
-    To save a view in an .frm file we need its unequivocal
-    definition in SQL that takes into account sql_mode and
-    environmental settings.  Currently such definition is restored
-    by traversing through the parsed tree of a view and
-    print()'ing SQL syntax of every node to a String buffer. This
-    method is used to print the SQL definition of an item. The
-    second use of this method is for EXPLAIN EXTENDED, to print
-    the SQL of a query after all optimizations of the parsed tree
-    have been done.
+
+  /**
+    This method is used for to:
+      - to generate a view definition query (SELECT-statement);
+      - to generate a SQL-query for EXPLAIN EXTENDED;
+      - to generate a SQL-query to be shown in INFORMATION_SCHEMA;
+      - debug.
+
+    For more information about view definition query, INFORMATION_SCHEMA
+    query and why they should be generated from the Item-tree, @see
+    mysql_register_view().
   */
-  virtual void print(String *str_arg) { str_arg->append(full_name()); }
-  void print_item_w_name(String *);
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    str->append(full_name());
+  }
+
+  void print_item_w_name(String *, enum_query_type query_type);
   virtual void update_used_tables() {}
   virtual void split_sum_func(THD *thd, Item **ref_pointer_array,
                               List<Item> &fields) {}
@@ -1134,7 +1137,7 @@ public:
   const Item *this_item() const;
   Item **this_item_addr(THD *thd, Item **);
 
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 
 public:
   inline const LEX_STRING *my_name() const;
@@ -1203,7 +1206,7 @@ public:
     Item_case_expr can not occur in views, so here it is only for debug
     purposes.
   */
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 
 private:
   uint m_case_expr_id;
@@ -1261,7 +1264,7 @@ public:
   String *val_str(String *sp);
   my_decimal *val_decimal(my_decimal *);
   bool is_null();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 
   Item_result result_type() const
   {
@@ -1343,7 +1346,7 @@ public:
   const char *full_name() const;
   void cleanup();
   bool remove_dependence_processor(uchar * arg);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   virtual bool change_context_processor(uchar *cntx)
     { context= (Name_resolution_context *)cntx; return FALSE; }
   friend bool insert_fields(THD *thd, Name_resolution_context *context,
@@ -1473,7 +1476,7 @@ public:
   Item *safe_charset_converter(CHARSET_INFO *tocs);
   int fix_outer_field(THD *thd, Field **field, Item **reference);
   virtual Item *update_value_transformer(uchar *select_arg);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   Field::geometry_type get_geometry_type() const
   {
     DBUG_ASSERT(field_type() == MYSQL_TYPE_GEOMETRY);
@@ -1511,7 +1514,12 @@ public:
   bool basic_const_item() const { return 1; }
   Item *clone_item() { return new Item_null(name); }
   bool is_null() { return 1; }
-  void print(String *str) { str->append(STRING_WITH_LEN("NULL")); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    str->append(STRING_WITH_LEN("NULL"));
+  }
+
   Item *safe_charset_converter(CHARSET_INFO *tocs);
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
 };
@@ -1645,7 +1653,7 @@ public:
   */
   virtual table_map used_tables() const
   { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool is_null()
   { DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; }
   bool basic_const_item() const;
@@ -1703,7 +1711,7 @@ public:
   Item *clone_item() { return new Item_int(name,value,max_length); }
   // to prevent drop fixed flag (no need parent cleanup call)
   void cleanup() {}
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   Item_num *neg() { value= -value; return this; }
   uint decimal_precision() const
   { return (uint)(max_length - test(value < 0)); }
@@ -1723,7 +1731,7 @@ public:
   String *val_str(String*);
   Item *clone_item() { return new Item_uint(name, value, max_length); }
   int save_in_field(Field *field, bool no_conversions);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   Item_num *neg ();
   uint decimal_precision() const { return max_length; }
   bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
@@ -1759,7 +1767,7 @@ public:
   }
   // to prevent drop fixed flag (no need parent cleanup call)
   void cleanup() {}
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   Item_num *neg()
   {
     my_decimal_neg(&decimal_value);
@@ -1818,7 +1826,7 @@ public:
   Item *clone_item()
   { return new Item_float(name, value, decimals, max_length); }
   Item_num *neg() { value= -value; return this; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool eq(const Item *, bool binary_cmp) const;
 };
 
@@ -1831,7 +1839,12 @@ public:
                         uint length)
     :Item_float(NullS, val_arg, decimal_par, length), func_name(str)
   {}
-  void print(String *str) { str->append(func_name); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    str->append(func_name);
+  }
+
   Item *safe_charset_converter(CHARSET_INFO *tocs);
 };
 
@@ -1922,7 +1935,7 @@ public:
     str_value.append(str, length);
     max_length= str_value.numchars() * collation.collation->mbmaxlen;
   }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   // to prevent drop fixed flag (no need parent cleanup call)
   void cleanup() {}
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
@@ -1981,7 +1994,12 @@ public:
     :Item_string(NullS, str, length, cs, dv), func_name(name_par)
   {}
   Item *safe_charset_converter(CHARSET_INFO *tocs);
-  void print(String *str) { str->append(func_name); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    str->append(func_name);
+  }
+
   bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
 };
 
@@ -2071,7 +2089,7 @@ public:
   enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
   // to prevent drop fixed flag (no need parent cleanup call)
   void cleanup() {}
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool eq(const Item *item, bool binary_cmp) const;
   virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
@@ -2192,7 +2210,7 @@ public:
   }
   bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
   { return (*ref)->walk(processor, walk_subquery, arg); }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool result_as_longlong()
   {
     return (*ref)->result_as_longlong();
@@ -2339,7 +2357,7 @@ public:
   my_decimal *val_decimal(my_decimal *);
   bool val_bool();
   bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   /*
     we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
   */
@@ -2514,7 +2532,7 @@ public:
   enum Type type() const { return DEFAULT_VALUE_ITEM; }
   bool eq(const Item *item, bool binary_cmp) const;
   bool fix_fields(THD *, Item **);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   int save_in_field(Field *field_arg, bool no_conversions);
   table_map used_tables() const { return (table_map)0L; }
 
@@ -2547,7 +2565,7 @@ public:
      arg(a) {}
   bool eq(const Item *item, bool binary_cmp) const;
   bool fix_fields(THD *, Item **);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   int save_in_field(Field *field_arg, bool no_conversions)
   {
     return Item_field::save_in_field(field_arg, no_conversions);
@@ -2618,7 +2636,7 @@ public:
   enum Type type() const { return TRIGGER_FIELD_ITEM; }
   bool eq(const Item *item, bool binary_cmp) const;
   bool fix_fields(THD *, Item **);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   table_map used_tables() const { return (table_map)0L; }
   Field *get_tmp_table_field() { return 0; }
   Item *copy_or_same(THD *thd) { return this; }
@@ -2711,7 +2729,7 @@ public:
   virtual void keep_array() {}
   // to prevent drop fixed flag (no need parent cleanup call)
   void cleanup() {}
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool eq_def(Field *field) 
   { 
     return cached_field ? cached_field->eq_def (field) : FALSE;
diff -Nrup a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
--- a/sql/item_cmpfunc.cc	2008-02-08 18:55:02 +03:00
+++ b/sql/item_cmpfunc.cc	2008-02-22 13:30:30 +03:00
@@ -286,10 +286,10 @@ longlong Item_func_not::val_int()
   higher than the precedence of NOT.
 */
 
-void Item_func_not::print(String *str)
+void Item_func_not::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  Item_func::print(str);
+  Item_func::print(str, query_type);
   str->append(')');
 }
 
@@ -321,12 +321,12 @@ bool Item_func_not_all::empty_underlying
           (test_sub_item && !test_sub_item->any_value()));
 }
 
-void Item_func_not_all::print(String *str)
+void Item_func_not_all::print(String *str, enum_query_type query_type)
 {
   if (show)
-    Item_func::print(str);
+    Item_func::print(str, query_type);
   else
-    args[0]->print(str);
+    args[0]->print(str, query_type);
 }
 
 
@@ -1422,10 +1422,10 @@ void Item_func_truth::fix_length_and_dec
 }
 
 
-void Item_func_truth::print(String *str)
+void Item_func_truth::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" is "));
   if (! affirmative)
     str->append(STRING_WITH_LEN("not "));
@@ -2109,16 +2109,16 @@ longlong Item_func_between::val_int()
 }
 
 
-void Item_func_between::print(String *str)
+void Item_func_between::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   if (negated)
     str->append(STRING_WITH_LEN(" not"));
   str->append(STRING_WITH_LEN(" between "));
-  args[1]->print(str);
+  args[1]->print(str, query_type);
   str->append(STRING_WITH_LEN(" and "));
-  args[2]->print(str);
+  args[2]->print(str, query_type);
   str->append(')');
 }
 
@@ -2763,26 +2763,26 @@ uint Item_func_case::decimal_precision()
     Fix this so that it prints the whole CASE expression
 */
 
-void Item_func_case::print(String *str)
+void Item_func_case::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("(case "));
   if (first_expr_num != -1)
   {
-    args[first_expr_num]->print(str);
+    args[first_expr_num]->print(str, query_type);
     str->append(' ');
   }
   for (uint i=0 ; i < ncases ; i+=2)
   {
     str->append(STRING_WITH_LEN("when "));
-    args[i]->print(str);
+    args[i]->print(str, query_type);
     str->append(STRING_WITH_LEN(" then "));
-    args[i+1]->print(str);
+    args[i+1]->print(str, query_type);
     str->append(' ');
   }
   if (else_expr_num != -1)
   {
     str->append(STRING_WITH_LEN("else "));
-    args[else_expr_num]->print(str);
+    args[else_expr_num]->print(str, query_type);
     str->append(' ');
   }
   str->append(STRING_WITH_LEN("end)"));
@@ -3706,14 +3706,14 @@ void Item_func_in::fix_length_and_dec()
 }
 
 
-void Item_func_in::print(String *str)
+void Item_func_in::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   if (negated)
     str->append(STRING_WITH_LEN(" not"));
   str->append(STRING_WITH_LEN(" in ("));
-  print_args(str, 1);
+  print_args(str, 1, query_type);
   str->append(STRING_WITH_LEN("))"));
 }
 
@@ -4084,19 +4084,19 @@ void Item_cond::update_used_tables()
 }
 
 
-void Item_cond::print(String *str)
+void Item_cond::print(String *str, enum_query_type query_type)
 {
   str->append('(');
   List_iterator_fast<Item> li(list);
   Item *item;
   if ((item=li++))
-    item->print(str);
+    item->print(str, query_type);
   while ((item=li++))
   {
     str->append(' ');
     str->append(func_name());
     str->append(' ');
-    item->print(str);
+    item->print(str, query_type);
   }
   str->append(')');
 }
@@ -4279,10 +4279,10 @@ longlong Item_func_isnotnull::val_int()
 }
 
 
-void Item_func_isnotnull::print(String *str)
+void Item_func_isnotnull::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" is not null)"));
 }
 
@@ -5276,24 +5276,24 @@ Item *Item_equal::transform(Item_transfo
   return Item_func::transform(transformer, arg);
 }
 
-void Item_equal::print(String *str)
+void Item_equal::print(String *str, enum_query_type query_type)
 {
   str->append(func_name());
   str->append('(');
   List_iterator_fast<Item_field> it(fields);
   Item *item;
   if (const_item)
-    const_item->print(str);
+    const_item->print(str, query_type);
   else
   {
     item= it++;
-    item->print(str);
+    item->print(str, query_type);
   }
   while ((item= it++))
   {
     str->append(',');
     str->append(' ');
-    item->print(str);
+    item->print(str, query_type);
   }
   str->append(')');
 }
diff -Nrup a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
--- a/sql/item_cmpfunc.h	2008-02-01 13:50:17 +03:00
+++ b/sql/item_cmpfunc.h	2008-02-22 13:30:30 +03:00
@@ -123,7 +123,7 @@ public:
   virtual bool val_bool();
   virtual longlong val_int();
   virtual void fix_length_and_dec();
-  virtual void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 
 protected:
   Item_func_truth(Item *a, bool a_value, bool a_affirmative)
@@ -338,7 +338,12 @@ public:
   optimize_type select_optimize() const { return OPTIMIZE_OP; }
   virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; }
   bool have_rev_func() const { return rev_functype() != UNKNOWN_FUNC; }
-  void print(String *str) { Item_func::print_op(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    Item_func::print_op(str, query_type);
+  }
+
   bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); }
   bool is_bool_func() { return 1; }
   CHARSET_INFO *compare_collation() { return cmp.cmp_collation.collation; }
@@ -368,7 +373,7 @@ public:
   enum Functype functype() const { return NOT_FUNC; }
   const char *func_name() const { return "not"; }
   Item *neg_transformer(THD *thd);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 class Item_maxmin_subselect;
@@ -433,7 +438,7 @@ public:
   longlong val_int();
   enum Functype functype() const { return NOT_ALL_FUNC; }
   const char *func_name() const { return "<not>"; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; };
   void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; };
   bool empty_underlying_subquery();
@@ -594,7 +599,7 @@ public:
   const char *func_name() const { return "between"; }
   bool fix_fields(THD *, Item **);
   void fix_length_and_dec();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool is_bool_func() { return 1; }
   CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
   uint decimal_precision() const { return 1; }
@@ -608,7 +613,11 @@ public:
   longlong val_int();
   optimize_type select_optimize() const { return OPTIMIZE_NONE; }
   const char *func_name() const { return "strcmp"; }
-  void print(String *str) { Item_func::print(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    Item_func::print(str, query_type);
+  }
 };
 
 
@@ -711,7 +720,12 @@ public:
   void fix_length_and_dec();
   uint decimal_precision() const { return args[0]->decimal_precision(); }
   const char *func_name() const { return "nullif"; }
-  void print(String *str) { Item_func::print(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    Item_func::print(str, query_type);
+  }
+
   table_map not_null_tables() const { return 0; }
   bool is_null();
 };
@@ -1141,7 +1155,7 @@ public:
   enum Item_result result_type () const { return cached_result_type; }
   enum_field_types field_type() const { return cached_field_type; }
   const char *func_name() const { return "case"; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   Item *find_item(String *str);
   CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
   void cleanup();
@@ -1208,7 +1222,7 @@ public:
   }
   optimize_type select_optimize() const
     { return OPTIMIZE_KEY; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   enum Functype functype() const { return IN_FUNC; }
   const char *func_name() const { return " IN "; }
   bool nulls_in_row();
@@ -1330,7 +1344,7 @@ public:
   table_map not_null_tables() const
   { return abort_on_null ? not_null_tables_cache : 0; }
   Item *neg_transformer(THD *thd);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
   void top_level_item() { abort_on_null=1; }
 };
@@ -1395,7 +1409,12 @@ public:
   longlong val_int();
   bool fix_fields(THD *thd, Item **ref);
   const char *func_name() const { return "regexp"; }
-  void print(String *str) { print_op(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    print_op(str, query_type);
+  }
+
   CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
 };
 
@@ -1407,7 +1426,11 @@ public:
   Item_func_regex(Item *a,Item *b) :Item_bool_func(a,b) {}
   longlong val_int() { return 0;}
   const char *func_name() const { return "regex"; }
-  void print(String *str) { print_op(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    print_op(str, query_type);
+  }
 };
 
 #endif /* USE_REGEX */
@@ -1444,7 +1467,7 @@ public:
   List<Item>* argument_list() { return &list; }
   table_map used_tables() const;
   void update_used_tables();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
   friend int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
                          COND **conds);
@@ -1568,7 +1591,7 @@ public:
   void update_used_tables();
   bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
   Item *transform(Item_transformer transformer, uchar *arg);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   CHARSET_INFO *compare_collation() 
   { return fields.head()->collation.collation; }
 }; 
diff -Nrup a/sql/item_func.cc b/sql/item_func.cc
--- a/sql/item_func.cc	2008-01-25 20:14:58 +03:00
+++ b/sql/item_func.cc	2008-02-22 13:30:30 +03:00
@@ -374,37 +374,37 @@ table_map Item_func::not_null_tables() c
 }
 
 
-void Item_func::print(String *str)
+void Item_func::print(String *str, enum_query_type query_type)
 {
   str->append(func_name());
   str->append('(');
-  print_args(str, 0);
+  print_args(str, 0, query_type);
   str->append(')');
 }
 
 
-void Item_func::print_args(String *str, uint from)
+void Item_func::print_args(String *str, uint from, enum_query_type query_type)
 {
   for (uint i=from ; i < arg_count ; i++)
   {
     if (i != from)
       str->append(',');
-    args[i]->print(str);
+    args[i]->print(str, query_type);
   }
 }
 
 
-void Item_func::print_op(String *str)
+void Item_func::print_op(String *str, enum_query_type query_type)
 {
   str->append('(');
   for (uint i=0 ; i < arg_count-1 ; i++)
   {
-    args[i]->print(str);
+    args[i]->print(str, query_type);
     str->append(' ');
     str->append(func_name());
     str->append(' ');
   }
-  args[arg_count-1]->print(str);
+  args[arg_count-1]->print(str, query_type);
   str->append(')');
 }
 
@@ -884,10 +884,10 @@ my_decimal *Item_func_numhybrid::val_dec
 }
 
 
-void Item_func_signed::print(String *str)
+void Item_func_signed::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("cast("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" as signed)"));
 
 }
@@ -955,10 +955,10 @@ longlong Item_func_signed::val_int()
 }
 
 
-void Item_func_unsigned::print(String *str)
+void Item_func_unsigned::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("cast("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" as unsigned)"));
 
 }
@@ -1064,7 +1064,7 @@ err:
 }
 
 
-void Item_decimal_typecast::print(String *str)
+void Item_decimal_typecast::print(String *str, enum_query_type query_type)
 {
   char len_buf[20*3 + 1];
   char *end;
@@ -1072,7 +1072,7 @@ void Item_decimal_typecast::print(String
   uint precision= my_decimal_length_to_precision(max_length, decimals,
                                                  unsigned_flag);
   str->append(STRING_WITH_LEN("cast("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" as decimal("));
 
   end=int10_to_str(precision, len_buf,10);
@@ -2537,16 +2537,16 @@ longlong Item_func_locate::val_int()
 }
 
 
-void Item_func_locate::print(String *str)
+void Item_func_locate::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("locate("));
-  args[1]->print(str);
+  args[1]->print(str, query_type);
   str->append(',');
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   if (arg_count == 3)
   {
     str->append(',');
-    args[2]->print(str);
+    args[2]->print(str, query_type);
   }
   str->append(')');
 }
@@ -3095,7 +3095,7 @@ void Item_udf_func::cleanup()
 }
 
 
-void Item_udf_func::print(String *str)
+void Item_udf_func::print(String *str, enum_query_type query_type)
 {
   str->append(func_name());
   str->append('(');
@@ -3103,7 +3103,7 @@ void Item_udf_func::print(String *str)
   {
     if (i != 0)
       str->append(',');
-    args[i]->print_item_w_name(str);
+    args[i]->print_item_w_name(str, query_type);
   }
   str->append(')');
 }
@@ -3683,12 +3683,12 @@ longlong Item_func_benchmark::val_int()
 }
 
 
-void Item_func_benchmark::print(String *str)
+void Item_func_benchmark::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("benchmark("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(',');
-  args[1]->print(str);
+  args[1]->print(str, query_type);
   str->append(')');
 }
 
@@ -4264,22 +4264,23 @@ my_decimal *Item_func_set_user_var::val_
 }
 
 
-void Item_func_set_user_var::print(String *str)
+void Item_func_set_user_var::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("(@"));
   str->append(name.str, name.length);
   str->append(STRING_WITH_LEN(":="));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(')');
 }
 
 
-void Item_func_set_user_var::print_as_stmt(String *str)
+void Item_func_set_user_var::print_as_stmt(String *str,
+                                           enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("set @"));
   str->append(name.str, name.length);
   str->append(STRING_WITH_LEN(":="));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(')');
 }
 
@@ -4652,7 +4653,7 @@ enum Item_result Item_func_get_user_var:
 }
 
 
-void Item_func_get_user_var::print(String *str)
+void Item_func_get_user_var::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("(@"));
   str->append(name.str,name.length);
@@ -4750,7 +4751,7 @@ my_decimal* Item_user_var_as_out_param::
 }
 
 
-void Item_user_var_as_out_param::print(String *str)
+void Item_user_var_as_out_param::print(String *str, enum_query_type query_type)
 {
   str->append('@');
   str->append(name.str,name.length);
@@ -5089,12 +5090,12 @@ double Item_func_match::val_real()
                                                  table->record[0], 0));
 }
 
-void Item_func_match::print(String *str)
+void Item_func_match::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("(match "));
-  print_args(str, 1);
+  print_args(str, 1, query_type);
   str->append(STRING_WITH_LEN(" against ("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   if (flags & FT_BOOL)
     str->append(STRING_WITH_LEN(" in boolean mode"));
   else if (flags & FT_EXPAND)
@@ -5505,7 +5506,7 @@ Item_result
 Item_func_sp::result_type() const
 {
   DBUG_ENTER("Item_func_sp::result_type");
-  DBUG_PRINT("info", ("m_sp = %p", m_sp));
+  DBUG_PRINT("info", ("m_sp = %p", (void *) m_sp));
   DBUG_ASSERT(sp_result_field);
   DBUG_RETURN(sp_result_field->result_type());
 }
diff -Nrup a/sql/item_func.h b/sql/item_func.h
--- a/sql/item_func.h	2007-12-13 14:57:03 +03:00
+++ b/sql/item_func.h	2008-02-22 13:30:30 +03:00
@@ -140,9 +140,9 @@ public:
   inline uint argument_count() const { return arg_count; }
   inline void remove_arguments() { arg_count=0; }
   void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
-  void print(String *str);
-  void print_op(String *str);
-  void print_args(String *str, uint from);
+  virtual void print(String *str, enum_query_type query_type);
+  void print_op(String *str, enum_query_type query_type);
+  void print_args(String *str, uint from, enum_query_type query_type);
   virtual void fix_num_length_and_dec();
   void count_only_length();
   void count_real_length();
@@ -293,7 +293,12 @@ class Item_num_op :public Item_func_numh
  public:
   Item_num_op(Item *a,Item *b) :Item_func_numhybrid(a, b) {}
   virtual void result_precision()= 0;
-  void print(String *str) { print_op(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    print_op(str, query_type);
+  }
+
   void find_num_type();
   String *str_op(String *str) { DBUG_ASSERT(0); return 0; }
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
@@ -339,7 +344,7 @@ public:
   longlong val_int_from_str(int *error);
   void fix_length_and_dec()
   { max_length=args[0]->max_length; unsigned_flag=0; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   uint decimal_precision() const { return args[0]->decimal_precision(); }
 };
 
@@ -352,7 +357,7 @@ public:
   void fix_length_and_dec()
   { max_length=args[0]->max_length; unsigned_flag=1; }
   longlong val_int();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -373,7 +378,7 @@ public:
   enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
   void fix_length_and_dec() {};
   const char *func_name() const { return "decimal_typecast"; }
-  void print(String *);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -441,7 +446,12 @@ public:
   longlong val_int();
   const char *func_name() const { return "DIV"; }
   void fix_length_and_dec();
-  void print(String *str) { print_op(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    print_op(str, query_type);
+  }
+
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
 };
 
@@ -843,7 +853,7 @@ public:
   const char *func_name() const { return "locate"; }
   longlong val_int();
   void fix_length_and_dec();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -900,7 +910,11 @@ public:
   Item_func_bit(Item *a, Item *b) :Item_int_func(a, b) {}
   Item_func_bit(Item *a) :Item_int_func(a) {}
   void fix_length_and_dec() { unsigned_flag= 1; }
-  void print(String *str) { print_op(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    print_op(str, query_type);
+  }
 };
 
 class Item_func_bit_or :public Item_func_bit
@@ -950,7 +964,11 @@ public:
   Item_func_bit_neg(Item *a) :Item_func_bit(a) {}
   longlong val_int();
   const char *func_name() const { return "~"; }
-  void print(String *str) { Item_func::print(str); }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    Item_func::print(str, query_type);
+  }
 };
 
 
@@ -979,7 +997,7 @@ public:
   longlong val_int();
   const char *func_name() const { return "benchmark"; }
   void fix_length_and_dec() { max_length=1; maybe_null=0; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -1076,7 +1094,7 @@ public:
   Item_result result_type () const { return udf.result_type(); }
   table_map not_null_tables() const { return 0; }
   bool is_expensive() { return 1; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -1313,8 +1331,8 @@ public:
   enum Item_result result_type () const { return cached_result_type; }
   bool fix_fields(THD *thd, Item **ref);
   void fix_length_and_dec();
-  void print(String *str);
-  void print_as_stmt(String *str);
+  virtual void print(String *str, enum_query_type query_type);
+  void print_as_stmt(String *str, enum_query_type query_type);
   const char *func_name() const { return "set_user_var"; }
   int save_in_field(Field *field, bool no_conversions,
                     bool can_use_result_field);
@@ -1344,7 +1362,7 @@ public:
   my_decimal *val_decimal(my_decimal*);
   String *val_str(String* str);
   void fix_length_and_dec();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   enum Item_result result_type() const;
   /*
     We must always return variables as strings to guard against selects of type
@@ -1389,7 +1407,7 @@ public:
   my_decimal *val_decimal(my_decimal *decimal_buffer);
   /* fix_fields() binds variable name with its entry structure */
   bool fix_fields(THD *thd, Item **ref);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   void set_null_value(CHARSET_INFO* cs);
   void set_value(const char *str, uint length, CHARSET_INFO* cs);
 };
@@ -1467,7 +1485,7 @@ public:
   /* The following should be safe, even if we compare doubles */
   longlong val_int() { DBUG_ASSERT(fixed == 1); return val_real() != 0.0; }
   double val_real();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 
   bool fix_index();
   void init_search(bool no_order);
diff -Nrup a/sql/item_geofunc.h b/sql/item_geofunc.h
--- a/sql/item_geofunc.h	2007-10-12 14:31:18 +04:00
+++ b/sql/item_geofunc.h	2008-02-22 13:30:30 +03:00
@@ -224,8 +224,13 @@ public:
       DBUG_ASSERT(0);  // Should never happened
       return "sp_unknown"; 
     }
-    }
-  void print(String *str) { Item_func::print(str); }
+  }
+
+  virtual inline void print(String *str, enum_query_type query_type)
+  {
+    Item_func::print(str, query_type);
+  }
+
   void fix_length_and_dec() { maybe_null= 1; }
   bool is_null() { (void) val_int(); return null_value; }
 };
diff -Nrup a/sql/item_row.cc b/sql/item_row.cc
--- a/sql/item_row.cc	2007-10-11 21:29:05 +04:00
+++ b/sql/item_row.cc	2008-02-22 13:30:30 +03:00
@@ -134,14 +134,14 @@ bool Item_row::check_cols(uint c)
   return 0;
 }
 
-void Item_row::print(String *str)
+void Item_row::print(String *str, enum_query_type query_type)
 {
   str->append('(');
   for (uint i= 0; i < arg_count; i++)
   {
     if (i)
       str->append(',');
-    items[i]->print(str);
+    items[i]->print(str, query_type);
   }
   str->append(')');
 }
diff -Nrup a/sql/item_row.h b/sql/item_row.h
--- a/sql/item_row.h	2007-05-10 13:59:27 +04:00
+++ b/sql/item_row.h	2008-02-22 13:30:30 +03:00
@@ -65,7 +65,7 @@ public:
   bool const_item() const { return const_item_cache; };
   enum Item_result result_type() const { return ROW_RESULT; }
   void update_used_tables();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 
   bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
   Item *transform(Item_transformer transformer, uchar *arg);
diff -Nrup a/sql/item_strfunc.cc b/sql/item_strfunc.cc
--- a/sql/item_strfunc.cc	2007-12-14 18:33:33 +03:00
+++ b/sql/item_strfunc.cc	2008-02-22 13:30:30 +03:00
@@ -1594,20 +1594,20 @@ void Item_func_trim::fix_length_and_dec(
   }
 }
 
-void Item_func_trim::print(String *str)
+void Item_func_trim::print(String *str, enum_query_type query_type)
 {
   if (arg_count == 1)
   {
-    Item_func::print(str);
+    Item_func::print(str, query_type);
     return;
   }
   str->append(Item_func_trim::func_name());
   str->append('(');
   str->append(mode_name());
   str->append(' ');
-  args[1]->print(str);
+  args[1]->print(str, query_type);
   str->append(STRING_WITH_LEN(" from "));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(')');
 }
 
@@ -2116,12 +2116,12 @@ String *Item_func_format::val_str(String
 }
 
 
-void Item_func_format::print(String *str)
+void Item_func_format::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("format("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(',');
-  args[1]->print(str);
+  args[1]->print(str, query_type);
   str->append(')');
 }
 
@@ -2292,14 +2292,14 @@ Item *Item_func_make_set::transform(Item
 }
 
 
-void Item_func_make_set::print(String *str)
+void Item_func_make_set::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("make_set("));
-  item->print(str);
+  item->print(str, query_type);
   if (arg_count)
   {
     str->append(',');
-    print_args(str, 0);
+    print_args(str, 0, query_type);
   }
   str->append(')');
 }
@@ -2710,10 +2710,10 @@ void Item_func_conv_charset::fix_length_
   max_length = args[0]->max_length*conv_charset->mbmaxlen;
 }
 
-void Item_func_conv_charset::print(String *str)
+void Item_func_conv_charset::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("convert("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" using "));
   str->append(conv_charset->csname);
   str->append(')');
@@ -2781,10 +2781,10 @@ bool Item_func_set_collation::eq(const I
 }
 
 
-void Item_func_set_collation::print(String *str)
+void Item_func_set_collation::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" collate "));
   DBUG_ASSERT(args[1]->basic_const_item() &&
               args[1]->type() == Item::STRING_ITEM);
@@ -2903,10 +2903,10 @@ String *Item_func_unhex::val_str(String 
 }
 
 
-void Item_func_binary::print(String *str)
+void Item_func_binary::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("cast("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" as binary)"));
 }
 
diff -Nrup a/sql/item_strfunc.h b/sql/item_strfunc.h
--- a/sql/item_strfunc.h	2008-02-01 13:50:17 +03:00
+++ b/sql/item_strfunc.h	2008-02-22 13:30:30 +03:00
@@ -225,7 +225,7 @@ public:
   String *val_str(String *);
   void fix_length_and_dec();
   const char *func_name() const { return "trim"; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   virtual const char *mode_name() const { return "both"; }
 };
 
@@ -482,7 +482,7 @@ public:
       Item_str_func::walk(processor, walk_subquery, arg);
   }
   Item *transform(Item_transformer transformer, uchar *arg);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -494,7 +494,7 @@ public:
   String *val_str(String *);
   void fix_length_and_dec();
   const char *func_name() const { return "format"; }
-  void print(String *);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -617,7 +617,7 @@ public:
     collation.set(&my_charset_bin);
     max_length=args[0]->max_length;
   }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   const char *func_name() const { return "cast_as_binary"; }
 };
 
@@ -719,7 +719,7 @@ public:
   String *val_str(String *);
   void fix_length_and_dec();
   const char *func_name() const { return "convert"; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 class Item_func_set_collation :public Item_str_func
@@ -731,7 +731,7 @@ public:
   bool eq(const Item *item, bool binary_cmp) const;
   const char *func_name() const { return "collate"; }
   enum Functype functype() const { return COLLATE_FUNC; }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   Item_field *filed_for_view_update()
   {
     /* this function is transparent for view updating */
diff -Nrup a/sql/item_subselect.cc b/sql/item_subselect.cc
--- a/sql/item_subselect.cc	2007-12-20 23:24:03 +03:00
+++ b/sql/item_subselect.cc	2008-02-22 13:30:30 +03:00
@@ -306,10 +306,10 @@ void Item_subselect::update_used_tables(
 }
 
 
-void Item_subselect::print(String *str)
+void Item_subselect::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  engine->print(str);
+  engine->print(str, query_type);
   str->append(')');
 }
 
@@ -391,10 +391,10 @@ void Item_maxmin_subselect::cleanup()
 }
 
 
-void Item_maxmin_subselect::print(String *str)
+void Item_maxmin_subselect::print(String *str, enum_query_type query_type)
 {
   str->append(max?"<max>":"<min>", 5);
-  Item_singlerow_subselect::print(str);
+  Item_singlerow_subselect::print(str, query_type);
 }
 
 
@@ -630,10 +630,10 @@ Item_exists_subselect::Item_exists_subse
 }
 
 
-void Item_exists_subselect::print(String *str)
+void Item_exists_subselect::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("exists"));
-  Item_subselect::print(str);
+  Item_subselect::print(str, query_type);
 }
 
 
@@ -1553,16 +1553,16 @@ err:
 }
 
 
-void Item_in_subselect::print(String *str)
+void Item_in_subselect::print(String *str, enum_query_type query_type)
 {
   if (transformed)
     str->append(STRING_WITH_LEN("<exists>"));
   else
   {
-    left_expr->print(str);
+    left_expr->print(str, query_type);
     str->append(STRING_WITH_LEN(" in "));
   }
-  Item_subselect::print(str);
+  Item_subselect::print(str, query_type);
 }
 
 
@@ -1587,18 +1587,18 @@ Item_allany_subselect::select_transforme
 }
 
 
-void Item_allany_subselect::print(String *str)
+void Item_allany_subselect::print(String *str, enum_query_type query_type)
 {
   if (transformed)
     str->append(STRING_WITH_LEN("<exists>"));
   else
   {
-    left_expr->print(str);
+    left_expr->print(str, query_type);
     str->append(' ');
     str->append(func->symbol(all));
     str->append(all ? " all " : " any ", 5);
   }
-  Item_subselect::print(str);
+  Item_subselect::print(str, query_type);
 }
 
 
@@ -2384,22 +2384,24 @@ table_map subselect_union_engine::upper_
 }
 
 
-void subselect_single_select_engine::print(String *str)
+void subselect_single_select_engine::print(String *str,
+                                           enum_query_type query_type)
 {
-  select_lex->print(thd, str);
+  select_lex->print(thd, str, query_type);
 }
 
 
-void subselect_union_engine::print(String *str)
+void subselect_union_engine::print(String *str, enum_query_type query_type)
 {
-  unit->print(str);
+  unit->print(str, query_type);
 }
 
 
-void subselect_uniquesubquery_engine::print(String *str)
+void subselect_uniquesubquery_engine::print(String *str,
+                                            enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("<primary_index_lookup>("));
-  tab->ref.items[0]->print(str);
+  tab->ref.items[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" in "));
   str->append(tab->table->s->table_name.str,
tab->table->s->table_name.length);
   KEY *key_info= tab->table->key_info+ tab->ref.key;
@@ -2408,16 +2410,17 @@ void subselect_uniquesubquery_engine::pr
   if (cond)
   {
     str->append(STRING_WITH_LEN(" where "));
-    cond->print(str);
+    cond->print(str, query_type);
   }
   str->append(')');
 }
 
 
-void subselect_indexsubquery_engine::print(String *str)
+void subselect_indexsubquery_engine::print(String *str,
+                                           enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("<index_lookup>("));
-  tab->ref.items[0]->print(str);
+  tab->ref.items[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" in "));
   str->append(tab->table->s->table_name.str,
tab->table->s->table_name.length);
   KEY *key_info= tab->table->key_info+ tab->ref.key;
@@ -2428,12 +2431,12 @@ void subselect_indexsubquery_engine::pri
   if (cond)
   {
     str->append(STRING_WITH_LEN(" where "));
-    cond->print(str);
+    cond->print(str, query_type);
   }
   if (having)
   {
     str->append(STRING_WITH_LEN(" having "));
-    having->print(str);
+    having->print(str, query_type);
   }
   str->append(')');
 }
diff -Nrup a/sql/item_subselect.h b/sql/item_subselect.h
--- a/sql/item_subselect.h	2007-10-30 17:18:38 +03:00
+++ b/sql/item_subselect.h	2008-02-22 13:30:30 +03:00
@@ -103,7 +103,7 @@ public:
   inline bool get_const_item_cache() { return const_item_cache; }
   Item *get_tmp_table_item(THD *thd);
   void update_used_tables();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   virtual bool have_guarded_conds() { return FALSE; }
   bool change_engine(subselect_engine *eng)
   {
@@ -203,7 +203,7 @@ protected:
 public:
   Item_maxmin_subselect(THD *thd, Item_subselect *parent,
 			st_select_lex *select_lex, bool max);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   void cleanup();
   bool any_value() { return was_values; }
   void register_value() { was_values= TRUE; }
@@ -234,7 +234,7 @@ public:
   my_decimal *val_decimal(my_decimal *);
   bool val_bool();
   void fix_length_and_dec();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 
   friend class select_exists_subselect;
   friend class subselect_uniquesubquery_engine;
@@ -312,7 +312,7 @@ public:
   void top_level_item() { abort_on_null=1; }
   inline bool is_top_level_item() { return abort_on_null; }
   bool test_limit(st_select_lex_unit *unit);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool fix_fields(THD *thd, Item **ref);
 
   friend class Item_ref_null_helper;
@@ -335,7 +335,7 @@ public:
   // only ALL subquery has upper not
   subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
   trans_res select_transformer(JOIN *join);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -399,7 +399,7 @@ public:
   virtual bool may_be_null() { return maybe_null; };
   virtual table_map upper_select_const_tables()= 0;
   static table_map calc_const_tables(TABLE_LIST *);
-  virtual void print(String *str)= 0;
+  virtual void print(String *str, enum_query_type query_type)= 0;
   virtual bool change_result(Item_subselect *si, select_subselect *result)= 0;
   virtual bool no_tables()= 0;
   virtual bool is_executed() const { return FALSE; }
@@ -430,7 +430,7 @@ public:
   uint8 uncacheable();
   void exclude();
   table_map upper_select_const_tables();
-  void print (String *str);
+  virtual void print (String *str, enum_query_type query_type);
   bool change_result(Item_subselect *si, select_subselect *result);
   bool no_tables();
   bool may_be_null();
@@ -454,7 +454,7 @@ public:
   uint8 uncacheable();
   void exclude();
   table_map upper_select_const_tables();
-  void print (String *str);
+  virtual void print (String *str, enum_query_type query_type);
   bool change_result(Item_subselect *si, select_subselect *result);
   bool no_tables();
   bool is_executed() const;
@@ -511,7 +511,7 @@ public:
   uint8 uncacheable() { return UNCACHEABLE_DEPENDENT; }
   void exclude();
   table_map upper_select_const_tables() { return 0; }
-  void print (String *str);
+  virtual void print (String *str, enum_query_type query_type);
   bool change_result(Item_subselect *si, select_subselect *result);
   bool no_tables();
   int scan_table();
@@ -565,7 +565,7 @@ public:
      having(having_arg)
   {}
   int exec();
-  void print (String *str);
+  virtual void print (String *str, enum_query_type query_type);
 };
 
 
diff -Nrup a/sql/item_sum.cc b/sql/item_sum.cc
--- a/sql/item_sum.cc	2008-01-25 20:14:58 +03:00
+++ b/sql/item_sum.cc	2008-02-22 13:30:30 +03:00
@@ -359,14 +359,14 @@ void Item_sum::make_field(Send_field *tm
 }
 
 
-void Item_sum::print(String *str)
+void Item_sum::print(String *str, enum_query_type query_type)
 {
   str->append(func_name());
   for (uint i=0 ; i < arg_count ; i++)
   {
     if (i)
       str->append(',');
-    args[i]->print(str);
+    args[i]->print(str, query_type);
   }
   str->append(')');
 }
@@ -2716,7 +2716,7 @@ void Item_udf_sum::cleanup()
 }
 
 
-void Item_udf_sum::print(String *str)
+void Item_udf_sum::print(String *str, enum_query_type query_type)
 {
   str->append(func_name());
   str->append('(');
@@ -2724,7 +2724,7 @@ void Item_udf_sum::print(String *str)
   {
     if (i)
       str->append(',');
-    args[i]->print(str);
+    args[i]->print(str, query_type);
   }
   str->append(')');
 }
@@ -3460,7 +3460,7 @@ String* Item_func_group_concat::val_str(
 }
 
 
-void Item_func_group_concat::print(String *str)
+void Item_func_group_concat::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("group_concat("));
   if (distinct)
@@ -3469,7 +3469,7 @@ void Item_func_group_concat::print(Strin
   {
     if (i)
       str->append(',');
-    args[i]->print(str);
+    args[i]->print(str, query_type);
   }
   if (arg_count_order)
   {
@@ -3478,7 +3478,7 @@ void Item_func_group_concat::print(Strin
     {
       if (i)
         str->append(',');
-      (*order[i]->item)->print(str);
+      (*order[i]->item)->print(str, query_type);
       if (order[i]->asc)
         str->append(STRING_WITH_LEN(" ASC"));
       else
diff -Nrup a/sql/item_sum.h b/sql/item_sum.h
--- a/sql/item_sum.h	2007-12-14 14:40:36 +03:00
+++ b/sql/item_sum.h	2008-02-22 13:30:30 +03:00
@@ -343,7 +343,7 @@ public:  
   }
   virtual bool const_item() const { return forced_const; }
   void make_field(Send_field *field);
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   void fix_num_length_and_dec();
 
   /*
@@ -984,7 +984,7 @@ public:
   void reset_field() {};
   void update_field() {};
   void cleanup();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -1257,7 +1257,7 @@ public:
   String* val_str(String* str);
   Item *copy_or_same(THD* thd);
   void no_rows_in_result() {}
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   virtual bool change_context_processor(uchar *cntx)
     { context= (Name_resolution_context *)cntx; return FALSE; }
 };
diff -Nrup a/sql/item_timefunc.cc b/sql/item_timefunc.cc
--- a/sql/item_timefunc.cc	2008-02-01 13:50:17 +03:00
+++ b/sql/item_timefunc.cc	2008-02-22 13:30:30 +03:00
@@ -2217,23 +2217,23 @@ static const char *interval_names[]=
   "second_microsecond"
 };
 
-void Item_date_add_interval::print(String *str)
+void Item_date_add_interval::print(String *str, enum_query_type query_type)
 {
   str->append('(');
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(date_sub_interval?" - interval ":" + interval ");
-  args[1]->print(str);
+  args[1]->print(str, query_type);
   str->append(' ');
   str->append(interval_names[int_type]);
   str->append(')');
 }
 
-void Item_extract::print(String *str)
+void Item_extract::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("extract("));
   str->append(interval_names[int_type]);
   str->append(STRING_WITH_LEN(" from "));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(')');
 }
 
@@ -2374,20 +2374,20 @@ bool Item_char_typecast::eq(const Item *
   return 1;
 }
 
-void Item_typecast::print(String *str)
+void Item_typecast::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("cast("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" as "));
   str->append(cast_type());
   str->append(')');
 }
 
 
-void Item_char_typecast::print(String *str)
+void Item_char_typecast::print(String *str, enum_query_type query_type)
 {
   str->append(STRING_WITH_LEN("cast("));
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(STRING_WITH_LEN(" as char"));
   if (cast_length >= 0)
   {
@@ -2822,7 +2822,7 @@ null_date:
 }
 
 
-void Item_func_add_time::print(String *str)
+void Item_func_add_time::print(String *str, enum_query_type query_type)
 {
   if (is_date)
   {
@@ -2836,9 +2836,9 @@ void Item_func_add_time::print(String *s
     else
       str->append(STRING_WITH_LEN("subtime("));
   }
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(',');
-  args[1]->print(str);
+  args[1]->print(str, query_type);
   str->append(')');
 }
 
@@ -3083,7 +3083,7 @@ null_date:
 }
 
 
-void Item_func_timestamp_diff::print(String *str)
+void Item_func_timestamp_diff::print(String *str, enum_query_type query_type)
 {
   str->append(func_name());
   str->append('(');
@@ -3123,7 +3123,7 @@ void Item_func_timestamp_diff::print(Str
   for (uint i=0 ; i < 2 ; i++)
   {
     str->append(',');
-    args[i]->print(str);
+    args[i]->print(str, query_type);
   }
   str->append(')');
 }
@@ -3163,7 +3163,7 @@ String *Item_func_get_format::val_str(St
 }
 
 
-void Item_func_get_format::print(String *str)
+void Item_func_get_format::print(String *str, enum_query_type query_type)
 {
   str->append(func_name());
   str->append('(');
@@ -3181,7 +3181,7 @@ void Item_func_get_format::print(String 
   default:
     DBUG_ASSERT(0);
   }
-  args[0]->print(str);
+  args[0]->print(str, query_type);
   str->append(')');
 }
 
diff -Nrup a/sql/item_timefunc.h b/sql/item_timefunc.h
--- a/sql/item_timefunc.h	2008-01-10 14:18:28 +03:00
+++ b/sql/item_timefunc.h	2008-02-22 13:30:30 +03:00
@@ -694,7 +694,7 @@ public:
   longlong val_int();
   bool get_date(MYSQL_TIME *res, uint fuzzy_date);
   bool eq(const Item *item, bool binary_cmp) const;
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -711,7 +711,7 @@ class Item_extract :public Item_int_func
   const char *func_name() const { return "extract"; }
   void fix_length_and_dec();
   bool eq(const Item *item, bool binary_cmp) const;
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
 };
 
@@ -735,7 +735,7 @@ public:
     max_length=args[0]->max_length;
   }
   virtual const char* cast_type() const= 0;
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -767,7 +767,7 @@ public:
   const char* cast_type() const { return "char"; };
   String *val_str(String *a);
   void fix_length_and_dec();
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -901,7 +901,7 @@ public:
   {
     return tmp_table_field_from_field_type(table, 0);
   }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
   const char *func_name() const { return "add_time"; }
   double val_real() { return val_real_from_decimal(); }
   my_decimal *val_decimal(my_decimal *decimal_value)
@@ -977,7 +977,7 @@ public:
     decimals=0;
     maybe_null=1;
   }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
@@ -1001,7 +1001,7 @@ public:
     decimals=0;
     max_length=17*MY_CHARSET_BIN_MB_MAXLEN;
   }
-  void print(String *str);
+  virtual void print(String *str, enum_query_type query_type);
 };
 
 
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h	2008-02-08 18:55:02 +03:00
+++ b/sql/mysql_priv.h	2008-02-22 13:30:30 +03:00
@@ -44,6 +44,19 @@
 #include "sql_plugin.h"
 #include "scheduler.h"
 
+/**
+  Query type constants.
+
+  QT_ORDINARY -- ordinary SQL query.
+  QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without
+  character set introducers).
+*/
+enum enum_query_type
+{
+  QT_ORDINARY,
+  QT_IS
+};
+
 /* TODO convert all these three maps to Bitmap classes */
 typedef ulonglong table_map;          /* Used for table bits in join */
 #if MAX_INDEXES <= 64
@@ -1708,7 +1721,7 @@ bool mysql_manager_submit(void (*action)
 
 /* sql_test.cc */
 #ifndef DBUG_OFF
-void print_where(COND *cond,const char *info);
+void print_where(COND *cond,const char *info, enum_query_type query_type);
 void print_cached_tables(void);
 void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
 void print_plan(JOIN* join,uint idx, double record_count, double read_time,
diff -Nrup a/sql/sp_head.cc b/sql/sp_head.cc
--- a/sql/sp_head.cc	2008-02-19 15:57:58 +03:00
+++ b/sql/sp_head.cc	2008-02-22 13:30:30 +03:00
@@ -2933,7 +2933,7 @@ sp_instr_set::print(String *str)
   }
   str->qs_append(m_offset);
   str->qs_append(' ');
-  m_value->print(str);
+  m_value->print(str, QT_ORDINARY);
 }
 
 
@@ -2961,9 +2961,9 @@ void
 sp_instr_set_trigger_field::print(String *str)
 {
   str->append(STRING_WITH_LEN("set_trigger_field "));
-  trigger_field->print(str);
+  trigger_field->print(str, QT_ORDINARY);
   str->append(STRING_WITH_LEN(":="));
-  value->print(str);
+  value->print(str, QT_ORDINARY);
 }
 
 /*
@@ -3089,7 +3089,7 @@ sp_instr_jump_if_not::print(String *str)
   str->qs_append('(');
   str->qs_append(m_cont_dest);
   str->qs_append(STRING_WITH_LEN(") "));
-  m_expr->print(str);
+  m_expr->print(str, QT_ORDINARY);
 }
 
 
@@ -3177,7 +3177,7 @@ sp_instr_freturn::print(String *str)
   str->qs_append(STRING_WITH_LEN("freturn "));
   str->qs_append((uint)m_type);
   str->qs_append(' ');
-  m_value->print(str);
+  m_value->print(str, QT_ORDINARY);
 }
 
 /*
@@ -3665,7 +3665,7 @@ sp_instr_set_case_expr::print(String *st
   str->qs_append(STRING_WITH_LEN(") "));
   str->qs_append(m_case_expr_id);
   str->qs_append(' ');
-  m_case_expr->print(str);
+  m_case_expr->print(str, QT_ORDINARY);
 }
 
 uint
diff -Nrup a/sql/sql_lex.cc b/sql/sql_lex.cc
--- a/sql/sql_lex.cc	2007-12-20 23:24:05 +03:00
+++ b/sql/sql_lex.cc	2008-02-22 13:30:30 +03:00
@@ -1947,7 +1947,7 @@ bool st_select_lex::setup_ref_array(THD 
 }
 
 
-void st_select_lex_unit::print(String *str)
+void st_select_lex_unit::print(String *str, enum_query_type query_type)
 {
   bool union_all= !union_distinct;
   for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
@@ -1962,7 +1962,7 @@ void st_select_lex_unit::print(String *s
     }
     if (sl->braces)
       str->append('(');
-    sl->print(thd, str);
+    sl->print(thd, str, query_type);
     if (sl->braces)
       str->append(')');
   }
@@ -1971,16 +1971,19 @@ void st_select_lex_unit::print(String *s
     if (fake_select_lex->order_list.elements)
     {
       str->append(STRING_WITH_LEN(" order by "));
-      fake_select_lex->print_order(str,
-				   (ORDER *) fake_select_lex->
-				   order_list.first);
+      fake_select_lex->print_order(
+        str,
+        (ORDER *) fake_select_lex->order_list.first,
+        query_type);
     }
-    fake_select_lex->print_limit(thd, str);
+    fake_select_lex->print_limit(thd, str, query_type);
   }
 }
 
 
-void st_select_lex::print_order(String *str, ORDER *order)
+void st_select_lex::print_order(String *str,
+                                ORDER *order,
+                                enum_query_type query_type)
 {
   for (; order; order= order->next)
   {
@@ -1991,7 +1994,7 @@ void st_select_lex::print_order(String *
       str->append(buffer, length);
     }
     else
-      (*order->item)->print(str);
+      (*order->item)->print(str, query_type);
     if (!order->asc)
       str->append(STRING_WITH_LEN(" desc"));
     if (order->next)
@@ -2000,7 +2003,9 @@ void st_select_lex::print_order(String *
 }
  
 
-void st_select_lex::print_limit(THD *thd, String *str)
+void st_select_lex::print_limit(THD *thd,
+                                String *str,
+                                enum_query_type query_type)
 {
   SELECT_LEX_UNIT *unit= master_unit();
   Item_subselect *item= unit->item;
@@ -2019,10 +2024,10 @@ void st_select_lex::print_limit(THD *thd
     str->append(STRING_WITH_LEN(" limit "));
     if (offset_limit)
     {
-      offset_limit->print(str);
+      offset_limit->print(str, query_type);