1 /*
2    Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
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_FK_UTIL_H
26 #define NDB_FK_UTIL_H
27 
28 #include <set>
29 #include <string>
30 #include <vector>
31 
32 #include "storage/ndb/include/ndbapi/NdbApi.hpp"
33 
34 using Ndb_fk_list = std::vector<NdbDictionary::ForeignKey>;
35 
36 // Database name guard for Ndb objects
37 struct Ndb_db_guard {
Ndb_db_guardNdb_db_guard38   Ndb_db_guard(class Ndb *ndb) {
39     this->ndb = ndb;
40     save_db = ndb->getDatabaseName();
41   }
42 
restoreNdb_db_guard43   void restore() { ndb->setDatabaseName(save_db.c_str()); }
44 
~Ndb_db_guardNdb_db_guard45   ~Ndb_db_guard() { ndb->setDatabaseName(save_db.c_str()); }
46 
47  private:
48   Ndb *ndb;
49   std::string save_db;
50 };
51 
52 const char *fk_split_name(char dst[], const char *src, bool index = false);
53 bool fetch_referenced_tables_from_ndb_dictionary(
54     class THD *thd, const char *schema_name, const char *table_name,
55     std::set<std::pair<std::string, std::string>> &referenced_tables);
56 
57 bool retrieve_foreign_key_list_from_ndb(NdbDictionary::Dictionary *dict,
58                                         const NdbDictionary::Table *table,
59                                         Ndb_fk_list *fk_list);
60 
61 #endif
62