Sybase 12.5-BDE-ADO“where myColumn=null”失败

发布于 2024-12-21 04:13:59 字数 952 浏览 4 评论 0原文

我们有一个旧的应用程序,它读取 SQL 文本文件并将它们发送到 Sybase ASE 12.51。我们的遗留应用程序是用 Delphi 5 编写的,并使用 BDE TQuery 组件来执行此过程,并使用 BDE SQLinks for Sybase 访问 Sybase。

伪代码:

SQLText=readSQLFile;
aTQuery.SQL.add(SQLText);
aTQuery.ExecSQL;

最近我们将数据库访问层迁移到Delphi XE ADO 实现 - TADOQuery,使用Sybase 提供的ADO 提供程序,仍然使用相同的模型:

SQLText=readSQLFile;
aTADOQuery.SQL.add(SQLText)
aTADOQuery.ExecSQL;

迁移到ADO 后,我们发现某些数据丢失。我们将失败追溯到这个 SQL 构造:

Select myColumn from myTable 
Where  tranID = null

知道这个构造充其量在语义上是有问题的,当我看到这段代码时,我做了“双重考虑”,但 Sybase 12.5 接受它 - 然而使用 ADO,这个段失败了。

我们决定更改:

Where  tranID = null

更改为

Where  tranID is null

然后加载丢失的数据 - 问题得到解决,对于该细分市场和其他几个细分市场也是如此。

< strong>有人对这种行为有解释吗? ADO 显然在哪里/为什么拦截并拒绝了该序列,而 BDE 却通过了它?

TIA

We have an old application that reads in SQL text files and sends them to Sybase ASE 12.51. Our legacy app was written in Delphi 5 and is using the BDE TQuery component for this process and accessing Sybase with the BDE SQLinks for Sybase.

Pseudo code:

SQLText=readSQLFile;
aTQuery.SQL.add(SQLText);
aTQuery.ExecSQL;

Recently we moved our DB access layer to the Delphi XE ADO implementation - TADOQuery, using the Sybase supplied ADO provider, still using same model:

SQLText=readSQLFile;
aTADOQuery.SQL.add(SQLText)
aTADOQuery.ExecSQL;

After migrating to ADO, we discovered that certain data was missing. We traced the failure to this SQL construct:

Select myColumn from myTable 
Where  tranID = null

Knowing that this construct is sematically questionable at best, I did a 'double take' when I saw this code, but Sybase 12.5 accepts it - however using ADO, this segment fails.

We decided to change:

Where  tranID = null

to

Where  tranID is null

Then the missing data was loaded - problem solved, for this segment and several others as well.

Does anyone have an explanation for this behavior? Where/why did ADO apparently intercept and reject this seqment whereas the BDE passed it thru?

TIA

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

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

发布评论

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

评论(1

听,心雨的声音 2024-12-28 04:13:59

“NULL”有非常特殊的含义,SQL需要特殊处理。您不能将值与“NULL”进行比较,这就是为什么有特殊运算符 IS (NOT) NULL 来检查它。详尽的解释需要一些篇幅,这里简单解释一下。

从“数学”的角度来看,NULL可以被认为是“无穷大”。您无法轻松比较两个无限值,例如考虑整数和偶数的集合。两者都是无限的,但从逻辑上看,前者比后者大。你只能说这两个集合都是无限的。

这也有助于解释例如为什么 1 + NULL 返回 NULL 等等(通常只有像 SUM() ecc 这样的聚合函数可能会忽略 NULL 值 - 忽略,而不是将 NULL 变成零)。

这个比喻在排序中可能不成立,因为某些数据库选择将 NULL 视为小于任何值(某种 -无穷大,从而按升序首先返回它们),反之亦然。有些可以选择设置返回 NULL 的位置。

检查有关 NULL 算术和 NULL 比较的数据库文档。 field = NULL 应该从来没有被使用过,不知道 Sybase 是否接受它,但大多数 SQL 实现不接受,我猜它不符合 SQL 标准。最好习惯 IS (NOT) NULL 语法。

更新:Sybase 有一个“set ansinull”选项,来自 文档(始终为 RTFM!),在 12.5.1 中它被扩展为不允许 '= NULL' 语法(当设置为 ON 以使其符合 SQL 标准时)。当设置为 OFF 时,“= NULL”相当于“IS NULL”。

也许 SQL 链接或 ADO 提供程序将其设置为一个值或另一个值。

"NULL" has a very special meaning, and SQL needs a special handling. You can't compare a value to "NULL", that's why there is the special operator IS (NOT) NULL to check for it. An exhaustive explanation would take some space, here a simple explanation.

From a "mathematical" point of view, NULL can be thought as "infinity". You can't compare two infinite values easily, for example think about the set of integer numbers and even numbers. Both are infinite, but it seems logical the former is larger than the latter. All you can say IS both sets are infinite.

That's also helps to explain for example why 1 + NULL returns NULL and so on (usually only aggregate functions like SUM() ecc. may ignore NULL values - ignore, not turn NULLs into zeroes).

This metaphor may not hold true in sorting, because some databases choose to consider NULL less than any value (some kind of -infinity and thereby returning them first in ascending order), other the other way round. Some have an option to set where to return NULLs.

Check your database documentation about NULL arithmetics and NULL comparisons. field = NULL should have never been used, don't know if Sybase accepts it, but most SQL implementations don't, and I guess it is not SQL standards compliant. It is far better to get used to the IS (NOT) NULL syntax.

Update: Sybase has a "set ansinull" option, from the documentation (always RTFM!), in 12.5.1 it was expanded to disallow the '= NULL' syntax (when set to ON to make it compliant with SQL standards). When set to OFF '= NULL' works as 'IS NULL'.

Maybe the SQL Links or the ADO provider set it to one value or the other.

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