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

📄 resultset.cpp.svn-base

📁 絲路server源碼 Silk Road server source
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
  CHECK_INSERT_ROW;  if(!LOCATION_IS_VALID) {    throw SQLException      (ODBCXX_STRING_CONST("[libodbc++]: No current row"));  }  this->_applyPosition(SQL_REFRESH);}void ResultSet::deleteRow(){  CHECK_SCROLLABLE_CURSOR;  CHECK_INSERT_ROW;  if(!LOCATION_IS_VALID) {    throw SQLException      (ODBCXX_STRING_CONST("[libodbc++]: No current row"));  }  {#if ODBCVER >= 0x0300    ValueSaver<SQLUINTEGER> _rows(rowsInRowset_);#endif    this->_applyPosition(SQL_DELETE);  }}void ResultSet::cancelRowUpdates(){  CHECK_SCROLLABLE_CURSOR;  if(LOCATION_IS_VALID) {    // do a refresh    this->refreshRow();  } else if(location_==INSERT_ROW) {    // this will set all values to NULL    rowset_->afterUpdate();  } else {    throw SQLException      (ODBCXX_STRING_CONST("[libodbc++]: No current row"));  }}int ResultSet::findColumn(const ODBCXX_STRING& colName){  for(int i=1; i<=metaData_->getColumnCount(); i++) {    if(#if !defined(WIN32)# if defined(ODBCXX_UNICODE)       wcscasecmp# else       strcasecmp# endif#elif defined(ODBCXX_HAVE__STRICMP)# if defined(ODBCXX_UNICODE)       _wcsicmp# else       _stricmp# endif#elif defined(ODBCXX_HAVE_STRICMP)# if defined(ODBCXX_UNICODE)       wcsicmp# else       stricmp# endif#else# error Cannot determine case-insensitive string compare function#endif       (ODBCXX_STRING_CSTR(colName),        ODBCXX_STRING_CSTR(metaData_->getColumnName(i)))==0) {      return i;    }  }  throw SQLException    (ODBCXX_STRING_CONST("[libodbc++]: Column ")+colName+ODBCXX_STRING_CONST(" not found in result set"));  //shut up MSVC  return 0;}int ResultSet::getRow(){  if(location_>0 && rowsInRowset_>0) {    return location_+rowset_->getCurrentRow();  } else if(location_==INSERT_ROW && locBeforeInsert_>0) {    return locBeforeInsert_+rowBeforeInsert_;  }  return 0;}ODBCXX_STRING ResultSet::getCursorName(){  ODBCXX_CHAR_TYPE buf[256];  SQLSMALLINT t;  SQLRETURN r=SQLGetCursorName(hstmt_,                               (ODBCXX_SQLCHAR*)buf,                               255,                               &t);  this->_checkStmtError(hstmt_,r,ODBCXX_STRING_CONST("Error fetching cursor name"));  buf[255]=0;  return ODBCXX_STRING_C(buf);}bool ResultSet::rowDeleted(){  return (rowStatus_[rowset_->getCurrentRow()-bindPos_]==SQL_ROW_DELETED);}bool ResultSet::rowInserted(){  return (rowStatus_[rowset_->getCurrentRow()-bindPos_]==SQL_ROW_ADDED);}bool ResultSet::rowUpdated(){  return (rowStatus_[rowset_->getCurrentRow()-bindPos_]==SQL_ROW_UPDATED);}bool ResultSet::isAfterLast(){  return location_==AFTER_LAST;}bool ResultSet::isBeforeFirst(){  return location_==BEFORE_FIRST;}bool ResultSet::isFirst(){  CHECK_INSERT_ROW;  if(!LOCATION_IS_VALID) {    return false;  }  if(location_!=UNKNOWN) {    return (location_==1 && rowset_->getCurrentRow()==0);  }  // to do more, we need scrolling  CHECK_SCROLLABLE_CURSOR;  // we have to do a fetch  // as with isLast(), fall down to rowset size=1  int oldfs=currentFetchSize_;  newFetchSize_=1;  int oldpos=rowset_->getCurrentRow();  this->_prepareForFetch();  this->_doFetch(SQL_FETCH_PREV,0);  bool havePrev=LOCATION_IS_VALID;  newFetchSize_=oldfs;  this->_prepareForFetch();  this->_doFetch(SQL_FETCH_NEXT,0);  rowset_->setCurrentRow(oldpos);  this->_applyPosition();  return !havePrev;}bool ResultSet::isLast(){  CHECK_INSERT_ROW;  if(!LOCATION_IS_VALID ||     rowset_->getCurrentRow() < rowsInRowset_-1) {    //we know for sure    return false;  }  //nothing we can do if we aren't scrolling  CHECK_SCROLLABLE_CURSOR;  //here, we fall down to a rowset size of 1 in order to  //be able to come back to exactly the same position  int oldfs=currentFetchSize_;  int oldpos=rowset_->getCurrentRow();  newFetchSize_=1;  this->_prepareForFetch();  this->_doFetch(SQL_FETCH_NEXT,0);  bool haveMore=LOCATION_IS_VALID;  newFetchSize_=oldfs;  this->_prepareForFetch();  // return to our position  this->_doFetch(SQL_FETCH_PREV,0);  rowset_->setCurrentRow(oldpos);  this->_applyPosition();  return !haveMore;}#define CHECK_COL(x)                                        \do {                                                        \  if(x<1 || x>metaData_->getColumnCount()) {                \    throw SQLException                                        \      (ODBCXX_STRING_CONST("Column index out of range"));\  }                                                        \} while(false)// this allows the position to be on the insert row#define CHECK_LOCATION                                                \do {                                                                \  if(!LOCATION_IS_VALID && location_!=INSERT_ROW) {                \    throw SQLException                                                \      (ODBCXX_STRING_CONST("[libodbc++]: No current row"));        \  }                                                                \} while(false)#define IMPLEMENT_GET(RETTYPE,FUNCSUFFIX)                        \RETTYPE ResultSet::get##FUNCSUFFIX(int idx)                        \{                                                                \  CHECK_COL(idx);                                                \  CHECK_LOCATION;                                               \  DataHandler* dh=rowset_->getColumn(idx);                        \  lastWasNull_=dh->isNull();                                        \  return dh->get##FUNCSUFFIX();                                        \}                                                                \                                                                \RETTYPE ResultSet::get##FUNCSUFFIX(const ODBCXX_STRING& colName)\{                                                                \  return this->get##FUNCSUFFIX(this->findColumn(colName));        \}#define IMPLEMENT_UPDATE(TYPE,FUNCSUFFIX)                                \void ResultSet::update##FUNCSUFFIX(int idx, TYPE val)                        \{                                                                        \  CHECK_COL(idx);                                                        \  CHECK_LOCATION;                                                       \  DataHandler* dh=rowset_->getColumn(idx);                                \  dh->set##FUNCSUFFIX(val);                                                \}                                                                        \                                                                        \void ResultSet::update##FUNCSUFFIX(const ODBCXX_STRING& colName, TYPE val)\{                                                                        \  this->update##FUNCSUFFIX(this->findColumn(colName),val);                \}#define IMPLEMENT_BOTH(TYPE,FUNCSUFFIX)                \IMPLEMENT_GET(TYPE,FUNCSUFFIX);                        \IMPLEMENT_UPDATE(TYPE,FUNCSUFFIX)IMPLEMENT_BOTH(double,Double);IMPLEMENT_BOTH(bool,Boolean);IMPLEMENT_BOTH(signed char,Byte);IMPLEMENT_BOTH(float,Float);IMPLEMENT_BOTH(int,Int);IMPLEMENT_BOTH(Long,Long);IMPLEMENT_BOTH(short,Short);//darn, this didn't fit in//IMPLEMENT_GET(ODBCXX_BYTES,Bytes);//IMPLEMENT_UPDATE(const ODBCXX_BYTES&, Bytes);//IMPLEMENT_GET(ODBCXX_STRING,String);//IMPLEMENT_UPDATE(const ODBCXX_STRING&, String);IMPLEMENT_GET(Date,Date);IMPLEMENT_UPDATE(const Date&, Date);IMPLEMENT_GET(Time,Time);IMPLEMENT_UPDATE(const Time&, Time);IMPLEMENT_GET(Timestamp,Timestamp);IMPLEMENT_UPDATE(const Timestamp&, Timestamp);void ResultSet::updateString(int idx, const ODBCXX_STRING& str){  CHECK_COL(idx);  CHECK_LOCATION;  DataHandler* dh=rowset_->getColumn(idx);#if defined(ODBCXX_HAVE_SQLUCODE_H)  if((dh->getSQLType()!=Types::LONGVARCHAR)&&(dh->getSQLType()!=Types::WLONGVARCHAR)) {#else  if((dh->getSQLType()!=Types::LONGVARCHAR)) {#endif    dh->setString(str);  } else {    dh->setStream(stringToStream(str), str.length());  }}void ResultSet::updateString(const ODBCXX_STRING& colName,                             const ODBCXX_STRING& str){  this->updateString(this->findColumn(colName),str);}ODBCXX_STRING ResultSet::getString(int idx){  CHECK_COL(idx);  CHECK_LOCATION;  DataHandler* dh=rowset_->getColumn(idx);#if defined(ODBCXX_HAVE_SQLUCODE_H)  if((dh->getSQLType()!=Types::LONGVARCHAR)&&(dh->getSQLType()!=Types::WLONGVARCHAR)) {#else  if((dh->getSQLType()!=Types::LONGVARCHAR)) {#endif    lastWasNull_=dh->isNull();    return dh->getString();  } else {    // lazily fetch the stream as a string    return streamToString(this->getAsciiStream(idx));  }}ODBCXX_STRING ResultSet::getString(const ODBCXX_STRING& colName){  return this->getString(this->findColumn(colName));}void ResultSet::updateBytes(int idx, const ODBCXX_BYTES& b){  CHECK_COL(idx);  CHECK_LOCATION;  DataHandler* dh=rowset_->getColumn(idx);  if(dh->getSQLType()!=Types::LONGVARBINARY) {    dh->setBytes(b);  } else {    dh->setStream(bytesToStream(b));  }}void ResultSet::updateBytes(const ODBCXX_STRING& colName,                            const ODBCXX_BYTES& b){  this->updateBytes(this->findColumn(colName),b);}ODBCXX_BYTES ResultSet::getBytes(int idx){  CHECK_COL(idx);  CHECK_LOCATION;  DataHandler* dh=rowset_->getColumn(idx);  if(dh->getSQLType()!=Types::LONGVARBINARY) {    lastWasNull_=dh->isNull();    return dh->getBytes();  } else {    return streamToBytes(this->getBinaryStream(idx));  }}ODBCXX_BYTES ResultSet::getBytes(const ODBCXX_STRING& colName){  return this->getBytes(this->findColumn(colName));}//nor did thisvoid ResultSet::updateNull(int idx){  CHECK_COL(idx);  CHECK_LOCATION;  rowset_->getColumn(idx)->setNull();}void ResultSet::updateNull(const ODBCXX_STRING& colName){  this->updateNull(this->findColumn(colName));}//or thisODBCXX_STREAM* ResultSet::getAsciiStream(int idx){  CHECK_COL(idx);  CHECK_LOCATION;  // we can't get the stream of the insert row  CHECK_INSERT_ROW;  //if the stream is not created yet, we create it  DataHandler* dh=rowset_->getColumn(idx);  ODBCXX_STREAM* s=dh->getStream();  if(s==NULL) {#if defined(ODBCXX_HAVE_SQLUCODE_H)    s=new DataStream(this,hstmt_,idx,SQL_C_TCHAR,#else    s=new DataStream(this,hstmt_,idx,SQL_C_CHAR,#endif                     dh->dataStatus_[dh->currentRow_]);    dh->setStream(s);  }  lastWasNull_=dh->isNull();  return s;}ODBCXX_STREAM* ResultSet::getAsciiStream(const ODBCXX_STRING& colName){  return this->getAsciiStream(this->findColumn(colName));}ODBCXX_STREAM* ResultSet::getBinaryStream(int idx){  CHECK_COL(idx);  CHECK_LOCATION;  CHECK_INSERT_ROW;  DataHandler* dh=rowset_->getColumn(idx);  ODBCXX_STREAM* s=dh->getStream();  if(s==NULL) {    s=new DataStream(this,hstmt_,idx,SQL_C_BINARY,                     dh->dataStatus_[dh->currentRow_]);    dh->setStream(s);  }  lastWasNull_=dh->isNull();  return s;}ODBCXX_STREAM* ResultSet::getBinaryStream(const ODBCXX_STRING& colName){  return this->getBinaryStream(this->findColumn(colName));}void ResultSet::updateAsciiStream(int idx, ODBCXX_STREAM* s, int len){  CHECK_COL(idx);  CHECK_LOCATION;  DataHandler* dh=rowset_->getColumn(idx);  dh->setStream(s,len);}void ResultSet::updateAsciiStream(const ODBCXX_STRING& colName,                                  ODBCXX_STREAM* s, int len){  this->updateAsciiStream(findColumn(colName),s,len);}void ResultSet::updateBinaryStream(int idx, ODBCXX_STREAM* s, int len){  CHECK_COL(idx);  CHECK_LOCATION;  DataHandler* dh=rowset_->getColumn(idx);  dh->setStream(s,len);}void ResultSet::updateBinaryStream(const ODBCXX_STRING& colName,                                   ODBCXX_STREAM* s, int len){  this->updateBinaryStream(findColumn(colName),s,len);}

⌨️ 快捷键说明

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