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

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. #include <ndb_global.h>
  14. #include <NdbConnection.hpp>
  15. #include <NdbOperation.hpp>
  16. #include "NdbApiSignal.hpp"
  17. #include "NdbRecAttr.hpp"
  18. #include "NdbUtil.hpp"
  19. #include "NdbBlob.hpp"
  20. #include "ndbapi_limits.h"
  21. #include <signaldata/TcKeyReq.hpp>
  22. #include "NdbDictionaryImpl.hpp"
  23. #include "API.hpp"
  24. #include <NdbOut.hpp>
  25. /******************************************************************************
  26.  * NdbOperation(Ndb* aNdb, Table* aTable);
  27.  *
  28.  * Return Value:  None
  29.  * Parameters:    aNdb: Pointers to the Ndb object.
  30.  *                aTable: Pointers to the Table object
  31.  * Remark:        Creat an object of NdbOperation. 
  32.  ****************************************************************************/
  33. NdbOperation::NdbOperation(Ndb* aNdb) :
  34.   theReceiver(aNdb),
  35.   theErrorLine(0),
  36.   theNdb(aNdb),
  37.   //theTable(aTable),
  38.   theNdbCon(NULL),
  39.   theNext(NULL),
  40.   theTCREQ(NULL),
  41.   theFirstATTRINFO(NULL),
  42.   theCurrentATTRINFO(NULL),
  43.   theTotalCurrAI_Len(0),
  44.   theAI_LenInCurrAI(0),
  45.   theFirstKEYINFO(NULL),
  46.   theLastKEYINFO(NULL),
  47.   theFirstLabel(NULL),
  48.   theLastLabel(NULL),
  49.   theFirstBranch(NULL),
  50.   theLastBranch(NULL),
  51.   theFirstCall(NULL),
  52.   theLastCall(NULL),
  53.   theFirstSubroutine(NULL),
  54.   theLastSubroutine(NULL),
  55.   theNoOfLabels(0),
  56.   theNoOfSubroutines(0),
  57.   m_currentTable(NULL), //theTableId(0xFFFF),
  58.   m_accessTable(NULL), //theAccessTableId(0xFFFF),
  59.   //theSchemaVersion(0), 
  60.   theTotalNrOfKeyWordInSignal(8),
  61.   theTupKeyLen(0),
  62.   theNoOfTupKeyDefined(0),
  63.   theOperationType(NotDefined),
  64.   theStatus(Init),
  65.   theMagicNumber(0xFE11D0),
  66.   theScanInfo(0),
  67.   theDistrKeySize(0),
  68.   theDistributionGroup(0),
  69.   m_tcReqGSN(GSN_TCKEYREQ),
  70.   m_keyInfoGSN(GSN_KEYINFO),
  71.   m_attrInfoGSN(GSN_ATTRINFO),
  72.   theBlobList(NULL),
  73.   m_abortOption(-1)
  74. {
  75.   theReceiver.init(NdbReceiver::NDB_OPERATION, this);
  76.   theError.code = 0;
  77. }
  78. /*****************************************************************************
  79.  * ~NdbOperation();
  80.  *
  81.  * Remark:         Delete tables for connection pointers (id).
  82.  *****************************************************************************/
  83. NdbOperation::~NdbOperation( )
  84. {
  85. }
  86. /******************************************************************************
  87.  *void setErrorCode(int anErrorCode);
  88.  *
  89.  * Remark:         Set an Error Code on operation and 
  90.  *                 on connection set an error status.
  91.  *****************************************************************************/
  92. void
  93. NdbOperation::setErrorCode(int anErrorCode)
  94. {
  95.   theError.code = anErrorCode;
  96.   theNdbCon->theErrorLine = theErrorLine;
  97.   theNdbCon->theErrorOperation = this;
  98.   theNdbCon->setOperationErrorCode(anErrorCode);
  99. }
  100. /******************************************************************************
  101.  * void setErrorCodeAbort(int anErrorCode);
  102.  *
  103.  * Remark:         Set an Error Code on operation and on connection set 
  104.  *                 an error status.
  105.  *****************************************************************************/
  106. void
  107. NdbOperation::setErrorCodeAbort(int anErrorCode)
  108. {
  109.   theError.code = anErrorCode;
  110.   theNdbCon->theErrorLine = theErrorLine;
  111.   theNdbCon->theErrorOperation = this;
  112.   theNdbCon->setOperationErrorCodeAbort(anErrorCode);
  113. }
  114. /*****************************************************************************
  115.  * int init();
  116.  *
  117.  * Return Value:  Return 0 : init was successful.
  118.  *                Return -1: In all other case.  
  119.  * Remark:        Initiates operation record after allocation.
  120.  *****************************************************************************/
  121. int
  122. NdbOperation::init(const NdbTableImpl* tab, NdbConnection* myConnection){
  123.   NdbApiSignal* tSignal;
  124.   theStatus = Init;
  125.   theError.code = 0;
  126.   theErrorLine = 1;
  127.   m_currentTable = m_accessTable = tab;
  128.   
  129.   theNdbCon = myConnection;
  130.   for (Uint32 i=0; i<NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY; i++)
  131.     for (int j=0; j<3; j++)
  132.       theTupleKeyDefined[i][j] = 0;
  133.   theFirstATTRINFO    = NULL;
  134.   theCurrentATTRINFO  = NULL;
  135.   theFirstKEYINFO     = NULL;
  136.   theLastKEYINFO      = NULL;  
  137.   
  138.   theTupKeyLen = 0;
  139.   theNoOfTupKeyDefined = 0;
  140.   theDistrKeySize = 0;
  141.   theDistributionGroup = 0;
  142.   theTotalCurrAI_Len = 0;
  143.   theAI_LenInCurrAI = 0;
  144.   theStartIndicator = 0;
  145.   theCommitIndicator = 0;
  146.   theSimpleIndicator = 0;
  147.   theDirtyIndicator = 0;
  148.   theInterpretIndicator = 0;
  149.   theDistrGroupIndicator= 0;
  150.   theDistrGroupType     = 0;
  151.   theDistrKeyIndicator  = 0;
  152.   theScanInfo         = 0;
  153.   theTotalNrOfKeyWordInSignal = 8;
  154.   theMagicNumber        = 0xABCDEF01;
  155.   theBlobList = NULL;
  156.   m_abortOption = -1;
  157.   tSignal = theNdb->getSignal();
  158.   if (tSignal == NULL)
  159.   {
  160.     setErrorCode(4000);
  161.     return -1;
  162.   }
  163.   theTCREQ = tSignal;
  164.   theTCREQ->setSignal(m_tcReqGSN);
  165.   theAI_LenInCurrAI = 20;
  166.   TcKeyReq * const tcKeyReq = CAST_PTR(TcKeyReq, theTCREQ->getDataPtrSend());
  167.   tcKeyReq->scanInfo = 0;
  168.   theKEYINFOptr = &tcKeyReq->keyInfo[0];
  169.   theATTRINFOptr = &tcKeyReq->attrInfo[0];
  170.   theReceiver.init(NdbReceiver::NDB_OPERATION, this);
  171.   return 0;
  172. }
  173. /******************************************************************************
  174.  * void release();
  175.  *
  176.  * Remark:        Release all objects connected to the operation object.
  177.  *****************************************************************************/
  178. void
  179. NdbOperation::release()
  180. {
  181.   NdbApiSignal* tSignal;
  182.   NdbApiSignal* tSaveSignal;
  183.   NdbBranch* tBranch;
  184.   NdbBranch* tSaveBranch;
  185.   NdbLabel* tLabel;
  186.   NdbLabel* tSaveLabel;
  187.   NdbCall* tCall;
  188.   NdbCall* tSaveCall;
  189.   NdbSubroutine* tSubroutine;
  190.   NdbSubroutine* tSaveSubroutine;
  191.   NdbBlob* tBlob;
  192.   NdbBlob* tSaveBlob;
  193.   if (theTCREQ != NULL)
  194.   {
  195.     theNdb->releaseSignal(theTCREQ);
  196.   }
  197.   theTCREQ = NULL;
  198.   tSignal = theFirstATTRINFO;
  199.   while (tSignal != NULL)
  200.   {
  201.     tSaveSignal = tSignal;
  202.     tSignal = tSignal->next();
  203.     theNdb->releaseSignal(tSaveSignal);
  204.   }
  205.   theFirstATTRINFO = NULL;
  206.   theCurrentATTRINFO = NULL;
  207.   tSignal = theFirstKEYINFO;
  208.   while (tSignal != NULL)
  209.   {
  210.     tSaveSignal = tSignal;
  211.     tSignal = tSignal->next();
  212.     theNdb->releaseSignal(tSaveSignal);
  213.   }
  214.   theFirstKEYINFO = NULL;
  215.   theLastKEYINFO = NULL;
  216.   if (theInterpretIndicator == 1)
  217.   {
  218.     tBranch = theFirstBranch;
  219.     while (tBranch != NULL)
  220.     {
  221.       tSaveBranch = tBranch;
  222.       tBranch = tBranch->theNext;
  223.       theNdb->releaseNdbBranch(tSaveBranch);
  224.     }
  225.     tLabel = theFirstLabel;
  226.     while (tLabel != NULL)
  227.     {
  228.       tSaveLabel = tLabel;
  229.       tLabel = tLabel->theNext;
  230.       theNdb->releaseNdbLabel(tSaveLabel);
  231.     }
  232.     tCall = theFirstCall;
  233.     while (tCall != NULL)
  234.     {
  235.       tSaveCall = tCall;
  236.       tCall = tCall->theNext;
  237.       theNdb->releaseNdbCall(tSaveCall);
  238.     }
  239.     tSubroutine = theFirstSubroutine;
  240.     while (tSubroutine != NULL)
  241.     {
  242.       tSaveSubroutine = tSubroutine;
  243.       tSubroutine = tSubroutine->theNext;
  244.       theNdb->releaseNdbSubroutine(tSaveSubroutine);
  245.     }
  246.   }
  247.   tBlob = theBlobList;
  248.   while (tBlob != NULL)
  249.   {
  250.     tSaveBlob = tBlob;
  251.     tBlob = tBlob->theNext;
  252.     theNdb->releaseNdbBlob(tSaveBlob);
  253.   }
  254.   theBlobList = NULL;
  255.   theReceiver.release();
  256. }
  257. NdbRecAttr*
  258. NdbOperation::getValue(const char* anAttrName, char* aValue)
  259. {
  260.   return getValue_impl(m_currentTable->getColumn(anAttrName), aValue);
  261. }
  262. NdbRecAttr*
  263. NdbOperation::getValue(Uint32 anAttrId, char* aValue)
  264. {
  265.   return getValue_impl(m_currentTable->getColumn(anAttrId), aValue);
  266. }
  267. NdbRecAttr*
  268. NdbOperation::getValue(const NdbDictionary::Column* col, char* aValue)
  269. {
  270.   return getValue_impl(&NdbColumnImpl::getImpl(*col), aValue);
  271. }
  272. int
  273. NdbOperation::equal(const char* anAttrName, 
  274.     const char* aValuePassed, 
  275.     Uint32 aVariableKeyLen)
  276. {
  277.   return equal_impl(m_accessTable->getColumn(anAttrName), aValuePassed, aVariableKeyLen);
  278. }
  279. int
  280. NdbOperation::equal(Uint32 anAttrId, 
  281.     const char* aValuePassed, 
  282.     Uint32 aVariableKeyLen)
  283. {
  284.   return equal_impl(m_accessTable->getColumn(anAttrId), aValuePassed, aVariableKeyLen);
  285. }
  286. int
  287. NdbOperation::setValue( const char* anAttrName, 
  288. const char* aValuePassed, 
  289. Uint32 len)
  290. {
  291.   return setValue(m_currentTable->getColumn(anAttrName), aValuePassed, len);
  292. }
  293. int
  294. NdbOperation::setValue( Uint32 anAttrId, 
  295. const char* aValuePassed, 
  296. Uint32 len)
  297. {
  298.   return setValue(m_currentTable->getColumn(anAttrId), aValuePassed, len);
  299. }
  300. NdbBlob*
  301. NdbOperation::getBlobHandle(const char* anAttrName)
  302. {
  303.   return getBlobHandle(theNdbCon, m_currentTable->getColumn(anAttrName));
  304. }
  305. NdbBlob*
  306. NdbOperation::getBlobHandle(Uint32 anAttrId)
  307. {
  308.   return getBlobHandle(theNdbCon, m_currentTable->getColumn(anAttrId));
  309. }
  310. int
  311. NdbOperation::incValue(const char* anAttrName, Uint32 aValue)
  312. {
  313.   return incValue(m_currentTable->getColumn(anAttrName), aValue);
  314. }
  315. int
  316. NdbOperation::incValue(const char* anAttrName, Uint64 aValue)
  317. {
  318.   return incValue(m_currentTable->getColumn(anAttrName), aValue);
  319. }
  320. int
  321. NdbOperation::incValue(Uint32 anAttrId, Uint32 aValue)
  322. {
  323.   return incValue(m_currentTable->getColumn(anAttrId), aValue);
  324. }
  325. int
  326. NdbOperation::incValue(Uint32 anAttrId, Uint64 aValue)
  327. {
  328.   return incValue(m_currentTable->getColumn(anAttrId), aValue);
  329. }
  330. int
  331. NdbOperation::subValue( const char* anAttrName, Uint32 aValue)
  332. {
  333.   return subValue(m_currentTable->getColumn(anAttrName), aValue);
  334. }
  335. int
  336. NdbOperation::subValue(Uint32 anAttrId, Uint32 aValue)
  337. {
  338.   return subValue(m_currentTable->getColumn(anAttrId), aValue);
  339. }
  340. int
  341. NdbOperation::read_attr(const char* anAttrName, Uint32 RegDest)
  342. {
  343.   return read_attr(m_currentTable->getColumn(anAttrName), RegDest);
  344. }
  345. int
  346. NdbOperation::read_attr(Uint32 anAttrId, Uint32 RegDest)
  347. {
  348.   return read_attr(m_currentTable->getColumn(anAttrId), RegDest);
  349. }
  350. int
  351. NdbOperation::write_attr(const char* anAttrName, Uint32 RegDest)
  352. {
  353.   return write_attr(m_currentTable->getColumn(anAttrName), RegDest);
  354. }
  355. int
  356. NdbOperation::write_attr(Uint32 anAttrId, Uint32 RegDest)
  357. {
  358.   return write_attr(m_currentTable->getColumn(anAttrId), RegDest);
  359. }
  360. const char*
  361. NdbOperation::getTableName() const
  362. {
  363.   return m_currentTable->m_externalName.c_str();
  364. }