#define TABLE_HPP
#include <vector>
#include <map>
#include <string>
#include "connection.hpp"
namespace sqlpp
{
class Table
{
public:
typedef std::vector<std::string> field_list;
typedef std::map<int, std::string> row_digit;
typedef std::map<std::string, std::string> row_string;
typedef row_string row;
typedef std::vector<row_digit> rows_digit;
typedef std::vector<row> rows_string;
typedef rows_string rows;
Table(const std::string& cmd, Connection& conn)throw();
Table(Connection& conn)throw();
virtual ~Table();
void download(const std::string& cmd)throw(sqlerror);
void download(void) throw(sqlerror);
void online_start(row_digit& row)throw(sqlerror);
void online_next(row_digit& row)throw(sqlerror);
bool online_is_eof(void)throw();
template<typename row_type>
std::vector<row_type>& get_rows(void)throw();
field_list& get_fields(void)throw();
const std::string& get_create_cmd(void)const throw();
const std::vector<std::string>& get_update_cmds(void)const throw();
protected:
private:
const Table& operator=(const Table& rh);
Table(const Table& rh);
void trans_to_digit(void)throw();//trans row index to digit
void trans_to_string(void)throw();//trans row index to string
//create,modify,update table sql cmd list;
std::vector<std::string> _update_cmds;
std::vector<row_digit> _rows;
std::vector<row_string> _rows_string;
field_list _fields;
std::string _create_cmd;
bool _is_row_digit;
//for online assess
unsigned int _num_fields;
MYSQL_RES* _ptr_result;
Connection& _conn;
};
/*
must this write.or g++ report error
*/
template<typename row_type>
inline std::vector<row_type>& Table::get_rows(void)throw()
{
}
template <>
inline Table::rows_digit& Table::get_rows<Table::row_digit>(void)throw()
{
if (!_is_row_digit)//now is string
{
trans_to_digit();
}
return _rows;
}
template <>
inline Table::rows& Table::get_rows<Table::row>(void)throw()
{
if (_is_row_digit)//now is digit
{
trans_to_string();
}
return _rows_string;
}
};
#endif