SQLRETURN SQL_API SQLColumnPrivilegesA(SQLHSTMT StatementHandle, SQLCHAR *CatalogName, SQLSMALLINT NameLength1, SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName, SQLSMALLINT NameLength3, SQLCHAR *ColumnName, SQLSMALLINT NameLength4) { return SQLColumnPrivileges(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, ColumnName, NameLength4); }
SQLRETURN SQLColumnPrivilegesA( SQLHSTMT statement_handle, SQLCHAR *catalog_name, SQLSMALLINT name_length1, SQLCHAR *schema_name, SQLSMALLINT name_length2, SQLCHAR *table_name, SQLSMALLINT name_length3, SQLCHAR *column_name, SQLSMALLINT name_length4 ) { return SQLColumnPrivileges( statement_handle, catalog_name, name_length1, schema_name, name_length2, table_name, name_length3, column_name, name_length4 ); }
/* get the column privileges that meet specified criteria */ int TbListColumnPrivileges(SQLHANDLE hdbc) { SQLRETURN cliRC = SQL_SUCCESS; int rc = 0; SQLHANDLE hstmt; /* statement handle */ SQLHANDLE hstmtTable; struct { SQLINTEGER ind; SQLCHAR val[129]; } colName, grantor, grantee, privilege; struct { SQLINTEGER ind; SQLCHAR val[4]; } is_grantable; /* criteria to look for */ SQLCHAR tbSchema[] = "SCHEMA"; SQLCHAR tbName[] = "TABLE_NAME"; SQLCHAR colNamePattern[] = "%"; SQLCHAR stmt[100]; printf("\n-----------------------------------------------------------"); printf("\nUSE THE CLI FUNCTIONS\n"); printf(" SQLSetConnectAttr\n"); printf(" SQLAllocHandle\n"); printf(" SQLTablePrivileges\n"); printf(" SQLBindCol\n"); printf(" SQLFetch\n"); printf(" SQLFreeHandle\n"); printf("TO GET COLUMN PRIVILEGES THAT MEET SPECIFIED CRITERIA:\n"); /* set AUTOCOMMIT on */ cliRC = SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS); DBC_HANDLE_CHECK(hdbc, cliRC); /* allocate a statement handle */ cliRC = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmtTable); DBC_HANDLE_CHECK(hdbc, cliRC); /* create a test table */ sprintf((char *)stmt, "CREATE TABLE %s.%s (COL1 CHAR(10))", tbSchema, tbName); printf("\n Directly execute\n"); printf(" %s\n", stmt); /* directly execute the statement */ cliRC = SQLExecDirect(hstmtTable, stmt, SQL_NTS); STMT_HANDLE_CHECK(hstmtTable, hdbc, cliRC); /* allocate a statement handle */ cliRC = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); DBC_HANDLE_CHECK(hdbc, cliRC); /* call SQLColumnPrivileges */ printf("\n Call SQLColumnPrivileges for:\n"); printf(" tbSchema = %s\n", tbSchema); printf(" tbName = %s\n", tbName); /* get privileges associated with the columns of a table */ cliRC = SQLColumnPrivileges(hstmt, NULL, 0, tbSchema, SQL_NTS, tbName, SQL_NTS, colNamePattern, SQL_NTS); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); /* bind column 4 to variable */ cliRC = SQLBindCol(hstmt, 4, SQL_C_CHAR, colName.val, 129, &colName.ind); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); /* bind column 5 to variable */ cliRC = SQLBindCol(hstmt, 5, SQL_C_CHAR, (SQLPOINTER)grantor.val, 129, &grantor.ind); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); /* bind column 6 to variable */ cliRC = SQLBindCol(hstmt, 6, SQL_C_CHAR, (SQLPOINTER)grantee.val, 129, &grantee.ind); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); /* bind column 7 to variable */ cliRC = SQLBindCol(hstmt, 7, SQL_C_CHAR, (SQLPOINTER)privilege.val, 129, &privilege.ind); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); /* bind column 8 to variable */ cliRC = SQLBindCol(hstmt, 8, SQL_C_CHAR, (SQLPOINTER)is_grantable.val, 4, &is_grantable.ind); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); /* fetch each row and display */ printf("\n Current User's Privileges for table %s.%s\n", tbSchema, tbName); printf(" Column Grantor Grantee Privilege Grantable\n"); printf(" ------- -------- ------------ ---------- ---------\n"); /* fetch next row */ cliRC = SQLFetch(hstmt); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); if (cliRC == SQL_NO_DATA_FOUND) { printf("\n Data not found.\n"); } while (cliRC != SQL_NO_DATA_FOUND) { printf(" %-7s", colName.val); printf(" %-8s", grantor.val); printf(" %-12s", grantee.val); printf(" %-10s", privilege.val); printf(" %-3s\n", is_grantable.val); /* fetch next row */ cliRC = SQLFetch(hstmt); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); } /* endwhile */ /* free the statement handle */ cliRC = SQLFreeHandle(SQL_HANDLE_STMT, hstmt); STMT_HANDLE_CHECK(hstmt, hdbc, cliRC); /* drop the test table */ sprintf((char *)stmt, "DROP TABLE %s.%s", tbSchema, tbName); printf("\n Directly execute\n"); printf(" %s\n", stmt); /* directly execute the statement */ cliRC = SQLExecDirect(hstmtTable, stmt, SQL_NTS); STMT_HANDLE_CHECK(hstmtTable, hdbc, cliRC); /* free the statement handle */ cliRC = SQLFreeHandle(SQL_HANDLE_STMT, hstmtTable); STMT_HANDLE_CHECK(hstmtTable, hdbc, cliRC); return rc; } /* TbListColumnPrivileges */
static int odbc_dispatch17(void) { unsigned long retval; PWord rval; int rtype; PWord arg1; int type1; PWord arg2; int type2; PWord arg3; int type3; PWord arg4; int type4; PWord arg5; int type5; PWord arg6; int type6; PWord arg7; int type7; PWord arg8; int type8; PWord arg9; int type9; PWord arg10; int type10; PWord arg11; int type11; PI_getan(&arg1,&type1,1); if (type1 != PI_INT) if (!CI_get_integer((unsigned long *)&arg1,type1)) PI_FAIL; PI_getan(&arg2,&type2,2); if (type2 != PI_INT) if (!CI_get_integer((unsigned long *)&arg2,type2)) PI_FAIL; PI_getan(&arg3,&type3,3); if (type3 == PI_SYM) arg3 = (unsigned long) PI_getsymname(0,arg3,0); else if (!CI_get_integer((unsigned long *)&arg3,type3)) PI_FAIL; PI_getan(&arg4,&type4,4); if (type4 != PI_INT) if (!CI_get_integer((unsigned long *)&arg4,type4)) PI_FAIL; PI_getan(&arg5,&type5,5); if (type5 == PI_SYM) arg5 = (unsigned long) PI_getsymname(0,arg5,0); else if (!CI_get_integer((unsigned long *)&arg5,type5)) PI_FAIL; PI_getan(&arg6,&type6,6); if (type6 != PI_INT) if (!CI_get_integer((unsigned long *)&arg6,type6)) PI_FAIL; PI_getan(&arg7,&type7,7); if (type7 == PI_SYM) arg7 = (unsigned long) PI_getsymname(0,arg7,0); else if (!CI_get_integer((unsigned long *)&arg7,type7)) PI_FAIL; PI_getan(&arg8,&type8,8); if (type8 != PI_INT) if (!CI_get_integer((unsigned long *)&arg8,type8)) PI_FAIL; PI_getan(&arg9,&type9,9); if (type9 == PI_SYM) arg9 = (unsigned long) PI_getsymname(0,arg9,0); else if (!CI_get_integer((unsigned long *)&arg9,type9)) PI_FAIL; PI_getan(&arg10,&type10,10); if (type10 != PI_INT) if (!CI_get_integer((unsigned long *)&arg10,type10)) PI_FAIL; PI_getan(&arg11,&type11,11); switch(arg1) { case 0: retval = (unsigned long) SQLProcedureColumns(((SQLHSTMT ) arg2),((SQLCHAR * ) arg3),((SQLSMALLINT ) arg4),((SQLCHAR * ) arg5),((SQLSMALLINT ) arg6),((SQLCHAR * ) arg7),((SQLSMALLINT ) arg8),((SQLCHAR * ) arg9),((SQLSMALLINT ) arg10)); break; case 1: retval = (unsigned long) SQLColumnPrivileges(((SQLHSTMT ) arg2),((SQLCHAR * ) arg3),((SQLSMALLINT ) arg4),((SQLCHAR * ) arg5),((SQLSMALLINT ) arg6),((SQLCHAR * ) arg7),((SQLSMALLINT ) arg8),((SQLCHAR * ) arg9),((SQLSMALLINT ) arg10)); break; case 2: retval = (unsigned long) SQLTables(((SQLHSTMT ) arg2),((SQLCHAR * ) arg3),((SQLSMALLINT ) arg4),((SQLCHAR * ) arg5),((SQLSMALLINT ) arg6),((SQLCHAR * ) arg7),((SQLSMALLINT ) arg8),((SQLCHAR * ) arg9),((SQLSMALLINT ) arg10)); break; case 3: retval = (unsigned long) SQLColumns(((SQLHSTMT ) arg2),((SQLCHAR * ) arg3),((SQLSMALLINT ) arg4),((SQLCHAR * ) arg5),((SQLSMALLINT ) arg6),((SQLCHAR * ) arg7),((SQLSMALLINT ) arg8),((SQLCHAR * ) arg9),((SQLSMALLINT ) arg10)); break; default: PI_FAIL; } PI_makedouble(&rval,&rtype,(double) retval); if (PI_unify(arg11,type11,rval,rtype)) PI_SUCCEED; PI_FAIL; }