Problem to execute a SQLite query [closed]

6

Table declaration

@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(){

}

}

Inquiry

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 am trying to query if there is an item with the id that I have saved in the alarmes table and generates this error.

    
asked by anonymous 27.07.2015 / 21:28

1 answer

0

Resolution : I was forgetting to put 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);
        }
    }
}
    
31.08.2016 / 21:00