[v4 PATCH 1/2] odbccp32: Implement SQLInstallTranslator
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Wed Apr 5 04:34:31 CDT 2017
v2 - Correct test to work under XP - Thanks Hans.
v3 - Correct Long lines.
- Removed extra \0
- Added size test.
v4 - No changes
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
dlls/odbccp32/odbccp32.c | 13 ++++-----
dlls/odbccp32/tests/misc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 6 deletions(-)
diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c
index 6a2c484379..7b2f020bbe 100644
--- a/dlls/odbccp32/odbccp32.c
+++ b/dlls/odbccp32/odbccp32.c
@@ -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;
diff --git a/dlls/odbccp32/tests/misc.c b/dlls/odbccp32/tests/misc.c
index 35b9f35033..7a6e8db3ef 100644
--- a/dlls/odbccp32/tests/misc.c
+++ b/dlls/odbccp32/tests/misc.c
@@ -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();
}
--
2.11.0
More information about the wine-patches
mailing list