Imported Upstream version 4.2.0.179

Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent 183bba2c9a
commit 6992685b86
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -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)

View File

@@ -559,8 +559,10 @@ namespace Mono.Data.Tds.Protocol
* If the value is null, not setting the size to 0 will cause varchar
* fields to get inserted as an empty string rather than an null.
*/
if (param.Value == null || param.Value == DBNull.Value)
size = 0;
if (colType != TdsColumnType.IntN && colType != TdsColumnType.DateTimeN) {
if (param.Value == null || param.Value == DBNull.Value)
size = 0;
}
// Change colType according to the following table
/*
@@ -584,6 +586,13 @@ namespace Mono.Data.Tds.Protocol
} else if (colType == TdsColumnType.BigVarBinary) {
if (size > 8000)
colType = TdsColumnType.Image;
} else if (colType == TdsColumnType.DateTime2 ||
colType == TdsColumnType.DateTimeOffset) {
// HACK: Wire-level DateTime{2,Offset}
// require TDS 7.3, which this driver
// does not implement correctly--so we
// serialize to ASCII instead.
colType = TdsColumnType.Char;
}
// Calculation of TypeInfo field
/*
@@ -713,6 +722,8 @@ namespace Mono.Data.Tds.Protocol
case "nchar" :
case "text" :
case "ntext" :
case "datetime2":
case "datetimeoffset":
byte [] tmp = param.GetBytes ();
Comm.Append (tmp);
break;

View File

@@ -35,6 +35,8 @@ namespace Mono.Data.Tds.Protocol {
Char = 0x2f, // SYBCHAR
DateTime = 0x3d, // SYBDATETIME
DateTime4 = 0x3a, // SYBDATETIME4
DateTime2 = 0x2a, // SYBMSDATETIME2
DateTimeOffset = 0x2b, // SYBMSDATETIMEOFFSET
DateTimeN = 0x6f, // SYBDATETIMN
Decimal = 0x6a, // SYBDECIMAL
Real = 0x3b, // SYBREAL

View File

@@ -219,6 +219,9 @@ namespace Mono.Data.Tds.Protocol {
case TypeCode.Object :
if (o is byte[])
Append ((byte[]) o);
else if (o is Guid)
Append (((Guid) o).ToByteArray ());
else break;
return;
case TypeCode.Int16 :
Append ((short) o);