Skip to content

Commit

Permalink
TEIID-5615 fixing the binding of null
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jan 22, 2019
1 parent 1cd6e81 commit 2bf27bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Expand Up @@ -17,11 +17,6 @@
*/
package org.teiid.transport;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
Expand All @@ -43,6 +38,11 @@
import org.teiid.odbc.ODBCServerRemote;
import org.teiid.runtime.RuntimePlugin;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

/**
* Represents the messages going from PG ODBC Client --> back end Server
* Some parts of this code is taken from H2's implementation of ODBC
Expand Down Expand Up @@ -271,6 +271,9 @@ private Object buildBind(NullTerminatedStringDataInputStream data) throws IOExce
Object[] params = new Object[paramCount];
for (int i = 0; i < paramCount; i++) {
int paramLen = data.readInt();
if (paramLen == -1) {
continue;
}
byte[] paramdata = createByteArray(paramLen);
data.readFully(paramdata);

Expand Down
Expand Up @@ -299,6 +299,21 @@ private void connect(String database) throws SQLException {
ps.execute();
assertEquals(1, ps.getUpdateCount());
}

@Test public void testPreparedNull() throws Exception {
Statement stmt = conn.createStatement();
stmt.execute("create temporary table foobar (id integer, optional varchar);");

PreparedStatement ps = conn.prepareStatement("insert into foobar (id, optional) values (?, ?)");
ps.setInt(1, 1);
ps.setString(2, null);
ps.execute();
assertEquals(1, ps.getUpdateCount());

ResultSet rs = stmt.executeQuery("select optional from foobar");
rs.next();
assertNull(rs.getString(1));
}

@Test public void testPreparedError() throws Exception {
PreparedStatement stmt = conn.prepareStatement("select cast(? as integer)");
Expand Down

0 comments on commit 2bf27bc

Please sign in to comment.