sqlresult.cpp

Go to the documentation of this file.
00001 /*
00002 _______________________________________________________________________________
00003 
00004                                  SqlWrapperXX
00005 
00006 -------------------------------------------------------------------------------
00007 Copyright (c) 2007 Kai Braaten
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
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 &param )
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 }

Generated on Sat Aug 18 16:21:44 2007 for SqlWrapperXX by  doxygen 1.5.0