Thread: I found a bug in the jdbc driver

I found a bug in the jdbc driver

From
innuendo-nh@libero.it
Date:
I have just found a bug in the latest jdbc driver.

The error is in the class org.postgresql.jdbc2.AbstractJdbc2ResultSet

the method parseQuery() has a bug:

if you give as sql query something like "SELECT * FROM tablename;", that is a
valid sql statement, and you try to use a resultset update method (like
updateInt()),  you receive an SQLException saying: No Primary Keys. this is
because the method parseQuery() make a too simplified use of the
StringTokenizer, so the variable tableName is set at something like this:
"tablename;". So when the isUpdateable() method request for the primary keys of
the table 'tablename;', postgres answers there are no rows (it can't fond any
primary key for the table because it doesn't exists). The problem can be
resolved writing the sql statement very carefully: you must insert blanks
between any part of the sql statement (operators, keywords, ecc.). In my example
the solution is to insert a blank before the semicolon ("SELECT * FROM tablename
;").

I think i can resolve the problem, modifying the driver, but i wuold be glad to
know if someone else is already working at it now.

I hope this can be useful.

Inny.


Re: I found a bug in the jdbc driver

From
Dave Cramer
Date:
Good catch, go right ahead and fix it, please submit the fix as a
context diff

Thanks,

Dave
On Thu, 2003-05-22 at 09:57, =?iso-8859-1?Q?innuendo-nh@libero.it?=
wrote:
> I have just found a bug in the latest jdbc driver.
>
> The error is in the class org.postgresql.jdbc2.AbstractJdbc2ResultSet
>
> the method parseQuery() has a bug:
>
> if you give as sql query something like "SELECT * FROM tablename;", that is a
> valid sql statement, and you try to use a resultset update method (like
> updateInt()),  you receive an SQLException saying: No Primary Keys. this is
> because the method parseQuery() make a too simplified use of the
> StringTokenizer, so the variable tableName is set at something like this:
> "tablename;". So when the isUpdateable() method request for the primary keys of
> the table 'tablename;', postgres answers there are no rows (it can't fond any
> primary key for the table because it doesn't exists). The problem can be
> resolved writing the sql statement very carefully: you must insert blanks
> between any part of the sql statement (operators, keywords, ecc.). In my example
> the solution is to insert a blank before the semicolon ("SELECT * FROM tablename
> ;").
>
> I think i can resolve the problem, modifying the driver, but i wuold be glad to
> know if someone else is already working at it now.
>
> I hope this can be useful.
>
> Inny.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>
--
Dave Cramer <Dave@micro-automation.net>


Re: I found a bug in the jdbc driver

From
Kris Jurka
Date:

On Thu, 22 May 2003 =?iso-8859-1?Q?innuendo-nh@libero.it?= wrote:

> I have just found a bug in the latest jdbc driver.
>
> The error is in the class org.postgresql.jdbc2.AbstractJdbc2ResultSet
>
> the method parseQuery() has a bug:

There are a number of problems with this method.  It is a very simple
function trying to do a very complicated task.  I noted this in
the following message in December...

What could really use some work is the parseQuery method in
org.postgresql.jdbc2.AbstractJdbc2ResultSet.  When determining if a
ResultSet can be updated it does not check that all colums of the result
set aren't derived columns.  The check to make sure it is a single table
is not particularly good.  It fails on things like:

SELECT CURRENT_TIMESTAMP;
SELECT a AS from FROM t;
SELECT a FROM t1 LEFT JOIN t2 ON (t1.id=t2.id);
SELECT a FROM t1 UNION SELECT a FROM t2;

I'm not sure how much this can be improved without building a full blown
parser into the driver.


Re: I found a bug in the jdbc driver

From
Csaba Nagy
Date:
Hi all,

Is the semicolon legal in SQL statements passed to the JDBC API ?
I'm asking this because I've had problems with semicolons with other
drivers too (e.g. Oracle).
OTOH, for the given problem, my opinion is that the driver should use
some meta data passed back from the server after the server executes the
query to find out what tables/fields were used (makes no sense to write
a JDBC-side parser, too high risk of getting out of sync against the
server's parser). I guess this is not supported by the current
communication protocol, but my point is to push this as a real solution.

Cheers,
Csaba.


On Thu, 2003-05-22 at 15:57, innuendo-nh@libero.it wrote:
> I have just found a bug in the latest jdbc driver.
>
> The error is in the class org.postgresql.jdbc2.AbstractJdbc2ResultSet
>
> the method parseQuery() has a bug:
>
> if you give as sql query something like "SELECT * FROM tablename;", that is a
> valid sql statement, and you try to use a resultset update method (like
> updateInt()),  you receive an SQLException saying: No Primary Keys. this is
> because the method parseQuery() make a too simplified use of the
> StringTokenizer, so the variable tableName is set at something like this:
> "tablename;". So when the isUpdateable() method request for the primary keys of
> the table 'tablename;', postgres answers there are no rows (it can't fond any
> primary key for the table because it doesn't exists). The problem can be
> resolved writing the sql statement very carefully: you must insert blanks
> between any part of the sql statement (operators, keywords, ecc.). In my example
> the solution is to insert a blank before the semicolon ("SELECT * FROM tablename
> ;").
>
> I think i can resolve the problem, modifying the driver, but i wuold be glad to
> know if someone else is already working at it now.
>
> I hope this can be useful.
>
> Inny.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>



Re: I found a bug in the jdbc driver

From
Dave Cramer
Date:
The new protocol is going to deal with some of these issues.

Dave
On Mon, 2003-05-26 at 04:42, Csaba Nagy wrote:
> Hi all,
>
> Is the semicolon legal in SQL statements passed to the JDBC API ?
> I'm asking this because I've had problems with semicolons with other
> drivers too (e.g. Oracle).
> OTOH, for the given problem, my opinion is that the driver should use
> some meta data passed back from the server after the server executes the
> query to find out what tables/fields were used (makes no sense to write
> a JDBC-side parser, too high risk of getting out of sync against the
> server's parser). I guess this is not supported by the current
> communication protocol, but my point is to push this as a real solution.
>
> Cheers,
> Csaba.
>
>
> On Thu, 2003-05-22 at 15:57, innuendo-nh@libero.it wrote:
> > I have just found a bug in the latest jdbc driver.
> >
> > The error is in the class org.postgresql.jdbc2.AbstractJdbc2ResultSet
> >
> > the method parseQuery() has a bug:
> >
> > if you give as sql query something like "SELECT * FROM tablename;", that is a
> > valid sql statement, and you try to use a resultset update method (like
> > updateInt()),  you receive an SQLException saying: No Primary Keys. this is
> > because the method parseQuery() make a too simplified use of the
> > StringTokenizer, so the variable tableName is set at something like this:
> > "tablename;". So when the isUpdateable() method request for the primary keys of
> > the table 'tablename;', postgres answers there are no rows (it can't fond any
> > primary key for the table because it doesn't exists). The problem can be
> > resolved writing the sql statement very carefully: you must insert blanks
> > between any part of the sql statement (operators, keywords, ecc.). In my example
> > the solution is to insert a blank before the semicolon ("SELECT * FROM tablename
> > ;").
> >
> > I think i can resolve the problem, modifying the driver, but i wuold be glad to
> > know if someone else is already working at it now.
> >
> > I hope this can be useful.
> >
> > Inny.
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>
--
Dave Cramer <Dave@micro-automation.net>


Re: I found a bug in the jdbc driver

From
Dave Cramer
Date:
Good catch, go right ahead and fix it, please submit the fix as a
context diff

Thanks,

Dave
On Thu, 2003-05-22 at 09:57, =?iso-8859-1?Q?innuendo-nh@libero.it?=
wrote:
> I have just found a bug in the latest jdbc driver.
>
> The error is in the class org.postgresql.jdbc2.AbstractJdbc2ResultSet
>
> the method parseQuery() has a bug:
>
> if you give as sql query something like "SELECT * FROM tablename;", that is a
> valid sql statement, and you try to use a resultset update method (like
> updateInt()),  you receive an SQLException saying: No Primary Keys. this is
> because the method parseQuery() make a too simplified use of the
> StringTokenizer, so the variable tableName is set at something like this:
> "tablename;". So when the isUpdateable() method request for the primary keys of
> the table 'tablename;', postgres answers there are no rows (it can't fond any
> primary key for the table because it doesn't exists). The problem can be
> resolved writing the sql statement very carefully: you must insert blanks
> between any part of the sql statement (operators, keywords, ecc.). In my example
> the solution is to insert a blank before the semicolon ("SELECT * FROM tablename
> ;").
>
> I think i can resolve the problem, modifying the driver, but i wuold be glad to
> know if someone else is already working at it now.
>
> I hope this can be useful.
>
> Inny.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>