Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -464,14 +463,15 @@ private void writeRowDescription(final Map<String, PostgresType> 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<String, PostgresType> 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.
Expand All @@ -489,16 +489,16 @@ private void writeRowDescription(final Map<String, PostgresType> 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<Result> resultSet, final Map<String, PostgresType> 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();
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.arcadedb.postgres;

import com.arcadedb.database.Binary;
import com.arcadedb.database.DatabaseFactory;

import java.nio.*;
Expand Down Expand Up @@ -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";
Expand All @@ -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) {
Expand Down
Loading