views:

72

answers:

2

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;

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

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

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

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?

A: 

I used to work a lot with firebird in my last job, this error happens when you already have a large (length) varchar field value stored in the db and you are trying to "get" the string in delphi, try updating the value in the db to a smaller (length) varchar. I'm not sure if will work for you but give it a try.

eiefai
It actually seems like Firebird is doing its job correctly on this. The data comes out of a varchar(10) field in the Firebird database into a TSQLQuery. On the step where this data is transferred through a dataset provider to a client dataset the issue arises. I am speculating that when the client dataset gets a field based on a function or CASE statement it does not know how long the field might get but unfortunately sets the length of the receiving field at whatever length the first instance of data is. It could be that the only way around it is the CAST that I did.
A: 

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.