Skip to content

Commit

Permalink
fixed bug, where empty array for DynamicActiveRecord::dynColSqlMaria(…
Browse files Browse the repository at this point in the history
…) creates invlid COLUMN_CREATE command
  • Loading branch information
danil zakablukovskii committed Jun 7, 2015
1 parent df64ce2 commit 5b70ba1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
## 0.2.0 June 6 2015

- Enh: New attribute name getter method DynamicActiveRecord::allAttributes()

## 0.2.1 June 8 2015

- Bug: Empty array in DynamicActiveRecord::dynColSqlMaria() creates invalid COLUMN_CREATE() command
16 changes: 10 additions & 6 deletions DynamicActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,31 @@ public static function find()
* @return string SQL for a DB Expression
* @throws \yii\base\Exception
*/
private static function dynColSqlMaria($attrs, & $params)
private static function dynColSqlMaria(array $attrs, & $params)
{
$sql = [];
foreach ($attrs as $key => $value) {
if (!is_scalar($value) && empty($value)) {
if (is_object($value)) {
$value = (array)$value;
}
if ($value === [] || $value === null) {
continue;
}

$phKey = static::placeholder();
$phValue = static::placeholder();
$sql[] = $phKey;
$params[$phKey] = $key;
if (is_scalar($value) || $value === null) {

if (is_scalar($value)) {
$sql[] = $phValue;
$params[$phValue] = $value;
} else {
$sql[] = static::dynColSqlMaria((array) $value, $params);
} elseif (is_array($value)) {
$sql[] = static::dynColSqlMaria($value, $params);
}
}

return 'COLUMN_CREATE(' . implode(',', $sql) . ')';
return $sql === [] ? 'null' : 'COLUMN_CREATE(' . implode(',', $sql) . ')';
}

/**
Expand Down

0 comments on commit 5b70ba1

Please sign in to comment.