6.4.6.14 GetSchema(string collectionName, string[] restrictions)
このメソッドは、コレクション名に指定された文字列および制限値に指定された文字列配列を使用して、OracleConnection
のデータ・ソースのスキーマ情報を戻します。
宣言
// C# public override DataTable GetSchema (string collectionName, string[] restrictions);
パラメータ
-
collectionName
取得されるメタデータのコレクション名。
-
restrictions
取得されるメタデータに適用される制限の配列。
戻り値
DataTable
オブジェクト。
例外
-
ArgumentException
- 要求されたコレクションが定義されていません。 -
InvalidOperationException
- 次の条件の1つが存在します。-
接続がクローズされています。
-
要求されたコレクションは現行バージョンのOracle Databaseではサポートされていません。
-
要求されたコレクションがサポートしているよりも多くの制限が指定されています。
-
要求されたコレクションに対して移入文字列が指定されていません。
-
備考
このメソッドは、メタデータ・コレクションの名前と、戻されたDataTable
内の行をフィルタする制限を指定する文字列値の配列を取得します。これは、指定された制限と一致する指定されたメタデータ・コレクションからの行のみが含まれるDataTable
を戻します。
たとえば、Columns
コレクションに3つの制限(owner
、tablename
およびcolumnname
)がある場合、スキーマにかかわらずEMP
表に対するすべての列を取得するには、GetSchema
メソッドで最低でも値nullとEMP
を渡す必要があります。
制限値が何も渡されない場合、その制限にはNullを渡すことと同じデフォルト値が使用されます。これは、パラメータ値に空の文字列を渡すこととは異なります。この場合、空の文字列(""
)は指定されたパラメータの値を考慮します。
collectionName
では大文字小文字は区別されませんが、制限(文字列値)では区別されます。
例
// C# using System; using System.Data; using System.Data.Common; using Oracle.DataAccess.Client; class GetSchemaSample { static void Main(string[] args) { string constr = "User Id=scott; Password=tiger; Data Source=oracle;"; string ProviderName = "Oracle.DataAccess.Client"; DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName); using (DbConnection conn = factory.CreateConnection()) { try { conn.ConnectionString = constr; conn.Open(); //Get Restrictions DataTable dtRestrictions = conn.GetSchema(DbMetaDataCollectionNames.Restrictions); DataView dv = dtRestrictions.DefaultView; dv.RowFilter = "CollectionName = 'Columns'"; dv.Sort = "RestrictionNumber"; for (int i = 0; i < dv.Count; i++) Console.WriteLine("{0} (default) {1}" , dtRestrictions.Rows[i]["RestrictionName"], dtRestrictions.Rows[i]["RestrictionDefault"]); //Set restriction string array string[] restrictions = new string[3]; //Get all columns from all tables owned by "SCOTT" restrictions[0] = "SCOTT"; DataTable dtAllScottCols = conn.GetSchema("Columns", restrictions); // clear collection for (int i = 0; i < 3; i++) restrictions[i] = null; //Get all columns from all tables named "EMP" owned by any //owner/schema restrictions[1] = "EMP"; DataTable dtAllEmpCols = conn.GetSchema("Columns", restrictions); // clear collection for (int i = 0; i < 3; i++) restrictions[i] = null; //Get columns named "EMPNO" from tables named "EMP", //owned by any owner/schema restrictions[1] = "EMP"; restrictions[2] = "EMPNO"; DataTable dtAllScottEmpCols = conn.GetSchema("Columns", restrictions); // clear collection for (int i = 0; i < 3; i++) restrictions[i] = null; //Get columns named "EMPNO" from all //tables, owned by any owner/schema restrictions[2] = "EMPNO"; DataTable dtAllEmpNoCols = conn.GetSchema("Columns", restrictions); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); } } } }