Skip to content

Commit

Permalink
fix(jdbc): getColumns doesn't correctly parse precision/scale with wh…
Browse files Browse the repository at this point in the history
…itespace

Closes: #1215
  • Loading branch information
gotson committed Dec 6, 2024
1 parent 27cbdc0 commit 8455468
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,10 @@ public ResultSet getColumns(String c, String s, String tblNamePattern, String co
}
// try to parse the values
try {
int iInteger = Integer.parseUnsignedInt(sInteger);
int iInteger = Integer.parseUnsignedInt(sInteger.trim());
// parse decimals?
if (sDecimal != null) {
iDecimalDigits = Integer.parseUnsignedInt(sDecimal);
iDecimalDigits = Integer.parseUnsignedInt(sDecimal.trim());
// columns size equals sum of integer and decimal part
// of dimension
iColumnSize = iInteger + iDecimalDigits;
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/sqlite/DBMetaDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,24 @@ public void getColumns() throws SQLException {
assertThat(rs.getString("COLUMN_NAME")).isEqualTo("sql");
}

@Test
public void getColumnsPrecisionScale() throws SQLException {
stat.executeUpdate("create table gh_1215 (n numeric ( 10 , 5 ), d decimal ( 10 ))");

ResultSet rs = meta.getColumns(null, null, "gh_1215", "%");
assertThat(rs.next()).isTrue();
assertThat(rs.getString("COLUMN_NAME")).isEqualTo("n");
assertThat(rs.getString("TYPE_NAME")).isEqualTo("NUMERIC");
assertThat(rs.getString("COLUMN_SIZE")).isEqualTo("15");
assertThat(rs.getString("DECIMAL_DIGITS")).isEqualTo("5");
assertThat(rs.next()).isTrue();
assertThat(rs.getString("COLUMN_NAME")).isEqualTo("d");
assertThat(rs.getString("TYPE_NAME")).isEqualTo("DECIMAL");
assertThat(rs.getString("COLUMN_SIZE")).isEqualTo("10");
assertThat(rs.getString("DECIMAL_DIGITS")).isEqualTo("0");
assertThat(rs.next()).isFalse();
}

@Test
public void getColumnsIncludingGenerated() throws SQLException {
stat.executeUpdate("create table gh_724 (i integer,j integer generated always as (i))");
Expand Down

0 comments on commit 8455468

Please sign in to comment.