30 #if MYSQL_VERSION_ID >= 40100
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);
226 if (!
IsResultSetMode() || (nfield<0) || (nfield>=fNumBuffers))
return 0;
258 SetError(-1,
"Cannot call for that statement",
"NextIteration");
272 if (mysql_stmt_execute(
fStmt))
308 if (numpars<=0)
return;
310 fNumBuffers = numpars;
316 memset(
fBuffer, 0,
sizeof(TParamData)*fNumBuffers);
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:
346 if (sig) snprintf(buf,100,
"%lld",*((
Long64_t*) addr));
else
347 snprintf(buf,100,
"%llu",*((
ULong64_t*) addr));
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();
488 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) &&
fBuffer[npar].fSign)
501 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && !
fBuffer[npar].fSign)
514 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) &&
fBuffer[npar].fSign)
527 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) &&
fBuffer[npar].fSign)
540 if ((
fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) && !
fBuffer[npar].fSign)
553 if (
fBuffer[npar].fSqlType==MYSQL_TYPE_DOUBLE)
566 if ((
fBind[npar].buffer_type==MYSQL_TYPE_STRING)
567 || (
fBind[npar].buffer_type==MYSQL_TYPE_BLOB)
568 || (
fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING)
569 #
if MYSQL_VERSION_ID >= 50022
570 || (
fBuffer[npar].fSqlType==MYSQL_TYPE_NEWDECIMAL)
573 if (
fBuffer[npar].fResNull)
return 0;
574 char* str = (
char*)
fBuffer[npar].fMem;
577 if (1.*len<size) str[len] = 0;
else
595 if ((
fBind[npar].buffer_type==MYSQL_TYPE_STRING) ||
596 (
fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING) ||
597 (
fBind[npar].buffer_type==MYSQL_TYPE_BLOB) ||
598 (
fBind[npar].buffer_type==MYSQL_TYPE_TINY_BLOB) ||
599 (
fBind[npar].buffer_type==MYSQL_TYPE_MEDIUM_BLOB) ||
600 (
fBind[npar].buffer_type==MYSQL_TYPE_LONG_BLOB)) {
619 switch(
fBind[npar].buffer_type) {
620 case MYSQL_TYPE_DATETIME:
621 case MYSQL_TYPE_TIMESTAMP:
622 case MYSQL_TYPE_DATE: {
623 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
645 switch(
fBind[npar].buffer_type) {
646 case MYSQL_TYPE_DATETIME:
647 case MYSQL_TYPE_TIMESTAMP:
648 case MYSQL_TYPE_TIME: {
649 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
671 switch(
fBind[npar].buffer_type) {
672 case MYSQL_TYPE_DATETIME:
673 case MYSQL_TYPE_TIMESTAMP: {
674 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
699 switch(
fBind[npar].buffer_type) {
700 case MYSQL_TYPE_DATETIME:
701 case MYSQL_TYPE_TIMESTAMP: {
702 MYSQL_TIME* tm = (MYSQL_TIME*)
fBuffer[npar].fMem;
726 if ((npar<0) || (npar>=fNumBuffers))
return kFALSE;
739 case MYSQL_TYPE_LONG: allocsize =
sizeof(int);
break;
740 case MYSQL_TYPE_LONGLONG: allocsize =
sizeof(
Long64_t);
break;
741 case MYSQL_TYPE_SHORT: allocsize =
sizeof(short);
break;
742 case MYSQL_TYPE_TINY: allocsize =
sizeof(char);
break;
743 case MYSQL_TYPE_FLOAT: allocsize =
sizeof(float);
break;
744 case MYSQL_TYPE_DOUBLE: allocsize =
sizeof(
double);
break;
745 #if MYSQL_VERSION_ID >= 50022
746 case MYSQL_TYPE_NEWDECIMAL :
748 case MYSQL_TYPE_STRING: allocsize = sqlsize > 256 ? sqlsize : 256;
break;
749 case MYSQL_TYPE_VAR_STRING: allocsize = sqlsize > 256 ? sqlsize : 256;
break;
750 case MYSQL_TYPE_MEDIUM_BLOB:
751 case MYSQL_TYPE_LONG_BLOB:
752 case MYSQL_TYPE_BLOB: allocsize = sqlsize >= 65525 ? sqlsize : 65535;
break;
753 case MYSQL_TYPE_TINY_BLOB: allocsize = sqlsize > 255 ? sqlsize : 255;
break;
754 case MYSQL_TYPE_TIME:
755 case MYSQL_TYPE_DATE:
756 case MYSQL_TYPE_TIMESTAMP:
757 case MYSQL_TYPE_DATETIME: allocsize =
sizeof(MYSQL_TIME); doreset =
true;
break;
758 default:
SetError(-1,
"Nonsupported SQL type",
"SetSQLParamType");
return kFALSE;
768 if ((allocsize>0) &&
fBuffer[npar].fMem && doreset)
769 memset(
fBuffer[npar].fMem, 0, allocsize);
771 fBind[npar].buffer_type = enum_field_types(sqltype);
773 fBind[npar].buffer_length = allocsize;
776 fBind[npar].is_unsigned = !sig;
790 SetError(-1,
"Cannot set parameter for statement", method);
794 if ((npar<0) || (npar>=fNumBuffers)) {
795 SetError(-1,
Form(
"Invalid parameter number %d",npar), method);
801 SetError(-1,
"Cannot initialize parameter buffer", method);
805 if ((
fBuffer[npar].fSqlType!=sqltype) ||
806 (
fBuffer[npar].fSign != sig))
return 0;
824 void* addr =
BeforeSet(
"SetNull", npar, MYSQL_TYPE_LONG);
840 void* addr =
BeforeSet(
"SetInt", npar, MYSQL_TYPE_LONG);
843 *((
int*) addr) =
value;
856 *((
unsigned int*) addr) =
value;
866 void* addr =
BeforeSet(
"SetLong", npar, MYSQL_TYPE_LONG);
869 *((
int*) addr) =
value;
879 void* addr =
BeforeSet(
"SetLong64", npar, MYSQL_TYPE_LONGLONG);
892 void* addr =
BeforeSet(
"SetULong64", npar, MYSQL_TYPE_LONGLONG,
kFALSE);
908 *((
double*) addr) =
value;
918 Int_t len = value ? strlen(value) : 0;
920 void* addr =
BeforeSet(
"SetString", npar, MYSQL_TYPE_STRING,
true, maxsize);
922 if (addr==0)
return kFALSE;
924 if (len >=
fBuffer[npar].fSize) {
937 if (value) strcpy((
char*) addr, value);
938 else ((
char*)addr)[0]=
'\0';
950 if (size>=maxsize) maxsize = size + 1;
952 int bin_type = MYSQL_TYPE_BLOB;
953 if (maxsize > 65525) bin_type = MYSQL_TYPE_MEDIUM_BLOB;
954 if (maxsize > 16777205) bin_type = MYSQL_TYPE_LONG_BLOB;
956 void* addr =
BeforeSet(
"SetBinary", npar, bin_type,
true, maxsize);
958 if (addr==0)
return kFALSE;
960 if (size >=
fBuffer[npar].fSize) {
973 memcpy(addr, mem, size);
985 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetDate", npar, MYSQL_TYPE_DATE);
1001 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetTime", npar, MYSQL_TYPE_TIME);
1017 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetDatime", npar, MYSQL_TYPE_DATETIME);
1021 addr->month = month;
1036 MYSQL_TIME* addr = (MYSQL_TIME*)
BeforeSet(
"SetTimestamp", npar, MYSQL_TYPE_TIMESTAMP);
1040 addr->month = month;
1406 #endif // MYSQL_VERSION_ID > 40100
virtual Bool_t SetLong64(Int_t npar, Long64_t value)
Set parameter value as 64-bit integer.
virtual Int_t GetNumParameters()
Return number of statement parameters.
virtual Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000)
Set parameter value as binary data.
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
const char * ConvertToString(Int_t npar)
Convert field value to string.
#define CheckStmt(method, res)
virtual ULong64_t GetULong64(Int_t npar)
Return field value as unsigned 64-bit integer.
void ClearError()
reset error fields
virtual Int_t GetNumAffectedRows()
Return number of affected rows after statement is processed.
virtual Bool_t SetNull(Int_t npar)
Set NULL as parameter value.
virtual Bool_t SetLong(Int_t npar, Long_t value)
Set parameter value as long integer.
void SetError(Int_t code, const char *msg, const char *method=0)
set new values for error fields if method specified, displays error message
Bool_t IsSetParsMode() const
indicates when parameters bind should be called
virtual Bool_t NextResultRow()
Shift cursor to nect row in result set.
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"
char * fStrBuffer
indicates if argument is null
void FreeBuffers()
Release all buffers, used by statement.
virtual Bool_t SetULong64(Int_t npar, ULong64_t value)
Set parameter value as unsigned 64-bit integer.
Bool_t fNeedParBind
number of iteration
virtual void Close(Option_t *="")
Close statement.
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 SetBuffersNumber(Int_t n)
Allocate buffers for statement parameters/ result fields.
virtual Int_t GetInt(Int_t npar)
Return field value as integer.
virtual Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day)
Return field value as date.
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
virtual Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256)
Set parameter value as string.
#define CheckErrNo(method, force, res)
virtual Int_t GetNumFields()
Return number of fields in result set.
virtual Bool_t SetDouble(Int_t npar, Double_t value)
Set parameter value as double.
Double_t length(const TVector2 &v)
my_bool fResNull
length argument
virtual Long64_t GetLong64(Int_t npar)
Return field value as 64-bit integer.
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.
Int_t fSize
allocated data buffer
char * Form(const char *fmt,...)
virtual Double_t GetDouble(Int_t npar)
Return field value as double.
MYSQL_BIND * fBind
number of statement parameters
Int_t fNumBuffers
executed statement
TMySQLStatement(const TMySQLStatement &)
virtual Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec)
Return field value as time.
Bool_t IsResultSetMode() const
Bool_t fSign
sqltype of parameter
long double ConvertToNumeric(Int_t npar)
Convert field to numeric value.
virtual Bool_t SetUInt(Int_t npar, UInt_t value)
Set parameter value as unsigned integer.
unsigned long long ULong64_t
virtual Bool_t SetInt(Int_t npar, Int_t value)
Set parameter value as integer.
virtual Bool_t Process()
Process statement.
virtual Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size)
Return field value as binary array.
virtual const char * GetFieldName(Int_t nfield)
Returns field name in result set.
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 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 Long_t GetLong(Int_t npar)
Return field value as long integer.
#define CheckGetField(method, defres)
Int_t fWorkingMode
parameter definition structures
TParamData * fBuffer
array of bind data
virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
Set parameter value as date.
virtual const char * GetString(Int_t npar)
Return field value as string.
virtual Bool_t IsNull(Int_t npar)
Checks if field value is null.
char * fFieldName
special buffer to be used for string conversions
virtual UInt_t GetUInt(Int_t npar)
Return field value as unsigned integer.
virtual Bool_t NextIteration()
Increment iteration counter for statement, where parameter can be set.
static ULong64_t fgAllocSizeLimit
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
ULong_t fResLength
signed - not signed type
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.
Int_t fSqlType
size of allocated data
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 StoreResult()
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods...
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
virtual ~TMySQLStatement()
Destructor.