}
break;
- /* Returns an array of __all__ pages, where each entry is made up
- of the fields from the database requested with the $args array,
- e.g. array("flags","meta","lastmodified");
+ /* Returns an array of the lastest versions of __all__ pages,
+ where each entry is made up of the fields from the database
+ requested with the $args array, e.g.
+ array("flags","meta","lastmodified");
*/
case "GETALL":
switch ($CFG->dbfamily) {
case 'postgres':
- $sql= "SELECT pagename AS id, ".
+ // All but the latest version eliminated by DISTINCT
+ // ON (pagename)
+ $sql= "SELECT DISTINCT ON (pagename) pagename AS id, ".
implode(", ", $args) .
" FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
" WHERE wiki = ".$wiki_entry->id.
- " GROUP BY pagename, ".implode(", ", $args);
+ " ORDER BY pagename, version DESC";
break;
+ case 'mysql':
+ // All but the latest version eliminated by
+ // mysql-specific GROUP BY-semantics
+ $sql= "SELECT pagename AS id, ".
+ implode(", ", $args) .
+ " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
+ " WHERE wiki = ".$wiki_entry->id.
+ " GROUP BY id, version DESC " ;
default:
+ // All but the latest version are here eliminated in
+ // get_records_sql, since it will return an array
+ // with only one result per id-field value. Note,
+ // that for this to work the query needs to order the
+ // records ascending by version, so later versions
+ // will overwrite previous ones in
+ // recordset_to_array. This is not pretty.
$sql= "SELECT pagename AS id, ".
implode(", ", $args) .
" FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
" WHERE wiki = ".$wiki_entry->id.
- " GROUP BY id, version " ;
+ " ORDER BY version";
}
- #print "$sql";
$result=get_records_sql($sql);
$r = new ewiki_dbquery_result($args);
- $drop = "";
- #while ($result && ($row = mysql_fetch_array($result, MYSQL_ASSOC))) {
- # $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"];
- # if ($i != $drop) {
- # $drop = $i;
- # $r->add($row);
- # }
- #}
- #print "<pre>"; print_r($result); print "</pre>";
- if(!$result) {
- $result=array();
- }
- while(list($key, $val) = each($result)) {
- $row=get_object_vars($val);
- $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"];
- if ($i != $drop) {
- $drop = $i;
- $r->add($row);
- }
+ if ($result) {
+ foreach($result as $val) {
+ $r->add(get_object_vars($val));
+ }
}
break;