Ticket #913: getAttribute.patch

File getAttribute.patch, 4.7 kB (added by foxmask, 16 months ago)
  • db/jDbConnection.class.php

     
    3030    const ATTR_CURSOR = 10; 
    3131    const CURSOR_FWDONLY = 0; 
    3232    const CURSOR_SCROLL = 1; 
    33  
     33    const ATTR_CLIENT_VERSION = null; 
     34    const ATTR_SERVER_INFO = null; 
     35    const ATTR_SERVER_VERSION = null; 
     36     
    3437    /** 
    3538    * profile properties used by the connector 
    3639    * @var array 
     
    229232    abstract public function lastInsertId($fromSequence=''); 
    230233 
    231234    /** 
    232      * Not implemented 
     235     * return the value of the Attribute of the current Connection 
    233236     * @param integer $id the attribut id 
    234237     * @return string the attribute value 
    235238     */ 
    236     public function getAttribute($id){ return '';} 
     239    abstract public function getAttribute($id); 
    237240 
    238241    /** 
    239      * Not implemented 
     242     * set the value of the Attribute of the current Connection 
    240243     * @param integer $id the attribut id 
    241244     * @param string $value the attribute value 
    242245     */ 
    243     public function setAttribute($id, $value){ } 
     246    public function setAttribute($id, $value) {         
     247        define ("$id", $value); 
     248    } 
    244249 
    245250    /** 
    246251     * 
  • plugins/db/mysql/mysql.dbconnection.php

     
    3232            throw new jException('jelix~db.error.nofunction','mysql'); 
    3333        } 
    3434        parent::__construct($profile); 
     35        $this->_setAttributes(); 
    3536    } 
    3637 
    3738    /** 
     
    9091              && isset($this->_charsets[$GLOBALS['gJConfig']->charset])){ 
    9192                mysql_query("SET NAMES '".$this->_charsets[$GLOBALS['gJConfig']->charset]."'", $cnx); 
    9293            } 
     94             
     95             
    9396            return $cnx; 
    9497        }else{ 
    9598            throw new jException('jelix~db.error.connection',$this->profile['host']); 
     
    156159        return mysql_real_escape_string($text,  $this->_connection ); 
    157160    } 
    158161 
     162    /** 
     163     * return the value of the given Attribute 
     164     * @param the Attribute to get 
     165     * @return string the value of the Attribute 
     166     */ 
     167    public function getAttribute($id) { 
     168        return constant("ATTR_$id"); 
     169    } 
     170     
     171    protected function _setAttributes() { 
     172        $this->setAttribute("ATTR_CLIENT_VERSION",mysql_get_client_info()); 
     173        $this->setAttribute("ATTR_SERVER_INFO",mysql_get_host_info($this->_connect())); 
     174        $this->setAttribute("ATTR_SERVER_VERSION",mysql_get_server_info($this->_connect())); 
     175    } 
    159176} 
    160177 
  • plugins/db/pgsql/pgsql.dbconnection.php

     
    3939                { 
    4040                        $this->setAutoCommit(true); 
    4141        } 
     42        $this->_setAttributes(); 
    4243    } 
    4344 
    4445    /** 
     
    191192    protected function _quote($text){ 
    192193        return pg_escape_string($text); 
    193194    } 
     195     
     196 
     197    /** 
     198     * return the value of the given Attribute 
     199     * @param the Attribute to get 
     200     * @return string the value of the Attribute 
     201     */ 
     202    public function getAttribute($id) { 
     203        return constant("ATTR_$id"); 
     204    } 
     205     
     206    protected function _setAttributes() { 
     207        $v = pg_version($this->_connect()); 
     208        $this->setAttribute("ATTR_CLIENT_VERSION",array_key_exists('client') ? $v['client'] : null); 
     209        $this->setAttribute("ATTR_SERVER_INFO",null); 
     210        $this->setAttribute("ATTR_SERVER_VERSION", pg_parameter_status($this->_connect(),'server_info')); 
     211    } 
     212     
    194213} 
    195214 
  • plugins/db/sqlite/sqlite.dbconnection.php

     
    2121            throw new jException('jelix~db.error.nofunction','sqlite'); 
    2222        } 
    2323        parent::__construct($profile); 
     24        $this->_setAttributes(); 
    2425    } 
    2526 
    2627    /** 
     
    115116        return sqlite_escape_string($text); 
    116117    } 
    117118 
     119 
     120    /** 
     121     * return the value of the given Attribute 
     122     * @param the Attribute to get 
     123     * @return string the value of the Attribute 
     124     */ 
     125    public function getAttribute($id) { 
     126        return constant("ATTR_$id"); 
     127    } 
     128     
     129    protected function _setAttributes() { 
     130        $this->setAttribute("ATTR_CLIENT_VERSION",sqlite_libversion(); 
     131        $this->setAttribute("ATTR_SERVER_INFO",null); 
     132        $this->setAttribute("ATTR_SERVER_VERSION", null); 
     133    } 
     134     
    118135} 
    119136