Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a row from Parse Table

I have a table called Favourite tags. it has fields - Tag, User( Pointer- respectiv user objectid).where User can store a tag and along with user-objectid as pointer in user filed and user remove the tag from favourite

For Storing/Updating: it is working fine .

           ParseObject favtagobject = new ParseObject("Favourite");
            favtagobject.put("Tag", "#" + keyword);
                favtagobject.put("User", ParseUser.getCurrentUser());
                favtagobject.saveInBackground();

For removing/deleting the tag from table: Below code is not working

           ParseObject favtagobject = new ParseObject("Favourite");
             favtagobject.put("Tag", "#" + keyword);
                favtagobject.put("User", ParseUser.getCurrentUser());
                favtagobject.deleteInBackground(new DeleteCallback() {

                    @Override
                    public void done(com.parse.ParseException arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("deleted the tag succesfully");
                    }
                });

i want to delete a row from table i know which row to be deleted. Please help me out.

like image 957
Sree Reddy Menon Avatar asked Feb 17 '15 14:02

Sree Reddy Menon


People also ask

How to delete a row from a table in SQL?

Introduction to SQL Server DELETE statement. To remove one or more rows from a table completely, you use the DELETE statement. The following illustrates its syntax: DELETE [ TOP ( expression ) [ PERCENT ] ] FROM table_name [ WHERE search_condition]; Code language: SQL (Structured Query Language) (sql) First, you specify the name of the table ...

How do I delete a specific row in PostgreSQL?

The PostgreSQL DELETE statement allows you to delete one or more rows from a table. First, specify the name of the table from which you want to delete data after the DELETE FROM keywords. Second, use a condition in the WHERE clause to specify which rows from the table to delete. The WHERE clause is optional.

How to limit the number of rows deleted from a table?

In this case, you need to specify the search_condition in the WHERE clause to limit the number of rows that are deleted. The rows that cause the search_condition evaluates to true will be deleted. The WHERE clause is optional. If you skip it, the DELETE statement will remove all rows from the table. Let’s create a new table for the demonstration.

How do I delete all records in a table?

Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record (s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted! Below is a selection from the "Customers" table in the Northwind sample database:


1 Answers

Basically, when you use 'new ParseObject("Favourite");' it will construct a new ParseObject. This parseObject does not exist in your database until you call any variant of .save() on it. Hence when you do this

    ParseObject favtagobject = new ParseObject("Favourite");
         favtagobject.put("Tag", "#" + keyword);
            favtagobject.put("User", ParseUser.getCurrentUser());
            favtagobject.deleteInBackground(new DeleteCallback() {

                @Override
                public void done(com.parse.ParseException arg0) {
                    // TODO Auto-generated method stub
                    System.out.println("deleted the tag succesfully");
                }
            });

All you're doing is creating a new object, that does not exist in your database and then try to delete it? What you're looking for is this

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Favourite");
    query.whereEqualTo("Tag", "#" + keyword);
    query.whereEqualTo("User", ParseUser.getCurrentUser());
    query.getFirstInBackground(new FindCallBack() {

            @Override
            public void done(ParseObject object, com.parse.ParseException arg0) {
               // TODO Auto-generated method stub
                   object.delete();
                   object.saveInBackground();
            }
        }););

This will first get the object from your database and then delete the row from table and save the changes made to the object!

like image 83
Bart de Ruijter Avatar answered Nov 13 '22 09:11

Bart de Ruijter