Question

Using the greenDAO generator i use:

entity.addDateProperty("date").notNull();

I insert the value: '2013-10-30', and when i check on my database i have the value there. I checked this value with this query:

select datetime(date) from myTable;

and it returns: 2013-10-10 00:00:00

now in android, when i try to retrieve this value i do (for each row):

myTable.getDate();

which always returns 01/01/1970.

What i found (but might not be the cause for this problem):

  1. I did some debug in my code, and i found out that the class myTableDao.java, generated by greenDAO, on method public void readEntity(Cursor cursor, History_Job entity, int offset) is returning the value "2013" from the cursor:

    entity.setDate(new java.util.Date(cursor.getLong(offset + 1)));

  2. Still inside myTableDao.java, method createTable() i have this field declared as Integer.

    ... "'DATE' INTEGER NOT NULL ," + // 1: date ...

Am i doing something wrong with the property DATE, or is it a bug on greenDAO when trying to use this type of field?

Was it helpful?

Solution 2

GreenDao always returns Date in that particular format. You can call it a bug.

You can see the code here

https://github.com/greenrobot/greenDAO

What you can do is

  • fork GreenDao from here
  • Add a method setDateFormat(String format) and also contributes to others.

See doc of SQLite Date Datatypes here.

SQLite stores date in three formats TEXT,REAL and INTEGER so its all about the GreenDao method which is returning date to you. You can make it modify.

OTHER TIPS

GreenDao uses Java Date objects in the Entities and stores their Date.getTime() (time-in-millis-since-epoch) value as a SQLite INTEGER. This works just fine both ways if you use it properly. I'm not sure why you're manually inserting dates - that defeats the purpose of using an ORM library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top