String truncation when passing to ClientDataset

I use Firebird 2.1, DBExpress Driver from DevArt and Delphi 2010. Some of my reports, which were used to work with Delphi 2006, stopped working and issued an error message indicating that "arithmetic exception, numeric overflow or line truncation" had occurred. An error occurred at this point in my code:

cds.Data := dsProvider.Data; 

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

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

T.sCode - Varchar field (10). My conclusion is that the query returns data to dsProvider and that when dsProvider.Data is passed to 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 "iif" to a CASE statement. I was able to solve the problem by following these steps:

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

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

+2
source share
2 answers

Well, with a little more experience, it looks like I see that this truncation error is showing up sequentially with the ClientDatasets Delphi 2010 version. If I find a resolution that does not require the use of CAST in the request, I will post it here. But now I am going to close this publication.

0
source

In my last assignment, I worked a lot with firebird, this error occurs when you already have a large value for the length of the varchar field stored in db, and you are trying to "get" a string in delphi, try updating the value in db to a shorter (length) varchar . I'm not sure what works for you, but give it a try.

0
source

Source: https://habr.com/ru/post/913029/


All Articles