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
]]>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
@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;
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.
]]>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
]]>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.
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;
Thank you.
]]>