0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Added verbatim table

This commit is contained in:
Roland Bock 2013-11-16 23:19:37 +01:00
parent 5304e77f4a
commit 8d12d23d67
5 changed files with 117 additions and 1 deletions

View File

@ -38,6 +38,7 @@
#include <sqlpp11/max.h> #include <sqlpp11/max.h>
#include <sqlpp11/avg.h> #include <sqlpp11/avg.h>
#include <sqlpp11/sum.h> #include <sqlpp11/sum.h>
#include <sqlpp11/verbatim_table.h>
namespace sqlpp namespace sqlpp
{ {

View File

@ -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 <sqlpp11/no_value.h>
namespace sqlpp
{
namespace detail
{
struct unusable_pseudo_column_t
{
struct _name_t
{
template<typename T>
struct _member_t
{
};
};
using _value_type = no_value_t;
struct _column_type {};
};
}
struct verbatim_table_t: public sqlpp::table_base_t<verbatim_table_t, detail::unusable_pseudo_column_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<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << _name;
}
std::string _name;
};
verbatim_table_t verbatim_table(std::string name)
{
return { name };
}
}
#endif

View File

@ -364,5 +364,23 @@ int main()
static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement");
} }
// test verbatim_table
{
using T = decltype(sqlpp::verbatim_table("cheesecake"));
static_assert(not sqlpp::is_named_expression_t<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_table_t<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<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
}
return 0; return 0;
} }

View File

@ -318,7 +318,13 @@ int main()
// Test that select can be called with zero columns if it is used with dynamic columns. // 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); 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";
} }

View File

@ -34,8 +34,18 @@ namespace sqlpp
template<typename T> template<typename T>
struct is_regular 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 static constexpr bool value = true
#if defined SQLPP_TEST_NO_THROW_MOVE_CONSTRUCTIBLE
and std::is_nothrow_move_constructible<T>::value and std::is_nothrow_move_constructible<T>::value
#endif
and std::is_move_assignable<T>::value // containers and strings are not noexcept_assignable and std::is_move_assignable<T>::value // containers and strings are not noexcept_assignable
and std::is_copy_constructible<T>::value and std::is_copy_constructible<T>::value
and std::is_copy_assignable<T>::value and std::is_copy_assignable<T>::value