<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-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * @see Zend_Db_Adapter_Abstract
 */
require_once 'Zend/Db/Adapter/Abstract.php';

/**
 * @see Zend_Db_Statement_Sqlsrv
 */
require_once 'Zend/Db/Statement/Sqlsrv.php';

/**
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
{
    /**
     * User-provided configuration.
     *
     * Basic keys are:
     *
     * username => (string) Connect to the database as this username.
     * password => (string) Password associated with the username.
     * dbname   => The name of the local SQL Server instance
     *
     * @var array
     */
    protected $_config = array(
        'dbname'       => null,
        'username'     => null,
        'password'     => <PASSWORD>,
    );

    /**
     * Last insert id from INSERT query
     *
     * @var int
     */
    protected $_lastInsertId;

    /**
     * Query used to fetch last insert id
     *
     * @var string
     */
    protected $_lastInsertSQL = 'SELECT SCOPE_IDENTITY() as Current_Identity';

    /**
     * Keys are UPPERCASE SQL datatypes or the constants
     * Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
     *
     * Values are:
     * 0 = 32-bit integer
     * 1 = 64-bit integer
     * 2 = float or decimal
     *
     * @var array Associative array of datatypes to values 0, 1, or 2.
     */
    protected $_numericDataTypes = array(
        Zend_Db::INT_TYPE    => Zend_Db::INT_TYPE,
        Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
        Zend_Db::FLOAT_TYPE  => Zend_Db::FLOAT_TYPE,
        'INT'                => Zend_Db::INT_TYPE,
        'SMALLINT'           => Zend_Db::INT_TYPE,
        'TINYINT'            => Zend_Db::INT_TYPE,
        'BIGINT'             => Zend_Db::BIGINT_TYPE,
        'DECIMAL'            => Zend_Db::FLOAT_TYPE,
        'FLOAT'              => Zend_Db::FLOAT_TYPE,
        'MONEY'              => Zend_Db::FLOAT_TYPE,
        'NUMERIC'            => Zend_Db::FLOAT_TYPE,
        'REAL'               => Zend_Db::FLOAT_TYPE,
        'SMALLMONEY'         => Zend_Db::FLOAT_TYPE,
    );

    /**
     * Default class name for a DB statement.
     *
     * @var string
     */
    protected $_defaultStmtClass = 'Zend_Db_Statement_Sqlsrv';

    /**
     * Creates a connection resource.
     *
     * @return void
     * @throws Zend_Db_Adapter_Sqlsrv_Exception
     */
    protected function _connect()
    {
        if (is_resource($this->_connection)) {
            // connection already exists
            return;
        }

        if (!extension_loaded('sqlsrv')) {
            /**
             * @see Zend_Db_Adapter_Sqlsrv_Exception
             */
            require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
            throw new Zend_Db_Adapter_Sqlsrv_Exception('The Sqlsrv extension is required for this adapter but the extension is not loaded');
        }

        $serverName = $this->_config['host'];
        if (isset($this->_config['port'])) {
            $port        = (integer) $this->_config['port'];
            $serverName .= ', ' . $port;
        }

        $connectionInfo = array(
            'Database' => $this->_config['dbname'],
            'UID'      => $this->_config['username'],
            'PWD'      => $this->_config['password'],
        );

        if (!empty($this->_config['driver_options'])) {
            foreach ($this->_config['driver_options'] as $option => $value) {
                // A value may be a constant.
                if (is_string($value)) {
                    $constantValue = @constant(strtoupper($value));
                    if ($constantValue === null) {
                        $connectionInfo[$option] = $value;
                    } else {
                        $connectionInfo[$option] = $constantValue;
                    }
                }
            }
        }

        $this->_connection = sqlsrv_connect($serverName, $connectionInfo);

        if (!$this->_connection) {
            /**
             * @see Zend_Db_Adapter_Sqlsrv_Exception
             */
            require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
            throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
        }

        sqlsrv_query($this->_connection, 'SET QUOTED_IDENTIFIER ON');<commit_msg>ZF-7514 - Add support for Windows authentication <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-2009 Zend Technologies USA Inc. (http://www.zend.<EMAIL>)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * @see Zend_Db_Adapter_Abstract
 */
require_once 'Zend/Db/Adapter/Abstract.php';

/**
 * @see Zend_Db_Statement_Sqlsrv
 */
require_once 'Zend/Db/Statement/Sqlsrv.php';

/**
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
{
    /**
     * User-provided configuration.
     *
     * Basic keys are:
     *
     * username => (string) Connect to the database as this username.
     * password => (string) Password associated with the username.
     * dbname   => The name of the local SQL Server instance
     *
     * @var array
     */
    protected $_config = array(
        'dbname'       => null,
        'username'     => null,
        'password'     => <PASSWORD>,
    );

    /**
     * Last insert id from INSERT query
     *
     * @var int
     */
    protected $_lastInsertId;

    /**
     * Query used to fetch last insert id
     *
     * @var string
     */
    protected $_lastInsertSQL = 'SELECT SCOPE_IDENTITY() as Current_Identity';

    /**
     * Keys are UPPERCASE SQL datatypes or the constants
     * Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
     *
     * Values are:
     * 0 = 32-bit integer
     * 1 = 64-bit integer
     * 2 = float or decimal
     *
     * @var array Associative array of datatypes to values 0, 1, or 2.
     */
    protected $_numericDataTypes = array(
        Zend_Db::INT_TYPE    => Zend_Db::INT_TYPE,
        Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
        Zend_Db::FLOAT_TYPE  => Zend_Db::FLOAT_TYPE,
        'INT'                => Zend_Db::INT_TYPE,
        'SMALLINT'           => Zend_Db::INT_TYPE,
        'TINYINT'            => Zend_Db::INT_TYPE,
        'BIGINT'             => Zend_Db::BIGINT_TYPE,
        'DECIMAL'            => Zend_Db::FLOAT_TYPE,
        'FLOAT'              => Zend_Db::FLOAT_TYPE,
        'MONEY'              => Zend_Db::FLOAT_TYPE,
        'NUMERIC'            => Zend_Db::FLOAT_TYPE,
        'REAL'               => Zend_Db::FLOAT_TYPE,
        'SMALLMONEY'         => Zend_Db::FLOAT_TYPE,
    );

    /**
     * Default class name for a DB statement.
     *
     * @var string
     */
    protected $_defaultStmtClass = 'Zend_Db_Statement_Sqlsrv';

    /**
     * Creates a connection resource.
     *
     * @return void
     * @throws Zend_Db_Adapter_Sqlsrv_Exception
     */
    protected function _connect()
    {
        if (is_resource($this->_connection)) {
            // connection already exists
            return;
        }

        if (!extension_loaded('sqlsrv')) {
            /**
             * @see Zend_Db_Adapter_Sqlsrv_Exception
             */
            require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
            throw new Zend_Db_Adapter_Sqlsrv_Exception('The Sqlsrv extension is required for this adapter but the extension is not loaded');
        }

        $serverName = $this->_config['host'];
        if (isset($this->_config['port'])) {
            $port        = (integer) $this->_config['port'];
            $serverName .= ', ' . $port;
        }

        $connectionInfo = array(
            'Database' => $this->_config['dbname'],
        );
		
		if (isset($this->_config['username']) && isset($this->_config['password']))
		{
			$connectionInfo += array(
				'UID'      => $this->_config['username'],
				'PWD'      => $this->_config['password'],
			);
		}
		// else - windows authentication
			
        if (!empty($this->_config['driver_options'])) {
            foreach ($this->_config['driver_options'] as $option => $value) {
                // A value may be a constant.
                if (is_string($value)) {
                    $constantValue = @constant(strtoupper($value));
                    if ($constantValue === null) {
                        $connectionInfo[$option] = $value;
                    } else {
                        $connectionInfo[$option] = $constantValue;
                    }
                }
            }
        }

        $this->_connection = sqlsrv_connect($serverName, $connectionInfo);

        if (!$this->_connection) {
            /**
             * @see Zend_Db_Adapter_Sqlsrv_Exception
             */
            require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
            throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
        }
    }
	
	/**
     * Check for config options that are mandatory.
     * Throw exceptions if any are missing.
     *
     * @param array $config
     * @throws Zend_Db_Adapter_Exception
     */
	protected function _checkRequiredOptions(array $config)
    {
        // we need at least a dbname
        if (! array_key_exists('dbname', $config)) {
            /** @see Zend_Db_Adapter_Exception */
            require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'dbname' that names the database instance");
        }

        if (! array_key_exists('password', $config) && array_key_exists('username', $config)) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'password' for login credentials.
												If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
        }

        if (array_key_exists('password', $config) && !array_key_exists('username', $config)) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'username' for login credentials.
												If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
        }
{'fraction_non_alphanumeric': 0.11736736736736737, 'fraction_numerical': 0.004671338004671338, 'mean_word_length': 2.019899244332494, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 79, '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': '1346104', 'n_tokens_mistral': 3658, 'n_tokens_neox': 3466, 'n_words': 853}