Documentation TYPO3 par Ameos

adodb-oracle.inc.php

00001 <?php
00002 /*
00003 V4.80 8 Mar 2006  (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
00004   Released under both BSD license and Lesser GPL library license. 
00005   Whenever there is any discrepancy between the two licenses, 
00006   the BSD license will take precedence.
00007 
00008   Latest version is available at http://adodb.sourceforge.net
00009   
00010   Oracle data driver. Requires Oracle client. Works on Windows and Unix and Oracle 7.
00011   
00012   If you are using Oracle 8 or later, use the oci8 driver which is much better and more reliable.
00013 */
00014 
00015 // security - hide paths
00016 if (!defined('ADODB_DIR')) die();
00017 
00018 class ADODB_oracle extends ADOConnection {
00019         var $databaseType = "oracle";
00020         var $replaceQuote = "''"; // string to use to replace quotes
00021         var $concat_operator='||';
00022         var $_curs;
00023         var $_initdate = true; // init date to YYYY-MM-DD
00024         var $metaTablesSQL = 'select table_name from cat';      
00025         var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno";
00026         var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')";
00027         var $sysTimeStamp = 'SYSDATE';
00028         var $connectSID = true;
00029         
00030         function ADODB_oracle() 
00031         {
00032         }
00033 
00034         // format and return date string in database date format
00035         function DBDate($d)
00036         {
00037                 if (is_string($d)) $d = ADORecordSet::UnixDate($d);
00038                 return 'TO_DATE('.adodb_date($this->fmtDate,$d).",'YYYY-MM-DD')";
00039         }
00040         
00041         // format and return date string in database timestamp format
00042         function DBTimeStamp($ts)
00043         {
00044 
00045                 if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts);
00046                 return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";
00047         }
00048 
00049         
00050         function BeginTrans()
00051         {         
00052                  $this->autoCommit = false;
00053                  ora_commitoff($this->_connectionID);
00054                  return true;
00055         }
00056 
00057         
00058         function CommitTrans($ok=true) 
00059         { 
00060                    if (!$ok) return $this->RollbackTrans();
00061                    $ret = ora_commit($this->_connectionID);
00062                    ora_commiton($this->_connectionID);
00063                    return $ret;
00064         }
00065 
00066         
00067         function RollbackTrans()
00068         {
00069                 $ret = ora_rollback($this->_connectionID);
00070                 ora_commiton($this->_connectionID);
00071                 return $ret;
00072         }
00073 
00074 
00075         /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */
00076         function ErrorMsg() 
00077         {   
00078         if ($this->_errorMsg !== false) return $this->_errorMsg;
00079 
00080         if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs);
00081                 if (empty($this->_errorMsg)) $this->_errorMsg = @ora_error($this->_connectionID);
00082                 return $this->_errorMsg;
00083         }
00084 
00085  
00086         function ErrorNo() 
00087         {
00088                 if ($this->_errorCode !== false) return $this->_errorCode;
00089 
00090                 if (is_resource($this->_curs)) $this->_errorCode = @ora_errorcode($this->_curs);
00091                 if (empty($this->_errorCode)) $this->_errorCode = @ora_errorcode($this->_connectionID);
00092         return $this->_errorCode;
00093         }
00094 
00095         
00096 
00097                 // returns true or false
00098                 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0)
00099                 {
00100                         if (!function_exists('ora_plogon')) return null;
00101                                 
00102             // <G. Giunta 2003/03/03/> Reset error messages before connecting
00103             $this->_errorMsg = false;
00104                     $this->_errorCode = false;
00105         
00106             // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set
00107             // the oracle home to the host name of remote DB?
00108 //                      if ($argHostname) putenv("ORACLE_HOME=$argHostname");
00109 
00110                         if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <jorma.tuomainen@ppoy.fi>
00111                                 if (empty($argDatabasename)) $argDatabasename = $argHostname;
00112                                 else {
00113                                         if(strpos($argHostname,":")) {
00114                                                 $argHostinfo=explode(":",$argHostname);
00115                                                 $argHostname=$argHostinfo[0];
00116                                                 $argHostport=$argHostinfo[1];
00117                                         } else {
00118                                                 $argHostport="1521";
00119                                         }
00120 
00121 
00122                                         if ($this->connectSID) {
00123                                                 $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
00124                                                 .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";
00125                                         } else
00126                                                 $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
00127                                                 .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";
00128                                 }
00129 
00130                         }
00131 
00132                         if ($argDatabasename) $argUsername .= "@$argDatabasename";
00133 
00134                 //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
00135                         if ($mode = 1)
00136                                 $this->_connectionID = ora_plogon($argUsername,$argPassword);
00137                         else
00138                                 $this->_connectionID = ora_logon($argUsername,$argPassword);
00139                         if ($this->_connectionID === false) return false;
00140                         if ($this->autoCommit) ora_commiton($this->_connectionID);
00141                         if ($this->_initdate) {
00142                                 $rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
00143                                 if ($rs) ora_close($rs);
00144                         }
00145 
00146                         return true;
00147                 }
00148 
00149 
00150                 // returns true or false
00151                 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
00152                 {
00153                         return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 1);
00154                 }
00155 
00156 
00157                 // returns query ID if successful, otherwise false
00158                 function _query($sql,$inputarr=false)
00159                 {
00160             // <G. Giunta 2003/03/03/> Reset error messages before executing
00161             $this->_errorMsg = false;
00162                     $this->_errorCode = false;
00163 
00164                         $curs = ora_open($this->_connectionID);
00165                  
00166                         if ($curs === false) return false;
00167                         $this->_curs = $curs;
00168                         if (!ora_parse($curs,$sql)) return false;
00169                         if (ora_exec($curs)) return $curs;
00170             // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message
00171             // that we can obtain ONLY from the cursor (and not from the connection)
00172             $this->_errorCode = @ora_errorcode($curs);
00173             $this->_errorMsg = @ora_error($curs);
00174             // </G. Giunta 2004/03/03>            
00175                         @ora_close($curs);
00176                         return false;
00177                 }
00178 
00179 
00180                 // returns true or false
00181                 function _close()
00182                 {
00183                         return @ora_logoff($this->_connectionID);
00184                 }
00185 
00186 
00187 
00188 }
00189 
00190 
00191 /*--------------------------------------------------------------------------------------
00192                  Class Name: Recordset
00193 --------------------------------------------------------------------------------------*/
00194 
00195 class ADORecordset_oracle extends ADORecordSet {
00196 
00197         var $databaseType = "oracle";
00198         var $bind = false;
00199 
00200         function ADORecordset_oracle($queryID,$mode=false)
00201         {
00202                 
00203                 if ($mode === false) { 
00204                         global $ADODB_FETCH_MODE;
00205                         $mode = $ADODB_FETCH_MODE;
00206                 }
00207                 $this->fetchMode = $mode;
00208                 
00209                 $this->_queryID = $queryID;
00210         
00211                 $this->_inited = true;
00212                 $this->fields = array();
00213                 if ($queryID) {
00214                         $this->_currentRow = 0;
00215                         $this->EOF = !$this->_fetch();
00216                         @$this->_initrs();
00217                 } else {
00218                         $this->_numOfRows = 0;
00219                         $this->_numOfFields = 0;
00220                         $this->EOF = true;
00221                 }
00222                 
00223                 return $this->_queryID;
00224         }
00225 
00226 
00227 
00228            /*           Returns: an object containing field information.
00229                            Get column information in the Recordset object. fetchField() can be used in order to obtain information about
00230                            fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
00231                            fetchField() is retrieved.           */
00232 
00233            function &FetchField($fieldOffset = -1)
00234            {
00235                         $fld = new ADOFieldObject;
00236                         $fld->name = ora_columnname($this->_queryID, $fieldOffset);
00237                         $fld->type = ora_columntype($this->_queryID, $fieldOffset);
00238                         $fld->max_length = ora_columnsize($this->_queryID, $fieldOffset);
00239                         return $fld;
00240            }
00241 
00242         /* Use associative array to get fields array */
00243         function Fields($colname)
00244         {
00245                 if (!$this->bind) {
00246                         $this->bind = array();
00247                         for ($i=0; $i < $this->_numOfFields; $i++) {
00248                                 $o = $this->FetchField($i);
00249                                 $this->bind[strtoupper($o->name)] = $i;
00250                         }
00251                 }
00252                 
00253                  return $this->fields[$this->bind[strtoupper($colname)]];
00254         }
00255         
00256    function _initrs()
00257    {
00258                    $this->_numOfRows = -1;
00259                    $this->_numOfFields = @ora_numcols($this->_queryID);
00260    }
00261 
00262 
00263    function _seek($row)
00264    {
00265                    return false;
00266    }
00267 
00268    function _fetch($ignore_fields=false) {
00269 // should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1
00270                 if ($this->fetchMode & ADODB_FETCH_ASSOC)
00271                         return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC);
00272                 else 
00273                         return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS);
00274    }
00275 
00276    /*           close() only needs to be called if you are worried about using too much memory while your script
00277                    is running. All associated result memory for the specified result identifier will automatically be freed.            */
00278 
00279    function _close() 
00280 {
00281                    return @ora_close($this->_queryID);
00282    }
00283 
00284         function MetaType($t,$len=-1)
00285         {
00286                 if (is_object($t)) {
00287                         $fieldobj = $t;
00288                         $t = $fieldobj->type;
00289                         $len = $fieldobj->max_length;
00290                 }
00291                 
00292                 switch (strtoupper($t)) {
00293                 case 'VARCHAR':
00294                 case 'VARCHAR2':
00295                 case 'CHAR':
00296                 case 'VARBINARY':
00297                 case 'BINARY':
00298                                 if ($len <= $this->blobSize) return 'C';
00299                 case 'LONG':
00300                 case 'LONG VARCHAR':
00301                 case 'CLOB':
00302                 return 'X';
00303                 case 'LONG RAW':
00304                 case 'LONG VARBINARY':
00305                 case 'BLOB':
00306                                 return 'B';
00307                 
00308                 case 'DATE': return 'D';
00309                 
00310                 //case 'T': return 'T';
00311                 
00312                 case 'BIT': return 'L';
00313                 case 'INT': 
00314                 case 'SMALLINT':
00315                 case 'INTEGER': return 'I';
00316                 default: return 'N';
00317                 }
00318         }
00319 }
00320 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6