Android :: SQLite, no such column found?

Hi everyone, I'm new to Android simulator and would like to help with this?

android.database.sqlite.SQLiteException: there is no such column: asd :, at compilation: DELETE FROM labels WHERE name = asd

this is the error facing, and here is the code:

this is the method in DBhelper:

/** * Delete a label table * */ public void deleteLabel(String label) { SQLiteDatabase db = this.getWritableDatabase(); // ContentValues values = new ContentValues(); // values.remove(label); // Deleting Row db.delete(TABLE_LABELS, KEY_NAME + "=" + label, null); db.close(); // Closing database connection } 

and here is the main operation code calling the method:

 // for spinner onItemListener // and here is what label is final String label = parent.getItemAtPosition(position).toString(); Button dialogDeletelButton = (Button) dialog .findViewById(R.id.deleteButton); dialogDeletelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // database handler DatabaseHandler db = new DatabaseHandler( getApplicationContext()); // inserting new label into database db.deleteLabel(label); // Hiding the keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(inputLabel.getWindowToken(), 0); // loading spinner without the deleted data loadSpinnerData(); } }); 
+6
source share
1 answer

You almost certainly need to specify 'asd' (i.e. the label variable in your code). If quoted, this is a string to compare with the name column.

If it is incorrect, SQL simply treats it as a different column name.

You can do this in your work with:

 db.deleteLabel ("'" + label + "'"); 

but it may be easier to change the helper function:

 db.delete (TABLE_LABELS, KEY_NAME + "='" + label + "'", null); 

since it looks like you can do something with an unquoted tag at some point ( ContentValues material that is currently commented out).

+13
source

All Articles