You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under certain circumstances, the call to Convert.ToDateTime in this method will throw a FormatException when attempting to retrieve a DateTime value inserted into a text column:
Set the current locale to the invariant culture using: CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
Insert a DateTime value with the date of "2024-02-29 00:00:00" into the column using a parameterized query with a DateTime parameter.
Change the locale to ar-SA using: CultureInfo.CurrentCulture = CultureInfo.GetCulture("ar-SA");
Select the text value from the table without casting the value in the query to date/time type.
Use FbDataReader.GetDateTime() to retrieve the value and observe the exception.
A format exception is generated because the call to Convert.ToDateTime uses the current culture of the calling application and does not correctly parse the value that was stored in the database. This method should either attempt a direct cast to a DateTime and throw an InvalidCastException or perform an implict conversion from the string value to a DateTime value using the inverse conversion as performed by the database upon insert. The latter provides consistent insert and select functionality.
It may be sufficient to use the InvariantCulture in the call to Convert.ToDateTime here, but I personally do not know how Firebase converts DateTime values to text. Additional tests may be required for other locale combinations to ensure correct functionality.
The text was updated successfully, but these errors were encountered:
The usage of CurrentCulture is certainly wrong. On the other hand this method is not expected to work with strings. If you store DateTime in database as a string, you're doing it wrong. Firebird has dedicated datatype(s) for date/time.
Obviously it is not be advisable to store a DateTime in a text column. However there are likely cases where users have done so. When given a DateTime object as a parameter to insert, Firebase silently converts the value to text. The expectation here is that the driver should be able to reverse the conversion from text when asked to do so.
Under certain circumstances, the call to Convert.ToDateTime in this method will throw a FormatException when attempting to retrieve a DateTime value inserted into a text column:
NETProvider/src/FirebirdSql.Data.FirebirdClient/Common/DbValue.cs
Lines 246 to 255 in 73b0082
Steps to reproduce this issue are as follows:
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentCulture = CultureInfo.GetCulture("ar-SA");
A format exception is generated because the call to Convert.ToDateTime uses the current culture of the calling application and does not correctly parse the value that was stored in the database. This method should either attempt a direct cast to a DateTime and throw an InvalidCastException or perform an implict conversion from the string value to a DateTime value using the inverse conversion as performed by the database upon insert. The latter provides consistent insert and select functionality.
It may be sufficient to use the InvariantCulture in the call to Convert.ToDateTime here, but I personally do not know how Firebase converts DateTime values to text. Additional tests may be required for other locale combinations to ensure correct functionality.
The text was updated successfully, but these errors were encountered: