$options->QueryFrom & INNER JOIN

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
jmcgov
Veteran Member
Posts: 79
Joined: 2018-12-19 01:31
Location: Northern Ireland

$options->QueryFrom & INNER JOIN

Post by jmcgov » 2023-01-30 15:22

Hi A'g'ers
Im stuck on something, which I think is possible - Im trying to inner join on a $options->QueryFrom edit. I have this

Code: Select all

$options->QueryFrom = 'FROM `u05_tank` INNER JOIN `membership_users` ON `u05_tank`.`username` = `membership_users`.`memberID`';
and get
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `u05_tank` INNER JOIN `membership_users` as `u05_tank1` ON `u05_tank`.`user' at line 1
Any ideas, please

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

Re: $options->QueryFrom & INNER JOIN

Post by jsetzer » 2023-01-30 15:38

I'm wondering why the error message says
INNER JOIN `membership_users` as `u05_tank1`
but the SQL code you have posted does not contain any "as `...`"

You should var_dump() and check the other ->Query*-properties of $options, maybe there are default settings for joins somewhere else.
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
jmcgov
Veteran Member
Posts: 79
Joined: 2018-12-19 01:31
Location: Northern Ireland

Re: $options->QueryFrom & INNER JOIN

Post by jmcgov » 2023-01-30 17:06

Thanks for your input Js
Oops, I think I had 2 windows open and was fiddling around with the query - and mismatched my cut n paste.
Taking it from the top, and the anwer to your query

Code: Select all

$options->QueryFrom = 'FROM `u05_tank` INNER JOIN `membership_users` ON `u05_tank`.`username` = `membership_users`.`memberID`';
$options->QueryWhere = 'WHERE `u05_tank`.`club` = "'.$clubID.'" AND `u05_tank`.`active` = 1 AND `membership_users`.`isBanned` = 1';
Error message os
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `u05_tank` INNER JOIN `membership_users` ON `u05_tank`.`username` = `member' at line 1

Im not sure if this is conflicting - from the tablename_view (not in hooks, which I dont want to edit for maintenance overload purposes)

Code: Select all

$x->QueryFrom = "`u05_tank` LEFT JOIN `c09_club` as c09_club1 ON `c09_club1`.`clubID`=`u05_tank`.`club` LEFT JOIN `u04_address` as u04_address1 ON `u04_address1`.`addressID`=`u05_tank`.`address` LEFT JOIN `u02_person` as u02_person1 ON `u02_person1`.`personID`=`u05_tank`.`payContact` LEFT JOIN `u02_person` as u02_person2 ON `u02_person2`.`personID`=`u05_tank`.`accessContact` ";
The var dump is showing

Code: Select all

 [QueryFrom] => FROM `u05_tank` INNER JOIN `membership_users` ON `u05_tank`.`username` = `membership_users`.`memberID`
 [QueryOrder] => 
 [QueryWhere] => WHERE `u05_tank`.`club` = "BT33-0" AND `u05_tank`.`active` = 1 AND `membership_users`.`isBanned` = 1

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

Re: $options->QueryFrom & INNER JOIN

Post by pbottcher » 2023-01-30 19:01

Hi,

try

Code: Select all

$options->QueryFrom = ' `u05_tank` INNER JOIN `membership_users` ON `u05_tank`.`username` = `membership_users`.`memberID`';
I think there is no need for the first FROM. But looking at your original query you may need the other fields (joins) as well.
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
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: $options->QueryFrom & INNER JOIN

Post by jsetzer » 2023-01-30 19:29

Still the error message shows a different JOIN than your $options->QueryFrom:
INNER JOIN `membership_users` ON `u05_tank`.`username` = `membership_users`.`memberID`';
vs
INNER JOIN `membership_users` ON `u05_tank`.`username` = `member'
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
jmcgov
Veteran Member
Posts: 79
Joined: 2018-12-19 01:31
Location: Northern Ireland

Re: $options->QueryFrom & INNER JOIN

Post by jmcgov » 2023-01-30 21:35

Ah,
The error is produced by app gini, it renders a portion of the problematic query only, ie "near" to use the same terminology

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

Re: $options->QueryFrom & INNER JOIN

Post by jsetzer » 2023-01-31 07:24

Any ideas, please
Sometimes AppGini has to append numbers to table-aliases to avoid duplicates in SQL commands, especially when joining tables, especially when joining the same table multiple times. It could be that, for example, AppGini does not address `TABLENAME` but `TABLENAME1` instead.

If, for example, AppGini has already joined membership_userrecords, membership_users,
membership_groups and/or *_permissions for applying group- and user-specific constraints, there could be a name- and/or alias-collision with your specific, custom join.

So, for me it is always helpful for debugging to see the actual final SQL statement.

As we have seen, MySQL only names a part of the SQL command on errors ("... NEAR ...") which sometimes helps, sometimes not at all.

When you have found the place where AppGini executes the final SQL statement, it could help to var_dump(...); exit(); and check the complete final SQL which raises the error.


Tip
In latest version we also have the Query Log feature in Admin Area. The invalid SQL statement should be listed there completely (not partly) which could help finding naming collisions


This is just an idea.
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
jmcgov
Veteran Member
Posts: 79
Joined: 2018-12-19 01:31
Location: Northern Ireland

Re: $options->QueryFrom & INNER JOIN

Post by jmcgov » 2023-02-01 23:01

Right, based on that, I'll do two things. I’ll do an as tablename99 version and get the full error. I’m lucky to have convinced the client to put this to post launch, taking the pressure down a step for me.

User avatar
jmcgov
Veteran Member
Posts: 79
Joined: 2018-12-19 01:31
Location: Northern Ireland

Re: $options->QueryFrom & INNER JOIN

Post by jmcgov » 2023-02-01 23:06

pböttcher wrote:
2023-01-30 19:01
Hi,

try

Code: Select all

$options->QueryFrom = ' `u05_tank` INNER JOIN `membership_users` ON `u05_tank`.`username` = `membership_users`.`memberID`';
I think there is no need for the first FROM. But looking at your original query you may need the other fields (joins) as well.
Thanks, unfortunately no joy with that either.

Post Reply