Skip to content

Commit

Permalink
Merge pull request #49 from mobbexco/added-column-value-validation-EC…
Browse files Browse the repository at this point in the history
…O-1101

[ECO-1101] Added column value validation
  • Loading branch information
jlmobbex authored Dec 3, 2024
2 parents cfe92fb + b1736a8 commit c5b4b5f
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Model/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,12 @@ public function getColumn($name)
public function getColumns()
{
$columns = $this->db->query("SHOW COLUMNS FROM $this->table;") ?: [];

// Sort current db colums by keys (do not use array_walk)
foreach ($columns as &$column) {
foreach ($columns as &$column){
ksort($column);

if ($column['Default'] === 'CURRENT_TIMESTAMP')
$column['Default'] = 'current_timestamp()';
$column = $this->validateValue($column);
}

return $columns ?: [];
}

Expand Down Expand Up @@ -277,4 +274,25 @@ public function changeCharset()
($column['Null'] == 'NO' ? 'NOT NULL;' : ';')
);
}

/**
* Validates the value of a column.
*
* @param array $column Column definition array.
*
* @return array The normalized column definition.
*/
public function validateValue($column){

if ($column['Default'] === 'CURRENT_TIMESTAMP')
$column['Default'] = 'current_timestamp()';

if ($column['Extra'] === 'DEFAULT_GENERATED')
$column['Extra'] = '';

if ($column['Type'] === 'int')
$column['Type'] = 'int(11)';

return $column;
}
}

0 comments on commit c5b4b5f

Please sign in to comment.