/** * Compile the SQL query and return it. Replaces any parameters with their * given values. * * @param mixed $db Database instance or name of instance * @return string */ public function compile($db = NULL) { if (!is_object($db)) { // Get the database instance $db = Database::instance($db); } // Import the SQL locally $sql = $this->_sql; if (!empty($this->_parameters)) { // Quote all of the values $values = array_map([$db, 'quote'], $this->_parameters); // Replace the values in the SQL $sql = strtr($sql, $values); } return $sql; }