DB::MySQL_ResultSet Class Reference

#include <mysql_db.h>

Inheritance diagram for DB::MySQL_ResultSet:

DB::ResultSet List of all members.

Public Member Functions

bool close (void)
bool next (void)
unsigned long recordCount (void) const
unsigned int findColumn (const char *field) const
const char * getString (const int idx) const
const int getInteger (const int idx) const
const bool getBool (const int idx) const
const time_t getUnixTime (const int idx) const
const double getDouble (const int idx) const
const float getFloat (const int idx) const
const long getLong (const int idx) const
const short getShort (const int idx) const
void * operator new (size_t bytes)
void operator delete (void *ptr)

Protected Member Functions

 MySQL_ResultSet (MYSQL_RES *res)
 ~MySQL_ResultSet ()

Private Member Functions

 MySQL_ResultSet ()
 MySQL_ResultSet (const MySQL_ResultSet &old)
const MySQL_ResultSetoperator= (const MySQL_ResultSet &old)

Private Attributes

MYSQL_RES * res_
MYSQL_ROW row_

Friends

class MySQL_Connection

Detailed Description

Definition at line 31 of file mysql_db.h.


Constructor & Destructor Documentation

DB::MySQL_ResultSet::MySQL_ResultSet ( MYSQL_RES *  res  )  [inline, protected]

Definition at line 35 of file mysql_db.h.

00035 : res_(res) {};

DB::MySQL_ResultSet::~MySQL_ResultSet (  )  [protected]

Definition at line 33 of file mysql_db.cpp.

References res_.

00034 {
00035     if (res_) {
00036         ACE_DEBUG((LM_ERROR,"Warning ResultSet wasn't closed or deleted.\n"));
00037     }
00038 }

DB::MySQL_ResultSet::MySQL_ResultSet (  )  [inline, private]

Definition at line 38 of file mysql_db.h.

00038 {};

DB::MySQL_ResultSet::MySQL_ResultSet ( const MySQL_ResultSet old  )  [private]


Member Function Documentation

bool DB::MySQL_ResultSet::close ( void   )  [virtual]

Implements DB::ResultSet.

Definition at line 41 of file mysql_db.cpp.

References res_, and row_.

00042 {
00043     if (!res_) return (false);
00044 
00045     // eat remaining rows, if there are some
00046     while ((row_ = mysql_fetch_row(res_)) != NULL) {
00047         ;
00048     }
00049 
00050     mysql_free_result(res_);
00051     res_ = NULL;
00052     delete this;
00053 
00054     return (true);
00055 }

unsigned int DB::MySQL_ResultSet::findColumn ( const char *  field  )  const [virtual]

Implements DB::ResultSet.

Definition at line 78 of file mysql_db.cpp.

References res_.

00079 {
00080     unsigned int num_fields;
00081     unsigned int i;
00082     MYSQL_FIELD *field;
00083 
00084     num_fields = mysql_num_fields(res_);
00085     for (i=0; i<num_fields; i++) {
00086         field = mysql_fetch_field_direct(res_, i);
00087         if (ACE_OS::strcmp(field->name,fld) == 0) {
00088             return (i);
00089         }
00090     }
00091     return (i);
00092 }

const bool DB::MySQL_ResultSet::getBool ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 107 of file mysql_db.cpp.

References row_.

00108 {
00109     if (row_[idx] && row_[idx][0] == '1') {
00110         return (true);
00111     }
00112     return (false);
00113 }

const double DB::MySQL_ResultSet::getDouble ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 165 of file mysql_db.cpp.

References row_.

00166 {
00167     char *pEnd;
00168     return ((row_[idx] ? ACE_OS::strtod(row_[idx], &pEnd) : 0));
00169 }

const float DB::MySQL_ResultSet::getFloat ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 172 of file mysql_db.cpp.

References row_.

00173 {
00174     return ((row_[idx] ? atof(row_[idx]) : 0));
00175 }

const int DB::MySQL_ResultSet::getInteger ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 101 of file mysql_db.cpp.

References row_.

00102 {
00103     return ((const int) ACE_OS::atoi(row_[idx]));
00104 }

const long DB::MySQL_ResultSet::getLong ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 178 of file mysql_db.cpp.

References row_.

00179 {
00180     return ((row_[idx] ? atol(row_[idx]) : 0L));
00181 }

const short DB::MySQL_ResultSet::getShort ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 184 of file mysql_db.cpp.

References row_.

00185 {
00186     return ((short) (row_[idx] ? ACE_OS::atoi(row_[idx]) : 0));
00187 }

const char * DB::MySQL_ResultSet::getString ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 95 of file mysql_db.cpp.

References row_.

00096 {
00097     return (row_[idx]);
00098 }

const time_t DB::MySQL_ResultSet::getUnixTime ( const int  idx  )  const [virtual]

Implements DB::ResultSet.

Definition at line 116 of file mysql_db.cpp.

References row_.

00117 {
00118     struct tm tmp;
00119     // ACE_DEBUG((LM_DEBUG, ACE_TEXT("Read UnixTime: %s\n"), row_[idx]));
00120 
00121     if (row_[idx]) {
00122         // switch on the type of field
00123         // Basically, there are two types of returns I've seen
00124         // 1. has a hypen and is fully parseable
00125         // 2. has no hypen and is an older timestamp field
00126         // The others are raw DATE or TIME
00127         int Ypos = 0;
00128         int Mpos = 4;
00129         int Dpos = 6;
00130         int hpos = 8;
00131         int mpos = 10;
00132         int spos = 12;
00133         if (strchr(row_[idx], '-') != NULL) {
00134             ++Mpos;
00135             Dpos = 8;
00136             hpos = 11;
00137             mpos = 14;
00138             spos = 17;
00139         }
00140         tmp.tm_wday = 0;
00141         tmp.tm_yday = 0;
00142         tmp.tm_isdst = 0;
00143         tmp.tm_year = (((row_[idx][Ypos] - '0') * 1000) + ((row_[idx][Ypos+1] - '0') * 100) + ((row_[idx][Ypos+2] - '0') * 10) + (row_[idx][Ypos+3] - '0')) - 1900;
00144         tmp.tm_mon = (((row_[idx][Mpos] - '0') * 10) + (row_[idx][Mpos+1] - '0')) - 1; /* 0 - 11 */
00145         tmp.tm_mday = (((row_[idx][Dpos] - '0') * 10) + (row_[idx][Dpos+1] - '0')); /* 1 - 31 */
00146         tmp.tm_hour = (((row_[idx][hpos] - '0') * 10) + (row_[idx][hpos+1] - '0')) - 1; /* 0 - 23 */
00147         tmp.tm_min = (((row_[idx][mpos] - '0') * 10) + (row_[idx][mpos+1] - '0')); /* 0-59 */
00148         tmp.tm_sec = (((row_[idx][spos] - '0') * 10) + (row_[idx][spos+1] - '0')); /* 0-59 */
00149 
00150         /*
00151         ACE_DEBUG((LM_DEBUG, ACE_TEXT("y=%d m=%d d=%d h=%d m=%d s=%d\n"), 
00152                    tmp.tm_year,
00153                    tmp.tm_mon,
00154                    tmp.tm_mday,
00155                    tmp.tm_hour,
00156                    tmp.tm_min,
00157                    tmp.tm_sec));
00158         */
00159         return (mktime(&tmp));
00160     }
00161     return (0);
00162 }

bool DB::MySQL_ResultSet::next ( void   )  [virtual]

Implements DB::ResultSet.

Definition at line 58 of file mysql_db.cpp.

References res_, and row_.

00059 {
00060     row_ = mysql_fetch_row(res_);
00061     return ((row_ != NULL ? true : false));
00062 }

void DB::MySQL_ResultSet::operator delete ( void *  ptr  ) 

Definition at line 209 of file mysql_db.cpp.

00210 {
00211   delete [] static_cast <char *> (ptr);
00212 }

void * DB::MySQL_ResultSet::operator new ( size_t  bytes  ) 

Definition at line 190 of file mysql_db.cpp.

00191 {
00192   return (::new char[bytes]);
00193 }

const MySQL_ResultSet& DB::MySQL_ResultSet::operator= ( const MySQL_ResultSet old  )  [private]

unsigned long DB::MySQL_ResultSet::recordCount ( void   )  const [virtual]

Implements DB::ResultSet.

Definition at line 65 of file mysql_db.cpp.

References res_.

00066 {
00067     /* NOTE: This call ALWAYS fails because mysql_use_result
00068        is used, UNTIL all rows have been read. This is documented
00069        in the MySQL manual.
00070 
00071        I still opt for using mysql_use_result as it reduces
00072        the traffic/memory requirements on the client side.
00073     */
00074     return ((unsigned long) mysql_num_rows(res_));
00075 }


Friends And Related Function Documentation

friend class MySQL_Connection [friend]

Definition at line 33 of file mysql_db.h.


Member Data Documentation

MYSQL_RES* DB::MySQL_ResultSet::res_ [private]

Definition at line 72 of file mysql_db.h.

Referenced by close(), findColumn(), next(), recordCount(), and ~MySQL_ResultSet().

MYSQL_ROW DB::MySQL_ResultSet::row_ [private]

Definition at line 73 of file mysql_db.h.

Referenced by close(), getBool(), getDouble(), getFloat(), getInteger(), getLong(), getShort(), getString(), getUnixTime(), and next().


The documentation for this class was generated from the following files:
Generated on Tue Apr 24 18:59:42 2007 for DbAbstract by  doxygen 1.4.7