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, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26
27
28 /*********************************************************************
29 Name: NdbSchemaCon.cpp
30 Include:
31 Link:
32 Author: UABMNST Mona Natterkvist UAB/B/SD
33 EMIKRON Mikael Ronstrom
34 Date: 020826
35 Version: 3.0
36 Description: Old Interface between application and NDB
37 Documentation:
38 Adjust: 980126 UABMNST First version.
39 020826 EMIKRON New version adapted to new DICT version
40 040524 Magnus Svensson - Adapted to not be included in public NdbApi
41 unless the user wants to use it.
42
43 NOTE: This file is only used as a compatibility layer for old test programs,
44 New programs should use NdbDictionary.hpp
45 *********************************************************************/
46
47 #include <ndb_global.h>
48 #include <NdbApi.hpp>
49 #include <NdbSchemaCon.hpp>
50 #include <NdbSchemaOp.hpp>
51
52
53 /*********************************************************************
54 NdbSchemaCon(Ndb* aNdb);
55
56 Parameters: aNdb: Pointers to the Ndb object
57 Remark: Creates a schemacon object.
58 ************************************************************************************************/
NdbSchemaCon(Ndb * aNdb)59 NdbSchemaCon::NdbSchemaCon( Ndb* aNdb ) :
60 theNdb(aNdb),
61 theFirstSchemaOpInList(NULL),
62 theMagicNumber(0x75318642)
63 {
64 theError.code = 0;
65 }//NdbSchemaCon::NdbSchemaCon()
66
67 /*********************************************************************
68 ~NdbSchemaCon();
69
70 Remark: Deletes the connection object.
71 ************************************************************************************************/
~NdbSchemaCon()72 NdbSchemaCon::~NdbSchemaCon()
73 {
74 }//NdbSchemaCon::~NdbSchemaCon()
75
76 /*********************************************************************
77 NdbSchemaOp* getNdbSchemaOp();
78
79 Return Value Return a pointer to a NdbSchemaOp object if getNdbSchemaOp was sussesful.
80 Return NULL: In all other case.
81 Parameters: tableId : Id of the database table beeing deleted.
82 ************************************************************************************************/
83 NdbSchemaOp*
getNdbSchemaOp()84 NdbSchemaCon::getNdbSchemaOp()
85 {
86 NdbSchemaOp* tSchemaOp;
87 if (theFirstSchemaOpInList != NULL) {
88 theError.code = 4401; // Only support one add table per transaction
89 return NULL;
90 }//if
91 tSchemaOp = new NdbSchemaOp(theNdb);
92 if ( tSchemaOp == NULL ) {
93 theError.code = 4000; // Could not allocate schema operation
94 return NULL;
95 }//if
96 theFirstSchemaOpInList = tSchemaOp;
97 int retValue = tSchemaOp->init(this);
98 if (retValue == -1) {
99 release();
100 theError.code = 4000; // Could not allocate buffer in schema operation
101 return NULL;
102 }//if
103 return tSchemaOp;
104 }//NdbSchemaCon::getNdbSchemaOp()
105
106 /*********************************************************************
107 int execute();
108
109 Return Value: Return 0 : execute was successful.
110 Return -1: In all other case.
111 Parameters : aTypeOfExec: Type of execute.
112 Remark: Initialise connection object for new transaction.
113 ************************************************************************************************/
114 int
execute()115 NdbSchemaCon::execute()
116 {
117 if(theError.code != 0) {
118 return -1;
119 }//if
120
121 NdbSchemaOp* tSchemaOp;
122
123 tSchemaOp = theFirstSchemaOpInList;
124 if (tSchemaOp == NULL) {
125 theError.code = 4402;
126 return -1;
127 }//if
128
129 if ((tSchemaOp->sendRec() == -1) || (theError.code != 0)) {
130 // Error Code already set in other place
131 return -1;
132 }//if
133
134 return 0;
135 }//NdbSchemaCon::execute()
136
137 /*********************************************************************
138 void release();
139
140 Remark: Release all schemaop.
141 ************************************************************************************************/
142 void
release()143 NdbSchemaCon::release()
144 {
145 NdbSchemaOp* tSchemaOp;
146 tSchemaOp = theFirstSchemaOpInList;
147 if (tSchemaOp != NULL) {
148 tSchemaOp->release();
149 delete tSchemaOp;
150 }//if
151 theFirstSchemaOpInList = NULL;
152 return;
153 }//NdbSchemaCon::release()
154
155 #include <NdbError.hpp>
156
157 static void
update(const NdbError & _err)158 update(const NdbError & _err){
159 NdbError & error = (NdbError &) _err;
160 ndberror_struct ndberror = (ndberror_struct)error;
161 ndberror_update(&ndberror);
162 error = NdbError(ndberror);
163 }
164
165 const
166 NdbError &
getNdbError() const167 NdbSchemaCon::getNdbError() const {
168 update(theError);
169 return theError;
170 }
171
172
173
174
175
176
177
178
179