Recent

Author Topic: Dataset has no fields [SOLVED]  (Read 5300 times)

Dalgor

  • Newbie
  • Posts: 4
Dataset has no fields [SOLVED]
« on: December 25, 2014, 03:48:00 pm »
Hi all,

I'm not an experienced coder and new with Lazarus.
I set up two parallel sqlqueries on a form (separate sqltransaction, sqlquery, dataset and even dbconnection), i have two dbgrids to show the data.
The connections are created basically according to the Sqldb tutorial. All components have the same properties set, i checked them many times.
My problem is: the second dataset (roles) has two records, but no fields. Does anyone has any idea why is that? I spent days with debugging without success.

procedure TUsersForm.RefreshUsers;
begin
  SQLTransactionGetUsers.Commit;
  SQLQueryGetUsers.Close;
  SQLQueryGetUsers.SQL.Text := 'select kezelo_id, login, nev, jelszo, jog_id, jog, ervenyes from SP_GET_USERS(' + IntToStr(MainForm.current_user_kezelo_id) + ');';
  SQLQueryGetUsers.Open;
end;   

procedure TUsersForm.RefreshRoles;
begin
  SQLTransactionGetRoles.Commit;
  SQLQueryGetRoles.Close;
  SQLQueryGetRoles.SQL.Text := 'select jog_id, leiras from SP_GET_ROLES;';
  SQLQueryGetRoles.Open;
  DatasourceGetRoles.DataSet.Active:=true;
  ShowMessage('Datasource GetRoles field count: ' + IntToStr(DatasourceGetRoles.DataSet.FieldCount));                      //output: 0
  ShowMessage('Datasource GetRoles record count: ' + IntToStr(DatasourceGetRoles.DataSet.RecordCount));             //output: 2
end;                           

The Firebird stored procedure (gives correct output in FlameRobin):
alter procedure sp_get_roles returns (jog_id smallint, leiras varchar(50)) as
begin
   for select jog_id, leiras
      from t_szerepkorok
      into :jog_id, :leiras
   do
   suspend;
end ^


Platform: Win7
Lazarus version: 1.0.13, FPC version 2.6.2
Firebird 2.5.2 embedded
« Last Edit: December 29, 2014, 12:05:27 am by Dalgor »

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: Dataset has no fields
« Reply #1 on: December 25, 2014, 07:23:56 pm »
Interesting!
What value returns:
  ShowMessageFmt(GetRoles FieldDefs: %d', [DatasourceGetRoles.DataSet.FieldDefs.Count]);
?

Dalgor

  • Newbie
  • Posts: 4
Re: Dataset has no fields
« Reply #2 on: December 25, 2014, 08:26:34 pm »
Thanks for answering in such a short notice.

GetRoles FieldDefs: 2

I forgot to mention but obviously the dbgrid shows up empty.

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: Dataset has no fields
« Reply #3 on: December 26, 2014, 09:40:12 am »
So it seems, that field definitions are fetched from Firebird correctly, but Fields are not created as expected.
I have no idea where can be problem ?
Can you reproduce it with latest version Lazarus + FPC ?
If it is reproducible, can you upload here your testing code?

Dalgor

  • Newbie
  • Posts: 4
Re: Dataset has no fields
« Reply #4 on: December 27, 2014, 11:29:53 pm »
I upgraded my environment (should have done that before asking) and the issue still exists (Laz 1.2.6 / FPC 2.6.4).

I hope i included everything necessary (could not add  Firebird embedded's files because of the size constraint).
The form in question is KifutStartUsersForm (bottom middle button on the main screen after login).
There are remains of debugging attempts there, i left it as it is.

Thanks.

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: Dataset has no fields
« Reply #5 on: December 28, 2014, 06:27:30 pm »
Problem is that after:
  SQLQueryGetRoles.Open
you use:
  SQLTransactionGetRoles.Commit;
Commit by default closes all active dataset which are using given transaction.

Use instead of Commit:
  SQLTransactionGetRoles.CommitRetaining;

You can try also move ShowMessages after your Commit and you will see, that there will be FieldCount=2

Dalgor

  • Newbie
  • Posts: 4
Re: Dataset has no fields [SOLVED]
« Reply #6 on: December 29, 2014, 12:07:16 am »
I put that commit there "just to make sure"...

You were right, the data shows up now in the grid.

Thanks for your help!

 

TinyPortal © 2005-2018