Commit a35a681f authored by Marc G. Fournier's avatar Marc G. Fournier

The getColumns() method in DataBaseMetaData.java returns a column size

of -1 for varchar's.

From: CNT systemen BV <cntsys@cistron.nl>
parent 0e1a352f
...@@ -35,6 +35,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData ...@@ -35,6 +35,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
static final int iBoolOid = 16; // OID for bool static final int iBoolOid = 16; // OID for bool
static final int iInt2Oid = 21; // OID for int2 static final int iInt2Oid = 21; // OID for int2
static final int iInt4Oid = 23; // OID for int4 static final int iInt4Oid = 23; // OID for int4
static final int VARHDRSZ = 4; // length for int4
public DatabaseMetaData(Connection conn) public DatabaseMetaData(Connection conn)
{ {
...@@ -1848,13 +1849,14 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData ...@@ -1848,13 +1849,14 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[17] = new Field(connection, new String("IS_NULLABLE"), iVarcharOid, 32); f[17] = new Field(connection, new String("IS_NULLABLE"), iVarcharOid, 32);
// Now form the query // Now form the query
r = connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern+"' and a.attname like '"+columnNamePattern+"' and a.attnum>0 order by c.relname,a.attnum"); r = connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern+"' and a.attname like '"+columnNamePattern+"' and a.attnum>0 order by c.relname,a.attnum");
while(r.next()) { while(r.next()) {
byte[][] tuple = new byte[18][0]; byte[][] tuple = new byte[18][0];
String name = r.getString(1); String name = r.getString(1);
String remarks = new String("no remarks"); String remarks = new String("no remarks");
String columnSize;
// Fetch the description for the table (if any) // Fetch the description for the table (if any)
ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1)); ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
...@@ -1876,7 +1878,15 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData ...@@ -1876,7 +1878,15 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[4] = Integer.toString(Field.getSQLType(typname)).getBytes(); // Data type tuple[4] = Integer.toString(Field.getSQLType(typname)).getBytes(); // Data type
tuple[5] = typname.getBytes(); // Type name tuple[5] = typname.getBytes(); // Type name
tuple[6] = r.getString(7).getBytes(); // Column size // Looking at the psql source,
// I think the length of a varchar as specified when the table was created
// should be extracted from atttypmod which contains this length + sizeof(int32)
if (typname.equals("bpchar") || typname.equals("varchar")) {
int atttypmod = r.getInt(8);
columnSize = Integer.toString(atttypmod != -1 ? atttypmod - VARHDRSZ : 0);
} else
columnSize = r.getString(7);
tuple[6] = columnSize.getBytes(); // Column size
tuple[7] = null; // Buffer length tuple[7] = null; // Buffer length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment