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

Various bug fixes #17

Merged
merged 6 commits into from
Sep 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.LinkedList;
Expand Down Expand Up @@ -440,6 +441,9 @@ public int[] executeBatch() throws SQLException {
private List<Long> executeParameterizedBatch() throws SQLException {
throwIfClosed();
try {
if ( parameterBatch.isEmpty() ) {
return new ArrayList<>();
}
StatementBatchResponse status = getClient().executeIndexedStatementBatch( statementId, parameterBatch, getTimeout() );
return status.getScalarsList();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

public class PolyphenyResultSetMetadata implements ResultSetMetaData {

private List<PolyphenyColumnMeta> columnMetas;
private Map<String, Integer> columnIndexes;
private final List<PolyphenyColumnMeta> columnMetas;
private final Map<String, Integer> columnIndexes;


public PolyphenyResultSetMetadata( List<PolyphenyColumnMeta> columnMetas ) {
this.columnMetas = columnMetas;
this.columnIndexes = this.columnMetas.stream().collect( Collectors.toMap( PolyphenyColumnMeta::getColumnLabel, c -> c.getOrdinal() + 1, ( m, n ) -> n ) );
this.columnIndexes = this.columnMetas.stream().collect( Collectors.toMap( c -> c.getColumnName().toLowerCase(), c -> c.getOrdinal() + 1, ( m, n ) -> n ) );

}

Expand All @@ -47,7 +47,7 @@ private PolyphenyColumnMeta getMeta( int columnIndex ) throws SQLException {


public int getColumnIndexFromLabel( String columnLabel ) throws SQLException {
Integer columnIndex = columnIndexes.get( columnLabel );
Integer columnIndex = columnIndexes.get( columnLabel.toLowerCase() );
if ( columnIndex == null ) {
throw new PrismInterfaceServiceException( PrismInterfaceErrors.COLUMN_NOT_EXISTS, "Invalid column label: " + columnLabel );
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/polypheny/jdbc/types/TypedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public int asInt() throws SQLException {
if ( isNull() ) {
return 0;
}
throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER or BIGINT." );
throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER, BIGINT or DECIMAL." );
}


Expand All @@ -680,10 +680,13 @@ public long asLong() throws SQLException {
if ( integerValue != null ) {
return integerValue;
}
if ( bigDecimalValue != null ) {
return bigDecimalValue.longValue();
}
if ( isNull() ) {
return 0;
}
throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER or BIGINT." );
throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER, BIGINT or DECIMAL." );
}


Expand Down Expand Up @@ -1049,6 +1052,9 @@ public Timestamp asTimestamp() throws SQLException {

@Override
public Timestamp asTimestamp( Calendar calendar ) throws SQLException {
if ( isNull() ) {
return null;
}
return TypedValueUtils.getTimestampInCalendar( asTimestamp(), calendar );
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/polypheny/jdbc/utils/TypedValueUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public static Timestamp getTimestampInCalendar( Timestamp timestamp, Calendar ca


private static long getTimeLongInCalendar( long value, Calendar calendar ) {
if ( calendar == null ) {
return value - Calendar.getInstance().getTimeZone().getOffset( value );
}
return value - calendar.getTimeZone().getOffset( value );
}

Expand Down
12 changes: 0 additions & 12 deletions src/test/java/org/polypheny/jdbc/types/TypedValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,6 @@ public void fromAsciiStreamWithValidStream() throws SQLException {
}


@Test()
public void fromTimeWithNullCalendarThrowsException() {
assertThrows( NullPointerException.class, () -> TypedValue.fromTime( new Time( 10, 30, 0 ), null ) );
}


@Test
public void timeZoneTest() {
Time input = new Time( 123456 );
Expand Down Expand Up @@ -415,12 +409,6 @@ public void asTimeWithValidValue() throws SQLException {
}


@Test()
public void fromDateWhenNullCalendarProvidedThenThrowException() {
assertThrows( NullPointerException.class, () -> TypedValue.fromDate( new Date( 2022, 1, 1 ), null ) );
}


@Test
public void fromDateWhenValidDateAndCalendarProvided() throws SQLException {
Date date = new Date( 2021, Calendar.JANUARY, 1 );
Expand Down