- server: allow <db_host> to include a :port

svn path=/trunk/boinc/; revision=25405
This commit is contained in:
David Anderson 2012-03-12 21:45:29 +00:00
parent f52ce7153e
commit c703b68090
2 changed files with 22 additions and 2 deletions

View File

@ -2562,3 +2562,9 @@ Rom 12 Mar 2012
samples/vboxsamples/
vboxwrapper.cpp
David 12 Mar 2012
- server: allow <db_host> to include a :port
db/
db_base.cpp

View File

@ -37,7 +37,9 @@ DB_CONN::DB_CONN() {
mysql = 0;
}
int DB_CONN::open(char* db_name, char* db_host, char* db_user, char* dbpassword) {
int DB_CONN::open(
char* db_name, char* db_host, char* db_user, char* dbpassword
) {
mysql = mysql_init(0);
if (!mysql) return ERR_DB_CANT_INIT;
@ -68,11 +70,23 @@ int DB_CONN::open(char* db_name, char* db_host, char* db_user, char* dbpassword)
my_bool mbReconnect = 1;
mysql_options(mysql, MYSQL_OPT_RECONNECT, &mbReconnect);
}
// parse hostname:port
//
char host[256];
int port = 0;
strcpy(host, db_host);
char* p = strchr(host, ':');
if (p) {
*p = 0;
port = atoi(p+1);
}
// CLIENT_FOUND_ROWS means that the # of affected rows for an update
// is the # matched by the where, rather than the # actually changed
//
mysql = mysql_real_connect(
mysql, db_host, db_user, dbpassword, db_name, 0, 0, CLIENT_FOUND_ROWS
mysql, host, db_user, dbpassword, db_name, port, 0, CLIENT_FOUND_ROWS
);
if (mysql == 0) return ERR_DB_CANT_CONNECT;