On Tue, 2009-09-15 at 19:26 +0000, Joseph Shraibman wrote:
> The following bug has been logged online:
>
> Bug reference: 5058
> Logged by: Joseph Shraibman
> Email address: jks@selectacast.net
> PostgreSQL version: 8.2.14
> Operating system: Linux
> Description: [jdbc] Silent failure with executeUpdate()
> Details:
>
> I was trying to figure out why I was getting different results with sql I
> was running through jdbc and running through psql. I was able to fix the
> bug by changing an executeUpdate() to an execute(). See attached code.
>
While the test case is appreciated, it's not really that clear what's
expected to happen vs what happens, at what point things go wrong and
under what circumstances, etc. Looking at your code and your post, I
can't tell:
- If the code you've attached is before or after the change described
- Where the change is/was made
- Why
- What it actually does
There are also a couple of randomly commented-out bits of code that seem
odd, some code seems like unnecessary wrapper code in such a simple
example ( eg getStatement(...) ) and some of the code is downright
hairy. In particular:
private static StringBuilder toString(Object o, StringBuilder sb)
cries out "use parameterized queries!". You're making life unnecessarily
hard for yourself, increasing SQL injection risk dramatically, and
giving yourself more to debug than you need by building queries as
strings including all parameters.
Perhaps you could pare down the code to that required to demonstrate the
issue and document the issue a little? Cut out unnecessary or duplicate
code (why are there two doQuery() implementations with mostly the same
code), drop any result-printing code etc if it doesn't help demonstrate
the bug you're reporting, remove commented out code and empty blocks,
and generally tidy things up so that the reader can read it to follow
your problem report, not puzzle out why your code does things how it
does.
Above all else, make sure to provide an explanation of where the problem
you are reporting arises, what actually happens, what you expect to
happen instead, and what exactly you change to "fix" it.
It might help to turn detailed error logging on in the server and
capture the server error log for your "silent" query failure, too.
--
Craig Ringer