Repository: apache/arrow
File: cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc (C++)

Code before:
  ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(this->stmt, sql_query, query_length));

  ASSERT_EQ(SQL_SUCCESS, SQLFetch(this->stmt));

  CheckIntColumn(this->stmt, 1, 1);
  CheckStringColumnW(this->stmt, 2, L"One");
  CheckIntColumn(this->stmt, 3, 3);

  ASSERT_EQ(SQL_SUCCESS, SQLRowCount(this->stmt, &row_count));

  EXPECT_EQ(expected_value, row_count);
}

TYPED_TEST(StatementTest, SQLRowCountReturnsSuccessOnNullptr) {
  SQLWCHAR sql_query[] = L"SELECT 1 AS col1, 'One' AS col2, 3 AS col3";
  SQLINTEGER query_length = static_cast<SQLINTEGER>(wcslen(sql_query));

  ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(this->stmt, sql_query, query_length));

  ASSERT_EQ(SQL_SUCCESS, SQLFetch(this->stmt));

  CheckIntColumn(this->stmt, 1, 1);
  CheckStringColumnW(this->stmt, 2, L"One");
  CheckIntColumn(this->stmt, 3, 3);

  ASSERT_EQ(SQL_SUCCESS, SQLRowCount(this->stmt, 0));
}

TYPED_TEST(StatementTest, SQLRowCountFunctionSequenceErrorOnNoQuery) {
  SQLLEN row_count = 0;
  SQLLEN expected_value = 0;

  ASSERT_EQ(SQL_ERROR, SQLRowCount(this->stmt, &row_count));
  VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorStateHY010);

  EXPECT_EQ(expected_value, row_count);
}

}  // namespace arrow::flight::sql::odbc


Review comment (bug):
nit, but can we write `nullptr` for nullptr and not use 0?

Code after:
  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 5, SQL_C_SSHORT, &ssmall_int_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<int16_t>::min(), ssmall_int_val);

  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 6, SQL_C_SSHORT, &ssmall_int_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<int16_t>::max(), ssmall_int_val);

  // Unsigned Small Int
  uint16_t usmall_int_val;
  buf_len = sizeof(usmall_int_val);
  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 7, SQL_C_USHORT, &usmall_int_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<uint16_t>::min(), usmall_int_val);

  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 8, SQL_C_USHORT, &usmall_int_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<uint16_t>::max(), usmall_int_val);

  // Signed Integer
  SQLINTEGER slong_val;
  buf_len = sizeof(slong_val);
  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 9, SQL_C_SLONG, &slong_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<SQLINTEGER>::min(), slong_val);

  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 10, SQL_C_SLONG, &slong_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<SQLINTEGER>::max(), slong_val);

  // Unsigned Integer
  SQLUINTEGER ulong_val;
  buf_len = sizeof(ulong_val);
  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 11, SQL_C_ULONG, &ulong_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<SQLUINTEGER>::min(), ulong_val);

  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 12, SQL_C_ULONG, &ulong_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<SQLUINTEGER>::max(), ulong_val);

  // Signed Big Int
  SQLBIGINT sbig_int_val;
  buf_len = sizeof(sbig_int_val);
  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 13, SQL_C_SBIGINT, &sbig_int_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<SQLBIGINT>::min(), sbig_int_val);

  ASSERT_EQ(SQL_SUCCESS,
            SQLGetData(this->stmt, 14, SQL_C_SBIGINT, &sbig_int_val, buf_len, &ind));
  EXPECT_EQ(std::numeric_limits<SQLBIGINT>::max(), sbig_int_val);