java - Android unable to write datetime to sqllite database -


i'm using google tasks api in app. 1 of fields in app "due date" requires datetime object. im using android datepicker dailog , edittext view capture due date , converting user input datetime format. when try write sqlite database following exception.

error inserting due=2015-06-14t15:58:38.572-04:00 title=test app _id=taskid0.07429873487580996 status=needsaction notes=test write     android.database.sqlite.sqliteexception: table tasks has no column named due (code 1): , while compiling: insert tasks(due,title,_id,status,notes) values (?,?,?,?,?) 

which confusing because define column named "due". further in logs there exception.

06-14 15:58:38.607  15395-15395/com.github.idclark.forgetmenot e/editfragment﹕ null     java.text.parseexception: unparseable date: "06/14/15" (at offset 8)             @ java.text.dateformat.parse(dateformat.java:579)             @ com.github.idclark.forgetmenot.editfragment.gettaskduedate(editfragment.java:64) 

the schema defined

public static final class taskentry implements basecolumns {          public static final string table_name = "tasks";         public static final string column_task_id = "_id";         public static final string column_task_title = "title";         public static final string column_task_updated = "updated";         public static final string column_task_selflink = "selflink";         public static final string column_task_parent = "parent";         public static final string column_task_position = "position";         public static final string column_task_notes = "notes";         public static final string column_task_status = "status";         public static final string column_task_due = "due";         public static final string column_task_completed = "completed";         public static final string column_task_deleted = "deleted";         public static final string column_task_hidden = "hidden"; 

so "due" column exist. , table created

@override     public void oncreate(sqlitedatabase db) {          //status must either needsaction or completed          final string create_task_table =                 "create table " + taskentry.table_name + " (" +                         taskentry._id + " integer primary key," +                         taskentry.column_task_id + "text not null, " +                         taskentry.column_task_title + "text not null, " +                         taskentry.column_task_completed + "text, " +                         taskentry.column_task_notes + "text, " +                         taskentry.column_task_status + "text not null, " +                         taskentry.column_task_due + "datetime, " +                         taskentry.column_task_updated + "datetime, " +                         taskentry.column_task_parent + "text, " +                         taskentry.column_task_deleted + "boolean, " +                         taskentry.column_task_selflink + "text, " +                         taskentry.column_task_position + "text, " +                         taskentry.column_task_hidden + "text" + ")";          db.execsql(create_task_table);     } 

the due date conversion takes place in method.

public datetime gettaskduedate() {     mduedate = (edittext) getactivity().findviewbyid(r.id.task_due_date);     return new datetime(mduedate.gettext().tostring()); } 

the data written database

public boolean insertrow(task task) {         contentvalues values = new contentvalues();         values.put(taskcontract.taskentry.column_task_status, task.getstatus());         values.put(taskcontract.taskentry.column_task_id,task.getid());         values.put(taskcontract.taskentry.column_task_title,task.gettitle());         values.put(taskcontract.taskentry.column_task_due, task.getdue().tostring());         values.put(taskcontract.taskentry.column_task_notes, task.getnotes());          sqlitedatabase db = this.getwritabledatabase();         boolean createsuccessful = db.insert(taskcontract.taskentry.table_name, null, values) > 0;         db.close();         return createsuccessful;     } 

i'm confused why write fails, , sql claims there no "due" column. though there parse exception, see timestamp in logs well. part of problem i'm calling .tostring() on datetime object before writing db? don't have lot of sql experience , genuinely confused make of these exceptions.

for sqlite issue, need have whitespace between column names , types. example, change

taskentry.column_task_due + "datetime, " + 

to

taskentry.column_task_due + " datetime, " + 

there's similar problem of columns.

after fixing create table sql, uninstall , reinstall app recreate database.

for date parsing problem, use date format matches data. if need detailed it, post new question.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -