diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index b916bbbe8..3ca6d8743 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -249,6 +249,14 @@ class DataMapperAbstract implements DataMapperInterface */ protected static string $datetimeFormat = 'Y-m-d H:i:s'; + /** + * Raw query data from last query + * + * @var array + * @since 1.0.0 + */ + protected static array $lastQueryData = []; + /** * Constructor. * @@ -1449,6 +1457,11 @@ class DataMapperAbstract implements DataMapperInterface */ private static function updateModel(object $obj, mixed $objId, \ReflectionClass $refClass = null, int $depth = 1) : void { + // Model doesn't have anything to update + if (\count(static::$columns) < 2) { + return; + } + $query = new Builder(self::$db); $query->update(static::$table) ->where(static::$table . '.' . static::$primaryField, '=', $objId); @@ -1507,9 +1520,14 @@ class DataMapperAbstract implements DataMapperInterface } } - $sth = self::$db->con->prepare($query->toSql()); - if ($sth !== false) { - $sth->execute(); + try { + $sth = self::$db->con->prepare($query->toSql()); + if ($sth !== false) { + $sth->execute(); + } + } catch (\Throwable $t) { + echo $t->getMessage(); + echo $query->toSql(); } } @@ -2641,6 +2659,11 @@ class DataMapperAbstract implements DataMapperInterface if (!empty($keys) || $primaryKey === null) { $dbData = self::getRaw($keys, self::$relations, $depth, $ref, $query); + + if (static::class === self::$parentMapper) { + static::$lastQueryData = $dbData; + } + foreach ($dbData as $row) { $value = $row[static::$primaryField . '_' . $depth]; $obj[$value] = self::createBaseModel(); @@ -2664,6 +2687,11 @@ class DataMapperAbstract implements DataMapperInterface return $obj; } + public static function getDataLastQuery() : array + { + return static::$lastQueryData; + } + /** * Get object. * diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index d8862eeac..b948364e4 100644 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -84,6 +84,10 @@ abstract class GrammarAbstract 'COUNT(', 'MAX(', 'MIN(', + 'SUM(', + 'DATE(', + 'YEAR(', + 'MONTH(', ]; /** diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 150775cb4..271366bf5 100644 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -1402,6 +1402,7 @@ class Builder extends BuilderAbstract public function execute() : mixed { try { + $t = $this->toSql(); $sth = $this->connection->con->prepare($this->toSql()); foreach ($this->binds as $key => $bind) { diff --git a/Localization/Defaults/Country.php b/Localization/Defaults/Country.php index 2da04b64e..941101ca1 100644 --- a/Localization/Defaults/Country.php +++ b/Localization/Defaults/Country.php @@ -72,6 +72,22 @@ class Country */ protected string $subdevision = ''; + /** + * Country region. + * + * @var string + * @since 1.0.0 + */ + protected string $region = ''; + + /** + * Country developed. + * + * @var string + * @since 1.0.0 + */ + protected bool $isDeveloped = false; + /** * Get id * @@ -143,4 +159,28 @@ class Country { return $this->subdevision; } + + /** + * Get country region + * + * @return string + * + * @since 1.0.0 + */ + public function getRegion() : string + { + return $this->region; + } + + /** + * Is country developed + * + * @return bool + * + * @since 1.0.0 + */ + public function isDeveloped() : bool + { + return $this->isDeveloped; + } } diff --git a/Localization/Defaults/CountryMapper.php b/Localization/Defaults/CountryMapper.php index 02577ef91..590e3ae9a 100644 --- a/Localization/Defaults/CountryMapper.php +++ b/Localization/Defaults/CountryMapper.php @@ -38,6 +38,8 @@ class CountryMapper extends DataMapperAbstract 'country_code2' => ['name' => 'country_code2', 'type' => 'string', 'internal' => 'code2'], 'country_code3' => ['name' => 'country_code3', 'type' => 'string', 'internal' => 'code3'], 'country_numeric' => ['name' => 'country_numeric', 'type' => 'int', 'internal' => 'numeric'], + 'country_region' => ['name' => 'country_region', 'type' => 'string', 'internal' => 'region'], + 'country_developed' => ['name' => 'country_developed', 'type' => 'bool', 'internal' => 'isDeveloped'], ]; /** diff --git a/Localization/Defaults/localization.sqlite b/Localization/Defaults/localization.sqlite index 555daaee8..a87dc7249 100644 Binary files a/Localization/Defaults/localization.sqlite and b/Localization/Defaults/localization.sqlite differ