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

Commita35a681

Browse files
committed
The getColumns() method in DataBaseMetaData.java returns a column size
of -1 for varchar's.From: CNT systemen BV <cntsys@cistron.nl>
1 parent0e1a352 commita35a681

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
3535
staticfinalintiBoolOid =16;// OID for bool
3636
staticfinalintiInt2Oid =21;// OID for int2
3737
staticfinalintiInt4Oid =23;// OID for int4
38+
staticfinalintVARHDRSZ =4;// length for int4
3839

3940
publicDatabaseMetaData(Connectionconn)
4041
{
@@ -1848,13 +1849,14 @@ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, Strin
18481849
f[17] =newField(connection,newString("IS_NULLABLE"),iVarcharOid,32);
18491850

18501851
// Now form the query
1851-
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");
1852+
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");
18521853

18531854
while(r.next()) {
18541855
byte[][]tuple =newbyte[18][0];
18551856

18561857
Stringname =r.getString(1);
18571858
Stringremarks =newString("no remarks");
1859+
StringcolumnSize;
18581860

18591861
// Fetch the description for the table (if any)
18601862
ResultSetdr =connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
@@ -1875,8 +1877,16 @@ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, Strin
18751877
dr.close();
18761878
tuple[4] =Integer.toString(Field.getSQLType(typname)).getBytes();// Data type
18771879
tuple[5] =typname.getBytes();// Type name
1878-
1879-
tuple[6] =r.getString(7).getBytes();// Column size
1880+
1881+
// Looking at the psql source,
1882+
// I think the length of a varchar as specified when the table was created
1883+
// should be extracted from atttypmod which contains this length + sizeof(int32)
1884+
if (typname.equals("bpchar") ||typname.equals("varchar")) {
1885+
intatttypmod =r.getInt(8);
1886+
columnSize =Integer.toString(atttypmod != -1 ?atttypmod -VARHDRSZ :0);
1887+
}else
1888+
columnSize =r.getString(7);
1889+
tuple[6] =columnSize.getBytes();// Column size
18801890

18811891
tuple[7] =null;// Buffer length
18821892

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp