diff --git a/odbc-test-gauss/Makefile b/odbc-test-gauss/Makefile index 1f3297daf5888a1f07ff3bf5be6dd759d2367c95..d2f1c5cde5ced90f55bfc270cb0c2015ae73b1a6 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 0000000000000000000000000000000000000000..53f3dd9e692c064fefd6352eb9ef37ff3d89e57d --- /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 0000000000000000000000000000000000000000..ec90d57bdf7eb9455a4abafeb0faac0c5c9b4cf9 --- /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 81a501b2551cde4bf60dfdf2160ad41fb3c9c718..bdb38549cb919fad9de99874a63360e4ce445f6f 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