Обсуждение: DatabaseMetaData.getTablePrivileges()
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) ---------------------------------------------------------- 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; }
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
Вложения
> 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.
Вложения
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
> 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.
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
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