[unixODBC-support] HELP

Lizarazu Hernando, Juncal juncal.lizarazu at ikusi.com
Fri Jan 28 10:59:00 GMT 2011


Hi everybody,

 

            I have some trouble with the driver manager unixODBC and
MySQL working in UNICODE. I do not know if I am doing something wrong. I
am working with:

- driver unixODBC-2.3.0

- connector of MySQL: libmyodbc5.so 

 

            If I have understook well, both of them work with Unicode.
My doubt is if I need to do any special configuration for this in my
source program or in the unixODBC configuration. The problem is that to
get/insert datas into the database I have to do conversion of data with
and specific function.

            Next my program:

 

           #include <sql.h>

                 //#define SQL_WCHART_CONVERT      /// QUESTION:   IS IT
NECESSARY THIS 'define'?????

          #include <sqlext.h>

          #include <sqlucode.h>

          #include <wchar.h>

          #include <stdio.h>

 

            int main (int argc, wchar_t *argv[])

            {

            wchar_t dsn[254],st[254],code[20],text[250];

 SQLWCHAR dato[254],wst[254];

 

 SQLAllocEnv(&henv);

 SQLAllocConnect(henv, &hdbc);

 
SQLSetConnectAttrW(hdbc,SQL_ATTR_ANSI_APP,(SQLPOINTER)SQL_AA_FALSE,SQL_I
S_INTEGER);

 

 wcscpy(dsn,L"DSN=myconex;");

 wstrconvert(dato,dsn);

 

 
SQLDriverConnectW(hdbc,NULL,dato,SQL_NTS,NULL,0,NULL,SQL_DRIVER_NOPROMPT
);

 

 SQLAllocStmt(hdbc, &hstmts1);

 

 wcscpy(st,L"select * from prueba where code='EVA003'");   /* Get one
row from the table prueba */

 wstrconvert(wst,st);

 

SQLExecDirectW(hstmts1,wst,SQL_NTS);

SQLBindCol(hstmts1, 1, SQL_WCHAR, wcode, 20, &cb_code);

SQLBindCol(hstmts1, 2, SQL_WCHAR, wtext, 250, &cb_text);

Result = SQLFetch(hstmts1);

if (cb_code == SQL_NULL_DATA)  *wcode=0;

if (cb_text == SQL_NULL_DATA)  *wtext=0;

 

strconvert(code,wcode);

strconvert(text,wtext);

 

SQLFreeStmt(hstmts1, SQL_UNBIND);

SQLFreeStmt(hstmts1, SQL_DROP);

 

           SQLAllocStmt(hdbc, &hstmts2);                      /* And now
insert the row in the table prueba2 */

           swprintf(st,250,L"INSERT INTO prueba2 VALUES
('%S','%S')",code,text);

         

           wstrconvert(wst,st);

 

          SQLExecDirectW(hstmts2,wst,SQL_NTS);

          SQLFreeStmt(hstmts2, SQL_DROP);

          

          SQLDisconnect(hdbc);

          SQLFreeConnect(hdbc);

          SQLFreeEnv(henv);

         }

 

And the functions are :

 

void wstrconvert(SQLWCHAR *out, wchar_t *in)

{

while (*in)

 {

  *out++ = *in++;

 }

*out = 0;

}

 

void strconvert(wchar_t *out, SQLWCHAR *in)

{

while (*in)

 {

  *out++ = *in++;

 }

*out = 0;

}

 

I am very surprised by having to add the pink lines so that the program
works. I expected that the odbc would work without any conversion of
data types. Might it be that I have to do any specific configuration or
is there anything wrong? Can the odbc do this conversions automatically?

 

I would be very grateful if you help me solving this trouble.

Looking forward to your answer.

Thanks in advance.

Regards.

 

Juncal.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20110128/4dffc5af/attachment.html>


More information about the unixODBC-support mailing list