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; UnsafeNativeMethods.ADORecordsetConstruction?recordset = (adodb as UnsafeNativeMethods.ADORecordsetConstruction); UnsafeNativeMethods.ADORecordConstruction? record = null; if (null != recordset) { if (multipleResults) { // The NextRecordset method is not available on a disconnected Recordset object, where ActiveConnection has been set to NULL object activeConnection; activeConnection = ((UnsafeNativeMethods.Recordset15)adodb).get_ActiveConnection(); if (null == activeConnection) { multipleResults = false; } } } else { record = (adodb as UnsafeNativeMethods.ADORecordConstruction); if (null != record) { 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; 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; OleDbHResult hr = ((UnsafeNativeMethods.Recordset15)adodb).NextRecordset(out recordsAffected, out nextresult); if (0 > hr) { // Current provider does not support returning multiple recordsets from a single execution. if (ODB.ADODB_NextResultError != (int)hr) { SafeNativeMethods.Wrapper.ClearErrorInfo(); string message = string.Empty; throw new COMException(message, (int)hr); } break; } adodb = nextresult; if (null != adodb) { recordset = (UnsafeNativeMethods.ADORecordsetConstruction)adodb; if (incrementResultCount) { resultCount++; } continue; } } break; } while (null != recordset); if ((null != recordset) && (closeRecordset || (null == adodb))) { FillClose(true, recordset); } } else if (null != record) { results = FillFromRecord(data, record, srcTable !); if (closeRecordset) { FillClose(false, record); } } else { throw ODB.Fill_NotADODB("adodb"); } return(results); }
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 Type recordsetType = null; UnsafeNativeMethods.ADORecordConstruction record = null; UnsafeNativeMethods.ADORecordsetConstruction recordset = null; try { #if DEBUG ODB.Trace_Cast("Object", "ADORecordsetConstruction", "get_Rowset"); #endif recordset = (UnsafeNativeMethods.ADORecordsetConstruction)adodb; recordsetType = adodb.GetType(); if (multipleResults) { // The NextRecordset method is not available on a disconnected Recordset object, where ActiveConnection has been set to NULL object activeConnection = recordsetType.InvokeMember("ActiveConnection", BindingFlags.GetProperty, null, adodb, new object[0]); if (null == activeConnection) { multipleResults = false; } } } catch (InvalidCastException e) { ADP.TraceException(e); try { #if DEBUG ODB.Trace_Cast("Object", "ADORecordConstruction", "get_Row"); #endif record = (UnsafeNativeMethods.ADORecordConstruction)adodb; multipleResults = false; // IRow implies CommandBehavior.SingleRow which implies CommandBehavior.SingleResult } catch (InvalidCastException f) { // $Consider: telling use either type of object passed in throw ODB.Fill_NotADODB("adodb", f); } } 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 = DbDataAdapter.GetSourceTableName(srcTable, resultCount); } results += FillFromRecordset(data, recordset, tmp, out incrementResultCount); if (multipleResults) { value[0] = DBNull.Value; try { adodb = recordsetType.InvokeMember("NextRecordset", BindingFlags.InvokeMethod, null, adodb, value); if (null != adodb) { try { #if DEBUG ODB.Trace_Cast("ADODB", "ADORecordsetConstruction", "get_Rowset"); #endif recordset = (UnsafeNativeMethods.ADORecordsetConstruction)adodb; } catch (Exception e) { ADP.TraceException(e); break; } recordsetType = adodb.GetType(); // MDAC 59253 if (incrementResultCount) { resultCount++; } continue; } } catch (TargetInvocationException e) { // MDAC 59244, 65506 if (e.InnerException is COMException) { FillNextResultError((COMException)e.InnerException, e); closeRecordset = true; // MDAC 60408 } else { throw; } } catch (COMException e) { // used as backup to the TargetInvocationException FillNextResultError(e, e); closeRecordset = true; // MDAC 60408 } } break; } while(null != recordset); if ((null != recordset) && (closeRecordset || (null == adodb))) // MDAC 59746, 60902 { FillClose(recordsetType, recordset); } } else if (null != record) { results = FillFromRecord(data, record, srcTable); if (closeRecordset) // MDAC 66668 { FillClose(adodb.GetType(), record); // MDAC 60848 } } else { throw ODB.Fill_NotADODB("adodb", null); } return(results); }
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); }
private int FillFromADODB(object data, object adodb, string srcTable, bool multipleResults) { string sourceTableName; bool flag2; bool flag = multipleResults; Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n"); System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction recordset = adodb as System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction; System.Data.Common.UnsafeNativeMethods.ADORecordConstruction record = null; if (recordset != null) { if (multipleResults) { Bid.Trace("<oledb.Recordset15.get_ActiveConnection|API|ADODB>\n"); if (((System.Data.Common.UnsafeNativeMethods.Recordset15)adodb).get_ActiveConnection() == null) { multipleResults = false; } } } else { Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordConstruction\n"); record = adodb as System.Data.Common.UnsafeNativeMethods.ADORecordConstruction; if (record != null) { multipleResults = false; } } int num = 0; if (recordset == null) { if (record == null) { throw ODB.Fill_NotADODB("adodb"); } num = this.FillFromRecord(data, record, srcTable); if (flag) { this.FillClose(false, record); } return(num); } int index = 0; object[] objArray = new object[1]; Label_0068: sourceTableName = null; if (data is DataSet) { sourceTableName = GetSourceTableName(srcTable, index); } num += this.FillFromRecordset(data, recordset, sourceTableName, out flag2); if (multipleResults) { object obj2; object obj4; objArray[0] = DBNull.Value; Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB>\n"); OleDbHResult result = ((System.Data.Common.UnsafeNativeMethods.Recordset15)adodb).NextRecordset(out obj4, out obj2); Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB|RET> %08X{HRESULT}\n", result); if (OleDbHResult.S_OK > result) { if (((OleDbHResult)(-2146825037)) != result) { System.Data.Common.UnsafeNativeMethods.IErrorInfo ppIErrorInfo = null; System.Data.Common.UnsafeNativeMethods.GetErrorInfo(0, out ppIErrorInfo); string message = string.Empty; if (ppIErrorInfo != null) { ODB.GetErrorDescription(ppIErrorInfo, result, out message); } throw new COMException(message, (int)result); } } else { adodb = obj2; if (adodb != null) { Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction\n"); recordset = (System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction)adodb; if (flag2) { index++; } if (recordset != null) { goto Label_0068; } } } } if ((recordset != null) && (flag || (adodb == null))) { this.FillClose(true, recordset); } return(num); }