diff --git a/e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java b/e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java index 51fc44c83d..fc38ae8bff 100644 --- a/e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java +++ b/e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java @@ -23,8 +23,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.sql.*; -import java.util.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; import static org.assertj.core.api.Assertions.assertThat; @@ -67,6 +71,19 @@ void simpleSQLQuery() throws Exception { } } + @Test + void bigResultSetSQLQuery() throws Exception { + + try (final Statement st = conn.createStatement()) { + + try (final ResultSet rs = st.executeQuery("SELECT * FROM Beer limit -1")) { + while (rs.next()) { + assertThat(rs.getString("name")).isNotBlank(); + } + } + } + } + @Test void simpleGremlinQuery() throws Exception { try (final Statement st = conn.createStatement()) { diff --git a/postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java b/postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java index c9368c4dd4..8461084c53 100755 --- a/postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java +++ b/postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java @@ -20,6 +20,7 @@ import com.arcadedb.Constants; import com.arcadedb.GlobalConfiguration; +import com.arcadedb.database.Binary; import com.arcadedb.database.Database; import com.arcadedb.database.DatabaseContext; import com.arcadedb.database.DatabaseFactory; @@ -47,8 +48,6 @@ import java.io.EOFException; import java.io.IOException; import java.net.Socket; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; @@ -464,14 +463,15 @@ private void writeRowDescription(final Map columns) { if (columns == null) return; - final ByteBuffer bufferDescription = ByteBuffer.allocate(64 * 1024).order(ByteOrder.BIG_ENDIAN); +// final ByteBuffer bufferDescription = ByteBuffer.allocate(64 * 1024).order(ByteOrder.BIG_ENDIAN); + final Binary bufferDescription = new Binary(); for (final Map.Entry col : columns.entrySet()) { final String columnName = col.getKey(); final PostgresType columnType = col.getValue(); - bufferDescription.put(columnName.getBytes(DatabaseFactory.getDefaultCharset()));//The field name. - bufferDescription.put((byte) 0); + bufferDescription.putByteArray(columnName.getBytes(DatabaseFactory.getDefaultCharset()));//The field name. + bufferDescription.putByte((byte) 0); bufferDescription.putInt( 0); //If the field can be identified as a column of a specific table, the object ID of the table; otherwise zero. @@ -489,16 +489,16 @@ private void writeRowDescription(final Map columns) { bufferDescription.flip(); writeMessage("row description", () -> { channel.writeUnsignedShort((short) columns.size()); - channel.writeBuffer(bufferDescription); - }, 'T', 4 + 2 + bufferDescription.limit()); + channel.writeBuffer(bufferDescription.getByteBuffer()); + }, 'T', 4 + 2 + bufferDescription.capacity()); } private void writeDataRows(final List resultSet, final Map columns) throws IOException { if (resultSet.isEmpty()) return; - final ByteBuffer bufferData = ByteBuffer.allocate(128 * 1024).order(ByteOrder.BIG_ENDIAN); - final ByteBuffer bufferValues = ByteBuffer.allocate(128 * 1024).order(ByteOrder.BIG_ENDIAN); + final Binary bufferData = new Binary(); + final Binary bufferValues = new Binary(); for (final Result row : resultSet) { bufferData.clear(); @@ -546,19 +546,19 @@ else if (record instanceof Edge) } bufferValues.flip(); - bufferData.put((byte) 'D'); - bufferData.putInt(4 + bufferValues.limit()); - bufferData.put(bufferValues); + bufferData.putByte((byte) 'D'); + bufferData.putInt(4 + bufferValues.getByteBuffer().limit()); + bufferData.putBuffer(bufferValues.getByteBuffer()); bufferData.flip(); - channel.writeBuffer(bufferData); + channel.writeBuffer(bufferData.getByteBuffer()); } channel.flush(); if (DEBUG) LogManager.instance().log(this, Level.INFO, "PSQL:-> %d row data (%s) (thread=%s)", resultSet.size(), - FileUtils.getSizeAsString(bufferData.limit()), Thread.currentThread().getId()); + FileUtils.getSizeAsString(bufferData.getByteBuffer().limit()), Thread.currentThread().getId()); } private void bindCommand() { diff --git a/postgresw/src/main/java/com/arcadedb/postgres/PostgresType.java b/postgresw/src/main/java/com/arcadedb/postgres/PostgresType.java index 0cb73d4732..de48874c1d 100644 --- a/postgresw/src/main/java/com/arcadedb/postgres/PostgresType.java +++ b/postgresw/src/main/java/com/arcadedb/postgres/PostgresType.java @@ -18,6 +18,7 @@ */ package com.arcadedb.postgres; +import com.arcadedb.database.Binary; import com.arcadedb.database.DatabaseFactory; import java.nio.*; @@ -110,7 +111,7 @@ public enum PostgresType { // } // } - public void serializeAsText(final long code, final ByteBuffer typeBuffer, Object value) { + public void serializeAsText(final long code, final Binary typeBuffer, Object value) { if (value == null) { if (code == BOOLEAN.code) value = "0"; @@ -122,7 +123,7 @@ public void serializeAsText(final long code, final ByteBuffer typeBuffer, Object final byte[] str = value.toString().getBytes(DatabaseFactory.getDefaultCharset()); typeBuffer.putInt(str.length); - typeBuffer.put(str); + typeBuffer.putByteArray(str); } public static Object deserialize(final long code, final int formatCode, final byte[] valueAsBytes) {