Hi,
In my database I have a table called ThingsInACircle
. Every time a Thing
is added to the ThingsInACircle
, it gets added with a ThingId
that is auto incremented.
Imagine the Things
in this table as being in a circle.
SELECT Thing FROM ThingsInACircle WHERE ThingId = 10
is next to
SELECT Thing FROM ThingsInACircle WHERE ThingId = 11
.
Also...
SELECT Thing FROM ThingsInACircle WHERE ThingId = min(ThingId)
is next to
SELECT Thing FROM ThingsInACircle WHERE ThingId = max(ThingId)
I want to be able to say: For a given ThingId and an offset, return all of the records in ThingsInACircle ranging from the ThingId to (ThingId + offset) (offset may be negative).
So, take this as an example set up:
Here is a list of our ThingIds: 1 2 3 4 5 6 7 8 9
If I want all the ThingIds where @ThingId = 2 and @offset = 3, there's no problem
SELECT ThingId FROM ThingsInACircle WHERE
ThingId BETWEEN @ThingId AND (@ThingId + @offset)
and it would return: 2 3 4 5
But, if I want all the ThingIds where @ThingId = 8 and @offset = 3, then there's a problem
The function should return: 7 8 9 1
So here's my dilemma, should my Data Access Layer contain a query that uses a more complicated stored procedure (Selecting min, max, and using if & else to determine if they have been exceeded) to determine exactly which records to retrieve in order to treat the records as being linked in a circle?
Or should the Business Logic Layer determine whether or not the user has requested an id + offset that exceeds min or max and then use simple DAL methods to accomplish what it needs to return?
This may just be a matter of opinion. I just started learning about three-tiered structure two days ago by following microsofts tutorial, so I just want to get an idea of how some people think DAL and BLL should be formed: If DAL should be simple and BLL should do all of the verifying... Or the other way around... Or something I've missed all together.