views:

58

answers:

1

I have some queries being run in a java program that makes use of a PostgreSQL database and some parts of an old version of JDataStore (the parts used to interact with the database). Sometimes the queries are sent to the database twice from one execution of a query. What's even more odd is that the first query sent is slightly different than the second, and is incorrect. For example:

First Query (incorrect)
SELECT b."construct_id", c."instance_id", a.SymbolName, c.Address AddressDecimal,
       c.Description, b.ConstructName, a.DeclarationType, a.Symbol_id,
       a.SymbolType_id, a.Construct_id, a.Leaf 
FROM tblSymbolDeclaration a, tblLanguageConstructName b, tblSymbolInstance c  
WHERE a.Construct_id = b.Construct_id and a.Symbol_id = c.Symbol_id
  and a.DeclarationType = 1 and a.Root = 1

Note the two fields at the start of that query, and the lack of the word 'as', compared with this:

Second Query (correct)
SELECT a.SymbolName, c.Address as AddressDecimal, c.Description, 
       b.ConstructName, a.DeclarationType, a.Symbol_id, a.SymbolType_id,
       a.Construct_id, a.Leaf 
FROM tblSymbolDeclaration a, tblLanguageConstructName b, tblSymbolInstance c 
WHERE a.Construct_id = b.Construct_id and a.Symbol_id = c.Symbol_id 
  and a.DeclarationType = 1 and a.Root = 1

We have a set list of queries we use, and the first query is not even in that list. What could cause this? (Sorry that I have provided no code, but it is not feasible to do so in this situation.)

A: 

The query wouldn't just "change" like that. I'm sure the field name "instance_id" isn't being created in the ether. I think it is a mistake in the construction of the query itself.

  1. How is the query being constructed and passed to the database?
  2. Where are you seeing the "incorrect" query exactly?

Ok, shot in the dark here, but try changing your query to this just for the sake of changing it. See what your server tells you then.

String myQuery = ""
+ "SELECT a.symbolname, "
+ "       c.address AS addressdecimal, "
+ "       c.DESCRIPTION, "
+ "       b.constructname, "
+ "       a.declarationtype, "
+ "       a.symbol_id, "
+ "       a.symboltype_id, "
+ "       a.construct_id, "
+ "       a.leaf "
+ "FROM   tblsymboldeclaration a "
+ "       INNER JOIN tbllanguageconstructname b "
+ "         ON a.construct_id = b.construct_id "
+ "       INNER JOIN tblsymbolinstance c "
+ "         ON a.symbol_id = c.symbol_id "
+ "WHERE  a.declarationtype = 1 "
+ "       AND a.ROOT = 1";
Melvin
Yes, those would be my thoughts too. I'm no SQL expert, however.1. The query is stored as a string in source code (the whole thing - it's not constructed in code at all). I pass the string directly to a QueryDataSet object and then run executeQuery() on it (these are from JDataStore; I don't expect anyone to know much about it) 2. I'm seeing both queries in the SQL server's log file.
Chris
Your edit seems to have worked, but I don't understand why.
Chris