1 /*
2    Copyright (c) 2011, 2021, Oracle and/or its affiliates.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NDB_LOCAL_SCHEMA_H
26 #define NDB_LOCAL_SCHEMA_H
27 
28 class Ndb_local_schema
29 {
30   /*
31     Base functionality for working with local schema
32     objects like tables, triggers and databases
33   */
34   class Base {
35     bool m_have_mdl_lock;
36     bool m_push_warnings;
37 
38     bool mdl_try_lock(void) const;
39     void mdl_unlock(void);
40 
41   protected:
42     class THD* m_thd;
43     const char* m_db;
44     const char* m_name;
45 
46     void log_warning(const char* fmt, ...) const;
47 
48     Base(); // Not implemented
49     Base(const Base&); // Not implemented
50     Base(class THD* thd, const char* db, const char* name);
51     ~Base();
52 
have_mdl_lock(void)53     bool have_mdl_lock(void) const { return m_have_mdl_lock; }
54   };
55 
56 public:
57 
58   /*
59     Class used for working with a table in the
60     local MySQL Servers "dictionary"
61   */
62 
63   class Table : protected Base
64   {
65     bool m_frm_file_exist;
66     bool m_ndb_file_exist;
67     bool m_has_triggers;
68 
69     bool file_exists(const char* ext) const;
70     bool remove_file(const char* ext) const;
71     bool rename_file(const char* new_db, const char* new_name,
72                      const char* ext) const;
73 
74     // Read the engine type from .frm and return true if it says NDB
75     bool frm_engine_is_ndb(void) const;
76 
77   public:
78     Table(); // Not implemented
79     Table(const Table&); // Not implemented
80     Table(class THD* thd, const char* db, const char* name);
81 
82     bool is_local_table(void) const;
83     void remove_table(void) const;
84     void rename_table(const char* new_db, const char* new_name) const;
85   };
86 };
87 
88 #endif
89