sqlite_orm
sqlite_orm copied to clipboard
`in` constraint can't be used in `check` context
The following test case:
struct Rect {
int id = 0;
int x = 0;
int y = 0;
int width = 0;
int height = 0;
std::string join_type = "miter";
};
auto storage = make_storage({},
make_table("RECT",
make_column("id", &Rect::id, primary_key()),
make_column("x", &Rect::x),
make_column("y", &Rect::y),
make_column("width", &Rect::width),
make_column("height", &Rect::height),
make_column("join_type", &Rect::join_type),
check(in(&Rect::join_type, {"miter", "round", "bevel"}))));
storage.sync_schema();
gives an SQL syntax error:
near ""join_type"": syntax error: SQL logic error
It is because the generated SQL statement for the table creation:
CREATE TABLE 'RECT' (
'id' INTEGER PRIMARY KEY NOT NULL ,
'x' INTEGER NOT NULL ,
'y' INTEGER NOT NULL ,
'width' INTEGER NOT NULL ,
'height' INTEGER NOT NULL ,
'join_type' TEXT NOT NULL ,
CHECK "join_type" IN ('miter', 'round', 'bevel')
)
is missing parentheses around the CHECK expression.
Hi. Thanks for the report. I'll fix it today
@fnc12 , thanks for an ultra fast response! I actually already have a fix locally, am about to create a PR!!
@mejdys that's cool! Please don't forget to add unit tests for serialization. Thanks!
@mejdys what branch do you use? I can't repro it in dev. Looks like this bug is fixed already
Hm, indeed, it works on dev. I only tested it on master before raising the issue. Great to see it gone, thanks, will wait for the next release then :)
Next release will be very soon. Thanks for reporting
Tried on 1.8.1, works fine indeed! thanks!