#ifndef _MIRRORDATABASE_H_ #define _MIRRORDATABASE_H_ #include #include #include #include "mysql.h" class MirrorDatabase { public: MirrorDatabase (const char *server, const char* database) throw(const char*); ~MirrorDatabase (); void BeginTransaction (); void EndTransaction (); void EndRemoteQuery (); void SetTables (const char* table, const char* local_table_name = ""); void LocalAddTable (const char* table, const char* local_table_name = ""); void LocalForceAddTable (const char* table); void LocalAddField (const char* fieldname); template void LocalAddValue (T value) { const char *delims = " \t\r\n"; std::ostringstream str_value; str_value << value; std::string new_val = str_value.str (); // trim leading whitespace std::string::size_type notwhite = new_val.find_first_not_of (delims); new_val.erase (0, notwhite); // trim trailing whitespace notwhite = new_val.find_last_not_of (delims); new_val.erase (notwhite + 1); _values.push_back (new_val); } void LocalAddRow () throw(const char*); bool LocalTableExists(const char* table); void RemoteSetQuery (const char* query_str); unsigned int RemoteGetNumberRows (); unsigned int RemoteGetNumberFields (); const char* RemoteGetFieldName (int column); const char* RemoteGetFieldValue (int column); void RemoteNextRow() throw(const char*); bool RemoteIsValueNum(int column); void RemoteExecute () throw(const char*); private: bool SameSchemas(const char* table); MYSQL *_remote_SQL; MYSQL_RES *_remote_result; MYSQL_ROW _remote_row; MYSQL_FIELD *_remote_fields; std::string _remote_query; std::string _error_msg; std::string _remote_table; std::string _local_table; std::vector _fields; std::vector _values; }; #endif