Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting all the records from table -Parse.com

i have around 13000 records on one table(HashTag -classname) . i want to retrieve all of them on a single query. but parse allows only 1000 per query. any other ways get the all the records..

 ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag");
 query.whereExists("Tag"); query.orderByAscending("Type"); query.setLimit(1000);
 query.findInBackground(new FindCallback<ParseObject>() {

                                @Override
                                public void done(List<ParseObject> list,
                                        ParseException e) {
                                    // TODO Auto-generated method stub
                                    if (e == null)
                                    {
                                        if (list.size() > 0) {
                                            for (int i = 0; i < list.size(); i++) {
                                                ParseObject p = list.get(i);
                                                String tagid = p.getString("Tag");
                                                String Type = p.getString("Type");
                                                class2 c2 = new class2();
                                                c2.type = "" + Type;
                                                c2.tag = "" + tagid;
                                                listClass2.add(c2);



                                            }

                                        }
like image 783
Sree Reddy Menon Avatar asked Sep 23 '14 14:09

Sree Reddy Menon


People also ask

How get all records from a table in SQL?

In its most simple form, the SELECT clause has the following SQL syntax for a Microsoft SQL Server database: SELECT * FROM <TableName>; This SQL query will select all columns and all rows from the table.

How can I get all data from a table?

SELECT statements SELECT column1, column2 FROM table1, table2 WHERE column2='value'; In the above SQL statement: The SELECT clause specifies one or more columns to be retrieved; to specify multiple columns, use a comma and a space between column names. To retrieve all columns, use the wild card * (an asterisk).

Which command is used to retrieve all records from a table?

The SQL SELECT statement is used to retrieve records from one or more tables in your SQL database. The records retrieved are known as a result set.

What is the SQL query for displaying all the records from a table called orders?

Run the Orders Query (Orders Qry on the Query list): It lists all orders for all customers, without going into line items (order details), by retrieving related data from the Orders and Customers tables.


2 Answers

Sure, you can run multiple queries on the same table, with query's skip property incremented by 1000 each time:

  1. Get the total number of records via query.count(), and use it to set a 'skip' variable
  2. Run a new query for each 1000 records, updating your skip property accordingly
  3. Process records as normal when each query returns

Something like this:

    ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag");
    query.whereExists("Tag");
    query.countInBackground(new CountCallback() {
        public void done(int count, ParseException e) {
        if (e == null) {
              // The count request succeeded. Run the query multiple times using the query count
          int numQueries = Math.ceil(count / 1000); //Gives you how many queries to run
          for(int skipNum = 0; l < numQueries; l++){
             ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag");
             query.whereExists("Tag"); query.orderByAscending("Type"); 
             query.setLimit(skipNum * 1000);
             query.findInBackground(new FindCallback<ParseObject>() {
                //Run your query as normal here

             }
          }
        } else {
          // The request failed
        }
      }
like image 111
Ryan Kreager Avatar answered Oct 09 '22 21:10

Ryan Kreager


//Declare  a global variable for storing the complete data
private static List<ParseObject>allObjects;
allObjects=new ArrayList<ParseObject>();
ParseQuery<ParseObject>query3=ParseQuery.getQuery("HashTag");
query3.whereExists("Tag");
query3.setLimit(1000);
query3.findInBackground(getallobjects());
int limit=1000;
int skip=0;
//callback method:
private FindCallback<ParseObject>getallobjects(){  
    return new FindCallback<ParseObject>(){
        @Override
        public void done(List<ParseObject>list,ParseException e){
            allObjects.addAll(list);
            if(list.size()==limit){
                skip=skip+limit;
                ParseQuery<ParseObject>query=ParseQuery.getQuery("HashTag");
                query.setSkip(skip);
                query.setLimit(limit);
                query.findInBackground(getallobjects());
            }else{
                //you have full data in allobjects
                for(int i=0;i<allObjects.size();i++){}
            }
        }}}
like image 41
Sree Reddy Menon Avatar answered Oct 09 '22 21:10

Sree Reddy Menon