Skip to content

Instantly share code, notes, and snippets.

@tomdcc
Created November 1, 2016 03:35
Show Gist options
  • Save tomdcc/52a7e572a4a8fd2082e081bf94cf2397 to your computer and use it in GitHub Desktop.
Save tomdcc/52a7e572a4a8fd2082e081bf94cf2397 to your computer and use it in GitHub Desktop.
Test case showing jOOQ 3.8.5 issue with arrays of bytea
import org.jooq.DSLContext;
import org.jooq.Record1;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import org.jooq.impl.DefaultConfiguration;
import org.jooq.util.postgres.PostgresDataType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.postgresql.ds.PGSimpleDataSource;
import java.sql.SQLException;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.sql;
import static org.junit.Assert.assertEquals;
public class Jooq385Test {
private static PGSimpleDataSource ds;
private static DSLContext dsl;
@BeforeClass
public static void setupClass() throws SQLException {
ds = new PGSimpleDataSource();
ds.setDatabaseName("jooq_test");
dsl = DSL.using(new DefaultConfiguration().set(SQLDialect.POSTGRES).set(ds));
}
@Test
public void testArrayOfBytea() {
Record1<byte[][]> r = dsl.select(field(sql("ARRAY[E'hi'::bytea, E'there'::bytea]"), PostgresDataType.BYTEA.getArrayDataType()))
.fetchOne();
byte[][] array = r.value1();
assertEquals("hi", new String(array[0]));
assertEquals("there", new String(array[1]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment