diff --git a/include/sqlpp11/data_types.h b/include/sqlpp11/data_types.h index c9776077..b447a214 100644 --- a/include/sqlpp11/data_types.h +++ b/include/sqlpp11/data_types.h @@ -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 #include #include #include diff --git a/include/sqlpp11/data_types/blob.h b/include/sqlpp11/data_types/blob.h new file mode 100644 index 00000000..3196dd31 --- /dev/null +++ b/include/sqlpp11/data_types/blob.h @@ -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 +#include +#include +#include +#include +#include +#include + +// blob specific functions +#include +#include + +#endif diff --git a/include/sqlpp11/data_types/blob/column_operators.h b/include/sqlpp11/data_types/blob/column_operators.h new file mode 100644 index 00000000..6c4f88da --- /dev/null +++ b/include/sqlpp11/data_types/blob/column_operators.h @@ -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 +#include +#include +#include + +namespace sqlpp +{ + template + struct concat_t; + + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + auto operator+=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), + concat_t>{*static_cast(this), rhs{t}}}; + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/blob/data_type.h b/include/sqlpp11/data_types/blob/data_type.h new file mode 100644 index 00000000..a1eea3ef --- /dev/null +++ b/include/sqlpp11/data_types/blob/data_type.h @@ -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 +#include + +namespace sqlpp +{ + struct blob + { + using _traits = make_traits; + using _cpp_value_type = std::vector; + + template + using _is_valid_operand = is_blob_t; + }; + + using blob = blob; + using mediumblob = blob; +} +#endif diff --git a/include/sqlpp11/data_types/blob/expression_operators.h b/include/sqlpp11/data_types/blob/expression_operators.h new file mode 100644 index 00000000..3631fa83 --- /dev/null +++ b/include/sqlpp11/data_types/blob/expression_operators.h @@ -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 +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct like_t; + + template + struct return_type_like> + { + using check = consistent_t; + using type = like_t, wrap_operand_t>; + }; + + template + struct expression_operators : public basic_expression_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + auto like(const R& r) const -> return_type_like_t + { + return_type_like::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/blob/operand.h b/include/sqlpp11/data_types/blob/operand.h new file mode 100644 index 00000000..78033d33 --- /dev/null +++ b/include/sqlpp11/data_types/blob/operand.h @@ -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 +#include +#include +#include + +namespace sqlpp +{ + struct blob; + + struct blob_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = std::vector; + + 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 + struct serializer_t + { + 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 diff --git a/include/sqlpp11/data_types/blob/parameter_value.h b/include/sqlpp11/data_types/blob/parameter_value.h new file mode 100644 index 00000000..e2e70a4c --- /dev/null +++ b/include/sqlpp11/data_types/blob/parameter_value.h @@ -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 +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_blob_parameter(index, &_value, _is_null); + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/blob/result_field.h b/include/sqlpp11/data_types/blob/result_field.h new file mode 100644 index 00000000..df28e203 --- /dev/null +++ b/include/sqlpp11/data_types/blob/result_field.h @@ -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 +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct result_field_t> + : public result_field_base> + { + const char* blob{nullptr}; // Non-owning + size_t len{}; + + template + 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 + 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 + inline std::ostream& operator<<( + std::ostream& os, const result_field_t>& e) + { + if (e.is_null() and not NullIsTrivialValue) + { + return os << "NULL"; + } + else + { + return os << e.value(); + } + } +} +#endif diff --git a/include/sqlpp11/data_types/blob/wrap_operand.h b/include/sqlpp11/data_types/blob/wrap_operand.h new file mode 100644 index 00000000..7556ccbe --- /dev/null +++ b/include/sqlpp11/data_types/blob/wrap_operand.h @@ -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 +#include +#include +#include + +namespace sqlpp +{ + struct blob_operand; + + template <> + struct wrap_operand, void> + { + using type = blob_operand; + }; +} +#endif diff --git a/include/sqlpp11/data_types/text/data_type.h b/include/sqlpp11/data_types/text/data_type.h index d3ed84eb..de8fc0e1 100644 --- a/include/sqlpp11/data_types/text/data_type.h +++ b/include/sqlpp11/data_types/text/data_type.h @@ -40,7 +40,6 @@ namespace sqlpp using _is_valid_operand = is_text_t; }; - using blob = text; using varchar = text; using char_ = text; using binary = text; diff --git a/include/sqlpp11/data_types/text/expression_operators.h b/include/sqlpp11/data_types/text/expression_operators.h index 6802a795..ea40f697 100644 --- a/include/sqlpp11/data_types/text/expression_operators.h +++ b/include/sqlpp11/data_types/text/expression_operators.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace sqlpp { @@ -40,15 +41,6 @@ namespace sqlpp template struct like_t; - template - struct return_type_like - { - using check = assert_valid_operands; - using type = bad_expression; - }; - template - using return_type_like_t = typename return_type_like::type; - template struct return_type_like> { diff --git a/include/sqlpp11/data_types/text/return_type_like.h b/include/sqlpp11/data_types/text/return_type_like.h new file mode 100644 index 00000000..8262c567 --- /dev/null +++ b/include/sqlpp11/data_types/text/return_type_like.h @@ -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 + +namespace sqlpp +{ + template + struct return_type_like + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_like_t = typename return_type_like::type; +} + +#endif diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 4f0a2051..7db9ac53 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -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 + using is_blob_t = std::is_same, blob>; + struct boolean; template using is_boolean_t = std::is_same, boolean>; diff --git a/test_serializer/Blob.cpp b/test_serializer/Blob.cpp new file mode 100644 index 00000000..d9f770c5 --- /dev/null +++ b/test_serializer/Blob.cpp @@ -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 + +#include + +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 + { + return std::vector(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; +} diff --git a/test_serializer/CMakeLists.txt b/test_serializer/CMakeLists.txt index 2246b936..042908e0 100644 --- a/test_serializer/CMakeLists.txt +++ b/test_serializer/CMakeLists.txt @@ -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}) diff --git a/tests/MockDb.h b/tests/MockDb.h index 05271893..3cc99661 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -36,9 +36,10 @@ #include // 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 @@ -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; diff --git a/tests/Sample.h b/tests/Sample.h index 15e7ee69..b610d618 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -97,9 +97,31 @@ namespace test }; using _traits = sqlpp::make_traits; }; + struct Book + { + struct _alias_t + { + static constexpr const char _literal[] = "book"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T book; + T& operator()() + { + return book; + } + const T& operator()() const + { + return book; + } + }; + }; + using _traits = sqlpp::make_traits; + }; } - struct TabFoo : sqlpp::table_t + struct TabFoo : sqlpp::table_t { struct _alias_t {