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"
34 #include "wine/heap.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(odbc
);
40 /* Registry key names */
41 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};
42 static const WCHAR odbcW
[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C',0};
43 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};
44 static const WCHAR odbcdrivers
[] = {'O','D','B','C',' ','D','r','i','v','e','r','s',0};
45 static const WCHAR odbctranslators
[] = {'O','D','B','C',' ','T','r','a','n','s','l','a','t','o','r','s',0};
47 /* This config mode is known to be process-wide.
48 * MSDN documentation suggests that the value is hidden somewhere in the registry but I haven't found it yet.
49 * Although both the registry and the ODBC.ini files appear to be maintained together they are not maintained automatically through the registry's IniFileMapping.
51 static UWORD config_mode
= ODBC_BOTH_DSN
;
53 /* MSDN documentation suggests that the error subsystem handles errors 1 to 8
54 * only and experimentation (Windows 2000) shows that the errors are process-
55 * wide so go for the simple solution; static arrays.
57 static int num_errors
;
58 static int error_code
[8];
59 static const WCHAR
*error_msg
[8];
60 static const WCHAR odbc_error_general_err
[] = {'G','e','n','e','r','a','l',' ','e','r','r','o','r',0};
61 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};
62 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};
63 static const WCHAR odbc_error_out_of_mem
[] = {'O','u','t',' ','o','f',' ','m','e','m','o','r','y',0};
64 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};
65 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};
66 static const WCHAR odbc_error_invalid_dsn
[] = {'I','n','v','a','l','i','d',' ','D','S','N',0};
67 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};
68 static const WCHAR odbc_error_request_failed
[] = {'R','e','q','u','e','s','t',' ','F','a','i','l','e','d',0};
69 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};
71 static BOOL (WINAPI
*pConfigDSN
)(HWND hwnd
, WORD request
, const char *driver
, const char *attr
);
72 static BOOL (WINAPI
*pConfigDSNW
)(HWND hwnd
, WORD request
, const WCHAR
*driver
, const WCHAR
*attr
);
74 /* Push an error onto the error stack, taking care of ranges etc. */
75 static void push_error(int code
, LPCWSTR msg
)
77 if (num_errors
< ARRAY_SIZE(error_code
))
79 error_code
[num_errors
] = code
;
80 error_msg
[num_errors
] = msg
;
85 /* Clear the error stack */
86 static void clear_errors(void)
91 static inline WCHAR
*heap_strdupAtoW(const char *str
)
98 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
99 ret
= heap_alloc(len
*sizeof(WCHAR
));
101 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
108 BOOL WINAPI
ODBCCPlApplet( LONG i
, LONG j
, LONG
* p1
, LONG
* p2
)
111 FIXME( "( %d %d %p %p) : stub!\n", i
, j
, p1
, p2
);
115 static LPWSTR
SQLInstall_strdup_multi(LPCSTR str
)
124 for (p
= str
; *p
; p
+= lstrlenA(p
) + 1)
127 len
= MultiByteToWideChar(CP_ACP
, 0, str
, p
- str
, NULL
, 0 );
128 ret
= HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
129 MultiByteToWideChar(CP_ACP
, 0, str
, p
- str
, ret
, len
);
135 static LPWSTR
SQLInstall_strdup(LPCSTR str
)
143 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0 );
144 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
145 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
150 /* Convert the wide string or zero-length-terminated list of wide strings to a
151 * narrow string or zero-length-terminated list of narrow strings.
152 * Do not try to emulate windows undocumented excesses (e.g. adding a third \0
155 * mode Indicates the sort of string.
156 * 1 denotes that the buffers contain strings terminated by a single nul
158 * 2 denotes that the buffers contain zero-length-terminated lists
159 * (frequently erroneously referred to as double-null-terminated)
160 * buffer The narrow-character buffer into which to place the result. This
161 * must be a non-null pointer to the first element of a buffer whose
162 * length is passed in buffer_length.
163 * str The wide-character buffer containing the string or list of strings to
164 * be converted. str_length defines how many wide characters in the
165 * buffer are to be converted, including all desired terminating nul
167 * str_length Effective length of str
168 * buffer_length Length of buffer
169 * returned_length A pointer to a variable that will receive the number of
170 * narrow characters placed into the buffer. This pointer
173 static BOOL
SQLInstall_narrow(int mode
, LPSTR buffer
, LPCWSTR str
, WORD str_length
, WORD buffer_length
, WORD
*returned_length
)
175 LPSTR pbuf
; /* allows us to allocate a temporary buffer only if needed */
176 int len
; /* Length of the converted list */
177 BOOL success
= FALSE
;
178 assert(mode
== 1 || mode
== 2);
179 assert(buffer_length
);
180 len
= WideCharToMultiByte(CP_ACP
, 0, str
, str_length
, 0, 0, NULL
, NULL
);
183 if (len
> buffer_length
)
185 pbuf
= HeapAlloc(GetProcessHeap(), 0, len
);
191 len
= WideCharToMultiByte(CP_ACP
, 0, str
, str_length
, pbuf
, len
, NULL
, NULL
);
196 if (buffer_length
> (mode
- 1))
198 memcpy (buffer
, pbuf
, buffer_length
-mode
);
199 *(buffer
+buffer_length
-mode
) = '\0';
201 *(buffer
+buffer_length
-1) = '\0';
205 *returned_length
= pbuf
== buffer
? len
: buffer_length
;
211 ERR("transferring wide to narrow\n");
215 HeapFree(GetProcessHeap(), 0, pbuf
);
220 ERR("measuring wide to narrow\n");
225 static HMODULE
load_config_driver(const WCHAR
*driver
)
227 static WCHAR reg_driver
[] = {'d','r','i','v','e','r',0};
230 WCHAR
*filename
= NULL
;
231 DWORD size
= 0, type
;
234 if ((ret
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
)) == ERROR_SUCCESS
)
238 if ((ret
= RegOpenKeyW(hkey
, driver
, &hkeydriver
)) == ERROR_SUCCESS
)
240 ret
= RegGetValueW(hkeydriver
, NULL
, reg_driver
, RRF_RT_REG_SZ
, &type
, NULL
, &size
);
241 if(ret
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
243 RegCloseKey(hkeydriver
);
245 push_error(ODBC_ERROR_INVALID_DSN
, odbc_error_invalid_dsn
);
250 filename
= HeapAlloc(GetProcessHeap(), 0, size
);
253 RegCloseKey(hkeydriver
);
255 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
259 ret
= RegGetValueW(hkeydriver
, NULL
, reg_driver
, RRF_RT_REG_SZ
, &type
, filename
, &size
);
261 RegCloseKey(hkeydriver
);
267 if(ret
!= ERROR_SUCCESS
)
269 HeapFree(GetProcessHeap(), 0, filename
);
270 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
274 hmod
= LoadLibraryW(filename
);
275 HeapFree(GetProcessHeap(), 0, filename
);
278 push_error(ODBC_ERROR_LOAD_LIB_FAILED
, odbc_error_load_lib_failed
);
283 static BOOL
write_config_value(const WCHAR
*driver
, const WCHAR
*args
)
286 HKEY hkey
, hkeydriver
;
292 if((ret
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
)) == ERROR_SUCCESS
)
294 if((ret
= RegOpenKeyW(hkey
, driver
, &hkeydriver
)) == ERROR_SUCCESS
)
296 WCHAR
*divider
, *value
;
298 name
= heap_alloc( (lstrlenW(args
) + 1) * sizeof(WCHAR
));
301 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
304 lstrcpyW(name
, args
);
306 divider
= wcschr(name
,'=');
309 push_error(ODBC_ERROR_INVALID_KEYWORD_VALUE
, odbc_error_invalid_keyword
);
316 TRACE("Write pair: %s = %s\n", debugstr_w(name
), debugstr_w(value
));
317 if(RegSetValueExW(hkeydriver
, name
, 0, REG_SZ
, (BYTE
*)value
,
318 (lstrlenW(value
)+1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
319 ERR("Failed to write registry installed key\n");
322 RegCloseKey(hkeydriver
);
328 if(ret
!= ERROR_SUCCESS
)
329 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
331 return ret
== ERROR_SUCCESS
;
334 RegCloseKey(hkeydriver
);
341 BOOL WINAPI
SQLConfigDataSourceW(HWND hwnd
, WORD request
, LPCWSTR driver
, LPCWSTR attributes
)
346 TRACE("%p, %d, %s, %s\n", hwnd
, request
, debugstr_w(driver
), debugstr_w(attributes
));
350 for (p
= attributes
; *p
; p
+= lstrlenW(p
) + 1)
351 TRACE("%s\n", debugstr_w(p
));
356 mod
= load_config_driver(driver
);
360 pConfigDSNW
= (void*)GetProcAddress(mod
, "ConfigDSNW");
362 ret
= pConfigDSNW(hwnd
, request
, driver
, attributes
);
364 ERR("Failed to find ConfigDSNW\n");
367 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
374 BOOL WINAPI
SQLConfigDataSource(HWND hwnd
, WORD request
, LPCSTR driver
, LPCSTR attributes
)
380 TRACE("%p, %d, %s, %s\n", hwnd
, request
, debugstr_a(driver
), debugstr_a(attributes
));
385 for (p
= attributes
; *p
; p
+= lstrlenA(p
) + 1)
386 TRACE("%s\n", debugstr_a(p
));
391 driverW
= heap_strdupAtoW(driver
);
394 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
398 mod
= load_config_driver(driverW
);
405 pConfigDSN
= (void*)GetProcAddress(mod
, "ConfigDSN");
408 TRACE("Calling ConfigDSN\n");
409 ret
= pConfigDSN(hwnd
, request
, driver
, attributes
);
413 pConfigDSNW
= (void*)GetProcAddress(mod
, "ConfigDSNW");
417 TRACE("Calling ConfigDSNW\n");
419 attr
= SQLInstall_strdup_multi(attributes
);
421 ret
= pConfigDSNW(hwnd
, request
, driverW
, attr
);
427 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
435 BOOL WINAPI
SQLConfigDriverW(HWND hwnd
, WORD request
, LPCWSTR driver
,
436 LPCWSTR args
, LPWSTR msg
, WORD msgmax
, WORD
*msgout
)
438 BOOL (WINAPI
*pConfigDriverW
)(HWND hwnd
, WORD request
, const WCHAR
*driver
, const WCHAR
*args
, const WCHAR
*msg
, WORD msgmax
, WORD
*msgout
);
440 BOOL funcret
= FALSE
;
443 TRACE("(%p %d %s %s %p %d %p)\n", hwnd
, request
, debugstr_w(driver
),
444 debugstr_w(args
), msg
, msgmax
, msgout
);
446 if(request
== ODBC_CONFIG_DRIVER
)
448 return write_config_value(driver
, args
);
451 hmod
= load_config_driver(driver
);
455 pConfigDriverW
= (void*)GetProcAddress(hmod
, "ConfigDriverW");
457 funcret
= pConfigDriverW(hwnd
, request
, driver
, args
, msg
, msgmax
, msgout
);
460 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
467 BOOL WINAPI
SQLConfigDriver(HWND hwnd
, WORD request
, LPCSTR driver
,
468 LPCSTR args
, LPSTR msg
, WORD msgmax
, WORD
*msgout
)
470 BOOL (WINAPI
*pConfigDriverA
)(HWND hwnd
, WORD request
, const char *driver
, const char *args
, const char *msg
, WORD msgmax
, WORD
*msgout
);
473 BOOL funcret
= FALSE
;
476 TRACE("(%p %d %s %s %p %d %p)\n", hwnd
, request
, debugstr_a(driver
),
477 debugstr_a(args
), msg
, msgmax
, msgout
);
479 driverW
= heap_strdupAtoW(driver
);
482 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
485 if(request
== ODBC_CONFIG_DRIVER
)
488 WCHAR
*argsW
= heap_strdupAtoW(args
);
491 ret
= write_config_value(driverW
, argsW
);
492 HeapFree(GetProcessHeap(), 0, argsW
);
496 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
499 HeapFree(GetProcessHeap(), 0, driverW
);
504 hmod
= load_config_driver(driverW
);
505 HeapFree(GetProcessHeap(), 0, driverW
);
509 pConfigDriverA
= (void*)GetProcAddress(hmod
, "ConfigDriver");
511 funcret
= pConfigDriverA(hwnd
, request
, driver
, args
, msg
, msgmax
, msgout
);
514 push_error(ODBC_ERROR_REQUEST_FAILED
, odbc_error_request_failed
);
521 BOOL WINAPI
SQLCreateDataSourceW(HWND hwnd
, LPCWSTR lpszDS
)
524 FIXME("%p %s\n", hwnd
, debugstr_w(lpszDS
));
525 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
529 BOOL WINAPI
SQLCreateDataSource(HWND hwnd
, LPCSTR lpszDS
)
532 FIXME("%p %s\n", hwnd
, debugstr_a(lpszDS
));
533 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
537 BOOL WINAPI
SQLGetAvailableDriversW(LPCWSTR lpszInfFile
, LPWSTR lpszBuf
,
538 WORD cbBufMax
, WORD
*pcbBufOut
)
541 FIXME("%s %p %d %p\n", debugstr_w(lpszInfFile
), lpszBuf
, cbBufMax
, pcbBufOut
);
542 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
546 BOOL WINAPI
SQLGetAvailableDrivers(LPCSTR lpszInfFile
, LPSTR lpszBuf
,
547 WORD cbBufMax
, WORD
*pcbBufOut
)
550 FIXME("%s %p %d %p\n", debugstr_a(lpszInfFile
), lpszBuf
, cbBufMax
, pcbBufOut
);
551 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
555 BOOL WINAPI
SQLGetConfigMode(UWORD
*pwConfigMode
)
558 TRACE("%p\n", pwConfigMode
);
560 *pwConfigMode
= config_mode
;
564 BOOL WINAPI
SQLGetInstalledDriversW(WCHAR
*buf
, WORD size
, WORD
*sizeout
)
577 TRACE("%p %d %p\n", buf
, size
, sizeout
);
581 push_error(ODBC_ERROR_INVALID_BUFF_LEN
, odbc_error_invalid_buff_len
);
585 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, drivers_key
, 0, KEY_QUERY_VALUE
, &drivers
);
588 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
593 value
= heap_alloc(valuelen
* sizeof(WCHAR
));
600 res
= RegEnumValueW(drivers
, index
, value
, &len
, NULL
, NULL
, NULL
, NULL
);
601 while (res
== ERROR_MORE_DATA
)
603 value
= heap_realloc(value
, ++len
* sizeof(WCHAR
));
604 res
= RegEnumValueW(drivers
, index
, value
, &len
, NULL
, NULL
, NULL
, NULL
);
606 if (res
== ERROR_SUCCESS
)
608 lstrcpynW(buf
+ written
, value
, size
- written
);
609 written
+= min(len
+ 1, size
- written
);
611 else if (res
== ERROR_NO_MORE_ITEMS
)
615 push_error(ODBC_ERROR_GENERAL_ERR
, odbc_error_general_err
);
625 RegCloseKey(drivers
);
631 BOOL WINAPI
SQLGetInstalledDrivers(char *buf
, WORD size
, WORD
*sizeout
)
637 TRACE("%p %d %p\n", buf
, size
, sizeout
);
641 push_error(ODBC_ERROR_INVALID_BUFF_LEN
, odbc_error_invalid_buff_len
);
645 wbuf
= heap_alloc(size
* sizeof(WCHAR
));
648 push_error(ODBC_ERROR_OUT_OF_MEM
, odbc_error_out_of_mem
);
652 ret
= SQLGetInstalledDriversW(wbuf
, size
, &written
);
660 *sizeout
= WideCharToMultiByte(CP_ACP
, 0, wbuf
, written
, NULL
, 0, NULL
, NULL
);
661 WideCharToMultiByte(CP_ACP
, 0, wbuf
, written
, buf
, size
, NULL
, NULL
);
667 static HKEY
get_privateprofile_sectionkey(LPCWSTR section
, LPCWSTR filename
)
669 HKEY hkey
, hkeyfilename
, hkeysection
;
672 if (RegOpenKeyW(HKEY_CURRENT_USER
, odbcW
, &hkey
))
675 ret
= RegOpenKeyW(hkey
, filename
, &hkeyfilename
);
680 ret
= RegOpenKeyW(hkeyfilename
, section
, &hkeysection
);
681 RegCloseKey(hkeyfilename
);
683 return ret
? NULL
: hkeysection
;
686 int WINAPI
SQLGetPrivateProfileStringW(LPCWSTR section
, LPCWSTR entry
,
687 LPCWSTR defvalue
, LPWSTR buff
, int buff_len
, LPCWSTR filename
)
689 BOOL usedefault
= TRUE
;
693 TRACE("%s %s %s %p %d %s\n", debugstr_w(section
), debugstr_w(entry
),
694 debugstr_w(defvalue
), buff
, buff_len
, debugstr_w(filename
));
698 if (buff_len
<= 0 || !section
)
704 if (!defvalue
|| !buff
)
707 sectionkey
= get_privateprofile_sectionkey(section
, filename
);
714 size
= buff_len
* sizeof(*buff
);
715 if (RegGetValueW(sectionkey
, NULL
, entry
, RRF_RT_REG_SZ
, &type
, buff
, &size
) == ERROR_SUCCESS
)
718 ret
= (size
/ sizeof(*buff
)) - 1;
723 WCHAR name
[MAX_PATH
];
729 memset(buff
, 0, buff_len
);
731 namelen
= sizeof(name
);
732 while (RegEnumValueW(sectionkey
, index
, name
, &namelen
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
734 if ((ret
+ namelen
+1) > buff_len
)
737 lstrcpyW(buff
+ret
, name
);
739 namelen
= sizeof(name
);
744 RegCloseKey(sectionkey
);
747 usedefault
= entry
!= NULL
;
751 lstrcpynW(buff
, defvalue
, buff_len
);
752 ret
= lstrlenW(buff
);
758 int WINAPI
SQLGetPrivateProfileString(LPCSTR section
, LPCSTR entry
,
759 LPCSTR defvalue
, LPSTR buff
, int buff_len
, LPCSTR filename
)
761 WCHAR
*sectionW
, *filenameW
;
762 BOOL usedefault
= TRUE
;
766 TRACE("%s %s %s %p %d %s\n", debugstr_a(section
), debugstr_a(entry
),
767 debugstr_a(defvalue
), buff
, buff_len
, debugstr_a(filename
));
777 if (!section
|| !defvalue
|| !buff
)
780 sectionW
= heap_strdupAtoW(section
);
781 filenameW
= heap_strdupAtoW(filename
);
783 sectionkey
= get_privateprofile_sectionkey(sectionW
, filenameW
);
786 heap_free(filenameW
);
794 size
= buff_len
* sizeof(*buff
);
795 if (RegGetValueA(sectionkey
, NULL
, entry
, RRF_RT_REG_SZ
, &type
, buff
, &size
) == ERROR_SUCCESS
)
798 ret
= (size
/ sizeof(*buff
)) - 1;
803 char name
[MAX_PATH
] = {0};
809 memset(buff
, 0, buff_len
);
811 namelen
= sizeof(name
);
812 while (RegEnumValueA(sectionkey
, index
, name
, &namelen
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
814 if ((ret
+ namelen
+1) > buff_len
)
817 lstrcpyA(buff
+ret
, name
);
820 namelen
= sizeof(name
);
825 RegCloseKey(sectionkey
);
828 usedefault
= entry
!= NULL
;
832 lstrcpynA(buff
, defvalue
, buff_len
);
839 BOOL WINAPI
SQLGetTranslatorW(HWND hwndParent
, LPWSTR lpszName
, WORD cbNameMax
,
840 WORD
*pcbNameOut
, LPWSTR lpszPath
, WORD cbPathMax
,
841 WORD
*pcbPathOut
, DWORD
*pvOption
)
844 FIXME("%p %s %d %p %p %d %p %p\n", hwndParent
, debugstr_w(lpszName
), cbNameMax
,
845 pcbNameOut
, lpszPath
, cbPathMax
, pcbPathOut
, pvOption
);
846 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
850 BOOL WINAPI
SQLGetTranslator(HWND hwndParent
, LPSTR lpszName
, WORD cbNameMax
,
851 WORD
*pcbNameOut
, LPSTR lpszPath
, WORD cbPathMax
,
852 WORD
*pcbPathOut
, DWORD
*pvOption
)
855 FIXME("%p %s %d %p %p %d %p %p\n", hwndParent
, debugstr_a(lpszName
), cbNameMax
,
856 pcbNameOut
, lpszPath
, cbPathMax
, pcbPathOut
, pvOption
);
857 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
861 BOOL WINAPI
SQLInstallDriverW(LPCWSTR lpszInfFile
, LPCWSTR lpszDriver
,
862 LPWSTR lpszPath
, WORD cbPathMax
, WORD
* pcbPathOut
)
867 TRACE("%s %s %p %d %p\n", debugstr_w(lpszInfFile
),
868 debugstr_w(lpszDriver
), lpszPath
, cbPathMax
, pcbPathOut
);
873 return SQLInstallDriverExW(lpszDriver
, NULL
, lpszPath
, cbPathMax
,
874 pcbPathOut
, ODBC_INSTALL_COMPLETE
, &usage
);
877 BOOL WINAPI
SQLInstallDriver(LPCSTR lpszInfFile
, LPCSTR lpszDriver
,
878 LPSTR lpszPath
, WORD cbPathMax
, WORD
* pcbPathOut
)
883 TRACE("%s %s %p %d %p\n", debugstr_a(lpszInfFile
),
884 debugstr_a(lpszDriver
), lpszPath
, cbPathMax
, pcbPathOut
);
889 return SQLInstallDriverEx(lpszDriver
, NULL
, lpszPath
, cbPathMax
,
890 pcbPathOut
, ODBC_INSTALL_COMPLETE
, &usage
);
893 static void write_registry_values(const WCHAR
*regkey
, const WCHAR
*driver
, const WCHAR
*path_in
, WCHAR
*path
,
896 static const WCHAR installed
[] = {'I','n','s','t','a','l','l','e','d',0};
897 static const WCHAR slash
[] = {'\\', 0};
898 static const WCHAR driverW
[] = {'D','r','i','v','e','r',0};
899 static const WCHAR setupW
[] = {'S','e','t','u','p',0};
900 static const WCHAR translator
[] = {'T','r','a','n','s','l','a','t','o','r',0};
901 HKEY hkey
, hkeydriver
;
903 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
) == ERROR_SUCCESS
)
905 if (RegCreateKeyW(hkey
, regkey
, &hkeydriver
) == ERROR_SUCCESS
)
907 if(RegSetValueExW(hkeydriver
, driver
, 0, REG_SZ
, (BYTE
*)installed
, sizeof(installed
)) != ERROR_SUCCESS
)
908 ERR("Failed to write registry installed key\n");
910 RegCloseKey(hkeydriver
);
913 if (RegCreateKeyW(hkey
, driver
, &hkeydriver
) == ERROR_SUCCESS
)
917 DWORD usagecount
= 0;
920 /* Skip name entry */
922 p
+= lstrlenW(p
) + 1;
925 GetSystemDirectoryW(path
, MAX_PATH
);
927 lstrcpyW(path
, path_in
);
930 size
= sizeof(usagecount
);
931 RegGetValueA(hkeydriver
, NULL
, "UsageCount", RRF_RT_DWORD
, &type
, &usagecount
, &size
);
932 TRACE("Usage count %d\n", usagecount
);
934 for (; *p
; p
+= lstrlenW(p
) + 1)
936 WCHAR
*divider
= wcschr(p
,'=');
943 /* Write pair values to the registry. */
944 lstrcpynW(entry
, p
, divider
- p
+ 1);
947 TRACE("Writing pair %s,%s\n", debugstr_w(entry
), debugstr_w(divider
));
949 /* Driver, Setup, Translator entries use the system path unless a path is specified. */
950 if(lstrcmpiW(driverW
, entry
) == 0 || lstrcmpiW(setupW
, entry
) == 0 ||
951 lstrcmpiW(translator
, entry
) == 0)
953 len
= lstrlenW(path
) + lstrlenW(slash
) + lstrlenW(divider
) + 1;
954 value
= heap_alloc(len
* sizeof(WCHAR
));
957 ERR("Out of memory\n");
961 lstrcpyW(value
, path
);
962 lstrcatW(value
, slash
);
963 lstrcatW(value
, divider
);
967 len
= lstrlenW(divider
) + 1;
968 value
= heap_alloc(len
* sizeof(WCHAR
));
969 lstrcpyW(value
, divider
);
972 if (RegSetValueExW(hkeydriver
, entry
, 0, REG_SZ
, (BYTE
*)value
,
973 (lstrlenW(value
)+1)*sizeof(WCHAR
)) != ERROR_SUCCESS
)
974 ERR("Failed to write registry data %s %s\n", debugstr_w(entry
), debugstr_w(value
));
979 ERR("No pair found. %s\n", debugstr_w(p
));
984 /* Set Usage Count */
986 if (RegSetValueExA(hkeydriver
, "UsageCount", 0, REG_DWORD
, (BYTE
*)&usagecount
, sizeof(usagecount
)) != ERROR_SUCCESS
)
987 ERR("Failed to write registry UsageCount key\n");
990 *usage_count
= usagecount
;
992 RegCloseKey(hkeydriver
);
999 BOOL WINAPI
SQLInstallDriverExW(LPCWSTR lpszDriver
, LPCWSTR lpszPathIn
,
1000 LPWSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1001 WORD fRequest
, LPDWORD lpdwUsageCount
)
1004 WCHAR path
[MAX_PATH
];
1007 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszDriver
),
1008 debugstr_w(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1009 fRequest
, lpdwUsageCount
);
1011 write_registry_values(odbcdrivers
, lpszDriver
, lpszPathIn
, path
, lpdwUsageCount
);
1013 len
= lstrlenW(path
);
1018 if (lpszPathOut
&& cbPathOutMax
> len
)
1020 lstrcpyW(lpszPathOut
, path
);
1026 BOOL WINAPI
SQLInstallDriverEx(LPCSTR lpszDriver
, LPCSTR lpszPathIn
,
1027 LPSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1028 WORD fRequest
, LPDWORD lpdwUsageCount
)
1030 LPWSTR driver
, pathin
;
1031 WCHAR pathout
[MAX_PATH
];
1036 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszDriver
),
1037 debugstr_a(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1038 fRequest
, lpdwUsageCount
);
1040 driver
= SQLInstall_strdup_multi(lpszDriver
);
1041 pathin
= SQLInstall_strdup(lpszPathIn
);
1043 ret
= SQLInstallDriverExW(driver
, pathin
, pathout
, MAX_PATH
, &cbOut
,
1044 fRequest
, lpdwUsageCount
);
1047 int len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1052 *pcbPathOut
= len
- 1;
1054 if (!lpszPathOut
|| cbPathOutMax
< len
)
1059 len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1060 cbPathOutMax
, NULL
, NULL
);
1065 HeapFree(GetProcessHeap(), 0, driver
);
1066 HeapFree(GetProcessHeap(), 0, pathin
);
1070 BOOL WINAPI
SQLInstallDriverManagerW(LPWSTR lpszPath
, WORD cbPathMax
,
1074 WCHAR path
[MAX_PATH
];
1076 TRACE("(%p %d %p)\n", lpszPath
, cbPathMax
, pcbPathOut
);
1078 if (cbPathMax
< MAX_PATH
)
1083 len
= GetSystemDirectoryW(path
, MAX_PATH
);
1088 if (lpszPath
&& cbPathMax
> len
)
1090 lstrcpyW(lpszPath
, path
);
1096 BOOL WINAPI
SQLInstallDriverManager(LPSTR lpszPath
, WORD cbPathMax
,
1100 WORD len
, cbOut
= 0;
1101 WCHAR path
[MAX_PATH
];
1103 TRACE("(%p %d %p)\n", lpszPath
, cbPathMax
, pcbPathOut
);
1105 if (cbPathMax
< MAX_PATH
)
1110 ret
= SQLInstallDriverManagerW(path
, MAX_PATH
, &cbOut
);
1113 len
= WideCharToMultiByte(CP_ACP
, 0, path
, -1, lpszPath
, 0,
1118 *pcbPathOut
= len
- 1;
1120 if (!lpszPath
|| cbPathMax
< len
)
1123 len
= WideCharToMultiByte(CP_ACP
, 0, path
, -1, lpszPath
,
1124 cbPathMax
, NULL
, NULL
);
1130 BOOL WINAPI
SQLInstallODBCW(HWND hwndParent
, LPCWSTR lpszInfFile
,
1131 LPCWSTR lpszSrcPath
, LPCWSTR lpszDrivers
)
1134 FIXME("%p %s %s %s\n", hwndParent
, debugstr_w(lpszInfFile
),
1135 debugstr_w(lpszSrcPath
), debugstr_w(lpszDrivers
));
1136 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1140 BOOL WINAPI
SQLInstallODBC(HWND hwndParent
, LPCSTR lpszInfFile
,
1141 LPCSTR lpszSrcPath
, LPCSTR lpszDrivers
)
1144 FIXME("%p %s %s %s\n", hwndParent
, debugstr_a(lpszInfFile
),
1145 debugstr_a(lpszSrcPath
), debugstr_a(lpszDrivers
));
1146 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1150 SQLRETURN WINAPI
SQLInstallerErrorW(WORD iError
, DWORD
*pfErrorCode
,
1151 LPWSTR lpszErrorMsg
, WORD cbErrorMsgMax
, WORD
*pcbErrorMsg
)
1153 TRACE("%d %p %p %d %p\n", iError
, pfErrorCode
, lpszErrorMsg
,
1154 cbErrorMsgMax
, pcbErrorMsg
);
1160 else if (iError
<= num_errors
)
1162 BOOL truncated
= FALSE
;
1167 *pfErrorCode
= error_code
[iError
];
1168 msg
= error_msg
[iError
];
1169 len
= msg
? lstrlenW(msg
) : 0;
1173 if (cbErrorMsgMax
< len
)
1175 len
= cbErrorMsgMax
;
1178 if (lpszErrorMsg
&& len
)
1182 memcpy (lpszErrorMsg
, msg
, len
* sizeof(WCHAR
));
1192 /* Yes. If you pass a null pointer and a large length it is not an error! */
1196 return truncated
? SQL_SUCCESS_WITH_INFO
: SQL_SUCCESS
;
1199 /* 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 */
1203 if (lpszErrorMsg
&& cbErrorMsgMax
> 0)
1204 *lpszErrorMsg
= '\0';
1209 SQLRETURN WINAPI
SQLInstallerError(WORD iError
, DWORD
*pfErrorCode
,
1210 LPSTR lpszErrorMsg
, WORD cbErrorMsgMax
, WORD
*pcbErrorMsg
)
1215 TRACE("%d %p %p %d %p\n", iError
, pfErrorCode
, lpszErrorMsg
,
1216 cbErrorMsgMax
, pcbErrorMsg
);
1219 if (lpszErrorMsg
&& cbErrorMsgMax
)
1221 wbuf
= HeapAlloc(GetProcessHeap(), 0, cbErrorMsgMax
*sizeof(WCHAR
));
1225 ret
= SQLInstallerErrorW(iError
, pfErrorCode
, wbuf
, cbErrorMsgMax
, &cbwbuf
);
1229 SQLInstall_narrow(1, lpszErrorMsg
, wbuf
, cbwbuf
+1, cbErrorMsgMax
, &cbBuf
);
1230 HeapFree(GetProcessHeap(), 0, wbuf
);
1232 *pcbErrorMsg
= cbBuf
-1;
1237 BOOL WINAPI
SQLInstallTranslatorExW(LPCWSTR lpszTranslator
, LPCWSTR lpszPathIn
,
1238 LPWSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1239 WORD fRequest
, LPDWORD lpdwUsageCount
)
1242 WCHAR path
[MAX_PATH
];
1245 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszTranslator
),
1246 debugstr_w(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1247 fRequest
, lpdwUsageCount
);
1249 write_registry_values(odbctranslators
, lpszTranslator
, lpszPathIn
, path
, lpdwUsageCount
);
1251 len
= lstrlenW(path
);
1256 if (lpszPathOut
&& cbPathOutMax
> len
)
1258 lstrcpyW(lpszPathOut
, path
);
1264 BOOL WINAPI
SQLInstallTranslatorEx(LPCSTR lpszTranslator
, LPCSTR lpszPathIn
,
1265 LPSTR lpszPathOut
, WORD cbPathOutMax
, WORD
*pcbPathOut
,
1266 WORD fRequest
, LPDWORD lpdwUsageCount
)
1269 LPWSTR translator
, pathin
;
1270 WCHAR pathout
[MAX_PATH
];
1275 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszTranslator
),
1276 debugstr_a(lpszPathIn
), lpszPathOut
, cbPathOutMax
, pcbPathOut
,
1277 fRequest
, lpdwUsageCount
);
1279 for (p
= lpszTranslator
; *p
; p
+= lstrlenA(p
) + 1)
1280 TRACE("%s\n", debugstr_a(p
));
1282 translator
= SQLInstall_strdup_multi(lpszTranslator
);
1283 pathin
= SQLInstall_strdup(lpszPathIn
);
1285 ret
= SQLInstallTranslatorExW(translator
, pathin
, pathout
, MAX_PATH
,
1286 &cbOut
, fRequest
, lpdwUsageCount
);
1289 int len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1294 *pcbPathOut
= len
- 1;
1296 if (!lpszPathOut
|| cbPathOutMax
< len
)
1301 len
= WideCharToMultiByte(CP_ACP
, 0, pathout
, -1, lpszPathOut
,
1302 cbPathOutMax
, NULL
, NULL
);
1307 HeapFree(GetProcessHeap(), 0, translator
);
1308 HeapFree(GetProcessHeap(), 0, pathin
);
1312 BOOL WINAPI
SQLInstallTranslator(LPCSTR lpszInfFile
, LPCSTR lpszTranslator
,
1313 LPCSTR lpszPathIn
, LPSTR lpszPathOut
, WORD cbPathOutMax
,
1314 WORD
*pcbPathOut
, WORD fRequest
, LPDWORD lpdwUsageCount
)
1317 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_a(lpszInfFile
),
1318 debugstr_a(lpszTranslator
), debugstr_a(lpszPathIn
), lpszPathOut
,
1319 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1324 return SQLInstallTranslatorEx(lpszTranslator
, lpszPathIn
, lpszPathOut
,
1325 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1328 BOOL WINAPI
SQLInstallTranslatorW(LPCWSTR lpszInfFile
, LPCWSTR lpszTranslator
,
1329 LPCWSTR lpszPathIn
, LPWSTR lpszPathOut
, WORD cbPathOutMax
,
1330 WORD
*pcbPathOut
, WORD fRequest
, LPDWORD lpdwUsageCount
)
1333 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_w(lpszInfFile
),
1334 debugstr_w(lpszTranslator
), debugstr_w(lpszPathIn
), lpszPathOut
,
1335 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1340 return SQLInstallTranslatorExW(lpszTranslator
, lpszPathIn
, lpszPathOut
,
1341 cbPathOutMax
, pcbPathOut
, fRequest
, lpdwUsageCount
);
1344 BOOL WINAPI
SQLManageDataSources(HWND hwnd
)
1347 FIXME("%p\n", hwnd
);
1348 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1352 SQLRETURN WINAPI
SQLPostInstallerErrorW(DWORD fErrorCode
, LPCWSTR szErrorMsg
)
1354 FIXME("%u %s\n", fErrorCode
, debugstr_w(szErrorMsg
));
1355 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1359 SQLRETURN WINAPI
SQLPostInstallerError(DWORD fErrorCode
, LPCSTR szErrorMsg
)
1361 FIXME("%u %s\n", fErrorCode
, debugstr_a(szErrorMsg
));
1362 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1366 BOOL WINAPI
SQLReadFileDSNW(LPCWSTR lpszFileName
, LPCWSTR lpszAppName
,
1367 LPCWSTR lpszKeyName
, LPWSTR lpszString
, WORD cbString
,
1371 FIXME("%s %s %s %s %d %p\n", debugstr_w(lpszFileName
), debugstr_w(lpszAppName
),
1372 debugstr_w(lpszKeyName
), debugstr_w(lpszString
), cbString
, pcbString
);
1373 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1377 BOOL WINAPI
SQLReadFileDSN(LPCSTR lpszFileName
, LPCSTR lpszAppName
,
1378 LPCSTR lpszKeyName
, LPSTR lpszString
, WORD cbString
,
1382 FIXME("%s %s %s %s %d %p\n", debugstr_a(lpszFileName
), debugstr_a(lpszAppName
),
1383 debugstr_a(lpszKeyName
), debugstr_a(lpszString
), cbString
, pcbString
);
1384 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1388 BOOL WINAPI
SQLRemoveDefaultDataSource(void)
1392 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1396 BOOL WINAPI
SQLRemoveDriverW(LPCWSTR drivername
, BOOL remove_dsn
, LPDWORD usage_count
)
1399 DWORD usagecount
= 1;
1402 TRACE("%s %d %p\n", debugstr_w(drivername
), remove_dsn
, usage_count
);
1404 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
) == ERROR_SUCCESS
)
1408 if (RegOpenKeyW(hkey
, drivername
, &hkeydriver
) == ERROR_SUCCESS
)
1413 size
= sizeof(usagecount
);
1414 RegGetValueA(hkeydriver
, NULL
, "UsageCount", RRF_RT_DWORD
, &type
, &usagecount
, &size
);
1415 TRACE("Usage count %d\n", usagecount
);
1416 count
= usagecount
- 1;
1419 if (RegSetValueExA(hkeydriver
, "UsageCount", 0, REG_DWORD
, (BYTE
*)&count
, sizeof(count
)) != ERROR_SUCCESS
)
1420 ERR("Failed to write registry UsageCount key\n");
1423 RegCloseKey(hkeydriver
);
1431 if (RegDeleteKeyW(hkey
, drivername
) != ERROR_SUCCESS
)
1432 ERR("Failed to delete registry key: %s\n", debugstr_w(drivername
));
1434 if (RegOpenKeyW(hkey
, odbcdrivers
, &hkeydriver
) == ERROR_SUCCESS
)
1436 if(RegDeleteValueW(hkeydriver
, drivername
) != ERROR_SUCCESS
)
1437 ERR("Failed to delete registry value: %s\n", debugstr_w(drivername
));
1438 RegCloseKey(hkeydriver
);
1446 *usage_count
= usagecount
;
1451 BOOL WINAPI
SQLRemoveDriver(LPCSTR lpszDriver
, BOOL fRemoveDSN
,
1452 LPDWORD lpdwUsageCount
)
1458 TRACE("%s %d %p\n", debugstr_a(lpszDriver
), fRemoveDSN
, lpdwUsageCount
);
1460 driver
= SQLInstall_strdup(lpszDriver
);
1462 ret
= SQLRemoveDriverW(driver
, fRemoveDSN
, lpdwUsageCount
);
1464 HeapFree(GetProcessHeap(), 0, driver
);
1468 BOOL WINAPI
SQLRemoveDriverManager(LPDWORD pdwUsageCount
)
1471 FIXME("%p\n", pdwUsageCount
);
1472 if (pdwUsageCount
) *pdwUsageCount
= 1;
1476 BOOL WINAPI
SQLRemoveDSNFromIniW(LPCWSTR lpszDSN
)
1479 FIXME("%s\n", debugstr_w(lpszDSN
));
1480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1484 BOOL WINAPI
SQLRemoveDSNFromIni(LPCSTR lpszDSN
)
1487 FIXME("%s\n", debugstr_a(lpszDSN
));
1488 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1492 BOOL WINAPI
SQLRemoveTranslatorW(const WCHAR
*translator
, DWORD
*usage_count
)
1495 DWORD usagecount
= 1;
1499 TRACE("%s %p\n", debugstr_w(translator
), usage_count
);
1501 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, odbcini
, &hkey
) == ERROR_SUCCESS
)
1505 if (RegOpenKeyW(hkey
, translator
, &hkeydriver
) == ERROR_SUCCESS
)
1510 size
= sizeof(usagecount
);
1511 RegGetValueA(hkeydriver
, NULL
, "UsageCount", RRF_RT_DWORD
, &type
, &usagecount
, &size
);
1512 TRACE("Usage count %d\n", usagecount
);
1513 count
= usagecount
- 1;
1516 if (RegSetValueExA(hkeydriver
, "UsageCount", 0, REG_DWORD
, (BYTE
*)&count
, sizeof(count
)) != ERROR_SUCCESS
)
1517 ERR("Failed to write registry UsageCount key\n");
1520 RegCloseKey(hkeydriver
);
1528 if(RegDeleteKeyW(hkey
, translator
) != ERROR_SUCCESS
)
1530 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
1531 WARN("Failed to delete registry key: %s\n", debugstr_w(translator
));
1535 if (ret
&& RegOpenKeyW(hkey
, odbctranslators
, &hkeydriver
) == ERROR_SUCCESS
)
1537 if(RegDeleteValueW(hkeydriver
, translator
) != ERROR_SUCCESS
)
1539 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND
, odbc_error_component_not_found
);
1540 WARN("Failed to delete registry key: %s\n", debugstr_w(translator
));
1544 RegCloseKey(hkeydriver
);
1551 if (ret
&& usage_count
)
1552 *usage_count
= usagecount
;
1557 BOOL WINAPI
SQLRemoveTranslator(LPCSTR lpszTranslator
, LPDWORD lpdwUsageCount
)
1563 TRACE("%s %p\n", debugstr_a(lpszTranslator
), lpdwUsageCount
);
1565 translator
= SQLInstall_strdup(lpszTranslator
);
1566 ret
= SQLRemoveTranslatorW(translator
, lpdwUsageCount
);
1568 HeapFree(GetProcessHeap(), 0, translator
);
1572 BOOL WINAPI
SQLSetConfigMode(UWORD wConfigMode
)
1575 TRACE("%u\n", wConfigMode
);
1577 if (wConfigMode
> ODBC_SYSTEM_DSN
)
1579 push_error(ODBC_ERROR_INVALID_PARAM_SEQUENCE
, odbc_error_invalid_param_sequence
);
1584 config_mode
= wConfigMode
;
1589 BOOL WINAPI
SQLValidDSNW(LPCWSTR lpszDSN
)
1591 static const WCHAR invalid
[] = {'[',']','{','}','(',')',',',';','?','*','=','!','@','\\',0};
1593 TRACE("%s\n", debugstr_w(lpszDSN
));
1595 if(lstrlenW(lpszDSN
) > SQL_MAX_DSN_LENGTH
|| wcspbrk(lpszDSN
, invalid
) != NULL
)
1603 BOOL WINAPI
SQLValidDSN(LPCSTR lpszDSN
)
1605 static const char *invalid
= "[]{}(),;?*=!@\\";
1607 TRACE("%s\n", debugstr_a(lpszDSN
));
1609 if(strlen(lpszDSN
) > SQL_MAX_DSN_LENGTH
|| strpbrk(lpszDSN
, invalid
) != NULL
)
1617 BOOL WINAPI
SQLWriteDSNToIniW(LPCWSTR lpszDSN
, LPCWSTR lpszDriver
)
1620 FIXME("%s %s\n", debugstr_w(lpszDSN
), debugstr_w(lpszDriver
));
1624 BOOL WINAPI
SQLWriteDSNToIni(LPCSTR lpszDSN
, LPCSTR lpszDriver
)
1627 FIXME("%s %s\n", debugstr_a(lpszDSN
), debugstr_a(lpszDriver
));
1631 BOOL WINAPI
SQLWriteFileDSNW(LPCWSTR lpszFileName
, LPCWSTR lpszAppName
,
1632 LPCWSTR lpszKeyName
, LPCWSTR lpszString
)
1635 FIXME("%s %s %s %s\n", debugstr_w(lpszFileName
), debugstr_w(lpszAppName
),
1636 debugstr_w(lpszKeyName
), debugstr_w(lpszString
));
1637 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1641 BOOL WINAPI
SQLWriteFileDSN(LPCSTR lpszFileName
, LPCSTR lpszAppName
,
1642 LPCSTR lpszKeyName
, LPCSTR lpszString
)
1645 FIXME("%s %s %s %s\n", debugstr_a(lpszFileName
), debugstr_a(lpszAppName
),
1646 debugstr_a(lpszKeyName
), debugstr_a(lpszString
));
1647 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1651 BOOL WINAPI
SQLWritePrivateProfileStringW(LPCWSTR lpszSection
, LPCWSTR lpszEntry
,
1652 LPCWSTR lpszString
, LPCWSTR lpszFilename
)
1654 static const WCHAR empty
[] = {0};
1659 TRACE("%s %s %s %s\n", debugstr_w(lpszSection
), debugstr_w(lpszEntry
),
1660 debugstr_w(lpszString
), debugstr_w(lpszFilename
));
1662 if(!lpszFilename
|| !*lpszFilename
)
1664 push_error(ODBC_ERROR_INVALID_STR
, odbc_error_invalid_param_string
);
1668 if ((ret
= RegCreateKeyW(HKEY_CURRENT_USER
, odbcW
, &hkey
)) == ERROR_SUCCESS
)
1672 if ((ret
= RegCreateKeyW(hkey
, lpszFilename
, &hkeyfilename
)) == ERROR_SUCCESS
)
1676 if ((ret
= RegCreateKeyW(hkeyfilename
, lpszSection
, &hkey_section
)) == ERROR_SUCCESS
)
1679 ret
= RegSetValueExW(hkey_section
, lpszEntry
, 0, REG_SZ
, (BYTE
*)lpszString
, (lstrlenW(lpszString
)+1)*sizeof(WCHAR
));
1681 ret
= RegSetValueExW(hkey_section
, lpszEntry
, 0, REG_SZ
, (BYTE
*)empty
, sizeof(empty
));
1682 RegCloseKey(hkey_section
);
1685 RegCloseKey(hkeyfilename
);
1691 return ret
== ERROR_SUCCESS
;
1694 BOOL WINAPI
SQLWritePrivateProfileString(LPCSTR lpszSection
, LPCSTR lpszEntry
,
1695 LPCSTR lpszString
, LPCSTR lpszFilename
)
1698 WCHAR
*sect
, *entry
, *string
, *file
;
1700 TRACE("%s %s %s %s\n", lpszSection
, lpszEntry
, lpszString
, lpszFilename
);
1702 sect
= heap_strdupAtoW(lpszSection
);
1703 entry
= heap_strdupAtoW(lpszEntry
);
1704 string
= heap_strdupAtoW(lpszString
);
1705 file
= heap_strdupAtoW(lpszFilename
);
1707 ret
= SQLWritePrivateProfileStringW(sect
, entry
, string
, file
);