From 7343714642e20f82bda38435627032e8d72b9e53 Mon Sep 17 00:00:00 2001 From: "Kamshory, MT" Date: Sun, 1 Feb 2026 09:24:44 +0700 Subject: [PATCH 1/2] Use native Yaml function if exists --- src/Util/PicoYamlUtil.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Util/PicoYamlUtil.php b/src/Util/PicoYamlUtil.php index e394c876..a14bda94 100644 --- a/src/Util/PicoYamlUtil.php +++ b/src/Util/PicoYamlUtil.php @@ -89,6 +89,9 @@ public static function arrayDepth($array) { */ public static function dump($input, $inline, $indent, $flags) // NOSONAR { + if (function_exists('yaml_emit')) { + return yaml_emit($input, YAML_UTF8_ENCODING); + } if($inline == null || $inline < 0) { $inline = self::arrayDepth($input); @@ -111,6 +114,9 @@ public static function dump($input, $inline, $indent, $flags) // NOSONAR */ public static function parseFile($file) { + if (function_exists('yaml_parse_file')) { + return yaml_parse_file($file); + } $yaml = new Spicy(); return $yaml->loadFile($file); } @@ -128,6 +134,9 @@ public static function parseFile($file) */ public static function parse($rawData) { + if (function_exists('yaml_parse')) { + return yaml_parse($rawData); + } $yaml = new Spicy(); return $yaml->loadString($rawData); } From 4c760a75f08611c31bccf864a8ff9f8033786f46 Mon Sep 17 00:00:00 2001 From: "Kamshory, MT" Date: Sat, 28 Feb 2026 13:08:48 +0700 Subject: [PATCH 2/2] Bug fix empty value --- CHANGELOG.md | 25 +++++++++++++++++++++++++ src/Generator/PicoDatabaseDump.php | 9 +++++++++ 2 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad0fce6..7d83f5a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1501,3 +1501,28 @@ $secretConfig->retrieve('database', 'credentials', 'username'); 2. **Improved UUID Implementation** Replaced the legacy unique ID generation based on PHP’s `uniqid()` function with a **real UUID implementation**, ensuring better uniqueness guarantees and compliance with UUID standards. + +# MagicObject Version 3.22.1 + +## Bug Fixes + +1. **Empty Value in Insert Query** + + Fixed a bug when generating `INSERT` queries with empty values. + + Previously, the generated query was: + + ```sql + INSERT INTO any (any1, any2, any3) VALUES (1, , 'any3'); + ``` + + Now it has been corrected to: + + ```sql + INSERT INTO any (any1, any2, any3) VALUES (1, '', 'any3'); + ``` + + This change ensures that empty values are properly handled as empty strings (`''`), resulting in valid SQL syntax and improved compatibility across different databases. + + +With this fix, MagicObject now handles optional or missing fields more reliably during insert operations. diff --git a/src/Generator/PicoDatabaseDump.php b/src/Generator/PicoDatabaseDump.php index 3df87d38..d95511df 100644 --- a/src/Generator/PicoDatabaseDump.php +++ b/src/Generator/PicoDatabaseDump.php @@ -266,6 +266,15 @@ public function fixData($data, $columnInfo, $isPgSql, $isSqlite, $isSqlServer) if ($value === null) { // Handle NULL values $data[$key] = 'null'; + } else if (empty($value)) { + if(isset($columnInfo[$key]) && in_array($columnInfo[$key]->normalizedType, ['string', 'text'])) + { + $data[$key] = "''"; + } + else + { + $data[$key] = 'null'; + } } else if (isset($columnInfo[$key]) && in_array($columnInfo[$key]->normalizedType, ['integer', 'float'])) { // Keep numeric values as they are (no quotes) $data[$key] = $value;