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
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);
 }
Example #2
0
 public function testReplaceClauseOnlyKeyword()
 {
     $parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10');
     $this->assertEquals(' SELECT SQL_CALC_FOUND_ROWS *, (SELECT 1) FROM film LIMIT 0, 10', Query::replaceClause($parser->statements[0], $parser->list, 'SELECT SQL_CALC_FOUND_ROWS', true));
 }