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#include <sqlite3.h>
18
20 sqlite3 *fConn;
21 sqlite3_stmt *fRes;
22};
23
25
26private:
27 SQLite3_Stmt_t *fStmt{nullptr}; //! executed statement
28 Int_t fWorkingMode{0}; //! 1 - setting parameters, 2 - retrieving results
29 Int_t fNumPars{0}; //! Number of bindable / gettable parameters
30 Int_t fIterationCount{0}; //! Iteration count
31
32 Bool_t IsSetParsMode() const { return fWorkingMode==1; }
33 Bool_t IsResultSetMode() const { return fWorkingMode==2; }
34
35 Bool_t SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize = 0);
36
37 long double ConvertToNumeric(Int_t npar);
38 const char *ConvertToString(Int_t npar);
39
40 Bool_t CheckBindError(const char *method, int res);
41
42public:
44 virtual ~TSQLiteStatement();
45
46 void Close(Option_t * = "") final;
47
48 Int_t GetBufferLength() const final { return 1; }
49 Int_t GetNumParameters() final;
50
51 Bool_t SetNull(Int_t npar) final;
52 Bool_t SetInt(Int_t npar, Int_t value) final;
53 Bool_t SetUInt(Int_t npar, UInt_t value) final;
54 Bool_t SetLong(Int_t npar, Long_t value) final;
55 Bool_t SetLong64(Int_t npar, Long64_t value) final;
56 Bool_t SetULong64(Int_t npar, ULong64_t value) final;
57 Bool_t SetDouble(Int_t npar, Double_t value) final;
58 Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256) final;
59 Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final;
60 Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final;
61 Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final;
62 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;
64 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;
65
66 Bool_t NextIteration() final;
67
68 Bool_t Process() final;
70
71 Bool_t StoreResult() final;
72 Int_t GetNumFields() final;
73 const char *GetFieldName(Int_t nfield) final;
74 Bool_t NextResultRow() final;
75
76 Bool_t IsNull(Int_t npar) final;
77 Int_t GetInt(Int_t npar) final;
78 UInt_t GetUInt(Int_t npar) final;
79 Long_t GetLong(Int_t npar) final;
80 Long64_t GetLong64(Int_t npar) final;
81 ULong64_t GetULong64(Int_t npar) final;
82 Double_t GetDouble(Int_t npar) final;
83 const char *GetString(Int_t npar) final;
84 Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size) final;
85 Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) final;
86 Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) final;
87 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;
89 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;
90
91 ClassDefOverride(TSQLiteStatement, 0); // SQL statement class for SQLite DB
92};
93
94#endif
int Int_t
Definition: RtypesCore.h:43
unsigned int UInt_t
Definition: RtypesCore.h:44
long Long_t
Definition: RtypesCore.h:52
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
long long Long64_t
Definition: RtypesCore.h:71
unsigned long long ULong64_t
Definition: RtypesCore.h:72
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
Set parameter value as string.
Int_t GetBufferLength() const final
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
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.
ClassDefOverride(TSQLiteStatement, 0)
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.
Bool_t SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize=0)
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.
sqlite3_stmt * fRes