|
13 | 13 | /**
|
14 | 14 | * This class provides information about the database as a whole.
|
15 | 15 | *
|
16 |
| - * $Id: DatabaseMetaData.java,v 1.37 2001/11/02 23:50:08 davec Exp $ |
| 16 | + * $Id: DatabaseMetaData.java,v 1.38 2001/11/09 02:57:25 davec Exp $ |
17 | 17 | *
|
18 | 18 | * <p>Many of the methods here return lists of information in ResultSets. You
|
19 | 19 | * can use the normal ResultSet methods such as getString and getInt to
|
@@ -2272,72 +2272,117 @@ public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String t
|
2272 | 2272 | );
|
2273 | 2273 | }
|
2274 | 2274 |
|
2275 |
| -privatevoidparseConstraint(java.sql.ResultSetkeyRelation,Vectortuples)throwsSQLException |
| 2275 | +privatejava.sql.ResultSetgetImportedExportedKeys(Stringcatalog,Stringschema,StringprimaryTable,StringforeignTable)throwsSQLException |
2276 | 2276 | {
|
2277 |
| -bytetuple[][]=newbyte[14][0]; |
2278 |
| -for (intk =0;k <14;k++) |
2279 |
| -tuple[k] =null; |
2280 |
| -Strings=keyRelation.getString(1); |
2281 |
| -intpos=s.indexOf("\\000"); |
2282 |
| -if(pos>-1) |
2283 |
| - { |
2284 |
| -tuple[11]=s.substring(0,pos).getBytes();;// FK_NAME |
2285 |
| -intpos2=s.indexOf("\\000",pos+1); |
2286 |
| -if(pos2>-1) |
2287 |
| -{ |
2288 |
| -tuple[2]=s.substring(pos+4,pos2).getBytes();;// PKTABLE_NAME |
2289 |
| -pos=s.indexOf("\\000",pos2+1); |
2290 |
| -if(pos>-1) |
2291 |
| - { |
2292 |
| -tuple[6]=s.substring(pos2+4,pos).getBytes();;// FKTABLE_NAME |
2293 |
| -pos=s.indexOf("\\000",pos+1);// Ignore MATCH type |
2294 |
| -if(pos>-1) |
2295 |
| -{ |
2296 |
| -pos2=s.indexOf("\\000",pos+1); |
2297 |
| -if(pos2>-1) |
2298 |
| - { |
2299 |
| -tuple[3]=s.substring(pos+4,pos2).getBytes();;// PKCOLUMN_NAME |
2300 |
| -pos=s.indexOf("\\000",pos2+1); |
2301 |
| -if(pos>-1) |
2302 |
| -{ |
2303 |
| -tuple[7]=s.substring(pos2+4,pos).getBytes();//FKCOLUMN_NAME |
| 2277 | +Fieldf[]=newField[14]; |
| 2278 | + |
| 2279 | +f[0]=newField(connection,"PKTABLE_CAT",iVarcharOid,32); |
| 2280 | +f[1]=newField(connection,"PKTABLE_SCHEM",iVarcharOid,32); |
| 2281 | +f[2]=newField(connection,"PKTABLE_NAME",iVarcharOid,32); |
| 2282 | +f[3]=newField(connection,"PKCOLUMN_NAME",iVarcharOid,32); |
| 2283 | +f[4]=newField(connection,"FKTABLE_CAT",iVarcharOid,32); |
| 2284 | +f[5]=newField(connection,"FKTABLE_SCHEM",iVarcharOid,32); |
| 2285 | +f[6]=newField(connection,"FKTABLE_NAME",iVarcharOid,32); |
| 2286 | +f[7]=newField(connection,"FKCOLUMN_NAME",iVarcharOid,32); |
| 2287 | +f[8]=newField(connection,"KEY_SEQ",iInt2Oid,2); |
| 2288 | +f[9]=newField(connection,"UPDATE_RULE",iInt2Oid,2); |
| 2289 | +f[10]=newField(connection,"DELETE_RULE",iInt2Oid,2); |
| 2290 | +f[11]=newField(connection,"FK_NAME",iVarcharOid,32); |
| 2291 | +f[12]=newField(connection,"PK_NAME",iVarcharOid,32); |
| 2292 | +f[13]=newField(connection,"DEFERRABILITY",iInt2Oid,2); |
| 2293 | + |
| 2294 | +java.sql.ResultSetrs =connection.ExecSQL("SELECT c.relname,c2.relname," |
| 2295 | + +"t.tgconstrname,ic.relname," |
| 2296 | + +"t.tgdeferrable,t.tginitdeferred," |
| 2297 | + +"t.tgnargs,t.tgargs,p.proname " |
| 2298 | + +"FROM pg_trigger t,pg_class c,pg_class c2," |
| 2299 | + +"pg_class ic,pg_proc p, pg_index i " |
| 2300 | + +"WHERE t.tgrelid=c.oid AND t.tgconstrrelid=c2.oid " |
| 2301 | + +"AND t.tgfoid=p.oid AND tgisconstraint " |
| 2302 | + + ((primaryTable!=null) ?"AND c2.relname='"+primaryTable+"' " :"") |
| 2303 | + + ((foreignTable!=null) ?"AND c.relname='"+foreignTable+"' " :"") |
| 2304 | + +"AND i.indrelid=c.oid " |
| 2305 | + +"AND i.indexrelid=ic.oid AND i.indisprimary " |
| 2306 | + +"ORDER BY c.relname,c2.relname" |
| 2307 | + ); |
| 2308 | +Vectortuples =newVector(); |
| 2309 | +shortseq=0; |
| 2310 | +if(rs.next()) { |
| 2311 | +booleanhasMore; |
| 2312 | +do { |
| 2313 | +bytetuple[][]=newbyte[14][0]; |
| 2314 | +for (intk =0;k <14;k++) |
| 2315 | +tuple[k] =null; |
| 2316 | + |
| 2317 | +StringfKeyName=rs.getString(3); |
| 2318 | +booleanfoundRule=false; |
| 2319 | +do { |
| 2320 | +Stringproname=rs.getString(9); |
| 2321 | +if(proname!=null &&proname.startsWith("RI_FKey_")) { |
| 2322 | +intcol=-1; |
| 2323 | +if(proname.endsWith("_upd"))col=9;// UPDATE_RULE |
| 2324 | +elseif(proname.endsWith("_del"))col=10;// DELETE_RULE |
| 2325 | +if(col>-1) { |
| 2326 | +Stringrule=proname.substring(8,proname.length()-4); |
| 2327 | +intaction=importedKeyNoAction; |
| 2328 | +if("cascade".equals(rule))action=importedKeyCascade; |
| 2329 | +elseif("setnull".equals(rule))action=importedKeySetNull; |
| 2330 | +elseif("setdefault".equals(rule))action=importedKeySetDefault; |
| 2331 | +tuple[col]=Integer.toString(action).getBytes(); |
| 2332 | +foundRule=true; |
| 2333 | + } |
| 2334 | +} |
| 2335 | + }while((hasMore=rs.next()) &&fKeyName.equals(rs.getString(3))); |
| 2336 | + |
| 2337 | +if(foundRule) { |
| 2338 | +tuple[2]=rs.getBytes(2);//PKTABLE_NAME |
| 2339 | +tuple[6]=rs.getBytes(1);//FKTABLE_NAME |
| 2340 | + |
| 2341 | +// Parse the tgargs data |
| 2342 | +StringBufferfkeyColumns=newStringBuffer(); |
| 2343 | +StringBufferpkeyColumns=newStringBuffer(); |
| 2344 | +intnumColumns=(rs.getInt(7) >>1) -2; |
| 2345 | +Strings=rs.getString(8); |
| 2346 | +intpos=s.lastIndexOf("\\000"); |
| 2347 | +for(intc=0;c<numColumns;c++) { |
| 2348 | +if(pos>-1) { |
| 2349 | +intpos2=s.lastIndexOf("\\000",pos-1); |
| 2350 | +if(pos2>-1) { |
| 2351 | +if(fkeyColumns.length()>0)fkeyColumns.insert(0,','); |
| 2352 | +fkeyColumns.insert(0,s.substring(pos2+4,pos));//FKCOLUMN_NAME |
| 2353 | +pos=s.lastIndexOf("\\000",pos2-1); |
| 2354 | +if(pos>-1) { |
| 2355 | +if(pkeyColumns.length()>0)pkeyColumns.insert(0,','); |
| 2356 | +pkeyColumns.insert(0,s.substring(pos+4,pos2));//PKCOLUMN_NAME |
| 2357 | + } |
2304 | 2358 | }
|
2305 | 2359 | }
|
2306 | 2360 | }
|
| 2361 | +tuple[7]=fkeyColumns.toString().getBytes();//FKCOLUMN_NAME |
| 2362 | +tuple[3]=pkeyColumns.toString().getBytes();//PKCOLUMN_NAME |
| 2363 | + |
| 2364 | +tuple[8]=Integer.toString(seq++).getBytes();//KEY_SEQ |
| 2365 | +tuple[11]=fKeyName.getBytes();//FK_NAME |
| 2366 | +tuple[12]=rs.getBytes(4);//PK_NAME |
| 2367 | + |
| 2368 | +// DEFERRABILITY |
| 2369 | +intdeferrability=importedKeyNotDeferrable; |
| 2370 | +booleandeferrable=rs.getBoolean(5); |
| 2371 | +booleaninitiallyDeferred=rs.getBoolean(6); |
| 2372 | +if(deferrable) { |
| 2373 | +if(initiallyDeferred) |
| 2374 | +deferrability=importedKeyInitiallyDeferred; |
| 2375 | +else |
| 2376 | +deferrability=importedKeyInitiallyImmediate; |
| 2377 | +} |
| 2378 | +tuple[13]=Integer.toString(deferrability).getBytes(); |
| 2379 | + |
| 2380 | +tuples.addElement(tuple); |
2307 | 2381 | }
|
2308 |
| -} |
| 2382 | +}while(hasMore); |
2309 | 2383 | }
|
2310 | 2384 |
|
2311 |
| -// UPDATE_RULE |
2312 |
| -Stringrule=keyRelation.getString(2); |
2313 |
| -intaction=importedKeyNoAction; |
2314 |
| -if("cascade".equals(rule))action=importedKeyCascade; |
2315 |
| -elseif("setnull".equals(rule))action=importedKeySetNull; |
2316 |
| -elseif("setdefault".equals(rule))action=importedKeySetDefault; |
2317 |
| -tuple[9]=Integer.toString(action).getBytes(); |
2318 |
| - |
2319 |
| -// DELETE_RULE |
2320 |
| -rule=keyRelation.getString(3); |
2321 |
| -action=importedKeyNoAction; |
2322 |
| -if("cascade".equals(rule))action=importedKeyCascade; |
2323 |
| -elseif("setnull".equals(rule))action=importedKeySetNull; |
2324 |
| -elseif("setdefault".equals(rule))action=importedKeySetDefault; |
2325 |
| -tuple[10]=Integer.toString(action).getBytes(); |
2326 |
| - |
2327 |
| -// DEFERRABILITY |
2328 |
| -intdeferrability=importedKeyNotDeferrable; |
2329 |
| -booleandeferrable=keyRelation.getBoolean(4); |
2330 |
| -if(deferrable) |
2331 |
| - { |
2332 |
| -if(keyRelation.getBoolean(5)) |
2333 |
| -deferrability=importedKeyInitiallyDeferred; |
2334 |
| -else |
2335 |
| -deferrability=importedKeyInitiallyImmediate; |
2336 |
| - } |
2337 |
| -tuple[13]=Integer.toString(deferrability).getBytes(); |
2338 |
| -for (inti=0;i<14;i++){ |
2339 |
| -tuples.addElement(tuple[i]); |
2340 |
| - } |
| 2385 | +returnnewResultSet(connection,f,tuples,"OK",1); |
2341 | 2386 | }
|
2342 | 2387 |
|
2343 | 2388 | /**
|
@@ -2393,51 +2438,7 @@ private void parseConstraint(java.sql.ResultSet keyRelation, Vector tuples) thro
|
2393 | 2438 | */
|
2394 | 2439 | publicjava.sql.ResultSetgetImportedKeys(Stringcatalog,Stringschema,Stringtable)throwsSQLException
|
2395 | 2440 | {
|
2396 |
| -Fieldf[]=newField[14]; |
2397 |
| - |
2398 |
| -f[0]=newField(connection,"PKTABLE_CAT",iVarcharOid,32); |
2399 |
| -f[1]=newField(connection,"PKTABLE_SCHEM",iVarcharOid,32); |
2400 |
| -f[2]=newField(connection,"PKTABLE_NAME",iVarcharOid,32); |
2401 |
| -f[3]=newField(connection,"PKCOLUMN_NAME",iVarcharOid,32); |
2402 |
| -f[4]=newField(connection,"FKTABLE_CAT",iVarcharOid,32); |
2403 |
| -f[5]=newField(connection,"FKTABLE_SCHEM",iVarcharOid,32); |
2404 |
| -f[6]=newField(connection,"FKTABLE_NAME",iVarcharOid,32); |
2405 |
| -f[7]=newField(connection,"FKCOLUMN_NAME",iVarcharOid,32); |
2406 |
| -f[8]=newField(connection,"KEY_SEQ",iInt2Oid,2); |
2407 |
| -f[9]=newField(connection,"UPDATE_RULE",iInt2Oid,2); |
2408 |
| -f[10]=newField(connection,"DELETE_RULE",iInt2Oid,2); |
2409 |
| -f[11]=newField(connection,"FK_NAME",iVarcharOid,32); |
2410 |
| -f[12]=newField(connection,"PK_NAME",iVarcharOid,32); |
2411 |
| -f[13]=newField(connection,"DEFERRABILITY",iInt2Oid,2); |
2412 |
| - |
2413 |
| -java.sql.ResultSetrs =connection.ExecSQL("SELECT a.tgargs," |
2414 |
| - +"substring(a.proname from 9 for (char_length(a.proname)-12))," |
2415 |
| - +"substring(b.proname from 9 for (char_length(b.proname)-12))," |
2416 |
| - +"a.tgdeferrable," |
2417 |
| - +"a.tginitdeferred " |
2418 |
| - +"FROM " |
2419 |
| - +"(SELECT t.tgargs, t.tgconstrname, p.proname, t.tgdeferrable," |
2420 |
| - +"t.tginitdeferred " |
2421 |
| - +"FROM pg_class as c, pg_proc as p, pg_trigger as t " |
2422 |
| - +"WHERE c.relfilenode=t.tgrelid AND t.tgfoid = p.oid " |
2423 |
| - +"AND p.proname LIKE 'RI_FKey_%_upd') as a," |
2424 |
| - +"(SELECT t.tgconstrname, p.proname " |
2425 |
| - +"FROM pg_class as c, pg_proc as p, pg_trigger as t " |
2426 |
| - +"WHERE c.relfilenode=t.tgrelid AND t.tgfoid = p.oid " |
2427 |
| - +"AND p.proname LIKE 'RI_FKey_%_del') as b," |
2428 |
| - +"(SELECT t.tgconstrname FROM pg_class as c, pg_trigger as t " |
2429 |
| - +"WHERE c.relname like '"+table+"' AND c.relfilenode=t.tgrelid) as c " |
2430 |
| - +"WHERE a.tgconstrname=b.tgconstrname AND a.tgconstrname=c.tgconstrname" |
2431 |
| - ); |
2432 |
| -Vectortuples =newVector(); |
2433 |
| - |
2434 |
| -while (rs.next()) |
2435 |
| - { |
2436 |
| - |
2437 |
| -parseConstraint(rs,tuples); |
2438 |
| - } |
2439 |
| - |
2440 |
| -returnnewResultSet(connection,f,tuples,"OK",1); |
| 2441 | +returngetImportedExportedKeys(catalog,schema,null,table); |
2441 | 2442 | }
|
2442 | 2443 |
|
2443 | 2444 | /**
|
@@ -2495,47 +2496,7 @@ public java.sql.ResultSet getImportedKeys(String catalog, String schema, String
|
2495 | 2496 | */
|
2496 | 2497 | publicjava.sql.ResultSetgetExportedKeys(Stringcatalog,Stringschema,Stringtable)throwsSQLException
|
2497 | 2498 | {
|
2498 |
| -Fieldf[] =newField[14]; |
2499 |
| - |
2500 |
| -f[0] =newField(connection,"PKTABLE_CAT",iVarcharOid,32); |
2501 |
| -f[1] =newField(connection,"PKTABLE_SCHEM",iVarcharOid,32); |
2502 |
| -f[2] =newField(connection,"PKTABLE_NAME",iVarcharOid,32); |
2503 |
| -f[3] =newField(connection,"PKCOLUMN_NAME",iVarcharOid,32); |
2504 |
| -f[4] =newField(connection,"FKTABLE_CAT",iVarcharOid,32); |
2505 |
| -f[5] =newField(connection,"FKTABLE_SCHEM",iVarcharOid,32); |
2506 |
| -f[6] =newField(connection,"FKTABLE_NAME",iVarcharOid,32); |
2507 |
| -f[7] =newField(connection,"FKCOLUMN_NAME",iVarcharOid,32); |
2508 |
| -f[8] =newField(connection,"KEY_SEQ",iInt2Oid,2); |
2509 |
| -f[9] =newField(connection,"UPDATE_RULE",iInt2Oid,2); |
2510 |
| -f[10] =newField(connection,"DELETE_RULE",iInt2Oid,2); |
2511 |
| -f[11] =newField(connection,"FK_NAME",iVarcharOid,32); |
2512 |
| -f[12] =newField(connection,"PK_NAME",iVarcharOid,32); |
2513 |
| -f[13] =newField(connection,"DEFERRABILITY",iInt2Oid,2); |
2514 |
| - |
2515 |
| -java.sql.ResultSetrs =connection.ExecSQL("SELECT a.tgargs," |
2516 |
| - +"substring(a.proname from 9 for (char_length(a.proname)-12))," |
2517 |
| - +"substring(b.proname from 9 for (char_length(b.proname)-12))," |
2518 |
| - +"a.tgdeferrable," |
2519 |
| - +"a.tginitdeferred " |
2520 |
| - +"FROM " |
2521 |
| - +"(SELECT t.tgargs, t.tgconstrname, p.proname," |
2522 |
| - +"t.tgdeferrable, t.tginitdeferred " |
2523 |
| - +"FROM pg_class as c, pg_proc as p, pg_trigger as t " |
2524 |
| - +"WHERE c.relname like '"+table+"' AND c.relfilenode=t.tgrelid " |
2525 |
| - +"AND t.tgfoid = p.oid AND p.proname LIKE 'RI_FKey_%_upd') as a, " |
2526 |
| - +"(SELECT t.tgconstrname, p.proname " |
2527 |
| - +"FROM pg_class as c, pg_proc as p, pg_trigger as t " |
2528 |
| - +"WHERE c.relname like '"+table+"' AND c.relfilenode=t.tgrelid " |
2529 |
| - +"AND t.tgfoid = p.oid AND p.proname LIKE 'RI_FKey_%_del') as b " |
2530 |
| - +"WHERE a.tgconstrname=b.tgconstrname"); |
2531 |
| -Vectortuples =newVector(); |
2532 |
| - |
2533 |
| -while (rs.next()) |
2534 |
| -{ |
2535 |
| -parseConstraint(rs,tuples); |
2536 |
| -} |
2537 |
| - |
2538 |
| -returnnewResultSet(connection,f,tuples,"OK",1); |
| 2499 | +returngetImportedExportedKeys(catalog,schema,table,null); |
2539 | 2500 | }
|
2540 | 2501 |
|
2541 | 2502 | /**
|
@@ -2596,7 +2557,7 @@ public java.sql.ResultSet getExportedKeys(String catalog, String schema, String
|
2596 | 2557 | */
|
2597 | 2558 | publicjava.sql.ResultSetgetCrossReference(StringprimaryCatalog,StringprimarySchema,StringprimaryTable,StringforeignCatalog,StringforeignSchema,StringforeignTable)throwsSQLException
|
2598 | 2559 | {
|
2599 |
| -throworg.postgresql.Driver.notImplemented(); |
| 2560 | +returngetImportedExportedKeys(primaryCatalog,primarySchema,primaryTable,foreignTable); |
2600 | 2561 | }
|
2601 | 2562 |
|
2602 | 2563 | /**
|
|