Skip to content

Commit

Permalink
intersvyaz/pdo-oc8 lob support
Browse files Browse the repository at this point in the history
  • Loading branch information
kikimor committed Mar 13, 2015
1 parent 5aa5380 commit 4ff1015
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
54 changes: 41 additions & 13 deletions DbHttpSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use CDbHttpSession;
use Exception;
use PDO;
use Intersvyaz\Pdo\Oci8;

class DbHttpSession extends CDbHttpSession
{
Expand Down Expand Up @@ -47,11 +48,14 @@ public function regenerateID($deleteOldSession = false)
->bindValue(':oldID', $oldID)
->execute();
} else {
$fp = fopen('php://memory', "rwb");
$transaction = $db->beginTransaction();

fwrite($fp, stream_get_contents($row['DATA']));
fseek($fp, 0);
if ($this->isOci8Driver()) {
$fp = $row['DATA'];
} else {
$fp = fopen('php://memory', "rwb");
fwrite($fp, stream_get_contents($row['DATA']));
fseek($fp, 0);
$transaction = $db->beginTransaction();
}

$db->createCommand("INSERT INTO {$this->sessionTableName} (id, expire,data)
VALUES (:id, :expire, empty_blob()) returning data into :data")
Expand All @@ -60,8 +64,10 @@ public function regenerateID($deleteOldSession = false)
->bindParam(':data', $fp, PDO::PARAM_LOB)
->execute();

$transaction->commit();
fclose($fp);
if (!$this->isOci8Driver()) {
$transaction->commit();
fclose($fp);
}
}
} else {
// shouldn't reach here normally
Expand Down Expand Up @@ -100,6 +106,11 @@ public function readSession($id)
->bindValue(':id', $id)
->bindValue(':expire', time())
->queryRow();

if ($this->isOci8Driver()) {
return $data['DATA'];
}

return $data === false ? '' : stream_get_contents($data['DATA']);
}

Expand All @@ -122,17 +133,25 @@ public function writeSession($id, $data)
WHERE id=:id returning data into :data";
}

$fp = fopen('php://memory', "rwb");
$transaction = $db->beginTransaction();
fwrite($fp, $data);
fseek($fp, 0);
if ($this->isOci8Driver()) {
$fp = $data;
} else {
$fp = fopen('php://memory', "rwb");
fwrite($fp, $data);
fseek($fp, 0);
$transaction = $db->beginTransaction();
}

$db->createCommand($sql)
->bindValue(':id', $id)
->bindValue(':expire', $expire)
->bindParam(':data', $fp, PDO::PARAM_LOB)
->execute();
$transaction->commit();
fclose($fp);

if (!$this->isOci8Driver()) {
$transaction->commit();
fclose($fp);
}
} catch (Exception $e) {
if (YII_DEBUG) {
echo $e->getMessage();
Expand All @@ -142,4 +161,13 @@ public function writeSession($id, $data)
}
return true;
}

/**
* @return bool
* @throws \CDbException
*/
protected function isOci8Driver()
{
return $this->getDbConnection()->pdoClass == Oci8::class;
}
}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
Yii httpsession extension by using PDOOCI as session data storage.

### 2.0.0. ###
Starting with v2.0.0 requires [intersvyaz/laravel-pdo-via-oci8](https://github.com/intersvyaz/laravel-pdo-via-oci8). Configure connection:

```php
'oracleMainDb' => [
'class' => CDbConnection::class,
'connectionString' => 'oci:dbname=DATABASE',
...
'pdoClass' => Intersvyaz\Pdo\Oci8::class,
```
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"require": {
"php": ">=5.4.0",
"yiisoft/yii" : "~1.1.15"
"yiisoft/yii" : "~1.1.15",
"intersvyaz/pdo-oci8": "~1.0.0"
},
"require-dev":{
"phpunit/phpunit": "~4.3",
Expand All @@ -21,6 +22,10 @@
{
"name": "Rustam Gumerov",
"email": "psrustik@gmail.com"
},
{
"name": "kikimor",
"email": "i@kikimor.ru"
}
]
}

0 comments on commit 4ff1015

Please sign in to comment.