1 /*
2    Copyright (c) 2003, 2010, 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 NDBT_TABLE_HPP
26 #define NDBT_TABLE_HPP
27 
28 #include <ndb_global.h>
29 
30 #include <NdbApi.hpp>
31 #include <NdbOut.hpp>
32 
33 class NDBT_Attribute : public NdbDictionary::Column {
34 public:
NDBT_Attribute(const char * _name,NdbDictionary::Column::Type _type,int _length=1,bool _pk=false,bool _nullable=false,CHARSET_INFO * cs=0,NdbDictionary::Column::StorageType storage=NdbDictionary::Column::StorageTypeMemory,bool dynamic=false,const void * defaultVal=NULL,Uint32 defaultValBytes=0)35   NDBT_Attribute(const char* _name,
36 		 NdbDictionary::Column::Type _type,
37 		 int _length = 1,
38 		 bool _pk = false,
39 		 bool _nullable = false,
40 		 CHARSET_INFO *cs= 0,
41 		 NdbDictionary::Column::StorageType storage = NdbDictionary::Column::StorageTypeMemory,
42                  bool dynamic = false,
43                  const void* defaultVal = NULL,
44                  Uint32 defaultValBytes = 0):
45     NdbDictionary::Column(_name)
46   {
47     assert(_name != 0);
48 
49     setType(_type);
50     setLength(_length);
51     setNullable(_nullable);
52     setPrimaryKey(_pk);
53     if (cs)
54     {
55       setCharset(cs);
56     }
57     setStorageType(storage);
58     setDynamic(dynamic);
59     setDefaultValue(defaultVal, defaultValBytes);
60   }
61 };
62 
63 class NDBT_Table : public NdbDictionary::Table {
64   /**
65    * Print meta information about table
66    * (information on how it is strored, what the attributes look like etc.)
67    */
68   friend class NdbOut& operator <<(class NdbOut&, const NDBT_Table &);
69 public:
70 
NDBT_Table(const char * name,int noOfAttributes,const NdbDictionary::Column attributes[])71   NDBT_Table(const char* name,
72 	     int noOfAttributes,
73 	     const NdbDictionary::Column attributes[])
74     : NdbDictionary::Table(name)
75   {
76     assert(name != 0);
77 
78     //setStoredTable(stored);
79     for(int i = 0; i<noOfAttributes; i++)
80       addColumn(attributes[i]);
81 
82     // validate() might cause initialization order problem with charset
83     NdbError error;
84     int ret = aggregate(error);
85     (void)ret;
86     assert(ret == 0);
87   }
88 
NDBT_Table(const char * name,int noOfAttributes,NdbDictionary::Column * attributePtrs[])89   NDBT_Table(const char* name,
90 	     int noOfAttributes,
91 	     NdbDictionary::Column* attributePtrs[])
92     : NdbDictionary::Table(name)
93   {
94     assert(name != 0);
95 
96     //setStoredTable(stored);
97     for(int i = 0; i<noOfAttributes; i++)
98       addColumn(*attributePtrs[i]);
99 
100     // validate() might cause initialization order problem with charset
101     NdbError error;
102     int ret = aggregate(error);
103     assert(ret == 0);
104   }
105 
106   static const NdbDictionary::Table * discoverTableFromDb(Ndb* ndb,
107 							  const char * name);
108 };
109 
110 inline
111 const NdbDictionary::Table *
discoverTableFromDb(Ndb * ndb,const char * name)112 NDBT_Table::discoverTableFromDb(Ndb* ndb, const char * name){
113   return ndb->getDictionary()->getTable(name);
114 }
115 
116 
117 /**
118  * Print meta information about index
119  * (information on how it is strored, what the attributes look like etc.)
120  */
121 class NdbOut& operator <<(class NdbOut&, const NdbDictionary::Index &);
122 
123 
124 
125 #endif
126