Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data / System / Data / OleDb / OleDbEnumerator.cs
blobfdd83b9c030d60e3841b2a16c33c4e8295e3803d
1 //------------------------------------------------------------------------------
2 // <copyright file="OleDbEnumerator.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
9 namespace System.Data.OleDb {
11 using System;
12 using System.ComponentModel;
13 using System.Data.Common;
14 using System.Globalization;
15 using System.Security;
16 using System.Security.Permissions;
18 public sealed class OleDbEnumerator {
20 public OleDbEnumerator() {
23 public DataTable GetElements() {
24 OleDbConnection.ExecutePermission.Demand();
26 DataTable dataTable = new DataTable("MSDAENUM"); // WebData 112482
27 dataTable.Locale = CultureInfo.InvariantCulture;
28 OleDbDataReader dataReader = GetRootEnumerator();
29 OleDbDataAdapter.FillDataTable(dataReader, dataTable);
30 return dataTable;
33 static public OleDbDataReader GetEnumerator(Type type) {
34 OleDbConnection.ExecutePermission.Demand();
36 return GetEnumeratorFromType(type);
39 static internal OleDbDataReader GetEnumeratorFromType(Type type) { // WebData 99005
40 // will demand security appropriately
41 object value = Activator.CreateInstance(type, System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Instance, null, null, CultureInfo.InvariantCulture, null);
42 return GetEnumeratorReader(value);
45 static private OleDbDataReader GetEnumeratorReader(object value) {
46 NativeMethods.ISourcesRowset srcrowset = null;
48 try {
49 srcrowset = (NativeMethods.ISourcesRowset) value;
51 catch(InvalidCastException) {
52 throw ODB.ISourcesRowsetNotSupported();
54 if (null == srcrowset) {
55 throw ODB.ISourcesRowsetNotSupported();
57 value = null; // still held by ISourcesRowset, reused for IRowset
59 int propCount = 0;
60 IntPtr propSets = ADP.PtrZero;
62 Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB> IID_IRowset\n");
63 OleDbHResult hr = srcrowset.GetSourcesRowset(ADP.PtrZero, ODB.IID_IRowset, propCount, propSets, out value);
64 Bid.Trace("<oledb.ISourcesRowset.GetSourcesRowset|API|OLEDB|RET> %08X{HRESULT}\n", hr);
66 Exception f = OleDbConnection.ProcessResults(hr, null, null);
67 if (null != f) {
68 throw f;
71 OleDbDataReader dataReader = new OleDbDataReader(null, null, 0, CommandBehavior.Default);
72 dataReader.InitializeIRowset(value, ChapterHandle.DB_NULL_HCHAPTER, ADP.RecordsUnaffected);
73 dataReader.BuildMetaInfo();
74 dataReader.HasRowsRead();
75 return dataReader;
78 static public OleDbDataReader GetRootEnumerator() {
79 OleDbConnection.ExecutePermission.Demand();
81 IntPtr hscp;
82 Bid.ScopeEnter(out hscp, "<oledb.OleDbEnumerator.GetRootEnumerator|API>\n");
83 try {
84 //readonly Guid CLSID_MSDAENUM = new Guid(0xc8b522d0,0x5cf3,0x11ce,0xad,0xe5,0x00,0xaa,0x00,0x44,0x77,0x3d);
85 //Type msdaenum = Type.GetTypeFromCLSID(CLSID_MSDAENUM, true);
86 const string PROGID_MSDAENUM = "MSDAENUM";
87 Type msdaenum = Type.GetTypeFromProgID(PROGID_MSDAENUM, true);
88 return GetEnumeratorFromType(msdaenum);
90 finally {
91 Bid.ScopeLeave(ref hscp);