So despite using SQL for about 8 years now; I have never really got to grips with the intracies of it.
Anyways, I had to count the number of rows that contained a unique combination of two columns.
In this case, I needed to find all the html pages that were deleted, all the html pages that were undeleted, all the binary pages that were deleted and all the binary pages that were undeleted.
So after banging my head against a brick SQL wall for a few minutes, I resorted to code:
public final class JdbcStatisticsDAO extends JdbcDaoSupport implements StatisticsDAO {
@SuppressWarnings("unchecked")
public PageStatistics getPageStatistics(final Page page) {
String sql = "select discriminator, is_deleted from page where ….";
List
Lovely; isn't it :)
Then I happened to chat to the Oracle guru that is Hongfeng :) who pointed out that I should use a combination of count and groupBy. A few minutes later and Hongfeng managed to find the exact page in one of the 5642 Oracle reference manuals.
This results in this:
public PageStatistics getPageStatistics(final Page page) {
String sql = "select discriminator, is_deleted, count(*) as theCount from page where page.url = '" + page.getUrl() + "' or page.url like '" + page.getUrlPath() + "%' group by discriminator, is_deleted";
List
The code is still ugly as anything; but the SQL is cool. Much more efficient.
Cheers Hongfeng :)
Hey, any chance you could avoid posting run-on lines of code to the blogs, they really, really mess up the page layout!
:¬)
08 Feb 2006, 16:55
I will have a chat with one of the blog guys to see whether this can be done automatically in textile… Otherwise yes; I will try and behave :)
08 Feb 2006, 17:47
Mike
Hi Colin,
Just put the code in a DIV with the css marked with "overflow:scroll" and it'll appear with scrollbars…
Cheers
Mike
PS congratulations on being published. Always good to see fellow Brits involved with OSS.
24 Feb 2006, 15:29
Add a comment
You are not allowed to comment on this entry as it has restricted commenting permissions.