You are not logged in.
Pages: 1
Hello people,
I seek a little code or sample illustrating a process of displaying a result of a Query ( SQL statement ) in a DBGrid using Lazarus/Fpc and mORMot.
I do not see any *LCL* unit that bind mORMot data.
Thank you.
Offline
I am using the mORMot for filling DBGrids with Lazarus.
The TBufDataset is very suitable. It is used in SynDBMidasVCL.
Works very well.
ProjectDataset:=TSQLPropsToClientDataSet(Self,TSQLProject.RecordProps);
ProjectDataset.Active:=False;
ProjectDataset.Fields.Clear;
ProjectDataset.CreateDataset;
ProjectDataset.Active:=True;
DataSourceProject.DataSet:=ProjectDataset; //<----- this datasource is connected with a DBGrid
ProjectDataset.IndexFieldNames:='Code';
with TSQLProject.RecordProps do s:='ID,'+CSVFromFieldBits(FieldBitsFromExcludingCSV('Summary'));
Project := TSQLProject.CreateAndFillPrepare(DataBase,'',s);
T:=Project.FillTable;
if Assigned(T) then
begin
ProjectDataset.DisableControls;
ToClientDataSet(TClientDataSet(ProjectDataset),T);
ProjectDataset.First;
ProjectDataset.EnableControls;
end;
Project.Free;
ProjectDataset.BeforeScroll:=@DatasetBeforeScroll;
ProjectDataset.AfterScroll:=@DatasetAfterScroll;
Offline
I am using the mORMot for filling DBGrids with Lazarus.
The TBufDataset is very suitable. It is used in SynDBMidasVCL.
Works very well.
@AOG I can't compile trunk mORMot SynDBMidasVCL.pas with Lazarus 2fix, fpc 3.2fix. Do you have custom version, can you upload your version. SynDBMidasVCL use SynDBVCL and first error is in PSGetTableName, function GetTableNameFromSQL come from dbcommon Delphi only, I change to:
result := {$ifdef fpc}'' {$else} GetTableNameFromSQL(fCommandText){$endif};
Next error is in SynDBMidasVCL line 281 function From don't exist.
Any hint how you use dataset in Lazarus.
Offline
Here you go.
https://github.com/LongDirtyAnimAlf/mOR … LExtra.pas
Please feel free to use and ask any question.
I will take a closer look, but AFAIK all the rest is vanilla mORMot latest of a couple of weeks ago. Compiled with FPC fixes 3.2
Last edited by AOG (2020-06-11 17:52:19)
Offline
Thanks AOG, but this unit is not replacement for SynDBMidasVCL I need dataset from SynDB server to execute any query in existing not ORM Firebird DB.
Offline
Project := TSQLProject.CreateAndFillPrepare(DataBase,'Place your SQL here !',s);
Is the above not suitable ?
Offline
Is the above not suitable ?
Not suitable this time. TSQLProject is TSQLRecord descendant, I don't use ORM in this db, it is existing ERP database. I use TSQLDBServerSockets from SynDBRemote on server side and TSQLDBSocketConnectionProperties on client. Now I load data in T..ObjectDynArray and display data in VirtualStringTree like a DBGrid. Works well and fast but need a lot of boilerplate code. You define dataset fields from TSQLRecord props. I will try from data in ISQLDBRows interface.
Offline
@ab
I just investigate SynDBMidasVCL and find a bug for fpc to work.
{$endif FPC} in line 193 must be moved to line 226. First 3 ToClientDataSet functions are Delphi midas dependent. Also exclude add {$ifndef fpc} in implementation for first 3. Last 2 functions works fine with fpc and TBufDataset.
Offline
@ab
I just investigate SynDBMidasVCL and find a bug for fpc to work.
{$endif FPC} in line 193 must be moved to line 226. First 3 ToClientDataSet functions are Delphi midas dependent. Also exclude add {$ifndef fpc} in implementation for first 3. Last 2 functions works fine with fpc and TBufDataset.
hello.
Could you provide a unit complete source code for this.
I Urge to use it in my lazarus project.
I use this code :
procedure TForm1.Button1Click(Sender: TObject);
begin
if ds1.DataSet <> nil then
ds1.DataSet.Free;
//
if f_Prox <> nil then
FreeAndNil(f_Prox);
//
f_Prox := TSQLDBWinHTTPConnectionProperties.Create('127.0.0.1:'+edtPort.Text, 'Medec1',
'user', 'pass');
//
if f_Prox = nil then
raise Exception.Create(' httpConnection not !!! ');
//
//
stmt := f_Prox.NewThreadSafeStatement;
try
stmt.Execute('select * from uc_fzchs',True);
//ds1.DataSet := ToClientDataSet(self,stmt)
ds1.DataSet := SQLProToClientDataSet(Self, f_Prox); // ToDataSet(self,stmt); // in this stage it does not even compile.
finally
FreeAndNil(stmt);
FreeAndNil(f_Prox);
end;
end;
Offline
Use local interface variables, not class variables.
Then you don't need to use Free.
Ensure you release the stmt first by explicitely call stmt := nil.
Please check the docs.
Thanks, but could you recommande me an exemple or providence a portion of code to just begin
Thanks
Offline
Quick search in the doc reveals
https://synopse.info/files/html/Synopse … l#TITL_195
Offline
hello.
Could you provide a unit complete source code for this.
I Urge to use it in my lazarus project.
Already merged in trunk https://github.com/synopse/mORMot/pull/327
This is my code how I open/create TBufDataset
function TDBConn.OpenAttOpt(aId: integer): TBufDataset;
var Stmt: ISQLDBRows;
begin
Stmt := fProps.Execute('SELECT ID_ATT, WWVALUE, LABEL '+
'FROM WWATT_OPT '+
'WHERE ID_ATT=? ORDER BY ID_ATT, WWVALUE', [aID]);
if not Assigned(fAttOptDataSet) then begin
fAttOptDataSet := TBufDataset.Create(nil);
fAttOptDataSet.FieldDefs.Add('ID_ATT',ftInteger);
fAttOptDataSet.FieldDefs.Add('WWVALUE',ftString, 25);
fAttOptDataSet.FieldDefs.Add('LABEL',ftString, 40);
fAttOptDataSet.CreateDataSet;
fAttOptDataSet.Fields[0].Visible:=False;
fAttOptDataSet.Fields[1].DisplayLabel:='Value';
fAttOptDataSet.Fields[1].DisplayWidth:=25;
fAttOptDataSet.Fields[2].DisplayLabel:='Label';
fAttOptDataSet.Fields[2].DisplayWidth:=40;
end;
if ToClientDataSet(fAttOptDataSet, Stmt.Instance, 0, cdsReplace, false) then
result := fAttOptDataSet
else
result := nil;
end;
Note: If SQL is empty autocreated fields is Bad, I always create fields manually
Last edited by ttomas (2020-08-11 08:41:00)
Offline
Hello all,
I've posted a situation in lazarus/fpc forum, in case you can help.
https://forum.lazarus.freepascal.org/in … ic=52420.0
Thank you.
Offline
Pages: 1