Fixed
Status Update
Comments
se...@google.com <se...@google.com> #2
Null primary keys are accepted by sqlite: http://www.sqlite.org/lang_createtable.html#primkeyconst
Thou, I agree that here we should be stricter than sqlite and force NOT NULL on primary keys, even if there is no "NonNull" annotation presented.
Thou, I agree that here we should be stricter than sqlite and force NOT NULL on primary keys, even if there is no "NonNull" annotation presented.
fl...@google.com <fl...@google.com>
yb...@google.com <yb...@google.com> #3
i'm not sure if we should since SQLite does allow it. I think it is better to stick with what SQLite does for consistency.
yb...@google.com <yb...@google.com> #4
actually, after discussing w/ sergey and reading the documentation properly, SQLite itself considers this a bug.
i redact my comment, we should insert NOT_NULL by default.
from docs:
According to the SQL standard, PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a bug in some early versions, this is not the case in SQLite. Unless the column is an INTEGER PRIMARY KEY or the table is a WITHOUT ROWID table or the column is declared NOT NULL, SQLite allows NULL values in a PRIMARY KEY column. SQLite could be fixed to conform to the standard, but doing so might break legacy applications. Hence, it has been decided to merely document the fact that SQLite allowing NULLs in most PRIMARY KEY columns.
i redact my comment, we should insert NOT_NULL by default.
from docs:
According to the SQL standard, PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a bug in some early versions, this is not the case in SQLite. Unless the column is an INTEGER PRIMARY KEY or the table is a WITHOUT ROWID table or the column is declared NOT NULL, SQLite allows NULL values in a PRIMARY KEY column. SQLite could be fixed to conform to the standard, but doing so might break legacy applications. Hence, it has been decided to merely document the fact that SQLite allowing NULLs in most PRIMARY KEY columns.
yb...@google.com <yb...@google.com> #5
also, to make it more explicit, we can force the developer to add the @NonNull annotation on primary keys thought it might be a bit inconvenient.
Description
Version used: 1.0.0-alpha8
Given the following entity:
@Entity(tableName = "foo")
public class FooEntity {
@PrimaryKey
@ColumnInfo(name = "bar")
private String bar;
@ColumnInfo(name = "baz")
private String baz;
public FooEntity(String bar, String baz) {
this.bar= bar;
this.baz= baz;
}
}
I'm able to insert the follwing entities into the database without errors:
new FooEntity(null, "one");
new FooEntity(null, "two");
new FooEntity(null, "three");
Is this behaviour intended? Should PrimaryKey columns be NonNull by default (not sure especially with multi column primary keys and auto increment columns)?
If null is a valid value for a primary key column, I believe there should by a primary key violation if I try to put the same key multiple times into the table.