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
|
public class TypeProduitDB extends SQLiteOpenHelper{
private static final int BD_VERSION = 1;
private static final String BD_NAME = "typeproduit.db";
private static final String TB_TYPE_PRODUIT = "typeProduit";
private static final String TB_COL_ID = "_id";
private static final String TB_COL_LIBELLE = "libelle";
private static final String CREER_TB= "CREATE TABLE " + TB_TYPE_PRODUIT + " ("
+ TB_COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + TB_COL_LIBELLE + " TEXT ); ";
private SQLiteDatabase bdd;
public TypeProduitDB(Context context) {
super(context,BD_NAME,null, BD_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREER_TB);
/* je voudrais remplir ma table une fois la base de données créée
puisque les données de la table ne changent pas
dans le temps*/
}
public boolean Open()/* cette methode me permeterra juste d'ouvrir l
a base de données pour récupérer les données,sans faire des insert/update par la suite*/
{
try {
bdd = this.getWritableDatabase();
}
catch (SQLiteException ex){
bdd = this.getReadableDatabase();
}
return ( bdd != null);
}
public void Close()
{
if( bdd != null)
bdd.close();
}
public Object[] SelectAll()
{
Cursor cursor = bdd.rawQuery("select " + TB_COL_LIBELLE + " from "+TB_TYPE_PRODUIT, null);
if (cursor.getCount() == 0)
return null;
ArrayList<String> tp = new ArrayList<String>() ;
if(cursor.moveToFirst())
{
do
{
tp.add(cursor.getString(0));
}while(cursor.moveToNext());
}
cursor.close();
return tp.toArray();
} |
Partager