#include <mysql_db.h>
Inheritance diagram for DB::MySQL_ResultSet:

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_ResultSet & | operator= (const MySQL_ResultSet &old) |
Private Attributes | |
| MYSQL_RES * | res_ |
| MYSQL_ROW | row_ |
Friends | |
| class | MySQL_Connection |
Definition at line 31 of file mysql_db.h.
| DB::MySQL_ResultSet::MySQL_ResultSet | ( | MYSQL_RES * | res | ) | [inline, protected] |
| 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] |
| DB::MySQL_ResultSet::MySQL_ResultSet | ( | const MySQL_ResultSet & | old | ) | [private] |
| bool DB::MySQL_ResultSet::close | ( | void | ) | [virtual] |
Implements DB::ResultSet.
Definition at line 41 of file mysql_db.cpp.
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] |
| 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] |
| const short DB::MySQL_ResultSet::getShort | ( | const int | idx | ) | const [virtual] |
| 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] |
| void DB::MySQL_ResultSet::operator delete | ( | void * | ptr | ) |
| void * DB::MySQL_ResultSet::operator new | ( | size_t | bytes | ) |
| 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 }
friend class MySQL_Connection [friend] |
Definition at line 33 of file mysql_db.h.
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().
1.4.7