Installing unixODBC

前端之家收集整理的这篇文章主要介绍了Installing unixODBC前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CobolScript Professional for Linux,FreeBSD,and SunOS.


Overview


CobolScript Professional uses the ODBC specification to connect to data sources. You must install unixODBC in order to use CobolScript Professional for Linux,or SunOS. unixODBC has a GUI component,but it is not required to use CobolScript Professional. If you are running Linux with a kernel older than 2.2.12,you should not install the GUI.


Installing unixODBC without the GUI


Step 1. Download unixODBC from
here .
Step 2. Copy the unixODBC*.tar.gz to /usr/local
Step 3. gunzip unixODBC*.tar.gz
Step 4. tar xvf unixODBC*.tar
Step 5. cd unixODBC*
Step 6. ./configure --enable-gui=no
Step 7. make
Step 8. make install
Step 9. cd /etc
Step 10. Edit the file ld.so.conf and add "/usr/local/lib" to it.
Step 11. ldconfig (Running this command will allow your system to see the unixODBC shared libraries)
Step 12. Add the unixODBC drivers that you want to use to the /usr/local/etc/odbcinst.ini file.
  1. Here is an example of an odbcinst.ini file.
  2.  
  3. [MysqL]
  4. Description = MysqL Driver
  5. Driver = /usr/local/lib/libmyodbc.so
  6. Setup = /usr/local/lib/libodbcmyS.so
  7. FileUsage = 1
  8.  
  9. [Postgresql]
  10. Description = Postgresql Driver
  11. Driver = /usr/local/lib/libodbcpsql.so
  12. Setup = /usr/local/lib/libodbcpsqlS.so
  13. FileUsage = 1
  14.  
Step 13. Add your Data Source Names to /usr/local/etc/odbc.ini Here is an example of a odbc.ini with two Data Source Names - Postgresql and MysqL
  1. [Postgresql]
  2. Description = Postgresql
  3. Driver = Postgresql
  4. Trace = No
  5. TraceFile =
  6. Database = test
  7. Servername = localhost
  8. UserName = postgres
  9. Password = mypass
  10. Port = 5432
  11. Protocol = 6.4
  12. ReadOnly = No
  13. RowVersioning = No
  14. ShowSystemTables = No
  15. ShowOidColumn = No
  16. FakeOidIndex = No
  17. ConnSettings =
  18.  
  19. [MysqL]
  20. Description = MysqL
  21. Driver = MysqL
  22. Trace = Yes
  23. TraceFile = /tmp/MysqL.odbc.log
  24. Server = localhost
  25. Port = 3306
  26. Database = deskware
  27. User = root
  28. Password = mypass
  29.  
  30.  



Installing unixODBC with the GUI

Step 1. Download QT Free Edition from here.
Step 2. Copy or move the qt-2.0.2.tar.gz file to /usr/local
Step 3. gunzip qt-2.0.2.tar.gz
Step 4. tar -xvf qt-2.0.2.tar
Step 5. mv qt-2.0.2 qt
Step 6. Set the following environment variables in your .profile or .login depending on the shell you are using.
  1. In .profile (if your shell is bash,ksh,zsh or sh),add the
  2. following lines:
  3.  
  4. QTDIR=/usr/local/qt
  5. PATH=$QTDIR/bin:$PATH
  6. if [ $MANPATH ]
  7. then
  8. MANPATH=$QTDIR/man:$MANPATH
  9. else
  10. MANPATH=$QTDIR/man
  11. fi
  12. if [ $LD_LIBRARY_PATH ]
  13. then
  14. LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
  15. else
  16. LD_LIBRARY_PATH=$QTDIR/lib
  17. fi
  18. LIBRARY_PATH=$LD_LIBRARY_PATH
  19. if [ $CPLUS_INCLUDE_PATH ]
  20. then
  21. CPLUS_INCLUDE_PATH=$QTDIR/include:$CPLUS_INCLUDE_PATH
  22. else
  23. CPLUS_INCLUDE_PATH=$QTDIR/include
  24. fi
  25.  
  26. export QTDIR PATH MANPATH LD_LIBRARY_PATH LIBRARY_PATH
  27. export CPLUS_INCLUDE_PATH
  28.  
  29. In .login (in case your shell is csh or tcsh),add the following lines:
  30.  
  31. if ( ! $?QTDIR ) then
  32. setenv QTDIR /usr/local/qt
  33. endif
  34. if ( $?PATH ) then
  35. setenv PATH $QTDIR/bin:$PATH
  36. else
  37. setenv PATH $QTDIR/bin
  38. endif
  39. if ( $?MANPATH ) then
  40. setenv MANPATH $QTDIR/man:$MANPATH
  41. else
  42. setenv MANPATH $QTDIR/man
  43. endif
  44. if ( $?LD_LIBRARY_PATH ) then
  45. setenv LD_LIBRARY_PATH $QTDIR/lib:$LD_LIBRARY_PATH
  46. else
  47. setenv LD_LIBRARY_PATH $QTDIR/lib
  48. endif
  49. if ( ! $?LIBRARY_PATH ) then
  50. setenv LIBRARY_PATH $LD_LIBRARY_PATH
  51. endif
  52. if ( $?CPLUS_INCLUDE_PATH ) then
  53. setenv CPLUS_INCLUDE_PATH $QTDIR/include:$CPLUS_INCLUDE_PATH
  54. else
  55. setenv CPLUS_INCLUDE_PATH $QTDIR/include
  56. endif
  57.  
  58. After you have done this,you will need to login again,or
  59. re-source the profile before continuing,so that at least $QTDIR
  60. is set. The installation will give an error message and not
  61. proceed otherwise.

Step 7. cd qt
Step 8. ./configure
Step 9. make
Step 10. Download unixODBC from here.
Step 11. Copy or move the unixODBC*.tar.gz to /usr/local
Step 12. gunzip unixODBC*.tar.gz
Step 13. tar xvf unixODBC*.tar
Step 14. cd unixODBC*
Step 15. ./configure
Step 16. make
Step 17. make install
Step 18. cd /etc
Step 19. Edit the file ld.so.conf and add "/usr/local/lib" to it.
Step 20. ldconfig (Running this command will allow your system to see the unixODBC shared libraries)
Step 21. Add the unixODBC drivers that you want to use to the /usr/local/etc/odbcinst.ini file.
  1. Here is an example of an odbcinst.ini file.
  2.  
  3. [MysqL]
  4. Description = MysqL Driver
  5. Driver = /usr/local/lib/libmyodbc.so
  6. Setup = /usr/local/lib/libodbcmyS.so
  7. FileUsage = 1
  8.  
  9. [Postgresql]
  10. Description = Postgresql Driver
  11. Driver = /usr/local/lib/libodbcpsql.so
  12. Setup = /usr/local/lib/libodbcpsqlS.so
  13. FileUsage = 1
  14.  
Step 22. Add your Data Source Names to /usr/local/etc/odbc.ini Here is an example of a odbc.ini with two Data Source Names - Postgresql and MysqL
  1. [Postgresql]
  2. Description = Postgresql
  3. Driver = Postgresql
  4. Trace = No
  5. TraceFile =
  6. Database = test
  7. Servername = localhost
  8. UserName = postgres
  9. Password = mypass
  10. Port = 5432
  11. Protocol = 6.4
  12. ReadOnly = No
  13. RowVersioning = No
  14. ShowSystemTables = No
  15. ShowOidColumn = No
  16. FakeOidIndex = No
  17. ConnSettings =
  18.  
  19. [MysqL]
  20. Description = MysqL
  21. Driver = MysqL
  22. Trace = Yes
  23. TraceFile = /tmp/MysqL.odbc.log
  24. Server = localhost
  25. Port = 3306
  26. Database = deskware
  27. User = root
  28. Password = mypass
  29.  
  30.  



unixODBC non-GUI Component

isql is a command line tool that allows you to connect to your data sources,send sql commands to the data source,and receive results from the data source. You can execute it by typing "/usr/local/bin/isql ".




unixODBC GUI Components

ODBCConfig is a tool is designed to allow you to easily setup a Data Source Name. You can execute it by typing "/usr/local/bin/ODBCConfig".



DataManager is a graphical tool for exploring data sources. You can execute it by typing "/usr/local/bin/DataManager".




unixODBC Drivers

unixODBC comes with drivers for Minisql,Postgresql,News Server,and SQI. A MysqL unixODBC driver can be found here.


Resources for unixODBC Drivers

Company unixODBC Driver Data Source
Postgresql
http://www.postgresql.org
Postgresql Driver included with unixODBC Postgresql
T.C.X DataKonsult AB
Fax: +46-8-7296905
http://www.mysql.com/download_myodbc.html
MyODBC Driver for unixODBC MysqL
YARD Software GmbH
Tel.: +49 221 98664-0 Fax.: +49 221 98664-99
http://www.yard.de
YARD unixODBC Driver YARD-sql
Hughes Technologies
Fax: +61 7 5529 2299
http://www.Hughes.com.au/
Minisql Driver included with unixODBC Minisql
SQI Text File Driver
sql unixODBC Driver for Text Files Text Files
Ke Jin's Net News ODBC Driver
Internet News Server Driver included with unixODBC Internet News Server
Easysoft
Tel: +44 (0) 113 222 0400 Fax: +44 (0) 113 222 0500
http://www.easysoft.com/
Easysoft's ODBC-ODBC Bridge ODBC-ODBC



Example sql Statements with CobolScript

  1. CREATE TABLE
  2. exec sql
  3. create table customer
  4. ( firstname varchar(20),lastname varchar(20),description varchar(50))
  5. end-exec.
  6. INSERT
  7. exec sql
  8. insert into customer
  9. values (:customer-first-name,:customer-last-name,:customer-description)
  10. end-exec.
  11. DELETE
  12. exec sql
  13. delete from customer
  14. where firstname = 'dean6'
  15. end-exec.
  16. UPDATE
  17. exec sql
  18. update customer
  19. set description = 'update test again'
  20. where firstname = :customer-first-name and
  21. lastname = :customer-last-name
  22. end-exec.
  23. SELECT
  24. exec sql
  25. select firstname,lastname,description
  26. into :customer-first-name,:customer-description
  27. from customer
  28. where firstname = 'dean8 '
  29. end-exec.
  30. DECLARE
  31. exec sql
  32. declare cust_cursor cursor for
  33. select firstname,dollar_amount
  34. from customer
  35. order by firstname
  36. end-exec.
  37. OPEN
  38. exec sql open cust_cursor end-exec. CLOSE
  39. exec sql close cust_cursor end-exec. FETCH exec sql fetch relative :row-position cust_cursor into :customer-first-name,:customer-dollar-amount end-exec. FETCH Syntax: FETCH {NEXT | PRIOR | FIRST | LAST | ABSOLUTE {int-constant | host-constant } | RELATVIE {int-constant | host-constant }} cursor-name INTO host-variable [,...] COMMIT exec sql commit end-exec. ROLLBACK exec sql rollback end-exec.



A Sample CobolScript Program using a MysqL Database

  1. 1 misc.
  2. 5 data-source-name pic x(50).
  3. 5 user-id pic x(10).
  4. 5 password pic x(10).
  5. 5 return-code pic s9(05).
  6. 5 row-position pic s9(05).
  7. 5 formatted-balance pic $$$,$$$.99.
  8. 1 customer-table.
  9. 5 customer-first-name pic x(20).
  10. 5 customer-last-name pic x(20).
  11. 5 customer-description pic x(70).
  12. 5 customer-balance pic 9(06).99.
  13. 1 sql-return-codes.
  14. 5 sqlstate pic x(05).
  15. 5 sqlnativeerror pic s9(06).
  16. 5 sqlerrormessage pic x(500).
  17. 5 sqlstatement pic x(500).
  18. main.
  19. perform connect_to_database.
  20. perform create_table.
  21. perform alter_table.
  22. perform create_index.
  23. perform insert_into_table.
  24. perform select_from_table.
  25. perform build_cursor.
  26. perform update_table.
  27. perform delete_from_table.
  28. perform drop_index.
  29. perform drop_table.
  30. perform disconnect_from_database.
  31. stop run.
  32. connect_to_database.
  33. move `MysqL` to data-source-name.
  34. move `testuser` to user-id.
  35. move `testpass` to password.
  36. opendb using data-source-name
  37. user-id
  38. password
  39. return-code.
  40. create_table.
  41. exec sql
  42. create table customer
  43. (firstname varchar(20),description varchar(70) )
  44. end-exec.
  45. alter_table.
  46. exec sql
  47. alter table customer add
  48. balance decimal(6,2)
  49. end-exec.
  50. create_index.
  51. exec sql
  52. create index cust_index on customer (firstname)
  53. end-exec.
  54. insert_into_table.
  55. exec sql
  56. commit
  57. end-exec.
  58. move `John` to customer-first-name.
  59. move `Doe` to customer-last-name.
  60. move `Senior Director at ACME Software House` to customer-description.
  61. move 99.95 to customer-balance.
  62. exec sql
  63. insert into customer
  64. values (:customer-first-name,:customer-description,:customer-balance )
  65. end-exec.
  66. exec sql
  67. insert into customer
  68. values ('Jane','Doe','Senior Programmer',123.95 )
  69. end-exec.
  70. exec sql
  71. insert into customer
  72. values ('Matt','Junior Programmer',23.00 )
  73. end-exec.
  74. exec sql
  75. insert into customer
  76. values ('Charles','GEM Programmer',199.99 )
  77. end-exec.
  78. exec sql
  79. commit
  80. end-exec.
  81. exec sql
  82. insert into customer
  83. values ('Jason','Programmer',99.00 )
  84. end-exec.
  85. exec sql
  86. rollback
  87. end-exec.
  88. select_from_table.
  89. exec sql
  90. select firstname,description,balance
  91. into :customer-first-name,:formatted-balance
  92. from customer
  93. where lastname = 'Doe' and
  94. firstname = 'Charles'
  95. end-exec.
  96. if sqlnativeerror = 0 then
  97. display `select into statement successful`
  98. display `firstname: ` & customer-first-name
  99. display `lastname: ` & customer-last-name
  100. display `description: ` & customer-description
  101. display `balance: ` & formatted-balance
  102. else
  103. display `select into statement Failed`
  104. display `sql-return-codes: ` & sql-return-codes
  105. end-if.
  106. build_cursor.
  107. exec sql
  108. declare cust_cursor cursor for
  109. select firstname,balance
  110. from customer
  111. order by balance
  112. end-exec.
  113. open_cursor.
  114. exec sql
  115. open cust_cursor
  116. end-exec.
  117. fetch_cursor.
  118. display ``.
  119. display `firstname lastname balance`.
  120. display `----------------------------------------------------`.
  121. exec sql
  122. fetch last cust_cursor
  123. into :customer-first-name,:formatted-balance
  124. end-exec.
  125. if sqlnativeerror = 0 then
  126. display customer-first-name & ` ` & customer-last-name & ` ` & formatted-balance
  127. end-if.
  128. move -1 to row-position.
  129. exec sql
  130. fetch relative :row-position cust_cursor
  131. into :customer-first-name,:formatted-balance
  132. end-exec.
  133. if sqlnativeerror = 0 then
  134. display customer-first-name & ` ` & customer-last-name & ` ` & formatted-balance
  135. end-if.
  136. perform fetch-data-from-database
  137. until sqlnativeerror = 100.
  138. display `----------------------------------------------------`.
  139. display ``.
  140. exec sql
  141. close cust_cursor
  142. end-exec.
  143. if sqlnativeerror = 0 then
  144. display `close cursor successful`
  145. else
  146. display `close cursor Failed`
  147. display `sql-return-codes: ` & sql-return-codes
  148. end-if.
  149. fetch-data-from-database.
  150. exec sql
  151. fetch next cust_cursor
  152. into :customer-first-name,:formatted-balance
  153. end-exec.
  154. if sqlnativeerror = 0 then
  155. display customer-first-name & ` ` & customer-last-name & ` ` & formatted-balance
  156. end-if.
  157. update_table.
  158. move `Doe` to customer-last-name.
  159. exec sql
  160. update customer
  161. set lastname = 'Jones'
  162. where firstname = 'Matt' and
  163. lastname = :customer-last-name
  164. end-exec.
  165. exec sql
  166. commit
  167. end-exec.
  168. delete_from_table.
  169. exec sql
  170. delete from customer
  171. where firstname = 'Charles' and lastname = 'Doe'
  172. end-exec.
  173. exec sql
  174. commit
  175. end-exec.
  176. drop_index.
  177. exec sql
  178. drop index cust_index on customer
  179. end-exec.
  180. drop_table.
  181. exec sql
  182. drop table customer
  183. end-exec.
  184. disconnect_from_database.
  185. closedb using return-code.
@H_773_301@

猜你在找的Postgre SQL相关文章