mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Merge tag '0.7' into develop
Fixed compiler errors and warnings for clang. Smaller memory footprint for non-dynamic cases.
This commit is contained in:
commit
0ad689c116
@ -27,29 +27,13 @@
|
|||||||
#ifndef SQLPP_ASSIGNMENT_LIST_H
|
#ifndef SQLPP_ASSIGNMENT_LIST_H
|
||||||
#define SQLPP_ASSIGNMENT_LIST_H
|
#define SQLPP_ASSIGNMENT_LIST_H
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/detail/set.h>
|
#include <sqlpp11/detail/set.h>
|
||||||
#include <sqlpp11/detail/serialize_tuple.h>
|
#include <sqlpp11/detail/serialize_tuple.h>
|
||||||
#include <sqlpp11/detail/serializable.h>
|
#include <sqlpp11/detail/serializable_list.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename Db>
|
|
||||||
struct dynamic_assignment_list
|
|
||||||
{
|
|
||||||
using type = std::vector<detail::serializable_t<Db>>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct dynamic_assignment_list<void>
|
|
||||||
{
|
|
||||||
using type = std::vector<noop>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Database, template<typename> class ProhibitPredicate, typename... Assignments>
|
template<typename Database, template<typename> class ProhibitPredicate, typename... Assignments>
|
||||||
struct assignment_list_t
|
struct assignment_list_t
|
||||||
{
|
{
|
||||||
@ -75,7 +59,7 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
static_assert(is_assignment_t<typename std::decay<Assignment>::type>::value, "set() arguments require to be assigments");
|
static_assert(is_assignment_t<typename std::decay<Assignment>::type>::value, "set() arguments require to be assigments");
|
||||||
static_assert(not ProhibitPredicate<typename std::decay<Assignment>::type::column_type>::value, "set() argument must not be updated");
|
static_assert(not ProhibitPredicate<typename std::decay<Assignment>::type::column_type>::value, "set() argument must not be updated");
|
||||||
_dynamic_assignments.push_back(std::forward<Assignment>(assignment));
|
_dynamic_assignments.emplace_back(std::forward<Assignment>(assignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Db>
|
template<typename Db>
|
||||||
@ -83,18 +67,11 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
os << " SET ";
|
os << " SET ";
|
||||||
detail::serialize_tuple(os, db, _assignments, ',');
|
detail::serialize_tuple(os, db, _assignments, ',');
|
||||||
bool first = sizeof...(Assignments) == 0;
|
_dynamic_assignments.serialize(os, db, sizeof...(Assignments) == 0);
|
||||||
for (const auto& assignment : _dynamic_assignments)
|
|
||||||
{
|
|
||||||
if (not first)
|
|
||||||
os << ',';
|
|
||||||
assignment.serialize(os, db);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<Assignments...> _assignments;
|
std::tuple<typename std::decay<Assignments>::type...> _assignments;
|
||||||
typename detail::dynamic_assignment_list<Database>::type _dynamic_assignments;
|
typename detail::serializable_list<Database> _dynamic_assignments;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,9 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
struct named_serializable_t
|
struct named_serializable_t
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T,
|
||||||
|
typename std::enable_if<not std::is_same<typename std::decay<T>::type, named_serializable_t<Db>>::value, int>::type = 0 // prevent accidental overload for copy constructor
|
||||||
|
>
|
||||||
named_serializable_t(T&& t):
|
named_serializable_t(T&& t):
|
||||||
_impl(std::make_shared<_impl_t<typename std::decay<T>::type>>(std::forward<T>(t)))
|
_impl(std::make_shared<_impl_t<typename std::decay<T>::type>>(std::forward<T>(t)))
|
||||||
{}
|
{}
|
||||||
@ -84,7 +86,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
std::string _get_name() const
|
std::string _get_name() const
|
||||||
{
|
{
|
||||||
T::_name_t::_get_name();
|
return T::_name_t::_get_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
T _t;
|
T _t;
|
||||||
|
@ -38,7 +38,9 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
struct serializable_t
|
struct serializable_t
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T,
|
||||||
|
typename std::enable_if<not std::is_same<typename std::decay<T>::type, serializable_t<Db>>::value, int>::type = 0 // prevent accidental overload for copy constructor
|
||||||
|
>
|
||||||
serializable_t(T&& t):
|
serializable_t(T&& t):
|
||||||
_impl(std::make_shared<_impl_t<typename std::decay<T>::type>>(std::forward<T>(t)))
|
_impl(std::make_shared<_impl_t<typename std::decay<T>::type>>(std::forward<T>(t)))
|
||||||
{}
|
{}
|
||||||
|
108
include/sqlpp11/detail/serializable_list.h
Normal file
108
include/sqlpp11/detail/serializable_list.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* 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_SERIALIZABLE_LIST_H
|
||||||
|
#define SQLPP_SERIALIZABLE_LIST_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <sqlpp11/detail/serializable.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename Db>
|
||||||
|
struct serializable_list
|
||||||
|
{
|
||||||
|
std::vector<detail::serializable_t<Db>> _serializables;
|
||||||
|
|
||||||
|
std::size_t size() const
|
||||||
|
{
|
||||||
|
return _serializables.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const
|
||||||
|
{
|
||||||
|
return _serializables.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Expr>
|
||||||
|
void emplace_back(Expr&& expr)
|
||||||
|
{
|
||||||
|
_serializables.emplace_back(std::forward<Expr>(expr));
|
||||||
|
}
|
||||||
|
|
||||||
|
void serialize(std::ostream& os, Db& db, bool first) const
|
||||||
|
{
|
||||||
|
for (const auto entry : _serializables)
|
||||||
|
{
|
||||||
|
if (not first)
|
||||||
|
os << ',';
|
||||||
|
entry.serialize(os, db);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void serialize(std::ostream& os, Db& db, const std::string& separator, bool first) const
|
||||||
|
{
|
||||||
|
for (const auto entry : _serializables)
|
||||||
|
{
|
||||||
|
if (not first)
|
||||||
|
os << separator;
|
||||||
|
entry.serialize(os, db);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct serializable_list<void>
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
void emplace_back(const T&) {}
|
||||||
|
|
||||||
|
constexpr std::size_t size() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool empty() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Db>
|
||||||
|
void serialize(std::ostream&, Db&, bool) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -76,8 +76,8 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
static_assert(NotInverted and Db::_supports_in
|
static_assert((NotInverted and Db::_supports_in)
|
||||||
or _inverted and Db::_supports_not_in, "in() and/or not_in() not supported by current database");
|
or (_inverted and Db::_supports_not_in), "in() and/or not_in() not supported by current database");
|
||||||
_operand.serialize(os, db);
|
_operand.serialize(os, db);
|
||||||
os << (_inverted ? " NOT IN(" : " IN(");
|
os << (_inverted ? " NOT IN(" : " IN(");
|
||||||
detail::serialize_tuple(os, db, _args, ',');
|
detail::serialize_tuple(os, db, _args, ',');
|
||||||
|
@ -27,11 +27,10 @@
|
|||||||
#ifndef SQLPP_INSERT_LIST_H
|
#ifndef SQLPP_INSERT_LIST_H
|
||||||
#define SQLPP_INSERT_LIST_H
|
#define SQLPP_INSERT_LIST_H
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/detail/set.h>
|
#include <sqlpp11/detail/set.h>
|
||||||
#include <sqlpp11/detail/serialize_tuple.h>
|
#include <sqlpp11/detail/serialize_tuple.h>
|
||||||
#include <sqlpp11/detail/serializable.h>
|
#include <sqlpp11/detail/serializable_list.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -47,18 +46,6 @@ namespace sqlpp
|
|||||||
os << " DEFAULT VALUES";
|
os << " DEFAULT VALUES";
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Db>
|
|
||||||
struct dynamic_column_list
|
|
||||||
{
|
|
||||||
using type = std::vector<detail::serializable_t<Db>>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct dynamic_column_list<void>
|
|
||||||
{
|
|
||||||
using type = std::vector<noop>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Column>
|
template<typename Column>
|
||||||
struct insert_column
|
struct insert_column
|
||||||
{
|
{
|
||||||
@ -107,8 +94,8 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
static_assert(is_assignment_t<typename std::decay<Assignment>::type>::value, "set() arguments require to be assigments");
|
static_assert(is_assignment_t<typename std::decay<Assignment>::type>::value, "set() arguments require to be assigments");
|
||||||
static_assert(not ProhibitPredicate<typename std::decay<Assignment>::type>::value, "set() argument must not be used in insert");
|
static_assert(not ProhibitPredicate<typename std::decay<Assignment>::type>::value, "set() argument must not be used in insert");
|
||||||
_dynamic_columns.push_back(std::forward<typename Assignment::column_type>(assignment._lhs));
|
_dynamic_columns.emplace_back(detail::insert_column<typename Assignment::column_type>{std::forward<typename Assignment::column_type>(assignment._lhs)});
|
||||||
_dynamic_values.push_back(std::forward<typename Assignment::value_type>(assignment._rhs));
|
_dynamic_values.emplace_back(std::forward<typename Assignment::value_type>(assignment._rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Db>
|
template<typename Db>
|
||||||
@ -120,38 +107,22 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
constexpr bool first = sizeof...(Assignments) == 0;
|
||||||
|
|
||||||
os << " (";
|
os << " (";
|
||||||
detail::serialize_tuple(os, db, _columns, ',');
|
detail::serialize_tuple(os, db, _columns, ',');
|
||||||
{
|
_dynamic_columns.serialize(os, db, first);
|
||||||
bool first = sizeof...(Assignments) == 0;
|
|
||||||
for (const auto column : _dynamic_columns)
|
|
||||||
{
|
|
||||||
if (not first)
|
|
||||||
os << ',';
|
|
||||||
column.serialize(os, db);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os << ") VALUES (";
|
os << ") VALUES (";
|
||||||
detail::serialize_tuple(os, db, _values, ',');
|
detail::serialize_tuple(os, db, _values, ',');
|
||||||
{
|
_dynamic_values.serialize(os, db, first);
|
||||||
bool first = sizeof...(Assignments) == 0;
|
|
||||||
for (const auto column : _dynamic_values)
|
|
||||||
{
|
|
||||||
if (not first)
|
|
||||||
os << ',';
|
|
||||||
column.serialize(os, db);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os << ")";
|
os << ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<detail::insert_column<typename Assignments::column_type>...> _columns;
|
std::tuple<detail::insert_column<typename Assignments::column_type>...> _columns;
|
||||||
std::tuple<typename Assignments::value_type...> _values;
|
std::tuple<typename Assignments::value_type...> _values;
|
||||||
typename detail::dynamic_column_list<Database>::type _dynamic_columns;
|
typename detail::serializable_list<Database> _dynamic_columns;
|
||||||
typename detail::dynamic_column_list<Database>::type _dynamic_values;
|
typename detail::serializable_list<Database> _dynamic_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,8 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
static_assert(NotInverted and Db::_supports_is_null
|
static_assert((NotInverted and Db::_supports_is_null)
|
||||||
or _inverted and Db::_supports_is_not_null, "is_null() and/or is_not_null() not supported by current database");
|
or (_inverted and Db::_supports_is_not_null), "is_null() and/or is_not_null() not supported by current database");
|
||||||
_operand.serialize(os, db);
|
_operand.serialize(os, db);
|
||||||
os << (_inverted ? " IS NOT NULL" : " IS NULL");
|
os << (_inverted ? " IS NOT NULL" : " IS NULL");
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ namespace sqlpp
|
|||||||
void push_back(Expr&& expr)
|
void push_back(Expr&& expr)
|
||||||
{
|
{
|
||||||
_dynamic_expression_names.push_back(std::decay<Expr>::type::_name_t::_get_name());
|
_dynamic_expression_names.push_back(std::decay<Expr>::type::_name_t::_get_name());
|
||||||
_dynamic_expressions.push_back(std::forward<Expr>(expr));
|
_dynamic_expressions.emplace_back(std::forward<Expr>(expr));
|
||||||
}
|
}
|
||||||
void serialize(std::ostream& os, Db& db, bool first) const
|
void serialize(std::ostream& os, Db& db, bool first) const
|
||||||
{
|
{
|
||||||
|
@ -28,12 +28,11 @@
|
|||||||
#define SQLPP_WHERE_H
|
#define SQLPP_WHERE_H
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <vector>
|
|
||||||
#include <sqlpp11/select_fwd.h>
|
#include <sqlpp11/select_fwd.h>
|
||||||
#include <sqlpp11/expression.h>
|
#include <sqlpp11/expression.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/detail/set.h>
|
#include <sqlpp11/detail/set.h>
|
||||||
#include <sqlpp11/detail/serializable.h>
|
#include <sqlpp11/detail/serializable_list.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -65,7 +64,7 @@ namespace sqlpp
|
|||||||
void add(Expr&& expr)
|
void add(Expr&& expr)
|
||||||
{
|
{
|
||||||
static_assert(is_expression_t<typename std::decay<Expr>::type>::value, "invalid expression argument in where()");
|
static_assert(is_expression_t<typename std::decay<Expr>::type>::value, "invalid expression argument in where()");
|
||||||
_conditions.push_back(std::forward<Expr>(expr));
|
_conditions.emplace_back(std::forward<Expr>(expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
@ -75,16 +74,10 @@ namespace sqlpp
|
|||||||
|
|
||||||
os << " WHERE ";
|
os << " WHERE ";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (const auto& condition : _conditions)
|
_conditions.serialize(os, db, " AND ", true);
|
||||||
{
|
|
||||||
if (not first)
|
|
||||||
os << " AND ";
|
|
||||||
condition.serialize(os, db);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<detail::serializable_t<Db>> _conditions;
|
detail::serializable_list<Db> _conditions;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user