Skip to content

Commit

Permalink
CONJ-883 - mandatory hostname when using unix socket
Browse files Browse the repository at this point in the history
when using unix socket, hostname is now not mandatory, permitting connection string like `jdbc:mariadb:///?user=myUser&password=MyPwd&localSocket=/path`
  • Loading branch information
rusher committed May 11, 2021
1 parent 6bffa7b commit 2150bfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ private static Socket createSocket(final String host, final int port, final Opti

if (!socket.isConnected()) {
InetSocketAddress sockAddr =
options.pipe == null ? new InetSocketAddress(host, port) : null;
(options.pipe == null && options.localSocket == null)
? new InetSocketAddress(host, port)
: null;
socket.connect(sockAddr, options.connectTimeout);
}
return socket;
Expand Down Expand Up @@ -1357,7 +1359,7 @@ public void connectWithoutProxy() throws SQLException {

// CONJ-293 : handle name-pipe without host
if (hosts.isEmpty()) {
if (options.pipe != null) {
if (options.pipe != null || options.localSocket != null) {
try {
createConnection(null, username);
return;
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/mariadb/jdbc/DriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,11 @@ public void localSocket() throws Exception {
st.execute("CREATE USER testSocket@'localhost' IDENTIFIED BY 'MySup5%rPassw@ord'");
st.execute("GRANT SELECT on *.* to testSocket@'localhost' IDENTIFIED BY 'MySup5%rPassw@ord'");
st.execute("FLUSH PRIVILEGES");
String connString = connU + "?user=testSocket&password=MySup5%rPassw@ord&localSocket=" + path;
String connString =
"jdbc:mariadb:///"
+ database
+ "?user=testSocket&password=MySup5%rPassw@ord&localSocket="
+ path;

try (Connection connection = openConnection(connString, null)) {
rs = connection.createStatement().executeQuery("select 1");
Expand Down

0 comments on commit 2150bfe

Please sign in to comment.