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

Added serializer to interpreter

The serializer has partial specializations for all templates. It is a
good basis if the connector/database requires strings close to the
standard.

The interpreter is unspecialized (and uses a static assert to say so).
It is a good basis if the connector/database requires a different
interpretation, e.g. re-writing the expression tree.

The interpretable_t implements three methods for interpretation:
serializing with the sqlpp::serializer_context, serializing with the
database's serialization context and interpretation with the database's
interpretation context.
This commit is contained in:
rbock 2014-02-18 17:45:08 +01:00
parent 26f322b86a
commit abf4bb8e9a
65 changed files with 423 additions and 293 deletions

View File

@ -48,14 +48,14 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Expression, typename AliasProvider>
struct interpreter_t<Context, expression_alias_t<Expression, AliasProvider>>
struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>>
{
using T = expression_alias_t<Expression, AliasProvider>;
static Context& _(const T& t, Context& context)
{
context << '(';
interpret(t._expression, context);
serialize(t._expression, context);
context << ") AS ";
context << T::_name_t::_get_name();
return context;

View File

@ -54,7 +54,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Table>
struct interpreter_t<Context, all_of_t<Table>>
struct serializer_t<Context, all_of_t<Table>>
{
using T = all_of_t<Table>;

View File

@ -76,14 +76,14 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Select>
struct interpreter_t<Context, vendor::any_t<Select>>
struct serializer_t<Context, vendor::any_t<Select>>
{
using T = vendor::any_t<Select>;
static Context& _(const T& t, Context& context)
{
context << "ANY(";
interpret(t._select, context);
serialize(t._select, context);
context << ")";
return context;
}

View File

@ -27,7 +27,6 @@
#ifndef SQLPP_AVG_H
#define SQLPP_AVG_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
@ -74,7 +73,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Flag, typename Expr>
struct interpreter_t<Context, vendor::avg_t<Flag, Expr>>
struct serializer_t<Context, vendor::avg_t<Flag, Expr>>
{
using T = vendor::avg_t<Flag, Expr>;
@ -83,10 +82,10 @@ namespace sqlpp
context << "AVG(";
if (std::is_same<sqlpp::distinct_t, Flag>::value)
{
interpret(Flag(), context);
serialize(Flag(), context);
context << ' ';
}
interpret(t._expr, context);
serialize(t._expr, context);
context << ")";
return context;
}

View File

@ -35,7 +35,7 @@
#include <sqlpp11/type_traits.h>
#include <sqlpp11/vendor/assignment.h>
#include <sqlpp11/vendor/expression.h>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/vendor/serializer.h>
#include <sqlpp11/vendor/wrong.h>
#include <sqlpp11/detail/type_set.h>
@ -109,7 +109,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename... Args>
struct interpreter_t<Context, column_t<Args...>>
struct serializer_t<Context, column_t<Args...>>
{
using T = column_t<Args...>;

View File

@ -74,7 +74,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Flag, typename Expr>
struct interpreter_t<Context, vendor::count_t<Flag, Expr>>
struct serializer_t<Context, vendor::count_t<Flag, Expr>>
{
using T = vendor::count_t<Flag, Expr>;
@ -83,10 +83,10 @@ namespace sqlpp
context << "COUNT(";
if (std::is_same<sqlpp::distinct_t, Flag>::value)
{
interpret(Flag(), context);
serialize(Flag(), context);
context << ' ';
}
interpret(t._expr, context);
serialize(t._expr, context);
context << ")";
return context;
}

View File

@ -43,7 +43,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context>
struct interpreter_t<Context, default_value_t>
struct serializer_t<Context, default_value_t>
{
using Operand = default_value_t;

View File

@ -72,14 +72,14 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Select>
struct interpreter_t<Context, vendor::exists_t<Select>>
struct serializer_t<Context, vendor::exists_t<Select>>
{
using T = vendor::exists_t<Select>;
static Context& _(const T& t, Context& context)
{
context << "EXISTS(";
interpret(t._select, context);
serialize(t._select, context);
context << ")";
return context;
}

View File

@ -71,7 +71,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename ValueType>
struct interpreter_t<Context, verbatim_t<ValueType>>
struct serializer_t<Context, verbatim_t<ValueType>>
{
using T = verbatim_t<ValueType>;
@ -94,7 +94,7 @@ namespace sqlpp
{
static_assert(not make_parameter_list_t<Expression>::type::size::value, "parameters not supported in flattened expressions");
context.clear();
interpret(exp, context);
serialize(exp, context);
return { context.str() };
}
@ -121,7 +121,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Container>
struct interpreter_t<Context, value_list_t<Container>>
struct serializer_t<Context, value_list_t<Container>>
{
using T = value_list_t<Container>;
@ -135,7 +135,7 @@ namespace sqlpp
else
context << ',';
interpret(value(entry), context);
serialize(value(entry), context);
}
return context;
}

View File

@ -166,15 +166,15 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Database, typename... Policies>
struct interpreter_t<Context, insert_t<Database, Policies...>>
struct serializer_t<Context, insert_t<Database, Policies...>>
{
using T = insert_t<Database, Policies...>;
static Context& _(const T& t, Context& context)
{
context << "INSERT INTO ";
interpret(t._table, context);
interpret(t._insert_value_list, context);
serialize(t._table, context);
serialize(t._insert_value_list, context);
return context;
}
};

View File

@ -145,18 +145,18 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename JoinType, typename Lhs, typename Rhs, typename On>
struct interpreter_t<Context, join_t<JoinType, Lhs, Rhs, On>>
struct serializer_t<Context, join_t<JoinType, Lhs, Rhs, On>>
{
using T = join_t<JoinType, Lhs, Rhs, On>;
static Context& _(const T& t, Context& context)
{
static_assert(not vendor::is_noop<On>::value, "joined tables require on()");
interpret(t._lhs, context);
serialize(t._lhs, context);
context << JoinType::_name;
context << " JOIN ";
interpret(t._rhs, context);
interpret(t._on, context);
serialize(t._rhs, context);
serialize(t._on, context);
return context;
}
};

View File

@ -27,7 +27,6 @@
#ifndef SQLPP_MAX_H
#define SQLPP_MAX_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
@ -73,14 +72,14 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Expr>
struct interpreter_t<Context, vendor::max_t<Expr>>
struct serializer_t<Context, vendor::max_t<Expr>>
{
using T = vendor::max_t<Expr>;
static Context& _(const T& t, Context& context)
{
context << "MAX(";
interpret(t._expr, context);
serialize(t._expr, context);
context << ")";
return context;
}

View File

@ -27,7 +27,6 @@
#ifndef SQLPP_MIN_H
#define SQLPP_MIN_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
@ -73,14 +72,14 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Expr>
struct interpreter_t<Context, vendor::min_t<Expr>>
struct serializer_t<Context, vendor::min_t<Expr>>
{
using T = vendor::min_t<Expr>;
static Context& _(const T& t, Context& context)
{
context << "MIN(";
interpret(t._expr, context);
serialize(t._expr, context);
context << ")";
return context;
}

View File

@ -106,7 +106,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename... Columns>
struct interpreter_t<Context, multi_column_t<void, Columns...>>
struct serializer_t<Context, multi_column_t<void, Columns...>>
{
using T = multi_column_t<void, Columns...>;
@ -117,7 +117,7 @@ namespace sqlpp
};
template<typename Context, typename AliasProvider, typename... Columns>
struct interpreter_t<Context, multi_column_alias_t<AliasProvider, Columns...>>
struct serializer_t<Context, multi_column_alias_t<AliasProvider, Columns...>>
{
using T = multi_column_alias_t<AliasProvider, Columns...>;

View File

@ -43,7 +43,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context>
struct interpreter_t<Context, null_t>
struct serializer_t<Context, null_t>
{
using Operand = null_t;

View File

@ -57,7 +57,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Database, typename... Expr>
struct interpreter_t<Context, on_t<Database, Expr...>>
struct serializer_t<Context, on_t<Database, Expr...>>
{
using T = on_t<Database, Expr...>;

View File

@ -54,7 +54,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename ValueType, typename NameType>
struct interpreter_t<Context, parameter_t<ValueType, NameType>>
struct serializer_t<Context, parameter_t<ValueType, NameType>>
{
using T = parameter_t<ValueType, NameType>;

View File

@ -189,16 +189,16 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Database, typename... Policies>
struct interpreter_t<Context, remove_t<Database, Policies...>>
struct serializer_t<Context, remove_t<Database, Policies...>>
{
using T = remove_t<Database, Policies...>;
static Context& _(const T& t, Context& context)
{
context << "DELETE FROM ";
interpret(t._table, context);
interpret(t._using, context);
interpret(t._where, context);
serialize(t._table, context);
serialize(t._using, context);
serialize(t._where, context);
return context;
}
};

View File

@ -42,7 +42,7 @@
#include <sqlpp11/vendor/limit.h>
#include <sqlpp11/vendor/offset.h>
#include <sqlpp11/vendor/expression.h>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/vendor/serializer.h>
#include <sqlpp11/vendor/wrong.h>
#include <sqlpp11/vendor/policy_update.h>
@ -540,7 +540,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Database, typename... Policies>
struct interpreter_t<Context, select_t<Database, Policies...>>
struct serializer_t<Context, select_t<Database, Policies...>>
{
using T = select_t<Database, Policies...>;
@ -548,15 +548,15 @@ namespace sqlpp
{
context << "SELECT ";
interpret(t._flag_list, context);
interpret(t._column_list, context);
interpret(t._from, context);
interpret(t._where, context);
interpret(t._group_by, context);
interpret(t._having, context);
interpret(t._order_by, context);
interpret(t._limit, context);
interpret(t._offset, context);
serialize(t._flag_list, context);
serialize(t._column_list, context);
serialize(t._from, context);
serialize(t._where, context);
serialize(t._group_by, context);
serialize(t._having, context);
serialize(t._order_by, context);
serialize(t._limit, context);
serialize(t._offset, context);
return context;
}

View File

@ -47,7 +47,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context>
struct interpreter_t<Context, all_t>
struct serializer_t<Context, all_t>
{
static Context& _(const all_t&, Context& context)
{
@ -69,7 +69,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context>
struct interpreter_t<Context, distinct_t>
struct serializer_t<Context, distinct_t>
{
static Context& _(const distinct_t&, Context& context)
{
@ -91,7 +91,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context>
struct interpreter_t<Context, straight_join_t>
struct serializer_t<Context, straight_join_t>
{
static Context& _(const straight_join_t&, Context& context)
{

View File

@ -0,0 +1,43 @@
/*
* 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_SERIALIZE_H
#define SQLPP_SERIALIZE_H
#include <sqlpp11/vendor/serializer.h>
namespace sqlpp
{
template<typename T, typename Context>
auto serialize(const T& t, Context& context)
-> decltype(vendor::serializer_t<Context, T>::_(t, context))
{
return vendor::serializer_t<Context, T>::_(t, context);
}
}
#endif

View File

@ -23,16 +23,16 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SERIALIZER_H
#define SQLPP_SERIALIZER_H
#ifndef SQLPP_SERIALIZER_CONTEXT_H
#define SQLPP_SERIALIZER_CONTEXT_H
#include <ostream>
namespace sqlpp
{
struct serializer_t
struct serializer_context_t
{
serializer_t(std::ostream& os):
serializer_context_t(std::ostream& os):
_os(os)
{}
@ -49,6 +49,7 @@ namespace sqlpp
std::string escape(std::string arg)
{
// FIXME: Need to do better escaping
return arg;
}

View File

@ -75,14 +75,14 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Select>
struct interpreter_t<Context, vendor::some_t<Select>>
struct serializer_t<Context, vendor::some_t<Select>>
{
using T = vendor::some_t<Select>;
static Context& _(const T& t, Context& context)
{
context << "SOME(";
interpret(t._select, context);
serialize(t._select, context);
context << ")";
return context;
}

View File

@ -46,13 +46,13 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Expression, sort_type SortType>
struct interpreter_t<Context, sort_order_t<Expression, SortType>>
struct serializer_t<Context, sort_order_t<Expression, SortType>>
{
using T = sort_order_t<Expression, SortType>;
static Context& _(const T& t, Context& context)
{
interpret(t._expression, context);
serialize(t._expression, context);
switch(SortType)
{
case sort_type::asc:

View File

@ -27,7 +27,6 @@
#ifndef SQLPP_SUM_H
#define SQLPP_SUM_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
@ -74,7 +73,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Flag, typename Expr>
struct interpreter_t<Context, vendor::sum_t<Flag, Expr>>
struct serializer_t<Context, vendor::sum_t<Flag, Expr>>
{
using T = vendor::sum_t<Flag, Expr>;
@ -83,10 +82,10 @@ namespace sqlpp
context << "SUM(";
if (std::is_same<sqlpp::distinct_t, Flag>::value)
{
interpret(Flag(), context);
serialize(Flag(), context);
context << ' ';
}
interpret(t._expr, context);
serialize(t._expr, context);
context << ")";
return context;
}

View File

@ -96,7 +96,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename X>
struct interpreter_t<Context, X, typename std::enable_if<std::is_base_of<table_base_t, X>::value and not is_pseudo_table_t<X>::value, void>::type>
struct serializer_t<Context, X, typename std::enable_if<std::is_base_of<table_base_t, X>::value and not is_pseudo_table_t<X>::value, void>::type>
{
using T = X;

View File

@ -64,14 +64,14 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename X>
struct interpreter_t<Context, X, typename std::enable_if<std::is_base_of<table_alias_base_t, X>::value, void>::type>
struct serializer_t<Context, X, typename std::enable_if<std::is_base_of<table_alias_base_t, X>::value, void>::type>
{
using T = X;
static Context& _(const T& t, Context& context)
{
context << "(";
interpret(t._table, context);
serialize(t._table, context);
context << ") AS " << T::_name_t::_get_name();
return context;
}

View File

@ -30,7 +30,8 @@
// TVIN: Trivial value is NULL
#include <sqlpp11/type_traits.h>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/serialize.h>
#include <sqlpp11/vendor/serializer.h>
namespace sqlpp
{
@ -61,7 +62,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Operand>
struct interpreter_t<Context, tvin_t<Operand>>
struct serializer_t<Context, tvin_t<Operand>>
{
using T = tvin_t<Operand>;
@ -117,7 +118,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Operand>
struct interpreter_t<Context, tvin_wrap_t<Operand>>
struct serializer_t<Context, tvin_wrap_t<Operand>>
{
using T = tvin_wrap_t<Operand>;
@ -129,7 +130,7 @@ namespace sqlpp
}
else
{
interpret(t._value, context);
serialize(t._value, context);
}
return context;
}

View File

@ -191,16 +191,16 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Database, typename... Policies>
struct interpreter_t<Context, update_t<Database, Policies...>>
struct serializer_t<Context, update_t<Database, Policies...>>
{
using T = update_t<Database, Policies...>;
static Context& _(const T& t, Context& context)
{
context << "UPDATE ";
interpret(t._table, context);
interpret(t._update_list, context);
interpret(t._where, context);
serialize(t._table, context);
serialize(t._update_list, context);
serialize(t._where, context);
return context;
}
};

View File

@ -30,7 +30,8 @@
#include <sqlpp11/default_value.h>
#include <sqlpp11/null.h>
#include <sqlpp11/tvin.h>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/serialize.h>
#include <sqlpp11/vendor/serializer.h>
#include <sqlpp11/vendor/simple_column.h>
namespace sqlpp
@ -64,15 +65,15 @@ namespace sqlpp
};
template<typename Context, typename Lhs, typename Rhs>
struct interpreter_t<Context, assignment_t<Lhs, Rhs>>
struct serializer_t<Context, assignment_t<Lhs, Rhs>>
{
using T = assignment_t<Lhs, Rhs>;
static Context& _(const T& t, Context& context)
{
interpret(simple_column(t._lhs), context);
serialize(simple_column(t._lhs), context);
context << "=";
interpret(t._rhs, context);
serialize(t._rhs, context);
return context;
}
};
@ -103,13 +104,13 @@ namespace sqlpp
};
template<typename Context, typename Lhs, typename Rhs>
struct interpreter_t<Context, assignment_t<Lhs, tvin_t<Rhs>>>
struct serializer_t<Context, assignment_t<Lhs, tvin_t<Rhs>>>
{
using T = assignment_t<Lhs, tvin_t<Rhs>>;
static Context& _(const T& t, Context& context)
{
interpret(simple_column(t._lhs), context);
serialize(simple_column(t._lhs), context);
if (t._rhs._value._is_trivial())
{
context << "=NULL";
@ -117,7 +118,7 @@ namespace sqlpp
else
{
context << "=";
interpret(t._rhs._value, context);
serialize(t._rhs._value, context);
}
return context;
}

View File

@ -71,7 +71,7 @@ namespace sqlpp
};
template<typename Context, typename First, typename... Args>
struct interpreter_t<Context, concat_t<First, Args...>>
struct serializer_t<Context, concat_t<First, Args...>>
{
using T = concat_t<First, Args...>;

View File

@ -32,7 +32,7 @@
#include <sqlpp11/tvin.h>
#include <sqlpp11/vendor/noop.h>
#include <sqlpp11/vendor/expression_fwd.h>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/vendor/serializer.h>
#include <sqlpp11/vendor/wrap_operand.h>
namespace sqlpp
@ -62,14 +62,14 @@ namespace sqlpp
};
template<typename Context, typename Lhs, typename Rhs>
struct interpreter_t<Context, equal_to_t<Lhs, Rhs>>
struct serializer_t<Context, equal_to_t<Lhs, Rhs>>
{
using T = equal_to_t<Lhs, Rhs>;
static Context& _(const T& t, Context& context)
{
context << "(";
interpret(t._lhs, context);
serialize(t._lhs, context);
if (t._rhs._is_trivial())
{
context << " IS NULL";
@ -77,7 +77,7 @@ namespace sqlpp
else
{
context << "=";
interpret(t._rhs, context);
serialize(t._rhs, context);
}
context << ")";
return context;
@ -106,16 +106,15 @@ namespace sqlpp
tvin_wrap_t<Rhs> _rhs;
};
/*
template<typename Context, typename Lhs, typename Rhs>
struct interpreter_t<Context, not_equal_to_t<Lhs, Rhs>>
struct serializer_t<Context, not_equal_to_t<Lhs, Rhs>>
{
using T = not_equal_to_t<Lhs, Rhs>;
static Context& _(const T& t, Context& context)
{
context << "(";
interpret(t._lhs, context);
serialize(t._lhs, context);
if (t._rhs._is_trivial())
{
context << " IS NOT NULL";
@ -123,13 +122,12 @@ namespace sqlpp
else
{
context << "!=";
interpret(t._rhs, context);
serialize(t._rhs, context);
}
context << ")";
return context;
}
};
*/
template<typename Rhs>
struct unary_expression_t<tag::logical_not, Rhs>: public ::sqlpp::detail::boolean::template operators<logical_not_t<Rhs>>
@ -152,7 +150,7 @@ namespace sqlpp
};
template<typename Context, typename Rhs>
struct interpreter_t<Context, logical_not_t<Rhs>>
struct serializer_t<Context, logical_not_t<Rhs>>
{
using T = logical_not_t<Rhs>;
@ -160,7 +158,7 @@ namespace sqlpp
{
context << "(";
context << "NOT ";
interpret(t._lhs, context);
serialize(t._lhs, context);
context << ")";
return context;
}
@ -191,16 +189,16 @@ namespace sqlpp
};
template<typename Context, typename Lhs, typename O, typename Rhs>
struct interpreter_t<Context, binary_expression_t<Lhs, O, Rhs>>
struct serializer_t<Context, binary_expression_t<Lhs, O, Rhs>>
{
using T = binary_expression_t<Lhs, O, Rhs>;
static Context& _(const T& t, Context& context)
{
context << "(";
interpret(t._lhs, context);
serialize(t._lhs, context);
context << O::_name;
interpret(t._rhs, context);
serialize(t._rhs, context);
context << ")";
return context;
}
@ -226,7 +224,7 @@ namespace sqlpp
};
template<typename Context, typename O, typename Rhs>
struct interpreter_t<Context, unary_expression_t<O, Rhs>>
struct serializer_t<Context, unary_expression_t<O, Rhs>>
{
using T = unary_expression_t<O, Rhs>;
@ -234,7 +232,7 @@ namespace sqlpp
{
context << "(";
context << O::_name;
interpret(t._rhs, context);
serialize(t._rhs, context);
context << ")";
return context;
}

View File

@ -83,7 +83,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Tables>
struct interpreter_t<Context, from_t<Database, Tables...>>
struct serializer_t<Context, from_t<Database, Tables...>>
{
using T = from_t<Database, Tables...>;
@ -101,7 +101,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_from_t>
struct serializer_t<Context, no_from_t>
{
using T = no_from_t;

View File

@ -82,7 +82,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct interpreter_t<Context, group_by_t<Database, Expressions...>>
struct serializer_t<Context, group_by_t<Database, Expressions...>>
{
using T = group_by_t<Database, Expressions...>;
@ -100,7 +100,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_group_by_t>
struct serializer_t<Context, no_group_by_t>
{
using T = no_group_by_t;

View File

@ -79,7 +79,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct interpreter_t<Context, having_t<Database, Expressions...>>
struct serializer_t<Context, having_t<Database, Expressions...>>
{
using T = having_t<Database, Expressions...>;
@ -97,7 +97,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_having_t>
struct serializer_t<Context, no_having_t>
{
using T = no_having_t;

View File

@ -74,13 +74,13 @@ namespace sqlpp
};
template<typename Context, bool NotInverted, typename Operand, typename... Args>
struct interpreter_t<Context, vendor::in_t<NotInverted, Operand, Args...>>
struct serializer_t<Context, vendor::in_t<NotInverted, Operand, Args...>>
{
using T = vendor::in_t<NotInverted, Operand, Args...>;
static Context& _(const T& t, Context& context)
{
interpret(t._operand, context);
serialize(t._operand, context);
context << (t._inverted ? " NOT IN(" : " IN(");
interpret_tuple(t._args, ',', context);
context << ')';

View File

@ -31,7 +31,7 @@
#include <sqlpp11/null.h>
#include <sqlpp11/tvin.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/vendor/serializer.h>
#include <sqlpp11/detail/type_set.h>
namespace sqlpp
@ -102,7 +102,7 @@ namespace sqlpp
};
template<typename Context, typename ValueType>
struct interpreter_t<Context, insert_value_t<ValueType>>
struct serializer_t<Context, insert_value_t<ValueType>>
{
using T = insert_value_t<ValueType>;
@ -113,7 +113,7 @@ namespace sqlpp
else if (t._is_default)
context << "DEFAULT";
else
interpret(t._value, context);
serialize(t._value, context);
return context;
}
};

View File

@ -171,7 +171,7 @@ namespace sqlpp
// Interpreters
template<typename Context>
struct interpreter_t<Context, insert_default_values_t>
struct serializer_t<Context, insert_default_values_t>
{
using T = insert_default_values_t;
@ -183,7 +183,7 @@ namespace sqlpp
};
template<typename Context, typename... Columns>
struct interpreter_t<Context, column_list_t<Columns...>>
struct serializer_t<Context, column_list_t<Columns...>>
{
using T = column_list_t<Columns...>;
@ -210,7 +210,7 @@ namespace sqlpp
};
template<typename Context, typename Database, typename... Assignments>
struct interpreter_t<Context, insert_list_t<Database, Assignments...>>
struct serializer_t<Context, insert_list_t<Database, Assignments...>>
{
using T = insert_list_t<Database, Assignments...>;
@ -218,7 +218,7 @@ namespace sqlpp
{
if (sizeof...(Assignments) + t._dynamic_columns.size() == 0)
{
interpret(insert_default_values_t(), context);
serialize(insert_default_values_t(), context);
}
else
{
@ -239,7 +239,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_insert_value_list_t>
struct serializer_t<Context, no_insert_value_list_t>
{
using T = no_insert_value_list_t;

View File

@ -28,8 +28,8 @@
#define SQLPP_INTERPRET_TUPLE_H
#include <tuple>
#include <ostream>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/serialize.h>
namespace sqlpp
{
@ -54,7 +54,7 @@ namespace sqlpp
using entry_type = typename std::tuple_element<index, Tuple>::type;
if (requires_braces_t<entry_type>::value)
context << "(";
interpret(entry, context);
serialize(entry, context);
if (requires_braces_t<entry_type>::value)
context << ")";
_impl(t, separator, context, type<index + 1>());

View File

@ -28,8 +28,9 @@
#define SQLPP_INTERPRETABLE_H
#include <memory>
#include <sqlpp11/serializer.h>
#include <sqlpp11/serializer_context.h>
#include <sqlpp11/parameter_list.h>
#include <sqlpp11/serialize.h>
#include <sqlpp11/interpret.h>
namespace sqlpp
@ -39,7 +40,8 @@ namespace sqlpp
template<typename Db>
struct interpretable_t
{
using _context_t = typename Db::_context_t;
using _serializer_context_t = typename Db::_serializer_context_t;
using _interpreter_context_t = typename Db::_interpreter_context_t;
template<typename T>
interpretable_t(T t):
@ -52,12 +54,17 @@ namespace sqlpp
interpretable_t& operator=(interpretable_t&&) = default;
~interpretable_t() = default;
sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const
sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const
{
return _impl->interpret(context);
return _impl->serialize(context);
}
_context_t& interpret(_context_t& context) const
_serializer_context_t& serialize(_serializer_context_t& context) const
{
return _impl->serialize(context);
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
return _impl->interpret(context);
}
@ -65,8 +72,9 @@ namespace sqlpp
private:
struct _impl_base
{
virtual sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const = 0;
virtual _context_t& interpret(_context_t& context) const = 0;
virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0;
virtual _serializer_context_t& serialize(_serializer_context_t& context) const = 0;
virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0;
};
template<typename T>
@ -77,15 +85,21 @@ namespace sqlpp
_t(t)
{}
sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const
sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const
{
sqlpp::interpret(_t, context);
sqlpp::serialize(_t, context);
return context;
}
_context_t& interpret(_context_t& context) const
_serializer_context_t& serialize(_serializer_context_t& context) const
{
sqlpp::interpret(_t, context);
Db::_serialize_interpretable(_t, context);
return context;
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
Db::_interpret_interpretable(_t, context);
return context;
}
@ -96,13 +110,13 @@ namespace sqlpp
};
template<typename Context, typename Database>
struct interpreter_t<Context, interpretable_t<Database>>
struct serializer_t<Context, interpretable_t<Database>>
{
using T = interpretable_t<Database>;
static Context& _(const T& t, Context& context)
{
t.interpret(context);
t.serialize(context);
return context;
}
};

View File

@ -91,7 +91,7 @@ namespace sqlpp
context << separator;
first = false;
}
interpret(entry, context);
serialize(entry, context);
}
return context;
}

View File

@ -70,13 +70,13 @@ namespace sqlpp
};
template<typename Context, bool NotInverted, typename Operand>
struct interpreter_t<Context, ::sqlpp::vendor::is_null_t<NotInverted, Operand>>
struct serializer_t<Context, ::sqlpp::vendor::is_null_t<NotInverted, Operand>>
{
using T = ::sqlpp::vendor::is_null_t<NotInverted, Operand>;
static Context& _(const T& t, Context& context)
{
interpret(t._operand, context);
serialize(t._operand, context);
context << (t._inverted ? " IS NOT NULL" : " IS NULL");
return context;
}

View File

@ -74,15 +74,15 @@ namespace sqlpp
};
template<typename Context, typename Operand, typename Pattern>
struct interpreter_t<Context, like_t<Operand, Pattern>>
struct serializer_t<Context, like_t<Operand, Pattern>>
{
using T = like_t<Operand, Pattern>;
static Context& _(const T& t, Context& context)
{
interpret(t._operand, context);
serialize(t._operand, context);
context << " LIKE(";
interpret(t._pattern, context);
serialize(t._pattern, context);
context << ")";
return context;
}

View File

@ -97,7 +97,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database>
struct interpreter_t<Context, dynamic_limit_t<Database>>
struct serializer_t<Context, dynamic_limit_t<Database>>
{
using T = dynamic_limit_t<Database>;
@ -106,27 +106,27 @@ namespace sqlpp
if (t._initialized)
{
context << " LIMIT ";
interpret(t._value, context);
serialize(t._value, context);
}
return context;
}
};
template<typename Context, typename Limit>
struct interpreter_t<Context, limit_t<Limit>>
struct serializer_t<Context, limit_t<Limit>>
{
using T = limit_t<Limit>;
static Context& _(const T& t, Context& context)
{
context << " LIMIT ";
interpret(t._value, context);
serialize(t._value, context);
return context;
}
};
template<typename Context>
struct interpreter_t<Context, no_limit_t>
struct serializer_t<Context, no_limit_t>
{
using T = no_limit_t;

View File

@ -28,7 +28,7 @@
#define SQLPP_NAMED_SERIALIZABLE_H
#include <memory>
#include <sqlpp11/serializer.h>
#include <sqlpp11/serializer_context.h>
#include <sqlpp11/parameter_list.h>
namespace sqlpp
@ -38,7 +38,8 @@ namespace sqlpp
template<typename Db>
struct named_interpretable_t
{
using _context_t = typename Db::_context_t;
using _serializer_context_t = typename Db::_serializer_context_t;
using _interpreter_context_t = typename Db::_interpreter_context_t;
template<typename T>
named_interpretable_t(T t):
@ -51,12 +52,17 @@ namespace sqlpp
named_interpretable_t& operator=(named_interpretable_t&&) = default;
~named_interpretable_t() = default;
sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const
sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const
{
return _impl->interpret(context);
return _impl->serialize(context);
}
_context_t& interpret(_context_t& context) const
_serializer_context_t& serialize(_serializer_context_t& context) const
{
return _impl->serialize(context);
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
return _impl->interpret(context);
}
@ -69,8 +75,9 @@ namespace sqlpp
private:
struct _impl_base
{
virtual sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const = 0;
virtual _context_t& interpret(_context_t& context) const = 0;
virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0;
virtual _serializer_context_t& serialize(_serializer_context_t& context) const = 0;
virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0;
virtual std::string _get_name() const = 0;
};
@ -82,15 +89,21 @@ namespace sqlpp
_t(t)
{}
sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const
sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const
{
sqlpp::interpret(_t, context);
sqlpp::serialize(_t, context);
return context;
}
_context_t& interpret(_context_t& context) const
_serializer_context_t& serialize(_serializer_context_t& context) const
{
sqlpp::interpret(_t, context);
Db::_serialize_interpretable(_t, context);
return context;
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
Db::_interpret_interpretable(_t, context);
return context;
}
@ -106,13 +119,13 @@ namespace sqlpp
};
template<typename Context, typename Database>
struct interpreter_t<Context, named_interpretable_t<Database>>
struct serializer_t<Context, named_interpretable_t<Database>>
{
using T = named_interpretable_t<Database>;
static Context& _(const T& t, Context& context)
{
t.interpret(context);
t.serialize(context);
return context;
}
};

View File

@ -39,7 +39,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, noop>
struct serializer_t<Context, noop>
{
using T = noop;

View File

@ -97,20 +97,20 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Offset>
struct interpreter_t<Context, offset_t<Offset>>
struct serializer_t<Context, offset_t<Offset>>
{
using T = offset_t<Offset>;
static Context& _(const T& t, Context& context)
{
context << " OFFSET ";
interpret(t._value, context);
serialize(t._value, context);
return context;
}
};
template<typename Context, typename Database>
struct interpreter_t<Context, dynamic_offset_t<Database>>
struct serializer_t<Context, dynamic_offset_t<Database>>
{
using T = dynamic_offset_t<Database>;
@ -119,14 +119,14 @@ namespace sqlpp
if (t._initialized)
{
context << " OFFSET ";
interpret(t._value, context);
serialize(t._value, context);
}
return context;
}
};
template<typename Context>
struct interpreter_t<Context, no_offset_t>
struct serializer_t<Context, no_offset_t>
{
using T = no_offset_t;

View File

@ -79,7 +79,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct interpreter_t<Context, order_by_t<Database, Expressions...>>
struct serializer_t<Context, order_by_t<Database, Expressions...>>
{
using T = order_by_t<Database, Expressions...>;
@ -97,7 +97,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_order_by_t>
struct serializer_t<Context, no_order_by_t>
{
using T = no_order_by_t;

View File

@ -99,7 +99,7 @@ namespace sqlpp
};
template<typename Context, typename Db>
struct interpreter_t<Context, dynamic_select_column_list<Db>>
struct serializer_t<Context, dynamic_select_column_list<Db>>
{
using T = dynamic_select_column_list<Db>;
@ -112,14 +112,14 @@ namespace sqlpp
first = false;
else
context << ',';
interpret(column, context);
serialize(column, context);
}
return context;
}
};
template<typename Context>
struct interpreter_t<Context, dynamic_select_column_list<void>>
struct serializer_t<Context, dynamic_select_column_list<void>>
{
using T = dynamic_select_column_list<void>;
@ -212,7 +212,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Columns>
struct interpreter_t<Context, select_column_list_t<Database, Columns...>>
struct serializer_t<Context, select_column_list_t<Database, Columns...>>
{
using T = select_column_list_t<Database, Columns...>;
@ -224,13 +224,13 @@ namespace sqlpp
interpret_tuple(t._columns, ',', context);
if (T::size::value and not t._dynamic_columns.empty())
context << ',';
interpret(t._dynamic_columns, context);
serialize(t._dynamic_columns, context);
return context;
}
};
template<typename Context>
struct interpreter_t<Context, no_select_column_list_t>
struct serializer_t<Context, no_select_column_list_t>
{
using T = no_select_column_list_t;

View File

@ -81,7 +81,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Flags>
struct interpreter_t<Context, select_flag_list_t<Database, Flags...>>
struct serializer_t<Context, select_flag_list_t<Database, Flags...>>
{
using T = select_flag_list_t<Database, Flags...>;
@ -98,7 +98,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_select_flag_list_t>
struct serializer_t<Context, no_select_flag_list_t>
{
using T = no_select_flag_list_t;

View File

@ -68,13 +68,13 @@ namespace sqlpp
namespace vendor
{
template<typename Context, typename Select, typename... NamedExpr>
struct interpreter_t<Context, select_pseudo_table_t<Select, NamedExpr...>>
struct serializer_t<Context, select_pseudo_table_t<Select, NamedExpr...>>
{
using T = select_pseudo_table_t<Select, NamedExpr...>;
static Context& _(const T& t, Context& context)
{
interpret(t._select, context);
serialize(t._select, context);
return context;
}
};

48
include/sqlpp11/vendor/serializer.h vendored Normal file
View File

@ -0,0 +1,48 @@
/*
* 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_VENDOR_SERIALIZER_H
#define SQLPP_VENDOR_SERIALIZER_H
#include <sqlpp11/vendor/wrong.h>
namespace sqlpp
{
namespace vendor
{
template<typename Context, typename T, typename Enable = void>
struct serializer_t
{
static void _(const T& t, Context& context)
{
static_assert(wrong_t<Context, T>::value, "missing serializer specialization");
}
};
}
}
#endif

View File

@ -27,7 +27,7 @@
#ifndef SQLPP_SIMPLE_COLUMN_H
#define SQLPP_SIMPLE_COLUMN_H
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/vendor/serializer.h>
namespace sqlpp
{
@ -40,7 +40,7 @@ namespace sqlpp
};
template<typename Context, typename Column>
struct interpreter_t<Context, simple_column_t<Column>>
struct serializer_t<Context, simple_column_t<Column>>
{
using T = simple_column_t<Column>;

View File

@ -63,13 +63,13 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename Table>
struct interpreter_t<Context, single_table_t<Database, Table>>
struct serializer_t<Context, single_table_t<Database, Table>>
{
using T = single_table_t<Database, Table>;
static Context& _(const T& t, Context& context)
{
interpret(t._table, context);
serialize(t._table, context);
return context;
}
};

View File

@ -88,7 +88,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Assignments>
struct interpreter_t<Context, update_list_t<Database, Assignments...>>
struct serializer_t<Context, update_list_t<Database, Assignments...>>
{
using T = update_list_t<Database, Assignments...>;
@ -104,7 +104,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_update_list_t>
struct serializer_t<Context, no_update_list_t>
{
using T = no_update_list_t;

View File

@ -81,7 +81,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Tables>
struct interpreter_t<Context, using_t<Database, Tables...>>
struct serializer_t<Context, using_t<Database, Tables...>>
{
using T = using_t<Database, Tables...>;
@ -99,7 +99,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_using_t>
struct serializer_t<Context, no_using_t>
{
using T = no_using_t;

View File

@ -104,7 +104,7 @@ namespace sqlpp
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct interpreter_t<Context, where_t<Database, Expressions...>>
struct serializer_t<Context, where_t<Database, Expressions...>>
{
using T = where_t<Database, Expressions...>;
@ -122,7 +122,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, where_t<void, bool>>
struct serializer_t<Context, where_t<void, bool>>
{
using T = where_t<void, bool>;
@ -135,7 +135,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, no_where_t>
struct serializer_t<Context, no_where_t>
{
using T = no_where_t;

View File

@ -28,7 +28,7 @@
#define SQLPP_DETAIL_WRAP_OPERAND_H
#include <string>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/vendor/serializer.h>
#include <sqlpp11/detail/type_set.h>
namespace sqlpp
@ -70,7 +70,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, boolean_operand>
struct serializer_t<Context, boolean_operand>
{
using Operand = boolean_operand;
@ -108,7 +108,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, integral_operand>
struct serializer_t<Context, integral_operand>
{
using Operand = integral_operand;
@ -147,7 +147,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, floating_point_operand>
struct serializer_t<Context, floating_point_operand>
{
using Operand = floating_point_operand;
@ -185,7 +185,7 @@ namespace sqlpp
};
template<typename Context>
struct interpreter_t<Context, text_operand>
struct serializer_t<Context, text_operand>
{
using Operand = text_operand;

View File

@ -68,7 +68,7 @@ namespace sqlpp
namespace vendor
{
template<typename Context>
struct interpreter_t<Context, verbatim_table_t>
struct serializer_t<Context, verbatim_table_t>
{
using T = verbatim_table_t;

View File

@ -30,7 +30,7 @@
#include <iostream>
DbMock db;
DbMock::_context_t printer(std::cerr);
DbMock::_serializer_context_t printer(std::cerr);
int main()
{
@ -58,16 +58,16 @@ int main()
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
interpret(insert_into(t).default_values(), printer).flush();
interpret(insert_into(t), printer).flush();
interpret(insert_into(t).set(t.beta = "kirschauflauf"), printer).flush();
interpret(insert_into(t).columns(t.beta), printer).flush();
serialize(insert_into(t).default_values(), printer).flush();
serialize(insert_into(t), printer).flush();
serialize(insert_into(t).set(t.beta = "kirschauflauf"), printer).flush();
serialize(insert_into(t).columns(t.beta), printer).flush();
auto multi_insert = insert_into(t).columns(t.beta, t.delta);
multi_insert.add_values(t.beta = "cheesecake", t.delta = 1);
multi_insert.add_values(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value);
auto i = dynamic_insert_into(db, t).dynamic_set();
i.add_set(t.beta = "kirschauflauf");
interpret(i, printer).flush();
serialize(i, printer).flush();
return 0;
}

View File

@ -35,7 +35,7 @@
#include <iostream>
DbMock db = {};
DbMock::_context_t printer(std::cerr);
DbMock::_serializer_context_t printer(std::cerr);
SQLPP_ALIAS_PROVIDER(kaesekuchen);
int main()
@ -43,122 +43,122 @@ int main()
test::TabFoo f;
test::TabBar t;
interpret(insert_into(t).columns(t.beta, t.gamma), printer).flush();
serialize(insert_into(t).columns(t.beta, t.gamma), printer).flush();
{
auto i = insert_into(t).columns(t.gamma, t.beta);
i.add_values(t.gamma = true, t.beta = "cheesecake");
interpret(i, printer).flush();
serialize(i, printer).flush();
i.add_values(t.gamma = false, t.beta = sqlpp::tvin("coffee"));
i.add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string()));
interpret(i, printer).flush();
serialize(i, printer).flush();
i.add_values(t.gamma = sqlpp::default_value, t.beta = sqlpp::null);
interpret(i, printer).flush();
serialize(i, printer).flush();
}
interpret(t.alpha = sqlpp::null, printer).flush();
interpret(t.alpha = sqlpp::default_value, printer).flush();
interpret(t.alpha, printer).flush();
interpret(-t.alpha, printer).flush();
interpret(+t.alpha, printer).flush();
interpret(-(t.alpha + 7), printer).flush();
interpret(t.alpha = 0, printer).flush();
interpret(t.alpha = sqlpp::tvin(0), printer).flush();
interpret(t.alpha == 0, printer).flush();
interpret(t.alpha == sqlpp::tvin(0), printer).flush();
interpret(t.alpha != 0, printer).flush();
interpret(t.gamma != sqlpp::tvin(false), printer).flush();
interpret(t.alpha == 7, printer).flush();
interpret(t.beta + "kaesekuchen", printer).flush();
serialize(t.alpha = sqlpp::null, printer).flush();
serialize(t.alpha = sqlpp::default_value, printer).flush();
serialize(t.alpha, printer).flush();
serialize(-t.alpha, printer).flush();
serialize(+t.alpha, printer).flush();
serialize(-(t.alpha + 7), printer).flush();
serialize(t.alpha = 0, printer).flush();
serialize(t.alpha = sqlpp::tvin(0), printer).flush();
serialize(t.alpha == 0, printer).flush();
serialize(t.alpha == sqlpp::tvin(0), printer).flush();
serialize(t.alpha != 0, printer).flush();
serialize(t.gamma != sqlpp::tvin(false), printer).flush();
serialize(t.alpha == 7, printer).flush();
serialize(t.beta + "kaesekuchen", printer).flush();
interpret(sqlpp::select(), printer).flush();
interpret(sqlpp::select().flags(sqlpp::distinct), printer).flush();
interpret(select(t.alpha, t.beta).flags(sqlpp::distinct), printer).flush();
interpret(select(t.alpha, t.beta), printer).flush();
interpret(select(t.alpha, t.beta).from(t), printer).flush();
interpret(select(t.alpha, t.beta).from(t).where(t.alpha == 3), printer).flush();
interpret(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).flush();
interpret(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")), printer).flush();
interpret(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")).order_by(t.beta.asc()), printer).flush();
interpret(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")).order_by(t.beta.asc()).limit(17).offset(3), printer).flush();
serialize(sqlpp::select(), printer).flush();
serialize(sqlpp::select().flags(sqlpp::distinct), printer).flush();
serialize(select(t.alpha, t.beta).flags(sqlpp::distinct), printer).flush();
serialize(select(t.alpha, t.beta), printer).flush();
serialize(select(t.alpha, t.beta).from(t), printer).flush();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3), printer).flush();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).flush();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")), printer).flush();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")).order_by(t.beta.asc()), printer).flush();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")).order_by(t.beta.asc()).limit(17).offset(3), printer).flush();
interpret(parameter(sqlpp::bigint(), t.alpha), printer).flush();
interpret(parameter(t.alpha), printer).flush();
interpret(t.alpha == parameter(t.alpha), printer).flush();
interpret(t.alpha == parameter(t.alpha) and (t.beta + "gimmick").like(parameter(t.beta)), printer).flush();
serialize(parameter(sqlpp::bigint(), t.alpha), printer).flush();
serialize(parameter(t.alpha), printer).flush();
serialize(t.alpha == parameter(t.alpha), printer).flush();
serialize(t.alpha == parameter(t.alpha) and (t.beta + "gimmick").like(parameter(t.beta)), printer).flush();
interpret(insert_into(t), printer).flush();
interpret(insert_into(f).default_values(), printer).flush();
interpret(insert_into(t).set(t.gamma = true), printer).flush();
//interpret(insert_into(t).set(t.gamma = sqlpp::tvin(false)), printer).flush(); cannot test this since gamma cannot be null and a static assert is thrown
serialize(insert_into(t), printer).flush();
serialize(insert_into(f).default_values(), printer).flush();
serialize(insert_into(t).set(t.gamma = true), printer).flush();
//serialize(insert_into(t).set(t.gamma = sqlpp::tvin(false)), printer).flush(); cannot test this since gamma cannot be null and a static assert is thrown
interpret(update(t), printer).flush();
interpret(update(t).set(t.gamma = true), printer).flush();
interpret(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).flush();
serialize(update(t), printer).flush();
serialize(update(t).set(t.gamma = true), printer).flush();
serialize(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).flush();
interpret(remove_from(t), printer).flush();
interpret(remove_from(t).using_(t), printer).flush();
interpret(remove_from(t).where(t.alpha == sqlpp::tvin(0)), printer).flush();
interpret(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).flush();
serialize(remove_from(t), printer).flush();
serialize(remove_from(t).using_(t), printer).flush();
serialize(remove_from(t).where(t.alpha == sqlpp::tvin(0)), printer).flush();
serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).flush();
// functions
sqlpp::interpret(sqlpp::value(7), printer).flush(); // FIXME: Why is the namespace specifier required?
interpret(sqlpp::verbatim<sqlpp::detail::integral>("irgendwas integrales"), printer).flush();
interpret(sqlpp::value_list(std::vector<int>({1,2,3,4,5,6,8})), printer).flush();
interpret(exists(select(t.alpha).from(t)), printer).flush();
interpret(any(select(t.alpha).from(t)), printer).flush();
interpret(some(select(t.alpha).from(t)), printer).flush();
interpret(count(t.alpha), printer).flush();
interpret(min(t.alpha), printer).flush();
interpret(max(t.alpha), printer).flush();
interpret(avg(t.alpha), printer).flush();
interpret(sum(t.alpha), printer).flush();
interpret(sqlpp::verbatim_table("whatever"), printer).flush();
serialize(sqlpp::value(7), printer).flush();
serialize(sqlpp::verbatim<sqlpp::detail::integral>("irgendwas integrales"), printer).flush();
serialize(sqlpp::value_list(std::vector<int>({1,2,3,4,5,6,8})), printer).flush();
serialize(exists(select(t.alpha).from(t)), printer).flush();
serialize(any(select(t.alpha).from(t)), printer).flush();
serialize(some(select(t.alpha).from(t)), printer).flush();
serialize(count(t.alpha), printer).flush();
serialize(min(t.alpha), printer).flush();
serialize(max(t.alpha), printer).flush();
serialize(avg(t.alpha), printer).flush();
serialize(sum(t.alpha), printer).flush();
serialize(sqlpp::verbatim_table("whatever"), printer).flush();
// alias
interpret(t.as(t.alpha), printer).flush();
interpret(t.as(t.alpha).beta, printer).flush();
serialize(t.as(t.alpha), printer).flush();
serialize(t.as(t.alpha).beta, printer).flush();
// select alias
interpret(select(t.alpha).from(t).where(t.beta > "kaesekuchen").as(t.gamma), printer).flush();
serialize(select(t.alpha).from(t).where(t.beta > "kaesekuchen").as(t.gamma), printer).flush();
interpret(t.alpha.is_null(), printer).flush();
serialize(t.alpha.is_null(), printer).flush();
// join
interpret(t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta), printer).flush();
serialize(t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta), printer).flush();
// multi_column
interpret(multi_column(t.alpha, (t.beta + "cake").as(t.gamma)).as(t.alpha), printer).flush();
interpret(multi_column(all_of(t)).as(t), printer).flush();
interpret(all_of(t).as(t), printer).flush();
serialize(multi_column(t.alpha, (t.beta + "cake").as(t.gamma)).as(t.alpha), printer).flush();
serialize(multi_column(all_of(t)).as(t), printer).flush();
serialize(all_of(t).as(t), printer).flush();
// dynamic select
{
auto s = dynamic_select(db).dynamic_flags().dynamic_columns();
s.add_column(t.beta);
s.add_column(t.gamma);
interpret(s, printer).flush();
serialize(s, printer).flush();
}
{
auto s = dynamic_select(db).dynamic_flags().dynamic_columns();
s.add_flag(sqlpp::distinct);
s.add_column(t.beta);
s.add_column(t.gamma);
interpret(s, printer).flush();
serialize(s, printer).flush();
}
{
auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha);
s.add_flag(sqlpp::all);
s.add_column(t.beta);
s.add_column(t.gamma);
interpret(s, printer).flush();
serialize(s, printer).flush();
}
// distinct aggregate
interpret(count(sqlpp::distinct, t.alpha % 7), printer).flush();
interpret(avg(sqlpp::distinct, t.alpha - 7), printer).flush();
interpret(sum(sqlpp::distinct, t.alpha + 7), printer).flush();
serialize(count(sqlpp::distinct, t.alpha % 7), printer).flush();
serialize(avg(sqlpp::distinct, t.alpha - 7), printer).flush();
serialize(sum(sqlpp::distinct, t.alpha + 7), printer).flush();
interpret(select(all_of(t)).from(t).where(true), printer).flush();
interpret(select(all_of(t)).from(t).where(false), printer).flush();
serialize(select(all_of(t)).from(t).where(true), printer).flush();
serialize(select(all_of(t)).from(t).where(false), printer).flush();
return 0;
}

View File

@ -27,14 +27,29 @@
#define SQLPP_MOCK_DB_H
#include <sqlpp11/connection.h>
#include <sqlpp11/serializer.h>
#include <sqlpp11/serializer_context.h>
#include <sqlpp11/serialize.h>
struct DbMock: public sqlpp::connection
{
struct _context_t : public sqlpp::serializer_t
struct _serializer_context_t : public sqlpp::serializer_context_t
{
_context_t(std::ostream& os): sqlpp::serializer_t(os) {}
_serializer_context_t(std::ostream& os): sqlpp::serializer_context_t(os) {}
};
using _interpreter_context_t = _serializer_context_t;
template<typename T>
static _serializer_context_t& _serialize_interpretable(const T& t, _serializer_context_t& context)
{
return ::sqlpp::serialize(t, context);
}
template<typename T>
static _interpreter_context_t& _interpret_interpretable(const T& t, _interpreter_context_t& context)
{
return ::sqlpp::serialize(t, context);
}
};
#endif

View File

@ -31,7 +31,7 @@
DbMock db;
DbMock::_context_t printer(std::cerr);
DbMock::_serializer_context_t printer(std::cerr);
int main()
{
@ -56,13 +56,13 @@ int main()
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
interpret(remove_from(t), printer).flush();
interpret(remove_from(t).where(t.beta != "transparent"), printer).flush();
interpret(remove_from(t).using_(t), printer).flush();
serialize(remove_from(t), printer).flush();
serialize(remove_from(t).where(t.beta != "transparent"), printer).flush();
serialize(remove_from(t).using_(t), printer).flush();
auto r = dynamic_remove_from(db, t).dynamic_using().dynamic_where();
r.add_using(t);
r.add_where(t.beta != "transparent");
interpret(r, printer).flush();
serialize(r, printer).flush();
return 0;
}

View File

@ -34,7 +34,7 @@
DbMock db = {};
DbMock::_context_t printer(std::cerr);
DbMock::_serializer_context_t printer(std::cerr);
namespace alias
{
@ -311,7 +311,7 @@ int main()
s.set_limit(30);
s.set_limit(3);
std::cerr << "------------------------\n";
interpret(s, printer).flush();
serialize(s, printer).flush();
std::cerr << "------------------------\n";
using T = decltype(s);
static_assert(sqlpp::is_regular<T>::value, "type requirement");
@ -321,13 +321,13 @@ int main()
{
auto s = dynamic_select(db).dynamic_columns();
s.add_column(t.alpha);
interpret(s, printer).flush();
serialize(s, printer).flush();
}
// Test that verbatim_table compiles
{
auto s = select(t.alpha).from(sqlpp::verbatim_table("my_unknown_table"));
interpret(s, printer).flush();
serialize(s, printer).flush();
}
@ -344,9 +344,9 @@ int main()
auto y = t.gamma and true and t.gamma;
!t.gamma;
t.beta < "kaesekuchen";
interpret(t.beta + "hallenhalma", printer).flush();
serialize(t.beta + "hallenhalma", printer).flush();
static_assert(sqlpp::must_not_insert_t<decltype(t.alpha)>::value, "alpha must not be inserted");
interpret(t.alpha, printer).flush();
serialize(t.alpha, printer).flush();
std::cerr << "\n" << sizeof(test::TabBar) << std::endl;
static_assert(std::is_same<typename decltype(t.alpha)::_value_type::_is_named_expression, std::true_type>::value, "alpha should be a named expression");
static_assert(sqlpp::is_named_expression_t<decltype(t.alpha)>::value, "alpha should be a named expression");
@ -356,7 +356,7 @@ int main()
auto l = t.as(alias::left);
auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right);
static_assert(sqlpp::is_boolean_t<decltype(select(t.gamma).from(t))>::value, "select(bool) has to be a bool");
interpret(sqlpp::select().flags(sqlpp::distinct, sqlpp::straight_join).columns(l.alpha, l.beta, select(r.a).from(r))
serialize(sqlpp::select().flags(sqlpp::distinct, sqlpp::straight_join).columns(l.alpha, l.beta, select(r.a).from(r))
.from(l, r)
.where(t.beta == "hello world" and select(t.gamma).from(t))// .as(alias::right))
.group_by(l.gamma, r.a)

View File

@ -30,7 +30,7 @@
#include "is_regular.h"
DbMock db;
DbMock::_context_t printer(std::cerr);
DbMock::_serializer_context_t printer(std::cerr);
int main()
{
@ -56,13 +56,13 @@ int main()
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
interpret(update(t), printer).flush();
interpret(update(t).set(t.gamma = false), printer).flush();
interpret(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).flush();
interpret(update(t).set(t.beta = "opaque").where(t.beta != t.beta), printer).flush();
serialize(update(t), printer).flush();
serialize(update(t).set(t.gamma = false), printer).flush();
serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).flush();
serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta), printer).flush();
auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where();
u.add_set(t.gamma = false);
interpret(u, printer).flush();
serialize(u, printer).flush();
return 0;
}