41 unsigned long bindParamcount = sqlite3_bind_parameter_count(
fStmt->
fRes);
43 if (bindParamcount > 0) {
76#define CheckStmt(method, res) \
80 SetError(-1,"Statement handle is 0",method); \
85#define CheckErrNo(method, force, res) \
87 int stmterrno = sqlite3_errcode(fStmt->fConn); \
88 if ((stmterrno!=0) || force) { \
89 const char* stmterrmsg = sqlite3_errmsg(fStmt->fConn); \
90 if (stmterrno==0) { stmterrno = -1; stmterrmsg = "SQLite statement error"; } \
91 SetError(stmterrno, stmterrmsg, method); \
96#define CheckGetField(method, res) \
99 if (!IsResultSetMode()) { \
100 SetError(-1,"Cannot get statement parameters",method); \
103 if ((npar<0) || (npar>=fNumPars)) { \
104 SetError(-1,Form("Invalid parameter number %d", npar),method); \
112 if (res == SQLITE_RANGE) {
113 SetError(-1,
Form(
"SQLite parameter out of bounds, error: %d %s", res, sqlite3_errmsg(
fStmt->
fConn)), method);
116 if (res != SQLITE_OK) {
117 SetError(-1,
Form(
"SQLite error code during parameter binding, error: %d %s", res, sqlite3_errmsg(
fStmt->
fConn)), method);
131 if ((res != SQLITE_DONE) && (res != SQLITE_ROW)) {
132 SetError(-1,
Form(
"SQLite error code during statement-stepping: %d %s", res, sqlite3_errmsg(
fStmt->
fConn)),
"Process");
138 if (res == SQLITE_DONE) {
152 if (res == SQLITE_ROW) {
217 return sqlite3_column_name(
fStmt->
fRes, nfield);
251 SetError(-1,
"Cannot call for that statement",
"NextIteration");
275 return reinterpret_cast<const char *
>(sqlite3_column_text(
fStmt->
fRes, npar));
285 return (
long double) sqlite3_column_double(
fStmt->
fRes, npar);
295 return (sqlite3_column_type(
fStmt->
fRes, npar) == SQLITE_NULL);
365 return reinterpret_cast<const char *
>(sqlite3_column_text(
fStmt->
fRes, npar));
380 size_t sz = sqlite3_column_bytes(
fStmt->
fRes, npar);
382 delete [](
unsigned char*) mem;
383 mem = (
void*)
new unsigned char[sz];
387 memcpy(mem, sqlite3_column_blob(
fStmt->
fRes, npar), sz);
399 TString val =
reinterpret_cast<const char*
>(sqlite3_column_text(
fStmt->
fRes, npar));
402 month =
d.GetMonth();
415 TString val =
reinterpret_cast<const char*
>(sqlite3_column_text(
fStmt->
fRes, npar));
431 TString val =
reinterpret_cast<const char*
>(sqlite3_column_text(
fStmt->
fRes, npar));
434 month =
d.GetMonth();
451 TString val =
reinterpret_cast<const char*
>(sqlite3_column_text(
fStmt->
fRes, npar));
458 month =
d.GetMonth();
475 int res = sqlite3_bind_null(
fStmt->
fRes, npar + 1);
485 int res = sqlite3_bind_int(
fStmt->
fRes, npar + 1, value);
506 int res = sqlite3_bind_int64(
fStmt->
fRes, npar + 1, value);
516 int res = sqlite3_bind_int64(
fStmt->
fRes, npar + 1, value);
537 int res = sqlite3_bind_double(
fStmt->
fRes, npar + 1, value);
547 int res = sqlite3_bind_text(
fStmt->
fRes, npar + 1, value, maxsize, SQLITE_TRANSIENT);
560 SetError(-1,
"Passing negative value to size for BLOB to SQLite would cause undefined behaviour, refusing it!",
"SetBinary");
564 int res = sqlite3_bind_blob(
fStmt->
fRes, npar + 1, mem, (
size_t)size, SQLITE_TRANSIENT);
575 int res = sqlite3_bind_text(
fStmt->
fRes, npar + 1, (
char*)
d.AsSQLString(), -1, SQLITE_TRANSIENT);
587 int res = sqlite3_bind_text(
fStmt->
fRes, npar + 1, (
char*)
d.AsSQLString(), -1, SQLITE_TRANSIENT);
599 int res = sqlite3_bind_text(
fStmt->
fRes, npar + 1, (
char*)
d.AsSQLString(), -1, SQLITE_TRANSIENT);
611 TDatime d(year,month,day,hour,min,sec);
613 value.
Form(
"%s.%03d", (
char*)
d.AsSQLString(), frac);
615 int res = sqlite3_bind_text(
fStmt->
fRes, npar + 1, value.
Data(), -1, SQLITE_TRANSIENT);
unsigned long long ULong64_t
#define CheckErrNo(method, force, res)
#define CheckGetField(method, res)
#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...
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
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
Set parameter value as string.
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 as time.
void Close(Option_t *="") final
Close statement.
Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final
Set parameter value as time.
Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
Set parameter value as binary data.
Bool_t SetLong64(Int_t npar, Long64_t value) final
Set parameter value as 64-bit integer.
UInt_t GetUInt(Int_t npar) final
Get unsigned integer.
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 as timestamp.
Bool_t IsNull(Int_t npar) final
Checks if field value is null.
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.
virtual ~TSQLiteStatement()
Destructor.
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
Set parameter value as date.
Int_t fIterationCount
Number of bindable / gettable parameters.
Long_t GetLong(Int_t npar) final
Get long.
Int_t GetInt(Int_t npar) final
Get integer.
Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size) final
Return field value as binary array.
Bool_t CheckBindError(const char *method, int res)
ULong64_t GetULong64(Int_t npar) final
Return field value as unsigned 64-bit integer.
Bool_t SetLong(Int_t npar, Long_t value) final
Set parameter value as long.
const char * GetString(Int_t npar) final
Return field value as string.
Bool_t SetNull(Int_t npar) final
Set NULL as parameter value.
const char * ConvertToString(Int_t npar)
Convert field value to string.
Int_t fWorkingMode
executed statement
Bool_t SetInt(Int_t npar, Int_t value) final
Set parameter value as integer.
Bool_t IsSetParsMode() const
Iteration count.
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
Return field value as date.
Int_t fNumPars
1 - setting parameters, 2 - retrieving results
Long64_t GetLong64(Int_t npar) final
Get long64.
Bool_t NextIteration() final
Increment iteration counter for statement, where parameter can be set.
Bool_t IsResultSetMode() const
Bool_t StoreResult() final
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods.
Bool_t SetDouble(Int_t npar, Double_t value) final
Set parameter value as double value.
Int_t GetNumAffectedRows() final
Return number of affected rows after statement is processed.
Bool_t Process() final
Process statement.
Bool_t SetULong64(Int_t npar, ULong64_t value) final
Set parameter value as unsigned 64-bit integer.
Bool_t SetUInt(Int_t npar, UInt_t value) final
Set parameter value as unsigned integer.
Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) final
Set parameter value as date & time.
Bool_t NextResultRow() final
Shift cursor to next row in result set.
const char * GetFieldName(Int_t nfield) final
Returns field name in result set.
Int_t GetNumFields() final
Return number of fields in result set.
Double_t GetDouble(Int_t npar) final
Return field value as double.
Int_t GetNumParameters() final
Return number of statement parameters.
TSQLiteStatement(SQLite3_Stmt_t *stmt, Bool_t errout=kTRUE)
Normal constructor.
long double ConvertToNumeric(Int_t npar)
Convert field to numeric.
const char * Data() const
Ssiz_t Last(char c) const
Find last occurrence of a character c.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
A zero length substring is legal.
const char * Data() const