/**
  * Returns the static model of ParticipantAttributeNames table
  *
  * @static
  * @access public
  * @param string $class
  * @return ParticipantAttributeNames
  */
 public static function model($class = __CLASS__)
 {
     $model = parent::model($class);
     $keys = $model->tableSchema->primaryKey;
     if (is_array($keys) && count($keys) == 2) {
         // Fix the primary key, needed for PgSQL http://bugs.limesurvey.org/view.php?id=6707
         // First load the helper
         Yii::app()->loadHelper('update/updatedb');
         $dbType = setsDBDriverName();
         setVarchar($dbType);
         $table = 'participant_attribute_names';
         if ($dbType == 'mysql') {
             // Only for mysql first remove auto increment
             alterColumn($model->tableName(), $model->primaryKey(), $model->tableSchema->getColumn($model->primaryKey())->dbType, false);
         }
         dropPrimaryKey($table);
         addPrimaryKey($table, (array) $model->primaryKey());
         if ($dbType == 'mysql') {
             // Add back auto increment
             alterColumn($model->tableName(), $model->primaryKey(), Yii::app()->getConfig('autoincrement'));
         }
         // Refresh all schema data now just to make sure
         Yii::app()->db->schema->refresh();
         $model->refreshMetaData();
     }
     return $model;
 }
예제 #2
0
/**
* Special customisation because Yii is limited in its ability to handle varchar fields of lenghts other than 255 in a cross-db
* compatible way. see http://www.yiiframework.com/forum/index.php/topic/32289-cross-db-compatible-varchar-field-length-definitions/
* and http://github.com/yiisoft/yii/issues/765
*
* Note that it sets values for the config files for use later, and does not return any values.
* Access the set values using Yii::app()->getConfig('varchar') or Yii::app()->getConfigu('autoincrement');
*
* @param mixed $sDBDriverName The name of the db driver being used. If the parameter is forgotten, the
*                             function is capable of retrieving it itself.
*/
function setVarchar($sDBDriverName = null)
{
    if (!$sDBDriverName) {
        $sDBDriverName = setsDBDriverName();
    }
    if ($sDBDriverName == 'pgsql') {
        Yii::app()->setConfig('varchar', $sVarchar = 'character varying');
        Yii::app()->setConfig('autoincrement', $sAutoIncrement = 'serial');
    } elseif ($sDBDriverName == 'mssql') {
        Yii::app()->setConfig('varchar', $sVarchar = 'varchar');
        Yii::app()->setConfig('autoincrement', $sAutoIncrement = 'integer NOT NULL IDENTITY (1,1)');
    } else {
        Yii::app()->setConfig('varchar', $sVarchar = 'varchar');
        Yii::app()->setConfig('autoincrement', $sAutoIncrement = 'int(11) NOT NULL AUTO_INCREMENT');
    }
}