Skip to content

SQLTablePrivileges

SQLTablePrivileges#

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.

SQLTablePrivilegesW() as a Unicode string supports same execution as SQLTablePrivileges().

Syntax#

SQLRETURN  SQLTablePrivileges(
    SQLHSTMT        stmt,   
    SQLCHAR *       cName,  
    SQLSMALLINT     cNaneLength,        
    SQLCHAR *       sName,      
    SQLSMALLINT     sNameLength,        
    SQLCHAR *       tName, 
    SQLSMALLINT     tNameLength);

Arguments#

Data Type Argument In/Out Description
SQLHSTMT stmt Input Statement handle
SQLCHAR* cName Input Catalog nam
SQLSMALLINT cNameLength Input The length, in bytes, of *cName
SQLCHAR * sName Input Name of the schema to retrieve
SQLSMALLINT sNameLength Input The length, in bytes, of *sName
SQLCHAR * tName Input Table name to retrieve
SQLSMALLINT tNameLength Input The length, in bytes, of *tName

Result Values#

SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR

Description#

SQLTablePrivileges() returns the data in the standard result set format sorted by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, PRIVILEGE, and GRANTEE.

Column Name No. Data Type Description
TABLE_CAT 1 VARCHAR Always NULL Return
TABLE_SCHEM 2 VARCHAR Schema name.
NULL if not applicable to the database.
TABLE_NAME 3 VARCHAR (NOT NULL) Table name
GRANTOR 4 VARCHAR Name of the user who granted the privilege
NULL if not applicable to the database.
GRANTEE 5 VARCHAR (NOT NULL) Name of the user to whom the privilege was granted.
PRIVILEGE 6 VARCHAR (NOT NULL) Table privilege. One of the following privileges:
- ALTER: The grantee can change the definition of the table.
- DELETE: The grantee can dele the rows in the table.
- INDEX: The grantee can perform index operations (such as create or alter) for the table.
- INSERT: The grantee can insert new rows to the table.
- REFERENCES: The grantee can refer to the columns of the table with the limited conditions.
- SELECT: The grantee can search one or multiple columns in the table.
- UPDATE: The grantee can modify one or more data for the table.
IS_GRANTABLE 7 VARCHAR Indicates whether the grantee can give privilege to other users. Yes. No. Or NULL if unknown or not applicable to the database.

[Table 2‑6] Columns Returned by SQLTablePrivileges()

Diagnosis#

SQLSTATE Description Comments
08S01 Communication channel error Communication channel failure before the function processing is completed between the Altibase CLI driver and the database
HY009 Invalid Arguments used (null pointer). Argument cName is a NULL pointer.
HY090 Invalid character string or buffer length One of the name length Arguments is smaller than 0 or is not equal to SQL_NTS.
SQLBindCol
SQLCancel
SQLColumns
SQLFetch
SQLPrimaryKeys
SQLStatistics
SQLTables

Example#

< Refer to: $ALTIBASE_HOME/sample/SQLCLI/demo_meta10.cpp >

if (SQLTablePrivileges(stmt,
                       NULL, 0,
                       "SYS", SQL_NTS,
                       "DEMO_META10", SQL_NTS) != SQL_SUCCESS)
    {
        execute_err(dbc, stmt, "SQLTablePrivileges");
        SQLFreeStmt(stmt, SQL_DROP);
        return SQL_ERROR;
    }

    SQLBindCol(stmt, 2, SQL_C_CHAR, szSchema, NAME_LEN, &cbSchema);
    SQLBindCol(stmt, 3, SQL_C_CHAR, szTableName, NAME_LEN,&cbTableName);
    SQLBindCol(stmt, 4, SQL_C_CHAR, szGrantor, NAME_LEN, &cbGrantor);
    SQLBindCol(stmt, 5, SQL_C_CHAR, szGrantee, NAME_LEN, &cbGrantee);
    SQLBindCol(stmt, 6, SQL_C_CHAR, szPrivilege, NAME_LEN,&cbPrivilege);
    SQLBindCol(stmt, 7, SQL_C_CHAR, szGrantable, 5, &cbGrantable);