0

This is further to my question earlier, on the db.update.

I'm used the code Karakuri's suggested and modified the database adapter method to the following. Note that fma in an integer number (34, actually) the database adapter got from mainactivity

    public void updateJ(int fma){
         String where = "coli = ?";

        ContentValues arw = new ContentValues();
        cv.put("coli", fma);

            the below no longer used but null the last argument instead
        //  String jusi =  Integer.toString(fma);
        // String[] whereArgs = new String[] {jusi};
        //Log.w(TAG, "whereArgs = " + whereArgs);


        db.update("superTable", cv, where, null);
            }

It still does not work. // from previous 'the log.w reads as 06-02 16:24:31.695: W/DBA information(18940): whereArgs = [Ljava.lang.String;@5299a034'

//But I have a question after reading online tutorials and android website and also Karakuri's explanation that the fourth argument whereArgs is suppose to be a String[] instead of a String or an int. But the column 'coli' in superTable is an integer by design. How do I go about making it accept an int rather than a String[]?

I've replaced the whereargs with null and essentially use the cv.put directly using the int fma variable, but it still doesn't work? converted the int to string before putting in and it doesnt work also.

user3492802
  • 179
  • 9
  • why are you making it an array in the first place? plus is your "coli" column an int or a string? why are you comparing an int with a string array? – Sergey Benner Jun 02 '14 at 16:33
  • coli is an int. The db.update() method will not accept a int or a string as whereArgs. The method update(String, ContentValues, String, String[]) in the type SQLiteDatabase is not applicable for the arguments (String, ContentValues, String, int) – user3492802 Jun 02 '14 at 16:39
  • just to give you the ideas. http://stackoverflow.com/questions/9798473/sqlite-in-android-how-to-update-a-specific-row and here http://stackoverflow.com/questions/5987863/android-sqlite-update-statement --- see the last param is null there :))) – Sergey Benner Jun 02 '14 at 16:42
  • Thanks for the suggestion. I've just tried putting 'null' instead of 'whereArgs' but its still not updating.. – user3492802 Jun 02 '14 at 16:49
  • Should I convert the fma to a String? .. hmm . scratch that. Just converted it to string and reinsert and it still doesnt work – user3492802 Jun 02 '14 at 16:53
  • You are updating your row value using where "coli = 'jusi'. But you don't have such value present in your coli column – Kunu Jun 02 '14 at 17:02
  • I've updated the method as per above. jusi variable is no longer a factor, but the update is still unable to work.. – user3492802 Jun 03 '14 at 07:58

1 Answers1

0

It still does not work. // from previous 'the log.w reads as 06-02 16:24:31.695: W/DBA information(18940): whereArgs = [Ljava.lang.String;@5299a034'

You don't pass the whereArgs to the update(), that's why it "does not work". Change

db.update("superTable", cv, where, null);

to

db.update("superTable", cv, where, whereArgs);

The log output is what one would expect when calling toString() on a String[] string array.

laalto
  • 150,114
  • 66
  • 286
  • 303