1

I am pretty new to SQLite databases, so please forgive me...

I have a database with integer values. When updating a row in the database using the code below, there is somehting I don't understand. whereArgs is of type String[], though the values you are looking for are integers, so I would expect that one should pass in a int[].

    SQ.update(table, values, whereClause, whereArgs)

Where do I go wrong?

Example code (hypothetical):

public void changeOneIntoTwo(DatabaseOperations dop) {
    SQLiteDatabase SQ = dop.getWritableDatabase();
    String selection = "ValuesColumn = ?";
    String[] args = {"1"};
    ContentValues cv = new ContentValues();
    cv.put("ValuesColumn", 2);
    SQ.update("MyTable", cv, selection, args);
}
22
  • 2
    Looks like it doesn't support ints as parameterised args. It should be safe just to do selection = "ValuesColumn = " + Integer.toString(myNumber); Commented Oct 20, 2015 at 19:15
  • 1
    Just pass the string array, sqlite will "know" if it's an int. stackoverflow.com/questions/17481981/… Commented Oct 20, 2015 at 19:20
  • 1
    in sql, string 1 and int 1 both are correctly represented as '1'. So no worries to have, the sql engine will know what type to expect for what column. Commented Oct 20, 2015 at 19:28
  • Java being so very precise, I am a bit disappointed that sqlite is all of a sudden interpreting strings as ints... But thanks, anyway! Commented Oct 20, 2015 at 19:28
  • @njzk2 This is wrong; the comparison will work only if the column has numeric affinity. Commented Oct 20, 2015 at 20:56

1 Answer 1

-1

selection is the condition that you put in where clause of Sql query and args is what replaced by "?" of selection .

for example : lets assume you need your sql query select * from Mytable where ValuesColumn ='1' and Name = 'MVB'. so in this case

String selection = "ValuesColumn = ? AND Name = ?";

String[] args = {"1","MVB"};

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.