1 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 /* drop and alter of tablespaces */
24 
25 #include "sql_priv.h"
26 #include "unireg.h"
27 #include "sql_tablespace.h"
28 #include "sql_table.h"                          // write_bin_log
29 #include "sql_class.h"                          // THD
30 
mysql_alter_tablespace(THD * thd,st_alter_tablespace * ts_info)31 int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info)
32 {
33   int error= HA_ADMIN_NOT_IMPLEMENTED;
34   handlerton *hton= ts_info->storage_engine;
35 
36   DBUG_ENTER("mysql_alter_tablespace");
37   /*
38     If the user haven't defined an engine, this will fallback to using the
39     default storage engine.
40   */
41   if (hton == NULL || hton->state != SHOW_OPTION_YES)
42   {
43     hton= ha_default_handlerton(thd);
44     if (ts_info->storage_engine != 0)
45       push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
46                           ER_WARN_USING_OTHER_HANDLER,
47                           ER(ER_WARN_USING_OTHER_HANDLER),
48                           ha_resolve_storage_engine_name(hton),
49                           ts_info->tablespace_name ? ts_info->tablespace_name
50                                                 : ts_info->logfile_group_name);
51   }
52 
53   if (hton->alter_tablespace)
54   {
55     if ((error= hton->alter_tablespace(hton, thd, ts_info)))
56     {
57       if (error == HA_ADMIN_NOT_IMPLEMENTED)
58       {
59         my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "");
60       }
61       else if (error == 1)
62       {
63         DBUG_RETURN(1);
64       }
65       else
66       {
67         my_error(error, MYF(0));
68       }
69       DBUG_RETURN(error);
70     }
71   }
72   else
73   {
74     my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0),
75              ha_resolve_storage_engine_name(hton),
76              "TABLESPACE or LOGFILE GROUP");
77     DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
78   }
79   error= write_bin_log(thd, FALSE, thd->query(), thd->query_length());
80   DBUG_RETURN(error);
81 }
82