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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION=1;
private static final String DATABASE_NAME="Donsang.db";
private static final String TABLE_NAME="Inscription";
private static final String COLUMN_ID="id";
private static final String COLUMN_PSEUDO="pseudo";
private static final String COLUMN_NAME="nom";
private static final String COLUMN_PHONE="phone";
private static final String COLUMN_NAISSANCE="naissance";
private static final String COLUMN_DATEDON="datedon";
private static final String COLUMN_IMAGE="image";
SQLiteDatabase db;
private static final String TABLE_CREATE="create table Inscription (id integer primary key not null auto_increment,"+
"pseudo text not null,nom text not null,phone text not null,naissance text not null" +
"datedon text not null,image Blob";
public DatabaseHelper(Context context)
{
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
this.db=db;
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
String query="DROP TABLE IF EXISTS " + TABLE_NAME;
db.execSQL(query);
this.onCreate(db);
}
public boolean insertData(String pseudo,String nom,String phone,String naissance,String datedon,
String image)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues contentValues=new ContentValues();
contentValues.put(COLUMN_PSEUDO,pseudo);
contentValues.put(COLUMN_NAME,nom);
contentValues.put(COLUMN_PHONE,phone);
contentValues.put(COLUMN_NAISSANCE,naissance);
contentValues.put(COLUMN_DATEDON,datedon);
contentValues.put(COLUMN_IMAGE,image);
long result= db.insert(TABLE_NAME,null,contentValues);
if(result==-1)
return false;
else
return true;
}
public List<Inscription> getAll()
{
String[] columns = {
COLUMN_PSEUDO,
COLUMN_NAME,
COLUMN_PHONE,
COLUMN_NAISSANCE,
COLUMN_DATEDON,
COLUMN_IMAGE
};
String sortOrder =
COLUMN_PSEUDO + " ASC";
List<Inscription> inscritList = new ArrayList<Inscription>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME,
columns,
null,
null,
null,
null,
sortOrder);
if (cursor.moveToFirst()) {
do {
Inscription user = new Inscription();
user.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(COLUMN_ID))));
user.setPseudo(cursor.getString(cursor.getColumnIndex(COLUMN_PSEUDO)));
user.setNom(cursor.getString(cursor.getColumnIndex(COLUMN_NAME)));
user.setPhone(cursor.getInt(cursor.getColumnIndex(COLUMN_PHONE)));
user.setNaissance(cursor.getString(cursor.getColumnIndex(COLUMN_NAISSANCE)));
user.setDate(cursor.getString(cursor.getColumnIndex(COLUMN_DATEDON)));
user.setImage(cursor.getBlob(cursor.getColumnIndex(COLUMN_IMAGE)));
inscritList.add(user);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return inscritList;
}
public boolean checkInscris(String phone) {
String[] columns = {
COLUMN_ID
};
SQLiteDatabase db = this.getReadableDatabase();
String selection = COLUMN_PHONE + " = ?";
String[] selectionArgs = {phone};
Cursor cursor = db.query(TABLE_NAME,
columns,
selection,
selectionArgs,
null,
null,
null);
int cursorCount = cursor.getCount();
cursor.close();
db.close();
if (cursorCount > 0) {
return true;
}
return false;
}
public boolean checkInscris(String pseudo, String phone) {
String[] columns = {
COLUMN_ID
};
SQLiteDatabase db = this.getReadableDatabase();
String selection = COLUMN_PSEUDO + " = ?" + " AND " + COLUMN_PHONE + " = ?";
String[] selectionArgs = {pseudo, phone};
Cursor cursor = db.query(TABLE_NAME,
columns,
selection,
selectionArgs,
null,
null,
null);
int cursorCount = cursor.getCount();
cursor.close();
db.close();
if (cursorCount > 0) {
return true;
}
return false;
} |
Partager