#include <mysqlNetwork.hpp>

Public Member Functions | |
| MySQLNetwork (const std::string &_userName, const std::string &_passWord, const std::string &_serverName, int _portNumber) throw (Error) | |
| virtual | ~MySQLNetwork (void) |
| const std::string & | getServerName (void) const |
| int | getPortNumber (void) const |
| virtual void | connect (const std::string &database, MYSQL *m) throw (Error) |
Protected Attributes | |
| std::string | serverName |
| int | portNumber |
Definition at line 27 of file mysqlNetwork.hpp.
| MySQLNetwork::MySQLNetwork | ( | const std::string & | _userName, | |
| const std::string & | _passWord, | |||
| const std::string & | _serverName, | |||
| int | _portNumber | |||
| ) | throw (Error) |
Constructor. Store information for connecting to a MySQL server over the network.
| _userName | Name of database user. | |
| _passWord | Password of database-user. | |
| _serverName | Name of the server hosting the database (for example localhost). | |
| _portNumber | Server-port. |
Definition at line 22 of file mysqlNetwork.cpp.
00025 : 00026 MySQLServer( _userName, _passWord ), serverName(_serverName), 00027 portNumber( _portNumber ) 00028 { 00029 connect( "", &connection ); 00030 }
| MySQLNetwork::~MySQLNetwork | ( | void | ) | [virtual] |
Definition at line 72 of file mysqlNetwork.cpp.
References MySQLServer::connection.
00073 { 00074 mysql_close( &connection ); 00075 }
| const std::string& MySQLNetwork::getServerName | ( | void | ) | const [inline] |
| int MySQLNetwork::getPortNumber | ( | void | ) | const [inline] |
| void MySQLNetwork::connect | ( | const std::string & | database, | |
| MYSQL * | m | |||
| ) | throw (Error) [virtual] |
Implements MySQLServer.
Definition at line 33 of file mysqlNetwork.cpp.
References ERRORMACRO.
00035 { 00036 mysql_init( m ); 00037 00038 const int timeout = 10;// seconds 00039 mysql_options( m, MYSQL_OPT_CONNECT_TIMEOUT, 00040 (const char *)&timeout ); 00041 00042 try { 00043 00044 // Specifying an alternative port will lead to a crash in the library :-( 00045 ERRORMACRO( mysql_real_connect( m, 00046 serverName.c_str(), userName.c_str(), 00047 passWord.empty() ? (const char *)NULL : 00048 passWord.c_str(), 00049 database.empty() ? (const char *)NULL : 00050 database.c_str(), 00051 portNumber != MYSQL_PORT ? portNumber : 0, 00052 NULL, 0 ), 00053 Error, , "Error connecting to server '" 00054 << serverName << "' as user '" << userName << "' " 00055 << ( passWord.empty() ? "without" : "with" ) << " password: " 00056 << mysql_error( m ) ); 00057 00058 // Set character-set of connection to UTF-8. 00059 // If the server is older than MySQL 4.1, the resulting error-message is 00060 // being ignored. 00061 mysql_query( m, "SET NAMES utf8;" ); 00062 00063 } catch ( Error &e ) { 00064 00065 mysql_close( m ); 00066 throw e; 00067 00068 }; 00069 };
std::string MySQLNetwork::serverName [protected] |
int MySQLNetwork::portNumber [protected] |