odbccp32: Implement SQLInstallTranslator.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alistair Leslie-Hughes 2017-04-05 01:29:09 +00:00 committed by Alexandre Julliard
parent afaec19469
commit d687fc8f34
2 changed files with 74 additions and 6 deletions

View File

@ -41,6 +41,7 @@ static const WCHAR drivers_key[] = {'S','o','f','t','w','a','r','e','\\','O','D'
static const WCHAR odbcW[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C',0};
static const WCHAR odbcini[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','O','D','B','C','I','N','S','T','.','I','N','I','\\',0};
static const WCHAR odbcdrivers[] = {'O','D','B','C',' ','D','r','i','v','e','r','s',0};
static const WCHAR odbctranslators[] = {'O','D','B','C',' ','T','r','a','n','s','l','a','t','o','r','s',0};
/* This config mode is known to be process-wide.
* MSDN documentation suggests that the value is hidden somewhere in the registry but I haven't found it yet.
@ -636,6 +637,7 @@ static void write_registry_values(const WCHAR *regkey, const WCHAR *driver, cons
static const WCHAR slash[] = {'\\', 0};
static const WCHAR driverW[] = {'D','r','i','v','e','r',0};
static const WCHAR setupW[] = {'S','e','t','u','p',0};
static const WCHAR translator[] = {'T','r','a','n','s','l','a','t','o','r',0};
HKEY hkey, hkeydriver;
if (RegCreateKeyW(HKEY_LOCAL_MACHINE, odbcini, &hkey) == ERROR_SUCCESS)
@ -684,8 +686,9 @@ static void write_registry_values(const WCHAR *regkey, const WCHAR *driver, cons
divider++;
TRACE("Writing pair %s,%s\n", debugstr_w(entry), debugstr_w(divider));
/* Driver and Setup entries use the system path unless a path is specified. */
if(lstrcmpiW(driverW, entry) == 0 || lstrcmpiW(setupW, entry) == 0)
/* Driver, Setup, Translator entries use the system path unless a path is specified. */
if(lstrcmpiW(driverW, entry) == 0 || lstrcmpiW(setupW, entry) == 0 ||
lstrcmpiW(translator, entry) == 0)
{
len = lstrlenW(path) + lstrlenW(slash) + lstrlenW(divider) + 1;
value = heap_alloc(len * sizeof(WCHAR));
@ -976,7 +979,6 @@ BOOL WINAPI SQLInstallTranslatorExW(LPCWSTR lpszTranslator, LPCWSTR lpszPathIn,
WORD fRequest, LPDWORD lpdwUsageCount)
{
UINT len;
LPCWSTR p;
WCHAR path[MAX_PATH];
clear_errors();
@ -984,10 +986,9 @@ BOOL WINAPI SQLInstallTranslatorExW(LPCWSTR lpszTranslator, LPCWSTR lpszPathIn,
debugstr_w(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
fRequest, lpdwUsageCount);
for (p = lpszTranslator; *p; p += lstrlenW(p) + 1)
TRACE("%s\n", debugstr_w(p));
write_registry_values(odbctranslators, lpszTranslator, lpszPathIn, path, lpdwUsageCount);
len = GetSystemDirectoryW(path, MAX_PATH);
len = lstrlenW(path);
if (pcbPathOut)
*pcbPathOut = len;

View File

@ -473,6 +473,72 @@ static void test_SQLInstallDriverEx(void)
ok(cnt == 0, "SQLRemoveDriver failed %d\n", cnt);
}
void test_SQLInstallTranslatorEx(void)
{
char path[MAX_PATH];
char syspath[MAX_PATH];
WORD size = 0;
BOOL ret, sql_ret;
DWORD cnt, error_code = 0;
HKEY hkey;
LONG res;
GetSystemDirectoryA(syspath, MAX_PATH);
ret = SQLInstallTranslatorEx("WINE ODBC Translator\0Translator=sample.dll\0Setup=sample.dll\0",
NULL, path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL);
sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
if (sql_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED)
{
win_skip("not enough privileges\n");
return;
}
ok(sql_ret && error_code == SQL_SUCCESS, "SQLInstallDriverEx failed %d, %u\n", sql_ret, error_code);
ok(!strcmp(path, syspath), "invalid path %s\n", path);
ok(size == strlen(path), "invalid length %d\n", size);
ret = SQLInstallTranslatorEx("WINE ODBC Translator Path\0Translator=sample.dll\0Setup=sample.dll\0",
"c:\\temp", path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL);
sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
ok(sql_ret && error_code == SQL_SUCCESS, "SQLInstallTranslatorEx failed %d, %u\n", sql_ret, error_code);
ok(!strcmp(path, "c:\\temp"), "invalid path %s\n", path);
ok(size == strlen(path), "invalid length %d\n", size);
if(ret)
{
res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI\\WINE ODBC Translator", 0,
KEY_READ, &hkey);
ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
if (res == ERROR_SUCCESS)
{
DWORD type = 0xdeadbeef, size = MAX_PATH;
char driverpath[MAX_PATH];
strcpy(driverpath, syspath);
strcat(driverpath, "\\sample.dll");
memset(path, 0, sizeof(path));
res = RegQueryValueExA(hkey, "Translator", NULL, &type, (BYTE *)path, &size);
ok(res == ERROR_SUCCESS, "RegGetValueA failed\n");
ok(type == REG_SZ, "got %u\n", type);
ok(size == strlen(driverpath) + 1, "got %u\n", size);
ok(!strcmp(path, driverpath), "invalid path %s\n", path);
RegCloseKey(hkey);
}
}
cnt = 100;
ret = SQLRemoveTranslator("WINE ODBC Translator", &cnt);
todo_wine ok(ret, "SQLRemoveTranslator failed\n");
todo_wine ok(cnt == 0, "SQLRemoveTranslator failed %d\n", cnt);
cnt = 100;
ret = SQLRemoveTranslator("WINE ODBC Translator Path", &cnt);
todo_wine ok(ret, "SQLRemoveTranslator failed\n");
todo_wine ok(cnt == 0, "SQLRemoveTranslator failed %d\n", cnt);
}
START_TEST(misc)
{
test_SQLConfigMode();
@ -482,4 +548,5 @@ START_TEST(misc)
test_SQLGetPrivateProfileString();
test_SQLGetPrivateProfileStringW();
test_SQLInstallDriverEx();
test_SQLInstallTranslatorEx();
}