1 | /************************************************** |
2 | * _SQLWriteInstalledDrivers |
3 | * |
4 | * Added to allow ODBC Config programs and the iODBC |
5 | * driver manager to access system information without |
6 | * having to worry about where it is... just like accessing |
7 | * Data Source information. So no surprise... its just |
8 | * like SQLWritePrivateProfileString()! |
9 | ************************************************** |
10 | * This code was created by Peter Harvey @ CodeByDesign. |
11 | * Released under LGPL 28.JAN.99 |
12 | * |
13 | * Contributions from... |
14 | * ----------------------------------------------- |
15 | * Peter Harvey - pharvey@codebydesign.com |
16 | **************************************************/ |
17 | |
18 | #include <config.h> |
19 | #include <odbcinstext.h> |
20 | |
21 | BOOL _SQLWriteInstalledDrivers( |
22 | LPCSTR pszSection, |
23 | LPCSTR pszEntry, |
24 | LPCSTR pszString ) |
25 | { |
26 | HINI hIni; |
27 | char szIniName[ ODBC_FILENAME_MAX * 2 + 1 ]; |
28 | char b1[ ODBC_FILENAME_MAX + 1 ], b2[ ODBC_FILENAME_MAX + 1 ]; |
29 | |
30 | /* SANITY CHECKS */ |
31 | if ( pszSection == NULL ) |
32 | { |
33 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" ); |
34 | return FALSE; |
35 | } |
36 | if ( pszSection[0] == '\0' ) |
37 | { |
38 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" ); |
39 | return FALSE; |
40 | } |
41 | |
42 | /* OK */ |
43 | |
44 | #ifdef VMS |
45 | sprintf( szIniName, "%s:%s" , odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) ); |
46 | #else |
47 | sprintf( szIniName, "%s/%s" , odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) ); |
48 | #endif |
49 | |
50 | #ifdef __OS2__ |
51 | if ( iniOpen( &hIni, szIniName, "#;" , '[', ']', '=', TRUE, 1L ) != INI_SUCCESS ) |
52 | #else |
53 | if ( iniOpen( &hIni, szIniName, "#;" , '[', ']', '=', TRUE ) != INI_SUCCESS ) |
54 | #endif |
55 | { |
56 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_REQUEST_FAILED, "" ); |
57 | return FALSE; |
58 | } |
59 | |
60 | /* delete section */ |
61 | if ( pszEntry == NULL ) |
62 | { |
63 | if ( iniObjectSeek( hIni, (char *)pszSection ) == INI_SUCCESS ) |
64 | iniObjectDelete( hIni ); |
65 | } |
66 | /* delete entry */ |
67 | else if ( pszString == NULL ) |
68 | { |
69 | if ( iniPropertySeek( hIni, (char *)pszSection, (char *)pszEntry, "" ) == INI_SUCCESS ) |
70 | iniPropertyDelete( hIni ); |
71 | } |
72 | else |
73 | { |
74 | /* add section */ |
75 | if ( iniObjectSeek( hIni, (char *)pszSection ) != INI_SUCCESS ) |
76 | { |
77 | iniObjectInsert( hIni, (char *)pszSection ); |
78 | } |
79 | |
80 | /* update entry */ |
81 | if ( iniPropertySeek( hIni, (char *)pszSection, (char *)pszEntry, "" ) == INI_SUCCESS ) |
82 | { |
83 | /* iniObjectSeek( hIni, (char *)pszSection ); */ |
84 | iniPropertyUpdate( hIni, (char *)pszEntry, (char *)pszString ); |
85 | } |
86 | /* add entry */ |
87 | else |
88 | { |
89 | iniObjectSeek( hIni, (char *)pszSection ); |
90 | iniPropertyInsert( hIni, (char *)pszEntry, (char *)pszString ); |
91 | } |
92 | |
93 | } |
94 | |
95 | if ( iniCommit( hIni ) != INI_SUCCESS ) |
96 | { |
97 | iniClose( hIni ); |
98 | inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_REQUEST_FAILED, "" ); |
99 | return FALSE; |
100 | } |
101 | |
102 | iniClose( hIni ); |
103 | |
104 | return TRUE; |
105 | } |
106 | |
107 | |
108 | |
109 | |
110 | |