Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too many bind arguments. 5 arguments were provided but the statement needs 4 arguments

I get the IllegalArgumentException above when executing the function below. What I don't get is that when I run the debugger, the values variable clearly only contains 4 arguments, as it should.

So...

(1) Where does this mysterious fifth argument come from?

(2) How should I approach finding this error?

db.update(
    UppdragEntry.TABLE_NAME,
    values,
    selection,
    selectionArgs);
like image 922
abc32112 Avatar asked Jul 17 '14 07:07

abc32112


1 Answers

Selection contains the following: String selection = "_id"; String[] selectionArgs = {" =" + personId};

You have a value in selectionArgs but no ? placeholder for it in selection.

Change it to

String selection = "_id = ?";
String[] selectionArgs = { "" + personId };

The method builds an SQL string. Supplied ContentValues are built as ? placeholder and bind arguments. Additional selection args are also provided as bind arguments and they must be matched with equal number of ? placeholders.

like image 155
laalto Avatar answered Oct 31 '22 09:10

laalto