DB2 Version 10.1 for Linux, UNIX, and Windows

DB2DataReader.GetSchemaTable Method

Returns a DataTable that describes the column metadata of the DB2DataReader.

Namespace:
IBM®.Data.DB2®
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax

[Visual Basic]
Public Function GetSchemaTable() As DataTable
[C#]
public DataTable GetSchemaTable();
[C++]
public: DataTable* GetSchemaTable();
[JScript]
public function GetSchemaTable() : DataTable;

Return value

A DataTable that describes the column metadata.

Exceptions

Exception type Condition
InvalidOperationException The DB2DataReader is closed.

Remarks

The GetSchemaTable method returns metadata about each column in the following order.

Field name Description
ColumnName The name of the column if it can be determined; this name might not be unique. The name always reflects the most recent name of the column in the current view or command text. If the column name cannot be determined, a null value is returned.
ColumnOrdinal The ordinal of the column. This value is zero for the bookmark column of the row, if any. Other columns are numbered starting with 1. This field cannot contain a null value.
ColumnSize The maximum possible length of a value in the column. For columns that use a fixed-length data type, this value is the size of the data type.
NumericPrecision If the DB2 Data Type is a numeric data type, the maximum precision of the column; otherwise, null.
NumericScale If the DB2 Data Type is decimal, the number of digits to the right of the decimal point; otherwise, null.
DataType A data type that maps to the DB2 Data Type.
ProviderType The DB2Type enumeration.
IsLong true if the column contains a binary large object (BLOB) that contains very long data.
AllowDBNull true if the consumer can set the column to a null value or if the driver cannot determine whether the consumer can set the column to a null value; otherwise, false. A column can contain a null value, even if it cannot be set to a null value.
IsReadOnly true if the column cannot be modified; otherwise, false.
IsRowVersion Set if the column contains a persistent row identifier that cannot be written to.
IsUnique
true or false, defined as follows:
  • true. No two rows in the base table, that is returned in BaseTableName, can have the same value in this column. The value of th IsUnique column is guaranteed to be true if the column constitutes a key by itself or if there is a constraint of type UNIQUE that applies only to this column.
  • false. The column in the base table can contain duplicate values. The default value for the IsUnique column is false. For tables with composite primary keys, the value of the IsUnique column is reported as false even if a unique constraint exists on one or more of the columns.
IsKey true or false, defined as follows:
  • true. The column is one of a set of columns in the rowset that, when taken together, uniquely identify the row in the rowset. This set of columns does not have to be a minimal set of columns. This set of columns can be generated from a base table primary key, a unique constraint, or a unique index.
  • false. The column is not required to uniquely identify the row.
IsAutoIncrement true if the column assigns values to new rows in fixed increments; otherwise, false. The default for this column is false.
BaseSchemaName The name of the schema in the database that contains the column if the base schema name can be determined. The value of BaseSchemaName is a null value if the base schema name cannot be determined. The default for this column is a null value.
BaseCatalogName The name of the catalog in the database that contains the column if the catalog name can be determined. The value of BaseCatalogName is a null value if the base catalog name cannot be determined. The default for this column is a null value.
BaseTableName The name of the table or view in the database that contains the column if the name of the table can be determined. The value of BaseTableName is a null value if the base table name cannot be determined. The default for this column is a null value.
BaseColumnName The name of the column in the database, if possible. This name might be different than the column name returned in the ColumnName column if you used an alias. The value of the BaseColumnName column is a null value if the base column name cannot be determined or if the rowset column is derived from, but is not identical to, a column in the database. The default for the BaseColumnName column is a null value.
ModuleName
  • Schema data table returned by the DB2DataReader.GetSchemaTable() call will now include a nullable ModuleName column that will be set when procedures belonging to a module are used. This new column ModuleName will be inserted at the end of the DataTable so that applications that access the value by ordinal numbers are not affected. Thus a fully qualified name of a procedure schema.module.procname will be split into 3 columns of the schema data table BaseSchemaName, ModuleName and BaseTableName respectively.
  • Schema data table returned by the DB2Connection.GetSchema() call will now report Module name for the Procedures and ProcedureParameters collections. In addition, the restriction set for each of those collections will be augmented to include the Module name as one of the search parameters.

A row is returned for every column in the result set.

DB2CommandBuilder needs to correctly identify the primary keys of a table to work correctly. If the BaseTableName column is not returned for every column in the results of a query, IBM Data Server Provider for .NET tries to parse the SQL statement to find the table names involved in the query. This approach works with UPDATE, INSERT, DELETE and simple SELECT statements but not with stored procedures or SELECT statements that are based on joins. If some or all of the schema information is missing from a table, the DB2CommandBuilder does not work correctly because it does not have enough schema information to automatically generate the correct INSERT, UPDATE, or DELETE statements.