77
77
assertEquals(rs.getInt("DATA_TYPE"), java.sql.Types.INTEGER);
78
78
assertEquals(rs.getString("TYPE_NAME"), "int");
82
/** Same as getImportedKeys, with one foreign key in a table in another catalog */
84
public void getImportedKeys() throws Exception{
85
Statement st = connection.createStatement();
87
st.execute("DROP TABLE IF EXISTS product_order");
88
st.execute("DROP TABLE IF EXISTS t1.product ");
89
st.execute("DROP TABLE IF EXISTS `cus``tomer`");
90
st.execute("DROP DATABASE IF EXISTS test1");
92
st.execute("CREATE DATABASE IF NOT EXISTS t1");
94
st.execute("CREATE TABLE t1.product (\n" +
95
" category INT NOT NULL, id INT NOT NULL,\n" +
97
" PRIMARY KEY(category, id)\n" +
100
st.execute("CREATE TABLE `cus``tomer` (\n" +
101
" id INT NOT NULL,\n" +
102
" PRIMARY KEY (id)\n" +
105
st.execute("CREATE TABLE product_order (\n" +
106
" no INT NOT NULL AUTO_INCREMENT,\n" +
107
" product_category INT NOT NULL,\n" +
108
" product_id INT NOT NULL,\n" +
109
" customer_id INT NOT NULL,\n" +
111
" PRIMARY KEY(no),\n" +
112
" INDEX (product_category, product_id),\n" +
113
" INDEX (customer_id),\n" +
115
" FOREIGN KEY (product_category, product_id)\n" +
116
" REFERENCES t1.product(category, id)\n" +
117
" ON UPDATE CASCADE ON DELETE RESTRICT,\n" +
119
" FOREIGN KEY (customer_id)\n" +
120
" REFERENCES `cus``tomer`(id)\n" +
126
Test that I_S implementation is equivalent to parsing "show create table" .
127
Get result sets using either method and compare (ignore minor differences INT vs SMALLINT
129
ResultSet rs1 = ((MySQLDatabaseMetaData)connection.getMetaData()).getImportedKeysUsingShowCreateTable("test", null, "product_order");
130
ResultSet rs2 = ((MySQLDatabaseMetaData)connection.getMetaData()).getImportedKeysUsingInformationSchema("test", null, "product_order");
131
assertEquals(rs1.getMetaData().getColumnCount(), rs2.getMetaData().getColumnCount());
135
assertTrue(rs2.next());
136
for (int i = 1; i <= rs1.getMetaData().getColumnCount(); i++) {
137
Object s1 = rs1.getObject(i);
138
Object s2 = rs2.getObject(i);
139
if (s1 instanceof Number && s2 instanceof Number) {
140
assertEquals(((Number)s1).intValue(), ((Number)s2).intValue());
142
if (s1 != null && s2 != null && !s1.equals(s2)) {
143
System.out.println("s1= " + s1 + "," + "s2 = " + s2) ;
150
/* Also compare metadata */
151
ResultSetMetaData md1 = rs1.getMetaData();
152
ResultSetMetaData md2 = rs2.getMetaData();
153
for (int i = 1; i <= md1.getColumnCount(); i++) {
154
assertEquals(md1.getColumnLabel(i),md2.getColumnLabel(i));
159
public void ttt() throws Exception {
160
ResultSet rs = connection.getMetaData().getImportedKeys("test",null,"product_order");
164
System.out.println( "" + k + " ===================");
165
for (int i = 1 ; i <= rs.getMetaData().getColumnCount();i++) {
166
System.out.println(rs.getMetaData().getColumnLabel(i) + " = " + rs.getObject(i));
82
171
public void exportedKeysTest() throws SQLException {
83
172
Statement stmt = connection.createStatement();