Re: [JDBC] PATCH to org/postgresql/jdbc2/DatabaseMetaData.java

2001-03-19 Thread Bruce Momjian


Peter, can you comment on this?


> ---
> postgresql-7.1beta4/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
> Mon Jan 29 03:53:56 2001
> +++
> 
>postgresql-7.1beta4-new/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
> Sat Feb 17 10:22:38 2001
> @@ -1048,7 +1048,7 @@
>/**
> * Can statements remain open across commits?  They may, but
> * this driver cannot guarentee that.  In further reflection.
> -   * we are talking a Statement object jere, so the answer is
> +   * we are talking a Statement object here, so the answer is
> * yes, since the Statement is only a vehicle to ExecSQL()
> *
> * @return true if they always remain open; false otherwise
> @@ -2185,6 +2185,81 @@
>   );
>}
>  
> +  private Vector importLoop(java.sql.ResultSet keyRelation) throws
> SQLException {
> +String s,s2;
> +String origTable=null, primTable=new String(""), schema;
> +int i;
> +Vector v;
> +
> +s=keyRelation.getString(1);
> +s2=s;
> +System.out.println(s);
> +v=new Vector();
> +for (i=0;;i++) {
> +  s=s.substring(s.indexOf("\\000")+4);
> +  if (s.compareTo("")==0) {
> + System.out.println();
> + break;
> +  }
> +  s2=s.substring(0,s.indexOf("\\000"));
> +  switch (i) {
> +  case 0:
> + origTable=s2;
> + break;
> +  case 1:
> + primTable=s2;
> + break;
> +  case 2:
> + schema=s2;
> + break;
> +  default:
> + v.add(s2);
> +  }
> +  }
> +
> +  java.sql.ResultSet rstmp=connection.ExecSQL("select * from
> "+origTable+" where 1=0");
> +  java.sql.ResultSetMetaData origCols=rstmp.getMetaData();
> +
> +  String stmp;
> +  Vector tuples=new Vector();
> +  byte tuple[][];
> +
> +  // the foreign keys are only on even positions in the Vector.
> +  for (i=0;i +stmp=(String)v.elementAt(i);
> +
> +for (int j=1;j<=origCols.getColumnCount();j++) {
> +  if (stmp.compareTo(origCols.getColumnName(j))==0) {
> + tuple=new byte[14][0];
> +
> + for (int k=0;k<14;k++)
> +   tuple[k]=null;
> +
> + //PKTABLE_NAME
> + tuple[2]=primTable.getBytes();
> + //PKTABLE_COLUMN
> + stmp=(String)v.elementAt(i+1);
> + tuple[3]=stmp.getBytes();
> + //FKTABLE_NAME
> + tuple[6]=origTable.getBytes();
> + //FKCOLUMN_NAME
> + tuple[7]=origCols.getColumnName(j).getBytes();
> + //KEY_SEQ
> + tuple[8]=Integer.toString(j).getBytes();
> +
> + tuples.add(tuple);
> +
> + System.out.println(origCols.getColumnName(j)+
> + ": "+j+" -> "+primTable+": "+
> + (String)v.elementAt(i+1));
> + break;
> +  }
> +}
> +  }
> +
> +  return tuples;
> +  }
> +
>/**
> * Get a description of the primary key columns that are
> * referenced by a table's foreign key columns (the primary keys
> @@ -2238,8 +2313,39 @@
> */
>public java.sql.ResultSet getImportedKeys(String catalog, String
> schema, String table) throws SQLException
>{
> -// XXX-Not Implemented
> -return null;
> +// Added by Ola Sundell <[EMAIL PROTECTED]>
> +// FIXME: error checking galore!
> +java.sql.ResultSet rsret;
> +Field f[]=new Field[14];
> +byte tuple[][];
> +
> +f[0]=new Field(connection, "PKTABLE_CAT", iVarcharOid, 32);
> +f[1]=new Field(connection, "PKTABLE_SCHEM", iVarcharOid, 32);
> +f[2]=new Field(connection, "PKTABLE_NAME", iVarcharOid, 32);
> +f[3]=new Field(connection, "PKCOLUMN_NAME", iVarcharOid, 32);
> +f[4]=new Field(connection, "FKTABLE_CAT", iVarcharOid, 32);
> +f[5]=new Field(connection, "FKTABLE_SCHEM", iVarcharOid, 32);
> +f[6]=new Field(connection, "FKTABLE_NAME", iVarcharOid, 32);
> +f[7]=new Field(connection, "FKCOLUMN_NAME", iVarcharOid, 32);
> +f[8]=new Field(connection, "KEY_SEQ", iInt2Oid, 2);
> +f[9]=new Field(connection, "UPDATE_RULE", iInt2Oid, 2);
> +f[10]=new Field(connection, "DELETE_RULE", iInt2Oid, 2);
> +f[11]=new Field(connection, "FK_NAME", iVarcharOid, 32);
> +f[12]=new Field(connection, "PK_NAME", iVarcharOid, 32);
> +f[13]=new Field(connection, "DEFERRABILITY", iInt2Oid, 2);
> +
> +java.sql.ResultSet rs=connection.ExecSQL("select t.tgargs "+
> + "from pg_class as c, pg_trigger as t "+
> + "where c.relname like '"+table+"' and
> c.relfilenode=t.tgrelid");
> +Vector tuples=new Vector();
> +
> +while (rs.next()) {
> + tuples.addAll(importLoop(rs));  
> +}
> +
> +rsret=new ResultSet(connection, f, tuples, "OK", 1);
> +
> +return rsret;
>}
>  
>/**
> 
> 
> 


-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 853-3000
  +  If your life is a hard drive, |  830 Blythe Avenue
  +  Christ can be your backup.|  Drexel Hill, Pennsylvania 19026

---(end of broadcast)---
TIP 4: Don't 'kill -9' the 

Re: [JDBC] PATCH to org/postgresql/jdbc2/DatabaseMetaData.java

2001-03-01 Thread Peter Mount

I'll take a look at this patch shortly.

Sorry for the delay, work has been hectic this week so I'm about 4 days 
behind with emails.

Peter

At 17:22 25/02/01 -0500, Ola Sundell wrote:
>---
>postgresql-7.1beta4/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
>Mon Jan 29 03:53:56 2001
>+++
>postgresql-7.1beta4-new/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
>Sat Feb 17 10:22:38 2001
>@@ -1048,7 +1048,7 @@
>/**
> * Can statements remain open across commits?  They may, but
> * this driver cannot guarentee that.  In further reflection.
>-   * we are talking a Statement object jere, so the answer is
>+   * we are talking a Statement object here, so the answer is
> * yes, since the Statement is only a vehicle to ExecSQL()
> *
> * @return true if they always remain open; false otherwise
>@@ -2185,6 +2185,81 @@
>   );
>}
>
>+  private Vector importLoop(java.sql.ResultSet keyRelation) throws
>SQLException {
>+String s,s2;
>+String origTable=null, primTable=new String(""), schema;
>+int i;
>+Vector v;
>+
>+s=keyRelation.getString(1);
>+s2=s;
>+System.out.println(s);
>+v=new Vector();
>+for (i=0;;i++) {
>+  s=s.substring(s.indexOf("\\000")+4);
>+  if (s.compareTo("")==0) {
>+   System.out.println();
>+   break;
>+  }
>+  s2=s.substring(0,s.indexOf("\\000"));
>+  switch (i) {
>+  case 0:
>+   origTable=s2;
>+   break;
>+  case 1:
>+   primTable=s2;
>+   break;
>+  case 2:
>+   schema=s2;
>+   break;
>+  default:
>+   v.add(s2);
>+  }
>+  }
>+
>+  java.sql.ResultSet rstmp=connection.ExecSQL("select * from
>"+origTable+" where 1=0");
>+  java.sql.ResultSetMetaData origCols=rstmp.getMetaData();
>+
>+  String stmp;
>+  Vector tuples=new Vector();
>+  byte tuple[][];
>+
>+  // the foreign keys are only on even positions in the Vector.
>+  for (i=0;i+stmp=(String)v.elementAt(i);
>+
>+for (int j=1;j<=origCols.getColumnCount();j++) {
>+  if (stmp.compareTo(origCols.getColumnName(j))==0) {
>+   tuple=new byte[14][0];
>+
>+   for (int k=0;k<14;k++)
>+ tuple[k]=null;
>+
>+   //PKTABLE_NAME
>+   tuple[2]=primTable.getBytes();
>+   //PKTABLE_COLUMN
>+   stmp=(String)v.elementAt(i+1);
>+   tuple[3]=stmp.getBytes();
>+   //FKTABLE_NAME
>+   tuple[6]=origTable.getBytes();
>+   //FKCOLUMN_NAME
>+   tuple[7]=origCols.getColumnName(j).getBytes();
>+   //KEY_SEQ
>+   tuple[8]=Integer.toString(j).getBytes();
>+
>+   tuples.add(tuple);
>+
>+   System.out.println(origCols.getColumnName(j)+
>+   ": "+j+" -> "+primTable+": "+
>+   (String)v.elementAt(i+1));
>+   break;
>+  }
>+}
>+  }
>+
>+  return tuples;
>+  }
>+
>/**
> * Get a description of the primary key columns that are
> * referenced by a table's foreign key columns (the primary keys
>@@ -2238,8 +2313,39 @@
> */
>public java.sql.ResultSet getImportedKeys(String catalog, String
>schema, String table) throws SQLException
>{
>-// XXX-Not Implemented
>-return null;
>+// Added by Ola Sundell <[EMAIL PROTECTED]>
>+// FIXME: error checking galore!
>+java.sql.ResultSet rsret;
>+Field f[]=new Field[14];
>+byte tuple[][];
>+
>+f[0]=new Field(connection, "PKTABLE_CAT", iVarcharOid, 32);
>+f[1]=new Field(connection, "PKTABLE_SCHEM", iVarcharOid, 32);
>+f[2]=new Field(connection, "PKTABLE_NAME", iVarcharOid, 32);
>+f[3]=new Field(connection, "PKCOLUMN_NAME", iVarcharOid, 32);
>+f[4]=new Field(connection, "FKTABLE_CAT", iVarcharOid, 32);
>+f[5]=new Field(connection, "FKTABLE_SCHEM", iVarcharOid, 32);
>+f[6]=new Field(connection, "FKTABLE_NAME", iVarcharOid, 32);
>+f[7]=new Field(connection, "FKCOLUMN_NAME", iVarcharOid, 32);
>+f[8]=new Field(connection, "KEY_SEQ", iInt2Oid, 2);
>+f[9]=new Field(connection, "UPDATE_RULE", iInt2Oid, 2);
>+f[10]=new Field(connection, "DELETE_RULE", iInt2Oid, 2);
>+f[11]=new Field(connection, "FK_NAME", iVarcharOid, 32);
>+f[12]=new Field(connection, "PK_NAME", iVarcharOid, 32);
>+f[13]=new Field(connection, "DEFERRABILITY", iInt2Oid, 2);
>+
>+java.sql.ResultSet rs=connection.ExecSQL("select t.tgargs "+
>+   "from pg_class as c, pg_trigger as t "+
>+   "where c.relname like '"+table+"' and
>c.relfilenode=t.tgrelid");
>+Vector tuples=new Vector();
>+
>+while (rs.next()) {
>+   tuples.addAll(importLoop(rs));
>+}
>+
>+rsret=new ResultSet(connection, f, tuples, "OK", 1);
>+
>+return rsret;
>}
>
>/**