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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
public class Records extends SQLiteOpenHelper implements BaseColumns {
private Context myContext;
private SQLiteDatabase myDataBase;
private static final String TAG = "Records";
private static String DB_PATH = "data/data/com.dlfile/databases/";
private static final String DB_NAME = "electeur5.sqlite";
private static final int DB_VERSION = 1;
private static final String TABLE_NAME = "alpha1";
private static final String COLUMN_NOM = "nom";
private final int COLUMN_NOM_ID = 0;
private static final String COLUMN_NOMM = "nom_marital";
private final int COLUMN_NOMM_ID = 1;
private static final String COLUMN_PRENOM = "prenom";
private final int COLUMN_PRENOM_ID = 2;
private final String COLUMN_DATE = "date_naissance";
private final int COLUMN_DATE_ID = 3;
private final String COLUMN_NUMERO = "numero";
private final int COLUMN_NUMERO_ID = 4;
private final String COLUMN_ADRESSE = "adresse";
private final int COLUMN_ADRESSE_ID = 5;
private final String COLUMN_CODEEL = "code_electeur";
private final int COLUMN_CODEEL_ID = 6;
private final String COLUMN_BUREAU = "bureau";
private final int COLUMN_BUREAU_ID = 7;
private final String COLUMN_DOCID = "docid";
private final int COLUMN_DOCID_ID = 8 ;
public void openDatabase() throws SQLException {
Log.e(TAG, "openDatabase called");
String path = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.NO_LOCALIZED_COLLATORS
| SQLiteDatabase.OPEN_READONLY);
}
@Override
public synchronized void close() {
if (myDataBase != null)
myDataBase.close();
super.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void insert(String text) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_NOM, text);
db.insert(TABLE_NAME, COLUMN_NOM, values);
}
public List<String> search(String query, String rechPrenom) {
List<String> result = new ArrayList<String>();
SQLiteDatabase db = getReadableDatabase();
final Cursor cursor = db.query(TABLE_NAME, new String[] { COLUMN_NOM,
COLUMN_NOMM, COLUMN_PRENOM, COLUMN_DATE, COLUMN_NUMERO,
COLUMN_ADRESSE, COLUMN_CODEEL, COLUMN_BUREAU,COLUMN_DOCID }, (COLUMN_NOMM
+ " LIKE ? AND " + COLUMN_PRENOM + " LIKE ? "), new String[] {
query, rechPrenom + "%" }, null, null, null);
// + " OR " +(COLUMN_NOMM +" LIKE ? AND " + COLUMN_PRENOM + " LIKE ? ")
// " OR "+ COLUMN_NOM +
if (cursor.moveToFirst()) {
do {
String text = cursor.getString(COLUMN_NOMM_ID) + " "
+ cursor.getString(COLUMN_PRENOM_ID)
+ "\n Nom de naissance: "
+ cursor.getString(COLUMN_NOM_ID)
+ "\n Date de naissance: "
+ cursor.getString(COLUMN_DATE_ID) + "\n Adresse: "
+ cursor.getString(COLUMN_NUMERO_ID) + " "
+ cursor.getString(COLUMN_ADRESSE_ID)
+ "\n N° Electeur: "
+ cursor.getString(COLUMN_CODEEL_ID) + "\n Bureau: "
+ cursor.getString(COLUMN_BUREAU_ID) + "\n Numéro d'inscrit: "
+ cursor.getString(COLUMN_DOCID_ID);
result.add(text);
} while (cursor.moveToNext());
}
cursor.close();
return result;
}
} |
Partager