ODBC supports Unicode parameter types so use SQL_C_WCHAR
and SQL_WVARCHAR
instead of SQL_C_CHAR
and SQL_VARCHAR
respectively.
You have two other issues as well.
First you are passing an ANSI string
as a parameter. If you are using Unicode you need to use a wide string - wstring
instead.
Second you are not passing a valid buffer to SQLBindParameter
. The value returned by string.c_str() is a const char*
that is a read only buffer. It is not valid to pass hat to a function that requires a writable buffer - doing this will corrupt your string. However you won't see any corruption in your case because you the call to path.length()
WILL return zero so SQLBindParameter
will never return any data.
You will need to declare WCHAR
array buffer and pass that to SQLBindParameter
which will give it a valid buffer to write data into. You can then transfer that buffer to a wstring
if you need it in a C++ object.
So something like this:
WCHAR path[401]; // 401 - width of you column + 1 for the null terminator
SQLBindParameter(statement, 1, SQL_PARAM_OUTPUT, SQL_C_WCHAR, SQL_WVARCHAR, 400, 0, (SQLPOINTER)path, sizeof(path), &pathstrlen);
Edit
Ffrom looking at the ODBC data conversion table it appears that you should be able to get ODBC to convert that data from Unicode to ANSI for you if you to not want to deal with Unicode strings in your application.
char path[401]; // 401 - width of you column + 1 for the null terminator
SQLBindParameter(statement, 1, SQL_PARAM_OUTPUT, SQL_C_WCHAR, SQL_WVARCHAR, 400, 0, (SQLPOINTER)path, sizeof(path), &pathstrlen);