// @(#)root/mysql:$Id: TMySQLRow.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: Fons Rademakers   15/02/2000

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TMySQLRow.h"


ClassImp(TMySQLRow)

//______________________________________________________________________________
TMySQLRow::TMySQLRow(void *res, ULong_t rowHandle)
{
   // Single row of query result.

   fResult      = (MYSQL_RES *) res;
   fFields      = (MYSQL_ROW) rowHandle;
   fFieldLength = 0;
}

//______________________________________________________________________________
TMySQLRow::~TMySQLRow()
{
   // Destroy row object.

   if (fFields)
      Close();
}

//______________________________________________________________________________
void TMySQLRow::Close(Option_t *)
{
   // Close row.
   
   if (!fFields)
      return;

   fFields      = 0;
   fResult      = 0;
   fFieldLength = 0;
}

//______________________________________________________________________________
Bool_t TMySQLRow::IsValid(Int_t field)
{
   // Check if row is open and field index within range.
   
   if (!fFields) {
      Error("IsValid", "row closed");
      return kFALSE;
   }
   if (field < 0 || field >= (Int_t)mysql_num_fields(fResult)) {
      Error("IsValid", "field index out of bounds");
      return kFALSE;
   }
   return kTRUE;
}

//______________________________________________________________________________
ULong_t TMySQLRow::GetFieldLength(Int_t field)
{
   // Get length in bytes of specified field.
   
   if (!IsValid(field))
      return 0;

   if (!fFieldLength)
      fFieldLength = mysql_fetch_lengths(fResult);
   
   if (!fFieldLength) {
      Error("GetFieldLength", "cannot get field length");
      return 0;
   }

   return fFieldLength[field];
}

//______________________________________________________________________________
const char *TMySQLRow::GetField(Int_t field)
{
   // Get specified field from row (0 <= field < GetFieldCount()).

   if (!IsValid(field))
      return 0;

   return fFields[field];
}

Last change: Wed Jun 25 08:49:43 2008
Last generated: 2008-06-25 08:49

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.