Repository navigation
Closed
Milestone
Description
This bug is solved by the resolution of issue #437 in v3.0, but I did not see this bug reported before.
It is still present in (at least) v2.2.x, and causes a crash.
When a point coordinate is lower than 0.001ish (I don't know the exact point), there is an automatic switch to the scientific notation by Postgres. The insertion goes well, but the read from the db fails with a FormatException in ExtendedBackendToNativeTypeConverter.
Test to reproduce it (in CommandTests):
[Test]
public void TestPointScientificSupport()
{
ExecuteNonQuery("INSERT INTO data (field_point) VALUES ( '(4, 0.00003)' )");
var command = new NpgsqlCommand("select field_point from data", Conn);
var p = (NpgsqlPoint)command.ExecuteScalar();
Assert.AreEqual(4, p.X);
Assert.AreEqual(0.00003, p.Y);
}
StackTrace:
System.InvalidCastException : Le format de la chaîne d'entrée est incorrect.
----> System.FormatException : Le format de la chaîne d'entrée est incorrect.
à Npgsql.ForwardsOnlyDataReader.GetProviderSpecificValue(Int32 ordinal) dans NpgsqlDataReader.cs: line 1443
à Npgsql.ForwardsOnlyDataReader.GetValue(Int32 Index) dans NpgsqlDataReader.cs: line 1416
à Npgsql.NpgsqlCommand.ExecuteScalar() dans NpgsqlCommand.PrepareExecute.cs: line 420
à NpgsqlTests.CommandTests.TestPointScientificSupport() dans CommandTests.cs: line 1718
--FormatException
à System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt)
à System.Single.Parse(String s, NumberStyles style, IFormatProvider provider)
à NpgsqlTypes.ExtendedBackendToNativeTypeConverter.ToPoint(NpgsqlBackendTypeInfo TypeInfo, Byte[] bBackendData, Int16 TypeSize, Int32 TypeModifier) dans NpgsqlTypeConvBackendToNative.cs: line 341
à NpgsqlTypes.NpgsqlBackendTypeInfo.ConvertBackendTextToNative(Byte[] BackendData, Int16 TypeSize, Int32 TypeModifier) dans NpgsqlTypeInfoBackend.cs: line 210
à NpgsqlTypes.NpgsqlTypesHelper.ConvertBackendStringToSystemType(NpgsqlBackendTypeInfo TypeInfo, Byte[] data, Int16 typeSize, Int32 typeModifier) dans NpgsqlTypesHelper.cs: line 248
à Npgsql.StringRowReader.ReadNext() dans NpgsqlAsciiRow.cs: line 84
Again, this is solved by #437, so is a bugfix in 2.2.x doable?
Activity
roji commentedon Mar 2, 2015
This seems to be a matter of fixing the regular expressions in NpgsqlTypeConvBackendToNative, I'll do this for 2.2.5.
roji commentedon Mar 2, 2015
I've pushed a fix for this in 2.2, it's now building on the build server and will be released with 2.2.5.
However, please note that in 2.2 NpgsqlPoint is mistakenly parsed as a pair of Single values (it should be double, fixed in 3.0). Also, your assertion for complete equality to 0.00003 is too strict - floating point values should be compared with a tolerance value.
Correctly parse scientific notation for geometric types
Tradioyes commentedon Mar 2, 2015
Sorry for the Equality comparison, I just did a quick test to show the stacktrace by editing the existing TestPoint.
I'll edit my version to support doubles until 3.0 comes out, thanks for the patch!