Skip to content

Open Cobol ESQL (ocesql) is an open-source Embedded SQL pre-compiler and run-time library designed for COBOL applications which access an open-source database.

License

Notifications You must be signed in to change notification settings

moriyama/Open-COBOL-ESQL

 
 

Repository files navigation

                   Open Cobol ESQL (Ocesql)
                       Version 1.3.0

                       March 24, 2022

                 Tokyo System House Co., Ltd.
                  opencobol@tsh-world.co.jp

1. Introduction
===============

Open Cobol ESQL (ocesql) is an open-source Embedded SQL pre-compiler
and run-time library designed for COBOL applications which access 
an open-source database.  Ocesql translates each EXEC SQL statements
into the standard COBOL CALL statements to the run-time library.

2. Package overview
===================

This package includes the following subdirectories:

    - copy          Copy books for pre-compiled COBOL programs
    - dblib         DB access library (Run-time library)
    - ocesql        ESQL pre-compiler
    - sample        Sample cobol programs

A build of this package typically installs an ocesql executable and 
run-time library as follows:

    - ocesql        ESQL pre-compiler
    - libocesql.so  Run-time library

3. License
==========

All programs except those in dblib subdirectories are distributed
under the GNU General Public License.  See COPYING for details.

Programs in dblib subdirectories are distributed under the GNU
Lesser General Public License.  See COPYING.LIB for details.

See also AUTHORS for the author and contributors.

4. Requirements
===============

  1) Open-source database

    Ocesql currently supports PostgreSQL database only.

    o PostgreSQL C Library (libpq) 8.4 or later
      https://www.postgresql.org/
      https://www.postgresql.jp/

  2) COBOL Development System

    Ocesql is tested with the following COBOL compilers:

    o OpenCOBOL 1.1
      https://sourceforge.net/projects/open-cobol/

    o opensource COBOL 1.5.2J
      https://www.osscons.jp/osscobol/download/

    o Micro Focus Server Express 5.1
      Micro Focus Visual COBOL 2.1 for x64/x86 Linux
      https://www.microfocus.com/
      https://www.microfocus.co.jp/

    o GnuCOBOL 2.2
      https://www.gnu.org/software/gnucobol/

5. Installation
===============

To install Ocesql:

    ./configure
    make
    make install

For use with PostgreSQL 9.0 or later:

    export CPPFLAGS="-I/usr/pgsql-9.x/include"
    export LDFLAGS="-L/usr/pgsql-9.x/lib"
    ./configure
    make
    make install

The "make install" will default to "/usr/local" as the install path.
You may override this by specifying "--prefix=<your install path>" 
to the "./configure" command.

6. Sample programs
==================

Ocesql comes with two sample programs that demonstrate embedded 
SQL in a COBOL application.  The "sample" directory contains
following programs:

  o INSERTTBL.cbl ---- CONNECT, DROP TABLE, CREATE TABLE, 
                       INSERT, COMMIT, ROLLBACK, DISCONNECT

  o FETCHTBL.cbl ----- CONNECT, SELECT COUNT(*), DECLARE cursor, 
                       FETCH cursor, COMMIT, ROLLBACK, DISCONNECT

* Note that these sample programs includes Japanese Shift-JIS characters.
  If you wish to run on non-Japanese environment, modify them first.

To run the sample programs: 

  1) Create a sample database named "testdb"

     When PostgreSQL:

       createdb -T template0 testdb

       If working on Japanese environment, encoding should be UTF-8.

       createdb -E UTF8 -T template0 --lc-collate=ja_JP.UTF-8 --lc-ctype=ja_JP.UTF-8 testdb

  2) Pre-compile the sample programs

       cd <your install path>/ocesql-1.3.0/sample
       ocesql INSERTTBL.cbl INSERTTBL.cob
       ocesql FETCHTBL.cbl FETCHTBL.cob

   * Usage: ocesql [--inc=<include path>] SOURCE [DESTFILE] [LOGFILE]

  3) Compile the sample programs with COBOL compiler and 
     generate executable files:

     Working with Micro Focus Server Express or Visual COBOL:

       export COBCPY=<your install path>/ocesql-1.3.0/copy
       cob -ze "" /usr/local/lib/libocesql.so -o mfocesql.so
       cob -x INSERTTBL.cob -C"INITCALL(mfocesql)"
       cob -x FETCHTBL.cob -C"INITCALL(mfocesql)"

     Working with OpenCOBOL or opensource COBOL:

       export COBCPY=<your install path>/ocesql-1.3.0/copy
       cobc -x -locesql INSERTTBL.cob
       cobc -x -locesql FETCHTBL.cob

  4) Run the sample programs:
  
       ./INSERTTBL
       ./FETCHTBL

   * To create a sample table, run INSERTTBL first.

7. Working with PostgreSQL
==========================

7-1. SQL Verbs
--------------
Ocesql accepts most SQL verbs supported by PostgreSQL's libpq.

The pre-compiler translates each embedded SQL statement into a standard
COBOL CALL statement to the run-time library.  When the CALL statement
is executed, the original SQL statement is passed to libpq's functions
like PQexecParams or PQexec, which in turn submits it to the database.

There are some exceptions to this rule.  When the following SQL verbs
are found, the pre-compiler performs syntax checking, parses these verbs
and generates a series of special SQL commands:

  o CONNECT username IDENTIFIED BY passwd USING dbname
  o DISCONNECT
  o SELECT ... INTO :host-variable ...
  o DECLARE CURSOR cursor FOR SELECT ...
  o OPEN cursor
  o CLOSE cursor
  o FETCH cursor INTO :host-variable

The sample programs demonstrate the use of these special verbs.

7-2. Error handling
-------------------
If SQLCODE or SQLSTATE of SQLCA is set to non-zero value, 
this means that a PostgreSQL error has happened internally.  
SQLSTATE is set to one of the PostgreSQL error codes listed in 
the following URL:

  https://www.postgresql.org/docs/8.4/static/errcodes-appendix.html
  https://www.postgresql.jp/document/8.4/html/errcodes-appendix.html

The sample programs demonstrate the use of SQLSTATE.

8. Working with other databases
===============================
Ocesql is currently supports PostgreSQL only, although it is designed 
to work with several open-source databases, 

----------------------------------------------------------------------
Copyright 2019 Tokyo System House Co., Ltd.

About

Open Cobol ESQL (ocesql) is an open-source Embedded SQL pre-compiler and run-time library designed for COBOL applications which access an open-source database.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 55.1%
  • C 36.7%
  • Makefile 4.7%
  • Lex 1.3%
  • Yacc 1.3%
  • Python 0.4%
  • Other 0.5%