29using namespace oracle::occi;
46 fNumIterations(niter),
52 fStmt->setPrefetchMemorySize(1000000);
53 fStmt->setPrefetchRowCount(niter);
54 fStmt->setMaxIterations(niter);
92#define CheckStatement(method, res) \
96 SetError(-1,"Statement is not correctly initialized",method); \
102#define CheckSetPar(method) \
104 CheckStatement(method, kFALSE); \
105 if (!IsParSettMode()) { \
106 SetError(-1,"Parameters cannot be set for this statement", method); \
110 TString errmsg("Invalid parameter number "); \
112 SetError(-1,errmsg.Data(),method); \
117#define CheckGetField(method, defres) \
120 if (!IsResultSet()) { \
121 SetError(-1,"There is no result set for statement", method); \
124 if ((npar<0) || (npar>=fBufferSize)) { \
125 TString errmsg("Invalid parameter number "); \
127 SetError(-1,errmsg.Data(),method); \
176 fStmt->executeUpdate();
183 }
catch (SQLException &oraex) {
184 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"Process");
199 return fStmt->getUpdateCount();
200 }
catch (SQLException &oraex) {
201 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetNumAffectedRows");
215 Info(
"GetParametersNumber",
"Not implemented");
228 fStmt->setNull(npar+1, OCCIINT);
231 }
catch (SQLException &oraex) {
232 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetNull");
247 fStmt->setInt(npar+1, value);
250 }
catch (SQLException &oraex) {
251 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetInt");
265 fStmt->setUInt(npar+1, value);
267 }
catch (SQLException &oraex) {
268 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetUInt");
282 fStmt->setNumber(npar+1, Number(value));
284 }
catch (SQLException &oraex) {
285 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetLong");
298 fStmt->setNumber(npar+1, Number((
long double)value));
300 }
catch (SQLException &oraex) {
301 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetLong64");
314 fStmt->setNumber(npar+1, Number((
long double)value));
316 }
catch (SQLException &oraex) {
317 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetULong64");
330 fStmt->setDouble(npar+1, value);
332 }
catch (SQLException &oraex) {
333 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetDouble");
349 fStmt->setDatabaseNCHARParam(npar+1,
true);
350 fStmt->setMaxParamSize(npar+1, maxsize);
353 fStmt->setString(npar+1, value);
355 }
catch (SQLException &oraex) {
356 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetString");
372 fStmt->setMaxParamSize(npar+1, maxsize);
374 Bytes buf((
unsigned char*) mem, size);
376 fStmt->setBytes(npar+1, buf);
380 }
catch (SQLException &oraex) {
381 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetBinary");
394 Date tm =
fStmt->getDate(npar+1);
396 unsigned int o_month, o_day, o_hour, o_minute, o_second;
397 tm.getDate(o_year, o_month, o_day, o_hour, o_minute, o_second);
398 tm.setDate(year, month, day, o_hour, o_minute, o_second);
399 fStmt->setDate(npar+1, tm);
401 }
catch (SQLException &oraex) {
402 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetDate");
416 Date tm =
fStmt->getDate(npar+1);
418 unsigned int o_month, o_day, o_hour, o_minute, o_second;
419 tm.getDate(o_year, o_month, o_day, o_hour, o_minute, o_second);
420 tm.setDate(o_year, o_month, o_day, hour, min, sec);
421 fStmt->setDate(npar+1, tm);
423 }
catch (SQLException &oraex) {
424 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetTime");
438 Date tm(
fEnv, year, month, day, hour, min, sec);
439 fStmt->setDate(npar+1, tm);
441 }
catch (SQLException &oraex) {
442 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetDatime");
456 Timestamp tm(
fEnv, year, month, day, hour, min, sec, frac);
457 fStmt->setTimestamp(npar+1, tm);
459 }
catch (SQLException &oraex) {
460 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetTimestamp");
474 setVector(
fStmt, npar+1, value, schemaName, typeName);
476 }
catch (SQLException &oraex) {
477 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVInt");
491 setVector(
fStmt, npar+1, value, schemaName, typeName);
493 }
catch (SQLException &oraex) {
494 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVUInt");
508 std::vector<Number> nvec;
509 for (std::vector<Long_t>::const_iterator it = value.begin();
512 nvec.push_back(Number(*it));
514 setVector(
fStmt, npar+1, nvec, schemaName, typeName);
516 }
catch (SQLException &oraex) {
517 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVLong");
530 std::vector<Number> nvec;
531 for (std::vector<Long64_t>::const_iterator it = value.begin();
534 nvec.push_back(Number((
long double)*it));
536 setVector(
fStmt, npar+1, nvec, schemaName, typeName);
538 }
catch (SQLException &oraex) {
539 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVLong64");
552 std::vector<Number> nvec;
553 for (std::vector<ULong64_t>::const_iterator it = value.begin();
556 nvec.push_back(Number((
long double)*it));
558 setVector(
fStmt, npar+1, nvec, schemaName, typeName);
560 }
catch (SQLException &oraex) {
561 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVULong64");
574 setVector(
fStmt, npar+1, value, schemaName, typeName);
576 }
catch (SQLException &oraex) {
577 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVDouble");
593 fStmt->executeUpdate();
597 fStmt->addIteration();
603 }
catch (SQLException &oraex) {
604 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"NextIteration");
618 if (
fStmt->status() == Statement::RESULT_SET_AVAILABLE) {
627 }
catch (SQLException &oraex) {
628 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"StoreResult");
644 fResult->setMaxColumnSize(nfield+1, maxsize);
646 fStmt->setMaxParamSize(nfield+1, maxsize);
648 }
catch (SQLException &oraex) {
649 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetMaxFieldSize");
674 std::string buff = (*fFieldInfo)[npar].getString(MetaData::ATTR_NAME);
676 if (buff.length()==0)
return 0;
680 strcpy(
fBuffer[npar].namebuf, buff.c_str());
694 SetError(-1,
"There is no result set for statement",
"NextResultRow");
707 if (
fResult->next() == oracle::occi::ResultSet::END_OF_FETCH) {
713 }
catch (SQLException &oraex) {
714 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"NextResultRow");
716 if (oraex.getErrorCode()==32108)
717 Info(
"NextResultRow",
"Use TSQLStatement::SetMaxFieldSize() to solve a problem");
732 return fResult->isNull(npar+1);
733 }
catch (SQLException &oraex) {
734 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"IsNull");
752 }
catch (SQLException &oraex) {
753 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetInt");
770 res =
fResult->getUInt(npar+1);
771 }
catch (SQLException &oraex) {
772 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetUInt");
791 }
catch (SQLException &oraex) {
792 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetLong");
810 }
catch (SQLException &oraex) {
811 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetLong64");
829 }
catch (SQLException &oraex) {
830 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetULong64");
847 res =
fResult->getDouble(npar+1);
848 }
catch (SQLException &oraex) {
849 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetDouble");
865 if (
fResult->isNull(npar+1))
return 0;
867 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
873 int prec = (*fFieldInfo)[npar].getInt(MetaData::ATTR_PRECISION);
874 int scale = (*fFieldInfo)[npar].getInt(MetaData::ATTR_SCALE);
876 if ((scale == 0) || (prec == 0)) {
877 res =
fResult->getString(npar+1);
879 double double_val =
fResult->getDouble(npar+1);
890 res =
fResult->getString(npar+1);
896 case SQLT_TIMESTAMP_TZ:
897 case SQLT_TIMESTAMP_LTZ:
901 res =
fResult->getString(npar+1);
902 Info(
"getString",
"Type %d may not be supported", datatype);
905 int len = res.length();
910 strcpy(
fBuffer[npar].strbuf, res.c_str());
915 }
catch (SQLException &oraex) {
916 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetString");
935 if (
fBuffer[npar].strbufsize>=0) {
944 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
948 Bytes parbytes =
fResult->getBytes(npar+1);
950 size = parbytes.length();
959 parbytes.getBytes((
unsigned char*) mem, size);
966 Blob parblob =
fResult->getBlob(npar+1);
968 size = parblob.length();
977 parblob.read(size, (
unsigned char*) mem, size);
984 Clob parclob =
fResult->getClob(npar+1);
986 size = parclob.length();
995 parclob.read(size, (
unsigned char*) mem, size);
1004 Bfile parbfile =
fResult->getBfile(npar+1);
1006 size = parbfile.length();
1015 parbfile.read(size, (
unsigned char*) mem, size);
1022 Error(
"GetBinary",
"Oracle data type %d not supported", datatype);
1023 SetError(-1,
"Unsupported type for binary convertion",
"GetBinary");
1029 }
catch (SQLException &oraex) {
1030 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetBinary");
1042 Int_t hour, min, sec;
1044 return GetDatime(npar, year, month, day, hour, min, sec);
1052 Int_t year, month, day;
1054 return GetDatime(npar, year, month, day, hour, min, sec);
1065 if (!
fResult->isNull(npar+1)) {
1066 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
1068 if (datatype!=SQLT_DAT)
return kFALSE;
1070 Date tm =
fResult->getDate(npar+1);
1072 unsigned int o_month, o_day, o_hour, o_minute, o_second;
1073 tm.getDate(o_year, o_month, o_day, o_hour, o_minute, o_second);
1074 year = (
Int_t) o_year;
1075 month = (
Int_t) o_month;
1076 day = (
Int_t) o_day;
1077 hour = (
Int_t) o_hour;
1078 min = (
Int_t) o_minute;
1079 sec = (
Int_t) o_second;
1082 }
catch (SQLException &oraex) {
1083 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetDatime");
1097 if (!
fResult->isNull(npar+1)) {
1098 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
1100 if ((datatype!=SQLT_TIMESTAMP) &&
1101 (datatype!=SQLT_TIMESTAMP_TZ) &&
1102 (datatype!=SQLT_TIMESTAMP_LTZ))
return kFALSE;
1104 Timestamp tm =
fResult->getTimestamp(npar+1);
1106 unsigned int o_month, o_day, o_hour, o_minute, o_second, o_frac;
1107 tm.getDate(o_year, o_month, o_day);
1108 tm.getTime(o_hour, o_minute, o_second, o_frac);
1109 year = (
Int_t) o_year;
1110 month = (
Int_t) o_month;
1111 day = (
Int_t) o_day;
1112 hour = (
Int_t) o_hour;
1113 min = (
Int_t) o_minute;
1114 sec = (
Int_t) o_second;
1115 frac = (
Int_t) o_frac;
1118 }
catch (SQLException &oraex) {
1119 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetTimestamp");
1133 getVector(
fResult, npar+1, value);
1135 }
catch (SQLException &oraex) {
1136 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVInt");
1149 getVector(
fResult, npar+1, value);
1151 }
catch (SQLException &oraex) {
1152 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVUInt");
1165 std::vector<Number> res;
1167 getVector(
fResult, npar+1, res);
1168 for (std::vector<Number>::const_iterator it = res.begin();
1171 value.push_back((
Long_t)*it);
1174 }
catch (SQLException &oraex) {
1175 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVLong");
1187 std::vector<Number> res;
1189 getVector(
fResult, npar+1, res);
1190 for (std::vector<Number>::const_iterator it = res.begin();
1193 value.push_back((
Long_t)*it);
1196 }
catch (SQLException &oraex) {
1197 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVLong64");
1209 std::vector<Number> res;
1211 getVector(
fResult, npar+1, res);
1212 for (std::vector<Number>::const_iterator it = res.begin();
1215 value.push_back((
Long_t)(
long double)*it);
1218 }
catch (SQLException &oraex) {
1219 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVULong64");
1232 getVector(
fResult, npar+1, value);
1234 }
catch (SQLException &oraex) {
1235 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVDouble");
unsigned long long ULong64_t
#define CheckStatement(method, res)
#define CheckSetPar(method)
#define CheckGetField(method, defres)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
oracle::occi::Statement * fStmt
virtual Int_t GetNumFields()
Returns number of fields in result set.
virtual Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000)
set parameter value as binary data
virtual Bool_t NextIteration()
Add next iteration for statement with parameters.
virtual Bool_t SetVUInt(Int_t npar, const std::vector< UInt_t > value, const char *schemaName, const char *typeName)
Set vector of unsigned integer values for parameter npar.
void SetBufferSize(Int_t size)
Set buffer size, which is used to keep string values of currently fetched column.
virtual Bool_t SetULong64(Int_t npar, ULong64_t value)
Set unsigned 64-bit integer value for parameter npar.
virtual const char * GetString(Int_t npar)
return field value as string
virtual Bool_t SetUInt(Int_t npar, UInt_t value)
Set unsigned integer value for parameter npar.
virtual Bool_t GetVInt(Int_t npar, std::vector< Int_t > &value)
return field value as vector of integers
virtual Bool_t GetVLong64(Int_t npar, std::vector< Long64_t > &value)
return field value as vector of 64-bit integers
virtual const char * GetFieldName(Int_t nfield)
Return field name in result set.
virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec)
Set time value for parameter npar.
virtual Bool_t SetVLong64(Int_t npar, const std::vector< Long64_t > value, const char *schemaName, const char *typeName)
Set vector of 64-bit integer values for parameter npar.
virtual Long_t GetLong(Int_t npar)
return field value as long integer
virtual void Close(Option_t *="")
Close Oracle statement Removes and destroys all buffers and metainfo.
oracle::occi::Environment * fEnv
virtual Bool_t GetVLong(Int_t npar, std::vector< Long_t > &value)
return field value as vector of long integers
virtual Bool_t GetVUInt(Int_t npar, std::vector< UInt_t > &value)
return field value as vector of unsigned integers
virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
Set date value for parameter npar.
virtual ~TOracleStatement()
Destructor of TOracleStatement clas.
virtual Double_t GetDouble(Int_t npar)
return field value as double
virtual Bool_t GetVULong64(Int_t npar, std::vector< ULong64_t > &value)
return field value as vector of unsigned 64-bit integers
virtual Bool_t SetVInt(Int_t npar, const std::vector< Int_t > value, const char *schemaName, const char *typeName)
Set vector of integer values for parameter npar.
virtual Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256)
Set string value for parameter npar.
virtual Bool_t SetVULong64(Int_t npar, const std::vector< ULong64_t > value, const char *schemaName, const char *typeName)
Set vector of unsigned 64-bit integer values for parameter npar.
virtual Bool_t SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac=0)
Set date & time value for parameter npar.
virtual Bool_t SetInt(Int_t npar, Int_t value)
Set integer value for parameter npar.
void CloseBuffer()
Destroy buffers, used in data fetching.
virtual Int_t GetInt(Int_t npar)
return field value as integer
virtual Bool_t SetMaxFieldSize(Int_t nfield, Long_t maxsize)
Defines maximum size for field which must be used for read or write operation Some Oracle types as LO...
virtual Bool_t SetVLong(Int_t npar, const std::vector< Long_t > value, const char *schemaName, const char *typeName)
Set vector of long integer values for parameter npar.
virtual Bool_t Process()
Process SQL statement.
virtual Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size)
Return field value as binary array Supports LONG, BLOB, CLOB, BFILE, CFILE types of columns Reads com...
virtual Bool_t NextResultRow()
Move cursor to next row in result set.
virtual Bool_t StoreResult()
Store result of statement processing.
Bool_t IsParSettMode() const
virtual Bool_t SetDouble(Int_t npar, Double_t value)
Set double value for parameter npar.
virtual Bool_t SetLong(Int_t npar, Long_t value)
Set long integer value for parameter npar.
virtual Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec)
Set date & time value for parameter npar.
TOracleStatement(oracle::occi::Environment *env, oracle::occi::Connection *conn, oracle::occi::Statement *stmt, Int_t niter, Bool_t errout=kTRUE)
Normal constructor of TOracleStatement class On creation time specifies buffer length,...
virtual UInt_t GetUInt(Int_t npar)
return field value as unsigned integer
virtual ULong64_t GetULong64(Int_t npar)
return field value as unsigned 64-bit integer
virtual Int_t GetNumParameters()
Return number of parameters in statement Not yet implemented for Oracle.
virtual Bool_t GetDatime(Int_t npar, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec)
return field value as date & time
virtual Int_t GetNumAffectedRows()
Return number of affected rows after statement Process() was called Make sense for queries like SELEC...
virtual Bool_t GetVDouble(Int_t npar, std::vector< Double_t > &value)
return field value as vector of doubles
oracle::occi::Connection * fConn
virtual Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec)
return field value as time
Bool_t IsResultSet() const
virtual Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day)
return field value as date
virtual Bool_t SetVDouble(Int_t npar, const std::vector< Double_t > value, const char *schemaName, const char *typeName)
Set vector of double values for parameter npar.
virtual Long64_t GetLong64(Int_t npar)
return field value as 64-bit integer
virtual Bool_t IsNull(Int_t)
Checks if fieled value in result set is NULL.
virtual Bool_t SetLong64(Int_t npar, Long64_t value)
Set 64-bit integer value for parameter npar.
virtual Bool_t SetNull(Int_t npar)
Set NULL as value of parameter npar.
oracle::occi::ResultSet * fResult
std::vector< oracle::occi::MetaData > * fFieldInfo
virtual Bool_t GetTimestamp(Int_t npar, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec, Int_t &frac)
return field value as date & time
static const char * GetFloatFormat()
return current printf format for float/double members, default "%e"
void SetError(Int_t code, const char *msg, const char *method=0)
set new values for error fields if method specified, displays error message
void ClearError()
reset error fields