32#define kSqlTime 123781
33#define kSqlDate 123782
34#define kSqlTimestamp 123783
35#define kSqlBinary 123784
60 SQLSMALLINT paramsCount = 0;
61 SQLRETURN retcode = SQLNumParams(
fHstmt, ¶msCount);
70 SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
73 retcode = SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) (
long) setsize, 0);
76 SQLUINTEGER getsize = 0;
78 retcode = SQLGetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, &getsize, 0, 0);
84 if (getsize<=1) bufferlen=1;
else
85 if (getsize!=setsize) {
86 SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) 1, 0);
118 SQLFreeHandle(SQL_HANDLE_STMT,
fHstmt);
130 SQLRETURN retcode = SQL_SUCCESS;
139 SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) (
long) setsize, 0);
141 retcode = SQLExecute(
fHstmt);
153 retcode = SQLExecute(
fHstmt);
167 SQLRETURN retcode = SQL_SUCCESS;
169 retcode = SQLRowCount(
fHstmt, &rowCount);
186 SetError(-1,
"Call Process() method before",
"StoreResult");
192 SQLSMALLINT columnCount = 0;
194 SQLRETURN retcode = SQLNumResultCols(
fHstmt, &columnCount);
197 if (columnCount==0)
return kFALSE;
203 SQLSetStmtAttr(
fHstmt, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0);
204 SQLSetStmtAttr(
fHstmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) arrsize, 0);
209 SQLCHAR columnName[1024];
210 SQLSMALLINT nameLength;
211 SQLSMALLINT dataType;
213 SQLSMALLINT decimalDigits;
214 SQLSMALLINT nullable;
216 retcode = SQLDescribeCol(
fHstmt,
n+1, columnName, 1024,
217 &nameLength, &dataType,
218 &columnSize, &decimalDigits, &nullable);
224 strlcpy(
fBuffer[
n].fBnamebuffer, (
const char*) columnName, nameLength+1);
272 SQLRETURN retcode = SQLFetchScroll(
fHstmt, SQL_FETCH_NEXT, 0);
280 SQLULEN rownumber = 0;
281 SQLRETURN retcode2 = SQLGetStmtAttr(
fHstmt, SQL_ATTR_ROW_NUMBER, &rownumber, 0, 0);
291 SetError(-1,
"Missmatch between buffer length and fetched rows number",
"NextResultRow");
309 if ((retcode== SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
return kFALSE;
318 ret = SQLGetDiagRec(SQL_HANDLE_STMT,
fHstmt, ++i, state, &native,
text,
319 sizeof(
text), &len );
320 if (ret == SQL_SUCCESS)
SetError(native, (
const char*)
text, method);
323 while( ret == SQL_SUCCESS );
337 SQLRETURN retcode = SQLExecute(
fHstmt);
413 SetError(-1,
"Internal error. Column number invalid",
"BindColumn");
417 if (
fBuffer[ncol].fBsqltype!=0) {
418 SetError(-1,
"Internal error. Bind for column already done",
"BindColumn");
422 SQLSMALLINT sqlctype = 0;
425 case SQL_VARCHAR: sqlctype = SQL_C_CHAR;
break;
427 case SQL_LONGVARBINARY:
428 case SQL_VARBINARY: sqlctype = SQL_C_BINARY;
break;
429 case SQL_LONGVARCHAR:
Info(
"BindColumn",
"BIG VARCHAR not supported yet");
return kFALSE;
break;
431 case SQL_DECIMAL: sqlctype = SQL_C_DOUBLE;
break;
432 case SQL_NUMERIC: sqlctype = SQL_C_DOUBLE;
break;
433 case SQL_SMALLINT: sqlctype = SQL_C_SLONG;
break;
434 case SQL_INTEGER: sqlctype = SQL_C_SLONG;
break;
435 case SQL_FLOAT: sqlctype = SQL_C_FLOAT;
break;
437 case SQL_DOUBLE: sqlctype = SQL_C_DOUBLE;
break;
438 case SQL_TINYINT: sqlctype = SQL_C_STINYINT;
break;
439 case SQL_BIGINT: sqlctype = SQL_C_SBIGINT;
break;
440 case SQL_TYPE_DATE: sqlctype = SQL_C_TYPE_DATE;
break;
441 case SQL_TYPE_TIME: sqlctype = SQL_C_TYPE_TIME;
break;
442 case SQL_TYPE_TIMESTAMP: sqlctype = SQL_C_TYPE_TIMESTAMP;
break;
444 SetError(-1,
Form(
"SQL type %d not supported",sqltype),
"BindColumn");
452 case SQL_C_ULONG: elemsize =
sizeof(SQLUINTEGER);
break;
453 case SQL_C_SLONG: elemsize =
sizeof(SQLINTEGER);
break;
454 case SQL_C_UBIGINT: elemsize =
sizeof(
ULong64_t);
break;
455 case SQL_C_SBIGINT: elemsize =
sizeof(
Long64_t);
break;
456 case SQL_C_USHORT: elemsize =
sizeof(SQLUSMALLINT);
break;
457 case SQL_C_SSHORT: elemsize =
sizeof(SQLSMALLINT);
break;
458 case SQL_C_UTINYINT: elemsize =
sizeof(SQLCHAR);
break;
459 case SQL_C_STINYINT: elemsize =
sizeof(SQLSCHAR);
break;
460 case SQL_C_FLOAT: elemsize =
sizeof(SQLREAL);
break;
461 case SQL_C_DOUBLE: elemsize =
sizeof(SQLDOUBLE);
break;
462 case SQL_C_CHAR: elemsize =
size;
break;
463 case SQL_C_BINARY: elemsize =
size;
break;
464 case SQL_C_TYPE_DATE: elemsize =
sizeof(DATE_STRUCT);
break;
465 case SQL_C_TYPE_TIME: elemsize =
sizeof(TIME_STRUCT);
break;
466 case SQL_C_TYPE_TIMESTAMP: elemsize =
sizeof(TIMESTAMP_STRUCT);
break;
469 SetError(-1,
Form(
"SQL C Type %d is not supported",sqlctype),
"BindColumn");
498 if (
fBuffer[npar].fBroottype!=0) {
499 SetError(-1,
Form(
"ParameterType for par %d already specified", npar),
"BindParam");
503 SQLSMALLINT sqltype = 0, sqlctype = 0;
507 case kUInt_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_ULONG; elemsize =
sizeof(SQLUINTEGER);
break;
508 case kInt_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_SLONG; elemsize =
sizeof(SQLINTEGER);
break;
509 case kULong_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_ULONG; elemsize =
sizeof(SQLUINTEGER);
break;
510 case kLong_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_SLONG; elemsize =
sizeof(SQLINTEGER);
break;
514 case kULong64_t: sqltype = SQL_BIGINT; sqlctype = SQL_C_UBIGINT; elemsize =
sizeof(
ULong64_t);
break;
515 case kLong64_t: sqltype = SQL_BIGINT; sqlctype = SQL_C_SBIGINT; elemsize =
sizeof(
Long64_t);
break;
517 case kUShort_t: sqltype = SQL_SMALLINT;sqlctype = SQL_C_USHORT; elemsize =
sizeof(SQLUSMALLINT);
break;
518 case kShort_t: sqltype = SQL_SMALLINT;sqlctype = SQL_C_SSHORT; elemsize =
sizeof(SQLSMALLINT);
break;
519 case kUChar_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_UTINYINT; elemsize =
sizeof(SQLCHAR);
break;
520 case kChar_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_STINYINT; elemsize =
sizeof(SQLSCHAR);
break;
521 case kBool_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_UTINYINT; elemsize =
sizeof(SQLCHAR);
break;
522 case kFloat_t: sqltype = SQL_FLOAT; sqlctype = SQL_C_FLOAT; elemsize =
sizeof(SQLREAL);
break;
523 case kFloat16_t: sqltype = SQL_FLOAT; sqlctype = SQL_C_FLOAT; elemsize =
sizeof(SQLREAL);
break;
524 case kDouble_t: sqltype = SQL_DOUBLE; sqlctype = SQL_C_DOUBLE; elemsize =
sizeof(SQLDOUBLE);
break;
525 case kDouble32_t: sqltype = SQL_DOUBLE; sqlctype = SQL_C_DOUBLE; elemsize =
sizeof(SQLDOUBLE);
break;
526 case kCharStar: sqltype = SQL_CHAR; sqlctype = SQL_C_CHAR; elemsize =
size;
break;
527 case kSqlBinary: sqltype = SQL_BINARY; sqlctype = SQL_C_BINARY; elemsize =
size;
break;
528 case kSqlDate: sqltype = SQL_TYPE_DATE; sqlctype = SQL_C_TYPE_DATE; elemsize =
sizeof(DATE_STRUCT);
break;
529 case kSqlTime: sqltype = SQL_TYPE_TIME; sqlctype = SQL_C_TYPE_TIME; elemsize =
sizeof(TIME_STRUCT);
break;
530 case kSqlTimestamp: sqltype = SQL_TYPE_TIMESTAMP; sqlctype = SQL_C_TYPE_TIMESTAMP; elemsize =
sizeof(TIMESTAMP_STRUCT);
break;
532 SetError(-1,
Form(
"Root type %d is not supported", roottype),
"BindParam");
540 SQLBindParameter(
fHstmt, npar+1, SQL_PARAM_INPUT,
541 sqlctype, sqltype, 0, 0,
542 buffer, elemsize, lenarray);
568 SetError(-1,
"Invalid parameter number",
"GetParAddr");
572 if (
fBuffer[npar].fBbuffer==0) {
574 if (!
BindParam(npar, roottype, length))
return 0;
576 if (
fBuffer[npar].fBbuffer==0)
return 0;
580 if (
fBuffer[npar].fBroottype!=roottype)
return 0;
591 if (addr==0)
return 0;
593 switch (
fBuffer[npar].fBsqlctype) {
594 case SQL_C_ULONG:
return *((SQLUINTEGER*) addr);
break;
595 case SQL_C_SLONG:
return *((SQLINTEGER*) addr);
break;
596 case SQL_C_UBIGINT:
return *((
ULong64_t*) addr);
break;
597 case SQL_C_SBIGINT:
return *((
Long64_t*) addr);
break;
598 case SQL_C_USHORT:
return *((SQLUSMALLINT*) addr);
break;
599 case SQL_C_SSHORT:
return *((SQLSMALLINT*) addr);
break;
600 case SQL_C_UTINYINT:
return *((SQLCHAR*) addr);
break;
601 case SQL_C_STINYINT:
return *((SQLSCHAR*) addr);
break;
602 case SQL_C_FLOAT:
return *((SQLREAL*) addr);
break;
603 case SQL_C_DOUBLE:
return *((SQLDOUBLE*) addr);
break;
604 case SQL_C_TYPE_DATE: {
605 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
606 TDatime rtm(dt->year, dt->month, dt->day, 0, 0, 0);
610 case SQL_C_TYPE_TIME: {
611 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
612 TDatime rtm(2000, 1, 1, tm->hour, tm->minute, tm->second);
616 case SQL_C_TYPE_TIMESTAMP: {
617 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
618 TDatime rtm(tm->year, tm->month, tm->day,
619 tm->hour, tm->minute, tm->second);
633 if (addr==0)
return 0;
634 if (
fBuffer[npar].fBstrbuffer==0)
639 switch(
fBuffer[npar].fBsqlctype) {
640#if (SIZEOF_LONG == 8)
641 case SQL_C_SLONG:
snprintf(buf, 100,
"%d", *((SQLINTEGER*) addr));
break;
642 case SQL_C_ULONG:
snprintf(buf, 100,
"%u", *((SQLUINTEGER*) addr));
break;
644 case SQL_C_SLONG:
snprintf(buf, 100,
"%ld", (
long)*((SQLINTEGER*) addr));
break;
645 case SQL_C_ULONG:
snprintf(buf, 100,
"%lu", (
unsigned long)*((SQLUINTEGER*) addr));
break;
649 case SQL_C_SSHORT:
snprintf(buf, 100,
"%hd", *((SQLSMALLINT*) addr));
break;
650 case SQL_C_USHORT:
snprintf(buf, 100,
"%hu", *((SQLUSMALLINT*) addr));
break;
651 case SQL_C_STINYINT:
snprintf(buf, 100,
"%d", *((SQLSCHAR*) addr));
break;
652 case SQL_C_UTINYINT:
snprintf(buf, 100,
"%u", *((SQLCHAR*) addr));
break;
655 case SQL_C_TYPE_DATE: {
656 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
657 snprintf(buf,100,
"%4.4d-%2.2d-%2.2d",
658 dt->year, dt->month, dt->day);
661 case SQL_C_TYPE_TIME: {
662 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
663 snprintf(buf,100,
"%2.2d:%2.2d:%2.2d",
664 tm->hour, tm->minute, tm->second);
667 case SQL_C_TYPE_TIMESTAMP: {
668 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
669 snprintf(buf,100,
"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
670 tm->year, tm->month, tm->day,
671 tm->hour, tm->minute, tm->second);
686 if (addr==0)
return kTRUE;
697 if (addr==0)
return 0;
699 if (
fBuffer[npar].fBsqlctype==SQL_C_SLONG)
700 return (
Int_t) *((SQLINTEGER*) addr);
711 if (addr==0)
return 0;
713 if (
fBuffer[npar].fBsqlctype==SQL_C_ULONG)
714 return (
UInt_t) *((SQLUINTEGER*) addr);
725 if (addr==0)
return 0;
727 if (
fBuffer[npar].fBsqlctype==SQL_C_SLONG)
728 return (
Long_t) *((SQLINTEGER*) addr);
739 if (addr==0)
return 0;
741 if (
fBuffer[npar].fBsqlctype==SQL_C_SBIGINT)
753 if (addr==0)
return 0;
755 if (
fBuffer[npar].fBsqlctype==SQL_C_UBIGINT)
767 if (addr==0)
return 0;
769 if (
fBuffer[npar].fBsqlctype==SQL_C_DOUBLE)
770 return *((SQLDOUBLE*) addr);
781 if (addr==0)
return 0;
783 if (
fBuffer[npar].fBsqlctype==SQL_C_CHAR) {
788 if ((len == SQL_NULL_DATA) || (len==0))
return 0;
790 char* res = (
char*) addr;
791 if (len <
fBuffer[npar].fBelementsize) {
796 if (len >
fBuffer[npar].fBelementsize) {
797 SetError(-1,
Form(
"Problems with string size %d", len),
"GetString");
801 if (
fBuffer[npar].fBstrbuffer==0)
804 strlcpy(
fBuffer[npar].fBstrbuffer, res, len+1);
823 if (addr==0)
return kFALSE;
825 if ((
fBuffer[npar].fBsqlctype==SQL_C_BINARY) ||
826 (
fBuffer[npar].fBsqlctype==SQL_C_CHAR)) {
831 if ((len == SQL_NULL_DATA) || (len==0))
return kTRUE;
835 if (
fBuffer[npar].fBstrbuffer==0)
855 if (addr==0)
return kFALSE;
857 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_DATE)
return kFALSE;
859 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
873 if (addr==0)
return kFALSE;
875 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIME)
return kFALSE;
877 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
891 if (addr==0)
return kFALSE;
893 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIMESTAMP)
return kFALSE;
895 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
912 if (addr==0)
return kFALSE;
914 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIMESTAMP)
return kFALSE;
916 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
942 *((SQLINTEGER*) addr) = 0;
956 if (addr==0)
return kFALSE;
958 *((SQLINTEGER*) addr) = value;
971 if (addr==0)
return kFALSE;
973 *((SQLUINTEGER*) addr) = value;
986 if (addr==0)
return kFALSE;
988 *((SQLINTEGER*) addr) = value;
1001 if (addr==0)
return kFALSE;
1016 if (addr==0)
return kFALSE;
1031 if (addr==0)
return kFALSE;
1033 *((SQLDOUBLE*) addr) = value;
1047 if (addr==0)
return kFALSE;
1050 int len = strlen(value);
1052 if (len>=
fBuffer[npar].fBelementsize) {
1054 strlcpy((
char*) addr, value, len+1);
1058 strlcpy((
char*) addr, value, maxsize);
1061 *((
char*) addr) = 0;
1065 *((
char*) addr) = 0;
1078 if (addr==0)
return kFALSE;
1083 memcpy(addr, mem,
size);
1095 if (addr==0)
return kFALSE;
1097 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
1113 if (addr==0)
return kFALSE;
1115 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
1131 if (addr==0)
return kFALSE;
1133 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
1153 if (addr==0)
return kFALSE;
1155 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
1162 tm->fraction = frac;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned long long ULong64_t
char * Form(const char *fmt,...)
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Int_t GetDate() const
Return date in form of 19971224 (i.e. 24/12/1997)
UInt_t Get() const
Return raw date/time as encoded by TDatime.
Int_t GetTime() const
Return time in form of 123623 (i.e. 12:36:23)
void SetNumBuffers(Int_t isize, Int_t ilen)
set number of buffers
Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size) final
return parameter as binary data
Bool_t Process() final
process statement
void FreeBuffers()
Free allocated buffers.
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 &) final
return field value as time stamp
Bool_t BindParam(Int_t n, Int_t type, Int_t size=1024)
Bind query parameter with buffer. Creates buffer of appropriate type.
Long64_t GetLong64(Int_t npar) final
get parameter as Long64_t
const char * GetString(Int_t npar) final
get parameter as string
Bool_t IsNull(Int_t) final
Verifies if field value is NULL.
TODBCStatement(SQLHSTMT stmt, Int_t rowarrsize, Bool_t errout=kTRUE)
constructor
Double_t GetDouble(Int_t npar) final
get parameter as Double_t
Bool_t IsParSettMode() const
const char * ConvertToString(Int_t npar)
convert to string
Long_t GetLong(Int_t npar) final
get parameter as Long_t
long double ConvertToNumeric(Int_t npar)
convert to numeric type
virtual ~TODBCStatement()
destructor
ULong64_t GetULong64(Int_t npar) final
get parameter as ULong64_t
Int_t GetInt(Int_t npar) final
get parameter as integer
Int_t GetNumFields() final
return number of fields
void * GetParAddr(Int_t npar, Int_t roottype=0, Int_t length=0)
Get parameter address.
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
Int_t fBufferPreferredSize
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 parameter value as timestamp
Int_t GetNumAffectedRows() final
get number of affected rows
Bool_t NextIteration() final
run next iteration
SQLUSMALLINT * fStatusBuffer
Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec) final
return field value as time
Bool_t SetLong64(Int_t npar, Long64_t value) final
set parameter as Long64_t
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
return field value as date
UInt_t GetUInt(Int_t npar) final
get parameter as unsigned integer
Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
set parameter value as binary data
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 parameter value as date & time
Bool_t SetULong64(Int_t npar, ULong64_t value) final
set parameter as ULong64_t
SQLUINTEGER fNumRowsFetched
Bool_t SetNull(Int_t npar) final
Set NULL as parameter value If NULL should be set for statement parameter during first iteration,...
Bool_t BindColumn(Int_t ncol, SQLSMALLINT sqltype, SQLUINTEGER size)
Bind result column to buffer. Allocate buffer of appropriate type.
Bool_t StoreResult() final
Store result of statement processing.
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
set parameter value as date
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
set parameter as string
SQLUINTEGER fNumParsProcessed
Bool_t SetLong(Int_t npar, Long_t value) final
set parameter as Long_t
Bool_t ExtractErrors(SQLRETURN retcode, const char *method)
Extract errors, produced by last ODBC function call.
Bool_t IsResultSet() const
virtual void Close(Option_t *="") final
Close statement.
Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final
set parameter value as time
Bool_t NextResultRow() final
next result row
Bool_t SetUInt(Int_t npar, UInt_t value) final
set parameter as UInt_t
Bool_t SetDouble(Int_t npar, Double_t value) final
set parameter as Double_t
ODBCBufferRec_t * fBuffer
const char * GetFieldName(Int_t nfield) final
return field name
Int_t GetNumParameters() final
return number of parameters
Bool_t SetInt(Int_t npar, Int_t value) final
set parameter as Int_t
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static const char * GetFloatFormat()
return current printf format for float/double members, default "%e"
virtual Bool_t IsError() const
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