Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMySQLStatement.cxx
Go to the documentation of this file.
1// @(#)root/mysql:$Id$
2// Author: Sergey Linev 6/02/2006
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// SQL statement class for MySQL //
15// //
16// See TSQLStatement class documentation for more details. //
17// //
18//////////////////////////////////////////////////////////////////////////
19
20#include "TMySQLStatement.h"
21#include "TMySQLServer.h"
22#include "TDataType.h"
23#include "TDatime.h"
24#include "snprintf.h"
25#include "strlcpy.h"
26#include <cstdlib>
27
29
31
32////////////////////////////////////////////////////////////////////////////////
33/// Return limit for maximal allocated memory for single parameter
34
36{
37 return fgAllocSizeLimit;
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Set limit for maximal allocated memory for single parameter
42
44{
46}
47
48#if MYSQL_VERSION_ID >= 40100
49
50////////////////////////////////////////////////////////////////////////////////
51/// Normal constructor.
52/// Checks if statement contains parameters tags.
53
55 TSQLStatement(errout),
56 fStmt(stmt)
57{
58 ULong_t paramcount = mysql_stmt_param_count(fStmt);
59
60 if (paramcount>0) {
61 fWorkingMode = 1;
62 SetBuffersNumber(paramcount);
64 fIterationCount = -1;
65 }
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Destructor.
70
72{
73 Close();
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Close statement.
78
80{
81 if (fStmt)
82 mysql_stmt_close(fStmt);
83
84 fStmt = nullptr;
85
87}
88
89
90// Reset error and check that statement exists
91#define CheckStmt(method, res) \
92 { \
93 ClearError(); \
94 if (fStmt==0) { \
95 SetError(-1,"Statement handle is 0",method); \
96 return res; \
97 } \
98 }
99
100// check last mysql statement error code
101#define CheckErrNo(method, force, res) \
102 { \
103 unsigned int stmterrno = mysql_stmt_errno(fStmt); \
104 if ((stmterrno!=0) || force) { \
105 const char* stmterrmsg = mysql_stmt_error(fStmt); \
106 if (stmterrno==0) { stmterrno = 11111; stmterrmsg = "MySQL statement error"; } \
107 SetError(stmterrno, stmterrmsg, method); \
108 return res; \
109 } \
110 }
111
112
113// check last mysql statement error code
114#define CheckGetField(method, res) \
115 { \
116 ClearError(); \
117 if (!IsResultSetMode()) { \
118 SetError(-1,"Cannot get statement parameters",method); \
119 return res; \
120 } \
121 if ((npar<0) || (npar>=fNumBuffers)) { \
122 SetError(-1,Form("Invalid parameter number %d", npar),method); \
123 return res; \
124 } \
125 }
126
127////////////////////////////////////////////////////////////////////////////////
128/// Process statement.
129
131{
132 CheckStmt("Process",kFALSE);
133
134 // if parameters was set, processing just means of closing parameters and variables
135 if (IsSetParsMode()) {
136 if (fIterationCount>=0)
137 if (!NextIteration()) return kFALSE;
138 fWorkingMode = 0;
139 fIterationCount = -1;
140 FreeBuffers();
141 return kTRUE;
142 }
143
144 if (mysql_stmt_execute(fStmt))
145 CheckErrNo("Process",kTRUE, kFALSE);
146
147 return kTRUE;
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Return number of affected rows after statement is processed.
152
154{
155 CheckStmt("Process", -1);
156
157 my_ulonglong res = mysql_stmt_affected_rows(fStmt);
158
159 if (res == (my_ulonglong) -1)
160 CheckErrNo("GetNumAffectedRows", kTRUE, -1);
161
162 return (Int_t) res;
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Return number of statement parameters.
167
169{
170 CheckStmt("GetNumParameters", -1);
171
172 Int_t res = mysql_stmt_param_count(fStmt);
173
174 CheckErrNo("GetNumParameters", kFALSE, -1);
175
176 return res;
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Store result of statement processing to access them
181/// via GetInt(), GetDouble() and so on methods.
182
184{
185 CheckStmt("StoreResult", kFALSE);
186 if (fWorkingMode!=0) {
187 SetError(-1,"Cannot store result for that statement","StoreResult");
188 return kFALSE;
189 }
190
191 if (mysql_stmt_store_result(fStmt))
192 CheckErrNo("StoreResult",kTRUE, kFALSE);
193
194 // allocate memeory for data reading from query
195 MYSQL_RES* meta = mysql_stmt_result_metadata(fStmt);
196 if (meta) {
197 int count = mysql_num_fields(meta);
198
199 SetBuffersNumber(count);
200
201 MYSQL_FIELD *fields = mysql_fetch_fields(meta);
202
203 for (int n=0;n<count;n++) {
204 SetSQLParamType(n, fields[n].type, (fields[n].flags & UNSIGNED_FLAG) == 0, fields[n].length);
205 if (fields[n].name)
206 fBuffer[n].fFieldName = fields[n].name;
207 }
208
209 mysql_free_result(meta);
210 }
211
212 if (!fBind) return kFALSE;
213
214 /* Bind the buffers */
215 if (mysql_stmt_bind_result(fStmt, fBind))
216 CheckErrNo("StoreResult",kTRUE, kFALSE);
217
218 fWorkingMode = 2;
219
220 return kTRUE;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Return number of fields in result set.
225
227{
228 return IsResultSetMode() ? fNumBuffers : -1;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Returns field name in result set.
233
234const char* TMySQLStatement::GetFieldName(Int_t nfield)
235{
236 if (!IsResultSetMode() || (nfield<0) || (nfield>=fNumBuffers)) return nullptr;
237
238 return fBuffer[nfield].fFieldName.empty() ? nullptr : fBuffer[nfield].fFieldName.c_str();
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Shift cursor to nect row in result set.
243
245{
246 if ((fStmt==0) || !IsResultSetMode()) return kFALSE;
247
248 Bool_t res = !mysql_stmt_fetch(fStmt);
249
250 if (!res) {
251 fWorkingMode = 0;
252 FreeBuffers();
253 }
254
255 return res;
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Increment iteration counter for statement, where parameter can be set.
260/// Statement with parameters of previous iteration
261/// automatically will be applied to database.
262
264{
265 ClearError();
266
267 if (!IsSetParsMode() || (fBind==0)) {
268 SetError(-1,"Cannot call for that statement","NextIteration");
269 return kFALSE;
270 }
271
273
274 if (fIterationCount==0) return kTRUE;
275
276 if (fNeedParBind) {
278 if (mysql_stmt_bind_param(fStmt, fBind))
279 CheckErrNo("NextIteration",kTRUE, kFALSE);
280 }
281
282 if (mysql_stmt_execute(fStmt))
283 CheckErrNo("NextIteration", kTRUE, kFALSE);
284
285 return kTRUE;
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Release all buffers, used by statement.
290
292{
293 if (fBuffer) {
294 for (Int_t n=0; n<fNumBuffers;n++) {
295 free(fBuffer[n].fMem);
296 }
297 delete[] fBuffer;
298 }
299
300 if (fBind)
301 delete[] fBind;
302
303 fBuffer = nullptr;
304 fBind = nullptr;
305 fNumBuffers = 0;
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Allocate buffers for statement parameters/ result fields.
310
312{
313 FreeBuffers();
314 if (numpars<=0) return;
315
316 fNumBuffers = numpars;
317
319 memset(fBind, 0, sizeof(MYSQL_BIND)*fNumBuffers);
320
321 fBuffer = new TParamData[fNumBuffers];
322 for (int n=0;n<fNumBuffers;++n) {
323 fBuffer[n].fMem = nullptr;
324 fBuffer[n].fSize = 0;
325 fBuffer[n].fSqlType = 0;
327 fBuffer[n].fResLength = 0;
328 fBuffer[n].fResNull = false;
329 fBuffer[n].fStrBuffer.clear();
330 fBuffer[n].fFieldName.clear();
331 }
332}
333
334////////////////////////////////////////////////////////////////////////////////
335/// Convert field value to string.
336
338{
339 if (fBuffer[npar].fResNull)
340 return nullptr;
341
342 void *addr = fBuffer[npar].fMem;
343 Bool_t sig = fBuffer[npar].fSign;
344
345 if (!addr)
346 return nullptr;
347
348 if ((fBind[npar].buffer_type==MYSQL_TYPE_STRING) ||
349 (fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING))
350 return (const char *) addr;
351
352 constexpr int kSize = 100;
353 char buf[kSize];
354 int len = 0;
355
356 switch(fBind[npar].buffer_type) {
357 case MYSQL_TYPE_LONG:
358 if (sig) len = snprintf(buf, kSize, "%d",*((int*) addr));
359 else len = snprintf(buf, kSize, "%u",*((unsigned int*) addr));
360 break;
361 case MYSQL_TYPE_LONGLONG:
362 if (sig) len = snprintf(buf, kSize, "%lld",*((Long64_t*) addr)); else
363 len = snprintf(buf, kSize, "%llu",*((ULong64_t*) addr));
364 break;
365 case MYSQL_TYPE_SHORT:
366 if (sig) len = snprintf(buf, kSize, "%hd",*((short*) addr)); else
367 len = snprintf(buf, kSize, "%hu",*((unsigned short*) addr));
368 break;
369 case MYSQL_TYPE_TINY:
370 if (sig) len = snprintf(buf, kSize, "%d",*((char*) addr)); else
371 len = snprintf(buf, kSize, "%u",*((unsigned char*) addr));
372 break;
373 case MYSQL_TYPE_FLOAT:
374 len = snprintf(buf, kSize, TSQLServer::GetFloatFormat(), *((float*) addr));
375 break;
376 case MYSQL_TYPE_DOUBLE:
377 len = snprintf(buf, kSize, TSQLServer::GetFloatFormat(), *((double*) addr));
378 break;
379 case MYSQL_TYPE_DATETIME:
380 case MYSQL_TYPE_TIMESTAMP: {
381 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
382 len = snprintf(buf, kSize, "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
383 tm->year, tm->month, tm->day,
384 tm->hour, tm->minute, tm->second);
385 break;
386 }
387 case MYSQL_TYPE_TIME: {
388 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
389 len = snprintf(buf, kSize, "%2.2d:%2.2d:%2.2d",
390 tm->hour, tm->minute, tm->second);
391 break;
392 }
393 case MYSQL_TYPE_DATE: {
394 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
395 len = snprintf(buf, kSize, "%4.4d-%2.2d-%2.2d",
396 tm->year, tm->month, tm->day);
397 break;
398 }
399 default:
400 return nullptr;
401 }
402
403 if (len >= kSize)
404 SetError(-1, Form("Cannot convert param %d into string - buffer too small", npar));
405
406 fBuffer[npar].fStrBuffer = buf;
407
408 return fBuffer[npar].fStrBuffer.c_str();
409}
410
411////////////////////////////////////////////////////////////////////////////////
412/// Convert field to numeric value.
413
415{
416 if (fBuffer[npar].fResNull) return 0;
417
418 void* addr = fBuffer[npar].fMem;
419 Bool_t sig = fBuffer[npar].fSign;
420
421 if (addr==0) return 0;
422
423 switch(fBind[npar].buffer_type) {
424 case MYSQL_TYPE_LONG:
425 if (sig) return *((int*) addr); else
426 return *((unsigned int*) addr);
427 break;
428 case MYSQL_TYPE_LONGLONG:
429 if (sig) return *((Long64_t*) addr); else
430 return *((ULong64_t*) addr);
431 break;
432 case MYSQL_TYPE_SHORT:
433 if (sig) return *((short*) addr); else
434 return *((unsigned short*) addr);
435 break;
436 case MYSQL_TYPE_TINY:
437 if (sig) return *((char*) addr); else
438 return *((unsigned char*) addr);
439 break;
440 case MYSQL_TYPE_FLOAT:
441 return *((float*) addr);
442 break;
443 case MYSQL_TYPE_DOUBLE:
444 return *((double*) addr);
445 break;
446#if MYSQL_VERSION_ID >= 50022
447 case MYSQL_TYPE_NEWDECIMAL /* new MYSQL_TYPE fixed precision decimal */:
448#endif
449 case MYSQL_TYPE_STRING:
450 case MYSQL_TYPE_VAR_STRING:
451 case MYSQL_TYPE_BLOB: {
452 char* str = (char*) addr;
454 if ((str==0) || (*str==0) || (len==0)) return 0;
455 Int_t size = fBuffer[npar].fSize;
456 if (1.*len<size)
457 str[len] = 0;
458 else
459 str[size-1] = 0;
460 long double buf = 0;
461 sscanf(str,"%Lf",&buf);
462 return buf;
463 break;
464 }
465 case MYSQL_TYPE_DATETIME:
466 case MYSQL_TYPE_TIMESTAMP: {
467 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
468 TDatime rtm(tm->year, tm->month, tm->day,
469 tm->hour, tm->minute, tm->second);
470 return rtm.Get();
471 break;
472 }
473 case MYSQL_TYPE_DATE: {
474 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
475 TDatime rtm(tm->year, tm->month, tm->day, 0, 0, 0);
476 return rtm.GetDate();
477 break;
478 }
479 case MYSQL_TYPE_TIME: {
480 MYSQL_TIME* tm = (MYSQL_TIME*) addr;
481 TDatime rtm(2000, 1, 1, tm->hour, tm->minute, tm->second);
482 return rtm.GetTime();
483 break;
484 }
485
486 default:
487 return 0;
488 }
489}
490
491////////////////////////////////////////////////////////////////////////////////
492/// Checks if field value is null.
493
495{
496 CheckGetField("IsNull", kTRUE);
497
498 return fBuffer[npar].fResNull;
499}
500
501////////////////////////////////////////////////////////////////////////////////
502/// Return field value as integer.
503
505{
506 CheckGetField("GetInt", 0);
507
508 if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && fBuffer[npar].fSign)
509 return (Int_t) *((int*) fBuffer[npar].fMem);
510
511 return (Int_t) ConvertToNumeric(npar);
512}
513
514////////////////////////////////////////////////////////////////////////////////
515/// Return field value as unsigned integer.
516
518{
519 CheckGetField("GetUInt", 0);
520
521 if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && !fBuffer[npar].fSign)
522 return (UInt_t) *((unsigned int*) fBuffer[npar].fMem);
523
524 return (UInt_t) ConvertToNumeric(npar);
525}
526
527////////////////////////////////////////////////////////////////////////////////
528/// Return field value as long integer.
529
531{
532 CheckGetField("GetLong", 0);
533
534 if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && fBuffer[npar].fSign)
535 return (Long_t) *((int*) fBuffer[npar].fMem);
536
537 return (Long_t) ConvertToNumeric(npar);
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Return field value as 64-bit integer.
542
544{
545 CheckGetField("GetLong64", 0);
546
547 if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) && fBuffer[npar].fSign)
548 return (Long64_t) *((Long64_t*) fBuffer[npar].fMem);
549
550 return (Long64_t) ConvertToNumeric(npar);
551}
552
553////////////////////////////////////////////////////////////////////////////////
554/// Return field value as unsigned 64-bit integer.
555
557{
558 CheckGetField("GetULong64", 0);
559
560 if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) && !fBuffer[npar].fSign)
561 return (ULong64_t) *((ULong64_t*) fBuffer[npar].fMem);
562
563 return (ULong64_t) ConvertToNumeric(npar);
564}
565
566////////////////////////////////////////////////////////////////////////////////
567/// Return field value as double.
568
570{
571 CheckGetField("GetDouble", 0);
572
573 if (fBuffer[npar].fSqlType==MYSQL_TYPE_DOUBLE)
574 return (Double_t) *((double*) fBuffer[npar].fMem);
575
576 return (Double_t) ConvertToNumeric(npar);
577}
578
579////////////////////////////////////////////////////////////////////////////////
580/// Return field value as string.
581
582const char *TMySQLStatement::GetString(Int_t npar)
583{
584 CheckGetField("GetString", 0);
585
586 if ((fBind[npar].buffer_type==MYSQL_TYPE_STRING)
587 || (fBind[npar].buffer_type==MYSQL_TYPE_BLOB)
588 || (fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING)
589#if MYSQL_VERSION_ID >= 50022
590 || (fBuffer[npar].fSqlType==MYSQL_TYPE_NEWDECIMAL)
591#endif
592 ) {
593 if (fBuffer[npar].fResNull) return nullptr;
594 char *str = (char *) fBuffer[npar].fMem;
596 Int_t size = fBuffer[npar].fSize;
597 if (1.*len<size) str[len] = 0; else
598 str[size-1] = 0;
599 return str;
600 }
601
602 return ConvertToString(npar);
603}
604
605////////////////////////////////////////////////////////////////////////////////
606/// Return field value as binary array.
607
609{
610 mem = 0;
611 size = 0;
612
613 CheckGetField("GetBinary", kFALSE);
614
615 if ((fBind[npar].buffer_type==MYSQL_TYPE_STRING) ||
616 (fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING) ||
617 (fBind[npar].buffer_type==MYSQL_TYPE_BLOB) ||
618 (fBind[npar].buffer_type==MYSQL_TYPE_TINY_BLOB) ||
619 (fBind[npar].buffer_type==MYSQL_TYPE_MEDIUM_BLOB) ||
620 (fBind[npar].buffer_type==MYSQL_TYPE_LONG_BLOB)) {
621 if (fBuffer[npar].fResNull) return kTRUE;
622 mem = fBuffer[npar].fMem;
623 size = fBuffer[npar].fResLength;
624 return kTRUE;
625 }
626
627 return kFALSE;
628}
629
630////////////////////////////////////////////////////////////////////////////////
631/// Return field value as date.
632
633Bool_t TMySQLStatement::GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day)
634{
635 CheckGetField("GetDate", kFALSE);
636
637 if (fBuffer[npar].fResNull) return kFALSE;
638
639 switch(fBind[npar].buffer_type) {
640 case MYSQL_TYPE_DATETIME:
641 case MYSQL_TYPE_TIMESTAMP:
642 case MYSQL_TYPE_DATE: {
643 MYSQL_TIME* tm = (MYSQL_TIME*) fBuffer[npar].fMem;
644 if (tm==0) return kFALSE;
645 year = tm->year;
646 month = tm->month;
647 day = tm->day;
648 break;
649 }
650 default:
651 return kFALSE;
652 }
653 return kTRUE;
654}
655
656////////////////////////////////////////////////////////////////////////////////
657/// Return field value as time.
658
659Bool_t TMySQLStatement::GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec)
660{
661 CheckGetField("GetTime", kFALSE);
662
663 if (fBuffer[npar].fResNull) return kFALSE;
664
665 switch(fBind[npar].buffer_type) {
666 case MYSQL_TYPE_DATETIME:
667 case MYSQL_TYPE_TIMESTAMP:
668 case MYSQL_TYPE_TIME: {
669 MYSQL_TIME* tm = (MYSQL_TIME*) fBuffer[npar].fMem;
670 if (tm==0) return kFALSE;
671 hour = tm->hour;
672 min = tm->minute;
673 sec = tm->second;
674 break;
675 }
676 default:
677 return kFALSE;
678 }
679 return kTRUE;
680}
681
682////////////////////////////////////////////////////////////////////////////////
683/// Return field value as date & time.
684
685Bool_t TMySQLStatement::GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec)
686{
687 CheckGetField("GetDatime", kFALSE);
688
689 if (fBuffer[npar].fResNull) return kFALSE;
690
691 switch(fBind[npar].buffer_type) {
692 case MYSQL_TYPE_DATETIME:
693 case MYSQL_TYPE_TIMESTAMP: {
694 MYSQL_TIME* tm = (MYSQL_TIME*) fBuffer[npar].fMem;
695 if (tm==0) return kFALSE;
696 year = tm->year;
697 month = tm->month;
698 day = tm->day;
699 hour = tm->hour;
700 min = tm->minute;
701 sec = tm->second;
702 break;
703 }
704 default:
705 return kFALSE;
706 }
707 return kTRUE;
708}
709
710////////////////////////////////////////////////////////////////////////////////
711/// Return field value as time stamp.
712
713Bool_t TMySQLStatement::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)
714{
715 CheckGetField("GetTimstamp", kFALSE);
716
717 if (fBuffer[npar].fResNull) return kFALSE;
718
719 switch(fBind[npar].buffer_type) {
720 case MYSQL_TYPE_DATETIME:
721 case MYSQL_TYPE_TIMESTAMP: {
722 MYSQL_TIME* tm = (MYSQL_TIME*) fBuffer[npar].fMem;
723 if (tm==0) return kFALSE;
724 year = tm->year;
725 month = tm->month;
726 day = tm->day;
727 hour = tm->hour;
728 min = tm->minute;
729 sec = tm->second;
730 frac = 0;
731 break;
732 }
733 default:
734 return kFALSE;
735 }
736 return kTRUE;
737}
738
739////////////////////////////////////////////////////////////////////////////////
740/// Set parameter type to be used as buffer.
741/// Used in both setting data to database and retrieving data from data base.
742/// Initialize proper MYSQL_BIND structure and allocate required buffers.
743
744Bool_t TMySQLStatement::SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize)
745{
746 if ((npar<0) || (npar>=fNumBuffers)) return kFALSE;
747
748 fBuffer[npar].fMem = nullptr;
749 fBuffer[npar].fSize = 0;
750 fBuffer[npar].fResLength = 0;
751 fBuffer[npar].fResNull = false;
752 fBuffer[npar].fStrBuffer.clear();
753
754 ULong64_t allocsize = 0;
755
756 Bool_t doreset = false;
757
758 switch (sqltype) {
759 case MYSQL_TYPE_LONG: allocsize = sizeof(int); break;
760 case MYSQL_TYPE_LONGLONG: allocsize = sizeof(Long64_t); break;
761 case MYSQL_TYPE_SHORT: allocsize = sizeof(short); break;
762 case MYSQL_TYPE_TINY: allocsize = sizeof(char); break;
763 case MYSQL_TYPE_FLOAT: allocsize = sizeof(float); break;
764 case MYSQL_TYPE_DOUBLE: allocsize = sizeof(double); break;
765#if MYSQL_VERSION_ID >= 50022
766 case MYSQL_TYPE_NEWDECIMAL /* new MYSQL_TYPE fixed precision decimal */:
767#endif
768 case MYSQL_TYPE_STRING: allocsize = sqlsize > 256 ? sqlsize : 256; break;
769 case MYSQL_TYPE_VAR_STRING: allocsize = sqlsize > 256 ? sqlsize : 256; break;
770 case MYSQL_TYPE_MEDIUM_BLOB:
771 case MYSQL_TYPE_LONG_BLOB:
772 case MYSQL_TYPE_BLOB: allocsize = sqlsize >= 65525 ? sqlsize : 65535; break;
773 case MYSQL_TYPE_TINY_BLOB: allocsize = sqlsize > 255 ? sqlsize : 255; break;
774 case MYSQL_TYPE_TIME:
775 case MYSQL_TYPE_DATE:
776 case MYSQL_TYPE_TIMESTAMP:
777 case MYSQL_TYPE_DATETIME: allocsize = sizeof(MYSQL_TIME); doreset = true; break;
778 default: SetError(-1, Form("SQL type not supported: %d", sqltype),"SetSQLParamType"); return kFALSE;
779 }
780
781 // SL: 256 bytes is default size value for string or tiny blob
782 // therefore small fgAllocSizeLimit only has effect for data over limit of 256 bytes
783 if ((fgAllocSizeLimit > 256) && (allocsize > fgAllocSizeLimit))
784 allocsize = fgAllocSizeLimit;
785
786 fBuffer[npar].fMem = malloc(allocsize);
787 fBuffer[npar].fSize = allocsize;
788 fBuffer[npar].fSqlType = sqltype;
789 fBuffer[npar].fSign = sig;
790
791 if (fBuffer[npar].fMem && doreset)
792 memset(fBuffer[npar].fMem, 0, allocsize);
793
794 fBind[npar].buffer_type = enum_field_types(sqltype);
795 fBind[npar].buffer = fBuffer[npar].fMem;
796 fBind[npar].buffer_length = allocsize;
797 fBind[npar].is_null= &(fBuffer[npar].fResNull);
798 fBind[npar].length = &(fBuffer[npar].fResLength);
799 fBind[npar].is_unsigned = !sig;
800
801 return kTRUE;
802}
803
804////////////////////////////////////////////////////////////////////////////////
805/// Check boundary condition before setting value of parameter.
806/// Return address of parameter buffer.
807
808void *TMySQLStatement::BeforeSet(const char* method, Int_t npar, Int_t sqltype, Bool_t sig, ULong_t size)
809{
810 ClearError();
811
812 if (!IsSetParsMode()) {
813 SetError(-1,"Cannot set parameter for statement", method);
814 return 0;
815 }
816
817 if ((npar<0) || (npar>=fNumBuffers)) {
818 SetError(-1,Form("Invalid parameter number %d",npar), method);
819 return 0;
820 }
821
822 if ((fIterationCount==0) && (fBuffer[npar].fSqlType==0))
823 if (!SetSQLParamType(npar, sqltype, sig, size)) {
824 SetError(-1,"Cannot initialize parameter buffer", method);
825 return 0;
826 }
827
828 if ((fBuffer[npar].fSqlType!=sqltype) ||
829 (fBuffer[npar].fSign != sig)) return 0;
830
831 fBuffer[npar].fResNull = false;
832
833 return fBuffer[npar].fMem;
834}
835
836////////////////////////////////////////////////////////////////////////////////
837/// Set NULL as parameter value.
838/// If NULL should be set for statement parameter during first iteration,
839/// one should call before proper Set... method to identify type of argument for
840/// the future. For instance, if one suppose to have double as type of parameter,
841/// code should look like:
842/// stmt->SetDouble(2, 0.);
843/// stmt->SetNull(2);
844
846{
847 void* addr = BeforeSet("SetNull", npar, MYSQL_TYPE_LONG);
848
849 if (addr!=0)
850 *((int*) addr) = 0;
851
852 if ((npar>=0) && (npar<fNumBuffers))
853 fBuffer[npar].fResNull = true;
854
855 return kTRUE;
856}
857
858////////////////////////////////////////////////////////////////////////////////
859/// Set parameter value as integer.
860
862{
863 void* addr = BeforeSet("SetInt", npar, MYSQL_TYPE_LONG);
864
865 if (addr!=0)
866 *((int*) addr) = value;
867
868 return (addr!=0);
869}
870
871////////////////////////////////////////////////////////////////////////////////
872/// Set parameter value as unsigned integer.
873
875{
876 void* addr = BeforeSet("SetUInt", npar, MYSQL_TYPE_LONG, kFALSE);
877
878 if (addr!=0)
879 *((unsigned int*) addr) = value;
880
881 return (addr!=0);
882}
883
884////////////////////////////////////////////////////////////////////////////////
885/// Set parameter value as long integer.
886
888{
889 void* addr = BeforeSet("SetLong", npar, MYSQL_TYPE_LONG);
890
891 if (addr!=0)
892 *((int*) addr) = value;
893
894 return (addr!=0);
895}
896
897////////////////////////////////////////////////////////////////////////////////
898/// Set parameter value as 64-bit integer.
899
901{
902 void* addr = BeforeSet("SetLong64", npar, MYSQL_TYPE_LONGLONG);
903
904 if (addr!=0)
905 *((Long64_t*) addr) = value;
906
907 return (addr!=0);
908}
909
910////////////////////////////////////////////////////////////////////////////////
911/// Set parameter value as unsigned 64-bit integer.
912
914{
915 void* addr = BeforeSet("SetULong64", npar, MYSQL_TYPE_LONGLONG, kFALSE);
916
917 if (addr!=0)
918 *((ULong64_t*) addr) = value;
919
920 return (addr!=0);
921}
922
923////////////////////////////////////////////////////////////////////////////////
924/// Set parameter value as double.
925
927{
928 void* addr = BeforeSet("SetDouble", npar, MYSQL_TYPE_DOUBLE, kFALSE);
929
930 if (addr!=0)
931 *((double*) addr) = value;
932
933 return (addr!=0);
934}
935
936////////////////////////////////////////////////////////////////////////////////
937/// Set parameter value as string.
938
939Bool_t TMySQLStatement::SetString(Int_t npar, const char* value, Int_t maxsize)
940{
941 Int_t len = value ? strlen(value) : 0;
942
943 void *addr = BeforeSet("SetString", npar, MYSQL_TYPE_STRING, true, maxsize);
944
945 if (!addr) return kFALSE;
946
947 if (len >= fBuffer[npar].fSize) {
948 free(fBuffer[npar].fMem);
949
950 fBuffer[npar].fMem = malloc(len+1);
951 fBuffer[npar].fSize = len + 1;
952
953 fBind[npar].buffer = fBuffer[npar].fMem;
954 fBind[npar].buffer_length = fBuffer[npar].fSize;
955
956 addr = fBuffer[npar].fMem;
958 }
959
960 if (value)
961 strlcpy((char*) addr, value, fBuffer[npar].fSize);
962 else
963 ((char *)addr)[0] = 0;
964
965 fBuffer[npar].fResLength = len;
966
967 return kTRUE;
968}
969
970////////////////////////////////////////////////////////////////////////////////
971/// Set parameter value as binary data.
972
973Bool_t TMySQLStatement::SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize)
974{
975 if (size>=maxsize) maxsize = size + 1;
976
977 int bin_type = MYSQL_TYPE_BLOB;
978 if (maxsize > 65525) bin_type = MYSQL_TYPE_MEDIUM_BLOB;
979 if (maxsize > 16777205) bin_type = MYSQL_TYPE_LONG_BLOB;
980
981 void* addr = BeforeSet("SetBinary", npar, bin_type, true, maxsize);
982
983 if (addr==0) return kFALSE;
984
985 if (size >= fBuffer[npar].fSize) {
986 free(fBuffer[npar].fMem);
987
988 fBuffer[npar].fMem = malloc(size+1);
989 fBuffer[npar].fSize = size + 1;
990
991 fBind[npar].buffer = fBuffer[npar].fMem;
992 fBind[npar].buffer_length = fBuffer[npar].fSize;
993
994 addr = fBuffer[npar].fMem;
996 }
997
998 memcpy(addr, mem, size);
999
1000 fBuffer[npar].fResLength = size;
1001
1002 return kTRUE;
1003}
1004
1005////////////////////////////////////////////////////////////////////////////////
1006/// Set parameter value as date.
1007
1008Bool_t TMySQLStatement::SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
1009{
1010 MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetDate", npar, MYSQL_TYPE_DATE);
1011
1012 if (addr!=0) {
1013 addr->year = year;
1014 addr->month = month;
1015 addr->day = day;
1016 }
1017
1018 return (addr!=0);
1019}
1020
1021////////////////////////////////////////////////////////////////////////////////
1022/// Set parameter value as time.
1023
1025{
1026 MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetTime", npar, MYSQL_TYPE_TIME);
1027
1028 if (addr!=0) {
1029 addr->hour = hour;
1030 addr->minute = min;
1031 addr->second = sec;
1032 }
1033
1034 return (addr!=0);
1035}
1036
1037////////////////////////////////////////////////////////////////////////////////
1038/// Set parameter value as date & time.
1039
1040Bool_t TMySQLStatement::SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec)
1041{
1042 MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetDatime", npar, MYSQL_TYPE_DATETIME);
1043
1044 if (addr!=0) {
1045 addr->year = year;
1046 addr->month = month;
1047 addr->day = day;
1048 addr->hour = hour;
1049 addr->minute = min;
1050 addr->second = sec;
1051 }
1052
1053 return (addr!=0);
1054}
1055
1056////////////////////////////////////////////////////////////////////////////////
1057/// Set parameter value as timestamp.
1058
1059Bool_t TMySQLStatement::SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t)
1060{
1061 MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetTimestamp", npar, MYSQL_TYPE_TIMESTAMP);
1062
1063 if (addr!=0) {
1064 addr->year = year;
1065 addr->month = month;
1066 addr->day = day;
1067 addr->hour = hour;
1068 addr->minute = min;
1069 addr->second = sec;
1070 }
1071
1072 return (addr!=0);
1073}
1074
1075#else
1076
1077////////////////////////////////////////////////////////////////////////////////
1078/// Normal constructor.
1079/// For MySQL version < 4.1 no statement is supported
1080
1082{
1083}
1084
1085////////////////////////////////////////////////////////////////////////////////
1086/// Destructor.
1087
1089{
1090}
1091
1092////////////////////////////////////////////////////////////////////////////////
1093/// Close statement
1094
1096{
1097}
1098
1099////////////////////////////////////////////////////////////////////////////////
1100/// Process statement.
1101
1103{
1104 return kFALSE;
1105}
1106
1107////////////////////////////////////////////////////////////////////////////////
1108/// Return number of affected rows after statement is processed.
1109
1111{
1112 return 0;
1113}
1114
1115////////////////////////////////////////////////////////////////////////////////
1116/// Return number of statement parameters.
1117
1119{
1120 return 0;
1121}
1122
1123////////////////////////////////////////////////////////////////////////////////
1124/// Store result of statement processing to access them
1125/// via GetInt(), GetDouble() and so on methods.
1126
1128{
1129 return kFALSE;
1130}
1131
1132////////////////////////////////////////////////////////////////////////////////
1133/// Return number of fields in result set.
1134
1136{
1137 return 0;
1138}
1139
1140////////////////////////////////////////////////////////////////////////////////
1141/// Returns field name in result set.
1142
1144{
1145 return 0;
1146}
1147
1148////////////////////////////////////////////////////////////////////////////////
1149/// Shift cursor to nect row in result set.
1150
1152{
1153 return kFALSE;
1154}
1155
1156
1157////////////////////////////////////////////////////////////////////////////////
1158/// Increment iteration counter for statement, where parameter can be set.
1159/// Statement with parameters of previous iteration
1160/// automatically will be applied to database.
1161
1163{
1164 return kFALSE;
1165}
1166
1167////////////////////////////////////////////////////////////////////////////////
1168/// Release all buffers, used by statement.
1169
1171{
1172}
1173
1174////////////////////////////////////////////////////////////////////////////////
1175/// Allocate buffers for statement parameters/ result fields.
1176
1178{
1179}
1180
1181////////////////////////////////////////////////////////////////////////////////
1182/// Convert field value to string.
1183
1185{
1186 return 0;
1187}
1188
1189////////////////////////////////////////////////////////////////////////////////
1190/// Convert field to numeric value.
1191
1193{
1194 return 0;
1195}
1196
1197////////////////////////////////////////////////////////////////////////////////
1198/// Checks if field value is null.
1199
1201{
1202 return kTRUE;
1203}
1204
1205////////////////////////////////////////////////////////////////////////////////
1206/// Return field value as integer.
1207
1209{
1210 return 0;
1211}
1212
1213////////////////////////////////////////////////////////////////////////////////
1214/// Return field value as unsigned integer.
1215
1217{
1218 return 0;
1219}
1220
1221////////////////////////////////////////////////////////////////////////////////
1222/// Return field value as long integer.
1223
1225{
1226 return 0;
1227}
1228
1229////////////////////////////////////////////////////////////////////////////////
1230/// Return field value as 64-bit integer.
1231
1233{
1234 return 0;
1235}
1236
1237////////////////////////////////////////////////////////////////////////////////
1238/// Return field value as unsigned 64-bit integer.
1239
1241{
1242 return 0;
1243}
1244
1245////////////////////////////////////////////////////////////////////////////////
1246/// Return field value as double.
1247
1249{
1250 return 0.;
1251}
1252
1253////////////////////////////////////////////////////////////////////////////////
1254/// Return field value as string.
1255
1257{
1258 return 0;
1259}
1260
1261////////////////////////////////////////////////////////////////////////////////
1262/// Return field value as binary array.
1263
1265{
1266 return kFALSE;
1267}
1268
1269
1270////////////////////////////////////////////////////////////////////////////////
1271/// Return field value as date.
1272
1274{
1275 return kFALSE;
1276}
1277
1278////////////////////////////////////////////////////////////////////////////////
1279/// Return field value as time.
1280
1282{
1283 return kFALSE;
1284}
1285
1286////////////////////////////////////////////////////////////////////////////////
1287/// Return field value as date & time.
1288
1290{
1291 return kFALSE;
1292}
1293
1294////////////////////////////////////////////////////////////////////////////////
1295/// Return field value as time stamp.
1296
1298{
1299 return kFALSE;
1300}
1301
1302////////////////////////////////////////////////////////////////////////////////
1303/// Set parameter type to be used as buffer.
1304/// Used in both setting data to database and retriving data from data base.
1305/// Initialize proper MYSQL_BIND structure and allocate required buffers.
1306
1308{
1309 return kFALSE;
1310}
1311
1312////////////////////////////////////////////////////////////////////////////////
1313/// Check boundary condition before setting value of parameter.
1314/// Return address of parameter buffer.
1315
1317{
1318 return 0;
1319}
1320
1321////////////////////////////////////////////////////////////////////////////////
1322/// Set NULL as parameter value.
1323/// If NULL should be set for statement parameter during first iteration,
1324/// one should call before proper Set... method to identify type of argument for
1325/// the future. For instance, if one suppose to have double as type of parameter,
1326/// code should look like:
1327/// stmt->SetDouble(2, 0.);
1328/// stmt->SetNull(2);
1329
1331{
1332 return kFALSE;
1333}
1334
1335////////////////////////////////////////////////////////////////////////////////
1336/// Set parameter value as integer.
1337
1339{
1340 return kFALSE;
1341}
1342
1343////////////////////////////////////////////////////////////////////////////////
1344/// Set parameter value as unsigned integer.
1345
1347{
1348 return kFALSE;
1349}
1350
1351////////////////////////////////////////////////////////////////////////////////
1352/// Set parameter value as long integer.
1353
1355{
1356 return kFALSE;
1357}
1358
1359////////////////////////////////////////////////////////////////////////////////
1360/// Set parameter value as 64-bit integer.
1361
1363{
1364 return kFALSE;
1365}
1366
1367////////////////////////////////////////////////////////////////////////////////
1368/// Set parameter value as unsigned 64-bit integer.
1369
1371{
1372 return kFALSE;
1373}
1374
1375////////////////////////////////////////////////////////////////////////////////
1376/// Set parameter value as double.
1377
1379{
1380 return kFALSE;
1381}
1382
1383////////////////////////////////////////////////////////////////////////////////
1384/// Set parameter value as string.
1385
1387{
1388 return kFALSE;
1389}
1390
1391////////////////////////////////////////////////////////////////////////////////
1392/// Set parameter value as binary data.
1393
1395{
1396 return kFALSE;
1397}
1398
1399////////////////////////////////////////////////////////////////////////////////
1400/// Set parameter value as date.
1401
1403{
1404 return kFALSE;
1405}
1406
1407////////////////////////////////////////////////////////////////////////////////
1408/// Set parameter value as time.
1409
1411{
1412 return kFALSE;
1413}
1414
1415////////////////////////////////////////////////////////////////////////////////
1416/// Set parameter value as date & time.
1417
1419{
1420 return kFALSE;
1421}
1422
1423////////////////////////////////////////////////////////////////////////////////
1424/// Set parameter value as timestamp.
1425
1427{
1428 return kFALSE;
1429}
1430
1431#endif // MYSQL_VERSION_ID > 40100
size_t fSize
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
unsigned long ULong_t
Definition RtypesCore.h:55
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define CheckErrNo(method, force, res)
#define CheckGetField(method, defres)
#define CheckStmt(method, res)
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
@ kSize
Definition TStructNode.h:26
#define free
Definition civetweb.c:1539
#define snprintf
Definition civetweb.c:1540
#define malloc
Definition civetweb.c:1536
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
static ULong64_t fgAllocSizeLimit
void SetBuffersNumber(Int_t n)
Allocate buffers for statement parameters/ result fields.
Bool_t SetInt(Int_t npar, Int_t value) final
Set parameter value as integer.
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.
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.
UInt_t GetUInt(Int_t npar) final
Return field value as unsigned integer.
Bool_t NextIteration() final
Increment iteration counter for statement, where parameter can be set.
Double_t GetDouble(Int_t npar) final
Return field value as double.
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 IsSetParsMode() const
indicates when parameters bind should be called
const char * ConvertToString(Int_t npar)
Convert field value to string.
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
Return field value as date.
Bool_t SetDouble(Int_t npar, Double_t value) final
Set parameter value as double.
MYSQL_STMT * fStmt
Bool_t SetUInt(Int_t npar, UInt_t value) final
Set parameter value as unsigned integer.
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.
Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec) final
Return field value as time.
Bool_t Process() final
Process statement.
Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
Set parameter value as binary data.
static void SetAllocSizeLimit(ULong_t sz)
Set limit for maximal allocated memory for single parameter.
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.
Int_t fWorkingMode
parameter definition structures
Int_t GetNumParameters() final
Return number of statement parameters.
void FreeBuffers()
Release all buffers, used by statement.
Bool_t IsNull(Int_t npar) final
Checks if field value is null.
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
ULong64_t GetULong64(Int_t npar) final
Return field value as unsigned 64-bit integer.
Long64_t GetLong64(Int_t npar) final
Return field value as 64-bit integer.
static ULong_t GetAllocSizeLimit()
Return limit for maximal allocated memory for single parameter.
Bool_t IsResultSetMode() const
virtual ~TMySQLStatement()
Destructor.
const char * GetFieldName(Int_t nfield) final
Returns field name in result set.
Bool_t SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize=0)
Set parameter type to be used as buffer.
Int_t GetInt(Int_t npar) final
Return field value as integer.
TParamData * fBuffer
array of bind data
Int_t GetNumFields() final
Return number of fields in result set.
Bool_t fNeedParBind
number of iteration
Bool_t SetLong(Int_t npar, Long_t value) final
Set parameter value as long integer.
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
Set parameter value as date.
Bool_t StoreResult() final
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods.
Int_t fNumBuffers
executed statement
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
Set parameter value as string.
Long_t GetLong(Int_t npar) final
Return field value as long integer.
TMySQLStatement(const TMySQLStatement &)=delete
Bool_t SetLong64(Int_t npar, Long64_t value) final
Set parameter value as 64-bit integer.
Int_t GetNumAffectedRows() final
Return number of affected rows after statement is processed.
Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size) final
Return field value as binary array.
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.
long double ConvertToNumeric(Int_t npar)
Convert field to numeric value.
const char * GetString(Int_t npar) final
Return field value as string.
Bool_t SetNull(Int_t npar) final
Set NULL as parameter value.
Bool_t SetULong64(Int_t npar, ULong64_t value) final
Set parameter value as unsigned 64-bit integer.
Bool_t NextResultRow() final
Shift cursor to nect row in result set.
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=nullptr)
set new values for error fields if method specified, displays error message
void ClearError()
reset error fields
const Int_t n
Definition legend1.C:16
Bool_t fSign
sqltype of parameter
std::string fFieldName
special buffer to be used for string conversions
ULong_t fResLength
signed - not signed type
Int_t fSize
allocated data buffer
my_bool fResNull
length argument
std::string fStrBuffer
indicates if argument is null
Int_t fSqlType
size of allocated data