delphi“关键字使用无效” 在 TQuery 中

发布于 2024-07-06 02:57:53 字数 403 浏览 3 评论 0原文

我正在尝试使用以下针对文件 Journal.db 的 TQuery 的结果填充 TDBGrid:

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

我已经尝试了 Journal."Where"Journal.[Where]无济于事。

我也尝试过:选择 Journal.[Where] 作为“位置” 具有相同的结果。

Journal.db 是第三方创建的文件,我无法更改字段名称。

问题是我感兴趣的字段称为“where”,并且可以理解地导致上述错误。 我如何引用该字段而不导致 BDE(大概)爆炸?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

夜雨飘雪 2024-07-13 02:57:53

啊,我又爱上了delphi...我找到了一个解决方法。 TQuery 组件具有 Filter 属性:-)
我在查询中省略了“Where=”where 子句,同时仍然保留所有其他“and”条件。
我将 Filter 属性设置为“Where = 'RainPump'”。
我将 Filtered 属性设置为 True,生活再次美好起来。

我仍然想知道是否有更聪明的方法使用这种旧技术来做到这一点,但如果它很愚蠢并且有效,那么它并不愚蠢。

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.

酒废 2024-07-13 02:57:53

我担心阅读此线程的人会得到这样的印象:BDE SQL 引擎无法处理该查询:

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

并且会浪费时间不必要地绕圈子。

事实上,这种构造效果很好。 “Where”周围的引号使 BDE 不会将其解释为关键字,正如您所期望的那样。

我不知道鲍德里克的特殊情况出了什么问题,也不知道他以什么顺序尝试过。 他将问题描述为查询 *.db 表,但他的 SQL 错误看起来更像是在直通模式下遇到的错误。 或者,可能他简化了提交代码,从而消除了错误的真正原因。

我的测试执行:
BDE v.5.2 (5.2.0.2)
Windows 版 Paradox v.7 (32b)
Delphi 5.0 (5.62)

成功的语句的各种版本:

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

看起来正确但因“无效使用关键字”而失败的语句版本:

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。

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.

好久不见√ 2024-07-13 02:57:53

您可以将结果集插入到带有“值”(不指定列名)的新表中,其中您在新表中给出了自己的列名,然后使用 TQuery 从该表中进行选择,如下所示:

Query1.sql.clear;
query1,sql.add('Insert into newtable values (select * from Journal);');
query1.sql.add('Select * from newtable where newcolumn = "Rainpump";');
query1.open;

You can insert the resultset into a new table with "values" (specifying no column names) where you have given your own column names in the new table and then do a select from that table, Using a TQuery, something like:

Query1.sql.clear;
query1,sql.add('Insert into newtable values (select * from Journal);');
query1.sql.add('Select * from newtable where newcolumn = "Rainpump";');
query1.open;
生生不灭 2024-07-13 02:57:53

像这样重写它,应该可以工作:

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

Rewrite it like this, should work:

select * from Journal where Journal.[where] = "RainPump"
毁梦 2024-07-13 02:57:53

我,我会重命名这个尴尬的专栏。

Me, I'd rename the awkward column.

尐籹人 2024-07-13 02:57:53

在 MySQL 中,表/列名称可以用 ``(带角度的单引号)括起来。 我不确定 BDE 允许什么,但你可以尝试将 [where] 替换为 `where`

In MySQL, table/column names can be enclosed in `` (the angled single quotes). I'm not sure what the BDE allows, but you could try replacing [where] with `where`

沧桑㈠ 2024-07-13 02:57:53
select * from Journal where Journal."where" = "RainPump"
select * from Journal where Journal."where" = "RainPump"
浅沫记忆 2024-07-13 02:57:53

好的,所以在任何 SQL 系统中以键盘命名列都是不好的。 您会将列命名为“select”或“count”或“alter”或“table”,或者可能只是为了好玩“truncate”或“drop”? 我希望不会。

即使您针对实例构建了解决方案,您也会为追随您的人创建一个雷区。 按照mj2008说的做,重命名血腥专栏。

允许此列名称持续存在是构建系统的人最糟糕的例子,并且会让您出现在任何项目经理的粪便列表中。

Ok, so naming columns after keyboards is bad in ANY SQL system. Would you name a column "select" or "count" or "alter" or "table" or perhaps just for the fun of it "truncate" or "drop"? I would hope not.

Even if you build in the work around for this instance you are creating a mine field for whomever comes after you. Do what mj2008 said and rename the bloody column.

Allowing this column name to persist is the worst example of someone who is building a system and would get you on the poop list for any project manager.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文