Debian Codegraph @

doc/AdministratorManual/odbcinst.html

raw symbols SCIP
1 <html>
2 <head>
3 <title>unixODBC without the GUI</title>
4 </head>
5 <body>
6 <h1><center>unixODBC without the GUI</center></h1>
7 <h3><center>Or<br>
8 everything you wanted to know about odbcinst but were afraid to ask</center></h3>
9 <h3>Purpose</h3>
10 A lot of people are using unixODBC but for a number of reasons are not building
11 the GUI configuration and testing tools (ODBCConfig and DataManager). This
12 document is aimed at these people and hopes to explain what you need to do
13 and when to do it.
14 <br>
15
16 <h3>What's a ini file ?</h3>
17
18 ODBC first appeared within Windows 3.0. At this time Windows used .ini files
19 to contain configuration information. These are text files containing the
20 following layout
21 <pre>[section1]
22 entry1 = value
23 entry2 = value
24
25 [section2]
26 entry1 = value
27 entry2 = value
28 ...</pre>
29 With the advent of Windows NT these ini files have been replaced by the
30 registry, but the API to access them in ODBC has remained the same. Windows
31 has two function in odbcinst.dll that allow applications and drivers to
32 query and modify these files, SQLGetPrivateProfileString and
33 SQLPutPrivateProfileString.
34 <p>As part of unixODBC's aim of reproducing the ODBC environment on non
35 Windows platform's the ini files and libodbcinst provide the same format
36 and functionality.
37
38 <h3>System versus User</h3>
39 ODBC distinguishes between two types of ini files. System ini files are
40 designed to be accessible but not modifiable by any user, and user files
41 are private to a particular user, and may be modified by that user.
42
43 <p>The system files are odbcinst.ini and odbc.ini (note no leading dot),
44 and the user file is ~/.odbc.ini in each user's home directory (note
45 leading dot).
46
47 <p>The system file odbcinst.ini contains information about ODBC drivers
48 available to all users, and the odbc.ini file contains information about
49 DSN's available to all users. These &quot;System DSN's&quot; are useful
50 for application such as web servers that may not be running as a real user
51 and so will not have a home directory to contain a .odbc.ini file.
52
53 <p>A good example of this is Apache and PHP with ODBC support. When the
54 http server is first started it calls SQLAllocEnv as root. it then at a
55 later time changes to the specified user (in my case nobody) and calls
56 SQLConnect. If the DSN's was not a system DSN then this fails.
57
58 <h3>FILEDSN's</h3>
59 ODBC 3 also has a third sort of DSN, a file DSN. These store the connection
60 information in a file that may be accessible to anyone. unixODBC does not
61 at this time support FILEDSN's but it will when I get around to it. They
62 are useful things but of less use to UNIX's than NT. Because of the MS view
63 that everyone should have Windows on there desk, each workstation will have
64 it's own registry with it's own set of system and user DSN's that can not
65 be used by other workstations. File DSN's are a fix to allow the information
66 to be stored in a central server that is accessible to all the workstations.
67
68 <h3>Why not vi ?</h3>
69 All the configuration files needed by unixODBC are plain text files, so there
70 is no reason that you can not use your favorite text editor to setup the files.
71 <p>
72 However since beta 1.6 the location of the system files odbcinst.ini and
73 odbc.ini are determined by the configure script. The default location is
74 /usr/local/etc, and if a prefix is specified the location is {prefix}/etc.
75 The location of the etc path can be broken out of the normal prefix tree
76 by specifying --sysconfdir=DIR, so the following will expect the system
77 files to be in the same location as pre 1.6 builds.
78 <pre>./configure --sysconfdir=/etc</pre>
79 The upshot of all this is that if you use odbcinst to configure the files
80 you can be sure that the same path to the files will be used as are used by
81 the driver manager, so the modifications will take effect.
82
83 <h3>What goes into them ?</h3>
84
85 Ok now we know a bit of the history of ini files and ODBC so now we need to
86 get to the bit that is actually of use. What you put in them.
87
88 <h4>odbcinst.ini</h4>
89
90 This contains a section heading that provides a name for the driver, so
91 for the example below PostgreSQL to indicate a Postgres driver. The
92 following lines contain a description and then the important bits. The
93 Driver and Setup paths point to the ODBC driver and setup libs. The
94 setup lib is used when you click on Add in ODBCConfig to add a new DSN,
95 but as this document is about not using the GUI tools, this is not
96 that important for us. Far more important is the Driver entry (vital in fact)
97 This is the library that the driver manager will dynamically load when
98 SQLConnect or SQLDriverConnect is called for that DSN. If this points
99 to the wrong place the DSN will not work. If the dlopen() fails the DSN will
100 not work. The fileusage entry is added by the odbcinst program, so if
101 you are using a text editor, you will need to add it yourself.
102 <pre>
103 [PostgreSQL]
104 Description = PostgreSQL driver for Linux & Win32
105 Driver = /usr/local/lib/libodbcpsql.so
106 Setup = /usr/local/lib/libodbcpsqlS.so
107 FileUsage = 1
108 </pre>
109
110 <h4>templates</h4>
111
112 odbcinst expects to be supplied with a template file. If you are adding a
113 driver for the above entry the template file would contain the following
114 <pre>
115 [PostgreSQL]
116 Description = PostgreSQL driver for Linux & Win32
117 Driver = /usr/local/lib/libodbcpsql.so
118 Setup = /usr/local/lib/libodbcpsqlS.so
119 </pre>
120
121 and you would invoke odbcinst with the following arguments, assuming that
122 you have created a file template_file with the above entries in.
123 <pre>
124 odbcinst -i -d -f template_file
125 </pre>
126 The args to odbcinst are as follows
127 <p>-i install
128 <br>-d driver
129 <br>-f name of template file
130 <p>
131
132 <h4>Threads</h4>
133 Since 1.6 if the driver manager was built with thread support you may
134 add another entry to each driver entry. For example
135 <pre>
136 [PostgreSQL]
137 Description = PostgreSQL driver for Linux & Win32
138 Driver = /usr/local/lib/libodbcpsql.so
139 Setup = /usr/local/lib/libodbcpsqlS.so
140 <b>Threading = 2</b>
141 </pre>
142
143 This entry alters the default thread serialization level. More details
144 can be found in the file DriverManager/__handles.c in the source tree.
145
146 <h4>[.]odbc.ini</h4>
147 The contents of the odbc.ini files are a bit more complicated, but they follow
148 just the same format as the odbcinst.ini entries. These are complicated by each
149 driver requiring different entries. The entries for all the drivers supplied
150 with the distribution are included below for reference. The entries may be
151 added in the same way using odbcinst, or a text editor. A sample entry
152 to match the above driver could be
153 <pre>
154 [PostgreSQL]
155 Description = Test to Postgres
156 Driver = PostgreSQL
157 Trace = Yes
158 TraceFile = sql.log
159 Database = nick
160 Servername = localhost
161 UserName =
162 Password =
163 Port = 5432
164 Protocol = 6.4
165 ReadOnly = No
166 RowVersioning = No
167 ShowSystemTables = No
168 ShowOidColumn = No
169 FakeOidIndex = No
170 ConnSettings =
171 </pre>
172
173 And this may be written to a template file, and inserted in the ini file
174 for the current user by
175 <pre>
176 odbcinst -i -s -f template_file
177 </pre>
178
179 The individual entries of course may vary.
180
181 <p>The Driver line is used to match the [section] entry in the odbcinst.ini
182 file and the Driver line in the odbcinst file is used to find the
183 path for the driver library, and this loaded and the connection is then
184 established. It's possible to replace the driver entry with a path to
185 the driver itself. This can be used, for example if the user can't get
186 root access to setup anything in /etc (less important now because of
187 the movable etc path). For example
188
189 <pre>
190 [PostgreSQL]
191 Description = Test to Postgres
192 Driver = /usr/local/lib/libodbcpsql.so
193 Trace = Yes
194 TraceFile = sql.log
195 Database = nick
196 Servername = localhost
197 UserName =
198 Password =
199 Port = 5432
200 Protocol = 6.4
201 ReadOnly = No
202 RowVersioning = No
203 ShowSystemTables = No
204 ShowOidColumn = No
205 FakeOidIndex = No
206 ConnSettings =
207 </pre>
208
209 <h3>Templates</h3>
210
211 The templates for the included drivers are...
212
213 <h4>Postgress</h4>
214 <pre>
215 [PostgreSQL]
216 Description = Test to Postgres
217 Driver = PostgreSQL
218 Trace = Yes
219 TraceFile = sql.log
220 Database = nick
221 Servername = localhost
222 UserName =
223 Password =
224 Port = 5432
225 Protocol = 6.4
226 ReadOnly = No
227 RowVersioning = No
228 ShowSystemTables = No
229 ShowOidColumn = No
230 FakeOidIndex = No
231 ConnSettings =
232 </pre>
233
234 <h4>Mini SQL</h4>
235 <pre>
236 [Mini SQL]
237 Description = MiniSQL
238 Driver = MiniSQL
239 Trace = No
240 TraceFile =
241 Host = localhost
242 Database =
243 ConfigFile =
244 </pre>
245
246 <h4>MySQL</h4>
247 <pre>
248 [MySQL]
249 Description = MySQL
250 Driver = MySQL
251 Trace = No
252 TraceFile =
253 Host = localhost
254 Port =
255 Socket =
256 Database =
257 </pre>
258
259 <h4>NNTP driver</h4>
260 <pre>
261 [nntp Data Source]
262 Description = nntp Driver
263 Driver = nntp Driver
264 Trace = No
265 TraceFile =
266 Host = localhost
267 Database =
268 Port =
269 </pre>
270
271 <h4>Sybase SQL Anywhere 5.0</h4> Thanks Greg.
272 <pre>
273 [Sybase SQL Anywhere 5.0]
274 Driver=Sybase SQL Anywhere 5.0
275 Description=Sybase SQL Anywhere 5.0 ODBC Driver
276 Userid=dba
277 Password=sql
278 DatabaseFile=sademo.db
279 </pre>
280
281 Hopefully this will be of some use to someone... <a href="mailto:[email protected]">Nick Gorham</a>
282
283 </body>
284 </html>