extends SQLiteOpenHelper to create your own data helper
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class DataHelper extends SQLiteOpenHelper {
private static final String TABLE_UPDATE = "updatedb";
private static final String CREATE_BDD = "CREATE TABLE " + TABLE_UPDATE +
" (script_name TEXT PRIMARY KEY, " +
"script_description TEXT, website TEXT, script_ver TEXT, " +
"script_author TEXT, username TEXT, " +
"date_first_upload TEXT, date_last_update TEXT, " +
"phone_brand TEXT, phone_model TEXT, " +
"phone_firm_ver TEXT, phone_android_sdk TEXT," +
"category TEXT, script_downloads TEXT, " +
"zip_attached TEXT, execution TEXT, " +
"md5sum_int TEXT, md5sum_ext TEXT, link_ext TEXT, link_txt TEXT, md5sum_txt TEXT);";
public DataHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
//on cr la table partir de la requte crite dans la variable CREATE_BDD
db.execSQL(CREATE_BDD);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//On peut fait ce qu'on veut ici moi j'ai dcid de supprimer la table et de la recrer
//comme a lorsque je change la version les id repartent de 0
db.execSQL("DROP TABLE " + TABLE_UPDATE + ";");
onCreate(db);
}
}
Related examples in the same category