30 #define kSqlTime 123781 31 #define kSqlDate 123782 32 #define kSqlTimestamp 123783 33 #define kSqlBinary 123784 58 SQLSMALLINT paramsCount = 0;
59 SQLRETURN retcode = SQLNumParams(
fHstmt, ¶msCount);
68 SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
71 retcode = SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) (
long) setsize, 0);
74 SQLUINTEGER getsize = 0;
76 retcode = SQLGetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, &getsize, 0, 0);
82 if (getsize<=1) bufferlen=1;
else 83 if (getsize!=setsize) {
84 SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) 1, 0);
116 SQLFreeHandle(SQL_HANDLE_STMT,
fHstmt);
128 SQLRETURN retcode = SQL_SUCCESS;
137 SQLSetStmtAttr(
fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) (
long) setsize, 0);
139 retcode = SQLExecute(
fHstmt);
151 retcode = SQLExecute(
fHstmt);
165 SQLRETURN retcode = SQL_SUCCESS;
167 retcode = SQLRowCount(
fHstmt, &rowCount);
184 SetError(-1,
"Call Process() method before",
"StoreResult");
190 SQLSMALLINT columnCount = 0;
192 SQLRETURN retcode = SQLNumResultCols(
fHstmt, &columnCount);
195 if (columnCount==0)
return kFALSE;
201 SQLSetStmtAttr(
fHstmt, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0);
202 SQLSetStmtAttr(
fHstmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) arrsize, 0);
207 SQLCHAR columnName[1024];
208 SQLSMALLINT nameLength;
209 SQLSMALLINT dataType;
211 SQLSMALLINT decimalDigits;
212 SQLSMALLINT nullable;
214 retcode = SQLDescribeCol(
fHstmt,
n+1, columnName, 1024,
215 &nameLength, &dataType,
216 &columnSize, &decimalDigits, &nullable);
222 strlcpy(
fBuffer[
n].fBnamebuffer, (
const char*) columnName, nameLength+1);
270 SQLRETURN retcode = SQLFetchScroll(
fHstmt, SQL_FETCH_NEXT, 0);
278 SQLULEN rownumber = 0;
279 SQLRETURN retcode2 = SQLGetStmtAttr(
fHstmt, SQL_ATTR_ROW_NUMBER, &rownumber, 0, 0);
284 fLastResultRow = rownumber;
289 SetError(-1,
"Missmatch between buffer length and fetched rows number",
"NextResultRow");
307 if ((retcode== SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
return kFALSE;
316 ret = SQLGetDiagRec(SQL_HANDLE_STMT,
fHstmt, ++i, state, &native, text,
317 sizeof(text), &len );
318 if (ret == SQL_SUCCESS)
SetError(native, (
const char*) text, method);
321 while( ret == SQL_SUCCESS );
335 SQLRETURN retcode = SQLExecute(
fHstmt);
411 SetError(-1,
"Internal error. Column number invalid",
"BindColumn");
415 if (
fBuffer[ncol].fBsqltype!=0) {
416 SetError(-1,
"Internal error. Bind for column already done",
"BindColumn");
420 SQLSMALLINT sqlctype = 0;
423 case SQL_VARCHAR: sqlctype = SQL_C_CHAR;
break;
425 case SQL_LONGVARBINARY:
426 case SQL_VARBINARY: sqlctype = SQL_C_BINARY;
break;
427 case SQL_LONGVARCHAR:
Info(
"BindColumn",
"BIG VARCHAR not supported yet");
return kFALSE;
break;
429 case SQL_DECIMAL: sqlctype = SQL_C_DOUBLE;
break;
430 case SQL_NUMERIC: sqlctype = SQL_C_DOUBLE;
break;
431 case SQL_SMALLINT: sqlctype = SQL_C_SLONG;
break;
432 case SQL_INTEGER: sqlctype = SQL_C_SLONG;
break;
433 case SQL_FLOAT: sqlctype = SQL_C_FLOAT;
break;
435 case SQL_DOUBLE: sqlctype = SQL_C_DOUBLE;
break;
436 case SQL_TINYINT: sqlctype = SQL_C_STINYINT;
break;
437 case SQL_BIGINT: sqlctype = SQL_C_SBIGINT;
break;
438 case SQL_TYPE_DATE: sqlctype = SQL_C_TYPE_DATE;
break;
439 case SQL_TYPE_TIME: sqlctype = SQL_C_TYPE_TIME;
break;
440 case SQL_TYPE_TIMESTAMP: sqlctype = SQL_C_TYPE_TIMESTAMP;
break;
442 SetError(-1,
Form(
"SQL type %d not supported",sqltype),
"BindColumn");
450 case SQL_C_ULONG: elemsize =
sizeof(SQLUINTEGER);
break;
451 case SQL_C_SLONG: elemsize =
sizeof(SQLINTEGER);
break;
452 case SQL_C_UBIGINT: elemsize =
sizeof(
ULong64_t);
break;
453 case SQL_C_SBIGINT: elemsize =
sizeof(
Long64_t);
break;
454 case SQL_C_USHORT: elemsize =
sizeof(SQLUSMALLINT);
break;
455 case SQL_C_SSHORT: elemsize =
sizeof(SQLSMALLINT);
break;
456 case SQL_C_UTINYINT: elemsize =
sizeof(SQLCHAR);
break;
457 case SQL_C_STINYINT: elemsize =
sizeof(SQLSCHAR);
break;
458 case SQL_C_FLOAT: elemsize =
sizeof(SQLREAL);
break;
459 case SQL_C_DOUBLE: elemsize =
sizeof(SQLDOUBLE);
break;
460 case SQL_C_CHAR: elemsize = size;
break;
461 case SQL_C_BINARY: elemsize = size;
break;
462 case SQL_C_TYPE_DATE: elemsize =
sizeof(DATE_STRUCT);
break;
463 case SQL_C_TYPE_TIME: elemsize =
sizeof(TIME_STRUCT);
break;
464 case SQL_C_TYPE_TIMESTAMP: elemsize =
sizeof(TIMESTAMP_STRUCT);
break;
467 SetError(-1,
Form(
"SQL C Type %d is not supported",sqlctype),
"BindColumn");
496 if (
fBuffer[npar].fBroottype!=0) {
497 SetError(-1,
Form(
"ParameterType for par %d already specified", npar),
"BindParam");
501 SQLSMALLINT sqltype = 0, sqlctype = 0;
505 case kUInt_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_ULONG; elemsize =
sizeof(SQLUINTEGER);
break;
506 case kInt_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_SLONG; elemsize =
sizeof(SQLINTEGER);
break;
507 case kULong_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_ULONG; elemsize =
sizeof(SQLUINTEGER);
break;
508 case kLong_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_SLONG; elemsize =
sizeof(SQLINTEGER);
break;
512 case kULong64_t: sqltype = SQL_BIGINT; sqlctype = SQL_C_UBIGINT; elemsize =
sizeof(
ULong64_t);
break;
513 case kLong64_t: sqltype = SQL_BIGINT; sqlctype = SQL_C_SBIGINT; elemsize =
sizeof(
Long64_t);
break;
515 case kUShort_t: sqltype = SQL_SMALLINT;sqlctype = SQL_C_USHORT; elemsize =
sizeof(SQLUSMALLINT);
break;
516 case kShort_t: sqltype = SQL_SMALLINT;sqlctype = SQL_C_SSHORT; elemsize =
sizeof(SQLSMALLINT);
break;
517 case kUChar_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_UTINYINT; elemsize =
sizeof(SQLCHAR);
break;
518 case kChar_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_STINYINT; elemsize =
sizeof(SQLSCHAR);
break;
519 case kBool_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_UTINYINT; elemsize =
sizeof(SQLCHAR);
break;
520 case kFloat_t: sqltype = SQL_FLOAT; sqlctype = SQL_C_FLOAT; elemsize =
sizeof(SQLREAL);
break;
521 case kFloat16_t: sqltype = SQL_FLOAT; sqlctype = SQL_C_FLOAT; elemsize =
sizeof(SQLREAL);
break;
522 case kDouble_t: sqltype = SQL_DOUBLE; sqlctype = SQL_C_DOUBLE; elemsize =
sizeof(SQLDOUBLE);
break;
523 case kDouble32_t: sqltype = SQL_DOUBLE; sqlctype = SQL_C_DOUBLE; elemsize =
sizeof(SQLDOUBLE);
break;
524 case kCharStar: sqltype = SQL_CHAR; sqlctype = SQL_C_CHAR; elemsize = size;
break;
525 case kSqlBinary: sqltype = SQL_BINARY; sqlctype = SQL_C_BINARY; elemsize = size;
break;
526 case kSqlDate: sqltype = SQL_TYPE_DATE; sqlctype = SQL_C_TYPE_DATE; elemsize =
sizeof(DATE_STRUCT);
break;
527 case kSqlTime: sqltype = SQL_TYPE_TIME; sqlctype = SQL_C_TYPE_TIME; elemsize =
sizeof(TIME_STRUCT);
break;
528 case kSqlTimestamp: sqltype = SQL_TYPE_TIMESTAMP; sqlctype = SQL_C_TYPE_TIMESTAMP; elemsize =
sizeof(TIMESTAMP_STRUCT);
break;
530 SetError(-1,
Form(
"Root type %d is not supported", roottype),
"BindParam");
538 SQLBindParameter(
fHstmt, npar+1, SQL_PARAM_INPUT,
539 sqlctype, sqltype, 0, 0,
540 buffer, elemsize, lenarray);
566 SetError(-1,
"Invalid parameter number",
"GetParAddr");
570 if (
fBuffer[npar].fBbuffer==0) {
572 if (!
BindParam(npar, roottype, length))
return 0;
574 if (
fBuffer[npar].fBbuffer==0)
return 0;
578 if (
fBuffer[npar].fBroottype!=roottype)
return 0;
589 if (addr==0)
return 0;
591 switch (
fBuffer[npar].fBsqlctype) {
592 case SQL_C_ULONG:
return *((SQLUINTEGER*) addr);
break;
593 case SQL_C_SLONG:
return *((SQLINTEGER*) addr);
break;
594 case SQL_C_UBIGINT:
return *((
ULong64_t*) addr);
break;
595 case SQL_C_SBIGINT:
return *((
Long64_t*) addr);
break;
596 case SQL_C_USHORT:
return *((SQLUSMALLINT*) addr);
break;
597 case SQL_C_SSHORT:
return *((SQLSMALLINT*) addr);
break;
598 case SQL_C_UTINYINT:
return *((SQLCHAR*) addr);
break;
599 case SQL_C_STINYINT:
return *((SQLSCHAR*) addr);
break;
600 case SQL_C_FLOAT:
return *((SQLREAL*) addr);
break;
601 case SQL_C_DOUBLE:
return *((SQLDOUBLE*) addr);
break;
602 case SQL_C_TYPE_DATE: {
603 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
604 TDatime rtm(dt->year, dt->month, dt->day, 0, 0, 0);
608 case SQL_C_TYPE_TIME: {
609 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
610 TDatime rtm(2000, 1, 1, tm->hour, tm->minute, tm->second);
614 case SQL_C_TYPE_TIMESTAMP: {
615 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
616 TDatime rtm(tm->year, tm->month, tm->day,
617 tm->hour, tm->minute, tm->second);
631 if (addr==0)
return 0;
632 if (
fBuffer[npar].fBstrbuffer==0)
637 switch(
fBuffer[npar].fBsqlctype) {
638 #if (SIZEOF_LONG == 8) 639 case SQL_C_SLONG:
snprintf(buf, 100,
"%d", *((SQLINTEGER*) addr));
break;
640 case SQL_C_ULONG:
snprintf(buf, 100,
"%u", *((SQLUINTEGER*) addr));
break;
642 case SQL_C_SLONG:
snprintf(buf, 100,
"%ld", (
long)*((SQLINTEGER*) addr));
break;
643 case SQL_C_ULONG:
snprintf(buf, 100,
"%lu", (
unsigned long)*((SQLUINTEGER*) addr));
break;
647 case SQL_C_SSHORT:
snprintf(buf, 100,
"%hd", *((SQLSMALLINT*) addr));
break;
648 case SQL_C_USHORT:
snprintf(buf, 100,
"%hu", *((SQLUSMALLINT*) addr));
break;
649 case SQL_C_STINYINT:
snprintf(buf, 100,
"%d", *((SQLSCHAR*) addr));
break;
650 case SQL_C_UTINYINT:
snprintf(buf, 100,
"%u", *((SQLCHAR*) addr));
break;
653 case SQL_C_TYPE_DATE: {
654 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
655 snprintf(buf,100,
"%4.4d-%2.2d-%2.2d",
656 dt->year, dt->month, dt->day);
659 case SQL_C_TYPE_TIME: {
660 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
661 snprintf(buf,100,
"%2.2d:%2.2d:%2.2d",
662 tm->hour, tm->minute, tm->second);
665 case SQL_C_TYPE_TIMESTAMP: {
666 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
667 snprintf(buf,100,
"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
668 tm->year, tm->month, tm->day,
669 tm->hour, tm->minute, tm->second);
684 if (addr==0)
return kTRUE;
695 if (addr==0)
return 0;
697 if (
fBuffer[npar].fBsqlctype==SQL_C_SLONG)
698 return (
Int_t) *((SQLINTEGER*) addr);
709 if (addr==0)
return 0;
711 if (
fBuffer[npar].fBsqlctype==SQL_C_ULONG)
712 return (
UInt_t) *((SQLUINTEGER*) addr);
723 if (addr==0)
return 0;
725 if (
fBuffer[npar].fBsqlctype==SQL_C_SLONG)
726 return (
Long_t) *((SQLINTEGER*) addr);
737 if (addr==0)
return 0;
739 if (
fBuffer[npar].fBsqlctype==SQL_C_SBIGINT)
751 if (addr==0)
return 0;
753 if (
fBuffer[npar].fBsqlctype==SQL_C_UBIGINT)
765 if (addr==0)
return 0;
767 if (
fBuffer[npar].fBsqlctype==SQL_C_DOUBLE)
768 return *((SQLDOUBLE*) addr);
779 if (addr==0)
return 0;
781 if (
fBuffer[npar].fBsqlctype==SQL_C_CHAR) {
786 if ((len == SQL_NULL_DATA) || (len==0))
return 0;
788 char* res = (
char*) addr;
789 if (len <
fBuffer[npar].fBelementsize) {
794 if (len >
fBuffer[npar].fBelementsize) {
795 SetError(-1,
Form(
"Problems with string size %d", len),
"GetString");
799 if (
fBuffer[npar].fBstrbuffer==0)
802 strlcpy(
fBuffer[npar].fBstrbuffer, res, len+1);
821 if (addr==0)
return kFALSE;
823 if ((
fBuffer[npar].fBsqlctype==SQL_C_BINARY) ||
824 (
fBuffer[npar].fBsqlctype==SQL_C_CHAR)) {
829 if ((len == SQL_NULL_DATA) || (len==0))
return kTRUE;
833 if (
fBuffer[npar].fBstrbuffer==0)
836 memcpy(
fBuffer[npar].fBstrbuffer, addr, size);
853 if (addr==0)
return kFALSE;
855 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_DATE)
return kFALSE;
857 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
871 if (addr==0)
return kFALSE;
873 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIME)
return kFALSE;
875 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
889 if (addr==0)
return kFALSE;
891 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIMESTAMP)
return kFALSE;
893 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
910 if (addr==0)
return kFALSE;
912 if (
fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIMESTAMP)
return kFALSE;
914 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
940 *((SQLINTEGER*) addr) = 0;
954 if (addr==0)
return kFALSE;
956 *((SQLINTEGER*) addr) = value;
969 if (addr==0)
return kFALSE;
971 *((SQLUINTEGER*) addr) = value;
984 if (addr==0)
return kFALSE;
986 *((SQLINTEGER*) addr) = value;
999 if (addr==0)
return kFALSE;
1014 if (addr==0)
return kFALSE;
1029 if (addr==0)
return kFALSE;
1031 *((SQLDOUBLE*) addr) = value;
1045 if (addr==0)
return kFALSE;
1048 int len = strlen(value);
1050 if (len>=
fBuffer[npar].fBelementsize) {
1052 strlcpy((
char*) addr, value, len+1);
1056 strlcpy((
char*) addr, value, maxsize);
1059 *((
char*) addr) = 0;
1063 *((
char*) addr) = 0;
1076 if (addr==0)
return kFALSE;
1078 if (size>
fBuffer[npar].fBelementsize)
1081 memcpy(addr, mem, size);
1093 if (addr==0)
return kFALSE;
1095 DATE_STRUCT* dt = (DATE_STRUCT*) addr;
1111 if (addr==0)
return kFALSE;
1113 TIME_STRUCT* tm = (TIME_STRUCT*) addr;
1129 if (addr==0)
return kFALSE;
1131 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
1151 if (addr==0)
return kFALSE;
1153 TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr;
1160 tm->fraction = frac;
virtual const char * GetFieldName(Int_t nfield)
return field name
SQLUINTEGER fNumRowsFetched
Int_t fBufferPreferredSize
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 void Info(const char *method, const char *msgfmt,...) const
Issue info message.
virtual const char * GetString(Int_t npar)
get parameter as string
virtual Bool_t NextResultRow()
next result row
void ClearError()
reset error fields
void SetError(Int_t code, const char *msg, const char *method=0)
set new values for error fields if method specified, displays error message
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 parameter value as timestamp
virtual Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day)
return field value as date
virtual Bool_t SetInt(Int_t npar, Int_t value)
set parameter as Int_t
virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
set parameter value as date
virtual UInt_t GetUInt(Int_t npar)
get parameter as unsigned integer
SQLUINTEGER fNumParsProcessed
virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec)
set parameter value as time
static const char * GetFloatFormat()
return current printf format for float/double members, default "%e"
Int_t GetDate() const
Return date in form of 19971224 (i.e. 24/12/1997)
virtual Bool_t SetLong(Int_t npar, Long_t value)
set parameter as Long_t
virtual Int_t GetInt(Int_t npar)
get parameter as integer
virtual ~TODBCStatement()
destructor
Bool_t BindParam(Int_t n, Int_t type, Int_t size=1024)
Bind query parameter with buffer. Creates buffer of appropriate type.
virtual Int_t GetNumAffectedRows()
get number of affected rows
Bool_t ExtractErrors(SQLRETURN retcode, const char *method)
Extract errors, produced by last ODBC function call.
void * GetParAddr(Int_t npar, Int_t roottype=0, Int_t length=0)
Get parameter address.
virtual Double_t GetDouble(Int_t npar)
get parameter as Double_t
TODBCStatement(SQLHSTMT stmt, Int_t rowarrsize, Bool_t errout=kTRUE)
constructor
const char * ConvertToString(Int_t npar)
convert to string
virtual Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256)
set parameter as string
Bool_t BindColumn(Int_t ncol, SQLSMALLINT sqltype, SQLUINTEGER size)
Bind result column to buffer. Allocate buffer of appropriate type.
Bool_t IsParSettMode() const
long double ConvertToNumeric(Int_t npar)
convert to numeric type
virtual Bool_t Process()
process statement
UInt_t Get() const
Return raw date/time as encoded by TDatime.
ODBCBufferRec_t * fBuffer
char * Form(const char *fmt,...)
virtual Bool_t IsError() const
virtual Int_t GetNumParameters()
return number of parameters
virtual Bool_t SetLong64(Int_t npar, Long64_t value)
set parameter as Long64_t
Int_t GetTime() const
Return time in form of 123623 (i.e. 12:36:23)
virtual ULong64_t GetULong64(Int_t npar)
get parameter as ULong64_t
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 &)
return field value as time stamp
virtual Bool_t IsNull(Int_t)
Verifies if field value is NULL.
Bool_t IsResultSet() const
unsigned long long ULong64_t
virtual Bool_t SetNull(Int_t npar)
Set NULL as parameter value If NULL should be set for statement parameter during first iteration...
virtual Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size)
return parameter as binary data
virtual Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec)
return field value as time
virtual Bool_t SetDouble(Int_t npar, Double_t value)
set parameter as Double_t
void FreeBuffers()
Free allocated buffers.
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 SetULong64(Int_t npar, ULong64_t value)
set parameter as ULong64_t
virtual Long64_t GetLong64(Int_t npar)
get parameter as Long64_t
virtual void Close(Option_t *="")
Close statement.
virtual Bool_t SetUInt(Int_t npar, UInt_t value)
set parameter as UInt_t
SQLUSMALLINT * fStatusBuffer
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 parameter value as date & time
void SetNumBuffers(Int_t isize, Int_t ilen)
set number of buffers
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
virtual Bool_t NextIteration()
run next iteration
virtual Int_t GetNumFields()
return number of fields
virtual Bool_t StoreResult()
Store result of statement processing.
virtual Long_t GetLong(Int_t npar)
get parameter as Long_t