Skip to content

Commit

Permalink
JDBC-426 DatabaseMetadata.getColumn returns 0 for DECIMAL_DIGITS for …
Browse files Browse the repository at this point in the history
…NUMERIC(15,2) in dialect 1
  • Loading branch information
mrotteveel committed Mar 25, 2016
1 parent f8c4c94 commit bd224c1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/main/org/firebirdsql/jdbc/AbstractFieldMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ else if (sqlSubtype == SUBTYPE_DECIMAL)
return "BIGINT";
case ISCConstants.SQL_DOUBLE:
case ISCConstants.SQL_D_FLOAT:
return "DOUBLE PRECISION";
if (sqlSubtype == SUBTYPE_NUMERIC || (sqlSubtype == 0 && sqlScale < 0))
return "NUMERIC";
else if (sqlSubtype == SUBTYPE_DECIMAL)
return "DECIMAL";
else
return "DOUBLE PRECISION";
case ISCConstants.SQL_FLOAT:
return "FLOAT";
case ISCConstants.SQL_TEXT:
Expand Down
7 changes: 6 additions & 1 deletion src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,12 @@ else if (sqlsubtype == SUBTYPE_DECIMAL)
return "INTEGER";
case double_type:
case d_float_type:
return "DOUBLE PRECISION";
if (sqlsubtype == SUBTYPE_NUMERIC || (sqlsubtype == 0 && sqlscale < 0))
return "NUMERIC";
else if (sqlsubtype == SUBTYPE_DECIMAL)
return "DECIMAL";
else
return "DOUBLE PRECISION";
case float_type:
return "FLOAT";
case char_type:
Expand Down
7 changes: 6 additions & 1 deletion src/main/org/firebirdsql/jdbc/field/JdbcTypeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ else if (subtype == SUBTYPE_DECIMAL)
return Types.BIGINT;
case ISCConstants.SQL_DOUBLE:
case ISCConstants.SQL_D_FLOAT:
return Types.DOUBLE;
if (subtype == SUBTYPE_NUMERIC || (subtype == 0 && scale < 0))
return Types.NUMERIC;
else if (subtype == SUBTYPE_DECIMAL)
return Types.DECIMAL;
else
return Types.DOUBLE;
case ISCConstants.SQL_FLOAT:
return Types.FLOAT;
case ISCConstants.SQL_TEXT:
Expand Down
81 changes: 81 additions & 0 deletions src/test/org/firebirdsql/jdbc/TestFBDatabaseMetaDataDialect1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Firebird Open Source JavaEE Connector - JDBC Driver
*
* Distributable under LGPL license.
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LGPL License for more details.
*
* This file was created by members of the firebird development team.
* All individual contributions remain the Copyright (C) of those
* individuals. Contributors to this file are either listed here or
* can be obtained from a source control history command.
*
* All rights reserved.
*/
package org.firebirdsql.jdbc;

import org.firebirdsql.common.DdlHelper;
import org.firebirdsql.management.FBManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.sql.*;
import java.util.Properties;

import static org.firebirdsql.common.FBTestProperties.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Tests for database metadata in dialect 1.
*
* @author <a href="mailto:mrotteveel@users.sourceforge.net">Mark Rotteveel</a>
*/
public class TestFBDatabaseMetaDataDialect1 {

protected FBManager fbManager = null;

/**
* Basic setup of the test database.
*
* @throws Exception
*/
@Before
public void basicSetUp() throws Exception {
fbManager = createFBManager();
fbManager.setDialect(1);
defaultDatabaseSetUp(fbManager);
}

/**
* Basic teardown of the test database
*
* @throws Exception
*/
@After
public void basicTearDown() throws Exception {
defaultDatabaseTearDown(fbManager);
fbManager = null;
}

@Test
public void testLargeNumeric() throws Exception {
Properties props = getDefaultPropertiesForConnection();
props.setProperty("sqlDialect", "1");
try (Connection connection = DriverManager.getConnection(getUrl(), props)) {
DdlHelper.executeCreateTable(connection, "CREATE TABLE x (col NUMERIC(15,2))");
final DatabaseMetaData md = connection.getMetaData();
final ResultSet columns = md.getColumns(null, null, "X", "COL");
assertTrue(columns.next());
assertEquals("NUMERIC", columns.getString("TYPE_NAME"));
assertEquals(Types.NUMERIC, columns.getInt("DATA_TYPE"));
assertEquals(2, columns.getInt("DECIMAL_DIGITS"));
}
}

}

0 comments on commit bd224c1

Please sign in to comment.