简体   繁体   English

在MSDASQL中用WHERE子句进行SUBSTRING会导致错误

[英]SUBSTRING with WHERE clause in MSDASQL causes error

I'm testing a feature in a Progress OpenEdge application that loads data into DB tables. 我正在测试Progress OpenEdge应用程序中的一项功能,该功能可将数据加载到数据库表中。 Many of the fields in the table I'm testing are limited by our application to 256 characters, so I'm doing some edge case testing, trying to load in entries that are less than, equal to, and greater than 256 characters. 我正在测试的表中的许多字段都被我们的应用程序限制为256个字符,因此我正在进行一些边缘案例测试,试图加载小于,等于和大于256个字符的条目。 After the data load, I query the DB and validate the results. 数据加载后,我查询数据库并验证结果。 I'm using the OLE DB provider for ODBC drivers through the testing program TestComplete. 我正在通过测试程序TestComplete将OLE DB提供程序用于ODBC驱动程序。 This is the query I'm using: 这是我正在使用的查询:

SELECT SUBSTRING(lname, 1, 30)
FROM pub.referral
WHERE lname LIKE 'valid%'

Before I run my test, the ODBC driver has no problem with this query. 在运行测试之前,ODBC驱动程序对此查询没有任何问题。 After I run it, though, there are fields in this table that have 256 characters, and the ODBC driver has problems with data of that length. 但是,运行它后,此表中的字段包含256个字符,并且ODBC驱动程序存在该长度的数据问题。 I thought to avoid that by using SUBSTRING , but I still get a validation error when I try to use this query: 我本想通过使用SUBSTRING避免这种情况,但是当我尝试使用此查询时,仍然出现验证错误:

The specified query is invalid. Database engine reports: [DataDirect][ODBC Progress OpenEdge Wire Protocol driver]Error in row

Informative! 信息化! That's the error I usually see when there's data in a table that's longer than ODBC likes. 当表中的数据长于ODBC喜欢的数据时,我通常会看到这种错误。 Strangely, though, if I take out the WHERE clause, the query validates and returns data in 30 character chunks, like I specified in the SUBSTRING . 不过,奇怪的是,如果我删除WHERE子句,查询将以30个字符的块形式验证并返回数据,就像我在SUBSTRING指定的那样。

Is this happening because I have more characters than the ODBC driver expects in a field, or because of something else having to do with the WHERE clause (incorrect syntax, etc.?) How can I get around this? 发生这种情况是因为我在一个字段中所拥有的字符数比ODBC驱动程序所期望的要多,或者是由于其他与WHERE子句有关的事情(语法不正确等?)。我该如何解决呢? I would like to do this without changing settings through dbtool - it's important to me to have the particular settings that I have in my DB in order for my tests to be accurate. 我想做到这一点而无需通过dbtool更改设置-对我来说,拥有我数据库中的特定设置对我来说很重要,以使测试准确。

What I suspect is that the engine is reading non-matching records to see if they match the WHERE condition. 我怀疑引擎正在读取不匹配的记录,以查看它们是否符合WHERE条件。 If the non-matching records have fields longer than their SQL-WIDTH / MAX-WIDTH setting, that might give the result you're seeing. 如果不匹配的记录的字段长于其SQL-WIDTH / MAX-WIDTH设置,则可能会得到您看到的结果。

Doing the search without using a WHERE clause means every record is part of the result set and will get processed by the SUBSTRING() command before being output. 在不使用WHERE子句的情况下进行搜索意味着每条记录都是结果集的一部分,并且将在输出之前由SUBSTRING()命令进行处理。

A way to test this is to do a WHERE with an equality match - the engine should only read records which match the WHERE spec, do the SUBSTRING(), and work as expected. 一种测试方法是在WHERE中进行相等匹配-引擎应仅读取与WHERE规范匹配的记录,执行SUBSTRING()并按预期工作。

In terms of "getting around" this - either shorten the data or make the SQL-WIDTH or MAX-WIDTH setting bigger for those fields. 就“解决”而言-缩短数据或使这些字段的SQL-WIDTH或MAX-WIDTH设置更大。

Here's a KB on the topic: http://knowledgebase.progress.com/articles/Article/P162121 这是有关该主题的知识库: http : //knowledgebase.progress.com/articles/Article/P162121

Here's a KB on dealing with "too big" columns: http://knowledgebase.progress.com/articles/Article/P126779?q=SQL%3A+Data+truncated+and+Invalid+long+datatype+and+error&l=en_US&type=Article__kav&fs=Search&pn=1 这是处理“过大”列的知识库: http : //knowledgebase.progress.com/articles/Article/P126779?q=SQL%3A+Data+截断+和+无效+ long +数据类型+和+ error&l = EN_US&键入= Article__kav&FS =搜寻和PN = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM