Modify the original DV SQL

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Modify the original DV SQL

Post by cesteban » 2019-10-07 16:29

Hello,

How can I modify the SQL statement of a detail view to add an additional search where condition?

I don't want to use filters because the user can remove them and I need him not to have access to other records

The option to access their own records does not help me because the user is not always who creates their records

Thank you

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Modify the original DV SQL

Post by jsetzer » 2019-10-07 17:22

Do you really mean "detail view"? Or do you want to restrict the visible records in table-view?

Maybe you can do additional auth checks in _dv function of hooks/TABLENAME.php and perhaps redirect the user conditionally.
Best
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-07 17:54

Sorry, the Table View

I need to modify the Query to add a Where condition!!!

Regards

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pbottcher » 2019-10-07 18:41

Hi,

you can use the TABLENAME_init function.

add:

Code: Select all

$options->QueryWhere="where YOUR CLAUSE";
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-07 20:02

Thanks

In which file I include the option?

Regards

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pbottcher » 2019-10-07 20:08

in the hooks/TABLENAME.php file

where TABLENAME is the table where you want to apply the where clause to the sql query.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-07 20:51

Thaks

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-07 22:10

Sorry, It's not working

This is my test code:

function Pagos_init(&$options, $memberInfo, &$args){
$options->QueryWhere="WHERE Casa = 30";
return TRUE;
}

and I get nothing, if I run the statment:

Select * from Pagos WHERE Casa = 30

I got records


Regards

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pbottcher » 2019-10-08 06:38

Hi,

maybe you need to check if there is already a where statement for that table. In that case you would need

$options->QueryWhere=" AND Casa = 30";
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-08 17:57

Hi,

I already tried it but it doesn't work

Is there any way to see the SQL statement which is sent, in order to see how complete the SQL statement?

Thank you

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pbottcher » 2019-10-08 20:42

try to add this in the init part. you shall see the $option parameters

ob_start();
$xc=get_object_vars($options);
ksort($xc);
print_r($xc);
$c=ob_get_clean();
echo "<pre>".htmlspecialchars($c)."</pre>";
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-10 15:18

Thanks

The information I obtain before including the statement is:

[QueryWhere] =>

And after including the statement is:

[QueryWhere] => Casa = 30

But I still get the error that no records are found

The information does not show me the SQL statement to know how the request for records is being made

Best regards

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pbottcher » 2019-10-10 15:23

Hi ,

you need to add the "WHERE " string as well.

So after changing the QueryWhere should show:

[QueryWhere] => WHERE Casa = 30
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-10 15:53

Now I get this, but still without records

[QueryWhere] => WHERE Casa = 30

Regards

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pbottcher » 2019-10-10 16:54

hmmm, that is strange.

is it possible that you post all the Query fields?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Modify the original DV SQL

Post by cesteban » 2019-10-10 18:05

Thanks, I could fix it with this:

$options->QueryWhere=" WHERE `Pagos`.`Casa` = 30";

It's working

Best regards

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Modify the original DV SQL

Post by peebee » 2019-12-09 04:36

Hi Cesteban,

Did you manage to get your WHERE clause in the [QueryWhere] => hook to work with standard Appgini filters?

I am trying to achieve a similar thing as you but I can manage to get filters to work when the WHERE clause is applied?

See here: viewtopic.php?f=2&p=11686#p11654

Any advice/help welcome. Thanks.

Post Reply