#include <mysqlSocket.hpp>

Public Member Functions | |
| MySQLSocket (const std::string &_userName, const std::string &_passWord, const std::string &_socketName, MySQLDaemonPtr _daemon=MySQLDaemonPtr()) throw (Error) | |
| virtual | ~MySQLSocket (void) |
| Destructor. | |
| const std::string & | getSocketName (void) const |
| virtual void | connect (const std::string &database, MYSQL *m) throw (Error) |
| MySQLDaemonPtr | getDaemon (void) const |
Protected Attributes | |
| std::string | socketName |
| MySQLDaemonPtr | daemon |
Store information for connecting to MySQL using a file-socket.
Definition at line 28 of file mysqlSocket.hpp.
| MySQLSocket::MySQLSocket | ( | const std::string & | _userName, | |
| const std::string & | _passWord, | |||
| const std::string & | _socketName, | |||
| MySQLDaemonPtr | _daemon = MySQLDaemonPtr() | |||
| ) | throw (Error) |
Constructor. Store information about the file-socket and the MySQL server.
| _userName | Name of database user. | |
| _passWord | Password of database-user. | |
| _socketName | Name of the socket for connecting to the server (for example /var/lib/mysql/mysql.sock). |
Definition at line 23 of file mysqlSocket.cpp.
00027 : 00028 MySQLServer( _userName, _passWord ), socketName(_socketName), 00029 daemon(_daemon) 00030 { 00031 connect( "", &connection ); }
| MySQLSocket::~MySQLSocket | ( | void | ) | [virtual] |
Destructor.
Definition at line 84 of file mysqlSocket.cpp.
References MySQLServer::connection.
00085 { 00086 mysql_close( &connection ); 00087 }
| void MySQLSocket::connect | ( | const std::string & | database, | |
| MYSQL * | m | |||
| ) | throw (Error) [virtual] |
Implements MySQLServer.
Definition at line 33 of file mysqlSocket.cpp.
References timer::elapsed(), and 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 MYSQL *result = NULL; 00045 timer t; 00046 00047 // Loop if the mysql-daemon was started by this program (server may not 00048 // be up yet in this case). 00049 do { 00050 // Specifying an alternative port will lead to a crash in the library :-( 00051 result = mysql_real_connect( m, NULL, 00052 userName.c_str(), 00053 passWord.empty() ? (const char *)NULL : 00054 passWord.c_str(), 00055 database.empty() ? (const char *)NULL : 00056 database.c_str(), 00057 0, socketName.c_str(), 0 ); 00058 if ( result == NULL ) { 00059 if ( t.elapsed() > timeout || 00060 mysql_errno( m ) != CR_CONNECTION_ERROR || 00061 !daemon ) { 00062 ERRORMACRO( result != NULL, Error, , "Error connecting to socket '" 00063 << socketName << "' as user '" << userName << "' " 00064 << ( passWord.empty() ? "without" : "with" ) 00065 << " password: " << mysql_error( m ) ); 00066 } else 00067 sleep( 1 ); 00068 }; 00069 } while ( result == NULL ); 00070 00071 // Set character-set of connection to UTF-8. 00072 // If the server is older than MySQL 4.1, the resulting error-message is 00073 // being ignored. 00074 mysql_query( m, "SET NAMES utf8;" ); 00075 00076 } catch ( Error &e ) { 00077 00078 mysql_close( m ); 00079 throw e; 00080 00081 }; 00082 };
| MySQLDaemonPtr MySQLSocket::getDaemon | ( | void | ) | const [inline] |
| const std::string& MySQLSocket::getSocketName | ( | void | ) | const [inline] |
MySQLDaemonPtr MySQLSocket::daemon [protected] |
Definition at line 54 of file mysqlSocket.hpp.
Referenced by getDaemon().
std::string MySQLSocket::socketName [protected] |
Definition at line 52 of file mysqlSocket.hpp.
Referenced by getSocketName().