d3d8: Avoid '\n' in middle of TRACE() messages.
[wine.git] / dlls / odbccp32 / odbccp32.c
blobbc643d46db81fad4c8c0deeda02f6ccdbaaa482b
1 /*
2 * Implementation of the ODBC driver installer
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2005 Hans Leidekker
6 * Copyright 2007 Bill Medland
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <assert.h>
24 #include <stdarg.h>
26 #define COBJMACROS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winnls.h"
32 #include "wine/debug.h"
34 #include "odbcinst.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(odbc);
38 /* Registry key names */
39 static const WCHAR drivers_key[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','O','D','B','C','I','N','S','T','.','I','N','I','\\','O','D','B','C',' ','D','r','i','v','e','r','s',0};
40 static const WCHAR odbcW[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C',0};
42 /* This config mode is known to be process-wide.
43 * MSDN documentation suggests that the value is hidden somewhere in the registry but I haven't found it yet.
44 * Although both the registry and the ODBC.ini files appear to be maintained together they are not maintained automatically through the registry's IniFileMapping.
46 static UWORD config_mode = ODBC_BOTH_DSN;
48 /* MSDN documentation suggests that the error subsystem handles errors 1 to 8
49 * only and experimentation (Windows 2000) shows that the errors are process-
50 * wide so go for the simple solution; static arrays.
52 static int num_errors;
53 static int error_code[8];
54 static const WCHAR *error_msg[8];
55 static const WCHAR odbc_error_general_err[] = {'G','e','n','e','r','a','l',' ','e','r','r','o','r',0};
56 static const WCHAR odbc_error_invalid_buff_len[] = {'I','n','v','a','l','i','d',' ','b','u','f','f','e','r',' ','l','e','n','g','t','h',0};
57 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};
58 static const WCHAR odbc_error_out_of_mem[] = {'O','u','t',' ','o','f',' ','m','e','m','o','r','y',0};
59 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};
60 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};
62 /* Push an error onto the error stack, taking care of ranges etc. */
63 static void push_error(int code, LPCWSTR msg)
65 if (num_errors < sizeof error_code/sizeof error_code[0])
67 error_code[num_errors] = code;
68 error_msg[num_errors] = msg;
69 num_errors++;
73 /* Clear the error stack */
74 static void clear_errors(void)
76 num_errors = 0;
79 static inline void * heap_alloc(size_t len)
81 return HeapAlloc(GetProcessHeap(), 0, len);
84 static inline BOOL heap_free(void *mem)
86 return HeapFree(GetProcessHeap(), 0, mem);
89 static inline WCHAR *heap_strdupAtoW(const char *str)
91 LPWSTR ret = NULL;
93 if(str) {
94 DWORD len;
96 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
97 ret = heap_alloc(len*sizeof(WCHAR));
98 if(ret)
99 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
102 return ret;
106 BOOL WINAPI ODBCCPlApplet( LONG i, LONG j, LONG * p1, LONG * p2)
108 clear_errors();
109 FIXME( "( %d %d %p %p) : stub!\n", i, j, p1, p2);
110 return FALSE;
113 static LPWSTR SQLInstall_strdup_multi(LPCSTR str)
115 LPCSTR p;
116 LPWSTR ret = NULL;
117 DWORD len;
119 if (!str)
120 return ret;
122 for (p = str; *p; p += lstrlenA(p) + 1)
125 len = MultiByteToWideChar(CP_ACP, 0, str, p - str, NULL, 0 );
126 ret = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
127 MultiByteToWideChar(CP_ACP, 0, str, p - str, ret, len );
128 ret[len] = 0;
130 return ret;
133 static LPWSTR SQLInstall_strdup(LPCSTR str)
135 DWORD len;
136 LPWSTR ret = NULL;
138 if (!str)
139 return ret;
141 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0 );
142 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
143 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len );
145 return ret;
148 /* Convert the wide string or zero-length-terminated list of wide strings to a
149 * narrow string or zero-length-terminated list of narrow strings.
150 * Do not try to emulate windows undocumented excesses (e.g. adding a third \0
151 * to a list)
152 * Arguments
153 * mode Indicates the sort of string.
154 * 1 denotes that the buffers contain strings terminated by a single nul
155 * character
156 * 2 denotes that the buffers contain zero-length-terminated lists
157 * (frequently erroneously referred to as double-null-terminated)
158 * buffer The narrow-character buffer into which to place the result. This
159 * must be a non-null pointer to the first element of a buffer whose
160 * length is passed in buffer_length.
161 * str The wide-character buffer containing the string or list of strings to
162 * be converted. str_length defines how many wide characters in the
163 * buffer are to be converted, including all desired terminating nul
164 * characters.
165 * str_length Effective length of str
166 * buffer_length Length of buffer
167 * returned_length A pointer to a variable that will receive the number of
168 * narrow characters placed into the buffer. This pointer
169 * may be NULL.
171 static BOOL SQLInstall_narrow(int mode, LPSTR buffer, LPCWSTR str, WORD str_length, WORD buffer_length, WORD *returned_length)
173 LPSTR pbuf; /* allows us to allocate a temporary buffer only if needed */
174 int len; /* Length of the converted list */
175 BOOL success = FALSE;
176 assert(mode == 1 || mode == 2);
177 assert(buffer_length);
178 len = WideCharToMultiByte(CP_ACP, 0, str, str_length, 0, 0, NULL, NULL);
179 if (len > 0)
181 if (len > buffer_length)
183 pbuf = HeapAlloc(GetProcessHeap(), 0, len);
185 else
187 pbuf = buffer;
189 len = WideCharToMultiByte(CP_ACP, 0, str, str_length, pbuf, len, NULL, NULL);
190 if (len > 0)
192 if (pbuf != buffer)
194 if (buffer_length > (mode - 1))
196 memcpy (buffer, pbuf, buffer_length-mode);
197 *(buffer+buffer_length-mode) = '\0';
199 *(buffer+buffer_length-1) = '\0';
201 if (returned_length)
203 *returned_length = pbuf == buffer ? len : buffer_length;
205 success = TRUE;
207 else
209 ERR("transferring wide to narrow\n");
211 if (pbuf != buffer)
213 HeapFree(GetProcessHeap(), 0, pbuf);
216 else
218 ERR("measuring wide to narrow\n");
220 return success;
223 BOOL WINAPI SQLConfigDataSourceW(HWND hwndParent, WORD fRequest,
224 LPCWSTR lpszDriver, LPCWSTR lpszAttributes)
226 LPCWSTR p;
228 clear_errors();
229 FIXME("%p %d %s %s\n", hwndParent, fRequest, debugstr_w(lpszDriver),
230 debugstr_w(lpszAttributes));
232 for (p = lpszAttributes; *p; p += lstrlenW(p) + 1)
233 FIXME("%s\n", debugstr_w(p));
235 return TRUE;
238 BOOL WINAPI SQLConfigDataSource(HWND hwndParent, WORD fRequest,
239 LPCSTR lpszDriver, LPCSTR lpszAttributes)
241 FIXME("%p %d %s %s\n", hwndParent, fRequest, debugstr_a(lpszDriver),
242 debugstr_a(lpszAttributes));
243 clear_errors();
244 return TRUE;
247 BOOL WINAPI SQLConfigDriverW(HWND hwndParent, WORD fRequest, LPCWSTR lpszDriver,
248 LPCWSTR lpszArgs, LPWSTR lpszMsg, WORD cbMsgMax, WORD *pcbMsgOut)
250 clear_errors();
251 FIXME("(%p %d %s %s %p %d %p)\n", hwndParent, fRequest, debugstr_w(lpszDriver),
252 debugstr_w(lpszArgs), lpszMsg, cbMsgMax, pcbMsgOut);
253 return TRUE;
256 BOOL WINAPI SQLConfigDriver(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver,
257 LPCSTR lpszArgs, LPSTR lpszMsg, WORD cbMsgMax, WORD *pcbMsgOut)
259 clear_errors();
260 FIXME("(%p %d %s %s %p %d %p)\n", hwndParent, fRequest, debugstr_a(lpszDriver),
261 debugstr_a(lpszArgs), lpszMsg, cbMsgMax, pcbMsgOut);
262 return TRUE;
265 BOOL WINAPI SQLCreateDataSourceW(HWND hwnd, LPCWSTR lpszDS)
267 clear_errors();
268 FIXME("%p %s\n", hwnd, debugstr_w(lpszDS));
269 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
270 return FALSE;
273 BOOL WINAPI SQLCreateDataSource(HWND hwnd, LPCSTR lpszDS)
275 clear_errors();
276 FIXME("%p %s\n", hwnd, debugstr_a(lpszDS));
277 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
278 return FALSE;
281 BOOL WINAPI SQLGetAvailableDriversW(LPCWSTR lpszInfFile, LPWSTR lpszBuf,
282 WORD cbBufMax, WORD *pcbBufOut)
284 clear_errors();
285 FIXME("%s %p %d %p\n", debugstr_w(lpszInfFile), lpszBuf, cbBufMax, pcbBufOut);
286 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
287 return FALSE;
290 BOOL WINAPI SQLGetAvailableDrivers(LPCSTR lpszInfFile, LPSTR lpszBuf,
291 WORD cbBufMax, WORD *pcbBufOut)
293 clear_errors();
294 FIXME("%s %p %d %p\n", debugstr_a(lpszInfFile), lpszBuf, cbBufMax, pcbBufOut);
295 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
296 return FALSE;
299 BOOL WINAPI SQLGetConfigMode(UWORD *pwConfigMode)
301 clear_errors();
302 TRACE("%p\n", pwConfigMode);
303 if (pwConfigMode)
304 *pwConfigMode = config_mode;
305 return TRUE;
308 /* This is implemented sensibly rather than according to exact conformance to Microsoft's buggy implementations
309 * e.g. The Microsoft one occasionally actually adds a third nul character (possibly beyond the buffer).
310 * e.g. If the key has no drivers then version 3.525.1117.0 does not modify the buffer at all, not even a nul character.
312 BOOL WINAPI SQLGetInstalledDriversW(LPWSTR lpszBuf, WORD cbBufMax,
313 WORD *pcbBufOut)
315 HKEY hDrivers; /* Registry handle to the Drivers key */
316 LONG reg_ret; /* Return code from registry functions */
317 BOOL success = FALSE; /* The value we will return */
319 clear_errors();
321 TRACE("%p %d %p\n", lpszBuf, cbBufMax, pcbBufOut);
323 if (!lpszBuf || cbBufMax == 0)
325 push_error(ODBC_ERROR_INVALID_BUFF_LEN, odbc_error_invalid_buff_len);
327 else if ((reg_ret = RegOpenKeyExW (HKEY_LOCAL_MACHINE /* The drivers does not depend on the config mode */,
328 drivers_key, 0, KEY_READ /* Maybe overkill */,
329 &hDrivers)) == ERROR_SUCCESS)
331 DWORD index = 0;
332 cbBufMax--;
333 success = TRUE;
334 while (cbBufMax > 0)
336 DWORD size_name;
337 size_name = cbBufMax;
338 if ((reg_ret = RegEnumValueW(hDrivers, index, lpszBuf, &size_name, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS)
340 index++;
341 assert (size_name < cbBufMax && *(lpszBuf + size_name) == 0);
342 size_name++;
343 cbBufMax-= size_name;
344 lpszBuf+=size_name;
346 else
348 if (reg_ret != ERROR_NO_MORE_ITEMS)
350 success = FALSE;
351 push_error(ODBC_ERROR_GENERAL_ERR, odbc_error_general_err);
353 break;
356 *lpszBuf = 0;
357 if ((reg_ret = RegCloseKey (hDrivers)) != ERROR_SUCCESS)
358 TRACE ("Error %d closing ODBC Drivers key\n", reg_ret);
360 else
362 /* MSDN states that it returns failure with COMPONENT_NOT_FOUND in this case.
363 * Version 3.525.1117.0 (Windows 2000) does not; it actually returns success.
364 * I doubt if it will actually be an issue.
366 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND, odbc_error_component_not_found);
368 return success;
371 BOOL WINAPI SQLGetInstalledDrivers(LPSTR lpszBuf, WORD cbBufMax,
372 WORD *pcbBufOut)
374 BOOL ret;
375 int size_wbuf = cbBufMax;
376 LPWSTR wbuf;
377 WORD size_used;
379 TRACE("%p %d %p\n", lpszBuf, cbBufMax, pcbBufOut);
381 wbuf = HeapAlloc(GetProcessHeap(), 0, size_wbuf*sizeof(WCHAR));
382 if (wbuf)
384 ret = SQLGetInstalledDriversW(wbuf, size_wbuf, &size_used);
385 if (ret)
387 if (!(ret = SQLInstall_narrow(2, lpszBuf, wbuf, size_used, cbBufMax, pcbBufOut)))
389 push_error(ODBC_ERROR_GENERAL_ERR, odbc_error_general_err);
392 HeapFree(GetProcessHeap(), 0, wbuf);
393 /* ignore failure; we have achieved the aim */
395 else
397 push_error(ODBC_ERROR_OUT_OF_MEM, odbc_error_out_of_mem);
398 ret = FALSE;
400 return ret;
403 static HKEY get_privateprofile_sectionkey(LPCWSTR section, LPCWSTR filename)
405 HKEY hkey, hkeyfilename, hkeysection;
406 LONG ret;
408 if (RegOpenKeyW(HKEY_CURRENT_USER, odbcW, &hkey))
409 return NULL;
411 ret = RegOpenKeyW(hkey, filename, &hkeyfilename);
412 RegCloseKey(hkey);
413 if (ret)
414 return NULL;
416 ret = RegOpenKeyW(hkeyfilename, section, &hkeysection);
417 RegCloseKey(hkeyfilename);
419 return ret ? NULL : hkeysection;
422 int WINAPI SQLGetPrivateProfileStringW(LPCWSTR section, LPCWSTR entry,
423 LPCWSTR defvalue, LPWSTR buff, int buff_len, LPCWSTR filename)
425 BOOL usedefault = TRUE;
426 HKEY sectionkey;
427 LONG ret = 0;
429 TRACE("%s %s %s %p %d %s\n", debugstr_w(section), debugstr_w(entry),
430 debugstr_w(defvalue), buff, buff_len, debugstr_w(filename));
432 clear_errors();
434 if (buff_len <= 0 || !section)
435 return 0;
437 if(buff)
438 buff[0] = 0;
440 if (!defvalue || !buff)
441 return 0;
443 sectionkey = get_privateprofile_sectionkey(section, filename);
444 if (sectionkey)
446 DWORD type, size;
448 if (entry)
450 size = buff_len * sizeof(*buff);
451 if (RegGetValueW(sectionkey, NULL, entry, RRF_RT_REG_SZ, &type, buff, &size) == ERROR_SUCCESS)
453 usedefault = FALSE;
454 ret = (size / sizeof(*buff)) - 1;
457 else
459 WCHAR name[MAX_PATH];
460 DWORD index = 0;
461 DWORD namelen;
463 usedefault = FALSE;
465 memset(buff, 0, buff_len);
467 namelen = sizeof(name);
468 while (RegEnumValueW(sectionkey, index, name, &namelen, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
470 if ((ret + namelen+1) > buff_len)
471 break;
473 lstrcpyW(buff+ret, name);
474 ret += namelen+1;
475 namelen = sizeof(name);
476 index++;
480 RegCloseKey(sectionkey);
482 else
483 usedefault = entry != NULL;
485 if (usedefault)
487 lstrcpynW(buff, defvalue, buff_len);
488 ret = lstrlenW(buff);
491 return ret;
494 int WINAPI SQLGetPrivateProfileString(LPCSTR section, LPCSTR entry,
495 LPCSTR defvalue, LPSTR buff, int buff_len, LPCSTR filename)
497 WCHAR *sectionW, *filenameW;
498 BOOL usedefault = TRUE;
499 HKEY sectionkey;
500 LONG ret = 0;
502 TRACE("%s %s %s %p %d %s\n", debugstr_a(section), debugstr_a(entry),
503 debugstr_a(defvalue), buff, buff_len, debugstr_a(filename));
505 clear_errors();
507 if (buff_len <= 0)
508 return 0;
510 if (buff)
511 buff[0] = 0;
513 if (!section || !defvalue || !buff)
514 return 0;
516 sectionW = heap_strdupAtoW(section);
517 filenameW = heap_strdupAtoW(filename);
519 sectionkey = get_privateprofile_sectionkey(sectionW, filenameW);
521 heap_free(sectionW);
522 heap_free(filenameW);
524 if (sectionkey)
526 DWORD type, size;
528 if (entry)
530 size = buff_len * sizeof(*buff);
531 if (RegGetValueA(sectionkey, NULL, entry, RRF_RT_REG_SZ, &type, buff, &size) == ERROR_SUCCESS)
533 usedefault = FALSE;
534 ret = (size / sizeof(*buff)) - 1;
537 else
539 char name[MAX_PATH] = {0};
540 DWORD index = 0;
541 DWORD namelen;
543 usedefault = FALSE;
545 memset(buff, 0, buff_len);
547 namelen = sizeof(name);
548 while (RegEnumValueA(sectionkey, index, name, &namelen, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
550 if ((ret + namelen+1) > buff_len)
551 break;
553 lstrcpyA(buff+ret, name);
555 ret += namelen+1;
556 namelen = sizeof(name);
557 index++;
561 RegCloseKey(sectionkey);
563 else
564 usedefault = entry != NULL;
566 if (usedefault)
568 lstrcpynA(buff, defvalue, buff_len);
569 ret = strlen(buff);
572 return ret;
575 BOOL WINAPI SQLGetTranslatorW(HWND hwndParent, LPWSTR lpszName, WORD cbNameMax,
576 WORD *pcbNameOut, LPWSTR lpszPath, WORD cbPathMax,
577 WORD *pcbPathOut, DWORD *pvOption)
579 clear_errors();
580 FIXME("%p %s %d %p %p %d %p %p\n", hwndParent, debugstr_w(lpszName), cbNameMax,
581 pcbNameOut, lpszPath, cbPathMax, pcbPathOut, pvOption);
582 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
583 return FALSE;
586 BOOL WINAPI SQLGetTranslator(HWND hwndParent, LPSTR lpszName, WORD cbNameMax,
587 WORD *pcbNameOut, LPSTR lpszPath, WORD cbPathMax,
588 WORD *pcbPathOut, DWORD *pvOption)
590 clear_errors();
591 FIXME("%p %s %d %p %p %d %p %p\n", hwndParent, debugstr_a(lpszName), cbNameMax,
592 pcbNameOut, lpszPath, cbPathMax, pcbPathOut, pvOption);
593 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
594 return FALSE;
597 BOOL WINAPI SQLInstallDriverW(LPCWSTR lpszInfFile, LPCWSTR lpszDriver,
598 LPWSTR lpszPath, WORD cbPathMax, WORD * pcbPathOut)
600 DWORD usage;
602 clear_errors();
603 TRACE("%s %s %p %d %p\n", debugstr_w(lpszInfFile),
604 debugstr_w(lpszDriver), lpszPath, cbPathMax, pcbPathOut);
606 if (lpszInfFile)
607 return FALSE;
609 return SQLInstallDriverExW(lpszDriver, NULL, lpszPath, cbPathMax,
610 pcbPathOut, ODBC_INSTALL_COMPLETE, &usage);
613 BOOL WINAPI SQLInstallDriver(LPCSTR lpszInfFile, LPCSTR lpszDriver,
614 LPSTR lpszPath, WORD cbPathMax, WORD * pcbPathOut)
616 DWORD usage;
618 clear_errors();
619 TRACE("%s %s %p %d %p\n", debugstr_a(lpszInfFile),
620 debugstr_a(lpszDriver), lpszPath, cbPathMax, pcbPathOut);
622 if (lpszInfFile)
623 return FALSE;
625 return SQLInstallDriverEx(lpszDriver, NULL, lpszPath, cbPathMax,
626 pcbPathOut, ODBC_INSTALL_COMPLETE, &usage);
629 BOOL WINAPI SQLInstallDriverExW(LPCWSTR lpszDriver, LPCWSTR lpszPathIn,
630 LPWSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
631 WORD fRequest, LPDWORD lpdwUsageCount)
633 UINT len;
634 LPCWSTR p;
635 WCHAR path[MAX_PATH];
637 clear_errors();
638 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszDriver),
639 debugstr_w(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
640 fRequest, lpdwUsageCount);
642 for (p = lpszDriver; *p; p += lstrlenW(p) + 1)
643 TRACE("%s\n", debugstr_w(p));
645 len = GetSystemDirectoryW(path, MAX_PATH);
647 if (pcbPathOut)
648 *pcbPathOut = len;
650 len = GetSystemDirectoryW(path, MAX_PATH);
652 if (lpszPathOut && cbPathOutMax > len)
654 lstrcpyW(lpszPathOut, path);
655 return TRUE;
657 return FALSE;
660 BOOL WINAPI SQLInstallDriverEx(LPCSTR lpszDriver, LPCSTR lpszPathIn,
661 LPSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
662 WORD fRequest, LPDWORD lpdwUsageCount)
664 LPCSTR p;
665 LPWSTR driver, pathin;
666 WCHAR pathout[MAX_PATH];
667 BOOL ret;
668 WORD cbOut = 0;
670 clear_errors();
671 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszDriver),
672 debugstr_a(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
673 fRequest, lpdwUsageCount);
675 for (p = lpszDriver; *p; p += lstrlenA(p) + 1)
676 TRACE("%s\n", debugstr_a(p));
678 driver = SQLInstall_strdup_multi(lpszDriver);
679 pathin = SQLInstall_strdup(lpszPathIn);
681 ret = SQLInstallDriverExW(driver, pathin, pathout, MAX_PATH, &cbOut,
682 fRequest, lpdwUsageCount);
683 if (ret)
685 int len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
686 0, NULL, NULL);
687 if (len)
689 if (pcbPathOut)
690 *pcbPathOut = len - 1;
692 if (!lpszPathOut || cbPathOutMax < len)
694 ret = FALSE;
695 goto out;
697 len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
698 cbPathOutMax, NULL, NULL);
702 out:
703 HeapFree(GetProcessHeap(), 0, driver);
704 HeapFree(GetProcessHeap(), 0, pathin);
705 return ret;
708 BOOL WINAPI SQLInstallDriverManagerW(LPWSTR lpszPath, WORD cbPathMax,
709 WORD *pcbPathOut)
711 UINT len;
712 WCHAR path[MAX_PATH];
714 TRACE("(%p %d %p)\n", lpszPath, cbPathMax, pcbPathOut);
716 if (cbPathMax < MAX_PATH)
717 return FALSE;
719 clear_errors();
721 len = GetSystemDirectoryW(path, MAX_PATH);
723 if (pcbPathOut)
724 *pcbPathOut = len;
726 if (lpszPath && cbPathMax > len)
728 lstrcpyW(lpszPath, path);
729 return TRUE;
731 return FALSE;
734 BOOL WINAPI SQLInstallDriverManager(LPSTR lpszPath, WORD cbPathMax,
735 WORD *pcbPathOut)
737 BOOL ret;
738 WORD len, cbOut = 0;
739 WCHAR path[MAX_PATH];
741 TRACE("(%p %d %p)\n", lpszPath, cbPathMax, pcbPathOut);
743 if (cbPathMax < MAX_PATH)
744 return FALSE;
746 clear_errors();
748 ret = SQLInstallDriverManagerW(path, MAX_PATH, &cbOut);
749 if (ret)
751 len = WideCharToMultiByte(CP_ACP, 0, path, -1, lpszPath, 0,
752 NULL, NULL);
753 if (len)
755 if (pcbPathOut)
756 *pcbPathOut = len - 1;
758 if (!lpszPath || cbPathMax < len)
759 return FALSE;
761 len = WideCharToMultiByte(CP_ACP, 0, path, -1, lpszPath,
762 cbPathMax, NULL, NULL);
765 return ret;
768 BOOL WINAPI SQLInstallODBCW(HWND hwndParent, LPCWSTR lpszInfFile,
769 LPCWSTR lpszSrcPath, LPCWSTR lpszDrivers)
771 clear_errors();
772 FIXME("%p %s %s %s\n", hwndParent, debugstr_w(lpszInfFile),
773 debugstr_w(lpszSrcPath), debugstr_w(lpszDrivers));
774 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
775 return FALSE;
778 BOOL WINAPI SQLInstallODBC(HWND hwndParent, LPCSTR lpszInfFile,
779 LPCSTR lpszSrcPath, LPCSTR lpszDrivers)
781 clear_errors();
782 FIXME("%p %s %s %s\n", hwndParent, debugstr_a(lpszInfFile),
783 debugstr_a(lpszSrcPath), debugstr_a(lpszDrivers));
784 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
785 return FALSE;
788 SQLRETURN WINAPI SQLInstallerErrorW(WORD iError, DWORD *pfErrorCode,
789 LPWSTR lpszErrorMsg, WORD cbErrorMsgMax, WORD *pcbErrorMsg)
791 TRACE("%d %p %p %d %p\n", iError, pfErrorCode, lpszErrorMsg,
792 cbErrorMsgMax, pcbErrorMsg);
794 if (iError == 0)
796 return SQL_ERROR;
798 else if (iError <= num_errors)
800 BOOL truncated = FALSE;
801 WORD len;
802 LPCWSTR msg;
803 iError--;
804 if (pfErrorCode)
805 *pfErrorCode = error_code[iError];
806 msg = error_msg[iError];
807 len = msg ? lstrlenW(msg) : 0;
808 if (pcbErrorMsg)
809 *pcbErrorMsg = len;
810 len++;
811 if (cbErrorMsgMax < len)
813 len = cbErrorMsgMax;
814 truncated = TRUE;
816 if (lpszErrorMsg && len)
818 if (msg)
820 memcpy (lpszErrorMsg, msg, len * sizeof(WCHAR));
822 else
824 assert(len==1);
825 *lpszErrorMsg = 0;
828 else
830 /* Yes. If you pass a null pointer and a large length it is not an error! */
831 truncated = TRUE;
834 return truncated ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
837 /* At least on Windows 2000 , the buffers are not altered in this case. However that is a little too dangerous a test for just now */
838 if (pcbErrorMsg)
839 *pcbErrorMsg = 0;
841 if (lpszErrorMsg && cbErrorMsgMax > 0)
842 *lpszErrorMsg = '\0';
844 return SQL_NO_DATA;
847 SQLRETURN WINAPI SQLInstallerError(WORD iError, DWORD *pfErrorCode,
848 LPSTR lpszErrorMsg, WORD cbErrorMsgMax, WORD *pcbErrorMsg)
850 SQLRETURN ret;
851 LPWSTR wbuf;
852 WORD cbwbuf;
853 TRACE("%d %p %p %d %p\n", iError, pfErrorCode, lpszErrorMsg,
854 cbErrorMsgMax, pcbErrorMsg);
856 wbuf = 0;
857 if (lpszErrorMsg && cbErrorMsgMax)
859 wbuf = HeapAlloc(GetProcessHeap(), 0, cbErrorMsgMax*sizeof(WCHAR));
860 if (!wbuf)
861 return SQL_ERROR;
863 ret = SQLInstallerErrorW(iError, pfErrorCode, wbuf, cbErrorMsgMax, &cbwbuf);
864 if (wbuf)
866 WORD cbBuf = 0;
867 SQLInstall_narrow(1, lpszErrorMsg, wbuf, cbwbuf+1, cbErrorMsgMax, &cbBuf);
868 HeapFree(GetProcessHeap(), 0, wbuf);
869 if (pcbErrorMsg)
870 *pcbErrorMsg = cbBuf-1;
872 return ret;
875 BOOL WINAPI SQLInstallTranslatorExW(LPCWSTR lpszTranslator, LPCWSTR lpszPathIn,
876 LPWSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
877 WORD fRequest, LPDWORD lpdwUsageCount)
879 UINT len;
880 LPCWSTR p;
881 WCHAR path[MAX_PATH];
883 clear_errors();
884 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszTranslator),
885 debugstr_w(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
886 fRequest, lpdwUsageCount);
888 for (p = lpszTranslator; *p; p += lstrlenW(p) + 1)
889 TRACE("%s\n", debugstr_w(p));
891 len = GetSystemDirectoryW(path, MAX_PATH);
893 if (pcbPathOut)
894 *pcbPathOut = len;
896 if (lpszPathOut && cbPathOutMax > len)
898 lstrcpyW(lpszPathOut, path);
899 return TRUE;
901 return FALSE;
904 BOOL WINAPI SQLInstallTranslatorEx(LPCSTR lpszTranslator, LPCSTR lpszPathIn,
905 LPSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
906 WORD fRequest, LPDWORD lpdwUsageCount)
908 LPCSTR p;
909 LPWSTR translator, pathin;
910 WCHAR pathout[MAX_PATH];
911 BOOL ret;
912 WORD cbOut = 0;
914 clear_errors();
915 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszTranslator),
916 debugstr_a(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
917 fRequest, lpdwUsageCount);
919 for (p = lpszTranslator; *p; p += lstrlenA(p) + 1)
920 TRACE("%s\n", debugstr_a(p));
922 translator = SQLInstall_strdup_multi(lpszTranslator);
923 pathin = SQLInstall_strdup(lpszPathIn);
925 ret = SQLInstallTranslatorExW(translator, pathin, pathout, MAX_PATH,
926 &cbOut, fRequest, lpdwUsageCount);
927 if (ret)
929 int len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
930 0, NULL, NULL);
931 if (len)
933 if (pcbPathOut)
934 *pcbPathOut = len - 1;
936 if (!lpszPathOut || cbPathOutMax < len)
938 ret = FALSE;
939 goto out;
941 len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
942 cbPathOutMax, NULL, NULL);
946 out:
947 HeapFree(GetProcessHeap(), 0, translator);
948 HeapFree(GetProcessHeap(), 0, pathin);
949 return ret;
952 BOOL WINAPI SQLInstallTranslator(LPCSTR lpszInfFile, LPCSTR lpszTranslator,
953 LPCSTR lpszPathIn, LPSTR lpszPathOut, WORD cbPathOutMax,
954 WORD *pcbPathOut, WORD fRequest, LPDWORD lpdwUsageCount)
956 clear_errors();
957 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_a(lpszInfFile),
958 debugstr_a(lpszTranslator), debugstr_a(lpszPathIn), lpszPathOut,
959 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
961 if (lpszInfFile)
962 return FALSE;
964 return SQLInstallTranslatorEx(lpszTranslator, lpszPathIn, lpszPathOut,
965 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
968 BOOL WINAPI SQLInstallTranslatorW(LPCWSTR lpszInfFile, LPCWSTR lpszTranslator,
969 LPCWSTR lpszPathIn, LPWSTR lpszPathOut, WORD cbPathOutMax,
970 WORD *pcbPathOut, WORD fRequest, LPDWORD lpdwUsageCount)
972 clear_errors();
973 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_w(lpszInfFile),
974 debugstr_w(lpszTranslator), debugstr_w(lpszPathIn), lpszPathOut,
975 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
977 if (lpszInfFile)
978 return FALSE;
980 return SQLInstallTranslatorExW(lpszTranslator, lpszPathIn, lpszPathOut,
981 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
984 BOOL WINAPI SQLManageDataSources(HWND hwnd)
986 clear_errors();
987 FIXME("%p\n", hwnd);
988 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
989 return FALSE;
992 SQLRETURN WINAPI SQLPostInstallerErrorW(DWORD fErrorCode, LPCWSTR szErrorMsg)
994 FIXME("%u %s\n", fErrorCode, debugstr_w(szErrorMsg));
995 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
996 return FALSE;
999 SQLRETURN WINAPI SQLPostInstallerError(DWORD fErrorCode, LPCSTR szErrorMsg)
1001 FIXME("%u %s\n", fErrorCode, debugstr_a(szErrorMsg));
1002 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1003 return FALSE;
1006 BOOL WINAPI SQLReadFileDSNW(LPCWSTR lpszFileName, LPCWSTR lpszAppName,
1007 LPCWSTR lpszKeyName, LPWSTR lpszString, WORD cbString,
1008 WORD *pcbString)
1010 clear_errors();
1011 FIXME("%s %s %s %s %d %p\n", debugstr_w(lpszFileName), debugstr_w(lpszAppName),
1012 debugstr_w(lpszKeyName), debugstr_w(lpszString), cbString, pcbString);
1013 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1014 return FALSE;
1017 BOOL WINAPI SQLReadFileDSN(LPCSTR lpszFileName, LPCSTR lpszAppName,
1018 LPCSTR lpszKeyName, LPSTR lpszString, WORD cbString,
1019 WORD *pcbString)
1021 clear_errors();
1022 FIXME("%s %s %s %s %d %p\n", debugstr_a(lpszFileName), debugstr_a(lpszAppName),
1023 debugstr_a(lpszKeyName), debugstr_a(lpszString), cbString, pcbString);
1024 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1025 return FALSE;
1028 BOOL WINAPI SQLRemoveDefaultDataSource(void)
1030 clear_errors();
1031 FIXME("\n");
1032 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1033 return FALSE;
1036 BOOL WINAPI SQLRemoveDriverW(LPCWSTR lpszDriver, BOOL fRemoveDSN,
1037 LPDWORD lpdwUsageCount)
1039 clear_errors();
1040 FIXME("%s %d %p\n", debugstr_w(lpszDriver), fRemoveDSN, lpdwUsageCount);
1041 if (lpdwUsageCount) *lpdwUsageCount = 1;
1042 return TRUE;
1045 BOOL WINAPI SQLRemoveDriver(LPCSTR lpszDriver, BOOL fRemoveDSN,
1046 LPDWORD lpdwUsageCount)
1048 clear_errors();
1049 FIXME("%s %d %p\n", debugstr_a(lpszDriver), fRemoveDSN, lpdwUsageCount);
1050 if (lpdwUsageCount) *lpdwUsageCount = 1;
1051 return TRUE;
1054 BOOL WINAPI SQLRemoveDriverManager(LPDWORD pdwUsageCount)
1056 clear_errors();
1057 FIXME("%p\n", pdwUsageCount);
1058 if (pdwUsageCount) *pdwUsageCount = 1;
1059 return TRUE;
1062 BOOL WINAPI SQLRemoveDSNFromIniW(LPCWSTR lpszDSN)
1064 clear_errors();
1065 FIXME("%s\n", debugstr_w(lpszDSN));
1066 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1067 return FALSE;
1070 BOOL WINAPI SQLRemoveDSNFromIni(LPCSTR lpszDSN)
1072 clear_errors();
1073 FIXME("%s\n", debugstr_a(lpszDSN));
1074 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1075 return FALSE;
1078 BOOL WINAPI SQLRemoveTranslatorW(LPCWSTR lpszTranslator, LPDWORD lpdwUsageCount)
1080 clear_errors();
1081 FIXME("%s %p\n", debugstr_w(lpszTranslator), lpdwUsageCount);
1082 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1083 return FALSE;
1086 BOOL WINAPI SQLRemoveTranslator(LPCSTR lpszTranslator, LPDWORD lpdwUsageCount)
1088 clear_errors();
1089 FIXME("%s %p\n", debugstr_a(lpszTranslator), lpdwUsageCount);
1090 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1091 return FALSE;
1094 BOOL WINAPI SQLSetConfigMode(UWORD wConfigMode)
1096 clear_errors();
1097 TRACE("%u\n", wConfigMode);
1099 if (wConfigMode > ODBC_SYSTEM_DSN)
1101 push_error(ODBC_ERROR_INVALID_PARAM_SEQUENCE, odbc_error_invalid_param_sequence);
1102 return FALSE;
1104 else
1106 config_mode = wConfigMode;
1107 return TRUE;
1111 BOOL WINAPI SQLValidDSNW(LPCWSTR lpszDSN)
1113 clear_errors();
1114 FIXME("%s\n", debugstr_w(lpszDSN));
1115 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1116 return FALSE;
1119 BOOL WINAPI SQLValidDSN(LPCSTR lpszDSN)
1121 clear_errors();
1122 FIXME("%s\n", debugstr_a(lpszDSN));
1123 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1124 return FALSE;
1127 BOOL WINAPI SQLWriteDSNToIniW(LPCWSTR lpszDSN, LPCWSTR lpszDriver)
1129 clear_errors();
1130 FIXME("%s %s\n", debugstr_w(lpszDSN), debugstr_w(lpszDriver));
1131 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1132 return FALSE;
1135 BOOL WINAPI SQLWriteDSNToIni(LPCSTR lpszDSN, LPCSTR lpszDriver)
1137 clear_errors();
1138 FIXME("%s %s\n", debugstr_a(lpszDSN), debugstr_a(lpszDriver));
1139 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1140 return FALSE;
1143 BOOL WINAPI SQLWriteFileDSNW(LPCWSTR lpszFileName, LPCWSTR lpszAppName,
1144 LPCWSTR lpszKeyName, LPCWSTR lpszString)
1146 clear_errors();
1147 FIXME("%s %s %s %s\n", debugstr_w(lpszFileName), debugstr_w(lpszAppName),
1148 debugstr_w(lpszKeyName), debugstr_w(lpszString));
1149 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1150 return FALSE;
1153 BOOL WINAPI SQLWriteFileDSN(LPCSTR lpszFileName, LPCSTR lpszAppName,
1154 LPCSTR lpszKeyName, LPCSTR lpszString)
1156 clear_errors();
1157 FIXME("%s %s %s %s\n", debugstr_a(lpszFileName), debugstr_a(lpszAppName),
1158 debugstr_a(lpszKeyName), debugstr_a(lpszString));
1159 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1160 return FALSE;
1163 BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry,
1164 LPCWSTR lpszString, LPCWSTR lpszFilename)
1166 LONG ret;
1167 HKEY hkey;
1169 clear_errors();
1170 TRACE("%s %s %s %s\n", debugstr_w(lpszSection), debugstr_w(lpszEntry),
1171 debugstr_w(lpszString), debugstr_w(lpszFilename));
1173 if(!lpszFilename || !*lpszFilename)
1175 push_error(ODBC_ERROR_INVALID_STR, odbc_error_invalid_param_string);
1176 return FALSE;
1179 if ((ret = RegCreateKeyW(HKEY_CURRENT_USER, odbcW, &hkey)) == ERROR_SUCCESS)
1181 HKEY hkeyfilename;
1183 if ((ret = RegCreateKeyW(hkey, lpszFilename, &hkeyfilename)) == ERROR_SUCCESS)
1185 HKEY hkey_section;
1187 if ((ret = RegCreateKeyW(hkeyfilename, lpszSection, &hkey_section)) == ERROR_SUCCESS)
1189 ret = RegSetValueExW(hkey_section, lpszEntry, 0, REG_SZ, (BYTE*)lpszString, (lstrlenW(lpszString)+1)*sizeof(WCHAR));
1190 RegCloseKey(hkey_section);
1193 RegCloseKey(hkeyfilename);
1196 RegCloseKey(hkey);
1199 return ret == ERROR_SUCCESS;
1202 BOOL WINAPI SQLWritePrivateProfileString(LPCSTR lpszSection, LPCSTR lpszEntry,
1203 LPCSTR lpszString, LPCSTR lpszFilename)
1205 BOOL ret;
1206 WCHAR *sect, *entry, *string, *file;
1207 clear_errors();
1208 TRACE("%s %s %s %s\n", lpszSection, lpszEntry, lpszString, lpszFilename);
1210 sect = heap_strdupAtoW(lpszSection);
1211 entry = heap_strdupAtoW(lpszEntry);
1212 string = heap_strdupAtoW(lpszString);
1213 file = heap_strdupAtoW(lpszFilename);
1215 ret = SQLWritePrivateProfileStringW(sect, entry, string, file);
1217 heap_free(sect);
1218 heap_free(entry);
1219 heap_free(string);
1220 heap_free(file);
1222 return ret;