我在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;
}
答案 0 :(得分:2)
数据库中没有conecptID
值为0的任何条目,同样的原因是您已在conceptID
中将concept table
声明为Integer Auto Increment
所以当您插入第一个记录值将是conceptId值将为1
,
您是否可以尝试在查询中传递1,并且只是检查最初尝试使用select * from ....
尝试从数据库中获取所有记录