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-issue-importer opened this issue Aug 9, 2018 · 4 comments
Closed

Bug if use Replace with parameter [DNET840] #775

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

Comments

@firebird-issue-importer
Copy link

@firebird-issue-importer firebird-issue-importer commented Aug 9, 2018

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-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Aug 9, 2018

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-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Sep 14, 2018

Modified by: @cincuranet

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

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Oct 8, 2018

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-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Oct 8, 2018

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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants