Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 98: Loading data objects from server with an SQL query
April 16, 2015 by markpiller

Previously I have reviewed multiple techniques for loading data objects from the persistent server-side storage. There is a list of all articles categorized by topic. In this post I am going to review the API for loading data objects using an SQL query. I already wrote once about SQL queries in Backendless and that post described how to test queries using console. I recommend reading that post before reviewing the samples below.

Consider the following data tables:

There are 2 Person objects:
person-objects

And there are 3 Address objects. Notice there is a one-to-many relation between Person and Address objects:
address-objects

Suppose you need to load all persons who are older than 21 and live in New York city. The following query expresses exactly that condition:

Notice the query references object properties/columns to define the search expression. The addresses column in the Person table references a collection of the Address objects. Since Address has the city column, it is identified using the dot notation in the query.

The code below demonstrates the query in action:

Asynchronous API sample (Android and Plain Java):

Synchronous API sample (Plain Java only):

Program output:

The API is designed in a way that let’s you combine query-based search with sorting, loading of relations, paging and many other data search-related features of Backendless.

 

Share this post
Tweet about this on TwitterShare on FacebookGoogle+