소스 검색

fcl-db: mssql: cancel all pending results in case of unpreparation statement and in case dataset is closed.

git-svn-id: trunk@37975 -
lacak 7 년 전
부모
커밋
f51f09414b
1개의 변경된 파일18개의 추가작업 그리고 5개의 파일을 삭제
  1. 18 5
      packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

+ 18 - 5
packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

@@ -65,6 +65,7 @@ type
     function CheckError(const Ret: RETCODE): RETCODE;
     procedure Execute(const cmd: string); overload;
     procedure ExecuteDirectSQL(const Query: string);
+    procedure CancelQuery;
     procedure GetParameters(cursor: TSQLCursor; AParams: TParams);
     function TranslateFldType(SQLDataType: integer): TFieldType;
     function AutoCommit: boolean;
@@ -226,9 +227,9 @@ var
   ParamBinding : TParamBinding;
 begin
   if assigned(AParams) and (AParams.Count > 0) then
-    FQuery:=AParams.ParseSQL(Buf, false, sqEscapeSlash in FConnection.ConnOptions, sqEscapeRepeat in FConnection.ConnOptions, psSimulated, ParamBinding, FParamReplaceString)
+    FQuery := AParams.ParseSQL(Buf, False, sqEscapeSlash in FConnection.ConnOptions, sqEscapeRepeat in FConnection.ConnOptions, psSimulated, ParamBinding, FParamReplaceString)
   else
-    FQuery:=Buf;
+    FQuery := Buf;
   FPrepared := True;
 end;
 
@@ -346,6 +347,17 @@ begin
   end;
 end;
 
+procedure TMSSQLConnection.CancelQuery;
+begin
+  // Cancel the query currently being retrieved, discarding all pending rows and all remaining resultsets
+  if Fstatus = MORE_ROWS then begin
+    repeat
+      dbcanquery(FDBProc);
+    until dbresults(FDBProc) <> SUCCEED;
+    Fstatus := NO_MORE_ROWS;
+  end;
+end;
+
 function TMSSQLConnection.GetHandle: pointer;
 begin
   Result:=FDBProc;
@@ -575,8 +587,8 @@ end;
 
 procedure TMSSQLConnection.UnPrepareStatement(cursor: TSQLCursor);
 begin
-  if assigned(FDBProc) and (Fstatus <> NO_MORE_ROWS) then
-    dbcanquery(FDBProc);
+  CancelQuery;
+  cursor.FPrepared := False;
 end;
 
 procedure TMSSQLConnection.Execute(const cmd: string);
@@ -923,7 +935,8 @@ end;
 
 procedure TMSSQLConnection.FreeFldBuffers(cursor: TSQLCursor);
 begin
-  inherited FreeFldBuffers(cursor);
+  CancelQuery;
+  inherited;
 end;
 
 procedure TMSSQLConnection.UpdateIndexDefs(IndexDefs: TIndexDefs; TableName: string);