Skip to content
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

This file was deleted.

4 changes: 2 additions & 2 deletions src/libraries/System.Data.OleDb/src/DbBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ internal int MaxLen
{
case (NativeDBType.BSTR): // ADP.PtrSize
case (NativeDBType.HCHAPTER): // ADP.PtrSize
case (NativeDBType.PROPVARIANT): // sizeof(PROPVARIANT)
case (NativeDBType.VARIANT): // 16 or 24 (8 + ADP.PtrSize *2)
case (NativeDBType.PROPVARIANT): // sizeof(ComVariant)
case (NativeDBType.VARIANT): // sizeof(ComVariant)
case (NativeDBType.BYREF | NativeDBType.BYTES): // ADP.PtrSize
case (NativeDBType.BYREF | NativeDBType.WSTR): // ADP.PtrSize
// allocate extra space to cache original value for disposal
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Data.OleDb/src/DbPropSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected override bool ReleaseHandle()
IntPtr vptr = ADP.IntPtrOffset(rgProperties, ODB.OffsetOf_tagDBPROP_Value);
for (int k = 0; k < cProperties; ++k, vptr = ADP.IntPtrOffset(vptr, ODB.SizeOf_tagDBPROP))
{
Interop.OleAut32.VariantClear(vptr);
Interop.Ole32.PropVariantClear(vptr);
}
Interop.Ole32.CoTaskMemFree(rgProperties);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Data.OleDb/src/OleDb_Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Data.Common;
using System.Runtime.InteropServices.Marshalling;

namespace System.Data.OleDb
{
Expand Down Expand Up @@ -148,8 +149,7 @@ internal sealed class NativeDBType
private static readonly NativeDBType D_LongVarBinary = new NativeDBType(0xff, -1, false, true, OleDbType.LongVarBinary, NativeDBType.BYTES, S_LONGVARBINARY, typeof(byte[]), NativeDBType.BYTES, DbType.Binary); // 19
private static readonly NativeDBType D_LongVarChar = new NativeDBType(0xff, -1, false, true, OleDbType.LongVarChar, NativeDBType.STR, S_LONGVARCHAR, typeof(string), NativeDBType.WSTR/*STR*/, DbType.AnsiString); // 20 - (ansi pointer)
private static readonly NativeDBType D_Numeric = new NativeDBType(28, 19, true, false, OleDbType.Numeric, NativeDBType.NUMERIC, S_NUMERIC, typeof(decimal), NativeDBType.NUMERIC, DbType.Decimal); // 21 - (tagDB_Numeric)
private static readonly unsafe NativeDBType D_PropVariant = new NativeDBType(0xff, sizeof(PROPVARIANT),
true, false, OleDbType.PropVariant, NativeDBType.PROPVARIANT, S_PROPVARIANT, typeof(object), NativeDBType.VARIANT, DbType.Object); // 22
private static readonly unsafe NativeDBType D_PropVariant = new NativeDBType(0xff, sizeof(ComVariant), true, false, OleDbType.PropVariant, NativeDBType.PROPVARIANT, S_PROPVARIANT, typeof(object), NativeDBType.VARIANT, DbType.Object); // 22
private static readonly NativeDBType D_Single = new NativeDBType(7, 4, true, false, OleDbType.Single, NativeDBType.R4, S_R4, typeof(float), NativeDBType.R4, DbType.Single); // 23 - single
private static readonly NativeDBType D_Double = new NativeDBType(15, 8, true, false, OleDbType.Double, NativeDBType.R8, S_R8, typeof(double), NativeDBType.R8, DbType.Double); // 24 - double
private static readonly NativeDBType D_UnsignedTinyInt = new NativeDBType(3, 1, true, false, OleDbType.UnsignedTinyInt, NativeDBType.UI1, S_UI1, typeof(byte), NativeDBType.UI1, DbType.Byte); // 25 - byte7
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/System.Data.OleDb/src/OleDb_Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Text;

namespace System.Data.OleDb
Expand Down Expand Up @@ -569,7 +571,7 @@ internal static InvalidOperationException IDBInfoNotSupported()
internal static readonly int SizeOf_tagDBPROPINFO = IsRunningOnX86 ? Marshal.SizeOf<tagDBPROPINFO_x86>() : Marshal.SizeOf<tagDBPROPINFO>();
internal static readonly int SizeOf_tagDBPROPIDSET = Marshal.SizeOf<tagDBPROPIDSET>();
internal static readonly int SizeOf_Guid = Marshal.SizeOf<Guid>();
internal static readonly int SizeOf_Variant = 8 + (2 * IntPtr.Size); // 16 on 32bit, 24 on 64bit
internal static readonly int SizeOf_Variant = Unsafe.SizeOf<ComVariant>();

internal static readonly int OffsetOf_tagDBPROP_Status = IsRunningOnX86 ? Marshal.OffsetOf(typeof(tagDBPROP_x86), "dwStatus").ToInt32() : Marshal.OffsetOf(typeof(tagDBPROP), "dwStatus").ToInt32();
internal static readonly int OffsetOf_tagDBPROP_Value = IsRunningOnX86 ? Marshal.OffsetOf(typeof(tagDBPROP_x86), "vValue").ToInt32() : Marshal.OffsetOf(typeof(tagDBPROP), "vValue").ToInt32();
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected override bool ReleaseHandle()
for (int k = 0; k < infoCount; ++k)
{
IntPtr valuePtr = ADP.IntPtrOffset(infoPtr, (k * ODB.SizeOf_tagDBPROPINFO) + ODB.OffsetOf_tagDBPROPINFO_Value);
Interop.OleAut32.VariantClear(valuePtr);
Interop.Ole32.PropVariantClear(valuePtr);
}
Interop.Ole32.CoTaskMemFree(infoPtr); // was allocated by provider
}
Expand Down
48 changes: 7 additions & 41 deletions src/libraries/System.Data.OleDb/src/RowBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace System.Data.OleDb
{
Expand Down Expand Up @@ -407,14 +408,11 @@ private unsafe void ResetValues(IntPtr buffer, object? iaccessor)
ValidateCheck(valueOffset, 2 * IntPtr.Size);
FreeCoTaskMem(buffer, valueOffset);
break;
case NativeDBType.VARIANT:
case NativeDBType.PROPVARIANT:
ValidateCheck(valueOffset, 2 * sizeof(PROPVARIANT));
ValidateCheck(valueOffset, 2 * sizeof(ComVariant));
FreePropVariant(buffer, valueOffset);
break;
case NativeDBType.VARIANT:
ValidateCheck(valueOffset, 2 * ODB.SizeOf_Variant);
FreeVariant(buffer, valueOffset);
break;
case NativeDBType.BSTR:
ValidateCheck(valueOffset, 2 * IntPtr.Size);
FreeBstr(buffer, valueOffset);
Expand Down Expand Up @@ -533,48 +531,16 @@ private static void FreeCoTaskMem(IntPtr buffer, int valueOffset)
}
}

private static void FreeVariant(IntPtr buffer, int valueOffset)
{
// two contiguous VARIANT structures that need to be freed
// the second should only be freed if different from the first

Debug.Assert(0 == (ODB.SizeOf_Variant % 8), "unexpected VARIANT size mutiplier");
Debug.Assert(0 == valueOffset % 8, "unexpected unaligned ptr offset");

IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset);
IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + ODB.SizeOf_Variant);
bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, ODB.SizeOf_Variant);

RuntimeHelpers.PrepareConstrainedRegions();
try
{ }
finally
{
// always clear the first structure
Interop.OleAut32.VariantClear(currentHandle);
if (different)
{
// second structure different from the first
Interop.OleAut32.VariantClear(originalHandle);
}
else
{
// second structure same as the first, just clear the field
SafeNativeMethods.ZeroMemory(originalHandle, ODB.SizeOf_Variant);
}
}
}

private static unsafe void FreePropVariant(IntPtr buffer, int valueOffset)
{
// two contiguous PROPVARIANT structures that need to be freed
// the second should only be freed if different from the first
Debug.Assert(0 == (sizeof(PROPVARIANT) % 8), "unexpected PROPVARIANT size mutiplier");
Debug.Assert(0 == (sizeof(ComVariant) % 8), "unexpected PROPVARIANT size mutiplier");
Debug.Assert(0 == valueOffset % 8, "unexpected unaligned ptr offset");

IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset);
IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + sizeof(PROPVARIANT));
bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, sizeof(PROPVARIANT));
IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + sizeof(ComVariant));
bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, sizeof(ComVariant));

RuntimeHelpers.PrepareConstrainedRegions();
try
Expand All @@ -591,7 +557,7 @@ private static unsafe void FreePropVariant(IntPtr buffer, int valueOffset)
else
{
// second structure same as the first, just clear the field
SafeNativeMethods.ZeroMemory(originalHandle, sizeof(PROPVARIANT));
SafeNativeMethods.ZeroMemory(originalHandle, sizeof(ComVariant));
}
}
}
Expand Down
Loading