Commit 05c4d3fb authored by Andreas Pohl's avatar Andreas Pohl Committed by Steve Müller

Corrected PR for persistent SQLAny-Connections

* removed "charset" patch
* implemeted resource_type compare with in_array instead of regex
* implemented functional tests for connection and statement.
parent da64aff6
......@@ -48,9 +48,16 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/
public function __construct($dsn, $persistent = false)
{
$allowedResourceTypes = array(
'SQLAnywhere connection'
,'SQLAnywhere persistent connection ' //note the blank!
);
$this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn);
if ( ! is_resource($this->connection) || !preg_match('/^SQLAnywhere.*connection.*/',get_resource_type($this->connection)) ) {
$resourceType = get_resource_type($this->connection);
if ( ! is_resource($this->connection) || !in_array($resourceType, $allowedResourceTypes, true)) {
throw SQLAnywhereException::fromSQLAnywhereError();
}
......
......@@ -74,7 +74,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function __construct($conn, $sql)
{
if ( ! is_resource($conn) || !preg_match('/^SQLAnywhere.*connection.*/',get_resource_type($conn))) {
$allowedResourceTypes = array(
'SQLAnywhere connection'
,'SQLAnywhere persistent connection ' //note the blank!
);
$resourceType = get_resource_type($conn);
if ( ! is_resource($conn) || !in_array($resourceType, $allowedResourceTypes, true)) {
throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn);
}
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Driver\SQLAnywhere;
use Doctrine\DBAL\DriverManager;
class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
protected function setUp()
{
if (!extension_loaded('sqlanywhere')) {
$this->markTestSkipped('sqlanywhere is not installed.');
}
parent::setUp();
if ( !($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\SQLAnywhere\Driver)) {
$this->markTestSkipped('sqlanywhere only test.');
}
}
protected function tearDown()
{
parent::tearDown();
}
public function testNonPersistentConnection()
{
$params = $this->_conn->getParams();
$params['persistent'] = false;
$conn = DriverManager::getConnection($params);
$conn->connect();
$this->assertTrue($conn->isConnected(), 'No SQLAnywhere-nonpersistent connection established');
}
public function testPersistentConnection()
{
$params = $this->_conn->getParams();
$params['persistent'] = true;
$conn = DriverManager::getConnection($params);
$conn->connect();
$this->assertTrue($conn->isConnected(), 'No SQLAnywhere-persistent connection established');
}
}
<?php
namespace Doctrine\Tests\DBAL\Functional\Driver\SQLAnywhere;
use Doctrine\DBAL\DriverManager;
class StatementTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
protected function setUp()
{
if (!extension_loaded('sqlanywhere')) {
$this->markTestSkipped('sqlanywhere is not installed.');
}
parent::setUp();
if ( !($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\SQLAnywhere\Driver)) {
$this->markTestSkipped('sqlanywhere only test.');
}
}
protected function tearDown()
{
parent::tearDown();
}
public function testNonPersistentStatement()
{
$params = $this->_conn->getParams();
$params['persistent'] = false;
$conn = DriverManager::getConnection($params);
$conn->connect();
$this->assertTrue($conn->isConnected(),'No SQLAnywhere-Connection established');
$prepStmt = $conn->prepare('SELECT 1');
$this->assertTrue($prepStmt->execute(),' Statement non-persistent failed');
}
public function testPersistentStatement()
{
$params = $this->_conn->getParams();
$params['persistent'] = true;
$conn = DriverManager::getConnection($params);
$conn->connect();
$this->assertTrue($conn->isConnected(),'No SQLAnywhere-Connection established');
$prepStmt = $conn->prepare('SELECT 1');
$this->assertTrue($prepStmt->execute(),' Statement persistent failed');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment