00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "sqlresult.hpp"
00030
00031 SqlRow::SqlRow( const int param )
00032 : _columns( param )
00033 {
00034
00035 }
00036
00037 SqlRow::~SqlRow()
00038 {
00039
00040 }
00041
00042 int SqlRow::columns() const
00043 {
00044 return _columns;
00045 }
00046
00047 void SqlRow::add( const string ¶m )
00048 {
00049 data.push( param );
00050 }
00051
00052 string SqlRow::fetch()
00053 {
00054 string theData;
00055
00056 if( empty() )
00057 {
00058 theData = "";
00059 }
00060 else
00061 {
00062 theData = data.front();
00063 data.pop();
00064 }
00065
00066 return theData;
00067 }
00068
00069 bool SqlRow::empty() const
00070 {
00071 return data.empty();
00072 }
00073
00074 SqlResult::SqlResult()
00075 {
00076 }
00077
00078 SqlResult::~SqlResult()
00079 {
00080 while( !results.empty() )
00081 {
00082 SqlRow *curr = results.front();
00083 results.pop();
00084 delete curr;
00085 }
00086 }
00087
00088 void SqlResult::add( SqlRow *param )
00089 {
00090 results.push( param );
00091 }
00092
00093 int SqlResult::rows() const
00094 {
00095 return results.size();
00096 }
00097
00098 string SqlResult::fetch()
00099 {
00100 if( results.empty() )
00101 {
00102 return "";
00103 }
00104
00105 SqlRow *theRow = results.front();
00106 string theData = theRow->fetch();
00107
00108 if( theRow->empty() )
00109 {
00110 results.pop();
00111 delete theRow;
00112 }
00113
00114 return theData;
00115 }
00116
00117 int SqlResult::fetchInteger()
00118 {
00119 return static_cast< int >( strtol( fetch().c_str(), 0, 10 ) );
00120 }
00121
00122 long SqlResult::fetchLong()
00123 {
00124 return strtol( fetch().c_str(), 0, 10 );
00125 }
00126
00127 float SqlResult::fetchFloat()
00128 {
00129 return strtof( fetch().c_str(), 0 );
00130 }
00131
00132 double SqlResult::fetchDouble()
00133 {
00134 return strtod( fetch().c_str(), 0 );
00135 }
00136
00137 const char *SqlResult::fetchCstring()
00138 {
00139 return fetch().c_str();
00140 }
00141
00142 void SqlResult::skip( int times )
00143 {
00144 if( times < 0 )
00145 times = 1;
00146
00147 for( int n = 0; n < times; ++n )
00148 fetch();
00149 }
00150
00151 void SqlResult::skipRow()
00152 {
00153 if( !results.empty() )
00154 {
00155 SqlRow *theRow = results.front();
00156 results.pop();
00157 delete theRow;
00158 }
00159 }
00160
00161 bool SqlResult::empty() const
00162 {
00163 return results.empty();
00164 }