#include "TOracleRow.h"
#include "Riostream.h"
#include <string.h>
using namespace std;
ClassImp(TOracleRow);
TOracleRow::TOracleRow(ResultSet *rs, vector<MetaData> *fieldMetaData)
{
fResult = rs;
fFieldInfo = fieldMetaData;
fFieldCount = fFieldInfo->size();
fFieldsBuffer = 0;
GetRowData();
}
TOracleRow::~TOracleRow()
{
Close();
}
void TOracleRow::Close(Option_t *)
{
if (fFieldsBuffer!=0) {
for (int n=0;n<fFieldCount;n++)
if (fFieldsBuffer[n]) delete[] fFieldsBuffer[n];
delete[] fFieldsBuffer;
}
fFieldInfo = 0;
fFieldCount = 0;
fResult = 0;
}
Bool_t TOracleRow::IsValid(Int_t field)
{
if (!fResult) {
Error("IsValid", "row closed");
return kFALSE;
}
if (field < 0 || field >= (Int_t)fFieldInfo->size()) {
Error("IsValid", "field index out of bounds");
return kFALSE;
}
return kTRUE;
}
ULong_t TOracleRow::GetFieldLength(Int_t field)
{
if (!IsValid(field) || fFieldInfo->size() <= 0)
return 0;
MetaData fieldMD = (*fFieldInfo)[field];
return fieldMD.getInt(MetaData::ATTR_DATA_SIZE);
}
const char* TOracleRow::GetField(Int_t field)
{
if ((field<0) || (field>=fFieldCount)) {
Error("TOracleRow","GetField(): out-of-range or No RowData/ResultSet/MetaData");
return 0;
}
return fFieldsBuffer ? fFieldsBuffer[field] : 0;
}
void TOracleRow::GetRowData()
{
if (!fResult || !fFieldInfo || (fFieldCount<=0)) return;
fFieldsBuffer = new char* [fFieldCount];
for (int n=0;n<fFieldCount;n++)
fFieldsBuffer[n] = 0;
std::string res;
char str_number[200];
int fPrecision, fScale, fDataType;
double double_val;
try {
for (int field=0;field<fFieldCount;field++) {
if (fResult->isNull(field+1)) continue;
fDataType = (*fFieldInfo)[field].getInt(MetaData::ATTR_DATA_TYPE);
switch (fDataType) {
case SQLT_NUM:
fPrecision = (*fFieldInfo)[field].getInt(MetaData::ATTR_PRECISION);
fScale = (*fFieldInfo)[field].getInt(MetaData::ATTR_SCALE);
if ((fScale == 0) || (fPrecision == 0)) {
res = fResult->getString(field+1);
} else {
double_val = fResult->getDouble(field+1);
sprintf(str_number, "%lf", double_val);
res = str_number;
}
break;
case SQLT_CHR:
case SQLT_VCS:
case SQLT_AFC:
case SQLT_AVC:
res = fResult->getString(field+1);
break;
case SQLT_DAT:
res = (fResult->getDate(field+1)).toText("MM/DD/YYYY, HH24:MI:SS");
break;
case SQLT_TIMESTAMP:
case SQLT_TIMESTAMP_TZ:
case SQLT_TIMESTAMP_LTZ:
res = (fResult->getTimestamp(field+1)).toText("MM/DD/YYYY, HH24:MI:SS",0);
break;
default:
Error("GetRowData()","Oracle type %d not supported.", fDataType);
continue;
}
int len = res.length();
if (len>0) {
fFieldsBuffer[field] = new char[len+1];
strcpy(fFieldsBuffer[field], res.c_str());
}
}
} catch (SQLException &oraex) {
Error("GetRowData()", (oraex.getMessage()).c_str());
}
}
Last change: Wed Jun 25 08:50:01 2008
Last generated: 2008-06-25 08:50
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.