pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedDatabaseMetaData.getTablePrivileges()
8+ messages / 5 participants
[nested] [flat]
* DatabaseMetaData.getTablePrivileges()
@ 2010-10-08 00:50 danap@itstriangle.com
0 siblings, 0 replies; 8+ messages in thread
From: danap@itstriangle.com @ 2010-10-08 00:50 UTC (permalink / raw)
To: pgsql-jdbc
Today I update the one of the development systems for the MyJSQLView
project to
test the PostgreSQL 9.0 database. Once the database was installed and also
the
latest JDBC 9.0-801 I tested the program. The application crashed and
after some
testing I attributed the exception to the empty string "" parameter for the
schemaPattern argument in DatabaseMetaData.getTablePrivileges() for the JDBC.
Well not sure the JDBC is really causing the problem, it is throwing the
exception,
but the error disappears when the same JDBC is used with the PostgreSQL 8.4.4
database. The Java API since I'm pretty sure 1.4 clearly indicates the empty
string "" is valid for the schemaPattern parameter.
"
Parameters:
schemaPattern - a schema name pattern; must match the schema name as it is
stored
in the database; "" retrieves those without a schema; null means that the
schema
name should not be used to narrow the search
"
Particulars, Exception, and Abbreviated Code attached.
Source for the code, MyJSQLView_Access,
http://code.google.com/p/myjsqlview/source/browse/
danap.
--------------------------------------------------------
Linux Platform
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
postgresql-9.0-801.jdbc3.jar & postgresql-9.0.801.jdbc4.jar
SQL version: PostgreSQL 8.4.4 (Works Fine)
SQL version: PostgreSQL 9.0.1 (Crashes)
Exception in thread "AWT-EventQueue-0"
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at
org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.addACLPrivileges(AbstractJdbc2DatabaseMetaData.java:2799)
at
org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.parseACL(AbstractJdbc2DatabaseMetaData.java:2878)
at
org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.getTablePrivileges(AbstractJdbc2DatabaseMetaData.java:2700)
at
com.dandymadeproductions.myjsqlview.MyJSQLView_Access.loadDBTables(MyJSQLView_Access.java:1559)
at
com.dandymadeproductions.myjsqlview.MyJSQLView_Access.accessCheck(MyJSQLView_Access.java:1200)
at
com.dandymadeproductions.myjsqlview.MyJSQLView_Access.actionPerformed(MyJSQLView_Access.java:628)
----------------------------------------------------------
Attachments:
dbTables.txt (text/plain, 1.2K) download
DatabaseMetaData dbMetaData;
ResultSet db_resultSet;
try
{
dbMetaData = dbConnection.getMetaData();
db_resultSet = dbMetaData.getTables(catalog, schemaPattern, tableNamePattern, tableTypes);
schemas.removeAllElements();
tables.removeAllElements();
while (db_resultSet.next())
{
// ************************************************************
// PostgreSQL databases may have schemas that limit access to
// tables by users. So make a check and remove tables that are
// not accessable by the user.
if (subProtocol.equals("postgresql"))
{
db_resultSet = dbMetaData.getTablePrivileges(db, "", "%");
while (db_resultSet.next())
{
String tableName, grantee, user;
tableName = db_resultSet.getString("TABLE_NAME");
if (tables.contains(tableName))
{
grantee = db_resultSet.getString("GRANTEE");
user = MyJSQLView_Access.getCurrentUser();
if (tables.contains(tableName) && !grantee.equals(user))
tables.remove(tableName);
}
}
}
db_resultSet.close();
}
catch (SQLException e)
{
throw e;
}
^ permalink raw reply [nested|flat] 8+ messages in thread
* DatabaseMetaData.getTablePrivileges()
@ 2010-10-08 01:16 danap <danap@ttc-cmc.net>
0 siblings, 1 reply; 8+ messages in thread
From: danap @ 2010-10-08 01:16 UTC (permalink / raw)
To: pgsql-jdbc
Today I update the one of the development systems for the MyJSQLView
project to test the PostgreSQL 9.0 database. Once the database was
installed and also the latest JDBC 9.0-801 I tested the program. The
application crashed and after some testing I attributed the exception to
the empty string "" parameter for the schemaPattern argument in
DatabaseMetaData.getTablePrivileges() for the JDBC. Well not sure
the JDBC is really causing the problem, it is throwing the exception,
but the error disappears when the same JDBC is used with the
PostgreSQL 8.4.4 database. The Java API since I'm pretty sure 1.4
clearly indicates the empty string "" is valid for the schemaPattern
parameter.
"
Parameters:
schemaPattern - a schema name pattern; must match the schema
name as it is stored in the database; "" retrieves those without a
schema; null means that the schema name should not be used to
narrow the search
"
Particulars, Exception, and Abbreviated Code attached.
Source for the code, MyJSQLView_Access;
http://code.google.com/p/myjsqlview/source/browse/
danap.
--------------------------------------------------------
Linux Platform
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
postgresql-9.0-801.jdbc3.jar & postgresql-9.0.801.jdbc4.jar
SQL version: PostgreSQL 8.4.4 (Works Fine)
SQL version: PostgreSQL 9.0.1 (Crashes)
Exception in thread "AWT-EventQueue-0"
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at
org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.addACLPrivileges(AbstractJdbc2DatabaseMetaData.java:2799)
at
org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.parseACL(AbstractJdbc2DatabaseMetaData.java:2878)
at
org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.getTablePrivileges(AbstractJdbc2DatabaseMetaData.java:2700)
at
com.dandymadeproductions.myjsqlview.MyJSQLView_Access.loadDBTables(MyJSQLView_Access.java:1559)
at
com.dandymadeproductions.myjsqlview.MyJSQLView_Access.accessCheck(MyJSQLView_Access.java:1200)
at
com.dandymadeproductions.myjsqlview.MyJSQLView_Access.actionPerformed(MyJSQLView_Access.java:628)
----------------------------------------------------------
Attachments:
dbTables.txt (text/plain, 1.2K) download
DatabaseMetaData dbMetaData;
ResultSet db_resultSet;
try
{
dbMetaData = dbConnection.getMetaData();
db_resultSet = dbMetaData.getTables(catalog, schemaPattern, tableNamePattern, tableTypes);
schemas.removeAllElements();
tables.removeAllElements();
while (db_resultSet.next())
{
// ************************************************************
// PostgreSQL databases may have schemas that limit access to
// tables by users. So make a check and remove tables that are
// not accessable by the user.
if (subProtocol.equals("postgresql"))
{
db_resultSet = dbMetaData.getTablePrivileges(db, "", "%");
while (db_resultSet.next())
{
String tableName, grantee, user;
tableName = db_resultSet.getString("TABLE_NAME");
if (tables.contains(tableName))
{
grantee = db_resultSet.getString("GRANTEE");
user = MyJSQLView_Access.getCurrentUser();
if (tables.contains(tableName) && !grantee.equals(user))
tables.remove(tableName);
}
}
}
db_resultSet.close();
}
catch (SQLException e)
{
throw e;
}
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getTablePrivileges()
@ 2010-10-09 06:37 Kris Jurka <books@ejurka.com>
parent: danap <danap@ttc-cmc.net>
0 siblings, 1 reply; 8+ messages in thread
From: Kris Jurka @ 2010-10-09 06:37 UTC (permalink / raw)
To: danap <danap@ttc-cmc.net>; +Cc: pgsql-jdbc
On Thu, 7 Oct 2010, danap wrote:
> Today I update the one of the development systems for the MyJSQLView
> project to test the PostgreSQL 9.0 database. Once the database was
> installed and also the latest JDBC 9.0-801 I tested the program. The
> application crashed and after some testing I attributed the exception to
> the empty string "" parameter for the schemaPattern argument in
> DatabaseMetaData.getTablePrivileges() for the JDBC.
>
> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
> at java.lang.String.substring(Unknown Source)
> at
> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.addACLPrivileges(AbstractJdbc2DatabaseMetaData.java:2799)
> at
> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.parseACL(AbstractJdbc2DatabaseMetaData.java:2878)
> at
> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.getTablePrivileges(AbstractJdbc2DatabaseMetaData.java:2700)
> at
This error has nothing to do with using "" as a schema pattern. The
problem is that the server is supplying an ACL that the JDBC driver is
failing to parse correctly. So if these are the same databases, something
has changed in the 9.0 representation of privileges. I'm not sure what
that change might be. I've built a driver with the attached patch to show
the failing ACL. If you can provide the output on the failure, we can
likely fix it with little trouble.
http://ejurka.com/pgsql/jars/acl/
Kris Jurka
Attachments:
acldebug.patch (text/plain, 1.5K) download
? acldebug.patch
Index: org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v
retrieving revision 1.57
diff -c -r1.57 AbstractJdbc2DatabaseMetaData.java
*** org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 10 Aug 2010 19:46:13 -0000 1.57
--- org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 9 Oct 2010 06:19:54 -0000
***************
*** 2585,2591 ****
byte column[] = rs.getBytes("attname");
String owner = rs.getString("usename");
String acl = rs.getString("relacl");
! Hashtable permissions = parseACL(acl, owner);
String permNames[] = new String[permissions.size()];
Enumeration e = permissions.keys();
int i = 0;
--- 2585,2596 ----
byte column[] = rs.getBytes("attname");
String owner = rs.getString("usename");
String acl = rs.getString("relacl");
! Hashtable permissions;
! try {
! permissions = parseACL(acl, owner);
! } catch (Exception e) {
! throw new PSQLException("Failed to parse: [" + acl + "]", PSQLState.UNEXPECTED_ERROR, e);
! }
String permNames[] = new String[permissions.size()];
Enumeration e = permissions.keys();
int i = 0;
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getTablePrivileges()
@ 2010-10-10 20:32 dmp <danap@ttc-cmc.net>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 8+ messages in thread
From: dmp @ 2010-10-10 20:32 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
> On Thu, 7 Oct 2010, danap wrote:
>
>> Today I update the one of the development systems for the MyJSQLView
>> project to test the PostgreSQL 9.0 database. Once the database was
>> installed and also the latest JDBC 9.0-801 I tested the program. The
>> application crashed and after some testing I attributed the exception to
>> the empty string "" parameter for the schemaPattern argument in
>> DatabaseMetaData.getTablePrivileges() for the JDBC.
>>
>> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
>> at java.lang.String.substring(Unknown Source)
>> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.addACLPrivileges(AbstractJdbc2DatabaseMetaData.java:2799)
>> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.parseACL(AbstractJdbc2DatabaseMetaData.java:2878)
>> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.getTablePrivileges(AbstractJdbc2DatabaseMetaData.java:2700)
> Kris Jurka wrote:
> This error has nothing to do with using "" as a schema pattern. The
> problem is that the server is supplying an ACL that the JDBC driver is
> failing to parse correctly. So if these are the same databases,
> something has changed in the 9.0 representation of privileges. I'm not
> sure what that change might be. I've built a driver with the attached
> patch to show the failing ACL. If you can provide the output on the
> failure, we can likely fix it with little trouble.
>
> http://ejurka.com/pgsql/jars/acl/
>
> Kris Jurka
I guess some additional information should have been provided
with the initial posting. The newly installed 9.0.1 database was
done anew. The database was dumped from 8.4.4 then imported into
the new 9.0.1 configuration. So the databases were the same. Second
I had already gotten the application up and running before posting
here by providing the space character for the schemaPattern parameter in
the getTablePrivileges() method.
Now it looks like you said Kris the exception has nothing to do with
the empty space, "", parameter for the schemaPattern except either
that documented valid input or NULL will bring out the exception. The
exception as your patch looks for has to do with parsing the reacl
entry. That entry is for the pg_largeobject and is {}.
The SQL query to bring up the needed data to see this is:
SELECT n.nspname,c.relname,u.usename,c.relacl FROM
pg_catalog.pg_namespace n, pg_catalog.pg_class c, pg_catalog.pg_user u
WHERE c.relnamespace = n.oid AND u.usesysid = c.relowner AND c.relkind
= 'r' AND c.relname LIKE '%' ORDER BY nspname, relname
I'm not sure if the mail list will except it, but attached is the
pdf output for that query for both the 8.4.4 and 9.0.1 databases.
Links here:
http://dandymadeproductions.com/temp/sql_empty_schemaPattern_8.4.4.pdf
http://dandymadeproductions.com/temp/sql_empty_schemaPattern_9.0.1.pdf
danap.
Attachments:
sql_empty_schemaPattern_8.4.4.pdf (application/pdf, 5.5K) download
sql_empty_schemaPattern_9.0.1.pdf (application/pdf, 5.7K) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getTablePrivileges()
@ 2010-10-16 00:51 Kris Jurka <books@ejurka.com>
parent: dmp <danap@ttc-cmc.net>
0 siblings, 2 replies; 8+ messages in thread
From: Kris Jurka @ 2010-10-16 00:51 UTC (permalink / raw)
To: dmp <danap@ttc-cmc.net>; +Cc: pgsql-jdbc
On Sun, 10 Oct 2010, dmp wrote:
> Now it looks like you said Kris the exception has nothing to do with
> the empty space, "", parameter for the schemaPattern except either
> that documented valid input or NULL will bring out the exception. The
> exception as your patch looks for has to do with parsing the reacl
> entry. That entry is for the pg_largeobject and is {}.
I've fixed this problem in CVS. I've posted a new driver version here
with the fix because there are no immediate plans for a new official
release.
http://ejurka.com/pgsql/jars/acl/
Kris Jurka
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getTablePrivileges()
@ 2010-10-16 16:15 dmp <danap@ttc-cmc.net>
parent: Kris Jurka <books@ejurka.com>
1 sibling, 0 replies; 8+ messages in thread
From: dmp @ 2010-10-16 16:15 UTC (permalink / raw)
To: pgsql-jdbc
> On Sun, 10 Oct 2010, dmp wrote:
>
>> Now it looks like you said Kris the exception has nothing to do with
>> the empty space, "", parameter for the schemaPattern except either
>> that documented valid input or NULL will bring out the exception. The
>> exception as your patch looks for has to do with parsing the reacl
>> entry. That entry is for the pg_largeobject and is {}.
>Kris Jurka wrote:
>
> I've fixed this problem in CVS. I've posted a new driver version here
> with the fix because there are no immediate plans for a new official
> release.
>
> http://ejurka.com/pgsql/jars/acl/
>
> Kris Jurka
Thank you Kris for your contributions. I updated my local CVS copy
of the pgjdbc and rebuilt the jar file myself and everything works fine.
danap.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getTablePrivileges()
@ 2010-10-19 15:03 David Fetter <david@fetter.org>
parent: Kris Jurka <books@ejurka.com>
1 sibling, 1 reply; 8+ messages in thread
From: David Fetter @ 2010-10-19 15:03 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
On Fri, Oct 15, 2010 at 08:51:48PM -0400, Kris Jurka wrote:
> On Sun, 10 Oct 2010, dmp wrote:
>
> >Now it looks like you said Kris the exception has nothing to do with
> >the empty space, "", parameter for the schemaPattern except either
> >that documented valid input or NULL will bring out the exception. The
> >exception as your patch looks for has to do with parsing the reacl
> >entry. That entry is for the pg_largeobject and is {}.
>
> I've fixed this problem in CVS. I've posted a new driver version
> here with the fix because there are no immediate plans for a new
> official release.
When do you plan another official release, or if that's not actually
planned yet, what kind of event would trigger one?
Cheers,
David (who'd like to see a fully compliant JDBC driver for PostgreSQL).
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getTablePrivileges()
@ 2010-10-19 18:47 Kris Jurka <books@ejurka.com>
parent: David Fetter <david@fetter.org>
0 siblings, 0 replies; 8+ messages in thread
From: Kris Jurka @ 2010-10-19 18:47 UTC (permalink / raw)
To: David Fetter <david@fetter.org>; +Cc: pgsql-jdbc
On Tue, 19 Oct 2010, David Fetter wrote:
> When do you plan another official release, or if that's not actually
> planned yet, what kind of event would trigger one?
>
Without making it sound too random, there is never really a schedule.
Some time passes, some bugs are fixed, when enough time has passed or a
particularly serious bug is fixed and I have the time, a new release goes
out.
So if a serious problem is found a new release could go out tomorrow, but
it's likely a new release won't go out for several months.
Kris Jurka
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2010-10-19 18:47 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-10-08 00:50 DatabaseMetaData.getTablePrivileges() danap@itstriangle.com
2010-10-08 01:16 DatabaseMetaData.getTablePrivileges() danap <danap@ttc-cmc.net>
2010-10-09 06:37 ` Kris Jurka <books@ejurka.com>
2010-10-10 20:32 ` dmp <danap@ttc-cmc.net>
2010-10-16 00:51 ` Kris Jurka <books@ejurka.com>
2010-10-16 16:15 ` dmp <danap@ttc-cmc.net>
2010-10-19 15:03 ` David Fetter <david@fetter.org>
2010-10-19 18:47 ` Kris Jurka <books@ejurka.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox