PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/concreteOLD/libraries/3rdparty/adodb/drivers/adodb-oracle.inc.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 342 lines | 230 code | 71 blank | 41 comment | 42 complexity | 07d216be454be0c79d54710c05ccca2a MD5 | raw file
  1. <?php
  2. /*
  3. V5.10 10 Nov 2009 (c) 2000-2009 John Lim (jlim#natsoft.com). All rights reserved.
  4. Released under both BSD license and Lesser GPL library license.
  5. Whenever there is any discrepancy between the two licenses,
  6. the BSD license will take precedence.
  7. Latest version is available at http://adodb.sourceforge.net
  8. Oracle data driver. Requires Oracle client. Works on Windows and Unix and Oracle 7.
  9. If you are using Oracle 8 or later, use the oci8 driver which is much better and more reliable.
  10. */
  11. // security - hide paths
  12. if (!defined('ADODB_DIR')) die();
  13. class ADODB_oracle extends ADOConnection {
  14. var $databaseType = "oracle";
  15. var $replaceQuote = "''"; // string to use to replace quotes
  16. var $concat_operator='||';
  17. var $_curs;
  18. var $_initdate = true; // init date to YYYY-MM-DD
  19. var $metaTablesSQL = 'select table_name from cat';
  20. var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno";
  21. var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')";
  22. var $sysTimeStamp = 'SYSDATE';
  23. var $connectSID = true;
  24. function ADODB_oracle()
  25. {
  26. }
  27. // format and return date string in database date format
  28. function DBDate($d)
  29. {
  30. if (is_string($d)) $d = ADORecordSet::UnixDate($d);
  31. if (is_object($d)) $ds = $d->format($this->fmtDate);
  32. else $ds = adodb_date($this->fmtDate,$d);
  33. return 'TO_DATE('.$ds.",'YYYY-MM-DD')";
  34. }
  35. // format and return date string in database timestamp format
  36. function DBTimeStamp($ts)
  37. {
  38. if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
  39. if (is_object($ts)) $ds = $ts->format($this->fmtDate);
  40. else $ds = adodb_date($this->fmtTimeStamp,$ts);
  41. return 'TO_DATE('.$ds.",'RRRR-MM-DD, HH:MI:SS AM')";
  42. }
  43. function BindDate($d)
  44. {
  45. $d = ADOConnection::DBDate($d);
  46. if (strncmp($d,"'",1)) return $d;
  47. return substr($d,1,strlen($d)-2);
  48. }
  49. function BindTimeStamp($d)
  50. {
  51. $d = ADOConnection::DBTimeStamp($d);
  52. if (strncmp($d,"'",1)) return $d;
  53. return substr($d,1,strlen($d)-2);
  54. }
  55. function BeginTrans()
  56. {
  57. $this->autoCommit = false;
  58. ora_commitoff($this->_connectionID);
  59. return true;
  60. }
  61. function CommitTrans($ok=true)
  62. {
  63. if (!$ok) return $this->RollbackTrans();
  64. $ret = ora_commit($this->_connectionID);
  65. ora_commiton($this->_connectionID);
  66. return $ret;
  67. }
  68. function RollbackTrans()
  69. {
  70. $ret = ora_rollback($this->_connectionID);
  71. ora_commiton($this->_connectionID);
  72. return $ret;
  73. }
  74. /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */
  75. function ErrorMsg()
  76. {
  77. if ($this->_errorMsg !== false) return $this->_errorMsg;
  78. if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs);
  79. if (empty($this->_errorMsg)) $this->_errorMsg = @ora_error($this->_connectionID);
  80. return $this->_errorMsg;
  81. }
  82. function ErrorNo()
  83. {
  84. if ($this->_errorCode !== false) return $this->_errorCode;
  85. if (is_resource($this->_curs)) $this->_errorCode = @ora_errorcode($this->_curs);
  86. if (empty($this->_errorCode)) $this->_errorCode = @ora_errorcode($this->_connectionID);
  87. return $this->_errorCode;
  88. }
  89. // returns true or false
  90. function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0)
  91. {
  92. if (!function_exists('ora_plogon')) return null;
  93. // <G. Giunta 2003/03/03/> Reset error messages before connecting
  94. $this->_errorMsg = false;
  95. $this->_errorCode = false;
  96. // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set
  97. // the oracle home to the host name of remote DB?
  98. // if ($argHostname) putenv("ORACLE_HOME=$argHostname");
  99. if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <jorma.tuomainen@ppoy.fi>
  100. if (empty($argDatabasename)) $argDatabasename = $argHostname;
  101. else {
  102. if(strpos($argHostname,":")) {
  103. $argHostinfo=explode(":",$argHostname);
  104. $argHostname=$argHostinfo[0];
  105. $argHostport=$argHostinfo[1];
  106. } else {
  107. $argHostport="1521";
  108. }
  109. if ($this->connectSID) {
  110. $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
  111. .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";
  112. } else
  113. $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
  114. .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";
  115. }
  116. }
  117. if ($argDatabasename) $argUsername .= "@$argDatabasename";
  118. //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
  119. if ($mode == 1)
  120. $this->_connectionID = ora_plogon($argUsername,$argPassword);
  121. else
  122. $this->_connectionID = ora_logon($argUsername,$argPassword);
  123. if ($this->_connectionID === false) return false;
  124. if ($this->autoCommit) ora_commiton($this->_connectionID);
  125. if ($this->_initdate) {
  126. $rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
  127. if ($rs) ora_close($rs);
  128. }
  129. return true;
  130. }
  131. // returns true or false
  132. function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  133. {
  134. return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 1);
  135. }
  136. // returns query ID if successful, otherwise false
  137. function _query($sql,$inputarr=false)
  138. {
  139. // <G. Giunta 2003/03/03/> Reset error messages before executing
  140. $this->_errorMsg = false;
  141. $this->_errorCode = false;
  142. $curs = ora_open($this->_connectionID);
  143. if ($curs === false) return false;
  144. $this->_curs = $curs;
  145. if (!ora_parse($curs,$sql)) return false;
  146. if (ora_exec($curs)) return $curs;
  147. // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message
  148. // that we can obtain ONLY from the cursor (and not from the connection)
  149. $this->_errorCode = @ora_errorcode($curs);
  150. $this->_errorMsg = @ora_error($curs);
  151. // </G. Giunta 2004/03/03>
  152. @ora_close($curs);
  153. return false;
  154. }
  155. // returns true or false
  156. function _close()
  157. {
  158. return @ora_logoff($this->_connectionID);
  159. }
  160. }
  161. /*--------------------------------------------------------------------------------------
  162. Class Name: Recordset
  163. --------------------------------------------------------------------------------------*/
  164. class ADORecordset_oracle extends ADORecordSet {
  165. var $databaseType = "oracle";
  166. var $bind = false;
  167. function ADORecordset_oracle($queryID,$mode=false)
  168. {
  169. if ($mode === false) {
  170. global $ADODB_FETCH_MODE;
  171. $mode = $ADODB_FETCH_MODE;
  172. }
  173. $this->fetchMode = $mode;
  174. $this->_queryID = $queryID;
  175. $this->_inited = true;
  176. $this->fields = array();
  177. if ($queryID) {
  178. $this->_currentRow = 0;
  179. $this->EOF = !$this->_fetch();
  180. @$this->_initrs();
  181. } else {
  182. $this->_numOfRows = 0;
  183. $this->_numOfFields = 0;
  184. $this->EOF = true;
  185. }
  186. return $this->_queryID;
  187. }
  188. /* Returns: an object containing field information.
  189. Get column information in the Recordset object. fetchField() can be used in order to obtain information about
  190. fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
  191. fetchField() is retrieved. */
  192. function FetchField($fieldOffset = -1)
  193. {
  194. $fld = new ADOFieldObject;
  195. $fld->name = ora_columnname($this->_queryID, $fieldOffset);
  196. $fld->type = ora_columntype($this->_queryID, $fieldOffset);
  197. $fld->max_length = ora_columnsize($this->_queryID, $fieldOffset);
  198. return $fld;
  199. }
  200. /* Use associative array to get fields array */
  201. function Fields($colname)
  202. {
  203. if (!$this->bind) {
  204. $this->bind = array();
  205. for ($i=0; $i < $this->_numOfFields; $i++) {
  206. $o = $this->FetchField($i);
  207. $this->bind[strtoupper($o->name)] = $i;
  208. }
  209. }
  210. return $this->fields[$this->bind[strtoupper($colname)]];
  211. }
  212. function _initrs()
  213. {
  214. $this->_numOfRows = -1;
  215. $this->_numOfFields = @ora_numcols($this->_queryID);
  216. }
  217. function _seek($row)
  218. {
  219. return false;
  220. }
  221. function _fetch($ignore_fields=false) {
  222. // should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1
  223. if ($this->fetchMode & ADODB_FETCH_ASSOC)
  224. return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC);
  225. else
  226. return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS);
  227. }
  228. /* close() only needs to be called if you are worried about using too much memory while your script
  229. is running. All associated result memory for the specified result identifier will automatically be freed. */
  230. function _close()
  231. {
  232. return @ora_close($this->_queryID);
  233. }
  234. function MetaType($t,$len=-1)
  235. {
  236. if (is_object($t)) {
  237. $fieldobj = $t;
  238. $t = $fieldobj->type;
  239. $len = $fieldobj->max_length;
  240. }
  241. switch (strtoupper($t)) {
  242. case 'VARCHAR':
  243. case 'VARCHAR2':
  244. case 'CHAR':
  245. case 'VARBINARY':
  246. case 'BINARY':
  247. if ($len <= $this->blobSize) return 'C';
  248. case 'LONG':
  249. case 'LONG VARCHAR':
  250. case 'CLOB':
  251. return 'X';
  252. case 'LONG RAW':
  253. case 'LONG VARBINARY':
  254. case 'BLOB':
  255. return 'B';
  256. case 'DATE': return 'D';
  257. //case 'T': return 'T';
  258. case 'BIT': return 'L';
  259. case 'INT':
  260. case 'SMALLINT':
  261. case 'INTEGER': return 'I';
  262. default: return 'N';
  263. }
  264. }
  265. }
  266. ?>