diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2015-05-07 12:54:49 +0300 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2015-05-07 12:54:49 +0300 |
commit | 371944bed96981702f5e7a32b30b9fc214db4fbf (patch) | |
tree | b793498f640bb461b411957fd3fd523b7dca155f /mcs/class/Mono.Data.Tds | |
parent | b661dde23abc4840e26e28ff8db76401eea9a066 (diff) | |
parent | 3a81bfc27525bcec2fa04340fcd1567347c04ca9 (diff) |
Merge pull request #1772 from ztzg/sql-server-variant
Fix SQL Server 2012 variant parameters and return values
Diffstat (limited to 'mcs/class/Mono.Data.Tds')
-rw-r--r-- | mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs | 41 | ||||
-rw-r--r-- | mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs | 2 |
2 files changed, 42 insertions, 1 deletions
diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs index 580c8dd85fa..5cb0ae8a4ce 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs @@ -932,6 +932,11 @@ namespace Mono.Data.Tds.Protocol element = new Guid (guidBytes); } break; + case TdsColumnType.Variant : + if (outParam) + comm.Skip (4); + element = GetVariantValue(); + break; default : return DBNull.Value; } @@ -956,6 +961,40 @@ namespace Mono.Data.Tds.Protocol return result; } + private object GetVariantValue () + { + uint len = (uint)comm.GetTdsInt (); + if (len == 0) + return DBNull.Value; + + // VARIANT_BASETYPE + TdsColumnType colType = (TdsColumnType)comm.GetByte (); + // VARIANT_PROPBYTES + byte propbytes = comm.GetByte (); + if (propbytes != 0) + // VARIANT_PROPERTIES + comm.Skip (propbytes); + + len -= (uint)propbytes + 2; + + switch (colType) + { + case TdsColumnType.Int1 : + case TdsColumnType.Int2 : + case TdsColumnType.Int4 : + case TdsColumnType.BigInt : + return GetIntValue (colType); + default: + // The old code was ignoring variants + // and returning null. Should we + // throw an exception? + comm.Skip (len); + break; + } + + return DBNull.Value; + } + private object GetDateTimeValue ( TdsColumnType? type ) @@ -1291,7 +1330,7 @@ namespace Mono.Data.Tds.Protocol internal bool IsBlobType (TdsColumnType columnType) { - return (columnType == TdsColumnType.Text || columnType == TdsColumnType.Image || columnType == TdsColumnType.NText); + return (columnType == TdsColumnType.Text || columnType == TdsColumnType.Image || columnType == TdsColumnType.NText || columnType == TdsColumnType.Variant); } internal bool IsLargeType (TdsColumnType columnType) diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs b/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs index d8a4b34fb13..b569f643072 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs @@ -480,6 +480,8 @@ namespace Mono.Data.Tds { return TdsColumnType.BigVarBinary; case "varchar": return TdsColumnType.BigVarChar; + case "sql_variant": + return TdsColumnType.Variant; default: throw new NotSupportedException ("Unknown Type : " + TypeName); } |