mysql param types, async search, bugfix
This commit is contained in:
@@ -100,14 +100,14 @@ class Parameter {
|
||||
return $str;
|
||||
}
|
||||
|
||||
public static function parseType($value): int {
|
||||
public static function parseType(mixed $value, bool $strict = false): int {
|
||||
if (is_array($value))
|
||||
return Parameter::TYPE_ARRAY;
|
||||
else if (is_numeric($value) && intval($value) == $value)
|
||||
else if (is_int($value) || (!$strict && is_numeric($value) && intval($value) == $value))
|
||||
return Parameter::TYPE_INT;
|
||||
else if (is_float($value) || (is_numeric($value) && floatval($value) == $value))
|
||||
else if (is_float($value) || (!$strict && is_numeric($value) && floatval($value) == $value))
|
||||
return Parameter::TYPE_FLOAT;
|
||||
else if (is_bool($value) || $value == "true" || $value == "false")
|
||||
else if (is_bool($value) || (!$strict && ($value == "true" || $value == "false")))
|
||||
return Parameter::TYPE_BOOLEAN;
|
||||
else if (is_a($value, 'DateTime'))
|
||||
return Parameter::TYPE_DATE_TIME;
|
||||
|
||||
@@ -91,7 +91,7 @@ class MySQL extends SQL {
|
||||
private function getPreparedParams($values): array {
|
||||
$sqlParams = array('');
|
||||
foreach ($values as $value) {
|
||||
$paramType = Parameter::parseType($value);
|
||||
$paramType = Parameter::parseType($value, true); // TODO: is strict type checking really correct here?
|
||||
switch ($paramType) {
|
||||
case Parameter::TYPE_BOOLEAN:
|
||||
$value = $value ? 1 : 0;
|
||||
|
||||
@@ -342,7 +342,9 @@ class DatabaseEntityHandler implements Persistable {
|
||||
|
||||
$value = $row[$columnName];
|
||||
if ($column instanceof DateTimeColumn) {
|
||||
$value = new \DateTime($value);
|
||||
if ($value !== null) {
|
||||
$value = new \DateTime($value);
|
||||
}
|
||||
} else if ($column instanceof JsonColumn) {
|
||||
$value = json_decode($value, true);
|
||||
} else if (isset($this->relations[$propertyName])) {
|
||||
|
||||
@@ -138,7 +138,7 @@ class DatabaseEntityQuery extends Select {
|
||||
}
|
||||
}
|
||||
|
||||
public function execute(): DatabaseEntity|array|null {
|
||||
public function execute(): DatabaseEntity|array|null|false {
|
||||
|
||||
if ($this->logVerbose) {
|
||||
$params = [];
|
||||
@@ -148,7 +148,7 @@ class DatabaseEntityQuery extends Select {
|
||||
|
||||
$res = parent::execute();
|
||||
if ($res === null || $res === false) {
|
||||
return null;
|
||||
return $res;
|
||||
}
|
||||
|
||||
if ($this->resultType === SQL::FETCH_ALL) {
|
||||
|
||||
Reference in New Issue
Block a user