@@ -2400,4 +2400,74 @@ TYPED_TEST(FlightSQLODBCTestBase, TestSQLNativeSqlReturnsErrorOnBadInputs) {
24002400 this ->disconnect ();
24012401}
24022402
2403+ TYPED_TEST (FlightSQLODBCTestBase, SQLNumResultColsReturnsColumnsOnSelect) {
2404+ this ->connect ();
2405+
2406+ SQLSMALLINT columnCount = 0 ;
2407+ SQLSMALLINT expectedValue = 3 ;
2408+ SQLWCHAR sqlQuery[] = L" SELECT 1 AS col1, 'One' AS col2, 3 AS col3" ;
2409+ SQLINTEGER queryLength = static_cast <SQLINTEGER>(wcslen (sqlQuery));
2410+
2411+ SQLRETURN ret = SQLExecDirect (this ->stmt , sqlQuery, queryLength);
2412+
2413+ EXPECT_EQ (ret, SQL_SUCCESS);
2414+
2415+ ret = SQLFetch (this ->stmt );
2416+
2417+ EXPECT_EQ (ret, SQL_SUCCESS);
2418+
2419+ CheckIntColumn (this ->stmt , 1 , 1 );
2420+ CheckStringColumnW (this ->stmt , 2 , L" One" );
2421+ CheckIntColumn (this ->stmt , 3 , 3 );
2422+
2423+ ret = SQLNumResultCols (this ->stmt , &columnCount);
2424+
2425+ EXPECT_EQ (ret, SQL_SUCCESS);
2426+
2427+ EXPECT_EQ (columnCount, expectedValue);
2428+
2429+ this ->disconnect ();
2430+ }
2431+
2432+ TYPED_TEST (FlightSQLODBCTestBase, SQLNumResultColsReturnsSuccessOnNullptr) {
2433+ this ->connect ();
2434+
2435+ SQLWCHAR sqlQuery[] = L" SELECT 1 AS col1, 'One' AS col2, 3 AS col3" ;
2436+ SQLINTEGER queryLength = static_cast <SQLINTEGER>(wcslen (sqlQuery));
2437+
2438+ SQLRETURN ret = SQLExecDirect (this ->stmt , sqlQuery, queryLength);
2439+
2440+ EXPECT_EQ (ret, SQL_SUCCESS);
2441+
2442+ ret = SQLFetch (this ->stmt );
2443+
2444+ EXPECT_EQ (ret, SQL_SUCCESS);
2445+
2446+ CheckIntColumn (this ->stmt , 1 , 1 );
2447+ CheckStringColumnW (this ->stmt , 2 , L" One" );
2448+ CheckIntColumn (this ->stmt , 3 , 3 );
2449+
2450+ ret = SQLNumResultCols (this ->stmt , nullptr );
2451+
2452+ EXPECT_EQ (ret, SQL_SUCCESS);
2453+
2454+ this ->disconnect ();
2455+ }
2456+
2457+ TYPED_TEST (FlightSQLODBCTestBase, SQLNumResultColsFunctionSequenceErrorOnNoQuery) {
2458+ this ->connect ();
2459+
2460+ SQLSMALLINT columnCount = 0 ;
2461+ SQLSMALLINT expectedValue = 0 ;
2462+
2463+ SQLRETURN ret = SQLNumResultCols (this ->stmt , &columnCount);
2464+
2465+ EXPECT_EQ (ret, SQL_ERROR);
2466+ VerifyOdbcErrorState (SQL_HANDLE_STMT, this ->stmt , error_state_HY010);
2467+
2468+ EXPECT_EQ (columnCount, expectedValue);
2469+
2470+ this ->disconnect ();
2471+ }
2472+
24032473} // namespace arrow::flight::sql::odbc
0 commit comments