I want to insert the image, delete the images and retrieving all the images from SQLite database. I am creating the database with code shown below.
But how can I call these methods in MainActivity
?
public class Imagehelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="abhi.db";
private static final int SCHEMA_VERSION=1;
public Imagehelper(Context context) {
super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE Image(_id INTEGER PRIMARY KEY AUTOINCREMENT,imageblob BLOB);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public Cursor getAll() {
return(getReadableDatabase().rawQuery("SELECT imageblob FROM Image",null));
}
public void insert(byte[] bytes)
{
ContentValues cv=new ContentValues();
cv.put("imageblob",bytes);
Log.e("inserted", "inserted");
getWritableDatabase().insert("Image","imageblob",cv);
System.out.println(":vlfkv: " +cv.size());
}
public byte[] getImage(Cursor c)
{
return(c.getBlob(1));
}
public void deletePhoto(String id) {
SQLiteDatabase database = this.getWritableDatabase();
String deleteQuery = "DELETE FROM Image where _id='"+ id +"'";
Log.d("query",deleteQuery);
database.execSQL(deleteQuery);
}
}