List:Internals« Previous MessageNext Message »
From:sanja Date:July 15 2005 9:17pm
Subject:bk commit into 5.0 tree (bell:1.1950)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of bell. When bell 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
  1.1950 05/07/16 00:17:05 bell@stripped +12 -0
  Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-5.0
  into  sanja.is.com.ua:/home/bell/mysql/bk/work-bug6-5.0

  sql/sql_class.h
    1.249 05/07/16 00:17:01 bell@stripped +0 -0
    merge

  sql/item_cmpfunc.cc
    1.163 05/07/16 00:17:01 bell@stripped +6 -6
    merge

  mysql-test/t/view.test
    1.87 05/07/16 00:17:01 bell@stripped +0 -0
    merge

  mysql-test/t/sp-security.test
    1.18 05/07/16 00:17:01 bell@stripped +30 -29
    merge

  mysql-test/r/view.result
    1.92 05/07/16 00:17:01 bell@stripped +0 -0
    merge

  mysql-test/r/sp-security.result
    1.16 05/07/16 00:17:01 bell@stripped +17 -17
    merge

  sql/sql_yacc.yy
    1.406 05/07/16 00:06:12 bell@stripped +0 -0
    Auto merged

  sql/item_strfunc.h
    1.96 05/07/16 00:06:12 bell@stripped +0 -0
    Auto merged

  sql/item_strfunc.cc
    1.242 05/07/16 00:06:12 bell@stripped +0 -0
    Auto merged

  sql/item.h
    1.153 05/07/16 00:06:12 bell@stripped +0 -0
    Auto merged

  sql/item.cc
    1.155 05/07/16 00:06:12 bell@stripped +0 -0
    Auto merged

  BitKeeper/etc/config
    1.15 05/07/16 00:06:12 bell@stripped +0 -1
    Auto merged

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	bell
# Host:	sanja.is.com.ua
# Root:	/home/bell/mysql/bk/work-bug6-5.0/RESYNC

--- 1.154/sql/item.cc	2005-07-14 15:47:58 +03:00
+++ 1.155/sql/item.cc	2005-07-16 00:06:12 +03:00
@@ -663,6 +663,33 @@
 }
 
 
+Item *Item_static_string_func::safe_charset_converter(CHARSET_INFO *tocs)
+{
+  Item_string *conv;
+  uint conv_errors;
+  String tmp, cstr, *ostr= val_str(&tmp);
+  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
+  if (conv_errors ||
+      !(conv= new Item_static_string_func(func_name,
+                                          cstr.ptr(), cstr.length(),
+                                          cstr.charset(),
+                                          collation.derivation)))
+  {
+    /*
+      Safe conversion is not possible (or EOM).
+      We could not convert a string into the requested character set
+      without data loss. The target charset does not cover all the
+      characters from the string. Operation cannot be done correctly.
+    */
+    return NULL;
+  }
+  conv->str_value.copy();
+  /* Ensure that no one is going to change the result string */
+  conv->str_value.mark_as_const();
+  return conv;
+}
+
+
 bool Item_string::eq(const Item *item, bool binary_cmp) const
 {
   if (type() == item->type() && item->basic_const_item())

--- 1.152/sql/item.h	2005-07-14 14:01:40 +03:00
+++ 1.153/sql/item.h	2005-07-16 00:06:12 +03:00
@@ -1314,6 +1314,7 @@
                           Derivation dv= DERIVATION_COERCIBLE)
     :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); }
 };
 

--- 1.162/sql/item_cmpfunc.cc	2005-07-04 16:00:55 +03:00
+++ 1.163/sql/item_cmpfunc.cc	2005-07-16 00:17:01 +03:00
@@ -237,32 +237,35 @@
     set_cmp_func();
     return;
   }
-    
-  Item *real_item= args[0]->real_item();
-  if (real_item->type() == FIELD_ITEM)
+
+  if (!thd->is_context_analysis_only())
   {
-    Field *field= ((Item_field*) real_item)->field;
-    if (field->can_be_compared_as_longlong())
+    Item *real_item= args[0]->real_item();
+    if (real_item->type() == FIELD_ITEM)
     {
-      if (convert_constant_item(thd, field,&args[1]))
+      Field *field=((Item_field*) real_item)->field;
+      if (field->can_be_compared_as_longlong())
       {
-	cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
-			 INT_RESULT);		// Works for all types.
-	return;
+        if (convert_constant_item(thd, field,&args[1]))
+        {
+          cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
+                           INT_RESULT);		// Works for all types.
+          return;
+        }
       }
     }
-  }
-  real_item= args[1]->real_item();
-  if (real_item->type() == FIELD_ITEM)
-  {
-    Field *field= ((Item_field*) real_item)->field;
-    if (field->can_be_compared_as_longlong())
+    real_item= args[1]->real_item();
+    if (real_item->type() == FIELD_ITEM /* && !real_item->const_item() */)
     {
-      if (convert_constant_item(thd, field,&args[0]))
+      Field *field=((Item_field*) real_item)->field;
+      if (field->can_be_compared_as_longlong())
       {
-	cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
-			 INT_RESULT); // Works for all types.
-	return;
+        if (convert_constant_item(thd, field,&args[0]))
+        {
+          cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
+                           INT_RESULT); // Works for all types.
+          return;
+        }
       }
     }
   }
@@ -990,7 +993,8 @@
   if (args[0]->type() == FIELD_ITEM)
   {
     Field *field=((Item_field*) args[0])->field;
-    if (field->can_be_compared_as_longlong())
+    if (!thd->is_context_analysis_only() &&
+        field->can_be_compared_as_longlong())
     {
       /*
         The following can't be recoded with || as convert_constant_item

--- 1.241/sql/item_strfunc.cc	2005-07-13 13:23:31 +03:00
+++ 1.242/sql/item_strfunc.cc	2005-07-16 00:06:12 +03:00
@@ -1552,9 +1552,11 @@
   uint conv_errors;
   String tmp, cstr, *ostr= val_str(&tmp);
   cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
-  if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
-                                             cstr.charset(),
-                                             collation.derivation)))
+  if (conv_errors ||
+      !(conv= new Item_static_string_func(fully_qualified_func_name(),
+                                          cstr.ptr(), cstr.length(),
+                                          cstr.charset(),
+                                          collation.derivation)))
   {
     return NULL;
   }
@@ -1584,13 +1586,24 @@
   DBUG_ASSERT(fixed == 1);
   THD          *thd=current_thd;
   CHARSET_INFO *cs= system_charset_info;
-  const char   *host= thd->host_or_ip;
+  const char   *host, *user;
   uint		res_length;
 
+  if (is_current)
+  {
+    user= thd->priv_user;
+    host= thd->priv_host;
+  }
+  else
+  {
+    user= thd->user;
+    host= thd->host_or_ip;
+  }
+
   // For system threads (e.g. replication SQL thread) user may be empty
-  if (!thd->user)
+  if (!user)
     return &my_empty_string;
-  res_length= (strlen(thd->user)+strlen(host)+2) * cs->mbmaxlen;
+  res_length= (strlen(user)+strlen(host)+2) * cs->mbmaxlen;
 
   if (str->alloc(res_length))
   {
@@ -1598,11 +1611,12 @@
     return 0;
   }
   res_length=cs->cset->snprintf(cs, (char*)str->ptr(), res_length, "%s@%s",
-			  thd->user, host);
+			        user, host);
   str->length(res_length);
   str->set_charset(cs);
   return str;
 }
+
 
 void Item_func_soundex::fix_length_and_dec()
 {

--- 1.95/sql/item_strfunc.h	2005-07-03 14:17:46 +03:00
+++ 1.96/sql/item_strfunc.h	2005-07-16 00:06:12 +03:00
@@ -357,8 +357,15 @@
   Item_func_sysconst()
   { collation.set(system_charset_info,DERIVATION_SYSCONST); }
   Item *safe_charset_converter(CHARSET_INFO *tocs);
+  /*
+    Used to create correct Item name in new converted item in
+    safe_charset_converter, return string representation of this function
+    call
+  */
+  virtual const char *fully_qualified_func_name() const = 0;
 };
 
+
 class Item_func_database :public Item_func_sysconst
 {
 public:
@@ -370,18 +377,27 @@
     maybe_null=1;
   }
   const char *func_name() const { return "database"; }
+  const char *fully_qualified_func_name() const { return "database()"; }
 };
 
+
 class Item_func_user :public Item_func_sysconst
 {
+  bool is_current;
+
 public:
-  Item_func_user() :Item_func_sysconst() {}
+  Item_func_user(bool is_current_arg)
+    :Item_func_sysconst(), is_current(is_current_arg) {}
   String *val_str(String *);
-  void fix_length_and_dec() 
-  { 
-    max_length= (USERNAME_LENGTH+HOSTNAME_LENGTH+1)*system_charset_info->mbmaxlen;
+  void fix_length_and_dec()
+  {
+    max_length= ((USERNAME_LENGTH + HOSTNAME_LENGTH + 1) *
+                 system_charset_info->mbmaxlen);
   }
-  const char *func_name() const { return "user"; }
+  const char *func_name() const
+    { return is_current ? "current_user" : "user"; }
+  const char *fully_qualified_func_name() const
+    { return is_current ? "current_user()" : "user()"; }
 };
 
 

--- 1.248/sql/sql_class.h	2005-07-15 12:21:01 +03:00
+++ 1.249/sql/sql_class.h	2005-07-16 00:17:01 +03:00
@@ -1467,6 +1467,8 @@
              (variables.sql_mode & MODE_STRICT_ALL_TABLES)));
   }
   void set_status_var_init();
+  bool is_context_analysis_only()
+    { return current_arena->is_stmt_prepare() || lex->view_prepare_mode; }
   bool push_open_tables_state();
   void pop_open_tables_state();
 };

--- 1.405/sql/sql_yacc.yy	2005-07-14 23:31:00 +03:00
+++ 1.406/sql/sql_yacc.yy	2005-07-16 00:06:12 +03:00
@@ -4806,7 +4806,7 @@
 	| UNIX_TIMESTAMP '(' expr ')'
 	  { $$= new Item_func_unix_timestamp($3); }
 	| USER '(' ')'
-	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
+	  { $$= new Item_func_user(FALSE); Lex->safe_to_cache_query=0; }
 	| UTC_DATE_SYM optional_braces
 	  { $$= new Item_func_curdate_utc(); Lex->safe_to_cache_query=0;}
 	| UTC_TIME_SYM optional_braces

--- 1.91/mysql-test/r/view.result	2005-07-15 01:29:32 +03:00
+++ 1.92/mysql-test/r/view.result	2005-07-16 00:17:01 +03:00
@@ -1831,6 +1831,31 @@
 t
 01:00
 drop view v1;
+create table t1 (a timestamp default now());
+create table t2 (b timestamp default now());
+create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now();
+SHOW CREATE VIEW v1;
+View	Create View
+v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b`,(`test`.`t1`.`a` < now()) AS `t1.a < now()` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` < now())
+drop view v1;
+drop table t1, t2;
+CREATE TABLE t1 ( a varchar(50) );
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER();
+SHOW CREATE VIEW v1;
+View	Create View
+v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = current_user())
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION();
+SHOW CREATE VIEW v1;
+View	Create View
+v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = version())
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE();
+SHOW CREATE VIEW v1;
+View	Create View
+v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = database())
+DROP VIEW v1;
+DROP TABLE t1;
 CREATE TABLE t1 (col1 time);
 CREATE TABLE t2 (col1 time);
 CREATE VIEW v1 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;

--- 1.86/mysql-test/t/view.test	2005-07-15 01:29:32 +03:00
+++ 1.87/mysql-test/t/view.test	2005-07-16 00:17:01 +03:00
@@ -1674,6 +1674,27 @@
 drop view v1;
 
 #
+# evaluation constant functions in WHERE (BUG#4663)
+#
+create table t1 (a timestamp default now());
+create table t2 (b timestamp default now());
+create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now();
+SHOW CREATE VIEW v1;
+drop view v1;
+drop table t1, t2;
+CREATE TABLE t1 ( a varchar(50) );
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER();
+SHOW CREATE VIEW v1;
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION();
+SHOW CREATE VIEW v1;
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE();
+SHOW CREATE VIEW v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+#
 # checking views after some view with error (BUG#11337)
 #
 CREATE TABLE t1 (col1 time);

--- 1.15/mysql-test/r/sp-security.result	2005-07-07 18:55:10 +03:00
+++ 1.16/mysql-test/r/sp-security.result	2005-07-16 00:17:01 +03:00
@@ -212,3 +212,27 @@
 drop function bug_9503;
 use test;
 drop database mysqltest;
+use test;
+select current_user();
+current_user()
+root@localhost
+select user();
+user()
+root@localhost
+create procedure bug7291_0 () sql security invoker select current_user(), user();
+create procedure bug7291_1 () sql security definer call bug7291_0();
+create procedure bug7291_2 () sql security invoker call bug7291_0();
+grant execute on procedure bug7291_0 to user1@localhost;
+grant execute on procedure bug7291_1 to user1@localhost;
+grant execute on procedure bug7291_2 to user1@localhost;
+call bug7291_2();
+current_user()	user()
+user1@localhost	user1@localhost
+call bug7291_1();
+current_user()	user()
+root@localhost	user1@localhost
+drop procedure bug7291_1;
+drop procedure bug7291_2;
+drop procedure bug7291_0;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM user1@localhost;
+drop user user1@localhost;

--- 1.17/mysql-test/t/sp-security.test	2005-07-07 18:44:04 +03:00
+++ 1.18/mysql-test/t/sp-security.test	2005-07-16 00:17:01 +03:00
@@ -341,3 +341,33 @@
 drop function bug_9503;
 use test;
 drop database mysqltest;
+
+#
+# correct value from current_user() in function run from "security definer"
+# (BUG#7291)
+#
+connection con1root;
+use test;
+
+select current_user();
+select user();
+create procedure bug7291_0 () sql security invoker select current_user(), user();
+create procedure bug7291_1 () sql security definer call bug7291_0();
+create procedure bug7291_2 () sql security invoker call bug7291_0();
+grant execute on procedure bug7291_0 to user1@localhost;
+grant execute on procedure bug7291_1 to user1@localhost;
+grant execute on procedure bug7291_2 to user1@localhost;
+
+connect (user1,localhost,user1,,);
+connection user1;
+
+call bug7291_2();
+call bug7291_1();
+
+connection con1root;
+drop procedure bug7291_1;
+drop procedure bug7291_2;
+drop procedure bug7291_0;
+disconnect user1;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM user1@localhost;
+drop user user1@localhost;
Thread
bk commit into 5.0 tree (bell:1.1950)sanja15 Jul