Skip to content

Commit 84f329f

Browse files
author
Bogdan Degtyariov
committed
Fixed bug #31818110 - Legacy (JDBC) Connector/C++ cannot connect to a non-default port other than 3306
1 parent 178e876 commit 84f329f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

driver/mysql_connection.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,23 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
600600
bool secure_auth= true;
601601
#endif
602602

603+
/* Port from options must be set as default for all hosts where port
604+
is not specified */
605+
{
606+
sql::ConnectOptionsMap::const_iterator it = properties.find("port");
607+
if (it != properties.end()) {
608+
try {
609+
p_i = (it->second).get< int >();
610+
} catch (sql::InvalidArgumentException&) {
611+
throw sql::InvalidArgumentException("Wrong type passed for port expected int");
612+
}
613+
if (p_i) {
614+
uri.setDefaultPort(*p_i);
615+
} else {
616+
throw sql::InvalidArgumentException("No long long value passed for port");
617+
}
618+
}
619+
}
603620

604621
/* Values set in properties individually should have priority over those
605622
we restore from Uri */

driver/mysql_uri.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool parseUri(const sql::SQLString & str, MySQL_Uri& uri)
166166
size_t sep = 0;
167167

168168
std::string name;
169-
unsigned int port = DEFAULT_TCP_PORT;
169+
unsigned int port = uri.DefaultPort();
170170

171171
if (hostname[0] == MYURI_HOST_BEGIN)
172172
{

0 commit comments

Comments
 (0)