开发者

Additional, unspecified fields being added to a query

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       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.)


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";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜