删除特定Blob值Sqlite数据库

时间:2016-09-09 11:19:56

标签: android sqlite

我试图删除存储的blob(图像)值,但无法得到它如何删除我已经尝试过但它无法正常删除字符串值i-e视频标题等

这是我的代码,其中获取gridview的所选项目和图像的标题,并将该图像转换为字节数组以匹配该字节数组值与DB blob值(如果我在这里做错了,请纠正我)

gv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {


            TextView tv=(TextView)view.findViewById(R.id.vtitle);
            ImageView img=(ImageView)view.findViewById(R.id.tit_img);
            img.buildDrawingCache();
            Bitmap bm=img.getDrawingCache();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bm.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            final byte[] img_value = stream.toByteArray();
            final String value=tv.getText().toString();

这就是我在这里删除Gridview所选视频项目的标题我想要删除存储在另一个表格中的图像

 db.delete("vdetail","title=?",new String[]{value});

我尝试了这个用于图像,但它不起作用

db.execSQL("image","thumb=?",img_value);

这就是我创建表格的方式

db= openOrCreateDatabase("MyDb", MODE_PRIVATE, null);
    db.execSQL("create table if not exists image(thumb blob)");
    db.execSQL("create table if not exists vdetail(title varchar,id varchar)");

并且在这里成功存储了图像标题和id

public void Save(View view)
{

    bitmap = BitmapFactory.decodeByteArray(
            getIntent().getByteArrayExtra("byteArray"), 0, getIntent().getByteArrayExtra("byteArray").length);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] bitmapdata = stream.toByteArray();
    ContentValues values=new ContentValues();
    ContentValues values1=new ContentValues();
    values.put("thumb",bitmapdata);
    values1.put("title",title);
    values1.put("id",id);
    db.insertWithOnConflict("image",null,values,SQLiteDatabase.CONFLICT_REPLACE);
    db.insertWithOnConflict("vdetail",null,values1,SQLiteDatabase.CONFLICT_REPLACE);
    Log.d("saving", "m here buddy: ");
    Toast.makeText(getApplicationContext(),"Saved",Toast.LENGTH_SHORT).show();
}

从意外额外的先前活动中接收图像(位图)

0 个答案:

没有答案