Logo ROOT   master
Reference Guide
TPgSQLRow.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 "TPgSQLRow.h"
13 
14 
16 
17 ////////////////////////////////////////////////////////////////////////////////
18 /// Single row of query result.
19 
20 TPgSQLRow::TPgSQLRow(void *res, ULong_t rowHandle)
21 {
22  fResult = (PGresult *) res;
23  fRowNum = (ULong_t) rowHandle;
24 }
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Destroy row object.
28 
30 {
31  if (fRowNum)
32  Close();
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Close row.
37 
39 {
40  if (!fRowNum)
41  return;
42 
43  fResult = 0;
44  fRowNum = 0;
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Check if row is open and field index within range.
49 
51 {
52  if (field < 0 || field >= (Int_t)PQnfields(fResult)) {
53  Error("IsValid", "field index out of bounds");
54  return kFALSE;
55  }
56  return kTRUE;
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Get length in bytes of specified field.
61 
63 {
64  if (!IsValid(field))
65  return 0;
66 
67  ULong_t fieldLength = (ULong_t) PQfsize(fResult, field);
68 
69  if (!fieldLength) {
70  Error("GetFieldLength", "cannot get field length");
71  return 0;
72  }
73 
74  return fieldLength;
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Get specified field from row (0 <= field < GetFieldCount()).
79 
80 const char *TPgSQLRow::GetField(Int_t field)
81 {
82  if (!IsValid(field))
83  return 0;
84 
85  return PQgetvalue(fResult, fRowNum, field);
86 }
Bool_t IsValid(Int_t field)
Check if row is open and field index within range.
Definition: TPgSQLRow.cxx:50
TPgSQLRow(void *result, ULong_t rowHandle)
Single row of query result.
Definition: TPgSQLRow.cxx:20
void Close(Option_t *opt="") final
Close row.
Definition: TPgSQLRow.cxx:38
const char Option_t
Definition: RtypesCore.h:62
~TPgSQLRow()
Destroy row object.
Definition: TPgSQLRow.cxx:29
ULong_t GetFieldLength(Int_t field) final
Get length in bytes of specified field.
Definition: TPgSQLRow.cxx:62
PGresult * fResult
Definition: TPgSQLRow.h:28
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:887
const char * GetField(Int_t field) final
Get specified field from row (0 <= field < GetFieldCount()).
Definition: TPgSQLRow.cxx:80
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define ClassImp(name)
Definition: Rtypes.h:365
unsigned long ULong_t
Definition: RtypesCore.h:51
const Bool_t kTRUE
Definition: RtypesCore.h:87
ULong_t fRowNum
Definition: TPgSQLRow.h:29