Commit 8589c065 authored by Lucas NAURY's avatar Lucas NAURY

Initialisation de la DB si vide

parent 63d33379
......@@ -26,11 +26,11 @@ public class DBHelper extends SQLiteOpenHelper {
static final String DB_NAME = "LEBONCOIN.DB";
// database version
static final int DB_VERSION = 1;
static final int DB_VERSION = 2;
// Creating table query
private static final String CREATE_TABLE = "create table " + TABLE_NAME + "(" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + TITLE + " TEXT NOT NULL, " + ADDRESS + " TEXT, " + IMAGE + " TEXT, " + PRICE + " DOUBLE, " + DESCRIPTION + "TEXT);";
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + TITLE + " TEXT NOT NULL, " + ADDRESS + " TEXT, " + IMAGE + " TEXT, " + PRICE + " DOUBLE, " + DESCRIPTION + " TEXT);";
public DBHelper(Context context) {
super(context,
......
......@@ -24,7 +24,6 @@ public class DBManager {
private DBManager(Context c) {
context = c;
//init(); // Useful for adding ads for the first time.
}
public static DBManager getDBManager(Context context) {
......@@ -37,6 +36,12 @@ public class DBManager {
public DBManager open() throws SQLException {
dbHelper = new DBHelper(context);
database = dbHelper.getWritableDatabase();
//S'il n'y a pas d'annonce, on initialise une liste d'annonces
if(this.getAll().size() == 0){
init();
}
return this;
}
......@@ -100,7 +105,6 @@ public class DBManager {
Cursor cursor = this.fetch();
if (cursor.moveToFirst()) {
do {
String titre = cursor.getString(abs(cursor.getColumnIndex(DBHelper.TITLE)));
String adresse = cursor.getString(abs(cursor.getColumnIndex(DBHelper.ADDRESS)));
......@@ -110,7 +114,6 @@ public class DBManager {
annonces.add(new Annonce(titre, adresse, image, prix, description));
} while (cursor.moveToNext());
}
return annonces;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment