2. More About the Object Relational Model
* Sorting and Limiting Array Results
<< Previous   |   Back to Main   |   * Late Binding of Related Objects >>

View Source
will open in a new window
Manipulating LoadAll and LoadArrayBy Results
(Note: for more information about "QQ::"-related classes (a.k.a. Qcodo Query), please refer to section 3 of the Examples Site.)

All Code Genereated LoadAll and LoadArrayByXXX methods take in an optional Qcodo Query Clauses parameter, where you can specify an unlimited number of QQClause objects, including (but not limited) functionality that handles ORDER BY, LIMIT and Object Expansion. We will discuss Object Expansion in the examples that deal with Late Binding and Early Binding. But for this example, we'll focus on using using QQ::OrderBy() and QQ::LimitInfo() to manipulate how the results come out of the database.

OrderBy and LimitInfo are actually really straightforward to use. Order By takes in any number of Qcodo Query Node columns, followed by an optional boolean (to specify ascending/decending), which will be used in a SQL ORDER BY clause in the SELECT statement. So you can simply say QQ::OrderBy(QQN::Person()->LastName) to sort all the Person objects by last name.

LimitInfo takes in a Maximum Row Count, followed by an optional offset. So if you specified "10, 4", the result set would contain at most 10 rows, starting with row #5 (the offset is based on a 0 index). Depending on which database platform you are on, the database adapter will appropriately handle how to deal with this Limit information.

As a final reminder, note that you can use either, both, more or none of these optional QQClause parameters whenever you make your LoadAll or LoadArrayBy calls.

List All the People, Ordered by Last Name then First Name

455, 45 (ID #16)
5456, Alex (ID #5)
Brady, Linda (ID #9)
Carlisle, Brett (ID #11)
Doe, Jane (ID #13)
Doe, joe (ID #1)
Doe, John (ID #18)
Grant, Hugh (ID #14)
hh, hh (ID #19)
Ho, Mike (ID #4)
Jones, Samantha (ID #8)
Pratt, Jacob (ID #12)
Public, Kendall (ID #2)
Robinson, Ben (ID #3)
Smith, Bob (ID #17)
Smith, Jennifer (ID #10)
Smith, Wendy (ID #6)
Williams, Tom (ID #15)
Wolfe, Karen (ID #7)

List Five People, Start with the Third from the Top, Ordered by Last Name then First Name

Brady, Linda (ID #9)
Carlisle, Brett (ID #11)
Doe, Jane (ID #13)
Doe, joe (ID #1)
Doe, John (ID #18)