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

Updated joins and updated columns to work with sqlite3

The new behaviour is closer to the standard, I think
This commit is contained in:
rbock 2014-01-27 11:45:46 +01:00
parent d4d8429947
commit 471dffebc0
5 changed files with 73 additions and 28 deletions

View File

@ -77,13 +77,15 @@ namespace sqlpp
template<typename JoinType, typename Lhs, typename Rhs, typename On = vendor::noop>
struct join_t
{
static_assert(is_table_t<Lhs>::value, "invalid lhs argument for join()");
static_assert(is_table_t<Rhs>::value, "invalid rhs argument for join()");
static_assert(is_table_t<Lhs>::value, "lhs argument for join() has to be a table or join");
static_assert(is_table_t<Rhs>::value, "rhs argument for join() has to be a table");
static_assert(not is_join_t<Rhs>::value, "rhs argument for join must not be a join");
static_assert(vendor::is_noop<On>::value or is_on_t<On>::value, "invalid on expression in join().on()");
static_assert(Lhs::_table_set::template is_disjunct_from<typename Rhs::_table_set>::value, "joined tables must not be identical");
using _is_table = std::true_type;
using _is_join = std::true_type;
using _table_set = typename Lhs::_table_set::template join<typename Rhs::_table_set>::type;
template<typename OnT>
@ -140,7 +142,6 @@ namespace sqlpp
On _on;
};
// FIXME: Need to check if db supports the join type. e.g. sqlite does not support right outer or full outer join
namespace vendor
{
template<typename Context, typename JoinType, typename Lhs, typename Rhs, typename On>
@ -154,9 +155,7 @@ namespace sqlpp
interpret(t._lhs, context);
context << JoinType::_name;
context << " JOIN ";
context << "(";
interpret(t._rhs, context);
context << ")";
interpret(t._on, context);
return context;
}

View File

@ -94,6 +94,7 @@ namespace sqlpp
SQLPP_IS_COLUMN_TRAIT_GENERATOR(can_be_null);
SQLPP_TYPE_TRAIT_GENERATOR(is_table);
SQLPP_TYPE_TRAIT_GENERATOR(is_join);
SQLPP_TYPE_TRAIT_GENERATOR(is_pseudo_table);
SQLPP_TYPE_TRAIT_GENERATOR(is_column);
SQLPP_TYPE_TRAIT_GENERATOR(is_select);

View File

@ -31,6 +31,7 @@
#include <sqlpp11/null.h>
#include <sqlpp11/tvin.h>
#include <sqlpp11/vendor/interpreter.h>
#include <sqlpp11/vendor/simple_column.h>
namespace sqlpp
{
@ -68,7 +69,7 @@ namespace sqlpp
static Context& _(const T& t, Context& context)
{
interpret(t._lhs, context);
interpret(simple_column(t._lhs), context);
context << "=";
interpret(t._rhs, context);
return context;
@ -107,7 +108,7 @@ namespace sqlpp
static Context& _(const T& t, Context& context)
{
interpret(t._lhs, context);
interpret(simple_column(t._lhs), context);
if (t._rhs._value._is_trivial())
{
context << "=NULL";

View File

@ -31,6 +31,7 @@
#include <sqlpp11/detail/set.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/vendor/simple_column.h>
namespace sqlpp
{
@ -54,25 +55,6 @@ namespace sqlpp
}
};
template<typename Column>
struct insert_column_t
{
Column _column;
};
template<typename Context, typename Column>
struct interpreter_t<Context, insert_column_t<Column>>
{
using T = insert_column_t<Column>;
static Context& _(const T& t, Context& context)
{
context << t._column._get_name();
return context;
}
};
template<typename Database, typename... Assignments>
struct insert_list_t
{
@ -110,12 +92,12 @@ namespace sqlpp
{
static_assert(is_assignment_t<typename std::decay<Assignment>::type>::value, "set() arguments require to be assigments");
static_assert(not must_not_insert_t<typename std::decay<Assignment>::type>::value, "set() argument must not be used in insert");
_dynamic_columns.emplace_back(insert_column_t<typename Assignment::_column_t>{std::forward<typename Assignment::_column_t>(assignment._lhs)});
_dynamic_columns.emplace_back(simple_column_t<typename Assignment::_column_t>{std::forward<typename Assignment::_column_t>(assignment._lhs)});
_dynamic_values.emplace_back(std::forward<typename Assignment::value_type>(assignment._rhs));
}
std::tuple<insert_column_t<typename Assignments::_column_t>...> _columns;
std::tuple<simple_column_t<typename Assignments::_column_t>...> _columns;
std::tuple<typename Assignments::value_type...> _values;
typename vendor::interpretable_list_t<Database> _dynamic_columns;
typename vendor::interpretable_list_t<Database> _dynamic_values;

62
include/sqlpp11/vendor/simple_column.h vendored Normal file
View File

@ -0,0 +1,62 @@
/*
* 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_SIMPLE_COLUMN_H
#define SQLPP_SIMPLE_COLUMN_H
#include <sqlpp11/vendor/interpreter.h>
namespace sqlpp
{
namespace vendor
{
template<typename Column>
struct simple_column_t
{
Column _column;
};
template<typename Context, typename Column>
struct interpreter_t<Context, simple_column_t<Column>>
{
using T = simple_column_t<Column>;
static Context& _(const T& t, Context& context)
{
context << t._column._get_name();
return context;
}
};
template<typename Column>
simple_column_t<Column> simple_column(Column c)
{
return {c};
}
}
}
#endif