From: Hiroshi Inoue Date: Wed, 30 Nov 2022 02:54:50 +0000 (+0900) Subject: Enable SQLColumnPrivileges functionality. X-Git-Tag: REL-15_00_0000~5 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=15eba3aa7831e4343a96c55ec1acb6f3584ab6fa;p=psqlodbc.git Enable SQLColumnPrivileges functionality. Add a regression test for SQLColumnPrivileges(). --- diff --git a/info.c b/info.c index 8563a89..37f1d49 100644 --- a/info.c +++ b/info.c @@ -1388,7 +1388,7 @@ PGAPI_GetFunctions(HDBC hdbc, /* ODBC level 2 functions */ pfExists[SQL_API_SQLBROWSECONNECT] = FALSE; - pfExists[SQL_API_SQLCOLUMNPRIVILEGES] = FALSE; + pfExists[SQL_API_SQLCOLUMNPRIVILEGES] = TRUE; pfExists[SQL_API_SQLDATASOURCES] = FALSE; /* only implemented by * DM */ if (SUPPORT_DESCRIBE_PARAM(ci)) @@ -1512,7 +1512,7 @@ PGAPI_GetFunctions(HDBC hdbc, *pfExists = FALSE; break; case SQL_API_SQLCOLUMNPRIVILEGES: - *pfExists = FALSE; + *pfExists = TRUE; break; case SQL_API_SQLDATASOURCES: *pfExists = FALSE; @@ -3721,7 +3721,7 @@ PGAPI_ColumnPrivileges(HSTMT hstmt, } initPQExpBuffer(&column_query); #define return DONT_CALL_RETURN_FROM_HERE??? - appendPQExpBufferStr(&column_query, "select '' as TABLE_CAT, table_schema as TABLE_SCHEM," + appendPQExpBufferStr(&column_query, "select table_catalog as TABLE_CAT, table_schema as TABLE_SCHEM," " table_name, column_name, grantor, grantee," " privilege_type as PRIVILEGE, is_grantable from" " information_schema.column_privileges where true"); diff --git a/odbcapi30.c b/odbcapi30.c index e2d1061..38f41df 100644 --- a/odbcapi30.c +++ b/odbcapi30.c @@ -614,8 +614,7 @@ MYLOG(DETAIL_LOG_LEVEL, "lie=%d\n", ci->drivers.lie); SQL_FUNC_ESET(pfExists, SQL_API_SQLTABLES); /* 54 */ if (ci->drivers.lie) SQL_FUNC_ESET(pfExists, SQL_API_SQLBROWSECONNECT); /* 55 */ - if (ci->drivers.lie) - SQL_FUNC_ESET(pfExists, SQL_API_SQLCOLUMNPRIVILEGES); /* 56 */ + SQL_FUNC_ESET(pfExists, SQL_API_SQLCOLUMNPRIVILEGES); /* 56 */ SQL_FUNC_ESET(pfExists, SQL_API_SQLDATASOURCES); /* 57 */ if (SUPPORT_DESCRIBE_PARAM(ci) || ci->drivers.lie) SQL_FUNC_ESET(pfExists, SQL_API_SQLDESCRIBEPARAM); /* 58 */ diff --git a/test/expected/catalogfunctions.out b/test/expected/catalogfunctions.out index a414829..3e929ba 100644 --- a/test/expected/catalogfunctions.out +++ b/test/expected/catalogfunctions.out @@ -87,6 +87,21 @@ contrib_regression public testtab_fk id 4 int4 contrib_regression public testtab_fk t 12 varchar contrib_regression public testview id 4 int4 contrib_regression public testview t 12 varchar +Check for SQLColumnPrivileges +Result set metadata: +table_cat: VARCHAR(63) digits: 0, nullable +table_schem: VARCHAR(63) digits: 0, nullable +table_name: VARCHAR(63) digits: 0, nullable +column_name: VARCHAR(63) digits: 0, nullable +grantor: VARCHAR(63) digits: 0, nullable +grantee: VARCHAR(63) digits: 0, nullable +privilege: VARCHAR(255) digits: 0, nullable +is_grantable: VARCHAR(3) digits: 0, nullable +Result set: +contrib_regression public testtab1 id UPDATE YES +contrib_regression public testtab1 id SELECT YES +contrib_regression public testtab1 id REFERENCES YES +contrib_regression public testtab1 id INSERT YES Check for SQLSpecialColumns Result set metadata: SCOPE: SMALLINT(5) digits: 0, nullable diff --git a/test/expected/catalogfunctions_1.out b/test/expected/catalogfunctions_1.out index 6c3d2b2..d645591 100644 --- a/test/expected/catalogfunctions_1.out +++ b/test/expected/catalogfunctions_1.out @@ -87,6 +87,21 @@ contrib_regression public testtab_fk id 4 int4 contrib_regression public testtab_fk t -9 varchar contrib_regression public testview id 4 int4 contrib_regression public testview t -9 varchar +Check for SQLColumnPrivileges +Result set metadata: +table_cat: WVARCHAR(63) digits: 0, nullable +table_schem: WVARCHAR(63) digits: 0, nullable +table_name: WVARCHAR(63) digits: 0, nullable +column_name: WVARCHAR(63) digits: 0, nullable +grantor: WVARCHAR(63) digits: 0, nullable +grantee: WVARCHAR(63) digits: 0, nullable +privilege: WVARCHAR(255) digits: 0, nullable +is_grantable: WVARCHAR(3) digits: 0, nullable +Result set: +contrib_regression public testtab1 id UPDATE YES +contrib_regression public testtab1 id SELECT YES +contrib_regression public testtab1 id REFERENCES YES +contrib_regression public testtab1 id INSERT YES Check for SQLSpecialColumns Result set metadata: SCOPE: SMALLINT(5) digits: 0, nullable diff --git a/test/src/catalogfunctions-test.c b/test/src/catalogfunctions-test.c index b93ec69..efbcfa4 100644 --- a/test/src/catalogfunctions-test.c +++ b/test/src/catalogfunctions-test.c @@ -20,6 +20,9 @@ #include "common.h" +/* define a macro to simplify function calls */ +#define PRINT_RESULT_SERIES(hstmt, idarray, rowcount) print_result_series(hstmt, idarray, sizeof(idarray)/sizeof(idarray[0]), rowcount) + int main(int argc, char **argv) { @@ -27,6 +30,7 @@ main(int argc, char **argv) HSTMT hstmt = SQL_NULL_HSTMT; /* Cases where output is limited to relevant information only */ SQLSMALLINT sql_tab_privileges_ids[6] = {1, 2, 3, 4, 6, 7}; + SQLSMALLINT sql_column_privileges_ids[6] = {1, 2, 3, 4, 7, 8}; SQLSMALLINT sql_column_ids[6] = {1, 2, 3, 4, 5, 6}; SQLSMALLINT sql_pro_column_ids[] = {1, 2, 3, 4, 5, 6, 7}; char buf[1000]; @@ -79,22 +83,22 @@ main(int argc, char **argv) * to get the OID in output, and this information looks to be * enough. */ - print_result_series(hstmt, sql_column_ids, 6, -1); + PRINT_RESULT_SERIES(hstmt, sql_column_ids, -1); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLColumnPrivileges */ - //printf("Check for SQLColumnPrivileges\n"); - //rc = SQLColumnPrivileges(hstmt, - // NULL, 0, - // (SQLCHAR *) "public", SQL_NTS, - // (SQLCHAR *) "testtab1", SQL_NTS, - // (SQLCHAR *) "id", SQL_NTS); - //CHECK_STMT_RESULT(rc, "SQLColumnPrivileges failed", hstmt); - //print_result_meta(hstmt); - //print_result(hstmt); - //rc = SQLFreeStmt(hstmt, SQL_CLOSE); - //CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + printf("Check for SQLColumnPrivileges\n"); + rc = SQLColumnPrivileges(hstmt, + NULL, 0, + (SQLCHAR *) "public", SQL_NTS, + (SQLCHAR *) "testtab1", SQL_NTS, + (SQLCHAR *) "id", SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLColumnPrivileges failed", hstmt); + print_result_meta(hstmt); + PRINT_RESULT_SERIES(hstmt, sql_column_privileges_ids, -1); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLSpecialColumns */ printf("Check for SQLSpecialColumns\n"); @@ -187,7 +191,7 @@ main(int argc, char **argv) (SQLCHAR *) "set_byte", SQL_NTS, NULL, 0); CHECK_STMT_RESULT(rc, "SQLProcedureColumns failed", hstmt); - print_result_series(hstmt, sql_pro_column_ids, sizeof(sql_pro_column_ids) / sizeof(sql_pro_column_ids[0]), -1); + PRINT_RESULT_SERIES(hstmt, sql_pro_column_ids, -1); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* @@ -199,7 +203,7 @@ main(int argc, char **argv) (SQLCHAR *) "getfoo", SQL_NTS, NULL, 0); CHECK_STMT_RESULT(rc, "SQLProcedureColumns failed", hstmt); - print_result_series(hstmt, sql_pro_column_ids, sizeof(sql_pro_column_ids) / sizeof(sql_pro_column_ids[0]), -1); + PRINT_RESULT_SERIES(hstmt, sql_pro_column_ids, -1); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* @@ -211,7 +215,7 @@ main(int argc, char **argv) (SQLCHAR *) "getboo", SQL_NTS, NULL, 0); CHECK_STMT_RESULT(rc, "SQLProcedureColumns failed", hstmt); - print_result_series(hstmt, sql_pro_column_ids, sizeof(sql_pro_column_ids) / sizeof(sql_pro_column_ids[0]), -1); + PRINT_RESULT_SERIES(hstmt, sql_pro_column_ids, -1); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* @@ -223,7 +227,7 @@ main(int argc, char **argv) (SQLCHAR *) "tbl_arg", SQL_NTS, NULL, 0); CHECK_STMT_RESULT(rc, "SQLProcedureColumns failed", hstmt); - print_result_series(hstmt, sql_pro_column_ids, sizeof(sql_pro_column_ids) / sizeof(sql_pro_column_ids[0]), -1); + PRINT_RESULT_SERIES(hstmt, sql_pro_column_ids, -1); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* @@ -236,7 +240,7 @@ main(int argc, char **argv) (SQLCHAR *) "set_of", SQL_NTS, NULL, 0); CHECK_STMT_RESULT(rc, "SQLProcedureColumns failed", hstmt); - print_result_series(hstmt, sql_pro_column_ids, sizeof(sql_pro_column_ids) / sizeof(sql_pro_column_ids[0]), -1); + PRINT_RESULT_SERIES(hstmt, sql_pro_column_ids, -1); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); @@ -248,7 +252,7 @@ main(int argc, char **argv) (SQLCHAR *) "testtab1", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLTablePrivileges failed", hstmt); print_result_meta(hstmt); - print_result_series(hstmt, sql_tab_privileges_ids, 6, 5); + PRINT_RESULT_SERIES(hstmt, sql_tab_privileges_ids, 5); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);