Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android :: SQLite, no such column found?

Hey all Im a newbie Androidian, and would love some help with this?

android.database.sqlite.SQLiteException: no such column: asd: , while compiling: DELETE FROM labels WHERE name=asd

this is the error am facing, and here's the code:

this is the method in the 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's the main Activity code that invoke 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();

            }
        });
like image 904
Tayseer Avatar asked Nov 01 '12 08:11

Tayseer


People also ask

Is SQLite deprecated in Android?

In which case, does that mean that SQLLite is deprecated in Android? No.

Is SQLite still used in Android?

Android SQLite is the mostly preferred way to store data for android applications. For many applications, SQLite is the apps backbone whether it's used directly or via some third-party wrapper. Below is the final app we will create today using Android SQLite database.

What is the alternative of SQLite in Android?

But if you want to replace SQLite completely, there are also quite a few alternative databases: Couchbase Lite, Interbase, LevelDB, Oracle Berkeley DB (formerly Oracle's mobile database was "Oracle Database Lite"), Realm, SnappyDB, Sparksee Mobile (graph database, brand-new at the time of this article), SQL Anywhere, ...


1 Answers

You almost certainly need to quote 'asd' (i.e., the label variable in your code). If it's quoted, it's a string to compare against the name column.

If it's unquoted, SQL just treats it as another column name.

You could do this in your activity with:

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

but it may be cleaner to change the helper function:

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

since it looks like you may want to do something with the unquoted label at some point in there (the ContentValues stuff which is currently commented out).

like image 184
paxdiablo Avatar answered Sep 25 '22 12:09

paxdiablo