Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 9 additions & 0 deletions src/Generator/PicoDatabaseDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/Util/PicoYamlUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down