Commit f1243acd authored by Vadim Zeitlin's avatar Vadim Zeitlin

Add helper function for copying string to PostgreSQL backend

This helper is trivial but it's still better not to repeat these 2 lines
4 times.
parent 5e6f37e3
......@@ -204,6 +204,10 @@ struct postgresql_standard_use_type_backend : details::standard_use_type_backend
int position_;
std::string name_;
char * buf_;
private:
// Allocate buf_ of appropriate size and copy string data into it.
void copy_from_string(std::string const& s);
};
struct postgresql_vector_use_type_backend : details::vector_use_type_backend
......
......@@ -71,11 +71,7 @@ void postgresql_standard_use_type_backend::pre_use(indicator const * ind)
}
break;
case x_stdstring:
{
std::string const& s = exchange_type_cast<x_stdstring>(data_);
buf_ = new char[s.size() + 1];
std::strcpy(buf_, s.c_str());
}
copy_from_string(exchange_type_cast<x_stdstring>(data_));
break;
case x_short:
{
......@@ -114,12 +110,7 @@ void postgresql_standard_use_type_backend::pre_use(indicator const * ind)
}
break;
case x_double:
{
std::string const s = double_to_cstring(exchange_type_cast<x_double>(data_));
buf_ = new char[s.size() + 1];
std::strcpy(buf_, s.c_str());
}
copy_from_string(double_to_cstring(exchange_type_cast<x_double>(data_)));
break;
case x_stdtm:
{
......@@ -163,19 +154,13 @@ void postgresql_standard_use_type_backend::pre_use(indicator const * ind)
case x_xmltype:
{
xml_type * xml = static_cast<xml_type *>(data_);
std::string * s = &(xml->value);
buf_ = new char[s->size() + 1];
std::strcpy(buf_, s->c_str());
copy_from_string(xml->value);
}
break;
case x_longstring:
{
long_string * ls = static_cast<long_string *>(data_);
std::string * s = &(ls->value);
buf_ = new char[s->size() + 1];
std::strcpy(buf_, s->c_str());
copy_from_string(xml->value);
}
break;
......@@ -217,3 +202,9 @@ void postgresql_standard_use_type_backend::clean_up()
buf_ = NULL;
}
}
void postgresql_standard_use_type_backend::copy_from_string(std::string const& s)
{
buf_ = new char[s.size() + 1];
std::strcpy(buf_, s.c_str());
}
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