Android SQL Blob

I'm trying to store and array of bytes (byte[]) into a DB. I have the array of bytes, a content provider and a database. When I try to insert into the Blob the insert returns -1. Can somebody show me how to get this done.

Insert

byte[] inData = nw.receive();
ContentValues values = new ContentValues();
values.put(InDatabase.Columns.DATA, inData);
values.put(InDatabase.Columns.SIZE, inData.length);
NetService.this.getContentResolver().insert(InContentProvider.CONTENT_URI, values);

Content Provider

mDB = mDBHelper.getWritableDatabase();
Long rowId = mDB.insert(mDBHelper.tableName(), null, aValues);

Database


@Override 
public void onCreate(SQLiteDatabase db) { 
        db.execSQL("CREATE table " + TABLE_NAME + "(id INTEGER PRIMARY KEY AUTOINCREMENT, data BLOB, size INTEGER);"); 
}

Like I said If I don't put the values.put(InDatabase.Columns.DATA, inData) , it works perfect.


So the implementation was right, the problem was with the SQLiteDatabaseHelper. I did not implement the onUpdate() method. Because my database already existed on the device with a different layout (the BLOB field did not exist) the insert method failed.

A quick uninstall of the .apk fixed the problem. I could also implement the onUpdate method so when the database version changes there is a table drop or update.

链接地址: http://www.djcxy.com/p/31962.html

上一篇: 为什么我的异常处理程序不会捕获Android SQLite插入错误?

下一篇: Android SQL Blob