📄 ndbdictionary.hpp
字号:
/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef NdbDictionary_H#define NdbDictionary_H#include <ndb_types.h>class Ndb;struct charset_info_st;typedef struct charset_info_st CHARSET_INFO;/** * @class NdbDictionary * @brief Data dictionary class * * The preferred and supported way to create and drop tables and indexes * in ndb is through the * MySQL Server (see MySQL reference Manual, section MySQL Cluster). * * Tables and indexes that are created directly through the * NdbDictionary class * can not be viewed from the MySQL Server. * Dropping indexes directly via the NdbApi will cause inconsistencies * if they were originally created from a MySQL Cluster. * * This class supports schema data enquiries such as: * -# Enquiries about tables * (Dictionary::getTable, Table::getNoOfColumns, * Table::getPrimaryKey, and Table::getNoOfPrimaryKeys) * -# Enquiries about indexes * (Dictionary::getIndex, Index::getNoOfColumns, * and Index::getColumn) * * This class supports schema data definition such as: * -# Creating tables (Dictionary::createTable) and table columns * -# Dropping tables (Dictionary::dropTable) * -# Creating secondary indexes (Dictionary::createIndex) * -# Dropping secondary indexes (Dictionary::dropIndex) * * NdbDictionary has several help (inner) classes to support this: * -# NdbDictionary::Dictionary the dictionary handling dictionary objects * -# NdbDictionary::Table for creating tables * -# NdbDictionary::Column for creating table columns * -# NdbDictionary::Index for creating secondary indexes * * See @ref ndbapi_simple_index.cpp for details of usage. */class NdbDictionary {public: NdbDictionary() {} /* Remove gcc warning */ /** * @class Object * @brief Meta information about a database object (a table, index, etc) */ class Object { public: Object() {} /* Remove gcc warning */ virtual ~Object() {} /* Remove gcc warning */ /** * Status of object */ enum Status { New, ///< The object only exist in memory and ///< has not been created in the NDB Kernel Changed, ///< The object has been modified in memory ///< and has to be commited in NDB Kernel for ///< changes to take effect Retrieved, ///< The object exist and has been read ///< into main memory from NDB Kernel Invalid, ///< The object has been invalidated ///< and should not be used Altered ///< Table has been altered in NDB kernel ///< but is still valid for usage }; /** * Get status of object */ virtual Status getObjectStatus() const = 0; /** * Get version of object */ virtual int getObjectVersion() const = 0; /** * Object type */ enum Type { TypeUndefined = 0, ///< Undefined SystemTable = 1, ///< System table UserTable = 2, ///< User table (may be temporary) UniqueHashIndex = 3, ///< Unique un-ordered hash index OrderedIndex = 6, ///< Non-unique ordered index HashIndexTrigger = 7, ///< Index maintenance, internal IndexTrigger = 8, ///< Index maintenance, internal SubscriptionTrigger = 9,///< Backup or replication, internal ReadOnlyConstraint = 10 ///< Trigger, internal }; /** * Object state */ enum State { StateUndefined = 0, ///< Undefined StateOffline = 1, ///< Offline, not usable StateBuilding = 2, ///< Building, not yet usable StateDropping = 3, ///< Offlining or dropping, not usable StateOnline = 4, ///< Online, usable StateBackup = 5, ///< Online, being backuped, usable StateBroken = 9 ///< Broken, should be dropped and re-created }; /** * Object store */ enum Store { StoreUndefined = 0, ///< Undefined StoreTemporary = 1, ///< Object or data deleted on system restart StorePermanent = 2 ///< Permanent. logged to disk }; /** * Type of fragmentation. * * This parameter specifies how data in the table or index will * be distributed among the db nodes in the cluster.<br> * The bigger the table the more number of fragments should be used. * Note that all replicas count as same "fragment".<br> * For a table, default is FragAllMedium. For a unique hash index, * default is taken from underlying table and cannot currently * be changed. */ enum FragmentType { FragUndefined = 0, ///< Fragmentation type undefined or default FragSingle = 1, ///< Only one fragment FragAllSmall = 2, ///< One fragment per node, default FragAllMedium = 3, ///< two fragments per node FragAllLarge = 4 ///< Four fragments per node. }; }; class Table; // forward declaration /** * @class Column * @brief Represents a column in an NDB Cluster table * * Each column has a type. The type of a column is determined by a number * of type specifiers. * The type specifiers are: * - Builtin type * - Array length or max length * - Precision and scale (not used yet) * - Character set for string types * - Inline and part sizes for blobs * * Types in general correspond to MySQL types and their variants. * Data formats are same as in MySQL. NDB API provides no support for * constructing such formats. NDB kernel checks them however. */ class Column { public: /** * The builtin column types */ enum Type { Undefined = NDB_TYPE_UNDEFINED, ///< Undefined Tinyint = NDB_TYPE_TINYINT, ///< 8 bit. 1 byte signed integer, can be used in array Tinyunsigned = NDB_TYPE_TINYUNSIGNED, ///< 8 bit. 1 byte unsigned integer, can be used in array Smallint = NDB_TYPE_SMALLINT, ///< 16 bit. 2 byte signed integer, can be used in array Smallunsigned = NDB_TYPE_SMALLUNSIGNED, ///< 16 bit. 2 byte unsigned integer, can be used in array Mediumint = NDB_TYPE_MEDIUMINT, ///< 24 bit. 3 byte signed integer, can be used in array Mediumunsigned = NDB_TYPE_MEDIUMUNSIGNED,///< 24 bit. 3 byte unsigned integer, can be used in array Int = NDB_TYPE_INT, ///< 32 bit. 4 byte signed integer, can be used in array Unsigned = NDB_TYPE_UNSIGNED, ///< 32 bit. 4 byte unsigned integer, can be used in array Bigint = NDB_TYPE_BIGINT, ///< 64 bit. 8 byte signed integer, can be used in array Bigunsigned = NDB_TYPE_BIGUNSIGNED, ///< 64 Bit. 8 byte signed integer, can be used in array Float = NDB_TYPE_FLOAT, ///< 32-bit float. 4 bytes float, can be used in array Double = NDB_TYPE_DOUBLE, ///< 64-bit float. 8 byte float, can be used in array Olddecimal = NDB_TYPE_OLDDECIMAL, ///< MySQL < 5.0 signed decimal, Precision, Scale Olddecimalunsigned = NDB_TYPE_OLDDECIMALUNSIGNED, Decimal = NDB_TYPE_DECIMAL, ///< MySQL >= 5.0 signed decimal, Precision, Scale Decimalunsigned = NDB_TYPE_DECIMALUNSIGNED, Char = NDB_TYPE_CHAR, ///< Len. A fixed array of 1-byte chars Varchar = NDB_TYPE_VARCHAR, ///< Length bytes: 1, Max: 255 Binary = NDB_TYPE_BINARY, ///< Len Varbinary = NDB_TYPE_VARBINARY, ///< Length bytes: 1, Max: 255 Datetime = NDB_TYPE_DATETIME, ///< Precision down to 1 sec (sizeof(Datetime) == 8 bytes ) Date = NDB_TYPE_DATE, ///< Precision down to 1 day(sizeof(Date) == 4 bytes ) Blob = NDB_TYPE_BLOB, ///< Binary large object (see NdbBlob) Text = NDB_TYPE_TEXT, ///< Text blob Bit = NDB_TYPE_BIT, ///< Bit, length specifies no of bits Longvarchar = NDB_TYPE_LONGVARCHAR, ///< Length bytes: 2, little-endian Longvarbinary = NDB_TYPE_LONGVARBINARY, ///< Length bytes: 2, little-endian Time = NDB_TYPE_TIME, ///< Time without date Year = NDB_TYPE_YEAR, ///< Year 1901-2155 (1 byte) Timestamp = NDB_TYPE_TIMESTAMP ///< Unix time }; /** * @name General * @{ */ /** * Get name of column * @return Name of the column */ const char* getName() const; /** * Get if the column is nullable or not */ bool getNullable() const; /** * Check if column is part of primary key */ bool getPrimaryKey() const; /** * Get number of column (horizontal position within table) */ int getColumnNo() const; /** * Check if column is equal to some other column * @param column Column to compare with * @return true if column is equal to some other column otherwise false. */ bool equal(const Column& column) const; /** @} *******************************************************************/ /** * @name Get Type Specifiers * @{ */ /** * Get type of column */ Type getType() const; /** * Get precision of column. * @note Only applicable for decimal types */ int getPrecision() const; /** * Get scale of column. * @note Only applicable for decimal types */ int getScale() const; /** * Get length for column * Array length for column or max length for variable length arrays. */ int getLength() const; /** * For Char or Varchar or Text, get MySQL CHARSET_INFO. This * specifies both character set and collation. See get_charset() * etc in MySQL. (The cs is not "const" in MySQL). */ CHARSET_INFO* getCharset() const; /** * For blob, get "inline size" i.e. number of initial bytes * to store in table's blob attribute. This part is normally in * main memory and can be indexed and interpreted. */ int getInlineSize() const; /** * For blob, get "part size" i.e. number of bytes to store in * each tuple of the "blob table". Can be set to zero to omit parts * and to allow only inline bytes ("tinyblob"). */ int getPartSize() const; /** * For blob, set or get "stripe size" i.e. number of consecutive * <em>parts</em> to store in each node group. */ int getStripeSize() const; /** * Get size of element */ int getSize() const; /** * Check if column is part of partition key * * A <em>partition key</em> is a set of attributes which are used * to distribute the tuples onto the NDB nodes. * The partition key uses the NDB Cluster hashing function. * * An example where this is useful is TPC-C where it might be * good to use the warehouse id and district id as the partition key. * This would place all data for a specific district and warehouse * in the same database node. * * Locally in the fragments the full primary key * will still be used with the hashing algorithm. * * @return true then the column is part of * the partition key. */ bool getPartitionKey() const;#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED inline bool getDistributionKey() const { return getPartitionKey(); };#endif /** @} *******************************************************************/ /** * @name Column creation * @{ * * These operations should normally not be performed in an NbdApi program * as results will not be visable in the MySQL Server * */ /** * Constructor * @param name Name of column */ Column(const char * name = ""); /** * Copy constructor * @param column Column to be copied */ Column(const Column& column); ~Column(); /** * Set name of column * @param name Name of the column */ int setName(const char * name); /** * Set whether column is nullable or not */ void setNullable(bool); /** * Set that column is part of primary key */ void setPrimaryKey(bool); /** * Set type of column * @param type Type of column * * @note setType resets <em>all</em> column attributes * to (type dependent) defaults and should be the first * method to call. Default type is Unsigned. */ void setType(Type type); /** * Set precision of column. * @note Only applicable for decimal types */ void setPrecision(int); /** * Set scale of column. * @note Only applicable for decimal types */ void setScale(int); /** * Set length for column * Array length for column or max length for variable length arrays. */ void setLength(int length); /** * For Char or Varchar or Text, get MySQL CHARSET_INFO. This
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -