Обсуждение: jdbc ResultSetMetaData::isWritable()
hello, i think there's a simple error in the "isWritable" method of the ResultSetMetaData class in the jdbc2 postgresql driver. the isWritable method looks like this: public boolean isWritable(int column) throws SQLException { if (isReadOnly(column)) return true; else return false; } and isReadOnly looks like this: public boolean isReadOnly(int column) throws SQLException { return false; } hence, isWritable() will always return false. this is something of a problem :) just switch the booleans in isReadOnly and everything should work just fine. i have verified this in the 7.1.3 source, and it appears to work the same way in at least 7.1.2 as well. let me know if i can provide further information. thanks, ian wehrman -- Labfire, Inc. Seamless Technical Solutions http://labfire.com/
On Mon, 3 Sep 2001 22:01:17 -0500, you wrote: >public boolean isWritable(int column) throws SQLException >{ > if (isReadOnly(column)) > return true; > else > return false; >} The author probably intended: public boolean isWritable(int column) throws SQLException { return !isReadOnly(column); } And if he would have coded it this way he wouldn't have made this mistake :-) >hence, isWritable() will always return false. this is something >of a problem :) Why exactly? In a way, true is just as incorrect as false, and perhaps it should throw "not implemented". But I guess that would be too non-backwardly-compatible. >let me know if i can provide further information. Will you submit a patch? Regards, René Pijlman <rene@lab.applinet.nl>
Well, if it is that easy, I can do it. Patch attached and applied. > On Mon, 3 Sep 2001 22:01:17 -0500, you wrote: > >public boolean isWritable(int column) throws SQLException > >{ > > if (isReadOnly(column)) > > return true; > > else > > return false; > >} > > The author probably intended: > > public boolean isWritable(int column) throws SQLException > { > return !isReadOnly(column); > } > > And if he would have coded it this way he wouldn't have made > this mistake :-) > > >hence, isWritable() will always return false. this is something > >of a problem :) > > Why exactly? In a way, true is just as incorrect as false, and > perhaps it should throw "not implemented". But I guess that > would be too non-backwardly-compatible. > > >let me know if i can provide further information. > > Will you submit a patch? > > Regards, > Ren? Pijlman <rene@lab.applinet.nl> > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 Index: src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java,v retrieving revision 1.3 diff -c -r1.3 ResultSetMetaData.java *** src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java 2001/08/24 16:50:16 1.3 --- src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java 2001/09/06 18:25:56 *************** *** 419,428 **** */ public boolean isWritable(int column) throws SQLException { ! if (isReadOnly(column)) ! return true; ! else ! return false; } /** --- 419,425 ---- */ public boolean isWritable(int column) throws SQLException { ! return !isReadOnly(column); } /** Index: src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java,v retrieving revision 1.3 diff -c -r1.3 ResultSetMetaData.java *** src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java 2001/08/24 16:50:18 1.3 --- src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java 2001/09/06 18:25:56 *************** *** 414,423 **** */ public boolean isWritable(int column) throws SQLException { ! if (isReadOnly(column)) ! return true; ! else ! return false; } /** --- 414,420 ---- */ public boolean isWritable(int column) throws SQLException { ! return !isReadOnly(column); } /**
On Thu, 6 Sep 2001 14:26:49 -0400 (EDT), you wrote: >Well, if it is that easy, I can do it. Patch attached and applied. > >> On Mon, 3 Sep 2001 22:01:17 -0500, you wrote: >> public boolean isWritable(int column) throws SQLException >> { >> return !isReadOnly(column); >> } Actually, I think this change has a consequence for this method in the same class: public boolean isDefinitelyWritable(int column) throws SQLException { return isWritable(column); } This is from the JDBC spec (http://java.sun.com/j2se/1.3/docs/api/java/sql/ResultSetMetaData.html): isReadOnly() - Indicates whether the designated column is definitely not writable. isWritable() - Indicates whether it is possible for a write on the designated column to succeed. isDefinitelyWritable() - Indicates whether a write on the designated column will definitely succeed. At this time we don't really implement the fine semantics of these methods. I would suggest the following defaults: isReadOnly() false isWritable() true isDefinitelyWritable() false And that would mean that your patch is correct, but isDefinitelyWritable() would need to be patched accordingly: public boolean isDefinitelyWritable(int column) throws SQLException { return false; } Again, both in jdbc1 and jdbc2. Regards, René Pijlman <rene@lab.applinet.nl>
Change applied. Thanks. > On Thu, 6 Sep 2001 14:26:49 -0400 (EDT), you wrote: > >Well, if it is that easy, I can do it. Patch attached and applied. > > > >> On Mon, 3 Sep 2001 22:01:17 -0500, you wrote: > >> public boolean isWritable(int column) throws SQLException > >> { > >> return !isReadOnly(column); > >> } > > Actually, I think this change has a consequence for this method > in the same class: > > public boolean isDefinitelyWritable(int column) > throws SQLException > { > return isWritable(column); > } > > This is from the JDBC spec > (http://java.sun.com/j2se/1.3/docs/api/java/sql/ResultSetMetaData.html): > > isReadOnly() - Indicates whether the designated column is > definitely not writable. > > isWritable() - Indicates whether it is possible for a write on > the designated column to succeed. > > isDefinitelyWritable() - Indicates whether a write on the > designated column will definitely succeed. > > At this time we don't really implement the fine semantics of > these methods. I would suggest the following defaults: > > isReadOnly() false > isWritable() true > isDefinitelyWritable() false > > And that would mean that your patch is correct, but > isDefinitelyWritable() would need to be patched accordingly: > > public boolean isDefinitelyWritable(int column) > throws SQLException > { > return false; > } > > Again, both in jdbc1 and jdbc2. > > Regards, > Ren? Pijlman <rene@lab.applinet.nl> > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026