SQLGetSchema

Syntax

SQLGetSchema(ConnectNum, Type, Qualifier$)

Remarks

Establishes a pseudo-query on a data source connection to provide information about the schema (structure) of the data source. After SQLGetSchema establishes a pseudo-query and returns a value describing the available information, use SQLGetSchemaItem$ one or more times to return the available string or strings of information about the data source structure. SQLGetSchema works with the ODBC API functions SQLGetInfo and SQLTables to find the requested information; for complete information about these API functions, see the Microsoft ODBC Programmer's Reference in the Microsoft ODBC Software Development Kit version 2.10.

For a complete example macro using SQLGetSchema, see the third example macro described in "Using the ODBC Extensions" earlier in this appendix.

Arguments

Explanation

ConnectNum

The unique connection ID of the data source you want information about, returned by a previously executed SQLOpen function. If ConnectNum is not valid, SQLGetSchema returns 0 (zero).

Type

A value between 1 and 14 that specifies the type of information
you want returned. For descriptions of the information that can be returned, see the table of return values, following.

Qualifier$

A text string used to qualify the search for the requested information. This string should be enclosed by quotation marks. Note that Qualifier$ is only included for Type values of 3, 4, and 5. For other Type values, Qualifier$ should be an empty string ("").

If Type is 3, Qualifier$ should be the name of a database in the current data source. SQLGetSchema will then only return the number of table owners in that database. If you specify an empty string (""), the function will return the number of all owners of all databases on ConnectNum.

If Type is 4, Qualifier$ should be both a database name and an owner name. The syntax of Qualifier$ is "Database.Owner". SQLGetSchema will then return the number of tables that are located in the given database and owned by the given owner. If you specify an empty string (""), the function will return the number of all table names in all databases owned by all owners on ConnectNum.

If Type is 5, Qualifier$ should be the name of a table. Information about the columns in that table will be returned.


The numeric value returned by the SQLGetSchema function depends on the value of the Type argument that was passed, as described in the following table. Use SQLGetSchemaItem$ one or more times to return the available string or strings, as indicated by the numeric return value of SQLGetSchema.

Type

Meaning of return value

1

Number of available data sources.

2

Number of databases on the current connection.

3

Number of owners in a database on the current connection. This Type requires that a value be specified for Qualifier$.

4

Number of tables for a given owner and database on the current connection. This Type requires that a value be specified for Qualifier$.

5

Number describing a two-dimensional array listing the columns in
a particular table and their data types. The return value is the total number of string values available. The odd-numbered items are the names of the columns. The even-numbered items are the data types of the columns. This Type requires that a value be specified for Qualifier$.

6

If a non-error value, the user ID of the current user is available.

7

If a non-error value, the name of the current database is available.

8

If a non-error value, the name of the data source as given in the ODBC.INI file (Windows 3.x) or the registry (Windows 95 and Windows NT) is available.

9

If a non-error value, the name of the data source DBMS (i.e. Oracle, SQL Server, etc.) is available.

10

If a non-error value, the name of the server name for the data source is available.

11

If a non-error value, the terminology used by the data source to refer to owners ( i.e. "owner", "Authorization ID", "Schema", etc.) is available.

12

If a non-error value, the terminology used by the data source to refer to tables ( i.e. "table", "file", etc.) is available.

13

If a non-error value, the terminology used by the data source to refer to qualifiers (i.e. "database" or "directory") is available.

14

If a non-error value, the terminology used by the data source to refer to procedures (i.e. "database procedure", "stored procedure", or "procedure") is available.


Note

The SQLGetSchema function should not overwrite the pending results of another query sent to the same data source. To avoid overwriting pending query results, establish a new connection to the data source using SQLOpen, and specify the resulting connection ID for SQLGetSchema.