Einzelnen Beitrag anzeigen

bl3nder

Registriert seit: 18. Aug 2006
89 Beiträge
 
#11

Re: Zeos Query - too many connections

  Alt 19. Aug 2008, 11:56
Also hier mal zur Erklaerung, vielleicht kann man den Fehler so finden:


Habe 2 Units Model.pas und Model_Database.pas



In Model.pas habe ich folgende Klassen:

Delphi-Quellcode:

  TAttributes = class(TObject)
  private
  public
  end;

  TMain = class(TObject)
  private
  public
    function DBSearch(Criteria: TAttributes): TObjectList; Virtual; Abstract;
    function DBCreate(): TZQuery; Virtual; Abstract;
    function DBEdit(): TZQuery; Virtual; Abstract;
    function DBDelete(): TZQuery; Virtual; Abstract;
  end;





  { ---- Attributes ---- }

  TDockingstationAttributes = class(TAttributes)
  private
    FComment: String;
    FFabricant: String;
    FID: Integer;
    //..
  public
    function GetComment: String;
    function GetFabricant: String;
    function GetID: Integer;
   //...
    procedure SetComment(Comment: String);
    procedure SetFabricant(Fabricant: String);
    procedure SetID(ID: Integer);
    //...
  end;
  { ---- /Attributes ---- }


  { ---- Main ---- }
  TDockingstation = class(TMain)
  private
    FAttributes : TDockingstationAttributes;
  public
    constructor Create();

    function GetAttributes(): TDockingstationAttributes;

    procedure SetAttributes(Comment: String='';Fabricant: String='';
      ID: Integer=0; ...);

  end;

  { ---- /Main ---- }


  { ---- Search ---- }

  TDockingstationSearch = class(TMain)
  private
  public
    function DBSearch(Modus: String; Criteria: TDockingstationAttributes)
      : TObjectList; Overload;
  end;

  { ---- /Search ---- }





  { ---- Attributes ---- }


  TComputerAttributes = class(TAttributes)
  private
    //..
    FComment: String;
    //..
    FGraphicCard: String;
  //..
    FDockingstation: TDockingstation; // <-- Computer enthaelt dockingstation objekt
  public
  //..get/set
  end;

  { ---- /Attributes ---- }


  { ---- Main ---- }

  TComputer = class(TMain)
  private
    FAttributes: TComputerAttributes;
  public
    constructor Create();

    function GetAttributes(): TComputerAttributes;

    procedure SetAttributes(Comment: String='';...GraphicCard: String='';...);

  end;

  { ---- /Main ---- }


  { ---- Search ---- }

  TComputerSearch = class(TMain)
  private
  public
    function DBSearch(Modus: String; Criteria: TComputerAttributes): TObjectList; Overload;
  end;

  { ---- /Search ---- }


implementation

//............


function TDockingstationSearch.DBSearch(Modus: String;
  Criteria: TDockingstationAttributes): TObjectList;
var
FMdbDsSearch: Model_Database.TDockingstationSearch;
FWsList: TObjectList;
begin
  FWsList := TObjectList.Create;
  FMdbDsSearch := Model_Database.TDockingstationSearch.Create;

  FWsList := FMdbDsSearch.DBSearch(Modus,Criteria);

  Result := FWsList;
end;


//................

function TComputerSearch.DBSearch(Modus: String; Criteria: TComputerAttributes)
  : TObjectList;
var
FMdbCSearch: Model_Database.TComputerSearch;
FCList: TObjectList;
begin
  FCList := TObjectList.Create;
  FMdbCSearch := Model_Database.TComputerSearch.Create;

  FCList := FMdbCSearch.DBSearch(Modus,Criteria);
  Result := FCList;
end;

//..










In Model_Database.pas steht folgendes:


Delphi-Quellcode:
  TDatabase = class(TObject)
  private
    FWQuery : TZQuery;
    FDQuery : TZQuery;
    FCQuery : TZQuery;
    FMQuery : TZQuery;
    FSqlConnection : TZConnection;
  public
    constructor Create();

    function DBSearch(Criteria: Model.TAttributes)
      : TObjectList; virtual; abstract;
    procedure DBCreate(); virtual; abstract;
    procedure DBEdit(); virtual; abstract;
    procedure DBDelete(); virtual; abstract;
  end;




  TDockingstationSearch = class(TDatabase)
  private
  public
    function DBSearch(Modus: String; Criteria: Model.TDockingstationAttributes)
      : TObjectList; Overload;
  end;

  TComputerSearch = class(TDatabase)
  private
  public
    function DBSearch(Modus: String; Criteria: Model.TComputerAttributes)
      : TObjectList; Overload;
  end;

implementation




constructor TDatabase.Create();
begin
  FSqlConnection := TZConnection.Create(FSqlConnection);
  FSqlConnection.HostName := ''; //Server
  FSqlConnection.User := ''; //Benutzername
  FSqlConnection.Password := ''; //Passwort
  FSqlConnection.Database := ''; //Name der Datenbank
  FSqlConnection.Protocol := 'mysql-4.1';
  FSqlConnection.Port := 3306;


  FDQuery := TZQuery.Create(FDQuery);
  FDQuery.Connection := FSqlConnection;
  FCQuery := TZQuery.Create(FCQuery);
  FCQuery.Connection := FSqlConnection;

end;





function TDockingstationSearch.DBSearch(Modus: String;
  Criteria: Model.TDockingstationAttributes): TObjectList;
var
FDSList: TObjectList;
I: Integer;
FEqual1,FEqual2 : String;
FMyDockingstation: Model.TDockingstation;
begin
  FDSList := TObjectList.Create;
  FMyDockingstation := Model.TDockingstation.Create;

 
//...
  // Search in the database for dockingstations by using the criteria
  FDQuery.Close;

  FDQuery.SQL.Text := 'SELECT * FROM Dockingstation';
  FDQuery.SQL.Add(' WHERE (1=1');
//...
  FDQuery.SQL.Add(')');
  FDQuery.Open;

  while not FDQuery.EOF do
  begin
    // Use search result to create a new dockingstation object
    FMyDockingstation.SetAttributes('','',
      FDQuery.FieldByName('DockingstationID').AsInteger,'',
       );

    // Add dockingstation to a list of dockingstation ojects
    FDSList.Add(FMyDockingstation);

    FDQuery.Next;
  end;

  FDQuery.Free;
  Result := FDSList;

end;


function TComputerSearch.DBSearch(Modus: String;
  Criteria: Model.TComputerAttributes): TObjectList;
var
//..

begin
  //..

  FCList := TObjectList.Create;

//..

  // Search in the database for computers by using the criteria
  FCQuery.Close;

  FCQuery.SQL.Text := 'SELECT';
  FCQuery.SQL.Add('....');
//...
  FCQuery.Open;

  while not FCQuery.EOF do
  begin
    FMyComputer := Model.TComputer.Create;

    // Use search result to create a new computer object
    FMyID := FCQuery.FieldByName('RechnerID').AsInteger;

   
    FMyComment := FCQuery.FieldByName('Bemerkungen').AsString;
    FMyGraphicCard := FCQuery.FieldByName('Grafikkarte').AsString;
    //...

  



// HIER KOENNTE DER FEHLER LIEGEN WEIL ICH HIER WIEDER EINE DOCKINGSTATIONSEARCH ERZEUGE UND DAS GANZE IN DER GROSSEN WHILE SCHLEIFE VOM FCSQLQUERY ---------------------

  if (FCQuery.FieldByName('DockingstationID').AsInteger > 0) then
      begin
        FMyDSearch := TDockingstationSearch.Create;
        FMyDCriteria := TDockingstationAttributes.Create;
       
        // Search for the dockingstation that is used by the computer
        FMyDCriteria.SetID(
          FCQuery.FieldByName('DockingstationID').AsInteger);
        
        FDList := FMyDSearch.DBSearch('vague',FMyDCriteria);
        


        // Create the dockingstation object for the computer object
        FMyDockingstation := FDList[0] as Model.TDockingstation;
      
      end;
 
//---------------------



    // Set all the information of the computer object
    FMyComputer.SetAttributes(...,FMyComment,...,FMyGraphicCard,.., FMyDockingstation...);

    // Add computer object to a list of computer ojects
    FCList.Add(FMyComputer);

    FCQuery.Next;
  end;


  FCQuery.Free;
  Result := FCList;

end;
  Mit Zitat antworten Zitat