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, FreeBSD, or SunOS. UnixODBC has a GUI component, but it is not required to use CobolScript Professional. If you are running Linux with a kenergy 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 TO / USR / LOCAL.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 UnixDbc Drivers That You Want To Use to the /us R /USR/LOCAL/etc/odbcinst.ini file.
Here is an esample 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 = 1
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
[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 Unixocc 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.
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 / incrude
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
Stenv QTDIR / USR / local / qt
ENDIF
IF ($? PATH) THEN
SetENV PATD $ 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_pathelse
STENV 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 / incrude
ENDIF
After you have done this, you will need to login again, or
RE-SOURCE THE PROFILE 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 unixosisbc * .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 Unix)
Step 21. Add The UnixoDbc Drivers That You Want To Use to the /us/local/etc/odbcinst.ini file.
Here is an esample 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 = 1
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
[PostgreSQL]
Description = PostgreSQL
Driver = postgreSQL
TRACE = NO
TRACEFILE =
Database = TEST
ServerName = localhostusername = 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 DriverData SourcePostgreSQL http://www.postgresql.org PostgreSQL Driver included with unixODBCPostgreSQLT.CX DataKonsult AB Fax: 46-8-7296905http: //www.mysql.com/download_myodbc.html MyODBC Driver for unixODBCMySQLYARD Software GmbHTel .: 49 221 98664-0 Fax .: 49 221 98664-99 http://www.yard.de Yard UNIXODBC DRIVERYARD-SQLHUGHES TECHNOLOGIESFAX: 61 7 5529 2299HTTP: //www.hughes.com.au/ minisql Driver Included with unixODBCMiniSQLSQI Text File DriverSQL unixODBC Driver for Text FilesText FilesKe Jin's Net News ODBC DriverInternet News Server Driver included with unixODBCInternet News ServerEasysoftTel: 44 (0) 113 222 0400 Fax: 44 (0) 113 222 0500http: //www.easysoft. COM / EasySoft's ODBC-ODBC BridgeoDBC-ODBCEXAMPLE SQL Statements with CobolScriptcreate 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-Last-Name,
: CUSTOMER-DESCRIPTION
From customer
Where firstname = 'dean8'
End-exec.
Declare
EXEC 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_Cursorend-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 connection_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 use Data-Source-Name
User-id
Password
Return-code.
Create_Table.
EXEC SQL
Create Table Customer
(FirstName Varchar (20),
Lastname 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-Last-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',
'Doe',
'Junior Programmer',
23.00)
End-exec.
EXEC SQL
Insert Into Customer
Values ('charles ",
'Doe',
'Gem Programmer',
199.99)
End-exec.
EXEC SQL
Commit
End-exec.
EXEC SQL
Insert Into Customer
Values ('jason ",
'Doe',
'Programmer',
99.00)
End-exec.
EXEC SQL
Rollback
End-exec.
SELECT_FROM_TABLE.
EXEC SQL
Select Firstname, Lastname, Description, Balance
INTO: Customer-First-Name,
: Customer-Last-Name,
: CUSTOMER-DESCRIPTION,
: 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-Codesend-IF.
Build_cursor.
EXEC SQL
DECLARE CUST_CURSOR CURSOR FOR
Select Firstname, Lastname, 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,: Customer-Last-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,: Customer-Last-Name,: Formatted-Balance
End-exec.
if SqlnativeError = 0 THEN
Display Customer-First-Name & `& Customer-Last-Name &` `& formatted-balance
END-IF.
Perform fetch-data-from-catabase
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-data.
EXEC SQL
Fetch Next Cust_Cursor
INTO: CUSTOMER-FIRST-NAME,: Customer-Last-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.