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