Subject | Re: [firebird-support] "arithmetic exception, numeric overflow, or string truncation" - string is compared differently if it is passed as parameter. |
---|---|
Author | Helen Borrie |
Post date | 2009-04-03T07:50:19Z |
At 07:20 PM 3/04/2009, you wrote:
SELECT * FROM ZZZ WHERE XXX LIKE :XXX
is passed across the API as
SELECT * FROM ZZZ WHERE XXX LIKE ?
The XSQLVAR structure has been primed to expect a string of no more than 6 characters (that's what VARCHAR(6) prescribes) but you are passing 7.
Make the parameterised statement as
SELECT * FROM ZZZ WHERE XXX LIKE :XXX || '%'
and pass only the value for the parameter itself.
If all of these varchar(6) values are 6 characters long then you don't want to use the LIKE predicate, anyway. It's an equality check you want for this. If in fact you have some values that are shorter than 6 characters, use STARTING WITH instead and avoid the problems of having to mess about with Delphi strings:
SELECT * FROM ZZZ WHERE XXX STARTING WITH :XXX
./heLen
>I tried to post it to newsgroup, but it didn't arrive, so I'm posting itWow, that's a strange guess! A "named parameter" is a purely Delphi thing.
> to mailing list also.
>
>Table ZZZ has VARCHAR(6) field XXX
>
>Following query works without errors:
>
>"SELECT * FROM ZZZ WHERE XXX LIKE '001001%'"
>
>But following query does not:
>"SELECT * FROM ZZZ WHERE XXX LIKE :XXX"
>where parameter :XXX is set to '001001%'
>
>The error is:
>Dynamic SQL Error
>SQL Error Code = -303
>arithmetic exception, numeric overflow, or string truncation.
>
> I understand, that it is caused by the fact, that parameter is longer
>then field name, but is this correct behavior?
>And why is it behavingA parameter is not a variable: it is a placeholder for a data element of a known type. The statement
>differently, when string is embedded in SQL instead of passing it as
>parameter?
SELECT * FROM ZZZ WHERE XXX LIKE :XXX
is passed across the API as
SELECT * FROM ZZZ WHERE XXX LIKE ?
The XSQLVAR structure has been primed to expect a string of no more than 6 characters (that's what VARCHAR(6) prescribes) but you are passing 7.
Make the parameterised statement as
SELECT * FROM ZZZ WHERE XXX LIKE :XXX || '%'
and pass only the value for the parameter itself.
If all of these varchar(6) values are 6 characters long then you don't want to use the LIKE predicate, anyway. It's an equality check you want for this. If in fact you have some values that are shorter than 6 characters, use STARTING WITH instead and avoid the problems of having to mess about with Delphi strings:
SELECT * FROM ZZZ WHERE XXX STARTING WITH :XXX
./heLen