aboutsummaryrefslogtreecommitdiff
path: root/doc/src/sgml/odbc.sgml
blob: e2182adbef1524b8e51597ac3b62efc703eb2dbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/odbc.sgml,v 1.15 2000/05/02 20:01:52 thomas Exp $
-->

 <chapter id="odbc">
  <docinfo>
   <authorgroup>
    <author>
     <firstname>Tim</firstname>
     <surname>Goeke</surname>
    </author>
    <author>
     <firstname>Thomas</firstname>
     <surname>Lockhart</surname>
    </author>
   </authorgroup>
   <date>1998-10-21</date>
  </docinfo>

  <title>ODBC Interface</title>

  <note>
   <para>
    Background information originally by
    <ulink url="mailto:tgoeke@xpressway.com">Tim Goeke</ulink>
   </para>
  </note>

  <para>
   <acronym>ODBC</acronym> (Open Database Connectivity) is an abstract 
   <acronym>API</acronym> 
   which allows you to write applications which can interoperate
   with various <acronym>RDBMS</acronym> servers.
   <acronym>ODBC</acronym> provides a product-neutral interface 
   between frontend applications and database servers,
   allowing a user or developer to write applications which are 
   transportable between servers from different manufacturers..
  </para>

  <sect1>
   <title>Background</title>

   <para>
    The <acronym>ODBC</acronym> <acronym>API</acronym> matches up 
    on the backend to an <acronym>ODBC</acronym>-compatible data source.
    This could be anything from a text file to an Oracle or 
    <productname>Postgres</productname> <acronym>RDBMS</acronym>.
   </para>

   <para>
    The backend access come from <acronym>ODBC</acronym> drivers, 
    or vendor specifc drivers that
    allow data access.   <productname>psqlODBC</productname> is such a driver,
    along with others that are
    available, such as the OpenLink <acronym>ODBC</acronym> drivers.
   </para>

   <para>
    Once you write an <acronym>ODBC</acronym> application, 
    you <emphasis>should</emphasis> be able to connect to <emphasis>any</emphasis>
    back end database, regardless of the vendor, as long as the database schema
    is the same.
   </para>

   <para>
    For example. you could have <productname>MS SQL Server</productname>
    and <productname>Postgres</productname> servers which have
    exactly the same data.  Using <acronym>ODBC</acronym>, 
    your Windows application would make exactly the
    same calls and the back end data source would look the same (to the Windows
    app).
   </para>

<!--
   <para>
    <ulink url="http://www.insightdist.com/">Insight Distributors</ulink> 
    provides active and ongoing
    support for the core <productname>psqlODBC</productname> distribution. 
    They provide a
    <ulink url="http://www.insightdist.com/psqlodbc/"><acronym>FAQ</acronym></ulink>,
    ongoing development on the code base, and actively participate on the 
    <ulink url="mailto:interfaces@postgresql.org">interfaces mailing list</ulink>.
   </para>
-->
  </sect1>

  <sect1>
   <title><productname>Windows</productname> Applications</title>

   <para>
    In the real world, differences in drivers and the level of 
    <acronym>ODBC</acronym> support
    lessens the potential of <acronym>ODBC</acronym>:

    <itemizedlist spacing="compact" mark="bullet">
     <listitem>
      <para>
       Access, Delphi, and Visual Basic all support <acronym>ODBC</acronym> directly.
      </para>
     </listitem>
     <listitem>
      <para>
       Under C++, such as Visual C++, 
       you can use the C++ <acronym>ODBC</acronym> <acronym>API</acronym>.
      </para>
     </listitem>

     <listitem>
      <para>
       In Visual C++, you can use the CRecordSet class, which wraps the 
       <acronym>ODBC</acronym> <acronym>API</acronym>
       set within an MFC 4.2 class.  This is the easiest route if you are doing
       Windows C++ development under Windows NT.
      </para>
     </listitem>
    </itemizedlist>
   </para>

   <sect2>
    <title>Writing Applications</title>

    <para>
     <quote>
      If I write an application for <productname>Postgres</productname> 
      can I write it using <acronym>ODBC</acronym> calls
      to the <productname>Postgres</productname> server, 
      or is that only when another database program 
      like MS SQL Server or Access needs to access the data?
     </quote>
    </para>
    <para>
     The <acronym>ODBC</acronym> <acronym>API</acronym>
     is the way to go.
     For <productname>Visual C++</productname> coding you can find out more at
     Microsoft's web site or in your <productname>VC++</productname> docs.
    </para>

    <para>
     Visual Basic and the other RAD tools have Recordset objects 
     that use <acronym>ODBC</acronym>
     directly to access data.  Using the data-aware controls, you can quickly
     link to the <acronym>ODBC</acronym> back end database 
     (<emphasis>very</emphasis> quickly).
    </para>

    <para>
     Playing around with MS Access will help you sort this out.  Try using
     <literal>File->Get External Data</literal>.
    </para>

    <tip>
     <para>
      You'll have to set up a DSN first.
     </para>
    </tip>

    <!--
   <Para>
   <Tip>
   <Para>
    The <productname>Postgres</productname> datetime type will break MS Access.
   </Para>
   </Tip>
    -->
   </sect2>
  </sect1>

  <sect1>
   <title>Unix Installation</title>

   <para>
    <productname>ApplixWare</productname> has an 
    <acronym>ODBC</acronym> database interface
    supported on at least some platforms. 
    <productname>ApplixWare</productname> v4.4.2 has been
    demonstrated under Linux with <productname>Postgres</productname> v7.0 
    using the <productname>psqlODBC</productname>
    driver contained in the <productname>Postgres</productname> distribution.
   </para>

   <sect2>
    <title>Building the Driver</title>

    <para>
     The first thing
     to note about the <productname>psqlODBC</productname> driver
     (or any <acronym>ODBC</acronym> driver) is that there must
     exist a driver manager on the system where
     the <acronym>ODBC</acronym> driver is to be
     used. There exists a freeware <acronym>ODBC</acronym> driver for Unix
     called <productname>iodbc</productname> which
     can be obtained from various locations on the Net, including at
     <ulink url="http://www.as220.org/FreeODBC/iodbc-2.12.shar.Z">AS200</ulink>. 
     Instructions for installing <productname>iodbc</productname>
     are beyond the scope of this
     document, but there is a <filename>README</filename>
     that can be found inside the <productname>iodbc</productname> compressed
     .shar file that should explain how to get it up and running.
    </para>

    <para>
     Having said that, any driver manager that you can find for your platform
     should support the <productname>psqlODBC</productname> driver
     or any <acronym>ODBC</acronym> driver.
    </para>

    <para>
     The Unix configuration files for <productname>psqlODBC</productname>
     have recently been extensively
     reworked to allow for easy building on supported platforms as
     well as to allow for support of other Unix platforms in the future.
     The new configuration and build files for the driver should make it
     a simple process to build the driver on the supported platforms. Currently
     these include Linux and FreeBSD but we are hoping other users will
     contribute the necessary information to quickly expand the number of
     platforms for which the driver can be built.
    </para>

    <para>
     There are actually two separate methods to build the driver depending on
     how you received it and these differences come down to only where and how to
     run <application>configure</application> and <application>make</application>. 
     The driver can be built in a standalone, client-only installation, or can be 
     built as a part of the main <productname>Postgres</productname> distribution.
     The standalone installation is convenient if you have <acronym>ODBC</acronym>
     client applications on multiple, heterogeneous platforms. The integrated
     installation is convenient when the target client is the same as the
     server, or when the client and server have similar runtime configurations.
    </para>

    <para>
     Specifically if you have received the <productname>psqlODBC</productname>
     driver as part of the <productname>Postgres</productname> distribution
     (from now on referred to as an "integrated" build) then you will
     configure and make the <acronym>ODBC</acronym> driver
     from the top level source directory
     of the <productname>Postgres</productname> distribution
     along with the rest of its libraries.
     If you received the driver as a standalone package than you will run
     configure and make from the directory in which you unpacked the
     driver source.
    </para>

    <procedure>
     <title>Integrated Installation</title>

     <para>
      This installation procedure is appropriate for an integrated installation.
     </para>

     <step performance="required">
      <para>
       Specify the <option>--with-odbc</option>
       command-line argument for <application>src/configure</application>:

       <programlisting>
% ./configure --with-odbc
% make
       </programlisting>
      </para>
     </step>

     <step performance="required">
      <para>
       Rebuild the <productname>Postgres</productname> distribution:

       <programlisting>
% make install
       </programlisting>
      </para>
     </step>

     <step performance="optional">
      <para>
       Install the ODBC catalog extensions available in
       <filename>PGROOT/contrib/odbc/odbc.sql</filename>:

       <programlisting>
% psql -e template1 &lt; $PGROOT/contrib/odbc/odbc.sql
       </programlisting>

       where specifying <literal>template1</literal> as the target
       database will ensure that all subsequent new databases will
       have these same definitions.
      </para>
     </step>
    </procedure>

    <para>
     Once configured, the <acronym>ODBC</acronym> driver will be built and installed
     into the areas defined for the other components of the
     <productname>Postgres</productname> system. The installation-wide
     <acronym>ODBC</acronym> configuration file will be placed into
     the top directory of the Postgres target tree (<envar>POSTGRESDIR</envar>).
     This can be overridden from the <application>make</application> command-line
     as
     <programlisting>
% make ODBCINST=<replaceable>filename</replaceable> install
     </programlisting>
    </para>

    <procedure>
     <title>Pre-v6.4 Integrated Installation</title>

     <para>
      If you have a <productname>Postgres</productname> installation older than
      v6.4, you have the original source tree available, 
      and you want to use the newest version of the <acronym>ODBC</acronym>
      driver, then you may want to try this form of installation.
     </para>

     <step performance="required">
      <para>
       Copy the output tar file to your target system and unpack it into a 
       clean directory.
      </para>
     </step>
     <step performance="required">
      <para>
       From the directory containing the
       sources, type:

       <programlisting>
% ./configure
% make
% make POSTGRESDIR=<replaceable class="parameter">PostgresTopDir</replaceable> install
       </programlisting>
      </para>
     </step>

     <step performance="optional">
      <para>
       If you would like to install components into different trees, 
       then you can specify various destinations explicitly:

       <programlisting>
% make BINDIR=bindir  LIBDIR=libdir  HEADERDIR=headerdir ODBCINST=instfile install
       </programlisting>
      </para>
     </step>
    </procedure>

    <procedure>
     <title>Standalone Installation</title>

     <para>
      A standalone installation is not integrated with or built on the normal
      <productname>Postgres</productname> distribution. It should be best suited
      for building the <acronym>ODBC</acronym> driver for multiple, heterogeneous
      clients who do not have a locally-installed <productname>Postgres</productname>
      source tree.
     </para>

     <para>
      The default location for libraries and headers 
      for the standalone installation is <filename>/usr/local/lib</filename>
      and <filename>/usr/local/include/iodbc</filename>, respectively.
      There is another system wide configuration file that gets installed
      as <filename>/share/odbcinst.ini</filename> (if <filename>/share</filename>
      exists) or as <filename>/etc/odbcinst.ini</filename>
      (if <filename>/share</filename> does not exist).
     </para>

     <note>
      <para>
       Installation of files into <filename>/share</filename>
       or <filename>/etc</filename> requires system root privileges.
       Most installation steps for <productname>Postgres</productname> do not
       have this requirement, and you can choose another destination which
       is writable by your non-root <productname>Postgres</productname> superuser
       account instead.
      </para>
     </note>

     <step performance="required">
      <para>
       The standalone installation distribution can be built from the
       <productname>Postgres</productname> distribution or may be obtained from 
       <ulink url="http://www.insightdist.com/psqlodbc">Insight Distributors</ulink>,
       the current maintainers of the non-Unix sources.
      </para>

      <para>
       Copy the zip
       or gzipped tarfile to an empty directory. If using the zip package
       unzip it with the command 
       <programlisting>
% unzip -a <replaceable>packagename</replaceable>
       </programlisting>

       The <option>-a</option> option
       is necessary to get rid of <acronym>DOS</acronym> 
       CR/LF pairs in the source files.
      </para>

      <para>
       If you have the gzipped tar package than simply run

       <programlisting>
% tar -xzf <replaceable>packagename</replaceable>
       </programlisting>
      </para>

      <substeps>

       <step performance="optional">
	<para>
	 To create a tar file for a complete standalone installation
	 from the main <productname>Postgres</productname> source tree:
	</para>
       </step>
      </substeps>
     </step>
     <step performance="required">
      <para>
       Configure the main <productname>Postgres</productname> distribution.
      </para>
     </step>
     <step performance="required">
      <para>
       Create the tar file:

       <programlisting>
% cd interfaces/odbc
% make standalone
       </programlisting>
      </para>
     </step>

     <step performance="required">
      <para>
       Copy the output tar file to your target system. Be sure to transfer as
       a binary file if using <application>ftp</application>.
      </para>
     </step>

     <step performance="required">
      <para>
       Unpack the tar file into a clean
       directory.
      </para>
     </step>

     <step performance="required">
      <para>
       Configure the standalone installation:

       <programlisting>
% ./configure
       </programlisting>
      </para>

      <para>
       The configuration can be done with options:

       <programlisting>
% ./configure --prefix=<replaceable>rootdir</replaceable> --with-odbc=<replaceable>inidir</replaceable>
       </programlisting>

       where <option>--prefix</option> installs the libraries and headers in
       the directories <filename><replaceable>rootdir</replaceable>/lib</filename> and
       <filename><replaceable>rootdir</replaceable>/include/iodbc</filename>, and
       <option>--with-odbc</option> installs <filename>odbcinst.ini</filename> in the
       specified directory.
      </para>

      <para>
       Note that both of these options can also be used from the integrated build
       but be aware that <emphasis>when used in the integrated build</emphasis>
       <option>--prefix</option> will also apply to the rest of
       your <productname>Postgres</productname> installation.
       <option>--with-odbc</option> applies only to the configuration file
       <filename>odbcinst.ini</filename>.
      </para>
     </step>

     <step performance="required">
      <para>
       Compile and link the source code:

       <programlisting>
% make ODBCINST=<replaceable>instdir</replaceable>
       </programlisting>
      </para>

      <para>
       You can also override the default location for installation on the
       'make' command line. This only applies to the installation of the
       library and header files. Since the driver needs to know the location
       of the odbcinst.ini file attempting to override the enviroment variable
       that specifies its installation directory will probably cause you
       headaches. It is safest simply to allow the driver to install the
       odbcinst.ini file in the default directory or the directory you specified
       on the './configure' command line with --with-odbc.
      </para>
     </step>

     <!--
     This doesn't currently work - thomas 1998-10-19
    <tip>
    <para>
    <envar>ODBCINST</envar> can be specified during configuration or during
     the compilation. It is not necessary to do so in both steps.
    </tip>
     -->

     <step performance="required">
      <para>
       Install the source code:

       <programlisting>
% make POSTGRESDIR=<replaceable>targettree</replaceable> install
       </programlisting>
      </para>

      <para>
       To override the library and header installation directories separately
       you need to pass the correct installation variables on the
       <literal>make install</literal> command line. These variables are
       <envar>LIBDIR</envar>, <envar>HEADERDIR</envar>
       and <envar>ODBCINST</envar>.
       Overriding <envar>POSTGRESDIR</envar> on the make command line will cause
       <envar>LIBDIR</envar> and <envar>HEADERDIR</envar>
       to be rooted at the new directory you specify. 
       <envar>ODBCINST</envar> is independent of <envar>POSTGRESDIR</envar>.
      </para>

      <para>
       Here is how you would specify the various destinations explicitly:

       <programlisting>
% make BINDIR=<replaceable>bindir</replaceable> LIBDIR=<replaceable>libdir</replaceable> HEADERDIR=<replaceable>headerdir</replaceable> install
       </programlisting>
      </para>

      <para>
       For example, typing

       <programlisting>
% make POSTGRESDIR=/opt/psqlodbc install
       </programlisting>

       (after you've used
       <application>./configure</application> and <application>make</application>)
       will cause the libraries and headers to be installed in the directories
       <filename>/opt/psqlodbc/lib</filename>
       and <filename>/opt/psqlodbc/include/iodbc</filename> respectively.
      </para>

      <para>
       The command

       <programlisting>
% make POSTGRESDIR=/opt/psqlodbc HEADERDIR=/usr/local install
       </programlisting>

       should cause the libraries to be installed in /opt/psqlodbc/lib and
       the headers in /usr/local/include/iodbc. If this doesn't work as
       expected please contact one of the maintainers.
      </para>
     </step>
    </procedure>
   </sect2>
  </sect1>

  <sect1>
   <title>Configuration Files</title>

   <para>
    <filename>~/.odbc.ini</filename> contains user-specified access information 
    for the <productname>psqlODBC</productname> driver. 
    The file uses conventions typical for <productname>Windows</productname> 
    Registry files, but despite this restriction can be made to work.
   </para>

   <para>
    The <filename>.odbc.ini</filename> file has three required sections. 
    The first is <literal>[ODBC Data Sources]</literal>
    which is a list of arbitrary names and descriptions for each database 
    you wish to access. The second required section is the 
    Data Source Specification and there will be one of these sections
    for each database. 
    Each section must be labeled with the name given in 
    <literal>[ODBC Data Sources]</literal> and must contain the following entries: 

    <programlisting>
Driver = <replaceable>POSTGRESDIR</replaceable>/lib/libpsqlodbc.so
Database=<replaceable>DatabaseName</replaceable>
Servername=localhost
Port=5432
    </programlisting>

    <tip>
     <para>
      Remember that the <productname>Postgres</productname> database name is
      usually a single word, without path names of any sort. 
      The <productname>Postgres</productname> server manages the actual access
      to the database, and you need only specify the name from the client.
     </para>
    </tip>

    Other entries may be inserted to control the format of the display. 
    The third required section is <literal>[ODBC]</literal> 
    which must contain the <literal>InstallDir</literal> keyword 
    and which may contain other options.
   </para>

   <para>
    Here is an example <filename>.odbc.ini</filename> file, 
    showing access information for three databases:

    <programlisting>
[ODBC Data Sources]
DataEntry = Read/Write Database
QueryOnly = Read-only Database
Test = Debugging Database
Default = Postgres Stripped

[DataEntry]
ReadOnly = 0
Servername = localhost
Database = Sales

[QueryOnly]
ReadOnly = 1
Servername = localhost
Database = Sales

[Test]
Debug = 1
CommLog = 1
ReadOnly = 0
Servername = localhost
Username = tgl
Password = "no$way"
Port = 5432
Database = test

[Default]
Servername = localhost
Database = tgl
Driver = /opt/postgres/current/lib/libpsqlodbc.so

[ODBC]
InstallDir = /opt/applix/axdata/axshlib
    </programlisting>
   </para>
  </sect1>

  <sect1>
   <title>ApplixWare</title>

   <sect2>
    <title>Configuration</title>

    <para>
     <productname>ApplixWare</productname> must be configured correctly
     in order for it to
     be able to access the <productname>Postgres</productname>
     <acronym>ODBC</acronym> software drivers.
    </para>

    <procedure>
     <title>Enabling ApplixWare Database Access</title>

     <para>
      These instructions are for the <literal>4.4.2</literal> release of
      <productname>ApplixWare</productname> on <productname>Linux</productname>.
      Refer to the <citetitle>Linux Sys Admin</citetitle> on-line book
      for more detailed information.
     </para>

     <step performance="required">
      <para>
       You must modify <filename>axnet.cnf</filename> so that
       <filename>elfodbc</filename> can
       find <filename>libodbc.so</filename>
       (the <acronym>ODBC</acronym> driver manager) shared library.
       This library is included with the ApplixWare distribution,
       but <filename>axnet.cnf</filename> needs to be modified to point to the 
       correct location.
      </para>

      <para>
       As root, edit the file
       <filename><replaceable>applixroot</replaceable>/applix/axdata/axnet.cnf</filename>.
      </para>

      <substeps>

       <step performance="required">
	<para>
	 At the bottom of <filename>axnet.cnf</filename>,
	 find the line that starts with

	 <programlisting>
#libFor elfodbc /ax/<replaceable>...</replaceable>
	 </programlisting>
	</para>
       </step>
       <step performance="required">
	<para>
	 Change line to read

	 <programlisting>
libFor elfodbc <replaceable>applixroot</replaceable>/applix/axdata/axshlib/lib
	 </programlisting>

	 which will tell elfodbc to look in this directory
	 for the <acronym>ODBC</acronym> support library.
	 Typically <productname>Applix</productname> is installed in
	 <filename>/opt</filename> so the full path would be
	 <filename>/opt/applix/axdata/axshlib/lib</filename>,
	 but if you have installed <productname>Applix</productname>
	 somewhere else then change the path accordingly.
	</para>
       </step>
      </substeps>
     </step>

     <step performance="required">
      <para>
       Create <filename>.odbc.ini</filename> as 
       described above.  You may also want to add the flag

       <programlisting>
TextAsLongVarchar=0
       </programlisting>

       to the database-specific portion of <filename>.odbc.ini</filename>
       so that text fields will not be shown as <literal>**BLOB**</literal>.
      </para>
     </step>
    </procedure>

    <procedure>
     <title>Testing ApplixWare ODBC Connections</title>

     <step performance="required">
      <para>
       Bring up <application>Applix Data</application>
      </para>
     </step>

     <step performance="required">
      <para>
       Select the <productname>Postgres</productname> database of interest.
      </para>

      <substeps>

       <step performance="required">
	<para>
	 Select <command>Query->Choose Server</command>.  
	</para>
       </step>
       <step performance="required">
	<para>
	 Select <acronym>ODBC</acronym>, and click <command>Browse</command>.
	 The database you configured in <filename>.odbc.ini</filename>
	 should be shown.  Make sure that the <option>Host: field</option>
	 is empty (if it is not, axnet will try to contact axnet on another machine
	 to look for the database).
	</para>
       </step>
       <step performance="required">
	<para>
	 Select the database in the box that was launched by <command>Browse</command>,
	 then click <command>OK</command>.
	</para>
       </step>
       <step performance="required">
	<para>
	 Enter username and password in the login identification dialog,
	 and click <command>OK</command>.
	</para>
       </step>
      </substeps>

      <para>
       You should see "<literal>Starting elfodbc server</literal>"
       in the lower left corner of the
       data window.  If you get an error dialog box, see the debugging section
       below.
      </para>
     </step>
     <step performance="required">
      <para>
       The 'Ready' message will appear in the lower left corner of the data
       window.  This indicates that you can now enter queries.
      </para>
     </step>
     <step performance="required">
      <para>
       Select a table from Query->Choose tables, and then select Query->Query
       to access the database.  The first 50 or so rows from the table should
       appear.
      </para>
     </step>
    </procedure>
   </sect2>

   <sect2>
    <title>Common Problems</title>

    <para>
     The following messages can appear while trying to make an
     <acronym>ODBC</acronym> connection through 
     <productname>Applix Data</productname>:

     <variablelist>
      <varlistentry>
       <term>
	Cannot launch gateway on server
       </term>
       <listitem>
	<para>
	 <literal>elfodbc</literal> can't find <filename>libodbc.so</filename>.  
	 Check your <filename>axnet.cnf</filename>.
	</para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term>
	Error from ODBC Gateway:
	IM003::[iODBC][Driver Manager]Specified driver could not be loaded
       </term>
       <listitem>
	<para>
	 <filename>libodbc.so</filename> cannot find the driver listed in
	 <filename>.odbc.ini</filename>. Verify the settings.
	</para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term>
	Server: Broken Pipe
       </term>

       <listitem>
	<para>
	 The driver process has terminated due to some other
	 problem.  You might not have an up-to-date version
	 of the <productname>Postgres</productname>
	 <acronym>ODBC</acronym> package.
	</para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term>
	setuid to 256: failed to launch gateway
       </term>

       <listitem>
	<para>
	 The September release of ApplixWare v4.4.1 (the first release with official
	 <acronym>ODBC</acronym> support under Linux) shows problems when usernames
	 exceed eight (8) characters in length.
	 Problem description ontributed by 
	 <ulink url="mailto:scampbell@lear.com">Steve Campbell</ulink>.
	</para>
       </listitem>
      </varlistentry>

     </variablelist>
    </para>

    <para>
     <note>
      <title>Author</title>

      <para>
       Contributed by 
       <ulink url="mailto:scampbell@lear.com">Steve Campbell</ulink> on
       1998-10-20.
      </para>
     </note>

     The <application>axnet</application> program's security system
     seems a little suspect. <application>axnet</application> does things
     on behalf of the user and on a true
     multiple user system it really should be run with root security 
     (so it can read/write in each user's directory).  
     I would hesitate to recommend this, however, since we have no idea what 
     security holes this creates.
    </para>
   </sect2>

   <sect2>
    <title>Debugging ApplixWare ODBC Connections</title>

    <para>
     One good tool for debugging connection problems uses the Unix system
     utility <application>strace</application>.
    </para>
    <procedure>
     <title>Debugging with strace</title>

     <step performance="required">
      <para>
       Start applixware.
      </para>
     </step>
     <step performance="required">
      <para>
       Start an <application>strace</application> on
       the axnet process.  For example, if

       <programlisting>
% ps -aucx | grep ax 
       </programlisting>

       shows

       <programlisting>
cary   10432  0.0  2.6  1740   392  ?  S  Oct  9  0:00 axnet
cary   27883  0.9 31.0 12692  4596  ?  S   10:24  0:04 axmain
       </programlisting>
      </para>

      <para>
       Then run

       <programlisting>
% strace -f -s 1024 -p 10432
       </programlisting>
      </para>
     </step>

     <step performance="required">
      <para>
       Check the strace output.
      </para>
      <note>
       <title>Note from Cary</title>

       <para>
	Many of the error messages from <productname>ApplixWare</productname>
	go to <filename>stderr</filename>, 
	but I'm not sure where <filename>stderr</filename>
	is sent, so <application>strace</application> is the way to find out.
       </para>
      </note>
     </step>
    </procedure>

    <para>
     For example, after getting
     a "<literal>Cannot launch gateway on server</literal>", 
     I ran strace on axnet and got

     <programlisting>
[pid 27947] open("/usr/lib/libodbc.so", O_RDONLY) = -1 ENOENT
(No such file or directory)
[pid 27947] open("/lib/libodbc.so", O_RDONLY) = -1 ENOENT
(No such file or directory)
[pid 27947] write(2, "/usr2/applix/axdata/elfodbc:
can't load library 'libodbc.so'\n", 61) = -1 EIO (I/O error)
     </programlisting>  
     So what is happening is that applix elfodbc is searching for libodbc.so, but it
     can't find it.  That is why axnet.cnf needed to be changed.
    </para>
   </sect2>

   <sect2>
    <title>Running the ApplixWare Demo</title>

    <para>
     In order to go through the 
     <citetitle>ApplixWare Data Tutorial</citetitle>, you need to create
     the sample tables that the Tutorial refers to.  The ELF Macro used to
     create the tables tries to use a NULL condition 
     on many of the database columns,
     and <productname>Postgres</productname> does not currently allow this option.
    </para>
    <para>
     To get around this problem, you can do the following:
    </para>

    <procedure>
     <title>Modifying the ApplixWare Demo</title>

     <step performance="required">
      <para>
       Copy <filename>/opt/applix/axdata/eng/Demos/sqldemo.am</filename>
       to a local directory.
      </para>
     </step>

     <step performance="required">
      <para>
       Edit this local copy of <filename>sqldemo.am</filename>:
      </para>

      <substeps>

       <step performance="required">
	<para>
	 Search for 'null_clause = "NULL"
	</para>
       </step>

       <step performance="required">
	<para>
	 Change this to null_clause = ""
	</para>
       </step>

      </substeps>
     </step>
     <step performance="required">
      <para>
       Start <application>Applix Macro Editor</application>.
      </para>
     </step>

     <step performance="required">
      <para>
       Open the sqldemo.am file from the <application>Macro Editor</application>.
      </para>
     </step>

     <step performance="required">
      <para>
       Select <command>File->Compile and Save</command>.
      </para>
     </step>

     <step performance="required">
      <para>
       Exit <application>Macro Editor</application>.
      </para>
     </step>

     <step performance="required">
      <para>
       Start <application>Applix Data</application>.
      </para>
     </step>

     <step performance="required">
      <para>
       Select <command>*->Run Macro</command>
      </para>
     </step>

     <step performance="required">
      <para>
       Enter the value "<literal>sqldemo</literal>", then click <command>OK</command>.
      </para>

      <para>
       You should see the progress in the status line of the data window
       (in the lower left corner).
      </para>
     </step>

     <step performance="required">
      <para>
       You should now be able to access the demo tables.
      </para>
     </step>
    </procedure>
   </sect2>
   <sect2>
    <title>Useful Macros</title>

    <para>
     You can add information about your
     database login and password to the standard Applix startup
     macro file. This is an example 
     <filename>~/axhome/macros/login.am</filename> file:

     <programlisting>
macro login
set_set_system_var@("sql_username@","tgl")
set_system_var@("sql_passwd@","no$way")
endmacro
     </programlisting>

     <caution>
      <para>
       You should be careful about the file protections on any file containing
       username and password information.
      </para>
     </caution>
    </para>
   </sect2>
   <sect2>
    <title>Supported Platforms</title>

    <para>
     <productname>psqlODBC</productname> has been built and tested
     on <productname>Linux</productname>. There have been reports of success
     with FreeBSD and with Solaris. There are no known restrictions
     on the basic code for other platforms which already support
     <productname>Postgres</productname>.
    </para>
   </sect2>
  </sect1>
 </chapter>

<!-- Keep this comment at the end of the file
Local variables:
mode:sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"./reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:("/usr/lib/sgml/catalog")
sgml-local-ecat-files:nil
End:
-->