fcl-db: odbc: go to first selectable result. issue #38664

git-svn-id: trunk@49049 -
(cherry picked from commit fa0b053b21)
This commit is contained in:
ondrej 2021-03-25 09:44:14 +00:00 committed by marcoonthegit
parent 2338aa4d5e
commit 35da09230a
2 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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');