Giter Site home page Giter Site logo

Comments (9)

ppasieka avatar ppasieka commented on May 23, 2024

@dotMorten do you have any materials where I could learn more about the bit patterns used in implementing HierarchyId?

Or maybe you have some ideas how to fix this issue?

from microsoft.sqlserver.types.

dotMorten avatar dotMorten commented on May 23, 2024

do you have any materials where I could learn more about the bit patterns used in implementing HierarchyId?

Nope. I didn't even provide this implementation (community contribution), and honestly don't even know what it is used for. Part of me wish I didn't accept the PR, because I have a really hard time maintaining that part of the source code, and really rely on the community to do this.

from microsoft.sqlserver.types.

ppasieka avatar ppasieka commented on May 23, 2024

@olmobrutall Would you be able to help with this issue? Or provide some materials where I could learn more about these bits patterns?
Definitely, serialization part is broken. When I try to look at data in SQL management studio I'm getting an exception
after using .ToString on HierarchyId

A .NET Framework error occurred during execution of user-defined routine or aggregate "hierarchyid": 
Microsoft.SqlServer.Types.HierarchyIdException: 24000: SqlHierarchyId operation failed because HierarchyId object was constructed from an invalid binary string. 
Microsoft.SqlServer.Types.HierarchyIdException: 
   at Microsoft.SqlServer.Types.ex_raise(Int32 major, Int32 minor, Int32 sev, Int32 state, Object param1, Object param2, Object param3)
   at Microsoft.SqlServer.Types.OrdPath.GetBits(UInt16 startBit, UInt16 nBits, UInt64& bits)
   at Microsoft.SqlServer.Types.OrdPath.ExtractOrd(UInt16& bitOffset, UInt32 stage, Int64& ord)
   at Microsoft.SqlServer.Types.OrdPath.ExtractComponent(UInt16& bitOffset, SComponent& component, levelType& type)
   at Microsoft.SqlServer.Types.OrdPath.ToString()

from microsoft.sqlserver.types.

olmobrutall avatar olmobrutall commented on May 23, 2024

Hi @ppasieka,

the bit patterns come from http://www.adammil.net/blog/v100_how_the_SQL_Server_hierarchyid_data_type_works_kind_of_.html

Not sure if I’ll find time to work on it, but I can review a potential change if you go for it.

Cheers

from microsoft.sqlserver.types.

olmobrutall avatar olmobrutall commented on May 23, 2024

It's definitely an issue with serialization, I've converted the code to a Unit Test and also compare with values comming from the database:

        [DataTestMethod]
        [DataRow("/1.0.2/")]
        [DataRow("/1.1.2/")]
        [DataRow("/1.2.2/")]
        [DataRow("/1.3.2/")]
        [DataRow("/3.0/")]
        public void SerializeDeserialize(string route)
        {
            var parsed = SqlHierarchyId.Parse(route);
            //var ms = new MemoryStream();
            //parsed.Write(new BinaryWriter(ms));
            //ms.Position = 0;
            //var roundTrip = new Microsoft.SqlServer.Types.SqlHierarchyId();
            //roundTrip.Read(new BinaryReader(ms));
            //Assert.AreEqual(parsed, roundTrip);

            using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=HierarchyTest;Integrated Security=true"))
            {
                con.Open();
                var id = new SqlCommand($"INSERT INTO [dbo].[TreeNode] (Route) output INSERTED.ID VALUES ('{route}') ", con).ExecuteScalar();

                using (var reader = new SqlCommand($"SELECT Route FROM [dbo].[TreeNode] WHERE ID = " + id, con).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var roundTrip = new Microsoft.SqlServer.Types.SqlHierarchyId();
                        roundTrip.Read(new BinaryReader(reader.GetStream(0)));
                        Assert.AreEqual(parsed, roundTrip);
                    }
                }
            }

The deserializer works, the serializer produces the error. Maybe tomorrow I can take a deeper look.

from microsoft.sqlserver.types.

ppasieka avatar ppasieka commented on May 23, 2024

@olmobrutall Thanks. I will also look into it tomorrow :) And yes I came to the same conclusion that the issue is with a serializer. Deserialization part work for me without any problems so far

from microsoft.sqlserver.types.

olmobrutall avatar olmobrutall commented on May 23, 2024

Fixed in #55

from microsoft.sqlserver.types.

ppasieka avatar ppasieka commented on May 23, 2024

@olmobrutall amazing 👍 I will check it against my project. Thanks for that fast response 😊

from microsoft.sqlserver.types.

ppasieka avatar ppasieka commented on May 23, 2024

@dotMorten Fix provided in #55 works nicely. What do you think about creating a release? With PRs #55 and #47 out, the list of HierarychId problems would be reduced to only one (#36)

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.