1 /* Copyright (c) 2003-2007 MySQL AB
2    Use is subject to license terms
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 as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
16 
17 #ifndef NdbDictionary_H
18 #define NdbDictionary_H
19 
20 #include <ndb_types.h>
21 
22 class Ndb;
23 struct charset_info_st;
24 typedef struct charset_info_st CHARSET_INFO;
25 
26 /**
27  * @class NdbDictionary
28  * @brief Data dictionary class
29  *
30  * The preferred and supported way to create and drop tables and indexes
31  * in ndb is through the
32  * MySQL Server (see MySQL reference Manual, section MySQL Cluster).
33  *
34  * Tables and indexes that are created directly through the
35  * NdbDictionary class
36  * can not be viewed from the MySQL Server.
37  * Dropping indexes directly via the NdbApi will cause inconsistencies
38  * if they were originally created from a MySQL Cluster.
39  *
40  * This class supports schema data enquiries such as:
41  * -# Enquiries about tables
42  *    (Dictionary::getTable, Table::getNoOfColumns,
43  *    Table::getPrimaryKey, and Table::getNoOfPrimaryKeys)
44  * -# Enquiries about indexes
45  *    (Dictionary::getIndex, Index::getNoOfColumns,
46  *    and Index::getColumn)
47  *
48  * This class supports schema data definition such as:
49  * -# Creating tables (Dictionary::createTable) and table columns
50  * -# Dropping tables (Dictionary::dropTable)
51  * -# Creating secondary indexes (Dictionary::createIndex)
52  * -# Dropping secondary indexes (Dictionary::dropIndex)
53  *
54  * NdbDictionary has several help (inner) classes to support this:
55  * -# NdbDictionary::Dictionary the dictionary handling dictionary objects
56  * -# NdbDictionary::Table for creating tables
57  * -# NdbDictionary::Column for creating table columns
58  * -# NdbDictionary::Index for creating secondary indexes
59  *
60  * See @ref ndbapi_simple_index.cpp for details of usage.
61  */
62 class NdbDictionary {
63 public:
NdbDictionary()64   NdbDictionary() {}                          /* Remove gcc warning */
65   /**
66    * @class Object
67    * @brief Meta information about a database object (a table, index, etc)
68    */
69   class Object {
70   public:
Object()71     Object() {}                               /* Remove gcc warning */
~Object()72     virtual ~Object() {}                      /* Remove gcc warning */
73     /**
74      * Status of object
75      */
76     enum Status {
77       New,                    ///< The object only exist in memory and
78                               ///< has not been created in the NDB Kernel
79       Changed,                ///< The object has been modified in memory
80                               ///< and has to be commited in NDB Kernel for
81                               ///< changes to take effect
82       Retrieved,              ///< The object exist and has been read
83                               ///< into main memory from NDB Kernel
84       Invalid,                ///< The object has been invalidated
85                               ///< and should not be used
86       Altered                 ///< Table has been altered in NDB kernel
87                               ///< but is still valid for usage
88     };
89 
90     /**
91      * Get status of object
92      */
93     virtual Status getObjectStatus() const = 0;
94 
95     /**
96      * Get version of object
97      */
98     virtual int getObjectVersion() const = 0;
99 
100     virtual int getObjectId() const = 0;
101 
102     /**
103      * Object type
104      */
105     enum Type {
106       TypeUndefined = 0,      ///< Undefined
107       SystemTable = 1,        ///< System table
108       UserTable = 2,          ///< User table (may be temporary)
109       UniqueHashIndex = 3,    ///< Unique un-ordered hash index
110       OrderedIndex = 6,       ///< Non-unique ordered index
111       HashIndexTrigger = 7,   ///< Index maintenance, internal
112       IndexTrigger = 8,       ///< Index maintenance, internal
113       SubscriptionTrigger = 9,///< Backup or replication, internal
114       ReadOnlyConstraint = 10,///< Trigger, internal
115       Tablespace = 20,        ///< Tablespace
116       LogfileGroup = 21,      ///< Logfile group
117       Datafile = 22,          ///< Datafile
118       Undofile = 23           ///< Undofile
119     };
120 
121     /**
122      * Object state
123      */
124     enum State {
125       StateUndefined = 0,     ///< Undefined
126       StateOffline = 1,       ///< Offline, not usable
127       StateBuilding = 2,      ///< Building, not yet usable
128       StateDropping = 3,      ///< Offlining or dropping, not usable
129       StateOnline = 4,        ///< Online, usable
130       StateBackup = 5,        ///< Online, being backuped, usable
131       StateBroken = 9         ///< Broken, should be dropped and re-created
132     };
133 
134     /**
135      * Object store
136      */
137     enum Store {
138       StoreUndefined = 0,     ///< Undefined
139       StoreNotLogged = 1,     ///< Object or data deleted on system restart
140       StorePermanent = 2      ///< Permanent. logged to disk
141     };
142 
143     /**
144      * Type of fragmentation.
145      *
146      * This parameter specifies how data in the table or index will
147      * be distributed among the db nodes in the cluster.<br>
148      * The bigger the table the more number of fragments should be used.
149      * Note that all replicas count as same "fragment".<br>
150      * For a table, default is FragAllMedium.  For a unique hash index,
151      * default is taken from underlying table and cannot currently
152      * be changed.
153      */
154     enum FragmentType {
155       FragUndefined = 0,      ///< Fragmentation type undefined or default
156       FragSingle = 1,         ///< Only one fragment
157       FragAllSmall = 2,       ///< One fragment per node, default
158       FragAllMedium = 3,      ///< two fragments per node
159       FragAllLarge = 4,       ///< Four fragments per node.
160       DistrKeyHash = 5,
161       DistrKeyLin = 6,
162       UserDefined = 7
163     };
164   };
165 
166   class Dictionary; // Forward declaration
167 
168   class ObjectId : public Object
169   {
170   public:
171     ObjectId();
172     virtual ~ObjectId();
173 
174     /**
175      * Get status of object
176      */
177     virtual Status getObjectStatus() const;
178 
179     /**
180      * Get version of object
181      */
182     virtual int getObjectVersion() const;
183 
184     virtual int getObjectId() const;
185 
186   private:
187     friend class NdbDictObjectImpl;
188     class NdbDictObjectImpl & m_impl;
189   };
190 
191   class Table; // forward declaration
192   class Tablespace; // forward declaration
193 //  class NdbEventOperation; // forward declaration
194 
195   /**
196    * @class Column
197    * @brief Represents a column in an NDB Cluster table
198    *
199    * Each column has a type. The type of a column is determined by a number
200    * of type specifiers.
201    * The type specifiers are:
202    * - Builtin type
203    * - Array length or max length
204    * - Precision and scale (not used yet)
205    * - Character set for string types
206    * - Inline and part sizes for blobs
207    *
208    * Types in general correspond to MySQL types and their variants.
209    * Data formats are same as in MySQL.  NDB API provides no support for
210    * constructing such formats.  NDB kernel checks them however.
211    */
212   class Column {
213   public:
214     /**
215      * The builtin column types
216      */
217     enum Type {
218       Undefined = NDB_TYPE_UNDEFINED,   ///< Undefined
219       Tinyint = NDB_TYPE_TINYINT,       ///< 8 bit. 1 byte signed integer, can be used in array
220       Tinyunsigned = NDB_TYPE_TINYUNSIGNED,  ///< 8 bit. 1 byte unsigned integer, can be used in array
221       Smallint = NDB_TYPE_SMALLINT,      ///< 16 bit. 2 byte signed integer, can be used in array
222       Smallunsigned = NDB_TYPE_SMALLUNSIGNED, ///< 16 bit. 2 byte unsigned integer, can be used in array
223       Mediumint = NDB_TYPE_MEDIUMINT,     ///< 24 bit. 3 byte signed integer, can be used in array
224       Mediumunsigned = NDB_TYPE_MEDIUMUNSIGNED,///< 24 bit. 3 byte unsigned integer, can be used in array
225       Int = NDB_TYPE_INT,           ///< 32 bit. 4 byte signed integer, can be used in array
226       Unsigned = NDB_TYPE_UNSIGNED,      ///< 32 bit. 4 byte unsigned integer, can be used in array
227       Bigint = NDB_TYPE_BIGINT,        ///< 64 bit. 8 byte signed integer, can be used in array
228       Bigunsigned = NDB_TYPE_BIGUNSIGNED,   ///< 64 Bit. 8 byte signed integer, can be used in array
229       Float = NDB_TYPE_FLOAT,         ///< 32-bit float. 4 bytes float, can be used in array
230       Double = NDB_TYPE_DOUBLE,        ///< 64-bit float. 8 byte float, can be used in array
231       Olddecimal = NDB_TYPE_OLDDECIMAL,    ///< MySQL < 5.0 signed decimal,  Precision, Scale
232       Olddecimalunsigned = NDB_TYPE_OLDDECIMALUNSIGNED,
233       Decimal = NDB_TYPE_DECIMAL,    ///< MySQL >= 5.0 signed decimal,  Precision, Scale
234       Decimalunsigned = NDB_TYPE_DECIMALUNSIGNED,
235       Char = NDB_TYPE_CHAR,          ///< Len. A fixed array of 1-byte chars
236       Varchar = NDB_TYPE_VARCHAR,       ///< Length bytes: 1, Max: 255
237       Binary = NDB_TYPE_BINARY,        ///< Len
238       Varbinary = NDB_TYPE_VARBINARY,     ///< Length bytes: 1, Max: 255
239       Datetime = NDB_TYPE_DATETIME,    ///< Precision down to 1 sec (sizeof(Datetime) == 8 bytes )
240       Date = NDB_TYPE_DATE,            ///< Precision down to 1 day(sizeof(Date) == 4 bytes )
241       Blob = NDB_TYPE_BLOB,        ///< Binary large object (see NdbBlob)
242       Text = NDB_TYPE_TEXT,         ///< Text blob
243       Bit = NDB_TYPE_BIT,          ///< Bit, length specifies no of bits
244       Longvarchar = NDB_TYPE_LONGVARCHAR,  ///< Length bytes: 2, little-endian
245       Longvarbinary = NDB_TYPE_LONGVARBINARY, ///< Length bytes: 2, little-endian
246       Time = NDB_TYPE_TIME,        ///< Time without date
247       Year = NDB_TYPE_YEAR,   ///< Year 1901-2155 (1 byte)
248       Timestamp = NDB_TYPE_TIMESTAMP  ///< Unix time
249     };
250 
251     /*
252      * Array type specifies internal attribute format.
253      *
254      * - ArrayTypeFixed is stored as fixed number of bytes.  This type
255      *   is fastest to access but can waste space.
256      *
257      * - ArrayTypeVar is stored as variable number of bytes with a fixed
258      *   overhead of 2 bytes.
259      *
260      * Default is ArrayTypeVar for Var* types and ArrayTypeFixed for
261      * others.  The default is normally ok.
262      */
263     enum ArrayType {
264       ArrayTypeFixed = NDB_ARRAYTYPE_FIXED,          // 0 length bytes
265       ArrayTypeShortVar = NDB_ARRAYTYPE_SHORT_VAR,   // 1 length bytes
266       ArrayTypeMediumVar = NDB_ARRAYTYPE_MEDIUM_VAR // 2 length bytes
267     };
268 
269     /*
270      * Storage type specifies whether attribute is stored in memory or
271      * on disk.  Default is memory.  Disk attributes are potentially
272      * much slower to access and cannot be indexed in version 5.1.
273      */
274     enum StorageType {
275       StorageTypeMemory = NDB_STORAGETYPE_MEMORY,
276       StorageTypeDisk = NDB_STORAGETYPE_DISK
277     };
278 
279     /**
280      * @name General
281      * @{
282      */
283 
284     /**
285      * Get name of column
286      * @return  Name of the column
287      */
288     const char* getName() const;
289 
290     /**
291      * Get if the column is nullable or not
292      */
293     bool getNullable() const;
294 
295     /**
296      * Check if column is part of primary key
297      */
298     bool getPrimaryKey() const;
299 
300     /**
301      *  Get number of column (horizontal position within table)
302      */
303     int getColumnNo() const;
304 
305 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
306     int getAttrId() const;
307 #endif
308 
309     /**
310      * Check if column is equal to some other column
311      * @param  column  Column to compare with
312      * @return  true if column is equal to some other column otherwise false.
313      */
314     bool equal(const Column& column) const;
315 
316 
317     /** @} *******************************************************************/
318     /**
319      * @name Get Type Specifiers
320      * @{
321      */
322 
323     /**
324      * Get type of column
325      */
326     Type getType() const;
327 
328     /**
329      * Get precision of column.
330      * @note Only applicable for decimal types
331      */
332     int getPrecision() const;
333 
334     /**
335      * Get scale of column.
336      * @note Only applicable for decimal types
337      */
338     int getScale() const;
339 
340     /**
341      * Get length for column
342      * Array length for column or max length for variable length arrays.
343      */
344     int getLength() const;
345 
346     /**
347      * For Char or Varchar or Text, get MySQL CHARSET_INFO.  This
348      * specifies both character set and collation.  See get_charset()
349      * etc in MySQL.  (The cs is not "const" in MySQL).
350      */
351     CHARSET_INFO* getCharset() const;
352 
353 
354     /**
355      * For blob, get "inline size" i.e. number of initial bytes
356      * to store in table's blob attribute.  This part is normally in
357      * main memory and can be indexed and interpreted.
358      */
359     int getInlineSize() const;
360 
361     /**
362      * For blob, get "part size" i.e. number of bytes to store in
363      * each tuple of the "blob table".  Can be set to zero to omit parts
364      * and to allow only inline bytes ("tinyblob").
365      */
366     int getPartSize() const;
367 
368     /**
369      * For blob, set or get "stripe size" i.e. number of consecutive
370      * <em>parts</em> to store in each node group.
371      */
372     int getStripeSize() const;
373 
374     /**
375      * Get size of element
376      */
377     int getSize() const;
378 
379     /**
380      * Check if column is part of partition key
381      *
382      * A <em>partition key</em> is a set of attributes which are used
383      * to distribute the tuples onto the NDB nodes.
384      * The partition key uses the NDB Cluster hashing function.
385      *
386      * An example where this is useful is TPC-C where it might be
387      * good to use the warehouse id and district id as the partition key.
388      * This would place all data for a specific district and warehouse
389      * in the same database node.
390      *
391      * Locally in the fragments the full primary key
392      * will still be used with the hashing algorithm.
393      *
394      * @return  true then the column is part of
395      *                 the partition key.
396      */
397     bool getPartitionKey() const;
398 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
getDistributionKey() const399     inline bool getDistributionKey() const { return getPartitionKey(); };
400 #endif
401 
402     ArrayType getArrayType() const;
403     StorageType getStorageType() const;
404 
405     /** @} *******************************************************************/
406 
407 
408     /**
409      * @name Column creation
410      * @{
411      *
412      * These operations should normally not be performed in an NbdApi program
413      * as results will not be visable in the MySQL Server
414      *
415      */
416 
417     /**
418      * Constructor
419      * @param   name   Name of column
420      */
421     Column(const char * name = "");
422     /**
423      * Copy constructor
424      * @param  column  Column to be copied
425      */
426     Column(const Column& column);
427     ~Column();
428 
429     /**
430      * Set name of column
431      * @param  name  Name of the column
432      */
433     int setName(const char * name);
434 
435     /**
436      * Set whether column is nullable or not
437      */
438     void setNullable(bool);
439 
440     /**
441      * Set that column is part of primary key
442      */
443     void setPrimaryKey(bool);
444 
445     /**
446      * Set type of column
447      * @param  type  Type of column
448      *
449      * @note setType resets <em>all</em> column attributes
450      *       to (type dependent) defaults and should be the first
451      *       method to call.  Default type is Unsigned.
452      */
453     void setType(Type type);
454 
455     /**
456      * Set precision of column.
457      * @note Only applicable for decimal types
458      */
459     void setPrecision(int);
460 
461     /**
462      * Set scale of column.
463      * @note Only applicable for decimal types
464      */
465     void setScale(int);
466 
467     /**
468      * Set length for column
469      * Array length for column or max length for variable length arrays.
470      */
471     void setLength(int length);
472 
473     /**
474      * For Char or Varchar or Text, get MySQL CHARSET_INFO.  This
475      * specifies both character set and collation.  See get_charset()
476      * etc in MySQL.  (The cs is not "const" in MySQL).
477      */
478     void setCharset(CHARSET_INFO* cs);
479 
480     /**
481      * For blob, get "inline size" i.e. number of initial bytes
482      * to store in table's blob attribute.  This part is normally in
483      * main memory and can be indexed and interpreted.
484      */
485     void setInlineSize(int size);
486 
487     /**
488      * For blob, get "part size" i.e. number of bytes to store in
489      * each tuple of the "blob table".  Can be set to zero to omit parts
490      * and to allow only inline bytes ("tinyblob").
491      */
492     void setPartSize(int size);
493 
494     /**
495      * For blob, get "stripe size" i.e. number of consecutive
496      * <em>parts</em> to store in each node group.
497      */
498     void setStripeSize(int size);
499 
500     /**
501      * Set partition key
502      * @see getPartitionKey
503      *
504      * @param  enable  If set to true, then the column will be part of
505      *                 the partition key.
506      */
507     void setPartitionKey(bool enable);
508 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
setDistributionKey(bool enable)509     inline void setDistributionKey(bool enable)
510     { setPartitionKey(enable); };
511 #endif
512 
513     void setArrayType(ArrayType type);
514     void setStorageType(StorageType type);
515 
516     /** @} *******************************************************************/
517 
518 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
519     const Table * getBlobTable() const;
520 
521     void setAutoIncrement(bool);
522     bool getAutoIncrement() const;
523     void setAutoIncrementInitialValue(Uint64 val);
524     int setDefaultValue(const char*);
525     const char* getDefaultValue() const;
526 
527     static const Column * FRAGMENT;
528     static const Column * FRAGMENT_FIXED_MEMORY;
529     static const Column * FRAGMENT_VARSIZED_MEMORY;
530     static const Column * ROW_COUNT;
531     static const Column * COMMIT_COUNT;
532     static const Column * ROW_SIZE;
533     static const Column * RANGE_NO;
534     static const Column * DISK_REF;
535     static const Column * RECORDS_IN_RANGE;
536     static const Column * ROWID;
537     static const Column * ROW_GCI;
538     static const Column * ANY_VALUE;
539     static const Column * COPY_ROWID;
540 
541     int getSizeInBytes() const;
542 #endif
543 
544   private:
545 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
546     friend class NdbRecAttr;
547     friend class NdbColumnImpl;
548 #endif
549     class NdbColumnImpl & m_impl;
550     Column(NdbColumnImpl&);
551     Column& operator=(const Column&);
552   };
553 
554 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
555   /**
556    * ???
557    */
558   typedef Column Attribute;
559 #endif
560 
561   /**
562    * @brief Represents a table in NDB Cluster
563    *
564    * <em>TableSize</em><br>
565    * When calculating the data storage one should add the size of all
566    * attributes (each attributeconsumes at least 4 bytes) and also an overhead
567    * of 12 byte. Variable size attributes (not supported yet) will have a
568    * size of 12 bytes plus the actual data storage parts where there is an
569    * additional overhead based on the size of the variable part.<br>
570    * An example table with 5 attributes:
571    * one 64 bit attribute, one 32 bit attribute,
572    * two 16 bit attributes and one array of 64 8 bits.
573    * This table will consume
574    * 12 (overhead) + 8 + 4 + 2*4 (4 is minimum) + 64 = 96 bytes per record.
575    * Additionally an overhead of about 2 % as page headers and waste should
576    * be allocated. Thus, 1 million records should consume 96 MBytes
577    * plus the overhead 2 MByte and rounded up to 100 000 kBytes.<br>
578    *
579    */
580   class Table : public Object {
581   public:
582     /*
583      * Single user mode specifies access rights to table during single user mode
584      */
585     enum SingleUserMode {
586       SingleUserModeLocked    = NDB_SUM_LOCKED,
587       SingleUserModeReadOnly  = NDB_SUM_READONLY,
588       SingleUserModeReadWrite = NDB_SUM_READ_WRITE
589     };
590 
591     /**
592      * @name General
593      * @{
594      */
595 
596     /**
597      * Get table name
598      */
599     const char * getName() const;
600 
601     /**
602      * Get table id
603      */
604     int getTableId() const;
605 
606     /**
607      * Get column definition via name.
608      * @return null if none existing name
609      */
610     const Column* getColumn(const char * name) const;
611 
612     /**
613      * Get column definition via index in table.
614      * @return null if none existing name
615      */
616     Column* getColumn(const int attributeId);
617 
618     /**
619      * Get column definition via name.
620      * @return null if none existing name
621      */
622     Column* getColumn(const char * name);
623 
624     /**
625      * Get column definition via index in table.
626      * @return null if none existing name
627      */
628     const Column* getColumn(const int attributeId) const;
629 
630     /** @} *******************************************************************/
631     /**
632      * @name Storage
633      * @{
634      */
635 
636     /**
637      * If set to false, then the table is a temporary
638      * table and is not logged to disk.
639      *
640      * In case of a system restart the table will still
641      * be defined and exist but will be empty.
642      * Thus no checkpointing and no logging is performed on the table.
643      *
644      * The default value is true and indicates a normal table
645      * with full checkpointing and logging activated.
646      */
647     bool getLogging() const;
648 
649     /**
650      * Get fragmentation type
651      */
652     FragmentType getFragmentType() const;
653 
654     /**
655      * Get KValue (Hash parameter.)
656      * Only allowed value is 6.
657      * Later implementations might add flexibility in this parameter.
658      */
659     int getKValue() const;
660 
661     /**
662      * Get MinLoadFactor  (Hash parameter.)
663      * This value specifies the load factor when starting to shrink
664      * the hash table.
665      * It must be smaller than MaxLoadFactor.
666      * Both these factors are given in percentage.
667      */
668     int getMinLoadFactor() const;
669 
670     /**
671      * Get MaxLoadFactor  (Hash parameter.)
672      * This value specifies the load factor when starting to split
673      * the containers in the local hash tables.
674      * 100 is the maximum which will optimize memory usage.
675      * A lower figure will store less information in each container and thus
676      * find the key faster but consume more memory.
677      */
678     int getMaxLoadFactor() const;
679 
680     /** @} *******************************************************************/
681     /**
682      * @name Other
683      * @{
684      */
685 
686     /**
687      * Get number of columns in the table
688      */
689     int getNoOfColumns() const;
690 
691     /**
692      * Get number of primary keys in the table
693      */
694     int getNoOfPrimaryKeys() const;
695 
696     /**
697      * Get name of primary key
698      */
699     const char* getPrimaryKey(int no) const;
700 
701     /**
702      * Check if table is equal to some other table
703      */
704     bool equal(const Table&) const;
705 
706     /**
707      * Get frm file stored with this table
708      */
709     const void* getFrmData() const;
710     Uint32 getFrmLength() const;
711 
712     /**
713      * Get Fragment Data (id, state and node group)
714      */
715     const void *getFragmentData() const;
716     Uint32 getFragmentDataLen() const;
717 
718     /**
719      * Get Range or List Array (value, partition)
720      */
721     const void *getRangeListData() const;
722     Uint32 getRangeListDataLen() const;
723 
724     /**
725      * Get Tablespace Data (id, version)
726      */
727     const void *getTablespaceData() const;
728     Uint32 getTablespaceDataLen() const;
729 
730     /** @} *******************************************************************/
731 
732     /**
733      * @name Table creation
734      * @{
735      *
736      * These methods should normally not be used in an application as
737      * the result is not accessible from the MySQL Server
738      *
739      */
740 
741     /**
742      * Constructor
743      * @param  name   Name of table
744      */
745     Table(const char * name = "");
746 
747     /**
748      * Copy constructor
749      * @param  table  Table to be copied
750      */
751     Table(const Table& table);
752     virtual ~Table();
753 
754     /**
755      * Assignment operator, deep copy
756      * @param  table  Table to be copied
757      */
758     Table& operator=(const Table& table);
759 
760     /**
761      * Name of table
762      * @param  name  Name of table
763      */
764     int setName(const char * name);
765 
766     /**
767      * Add a column definition to a table
768      * @note creates a copy
769      */
770     int addColumn(const Column &);
771 
772     /**
773      * @see NdbDictionary::Table::getLogging.
774      */
775     void setLogging(bool);
776 
777     /**
778      * Set/Get Linear Hash Flag
779      */
780     void setLinearFlag(Uint32 flag);
781     bool getLinearFlag() const;
782 
783     /**
784      * Set fragment count
785      */
786     void setFragmentCount(Uint32);
787 
788     /**
789      * Get fragment count
790      */
791     Uint32 getFragmentCount() const;
792 
793     /**
794      * Set fragmentation type
795      */
796     void setFragmentType(FragmentType);
797 
798     /**
799      * Set KValue (Hash parameter.)
800      * Only allowed value is 6.
801      * Later implementations might add flexibility in this parameter.
802      */
803     void setKValue(int kValue);
804 
805     /**
806      * Set MinLoadFactor  (Hash parameter.)
807      * This value specifies the load factor when starting to shrink
808      * the hash table.
809      * It must be smaller than MaxLoadFactor.
810      * Both these factors are given in percentage.
811      */
812     void setMinLoadFactor(int);
813 
814     /**
815      * Set MaxLoadFactor  (Hash parameter.)
816      * This value specifies the load factor when starting to split
817      * the containers in the local hash tables.
818      * 100 is the maximum which will optimize memory usage.
819      * A lower figure will store less information in each container and thus
820      * find the key faster but consume more memory.
821      */
822     void setMaxLoadFactor(int);
823 
824     int setTablespaceName(const char * name);
825     const char * getTablespaceName() const;
826     int setTablespace(const class Tablespace &);
827     bool getTablespace(Uint32 *id= 0, Uint32 *version= 0) const;
828 
829     /**
830      * Get table object type
831      */
832     Object::Type getObjectType() const;
833 
834     /**
835      * Get object status
836      */
837     virtual Object::Status getObjectStatus() const;
838     void setStatusInvalid() const;
839 
840     /**
841      * Get object version
842      */
843     virtual int getObjectVersion() const;
844 
845     /**
846      * Set/Get indicator if default number of partitions is used in table.
847      */
848     void setDefaultNoPartitionsFlag(Uint32 indicator);
849     Uint32 getDefaultNoPartitionsFlag() const;
850 
851     /**
852      * Get object id
853      */
854     virtual int getObjectId() const;
855 
856     /**
857      * Set frm file to store with this table
858      */
859     int setFrm(const void* data, Uint32 len);
860 
861     /**
862      * Set array of fragment information containing
863      * Fragment Identity
864      * Node group identity
865      * Fragment State
866      */
867     int setFragmentData(const void* data, Uint32 len);
868 
869     /**
870      * Set/Get tablespace names per fragment
871      */
872     int setTablespaceNames(const void* data, Uint32 len);
873     const void *getTablespaceNames();
874     Uint32 getTablespaceNamesLen() const;
875 
876     /**
877      * Set tablespace information per fragment
878      * Contains a tablespace id and a tablespace version
879      */
880     int setTablespaceData(const void* data, Uint32 len);
881 
882     /**
883      * Set array of information mapping range values and list values
884      * to fragments. This is essentially a sorted map consisting of
885      * pairs of value, fragment identity. For range partitions there is
886      * one pair per fragment. For list partitions it could be any number
887      * of pairs, at least as many as there are fragments.
888      */
889     int setRangeListData(const void* data, Uint32 len);
890 
891     /**
892      * Set table object type
893      */
894     void setObjectType(Object::Type type);
895 
896     /**
897      * Set/Get Maximum number of rows in table (only used to calculate
898      * number of partitions).
899      */
900     void setMaxRows(Uint64 maxRows);
901     Uint64 getMaxRows() const;
902 
903     /**
904      * Set/Get Minimum number of rows in table (only used to calculate
905      * number of partitions).
906      */
907     void setMinRows(Uint64 minRows);
908     Uint64 getMinRows() const;
909 
910     /**
911      * Set/Get SingleUserMode
912      */
913     void setSingleUserMode(enum SingleUserMode);
914     enum SingleUserMode getSingleUserMode() const;
915 
916 
917     /** @} *******************************************************************/
918 
919     /**
920      *
921      */
922     void setRowGCIIndicator(bool value);
923     bool getRowGCIIndicator() const;
924 
925     void setRowChecksumIndicator(bool value);
926     bool getRowChecksumIndicator() const;
927 
928 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
929     const char *getMysqlName() const;
930 
setStoredTable(bool x)931     void setStoredTable(bool x) { setLogging(x); }
getStoredTable() const932     bool getStoredTable() const { return getLogging(); }
933 
934     int getRowSizeInBytes() const ;
935     int createTableInDb(Ndb*, bool existingEqualIsOk = true) const ;
936 
937     int getReplicaCount() const ;
938 
939     bool getTemporary();
940     void setTemporary(bool);
941 
942     /**
943      * Only table with varpart do support online add column
944      *   Add property so that table wo/ varsize column(s) still
945      *   allocates varpart-ref, so that later online add column is possible
946      */
947     bool getForceVarPart() const;
948     void setForceVarPart(bool);
949 
950     /**
951      * Check if any of column in bitmaps are disk columns
952      *   returns bitmap of different columns
953      *     bit 0 = atleast 1 pk column is set
954      *     bit 1 = atleast 1 disk column set
955      *     bit 2 = atleast 1 non disk column set
956      *   passing NULL pointer will equal to bitmap with all columns set
957      */
958     int checkColumns(const Uint32* bitmap, unsigned len_in_bytes) const;
959 #endif
960 
961     // these 2 are not de-doxygenated
962 
963     /**
964      * This method is not needed in normal usage.
965      *
966      * Compute aggregate data on table being defined.  Required for
967      * aggregate methods such as getNoOfPrimaryKeys() to work before
968      * table has been created and retrieved via getTable().
969      *
970      * May adjust some column flags.  If no PK is so far marked as
971      * distribution key then all PK's will be marked.
972      *
973      * Returns 0 on success.  Returns -1 and sets error if an
974      * inconsistency is detected.
975      */
976     int aggregate(struct NdbError& error);
977 
978     /**
979      * This method is not needed in normal usage.
980      *
981      * Validate new table definition before create.  Does aggregate()
982      * and additional checks.  There may still be errors which are
983      * detected only by NDB kernel at create table.
984      *
985      * Create table and retrieve table do validate() automatically.
986      *
987      * Returns 0 on success.  Returns -1 and sets error if an
988      * inconsistency is detected.
989      */
990     int validate(struct NdbError& error);
991 
992   private:
993 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
994     friend class Ndb;
995     friend class NdbDictionaryImpl;
996     friend class NdbTableImpl;
997     friend class NdbEventOperationImpl;
998 #endif
999     class NdbTableImpl & m_impl;
1000     Table(NdbTableImpl&);
1001   };
1002 
1003   /**
1004    * @class Index
1005    * @brief Represents an index in an NDB Cluster
1006    */
1007   class Index : public Object {
1008   public:
1009 
1010     /**
1011      * @name Getting Index properties
1012      * @{
1013      */
1014 
1015     /**
1016      * Get the name of an index
1017      */
1018     const char * getName() const;
1019 
1020     /**
1021      * Get the name of the table being indexed
1022      */
1023     const char * getTable() const;
1024 
1025     /**
1026      * Get the number of columns in the index
1027      */
1028     unsigned getNoOfColumns() const;
1029 
1030 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1031     /**
1032      * Get the number of columns in the index
1033      * Depricated, use getNoOfColumns instead.
1034      */
1035     int getNoOfIndexColumns() const;
1036 #endif
1037 
1038     /**
1039      * Get a specific column in the index
1040      */
1041     const Column * getColumn(unsigned no) const ;
1042 
1043 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1044     /**
1045      * Get a specific column name in the index
1046      * Depricated, use getColumn instead.
1047      */
1048     const char * getIndexColumn(int no) const ;
1049 #endif
1050 
1051     /**
1052      * Represents type of index
1053      */
1054     enum Type {
1055       Undefined = 0,          ///< Undefined object type (initial value)
1056       UniqueHashIndex = 3,    ///< Unique un-ordered hash index
1057                               ///< (only one currently supported)
1058       OrderedIndex = 6        ///< Non-unique ordered index
1059     };
1060 
1061     /**
1062      * Get index type of the index
1063      */
1064     Type getType() const;
1065 
1066     /**
1067      * Check if index is set to be stored on disk
1068      *
1069      * @return if true then logging id enabled
1070      *
1071      * @note Non-logged indexes are rebuilt at system restart.
1072      * @note Ordered index does not currently support logging.
1073      */
1074     bool getLogging() const;
1075 
1076     /**
1077      * Get object status
1078      */
1079     virtual Object::Status getObjectStatus() const;
1080 
1081     /**
1082      * Get object version
1083      */
1084     virtual int getObjectVersion() const;
1085 
1086     /**
1087      * Get object id
1088      */
1089     virtual int getObjectId() const;
1090 
1091     /** @} *******************************************************************/
1092 
1093     /**
1094      * @name Index creation
1095      * @{
1096      *
1097      * These methods should normally not be used in an application as
1098      * the result will not be visible from the MySQL Server
1099      *
1100      */
1101 
1102     /**
1103      *  Constructor
1104      *  @param  name  Name of index
1105      */
1106     Index(const char * name = "");
1107     virtual ~Index();
1108 
1109     /**
1110      * Set the name of an index
1111      */
1112     int setName(const char * name);
1113 
1114     /**
1115      * Define the name of the table to be indexed
1116      */
1117     int setTable(const char * name);
1118 
1119     /**
1120      * Add a column to the index definition
1121      * Note that the order of columns will be in
1122      * the order they are added (only matters for ordered indexes).
1123      */
1124     int addColumn(const Column & c);
1125 
1126     /**
1127      * Add a column name to the index definition
1128      * Note that the order of indexes will be in
1129      * the order they are added (only matters for ordered indexes).
1130      */
1131     int addColumnName(const char * name);
1132 
1133 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1134     /**
1135      * Add a column name to the index definition
1136      * Note that the order of indexes will be in
1137      * the order they are added (only matters for ordered indexes).
1138      * Depricated, use addColumnName instead.
1139      */
1140     int addIndexColumn(const char * name);
1141 #endif
1142 
1143     /**
1144      * Add several column names to the index definition
1145      * Note that the order of indexes will be in
1146      * the order they are added (only matters for ordered indexes).
1147      */
1148     int  addColumnNames(unsigned noOfNames, const char ** names);
1149 
1150 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1151     /**
1152      * Add several column names to the index definition
1153      * Note that the order of indexes will be in
1154      * the order they are added (only matters for ordered indexes).
1155      * Depricated, use addColumnNames instead.
1156      */
1157     int addIndexColumns(int noOfNames, const char ** names);
1158 #endif
1159 
1160     /**
1161      * Set index type of the index
1162      */
1163     void setType(Type type);
1164 
1165     /**
1166      * Enable/Disable index storage on disk
1167      *
1168      * @param enable  If enable is set to true, then logging becomes enabled
1169      *
1170      * @see NdbDictionary::Index::getLogging
1171      */
1172     void setLogging(bool enable);
1173 
1174 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
setStoredIndex(bool x)1175     void setStoredIndex(bool x) { setLogging(x); }
getStoredIndex() const1176     bool getStoredIndex() const { return getLogging(); }
1177 
1178     bool getTemporary();
1179     void setTemporary(bool);
1180 #endif
1181 
1182     /** @} *******************************************************************/
1183 
1184   private:
1185 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1186     friend class NdbIndexImpl;
1187     friend class NdbIndexStat;
1188 #endif
1189     class NdbIndexImpl & m_impl;
1190     Index(NdbIndexImpl&);
1191   };
1192 
1193   /**
1194    * @brief Represents an Event in NDB Cluster
1195    *
1196    */
1197   class Event : public Object  {
1198   public:
1199     /**
1200      * Specifies the type of database operations an Event listens to
1201      */
1202 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1203     /** TableEvent must match 1 << TriggerEvent */
1204 #endif
1205     enum TableEvent {
1206       TE_INSERT      =1<<0, ///< Insert event on table
1207       TE_DELETE      =1<<1, ///< Delete event on table
1208       TE_UPDATE      =1<<2, ///< Update event on table
1209 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1210       TE_SCAN        =1<<3, ///< Scan event on table
1211       TE_FIRST_NON_DATA_EVENT =1<<4,
1212 #endif
1213       TE_DROP        =1<<4, ///< Drop of table
1214       TE_ALTER       =1<<5, ///< Alter of table
1215       TE_CREATE      =1<<6, ///< Create of table
1216       TE_GCP_COMPLETE=1<<7, ///< GCP is complete
1217       TE_CLUSTER_FAILURE=1<<8, ///< Cluster is unavailable
1218       TE_STOP        =1<<9, ///< Stop of event operation
1219       TE_NODE_FAILURE=1<<10, ///< Node failed
1220       TE_SUBSCRIBE   =1<<11, ///< Node subscribes
1221       TE_UNSUBSCRIBE =1<<12, ///< Node unsubscribes
1222       TE_ALL=0xFFFF         ///< Any/all event on table (not relevant when
1223                             ///< events are received)
1224     };
1225 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1226     enum _TableEvent {
1227       _TE_INSERT=0,
1228       _TE_DELETE=1,
1229       _TE_UPDATE=2,
1230       _TE_SCAN=3,
1231       _TE_FIRST_NON_DATA_EVENT=4,
1232       _TE_DROP=4,
1233       _TE_ALTER=5,
1234       _TE_CREATE=6,
1235       _TE_GCP_COMPLETE=7,
1236       _TE_CLUSTER_FAILURE=8,
1237       _TE_STOP=9,
1238       _TE_NODE_FAILURE=10,
1239       _TE_SUBSCRIBE=11,
1240       _TE_UNSUBSCRIBE=12,
1241       _TE_NUL=13, // internal (e.g. INS o DEL within same GCI)
1242       _TE_ACTIVE=14 // internal (node becomes active)
1243     };
1244 #endif
1245     /**
1246      *  Specifies the durability of an event
1247      * (future version may supply other types)
1248      */
1249     enum EventDurability {
1250       ED_UNDEFINED
1251 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1252       = 0
1253 #endif
1254 #if 0 // not supported
1255       ,ED_SESSION = 1,
1256       // Only this API can use it
1257       // and it's deleted after api has disconnected or ndb has restarted
1258 
1259       ED_TEMPORARY = 2
1260       // All API's can use it,
1261       // But's its removed when ndb is restarted
1262 #endif
1263       ,ED_PERMANENT    ///< All API's can use it.
1264                        ///< It's still defined after a cluster system restart
1265 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1266       = 3
1267 #endif
1268     };
1269 
1270     /**
1271      * Specifies reporting options for table events
1272      */
1273     enum EventReport {
1274       ER_UPDATED = 0,
1275       ER_ALL = 1, // except not-updated blob inlines
1276       ER_SUBSCRIBE = 2
1277     };
1278 
1279     /**
1280      *  Constructor
1281      *  @param  name  Name of event
1282      */
1283     Event(const char *name);
1284     /**
1285      *  Constructor
1286      *  @param  name  Name of event
1287      *  @param  table Reference retrieved from NdbDictionary
1288      */
1289     Event(const char *name, const NdbDictionary::Table& table);
1290     virtual ~Event();
1291     /**
1292      * Set unique identifier for the event
1293      */
1294     int setName(const char *name);
1295     /**
1296      * Get unique identifier for the event
1297      */
1298     const char *getName() const;
1299     /**
1300      * Get table that the event is defined on
1301      *
1302      * @return pointer to table or NULL if no table has been defined
1303      */
1304     const NdbDictionary::Table * getTable() const;
1305     /**
1306      * Define table on which events should be detected
1307      *
1308      * @note calling this method will default to detection
1309      *       of events on all columns. Calling subsequent
1310      *       addEventColumn calls will override this.
1311      *
1312      * @param table reference retrieved from NdbDictionary
1313      */
1314     void setTable(const NdbDictionary::Table& table);
1315     /**
1316      * Set table for which events should be detected
1317      *
1318      * @note preferred way is using setTable(const NdbDictionary::Table&)
1319      *       or constructor with table object parameter
1320      */
1321     int setTable(const char *tableName);
1322     /**
1323      * Get table name for events
1324      *
1325      * @return table name
1326      */
1327     const char* getTableName() const;
1328     /**
1329      * Add type of event that should be detected
1330      */
1331     void addTableEvent(const TableEvent te);
1332     /**
1333      * Check if a specific table event will be detected
1334      */
1335     bool getTableEvent(const TableEvent te) const;
1336     /**
1337      * Set durability of the event
1338      */
1339     void setDurability(EventDurability);
1340     /**
1341      * Get durability of the event
1342      */
1343     EventDurability getDurability() const;
1344     /**
1345      * Set report option of the event
1346      */
1347     void setReport(EventReport);
1348     /**
1349      * Get report option of the event
1350      */
1351     EventReport getReport() const;
1352 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1353     void addColumn(const Column &c);
1354 #endif
1355     /**
1356      * Add a column on which events should be detected
1357      *
1358      * @param attrId Column id
1359      *
1360      * @note errors will mot be detected until createEvent() is called
1361      */
1362     void addEventColumn(unsigned attrId);
1363     /**
1364      * Add a column on which events should be detected
1365      *
1366      * @param columnName Column name
1367      *
1368      * @note errors will not be detected until createEvent() is called
1369      */
1370     void addEventColumn(const char * columnName);
1371     /**
1372      * Add several columns on which events should be detected
1373      *
1374      * @param n Number of columns
1375      * @param columnNames Column names
1376      *
1377      * @note errors will mot be detected until
1378      *       NdbDictionary::Dictionary::createEvent() is called
1379      */
1380     void addEventColumns(int n, const char ** columnNames);
1381 
1382     /**
1383      * Get no of columns defined in an Event
1384      *
1385      * @return Number of columns, -1 on error
1386      */
1387     int getNoOfEventColumns() const;
1388 
1389     /**
1390      * Get a specific column in the event
1391      */
1392     const Column * getEventColumn(unsigned no) const;
1393 
1394     /**
1395      * The merge events flag is false by default.  Setting it true
1396      * implies that events are merged in following ways:
1397      *
1398      * - for given NdbEventOperation associated with this event,
1399      *   events on same PK within same GCI are merged into single event
1400      *
1401      * - a blob table event is created for each blob attribute
1402      *   and blob events are handled as part of main table events
1403      *
1404      * - blob post/pre data from the blob part events can be read
1405      *   via NdbBlob methods as a single value
1406      *
1407      * NOTE: Currently this flag is not inherited by NdbEventOperation
1408      * and must be set on NdbEventOperation explicitly.
1409      */
1410     void mergeEvents(bool flag);
1411 
1412     /**
1413      * Get object status
1414      */
1415     virtual Object::Status getObjectStatus() const;
1416 
1417     /**
1418      * Get object version
1419      */
1420     virtual int getObjectVersion() const;
1421 
1422     /**
1423      * Get object id
1424      */
1425     virtual int getObjectId() const;
1426 
1427 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1428     void print();
1429 #endif
1430 
1431   private:
1432 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1433     friend class NdbEventImpl;
1434     friend class NdbEventOperationImpl;
1435 #endif
1436     class NdbEventImpl & m_impl;
1437     Event(NdbEventImpl&);
1438   };
1439 
1440   struct AutoGrowSpecification {
1441     Uint32 min_free;
1442     Uint64 max_size;
1443     Uint64 file_size;
1444     const char * filename_pattern;
1445   };
1446 
1447   /**
1448    * @class LogfileGroup
1449    */
1450   class LogfileGroup : public Object {
1451   public:
1452     LogfileGroup();
1453     LogfileGroup(const LogfileGroup&);
1454     virtual ~LogfileGroup();
1455 
1456     void setName(const char * name);
1457     const char* getName() const;
1458 
1459     void setUndoBufferSize(Uint32 sz);
1460     Uint32 getUndoBufferSize() const;
1461 
1462     void setAutoGrowSpecification(const AutoGrowSpecification&);
1463     const AutoGrowSpecification& getAutoGrowSpecification() const;
1464 
1465     Uint64 getUndoFreeWords() const;
1466 
1467     /**
1468      * Get object status
1469      */
1470     virtual Object::Status getObjectStatus() const;
1471 
1472     /**
1473      * Get object version
1474      */
1475     virtual int getObjectVersion() const;
1476 
1477     /**
1478      * Get object id
1479      */
1480     virtual int getObjectId() const;
1481 
1482   private:
1483     friend class NdbDictionaryImpl;
1484     friend class NdbLogfileGroupImpl;
1485     class NdbLogfileGroupImpl & m_impl;
1486     LogfileGroup(NdbLogfileGroupImpl&);
1487   };
1488 
1489   /**
1490    * @class Tablespace
1491    */
1492   class Tablespace : public Object {
1493   public:
1494     Tablespace();
1495     Tablespace(const Tablespace&);
1496     virtual ~Tablespace();
1497 
1498     void setName(const char * name);
1499     const char* getName() const;
1500 
1501     void setExtentSize(Uint32 sz);
1502     Uint32 getExtentSize() const;
1503 
1504     void setAutoGrowSpecification(const AutoGrowSpecification&);
1505     const AutoGrowSpecification& getAutoGrowSpecification() const;
1506 
1507     void setDefaultLogfileGroup(const char * name);
1508     void setDefaultLogfileGroup(const class LogfileGroup&);
1509 
1510     const char * getDefaultLogfileGroup() const;
1511     Uint32 getDefaultLogfileGroupId() const;
1512 
1513     /**
1514      * Get object status
1515      */
1516     virtual Object::Status getObjectStatus() const;
1517 
1518     /**
1519      * Get object version
1520      */
1521     virtual int getObjectVersion() const;
1522 
1523     /**
1524      * Get object id
1525      */
1526     virtual int getObjectId() const;
1527 
1528   private:
1529     friend class NdbTablespaceImpl;
1530     class NdbTablespaceImpl & m_impl;
1531     Tablespace(NdbTablespaceImpl&);
1532   };
1533 
1534   class Datafile : public Object {
1535   public:
1536     Datafile();
1537     Datafile(const Datafile&);
1538     virtual ~Datafile();
1539 
1540     void setPath(const char * name);
1541     const char* getPath() const;
1542 
1543     void setSize(Uint64);
1544     Uint64 getSize() const;
1545     Uint64 getFree() const;
1546 
1547     int setTablespace(const char * name);
1548     int setTablespace(const class Tablespace &);
1549     const char * getTablespace() const;
1550     void getTablespaceId(ObjectId * dst) const;
1551 
1552     void setNode(Uint32 nodeId);
1553     Uint32 getNode() const;
1554 
1555     Uint32 getFileNo() const;
1556 
1557     /**
1558      * Get object status
1559      */
1560     virtual Object::Status getObjectStatus() const;
1561 
1562     /**
1563      * Get object version
1564      */
1565     virtual int getObjectVersion() const;
1566 
1567     /**
1568      * Get object id
1569      */
1570     virtual int getObjectId() const;
1571 
1572   private:
1573     friend class NdbDatafileImpl;
1574     class NdbDatafileImpl & m_impl;
1575     Datafile(NdbDatafileImpl&);
1576   };
1577 
1578   class Undofile : public Object {
1579   public:
1580     Undofile();
1581     Undofile(const Undofile&);
1582     virtual ~Undofile();
1583 
1584     void setPath(const char * path);
1585     const char* getPath() const;
1586 
1587     void setSize(Uint64);
1588     Uint64 getSize() const;
1589 
1590     void setLogfileGroup(const char * name);
1591     void setLogfileGroup(const class LogfileGroup &);
1592     const char * getLogfileGroup() const;
1593     void getLogfileGroupId(ObjectId * dst) const;
1594 
1595     void setNode(Uint32 nodeId);
1596     Uint32 getNode() const;
1597 
1598     Uint32 getFileNo() const;
1599 
1600     /**
1601      * Get object status
1602      */
1603     virtual Object::Status getObjectStatus() const;
1604 
1605     /**
1606      * Get object version
1607      */
1608     virtual int getObjectVersion() const;
1609 
1610     /**
1611      * Get object id
1612      */
1613     virtual int getObjectId() const;
1614 
1615   private:
1616     friend class NdbUndofileImpl;
1617     class NdbUndofileImpl & m_impl;
1618     Undofile(NdbUndofileImpl&);
1619   };
1620 
1621   /**
1622    * @class Dictionary
1623    * @brief Dictionary for defining and retreiving meta data
1624    */
1625   class Dictionary {
1626   public:
1627     /**
1628      * @class List
1629      * @brief Structure for retrieving lists of object names
1630      */
1631     struct List {
1632       /**
1633        * @struct  Element
1634        * @brief   Object to be stored in an NdbDictionary::Dictionary::List
1635        */
1636       struct Element {
1637 	unsigned id;            ///< Id of object
1638         Object::Type type;      ///< Type of object
1639         Object::State state;    ///< State of object
1640         Object::Store store;    ///< How object is logged
1641         Uint32 temp;            ///< Temporary status of object
1642 	char * database;        ///< In what database the object resides
1643 	char * schema;          ///< What schema the object is defined in
1644 	char * name;            ///< Name of object
ElementNdbDictionary::Dictionary::List::Element1645         Element() :
1646           id(0),
1647           type(Object::TypeUndefined),
1648           state(Object::StateUndefined),
1649           store(Object::StoreUndefined),
1650           temp(NDB_TEMP_TAB_PERMANENT),
1651 	  database(0),
1652 	  schema(0),
1653           name(0) {
1654         }
1655       };
1656       unsigned count;           ///< Number of elements in list
1657       Element * elements;       ///< Pointer to array of elements
ListNdbDictionary::Dictionary::List1658       List() : count(0), elements(0) {}
~ListNdbDictionary::Dictionary::List1659       ~List() {
1660         if (elements != 0) {
1661           for (unsigned i = 0; i < count; i++) {
1662             delete[] elements[i].database;
1663             delete[] elements[i].schema;
1664             delete[] elements[i].name;
1665             elements[i].name = 0;
1666           }
1667           delete[] elements;
1668           count = 0;
1669           elements = 0;
1670         }
1671       }
1672     };
1673 
1674     /**
1675      * @name General
1676      * @{
1677      */
1678 
1679     /**
1680      * Fetch list of all objects, optionally restricted to given type.
1681      *
1682      * @param list   List of objects returned in the dictionary
1683      * @param type   Restrict returned list to only contain objects of
1684      *               this type
1685      *
1686      * @return       -1 if error.
1687      *
1688      */
1689     int listObjects(List & list, Object::Type type = Object::TypeUndefined);
1690     int listObjects(List & list,
1691 		    Object::Type type = Object::TypeUndefined) const;
1692 
1693     /**
1694      * Get the latest error
1695      *
1696      * @return   Error object.
1697      */
1698     const struct NdbError & getNdbError() const;
1699 
1700     /** @} *******************************************************************/
1701 
1702     /**
1703      * @name Retrieving references to Tables and Indexes
1704      * @{
1705      */
1706 
1707     /**
1708      * Get table with given name, NULL if undefined
1709      * @param name   Name of table to get
1710      * @return table if successful otherwise NULL.
1711      */
1712     const Table * getTable(const char * name) const;
1713 
1714 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1715     /**
1716      * Given main table, get blob table.
1717      */
1718     const Table * getBlobTable(const Table *, const char * col_name);
1719     const Table * getBlobTable(const Table *, Uint32 col_no);
1720 
1721     /*
1722      * Save a table definition in dictionary cache
1723      * @param table Object to put into cache
1724      */
1725     void putTable(const Table * table);
1726 #endif
1727 
1728     /**
1729      * Get index with given name, NULL if undefined
1730      * @param indexName  Name of index to get.
1731      * @param tableName  Name of table that index belongs to.
1732      * @return  index if successful, otherwise 0.
1733      */
1734     const Index * getIndex(const char * indexName,
1735 			   const char * tableName) const;
1736 
1737     /**
1738      * Fetch list of indexes of given table.
1739      * @param list  Reference to list where to store the listed indexes
1740      * @param tableName  Name of table that index belongs to.
1741      * @return  0 if successful, otherwise -1
1742      */
1743     int listIndexes(List & list, const char * tableName);
1744     int listIndexes(List & list, const char * tableName) const;
1745 
1746 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1747     /**
1748      * Fetch list of indexes of given table.
1749      * @param list  Reference to list where to store the listed indexes
1750      * @param table  Reference to table that index belongs to.
1751      * @return  0 if successful, otherwise -1
1752      */
1753     int listIndexes(List & list, const Table &table) const;
1754 #endif
1755 
1756     /** @} *******************************************************************/
1757     /**
1758      * @name Events
1759      * @{
1760      */
1761 
1762     /**
1763      * Create event given defined Event instance
1764      * @param event Event to create
1765      * @return 0 if successful otherwise -1.
1766      */
1767     int createEvent(const Event &event);
1768 
1769     /**
1770      * Drop event with given name
1771      * @param eventName  Name of event to drop.
1772      * @return 0 if successful otherwise -1.
1773      */
1774     int dropEvent(const char * eventName);
1775 
1776     /**
1777      * Get event with given name.
1778      * @param eventName  Name of event to get.
1779      * @return an Event if successful, otherwise NULL.
1780      */
1781     const Event * getEvent(const char * eventName);
1782 
1783     /** @} *******************************************************************/
1784 
1785     /**
1786      * @name Table creation
1787      * @{
1788      *
1789      * These methods should normally not be used in an application as
1790      * the result will not be visible from the MySQL Server
1791      */
1792 
1793     /**
1794      * Create defined table given defined Table instance
1795      * @param table Table to create
1796      * @return 0 if successful otherwise -1.
1797      */
1798     int createTable(const Table &table);
1799 
1800     /**
1801      * Drop table given retrieved Table instance
1802      * @param table Table to drop
1803      * @return 0 if successful otherwise -1.
1804      */
1805     int dropTable(Table & table);
1806 
1807     /**
1808      * Drop table given table name
1809      * @param name   Name of table to drop
1810      * @return 0 if successful otherwise -1.
1811      */
1812     int dropTable(const char * name);
1813 
1814 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1815     /**
1816      * Alter defined table given defined Table instance
1817      * @param table Table to alter
1818      * @return  -2 (incompatible version) <br>
1819      *          -1 general error          <br>
1820      *           0 success
1821      */
1822     int alterTable(const Table &table);
1823 
1824     /**
1825      * Invalidate cached table object
1826      * @param name  Name of table to invalidate
1827      */
1828     void invalidateTable(const char * name);
1829 #endif
1830 
1831     /**
1832      * Remove table from local cache
1833      */
1834     void removeCachedTable(const char * table);
1835     /**
1836      * Remove index from local cache
1837      */
1838     void removeCachedIndex(const char * index, const char * table);
1839 
1840 
1841     /** @} *******************************************************************/
1842     /**
1843      * @name Index creation
1844      * @{
1845      *
1846      * These methods should normally not be used in an application as
1847      * the result will not be visible from the MySQL Server
1848      *
1849      */
1850 
1851     /**
1852      * Create index given defined Index instance
1853      * @param index Index to create
1854      * @return 0 if successful otherwise -1.
1855      */
1856     int createIndex(const Index &index);
1857     int createIndex(const Index &index, const Table &table);
1858 
1859     /**
1860      * Drop index with given name
1861      * @param indexName  Name of index to drop.
1862      * @param tableName  Name of table that index belongs to.
1863      * @return 0 if successful otherwise -1.
1864      */
1865     int dropIndex(const char * indexName,
1866 		  const char * tableName);
1867 
1868 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1869     void removeCachedTable(const Table *table);
1870     void removeCachedIndex(const Index *index);
1871     void invalidateTable(const Table *table);
1872     /**
1873      * Invalidate cached index object
1874      */
1875     void invalidateIndex(const char * indexName,
1876                          const char * tableName);
1877     void invalidateIndex(const Index *index);
1878     /**
1879      * Force gcp and wait for gcp complete
1880      */
1881     int forceGCPWait();
1882 #endif
1883 
1884     /** @} *******************************************************************/
1885 
1886     /** @} *******************************************************************/
1887     /**
1888      * @name Disk data objects
1889      * @{
1890      */
1891 
1892     int createLogfileGroup(const LogfileGroup &, ObjectId* = 0);
1893     int dropLogfileGroup(const LogfileGroup&);
1894     LogfileGroup getLogfileGroup(const char * name);
1895 
1896     int createTablespace(const Tablespace &, ObjectId* = 0);
1897     int dropTablespace(const Tablespace&);
1898     Tablespace getTablespace(const char * name);
1899     Tablespace getTablespace(Uint32 tablespaceId);
1900 
1901     int createDatafile(const Datafile &, bool overwrite_existing = false, ObjectId* = 0);
1902     int dropDatafile(const Datafile&);
1903     Datafile getDatafile(Uint32 node, const char * path);
1904 
1905     int createUndofile(const Undofile &, bool overwrite_existing = false, ObjectId * = 0);
1906     int dropUndofile(const Undofile&);
1907     Undofile getUndofile(Uint32 node, const char * path);
1908 
1909     /** @} *******************************************************************/
1910 
1911   protected:
1912     Dictionary(Ndb & ndb);
1913     ~Dictionary();
1914 
1915   private:
1916 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1917     friend class NdbDictionaryImpl;
1918     friend class UtilTransactions;
1919     friend class NdbBlob;
1920 #endif
1921     class NdbDictionaryImpl & m_impl;
1922     Dictionary(NdbDictionaryImpl&);
1923     const Table * getIndexTable(const char * indexName,
1924 				const char * tableName) const;
1925   public:
1926 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1927     const Table * getTable(const char * name, void **data) const;
1928     void set_local_table_data_size(unsigned sz);
1929 
1930     const Index * getIndexGlobal(const char * indexName,
1931                                  const Table &ndbtab) const;
1932     const Table * getTableGlobal(const char * tableName) const;
1933     int alterTableGlobal(const Table &f, const Table &t);
1934     int dropTableGlobal(const Table &ndbtab);
1935     int dropIndexGlobal(const Index &index);
1936     int removeIndexGlobal(const Index &ndbidx, int invalidate) const;
1937     int removeTableGlobal(const Table &ndbtab, int invalidate) const;
1938 #endif
1939   };
1940 };
1941 
1942 class NdbOut& operator <<(class NdbOut& out, const NdbDictionary::Column& col);
1943 
1944 #endif
1945