Made no_value to a more complete value type

This allows to select NULL via a case statement (seems to make more
sense than disallowing it).
This commit is contained in:
rbock
2015-12-23 16:01:45 +01:00
parent 3efae18e08
commit b41f1add8c
28 changed files with 340 additions and 42 deletions

View File

@@ -83,7 +83,7 @@ namespace sqlpp
auto _else_impl(const std::true_type&, Else else_) -> case_t<When, Then, Else>
{
return {_when, _then, else_};
};
}
template <typename Else>
auto _else_impl(const std::false_type&, Else else_) -> void;
@@ -105,7 +105,7 @@ namespace sqlpp
static_assert(detail::valid_else_t<Then, Else>::value,
"arguments of then and else must be expressions of the same type (or null)");
return _else_impl(detail::valid_else_t<Then, Else>{}, else_);
};
}
private:
When _when;
@@ -119,7 +119,7 @@ namespace sqlpp
auto _then_impl(const std::true_type&, Then t) -> case_then_t<When, wrap_operand_t<Then>>
{
return {_when, t};
};
}
template <typename Then>
auto _then_impl(const std::false_type&, Then t) -> void;
@@ -140,7 +140,7 @@ namespace sqlpp
{
static_assert(detail::valid_then_t<Then>::value, "then argument must be a value expression");
return _then_impl(detail::valid_then_t<Then>{}, t);
};
}
private:
When _when;

View File

@@ -33,5 +33,6 @@
#include <sqlpp11/data_types/text.h>
#include <sqlpp11/data_types/day_point.h>
#include <sqlpp11/data_types/time_point.h>
#include <sqlpp11/data_types/no_value.h>
#endif

View File

@@ -27,26 +27,12 @@
#ifndef SQLPP_NO_VALUE_H
#define SQLPP_NO_VALUE_H
#include <type_traits>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/data_types/column_operators.h>
#include <sqlpp11/data_types/no_value/data_type.h>
#include <sqlpp11/data_types/no_value/operand.h>
#include <sqlpp11/data_types/no_value/wrap_operand.h>
#include <sqlpp11/data_types/no_value/expression_operators.h>
#include <sqlpp11/data_types/no_value/column_operators.h>
#include <sqlpp11/data_types/no_value/parameter_value.h>
#include <sqlpp11/data_types/no_value/result_field.h>
namespace sqlpp
{
struct no_value_t
{
using _traits = make_traits<no_value_t>;
using _cpp_value_type = void;
};
template <typename Base>
struct expression_operators<Base, no_value_t>
{
};
template <typename Base>
struct column_operators<Base, no_value_t>
{
};
}
#endif

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2013-2015, 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_NO_VALUE_COLUMN_OPERATORS_H
#define SQLPP_NO_VALUE_COLUMN_OPERATORS_H
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
struct no_value_t;
template <typename Base>
struct column_operators<Base, no_value_t>
{
};
}
#endif

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2013-2015, 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_NO_VALUE_DATA_TYPE_H
#define SQLPP_NO_VALUE_DATA_TYPE_H
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct no_value_t
{
using _traits = make_traits<no_value_t>;
using _cpp_value_type = void;
template <typename T>
using _is_valid_operand = wrong_t<T>;
};
}
#endif

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013-2015, 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_NO_VALUE_EXPRESSION_OPERATORS_H
#define SQLPP_NO_VALUE_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_return_types.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
namespace sqlpp
{
template <typename Expression>
struct expression_operators<Expression, no_value_t> : public basic_expression_operators<Expression, no_value_t>
{
};
}
#endif

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2013-2015, 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_NO_VALUE_OPERAND_H
#define SQLPP_NO_VALUE_OPERAND_H
namespace sqlpp
{
// There is no no_value operand
}
#endif

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2013-2015, 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_NO_VALUE_PARAMETER_VALUE_H
#define SQLPP_NO_VALUE_PARAMETER_VALUE_H
namespace sqlpp
{
// There is no no_value parameter
}
#endif

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2013-2015, 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_NO_VALUE_RESULT_FIELD_H
#define SQLPP_NO_VALUE_RESULT_FIELD_H
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/no_value/data_type.h>
#include <sqlpp11/field_spec.h>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, no_value_t, CanBeNull, NullIsTrivialValue>>
{
template <typename Target>
void _bind(Target&, size_t)
{
}
template <typename Target>
void _post_bind(Target&, size_t)
{
}
void _validate() const
{
}
void _invalidate() const
{
}
constexpr bool is_null() const
{
return true;
}
};
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
inline std::ostream& operator<<(
std::ostream& os, const result_field_t<Db, field_spec_t<NameType, no_value_t, CanBeNull, NullIsTrivialValue>>&)
{
os << "NULL";
return os;
}
}
#endif

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2013-2015, 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_NO_VALUE_WRAP_OPERAND_H
#define SQLPP_NO_VALUE_WRAP_OPERAND_H
namespace sqlpp
{
// There is no no_value operand
}
#endif

View File

@@ -27,7 +27,7 @@
#ifndef SQLPP_DEFAULT_VALUE_H
#define SQLPP_DEFAULT_VALUE_H
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -29,7 +29,7 @@
#include <sqlpp11/statement_fwd.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
#include <sqlpp11/no_data.h>
#include <sqlpp11/prepared_insert.h>
#include <sqlpp11/serializer.h>

View File

@@ -27,7 +27,6 @@
#ifndef SQLPP_MULTI_COLUMN_H
#define SQLPP_MULTI_COLUMN_H
#include <sqlpp11/no_value.h>
#include <sqlpp11/logic.h>
#include <sqlpp11/detail/type_set.h>
@@ -35,6 +34,8 @@
namespace sqlpp
{
struct no_value_t;
template <typename AliasProvider, typename... Columns>
struct multi_column_alias_t;

View File

@@ -28,7 +28,7 @@
#define SQLPP_NOOP_H
#include <type_traits>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
#include <sqlpp11/serializer.h>
#include <sqlpp11/prepared_execute.h>

View File

@@ -27,7 +27,7 @@
#ifndef SQLPP_NULL_H
#define SQLPP_NULL_H
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -29,7 +29,7 @@
#include <sqlpp11/parameter_list.h>
#include <sqlpp11/result.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -29,7 +29,7 @@
#include <sqlpp11/parameter_list.h>
#include <sqlpp11/result.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -29,7 +29,7 @@
#include <sqlpp11/parameter_list.h>
#include <sqlpp11/result.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -29,7 +29,7 @@
#include <sqlpp11/parameter_list.h>
#include <sqlpp11/result.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -29,7 +29,7 @@
#include <sqlpp11/parameter_list.h>
#include <sqlpp11/result.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -30,7 +30,7 @@
#include <tuple>
#include <sqlpp11/result_row.h>
#include <sqlpp11/table.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
#include <sqlpp11/field_spec.h>
#include <sqlpp11/expression_fwd.h>
#include <sqlpp11/select_pseudo_table.h>

View File

@@ -27,7 +27,7 @@
#ifndef SQLPP_SELECT_PSEUDO_TABLE_H
#define SQLPP_SELECT_PSEUDO_TABLE_H
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -28,7 +28,7 @@
#define SQLPP_SINGLE_TABLE_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
#include <sqlpp11/no_data.h>
#include <sqlpp11/serializer.h>
#include <sqlpp11/prepared_insert.h>

View File

@@ -33,7 +33,7 @@
#include <sqlpp11/column.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/join.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -27,7 +27,7 @@
#ifndef SQLPP_VERBATIM_H
#define SQLPP_VERBATIM_H
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/serialize.h>

View File

@@ -27,7 +27,7 @@
#ifndef SQLPP_VERBATIM_TABLE_H
#define SQLPP_VERBATIM_TABLE_H
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
namespace sqlpp
{

View File

@@ -29,7 +29,7 @@
#include <sstream>
#include <iostream>
#include <sqlpp11/schema.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/data_types/no_value.h>
#include <sqlpp11/serialize.h>
#include <sqlpp11/serializer_context.h>
#include <sqlpp11/connection.h>

View File

@@ -164,5 +164,11 @@ int Select(int, char**)
select(sqlpp::value(7).as(t.alpha));
for (const auto& row :
db(select(sqlpp::case_when(true).then(sqlpp::null).else_(sqlpp::null).as(t.beta)).from(t).where(true)))
{
std::cerr << row.beta << std::endl;
}
return 0;
}