use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBStatement method testIsSimpleIdentifier.
@Test
public void testIsSimpleIdentifier() throws Exception {
// Only testing dialect 3
try (FBStatement stmt = (FBStatement) con.createStatement()) {
assertTrue("Simple$Identifier_", stmt.isSimpleIdentifier("Simple$Identifier_"));
assertFalse("1Simple$Identifier_", stmt.isSimpleIdentifier("1Simple$Identifier_"));
assertFalse("", stmt.isSimpleIdentifier(""));
assertTrue("A234567890123456789012345678901", stmt.isSimpleIdentifier("A234567890123456789012345678901"));
FirebirdSupportInfo supportInfo = getDefaultSupportInfo();
String maxLengthIdentifier = generateIdentifier(supportInfo.maxIdentifierLengthCharacters());
assertTrue(maxLengthIdentifier, stmt.isSimpleIdentifier(maxLengthIdentifier));
String tooLongIdentifier = generateIdentifier(supportInfo.maxIdentifierLengthCharacters() + 1);
assertFalse(tooLongIdentifier, stmt.isSimpleIdentifier(tooLongIdentifier));
}
}
use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBPreparedStatement method testCancelStatement.
// @formatter:on
@Test
public void testCancelStatement() throws Exception {
// TODO Investigate why this doesn't work.
assumeThat("Test doesn't work with local protocol", FBTestProperties.GDS_TYPE, not(equalTo(LocalGDSFactoryPlugin.LOCAL_TYPE_NAME)));
final FirebirdSupportInfo supportInfo = supportInfoFor(con);
assumeTrue("Test requires fb_cancel_operations support", supportInfo.supportsCancelOperation());
assumeTrue("Test requires EXECUTE BLOCK support", supportInfo.supportsExecuteBlock());
final AtomicBoolean cancelFailed = new AtomicBoolean(false);
try (Statement stmt = con.createStatement()) {
Thread cancelThread = new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(5);
stmt.cancel();
} catch (SQLException ex) {
cancelFailed.set(true);
} catch (InterruptedException ex) {
// empty
}
}
}, "cancel-thread");
cancelThread.start();
long start = 0;
try {
start = System.currentTimeMillis();
stmt.execute(LONG_RUNNING_STATEMENT);
fail("Statement should raise a cancel exception");
} catch (SQLException ex) {
long end = System.currentTimeMillis();
System.out.println("testCancelStatement: statement cancelled after " + (end - start) + " milliseconds");
assertThat("Unexpected exception for cancellation", ex, allOf(message(startsWith(getFbMessage(ISCConstants.isc_cancelled))), errorCode(equalTo(ISCConstants.isc_cancelled)), sqlState(equalTo("HY008"))));
// everything is fine
} finally {
cancelThread.join();
}
assertFalse("Issuing statement cancel failed", cancelFailed.get());
}
}
use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class TestFBPreparedStatement method testParameterIsNullQueryWithNull.
/**
* Tests NULL parameter when using null value in {@link PreparedStatement#setString(int, String)}
*/
@Test
public void testParameterIsNullQueryWithNull() 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, null);
ps.setString(2, null);
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 TestFBResultSetMetaDataParametrized method testData.
@Parameterized.Parameters(name = "Index {0} ({2})")
public static Collection<Object[]> testData() {
List<Object[]> testData = new ArrayList<>(Arrays.asList(create(1, "java.lang.String", 60, "SIMPLE_FIELD", "SIMPLE_FIELD", VARCHAR, "VARCHAR", 60, 0, TABLE_NAME, columnNullable, true, false), create(2, "java.lang.String", 60, "TWO_BYTE_FIELD", "TWO_BYTE_FIELD", VARCHAR, "VARCHAR", 60, 0, TABLE_NAME, columnNullable, true, false), create(3, "java.lang.String", 60, "THREE_BYTE_FIELD", "THREE_BYTE_FIELD", VARCHAR, "VARCHAR", 60, 0, TABLE_NAME, columnNullable, true, false), create(4, "java.lang.Long", 20, "LONG_FIELD", "LONG_FIELD", BIGINT, "BIGINT", 19, 0, TABLE_NAME, columnNullable, true, true), create(5, "java.lang.Integer", 11, "INT_FIELD", "INT_FIELD", INTEGER, "INTEGER", 10, 0, TABLE_NAME, columnNullable, true, true), create(6, "java.lang.Integer", 6, "SHORT_FIELD", "SHORT_FIELD", SMALLINT, "SMALLINT", 5, 0, TABLE_NAME, columnNullable, true, true), create(7, "java.lang.Double", 9, "FLOAT_FIELD", "FLOAT_FIELD", FLOAT, "FLOAT", 7, 0, TABLE_NAME, columnNullable, true, true), create(8, "java.lang.Double", 17, "DOUBLE_FIELD", "DOUBLE_FIELD", DOUBLE, "DOUBLE PRECISION", 15, 0, TABLE_NAME, columnNullable, true, true), create(9, "java.math.BigDecimal", 5, "SMALLINT_NUMERIC", "SMALLINT_NUMERIC", NUMERIC, "NUMERIC", 3, 1, TABLE_NAME, columnNullable, true, true), create(10, "java.math.BigDecimal", 5, "INTEGER_DECIMAL_1", "INTEGER_DECIMAL_1", DECIMAL, "DECIMAL", 3, 1, TABLE_NAME, columnNullable, true, true), create(11, "java.math.BigDecimal", 7, "INTEGER_NUMERIC", "INTEGER_NUMERIC", NUMERIC, "NUMERIC", 5, 2, TABLE_NAME, columnNullable, true, true), create(12, "java.math.BigDecimal", 11, "INTEGER_DECIMAL_2", "INTEGER_DECIMAL_2", DECIMAL, "DECIMAL", 9, 3, TABLE_NAME, columnNullable, true, true), create(13, "java.math.BigDecimal", 12, "BIGINT_NUMERIC", "BIGINT_NUMERIC", NUMERIC, "NUMERIC", 10, 4, TABLE_NAME, columnNullable, true, true), create(14, "java.math.BigDecimal", 20, "BIGINT_DECIMAL", "BIGINT_DECIMAL", DECIMAL, "DECIMAL", 18, 9, TABLE_NAME, columnNullable, true, true), create(15, "java.sql.Date", 10, "DATE_FIELD", "DATE_FIELD", DATE, "DATE", 10, 0, TABLE_NAME, columnNullable, true, false), create(16, "java.sql.Time", 8, "TIME_FIELD", "TIME_FIELD", TIME, "TIME", 8, 0, TABLE_NAME, columnNullable, true, false), create(17, "java.sql.Timestamp", 19, "TIMESTAMP_FIELD", "TIMESTAMP_FIELD", TIMESTAMP, "TIMESTAMP", 19, 0, TABLE_NAME, columnNullable, true, false), create(18, "[B", 0, "BLOB_FIELD", "BLOB_FIELD", LONGVARBINARY, "BLOB SUB_TYPE 0", 0, 0, TABLE_NAME, columnNullable, false, false), create(19, "java.lang.String", 0, "BLOB_TEXT_FIELD", "BLOB_TEXT_FIELD", LONGVARCHAR, "BLOB SUB_TYPE 1", 0, 0, TABLE_NAME, columnNullable, false, false), // TODO Report actual subtype value
create(20, "java.sql.Blob", 0, "BLOB_MINUS_ONE", "BLOB_MINUS_ONE", BLOB, "BLOB SUB_TYPE <0", 0, 0, TABLE_NAME, columnNullable, false, false)));
final FirebirdSupportInfo supportInfo = getDefaultSupportInfo();
if (supportInfo.supportsBoolean()) {
testData.add(create(testData.size() + 1, "java.lang.Boolean", 5, "BOOLEAN_FIELD", "BOOLEAN_FIELD", BOOLEAN, "BOOLEAN", 1, 0, TABLE_NAME, columnNullable, true, false));
}
if (supportInfo.supportsDecfloat()) {
testData.add(create(testData.size() + 1, "java.math.BigDecimal", 23, "DECFLOAT16_FIELD", "DECFLOAT16_FIELD", JaybirdTypeCodes.DECFLOAT, "DECFLOAT", 16, 0, TABLE_NAME, columnNullable, true, true));
testData.add(create(testData.size() + 1, "java.math.BigDecimal", 42, "DECFLOAT34_FIELD", "DECFLOAT34_FIELD", JaybirdTypeCodes.DECFLOAT, "DECFLOAT", 34, 0, TABLE_NAME, columnNullable, true, true));
}
if (supportInfo.supportsDecimalPrecision(34)) {
testData.add(create(testData.size() + 1, "java.math.BigDecimal", 27, "COL_NUMERIC25_20", "COL_NUMERIC25_20", NUMERIC, "NUMERIC", 25, 20, TABLE_NAME, columnNullable, true, true));
testData.add(create(testData.size() + 1, "java.math.BigDecimal", 32, "COL_DECIMAL30_5", "COL_DECIMAL30_5", DECIMAL, "DECIMAL", 30, 5, TABLE_NAME, columnNullable, true, true));
}
return testData;
}
use of org.firebirdsql.util.FirebirdSupportInfo in project jaybird by FirebirdSQL.
the class AbstractStatementTest method testSelect_WithParameters_Describe.
@Test
public void testSelect_WithParameters_Describe() throws Exception {
allocateStatement();
statement.prepare("SELECT a.RDB$CHARACTER_SET_NAME " + "FROM RDB$CHARACTER_SETS a " + "WHERE a.RDB$CHARACTER_SET_ID = ? OR a.RDB$BYTES_PER_CHARACTER = ?");
assertEquals("Unexpected StatementType", StatementType.SELECT, statement.getType());
final RowDescriptor fields = statement.getFieldDescriptor();
assertNotNull("Fields", fields);
final FirebirdSupportInfo supportInfo = supportInfoFor(db);
final boolean supportsTableAlias = supportInfo.supportsTableAlias();
final int metadataCharSetId = supportInfo.reportedMetadataCharacterSetId();
List<FieldDescriptor> expectedFields = Collections.singletonList(new FieldDescriptor(0, db.getDatatypeCoder(), ISCConstants.SQL_TEXT | 1, metadataCharSetId, 0, supportInfo.maxReportedIdentifierLengthBytes(), "RDB$CHARACTER_SET_NAME", supportsTableAlias ? "A" : null, "RDB$CHARACTER_SET_NAME", "RDB$CHARACTER_SETS", "SYSDBA"));
assertEquals("Unexpected values for fields", expectedFields, fields.getFieldDescriptors());
final RowDescriptor parameters = statement.getParameterDescriptor();
assertNotNull("Parameters", parameters);
List<FieldDescriptor> expectedParameters = Arrays.asList(new FieldDescriptor(0, db.getDatatypeCoder(), ISCConstants.SQL_SHORT | 1, 0, 0, 2, null, null, null, null, null), new FieldDescriptor(1, db.getDatatypeCoder(), ISCConstants.SQL_SHORT | 1, 0, 0, 2, null, null, null, null, null));
assertEquals("Unexpected values for parameters", expectedParameters, parameters.getFieldDescriptors());
}
Aggregations