Android复合主键?
谁能告诉我如何在 Android 1.6 中声明包含自动增量 _id 列的复合主键?我不确定语法。当我尝试添加值时,我最终只是在Java中强制执行它(其中registrationNumber + date在表中必须是唯一的):
Cursor fuelUpsCursor = getFuelUps(registrationNumber, date);
if(!fuelUpsCursor.moveToNext())
{
//add registrationNumber and date
}
我真的不需要_id列,但如果表不需要,它会让生活变得棘手有一个。
干杯, 巴里
Can anyone tell me how to declare a composite primary key in Android 1.6 which includes an autoincrement _id column? I'm not sure of the syntax. I've ended up just enforcing it in Java when I try to add values (where registrationNumber + date has to be unique in the table):
Cursor fuelUpsCursor = getFuelUps(registrationNumber, date);
if(!fuelUpsCursor.moveToNext())
{
//add registrationNumber and date
}
I don't really need the _id column but it can make life tricky if tables don't have one.
Cheers,
Barry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题没有多大意义。您的主题行要求“复合外键”,您的第一句话要求“复合主键”和
AUTOINCRMENT
,然后您的示例代码会忽略它。我将这样解释您的问题:您希望表中的
_ID INTEGER PRIMARY KEY AUTOINCRMENT
列能够使用 Android 的CursorAdapter
,但您还希望确保其他两列的组合是唯一的。在这种情况下,我认为您想要使用
UNIQUE
约束:Your question does not make much sense. Your subject line asks for a "composite foreign key", your first sentence asks for a "composite primary key" with an
AUTOINCREMENT
that your sample code then ignores.I am going to interpret your question this way: You want an
_ID INTEGER PRIMARY KEY AUTOINCREMENT
column in your table to be able to use Android'sCursorAdapter
, but you want to also make sure that the combination of two other columns is unique.In that case, I think that you want to use a
UNIQUE
constraint: