|
Obtains database schema information from the provider.
Set recordset = connection.OpenSchema (QueryType,
Criteria, SchemaID)
QueryType
The type of schema query to run. Can be any of the constants listed below.
Criteria
Optional array of query constraints for each QueryType option, as listed below:
QueryType values |
Criteria values |
adSchemaAsserts |
CONSTRAINT_CATALOG |
adSchemaCatalogs |
CATALOG_NAME |
asSchemaCharacterSets |
CHARACTER_SET_CATALOG |
adSchemaCheckConstraints |
CONSTRAINT_CATALOG |
adSchemaCollations |
COLLATION_CATALOG |
adSchemaColumnDomainUsage |
DOMAIN_CATALOG |
adSchemaColumnPrivileges |
TABLE_CATALOG |
adSchemaColumns |
TABLE_CATALOG |
adSchemaConstraintTableUsage |
TABLE_CATALOG |
adSchemaForeignKeys |
PK_TABLE_CATALOG |
adSchemaIndexes |
TABLE_CATALOG |
adSchemaKeyColumnUsage |
CONSTRAINT_CATALOG |
adSchemaPrimaryKeys |
PK_TABLE_CATALOG |
adSchemaProcedureColumns |
PROCEDURE_CATALOG |
adSchemaProcedures |
PROCEDURE_CATALOG |
adSchemaProviderSpecific |
see Remarks |
adSchemaProviderTypes |
DATA_TYPE |
adSchemaReferentialConstraints |
CONSTRAINT_CATALOG |
adSchemaSchemata |
CATALOG_NAME |
adSchemaSQLLanguages |
<none> |
adSchemaStatistics |
TABLE_CATALOG |
adSchemaTableConstraints |
CONSTRAINT_CATALOG |
adSchemaTablePrivileges |
TABLE_CATALOG |
adSchemaTables |
TABLE_CATALOG |
adSchemaTranslations |
TRANSLATION_CATALOG |
adSchemaUsagePrivileges |
OBJECT_CATALOG |
adSchemaViewColumnUsage |
VIEW_CATALOG |
adSchemaViewTableUsage |
VIEW_CATALOG |
adSchemaViews |
TABLE_CATALOG |
SchemaID
The GUID for a provider-schema schema query is not defined by the OLE DB 1.1 specification. This parameter is required if QueryType is set to adSchemaProviderSpecific; otherwise, it is not used.
Returns an ADO Recordset Object that contains schema information.
The OpenSchema method returns information about the data source, such as information about the tables on the server and the columns in the tables.
The Criteria argument is an array of values that can be used to limit the results of a schema query. Each schema query has a different set of parameters that it supports. The actual schemas are defined by the OLE DB specification under the "IDBSchemaRowset" interface. The ones supported in ADO 1.5 are listed above.
The constant adSchemaProviderSpecific is used for the QueryType argument if the provider defines its own non-standard schema queries outside those listed above. When this constant is used, the SchemaID argument is required to pass the GUID of the schema query to execute. If QueryType is set to adSchemaProviderSpecific but SchemaID is not provided, an error will result.
Providers are not required to support all of the OLE DB standard schema queries. Specifically, only adSchemaTables, adSchemaColumns and adSchemaProviderTypes are required by the OLE DB specification. However, the provider is not required to support the Criteria constraints listed above for those schema queries.
This Visual Basic example uses the OpenSchema method to display the name and type of each table in the Pubs database.
Public Sub OpenSchemaX()
Dim cnn1 As ADODB.Connection
Dim rstSchema As ADODB.Recordset
Dim strCnn As String
Set cnn1 = New ADODB.Connection
strCnn = "driver={SQL Server};server=srv;" & _
"uid=sa;pwd=;database=pubs"
cnn1.Open strCnn
Set rstSchema = cnn1.OpenSchema(adSchemaTables)
Do Until rstSchema.EOF
Debug.Print "Table name: " & _
rstSchema!TABLE_NAME & vbCr & _
"Table type: " & rstSchema!TABLE_TYPE & vbCr
rstSchema.MoveNext
Loop
rstSchema.Close
cnn1.Close
End Sub
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.