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
18
19////////////////////////////////////////////////////////////////////////////////
20/// SQLite query result.
21
23{
24 fResult = (sqlite3_stmt *) result;
25
26 // RowCount is -1, as sqlite cannot determine RowCount beforehand:
27 fRowCount = -1;
28}
29
30////////////////////////////////////////////////////////////////////////////////
31/// Cleanup SQLite query result.
32
34{
35 if (fResult)
36 Close();
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Close query result.
41
43{
44 if (!fResult)
45 return;
46
47 sqlite3_finalize(fResult);
48 fResult = nullptr;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Check if result set is open and field index within range.
53
55{
56 if (!fResult) {
57 Error("IsValid", "result set closed");
58 return kFALSE;
59 }
60 if (field < 0 || field >= GetFieldCount()) {
61 Error("IsValid", "field index out of bounds");
62 return kFALSE;
63 }
64 return kTRUE;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Get number of fields in result.
69
71{
72 if (!fResult) {
73 Error("GetFieldCount", "result set closed");
74 return 0;
75 }
76 return sqlite3_column_count(fResult);
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Get name of specified field.
81
83{
84 if (!fResult) {
85 Error("GetFieldName", "result set closed");
86 return nullptr;
87 }
88 return sqlite3_column_name(fResult, field);
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// SQLite can not determine the row count for a Query, return -1 instead.
93/// For similar functionality, call Next() until it retruns nullptr.
94
96{
97 return -1;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Get next query result row. The returned object must be
102/// deleted by the user.
103
105{
106 if (!fResult) {
107 Error("Next", "result set closed");
108 return nullptr;
109 }
110
111 int ret = sqlite3_step(fResult);
112 if ((ret != SQLITE_DONE) && (ret != SQLITE_ROW)) {
113 Error("Statement", "SQL Error: %d %s", ret, sqlite3_errmsg(sqlite3_db_handle(fResult)));
114 return nullptr;
115 }
116 if (ret == SQLITE_DONE) {
117 // Finished executing, no other row!
118 return nullptr;
119 }
120 return new TSQLiteRow((void *) fResult, -1);
121}
122
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
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:993
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.