Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
[Solved] Faulty SQL generated by SQLBuilder?
When preforming the following lines of code :
---start---
$sql = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
$sql->Clear();
$sql->SetMainTable('Comment','v');
$sql->AddSelect(array('CommentID','DateCreated','DiscussionID'),'v');
$sql->AddJoin('Discussion', 'u', 'FirstCommentID','v','CommentID','left join');
$sql->AddSelect(array('Name'),'u');
$sql->AddWhere('u','CategoryID','',$this->Context->Configuration['BLOG_CATEGORY_ID'],'!=');
$sql->AddWhere('u','CategoryID','',$this->Context->Configuration['ARTICLEADMIN_CATEGORY'],'!=');
$sql->AddWhere('u','FirstCommentID','v','CommentID','=');
$sql->AddLimit(0, 5);
---end---
And then doing a "echo $sql->GetSelect();" it gives me that the SQL generated is :
select v.CommentID as CommentID, v.DateCreated as DateCreated, v.DiscussionID as DiscussionID, u.Name as Name from LUM_Comment v left join LUM_Discussion u on v.CommentID = u.FirstCommentID where u.CategoryID != '4' and u.CategoryID != '4' and u.FirstCommentID = 'v.CommentID' limit 0, 5
The problem here being :
u.FirstCommentID = 'v.CommentID'
since its a comparition between two tables and not a value it should be :
u.FirstCommentID = v.CommentID
Any feedback on what causes this or any halfdecent workaround rather then doing a regular mysql_query ?
0
This discussion has been closed.
Comments
$sql->AddWhere('u','FirstCommentID','v','CommentID','=', 'and', '', '0')
The last argument is to quote the parameter 2 (set to 1 by default).