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

Bug if use Replace with parameter [DNET840] #775

Closed
firebird-automations opened this issue Aug 9, 2018 · 4 comments
Closed

Bug if use Replace with parameter [DNET840] #775

firebird-automations opened this issue Aug 9, 2018 · 4 comments

Comments

@firebird-automations
Copy link

Submitted by: jack128 (jack128)

script to create db:

CREATE DATABASE 'localhost:C:\Data\TEMP_3ED4BB49-EE30-4D79-8038-EBC5C24C536D.FDB'
USER 'SYSDBA' PASSWORD 'masterkey';

create table TempTable (caption varchar(255));

insert into TempTable values('1');
commit;

test:
static void Main(string[] args)
{
var filename = @"C:\Data\Temp_3ED4BB49-EE30-4D79-8038-EBC5C24C536D.fdb";

        var connectionString = new FbConnectionStringBuilder
        \{
            UserID = "SYSDBA",
            Password = "masterkey",
            Database = filename,
        \}\.ConnectionString;

        using \(var conn = new FbConnection\(connectionString\)\)
        \{
            conn\.Open\(\);
            using \(var command = conn\.CreateCommand\(\)\)
            \{
                const string sql = @"select \* from TempTable t where t\.caption like Replace\(@p, '\~', '\~\~'\)"; // this query does not return row, although should, I check it in IBExpert
                //const string sql = @"select \* from TempTable t where t\.caption like @p"; // this query returns row as expected

                command\.CommandText = sql;
                var p = command\.CreateParameter\(\);
                p\.ParameterName = "p";
                p\.Value = "1";
                command\.Parameters\.Add\(p\);

                using \(var reader = command\.ExecuteReader\(\)\)
                \{
                    if \(\!reader\.Read\(\)\)
                        throw new Exception\("1 row should be returned"\);
                \}
            \}
        \}
    \}
@firebird-automations
Copy link
Author

Modified by: jack128 (jack128)

description: script to create db:

CREATE DATABASE 'localhost:C:\Data\TEMP_3ED4BB49-EE30-4D79-8038-EBC5C24C536D.FDB'
USER 'SYSDBA' PASSWORD 'masterkey';

create table TempTable (caption varchar(255));

insert into TempTable values('1');
commit;

test:
static void Main(string[] args)
{
var filename = @"C:\Data\Temp_3ED4BB49-EE30-4D79-8038-EBC5C24C536D.fdb";

        var connectionString = new FbConnectionStringBuilder
        \{
            UserID = "SYSDBA",
            Password = "masterkey",
            Database = filename,
        \}\.ConnectionString;

        using \(var conn = new FbConnection\(connectionString\)\)
        \{
            conn\.Open\(\);
            using \(var command = conn\.CreateCommand\(\)\)
            \{
                const string sql = @"select \* from TempTable t where t\.caption like Replace\(@p, '\~', '\~\~'\)"; // this query does not return row, although should
                //const string sql = @"select \* from TempTable t where t\.caption like @p"; // this query returns row as expected

                command\.CommandText = sql;
                var p = command\.CreateParameter\(\);
                p\.ParameterName = "p";
                p\.Value = "1";
                command\.Parameters\.Add\(p\);

                using \(var reader = command\.ExecuteReader\(\)\)
                \{
                    if \(\!reader\.Read\(\)\)
                        throw new Exception\("1 row should be returned"\);
                \}
            \}
        \}
    \}

=>

script to create db:

CREATE DATABASE 'localhost:C:\Data\TEMP_3ED4BB49-EE30-4D79-8038-EBC5C24C536D.FDB'
USER 'SYSDBA' PASSWORD 'masterkey';

create table TempTable (caption varchar(255));

insert into TempTable values('1');
commit;

test:
static void Main(string[] args)
{
var filename = @"C:\Data\Temp_3ED4BB49-EE30-4D79-8038-EBC5C24C536D.fdb";

        var connectionString = new FbConnectionStringBuilder
        \{
            UserID = "SYSDBA",
            Password = "masterkey",
            Database = filename,
        \}\.ConnectionString;

        using \(var conn = new FbConnection\(connectionString\)\)
        \{
            conn\.Open\(\);
            using \(var command = conn\.CreateCommand\(\)\)
            \{
                const string sql = @"select \* from TempTable t where t\.caption like Replace\(@p, '\~', '\~\~'\)"; // this query does not return row, although should, I check it in IBExpert
                //const string sql = @"select \* from TempTable t where t\.caption like @p"; // this query returns row as expected

                command\.CommandText = sql;
                var p = command\.CreateParameter\(\);
                p\.ParameterName = "p";
                p\.Value = "1";
                command\.Parameters\.Add\(p\);

                using \(var reader = command\.ExecuteReader\(\)\)
                \{
                    if \(\!reader\.Read\(\)\)
                        throw new Exception\("1 row should be returned"\);
                \}
            \}
        \}
    \}

@firebird-automations
Copy link
Author

Modified by: @cincuranet

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

@firebird-automations
Copy link
Author

Commented by: @cincuranet

The problem is that the replacement "'~~'" is CHAR(2) and hence the comparison with "caption" does not match. If you'd do "Replace(@p, '~', cast('~~' as varchar(255)))", it would work as expected.

@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