简体   繁体   English

不一致的android sqlite数据库检查

[英]Inconsistent android sqlite database check

I am trying to check if an entry in an sqlite android database exists. 我正在尝试检查sqlite android数据库中是否存在条目。 My code works when the Id's are unique but when there are duplicate Ids with different suspensionUnit values, things are inconsistent. 当Id是唯一的,但是当重复的Id具有不同的suspensionUnit值时,我的代码将起作用,这是不一致的。 On the first try my code returns false regardless of whats in the db ie even when it should return true it always returns false the first time. 第一次尝试时,无论数据库中有什么内容,我的代码都将返回false,即,即使应该返回true,也总是在第一次返回false。 Trying again, however returns true and continues to return true so long as I am in the same fragment. 但是,再次尝试返回true,只要我在同一片段中,就继续返回true。 Now, if I try checking for another entry with the same Id but different suspensionUnit I will get false on the first attempt and then true again and again. 现在,如果我尝试检查具有相同ID的另一个入口,但不同suspensionUnit我会得到错误的第一次尝试,然后真正的一遍又一遍。 If I now try the first entry (the one we started with) it goes back to false again. 如果我现在尝试第一个条目(我们开始使用的条目),它将再次返回false。 ARGH 阿格

public Boolean getGear(String id, String suspensionUnit) {
        SQLiteDatabase db = this.getReadableDatabase();

        String Query = "Select * from " + TABLE_GEAR
                + " where " + KEY_GEAR_ID + " = \"" + id
                + "\" and " + KEY_SUSPENSION_UNIT + " = \"" + suspensionUnit + "\";";
        Cursor cursor = db.rawQuery(Query, null);
        if(cursor.getCount() <= 0){
            cursor.close();
            return false;
        }
        cursor.close();
        return true;
    }

Found the error in another part of my code where I was erroneously updating everything in the table. 在我错误地更新表中所有内容的代码的另一部分中发现了错误。 doh h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM