Frontend, Bugfixes

This commit is contained in:
2020-04-04 01:15:59 +02:00
parent efe3ada470
commit 8ce74edc38
30 changed files with 501 additions and 132 deletions

View File

@@ -7,7 +7,7 @@ class CondOr extends Condition {
private array $conditions;
public function __construct(...$conditions) {
$this->conditions = $conditions;
$this->conditions = (!empty($conditions) && is_array($conditions[0])) ? $conditions[0] : $conditions;
}
public function getConditions() { return $this->conditions; }

View File

@@ -2,6 +2,8 @@
namespace Driver\SQL\Query;
use Driver\SQL\Condition\CondOr;
class Delete extends Query {
private string $table;
@@ -14,7 +16,7 @@ class Delete extends Query {
}
public function where(...$conditions) {
$this->conditions = array_merge($this->conditions, $conditions);
$this->conditions[] = (count($conditions) === 1 ? $conditions : new CondOr($conditions));
return $this;
}

View File

@@ -7,9 +7,16 @@ use Driver\SQL\SQL;
abstract class Query {
protected SQL $sql;
public bool $dump;
public function __construct($sql) {
$this->sql = $sql;
$this->dump = false;
}
public function dump() {
$this->dump = true;
return $this;
}
public abstract function execute();

View File

@@ -2,6 +2,7 @@
namespace Driver\SQL\Query;
use Driver\SQL\Condition\CondOr;
use Driver\SQL\Join;
class Select extends Query {
@@ -33,7 +34,7 @@ class Select extends Query {
}
public function where(...$conditions) {
$this->conditions = array_merge($this->conditions, $conditions);
$this->conditions[] = (count($conditions) === 1 ? $conditions : new CondOr($conditions));
return $this;
}

View File

@@ -2,6 +2,8 @@
namespace Driver\SQL\Query;
use Driver\SQL\Condition\CondOr;
class Update extends Query {
private array $values;
@@ -16,7 +18,7 @@ class Update extends Query {
}
public function where(...$conditions) {
$this->conditions = array_merge($this->conditions, $conditions);
$this->conditions[] = (count($conditions) === 1 ? $conditions : new CondOr($conditions));
return $this;
}

View File

@@ -144,6 +144,7 @@ abstract class SQL {
$returning = $this->getReturning($returningCol);
$query = "INSERT INTO $tableName$columnStr VALUES$values$onDuplicateKey$returning";
if($insert->dump) { var_dump($query); var_dump($parameters); }
$res = $this->execute($query, $parameters, !empty($returning));
$success = ($res !== FALSE);
@@ -189,6 +190,7 @@ abstract class SQL {
$limit = ($select->getLimit() > 0 ? (" LIMIT " . $select->getLimit()) : "");
$offset = ($select->getOffset() > 0 ? (" OFFSET " . $select->getOffset()) : "");
$query = "SELECT $columns FROM $tables$joinStr$where$orderBy$limit$offset";
if($select->dump) { var_dump($query); var_dump($params); }
return $this->execute($query, $params, true);
}
@@ -198,6 +200,7 @@ abstract class SQL {
$where = $this->getWhereClause($delete->getConditions(), $params);
$query = "DELETE FROM $table$where";
if($delete->dump) { var_dump($query); }
return $this->execute($query);
}
@@ -218,6 +221,7 @@ abstract class SQL {
$where = $this->getWhereClause($update->getConditions(), $params);
$query = "UPDATE $table SET $valueStr$where";
if($update->dump) { var_dump($query); var_dump($params); }
return $this->execute($query, $params);
}
@@ -290,6 +294,7 @@ abstract class SQL {
protected abstract function execute($query, $values=NULL, $returnValues=false);
protected function buildCondition($condition, &$params) {
if ($condition instanceof CondOr) {
$conditions = array();
foreach($condition->getConditions() as $cond) {
@@ -304,7 +309,7 @@ abstract class SQL {
} else if ($condition instanceof CondBool) {
return $this->columnName($condition->getValue());
} else if (is_array($condition)) {
if (count($condition) == 1) {
if (count($condition) === 1) {
return $this->buildCondition($condition[0], $params);
} else {
$conditions = array();