开发者

Odd database error: Empty values?

I'm creating an activity that views a record and displays it's data to a user to modify. After everything is done just click a button to save the data back into the database. However, once saving time comes around I get an unusual "java.lang.IllegalArgumentException: Empty values" error. I think it's a SQL code error on my end, but I don't know enough about SQL to find it. Can I get a couple of eyes to see what I did wrong?

Thanks ~Aedon

Here is where the save button is declared and the listener is set. mBoundService is the service that hosts the 开发者_开发百科database and it's calls. DevicesTable is a class that holds the table and column names. DevicesTable.gt_fields[0] is autoincrementID and then serial, name, and first seen columns

public void init() {        
    mDevName = (EditText)findViewById(R.id.dv_name);
    mCurReads = (TextView)findViewById(R.id.dv_readings);
    mSave = (Button)findViewById(R.id.dv_save);
        mSave.setOnClickListener(new OnClickListener() {
            @Override public void onClick(View arg0) {
                mBoundService.updateRecord(DevicesTable.gt_name, mId, DevicesTable.g_fields[2], mDevName.getText().toString());
            }
        });
}

And this is the database call itself.

/**
 * Updates a record at the given table with the given record.
 * @param table The table to update
 * @param id The id of the actual record. Do not pass the incorrect id!
 * @param column The column in which the data is changing
 * @param data The data that is to be changed to
 */
public void updateRecord(String table, String id, String column, String data) {
    mDB.update(table, null, "SET " + column + " = '" + data + "',", new String[]{"id=" + id});
}


You need to pass in a ContentValues object to tell the database what values go in what columns in the updated row(s). The strings in the third and fourth arguments make up a WHERE clause that indicate what row(s) should be updated. For example:

ContentValues values = new ContentValues();
values.put("foo", 123);
values.put("bar", 456);

db.update("some_table", values, "id=789", null);

This would be equivalent to issuing the query

UPDATE some_table SET foo = 123, bar = 456 WHERE id = 789

Your code attempts to stuff the entire query into the WHERE clause, and update() stops you in your tracks because the values argument is null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜