Ignore:
Timestamp:
09/26/13 15:41:49 (11 years ago)
Author:
angelo
Message:

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/drivers/adodb-db2.inc.php

    r34 r8222  
    11<?php 
    22/*  
    3   V4.94 23 Jan 2007  (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved. 
     3  V5.18 3 Sep 2012  (c) 2000-2012 (jlim#natsoft.com). All rights reserved. 
    44 
    55  This is a version of the ADODB driver for DB2.  It uses the 'ibm_db2' PECL extension 
     
    2525 
    2626 
     27 
     28 
     29 
    2730class ADODB_db2 extends ADOConnection { 
    2831        var $databaseType = "db2";       
     
    3437        var $sysTimeStamp = 'CURRENT TIMESTAMP'; 
    3538         
    36         var $fmtTimeStamp = "'Y-m-d-H:i:s'"; 
     39        var $fmtTimeStamp = "'Y-m-d H:i:s'"; 
    3740        var $replaceQuote = "''"; // string to use to replace quotes 
    3841        var $dataProvider = "db2"; 
     
    4548        var $_bindInputArray = false;    
    4649        var $_genIDSQL = "VALUES NEXTVAL FOR %s"; 
    47         var $_genSeqSQL = "CREATE SEQUENCE %s START WITH 1 NO MAXVALUE NO CYCLE"; 
     50        var $_genSeqSQL = "CREATE SEQUENCE %s START WITH %s NO MAXVALUE NO CYCLE"; 
    4851        var $_dropSeqSQL = "DROP SEQUENCE %s"; 
    4952        var $_autocommit = true; 
     
    5356        var $hasInsertID = true; 
    5457         
     58         
    5559    function _insertid() 
    5660    { 
     
    6973                 
    7074                if (!function_exists('db2_connect')) { 
    71                         ADOConnection::outp("Warning: The old ODBC based DB2 driver has been renamed 'odbc_db2'. This ADOdb driver calls PHP's native db2 extension."); 
     75                        ADOConnection::outp("Warning: The old ODBC based DB2 driver has been renamed 'odbc_db2'. This ADOdb driver calls PHP's native db2 extension which is not installed."); 
    7276                        return null; 
    7377                } 
     
    7680                ini_set('ibm_db2.binmode', $this->binmode); 
    7781 
    78                 if ($argDatabasename) { 
    79                         $this->_connectionID = db2_connect($argDatabasename,$argUsername,$argPassword); 
     82                if ($argDatabasename && empty($argDSN)) { 
     83                 
     84                        if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_connect($argDatabasename,null,null); 
     85                        else $this->_connectionID = db2_connect($argDatabasename,$argUsername,$argPassword); 
    8086                } else { 
    81                         $this->_connectionID = db2_connect($argDSN,$argUsername,$argPassword); 
     87                        if ($argDatabasename) $schema = $argDatabasename; 
     88                        if (stripos($argDSN,'UID=') && stripos($argDSN,'PWD=')) $this->_connectionID = db2_connect($argDSN,null,null); 
     89                        else $this->_connectionID = db2_connect($argDSN,$argUsername,$argPassword); 
    8290                } 
    8391                if (isset($php_errormsg)) $php_errormsg = ''; 
     
    8795 
    8896                $this->_errorMsg = @db2_conn_errormsg(); 
    89   
    9097                if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 
    9198                 
     99                if ($this->_connectionID && isset($schema)) $this->Execute("SET SCHEMA=$schema"); 
    92100                return $this->_connectionID != false; 
    93101        } 
     
    107115                $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 
    108116                 
    109                 if ($argDatabasename) { 
    110                         $this->_connectionID = db2_pconnect($argDatabasename,$argUsername,$argPassword); 
     117                if ($argDatabasename && empty($argDSN)) { 
     118                 
     119                        if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_pconnect($argDatabasename,null,null); 
     120                        else $this->_connectionID = db2_pconnect($argDatabasename,$argUsername,$argPassword); 
    111121                } else { 
    112                         $this->_connectionID = db2_pconnect($argDSN,$argUsername,$argPassword); 
     122                        if ($argDatabasename) $schema = $argDatabasename; 
     123                        if (stripos($argDSN,'UID=') && stripos($argDSN,'PWD=')) $this->_connectionID = db2_pconnect($argDSN,null,null); 
     124                        else $this->_connectionID = db2_pconnect($argDSN,$argUsername,$argPassword); 
    113125                } 
    114126                if (isset($php_errormsg)) $php_errormsg = ''; 
     
    118130                if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 
    119131                 
     132                if ($this->_connectionID && isset($schema)) $this->Execute("SET SCHEMA=$schema"); 
    120133                return $this->_connectionID != false; 
    121134        } 
     
    198211        function ServerInfo() 
    199212        { 
    200          
    201                 if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { 
    202                         $dsn = strtoupper($this->host); 
    203                         $first = true; 
    204                         $found = false; 
    205                          
    206                         if (!function_exists('db2_data_source')) return false; 
    207                          
    208                         while(true) { 
    209                                  
    210                                 $rez = @db2_data_source($this->_connectionID, 
    211                                         $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT); 
    212                                 $first = false; 
    213                                 if (!is_array($rez)) break; 
    214                                 if (strtoupper($rez['server']) == $dsn) { 
    215                                         $found = true; 
    216                                         break; 
    217                                 } 
    218                         }  
    219                         if (!$found) return ADOConnection::ServerInfo(); 
    220                         if (!isset($rez['version'])) $rez['version'] = ''; 
    221                         return $rez; 
     213                $row = $this->GetRow("SELECT service_level, fixpack_num FROM TABLE(sysproc.env_get_inst_info())  
     214                        as INSTANCEINFO"); 
     215 
     216                 
     217                if ($row) {              
     218                        $info['version'] = $row[0].':'.$row[1]; 
     219                        $info['fixpack'] = $row[1]; 
     220                        $info['description'] = ''; 
    222221                } else { 
    223222                        return ADOConnection::ServerInfo(); 
    224223                } 
    225         } 
    226  
     224                 
     225                return $info; 
     226        } 
    227227         
    228228        function CreateSequence($seqname='adodbseq',$start=1) 
    229229        { 
    230230                if (empty($this->_genSeqSQL)) return false; 
    231                 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); 
     231                $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$start)); 
    232232                if (!$ok) return false; 
    233233                return true; 
     
    238238                if (empty($this->_dropSeqSQL)) return false; 
    239239                return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); 
     240        } 
     241         
     242        function SelectLimit($sql,$nrows=-1,$offset=-1,$inputArr=false) 
     243        { 
     244                $nrows = (integer) $nrows; 
     245                if ($offset <= 0) { 
     246                // could also use " OPTIMIZE FOR $nrows ROWS " 
     247                        if ($nrows >= 0) $sql .=  " FETCH FIRST $nrows ROWS ONLY "; 
     248                        $rs = $this->Execute($sql,$inputArr); 
     249                } else { 
     250                        if ($offset > 0 && $nrows < 0); 
     251                        else { 
     252                                $nrows += $offset; 
     253                                $sql .=  " FETCH FIRST $nrows ROWS ONLY "; 
     254                        } 
     255                        $rs = ADOConnection::SelectLimit($sql,-1,$offset,$inputArr); 
     256                } 
     257                 
     258                return $rs; 
    240259        } 
    241260         
     
    250269                // if you have to modify the parameter below, your database is overloaded, 
    251270                // or you need to implement generation of id's yourself! 
    252                 $num = $this->GetOne("VALUES NEXTVAL FOR $seq"); 
     271                                $num = $this->GetOne("VALUES NEXTVAL FOR $seq"); 
    253272                                return $num; 
    254                         } 
     273        } 
    255274 
    256275 
     
    336355                if (!$rs) return false; 
    337356                 
    338                 $arr =& $rs->GetArray(); 
     357                $arr = $rs->GetArray(); 
    339358                $rs->Close(); 
    340359                $arr2 = array(); 
     
    391410         
    392411         
    393         function &MetaTables($ttype=false,$schema=false) 
     412        function MetaTables($ttype=false,$schema=false) 
    394413        { 
    395414        global $ADODB_FETCH_MODE; 
     
    407426                } 
    408427                 
    409                 $arr =& $rs->GetArray(); 
    410                  
     428                $arr = $rs->GetArray(); 
    411429                $rs->Close(); 
    412430                $arr2 = array(); 
     
    418436                        if (!$arr[$i][2]) continue; 
    419437                        $type = $arr[$i][3]; 
     438                        $owner = $arr[$i][1]; 
    420439                        $schemaval = ($schema) ? $arr[$i][1].'.' : ''; 
    421440                        if ($ttype) {  
    422441                                if ($isview) { 
    423442                                        if (strncmp($type,'V',1) === 0) $arr2[] = $schemaval.$arr[$i][2]; 
    424                                 } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 
    425                         } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 
     443                                } else if (strncmp($owner,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 
     444                        } else if (strncmp($owner,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 
    426445                } 
    427446                return $arr2; 
     
    496515        } 
    497516         
    498         function &MetaColumns($table) 
     517        function MetaColumns($table, $normalize=true) 
    499518        { 
    500519        global $ADODB_FETCH_MODE; 
     
    512531                if (empty($qid)) return $false; 
    513532                 
    514                 $rs =& new ADORecordSet_db2($qid); 
     533                $rs = new ADORecordSet_db2($qid); 
    515534                $ADODB_FETCH_MODE = $savem; 
    516535                 
     
    564583                if (empty($qid)) return $false; 
    565584                 
    566                 $rs =& new ADORecordSet_db2($qid); 
     585                $rs = new ADORecordSet_db2($qid); 
    567586                $ADODB_FETCH_MODE = $savem; 
    568587                 
     
    592611        } 
    593612         
     613                 
    594614        function Prepare($sql) 
    595615        { 
     
    720740 
    721741        // returns the field object 
    722         function &FetchField($offset = -1)  
     742        function FetchField($offset = -1)  
    723743        { 
    724744                $o= new ADOFieldObject(); 
     
    762782         
    763783        // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated 
    764         function &GetArrayLimit($nrows,$offset=-1)  
     784        function GetArrayLimit($nrows,$offset=-1)  
    765785        { 
    766786                if ($offset <= 0) { 
    767                         $rs =& $this->GetArray($nrows); 
     787                        $rs = $this->GetArray($nrows); 
    768788                        return $rs; 
    769789                } 
     
    774794                 
    775795                if ($this->fetchMode & ADODB_FETCH_ASSOC) { 
    776                         $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 
     796                        $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE); 
    777797                } 
    778798                 
     
    796816                        if ($this->fields) { 
    797817                                if ($this->fetchMode & ADODB_FETCH_ASSOC) { 
    798                                         $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 
     818                                        $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE); 
    799819                                } 
    800820                                return true; 
     
    812832                if ($this->fields) { 
    813833                        if ($this->fetchMode & ADODB_FETCH_ASSOC) { 
    814                                 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 
     834                                $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE); 
    815835                        } 
    816836                        return true; 
Note: See TracChangeset for help on using the changeset viewer.