29using namespace oracle::occi;
42 fNumIterations(niter),
46 fStmt->setPrefetchMemorySize(1000000);
47 fStmt->setPrefetchRowCount(niter);
48 fStmt->setMaxIterations(niter);
86#define CheckStatement(method, res) \
90 SetError(-1,"Statement is not correctly initialized",method); \
96#define CheckSetPar(method) \
98 CheckStatement(method, kFALSE); \
99 if (!IsParSettMode()) { \
100 SetError(-1,"Parameters cannot be set for this statement", method); \
104 TString errmsg("Invalid parameter number "); \
106 SetError(-1,errmsg.Data(),method); \
111#define CheckGetField(method, defres) \
114 if (!IsResultSet()) { \
115 SetError(-1,"There is no result set for statement", method); \
118 if ((npar<0) || (npar>=fBufferSize)) { \
119 TString errmsg("Invalid parameter number "); \
121 SetError(-1,errmsg.Data(),method); \
169 fStmt->executeUpdate();
176 }
catch (SQLException &oraex) {
177 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"Process");
192 return fStmt->getUpdateCount();
193 }
catch (SQLException &oraex) {
194 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetNumAffectedRows");
208 Info(
"GetParametersNumber",
"Not implemented");
221 fStmt->setNull(npar+1, OCCIINT);
224 }
catch (SQLException &oraex) {
225 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetNull");
240 fStmt->setInt(npar+1, value);
243 }
catch (SQLException &oraex) {
244 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetInt");
258 fStmt->setUInt(npar+1, value);
260 }
catch (SQLException &oraex) {
261 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetUInt");
275 fStmt->setNumber(npar+1, Number(value));
277 }
catch (SQLException &oraex) {
278 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetLong");
291 fStmt->setNumber(npar+1, Number((
long double)value));
293 }
catch (SQLException &oraex) {
294 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetLong64");
307 fStmt->setNumber(npar+1, Number((
long double)value));
309 }
catch (SQLException &oraex) {
310 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetULong64");
323 fStmt->setDouble(npar+1, value);
325 }
catch (SQLException &oraex) {
326 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetDouble");
342 fStmt->setDatabaseNCHARParam(npar+1,
true);
343 fStmt->setMaxParamSize(npar+1, maxsize);
346 fStmt->setString(npar+1, value);
348 }
catch (SQLException &oraex) {
349 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetString");
365 fStmt->setMaxParamSize(npar+1, maxsize);
367 Bytes buf((
unsigned char*) mem, size);
369 fStmt->setBytes(npar+1, buf);
373 }
catch (SQLException &oraex) {
374 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetBinary");
387 Date tm =
fStmt->getDate(npar+1);
389 unsigned int o_month, o_day, o_hour, o_minute, o_second;
390 tm.getDate(o_year, o_month, o_day, o_hour, o_minute, o_second);
391 tm.setDate(year, month, day, o_hour, o_minute, o_second);
392 fStmt->setDate(npar+1, tm);
394 }
catch (SQLException &oraex) {
395 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetDate");
409 Date tm =
fStmt->getDate(npar+1);
411 unsigned int o_month, o_day, o_hour, o_minute, o_second;
412 tm.getDate(o_year, o_month, o_day, o_hour, o_minute, o_second);
413 tm.setDate(o_year, o_month, o_day, hour, min, sec);
414 fStmt->setDate(npar+1, tm);
416 }
catch (SQLException &oraex) {
417 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetTime");
431 Date tm(
fEnv, year, month, day, hour, min, sec);
432 fStmt->setDate(npar+1, tm);
434 }
catch (SQLException &oraex) {
435 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetDatime");
449 Timestamp tm(
fEnv, year, month, day, hour, min, sec, frac);
450 fStmt->setTimestamp(npar+1, tm);
452 }
catch (SQLException &oraex) {
453 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetTimestamp");
467 setVector(
fStmt, npar+1, value, schemaName, typeName);
469 }
catch (SQLException &oraex) {
470 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVInt");
484 setVector(
fStmt, npar+1, value, schemaName, typeName);
486 }
catch (SQLException &oraex) {
487 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVUInt");
501 std::vector<Number> nvec;
502 for (std::vector<Long_t>::const_iterator it = value.begin();
505 nvec.push_back(Number(*it));
507 setVector(
fStmt, npar+1, nvec, schemaName, typeName);
509 }
catch (SQLException &oraex) {
510 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVLong");
523 std::vector<Number> nvec;
524 for (std::vector<Long64_t>::const_iterator it = value.begin();
527 nvec.push_back(Number((
long double)*it));
529 setVector(
fStmt, npar+1, nvec, schemaName, typeName);
531 }
catch (SQLException &oraex) {
532 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVLong64");
545 std::vector<Number> nvec;
546 for (std::vector<ULong64_t>::const_iterator it = value.begin();
549 nvec.push_back(Number((
long double)*it));
551 setVector(
fStmt, npar+1, nvec, schemaName, typeName);
553 }
catch (SQLException &oraex) {
554 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVULong64");
567 setVector(
fStmt, npar+1, value, schemaName, typeName);
569 }
catch (SQLException &oraex) {
570 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetVDouble");
586 fStmt->executeUpdate();
590 fStmt->addIteration();
596 }
catch (SQLException &oraex) {
597 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"NextIteration");
611 if (
fStmt->status() == Statement::RESULT_SET_AVAILABLE) {
620 }
catch (SQLException &oraex) {
621 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"StoreResult");
637 fResult->setMaxColumnSize(nfield+1, maxsize);
639 fStmt->setMaxParamSize(nfield+1, maxsize);
641 }
catch (SQLException &oraex) {
642 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"SetMaxFieldSize");
665 if (
fBuffer[npar].namebuf.empty())
666 fBuffer[npar].
namebuf = (*fFieldInfo)[npar].getString(MetaData::ATTR_NAME);
680 SetError(-1,
"There is no result set for statement",
"NextResultRow");
694 if (
fResult->next() == oracle::occi::ResultSet::END_OF_FETCH) {
700 }
catch (SQLException &oraex) {
701 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"NextResultRow");
703 if (oraex.getErrorCode()==32108)
704 Info(
"NextResultRow",
"Use TSQLStatement::SetMaxFieldSize() to solve a problem");
719 return fResult->isNull(npar+1);
720 }
catch (SQLException &oraex) {
721 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"IsNull");
739 }
catch (SQLException &oraex) {
740 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetInt");
757 res =
fResult->getUInt(npar+1);
758 }
catch (SQLException &oraex) {
759 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetUInt");
778 }
catch (SQLException &oraex) {
779 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetLong");
797 }
catch (SQLException &oraex) {
798 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetLong64");
816 }
catch (SQLException &oraex) {
817 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetULong64");
834 res =
fResult->getDouble(npar+1);
835 }
catch (SQLException &oraex) {
836 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetDouble");
853 if (
fResult->isNull(npar+1))
return 0;
855 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
861 int prec = (*fFieldInfo)[npar].getInt(MetaData::ATTR_PRECISION);
862 int scale = (*fFieldInfo)[npar].getInt(MetaData::ATTR_SCALE);
864 if ((scale == 0) || (prec == 0)) {
865 res =
fResult->getString(npar+1);
867 double double_val =
fResult->getDouble(npar+1);
878 res =
fResult->getString(npar+1);
884 case SQLT_TIMESTAMP_TZ:
885 case SQLT_TIMESTAMP_LTZ:
889 res =
fResult->getString(npar+1);
890 Info(
"getString",
"Type %d may not be supported", datatype);
893 int len = res.length();
898 strncpy((
char *)
fBuffer[npar].membuf, res.c_str(), len+1);
903 }
catch (SQLException &oraex) {
904 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetString");
923 if (
fBuffer[npar].bufsize >= 0) {
932 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
936 Bytes parbytes =
fResult->getBytes(npar+1);
938 size = parbytes.length();
947 parbytes.getBytes((
unsigned char *) mem, size);
954 Blob parblob =
fResult->getBlob(npar+1);
956 size = parblob.length();
965 parblob.read(size, (
unsigned char *) mem, size);
972 Clob parclob =
fResult->getClob(npar+1);
974 size = parclob.length();
983 parclob.read(size, (
unsigned char *) mem, size);
992 Bfile parbfile =
fResult->getBfile(npar+1);
994 size = parbfile.length();
1003 parbfile.read(size, (
unsigned char *) mem, size);
1010 Error(
"GetBinary",
"Oracle data type %d not supported", datatype);
1011 SetError(-1,
"Unsupported type for binary convertion",
"GetBinary");
1017 }
catch (SQLException &oraex) {
1018 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetBinary");
1030 Int_t hour, min, sec;
1032 return GetDatime(npar, year, month, day, hour, min, sec);
1040 Int_t year, month, day;
1042 return GetDatime(npar, year, month, day, hour, min, sec);
1053 if (!
fResult->isNull(npar+1)) {
1054 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
1056 if (datatype!=SQLT_DAT)
return kFALSE;
1058 Date tm =
fResult->getDate(npar+1);
1060 unsigned int o_month, o_day, o_hour, o_minute, o_second;
1061 tm.getDate(o_year, o_month, o_day, o_hour, o_minute, o_second);
1062 year = (
Int_t) o_year;
1063 month = (
Int_t) o_month;
1064 day = (
Int_t) o_day;
1065 hour = (
Int_t) o_hour;
1066 min = (
Int_t) o_minute;
1067 sec = (
Int_t) o_second;
1070 }
catch (SQLException &oraex) {
1071 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetDatime");
1085 if (!
fResult->isNull(npar+1)) {
1086 int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
1088 if ((datatype!=SQLT_TIMESTAMP) &&
1089 (datatype!=SQLT_TIMESTAMP_TZ) &&
1090 (datatype!=SQLT_TIMESTAMP_LTZ))
return kFALSE;
1092 Timestamp tm =
fResult->getTimestamp(npar+1);
1094 unsigned int o_month, o_day, o_hour, o_minute, o_second, o_frac;
1095 tm.getDate(o_year, o_month, o_day);
1096 tm.getTime(o_hour, o_minute, o_second, o_frac);
1097 year = (
Int_t) o_year;
1098 month = (
Int_t) o_month;
1099 day = (
Int_t) o_day;
1100 hour = (
Int_t) o_hour;
1101 min = (
Int_t) o_minute;
1102 sec = (
Int_t) o_second;
1103 frac = (
Int_t) o_frac;
1106 }
catch (SQLException &oraex) {
1107 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetTimestamp");
1121 getVector(
fResult, npar+1, value);
1123 }
catch (SQLException &oraex) {
1124 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVInt");
1137 getVector(
fResult, npar+1, value);
1139 }
catch (SQLException &oraex) {
1140 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVUInt");
1153 std::vector<Number> res;
1155 getVector(
fResult, npar+1, res);
1156 for (std::vector<Number>::const_iterator it = res.begin();
1159 value.push_back((
Long_t)*it);
1162 }
catch (SQLException &oraex) {
1163 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVLong");
1175 std::vector<Number> res;
1177 getVector(
fResult, npar+1, res);
1178 for (std::vector<Number>::const_iterator it = res.begin();
1181 value.push_back((
Long_t)*it);
1184 }
catch (SQLException &oraex) {
1185 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVLong64");
1197 std::vector<Number> res;
1199 getVector(
fResult, npar+1, res);
1200 for (std::vector<Number>::const_iterator it = res.begin();
1203 value.push_back((
Long_t)(
long double)*it);
1206 }
catch (SQLException &oraex) {
1207 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(),
"GetVULong64");
1220 getVector(
fResult, npar+1, value);
1222 }
catch (SQLException &oraex) {
1223 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.
Bool_t SetVInt(Int_t npar, const std::vector< Int_t > value, const char *schemaName, const char *typeName) final
Set vector of integer values for parameter npar.
oracle::occi::Statement * fStmt
UInt_t GetUInt(Int_t npar) final
return field value as unsigned integer
Double_t GetDouble(Int_t npar) final
return field value as double
void SetBufferSize(Int_t size)
Set buffer size, which is used to keep string values of currently fetched column.
Long64_t GetLong64(Int_t npar) final
return field value as 64-bit integer
const char * GetString(Int_t npar) final
return field value as string
Bool_t SetDouble(Int_t npar, Double_t value) final
Set double value for parameter npar.
ULong64_t GetULong64(Int_t npar) final
return field value as unsigned 64-bit integer
Bool_t SetLong64(Int_t npar, Long64_t value) final
Set 64-bit integer value for parameter npar.
Bool_t SetVLong64(Int_t npar, const std::vector< Long64_t > value, const char *schemaName, const char *typeName) final
Set vector of 64-bit integer values for parameter npar.
Bool_t SetUInt(Int_t npar, UInt_t value) final
Set unsigned integer value for parameter npar.
oracle::occi::Environment * fEnv
Bool_t GetVDouble(Int_t npar, std::vector< Double_t > &value) final
return field value as vector of doubles
Bool_t GetVULong64(Int_t npar, std::vector< ULong64_t > &value) final
return field value as vector of unsigned 64-bit integers
Bool_t NextResultRow() final
Move cursor to next row in result set.
Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
set parameter value as binary data
virtual ~TOracleStatement()
Destructor of TOracleStatement clas.
Int_t GetNumFields() final
Returns number of fields in result set.
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) final
Set date & time value for parameter npar.
const char * GetFieldName(Int_t nfield) final
Return field name in result set.
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
Set date value for parameter npar.
Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec) final
return field value as time
Bool_t GetVLong(Int_t npar, std::vector< Long_t > &value) final
return field value as vector of long integers
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
Set string value for parameter npar.
Bool_t SetVUInt(Int_t npar, const std::vector< UInt_t > value, const char *schemaName, const char *typeName) final
Set vector of unsigned integer values for parameter npar.
Bool_t SetMaxFieldSize(Int_t nfield, Long_t maxsize) final
Defines maximum size for field which must be used for read or write operation Some Oracle types as LO...
void CloseBuffer()
Destroy buffers, used in data fetching.
Bool_t SetVULong64(Int_t npar, const std::vector< ULong64_t > value, const char *schemaName, const char *typeName) final
Set vector of unsigned 64-bit integer values for parameter npar.
Bool_t GetVUInt(Int_t npar, std::vector< UInt_t > &value) final
return field value as vector of unsigned integers
Bool_t SetULong64(Int_t npar, ULong64_t value) final
Set unsigned 64-bit integer value for parameter npar.
Bool_t SetLong(Int_t npar, Long_t value) final
Set long integer value for parameter npar.
Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final
Set time value for parameter npar.
Bool_t NextIteration() final
Add next iteration for statement with parameters.
Int_t GetInt(Int_t npar) final
return field value as integer
Bool_t IsNull(Int_t) final
Checks if fieled value in result set is NULL.
Bool_t IsParSettMode() const
Bool_t GetVInt(Int_t npar, std::vector< Int_t > &value) final
return field value as vector of integers
Bool_t Process() final
Process SQL statement.
Long_t GetLong(Int_t npar) final
return field value as long integer
TOracleStatement(oracle::occi::Environment *env, oracle::occi::Connection *conn, oracle::occi::Statement *stmt, Int_t niter, Bool_t errout=kTRUE)
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) final
return field value as date & time
Bool_t SetNull(Int_t npar) final
Set NULL as value of parameter npar.
Int_t GetNumParameters() final
Return number of parameters in statement Not yet implemented for Oracle.
Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) final
Set date & time value for parameter npar.
Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size) final
Return field value as binary array Supports LONG, BLOB, CLOB, BFILE, CFILE types of columns Reads com...
void Close(Option_t *="") final
Close Oracle statement Removes and destroys all buffers and metainfo.
oracle::occi::Connection * fConn
Bool_t SetVLong(Int_t npar, const std::vector< Long_t > value, const char *schemaName, const char *typeName) final
Set vector of long integer values for parameter npar.
Bool_t SetVDouble(Int_t npar, const std::vector< Double_t > value, const char *schemaName, const char *typeName) final
Set vector of double values for parameter npar.
Bool_t IsResultSet() const
Bool_t GetDatime(Int_t npar, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec) final
return field value as date & time
Bool_t StoreResult() final
Store result of statement processing.
Bool_t GetVLong64(Int_t npar, std::vector< Long64_t > &value) final
return field value as vector of 64-bit integers
Bool_t SetInt(Int_t npar, Int_t value) final
Set integer value for parameter npar.
Int_t GetNumAffectedRows() final
Return number of affected rows after statement Process() was called Make sense for queries like SELEC...
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
return field value as date
oracle::occi::ResultSet * fResult
std::vector< oracle::occi::MetaData > * fFieldInfo
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=nullptr)
set new values for error fields if method specified, displays error message
void ClearError()
reset error fields
const char * Data() const