Skip to content
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

Closed
firebird-automations opened this issue Mar 7, 2012 · 14 comments
Closed

FbCommand mishandling BLOB field parameters [DNET420] #418

firebird-automations opened this issue Mar 7, 2012 · 14 comments

Comments

@firebird-automations
Copy link

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))

@firebird-automations
Copy link
Author

Modified by: Scott Morgan (blumf)

description: Assume a table of form:
CREATE TABLE PHRASES ( TEXT BLOB SUB_TYPE 1 );

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))
cmd.Parameters.Add("@search_str", FbDbType.Text).Value = "dont exist"; // <-- 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 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:
CREATE TABLE PHRASES ( TEXT BLOB SUB_TYPE 1 );

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))
cmd.Parameters.Add("@search_str", FbDbType.Text).Value = "dont exist"; // <-- 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 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))

@firebird-automations
Copy link
Author

Commented by: Scott Morgan (blumf)

Confirmed that it also throws exception when resultset has data

@firebird-automations
Copy link
Author

Modified by: Scott Morgan (blumf)

description: Assume a table of form:
CREATE TABLE PHRASES ( TEXT BLOB SUB_TYPE 1 );

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))
cmd.Parameters.Add("@search_str", FbDbType.Text).Value = "dont exist"; // <-- 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 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:
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))

summary: FbCommand mishandling BLOB field parameters on empty resultsets => FbCommand mishandling BLOB field parameters

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue relate to DNET124 [ DNET124 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue relate to DNET124 [ DNET124 ] =>

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is related to DNET124 [ DNET124 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-automations
Copy link
Author

Commented by: @cincuranet

I'm unable to reproduce this issue with version 2.7.7. Can you recheck?

@firebird-automations
Copy link
Author

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.
"123456%" = works
"1234567%" = fails

Exception dump from 2.7.7:

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:\Dev\NETProvider\source\FirebirdSql\Data\Client\Managed\Version10\XdrStream.cs:line 700
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.Write(Descriptor descriptor) in C:\Dev\NETProvider\source\FirebirdSql\Data\Client\Managed\Version10\XdrStream.cs:line 655
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.SendExecuteToBuffer() in C:\Dev\NETProvider\source\FirebirdSql\Data\Client\Managed\Version10\GdsStatement.cs:line 595
at FirebirdSql.Data.Client.Managed.Version12.GdsStatement.Execute() in C:\Dev\NETProvider\source\FirebirdSql\Data\Client\Managed\Version12\GdsStatement.cs:line 61
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteCommand(CommandBehavior behavior, Boolean returnsSet) in C:\Dev\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 1240
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader(CommandBehavior behavior) in C:\Dev\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 548
--- End of inner exception stack trace ---
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader(CommandBehavior behavior) in C:\Dev\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 554
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader() in C:\Dev\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 538
at fb.net_test001.Program.Main(String[] args) in C:\projects\VC10\tests\fb.net_test001\fb.net_test001\Program.cs:line 30

@firebird-automations
Copy link
Author

Commented by: @cincuranet

This code works in 2.7.7 fine:
using (var conn = new FbConnection("database=localhost:test.fdb;user=sysdba;password=masterkey;character set=utf8"))
{
FbConnection.CreateDatabase(conn.ConnectionString, true);
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "RECREATE TABLE PHRASES ( TEXT BLOB SUB_TYPE 1 );";
cmd.ExecuteNonQuery();
}
using (FbCommand cmd = new FbCommand("SELECT TEXT FROM PHRASES WHERE LOWER(TEXT) LIKE @search_str", conn))
{
cmd.Parameters.Add("@search_str", FbDbType.Text).Value = "123456789123456789"; // <-- needs to be >7 chars long
FbDataReader reader = cmd.ExecuteReader();
}
}

Provide a reproducible test case.

@firebird-automations
Copy link
Author

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

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Might be. So now it behaves OK?

@firebird-automations
Copy link
Author

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.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: In Progress [ 3 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants