sqlite_orm icon indicating copy to clipboard operation
sqlite_orm copied to clipboard

statement for alter table with string default value has double single quotes

Open Hartigan opened this issue 9 years ago • 9 comments

I found bug with default value and sync schema. First revision of schema:

make_storage("test_db.sqlite",
    make_table("User",
        make_column("Id",
            &User::userId,
            primary_key()),
        make_column("Name",
            &User::name),
        make_column("Age",
            &User::age)));

Second revision(with std::string field 'email'):

make_storage("test_db.sqlite",
    make_table("User",
        make_column("Id",
            &User::userId,
            primary_key()),
        make_column("Name",
            &User::name),
        make_column("Age",
            &User::age),
        make_column("Email",
            &User::email,
            default_value("[email protected]"))));

Single qoutes was added in default_value_extractor and get_table_info. Generated statement: ALTER TABLE User ADD COLUMN Email TEXT NOT NULL DEFAULT ''[email protected]''

Hartigan avatar Sep 20 '17 09:09 Hartigan

so expected statement is ALTER TABLE User ADD COLUMN Email TEXT NOT NULL DEFAULT '[email protected]' ?

fnc12 avatar Sep 20 '17 10:09 fnc12

yes

Hartigan avatar Sep 20 '17 10:09 Hartigan

thanks for a bug report. Default value is least tested feature from all library features. So it is time to fix it and cover with tests. I'm gonna fix this in a few days.

fnc12 avatar Sep 20 '17 10:09 fnc12

Thanks

Hartigan avatar Sep 20 '17 10:09 Hartigan

To take care of use case involving table and column names as numbers(e.g. 1) .

It should be ALTER TABLE "User" ADD COLUMN "Email" TEXT NOT NULL DEFAULT '[email protected]' ? https://www.sqlite.org/lang_keywords.html https://stackoverflow.com/questions/34884362/escape-table-name-in-sqlite https://stackoverflow.com/questions/4007780/sqlite-issue-with-table-names-using-numbers

ElephantInTheRoomFirst avatar Sep 20 '17 10:09 ElephantInTheRoomFirst

@Hartigan does storage work after modifying schema with email column?

fnc12 avatar Sep 20 '17 10:09 fnc12

https://www.sqlite.org/lang_keywords.html

ElephantInTheRoomFirst avatar Sep 20 '17 10:09 ElephantInTheRoomFirst

@fnc12 storage not worked because statement ALTER TABLE User ADD COLUMN Email TEXT NOT NULL DEFAULT ''[email protected]'' cannot be prepared

Hartigan avatar Sep 20 '17 10:09 Hartigan

@Hartigan ok. I'll fix it and cover with unit tests

fnc12 avatar Sep 20 '17 10:09 fnc12