Main | License | Installation | FAQ | Screenshots | Contact | Links | Sf.net | Freshmeat.net | KDE-Apps.org
Requirements | Design | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

MySQLNetwork Class Reference
[MySQL C++ Wrappers]

#include <mysqlNetwork.hpp>

Inheritance diagram for MySQLNetwork:

Inheritance graph
[legend]

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

Detailed Description

Store information for connecting to a MySQL server over the network.
Date:
Sun Feb 19 2006
Author:
Jan Wedekind (wedesoft@users.sourceforge.net)

Definition at line 27 of file mysqlNetwork.hpp.


Constructor & Destructor Documentation

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.

Parameters:
_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 }


Member Function Documentation

const std::string& MySQLNetwork::getServerName ( void   )  const [inline]

Definition at line 44 of file mysqlNetwork.hpp.

References serverName.

00044 { return serverName; }

int MySQLNetwork::getPortNumber ( void   )  const [inline]

Definition at line 46 of file mysqlNetwork.hpp.

References portNumber.

00046 { return portNumber; }

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 };


Field Documentation

std::string MySQLNetwork::serverName [protected]

Definition at line 51 of file mysqlNetwork.hpp.

Referenced by getServerName().

int MySQLNetwork::portNumber [protected]

Definition at line 53 of file mysqlNetwork.hpp.

Referenced by getPortNumber().


The documentation for this class was generated from the following files:

anymeal 0.30 - recipe management software - Make the most of your food! - © Jan Wedekind Sun Sep 14 16:01:29 2008 - GNU Free Documentation License