org.apache.derbyTesting.functionTests.tests.jdbcapi
Class DatabaseMetaDataTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.jdbcapi.DatabaseMetaDataTest
All Implemented Interfaces:
junit.framework.Test

public class DatabaseMetaDataTest
extends BaseJDBCTestCase

Test the DatabaseMetaData api.

For a number of methods that return a ResultSet to determine the attributes of SQL objects (e.g. getTables) two methods are provided. A non-modify and a modify one.
The non-modify method tests that the getXXX method call works. This can be used by other tests where issues have been seen with database meta data, such as upgrade and read-only databases. The non-modify means that the test method does not change the database in order to test the return of the getXXX method is correct.

This test is also called from the upgrade tests to test that metadata continues to work at various points in the upgrade.


Field Summary
private static java.lang.String[] BUILTIN_SCHEMAS
          All the builtin schemas.
private static java.lang.String[] IDS
          Six combinations of valid identifiers with mixed case, to see how the various pattern matching and returned values handle them.
private  boolean modifiedDatabase
          Did the test modifiy the database.
private static java.lang.String[][] NUMERIC_FUNCTIONS
           
private static java.lang.String[][] STRING_FUNCTIONS
           
private static java.lang.String[][] SYSTEM_FUNCTIONS
           
private static java.lang.String[][] TIMEDATE_FUNCTIONS
           
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
DatabaseMetaDataTest(java.lang.String name)
           
 
Method Summary
private  void assertFullResultSet(java.sql.ResultSet[] rs, java.lang.String[][] expRS, boolean trim)
          Helper method - unravles a ResultSet array created e.g.
private  void assertGetImportedAndExportedKeysShape(java.sql.ResultSet[] rss)
          Assert the shape of the ResultSets for getImportedKeys, getExportedKeys and getCrossReference.
private  void assertMatchesPattern(java.lang.String pattern, java.lang.String result)
           
static void assertMetaDataResultSet(java.sql.ResultSet rs, java.lang.String[] columnNames, int[] columnTypes, boolean[] nullability)
           
private  void checkCatalogsShape(java.sql.ResultSet rs)
          Check the shape of the ResultSet from any getCatlogs call.
private  void checkColumnsShape(java.sql.ResultSet rs, int odbc)
           
private  void checkGetTablesODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table, java.lang.String[] tableTypes)
          Execute and check the ODBC variant of getTables which uses a procedure to provide the same information to ODBC clients.
private  void checkODBCKeys(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable, java.lang.String fCatalog, java.lang.String fSchema, java.lang.String fTable)
          Execute a call to the ODBC system procedure "SQLFOREIGNKEYS" and verify the results by comparing them with the results of an equivalent JDBC call (if one exists).
private  void checkODBCKeysShape(java.sql.ResultSet rs)
          Check the shape of the ResultSet from a call to the ODBC function SQLForeignKeys.
static void checkSchemas(java.sql.ResultSet rs, java.lang.String[] userExpected)
          Check the returned information from a getSchemas().
private static void checkSchemasShape(java.sql.ResultSet rs)
          Check the shape of the ResultSet from any getSchemas call.
private  void checkTablesShape(java.sql.ResultSet rs)
          Check the shape of the ResultSet from any getTables call.
private static void checkVersionColumnsShape(java.sql.ResultSet[] rs)
          Check the shape of the ResultSet from any getVersionColumns call.
private static junit.framework.Test connectionPoolingSuite(java.lang.String jdbcClient)
          Returns a suite of tests to be run with connection pooling enabled.
private  void createObjectsForKeysTests()
          Create the tables for get*Keys tests
private  void createSchemasForTests()
           
private  int createTablesForTest(boolean skipXML)
          Create a set of tables using the identifiers in IDS.
static void crossCheckGetColumnRowAndResultSetMetaData(java.sql.ResultSet rs, java.sql.ResultSetMetaData rsmdt, int odbc)
          Cross check a single row from getColumns() with ResultSetMetaData for a SELECT * from the same table.
private  void crossCheckGetColumnsAndResultSetMetaData(java.sql.ResultSet rs, boolean partial, int odbc)
          Compare a ResultSet from getColumns() with ResultSetMetaData returned from a SELECT * against the table.
private  boolean doesMatch(java.lang.String pattern, int pp, java.lang.String result, int rp)
          See if a string matches the pattern as defined by DatabaseMetaData.
private  void dropObjectsForKeysTests()
          Drop the database objects for get*Keys tests
private  void escapedFunctions(java.lang.String[][] specList, java.lang.String metaDataList)
          Check that the list of escaped functions provided by the driver is a strict subet of the specified set, the list does not contain duplicates, all the functions listed can be executed and that if a function is not in the list but is specified it cannot be executed.
private  void executeEscaped(java.lang.String[] specDetails)
          Test we can execute a function listed as a supported JDBC escaped function.
private  java.sql.ResultSet[] getBestRowIdentifier(java.lang.String catalog, java.lang.String schema, java.lang.String table, int scope, boolean nullable)
          Helper method for testing getBestRowIdentifier - calls dmd.getBestRowIdentifier for the JDBC call, and getBestRowIdentifierODBC for the ODBC procedure
private  java.sql.ResultSet getBestRowIdentifierODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table, int scope, boolean nullable)
          Helper method for testing getBestRowIdentifier - calls the ODBC procedure
private  java.sql.ResultSet[] getColumnPrivileges(java.lang.String catalog, java.lang.String schema, java.lang.String table, java.lang.String columnNamePattern)
          Helper method for testing getColumnPrivileges - calls dmd.getIndexInfo for the JDBC call, and getColumnPrivilegesODBC for the ODBC procedure
private  java.sql.ResultSet getColumnPrivilegesODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table, java.lang.String columnNamePattern)
          Helper method for testing getColumnPrivileges - calls the ODBC procedure
private  java.sql.ResultSet[] getColumns(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tableNamePattern, java.lang.String columnNamePattern)
          Helper method for testing getColumns - calls dmd.getColumns for the JDBC call, and getColumnsODBC for the ODBC procedure
private  java.sql.ResultSet getColumnsODBC(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tableNamePattern, java.lang.String columnNamePattern)
          Implement ODBC equivalent for getColumns - SYSIBM.SQLCOLUMNS
private  java.sql.ResultSet[] getCrossReference(java.lang.String parentcatalog, java.lang.String parentschema, java.lang.String parenttable, java.lang.String foreigncatalog, java.lang.String foreignschema, java.lang.String foreigntable)
          Helper method for testing getCrossReference - calls dmd.getCrossReference for the JDBC call, and getCrossReferenceODBC for the ODBC procedure
private  java.sql.ResultSet getCrossReferenceODBC(java.lang.String parentcatalog, java.lang.String parentschema, java.lang.String parenttable, java.lang.String foreigncatalog, java.lang.String foreignschema, java.lang.String foreigntable)
          Helper method for testing getCrossReference - calls the ODBC procedure
private  java.sql.DatabaseMetaData getDMD()
           
private  java.sql.ResultSet getDMDTables(java.sql.DatabaseMetaData dmd, java.lang.String catalog, java.lang.String schema, java.lang.String table, java.lang.String[] tableTypes)
          Execute dmd.getTables() but perform additional checking of the ODBC variant.
private  java.sql.ResultSet[] getExportedKeys(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Helper method for testing getExportedKeys - calls dmd.getExportedKeys for the JDBC call, and getExportedKeysODBC for the ODBC procedure
private  java.sql.ResultSet getExportedKeysODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Helper method for testing getExportedKeys - calls the ODBC procedure
private  java.sql.ResultSet[] getImportedKeys(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Helper method for testing getImportedKeys - calls dmd.getImportedKeys for the JDBC call, and getImportedKeysODBC for the ODBC procedure
private  java.sql.ResultSet getImportedKeysODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Helper method for testing getImportedKeys - calls the ODBC procedure
private  java.sql.ResultSet[] getIndexInfo(java.lang.String catalog, java.lang.String schema, java.lang.String table, boolean unique, boolean approximate)
          Helper method for testing getIndexInfo - calls dmd.getIndexInfo for the JDBC call, and getIndexInfoODBC for the ODBC procedure
private  java.sql.ResultSet getIndexInfoODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table, boolean unique, boolean approximate)
          Helper method for testing getIndexInfo - calls the ODBC procedure
static int getJDBCType(java.lang.String type)
          Given a valid SQL type return the corresponding JDBC type identifier from java.sql.Types.
private  java.lang.String getPattern(java.util.Random rand, java.lang.String[] dbIDS)
           
private static void getpc(int a, long b)
          overload getpc to further test getProcedureColumns private method shouldn't be returned with alias, ok with procedure
static void getpc(int a, long[] b)
          overload getpc to further test getProcedureColumns
static byte[] getpc(java.lang.String a, java.math.BigDecimal b, short c, byte d, short e, int f, long g, float h, double i, byte[] j, java.sql.Date k, java.sql.Time l, java.sql.Timestamp T)
          dummy method to test getProcedureColumns
 void getpc(java.lang.String a, java.lang.String b)
          instance method for getProcedureColumns testing with method alias, this should not be returned by getProcedureColumns but DB2 returns this with a java procedure
static void getpc4a()
          this method should notbe seen by getProcedureColumns as it has no parameters and no return value.
static int getpc4b()
          check a method with no paramters and a return value works for getProcedureColumns
static int getPrecision(int jdbcType, java.lang.String type)
          Given a valid SQL type return the corresponding precision/length for this specific value if the type is variable, e.g.
private  java.sql.ResultSet[] getPrimaryKeys(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Helper method for testing getPrimaryKeys - calls dmd.getPrimaryKeys for the JDBC call, and getPrimaryKeysODBC for the ODBC procedure
private  java.sql.ResultSet getPrimaryKeysODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Helper method for testing getPrimaryKeys - calls the ODBC procedure
private  java.sql.ResultSet[] getProcedureColumns(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String procedureNamePattern, java.lang.String columnNamePattern)
          Helper method for testing getProcedureColumns - calls dmd.getProcedureColumns for the JDBC call, and getProcedureColumnssODBC for the ODBC procedure
private  java.sql.ResultSet getProcedureColumnsODBC(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String procedureNamePattern, java.lang.String columnNamePattern)
          Helper method for testing getProcedureColumns - calls the ODBC procedure
private  java.sql.ResultSet[] getProcedures(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String procedureNamePattern)
          Helper method for testing getProcedures - calls dmd.getProcedures for the JDBC call, and getProceduresODBC for the ODBC procedure
private  java.sql.ResultSet getProceduresODBC(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String procedureNamePattern)
          Helper method for testing getProcedures - calls the ODBC procedure
private  java.lang.String[] getSortedIdentifiers()
          Return the identifiers used to create schemas, tables etc. in the order the database stores them.
static java.util.List getSQLTypes(java.sql.Connection conn)
          Return a list of all valid supported datatypes as Strings suitable for use in any SQL statement where a SQL type is expected.
static java.lang.String getStoredIdentifier(java.lang.String sqlIdentifier)
           
private  java.sql.ResultSet[] getTablePrivileges(java.lang.String catalog, java.lang.String schema, java.lang.String tableNamePattern)
          Helper method for testing getTablePrivileges - calls dmd.getIndexInfo for the JDBC call, and getTablePrivilegesODBC for the ODBC procedure
private  java.sql.ResultSet getTablePrivilegesODBC(java.lang.String catalog, java.lang.String schema, java.lang.String tableNamePattern)
          Helper method for testing getTablePrivileges - calls the ODBC procedure
private  java.sql.ResultSet[] getVersionColumns(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Helper method for testing getVersionColumns - calls dmd.getVersionColumns for the JDBC call, and getVersionColumnsODBC for the ODBC procedure
 java.sql.ResultSet getVersionColumnsODBC(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Implement ODBC equivalent for getVersionColumns - SYSIBM.SQLCOLUMNS
 void initialCompilationTest()
          Tests that a meta-data query is compiled and stored correctly even when there's a lock on the system tables (DERBY-2584).
static void isro()
          method used in testBugFixes, for testing nexted connection metadata
 void recompileTimeoutTest()
          Tests that we don't get an internal timeout when a meta-data statement is recompiled because the size of the tables it queries has changed (DERBY-3693).
static junit.framework.Test suite()
          Default suite for running this test.
protected  void tearDown()
          Tear down this fixture, sub-classes should call super.tearDown().
 void testBugFixes()
           
 void testConnectionSpecific()
          Methods that return information specific to the current connection.
 void testConstants()
          This is not a test of Derby but JDBC constants for meta data that this test depends on.
 void testDataSourceLimits()
          Test group of methods provides the limits imposed by a given data source Methods start with 'getMax'.
 void testDetermineFeatureSupport()
          Test the methods that indicate if a feature is supported or not.
 void testDMDconnClosed()
          Reading of DatabaseMetaData obtained earlier, after a connection is closed.
 void testGetBestRowIdentifier()
          Test getBestRowIdentifier
 void testGetColumnPrivileges()
          Test getGetColumnPrivileges; does not modify database For further testing see test lang.grantRevokeTest
 void testGetColumnsModify()
          Test getColumns() with modifying the database.
 void testGetColumnsReadOnly()
          Test getTableColumns().
 void testGetIndexInfo()
          Test getIndexInfo; does not modify database
 void testGetPrimaryKeys()
          Test getPrimaryKeys; does modify database
 void testGetProceduresGetProcColumns()
          Test DatabaseMetaData.getProcedures and .getProcedureColumns, Both for JDBC and ODBC.
 void testGetSchemasModify()
          Test getSchemas().
 void testGetSchemasReadOnly()
          Test getSchemas() without modifying the database.
 void testGetTablePrivileges()
          Test getGetTablePrivileges; does not modify database For further testing see test lang.grantRevokeTest
 void testGetTablesModify()
          Test getTables() with modifying the database.
 void testGetTablesReadOnly()
          Test getTables() without modifying the database.
 void testGetTypeInfo()
          Test getTypeInfo
 void testGetURL()
          getURL() method.
 void testGetXXportedKeys()
          Test getImportedKeys, getExportedKeys, getCrossReference; modifies db
 void testGetXXportedKeysODBC()
          Execute and check the ODBC variant of getImported/Exported keys, which uses the SQLFOREIGNKEYS system procedure to provide the same information to ODBC clients.
 void testIdentifierStorage()
          Derby stores unquoted identifiers as upper case and quoted ones as mixed case.
 void testMiscellaneous()
           
 void testMoreGetIndexInfo()
          Test getIndexInfo further; does modify database
 void testNullInfo()
          methods that return information about handling NULL.
 void testNumericFunctions()
          JDBC escaped numeric functions - JDBC 3.0 C.1
 void testReferentialAction()
          Test referential action values; modifies database
 void testSQLKeywords()
          Method getSQLKeywords, returns list of SQL keywords that are not defined by SQL92.
 void testStringFunctions()
          JDBC escaped string functions - JDBC 3.0 C.2
 void testSystemFunctions()
          JDBC escaped system functions - JDBC 3.0 C.4
 void testTableTypes()
          Test getTableTypes()
 void testTimeDataFunctions()
          JDBC escaped date time functions - JDBC 3.0 C.3
 void testUnimplementedSQLObjectAttributes()
          Test methods that describe attributes of SQL Objects that are not supported by derby.
 void testVersionInfo()
          Methods that describe the version of the driver and database.
 void verifyBRIResults(java.sql.ResultSet[] rss, java.lang.String[][] expRS)
          helper method for test testGetBestRowIdentifier
 void verifyReferentialAction(java.sql.ResultSet[] rs, short[] expRes)
           
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
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, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NUMERIC_FUNCTIONS

private static final java.lang.String[][] NUMERIC_FUNCTIONS

TIMEDATE_FUNCTIONS

private static final java.lang.String[][] TIMEDATE_FUNCTIONS

SYSTEM_FUNCTIONS

private static final java.lang.String[][] SYSTEM_FUNCTIONS

STRING_FUNCTIONS

private static final java.lang.String[][] STRING_FUNCTIONS

modifiedDatabase

private boolean modifiedDatabase
Did the test modifiy the database.


IDS

private static final java.lang.String[] IDS
Six combinations of valid identifiers with mixed case, to see how the various pattern matching and returned values handle them. This test only creates objects in these schemas.


BUILTIN_SCHEMAS

private static final java.lang.String[] BUILTIN_SCHEMAS
All the builtin schemas.

Constructor Detail

DatabaseMetaDataTest

public DatabaseMetaDataTest(java.lang.String name)
Method Detail

tearDown

protected void tearDown()
                 throws java.lang.Exception
Description copied from class: BaseJDBCTestCase
Tear down this fixture, sub-classes should call super.tearDown(). This cleanups & closes the connection if it is open and any statement objects returned through the utility methods.

Overrides:
tearDown in class BaseJDBCTestCase
Throws:
java.lang.Exception

suite

public static junit.framework.Test suite()
Default suite for running this test.


connectionPoolingSuite

private static junit.framework.Test connectionPoolingSuite(java.lang.String jdbcClient)
Returns a suite of tests to be run with connection pooling enabled.

Parameters:
jdbcClient - name of the client being used (for verbosity only)
Returns:
A suite of tests.

getSortedIdentifiers

private java.lang.String[] getSortedIdentifiers()
Return the identifiers used to create schemas, tables etc. in the order the database stores them.


getDMD

private final java.sql.DatabaseMetaData getDMD()
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException

initialCompilationTest

public void initialCompilationTest()
                            throws java.sql.SQLException
Tests that a meta-data query is compiled and stored correctly even when there's a lock on the system tables (DERBY-2584). This test must run on a fresh database (that is, getIndexInfo must not have been prepared and stored in SYS.SYSSTATEMENTS).

Throws:
java.sql.SQLException

recompileTimeoutTest

public void recompileTimeoutTest()
                          throws java.sql.SQLException
Tests that we don't get an internal timeout when a meta-data statement is recompiled because the size of the tables it queries has changed (DERBY-3693). The test must be run on a fresh database, to ensure that SYSTABLES initially has a relatively small number of records. The lock timeout must be high (more than 60 seconds) to enable us to see the difference between an internal lock timeout and slow execution. derby.language.stalePlanCheckInterval should be set to 5 (the lowest possible value) so that we don't have to wait long for the query plan to be invalidated.

Throws:
java.sql.SQLException

testDetermineFeatureSupport

public void testDetermineFeatureSupport()
                                 throws java.sql.SQLException
Test the methods that indicate if a feature is supported or not. Methods start with 'support'. See secton 7.3 in JDBC 3.0 specification.

Throws:
java.sql.SQLException

testDataSourceLimits

public void testDataSourceLimits()
                          throws java.sql.SQLException
Test group of methods provides the limits imposed by a given data source Methods start with 'getMax'. See section 7.4 in JDBC 3.0 specification. Note a return of zero from one of these functions means no limit or limit not known.

Throws:
java.sql.SQLException

testMiscellaneous

public void testMiscellaneous()
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

testVersionInfo

public void testVersionInfo()
                     throws java.sql.SQLException
Methods that describe the version of the driver and database.

Throws:
java.sql.SQLException

testGetURL

public void testGetURL()
                throws java.sql.SQLException
getURL() method. Note that this method is the only JDBC 3 DatabaseMetaData method that is dropped in JSR169.

Throws:
java.sql.SQLException

testIdentifierStorage

public void testIdentifierStorage()
                           throws java.sql.SQLException
Derby stores unquoted identifiers as upper case and quoted ones as mixed case. They are always compared case sensitive.

Throws:
java.sql.SQLException

testNullInfo

public void testNullInfo()
                  throws java.sql.SQLException
methods that return information about handling NULL.

Throws:
java.sql.SQLException

testSQLKeywords

public void testSQLKeywords()
                     throws java.sql.SQLException
Method getSQLKeywords, returns list of SQL keywords that are not defined by SQL92.

Throws:
java.sql.SQLException

testConnectionSpecific

public void testConnectionSpecific()
                            throws java.sql.SQLException
Methods that return information specific to the current connection.

Throws:
java.sql.SQLException

testConstants

public void testConstants()
This is not a test of Derby but JDBC constants for meta data that this test depends on. The constants for nullability are the same but let's check to make sure.


testUnimplementedSQLObjectAttributes

public void testUnimplementedSQLObjectAttributes()
                                          throws java.sql.SQLException
Test methods that describe attributes of SQL Objects that are not supported by derby. In each case the metadata should return an empty ResultSet of the correct shape, and with correct names, datatypes and nullability for the columns in the ResultSet.

Throws:
java.sql.SQLException

getVersionColumnsODBC

public java.sql.ResultSet getVersionColumnsODBC(java.lang.String catalog,
                                                java.lang.String schema,
                                                java.lang.String table)
                                         throws java.sql.SQLException
Implement ODBC equivalent for getVersionColumns - SYSIBM.SQLCOLUMNS

Throws:
java.sql.SQLException

getVersionColumns

private java.sql.ResultSet[] getVersionColumns(java.lang.String catalog,
                                               java.lang.String schema,
                                               java.lang.String table)
                                        throws java.sql.SQLException
Helper method for testing getVersionColumns - calls dmd.getVersionColumns for the JDBC call, and getVersionColumnsODBC for the ODBC procedure

Throws:
java.sql.SQLException

getStoredIdentifier

public static java.lang.String getStoredIdentifier(java.lang.String sqlIdentifier)

testGetSchemasReadOnly

public void testGetSchemasReadOnly()
                            throws java.sql.SQLException
Test getSchemas() without modifying the database.

Throws:
java.sql.SQLException

testGetSchemasModify

public void testGetSchemasModify()
                          throws java.sql.SQLException
Test getSchemas().

Throws:
java.sql.SQLException

createSchemasForTests

private void createSchemasForTests()
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

checkSchemas

public static void checkSchemas(java.sql.ResultSet rs,
                                java.lang.String[] userExpected)
                         throws java.sql.SQLException
Check the returned information from a getSchemas(). The passed in String[] expected is a list of the schemas expected to be present in the returned set. The returned set may contain additional schemas which will be ignored, thus this test can be used regardless of the database state. The builtin schemas are automatically checked and must not be part of the passed in list.

Throws:
java.sql.SQLException

checkSchemasShape

private static void checkSchemasShape(java.sql.ResultSet rs)
                               throws java.sql.SQLException
Check the shape of the ResultSet from any getSchemas call.

Throws:
java.sql.SQLException

getDMDTables

private java.sql.ResultSet getDMDTables(java.sql.DatabaseMetaData dmd,
                                        java.lang.String catalog,
                                        java.lang.String schema,
                                        java.lang.String table,
                                        java.lang.String[] tableTypes)
                                 throws java.sql.SQLException,
                                        java.io.IOException
Execute dmd.getTables() but perform additional checking of the ODBC variant.

Throws:
java.io.IOException
java.sql.SQLException

testGetTablesReadOnly

public void testGetTablesReadOnly()
                           throws java.sql.SQLException,
                                  java.io.IOException
Test getTables() without modifying the database.

Throws:
java.sql.SQLException
java.io.IOException

testGetTablesModify

public void testGetTablesModify()
                         throws java.sql.SQLException,
                                java.io.IOException
Test getTables() with modifying the database.

Throws:
java.sql.SQLException
java.io.IOException

checkGetTablesODBC

private void checkGetTablesODBC(java.lang.String catalog,
                                java.lang.String schema,
                                java.lang.String table,
                                java.lang.String[] tableTypes)
                         throws java.sql.SQLException,
                                java.io.IOException
Execute and check the ODBC variant of getTables which uses a procedure to provide the same information to ODBC clients.

Throws:
java.io.IOException
java.sql.SQLException

createTablesForTest

private int createTablesForTest(boolean skipXML)
                         throws java.sql.SQLException
Create a set of tables using the identifiers in IDS. For each identifier in IDS a schema is created. For each identifier in IDS create a table in every schema just created. Each table has five columns with names using the identifiers from IDS suffixed with _N where N is the column number in the table. The base name for each column is round-robined from the set of IDS. The type of each column is round-robined from the set of supported types returned by getSQLTypes.
skipXML can be set to true to create tables without any XML columns. This is useful for getColumns() testing where the fixture compares the output of DatabaseMetaData to ResultSetMetaData by a SELCT * from the table. However for XML columns they cannot be returned through JDBC yet.

Parameters:
skipXML - true if tables with the XML column should not be created.
Throws:
java.sql.SQLException

testGetColumnsReadOnly

public void testGetColumnsReadOnly()
                            throws java.sql.SQLException
Test getTableColumns(). Contents are compared to the ResultSetMetaData for a SELECT * from the table. All columns in all tables are checked.

Throws:
java.sql.SQLException

testGetColumnsModify

public void testGetColumnsModify()
                          throws java.sql.SQLException
Test getColumns() with modifying the database.

Throws:
java.sql.SQLException

assertMatchesPattern

private void assertMatchesPattern(java.lang.String pattern,
                                  java.lang.String result)

doesMatch

private boolean doesMatch(java.lang.String pattern,
                          int pp,
                          java.lang.String result,
                          int rp)
See if a string matches the pattern as defined by DatabaseMetaData. By passing in non-zero values can check sub-sets of the pattern against the sub strings of the result.
_ matches a single character
% matches zero or more characters
Other characters match themselves.

Parameters:
pattern - Pattern
pp - Position in pattern to start the actual pattern from
result - result string
rp - position in result to starting checking
Returns:
true if a match is found

getPattern

private java.lang.String getPattern(java.util.Random rand,
                                    java.lang.String[] dbIDS)

crossCheckGetColumnsAndResultSetMetaData

private void crossCheckGetColumnsAndResultSetMetaData(java.sql.ResultSet rs,
                                                      boolean partial,
                                                      int odbc)
                                               throws java.sql.SQLException
Compare a ResultSet from getColumns() with ResultSetMetaData returned from a SELECT * against the table. This method handles situations where a full set of the columns are in the ResultSet. The first action is to call rs.next(). The ResultSet will be closed by this method.

Parameters:
rs - resultset to crossCheck
partial - used to indicate if ordinal position should get checked
odbc - - flag to indicate if this was a resultset obtained from a JDBC (0) or ODBC (1) call.
Throws:
java.sql.SQLException

crossCheckGetColumnRowAndResultSetMetaData

public static void crossCheckGetColumnRowAndResultSetMetaData(java.sql.ResultSet rs,
                                                              java.sql.ResultSetMetaData rsmdt,
                                                              int odbc)
                                                       throws java.sql.SQLException
Cross check a single row from getColumns() with ResultSetMetaData for a SELECT * from the same table.

Parameters:
rs - ResultSet from getColumns already positioned on the row.
rsmdt - ResultSetMetaData for the SELECT *
odbc - 0 for JDBC call, 1 for ODBC. Needed to allow for difference in using BUFFER_LENGTH (ODBC) or no(JDBC).
Throws:
java.sql.SQLException

getColumnsODBC

private java.sql.ResultSet getColumnsODBC(java.lang.String catalog,
                                          java.lang.String schemaPattern,
                                          java.lang.String tableNamePattern,
                                          java.lang.String columnNamePattern)
                                   throws java.sql.SQLException
Implement ODBC equivalent for getColumns - SYSIBM.SQLCOLUMNS

Throws:
java.sql.SQLException

getColumns

private java.sql.ResultSet[] getColumns(java.lang.String catalog,
                                        java.lang.String schemaPattern,
                                        java.lang.String tableNamePattern,
                                        java.lang.String columnNamePattern)
                                 throws java.sql.SQLException
Helper method for testing getColumns - calls dmd.getColumns for the JDBC call, and getColumnsODBC for the ODBC procedure

Throws:
java.sql.SQLException

testTableTypes

public void testTableTypes()
                    throws java.sql.SQLException
Test getTableTypes()

Throws:
java.sql.SQLException

testGetTypeInfo

public void testGetTypeInfo()
                     throws java.sql.SQLException
Test getTypeInfo

Throws:
java.sql.SQLException

checkColumnsShape

private void checkColumnsShape(java.sql.ResultSet rs,
                               int odbc)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

checkTablesShape

private void checkTablesShape(java.sql.ResultSet rs)
                       throws java.sql.SQLException
Check the shape of the ResultSet from any getTables call. Note nullability of TABLE_CAT is not nullable for Derby even though it doesn't support catalogs because the SQL query returns a constant (empty string) for a table's catalog.

Throws:
java.sql.SQLException

checkCatalogsShape

private void checkCatalogsShape(java.sql.ResultSet rs)
                         throws java.sql.SQLException
Check the shape of the ResultSet from any getCatlogs call.

Throws:
java.sql.SQLException

checkVersionColumnsShape

private static void checkVersionColumnsShape(java.sql.ResultSet[] rs)
                                      throws java.sql.SQLException
Check the shape of the ResultSet from any getVersionColumns call.

Throws:
java.sql.SQLException

assertMetaDataResultSet

public static void assertMetaDataResultSet(java.sql.ResultSet rs,
                                           java.lang.String[] columnNames,
                                           int[] columnTypes,
                                           boolean[] nullability)
                                    throws java.sql.SQLException
Throws:
java.sql.SQLException

testNumericFunctions

public void testNumericFunctions()
                          throws java.sql.SQLException
JDBC escaped numeric functions - JDBC 3.0 C.1

Throws:
java.sql.SQLException

testStringFunctions

public void testStringFunctions()
                         throws java.sql.SQLException
JDBC escaped string functions - JDBC 3.0 C.2

Throws:
java.sql.SQLException

testTimeDataFunctions

public void testTimeDataFunctions()
                           throws java.sql.SQLException
JDBC escaped date time functions - JDBC 3.0 C.3

Throws:
java.sql.SQLException

testSystemFunctions

public void testSystemFunctions()
                         throws java.sql.SQLException
JDBC escaped system functions - JDBC 3.0 C.4

Throws:
java.sql.SQLException

escapedFunctions

private void escapedFunctions(java.lang.String[][] specList,
                              java.lang.String metaDataList)
                       throws java.sql.SQLException
Check that the list of escaped functions provided by the driver is a strict subet of the specified set, the list does not contain duplicates, all the functions listed can be executed and that if a function is not in the list but is specified it cannot be executed.

Throws:
java.sql.SQLException

executeEscaped

private void executeEscaped(java.lang.String[] specDetails)
                     throws java.sql.SQLException
Test we can execute a function listed as a supported JDBC escaped function. We don't care about the actual return value, that should be tested elsewhere in the specific test of a function.

Throws:
java.sql.SQLException

getSQLTypes

public static java.util.List getSQLTypes(java.sql.Connection conn)
                                  throws java.sql.SQLException
Return a list of all valid supported datatypes as Strings suitable for use in any SQL statement where a SQL type is expected. For variable sized types the string will have random valid length information. E.g. CHAR(37).

Throws:
java.sql.SQLException

getJDBCType

public static int getJDBCType(java.lang.String type)
Given a valid SQL type return the corresponding JDBC type identifier from java.sql.Types. Will assert if the type is not known (in future, currently just return Types.NULL).


getPrecision

public static int getPrecision(int jdbcType,
                               java.lang.String type)
Given a valid SQL type return the corresponding precision/length for this specific value if the type is variable, e.g. CHAR(5) will return 5, but LONG VARCHAR will return 0.


testGetXXportedKeysODBC

public void testGetXXportedKeysODBC()
                             throws java.sql.SQLException,
                                    java.io.IOException
Execute and check the ODBC variant of getImported/Exported keys, which uses the SQLFOREIGNKEYS system procedure to provide the same information to ODBC clients. Note that for "correctness" we just compare the results to those of the equivalent JDBC calls; this fixture assumes that the the JDBC calls return correct results (testing of the JDBC results occurs elsewhere, see fixtures testGetXXportedKeys()

Throws:
java.sql.SQLException
java.io.IOException

checkODBCKeys

private void checkODBCKeys(java.lang.String pCatalog,
                           java.lang.String pSchema,
                           java.lang.String pTable,
                           java.lang.String fCatalog,
                           java.lang.String fSchema,
                           java.lang.String fTable)
                    throws java.sql.SQLException,
                           java.io.IOException
Execute a call to the ODBC system procedure "SQLFOREIGNKEYS" and verify the results by comparing them with the results of an equivalent JDBC call (if one exists).

Throws:
java.sql.SQLException
java.io.IOException

checkODBCKeysShape

private void checkODBCKeysShape(java.sql.ResultSet rs)
                         throws java.sql.SQLException
Check the shape of the ResultSet from a call to the ODBC function SQLForeignKeys.

Throws:
java.sql.SQLException

testGetBestRowIdentifier

public void testGetBestRowIdentifier()
                              throws java.sql.SQLException
Test getBestRowIdentifier

Throws:
java.sql.SQLException

getBestRowIdentifierODBC

private java.sql.ResultSet getBestRowIdentifierODBC(java.lang.String catalog,
                                                    java.lang.String schema,
                                                    java.lang.String table,
                                                    int scope,
                                                    boolean nullable)
                                             throws java.sql.SQLException
Helper method for testing getBestRowIdentifier - calls the ODBC procedure

Throws:
java.sql.SQLException

getBestRowIdentifier

private java.sql.ResultSet[] getBestRowIdentifier(java.lang.String catalog,
                                                  java.lang.String schema,
                                                  java.lang.String table,
                                                  int scope,
                                                  boolean nullable)
                                           throws java.sql.SQLException
Helper method for testing getBestRowIdentifier - calls dmd.getBestRowIdentifier for the JDBC call, and getBestRowIdentifierODBC for the ODBC procedure

Throws:
java.sql.SQLException

verifyBRIResults

public void verifyBRIResults(java.sql.ResultSet[] rss,
                             java.lang.String[][] expRS)
                      throws java.sql.SQLException
helper method for test testGetBestRowIdentifier

Parameters:
rss - - ResultSet array from getBestRowIdentifier; rss[0] will have the JDBC result, rss[1] the ODBC result
expRS - - bidimensional String array with expected result row(s)
Throws:
java.sql.SQLException

testGetColumnPrivileges

public void testGetColumnPrivileges()
                             throws java.sql.SQLException
Test getGetColumnPrivileges; does not modify database For further testing see test lang.grantRevokeTest

Throws:
java.sql.SQLException

getColumnPrivilegesODBC

private java.sql.ResultSet getColumnPrivilegesODBC(java.lang.String catalog,
                                                   java.lang.String schema,
                                                   java.lang.String table,
                                                   java.lang.String columnNamePattern)
                                            throws java.sql.SQLException
Helper method for testing getColumnPrivileges - calls the ODBC procedure

Throws:
java.sql.SQLException

getColumnPrivileges

private java.sql.ResultSet[] getColumnPrivileges(java.lang.String catalog,
                                                 java.lang.String schema,
                                                 java.lang.String table,
                                                 java.lang.String columnNamePattern)
                                          throws java.sql.SQLException
Helper method for testing getColumnPrivileges - calls dmd.getIndexInfo for the JDBC call, and getColumnPrivilegesODBC for the ODBC procedure

Throws:
java.sql.SQLException

testGetTablePrivileges

public void testGetTablePrivileges()
                            throws java.sql.SQLException
Test getGetTablePrivileges; does not modify database For further testing see test lang.grantRevokeTest

Throws:
java.sql.SQLException

getTablePrivilegesODBC

private java.sql.ResultSet getTablePrivilegesODBC(java.lang.String catalog,
                                                  java.lang.String schema,
                                                  java.lang.String tableNamePattern)
                                           throws java.sql.SQLException
Helper method for testing getTablePrivileges - calls the ODBC procedure

Throws:
java.sql.SQLException

getTablePrivileges

private java.sql.ResultSet[] getTablePrivileges(java.lang.String catalog,
                                                java.lang.String schema,
                                                java.lang.String tableNamePattern)
                                         throws java.sql.SQLException
Helper method for testing getTablePrivileges - calls dmd.getIndexInfo for the JDBC call, and getTablePrivilegesODBC for the ODBC procedure

Throws:
java.sql.SQLException

testGetIndexInfo

public void testGetIndexInfo()
                      throws java.sql.SQLException
Test getIndexInfo; does not modify database

Throws:
java.sql.SQLException

testMoreGetIndexInfo

public void testMoreGetIndexInfo()
                          throws java.sql.SQLException
Test getIndexInfo further; does modify database

Throws:
java.sql.SQLException

getIndexInfoODBC

private java.sql.ResultSet getIndexInfoODBC(java.lang.String catalog,
                                            java.lang.String schema,
                                            java.lang.String table,
                                            boolean unique,
                                            boolean approximate)
                                     throws java.sql.SQLException
Helper method for testing getIndexInfo - calls the ODBC procedure

Throws:
java.sql.SQLException

getIndexInfo

private java.sql.ResultSet[] getIndexInfo(java.lang.String catalog,
                                          java.lang.String schema,
                                          java.lang.String table,
                                          boolean unique,
                                          boolean approximate)
                                   throws java.sql.SQLException
Helper method for testing getIndexInfo - calls dmd.getIndexInfo for the JDBC call, and getIndexInfoODBC for the ODBC procedure

Throws:
java.sql.SQLException

assertFullResultSet

private void assertFullResultSet(java.sql.ResultSet[] rs,
                                 java.lang.String[][] expRS,
                                 boolean trim)
                          throws java.sql.SQLException
Helper method - unravles a ResultSet array created e.g. with this.getIndexInfo, i.e. Resultset[0] has the JDBC resultset and ResultSet[1] the ODBC resultset

Throws:
java.sql.SQLException

createObjectsForKeysTests

private void createObjectsForKeysTests()
                                throws java.sql.SQLException
Create the tables for get*Keys tests

Throws:
java.sql.SQLException

dropObjectsForKeysTests

private void dropObjectsForKeysTests()
                              throws java.sql.SQLException
Drop the database objects for get*Keys tests

Throws:
java.sql.SQLException

testGetPrimaryKeys

public void testGetPrimaryKeys()
                        throws java.sql.SQLException
Test getPrimaryKeys; does modify database

Throws:
java.sql.SQLException

getPrimaryKeysODBC

private java.sql.ResultSet getPrimaryKeysODBC(java.lang.String catalog,
                                              java.lang.String schema,
                                              java.lang.String table)
                                       throws java.sql.SQLException
Helper method for testing getPrimaryKeys - calls the ODBC procedure

Throws:
java.sql.SQLException

getPrimaryKeys

private java.sql.ResultSet[] getPrimaryKeys(java.lang.String catalog,
                                            java.lang.String schema,
                                            java.lang.String table)
                                     throws java.sql.SQLException
Helper method for testing getPrimaryKeys - calls dmd.getPrimaryKeys for the JDBC call, and getPrimaryKeysODBC for the ODBC procedure

Throws:
java.sql.SQLException

testGetXXportedKeys

public void testGetXXportedKeys()
                         throws java.sql.SQLException
Test getImportedKeys, getExportedKeys, getCrossReference; modifies db

Throws:
java.sql.SQLException

getImportedKeysODBC

private java.sql.ResultSet getImportedKeysODBC(java.lang.String catalog,
                                               java.lang.String schema,
                                               java.lang.String table)
                                        throws java.sql.SQLException
Helper method for testing getImportedKeys - calls the ODBC procedure

Throws:
java.sql.SQLException

getImportedKeys

private java.sql.ResultSet[] getImportedKeys(java.lang.String catalog,
                                             java.lang.String schema,
                                             java.lang.String table)
                                      throws java.sql.SQLException
Helper method for testing getImportedKeys - calls dmd.getImportedKeys for the JDBC call, and getImportedKeysODBC for the ODBC procedure

Throws:
java.sql.SQLException

assertGetImportedAndExportedKeysShape

private void assertGetImportedAndExportedKeysShape(java.sql.ResultSet[] rss)
                                            throws java.sql.SQLException
Assert the shape of the ResultSets for getImportedKeys, getExportedKeys and getCrossReference.

Parameters:
rss - ResultSets from JDBC and ODBC calls.
Throws:
java.sql.SQLException

getExportedKeysODBC

private java.sql.ResultSet getExportedKeysODBC(java.lang.String catalog,
                                               java.lang.String schema,
                                               java.lang.String table)
                                        throws java.sql.SQLException
Helper method for testing getExportedKeys - calls the ODBC procedure

Throws:
java.sql.SQLException

getExportedKeys

private java.sql.ResultSet[] getExportedKeys(java.lang.String catalog,
                                             java.lang.String schema,
                                             java.lang.String table)
                                      throws java.sql.SQLException
Helper method for testing getExportedKeys - calls dmd.getExportedKeys for the JDBC call, and getExportedKeysODBC for the ODBC procedure

Throws:
java.sql.SQLException

getCrossReferenceODBC

private java.sql.ResultSet getCrossReferenceODBC(java.lang.String parentcatalog,
                                                 java.lang.String parentschema,
                                                 java.lang.String parenttable,
                                                 java.lang.String foreigncatalog,
                                                 java.lang.String foreignschema,
                                                 java.lang.String foreigntable)
                                          throws java.sql.SQLException
Helper method for testing getCrossReference - calls the ODBC procedure

Throws:
java.sql.SQLException

getCrossReference

private java.sql.ResultSet[] getCrossReference(java.lang.String parentcatalog,
                                               java.lang.String parentschema,
                                               java.lang.String parenttable,
                                               java.lang.String foreigncatalog,
                                               java.lang.String foreignschema,
                                               java.lang.String foreigntable)
                                        throws java.sql.SQLException
Helper method for testing getCrossReference - calls dmd.getCrossReference for the JDBC call, and getCrossReferenceODBC for the ODBC procedure

Throws:
java.sql.SQLException

testReferentialAction

public void testReferentialAction()
                           throws java.sql.SQLException
Test referential action values; modifies database

Throws:
java.sql.SQLException

verifyReferentialAction

public void verifyReferentialAction(java.sql.ResultSet[] rs,
                                    short[] expRes)
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

testGetProceduresGetProcColumns

public void testGetProceduresGetProcColumns()
                                     throws java.sql.SQLException
Test DatabaseMetaData.getProcedures and .getProcedureColumns, Both for JDBC and ODBC. Further testing of these methods is done in lang/LangProcedureTest

Throws:
SQLexception
java.sql.SQLException

getProceduresODBC

private java.sql.ResultSet getProceduresODBC(java.lang.String catalog,
                                             java.lang.String schemaPattern,
                                             java.lang.String procedureNamePattern)
                                      throws java.sql.SQLException
Helper method for testing getProcedures - calls the ODBC procedure

Throws:
java.sql.SQLException

getProcedures

private java.sql.ResultSet[] getProcedures(java.lang.String catalog,
                                           java.lang.String schemaPattern,
                                           java.lang.String procedureNamePattern)
                                    throws java.sql.SQLException
Helper method for testing getProcedures - calls dmd.getProcedures for the JDBC call, and getProceduresODBC for the ODBC procedure

Throws:
java.sql.SQLException

getProcedureColumnsODBC

private java.sql.ResultSet getProcedureColumnsODBC(java.lang.String catalog,
                                                   java.lang.String schemaPattern,
                                                   java.lang.String procedureNamePattern,
                                                   java.lang.String columnNamePattern)
                                            throws java.sql.SQLException
Helper method for testing getProcedureColumns - calls the ODBC procedure

Throws:
java.sql.SQLException

getProcedureColumns

private java.sql.ResultSet[] getProcedureColumns(java.lang.String catalog,
                                                 java.lang.String schemaPattern,
                                                 java.lang.String procedureNamePattern,
                                                 java.lang.String columnNamePattern)
                                          throws java.sql.SQLException
Helper method for testing getProcedureColumns - calls dmd.getProcedureColumns for the JDBC call, and getProcedureColumnssODBC for the ODBC procedure

Throws:
java.sql.SQLException

testBugFixes

public void testBugFixes()
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

isro

public static void isro()
                 throws java.sql.SQLException
method used in testBugFixes, for testing nexted connection metadata

Throws:
java.sql.SQLException

getpc

public static byte[] getpc(java.lang.String a,
                           java.math.BigDecimal b,
                           short c,
                           byte d,
                           short e,
                           int f,
                           long g,
                           float h,
                           double i,
                           byte[] j,
                           java.sql.Date k,
                           java.sql.Time l,
                           java.sql.Timestamp T)
dummy method to test getProcedureColumns


getpc

public static void getpc(int a,
                         long[] b)
overload getpc to further test getProcedureColumns


getpc

private static void getpc(int a,
                          long b)
overload getpc to further test getProcedureColumns private method shouldn't be returned with alias, ok with procedure


getpc

public void getpc(java.lang.String a,
                  java.lang.String b)
instance method for getProcedureColumns testing with method alias, this should not be returned by getProcedureColumns but DB2 returns this with a java procedure


getpc4a

public static void getpc4a()
this method should notbe seen by getProcedureColumns as it has no parameters and no return value.


getpc4b

public static int getpc4b()
check a method with no paramters and a return value works for getProcedureColumns


testDMDconnClosed

public void testDMDconnClosed()
                       throws java.sql.SQLException
Reading of DatabaseMetaData obtained earlier, after a connection is closed.

Throws:
java.sql.SQLException

Built on Thu 2009-11-26 18:42:53-0800, from revision 884739

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.