Skip to content

Commit

Permalink
[CONJ-1067] ResultSetMetaData.getColumnTypeName() does not return UNS…
Browse files Browse the repository at this point in the history
…IGNED for DECIMAL, DOUBLE and FLOAT columns
  • Loading branch information
rusher committed Apr 4, 2023
1 parent 753ac15 commit 1448316
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public int getColumnType(Configuration conf) {
}

public String getColumnTypeName(Configuration conf) {
return "DECIMAL";
if (isSigned()) return "DECIMAL";
return "DECIMAL UNSIGNED";
}

public int getPrecision() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public int getColumnType(Configuration conf) {
}

public String getColumnTypeName(Configuration conf) {
return "DOUBLE";
if (isSigned()) return "DOUBLE";
return "DOUBLE UNSIGNED";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public int getColumnType(Configuration conf) {
}

public String getColumnTypeName(Configuration conf) {
return "FLOAT";
if (isSigned()) return "FLOAT";
return "FLOAT UNSIGNED";
}

@Override
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/StatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ public void longGeneratedId(BigInteger expected) throws SQLException {
assertTrue(new BigDecimal(expected).compareTo(rs.getBigDecimal(1)) == 0);
}

@Test
public void unsignedMetadataResult() throws SQLException {
Statement stmt = sharedConn.createStatement();
stmt.execute("DROP TABLE IF EXISTS unsignedMetadataResult");
stmt.execute(
"CREATE TABLE unsignedMetadataResult("
+ "c0 TINYINT UNSIGNED, "
+ "c1 SMALLINT UNSIGNED, "
+ "c2 MEDIUMINT UNSIGNED, "
+ "c3 INTEGER UNSIGNED, "
+ "c4 BIGINT UNSIGNED, "
+ "c5 DOUBLE UNSIGNED, "
+ "c6 FLOAT UNSIGNED, "
+ "c7 DECIMAL UNSIGNED)");
stmt.execute("INSERT INTO unsignedMetadataResult VALUES(10,11,12,13,14,15,16,17)");
assertTrue(stmt.execute("SELECT * FROM unsignedMetadataResult"));

ResultSet rs = stmt.getResultSet();
ResultSetMetaData rsMetaData = rs.getMetaData();
for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {
assertTrue(rsMetaData.getColumnTypeName(i).contains("UNSIGNED"));
}
stmt.execute("DROP TABLE unsignedMetadataResult");
}

@Test
public void getConnection() throws SQLException {
Statement stmt = sharedConn.createStatement();
Expand Down

0 comments on commit 1448316

Please sign in to comment.