diff options
-rw-r--r-- | class/TableIterator.php | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/class/TableIterator.php b/class/TableIterator.php index 6e44c18..6cc85e9 100644 --- a/class/TableIterator.php +++ b/class/TableIterator.php @@ -72,16 +72,22 @@ class TableIterator implements Iterator $this->_sql = $table; } else { // check field, orderby, limit, start in criterias - $field=""; - $orderby=""; - $limit=0; - $start=0; + $field = ''; + $orderby = ''; + $limit = 0; + $start = 0; + $distinct = ''; if (is_array($crit) && count($crit)) { foreach ($crit as $key => $val) { if ($key==="FIELDS") { $field = $val; unset($crit[$key]); + } else if ($key==="DISTINCT") { + if ($val) { + $distinct = $key; + } + unset($crit[$key]); } else if ($key==="ORDER") { $orderby = $val; unset($crit[$key]); @@ -101,19 +107,19 @@ class TableIterator implements Iterator foreach ($field as $t => $f) { if (is_numeric($t)) { $this->_sql .= (empty($this->_sql) - ? "SELECT " : ",") . $f; + ? "SELECT $distinct " : ",") . $f; } else if (is_array($f)) { $this->_sql .= (empty($this->_sql) - ? "SELECT $t." : ",$t.") . implode(",$t.", $f); + ? "SELECT $distinct $t." : ",$t.") . implode(",$t.", $f); } else { $this->_sql .= (empty($this->_sql) - ? "SELECT " : ",") . "$t.$f"; + ? "SELECT $distinct " : ",") . "$t.$f"; } } } else if (empty($field)) { $this->_sql = "SELECT *"; } else { - $this->_sql = "SELECT `$field`"; + $this->_sql = "SELECT $distinct `$field`"; } // FROM table list if (is_array($table)) { @@ -206,9 +212,12 @@ class TableIterator implements Iterator } else if (is_numeric($value)) { // Integer $ret .= "$name=$value"; - } else { + } else if (strpos($value,'%')===false){ // String $ret .= "$name='$value'"; + } else { + // String with pattern + $ret .= "$name LIKE '$value'"; } } return $ret; |