传输到ClientDataset时的字符串截断

传输到ClientDataset时的字符串截断

本文介绍了传输到ClientDataset时的字符串截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebird 2.1,DevArt和Delphi 2010的DBExpress驱动程序。我一些以前与Delphi 2006一起使用的报告停止工作,并产生一条错误消息,指出算术异常,数字溢出或字符串截断发生了。我的代码此时发生错误:

I'm using Firebird 2.1, DBExpress Driver from DevArt and Delphi 2010. Some of my reports that used to work with Delphi 2006 stopped working and produced an error message indicating that "arithmetic exception, numeric overflow, or string truncation" had occurred. The error occurred at this point in my code:

cds.Data := dsProvider.Data;

我在SQL语句中找到了引起错误的位置:

I found the place in my SQL statement that caused the error:

iif(ytd.hPayType <> -1,t.sCode, 'NET') sPayType

T.sCode是Varchar(10)字段。我的结论是,查询将数据返回到dsProvider,并且当dsProvider.Data传递到cds.Data时,cds组件会根据接收到的第一个值设置字段宽度。如果将 iif更改为CASE语句,则会收到相同的错误消息。我设法通过以下方法解决了这个问题:

T.sCode is a Varchar(10) field. My conclusion is that the query returns data to the dsProvider and that when the dsProvider.Data is passed to the cds.Data, the cds component sets the field width based on the first value it receives. I get the same error message if I change the "iif" to a CASE statement. I managed to work around the issue by doing this:

 CAST(iif(ytd.hPayType <> -1,t.sCode, 'NET') AS varchar(10)) sPayType

因为这曾经在Delphi中工作没有CAST的2006年,我认为新行为是由于对TClientDataset的更新引起的。拥有旧的,更宽容的行为会很好。有没有一种方法可以配置ClientDataset以不加投诉地接受它,还是我只需要告诉用户基于iif和CASE语句对字符串结果进行CAST?

Since this used to work in Delphi 2006 without the CAST, I assume that the new behavior is due to an update to the TClientDataset. It would be nice to have the old, more forgiving behavior. Is there a way to configure the ClientDataset to accept this without a complaint or do I need to just tell my users to CAST on string results based on iif and CASE statements?

推荐答案

好了,有了更多的经验,看来我看到这种截断错误与Delphi 2010版本的ClientDatasets一致显示。如果找到不需要在查询中使用CAST的解决方案,则将其发布在这里。但是现在,我要关闭此帖子。

Well, with a little more experience, it looks like I am seeing this truncation error show up consistently with the Delphi 2010 version of ClientDatasets. If I find a resolution that does not involve having to use CAST in the query, I will post it here. But for now, I am going to close this posting.

这篇关于传输到ClientDataset时的字符串截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:01