This is a migrated thread and some comments may be shown as answers.
String truncation exception from comparing '12345' to Char(3) '123' using Firebird
1 Answer 6 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Petteri
Top achievements
Rank 1
Petteri asked on 12 Jun 2015, 12:36 PM

I'm using this LINQ to check if input is valid

Kansalaisuuskoodis.Any(k => k.Kansalaisuuskoodi == input)
Where 'input' is a string and Kansalaisuuskoodi is a string mapped to a char(3) column (model generated from a Firebird database).

This call will fail if the length of input string is not exactly 3 characters:

 

Telerik.OpenAccess.Exceptions.DataStoreException: Count(*) query failed: Telerik.OpenAccess.RT.sql.SQLException: arithmetic exception, numeric overflow, or string truncation
string right truncation
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.RelationalStorageManager.executeCount(RelationalCompiledQuery cq, QueryParameters parameters)
SELECT COUNT(1) FROM ( SELECT a."Kansalaisuuskoodi" AS COL1, a."Kayttotiedot" AS COL2, a."LUONTIAIKA" AS COL3, a."MUUTOSAIKA" AS COL4, a."Maa" AS COL5 FROM "Kansalaisuus" a WHERE a."Kansalaisuuskoodi" = ? ) AS TMP_COUNT

This seems odd to me, since Firebird sql is working as expcted with such a query (comparing char(3) column with a varchar(5) input).

So currently I compare the lenght of the input before checking the database, but this seems like something should not be needed. 
Any idea what could cause this exception?

1 Answer, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 16 Jun 2015, 11:59 AM
Hi Petteri,
Thank you for contacting us.
The behavior is expected. Telerik Data Access does not truncate information when binding parameters. In your case, since you are using firebird, the database is complaining about the length of the string. Other databases silently accept the values and will truncate as needed.
So you proposed implementation, checking the length by yourself, is the right thing in this situation.

I hope this information is helpful for you.
Do come back in case you have any other question.

Regards,
Ralph Waldenmaier
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
LINQ (LINQ specific questions)
Asked by
Petteri
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Share this question
or