2

From the SQLiteDatabase documentation:

public int delete(String table, String whereClause, String[] whereArgs)

@return
the number of rows affected if a whereClause is passed in, 0 otherwise. To remove all rows and get a count pass "1" as the whereClause.

I am writing a program, but I can not get the exact meaning of the sentence above? Could anyone help me?

In my opinion, the method will return an int value that tell you how many rows you delete. But it says if you delete all rows, the delete method will return 1. But what if we delete just one row, will it still return 1?

  • 2
    Can we see the source from which you've given the excerpt? The role or position (or use) of 'whereClause' is unclear from your question. – Victor Bazarov Sep 14 '15 at 15:04
  • Is there a specific word or phrase that is confusing you? – ColleenV parted ways Sep 14 '15 at 17:19
2

TL;DR

Nick Moore's answer explains the meaning correctly. Now that you've clarified your confusions, I'd like to point out some important points, based on your misunderstandings:

  • If your whereClause causes the function to delete one row, it will return 1.
  • If you delete all rows (by passing "1" to whereClause), it will return the number of all rows that were deleted.
  • What if you do that (deleting all rows by passing "1" to whereClause), and the table has only one row (which means, it will delete just 1 row in total), will it still return 1? Yes, it will return 1. (Given that it works as stated.)

Reading comprehension:

Let's have a closer look at the sentences.

@return
the number of rows affected if a whereClause is passed in, 0 otherwise.

You can read @return in Javadoc documents (I presume) as "This method returns"; so it's "the method delete() returns ..." in our example.

It returns what? The sentence states the conditions in the pattern [ X if A-condition, Y otherwise ]. In other words, if A-condition applies, it returns X; otherwise, it returns Y.

So, this sentence means: If a whereClause is passed in, delete() returns the number of rows affected; otherwise (i.e. you do not specify a proper whereClause), it returns 0.

To remove all rows and get a count pass "1" as the whereClause.

I think the sentence would be clearer with a comma:
To remove all rows and get a count, pass "1" as the whereClause.

In other words,

To remove all rows and get a count pass "1" as the whereClause.
(= Pass "1" as the whereClause to remove all rows and get a count.)

This does not say what you understand ("if you delete all rows, the delete method will return 1"). It says, "To remove all rows, pass a string "1" as your whereClause". For example, this will remove all rows: delete(myTable, "1", myWhereArgs);

By doing so (deleting all rows by passing "1" as the whereClause), you will get "a count" as the return value. That is, delete() will delete all rows, and then return the count of all deleted rows.

So, what if we delete just one row, will it still return 1? Yes, it will return 1.

  • You're welcome! I'm glad I can help. – Damkerng T. Sep 15 '15 at 8:44
5

I am assuming this annotates a method definition that deletes rows from a database.

If you pass a 'whereClause' into the method, the method will return the number of rows that are deleted by the method.

If you do not pass it a 'whereClause', the method will return 0 (and presumably will delete no rows).

If you pass in a 'whereClause' with value "1", the method will remove all rows and return the number of rows deleted.

  • I've edited the question.. – vankee Sep 15 '15 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.