Commit 94667def authored by Alistair Leslie-Hughes's avatar Alistair Leslie-Hughes Committed by Alexandre Julliard

odbccp32: Implement SQLGetPrivateProfileStringW/SQLGetPrivateProfileString.

parent 376fe634
......@@ -399,28 +399,177 @@ BOOL WINAPI SQLGetInstalledDrivers(LPSTR lpszBuf, WORD cbBufMax,
return ret;
}
int WINAPI SQLGetPrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry,
LPCWSTR lpszDefault, LPCWSTR RetBuffer, int cbRetBuffer,
LPCWSTR lpszFilename)
static HKEY get_privateprofile_sectionkey(LPCWSTR section, LPCWSTR filename)
{
static const WCHAR odbcW[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\',0};
HKEY hkey, hkeyfilename, hkeysection;
LONG ret;
if (RegOpenKeyW(HKEY_CURRENT_USER, odbcW, &hkey))
return NULL;
ret = RegOpenKeyW(hkey, filename, &hkeyfilename);
RegCloseKey(hkey);
if (ret)
return NULL;
ret = RegOpenKeyW(hkeyfilename, section, &hkeysection);
RegCloseKey(hkeyfilename);
return ret ? NULL : hkeysection;
}
int WINAPI SQLGetPrivateProfileStringW(LPCWSTR section, LPCWSTR entry,
LPCWSTR defvalue, LPWSTR buff, int buff_len, LPCWSTR filename)
{
BOOL usedefault = TRUE;
HKEY sectionkey;
LONG ret = 0;
TRACE("%s %s %s %p %d %s\n", debugstr_w(section), debugstr_w(entry),
debugstr_w(defvalue), buff, buff_len, debugstr_w(filename));
clear_errors();
FIXME("%s %s %s %p %d %s\n", debugstr_w(lpszSection), debugstr_w(lpszEntry),
debugstr_w(lpszDefault), RetBuffer, cbRetBuffer,
debugstr_w(lpszFilename));
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
if (buff_len <= 0 || !section)
return 0;
if(buff)
buff[0] = 0;
if (!defvalue || !buff)
return 0;
sectionkey = get_privateprofile_sectionkey(section, filename);
if (sectionkey)
{
DWORD type, size;
if (entry)
{
size = buff_len * sizeof(*buff);
if (RegGetValueW(sectionkey, NULL, entry, RRF_RT_REG_SZ, &type, buff, &size) == ERROR_SUCCESS)
{
usedefault = FALSE;
ret = (size / sizeof(*buff)) - 1;
}
}
else
{
WCHAR name[MAX_PATH];
DWORD index = 0;
DWORD namelen;
usedefault = FALSE;
memset(buff, 0, buff_len);
namelen = sizeof(name);
while (RegEnumValueW(sectionkey, index, name, &namelen, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
if ((ret + namelen+1) > buff_len)
break;
lstrcpyW(buff+ret, name);
ret += namelen+1;
namelen = sizeof(name);
index++;
}
}
RegCloseKey(sectionkey);
}
else
usedefault = entry != NULL;
if (usedefault)
{
lstrcpynW(buff, defvalue, buff_len);
ret = lstrlenW(buff);
}
return ret;
}
int WINAPI SQLGetPrivateProfileString(LPCSTR lpszSection, LPCSTR lpszEntry,
LPCSTR lpszDefault, LPCSTR RetBuffer, int cbRetBuffer,
LPCSTR lpszFilename)
int WINAPI SQLGetPrivateProfileString(LPCSTR section, LPCSTR entry,
LPCSTR defvalue, LPSTR buff, int buff_len, LPCSTR filename)
{
WCHAR *sectionW, *filenameW;
BOOL usedefault = TRUE;
HKEY sectionkey;
LONG ret = 0;
TRACE("%s %s %s %p %d %s\n", debugstr_a(section), debugstr_a(entry),
debugstr_a(defvalue), buff, buff_len, debugstr_a(filename));
clear_errors();
FIXME("%s %s %s %p %d %s\n", debugstr_a(lpszSection), debugstr_a(lpszEntry),
debugstr_a(lpszDefault), RetBuffer, cbRetBuffer,
debugstr_a(lpszFilename));
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
if (buff_len <= 0)
return 0;
if (buff)
buff[0] = 0;
if (!section || !defvalue || !buff)
return 0;
sectionW = heap_strdupAtoW(section);
filenameW = heap_strdupAtoW(filename);
sectionkey = get_privateprofile_sectionkey(sectionW, filenameW);
heap_free(sectionW);
heap_free(filenameW);
if (sectionkey)
{
DWORD type, size;
if (entry)
{
size = buff_len * sizeof(*buff);
if (RegGetValueA(sectionkey, NULL, entry, RRF_RT_REG_SZ, &type, buff, &size) == ERROR_SUCCESS)
{
usedefault = FALSE;
ret = (size / sizeof(*buff)) - 1;
}
}
else
{
char name[MAX_PATH] = {0};
DWORD index = 0;
DWORD namelen;
usedefault = FALSE;
memset(buff, 0, buff_len);
namelen = sizeof(name);
while (RegEnumValueA(sectionkey, index, name, &namelen, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
if ((ret + namelen+1) > buff_len)
break;
lstrcpyA(buff+ret, name);
ret += namelen+1;
namelen = sizeof(name);
index++;
}
}
RegCloseKey(sectionkey);
}
else
usedefault = entry != NULL;
if (usedefault)
{
lstrcpynA(buff, defvalue, buff_len);
ret = strlen(buff);
}
return ret;
}
BOOL WINAPI SQLGetTranslatorW(HWND hwndParent, LPWSTR lpszName, WORD cbNameMax,
......
......@@ -24,6 +24,10 @@
#include "winreg.h"
#include "odbcinst.h"
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 };
static void test_SQLConfigMode(void)
{
BOOL bool_ret;
......@@ -133,8 +137,6 @@ static void test_SQLInstallDriverManager(void)
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;
......@@ -188,10 +190,229 @@ static void test_SQLWritePrivateProfileString(void)
}
}
static void test_SQLGetPrivateProfileString(void)
{
int ret;
char buffer[256] = {0};
LONG reg_ret;
strcpy(buffer, "wine");
ret = SQLGetPrivateProfileString(NULL, "testing" , "default", buffer, 256, "ODBC.INI");
ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer);
strcpy(buffer, "wine");
ret = SQLGetPrivateProfileString("wineodbc", NULL , "default", buffer, 256, "ODBC.INI");
ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer);
strcpy(buffer, "value");
ret = SQLGetPrivateProfileString("wineodbc", "testing" , NULL, buffer, 256, "ODBC.INI");
ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer);
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 256, "ODBC.INI");
ok(ret == strlen("defaultX"), "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, "defaultX"), "incorrect string '%s'\n", buffer);
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 4, "ODBC.INI");
ok(ret == strlen("def"), "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, "def"), "incorrect string '%s'\n", buffer);
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 8, "ODBC.INI");
ok(ret == strlen("default"), "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, "default"), "incorrect string '%s'\n", buffer);
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", NULL, 256, "ODBC.INI");
ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
strcpy(buffer, "value");
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 0, "ODBC.INI");
ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, "value"), "incorrect string '%s'\n", buffer);
ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini");
ok(ret, "SQLWritePrivateProfileString failed\n");
if(ret)
{
HKEY hkey;
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", buffer, 256, "abcd.ini");
ok(ret == strlen("value0123456789"), "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, "value0123456789"), "incorrect string '%s'\n", buffer);
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", NULL, 0, "abcd.ini");
ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", buffer, 7, "abcd.ini");
ok(ret == 6, "SQLGetPrivateProfileString returned %d\n", ret);
strcpy(buffer, "wine");
ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 10, "abcd.ini");
ok(ret == (strlen("testing")+1), "SQLGetPrivateProfileString returned %d\n", ret);
ok(!strcmp(buffer, "testing"), "incorrect string '%s'\n", buffer);
ret = SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini");
ok(ret, "SQLWritePrivateProfileString failed\n");
strcpy(buffer, "wine");
ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 256, "abcd.ini");
ok(ret == (strlen("testing") + strlen("value")+2), "SQLGetPrivateProfileString returned %d\n", ret);
if(ret >= (strlen("testing") + strlen("value")+2))
{
ok(memcmp(buffer, "testing\0value\0", 14) == 0, "incorrect string '%s'\n", buffer);
}
strcpy(buffer, "XXXXXXXXXXXXXXX");
ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 10, "abcd.ini");
ok(ret == (strlen("testing")+1), "SQLGetPrivateProfileString returned %d\n", ret);
if(ret >= (strlen("testing")+1))
{
ok(!strcmp(buffer, "testing"), "incorrect string '%s'\n", buffer);
/* Show that the buffer is cleared and partial enteries aren't added */
ok(memcmp(buffer, "testing\0X", 9) != 0, "incorrect string '%s'\n", buffer);
}
strcpy(buffer, "wine");
ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 2, "abcd.ini");
ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
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");
}
}
static void test_SQLGetPrivateProfileStringW(void)
{
static WCHAR testing[] = {'t','e','s','t','i','n','g',0};
static WCHAR wineodbc[] = {'w','i','n','e','o','d','b','c',0};
static WCHAR defaultval[] = {'d','e','f','a','u','l','t',0};
static WCHAR odbcini[] = {'O','D','B','C','.','I','N','I',0};
static WCHAR abcdini[] = {'a','b','c','d','.','I','N','I',0};
static WCHAR wine[] = {'w','i','n','e',0};
static WCHAR value[] = {'v','a','l','u','e',0};
static WCHAR empty[] = {0};
static WCHAR defaultX[] = {'d','e','f','a','u','l','t',0};
static WCHAR def[] = {'d','e','f',0};
static WCHAR value0[] = {'v','a','l','u','e','0','1','2','3','4','5','6','7','8','9',0};
static WCHAR testingvalue[] = {'t','e','s','t','i','n','g',0,'v','a','l','u','e',0};
int ret;
WCHAR buffer[256] = {0};
LONG reg_ret;
lstrcpyW(buffer, wine);
ret = SQLGetPrivateProfileStringW(NULL, testing , defaultval, buffer, 256, odbcini);
ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, wine), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
lstrcpyW(buffer, wine);
ret = SQLGetPrivateProfileStringW(wineodbc, NULL , defaultval, buffer, 256, odbcini);
ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, empty), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
lstrcpyW(buffer, value);
ret = SQLGetPrivateProfileStringW(wineodbc, testing , NULL, buffer, 256, odbcini);
ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, empty), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 256, odbcini);
ok(ret == lstrlenW(defaultX), "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, defaultX), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 4, odbcini);
ok(ret == lstrlenW(def), "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, def), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 8, odbcini);
ok(ret == lstrlenW(defaultX), "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, defaultX), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, NULL, 256, odbcini);
ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
lstrcpyW(buffer, value);
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 0, odbcini);
ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, value), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini");
ok(ret, "SQLWritePrivateProfileString failed\n");
if(ret)
{
HKEY hkey;
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 256, abcdini);
ok(ret == lstrlenW(value0), "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, value0), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, NULL, 0, abcdini);
ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 7, abcdini);
ok(ret == 6, "SQLGetPrivateProfileStringW returned %d\n", ret);
lstrcpyW(buffer, wine);
ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 10, abcdini);
ok(ret == lstrlenW(testing)+1, "SQLGetPrivateProfileStringW returned %d\n", ret);
ok(!lstrcmpW(buffer, testing), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
ret = SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini");
ok(ret, "SQLWritePrivateProfileString failed\n");
lstrcpyW(buffer, wine);
ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 256, abcdini);
ok(ret == (lstrlenW(testing) + lstrlenW(value)+2), "SQLGetPrivateProfileStringW returned %d\n", ret);
if(ret == (lstrlenW(testing) + lstrlenW(value)+2))
{
ok(!memcmp(buffer, testingvalue, sizeof(testingvalue)),
"incorrect string '%s'\n", wine_dbgstr_wn(buffer, ret));
}
lstrcpyW(buffer, value);
ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 10, abcdini);
ok(ret == lstrlenW(testing)+1, "SQLGetPrivateProfileStringW returned %d\n", ret);
if(ret >= lstrlenW(testing)+1)
{
ok(!lstrcmpW(buffer, testing), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
}
lstrcpyW(buffer, value);
ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 2, abcdini);
ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
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();
test_SQLGetPrivateProfileString();
test_SQLGetPrivateProfileStringW();
}
......@@ -84,8 +84,8 @@ BOOL WINAPI SQLGetAvailableDriversW(LPCWSTR,LPWSTR,WORD,WORD*);
BOOL WINAPI SQLGetConfigMode(UWORD*);
BOOL WINAPI SQLGetInstalledDrivers(LPSTR,WORD,WORD*);
BOOL WINAPI SQLGetInstalledDriversW(LPWSTR,WORD,WORD*);
int WINAPI SQLGetPrivateProfileString(LPCSTR,LPCSTR,LPCSTR,LPCSTR,int,LPCSTR);
int WINAPI SQLGetPrivateProfileStringW(LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,int,LPCWSTR);
int WINAPI SQLGetPrivateProfileString(LPCSTR,LPCSTR,LPCSTR,LPSTR,int,LPCSTR);
int WINAPI SQLGetPrivateProfileStringW(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,int,LPCWSTR);
BOOL WINAPI SQLGetTranslator(HWND,LPSTR,WORD,WORD*,LPSTR,WORD,WORD*,DWORD*);
BOOL WINAPI SQLGetTranslatorW(HWND,LPWSTR,WORD,WORD*,LPWSTR,WORD,WORD*,DWORD*);
BOOL WINAPI SQLInstallDriver(LPCSTR,LPCSTR,LPSTR,WORD,WORD*);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment