no such column: task_date (code 1):



  • no such column: task_date (code 1): , while compiling: SELECT * FROM tasks_table WHERE task_status = ? OR task_status = ? ORDER BY task_date

    I checked the code many times and couldn't find a mistake.

    DBHelper

     
    

    public class DBHelper extends SQLiteOpenHelper {

        public static final int DATABASE_VERSION = 1;
    
        public static final String DATABASE_NAME = "reminder_database";
    
        public static final String TASKS_TABLE = "tasks_table";
    
        public static final String TASK_TITLE_COLUMN = "task_title";
        public static final String TASK_DATE_COLUMN = "task_date";
        public static final String TASK_PRIORITY_COLUMN = "task_priority";
        public static final String TASK_STATUS_COLUMN = "task_status";
        public static final String TASK_TIME_STAMP_COLUMN = "task_time_stamp";
    
        private static final String TASKS_TABLE_CREATE_SCRIPT =  "CREATE TABLE "
                + TASKS_TABLE + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + TASK_TITLE_COLUMN + " TEXT NOT NULL, "
                + TASK_DATE_COLUMN + " LONG, " + TASK_PRIORITY_COLUMN + " INTEGER, "
                + TASK_STATUS_COLUMN + " INTEGER, " + TASK_TIME_STAMP_COLUMN + " LONG);";
    
    
        public static final String SELECTION_STATUS = DBHelper.TASK_STATUS_COLUMN + " = ?";
        public static final String SELECTION_TIME_STAMP = TASK_TIME_STAMP_COLUMN + " = ?";
    
        private DBQueryManager dbQueryManager;
        private DBUpdateManager dbUpdateManager;
    
    
    
        public DBHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            dbQueryManager = new DBQueryManager(getReadableDatabase());
            dbUpdateManager = new DBUpdateManager(getWritableDatabase());
        }
    
        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(TASKS_TABLE_CREATE_SCRIPT);
    
        }
    
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE " + TASKS_TABLE);
             onCreate(db);
        }
    
        public void saveTask(ModelTask task){
    
            ContentValues newValues = new ContentValues();
    
            newValues.put(TASK_TITLE_COLUMN,task.getTitle());
            newValues.put(TASK_DATE_COLUMN,task.getDate());
            newValues.put(TASK_STATUS_COLUMN,task.getStatus());
            newValues.put(TASK_PRIORITY_COLUMN,task.getPriority());
            newValues.put(TASK_TIME_STAMP_COLUMN, task.getTimeStamp());
    
            getWritableDatabase().insert(TASKS_TABLE, null, newValues);
    
        }
    
        public DBUpdateManager update() {
            return dbUpdateManager;
        }
    
        public DBQueryManager query() {
            return dbQueryManager;
        }
    
        public void removeTask(long timeStamp){
            getWritableDatabase().delete(TASKS_TABLE,SELECTION_TIME_STAMP,new String[]{Long.toString(timeStamp)});
    
        }
    }</code></pre></div></div></p><p>DBQueryManager</p><pre><code>ublic class DBQueryManager {
    private SQLiteDatabase sqLiteDatabase;
    
    public DBQueryManager(SQLiteDatabase sqLiteDatabase) {
        this.sqLiteDatabase = sqLiteDatabase;
    }
    
    
    public ModelTask getTask(long timeStamp){
        ModelTask modelTask = null;
        Cursor c = sqLiteDatabase.query(DBHelper.TASKS_TABLE,null,DBHelper.SELECTION_TIME_STAMP,
                new String[]{Long.toString(timeStamp)},null,null,null);
    
        if (c.moveToFirst()){
    
            String title = c.getString(c.getColumnIndex(DBHelper.TASK_TITLE_COLUMN));
            long date =  c.getLong(c.getColumnIndex(DBHelper.TASK_DATE_COLUMN));
            int priority = c.getInt(c.getColumnIndex(DBHelper.TASK_PRIORITY_COLUMN));
            int status = c.getInt(c.getColumnIndex(DBHelper.TASK_STATUS_COLUMN));
            modelTask = new ModelTask(title,date,priority,status,timeStamp);
    
        }
        c.close();
        return modelTask;
    
    }
    
    
    public List&lt;ModelTask&gt; getTask(String selection , String[] selectionArgs,String orderBy){
        List&lt;ModelTask&gt; tasks = new ArrayList&lt;&gt;();
    
        Cursor c = sqLiteDatabase.query(DBHelper.TASKS_TABLE, null,selection,selectionArgs,null,null,orderBy);
    
        if (c.moveToFirst()){
            do {
    
                String title = c.getString(c.getColumnIndex(DBHelper.TASK_TITLE_COLUMN));
                long date =  c.getLong(c.getColumnIndex(DBHelper.TASK_DATE_COLUMN));
                int priority = c.getInt(c.getColumnIndex(DBHelper.TASK_PRIORITY_COLUMN));
                int status = c.getInt(c.getColumnIndex(DBHelper.TASK_STATUS_COLUMN));
                long timeStamp = c.getInt(c.getColumnIndex(DBHelper.TASK_TIME_STAMP_COLUMN));
    
                ModelTask modelTask = new ModelTask(title,date,priority,status,timeStamp);
                tasks.add(modelTask);
    
    
    
            }while (c.moveToNext());
        }
        c.close();
        return tasks;
    
    
    }
    

    }



  • Maybe you should do this: 1. - amend the table code to read

    CREATE TABLE "tasks_table" (
        `_ID`   INTEGER PRIMARY KEY AUTOINCREMENT,
        `task_title`    TEXT NOT NULL,
        `task_date` INTEGER,
        `task_priority` INTEGER,
        `task_status`   INTEGER,
        `task_time_stamp`   INTEGER
    )
    

    2. Remove the request

    > SELECT * FROM tasks_table WHERE task_status = ? OR task_status = ?
    > ORDER BY task_date
    

    &quot;

     `SELECT * FROM tasks_table WHERE task_status = ? ORDER BY task_date;`
    

    I think I'll help you with my advice.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2