I’m using OLEDB to connect to my local Oracle 11gR2 database in VC++. I’m using CCommand::Open to Select rows from my database, which should contain strings.
When I’m using GetValue to get my data though, I only get the first character.
Here are my attempts at getting that data. Note that the same behavior happens in “GetValue” and in “GetColumnName”.
char* test = (CHAR*)cmd.GetColumnName(2);
cout << (CHAR*)cmd.GetColumnName(2) << endl;
printf_s( "%s", (CHAR*)cmd.GetColumnName(2));
printf_s( "%S", (CHAR*)cmd.GetColumnName(2)); //This one works,
//but I really need to store my data, not just print it.
I’m thinking this is a conversion problem from SQL to C++ data types, but I can’t put my finger on it. Help?
LPOLESTRis awchar_t*string (thanks LRiO for confirming that) which is basicallyunsigned short*. The reason you are getting just the first character is because each character takes up two bytes, and english letters happen to be a NULL byte followed by the ASCII code for that letter, which, when stored in a little-endian format, makes it a C-string with one character (because the bytes are stored backwards).You need to use
wcoutto print it:You can store it like this (along with its length via
wcslen):