mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Add blob data type
This commit is contained in:
parent
78c6bc0670
commit
1e029807da
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
|
||||
* Copyright (c) 2013-2017, Roland Bock, Aaron Bishop
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -27,6 +27,7 @@
|
||||
#ifndef SQLPP11_DATA_TYPES_H
|
||||
#define SQLPP11_DATA_TYPES_H
|
||||
|
||||
#include <sqlpp11/data_types/blob.h>
|
||||
#include <sqlpp11/data_types/boolean.h>
|
||||
#include <sqlpp11/data_types/integral.h>
|
||||
#include <sqlpp11/data_types/unsigned_integral.h>
|
||||
|
42
include/sqlpp11/data_types/blob.h
Normal file
42
include/sqlpp11/data_types/blob.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_H
|
||||
#define SQLPP_BLOB_H
|
||||
|
||||
#include <sqlpp11/data_types/blob/data_type.h>
|
||||
#include <sqlpp11/data_types/blob/operand.h>
|
||||
#include <sqlpp11/data_types/blob/wrap_operand.h>
|
||||
#include <sqlpp11/data_types/blob/expression_operators.h>
|
||||
#include <sqlpp11/data_types/blob/column_operators.h>
|
||||
#include <sqlpp11/data_types/blob/parameter_value.h>
|
||||
#include <sqlpp11/data_types/blob/result_field.h>
|
||||
|
||||
// blob specific functions
|
||||
#include <sqlpp11/data_types/text/like.h>
|
||||
#include <sqlpp11/data_types/text/concat.h>
|
||||
|
||||
#endif
|
57
include/sqlpp11/data_types/blob/column_operators.h
Normal file
57
include/sqlpp11/data_types/blob/column_operators.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_COLUMN_OPERATORS_H
|
||||
#define SQLPP_BLOB_COLUMN_OPERATORS_H
|
||||
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/assignment.h>
|
||||
#include <sqlpp11/data_types/blob/data_type.h>
|
||||
#include <sqlpp11/data_types/column_operators.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename... Args>
|
||||
struct concat_t;
|
||||
|
||||
template <typename Column>
|
||||
struct column_operators<Column, blob>
|
||||
{
|
||||
template <typename T>
|
||||
using _is_valid_operand = is_valid_operand<blob, T>;
|
||||
|
||||
template <typename T>
|
||||
auto operator+=(T t) const -> assignment_t<Column, concat_t<Column, wrap_operand_t<T>>>
|
||||
{
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
||||
|
||||
return {*static_cast<const Column*>(this),
|
||||
concat_t<Column, wrap_operand_t<T>>{*static_cast<const Column*>(this), rhs{t}}};
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
47
include/sqlpp11/data_types/blob/data_type.h
Normal file
47
include/sqlpp11/data_types/blob/data_type.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_DATA_TYPE_H
|
||||
#define SQLPP_BLOB_DATA_TYPE_H
|
||||
|
||||
#include <vector>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
struct blob
|
||||
{
|
||||
using _traits = make_traits<blob, tag::is_value_type>;
|
||||
using _cpp_value_type = std::vector<std::uint8_t>;
|
||||
|
||||
template <typename T>
|
||||
using _is_valid_operand = is_blob_t<T>;
|
||||
};
|
||||
|
||||
using blob = blob;
|
||||
using mediumblob = blob;
|
||||
}
|
||||
#endif
|
63
include/sqlpp11/data_types/blob/expression_operators.h
Normal file
63
include/sqlpp11/data_types/blob/expression_operators.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_EXPRESSION_OPERATORS_H
|
||||
#define SQLPP_BLOB_EXPRESSION_OPERATORS_H
|
||||
|
||||
#include <sqlpp11/operand_check.h>
|
||||
#include <sqlpp11/expression_operators.h>
|
||||
#include <sqlpp11/basic_expression_operators.h>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/data_types/blob/data_type.h>
|
||||
#include <sqlpp11/data_types/text/return_type_like.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Operand, typename Pattern>
|
||||
struct like_t;
|
||||
|
||||
template <typename L, typename R>
|
||||
struct return_type_like<L, R, binary_operand_check_t<L, is_blob_t, R, is_blob_t>>
|
||||
{
|
||||
using check = consistent_t;
|
||||
using type = like_t<wrap_operand_t<L>, wrap_operand_t<R>>;
|
||||
};
|
||||
|
||||
template <typename Expression>
|
||||
struct expression_operators<Expression, blob> : public basic_expression_operators<Expression>
|
||||
{
|
||||
template <typename T>
|
||||
using _is_valid_operand = is_valid_operand<blob, T>;
|
||||
|
||||
template <typename R>
|
||||
auto like(const R& r) const -> return_type_like_t<Expression, R>
|
||||
{
|
||||
return_type_like<Expression, R>::check::_();
|
||||
return {*static_cast<const Expression*>(this), wrap_operand_t<R>{r}};
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
89
include/sqlpp11/data_types/blob/operand.h
Normal file
89
include/sqlpp11/data_types/blob/operand.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_OPERAND_H
|
||||
#define SQLPP_BLOB_OPERAND_H
|
||||
|
||||
#include <vector>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/alias_operators.h>
|
||||
#include <sqlpp11/serializer.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
struct blob;
|
||||
|
||||
struct blob_operand : public alias_operators<blob_operand>
|
||||
{
|
||||
using _traits = make_traits<blob, tag::is_expression, tag::is_wrapped_value>;
|
||||
using _nodes = detail::type_vector<>;
|
||||
using _is_aggregate_expression = std::true_type;
|
||||
|
||||
using _value_t = std::vector<std::uint8_t>;
|
||||
|
||||
blob_operand() : _t{}
|
||||
{
|
||||
}
|
||||
|
||||
blob_operand(_value_t t) : _t(t)
|
||||
{
|
||||
}
|
||||
|
||||
blob_operand(const blob_operand&) = default;
|
||||
blob_operand(blob_operand&&) = default;
|
||||
blob_operand& operator=(const blob_operand&) = default;
|
||||
blob_operand& operator=(blob_operand&&) = default;
|
||||
~blob_operand() = default;
|
||||
|
||||
bool _is_trivial() const
|
||||
{
|
||||
return _t.empty();
|
||||
}
|
||||
|
||||
_value_t _t;
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, blob_operand>
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = blob_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
context << "x'";
|
||||
for (const auto c : t._t)
|
||||
{
|
||||
context << hexChars[c >> 4] << hexChars[c & 0x0F];
|
||||
}
|
||||
context << '\'';
|
||||
|
||||
return context;
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
53
include/sqlpp11/data_types/blob/parameter_value.h
Normal file
53
include/sqlpp11/data_types/blob/parameter_value.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_PARAMETER_VALUE_H
|
||||
#define SQLPP_BLOB_PARAMETER_VALUE_H
|
||||
|
||||
#include <sqlpp11/data_types/parameter_value.h>
|
||||
#include <sqlpp11/data_types/parameter_value_base.h>
|
||||
#include <sqlpp11/data_types/blob/data_type.h>
|
||||
#include <sqlpp11/data_types/blob/wrap_operand.h>
|
||||
#include <sqlpp11/data_types/blob/operand.h>
|
||||
#include <sqlpp11/tvin.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <>
|
||||
struct parameter_value_t<blob> : public parameter_value_base<blob>
|
||||
{
|
||||
using base = parameter_value_base<blob>;
|
||||
using base::base;
|
||||
using base::operator=;
|
||||
|
||||
template <typename Target>
|
||||
void _bind(Target& target, size_t index) const
|
||||
{
|
||||
target._bind_blob_parameter(index, &_value, _is_null);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
83
include/sqlpp11/data_types/blob/result_field.h
Normal file
83
include/sqlpp11/data_types/blob/result_field.h
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_RESULT_FIELD_H
|
||||
#define SQLPP_BLOB_RESULT_FIELD_H
|
||||
|
||||
#include <sqlpp11/basic_expression_operators.h>
|
||||
#include <sqlpp11/result_field.h>
|
||||
#include <sqlpp11/result_field_base.h>
|
||||
#include <sqlpp11/data_types/blob/data_type.h>
|
||||
#include <sqlpp11/field_spec.h>
|
||||
#include <ostream>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
|
||||
struct result_field_t<Db, field_spec_t<NameType, blob, CanBeNull, NullIsTrivialValue>>
|
||||
: public result_field_base<Db, field_spec_t<NameType, blob, CanBeNull, NullIsTrivialValue>>
|
||||
{
|
||||
const char* blob{nullptr}; // Non-owning
|
||||
size_t len{};
|
||||
|
||||
template <typename Target>
|
||||
void _bind(Target& target, size_t index)
|
||||
{
|
||||
target._bind_blob_result(index, &blob, &len);
|
||||
if (blob)
|
||||
this->_value.assign(blob, len);
|
||||
else
|
||||
this->_value.assign("");
|
||||
this->_is_null = (blob == nullptr);
|
||||
}
|
||||
|
||||
template <typename Target>
|
||||
void _post_bind(Target& target, size_t index)
|
||||
{
|
||||
target._post_bind_blob_result(index, &blob, &len);
|
||||
if (blob)
|
||||
this->_value.assign(blob, len);
|
||||
else
|
||||
this->_value.assign("");
|
||||
this->_is_null = (blob == nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
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, blob, CanBeNull, NullIsTrivialValue>>& e)
|
||||
{
|
||||
if (e.is_null() and not NullIsTrivialValue)
|
||||
{
|
||||
return os << "NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
return os << e.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
45
include/sqlpp11/data_types/blob/wrap_operand.h
Normal file
45
include/sqlpp11/data_types/blob/wrap_operand.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_BLOB_WRAP_OPERAND_H
|
||||
#define SQLPP_BLOB_WRAP_OPERAND_H
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/wrap_operand.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
struct blob_operand;
|
||||
|
||||
template <>
|
||||
struct wrap_operand<std::vector<std::uint8_t>, void>
|
||||
{
|
||||
using type = blob_operand;
|
||||
};
|
||||
}
|
||||
#endif
|
@ -40,7 +40,6 @@ namespace sqlpp
|
||||
using _is_valid_operand = is_text_t<T>;
|
||||
};
|
||||
|
||||
using blob = text;
|
||||
using varchar = text;
|
||||
using char_ = text;
|
||||
using binary = text;
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <sqlpp11/basic_expression_operators.h>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/data_types/text/data_type.h>
|
||||
#include <sqlpp11/data_types/text/return_type_like.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@ -40,15 +41,6 @@ namespace sqlpp
|
||||
template <typename Operand, typename Pattern>
|
||||
struct like_t;
|
||||
|
||||
template <typename T, typename Defer, typename Enable = void>
|
||||
struct return_type_like
|
||||
{
|
||||
using check = assert_valid_operands;
|
||||
using type = bad_expression<boolean>;
|
||||
};
|
||||
template <typename T, typename Defer>
|
||||
using return_type_like_t = typename return_type_like<T, Defer>::type;
|
||||
|
||||
template <typename L, typename R>
|
||||
struct return_type_like<L, R, binary_operand_check_t<L, is_text_t, R, is_text_t>>
|
||||
{
|
||||
|
44
include/sqlpp11/data_types/text/return_type_like.h
Normal file
44
include/sqlpp11/data_types/text/return_type_like.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2017, 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_RETURN_TYPE_LIKE_H
|
||||
#define SQLPP_RETURN_TYPE_LIKE_H
|
||||
|
||||
#include <sqlpp11/bad_expression.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename T, typename Defer, typename Enable = void>
|
||||
struct return_type_like
|
||||
{
|
||||
using check = assert_valid_operands;
|
||||
using type = bad_expression<boolean>;
|
||||
};
|
||||
template <typename T, typename Defer>
|
||||
using return_type_like_t = typename return_type_like<T, Defer>::type;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
|
||||
* Copyright (c) 2013-2017, Roland Bock, Aaron Bishop
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -63,6 +63,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
// data types
|
||||
struct blob;
|
||||
template <typename T>
|
||||
using is_blob_t = std::is_same<value_type_of<T>, blob>;
|
||||
|
||||
struct boolean;
|
||||
template <typename T>
|
||||
using is_boolean_t = std::is_same<value_type_of<T>, boolean>;
|
||||
|
67
test_serializer/Blob.cpp
Normal file
67
test_serializer/Blob.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.
|
||||
*/
|
||||
|
||||
#include "compare.h"
|
||||
#include "Sample.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
/*
|
||||
auto getTrue() -> std::string
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
return serialize(sqlpp::value(true), printer).str();
|
||||
}
|
||||
*/
|
||||
|
||||
auto getFalse() -> std::string
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
return serialize(sqlpp::value(false), printer).str();
|
||||
}
|
||||
|
||||
auto toByteVector(const std::string& s) -> std::vector<std::uint8_t>
|
||||
{
|
||||
return std::vector<std::uint8_t>(s.begin(), s.end());
|
||||
}
|
||||
}
|
||||
|
||||
int Blob(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
// const auto bar = test::TabBar{};
|
||||
|
||||
// Unconditionally
|
||||
compare(__LINE__, select(foo.book).from(foo).where(foo.book == toByteVector("john doe")),
|
||||
"SELECT tab_foo.book FROM tab_foo WHERE (tab_foo.book=x'6A6F686E20646F65')");
|
||||
|
||||
// Never
|
||||
compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2013-2016, Roland Bock
|
||||
# Copyright (c) 2013-2017, Roland Bock
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -23,14 +23,15 @@
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
set(test_serializer_names
|
||||
CustomQuery
|
||||
As
|
||||
Blob
|
||||
CustomQuery
|
||||
ForUpdate
|
||||
From
|
||||
In
|
||||
Insert
|
||||
TableAlias
|
||||
Where
|
||||
ForUpdate
|
||||
)
|
||||
|
||||
create_test_sourcelist(test_serializer_sources test_serializer_main.cpp ${test_serializer_names})
|
||||
|
@ -36,9 +36,10 @@
|
||||
#include <sstream>
|
||||
|
||||
// an object to store internal Mock flags and values to validate in tests
|
||||
struct InternalMockData {
|
||||
sqlpp::isolation_level _last_isolation_level;
|
||||
sqlpp::isolation_level _default_isolation_level;
|
||||
struct InternalMockData
|
||||
{
|
||||
sqlpp::isolation_level _last_isolation_level;
|
||||
sqlpp::isolation_level _default_isolation_level;
|
||||
};
|
||||
|
||||
template <bool enforceNullResultTreatment>
|
||||
@ -254,7 +255,7 @@ struct MockDbT : public sqlpp::connection
|
||||
|
||||
void start_transaction()
|
||||
{
|
||||
_mock_data._last_isolation_level = _mock_data._default_isolation_level;
|
||||
_mock_data._last_isolation_level = _mock_data._default_isolation_level;
|
||||
}
|
||||
|
||||
void start_transaction(sqlpp::isolation_level level)
|
||||
@ -264,22 +265,25 @@ struct MockDbT : public sqlpp::connection
|
||||
|
||||
void set_default_isolation_level(sqlpp::isolation_level level)
|
||||
{
|
||||
_mock_data._default_isolation_level = level;
|
||||
_mock_data._default_isolation_level = level;
|
||||
}
|
||||
|
||||
sqlpp::isolation_level get_default_isolation_level()
|
||||
{
|
||||
return _mock_data._default_isolation_level;
|
||||
return _mock_data._default_isolation_level;
|
||||
}
|
||||
|
||||
void rollback_transaction(bool)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void commit_transaction()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void report_rollback_failure(std::string)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
// temporary data store to verify the expected results were produced
|
||||
InternalMockData _mock_data;
|
||||
|
@ -97,9 +97,31 @@ namespace test
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::bigint_unsigned, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
struct Book
|
||||
{
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "book";
|
||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
||||
template <typename T>
|
||||
struct _member_t
|
||||
{
|
||||
T book;
|
||||
T& operator()()
|
||||
{
|
||||
return book;
|
||||
}
|
||||
const T& operator()() const
|
||||
{
|
||||
return book;
|
||||
}
|
||||
};
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::blob, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
}
|
||||
|
||||
struct TabFoo : sqlpp::table_t<TabFoo, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega, TabFoo_::Psi>
|
||||
struct TabFoo : sqlpp::table_t<TabFoo, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega, TabFoo_::Psi, TabFoo_::Book>
|
||||
{
|
||||
struct _alias_t
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user