From 178952572cafd635b32b89b740301dd1f3bb2325 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Tue, 16 Apr 2019 00:53:05 +0200 Subject: [PATCH] Fixed issue #13950: SQL Error when saving a response or getting a session token via API Dev: use onBeforeSave Yii event --- application/models/Session.php | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/application/models/Session.php b/application/models/Session.php index 1d98094be60..b75bee7e688 100644 --- a/application/models/Session.php +++ b/application/models/Session.php @@ -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 @@ -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 + } + } }