On Wed, May 7, 2008 at 8:44 PM, DanTMan <dan_the_man(a)telus.net> wrote:
Well... I was worried about people with tables like
"onsomething" or
whatever... But I suppose I can test strictly for things with whitespace
around them "/(^|\s)(ON|JOIN)(\s|$)/i" that should solve the issue.
Or use \b, that's what it's there for.
But I still think 3 is good. IMHO we should probably
do 5 and 3 for best
practice and avoidance of future issues.
Maybe, given how the API has its own database handling layer anyway, seemingly.
Actually, I used to do something to the Database
class. I actually had a
tweak for select and a few other functions. I basically added a extra
parameter $doQuery to the end which defaulted to true. Basically it
meant that you could explicitly send false and have select return a SQL
statement for you instead. That way you could go as far as to use
select, then manually UNION them together. But what would be absolutely
beautiful would be:
list( $user, $ug, $ugS) = $db->tableNameN('user', 'user_groups', $ug
=
$db->tableName("`$wgSharedDB`.`{$wgSharedPrefix}user_groups`");
$res = $db->union(
$db-join( $db->select( $user, conds, etc..., /*doQuery=*/false ),
$ug, conds, etc..., /*doQuery=*/false ),
$db-join( $db->select( $user, conds, etc..., /*doQuery=*/false ),
$ugS, conds, etc..., /*doQuery=*/false ),
);
^_^ Which basically, would have select return sql which join uses to
construct a join statement for. And then union, well... Unions them
together.
Operator overloading would be the awesomest for this. Consider this
Python statement:
res = SELECT + (field.field1, field.field2) + FROM( table.user,
table.page ) + WHERE( field.page_title == field.user_name and
field.page_namespace == NS_USER and field.user_id == 1729 ) + UNION +
...
with all operators (+, ==, and) overloaded, and
SELECT/FROM/WHERE/UNION object names, and "field" and "table" dummy
objects that just exist for __get__ methods (so table.user would be
the same as $dbr->tableName( 'user' )).
Of course, I don't seriously suggest such a thing, so I guess it's
off-topic, but I've pondered it before and thought it would be fun to
mention as a counterpoint. The fact that it's possible is somewhat
mind-boggling. Maybe an argument against operator overloading? :)