Browse Source

fcl-db: mssql: in case of network failure infinite loop can occurs in Fetch method. Bug #32524

git-svn-id: trunk@37537 -
lacak 7 years ago
parent
commit
05cddddf7c
1 changed files with 11 additions and 3 deletions
  1. 11 3
      packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

+ 11 - 3
packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

@@ -607,7 +607,9 @@ begin
 
     if not c.FSelectable then  //Sybase stored proc.
     begin
-      repeat until dbnextrow(FDBProc) = NO_MORE_ROWS;
+      repeat
+        Fstatus := dbnextrow(FDBProc);
+      until (Fstatus = NO_MORE_ROWS) or (Fstatus = FAIL);
       res := CheckError( dbresults(FDBProc) );
       // stored procedure information (return status and output parameters)
       // are available only after normal results are processed
@@ -742,12 +744,18 @@ begin
   // Compute rows resulting from the COMPUTE clause are not processed
   repeat
     Fstatus := dbnextrow(FDBProc);
+    // In case of network failure FAIL is returned
+    // Use dbsettime() to specify query timeout, else on Windows TCP KeepAliveTime is used, which defaults to 2 hours 
     Result  := Fstatus=REG_ROW;
-  until Result or (Fstatus = NO_MORE_ROWS);
+  until Result or (Fstatus = NO_MORE_ROWS) or (Fstatus = FAIL);
 
   if Fstatus = NO_MORE_ROWS then
     while dbresults(FDBProc) <> NO_MORE_RESULTS do // process remaining results if there are any
-      repeat until dbnextrow(FDBProc) = NO_MORE_ROWS;
+      repeat
+        Fstatus := dbnextrow(FDBProc);
+      until (Fstatus = NO_MORE_ROWS) or (Fstatus = FAIL);
+
+  if Fstatus = FAIL then CheckError(FAIL);
 end;
 
 function TMSSQLConnection.LoadField(cursor: TSQLCursor; FieldDef: TFieldDef;