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

insert_into() with add() does not support verbatim #489

Open
CJCombrink opened this issue Jun 13, 2023 · 3 comments
Open

insert_into() with add() does not support verbatim #489

CJCombrink opened this issue Jun 13, 2023 · 3 comments

Comments

@CJCombrink
Copy link
Contributor

It seems like the following is valid:

const gen::PublicMyTable t;
db(insert_into(t).set(
   t.name        = "name",
   t.description = "description",
   t.vals        = sqlpp::verbatim<sqlpp::text>("ARRAY[2,3]")));

But not when using add:

auto multi_insert = insert_into(t).columns(t.name, t.description, t.vals);
multi_insert.values.add(
  t.name        = "name",
  t.description = "description",
  t.vals        = sqlpp::verbatim<sqlpp::text>("ARRAY[2,3]"));
db(multi_insert);

I get the following compiler error (gcc 10)

sqlpp11/0.61/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/sqlpp11/insert_value_list.h:408:42: error: no matching function for call to ‘sqlpp::insert_value_t<sqlpp::column_t<gen::PublicMyTable, gen::PublicMyTable_::Vals> >::insert_value_t(<brace-enclosed initializer list>)’
[build]   408 |         _data._insert_values.emplace_back(insert_value_t<lhs_t<Assignments>>{assignments._rhs}...);

My table is defined as

CREATE TABLE MyTable
(
    name                TEXT,
    description         TEXT,
    vals                INTEGER[]
);

I have added the mapping of INTEGER[] to text in ddl2cpp.

PS: There is another bug here where MyTable does not generate due to the array INTEGER[] (see #488)

@rbock
Copy link
Owner

rbock commented Jun 14, 2023

I don't have a good solution for this, I am afraid. Multi line inserts values in a vector of tuples. For text fields they expect strings, but verbatim_t is not a string and not convertible to string (it would be serialized incorrectly if it were stored as string).

The quick workaround would be to use individual inserts.

A more long term solution could be

  • to introduce a way to change the tuple element for multi line insert, or
  • to introduce array types

Both would be non-trivial and take a while, I think.

@ghais
Copy link

ghais commented Jul 4, 2023

The same problem happens when doing insert_into with a select field.

auto q = insert_into(table).columns(table.x);
q.values.add(table.x = select(foo.id).from(foo).where(foo.id = 3);

Note that it works when doing a single insert.

@rbock
Copy link
Owner

rbock commented Jul 9, 2023

Yeah, that won´t work, because a sub select is not of type int64_t (or whatever the type of xis).

As mentioned above, the values are stored in a vector. But maybe that can be changed. I'll think about it.

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

3 participants