public class CastingTest extends BaseJDBCTestCase
Modifier and Type | Class and Description |
---|---|
static class |
CastingTest.TypedColumn |
Modifier and Type | Field and Description |
---|---|
static int |
BIGINT_OFFSET |
static int |
BLOB_OFFSET |
static int |
CHAR_FOR_BIT_OFFSET |
static int |
CHAR_OFFSET |
static int |
CLOB_OFFSET |
static int |
DATE_OFFSET |
static int |
DECIMAL_OFFSET |
static int |
DOUBLE_OFFSET |
private static java.lang.String[][] |
explicitCastValues |
private static CastingTest.TypedColumn[] |
ILLEGAL_BOOLEAN_CASTS |
static java.lang.String |
ILLEGAL_CAST_EXCEPTION_SQLSTATE |
static int |
INTEGER_OFFSET |
static int[] |
jdbcTypes |
static java.lang.String |
LANG_FORMAT_EXCEPTION_SQLSTATE |
static java.lang.String |
LANG_NOT_COMPARABLE_SQLSTATE |
static java.lang.String |
LANG_NOT_STORABLE_SQLSTATE |
private static CastingTest.TypedColumn[] |
LEGAL_BOOLEAN_CASTS |
static int |
LONGVARCHAR_FOR_BIT_OFFSET |
static int |
LONGVARCHAR_OFFSET |
static java.lang.String |
METHOD_NOT_FOUND_SQLSTATE |
static boolean |
n |
static int |
NULL_DATA_OFFSET |
static java.lang.String |
NULL_VALUE |
static int |
REAL_OFFSET |
static int |
SMALLINT_OFFSET |
static java.lang.String[][] |
SQLData |
static int |
SQLTYPE_ARRAY_SIZE |
static boolean[][] |
T_146
Table 146 - Supported explicit casts between Built-in DataTypes
This table has THE FOR BIT DATA TYPES broken out into separate columns
for clarity and testing
|
static boolean[][] |
T_147a
Table 147 describes Data Type Compatibility for Assignments
The table 147a covers the assignments as they do differ somewhat
from comparisons which can be found in 147b
|
static boolean[][] |
T_147b |
static int |
TIME_OFFSET |
static int |
TIMESTAMP_OFFSET |
static int |
VALID_DATA_OFFSET |
static java.lang.String |
VALID_DATE_STRING |
static java.lang.String |
VALID_TIME_STRING |
static java.lang.String |
VALID_TIMESTAMP_STRING |
static int |
VARCHAR_FOR_BIT_OFFSET |
static int |
VARCHAR_OFFSET |
static boolean |
X |
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
CastingTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
private void |
assertAllTypesCovered() |
private void |
assertBooleanResults(java.lang.String queryText,
boolean expectedValue,
int expectedRowCount) |
private void |
assertDataTruncation(java.sql.SQLWarning w,
int index,
boolean read,
boolean parameter,
int dataSize,
int transferSize) |
private void |
assertScalarResult(java.lang.String queryText,
int expectedValue) |
private java.sql.PreparedStatement |
chattyPrepare(java.lang.String text)
Prepare a statement and report its sql text.
|
private void |
checkDataTruncationResult(java.sql.Statement s,
java.lang.String sql)
Check the results for the queries in testDataTruncation().
|
private static void |
checkSupportedAssignment(int sourceType,
int targetType) |
private static void |
checkSupportedCast(int sourceType,
int targetType) |
private static void |
checkSupportedComparison(int sourceType,
int targetType) |
private void |
expectError(java.lang.String sqlState,
java.lang.String query)
Assert that the statement text, when compiled, raises an exception
|
private static java.lang.String |
formatString(java.lang.String str) |
private static java.lang.String |
getCompatibleString(int sourceType,
int targetType,
int dataOffset) |
private static java.lang.String |
getShortTypeName(int type)
Truncates (*) from typename
|
private static java.lang.String |
getTableName(int type)
Build a unique table name from the type
|
private void |
goodStatement(java.lang.String ddl)
Run good DDL.
|
private static boolean |
isBinaryType(int typeOffset) |
private static boolean |
isCastException(java.sql.SQLException se) |
private static boolean |
isCharacterType(int typeOffset) |
private static boolean |
isLob(int typeOffset) |
private static boolean |
isLongType(int typeOffset) |
private static boolean |
isMethodNotFoundException(java.sql.SQLException se) |
private static boolean |
isNotComparableException(java.sql.SQLException se) |
private static boolean |
isNotStorableException(java.sql.SQLException se) |
private static boolean |
isSupportedAssignment(int sourceType,
int targetType) |
private static boolean |
isSupportedCast(int sourceType,
int targetType) |
private static boolean |
isSupportedComparison(int sourceType,
int targetType) |
private static boolean |
isTime(int typeOffset) |
private static boolean |
isTimestamp(int typeOffset) |
private java.lang.String |
makeCastedColumnList(java.lang.String columnName,
CastingTest.TypedColumn[] targetTypes) |
private java.lang.String |
makeColumnList(CastingTest.TypedColumn[] columns) |
private java.lang.String |
makeRepeatedColumnList(java.lang.String columnName,
int N) |
private void |
makeTableForCasts(java.lang.String tableName,
CastingTest.TypedColumn[] columns) |
protected void |
setUp() |
private static boolean |
sqlStateMatches(java.sql.SQLException se,
java.lang.String expectedValue) |
static junit.framework.Test |
suite()
Create a test suite with all the tests in this class.
|
protected void |
tearDown()
Tear down this fixture, sub-classes should call
super.tearDown().
|
void |
test_derby887()
Verify that DERBY-887 is fixed.
|
void |
test_illegalBooleanCasts()
Verify that the illegal boolean casts work as expected.
|
void |
test_legalBooleanCasts()
Verify that the legal boolean casts work as expected.
|
void |
testAssignments() |
void |
testComparisons() |
void |
testDataTruncationWarning()
Test that a java.sql.DataTruncation warning is created when a cast
results in truncation.
|
void |
testDateTimeToTimestamp()
DERBY-896: Verify that casts from DATE and TIME to TIMESTAMP work.
|
void |
testExplicitCasts() |
assertCallError, assertCheckTable, assertCommitError, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertErrorCode, assertGetIntError, assertNextError, assertPreparedStatementError, assertResults, assertResults, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertStatementErrorUnordered, assertTableRowCount, assertUpdateCount, assertUpdateCount, assertWarning, chattyPrepare, chattyPrepareCall, checkAllConsistency, checkEstimatedRowCount, closeStatement, commit, createStatement, createStatement, createStatement, dropTable, dropTable, dropView, dropView, dumpRs, dumpRs, emptyStatementCache, executeQuery, expectCompilationError, expectCompilationError, expectExecutionError, getClientTransactionID, getConnection, getDatabaseProperty, getLastSQLException, goodStatement, goodUpdate, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runBare, runBareOverridable, runScript, runScript, runSQLCommands, setAutoCommit, usingDB2Client, usingDerbyNetClient, usingEmbedded
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, toString
public static java.lang.String VALID_DATE_STRING
public static java.lang.String VALID_TIME_STRING
public static java.lang.String VALID_TIMESTAMP_STRING
public static java.lang.String NULL_VALUE
public static java.lang.String ILLEGAL_CAST_EXCEPTION_SQLSTATE
public static java.lang.String LANG_NOT_STORABLE_SQLSTATE
public static java.lang.String LANG_NOT_COMPARABLE_SQLSTATE
public static java.lang.String METHOD_NOT_FOUND_SQLSTATE
public static java.lang.String LANG_FORMAT_EXCEPTION_SQLSTATE
public static int SQLTYPE_ARRAY_SIZE
public static int SMALLINT_OFFSET
public static int INTEGER_OFFSET
public static int BIGINT_OFFSET
public static int DECIMAL_OFFSET
public static int REAL_OFFSET
public static int DOUBLE_OFFSET
public static int CHAR_OFFSET
public static int VARCHAR_OFFSET
public static int LONGVARCHAR_OFFSET
public static int CHAR_FOR_BIT_OFFSET
public static int VARCHAR_FOR_BIT_OFFSET
public static int LONGVARCHAR_FOR_BIT_OFFSET
public static int CLOB_OFFSET
public static int DATE_OFFSET
public static int TIME_OFFSET
public static int TIMESTAMP_OFFSET
public static int BLOB_OFFSET
public static int[] jdbcTypes
public static int NULL_DATA_OFFSET
public static int VALID_DATA_OFFSET
public static java.lang.String[][] SQLData
public static final boolean n
public static final boolean X
public static final boolean[][] T_146
public static final boolean[][] T_147a
public static final boolean[][] T_147b
private static final java.lang.String[][] explicitCastValues
private static final CastingTest.TypedColumn[] LEGAL_BOOLEAN_CASTS
private static final CastingTest.TypedColumn[] ILLEGAL_BOOLEAN_CASTS
protected void setUp() throws java.sql.SQLException
setUp
in class junit.framework.TestCase
java.sql.SQLException
public void testAssignments() throws java.sql.SQLException
java.sql.SQLException
public void testExplicitCasts() throws java.sql.SQLException
java.sql.SQLException
public void testComparisons() throws java.sql.SQLException
java.sql.SQLException
public void test_derby887() throws java.lang.Exception
java.lang.Exception
public void test_legalBooleanCasts() throws java.lang.Exception
Verify that the legal boolean casts work as expected. This test helps verify that DERBY-887 is fixed. Verifies the following:
The following can't be tested until the BOOLEAN type is re-enabled:
java.lang.Exception
private void makeTableForCasts(java.lang.String tableName, CastingTest.TypedColumn[] columns) throws java.lang.Exception
java.lang.Exception
private java.lang.String makeColumnList(CastingTest.TypedColumn[] columns)
private java.lang.String makeCastedColumnList(java.lang.String columnName, CastingTest.TypedColumn[] targetTypes)
private java.lang.String makeRepeatedColumnList(java.lang.String columnName, int N)
private void assertBooleanResults(java.lang.String queryText, boolean expectedValue, int expectedRowCount) throws java.lang.Exception
java.lang.Exception
private void assertScalarResult(java.lang.String queryText, int expectedValue) throws java.lang.Exception
java.lang.Exception
private void assertAllTypesCovered() throws java.lang.Exception
java.lang.Exception
public void test_illegalBooleanCasts() throws java.lang.Exception
Verify that the illegal boolean casts work as expected. This test helps verify that DERBY-887 is fixed. Verifies the following:
The following can't be tested until the BOOLEAN type is re-enabled:
java.lang.Exception
public void testDataTruncationWarning() throws java.sql.SQLException
java.sql.SQLException
private void checkDataTruncationResult(java.sql.Statement s, java.lang.String sql) throws java.sql.SQLException
Check the results for the queries in testDataTruncation().
The method expects a query that returns three rows with columns of a character string or binary string data type, where some of the values are cast to a narrower data type.
Expect the following truncations to have taken place:
java.sql.SQLException
private void assertDataTruncation(java.sql.SQLWarning w, int index, boolean read, boolean parameter, int dataSize, int transferSize) throws java.sql.SQLException
java.sql.SQLException
public void testDateTimeToTimestamp() throws java.sql.SQLException
java.sql.SQLException
protected void tearDown() throws java.sql.SQLException, java.lang.Exception
BaseJDBCTestCase
tearDown
in class BaseJDBCTestCase
java.sql.SQLException
java.lang.Exception
private static java.lang.String getTableName(int type)
type
- table offsetprivate static java.lang.String getShortTypeName(int type)
type
- -
Type offsetprivate static java.lang.String getCompatibleString(int sourceType, int targetType, int dataOffset)
private static boolean isSupportedCast(int sourceType, int targetType)
private static boolean isSupportedAssignment(int sourceType, int targetType)
private static boolean isSupportedComparison(int sourceType, int targetType)
private static boolean isCastException(java.sql.SQLException se)
private static boolean isMethodNotFoundException(java.sql.SQLException se)
private static boolean sqlStateMatches(java.sql.SQLException se, java.lang.String expectedValue)
private static boolean isNotStorableException(java.sql.SQLException se)
private static boolean isNotComparableException(java.sql.SQLException se)
private static void checkSupportedCast(int sourceType, int targetType)
private static void checkSupportedAssignment(int sourceType, int targetType)
private static void checkSupportedComparison(int sourceType, int targetType)
private static boolean isLongType(int typeOffset)
private static boolean isCharacterType(int typeOffset)
private static boolean isBinaryType(int typeOffset)
private static boolean isTime(int typeOffset)
private static boolean isTimestamp(int typeOffset)
private static boolean isLob(int typeOffset)
private static java.lang.String formatString(java.lang.String str)
private void goodStatement(java.lang.String ddl) throws java.sql.SQLException
java.sql.SQLException
private void expectError(java.lang.String sqlState, java.lang.String query)
private java.sql.PreparedStatement chattyPrepare(java.lang.String text) throws java.sql.SQLException
java.sql.SQLException
public static junit.framework.Test suite()
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.