Skip to content

Commit 1ffd044

Browse files
author
Dave Cramer
committed
added imported/exported key testDatabaseMetaDataTest.java
1 parent 970ff81 commit 1ffd044

File tree

2 files changed

+101
-7
lines changed

2 files changed

+101
-7
lines changed

src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* PS: Do you know how difficult it is to type on a train? ;-)
1111
*
12-
* $Id: DatabaseMetaDataTest.java,v 1.5 2002/04/16 15:25:17 davec Exp $
12+
* $Id: DatabaseMetaDataTest.java,v 1.6 2002/05/30 16:26:55 davec Exp $
1313
*/
1414

1515
public class DatabaseMetaDataTest extends TestCase
@@ -32,7 +32,7 @@ protected void setUp() throws Exception
3232
protected void tearDown() throws Exception
3333
{
3434
JDBC2Tests.dropTable( con, "testmetadata" );
35-
35+
3636
JDBC2Tests.closeDB( con );
3737
}
3838
/*
@@ -51,23 +51,23 @@ public void testGetMetaData()
5151
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
5252

5353
rs.close();
54-
54+
5555
rs = dbmd.getColumns("", "", "test%", "%" );
5656
assertTrue( rs.next() );
5757
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
5858
assertTrue( rs.getString("COLUMN_NAME").equals("id") );
5959
assertTrue( rs.getInt("DATA_TYPE") == java.sql.Types.INTEGER );
60-
60+
6161
assertTrue( rs.next() );
6262
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
6363
assertTrue( rs.getString("COLUMN_NAME").equals("name") );
6464
assertTrue( rs.getInt("DATA_TYPE") == java.sql.Types.VARCHAR );
65-
65+
6666
assertTrue( rs.next() );
6767
assertTrue( rs.getString("TABLE_NAME").equals("testmetadata") );
6868
assertTrue( rs.getString("COLUMN_NAME").equals("updated") );
6969
assertTrue( rs.getInt("DATA_TYPE") == java.sql.Types.TIMESTAMP );
70-
70+
7171
}
7272
catch (SQLException ex)
7373
{
@@ -228,6 +228,75 @@ public void testIdentifiers()
228228
}
229229
}
230230

231+
public void testForeignKeys()
232+
{
233+
try
234+
{
235+
Connection con1 = JDBC2Tests.openDB();
236+
JDBC2Tests.createTable( con1, "people", "id int4 primary key, name text" );
237+
JDBC2Tests.createTable( con1, "policy", "id int4 primary key, name text" );
238+
JDBC2Tests.createTable( con1, "users", "id int4 primary key, people_id int4, policy_id int4,"+
239+
"CONSTRAINT people FOREIGN KEY (people_id) references people(id),"+
240+
"constraint policy FOREIGN KEY (policy_id) references policy(id)" );
241+
242+
243+
DatabaseMetaData dbmd = con.getMetaData();
244+
assertNotNull(dbmd);
245+
246+
ResultSet rs = dbmd.getImportedKeys(null, "", "users" );
247+
int j = 0;
248+
for (; rs.next(); j++ )
249+
{
250+
251+
String pkTableName = rs.getString( "PKTABLE_NAME" );
252+
assertTrue ( pkTableName.equals("people") || pkTableName.equals("policy") );
253+
254+
String pkColumnName = rs.getString( "PKCOLUMN_NAME" );
255+
assertTrue( pkColumnName.equals("id") );
256+
257+
String fkTableName = rs.getString( "FKTABLE_NAME" );
258+
assertTrue( fkTableName.equals( "users" ) );
259+
260+
String fkColumnName = rs.getString( "FKCOLUMN_NAME" );
261+
assertTrue( fkColumnName.equals( "people_id" ) || fkColumnName.equals( "policy_id" ) ) ;
262+
263+
String fkName = rs.getString( "FK_NAME" );
264+
assertTrue( fkName.equals( "people") || fkName.equals( "policy" ) );
265+
266+
String pkName = rs.getString( "PK_NAME" );
267+
268+
}
269+
270+
assertTrue ( j== 2 );
271+
272+
rs = dbmd.getExportedKeys( null, "", "people" );
273+
274+
// this is hacky, but it will serve the purpose
275+
assertTrue ( rs.next() );
276+
277+
for (int i = 0; i < 14 ; i++ )
278+
{
279+
assertTrue( rs.getString( "PKTABLE_NAME" ).equals( "people" ) );
280+
assertTrue( rs.getString( "PKCOLUMN_NAME" ).equals( "id" ) );
281+
282+
assertTrue( rs.getString( "FKTABLE_NAME" ).equals( "users" ) );
283+
assertTrue( rs.getString( "FKCOLUMN_NAME" ).equals( "people_id" ) );
284+
285+
assertTrue( rs.getString( "FK_NAME" ).equals( "people" ) );
286+
287+
}
288+
289+
290+
JDBC2Tests.dropTable( con1, "users" );
291+
JDBC2Tests.dropTable( con1, "people" );
292+
JDBC2Tests.dropTable( con1, "policy" );
293+
294+
}
295+
catch (SQLException ex)
296+
{
297+
fail(ex.getMessage());
298+
}
299+
}
231300
public void testTables()
232301
{
233302
try

src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.sql.*;
66

77
/*
8-
* $Id: MiscTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $
8+
* $Id: MiscTest.java,v 1.5 2002/05/30 16:26:55 davec Exp $
99
*
1010
* Some simple tests based on problems reported by users. Hopefully these will
1111
* help prevent previous problems from re-occuring ;-)
@@ -51,4 +51,29 @@ public void testDatabaseSelectNullBug()
5151
fail(ex.getMessage());
5252
}
5353
}
54+
55+
public void xtestLocking()
56+
{
57+
58+
System.out.println("testing lock");
59+
try
60+
{
61+
Connection con = JDBC2Tests.openDB();
62+
Connection con2 = JDBC2Tests.openDB();
63+
64+
JDBC2Tests.createTable(con, "test_lock", "name text");
65+
Statement st = con.createStatement();
66+
Statement st2 = con2.createStatement();
67+
con.setAutoCommit(false);
68+
st.execute("lock table test_lock");
69+
st2.executeUpdate( "insert into test_lock ( name ) values ('hello')" );
70+
con.commit();
71+
JDBC2Tests.dropTable(con, "test_lock");
72+
con.close();
73+
}
74+
catch ( Exception ex )
75+
{
76+
fail( ex.getMessage() );
77+
}
78+
}
5479
}

0 commit comments

Comments
 (0)