It is a very basic version of a query builder.
public static replaceClause ( |
||
$statement | The parsed query that has to be modified. | |
$list | 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. |
리턴 | string |
/** * 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); }
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)); }