MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbSchemaOp.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 
20 /*****************************************************************************
21 Name: NdbSchemaOp.cpp
22 Include:
23 Link:
24 Author: UABMNST Mona Natterkvist UAB/B/SD
25  EMIKRON Mikael Ronstrom
26 Date: 040524
27 Version: 3.0
28 Description: Interface between application and NDB
29 Documentation: Handles createTable and createAttribute calls
30 
31 Adjust: 980125 UABMNST First version.
32  020826 EMIKRON New version for new DICT
33  040524 Magnus Svensson - Adapted to not be included in public NdbApi
34  unless the user wants to use it.
35 
36  NOTE: This file is only used as a compatibility layer for old test programs,
37  New programs should use NdbDictionary.hpp
38 *****************************************************************************/
39 
40 #include <ndb_global.h>
41 #include <NdbApi.hpp>
42 #include <NdbSchemaOp.hpp>
43 #include <NdbSchemaCon.hpp>
44 
45 
46 /*****************************************************************************
47 NdbSchemaOp(Ndb* aNdb, Table* aTable);
48 
49 Return Value: None
50 Parameters: aNdb: Pointers to the Ndb object.
51  aTable: Pointers to the Table object
52 Remark: Creat an object of NdbSchemaOp.
53 *****************************************************************************/
54 NdbSchemaOp::NdbSchemaOp(Ndb* aNdb) :
55  theNdb(aNdb),
56  theSchemaCon(NULL),
57  m_currentTable(NULL)
58 {
59 }//NdbSchemaOp::NdbSchemaOp()
60 
61 /*****************************************************************************
62 ~NdbSchemaOp();
63 
64 Remark: Delete tables for connection pointers (id).
65 *****************************************************************************/
66 NdbSchemaOp::~NdbSchemaOp( )
67 {
68 }//~NdbSchemaOp::NdbSchemaOp()
69 
70 /*****************************************************************************
71 int createTable( const char* tableName )
72 *****************************************************************************/
73 int
74 NdbSchemaOp::createTable(const char* aTableName,
75  Uint32 aTableSize,
76  KeyType aTupleKey,
77  int aNrOfPages,
78  FragmentType aFragmentType,
79  int aKValue,
80  int aMinLoadFactor,
81  int aMaxLoadFactor,
82  int aMemoryType,
83  bool aStoredTable)
84 {
85  if(m_currentTable != 0){
86  return -1;
87  }
88 
89  m_currentTable = new NdbDictionary::Table(aTableName);
90  m_currentTable->setKValue(aKValue);
91  m_currentTable->setMinLoadFactor(aMinLoadFactor);
92  m_currentTable->setMaxLoadFactor(aMaxLoadFactor);
93  m_currentTable->setLogging(aStoredTable);
95  return 0;
96 }//NdbSchemaOp::createTable()
97 
98 /******************************************************************************
99 int createAttribute( const char* anAttrName,
100  KeyType aTupleyKey,
101  int anAttrSize,
102  int anArraySize,
103  AttrType anAttrType,
104  SafeType aSafeType,
105  StorageMode aStorageMode,
106  int aNullAttr,
107  int aStorageAttr );
108 
109 ******************************************************************************/
110 int
111 NdbSchemaOp::createAttribute( const char* anAttrName,
112  KeyType aTupleKey,
113  int anAttrSize,
114  int anArraySize,
115  AttrType anAttrType,
116  StorageMode aStorageMode,
117  bool nullable,
118  int aStorageAttr,
119  int aDistributionKeyFlag,
120  int aDistributionGroupFlag,
121  int aDistributionGroupNoOfBits,
122  bool aAutoIncrement,
123  const char* aDefaultValue)
124 {
125  if (m_currentTable == 0){
126  return -1;
127  }//if
128 
129  NdbDictionary::Column col(anAttrName);
130  switch(anAttrType){
131  case Signed:
132  if(anAttrSize == 64)
134  else
136  break;
137  case UnSigned:
138  if(anAttrSize == 64)
140  else
142  break;
143  case Float:
144  if(anAttrSize == 64)
146  else
148  break;
149  case String:
151  break;
152  case NoAttrTypeDef:
153  abort();
154  }
155  col.setLength(anArraySize);
156  col.setNullable(nullable);
157  if(aTupleKey != NoKey)
158  col.setPrimaryKey(true);
159  else
160  col.setPrimaryKey(false);
161 
162  col.setDistributionKey(aDistributionKeyFlag);
163  col.setAutoIncrement(aAutoIncrement);
164  col.setDefaultValue(aDefaultValue != 0 ? aDefaultValue : "");
165 
166  m_currentTable->addColumn(col);
167  return 0;
168 }
169 
170 /******************************************************************************
171 void release();
172 
173 Remark: Release all objects connected to the schemaop object.
174 ******************************************************************************/
175 void
176 NdbSchemaOp::release(){
177 }//NdbSchemaOp::release()
178 
179 /******************************************************************************
180 int sendRec()
181 
182 Return Value: Return 0 : send was succesful.
183  Return -1: In all other case.
184 Parameters:
185 Remark: Send and receive signals for schema transaction based on state
186 ******************************************************************************/
187 int
188 NdbSchemaOp::sendRec(){
189  int retVal = 0;
190  if(m_currentTable == 0){
191  retVal = -1;
192  } else {
193  retVal = theNdb->getDictionary()->createTable(* m_currentTable);
194  delete m_currentTable;
195  theSchemaCon->theError.code = theNdb->getDictionary()->getNdbError().code;
196  }
197 
198  return retVal;
199 }//NdbSchemaOp::sendRec()
200 
201 /******************************************************************************
202 int init();
203 
204 Return Value: Return 0 : init was successful.
205  Return -1: In all other case.
206 Remark: Initiates SchemaOp record after allocation.
207 ******************************************************************************/
208 int
209 NdbSchemaOp::init(NdbSchemaCon* aSchemaCon)
210 {
211  theSchemaCon = aSchemaCon;
212  return 0;
213 }//NdbSchemaOp::init()
214 
215 
216 const NdbError &
217 NdbSchemaOp::getNdbError() const
218 {
219  return theSchemaCon->getNdbError();
220 }
221