30#if MYSQL_VERSION_ID >= 40100
46 ULong_t paramcount = mysql_stmt_param_count(fStmt);
50 SetBuffersNumber(paramcount);
70 mysql_stmt_close(
fStmt);
79#define CheckStmt(method, res) \
83 SetError(-1,"Statement handle is 0",method); \
89#define CheckErrNo(method, force, res) \
91 unsigned int stmterrno = mysql_stmt_errno(fStmt); \
92 if ((stmterrno!=0) || force) { \
93 const char* stmterrmsg = mysql_stmt_error(fStmt); \
94 if (stmterrno==0) { stmterrno = 11111; stmterrmsg = "MySQL statement error"; } \
95 SetError(stmterrno, stmterrmsg, method); \
102#define CheckGetField(method, res) \
105 if (!IsResultSetMode()) { \
106 SetError(-1,"Cannot get statement parameters",method); \
109 if ((npar<0) || (npar>=fNumBuffers)) { \
110 SetError(-1,Form("Invalid parameter number %d", npar),method); \
132 if (mysql_stmt_execute(
fStmt))
145 my_ulonglong res = mysql_stmt_affected_rows(
fStmt);
147 if (res == (my_ulonglong) -1)
175 SetError(-1,
"Cannot store result for that statement",
"StoreResult");
179 if (mysql_stmt_store_result(
fStmt))
183 MYSQL_RES* meta = mysql_stmt_result_metadata(
fStmt);
185 int count = mysql_num_fields(meta);
189 MYSQL_FIELD *fields = mysql_fetch_fields(meta);
191 for (
int n=0;
n<count;
n++) {
193 if (fields[
n].
name!=0) {
199 mysql_free_result(meta);
258 SetError(-1,
"Cannot call for that statement",
"NextIteration");
272 if (mysql_stmt_execute(
fStmt))
308 if (numpars<=0)
return;
324 if (
fBuffer[npar].fResNull)
return 0;
329 if (addr==0)
return 0;
331 if ((
fBind[npar].buffer_type==MYSQL_TYPE_STRING) ||
332 (
fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING))
333 return (
const char*) addr;
335 if (
fBuffer[npar].fStrBuffer==0)
340 switch(
fBind[npar].buffer_type) {
341 case MYSQL_TYPE_LONG:
342 if (sig)
snprintf(buf,100,
"%d",*((
int*) addr));
343 else snprintf(buf,100,
"%u",*((
unsigned int*) addr));
345 case MYSQL_TYPE_LONGLONG:
349 case MYSQL_TYPE_SHORT:
350 if (sig)
snprintf(buf,100,
"%hd",*((
short*) addr));
else
351 snprintf(buf,100,
"%hu",*((
unsigned short*) addr));
353 case MYSQL_TYPE_TINY:
354 if (sig)
snprintf(buf,100,
"%d",*((
char*) addr));
else
355 snprintf(buf,100,
"%u",*((
unsigned char*) addr));
357 case MYSQL_TYPE_FLOAT:
360 case MYSQL_TYPE_DOUBLE:
363 case MYSQL_TYPE_DATETIME:
364 case MYSQL_TYPE_TIMESTAMP: {
365 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
366 snprintf(buf,100,
"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
367 tm->year, tm->month, tm->day,
368 tm->hour, tm->minute, tm->second);
371 case MYSQL_TYPE_TIME: {
372 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
373 snprintf(buf,100,
"%2.2d:%2.2d:%2.2d",
374 tm->hour, tm->minute, tm->second);
377 case MYSQL_TYPE_DATE: {
378 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
379 snprintf(buf,100,
"%4.4d-%2.2d-%2.2d",
380 tm->year, tm->month, tm->day);
394 if (
fBuffer[npar].fResNull)
return 0;
399 if (addr==0)
return 0;
401 switch(
fBind[npar].buffer_type) {
402 case MYSQL_TYPE_LONG:
403 if (sig)
return *((
int*) addr);
else
404 return *((
unsigned int*) addr);
406 case MYSQL_TYPE_LONGLONG:
407 if (sig)
return *((
Long64_t*) addr);
else
410 case MYSQL_TYPE_SHORT:
411 if (sig)
return *((
short*) addr);
else
412 return *((
unsigned short*) addr);
414 case MYSQL_TYPE_TINY:
415 if (sig)
return *((
char*) addr);
else
416 return *((
unsigned char*) addr);
418 case MYSQL_TYPE_FLOAT:
419 return *((
float*) addr);
421 case MYSQL_TYPE_DOUBLE:
422 return *((
double*) addr);
424#if MYSQL_VERSION_ID >= 50022
425 case MYSQL_TYPE_NEWDECIMAL :
427 case MYSQL_TYPE_STRING:
428 case MYSQL_TYPE_VAR_STRING:
429 case MYSQL_TYPE_BLOB: {
430 char* str = (
char*) addr;
432 if ((str==0) || (*str==0) || (len==0))
return 0;
439 sscanf(str,
"%Lf",&buf);
443 case MYSQL_TYPE_DATETIME:
444 case MYSQL_TYPE_TIMESTAMP: {
445 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
446 TDatime rtm(tm->year, tm->month, tm->day,
447 tm->hour, tm->minute, tm->second);
451 case MYSQL_TYPE_DATE: {
452 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
453 TDatime rtm(tm->year, tm->month, tm->day, 0, 0, 0);
454 return rtm.GetDate();
457 case MYSQL_TYPE_TIME: {
458 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
459 TDatime rtm(2000, 1, 1, tm->hour, tm->minute, tm->second);
460 return rtm.GetTime();
486 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) &&
fBuffer[npar].fSign)
499 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && !
fBuffer[npar].fSign)
512 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) &&
fBuffer[npar].fSign)
525 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) &&
fBuffer[npar].fSign)
538 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) && !
fBuffer[npar].fSign)
551 if (
fBuffer[npar].fSqlType==MYSQL_TYPE_DOUBLE)
564 if ((
fBind[npar].buffer_type==MYSQL_TYPE_STRING)
565 || (
fBind[npar].buffer_type==MYSQL_TYPE_BLOB)
566 || (
fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING)
567#
if MYSQL_VERSION_ID >= 50022
568 || (
fBuffer[npar].fSqlType==MYSQL_TYPE_NEWDECIMAL)
571 if (
fBuffer[npar].fResNull)
return 0;
572 char* str = (
char*)
fBuffer[npar].fMem;
575 if (1.*len<size) str[len] = 0;
else
593 if ((
fBind[npar].buffer_type==MYSQL_TYPE_STRING) ||
594 (
fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING) ||
595 (
fBind[npar].buffer_type==MYSQL_TYPE_BLOB) ||
596 (
fBind[npar].buffer_type==MYSQL_TYPE_TINY_BLOB) ||
597 (
fBind[npar].buffer_type==MYSQL_TYPE_MEDIUM_BLOB) ||
598 (
fBind[npar].buffer_type==MYSQL_TYPE_LONG_BLOB)) {
617 switch(
fBind[npar].buffer_type) {
618 case MYSQL_TYPE_DATETIME:
619 case MYSQL_TYPE_TIMESTAMP:
620 case MYSQL_TYPE_DATE: {
621 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
643 switch(
fBind[npar].buffer_type) {
644 case MYSQL_TYPE_DATETIME:
645 case MYSQL_TYPE_TIMESTAMP:
646 case MYSQL_TYPE_TIME: {
647 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
669 switch(
fBind[npar].buffer_type) {
670 case MYSQL_TYPE_DATETIME:
671 case MYSQL_TYPE_TIMESTAMP: {
672 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
697 switch(
fBind[npar].buffer_type) {
698 case MYSQL_TYPE_DATETIME:
699 case MYSQL_TYPE_TIMESTAMP: {
700 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
737 case MYSQL_TYPE_LONG: allocsize =
sizeof(int);
break;
738 case MYSQL_TYPE_LONGLONG: allocsize =
sizeof(
Long64_t);
break;
739 case MYSQL_TYPE_SHORT: allocsize =
sizeof(short);
break;
740 case MYSQL_TYPE_TINY: allocsize =
sizeof(char);
break;
741 case MYSQL_TYPE_FLOAT: allocsize =
sizeof(float);
break;
742 case MYSQL_TYPE_DOUBLE: allocsize =
sizeof(double);
break;
743#if MYSQL_VERSION_ID >= 50022
744 case MYSQL_TYPE_NEWDECIMAL :
746 case MYSQL_TYPE_STRING: allocsize = sqlsize > 256 ? sqlsize : 256;
break;
747 case MYSQL_TYPE_VAR_STRING: allocsize = sqlsize > 256 ? sqlsize : 256;
break;
748 case MYSQL_TYPE_MEDIUM_BLOB:
749 case MYSQL_TYPE_LONG_BLOB:
750 case MYSQL_TYPE_BLOB: allocsize = sqlsize >= 65525 ? sqlsize : 65535;
break;
751 case MYSQL_TYPE_TINY_BLOB: allocsize = sqlsize > 255 ? sqlsize : 255;
break;
752 case MYSQL_TYPE_TIME:
753 case MYSQL_TYPE_DATE:
754 case MYSQL_TYPE_TIMESTAMP:
755 case MYSQL_TYPE_DATETIME: allocsize =
sizeof(MYSQL_TIME); doreset =
true;
break;
756 default:
SetError(-1,
"Nonsupported SQL type",
"SetSQLParamType");
return kFALSE;
766 if ((allocsize>0) &&
fBuffer[npar].fMem && doreset)
767 memset(
fBuffer[npar].fMem, 0, allocsize);
769 fBind[npar].buffer_type = enum_field_types(sqltype);
771 fBind[npar].buffer_length = allocsize;
774 fBind[npar].is_unsigned = !sig;
788 SetError(-1,
"Cannot set parameter for statement", method);
793 SetError(-1,
Form(
"Invalid parameter number %d",npar), method);
799 SetError(-1,
"Cannot initialize parameter buffer", method);
803 if ((
fBuffer[npar].fSqlType!=sqltype) ||
804 (
fBuffer[npar].fSign != sig))
return 0;
822 void* addr =
BeforeSet(
"SetNull", npar, MYSQL_TYPE_LONG);
838 void* addr =
BeforeSet(
"SetInt", npar, MYSQL_TYPE_LONG);
841 *((
int*) addr) = value;
854 *((
unsigned int*) addr) = value;
864 void* addr =
BeforeSet(
"SetLong", npar, MYSQL_TYPE_LONG);
867 *((
int*) addr) = value;
877 void* addr =
BeforeSet(
"SetLong64", npar, MYSQL_TYPE_LONGLONG);
890 void* addr =
BeforeSet(
"SetULong64", npar, MYSQL_TYPE_LONGLONG,
kFALSE);
906 *((
double*) addr) = value;
916 Int_t len = value ? strlen(value) : 0;
918 void* addr =
BeforeSet(
"SetString", npar, MYSQL_TYPE_STRING,
true, maxsize);
920 if (addr==0)
return kFALSE;
922 if (len >=
fBuffer[npar].fSize) {
935 if (value) strcpy((
char*) addr, value);
936 else ((
char*)addr)[0]=
'\0';
948 if (size>=maxsize) maxsize = size + 1;
950 int bin_type = MYSQL_TYPE_BLOB;
951 if (maxsize > 65525) bin_type = MYSQL_TYPE_MEDIUM_BLOB;
952 if (maxsize > 16777205) bin_type = MYSQL_TYPE_LONG_BLOB;
954 void* addr =
BeforeSet(
"SetBinary", npar, bin_type,
true, maxsize);
956 if (addr==0)
return kFALSE;
958 if (size >=
fBuffer[npar].fSize) {
971 memcpy(addr, mem, size);
983 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetDate", npar, MYSQL_TYPE_DATE);
999 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetTime", npar, MYSQL_TYPE_TIME);
1015 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetDatime", npar, MYSQL_TYPE_DATETIME);
1019 addr->month = month;
1034 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetTimestamp", npar, MYSQL_TYPE_TIMESTAMP);
1038 addr->month = month;
unsigned long long ULong64_t
#define CheckErrNo(method, force, res)
#define CheckGetField(method, defres)
#define CheckStmt(method, res)
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...
static ULong64_t fgAllocSizeLimit
void SetBuffersNumber(Int_t n)
Allocate buffers for statement parameters/ result fields.
void * BeforeSet(const char *method, Int_t npar, Int_t sqltype, Bool_t sig=kTRUE, ULong_t size=0)
Check boundary condition before setting value of parameter.
virtual Int_t GetNumFields()
Return number of fields in result set.
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 const char * GetString(Int_t npar)
Return field value as string.
Bool_t IsSetParsMode() const
indicates when parameters bind should be called
virtual Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256)
Set parameter value as string.
const char * ConvertToString(Int_t npar)
Convert field value to string.
TMySQLStatement(const TMySQLStatement &)
virtual Bool_t Process()
Process statement.
virtual Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec)
Return field value as time.
virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
Set parameter value as date.
virtual Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size)
Return field value as binary array.
virtual Int_t GetNumAffectedRows()
Return number of affected rows after statement is processed.
virtual Bool_t NextResultRow()
Shift cursor to nect row in result set.
virtual Bool_t SetULong64(Int_t npar, ULong64_t value)
Set parameter value as unsigned 64-bit integer.
Int_t fWorkingMode
parameter definition structures
virtual Long_t GetLong(Int_t npar)
Return field value as long integer.
void FreeBuffers()
Release all buffers, used by statement.
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
virtual Bool_t SetDouble(Int_t npar, Double_t value)
Set parameter value as double.
virtual Bool_t SetInt(Int_t npar, Int_t value)
Set parameter value as integer.
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.
virtual Bool_t IsNull(Int_t npar)
Checks if field value is null.
Bool_t IsResultSetMode() const
virtual ~TMySQLStatement()
Destructor.
Bool_t SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize=0)
Set parameter type to be used as buffer.
virtual Bool_t SetLong(Int_t npar, Long_t value)
Set parameter value as long integer.
virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec)
Set parameter value as time.
virtual void Close(Option_t *="")
Close statement.
TParamData * fBuffer
array of bind data
virtual Bool_t SetUInt(Int_t npar, UInt_t value)
Set parameter value as unsigned integer.
virtual Bool_t NextIteration()
Increment iteration counter for statement, where parameter can be set.
Bool_t fNeedParBind
number of iteration
virtual Bool_t SetNull(Int_t npar)
Set NULL as parameter value.
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 UInt_t GetUInt(Int_t npar)
Return field value as unsigned integer.
virtual Int_t GetInt(Int_t npar)
Return field value as integer.
virtual Bool_t SetLong64(Int_t npar, Long64_t value)
Set parameter value as 64-bit integer.
virtual Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day)
Return field value as date.
virtual ULong64_t GetULong64(Int_t npar)
Return field value as unsigned 64-bit integer.
Int_t fNumBuffers
executed statement
virtual const char * GetFieldName(Int_t nfield)
Returns field name in result set.
virtual Double_t GetDouble(Int_t npar)
Return field value as double.
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 StoreResult()
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods.
virtual Int_t GetNumParameters()
Return number of statement parameters.
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 Long64_t GetLong64(Int_t npar)
Return field value as 64-bit integer.
long double ConvertToNumeric(Int_t npar)
Convert field to numeric value.
MYSQL_BIND * fBind
number of statement parameters
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
char * fFieldName
special buffer to be used for string conversions
Bool_t fSign
sqltype of parameter
char * fStrBuffer
indicates if argument is null
ULong_t fResLength
signed - not signed type
Int_t fSize
allocated data buffer
my_bool fResNull
length argument
Int_t fSqlType
size of allocated data