odbccp32: Implement SQLWritePrivateProfileStringA/W.

oldstable
Alistair Leslie-Hughes 2015-03-04 16:26:28 +11:00 committed by Alexandre Julliard
parent ef41e8205a
commit 67acce4aa6
3 changed files with 140 additions and 7 deletions

View File

@ -56,6 +56,7 @@ static const WCHAR odbc_error_invalid_buff_len[] = {'I','n','v','a','l','i','d',
static const WCHAR odbc_error_component_not_found[] = {'C','o','m','p','o','n','e','n','t',' ','n','o','t',' ','f','o','u','n','d',0};
static const WCHAR odbc_error_out_of_mem[] = {'O','u','t',' ','o','f',' ','m','e','m','o','r','y',0};
static const WCHAR odbc_error_invalid_param_sequence[] = {'I','n','v','a','l','i','d',' ','p','a','r','a','m','e','t','e','r',' ','s','e','q','u','e','n','c','e',0};
static const WCHAR odbc_error_invalid_param_string[] = {'I','n','v','a','l','i','d',' ','p','a','r','a','m','e','t','e','r',' ','s','t','r','i','n','g',0};
/* Push an error onto the error stack, taking care of ranges etc. */
static void push_error(int code, LPCWSTR msg)
@ -74,6 +75,33 @@ static void clear_errors(void)
num_errors = 0;
}
static inline void * heap_alloc(size_t len)
{
return HeapAlloc(GetProcessHeap(), 0, len);
}
static inline BOOL heap_free(void *mem)
{
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline WCHAR *heap_strdupAtoW(const char *str)
{
LPWSTR ret = NULL;
if(str) {
DWORD len;
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
ret = heap_alloc(len*sizeof(WCHAR));
if(ret)
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
}
return ret;
}
BOOL WINAPI ODBCCPlApplet( LONG i, LONG j, LONG * p1, LONG * p2)
{
clear_errors();
@ -965,17 +993,62 @@ BOOL WINAPI SQLWriteFileDSN(LPCSTR lpszFileName, LPCSTR lpszAppName,
BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry,
LPCWSTR lpszString, LPCWSTR lpszFilename)
{
LONG ret;
HKEY hkey;
WCHAR softwareodbc[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C',0};
clear_errors();
FIXME("\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
TRACE("%s %s %s %s\n", debugstr_w(lpszSection), debugstr_w(lpszEntry),
debugstr_w(lpszString), debugstr_w(lpszFilename));
if(!lpszFilename || !*lpszFilename)
{
push_error(ODBC_ERROR_INVALID_STR, odbc_error_invalid_param_string);
return FALSE;
}
if ((ret = RegCreateKeyW(HKEY_CURRENT_USER, softwareodbc, &hkey)) == ERROR_SUCCESS)
{
HKEY hkeyfilename;
if ((ret = RegCreateKeyW(hkey, lpszFilename, &hkeyfilename)) == ERROR_SUCCESS)
{
HKEY hkey_section;
if ((ret = RegCreateKeyW(hkeyfilename, lpszSection, &hkey_section)) == ERROR_SUCCESS)
{
ret = RegSetValueExW(hkey_section, lpszEntry, 0, REG_SZ, (BYTE*)lpszString, (lstrlenW(lpszString)+1)*sizeof(WCHAR));
RegCloseKey(hkey_section);
}
RegCloseKey(hkeyfilename);
}
RegCloseKey(hkey);
}
return ret == ERROR_SUCCESS;
}
BOOL WINAPI SQLWritePrivateProfileString(LPCSTR lpszSection, LPCSTR lpszEntry,
LPCSTR lpszString, LPCSTR lpszFilename)
{
BOOL ret;
WCHAR *sect, *entry, *string, *file;
clear_errors();
FIXME("\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
TRACE("%s %s %s %s\n", lpszSection, lpszEntry, lpszString, lpszFilename);
sect = heap_strdupAtoW(lpszSection);
entry = heap_strdupAtoW(lpszEntry);
string = heap_strdupAtoW(lpszString);
file = heap_strdupAtoW(lpszFilename);
ret = SQLWritePrivateProfileStringW(sect, entry, string, file);
heap_free(sect);
heap_free(entry);
heap_free(string);
heap_free(file);
return ret;
}

View File

@ -1,5 +1,5 @@
TESTDLL = odbccp32.dll
IMPORTS = odbccp32
IMPORTS = odbccp32 advapi32
C_SRCS = \
misc.c

View File

@ -21,6 +21,7 @@
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "odbcinst.h"
static void test_SQLConfigMode(void)
@ -129,9 +130,68 @@ static void test_SQLInstallDriverManager(void)
ok(path_out != 0xcafe, "Expected path_out to show the correct amount of bytes\n");
}
static void test_SQLWritePrivateProfileString(void)
{
static const WCHAR odbc_key[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','O','D','B','C','.','I','N','I','\\','w','i','n','e','o','d','b','c',0};
static const WCHAR abcd_key[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','a','b','c','d','.','I','N','I','\\','w','i','n','e','o','d','b','c',0};
static const WCHAR abcdini_key[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','a','b','c','d','.','I','N','I',0 };
BOOL ret;
LONG reg_ret;
DWORD error_code;
ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "");
ok(!ret, "SQLWritePrivateProfileString passed\n");
SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %d\n", error_code);
ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", NULL);
ok(!ret, "SQLWritePrivateProfileString passed\n");
SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %d\n", error_code);
ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "odbc.ini");
ok(ret, "SQLWritePrivateProfileString failed\n");
if(ret)
{
HKEY hkey;
reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, odbc_key, 0, KEY_READ, &hkey);
ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
if(reg_ret == ERROR_SUCCESS)
{
reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, odbc_key);
ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
RegCloseKey(hkey);
}
}
ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "abcd.ini");
ok(ret, "SQLWritePrivateProfileString failed\n");
if(ret)
{
HKEY hkey;
reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey);
ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
if(reg_ret == ERROR_SUCCESS)
{
reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key);
ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
RegCloseKey(hkey);
}
/* Cleanup key */
reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key);
ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
}
}
START_TEST(misc)
{
test_SQLConfigMode();
test_SQLInstallerError();
test_SQLInstallDriverManager();
test_SQLWritePrivateProfileString();
}