0

I'm fixing up a module and I have the following db_select() code, but I'm getting the following error:

Fatal error: Call to a member function execute() on a non-object in /var/www/xxx/sites/all/modules/xxx/xxx.module on line 414

I think it has something to do with the addExpression line, but I'm unsure of what this line does or what is the equivalent of addExpression in sql? What is MAX(poss), poss -- mean?

$query_poss = db_select('saved_lists', 'saved_lists')
  ->condition('saved_lists.lid', $lid)
  ->addExpression('MAX(poss)', 'poss')
  ->execute()
  ->fetchField();

1 Answer 1

3

The addExpression method returns the unique alias that was assigned for this expression, and thus cannot be chained.

Please look at this example and the document.

$q = db_select('parser_subtasks', 'st')
 ->condition('QueueID', $task['ID'])
 ->condition('IsDone', 0);
$q->addExpression('MIN(Delay)');
$min_time = $q->execute()->fetchField();
3
  • what is the equivalent of that in sql? im not sure what "unique alias" and expression mean when u mention it. MIN and MAX is meaning the highest or lowest of the returned results? sorry but its a bit confusing for me. Nov 5, 2015 at 5:02
  • your right i had to make it into a separate line. why is that? i understand max() now. Nov 5, 2015 at 5:55
  • @duckx The addExpression returns the alias you specified or a string like 'expression_2'. So that is not an object and don't have execute method. The condition method can be chained because it returns the query object itself.
    – leetom
    Nov 5, 2015 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.