From 90b59d5a45fbac61f7f568e4fda3a2db58ec96cf Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Thu, 7 Mar 2024 22:01:58 -0300 Subject: [PATCH] Adapt syntax col/table magiQL --- .../Syntax/Adapt/MSSQL/ColumnTable.php | 31 +++++++++++ .../Syntax/Adapt/MySQL/ColumnTable.php | 18 +++++++ .../Syntax/Adapt/Oracle/ColumnTable.php | 32 ++++++++++++ .../Syntax/Adapt/PostgreSQL/ColumnTable.php | 31 +++++++++++ system/MagiQL/Builder/Syntax/ColumnWriter.php | 52 +++++++++++++++++-- 5 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 system/MagiQL/Builder/Syntax/Adapt/MSSQL/ColumnTable.php create mode 100644 system/MagiQL/Builder/Syntax/Adapt/MySQL/ColumnTable.php create mode 100644 system/MagiQL/Builder/Syntax/Adapt/Oracle/ColumnTable.php create mode 100644 system/MagiQL/Builder/Syntax/Adapt/PostgreSQL/ColumnTable.php diff --git a/system/MagiQL/Builder/Syntax/Adapt/MSSQL/ColumnTable.php b/system/MagiQL/Builder/Syntax/Adapt/MSSQL/ColumnTable.php new file mode 100644 index 0000000..283c879 --- /dev/null +++ b/system/MagiQL/Builder/Syntax/Adapt/MSSQL/ColumnTable.php @@ -0,0 +1,31 @@ +writer->writeTableName($value->getTable()); + $key = $this->getWriteObj()->writeTableName($value->getTable()); } $column = $selectWriter->selectToColumn($key, $value); } @@ -136,7 +139,7 @@ class ColumnWriter public function writeColumnWithAlias(Column $column) { if (($alias = $column->getAlias()) && !$column->isAll()) { - return $this->writeColumn($column).' AS '.$this->writer->writeColumnAlias($alias); + return $this->writeColumn($column).' AS '.$this->getWriteObj()->writeColumnAlias($alias); } return $this->writeColumn($column); @@ -150,11 +153,52 @@ class ColumnWriter public function writeColumn(Column $column) { $alias = $column->getTable()->getAlias(); - $table = ($alias) ? $this->writer->writeTableAlias($alias) : $this->writer->writeTable($column->getTable()); + $table = ($alias) ? $this->getWriteObj()->writeTableAlias($alias) : $this->getWriteObj()->writeTable($column->getTable()); $columnString = (empty($table)) ? '' : "{$table}."; - $columnString .= $this->writer->writeColumnName($column); + $columnString .= $this->getWriteObj()->writeColumnName($column); return $columnString; } + + /** + * + * @return \Phacil\Framework\MagiQL\Api\BuilderInterface + */ + protected function getWriteObj() + { + if($this->writerAlternative) return $this->writerAlternative; + + $writerDbType = null; + if (method_exists($this->writer, 'getDb')) { + /** @var \Phacil\Framework\MagiQL */ + $writer = $this->writer; + $writerDbType = $writer->getDb()->getDBTypeId(); + unset($writer); + } + switch ($writerDbType) { + case DatabaseDriverInterface::LIST_DB_TYPE_ID['MYSQL']: + $this->writerAlternative = new \Phacil\Framework\MagiQL\Builder\Syntax\Adapt\MySQL\ColumnTable(); + break; + + case DatabaseDriverInterface::LIST_DB_TYPE_ID['MSSQL']: + $this->writerAlternative = new \Phacil\Framework\MagiQL\Builder\Syntax\Adapt\MSSQL\ColumnTable(); + break; + + case DatabaseDriverInterface::LIST_DB_TYPE_ID['POSTGRE']: + case DatabaseDriverInterface::LIST_DB_TYPE_ID['SQLLITE3']: + $this->writerAlternative = new \Phacil\Framework\MagiQL\Builder\Syntax\Adapt\PostgreSQL\ColumnTable(); + break; + + case DatabaseDriverInterface::LIST_DB_TYPE_ID['ORACLE']: + $this->writerAlternative = new \Phacil\Framework\MagiQL\Builder\Syntax\Adapt\Oracle\ColumnTable(); + break; + + default: + $this->writerAlternative = $this->writer; + break; + } + + return $this->writerAlternative; + } }