Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:LimeSurvey/LimeSurvey into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Sep 1, 2015
2 parents 8681f52 + 3b16afc commit f57baee
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;
}

0 comments on commit f57baee

Please sign in to comment.