1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
package fr.super_nantapp.pendugame;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import java.util.List;
public class DataBase extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "X-Game";
private static final int DATABASE_VERSION = 1;
public DataBase (Context context ){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
try {
TableUtils.createTable(connectionSource, Scores.class);
} catch( Exception ecxeption ){
return;
}
}
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
TableUtils.dropTable(connectionSource, Scores.class, true);
onCreate(database, connectionSource);
} catch (Exception ecxeption){
return;
}
}
public void insertScore( Scores score){
try {
Dao<Scores, Integer> dao = getDao(Scores.class);
dao.createIfNotExists(score);
} catch (Exception exception ){
return;
}
}
public List<Scores> readScores(){
try {
Dao<Scores, Integer> dao = getDao(Scores.class);
List<Scores> scores = dao.queryForAll();
return scores;
} catch (Exception exception ){
return null;
}
}
} |
Partager