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
   | package com.database.exploit;
 
 
import java.util.ArrayList;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
 
public class DatabaseHelper extends SQLiteOpenHelper {
 
    private static String DATABASE_NAME = "ELECT.sqlite";
    private static final int DATABASE_VERSION = 4;
    private SQLiteDatabase db;
    private static String TABLE_LISTELEC = "LISTELEC1";
 
    private static String CREATE_TABLE_LISTELEC1 = "create table "
            + TABLE_LISTELEC + " ("
            + "nom TEXT NOT NULL," + "nom_marital TEXT NOT NULL"
            + "prenom VARCHAR(250) NOT NULL" +"datenaissance TEXT NOT NULL"+"bureau TEXT NOT NULL"
            + ")";
 
    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        db = getWritableDatabase();
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_LISTELEC1);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_LISTELEC);
        onCreate(db);
    }
 
 
    /**
     * Charge le contenu de la table Listelec1
     * et retourne ce contenu sous la forme d'une liste de NOM + " " + PRENOM;
     */
    public ArrayList<String> getPersonnes() {
        ArrayList<String> output = new ArrayList<String>();
 
        String[] colonnesARecup = new String[] { "nom", "prenom" };
 
        Cursor cursorResults = db.query(TABLE_LISTELEC, colonnesARecup, null,
                null, null, null, "nom asc, prenom asc", null);
        if (null != cursorResults) {
            if (cursorResults.moveToFirst()) {
                do {
                    int columnIdxNom = cursorResults.getColumnIndex("nom");
                    int columnIdxPrenom = cursorResults
                            .getColumnIndex("prenom");
                    String nomPrenom = cursorResults.getString(columnIdxNom)
                            + " " + cursorResults.getString(columnIdxPrenom);
                    output.add(nomPrenom);
                } while (cursorResults.moveToNext());
            } // end§if
        }
 
        return output;
    }
 
} | 
Partager