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

sqlpp::value_or_null with prepared statements #435

Closed
dirkvdb opened this issue Apr 1, 2022 · 4 comments
Closed

sqlpp::value_or_null with prepared statements #435

dirkvdb opened this issue Apr 1, 2022 · 4 comments

Comments

@dirkvdb
Copy link
Contributor

dirkvdb commented Apr 1, 2022

Using the latest release I can't use sqlpp::value_or_null in combination with prepared statements.
I was using tvin before, but I get compilation errors now that I had to migrate to value_or_null

error C2679: binary '=': no operator found which takes a right-hand operand of type 'sqlpp::value_or_null_t<sqlpp::integer>' (or there is no acceptable conversion)
@rbock
Copy link
Owner

rbock commented Apr 1, 2022

I suspect that you might have been the only user of tvin...

Adding an assignment operator would be rather simple.
Can you show me a snippet of what you want to do?

@dirkvdb
Copy link
Contributor Author

dirkvdb commented Apr 1, 2022

I wrote a small function to replace the removed tvin

inline auto tvin(int64_t val)
{
    if (val == 0) {
        return sqlpp::value_or_null<sqlpp::integer>(sqlpp::null);
    } else {
        return sqlpp::value_or_null(val);
    }
}

I use it like this:

void InputDataBase::store_wlas_data(const std::vector<WlasInfo>& data)
{
    auto insertQuery = []() {
        return insert_into(WlasTable).set(
            WlasTable.vhsid   = parameter(WlasTable.vhsid),
            WlasTable.naam    = parameter(WlasTable.naam),
            WlasTable.beknaam = parameter(WlasTable.beknaam));
    };

    auto query = _db.prepare(insertQuery());

    for (auto& curData : data) {
        query.params.vhsid   = tvin(curData.vhasId);
        query.params.naam    = curData.name;
        query.params.beknaam = curData.catchment;
        _db(query);
    }
}

This works fine for regular queries, but not for prepared statements

@rbock
Copy link
Owner

rbock commented Apr 2, 2022

Thanks for the details. I added the missing assignment operator for parameters and some very basic tests.

Please give it a try.

@dirkvdb
Copy link
Contributor Author

dirkvdb commented Apr 2, 2022

It works, thanks a lot!

@dirkvdb dirkvdb closed this as completed Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants