GUID Type coversion error ------------------------- Key: DNET-376 URL: http://tracker.firebirdsql.org/browse/DNET-376 Project: .NET Data provider Issue Type: Bug Components: ADO.NET Provider Affects Versions: 2.6 Environment: Firebird 2.5 Reporter: ssdi Assignee: Jiri Cincura
My first post - http://216.121.112.228/browse/NH-2618 . Firebird 2.5 store Uuid into left to right convetion as "CHAR(16) CHARACTER SET OCTETS" (see http://www.firebirdfaq.org/faq98/ ). But ADO.NET Provider constructs System.Guid with System.Guid(byte[]) constructor, but System.GuidType shoul be constructed with Guid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k) for correct representation. Also see Firebird 2.5 builtin fuctions UUID_TO_CHAR() and CHAR_TO_UUID(). System.Guid reflection: {{{ // Creates a new guid from an array of bytes. // public Guid(byte[] b) { if (b==null) throw new ArgumentNullException("b"); if (b.Length != 16) throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_GuidArrayCtor"), "16")); _a = ((int)b[3] << 24) | ((int)b[2] << 16) | ((int)b[1] << 8) | b[0]; _b = (short)(((int)b[5] << 8) | b[4]); _c = (short)(((int)b[7] << 8) | b[6]); _d = b[8]; _e = b[9]; _f = b[10]; _g = b[11]; _h = b[12]; _i = b[13]; _j = b[14]; _k = b[15]; } // Creates a new GUID initialized to the value represented by the // arguments. The bytes are specified like this to avoid endianness issues. // public Guid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k) { _a = a; _b = b; _c = c; _d = d; _e = e; _f = f; _g = g; _h = h; _i = i; _j = j; _k = k; } }}} NUnit test: {{{ [Test] public void GuidMappingTest() { FbCommand createTable = new FbCommand("CREATE TABLE GUID_TEST (INT_FIELD INTEGER, GUID_FIELD CHAR(16) CHARACTER SET OCTETS)", Connection); createTable.ExecuteNonQuery(); createTable.Dispose(); var patternGuid = Guid.NewGuid(); // Insert the Guid FbCommand insert = new FbCommand("INSERT INTO GUID_TEST (INT_FIELD, GUID_FIELD) VALUES (@IntField, @GuidValue)", Connection); insert.Parameters.Add("@IntField", FbDbType.Integer).Value = this.GetId(); insert.Parameters.Add("@GuidValue", FbDbType.Guid).Value = patternGuid; insert.ExecuteNonQuery(); insert.Dispose(); // Select the value FbCommand select = new FbCommand("SELECT INT_FIELD, GUID_FIELD, UUID_TO_CHAR(GUID_FIELD) AS FBGUID FROM GUID_TEST", Connection); using (FbDataReader r = select.ExecuteReader()) { if (r.Read()) { var providerGuid = r.GetGuid(1); Console.WriteLine("patternGuid = {0}", patternGuid); Console.WriteLine("providerGuid = {0}", providerGuid); Assert.AreEqual(patternGuid, providerGuid); var fbGuidStr = r.GetString(2); var fbGuid = new Guid(fbGuidStr); Console.WriteLine("rfc4122Guid = {0}", fbGuid); Assert.AreEqual(patternGuid, fbGuid); } } } }}} Execution Result: {{{ GuidMappingTest: Failed Command: CREATE TABLE GUID_TEST (INT_FIELD INTEGER, GUID_FIELD CHAR(16) CHARACTER SET OCTETS) Command: INSERT INTO GUID_TEST (INT_FIELD, GUID_FIELD) VALUES (@IntField, @GuidValue) Name:@IntField Type:Integer Value:-169522060 Name:@GuidValue Type:Guid Value:f470fb5b-fbbd-412e-83f9-eb14aa132ad9 Command: SELECT INT_FIELD, GUID_FIELD, UUID_TO_CHAR(GUID_FIELD) AS FBGUID FROM GUID_TEST patternGuid = f470fb5b-fbbd-412e-83f9-eb14aa132ad9 providerGuid = f470fb5b-fbbd-412e-83f9-eb14aa132ad9 rfc4122Guid = 5bfb70f4-bdfb-2e41-83f9-eb14aa132ad9 Expected: f470fb5b-fbbd-412e-83f9-eb14aa132ad9 But was: 5bfb70f4-bdfb-2e41-83f9-eb14aa132ad9 }}} Best regards, Eugenyi Vinogradnyi (aka ssdi). -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://tracker.firebirdsql.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira ------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf _______________________________________________ Firebird-net-provider mailing list Firebird-net-provider@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/firebird-net-provider