X Tutup
Skip to content

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

@alenkacz

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();
            }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup