forked from FirebirdSQL/jaybird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JDBC-462 Fix FBBigDecimal, unsupported field sqltype: 481 with large …
…numeric in dialect 1
- Loading branch information
1 parent
fe9a9ba
commit c9497c0
Showing
3 changed files
with
59 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,29 +18,29 @@ | |
*/ | ||
package org.firebirdsql.jdbc; | ||
|
||
import org.firebirdsql.common.FBJUnit4TestBase; | ||
import org.firebirdsql.common.DdlHelper; | ||
import org.firebirdsql.gds.ISCConstants; | ||
import org.firebirdsql.gds.impl.GDSType; | ||
import org.firebirdsql.management.FBManager; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.sql.*; | ||
import java.util.Properties; | ||
|
||
import static org.firebirdsql.common.DdlHelper.executeCreateTable; | ||
import static org.firebirdsql.common.FBTestProperties.*; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Tests for updatable result sets with a dialect 1 database. | ||
* Tests for specific behavior in dialect 1 databases. | ||
* | ||
* @author <a href="mailto:[email protected]">Mark Rotteveel</a> | ||
* @since 2.2 | ||
*/ | ||
public class TestResultSetDialect1 extends FBJUnit4TestBase { | ||
public class TestDialect1Specifics { | ||
|
||
//@formatter:off | ||
public static final String CREATE_TABLE_STATEMENT = | ||
|
@@ -54,10 +54,10 @@ public class TestResultSetDialect1 extends FBJUnit4TestBase { | |
public static final String INSERT_INTO_TABLE_STATEMENT = "INSERT INTO test_table (id, str) VALUES(?, ?)"; | ||
//@formatter:on | ||
|
||
private FBManager fbManager; | ||
private Connection connection; | ||
|
||
@Before | ||
@Override | ||
public void basicSetUp() throws Exception { | ||
fbManager = createFBManager(); | ||
|
||
|
@@ -74,12 +74,9 @@ public void basicSetUp() throws Exception { | |
final Properties properties = getDefaultPropertiesForConnection(); | ||
properties.setProperty("sql_dialect", String.valueOf(ISCConstants.SQL_DIALECT_V5)); | ||
connection = DriverManager.getConnection(getUrl(), properties); | ||
|
||
executeCreateTable(connection, CREATE_TABLE_STATEMENT); | ||
} | ||
|
||
@After | ||
@Override | ||
public void basicTearDown() throws Exception { | ||
try { | ||
connection.close(); | ||
|
@@ -164,7 +161,35 @@ public void testDeleteRow() throws Exception { | |
} | ||
} | ||
|
||
@Test | ||
public void testGetDoubleNumeric() throws Exception { | ||
DdlHelper.executeCreateTable(connection, "create table testnumeric (id integer primary key, numericvalue numeric(18,2))"); | ||
try (Statement stmt = connection.createStatement()) { | ||
stmt.executeUpdate("insert into testnumeric(id, numericvalue) values(1, 34.01)"); | ||
try (ResultSet rs = stmt.executeQuery("select * from testnumeric")) { | ||
assertTrue("Expected a row", rs.next()); | ||
assertEquals(new BigDecimal("34.01"), rs.getBigDecimal("numericvalue")); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testSetDoubleNumeric() throws Exception { | ||
DdlHelper.executeCreateTable(connection, "create table testnumeric (id integer primary key, numericvalue numeric(18,2))"); | ||
try (PreparedStatement pstmt = connection.prepareStatement("insert into testnumeric(id, numericvalue) values(1, ?)")) { | ||
pstmt.setBigDecimal(1, new BigDecimal("34.01242323234")); | ||
pstmt.executeUpdate(); | ||
} | ||
|
||
try (Statement stmt = connection.createStatement(); | ||
ResultSet rs = stmt.executeQuery("select cast(numericvalue as varchar(50)) as numericvalue from testnumeric")) { | ||
assertTrue("Expected a row", rs.next()); | ||
assertEquals("34.01", rs.getString("numericvalue")); | ||
} | ||
} | ||
|
||
private void createTestData(int recordCount) throws Exception { | ||
executeCreateTable(connection, CREATE_TABLE_STATEMENT); | ||
connection.setAutoCommit(false); | ||
try (PreparedStatement ps = connection.prepareStatement(INSERT_INTO_TABLE_STATEMENT)) { | ||
for (int i = 0; i < recordCount; i++) { | ||
|