"fixed ambiguous column sql-error by adding table-name to id over which we join"

This commit is contained in:
Ralf Becker 2010-04-04 08:59:37 +00:00
parent 928a38d5cf
commit a45ea03b19

View File

@ -919,6 +919,11 @@ class so_sql
}
if ($extra_cols) $colums .= ($colums ? ',' : '').(is_array($extra_cols) ? implode(',',$extra_cols) : $extra_cols);
// add table-name to otherwise ambiguous id over which we join (incl. "AS id" to return it with the right name)
if ($join && $this->autoinc_id && strpos($colums,$this->autoinc_id) !== false)
{
$colums = preg_replace('/([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/','\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2',$colums);
}
$num_rows = 0; // as spec. in max_matches in the user-prefs
if (is_array($start)) list($start,$num_rows) = $start;