Defining a Query
Next, we need to add some data to our page. We are going to do that with a Caché query. We will define the query in Film and then access it in TopPicks using the CSP tag <csp:query>.
As its name suggests, a query is a way to get information from a Caché database. Queries can be defined and compiled as part of a class definition. Thereafter, they can be called by name as needed.
(Alternatively, we can use dynamic SQL requests to do the same thing, but that is generally less convenient and less efficient.)
Typically, a query defines
A set of properties to be retrieved. In this case, we are going to retrieve the following: the Object ID along with the Description, Length, Rating, and Title properties from the Film class and the CategoryName property from the FilmCategory class.
Selection criteria that limit the objects retrieved based on the values of one or more properties. We only want films that are currently showing, so our selection criteria is “PlayingNow = 1”.
Sorting specifications that determine the sequence in which objects are returned. We want to display films in sequence based on the number of tickets sold, with the largest number first.