/** * Builds a sql query with the specified connection * * @param SQLExpression $query The expression object to build from * @param array $parameters Out parameter for the resulting query parameters * @return string The resulting SQL as a string */ public function buildSQL(SQLExpression $query, &$parameters) { $sql = null; $parameters = array(); // Ignore null queries if ($query->isEmpty()) { return null; } if ($query instanceof SQLSelect) { $sql = $this->buildSelectQuery($query, $parameters); } elseif ($query instanceof SQLDelete) { $sql = $this->buildDeleteQuery($query, $parameters); } elseif ($query instanceof SQLInsert) { $sql = $this->buildInsertQuery($query, $parameters); } elseif ($query instanceof SQLUpdate) { $sql = $this->buildUpdateQuery($query, $parameters); } else { user_error("Not implemented: query generation for type " . $query->getType()); } return $sql; }
/** * Delete this object from the database by specified criteria * * @param rdbms.SQLExpression criteria * @return int number of affected rows * @throws rdbms.SQLException in case an error occurs */ public function doDelete(SQLExpression $criteria) { $db = $this->getConnection(); // Send it return $db->delete('from %c%c', $this->table, $criteria->toSQL($db, $this)); }
/** * Returns the WHERE clauses ready for inserting into a query. * * @param SQLExpression $query The expression object to build from * @param array $parameters Out parameter for the resulting query parameters * @return string Completed where condition */ public function buildWhereFragment(SQLExpression $query, array &$parameters) { // Get parameterised elements $where = $query->getWhereParameterised($whereParameters); if (empty($where)) { return ''; } // Join conditions $connective = $query->getConnective(); $parameters = array_merge($parameters, $whereParameters); $nl = $this->getSeparator(); return "{$nl}WHERE (" . implode("){$nl}{$connective} (", $where) . ")"; }