Re: mySQL and SQLDriverConnect

Igor Korot <[email protected]>
Newsgroups gmane.comp.db.unixodbc.devel
Message-ID <3872897.1214035854902.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net>

-----Original Message-----
>From: Igor Korot <[email protected]>
>Sent: Jun 21, 2008 2:38 AM
>To: Nick Gorham <[email protected]>, Development issues and topics for unixODBC <[email protected]>
>Subject: Re: [unixODBC-dev] mySQL and SQLDriverConnect
>
>Nick,
>
>-----Original Message-----
>>From: Nick Gorham <[email protected]>
>>Sent: Jun 20, 2008 12:16 PM
>>To: Igor Korot <[email protected]>, Development issues and topics for unixODBC <[email protected]>
>>Subject: Re: [unixODBC-dev] mySQL and SQLDriverConnect
>>
>>Igor Korot wrote:
>>
>>>Nick,
>>>
>>>-----Original Message-----
>>>  
>>>
>>>>From: Nick Gorham <[email protected]>
>>>>Sent: Jun 20, 2008 8:36 AM
>>>>To: Igor Korot <[email protected]>
>>>>Cc: Development issues and topics for unixODBC <[email protected]>
>>>>Subject: Re: [unixODBC-dev] mySQL and SQLDriverConnect
>>>>
>>>>Igor Korot wrote:
>>>>
>>>>    
>>>>
>>>>>>>     
>>>>>>>
>>>>>>>          
>>>>>>>
>>>>>>By the way, when you say you explicitly call the non unicode function, 
>>>>>>do you mean you call SQLDriverConnectA, becaue with UNICODE defined 
>>>>>>SQLDriverConnect becomes SQLDreiverConnectW (as it does in windows)
>>>>>>   
>>>>>>
>>>>>>        
>>>>>>
>>>>>retcode = SQLDriverConnect( m_hdbc, parentWnd, (SQLTCHAR FAR *)"DSN=test;", ...);
>>>>>                                               ^^^^^^^^^^^^^^
>>>>>
>>>>>I am doing casting of the parameters.
>>>>>In UNICODE version, this would become (SQLWCHAR FAR *).
>>>>>
>>>>>So, unless the linker is not smart, he should look at the proper signature of the
>>>>>function.
>>>>>
>>>>> 
>>>>>
>>>>>      
>>>>>
>>>>Not entirly correct
>>>>
>>>>(SQLTCHAR FAR *)"DSN=test;"
>>>>
>>>>when UNICODE is defined, will create a SQLWCHAR * pointer, but the thing it points to will still be a char string;
>>>>
>>>>I think thats the problem, you are passing the address 8bit string into a function thats expecting a 16bit sequence of values. Casting the pointer to a pointer of another type will not alter the thing thats being pointed to.
>>>>
>>>>Remember C will do what you tell it to, even if thats not what you want it to do :-)
>>>>    
>>>>
>>>
>>>Ok, it is very easy to check. ;-)
>>>It is morning here and I'm at work. When I come home, I will enable ODBC logging and run my
>>>program. Hopefully you are right, I was just banging my head over nothing and simply passing:
>>>"DSN=test;" without casting should fix the issue.
>>>  
>>>
>>
>>No, that sill wont work, you either need to pass  a wide string, or 
>>force the use of the ansi function
>>
>>SQLWCHAR str[] = { 'D','S','N','='.''t','e','s','t',';',0 };
>>SQLDriverConnect( ... str, SQL_NTS, ... );
>>
>>or
>>
>>SQLCHAR *str = "dsn=test;";
>>SQLDriverConnectA( ..., str, SQL_NTS, ... );
>>
>>-- 
>>Nick Gorham
>>Easysoft Limited
>>http://www.easysoft.com, http://www.unixODBC.org
>>
>
>I turned the logging on and here is the output and my code:
>
>[code]
>	wchar_t *temp_in = new wchar_t[connectStr.length()+1];
>	RETCODE retcode;
>	if( FwdOnlyCursors() )
>	{
>		retcode = SQLSetConnectOption( m_hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED );
>		if( retcode != SQL_SUCCESS )
>			wxLogError( _T( "SQLSetConnectionOption(CURSOR_LIB) failed!!" ) );
>	}
>	SQLTCHAR outConnectStr[SQL_MAX_CONNECTSTR_LEN+1];
>	short outConnectStrLen;
>	wxStrcpy( (char *) temp_in, connectStr );
>	temp_in[connectStr.length()] = '\0';
>	retcode = SQLDriverConnect( m_hdbc, parentWnd, (SQLTCHAR FAR *)temp_in, (SWORD) connectStr.length(), (SQLTCHAR FAR *) outConnectStr, WXSIZEOF( outConnectStr ), &outConnectStrLen, 
>#ifdef __WXMSW__
>	SQL_DRIVER_PROMPT );
>#endif
>#ifdef __WXGTK__
>	SQL_DRIVER_NOPROMPT );
>#endif
>[/code]
>
>where 
>connectStr = _T("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=test;User=root;Password=wasqra;Option=3;" )
>
>and the log:
>
>[code]
>[ODBC][6916][__handles.c][447]
>		Exit:[SQL_SUCCESS]
>			Environment = 0x81c7408
>[ODBC][6916][SQLSetEnvAttr.c][182]
>		Entry:            
>			Environment = 0x81c7408            
>			Attribute = SQL_ATTR_ODBC_VERSION            
>			Value = 0x3            
>			StrLen = 0
>[ODBC][6916][SQLSetEnvAttr.c][349]
>		Exit:[SQL_SUCCESS]
>[ODBC][6916][SQLAllocHandle.c][358]
>		Entry:
>			Handle Type = 2
>			Input Handle = 0x81c7408
>[ODBC][6916][SQLAllocHandle.c][476]
>		Exit:[SQL_SUCCESS]
>			Output Handle = 0x81c7998
>[ODBC][6916][SQLSetConnectOptionW.c][160]
>		Entry:            
>			Connection = 0x81c7998            
>			Option = SQL_ATTR_ODBC_CURSORS            
>			Value = 0
>[ODBC][6916][SQLDriverConnectW.c][246]
>		Entry:            
>			Connection = 0x81c7998            
>			Window Hdl = 0x8192180            
>			Str In = [Die=MSLOB .1Die}Sre=oahs;aaaets;srro;asodwsr;pin3][length = 98]            
>			Str Out = 0xbfac0bb0            
>			Str Out Max = 1025            
>			Str Out Ptr = 0xbfac1bb6            
>			Completion = 0
>[ODBC][6916][SQLDriverConnectW.c][433]Error: IM002
>[/code]
>
>So, it looks like the connection string is passed as a UNICODE in the UNICODE DM function.
>
>Thank you for the hint. Now I know what I need to look for...
>
>Thank you.


In addition:

connectStr is of type wxString.
Here is this class documented:

http://docs.wxwidgets.org/trunk/classwx_string.html

Thank you.
_______________________________________________
unixODBC-dev mailing list
[email protected]
http://mail.easysoft.com/mailman/listinfo/unixodbc-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.