jeudi 17 septembre 2015

db.insert() return -1 sqlite

I am using contentProvider's bulckInsert method to insert new data into my sqlite table. here is my code:

@Override
    public int bulkInsert(Uri uri, ContentValues[] values){
        int returnCount = 0;
        final SQLiteDatabase db = mDbHelper.getWritableDatabase();
        final int match = sUriMatcher.match(uri);
        long _id;
        switch (match){
            case USER_ACCOUNTS:
                db.beginTransaction();
                try {
                    for (ContentValues value : values){
                        _id = db.insert(UserAccountsEntry.TABLE_NAME, null, value);
                        if (_id != -1){
                            returnCount ++;
                        }
                    }
                    db.setTransactionSuccessful();
                } catch (Exception e){
                    e.printStackTrace();
                } finally {
                    db.endTransaction();
                }
                getContext().getContentResolver().notifyChange(uri, null);
                return  returnCount;
}

but _id = db.insert() return -1.

here is the value I am trying to insert

us_ac_id=2625650794301.978

and here is SQLiteOpenHelper onCreate method:

@Override
    public void onCreate(SQLiteDatabase db) {
        sDb = db;
        final String SQL_CREATE_USER_ACCOUNTS_TABLE = "CREATE TABLE " +
                UserAccountsEntry.TABLE_NAME + " (" +
                UserAccountsEntry.ACCOUNT_ID + " FLOAT, " +
                "UNIQUE (" +UserAccountsEntry.ACCOUNT_ID + " ) ON CONFLICT REPLACE);";

               db.execSQL(SQL_CREATE_USER_ACCOUNTS_TABLE);

    }

any ideas why it happens?

Aucun commentaire:

Enregistrer un commentaire