fnc12 / sqlite_orm

❤️ SQLite ORM light header only library for modern C++
GNU Affero General Public License v3.0
2.28k stars 316 forks source link

Custom bindings currently broken in dev #314

Closed swex closed 5 years ago

swex commented 5 years ago

Hi there, I just discovered that custom types broken in dev. It looks like problem in

template<class T>
typename std::enable_if<!is_base_of_template<T, compound_operator>::value, std::string>::type string_from_expression(const T &t, bool /*noTableName*/, bool escape, bool ignoreBindable = false) {

it gives strange condition for strings like:

SELECT 'superheros'.\"id\", 'superheros'.\"name\", 'superheros'.\"gender\" FROM 'superheros' WHERE ( 'superheros'.\"gender\" = '? ') 

not those quotes around ? and space after ?

template <>
struct statement_binder<Gender> {

    int bind(sqlite3_stmt* stmt, int index, const Gender& value)
    {
        return statement_binder<std::string>().bind(stmt, index, GenderToString(value));
        //  or return sqlite3_bind_text(stmt, index++, GenderToString(value).c_str(), -1, SQLITE_TRANSIENT);
    }
};

Also above bind is called, but sqlite3_bind error silently ignored by sqlite_orm.

fnc12 commented 5 years ago

Fix is almost ready https://github.com/fnc12/sqlite_orm/pull/316

fnc12 commented 5 years ago

Merged fix in dev branch. Please check it

swex commented 5 years ago

Yep it fixed now, thanks