Commit a9039660 authored by Pavel Vainerman's avatar Pavel Vainerman

(SQLxxxInterface): функции as_xxx() внесены в классы xxResult.

parent 5d5064d2
...@@ -173,39 +173,39 @@ string MySQLInterface::addslashes( const string& str ) ...@@ -173,39 +173,39 @@ string MySQLInterface::addslashes( const string& str )
return tmp.str(); return tmp.str();
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int num_cols( MySQLResult::iterator& it ) int MySQLResult::num_cols( const MySQLResult::iterator& it )
{ {
return it->size(); return it->size();
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int as_int( MySQLResult::iterator& it, int col ) int MySQLResult::as_int( const MySQLResult::iterator& it, int col )
{ {
// if( col<0 || col >it->size() ) // if( col<0 || col >it->size() )
// return 0; // return 0;
return uni_atoi( (*it)[col] ); return uni_atoi( (*it)[col] );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
double as_double( MySQLResult::iterator& it, int col ) double as_double( const MySQLResult::iterator& it, int col )
{ {
return atof( ((*it)[col]).c_str() ); return atof( ((*it)[col]).c_str() );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
string as_string( MySQLResult::iterator& it, int col ) string MySQLResult::as_string( const MySQLResult::iterator& it, int col )
{ {
return ((*it)[col]); return ((*it)[col]);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int as_int( MySQLResult::COL::iterator& it ) int MySQLResult::as_int( const MySQLResult::COL::iterator& it )
{ {
return uni_atoi( (*it) ); return uni_atoi( (*it) );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
double as_double( MySQLResult::COL::iterator& it ) double MySQLResult::as_double( const MySQLResult::COL::iterator& it )
{ {
return atof( (*it).c_str() ); return atof( (*it).c_str() );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
std::string as_string( MySQLResult::COL::iterator& it ) std::string MySQLResult::as_string( const MySQLResult::COL::iterator& it )
{ {
return (*it); return (*it);
} }
......
...@@ -116,20 +116,23 @@ class MySQLResult ...@@ -116,20 +116,23 @@ class MySQLResult
return res.empty(); return res.empty();
} }
// ----------------------------------------------------------------------------
// ROW
static int as_int( const MySQLResult::iterator&, int col );
static double as_double( const MySQLResult::iterator&, int col );
static std::string as_string( const MySQLResult::iterator&, int col );
// ----------------------------------------------------------------------------
// COL
static int num_cols( const MySQLResult::iterator& );
static int as_int( const MySQLResult::COL::iterator& );
static double as_double(const MySQLResult::COL::iterator& );
static std::string as_string( const MySQLResult::COL::iterator& );
// ----------------------------------------------------------------------------
protected: protected:
ROW res; ROW res;
}; };
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
int num_cols( MySQLResult::iterator& );
// ROW
int as_int( MySQLResult::iterator&, int col );
double as_double( MySQLResult::iterator&, int col );
std::string as_text( MySQLResult::iterator&, int col );
// ----------------------------------------------------------------------------
// COL
int as_int( MySQLResult::COL::iterator& );
double as_double( MySQLResult::COL::iterator& );
std::string as_string( MySQLResult::COL::iterator& );
// ----------------------------------------------------------------------------
#endif #endif
...@@ -41,7 +41,7 @@ int main(int argc, char** argv) ...@@ -41,7 +41,7 @@ int main(int argc, char** argv)
MySQLResult::COL col(*it); MySQLResult::COL col(*it);
for( MySQLResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ ) for( MySQLResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ )
cout << as_string(cit) << "(" << as_double(cit) << ") | "; cout << MySQLResult::as_string(cit) << "(" << MySQLResult::as_double(cit) << ") | ";
cout << endl; cout << endl;
} }
......
...@@ -152,45 +152,45 @@ bool PostgreSQLInterface::isConnection() ...@@ -152,45 +152,45 @@ bool PostgreSQLInterface::isConnection()
return (db && db->is_open()); return (db && db->is_open());
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int num_cols( PostgreSQLResult::iterator& it ) int PostgreSQLResult::num_cols( const PostgreSQLResult::iterator& it )
{ {
return it->size(); return it->size();
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int as_int( PostgreSQLResult::iterator& it, int col ) int PostgreSQLResult::as_int( const PostgreSQLResult::iterator& it, int col )
{ {
// if( col<0 || col >it->size() ) // if( col<0 || col >it->size() )
// return 0; // return 0;
return uni_atoi( (*it)[col] ); return uni_atoi( (*it)[col] );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
double as_double( PostgreSQLResult::iterator& it, int col ) double PostgreSQLResult::as_double( const PostgreSQLResult::iterator& it, int col )
{ {
return atof( ((*it)[col]).c_str() ); return atof( ((*it)[col]).c_str() );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
string as_string( PostgreSQLResult::iterator& it, int col ) std::string PostgreSQLResult::as_string( const PostgreSQLResult::iterator& it, int col )
{ {
return ((*it)[col]); return ((*it)[col]);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int as_int( PostgreSQLResult::COL::iterator& it ) int PostgreSQLResult::as_int( const PostgreSQLResult::COL::iterator& it )
{ {
return uni_atoi( (*it) ); return uni_atoi( (*it) );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
double as_double( PostgreSQLResult::COL::iterator& it ) double PostgreSQLResult::as_double( const PostgreSQLResult::COL::iterator& it )
{ {
return atof( (*it).c_str() ); return atof( (*it).c_str() );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
std::string as_string( PostgreSQLResult::COL::iterator& it ) std::string PostgreSQLResult::as_string( const PostgreSQLResult::COL::iterator& it )
{ {
return (*it); return (*it);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
#if 0 #if 0
PostgreSQLResult::COL get_col( PostgreSQLResult::ROW::iterator& it ) PostgreSQLResult::COL PostgreSQLResult::get_col( const PostgreSQLResult::ROW::iterator& it )
{ {
return (*it); return (*it);
} }
......
...@@ -78,21 +78,24 @@ class PostgreSQLResult ...@@ -78,21 +78,24 @@ class PostgreSQLResult
return row.empty(); return row.empty();
} }
// ----------------------------------------------------------------------------
// ROW
static int as_int( const PostgreSQLResult::iterator&, int col );
static double as_double( const PostgreSQLResult::iterator&, int col );
static std::string as_string( const PostgreSQLResult::iterator&, int col );
// ----------------------------------------------------------------------------
// COL
static int num_cols( const PostgreSQLResult::iterator& );
static int as_int( const PostgreSQLResult::COL::iterator& );
static double as_double( const PostgreSQLResult::COL::iterator& );
static std::string as_string(const PostgreSQLResult::COL::iterator& );
//----------------------------------------------------------------------------
protected: protected:
ROW row; ROW row;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int num_cols( PostgreSQLResult::iterator& );
// ROW
int as_int( PostgreSQLResult::iterator&, int col );
double as_double( PostgreSQLResult::iterator&, int col );
std::string as_text( PostgreSQLResult::iterator&, int col );
// ----------------------------------------------------------------------------
// COL
int as_int( PostgreSQLResult::COL::iterator& );
double as_double( PostgreSQLResult::COL::iterator& );
std::string as_string( PostgreSQLResult::COL::iterator& );
//----------------------------------------------------------------------------
#endif #endif
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
...@@ -41,7 +41,7 @@ int main(int argc, char** argv) ...@@ -41,7 +41,7 @@ int main(int argc, char** argv)
PostgreSQLResult::COL col(*it); PostgreSQLResult::COL col(*it);
for( PostgreSQLResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ ) for( PostgreSQLResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ )
cout << as_string(cit) << "(" << as_double(cit) << ") | "; cout << PostgreSQLResult::as_string(cit) << "(" << PostgreSQLResult::as_double(cit) << ") | ";
cout << endl; cout << endl;
} }
......
...@@ -201,45 +201,45 @@ bool SQLiteInterface::isConnection() ...@@ -201,45 +201,45 @@ bool SQLiteInterface::isConnection()
return connected; return connected;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int num_cols( SQLiteResult::iterator& it ) int SQLiteResult::num_cols( const SQLiteResult::iterator& it )
{ {
return it->size(); return it->size();
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int as_int( SQLiteResult::iterator& it, int col ) int SQLiteResult::as_int( const SQLiteResult::iterator& it, int col )
{ {
// if( col<0 || col >it->size() ) // if( col<0 || col >it->size() )
// return 0; // return 0;
return uni_atoi( (*it)[col] ); return uni_atoi( (*it)[col] );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
double as_double( SQLiteResult::iterator& it, int col ) double SQLiteResult::as_double( const SQLiteResult::iterator& it, int col )
{ {
return atof( ((*it)[col]).c_str() ); return atof( ((*it)[col]).c_str() );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
string as_string( SQLiteResult::iterator& it, int col ) string SQLiteResult::as_string( const SQLiteResult::iterator& it, int col )
{ {
return ((*it)[col]); return ((*it)[col]);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
int as_int( SQLiteResult::COL::iterator& it ) int SQLiteResult::as_int( const SQLiteResult::COL::iterator& it )
{ {
return uni_atoi( (*it) ); return uni_atoi( (*it) );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
double as_double( SQLiteResult::COL::iterator& it ) double SQLiteResult::as_double( const SQLiteResult::COL::iterator& it )
{ {
return atof( (*it).c_str() ); return atof( (*it).c_str() );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
std::string as_string( SQLiteResult::COL::iterator& it ) std::string SQLiteResult::as_string( const SQLiteResult::COL::iterator& it )
{ {
return (*it); return (*it);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
#if 0 #if 0
SQLiteResult::COL get_col( SQLiteResult::ROW::iterator& it ) SQLiteResult::COL SQLiteResult::get_col( SQLiteResult::ROW::iterator& it )
{ {
return (*it); return (*it);
} }
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
cout << "ROW: "; cout << "ROW: ";
SQLiteResult::COL col(*it); SQLiteResult::COL col(*it);
for( SQLiteResult::COL::iterator cit = it->begin(); cit!=it->end(); cit++ ) for( SQLiteResult::COL::iterator cit = it->begin(); cit!=it->end(); cit++ )
cout << as_string(cit) << "(" << as_double(cit) << ") | "; cout << SQLiteResult::as_string(cit) << "(" << SQLiteResult::as_double(cit) << ") | ";
cout << endl; cout << endl;
} }
...@@ -172,21 +172,24 @@ class SQLiteResult ...@@ -172,21 +172,24 @@ class SQLiteResult
return res.empty(); return res.empty();
} }
// ----------------------------------------------------------------------------
static int num_cols( const SQLiteResult::iterator& );
// ROW
static int as_int( const SQLiteResult::iterator&, int col );
static double as_double( const SQLiteResult::iterator&, int col );
static std::string as_string( const SQLiteResult::iterator&, int col );
// ----------------------------------------------------------------------------
// COL
static int as_int( const SQLiteResult::COL::iterator& );
static double as_double( const SQLiteResult::COL::iterator& );
static std::string as_string( const SQLiteResult::COL::iterator& );
protected: protected:
ROW res; ROW res;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int num_cols( SQLiteResult::iterator& );
// ROW
int as_int( SQLiteResult::iterator&, int col );
double as_double( SQLiteResult::iterator&, int col );
std::string as_string( SQLiteResult::iterator&, int col );
// ----------------------------------------------------------------------------
// COL
int as_int( SQLiteResult::COL::iterator& );
double as_double( SQLiteResult::COL::iterator& );
std::string as_string( SQLiteResult::COL::iterator& );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#endif #endif
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
...@@ -35,7 +35,7 @@ int main(int argc, char** argv) ...@@ -35,7 +35,7 @@ int main(int argc, char** argv)
SQLiteResult::COL col(*it); SQLiteResult::COL col(*it);
for( SQLiteResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ ) for( SQLiteResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ )
cout << as_string(cit) << "(" << as_double(cit) << ") | "; cout << SQLiteResult::as_string(cit) << "(" << SQLiteResult::as_double(cit) << ") | ";
cout << endl; cout << endl;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment