Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSQLiteResult.cxx
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#include "TSQLiteResult.h"
13#include "TSQLiteRow.h"
14
15#include <sqlite3.h>
16
17
18////////////////////////////////////////////////////////////////////////////////
19/// SQLite query result.
20
22{
24
25 // RowCount is -1, as sqlite cannot determine RowCount beforehand:
26 fRowCount = -1;
27}
28
29////////////////////////////////////////////////////////////////////////////////
30/// Cleanup SQLite query result.
31
37
38////////////////////////////////////////////////////////////////////////////////
39/// Close query result.
40
42{
43 if (!fResult)
44 return;
45
47 fResult = nullptr;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Check if result set is open and field index within range.
52
54{
55 if (!fResult) {
56 Error("IsValid", "result set closed");
57 return kFALSE;
58 }
60 Error("IsValid", "field index out of bounds");
61 return kFALSE;
62 }
63 return kTRUE;
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Get number of fields in result.
68
70{
71 if (!fResult) {
72 Error("GetFieldCount", "result set closed");
73 return 0;
74 }
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// Get name of specified field.
80
82{
83 if (!fResult) {
84 Error("GetFieldName", "result set closed");
85 return nullptr;
86 }
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// SQLite can not determine the row count for a Query, return -1 instead.
92/// For similar functionality, call Next() until it retruns nullptr.
93
95{
96 return -1;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Get next query result row. The returned object must be
101/// deleted by the user.
102
104{
105 if (!fResult) {
106 Error("Next", "result set closed");
107 return nullptr;
108 }
109
110 int ret = sqlite3_step(fResult);
111 if ((ret != SQLITE_DONE) && (ret != SQLITE_ROW)) {
112 Error("Statement", "SQL Error: %d %s", ret, sqlite3_errmsg(sqlite3_db_handle(fResult)));
113 return nullptr;
114 }
115 if (ret == SQLITE_DONE) {
116 // Finished executing, no other row!
117 return nullptr;
118 }
119 return new TSQLiteRow((void *) fResult, -1);
120}
121
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 result
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Int_t fRowCount
Definition TSQLResult.h:34
void Close(Option_t *opt="") final
Close query result.
sqlite3_stmt * fResult
const char * GetFieldName(Int_t field) final
Get name of specified field.
Int_t GetRowCount() const final
SQLite can not determine the row count for a Query, return -1 instead.
~TSQLiteResult()
Cleanup SQLite query result.
TSQLRow * Next() final
Get next query result row.
Int_t GetFieldCount() final
Get number of fields in result.
Bool_t IsValid(Int_t field)
Check if result set is open and field index within range.
TSQLiteResult(void *result)
SQLite query result.