New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FbCommand mishandling BLOB field parameters [DNET420] #418
Comments
Modified by: Scott Morgan (blumf)description: Assume a table of form: Then attempt the following, looking for a non-existent value: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE @search_str", conn)) An exception is thrown by ExecuteReader: Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: arithmetic exception, numeric overflow, or string truncation The problem seems to be the lib mistaking the field for a VARCHAR type when the resultset is empty. A workaround is to explicitly cast the parameter as a BLOB: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE CAST(@search_str" AS BLOB SUB_TYPE 1), conn)) => Assume a table of form: Then attempt the following, looking for a non-existent value: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE @search_str", conn)) An exception is thrown by ExecuteReader: Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: arithmetic exception, numeric overflow, or string truncation The problem seems to be the lib mistaking the field for a VARCHAR type when the resultset is empty. A workaround is to explicitly cast the parameter as a BLOB: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE CAST(@search_str AS BLOB SUB_TYPE 1)", conn)) |
Commented by: Scott Morgan (blumf) Confirmed that it also throws exception when resultset has data |
Modified by: Scott Morgan (blumf)description: Assume a table of form: Then attempt the following, looking for a non-existent value: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE @search_str", conn)) An exception is thrown by ExecuteReader: Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: arithmetic exception, numeric overflow, or string truncation The problem seems to be the lib mistaking the field for a VARCHAR type when the resultset is empty. A workaround is to explicitly cast the parameter as a BLOB: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE CAST(@search_str AS BLOB SUB_TYPE 1)", conn)) => Assume a table of form: Then attempt the following query: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE @search_str", conn)) An exception is thrown by ExecuteReader: Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: arithmetic exception, numeric overflow, or string truncation The problem seems to be the lib mistaking the field for a VARCHAR type. A workaround is to explicitly cast the parameter as a BLOB: FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE CAST(@search_str AS BLOB SUB_TYPE 1)", conn)) summary: FbCommand mishandling BLOB field parameters on empty resultsets => FbCommand mishandling BLOB field parameters |
Modified by: @cincuranet |
Modified by: @cincuranet |
Modified by: @cincuranet |
Modified by: @cincuranetstatus: Open [ 1 ] => In Progress [ 3 ] |
Commented by: @cincuranet I'm unable to reproduce this issue with version 2.7.7. Can you recheck? |
Commented by: Scott Morgan (blumf) Retested with 2.7.7, still failing. Make sure the search term is over 7 chars long, it works okay if it's below that limit. i.e. Exception dump from 2.7.7: Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: arithmetic exception, numeric overflow, or string truncation |
Commented by: @cincuranet This code works in 2.7.7 fine: Provide a reproducible test case. |
Commented by: Scott Morgan (blumf) This is interesting. I was running FB 2.5.0, getting the error. Upgraded to 2.5.1 and it now works, the field type is correctly identified as DbDataType.Text instead of VarChar Wonder if it's related to CORE3446 |
Commented by: @cincuranet Might be. So now it behaves OK? |
Commented by: Scott Morgan (blumf) Yeah, for FB 2.5.1 at least. Don't know if you'd want to test against FB 2.1 or earlier though. |
Submitted by: Scott Morgan (blumf)
Is related to DNET124
Assume a table of form:
CREATE TABLE PHRASES ( TEXT BLOB SUB_TYPE 1 );
Then attempt the following query:
FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE @search_str", conn))
cmd.Parameters.Add("@search_str", FbDbType.Text).Value = "search text"; // <-- needs to be >7 chars long
FbDataReader reader = cmd.ExecuteReader();
An exception is thrown by ExecuteReader:
Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: arithmetic exception, numeric overflow, or string truncation
string right truncation ---> FirebirdSql.Data.Common.IscException: arithmetic exception, numeric overflow, or string truncation
string right truncation
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.Write(DbField param) in C:\projects\http://fb.net\source\FirebirdSql\Data\Client\Managed\Version10\XdrStream.cs:line 695
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.Write(Descriptor descriptor) in C:\projects\http://fb.net\source\FirebirdSql\Data\Client\Managed\Version10\XdrStream.cs:line 650
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.SendExecuteToBuffer() in C:\projects\http://fb.net\source\FirebirdSql\Data\Client\Managed\Version10\GdsStatement.cs:line 596
at FirebirdSql.Data.Client.Managed.Version12.GdsStatement.Execute() in C:\projects\http://fb.net\source\FirebirdSql\Data\Client\Managed\Version12\GdsStatement.cs:line 61
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteCommand(CommandBehavior behavior, Boolean returnsSet) in C:\projects\http://fb.net\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 1250
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader(CommandBehavior behavior) in C:\projects\http://fb.net\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 551
The problem seems to be the lib mistaking the field for a VARCHAR type.
A workaround is to explicitly cast the parameter as a BLOB:
FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE CAST(@search_str AS BLOB SUB_TYPE 1)", conn))
The text was updated successfully, but these errors were encountered: