sqlite_orm icon indicating copy to clipboard operation
sqlite_orm copied to clipboard

`in` constraint can't be used in `check` context

Open mejdys opened this issue 3 years ago • 6 comments

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.

mejdys avatar Aug 19 '22 08:08 mejdys

Hi. Thanks for the report. I'll fix it today

fnc12 avatar Aug 19 '22 08:08 fnc12

@fnc12 , thanks for an ultra fast response! I actually already have a fix locally, am about to create a PR!!

mejdys avatar Aug 19 '22 08:08 mejdys

@mejdys that's cool! Please don't forget to add unit tests for serialization. Thanks!

fnc12 avatar Aug 19 '22 08:08 fnc12

@mejdys what branch do you use? I can't repro it in dev. Looks like this bug is fixed already

fnc12 avatar Aug 20 '22 04:08 fnc12

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 :)

mejdys avatar Aug 20 '22 15:08 mejdys

Next release will be very soon. Thanks for reporting

fnc12 avatar Aug 20 '22 15:08 fnc12

Tried on 1.8.1, works fine indeed! thanks!

mejdys avatar Feb 20 '23 18:02 mejdys