00001 // @(#)root/pgsql:$Id: TPgSQLRow.cxx 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: g.p.ciceri <gp.ciceri@acm.org> 01/06/2001 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #include "TPgSQLRow.h" 00013 00014 00015 ClassImp(TPgSQLRow) 00016 00017 //______________________________________________________________________________ 00018 TPgSQLRow::TPgSQLRow(void *res, ULong_t rowHandle) 00019 { 00020 // Single row of query result. 00021 00022 fResult = (PGresult *) res; 00023 fRowNum = (ULong_t) rowHandle; 00024 } 00025 00026 //______________________________________________________________________________ 00027 TPgSQLRow::~TPgSQLRow() 00028 { 00029 // Destroy row object. 00030 00031 if (fRowNum) 00032 Close(); 00033 } 00034 00035 //______________________________________________________________________________ 00036 void TPgSQLRow::Close(Option_t *) 00037 { 00038 // Close row. 00039 00040 if (!fRowNum) 00041 return; 00042 00043 fResult = 0; 00044 fRowNum = 0; 00045 } 00046 00047 //______________________________________________________________________________ 00048 Bool_t TPgSQLRow::IsValid(Int_t field) 00049 { 00050 // Check if row is open and field index within range. 00051 00052 if (field < 0 || field >= (Int_t)PQnfields(fResult)) { 00053 Error("IsValid", "field index out of bounds"); 00054 return kFALSE; 00055 } 00056 return kTRUE; 00057 } 00058 00059 //______________________________________________________________________________ 00060 ULong_t TPgSQLRow::GetFieldLength(Int_t field) 00061 { 00062 // Get length in bytes of specified field. 00063 00064 if (!IsValid(field)) 00065 return 0; 00066 00067 ULong_t fieldLength = (ULong_t) PQfsize(fResult, field); 00068 00069 if (!fieldLength) { 00070 Error("GetFieldLength", "cannot get field length"); 00071 return 0; 00072 } 00073 00074 return fieldLength; 00075 } 00076 00077 //______________________________________________________________________________ 00078 const char *TPgSQLRow::GetField(Int_t field) 00079 { 00080 // Get specified field from row (0 <= field < GetFieldCount()). 00081 00082 if (!IsValid(field)) 00083 return 0; 00084 00085 return PQgetvalue(fResult, fRowNum, field); 00086 }