private int FillFromRecord(object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable) { object?result = null; try { result = record.get_Row(); } catch (Exception e) { // UNDONE - should not be catching all exceptions!!! 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)); } 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 int FillFromRecord(Object data, UnsafeNativeMethods.ADORecordConstruction record, string srcTable) { object result = null; try { int hr; #if DEBUG ODB.Trace_Begin("ADORecordConstruction", "get_Row"); #endif hr = record.get_Row(out result); #if DEBUG ODB.Trace_End("ADORecordConstruction", "get_Row", hr); #endif } catch (Exception e) { ADP.TraceException(e); throw ODB.Fill_EmptyRecord("adodb", e); } if (null != result) { CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo; try { using (OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, IntPtr.Zero)) { dataReader.InitializeIRow(result, -1, behavior | CommandBehavior.SingleRow); dataReader.BuildMetaInfo(); if (data is DataTable) { return(base.Fill((DataTable)data, dataReader)); // MDAC 65506 } else { return(base.Fill((DataSet)data, srcTable, dataReader, 0, 0)); } } } catch { // MDAC 80973 throw; } } return(0); }
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) { 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); }