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
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public int getInt(int columnIndex) throws SQLException {
return switch (val) {
case Value.Null n -> 0;
case Value.Integer i -> (int) i.value();
case Value.Float f -> (int) f.value();
case Value.Float f -> (int) (long) f.value();
case Value.Text t -> (int) parseSqliteLong(t.value());
case Value.Blob b -> (int) parseSqliteLong(blobAsText(b));
};
Expand All @@ -474,7 +474,7 @@ public float getFloat(int columnIndex) throws SQLException {
Value val = getCurrentValue(columnIndex);
return switch (val) {
case Value.Null n -> 0.0F;
case Value.Integer i -> (float) i.value();
case Value.Integer i -> (float) (double) i.value();
case Value.Float f -> (float) f.value();
case Value.Text t -> (float) parseSqliteDouble(t.value());
case Value.Blob b -> (float) parseSqliteDouble(blobAsText(b));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ void realStorageTruncatesForIntegralGettersAndKeepsFractionForFloatingGetters()
assertNumeric(rs, 1, 1, 1L, 1.9f, 1.9);
}

@Test
void realStorageWrapsToIntThroughInt64LikeSqlite() throws SQLException {
LibsqlResultSet rs = resultSet(new Value.Float(3e9), new Value.Float(-3e9));

assertThat(rs.next()).isTrue();
assertThat(rs.getInt(1)).isEqualTo(-1294967296);
assertThat(rs.getObject(1, Integer.class)).isEqualTo(-1294967296);
assertThat(rs.getInt(2)).isEqualTo(1294967296);
}

@Test
void getBooleanOnWrappingRealIsFalse() throws SQLException {
LibsqlResultSet rs = resultSet(new Value.Float(4294967296.0));
assertThat(rs.next()).isTrue();
assertThat(rs.getBoolean(1)).isFalse();
}

@Test
void getFloatOnLargeIntegerRoundsThroughDouble() throws SQLException {
LibsqlResultSet rs = resultSet(new Value.Integer(1152921573326323713L));
assertThat(rs.next()).isTrue();
assertThat(rs.getFloat(1)).isEqualTo(1.1529215E18f);
}

@Test
void integerStorageIsReturnedUnchanged() throws SQLException {
LibsqlResultSet rs = resultSet(new Value.Integer(42));
Expand Down
Loading