Doug Schmidt - 305 - Feb 27, 2014

How do override the DateTime column formatting for the Sqlite provider?

What I want written to the Sqlite column is: dateTime.ToString(DateTimeSerializer.DateTimeFormatTicksUtcOffset);

I know that Sqlite doesn’t support DateTime natively, so OrmLite converts DateTimes to string values. But the default string formatting of DateTimes from OrmLite does not appear to be consistent, even though all my DateTimes are Kind=Utc. Sometimes it formats my DateTimes with a space between the date and time (which is wrong for UTC), and sometimes it formats them with a ‘T’ between the date and time (which is correct).

I’ve tried overriding SqliteOrmLiteDialectProvider.GetQuotedValue(), but that doesn’t seem to do it.

What’s the right way to use my own customer formatter for all DateTime values written to a Sqlite DB?

There isn’t an easier way, you’d have to inherit from SqliteOrmLiteDialectProviderBase and override the GetQuotedValue / GetValueOrDbNull methods to intercept the field conversions. 

Then you would use this custom provider instead in your OrmLiteDbFactory.

But if you have some failing tests we could fix it in master.

Doug Schmidt:

Yeah. I’ve actually had to override three methods:
GetQuotedValue() - for non-parameterized DB writes
SetParameterValue() - for parameterized DB writes
SetDbValue() - for DB reads

Almost working. I still need to figure out nullable DateTime support tho.