Thanks for asking. In my rush yesterday, I did not clarify the first part of this function.
I pass into this function a string which is an alias to the actual query to execute. For example, I'd pass in "GetRaces". The first SqlGetData executes a query on a table QueryList, which has two important fields - a QueryName and Query Text field. In that table is a row with 'GetRaces' for QueryName and 'SELECT Name FROM Race' for QueryText.
1 2 3 4 5 6 7
|
static struct _DBRow_QueryList
{
SQLCHAR Name[51];
SQLINTEGER NameLength;
SQLCHAR Text[256];
SQLINTEGER TextLength;
} DBRow_QueryList;
|
I cast DBRow_QueryList.Text into a string simply for my own readability. When I finish functionality of this method, I intend to make it more efficient by removing all the unnecessary casting. For now, though, I for some reason can read my own code better when I see that "string" name.
This code snippet works perfectly fine, minus some error handling I'll add when the overall functionality is complete. At this point in the code, you can assume the string QueryToExecute has a valid SELECT statement in it.
Down lower in the code, I have two lines commented: "DBRow_Race.Name," and "Result += (std::string)((char*)DBRow_Race.Name);"
If I use those two lines instead of the lines directly below each, I can confirm SqlGetData works fine with QueryToExecute = "SELECT Name FROM Race". Result gets values stored in it which match the values in the Race table. (eg "HumanCaucasianLatinoAsian...")
However, with using those two lines, I cannot pass in some other SELECT statement, like SELECT * FROM Race, because DBRow_Race.Name may not be an appropriate data type for other fields. So it's my goal to generalize that item in the second SqlGetData call in this function.
When I compile and run the program as is, using SELECT Name FROM Race, but using _ColumnInfo.TargetValue instead of DBRow_Race.Name, I see a 0x00000000 in _ColumnInfo.TargetValue instead of the first value, "Human", and get an error when doing Result += (std::string)((char*)_ColumnInfo.TargetValue);
Microsoft Visual C++ Debug Library
Debug Assertion Failed!
.....
File:c:\program files\...\xstring
Line:930
Expression: invalid null pointer
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
It seems clear to me that the assertion failed because SqlGetData did not know how to put the retrieved data into _ColumnInfo.TargetValue, but did not fail there because the data type was a valid SQLPOINTER with a buffer appropriately sized (sizeof(DBRow_Race.Name)). So the assertion failure happened only when trying to access that data source.
To reiterate my problem, I believe my problem is figuring out how to retrieve ambiguous data via SqlGetData.
If anyone is asking where the two dimensional vector of void pointers is, I'll answer now. I haven't implemented it yet. Its implementation will replace the "Result += ..." line, saving the retrieved data in the vector instead of a string. The Result string is simply being used for testing until I have the SqlGetData part figured out.
Thank you for asking, kbw, and thank you anyone else who takes the time to look at my problem.
I hope I didn't ramble too much, and hopefully clarified my problem better for others.