PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 218 lines | 151 code | 26 blank | 41 comment | 37 complexity | 95847e7134b03319bd96518e2fafffa2 MD5 | raw file
  1. <?php
  2. /*
  3. V5.10 10 Nov 2009 (c) 2000-2009 John Lim. 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. Portable version of oci8 driver, to make it more similar to other database drivers.
  9. The main differences are
  10. 1. that the OCI_ASSOC names are in lowercase instead of uppercase.
  11. 2. bind variables are mapped using ? instead of :<bindvar>
  12. Should some emulation of RecordCount() be implemented?
  13. */
  14. // security - hide paths
  15. if (!defined('ADODB_DIR')) die();
  16. include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
  17. class ADODB_oci8po extends ADODB_oci8 {
  18. var $databaseType = 'oci8po';
  19. var $dataProvider = 'oci8';
  20. 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
  21. var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
  22. function ADODB_oci8po()
  23. {
  24. $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200;
  25. # oci8po does not support adodb extension: adodb_movenext()
  26. }
  27. function Param($name)
  28. {
  29. return '?';
  30. }
  31. function Prepare($sql,$cursor=false)
  32. {
  33. $sqlarr = explode('?',$sql);
  34. $sql = $sqlarr[0];
  35. for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
  36. $sql .= ':'.($i-1) . $sqlarr[$i];
  37. }
  38. return ADODB_oci8::Prepare($sql,$cursor);
  39. }
  40. // emulate handling of parameters ? ?, replacing with :bind0 :bind1
  41. function _query($sql,$inputarr=false)
  42. {
  43. if (is_array($inputarr)) {
  44. $i = 0;
  45. if (is_array($sql)) {
  46. foreach($inputarr as $v) {
  47. $arr['bind'.$i++] = $v;
  48. }
  49. } else {
  50. $sqlarr = explode('?',$sql);
  51. $sql = $sqlarr[0];
  52. foreach($inputarr as $k => $v) {
  53. $sql .= ":$k" . $sqlarr[++$i];
  54. }
  55. }
  56. }
  57. return ADODB_oci8::_query($sql,$inputarr);
  58. }
  59. }
  60. /*--------------------------------------------------------------------------------------
  61. Class Name: Recordset
  62. --------------------------------------------------------------------------------------*/
  63. class ADORecordset_oci8po extends ADORecordset_oci8 {
  64. var $databaseType = 'oci8po';
  65. function ADORecordset_oci8po($queryID,$mode=false)
  66. {
  67. $this->ADORecordset_oci8($queryID,$mode);
  68. }
  69. function Fields($colname)
  70. {
  71. if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
  72. if (!$this->bind) {
  73. $this->bind = array();
  74. for ($i=0; $i < $this->_numOfFields; $i++) {
  75. $o = $this->FetchField($i);
  76. $this->bind[strtoupper($o->name)] = $i;
  77. }
  78. }
  79. return $this->fields[$this->bind[strtoupper($colname)]];
  80. }
  81. // lowercase field names...
  82. function _FetchField($fieldOffset = -1)
  83. {
  84. $fld = new ADOFieldObject;
  85. $fieldOffset += 1;
  86. $fld->name = OCIcolumnname($this->_queryID, $fieldOffset);
  87. if (ADODB_ASSOC_CASE == 0) $fld->name = strtolower($fld->name);
  88. $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
  89. $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
  90. if ($fld->type == 'NUMBER') {
  91. //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
  92. $sc = OCIColumnScale($this->_queryID, $fieldOffset);
  93. if ($sc == 0) $fld->type = 'INT';
  94. }
  95. return $fld;
  96. }
  97. /*
  98. function MoveNext()
  99. {
  100. if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
  101. $this->_currentRow += 1;
  102. return true;
  103. }
  104. if (!$this->EOF) {
  105. $this->_currentRow += 1;
  106. $this->EOF = true;
  107. }
  108. return false;
  109. }*/
  110. // 10% speedup to move MoveNext to child class
  111. function MoveNext()
  112. {
  113. if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
  114. global $ADODB_ANSI_PADDING_OFF;
  115. $this->_currentRow++;
  116. if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
  117. if (!empty($ADODB_ANSI_PADDING_OFF)) {
  118. foreach($this->fields as $k => $v) {
  119. if (is_string($v)) $this->fields[$k] = rtrim($v);
  120. }
  121. }
  122. return true;
  123. }
  124. if (!$this->EOF) {
  125. $this->EOF = true;
  126. $this->_currentRow++;
  127. }
  128. return false;
  129. }
  130. /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
  131. function GetArrayLimit($nrows,$offset=-1)
  132. {
  133. if ($offset <= 0) {
  134. $arr = $this->GetArray($nrows);
  135. return $arr;
  136. }
  137. for ($i=1; $i < $offset; $i++)
  138. if (!@OCIFetch($this->_queryID)) {
  139. $arr = array();
  140. return $arr;
  141. }
  142. if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
  143. $arr = array();
  144. return $arr;
  145. }
  146. if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
  147. $results = array();
  148. $cnt = 0;
  149. while (!$this->EOF && $nrows != $cnt) {
  150. $results[$cnt++] = $this->fields;
  151. $this->MoveNext();
  152. }
  153. return $results;
  154. }
  155. // Create associative array
  156. function _updatefields()
  157. {
  158. if (ADODB_ASSOC_CASE == 2) return; // native
  159. $arr = array();
  160. $lowercase = (ADODB_ASSOC_CASE == 0);
  161. foreach($this->fields as $k => $v) {
  162. if (is_integer($k)) $arr[$k] = $v;
  163. else {
  164. if ($lowercase)
  165. $arr[strtolower($k)] = $v;
  166. else
  167. $arr[strtoupper($k)] = $v;
  168. }
  169. }
  170. $this->fields = $arr;
  171. }
  172. function _fetch()
  173. {
  174. $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
  175. if ($ret) {
  176. global $ADODB_ANSI_PADDING_OFF;
  177. if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
  178. if (!empty($ADODB_ANSI_PADDING_OFF)) {
  179. foreach($this->fields as $k => $v) {
  180. if (is_string($v)) $this->fields[$k] = rtrim($v);
  181. }
  182. }
  183. }
  184. return $ret;
  185. }
  186. }
  187. ?>