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.
Options

[Solved] Faulty SQL generated by SQLBuilder?

edited October 2007 in Vanilla 1.0 Help
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 ?

Comments

  • Options
    edited October 2007
    Try:
    $sql->AddWhere('u','FirstCommentID','v','CommentID','=', 'and', '', '0')
    The last argument is to quote the parameter 2 (set to 1 by default).
  • Options
    Big thanks for the fast reply Dinoboff. Guess I should read the default values of the functions better next time =) Did put a few hours into it before putting it on the board tho.
This discussion has been closed.