Permalink
Browse files

Bug fix. NotesDb now handles notes with null valued dates.

  • Loading branch information...
1 parent d765dff commit 66fe05c4c787971a6081beaeec4b90a7448b93ad @brasse committed Jan 30, 2011
@@ -192,15 +192,19 @@ public long createNote(String content, List<String> tags) {
}
}
+ private Long dateToLong(Date d) {
+ return d != null ? d.getTime() : null;
+ }
+
public long createNote(Note note) {
mDb.beginTransaction();
try {
// Create note.
ContentValues noteValues = new ContentValues();
noteValues.put(KEY_KEY, note.getKey());
noteValues.put(KEY_DELETED, note.isDeleted());
- noteValues.put(KEY_CREATEDATE, note.getCreateDate().getTime());
- noteValues.put(KEY_MODIFYDATE, note.getModifyDate().getTime());
+ noteValues.put(KEY_CREATEDATE, dateToLong(note.getCreateDate()));
+ noteValues.put(KEY_MODIFYDATE, dateToLong(note.getModifyDate()));
noteValues.put(KEY_SYNCNUM, note.getSyncNum());
noteValues.put(KEY_VERSION, note.getVersion());
noteValues.put(KEY_MINVERSION, note.getMinVersion());
@@ -226,8 +230,8 @@ public void updateNote(Note note) {
ContentValues noteValues = new ContentValues();
noteValues.put(KEY_KEY, note.getKey());
noteValues.put(KEY_DELETED, note.isDeleted());
- noteValues.put(KEY_CREATEDATE, note.getCreateDate().getTime());
- noteValues.put(KEY_MODIFYDATE, note.getModifyDate().getTime());
+ noteValues.put(KEY_CREATEDATE, dateToLong(note.getCreateDate()));
+ noteValues.put(KEY_MODIFYDATE, dateToLong(note.getModifyDate()));
noteValues.put(KEY_SYNCNUM, note.getSyncNum());
noteValues.put(KEY_VERSION, note.getVersion());
noteValues.put(KEY_MINVERSION, note.getMinVersion());
@@ -254,8 +258,12 @@ public static Note noteFrom(Cursor cursor) {
note.setId(cursor.getLong(0));
note.setKey(cursor.getString(1));
note.setDeleted(cursor.getInt(2) != 0);
- note.setModifyDate(new Date(cursor.getLong(3)));
- note.setCreateDate(new Date(cursor.getLong(4)));
+ if (!cursor.isNull(3)) {
+ note.setModifyDate(new Date(cursor.getLong(3)));
+ }
+ if (!cursor.isNull(4)) {
+ note.setCreateDate(new Date(cursor.getLong(4)));
+ }
note.setSyncNum(cursor.getInt(5));
note.setVersion(cursor.getInt(6));
note.setMinVersion(cursor.getInt(7));
@@ -40,6 +40,11 @@ public String getString(int columnIndex) {
}
@Override
+ public boolean isNull(int columnIndex) {
+ return rows[position][columnIndex] == null;
+ }
+
+ @Override
public boolean isAfterLast() {
return position >= rows.length;
}
@@ -71,6 +71,18 @@ private void assertEqualNotes(Note note0, Note note1) {
assertEquals(note0.isUnread(), note1.isUnread());
}
+ public void testCanCreateAlmostEmptyNoteFromNoteObjectAndReadIt() {
+ Note note0 = new Note();
+ note0.setContent("Creating note from note object.");
+ Long id = db.createNote(note0);
+ assertTrue("Note creation failed.", id != -1);
+ assertEquals(id, note0.getId());
+ Note note1 = db.getNote(id);
+ assertNotNull(note1);
+ assertEquals(id, note1.getId());
+ assertEqualNotes(note0, note1);
+ }
+
public void testCanCreateFromNoteObjectAndReadIt() {
Note note0 = new Note();
note0.setContent("Creating note from note object.");
@@ -112,6 +124,8 @@ public void testCanCreateFromNoteObjectAndUpdateItAndReadIt() {
assertTrue("Note creation failed.", id != -1);
note0.setTags(Arrays.asList(new String[] {"x", "y", "z"}));
+ note0.setCreateDate(null);
+ note0.setModifyDate(null);
note0.setContent("new content");
db.updateNote(note0);

0 comments on commit 66fe05c

Please sign in to comment.