NdbSchemaCon.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

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