MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbSchemaCon.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 /*********************************************************************
22 Name: NdbSchemaCon.cpp
23 Include:
24 Link:
25 Author: UABMNST Mona Natterkvist UAB/B/SD
26  EMIKRON Mikael Ronstrom
27 Date: 020826
28 Version: 3.0
29 Description: Old Interface between application and NDB
30 Documentation:
31 Adjust: 980126 UABMNST First version.
32  020826 EMIKRON New version adapted to new DICT version
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 <NdbSchemaCon.hpp>
43 #include <NdbSchemaOp.hpp>
44 
45 
46 /*********************************************************************
47 NdbSchemaCon(Ndb* aNdb);
48 
49 Parameters: aNdb: Pointers to the Ndb object
50 Remark: Creates a schemacon object.
51 ************************************************************************************************/
52 NdbSchemaCon::NdbSchemaCon( Ndb* aNdb ) :
53  theNdb(aNdb),
54  theFirstSchemaOpInList(NULL),
55  theMagicNumber(0x75318642)
56 {
57  theError.code = 0;
58 }//NdbSchemaCon::NdbSchemaCon()
59 
60 /*********************************************************************
61 ~NdbSchemaCon();
62 
63 Remark: Deletes the connection object.
64 ************************************************************************************************/
65 NdbSchemaCon::~NdbSchemaCon()
66 {
67 }//NdbSchemaCon::~NdbSchemaCon()
68 
69 /*********************************************************************
70 NdbSchemaOp* getNdbSchemaOp();
71 
72 Return Value Return a pointer to a NdbSchemaOp object if getNdbSchemaOp was sussesful.
73  Return NULL: In all other case.
74 Parameters: tableId : Id of the database table beeing deleted.
75 ************************************************************************************************/
78 {
79  NdbSchemaOp* tSchemaOp;
80  if (theFirstSchemaOpInList != NULL) {
81  theError.code = 4401; // Only support one add table per transaction
82  return NULL;
83  }//if
84  tSchemaOp = new NdbSchemaOp(theNdb);
85  if ( tSchemaOp == NULL ) {
86  theError.code = 4000; // Could not allocate schema operation
87  return NULL;
88  }//if
89  theFirstSchemaOpInList = tSchemaOp;
90  int retValue = tSchemaOp->init(this);
91  if (retValue == -1) {
92  release();
93  theError.code = 4000; // Could not allocate buffer in schema operation
94  return NULL;
95  }//if
96  return tSchemaOp;
97 }//NdbSchemaCon::getNdbSchemaOp()
98 
99 /*********************************************************************
100 int execute();
101 
102 Return Value: Return 0 : execute was successful.
103  Return -1: In all other case.
104 Parameters : aTypeOfExec: Type of execute.
105 Remark: Initialise connection object for new transaction.
106 ************************************************************************************************/
107 int
109 {
110  if(theError.code != 0) {
111  return -1;
112  }//if
113 
114  NdbSchemaOp* tSchemaOp;
115 
116  tSchemaOp = theFirstSchemaOpInList;
117  if (tSchemaOp == NULL) {
118  theError.code = 4402;
119  return -1;
120  }//if
121 
122  if ((tSchemaOp->sendRec() == -1) || (theError.code != 0)) {
123  // Error Code already set in other place
124  return -1;
125  }//if
126 
127  return 0;
128 }//NdbSchemaCon::execute()
129 
130 /*********************************************************************
131 void release();
132 
133 Remark: Release all schemaop.
134 ************************************************************************************************/
135 void
136 NdbSchemaCon::release()
137 {
138  NdbSchemaOp* tSchemaOp;
139  tSchemaOp = theFirstSchemaOpInList;
140  if (tSchemaOp != NULL) {
141  tSchemaOp->release();
142  delete tSchemaOp;
143  }//if
144  theFirstSchemaOpInList = NULL;
145  return;
146 }//NdbSchemaCon::release()
147 
148 #include <NdbError.hpp>
149 
150 static void
151 update(const NdbError & _err){
152  NdbError & error = (NdbError &) _err;
153  ndberror_struct ndberror = (ndberror_struct)error;
154  ndberror_update(&ndberror);
155  error = NdbError(ndberror);
156 }
157 
158 const
159 NdbError &
161  update(theError);
162  return theError;
163 }
164 
165 
166 
167 
168 
169 
170 
171