diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad0fce..7d83f5a 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 3df87d3..d95511d 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; diff --git a/src/Util/PicoYamlUtil.php b/src/Util/PicoYamlUtil.php index e394c87..a14bda9 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); }