You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,363 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DBBindings.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
sealed internal class Bindings {
|
||||
|
||||
private readonly tagDBPARAMBINDINFO[] _bindInfo;
|
||||
private readonly tagDBBINDING[] _dbbindings;
|
||||
private readonly tagDBCOLUMNACCESS[] _dbcolumns;
|
||||
|
||||
private OleDbParameter[] _parameters;
|
||||
private int _collectionChangeID;
|
||||
|
||||
private OleDbDataReader _dataReader;
|
||||
private ColumnBinding[] _columnBindings;
|
||||
private RowBinding _rowBinding;
|
||||
|
||||
private int _index;
|
||||
private int _count;
|
||||
private int _dataBufferSize;
|
||||
private bool _ifIRowsetElseIRow;
|
||||
private bool _forceRebind;
|
||||
private bool _needToReset;
|
||||
|
||||
private Bindings(int count) {
|
||||
_count = count;
|
||||
|
||||
_dbbindings = new tagDBBINDING[count];
|
||||
for(int i = 0;i < _dbbindings.Length;++i) {
|
||||
_dbbindings[i] = new tagDBBINDING();
|
||||
}
|
||||
_dbcolumns = new tagDBCOLUMNACCESS[count];
|
||||
}
|
||||
|
||||
internal Bindings(OleDbParameter[] parameters, int collectionChangeID) : this(parameters.Length) {
|
||||
_bindInfo = new tagDBPARAMBINDINFO[parameters.Length];
|
||||
_parameters = parameters;
|
||||
_collectionChangeID = collectionChangeID;
|
||||
_ifIRowsetElseIRow = true;
|
||||
}
|
||||
|
||||
internal Bindings(OleDbDataReader dataReader, bool ifIRowsetElseIRow, int count) : this(count) {
|
||||
_dataReader = dataReader;
|
||||
_ifIRowsetElseIRow = ifIRowsetElseIRow;
|
||||
}
|
||||
|
||||
internal tagDBPARAMBINDINFO[] BindInfo {
|
||||
get { return _bindInfo; }
|
||||
}
|
||||
internal tagDBCOLUMNACCESS[] DBColumnAccess {
|
||||
get { return _dbcolumns; }
|
||||
}
|
||||
|
||||
internal int CurrentIndex {
|
||||
//get { return _index; }
|
||||
set {
|
||||
Debug.Assert((0 <= value) && (value < _count), "bad binding index");
|
||||
_index = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal ColumnBinding[] ColumnBindings() {
|
||||
Debug.Assert(null != _columnBindings, "null ColumnBindings");
|
||||
return _columnBindings;
|
||||
}
|
||||
|
||||
internal OleDbParameter[] Parameters() {
|
||||
Debug.Assert(null != _parameters, "null Parameters");
|
||||
return _parameters;
|
||||
}
|
||||
|
||||
internal RowBinding RowBinding() {
|
||||
//Debug.Assert(null != _rowBinding, "null RowBinding");
|
||||
return _rowBinding;
|
||||
}
|
||||
|
||||
internal bool ForceRebind {
|
||||
get { return _forceRebind; }
|
||||
set { _forceRebind = value; }
|
||||
}
|
||||
|
||||
// tagDBPARAMBINDINFO member access
|
||||
internal IntPtr DataSourceType {
|
||||
//get { return _bindInfo[_index].pwszDataSourceType; }
|
||||
set {
|
||||
_bindInfo[_index].pwszDataSourceType = value;
|
||||
}
|
||||
}
|
||||
internal IntPtr Name {
|
||||
//get { return _bindInfo[_index].pwszName; }
|
||||
set {
|
||||
_bindInfo[_index].pwszName= value;
|
||||
}
|
||||
}
|
||||
internal IntPtr ParamSize {
|
||||
get {
|
||||
if (null != _bindInfo) {
|
||||
return _bindInfo[_index].ulParamSize;
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
set {
|
||||
_bindInfo[_index].ulParamSize= value;
|
||||
}
|
||||
}
|
||||
internal int Flags {
|
||||
//get { return _bindInfo[_index].dwFlag; }
|
||||
set {
|
||||
_bindInfo[_index].dwFlags= value;
|
||||
}
|
||||
}
|
||||
|
||||
// tagDBBINDING member access
|
||||
//
|
||||
internal IntPtr Ordinal { // iOrdinal
|
||||
//get { return _dbbindings[_index].iOrdinal.ToInt32(); }
|
||||
set {
|
||||
_dbbindings[_index].iOrdinal = value;
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
/*internal int ValueOffset { // obValue
|
||||
get { return _dbbindings[_index].obValue.ToInt32(); }
|
||||
}
|
||||
internal int LengthOffset { // obLength
|
||||
get { return _dbbindings[_index].obLength.ToInt32(); }
|
||||
}
|
||||
internal int StatusOffset { // obStatus
|
||||
get { return _dbbindings[_index].obStatus.ToInt32(); }
|
||||
}*/
|
||||
#endif
|
||||
internal int Part { // dwPart
|
||||
#if DEBUG
|
||||
//get { return _dbbindings[_index].dwPart; }
|
||||
#endif
|
||||
set { _dbbindings[_index].dwPart = value; }
|
||||
}
|
||||
internal int ParamIO { // eParamIO
|
||||
#if DEBUG
|
||||
//get { return _dbbindings[_index].eParamIO; }
|
||||
#endif
|
||||
set { _dbbindings[_index].eParamIO = value; }
|
||||
}
|
||||
internal int MaxLen { // cbMaxLen
|
||||
//get { return (int) _dbbindings[_index].cbMaxLen; }
|
||||
set {
|
||||
Debug.Assert(0 <= value, "invalid MaxLen");
|
||||
|
||||
_dbbindings[_index].obStatus = (IntPtr) (_dataBufferSize + 0);
|
||||
_dbbindings[_index].obLength = (IntPtr) (_dataBufferSize + ADP.PtrSize);
|
||||
_dbbindings[_index].obValue = (IntPtr) (_dataBufferSize + ADP.PtrSize + ADP.PtrSize);
|
||||
_dataBufferSize += ADP.PtrSize + ADP.PtrSize;
|
||||
|
||||
switch(DbType) {
|
||||
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.BYREF | NativeDBType.BYTES): // ADP.PtrSize
|
||||
case (NativeDBType.BYREF | NativeDBType.WSTR): // ADP.PtrSize
|
||||
// allocate extra space to cache original value for disposal
|
||||
_dataBufferSize += System.Data.OleDb.RowBinding.AlignDataSize(value*2);
|
||||
_needToReset = true;
|
||||
break;
|
||||
default:
|
||||
_dataBufferSize += System.Data.OleDb.RowBinding.AlignDataSize(value);
|
||||
break;
|
||||
}
|
||||
|
||||
_dbbindings[_index].cbMaxLen = (IntPtr)value;
|
||||
_dbcolumns[_index].cbMaxLen = (IntPtr)value;
|
||||
}
|
||||
}
|
||||
internal int DbType { // wType
|
||||
get { return _dbbindings[_index].wType; }
|
||||
set {
|
||||
_dbbindings[_index].wType = (short) value;
|
||||
_dbcolumns[_index].wType = (short) value;
|
||||
}
|
||||
}
|
||||
internal byte Precision { // bPrecision
|
||||
#if DEBUG
|
||||
//get { return _dbbindings[_index].bPrecision; }
|
||||
|
||||
#endif
|
||||
set {
|
||||
if (null != _bindInfo) {
|
||||
_bindInfo[_index].bPrecision = value;
|
||||
}
|
||||
_dbbindings[_index].bPrecision = value;
|
||||
_dbcolumns[_index].bPrecision = value;
|
||||
}
|
||||
}
|
||||
internal byte Scale { // bScale
|
||||
#if DEBUG
|
||||
//get { return _dbbindings[_index].bScale; }
|
||||
#endif
|
||||
set {
|
||||
if (null != _bindInfo) {
|
||||
_bindInfo[_index].bScale = value;
|
||||
}
|
||||
_dbbindings[_index].bScale = value;
|
||||
_dbcolumns[_index].bScale = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal int AllocateForAccessor(OleDbDataReader dataReader, int indexStart, int indexForAccessor) {
|
||||
Debug.Assert(null == _rowBinding, "row binding already allocated");
|
||||
Debug.Assert(null == _columnBindings, "column bindings already allocated");
|
||||
|
||||
RowBinding rowBinding = System.Data.OleDb.RowBinding.CreateBuffer(_count, _dataBufferSize, _needToReset);
|
||||
_rowBinding = rowBinding;
|
||||
|
||||
ColumnBinding[] columnBindings = rowBinding.SetBindings(dataReader, this, indexStart, indexForAccessor, _parameters, _dbbindings, _ifIRowsetElseIRow);
|
||||
Debug.Assert(null != columnBindings, "null column bindings");
|
||||
_columnBindings = columnBindings;
|
||||
|
||||
if (!_ifIRowsetElseIRow) {
|
||||
Debug.Assert(columnBindings.Length == _dbcolumns.Length, "length mismatch");
|
||||
for(int i = 0; i < columnBindings.Length; ++i) { // WebData 94427
|
||||
_dbcolumns[i].pData = rowBinding.DangerousGetDataPtr(columnBindings[i].ValueOffset); // We are simply pointing at a location later in the buffer, so we're OK to not addref the buffer.
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
int index = -1;
|
||||
foreach(ColumnBinding binding in columnBindings) {
|
||||
Debug.Assert(index < binding.Index, "invaild index");
|
||||
index = binding.Index;
|
||||
}
|
||||
#endif
|
||||
return (indexStart + columnBindings.Length);
|
||||
}
|
||||
|
||||
|
||||
internal void ApplyInputParameters() {
|
||||
ColumnBinding[] columnBindings = this.ColumnBindings();
|
||||
OleDbParameter[] parameters = this.Parameters();
|
||||
|
||||
RowBinding().StartDataBlock();
|
||||
for(int i = 0; i < parameters.Length; ++i) {
|
||||
if (ADP.IsDirection(parameters[i], ParameterDirection.Input)) {
|
||||
columnBindings[i].SetOffset(parameters[i].Offset); // MDAC 80657
|
||||
columnBindings[i].Value(parameters[i].GetCoercedValue());
|
||||
}
|
||||
else {
|
||||
// always set ouput only and return value parameter values to null when executing
|
||||
parameters[i].Value = null;
|
||||
|
||||
//columnBindings[i].SetValueEmpty(); // webdata 115079
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void ApplyOutputParameters() {
|
||||
ColumnBinding[] columnBindings = this.ColumnBindings();
|
||||
OleDbParameter[] parameters = this.Parameters();
|
||||
|
||||
for(int i = 0; i < parameters.Length; ++i) {
|
||||
if (ADP.IsDirection(parameters[i], ParameterDirection.Output)) {
|
||||
parameters[i].Value = columnBindings[i].Value();
|
||||
}
|
||||
}
|
||||
CleanupBindings();
|
||||
}
|
||||
|
||||
internal bool AreParameterBindingsInvalid(OleDbParameterCollection collection) {
|
||||
Debug.Assert(null != collection, "null parameter collection");
|
||||
Debug.Assert(null != _parameters, "null parameters");
|
||||
|
||||
ColumnBinding[] columnBindings = this.ColumnBindings();
|
||||
if (!ForceRebind && ((collection.ChangeID == _collectionChangeID) && (_parameters.Length == collection.Count))) {
|
||||
for(int i = 0; i < columnBindings.Length; ++i) {
|
||||
ColumnBinding binding = columnBindings[i];
|
||||
|
||||
Debug.Assert(null != binding, "null column binding");
|
||||
Debug.Assert(binding.Parameter() == _parameters[i], "parameter mismatch");
|
||||
if (binding.IsParameterBindingInvalid(collection[i])) {
|
||||
//Debug.WriteLine("ParameterBindingsInvalid");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Debug.WriteLine("ParameterBindingsValid");
|
||||
return false; // collection and cached values are the same
|
||||
}
|
||||
//Debug.WriteLine("ParameterBindingsInvalid");
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void CleanupBindings() {
|
||||
RowBinding rowBinding = this.RowBinding();
|
||||
if (null != rowBinding) {
|
||||
rowBinding.ResetValues();
|
||||
|
||||
ColumnBinding[] columnBindings = this.ColumnBindings();
|
||||
for(int i = 0; i < columnBindings.Length; ++i) {
|
||||
ColumnBinding binding = columnBindings[i];
|
||||
if (null != binding) {
|
||||
binding.ResetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void CloseFromConnection() {
|
||||
if (null != _rowBinding) {
|
||||
_rowBinding.CloseFromConnection();
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
internal OleDbHResult CreateAccessor(UnsafeNativeMethods.IAccessor iaccessor, int flags) {
|
||||
Debug.Assert(null != _rowBinding, "no row binding");
|
||||
Debug.Assert(null != _columnBindings, "no column bindings");
|
||||
return _rowBinding.CreateAccessor(iaccessor, flags, _columnBindings);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_parameters = null;
|
||||
_dataReader = null;
|
||||
_columnBindings = null;
|
||||
|
||||
RowBinding rowBinding = _rowBinding;
|
||||
_rowBinding = null;
|
||||
if (null != rowBinding) {
|
||||
rowBinding.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
internal void GuidKindName(Guid guid, int eKind, IntPtr propid) {
|
||||
tagDBCOLUMNACCESS[] dbcolumns = DBColumnAccess;
|
||||
dbcolumns[_index].columnid.uGuid = guid;
|
||||
dbcolumns[_index].columnid.eKind = eKind;
|
||||
dbcolumns[_index].columnid.ulPropid = propid;
|
||||
}
|
||||
|
||||
internal void ParameterStatus(StringBuilder builder) {
|
||||
ColumnBinding[] columnBindings = ColumnBindings();
|
||||
for(int i = 0; i < columnBindings.Length; ++i) {
|
||||
ODB.CommandParameterStatus(builder, i, columnBindings[i].StatusValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DBPropSet.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
sealed internal class DBPropSet : SafeHandle {
|
||||
|
||||
private readonly Int32 propertySetCount;
|
||||
|
||||
// VSDD 621427: stores the exception with last error.HRESULT from IDBProperties.GetProperties
|
||||
private Exception lastErrorFromProvider;
|
||||
|
||||
private DBPropSet() : base(IntPtr.Zero, true) {
|
||||
propertySetCount = 0;
|
||||
}
|
||||
|
||||
internal DBPropSet(int propertysetCount) : this() {
|
||||
this.propertySetCount = propertysetCount;
|
||||
IntPtr countOfBytes = (IntPtr)(propertysetCount * ODB.SizeOf_tagDBPROPSET);
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try {} finally {
|
||||
base.handle = SafeNativeMethods.CoTaskMemAlloc(countOfBytes);
|
||||
if (ADP.PtrZero != base.handle) {
|
||||
SafeNativeMethods.ZeroMemory(base.handle, countOfBytes);
|
||||
}
|
||||
}
|
||||
if (ADP.PtrZero == base.handle) {
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
}
|
||||
|
||||
internal DBPropSet(UnsafeNativeMethods.IDBProperties properties, PropertyIDSet propidset, out OleDbHResult hr) : this() {
|
||||
Debug.Assert(null != properties, "null IDBProperties");
|
||||
|
||||
int propidsetcount = 0;
|
||||
if (null != propidset) {
|
||||
propidsetcount = propidset.Count;
|
||||
}
|
||||
Bid.Trace("<oledb.IDBProperties.GetProperties|API|OLEDB>\n");
|
||||
hr = properties.GetProperties(propidsetcount, propidset, out this.propertySetCount, out base.handle);
|
||||
Bid.Trace("<oledb.IDBProperties.GetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);
|
||||
|
||||
if (hr < 0) {
|
||||
// VSDD 621427: remember the last HRESULT. Note we do not want to raise exception now to avoid breaking change from Orcas RTM/SP1
|
||||
SetLastErrorInfo(hr);
|
||||
}
|
||||
}
|
||||
|
||||
internal DBPropSet(UnsafeNativeMethods.IRowsetInfo properties, PropertyIDSet propidset, out OleDbHResult hr) : this() {
|
||||
Debug.Assert(null != properties, "null IRowsetInfo");
|
||||
|
||||
int propidsetcount = 0;
|
||||
if (null != propidset) {
|
||||
propidsetcount = propidset.Count;
|
||||
}
|
||||
Bid.Trace("<oledb.IRowsetInfo.GetProperties|API|OLEDB>\n");
|
||||
hr = properties.GetProperties(propidsetcount, propidset, out this.propertySetCount, out base.handle);
|
||||
Bid.Trace("<oledb.IRowsetInfo.GetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);
|
||||
|
||||
if (hr < 0) {
|
||||
// VSDD 621427: remember the last HRESULT. Note we do not want to raise exception now to avoid breaking change from Orcas RTM/SP1
|
||||
SetLastErrorInfo(hr);
|
||||
}
|
||||
}
|
||||
|
||||
internal DBPropSet(UnsafeNativeMethods.ICommandProperties properties, PropertyIDSet propidset, out OleDbHResult hr) : this() {
|
||||
Debug.Assert(null != properties, "null ICommandProperties");
|
||||
|
||||
int propidsetcount = 0;
|
||||
if (null != propidset) {
|
||||
propidsetcount = propidset.Count;
|
||||
}
|
||||
Bid.Trace("<oledb.ICommandProperties.GetProperties|API|OLEDB>\n");
|
||||
hr = properties.GetProperties(propidsetcount, propidset, out this.propertySetCount, out base.handle);
|
||||
Bid.Trace("<oledb.ICommandProperties.GetProperties|API|OLEDB|RET> %08X{HRESULT}\n", hr);
|
||||
|
||||
if (hr < 0) {
|
||||
// VSDD 621427: remember the last HRESULT. Note we do not want to raise exception now to avoid breaking change from Orcas RTM/SP1
|
||||
SetLastErrorInfo(hr);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLastErrorInfo(OleDbHResult lastErrorHr) {
|
||||
// note: OleDbHResult is actually a simple wrapper over HRESULT with OLEDB-specific codes
|
||||
UnsafeNativeMethods.IErrorInfo errorInfo = null;
|
||||
string message = String.Empty;
|
||||
|
||||
OleDbHResult errorInfoHr = UnsafeNativeMethods.GetErrorInfo(0, out errorInfo); // 0 - IErrorInfo exists, 1 - no IErrorInfo
|
||||
if ((errorInfoHr == OleDbHResult.S_OK) && (errorInfo != null)) {
|
||||
ODB.GetErrorDescription(errorInfo, lastErrorHr, out message);
|
||||
// note that either GetErrorInfo or GetErrorDescription might fail in which case we will have only the HRESULT value in exception message
|
||||
}
|
||||
lastErrorFromProvider = new COMException(message, (int)lastErrorHr);
|
||||
}
|
||||
|
||||
public override bool IsInvalid {
|
||||
get {
|
||||
return (IntPtr.Zero == base.handle);
|
||||
}
|
||||
}
|
||||
|
||||
override protected bool ReleaseHandle() {
|
||||
// NOTE: The SafeHandle class guarantees this will be called exactly once and is non-interrutible.
|
||||
IntPtr ptr = base.handle;
|
||||
base.handle = IntPtr.Zero;
|
||||
if (ADP.PtrZero != ptr) {
|
||||
|
||||
int count = this.propertySetCount;
|
||||
for (int i = 0, offset = 0; i < count; ++i, offset += ODB.SizeOf_tagDBPROPSET) {
|
||||
|
||||
IntPtr rgProperties = Marshal.ReadIntPtr(ptr, offset);
|
||||
if(ADP.PtrZero != rgProperties) {
|
||||
int cProperties = Marshal.ReadInt32(ptr, offset + ADP.PtrSize);
|
||||
|
||||
IntPtr vptr = ADP.IntPtrOffset(rgProperties, ODB.OffsetOf_tagDBPROP_Value);
|
||||
for (int k = 0; k < cProperties; ++k, vptr = ADP.IntPtrOffset(vptr, ODB.SizeOf_tagDBPROP)) {
|
||||
SafeNativeMethods.VariantClear(vptr);
|
||||
}
|
||||
SafeNativeMethods.CoTaskMemFree(rgProperties);
|
||||
}
|
||||
}
|
||||
SafeNativeMethods.CoTaskMemFree(ptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal int PropertySetCount {
|
||||
get {
|
||||
return this.propertySetCount;
|
||||
}
|
||||
}
|
||||
|
||||
internal tagDBPROP[] GetPropertySet(int index, out Guid propertyset) {
|
||||
if ((index < 0) || (PropertySetCount <= index)) {
|
||||
if (lastErrorFromProvider != null)
|
||||
{
|
||||
// VSDD 621427: add extra error information for CSS/stress troubleshooting.
|
||||
// We need to keep same exception type to avoid breaking change with Orcas RTM/SP1.
|
||||
throw ADP.InternalError(ADP.InternalErrorCode.InvalidBuffer, lastErrorFromProvider);
|
||||
}
|
||||
else {
|
||||
throw ADP.InternalError(ADP.InternalErrorCode.InvalidBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
tagDBPROPSET propset = new tagDBPROPSET();
|
||||
tagDBPROP[] properties = null;
|
||||
|
||||
bool mustRelease = false;
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try {
|
||||
DangerousAddRef(ref mustRelease);
|
||||
IntPtr propertySetPtr = ADP.IntPtrOffset(DangerousGetHandle(), index * ODB.SizeOf_tagDBPROPSET);
|
||||
Marshal.PtrToStructure(propertySetPtr, propset);
|
||||
propertyset = propset.guidPropertySet;
|
||||
|
||||
properties = new tagDBPROP[propset.cProperties];
|
||||
for(int i = 0; i < properties.Length; ++i) {
|
||||
properties[i] = new tagDBPROP();
|
||||
IntPtr ptr = ADP.IntPtrOffset(propset.rgProperties, i * ODB.SizeOf_tagDBPROP);
|
||||
Marshal.PtrToStructure(ptr, properties[i]);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (mustRelease) {
|
||||
DangerousRelease();
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
internal void SetPropertySet(int index, Guid propertySet, tagDBPROP[] properties) {
|
||||
if ((index < 0) || (PropertySetCount <= index)) {
|
||||
if (lastErrorFromProvider != null) {
|
||||
// VSDD 621427: add extra error information for CSS/stress troubleshooting.
|
||||
// We need to keep same exception type to avoid breaking change with Orcas RTM/SP1.
|
||||
throw ADP.InternalError(ADP.InternalErrorCode.InvalidBuffer, lastErrorFromProvider);
|
||||
}
|
||||
else {
|
||||
throw ADP.InternalError(ADP.InternalErrorCode.InvalidBuffer);
|
||||
}
|
||||
}
|
||||
Debug.Assert(Guid.Empty != propertySet, "invalid propertySet");
|
||||
Debug.Assert((null != properties) && (0 < properties.Length), "invalid properties");
|
||||
|
||||
IntPtr countOfBytes = (IntPtr)(properties.Length * ODB.SizeOf_tagDBPROP);
|
||||
tagDBPROPSET propset = new tagDBPROPSET(properties.Length, propertySet);
|
||||
|
||||
bool mustRelease = false;
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try {
|
||||
DangerousAddRef(ref mustRelease);
|
||||
|
||||
IntPtr propsetPtr = ADP.IntPtrOffset(DangerousGetHandle(), index * ODB.SizeOf_tagDBPROPSET);
|
||||
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try {} finally {
|
||||
// must allocate and clear the memory without interruption
|
||||
propset.rgProperties = SafeNativeMethods.CoTaskMemAlloc(countOfBytes);
|
||||
if (ADP.PtrZero != propset.rgProperties) {
|
||||
// clearing is important so that we don't treat existing
|
||||
// garbage as important information during releaseHandle
|
||||
SafeNativeMethods.ZeroMemory(propset.rgProperties, countOfBytes);
|
||||
|
||||
// writing the structure to native memory so that it knows to free the referenced pointers
|
||||
Marshal.StructureToPtr(propset, propsetPtr, false/*deleteold*/);
|
||||
}
|
||||
}
|
||||
if (ADP.PtrZero == propset.rgProperties) {
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
||||
for(int i = 0; i < properties.Length; ++i) {
|
||||
Debug.Assert(null != properties[i], "null tagDBPROP " + i.ToString(CultureInfo.InvariantCulture));
|
||||
IntPtr propertyPtr = ADP.IntPtrOffset(propset.rgProperties, i * ODB.SizeOf_tagDBPROP);
|
||||
Marshal.StructureToPtr(properties[i], propertyPtr, false/*deleteold*/);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (mustRelease) {
|
||||
DangerousRelease();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static internal DBPropSet CreateProperty(Guid propertySet, int propertyId, bool required, object value) {
|
||||
tagDBPROP dbprop = new tagDBPROP(propertyId, required, value);
|
||||
DBPropSet propertyset = new DBPropSet(1);
|
||||
propertyset.SetPropertySet(0, propertySet, new tagDBPROP[1] { dbprop });
|
||||
return propertyset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,414 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OLEDB_Enum.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal enum DBStatus { // from 4214.0
|
||||
S_OK = 0,
|
||||
E_BADACCESSOR = 1,
|
||||
E_CANTCONVERTVALUE = 2,
|
||||
S_ISNULL = 3,
|
||||
S_TRUNCATED = 4,
|
||||
E_SIGNMISMATCH = 5,
|
||||
E_DATAOVERFLOW = 6,
|
||||
E_CANTCREATE = 7,
|
||||
E_UNAVAILABLE = 8,
|
||||
E_PERMISSIONDENIED = 9,
|
||||
E_INTEGRITYVIOLATION = 10,
|
||||
E_SCHEMAVIOLATION = 11,
|
||||
E_BADSTATUS = 12,
|
||||
S_DEFAULT = 13,
|
||||
S_CELLEMPTY = 14, // 2.0
|
||||
S_IGNORE = 15, // 2.0
|
||||
E_DOESNOTEXIST = 16, // 2.1
|
||||
E_INVALIDURL = 17, // 2.1
|
||||
E_RESOURCELOCKED = 18, // 2.1
|
||||
E_RESOURCEEXISTS = 19, // 2.1
|
||||
E_CANNOTCOMPLETE = 20, // 2.1
|
||||
E_VOLUMENOTFOUND = 21, // 2.1
|
||||
E_OUTOFSPACE = 22, // 2.1
|
||||
S_CANNOTDELETESOURCE = 23, // 2.1
|
||||
E_READONLY = 24, // 2.1
|
||||
E_RESOURCEOUTOFSCOPE = 25, // 2.1
|
||||
S_ALREADYEXISTS = 26, // 2.1
|
||||
E_CANCELED = 27, // 2.5
|
||||
E_NOTCOLLECTION = 28, // 2.5
|
||||
S_ROWSETCOLUMN = 29, // 2.6
|
||||
}
|
||||
|
||||
sealed internal class NativeDBType { // from 4214.0
|
||||
// Variant compatible
|
||||
internal const short EMPTY = 0; //
|
||||
internal const short NULL = 1; //
|
||||
internal const short I2 = 2; //
|
||||
internal const short I4 = 3; //
|
||||
internal const short R4 = 4; //
|
||||
internal const short R8 = 5; //
|
||||
internal const short CY = 6; //
|
||||
internal const short DATE = 7; //
|
||||
internal const short BSTR = 8; //
|
||||
internal const short IDISPATCH = 9; //
|
||||
internal const short ERROR = 10; //
|
||||
internal const short BOOL = 11; //
|
||||
internal const short VARIANT = 12; //
|
||||
internal const short IUNKNOWN = 13; //
|
||||
internal const short DECIMAL = 14; //
|
||||
internal const short I1 = 16; //
|
||||
internal const short UI1 = 17; //
|
||||
internal const short UI2 = 18; //
|
||||
internal const short UI4 = 19; //
|
||||
internal const short I8 = 20; //
|
||||
internal const short UI8 = 21; //
|
||||
internal const short FILETIME = 64; // 2.0
|
||||
internal const short DBUTCDATETIME = 65; // 9.0
|
||||
internal const short DBTIME_EX = 66; // 9.0
|
||||
internal const short GUID = 72; //
|
||||
internal const short BYTES = 128; //
|
||||
internal const short STR = 129; //
|
||||
internal const short WSTR = 130; //
|
||||
internal const short NUMERIC = 131; // with potential overflow
|
||||
internal const short UDT = 132; // should never be encountered
|
||||
internal const short DBDATE = 133; //
|
||||
internal const short DBTIME = 134; //
|
||||
internal const short DBTIMESTAMP = 135; // granularity reduced from 1ns to 100ns (sql is 3.33 milli seconds)
|
||||
internal const short HCHAPTER = 136; // 1.5
|
||||
internal const short PROPVARIANT = 138; // 2.0 - as variant
|
||||
internal const short VARNUMERIC = 139; // 2.0 - as string else ConversionException
|
||||
internal const short XML = 141; // 9.0
|
||||
internal const short VECTOR = unchecked((short)0x1000);
|
||||
internal const short ARRAY = unchecked((short)0x2000);
|
||||
internal const short BYREF = unchecked((short)0x4000); //
|
||||
internal const short RESERVED = unchecked((short)0x8000); // SystemException
|
||||
|
||||
// high mask
|
||||
internal const short HighMask = unchecked((short)0xf000);
|
||||
|
||||
static internal bool HasHighBit(short value) {
|
||||
return (0 != (HighMask & value));
|
||||
}
|
||||
/*
|
||||
static internal bool IsArray(short value) {
|
||||
return (ARRAY == (HighMask & value));
|
||||
}
|
||||
static internal bool IsByRef(short value) {
|
||||
return (BYREF == (HighMask & value));
|
||||
}
|
||||
static internal bool IsReserved(short value) {
|
||||
return (RESERVED == (HighMask & value));
|
||||
}
|
||||
static internal bool IsVector(short value) {
|
||||
return (VECTOR == (HighMask & value));
|
||||
}
|
||||
static internal int GetLowBits(short value) {
|
||||
return (value & ~HighMask);
|
||||
}
|
||||
*/
|
||||
|
||||
private const string S_BINARY = "DBTYPE_BINARY"; // DBTYPE_BYTES
|
||||
private const string S_BOOL = "DBTYPE_BOOL";
|
||||
private const string S_BSTR = "DBTYPE_BSTR";
|
||||
private const string S_CHAR = "DBTYPE_CHAR"; // DBTYPE_STR
|
||||
private const string S_CY = "DBTYPE_CY";
|
||||
private const string S_DATE = "DBTYPE_DATE";
|
||||
private const string S_DBDATE = "DBTYPE_DBDATE";
|
||||
private const string S_DBTIME = "DBTYPE_DBTIME";
|
||||
private const string S_DBTIMESTAMP = "DBTYPE_DBTIMESTAMP";
|
||||
private const string S_DECIMAL = "DBTYPE_DECIMAL";
|
||||
private const string S_ERROR = "DBTYPE_ERROR";
|
||||
private const string S_FILETIME = "DBTYPE_FILETIME";
|
||||
private const string S_GUID = "DBTYPE_GUID";
|
||||
private const string S_I1 = "DBTYPE_I1";
|
||||
private const string S_I2 = "DBTYPE_I2";
|
||||
private const string S_I4 = "DBTYPE_I4";
|
||||
private const string S_I8 = "DBTYPE_I8";
|
||||
private const string S_IDISPATCH = "DBTYPE_IDISPATCH";
|
||||
private const string S_IUNKNOWN = "DBTYPE_IUNKNOWN";
|
||||
private const string S_LONGVARBINARY = "DBTYPE_LONGVARBINARY"; // DBTYPE_BYTES
|
||||
private const string S_LONGVARCHAR = "DBTYPE_LONGVARCHAR"; // DBTYPE_STR
|
||||
private const string S_NUMERIC = "DBTYPE_NUMERIC";
|
||||
private const string S_PROPVARIANT = "DBTYPE_PROPVARIANT";
|
||||
private const string S_R4 = "DBTYPE_R4";
|
||||
private const string S_R8 = "DBTYPE_R8";
|
||||
private const string S_UDT = "DBTYPE_UDT";
|
||||
private const string S_UI1 = "DBTYPE_UI1";
|
||||
private const string S_UI2 = "DBTYPE_UI2";
|
||||
private const string S_UI4 = "DBTYPE_UI4";
|
||||
private const string S_UI8 = "DBTYPE_UI8";
|
||||
private const string S_VARBINARY = "DBTYPE_VARBINARY"; // DBTYPE_BYTES
|
||||
private const string S_VARCHAR = "DBTYPE_VARCHAR"; // DBTYPE_STR
|
||||
private const string S_VARIANT = "DBTYPE_VARIANT";
|
||||
private const string S_VARNUMERIC = "DBTYPE_VARNUMERIC";
|
||||
private const string S_WCHAR = "DBTYPE_WCHAR"; // DBTYPE_WSTR
|
||||
private const string S_WVARCHAR = "DBTYPE_WVARCHAR"; // DBTYPE_WSTR
|
||||
private const string S_WLONGVARCHAR = "DBTYPE_WLONGVARCHAR"; // DBTYPE_WSTR
|
||||
private const string S_XML = "DBTYPE_XML";
|
||||
|
||||
static private readonly NativeDBType D_Binary = new NativeDBType(0xff, -1, true, false, OleDbType.Binary, NativeDBType.BYTES, S_BINARY, typeof(System.Byte[]), NativeDBType.BYTES, DbType.Binary ); // 0
|
||||
static private readonly NativeDBType D_Boolean = new NativeDBType(0xff, 2, true, false, OleDbType.Boolean, NativeDBType.BOOL, S_BOOL, typeof(System.Boolean), NativeDBType.BOOL, DbType.Boolean ); // 1 - integer2 (variant_bool)
|
||||
static private readonly NativeDBType D_BSTR = new NativeDBType(0xff, ADP.PtrSize, false, false, OleDbType.BSTR, NativeDBType.BSTR, S_BSTR, typeof(System.String), NativeDBType.BSTR, DbType.String ); // 2 - integer4 (pointer)
|
||||
static private readonly NativeDBType D_Char = new NativeDBType(0xff, -1, true, false, OleDbType.Char, NativeDBType.STR, S_CHAR, typeof(System.String), NativeDBType.WSTR/*STR*/, DbType.AnsiStringFixedLength); // 3 - (ansi pointer)
|
||||
static private readonly NativeDBType D_Currency = new NativeDBType( 19, 8, true, false, OleDbType.Currency, NativeDBType.CY, S_CY, typeof(System.Decimal), NativeDBType.CY, DbType.Currency ); // 4 - integer8
|
||||
static private readonly NativeDBType D_Date = new NativeDBType(0xff, 8, true, false, OleDbType.Date, NativeDBType.DATE, S_DATE, typeof(System.DateTime), NativeDBType.DATE, DbType.DateTime ); // 5 - double
|
||||
static private readonly NativeDBType D_DBDate = new NativeDBType(0xff, 6, true, false, OleDbType.DBDate, NativeDBType.DBDATE, S_DBDATE, typeof(System.DateTime), NativeDBType.DBDATE, DbType.Date ); // 6 - (tagDBDate)
|
||||
static private readonly NativeDBType D_DBTime = new NativeDBType(0xff, 6, true, false, OleDbType.DBTime, NativeDBType.DBTIME, S_DBTIME, typeof(System.TimeSpan), NativeDBType.DBTIME, DbType.Time ); // 7 - (tagDBTime)
|
||||
static private readonly NativeDBType D_DBTimeStamp = new NativeDBType(0xff, 16, true, false, OleDbType.DBTimeStamp, NativeDBType.DBTIMESTAMP, S_DBTIMESTAMP, typeof(System.DateTime), NativeDBType.DBTIMESTAMP, DbType.DateTime ); // 8 - (tagDBTIMESTAMP)
|
||||
static private readonly NativeDBType D_Decimal = new NativeDBType( 28, 16, true, false, OleDbType.Decimal, NativeDBType.DECIMAL, S_DECIMAL, typeof(System.Decimal), NativeDBType.DECIMAL, DbType.Decimal ); // 9 - (tagDec) // MDAC 68447
|
||||
static private readonly NativeDBType D_Error = new NativeDBType(0xff, 4, true, false, OleDbType.Error, NativeDBType.ERROR, S_ERROR, typeof(System.Int32), NativeDBType.ERROR, DbType.Int32 ); // 10 - integer4
|
||||
static private readonly NativeDBType D_Filetime = new NativeDBType(0xff, 8, true, false, OleDbType.Filetime, NativeDBType.FILETIME, S_FILETIME, typeof(System.DateTime), NativeDBType.FILETIME, DbType.DateTime ); // 11 - integer8 // MDAC 59504
|
||||
static private readonly NativeDBType D_Guid = new NativeDBType(0xff, 16, true, false, OleDbType.Guid, NativeDBType.GUID, S_GUID, typeof(System.Guid), NativeDBType.GUID, DbType.Guid ); // 12 - ubyte[16]
|
||||
static private readonly NativeDBType D_TinyInt = new NativeDBType( 3, 1, true, false, OleDbType.TinyInt, NativeDBType.I1, S_I1, typeof(System.Int16), NativeDBType.I1, DbType.SByte ); // 13 - integer1 // MDAC 59492
|
||||
static private readonly NativeDBType D_SmallInt = new NativeDBType( 5, 2, true, false, OleDbType.SmallInt, NativeDBType.I2, S_I2, typeof(System.Int16), NativeDBType.I2, DbType.Int16 ); // 14 - integer2
|
||||
static private readonly NativeDBType D_Integer = new NativeDBType( 10, 4, true, false, OleDbType.Integer, NativeDBType.I4, S_I4, typeof(System.Int32), NativeDBType.I4, DbType.Int32 ); // 15 - integer4
|
||||
static private readonly NativeDBType D_BigInt = new NativeDBType( 19, 8, true, false, OleDbType.BigInt, NativeDBType.I8, S_I8, typeof(System.Int64), NativeDBType.I8, DbType.Int64 ); // 16 - integer8
|
||||
static private readonly NativeDBType D_IDispatch = new NativeDBType(0xff, ADP.PtrSize, true, false, OleDbType.IDispatch, NativeDBType.IDISPATCH, S_IDISPATCH, typeof(System.Object), NativeDBType.IDISPATCH, DbType.Object ); // 17 - integer4 (pointer)
|
||||
static private readonly NativeDBType D_IUnknown = new NativeDBType(0xff, ADP.PtrSize, true, false, OleDbType.IUnknown, NativeDBType.IUNKNOWN, S_IUNKNOWN, typeof(System.Object), NativeDBType.IUNKNOWN, DbType.Object ); // 18 - integer4 (pointer) // MDAC 64040
|
||||
static private readonly NativeDBType D_LongVarBinary = new NativeDBType(0xff, -1, false, true, OleDbType.LongVarBinary, NativeDBType.BYTES, S_LONGVARBINARY, typeof(System.Byte[]), NativeDBType.BYTES, DbType.Binary ); // 19
|
||||
static private readonly NativeDBType D_LongVarChar = new NativeDBType(0xff, -1, false, true, OleDbType.LongVarChar, NativeDBType.STR, S_LONGVARCHAR, typeof(System.String), NativeDBType.WSTR/*STR*/, DbType.AnsiString); // 20 - (ansi pointer)
|
||||
static private readonly NativeDBType D_Numeric = new NativeDBType( 28, 19, true, false, OleDbType.Numeric, NativeDBType.NUMERIC, S_NUMERIC, typeof(System.Decimal), NativeDBType.NUMERIC, DbType.Decimal ); // 21 - (tagDB_Numeric)
|
||||
static private readonly NativeDBType D_PropVariant = new NativeDBType(0xff, NativeOledbWrapper.SizeOfPROPVARIANT,
|
||||
true, false, OleDbType.PropVariant, NativeDBType.PROPVARIANT, S_PROPVARIANT, typeof(System.Object), NativeDBType.VARIANT, DbType.Object ); // 22
|
||||
static private readonly NativeDBType D_Single = new NativeDBType( 7, 4, true, false, OleDbType.Single, NativeDBType.R4, S_R4, typeof(System.Single), NativeDBType.R4, DbType.Single ); // 23 - single
|
||||
static private readonly NativeDBType D_Double = new NativeDBType( 15, 8, true, false, OleDbType.Double, NativeDBType.R8, S_R8, typeof(System.Double), NativeDBType.R8, DbType.Double ); // 24 - double
|
||||
static private readonly NativeDBType D_UnsignedTinyInt = new NativeDBType( 3, 1, true, false, OleDbType.UnsignedTinyInt, NativeDBType.UI1, S_UI1, typeof(System.Byte), NativeDBType.UI1, DbType.Byte ); // 25 - byte7
|
||||
static private readonly NativeDBType D_UnsignedSmallInt = new NativeDBType( 5, 2, true, false, OleDbType.UnsignedSmallInt, NativeDBType.UI2, S_UI2, typeof(System.Int32), NativeDBType.UI2, DbType.UInt16 ); // 26 - unsigned integer2
|
||||
static private readonly NativeDBType D_UnsignedInt = new NativeDBType( 10, 4, true, false, OleDbType.UnsignedInt, NativeDBType.UI4, S_UI4, typeof(System.Int64), NativeDBType.UI4, DbType.UInt32 ); // 27 - unsigned integer4
|
||||
static private readonly NativeDBType D_UnsignedBigInt = new NativeDBType( 20, 8, true, false, OleDbType.UnsignedBigInt, NativeDBType.UI8, S_UI8, typeof(System.Decimal), NativeDBType.UI8, DbType.UInt64 ); // 28 - unsigned integer8
|
||||
static private readonly NativeDBType D_VarBinary = new NativeDBType(0xff, -1, false, false, OleDbType.VarBinary, NativeDBType.BYTES, S_VARBINARY, typeof(System.Byte[]), NativeDBType.BYTES, DbType.Binary ); // 29
|
||||
static private readonly NativeDBType D_VarChar = new NativeDBType(0xff, -1, false, false, OleDbType.VarChar, NativeDBType.STR, S_VARCHAR, typeof(System.String), NativeDBType.WSTR/*STR*/, DbType.AnsiString); // 30 - (ansi pointer)
|
||||
static private readonly NativeDBType D_Variant = new NativeDBType(0xff, ODB.SizeOf_Variant, true, false, OleDbType.Variant, NativeDBType.VARIANT, S_VARIANT, typeof(System.Object), NativeDBType.VARIANT, DbType.Object ); // 31 - ubyte[16] (variant)
|
||||
static private readonly NativeDBType D_VarNumeric = new NativeDBType( 255, 16, true, false, OleDbType.VarNumeric, NativeDBType.VARNUMERIC, S_VARNUMERIC, typeof(System.Decimal), NativeDBType.DECIMAL, DbType.VarNumeric); // 32 - (unicode pointer)
|
||||
static private readonly NativeDBType D_WChar = new NativeDBType(0xff, -1, true, false, OleDbType.WChar, NativeDBType.WSTR, S_WCHAR, typeof(System.String), NativeDBType.WSTR, DbType.StringFixedLength); // 33 - (unicode pointer)
|
||||
static private readonly NativeDBType D_VarWChar = new NativeDBType(0xff, -1, false, false, OleDbType.VarWChar, NativeDBType.WSTR, S_WVARCHAR, typeof(System.String), NativeDBType.WSTR, DbType.String ); // 34 - (unicode pointer)
|
||||
static private readonly NativeDBType D_LongVarWChar = new NativeDBType(0xff, -1, false, true, OleDbType.LongVarWChar, NativeDBType.WSTR, S_WLONGVARCHAR, typeof(System.String), NativeDBType.WSTR, DbType.String ); // 35 - (unicode pointer)
|
||||
static private readonly NativeDBType D_Chapter = new NativeDBType(0xff, ADP.PtrSize, false, false, OleDbType.Empty, NativeDBType.HCHAPTER, S_UDT, typeof(IDataReader), NativeDBType.HCHAPTER, DbType.Object ); // 36 - (hierarchical chaper)
|
||||
static private readonly NativeDBType D_Empty = new NativeDBType(0xff, 0, false, false, OleDbType.Empty, NativeDBType.EMPTY, "", null, NativeDBType.EMPTY, DbType.Object ); // 37 - invalid param default
|
||||
static private readonly NativeDBType D_Xml = new NativeDBType(0xff, -1, false, false, OleDbType.VarWChar, NativeDBType.XML, S_XML, typeof(System.String), NativeDBType.WSTR, DbType.String ); // 38 - (unicode pointer)
|
||||
static private readonly NativeDBType D_Udt = new NativeDBType(0xff, -1, false, false, OleDbType.VarBinary, NativeDBType.UDT, S_BINARY, typeof(System.Byte[]), NativeDBType.BYTES, DbType.Binary ); // 39 - (unicode pointer)
|
||||
|
||||
static internal readonly NativeDBType Default = D_VarWChar; // MDAC 65324
|
||||
static internal readonly Byte MaximumDecimalPrecision = D_Decimal.maxpre;
|
||||
|
||||
private const int FixedDbPart = /*DBPART_VALUE*/0x1 | /*DBPART_STATUS*/0x4;
|
||||
private const int VarblDbPart = /*DBPART_VALUE*/0x1 | /*DBPART_LENGTH*/0x2 | /*DBPART_STATUS*/0x4;
|
||||
|
||||
internal readonly OleDbType enumOleDbType; // enum System.Data.OleDb.OleDbType
|
||||
internal readonly DbType enumDbType; // enum System.Data.DbType
|
||||
internal readonly short dbType; // OLE DB DBTYPE_
|
||||
internal readonly short wType; // OLE DB DBTYPE_ we ask OleDB Provider to bind as
|
||||
internal readonly Type dataType; // CLR Type
|
||||
|
||||
internal readonly int dbPart; // the DBPart w or w/out length
|
||||
internal readonly bool isfixed; // IsFixedLength
|
||||
internal readonly bool islong; // IsLongLength
|
||||
internal readonly Byte maxpre; // maxium precision for numeric types // $
|
||||
internal readonly int fixlen; // fixed length size in bytes (-1 for variable)
|
||||
|
||||
internal readonly String dataSourceType; // ICommandWithParameters.SetParameterInfo standard type name
|
||||
internal readonly StringMemHandle dbString; // ptr to native allocated memory for dataSourceType string
|
||||
|
||||
private NativeDBType(Byte maxpre, int fixlen, bool isfixed, bool islong, OleDbType enumOleDbType, short dbType, string dbstring, Type dataType, short wType, DbType enumDbType) {
|
||||
this.enumOleDbType = enumOleDbType;
|
||||
this.dbType = dbType;
|
||||
this.dbPart = (-1 == fixlen) ? VarblDbPart : FixedDbPart;
|
||||
this.isfixed = isfixed;
|
||||
this.islong = islong;
|
||||
this.maxpre = maxpre;
|
||||
this.fixlen = fixlen;
|
||||
this.wType = wType;
|
||||
this.dataSourceType = dbstring;
|
||||
this.dbString = new StringMemHandle(dbstring);
|
||||
this.dataType = dataType;
|
||||
this.enumDbType = enumDbType;
|
||||
}
|
||||
|
||||
internal bool IsVariableLength {
|
||||
get {
|
||||
return (-1 == fixlen);
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
override public string ToString() {
|
||||
return enumOleDbType.ToString();
|
||||
}
|
||||
#endif
|
||||
|
||||
static internal NativeDBType FromDataType(OleDbType enumOleDbType) {
|
||||
switch(enumOleDbType) { // @perfnote: Enum.IsDefined
|
||||
case OleDbType.Empty: return D_Empty; // 0
|
||||
case OleDbType.SmallInt: return D_SmallInt; // 2
|
||||
case OleDbType.Integer: return D_Integer; // 3
|
||||
case OleDbType.Single: return D_Single; // 4
|
||||
case OleDbType.Double: return D_Double; // 5
|
||||
case OleDbType.Currency: return D_Currency; // 6
|
||||
case OleDbType.Date: return D_Date; // 7
|
||||
case OleDbType.BSTR: return D_BSTR; // 8
|
||||
case OleDbType.IDispatch: return D_IDispatch; // 9
|
||||
case OleDbType.Error: return D_Error; // 10
|
||||
case OleDbType.Boolean: return D_Boolean; // 11
|
||||
case OleDbType.Variant: return D_Variant; // 12
|
||||
case OleDbType.IUnknown: return D_IUnknown; // 13
|
||||
case OleDbType.Decimal: return D_Decimal; // 14
|
||||
case OleDbType.TinyInt: return D_TinyInt; // 16
|
||||
case OleDbType.UnsignedTinyInt: return D_UnsignedTinyInt; // 17
|
||||
case OleDbType.UnsignedSmallInt: return D_UnsignedSmallInt; // 18
|
||||
case OleDbType.UnsignedInt: return D_UnsignedInt; // 19
|
||||
case OleDbType.BigInt: return D_BigInt; // 20
|
||||
case OleDbType.UnsignedBigInt: return D_UnsignedBigInt; // 21
|
||||
case OleDbType.Filetime: return D_Filetime; // 64
|
||||
case OleDbType.Guid: return D_Guid; // 72
|
||||
case OleDbType.Binary: return D_Binary; // 128
|
||||
case OleDbType.Char: return D_Char; // 129
|
||||
case OleDbType.WChar: return D_WChar; // 130
|
||||
case OleDbType.Numeric: return D_Numeric; // 131
|
||||
case OleDbType.DBDate: return D_DBDate; // 133
|
||||
case OleDbType.DBTime: return D_DBTime; // 134
|
||||
case OleDbType.DBTimeStamp: return D_DBTimeStamp; // 135
|
||||
case OleDbType.PropVariant: return D_PropVariant; // 138
|
||||
case OleDbType.VarNumeric: return D_VarNumeric; // 139
|
||||
case OleDbType.VarChar: return D_VarChar; // 200
|
||||
case OleDbType.LongVarChar: return D_LongVarChar; // 201
|
||||
case OleDbType.VarWChar: return D_VarWChar; // 202 // MDAC 64983: ORA-12704: character set mismatch
|
||||
case OleDbType.LongVarWChar: return D_LongVarWChar; // 203
|
||||
case OleDbType.VarBinary: return D_VarBinary; // 204
|
||||
case OleDbType.LongVarBinary: return D_LongVarBinary; // 205
|
||||
default:
|
||||
throw ODB.InvalidOleDbType(enumOleDbType);
|
||||
}
|
||||
}
|
||||
|
||||
static internal NativeDBType FromSystemType(object value) {
|
||||
IConvertible ic = (value as IConvertible);
|
||||
if (null != ic) {
|
||||
switch(ic.GetTypeCode()) {
|
||||
case TypeCode.Empty: return NativeDBType.D_Empty;
|
||||
case TypeCode.Object: return NativeDBType.D_Variant;
|
||||
case TypeCode.DBNull: throw ADP.InvalidDataType(TypeCode.DBNull);
|
||||
case TypeCode.Boolean: return NativeDBType.D_Boolean;
|
||||
case TypeCode.Char: return NativeDBType.D_Char;
|
||||
case TypeCode.SByte: return NativeDBType.D_TinyInt;
|
||||
case TypeCode.Byte: return NativeDBType.D_UnsignedTinyInt;
|
||||
case TypeCode.Int16: return NativeDBType.D_SmallInt;
|
||||
case TypeCode.UInt16: return NativeDBType.D_UnsignedSmallInt;
|
||||
case TypeCode.Int32: return NativeDBType.D_Integer;
|
||||
case TypeCode.UInt32: return NativeDBType.D_UnsignedInt;
|
||||
case TypeCode.Int64: return NativeDBType.D_BigInt;
|
||||
case TypeCode.UInt64: return NativeDBType.D_UnsignedBigInt;
|
||||
case TypeCode.Single: return NativeDBType.D_Single;
|
||||
case TypeCode.Double: return NativeDBType.D_Double;
|
||||
case TypeCode.Decimal: return NativeDBType.D_Decimal;
|
||||
case TypeCode.DateTime: return NativeDBType.D_DBTimeStamp;
|
||||
case TypeCode.String: return NativeDBType.D_VarWChar;
|
||||
default: throw ADP.UnknownDataTypeCode(value.GetType(), ic.GetTypeCode());
|
||||
}
|
||||
}
|
||||
else if (value is System.Byte[]) {
|
||||
return NativeDBType.D_VarBinary;
|
||||
}
|
||||
else if (value is System.Guid) {
|
||||
return NativeDBType.D_Guid;
|
||||
}
|
||||
else if (value is System.TimeSpan) {
|
||||
return NativeDBType.D_DBTime;
|
||||
}
|
||||
else {
|
||||
return NativeDBType.D_Variant;
|
||||
}
|
||||
//throw ADP.UnknownDataType(value.GetType());
|
||||
}
|
||||
|
||||
static internal NativeDBType FromDbType(DbType dbType) {
|
||||
switch(dbType) {
|
||||
case DbType.AnsiString: return D_VarChar;
|
||||
case DbType.AnsiStringFixedLength: return D_Char;
|
||||
case DbType.Binary: return D_VarBinary;
|
||||
case DbType.Byte: return D_UnsignedTinyInt;
|
||||
case DbType.Boolean: return D_Boolean;
|
||||
case DbType.Currency: return D_Currency;
|
||||
case DbType.Date: return D_DBDate;
|
||||
case DbType.DateTime: return D_DBTimeStamp;
|
||||
case DbType.Decimal: return D_Decimal;
|
||||
case DbType.Double: return D_Double;
|
||||
case DbType.Guid: return D_Guid;
|
||||
case DbType.Int16: return D_SmallInt;
|
||||
case DbType.Int32: return D_Integer;
|
||||
case DbType.Int64: return D_BigInt;
|
||||
case DbType.Object: return D_Variant;
|
||||
case DbType.SByte: return D_TinyInt;
|
||||
case DbType.Single: return D_Single;
|
||||
case DbType.String: return D_VarWChar;
|
||||
case DbType.StringFixedLength: return D_WChar;
|
||||
case DbType.Time: return D_DBTime;
|
||||
case DbType.UInt16: return D_UnsignedSmallInt;
|
||||
case DbType.UInt32: return D_UnsignedInt;
|
||||
case DbType.UInt64: return D_UnsignedBigInt;
|
||||
case DbType.VarNumeric: return D_VarNumeric;
|
||||
case DbType.Xml: return D_Xml;
|
||||
default:
|
||||
throw ADP.DbTypeNotSupported(dbType, typeof(OleDbType)); // MDAC 66009
|
||||
}
|
||||
}
|
||||
|
||||
static internal NativeDBType FromDBType(short dbType, bool isLong, bool isFixed) {
|
||||
switch(dbType) {
|
||||
//case EMPTY:
|
||||
//case NULL:
|
||||
case I2: return D_SmallInt;
|
||||
case I4: return D_Integer;
|
||||
case R4: return D_Single;
|
||||
case R8: return D_Double;
|
||||
case CY: return D_Currency;
|
||||
case DATE: return D_Date;
|
||||
case BSTR: return D_BSTR;
|
||||
case IDISPATCH: return D_IDispatch;
|
||||
case ERROR: return D_Error;
|
||||
case BOOL: return D_Boolean;
|
||||
case VARIANT: return D_Variant;
|
||||
case IUNKNOWN: return D_IUnknown;
|
||||
case DECIMAL: return D_Decimal;
|
||||
case I1: return D_TinyInt;
|
||||
case UI1: return D_UnsignedTinyInt;
|
||||
case UI2: return D_UnsignedSmallInt;
|
||||
case UI4: return D_UnsignedInt;
|
||||
case I8: return D_BigInt;
|
||||
case UI8: return D_UnsignedBigInt;
|
||||
case FILETIME: return D_Filetime;
|
||||
case GUID: return D_Guid;
|
||||
case BYTES: return (isLong) ? D_LongVarBinary : (isFixed) ? D_Binary : D_VarBinary;
|
||||
case STR: return (isLong) ? D_LongVarChar : (isFixed) ? D_Char : D_VarChar;
|
||||
case WSTR: return (isLong) ? D_LongVarWChar : (isFixed) ? D_WChar : D_VarWChar;
|
||||
case NUMERIC: return D_Numeric;
|
||||
//case UDT:
|
||||
case DBDATE: return D_DBDate;
|
||||
case DBTIME: return D_DBTime;
|
||||
case DBTIMESTAMP: return D_DBTimeStamp;
|
||||
case HCHAPTER: return D_Chapter;
|
||||
case PROPVARIANT: return D_PropVariant;
|
||||
case VARNUMERIC: return D_VarNumeric;
|
||||
case XML: return D_Xml;
|
||||
case UDT: return D_Udt;
|
||||
//case VECTOR:
|
||||
//case ARRAY:
|
||||
//case BYREF:
|
||||
//case RESERVED:
|
||||
default:
|
||||
if (0 != (NativeDBType.VECTOR & dbType)) {
|
||||
throw ODB.DBBindingGetVector();
|
||||
}
|
||||
return D_Variant; // MDAC 72067
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,403 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbCommandBuilder.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.ProviderBase;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
public sealed class OleDbCommandBuilder : DbCommandBuilder {
|
||||
|
||||
public OleDbCommandBuilder() : base() {
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public OleDbCommandBuilder(OleDbDataAdapter adapter) : this() {
|
||||
DataAdapter = adapter;
|
||||
}
|
||||
|
||||
[
|
||||
DefaultValue(null),
|
||||
ResCategoryAttribute(Res.DataCategory_Update),
|
||||
ResDescriptionAttribute(Res.OleDbCommandBuilder_DataAdapter), // MDAC 60524
|
||||
]
|
||||
new public OleDbDataAdapter DataAdapter {
|
||||
get {
|
||||
return (base.DataAdapter as OleDbDataAdapter);
|
||||
}
|
||||
set {
|
||||
base.DataAdapter = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void OleDbRowUpdatingHandler(object sender, OleDbRowUpdatingEventArgs ruevent) {
|
||||
RowUpdatingHandler(ruevent);
|
||||
}
|
||||
|
||||
new public OleDbCommand GetInsertCommand() {
|
||||
return (OleDbCommand) base.GetInsertCommand();
|
||||
}
|
||||
new public OleDbCommand GetInsertCommand(bool useColumnsForParameterNames) {
|
||||
return (OleDbCommand) base.GetInsertCommand(useColumnsForParameterNames);
|
||||
}
|
||||
|
||||
new public OleDbCommand GetUpdateCommand() {
|
||||
return (OleDbCommand) base.GetUpdateCommand();
|
||||
}
|
||||
new public OleDbCommand GetUpdateCommand(bool useColumnsForParameterNames) {
|
||||
return (OleDbCommand) base.GetUpdateCommand(useColumnsForParameterNames);
|
||||
}
|
||||
|
||||
new public OleDbCommand GetDeleteCommand() {
|
||||
return (OleDbCommand) base.GetDeleteCommand();
|
||||
}
|
||||
new public OleDbCommand GetDeleteCommand(bool useColumnsForParameterNames) {
|
||||
return (OleDbCommand) base.GetDeleteCommand(useColumnsForParameterNames);
|
||||
}
|
||||
|
||||
override protected string GetParameterName(int parameterOrdinal) {
|
||||
return "p" + parameterOrdinal.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
override protected string GetParameterName(string parameterName) {
|
||||
return parameterName;
|
||||
}
|
||||
|
||||
override protected string GetParameterPlaceholder(int parameterOrdinal) {
|
||||
return "?";
|
||||
}
|
||||
|
||||
override protected void ApplyParameterInfo(DbParameter parameter, DataRow datarow, StatementType statementType, bool whereClause) {
|
||||
OleDbParameter p = (OleDbParameter) parameter;
|
||||
object valueType = datarow[SchemaTableColumn.ProviderType];
|
||||
p.OleDbType = (OleDbType) valueType;
|
||||
|
||||
object bvalue = datarow[SchemaTableColumn.NumericPrecision];
|
||||
if (DBNull.Value != bvalue) {
|
||||
byte bval = (byte)(short)bvalue;
|
||||
p.PrecisionInternal = ((0xff != bval) ? bval : (byte)0);
|
||||
}
|
||||
|
||||
bvalue = datarow[SchemaTableColumn.NumericScale];
|
||||
if (DBNull.Value != bvalue) {
|
||||
byte bval = (byte)(short)bvalue;
|
||||
p.ScaleInternal = ((0xff != bval) ? bval : (byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
static public void DeriveParameters(OleDbCommand command) { // MDAC 65927
|
||||
OleDbConnection.ExecutePermission.Demand();
|
||||
|
||||
if (null == command) {
|
||||
throw ADP.ArgumentNull("command");
|
||||
}
|
||||
switch (command.CommandType) {
|
||||
case System.Data.CommandType.Text:
|
||||
throw ADP.DeriveParametersNotSupported(command);
|
||||
case System.Data.CommandType.StoredProcedure:
|
||||
break;
|
||||
case System.Data.CommandType.TableDirect:
|
||||
// CommandType.TableDirect - do nothing, parameters are not supported
|
||||
throw ADP.DeriveParametersNotSupported(command);
|
||||
default:
|
||||
throw ADP.InvalidCommandType(command.CommandType);
|
||||
}
|
||||
if (ADP.IsEmpty(command.CommandText)) {
|
||||
throw ADP.CommandTextRequired(ADP.DeriveParameters);
|
||||
}
|
||||
OleDbConnection connection = command.Connection;
|
||||
if (null == connection) {
|
||||
throw ADP.ConnectionRequired(ADP.DeriveParameters);
|
||||
}
|
||||
ConnectionState state = connection.State;
|
||||
if (ConnectionState.Open != state) {
|
||||
throw ADP.OpenConnectionRequired(ADP.DeriveParameters, state);
|
||||
}
|
||||
OleDbParameter[] list = DeriveParametersFromStoredProcedure(connection, command);
|
||||
|
||||
OleDbParameterCollection parameters = command.Parameters;
|
||||
parameters.Clear();
|
||||
|
||||
for(int i = 0; i < list.Length; ++i) {
|
||||
parameters.Add(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// known difference: when getting the parameters for a sproc, the
|
||||
// return value gets marked as a return value but for a sql stmt
|
||||
// the return value gets marked as an output parameter.
|
||||
static private OleDbParameter[] DeriveParametersFromStoredProcedure(OleDbConnection connection, OleDbCommand command) {
|
||||
OleDbParameter[] plist = new OleDbParameter[0];
|
||||
|
||||
if (connection.SupportSchemaRowset(OleDbSchemaGuid.Procedure_Parameters)) {
|
||||
string quotePrefix, quoteSuffix;
|
||||
connection.GetLiteralQuotes(ADP.DeriveParameters, out quotePrefix, out quoteSuffix);
|
||||
|
||||
Object[] parsed = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quotePrefix, quoteSuffix, '.', 4, true, Res.OLEDB_OLEDBCommandText, false); // MDAC 70930
|
||||
if (null == parsed[3]) {
|
||||
throw ADP.NoStoredProcedureExists(command.CommandText);
|
||||
}
|
||||
|
||||
Object[] restrictions = new object[4];
|
||||
object value;
|
||||
|
||||
// Parse returns an enforced 4 part array
|
||||
// 0) Server - ignored but removal would be a run-time breaking change from V1.0
|
||||
// 1) Catalog
|
||||
// 2) Schema
|
||||
// 3) ProcedureName
|
||||
|
||||
// Restrictions array which is passed to OleDb API expects:
|
||||
// 0) Catalog
|
||||
// 1) Schema
|
||||
// 2) ProcedureName
|
||||
// 3) ParameterName (leave null)
|
||||
|
||||
// Copy from Parse format to OleDb API format
|
||||
Array.Copy(parsed, 1, restrictions, 0, 3);
|
||||
|
||||
//if (cmdConnection.IsServer_msdaora) {
|
||||
// restrictions[1] = Convert.ToString(cmdConnection.UserId).ToUpper();
|
||||
//}
|
||||
DataTable table = connection.GetSchemaRowset(OleDbSchemaGuid.Procedure_Parameters, restrictions);
|
||||
|
||||
if (null != table) {
|
||||
DataColumnCollection columns = table.Columns;
|
||||
|
||||
DataColumn parameterName = null;
|
||||
DataColumn parameterDirection = null;
|
||||
DataColumn dataType = null;
|
||||
DataColumn maxLen = null;
|
||||
DataColumn numericPrecision = null;
|
||||
DataColumn numericScale = null;
|
||||
DataColumn backendtype = null;
|
||||
|
||||
int index = columns.IndexOf(ODB.PARAMETER_NAME);
|
||||
if (-1 != index) parameterName = columns[index];
|
||||
|
||||
index = columns.IndexOf(ODB.PARAMETER_TYPE);
|
||||
if (-1 != index) parameterDirection = columns[index];
|
||||
|
||||
index = columns.IndexOf(ODB.DATA_TYPE);
|
||||
if (-1 != index) dataType = columns[index];
|
||||
|
||||
index = columns.IndexOf(ODB.CHARACTER_MAXIMUM_LENGTH);
|
||||
if (-1 != index) maxLen = columns[index];
|
||||
|
||||
index = columns.IndexOf(ODB.NUMERIC_PRECISION);
|
||||
if (-1 != index) numericPrecision = columns[index];
|
||||
|
||||
index = columns.IndexOf(ODB.NUMERIC_SCALE);
|
||||
if (-1 != index) numericScale = columns[index];
|
||||
|
||||
index = columns.IndexOf(ODB.TYPE_NAME); // MDAC 72315
|
||||
if (-1 != index) backendtype = columns[index];
|
||||
|
||||
DataRow[] dataRows = table.Select(null, ODB.ORDINAL_POSITION_ASC, DataViewRowState.CurrentRows); // MDAC 70928
|
||||
plist = new OleDbParameter[dataRows.Length];
|
||||
for(index = 0; index < dataRows.Length; ++index) {
|
||||
DataRow dataRow = dataRows[index];
|
||||
|
||||
OleDbParameter parameter = new OleDbParameter();
|
||||
|
||||
if ((null != parameterName) && !dataRow.IsNull(parameterName, DataRowVersion.Default)) {
|
||||
// $
|
||||
parameter.ParameterName = Convert.ToString(dataRow[parameterName, DataRowVersion.Default], CultureInfo.InvariantCulture).TrimStart(new char[] { '@', ' ', ':'});
|
||||
}
|
||||
if ((null != parameterDirection) && !dataRow.IsNull(parameterDirection, DataRowVersion.Default)) {
|
||||
short direction = Convert.ToInt16(dataRow[parameterDirection, DataRowVersion.Default], CultureInfo.InvariantCulture);
|
||||
parameter.Direction = ConvertToParameterDirection(direction);
|
||||
}
|
||||
if ((null != dataType) && !dataRow.IsNull(dataType, DataRowVersion.Default)) {
|
||||
// need to ping FromDBType, otherwise WChar->WChar when the user really wants VarWChar
|
||||
short wType = Convert.ToInt16(dataRow[dataType, DataRowVersion.Default], CultureInfo.InvariantCulture);
|
||||
parameter.OleDbType = NativeDBType.FromDBType(wType, false, false).enumOleDbType;
|
||||
}
|
||||
if ((null != maxLen) && !dataRow.IsNull(maxLen, DataRowVersion.Default)) {
|
||||
parameter.Size = Convert.ToInt32(dataRow[maxLen, DataRowVersion.Default], CultureInfo.InvariantCulture);
|
||||
}
|
||||
switch(parameter.OleDbType) {
|
||||
case OleDbType.Decimal:
|
||||
case OleDbType.Numeric:
|
||||
case OleDbType.VarNumeric:
|
||||
if ((null != numericPrecision) && !dataRow.IsNull(numericPrecision, DataRowVersion.Default)) {
|
||||
// @devnote: unguarded cast from Int16 to Byte
|
||||
parameter.PrecisionInternal = (Byte) Convert.ToInt16(dataRow[numericPrecision], CultureInfo.InvariantCulture);
|
||||
}
|
||||
if ((null != numericScale) && !dataRow.IsNull(numericScale, DataRowVersion.Default)) {
|
||||
// @devnote: unguarded cast from Int16 to Byte
|
||||
parameter.ScaleInternal = (Byte) Convert.ToInt16(dataRow[numericScale], CultureInfo.InvariantCulture);
|
||||
}
|
||||
break;
|
||||
case OleDbType.VarBinary: // MDAC 72315
|
||||
case OleDbType.VarChar:
|
||||
case OleDbType.VarWChar:
|
||||
value = dataRow[backendtype, DataRowVersion.Default];
|
||||
if (value is string) {
|
||||
string backendtypename = ((string) value).ToLower(CultureInfo.InvariantCulture);
|
||||
switch(backendtypename) {
|
||||
case "binary":
|
||||
parameter.OleDbType = OleDbType.Binary;
|
||||
break;
|
||||
//case "varbinary":
|
||||
// parameter.OleDbType = OleDbType.VarBinary;
|
||||
// break;
|
||||
case "image":
|
||||
parameter.OleDbType = OleDbType.LongVarBinary;
|
||||
break;
|
||||
case "char":
|
||||
parameter.OleDbType = OleDbType.Char;
|
||||
break;
|
||||
//case "varchar":
|
||||
//case "varchar2":
|
||||
// parameter.OleDbType = OleDbType.VarChar;
|
||||
// break;
|
||||
case "text":
|
||||
parameter.OleDbType = OleDbType.LongVarChar;
|
||||
break;
|
||||
case "nchar":
|
||||
parameter.OleDbType = OleDbType.WChar;
|
||||
break;
|
||||
//case "nvarchar":
|
||||
// parameter.OleDbType = OleDbType.VarWChar;
|
||||
case "ntext":
|
||||
parameter.OleDbType = OleDbType.LongVarWChar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
//if (AdapterSwitches.OleDbSql.TraceVerbose) {
|
||||
// ADP.Trace_Parameter("StoredProcedure", parameter);
|
||||
//}
|
||||
plist[index] = parameter;
|
||||
}
|
||||
}
|
||||
if ((0 == plist.Length) && connection.SupportSchemaRowset(OleDbSchemaGuid.Procedures)) {
|
||||
restrictions = new Object[4] { null, null, command.CommandText, null};
|
||||
table = connection.GetSchemaRowset(OleDbSchemaGuid.Procedures, restrictions);
|
||||
if (0 == table.Rows.Count) {
|
||||
throw ADP.NoStoredProcedureExists(command.CommandText);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (connection.SupportSchemaRowset(OleDbSchemaGuid.Procedures)) {
|
||||
Object[] restrictions = new Object[4] { null, null, command.CommandText, null};
|
||||
DataTable table = connection.GetSchemaRowset(OleDbSchemaGuid.Procedures, restrictions);
|
||||
if (0 == table.Rows.Count) {
|
||||
throw ADP.NoStoredProcedureExists(command.CommandText);
|
||||
}
|
||||
// we don't ever expect a procedure with 0 parameters, they should have at least a return value
|
||||
throw ODB.NoProviderSupportForSProcResetParameters(connection.Provider); // MDAC 71968
|
||||
}
|
||||
else {
|
||||
throw ODB.NoProviderSupportForSProcResetParameters(connection.Provider); // MDAC 70918
|
||||
}
|
||||
return plist;
|
||||
}
|
||||
|
||||
static private ParameterDirection ConvertToParameterDirection(int value) {
|
||||
switch (value) {
|
||||
case ODB.DBPARAMTYPE_INPUT:
|
||||
return System.Data.ParameterDirection.Input;
|
||||
case ODB.DBPARAMTYPE_INPUTOUTPUT:
|
||||
return System.Data.ParameterDirection.InputOutput;
|
||||
case ODB.DBPARAMTYPE_OUTPUT:
|
||||
return System.Data.ParameterDirection.Output;
|
||||
case ODB.DBPARAMTYPE_RETURNVALUE:
|
||||
return System.Data.ParameterDirection.ReturnValue;
|
||||
default:
|
||||
return System.Data.ParameterDirection.Input;
|
||||
}
|
||||
}
|
||||
|
||||
public override string QuoteIdentifier(string unquotedIdentifier){
|
||||
return QuoteIdentifier(unquotedIdentifier, null /* use DataAdapter.SelectCommand.Connection if available */);
|
||||
}
|
||||
public string QuoteIdentifier( string unquotedIdentifier, OleDbConnection connection){
|
||||
ADP.CheckArgumentNull(unquotedIdentifier, "unquotedIdentifier");
|
||||
|
||||
// if the user has specificed a prefix use the user specified prefix and suffix
|
||||
// otherwise get them from the provider
|
||||
string quotePrefix = QuotePrefix;
|
||||
string quoteSuffix = QuoteSuffix;
|
||||
if (ADP.IsEmpty(quotePrefix) == true) {
|
||||
if (connection == null) {
|
||||
// VSTFDEVDIV 479567: use the adapter's connection if QuoteIdentifier was called from
|
||||
// DbCommandBuilder instance (which does not have an overload that gets connection object)
|
||||
connection = base.GetConnection() as OleDbConnection;
|
||||
if (connection == null) {
|
||||
throw ADP.QuotePrefixNotSet(ADP.QuoteIdentifier);
|
||||
}
|
||||
}
|
||||
connection.GetLiteralQuotes(ADP.QuoteIdentifier, out quotePrefix, out quoteSuffix);
|
||||
// if the quote suffix is null assume that it is the same as the prefix (See OLEDB spec
|
||||
// IDBInfo::GetLiteralInfo DBLITERAL_QUOTE_SUFFIX.)
|
||||
if (quoteSuffix == null) {
|
||||
quoteSuffix = quotePrefix;
|
||||
}
|
||||
}
|
||||
|
||||
return ADP.BuildQuotedString(quotePrefix,quoteSuffix,unquotedIdentifier);
|
||||
}
|
||||
|
||||
override protected void SetRowUpdatingHandler(DbDataAdapter adapter) {
|
||||
Debug.Assert(adapter is OleDbDataAdapter, "!OleDbDataAdapter");
|
||||
if (adapter == base.DataAdapter) { // removal case
|
||||
((OleDbDataAdapter)adapter).RowUpdating -= OleDbRowUpdatingHandler;
|
||||
}
|
||||
else { // adding case
|
||||
((OleDbDataAdapter)adapter).RowUpdating += OleDbRowUpdatingHandler;
|
||||
}
|
||||
}
|
||||
|
||||
public override string UnquoteIdentifier( string quotedIdentifier){
|
||||
return UnquoteIdentifier(quotedIdentifier, null /* use DataAdapter.SelectCommand.Connection if available */);
|
||||
}
|
||||
|
||||
public string UnquoteIdentifier(string quotedIdentifier, OleDbConnection connection){
|
||||
|
||||
ADP.CheckArgumentNull(quotedIdentifier, "quotedIdentifier");
|
||||
|
||||
|
||||
// if the user has specificed a prefix use the user specified prefix and suffix
|
||||
// otherwise get them from the provider
|
||||
string quotePrefix = QuotePrefix;
|
||||
string quoteSuffix = QuoteSuffix;
|
||||
if (ADP.IsEmpty(quotePrefix) == true) {
|
||||
if (connection == null) {
|
||||
// VSTFDEVDIV 479567: use the adapter's connection if UnquoteIdentifier was called from
|
||||
// DbCommandBuilder instance (which does not have an overload that gets connection object)
|
||||
connection = base.GetConnection() as OleDbConnection;
|
||||
if (connection == null) {
|
||||
throw ADP.QuotePrefixNotSet(ADP.UnquoteIdentifier);
|
||||
}
|
||||
}
|
||||
connection.GetLiteralQuotes(ADP.UnquoteIdentifier, out quotePrefix, out quoteSuffix);
|
||||
// if the quote suffix is null assume that it is the same as the prefix (See OLEDB spec
|
||||
// IDBInfo::GetLiteralInfo DBLITERAL_QUOTE_SUFFIX.)
|
||||
if (quoteSuffix == null) {
|
||||
quoteSuffix = quotePrefix;
|
||||
}
|
||||
}
|
||||
|
||||
String unquotedIdentifier;
|
||||
// ignoring the return value because it is acceptable for the quotedString to not be quoted in this
|
||||
// context.
|
||||
ADP.RemoveStringQuotes(quotePrefix, quoteSuffix, quotedIdentifier, out unquotedIdentifier);
|
||||
return unquotedIdentifier;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,179 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbConnectionFactory.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb
|
||||
{
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Data.ProviderBase;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
sealed internal class OleDbConnectionFactory : DbConnectionFactory {
|
||||
private OleDbConnectionFactory() : base() {}
|
||||
// At this time, the OleDb Managed Provider doesn't have any connection pool
|
||||
// counters because we'd only confuse people with "non-pooled" connections
|
||||
// that are actually being pooled by the native pooler.
|
||||
|
||||
private const string _metaDataXml = ":MetaDataXml";
|
||||
private const string _defaultMetaDataXml = "defaultMetaDataXml";
|
||||
|
||||
public static readonly OleDbConnectionFactory SingletonInstance = new OleDbConnectionFactory();
|
||||
|
||||
override public DbProviderFactory ProviderFactory {
|
||||
get {
|
||||
return OleDbFactory.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) {
|
||||
DbConnectionInternal result = new OleDbConnectionInternal((OleDbConnectionString)options, (OleDbConnection)owningObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous) {
|
||||
Debug.Assert(!ADP.IsEmpty(connectionString), "null connectionString");
|
||||
OleDbConnectionString result = new OleDbConnectionString(connectionString, (null != previous));
|
||||
return result;
|
||||
}
|
||||
|
||||
// SxS (VSDD 545786): metadata files are opened from <.NetRuntimeFolder>\CONFIG\<metadatafilename.xml>
|
||||
// this operation is safe in SxS because the file is opened in read-only mode and each NDP runtime accesses its own copy of the metadata
|
||||
// under the runtime folder.
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
|
||||
override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory){
|
||||
|
||||
Debug.Assert (internalConnection != null,"internalConnection may not be null.");
|
||||
cacheMetaDataFactory = false;
|
||||
|
||||
|
||||
OleDbConnectionInternal oleDbInternalConnection = (OleDbConnectionInternal) internalConnection;
|
||||
OleDbConnection oleDbOuterConnection = oleDbInternalConnection.Connection;
|
||||
Debug.Assert(oleDbOuterConnection != null,"outer connection may not be null.");
|
||||
|
||||
NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.oledb");
|
||||
Stream XMLStream =null;
|
||||
String providerFileName = oleDbOuterConnection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo,ODB.DBPROP_PROVIDERFILENAME) as string;
|
||||
|
||||
if (settings != null){
|
||||
|
||||
string [] values = null;
|
||||
string metaDataXML = null;
|
||||
// first try to get the provider specific xml
|
||||
|
||||
// if providerfilename is not supported we can't build the settings key needed to
|
||||
// get the provider specific XML path
|
||||
if (providerFileName != null){
|
||||
metaDataXML = providerFileName + _metaDataXml;
|
||||
values = settings.GetValues(metaDataXML);
|
||||
}
|
||||
|
||||
// if we did not find provider specific xml see if there is new default xml
|
||||
if (values == null) {
|
||||
metaDataXML =_defaultMetaDataXml;
|
||||
values = settings.GetValues(metaDataXML);
|
||||
}
|
||||
|
||||
// If there is new XML get it
|
||||
if (values != null) {
|
||||
XMLStream = ADP.GetXmlStreamFromValues(values,metaDataXML);
|
||||
}
|
||||
}
|
||||
|
||||
// if the xml was not obtained from machine.config use the embedded XML resource
|
||||
if (XMLStream == null) {
|
||||
XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OleDb.OleDbMetaData.xml");
|
||||
cacheMetaDataFactory = true;
|
||||
}
|
||||
|
||||
Debug.Assert (XMLStream != null,"XMLstream may not be null.");
|
||||
|
||||
// using the ServerVersion as the NormalizedServerVersion. Doing this for two reasons
|
||||
// 1) The Spec for DBPROP_DBMSVER normalizes the ServerVersion
|
||||
// 2) for OLE DB its the only game in town
|
||||
return new OleDbMetaDataFactory (XMLStream,
|
||||
oleDbInternalConnection.ServerVersion,
|
||||
oleDbInternalConnection.ServerVersion,
|
||||
oleDbInternalConnection.GetSchemaRowsetInformation());
|
||||
}
|
||||
|
||||
override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions(DbConnectionOptions connectionOptions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
override internal DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo (DbConnectionOptions connectionOptions) {
|
||||
return new OleDbConnectionPoolGroupProviderInfo();
|
||||
}
|
||||
|
||||
override internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnection connection) {
|
||||
OleDbConnection c = (connection as OleDbConnection);
|
||||
if (null != c) {
|
||||
return c.PoolGroup;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
override internal DbConnectionInternal GetInnerConnection(DbConnection connection) {
|
||||
OleDbConnection c = (connection as OleDbConnection);
|
||||
if (null != c) {
|
||||
return c.InnerConnection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
override protected int GetObjectId(DbConnection connection) {
|
||||
OleDbConnection c = (connection as OleDbConnection);
|
||||
if (null != c) {
|
||||
return c.ObjectID;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
override internal void PermissionDemand(DbConnection outerConnection) {
|
||||
OleDbConnection c = (outerConnection as OleDbConnection);
|
||||
if (null != c) {
|
||||
c.PermissionDemand();
|
||||
}
|
||||
}
|
||||
|
||||
override internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup) {
|
||||
OleDbConnection c = (outerConnection as OleDbConnection);
|
||||
if (null != c) {
|
||||
c.PoolGroup = poolGroup;
|
||||
}
|
||||
}
|
||||
|
||||
override internal void SetInnerConnectionEvent(DbConnection owningObject, DbConnectionInternal to) {
|
||||
OleDbConnection c = (owningObject as OleDbConnection);
|
||||
if (null != c) {
|
||||
c.SetInnerConnectionEvent(to);
|
||||
}
|
||||
}
|
||||
|
||||
override internal bool SetInnerConnectionFrom(DbConnection owningObject, DbConnectionInternal to, DbConnectionInternal from) {
|
||||
OleDbConnection c = (owningObject as OleDbConnection);
|
||||
if (null != c) {
|
||||
return c.SetInnerConnectionFrom(to, from);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override internal void SetInnerConnectionTo(DbConnection owningObject, DbConnectionInternal to) {
|
||||
OleDbConnection c = (owningObject as OleDbConnection);
|
||||
if (null != c) {
|
||||
c.SetInnerConnectionTo(to);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbConnection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb
|
||||
{
|
||||
using System.Data.ProviderBase;
|
||||
|
||||
internal sealed class OleDbConnectionPoolGroupProviderInfo : DbConnectionPoolGroupProviderInfo {
|
||||
private bool _hasQuoteFix;
|
||||
private string _quotePrefix, _quoteSuffix;
|
||||
|
||||
internal OleDbConnectionPoolGroupProviderInfo() {
|
||||
}
|
||||
|
||||
internal bool HasQuoteFix {
|
||||
get { return _hasQuoteFix; }
|
||||
}
|
||||
internal string QuotePrefix {
|
||||
get { return _quotePrefix; }
|
||||
}
|
||||
internal string QuoteSuffix {
|
||||
get { return _quoteSuffix; }
|
||||
}
|
||||
|
||||
internal void SetQuoteFix(string prefix, string suffix) {
|
||||
_quotePrefix = prefix;
|
||||
_quoteSuffix = suffix;
|
||||
_hasQuoteFix = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbDataAdapter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
[
|
||||
DefaultEvent("RowUpdated"),
|
||||
ToolboxItem("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterToolboxItem, " + AssemblyRef.MicrosoftVSDesigner),
|
||||
Designer("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterDesigner, " + AssemblyRef.MicrosoftVSDesigner),
|
||||
]
|
||||
public sealed class OleDbDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable {
|
||||
|
||||
static private readonly object EventRowUpdated = new object();
|
||||
static private readonly object EventRowUpdating = new object();
|
||||
|
||||
private OleDbCommand _deleteCommand, _insertCommand, _selectCommand, _updateCommand;
|
||||
|
||||
public OleDbDataAdapter() : base() {
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public OleDbDataAdapter(OleDbCommand selectCommand) : this() {
|
||||
SelectCommand = selectCommand;
|
||||
}
|
||||
|
||||
public OleDbDataAdapter(string selectCommandText, string selectConnectionString) : this() {
|
||||
OleDbConnection connection = new OleDbConnection(selectConnectionString);
|
||||
SelectCommand = new OleDbCommand(selectCommandText, connection);
|
||||
}
|
||||
|
||||
public OleDbDataAdapter(string selectCommandText, OleDbConnection selectConnection) : this() {
|
||||
SelectCommand = new OleDbCommand(selectCommandText, selectConnection);
|
||||
}
|
||||
|
||||
private OleDbDataAdapter(OleDbDataAdapter from) : base(from) {
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[
|
||||
DefaultValue(null),
|
||||
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
|
||||
ResCategoryAttribute(Res.DataCategory_Update),
|
||||
ResDescriptionAttribute(Res.DbDataAdapter_DeleteCommand),
|
||||
]
|
||||
new public OleDbCommand DeleteCommand {
|
||||
get { return _deleteCommand; }
|
||||
set { _deleteCommand = value; }
|
||||
}
|
||||
|
||||
IDbCommand IDbDataAdapter.DeleteCommand {
|
||||
get { return _deleteCommand; }
|
||||
set { _deleteCommand = (OleDbCommand)value; }
|
||||
}
|
||||
|
||||
[
|
||||
DefaultValue(null),
|
||||
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
|
||||
ResCategoryAttribute(Res.DataCategory_Update),
|
||||
ResDescriptionAttribute(Res.DbDataAdapter_InsertCommand),
|
||||
]
|
||||
new public OleDbCommand InsertCommand {
|
||||
get { return _insertCommand; }
|
||||
set { _insertCommand = value; }
|
||||
}
|
||||
|
||||
IDbCommand IDbDataAdapter.InsertCommand {
|
||||
get { return _insertCommand; }
|
||||
set { _insertCommand = (OleDbCommand)value; }
|
||||
}
|
||||
|
||||
[
|
||||
DefaultValue(null),
|
||||
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
|
||||
ResCategoryAttribute(Res.DataCategory_Fill),
|
||||
ResDescriptionAttribute(Res.DbDataAdapter_SelectCommand),
|
||||
]
|
||||
new public OleDbCommand SelectCommand {
|
||||
get { return _selectCommand; }
|
||||
set { _selectCommand = value; }
|
||||
}
|
||||
|
||||
IDbCommand IDbDataAdapter.SelectCommand {
|
||||
get { return _selectCommand; }
|
||||
set { _selectCommand = (OleDbCommand)value; }
|
||||
}
|
||||
|
||||
[
|
||||
DefaultValue(null),
|
||||
Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
|
||||
ResCategoryAttribute(Res.DataCategory_Update),
|
||||
ResDescriptionAttribute(Res.DbDataAdapter_UpdateCommand),
|
||||
]
|
||||
new public OleDbCommand UpdateCommand {
|
||||
get { return _updateCommand; }
|
||||
set { _updateCommand = value; }
|
||||
}
|
||||
|
||||
IDbCommand IDbDataAdapter.UpdateCommand {
|
||||
get { return _updateCommand; }
|
||||
set { _updateCommand = (OleDbCommand)value; }
|
||||
}
|
||||
|
||||
[
|
||||
ResCategoryAttribute(Res.DataCategory_Update),
|
||||
ResDescriptionAttribute(Res.DbDataAdapter_RowUpdated),
|
||||
]
|
||||
public event OleDbRowUpdatedEventHandler RowUpdated {
|
||||
add { Events.AddHandler(EventRowUpdated, value); }
|
||||
remove { Events.RemoveHandler(EventRowUpdated, value); }
|
||||
}
|
||||
|
||||
[
|
||||
ResCategoryAttribute(Res.DataCategory_Update),
|
||||
ResDescriptionAttribute(Res.DbDataAdapter_RowUpdating),
|
||||
]
|
||||
public event OleDbRowUpdatingEventHandler RowUpdating {
|
||||
add {
|
||||
OleDbRowUpdatingEventHandler handler = (OleDbRowUpdatingEventHandler) Events[EventRowUpdating];
|
||||
|
||||
// MDAC 58177, 64513
|
||||
// prevent someone from registering two different command builders on the adapter by
|
||||
// silently removing the old one
|
||||
if ((null != handler) && (value.Target is DbCommandBuilder)) {
|
||||
OleDbRowUpdatingEventHandler d = (OleDbRowUpdatingEventHandler) ADP.FindBuilder(handler);
|
||||
if (null != d) {
|
||||
Events.RemoveHandler(EventRowUpdating, d);
|
||||
}
|
||||
}
|
||||
Events.AddHandler(EventRowUpdating, value);
|
||||
}
|
||||
remove { Events.RemoveHandler(EventRowUpdating, value); }
|
||||
}
|
||||
|
||||
object ICloneable.Clone() {
|
||||
return new OleDbDataAdapter(this);
|
||||
}
|
||||
|
||||
override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) {
|
||||
return new OleDbRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
|
||||
}
|
||||
|
||||
override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) {
|
||||
return new OleDbRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
|
||||
}
|
||||
|
||||
internal static void FillDataTable(OleDbDataReader dataReader, params DataTable[] dataTables) {
|
||||
OleDbDataAdapter adapter = new OleDbDataAdapter();
|
||||
adapter.Fill(dataTables, dataReader, 0, 0);
|
||||
}
|
||||
|
||||
public int Fill(DataTable dataTable, object ADODBRecordSet) {
|
||||
System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
|
||||
permissionSet.AddPermission(OleDbConnection.ExecutePermission); // MDAC 77737
|
||||
permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode));
|
||||
permissionSet.Demand();
|
||||
|
||||
IntPtr hscp;
|
||||
Bid.ScopeEnter(out hscp, "<oledb.OleDbDataAdapter.Fill|API> %d#, dataTable, ADODBRecordSet\n", ObjectID);
|
||||
try {
|
||||
if (null == dataTable) {
|
||||
throw ADP.ArgumentNull("dataTable");
|
||||
}
|
||||
if (null == ADODBRecordSet) {
|
||||
throw ADP.ArgumentNull("adodb");
|
||||
}
|
||||
// user was required to have UnmanagedCode Permission just to create ADODB
|
||||
// (new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)).Demand();
|
||||
return FillFromADODB((object)dataTable, ADODBRecordSet, null, false); // MDAC 59249
|
||||
}
|
||||
finally {
|
||||
Bid.ScopeLeave(ref hscp);
|
||||
}
|
||||
}
|
||||
|
||||
public int Fill(DataSet dataSet, object ADODBRecordSet, string srcTable) {
|
||||
System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
|
||||
permissionSet.AddPermission(OleDbConnection.ExecutePermission); // MDAC 77737
|
||||
permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode));
|
||||
permissionSet.Demand();
|
||||
|
||||
IntPtr hscp;
|
||||
Bid.ScopeEnter(out hscp, "<oledb.OleDbDataAdapter.Fill|API> %d#, dataSet, ADODBRecordSet, srcTable='%ls'\n", ObjectID, srcTable);
|
||||
try {
|
||||
if (null == dataSet) {
|
||||
throw ADP.ArgumentNull("dataSet");
|
||||
}
|
||||
if (null == ADODBRecordSet) {
|
||||
throw ADP.ArgumentNull("adodb");
|
||||
}
|
||||
if (ADP.IsEmpty(srcTable)) {
|
||||
throw ADP.FillRequiresSourceTableName("srcTable");
|
||||
}
|
||||
// user was required to have UnmanagedCode Permission just to create ADODB
|
||||
// (new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)).Demand();
|
||||
return FillFromADODB((object)dataSet, ADODBRecordSet, srcTable, true);
|
||||
}
|
||||
finally {
|
||||
Bid.ScopeLeave(ref hscp);
|
||||
}
|
||||
}
|
||||
|
||||
private int FillFromADODB(Object data, object adodb, string srcTable, bool multipleResults) {
|
||||
Debug.Assert(null != data, "FillFromADODB: null data object");
|
||||
Debug.Assert(null != adodb, "FillFromADODB: null ADODB");
|
||||
Debug.Assert(!(adodb is DataTable), "call Fill( (DataTable) value)");
|
||||
Debug.Assert(!(adodb is DataSet), "call Fill( (DataSet) value)");
|
||||
|
||||
/*
|
||||
IntPtr adodbptr = ADP.PtrZero;
|
||||
try { // generate a new COM Callable Wrapper around the user object so they can't ReleaseComObject on us.
|
||||
adodbptr = Marshal.GetIUnknownForObject(adodb);
|
||||
adodb = System.Runtime.Remoting.Services.EnterpriseServicesHelper.WrapIUnknownWithComObject(adodbptr);
|
||||
}
|
||||
finally {
|
||||
if (ADP.PtrZero != adodbptr) {
|
||||
Marshal.Release(adodbptr);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool closeRecordset = multipleResults; // MDAC 60332, 66668
|
||||
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n");
|
||||
UnsafeNativeMethods.ADORecordsetConstruction recordset = (adodb as UnsafeNativeMethods.ADORecordsetConstruction);
|
||||
UnsafeNativeMethods.ADORecordConstruction record = null;
|
||||
|
||||
if (null != recordset) { // MDAC 78415
|
||||
if (multipleResults) {
|
||||
// The NextRecordset method is not available on a disconnected Recordset object, where ActiveConnection has been set to NULL
|
||||
object activeConnection;
|
||||
|
||||
Bid.Trace("<oledb.Recordset15.get_ActiveConnection|API|ADODB>\n");
|
||||
activeConnection = ((UnsafeNativeMethods.Recordset15)adodb).get_ActiveConnection();
|
||||
|
||||
if (null == activeConnection) {
|
||||
multipleResults = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordConstruction\n");
|
||||
record = (adodb as UnsafeNativeMethods.ADORecordConstruction);
|
||||
|
||||
if (null != record) { // MDAC 78415
|
||||
multipleResults = false; // IRow implies CommandBehavior.SingleRow which implies CommandBehavior.SingleResult
|
||||
}
|
||||
}
|
||||
// else throw ODB.Fill_NotADODB("adodb"); /* throw later, less code here*/
|
||||
|
||||
int results = 0;
|
||||
if (null != recordset) {
|
||||
int resultCount = 0;
|
||||
bool incrementResultCount; // MDAC 59632
|
||||
object[] value = new object[1];
|
||||
|
||||
do {
|
||||
string tmp = null;
|
||||
if (data is DataSet) {
|
||||
tmp = GetSourceTableName(srcTable, resultCount);
|
||||
}
|
||||
results += FillFromRecordset(data, recordset, tmp, out incrementResultCount);
|
||||
|
||||
if (multipleResults) {
|
||||
value[0] = DBNull.Value;
|
||||
|
||||
object recordsAffected;
|
||||
object nextresult;
|
||||
|
||||
Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB>\n");
|
||||
OleDbHResult hr = ((UnsafeNativeMethods.Recordset15)adodb).NextRecordset(out recordsAffected, out nextresult); // MDAC 78415
|
||||
Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB|RET> %08X{HRESULT}\n", hr);
|
||||
|
||||
if (0 > hr) {
|
||||
// Current provider does not support returning multiple recordsets from a single execution.
|
||||
if (ODB.ADODB_NextResultError != (int)hr) {
|
||||
UnsafeNativeMethods.IErrorInfo errorInfo = null;
|
||||
UnsafeNativeMethods.GetErrorInfo(0, out errorInfo);
|
||||
|
||||
string message = String.Empty;
|
||||
if (null != errorInfo) {
|
||||
OleDbHResult hresult = ODB.GetErrorDescription(errorInfo, hr, out message);
|
||||
}
|
||||
throw new COMException(message, (int)hr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
adodb = nextresult;
|
||||
if (null != adodb) {
|
||||
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n");
|
||||
recordset = (UnsafeNativeMethods.ADORecordsetConstruction) adodb;
|
||||
|
||||
if (incrementResultCount) {
|
||||
resultCount++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} while(null != recordset);
|
||||
|
||||
if ((null != recordset) && (closeRecordset || (null == adodb))) { // MDAC 59746, 60902
|
||||
FillClose(true, recordset);
|
||||
}
|
||||
}
|
||||
else if (null != record) {
|
||||
results = FillFromRecord(data, record, srcTable);
|
||||
if (closeRecordset) { // MDAC 66668
|
||||
FillClose(false, record); // MDAC 60848
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw ODB.Fill_NotADODB("adodb");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
//override protected int Fill(DataTable dataTable, IDataReader dataReader) { // MDAC 65506
|
||||
// return base.Fill(dataTable, dataReader);
|
||||
//}
|
||||
|
||||
private int FillFromRecordset(Object data, UnsafeNativeMethods.ADORecordsetConstruction recordset, string srcTable, out bool incrementResultCount) {
|
||||
incrementResultCount = false;
|
||||
|
||||
IntPtr chapter; /*ODB.DB_NULL_HCHAPTER*/
|
||||
object result = null;
|
||||
try {
|
||||
Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB>\n");
|
||||
result = recordset.get_Rowset(); // MDAC 83342
|
||||
Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB|RET> %08X{HRESULT}\n", 0);
|
||||
|
||||
Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB>\n");
|
||||
chapter = recordset.get_Chapter(); // MDAC 83342
|
||||
Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB|RET> %08X{HRESULT}\n", 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
//
|
||||
if (!ADP.IsCatchableExceptionType(e)) {
|
||||
throw;
|
||||
}
|
||||
|
||||
throw ODB.Fill_EmptyRecordSet("ADODBRecordSet", e);
|
||||
}
|
||||
|
||||
if (null != result) {
|
||||
CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;
|
||||
behavior |= CommandBehavior.SequentialAccess;
|
||||
|
||||
OleDbDataReader dataReader = null;
|
||||
try {
|
||||
// intialized with chapter only since we don't want ReleaseChapter called for this chapter handle
|
||||
ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(chapter);
|
||||
|
||||
dataReader = new OleDbDataReader(null, null, 0, behavior);
|
||||
dataReader.InitializeIRowset(result, chapterHandle, ADP.RecordsUnaffected);
|
||||
dataReader.BuildMetaInfo();
|
||||
|
||||
incrementResultCount = (0 < dataReader.FieldCount); // MDAC 59632
|
||||
if (incrementResultCount) {
|
||||
if (data is DataTable) {
|
||||
return base.Fill((DataTable) data, dataReader); // MDAC 65506
|
||||
}
|
||||
else {
|
||||
return base.Fill((DataSet) data, srcTable, dataReader, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (null != dataReader) {
|
||||
dataReader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int FillFromRecord(Object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable) {
|
||||
object result = null;
|
||||
try {
|
||||
Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB>\n");
|
||||
result = record.get_Row(); // MDAC 83342
|
||||
Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB|RET> %08X{HRESULT}\n", 0);
|
||||
}
|
||||
catch(Exception e) {
|
||||
//
|
||||
if (!ADP.IsCatchableExceptionType(e)) {
|
||||
throw;
|
||||
}
|
||||
|
||||
throw ODB.Fill_EmptyRecord("adodb", e);
|
||||
}
|
||||
|
||||
if (null != result) {
|
||||
CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo;
|
||||
behavior |= CommandBehavior.SequentialAccess | CommandBehavior.SingleRow;
|
||||
|
||||
OleDbDataReader dataReader = null;
|
||||
try {
|
||||
dataReader = new OleDbDataReader(null, null, 0, behavior);
|
||||
dataReader.InitializeIRow(result, ADP.RecordsUnaffected);
|
||||
dataReader.BuildMetaInfo();
|
||||
|
||||
if (data is DataTable) {
|
||||
return base.Fill((DataTable) data, dataReader); // MDAC 65506
|
||||
}
|
||||
else {
|
||||
return base.Fill((DataSet) data, srcTable, dataReader, 0, 0);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (null != dataReader) {
|
||||
dataReader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void FillClose(bool isrecordset, object value) {
|
||||
OleDbHResult hr;
|
||||
if (isrecordset) {
|
||||
Bid.Trace("<oledb.Recordset15.Close|API|ADODB>\n");
|
||||
hr = ((UnsafeNativeMethods.Recordset15)value).Close(); // MDAC 78415
|
||||
Bid.Trace("<oledb.Recordset15.Close|API|ADODB|RET> %08X{HRESULT}\n", hr);
|
||||
}
|
||||
else {
|
||||
Bid.Trace("<oledb._ADORecord.Close|API|ADODB>\n");
|
||||
hr = ((UnsafeNativeMethods._ADORecord)value).Close(); // MDAC 78415
|
||||
Bid.Trace("<oledb._ADORecord.Close|API|ADODB|RET> %08X{HRESULT}\n", hr);
|
||||
}
|
||||
if ((0 < (int)hr) && (ODB.ADODB_AlreadyClosedError != (int)hr)) {
|
||||
UnsafeNativeMethods.IErrorInfo errorInfo = null;
|
||||
UnsafeNativeMethods.GetErrorInfo(0, out errorInfo);
|
||||
string message = String.Empty;
|
||||
if (null != errorInfo) {
|
||||
OleDbHResult hresult = ODB.GetErrorDescription(errorInfo, hr, out message);
|
||||
}
|
||||
throw new COMException(message, (int)hr);
|
||||
}
|
||||
}
|
||||
|
||||
override protected void OnRowUpdated(RowUpdatedEventArgs value) {
|
||||
OleDbRowUpdatedEventHandler handler = (OleDbRowUpdatedEventHandler) Events[EventRowUpdated];
|
||||
if ((null != handler) && (value is OleDbRowUpdatedEventArgs)) {
|
||||
handler(this, (OleDbRowUpdatedEventArgs) value);
|
||||
}
|
||||
base.OnRowUpdated(value);
|
||||
}
|
||||
|
||||
override protected void OnRowUpdating(RowUpdatingEventArgs value) {
|
||||
OleDbRowUpdatingEventHandler handler = (OleDbRowUpdatingEventHandler) Events[EventRowUpdating];
|
||||
if ((null != handler) && (value is OleDbRowUpdatingEventArgs)) {
|
||||
handler(this, (OleDbRowUpdatingEventArgs) value);
|
||||
}
|
||||
base.OnRowUpdating(value);
|
||||
}
|
||||
|
||||
static private string GetSourceTableName(string srcTable, int index) {
|
||||
//if ((null != srcTable) && (0 <= index) && (index < srcTable.Length)) {
|
||||
if (0 == index) {
|
||||
return srcTable; //[index];
|
||||
}
|
||||
return srcTable + index.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbEnumerator.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
public sealed class OleDbEnumerator {
|
||||
|
||||
public OleDbEnumerator() {
|
||||
}
|
||||
|
||||
public DataTable GetElements() {
|
||||
OleDbConnection.ExecutePermission.Demand();
|
||||
|
||||
DataTable dataTable = new DataTable("MSDAENUM"); // WebData 112482
|
||||
dataTable.Locale = CultureInfo.InvariantCulture;
|
||||
OleDbDataReader dataReader = GetRootEnumerator();
|
||||
OleDbDataAdapter.FillDataTable(dataReader, dataTable);
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
static public OleDbDataReader GetEnumerator(Type type) {
|
||||
OleDbConnection.ExecutePermission.Demand();
|
||||
|
||||
return GetEnumeratorFromType(type);
|
||||
}
|
||||
|
||||
static internal OleDbDataReader GetEnumeratorFromType(Type type) { // WebData 99005
|
||||
// will demand security appropriately
|
||||
object value = Activator.CreateInstance(type, System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Instance, null, null, CultureInfo.InvariantCulture, null);
|
||||
return GetEnumeratorReader(value);
|
||||
}
|
||||
|
||||
static private OleDbDataReader GetEnumeratorReader(object value) {
|
||||
NativeMethods.ISourcesRowset srcrowset = null;
|
||||
|
||||
try {
|
||||
srcrowset = (NativeMethods.ISourcesRowset) value;
|
||||
}
|
||||
catch(InvalidCastException) {
|
||||
throw ODB.ISourcesRowsetNotSupported();
|
||||
}
|
||||
if (null == srcrowset) {
|
||||
throw ODB.ISourcesRowsetNotSupported();
|
||||
}
|
||||
value = null; // still held by ISourcesRowset, reused for IRowset
|
||||
|
||||
int propCount = 0;
|
||||
IntPtr propSets = ADP.PtrZero;
|
||||
|
||||
Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB> IID_IRowset\n");
|
||||
OleDbHResult hr = srcrowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, propCount, propSets, out value);
|
||||
Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB|RET> %08X{HRESULT}\n", hr);
|
||||
|
||||
Exception f = OleDbConnection.ProcessResults(hr, null, null);
|
||||
if (null != f) {
|
||||
throw f;
|
||||
}
|
||||
|
||||
OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, CommandBehavior.Default);
|
||||
dataReader.InitializeIRowset(value, ChapterHandle.DB_NULL_HCHAPTER, ADP.RecordsUnaffected);
|
||||
dataReader.BuildMetaInfo();
|
||||
dataReader.HasRowsRead();
|
||||
return dataReader;
|
||||
}
|
||||
|
||||
static public OleDbDataReader GetRootEnumerator() {
|
||||
OleDbConnection.ExecutePermission.Demand();
|
||||
|
||||
IntPtr hscp;
|
||||
Bid.ScopeEnter(out hscp, "<oledb.OleDbEnumerator.GetRootEnumerator|API>\n");
|
||||
try {
|
||||
//readonly Guid CLSID_MSDAENUM = new Guid(0xc8b522d0,0x5cf3,0x11ce,0xad,0xe5,0x00,0xaa,0x00,0x44,0x77,0x3d);
|
||||
//Type msdaenum = Type.GetTypeFromCLSID(CLSID_MSDAENUM, true);
|
||||
const string PROGID_MSDAENUM = "MSDAENUM";
|
||||
Type msdaenum = Type.GetTypeFromProgID(PROGID_MSDAENUM, true);
|
||||
return GetEnumeratorFromType(msdaenum);
|
||||
}
|
||||
finally {
|
||||
Bid.ScopeLeave(ref hscp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbError.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[Serializable]
|
||||
public sealed class OleDbError {
|
||||
readonly private string message;
|
||||
readonly private string source;
|
||||
readonly private string sqlState;
|
||||
readonly private int nativeError;
|
||||
|
||||
internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index) {
|
||||
OleDbHResult hr;
|
||||
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID;
|
||||
|
||||
Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS>\n");
|
||||
UnsafeNativeMethods.IErrorInfo errorInfo = errorRecords.GetErrorInfo(index, lcid);
|
||||
if (null != errorInfo) {
|
||||
|
||||
Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
|
||||
hr = errorInfo.GetDescription(out this.message);
|
||||
Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message);
|
||||
|
||||
if (OleDbHResult.DB_E_NOLOCALE == hr) { // MDAC 87303
|
||||
Bid.Trace("<oledb.ReleaseComObject|API|OS> ErrorInfo\n");
|
||||
Marshal.ReleaseComObject(errorInfo);
|
||||
|
||||
Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n");
|
||||
lcid = SafeNativeMethods.GetUserDefaultLCID();
|
||||
|
||||
Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lcid);
|
||||
errorInfo = errorRecords.GetErrorInfo(index, lcid);
|
||||
|
||||
if (null != errorInfo) {
|
||||
|
||||
Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS>\n");
|
||||
hr = errorInfo.GetDescription(out this.message);
|
||||
Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> Message='%ls'\n", this.message);
|
||||
}
|
||||
}
|
||||
if ((hr < 0) && ADP.IsEmpty(this.message)) {
|
||||
this.message = ODB.FailedGetDescription(hr);
|
||||
}
|
||||
if (null != errorInfo) {
|
||||
|
||||
Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n");
|
||||
hr = errorInfo.GetSource(out this.source);
|
||||
Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source);
|
||||
|
||||
if (OleDbHResult.DB_E_NOLOCALE == hr) { // MDAC 87303
|
||||
Marshal.ReleaseComObject(errorInfo);
|
||||
|
||||
Bid.Trace("<oledb.Kernel32.GetUserDefaultLCID|API|OS>\n");
|
||||
lcid = SafeNativeMethods.GetUserDefaultLCID();
|
||||
|
||||
Bid.Trace("<oledb.IErrorRecords.GetErrorInfo|API|OS> LCID=%d\n", lcid);
|
||||
errorInfo = errorRecords.GetErrorInfo(index, lcid);
|
||||
|
||||
if (null != errorInfo) {
|
||||
|
||||
Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS>\n");
|
||||
hr = errorInfo.GetSource(out this.source);
|
||||
Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> Source='%ls'\n", this.source);
|
||||
}
|
||||
}
|
||||
if ((hr < 0) && ADP.IsEmpty(this.source)) {
|
||||
this.source = ODB.FailedGetSource(hr);
|
||||
}
|
||||
Bid.Trace("<oledb.Marshal.ReleaseComObject|API|OS> ErrorInfo\n");
|
||||
Marshal.ReleaseComObject(errorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
UnsafeNativeMethods.ISQLErrorInfo sqlErrorInfo;
|
||||
|
||||
Bid.Trace("<oledb.IErrorRecords.GetCustomErrorObject|API|OS> IID_ISQLErrorInfo\n");
|
||||
hr = errorRecords.GetCustomErrorObject(index, ref ODB.IID_ISQLErrorInfo, out sqlErrorInfo);
|
||||
|
||||
if (null != sqlErrorInfo) {
|
||||
|
||||
Bid.Trace("<oledb.ISQLErrorInfo.GetSQLInfo|API|OS>\n");
|
||||
this.nativeError = sqlErrorInfo.GetSQLInfo(out this.sqlState);
|
||||
|
||||
Bid.Trace("<oledb.ReleaseComObject|API|OS> SQLErrorInfo\n");
|
||||
Marshal.ReleaseComObject(sqlErrorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public string Message {
|
||||
get {
|
||||
string message = this.message;
|
||||
return ((null != message) ? message : ADP.StrEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
public int NativeError {
|
||||
get {
|
||||
return this.nativeError;
|
||||
}
|
||||
}
|
||||
|
||||
public string Source {
|
||||
get {
|
||||
string source = this.source;
|
||||
return ((null != source) ? source : ADP.StrEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
public string SQLState {
|
||||
get {
|
||||
string sqlState = this.sqlState;
|
||||
return ((null != sqlState) ? sqlState : ADP.StrEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
override public string ToString() {
|
||||
return Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbErrorCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.Data.Common;
|
||||
|
||||
[Serializable, ListBindable(false)]
|
||||
public sealed class OleDbErrorCollection : System.Collections.ICollection {
|
||||
readonly private ArrayList items; // WebData 106655
|
||||
|
||||
internal OleDbErrorCollection(UnsafeNativeMethods.IErrorInfo errorInfo) {
|
||||
ArrayList items = new ArrayList();
|
||||
|
||||
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OS> IErrorRecords\n");
|
||||
UnsafeNativeMethods.IErrorRecords errorRecords = (errorInfo as UnsafeNativeMethods.IErrorRecords);
|
||||
if (null != errorRecords) {
|
||||
|
||||
int recordCount = errorRecords.GetRecordCount();
|
||||
Bid.Trace("<oledb.IErrorRecords.GetRecordCount|API|OS|RET> RecordCount=%d\n", recordCount);
|
||||
|
||||
for (int i = 0; i < recordCount; ++i) {
|
||||
OleDbError error = new OleDbError(errorRecords, i);
|
||||
items.Add(error);
|
||||
}
|
||||
}
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
bool System.Collections.ICollection.IsSynchronized {
|
||||
get { return false;}
|
||||
}
|
||||
|
||||
object System.Collections.ICollection.SyncRoot {
|
||||
get { return this;}
|
||||
}
|
||||
|
||||
public int Count {
|
||||
get {
|
||||
ArrayList items = this.items;
|
||||
return ((null != items) ? items.Count : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public OleDbError this[int index] {
|
||||
get {
|
||||
return (this.items[index] as OleDbError);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddRange(ICollection c) {
|
||||
items.AddRange(c);
|
||||
}
|
||||
|
||||
public void CopyTo(Array array, int index) {
|
||||
this.items.CopyTo(array, index);
|
||||
}
|
||||
|
||||
public void CopyTo (OleDbError[] array, int index) {
|
||||
this.items.CopyTo(array, index);
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator() {
|
||||
return this.items.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbException.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
[Serializable]
|
||||
public sealed class OleDbException : System.Data.Common.DbException {
|
||||
private OleDbErrorCollection oledbErrors;
|
||||
|
||||
internal OleDbException(string message, OleDbHResult errorCode, Exception inner) : base(message, inner) {
|
||||
HResult = (int)errorCode;
|
||||
this.oledbErrors = new OleDbErrorCollection(null);
|
||||
}
|
||||
|
||||
internal OleDbException(OleDbException previous, Exception inner) : base(previous.Message, inner) {
|
||||
HResult = previous.ErrorCode;
|
||||
this.oledbErrors = previous.oledbErrors;
|
||||
}
|
||||
|
||||
private OleDbException(string message, Exception inner, string source, OleDbHResult errorCode, OleDbErrorCollection errors) : base(message, inner) { // MDAC 84364
|
||||
Debug.Assert(null != errors, "OleDbException without OleDbErrorCollection");
|
||||
Source = source;
|
||||
HResult = (int)errorCode;
|
||||
this.oledbErrors = errors;
|
||||
}
|
||||
|
||||
// runtime will call even if private...
|
||||
private OleDbException(SerializationInfo si, StreamingContext sc) : base(si, sc) {
|
||||
oledbErrors = (OleDbErrorCollection) si.GetValue("oledbErrors", typeof(OleDbErrorCollection));
|
||||
}
|
||||
|
||||
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)]
|
||||
override public void GetObjectData(SerializationInfo si, StreamingContext context) { // MDAC 72003
|
||||
if (null == si) {
|
||||
throw new ArgumentNullException("si");
|
||||
}
|
||||
si.AddValue("oledbErrors", oledbErrors, typeof(OleDbErrorCollection));
|
||||
base.GetObjectData(si, context);
|
||||
}
|
||||
|
||||
[
|
||||
TypeConverterAttribute(typeof(ErrorCodeConverter))
|
||||
]
|
||||
override public int ErrorCode {
|
||||
get {
|
||||
return base.ErrorCode;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
|
||||
]
|
||||
public OleDbErrorCollection Errors {
|
||||
get {
|
||||
OleDbErrorCollection errors = this.oledbErrors;
|
||||
return ((null != errors) ? errors : new OleDbErrorCollection(null));
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ShouldSerializeErrors() { // MDAC 65548
|
||||
OleDbErrorCollection errors = this.oledbErrors;
|
||||
return ((null != errors) && (0 < errors.Count));
|
||||
}
|
||||
|
||||
static internal OleDbException CreateException(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode, Exception inner) { // MDAC 84364
|
||||
OleDbErrorCollection errors = new OleDbErrorCollection(errorInfo);
|
||||
string message = null;
|
||||
string source = null;
|
||||
OleDbHResult hr = 0;
|
||||
|
||||
if (null != errorInfo) {
|
||||
hr = errorInfo.GetDescription(out message);
|
||||
Bid.Trace("<oledb.IErrorInfo.GetDescription|API|OS|RET> %08X{HRESULT}, Description='%ls'\n", hr, message);
|
||||
|
||||
hr = errorInfo.GetSource(out source);
|
||||
Bid.Trace("<oledb.IErrorInfo.GetSource|API|OS|RET> %08X{HRESULT}, Source='%ls'\n", hr, source);
|
||||
}
|
||||
|
||||
int count = errors.Count;
|
||||
if (0 < errors.Count) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if ((null != message) && (message != errors[0].Message)) { // WebData 103032
|
||||
builder.Append(message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707
|
||||
if (1 < count) {
|
||||
builder.Append(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (0 < i) {
|
||||
builder.Append(Environment.NewLine);
|
||||
}
|
||||
builder.Append(errors[i].Message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707
|
||||
}
|
||||
message = builder.ToString();
|
||||
}
|
||||
if (ADP.IsEmpty(message)) {
|
||||
message = ODB.NoErrorMessage(errorCode); // MDAC 71170
|
||||
}
|
||||
return new OleDbException(message, inner, source, errorCode, errors);
|
||||
}
|
||||
|
||||
static internal OleDbException CombineExceptions(List<OleDbException> exceptions) {
|
||||
Debug.Assert(0 < exceptions.Count, "missing exceptions");
|
||||
if (1 < exceptions.Count) {
|
||||
OleDbErrorCollection errors = new OleDbErrorCollection(null);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
foreach(OleDbException exception in exceptions) {
|
||||
errors.AddRange(exception.Errors);
|
||||
builder.Append(exception.Message);
|
||||
builder.Append(Environment.NewLine);
|
||||
}
|
||||
return new OleDbException(builder.ToString(), null, exceptions[0].Source, (OleDbHResult)exceptions[0].ErrorCode, errors);
|
||||
}
|
||||
else {
|
||||
return exceptions[0];
|
||||
}
|
||||
}
|
||||
|
||||
sealed internal class ErrorCodeConverter : Int32Converter { // MDAC 68557
|
||||
|
||||
// converter classes should have public ctor
|
||||
public ErrorCodeConverter() {
|
||||
}
|
||||
|
||||
override public object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
|
||||
if (destinationType == null) {
|
||||
throw ADP.ArgumentNull("destinationType");
|
||||
}
|
||||
if ((destinationType == typeof(string)) && (value != null) && (value is Int32)) {
|
||||
return ODB.ELookup((OleDbHResult) value);
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbFactory.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
public sealed class OleDbFactory : DbProviderFactory {
|
||||
|
||||
public static readonly OleDbFactory Instance = new OleDbFactory();
|
||||
|
||||
private OleDbFactory() {
|
||||
}
|
||||
|
||||
public override DbCommand CreateCommand() {
|
||||
return new OleDbCommand();
|
||||
}
|
||||
|
||||
public override DbCommandBuilder CreateCommandBuilder() {
|
||||
return new OleDbCommandBuilder();
|
||||
}
|
||||
|
||||
public override DbConnection CreateConnection() {
|
||||
return new OleDbConnection();
|
||||
}
|
||||
|
||||
public override DbConnectionStringBuilder CreateConnectionStringBuilder() {
|
||||
return new OleDbConnectionStringBuilder();
|
||||
}
|
||||
|
||||
public override DbDataAdapter CreateDataAdapter() {
|
||||
return new OleDbDataAdapter();
|
||||
}
|
||||
|
||||
public override DbParameter CreateParameter() {
|
||||
return new OleDbParameter();
|
||||
}
|
||||
|
||||
public override CodeAccessPermission CreatePermission(PermissionState state) {
|
||||
return new OleDbPermission(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="OleDbInfoMessageEvent.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="true" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.OleDb {
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
public sealed class OleDbInfoMessageEventArgs : System.EventArgs {
|
||||
readonly private OleDbException exception;
|
||||
|
||||
internal OleDbInfoMessageEventArgs(OleDbException exception) {
|
||||
Debug.Assert(null != exception, "OleDbInfoMessageEventArgs without OleDbException");
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public int ErrorCode {
|
||||
get {
|
||||
return this.exception.ErrorCode;
|
||||
}
|
||||
}
|
||||
|
||||
public OleDbErrorCollection Errors {
|
||||
get {
|
||||
return this.exception.Errors;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ShouldSerializeErrors() { // MDAC 65548
|
||||
return this.exception.ShouldSerializeErrors();
|
||||
}
|
||||
|
||||
|
||||
public string Message {
|
||||
get {
|
||||
return this.exception.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public string Source {
|
||||
get {
|
||||
return this.exception.Source;
|
||||
}
|
||||
}
|
||||
|
||||
override public string ToString() {
|
||||
return Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user