getClause() public static method

Gets a specific clause.
public static getClause ( Statement $statement, TokensList $list, string $clause, integer | string $type, boolean $skipFirst = true ) : string
$statement SqlParser\Statement The parsed query that has to be modified.
$list SqlParser\TokensList The list of tokens.
$clause string The clause to be returned.
$type integer | string The type of the search. If int, -1 for everything that was before 0 only for the clause 1 for everything after If string, the name of the first clause that should not be included.
$skipFirst boolean Whether to skip the first keyword in clause.
return string
Example #1
0
 /**
  * Get url sql query without conditions to shorten URLs
  *
  * @param array $analyzed_sql_results analyzed sql results
  *
  * @return  string  $url_sql        analyzed sql query
  *
  * @access  private
  *
  * @see     _getTableBody()
  */
 private function _getUrlSqlQuery($analyzed_sql_results)
 {
     if ($analyzed_sql_results['querytype'] != 'SELECT' || mb_strlen($this->__get('sql_query')) < 200) {
         return $this->__get('sql_query');
     }
     $query = 'SELECT ' . Query::getClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'SELECT');
     $from_clause = Query::getClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'FROM');
     if (!empty($from_clause)) {
         $query .= ' FROM ' . $from_clause;
     }
     return $query;
 }
Example #2
0
 public function testGetClause()
 {
     $parser = new Parser('SELECT c.city_id, c.country_id ' . 'FROM `city` ' . 'WHERE city_id < 1 /* test */' . 'ORDER BY city_id ASC ' . 'LIMIT 0, 1 ' . 'INTO OUTFILE "/dev/null"');
     $this->assertEquals('WHERE city_id < 1 ORDER BY city_id ASC', Query::getClause($parser->statements[0], $parser->list, 'LIMIT', 'FROM'));
 }