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: 37
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: 257
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

User avatar
cesteban
Veteran Member
Posts: 37
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 608
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pböttcher » 2019-10-07 18:41

Hi,

you can use the TABLENAME_init function.

add:

Code: Select all

$options->QueryWhere="where YOUR CLAUSE";

User avatar
cesteban
Veteran Member
Posts: 37
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 608
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pböttcher » 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.

User avatar
cesteban
Veteran Member
Posts: 37
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: 37
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 608
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pböttcher » 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";

User avatar
cesteban
Veteran Member
Posts: 37
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 608
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pböttcher » 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>";

User avatar
cesteban
Veteran Member
Posts: 37
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 608
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pböttcher » 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

User avatar
cesteban
Veteran Member
Posts: 37
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 608
Joined: 2018-04-01 10:12

Re: Modify the original DV SQL

Post by pböttcher » 2019-10-10 16:54

hmmm, that is strange.

is it possible that you post all the Query fields?

User avatar
cesteban
Veteran Member
Posts: 37
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

Post Reply