Skip to content

Commit

Permalink
Fixed issue #7083: CDbException when using the Show Next / Show Last …
Browse files Browse the repository at this point in the history
…buttons in the response browser using tokens and MSSQL
  • Loading branch information
c-schmitz committed Jan 5, 2013
1 parent 54ed759 commit 8acdf7c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions application/models/Survey_dynamic.php
Expand Up @@ -170,14 +170,25 @@ public function addTokenCriteria($condition)
{
$newCriteria = new CDbCriteria();
$criteria = $this->getCommandBuilder()->createCriteria($condition);
$aSelectFields=Yii::app()->db->schema->getTable('{{survey_' . self::$sid . '}}')->getColumnNames();
$aSelectFields=array_diff($aSelectFields, array('token'));
$aSelect=array();
foreach($aSelectFields as $sField)
$aSelect[]='t.'.Yii::app()->db->schema->quoteColumnName($sField);
$aSelectFields=$aSelect;
$aSelectFields[]='t.token';

if ($criteria->select == '*')
{
$criteria->select = 't.*';
$criteria->select = $aSelectFields;
}

$newCriteria->join = "LEFT JOIN {{tokens_" . self::$sid . "}} tokens ON t.token = tokens.token";
$newCriteria->select = 'tokens.*'; // Otherwise we don't get records from the token table

$aTokenFields=Yii::app()->db->schema->getTable('{{tokens_' . self::$sid . '}}')->getColumnNames();
$aTokenFields=array_diff($aTokenFields, array('token'));

$newCriteria->select = $aTokenFields; // Otherwise we don't get records from the token table
$newCriteria->mergeWith($criteria);

return $newCriteria;
Expand Down

0 comments on commit 8acdf7c

Please sign in to comment.