-
Notifications
You must be signed in to change notification settings - Fork 934
Fix Guid.ToString() #1856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Guid.ToString() #1856
Conversation
Current failure on firebird is due provider not storing GUID correctly: http://tracker.firebirdsql.org/browse/DNET-509 (fixed in 6.0+) |
I think this has gone too far. @fredericDelaporte any thoughts on this topic? Shall we support such a case or shall we throw |
SybaseASA9Dialect most likely need to have an implementation similar to MySQL or Oracle. |
@hazzik Is there any Sybase I can use to test my query? |
I don't know. @fredericDelaporte might have one, but I'm not sure. |
You can download and test SAP SQL Anywhere 17 (formerly Sybase SQL Anywhere, formerly Sybase ASA, formerly SQL Anywhere (yes they have abandoned then retaken that name), formerly Watcom SQL, Watcom having been bought by Sybase) for free from here, no time limitation, no registration key required. (SAP has bought Sybase and is phasing out the Sybase name.) In fact there are two Sybase database systems. I consider that For the ASE ones, it is quite less convenient to test since free trials of ASE are time limited.
I have seen the test case, and I wonder, what is the use case for converting a GUID to a string representation on the db side rather than on the application side? Throwing It seems currently fixed for all tested databases. But for some of them, the fix looks brittle to me, and likely to be sensitive to system endianness. It would not be an issue for databases locked on one operating system family, but that is not the case of Oracle or MySQL by example. So for these databases, maybe better throw a not supported exception. (Is-it possible to "unregister" a function?) |
@@ -22,6 +23,8 @@ public MySQL5Dialect() | |||
RegisterCastType(DbType.Double, "DECIMAL(19,5)"); | |||
RegisterCastType(DbType.Single, "DECIMAL(19,5)"); | |||
RegisterCastType(DbType.Guid, "BINARY(16)"); | |||
|
|||
RegisterFunction("strguid", new SQLFunctionTemplate(NHibernateUtil.String, "concat(hex(reverse(substr(?1, 1, 4))), '-', hex(reverse(substring(?1, 5, 2))), '-', hex(reverse(substr(?1, 7, 2))), '-', hex(substr(?1, 9, 2)), '-', hex(substr(?1, 11)))")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So works both under Linux and Windows. But endianness is processor dependent. I guess both run under x86/amd64 systems. Anyone able of testing this with a PowerPC maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not have problems with endianness because on these 2 systems Guids are stored as .ToByteArray()
and retrieved by new Guid(byte[])
on a client side. As far as I know modern .NET Fx and .NET Core do not run on big-endian platforms. (Mono does, but we have much bigger problems there)
What we, potentially, can do is to add a runtime check into a function generator.
We also need to have a test which checks a server generated Guids.
@fredericDelaporte and @hazzik The firebase test is faild because database credential is not define.
|
This happens some times (rarely) |
The Travis and AppVeyor builds works on clean, fresh virtual machine images not having a lot of pre-installed software on it. Databases like Firebird have to be installed as part of the build process. Sometimes these installation steps fail. We just relaunch the build in such case. When not a team member, you cannot do this yourself, unless relaunching all the builds with some new commits. (On the other hand, the Teamcity build works on one supplied virtual machine with all the software we need permanently installed on it. So it has no installation steps troubles. But sometimes a build do not leave it in a clean state and causes subsequent builds to fail, like I did recently when testing a SAP SQL Anywhere build on it.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(double post)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in written in an unanswered comment, I wonder, what is the use case for converting a GUID to a string representation on the db side rather than on the application side?
In principle, why not doing that, provided that is not a complex thing to support. But apparently it is complex to support.
So unless I am missing something, why not just advise to not convert Guid to string in projections, but instead get them as Guid and convert them by code? It looks far more reliable.
(And for where clause, supply them as Guid rather than string.)
Sorry for the double post. GitHub encounters difficulties today. One hour after my first post, it was still not showing up on the page, so I have redone it. |
I don't know very well NHibernate Code, but I'm studying it. Is possible to NHibernate convert GUID on application side?
Where we can put this advise? |
The NHibernate Here is its read logic: nhibernate-core/src/NHibernate/Type/GuidType.cs Lines 21 to 34 in ba4147c
If some databases prove to yield some other type requiring a special handling, it could be added here. And its write logic: nhibernate-core/src/NHibernate/Type/GuidType.cs Lines 47 to 52 in ba4147c
The write logic relies on the driver to set the appropriate DbType on the parameter before hand, see here for example. If the current handling is not enough for some databases, maybe requiring another DbType , their driver would have to be adapted to set that other DbType , then the GuidType.Set could be adjusted to handle that other DbType case.
|
Should I use connection string of mysql with Old |
This thing is a MySql data provider setting. According to there:
It is also mentioned in the connector documentation:
So, deciding whether you need this setting or not depends on which type you use for storing your GUIDs. In version 8, MySQL has gained functions for converting between the two representations: |
Dues to a formatting issue in the comment, I only see this question now.
Well, it looks to me as such a specific need that I would tend to emit it only on issues or PR asking for supporting this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the fix still looks a bit "overkill" for my perceived usefulness of the fixed feature, at least now it is robustly tested. So why not merging this, if another contributor with validation rights approves it.
Fixes #1151