Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1134 Map inet type to InetAddress #1527

Merged
merged 10 commits into from Jul 23, 2019
@@ -39,6 +39,8 @@
import org.postgresql.util.PSQLState;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
@@ -549,6 +551,15 @@ public Object getObject(String type, String value, byte[] byteValue) throws SQLE
}
}

if (type.equals("inet")) {
try {
return InetAddress.getByName(value);
} catch (UnknownHostException e) {
throw new PSQLException(GT.tr("IP address {0} of a host could not be determined", value),
PSQLState.CONNECTION_FAILURE, e);
}
}

PGobject obj = null;

if (LOGGER.isLoggable(Level.FINEST)) {
@@ -36,7 +36,6 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
@@ -219,6 +218,10 @@ protected Object internalGetObject(int columnIndex, Field field) throws SQLExcep
return getString(columnIndex);
}

if (type.equals("inet")) {
return getInetAddress(getPGType(columnIndex), getString(columnIndex));
}

if (type.equals("uuid")) {
if (isBinary(columnIndex)) {
return getUUID(thisRow[columnIndex - 1]);
@@ -3056,6 +3059,16 @@ protected Object getUUID(byte[] data) throws SQLException {
return new UUID(ByteConverter.int8(data, 0), ByteConverter.int8(data, 8));
}

protected Object getInetAddress(String type, String data) throws SQLException {
InetAddress inet;
try {
inet = (InetAddress) connection.getObject(type, data, null);
} catch (IllegalArgumentException iae) {
throw new PSQLException(GT.tr("Invalid Inet data."), PSQLState.INVALID_PARAMETER_VALUE, iae);
}
return inet;
}

private class PrimaryKey {
int index; // where in the result set is this primaryKey
String name; // what is the columnName of this primary Key
@@ -3310,11 +3323,7 @@ public void updateArray(String columnName, Array x) throws SQLException {
if (addressString == null) {
return null;
}
try {
return type.cast(InetAddress.getByName(((PGobject) addressString).getValue()));
} catch (UnknownHostException e) {
throw new SQLException("could not create inet address from string '" + addressString + "'");
}
return type.cast(getObject(columnIndex));
// JSR-310 support
//#if mvn.project.property.postgresql.jdbc.spec >= "JDBC4.2"
} else if (type == LocalDate.class) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.