Results 1 to 5 of 5
  1. #1
    garnachito is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default function return 1 > 0 ??

    Hi guys

    I'm working in some exercises and I saw this line in my book:

    Java Code:
    return db.update(DBTABLE, args, KEY_ID + "=" + id, null) > 0;
    This method returns the number of rows affected, in this particular case it will always return 1 or 0, but I don't know what's the meaning of "> 0" at the end of the line

    Can you help me to understand this ?

    Thanks!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: function return 1 > 0 ??

    That line is likely part of a method that returns a boolean, right? So what will the above statement return if db.update(...) returns 1? What about if db.update(...) returns 0, what does the method that contains the line above return?

  3. #3
    garnachito is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: function return 1 > 0 ??

    This is the entire function

    Java Code:
    public boolean updateUser(long id, String name, String pass){
    			ContentValues args = new ContentValues();
    			args.put(KEY_NAME, name);
    			args.put(KEY_PASS, pass);
    			return db.update(DBTABLE, args, KEY_ID + "=" + id, null) > 0;
    		}
    Thanks!

  4. #4
    ContoNick is offline Member
    Join Date
    Dec 2011
    Location
    Croatia,Zagreb
    Posts
    24
    Rep Power
    0

    Default Re: function return 1 > 0 ??

    Its very simple,

    if
    Java Code:
    db.update(DBTABLE, args, KEY_ID + "=" + id, null)
    returns number greater than 0 (zero), method updateUser will return true.

    if
    Java Code:
    db.update(DBTABLE, args, KEY_ID + "=" + id, null)
    returns number lower or equal to 0 ( zero), method updateUser will return false.

  5. #5
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: function return 1 > 0 ??

    [QUOTE=garnachito;321736]This is the entire function

    Java Code:
    public boolean updateUser(long id, String name, String pass){
    			ContentValues args = new ContentValues();
    			args.put(KEY_NAME, name);
    			args.put(KEY_PASS, pass);
    			return db.update(DBTABLE, args, KEY_ID + "=" + id, null) > 0;
    		}
    If the row affected return statement will return 1 or return 0
    Regards
    Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475

Similar Threads

  1. What to return upon failure of a generic function
    By Lowest0ne in forum New To Java
    Replies: 1
    Last Post: 09-16-2012, 05:16 AM
  2. Simple "Global" function to return random int
    By mac666 in forum New To Java
    Replies: 2
    Last Post: 01-10-2012, 03:13 PM
  3. Return ArrayList function - Java
    By skp123 in forum New To Java
    Replies: 23
    Last Post: 05-01-2011, 04:11 AM
  4. Filling an array from the return value of the function
    By alex1988 in forum Java Applets
    Replies: 7
    Last Post: 02-02-2011, 09:29 AM
  5. getSession() Function Return Null value
    By dalchndr@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 11-04-2009, 07:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •