PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/adodb/adodb-php/drivers/adodb-oci8po.inc.php

https://bitbucket.org/openemr/openemr
PHP | 204 lines | 148 code | 26 blank | 30 comment | 28 complexity | 6a8af98939bc1f172a3aa3fd996e6c31 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, LGPL-3.0, BSD-3-Clause, Unlicense, MPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. @version v5.20.2 27-Dec-2015
  4. @copyright (c) 2000-2013 John Lim. All rights reserved.
  5. @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. Released under both BSD license and Lesser GPL library license.
  7. Whenever there is any discrepancy between the two licenses,
  8. the BSD license will take precedence.
  9. Latest version is available at http://adodb.sourceforge.net
  10. Portable version of oci8 driver, to make it more similar to other database drivers.
  11. The main differences are
  12. 1. that the OCI_ASSOC names are in lowercase instead of uppercase.
  13. 2. bind variables are mapped using ? instead of :<bindvar>
  14. Should some emulation of RecordCount() be implemented?
  15. */
  16. // security - hide paths
  17. if (!defined('ADODB_DIR')) die();
  18. include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
  19. class ADODB_oci8po extends ADODB_oci8 {
  20. var $databaseType = 'oci8po';
  21. var $dataProvider = 'oci8';
  22. var $metaColumnsSQL = "select lower(cname),coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net
  23. var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
  24. function __construct()
  25. {
  26. $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200;
  27. # oci8po does not support adodb extension: adodb_movenext()
  28. }
  29. function Param($name,$type='C')
  30. {
  31. return '?';
  32. }
  33. function Prepare($sql,$cursor=false)
  34. {
  35. $sqlarr = explode('?',$sql);
  36. $sql = $sqlarr[0];
  37. for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
  38. $sql .= ':'.($i-1) . $sqlarr[$i];
  39. }
  40. return ADODB_oci8::Prepare($sql,$cursor);
  41. }
  42. function Execute($sql,$inputarr=false)
  43. {
  44. return ADOConnection::Execute($sql,$inputarr);
  45. }
  46. // emulate handling of parameters ? ?, replacing with :bind0 :bind1
  47. function _query($sql,$inputarr=false)
  48. {
  49. if (is_array($inputarr)) {
  50. $i = 0;
  51. if (is_array($sql)) {
  52. foreach($inputarr as $v) {
  53. $arr['bind'.$i++] = $v;
  54. }
  55. } else {
  56. // Need to identify if the ? is inside a quoted string, and if
  57. // so not use it as a bind variable
  58. preg_match_all('/".*\??"|\'.*\?.*?\'/', $sql, $matches);
  59. foreach($matches[0] as $qmMatch){
  60. $qmReplace = str_replace('?', '-QUESTIONMARK-', $qmMatch);
  61. $sql = str_replace($qmMatch, $qmReplace, $sql);
  62. }
  63. $sqlarr = explode('?',$sql);
  64. $sql = $sqlarr[0];
  65. foreach($inputarr as $k => $v) {
  66. $sql .= ":$k" . $sqlarr[++$i];
  67. }
  68. $sql = str_replace('-QUESTIONMARK-', '?', $sql);
  69. }
  70. }
  71. return ADODB_oci8::_query($sql,$inputarr);
  72. }
  73. }
  74. /*--------------------------------------------------------------------------------------
  75. Class Name: Recordset
  76. --------------------------------------------------------------------------------------*/
  77. class ADORecordset_oci8po extends ADORecordset_oci8 {
  78. var $databaseType = 'oci8po';
  79. function __construct($queryID,$mode=false)
  80. {
  81. parent::__construct($queryID,$mode);
  82. }
  83. function Fields($colname)
  84. {
  85. if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
  86. if (!$this->bind) {
  87. $this->bind = array();
  88. for ($i=0; $i < $this->_numOfFields; $i++) {
  89. $o = $this->FetchField($i);
  90. $this->bind[strtoupper($o->name)] = $i;
  91. }
  92. }
  93. return $this->fields[$this->bind[strtoupper($colname)]];
  94. }
  95. // lowercase field names...
  96. function _FetchField($fieldOffset = -1)
  97. {
  98. $fld = new ADOFieldObject;
  99. $fieldOffset += 1;
  100. $fld->name = OCIcolumnname($this->_queryID, $fieldOffset);
  101. if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_LOWER) {
  102. $fld->name = strtolower($fld->name);
  103. }
  104. $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
  105. $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
  106. if ($fld->type == 'NUMBER') {
  107. $sc = OCIColumnScale($this->_queryID, $fieldOffset);
  108. if ($sc == 0) {
  109. $fld->type = 'INT';
  110. }
  111. }
  112. return $fld;
  113. }
  114. // 10% speedup to move MoveNext to child class
  115. function MoveNext()
  116. {
  117. if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
  118. global $ADODB_ANSI_PADDING_OFF;
  119. $this->_currentRow++;
  120. $this->_updatefields();
  121. if (!empty($ADODB_ANSI_PADDING_OFF)) {
  122. foreach($this->fields as $k => $v) {
  123. if (is_string($v)) $this->fields[$k] = rtrim($v);
  124. }
  125. }
  126. return true;
  127. }
  128. if (!$this->EOF) {
  129. $this->EOF = true;
  130. $this->_currentRow++;
  131. }
  132. return false;
  133. }
  134. /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
  135. function GetArrayLimit($nrows,$offset=-1)
  136. {
  137. if ($offset <= 0) {
  138. $arr = $this->GetArray($nrows);
  139. return $arr;
  140. }
  141. for ($i=1; $i < $offset; $i++)
  142. if (!@OCIFetch($this->_queryID)) {
  143. $arr = array();
  144. return $arr;
  145. }
  146. if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
  147. $arr = array();
  148. return $arr;
  149. }
  150. $this->_updatefields();
  151. $results = array();
  152. $cnt = 0;
  153. while (!$this->EOF && $nrows != $cnt) {
  154. $results[$cnt++] = $this->fields;
  155. $this->MoveNext();
  156. }
  157. return $results;
  158. }
  159. function _fetch()
  160. {
  161. global $ADODB_ANSI_PADDING_OFF;
  162. $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
  163. if ($ret) {
  164. $this->_updatefields();
  165. if (!empty($ADODB_ANSI_PADDING_OFF)) {
  166. foreach($this->fields as $k => $v) {
  167. if (is_string($v)) $this->fields[$k] = rtrim($v);
  168. }
  169. }
  170. }
  171. return $ret;
  172. }
  173. }