61 if (!defined(
'ADODB_DIR'))
die();
63 if (! defined(
"_ADODB_TEXT_LAYER")) {
64 define(
"_ADODB_TEXT_LAYER", 1 );
67 function adodb_cmp($a, $b) {
68 if ($a[0] == $b[0])
return 0;
69 return ($a[0] < $b[0]) ? -1 : 1;
72 function adodb_cmpr($a, $b) {
73 if ($a[0] == $b[0])
return 0;
74 return ($a[0] > $b[0]) ? -1 : 1;
76 class ADODB_text
extends ADOConnection {
77 var $databaseType =
'text';
85 var $hasTransactions =
false;
95 function RSRecordCount()
97 if (!empty($this->_rezarray))
return sizeof($this->_rezarray);
99 return sizeof($this->_origarray);
107 function _affectedrows()
113 function PConnect(&$array, $types =
false, $colnames =
false)
115 return $this->Connect($array, $types, $colnames);
118 function Connect(&$array, $types =
false, $colnames =
false)
120 if (is_string($array) and $array ===
'iluvphplens')
return 'me2';
123 $this->_origarray =
false;
127 $cols =
sizeof($row);
130 if ($colnames) $this->_colnames = $colnames;
132 $this->_colnames = $array[0];
133 $this->_skiprow1 =
true;
139 if ($this->_proberows >
sizeof($array)) $max =
sizeof($array);
140 else $max = $this->_proberows;
141 for ($j=($this->_skiprow1)?1:0;$j < $max; $j++) {
145 foreach($row as $v) {
149 if (!preg_match(
'/^[+-]{0,1}[0-9\.]+$/',$v)) {
153 if (isset($types[$i]) && $types[$i]==
'C')
continue;
159 if (strlen($v) == 0) $types[0] =
'C';
160 if (strpos($v,
'.') !==
false) $types[0] =
'N';
161 else $types[$i] =
'I';
165 if (strpos($v,
'.') !==
false) $types[$i] =
'N';
172 $this->_origarray = $array;
173 $this->_types = $types;
184 function _query(
$sql,$input_arr,$eval=
false)
186 if ($this->_origarray ===
false)
return false;
188 $eval = $this->evalAll;
189 $usql = strtoupper(trim(
$sql));
190 $usql = preg_replace(
"/[\t\n\r]/",
' ',$usql);
191 $usql = preg_replace(
'/ *BY/i',
' BY',strtoupper($usql));
193 $eregword =
'([A-Z_0-9]*)';
197 foreach($this->_colnames as $n) {
198 $n = strtoupper(trim($n));
199 $eval = str_replace(
"\$$n",
"\$arr[$i]",$eval);
205 $eval =
"\$rez=($eval);";
207 $where_arr = array();
209 reset($this->_origarray);
210 while (list($k_arr,$arr) = each($this->_origarray)) {
212 if ($i == 0 && $this->_skiprow1)
217 if ($rez) $where_arr[] = $arr;
221 $this->_rezarray = $where_arr;
223 $where_arr = $this->_origarray;
227 if (substr($usql,0,7) ==
'SELECT ') {
228 $at = strpos($usql,
' FROM ');
229 $sel = trim(substr($usql,7,$at-7));
232 if (substr($sel,0,8) ==
'DISTINCT') {
234 $sel = trim(substr($sel,8,$at));
240 if (strpos(
',',$sel)===
false) {
243 preg_match(
"/$eregword/",$sel,$colarr);
247 reset($this->_colnames);
248 while (list($k_n,$n) = each($this->_colnames)) {
250 if ($col == strtoupper(trim($n)))
break;
256 $projarray = array();
257 $projtypes = array($this->_types[$i]);
258 $projnames = array($n);
261 while (list($k_a,$a) = each($where_arr)) {
262 if ($i == 0 && $this->_skiprow1) {
263 $projarray[] = array($n);
268 $v = strtoupper($a[$i]);
269 if (! $distarr[$v]) {
270 $projarray[] = array($a[$i]);
274 $projarray[] = array($a[$i]);
282 if (empty($projarray)) {
283 $projtypes = $this->_types;
284 $projarray = $where_arr;
285 $projnames = $this->_colnames;
287 $this->_rezarray = $projarray;
288 $this->_reztypes = $projtypes;
289 $this->_reznames = $projnames;
292 $pos = strpos($usql,
' ORDER BY ');
293 if ($pos ===
false)
return $this;
294 $orderby = trim(substr($usql,$pos+10));
296 preg_match(
"/$eregword/",$orderby,$arr);
297 if (
sizeof($arr) < 2)
return $this;
299 $at = (integer) $col;
303 while (list($k_n,$n) = each($projnames)) {
304 if (strtoupper(trim($n)) == $col) {
312 if ($at <= 0 || $at >
sizeof($projarray[0]))
return $this;
317 $t = $projtypes[$at];
318 $num = ($t ==
'I' || $t ==
'N');
319 for ($i=($this->_skiprow1)?1:0, $max =
sizeof($projarray); $i < $max; $i++) {
320 $row = $projarray[$i];
321 $val = ($num)?(
float)$row[$at]:$row[$at];
322 $sorta[]=array($val,$i);
326 $orderby = substr($orderby,strlen($col)+1);
328 preg_match(
'/([A-Z_0-9]*)/i',$orderby,$arr);
330 if (trim($arr[1]) ==
'DESC') $sortf =
'adodb_cmpr';
331 else $sortf =
'adodb_cmp';
334 usort($sorta, $sortf);
338 if ($this->_skiprow1) $arr2[] = $projarray[0];
339 foreach($sorta as $v) {
340 $arr2[] = $projarray[$v[1]];
343 $this->_rezarray = $arr2;
372 class ADORecordSet_text
extends ADORecordSet_array
375 var $databaseType =
"text";
377 function ADORecordSet_text(&
$conn,$mode=
false)
379 $this->ADORecordSet_array();
381 $conn->_rezarray =
false;