Skip to content

Commit

Permalink
Fixed issue #09847: Non integer numerical input is saved as rounded i…
Browse files Browse the repository at this point in the history
…nteger to the database

Dev: decimal(30,10) is found at DECIMAL for Yii, no params
Dev: Same for PGsql
Dev: @todo : test with MsSQL
Dev: fix childrens too
Dev: @SamMousa : please do some test ;)
  • Loading branch information
Shnoulle committed Sep 1, 2015
1 parent e14cda4 commit 3b16afc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions application/core/db/PgsqlSchema.php
Expand Up @@ -10,8 +10,8 @@ public function __construct($conn) {
* Auto increment.
*/
$this->columnTypes['autoincrement'] = 'serial';

$this->columnTypes['longbinary'] = 'bytea';
$this->columnTypes['decimal'] = 'numeric (10,0)'; // Same default than MySql (not used)
}

public function createDatabase($name) {
Expand All @@ -22,4 +22,4 @@ public function createDatabase($name) {
}
return true;
}
}
}
33 changes: 21 additions & 12 deletions application/core/db/SmartColumnTypeTrait.php
Expand Up @@ -3,21 +3,30 @@
trait SmartColumnTypeTrait {
/**
* Adds support for replacing default arguments.
* @param type $type
* @param string $type
* @return string
*/
public function getColumnType($type)
{
$sResult=$type;
if (isset($this->columnTypes[$type])) {
$sResult=$this->columnTypes[$type];
} elseif (preg_match('/^(\w+)\((.+?)\)(.*)$/', $type, $matches)) {
if (isset($this->columnTypes[$matches[1]])) {
$sResult=preg_replace('/\(.+\)/', '(' . $matches[2] . ')', $this->columnTypes[$matches[1]]) . $matches[3];
if (isset(Yii::app()->db->schema->columnTypes[$type]))
{ // Direct : get it
$sResult=Yii::app()->db->schema->columnTypes[$type];
}
elseif (preg_match('/^([a-zA-Z ]+)\((.+?)\)(.*)$/', $type, $matches))
{ // With params : some test to do
$baseType = $this->getColumnType($matches[1]);
if(preg_match('/^([a-zA-Z ]+)\((.+?)\)(.*)$/', $baseType, $baseMatches))
{ // Replace the default Yii param
$sResult=preg_replace('/\(.+\)/', "(".$matches[2].")",parent::getColumnType($matches[1]." ".$matches[3]));
}
} elseif (preg_match('/^(\w+)\s+/', $type, $matches)) {
if (isset($this->columnTypes[$matches[1]])) {
$sResult=preg_replace('/^\w+/', $this->columnTypes[$matches[1]], $type);
else
{ // Get the base type and join
$sResult=join(" ",array($baseType,"(".$matches[2].")",$matches[3]));
}
}
return $sResult; }
}
else
{
$sResult = $this->getColumnType($type);
}
return $sResult;
}

1 comment on commit 3b16afc

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test code for 3.0 : http://pastebin.com/xKGMFcS5

Please sign in to comment.