mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / src / NdbSchemaCon.cpp
blob65cb9c0e83aaaee1f898a49deb2bd898ea62228d
1 /* Copyright (c) 2003-2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
18 /*********************************************************************
19 Name: NdbSchemaCon.cpp
20 Include:
21 Link:
22 Author: UABMNST Mona Natterkvist UAB/B/SD
23 EMIKRON Mikael Ronstrom
24 Date: 020826
25 Version: 3.0
26 Description: Old Interface between application and NDB
27 Documentation:
28 Adjust: 980126 UABMNST First version.
29 020826 EMIKRON New version adapted to new DICT version
30 040524 Magnus Svensson - Adapted to not be included in public NdbApi
31 unless the user wants to use it.
33 NOTE: This file is only used as a compatibility layer for old test programs,
34 New programs should use NdbDictionary.hpp
35 *********************************************************************/
37 #include <ndb_global.h>
38 #include <NdbApi.hpp>
39 #include <NdbSchemaCon.hpp>
40 #include <NdbSchemaOp.hpp>
43 /*********************************************************************
44 NdbSchemaCon(Ndb* aNdb);
46 Parameters: aNdb: Pointers to the Ndb object
47 Remark: Creates a schemacon object.
48 ************************************************************************************************/
49 NdbSchemaCon::NdbSchemaCon( Ndb* aNdb ) :
50 theNdb(aNdb),
51 theFirstSchemaOpInList(NULL),
52 theMagicNumber(0x75318642)
54 theError.code = 0;
55 }//NdbSchemaCon::NdbSchemaCon()
57 /*********************************************************************
58 ~NdbSchemaCon();
60 Remark: Deletes the connection object.
61 ************************************************************************************************/
62 NdbSchemaCon::~NdbSchemaCon()
64 }//NdbSchemaCon::~NdbSchemaCon()
66 /*********************************************************************
67 NdbSchemaOp* getNdbSchemaOp();
69 Return Value Return a pointer to a NdbSchemaOp object if getNdbSchemaOp was sussesful.
70 Return NULL: In all other case.
71 Parameters: tableId : Id of the database table beeing deleted.
72 ************************************************************************************************/
73 NdbSchemaOp*
74 NdbSchemaCon::getNdbSchemaOp()
76 NdbSchemaOp* tSchemaOp;
77 if (theFirstSchemaOpInList != NULL) {
78 theError.code = 4401; // Only support one add table per transaction
79 return NULL;
80 }//if
81 tSchemaOp = new NdbSchemaOp(theNdb);
82 if ( tSchemaOp == NULL ) {
83 theError.code = 4000; // Could not allocate schema operation
84 return NULL;
85 }//if
86 theFirstSchemaOpInList = tSchemaOp;
87 int retValue = tSchemaOp->init(this);
88 if (retValue == -1) {
89 release();
90 theError.code = 4000; // Could not allocate buffer in schema operation
91 return NULL;
92 }//if
93 return tSchemaOp;
94 }//NdbSchemaCon::getNdbSchemaOp()
96 /*********************************************************************
97 int execute();
99 Return Value: Return 0 : execute was successful.
100 Return -1: In all other case.
101 Parameters : aTypeOfExec: Type of execute.
102 Remark: Initialise connection object for new transaction.
103 ************************************************************************************************/
104 int
105 NdbSchemaCon::execute()
107 if(theError.code != 0) {
108 return -1;
109 }//if
111 NdbSchemaOp* tSchemaOp;
113 tSchemaOp = theFirstSchemaOpInList;
114 if (tSchemaOp == NULL) {
115 theError.code = 4402;
116 return -1;
117 }//if
119 if ((tSchemaOp->sendRec() == -1) || (theError.code != 0)) {
120 // Error Code already set in other place
121 return -1;
122 }//if
124 return 0;
125 }//NdbSchemaCon::execute()
127 /*********************************************************************
128 void release();
130 Remark: Release all schemaop.
131 ************************************************************************************************/
132 void
133 NdbSchemaCon::release()
135 NdbSchemaOp* tSchemaOp;
136 tSchemaOp = theFirstSchemaOpInList;
137 if (tSchemaOp != NULL) {
138 tSchemaOp->release();
139 delete tSchemaOp;
140 }//if
141 theFirstSchemaOpInList = NULL;
142 return;
143 }//NdbSchemaCon::release()
145 #include <NdbError.hpp>
147 static void
148 update(const NdbError & _err){
149 NdbError & error = (NdbError &) _err;
150 ndberror_struct ndberror = (ndberror_struct)error;
151 ndberror_update(&ndberror);
152 error = NdbError(ndberror);
155 const
156 NdbError &
157 NdbSchemaCon::getNdbError() const {
158 update(theError);
159 return theError;