0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Merged <data_type>/serialize.h into operand and result_field

This commit is contained in:
rbock 2015-10-31 10:20:35 +01:00
parent de1e8f27a4
commit 21d633bdf4
24 changed files with 159 additions and 371 deletions

View File

@ -34,6 +34,5 @@
#include <sqlpp11/data_types/boolean/column_operators.h> #include <sqlpp11/data_types/boolean/column_operators.h>
#include <sqlpp11/data_types/boolean/parameter_type.h> #include <sqlpp11/data_types/boolean/parameter_type.h>
#include <sqlpp11/data_types/boolean/result_field.h> #include <sqlpp11/data_types/boolean/result_field.h>
#include <sqlpp11/data_types/boolean/serialize.h>
#endif #endif

View File

@ -29,6 +29,7 @@
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h> #include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp namespace sqlpp
{ {
@ -63,6 +64,19 @@ namespace sqlpp
_value_t _t; _value_t _t;
}; };
template <typename Context>
struct serializer_t<Context, boolean_operand>
{
using _serialize_check = consistent_t;
using Operand = boolean_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
} }
#endif #endif

View File

@ -33,6 +33,7 @@
#include <sqlpp11/result_field_methods.h> #include <sqlpp11/result_field_methods.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/boolean/data_type.h> #include <sqlpp11/data_types/boolean/data_type.h>
#include <ostream>
namespace sqlpp namespace sqlpp
{ {
@ -103,5 +104,11 @@ namespace sqlpp
bool _is_null; bool _is_null;
signed char _value; signed char _value;
}; };
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<boolean, Db, FieldSpec>& e)
{
return serialize(e, os);
}
} }
#endif #endif

View File

@ -1,57 +0,0 @@
/*
* 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_BOOLEAN_SERIALIZE_H
#define SQLPP_BOOLEAN_SERIALIZE_H
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/boolean/operand.h>
#include <ostream>
namespace sqlpp
{
struct boolean;
template <typename Context>
struct serializer_t<Context, boolean_operand>
{
using _serialize_check = consistent_t;
using Operand = boolean_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<boolean, Db, FieldSpec>& e)
{
return serialize(e, os);
}
}
#endif

View File

@ -34,6 +34,5 @@
#include <sqlpp11/data_types/day_point/column_operators.h> #include <sqlpp11/data_types/day_point/column_operators.h>
#include <sqlpp11/data_types/day_point/parameter_type.h> #include <sqlpp11/data_types/day_point/parameter_type.h>
#include <sqlpp11/data_types/day_point/result_field.h> #include <sqlpp11/data_types/day_point/result_field.h>
#include <sqlpp11/data_types/day_point/serialize.h>
#endif #endif

View File

@ -27,9 +27,11 @@
#ifndef SQLPP_DAY_POINT_OPERAND_H #ifndef SQLPP_DAY_POINT_OPERAND_H
#define SQLPP_DAY_POINT_OPERAND_H #define SQLPP_DAY_POINT_OPERAND_H
#include <date.h>
#include <sqlpp11/chrono.h> #include <sqlpp11/chrono.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h> #include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp namespace sqlpp
{ {
@ -64,5 +66,19 @@ namespace sqlpp
_value_t _t; _value_t _t;
}; };
template <typename Context>
struct serializer_t<Context, day_point_operand>
{
using _serialize_check = consistent_t;
using Operand = day_point_operand;
static Context& _(const Operand& t, Context& context)
{
const auto ymd = ::date::year_month_day{t._t};
context << "DATE '" << ymd << "'";
return context;
}
};
} }
#endif #endif

View File

@ -33,6 +33,7 @@
#include <sqlpp11/result_field_methods.h> #include <sqlpp11/result_field_methods.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/day_point/data_type.h> #include <sqlpp11/data_types/day_point/data_type.h>
#include <ostream>
namespace sqlpp namespace sqlpp
{ {
@ -104,5 +105,20 @@ namespace sqlpp
bool _is_null; bool _is_null;
_cpp_value_type _value; _cpp_value_type _value;
}; };
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<day_point, Db, FieldSpec>& e)
{
if (e.is_null() and not null_is_trivial_value_t<FieldSpec>::value)
{
os << "NULL";
}
else
{
const auto ymd = ::date::year_month_day{e.value()};
os << ymd;
}
return os;
}
} }
#endif #endif

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 2015-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_DAY_POINT_SERIALIZE_H
#define SQLPP_DAY_POINT_SERIALIZE_H
#include <date.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/day_point/operand.h>
#include <ostream>
namespace sqlpp
{
template <typename Context>
struct serializer_t<Context, day_point_operand>
{
using _serialize_check = consistent_t;
using Operand = day_point_operand;
static Context& _(const Operand& t, Context& context)
{
const auto ymd = ::date::year_month_day{t._t};
context << "DATE '" << ymd << "'";
return context;
}
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<day_point, Db, FieldSpec>& e)
{
if (e.is_null() and not null_is_trivial_value_t<FieldSpec>::value)
{
os << "NULL";
}
else
{
const auto ymd = ::date::year_month_day{e.value()};
os << ymd;
}
return os;
}
}
#endif

View File

@ -34,6 +34,5 @@
#include <sqlpp11/data_types/floating_point/column_operators.h> #include <sqlpp11/data_types/floating_point/column_operators.h>
#include <sqlpp11/data_types/floating_point/parameter_type.h> #include <sqlpp11/data_types/floating_point/parameter_type.h>
#include <sqlpp11/data_types/floating_point/result_field.h> #include <sqlpp11/data_types/floating_point/result_field.h>
#include <sqlpp11/data_types/floating_point/serialize.h>
#endif #endif

View File

@ -29,6 +29,7 @@
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h> #include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp namespace sqlpp
{ {
@ -61,5 +62,18 @@ namespace sqlpp
_value_t _t; _value_t _t;
}; };
template <typename Context>
struct serializer_t<Context, floating_point_operand>
{
using _serialize_check = consistent_t;
using Operand = floating_point_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
} }
#endif #endif

View File

@ -33,6 +33,7 @@
#include <sqlpp11/result_field_methods.h> #include <sqlpp11/result_field_methods.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/floating_point/data_type.h> #include <sqlpp11/data_types/floating_point/data_type.h>
#include <ostream>
namespace sqlpp namespace sqlpp
{ {
@ -104,5 +105,11 @@ namespace sqlpp
bool _is_null; bool _is_null;
_cpp_value_type _value; _cpp_value_type _value;
}; };
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<floating_point, Db, FieldSpec>& e)
{
return serialize(e, os);
}
} }
#endif #endif

View File

@ -1,55 +0,0 @@
/*
* 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_FLOATING_POINT_SERIALIZE_H
#define SQLPP_FLOATING_POINT_SERIALIZE_H
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/integral/operand.h>
#include <ostream>
namespace sqlpp
{
template <typename Context>
struct serializer_t<Context, floating_point_operand>
{
using _serialize_check = consistent_t;
using Operand = floating_point_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<floating_point, Db, FieldSpec>& e)
{
return serialize(e, os);
}
}
#endif

View File

@ -34,6 +34,5 @@
#include <sqlpp11/data_types/integral/column_operators.h> #include <sqlpp11/data_types/integral/column_operators.h>
#include <sqlpp11/data_types/integral/parameter_type.h> #include <sqlpp11/data_types/integral/parameter_type.h>
#include <sqlpp11/data_types/integral/result_field.h> #include <sqlpp11/data_types/integral/result_field.h>
#include <sqlpp11/data_types/integral/serialize.h>
#endif #endif

View File

@ -29,6 +29,7 @@
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h> #include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp namespace sqlpp
{ {
@ -63,6 +64,19 @@ namespace sqlpp
_value_t _t; _value_t _t;
}; };
template <typename Context>
struct serializer_t<Context, integral_operand>
{
using _serialize_check = consistent_t;
using Operand = integral_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
} }
#endif #endif

View File

@ -33,6 +33,7 @@
#include <sqlpp11/result_field_methods.h> #include <sqlpp11/result_field_methods.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/integral/data_type.h> #include <sqlpp11/data_types/integral/data_type.h>
#include <ostream>
namespace sqlpp namespace sqlpp
{ {
@ -104,5 +105,11 @@ namespace sqlpp
bool _is_null; bool _is_null;
_cpp_value_type _value; _cpp_value_type _value;
}; };
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<integral, Db, FieldSpec>& e)
{
return serialize(e, os);
}
} }
#endif #endif

View File

@ -1,55 +0,0 @@
/*
* 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_INTEGRAL_SERIALIZE_H
#define SQLPP_INTEGRAL_SERIALIZE_H
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/integral/operand.h>
#include <ostream>
namespace sqlpp
{
template <typename Context>
struct serializer_t<Context, integral_operand>
{
using _serialize_check = consistent_t;
using Operand = integral_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<integral, Db, FieldSpec>& e)
{
return serialize(e, os);
}
}
#endif

View File

@ -34,7 +34,6 @@
#include <sqlpp11/data_types/text/column_operators.h> #include <sqlpp11/data_types/text/column_operators.h>
#include <sqlpp11/data_types/text/parameter_type.h> #include <sqlpp11/data_types/text/parameter_type.h>
#include <sqlpp11/data_types/text/result_field.h> #include <sqlpp11/data_types/text/result_field.h>
#include <sqlpp11/data_types/text/serialize.h>
// text specific functions // text specific functions
#include <sqlpp11/data_types/text/like.h> #include <sqlpp11/data_types/text/like.h>

View File

@ -30,6 +30,7 @@
#include <string> #include <string>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h> #include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp namespace sqlpp
{ {
@ -64,5 +65,18 @@ namespace sqlpp
_value_t _t; _value_t _t;
}; };
template <typename Context>
struct serializer_t<Context, text_operand>
{
using _serialize_check = consistent_t;
using Operand = text_operand;
static Context& _(const Operand& t, Context& context)
{
context << '\'' << context.escape(t._t) << '\'';
return context;
}
};
} }
#endif #endif

View File

@ -33,6 +33,7 @@
#include <sqlpp11/result_field_methods.h> #include <sqlpp11/result_field_methods.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/text/data_type.h> #include <sqlpp11/data_types/text/data_type.h>
#include <ostream>
namespace sqlpp namespace sqlpp
{ {
@ -112,5 +113,18 @@ namespace sqlpp
const char* _value_ptr; const char* _value_ptr;
size_t _len; size_t _len;
}; };
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<text, Db, FieldSpec>& e)
{
if (e.is_null() and not null_is_trivial_value_t<FieldSpec>::value)
{
return os << "NULL";
}
else
{
return os << e.value();
}
}
} }
#endif #endif

View File

@ -1,62 +0,0 @@
/*
* 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_TEXT_SERIALIZE_H
#define SQLPP_TEXT_SERIALIZE_H
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/text/operand.h>
#include <ostream>
namespace sqlpp
{
template <typename Context>
struct serializer_t<Context, text_operand>
{
using _serialize_check = consistent_t;
using Operand = text_operand;
static Context& _(const Operand& t, Context& context)
{
context << '\'' << context.escape(t._t) << '\'';
return context;
}
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<text, Db, FieldSpec>& e)
{
if (e.is_null() and not null_is_trivial_value_t<FieldSpec>::value)
{
return os << "NULL";
}
else
{
return os << e.value();
}
}
}
#endif

View File

@ -34,6 +34,5 @@
#include <sqlpp11/data_types/time_point/column_operators.h> #include <sqlpp11/data_types/time_point/column_operators.h>
#include <sqlpp11/data_types/time_point/parameter_type.h> #include <sqlpp11/data_types/time_point/parameter_type.h>
#include <sqlpp11/data_types/time_point/result_field.h> #include <sqlpp11/data_types/time_point/result_field.h>
#include <sqlpp11/data_types/time_point/serialize.h>
#endif #endif

View File

@ -27,9 +27,11 @@
#ifndef SQLPP_TIME_POINT_OPERAND_H #ifndef SQLPP_TIME_POINT_OPERAND_H
#define SQLPP_TIME_POINT_OPERAND_H #define SQLPP_TIME_POINT_OPERAND_H
#include <date.h>
#include <sqlpp11/chrono.h> #include <sqlpp11/chrono.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h> #include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp namespace sqlpp
{ {
@ -65,5 +67,21 @@ namespace sqlpp
_value_t _t; _value_t _t;
}; };
template <typename Context, typename Period>
struct serializer_t<Context, time_point_operand<Period>>
{
using _serialize_check = consistent_t;
using Operand = time_point_operand<Period>;
static Context& _(const Operand& t, Context& context)
{
const auto dp = ::date::floor<::date::days>(t._t);
const auto time = ::date::make_time(t._t - dp);
const auto ymd = ::date::year_month_day{dp};
context << "TIMESTAMP '" << ymd << ' ' << time << "'";
return context;
}
};
} }
#endif #endif

View File

@ -33,6 +33,7 @@
#include <sqlpp11/result_field_methods.h> #include <sqlpp11/result_field_methods.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/time_point/data_type.h> #include <sqlpp11/data_types/time_point/data_type.h>
#include <ostream>
namespace sqlpp namespace sqlpp
{ {
@ -105,5 +106,22 @@ namespace sqlpp
bool _is_null; bool _is_null;
_cpp_value_type _value; _cpp_value_type _value;
}; };
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<time_point, Db, FieldSpec>& e)
{
if (e.is_null() and not null_is_trivial_value_t<FieldSpec>::value)
{
os << "NULL";
}
else
{
const auto dp = ::date::floor<::date::days>(e.value());
const auto time = ::date::make_time(e.value() - dp);
const auto ymd = ::date::year_month_day{dp};
os << ymd << 'T' << time;
}
return os;
}
} }
#endif #endif

View File

@ -1,70 +0,0 @@
/*
* Copyright (c) 2015-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_TIME_POINT_SERIALIZE_H
#define SQLPP_TIME_POINT_SERIALIZE_H
#include <date.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/time_point/operand.h>
#include <ostream>
namespace sqlpp
{
template <typename Context, typename Period>
struct serializer_t<Context, time_point_operand<Period>>
{
using _serialize_check = consistent_t;
using Operand = time_point_operand<Period>;
static Context& _(const Operand& t, Context& context)
{
const auto dp = ::date::floor<::date::days>(t._t);
const auto time = ::date::make_time(t._t - dp);
const auto ymd = ::date::year_month_day{dp};
context << "TIMESTAMP '" << ymd << ' ' << time << "'";
return context;
}
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<time_point, Db, FieldSpec>& e)
{
if (e.is_null() and not null_is_trivial_value_t<FieldSpec>::value)
{
os << "NULL";
}
else
{
const auto dp = ::date::floor<::date::days>(e.value());
const auto time = ::date::make_time(e.value() - dp);
const auto ymd = ::date::year_month_day{dp};
os << "TIMESTAMP '" << ymd << ' ' << time << "'";
}
return os;
}
}
#endif