Commit 015d55b7 authored by unknown's avatar unknown
Browse files

Merge grichter@bk-internal.mysql.com:/home/bk/mysql-5.0

into lmy002.wdf.sap.corp:/home/georg/work/mysql/bugs/mysql-5.0-master


mysql-test/r/view.result:
  Auto merged
mysql-test/t/view.test:
  Auto merged
sql/sql_view.cc:
  Auto merged
parents d4da0420 458aa0e3
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -845,6 +845,15 @@ select * from v1;
cast(1 as char(3))
1
drop view v1;
create table t1 (a int);
create view v1 as select a from t1;
create database seconddb;
rename table v1 to seconddb.v1;
ERROR HY000: Changing schema from 'test' to 'seconddb' is not allowed.
rename table v1 to v2;
drop table t1;
drop view v2;
drop database seconddb;
create view v1 as select 'a',1;
create view v2 as select * from v1 union all select * from v1;
create view v3 as select * from v2 where 1 = (select `1` from v2);
+13 −0
Original line number Diff line number Diff line
@@ -785,6 +785,19 @@ show create view v1;
select * from v1;
drop view v1;

#
# renaming views
#
create table t1 (a int);
create view v1 as select a from t1;
create database seconddb;
-- error 1450
rename table v1 to seconddb.v1;
rename table v1 to v2;
drop table t1;
drop view v2;
drop database seconddb;

#
# bug handling from VIEWs
#
+53 −0
Original line number Diff line number Diff line
@@ -333,6 +333,59 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
  DBUG_RETURN(TRUE);
}

/*
  Renames a frm file (including backups) in same schema

  SYNOPSIS
    rename_in_schema_file
    schema            name of given schema           
    old_name          original file name
    new_name          new file name
    revision          revision number
    num_view_backups  number of backups

  RETURN
    0 - OK 
    1 - Error (only if renaming of frm failed)

*/
my_bool rename_in_schema_file(const char *schema, const char *old_name, 
                              const char *new_name, ulonglong revision, 
                              uint num_view_backups)
{
  char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN];

  strxnmov(old_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
           old_name, reg_ext, NullS);
  (void) unpack_filename(old_path, old_path);

  strxnmov(new_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
           new_name, reg_ext, NullS);
  (void) unpack_filename(new_path, new_path);

  if (my_rename(old_path, new_path, MYF(MY_WME)))
    return 1;

  /* check if arc_dir exists */
  strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS);
  (void) unpack_filename(arc_path, arc_path);
  
  if (revision > 0 && !access(arc_path, F_OK))
  {
    ulonglong limit= (revision > num_view_backups) ? revision - num_view_backups : 0;
    while (revision > limit) {
      my_snprintf(old_path, FN_REFLEN, "%s/%s%s-%04lu",
		  arc_path, old_name, reg_ext, (ulong)revision);
      (void) unpack_filename(old_path, old_path);
      my_snprintf(new_path, FN_REFLEN, "%s/%s%s-%04lu",
		  arc_path, new_name, reg_ext, (ulong)revision);
      (void) unpack_filename(new_path, new_path);
      my_rename(old_path, new_path, MYF(0));
      revision--;
    }
  }
  return 0;
}

/*
  Prepare frm to parse (read to memory)
+3 −0
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ my_bool
sql_create_definition_file(const LEX_STRING *dir, const  LEX_STRING *file_name,
			   const LEX_STRING *type,
			   gptr base, File_option *parameters, uint versions);
my_bool rename_in_schema_file(const char *schema, const char *old_name, 
                              const char *new_name, ulonglong revision, 
                              uint num_view_backups);

class File_parser: public Sql_alloc
{
+2 −0
Original line number Diff line number Diff line
@@ -5413,3 +5413,5 @@ ER_VIEW_OTHER_USER
        eng "You need the SUPER privilege for creation view with %-.64s@%-.64s definer"
ER_NO_SUCH_USER
        eng "There is not %-.64s@%-.64s registered"
ER_FORBID_SCHEMA_CHANGE
	eng "Changing schema from '%-.64s' to '%-.64s' is not allowed."
Loading