MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbSqlUtil.hpp
1 /*
2  Copyright (c) 2003, 2011, 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 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 St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NDB_SQL_UTIL_HPP
19 #define NDB_SQL_UTIL_HPP
20 
21 #include <ndb_global.h>
22 #include <kernel/ndb_limits.h>
23 
24 struct charset_info_st;
25 typedef struct charset_info_st CHARSET_INFO;
26 
37 class NdbSqlUtil {
38 public:
51  typedef int Cmp(const void* info, const void* p1, uint n1, const void* p2, uint n2);
52 
60  typedef int Like(const void* info, const void* p1, unsigned n1, const void* p2, unsigned n2);
61 
69  typedef int AndMask(const void* data, unsigned dataLen, const void* mask, unsigned maskLen, bool cmpZero);
70 
71  struct Type {
72  enum Enum {
73  Undefined = NDB_TYPE_UNDEFINED,
74  Tinyint = NDB_TYPE_TINYINT,
75  Tinyunsigned = NDB_TYPE_TINYUNSIGNED,
76  Smallint = NDB_TYPE_SMALLINT,
77  Smallunsigned = NDB_TYPE_SMALLUNSIGNED,
78  Mediumint = NDB_TYPE_MEDIUMINT,
79  Mediumunsigned = NDB_TYPE_MEDIUMUNSIGNED,
80  Int = NDB_TYPE_INT,
81  Unsigned = NDB_TYPE_UNSIGNED,
82  Bigint = NDB_TYPE_BIGINT,
83  Bigunsigned = NDB_TYPE_BIGUNSIGNED,
84  Float = NDB_TYPE_FLOAT,
85  Double = NDB_TYPE_DOUBLE,
86  Olddecimal = NDB_TYPE_OLDDECIMAL,
87  Char = NDB_TYPE_CHAR,
88  Varchar = NDB_TYPE_VARCHAR,
89  Binary = NDB_TYPE_BINARY,
90  Varbinary = NDB_TYPE_VARBINARY,
91  Datetime = NDB_TYPE_DATETIME,
92  Date = NDB_TYPE_DATE,
93  Blob = NDB_TYPE_BLOB,
94  Text = NDB_TYPE_TEXT,
95  Bit = NDB_TYPE_BIT,
96  Longvarchar = NDB_TYPE_LONGVARCHAR,
97  Longvarbinary = NDB_TYPE_LONGVARBINARY,
98  Time = NDB_TYPE_TIME,
99  Year = NDB_TYPE_YEAR,
100  Timestamp = NDB_TYPE_TIMESTAMP,
101  Olddecimalunsigned = NDB_TYPE_OLDDECIMALUNSIGNED,
102  Decimal = NDB_TYPE_DECIMAL,
103  Decimalunsigned = NDB_TYPE_DECIMALUNSIGNED
104  };
105  Enum m_typeId; // redundant
106  Cmp* m_cmp; // comparison method
107  Like* m_like; // "like" comparison method
108  AndMask* m_mask; // Mask comparison method
109  };
110 
114  static const Type& getType(Uint32 typeId);
115 
119  static uint check_column_for_pk(Uint32 typeId, const void* info);
120  static uint check_column_for_hash_index(Uint32 typeId, const void* info);
121  static uint check_column_for_ordered_index(Uint32 typeId, const void* info);
122 
128  static bool get_var_length(Uint32 typeId, const void* p, unsigned attrlen, Uint32& lb, Uint32& len);
129 
133  static int strnxfrm_bug7284(CHARSET_INFO* cs, unsigned char* dst, unsigned dstLen, const unsigned char*src, unsigned srcLen);
134 
138  static size_t ndb_strnxfrm(struct charset_info_st * cs,
139  uchar *dst, size_t dstlen,
140  const uchar *src, size_t srclen);
141 
148  static void convertByteOrder(Uint32 typeId,
149  Uint32 typeLog2Size,
150  Uint32 arrayType,
151  Uint32 arraySize,
152  uchar* data,
153  Uint32 dataByteSize);
154 
155 private:
156  friend class NdbPack;
160  static const Type m_typeList[];
164  static Cmp cmpTinyint;
165  static Cmp cmpTinyunsigned;
166  static Cmp cmpSmallint;
167  static Cmp cmpSmallunsigned;
168  static Cmp cmpMediumint;
169  static Cmp cmpMediumunsigned;
170  static Cmp cmpInt;
171  static Cmp cmpUnsigned;
172  static Cmp cmpBigint;
173  static Cmp cmpBigunsigned;
174  static Cmp cmpFloat;
175  static Cmp cmpDouble;
176  static Cmp cmpOlddecimal;
177  static Cmp cmpChar;
178  static Cmp cmpVarchar;
179  static Cmp cmpBinary;
180  static Cmp cmpVarbinary;
181  static Cmp cmpDatetime;
182  static Cmp cmpDate;
183  static Cmp cmpBlob;
184  static Cmp cmpText;
185  static Cmp cmpBit;
186  static Cmp cmpLongvarchar;
187  static Cmp cmpLongvarbinary;
188  static Cmp cmpTime;
189  static Cmp cmpYear;
190  static Cmp cmpTimestamp;
191  static Cmp cmpOlddecimalunsigned;
192  static Cmp cmpDecimal;
193  static Cmp cmpDecimalunsigned;
194  //
195  static Like likeChar;
196  static Like likeBinary;
197  static Like likeVarchar;
198  static Like likeVarbinary;
199  static Like likeLongvarchar;
200  static Like likeLongvarbinary;
201  //
202  static AndMask maskBit;
203 };
204 
205 #endif