$b[0]) ? -1 : 1;
}
class ADODB_text extends ADOConnection {
var $databaseType = 'text';
var $_origarray; // original data
var $_types;
var $_proberows = 8;
var $_colnames;
var $_skiprow1=false;
var $readOnly = true;
var $hasTransactions = false;
var $_rezarray;
var $_reznames;
var $_reztypes;
function RSRecordCount()
{
if (!empty($this->_rezarray)) return sizeof($this->_rezarray);
return sizeof($this->_origarray);
}
function _affectedrows()
{
return false;
}
// returns true or false
function PConnect(&$array, $types = false, $colnames = false)
{
return $this->Connect($array, $types, $colnames);
}
// returns true or false
function Connect(&$array, $types = false, $colnames = false)
{
if (is_string($array) and $array === 'iluvphplens') return 'me2';
if (!$array) {
$this->_origarray = false;
return true;
}
$row = $array[0];
$cols = sizeof($row);
if ($colnames) $this->_colnames = $colnames;
else {
$this->_colnames = $array[0];
$this->_skiprow1 = true;
}
if (!$types) {
// probe and guess the type
$types = array();
$firstrow = true;
if ($this->_proberows > sizeof($array)) $max = sizeof($array);
else $max = $this->_proberows;
for ($j=($this->_skiprow1)?1:0;$j < $max; $j++) {
$row = $array[$j];
if (!$row) break;
$i = -1;
foreach($row as $v) {
$i += 1;
//print " ($i ".$types[$i]. "$v) ";
$v = trim($v);
if (!preg_match('/^[+-]{0,1}[0-9\.]+$/',$v)) {
$types[$i] = 'C'; // once C, always C
continue;
}
if (isset($types[$i]) && $types[$i]=='C') continue;
if ($firstrow) {
// If empty string, we presume is character
// test for integer for 1st row only
// after that it is up to testing other rows to prove
// that it is not an integer
if (strlen($v) == 0) $types[0] = 'C';
if (strpos($v,'.') !== false) $types[0] = 'N';
else $types[$i] = 'I';
continue;
}
if (strpos($v,'.') !== false) $types[$i] = 'N';
}
$firstrow = false;
}
}
//print_r($types);
$this->_origarray = $array;
$this->_types = $types;
return true;
}
// returns queryID or false
// We presume that the select statement is on the same table (what else?),
// with the only difference being the order by.
//You can filter by using $eval and each clause is stored in $arr .eg. $arr[1] == 'name'
// also supports SELECT [DISTINCT] COL FROM ... -- only 1 col supported
function _query($sql,$input_arr,$eval=false)
{
if ($this->_origarray === false) return false;
$eval = $this->evalAll;
$usql = strtoupper(trim($sql));
$usql = preg_replace("/[\t\n\r]/",' ',$usql);
$usql = preg_replace('/ *BY/i',' BY',strtoupper($usql));
$eregword ='([A-Z_0-9]*)';
//print "
$sql $eval ";
if ($eval) {
$i = 0;
foreach($this->_colnames as $n) {
$n = strtoupper(trim($n));
$eval = str_replace("\$$n","\$arr[$i]",$eval);
$i += 1;
}
$i = 0;
$eval = "\$rez=($eval);";
//print "
Eval string = $eval
"; $where_arr = array(); reset($this->_origarray); foreach ($this->_origarray as $arr) { if ($i == 0 && $this->_skiprow1) $where_arr[] = $arr; else { eval($eval); //print " $i: result=$rez arr[0]={$arr[0]} arr[1]={$arr[1]}