SqlParser\Utils\Query::replaceClause PHP Method

replaceClause() public static method

It is a very basic version of a query builder.
public static replaceClause ( Statement $statement, TokensList $list, string $old, string $new = null, boolean $onlyType = false ) : string
$statement SqlParser\Statement The parsed query that has to be modified.
$list SqlParser\TokensList The list of tokens.
$old string The type of the clause that should be replaced. This can be an entire clause.
$new string The new clause. If this parameter is omitted it is considered to be equal with `$old`.
$onlyType boolean Whether only the type of the clause should be replaced or the entire clause.
return string
    public static function replaceClause($statement, $list, $old, $new = null, $onlyType = false)
    {
        // TODO: Update the tokens list and the statement.
        if ($new === null) {
            $new = $old;
        }
        if ($onlyType) {
            return static::getClause($statement, $list, $old, -1, false) . ' ' . $new . ' ' . static::getClause($statement, $list, $old, 0) . ' ' . static::getClause($statement, $list, $old, 1, false);
        }
        return static::getClause($statement, $list, $old, -1, false) . ' ' . $new . ' ' . static::getClause($statement, $list, $old, 1, false);
    }

Usage Example

Example #1
0
 /**
  * Prepare unsorted sql query and sort by key drop down
  *
  * @param array  $analyzed_sql_results analyzed sql results
  * @param string $sort_expression      sort expression
  *
  * @return  array   two element array - $unsorted_sql_query, $drop_down_html
  *
  * @access  private
  *
  * @see     _getTableHeaders()
  */
 private function _getUnsortedSqlAndSortByKeyDropDown($analyzed_sql_results, $sort_expression)
 {
     $drop_down_html = '';
     $unsorted_sql_query = Query::replaceClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'ORDER BY', '');
     // Data is sorted by indexes only if it there is only one table.
     if ($this->_isSelect($analyzed_sql_results)) {
         // grab indexes data:
         $indexes = Index::getFromTable($this->__get('table'), $this->__get('db'));
         // do we have any index?
         if (!empty($indexes)) {
             $drop_down_html = $this->_getSortByKeyDropDown($indexes, $sort_expression, $unsorted_sql_query);
         }
     }
     return array($unsorted_sql_query, $drop_down_html);
 }
All Usage Examples Of SqlParser\Utils\Query::replaceClause