Parses a query and gets all information about it.
public static getAll ( string $query ) : array | ||
$query | string | The query to be parsed. |
return | array | The array returned is the one returned by `static::getFlags()`, with the following keys added: - parser - the parser used to analyze the query; - statement - the first statement resulted from parsing; - select_tables - the real name of the tables selected; if there are no table names in the `SELECT` expressions, the table names are fetched from the `FROM` expressions - select_expr - selected expressions |
public function testGetAll() { $this->assertEquals(array('distinct' => false, 'drop_database' => false, 'group' => false, 'having' => false, 'is_affected' => false, 'is_analyse' => false, 'is_count' => false, 'is_delete' => false, 'is_explain' => false, 'is_export' => false, 'is_func' => false, 'is_group' => false, 'is_insert' => false, 'is_maint' => false, 'is_procedure' => false, 'is_replace' => false, 'is_select' => false, 'is_show' => false, 'is_subquery' => false, 'join' => false, 'limit' => false, 'offset' => false, 'order' => false, 'querytype' => false, 'reload' => false, 'select_from' => false, 'union' => false), Query::getAll('')); $query = 'SELECT *, actor.actor_id, sakila2.film.* FROM sakila2.city, sakila2.film, actor'; $parser = new Parser($query); $this->assertEquals(array_merge(Query::getFlags($parser->statements[0], true), array('parser' => $parser, 'statement' => $parser->statements[0], 'select_expr' => array('*'), 'select_tables' => array(array('actor', null), array('film', 'sakila2')))), Query::getAll($query)); $query = 'SELECT * FROM sakila.actor, film'; $parser = new Parser($query); $this->assertEquals(array_merge(Query::getFlags($parser->statements[0], true), array('parser' => $parser, 'statement' => $parser->statements[0], 'select_expr' => array('*'), 'select_tables' => array(array('actor', 'sakila'), array('film', null)))), Query::getAll($query)); $query = 'SELECT a.actor_id FROM sakila.actor AS a, film'; $parser = new Parser($query); $this->assertEquals(array_merge(Query::getFlags($parser->statements[0], true), array('parser' => $parser, 'statement' => $parser->statements[0], 'select_expr' => array(), 'select_tables' => array(array('actor', 'sakila')))), Query::getAll($query)); }
public function testGetAll() { $this->assertEquals(array(), Query::getAll('')); $query = 'SELECT *, actor.actor_id, sakila2.film.* FROM sakila2.city, sakila2.film, actor'; $parser = new Parser($query); $this->assertEquals(array_merge(Query::getFlags($parser->statements[0], true), array('parser' => $parser, 'statement' => $parser->statements[0], 'select_expr' => array('*'), 'select_tables' => array(array('actor', null), array('film', 'sakila2')))), Query::getAll($query)); $query = 'SELECT * FROM sakila.actor, film'; $parser = new Parser($query); $this->assertEquals(array_merge(Query::getFlags($parser->statements[0], true), array('parser' => $parser, 'statement' => $parser->statements[0], 'select_expr' => array('*'), 'select_tables' => array(array('actor', 'sakila'), array('film', null)))), Query::getAll($query)); $query = 'SELECT a.actor_id FROM sakila.actor AS a, film'; $parser = new Parser($query); $this->assertEquals(array_merge(Query::getFlags($parser->statements[0], true), array('parser' => $parser, 'statement' => $parser->statements[0], 'select_expr' => array(), 'select_tables' => array(array('actor', 'sakila')))), Query::getAll($query)); }
public function testGetAllEmpty() { $this->assertEquals(array(), Query::getAll('')); }