"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/adodb/adodb/drivers/adodb-oracle.inc.php Source File", "datetime" => "Sat Dec 2 19:22:26 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>
00001 <?php 00002 /* 00003 V4.90 8 June 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 BindDate($d) 00051 { 00052 $d = ADOConnection::DBDate($d); 00053 if (strncmp($d,"'",1)) return $d; 00054 00055 return substr($d,1,strlen($d)-2); 00056 } 00057 00058 function BindTimeStamp($d) 00059 { 00060 $d = ADOConnection::DBTimeStamp($d); 00061 if (strncmp($d,"'",1)) return $d; 00062 00063 return substr($d,1,strlen($d)-2); 00064 } 00065 00066 00067 00068 function BeginTrans() 00069 { 00070 $this->autoCommit = false; 00071 ora_commitoff($this->_connectionID); 00072 return true; 00073 } 00074 00075 00076 function CommitTrans($ok=true) 00077 { 00078 if (!$ok) return $this->RollbackTrans(); 00079 $ret = ora_commit($this->_connectionID); 00080 ora_commiton($this->_connectionID); 00081 return $ret; 00082 } 00083 00084 00085 function RollbackTrans() 00086 { 00087 $ret = ora_rollback($this->_connectionID); 00088 ora_commiton($this->_connectionID); 00089 return $ret; 00090 } 00091 00092 00093 /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */ 00094 function ErrorMsg() 00095 { 00096 if ($this->_errorMsg !== false) return $this->_errorMsg; 00097 00098 if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs); 00099 if (empty($this->_errorMsg)) $this->_errorMsg = @ora_error($this->_connectionID); 00100 return $this->_errorMsg; 00101 } 00102 00103 00104 function ErrorNo() 00105 { 00106 if ($this->_errorCode !== false) return $this->_errorCode; 00107 00108 if (is_resource($this->_curs)) $this->_errorCode = @ora_errorcode($this->_curs); 00109 if (empty($this->_errorCode)) $this->_errorCode = @ora_errorcode($this->_connectionID); 00110 return $this->_errorCode; 00111 } 00112 00113 00114 00115 // returns true or false 00116 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0) 00117 { 00118 if (!function_exists('ora_plogon')) return null; 00119 00120 // <G. Giunta 2003/03/03/> Reset error messages before connecting 00121 $this->_errorMsg = false; 00122 $this->_errorCode = false; 00123 00124 // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set 00125 // the oracle home to the host name of remote DB? 00126 // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); 00127 00128 if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <jorma.tuomainen@ppoy.fi> 00129 if (empty($argDatabasename)) $argDatabasename = $argHostname; 00130 else { 00131 if(strpos($argHostname,":")) { 00132 $argHostinfo=explode(":",$argHostname); 00133 $argHostname=$argHostinfo[0]; 00134 $argHostport=$argHostinfo[1]; 00135 } else { 00136 $argHostport="1521"; 00137 } 00138 00139 00140 if ($this->connectSID) { 00141 $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname 00142 .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; 00143 } else 00144 $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname 00145 .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; 00146 } 00147 00148 } 00149 00150 if ($argDatabasename) $argUsername .= "@$argDatabasename"; 00151 00152 //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>"; 00153 if ($mode = 1) 00154 $this->_connectionID = ora_plogon($argUsername,$argPassword); 00155 else 00156 $this->_connectionID = ora_logon($argUsername,$argPassword); 00157 if ($this->_connectionID === false) return false; 00158 if ($this->autoCommit) ora_commiton($this->_connectionID); 00159 if ($this->_initdate) { 00160 $rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'"); 00161 if ($rs) ora_close($rs); 00162 } 00163 00164 return true; 00165 } 00166 00167 00168 // returns true or false 00169 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 00170 { 00171 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 1); 00172 } 00173 00174 00175 // returns query ID if successful, otherwise false 00176 function _query($sql,$inputarr=false) 00177 { 00178 // <G. Giunta 2003/03/03/> Reset error messages before executing 00179 $this->_errorMsg = false; 00180 $this->_errorCode = false; 00181 00182 $curs = ora_open($this->_connectionID); 00183 00184 if ($curs === false) return false; 00185 $this->_curs = $curs; 00186 if (!ora_parse($curs,$sql)) return false; 00187 if (ora_exec($curs)) return $curs; 00188 // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message 00189 // that we can obtain ONLY from the cursor (and not from the connection) 00190 $this->_errorCode = @ora_errorcode($curs); 00191 $this->_errorMsg = @ora_error($curs); 00192 // </G. Giunta 2004/03/03> 00193 @ora_close($curs); 00194 return false; 00195 } 00196 00197 00198 // returns true or false 00199 function _close() 00200 { 00201 return @ora_logoff($this->_connectionID); 00202 } 00203 00204 00205 00206 } 00207 00208 00209 /*-------------------------------------------------------------------------------------- 00210 Class Name: Recordset 00211 --------------------------------------------------------------------------------------*/ 00212 00213 class ADORecordset_oracle extends ADORecordSet { 00214 00215 var $databaseType = "oracle"; 00216 var $bind = false; 00217 00218 function ADORecordset_oracle($queryID,$mode=false) 00219 { 00220 00221 if ($mode === false) { 00222 global $ADODB_FETCH_MODE; 00223 $mode = $ADODB_FETCH_MODE; 00224 } 00225 $this->fetchMode = $mode; 00226 00227 $this->_queryID = $queryID; 00228 00229 $this->_inited = true; 00230 $this->fields = array(); 00231 if ($queryID) { 00232 $this->_currentRow = 0; 00233 $this->EOF = !$this->_fetch(); 00234 @$this->_initrs(); 00235 } else { 00236 $this->_numOfRows = 0; 00237 $this->_numOfFields = 0; 00238 $this->EOF = true; 00239 } 00240 00241 return $this->_queryID; 00242 } 00243 00244 00245 00246 /* Returns: an object containing field information. 00247 Get column information in the Recordset object. fetchField() can be used in order to obtain information about 00248 fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by 00249 fetchField() is retrieved. */ 00250 00251 function &FetchField($fieldOffset = -1) 00252 { 00253 $fld = new ADOFieldObject; 00254 $fld->name = ora_columnname($this->_queryID, $fieldOffset); 00255 $fld->type = ora_columntype($this->_queryID, $fieldOffset); 00256 $fld->max_length = ora_columnsize($this->_queryID, $fieldOffset); 00257 return $fld; 00258 } 00259 00260 /* Use associative array to get fields array */ 00261 function Fields($colname) 00262 { 00263 if (!$this->bind) { 00264 $this->bind = array(); 00265 for ($i=0; $i < $this->_numOfFields; $i++) { 00266 $o = $this->FetchField($i); 00267 $this->bind[strtoupper($o->name)] = $i; 00268 } 00269 } 00270 00271 return $this->fields[$this->bind[strtoupper($colname)]]; 00272 } 00273 00274 function _initrs() 00275 { 00276 $this->_numOfRows = -1; 00277 $this->_numOfFields = @ora_numcols($this->_queryID); 00278 } 00279 00280 00281 function _seek($row) 00282 { 00283 return false; 00284 } 00285 00286 function _fetch($ignore_fields=false) { 00287 // should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1 00288 if ($this->fetchMode & ADODB_FETCH_ASSOC) 00289 return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); 00290 else 00291 return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS); 00292 } 00293 00294 /* close() only needs to be called if you are worried about using too much memory while your script 00295 is running. All associated result memory for the specified result identifier will automatically be freed. */ 00296 00297 function _close() 00298 { 00299 return @ora_close($this->_queryID); 00300 } 00301 00302 function MetaType($t,$len=-1) 00303 { 00304 if (is_object($t)) { 00305 $fieldobj = $t; 00306 $t = $fieldobj->type; 00307 $len = $fieldobj->max_length; 00308 } 00309 00310 switch (strtoupper($t)) { 00311 case 'VARCHAR': 00312 case 'VARCHAR2': 00313 case 'CHAR': 00314 case 'VARBINARY': 00315 case 'BINARY': 00316 if ($len <= $this->blobSize) return 'C'; 00317 case 'LONG': 00318 case 'LONG VARCHAR': 00319 case 'CLOB': 00320 return 'X'; 00321 case 'LONG RAW': 00322 case 'LONG VARBINARY': 00323 case 'BLOB': 00324 return 'B'; 00325 00326 case 'DATE': return 'D'; 00327 00328 //case 'T': return 'T'; 00329 00330 case 'BIT': return 'L'; 00331 case 'INT': 00332 case 'SMALLINT': 00333 case 'INTEGER': return 'I'; 00334 default: return 'N'; 00335 } 00336 } 00337 } 00338 ?>