Skip to content

Commit

Permalink
Add very simple XML and CLOB support to ODBC backend
Browse files Browse the repository at this point in the history
Handle them as plain strings and rely on the ODBC driver to perform the
required conversions.
  • Loading branch information
vadz committed Sep 14, 2017
1 parent fabb8f0 commit 6e47321
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/lobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ For PostgreSQL, these types are:

For Firebird, there is no special XML support, but `BLOB SUB_TYPE TEXT` can be
used for storing it, as well as long strings.

For ODBC backend, these types depend on the type of the database connected to.
In particularly important special case of Microsoft SQL Server, these types
are:

* `xml`
* `text`
10 changes: 10 additions & 0 deletions src/backends/odbc/standard-into-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void odbc_standard_into_type_backend::define_by_pos(
data = buf_;
break;
case x_stdstring:
case x_longstring:
case x_xmltype:
odbcType_ = SQL_C_CHAR;
// Patch: set to min between column size and 100MB (used ot be 32769)
// Column size for text data type can be too large for buffer allocation
Expand Down Expand Up @@ -159,6 +161,14 @@ void odbc_standard_into_type_backend::post_fetch(
throw soci_error("Buffer size overflow; maybe got too large string");
}
}
else if (type_ == x_longstring)
{
exchange_type_cast<x_longstring>(data_).value = buf_;
}
else if (type_ == x_xmltype)
{
exchange_type_cast<x_xmltype>(data_).value = buf_;
}
else if (type_ == x_stdtm)
{
std::tm& t = exchange_type_cast<x_stdtm>(data_);
Expand Down
9 changes: 9 additions & 0 deletions src/backends/odbc/standard-use-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ void* odbc_standard_use_type_backend::prepare_for_bind(
}
break;

case x_longstring:
copy_from_string(exchange_type_cast<x_longstring>(data_).value,
size, sqlType, cType);
break;
case x_xmltype:
copy_from_string(exchange_type_cast<x_xmltype>(data_).value,
size, sqlType, cType);
break;

// unsupported types
default:
throw soci_error("Use element used with non-supported type.");
Expand Down
28 changes: 28 additions & 0 deletions tests/odbc/test-odbc-mssql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ struct table_creator_for_get_affected_rows : table_creator_base
}
};

struct table_creator_for_clob : table_creator_base
{
table_creator_for_clob(soci::session & sql)
: table_creator_base(sql)
{
sql << "create table soci_test(id integer, s text)";
}
};

struct table_creator_for_xml : table_creator_base
{
table_creator_for_xml(soci::session & sql)
: table_creator_base(sql)
{
sql << "create table soci_test(id integer, x xml)";
}
};

//
// Support for SOCI Common Tests
//
Expand Down Expand Up @@ -147,6 +165,16 @@ class test_context : public test_context_base
return new table_creator_for_get_affected_rows(s);
}

tests::table_creator_base* table_creator_clob(soci::session& s) const
{
return new table_creator_for_clob(s);
}

tests::table_creator_base* table_creator_xml(soci::session& s) const
{
return new table_creator_for_xml(s);
}

std::string to_date_time(std::string const &datdt_string) const
{
return "convert(datetime, \'" + datdt_string + "\', 120)";
Expand Down

0 comments on commit 6e47321

Please sign in to comment.