Merge branch 'release/0.24'

This commit is contained in:
rbock
2014-08-16 18:47:46 +02:00
6 changed files with 152 additions and 35 deletions

View File

@@ -38,6 +38,24 @@
namespace sqlpp
{
namespace detail
{
template<typename... Args>
struct first_arg_impl
{
static_assert(wrong_t<first_arg_impl>::value, "At least one argument required");
};
template<typename T, typename... Args>
struct first_arg_impl<T, Args...>
{
using type = T;
};
template<typename... Args>
using first_arg_t = typename first_arg_impl<Args...>::type;
}
struct insert_default_values_data_t
{};
@@ -210,17 +228,8 @@ namespace sqlpp
using _traits = make_traits<no_value_t, ::sqlpp::tag::is_column_list>;
using _recursive_traits = make_recursive_traits<Columns...>;
static_assert(sizeof...(Columns), "at least one column required in columns()");
static_assert(not ::sqlpp::detail::has_duplicates<Columns...>::value, "at least one duplicate argument detected in columns()");
static_assert(::sqlpp::detail::all_t<is_column_t<Columns>::value...>::value, "at least one argument is not a column in columns()");
static_assert(::sqlpp::detail::none_t<must_not_insert_t<Columns>::value...>::value, "at least one column argument has a must_not_insert flag in its definition");
using _value_tuple_t = typename column_list_data_t<Columns...>::_value_tuple_t;
static_assert(required_tables_of<column_list_t>::size::value == 1, "columns from multiple tables in columns()");
// Data
using _data_t = column_list_data_t<Columns...>;
@@ -333,11 +342,23 @@ namespace sqlpp
return { *static_cast<typename Policies::_statement_t*>(this), insert_default_values_data_t{} };
}
template<typename... Args>
auto columns(Args... args)
-> _new_statement_t<column_list_t<Args...>>
template<typename... Columns>
auto columns(Columns... columns)
-> _new_statement_t<column_list_t<Columns...>>
{
return { *static_cast<typename Policies::_statement_t*>(this), column_list_data_t<Args...>{args...} };
static_assert(sizeof...(Columns), "at least one column required in columns()");
static_assert(not ::sqlpp::detail::has_duplicates<Columns...>::value, "at least one duplicate argument detected in columns()");
static_assert(::sqlpp::detail::all_t<is_column_t<Columns>::value...>::value, "at least one argument is not a column in columns()");
static_assert(::sqlpp::detail::none_t<must_not_insert_t<Columns>::value...>::value, "at least one column argument has a must_not_insert tag in its definition");
using _column_required_tables = ::sqlpp::detail::make_joined_set_t<required_tables_of<Columns>...>;
static_assert(_column_required_tables::size::value == 1, "columns() contains columns from several tables");
using _table = typename detail::first_arg_t<Columns...>::_table;
using required_columns = typename _table::_required_insert_columns;
using set_columns = detail::make_type_set_t<Columns...>;
static_assert(detail::is_subset_of<required_columns, set_columns>::value, "At least one required column is missing in columns()");
return { *static_cast<typename Policies::_statement_t*>(this), column_list_data_t<Columns...>{columns...} };
}
template<typename... Assignments>
@@ -345,6 +366,12 @@ namespace sqlpp
-> _new_statement_t<insert_list_t<void, Assignments...>>
{
static_assert(sizeof...(Assignments), "at least one assignment expression required in set()");
static_assert(sqlpp::detail::all_t<is_assignment_t<Assignments>::value...>::value, "at least one argument is not an assignment in set()");
using _table = typename detail::first_arg_t<Assignments...>::_lhs_t::_table;
using required_columns = typename _table::_required_insert_columns;
using columns = detail::make_type_set_t<typename Assignments::_lhs_t...>;
static_assert(detail::is_subset_of<required_columns, columns>::value, "At least one required column is missing in set()");
return _set_impl<void>(assignments...);
}

View File

@@ -1,17 +1,31 @@
include_directories(${CMAKE_BINARY_DIR}/tests)
add_executable(
no_conversion_operator_if_null_not_trivial
EXCLUDE_FROM_ALL
no_conversion_operator_if_null_not_trivial.cpp
)
add_custom_target(test_sqlpp_constraints COMMAND true)
add_custom_command(OUTPUT no_conversion_operator_if_null_not_trivial.out
COMMAND ${CMAKE_MAKE_PROGRAM} no_conversion_operator_if_null_not_trivial > ${CMAKE_CURRENT_BINARY_DIR}/no_conversion_operator_if_null_not_trivial.out 2>&1 || true
COMMAND grep "int i = row.alpha" ${CMAKE_CURRENT_BINARY_DIR}/no_conversion_operator_if_null_not_trivial.out > /dev/null
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/no_conversion_operator_if_null_not_trivial.cpp
COMMENT "no_conversion_operator_if_null_not_trivial"
)
function(test_constraint name pattern)
add_custom_target(test_constraints DEPENDS no_conversion_operator_if_null_not_trivial.out COMMAND true)
add_executable(
${name}
EXCLUDE_FROM_ALL
${name}.cpp
)
add_custom_command(OUTPUT ${name}.out
COMMAND ${CMAKE_MAKE_PROGRAM} ${name} > ${CMAKE_CURRENT_BINARY_DIR}/${name}.out 2>&1 || true
COMMAND grep ${pattern} ${CMAKE_CURRENT_BINARY_DIR}/${name}.out > /dev/null
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp
COMMENT "${name}"
)
add_custom_target(test_${name} DEPENDS ${name}.out COMMAND true)
add_dependencies(test_sqlpp_constraints test_${name})
endfunction(testconstraint)
test_constraint(no_conversion_operator_if_null_not_trivial "int i = row.alpha")
test_constraint(require_insert "required column is missing")
test_constraint(must_not_insert "one assignment is prohibited")

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2013-2014, 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 "MockDb.h"
#include <sqlpp11/insert.h>
#include <iostream>
MockDb db;
int main()
{
test::TabBar t;
insert_into(t).set(t.alpha = 7, t.gamma = false, t.beta = "alpha must not be set");
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2013-2014, 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 "MockDb.h"
#include <sqlpp11/insert.h>
#include <iostream>
MockDb db;
int main()
{
test::TabBar t;
insert_into(t).set(t.beta = "need also to insert gamma");
}

View File

@@ -54,16 +54,16 @@ int main()
}
db(insert_into(t).default_values());
db(insert_into(t).set(t.beta = "kirschauflauf"));
db(insert_into(t).set(t.gamma = true, t.beta = "kirschauflauf"));
serialize(insert_into(t).default_values(), printer).str();
serialize(insert_into(t), printer).str();
serialize(insert_into(t).set(t.beta = "kirschauflauf"), printer).str();
serialize(insert_into(t).columns(t.beta), printer).str();
auto multi_insert = insert_into(t).columns(t.beta, t.delta);
multi_insert.values.add(t.beta = "cheesecake", t.delta = 1);
multi_insert.values.add(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value);
serialize(insert_into(t).set(t.gamma = true, t.beta = "kirschauflauf"), printer).str();
serialize(insert_into(t).columns(t.gamma, t.beta), printer).str();
auto multi_insert = insert_into(t).columns(t.gamma, t.beta, t.delta);
multi_insert.values.add(t.gamma = true, t.beta = "cheesecake", t.delta = 1);
multi_insert.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::default_value, t.delta = sqlpp::default_value);
auto i = dynamic_insert_into(db, t).dynamic_set();
i.insert_list.add(t.beta = "kirschauflauf");
printer.reset();
@@ -72,9 +72,9 @@ int main()
db(multi_insert);
db(insert_into(t).set(t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")));
db(insert_into(t).set(t.delta = sqlpp::null));
db(insert_into(t).set(t.delta = sqlpp::default_value));
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")));
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::null));
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::default_value));
return 0;
}

View File

@@ -61,7 +61,7 @@ int main()
{
std::cerr << sub.alpha << std::endl;
}
db(insert_into(t).set(t.beta = row.beta));
db(insert_into(t).set(t.beta = row.beta, t.gamma = false));
}
sqlpp::select((t.alpha + 1).as(t.alpha)).flags(sqlpp::all).from(t);