Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get and set expected value for DdType.Date and DbType.Time #269

Merged
merged 5 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ internal static MetaType GetMetaTypeFromDbType(DbType target)
case DbType.Currency:
return s_metaMoney;
case DbType.Date:
return s_metaDate;
case DbType.DateTime:
return s_metaDateTime;
case DbType.Decimal:
Expand All @@ -301,7 +302,7 @@ internal static MetaType GetMetaTypeFromDbType(DbType target)
case DbType.StringFixedLength:
return s_metaNChar;
case DbType.Time:
return s_metaDateTime;
return MetaTime;
case DbType.Xml:
return MetaXml;
case DbType.DateTime2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,7 @@ public override DbType DbType
set
{
MetaType metatype = _metaType;
if ((null == metatype) || (metatype.DbType != value) ||
// Two special datetime cases for backward compat
// DbType.Date and DbType.Time should always be treated as setting DbType.DateTime instead
value == DbType.Date ||
value == DbType.Time)
if ((null == metatype) || (metatype.DbType != value))
{
PropertyTypeChanging();
_metaType = MetaType.GetMetaTypeFromDbType(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ internal static MetaType GetMetaTypeFromDbType(DbType target)
case DbType.Currency:
return MetaMoney;
case DbType.Date:
return MetaDate;
case DbType.DateTime:
return MetaDateTime;
case DbType.Decimal:
Expand All @@ -302,7 +303,7 @@ internal static MetaType GetMetaTypeFromDbType(DbType target)
case DbType.StringFixedLength:
return MetaNChar;
case DbType.Time:
return MetaDateTime;
return MetaTime;
case DbType.Xml:
return MetaXml;
case DbType.DateTime2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,7 @@ override public DbType DbType
set
{
MetaType metatype = _metaType;
if ((null == metatype) || (metatype.DbType != value) ||
// SQLBU 504029: Two special datetime cases for backward compat
// DbType.Date and DbType.Time should always be treated as setting DbType.DateTime instead
value == DbType.Date ||
value == DbType.Time)
if ((null == metatype) || (metatype.DbType != value))
{
PropertyTypeChanging();
_metaType = MetaType.GetMetaTypeFromDbType(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,17 @@ public void InferType_TimeSpan()
Assert.Equal(DbType.Time, param.DbType);
}

[Fact]
public void InferType_DateTimeOffset()
{
DateTimeOffset value = new DateTimeOffset(new DateTime(2019, 10, 15), new TimeSpan(1, 0, 0));

SqlParameter param = new SqlParameter();
param.Value = value;
Assert.Equal(SqlDbType.DateTimeOffset, param.SqlDbType);
Assert.Equal(DbType.DateTimeOffset, param.DbType);
}

[Fact]
public void LocaleId()
{
Expand Down Expand Up @@ -834,6 +845,48 @@ public void ResetDbType()
Assert.Null(p.Value);
}

[Theory]
[InlineData(DbType.AnsiString, SqlDbType.VarChar)]
[InlineData(DbType.AnsiStringFixedLength, SqlDbType.Char)]
[InlineData(DbType.Binary, SqlDbType.VarBinary)]
[InlineData(DbType.Boolean, SqlDbType.Bit)]
[InlineData(DbType.Byte, SqlDbType.TinyInt)]
[InlineData(DbType.Currency, SqlDbType.Money)]
[InlineData(DbType.Date, SqlDbType.Date)]
[InlineData(DbType.DateTime, SqlDbType.DateTime)]
[InlineData(DbType.DateTime2, SqlDbType.DateTime2)]
[InlineData(DbType.DateTimeOffset, SqlDbType.DateTimeOffset)]
[InlineData(DbType.Decimal, SqlDbType.Decimal)]
[InlineData(DbType.Double, SqlDbType.Float)]
[InlineData(DbType.Guid, SqlDbType.UniqueIdentifier)]
[InlineData(DbType.Int16, SqlDbType.SmallInt)]
[InlineData(DbType.Int32, SqlDbType.Int)]
[InlineData(DbType.Int64, SqlDbType.BigInt)]
[InlineData(DbType.Object, SqlDbType.Variant)]
[InlineData(DbType.Single, SqlDbType.Real)]
[InlineData(DbType.String, SqlDbType.NVarChar)]
[InlineData(DbType.Time, SqlDbType.Time)]
[InlineData(DbType.Xml, SqlDbType.Xml)]
public void Parameter_Supported(DbType dbType, SqlDbType sqlDbType)
{
var parameter = new SqlParameter();
parameter.DbType = dbType;
Assert.Equal(dbType, parameter.DbType);
Assert.Equal(sqlDbType, parameter.SqlDbType);
}

[Theory]
[InlineData(DbType.SByte)]
[InlineData(DbType.UInt16)]
[InlineData(DbType.UInt32)]
[InlineData(DbType.UInt64)]
[InlineData(DbType.VarNumeric)]
public void Parameter_NotSupported(DbType dbType)
{
var parameter = new SqlParameter();
Assert.Throws<ArgumentException>(() => parameter.DbType = dbType);
}

[Fact]
public void ResetSqlDbType()
{
Expand Down
Loading