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.
Here is an example of an odbcinst.ini file. [MysqL] Description = MysqL Driver Driver = /usr/local/lib/libmyodbc.so Setup = /usr/local/lib/libodbcmyS.so FileUsage = 1 [Postgresql] Description = Postgresql Driver Driver = /usr/local/lib/libodbcpsql.so Setup = /usr/local/lib/libodbcpsqlS.so FileUsage = 1Step 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
[Postgresql] Description = Postgresql Driver = Postgresql Trace = No TraceFile = Database = test Servername = localhost UserName = postgres Password = mypass Port = 5432 Protocol = 6.4 ReadOnly = No RowVersioning = No ShowSystemTables = No ShowOidColumn = No FakeOidIndex = No ConnSettings = [MysqL] Description = MysqL Driver = MysqL Trace = Yes TraceFile = /tmp/MysqL.odbc.log Server = localhost Port = 3306 Database = deskware User = root Password = mypass
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.
In .profile (if your shell is bash,ksh,zsh or sh),add the following lines: QTDIR=/usr/local/qt PATH=$QTDIR/bin:$PATH if [ $MANPATH ] then MANPATH=$QTDIR/man:$MANPATH else MANPATH=$QTDIR/man fi if [ $LD_LIBRARY_PATH ] then LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH else LD_LIBRARY_PATH=$QTDIR/lib fi LIBRARY_PATH=$LD_LIBRARY_PATH if [ $CPLUS_INCLUDE_PATH ] then CPLUS_INCLUDE_PATH=$QTDIR/include:$CPLUS_INCLUDE_PATH else CPLUS_INCLUDE_PATH=$QTDIR/include fi export QTDIR PATH MANPATH LD_LIBRARY_PATH LIBRARY_PATH export CPLUS_INCLUDE_PATH In .login (in case your shell is csh or tcsh),add the following lines: if ( ! $?QTDIR ) then setenv QTDIR /usr/local/qt endif if ( $?PATH ) then setenv PATH $QTDIR/bin:$PATH else setenv PATH $QTDIR/bin endif if ( $?MANPATH ) then setenv MANPATH $QTDIR/man:$MANPATH else setenv MANPATH $QTDIR/man endif if ( $?LD_LIBRARY_PATH ) then setenv LD_LIBRARY_PATH $QTDIR/lib:$LD_LIBRARY_PATH else setenv LD_LIBRARY_PATH $QTDIR/lib endif if ( ! $?LIBRARY_PATH ) then setenv LIBRARY_PATH $LD_LIBRARY_PATH endif if ( $?CPLUS_INCLUDE_PATH ) then setenv CPLUS_INCLUDE_PATH $QTDIR/include:$CPLUS_INCLUDE_PATH else setenv CPLUS_INCLUDE_PATH $QTDIR/include endif After you have done this,you will need to login again,or re-source the profile before continuing,so that at least $QTDIR is set. The installation will give an error message and not 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.
Here is an example of an odbcinst.ini file. [MysqL] Description = MysqL Driver Driver = /usr/local/lib/libmyodbc.so Setup = /usr/local/lib/libodbcmyS.so FileUsage = 1 [Postgresql] Description = Postgresql Driver Driver = /usr/local/lib/libodbcpsql.so Setup = /usr/local/lib/libodbcpsqlS.so FileUsage = 1Step 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
[Postgresql] Description = Postgresql Driver = Postgresql Trace = No TraceFile = Database = test Servername = localhost UserName = postgres Password = mypass Port = 5432 Protocol = 6.4 ReadOnly = No RowVersioning = No ShowSystemTables = No ShowOidColumn = No FakeOidIndex = No ConnSettings = [MysqL] Description = MysqL Driver = MysqL Trace = Yes TraceFile = /tmp/MysqL.odbc.log Server = localhost Port = 3306 Database = deskware User = root Password = mypass
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
CREATE TABLE exec sql create table customer ( firstname varchar(20),lastname varchar(20),description varchar(50)) end-exec. INSERT exec sql insert into customer values (:customer-first-name,:customer-last-name,:customer-description) end-exec. DELETE exec sql delete from customer where firstname = 'dean6' end-exec. UPDATE exec sql update customer set description = 'update test again' where firstname = :customer-first-name and lastname = :customer-last-name end-exec. SELECT exec sql select firstname,lastname,description into :customer-first-name,:customer-description from customer where firstname = 'dean8 ' end-exec. DECLAREexec sql declare cust_cursor cursor for select firstname,dollar_amount from customer order by firstname end-exec. OPEN exec sql open cust_cursor end-exec. CLOSE 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 misc. 5 data-source-name pic x(50). 5 user-id pic x(10). 5 password pic x(10). 5 return-code pic s9(05). 5 row-position pic s9(05). 5 formatted-balance pic $$$,$$$.99. 1 customer-table. 5 customer-first-name pic x(20). 5 customer-last-name pic x(20). 5 customer-description pic x(70). 5 customer-balance pic 9(06).99. 1 sql-return-codes. 5 sqlstate pic x(05). 5 sqlnativeerror pic s9(06). 5 sqlerrormessage pic x(500). 5 sqlstatement pic x(500). main. perform connect_to_database. perform create_table. perform alter_table. perform create_index. perform insert_into_table. perform select_from_table. perform build_cursor. perform update_table. perform delete_from_table. perform drop_index. perform drop_table. perform disconnect_from_database. stop run. connect_to_database. move `MysqL` to data-source-name. move `testuser` to user-id. move `testpass` to password. opendb using data-source-name user-id password return-code. create_table. exec sql create table customer (firstname varchar(20),description varchar(70) ) end-exec. alter_table. exec sql alter table customer add balance decimal(6,2) end-exec. create_index. exec sql create index cust_index on customer (firstname) end-exec. insert_into_table. exec sql commit end-exec. move `John` to customer-first-name. move `Doe` to customer-last-name. move `Senior Director at ACME Software House` to customer-description. move 99.95 to customer-balance. exec sql insert into customer values (:customer-first-name,:customer-description,:customer-balance ) end-exec. exec sql insert into customer values ('Jane','Doe','Senior Programmer',123.95 ) end-exec. exec sql insert into customer values ('Matt','Junior Programmer',23.00 ) end-exec. exec sql insert into customer values ('Charles','GEM Programmer',199.99 ) end-exec. exec sql commit end-exec. exec sql insert into customer values ('Jason','Programmer',99.00 ) end-exec. exec sql rollback end-exec. select_from_table. exec sql select firstname,description,balance into :customer-first-name,:formatted-balance from customer where lastname = 'Doe' and firstname = 'Charles' end-exec. if sqlnativeerror = 0 then display `select into statement successful` display `firstname: ` & customer-first-name display `lastname: ` & customer-last-name display `description: ` & customer-description display `balance: ` & formatted-balance else display `select into statement Failed` display `sql-return-codes: ` & sql-return-codes end-if. build_cursor. exec sql declare cust_cursor cursor for select firstname,balance from customer order by balance end-exec. open_cursor. exec sql open cust_cursor end-exec. fetch_cursor. display ``. display `firstname lastname balance`. display `----------------------------------------------------`. exec sql fetch last cust_cursor into :customer-first-name,:formatted-balance end-exec. if sqlnativeerror = 0 then display customer-first-name & ` ` & customer-last-name & ` ` & formatted-balance end-if. move -1 to row-position. exec sql fetch relative :row-position cust_cursor into :customer-first-name,:formatted-balance end-exec. if sqlnativeerror = 0 then display customer-first-name & ` ` & customer-last-name & ` ` & formatted-balance end-if. perform fetch-data-from-database until sqlnativeerror = 100. display `----------------------------------------------------`. display ``. exec sql close cust_cursor end-exec. if sqlnativeerror = 0 then display `close cursor successful` else display `close cursor Failed` display `sql-return-codes: ` & sql-return-codes end-if. fetch-data-from-database. exec sql fetch next cust_cursor into :customer-first-name,:formatted-balance end-exec. if sqlnativeerror = 0 then display customer-first-name & ` ` & customer-last-name & ` ` & formatted-balance end-if. update_table. move `Doe` to customer-last-name. exec sql update customer set lastname = 'Jones' where firstname = 'Matt' and lastname = :customer-last-name end-exec. exec sql commit end-exec. delete_from_table. exec sql delete from customer where firstname = 'Charles' and lastname = 'Doe' end-exec. exec sql commit end-exec. drop_index. exec sql drop index cust_index on customer end-exec. drop_table. exec sql drop table customer end-exec. disconnect_from_database. closedb using return-code.@H_533_301@