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
33 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(odbc
);
39 /* Registry key names */
40 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};
41 static const WCHAR odbcW
[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C',0};
42 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};
43 static const WCHAR odbcdrivers
[] = {'O','D','B','C',' ','D','r','i','v','e','r','s',0};
44 static const WCHAR odbctranslators
[] = {'O','D','B','C',' ','T','r','a','n','s','l','a','t','o','r','s',0};
46 /* This config mode is known to be process-wide.
47 * MSDN documentation suggests that the value is hidden somewhere in the registry but I haven't found it yet.
48 * Although both the registry and the ODBC.ini files appear to be maintained together they are not maintained automatically through the registry's IniFileMapping.
50 static UWORD config_mode
= ODBC_BOTH_DSN
;
52 /* MSDN documentation suggests that the error subsystem handles errors 1 to 8
53 * only and experimentation (Windows 2000) shows that the errors are process-
54 * wide so go for the simple solution; static arrays.
56 static int num_errors
;
57 static int error_code
[8];
58 static const WCHAR
*error_msg
[8];
59 static const WCHAR odbc_error_general_err
[] = {'G','e','n','e','r','a','l',' ','e','r','r','o','r',0};
60 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};
61 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};
62 static const WCHAR odbc_error_out_of_mem
[] = {'O','u','t',' ','o','f',' ','m','e','m','o','r','y',0};
63 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};
64 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};
65 static const WCHAR odbc_error_invalid_dsn
[] = {'I','n','v','a','l','i','d',' ','D','S','N',0};
66 static const WCHAR odbc_error_load_lib_failed
[] = {'L','o','a','d',' ','L','i','b','r','a','r','y',' ','F','a','i','l','e','d',0};
67 static const WCHAR odbc_error_request_failed
[] = {'R','e','q','u','e','s','t',' ','F','a','i','l','e','d',0};
68 static const WCHAR odbc_error_invalid_keyword
[] = {'I','n','v','a','l','i','d',' ','k','e','y','w','o','r','d',' ','v','a','l','u','e',0};
70 static BOOL (WINAPI
*pConfigDSN
)(HWND hwnd
, WORD request
, const char *driver
, const char *attr
);
71 static BOOL (WINAPI
*pConfigDSNW
)(HWND hwnd
, WORD request
, const WCHAR
*driver
, const WCHAR
*attr
);
73 /* Push an error onto the error stack, taking care of ranges etc. */
74 static void push_error(int code
, LPCWSTR msg
)
76 if (num_errors
< ARRAY_SIZE(error_code
))
78 error_code
[num_errors
] = code
;
79 error_msg
[num_errors
] = msg
;
84 /* Clear the error stack */
85 static void clear_errors(void)
90 static inline WCHAR
*strdupAtoW(const char *str
)
97 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
98 ret
= malloc(len
* sizeof(WCHAR
));
100 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
107 BOOL WINAPI
ODBCCPlApplet( LONG i
, LONG j
, LONG
* p1
, LONG
* p2
)
110 FIXME( "( %ld %ld %p %p) : stub!\n", i
, j
, p1
, p2
);
114 static LPWSTR
SQLInstall_strdup_multi(LPCSTR str
)
123 for (p
= str
; *p
; p
+= lstrlenA(p
) + 1)
126 len
= MultiByteToWideChar(CP_ACP
, 0, str
, p
- str
, NULL
, 0 );
127 ret
= malloc((len
+ 1) * sizeof(WCHAR
));
128 MultiByteToWideChar(CP_ACP
, 0, str
, p
- str
, ret
, len
);
134 static LPWSTR
SQLInstall_strdup(LPCSTR str
)
142 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0 );
143 ret
= malloc(len
* sizeof(WCHAR
));
144 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
149 /* Convert the wide string or zero-length-terminated list of wide strings to a
150 * narrow string or zero-length-terminated list of narrow strings.
151 * Do not try to emulate windows undocumented excesses (e.g. adding a third \0
154 * mode Indicates the sort of string.
155 * 1 denotes that the buffers contain strings terminated by a single nul
157 * 2 denotes that the buffers contain zero-length-terminated lists
158 * (frequently erroneously referred to as double-null-terminated)
159 * buffer The narrow-character buffer into which to place the result. This
160 * must be a non-null pointer to the first element of a buffer whose
161 * length is passed in buffer_length.
162 * str The wide-character buffer containing the string or list of strings to
163 * be converted. str_length defines how many wide characters in the
164 * buffer are to be converted, including all desired terminating nul
166 * str_length Effective length of str
167 * buffer_length Length of buffer
168 * returned_length A pointer to a variable that will receive the number of
169 * narrow characters placed into the buffer. This pointer
172 static BOOL
SQLInstall_narrow(int mode
, LPSTR buffer
, LPCWSTR str
, WORD str_length
, WORD buffer_length
, WORD
*returned_length
)
174 LPSTR pbuf
; /* allows us to allocate a temporary buffer only if needed */
175 int len
; /* Length of the converted list */
176 BOOL success
= FALSE
;
177 assert(mode
== 1 || mode
== 2);
178 assert(buffer_length
);
179 len
= WideCharToMultiByte(CP_ACP
, 0, str
, str_length
, 0, 0, NULL
, NULL
);
182 if (len
> buffer_length
)
190 len
= WideCharToMultiByte(CP_ACP
, 0, str
, str_length
, pbuf
, len
, NULL
, NULL
);
195 if (buffer_length
> (mode
- 1))
197 memcpy (buffer
, pbuf
, buffer_length
-mode
);
198 *(buffer
+buffer_length
-mode
) = '\0';
200 *(buffer
+buffer_length
-1) = '\0';
204 *returned_length
= pbuf
== buffer
? len
: buffer_length
;
210 ERR("transferring wide to narrow\n");
219 ERR("measuring wide to narrow\n");
224 static HMODULE
load_config_driver(const WCHAR
*driver
)
226 static WCHAR reg_driver
[] = {'d','r','i','v','e','r',0};
229 WCHAR
*filename
= NULL
;
230 DWORD size
= 0, type
;
233 if ((ret
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
)) == ERROR_SUCCESS
)
237 if ((ret
= RegOpenKeyW(hkey
, driver
, &hkeydriver
)) == ERROR_SUCCESS
)
239 ret
= RegGetValueW(hkeydriver
, NULL
, reg_driver
, RRF_RT_REG_SZ
, &type
, NULL
, &size
);
240 if(ret
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
242 RegCloseKey(hkeydriver
);
244 push_error(ODBC_ERROR_INVALID_DSN
, odbc_error_invalid_dsn
);
249 filename
= malloc(size
);
252 RegCloseKey(hkeydriver
);
254 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
258 ret
= RegGetValueW(hkeydriver
, NULL
, reg_driver
, RRF_RT_REG_SZ
, &type
, filename
, &size
);
260 RegCloseKey(hkeydriver
);
266 if(ret
!= ERROR_SUCCESS
)
269 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
273 hmod
= LoadLibraryExW(filename
, NULL
, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
| LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
);
277 push_error(ODBC_ERROR_LOAD_LIB_FAILED
, odbc_error_load_lib_failed
);
282 static BOOL
write_config_value(const WCHAR
*driver
, const WCHAR
*args
)
285 HKEY hkey
, hkeydriver
;
291 if((ret
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
)) == ERROR_SUCCESS
)
293 if((ret
= RegOpenKeyW(hkey
, driver
, &hkeydriver
)) == ERROR_SUCCESS
)
295 WCHAR
*divider
, *value
;
297 name
= malloc((wcslen(args
) + 1) * sizeof(WCHAR
));
300 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
303 lstrcpyW(name
, args
);
305 divider
= wcschr(name
,'=');
308 push_error(ODBC_ERROR_INVALID_KEYWORD_VALUE
, odbc_error_invalid_keyword
);
315 TRACE("Write pair: %s = %s\n", debugstr_w(name
), debugstr_w(value
));
316 if(RegSetValueExW(hkeydriver
, name
, 0, REG_SZ
, (BYTE
*)value
,
317 (lstrlenW(value
)+1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
318 ERR("Failed to write registry installed key\n");
321 RegCloseKey(hkeydriver
);
327 if(ret
!= ERROR_SUCCESS
)
328 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
330 return ret
== ERROR_SUCCESS
;
333 RegCloseKey(hkeydriver
);
340 static WORD
map_request(WORD request
)
345 case ODBC_ADD_SYS_DSN
:
348 case ODBC_CONFIG_DSN
:
349 case ODBC_CONFIG_SYS_DSN
:
350 return ODBC_CONFIG_DSN
;
352 case ODBC_REMOVE_DSN
:
353 case ODBC_REMOVE_SYS_DSN
:
354 return ODBC_REMOVE_DSN
;
357 FIXME("unhandled request %u\n", request
);
362 static UWORD
get_config_mode(WORD request
)
364 if (request
== ODBC_ADD_DSN
|| request
== ODBC_CONFIG_DSN
|| request
== ODBC_REMOVE_DSN
) return ODBC_USER_DSN
;
365 return ODBC_SYSTEM_DSN
;
368 BOOL WINAPI
SQLConfigDataSourceW(HWND hwnd
, WORD request
, LPCWSTR driver
, LPCWSTR attributes
)
372 UWORD config_mode_prev
= config_mode
;
375 TRACE("%p, %d, %s, %s\n", hwnd
, request
, debugstr_w(driver
), debugstr_w(attributes
));
379 for (p
= attributes
; *p
; p
+= lstrlenW(p
) + 1)
380 TRACE("%s\n", debugstr_w(p
));
385 mapped_request
= map_request(request
);
389 mod
= load_config_driver(driver
);
393 config_mode
= get_config_mode(request
);
395 pConfigDSNW
= (void*)GetProcAddress(mod
, "ConfigDSNW");
397 ret
= pConfigDSNW(hwnd
, mapped_request
, driver
, attributes
);
399 ERR("Failed to find ConfigDSNW\n");
401 config_mode
= config_mode_prev
;
404 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
411 BOOL WINAPI
SQLConfigDataSource(HWND hwnd
, WORD request
, LPCSTR driver
, LPCSTR attributes
)
416 UWORD config_mode_prev
= config_mode
;
419 TRACE("%p, %d, %s, %s\n", hwnd
, request
, debugstr_a(driver
), debugstr_a(attributes
));
424 for (p
= attributes
; *p
; p
+= lstrlenA(p
) + 1)
425 TRACE("%s\n", debugstr_a(p
));
430 mapped_request
= map_request(request
);
434 driverW
= strdupAtoW(driver
);
437 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
441 mod
= load_config_driver(driverW
);
448 config_mode
= get_config_mode(request
);
450 pConfigDSN
= (void*)GetProcAddress(mod
, "ConfigDSN");
453 TRACE("Calling ConfigDSN\n");
454 ret
= pConfigDSN(hwnd
, mapped_request
, driver
, attributes
);
458 pConfigDSNW
= (void*)GetProcAddress(mod
, "ConfigDSNW");
462 TRACE("Calling ConfigDSNW\n");
464 attr
= SQLInstall_strdup_multi(attributes
);
466 ret
= pConfigDSNW(hwnd
, mapped_request
, driverW
, attr
);
471 config_mode
= config_mode_prev
;
474 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
482 BOOL WINAPI
SQLConfigDriverW(HWND hwnd
, WORD request
, LPCWSTR driver
,
483 LPCWSTR args
, LPWSTR msg
, WORD msgmax
, WORD
*msgout
)
485 BOOL (WINAPI
*pConfigDriverW
)(HWND hwnd
, WORD request
, const WCHAR
*driver
, const WCHAR
*args
, const WCHAR
*msg
, WORD msgmax
, WORD
*msgout
);
487 BOOL funcret
= FALSE
;
490 TRACE("(%p %d %s %s %p %d %p)\n", hwnd
, request
, debugstr_w(driver
),
491 debugstr_w(args
), msg
, msgmax
, msgout
);
493 if(request
== ODBC_CONFIG_DRIVER
)
495 return write_config_value(driver
, args
);
498 hmod
= load_config_driver(driver
);
502 pConfigDriverW
= (void*)GetProcAddress(hmod
, "ConfigDriverW");
504 funcret
= pConfigDriverW(hwnd
, request
, driver
, args
, msg
, msgmax
, msgout
);
507 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
514 BOOL WINAPI
SQLConfigDriver(HWND hwnd
, WORD request
, LPCSTR driver
,
515 LPCSTR args
, LPSTR msg
, WORD msgmax
, WORD
*msgout
)
517 BOOL (WINAPI
*pConfigDriverA
)(HWND hwnd
, WORD request
, const char *driver
, const char *args
, const char *msg
, WORD msgmax
, WORD
*msgout
);
520 BOOL funcret
= FALSE
;
523 TRACE("(%p %d %s %s %p %d %p)\n", hwnd
, request
, debugstr_a(driver
),
524 debugstr_a(args
), msg
, msgmax
, msgout
);
526 driverW
= strdupAtoW(driver
);
529 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
532 if(request
== ODBC_CONFIG_DRIVER
)
535 WCHAR
*argsW
= strdupAtoW(args
);
538 ret
= write_config_value(driverW
, argsW
);
543 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
551 hmod
= load_config_driver(driverW
);
556 pConfigDriverA
= (void*)GetProcAddress(hmod
, "ConfigDriver");
558 funcret
= pConfigDriverA(hwnd
, request
, driver
, args
, msg
, msgmax
, msgout
);
561 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
568 BOOL WINAPI
SQLCreateDataSourceW(HWND hwnd
, LPCWSTR lpszDS
)
571 FIXME("%p %s\n", hwnd
, debugstr_w(lpszDS
));
572 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
576 BOOL WINAPI
SQLCreateDataSource(HWND hwnd
, LPCSTR lpszDS
)
579 FIXME("%p %s\n", hwnd
, debugstr_a(lpszDS
));
580 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
584 BOOL WINAPI
SQLGetAvailableDriversW(LPCWSTR lpszInfFile
, LPWSTR lpszBuf
,
585 WORD cbBufMax
, WORD
*pcbBufOut
)
588 FIXME("%s %p %d %p\n", debugstr_w(lpszInfFile
), lpszBuf
, cbBufMax
, pcbBufOut
);
589 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
593 BOOL WINAPI
SQLGetAvailableDrivers(LPCSTR lpszInfFile
, LPSTR lpszBuf
,
594 WORD cbBufMax
, WORD
*pcbBufOut
)
597 FIXME("%s %p %d %p\n", debugstr_a(lpszInfFile
), lpszBuf
, cbBufMax
, pcbBufOut
);
598 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
602 BOOL WINAPI
SQLGetConfigMode(UWORD
*pwConfigMode
)
605 TRACE("%p\n", pwConfigMode
);
607 *pwConfigMode
= config_mode
;
611 BOOL WINAPI
SQLGetInstalledDriversW(WCHAR
*buf
, WORD size
, WORD
*sizeout
)
624 TRACE("%p %d %p\n", buf
, size
, sizeout
);
628 push_error(ODBC_ERROR_INVALID_BUFF_LEN
, odbc_error_invalid_buff_len
);
632 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, drivers_key
, 0, KEY_QUERY_VALUE
, &drivers
);
635 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
640 value
= malloc(valuelen
* sizeof(WCHAR
));
647 res
= RegEnumValueW(drivers
, index
, value
, &len
, NULL
, NULL
, NULL
, NULL
);
648 while (res
== ERROR_MORE_DATA
)
650 value
= realloc(value
, ++len
* sizeof(WCHAR
));
651 res
= RegEnumValueW(drivers
, index
, value
, &len
, NULL
, NULL
, NULL
, NULL
);
653 if (res
== ERROR_SUCCESS
)
655 lstrcpynW(buf
+ written
, value
, size
- written
);
656 written
+= min(len
+ 1, size
- written
);
658 else if (res
== ERROR_NO_MORE_ITEMS
)
662 push_error(ODBC_ERROR_GENERAL_ERR
, odbc_error_general_err
);
672 RegCloseKey(drivers
);
678 BOOL WINAPI
SQLGetInstalledDrivers(char *buf
, WORD size
, WORD
*sizeout
)
684 TRACE("%p %d %p\n", buf
, size
, sizeout
);
688 push_error(ODBC_ERROR_INVALID_BUFF_LEN
, odbc_error_invalid_buff_len
);
692 wbuf
= malloc(size
* sizeof(WCHAR
));
695 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
699 ret
= SQLGetInstalledDriversW(wbuf
, size
, &written
);
707 *sizeout
= WideCharToMultiByte(CP_ACP
, 0, wbuf
, written
, NULL
, 0, NULL
, NULL
);
708 WideCharToMultiByte(CP_ACP
, 0, wbuf
, written
, buf
, size
, NULL
, NULL
);
714 static HKEY
get_privateprofile_sectionkey(LPCWSTR section
, LPCWSTR filename
)
716 HKEY hkey
, hkeyfilename
, hkeysection
;
719 if (RegOpenKeyW(HKEY_CURRENT_USER
, odbcW
, &hkey
))
722 ret
= RegOpenKeyW(hkey
, filename
, &hkeyfilename
);
727 ret
= RegOpenKeyW(hkeyfilename
, section
, &hkeysection
);
728 RegCloseKey(hkeyfilename
);
730 return ret
? NULL
: hkeysection
;
733 int WINAPI
SQLGetPrivateProfileStringW(LPCWSTR section
, LPCWSTR entry
,
734 LPCWSTR defvalue
, LPWSTR buff
, int buff_len
, LPCWSTR filename
)
736 BOOL usedefault
= TRUE
;
740 TRACE("%s %s %s %p %d %s\n", debugstr_w(section
), debugstr_w(entry
),
741 debugstr_w(defvalue
), buff
, buff_len
, debugstr_w(filename
));
745 if (buff_len
<= 0 || !section
)
751 if (!defvalue
|| !buff
)
754 sectionkey
= get_privateprofile_sectionkey(section
, filename
);
761 size
= buff_len
* sizeof(*buff
);
762 if (RegGetValueW(sectionkey
, NULL
, entry
, RRF_RT_REG_SZ
, &type
, buff
, &size
) == ERROR_SUCCESS
)
765 ret
= (size
/ sizeof(*buff
)) - 1;
770 WCHAR name
[MAX_PATH
];
776 memset(buff
, 0, buff_len
);
778 namelen
= sizeof(name
);
779 while (RegEnumValueW(sectionkey
, index
, name
, &namelen
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
781 if ((ret
+ namelen
+1) > buff_len
)
784 lstrcpyW(buff
+ret
, name
);
786 namelen
= sizeof(name
);
791 RegCloseKey(sectionkey
);
794 usedefault
= entry
!= NULL
;
798 lstrcpynW(buff
, defvalue
, buff_len
);
799 ret
= lstrlenW(buff
);
805 int WINAPI
SQLGetPrivateProfileString(LPCSTR section
, LPCSTR entry
,
806 LPCSTR defvalue
, LPSTR buff
, int buff_len
, LPCSTR filename
)
808 WCHAR
*sectionW
, *filenameW
;
809 BOOL usedefault
= TRUE
;
813 TRACE("%s %s %s %p %d %s\n", debugstr_a(section
), debugstr_a(entry
),
814 debugstr_a(defvalue
), buff
, buff_len
, debugstr_a(filename
));
824 if (!section
|| !defvalue
|| !buff
)
827 sectionW
= strdupAtoW(section
);
828 filenameW
= strdupAtoW(filename
);
830 sectionkey
= get_privateprofile_sectionkey(sectionW
, filenameW
);
841 size
= buff_len
* sizeof(*buff
);
842 if (RegGetValueA(sectionkey
, NULL
, entry
, RRF_RT_REG_SZ
, &type
, buff
, &size
) == ERROR_SUCCESS
)
845 ret
= (size
/ sizeof(*buff
)) - 1;
850 char name
[MAX_PATH
] = {0};
856 memset(buff
, 0, buff_len
);
858 namelen
= sizeof(name
);
859 while (RegEnumValueA(sectionkey
, index
, name
, &namelen
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
861 if ((ret
+ namelen
+1) > buff_len
)
864 lstrcpyA(buff
+ret
, name
);
867 namelen
= sizeof(name
);
872 RegCloseKey(sectionkey
);
875 usedefault
= entry
!= NULL
;
879 lstrcpynA(buff
, defvalue
, buff_len
);
886 BOOL WINAPI
SQLGetTranslatorW(HWND hwndParent
, LPWSTR lpszName
, WORD cbNameMax
,
887 WORD
*pcbNameOut
, LPWSTR lpszPath
, WORD cbPathMax
,
888 WORD
*pcbPathOut
, DWORD
*pvOption
)
891 FIXME("%p %s %d %p %p %d %p %p\n", hwndParent
, debugstr_w(lpszName
), cbNameMax
,
892 pcbNameOut
, lpszPath
, cbPathMax
, pcbPathOut
, pvOption
);
893 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
897 BOOL WINAPI
SQLGetTranslator(HWND hwndParent
, LPSTR lpszName
, WORD cbNameMax
,
898 WORD
*pcbNameOut
, LPSTR lpszPath
, WORD cbPathMax
,
899 WORD
*pcbPathOut
, DWORD
*pvOption
)
902 FIXME("%p %s %d %p %p %d %p %p\n", hwndParent
, debugstr_a(lpszName
), cbNameMax
,
903 pcbNameOut
, lpszPath
, cbPathMax
, pcbPathOut
, pvOption
);
904 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
908 BOOL WINAPI
SQLInstallDriverW(LPCWSTR lpszInfFile
, LPCWSTR lpszDriver
,
909 LPWSTR lpszPath
, WORD cbPathMax
, WORD
* pcbPathOut
)
914 TRACE("%s %s %p %d %p\n", debugstr_w(lpszInfFile
),
915 debugstr_w(lpszDriver
), lpszPath
, cbPathMax
, pcbPathOut
);
920 return SQLInstallDriverExW(lpszDriver
, NULL
, lpszPath
, cbPathMax
,
921 pcbPathOut
, ODBC_INSTALL_COMPLETE
, &usage
);
924 BOOL WINAPI
SQLInstallDriver(LPCSTR lpszInfFile
, LPCSTR lpszDriver
,
925 LPSTR lpszPath
, WORD cbPathMax
, WORD
* pcbPathOut
)
930 TRACE("%s %s %p %d %p\n", debugstr_a(lpszInfFile
),
931 debugstr_a(lpszDriver
), lpszPath
, cbPathMax
, pcbPathOut
);
936 return SQLInstallDriverEx(lpszDriver
, NULL
, lpszPath
, cbPathMax
,
937 pcbPathOut
, ODBC_INSTALL_COMPLETE
, &usage
);
940 static void write_registry_values(const WCHAR
*regkey
, const WCHAR
*driver
, const WCHAR
*path_in
, WCHAR
*path
,
943 static const WCHAR installed
[] = {'I','n','s','t','a','l','l','e','d',0};
944 static const WCHAR slash
[] = {'\\', 0};
945 static const WCHAR driverW
[] = {'D','r','i','v','e','r',0};
946 static const WCHAR setupW
[] = {'S','e','t','u','p',0};
947 static const WCHAR translator
[] = {'T','r','a','n','s','l','a','t','o','r',0};
948 HKEY hkey
, hkeydriver
;
950 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
) == ERROR_SUCCESS
)
952 if (RegCreateKeyW(hkey
, regkey
, &hkeydriver
) == ERROR_SUCCESS
)
954 if(RegSetValueExW(hkeydriver
, driver
, 0, REG_SZ
, (BYTE
*)installed
, sizeof(installed
)) != ERROR_SUCCESS
)
955 ERR("Failed to write registry installed key\n");
957 RegCloseKey(hkeydriver
);
960 if (RegCreateKeyW(hkey
, driver
, &hkeydriver
) == ERROR_SUCCESS
)
964 DWORD usagecount
= 0;
967 /* Skip name entry */
969 p
+= lstrlenW(p
) + 1;
972 GetSystemDirectoryW(path
, MAX_PATH
);
974 lstrcpyW(path
, path_in
);
977 size
= sizeof(usagecount
);
978 RegGetValueA(hkeydriver
, NULL
, "UsageCount", RRF_RT_DWORD
, &type
, &usagecount
, &size
);
979 TRACE("Usage count %ld\n", usagecount
);
981 for (; *p
; p
+= lstrlenW(p
) + 1)
983 WCHAR
*divider
= wcschr(p
,'=');
990 /* Write pair values to the registry. */
991 lstrcpynW(entry
, p
, divider
- p
+ 1);
994 TRACE("Writing pair %s,%s\n", debugstr_w(entry
), debugstr_w(divider
));
996 /* Driver, Setup, Translator entries use the system path unless a path is specified. */
997 if(lstrcmpiW(driverW
, entry
) == 0 || lstrcmpiW(setupW
, entry
) == 0 ||
998 lstrcmpiW(translator
, entry
) == 0)
1000 len
= lstrlenW(path
) + lstrlenW(slash
) + lstrlenW(divider
) + 1;
1001 value
= malloc(len
* sizeof(WCHAR
));
1004 ERR("Out of memory\n");
1008 lstrcpyW(value
, path
);
1009 lstrcatW(value
, slash
);
1010 lstrcatW(value
, divider
);
1014 len
= lstrlenW(divider
) + 1;
1015 value
= malloc(len
* sizeof(WCHAR
));
1016 lstrcpyW(value
, divider
);
1019 if (RegSetValueExW(hkeydriver
, entry
, 0, REG_SZ
, (BYTE
*)value
,
1020 (lstrlenW(value
)+1)*sizeof(WCHAR
)) != ERROR_SUCCESS
)
1021 ERR("Failed to write registry data %s %s\n", debugstr_w(entry
), debugstr_w(value
));
1026 ERR("No pair found. %s\n", debugstr_w(p
));
1031 /* Set Usage Count */
1033 if (RegSetValueExA(hkeydriver
, "UsageCount", 0, REG_DWORD
, (BYTE
*)&usagecount
, sizeof(usagecount
)) != ERROR_SUCCESS
)
1034 ERR("Failed to write registry UsageCount key\n");
1037 *usage_count
= usagecount
;
1039 RegCloseKey(hkeydriver
);
1046 BOOL WINAPI
SQLInstallDriverExW(LPCWSTR lpszDriver
, LPCWSTR lpszPathIn
,
1047 LPWSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1048 WORD fRequest
, LPDWORD lpdwUsageCount
)
1051 WCHAR path
[MAX_PATH
];
1054 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszDriver
),
1055 debugstr_w(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1056 fRequest
, lpdwUsageCount
);
1058 write_registry_values(odbcdrivers
, lpszDriver
, lpszPathIn
, path
, lpdwUsageCount
);
1060 len
= lstrlenW(path
);
1065 if (lpszPathOut
&& cbPathOutMax
> len
)
1067 lstrcpyW(lpszPathOut
, path
);
1073 BOOL WINAPI
SQLInstallDriverEx(LPCSTR lpszDriver
, LPCSTR lpszPathIn
,
1074 LPSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1075 WORD fRequest
, LPDWORD lpdwUsageCount
)
1077 LPWSTR driver
, pathin
;
1078 WCHAR pathout
[MAX_PATH
];
1083 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszDriver
),
1084 debugstr_a(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1085 fRequest
, lpdwUsageCount
);
1087 driver
= SQLInstall_strdup_multi(lpszDriver
);
1088 pathin
= SQLInstall_strdup(lpszPathIn
);
1090 ret
= SQLInstallDriverExW(driver
, pathin
, pathout
, MAX_PATH
, &cbOut
,
1091 fRequest
, lpdwUsageCount
);
1094 int len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1099 *pcbPathOut
= len
- 1;
1101 if (!lpszPathOut
|| cbPathOutMax
< len
)
1106 len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1107 cbPathOutMax
, NULL
, NULL
);
1117 BOOL WINAPI
SQLInstallDriverManagerW(LPWSTR lpszPath
, WORD cbPathMax
,
1121 WCHAR path
[MAX_PATH
];
1123 TRACE("(%p %d %p)\n", lpszPath
, cbPathMax
, pcbPathOut
);
1125 if (cbPathMax
< MAX_PATH
)
1130 len
= GetSystemDirectoryW(path
, MAX_PATH
);
1135 if (lpszPath
&& cbPathMax
> len
)
1137 lstrcpyW(lpszPath
, path
);
1143 BOOL WINAPI
SQLInstallDriverManager(LPSTR lpszPath
, WORD cbPathMax
,
1147 WORD len
, cbOut
= 0;
1148 WCHAR path
[MAX_PATH
];
1150 TRACE("(%p %d %p)\n", lpszPath
, cbPathMax
, pcbPathOut
);
1152 if (cbPathMax
< MAX_PATH
)
1157 ret
= SQLInstallDriverManagerW(path
, MAX_PATH
, &cbOut
);
1160 len
= WideCharToMultiByte(CP_ACP
, 0, path
, -1, lpszPath
, 0,
1165 *pcbPathOut
= len
- 1;
1167 if (!lpszPath
|| cbPathMax
< len
)
1170 len
= WideCharToMultiByte(CP_ACP
, 0, path
, -1, lpszPath
,
1171 cbPathMax
, NULL
, NULL
);
1177 BOOL WINAPI
SQLInstallODBCW(HWND hwndParent
, LPCWSTR lpszInfFile
,
1178 LPCWSTR lpszSrcPath
, LPCWSTR lpszDrivers
)
1181 FIXME("%p %s %s %s\n", hwndParent
, debugstr_w(lpszInfFile
),
1182 debugstr_w(lpszSrcPath
), debugstr_w(lpszDrivers
));
1183 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1187 BOOL WINAPI
SQLInstallODBC(HWND hwndParent
, LPCSTR lpszInfFile
,
1188 LPCSTR lpszSrcPath
, LPCSTR lpszDrivers
)
1191 FIXME("%p %s %s %s\n", hwndParent
, debugstr_a(lpszInfFile
),
1192 debugstr_a(lpszSrcPath
), debugstr_a(lpszDrivers
));
1193 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1197 SQLRETURN WINAPI
SQLInstallerErrorW(WORD iError
, DWORD
*pfErrorCode
,
1198 LPWSTR lpszErrorMsg
, WORD cbErrorMsgMax
, WORD
*pcbErrorMsg
)
1200 TRACE("%d %p %p %d %p\n", iError
, pfErrorCode
, lpszErrorMsg
,
1201 cbErrorMsgMax
, pcbErrorMsg
);
1207 else if (iError
<= num_errors
)
1209 BOOL truncated
= FALSE
;
1214 *pfErrorCode
= error_code
[iError
];
1215 msg
= error_msg
[iError
];
1216 len
= msg
? lstrlenW(msg
) : 0;
1220 if (cbErrorMsgMax
< len
)
1222 len
= cbErrorMsgMax
;
1225 if (lpszErrorMsg
&& len
)
1229 memcpy (lpszErrorMsg
, msg
, len
* sizeof(WCHAR
));
1239 /* Yes. If you pass a null pointer and a large length it is not an error! */
1243 return truncated
? SQL_SUCCESS_WITH_INFO
: SQL_SUCCESS
;
1246 /* 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 */
1250 if (lpszErrorMsg
&& cbErrorMsgMax
> 0)
1251 *lpszErrorMsg
= '\0';
1256 SQLRETURN WINAPI
SQLInstallerError(WORD iError
, DWORD
*pfErrorCode
,
1257 LPSTR lpszErrorMsg
, WORD cbErrorMsgMax
, WORD
*pcbErrorMsg
)
1262 TRACE("%d %p %p %d %p\n", iError
, pfErrorCode
, lpszErrorMsg
,
1263 cbErrorMsgMax
, pcbErrorMsg
);
1266 if (lpszErrorMsg
&& cbErrorMsgMax
)
1268 wbuf
= malloc(cbErrorMsgMax
* sizeof(WCHAR
));
1272 ret
= SQLInstallerErrorW(iError
, pfErrorCode
, wbuf
, cbErrorMsgMax
, &cbwbuf
);
1276 SQLInstall_narrow(1, lpszErrorMsg
, wbuf
, cbwbuf
+1, cbErrorMsgMax
, &cbBuf
);
1279 *pcbErrorMsg
= cbBuf
-1;
1284 BOOL WINAPI
SQLInstallTranslatorExW(LPCWSTR lpszTranslator
, LPCWSTR lpszPathIn
,
1285 LPWSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1286 WORD fRequest
, LPDWORD lpdwUsageCount
)
1289 WCHAR path
[MAX_PATH
];
1292 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszTranslator
),
1293 debugstr_w(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1294 fRequest
, lpdwUsageCount
);
1296 write_registry_values(odbctranslators
, lpszTranslator
, lpszPathIn
, path
, lpdwUsageCount
);
1298 len
= lstrlenW(path
);
1303 if (lpszPathOut
&& cbPathOutMax
> len
)
1305 lstrcpyW(lpszPathOut
, path
);
1311 BOOL WINAPI
SQLInstallTranslatorEx(LPCSTR lpszTranslator
, LPCSTR lpszPathIn
,
1312 LPSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1313 WORD fRequest
, LPDWORD lpdwUsageCount
)
1316 LPWSTR translator
, pathin
;
1317 WCHAR pathout
[MAX_PATH
];
1322 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszTranslator
),
1323 debugstr_a(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1324 fRequest
, lpdwUsageCount
);
1326 for (p
= lpszTranslator
; *p
; p
+= lstrlenA(p
) + 1)
1327 TRACE("%s\n", debugstr_a(p
));
1329 translator
= SQLInstall_strdup_multi(lpszTranslator
);
1330 pathin
= SQLInstall_strdup(lpszPathIn
);
1332 ret
= SQLInstallTranslatorExW(translator
, pathin
, pathout
, MAX_PATH
,
1333 &cbOut
, fRequest
, lpdwUsageCount
);
1336 int len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1341 *pcbPathOut
= len
- 1;
1343 if (!lpszPathOut
|| cbPathOutMax
< len
)
1348 len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1349 cbPathOutMax
, NULL
, NULL
);
1359 BOOL WINAPI
SQLInstallTranslator(LPCSTR lpszInfFile
, LPCSTR lpszTranslator
,
1360 LPCSTR lpszPathIn
, LPSTR lpszPathOut
, WORD cbPathOutMax
,
1361 WORD
*pcbPathOut
, WORD fRequest
, LPDWORD lpdwUsageCount
)
1364 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_a(lpszInfFile
),
1365 debugstr_a(lpszTranslator
), debugstr_a(lpszPathIn
), lpszPathOut
,
1366 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1371 return SQLInstallTranslatorEx(lpszTranslator
, lpszPathIn
, lpszPathOut
,
1372 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1375 BOOL WINAPI
SQLInstallTranslatorW(LPCWSTR lpszInfFile
, LPCWSTR lpszTranslator
,
1376 LPCWSTR lpszPathIn
, LPWSTR lpszPathOut
, WORD cbPathOutMax
,
1377 WORD
*pcbPathOut
, WORD fRequest
, LPDWORD lpdwUsageCount
)
1380 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_w(lpszInfFile
),
1381 debugstr_w(lpszTranslator
), debugstr_w(lpszPathIn
), lpszPathOut
,
1382 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1387 return SQLInstallTranslatorExW(lpszTranslator
, lpszPathIn
, lpszPathOut
,
1388 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1391 BOOL WINAPI
SQLManageDataSources(HWND hwnd
)
1394 FIXME("%p\n", hwnd
);
1395 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1399 SQLRETURN WINAPI
SQLPostInstallerErrorW(DWORD fErrorCode
, LPCWSTR szErrorMsg
)
1401 FIXME("%lu %s\n", fErrorCode
, debugstr_w(szErrorMsg
));
1402 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1406 SQLRETURN WINAPI
SQLPostInstallerError(DWORD fErrorCode
, LPCSTR szErrorMsg
)
1408 FIXME("%lu %s\n", fErrorCode
, debugstr_a(szErrorMsg
));
1409 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1413 BOOL WINAPI
SQLReadFileDSNW(LPCWSTR lpszFileName
, LPCWSTR lpszAppName
,
1414 LPCWSTR lpszKeyName
, LPWSTR lpszString
, WORD cbString
,
1418 FIXME("%s %s %s %s %d %p\n", debugstr_w(lpszFileName
), debugstr_w(lpszAppName
),
1419 debugstr_w(lpszKeyName
), debugstr_w(lpszString
), cbString
, pcbString
);
1420 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1424 BOOL WINAPI
SQLReadFileDSN(LPCSTR lpszFileName
, LPCSTR lpszAppName
,
1425 LPCSTR lpszKeyName
, LPSTR lpszString
, WORD cbString
,
1429 FIXME("%s %s %s %s %d %p\n", debugstr_a(lpszFileName
), debugstr_a(lpszAppName
),
1430 debugstr_a(lpszKeyName
), debugstr_a(lpszString
), cbString
, pcbString
);
1431 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1435 BOOL WINAPI
SQLRemoveDefaultDataSource(void)
1439 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1443 BOOL WINAPI
SQLRemoveDriverW(LPCWSTR drivername
, BOOL remove_dsn
, LPDWORD usage_count
)
1446 DWORD usagecount
= 1;
1449 TRACE("%s %d %p\n", debugstr_w(drivername
), remove_dsn
, usage_count
);
1451 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
) == ERROR_SUCCESS
)
1455 if (RegOpenKeyW(hkey
, drivername
, &hkeydriver
) == ERROR_SUCCESS
)
1460 size
= sizeof(usagecount
);
1461 RegGetValueA(hkeydriver
, NULL
, "UsageCount", RRF_RT_DWORD
, &type
, &usagecount
, &size
);
1462 TRACE("Usage count %ld\n", usagecount
);
1463 count
= usagecount
- 1;
1466 if (RegSetValueExA(hkeydriver
, "UsageCount", 0, REG_DWORD
, (BYTE
*)&count
, sizeof(count
)) != ERROR_SUCCESS
)
1467 ERR("Failed to write registry UsageCount key\n");
1470 RegCloseKey(hkeydriver
);
1478 if (RegDeleteKeyW(hkey
, drivername
) != ERROR_SUCCESS
)
1479 ERR("Failed to delete registry key: %s\n", debugstr_w(drivername
));
1481 if (RegOpenKeyW(hkey
, odbcdrivers
, &hkeydriver
) == ERROR_SUCCESS
)
1483 if(RegDeleteValueW(hkeydriver
, drivername
) != ERROR_SUCCESS
)
1484 ERR("Failed to delete registry value: %s\n", debugstr_w(drivername
));
1485 RegCloseKey(hkeydriver
);
1493 *usage_count
= usagecount
;
1498 BOOL WINAPI
SQLRemoveDriver(LPCSTR lpszDriver
, BOOL fRemoveDSN
,
1499 LPDWORD lpdwUsageCount
)
1505 TRACE("%s %d %p\n", debugstr_a(lpszDriver
), fRemoveDSN
, lpdwUsageCount
);
1507 driver
= SQLInstall_strdup(lpszDriver
);
1509 ret
= SQLRemoveDriverW(driver
, fRemoveDSN
, lpdwUsageCount
);
1515 BOOL WINAPI
SQLRemoveDriverManager(LPDWORD pdwUsageCount
)
1518 FIXME("%p\n", pdwUsageCount
);
1519 if (pdwUsageCount
) *pdwUsageCount
= 1;
1523 BOOL WINAPI
SQLRemoveDSNFromIniW(LPCWSTR lpszDSN
)
1527 TRACE("%s\n", debugstr_w(lpszDSN
));
1531 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\ODBC\\ODBC.INI\\ODBC Data Sources", &hkey
) == ERROR_SUCCESS
)
1533 RegDeleteValueW(hkey
, lpszDSN
);
1537 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\ODBC\\ODBC.INI", &hkey
) == ERROR_SUCCESS
)
1539 RegDeleteTreeW(hkey
, lpszDSN
);
1546 BOOL WINAPI
SQLRemoveDSNFromIni(LPCSTR lpszDSN
)
1551 TRACE("%s\n", debugstr_a(lpszDSN
));
1555 dsn
= SQLInstall_strdup(lpszDSN
);
1557 ret
= SQLRemoveDSNFromIniW(dsn
);
1559 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
1566 BOOL WINAPI
SQLRemoveTranslatorW(const WCHAR
*translator
, DWORD
*usage_count
)
1569 DWORD usagecount
= 1;
1573 TRACE("%s %p\n", debugstr_w(translator
), usage_count
);
1575 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
) == ERROR_SUCCESS
)
1579 if (RegOpenKeyW(hkey
, translator
, &hkeydriver
) == ERROR_SUCCESS
)
1584 size
= sizeof(usagecount
);
1585 RegGetValueA(hkeydriver
, NULL
, "UsageCount", RRF_RT_DWORD
, &type
, &usagecount
, &size
);
1586 TRACE("Usage count %ld\n", usagecount
);
1587 count
= usagecount
- 1;
1590 if (RegSetValueExA(hkeydriver
, "UsageCount", 0, REG_DWORD
, (BYTE
*)&count
, sizeof(count
)) != ERROR_SUCCESS
)
1591 ERR("Failed to write registry UsageCount key\n");
1594 RegCloseKey(hkeydriver
);
1602 if(RegDeleteKeyW(hkey
, translator
) != ERROR_SUCCESS
)
1604 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
1605 WARN("Failed to delete registry key: %s\n", debugstr_w(translator
));
1609 if (ret
&& RegOpenKeyW(hkey
, odbctranslators
, &hkeydriver
) == ERROR_SUCCESS
)
1611 if(RegDeleteValueW(hkeydriver
, translator
) != ERROR_SUCCESS
)
1613 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
1614 WARN("Failed to delete registry key: %s\n", debugstr_w(translator
));
1618 RegCloseKey(hkeydriver
);
1625 if (ret
&& usage_count
)
1626 *usage_count
= usagecount
;
1631 BOOL WINAPI
SQLRemoveTranslator(LPCSTR lpszTranslator
, LPDWORD lpdwUsageCount
)
1637 TRACE("%s %p\n", debugstr_a(lpszTranslator
), lpdwUsageCount
);
1639 translator
= SQLInstall_strdup(lpszTranslator
);
1640 ret
= SQLRemoveTranslatorW(translator
, lpdwUsageCount
);
1646 BOOL WINAPI
SQLSetConfigMode(UWORD wConfigMode
)
1649 TRACE("%u\n", wConfigMode
);
1651 if (wConfigMode
> ODBC_SYSTEM_DSN
)
1653 push_error(ODBC_ERROR_INVALID_PARAM_SEQUENCE
, odbc_error_invalid_param_sequence
);
1658 config_mode
= wConfigMode
;
1663 BOOL WINAPI
SQLValidDSNW(LPCWSTR lpszDSN
)
1665 static const WCHAR invalid
[] = {'[',']','{','}','(',')',',',';','?','*','=','!','@','\\',0};
1667 TRACE("%s\n", debugstr_w(lpszDSN
));
1669 if(lstrlenW(lpszDSN
) > SQL_MAX_DSN_LENGTH
|| wcspbrk(lpszDSN
, invalid
) != NULL
)
1677 BOOL WINAPI
SQLValidDSN(LPCSTR lpszDSN
)
1679 static const char *invalid
= "[]{}(),;?*=!@\\";
1681 TRACE("%s\n", debugstr_a(lpszDSN
));
1683 if(strlen(lpszDSN
) > SQL_MAX_DSN_LENGTH
|| strpbrk(lpszDSN
, invalid
) != NULL
)
1691 BOOL WINAPI
SQLWriteDSNToIniW(LPCWSTR lpszDSN
, LPCWSTR lpszDriver
)
1694 HKEY hkey
, hkeydriver
;
1695 WCHAR filename
[MAX_PATH
];
1697 TRACE("%s %s\n", debugstr_w(lpszDSN
), debugstr_w(lpszDriver
));
1701 if (!SQLValidDSNW(lpszDSN
))
1703 push_error(ODBC_ERROR_INVALID_DSN
, odbc_error_invalid_dsn
);
1707 /* It doesn't matter if we cannot find the driver, windows just writes a blank value. */
1709 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
) == ERROR_SUCCESS
)
1713 if (RegOpenKeyW(hkey
, lpszDriver
, &hkeydriver
) == ERROR_SUCCESS
)
1715 DWORD size
= MAX_PATH
* sizeof(WCHAR
);
1716 RegGetValueW(hkeydriver
, NULL
, L
"driver", RRF_RT_REG_SZ
, NULL
, filename
, &size
);
1717 RegCloseKey(hkeydriver
);
1722 if ((ret
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\ODBC\\ODBC.INI", &hkey
)) == ERROR_SUCCESS
)
1726 if ((ret
= RegCreateKeyW(hkey
, L
"ODBC Data Sources", &sources
)) == ERROR_SUCCESS
)
1728 RegSetValueExW(sources
, lpszDSN
, 0, REG_SZ
, (BYTE
*)lpszDriver
, (lstrlenW(lpszDriver
)+1)*sizeof(WCHAR
));
1729 RegCloseKey(sources
);
1731 RegDeleteTreeW(hkey
, lpszDSN
);
1732 if ((ret
= RegCreateKeyW(hkey
, lpszDSN
, &hkeydriver
)) == ERROR_SUCCESS
)
1734 RegSetValueExW(sources
, L
"driver", 0, REG_SZ
, (BYTE
*)filename
, (lstrlenW(filename
)+1)*sizeof(WCHAR
));
1735 RegCloseKey(hkeydriver
);
1741 if (ret
!= ERROR_SUCCESS
)
1742 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
1744 return ret
== ERROR_SUCCESS
;
1747 BOOL WINAPI
SQLWriteDSNToIni(LPCSTR lpszDSN
, LPCSTR lpszDriver
)
1750 WCHAR
*dsn
, *driver
;
1752 TRACE("%s %s\n", debugstr_a(lpszDSN
), debugstr_a(lpszDriver
));
1754 dsn
= SQLInstall_strdup(lpszDSN
);
1755 driver
= SQLInstall_strdup(lpszDriver
);
1757 ret
= SQLWriteDSNToIniW(dsn
, driver
);
1759 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
1767 BOOL WINAPI
SQLWriteFileDSNW(LPCWSTR lpszFileName
, LPCWSTR lpszAppName
,
1768 LPCWSTR lpszKeyName
, LPCWSTR lpszString
)
1771 FIXME("%s %s %s %s\n", debugstr_w(lpszFileName
), debugstr_w(lpszAppName
),
1772 debugstr_w(lpszKeyName
), debugstr_w(lpszString
));
1773 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1777 BOOL WINAPI
SQLWriteFileDSN(LPCSTR lpszFileName
, LPCSTR lpszAppName
,
1778 LPCSTR lpszKeyName
, LPCSTR lpszString
)
1781 FIXME("%s %s %s %s\n", debugstr_a(lpszFileName
), debugstr_a(lpszAppName
),
1782 debugstr_a(lpszKeyName
), debugstr_a(lpszString
));
1783 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1787 BOOL WINAPI
SQLWritePrivateProfileStringW(LPCWSTR lpszSection
, LPCWSTR lpszEntry
,
1788 LPCWSTR lpszString
, LPCWSTR lpszFilename
)
1790 static const WCHAR empty
[] = {0};
1795 TRACE("%s %s %s %s\n", debugstr_w(lpszSection
), debugstr_w(lpszEntry
),
1796 debugstr_w(lpszString
), debugstr_w(lpszFilename
));
1798 if(!lpszFilename
|| !*lpszFilename
)
1800 push_error(ODBC_ERROR_INVALID_STR
, odbc_error_invalid_param_string
);
1804 if ((ret
= RegCreateKeyW(HKEY_CURRENT_USER
, odbcW
, &hkey
)) == ERROR_SUCCESS
)
1808 if ((ret
= RegCreateKeyW(hkey
, lpszFilename
, &hkeyfilename
)) == ERROR_SUCCESS
)
1812 if ((ret
= RegCreateKeyW(hkeyfilename
, lpszSection
, &hkey_section
)) == ERROR_SUCCESS
)
1815 ret
= RegSetValueExW(hkey_section
, lpszEntry
, 0, REG_SZ
, (BYTE
*)lpszString
, (lstrlenW(lpszString
)+1)*sizeof(WCHAR
));
1817 ret
= RegSetValueExW(hkey_section
, lpszEntry
, 0, REG_SZ
, (BYTE
*)empty
, sizeof(empty
));
1818 RegCloseKey(hkey_section
);
1821 RegCloseKey(hkeyfilename
);
1827 return ret
== ERROR_SUCCESS
;
1830 BOOL WINAPI
SQLWritePrivateProfileString(LPCSTR lpszSection
, LPCSTR lpszEntry
,
1831 LPCSTR lpszString
, LPCSTR lpszFilename
)
1834 WCHAR
*sect
, *entry
, *string
, *file
;
1836 TRACE("%s %s %s %s\n", lpszSection
, lpszEntry
, lpszString
, lpszFilename
);
1838 sect
= strdupAtoW(lpszSection
);
1839 entry
= strdupAtoW(lpszEntry
);
1840 string
= strdupAtoW(lpszString
);
1841 file
= strdupAtoW(lpszFilename
);
1843 ret
= SQLWritePrivateProfileStringW(sect
, entry
, string
, file
);