MDAC 2.5 SDK - ODBC Programmer's Reference
Chapter 21: ODBC API Reference
Conformance
Version Introduced: ODBC 1.0
Standards Compliance: ODBC
Summary
SQLTablePrivileges returns a list of tables and the privileges associated with each table. The driver returns the information as a result set on the specified statement.
Syntax
SQLRETURN SQLTablePrivileges(
SQLHSTMT StatementHandle,
SQLCHAR * CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR * SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR * TableName,
SQLSMALLINT NameLength3);
Arguments
StatementHandle
[Input]
Statement handle.
CatalogName
[Input]
Table catalog. If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have catalogs. CatalogName cannot contain a string search pattern.
If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, CatalogName is treated as an identifier and its case is not significant. If it is SQL_FALSE, CatalogName is an ordinary argument; it is treated literally, and its case is significant. For more information, see "Arguments in Catalog Functions" in Chapter 7, "Catalog Functions."
NameLength1
[Input]
Length of *CatalogName.
SchemaName
[Input]
String search pattern for schema names. If a driver supports schemas for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have schemas.
If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, SchemaName is treated as an identifier and its case is not significant. If it is SQL_FALSE, SchemaName is a pattern value argument; it is treated literally, and its case is significant.
NameLength2
[Input]
Length of *SchemaName.
TableName
[Input]
String search pattern for table names.
If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, TableName is treated as an identifier and its case is not significant. If it is SQL_FALSE, TableName is a pattern value argument; it is treated literally, and its case is significant.
NameLength3
[Input]
Length of *TableName.
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLTablePrivileges returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle. The following table lists the SQLSTATE values commonly returned by SQLTablePrivileges and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
Comments
The SchemaName and TableName arguments accept search patterns. For more information about valid search patterns, see "Pattern Value Arguments" in Chapter 7, "Catalog Functions."
SQLTablePrivileges returns the results as a standard result set, ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, PRIVILEGE, and GRANTEE.
To determine the actual lengths of the TABLE_CAT, TABLE_SCHEM, and TABLE_NAME columns, an application can call SQLGetInfo with the SQL_MAX_CATALOG_NAME_LEN, SQL_MAX_SCHEMA_NAME_LEN, and SQL_MAX_TABLE_NAME_LEN options.
Note For more information about the general use, arguments, and returned data of ODBC catalog functions, see Chapter 7, "Catalog Functions."
The following columns have been renamed for ODBC 3.x. The column name changes do not affect backward compatibility because applications bind by column number.
ODBC 2.0 column | ODBC 3.x column |
TABLE_QUALIFIER | TABLE_CAT |
TABLE_OWNER | TABLE_SCHEM |
The following table lists the columns in the result set. Additional columns beyond column 7 (IS_GRANTABLE) can be defined by the driver. An application should gain access to driver-specific columns by counting down from the end of the result set rather than specifying an explicit ordinal position. For more information, see "Data Returned by Catalog Functions" in Chapter 7, "Catalog Functions."
Column name |
Column number | Data type |
Comments |
TABLE_CAT (ODBC 1.0) |
1 | Varchar | Catalog name; NULL if not applicable to the data source. If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have catalogs. |
TABLE_SCHEM (ODBC 1.0) |
2 | Varchar | Schema name; NULL if not applicable to the data source. If a driver supports schemas for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have schemas. |
TABLE_NAME (ODBC 1.0) |
3 | Varchar not NULL |
Table name. |
GRANTOR (ODBC 1.0) |
4 | Varchar | Name of the user who granted the privilege; NULL if not applicable to the data source.
For all rows in which the value in the GRANTEE column is the owner of the object, the GRANTOR column will be "_SYSTEM". |
GRANTEE (ODBC 1.0) |
5 | Varchar not NULL |
Name of the user to whom the privilege was granted. |
PRIVILEGE (ODBC 1.0) |
6 | Varchar not NULL |
The table privilege. May be one of the following or a data source–specific privilege.
SELECT: The grantee is permitted to retrieve data for one or more columns of the table. INSERT: The grantee is permitted to insert new rows containing data for one or more columns into the table. UPDATE: The grantee is permitted to update the data in one or more columns of the table. DELETE: The grantee is permitted to delete rows of data from the table. REFERENCES: The grantee is permitted to refer to one or more columns of the table within a constraint (for example, a unique, referential, or table check constraint). The scope of action permitted the grantee by a given table privilege is data source–dependent. For example, the UPDATE privilege might permit the grantee to update all columns in a table on one data source and only those columns for which the grantor has the UPDATE privilege on another data source. |
IS_GRANTABLE (ODBC 1.0) |
7 | Varchar | Indicates whether the grantee is permitted to grant the privilege to other users; "YES", "NO", or NULL if unknown or not applicable to the data source.
A privilege is either grantable or not grantable but not both. The result set returned by SQLColumnPrivileges will never contain two rows for which all columns except the IS_GRANTABLE column contain the same value. |
Code Example
For a code example of a similar function, see SQLColumns.
Related Functions
For information about | See |
Binding a buffer to a column in a result set | SQLBindCol |
Canceling statement processing | SQLCancel |
Returning privileges for a column or columns | SQLColumnPrivileges |
Returning the columns in a table or tables | SQLColumns |
Fetching a single row or a block of data in a forward-only direction | SQLFetch |
Fetching a block of data or scrolling through a result set | SQLFetchScroll |
Returning table statistics and indexes | SQLStatistics |
Returning a list of tables in a data source | SQLTables |