better sql error handling and new request data get function

This commit is contained in:
Dennis Eichhorn 2021-01-23 12:29:02 +01:00
parent b6cba39abf
commit bc7fe194c7
3 changed files with 37 additions and 12 deletions

View File

@ -601,7 +601,7 @@ class DataMapperAbstract implements DataMapperInterface
} }
} catch (\Throwable $t) { } catch (\Throwable $t) {
\var_dump($t->getMessage()); \var_dump($t->getMessage());
\var_dump($query->toSql()); \var_dump($a = $query->toSql());
return -1; return -1;
} }
@ -2271,7 +2271,10 @@ class DataMapperAbstract implements DataMapperInterface
static::$ownsOne[$def['internal']]['mapper']::fillRelations($value, self::$relations, $depth - 1); static::$ownsOne[$def['internal']]['mapper']::fillRelations($value, self::$relations, $depth - 1);
} }
if (!empty($value)) {
// todo: find better solution. this was because of a bug with the sales billing list query depth = 4. The address was set (from the client, referral or creator) but then somehow there was a second address element which was all null and null cannot be asigned to a string variable (e.g. country). The problem with this solution is that if the model expects an initialization (e.g. at lest set the elements to null, '', 0 etc.) this is now not done.
$refProp->setValue($obj, $value); $refProp->setValue($obj, $value);
}
} elseif (isset(static::$belongsTo[$def['internal']])) { } elseif (isset(static::$belongsTo[$def['internal']])) {
$default = null; $default = null;
if ($depth - 1 < 1 && $refProp->isInitialized($obj)) { if ($depth - 1 < 1 && $refProp->isInitialized($obj)) {
@ -2556,7 +2559,7 @@ class DataMapperAbstract implements DataMapperInterface
int $depth = 3 int $depth = 3
) : array ) : array
{ {
$query = self::getQuery(); $query = self::getQuery(depth: $depth);
$query->where(static::$table . '_' . $depth . '.' . ($column !== null ? self::getColumnByMember($column) : static::$primaryField), '>', $pivot) $query->where(static::$table . '_' . $depth . '.' . ($column !== null ? self::getColumnByMember($column) : static::$primaryField), '>', $pivot)
->orderBy(static::$table . '_' . $depth . '.' . ($column !== null ? self::getColumnByMember($column) : static::$primaryField), $order) ->orderBy(static::$table . '_' . $depth . '.' . ($column !== null ? self::getColumnByMember($column) : static::$primaryField), $order)
->limit($limit); ->limit($limit);

View File

@ -1401,6 +1401,7 @@ class Builder extends BuilderAbstract
*/ */
public function execute() : mixed public function execute() : mixed
{ {
try {
$sth = $this->connection->con->prepare($this->toSql()); $sth = $this->connection->con->prepare($this->toSql());
foreach ($this->binds as $key => $bind) { foreach ($this->binds as $key => $bind) {
@ -1410,6 +1411,9 @@ class Builder extends BuilderAbstract
} }
$sth->execute(); $sth->execute();
} catch (\Throwable $t) {
var_dump($this->toSql());
}
return $sth; return $sth;
} }

View File

@ -78,12 +78,13 @@ abstract class RequestAbstract implements MessageInterface
* Get data. * Get data.
* *
* @param string $key Data key * @param string $key Data key
* @param string $type Return type
* *
* @return mixed * @return mixed
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getData(string $key = null) : mixed public function getData(string $key = null, string $type = null) : mixed
{ {
if ($key === null) { if ($key === null) {
return $this->data; return $this->data;
@ -91,9 +92,26 @@ abstract class RequestAbstract implements MessageInterface
$key = \mb_strtolower($key); $key = \mb_strtolower($key);
if ($type === null) {
return $this->data[$key] ?? null; return $this->data[$key] ?? null;
} }
if (!isset($this->data[$key])) {
return null;
}
switch ($type) {
case 'int':
return (int) $this->data[$key];
case 'string':
return (string) $this->data[$key];
case 'float':
return (float) $this->data[$key];
default:
return $this->data[$key];
}
}
/** /**
* Get data. * Get data.
* *