Author: wyoung
Date: Mon Jul 16 15:41:53 2007
New Revision: 1698
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1698&view=rev
Log:
- Swapped server and password parameters to Connection's ctor and connect()
- Added a separate port number parameter at end of these functions'
parameter lists, which overrides the optional one which may be given
as part of the server parameter.
- Together, these two changes mean these interfaces are now compile-time
compatible with v2.3 up through the port parameter. It will continue
to break if you use parameters beyond this.
Modified:
trunk/lib/connection.cpp
trunk/lib/connection.h
Modified: trunk/lib/connection.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.cpp?rev=1698&r1=1697&r2=1698&view=diff
==============================================================================
--- trunk/lib/connection.cpp (original)
+++ trunk/lib/connection.cpp Mon Jul 16 15:41:53 2007
@@ -119,14 +119,14 @@
}
-Connection::Connection(cchar* db, cchar* password, cchar* user,
- cchar* server, unsigned long client_flag) :
+Connection::Connection(cchar* db, cchar* server, cchar* user,
+ cchar* password, unsigned long client_flag, unsigned int port) :
OptionalExceptions(),
Lockable(false),
connecting_(false)
{
mysql_init(&mysql_);
- if (connect(db, password, user, server, client_flag)) {
+ if (connect(db, server, user, password, client_flag, port)) {
unlock();
copacetic_ = is_connected_ = true;
}
@@ -173,8 +173,8 @@
bool
-Connection::connect(cchar* db, cchar* password, cchar* user,
- cchar* server, unsigned long client_flag)
+Connection::connect(cchar* db, cchar* server, cchar* user,
+ cchar* password, unsigned long client_flag, unsigned int port)
{
lock();
@@ -199,7 +199,6 @@
// Figure out what the server parameter means, then establish
// the connection.
error_message_.clear();
- unsigned int port = 0;
string host, socket_name;
scoped_var_set<bool> sb(connecting_, true);
if (parse_ipc_method(server, host, port, socket_name) &&
@@ -793,12 +792,11 @@
#endif
// Lacking any better idea, it must be some kind of TCP/IP address.
- // See if it includes a trailing port or service name.
const char* colon = strchr(server, ':');
if (colon) {
- if (colon[1]) {
- // Not just a lonely trailing colon, so assume what
follows
- // the colon is of substance.
+ if ((port == 0) && colon[1]) {
+ // Not a lonely trailing colon, and we don't already
have a
+ // port, so treat what follows the colon as interesting.
const char* service = colon + 1;
if (isdigit(service[0])) {
port = atoi(service);
@@ -821,8 +819,7 @@
}
}
- // We're happy with what we found after the colon, so treat the
- // rest of the name as a host address.
+ // Everything in front of the colon is the host address.
host.assign(server, colon - server);
}
else {
Modified: trunk/lib/connection.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.h?rev=1698&r1=1697&r2=1698&view=diff
==============================================================================
--- trunk/lib/connection.h (original)
+++ trunk/lib/connection.h Mon Jul 16 15:41:53 2007
@@ -122,17 +122,21 @@
/// with a greatly simplified interface.
///
/// \param db name of database to use
- /// \param password password to use when logging in
+ /// \param server specifies the IPC method and parameters for
+ /// contacting the server; see below for details
/// \param user user name to log in under, or 0 to use the user
/// name this program is running under
- /// \param server specifies the IPC method and parameters for
- /// contacting the server; see below for details
+ /// \param password password to use when logging in
/// \param client_flag special connection flags. See MySQL C API
/// documentation for \c mysql_real_connect() for details.
+ /// \param port TCP port number MySQL server is listening on, or 0
+ /// to use default value; note that you may also give this
as
+ /// part of the \c server parameter
///
/// The server parameter can be any of several different forms:
///
- /// - \b 0: Let the MySQL C API decide how to connect. This usually
+ /// - \b 0: Server is running on the same machine as the client;
+ /// let the MySQL C API decide how to connect. This usually
/// means Unix domain sockets with the default socket name on
/// *ix systems, and shared memory on Windows. If those options
/// aren't available, it will be a TCP/IP connection to the
@@ -148,9 +152,12 @@
/// assumes the string is some kind of network address, optionally
/// followed by a colon and port. The name can be in dotted quad
/// form, a host name, or a domain name. The port can either be a
- /// TCP/IP port number or a symbolic service name.
- Connection(cchar* db, cchar* password = 0, cchar* user = 0,
- cchar* server = 0, unsigned long client_flag = 0);
+ /// TCP/IP port number or a symbolic service name. If a port or
+ /// service name is given here and a nonzero value is passed for
+ /// the \c port parameter, the latter takes precedence.
+ Connection(cchar* db, cchar* server = 0, cchar* user = 0,
+ cchar* password = 0, unsigned long client_flag = 0,
+ unsigned int port = 0);
/// \brief Establish a new connection using the same parameters as
/// an existing C API connection.
@@ -175,8 +182,9 @@
/// If you call this method on an object that is already connected
/// to a database server, the previous connection is dropped and a
/// new connection is established.
- bool connect(cchar* db, cchar* password = 0, cchar* user = 0,
- cchar* server = 0, unsigned long client_flag = 0);
+ bool connect(cchar* db, cchar* server = 0, cchar* user = 0,
+ cchar* password = 0, unsigned long client_flag = 0,
+ unsigned int port = 0);
/// \brief Close connection to MySQL server.
///
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits