Enable SQLColumnPrivileges functionality.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 30 Nov 2022 02:54:50 +0000 (11:54 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Fri, 23 Dec 2022 10:17:45 +0000 (19:17 +0900)
Add a regression test for SQLColumnPrivileges().

info.c
odbcapi30.c
test/expected/catalogfunctions.out
test/expected/catalogfunctions_1.out
test/src/catalogfunctions-test.c

diff --git a/info.c b/info.c
index 8563a89240730d07e0ccd0f71cd1614c202aa8e3..37f1d49f631ce752beb21816213601522723ca05 100644 (file)
--- 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");
index e2d1061764b76244a598eba154659a255fb3ebca..38f41dff042a31082cd1e9dd272891e93d23816b 100644 (file)
@@ -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 */
index a41482961ce42e722dcd5a9d492a61a6e44b5021..3e929ba2844d1147b768be2311b0bd8be1b5ebe0 100644 (file)
@@ -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
index 6c3d2b24b81825761c9f95801f9a7ad8a70f919e..d645591eac7c816ab02942b9c1e157c92bf3300c 100644 (file)
@@ -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
index b93ec6951c814d5d7e0edec006a9471c64b2a20d..efbcfa4f59ddc563580074518478e146fb9e5d68 100644 (file)
@@ -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);