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

Commit1ebbfc1

Browse files
committed
Attached is the patch requested by Tom Lane (see below). It
includes two changes in the JDBC driver:1) When connected to a backend >= 7.2: use obj_description() andcol_description() instead of direct access to pg_description.2) In DatabaseMetaData.getTables()/getColumns()/getProcedures():when there is no comment on the object, return null in theREMARKS column of the ResultSet, instead of the default string"no remarks".Change 2 first appeared as a side-effect of change 1, but it isactually more compliant with the JDBC spec: "String objectcontaining an explanatory comment on the table/column/procedure,which may be null". The default string "no remarks" was strictlyspeaking incorrect, as it could not be distinguished from a realuser comment "no remarks". So I removed the default stringcompletely.Change 2 might break existing code that doesn't follow the JDBCspec and isn't prepared to handle a null in the REMARKS columnof getTables()/getColumns()/getProcedures.Patch tested with jdbc2 against both a 7.1 and a CVS tipbackend. I did not have a jdbc1 environment to build and testwith, but since the touched code is identical in jdbc1 and jdbc2I don't foresee any problems.Regards,Ren? Pijlman
1 parentb5453fa commit1ebbfc1

File tree

2 files changed

+64
-39
lines changed

2 files changed

+64
-39
lines changed

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
4343
staticfinalintiInt4Oid =23;// OID for int4
4444
staticfinalintVARHDRSZ =4;// length for int4
4545

46-
// This is a default value for remarks
47-
privatestaticfinalbytedefaultRemarks[]="no remarks".getBytes();
48-
49-
5046
publicDatabaseMetaData(Connectionconn)
5147
{
5248
this.connection =conn;
@@ -1517,8 +1513,6 @@ public java.sql.ResultSet getProcedures(String catalog, String schemaPattern, St
15171513
java.sql.ResultSetr;// ResultSet for the SQL query that we need to do
15181514
Vectorv =newVector();// The new ResultSet tuple stuff
15191515

1520-
byteremarks[] =defaultRemarks;
1521-
15221516
f[0] =newField(connection,"PROCEDURE_CAT",iVarcharOid,32);
15231517
f[1] =newField(connection,"PROCEDURE_SCHEM",iVarcharOid,32);
15241518
f[2] =newField(connection,"PROCEDURE_NAME",iVarcharOid,32);
@@ -1540,7 +1534,7 @@ public java.sql.ResultSet getProcedures(String catalog, String schemaPattern, St
15401534
tuple[1] =null;// Schema name
15411535
tuple[2] =r.getBytes(1);// Procedure name
15421536
tuple[3] =tuple[4] =tuple[5] =null;// Reserved
1543-
tuple[6] =remarks;// Remarks
1537+
tuple[6] =null;// Remarks
15441538

15451539
if (r.getBoolean(2))
15461540
tuple[7] =Integer.toString(java.sql.DatabaseMetaData.procedureReturnsResult).getBytes();
@@ -1684,6 +1678,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
16841678

16851679
// Now form the query
16861680
StringBuffersql =newStringBuffer("select relname,oid,relkind from pg_class where (");
1681+
16871682
booleannotFirst=false;
16881683
for(inti=0;i<types.length;i++) {
16891684
for(intj=0;j<getTableTypes.length;j++)
@@ -1704,19 +1699,24 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
17041699
// Now run the query
17051700
r =connection.ExecSQL(sql.toString());
17061701

1707-
byteremarks[];
1708-
17091702
while (r.next())
17101703
{
17111704
byte[][]tuple =newbyte[5][0];
17121705

17131706
// Fetch the description for the table (if any)
1714-
java.sql.ResultSetdr =connection.ExecSQL("select description from pg_description where objoid="+r.getInt(2));
1707+
StringgetDescriptionStatement =
1708+
connection.haveMinimumServerVersion("7.2") ?
1709+
"select obj_description("+r.getInt(2)+",'pg_class')" :
1710+
"select description from pg_description where objoid=" +r.getInt(2);
1711+
1712+
java.sql.ResultSetdr =connection.ExecSQL(getDescriptionStatement);
1713+
1714+
byteremarks[] =null;
1715+
17151716
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
17161717
dr.next();
17171718
remarks =dr.getBytes(1);
1718-
}else
1719-
remarks =defaultRemarks;
1719+
}
17201720
dr.close();
17211721

17221722
StringrelKind;
@@ -1919,22 +1919,35 @@ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, Strin
19191919
if (columnNamePattern ==null)columnNamePattern="%";
19201920

19211921
// Now form the query
1922-
// Modified by Stefan Andreasen <stefan@linux.kapow.dk>
1923-
r =connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod,d.adsrc from pg_class c,pg_attribute a,pg_attrdef d where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 and c.oid=d.adrelid and d.adnum=a.attnum order by c.relname,a.attnum");
1924-
1925-
byteremarks[];
1922+
Stringquery =
1923+
"select " +
1924+
(connection.haveMinimumServerVersion("7.2") ?"a.attrelid" :"a.oid") +
1925+
",c.relname,a.attname,a.atttypid," +
1926+
"a.attnum,a.attnotnull,a.attlen,a.atttypmod,d.adsrc from pg_class c," +
1927+
"pg_attribute a,pg_attrdef d where a.attrelid=c.oid and " +
1928+
"c.relname like '"+tableNamePattern.toLowerCase()+"' and " +
1929+
"a.attname like '"+columnNamePattern.toLowerCase()+"' and " +
1930+
"a.attnum>0 and c.oid=d.adrelid and d.adnum=a.attnum " +
1931+
"order by c.relname,a.attnum";
1932+
1933+
r =connection.ExecSQL(query);
19261934

19271935
while(r.next()) {
19281936
byte[][]tuple =newbyte[18][0];
19291937

19301938
// Fetch the description for the table (if any)
1931-
java.sql.ResultSetdr =connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
1939+
StringgetDescriptionStatement =
1940+
connection.haveMinimumServerVersion("7.2") ?
1941+
"select col_description(" +r.getInt(1) +"," +r.getInt(5) +")" :
1942+
"select description from pg_description where objoid=" +r.getInt(1);
1943+
1944+
java.sql.ResultSetdr =connection.ExecSQL(getDescriptionStatement);
1945+
19321946
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
19331947
dr.next();
19341948
tuple[11] =dr.getBytes(1);
19351949
}else
1936-
tuple[11] =defaultRemarks;
1937-
1950+
tuple[11] =null;
19381951
dr.close();
19391952

19401953
tuple[0] ="".getBytes();// Catalog name
@@ -1985,7 +1998,6 @@ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, Strin
19851998
r.close();
19861999
returnnewResultSet(connection,f,v,"OK",1);
19872000
}
1988-
19892001
/**
19902002
* Get a description of the access rights for a table's columns.
19912003
*

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

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
4343
staticfinalintiInt4Oid =23;// OID for int4
4444
staticfinalintVARHDRSZ =4;// length for int4
4545

46-
// This is a default value for remarks
47-
privatestaticfinalbytedefaultRemarks[]="no remarks".getBytes();
48-
49-
5046
publicDatabaseMetaData(Connectionconn)
5147
{
5248
this.connection =conn;
@@ -1517,8 +1513,6 @@ public java.sql.ResultSet getProcedures(String catalog, String schemaPattern, St
15171513
java.sql.ResultSetr;// ResultSet for the SQL query that we need to do
15181514
Vectorv =newVector();// The new ResultSet tuple stuff
15191515

1520-
byteremarks[] =defaultRemarks;
1521-
15221516
f[0] =newField(connection,"PROCEDURE_CAT",iVarcharOid,32);
15231517
f[1] =newField(connection,"PROCEDURE_SCHEM",iVarcharOid,32);
15241518
f[2] =newField(connection,"PROCEDURE_NAME",iVarcharOid,32);
@@ -1540,7 +1534,7 @@ public java.sql.ResultSet getProcedures(String catalog, String schemaPattern, St
15401534
tuple[1] =null;// Schema name
15411535
tuple[2] =r.getBytes(1);// Procedure name
15421536
tuple[3] =tuple[4] =tuple[5] =null;// Reserved
1543-
tuple[6] =remarks;// Remarks
1537+
tuple[6] =null;
15441538

15451539
if (r.getBoolean(2))
15461540
tuple[7] =Integer.toString(java.sql.DatabaseMetaData.procedureReturnsResult).getBytes();
@@ -1684,6 +1678,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
16841678

16851679
// Now form the query
16861680
StringBuffersql =newStringBuffer("select relname,oid,relkind from pg_class where (");
1681+
16871682
booleannotFirst=false;
16881683
for(inti=0;i<types.length;i++) {
16891684
for(intj=0;j<getTableTypes.length;j++)
@@ -1704,19 +1699,24 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
17041699
// Now run the query
17051700
r =connection.ExecSQL(sql.toString());
17061701

1707-
byteremarks[];
1708-
17091702
while (r.next())
17101703
{
17111704
byte[][]tuple =newbyte[5][0];
17121705

17131706
// Fetch the description for the table (if any)
1714-
java.sql.ResultSetdr =connection.ExecSQL("select description from pg_description where objoid="+r.getInt(2));
1707+
StringgetDescriptionStatement =
1708+
connection.haveMinimumServerVersion("7.2") ?
1709+
"select obj_description("+r.getInt(2)+",'pg_class')" :
1710+
"select description from pg_description where objoid=" +r.getInt(2);
1711+
1712+
java.sql.ResultSetdr =connection.ExecSQL(getDescriptionStatement);
1713+
1714+
byteremarks[] =null;
1715+
17151716
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
17161717
dr.next();
17171718
remarks =dr.getBytes(1);
1718-
}else
1719-
remarks =defaultRemarks;
1719+
}
17201720
dr.close();
17211721

17221722
StringrelKind;
@@ -1919,22 +1919,35 @@ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, Strin
19191919
if (columnNamePattern ==null)columnNamePattern="%";
19201920

19211921
// Now form the query
1922-
// Modified by Stefan Andreasen <stefan@linux.kapow.dk>
1923-
r =connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod,d.adsrc from pg_class c,pg_attribute a,pg_attrdef d where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 and c.oid=d.adrelid and d.adnum=a.attnum order by c.relname,a.attnum");
1924-
1925-
byteremarks[];
1922+
Stringquery =
1923+
"select " +
1924+
(connection.haveMinimumServerVersion("7.2") ?"a.attrelid" :"a.oid") +
1925+
",c.relname,a.attname,a.atttypid," +
1926+
"a.attnum,a.attnotnull,a.attlen,a.atttypmod,d.adsrc from pg_class c," +
1927+
"pg_attribute a,pg_attrdef d where a.attrelid=c.oid and " +
1928+
"c.relname like '"+tableNamePattern.toLowerCase()+"' and " +
1929+
"a.attname like '"+columnNamePattern.toLowerCase()+"' and " +
1930+
"a.attnum>0 and c.oid=d.adrelid and d.adnum=a.attnum " +
1931+
"order by c.relname,a.attnum";
1932+
1933+
r =connection.ExecSQL(query);
19261934

19271935
while(r.next()) {
19281936
byte[][]tuple =newbyte[18][0];
19291937

19301938
// Fetch the description for the table (if any)
1931-
java.sql.ResultSetdr =connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
1939+
StringgetDescriptionStatement =
1940+
connection.haveMinimumServerVersion("7.2") ?
1941+
"select col_description(" +r.getInt(1) +"," +r.getInt(5) +")" :
1942+
"select description from pg_description where objoid=" +r.getInt(1);
1943+
1944+
java.sql.ResultSetdr =connection.ExecSQL(getDescriptionStatement);
1945+
19321946
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
19331947
dr.next();
19341948
tuple[11] =dr.getBytes(1);
19351949
}else
1936-
tuple[11] =defaultRemarks;
1937-
1950+
tuple[11] =null;
19381951
dr.close();
19391952

19401953
tuple[0] ="".getBytes();// Catalog name

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp