summaryrefslogtreecommitdiff
path: root/storage/ndb/test/include/NdbSchemaCon.hpp
blob: 74be49d3b9390ce6a36ee1931c143c083aff90ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */

#ifndef NdbSchemaCon_H
#define NdbSchemaCon_H

#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED

#include <ndb_types.h>
#include "NdbError.hpp"
#include <NdbSchemaOp.hpp>

class NdbSchemaOp;
class Ndb;
class NdbApiSignal;

/**
 * @class NdbSchemaCon
 * @brief Represents a schema transaction.
 *
 * When creating a new table,
 * the first step is to get a NdbSchemaCon object to represent 
 * the schema transaction.
 * This is done by calling Ndb::startSchemaTransaction.
 * 
 * The next step is to get a NdbSchemaOp object by calling 
 * NdbSchemaCon::getNdbSchemaOp.
 * The NdbSchemaOp object then has methods to define the table and 
 * its attributes.
 *
 * Finally, the NdbSchemaCon::execute method inserts the table 
 * into the database. 
 *
 * @note   Currently only one table can be added per transaction.
 * @note Depricated, use NdbDictionary
 */
class NdbSchemaCon
{
friend class Ndb;
friend class NdbSchemaOp;
  
public:

  static 
  NdbSchemaCon* startSchemaTrans(Ndb* pNdb){
    return  new NdbSchemaCon(pNdb);
  }
  
  static 
  void closeSchemaTrans(NdbSchemaCon* pSchCon){
    delete pSchCon;
  }
  

  /**
   * Execute a schema transaction.
   * 
   * @return    0 if successful otherwise -1. 
   */
  int 		execute();	  
				  
  /**
   * Get a schemaoperation.
   *
   * @note Currently, only one operation per transaction is allowed.
   *
   * @return   Pointer to a NdbSchemaOp or NULL if unsuccessful.
   */ 
  NdbSchemaOp*	getNdbSchemaOp(); 
	
  /**
   * Get the latest error
   *
   * @return   Error object.
   */			     
  const NdbError & getNdbError() const;

private:

/******************************************************************************
 *	These are the create and delete methods of this class.
 *****************************************************************************/

  NdbSchemaCon(Ndb* aNdb); 
  ~NdbSchemaCon();

/******************************************************************************
 *	These are the private methods of this class.
 *****************************************************************************/

  void release();	         // Release all schemaop in schemaCon

 /***************************************************************************
  *	These methods are service methods to other classes in the NDBAPI.
  ***************************************************************************/

  int           checkMagicNumber();              // Verify correct object
  int           receiveDICTTABCONF(NdbApiSignal* aSignal);
  int           receiveDICTTABREF(NdbApiSignal* aSignal);


  int receiveCREATE_INDX_CONF(NdbApiSignal*);
  int receiveCREATE_INDX_REF(NdbApiSignal*);
  int receiveDROP_INDX_CONF(NdbApiSignal*);
  int receiveDROP_INDX_REF(NdbApiSignal*);


/*****************************************************************************
 *	These are the private variables of this class.
 *****************************************************************************/
  
 
  NdbError 	theError;	      	// Errorcode
  Ndb* 	theNdb;			// Pointer to Ndb object

  NdbSchemaOp*	theFirstSchemaOpInList;	// First operation in operation list.
  int 		theMagicNumber;	// Magic number 
};

inline
int
NdbSchemaCon::checkMagicNumber()
{
  if (theMagicNumber != 0x75318642)
    return -1;
  return 0;
}//NdbSchemaCon::checkMagicNumber()



#endif
#endif