@@ -2008,7 +2008,7 @@ public static string SqlType(TableMapping.Column column) {
2008
2008
return "bigint" ;
2009
2009
}
2010
2010
else if ( clrType == typeof ( DateTimeOffset ) ) {
2011
- return "bigint " ;
2011
+ return "blob " ;
2012
2012
}
2013
2013
else if ( clrType . IsEnum ) {
2014
2014
return column . StoreAsText ? "varchar" : "integer" ;
@@ -2285,7 +2285,7 @@ internal static void BindParameter(Sqlite3Statement stmt, int index, object? val
2285
2285
SQLite3 . BindInt64 ( stmt , index , dateTimeValue . Ticks ) ;
2286
2286
}
2287
2287
else if ( value is DateTimeOffset dateTimeOffsetValue ) {
2288
- SQLite3 . BindInt64 ( stmt , index , dateTimeOffsetValue . UtcTicks ) ;
2288
+ SQLite3 . BindBlob ( stmt , index , DateTimeOffsetToBytes ( dateTimeOffsetValue ) ) ;
2289
2289
}
2290
2290
else if ( value is byte [ ] byteArrayValue ) {
2291
2291
SQLite3 . BindBlob ( stmt , index , byteArrayValue ) ;
@@ -2348,7 +2348,7 @@ private class Binding {
2348
2348
return new DateTime ( SQLite3 . ColumnInt64 ( stmt , index ) ) ;
2349
2349
}
2350
2350
else if ( clrType == typeof ( DateTimeOffset ) ) {
2351
- return new DateTimeOffset ( SQLite3 . ColumnInt64 ( stmt , index ) , TimeSpan . Zero ) ;
2351
+ return BytesToDateTimeOffset ( SQLite3 . ColumnBlob ( stmt , index ) ) ;
2352
2352
}
2353
2353
else if ( clrType . IsEnum ) {
2354
2354
if ( type is SQLite3 . ColType . Text ) {
@@ -2407,6 +2407,18 @@ private class Binding {
2407
2407
}
2408
2408
}
2409
2409
}
2410
+
2411
+ internal static DateTimeOffset BytesToDateTimeOffset ( byte [ ] bytes ) {
2412
+ long dateTicks = BitConverter . ToInt64 ( bytes , 0 ) ;
2413
+ long offsetTicks = BitConverter . ToInt64 ( bytes , sizeof ( long ) ) ;
2414
+ return new DateTimeOffset ( new DateTime ( dateTicks ) , TimeSpan . FromTicks ( offsetTicks ) ) ;
2415
+ }
2416
+ internal static byte [ ] DateTimeOffsetToBytes ( DateTimeOffset dateTimeOffset ) {
2417
+ return [
2418
+ .. BitConverter . GetBytes ( dateTimeOffset . DateTime . Ticks ) ,
2419
+ .. BitConverter . GetBytes ( dateTimeOffset . Offset . Ticks )
2420
+ ] ;
2421
+ }
2410
2422
}
2411
2423
2412
2424
internal class FastColumnSetter {
@@ -2468,7 +2480,7 @@ internal class FastColumnSetter {
2468
2480
}
2469
2481
else if ( clrType == typeof ( DateTimeOffset ) ) {
2470
2482
return CreateNullableTypedSetterDelegate < T , DateTimeOffset > ( column , ( stmt , index ) => {
2471
- return new DateTimeOffset ( SQLite3 . ColumnInt64 ( stmt , index ) , TimeSpan . Zero ) ;
2483
+ return SQLiteCommand . BytesToDateTimeOffset ( SQLite3 . ColumnBlob ( stmt , index ) ) ;
2472
2484
} ) ;
2473
2485
}
2474
2486
else if ( clrType . IsEnum ) {
0 commit comments