简体   繁体   中英

SUBSTRING with WHERE clause in MSDASQL causes error

I'm testing a feature in a Progress OpenEdge application that loads data into DB tables. 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. 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. 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. 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. I thought to avoid that by using SUBSTRING , but I still get a validation error when I try to use this query:

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

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

What I suspect is that the engine is reading non-matching records to see if they match the WHERE condition. If the non-matching records have fields longer than their SQL-WIDTH / MAX-WIDTH setting, that might give the result you're seeing.

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.

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.

In terms of "getting around" this - either shorten the data or make the SQL-WIDTH or MAX-WIDTH setting bigger for those fields.

Here's a KB on the topic: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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