#1 2016-03-25 06:14:23

acid
Member
Registered: 2016-01-11
Posts: 3

How to executed custom SQL statements? (In ORM)

Hello,

Create a web appliction with mORMot Framework. (MVC + ORM)
I want to executed custom SQL ,get some record from external DB . (Select)

In TMVCApplication,

var
  res:ISQLDBRows;
begin
  res:=RestModel.Execute(...) ?
  ...
end;

What should I do?

Offline

#2 2016-03-25 08:27:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How to executed custom SQL statements? (In ORM)

Which statement do you expect to execute?
Are you sure the ORM is not able to create this query?
See http://synopse.info/files/html/Synopse% … #TITLE_115

Offline

#3 2016-03-25 08:53:18

acid
Member
Registered: 2016-01-11
Posts: 3

Re: How to executed custom SQL statements? (In ORM)

i.e.

select * from table1 order by fld1 asc,fld2 desc,fld3

Multiple fields, sort

I found ,mormot ORM only one sort field is supported . (in mssql 2008)

Offline

#4 2016-03-25 09:27:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How to executed custom SQL statements? (In ORM)

You then have to access directly the TSQLDBConnectionProperties of the external database definition.

Offline

#5 2016-03-26 02:52:52

acid
Member
Registered: 2016-01-11
Posts: 3

Re: How to executed custom SQL statements? (In ORM)

In TMVCApplication or it's derivative class ,
Is it possible to get instance of TSQLDBConnectionProperties (or TSQLDBConnection)?

i.e.
type
TMvcApp = class(TMVCApplication, IMyIntf)
   public
    procedure MyMethod ();
end;

-------impl--------
procedure TMvcApp.MyMethod ();
var
  props:TSQLDBConnectionProperties ;
begin

  //get TSQLDBConnectionProperties
  props:=Self.RestModel.GetDBConnectionProperties;

  ..... do something......

end;

Offline

#6 2016-03-26 16:36:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How to executed custom SQL statements? (In ORM)

You just need to store it in TMvcApp when you initialize the external database.

Offline

Board footer

Powered by FluxBB