Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default value for string #638

Closed
kungfu-origin opened this issue Dec 23, 2020 · 10 comments
Closed

default value for string #638

kungfu-origin opened this issue Dec 23, 2020 · 10 comments

Comments

@kungfu-origin
Copy link

kungfu-origin commented Dec 23, 2020

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 + "'";
                }
            }
        };
@fnc12
Copy link
Owner

fnc12 commented Dec 23, 2020

how can I reproduce the bug?

@kungfu-origin
Copy link
Author

kungfu-origin commented Dec 24, 2020

Try this code (with sqlite_orm 1.6):

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 <std::string> ("")),
                                       make_column("last_name", &Contact::lastName, default_value <std::string> ("")),
                                       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

@fnc12
Copy link
Owner

fnc12 commented Dec 25, 2020

@TaurusAI does it reproduce in dev branch?

@kungfu-origin
Copy link
Author

@TaurusAI does it reproduce in dev branch?

yes

@fnc12
Copy link
Owner

fnc12 commented Dec 29, 2020

@TaurusAI ok thanks. I shall fix it today

@fnc12
Copy link
Owner

fnc12 commented Dec 30, 2020

the fix is on its way #642

@kungfu-origin
Copy link
Author

the fix is on its way #642

Great, thanks!

@fnc12
Copy link
Owner

fnc12 commented Dec 30, 2020

@TaurusAI merged in dev branch. Please check it out

@fnc12 fnc12 added verify and removed in progress labels Dec 30, 2020
@fnc12
Copy link
Owner

fnc12 commented Jan 4, 2021

@TaurusAI does everything work?

@kungfu-origin
Copy link
Author

@TaurusAI does everything work?

Yes, dev is working now, thanks!

Looking forward to 1.7 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants