[PATCH 2/2] odbccp32: Implement SQLRemoveTranslator/W

Huw Davies huw at codeweavers.com
Thu Apr 6 02:59:11 CDT 2017


On Wed, Apr 05, 2017 at 09:51:15AM +0000, Alistair Leslie-Hughes wrote:
> v3 - Fix trace message.
> v4 - Fixed assignment of usage_count
> 
> Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
> ---
>  dlls/odbccp32/odbccp32.c   | 69 +++++++++++++++++++++++++++++++++++++++++-----
>  dlls/odbccp32/tests/misc.c |  8 +++---
>  2 files changed, 66 insertions(+), 11 deletions(-)
> 
> diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c
> index 7b2f020bbe..161f2c2bd2 100644
> --- a/dlls/odbccp32/odbccp32.c
> +++ b/dlls/odbccp32/odbccp32.c
> @@ -1229,20 +1229,75 @@ BOOL WINAPI SQLRemoveDSNFromIni(LPCSTR lpszDSN)
>      return FALSE;
>  }
>  
> -BOOL WINAPI SQLRemoveTranslatorW(LPCWSTR lpszTranslator, LPDWORD lpdwUsageCount)
> +BOOL WINAPI SQLRemoveTranslatorW(const WCHAR *translator, DWORD *usage_count)
>  {
> +    HKEY hkey;
> +    DWORD usagecount = 1;
> +
>      clear_errors();
> -    FIXME("%s %p\n", debugstr_w(lpszTranslator), lpdwUsageCount);
> -    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
> -    return FALSE;
> +    TRACE("%s %p\n", debugstr_w(translator), usage_count);
> +
> +    if (RegOpenKeyW(HKEY_LOCAL_MACHINE, odbcini, &hkey) == ERROR_SUCCESS)
> +    {
> +        HKEY hkeydriver;
> +
> +        if (RegOpenKeyW(hkey, translator, &hkeydriver) == ERROR_SUCCESS)
> +        {
> +            DWORD size, type;
> +            DWORD count;
> +
> +            size = sizeof(usagecount);
> +            RegGetValueA(hkeydriver, NULL, "UsageCount", RRF_RT_DWORD, &type, &usagecount, &size);
> +            TRACE("Usage count %d\n", usagecount);
> +            count = usagecount - 1;
> +            if (count)
> +            {
> +                 if (RegSetValueExA(hkeydriver, "UsageCount", 0, REG_DWORD, (BYTE*)&count, sizeof(count)) != ERROR_SUCCESS)
> +                    ERR("Failed to write registry UsageCount key\n");
> +            }
> +
> +            RegCloseKey(hkeydriver);
> +        }
> +
> +        if (usagecount)
> +            usagecount--;
> +
> +        if (!usagecount)
> +        {
> +            if(RegDeleteKeyW(hkey, translator) != ERROR_SUCCESS)
> +                ERR("Failed to delete registry key: %s\n", debugstr_w(translator));
> +
> +            if (RegOpenKeyW(hkey, odbctranslators, &hkeydriver) == ERROR_SUCCESS)
> +            {
> +                if(RegDeleteValueW(hkeydriver, translator) != ERROR_SUCCESS)
> +                    ERR("Failed to delete registry value: %s\n", debugstr_w(translator));
> +
> +                RegCloseKey(hkeydriver);
> +            }
> +        }
> +
> +        RegCloseKey(hkey);
> +    }
> +
> +    if (usage_count)
> +        *usage_count = usagecount;
> +
> +    return TRUE;
>  }

Sorry, I've just noticed that this returns TRUE even if the requested
translator isn't installed, which is not correct.  A test for that
would be good too.

Huw.



More information about the wine-devel mailing list