mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-06 20:48:40 +00:00
better sql error handling and new request data get function
This commit is contained in:
parent
b6cba39abf
commit
bc7fe194c7
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
$refProp->setValue($obj, $value);
|
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);
|
||||||
|
}
|
||||||
} 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);
|
||||||
|
|
|
||||||
|
|
@ -1401,16 +1401,20 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function execute() : mixed
|
public function execute() : mixed
|
||||||
{
|
{
|
||||||
$sth = $this->connection->con->prepare($this->toSql());
|
try {
|
||||||
|
$sth = $this->connection->con->prepare($this->toSql());
|
||||||
|
|
||||||
foreach ($this->binds as $key => $bind) {
|
foreach ($this->binds as $key => $bind) {
|
||||||
$type = self::getBindParamType($bind);
|
$type = self::getBindParamType($bind);
|
||||||
|
|
||||||
$sth->bindParam($key, $bind, $type);
|
$sth->bindParam($key, $bind, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sth->execute();
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
var_dump($this->toSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
$sth->execute();
|
|
||||||
|
|
||||||
return $sth;
|
return $sth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,13 +77,14 @@ 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,7 +92,24 @@ abstract class RequestAbstract implements MessageInterface
|
||||||
|
|
||||||
$key = \mb_strtolower($key);
|
$key = \mb_strtolower($key);
|
||||||
|
|
||||||
return $this->data[$key] ?? null;
|
if ($type === 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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user