find data from a table

hi

i want to find data from a table i created.
for example : i have “messages” table and i want to get all the data/values of the column “content” where the data/value of column “chatName” equals to “x” (some name).
i know i can search with “whereClause”, but i don’t know what data the map “BackendlessCollection<Map> foundContacts” gives me, and how i can use it for taking related details from the table (like my example).
I’ll be glad if you answer me

Hello Glen,

What version of Backendless do you use: v3 or v4?
What language do you use?

Regards, Olga

You can find the examples here (e.g. finding all contacts from the Contact table where the value of the “age” property equals 47)

Regards, Olga

hi

i’m using v3 and java (android studio)

but i don’t know how i take the data from the map “BackendlessCollection<Map> foundContacts”.

i want to get data from a column where in another column the value equals to my query.

The BackendlessCollection you receive is probably of type:

BackendlessCollection&lt;Map&lt;String, Object&gt;>

The key is the column name (String), the value is the whatever type you have in that column’s value (e.g. Integer for INT, String for STRING and TEXT, Map<String, Object> for RELATIONS).

I suppose the code you’re looking for is:

foundContacts.get( "yourColumnName" );

which will return the value of the specified column.

Regards, Olga

=========================This is get all data=========================



private List&lt;QuoteFromUser&gt; getAllQuoteOfUserFromSever() {
final List&lt;QuoteFromUser&gt; mQuoteList = new ArrayList&lt;&gt;();
final Integer[] size = {0};
final DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setSortBy("created DESC");
Backendless.Data.of(Constants.TABLE_USER).getObjectCount(new AsyncCallback&lt;Integer&gt;() {
@Override
public void handleResponse(Integer integer) {
size[0] = integer;
if (size[0] > 0) {
Random random = new Random();
// queryBuilder.setPageSize(size[0]).setOffset(random.nextInt(0));
Backendless.Persistence.of(Constants.TABLE_USER).find(queryBuilder, new AsyncCallback&lt;List&lt;Map&gt;>() {
@Override
public void handleResponse(List&lt;Map&gt; response) {
for (int i = 0; i < response.size(); i++) {
QuoteFromUser quoteFromUser = new QuoteFromUser();
quoteFromUser.setUserQuoteId(response.get(i).get("objectId").toString());
quoteFromUser.setUserQuoteCategoryName(response.get(i).get("userQuoteCategoryName").toString());
quoteFromUser.setUserTimeCreated(response.get(i).get("created").toString());
quoteFromUser.setUserQuoteContent(response.get(i).get("userQuoteContent").toString());
quoteFromUser.setUserQuoteAuthorName(response.get(i).get("userQuoteAuthorName").toString());
quoteFromUser.setUserQuoteDevice(response.get(i).get("userQuoteDevice").toString());
quoteFromUser.setUserQuoteLocation(response.get(i).get("userQuoteLocation").toString());
quoteFromUser.setUserQuoteCommentCount(Integer.parseInt(response.get(i).get("userQuoteCommentCount").toString()));
quoteFromUser.setUserQuoteShareCount(Integer.parseInt(response.get(i).get("userQuoteShareCount").toString()));
quoteFromUser.setUserQuoteLikeCount(Integer.parseInt(response.get(i).get("userQuoteLikeCount").toString()));
mQuoteList.add(quoteFromUser);
}
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(getApplicationContext(), getString(R.string.loading_error), Toast.LENGTH_SHORT).show();
}
});
} else {
// Toast.makeText(getApplicationContext(), getString(R.string.no_data_or_no_connect), Toast.LENGTH_SHORT).show();
}
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
// Toast.makeText(MainActivity.this, backendlessFault.toString(), Toast.LENGTH_SHORT).show();
}
});
return mQuoteList;
}

*This is method to get data of column



final List&lt;Quote&gt; mQuoteList = new ArrayList&lt;&gt;();
final Integer[] size = {0};
final DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause("quoteAuthorName = '" + author.getAuthorName() + "'");
Backendless.Data.of(Constants.TABLE_QUOTE).getObjectCount(queryBuilder, new AsyncCallback&lt;Integer&gt;() {
@Override
public void handleResponse(Integer integer) {
size[0] = integer;
if (size[0] > 0) {
queryBuilder.setPageSize(size[0]).setOffset(0);
Backendless.Persistence.of(Constants.TABLE_QUOTE).find(queryBuilder, new AsyncCallback&lt;List&lt;Map&gt;>() {
@Override
public void handleResponse(List&lt;Map&gt; response) {
for (int i = 0; i < size[0]; i++) {
Quote quote = new Quote();
quote.setQuoteId(response.get(i).get("objectId").toString());
quote.setQuoteCategoryName(response.get(i).get("quoteCategoryName").toString());
quote.setQuoteContent(response.get(i).get("quoteContent").toString());
quote.setQuoteAuthorName(response.get(i).get("quoteAuthorName").toString());
quote.setQuoteTimeCreated(response.get(i).get("created").toString());
mQuoteList.add(quote);
}
AdapterQuote adapterQuote = new AdapterQuote(context, mQuoteList);
lsvReadQuoteWhereClause.setAdapter(adapterQuote);
linearLayoutLoadingView.setVisibility(View.GONE);
tvNameOfClause.setText(author.getAuthorName() + " - " + mQuoteList.size());
HashMap mCategory = new HashMap();
mCategory.put("objectId", author.getAuthorId());
mCategory.put("authorQuoteCount", mQuoteList.size());
Backendless.Persistence.of(Constants.TABLE_AUTHOR).save(mCategory, new AsyncCallback&lt;Map&gt;() {
@Override
public void handleResponse(Map response) {
Log.i("SET AUTHOR QUOTE COUNT", "DONE ===========================");
}
@Override
public void handleFault(BackendlessFault fault) {
}
});
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(context, R.string.loading_error, Toast.LENGTH_SHORT).show();
}
});
} else {
Toast.makeText(context, R.string.no_quote, Toast.LENGTH_SHORT).show();
dialog.cancel();
}
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(context, R.string.loading_error, Toast.LENGTH_SHORT).show();
}

+++++++++++++++This is method to search++++++++++++++++++





private void getAuthorWithString(String inputContent) {
final DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setSortBy("created DESC");
String whereClause = "authorName LIKE '%" + inputContent + "%'";
queryBuilder.setWhereClause(whereClause);
Backendless.Persistence.of(Constants.TABLE_AUTHOR).find(queryBuilder, new AsyncCallback&lt;List&lt;Map&gt;>() {
@Override
public void handleResponse(List&lt;Map&gt; response) {
for (int i = 0; i < response.size(); i++) {
Author author = new Author();
author.setAuthorId(response.get(i).get("objectId").toString());
author.setAuthorName(response.get(i).get("authorName").toString());
author.setAuthorImage(response.get(i).get("authorImage").toString());
author.setAuthorBirthday(response.get(i).get("authorBirthday").toString());
author.setAuthorNationality(response.get(i).get("authorNationality").toString());
author.setAuthorBiography(response.get(i).get("authorBiography").toString());
author.setAuthorWikipedia(response.get(i).get("authorWikipedia").toString());
author.setAuthorShareCount(Integer.parseInt(response.get(i).get("authorShareCount").toString()));
author.setAuthorCommentCount(Integer.parseInt(response.get(i).get("authorCommentCount").toString()));
author.setAuthorLikeCount(Integer.parseInt(response.get(i).get("authorLikeCount").toString()));
author.setAuthorQuoteCount(Integer.parseInt(response.get(i).get("authorQuoteCount").toString()));
authorList.add(author);
}
linearLayout.setVisibility(View.GONE);
if (authorList.size() == 0) {
Toast.makeText(getApplicationContext(), getString(R.string.no_data), Toast.LENGTH_SHORT).show();
} else {
AdapterAuthorImage adapterAuthorImage = new AdapterAuthorImage(SearchQuoteActivity.this, authorList);
lsvSearch.setAdapter(adapterAuthorImage);
}
}
@Override
public void handleFault(BackendlessFault fault) {
// Toast.makeText(getApplicationContext(), getString(R.string.no_data), Toast.LENGTH_SHORT).show();
}
});
}

Hello, first of all, I suggest you, to use Backendless v4, because support of 3.X will be limited, from now you can not create new applications with 3.X more details here https://backendless.com/backendless-4-has-been-released-out-of-beta/

here it is an example how to use BackendlessCollection


BackendlessDataQuery dataQuery = new BackendlessDataQuery();
QueryOptions queryOptions = new QueryOptions();
queryOptions.setPageSize( 25 );
queryOptions.setOffset( 50 );
dataQuery.setQueryOptions( queryOptions );
Backendless.Data.of( Person.class ).find( dataQuery, 
                                       new AsyncCallback&lt;BackendlessCollection&lt;Person&gt;>()
  {
    @Override
    public void handleResponse( BackendlessCollection&lt;Person&gt; response )
    {
      // the "response" object is a collection of Person objects.
      // each item in the collection represents an object from the "Person" table 
      
      List&lt;Person&gt; persons = response.getCurrentPage();
      
      for(Person person : persons)
      {
      	System.out.println(person);
      }
    }
 
    @Override
    public void handleFault( BackendlessFault fault )
    {
       // use the getCode(), getMessage() or getDetail() on the fault object
       // to see the details of the error
    }
    });

notice, that BackendlessCollection was removed in Backendless 4, so when you are ready move to Backendless 4 you will need to rewrite your code