TYPO3 CMS  TYPO3_6-2
adodb-db2oci.inc.php
Go to the documentation of this file.
1 <?php
2 /*
3 V5.19 23-Apr-2014 (c) 2000-2014 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 Set tabs to 4 for best viewing.
8 
9  Latest version is available at http://adodb.sourceforge.net
10 
11  Microsoft Visual FoxPro data driver. Requires ODBC. Works only on MS Windows.
12 */
13 
14 // security - hide paths
15 if (!defined('ADODB_DIR')) die();
16 include(ADODB_DIR."/drivers/adodb-db2.inc.php");
17 
18 
19 if (!defined('ADODB_DB2OCI')){
20 define('ADODB_DB2OCI',1);
21 
22 /*
23 // regex code for smart remapping of :0, :1 bind vars to ? ?
24 function _colontrack($p)
25 {
26 global $_COLONARR,$_COLONSZ;
27  $v = (integer) substr($p,1);
28  if ($v > $_COLONSZ) return $p;
29  $_COLONARR[] = $v;
30  return '?';
31 }
32 
33 // smart remapping of :0, :1 bind vars to ? ?
34 function _colonscope($sql,$arr)
35 {
36 global $_COLONARR,$_COLONSZ;
37 
38  $_COLONARR = array();
39  $_COLONSZ = sizeof($arr);
40 
41  $sql2 = preg_replace("/(:[0-9]+)/e","_colontrack('\\1')",$sql);
42 
43  if (empty($_COLONARR)) return array($sql,$arr);
44 
45  foreach($_COLONARR as $k => $v) {
46  $arr2[] = $arr[$v];
47  }
48 
49  return array($sql2,$arr2);
50 }
51 */
52 
53 /*
54  Smart remapping of :0, :1 bind vars to ? ?
55 
56  Handles colons in comments -- and / * * / and in quoted strings.
57 */
58 
59 function _colonparser($sql,$arr)
60 {
61  $lensql = strlen($sql);
62  $arrsize = sizeof($arr);
63  $state = 'NORM';
64  $at = 1;
65  $ch = $sql[0];
66  $ch2 = @$sql[1];
67  $sql2 = '';
68  $arr2 = array();
69  $nprev = 0;
70 
71 
72  while (strlen($ch)) {
73 
74  switch($ch) {
75  case '/':
76  if ($state == 'NORM' && $ch2 == '*') {
77  $state = 'COMMENT';
78 
79  $at += 1;
80  $ch = $ch2;
81  $ch2 = $at < $lensql ? $sql[$at] : '';
82  }
83  break;
84 
85  case '*':
86  if ($state == 'COMMENT' && $ch2 == '/') {
87  $state = 'NORM';
88 
89  $at += 1;
90  $ch = $ch2;
91  $ch2 = $at < $lensql ? $sql[$at] : '';
92  }
93  break;
94 
95  case "\n":
96  case "\r":
97  if ($state == 'COMMENT2') $state = 'NORM';
98  break;
99 
100  case "'":
101  do {
102  $at += 1;
103  $ch = $ch2;
104  $ch2 = $at < $lensql ? $sql[$at] : '';
105  } while ($ch !== "'");
106  break;
107 
108  case ':':
109  if ($state == 'COMMENT' || $state == 'COMMENT2') break;
110 
111  //echo "$at=$ch $ch2, ";
112  if ('0' <= $ch2 && $ch2 <= '9') {
113  $n = '';
114  $nat = $at;
115  do {
116  $at += 1;
117  $ch = $ch2;
118  $n .= $ch;
119  $ch2 = $at < $lensql ? $sql[$at] : '';
120  } while ('0' <= $ch && $ch <= '9');
121  #echo "$n $arrsize ] ";
122  $n = (integer) $n;
123  if ($n < $arrsize) {
124  $sql2 .= substr($sql,$nprev,$nat-$nprev-1).'?';
125  $nprev = $at-1;
126  $arr2[] = $arr[$n];
127  }
128  }
129  break;
130 
131  case '-':
132  if ($state == 'NORM') {
133  if ($ch2 == '-') $state = 'COMMENT2';
134  $at += 1;
135  $ch = $ch2;
136  $ch2 = $at < $lensql ? $sql[$at] : '';
137  }
138  break;
139  }
140 
141  $at += 1;
142  $ch = $ch2;
143  $ch2 = $at < $lensql ? $sql[$at] : '';
144  }
145 
146  if ($nprev == 0) {
147  $sql2 = $sql;
148  } else {
149  $sql2 .= substr($sql,$nprev);
150  }
151 
152  return array($sql2,$arr2);
153 }
154 
155 class ADODB_db2oci extends ADODB_db2 {
156  var $databaseType = "db2oci";
157  var $sysTimeStamp = 'sysdate';
158  var $sysDate = 'trunc(sysdate)';
159  var $_bindInputArray = true;
160 
161  function ADODB_db2oci()
162  {
163  parent::ADODB_db2();
164  }
165 
166  function Param($name,$type='C')
167  {
168  return ':'.$name;
169  }
170 
171 
172  function MetaTables($ttype=false,$schema=false)
173  {
174  global $ADODB_FETCH_MODE;
175 
176  $savem = $ADODB_FETCH_MODE;
177  $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
178  $qid = db2_tables($this->_connectionID);
179 
180  $rs = new ADORecordSet_db2($qid);
181 
182  $ADODB_FETCH_MODE = $savem;
183  if (!$rs) {
184  $false = false;
185  return $false;
186  }
187 
188  $arr = $rs->GetArray();
189  $rs->Close();
190  $arr2 = array();
191  // adodb_pr($arr);
192  if ($ttype) {
193  $isview = strncmp($ttype,'V',1) === 0;
194  }
195  for ($i=0; $i < sizeof($arr); $i++) {
196  if (!$arr[$i][2]) continue;
197  $type = $arr[$i][3];
198  $schemaval = ($schema) ? $arr[$i][1].'.' : '';
199  $name = $schemaval.$arr[$i][2];
200  $owner = $arr[$i][1];
201  if (substr($name,0,8) == 'EXPLAIN_') continue;
202  if ($ttype) {
203  if ($isview) {
204  if (strncmp($type,'V',1) === 0) $arr2[] = $name;
205  } else if (strncmp($type,'T',1) === 0 && strncmp($owner,'SYS',3) !== 0) $arr2[] = $name;
206  } else if (strncmp($type,'T',1) === 0 && strncmp($owner,'SYS',3) !== 0) $arr2[] = $name;
207  }
208  return $arr2;
209  }
210 
211  function _Execute($sql, $inputarr=false )
212  {
213  if ($inputarr) list($sql,$inputarr) = _colonparser($sql, $inputarr);
214  return parent::_Execute($sql, $inputarr);
215  }
216 };
217 
218 
219 class ADORecordSet_db2oci extends ADORecordSet_db2 {
220 
221  var $databaseType = "db2oci";
222 
223  function ADORecordSet_db2oci($id,$mode=false)
224  {
225  return $this->ADORecordSet_db2($id,$mode);
226  }
227 }
228 
229 } //define
$sql
Definition: server.php:82
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:92
die
Definition: index.php:6
MetaTables($ttype=false, $schema=false)