greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

How does Greendao's insertOrReplace method avoid changing the corresponding value in the database when some filelds of the object are null? #1038

Open windfallsheng opened 4 years ago

windfallsheng commented 4 years ago

当对象的一些属性为null时,greendao的insertOrReplace方法怎么避免修改数据库里对应的值? EN:How does Greendao's insertOrReplace method avoid changing the corresponding value in the database when some filelds of the object are null?

greenrobot-team commented 4 years ago

This is the SQLite command used: https://github.com/greenrobot/greenDAO/blob/0cce6c004181eeec9b900c9bd2ef47d7f0c23893/DaoCore/src/main/java/org/greenrobot/greendao/internal/TableStatements.java#L67

According to https://www.sqlite.org/lang_conflict.html this means if an entity/row with this key exists, it will be deleted first before the given entity/row is inserted.