Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion

SqlBuilder Problem


function MakeFileAfterNewComment($Context) {
$Comment = $Context->DelegateParameters['Comment'];
if($Comment->WhisperUserID == false) {

// Init SqlBuilder
$s = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder');

// Get the Discussion Name
$DiscussionID = $Comment->DiscussionID;
$s->SetMainTable('Discussion', 'd');
$s->AddSelect('Name', 'd');
$s->AddWhere('d', 'DiscussionID', '', $DiscussionID, '=');
$DiscussionName = $this->Context->Database->Execute($s, $Comment, '', 'An error occurred while finding a Discussion name.');
}
}

$Context->AddToDelegate('CommentManager','PreSaveNewComment','MakeFileAfterNewComment');


From that i get this...

Fatal error: Call to a member function SetMainTable() on a non-object in C:\Server\htdocs\Vanilla\extensions\Flash Updator\default.php on line 21

Any help? I'm trying to learn how to use the sqlbuilder...

Comments

  • I think all the SQLbuilder code is OK, but I don't believe the context object is passed to the function directly... thus the ObjectFactory doesn't build it properly.

    Try this:function MakeFileAfterNewComment($CommentManager) {
    $Comment = $CommentManager->Context->DelegateParameters['Comment'];
    if($Comment->WhisperUserID == false) {

    // Init SqlBuilder
    $s = $CommentManager->Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder');

    // ...

    $DiscussionName = $CommentManager->Context->Database->Execute($s, $Comment, '', 'An error occurred while finding a Discussion name.');
  • I can't even connect to the object factory through either my code or yours
  • MarkMark vanilla
    Is your code included on a page where the CommentManager is created (ie. comments.php)?

    Also, WallPhone missed one context reference. It should always be accessed through the object that was passed into the function:

    function MakeFileAfterNewComment(&$CommentManager) {
    $Comment = $CommentManager->Context->DelegateParameters['Comment'];
    if ($Comment->WhisperUserID == false) {

    // Init SqlBuilder
    $s = $CommentManager->Context->ObjectFactory->NewContextObject($CommentManager->Context, 'SqlBuilder');

    // Get the Discussion Name
    $DiscussionID = $Comment->DiscussionID;
    $s->SetMainTable('Discussion', 'd');
    $s->AddSelect('Name', 'd');
    $s->AddWhere('d', 'DiscussionID', '', $DiscussionID, '=');
    $DiscussionName = $CommentManager->Context->Database->Execute($s, $Comment, '', 'An error occurred while finding a Discussion name.');
    }
    }

    $Context->AddToDelegate('CommentManager','PreSaveNewComment','MakeFileAfterNewComment');
  • Notice: Undefined property: Context::$DelegateParameters in ...\Vanilla\extensions\Flash Updator\default.php on line 12

    Notice: Trying to get property of non-object in ...\Vanilla\extensions\Flash Updator\default.php on line 13

    Notice: Trying to get property of non-object in ...\Vanilla\extensions\Flash Updator\default.php on line 19

    Catchable fatal error: Object of class SqlBuilder could not be converted to string in ...\Vanilla\library\Framework\Framework.Class.MySQL.php on line 37


    Well, that's what i get.... is something wrong here?
  • MarkMark vanilla
    Another typo... Let's try this again:

    function MakeFileAfterNewComment(&$CommentManager) {
    $Comment = $CommentManager->DelegateParameters['Comment'];
    if ($Comment->WhisperUserID == false) {

    // Init SqlBuilder
    $s = $CommentManager->Context->ObjectFactory->NewContextObject($CommentManager->Context, 'SqlBuilder');

    // Get the Discussion Name
    $DiscussionID = $Comment->DiscussionID;
    $s->SetMainTable('Discussion', 'd');
    $s->AddSelect('Name', 'd');
    $s->AddWhere('d', 'DiscussionID', '', $DiscussionID, '=');
    $ResultSet = $CommentManager->Context->Database->Select($s, $Comment, '', 'An error occurred while finding a Discussion name.');
    }
    }

    $Context->AddToDelegate('CommentManager','PreSaveNewComment','MakeFileAfterNewComment');
  • Thanks Mark, we hit the spot on this one :D

    This'll help me when i confront the RSS addon...
This discussion has been closed.