From b0dcdf6fdf3ed2a29518f08482e86febddc2e52b Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Sun, 6 Apr 2025 07:55:10 +0100 Subject: [PATCH 1/2] Add getAllTablesWithoutAliases method --- src/LightSQLParser.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/LightSQLParser.php b/src/LightSQLParser.php index fb2a929..5f00490 100644 --- a/src/LightSQLParser.php +++ b/src/LightSQLParser.php @@ -194,6 +194,22 @@ function getAllTables() { return array_unique($results); } + /** + * Get SQL Query Tables without aliases + * @return array + */ + function getAllTablesWithoutAliases() { + $raw = $this->getAllTables(); + $return = []; + foreach ($raw as $thistable) { + if (str_contains($thistable, " ")) { + $thistable = explode(" ", $thistable)[0]; + } + $return[] = $thistable; + } + return $return; + } + /** * Join tables. * @return array From 8612fc4c720c690552e03dfc219952b5b72d8b12 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Sun, 6 Apr 2025 08:00:28 +0100 Subject: [PATCH 2/2] README to document new method --- README.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c973972..a98407f 100644 --- a/README.md +++ b/README.md @@ -61,18 +61,31 @@ string(9) "Customers" ``` -How to retrieve the query's tables: +How to retrieve the query's tables (including aliases used in the query): ```php $parser->getAllTables(); ``` Output ``` array(1) { - [0]=> - string(9) "Customers" + [0]=> string(9) "Customers", + [1]=> string(5) "Alias" +} +``` + + +How to retrieve the query's tables (without aliases used in the query): +```php +$parser->getAllTablesWithoutAliases(); +``` +Output +``` +array(1) { + [0]=> string(9) "Customers" } ``` + ### Fields How to retrieve the query's fields: ```php @@ -102,10 +115,10 @@ array(2) { | getMethod | param $query
return string | Get SQL Query method | | getFields | param $query
return array | Get Query fields (at the moment only SELECTINSERTUPDATE) | | getTable | param $query
return string | Get SQL Query First Table | -| getTables | return array | Get SQL Query Tables | +| getTables | return array | Get SQL Query Tables (including aliases) | +| getTablesWithoutAliases | return array | Get SQL Query Tables (without aliases) | | getJoinTables | return array | Get SQL Query Join Tables | | hasJoin | return bool | Return if has join tables | | getSubQueries | return array | Get all SELECT subqueries | | hasSubQueries | return bool | Return if has subqueries | -