<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'rdbms.tds.TdsConnection',
    'rdbms.tds.TdsV5Protocol',
    'rdbms.sybase.SybaseDialect',
    'io.File'
  );

  /**
   * Connection to Sybase Databases via TDS 5.0
   *
   * @see   xp://rdbms.tds.TdsConnection
   */
  class SybasexConnection extends TdsConnection {
    protected static $lookup;

    static function __static() {
      if (strncasecmp(PHP_OS, 'Win', 3) === 0) {
        self::$lookup= 'useSqlIni';
      } else if (getenv('SYBASE')) {
        self::$lookup= 'useInterfaces';
      } else {
        self::$lookup= 'useFreeTds';
      }
    }

    /**
     * Parse an ini file
     *
     * @param   string ini
     * @return  [:[:string]] sections
     */
    protected function parseIni($ini) {
      $f= new File($ini);
      $f->open(FILE_MODE_READ);
      $section= NULL;
      $sections= array();
      while (FALSE !== ($line= $f->readLine())) {
        if ('' === $line || ';' === $line{0}) {
          continue;
        } else if ('[' === $line{0}) {
          $section= strtolower(trim($line, '[]'));
        } else if (FALSE !== ($p= strpos($line, '='))) {
          $key= trim(substr($line, 0, $p));
          $value= trim(substr($line, $p+ 1));
          $sections[$section][$key]= $value;
        }
      }
      $f->close();
      return $sections;
    }

    /**
     * Use sql.ini file if possible
     *
     * @param   rdbms.DSN dsn
     */
    protected function useSqlIni($dsn) {
      if (!file_exists($ini= getenv('SYBASE').'\\ini\\sql.ini')) return;

      $host= strtolower($dsn->getHost());
      $sections= $this->parseIni($ini);
      if (!isset($sections[$host])) return;

      sscanf($sections[$host]['query'], '%[^,],%[^,],%d', $proto, $host, $port);
      $dsn->url->setHost(gethostbyname($host));
      $dsn->url->setPort($port);
    }

    /**
     * Use Sybase interfaces file if possible
     *
     * @param   rdbms.DSN dsn
     */
    protected function useInterfaces($dsn) {
      // TODO
    }

    /**
     * Use FreeTDS config file if possible
     *
     * @param   rdbms.DSN dsn
     */
    protected function useFreeTds($dsn) {
      // TODO
    }

    /**
     * Constructor
     *
     * @param   rdbms.DSN dsn
     */
    public function __construct($dsn) {
      if (NULL === $dsn->getPort(NULL)) {       // Check lookup
        $this->{self::$lookup}($dsn);<commit_msg>- Refactor interface lookup to rdbms.tds.ConnectionLookup from   local method calls to rdbms.tds.ConnectionLookup implementations<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'rdbms.tds.TdsConnection',
    'rdbms.tds.TdsV5Protocol',
    'rdbms.tds.ConnectionLookup',
    'rdbms.sybase.SybaseDialect'
  );

  /**
   * Connection to Sybase Databases via TDS 5.0
   *
   * @see   xp://rdbms.tds.TdsConnection
   */
  class SybasexConnection extends TdsConnection {
    protected static $lookup;

    static function __static() {
      if (strncasecmp(PHP_OS, 'Win', 3) === 0) {
        self::$lookup= XPClass::forName('rdbms.tds.SqlIniLookup')->newInstance();
      } else if (getenv('SYBASE')) {
        self::$lookup= XPClass::forName('rdbms.tds.InterfacesLookup')->newInstance();
      } else {
        self::$lookup= XPClass::forName('rdbms.tds.FreeTdsLookup')->newInstance();
      }
    }

    /**
     * Constructor
     *
     * @param   rdbms.DSN dsn
     */
    public function __construct($dsn) {
      if (NULL === $dsn->getPort(NULL)) {       // Check lookup
        self::$lookup->lookup($dsn);
{'fraction_non_alphanumeric': 0.1751886001676446, 'fraction_numerical': 0.003911707180776753, 'mean_word_length': 2.2904411764705883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1458291', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1235, 'n_words': 242}