Recent

Author Topic: Database and zeos manual  (Read 12310 times)

notebook

  • New Member
  • *
  • Posts: 21
Database and zeos manual
« on: August 03, 2011, 10:01:56 pm »
I try manual zeoslib and work fine, if I all put in event on click.

I have second example but don' t work.


Code: [Select]
unit Unit2;

interface

uses
  Classes, SysUtils,sqldb,db,Types,Dialogs,ZConnection,
  ZDataset, ZSqlProcessor, ZStoredProcedure,DBGrids;
type
  connectiom=class(TObject)
    public
   function q(query: string): TDataSet;
   private
     c : TZConnection;
     qu : TZQuery;
     ds : TDataSource;

  end;



implementation


 function connectiom.q(query: string): TDataSet;
begin
  c := TZConnection.Create(nil);
  qu:=TZQuery.Create(nil);
  ds:=TDataSource.Create(nil);

  c.Catalog:='postgres';
  c.Database:='postgres';
  c.HostName:='127.0.0.1';
  c.Password:='postgres';
  c.port:=5432;
  c.Protocol:='postgresql-8';
  c.User:='postgres';

 qu.Connection:=c;
 qu.SQL.Text:=query;
 ds.DataSet:=qu;

 c.Connect;
 q.Active:=true;

end;

 end.





Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  DBGrids, ZConnection, ZDataset, unit2, db;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
  private
   p : connectiom;
   ds : TDataSource;

  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
   p:=connectiom.Create;
   ds:=TDataSource.Create(nil);


 ds.DataSet:=  p.q('select * from my_table');

   DBGrid1.DataSource:= ds;


end;

end.


what is wrong in unit1?
Is unit2 correct?

Can function  return dataset?
« Last Edit: August 03, 2011, 10:04:19 pm by notebook »

nicke85

  • Jr. Member
  • **
  • Posts: 92
  • #13#10
Re: Database and zeos manual
« Reply #1 on: August 03, 2011, 11:47:37 pm »
What is with this topic?
http://www.lazarus.freepascal.org/index.php/topic,14051.0.html
Is that the same topic twice?
ArchLinux X64 (XFCE) & Windows 7 SP1 Ultimate X64
FPC 2.7.1 / Lazarus 1.1 / ZeosDBO / fortes4lazarus -- all svn

notebook

  • New Member
  • *
  • Posts: 21
Re: Database and zeos manual
« Reply #2 on: August 04, 2011, 07:16:52 am »
What is with this topic?
http://www.lazarus.freepascal.org/index.php/topic,14051.0.html

This work If I put code on event.
I want create seperate class for connection and query, and yet one class for  BL.

Is that the same topic twice?

similar but diferent.

nicke85

  • Jr. Member
  • **
  • Posts: 92
  • #13#10
Re: Database and zeos manual
« Reply #3 on: August 04, 2011, 10:32:06 am »
I want create seperate class for connection and query, and yet one class for  BL.

You don't need to do that.Why do you need connection Class?
In zeos you have two elements for that ZConnectionGroup and ZGroupedConnection.These two elements is used to define one parameter for multiple connection so
just create these and then when need create ZConnection in runtime.

In your unit1 you call function connectiom.q and create dataset but where you destroy or free that dataset later?
ArchLinux X64 (XFCE) & Windows 7 SP1 Ultimate X64
FPC 2.7.1 / Lazarus 1.1 / ZeosDBO / fortes4lazarus -- all svn

notebook

  • New Member
  • *
  • Posts: 21
Re: Database and zeos manual
« Reply #4 on: August 05, 2011, 01:21:36 pm »
I want create seperate class for connection and query, and yet one class for  BL.

You don't need to do that.Why do you need connection Class?
In zeos you have two elements for that ZConnectionGroup and ZGroupedConnection.These two elements is used to define one parameter for multiple connection so
just create these and then when need create ZConnection in runtime.

In your unit1 you call function connectiom.q and create dataset but where you destroy or free that dataset later?

Thank you.

Can I return  data as  dataset and how?

notebook

  • New Member
  • *
  • Posts: 21
Re: Database and zeos manual
« Reply #5 on: August 05, 2011, 09:23:15 pm »
solved

Menkaura

  • Newbie
  • Posts: 1
Re: Database and zeos manual
« Reply #6 on: April 03, 2014, 09:53:13 pm »
I try manual zeoslib and work fine, if I all put in event on click.

I have second example but don' t work.


Code: [Select]
unit Unit2;

interface

uses
  Classes, SysUtils,sqldb,db,Types,Dialogs,ZConnection,
  ZDataset, ZSqlProcessor, ZStoredProcedure,DBGrids;
type
  connectiom=class(TObject)
    public
   function q(query: string): TDataSet;
   private
     c : TZConnection;
     qu : TZQuery;
     ds : TDataSource;

  end;



implementation


 function connectiom.q(query: string): TDataSet;
begin
  c := TZConnection.Create(nil);
  qu:=TZQuery.Create(nil);
  ds:=TDataSource.Create(nil);

  c.Catalog:='postgres';
  c.Database:='postgres';
  c.HostName:='127.0.0.1';
  c.Password:='postgres';
  c.port:=5432;
  c.Protocol:='postgresql-8';
  c.User:='postgres';

 qu.Connection:=c;
 qu.SQL.Text:=query;
 ds.DataSet:=qu;

 c.Connect;
 q.Active:=true;

end;

 end.





Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  DBGrids, ZConnection, ZDataset, unit2, db;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
  private
   p : connectiom;
   ds : TDataSource;

  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
   p:=connectiom.Create;
   ds:=TDataSource.Create(nil);


 ds.DataSet:=  p.q('select * from my_table');

   DBGrid1.DataSource:= ds;


end;

end.


what is wrong in unit1?
Is unit2 correct?

Can function  return dataset?


in unit2

change   q.Active:=true;  to qu.Active:=true;

and add following line

q:=ds.DataSet;

That works for me.

 

TinyPortal © 2005-2018