ROOT  6.06/09
Reference Guide
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 
17 
18 ////////////////////////////////////////////////////////////////////////////////
19 /// PgSQL query result.
20 
22 {
23  fResult = (PGresult *) result;
24  fRowCount = fResult ? PQntuples(fResult) : 0;
25  fCurrentRow = 0;
26 }
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Cleanup PgSQL query result.
30 
32 {
33  if (fResult)
34  Close();
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Close query result.
39 
41 {
42  if (!fResult)
43  return;
44 
45  PQclear(fResult);
46  fResult = 0;
47  fRowCount = 0;
48  fCurrentRow = 0;
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 PQnfields(fResult);
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Get name of specified field.
81 
83 {
84  if (!fResult) {
85  Error("GetFieldName", "result set closed");
86  return 0;
87  }
88  return PQfname(fResult, field);
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Get next query result row. The returned object must be
93 /// deleted by the user.
94 
96 {
97  Int_t row;
98 
99  if (!fResult) {
100  Error("Next", "result set closed");
101  return 0;
102  }
103  row = fCurrentRow++;
104  if (row >= fRowCount)
105  return 0;
106  else
107  return new TPgSQLRow((void *) fResult, (ULong_t) row);
108 }
const char Option_t
Definition: RtypesCore.h:62
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TSQLRow * Next()
Get next query result row.
Bool_t IsValid(Int_t field)
Check if result set is open and field index within range.
PGresult * fResult
Definition: TPgSQLResult.h:29
Int_t GetFieldCount()
Get number of fields in result.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
const char * GetFieldName(Int_t field)
Get name of specified field.
void Close(Option_t *opt="")
Close query result.
unsigned long ULong_t
Definition: RtypesCore.h:51
ClassImp(TPgSQLResult) TPgSQLResult
PgSQL query result.
Int_t fRowCount
Definition: TSQLResult.h:37
double result[121]
~TPgSQLResult()
Cleanup PgSQL query result.
const Bool_t kTRUE
Definition: Rtypes.h:91
ULong_t fCurrentRow
Definition: TPgSQLResult.h:30