SQL Join table Alias

This commit is contained in:
2021-01-07 14:59:36 +01:00
parent 810f51bdcc
commit fae8a71bac
5 changed files with 61 additions and 9 deletions

View File

@@ -16,6 +16,7 @@ use \Driver\SQL\Constraint\PrimaryKey;
use \Driver\SQL\Constraint\ForeignKey;
use Driver\SQL\Query\CreateTable;
use Driver\SQL\Query\Delete;
use Driver\SQL\Query\Drop;
use Driver\SQL\Query\Insert;
use Driver\SQL\Query\Query;
use Driver\SQL\Query\Select;
@@ -73,6 +74,10 @@ abstract class SQL {
return new Update($this, $table);
}
public function drop(string $table) {
return new Drop($this, $table);
}
// ####################
// ### ABSTRACT METHODS
// ####################
@@ -107,7 +112,9 @@ abstract class SQL {
$joinTable = $this->tableName($join->getTable());
$columnA = $this->columnName($join->getColumnA());
$columnB = $this->columnName($join->getColumnB());
$joinStr .= " $type JOIN $joinTable ON $columnA=$columnB";
$tableAlias = ($join->getTableAlias() ? " " . $join->getTableAlias() : "");
$joinStr .= " $type JOIN $joinTable$tableAlias ON $columnA=$columnB";
}
}
@@ -248,6 +255,12 @@ abstract class SQL {
return $this->execute($query, $params);
}
public function executeDrop(Drop $drop) {
$query = "DROP TABLE " . $this->tableName($drop->getTable());
if ($drop->dump) { var_dump($query); }
return $this->execute($query);
}
protected function getWhereClause($conditions, &$params) {
if (!$conditions) {
return "";