#1 Re: Other components » SynMustache and logical conditions. » 2023-04-16 22:06:27

tbo wrote:
Bsaidus wrote:

Thanks igor for help, but it do not work for me.

You do not register the default helper, so "IF" is not available to you. You have to write it like this:

mustache.RenderJSON(Context, Nil, TSynMustache.HelpersGetStandardList)

All in all, I would not solve this during generation, but calculate it outside and then pass it. How to use Mustache is described in this article with source code.

With best regards
Thomas

Thank you Thomas, I'll read.

#2 Re: Other components » SynMustache and logical conditions. » 2023-04-16 21:41:36

ab wrote:

Try to use the debugger to find out why it did not work.
For instance, put a breakpoint into the "if" helper, i.e. TSynMustache.If_().

You will learn a lot about how it works.

I did, but it do not even enter there.

#3 Re: Other components » SynMustache and logical conditions. » 2023-04-15 23:18:08

igors233 wrote:

Use:
<option value="111.222.333.111" {{#if host.mask="111.222.333.111"}} selected {{/if}}> 111.222.333.111 </option>
<option value="222.222.222.0" {{#if host.mask="222.222.222.0"}} selected {{/if}}>222.222.222.0</option>

Thanks igor for help, but it do not work for me.

// lazarus code 
procedure TForm1.Button2Click(Sender: TObject);
var
  Template,
  Context,
  Result: RawUTF8;
  mustache: TSynMustache;
begin

  Template := StringToUTF8(mmTemp.Text);            // mmTemp = memo for template
  Context := StringToUTF8(mmJson.Text);               // mmJson = memo for json
  mmRes.Append( UTF8ToString(Context) );            // mmRes = memo for resulting rendring

  mustache := TSynMustache.Parse(Template);

  mmRes.Append('-----------------------------------------------------------');

  mmRes.Append(mustache.RenderJSON(Context));

end;  

#4 Other components » SynMustache and logical conditions. » 2023-04-15 21:28:28

Bsaidus
Replies: 8

Hello.
I wonder if there is a possibility in SynMustache to do some controls based on condition to display the wanted value.
Ex:
  I have to render an html page that containe a <Select> tag with 3 <Option>, but I want to make one <option selected > for a given one depending on value in .json.
is it possible to do this on SynMustache.
The Mustache engine comming from Freepascal trunk is buggy

EX: from the fcl-mustache.

// json 
{
  "host":{
    "name"     : "uc1.uccenos.net",
    "ip"       : "123.33.32.1",
    "mask"     : "222.222.222.0",
    "gateway"  : "123.33.23.3" 
  }
}

//template 
// depending on the mask value from json & make the adequate <Option> selected
<br/>
<ul>
  <li>hostnam : {{host.name}}</li>
  <li>ip      : {{host.ip}}</li>
  <li>mask    : {{host.mask}}</li>
  <li>gateway : {{host.gateway}}</li>
 <select name="themask">
    <option value="111.222.333.111" {{[IF(mask='111.222.333.111', 'selected','')]}}> 111.222.333.111 </option>
    <option value="222.222.222.0"   {{[IF(mask='222.222.222.0', 'selected','')]}}> 222.222.222.0   </option>  
    <option value="333.222.333.111" {{[IF(mask='333.222.333.111', 'selected','')]}}> 333.222.333.111 </option>
</select>

Thanks  you.

#5 Re: mORMot 1 » Executing a shell command with mORMot » 2022-10-21 08:17:52

ab wrote:

Yes, just call the shell from the service code.
You can use RunProcess() from mORMotService.pas - it will work on all supported OS and compiler.

Of course, it won't be very efficient, since creating a process has a non negligeable cost.

Hello Ab,
Is this response, also Valid for RemoteDB access, I mean, I use the RemoteDB technique offred by mORMot, so How can I execute command(s) after the server receive some data from the Client.
 
            ClientData  => SynDBRemote(TSQLDBServerRemote) => + Save data in DB
                                                                                                + ExecuteCmd

thanks you

#7 Re: mORMot 1 » Delphi TClie'tDataset TBlobField and mORMot. » 2022-04-18 08:26:04

Working with Blob database field is ennoying when it comes to store and retrieve images.
I think there is a bug in the SynGDIplus.pas unit ( or It is ma that do not understand the use ).
I use delphi xe2 with last updates, mORMot trunk from github and MariaDB10.3 as database server
( Note that with lazarus all works fine without doing ).

As I sayed above, I use the RemoteDB protocol to Insert/Update and visualise data in simple form.
  I use Standard DB Controls from Delphi ( DBGrid, DbEdit, DbImage, ... )
    I use TClientDataset component for local data.

  To update record on database I use :
   

	    // cd1 = ClientDataset.
		procedure TForm1.btnUpdateClick(Sender: TObject);
		const
	   	  sSQL = 'Update uc_blobt set Name=?, Obs=?, Pics=? where id=?';
		var
		  LField: Data.DB.TBlobField;
		  LStrRaw: RawByteString ;
		begin
		  Screen.Cursor := crHourGlass;
		  cd1.DisableControls;
		  try
		    //LField := cd1pics as TBlobField;
		    LField := cd1.FieldByName('Pics') as TBlobField;
		    try
		      LStrRaw := fGetRawStringFromBlob(LField);   // Pasting Bitmap into local TBlobField
		      // LStrRaw := fGetRawStringFromBlob(img1);
		      gfP.ExecuteNoResult( sSQL, [ cd1Name.AsWideString, cd1Obs.AsWideString, LStrRaw, cd1id.AsInteger ] );
		    except
		      //Abort;
		    end;
		  finally
		     cd1.EnableControls;
		     Screen.Cursor := crDefault;
		   end;
		end;
			
		// Return RawByteString from TImage Bitmap ( not DB control )
		function TForm1.fGetRawStringFromBlob(const AImage: TImage): RawByteString;
		begin
		  try
		    SaveAsRawByteString(AImage.Picture, Result, gptBMP);
		  except
		  end;
		end;

                // Return RawByteString from TField ( TBlobField ) associated to DBImage
		function TForm1.fGetRawStringFromBlob(const AField: Data.db.TField): RawByteString;
		var
		  LMStream: TMemoryStream;
		  LSPic: TSynPicture;
		begin
		  LMStream := TMemoryStream.Create;
		  LSPic := TSynPicture.Create;
		  try
		    try
		      TBlobField(AField).SaveToStream(LMStream);
		      LMStream.Position := 0;
		      LSPic.LoadFromStream(LMStream);
		      if LSPic.Empty then
		        Exit;
		      SaveAsRawByteString(LSPic, Result, gptBMP);
		    except
		    end;
		  finally
		    FreeAndNil(LMStream);
		    FreeAndNil(LSPic);
		  end;
	     end;			
	

   
   
   
    Effectivelly the Image (Blob) is Updated into database server, But when trying to retrieve this Image using select, into a TImage or
    TBlobField (TdbImage) an Stream read error Exception occures
    I Tried to do another way by using a procedure that uses mORMOt GDI functions :

		procedure TForm1.fRetrieveImageBinary;
		var
		  LRStr: RawByteString ;
   		  LMStream: TMemoryStream;
		  Lbmp: TBitmap;
		begin
		//  LPic := TSynPicture.Create;
		//  LMStream := TMemoryStream.Create;
		  Lbmp := TBitmap.Create;
		  try
		//    TblobField(cd1Pics).SaveToStream(LMStream);
		//    LRStr := StreamToRawByteString(cd1Pics.AsAnsiString);
		    Lbmp := LoadFromRawByteString(cd1Pics.AsAnsiString);
		    img1.Picture.Assign(Lbmp);
		 finally
		   Lbmp.Free;
		//    LMStream.Free;
		//    LPic.Free;
		 end;
		end;

But nothing work.
(PS: In lazarus I use

 TBlobField.Value 

into the update/insert and it works.

here is a binary representation of the footprint in database blob field.
https://pasteboard.co/25A1VPoIQh46.jpg

So do you have a solution for this
Thanks you .

#8 Re: mORMot 1 » Delphi TClie'tDataset TBlobField and mORMot. » 2022-04-14 17:51:22

I use SynDBRemote.
I edit locally the record by adding an image to the blob field of ClientDataset then I save locally, after that I construct my SQL statement with "?" and execute it.
here is the code.

procedure TForm1.btnUpdateClick(Sender: TObject);
const
  sSQL = 'Update uc_blobt set Name=?, Obs=?, Pics=? where id=?';
var
  LField: Data.DB.TBlobField;
  LStrRaw: RawByteString ;
  Val: Variant;
begin
  Screen.Cursor := crHourGlass;
  cd1.DisableControls;
  try
    LField := cd1.FieldByName('Pics') as TBlobField;   // 'cd1' TClientDataset Field containig image file. ( locally)
    try
      LStrRaw := fGetRawStringFromBlob(LField);  // Encode countent of the blobfield into RawByteString
      gfP.ExecuteNoResult( sSQL, [ cd1Name.AsWideString, cd1Obs.AsWideString, LStrRaw, cd1id.AsInteger ] );
    except
      //Abort;
    end;
  finally
    cd1.EnableControls;
    Screen.Cursor := crDefault;
  end;

end;

function TForm1.fGetRawStringFromBlob(const AField: Data.db.TField): RawByteString;
var
 LMStream: TMemoryStream;
 LSPic: TSynPicture;
 LOutStr: RawByteString ;
begin
  LOutStr := '';
  LMStream := TMemoryStream.Create;
  LSPic := TSynPicture.Create;
  try
    try
      TBlobField(AField).SaveToStream(LMStream);
      LMStream.Position := 0;
      LSPic.LoadFromStream(LMStream);
      if LSPic.Empty then
        Exit;
      SaveAsRawByteString(LSPic, LOutStr, gptJPG);
      Result := LOutStr;
    except

    end;
  finally
    FreeAndNil(LMStream);
    FreeAndNil(LSPic);
  end;

end;

#9 mORMot 1 » Delphi TClie'tDataset TBlobField and mORMot. » 2022-04-14 14:00:33

Bsaidus
Replies: 5

Hello.
I have a little problem updating a table in containing a BLOB field that container Image.
The scenario is :
    - Having mORMot http server.
    - client application containing TClientDataset dBGrid and controls that goes with.
  After posting a data to ClientDataset in Local, the function updates record in remote server, but the image in the blob field do not and application gives error "can not open resultset" .
So what is the mechanism to assign the content of blob field (image) into the SQL query.

Ex: the update statement is : update tmptable set tmpblob=? Where Id=?
  The values of "?" Are given from the values of ClientDataset fields.

#10 Re: Free Pascal Compiler » Whats wrong with this code. » 2021-12-17 12:20:26

Hi,
To contour the problème, I used IdTCPClient to check the availibility of the server before creating the TSQLDBWinHTTPConnectionProperties instance.

Thanks anyway

#11 Re: Free Pascal Compiler » Whats wrong with this code. » 2021-12-16 09:15:55

I confirme, this is a Bug under Freepascal/lazarus.
You can test your self the code posted in the lazarus forum

https://forum.lazarus.freepascal.org/in … 544.0.html

#12 Re: Free Pascal Compiler » Whats wrong with this code. » 2021-12-15 13:28:15

Hello ab,
here you can find a simple test:   


test mORMot RemoteDB


PS: Using CMEM in the top of all used units in the project file .lpr, resolve things, But I do not know if it really catches the leak.

#13 Free Pascal Compiler » Whats wrong with this code. » 2021-12-15 08:54:06

Bsaidus
Replies: 4

Hi,
I use lazarus-2.0.12-fpc322.
I have the following code on the Create constructor of the datamodule followed by the destructor.

constructor TgMainDM.Create(AOwner: TComponent);
var
  sHostPort: String;
  iErr: Integer;
begin
  inherited Create(AOwner);

  iErr        := 0;                           // Error ID = 0
  gfP         := Nil;                         // Connection ID = NULL
  gSQLCache   := TStringList.Create;          // Initialise SQL cache
  //gFormList   := TStringList.Create;        // List of forms displayed
  gId         := -1 ;                         // Global iD for Patients, ... := 0
  gJConfig    := fQueryGetConfig();           // Read config json file
  gBUseCache  := gJConfig.Uc_UseCache;        // Use SQL cach or not


  //gfP         := fQueryHttpSQLConnection( gJConfig.Uc_host,
  //                  gJConfig.Uc_port, gJConfig.Uc_db,
  //                  gJConfig.Uc_user, gJConfig.Uc_pass
  //);                                          // Get Server connection parameter

{ ------------------------------------------------------------------------------- }

  sHostPort := gJConfig.Uc_host + ':' + gJConfig.Uc_port;
  try
    try
      gfP := TSQLDBWinHTTPConnectionProperties.Create( sHostPort , gJConfig.Uc_db,
        gJConfig.Uc_user, gJConfig.Uc_pass );

      if ( gfP<>nil ) then
        gfP.VariantStringAsWideString := true;
    except on E: Exception do
      begin
        iErr := 1;
        MessageDlg('HttpReq', 'Error connecting to Server'+ LineEnding+LineEnding+E.Message, mtWarning, [mbOK], 0);
        //raise Exception.Create('Error connecting to HttpServer: ' + LineEnding + E.Message);
        //gfP := Nil;
        //Application.Terminate;
      end;
    end;
  finally
    if ( iErr = 1 ) then
       FreeAndNil(gfP);
  end;

{ ------------------------------------------------------------------------------- }

end;

destructor TgMainDM.Destroy;
begin

  if gfP<>nil then
    FreeAndNil(gfP);
  FreeAndNil(gSQLCache);
  //FreeAndNil(gFormList);
  inherited Destroy;
end; 

The application has MainForm and DataModule auto created.
the datamodule is created first to instanciate RemoteDB connection to server.
if the server is running, alls goes OK, but if the server is shutdown, the except block executes and error message will appear and the MainForm shown.
But when I close the application, a memory leak is reported by HeapTrc.

Main Project:

program teryal;

{$mode delphi}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms,
  rxnew,
  lazcontrols, datetimectrls, memdslaz, dbflaz,
  umain,
  umaindm
  ;

{$R *.res}

begin
  RequireDerivedFormResource := True;
  Application.Scaled := True;
  Application.Initialize;
  Application.CreateForm(TgMainDM, gMainDM);
  Application.CreateForm(TfrMain, frMain);
  Application.Run;
end. 

What's wrong. ???

#14 mORMot 1 » Mormot functions in a DLL » 2021-06-08 10:08:24

Bsaidus
Replies: 5

Hello,
I have posted a question in lazarus forum
Issue With DLL, exposing some problems related to some made functions incapsulating mORMot functions and classes instances.
So.
Can we instantiate a Connection to remote server with global variable located in a DLL.
if no Can I initialise a global variable in Program, and give it as parameter to functions located in DLL.

Thank you.

#15 Re: Free Pascal Compiler » mORMot TQuery and Unicode ( french accent characters) » 2020-12-20 19:36:42

I will do & see.

Yessss, it works without modification of the Get Procedure.

#16 Re: Free Pascal Compiler » mORMot TQuery and Unicode ( french accent characters) » 2020-12-19 17:00:11

Re Hi,
I played with the procedure : GetAsWideString and added some code.
Now it works well:

function TQueryValue.GetAsWideString: SynUnicode;
begin
  CheckValue;
  with TVarData(fValue) do
  case VType of
    varNull:     result := '';
    varInt64:    result := UTF8ToSynUnicode(Int64ToUtf8(VInt64));
    {$ifdef fpc}  // +
    varString:   result := WideString(RawUTF8(VAny));//UTF8ToSynUnicode(RawUTF8(VAny));   // + 
    {$else}  // +
    varString:   result := UTF8ToSynUnicode(RawUTF8(VAny));
    {$endif}  // +
    {$ifdef HASVARUSTRING}
    varUString:  result := UnicodeString(VAny);
    {$endif}
  else Result := SynUnicode(fValue);
  end;
end; 

If someone needs or if you want to fixe the compatibility with FPC.
Do the samething for String.
Thanks

#18 Re: Free Pascal Compiler » mORMot TQuery and Unicode ( french accent characters) » 2020-12-18 19:27:33

I use lazarus 2.0.10 with fpc 3.2.0 in   {$mode delphi }  mode.
I must informe you that this does not function correctelly when it return a string that have accents

function fQueryComboBoxInit      (var oCBox : TComboBox; sChField : string): Boolean;
var
  fQuery: TQuery;
  fNc: TSQLDBConnection;
  fWstr, WSQL: WideString;
begin
  Result := False;
  oCBox.Clear;
  fNc := gfP.NewConnection;
  fQuery := TQuery.Create(fNc);
  WSQL := 'SELECT fz_desig FROM uc_fzchs WHERE fz_field = :sChField';
  with fQuery do
  begin
    try

      SQL.Clear;
      SQL.Add ( WSQL );
      try
        ParamByName('sChField').AsWideString := sChField;
        Open;
        oCBox.Items.Add(NullStr^);
        while not EOF do
        begin
          // fWstr := FieldByName('fz_desig').AsWideString ; // Not work, ether AsString ( return Alg insteed of Algérie)
          fWstr := FieldByName('fz_desig').AsVariant;   // works well 
          oCBox.Items.Append( fWstr );
          Next;
        end;
        oCBox.ItemIndex := 0;
      except
        raise;
      end;
    finally
      Free;
      fNc.Free;
    end;
  end;
  Result := True;
end;               

Just one question, is the native type "string" support caracters with accents ( french for exemple ) or I must use WideString ??

Thanks.

#19 Free Pascal Compiler » mORMot TQuery and Unicode ( french accent characters) » 2020-12-17 13:33:11

Bsaidus
Replies: 7

Hello, I have to use TQuery to execute SQL statement:

function fQueryComboBoxInit(var oCBox: TComboBox; sChField: string; sLocation: WideString): Boolean;
var
  fQuery: TQuery;
  fNc: TSQLDBConnection;
  fWstr, fWSQL: WideString;
begin
  REsult := False;
  fNc := gfP.NewConnection;
  fQuery := TQuery.Create(fNc);
  fWSQL := 'SELECT fz_desig FROM uc_fzchs WHERE fz_field = ' + QuotedStr(sChField) +
                '   AND fz_parent_id = (SELECT MIN(b.fz_seq) FROM uc_fzchs b ' +
                ' WHERE lower(b.fz_desig) LIKE lower(' + QuotedStr(  ' :text ' ) + '))';
                //' WHERE lower(b.fz_desig) LIKE lower(' + QuotedStr(sLocation) + ' ))' );
  with fQuery do
  begin
    try
      SQL.Clear;
      SQL.Add ( fWSQL );
      try
        fQuery.ParamByName('text').AsVariant := sLocation;    // not work for Algérie, Français ... .
        Open;
        oCBox.Clear;
        oCBox.Items.Add(NullStr^);
        while not EOF do
        begin
          fWstr := FieldByName('fz_desig').AsVariant;
          oCBox.Items.Append( fWstr );
          Next;
        end;
        oCBox.ItemIndex := 0;
      except
        raise;
      end;
    finally
      Free;
      fNc.Free;
    end;
  end;
  Result := True;

end;

But when executed, It return 0 records, Because it sends parameter in wrong character set.

?? Help please ??

#20 Re: Free Pascal Compiler » Using Lazarus DBGrid with mORMot. » 2020-12-06 21:39:44

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.

#21 Re: mORMot 1 » Bind mORMot Http(s) Server to an IP address. » 2020-08-20 09:57:33

ab wrote:

Did you try to use '1.2.3.4:8080' instead of plain '8080'?

No not yet .. .I'll try.
Thanks

#22 mORMot 1 » Bind mORMot Http(s) Server to an IP address. » 2020-08-19 12:04:12

Bsaidus
Replies: 2

Hello.
Is there any way to bind mORMot http(s) server to a specific IP address ( if I have a multiple card or Ip addresses ).

f_Http := TSQLDBServerRemote.Create( f_DB, 'Medec1', '8080', 'user', 'pass');

Thanks.

#23 Re: Free Pascal Compiler » Using Lazarus DBGrid with mORMot. » 2020-08-10 10:38:08

ab wrote:

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

#24 Re: Free Pascal Compiler » Using Lazarus DBGrid with mORMot. » 2020-08-08 21:49:59

ttomas wrote:

@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;     

#25 Free Pascal Compiler » Using Lazarus DBGrid with mORMot. » 2020-06-10 20:59:59

Bsaidus
Replies: 14

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.

#26 Re: mORMot 1 » What to choose for best results. » 2020-06-02 22:11:20

Thank you Arnaud for a quick reply.

ab wrote:

I would use SQlite3 as database engine, possibly with several databases, e.g. one per Doctor.
Or at least use SQLite3 with a Micro-Service orientation, i.e. not a single REST server, but several, each one with its context and purpose... and its own database.
This would give the best performance and scaling.

The database will be centralised ( the doctors can see Patients files simultaniousely ( not diagnostics ) ).
Do not you think that spread a SQLite3 db's and doing synchronization between them for each modification will engender much network trafic & much work in programmig.?


ab wrote:

Zeos is very good and well supported. But I would use the SynDB layer in front of it, to have direct JSON support, and the ability to switch to the ORM if needed.
And use MariaDB in preference to Firebird. Or even better, if a enterprise-grade DB is needed, consider PostgreSQL, which has SynDBZeos or direct SynDBPostgresql support.

Of course I'll use the mormot interface to ZEOS, and thank you for advising MariaDB.

ab wrote:

Of course, for a new project I would switch to Lazarus/FPC, since it is more stable (FPC 3.2 fixes + Lazarus 2.6), and has perfect Linux support, whereas we don't support Delphi for Linux.

Can I use the lazarus/fpc (3.2rc1) even in the RC state ??

ab wrote:

Instead of a VPN, I may also try our Relay feature, much easier to configure.

First time I listen that 'RELAY FEATURE', could you point me to the DOC or even to the exemple that treating this feature.?

ab wrote:

And I would use the ORM, to use objects, not SQL.

I have a poor experience with ORM's & I'm habituated to work with SQL, so It is not so easy to swich.


Thanks you ARNAUD.

#27 mORMot 1 » What to choose for best results. » 2020-06-02 21:25:44

Bsaidus
Replies: 3

Hello.
I want to know your opinion on what to choose to get best or very optimized results.
( or What you advise me basing on your experiences )

   1 )  for Database engines: 
           *  MariaDB or Firebird.
   2 )  for Object pascal dialect 
          * Delphi XE2, Delphi 2007 ( I have licenses ).
          * Lazarus/FPC
   3 ) Components for DB connection.
          * Zeos   ( I usually use ZEOS and I'm satisfied )

  Technical infos about the software.
    The soft I want to begin work is for Doctors, it will work with REST ( only REST no ORM ), and I want to use mORMot technologie for that.
    Certainnely the REST server and DB Server will be in some UNIX environnement.
    the communication will use VPN.

So What you advise me to choose ( mainelly DB engine that scall good.).

Thank you.

#28 Re: mORMot 1 » Error: project1 raised exception class 'External: SIGSEGV'. » 2019-10-30 13:28:51

ab wrote:

SynDB TQuery has NOTHING in common with DB.pas TQuery.

It is not a class, but a pointer to a record, so you need to write oQuery.FieldByName('....')^. for completion.
(unless you use Delphi mode which doesn't require the ^)


Ooops !! ah d'accord ! cool

#29 Re: mORMot 1 » Error: project1 raised exception class 'External: SIGSEGV'. » 2019-10-30 08:09:09

ab wrote:

I guess you are messing with classes.

oQuery.FIeldByName is NOT returning a TMemoField.

No, this is my uses clause.

uses
  Classes, SysUtils, JsonConf , Db,  
  mORMot, SynDB, SynTable, SynDBRemote, SynDBDataset;

and even the lazarus code completion gives an error while I try to push CTRL+SPACE after a point in

 oQuery.FieldByName('QRSQL_SQL'). 

Error is : Codetools, Errors: 1
mormotclassfuncs.pas(290,27) Error: illegal qualifier . found

PS : Note the point.

#30 mORMot 1 » Error: project1 raised exception class 'External: SIGSEGV'. » 2019-10-29 10:37:23

Bsaidus
Replies: 5

Hello,
I have this function that connect to Server and get a text record from DB.
But it generate an exception :

Error
Project project1 raised exception class 'External: SIGSEGV'.
 At address 5B7A2D
function TMORMotObject.fGetQRSQLList: Boolean;
var
  oQuery: TQuery;
  oStream: TMemoryStream;
  sSQLstring: String;
  fld: TField;
begin
  Result := False;
  try
    // replace Rqsql_id
    sSQLstring := fRQSQL_txt;
    sSQLstring := StringReplace( sSQLstring, ':fRQSQL_id', IntToStr(fRQSQL_id), [rfReplaceAll]);
    // Create a Stream
    oStream := TMemoryStream.Create;
    // Create Connection.
    oQuery := TQuery.Create( fP.ThreadSafeConnection );
    oQuery.SQL.Clear;
    //oQuery.SQL.Add( 'SELECT QRSQL_C_TEXT     ' + sLineBreak + '  FROM T_QRSQL          ' + sLineBreak +  ' WHERE QRSQL_B_ACTIV = 1' + sLineBreak + '   AND QRSQL_B_SUP   = 0' + sLineBreak + '   AND QRSQL_N_ID    = ' +  IntToStr(fRQSQL_id) );
    oQuery.SQL.Add( sSQLstring );
    //oQuery.ParamByName('fRQSQL_id').AsString := fRQSQL_id;
    oQuery.Open;
    //
    if oQuery.IsEmpty then
      raise Exception.Create('No QRSQL for this ID');
    // Save to stream
    TMemoField( oQuery.FieldByName('QRSQL_SQL')).SaveToStream( oStream ) ;       < -- here where exception is fired
    // fSQL.Text := TField(oQuery.FieldByName('QRSQL_SQL')).AsString;                    < -- this not work.
    //oQuery.FieldByName('QRSQL_SQL').SaveToStream( oStream ) ;
    if oStream.Size <= 0 then
      raise exception.Create('No SQL inside ...');
    oStream.Position := 0;
    // return the QRSQL to StringList
    fSQL.LoadFromStream(oStream);
  finally
    FreeAndNil(oQuery);
    FreeAndNil(oStream);
  end;
end;   

Thanks for help.

#31 mORMot 1 » TQuery Connection mapping. » 2019-10-28 14:45:42

Bsaidus
Replies: 0

Hello.
I use a TSQLDBWinHTTPConnectionProperties to create a Connection to remote server, and I use TQuery to do my Work, but the Create constructor for TQuery take a TSQLDBConnection.
So my question is How to mappe this connection (TSQLDBWinHTTPConnectionProperties) to work with TQuery.

Thanks you in advence.

#32 Re: mORMot 1 » ORacle issue!! » 2019-10-01 08:51:45

mpv wrote:

You can try with SynDBOracle instead zeos. And please, do not paste huge code blocks here, use gists instead

Yes smile !!

#33 mORMot 1 » ORacle issue!! » 2019-09-30 14:48:55

Bsaidus
Replies: 2

Hello,
I'm trying to experiment a client/server over http with mormot by publishing my oracle DB over Http.
And I have this issue :

20190930 14340552  +    SynDBZeos.TSQLDBZEOSStatement(07898f30).Prepare
20190930 14340552  +    	SynDBZeos.TSQLDBZEOSConnection(07880f18).Connect to oracle ORADEV for  at 0:
20190930 14340558 DB    		Connected to  using ORADEV 11002000
20190930 14340558  +    		SynDBZeos.TSQLDBZEOSStatement(07899060).Prepare
20190930 14340558  -    		00.002.194
20190930 14340558  +    		SynDBZeos.TSQLDBZEOSStatement(07899060).ExecutePrepared
20190930 14340558 SQL   			SynDBZeos.TSQLDBZEOSStatement(07899060) select sysdate from dual
20190930 14340558  -    		00.004.074
20190930 14340558  -    	00.090.270
20190930 14340558  -    00.090.820
20190930 14340558  +    SynDBZeos.TSQLDBZEOSStatement(07898f30).ExecutePrepared
20190930 14340558 SQL   	SynDBZeos.TSQLDBZEOSStatement(07898f30) select sysdate from dual
20190930 14340558  -    00.003.685
20190930 14340559  +    SynDBZeos.TSQLDBZEOSStatement(07899190).Prepare
20190930 14340559  -    00.000.689
20190930 14340559  +    SynDBZeos.TSQLDBZEOSStatement(07899190).ExecutePrepared
20190930 14340559 SQL   	SynDBZeos.TSQLDBZEOSStatement(07899190) select * from employee
20190930 14340559  -    00.003.119
20190930 14340633 EXC   EZSQLException ("SQL Error: OCI_ERROR: ORA-01406: la valeur de la colonne extraite a été tronquée\n") [] at   $0073F281  CHECKORACLEERROR,  line 1146 of C:/GNU/fpc3tr/Ccr/Zeos/src/dbc/ZDbcOracleUtils.pas  $00748A94  TZORACLERESULTSET__NEXT,  line 1616 of C:/GNU/fpc3tr/Ccr/Zeos/src/dbc/ZDbcOracleResultSet.pas  $00600587  TSQLDBZEOSSTATEMENT__STEP,  line 1177 of C:/GNU/fpc3tr/Ccr/mORMot/SynDBZeos.pas  $005F6804  TSQLDBSTATEMENT__FETCHALLTOBINARY,  line 7229 of C:/GNU/fpc3tr/Ccr/mORMot/SynDB.pas  $005ED8C5  TSQLDBCONNECTION__REMOTEPROCESSMESSAGE,  line 4598 of C:/GNU/fpc3tr/Ccr/mORMot/SynDB.pas  $005FC722  TSQLDBSERVERABSTRACT__PROCESS,  line 328 of C:/GNU/fpc3tr/Ccr/mORMot/SynDBRemote.pas  $0062E39E  THTTPSERVERGENERIC__REQUEST,  line 5849 of C:/GNU/fpc3tr/Ccr/mORMot/SynCrtSock.pas  $0063167F  THTTPAPISERVER__EXECUTE,  line 8933 of C:/GNU/fpc3tr/Ccr/mORMot/SynCrtSock.pas  $0043A725  $004130EE  $77386359  $77D77B74  $77D77B44
20190930 14342901  +    SynDBZeos.TSQLDBZEOSStatement(07899190).ExecutePrepared
20190930 14342901 SQL   	SynDBZeos.TSQLDBZEOSStatement(07899190) select * from employee
20190930 14342901  -    00.000.027
20190930 14342949 EXC   EZSQLException ("SQL Error: OCI_ERROR: ORA-01406: la valeur de la colonne extraite a été tronquée\n") [] at   $0073F281  CHECKORACLEERROR,  line 1146 of C:/GNU/fpc3tr/Ccr/Zeos/src/dbc/ZDbcOracleUtils.pas  $00748A94  TZORACLERESULTSET__NEXT,  line 1616 of C:/GNU/fpc3tr/Ccr/Zeos/src/dbc/ZDbcOracleResultSet.pas  $00600587  TSQLDBZEOSSTATEMENT__STEP,  line 1177 of C:/GNU/fpc3tr/Ccr/mORMot/SynDBZeos.pas  $005F6804  TSQLDBSTATEMENT__FETCHALLTOBINARY,  line 7229 of C:/GNU/fpc3tr/Ccr/mORMot/SynDB.pas  $005ED8C5  TSQLDBCONNECTION__REMOTEPROCESSMESSAGE,  line 4598 of C:/GNU/fpc3tr/Ccr/mORMot/SynDB.pas  $005FC722  TSQLDBSERVERABSTRACT__PROCESS,  line 328 of C:/GNU/fpc3tr/Ccr/mORMot/SynDBRemote.pas  $0062E39E  THTTPSERVERGENERIC__REQUEST,  line 5849 of C:/GNU/fpc3tr/Ccr/mORMot/SynCrtSock.pas  $0063167F  THTTPAPISERVER__EXECUTE,  line 8933 of C:/GNU/fpc3tr/Ccr/mORMot/SynCrtSock.pas  $0043A725  $004130EE  $77386359  $77D77B74  $77D77B44

// Client CODE in DELPHI

// Client CODE 

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Image1: TImage;
    btnOpen: TButton;
    DBGrid1: TDBGrid;
    ds1: TDataSource;
    DBNavigator1: TDBNavigator;
    ZConnection1: TZConnection;
    ZReadOnlyQuery1: TZReadOnlyQuery;
    procedure FormDestroy(Sender: TObject);
    procedure btnOpenClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

    Props, Props1: TSQLDBConnectionProperties;
    mystmt, mystmt1: TSQLDBStatement;
    Dst: TDataSet;

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if ds1.DataSet <> nil then
    ds1.DataSet.Free;
end;

procedure TForm1.btnOpenClick(Sender: TObject);
begin
  //
  if Props<>nil then
    FreeAndNil(Props);

  Props := TSQLDBWinHTTPConnectionProperties.Create('127.0.0.1:8111','fp','user','pass');
  if props = nil then
  begin
    ShowMessage('fuifhiuzezufh');
    Abort;
  end;
  //
  ds1.DataSet.Free; // release previous TDataSet
  ds1.DataSet := ToDataSet(ds1,Props.Execute('select * from employee',[]));

end;

// Server CODE in LAZARUS ( using ZEOS Dbo 7.2.4 stable)

// Server CODE 
unit umain;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  jsonConf,
  //
  mORMot,
  mORMotDB,
  SynCommons,
  SynDB,
  SynDBRemote,
  SynDBZeos,
  //
  SynLog

  ;

type

  TCntInfos = record
    sHost: String;
    sDB: String;
    iPort: Integer;
    sUser: String;
    sPass: String;
    sLib: String;
  end;

  { TForm1 }

  TForm1 = class(TForm)
    btnStart: TButton;
    btnStop: TButton;
    btnClose: TButton;
    Label1: TLabel;
    Memo1: TMemo;
    procedure btnStartClick(Sender: TObject);
    procedure btnStopClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private

  public
    fInfo: TCntInfos;
    fJCnf: TJSONConfig;
    fFileCfg: String;

    // mORMot vars
    fp: TSQLDBZEOSConnectionProperties;
    hts: TSQLDBServerHttpApi; //TSQLDBServerSockets;  //TSQLDBServerHttpApi
    //Server : TSQLHttpServer;
    //

    // gEneral functions .
    function fReadConfig: Boolean;
    function fStartServer: Boolean;
    function fStopServer: Boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  fp := nil;
  Hts:= nil;
  fFileCfg := '';

  // Read Config File .
  if not fReadConfig then begin
    ShowMessage('File not Exists: ' + fFileCfg);
    Application.Terminate;
  end;
  with Memo1.Lines do
  begin
    Add(fInfo.sHost);
    Add(fInfo.sDB);
    Add(IntToStr(fInfo.iPort));
    Add(fInfo.sUser);
    Add(fInfo.sPass);
    Add(fInfo.sLib);
  //end;
  end;

  // Start the server direct
  fStartServer;

end;

procedure TForm1.btnStartClick(Sender: TObject);
begin
  fStartServer;
end;

procedure TForm1.btnStopClick(Sender: TObject);
begin
  fStopServer;
end;

function TForm1.fReadConfig: Boolean;
begin
  Result := False;
  fFileCfg := ChangeFileExt(ParamStr(0), '.json');
  if not FileExists( fFileCfg ) then
    Exit;
  fJCnf :=  TJSONConfig.Create(nil);
  try
    fJCnf.Filename := fFileCfg;
    try
      with fInfo do
      begin
        //sHost := fJCnf.GetValue('/dbCnt/server'  , 'localhost');
        sDB   := fJCnf.GetValue('/dbCnt/db'      , 'employee');
        //iPort := fJCnf.GetValue('/dbCnt/port'    , 3050);
        sUser := fJCnf.GetValue('/dbCnt/user'    , 'root');
        sPass := fJCnf.GetValue('/dbCnt/passwd'  , 'thalla');
        sLib  := fJCnf.GetValue('/dbCnt/library' , 'c:\lib.dll');
      end;
    except
      raise;
    end;
  finally
    FreeAndNil(fJCnf);
  end;

  Result := True;
end;

function TForm1.fStartServer: Boolean;
var
  CStr: String;
begin
  //
  //  Try to publish SQLDatabase with mORMotServer
  //  using Http .
  //  Using Http/Json as transport lyer for requests and responses.
  //
  // Free Http Server.
  if Hts <> nil then FreeAndNil(Hts);
  // Free SQL Sever
  if fp <> nil then FreeAndNil(fp) ;
  // ---------------------------------------------------------------------------------------------
  // Create SQL server connection
  // ---------------------------------------------------------------------------------------------
  //fp := TSQLDBZEOSConnectionProperties.Create(
  //            TSQLDBZEOSConnectionProperties.URI(dFirebird,'127.0.0.1:3050','fbclient.dll',false),
  //            'EMPS', 'sysdba', 'masterkey' );
  // This is a Firebird connection .
  //CStr := fInfo.sHost + ':' + IntToString(fInfo.iPort);
  //fp := TSQLDBZEOSConnectionProperties.Create(
  //            TSQLDBZEOSConnectionProperties.URI(dFirebird, CStr, fInfo.sLib, false),
  //            fInfo.sDB,
  //            fInfo.sUser,
  //            fInfo.sPass );

  // This is to do for Oracle.
  fp := TSQLDBZEOSConnectionProperties.Create(
                TSQLDBZEOSConnectionProperties.URI(dOracle,'',fInfo.sLib),
                fInfo.sDB,
                fInfo.sUser,
                fInfo.sPass);

  // ---------------------------------------------------------------------------------------------
  // Create Http Server and publish the SQL server to the Web
  // ---------------------------------------------------------------------------------------------
  if fp <> nil then
    Hts := TSQLDBServerHttpApi.Create(fp,'fp','8111','user','pass');
  // ---------------------------------------------------------------------------------------------
  //

  //
  // logging
  //with TSynLog.Family do begin
  //  Level := LOG_VERBOSE;
  //  //Level := [sllException,sllExceptionOS];
  //  //HighResolutionTimestamp := true;
  //  //AutoFlushTimeOut := 5;
  //  //OnArchive := EventArchiveSynLZ;
  //  //OnArchive := EventArchiveZip;
  //  //ArchiveAfterDays := 1; // archive after one day
  //end;
  //with TSynLogDB.Family do
  //begin
  //Level := LOG_VERBOSE;
  //PerThreadLog := ptOneFilePerThread;
  //DestinationPath := 'C:\Logs';
  //end;
  with TSQLLog.Family do begin
    Level := LOG_VERBOSE;
    EchoToConsole := LOG_VERBOSE; // log all events to the console
  end;

end;

function TForm1.fStopServer: Boolean;
begin
  if fp <> nil then FreeAndNil(fp);
  if Hts<> nil then FreeAndNil(hts);
end;

end.

#34 Re: mORMot 1 » Error compilation on Delphi XE2 » 2019-09-30 13:34:43

ab wrote:

I don't have XE2 installed... I tested on 2007 and XE4... sorry...

Please check https://synopse.info/fossil/info/f8e8212372


thinks

#35 mORMot 1 » Error compilation on Delphi XE2 » 2019-09-30 08:56:33

Bsaidus
Replies: 2

Hello.
while trying compile a project Exemple on Delphi XE2  I have the following error on declaration of PMethod on mORMot.pas

  {$ifndef FPC_OR_UNICODE} // not defined on older Delphi versions
  PMethod = ^TMethod;
  {$endif}


[DCC Error] mORMot.pas(2854): E2003 Undeclared identifier: 'PMethod'
[DCC Error] mORMot.pas(2856): E2005 'PMethod' is not a type identifier
[DCC Error] mORMot.pas(21101): E2005 'PMethod' is not a type identifier
[DCC Error] mORMot.pas(21106): E2066 Missing operator or semicolon

It do not reconize the PMethod.

#36 Re: mORMot 1 » FPC/LAZARUS/Mormot Newbie needs help on chat demo [SOLVED!!!] » 2019-08-27 07:37:10

JuanK wrote:

Solved!!!

I download last version of NewPascal.zip and it compiled and worked!!!

Thanks for your time reading this...



No, NewPascal is not more maintained, I recommand you to use fpcupdeluxe ( https://github.com/LongDirtyAnimAlf/fpc … e/releases ) to install fpc 3.2 fixes with lazarus 2.0.4 fixes or read the following
https://synopse.info/forum/viewtopic.php?id=4895

#38 mORMot 1 » Adding Tag property to TQuery object. » 2019-08-25 17:29:40

Bsaidus
Replies: 2

Hello Arnaud,
Could you add a Tag property (Int64) to TQuery Component, I need it and I use it extensivelly to save params.

Thank you.

#39 Re: Free Pascal Compiler » fpc/lazarus - mormot » 2019-05-30 12:37:55

Hello All,
I think sometimes, or every time you change your production environment (FPC/Lazarus), you should if you do not mind tell us the SVN branch versions.
This will permit to us to follow you and well use the wonderful mORMot framework.

Thank you.

#40 Re: mORMot 1 » Executing a shell command with mORMot » 2019-05-12 08:05:15

OOOOOOOOhhhhh SUPpppppppperrrrr !!
I love mORMot really.
Thnks you .

#41 mORMot 1 » Executing a shell command with mORMot » 2019-05-10 14:36:35

Bsaidus
Replies: 6

Hello,
Suppose that I have a sqlite database on my linux server and deployed a mORMot based server (Exposing the sqlite database to the web using mORMot REST).
Is it possible that after sending a request to server, It process the request (manipulate data on the database ) and execute command or shell script after ??

Thanks.

#42 Re: mORMot 1 » Web access to mORMot Database published server. » 2019-04-17 07:29:26

ab wrote:

As documented, the remote connection is in proprietary optimized binary format, so will work only with the framework client code, only available with Delphi and FPC/Lazarus.

Merciiiiii !!

#43 mORMot 1 » Web access to mORMot Database published server. » 2019-04-15 13:42:30

Bsaidus
Replies: 2

Hello AB,
  I have this simple code.

var
   fp : TSQLDBOracleConnectionProperties;
   hts: TSQLDBServerHttpApi;
begin

  fp := TSQLDBOracleConnectionProperties.Create
          ('//OR1-srv1:1521/MMXJ1',
            '',
            'user1',
            'pass1'
          );
  Hts := TSQLDBServerHttpApi.Create(fp,'fp','80','user','pass');

end;

How can I access or Can I access this published database with others web technologie other then Delphi or lazarus?
if Not then, what to you recommand me to use.

PS: My database is huge, and I cant rewrite all using ORM's

Thanks you.

#45 mORMot 1 » mORMot Unidac direct acces to Oracle. » 2019-04-02 12:08:32

Bsaidus
Replies: 2

Hello !

Is there anyway to use SynDBunidac to direct connect to Oracle Server without using oci.dll??

Thanks you.

#46 Re: Free Pascal Compiler » fpc/lazarus - mormot » 2019-02-20 20:44:34

ab wrote:

For our production work, we picked up "preferred" revisions for FPC / Lazarus trunk, which are currently:
- FPC trunk SVN 40491
- Lazarus trunk SVN 59757

We enter those SVN revisions when building our own FPC + Lazarus, using https://github.com/newpascal/fpcupdelux … ses/latest
Just click on the "Setup +" button and enter above numbers before building.



Merci !!

#47 Free Pascal Compiler » fpc/lazarus - mormot » 2019-02-18 19:28:54

Bsaidus
Replies: 12

Hello.
Witch version of fpc/lazarus do you advice me to use with mORMot since newpascal is not maintained anymore??
Thanks.

#48 Re: mORMot 1 » CRUD with mORMot » 2019-01-07 20:14:05

Merci Arnaud.
Mais, j'ai pas trouver un exemple concret

   1. D'un serveur REST Http qui gère une base de données.
   2. Et d'un Client bureau avec un DBGrid.
J'ai beau chercher mais j'ai pas trouvé, a moin que j'ai raté quelque chose.

Merci.

#49 mORMot 1 » CRUD with mORMot » 2018-12-26 20:41:18

Bsaidus
Replies: 2

I wonder if you can do a tutorial ((video)) for using mORMot in REST/Json scenario, but using a desktop application ( for exemple: form+dbgrid+datasource (CRUD)).

    1. server application connected to Firebird or MariaDB using Zeos.
    2. Desktop application (Form+dbgrid+datasource) managing one table.
But the communication is in REST/JSON ( CRUD technique ).

Or a simple exemple can help.


Thanks you.

#50 Re: mORMot 1 » My mORMot Videos » 2018-12-16 20:04:14

Thanks for the video.
I wonder if you can do a tutorial video for using mORMot in REST/Json scenario, but using a desktop application ( for exemple: form+dbgrid+datasource (CRUD)).

    1. server application connected to Firebird or MariaDB using Zeos.
    2. Desktop application (Form+dbgrid+datasource) managing one table.

Thanks you.

Board footer

Powered by FluxBB