Skip to content

Commit

Permalink
Merge pull request #212 from franciscojunior/177-fix-xml-datatype-quo…
Browse files Browse the repository at this point in the history
…ting

Fix #177. Add proper quoting to xml datatype.
  • Loading branch information
franciscojunior committed Jun 9, 2014
2 parents 58b8743 + ffda7a6 commit 5747fb2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Npgsql/NpgsqlTypes/NpgsqlTypesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ private static NpgsqlNativeTypeMapping PrepareDefaultTypesMap()
nativeTypeMapping.AddType("uuid", NpgsqlDbType.Uuid, DbType.Guid, true);
nativeTypeMapping.AddTypeAlias("uuid", typeof (Guid));

nativeTypeMapping.AddType("xml", NpgsqlDbType.Xml, DbType.Xml, true);
nativeTypeMapping.AddType("xml", NpgsqlDbType.Xml, DbType.Xml, false,
BasicNativeToBackendTypeConverter.StringToTextText,
BasicNativeToBackendTypeConverter.StringToTextBinary);

nativeTypeMapping.AddType("interval", NpgsqlDbType.Interval, DbType.Object, true,
ExtendedNativeToBackendTypeConverter.ToInterval);
Expand Down
32 changes: 32 additions & 0 deletions tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,38 @@ public void TestCircleSupport()
Assert.AreEqual(5, circle.Radius);
}

[Test]
public void TestXmlParameter()
{
TestXmlParameter_Internal(false);
}

[Test]
public void TestXmlParameterPrepared()
{
TestXmlParameter_Internal(true);
}


private void TestXmlParameter_Internal(bool prepare)
{
using (var command = new NpgsqlCommand("select @PrecisionXML", Conn))
{
var sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <strings type=\"array\"> <string> this is a test with ' single quote </string></strings>";
var parameter = command.CreateParameter();
parameter.DbType = DbType.Xml; // To make it work we need to use DbType.String; and then CAST it in the sSQL: cast(@PrecisionXML as xml)
parameter.ParameterName = "@PrecisionXML";
parameter.Value = sXML;
command.Parameters.Add(parameter);

if (prepare)
command.Prepare();
command.ExecuteScalar();
}

}


[Test]
public void SetParameterValueNull()
{
Expand Down

0 comments on commit 5747fb2

Please sign in to comment.