Commit dc871b00 authored by Steve Müller's avatar Steve Müller Committed by GitHub

Merge pull request #2405 from andipohl/master

SQLAnywhere corrections for DSN generation and persistent connections
parents 0bd7781a 02e5607c
......@@ -50,7 +50,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
{
$this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn);
if ( ! is_resource($this->connection) || get_resource_type($this->connection) !== 'SQLAnywhere connection') {
if ( ! is_resource($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError();
}
......
......@@ -42,11 +42,11 @@ class SQLAnywhereException extends AbstractDriverException
*/
public static function fromSQLAnywhereError($conn = null, $stmt = null)
{
if (null !== $conn && ! (is_resource($conn) && get_resource_type($conn) === 'SQLAnywhere connection')) {
if (null !== $conn && ! (is_resource($conn))) {
throw new \InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn);
}
if (null !== $stmt && ! (is_resource($stmt) && get_resource_type($stmt) === 'SQLAnywhere statement')) {
if (null !== $stmt && ! (is_resource($stmt))) {
throw new \InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt);
}
......
......@@ -74,14 +74,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function __construct($conn, $sql)
{
if ( ! is_resource($conn) || get_resource_type($conn) !== 'SQLAnywhere connection') {
if ( ! is_resource($conn)) {
throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn);
}
$this->conn = $conn;
$this->stmt = sasql_prepare($conn, $sql);
if ( ! is_resource($this->stmt) || get_resource_type($this->stmt) !== 'SQLAnywhere statement') {
if ( ! is_resource($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($conn);
}
}
......@@ -195,7 +195,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function fetch($fetchMode = null)
{
if ( ! is_resource($this->result) || get_resource_type($this->result) !== 'SQLAnywhere result') {
if ( ! is_resource($this->result)) {
return false;
}
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Driver\SQLAnywhere;
use Doctrine\DBAL\DriverManager;
class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
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
{
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