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; }
private static OleDbDataReader GetEnumeratorReader(object value) { System.Data.Common.NativeMethods.ISourcesRowset rowset = null; try { rowset = (System.Data.Common.NativeMethods.ISourcesRowset) value; } catch (InvalidCastException) { throw ODB.ISourcesRowsetNotSupported(); } if (rowset == null) { throw ODB.ISourcesRowsetNotSupported(); } value = null; int cPropertySets = 0; IntPtr ptrZero = ADP.PtrZero; Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB> IID_IRowset\n"); OleDbHResult result = rowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, cPropertySets, ptrZero, out value); Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB|RET> %08X{HRESULT}\n", result); Exception exception = OleDbConnection.ProcessResults(result, null, null); if (exception != null) { throw exception; } OleDbDataReader reader = new OleDbDataReader(null, null, 0, CommandBehavior.Default); reader.InitializeIRowset(value, ChapterHandle.DB_NULL_HCHAPTER, ADP.RecordsUnaffected); reader.BuildMetaInfo(); reader.HasRowsRead(); return reader; }
private static OleDbDataReader GetEnumeratorReader(object?value) { NativeMethods.ISourcesRowset?srcrowset; try { srcrowset = (NativeMethods.ISourcesRowset?)value; } catch (InvalidCastException) { throw ODB.ISourcesRowsetNotSupported(); } if (null == srcrowset) { throw ODB.ISourcesRowsetNotSupported(); } int propCount = 0; IntPtr propSets = ADP.PtrZero; OleDbHResult hr = srcrowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, propCount, propSets, out value); 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); }
//protected override int Fill(DataTable dataTable, IDataReader dataReader) { // 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; try { result = recordset.get_Rowset(); chapter = recordset.get_Chapter(); } catch (Exception e) { // UNDONE - should not be catching all exceptions!!! 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 { // initialized 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); if (incrementResultCount) { if (data is DataTable) { return(base.Fill((DataTable)data, dataReader)); } else { return(base.Fill((DataSet)data, srcTable !, dataReader, 0, 0)); } } } finally { dataReader?.Close(); } } return(0); }
//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 { int hr; #if DEBUG ODB.Trace_Begin("ADORecordsetConstruction", "get_Rowset"); #endif hr = recordset.get_Rowset(out result); #if DEBUG ODB.Trace_End("ADORecordsetConstruction", "get_Rowset", hr); ODB.Trace_Begin("ADORecordsetConstruction", "get_Chapter"); #endif hr = recordset.get_Chapter(out chapter); #if DEBUG ODB.Trace_End("ADORecordsetConstruction", "get_Chapter", hr); #endif } catch (Exception e) { ADP.TraceException(e); throw ODB.Fill_EmptyRecordSet("adodbRecordSet", e); } if (null != result) { CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo; behavior |= CommandBehavior.SequentialAccess; try { using (OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, chapter)) { dataReader.InitializeIRowset(result, -1, behavior); 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)); } } } } catch { // MDAC 80973 throw; } } return(0); }
private int FillFromRecordset(object data, System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction recordset, string srcTable, out bool incrementResultCount) { IntPtr ptr; incrementResultCount = false; object result = null; try { Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB>\n"); result = recordset.get_Rowset(); Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB|RET> %08X{HRESULT}\n", 0); Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB>\n"); ptr = recordset.get_Chapter(); Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB|RET> %08X{HRESULT}\n", 0); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } throw ODB.Fill_EmptyRecordSet("ADODBRecordSet", exception); } if (result != null) { CommandBehavior commandBehavior = (MissingSchemaAction.AddWithKey != base.MissingSchemaAction) ? CommandBehavior.Default : CommandBehavior.KeyInfo; commandBehavior |= CommandBehavior.SequentialAccess; OleDbDataReader dataReader = null; try { ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(ptr); dataReader = new OleDbDataReader(null, null, 0, commandBehavior); dataReader.InitializeIRowset(result, chapterHandle, ADP.RecordsUnaffected); dataReader.BuildMetaInfo(); incrementResultCount = 0 < dataReader.FieldCount; if (incrementResultCount) { if (data is DataTable) { return(base.Fill((DataTable)data, dataReader)); } return(base.Fill((DataSet)data, srcTable, dataReader, 0, 0)); } } finally { if (dataReader != null) { dataReader.Close(); } } } return(0); }
internal DataTable GetSchemaRowset(Guid schema, object[] restrictions) { DataTable table2; IntPtr ptr; Bid.ScopeEnter(out ptr, "<oledb.OleDbConnectionInternal.GetSchemaRowset|INFO> %d#, schema=%ls, restrictions\n", base.ObjectID, schema); try { if (restrictions == null) { restrictions = new object[0]; } DataTable table = null; using (IDBSchemaRowsetWrapper wrapper = this.IDBSchemaRowset()) { System.Data.Common.UnsafeNativeMethods.IDBSchemaRowset rowset2 = wrapper.Value; if (rowset2 == null) { throw ODB.SchemaRowsetsNotSupported(this.Provider); } System.Data.Common.UnsafeNativeMethods.IRowset ppRowset = null; Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB> %d#\n", base.ObjectID); OleDbHResult result = rowset2.GetRowset(ADP.PtrZero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, ADP.PtrZero, out ppRowset); Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB|RET> %08X{HRESULT}\n", result); if (result < OleDbHResult.S_OK) { this.ProcessResults(result); } if (ppRowset != null) { using (OleDbDataReader reader = new OleDbDataReader(this.Connection, null, 0, CommandBehavior.Default)) { reader.InitializeIRowset(ppRowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero); reader.BuildMetaInfo(); reader.HasRowsRead(); table = new DataTable { Locale = CultureInfo.InvariantCulture, TableName = OleDbSchemaGuid.GetTextFromValue(schema) }; OleDbDataAdapter.FillDataTable(reader, new DataTable[] { table }); } } return(table); } } finally { Bid.ScopeLeave(ref ptr); } return(table2); }
internal DataTable GetSchemaRowset(Guid schema, object[] restrictions) { IntPtr hscp; Bid.ScopeEnter(out hscp, "<oledb.OleDbConnectionInternal.GetSchemaRowset|INFO> %d#, schema=%ls, restrictions\n", ObjectID, schema); try { if (null == restrictions) // MDAC 62243 { restrictions = new object[0]; } DataTable dataTable = null; using (IDBSchemaRowsetWrapper wrapper = IDBSchemaRowset()) { UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset = wrapper.Value; if (null == dbSchemaRowset) { throw ODB.SchemaRowsetsNotSupported(Provider); } UnsafeNativeMethods.IRowset rowset = null; OleDbHResult hr; Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB> %d#\n", ObjectID); hr = dbSchemaRowset.GetRowset(ADP.PtrZero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, ADP.PtrZero, out rowset); Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB|RET> %08X{HRESULT}\n", hr); if (hr < 0) // ignore infomsg { ProcessResults(hr); } if (null != rowset) { using (OleDbDataReader dataReader = new OleDbDataReader(Connection, null, 0, CommandBehavior.Default)) { dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero); dataReader.BuildMetaInfo(); dataReader.HasRowsRead(); dataTable = new DataTable(); dataTable.Locale = CultureInfo.InvariantCulture; dataTable.TableName = OleDbSchemaGuid.GetTextFromValue(schema); OleDbDataAdapter.FillDataTable(dataReader, dataTable); } } return(dataTable); } } finally { Bid.ScopeLeave(ref hscp); } }
internal DataTable GetSchemaRowset(Guid schema, object[] restrictions) { if (null == restrictions) { restrictions = Array.Empty <object>(); } DataTable dataTable = null; using (IDBSchemaRowsetWrapper wrapper = IDBSchemaRowset()) { UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset = wrapper.Value; if (null == dbSchemaRowset) { throw ODB.SchemaRowsetsNotSupported(Provider); } UnsafeNativeMethods.IRowset rowset = null; OleDbHResult hr; hr = dbSchemaRowset.GetRowset(ADP.PtrZero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, ADP.PtrZero, out rowset); if (hr < 0) { // ignore infomsg ProcessResults(hr); } if (null != rowset) { using (OleDbDataReader dataReader = new OleDbDataReader(Connection, null, 0, CommandBehavior.Default)) { dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero); dataReader.BuildMetaInfo(); dataReader.HasRowsRead(); dataTable = new DataTable(); dataTable.Locale = CultureInfo.InvariantCulture; dataTable.TableName = OleDbSchemaGuid.GetTextFromValue(schema); OleDbDataAdapter.FillDataTable(dataReader, dataTable); } } return(dataTable); } }
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); }
private static OleDbDataReader GetEnumeratorReader(object value) { System.Data.Common.NativeMethods.ISourcesRowset rowset = null; try { rowset = (System.Data.Common.NativeMethods.ISourcesRowset)value; } catch (InvalidCastException) { throw ODB.ISourcesRowsetNotSupported(); } if (rowset == null) { throw ODB.ISourcesRowsetNotSupported(); } value = null; int cPropertySets = 0; IntPtr ptrZero = ADP.PtrZero; Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB> IID_IRowset\n"); OleDbHResult result = rowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, cPropertySets, ptrZero, out value); Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB|RET> %08X{HRESULT}\n", result); Exception exception = OleDbConnection.ProcessResults(result, null, null); if (exception != null) { throw exception; } OleDbDataReader reader = new OleDbDataReader(null, null, 0, CommandBehavior.Default); reader.InitializeIRowset(value, ChapterHandle.DB_NULL_HCHAPTER, ADP.RecordsUnaffected); reader.BuildMetaInfo(); reader.HasRowsRead(); return(reader); }
private OleDbDataReader GetDataForReader(IntPtr ordinal, RowBinding rowbinding, int valueOffset) { System.Data.Common.UnsafeNativeMethods.IRowset rowset; System.Data.Common.UnsafeNativeMethods.IRowsetInfo info = this.IRowsetInfo(); Bid.Trace("<oledb.IRowsetInfo.GetReferencedRowset|API|OLEDB> %d#, ColumnOrdinal=%Id\n", this.ObjectID, ordinal); OleDbHResult result = info.GetReferencedRowset(ordinal, ref ODB.IID_IRowset, out rowset); Bid.Trace("<oledb.IRowsetInfo.GetReferencedRowset|API|OLEDB|RET> %08X{HRESULT}\n", result); this.ProcessResults(result); OleDbDataReader reader = null; if (rowset != null) { ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(rowset, rowbinding, valueOffset); reader = new OleDbDataReader(this._connection, this._command, 1 + this.Depth, this._commandBehavior & ~CommandBehavior.CloseConnection); reader.InitializeIRowset(rowset, chapterHandle, ADP.RecordsUnaffected); reader.BuildMetaInfo(); reader.HasRowsRead(); if (this._connection != null) { this._connection.AddWeakReference(reader, 2); } } return reader; }
private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method) { OleDbDataReader dataReader = null; OleDbException previous = null; int num2 = 0; try { object obj2; int num; this.ValidateConnectionAndTransaction(method); if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default) { behavior |= CommandBehavior.SingleResult; } switch (this.CommandType) { case ((System.Data.CommandType) 0): case System.Data.CommandType.Text: case System.Data.CommandType.StoredProcedure: num = this.ExecuteCommand(behavior, out obj2); break; case System.Data.CommandType.TableDirect: num = this.ExecuteTableDirect(behavior, out obj2); break; default: throw ADP.InvalidCommandType(this.CommandType); } if (this._executeQuery) { try { dataReader = new OleDbDataReader(this._connection, this, 0, this.commandBehavior); switch (num) { case 0: dataReader.InitializeIMultipleResults(obj2); dataReader.NextResult(); break; case 1: dataReader.InitializeIRowset(obj2, ChapterHandle.DB_NULL_HCHAPTER, this._recordsAffected); dataReader.BuildMetaInfo(); dataReader.HasRowsRead(); break; case 2: dataReader.InitializeIRow(obj2, this._recordsAffected); dataReader.BuildMetaInfo(); break; case 3: if (!this._isPrepared) { this.PrepareCommandText(2); } OleDbDataReader.GenerateSchemaTable(dataReader, this._icommandText, behavior); break; } obj2 = null; this._hasDataReader = true; this._connection.AddWeakReference(dataReader, 2); num2 = 1; return(dataReader); } finally { if (1 != num2) { this.canceling = true; if (dataReader != null) { dataReader.Dispose(); dataReader = null; } } } } try { if (num == 0) { UnsafeNativeMethods.IMultipleResults imultipleResults = (UnsafeNativeMethods.IMultipleResults)obj2; previous = OleDbDataReader.NextResults(imultipleResults, this._connection, this, out this._recordsAffected); } } finally { try { if (obj2 != null) { Marshal.ReleaseComObject(obj2); obj2 = null; } this.CloseFromDataReader(this.ParameterBindings); } catch (Exception exception3) { if (!ADP.IsCatchableExceptionType(exception3)) { throw; } if (previous == null) { throw; } previous = new OleDbException(previous, exception3); } } } finally { try { if ((dataReader == null) && (1 != num2)) { this.ParameterCleanup(); } } catch (Exception exception2) { if (!ADP.IsCatchableExceptionType(exception2)) { throw; } if (previous == null) { throw; } previous = new OleDbException(previous, exception2); } if (previous != null) { throw previous; } } return(dataReader); }
private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method) { OleDbDataReader dataReader = null; OleDbException nextResultsFailure = null; int state = ODB.InternalStateClosed; try { ValidateConnectionAndTransaction(method); if (0 != (CommandBehavior.SingleRow & behavior)) { // CommandBehavior.SingleRow implies CommandBehavior.SingleResult behavior |= CommandBehavior.SingleResult; } object executeResult; int resultType; switch(CommandType) { case 0: // uninitialized CommandType.Text case CommandType.Text: case CommandType.StoredProcedure: resultType = ExecuteCommand(behavior, out executeResult); break; case CommandType.TableDirect: resultType = ExecuteTableDirect(behavior, out executeResult); break; default: throw ADP.InvalidCommandType(CommandType); } if (_executeQuery) { try { dataReader = new OleDbDataReader(_connection, this, 0, this.commandBehavior); switch(resultType) { case ODB.ExecutedIMultipleResults: dataReader.InitializeIMultipleResults(executeResult); dataReader.NextResult(); break; case ODB.ExecutedIRowset: dataReader.InitializeIRowset(executeResult, ChapterHandle.DB_NULL_HCHAPTER, _recordsAffected); dataReader.BuildMetaInfo(); dataReader.HasRowsRead(); break; case ODB.ExecutedIRow: dataReader.InitializeIRow(executeResult, _recordsAffected); dataReader.BuildMetaInfo(); break; case ODB.PrepareICommandText: if (!_isPrepared) { PrepareCommandText(2); } OleDbDataReader.GenerateSchemaTable(dataReader, _icommandText, behavior); break; default: Debug.Assert(false, "ExecuteReaderInternal: unknown result type"); break; } executeResult = null; _hasDataReader = true; _connection.AddWeakReference(dataReader, OleDbReferenceCollection.DataReaderTag); // command stays in the executing state until the connection // has a datareader to track for it being closed state = ODB.InternalStateOpen; // MDAC 72655 } finally { if (ODB.InternalStateOpen != state) { this.canceling = true; if (null != dataReader) { ((IDisposable) dataReader).Dispose(); dataReader = null; } } } Debug.Assert(null != dataReader, "ExecuteReader should never return a null DataReader"); } else { // optimized code path for ExecuteNonQuery to not create a OleDbDataReader object try { if (ODB.ExecutedIMultipleResults == resultType) { UnsafeNativeMethods.IMultipleResults multipleResults = (UnsafeNativeMethods.IMultipleResults) executeResult; // may cause a Connection.ResetState which closes connection nextResultsFailure = OleDbDataReader.NextResults(multipleResults, _connection, this, out _recordsAffected); } } finally { try { if (null != executeResult) { Marshal.ReleaseComObject(executeResult); executeResult = null; } CloseFromDataReader(ParameterBindings); } catch(Exception e) { // if (!ADP.IsCatchableExceptionType(e)) { throw; } if (null != nextResultsFailure) { nextResultsFailure = new OleDbException(nextResultsFailure, e); } else { throw; } } } } } finally { // finally clear executing state try { if ((null == dataReader) && (ODB.InternalStateOpen != state)) { // MDAC 67218 ParameterCleanup(); } } catch(Exception e) { // if (!ADP.IsCatchableExceptionType(e)) { throw; } if (null != nextResultsFailure) { nextResultsFailure = new OleDbException(nextResultsFailure, e); } else { throw; } } if (null != nextResultsFailure) { throw nextResultsFailure; } } return dataReader; }
private OleDbDataReader GetDataForReader(IntPtr ordinal, RowBinding rowbinding, int valueOffset) { UnsafeNativeMethods.IRowsetInfo rowsetInfo = IRowsetInfo(); UnsafeNativeMethods.IRowset result; OleDbHResult hr; Bid.Trace("<oledb.IRowsetInfo.GetReferencedRowset|API|OLEDB> %d#, ColumnOrdinal=%Id\n", ObjectID, ordinal); hr = rowsetInfo.GetReferencedRowset((IntPtr)ordinal, ref ODB.IID_IRowset, out result); Bid.Trace("<oledb.IRowsetInfo.GetReferencedRowset|API|OLEDB|RET> %08X{HRESULT}\n", hr); ProcessResults(hr); OleDbDataReader reader = null; if (null != result) { // only when the first datareader is closed will the connection close ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(result, rowbinding, valueOffset); reader = new OleDbDataReader(_connection, _command, 1+Depth, _commandBehavior & ~CommandBehavior.CloseConnection); reader.InitializeIRowset(result, chapterHandle, ADP.RecordsUnaffected); reader.BuildMetaInfo(); reader.HasRowsRead(); if (null != _connection) { // connection tracks all readers to prevent cmd from executing // until all readers (including nested) are closed _connection.AddWeakReference(reader, OleDbReferenceCollection.DataReaderTag); } } return reader; }
internal void DumpToSchemaTable(UnsafeNativeMethods.IRowset rowset) { List<MetaData> metainfo = new List<MetaData>(); object hiddenColumns = null; using (OleDbDataReader dataReader = new OleDbDataReader(_connection, _command, Int32.MinValue, 0)) { dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero); dataReader.BuildSchemaTableInfo(rowset, true, false); hiddenColumns = GetPropertyValue(ODB.DBPROP_HIDDENCOLUMNS); // MDAC 55611, 72106 if (0 == dataReader.FieldCount) { return; } Debug.Assert(null == dataReader._fieldNameLookup, "lookup already exists"); FieldNameLookup lookup = new FieldNameLookup(dataReader, -1); dataReader._fieldNameLookup = lookup; // This column, together with the DBCOLUMN_GUID and DBCOLUMN_PROPID // columns, forms the ID of the column. One or more (but not all) of these columns // will be NULL, depending on which elements of the DBID structure the provider uses. MetaData columnidname = dataReader.FindMetaData(ODB.DBCOLUMN_IDNAME); MetaData columnguid = dataReader.FindMetaData(ODB.DBCOLUMN_GUID); MetaData columnpropid = dataReader.FindMetaData(ODB.DBCOLUMN_PROPID); MetaData columnname = dataReader.FindMetaData(ODB.DBCOLUMN_NAME); MetaData columnordinal = dataReader.FindMetaData(ODB.DBCOLUMN_NUMBER); MetaData dbtype = dataReader.FindMetaData(ODB.DBCOLUMN_TYPE); MetaData columnsize = dataReader.FindMetaData(ODB.DBCOLUMN_COLUMNSIZE); MetaData numericprecision = dataReader.FindMetaData(ODB.DBCOLUMN_PRECISION); MetaData numericscale = dataReader.FindMetaData(ODB.DBCOLUMN_SCALE); MetaData columnflags = dataReader.FindMetaData(ODB.DBCOLUMN_FLAGS); MetaData baseschemaname = dataReader.FindMetaData(ODB.DBCOLUMN_BASESCHEMANAME); MetaData basecatalogname = dataReader.FindMetaData(ODB.DBCOLUMN_BASECATALOGNAME); MetaData basetablename = dataReader.FindMetaData(ODB.DBCOLUMN_BASETABLENAME); MetaData basecolumnname = dataReader.FindMetaData(ODB.DBCOLUMN_BASECOLUMNNAME); MetaData isautoincrement = dataReader.FindMetaData(ODB.DBCOLUMN_ISAUTOINCREMENT); MetaData isunique = dataReader.FindMetaData(ODB.DBCOLUMN_ISUNIQUE); MetaData iskeycolumn = dataReader.FindMetaData(ODB.DBCOLUMN_KEYCOLUMN); // @devnote: because we want to use the DBACCESSOR_OPTIMIZED bit, // we are required to create the accessor before fetching any rows dataReader.CreateAccessors(false); ColumnBinding binding; while (dataReader.ReadRowset()) { dataReader.GetRowDataFromHandle(); MetaData info = new MetaData(); binding = columnidname.columnBinding; // MDAC 72627 if (!binding.IsValueNull()) { info.idname = (string)binding.Value(); info.kind = ODB.DBKIND_NAME; } binding = columnguid.columnBinding; if (!binding.IsValueNull()) { info.guid = binding.Value_GUID(); info.kind = ((ODB.DBKIND_NAME == info.kind) ? ODB.DBKIND_GUID_NAME : ODB.DBKIND_GUID); } binding = columnpropid.columnBinding; if (!binding.IsValueNull()) { info.propid = new IntPtr(binding.Value_UI4()); info.kind = ((ODB.DBKIND_GUID == info.kind) ? ODB.DBKIND_GUID_PROPID : ODB.DBKIND_PROPID); } binding = columnname.columnBinding; if (!binding.IsValueNull()) { info.columnName = (string)binding.Value(); } else { info.columnName = ""; } if (4 == ADP.PtrSize) { info.ordinal = (IntPtr)columnordinal.columnBinding.Value_UI4(); } else { info.ordinal = (IntPtr)columnordinal.columnBinding.Value_UI8(); } short wType = unchecked((short) dbtype.columnBinding.Value_UI2()); if (4 == ADP.PtrSize) { info.size = unchecked((int) columnsize.columnBinding.Value_UI4()); // WebData 99298 } else { info.size = ADP.IntPtrToInt32((IntPtr)unchecked((long)columnsize.columnBinding.Value_UI8())); } binding = numericprecision.columnBinding; if (!binding.IsValueNull()) { info.precision = (byte)binding.Value_UI2(); } binding = numericscale.columnBinding; if (!binding.IsValueNull()) { info.scale = (byte)binding.Value_I2(); } info.flags = unchecked((int) columnflags.columnBinding.Value_UI4()); bool islong = OleDbDataReader.IsLong(info.flags); bool isfixed = OleDbDataReader.IsFixed(info.flags); NativeDBType dbType = NativeDBType.FromDBType(wType, islong, isfixed); info.type = dbType; if (null != isautoincrement) { binding = isautoincrement.columnBinding; if (!binding.IsValueNull()) { info.isAutoIncrement = binding.Value_BOOL(); } } if (null != isunique) { binding = isunique.columnBinding; if (!binding.IsValueNull()) { info.isUnique = binding.Value_BOOL(); } } if (null != iskeycolumn) { binding = iskeycolumn.columnBinding; if (!binding.IsValueNull()) { info.isKeyColumn = binding.Value_BOOL(); } } if (null != baseschemaname) { binding = baseschemaname.columnBinding; if (!binding.IsValueNull()) { info.baseSchemaName = binding.ValueString(); } } if (null != basecatalogname) { binding = basecatalogname.columnBinding; if (!binding.IsValueNull()) { info.baseCatalogName = binding.ValueString(); } } if (null != basetablename) { binding = basetablename.columnBinding; if (!binding.IsValueNull()) { info.baseTableName = binding.ValueString(); } } if (null != basecolumnname) { binding = basecolumnname.columnBinding; if (!binding.IsValueNull()) { info.baseColumnName = binding.ValueString(); } } metainfo.Add(info); } } int visibleCount = metainfo.Count; if (hiddenColumns is Int32) { visibleCount -= (int)hiddenColumns; } // VSTFDevDiv 479578: // if one key column is invalidated, they all need to be invalidated. The SET is the key, // and subsets likely are not accurate keys. Note the assumption that the two loops below // will traverse the entire set of columns. bool disallowKeyColumns = false; for (int index = metainfo.Count - 1; visibleCount <= index; --index) { MetaData info = metainfo[index]; info.isHidden = true; if (disallowKeyColumns) { info.isKeyColumn = false; } else if (info.guid.Equals(ODB.DBCOL_SPECIALCOL)) { // MDAC 90827 info.isKeyColumn = false; // This is the first key column to be invalidated, scan back through the // columns we already processed to make sure none of those are marked as keys. disallowKeyColumns = true; for (int index2 = metainfo.Count-1; index < index2; --index2) { metainfo[index2].isKeyColumn = false; } } } for (int index = visibleCount - 1; 0 <= index; --index) { MetaData info = metainfo[index]; if (disallowKeyColumns) { info.isKeyColumn = false; } if (info.guid.Equals(ODB.DBCOL_SPECIALCOL)) { // MDAC 72390 #if DEBUG if (AdapterSwitches.DataSchema.TraceVerbose) { Debug.WriteLine("Filtered Column: DBCOLUMN_GUID=DBCOL_SPECIALCOL DBCOLUMN_NAME=" + info.columnName + " DBCOLUMN_KEYCOLUMN=" + info.isKeyColumn); } #endif info.isHidden = true; visibleCount--; } #if WIN32 else if (0 >= (int)info.ordinal) { #else else if (0 >= (long)info.ordinal) { #endif #if DEBUG if (AdapterSwitches.DataSchema.TraceVerbose) { Debug.WriteLine("Filtered Column: DBCOLUMN_NUMBER=" + info.ordinal.ToInt64().ToString(CultureInfo.InvariantCulture) + " DBCOLUMN_NAME=" + info.columnName); } #endif info.isHidden = true; visibleCount--; } else if (OleDbDataReader.DoColumnDropFilter(info.flags)) { #if DEBUG if (AdapterSwitches.DataSchema.TraceVerbose) { Debug.WriteLine("Filtered Column: DBCOLUMN_FLAGS=" + info.flags.ToString("X8", (System.IFormatProvider)null) + " DBCOLUMN_NAME=" + info.columnName); } #endif info.isHidden = true; visibleCount--; } } // metainfo.Sort(); // MDAC 68319 _visibleFieldCount = visibleCount; _metadata = metainfo.ToArray(); }
//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 OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method) { OleDbDataReader dataReader = null; OleDbException nextResultsFailure = null; int state = ODB.InternalStateClosed; try { ValidateConnectionAndTransaction(method); if (0 != (CommandBehavior.SingleRow & behavior)) { // CommandBehavior.SingleRow implies CommandBehavior.SingleResult behavior |= CommandBehavior.SingleResult; } object executeResult; int resultType; switch (CommandType) { case 0: // uninitialized CommandType.Text case CommandType.Text: case CommandType.StoredProcedure: resultType = ExecuteCommand(behavior, out executeResult); break; case CommandType.TableDirect: resultType = ExecuteTableDirect(behavior, out executeResult); break; default: throw ADP.InvalidCommandType(CommandType); } if (_executeQuery) { try { dataReader = new OleDbDataReader(_connection, this, 0, this.commandBehavior); switch (resultType) { case ODB.ExecutedIMultipleResults: dataReader.InitializeIMultipleResults(executeResult); dataReader.NextResult(); break; case ODB.ExecutedIRowset: dataReader.InitializeIRowset(executeResult, ChapterHandle.DB_NULL_HCHAPTER, _recordsAffected); dataReader.BuildMetaInfo(); dataReader.HasRowsRead(); break; case ODB.ExecutedIRow: dataReader.InitializeIRow(executeResult, _recordsAffected); dataReader.BuildMetaInfo(); break; case ODB.PrepareICommandText: if (!_isPrepared) { PrepareCommandText(2); } OleDbDataReader.GenerateSchemaTable(dataReader, _icommandText, behavior); break; default: Debug.Assert(false, "ExecuteReaderInternal: unknown result type"); break; } executeResult = null; _hasDataReader = true; _connection.AddWeakReference(dataReader, OleDbReferenceCollection.DataReaderTag); // command stays in the executing state until the connection // has a datareader to track for it being closed state = ODB.InternalStateOpen; } finally { if (ODB.InternalStateOpen != state) { this.canceling = true; if (null != dataReader) { ((IDisposable)dataReader).Dispose(); dataReader = null; } } } Debug.Assert(null != dataReader, "ExecuteReader should never return a null DataReader"); } else { // optimized code path for ExecuteNonQuery to not create a OleDbDataReader object try { if (ODB.ExecutedIMultipleResults == resultType) { UnsafeNativeMethods.IMultipleResults multipleResults = (UnsafeNativeMethods.IMultipleResults)executeResult; // may cause a Connection.ResetState which closes connection nextResultsFailure = OleDbDataReader.NextResults(multipleResults, _connection, this, out _recordsAffected); } } finally { try { if (null != executeResult) { Marshal.ReleaseComObject(executeResult); executeResult = null; } CloseFromDataReader(ParameterBindings); } catch (Exception e) { // UNDONE - should not be catching all exceptions!!! if (!ADP.IsCatchableExceptionType(e)) { throw; } if (null != nextResultsFailure) { nextResultsFailure = new OleDbException(nextResultsFailure, e); } else { throw; } } } } } finally { // finally clear executing state try { if ((null == dataReader) && (ODB.InternalStateOpen != state)) { ParameterCleanup(); } } catch (Exception e) { // UNDONE - should not be catching all exceptions!!! if (!ADP.IsCatchableExceptionType(e)) { throw; } if (null != nextResultsFailure) { nextResultsFailure = new OleDbException(nextResultsFailure, e); } else { throw; } } if (null != nextResultsFailure) { throw nextResultsFailure; } } return(dataReader); }
//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; }
internal void DumpToSchemaTable(System.Data.Common.UnsafeNativeMethods.IRowset rowset) { List<System.Data.OleDb.MetaData> list = new List<System.Data.OleDb.MetaData>(); object propertyValue = null; using (OleDbDataReader reader = new OleDbDataReader(this._connection, this._command, -2147483648, CommandBehavior.Default)) { reader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero); reader.BuildSchemaTableInfo(rowset, true, false); propertyValue = this.GetPropertyValue(0x102); if (reader.FieldCount == 0) { return; } FieldNameLookup lookup = new FieldNameLookup(reader, -1); reader._fieldNameLookup = lookup; System.Data.OleDb.MetaData data20 = reader.FindMetaData("DBCOLUMN_IDNAME"); System.Data.OleDb.MetaData data19 = reader.FindMetaData("DBCOLUMN_GUID"); System.Data.OleDb.MetaData data18 = reader.FindMetaData("DBCOLUMN_PROPID"); System.Data.OleDb.MetaData data17 = reader.FindMetaData("DBCOLUMN_NAME"); System.Data.OleDb.MetaData data12 = reader.FindMetaData("DBCOLUMN_NUMBER"); System.Data.OleDb.MetaData data16 = reader.FindMetaData("DBCOLUMN_TYPE"); System.Data.OleDb.MetaData data11 = reader.FindMetaData("DBCOLUMN_COLUMNSIZE"); System.Data.OleDb.MetaData data15 = reader.FindMetaData("DBCOLUMN_PRECISION"); System.Data.OleDb.MetaData data14 = reader.FindMetaData("DBCOLUMN_SCALE"); System.Data.OleDb.MetaData data13 = reader.FindMetaData("DBCOLUMN_FLAGS"); System.Data.OleDb.MetaData data10 = reader.FindMetaData("DBCOLUMN_BASESCHEMANAME"); System.Data.OleDb.MetaData data9 = reader.FindMetaData("DBCOLUMN_BASECATALOGNAME"); System.Data.OleDb.MetaData data8 = reader.FindMetaData("DBCOLUMN_BASETABLENAME"); System.Data.OleDb.MetaData data7 = reader.FindMetaData("DBCOLUMN_BASECOLUMNNAME"); System.Data.OleDb.MetaData data6 = reader.FindMetaData("DBCOLUMN_ISAUTOINCREMENT"); System.Data.OleDb.MetaData data5 = reader.FindMetaData("DBCOLUMN_ISUNIQUE"); System.Data.OleDb.MetaData data4 = reader.FindMetaData("DBCOLUMN_KEYCOLUMN"); reader.CreateAccessors(false); while (reader.ReadRowset()) { reader.GetRowDataFromHandle(); System.Data.OleDb.MetaData item = new System.Data.OleDb.MetaData(); ColumnBinding columnBinding = data20.columnBinding; if (!columnBinding.IsValueNull()) { item.idname = (string) columnBinding.Value(); item.kind = 2; } columnBinding = data19.columnBinding; if (!columnBinding.IsValueNull()) { item.guid = columnBinding.Value_GUID(); item.kind = (2 == item.kind) ? 0 : 6; } columnBinding = data18.columnBinding; if (!columnBinding.IsValueNull()) { item.propid = new IntPtr((long) columnBinding.Value_UI4()); item.kind = (6 == item.kind) ? 1 : 5; } columnBinding = data17.columnBinding; if (!columnBinding.IsValueNull()) { item.columnName = (string) columnBinding.Value(); } else { item.columnName = ""; } if (4 == ADP.PtrSize) { item.ordinal = (IntPtr) data12.columnBinding.Value_UI4(); } else { item.ordinal = (IntPtr) data12.columnBinding.Value_UI8(); } short dbType = (short) data16.columnBinding.Value_UI2(); if (4 == ADP.PtrSize) { item.size = (int) data11.columnBinding.Value_UI4(); } else { item.size = ADP.IntPtrToInt32((IntPtr) data11.columnBinding.Value_UI8()); } columnBinding = data15.columnBinding; if (!columnBinding.IsValueNull()) { item.precision = (byte) columnBinding.Value_UI2(); } columnBinding = data14.columnBinding; if (!columnBinding.IsValueNull()) { item.scale = (byte) columnBinding.Value_I2(); } item.flags = (int) data13.columnBinding.Value_UI4(); bool isLong = IsLong(item.flags); bool isFixed = IsFixed(item.flags); NativeDBType type = NativeDBType.FromDBType(dbType, isLong, isFixed); item.type = type; if (data6 != null) { columnBinding = data6.columnBinding; if (!columnBinding.IsValueNull()) { item.isAutoIncrement = columnBinding.Value_BOOL(); } } if (data5 != null) { columnBinding = data5.columnBinding; if (!columnBinding.IsValueNull()) { item.isUnique = columnBinding.Value_BOOL(); } } if (data4 != null) { columnBinding = data4.columnBinding; if (!columnBinding.IsValueNull()) { item.isKeyColumn = columnBinding.Value_BOOL(); } } if (data10 != null) { columnBinding = data10.columnBinding; if (!columnBinding.IsValueNull()) { item.baseSchemaName = columnBinding.ValueString(); } } if (data9 != null) { columnBinding = data9.columnBinding; if (!columnBinding.IsValueNull()) { item.baseCatalogName = columnBinding.ValueString(); } } if (data8 != null) { columnBinding = data8.columnBinding; if (!columnBinding.IsValueNull()) { item.baseTableName = columnBinding.ValueString(); } } if (data7 != null) { columnBinding = data7.columnBinding; if (!columnBinding.IsValueNull()) { item.baseColumnName = columnBinding.ValueString(); } } list.Add(item); } } int count = list.Count; if (propertyValue is int) { count -= (int) propertyValue; } bool flag = false; for (int i = list.Count - 1; count <= i; i--) { System.Data.OleDb.MetaData data3 = list[i]; data3.isHidden = true; if (flag) { data3.isKeyColumn = false; } else if (data3.guid.Equals(ODB.DBCOL_SPECIALCOL)) { data3.isKeyColumn = false; flag = true; for (int k = list.Count - 1; i < k; k--) { list[k].isKeyColumn = false; } } } for (int j = count - 1; 0 <= j; j--) { System.Data.OleDb.MetaData data2 = list[j]; if (flag) { data2.isKeyColumn = false; } if (data2.guid.Equals(ODB.DBCOL_SPECIALCOL)) { data2.isHidden = true; count--; } else if (0 >= ((int) data2.ordinal)) { data2.isHidden = true; count--; } else if (DoColumnDropFilter(data2.flags)) { data2.isHidden = true; count--; } } list.Sort(); this._visibleFieldCount = count; this._metadata = list.ToArray(); }
private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method) { OleDbDataReader dataReader = null; OleDbException previous = null; int num2 = 0; try { object obj2; int num; this.ValidateConnectionAndTransaction(method); if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default) { behavior |= CommandBehavior.SingleResult; } switch (this.CommandType) { case ((System.Data.CommandType) 0): case System.Data.CommandType.Text: case System.Data.CommandType.StoredProcedure: num = this.ExecuteCommand(behavior, out obj2); break; case System.Data.CommandType.TableDirect: num = this.ExecuteTableDirect(behavior, out obj2); break; default: throw ADP.InvalidCommandType(this.CommandType); } if (this._executeQuery) { try { dataReader = new OleDbDataReader(this._connection, this, 0, this.commandBehavior); switch (num) { case 0: dataReader.InitializeIMultipleResults(obj2); dataReader.NextResult(); break; case 1: dataReader.InitializeIRowset(obj2, ChapterHandle.DB_NULL_HCHAPTER, this._recordsAffected); dataReader.BuildMetaInfo(); dataReader.HasRowsRead(); break; case 2: dataReader.InitializeIRow(obj2, this._recordsAffected); dataReader.BuildMetaInfo(); break; case 3: if (!this._isPrepared) { this.PrepareCommandText(2); } OleDbDataReader.GenerateSchemaTable(dataReader, this._icommandText, behavior); break; } obj2 = null; this._hasDataReader = true; this._connection.AddWeakReference(dataReader, 2); num2 = 1; return dataReader; } finally { if (1 != num2) { this.canceling = true; if (dataReader != null) { dataReader.Dispose(); dataReader = null; } } } } try { if (num == 0) { UnsafeNativeMethods.IMultipleResults imultipleResults = (UnsafeNativeMethods.IMultipleResults) obj2; previous = OleDbDataReader.NextResults(imultipleResults, this._connection, this, out this._recordsAffected); } } finally { try { if (obj2 != null) { Marshal.ReleaseComObject(obj2); obj2 = null; } this.CloseFromDataReader(this.ParameterBindings); } catch (Exception exception3) { if (!ADP.IsCatchableExceptionType(exception3)) { throw; } if (previous == null) { throw; } previous = new OleDbException(previous, exception3); } } } finally { try { if ((dataReader == null) && (1 != num2)) { this.ParameterCleanup(); } } catch (Exception exception2) { if (!ADP.IsCatchableExceptionType(exception2)) { throw; } if (previous == null) { throw; } previous = new OleDbException(previous, exception2); } if (previous != null) { throw previous; } } return dataReader; }
internal DataTable GetSchemaRowset(Guid schema, object[] restrictions) { IntPtr hscp; Bid.ScopeEnter(out hscp, "<oledb.OleDbConnectionInternal.GetSchemaRowset|INFO> %d#, schema=%ls, restrictions\n", ObjectID, schema); try { if (null == restrictions) { // MDAC 62243 restrictions = new object[0]; } DataTable dataTable = null; using(IDBSchemaRowsetWrapper wrapper = IDBSchemaRowset()) { UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset = wrapper.Value; if (null == dbSchemaRowset) { throw ODB.SchemaRowsetsNotSupported(Provider); } UnsafeNativeMethods.IRowset rowset = null; OleDbHResult hr; Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB> %d#\n", ObjectID); hr = dbSchemaRowset.GetRowset(ADP.PtrZero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, ADP.PtrZero, out rowset); Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB|RET> %08X{HRESULT}\n", hr); if (hr < 0) { // ignore infomsg ProcessResults(hr); } if (null != rowset) { using(OleDbDataReader dataReader = new OleDbDataReader(Connection, null, 0, CommandBehavior.Default)) { dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero); dataReader.BuildMetaInfo(); dataReader.HasRowsRead(); dataTable = new DataTable(); dataTable.Locale = CultureInfo.InvariantCulture; dataTable.TableName = OleDbSchemaGuid.GetTextFromValue(schema); OleDbDataAdapter.FillDataTable(dataReader, dataTable); } } return dataTable; } } finally { Bid.ScopeLeave(ref hscp); } }
private int FillFromRecordset(object data, System.Data.Common.UnsafeNativeMethods.ADORecordsetConstruction recordset, string srcTable, out bool incrementResultCount) { IntPtr ptr; incrementResultCount = false; object result = null; try { Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB>\n"); result = recordset.get_Rowset(); Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB|RET> %08X{HRESULT}\n", 0); Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB>\n"); ptr = recordset.get_Chapter(); Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB|RET> %08X{HRESULT}\n", 0); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } throw ODB.Fill_EmptyRecordSet("ADODBRecordSet", exception); } if (result != null) { CommandBehavior commandBehavior = (MissingSchemaAction.AddWithKey != base.MissingSchemaAction) ? CommandBehavior.Default : CommandBehavior.KeyInfo; commandBehavior |= CommandBehavior.SequentialAccess; OleDbDataReader dataReader = null; try { ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(ptr); dataReader = new OleDbDataReader(null, null, 0, commandBehavior); dataReader.InitializeIRowset(result, chapterHandle, ADP.RecordsUnaffected); dataReader.BuildMetaInfo(); incrementResultCount = 0 < dataReader.FieldCount; if (incrementResultCount) { if (data is DataTable) { return base.Fill((DataTable) data, dataReader); } return base.Fill((DataSet) data, srcTable, dataReader, 0, 0); } } finally { if (dataReader != null) { dataReader.Close(); } } } return 0; }