mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Add tests for insert_columns
This commit is contained in:
parent
2198f95dab
commit
02b880b204
@ -183,7 +183,7 @@ namespace sqlpp
|
|||||||
struct column_list_data_t
|
struct column_list_data_t
|
||||||
{
|
{
|
||||||
// workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
|
// workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
|
||||||
column_list_data_t(Columns... cols) : _columns(simple_column_t<Columns>(cols)...)
|
column_list_data_t(Columns... cols) : _columns(simple_column_t<Columns>(std::move(cols))...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ namespace sqlpp
|
|||||||
~column_list_data_t() = default;
|
~column_list_data_t() = default;
|
||||||
|
|
||||||
using _value_tuple_t = std::tuple<insert_value_t<Columns>...>;
|
using _value_tuple_t = std::tuple<insert_value_t<Columns>...>;
|
||||||
std::tuple<Columns...> _columns;
|
std::tuple<simple_column_t<Columns>...> _columns;
|
||||||
std::vector<_value_tuple_t> _insert_values;
|
std::vector<_value_tuple_t> _insert_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -380,7 +380,7 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result += ',';
|
result += ", ";
|
||||||
}
|
}
|
||||||
result += '(';
|
result += '(';
|
||||||
result += tuple_to_sql_string(context, row, tuple_operand{", "});
|
result += tuple_to_sql_string(context, row, tuple_operand{", "});
|
||||||
|
@ -30,6 +30,7 @@ function(create_test name)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
create_test(group_by)
|
create_test(group_by)
|
||||||
|
create_test(insert_columns)
|
||||||
create_test(insert_default_values)
|
create_test(insert_default_values)
|
||||||
create_test(insert_set)
|
create_test(insert_set)
|
||||||
create_test(select_columns)
|
create_test(select_columns)
|
||||||
|
76
tests/core/serialize/clause/insert_columns.cpp
Normal file
76
tests/core/serialize/clause/insert_columns.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Roland Bock
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Sample.h"
|
||||||
|
#include "../compare.h"
|
||||||
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
|
SQLPP_CREATE_NAME_TAG(v);
|
||||||
|
|
||||||
|
int main(int, char* [])
|
||||||
|
{
|
||||||
|
const auto val = sqlpp::value(17);
|
||||||
|
const auto expr = sqlpp::value(17) + 4;
|
||||||
|
|
||||||
|
const auto foo = test::TabFoo{};
|
||||||
|
|
||||||
|
// Without values.
|
||||||
|
SQLPP_COMPARE(insert_columns(foo.id), " (id)");
|
||||||
|
SQLPP_COMPARE(insert_columns(foo.id, foo.textNnD), " (id, text_nn_d)");
|
||||||
|
|
||||||
|
// Single column.
|
||||||
|
{
|
||||||
|
auto i = insert_columns(foo.textNnD);
|
||||||
|
i.add_values(foo.textNnD = "cheese");
|
||||||
|
SQLPP_COMPARE(i, " (text_nn_d) VALUES ('cheese')");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto i = insert_columns(foo.id);
|
||||||
|
i.add_values(foo.id = 17);
|
||||||
|
i.add_values(foo.id = sqlpp::default_value);
|
||||||
|
SQLPP_COMPARE(i, " (id) VALUES (17), (DEFAULT)");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto i = insert_columns(foo.boolN);
|
||||||
|
i.add_values(foo.boolN = true);
|
||||||
|
i.add_values(foo.boolN = sqlpp::default_value);
|
||||||
|
i.add_values(foo.boolN = sqlpp::nullopt);
|
||||||
|
SQLPP_COMPARE(i, " (bool_n) VALUES (1), (DEFAULT), (NULL)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple columns.
|
||||||
|
{
|
||||||
|
auto i = insert_columns(foo.id, foo.boolN, foo.textNnD);
|
||||||
|
i.add_values(foo.id = sqlpp::default_value, foo.boolN = sqlpp::default_value, foo.textNnD = "cheese");
|
||||||
|
SQLPP_COMPARE(i, " (id, bool_n, text_nn_d) VALUES (DEFAULT, DEFAULT, 'cheese')");
|
||||||
|
|
||||||
|
i.add_values(foo.id = 17, foo.boolN = sqlpp::nullopt, foo.textNnD = "cake");
|
||||||
|
SQLPP_COMPARE(i, " (id, bool_n, text_nn_d) VALUES (DEFAULT, DEFAULT, 'cheese'), (17, NULL, 'cake')");
|
||||||
|
}
|
||||||
|
|
||||||
|
#warning: accept other value expressions, too? Or maye "just" verbatim as value, too?
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user