How to do multiple column unique-constraint in ormlite ( SQLite )

牧云@^-^@ 提交于 2019-12-05 02:44:44

How about using

@DatabaseField (uniqueCombo = true) 
String myField;

annotation instead - is it a matter of the uniqueIndexName being faster when accessing items in the table?

Edit:

As @Ready4Android pointed out, we've since added in version 4.20 support for uniqueCombo annotation field. Here are the docs:

http://ormlite.com/docs/unique-combo

There should be no performance differences between using this mechanism versus the uniqueIndexName mentioned below.


Yes. You can't do this with the unique=true tag but you can with a unique index.

@DatabaseField(uniqueIndexName = "unique_store_group_and_item_ids")
int store_group_id;
@DatabaseField(uniqueIndexName = "unique_store_group_and_item_ids")
int store_item_id;

This will create an index to accomplish the unique-ness but I suspect that the unique=true has a hidden index anyway. See the docs:

http://ormlite.com/docs/unique-index

I will look into allowing multiple unique fields. May not be supported by all database types.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!