Skip to content

Commit

Permalink
Fixed issue #13950: SQL Error when saving a response or getting a ses…
Browse files Browse the repository at this point in the history
…sion token via API

Dev: use onBeforeSave Yii event
  • Loading branch information
Shnoulle committed Apr 15, 2019
1 parent 03be0b6 commit 1789525
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion application/models/Session.php
Expand Up @@ -17,13 +17,22 @@

/**
* Class Session
*
* Extend CActiveRecord and not LSActiveRecord to disable plugin event (session can be used a lot)
*
* @property string $id Primary Key
* @property integer $expire
* @property string $data
*/
class Session extends CActiveRecord
{

/**
* @inheritdoc
*/
public function init()
{
$this->attachEventHandler("onBeforeSave", array($this, 'fixDataType'));
}
/**
* @inheritdoc
* @return Session
Expand Down Expand Up @@ -71,4 +80,28 @@ private function hexToStr($hex)
return $string;
}

/**
* Update data before saving
* @see \CDbHttpSession
* @return void
*/
public function fixDataType()
{
$db = $this->getDbConnection();
$dbType = $db->getDriverName();
switch($dbType) {
case 'sqlsrv':
case 'mssql':
case 'dblib':
$this->data=new CDbExpression('CONVERT(VARBINARY(MAX), '.$db->quoteValue($this->data).')');
break;
case 'pgsql':
$this->data=new CDbExpression($db->quoteValueWithType($this->data, PDO::PARAM_LOB)."::bytea");
break;
case 'mysql':
// Don't seems to need something
default:
// No update
}
}
}

0 comments on commit 1789525

Please sign in to comment.