propelorm/Propel — Issue #216: DBAdapter.php incorrect check for space before table name
Author: ChrisSharman
Created: 2011-12-04 09:35:38+00:00
State: open

I think there's a bug in lines 361-371 of DBAdapter.php.
Hopefully this is the right place to discuss?
It's trying to extract table name from a column expression, having
found the last '(' and the last '.' after it. It's looking for a
space.
2 issues -
a. $tableName is still null, so strpos isn't going to find a space.
b. it should be looking for the last space, not the first.
as it stands it doesn't handle 'IF(a, FLOOR(t.b), t.c)' properly - it
thinks 't.b), t' is the table name.
Workaround: parenthesize t.c
Fix below - not perfect but does as I think was intended.

Chris

Original:
} else { // FUNC(table.column)
// functions may contain qualifiers so only take the last
// word as the table name.
// COUNT(DISTINCT books.price)
$lastSpace = strpos($tableName, ' ');
if ($lastSpace !== false) { // COUNT(DISTINCT books.price)
$tableName = substr($tableName, $lastSpace + 1);
} else {
$tableName = substr($columnName, $parenPos + 1, $dotPos
- ($parenPos + 1));
}
}
Suggested correction: (preset tableName & use strrpos
} else { // FUNC(table.column)
// functions may contain qualifiers so only take the last
// word as the table name.
// COUNT(DISTINCT books.price)
$tableName = substr($columnName, $parenPos + 1, $dotPos -
($parenPos + 1));
$lastSpace = strrpos($tableName, ' ');
if ($lastSpace !== false) { // COUNT(DISTINCT books.price)
$tableName = substr($tableName, $lastSpace + 1);
}
}