Backendless Support
 
Waiting for user's response

Search data objects with sql prepared statements in Backendless in Android

How do i make the string variable `searchQuery`passed from the `SearchResultsActivity` to the `SearchResultPresenter` part of the `where clause`string. I am using MVP architecture in android. Thanks

My Activity

  1. public class SearchResultsActivity ...{
  2. ...
  3. mPresenter.getUsers(searchQuery);// method implemented in a presenter class
  4. ...
  5. }

My Presenter

  1. public class SearchResultPresenter ...{
  2. ...
  3. public void getUsers(String searchQuery) {
  4. String query = "....Contains(name, 'searchQuery') ";// this doesn't work, shows the method parameter `searchQuery` is never used.
  5. String whereClause = String.format(query, ...);
  6. }
  7. }

Something close to this

  1. Connection con = DriverManager.getConnection(url, "UN", "PW");
  2. PreparedStatement ps = con.prepareCall("select * from table where contains(name,?)");
  3. ps.setString(1,searchQuery);
  4. ResultSet rs = ps.executeQuery();

How would you define an active connection con in backendless?Would you kindly give an illustration by construction prepared statement object and using the same to execute the statement using the below sample code from one of your Support posts.

  1. double myLatitude = 32.779108;
  2. double myLongitude = -96.797000;
  3. String query = "distance( %f, %f, location.latitude, location.longitude ) < mi(5) and available = true";
  4. String whereClause = String.format( query, myLatitude, myLongitude );
  5. BackendlessDataQuery dataQuery = new BackendlessDataQuery( whereClause );
  6. QueryOptions queryOptions = new QueryOptions();
  7. queryOptions.addRelated( "location" );
  8. dataQuery.setQueryOptions( queryOptions );
  9. Backendless.Data.of( Car.class ).find( dataQuery, new AsyncCallback<BackendlessCollection<Car>>()

    {......}

Leave a Comment

Comments (1)

photo
1

Hi, Odhiambo.

1) If your question about how to work with Android activities - you should use official Google documentation and appropriate sites.

2) As for the latter code example - it is correct. Before you should just invoke Backendless.initApp() and then you are able make API calls to our servers.

If you have a problem with invocation of code related to our sdk, please provide code example which reproduce a problem and application id.