You are here

public function SelectQuery::__toString in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 src/SelectQuery.php \Drupal\salesforce\SelectQuery::__toString()
  2. 8.3 src/SelectQuery.php \Drupal\salesforce\SelectQuery::__toString()

Return the query as a string.

Return value

string The url-encoded query string.

Overrides SelectQueryInterface::__toString

File

src/SelectQuery.php, line 101

Class

SelectQuery
Class SelectQuery.

Namespace

Drupal\salesforce

Code

public function __toString() {
  $query = 'SELECT+';
  $query .= implode(',', array_unique($this->fields));
  $query .= "+FROM+" . $this->objectType;
  if (count($this->conditions) > 0) {
    $where = [];
    foreach ($this->conditions as $condition) {
      $where[] = implode('+', $condition);
    }
    $query .= '+WHERE+' . implode('+AND+', $where);
  }
  if ($this->order) {
    $query .= "+ORDER BY+";
    $fields = [];
    foreach ($this->order as $field => $direction) {
      $fields[] = $field . ' ' . $direction;
    }
    $query .= implode(',+', $fields);
  }
  if ($this->limit) {
    $query .= "+LIMIT+" . (int) $this->limit;
  }
  return $query;
}