2013-08-14 04:43:10 +08:00
|
|
|
/*
|
|
|
|
* 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_COLUMN_H
|
|
|
|
#define SQLPP_COLUMN_H
|
|
|
|
|
|
|
|
#include <sqlpp11/alias.h>
|
2014-01-18 22:50:16 +08:00
|
|
|
#include <sqlpp11/column_fwd.h>
|
2014-01-26 05:38:16 +08:00
|
|
|
#include <sqlpp11/default_value.h>
|
|
|
|
#include <sqlpp11/null.h>
|
2013-08-14 04:43:10 +08:00
|
|
|
#include <sqlpp11/sort_order.h>
|
2014-01-18 22:50:16 +08:00
|
|
|
#include <sqlpp11/type_traits.h>
|
2014-01-26 05:38:16 +08:00
|
|
|
#include <sqlpp11/vendor/assignment.h>
|
2014-01-18 22:50:16 +08:00
|
|
|
#include <sqlpp11/vendor/expression.h>
|
2014-01-26 05:38:16 +08:00
|
|
|
#include <sqlpp11/vendor/interpreter.h>
|
2014-01-29 21:28:07 +08:00
|
|
|
#include <sqlpp11/vendor/wrong.h>
|
2014-02-09 22:06:42 +08:00
|
|
|
#include <sqlpp11/detail/type_set.h>
|
2013-08-14 04:43:10 +08:00
|
|
|
|
|
|
|
namespace sqlpp
|
|
|
|
{
|
|
|
|
template<typename Table, typename ColumnSpec>
|
|
|
|
struct column_t: public ColumnSpec::_value_type::template operators<column_t<Table, ColumnSpec>>
|
|
|
|
{
|
2014-01-26 20:24:42 +08:00
|
|
|
using _is_column = std::true_type;
|
2014-02-04 14:32:37 +08:00
|
|
|
using _spec_t = ColumnSpec;
|
2013-08-14 04:43:10 +08:00
|
|
|
using _table = Table;
|
2014-02-09 22:06:42 +08:00
|
|
|
using _table_set = detail::type_set<_table>;
|
2013-08-14 04:43:10 +08:00
|
|
|
using _column_type = typename ColumnSpec::_column_type;
|
|
|
|
struct _value_type: ColumnSpec::_value_type
|
|
|
|
{
|
2013-09-29 15:02:51 +08:00
|
|
|
using _is_expression = std::true_type;
|
|
|
|
using _is_named_expression = std::true_type;
|
|
|
|
using _is_alias = std::false_type;
|
2013-08-14 04:43:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using _name_t = typename ColumnSpec::_name_t;
|
|
|
|
|
2013-09-23 02:42:19 +08:00
|
|
|
column_t() = default;
|
|
|
|
column_t(const column_t&) = default;
|
|
|
|
column_t(column_t&&) = default;
|
|
|
|
column_t& operator=(const column_t&) = default;
|
|
|
|
column_t& operator=(column_t&&) = default;
|
|
|
|
~column_t() = default;
|
|
|
|
|
2014-01-14 06:05:48 +08:00
|
|
|
static constexpr const char* _get_name()
|
|
|
|
{
|
|
|
|
return _name_t::_get_name();
|
|
|
|
}
|
2013-09-10 04:45:34 +08:00
|
|
|
|
2013-08-14 04:43:10 +08:00
|
|
|
template<typename alias_provider>
|
2014-01-30 15:43:55 +08:00
|
|
|
expression_alias_t<column_t, alias_provider> as(const alias_provider&) const
|
2013-08-14 04:43:10 +08:00
|
|
|
{
|
|
|
|
return { *this };
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-01-26 05:38:16 +08:00
|
|
|
auto operator =(T t) const
|
|
|
|
-> typename std::enable_if<_value_type::template _constraint<typename vendor::wrap_operand<T>::type>::value and not std::is_same<column_t, T>::value,
|
|
|
|
vendor::assignment_t<column_t, typename vendor::wrap_operand<T>::type>>::type
|
|
|
|
{
|
|
|
|
return { *this, {t} };
|
|
|
|
}
|
|
|
|
|
2014-02-13 15:44:09 +08:00
|
|
|
template<typename T>
|
|
|
|
auto operator =(T t) const
|
|
|
|
-> typename std::enable_if<not(_value_type::template _constraint<typename vendor::wrap_operand<T>::type>::value and not std::is_same<column_t, T>::value),
|
|
|
|
vendor::assignment_t<column_t, typename vendor::wrap_operand<T>::type>>::type
|
|
|
|
{
|
|
|
|
static_assert(sqlpp::vendor::wrong_t<T>::value, "invalid assignment operand");
|
|
|
|
}
|
|
|
|
|
2014-01-26 05:38:16 +08:00
|
|
|
auto operator =(sqlpp::null_t) const
|
|
|
|
->vendor::assignment_t<column_t, sqlpp::null_t>
|
|
|
|
{
|
|
|
|
static_assert(can_be_null_t<column_t>::value, "column cannot be null");
|
|
|
|
return { *this, {} };
|
|
|
|
}
|
|
|
|
|
|
|
|
auto operator =(sqlpp::default_value_t) const
|
|
|
|
->vendor::assignment_t<column_t, sqlpp::default_value_t>
|
2013-08-14 04:43:10 +08:00
|
|
|
{
|
2014-01-26 05:38:16 +08:00
|
|
|
return { *this, {} };
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-18 23:10:46 +08:00
|
|
|
namespace vendor
|
|
|
|
{
|
|
|
|
template<typename Context, typename... Args>
|
|
|
|
struct interpreter_t<Context, column_t<Args...>>
|
2014-01-12 17:13:15 +08:00
|
|
|
{
|
2014-01-18 23:10:46 +08:00
|
|
|
using T = column_t<Args...>;
|
|
|
|
|
|
|
|
static Context& _(const T& t, Context& context)
|
|
|
|
{
|
|
|
|
context << T::_table::_name_t::_get_name() << '.' << T::_name_t::_get_name();
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
};
|
2014-01-11 07:11:47 +08:00
|
|
|
|
2014-01-18 23:10:46 +08:00
|
|
|
}
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|