Ignore:
Timestamp:
06/29/07 15:17:46 (17 years ago)
Author:
niltonneto
Message:

Versão nova do ADODB (4.5 para 4.95)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpgwapi/inc/adodb/drivers/adodb-odbtp.inc.php

    r2 r34  
    11<?php 
    22/* 
    3 V4.51 29 July 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved. 
     3  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 
    44  Released under both BSD license and Lesser GPL library license. 
    55  Whenever there is any discrepancy between the two licenses, 
     
    2929        var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)"; 
    3030        var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'"; 
    31         var $_autocommit = true; 
    3231        var $_bindInputArray = false; 
    3332        var $_useUnicodeSQL = false; 
    3433        var $_canPrepareSP = false; 
     34        var $_dontPoolDBC = true; 
    3535 
    3636        function ADODB_odbtp() 
     
    107107        { 
    108108                $seqtab='adodb_seq'; 
    109                 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { 
     109                if( $this->odbc_driver == ODB_DRIVER_FOXPRO) { 
    110110                        $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); 
    111111                        //if using vfp dbc file 
     
    150150    function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 
    151151        { 
    152                 $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); 
    153                 if ($this->_connectionID === false) 
    154                 { 
     152                $this->_connectionID = odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); 
     153                if ($this->_connectionID === false) { 
    155154                        $this->_errorMsg = $this->ErrorMsg() ; 
    156155                        return false; 
    157156                } 
     157                 
     158                odbtp_convert_datetime($this->_connectionID,true); 
     159                 
     160                if ($this->_dontPoolDBC) { 
     161                        if (function_exists('odbtp_dont_pool_dbc')) 
     162                                @odbtp_dont_pool_dbc($this->_connectionID); 
     163                } 
     164                else { 
     165                        $this->_dontPoolDBC = true; 
     166                } 
    158167                $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID); 
    159  
    160                 // Set driver specific attributes 
    161                 switch( $this->odbc_driver ) { 
    162                         case ODB_DRIVER_MSSQL: 
     168                $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID)); 
     169                $this->odbc_name = $dbms; 
     170                 
     171                // Account for inconsistent DBMS names 
     172                if( $this->odbc_driver == ODB_DRIVER_ORACLE ) 
     173                        $dbms = 'oracle'; 
     174                else if( $this->odbc_driver == ODB_DRIVER_SYBASE ) 
     175                        $dbms = 'sybase'; 
     176 
     177                // Set DBMS specific attributes 
     178                switch( $dbms ) { 
     179                        case 'microsoft sql server': 
     180                                $this->databaseType = 'odbtp_mssql'; 
    163181                                $this->fmtDate = "'Y-m-d'"; 
    164182                                $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 
     
    177195                                $this->identitySQL = 'select @@IDENTITY'; 
    178196                                $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'"; 
     197                                $this->_canPrepareSP = true; 
    179198                                break; 
    180                         case ODB_DRIVER_JET: 
     199                        case 'access': 
     200                                $this->databaseType = 'odbtp_access'; 
    181201                                $this->fmtDate = "#Y-m-d#"; 
    182202                                $this->fmtTimeStamp = "#Y-m-d h:i:sA#"; 
     
    186206                                $this->hasTransactions = false; 
    187207                                $this->_canPrepareSP = true;  // For MS Access only. 
    188  
    189                                 // Can't rebind ODB_CHAR to ODB_WCHAR if row cache enabled. 
    190                                 if ($this->_useUnicodeSQL) 
    191                                         odbtp_use_row_cache($this->_connectionID, FALSE, 0); 
    192208                                break; 
    193                         case ODB_DRIVER_FOXPRO: 
     209                        case 'visual foxpro': 
     210                                $this->databaseType = 'odbtp_vfp'; 
    194211                                $this->fmtDate = "{^Y-m-d}"; 
    195212                                $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}"; 
     
    198215                                $this->ansiOuter = true; 
    199216                $this->hasTop = 'top'; 
    200                         $this->hasTransactions = false; 
     217                                $this->hasTransactions = false; 
    201218                                $this->replaceQuote = "'+chr(39)+'"; 
    202219                                $this->true = '.T.'; 
    203220                                $this->false = '.F.'; 
     221 
    204222                                break; 
    205                         case ODB_DRIVER_ORACLE: 
     223                        case 'oracle': 
     224                                $this->databaseType = 'odbtp_oci8'; 
    206225                                $this->fmtDate = "'Y-m-d 00:00:00'"; 
    207226                                $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 
     
    212231                                $this->concat_operator = '||'; 
    213232                                break; 
    214                         case ODB_DRIVER_SYBASE: 
     233                        case 'sybase': 
     234                                $this->databaseType = 'odbtp_sybase'; 
    215235                                $this->fmtDate = "'Y-m-d'"; 
    216236                                $this->fmtTimeStamp = "'Y-m-d H:i:s'"; 
     
    224244                                break; 
    225245                        default: 
     246                                $this->databaseType = 'odbtp'; 
    226247                                if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) ) 
    227                         $this->hasTransactions = true; 
     248                                        $this->hasTransactions = true; 
    228249                                else 
    229250                                        $this->hasTransactions = false; 
    230251                } 
    231252        @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID ); 
     253 
    232254                if ($this->_useUnicodeSQL ) 
    233255                        @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID); 
     256 
    234257        return true; 
    235258        } 
    236          
     259 
    237260        function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 
    238261        { 
     262                $this->_dontPoolDBC = false; 
    239263                return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase); 
    240264        } 
    241          
     265 
    242266        function SelectDB($dbName) 
    243267        { 
     
    245269                        return false; 
    246270                } 
    247                 $this->databaseName = $dbName; 
     271                $this->database = $dbName; 
     272                $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions 
    248273                return true; 
    249274        } 
     
    255280                $savem = $ADODB_FETCH_MODE; 
    256281                $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 
     282                if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 
     283                 
    257284                $arr =& $this->GetArray("||SQLTables||||$ttype"); 
     285                 
     286                if (isset($savefm)) $this->SetFetchMode($savefm); 
    258287                $ADODB_FETCH_MODE = $savem; 
    259288 
     
    262291                        if ($arr[$i][3] == 'SYSTEM TABLE' )     continue; 
    263292                        if ($arr[$i][2]) 
    264                                 $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; 
     293                                $arr2[] = $showSchema && $arr[$i][1]? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; 
    265294                } 
    266295                return $arr2; 
     
    277306                $savem = $ADODB_FETCH_MODE; 
    278307                $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 
     308                if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 
     309                 
    279310                $rs = $this->Execute( "||SQLColumns||$schema|$table" ); 
     311                 
     312                if (isset($savefm)) $this->SetFetchMode($savefm); 
    280313                $ADODB_FETCH_MODE = $savem; 
    281314 
    282                 if (!$rs) return false; 
    283                  
     315                if (!$rs || $rs->EOF) { 
     316                        $false = false; 
     317                        return $false; 
     318                } 
     319                $retarr = array(); 
    284320                while (!$rs->EOF) { 
    285321                        //print_r($rs->fields); 
     
    291327                        $fld->not_null = !empty($rs->fields[9]); 
    292328                                $fld->scale = $rs->fields[7]; 
    293                                 if (!is_null($rs->fields[12])) { 
    294                                         $fld->has_default = true; 
    295                                         $fld->default_value = $rs->fields[12]; 
    296                                 } 
     329                                if (isset($rs->fields[12])) // vfp does not have field 12 
     330                                        if (!is_null($rs->fields[12])) { 
     331                                                $fld->has_default = true; 
     332                                                $fld->default_value = $rs->fields[12]; 
     333                                        } 
    297334                                $retarr[strtoupper($fld->name)] = $fld; 
    298                         } else if (sizeof($retarr)>0) 
     335                        } else if (!empty($retarr)) 
    299336                                break; 
    300337                        $rs->MoveNext(); 
    301338                } 
    302                 $rs->Close();  
     339                $rs->Close(); 
    303340 
    304341                return $retarr; 
     
    336373                        $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3]; 
    337374                } 
    338                 if (!$arr) return false; 
    339  
     375                if (!$arr) { 
     376                        $false = false; 
     377                        return $false; 
     378                } 
     379                 
    340380                $arr2 = array(); 
    341381 
     
    354394                if ($this->transOff) return true; 
    355395                $this->transCnt += 1; 
    356                 $this->_autocommit = false; 
    357                 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,ODB_TXN_READUNCOMMITTED,$this->_connectionID); 
     396                $this->autoCommit = false; 
     397                if (defined('ODB_TXN_DEFAULT')) 
     398                        $txn = ODB_TXN_DEFAULT; 
     399                else 
     400                        $txn = ODB_TXN_READUNCOMMITTED; 
     401                $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID); 
    358402                if(!$rs) return false; 
    359                 else return true; 
     403                return true; 
    360404        } 
    361405 
     
    365409                if (!$ok) return $this->RollbackTrans(); 
    366410                if ($this->transCnt) $this->transCnt -= 1; 
    367                 $this->_autocommit = true; 
    368                 if( ($ret = odbtp_commit($this->_connectionID)) ) 
     411                $this->autoCommit = true; 
     412                if( ($ret = @odbtp_commit($this->_connectionID)) ) 
    369413                        $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 
    370414                return $ret; 
     
    375419                if ($this->transOff) return true; 
    376420                if ($this->transCnt) $this->transCnt -= 1; 
    377                 $this->_autocommit = true; 
    378                 if( ($ret = odbtp_rollback($this->_connectionID)) ) 
     421                $this->autoCommit = true; 
     422                if( ($ret = @odbtp_rollback($this->_connectionID)) ) 
    379423                        $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 
    380424                return $ret; 
     
    387431                        if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1'; 
    388432                } 
    389                 return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 
     433                $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 
     434                return $ret; 
    390435        } 
    391436 
     
    393438        { 
    394439                if (! $this->_bindInputArray) return $sql; // no binding 
    395                 $stmt = odbtp_prepare($sql,$this->_connectionID); 
     440                $stmt = @odbtp_prepare($sql,$this->_connectionID); 
    396441                if (!$stmt) { 
    397442                //      print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>"; 
     
    405450                if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures 
    406451 
    407                 $stmt = odbtp_prepare_proc($sql,$this->_connectionID); 
     452                $stmt = @odbtp_prepare_proc($sql,$this->_connectionID); 
    408453                if (!$stmt) return false; 
    409454                return array($sql,$stmt); 
     
    442487                        $name = '@'.$name; 
    443488                } 
    444                 return odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); 
     489                return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); 
    445490        } 
    446491 
     
    458503        { 
    459504                $sql = "UPDATE $table SET $column = ? WHERE $where"; 
    460                 if( !($stmt = odbtp_prepare($sql, $this->_connectionID)) ) 
     505                if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) ) 
    461506                        return false; 
    462                 if( !odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) 
     507                if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) 
    463508                        return false; 
    464                 if( !odbtp_set( $stmt, 1, $val ) ) 
     509                if( !@odbtp_set( $stmt, 1, $val ) ) 
    465510                        return false; 
    466                 return odbtp_execute( $stmt ) != false; 
     511                return @odbtp_execute( $stmt ) != false; 
    467512        } 
    468513 
     
    480525        function _query($sql,$inputarr=false) 
    481526        { 
     527        global $php_errormsg; 
     528         
    482529                if ($inputarr) { 
    483530                        if (is_array($sql)) { 
    484531                                $stmtid = $sql[1]; 
    485532                        } else { 
    486                                 $stmtid = odbtp_prepare($sql,$this->_connectionID); 
     533                                $stmtid = @odbtp_prepare($sql,$this->_connectionID); 
    487534                                if ($stmtid == false) { 
    488535                                        $this->_errorMsg = $php_errormsg; 
     
    490537                                } 
    491538                        } 
    492                         $num_params = odbtp_num_params( $stmtid ); 
     539                        $num_params = @odbtp_num_params( $stmtid ); 
    493540                        for( $param = 1; $param <= $num_params; $param++ ) { 
    494541                                @odbtp_input( $stmtid, $param ); 
    495542                                @odbtp_set( $stmtid, $param, $inputarr[$param-1] ); 
    496543                        } 
    497                         if (! odbtp_execute($stmtid) ) { 
     544                        if (!@odbtp_execute($stmtid) ) { 
    498545                                return false; 
    499546                        } 
    500547                } else if (is_array($sql)) { 
    501548                        $stmtid = $sql[1]; 
    502                         if (!odbtp_execute($stmtid)) { 
     549                        if (!@odbtp_execute($stmtid)) { 
    503550                                return false; 
    504551                        } 
    505552                } else { 
    506                         $stmtid = @odbtp_query($sql,$this->_connectionID); 
     553                        $stmtid = odbtp_query($sql,$this->_connectionID); 
    507554                } 
    508555                $this->_lastAffectedRows = 0; 
     
    541588                if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) 
    542589                        $this->_numOfRows = -1; 
     590 
     591                if (!$this->connection->_useUnicodeSQL) return; 
     592 
     593                if ($this->connection->odbc_driver == ODB_DRIVER_JET) { 
     594                        if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR, 
     595                                             $this->connection->_connectionID)) 
     596                        { 
     597                                for ($f = 0; $f < $this->_numOfFields; $f++) { 
     598                                        if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR) 
     599                                                @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR); 
     600                                } 
     601                        } 
     602                } 
    543603        } 
    544604 
     
    571631                        } 
    572632                } 
    573                  return $this->fields[$this->bind[strtoupper($colname)]]; 
     633                return $this->fields[$this->bind[strtoupper($colname)]]; 
    574634        } 
    575635 
     
    586646                                $this->fields = @odbtp_fetch_array($this->_queryID, $type); 
    587647                } 
     648                if ($this->databaseType = 'odbtp_vfp') { 
     649                        if ($this->fields) 
     650                        foreach($this->fields as $k => $v) { 
     651                                if (strncmp($v,'1899-12-30',10) == 0) $this->fields[$k] = ''; 
     652                        } 
     653                } 
    588654                return is_array($this->fields); 
    589655        } 
     
    598664                if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false; 
    599665                $this->EOF = false; 
    600           $this->_currentRow = 0; 
    601           return true; 
     666                $this->_currentRow = 0; 
     667                return true; 
    602668    } 
    603669 
    604     function MoveLast() 
    605    { 
     670        function MoveLast() 
     671        { 
    606672                if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false; 
    607673                $this->EOF = false; 
    608674                $this->_currentRow = $this->_numOfRows - 1; 
    609           return true; 
    610     } 
    611      
     675                return true; 
     676        } 
     677 
    612678        function NextRecordSet() 
    613679        { 
     
    626692} 
    627693 
     694class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp { 
     695 
     696        var $databaseType = 'odbtp_mssql'; 
     697 
     698        function ADORecordSet_odbtp_mssql($id,$mode=false) 
     699        { 
     700                return $this->ADORecordSet_odbtp($id,$mode); 
     701        } 
     702} 
     703 
     704class ADORecordSet_odbtp_access extends ADORecordSet_odbtp { 
     705 
     706        var $databaseType = 'odbtp_access'; 
     707 
     708        function ADORecordSet_odbtp_access($id,$mode=false) 
     709        { 
     710                return $this->ADORecordSet_odbtp($id,$mode); 
     711        } 
     712} 
     713 
     714class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp { 
     715 
     716        var $databaseType = 'odbtp_vfp'; 
     717 
     718        function ADORecordSet_odbtp_vfp($id,$mode=false) 
     719        { 
     720                return $this->ADORecordSet_odbtp($id,$mode); 
     721        } 
     722} 
     723 
     724class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp { 
     725 
     726        var $databaseType = 'odbtp_oci8'; 
     727 
     728        function ADORecordSet_odbtp_oci8($id,$mode=false) 
     729        { 
     730                return $this->ADORecordSet_odbtp($id,$mode); 
     731        } 
     732} 
     733 
     734class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp { 
     735 
     736        var $databaseType = 'odbtp_sybase'; 
     737 
     738        function ADORecordSet_odbtp_sybase($id,$mode=false) 
     739        { 
     740                return $this->ADORecordSet_odbtp($id,$mode); 
     741        } 
     742} 
    628743?> 
Note: See TracChangeset for help on using the changeset viewer.