~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/src/NdbSchemaCon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
 
 
17
 
 
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.
 
32
 
 
33
  NOTE: This file is only used as a compatibility layer for old test programs,
 
34
        New programs should use NdbDictionary.hpp
 
35
*********************************************************************/
 
36
 
 
37
#include <ndb_global.h>
 
38
#include <NdbApi.hpp>
 
39
#include <NdbSchemaCon.hpp>
 
40
#include <NdbSchemaOp.hpp>
 
41
 
 
42
 
 
43
/*********************************************************************
 
44
NdbSchemaCon(Ndb* aNdb);
 
45
 
 
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)
 
53
 
54
  theError.code = 0;
 
55
}//NdbSchemaCon::NdbSchemaCon()
 
56
 
 
57
/*********************************************************************
 
58
~NdbSchemaCon();
 
59
 
 
60
Remark:        Deletes the connection object. 
 
61
************************************************************************************************/
 
62
NdbSchemaCon::~NdbSchemaCon()
 
63
{
 
64
}//NdbSchemaCon::~NdbSchemaCon()
 
65
 
 
66
/*********************************************************************
 
67
NdbSchemaOp* getNdbSchemaOp();
 
68
 
 
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()
 
75
 
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()
 
95
 
 
96
/*********************************************************************
 
97
int execute();
 
98
 
 
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()
 
106
{
 
107
  if(theError.code != 0) {
 
108
    return -1;
 
109
  }//if
 
110
 
 
111
  NdbSchemaOp* tSchemaOp;
 
112
 
 
113
  tSchemaOp = theFirstSchemaOpInList;
 
114
  if (tSchemaOp == NULL) {
 
115
    theError.code = 4402;
 
116
    return -1;
 
117
  }//if
 
118
 
 
119
  if ((tSchemaOp->sendRec() == -1) || (theError.code != 0)) {
 
120
    // Error Code already set in other place
 
121
    return -1;
 
122
  }//if
 
123
  
 
124
  return 0;
 
125
}//NdbSchemaCon::execute()
 
126
 
 
127
/*********************************************************************
 
128
void release();
 
129
 
 
130
Remark:         Release all schemaop.
 
131
************************************************************************************************/
 
132
void 
 
133
NdbSchemaCon::release()
 
134
{
 
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()
 
144
 
 
145
#include <NdbError.hpp>
 
146
 
 
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);
 
153
}
 
154
 
 
155
const 
 
156
NdbError & 
 
157
NdbSchemaCon::getNdbError() const {
 
158
  update(theError);
 
159
  return theError;
 
160
}
 
161
 
 
162
 
 
163
 
 
164
 
 
165
            
 
166
 
 
167
 
 
168