rbock / sqlpp11

A type safe SQL template library for C++
BSD 2-Clause "Simplified" License
2.47k stars 341 forks source link

compilation fails for insert_into with sqlpp::verbatim_table #79

Closed isliser closed 8 years ago

isliser commented 8 years ago

Hello! I'm unable to compile such snippet

SQLPP_DECLARE_TABLE(
    (clients)
    ,
    (login,     int,            SQLPP_PRIMARY_KEY)
    (name,      text,           SQLPP_NOT_NULL)
    (address,   text,           SQLPP_NOT_NULL)
)
connection db...;
auto i = insert_into(sqlpp::verbatim_table("my_unknown_table")).columns(clients.login, clients.name, clients.address);
i.values.add(clients.login = 1, clients.name = "Roland", clients.address = "Neuburg");
i.values.add(clients.login = 2, clients.name = "Zaphod", clients.address = "Munich");
db(i);

Msvs 2015 update2 output:

insert.cpp 1>sqlpp11\insert_value_list.h(349): error C2338: at least one column requires a table which is otherwise not known in the statement 1> sqlpp11\postgresql\connection.h(286): note: see reference to function template instantiation 'void sqlpp::assert_no_unknown_tables_in_column_listt::(void)' being compiled 1> insert.cpp(47): note: see reference to function template instantiation 'void sqlpp::postgresql::connection::operator ()sqlpp::statement_t<Db,sqlpp::insert_t,sqlpp::into_t<void,Table,sqlpp::column_list_t<T,sqlpp::columnt<clients::clients,clients::clients::name>,sqlpp::columntclients::clients,clients::clients::address>>>(const sqlpp::statement_t<Db,sqlpp::insert_t,sqlpp::into_t<void,Table>,sqlpp::column_list_t<T,sqlpp::columnt<clients::clients,clients::clients::name>,sqlpp::columntclients::clients,clients::clients::address>> &)' being compiled 1> with 1> [ 1> Db=void, 1> Table=sqlpp::verbatim_table_t, 1> T=sqlpp::columntclients::clients,clients::clients::login 1> ]

Is it a bug or misuse of verbatim_table?

rbock commented 8 years ago

That is a misuse of verbatim_table. I would expect verbatim_table to be potentially useful in custom_query expressions. But I would have a hard time to come up with a reasonable example.