added imported/exported key testDatabaseMetaDataTest.java
This commit is contained in:
parent
970ff81e2f
commit
1ffd044af7
@ -9,7 +9,7 @@ import java.sql.*;
|
||||
*
|
||||
* PS: Do you know how difficult it is to type on a train? ;-)
|
||||
*
|
||||
* $Id: DatabaseMetaDataTest.java,v 1.5 2002/04/16 15:25:17 davec Exp $
|
||||
* $Id: DatabaseMetaDataTest.java,v 1.6 2002/05/30 16:26:55 davec Exp $
|
||||
*/
|
||||
|
||||
public class DatabaseMetaDataTest extends TestCase
|
||||
@ -32,7 +32,7 @@ public class DatabaseMetaDataTest extends TestCase
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
JDBC2Tests.dropTable( con, "testmetadata" );
|
||||
|
||||
|
||||
JDBC2Tests.closeDB( con );
|
||||
}
|
||||
/*
|
||||
@ -51,23 +51,23 @@ public class DatabaseMetaDataTest extends TestCase
|
||||
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
|
||||
|
||||
rs.close();
|
||||
|
||||
|
||||
rs = dbmd.getColumns("", "", "test%", "%" );
|
||||
assertTrue( rs.next() );
|
||||
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
|
||||
assertTrue( rs.getString("COLUMN_NAME").equals("id") );
|
||||
assertTrue( rs.getInt("DATA_TYPE") == java.sql.Types.INTEGER );
|
||||
|
||||
|
||||
assertTrue( rs.next() );
|
||||
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
|
||||
assertTrue( rs.getString("COLUMN_NAME").equals("name") );
|
||||
assertTrue( rs.getInt("DATA_TYPE") == java.sql.Types.VARCHAR );
|
||||
|
||||
|
||||
assertTrue( rs.next() );
|
||||
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
|
||||
assertTrue( rs.getString("COLUMN_NAME").equals("updated") );
|
||||
assertTrue( rs.getInt("DATA_TYPE") == java.sql.Types.TIMESTAMP );
|
||||
|
||||
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
@ -228,6 +228,75 @@ public class DatabaseMetaDataTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testForeignKeys()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection con1 = JDBC2Tests.openDB();
|
||||
JDBC2Tests.createTable( con1, "people", "id int4 primary key, name text" );
|
||||
JDBC2Tests.createTable( con1, "policy", "id int4 primary key, name text" );
|
||||
JDBC2Tests.createTable( con1, "users", "id int4 primary key, people_id int4, policy_id int4,"+
|
||||
"CONSTRAINT people FOREIGN KEY (people_id) references people(id),"+
|
||||
"constraint policy FOREIGN KEY (policy_id) references policy(id)" );
|
||||
|
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData();
|
||||
assertNotNull(dbmd);
|
||||
|
||||
ResultSet rs = dbmd.getImportedKeys(null, "", "users" );
|
||||
int j = 0;
|
||||
for (; rs.next(); j++ )
|
||||
{
|
||||
|
||||
String pkTableName = rs.getString( "PKTABLE_NAME" );
|
||||
assertTrue ( pkTableName.equals("people") || pkTableName.equals("policy") );
|
||||
|
||||
String pkColumnName = rs.getString( "PKCOLUMN_NAME" );
|
||||
assertTrue( pkColumnName.equals("id") );
|
||||
|
||||
String fkTableName = rs.getString( "FKTABLE_NAME" );
|
||||
assertTrue( fkTableName.equals( "users" ) );
|
||||
|
||||
String fkColumnName = rs.getString( "FKCOLUMN_NAME" );
|
||||
assertTrue( fkColumnName.equals( "people_id" ) || fkColumnName.equals( "policy_id" ) ) ;
|
||||
|
||||
String fkName = rs.getString( "FK_NAME" );
|
||||
assertTrue( fkName.equals( "people") || fkName.equals( "policy" ) );
|
||||
|
||||
String pkName = rs.getString( "PK_NAME" );
|
||||
|
||||
}
|
||||
|
||||
assertTrue ( j== 2 );
|
||||
|
||||
rs = dbmd.getExportedKeys( null, "", "people" );
|
||||
|
||||
// this is hacky, but it will serve the purpose
|
||||
assertTrue ( rs.next() );
|
||||
|
||||
for (int i = 0; i < 14 ; i++ )
|
||||
{
|
||||
assertTrue( rs.getString( "PKTABLE_NAME" ).equals( "people" ) );
|
||||
assertTrue( rs.getString( "PKCOLUMN_NAME" ).equals( "id" ) );
|
||||
|
||||
assertTrue( rs.getString( "FKTABLE_NAME" ).equals( "users" ) );
|
||||
assertTrue( rs.getString( "FKCOLUMN_NAME" ).equals( "people_id" ) );
|
||||
|
||||
assertTrue( rs.getString( "FK_NAME" ).equals( "people" ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
JDBC2Tests.dropTable( con1, "users" );
|
||||
JDBC2Tests.dropTable( con1, "people" );
|
||||
JDBC2Tests.dropTable( con1, "policy" );
|
||||
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
public void testTables()
|
||||
{
|
||||
try
|
||||
|
@ -5,7 +5,7 @@ import junit.framework.TestCase;
|
||||
import java.sql.*;
|
||||
|
||||
/*
|
||||
* $Id: MiscTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $
|
||||
* $Id: MiscTest.java,v 1.5 2002/05/30 16:26:55 davec Exp $
|
||||
*
|
||||
* Some simple tests based on problems reported by users. Hopefully these will
|
||||
* help prevent previous problems from re-occuring ;-)
|
||||
@ -51,4 +51,29 @@ public class MiscTest extends TestCase
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void xtestLocking()
|
||||
{
|
||||
|
||||
System.out.println("testing lock");
|
||||
try
|
||||
{
|
||||
Connection con = JDBC2Tests.openDB();
|
||||
Connection con2 = JDBC2Tests.openDB();
|
||||
|
||||
JDBC2Tests.createTable(con, "test_lock", "name text");
|
||||
Statement st = con.createStatement();
|
||||
Statement st2 = con2.createStatement();
|
||||
con.setAutoCommit(false);
|
||||
st.execute("lock table test_lock");
|
||||
st2.executeUpdate( "insert into test_lock ( name ) values ('hello')" );
|
||||
con.commit();
|
||||
JDBC2Tests.dropTable(con, "test_lock");
|
||||
con.close();
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
fail( ex.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user