lundi 15 février 2016

SQLite getting null values after insertion

I am inserting a row that has following 4 columns:

  1. Day
  2. Task
  3. Task Description
  4. TaskTime

But only two columns are inserted successfully i.e. Day and Task. However, Task Description and TaskTime are null apparently.

public Task createTask(String day, String task, String taskDescription, String taskTime) {
        ContentValues values = new ContentValues();
        values.put(MySQLiteHelper.COLUMN_DAY, day);
        values.put(MySQLiteHelper.COLUMN_TASK, task);
        values.put(MySQLiteHelper.COLUMN_TASK_DESCRIPTION, taskDescription);
        values.put(MySQLiteHelper.COLUMN_TASK_TIME, taskTime);

        System.out.println("Inserting task:" + task + " taskDescription:" + taskDescription + " taskTime:" + taskTime);
        long insertId = database.insert(MySQLiteHelper.TABLE_TASK, null,
                values);
        Cursor cursor = database.query(MySQLiteHelper.TABLE_TASK,
                allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null,
                null, null, null);
        cursor.moveToFirst();
        Task newTask = cursorToTask(cursor);
        System.out.println("Fetching cursor task:"+newTask.getTask()+" taskDescription:"+newTask.getTaskDescription()+" taskTime:"+newTask.getTaskTime());

        cursor.close();
        return newTask;
    }

I am using the aforementioned code to insert the data into the database. Could anyone explain why only two columns are getting inserted into the database instead of of 4 columns?

Aucun commentaire:

Enregistrer un commentaire