00001 // @(#)root/mysql:$Id: TMySQLRow.cxx 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Fons Rademakers 15/02/2000 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, 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 "TMySQLRow.h" 00013 00014 00015 ClassImp(TMySQLRow) 00016 00017 //______________________________________________________________________________ 00018 TMySQLRow::TMySQLRow(void *res, ULong_t rowHandle) 00019 { 00020 // Single row of query result. 00021 00022 fResult = (MYSQL_RES *) res; 00023 fFields = (MYSQL_ROW) rowHandle; 00024 fFieldLength = 0; 00025 } 00026 00027 //______________________________________________________________________________ 00028 TMySQLRow::~TMySQLRow() 00029 { 00030 // Destroy row object. 00031 00032 if (fFields) 00033 Close(); 00034 } 00035 00036 //______________________________________________________________________________ 00037 void TMySQLRow::Close(Option_t *) 00038 { 00039 // Close row. 00040 00041 if (!fFields) 00042 return; 00043 00044 fFields = 0; 00045 fResult = 0; 00046 fFieldLength = 0; 00047 } 00048 00049 //______________________________________________________________________________ 00050 Bool_t TMySQLRow::IsValid(Int_t field) 00051 { 00052 // Check if row is open and field index within range. 00053 00054 if (!fFields) { 00055 Error("IsValid", "row closed"); 00056 return kFALSE; 00057 } 00058 if (field < 0 || field >= (Int_t)mysql_num_fields(fResult)) { 00059 Error("IsValid", "field index out of bounds"); 00060 return kFALSE; 00061 } 00062 return kTRUE; 00063 } 00064 00065 //______________________________________________________________________________ 00066 ULong_t TMySQLRow::GetFieldLength(Int_t field) 00067 { 00068 // Get length in bytes of specified field. 00069 00070 if (!IsValid(field)) 00071 return 0; 00072 00073 if (!fFieldLength) 00074 fFieldLength = mysql_fetch_lengths(fResult); 00075 00076 if (!fFieldLength) { 00077 Error("GetFieldLength", "cannot get field length"); 00078 return 0; 00079 } 00080 00081 return fFieldLength[field]; 00082 } 00083 00084 //______________________________________________________________________________ 00085 const char *TMySQLRow::GetField(Int_t field) 00086 { 00087 // Get specified field from row (0 <= field < GetFieldCount()). 00088 00089 if (!IsValid(field)) 00090 return 0; 00091 00092 return fFields[field]; 00093 }