On Windows, the below code compiles successfully:
SQLWCHAR *qry = nullptr;
qry = L"SELECT * FROM my_table;";
However, on Linux with unixODBC, it fails to compile with an error:
error: cannot convert 'const wchar_t [24]' to 'SQLWCHAR*' {aka 'short
unsigned int*'} in assignment
qry = L"SELECT * FROM my_table;";
const wchar_t[24]
I could rewrite the code as:
std::wstring query = L"SELECT * FROM my_table;";
SQLWCHAR *qry = new SQLWCHAR[query.length() + 2];
memset( qry, '\0', query.length() + 2 );
const wchar_t *temp = src.c_str();
while( *qry )
{
qry++;
}
while( *temp )
{
*qry = *temp;
qry++;
temp++;
}
*qry++ = '\0';
*qry = '\0';
but using new
is expensive and slow.
Is there a better way?
EDIT:
My project settings in MSVC are:
/GS /analyze- /W4 /Zc:wchar_t /I"C:\Program Files (x86)\Visual Leak Detector\include" /I"..\dbinterface" /I"..\libhelpers" /Zi /Gm- /Od /Fd"vc_mswuddll\my_dll.pdb" /Zc:inline /fp:precise /D "__MEMORYLEAKS__" /D "WIN32" /D "_USRDLL" /D "DLL_EXPORTS" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE=1" /D "_CRT_NON_CONFORMING_SWPRINTFS=1" /D "_SCL_SECURE_NO_WARNINGS=1" /D "__WXMSW__" /D "_UNICODE" /D "WXUSINGDLL" /D "MY_DLL_BUILDING" /D "_WINDLL" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /Oy- /MDd /FC /Fa"vc_mswuddll\my_dll\" /EHsc /nologo /Fo"vc_mswuddll\my_dll\" /Fp"vc_mswuddll\my_dll\odbc.pch" /diagnostics:classic