diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index df97be91..54d49b3a 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -38,6 +38,7 @@ #include #include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h new file mode 100644 index 00000000..76661dda --- /dev/null +++ b/include/sqlpp11/verbatim_table.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013, 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. + */ + +#ifndef SQLPP_VERBATIM_TABLE_H +#define SQLPP_VERBATIM_TABLE_H + +#include + +namespace sqlpp +{ + namespace detail + { + struct unusable_pseudo_column_t + { + struct _name_t + { + template + struct _member_t + { + }; + }; + using _value_type = no_value_t; + struct _column_type {}; + }; + } + + struct verbatim_table_t: public sqlpp::table_base_t + { + using _value_type = no_value_t; + + verbatim_table_t(std::string name): + _name(name) + { + } + + verbatim_table_t(const verbatim_table_t& rhs) = default; + verbatim_table_t(verbatim_table_t&& rhs) = default; + verbatim_table_t& operator=(const verbatim_table_t& rhs) = default; + verbatim_table_t& operator=(verbatim_table_t&& rhs) = default; + ~verbatim_table_t() = default; + + template + void serialize(std::ostream& os, Db& db) const + { + os << _name; + } + + std::string _name; + }; + + verbatim_table_t verbatim_table(std::string name) + { + return { name }; + } + +} + +#endif diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index 1ec044f4..0cf35d4f 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -364,5 +364,23 @@ int main() static_assert(sqlpp::is_text_t::value, "type requirement"); } + // test verbatim_table + { + using T = decltype(sqlpp::verbatim_table("cheesecake")); + static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_expression_t::value, "type requirement"); + static_assert(sqlpp::is_table_t::value, "type requirement"); + } + + // test verbatim_table alias + { + SQLPP_ALIAS_PROVIDER_GENERATOR(kaesekuchen); + using T = decltype(sqlpp::verbatim_table("cheesecake").as(kaesekuchen)); + static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_expression_t::value, "type requirement"); + static_assert(sqlpp::is_table_t::value, "type requirement"); + static_assert(sqlpp::is_alias_t::value, "type requirement"); + } + return 0; } diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 52d2fd5a..3e579680 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -318,7 +318,13 @@ int main() // Test that select can be called with zero columns if it is used with dynamic columns. { auto s = dynamic_select(db).dynamic_columns().add_column(t.alpha); - s.serialize(std::cerr, db); + s.serialize(std::cerr, db); std::cerr << "\n"; + } + + // Test that verbatim_table compiles + { + auto s = select(t.alpha).from(sqlpp::verbatim_table("my_unknown_table")); + s.serialize(std::cerr, db); std::cerr << "\n"; } diff --git a/tests/is_regular.h b/tests/is_regular.h index 2790de5b..6e99e0e1 100644 --- a/tests/is_regular.h +++ b/tests/is_regular.h @@ -34,8 +34,18 @@ namespace sqlpp template struct is_regular { +#if defined __clang__ + #if __has_feature(cxx_thread_local) + #define SQLPP_TEST_NO_THROW_MOVE_CONSTRUCTIBLE // clang 3.2 has a problem with nothrow_constructibility (it also does not have thread_local support) + #endif +#else + #define SQLPP_TEST_NO_THROW_MOVE_CONSTRUCTIBLE +#endif + static constexpr bool value = true +#if defined SQLPP_TEST_NO_THROW_MOVE_CONSTRUCTIBLE and std::is_nothrow_move_constructible::value +#endif and std::is_move_assignable::value // containers and strings are not noexcept_assignable and std::is_copy_constructible::value and std::is_copy_assignable::value