Skip to content

Commit

Permalink
Fix toString and fromDate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasHafner authored and vogti committed Aug 16, 2024
1 parent 4bb162e commit 89dd37a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 38 deletions.
44 changes: 7 additions & 37 deletions src/main/java/org/polypheny/jdbc/types/TypedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public static TypedValue fromDate( Date dateValue ) {


public static TypedValue fromDate( Date dateValue, Calendar calendar ) {
if ( dateValue == null ) {
return fromNull();
}
return fromDate( TypedValueUtils.getDateInCalendar( dateValue, calendar ) );
}

Expand Down Expand Up @@ -1462,44 +1465,11 @@ private static PolyInterval getInterval( ProtoInterval interval ) {

@Override
public String toString() {
if ( isSerialized ) {
deserialize();
}
switch ( valueCase ) {
case BOOLEAN:
return "" + booleanValue;
case INTEGER:
return "" + integerValue;
case LONG:
return "" + bigintValue;
case BIG_DECIMAL:
return "" + bigDecimalValue;
case FLOAT:
return "" + floatValue;
case DOUBLE:
return "" + doubleValue;
case DATE:
return "" + dateValue;
case TIME:
return "" + timeValue;
case TIMESTAMP:
return "" + timestampValue;
case INTERVAL:
return "" + otherValue;
case STRING:
return varcharValue;
case BINARY:
return "BINARY";
case NULL:
return "NULL";
case LIST:
return "LIST";
case FILE:
return "FILE";
case DOCUMENT:
return "DOCUMENT";
try {
return asString();
} catch ( SQLException e ) {
throw new RuntimeException( e );
}
return "";
}

}
3 changes: 2 additions & 1 deletion src/test/java/org/polypheny/jdbc/types/TypedValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ public void fromDateWithNullDateAndCalendarProvided() {
Calendar calendar = Calendar.getInstance();
calendar.set( 2022, Calendar.JANUARY, 1 );

assertThrows( NullPointerException.class, () -> TypedValue.fromDate( null, calendar ) );
TypedValue value = TypedValue.fromDate( null, calendar );
assertTrue( value.isNull() );
}


Expand Down

0 comments on commit 89dd37a

Please sign in to comment.