Router, Logger, Bump v1.5
This commit is contained in:
@@ -59,7 +59,7 @@ class MySQL extends SQL {
|
||||
);
|
||||
|
||||
if (mysqli_connect_errno()) {
|
||||
$this->lastError = "Failed to connect to MySQL: " . mysqli_connect_error();
|
||||
$this->lastError = $this->logger->severe("Failed to connect to MySQL: " . mysqli_connect_error());
|
||||
$this->connection = NULL;
|
||||
return false;
|
||||
}
|
||||
@@ -164,20 +164,20 @@ class MySQL extends SQL {
|
||||
}
|
||||
$success = true;
|
||||
} else {
|
||||
$this->lastError = "PreparedStatement::get_result failed: $stmt->error ($stmt->errno)";
|
||||
$this->lastError = $this->logger->error("PreparedStatement::get_result failed: $stmt->error ($stmt->errno)");
|
||||
}
|
||||
} else {
|
||||
$success = true;
|
||||
}
|
||||
} else {
|
||||
$this->lastError = "PreparedStatement::execute failed: $stmt->error ($stmt->errno)";
|
||||
$this->lastError = $this->logger->error("PreparedStatement::execute failed: $stmt->error ($stmt->errno)");
|
||||
}
|
||||
} else {
|
||||
$this->lastError = "PreparedStatement::prepare failed: $stmt->error ($stmt->errno)";
|
||||
$this->lastError = $this->logger->error("PreparedStatement::prepare failed: $stmt->error ($stmt->errno)");
|
||||
}
|
||||
}
|
||||
} catch (\mysqli_sql_exception $exception) {
|
||||
$this->lastError = "MySQL::execute failed: $stmt->error ($stmt->errno)";
|
||||
$this->lastError = $this->logger->error("MySQL::execute failed: $stmt->error ($stmt->errno)");
|
||||
} finally {
|
||||
if ($res !== null && !is_bool($res)) {
|
||||
$res->close();
|
||||
@@ -214,7 +214,7 @@ class MySQL extends SQL {
|
||||
return " ON DUPLICATE KEY UPDATE " . implode(",", $updateValues);
|
||||
} else {
|
||||
$strategyClass = get_class($strategy);
|
||||
$this->lastError = "ON DUPLICATE Strategy $strategyClass is not supported yet.";
|
||||
$this->lastError = $this->logger->error("ON DUPLICATE Strategy $strategyClass is not supported yet.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class MySQL extends SQL {
|
||||
} else if($column instanceof JsonColumn) {
|
||||
return "LONGTEXT"; # some maria db setups don't allow JSON here…
|
||||
} else {
|
||||
$this->lastError = "Unsupported Column Type: " . get_class($column);
|
||||
$this->lastError = $this->logger->error("Unsupported Column Type: " . get_class($column));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -251,17 +251,17 @@ class MySQL extends SQL {
|
||||
public function getColumnDefinition(Column $column): ?string {
|
||||
$columnName = $this->columnName($column->getName());
|
||||
$defaultValue = $column->getDefaultValue();
|
||||
$type = $this->getColumnType($column);
|
||||
if (!$type) {
|
||||
if ($column instanceof EnumColumn) {
|
||||
$values = array();
|
||||
foreach($column->getValues() as $value) {
|
||||
$values[] = $this->getValueDefinition($value);
|
||||
}
|
||||
if ($column instanceof EnumColumn) { // check this, shouldn't it be in getColumnType?
|
||||
$values = array();
|
||||
foreach($column->getValues() as $value) {
|
||||
$values[] = $this->getValueDefinition($value);
|
||||
}
|
||||
|
||||
$values = implode(",", $values);
|
||||
$type = "ENUM($values)";
|
||||
} else {
|
||||
$values = implode(",", $values);
|
||||
$type = "ENUM($values)";
|
||||
} else {
|
||||
$type = $this->getColumnType($column);
|
||||
if (!$type) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ class MySQL extends SQL {
|
||||
if ($param instanceof Column) {
|
||||
$paramDefs[] = $this->getParameterDefinition($param);
|
||||
} else {
|
||||
$this->setLastError("PROCEDURE parameter type " . gettype($returns) . " is not implemented yet");
|
||||
$this->lastError = $this->logger->error("PROCEDURE parameter type " . gettype($returns) . " is not implemented yet");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -402,7 +402,7 @@ class MySQL extends SQL {
|
||||
if ($returns instanceof Column) {
|
||||
$paramDefs[] = $this->getParameterDefinition($returns, true);
|
||||
} else if (!($returns instanceof Trigger)) { // mysql does not need to return triggers here
|
||||
$this->setLastError("PROCEDURE RETURN type " . gettype($returns) . " is not implemented yet");
|
||||
$this->lastError = $this->logger->error("PROCEDURE RETURN type " . gettype($returns) . " is not implemented yet");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class PostgreSQL extends SQL {
|
||||
|
||||
$this->connection = @pg_connect(implode(" ", $connectionString), PGSQL_CONNECT_FORCE_NEW);
|
||||
if (!$this->connection) {
|
||||
$this->lastError = "Failed to connect to Database";
|
||||
$this->lastError = $this->logger->severe("Failed to connect to Database");
|
||||
$this->connection = NULL;
|
||||
return false;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ class PostgreSQL extends SQL {
|
||||
return " ON CONFLICT ($conflictingColumns) DO UPDATE SET $updateValues";
|
||||
} else {
|
||||
$strategyClass = get_class($strategy);
|
||||
$this->lastError = "ON DUPLICATE Strategy $strategyClass is not supported yet.";
|
||||
$this->lastError = $this->logger->error("ON DUPLICATE Strategy $strategyClass is not supported yet.");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
@@ -233,7 +233,7 @@ class PostgreSQL extends SQL {
|
||||
} else if($column instanceof JsonColumn) {
|
||||
return "JSON";
|
||||
} else {
|
||||
$this->lastError = "Unsupported Column Type: " . get_class($column);
|
||||
$this->lastError = $this->logger->error("Unsupported Column Type: " . get_class($column));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -317,8 +317,7 @@ class PostgreSQL extends SQL {
|
||||
if ($col instanceof KeyWord) {
|
||||
return $col->getValue();
|
||||
} elseif(is_array($col)) {
|
||||
$columns = array();
|
||||
foreach($col as $c) $columns[] = $this->columnName($c);
|
||||
$columns = array_map(function ($c) { return $this->columnName($c); }, $col);
|
||||
return implode(",", $columns);
|
||||
} else {
|
||||
if (($index = strrpos($col, ".")) !== FALSE) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Driver\SQL;
|
||||
|
||||
use Driver\Logger\Logger;
|
||||
use Driver\SQL\Column\Column;
|
||||
use Driver\SQL\Condition\Compare;
|
||||
use Driver\SQL\Condition\CondAnd;
|
||||
@@ -40,6 +41,7 @@ use Objects\ConnectionData;
|
||||
|
||||
abstract class SQL {
|
||||
|
||||
protected Logger $logger;
|
||||
protected string $lastError;
|
||||
protected $connection;
|
||||
protected ConnectionData $connectionData;
|
||||
@@ -50,6 +52,7 @@ abstract class SQL {
|
||||
$this->lastError = 'Unknown Error';
|
||||
$this->connectionData = $connectionData;
|
||||
$this->lastInsertId = 0;
|
||||
$this->logger = new Logger(getClassName($this), $this);
|
||||
}
|
||||
|
||||
public function isConnected(): bool {
|
||||
@@ -168,7 +171,7 @@ abstract class SQL {
|
||||
|
||||
return $code;
|
||||
} else {
|
||||
$this->lastError = "Unsupported constraint type: " . get_class($constraint);
|
||||
$this->lastError = $this->logger->error("Unsupported constraint type: " . get_class($constraint));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -200,7 +203,7 @@ abstract class SQL {
|
||||
} else if ($value === null) {
|
||||
return "NULL";
|
||||
} else {
|
||||
$this->lastError = "Cannot create unsafe value of type: " . gettype($value);
|
||||
$this->lastError = $this->logger->error("Cannot create unsafe value of type: " . gettype($value));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -290,7 +293,7 @@ abstract class SQL {
|
||||
} else if($haystack instanceof Select) {
|
||||
$values = $haystack->build($params);
|
||||
} else {
|
||||
$this->lastError = "Unsupported in-expression value: " . get_class($condition);
|
||||
$this->lastError = $this->logger->error("Unsupported in-expression value: " . get_class($condition));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -322,7 +325,7 @@ abstract class SQL {
|
||||
} else if ($condition instanceof Exists) {
|
||||
return "EXISTS(" .$condition->getSubQuery()->build($params) . ")";
|
||||
} else {
|
||||
$this->lastError = "Unsupported condition type: " . gettype($condition);
|
||||
$this->lastError = $this->logger->error("Unsupported condition type: " . gettype($condition));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -345,7 +348,7 @@ abstract class SQL {
|
||||
$alias = $this->columnName($exp->getAlias());
|
||||
return "SUM($value) AS $alias";
|
||||
} else {
|
||||
$this->lastError = "Unsupported expression type: " . get_class($exp);
|
||||
$this->lastError = $this->logger->error("Unsupported expression type: " . get_class($exp));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -370,6 +373,7 @@ abstract class SQL {
|
||||
} else if ($type === "postgres") {
|
||||
$sql = new PostgreSQL($connectionData);
|
||||
} else {
|
||||
Logger::instance()->error("Unknown database type: $type");
|
||||
return "Unknown database type";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user