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 @@ ...@@ -9,6 +9,7 @@
#define SOCI_EXCHANGE_CAST_H_INCLUDED #define SOCI_EXCHANGE_CAST_H_INCLUDED
#include "soci/soci-backend.h" #include "soci/soci-backend.h"
#include "soci/type-wrappers.h"
#include <ctime> #include <ctime>
...@@ -69,6 +70,18 @@ struct exchange_type_traits<x_stdtm> ...@@ -69,6 +70,18 @@ struct exchange_type_traits<x_stdtm>
typedef std::tm value_type; 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. // exchange_type_traits not defined for x_statement, x_rowid and x_blob here.
template <exchange_type e> template <exchange_type e>
......
...@@ -123,19 +123,11 @@ void firebird_standard_into_type_backend::exchangeData() ...@@ -123,19 +123,11 @@ void firebird_standard_into_type_backend::exchangeData()
break; break;
case x_longstring: case x_longstring:
{ copy_from_blob(exchange_type_cast<x_longstring>(data_).value);
long_string* const dst = static_cast<long_string*>(data_);
copy_from_blob(dst->value);
}
break; break;
case x_xmltype: case x_xmltype:
{ copy_from_blob(exchange_type_cast<x_xmltype>(data_).value);
xml_type* const dst = static_cast<xml_type*>(data_);
copy_from_blob(dst->value);
}
break; break;
default: default:
......
...@@ -149,19 +149,11 @@ void firebird_standard_use_type_backend::exchangeData() ...@@ -149,19 +149,11 @@ void firebird_standard_use_type_backend::exchangeData()
break; break;
case x_longstring: case x_longstring:
{ copy_to_blob(exchange_type_cast<x_longstring>(data_).value);
long_string const* const src = static_cast<long_string*>(data_);
copy_to_blob(src->value);
}
break; break;
case x_xmltype: case x_xmltype:
{ copy_to_blob(exchange_type_cast<x_xmltype>(data_).value);
xml_type const* const src = static_cast<xml_type*>(data_);
copy_to_blob(src->value);
}
break; break;
default: default:
......
...@@ -297,9 +297,8 @@ void oracle_standard_into_type_backend::post_fetch( ...@@ -297,9 +297,8 @@ void oracle_standard_into_type_backend::post_fetch(
if (indOCIHolder_ != -1) if (indOCIHolder_ != -1)
{ {
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_); 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) else if (type_ == x_longstring)
...@@ -307,9 +306,8 @@ void oracle_standard_into_type_backend::post_fetch( ...@@ -307,9 +306,8 @@ void oracle_standard_into_type_backend::post_fetch(
if (indOCIHolder_ != -1) if (indOCIHolder_ != -1)
{ {
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_); OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_);
long_string * ls = static_cast<long_string *>(data_);
read_from_lob(lobp, exchange_type_cast<x_longstring>(data_).value);
read_from_lob(lobp, ls->value);
} }
} }
} }
......
...@@ -292,9 +292,8 @@ void oracle_standard_use_type_backend::pre_exec(int /* num */) ...@@ -292,9 +292,8 @@ void oracle_standard_use_type_backend::pre_exec(int /* num */)
lazy_temp_lob_init(); lazy_temp_lob_init();
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_); 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; break;
case x_longstring: case x_longstring:
...@@ -304,9 +303,8 @@ void oracle_standard_use_type_backend::pre_exec(int /* num */) ...@@ -304,9 +303,8 @@ void oracle_standard_use_type_backend::pre_exec(int /* num */)
lazy_temp_lob_init(); lazy_temp_lob_init();
OCILobLocator * lobp = static_cast<OCILobLocator *>(ociData_); 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; break;
default: default:
......
...@@ -153,20 +153,10 @@ void postgresql_standard_into_type_backend::post_fetch( ...@@ -153,20 +153,10 @@ void postgresql_standard_into_type_backend::post_fetch(
} }
break; break;
case x_xmltype: case x_xmltype:
{ exchange_type_cast<x_xmltype>(data_).value.assign(buf);
xml_type * xml = static_cast<xml_type *>(data_);
std::string * dest = &(xml->value);
dest->assign(buf);
}
break; break;
case x_longstring: case x_longstring:
{ exchange_type_cast<x_longstring>(data_).value.assign(buf);
long_string * ls = static_cast<long_string *>(data_);
std::string * dest = &(ls->value);
dest->assign(buf);
}
break; break;
default: default:
......
...@@ -152,16 +152,10 @@ void postgresql_standard_use_type_backend::pre_use(indicator const * ind) ...@@ -152,16 +152,10 @@ void postgresql_standard_use_type_backend::pre_use(indicator const * ind)
} }
break; break;
case x_xmltype: case x_xmltype:
{ copy_from_string(exchange_type_cast<x_xmltype>(data_).value);
xml_type * xml = static_cast<xml_type *>(data_);
copy_from_string(xml->value);
}
break; break;
case x_longstring: case x_longstring:
{ copy_from_string(exchange_type_cast<x_longstring>(data_).value);
long_string * ls = static_cast<long_string *>(data_);
copy_from_string(xml->value);
}
break; break;
default: 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