pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: danap <danap@ttc-cmc.net>
To: pgsql-jdbc@postgresql.org
Subject: DatabaseMetaData.getTablePrivileges()
Date: Thu, 07 Oct 2010 19:16:53 -0600
Message-ID: <4CAE7105.1080805@ttc-cmc.net> (raw)

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; }

view thread (8+ messages)  latest in thread

Message-ID: <4CAE7105.1080805@ttc-cmc.net>
Permalink:  ../4CAE7105.1080805@ttc-cmc.net/
Also on:    postgresql.org/message-id/4CAE7105.1080805@ttc-cmc.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: danap@ttc-cmc.net
  Subject: Re: DatabaseMetaData.getTablePrivileges()
  In-Reply-To: <4CAE7105.1080805@ttc-cmc.net>
  References: <4CAE7105.1080805@ttc-cmc.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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