Restricting a query

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Restricting a query

jarosz
I have a table which contains records for 10 different clients.
I'd like to give a client the ability to search the table for only his records and not be able to see any of the other clients' records.

Is it possible to do this using the standard 4D Query editor by always applying an additional search criteria eg clientID=xxx?

Or do I need to build my own custom query editor?
I'm using 4D 15.4.

I'd be interested to hear how others have approached this...

Many thanks

Michael Jarosz
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restricting a query

4D Tech mailing list
Not sure if views work with normal query but I would start there.

Regards
Chuck

Sent from my iPhone

> On Jul 31, 2017, at 2:34 PM, jarosz via 4D_Tech <[hidden email]> wrote:
>
> I have a table which contains records for 10 different clients.
> I'd like to give a client the ability to search the table for only his
> records and not be able to see any of the other clients' records.
>
> Is it possible to do this using the standard 4D Query editor by always
> applying an additional search criteria eg clientID=xxx?
>
> Or do I need to build my own custom query editor?
> I'm using 4D 15.4.
>
> I'd be interested to hear how others have approached this...
>
> Many thanks
>
> Michael Jarosz
>
>
>
>
> --
> View this message in context: http://4d.1045681.n5.nabble.com/Restricting-a-query-tp5753437.html
> Sent from the 4D Tech mailing list archive at Nabble.com.
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restricting a query

4D Tech mailing list
In reply to this post by jarosz
Jarosz,
For that you'll want to build your own query editor. To achieve that sort
of separation of data you'll need to be careful that all queries and
selections created by relations are segregated by client.

On Mon, Jul 31, 2017 at 11:34 AM, jarosz via 4D_Tech <[hidden email]>
wrote:

> I have a table which contains records for 10 different clients.
> I'd like to give a client the ability to search the table for only his
> records and not be able to see any of the other clients' records.
>
> Is it possible to do this using the standard 4D Query editor by always
> applying an additional search criteria eg clientID=xxx?
>
> Or do I need to build my own custom query editor?
> I'm using 4D 15.4.
>
> I'd be interested to hear how others have approached this...
>
> Many thanks
>
> Michael Jarosz
>
>
>
>
> --
> View this message in context: http://4d.1045681.n5.nabble.
> com/Restricting-a-query-tp5753437.html
> Sent from the 4D Tech mailing list archive at Nabble.com.
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************




--
Kirk Brooks
San Francisco, CA
=======================

*The only thing necessary for the triumph of evil is for good men to do
nothing.*

*- Edmund Burke*
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restricting a query

4D Tech mailing list
In reply to this post by jarosz
I'll take it as read that you have a solid reason for commingling the data
from your various clients.

Something I've seen and like too is along the lines of
Filter_AfterSearch(->[Table])

So, after *any* search, you run a filter against the table. This can be
used for all sorts of things:

-- Exclude records marked 'deleted'

-- Filter records based on the user's role. A Manager might see more
records than a Floor_Worker (or the other way around.)

-- Filter by some kind of location setting.

-- What you were talking about.

You can implement the Filter_AfterSearch method however you like, I've
regularly seen big case statements with hooks for tables with special
filter rules. There are more involved ways, but a "case of" is an easy way
to start and experiment. It's also easy in Filter_AfterSearch to check that
the table has a selection before you worry about filtering it.

If you use the standard query editor, then you need code to bring up the
editor which is immediately followed by a call to Filter_AfterSearch. That
should do it. Just remember to do the same with your custom queries too so
that you don't leak data from other customers. The good part is that you
still just need the one line of code:

Filter_AfterSearch(->[Table])
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restricting a query

4D Tech mailing list
In reply to this post by jarosz
You can also filter BEFORE query.
for simplicity:
Query([table];[table]client_ID = $Current_Client_ID)
Query selection([table])

This will open 4D's query editor, and apply the query the user does to
the selection you created before hand.

On Mon, 31 Jul 2017 11:34:12 -0700 (MST), jarosz via 4D_Tech wrote:

> I have a table which contains records for 10 different clients.
> I'd like to give a client the ability to search the table for only his
> records and not be able to see any of the other clients' records.
>
> Is it possible to do this using the standard 4D Query editor by always
> applying an additional search criteria eg clientID=xxx?
>
> Or do I need to build my own custom query editor?
> I'm using 4D 15.4.
>
> I'd be interested to hear how others have approached this...
>
> Many thanks
>
> Michael Jarosz
>
>
>
>
> --
> View this message in context:
> http://4d.1045681.n5.nabble.com/Restricting-a-query-tp5753437.html
> Sent from the 4D Tech mailing list archive at Nabble.com.
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restricting a query

4D Tech mailing list
In reply to this post by jarosz
RE> I have a table which contains records for 10 different clients.
I'd like to give a client the ability to search the table for only his
records and not be able to see any of the other clients' records.

Is it possible to do this using the standard 4D Query editor by always
applying an additional search criteria eg clientID=xxx?

Or do I need to build my own custom query editor?
I'm using 4D 15.4.


Michael,

I *wish* you could use this with Views, but today Views only support SQL.
Please vote for my feature request (when you open the request, you'll see
a row of stars - click on the starts to give the request a 1-star, 2-star,
or preferably 4-star rating).  This feature requests asks that since views
are virtual tables, to allow all 4D query commands to point to the view as
if it were a table:

http://forums.4d.com/Post/EN/13716634/1/13716635#13716635


In the meantime, you can certainly add a QUERY SELECTION line after
calling the 4D query editor.

Best regards,


Bob Miller
Chomerics, a division of Parker Hannifin Corporation



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restricting a query

jarosz
In reply to this post by 4D Tech mailing list
Many thanks Chip

This is a really simple solution and works like a dream!

Regards

Michael Jarosz
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Restricting a query

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Jarosz

Actually you don’t need to build your own query editor. All you actually need to do is make sure you wrap any calls to the query editor(and to any query in general) so you can apply to any query a client filter



> On 31 Jul 2017, at 19:38, Kirk Brooks via 4D_Tech <[hidden email]> wrote:
>
> Jarosz,
> For that you'll want to build your own query editor. To achieve that sort
> of separation of data you'll need to be careful that all queries and
> selections created by relations are segregated by client.
>
> On Mon, Jul 31, 2017 at 11:34 AM, jarosz via 4D_Tech <[hidden email]>
> wrote:
>
>> I have a table which contains records for 10 different clients.
>> I'd like to give a client the ability to search the table for only his
>> records and not be able to see any of the other clients' records.
>>
>> Is it possible to do this using the standard 4D Query editor by always
>> applying an additional search criteria eg clientID=xxx?
>>
>> Or do I need to build my own custom query editor?
>> I'm using 4D 15.4.
>>
>> I'd be interested to hear how others have approached this...
>>
>> Many thanks
>>
>> Michael Jarosz
>>
>>
>>
>>
>> --
>> View this message in context: http://4d.1045681.n5.nabble.
>> com/Restricting-a-query-tp5753437.html
>> Sent from the 4D Tech mailing list archive at Nabble.com.
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> FAQ:  http://lists.4d.com/faqnug.html
>> Archive:  http://lists.4d.com/archives.html
>> Options: http://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:[hidden email]
>> **********************************************************************
>
>
>
>
> --
> Kirk Brooks
> San Francisco, CA
> =======================
>
> *The only thing necessary for the triumph of evil is for good men to do
> nothing.*
>
> *- Edmund Burke*
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Loading...