use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBPreparedStatement method testParameterIsNullQueryWithValues.
/**
* Tests NULL parameter when using actual (non-null) value in {@link PreparedStatement#setString(int, String)}
*/
@Test
public void testParameterIsNullQueryWithValues() throws Throwable {
final FirebirdSupportInfo supportInfo = supportInfoFor(con);
assumeTrue("test requires support for ? IS NULL", supportInfo.supportsNullDataType());
executeCreateTable(con, CREATE_TEST_CHARS_TABLE);
createIsNullTestData();
try (PreparedStatement ps = con.prepareStatement("SELECT id FROM testtab WHERE field2 = ? OR ? IS NULL ORDER BY 1")) {
ps.setString(1, "a");
ps.setString(2, "a");
ResultSet rs = ps.executeQuery();
assertTrue("Step 2.1 - should get a record.", rs.next());
assertEquals("Step 2.1 - ID should be equal 1", 1, rs.getInt(1));
assertFalse("Step 2 - should get only one record.", rs.next());
}
}
use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBPreparedStatement method testParameterIsNullQuerySetNull.
/**
* Tests NULL parameter when using {@link PreparedStatement#setNull(int, int)}
*/
@Test
public void testParameterIsNullQuerySetNull() throws Throwable {
final FirebirdSupportInfo supportInfo = supportInfoFor(con);
assumeTrue("test requires support for ? IS NULL", supportInfo.supportsNullDataType());
executeCreateTable(con, CREATE_TEST_CHARS_TABLE);
createIsNullTestData();
try (PreparedStatement ps = con.prepareStatement("SELECT id FROM testtab WHERE field2 = ? OR ? IS NULL ORDER BY 1")) {
ps.setNull(1, Types.VARCHAR);
ps.setNull(2, Types.VARCHAR);
ResultSet rs = ps.executeQuery();
assertTrue("Step 1.1 - should get a record.", rs.next());
assertEquals("Step 1.1 - ID should be equal 1", 1, rs.getInt(1));
assertTrue("Step 1.2 - should get a record.", rs.next());
assertEquals("Step 1.2 - ID should be equal 2", 2, rs.getInt(1));
}
}
use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBPreparedStatementMetaData method testData.
@Parameterized.Parameters(name = "Column {0} ({2})")
public static Collection<Object[]> testData() {
List<Object[]> testData = new ArrayList<>(Arrays.asList(create(1, "java.lang.String", parameterModeIn, VARCHAR, "VARCHAR", 60, 0, parameterNullable, false, "simple_field"), create(2, "java.lang.String", parameterModeIn, VARCHAR, "VARCHAR", 60, 0, parameterNullable, false, "two_byte_field"), create(3, "java.lang.String", parameterModeIn, VARCHAR, "VARCHAR", 60, 0, parameterNullable, false, "three_byte_field"), create(4, "java.lang.Long", parameterModeIn, BIGINT, "BIGINT", 19, 0, parameterNullable, true, "long_field"), create(5, "java.lang.Integer", parameterModeIn, INTEGER, "INTEGER", 10, 0, parameterNullable, true, "int_field"), create(6, "java.lang.Integer", parameterModeIn, SMALLINT, "SMALLINT", 5, 0, parameterNullable, true, "short_field"), create(7, "java.lang.Double", parameterModeIn, FLOAT, "FLOAT", 7, 0, parameterNullable, true, "float_field"), create(8, "java.lang.Double", parameterModeIn, DOUBLE, "DOUBLE PRECISION", 15, 0, parameterNullable, true, "double_field"), create(9, "java.math.BigDecimal", parameterModeIn, NUMERIC, "NUMERIC", 4, 1, parameterNullable, true, "smallint_numeric"), create(10, "java.math.BigDecimal", parameterModeIn, DECIMAL, "DECIMAL", 9, 1, parameterNullable, true, "integer_decimal_1"), create(11, "java.math.BigDecimal", parameterModeIn, NUMERIC, "NUMERIC", 9, 2, parameterNullable, true, "integer_numeric"), create(12, "java.math.BigDecimal", parameterModeIn, DECIMAL, "DECIMAL", 9, 3, parameterNullable, true, "integer_decimal_2"), create(13, "java.math.BigDecimal", parameterModeIn, NUMERIC, "NUMERIC", 18, 4, parameterNullable, true, "bigint_numeric"), create(14, "java.math.BigDecimal", parameterModeIn, DECIMAL, "DECIMAL", 18, 9, parameterNullable, true, "bigint_decimal"), create(15, "java.sql.Date", parameterModeIn, DATE, "DATE", 10, 0, parameterNullable, false, "date_field"), create(16, "java.sql.Time", parameterModeIn, TIME, "TIME", 8, 0, parameterNullable, false, "time_field"), create(17, "java.sql.Timestamp", parameterModeIn, TIMESTAMP, "TIMESTAMP", 19, 0, parameterNullable, false, "timestamp_field"), create(18, "[B", parameterModeIn, LONGVARBINARY, "BLOB SUB_TYPE 0", 0, 0, parameterNullable, false, "blob_field"), create(19, "java.lang.String", parameterModeIn, LONGVARCHAR, "BLOB SUB_TYPE 1", 0, 0, parameterNullable, false, "blob_text_field"), // TODO Report actual subtype value
create(20, "java.sql.Blob", parameterModeIn, BLOB, "BLOB SUB_TYPE <0", 0, 0, parameterNullable, false, "blob_minus_one")));
final FirebirdSupportInfo supportInfo = getDefaultSupportInfo();
if (supportInfo.supportsBoolean()) {
testData.add(create(testData.size() + 1, "java.lang.Boolean", parameterModeIn, BOOLEAN, "BOOLEAN", 1, 0, parameterNullable, false, "boolean_field"));
}
if (supportInfo.supportsDecfloat()) {
testData.add(create(testData.size() + 1, "java.math.BigDecimal", parameterModeIn, JaybirdTypeCodes.DECFLOAT, "DECFLOAT", 16, 0, parameterNullable, true, "decfloat16_field"));
testData.add(create(testData.size() + 1, "java.math.BigDecimal", parameterModeIn, JaybirdTypeCodes.DECFLOAT, "DECFLOAT", 34, 0, parameterNullable, true, "decfloat34_field"));
}
if (supportInfo.supportsDecimalPrecision(34)) {
testData.add(create(testData.size() + 1, "java.math.BigDecimal", parameterModeIn, NUMERIC, "NUMERIC", 34, 20, parameterNullable, true, "col_numeric25_20"));
testData.add(create(testData.size() + 1, "java.math.BigDecimal", parameterModeIn, DECIMAL, "DECIMAL", 34, 5, parameterNullable, true, "col_decimal30_5"));
}
return testData;
}
use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBDatabaseMetaDataColumns method getCreateStatements.
protected List<String> getCreateStatements() {
FirebirdSupportInfo supportInfo = supportInfoFor(con);
List<String> statements = new ArrayList<>();
statements.add(CREATE_DOMAIN_WITH_DEFAULT);
String createTable = CREATE_COLUMN_METADATA_TEST_TABLE;
if (!supportInfo.supportsBigint()) {
// No BIGINT support, replacing type so number of columns remain the same
createTable = CREATE_COLUMN_METADATA_TEST_TABLE.replace("col_bigint BIGINT,", "col_bigint DOUBLE PRECISION,");
}
if (supportInfo.supportsBoolean()) {
createTable = createTable.replace("/* boolean */", ", col_boolean BOOLEAN");
}
if (supportInfo.supportsDecfloat()) {
createTable = createTable.replace("/* decfloat */", ", col_decfloat16 DECFLOAT(16), col_decfloat34 DECFLOAT(34)");
}
if (supportInfo.supportsDecimalPrecision(34)) {
createTable = createTable.replace("/* extended numerics */", ", col_numeric25_20 NUMERIC(25, 20), col_decimal30_5 DECIMAL(30,5)");
}
statements.add(createTable);
if (supportInfo.supportsComment()) {
statements.add(ADD_COMMENT_ON_COLUMN);
}
return statements;
}
use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBStatisticsManager method testGetDatabaseTransactionInfo_usingConnection.
@Test
public void testGetDatabaseTransactionInfo_usingConnection() throws SQLException {
FirebirdSupportInfo supportInfo = getDefaultSupportInfo();
int oldest = supportInfo.isVersionEqualOrAbove(2, 5) ? 1 : 5;
int expectedNextOffset;
if (supportInfo.isVersionEqualOrAbove(3, 0)) {
expectedNextOffset = 1;
} else if (supportInfo.isVersionEqualOrAbove(2, 5)) {
expectedNextOffset = 2;
} else {
expectedNextOffset = 1;
}
createTestTable();
try (Connection conn = getConnectionViaDriverManager()) {
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
stmt.execute("select * from rdb$database");
FBStatisticsManager.DatabaseTransactionInfo databaseTransactionInfo = FBStatisticsManager.getDatabaseTransactionInfo(conn);
// The transaction values checked here might be implementation dependent
assertEquals("oldest", oldest, databaseTransactionInfo.getOldestTransaction());
assertEquals("oldest active", oldest + 1, databaseTransactionInfo.getOldestActiveTransaction());
assertEquals("oldest snapshot", oldest + 1, databaseTransactionInfo.getOldestSnapshotTransaction());
assertEquals("next", oldest + expectedNextOffset, databaseTransactionInfo.getNextTransaction());
assertEquals("active", 1, databaseTransactionInfo.getActiveTransactionCount());
}
}
Aggregations