-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atk4\Data\Persistence\Sql\Optimizer; | ||
|
||
use Atk4\Data\Persistence\Sql\Expression; | ||
|
||
class ParsedColumn | ||
{ | ||
/** @var Expression|string */ | ||
public $expr; | ||
/** @var string|null not-null iff expr is a string */ | ||
public $exprTableAlias; | ||
/** @var string */ | ||
public $columnAlias; | ||
|
||
public function __construct(Expression $expr, string $columnAlias) | ||
{ | ||
$exprIdentifier = Util::tryParseIdentifier($expr); | ||
if ($exprIdentifier !== false) { | ||
$this->exprTableAlias = $exprIdentifier[0]; | ||
$this->expr = $exprIdentifier[1]; | ||
} else { | ||
$this->expr = $expr; | ||
} | ||
|
||
$this->columnAlias = Util::parseSingleIdentifier($columnAlias); | ||
} | ||
|
||
public function getDsqlExpression(): Expression | ||
{ | ||
if ($this->exprTableAlias !== null) { | ||
return new Expression('{}.{} {}', [$this->expr, $this->exprTableAlias, $this->columnAlias]); | ||
Check failure on line 34 in src/Persistence/Sql/Optimizer/ParsedColumn.php GitHub Actions / Smoke (latest, StaticAnalysis)
|
||
} | ||
|
||
return new Expression('{} {}', [$this->expr, $this->columnAlias]); | ||
Check failure on line 37 in src/Persistence/Sql/Optimizer/ParsedColumn.php GitHub Actions / Smoke (latest, StaticAnalysis)
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atk4\Data\Persistence\Sql\Optimizer; | ||
|
||
use Atk4\Data\Persistence\Sql\Expression; | ||
use Atk4\Data\Persistence\Sql\Query; | ||
|
||
class ParsedSelect | ||
{ | ||
/** @var string */ | ||
public const TOP_QUERY_ALIAS = '__atk4_top_query__'; | ||
|
||
/** @var Query|string */ | ||
public $expr; | ||
/** @var string */ | ||
public $tableAlias; | ||
|
||
/** | ||
* @param Query|string $expr | ||
*/ | ||
public function __construct($expr, string $tableAlias) | ||
{ | ||
$exprIdentifier = Util::tryParseIdentifier($expr); | ||
if ($exprIdentifier !== false) { | ||
$this->expr = Util::parseSingleIdentifier($expr); | ||
} else { | ||
$this->expr = $expr; | ||
} | ||
|
||
$this->tableAlias = Util::parseSingleIdentifier($tableAlias); | ||
} | ||
|
||
// public function getDsqlExpression(): Expression | ||
// { | ||
// if ($this->tableAlias === self::TOP_QUERY_ALIAS) { | ||
// return new Expression('{}', [$this->expr]); | ||
// } | ||
// | ||
// return new Expression('{} {}', [$this->expr, $this->tableAlias]); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters