I am looking for a way to use sql query in condition of rule - if sql query returns something - proceed with rule, if it returns nothing - skip rule. Can anyone suggest way to go in this case? Thanks.

Comments

klausi’s picture

Component: Rules Core » Rules Engine

Add a condition to your rule and select "execute custom PHP code".
Insert something like

  $result = db_query("SELECT * FROM {your_wanted_table}");
  if (db_fetch_array($result)) {
    return TRUE;
  }
  else {
    return FALSE;
  }
henrijs.seso’s picture

Component: Rules Engine » Provided module integration
Category: support » feature

Thanks klausi!

Maybe this could be made as part of rules. Instead of sql query user can choose created view as condition.

mitchell’s picture

Component: Provided module integration » Rules Engine
Category: feature » support
Status: Active » Fixed

@mansspams: Please describe "view as condition" in #508550: Integration with Views module.

fago’s picture

Category: support » feature
Status: Fixed » Active

apart from using views for that I think having it as a separate condition where user could hand-write SQL would be nice too.

mitchell’s picture

@fago: Would this be an additional condition or could some help text with the PHP condition suffice?

fago’s picture

A separate condition, but it should help the user with using the usual placeholders %s %d.

henrijs.seso’s picture

... and replacing tokens right in the query

fago’s picture

uhm no, that would allow sql injection.. This should only be possible for the placeholders... Thus forcing the user to go with placeholders for dynamic stuff is important.

mitchell’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev

@fago: If there's no longer a php action in rules, and there's pdo support in core, then this feature probably doesn't make sense. Do you agree?

fago’s picture

It would still make sense, but I'm unsure whether this is something that should ship with rules itself.

mitchell’s picture

Status: Active » Postponed (maintainer needs more info)
klausi’s picture

Category: feature » bug
Priority: Normal » Critical
Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closed since no further information has been provided. Reopen if still an issue.