diff --git a/src/main/java/org/sqlite/jdbc3/JDBC3ResultSet.java b/src/main/java/org/sqlite/jdbc3/JDBC3ResultSet.java index c483995fd..764711289 100644 --- a/src/main/java/org/sqlite/jdbc3/JDBC3ResultSet.java +++ b/src/main/java/org/sqlite/jdbc3/JDBC3ResultSet.java @@ -157,10 +157,10 @@ public BigDecimal getBigDecimal(int col) throws SQLException { switch (safeGetColumnType(checkCol(col))) { case SQLITE_NULL: return null; - case SQLITE_FLOAT: - return BigDecimal.valueOf(safeGetDoubleCol(col)); case SQLITE_INTEGER: return BigDecimal.valueOf(safeGetLongCol(col)); + case SQLITE_FLOAT: + // avoid double precision default: final String stringValue = safeGetColumnText(col); try { diff --git a/src/test/java/org/sqlite/PrepStmtTest.java b/src/test/java/org/sqlite/PrepStmtTest.java index 393f237b4..403603cb0 100644 --- a/src/test/java/org/sqlite/PrepStmtTest.java +++ b/src/test/java/org/sqlite/PrepStmtTest.java @@ -7,6 +7,7 @@ import static org.assertj.core.data.Offset.offset; import java.io.ByteArrayInputStream; +import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.Date; @@ -830,4 +831,46 @@ public void gh914_reuseExecute() throws SQLException { assertThat(rs2).isNotNull(); } } + + @Test + public void gh1002_pi() throws SQLException { + BigDecimal pi = new BigDecimal("3.14"); + stat.executeUpdate("create table gh1002(nr number(10,2))"); + + try (PreparedStatement ps = conn.prepareStatement("insert into gh1002 values (?)")) { + ps.setBigDecimal(1, pi); + ps.execute(); + } + + ResultSet rs = stat.executeQuery("select nr from gh1002"); + assertThat(rs.getBigDecimal(1)).isEqualTo(pi); + } + + @Test + public void gh1002_pi_real() throws SQLException { + BigDecimal pi = new BigDecimal("3.14"); + stat.executeUpdate("create table gh1002(nr REAL)"); + + try (PreparedStatement ps = conn.prepareStatement("insert into gh1002 values (?)")) { + ps.setBigDecimal(1, pi); + ps.execute(); + } + + ResultSet rs = stat.executeQuery("select nr from gh1002"); + assertThat(rs.getBigDecimal(1)).isEqualTo(pi); + } + + @Test + public void gh1002_pi_text() throws SQLException { + BigDecimal pi = new BigDecimal("3.14"); + stat.executeUpdate("create table gh1002(nr TEXT)"); + + try (PreparedStatement ps = conn.prepareStatement("insert into gh1002 values (?)")) { + ps.setBigDecimal(1, pi); + ps.execute(); + } + + ResultSet rs = stat.executeQuery("select nr from gh1002"); + assertThat(rs.getBigDecimal(1)).isEqualTo(pi); + } }