Skip to content

NpgSqlCommand does not substitute parameters when there is a string with escaped apostrophe #240

Closed

Description

@alenkacz

When NpgSqlCommand is created with a string that contains escaped apostrophe, the parameters in the query after this string are not substitued even though the valid values are provided. Such parameters placed before the string with apostrophe are substitued correctly.

Following example creates a SQL "INSERT INTO TestTable (StringColumn, ByteaColumn) VALUES ('b''la', @someValue)" - the SomeValue is not substitued for the provided parameter value. If the @someValue would be placed before the 'b''la' string, everything would work.

using (var cmd = DbConnection.CreateCommand())
            {
                cmd.CommandText = "INSERT INTO TestTable (StringColumn, ByteaColumn) VALUES ('b''la', @SomeValue)";
                cmd.Parameters.AddWithValue("SomeValue", new byte[] { 1, });
                cmd.ExecuteNonQuery();
            }

Activity

  1. augi commented on May 12, 2014

    @augi

    I think it could be problem in NpgsqlCommand.AppendCommandReplacingParameterValues method.

  2. glenebob commented on Aug 2, 2014

    @glenebob
    Contributor

    Check out PR #307 ;)

  3. added this to the milestone on Aug 3, 2014
  4. self-assigned this
    on Aug 3, 2014
  5. added a commit that references this issue on Aug 4, 2014
  6. glenebob commented on Aug 4, 2014

    @glenebob
    Contributor

    PR #307 merged. Please have a look.

  7. franciscojunior commented on Aug 17, 2014

    @franciscojunior
    Member

    This is fixed in Npgsql 2.2.0-rc1. Please, give it a try and let us know if you find any other problem.

  8. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions