Bug reports Found a bug? Post it here please.
Version 4.x > Bug reports > Incorrect SQL queries behind 2 static methods under HitsInfoProvider class View modes: 
User avatar
Member
Member
seanbun-gmail - 5/6/2009 6:29:24 AM
   
Incorrect SQL queries behind 2 static methods under HitsInfoProvider class
Hi

1.GetObjectHitsInfo(Int32, Int32, HitsIntervalEnum, String, DateTime, DateTime)
2. GetObjectHitCount(Int32, Int32, HitsIntervalEnum, String, DateTime, DateTime)

I tried to get the pageview and web analytics info with above 2 methods and found they returned incorrect data with given date range. I checked both SQL Queries with SQL Server Profiler and found a bug (potentailly).

In order to get the hitsinfo record within the given date range, the condition of HitsStartTime should be "HitsStartTime >= @TimeBegin" as the red line shown below.

Please correct me if my logic is wrong.

Cheers,
Matt

-- Current Query
exec sp_executesql
N'SELECT SUM(HitsCount) FROM Analytics_Statistics, analytics_dayhits
WHERE StatisticsSiteID=@SiteID
AND StatisticsCode=@CodeName
AND StatisticsID=HitsStatisticsID
AND StatisticsObjectID=@ObjectID
AND @TimeBegin >= HitsStartTime
AND HitsEndTime <= @TimeEnd',N'@SiteID int,@CodeName nvarchar(9),@TimeBegin datetime,@TimeEnd datetime,@ObjectID int',@SiteID=78,@CodeName=N'pageviews',@TimeBegin='2009-05-06 00:00:00',@TimeEnd='2009-05-07 00:00:00',@ObjectID=1234

-- Correct Query
exec sp_executesql
N'SELECT *
FROM Analytics_Statistics, analytics_dayhits
WHERE StatisticsSiteID=@SiteID
AND StatisticsCode=@CodeName
AND StatisticsID=HitsStatisticsID
AND StatisticsObjectID=@ObjectID
AND @TimeBegin <= HitsStartTime
AND @TimeEnd >= HitsEndTime',
N'@SiteID int,@CodeName nvarchar(9),@TimeBegin datetime,@TimeEnd datetime,@ObjectID int',
@SiteID=78,@CodeName=N'pageviews',@TimeBegin='2009-05-05 00:00:00',
@TimeEnd='2009-05-08 00:00:00',@ObjectID=1234


User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/18/2009 6:03:24 AM
   
RE:Incorrect SQL queries behind 2 static methods under HitsInfoProvider class
Hi,

I think this is correct. For example we want to get some hour hits for file download. Lets say that in hour between 5 and 6 were 2 hits and in hour between 6 and 7 one hit. So, now you want to know the hits between 5:30 and 6:30, so you need to display the hits which where in the two hours between 5 and 7. I hope it makes more sense now. It also depends on the precision you are using - hour, day, month or year hits.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
seanbun-gmail - 5/18/2009 9:02:13 PM
   
RE:Incorrect SQL queries behind 2 static methods under HitsInfoProvider class
Hi Jurajo,

Thanks for your reply. According to your example, there are 2 rows in the db

---------------------
Start |Finish | Hit
---------------------
5:00 | 6:00 | 2
--------------------
6:00 | 7:00 | 1
--------------------

If we execute the top query (the one in the kentico system) and try to retrieve all data with starttime 5:00 and finish time 7:00, the second row would NOT be retrieved because it has a condition - HitsStartTime <= @TimeBegin (i.e. 6:00 > 5:00 and it breaks the condition).

Hope it makes sense. Appreciate your good support work again.

Cheers,
Matt

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/21/2009 6:16:26 AM
   
RE:Incorrect SQL queries behind 2 static methods under HitsInfoProvider class
Hi,

Thank you, I got it know, you are right, it is a bug. I am sorry for the inconvenience.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
seanbun-gmail - 5/21/2009 9:12:05 AM
   
RE:Incorrect SQL queries behind 2 static methods under HitsInfoProvider class
Thanks Juraj,

Look forward to getting the patch later.

Cheers,
Matt