* Sync up to trunk head (r65120).
[reactos.git] / dll / win32 / odbccp32 / odbccp32.c
1 /*
2 * Implementation of the ODBC driver installer
3 *
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2005 Hans Leidekker
6 * Copyright 2007 Bill Medland
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #define WIN32_NO_STATUS
24
25 #include <assert.h>
26 #include <stdarg.h>
27
28 #define COBJMACROS
29 #define NONAMELESSUNION
30
31 #include <windef.h>
32 #include <winbase.h>
33 #include <winreg.h>
34 #include <winnls.h>
35 #include <wine/debug.h>
36
37 #include <odbcinst.h>
38
39 WINE_DEFAULT_DEBUG_CHANNEL(odbc);
40
41 /* Registry key names */
42 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};
43
44 /* This config mode is known to be process-wide.
45 * MSDN documentation suggests that the value is hidden somewhere in the registry but I haven't found it yet.
46 * Although both the registry and the ODBC.ini files appear to be maintained together they are not maintained automatically through the registry's IniFileMapping.
47 */
48 static UWORD config_mode = ODBC_BOTH_DSN;
49
50 /* MSDN documentation suggests that the error subsystem handles errors 1 to 8
51 * only and experimentation (Windows 2000) shows that the errors are process-
52 * wide so go for the simple solution; static arrays.
53 */
54 static int num_errors;
55 static int error_code[8];
56 static const WCHAR *error_msg[8];
57 static const WCHAR odbc_error_general_err[] = {'G','e','n','e','r','a','l',' ','e','r','r','o','r',0};
58 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};
59 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};
60 static const WCHAR odbc_error_out_of_mem[] = {'O','u','t',' ','o','f',' ','m','e','m','o','r','y',0};
61 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};
62
63 /* Push an error onto the error stack, taking care of ranges etc. */
64 static void push_error(int code, LPCWSTR msg)
65 {
66 if (num_errors < sizeof error_code/sizeof error_code[0])
67 {
68 error_code[num_errors] = code;
69 error_msg[num_errors] = msg;
70 num_errors++;
71 }
72 }
73
74 /* Clear the error stack */
75 static void clear_errors(void)
76 {
77 num_errors = 0;
78 }
79
80 BOOL WINAPI ODBCCPlApplet( LONG i, LONG j, LONG * p1, LONG * p2)
81 {
82 clear_errors();
83 FIXME( "( %d %d %p %p) : stub!\n", i, j, p1, p2);
84 return FALSE;
85 }
86
87 static LPWSTR SQLInstall_strdup_multi(LPCSTR str)
88 {
89 LPCSTR p;
90 LPWSTR ret = NULL;
91 DWORD len;
92
93 if (!str)
94 return ret;
95
96 for (p = str; *p; p += lstrlenA(p) + 1)
97 ;
98
99 len = MultiByteToWideChar(CP_ACP, 0, str, p - str, NULL, 0 );
100 ret = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
101 MultiByteToWideChar(CP_ACP, 0, str, p - str, ret, len );
102 ret[len] = 0;
103
104 return ret;
105 }
106
107 static LPWSTR SQLInstall_strdup(LPCSTR str)
108 {
109 DWORD len;
110 LPWSTR ret = NULL;
111
112 if (!str)
113 return ret;
114
115 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0 );
116 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
117 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len );
118
119 return ret;
120 }
121
122 /* Convert the wide string or zero-length-terminated list of wide strings to a
123 * narrow string or zero-length-terminated list of narrow strings.
124 * Do not try to emulate windows undocumented excesses (e.g. adding a third \0
125 * to a list)
126 * Arguments
127 * mode Indicates the sort of string.
128 * 1 denotes that the buffers contain strings terminated by a single nul
129 * character
130 * 2 denotes that the buffers contain zero-length-terminated lists
131 * (frequently erroneously referred to as double-null-terminated)
132 * buffer The narrow-character buffer into which to place the result. This
133 * must be a non-null pointer to the first element of a buffer whose
134 * length is passed in buffer_length.
135 * str The wide-character buffer containing the string or list of strings to
136 * be converted. str_length defines how many wide characters in the
137 * buffer are to be converted, including all desired terminating nul
138 * characters.
139 * str_length Effective length of str
140 * buffer_length Length of buffer
141 * returned_length A pointer to a variable that will receive the number of
142 * narrow characters placed into the buffer. This pointer
143 * may be NULL.
144 */
145 static BOOL SQLInstall_narrow(int mode, LPSTR buffer, LPCWSTR str, WORD str_length, WORD buffer_length, WORD *returned_length)
146 {
147 LPSTR pbuf; /* allows us to allocate a temporary buffer only if needed */
148 int len; /* Length of the converted list */
149 BOOL success = FALSE;
150 assert(mode == 1 || mode == 2);
151 assert(buffer_length);
152 len = WideCharToMultiByte(CP_ACP, 0, str, str_length, 0, 0, NULL, NULL);
153 if (len > 0)
154 {
155 if (len > buffer_length)
156 {
157 pbuf = HeapAlloc(GetProcessHeap(), 0, len);
158 }
159 else
160 {
161 pbuf = buffer;
162 }
163 len = WideCharToMultiByte(CP_ACP, 0, str, str_length, pbuf, len, NULL, NULL);
164 if (len > 0)
165 {
166 if (pbuf != buffer)
167 {
168 if (buffer_length > (mode - 1))
169 {
170 memcpy (buffer, pbuf, buffer_length-mode);
171 *(buffer+buffer_length-mode) = '\0';
172 }
173 *(buffer+buffer_length-1) = '\0';
174 }
175 if (returned_length)
176 {
177 *returned_length = pbuf == buffer ? len : buffer_length;
178 }
179 success = TRUE;
180 }
181 else
182 {
183 ERR("transferring wide to narrow\n");
184 }
185 if (pbuf != buffer)
186 {
187 HeapFree(GetProcessHeap(), 0, pbuf);
188 }
189 }
190 else
191 {
192 ERR("measuring wide to narrow\n");
193 }
194 return success;
195 }
196
197 BOOL WINAPI SQLConfigDataSourceW(HWND hwndParent, WORD fRequest,
198 LPCWSTR lpszDriver, LPCWSTR lpszAttributes)
199 {
200 LPCWSTR p;
201
202 clear_errors();
203 FIXME("%p %d %s %s\n", hwndParent, fRequest, debugstr_w(lpszDriver),
204 debugstr_w(lpszAttributes));
205
206 for (p = lpszAttributes; *p; p += lstrlenW(p) + 1)
207 FIXME("%s\n", debugstr_w(p));
208
209 return TRUE;
210 }
211
212 BOOL WINAPI SQLConfigDataSource(HWND hwndParent, WORD fRequest,
213 LPCSTR lpszDriver, LPCSTR lpszAttributes)
214 {
215 FIXME("%p %d %s %s\n", hwndParent, fRequest, debugstr_a(lpszDriver),
216 debugstr_a(lpszAttributes));
217 clear_errors();
218 return TRUE;
219 }
220
221 BOOL WINAPI SQLConfigDriverW(HWND hwndParent, WORD fRequest, LPCWSTR lpszDriver,
222 LPCWSTR lpszArgs, LPWSTR lpszMsg, WORD cbMsgMax, WORD *pcbMsgOut)
223 {
224 clear_errors();
225 FIXME("(%p %d %s %s %p %d %p)\n", hwndParent, fRequest, debugstr_w(lpszDriver),
226 debugstr_w(lpszArgs), lpszMsg, cbMsgMax, pcbMsgOut);
227 return TRUE;
228 }
229
230 BOOL WINAPI SQLConfigDriver(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver,
231 LPCSTR lpszArgs, LPSTR lpszMsg, WORD cbMsgMax, WORD *pcbMsgOut)
232 {
233 clear_errors();
234 FIXME("(%p %d %s %s %p %d %p)\n", hwndParent, fRequest, debugstr_a(lpszDriver),
235 debugstr_a(lpszArgs), lpszMsg, cbMsgMax, pcbMsgOut);
236 return TRUE;
237 }
238
239 BOOL WINAPI SQLCreateDataSourceW(HWND hwnd, LPCWSTR lpszDS)
240 {
241 clear_errors();
242 FIXME("\n");
243 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
244 return FALSE;
245 }
246
247 BOOL WINAPI SQLCreateDataSource(HWND hwnd, LPCSTR lpszDS)
248 {
249 clear_errors();
250 FIXME("\n");
251 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
252 return FALSE;
253 }
254
255 BOOL WINAPI SQLGetAvailableDriversW(LPCWSTR lpszInfFile, LPWSTR lpszBuf,
256 WORD cbBufMax, WORD *pcbBufOut)
257 {
258 clear_errors();
259 FIXME("\n");
260 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
261 return FALSE;
262 }
263
264 BOOL WINAPI SQLGetAvailableDrivers(LPCSTR lpszInfFile, LPSTR lpszBuf,
265 WORD cbBufMax, WORD *pcbBufOut)
266 {
267 clear_errors();
268 FIXME("\n");
269 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
270 return FALSE;
271 }
272
273 BOOL WINAPI SQLGetConfigMode(UWORD *pwConfigMode)
274 {
275 clear_errors();
276 if (pwConfigMode)
277 *pwConfigMode = config_mode;
278 return TRUE;
279 }
280
281 /* This is implemented sensibly rather than according to exact conformance to Microsoft's buggy implementations
282 * e.g. The Microsoft one occasionally actually adds a third nul character (possibly beyond the buffer).
283 * 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.
284 */
285 BOOL WINAPI SQLGetInstalledDriversW(LPWSTR lpszBuf, WORD cbBufMax,
286 WORD *pcbBufOut)
287 {
288 HKEY hDrivers; /* Registry handle to the Drivers key */
289 LONG reg_ret; /* Return code from registry functions */
290 BOOL success = FALSE; /* The value we will return */
291
292 clear_errors();
293 if (!lpszBuf || cbBufMax == 0)
294 {
295 push_error(ODBC_ERROR_INVALID_BUFF_LEN, odbc_error_invalid_buff_len);
296 }
297 else if ((reg_ret = RegOpenKeyExW (HKEY_LOCAL_MACHINE /* The drivers does not depend on the config mode */,
298 drivers_key, 0, KEY_READ /* Maybe overkill */,
299 &hDrivers)) == ERROR_SUCCESS)
300 {
301 DWORD index = 0;
302 cbBufMax--;
303 success = TRUE;
304 while (cbBufMax > 0)
305 {
306 DWORD size_name;
307 size_name = cbBufMax;
308 if ((reg_ret = RegEnumValueW(hDrivers, index, lpszBuf, &size_name, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS)
309 {
310 index++;
311 assert (size_name < cbBufMax && *(lpszBuf + size_name) == 0);
312 size_name++;
313 cbBufMax-= size_name;
314 lpszBuf+=size_name;
315 }
316 else
317 {
318 if (reg_ret != ERROR_NO_MORE_ITEMS)
319 {
320 success = FALSE;
321 push_error(ODBC_ERROR_GENERAL_ERR, odbc_error_general_err);
322 }
323 break;
324 }
325 }
326 *lpszBuf = 0;
327 if ((reg_ret = RegCloseKey (hDrivers)) != ERROR_SUCCESS)
328 TRACE ("Error %d closing ODBC Drivers key\n", reg_ret);
329 }
330 else
331 {
332 /* MSDN states that it returns failure with COMPONENT_NOT_FOUND in this case.
333 * Version 3.525.1117.0 (Windows 2000) does not; it actually returns success.
334 * I doubt if it will actually be an issue.
335 */
336 push_error(ODBC_ERROR_COMPONENT_NOT_FOUND, odbc_error_component_not_found);
337 }
338 return success;
339 }
340
341 BOOL WINAPI SQLGetInstalledDrivers(LPSTR lpszBuf, WORD cbBufMax,
342 WORD *pcbBufOut)
343 {
344 BOOL ret;
345 int size_wbuf = cbBufMax;
346 LPWSTR wbuf;
347 WORD size_used;
348 wbuf = HeapAlloc(GetProcessHeap(), 0, size_wbuf*sizeof(WCHAR));
349 if (wbuf)
350 {
351 ret = SQLGetInstalledDriversW(wbuf, size_wbuf, &size_used);
352 if (ret)
353 {
354 if (!(ret = SQLInstall_narrow(2, lpszBuf, wbuf, size_used, cbBufMax, pcbBufOut)))
355 {
356 push_error(ODBC_ERROR_GENERAL_ERR, odbc_error_general_err);
357 }
358 }
359 HeapFree(GetProcessHeap(), 0, wbuf);
360 /* ignore failure; we have achieved the aim */
361 }
362 else
363 {
364 push_error(ODBC_ERROR_OUT_OF_MEM, odbc_error_out_of_mem);
365 ret = FALSE;
366 }
367 return ret;
368 }
369
370 int WINAPI SQLGetPrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry,
371 LPCWSTR lpszDefault, LPCWSTR RetBuffer, int cbRetBuffer,
372 LPCWSTR lpszFilename)
373 {
374 clear_errors();
375 FIXME("\n");
376 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
377 return FALSE;
378 }
379
380 int WINAPI SQLGetPrivateProfileString(LPCSTR lpszSection, LPCSTR lpszEntry,
381 LPCSTR lpszDefault, LPCSTR RetBuffer, int cbRetBuffer,
382 LPCSTR lpszFilename)
383 {
384 clear_errors();
385 FIXME("\n");
386 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
387 return FALSE;
388 }
389
390 BOOL WINAPI SQLGetTranslatorW(HWND hwndParent, LPWSTR lpszName, WORD cbNameMax,
391 WORD *pcbNameOut, LPWSTR lpszPath, WORD cbPathMax,
392 WORD *pcbPathOut, DWORD *pvOption)
393 {
394 clear_errors();
395 FIXME("\n");
396 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
397 return FALSE;
398 }
399
400 BOOL WINAPI SQLGetTranslator(HWND hwndParent, LPSTR lpszName, WORD cbNameMax,
401 WORD *pcbNameOut, LPSTR lpszPath, WORD cbPathMax,
402 WORD *pcbPathOut, DWORD *pvOption)
403 {
404 clear_errors();
405 FIXME("\n");
406 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
407 return FALSE;
408 }
409
410 BOOL WINAPI SQLInstallDriverW(LPCWSTR lpszInfFile, LPCWSTR lpszDriver,
411 LPWSTR lpszPath, WORD cbPathMax, WORD * pcbPathOut)
412 {
413 DWORD usage;
414
415 clear_errors();
416 TRACE("%s %s %p %d %p\n", debugstr_w(lpszInfFile),
417 debugstr_w(lpszDriver), lpszPath, cbPathMax, pcbPathOut);
418
419 if (lpszInfFile)
420 return FALSE;
421
422 return SQLInstallDriverExW(lpszDriver, NULL, lpszPath, cbPathMax,
423 pcbPathOut, ODBC_INSTALL_COMPLETE, &usage);
424 }
425
426 BOOL WINAPI SQLInstallDriver(LPCSTR lpszInfFile, LPCSTR lpszDriver,
427 LPSTR lpszPath, WORD cbPathMax, WORD * pcbPathOut)
428 {
429 DWORD usage;
430
431 clear_errors();
432 TRACE("%s %s %p %d %p\n", debugstr_a(lpszInfFile),
433 debugstr_a(lpszDriver), lpszPath, cbPathMax, pcbPathOut);
434
435 if (lpszInfFile)
436 return FALSE;
437
438 return SQLInstallDriverEx(lpszDriver, NULL, lpszPath, cbPathMax,
439 pcbPathOut, ODBC_INSTALL_COMPLETE, &usage);
440 }
441
442 BOOL WINAPI SQLInstallDriverExW(LPCWSTR lpszDriver, LPCWSTR lpszPathIn,
443 LPWSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
444 WORD fRequest, LPDWORD lpdwUsageCount)
445 {
446 UINT len;
447 LPCWSTR p;
448 WCHAR path[MAX_PATH];
449
450 clear_errors();
451 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszDriver),
452 debugstr_w(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
453 fRequest, lpdwUsageCount);
454
455 for (p = lpszDriver; *p; p += lstrlenW(p) + 1)
456 TRACE("%s\n", debugstr_w(p));
457
458 len = GetSystemDirectoryW(path, MAX_PATH);
459
460 if (pcbPathOut)
461 *pcbPathOut = len;
462
463 len = GetSystemDirectoryW(path, MAX_PATH);
464
465 if (lpszPathOut && cbPathOutMax > len)
466 {
467 lstrcpyW(lpszPathOut, path);
468 return TRUE;
469 }
470 return FALSE;
471 }
472
473 BOOL WINAPI SQLInstallDriverEx(LPCSTR lpszDriver, LPCSTR lpszPathIn,
474 LPSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
475 WORD fRequest, LPDWORD lpdwUsageCount)
476 {
477 LPCSTR p;
478 LPWSTR driver, pathin;
479 WCHAR pathout[MAX_PATH];
480 BOOL ret;
481 WORD cbOut = 0;
482
483 clear_errors();
484 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszDriver),
485 debugstr_a(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
486 fRequest, lpdwUsageCount);
487
488 for (p = lpszDriver; *p; p += lstrlenA(p) + 1)
489 TRACE("%s\n", debugstr_a(p));
490
491 driver = SQLInstall_strdup_multi(lpszDriver);
492 pathin = SQLInstall_strdup(lpszPathIn);
493
494 ret = SQLInstallDriverExW(driver, pathin, pathout, MAX_PATH, &cbOut,
495 fRequest, lpdwUsageCount);
496 if (ret)
497 {
498 int len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
499 0, NULL, NULL);
500 if (len)
501 {
502 if (pcbPathOut)
503 *pcbPathOut = len - 1;
504
505 if (!lpszPathOut || cbPathOutMax < len)
506 {
507 ret = FALSE;
508 goto out;
509 }
510 len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
511 cbPathOutMax, NULL, NULL);
512 }
513 }
514
515 out:
516 HeapFree(GetProcessHeap(), 0, driver);
517 HeapFree(GetProcessHeap(), 0, pathin);
518 return ret;
519 }
520
521 BOOL WINAPI SQLInstallDriverManagerW(LPWSTR lpszPath, WORD cbPathMax,
522 WORD *pcbPathOut)
523 {
524 UINT len;
525 WCHAR path[MAX_PATH];
526
527 TRACE("(%p %d %p)\n", lpszPath, cbPathMax, pcbPathOut);
528
529 if (cbPathMax < MAX_PATH)
530 return FALSE;
531
532 clear_errors();
533
534 len = GetSystemDirectoryW(path, MAX_PATH);
535
536 if (pcbPathOut)
537 *pcbPathOut = len;
538
539 if (lpszPath && cbPathMax > len)
540 {
541 lstrcpyW(lpszPath, path);
542 return TRUE;
543 }
544 return FALSE;
545 }
546
547 BOOL WINAPI SQLInstallDriverManager(LPSTR lpszPath, WORD cbPathMax,
548 WORD *pcbPathOut)
549 {
550 BOOL ret;
551 WORD len, cbOut = 0;
552 WCHAR path[MAX_PATH];
553
554 TRACE("(%p %d %p)\n", lpszPath, cbPathMax, pcbPathOut);
555
556 if (cbPathMax < MAX_PATH)
557 return FALSE;
558
559 clear_errors();
560
561 ret = SQLInstallDriverManagerW(path, MAX_PATH, &cbOut);
562 if (ret)
563 {
564 len = WideCharToMultiByte(CP_ACP, 0, path, -1, lpszPath, 0,
565 NULL, NULL);
566 if (len)
567 {
568 if (pcbPathOut)
569 *pcbPathOut = len - 1;
570
571 if (!lpszPath || cbPathMax < len)
572 return FALSE;
573
574 len = WideCharToMultiByte(CP_ACP, 0, path, -1, lpszPath,
575 cbPathMax, NULL, NULL);
576 }
577 }
578 return ret;
579 }
580
581 BOOL WINAPI SQLInstallODBCW(HWND hwndParent, LPCWSTR lpszInfFile,
582 LPCWSTR lpszSrcPath, LPCWSTR lpszDrivers)
583 {
584 clear_errors();
585 FIXME("\n");
586 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
587 return FALSE;
588 }
589
590 BOOL WINAPI SQLInstallODBC(HWND hwndParent, LPCSTR lpszInfFile,
591 LPCSTR lpszSrcPath, LPCSTR lpszDrivers)
592 {
593 clear_errors();
594 FIXME("\n");
595 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
596 return FALSE;
597 }
598
599 SQLRETURN WINAPI SQLInstallerErrorW(WORD iError, DWORD *pfErrorCode,
600 LPWSTR lpszErrorMsg, WORD cbErrorMsgMax, WORD *pcbErrorMsg)
601 {
602 TRACE("%d %p %p %d %p\n", iError, pfErrorCode, lpszErrorMsg,
603 cbErrorMsgMax, pcbErrorMsg);
604
605 if (iError == 0)
606 {
607 return SQL_ERROR;
608 }
609 else if (iError <= num_errors)
610 {
611 BOOL truncated = FALSE;
612 WORD len;
613 LPCWSTR msg;
614 iError--;
615 if (pfErrorCode)
616 *pfErrorCode = error_code[iError];
617 msg = error_msg[iError];
618 len = msg ? lstrlenW(msg) : 0;
619 if (pcbErrorMsg)
620 *pcbErrorMsg = len;
621 len++;
622 if (cbErrorMsgMax < len)
623 {
624 len = cbErrorMsgMax;
625 truncated = TRUE;
626 }
627 if (lpszErrorMsg && len)
628 {
629 if (msg)
630 {
631 memcpy (lpszErrorMsg, msg, len * sizeof(WCHAR));
632 }
633 else
634 {
635 assert(len==1);
636 *lpszErrorMsg = 0;
637 }
638 }
639 else
640 {
641 /* Yes. If you pass a null pointer and a large length it is not an error! */
642 truncated = TRUE;
643 }
644
645 return truncated ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
646 }
647
648 /* 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 */
649 if (pcbErrorMsg)
650 *pcbErrorMsg = 0;
651
652 if (lpszErrorMsg && cbErrorMsgMax > 0)
653 *lpszErrorMsg = '\0';
654
655 return SQL_NO_DATA;
656 }
657
658 SQLRETURN WINAPI SQLInstallerError(WORD iError, DWORD *pfErrorCode,
659 LPSTR lpszErrorMsg, WORD cbErrorMsgMax, WORD *pcbErrorMsg)
660 {
661 SQLRETURN ret;
662 LPWSTR wbuf;
663 WORD cbwbuf;
664 TRACE("%d %p %p %d %p\n", iError, pfErrorCode, lpszErrorMsg,
665 cbErrorMsgMax, pcbErrorMsg);
666
667 wbuf = 0;
668 if (lpszErrorMsg && cbErrorMsgMax)
669 {
670 wbuf = HeapAlloc(GetProcessHeap(), 0, cbErrorMsgMax*sizeof(WCHAR));
671 if (!wbuf)
672 return SQL_ERROR;
673 }
674 ret = SQLInstallerErrorW(iError, pfErrorCode, wbuf, cbErrorMsgMax, &cbwbuf);
675 if (wbuf)
676 {
677 WORD cbBuf = 0;
678 SQLInstall_narrow(1, lpszErrorMsg, wbuf, cbwbuf+1, cbErrorMsgMax, &cbBuf);
679 HeapFree(GetProcessHeap(), 0, wbuf);
680 if (pcbErrorMsg)
681 *pcbErrorMsg = cbBuf-1;
682 }
683 return ret;
684 }
685
686 BOOL WINAPI SQLInstallTranslatorExW(LPCWSTR lpszTranslator, LPCWSTR lpszPathIn,
687 LPWSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
688 WORD fRequest, LPDWORD lpdwUsageCount)
689 {
690 UINT len;
691 LPCWSTR p;
692 WCHAR path[MAX_PATH];
693
694 clear_errors();
695 TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszTranslator),
696 debugstr_w(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
697 fRequest, lpdwUsageCount);
698
699 for (p = lpszTranslator; *p; p += lstrlenW(p) + 1)
700 TRACE("%s\n", debugstr_w(p));
701
702 len = GetSystemDirectoryW(path, MAX_PATH);
703
704 if (pcbPathOut)
705 *pcbPathOut = len;
706
707 if (lpszPathOut && cbPathOutMax > len)
708 {
709 lstrcpyW(lpszPathOut, path);
710 return TRUE;
711 }
712 return FALSE;
713 }
714
715 BOOL WINAPI SQLInstallTranslatorEx(LPCSTR lpszTranslator, LPCSTR lpszPathIn,
716 LPSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
717 WORD fRequest, LPDWORD lpdwUsageCount)
718 {
719 LPCSTR p;
720 LPWSTR translator, pathin;
721 WCHAR pathout[MAX_PATH];
722 BOOL ret;
723 WORD cbOut = 0;
724
725 clear_errors();
726 TRACE("%s %s %p %d %p %d %p\n", debugstr_a(lpszTranslator),
727 debugstr_a(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
728 fRequest, lpdwUsageCount);
729
730 for (p = lpszTranslator; *p; p += lstrlenA(p) + 1)
731 TRACE("%s\n", debugstr_a(p));
732
733 translator = SQLInstall_strdup_multi(lpszTranslator);
734 pathin = SQLInstall_strdup(lpszPathIn);
735
736 ret = SQLInstallTranslatorExW(translator, pathin, pathout, MAX_PATH,
737 &cbOut, fRequest, lpdwUsageCount);
738 if (ret)
739 {
740 int len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
741 0, NULL, NULL);
742 if (len)
743 {
744 if (pcbPathOut)
745 *pcbPathOut = len - 1;
746
747 if (!lpszPathOut || cbPathOutMax < len)
748 {
749 ret = FALSE;
750 goto out;
751 }
752 len = WideCharToMultiByte(CP_ACP, 0, pathout, -1, lpszPathOut,
753 cbPathOutMax, NULL, NULL);
754 }
755 }
756
757 out:
758 HeapFree(GetProcessHeap(), 0, translator);
759 HeapFree(GetProcessHeap(), 0, pathin);
760 return ret;
761 }
762
763 BOOL WINAPI SQLInstallTranslator(LPCSTR lpszInfFile, LPCSTR lpszTranslator,
764 LPCSTR lpszPathIn, LPSTR lpszPathOut, WORD cbPathOutMax,
765 WORD *pcbPathOut, WORD fRequest, LPDWORD lpdwUsageCount)
766 {
767 clear_errors();
768 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_a(lpszInfFile),
769 debugstr_a(lpszTranslator), debugstr_a(lpszPathIn), lpszPathOut,
770 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
771
772 if (lpszInfFile)
773 return FALSE;
774
775 return SQLInstallTranslatorEx(lpszTranslator, lpszPathIn, lpszPathOut,
776 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
777 }
778
779 BOOL WINAPI SQLInstallTranslatorW(LPCWSTR lpszInfFile, LPCWSTR lpszTranslator,
780 LPCWSTR lpszPathIn, LPWSTR lpszPathOut, WORD cbPathOutMax,
781 WORD *pcbPathOut, WORD fRequest, LPDWORD lpdwUsageCount)
782 {
783 clear_errors();
784 TRACE("%s %s %s %p %d %p %d %p\n", debugstr_w(lpszInfFile),
785 debugstr_w(lpszTranslator), debugstr_w(lpszPathIn), lpszPathOut,
786 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
787
788 if (lpszInfFile)
789 return FALSE;
790
791 return SQLInstallTranslatorExW(lpszTranslator, lpszPathIn, lpszPathOut,
792 cbPathOutMax, pcbPathOut, fRequest, lpdwUsageCount);
793 }
794
795 BOOL WINAPI SQLManageDataSources(HWND hwnd)
796 {
797 clear_errors();
798 FIXME("\n");
799 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
800 return FALSE;
801 }
802
803 SQLRETURN WINAPI SQLPostInstallerErrorW(DWORD fErrorCode, LPCWSTR szErrorMsg)
804 {
805 FIXME("\n");
806 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
807 return FALSE;
808 }
809
810 SQLRETURN WINAPI SQLPostInstallerError(DWORD fErrorCode, LPCSTR szErrorMsg)
811 {
812 FIXME("\n");
813 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
814 return FALSE;
815 }
816
817 BOOL WINAPI SQLReadFileDSNW(LPCWSTR lpszFileName, LPCWSTR lpszAppName,
818 LPCWSTR lpszKeyName, LPWSTR lpszString, WORD cbString,
819 WORD *pcbString)
820 {
821 clear_errors();
822 FIXME("\n");
823 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
824 return FALSE;
825 }
826
827 BOOL WINAPI SQLReadFileDSN(LPCSTR lpszFileName, LPCSTR lpszAppName,
828 LPCSTR lpszKeyName, LPSTR lpszString, WORD cbString,
829 WORD *pcbString)
830 {
831 clear_errors();
832 FIXME("\n");
833 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
834 return FALSE;
835 }
836
837 BOOL WINAPI SQLRemoveDefaultDataSource(void)
838 {
839 clear_errors();
840 FIXME("\n");
841 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
842 return FALSE;
843 }
844
845 BOOL WINAPI SQLRemoveDriverW(LPCWSTR lpszDriver, BOOL fRemoveDSN,
846 LPDWORD lpdwUsageCount)
847 {
848 clear_errors();
849 FIXME("stub\n");
850 if (lpdwUsageCount) *lpdwUsageCount = 1;
851 return TRUE;
852 }
853
854 BOOL WINAPI SQLRemoveDriver(LPCSTR lpszDriver, BOOL fRemoveDSN,
855 LPDWORD lpdwUsageCount)
856 {
857 clear_errors();
858 FIXME("stub\n");
859 if (lpdwUsageCount) *lpdwUsageCount = 1;
860 return TRUE;
861 }
862
863 BOOL WINAPI SQLRemoveDriverManager(LPDWORD pdwUsageCount)
864 {
865 clear_errors();
866 FIXME("stub\n");
867 if (pdwUsageCount) *pdwUsageCount = 1;
868 return TRUE;
869 }
870
871 BOOL WINAPI SQLRemoveDSNFromIniW(LPCWSTR lpszDSN)
872 {
873 clear_errors();
874 FIXME("\n");
875 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
876 return FALSE;
877 }
878
879 BOOL WINAPI SQLRemoveDSNFromIni(LPCSTR lpszDSN)
880 {
881 clear_errors();
882 FIXME("\n");
883 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
884 return FALSE;
885 }
886
887 BOOL WINAPI SQLRemoveTranslatorW(LPCWSTR lpszTranslator, LPDWORD lpdwUsageCount)
888 {
889 clear_errors();
890 FIXME("\n");
891 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
892 return FALSE;
893 }
894
895 BOOL WINAPI SQLRemoveTranslator(LPCSTR lpszTranslator, LPDWORD lpdwUsageCount)
896 {
897 clear_errors();
898 FIXME("\n");
899 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
900 return FALSE;
901 }
902
903 BOOL WINAPI SQLSetConfigMode(UWORD wConfigMode)
904 {
905 clear_errors();
906 if (wConfigMode > ODBC_SYSTEM_DSN)
907 {
908 push_error(ODBC_ERROR_INVALID_PARAM_SEQUENCE, odbc_error_invalid_param_sequence);
909 return FALSE;
910 }
911 else
912 {
913 config_mode = wConfigMode;
914 return TRUE;
915 }
916 }
917
918 BOOL WINAPI SQLValidDSNW(LPCWSTR lpszDSN)
919 {
920 clear_errors();
921 FIXME("\n");
922 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
923 return FALSE;
924 }
925
926 BOOL WINAPI SQLValidDSN(LPCSTR lpszDSN)
927 {
928 clear_errors();
929 FIXME("\n");
930 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
931 return FALSE;
932 }
933
934 BOOL WINAPI SQLWriteDSNToIniW(LPCWSTR lpszDSN, LPCWSTR lpszDriver)
935 {
936 clear_errors();
937 FIXME("\n");
938 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
939 return FALSE;
940 }
941
942 BOOL WINAPI SQLWriteDSNToIni(LPCSTR lpszDSN, LPCSTR lpszDriver)
943 {
944 clear_errors();
945 FIXME("\n");
946 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
947 return FALSE;
948 }
949
950 BOOL WINAPI SQLWriteFileDSNW(LPCWSTR lpszFileName, LPCWSTR lpszAppName,
951 LPCWSTR lpszKeyName, LPCWSTR lpszString)
952 {
953 clear_errors();
954 FIXME("\n");
955 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
956 return FALSE;
957 }
958
959 BOOL WINAPI SQLWriteFileDSN(LPCSTR lpszFileName, LPCSTR lpszAppName,
960 LPCSTR lpszKeyName, LPCSTR lpszString)
961 {
962 clear_errors();
963 FIXME("\n");
964 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
965 return FALSE;
966 }
967
968 BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry,
969 LPCWSTR lpszString, LPCWSTR lpszFilename)
970 {
971 clear_errors();
972 FIXME("\n");
973 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
974 return FALSE;
975 }
976
977 BOOL WINAPI SQLWritePrivateProfileString(LPCSTR lpszSection, LPCSTR lpszEntry,
978 LPCSTR lpszString, LPCSTR lpszFilename)
979 {
980 clear_errors();
981 FIXME("\n");
982 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
983 return FALSE;
984 }