<commit_before><?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

namespace Zend\Db\Adapter\Driver\Sqlsrv;

use Zend\Db\Adapter\Driver\ConnectionInterface;

/**
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Connection implements ConnectionInterface
{
    /**
     * @var Sqlsrv
     */
    protected $driver = null;

    /**
     * @var array
     */
    protected $connectionParameters = array();
    
    /**
     * @var resource
     */
    protected $resource = null;

    /**
     * @var bool
     */
    protected $inTransaction = false;
    
    /**
     * Constructor
     * 
     * @param mixed $connectionInfo 
     */
    public function __construct($connectionInfo)
    {
        if (is_array($connectionInfo)) {
            $this->setConnectionParameters($connectionInfo);
        } elseif (is_resource($connectionInfo)) {
            $this->setResource($connectionInfo);
        }
    }
    /**
     * Set driver
     * 
     * @param  Sqlsrv $driver
     * @return Connection 
     */
    public function setDriver(Sqlsrv $driver)
    {
        $this->driver = $driver;
        return $this;
    }
    /**
     * Set connection parameters
     * 
     * @param  array $connectionParameters
     * @return Connection 
     */
    public function setConnectionParameters(array $connectionParameters)
    {
        $this->connectionParameters = $connectionParameters;
        return $this;
    }
    /**
     * Get connection parameters
     * 
     * @return array 
     */
    public function getConnectionParameters()
    {
        return $this->connectionParameters;
    }
    /**
     * Get default catalog
     * 
     * @return null 
     */
    public function getDefaultCatalog()
    {
        return null;
    }
    /**
     * Get dafault schema
     * 
     * @return string 
     */
    public function getDefaultSchema()
    {
        if (!$this->isConnected()) {
            $this->connect();
        }

        $result = sqlsrv_query($this->resource, 'SELECT SCHEMA_NAME()');
        $r = sqlsrv_fetch_array($result);
        return $r[0];
    }
    /**
     * Set resource
     * 
     * @param  resource $resource
     * @return Connection 
     */
    public function setResource($resource)
    {
        if (get_resource_type($resource) !== 'SQL Server Connection') {
            throw new \Exception('Resource provided was not of type SQL Server Connection');
        }
        $this->resource = $resource;
        return $this;
    }

    /**
     * @return resource
     */
    public function getResource()
    {
        return $this->resource;
    }
    /**
     * Connect
     * 
     * @return null 
     */
    public function connect()
    {
        if ($this->resource) {
            return;
        }
        
        $serverName = '.';
        $params = array();
        foreach ($this->connectionParameters as $cpName => $cpValue) {
            switch (strtolower($cpName)) {
                case 'hostname':
                case 'servername':
                    $serverName = $cpValue;
                    break;
                case 'username':
                case 'uid':
                    $params['UID'] = $cpValue;
                    break;
                case 'password':
                case '<PASSWORD>':
                    $params['PWD'] = $cpValue;
                    break;
                case 'database':
                case 'dbname':
                    $params['Database'] = $cpValue;
                    break;
            }
        }

        $this->resource = sqlsrv_connect($serverName, $params);

        if (!$this->resource) {
            $prevErrorException = new ErrorException(sqlsrv_errors());
            throw new \Exception('Connect Error', null, $prevErrorException);
        }

    }
    /**
     * Is connected
     * 
     * @return boolean 
     */
    public function isConnected()
    {
        return (is_resource($this->resource));
    }
    /**
     * Disconnect
     * 
     */
    public function disconnect()
    {
        sqlsrv_close($this->resource);
        unset($this->resource);
    }
    <commit_msg>Make Sqlsrv detection of configuration parameters consistent with the same code for Pdo<commit_after><?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

namespace Zend\Db\Adapter\Driver\Sqlsrv;

use Zend\Db\Adapter\Driver\ConnectionInterface;

/**
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Connection implements ConnectionInterface
{
    /**
     * @var Sqlsrv
     */
    protected $driver = null;

    /**
     * @var array
     */
    protected $connectionParameters = array();
    
    /**
     * @var resource
     */
    protected $resource = null;

    /**
     * @var bool
     */
    protected $inTransaction = false;
    
    /**
     * Constructor
     * 
     * @param mixed $connectionInfo 
     */
    public function __construct($connectionInfo)
    {
        if (is_array($connectionInfo)) {
            $this->setConnectionParameters($connectionInfo);
        } elseif (is_resource($connectionInfo)) {
            $this->setResource($connectionInfo);
        }
    }
    /**
     * Set driver
     * 
     * @param  Sqlsrv $driver
     * @return Connection 
     */
    public function setDriver(Sqlsrv $driver)
    {
        $this->driver = $driver;
        return $this;
    }
    /**
     * Set connection parameters
     * 
     * @param  array $connectionParameters
     * @return Connection 
     */
    public function setConnectionParameters(array $connectionParameters)
    {
        $this->connectionParameters = $connectionParameters;
        return $this;
    }
    /**
     * Get connection parameters
     * 
     * @return array 
     */
    public function getConnectionParameters()
    {
        return $this->connectionParameters;
    }
    /**
     * Get default catalog
     * 
     * @return null 
     */
    public function getDefaultCatalog()
    {
        return null;
    }
    /**
     * Get dafault schema
     * 
     * @return string 
     */
    public function getDefaultSchema()
    {
        if (!$this->isConnected()) {
            $this->connect();
        }

        $result = sqlsrv_query($this->resource, 'SELECT SCHEMA_NAME()');
        $r = sqlsrv_fetch_array($result);
        return $r[0];
    }
    /**
     * Set resource
     * 
     * @param  resource $resource
     * @return Connection 
     */
    public function setResource($resource)
    {
        if (get_resource_type($resource) !== 'SQL Server Connection') {
            throw new \Exception('Resource provided was not of type SQL Server Connection');
        }
        $this->resource = $resource;
        return $this;
    }

    /**
     * @return resource
     */
    public function getResource()
    {
        return $this->resource;
    }
    /**
     * Connect
     * 
     * @return null 
     */
    public function connect()
    {
        if ($this->resource) {
            return;
        }
        
        $serverName = '.';
        $params = array();
        foreach ($this->connectionParameters as $key => $value) {
            switch (strtolower($key)) {
                case 'hostname':
                case 'servername':
                    $serverName = (string) $value;
                    break;
                case 'username':
                case 'uid':
                    $params['UID'] = (string) $value;
                    break;
                case 'password':
                case '<PASSWORD>':
                    $params['PWD'] = (string) $value;
                    break;
                case 'database':
                case 'dbname':
                    $params['Database'] = (string) $value;
                    break;
            }
        }

        $this->resource = sqlsrv_connect($serverName, $params);

        if (!$this->resource) {
            $prevErrorException = new ErrorException(sqlsrv_errors());
            throw new \Exception('Connect Error', null, $prevErrorException);
        }

    }
    /**
     * Is connected
     * 
     * @return boolean 
     */
    public function isConnected()
    {
        return (is_resource($this->resource));
    }
    /**
     * Disconnect
     * 
     */
    public function disconnect()
    {
        sqlsrv_close($this->resource);
        unset($this->resource);
    }
    
{'fraction_non_alphanumeric': 0.116596427854706, 'fraction_numerical': 0.0034115994380895043, 'mean_word_length': 1.7510350538227988, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '974531', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2703, 'n_words': 680}