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

asd, asd (ID #16)
Brady, Linda (ID #9)
df, df (ID #19)
Dirac, Teo (ID #1)
Ho, Mike (ID #4)
Jenner, Kendalll (ID #2)
jose, Wendy (ID #6)
kula, kalle (ID #18)
Pratt, Jacob (ID #12)
prueba, Samantha (ID #8)
Robinson, Ben (ID #3)
sdfsdfsdf, sdfsdf (ID #17)
Smith, Alejnadro (ID #5)
Smith, Jennifer (ID #10)
Smiths, Brett (ID #11)
t, wdt (ID #13)
w, w (ID #14)
Wolfe, Karen (ID #7)
wwwgggggggg, w (ID #15)

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

df, df (ID #19)
Dirac, Teo (ID #1)
Ho, Mike (ID #4)
Jenner, Kendalll (ID #2)
jose, Wendy (ID #6)