42 unsigned long bindParamcount = sqlite3_bind_parameter_count(
fStmt->fRes);
44 if (bindParamcount > 0) {
67 sqlite3_finalize(
fStmt->fRes);
70 fStmt->fRes =
nullptr;
71 fStmt->fConn =
nullptr;
77#define CheckStmt(method, res) \
81 SetError(-1,"Statement handle is 0",method); \
86#define CheckErrNo(method, force, res) \
88 int stmterrno = sqlite3_errcode(fStmt->fConn); \
89 if ((stmterrno!=0) || force) { \
90 const char* stmterrmsg = sqlite3_errmsg(fStmt->fConn); \
91 if (stmterrno==0) { stmterrno = -1; stmterrmsg = "SQLite statement error"; } \
92 SetError(stmterrno, stmterrmsg, method); \
97#define CheckGetField(method, res) \
100 if (!IsResultSetMode()) { \
101 SetError(-1,"Cannot get statement parameters",method); \
104 if ((npar<0) || (npar>=fNumPars)) { \
105 SetError(-1,Form("Invalid parameter number %d", npar),method); \
113 if (res == SQLITE_RANGE) {
114 SetError(-1,
Form(
"SQLite parameter out of bounds, error: %d %s", res, sqlite3_errmsg(
fStmt->fConn)), method);
117 if (res != SQLITE_OK) {
118 SetError(-1,
Form(
"SQLite error code during parameter binding, error: %d %s", res, sqlite3_errmsg(
fStmt->fConn)), method);
131 int res = sqlite3_step(
fStmt->fRes);
132 if ((res != SQLITE_DONE) && (res != SQLITE_ROW)) {
133 SetError(-1,
Form(
"SQLite error code during statement-stepping: %d %s", res, sqlite3_errmsg(
fStmt->fConn)),
"Process");
139 if (res == SQLITE_DONE) {
140 sqlite3_reset(
fStmt->fRes);
153 if (res == SQLITE_ROW) {
180 Int_t res = sqlite3_bind_parameter_count(
fStmt->fRes);
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);
305 return (
Int_t) sqlite3_column_int(
fStmt->fRes, npar);
315 return (
UInt_t) sqlite3_column_int(
fStmt->fRes, npar);
325 return (
Long_t) sqlite3_column_int64(
fStmt->fRes, npar);
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);
496 int res = sqlite3_bind_int(
fStmt->fRes, npar + 1, (
Int_t)value);
506 int res = sqlite3_bind_int64(
fStmt->fRes, npar + 1, value);
516 int res = sqlite3_bind_int64(
fStmt->fRes, npar + 1, value);
527 int res = sqlite3_bind_int64(
fStmt->fRes, npar + 1, (
Long64_t)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);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
int Ssiz_t
String size (currently int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
const char Option_t
Option string (const char).
#define CheckErrNo(method, force, res)
#define CheckGetField(method, res)
#define CheckStmt(method, res)
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
TSQLStatement(Bool_t errout=kTRUE)
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.
SQLite3_Stmt_t * fStmt
! executed statement
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
Set parameter value as date.
Int_t fIterationCount
! Iteration count
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
! 1 - setting parameters, 2 - retrieving results
Bool_t SetInt(Int_t npar, Int_t value) final
Set parameter value as integer.
Bool_t IsSetParsMode() const
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
Return field value as date.
Int_t fNumPars
! Number of bindable / gettable parameters
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