Logo ROOT  
Reference Guide
TSQLiteStatement.h
Go to the documentation of this file.
1 // @(#)root/sqlite:$Id$
2 // Author: o.freyermuth <o.f@cern.ch>, 01/06/2013
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, 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 #ifndef ROOT_TSQLiteStatement
13 #define ROOT_TSQLiteStatement
14 
15 #include "TSQLStatement.h"
16 
17 class sqlite3;
18 class sqlite3_stmt;
19 
21  sqlite3 *fConn;
22  sqlite3_stmt *fRes;
23 };
24 
26 
27 private:
28  SQLite3_Stmt_t *fStmt{nullptr}; //! executed statement
29  Int_t fWorkingMode{0}; //! 1 - setting parameters, 2 - retrieving results
30  Int_t fNumPars{0}; //! Number of bindable / gettable parameters
31  Int_t fIterationCount{0}; //! Iteration count
32 
33  Bool_t IsSetParsMode() const { return fWorkingMode==1; }
34  Bool_t IsResultSetMode() const { return fWorkingMode==2; }
35 
36  Bool_t SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize = 0);
37 
38  long double ConvertToNumeric(Int_t npar);
39  const char *ConvertToString(Int_t npar);
40 
41  Bool_t CheckBindError(const char *method, int res);
42 
43 public:
45  virtual ~TSQLiteStatement();
46 
47  void Close(Option_t * = "") final;
48 
49  Int_t GetBufferLength() const final { return 1; }
50  Int_t GetNumParameters() final;
51 
52  Bool_t SetNull(Int_t npar) final;
53  Bool_t SetInt(Int_t npar, Int_t value) final;
54  Bool_t SetUInt(Int_t npar, UInt_t value) final;
55  Bool_t SetLong(Int_t npar, Long_t value) final;
56  Bool_t SetLong64(Int_t npar, Long64_t value) final;
57  Bool_t SetULong64(Int_t npar, ULong64_t value) final;
58  Bool_t SetDouble(Int_t npar, Double_t value) final;
59  Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256) final;
60  Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final;
61  Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final;
62  Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final;
63  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;
65  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;
66 
67  Bool_t NextIteration() final;
68 
69  Bool_t Process() final;
70  Int_t GetNumAffectedRows() final;
71 
72  Bool_t StoreResult() final;
73  Int_t GetNumFields() final;
74  const char *GetFieldName(Int_t nfield) final;
75  Bool_t NextResultRow() final;
76 
77  Bool_t IsNull(Int_t npar) final;
78  Int_t GetInt(Int_t npar) final;
79  UInt_t GetUInt(Int_t npar) final;
80  Long_t GetLong(Int_t npar) final;
81  Long64_t GetLong64(Int_t npar) final;
82  ULong64_t GetULong64(Int_t npar) final;
83  Double_t GetDouble(Int_t npar) final;
84  const char *GetString(Int_t npar) final;
85  Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size) final;
86  Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) final;
87  Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) final;
88  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;
90  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;
91 
92  ClassDefOverride(TSQLiteStatement, 0); // SQL statement class for SQLite DB
93 };
94 
95 #endif
TSQLiteStatement::SetString
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
Set parameter value as string.
Definition: TSQLiteStatement.cxx:547
TSQLiteStatement::ClassDefOverride
ClassDefOverride(TSQLiteStatement, 0)
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TSQLiteStatement::SetBinary
Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
Set parameter value as binary data.
Definition: TSQLiteStatement.cxx:559
TSQLiteStatement::SetTimestamp
virtual Bool_t SetTimestamp(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t=0)
Set parameter as timestamp.
Definition: TSQLStatement.cxx:421
TSQLiteStatement::CheckBindError
Bool_t CheckBindError(const char *method, int res)
Definition: TSQLiteStatement.cxx:112
Option_t
const char Option_t
Definition: RtypesCore.h:66
TSQLiteStatement::~TSQLiteStatement
virtual ~TSQLiteStatement()
Destructor.
Definition: TSQLiteStatement.cxx:57
TSQLiteStatement::NextResultRow
Bool_t NextResultRow() final
Shift cursor to next row in result set.
Definition: TSQLiteStatement.cxx:225
TSQLiteStatement::SetInt
Bool_t SetInt(Int_t npar, Int_t value) final
Set parameter value as integer.
Definition: TSQLiteStatement.cxx:485
TSQLiteStatement::GetNumFields
Int_t GetNumFields() final
Return number of fields in result set.
Definition: TSQLiteStatement.cxx:205
TSQLiteStatement
Definition: TSQLiteStatement.h:25
TSQLiteStatement::SetULong64
Bool_t SetULong64(Int_t npar, ULong64_t value) final
Set parameter value as unsigned 64-bit integer.
Definition: TSQLiteStatement.cxx:527
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TSQLiteStatement::ConvertToString
const char * ConvertToString(Int_t npar)
Convert field value to string.
Definition: TSQLiteStatement.cxx:273
SQLite3_Stmt_t::fConn
sqlite3 * fConn
Definition: TSQLiteStatement.h:21
TSQLiteStatement::GetBufferLength
Int_t GetBufferLength() const final
Definition: TSQLiteStatement.h:49
TSQLiteStatement::GetDatime
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.
Definition: TSQLiteStatement.cxx:429
SQLite3_Stmt_t
Definition: TSQLiteStatement.h:20
TSQLiteStatement::IsNull
Bool_t IsNull(Int_t npar) final
Checks if field value is null.
Definition: TSQLiteStatement.cxx:293
Int_t
int Int_t
Definition: RtypesCore.h:45
TSQLiteStatement::GetULong64
ULong64_t GetULong64(Int_t npar) final
Return field value as unsigned 64-bit integer.
Definition: TSQLiteStatement.cxx:343
TSQLStatement.h
TSQLiteStatement::GetInt
Int_t GetInt(Int_t npar) final
Get integer.
Definition: TSQLiteStatement.cxx:303
TSQLiteStatement::SetDate
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
Set parameter value as date.
Definition: TSQLiteStatement.cxx:574
TSQLiteStatement::Process
Bool_t Process() final
Process statement.
Definition: TSQLiteStatement.cxx:128
TSQLiteStatement::ConvertToNumeric
long double ConvertToNumeric(Int_t npar)
Convert field to numeric.
Definition: TSQLiteStatement.cxx:283
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TSQLiteStatement::GetNumAffectedRows
Int_t GetNumAffectedRows() final
Return number of affected rows after statement is processed.
Definition: TSQLiteStatement.cxx:167
TSQLiteStatement::SetLong64
Bool_t SetLong64(Int_t npar, Long64_t value) final
Set parameter value as 64-bit integer.
Definition: TSQLiteStatement.cxx:516
TSQLiteStatement::GetDate
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
Return field value as date.
Definition: TSQLiteStatement.cxx:397
bool
TSQLiteStatement::GetTimestamp
virtual Bool_t GetTimestamp(Int_t, Int_t &, Int_t &, Int_t &, Int_t &, Int_t &, Int_t &, Int_t &)
Get parameter as timestamp.
Definition: TSQLStatement.cxx:438
TSQLiteStatement::NextIteration
Bool_t NextIteration() final
Increment iteration counter for statement, where parameter can be set.
Definition: TSQLiteStatement.cxx:248
TSQLiteStatement::fStmt
SQLite3_Stmt_t * fStmt
Definition: TSQLiteStatement.h:28
TSQLiteStatement::IsSetParsMode
Bool_t IsSetParsMode() const
Iteration count.
Definition: TSQLiteStatement.h:33
TSQLiteStatement::SetSQLParamType
Bool_t SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize=0)
TSQLiteStatement::GetLong64
Long64_t GetLong64(Int_t npar) final
Get long64.
Definition: TSQLiteStatement.cxx:333
TSQLiteStatement::SetDatime
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.
Definition: TSQLiteStatement.cxx:597
TSQLiteStatement::TSQLiteStatement
TSQLiteStatement(SQLite3_Stmt_t *stmt, Bool_t errout=kTRUE)
Normal constructor.
Definition: TSQLiteStatement.cxx:36
TSQLiteStatement::GetString
const char * GetString(Int_t npar) final
Return field value as string.
Definition: TSQLiteStatement.cxx:363
TSQLiteStatement::SetDouble
Bool_t SetDouble(Int_t npar, Double_t value) final
Set parameter value as double value.
Definition: TSQLiteStatement.cxx:537
Long_t
long Long_t
Definition: RtypesCore.h:54
TSQLiteStatement::SetUInt
Bool_t SetUInt(Int_t npar, UInt_t value) final
Set parameter value as unsigned integer.
Definition: TSQLiteStatement.cxx:496
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TSQLiteStatement::GetNumParameters
Int_t GetNumParameters() final
Return number of statement parameters.
Definition: TSQLiteStatement.cxx:177
TSQLiteStatement::SetNull
Bool_t SetNull(Int_t npar) final
Set NULL as parameter value.
Definition: TSQLiteStatement.cxx:475
TSQLiteStatement::GetUInt
UInt_t GetUInt(Int_t npar) final
Get unsigned integer.
Definition: TSQLiteStatement.cxx:313
TSQLiteStatement::IsResultSetMode
Bool_t IsResultSetMode() const
Definition: TSQLiteStatement.h:34
TSQLiteStatement::Close
void Close(Option_t *="") final
Close statement.
Definition: TSQLiteStatement.cxx:65
SQLite3_Stmt_t::fRes
sqlite3_stmt * fRes
Definition: TSQLiteStatement.h:22
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
Double_t
double Double_t
Definition: RtypesCore.h:59
TSQLiteStatement::SetLong
Bool_t SetLong(Int_t npar, Long_t value) final
Set parameter value as long.
Definition: TSQLiteStatement.cxx:506
TSQLiteStatement::GetLong
Long_t GetLong(Int_t npar) final
Get long.
Definition: TSQLiteStatement.cxx:323
TSQLiteStatement::fWorkingMode
Int_t fWorkingMode
executed statement
Definition: TSQLiteStatement.h:29
TSQLiteStatement::fNumPars
Int_t fNumPars
1 - setting parameters, 2 - retrieving results
Definition: TSQLiteStatement.h:30
TSQLStatement
Definition: TSQLStatement.h:21
TSQLiteStatement::GetDouble
Double_t GetDouble(Int_t npar) final
Return field value as double.
Definition: TSQLiteStatement.cxx:353
TSQLiteStatement::StoreResult
Bool_t StoreResult() final
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods.
Definition: TSQLiteStatement.cxx:193
TSQLiteStatement::GetBinary
Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size) final
Return field value as binary array.
Definition: TSQLiteStatement.cxx:375
TSQLiteStatement::GetFieldName
const char * GetFieldName(Int_t nfield) final
Returns field name in result set.
Definition: TSQLiteStatement.cxx:213
TSQLiteStatement::GetTime
Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec) final
Return field as time.
Definition: TSQLiteStatement.cxx:413
TSQLiteStatement::SetTime
Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final
Set parameter value as time.
Definition: TSQLiteStatement.cxx:585
TSQLiteStatement::fIterationCount
Int_t fIterationCount
Number of bindable / gettable parameters.
Definition: TSQLiteStatement.h:31
int