From wstring to SQLCHAR

Go To StackoverFlow.com

0

what i need to do is to execute an SQL query:

wstring query = ( L "INSERT INTO database...........;

then i execute this:

CHECK( SQLExecDirectA( hStmt, query, SQL_NTS ), "execute query" );

but it doesn't compile, because the variable query must be an SQLCHAR otherwise function SQLExecDirectA wont work.

can anyone help please?

thanks!

2012-04-04 22:37
by Martin Ignacio Lopez
Do you have to use wstring instead of string - Éric Malenfant 2012-04-04 23:09
Besides the answer from David Feurle, you have to remember that std::wstring (or std::string) can not be converted directly to wchar_t * (or char *). You have to use e.g. query.c_str() to get a character pointer - Some programmer dude 2012-04-05 06:05


2

The function you are trying to call is called SQLExecDirect. (Nearly) all the functions in the winapi exist in two version - a ascii version and a wide version. Depending on your project settings (Multibyte character set/Unicode) SQLExecDirect is a define to either SQLExecDirectA or SQLExecDirectW (with SQLExecDirectA beeing the ascci version and SQLExecDirectW beeing the wide version).

The SQLExecDirectA means your are explicitely calling the ascii version with a wide string as parameter. Try calling SQLExecDirectW or SQLExecDirect if you want to use wide strings.

2012-04-05 05:20
by David Feurle
Ads