Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPgSQLResult.cxx
Go to the documentation of this file.
1// @(#)root/pgsql:$Id$
2// Author: g.p.ciceri <gp.ciceri@acm.org> 01/06/2001
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, 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 "TPgSQLResult.h"
13#include "TPgSQLRow.h"
14
15#include <libpq-fe.h>
16
18
19////////////////////////////////////////////////////////////////////////////////
20/// PgSQL query result.
21
23{
25 fRowCount = fResult ? PQntuples(fResult) : 0;
26 fCurrentRow = 0;
27}
28
29////////////////////////////////////////////////////////////////////////////////
30/// Cleanup PgSQL query result.
31
33{
34 if (fResult)
35 Close();
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Close query result.
40
42{
43 if (!fResult)
44 return;
45
46 PQclear(fResult);
47 fResult = nullptr;
48 fRowCount = 0;
49 fCurrentRow = 0;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Check if result set is open and field index within range.
54
56{
57 if (!fResult) {
58 Error("IsValid", "result set closed");
59 return kFALSE;
60 }
61 if (field < 0 || field >= GetFieldCount()) {
62 Error("IsValid", "field index out of bounds");
63 return kFALSE;
64 }
65 return kTRUE;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Get number of fields in result.
70
72{
73 if (!fResult) {
74 Error("GetFieldCount", "result set closed");
75 return 0;
76 }
77 return PQnfields(fResult);
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Get name of specified field.
82
84{
85 if (!fResult) {
86 Error("GetFieldName", "result set closed");
87 return nullptr;
88 }
89 return PQfname(fResult, field);
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Get next query result row. The returned object must be
94/// deleted by the user.
95
97{
98 if (!fResult) {
99 Error("Next", "result set closed");
100 return nullptr;
101 }
102 ULong_t row = fCurrentRow++;
103 if ((Int_t) row >= fRowCount)
104 return nullptr;
105
106 return new TPgSQLRow(fResult, row);
107}
unsigned long ULong_t
Definition RtypesCore.h:55
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
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
struct pg_result PGresult
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
const char * GetFieldName(Int_t field) final
Get name of specified field.
PGresult * fResult
Bool_t IsValid(Int_t field)
Check if result set is open and field index within range.
Int_t GetFieldCount() final
Get number of fields in result.
~TPgSQLResult()
Cleanup PgSQL query result.
ULong_t fCurrentRow
TSQLRow * Next() final
Get next query result row.
TPgSQLResult(PGresult *result)
PgSQL query result.
void Close(Option_t *opt="") final
Close query result.
Int_t fRowCount
Definition TSQLResult.h:34