summaryrefslogtreecommitdiffstats
path: root/src/ryuslash/org/dvdroid/DVDDataSource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ryuslash/org/dvdroid/DVDDataSource.java')
-rw-r--r--src/ryuslash/org/dvdroid/DVDDataSource.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/ryuslash/org/dvdroid/DVDDataSource.java b/src/ryuslash/org/dvdroid/DVDDataSource.java
index b9fe166..e10fb24 100644
--- a/src/ryuslash/org/dvdroid/DVDDataSource.java
+++ b/src/ryuslash/org/dvdroid/DVDDataSource.java
@@ -33,7 +33,8 @@ public class DVDDataSource
dbHelper.close();
}
- public DVD createDVD(String title, int watched, int wishlist)
+ private ContentValues createValues(String title, int watched,
+ int wishlist)
{
ContentValues values = new ContentValues();
@@ -41,6 +42,12 @@ public class DVDDataSource
values.put(SQLiteHelper.COLUMN_WATCHED, watched);
values.put(SQLiteHelper.COLUMN_WISHLIST, wishlist);
+ return values;
+ }
+
+ public DVD createDVD(String title, int watched, int wishlist)
+ {
+ ContentValues values = createValues(title, watched, wishlist);
long insertId = database.insert(SQLiteHelper.TABLE_DVD, null,
values);
Cursor cursor = database.query(SQLiteHelper.TABLE_DVD,
@@ -57,14 +64,42 @@ public class DVDDataSource
return newDVD;
}
+ public void updateDVD(long id, String title, int watched, int wishlist)
+ {
+ ContentValues values = createValues(title, watched, wishlist);
+ String whereArgs[] = { "" + id };
+
+ database.update(SQLiteHelper.TABLE_DVD, values, "id = ?",
+ whereArgs);
+ }
+
public void deleteDVD(DVD dvd)
{
- long id = dvd.getId();
- System.out.println("DVD deleted with id: " + id);
+ deleteDVD(dvd.getId());
+ }
+
+ public void deleteDVD(long id)
+ {
database.delete(SQLiteHelper.TABLE_DVD,
SQLiteHelper.COLUMN_ID + " = " + id, null);
}
+ public DVD getById(long id)
+ {
+ Cursor cursor = database.query(SQLiteHelper.TABLE_DVD,
+ allColumns,
+ SQLiteHelper.COLUMN_ID + " = " + id,
+ null, null, null, null);
+
+ cursor.moveToFirst();
+
+ DVD dvd = cursorToDVD(cursor);
+
+ cursor.close();
+
+ return dvd;
+ }
+
public List<DVD> getListFromCursor(Cursor cursor)
{
List<DVD> dvds = new ArrayList<DVD>();