Skip to content

Commit

Permalink
Adding support for TimeSpan, fixes praeclarum#152
Browse files Browse the repository at this point in the history
Merged-by: Øystein Krog <oystein.krog@gmail.com>
  • Loading branch information
louy authored and oysteinkrog committed Mar 8, 2014
1 parent 108e38b commit d85649f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/SQLite.Net/Orm.cs
Expand Up @@ -80,6 +80,10 @@ public static string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks)
int len = p.MaxStringLength;
return "varchar(" + len + ")";
}
if (clrType == typeof (TimeSpan))
{
return "bigint";
}
if (clrType == typeof (DateTime))
{
return storeDateTimeAsTicks ? "bigint" : "datetime";
Expand Down
8 changes: 8 additions & 0 deletions src/SQLite.Net/SQLiteCommand.cs
Expand Up @@ -267,6 +267,10 @@ private void BindAll(IDbStatement stmt)
{
isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(value));
}
else if (value is TimeSpan)
{
isqLite3Api.BindInt64(stmt, index, ((TimeSpan) value).Ticks);
}
else if (value is DateTime)
{
if (storeDateTimeAsTicks)
Expand Down Expand Up @@ -324,6 +328,10 @@ private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType)
{
return (float) _sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index);
}
if (clrType == typeof (TimeSpan))
{
return new TimeSpan(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index));
}
if (clrType == typeof (DateTime))
{
if (_conn.StoreDateTimeAsTicks)
Expand Down

0 comments on commit d85649f

Please sign in to comment.