From 782b093ac3acce1f5f5d974d6892412c6aff1c63 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Mon, 28 Mar 2022 17:24:46 -0700 Subject: [PATCH 1/4] [AD-678] add unit test for Get/Set Statement Attribute --- src/odbc-test/src/api_robustness_test.cpp | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/odbc-test/src/api_robustness_test.cpp b/src/odbc-test/src/api_robustness_test.cpp index 5f93d712c..80f08a131 100644 --- a/src/odbc-test/src/api_robustness_test.cpp +++ b/src/odbc-test/src/api_robustness_test.cpp @@ -166,6 +166,36 @@ BOOST_AUTO_TEST_CASE(TestSQLPrimaryKeysEmpty) { BOOST_CHECK_EQUAL(SQL_NO_DATA, ret); } +BOOST_AUTO_TEST_CASE(TestSQLSetStmtAttrGetStmtAttr) { + // check that statement array size is set correctly + + std::string dsnConnectionString; + CreateDsnConnectionStringForLocalServer(dsnConnectionString); + + Connect(dsnConnectionString); + + SQLCHAR buffer[ODBC_BUFFER_SIZE]; + SQLINTEGER resLen = 0; + + // repeat test for different values + SQLULEN valList[5] = {10, 52, 81, 103, 304}; + for (SQLULEN val : valList) { + SQLRETURN ret = + SQLSetStmtAttr(stmt, SQL_ATTR_ROW_ARRAY_SIZE, + reinterpret_cast< SQLPOINTER >(val), sizeof(val)); + + ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_STMT, stmt); + + ret = SQLGetStmtAttr(stmt, SQL_ATTR_ROW_ARRAY_SIZE, buffer, sizeof(buffer), + &resLen); + + ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_STMT, stmt); + + SQLINTEGER* bufferVal = reinterpret_cast< SQLINTEGER* >(buffer); + BOOST_CHECK_EQUAL(*bufferVal, val); + } +} + BOOST_AUTO_TEST_CASE(TestSQLDriverConnect, *disabled()) { // There are no checks because we do not really care what is the result of // these calls as long as they do not cause segmentation fault. From cfac21d38f5f13cd0dd567b7976b585ccb1b793e Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 30 Mar 2022 09:35:36 -0700 Subject: [PATCH 2/4] [AD-678] resolve code review comment *change buffer to SQLINTEGER type to avoid reinterpreting cast --- src/odbc-test/src/api_robustness_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/odbc-test/src/api_robustness_test.cpp b/src/odbc-test/src/api_robustness_test.cpp index 80f08a131..cd36d72c7 100644 --- a/src/odbc-test/src/api_robustness_test.cpp +++ b/src/odbc-test/src/api_robustness_test.cpp @@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(TestSQLSetStmtAttrGetStmtAttr) { Connect(dsnConnectionString); - SQLCHAR buffer[ODBC_BUFFER_SIZE]; + SQLINTEGER buffer[ODBC_BUFFER_SIZE]; SQLINTEGER resLen = 0; // repeat test for different values @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(TestSQLSetStmtAttrGetStmtAttr) { ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_STMT, stmt); - SQLINTEGER* bufferVal = reinterpret_cast< SQLINTEGER* >(buffer); + SQLINTEGER* bufferVal = buffer; BOOST_CHECK_EQUAL(*bufferVal, val); } } From ac0bb23eff29aa1f2034e05350e105de395cf9a8 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 30 Mar 2022 09:37:54 -0700 Subject: [PATCH 3/4] [AD-678] remove unnecessary variable assignment in test --- src/odbc-test/src/api_robustness_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/odbc-test/src/api_robustness_test.cpp b/src/odbc-test/src/api_robustness_test.cpp index cd36d72c7..b88929aba 100644 --- a/src/odbc-test/src/api_robustness_test.cpp +++ b/src/odbc-test/src/api_robustness_test.cpp @@ -191,8 +191,7 @@ BOOST_AUTO_TEST_CASE(TestSQLSetStmtAttrGetStmtAttr) { ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_STMT, stmt); - SQLINTEGER* bufferVal = buffer; - BOOST_CHECK_EQUAL(*bufferVal, val); + BOOST_CHECK_EQUAL(*buffer, val); } } From 0b2aa2a84193f18df465a3a71afcd18867e94ccd Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 30 Mar 2022 10:32:47 -0700 Subject: [PATCH 4/4] [AD-678] code review feedback from Bruce * we don't really need a buffer here, as SQLINTEGER suffice. Co-Authored-By: Bruce Irschick --- src/odbc-test/src/api_robustness_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/odbc-test/src/api_robustness_test.cpp b/src/odbc-test/src/api_robustness_test.cpp index b88929aba..7d53877e6 100644 --- a/src/odbc-test/src/api_robustness_test.cpp +++ b/src/odbc-test/src/api_robustness_test.cpp @@ -52,7 +52,7 @@ struct ApiRobustnessTestSuiteFixture : public odbc::OdbcTestSuite { * Constructor. */ ApiRobustnessTestSuiteFixture() : testCache(0) { - // No-op + // No-op } /** @@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(TestSQLSetStmtAttrGetStmtAttr) { Connect(dsnConnectionString); - SQLINTEGER buffer[ODBC_BUFFER_SIZE]; + SQLINTEGER actual_row_array_size; SQLINTEGER resLen = 0; // repeat test for different values @@ -186,12 +186,12 @@ BOOST_AUTO_TEST_CASE(TestSQLSetStmtAttrGetStmtAttr) { ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_STMT, stmt); - ret = SQLGetStmtAttr(stmt, SQL_ATTR_ROW_ARRAY_SIZE, buffer, sizeof(buffer), - &resLen); + ret = SQLGetStmtAttr(stmt, SQL_ATTR_ROW_ARRAY_SIZE, &actual_row_array_size, + sizeof(actual_row_array_size), &resLen); ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_STMT, stmt); - BOOST_CHECK_EQUAL(*buffer, val); + BOOST_CHECK_EQUAL(actual_row_array_size, val); } }