Contents of result sets from row queries

Result objects from row queries contain a set of row-like structures that correspond to the column selection array that you pass as an argument to the select method. Each structure in the set represents a row in the database result set. The members of each structure contain the values for that row in the database result set.

For example, you write the following Gosu code to begin a new query.

var query = Query.make(Company)

The preceding sample code sets the primary entity type for the query to Company. You can join other entity types to the query and specify restrictions, just like you can with entity queries. Unlike entity queries however, the results of row queries do not contain entity instances.

The results of row queries contain values selected and computed by the relational database, based on the column selection array that you pass to the select method. To set up the preceding query as a row query, call the select method and pass a Gosu array that specifies the columns you want to select for the result.

uses gw.api.database.Query
uses gw.api.database.QuerySelectColumns
uses gw.api.path.Paths

var query = Query.make(Company)
var rowResult = query.select({ // The select method with an array argument sets up a row query.
  QuerySelectColumns.pathWithAlias("Name", Paths.make(Company#Name)),
  QuerySelectColumns.pathWithAlias("City", Paths.make(Company#PrimaryAddress, Address#City)),
  QuerySelectColumns.path(Paths.make(Company#PrimaryAddress, Address#Country))
})

The members of results from row queries are structures that correspond to the column selection array that you specify.

After you retrieve a member from the result of a row query, you can only use the values the member contains. You cannot use object path notation with a retrieved member to access objects, methods, or properties from the domain graph of the primary entity type of the query.

The following Gosu code prints the company name and the city of the primary address for each Company in the result. The result member provides the Name column and the City column.

for (company in rowResult) {  // Members of a result from a row query are QueryRow objects.
  print (company.getColumn("Name") + ", " + 
         company.getColumn("City") + ", " + 
         company.getColumn(2))
}

You can only access columns from the members of a row result if you specified them in the column selection array.

See also