On Wed, Mar 02, 2005 at 12:08:56PM +0100, Matteo Campana wrote:
Quote:
Connection con("MyDB", "127.0.0.1", "root","rootpw", 3307, 1, 30,true,"");
This fails, indicating can not connect. However, leaving the program alone
and changing the port that the mysql server runs on to 3306, does work.
It appears that the port number in the API is simply being ignored.
Is it a bug? |
Actually, I believe it is an incorrect default socket_name. According to
the C API docs, the proper default value for the mysql_real_connect()
socket_name argument is NULL, and mysql++ (and your sample code above) passes
an empty string.
Workaround:
Connection con("MyDB", "127.0.0.1", "root","rootpw", 3307, 1, 30,true,0);
Below is a patch to fix the default in mysql++, as well as an update to
the example code to allow specifying the port from the command line.
It now works fine on my machine using port 3307.
- Chris
diff -u software/mysql++/examples/util.cpp:1.2 software/mysql++/examples/util.cpp:1.3
--- software/mysql++/examples/util.cpp:1.2 Sun Feb 6 17:56:45 2005
+++ software/mysql++/examples/util.cpp Fri Mar 4 02:18:15 2005
@@ -2,6 +2,7 @@
#include <iostream>
#include <iomanip>
+#include <stdlib.h>
using namespace std;
@@ -59,8 +60,8 @@
}
if ((argc > 1) && (argv[1][0] == '-')) {
- cout << "usage: " << argv[0] << " [host] [user] [password]" <<
- endl;
+ cout << "usage: " << argv[0] <<
+ " [host] [user] [password] [port]" << endl;
cout << endl << "\tConnects to database ";
if (kdb) {
cout << '"' << kdb << '"';
@@ -87,9 +88,13 @@
else if (argc == 3) {
success = con.connect(kdb, argv[1], argv[2]);
}
- else if (argc >= 4) {
+ else if (argc == 4) {
success = con.connect(kdb, argv[1], argv[2], argv[3]);
}
+ else if (argc >= 5) {
+ success = con.real_connect(kdb, argv[1], argv[2], argv[3],
+ atoi(argv[4]));
+ }
if (!success) {
cerr << "Database connection failed." << endl << endl;
diff -u software/mysql++/lib/connection.h:1.6 software/mysql++/lib/connection.h:1.7
--- software/mysql++/lib/connection.h:1.6 Fri Mar 4 01:44:05 2005
+++ software/mysql++/lib/connection.h Fri Mar 4 02:36:26 2005
@@ -54,13 +54,13 @@
Connection(const char* db, const char* host, const char* user,
const char* passwd, uint port, my_bool compress = 0,
unsigned int connect_timeout = 60, bool te = true,
- cchar* socket_name = "", unsigned int client_flag = 0);
+ cchar* socket_name = 0, unsigned int client_flag = 0);
~Connection();
bool real_connect(cchar* db = "", cchar* host = "",
cchar* user = "", cchar* passwd = "", uint port = 0,
my_bool compress = 0, unsigned int connect_timeout = 60,
- cchar* socket_name = "", unsigned int client_flag = 0);
+ cchar* socket_name = 0, unsigned int client_flag = 0);
void close()
{
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw