#1 2013-05-31 17:06:13

eraldo
Member
From: Brasil
Registered: 2010-07-22
Posts: 69
Website

Return a selection of a view

dear colleagues,

How the gentlemen are doing to return a selection of a view?

Offline

#2 2013-06-01 07:15:56

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: Return a selection of a view

hi,
i use a view base class with more overloaded methods that can return an array of selected ids/an array with all field values of selected rows/tobjectlist with all object selected etc etc...

Offline

#3 2013-06-01 15:05:34

eraldo
Member
From: Brasil
Registered: 2010-07-22
Posts: 69
Website

Re: Return a selection of a view

Dear lele9,

You could write a few lines of code exemplifying his method?

Offline

#4 2013-06-01 20:15:27

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

Re: Return a selection of a view

Please download the following pdf:
http://synopse.info/files/pdf/Synopse%2 … 201.18.pdf

Take a look at the paragraphs about ORM queries.

You have several code sample in there, using either CreateAndFillPrepare/FillOne either TSQLTableJSON.

RTFM!
smile

Offline

#5 2013-06-02 00:59:26

eraldo
Member
From: Brasil
Registered: 2010-07-22
Posts: 69
Website

Re: Return a selection of a view

I understand the use of CreateAndFillPrepare but when I want to do a select on a view instead of a table?

Offline

#6 2013-06-03 08:12:32

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: Return a selection of a view

sorry eraldo,
i don't understand...you need a method to do a select of view (where "view" is a database view) or you need a method to get an user's selection of record from a view (where "view" is V part in MVC)?

Offline

#7 2013-06-03 08:47:24

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

Re: Return a selection of a view

I suspect you are speaking about a DB view.

The ORM is not able to create a view, by design.
So it was not meant to work with it.
Depending on the backend database engine, it may work - but for instance for SQLIte3 it won't work, since it will try to create a missing table with the view name.

But both the SQLIte3 core and the underlying SynDB*.pas are able to access views.
So you can easily create an interface-based service, run a query on a view, then return it directly as RawJSON to the client.
Then, on the client, use a TSQLTableJSON to work on the context. You can use a dedicated TSQLRecord class mapping the returned view column layout for direct ORM access, with FillOne, as usual.

See sample in directory "SQLite3/Samples/16 - Execute SQL via services" for how to work with SQL queries via services.

Offline

#8 2013-06-03 11:42:04

eraldo
Member
From: Brasil
Registered: 2010-07-22
Posts: 69
Website

Re: Return a selection of a view

Thank lele9,

Really i'm speaking about the DB view.

The ab is correct. I'm currently using interface-based service, to return to the client a select on a view.

I imagined that someone could be doing this in another way.

Offline

Board footer

Powered by FluxBB