Skip to content

Commit

Permalink
Adjust examples to new code
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jan 23, 2017
1 parent 955911f commit 62e9dd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

* Fixed CLI wrappers for new API.
* Fixed README for new API.

## [4.0.0] - 2017-01-23

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ echo SqlParser\Utils\Formatter::format($query, array('type' => 'html'));
### Discoverying query type

```php
use SqlParser\Parser;
use SqlParser\Utils\Query;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Utils\Query;

$query = 'OPTIMIZE TABLE tbl';
$parser = new Parser($query);
Expand All @@ -64,16 +64,16 @@ echo $flags['querytype'];
require __DIR__."/vendor/autoload.php";

$query1 = "select * from a";
$parser = new SqlParser\Parser($query1);
$parser = new PhpMyAdmin\SqlParser\Parser($query1);

// inspect query
var_dump($parser->statements[0]); // outputs object(SqlParser\Statements\SelectStatement)
var_dump($parser->statements[0]); // outputs object(PhpMyAdmin\SqlParser\Statements\SelectStatement)

// modify query by replacing table a with table b
$table2 = new \SqlParser\Components\Expression("", "b", "", "");
$table2 = new \PhpMyAdmin\SqlParser\Components\Expression("", "b", "", "");
$parser->statements[0]->from[0] = $table2;

// build query again from an array of object(SqlParser\Statements\SelectStatement) to a string
// build query again from an array of object(PhpMyAdmin\SqlParser\Statements\SelectStatement) to a string
$statement = $parser->statements[0];
$query2 = $statement->build();
var_dump($query2); // outputs string(19) "SELECT * FROM `b` "
Expand Down

0 comments on commit 62e9dd1

Please sign in to comment.