Android 我在此查询中得到0个结果。我做错了什么?(安卓)

Android 我在此查询中得到0个结果。我做错了什么?(安卓),android,sql,database,sqlite,Android,Sql,Database,Sqlite,我在Android上使用SQLite。这是我的三张桌子: String query = "create table " + TABLE_PERSON + " (" + PERSON_COL_ID + " integer PRIMARY KEY AUTOINCREMENT, " + PERSON_COL_NAME + " text, " + PERSON_COL_SEX + " text CHECK (" + PERSON_

我在Android上使用SQLite。这是我的三张桌子:

String query = "create table " + TABLE_PERSON + " (" +
            PERSON_COL_ID + "  integer PRIMARY KEY AUTOINCREMENT, " +
            PERSON_COL_NAME + " text, " +
            PERSON_COL_SEX + " text CHECK (" + PERSON_COL_SEX + " IN ('M', 'F'))" +
            ");";
db.execSQL(query);

query = "create table " + TABLE_CONCEPT + " (" +
            CONCEPT_COL_ID + " integer PRIMARY KEY AUTOINCREMENT, " +
            CONCEPT_COL_NAME + " text, " +
            CONCEPT_COL_DATE + " text " +
            ");";
db.execSQL(query);

query = "create table " + TABLE_DEBT + " (" +
            DEBT_COL_ID + " integer PRIMARY KEY AUTOINCREMENT, " +
            DEBT_COL_CONCEPT + " integer REFERENCES " + TABLE_CONCEPT + ", " +
            DEBT_COL_CREDITOR + " integer REFERENCES " + TABLE_PERSON + ", " +
            DEBT_COL_DEBTOR + " integer REFERENCES " + TABLE_PERSON + ", " +
            DEBT_COL_ORIGAMT + " integer, " +
            DEBT_COL_PAIDSOFAR + " integer, " +
            DEBT_COL_DATEREPAID + " text" +
            ");";
db.execSQL(query);
在插入3个人、2个概念和1个债务后,我在进行以下查询后得到0个结果:

  Cursor cur = databaseHelper.getDebtsByConcept(0);
其中执行的查询如下所示:

public Cursor getDebtsByConcept(int conceptID) {
     String query = "select con.name, per1.name, per2.name, deb.origamt, deb.paidsofar, deb.daterepaid" +
            " from " +
            TABLE_PERSON + " per1, " + TABLE_PERSON + " per2, " +  TABLE_CONCEPT + " con, " + TABLE_DEBT + " deb" +
            " where deb.concept = " + conceptID +
            " and con.id = deb.concept " +
            " and per1.id = deb.creditorID" +
            " and per2.id = deb.debtorID;";

     Cursor res = db.rawQuery(query, null);
     return res;
}

数据库中不会有任何conecptID值为0的条目,原因是您已在概念表中将conceptID声明为整数自动递增,因此当您插入第一条记录时,conceptID值将为1


您是否可以尝试在查询中传递1,并仅在初始检查时尝试使用select*from….从数据库中获取所有记录

使用conceptID==1进行搜索也会返回0个条目。从债务中选择*返回一个条目,这是唯一存在的条目:列0->1,列1->0,列2->0,列3->0,列4->10000,列5->100,列6->xxx,数据中似乎有一些不匹配,您可以从中选择*。。其他表格,看看你得到了什么结果?我认为很明显发生了什么。债务表中的外键没有指向任何地方:>>债务>人员>概念我最终解决了它。非常感谢。问题是最明显的。