Skip to content

Commit 67a47c5

Browse files
committed
core/SQLiteCommand: Fix bug where DateTime was serialized using current culture (not invariant)
This caused errors when deserializing. DataTimeTest now fixed
1 parent 0939b4f commit 67a47c5

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/SQLite.Net/SQLiteCommand.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
using System;
2525
using System.Collections.Generic;
26+
using System.Globalization;
2627
using System.Linq;
2728
using System.Reflection;
2829
using JetBrains.Annotations;
@@ -348,7 +349,7 @@ internal static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, in
348349
}
349350
else
350351
{
351-
string val = ((DateTime) value).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
352+
string val = ((DateTime) value).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture);
352353
isqLite3Api.BindText16(stmt, index, val, -1, NegativePointer);
353354
}
354355
}
@@ -365,7 +366,7 @@ internal static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, in
365366
}
366367
else
367368
{
368-
string val = ((ISerializable<DateTime>) value).Serialize().ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
369+
string val = ((ISerializable<DateTime>) value).Serialize().ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture);
369370
isqLite3Api.BindText16(stmt, index, val, -1, NegativePointer);
370371
}
371372
}
@@ -471,7 +472,7 @@ private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType)
471472
{
472473
return new DateTime(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index), DateTimeKind.Utc);
473474
}
474-
return DateTime.Parse(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index));
475+
return DateTime.Parse(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index), CultureInfo.InvariantCulture);
475476
}
476477
if (clrType == typeof (DateTimeOffset))
477478
{
@@ -486,7 +487,7 @@ private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType)
486487
}
487488
else
488489
{
489-
value = DateTime.Parse(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index));
490+
value = DateTime.Parse(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index), CultureInfo.InvariantCulture);
490491
}
491492
return Activator.CreateInstance(clrType, value);
492493
}

0 commit comments

Comments
 (0)