Sqlite数据库插入在某些设备上始终返回-1

时间:2016-06-15 12:53:55

标签: database insert android-sqlite android-6.0-marshmallow android-6.0.1-marshmallow

我尝试在sqlite db中插入一个条目,但这在某些设备上不起作用! 该插件可与设备 Huawei Nexus 6P(Android 6.0,API23)配合使用,但不适用于设备 Samsung SM-G930F(Android 6.0.1,API23)

你能帮帮我吧!返回码总是" res = -1"。 这是我插入新注册的代码:

public boolean insertRegistration(Registration registration){

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put("phoneNumber", registration.getPhoneNumber());
    cv.put("serverPassword", registration.getServerPassword());
    cv.put("chatPassword", registration.getChatPassword());
    cv.put("username", registration.getUsername());
    cv.put("fileURL", registration.getFileURL());

    long res = 0;
    try
    {
        res = db.insert(TABLE_USER, null, cv);
    }
    catch(SQLException e)
    {
        // Sep 12, 2013 6:50:17 AM
        Log.e("Exception", "SQLException" + String.valueOf(e.getMessage()));
        e.printStackTrace();
    }

    if(res == -1)
        throw new RuntimeException("New registration can not be inserted into local db");
    db.close();
    return res >= 0;
}

调试器也不会出现问题!不会发回任何警告或错误!

db看起来像这样:

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(DATABASE_CREATE_USER);
}

创建用户数据库字符串:

  

private static final String DATABASE_CREATE_USER =" create table"               + TABLE_USER +"("               +" id整数主键自动增量,"               +" phoneNumber文本不为空,"               +" serverPassword文本不为空,"               +" chatPassword文字不为空,"               +" fileURL文本不为空,"               +"用户名文字不为空"               +");&#34 ;;

我总是得到返回代码" -1",如果我调试这行" res = db.insert(TABLE_USER,null,cv);"在设备"三星SM-G930F"。

提前谢谢你!

0 个答案:

没有答案