FEDRA emulsion software from the OPERA Collaboration
TOracleRow Class Reference

#include <TOracleRow.h>

Inheritance diagram for TOracleRow:
Collaboration diagram for TOracleRow:

Public Member Functions

void Close (Option_t *opt="")
 
const char * GetField (Int_t field)
 
ULong_t GetFieldLength (Int_t field)
 
 TOracleRow (ResultSet *rs, std::vector< MetaData > *fieldMetaData)
 
 TOracleRow (UInt_t updateCount)
 
 ~TOracleRow ()
 

Protected Member Functions

int GetRowData ()
 
int GetRowData2 ()
 

Private Member Functions

Bool_t IsValid (Int_t field)
 

Private Attributes

UInt_t fFieldCount
 
std::vector< MetaData > * fFieldInfo
 
std::vector< std::string > * fFields
 
ResultSet * fResult
 
Int_t fResultType
 
UInt_t fUpdateCount
 

Constructor & Destructor Documentation

◆ TOracleRow() [1/2]

TOracleRow::TOracleRow ( ResultSet *  rs,
std::vector< MetaData > *  fieldMetaData 
)

◆ TOracleRow() [2/2]

TOracleRow::TOracleRow ( UInt_t  updateCount)
36 {
37  fUpdateCount = updateCount;
38  fFieldCount = 0;
39  fFields = 0;
40  fResultType = 0;
41 }
std::vector< std::string > * fFields
Definition: TOracleRow.h:36
Int_t fResultType
Definition: TOracleRow.h:38
UInt_t fUpdateCount
Definition: TOracleRow.h:37
UInt_t fFieldCount
Definition: TOracleRow.h:35

◆ ~TOracleRow()

TOracleRow::~TOracleRow ( )
45 {
46  // Destroy row object.
47 
48  if (fResultType >= 0) {
49  Close();
50  }
51 }
void Close(Option_t *opt="")
Definition: TOracleRow.cxx:54

Member Function Documentation

◆ Close()

void TOracleRow::Close ( Option_t *  opt = "")
55 {
56  // Close row.
57 
58  if (fResultType == -1)
59  return;
60 
61  fFieldInfo = 0;
62  fFieldCount = 0;
63  fResult = 0;
64  fResultType = 0;
65  if (fFields)
66  delete fFields;
67 }
std::vector< MetaData > * fFieldInfo
Definition: TOracleRow.h:34
ResultSet * fResult
Definition: TOracleRow.h:33

◆ GetField()

const char * TOracleRow::GetField ( Int_t  field)
198 {
199  if (!IsValid(field) || !fResult || !fFields) {
200  Error("TOracleRow","GetField(): out-of-range or No RowData/ResultSet/MetaData");
201  return 0;
202  }
203  return (*fFields)[field].c_str();
204 }
Bool_t IsValid(Int_t field)
Definition: TOracleRow.cxx:70

◆ GetFieldLength()

ULong_t TOracleRow::GetFieldLength ( Int_t  field)
87 {
88  // Get length in bytes of specified field.
89 
90  if (!IsValid(field) || fFieldInfo->size() <= 0)
91  return 0;
92 
93  MetaData fieldMD = (*fFieldInfo)[field];
94 
95  return fieldMD.getInt(MetaData::ATTR_DATA_SIZE);
96 }

◆ GetRowData()

int TOracleRow::GetRowData ( )
protected
100 {
101  // Fetch a row from current resultset into fFields vector as ASCII
102  // supported Oracle internal types conversion:
103  // NUMBER -> int, float, double -> (char *)
104  // CHAR -> (char *)
105  // VARCHAR2 -> (char *)
106  // TIMESTAMP -> Timestamp -> (char *)
107  // DATE -> (char *)
108  // NOTE: above types are tested to work and this is the default impl.
109 
110  if (!fFields || !fResult || !fFieldInfo) {
111  Error("GetRowData()", "Empty row, resultset or MetaData");
112  return 0;
113  }
114  int fDataType, fDataSize, fPrecision, fScale;
115  char str_number[1024];
116  int int_val; double double_val; float float_val;
117  try {
118  for (UInt_t i=0; i<fFieldCount; i++) {
119  if (fResult->isNull(i+1)) {
120  (*fFields)[i] = "";
121  } else {
122  fDataType = (*fFieldInfo)[i].getInt(MetaData::ATTR_DATA_TYPE);
123  fDataSize = (*fFieldInfo)[i].getInt(MetaData::ATTR_DATA_SIZE);
124  fPrecision = (*fFieldInfo)[i].getInt(MetaData::ATTR_PRECISION);
125  fScale = (*fFieldInfo)[i].getInt(MetaData::ATTR_SCALE);
126  switch (fDataType) {
127  case 2: //NUMBER
128  if (fScale == 0 || fPrecision == 0) {
129  int_val = fResult->getInt(i+1);
130  sprintf(str_number, "%d", int_val);
131  } else if (fPrecision != 0 && fScale == -127) {
132  double_val = fResult->getDouble(i+1);
133  sprintf(str_number, "%lf", double_val);
134  } else if (fScale > 0) {
135  float_val = fResult->getFloat(i+1);
136  sprintf(str_number, "%f", float_val);
137  }
138  (*fFields)[i] = str_number;
139  break;
140  case 96: // CHAR
141  case 1: // VARCHAR2
142  (*fFields)[i] = fResult->getString(i+1);
143  break;
144  case 187: // TIMESTAMP
145  case 232: // TIMESTAMP WITH LOCAL TIMEZONE
146  case 188: // TIMESTAMP WITH TIMEZONE
147  (*fFields)[i] = (fResult->getTimestamp(i+1)).toText("MM/DD/YYYY, HH24:MI:SS",0);
148  break;
149  case 12: // DATE
150  //to fetch DATE, getDate() does NOT work in occi
151  (*fFields)[i] = fResult->getString(i+1);
152  break;
153  default:
154  Error("GetRowData()","Oracle type %d not supported.", fDataType);
155  return 0;
156  }
157  }
158  }
159  return 1;
160  } catch (SQLException &oraex) {
161  Error("GetRowData()", (oraex.getMessage()).c_str());
162  return 0;
163  }
164 }

◆ GetRowData2()

int TOracleRow::GetRowData2 ( )
protected
168 {
169  // Fetch a row from current resultset into fFields vector as ASCII.
170  // This impl only use getString() to fetch column value.
171  // Pro: support all type conversions, indicated by OCCI API doc
172  // Con: not tested for each Oracle internal type. it has problem on
173  // Timestamp or Date type conversion.
174  // NOTE: This is supposed to be the easiest and direct implemention.
175 
176  if (!fFields || !fResult || !fFieldInfo) {
177  Error("GetRowData2()", "Empty row, resultset or MetaData");
178  return 0;
179  }
180 
181  try {
182  for (UInt_t i=0; i<fFieldCount; i++) {
183  if (fResult->isNull(i+1)) {
184  (*fFields)[i] = "";
185  } else {
186  (*fFields)[i] = fResult->getString(i+1);
187  }
188  }
189  return 1;
190  } catch (SQLException &oraex) {
191  Error("GetRowData2()", (oraex.getMessage()).c_str());
192  return 0;
193  }
194 }

◆ IsValid()

Bool_t TOracleRow::IsValid ( Int_t  field)
private
71 {
72  // Check if row is open and field index within range.
73 
74  if (!fResult) {
75  Error("IsValid", "row closed");
76  return kFALSE;
77  }
78  if (field < 0 || field >= (Int_t)fFieldInfo->size()) {
79  Error("IsValid", "field index out of bounds");
80  return kFALSE;
81  }
82  return kTRUE;
83 }

Member Data Documentation

◆ fFieldCount

UInt_t TOracleRow::fFieldCount
private

◆ fFieldInfo

std::vector<MetaData>* TOracleRow::fFieldInfo
private

◆ fFields

std::vector<std::string>* TOracleRow::fFields
private

◆ fResult

ResultSet* TOracleRow::fResult
private

◆ fResultType

Int_t TOracleRow::fResultType
private

◆ fUpdateCount

UInt_t TOracleRow::fUpdateCount
private

The documentation for this class was generated from the following files: