I am trying to read a SQL Server table in C++ using a function like this..
CCommand<CDynamicAccessor>* Read(char* tblName)
{
wostringstream query;
query << "SELECT * FROM " << tblName;
return dataSource -> Query (query);
}
which calls this other function
CCommand<CDynamicAccessor>* Query(wostringstream& query)
{
HRESULT hr;
hr = _cmd.Open(_sess, _T(query.str().c_str()));
if (FAILED(hr))
{
std::wcout<<query.str().c_str() << "\n";
THROW_EXCEPTION("Command not executed.");
}
return &_cmd;
}
The problem is when I try to retrieve the column values using something like this
char* column20= (char*)cmd->GetValue("column20");
char* column21= (char*)cmd->GetValue("column21"); //Error
Because in the column20 I get the full string ex. “Value1”
But in the column21 I only get the first character ex. “V”, when I should get “Value2”
Is there any limitation in size or something like that which do not allow me to retrieve the full string for column21?
If so, what is the best way to solve this issue?
Most probably the result is a
wchar_t *string and you cast it tochar *