anchor.diff:    Result := _LastSQLScript;
   end;
   
  +{ TmDatabaseConnectionsCache }
  +
  +constructor TmDatabaseConnectionsCache.Create;
  +begin
  +  FIndex := TmStringDictionary.Create(true);
  +  FList := TList.Create;
  +  FCriticalSection := TCriticalSection.Create;
  +end;
  +
  +destructor TmDatabaseConnectionsCache.Destroy;
  +begin
  +  Self.CloseAll;
  +  FIndex.Free;
  +  FList.Free;
  +  FCriticalSection.Free;
  +  inherited Destroy;
  +end;
  +
  +procedure TmDatabaseConnectionsCache.CloseAll;
  +var
  +  i : integer;
  +  curConn : TmDatabaseConnection;
  +begin
  +  FCriticalSection.Acquire;
  +  try
  +    for i := 0 to FList.Count -  1 do
  +    begin
  +      curConn := TmDatabaseConnection(FList.Items[i]);
  +      if curConn.Connected then
  +        curConn.Close;
  +    end;
  +  finally
  +    FCriticalSection.Leave;
  +  end;
  +end;
  +
  +function TmDatabaseConnectionsCache.GetConnection(const aConnectionInfo: TmDatabaseConnectionInfo): TmDatabaseConnection;
  +var
  +  curList : TObjectList;
  +  curConn : TmDatabaseConnection;
  +  i : integer;
  +begin
  +  FCriticalSection.Acquire;
  +  try
  +    curList := FIndex.Find(aConnectionInfo.AsString) as TObjectList;
  +    if not Assigned(curList) then
  +    begin
  +      curList := TObjectList.Create(true);
  +      FIndex.Add(aConnectionInfo.AsString, curList);
  +    end;
  +    curConn := nil;
  +    for i := 0 to curList.Count - 1 do
  +    begin
  +      if not (curList.Items[i] as TmDatabaseConnection).FLocked then
  +      begin
  +        curConn := curList.Items[i] as TmDatabaseConnection;
  +        // it must be replaced as the old instance could be freed
  +        curConn.ConnectionInfo := aConnectionInfo;
  +        break;
  +      end;
  +    end;
  +    if not Assigned(curConn) then
  +    begin
  +      curConn := TmDatabaseConnection.Create(aConnectionInfo);
  +      curConn.FCached:= true;
  +      curList.Add(curConn);
  +    end;
  +
  +    curConn.FLocked:= true;
  +
  +    Result := curConn;
  +  finally
  +    FCriticalSection.Leave;
  +  end;
  +end;
  +
  +procedure TmDatabaseConnectionsCache.ReleaseConnection(aConnection: TmDatabaseConnection);
  +begin
  +  if Assigned(aConnection) then
  +    aConnection.FLocked:= false;
  +end;
  +
   
   { TmDatabaseConnectionsTandem }
   
  
positive.code: begin
    FImplementation := nil;
    FOwnsConnectionInfo:= false;
  end;
  
  constructor TmDatabaseConnection.Create(aConnectionInfo: TmDatabaseConnectionInfo; const aOwnsConnectionInfo: boolean);
  
negative.code: begin
    if not Assigned(FOwnedConnection) then
    begin
      {$IFDEF CACHE_CONNECTIONS}
        if Assigned(FConnectionInfo) then
          FOwnedConnection := _ConnectionsCache.GetConnection(FConnectionInfo)
        else
          FOwnedConnection := TmDatabaseConnection.Create;
      {$ELSE}
        FOwnedConnection := TmDatabaseConnection.Create;
        if Assigned(FConnectionInfo) then
          FOwnedConnection.ConnectionInfo := FConnectionInfo;
      {$ENDIF}
    end;
  end;
  
  destructor TmDatabaseConnectionsTandem.Destroy;
  begin
    {$IFDEF CACHE_CONNECTIONS}
    if Assigned(FOwnedConnection) then
      _ConnectionsCache.ReleaseConnection(FOwnedConnection);
    {$ELSE}
    FreeAndNil(FOwnedConnection);
    {$ENDIF}
    inherited Destroy;
  end;
  
  