Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41a20bb

Browse files
committed
jdbc2 implementation of getImportedKeys.
Ola Sundell
1 parente046e1d commit41a20bb

File tree

1 file changed

+109
-3
lines changed

1 file changed

+109
-3
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ public boolean supportsOpenCursorsAcrossRollback() throws SQLException
10481048
/**
10491049
* Can statements remain open across commits? They may, but
10501050
* this driver cannot guarentee that. In further reflection.
1051-
* we are talking a Statement objectjere, so the answer is
1051+
* we are talking a Statement objecthere, so the answer is
10521052
* yes, since the Statement is only a vehicle to ExecSQL()
10531053
*
10541054
* @return true if they always remain open; false otherwise
@@ -2183,6 +2183,81 @@ public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String t
21832183
);
21842184
}
21852185

2186+
privateVectorimportLoop(java.sql.ResultSetkeyRelation)throwsSQLException {
2187+
Strings,s2;
2188+
StringorigTable=null,primTable=newString(""),schema;
2189+
inti;
2190+
Vectorv;
2191+
2192+
s=keyRelation.getString(1);
2193+
s2=s;
2194+
System.out.println(s);
2195+
v=newVector();
2196+
for (i=0;;i++) {
2197+
s=s.substring(s.indexOf("\\000")+4);
2198+
if (s.compareTo("")==0) {
2199+
System.out.println();
2200+
break;
2201+
}
2202+
s2=s.substring(0,s.indexOf("\\000"));
2203+
switch (i) {
2204+
case0:
2205+
origTable=s2;
2206+
break;
2207+
case1:
2208+
primTable=s2;
2209+
break;
2210+
case2:
2211+
schema=s2;
2212+
break;
2213+
default:
2214+
v.add(s2);
2215+
}
2216+
}
2217+
2218+
java.sql.ResultSetrstmp=connection.ExecSQL("select * from "+origTable+" where 1=0");
2219+
java.sql.ResultSetMetaDataorigCols=rstmp.getMetaData();
2220+
2221+
Stringstmp;
2222+
Vectortuples=newVector();
2223+
bytetuple[][];
2224+
2225+
// the foreign keys are only on even positions in the Vector.
2226+
for (i=0;i<v.size();i+=2) {
2227+
stmp=(String)v.elementAt(i);
2228+
2229+
for (intj=1;j<=origCols.getColumnCount();j++) {
2230+
if (stmp.compareTo(origCols.getColumnName(j))==0) {
2231+
tuple=newbyte[14][0];
2232+
2233+
for (intk=0;k<14;k++)
2234+
tuple[k]=null;
2235+
2236+
//PKTABLE_NAME
2237+
tuple[2]=primTable.getBytes();
2238+
//PKTABLE_COLUMN
2239+
stmp=(String)v.elementAt(i+1);
2240+
tuple[3]=stmp.getBytes();
2241+
//FKTABLE_NAME
2242+
tuple[6]=origTable.getBytes();
2243+
//FKCOLUMN_NAME
2244+
tuple[7]=origCols.getColumnName(j).getBytes();
2245+
//KEY_SEQ
2246+
tuple[8]=Integer.toString(j).getBytes();
2247+
2248+
tuples.add(tuple);
2249+
2250+
System.out.println(origCols.getColumnName(j)+
2251+
": "+j+" -> "+primTable+": "+
2252+
(String)v.elementAt(i+1));
2253+
break;
2254+
}
2255+
}
2256+
}
2257+
2258+
returntuples;
2259+
}
2260+
21862261
/**
21872262
* Get a description of the primary key columns that are
21882263
* referenced by a table's foreign key columns (the primary keys
@@ -2236,8 +2311,39 @@ public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String t
22362311
*/
22372312
publicjava.sql.ResultSetgetImportedKeys(Stringcatalog,Stringschema,Stringtable)throwsSQLException
22382313
{
2239-
// XXX-Not Implemented
2240-
returnnull;
2314+
// Added by Ola Sundell <ola@miranda.org>
2315+
// FIXME: error checking galore!
2316+
java.sql.ResultSetrsret;
2317+
Fieldf[]=newField[14];
2318+
bytetuple[][];
2319+
2320+
f[0]=newField(connection,"PKTABLE_CAT",iVarcharOid,32);
2321+
f[1]=newField(connection,"PKTABLE_SCHEM",iVarcharOid,32);
2322+
f[2]=newField(connection,"PKTABLE_NAME",iVarcharOid,32);
2323+
f[3]=newField(connection,"PKCOLUMN_NAME",iVarcharOid,32);
2324+
f[4]=newField(connection,"FKTABLE_CAT",iVarcharOid,32);
2325+
f[5]=newField(connection,"FKTABLE_SCHEM",iVarcharOid,32);
2326+
f[6]=newField(connection,"FKTABLE_NAME",iVarcharOid,32);
2327+
f[7]=newField(connection,"FKCOLUMN_NAME",iVarcharOid,32);
2328+
f[8]=newField(connection,"KEY_SEQ",iInt2Oid,2);
2329+
f[9]=newField(connection,"UPDATE_RULE",iInt2Oid,2);
2330+
f[10]=newField(connection,"DELETE_RULE",iInt2Oid,2);
2331+
f[11]=newField(connection,"FK_NAME",iVarcharOid,32);
2332+
f[12]=newField(connection,"PK_NAME",iVarcharOid,32);
2333+
f[13]=newField(connection,"DEFERRABILITY",iInt2Oid,2);
2334+
2335+
java.sql.ResultSetrs=connection.ExecSQL("select t.tgargs "+
2336+
"from pg_class as c, pg_trigger as t "+
2337+
"where c.relname like '"+table+"' and c.relfilenode=t.tgrelid");
2338+
Vectortuples=newVector();
2339+
2340+
while (rs.next()) {
2341+
tuples.addAll(importLoop(rs));
2342+
}
2343+
2344+
rsret=newResultSet(connection,f,tuples,"OK",1);
2345+
2346+
returnrsret;
22412347
}
22422348

22432349
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp