Problem to execute a query in Sqlite

Asked

Viewed 228 times

6

Table statement

@DatabaseTable(tableName = "alarmes")
 public class ListenerAlarme {

@DatabaseField(generatedId = true)
public long id;

@DatabaseField(canBeNull = true)
public Date dataAlarme;

@DatabaseField(canBeNull = true)
public boolean notificado;

@DatabaseField(foreign = true, canBeNull = false, columnName = "id_item")
public ListenerItem item;

public ListenerAlarme(){

}

}

Consultation

List<ListenerAlarme> alarmeList = mAlarmeDao.queryBuilder().where().eq("id_item", mItem).query();

Error

07-27 16:06:12.304  14544-14544/makerapp.android.minhastarefas E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{makerapp.android.minhastarefas/makerapp.android.minhastarefas.ItemActivity}: java.lang.RuntimeException: java.sql.SQLException: Problems executing Android query: SELECT * FROM `alarmes` WHERE `id_item` = 1
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
        at android.app.ActivityThread.access$700(ActivityThread.java:140)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:177)
        at android.app.ActivityThread.main(ActivityThread.java:4947)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
        at dalvik.system.NativeStart.main(Native Method)

I’m trying to see if there’s an item with the id that I have saved in the table alarmes and generates this error.

  • The table alarmes has no column called id_item.

  • 2

    I think you have id_item yes: @DatabaseField(foreign = true, canBeNull = false, columnName = "id_item")

  • Paste your create table in the question please.

  • columnName = "id_item" arrow the column name, it calls id_item

1 answer

0

Resolution: I was forgetting to put the create in the right place.

public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
    try {
        TableUtils.createTable(connectionSource, ListenerList.class);
        TableUtils.createTable(connectionSource, ListenerItem.class);
        TableUtils.createTable(connectionSource, ListenerAlarme.class);
} catch (SQLException e) {
        Log.e(LOG_TAG, "Can't create database", e);
        throw new RuntimeException(e);
    }
}

 public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    if(oldVersion == 2) {
        try {
            TableUtils.createTable(connectionSource, ListenerAlarme.class);
        } catch (SQLException e) {
            Log.e(LOG_TAG, "Can't create database", e);
            throw new RuntimeException(e);
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.