Roan Kattouw wrote:
> 2010/5/12 Platonides <platoni...@gmail.com>:
>>        $n = Sql_query( "SELECT (SELECT COUNT(*) FROM code_rev WHERE
>> cr_repo_id=1 AND cr_timestamp >= '$epoch' $extra AND cr_path LIKE
>> "/trunk/phase3%") + (SELECT COUNT(*) FROM code_rev WHERE cr_repo_id=1
>> AND cr_timestamp >= '$epoch' $extra AND cr_path="/trunk") + (SELECT
>> COUNT(*) FROM code_rev WHERE cr_repo_id=1 AND cr_timestamp >= '$epoch'
>> $extra AND cr_path="/") );
>>
> This query won't work. Each revision has multiple entries on the
> code_rev table, one for each path. This means you need to use
> COUNT(DISTINCT cr_id) and need to drop the second and third
> subqueries.

That doesn't match the expected behavior from the SQL file.
Are you sure it works like that? Since there's a primary key on
(cr_repo_id, cr_id), you can't have multiple entries [on the same
repo] with the same cr_id. cr_path contains the shortest common parent
for all the involved files.
Thus, a change to /trunk/phase3 will store only /trunk if it also
applies to a branch. Or / (or is it ''?) if it also changed something at
the repository root, which is really unlikely.

Feel free to drop the check for /, perform the sum in php, and so on.
This was not intended as a final implementation.


> You also need to use single quotes throughout the query,
> because it's wrapped in double quotes.
Good point. I thought I was using single quotes on the whole query,
I missed the cr_path.


> Furthermore, the correct
> function name is mysql_query():
> 
> $n = mysql_query( "SELECT COUNT(DISTINCT cr_id) FROM code_rev WHERE
> cr_repo_id=1 AND cr_timestamp >= '$epoch' $extra AND cr_path LIKE
> '/trunk/phase3%'");

Opening the connection to the database and passing it to mysql_query
would be a good idea, too. :)
I didn't want to go into the detail of db connection so I put it in
terms of a generic Sql_query() call (initially it was, Sql query ->
SELECT...)




_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to