Giter Site home page Giter Site logo

Comments (5)

MaceWindu avatar MaceWindu commented on May 26, 2024 1

Thanks for you fixes! I don't really use Parse() for real projects (don't even use spatial types) - it's just a part of our tests https://github.com/linq2db/linq2db/blob/master/Tests/Linq/DataProvider/SqlServerTests.cs that I'm trying to enable for netstandard2.0 build. With latest version some stuff was fixed and I identified 3 failures:

//Expected: "LINESTRING (100 100, 20 180, 180 180)"
//  But was:  "LINESTRING (100 100, 100 100, 100 100)"
[Test, IncludeDataContextSource(ProviderName.SqlServer2008, ProviderName.SqlServer2012, ProviderName.SqlServer2014, TestProvName.SqlAzure)]
		public void Test1(string context)
		{
			using (var conn = new DataConnection(context))
			{
				var id = SqlGeometry.Parse("LINESTRING (100 100, 20 180, 180 180)");

				using (var cmd = conn.CreateCommand())
				{
					cmd.CommandText = "SELECT @p";
					var p = cmd.CreateParameter();
					cmd.Parameters.Add(p);

					((dynamic)p).UdtTypeName = "geometry";
					p.ParameterName = "@p";
					p.Value = id;

					Assert.That(cmd.ExecuteScalar().ToString(), Is.EqualTo(id.ToString()));
				}
			}
		}

// Message: System.Data.SqlClient.SqlException : The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 ("@p"): The supplied value is not a valid instance of data type geography. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.
		[Test, IncludeDataContextSource(ProviderName.SqlServer2008, ProviderName.SqlServer2012, ProviderName.SqlServer2014, TestProvName.SqlAzure)]
		public void Test2(string context)
		{
			using (var conn = new DataConnection(context))
			{
				var id = SqlGeography.Parse("LINESTRING (-122.36 47.656, -122.343 47.656)");

				using (var cmd = conn.CreateCommand())
				{
					cmd.CommandText = "SELECT @p";
					var p = cmd.CreateParameter();
					cmd.Parameters.Add(p);

					((dynamic)p).UdtTypeName = "geography";
					p.ParameterName = "@p";
					p.Value = id;

					Assert.That(cmd.ExecuteScalar().ToString(), Is.EqualTo(id.ToString()));
				}
			}
		}

//   Expected: "LINESTRING (-122.36 47.656, -122.343 47.656)"
//  But was:  "LINESTRING (47.656 -122.36, 47.656 -122.343)"
		[Test, IncludeDataContextSource(ProviderName.SqlServer2008, ProviderName.SqlServer2012, ProviderName.SqlServer2014, TestProvName.SqlAzure)]
		public void Test3(string context)
		{
			using (var conn = new DataConnection(context))
			{
				var id = SqlGeography.Parse("LINESTRING (-122.36 47.656, -122.343 47.656)");

				using (var cmd = conn.CreateCommand())
				{
					cmd.CommandText = "SELECT Cast(geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) as geography)";

					Assert.That(cmd.ExecuteScalar().ToString(), Is.EqualTo(id.ToString()));
				}
			}
		}

from microsoft.sqlserver.types.

dotMorten avatar dotMorten commented on May 26, 2024

Thanks! I'll look into porting my old WKT Reader over - my main goal was to be able to query Spatial Types in SqlServer.

Having said that, parsing from WKT is extremely expensive and not something I'd recommend doing.
On the other hand, I should look into getting WKB support put in as well, since that performs much Much MUCH better :-)

from microsoft.sqlserver.types.

dotMorten avatar dotMorten commented on May 26, 2024

I did a first pass at a WKT parser and pushed it here. It's somewhat untested (just two unit tests so far), but wanted to get it in for you try out, as it might be a little while before I get a chance to write some more tests.
Any feedback on how it works are much appreciated!

from microsoft.sqlserver.types.

dotMorten avatar dotMorten commented on May 26, 2024

Thank you! These test cases are great. I'll try and look at it tonight (althought I did a few tests parsing those WKTs specifically, and things seemed fine except Lat/Long is swapped in geography, so might be something else)

from microsoft.sqlserver.types.

dotMorten avatar dotMorten commented on May 26, 2024

@MaceWindu Again thank you. Especially one of the tests pointed out a really really bad bug. I have all the tests you shared above passing now. Do you mind trying again, and please let me know if anything else fails? Thanks!

from microsoft.sqlserver.types.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.