Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
query cache, reconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed Mar 29, 2019
1 parent 40d2d04 commit 17bdcfa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
15 changes: 9 additions & 6 deletions src/Driver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ abstract class Driver implements DriverInterface, LoggerAwareInterface
// DateTime format to be used to perform automatic conversion of DateTime objects.
protected const DATETIME = 'Y-m-d H:i:s';

// Driver specific PDO options
protected const DEFAULT_PDO_OPTIONS = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false
];

/**
* Connection configuration described in DBAL config file. Any driver can be used as data source
* for multiple databases as table prefix and quotation defined on Database instance level.
Expand All @@ -64,11 +71,7 @@ abstract class Driver implements DriverInterface, LoggerAwareInterface
'password' => '',

// pdo options
'options' => [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false
],
'options' => [],
];

/** @var PDO|null */
Expand All @@ -94,7 +97,7 @@ abstract class Driver implements DriverInterface, LoggerAwareInterface
*/
public function __construct(array $options)
{
$options['options'] = $this->options['options'] + ($options['options'] ?? []);
$options['options'] = ($options['options'] ?? []) + static::DEFAULT_PDO_OPTIONS;
$this->options = $options + $this->options;

if (!empty($this->options['profiling'])) {
Expand Down
12 changes: 4 additions & 8 deletions src/Driver/MySQL/MySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
*/
class MySQLDriver extends Driver
{
protected const TYPE = DatabaseInterface::MYSQL;
protected const TABLE_SCHEMA_CLASS = MySQLTable::class;
protected const QUERY_COMPILER = MySQLCompiler::class;

/**
* {@inheritdoc}
*/
protected $pdoOptions = [
protected const TYPE = DatabaseInterface::MYSQL;
protected const TABLE_SCHEMA_CLASS = MySQLTable::class;
protected const QUERY_COMPILER = MySQLCompiler::class;
protected const DEFAULT_PDO_OPTIONS = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "UTF8"',
Expand Down
20 changes: 8 additions & 12 deletions src/Driver/SQLServer/SQLServerDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@

class SQLServerDriver extends Driver
{
protected const TYPE = DatabaseInterface::SQL_SERVER;
protected const TABLE_SCHEMA_CLASS = SQLServerTable::class;
protected const QUERY_COMPILER = SQLServerCompiler::class;
protected const DATETIME = 'Y-m-d\TH:i:s.000';

/**
* @var array
*/
protected $pdoOptions = [
protected const TYPE = DatabaseInterface::SQL_SERVER;
protected const TABLE_SCHEMA_CLASS = SQLServerTable::class;
protected const QUERY_COMPILER = SQLServerCompiler::class;
protected const DATETIME = 'Y-m-d\TH:i:s.000';
protected const DEFAULT_PDO_OPTIONS = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_STRINGIFY_FETCHES => false
Expand Down Expand Up @@ -136,7 +132,7 @@ protected function bindParameters(Statement $statement, array $parameters): Stat
*
* @link http://en.wikipedia.org/wiki/Savepoint
*
* @param int $level Savepoint name/id, must not contain spaces and be valid database
* @param int $level Savepoint name/id, must not contain spaces and be valid database
* identifier.
*/
protected function savepointCreate(int $level)
Expand All @@ -150,7 +146,7 @@ protected function savepointCreate(int $level)
*
* @link http://en.wikipedia.org/wiki/Savepoint
*
* @param int $level Savepoint name/id, must not contain spaces and be valid database
* @param int $level Savepoint name/id, must not contain spaces and be valid database
* identifier.
*/
protected function savepointRelease(int $level)
Expand All @@ -164,7 +160,7 @@ protected function savepointRelease(int $level)
*
* @link http://en.wikipedia.org/wiki/Savepoint
*
* @param int $level Savepoint name/id, must not contain spaces and be valid database
* @param int $level Savepoint name/id, must not contain spaces and be valid database
* identifier.
*/
protected function savepointRollback(int $level)
Expand Down
14 changes: 14 additions & 0 deletions tests/Database/QueryCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types=1);
/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/

namespace Spiral\Database\Tests;

abstract class QueryCacheTest extends BaseTest
{

}

0 comments on commit 17bdcfa

Please sign in to comment.