Commit 556f5d33 authored by Vadim Zeitlin's avatar Vadim Zeitlin

Add exchange_type_traits<> specializations for XML and CLOB

There is no reason to not have them and this allows to write slightly
shorter and safer code using exchange_type_cast<> instead of "raw"
static_cast<>.
parent f1243acd
......@@ -9,6 +9,7 @@
#define SOCI_EXCHANGE_CAST_H_INCLUDED
#include "soci/soci-backend.h"
#include "soci/type-wrappers.h"
#include <ctime>
......@@ -69,6 +70,18 @@ struct exchange_type_traits<x_stdtm>
typedef std::tm value_type;
};
template <>
struct exchange_type_traits<x_longstring>
{
typedef long_string value_type;
};
template <>
struct exchange_type_traits<x_xmltype>
{
typedef xml_type value_type;
};
// exchange_type_traits not defined for x_statement, x_rowid and x_blob here.
template <exchange_type e>
......
......@@ -123,19 +123,11 @@ void firebird_standard_into_type_backend::exchangeData()
break;
case x_longstring:
{
long_string* const dst = static_cast<long_string*>(data_);
copy_from_blob(dst->value);
}
copy_from_blob(exchange_type_cast<x_longstring>(data_).value);
break;
case x_xmltype:
{
xml_type* const dst = static_cast<xml_type*>(data_);
copy_from_blob(dst->value);
}
copy_from_blob(exchange_type_cast<x_xmltype>(data_).value);
break;
default:
......
......@@ -149,19 +149,11 @@ void firebird_standard_use_type_backend::exchangeData()
break;
case x_longstring:
{
long_string const* const src = static_cast<long_string*>(data_);
copy_to_blob(src->value);
}
copy_to_blob(exchange_type_cast<x_longstring>(data_).value);
break;
case x_xmltype:
{
xml_type const* const src = static_cast<xml_type*>(data_);
copy_to_blob(src->value);
}
copy_to_blob(exchange_type_cast<x_xmltype>(data_).value);
break;
default:
......
......@@ -297,9 +297,8 @@ void oracle_standard_into_type_backend::post_fetch(
if (indOCIHolder_ != -1)
{
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_);
xml_type * xml = static_cast<xml_type *>(data_);
read_from_lob(lobp, xml->value);
read_from_lob(lobp, exchange_type_cast<x_xmltype>(data_).value);
}
}
else if (type_ == x_longstring)
......@@ -307,9 +306,8 @@ void oracle_standard_into_type_backend::post_fetch(
if (indOCIHolder_ != -1)
{
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_);
long_string * ls = static_cast<long_string *>(data_);
read_from_lob(lobp, ls->value);
read_from_lob(lobp, exchange_type_cast<x_longstring>(data_).value);
}
}
}
......
......@@ -292,9 +292,8 @@ void oracle_standard_use_type_backend::pre_exec(int /* num */)
lazy_temp_lob_init();
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_);
xml_type * xml = static_cast<xml_type *>(data_);
write_to_lob(lobp, xml->value);
write_to_lob(lobp, exchange_type_cast<x_xmltype>(data_).value);
}
break;
case x_longstring:
......@@ -304,9 +303,8 @@ void oracle_standard_use_type_backend::pre_exec(int /* num */)
lazy_temp_lob_init();
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_);
long_string * ls = static_cast<long_string *>(data_);
write_to_lob(lobp, ls->value);
write_to_lob(lobp, exchange_type_cast<x_longstring>(data_).value);
}
break;
default:
......
......@@ -153,20 +153,10 @@ void postgresql_standard_into_type_backend::post_fetch(
}
break;
case x_xmltype:
{
xml_type * xml = static_cast<xml_type *>(data_);
std::string * dest = &(xml->value);
dest->assign(buf);
}
exchange_type_cast<x_xmltype>(data_).value.assign(buf);
break;
case x_longstring:
{
long_string * ls = static_cast<long_string *>(data_);
std::string * dest = &(ls->value);
dest->assign(buf);
}
exchange_type_cast<x_longstring>(data_).value.assign(buf);
break;
default:
......
......@@ -152,16 +152,10 @@ void postgresql_standard_use_type_backend::pre_use(indicator const * ind)
}
break;
case x_xmltype:
{
xml_type * xml = static_cast<xml_type *>(data_);
copy_from_string(xml->value);
}
copy_from_string(exchange_type_cast<x_xmltype>(data_).value);
break;
case x_longstring:
{
long_string * ls = static_cast<long_string *>(data_);
copy_from_string(xml->value);
}
copy_from_string(exchange_type_cast<x_longstring>(data_).value);
break;
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment