⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hugooperations.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* 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; either version 2 of the License, or   (at your option) any later version.   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <HugoOperations.hpp>int HugoOperations::startTransaction(Ndb* pNdb){    if (pTrans != NULL){    ndbout << "HugoOperations::startTransaction, pTrans != NULL" << endl;    return NDBT_FAILED;  }  pTrans = pNdb->startTransaction();  if (pTrans == NULL) {    const NdbError err = pNdb->getNdbError();    ERR(err);    return NDBT_FAILED;  }  return NDBT_OK;}int HugoOperations::setTransaction(NdbTransaction* new_trans){    if (pTrans != NULL){    ndbout << "HugoOperations::startTransaction, pTrans != NULL" << endl;    return NDBT_FAILED;  }  pTrans = new_trans;  if (pTrans == NULL) {    return NDBT_FAILED;  }  return NDBT_OK;}void HugoOperations::setTransactionId(Uint64 id){  if (pTrans != NULL){    pTrans->setTransactionId(id);  }}int HugoOperations::closeTransaction(Ndb* pNdb){  UtilTransactions::closeTransaction(pNdb);  m_result_sets.clear();  m_executed_result_sets.clear();  return NDBT_OK;}NdbConnection* HugoOperations::getTransaction(){  return pTrans;}int HugoOperations::pkReadRecord(Ndb* pNdb,				 int recordNo,				 int numRecords,				 NdbOperation::LockMode lm){  int a;    allocRows(numRecords);  int check;  NdbOperation* pOp = 0;  pIndexScanOp = 0;  for(int r=0; r < numRecords; r++){        if(pOp == 0)    {      pOp = getOperation(pTrans, NdbOperation::ReadRequest);    }    if (pOp == NULL) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }    rand_lock_mode:    switch(lm){    case NdbOperation::LM_Read:    case NdbOperation::LM_Exclusive:    case NdbOperation::LM_CommittedRead:      if(idx && idx->getType() == NdbDictionary::Index::OrderedIndex && 	 pIndexScanOp == 0)      {	pIndexScanOp = ((NdbIndexScanOperation*)pOp);	check = pIndexScanOp->readTuples(lm);      }      else	check = pOp->readTuple(lm);      break;    default:      lm = (NdbOperation::LockMode)((rand() >> 16) & 3);      goto rand_lock_mode;    }        if( check == -1 ) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        // Define primary keys    for(a = 0; a<tab.getNoOfColumns(); a++){      if (tab.getColumn(a)->getPrimaryKey() == true){	if(equalForAttr(pOp, a, r+recordNo) != 0){	  ERR(pTrans->getNdbError());	  return NDBT_FAILED;	}      }    }    if(pIndexScanOp)      pIndexScanOp->end_of_bound(r);        if(r == 0 || pIndexScanOp == 0)    {      // Define attributes to read        for(a = 0; a<tab.getNoOfColumns(); a++){	if((rows[r]->attributeStore(a) = 	    pOp->getValue(tab.getColumn(a)->getName())) == 0) {	  ERR(pTrans->getNdbError());	  return NDBT_FAILED;	}      }     }    pOp = pIndexScanOp;  }  return NDBT_OK;}int HugoOperations::pkUpdateRecord(Ndb* pNdb,				   int recordNo,				   int numRecords,				   int updatesValue){  int a;   allocRows(numRecords);  int check;  for(int r=0; r < numRecords; r++){    NdbOperation* pOp = getOperation(pTrans, NdbOperation::UpdateRequest);    if (pOp == NULL) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        check = pOp->updateTuple();    if( check == -1 ) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK)    {      return NDBT_FAILED;    }  }  return NDBT_OK;}int HugoOperations::setValues(NdbOperation* pOp, int rowId, int updateId){  // Define primary keys  int a;  for(a = 0; a<tab.getNoOfColumns(); a++){    if (tab.getColumn(a)->getPrimaryKey() == true){      if(equalForAttr(pOp, a, rowId) != 0){	ERR(pTrans->getNdbError());	return NDBT_FAILED;      }    }  }    for(a = 0; a<tab.getNoOfColumns(); a++){    if (tab.getColumn(a)->getPrimaryKey() == false){      if(setValueForAttr(pOp, a, rowId, updateId ) != 0){ 	ERR(pTrans->getNdbError());	return NDBT_FAILED;      }    }  }    return NDBT_OK;}int HugoOperations::pkInsertRecord(Ndb* pNdb,				   int recordNo,				   int numRecords,				   int updatesValue){    int a, check;  for(int r=0; r < numRecords; r++){    NdbOperation* pOp = getOperation(pTrans, NdbOperation::InsertRequest);    if (pOp == NULL) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        check = pOp->insertTuple();    if( check == -1 ) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK)    {      return NDBT_FAILED;    }  }  return NDBT_OK;}int HugoOperations::pkWriteRecord(Ndb* pNdb,				  int recordNo,				  int numRecords,				  int updatesValue){    int a, check;  for(int r=0; r < numRecords; r++){    NdbOperation* pOp = pTrans->getNdbOperation(tab.getName());	    if (pOp == NULL) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        check = pOp->writeTuple();    if( check == -1 ) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        // Define primary keys    for(a = 0; a<tab.getNoOfColumns(); a++){      if (tab.getColumn(a)->getPrimaryKey() == true){	if(equalForAttr(pOp, a, r+recordNo) != 0){	  ERR(pTrans->getNdbError());	  return NDBT_FAILED;	}      }    }        // Define attributes to update    for(a = 0; a<tab.getNoOfColumns(); a++){      if (tab.getColumn(a)->getPrimaryKey() == false){	if(setValueForAttr(pOp, a, recordNo+r, updatesValue ) != 0){ 	  ERR(pTrans->getNdbError());	  return NDBT_FAILED;	}      }    }   }  return NDBT_OK;}int HugoOperations::pkWritePartialRecord(Ndb* pNdb,					 int recordNo,					 int numRecords){    int a, check;  for(int r=0; r < numRecords; r++){    NdbOperation* pOp = pTrans->getNdbOperation(tab.getName());	    if (pOp == NULL) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        check = pOp->writeTuple();    if( check == -1 ) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        // Define primary keys    for(a = 0; a<tab.getNoOfColumns(); a++){      if (tab.getColumn(a)->getPrimaryKey() == true){	if(equalForAttr(pOp, a, r+recordNo) != 0){	  ERR(pTrans->getNdbError());	  return NDBT_FAILED;	}      }    }  }  return NDBT_OK;}int HugoOperations::pkDeleteRecord(Ndb* pNdb,				   int recordNo,				   int numRecords){    int a, check;  for(int r=0; r < numRecords; r++){    NdbOperation* pOp = getOperation(pTrans, NdbOperation::DeleteRequest);    if (pOp == NULL) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        check = pOp->deleteTuple();    if( check == -1 ) {      ERR(pTrans->getNdbError());      return NDBT_FAILED;    }        // Define primary keys    for(a = 0; a<tab.getNoOfColumns(); a++){      if (tab.getColumn(a)->getPrimaryKey() == true){	if(equalForAttr(pOp, a, r+recordNo) != 0){	  ERR(pTrans->getNdbError());	  return NDBT_FAILED;	}      }    }  }  return NDBT_OK;}int HugoOperations::execute_Commit(Ndb* pNdb,				   AbortOption eao){  int check = 0;  check = pTrans->execute(Commit, eao);     if( check == -1 ) {    const NdbError err = pTrans->getNdbError();    ERR(err);    NdbOperation* pOp = pTrans->getNdbErrorOperation();    if (pOp != NULL){      const NdbError err2 = pOp->getNdbError();      ERR(err2);    }    if (err.code == 0)      return NDBT_FAILED;    return err.code;  }  for(int i = 0; i<m_result_sets.size(); i++){    m_executed_result_sets.push_back(m_result_sets[i]);    int rows = m_result_sets[i].records;    NdbScanOperation* rs = m_result_sets[i].m_result_set;    int res = rs->nextResult();    switch(res){    case 1:      return 626;    case -1:      const NdbError err = pTrans->getNdbError();      ERR(err);      return (err.code > 0 ? err.code : NDBT_FAILED);    }    // A row found    switch(rows){    case 0:      return 4000;    default:      m_result_sets[i].records--;      break;    }  }  m_result_sets.clear();    return NDBT_OK;}int HugoOperations::execute_NoCommit(Ndb* pNdb, AbortOption eao){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -