1 | /******************************************** |
2 | * SQLRemoveDSNFromIni |
3 | * |
4 | * Use the current Config Mode to determine the |
5 | * odbc.ini we will use. |
6 | * |
7 | ************************************************** |
8 | * This code was created by Peter Harvey @ CodeByDesign. |
9 | * Released under LGPL 28.JAN.99 |
10 | * |
11 | * Contributions from... |
12 | * ----------------------------------------------- |
13 | * Peter Harvey - pharvey@codebydesign.com |
14 | **************************************************/ |
15 | #include <config.h> |
16 | #include <odbcinstext.h> |
17 | |
18 | BOOL SQLRemoveDSNFromIni(LPCSTR pszDSN ) |
19 | { |
20 | HINI hIni; |
21 | char szINIFileName[ODBC_FILENAME_MAX+1]; |
22 | |
23 | inst_logClear(); |
24 | |
25 | /* SANITY CHECKS */ |
26 | if ( pszDSN == NULL ) |
27 | { |
28 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_DSN, "" ); |
29 | return FALSE; |
30 | } |
31 | |
32 | if ( pszDSN[0] == '\0' ) |
33 | { |
34 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_DSN, "" ); |
35 | return FALSE; |
36 | } |
37 | |
38 | /* GET ODBC INI FILE NAME */ |
39 | if ( _odbcinst_ConfigModeINI( szINIFileName ) == FALSE ) |
40 | { |
41 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_COMPONENT_NOT_FOUND, "" ); |
42 | return FALSE; |
43 | } |
44 | |
45 | #ifdef __OS2__ |
46 | if ( iniOpen( &hIni, szINIFileName, "#;" , '[', ']', '=', FALSE, 1L ) != INI_SUCCESS ) |
47 | #else |
48 | if ( iniOpen( &hIni, szINIFileName, "#;" , '[', ']', '=', FALSE ) != INI_SUCCESS ) |
49 | #endif |
50 | { |
51 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_COMPONENT_NOT_FOUND, "" ); |
52 | return FALSE; |
53 | } |
54 | |
55 | if ( iniObjectSeek( hIni, (char *)pszDSN ) == INI_SUCCESS ) |
56 | { |
57 | iniObjectDelete( hIni ); |
58 | if ( iniCommit( hIni ) != INI_SUCCESS ) |
59 | { |
60 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" ); |
61 | iniClose( hIni ); |
62 | return FALSE; |
63 | } |
64 | } |
65 | iniClose( hIni ); |
66 | |
67 | return TRUE; |
68 | } |
69 | |
70 | BOOL INSTAPI SQLRemoveDSNFromIniW(LPCWSTR lpszDSN) |
71 | { |
72 | char *dsn; |
73 | BOOL ret; |
74 | |
75 | inst_logClear(); |
76 | |
77 | dsn = _single_string_alloc_and_copy( lpszDSN ); |
78 | |
79 | ret = SQLRemoveDSNFromIni( dsn ); |
80 | |
81 | free( dsn ); |
82 | |
83 | return ret; |
84 | } |
85 | |