diff options
author | Remi Collet <fedora@famillecollet.com> | 2010-11-07 12:00:55 +0100 |
---|---|---|
committer | Remi Collet <fedora@famillecollet.com> | 2010-11-07 12:00:55 +0100 |
commit | e90245ea31dacef30ff5ee12c37143c3043a948a (patch) | |
tree | 71463b5a482b66ebe430c0db69fe0a11831b28c3 /class | |
parent | 80bbd251954928665af0521523652f2ae0190913 (diff) |
handle SELECT DISTINCT ...
Diffstat (limited to 'class')
-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; |