return dataset

Forum related to the ZDBC API-Layer

Moderators: gto, cipto_kh, EgonHugeist

notebook
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 04.08.2011, 07:25

return dataset

Postby notebook » 04.08.2011, 07:39

How I can return type dataset with data? here is example, but don't work.
I created unit2 with zeoslib classes, manual, and in unit1, I called unit2.


Code: Select all

unit Unit2;


interface

uses
  Classes, SysUtils,sqldb,db,Types,Dialogs,ZConnection,
  ZDataset, ZSqlProcessor, ZStoredProcedure;
type
  connectiom=class(TObject)
    public
   function q(query1: string): TDataSet;
   procedure z;

   private


  end;
  var
      c : TZConnection;
     qu : TZQuery;
     ds : TDataSource;




implementation

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

  c.Catalog:='postgres';
  c.Connected:=false;
  c.Database:='postgres';
  c.DesignConnection:=false;
  c.HostName:='127.0.0.1';
  c.LoginPrompt:=false;
  c.Password:='postgres';
  c.port:=5432;
  c.Protocol:='postgresql-8';
  c.ReadOnly:=false;
  c.User:='postgres';

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

end;

 procedure connectiom.z;
 begin

   c.Connect;
   qu.Active:=true;
 end;


 end.






Code: Select all

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 ;
   p.z;


end;

end.


guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Postby guidoaerts » 05.08.2011, 12:28

in unit1 you are assigning the result of p.q to ds.Dataset, and in p.q you assign qu to ds.dataset, but then q returns without result assigned.
maybe it works better if you replace in unit2

ds.DataSet:=qu;

with :

result := qu;

guido


Return to “ZDBC (ZEOS Database Connectivity)”

Who is online

Users browsing this forum: No registered users and 1 guest