From e1b69016fe93c298e744e591dd11cb95814aa72c Mon Sep 17 00:00:00 2001 From: gulugulu Date: Fri, 3 Feb 2023 10:29:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSQLGetCursorName=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E7=BB=93=E6=9E=9C=E4=B8=8E=E9=A2=84=E6=9C=9F=E4=B8=8D?= =?UTF-8?q?=E7=AC=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- odbc-test-gauss/Makefile | 1 + .../expected/odbc_SQLGetCursorName.log | 15 +++ odbc-test-gauss/odbc_SQLGetCursorName.c | 102 ++++++++++++++++++ results.c | 11 ++ 4 files changed, 129 insertions(+) create mode 100644 odbc-test-gauss/expected/odbc_SQLGetCursorName.log create mode 100644 odbc-test-gauss/odbc_SQLGetCursorName.c diff --git a/odbc-test-gauss/Makefile b/odbc-test-gauss/Makefile index 1f3297d..d2f1c5c 100644 --- a/odbc-test-gauss/Makefile +++ b/odbc-test-gauss/Makefile @@ -40,6 +40,7 @@ ifndef cases odbc_SQLExtendedFetch \ odbc_SQLGetConnectAttr \ odbc_SQLGetConnectOption \ + odbc_SQLGetCursorName \ odbc_SQLGetDescField \ odbc_SQLGetDiagField \ odbc_SQLGetEnvAttr \ diff --git a/odbc-test-gauss/expected/odbc_SQLGetCursorName.log b/odbc-test-gauss/expected/odbc_SQLGetCursorName.log new file mode 100644 index 0000000..53f3dd9 --- /dev/null +++ b/odbc-test-gauss/expected/odbc_SQLGetCursorName.log @@ -0,0 +1,15 @@ +connected +current cursorname is C1, len is 2 +current 2 cursorname is SQL_CUR0x1743f90, len is 16 +current 3 cursorname is A1B2C3D4E, len is 10 +SQLGetCursorName failed +HY090=[unixODBC][Driver Manager]Invalid string or buffer length +rc need to be -2: -2 +failed to SQLGetCursorName +HY009=The szCursor pointer is required +rc=-1 +SQLGetCursorName failed +HY009=The pcbCursor pointer is required +rc -1 current cursorname is C1, len is 0 +disconnecting +exit code : 0 diff --git a/odbc-test-gauss/odbc_SQLGetCursorName.c b/odbc-test-gauss/odbc_SQLGetCursorName.c new file mode 100644 index 0000000..ec90d57 --- /dev/null +++ b/odbc-test-gauss/odbc_SQLGetCursorName.c @@ -0,0 +1,102 @@ +#include +#include + +#include "common.h" + +int main(int argc, char **argv) +{ + int rc; + HSTMT hstmt = SQL_NULL_HSTMT; + HSTMT hstmt2 = SQL_NULL_HSTMT; + char param1[20] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + SQLLEN cbParam1; + SQLSMALLINT colcount; + SQLSMALLINT dataType; + SQLULEN paramSize; + SQLSMALLINT decDigits; + SQLSMALLINT nullable; + SQLUSMALLINT supported; + + test_connect(); + + rc = SQLAllocStmt(conn, &hstmt); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); + exit(1); + } + + rc = SQLSetCursorName(hstmt, (SQLCHAR*)"C1", SQL_NTS); + CHECK_STMT_RESULT(rc, "hstmt SQLSetCursorName failed", hstmt); + + char cursornamebuf[100]; + SQLSMALLINT cursornamelen; + + rc = SQLGetCursorName(hstmt, cursornamebuf, 100, &cursornamelen); + CHECK_STMT_RESULT(rc, "SQLGetCursorName failed", hstmt); + printf("current cursorname is %s, len is %d\n", cursornamebuf, cursornamelen); + + + /* 自动生成SQL_CUR开头的游标名 */ + HSTMT hstmt3 = SQL_NULL_HSTMT; + rc = SQLAllocStmt(conn, &hstmt3); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); + exit(1); + } + + rc = SQLExecDirect(hstmt3, (SQLCHAR *) "select * from pg_amop", SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt3); + + rc = SQLGetCursorName(hstmt3, cursornamebuf, 100, &cursornamelen); + CHECK_STMT_RESULT(rc, "SQLGetCursorName failed", hstmt3); + printf("current 2 cursorname is %s, len is %d\n", cursornamebuf, cursornamelen); + + /* get长度截断 */ + HSTMT hstmt4 = SQL_NULL_HSTMT; + rc = SQLAllocStmt(conn, &hstmt4); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); + exit(1); + } + + + rc = SQLSetCursorName(hstmt4, (SQLCHAR*)"A1B2C3D4E5", SQL_NTS); + CHECK_STMT_RESULT(rc, "hstmt SQLSetCursorName failed", hstmt); + + rc = SQLGetCursorName(hstmt4, cursornamebuf, 10, &cursornamelen); + CHECK_STMT_RESULT(rc, "SQLGetCursorName failed", hstmt4); + printf("current 3 cursorname is %s, len is %d\n", cursornamebuf, cursornamelen); + + + /* 错误用例 */ + rc = SQLGetCursorName(hstmt, cursornamebuf, -1, &cursornamelen); + PRINT_STMT_RESULT(rc, "SQLGetCursorName failed", hstmt); + + memset(cursornamebuf, 0, sizeof(cursornamebuf)); + rc = SQLGetCursorName(NULL, cursornamebuf, 100, &cursornamelen); + printf("rc need to be -2: %d\n", rc); + + memset(cursornamebuf, 0, sizeof(cursornamebuf)); + rc = SQLGetCursorName(hstmt, NULL, 100, &cursornamelen); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("failed to SQLGetCursorName", SQL_HANDLE_STMT, hstmt); + printf("rc=%d\n", rc); + } + + memset(cursornamebuf, 0, sizeof(cursornamebuf)); + cursornamelen = 0; + rc = SQLGetCursorName(hstmt, cursornamebuf, 100, NULL); + PRINT_STMT_RESULT(rc, "SQLGetCursorName failed", hstmt); + printf("rc %d current cursorname is %s, len is %d\n", rc, cursornamebuf, cursornamelen); + + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "12 SQLFreeStmt failed", hstmt); + + /* Clean up */ + test_disconnect(); + return 0; +} diff --git a/results.c b/results.c index 81a501b..bdb3854 100644 --- a/results.c +++ b/results.c @@ -4968,9 +4968,20 @@ PGAPI_GetCursorName(HSTMT hstmt, SC_set_error(stmt, STMT_TRUNCATED, "The buffer was too small for the GetCursorName.", func); } } + else + { + result = SQL_ERROR; + SC_set_error(stmt, STMT_INVALID_NULL_ARG, "The szCursor pointer is required", func); + } if (pcbCursor) *pcbCursor = (SQLSMALLINT) len; + else + { + /* m100: 长度字段为NULL时,也必须返回SQLERROR -1 */ + result = SQL_ERROR; + SC_set_error(stmt, STMT_INVALID_NULL_ARG, "The pcbCursor pointer is required", func); + } /* * Because this function causes no db-access, there's -- Gitee