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

fix: setNull for types not in java.sql.Types (e.g. uuid) #1160

Merged
merged 9 commits into from Jul 14, 2018
@@ -1232,9 +1232,25 @@ public void setClob(int i, Clob x) throws SQLException {
setLong(i, oid);
}

public void setNull(int i, int t, String s) throws SQLException {
public void setNull(int parameterIndex, int t, String typeName) throws SQLException {

if ( typeName == null ) {

This comment has been minimized.

Copy link
@vlsi

vlsi Jul 13, 2018

Member

Would you please trim spaces around typeName == null ?

setNull(parameterIndex, t);
return;
}

checkClosed();
setNull(i, t);

TypeInfo typeInfo = connection.getTypeInfo();

int oid = typeInfo.getPGType(typeName);

if (adjustIndex) {
parameterIndex--;
}

preparedParameters.setNull(parameterIndex, oid);

}

public void setRef(int i, Ref x) throws SQLException {
@@ -12,6 +12,8 @@
import static org.junit.Assert.fail;

import org.postgresql.PGStatement;
import org.postgresql.core.ServerVersion;
import org.postgresql.core.Version;
import org.postgresql.jdbc.PgStatement;
import org.postgresql.jdbc.PreferQueryMode;
import org.postgresql.test.TestUtil;
@@ -39,6 +41,7 @@
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Handler;
@@ -285,6 +288,20 @@ public void testSetNull() throws SQLException {
pstmt.executeUpdate();

pstmt.close();

assumeMinimumServerVersion(ServerVersion.v8_3);
pstmt = con.prepareStatement("select 'ok' where ?=? or (? is null) ");
pstmt.setObject(1, UUID.randomUUID(), Types.OTHER);
pstmt.setNull(2, Types.OTHER, "uuid");
pstmt.setNull(3, Types.OTHER, "uuid");
ResultSet rs = pstmt.executeQuery();

assertTrue(rs.next());
assertEquals("ok",rs.getObject(1));

rs.close();
pstmt.close();

}

@Test
@@ -560,7 +560,7 @@ public void testToString() throws SQLException {
public void nullArray() throws SQLException {
PreparedStatement ps = con.prepareStatement("INSERT INTO arrtest(floatarr) VALUES (?)");

ps.setNull(1, Types.ARRAY, "float8");
ps.setNull(1, Types.ARRAY, "float8[]");

This comment has been minimized.

Copy link
@vlsi

vlsi Jul 13, 2018

Member

This is an interesting side effect. I think it is worth including in a notable changes. So clients get prepared for "unexpected" operation of setNull (since String argument has been just ignored for ages)

ps.execute();

ps.close();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.