Re: [JDBC] DatabaseMetaData.getTables()

2001-10-28 Thread Jason Davies

I forgot to mention I'm using the current CVS.

On Sun, Oct 28, 2001 at 10:07:06AM +0100, Rene Pijlman wrote:
 On Sat, 27 Oct 2001 19:25:49 -0500, you wrote:
 There seems to be a problem with DatabaseMetaData.getTables()
 [...]
 It throws a NullPointerException:
 
 This may have been fixed by now:
 http://fts.postgresql.org/db/mw/msg.html?mid=1021572
 
 Regards,
 René Pijlman [EMAIL PROTECTED]

-- 
Jason Davies

[EMAIL PROTECTED]

 PGP signature


Re: [JDBC] DatabaseMetaData.getTables()

2001-10-28 Thread Jason Davies

On Sun, Oct 28, 2001 at 07:14:42AM -0500, Dave Cramer wrote:
 It appears the getBytes was previously being used to return a byte array
 of any arbitrary column.
 
 Fixes for blobs seem to have broken this. The question is as Jason
 pointed out which do we fix.
 
 It doesn't seem unreasonable to be able to return a byte array for any
 arbitray column. On the other hand is this the intended use?

This is what the documentation says:

public byte[] getBytes(int columnIndex)
throws SQLException   

  Retrieves the value of the designated column in the current row
  of this ResultSet object as a byte array in the Java
  programming language. The bytes represent the raw values
  returned by the driver.

It seems to imply that it _should_ return a byte array for any arbitary column. But as 
usual, it's up to us to decide. I think it's reasonable, since we are working with 
byte arrays in the code anyway.

-- 
Jason Davies

[EMAIL PROTECTED]

 PGP signature


[JDBC] DatabaseMetaData.getTables()

2001-10-27 Thread Jason Davies

Hi,

There seems to be a problem with DatabaseMetaData.getTables() when I do the following:

ResultSet R=conn.getMetaData().getTables(null, null, %, null);

It throws a NullPointerException:

java.lang.NullPointerException
at org.postgresql.jdbc2.DatabaseMetaData.getTables(DatabaseMetaData.java:1732)
at Test.main(Test.java:66)

Looking at the source, ResultSet.getBytes() is called and it returns null, causing 
this exception to be thrown. However I can use ResultSet.getString() without a 
problem. I'm using 7.1.3 at the moment. Does ResultSet.getBytes() need to be fixed or 
should getTables() be modified?

I'd be grateful for any insights. Or you can just tell me to use the latest cvs 
version of PostgreSQL :) What is the consensus on supporting older versions, will you 
phase out old code when 7.2 comes out?

-- 
Jason Davies

[EMAIL PROTECTED]

 PGP signature


Re: [JDBC] DatabaseMetaData.getImported/ExportedKeys() patch

2001-10-26 Thread Jason Davies

On Fri, Oct 26, 2001 at 09:52:11AM -0700, Barry Lind wrote:
 Jason,
 
 Can you explain what this patch is attempting to fix?  Given that we are 
 in beta with 7.2, I want to fully understand the problem here before 
 applying this patch. (Especially given that the diff is pretty large and 
 not a one or two line change).

I guess fix is slightly misleading. This patch implements 
DatabaseMetaData.getExportedKeys() which was previously not implemented, and provides 
a better implementation of DatabaseMetaData.getImportedKeys() which was previously 
half-implemented.

The methods are identical for both jdbc1 and jdbc2 so that's why the diff is quite 
large. Perhaps identical code should be put into a single class and have the code 
which differs in jdbc1 and jdbc2 in subclasses?

 Also what testing have you done on this?  (When you ask us to 'check 
 that it works', it doesn't give me a high level of confidence that this 
 is well tested).

:-) I have tested it but only with 7.1.3 at the moment. What I meant to say is please 
:check in case something major has been changed in 7.2. Also if the queries I'm using 
:can be optimized in any way that would be great.

At the moment a value for PK_NAME (primary key name) is not returned but the main part 
is implemented.

Sorry for the lack of info, I'll try and be more helpful next time :)

Jason Davies

 thanks,
 --Barry
 
 
 Jason Davies wrote:
 
  Hi,
  
  Here is a diff for DatabaseMetaData.getImportedKeys() and
  DatabaseMetaData.getExportedKeys(). Please check that it works :)
  
  Thanks,
  Jason Davies
  
  [EMAIL PROTECTED]
  
  
  
  
  Index: jdbc1/DatabaseMetaData.java
  ===
  RCS file: 
/projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java,v
  retrieving revision 1.35
  diff -c -r1.35 DatabaseMetaData.java
  *** jdbc1/DatabaseMetaData.java 2001/10/25 05:59:59 1.35
  --- jdbc1/DatabaseMetaData.java 2001/10/26 01:21:02
  ***
  *** 2260,2345 
 
 );
  }

  !   private void importLoop(Vector tuples, java.sql.ResultSet keyRelation) throws 
SQLException
  !   {
  !   String s, s2;
  !   String origTable = null, primTable = new String(), schema;
  !   int i;
  !   Vector v = new Vector();
  ! 
  !   s = keyRelation.getString(1);
  !   s2 = s;
  !   //System.out.println(s);
  ! 
  !   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.addElement(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  v.size();i += 2)
  {
  !   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