Sqlite_orm: default value for string

Created on 23 Dec 2020  路  10Comments  路  Source: fnc12/sqlite_orm

It appears sqlite only accept single quote for default string values, which requires the code below to use single quote when serializing:

        template<>
        struct statement_serializator<std::string, void> {
            using statement_type = std::string;

            template<class C>
            std::string operator()(const statement_type &c, const C &context) const {
                if(context.replace_bindable_with_question) {
                    return "?";
                } else {
                    return "'" + c + "'";
                }
            }
        };
bug verify

All 10 comments

how can I reproduce the bug?

Try this code (with sqlite_orm 1.6):

```c++
struct Contact {
int id = 0;
std::string firstName;
std::string lastName;
std::string phone;
};

using namespace sqlite_orm;
auto storage = make_storage("/tmp/test.sqlite",
make_table("contacts",
make_column("contact_id", &Contact::id, primary_key()),
make_column("first_name", &Contact::firstName, default_value ("")),
make_column("last_name", &Contact::lastName, default_value ("")),
make_column("phone", &Contact::phone)));
storage.sync_schema();
````
The error would be:

default value of column [first_name] is not constant in "CREATE TABLE 'contacts' ( 'contact_id' INTEGER PRIMARY KEY NOT NULL , 'first_name' TEXT DEFAULT ("") NOT NULL , 'last_name' TEXT DEFAULT ("") NOT NULL

@taurusai does it reproduce in dev branch?

@taurusai does it reproduce in dev branch?

yes

@taurusai ok thanks. I shall fix it today

the fix is on its way #642

Great, thanks!

@taurusai merged in dev branch. Please check it out

@taurusai does everything work?

@taurusai does everything work?

Yes, dev is working now, thanks!

Looking forward to 1.7 release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jakemumu picture jakemumu  路  9Comments

nfarid picture nfarid  路  8Comments

algobot76 picture algobot76  路  7Comments

nuttapongCodium picture nuttapongCodium  路  3Comments

fnc12 picture fnc12  路  12Comments