Skip to content

Commit c4d1a37

Browse files
authored
Merge pull request #186 from Planetbiru/feature/version-3.23.1
Feature/version 3.23.1
2 parents d26c156 + 4c760a7 commit c4d1a37

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,3 +1501,28 @@ $secretConfig->retrieve('database', 'credentials', 'username');
15011501
2. **Improved UUID Implementation**
15021502
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.
15031503

1504+
1505+
# MagicObject Version 3.22.1
1506+
1507+
## Bug Fixes
1508+
1509+
1. **Empty Value in Insert Query**
1510+
1511+
Fixed a bug when generating `INSERT` queries with empty values.
1512+
1513+
Previously, the generated query was:
1514+
1515+
```sql
1516+
INSERT INTO any (any1, any2, any3) VALUES (1, , 'any3');
1517+
```
1518+
1519+
Now it has been corrected to:
1520+
1521+
```sql
1522+
INSERT INTO any (any1, any2, any3) VALUES (1, '', 'any3');
1523+
```
1524+
1525+
This change ensures that empty values are properly handled as empty strings (`''`), resulting in valid SQL syntax and improved compatibility across different databases.
1526+
1527+
1528+
With this fix, MagicObject now handles optional or missing fields more reliably during insert operations.

src/Generator/PicoDatabaseDump.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ public function fixData($data, $columnInfo, $isPgSql, $isSqlite, $isSqlServer)
266266
if ($value === null) {
267267
// Handle NULL values
268268
$data[$key] = 'null';
269+
} else if (empty($value)) {
270+
if(isset($columnInfo[$key]) && in_array($columnInfo[$key]->normalizedType, ['string', 'text']))
271+
{
272+
$data[$key] = "''";
273+
}
274+
else
275+
{
276+
$data[$key] = 'null';
277+
}
269278
} else if (isset($columnInfo[$key]) && in_array($columnInfo[$key]->normalizedType, ['integer', 'float'])) {
270279
// Keep numeric values as they are (no quotes)
271280
$data[$key] = $value;

src/Util/PicoYamlUtil.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public static function arrayDepth($array) {
8989
*/
9090
public static function dump($input, $inline, $indent, $flags) // NOSONAR
9191
{
92+
if (function_exists('yaml_emit')) {
93+
return yaml_emit($input, YAML_UTF8_ENCODING);
94+
}
9295
if($inline == null || $inline < 0)
9396
{
9497
$inline = self::arrayDepth($input);
@@ -111,6 +114,9 @@ public static function dump($input, $inline, $indent, $flags) // NOSONAR
111114
*/
112115
public static function parseFile($file)
113116
{
117+
if (function_exists('yaml_parse_file')) {
118+
return yaml_parse_file($file);
119+
}
114120
$yaml = new Spicy();
115121
return $yaml->loadFile($file);
116122
}
@@ -128,6 +134,9 @@ public static function parseFile($file)
128134
*/
129135
public static function parse($rawData)
130136
{
137+
if (function_exists('yaml_parse')) {
138+
return yaml_parse($rawData);
139+
}
131140
$yaml = new Spicy();
132141
return $yaml->loadString($rawData);
133142
}

0 commit comments

Comments
 (0)