Discussion:
[soci-users] Clob vector reads
Andrew Grafham
2014-03-19 11:59:04 UTC
Permalink
Hi,

Should reading a Clob/Text field into a vector work in Soci 3.2.2 with ODBC
connecting to SQL server? I'm compiling using visual studio 2013 and MingW,
and the code crashes with both.

If I change the SQL to cast the Clob field to a Varchar, the problem goes
away, and the code works fine with MySQL.

The code I'm using is :-


#include <string>
#include <soci.h>
#include <iostream>


using namespace soci;
using namespace std;


int main()
{
try
{
session dbConnection("odbc", "xxxx");

std::string sql = "select colbfield from table where id = :a";

const int BATCH_SIZE = 300;

int id = 0;

std::vector<std::string> vClob(BATCH_SIZE);
std::vector<indicator> inds(BATCH_SIZE);

statement st = (dbConnection.prepare << sql, into(vClob, inds),
use(id));

st.execute();


while (st.fetch())
{
for (int i = 0; i < vClob.size(); i++)
std::cout << "Value = " << vClob.at(i) << std::endl;

vClob.resize(BATCH_SIZE);
}

}
catch (exception const &e)
{
std::cout << "Error: " << e.what() << '\n';
}
}
Mateusz Łoskot
2014-03-21 09:54:51 UTC
Permalink
Post by Andrew Grafham
Hi,
Should reading a Clob/Text field into a vector work in Soci 3.2.2 with ODBC
connecting to SQL server? I'm compiling using visual studio 2013 and MingW,
and the code crashes with both.
If I change the SQL to cast the Clob field to a Varchar, the problem goes
away, and the code works fine with MySQL.
Andrews,

AFAIR, CLOB support is not available, it's been on TODO list for quite
a long time now.

Best regards,
--
Mateusz Łoskot, http://mateusz.loskot.net
Andrew Grafham
2014-03-26 13:03:29 UTC
Permalink
Post by Andrew Grafham
Post by Andrew Grafham
Hi,
Should reading a Clob/Text field into a vector work in Soci 3.2.2 with
ODBC
Post by Andrew Grafham
connecting to SQL server? I'm compiling using visual studio 2013 and
MingW,
Post by Andrew Grafham
and the code crashes with both.
If I change the SQL to cast the Clob field to a Varchar, the problem goes
away, and the code works fine with MySQL.
Andrews,
AFAIR, CLOB support is not available, it's been on TODO list for quite
a long time now.
Best regards,
--
Mateusz Łoskot, http://mateusz.loskot.net
Thanks. I guess it's just by luck that it works on MySQL then?

I've come across another quirk - I'm doing vector inserts now, and I can
"use" a std::vector<boost::optional<boost::gregorian::date> > for
inserting, and that works fine, but if I try
std::vector<boost::optional<std::string> > , that doesn't seem to work (the
value inserted is always NULL, and there are definitely values populated
into the vector. Is that another known limitation?

Thanks

Andy
Andrew Grafham
2014-03-27 17:35:02 UTC
Permalink
Post by Andrew Grafham
Post by Andrew Grafham
Post by Andrew Grafham
Hi,
Should reading a Clob/Text field into a vector work in Soci 3.2.2 with
ODBC
Post by Andrew Grafham
connecting to SQL server? I'm compiling using visual studio 2013 and
MingW,
Post by Andrew Grafham
and the code crashes with both.
If I change the SQL to cast the Clob field to a Varchar, the problem
goes
Post by Andrew Grafham
away, and the code works fine with MySQL.
Andrews,
AFAIR, CLOB support is not available, it's been on TODO list for quite
a long time now.
Best regards,
--
Mateusz Łoskot, http://mateusz.loskot.net
Thanks. I guess it's just by luck that it works on MySQL then?
I've come across another quirk - I'm doing vector inserts now, and I can
"use" a std::vector<boost::optional<boost::gregorian::date> > for
inserting, and that works fine, but if I try
std::vector<boost::optional<std::string> > , that doesn't seem to work (the
value inserted is always NULL, and there are definitely values populated
into the vector. Is that another known limitation?
Thanks
Andy
I've played around with this a bit more, and inserting a vector of strings
using boost::optional seems to work on MySQL but not Oracle. I'm working
around it for the moment by using boost optional for everything other than
strings, where I use a separate soci::indicator vector).

Cheers

Andy

Loading...