Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delphi "Invalid use of keyword" in TQuery

Tags:

delphi

bde

tquery

I'm trying to populate a TDBGrid with the results of the following TQuery against the file Journal.db:

select * from Journal
where  Journal.where = "RainPump"

I've tried both Journal."Where" and Journal.[Where] to no avail.

I've also tried: select Journal.[Where] as "Location" with the same result.

Journal.db is a file created by a third party and I am unable to change the field names.

The problem is that the field I'm interested in is called 'where' and understandably causes the above error. How do I reference this field without causing the BDE (presumably) to explode?

like image 366
Baldric Avatar asked Dec 22 '22 14:12

Baldric


2 Answers

Aah, I'm loving delphi again... I found a workaround. The TQuery component has the Filter property :-)
I omitted the "Where=" where clause from the query whilst still keeping all the other 'and' conditions.
I set the Filter property to "Where = 'RainPump'".
I set the Filtered property to True and life is good again.

I'm still wondering if there's a smarter way to do this using this old technology but if it's stupid and it works, then it's not stupid.

like image 149
Baldric Avatar answered Jan 25 '23 17:01

Baldric


I'm afraid that someone reading this thread will get the impression that the BDE SQL engine cannot handle the query:

select * from Journal where Journal."Where" = "RainPump"

and will waste their time unnecessarily circumlocuting around it.

In fact this construction works fine. The quotes around "Where" keeps the BDE from interpreting it as a keyword, just as you would expect.

I don't know what is wrong in Baldric's particular situation, or what he tried in what order. He describes the problem as querying a *.db table, but his SQL error looks more like something you'd get in passthrough mode. Or, possibly he simplified his code for submission, thus eliminating the true cause of the error.

My tests performed with: BDE v.5.2 (5.2.0.2) Paradox for Windows v. 7 (32b) Delphi 5.0 (5.62)

Various versions of the statement that succeed:

select * from Journal D0 where D0."Where" = "RainPump"
select * from Journal where Journal."Where" = "RainPump"
select * from ":common:Journal" D0 where D0."Where" = "RainPump"
select * from ":common:Journal" where ":common:Journal"."Where" = "RainPump"
select * from :common:Journal where Journal."Where" = "RainPump"
select * from ":common:Journal" D0 where D0."GUMPIK" = 3
select * from ":common:Journal" where ":common:Journal"."GUMPIK" = 3
select * from :common:Journal where Journal."GUMPIK" = 3

Versions of the statement that look correct but fail with "Invalid use of keyword":

select * from ":common:Journal" where :common:Journal."Where" = "RainPump"
select * from :common:Journal where :common:Journal."Where" = "RainPump"
select * from ":common:Journal" where :common:Journal."GUMPIK" = 3
select * from :common:Journal where :common:Journal."GUMPIK" = 3

-Al.

like image 40
A. I. Breveleri Avatar answered Jan 25 '23 18:01

A. I. Breveleri