Index: test/my_unicode.c =================================================================== --- test/my_unicode.c (revision 1044) +++ test/my_unicode.c (working copy) @@ -1029,6 +1029,90 @@ } +/* + Bug#28168 odbc, non 7-bit password, connection failed +*/ +DECLARE_TEST(t_bug28168) +{ + SQLHANDLE hdbc1; + + wchar_t conn_in[512]= {0}; + wchar_t dummy[256]= {0}; + wchar_t *wstr; + SQLWCHAR errmsgtxt[256]= {0}; + SQLSMALLINT errmsglen; + + ok_env(henv, SQLAllocConnect(henv, &hdbc1)); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug28168"); + ok_sql(hstmt, "CREATE TABLE t_bug28168 (x int)"); + + ok_stmt(hstmt, + SQLExecDirectW(hstmt, + W(L"GRANT ALL ON t_bug28168 to " + L"'\x03A8\x0391\x03A1\x039F uid'@" + L"localhost identified by " + L"'\x03A8\x0391\x03A1\x039F pwd'"), + SQL_NTS)); + + ok_env(henv, SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1)); + + *conn_in= L'\0'; + wcscat(conn_in, L"DRIVER="); + mbstowcs(dummy, (char *)mydriver, sizeof(dummy)); + wcscat(conn_in, dummy); + wcscat(conn_in, L";UID="); + wcscat(conn_in, L"{\x03A8\x0391\x03A1\x039F uid}"); + wcscat(conn_in, L";PWD="); + wcscat(conn_in, L"{\x03A8\x0391\x03A1\x039F pwd}"); + wcscat(conn_in, L";DATABASE="); + mbstowcs(dummy, (char *)mydb, sizeof(dummy)); + wcscat(conn_in, dummy); + wcscat(conn_in, L";SERVER="); + mbstowcs(dummy, (char *)myserver, sizeof(dummy)); + wcscat(conn_in, dummy); + if (mysock != NULL) + { + wcscat(conn_in, L";SOCKET="); + mbstowcs(dummy, (char *)mysock, sizeof(dummy)); + wcscat(conn_in, dummy); + } + + ok_con(hdbc1, SQLDriverConnectW(hdbc1, NULL, W(conn_in), SQL_NTS, NULL, 0, + NULL, SQL_DRIVER_NOPROMPT)); + ok_con(hdbc1, SQLDisconnect(hdbc1)); + + /* we change the password in the connection string to test the error msg */ + wstr= wcsstr(conn_in, L" pwd}") - 4; + *wstr++= 'x'; + + expect_dbc(hdbc1, SQLDriverConnectW(hdbc1, NULL, W(conn_in), SQL_NTS, NULL, + 0, NULL, SQL_DRIVER_NOPROMPT), + SQL_ERROR); + ok_con(hdbc1, SQLGetDiagFieldW(SQL_HANDLE_DBC, hdbc1, 1, + SQL_DIAG_MESSAGE_TEXT, errmsgtxt, + 256 * sizeof(SQLWCHAR), &errmsglen)); + swprintf(dummy, 256, L"[MySQL][ODBC 5.1 Driver]Access denied for user " + L"'\x03A8\x0391\x03A1\x039F uid'@'localhost' " + L"(using password: YES)"); + + if (sizeof(SQLWCHAR) == sizeof(wchar_t)) + { + printMessage("expected msg: %ls\n", dummy); + printMessage("actual msg: %ls\n", errmsgtxt); + } + + is(!memcmp(errmsgtxt, W(dummy), wcslen(dummy) * sizeof(SQLWCHAR))); + is_num(errmsglen, wcslen(dummy) * sizeof(SQLWCHAR)); + + ok_con(hdbc1, SQLFreeHandle(SQL_HANDLE_DBC, hdbc1)); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug28168"); + + return OK; +} + + BEGIN_TESTS ADD_TEST(sqlconnect) ADD_TEST(sqlprepare) @@ -1050,6 +1134,7 @@ ADD_TEST(sqlprimarykeys) ADD_TEST(sqlstatistics) ADD_TEST(t_bug32161) + ADD_TEST(t_bug28168) END_TESTS Index: driver/connect.c =================================================================== --- driver/connect.c (revision 1044) +++ driver/connect.c (working copy) @@ -213,6 +213,7 @@ We always use utf8 for the connection, and change it afterwards if needed. */ mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8"); + dbc->cxn_charset_info= utf8_charset_info; if (!mysql_real_connect(mysql, ds_get_utf8attr(ds->server, &ds->server8),