diff --git a/packages/fcl-db/src/sqldb/odbc/odbcconn.pas b/packages/fcl-db/src/sqldb/odbc/odbcconn.pas index 144ad5f1fa..dc7c7f5846 100644 --- a/packages/fcl-db/src/sqldb/odbc/odbcconn.pas +++ b/packages/fcl-db/src/sqldb/odbc/odbcconn.pas @@ -873,10 +873,15 @@ begin if (Res<>SQL_NO_DATA) then ODBCCheckResult( Res, SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.' ); - if ODBCSuccess(SQLNumResultCols(ODBCCursor.FSTMTHandle, ColumnCount)) then - ODBCCursor.FSelectable:=ColumnCount>0 - else - ODBCCursor.FSelectable:=False; + // go to first selectable result - see issue #38664 + ODBCCursor.FSelectable:=False; + while not ODBCCursor.FSelectable and ODBCSuccess(Res) and + ODBCSuccess(SQLNumResultCols(ODBCCursor.FSTMTHandle, ColumnCount)) do + begin + ODBCCursor.FSelectable:=ColumnCount>0; + if not ODBCCursor.FSelectable then + Res:=SQLMoreResults(ODBCCursor.FSTMTHandle); + end; finally // free parameter buffers diff --git a/packages/odbc/src/odbcsql.inc b/packages/odbc/src/odbcsql.inc index 2500ea3fb1..1786d06486 100644 --- a/packages/odbc/src/odbcsql.inc +++ b/packages/odbc/src/odbcsql.inc @@ -1217,6 +1217,7 @@ type TSQLFetch=function (StatementHandle:SQLHSTMT):SQLRETURN;{$ifdef fpc} extd type TSQLNumResultCols=function (StatementHandle:SQLHSTMT; var ColumnCount:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif}; +type TSQLMoreResults=function (StatementHandle:SQLHSTMT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif}; type TSQLDescribeCol=function (StatementHandle:SQLHSTMT; ColumnNumber:SQLUSMALLINT;ColumnName:PSQLCHAR; @@ -1444,6 +1445,7 @@ var SQLCloseCursor:TSQLCloseCursor; var SQLExecute:TSQLExecute; var SQLFetch:TSQLFetch; var SQLNumResultCols:TSQLNumResultCols; +var SQLMoreResults:TSQLMoreResults; var SQLDescribeColA:TSQLDescribeCol; SQLDescribeColW:TSQLDescribeColW; var SQLFetchScroll:TSQLFetchScroll; @@ -1608,6 +1610,8 @@ var function SQLNumResultCols( StatementHandle:SQLHSTMT; var ColumnCount:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};external odbclib; + function SQLMoreResults( + StatementHandle:SQLHSTMT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};external odbclib; function SQLDescribeCol( StatementHandle:SQLHSTMT; ColumnNumber:SQLUSMALLINT; @@ -1918,6 +1922,7 @@ begin pointer(SQLExecute) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecute'); pointer(SQLFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLFetch'); pointer(SQLNumResultCols) := GetProcedureAddress(ODBCLibraryHandle,'SQLNumResultCols'); + pointer(SQLMoreResults) := GetProcedureAddress(ODBCLibraryHandle,'SQLMoreResults'); pointer(SQLFetchScroll) := GetProcedureAddress(ODBCLibraryHandle,'SQLFetchScroll'); pointer(SQLExtendedFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLExtendedFetch'); pointer(SQLGetData) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetData');