Getting Started With Citsql
Getting Started With Citsql
Getting Started With Citsql
Page 1
Getting Started with CitSQL Version 1.3
Contents
ACKNOWLEDGMENT ........................................................................................................ 5
INTRODUCTION ................................................................................................................. 6
Overview ............................................................................................................................................................................ 6
Usage ................................................................................................................................................................................ 13
Options............................................................................................................................................................................. 13
CloseOnCommit .......................................................................................................................................................... 17
CursorSynteticName .................................................................................................................................................... 18
DBEncoding................................................................................................................................................................. 18
DeallocateCloseCursor ................................................................................................................................................ 18
DefaultCCSID .............................................................................................................................................................. 19
DebugMode ................................................................................................................................................................. 20
ExpandIncludes ............................................................................................................................................................ 20
ForceStringMode ......................................................................................................................................................... 20
FreeFormatOutput ........................................................................................................................................................ 21
ImmediateCursor.......................................................................................................................................................... 21
IncludeSearchPath........................................................................................................................................................ 22
LibName ...................................................................................................................................................................... 22
LogMode...................................................................................................................................................................... 23
MaxMem ...................................................................................................................................................................... 24
NoRecCode .................................................................................................................................................................. 24
Prefetch ........................................................................................................................................................................ 24
Quote Translation......................................................................................................................................................... 25
SelectPrepare ............................................................................................................................................................... 26
StandardPrefix ............................................................................................................................................................. 26
StepLimit ..................................................................................................................................................................... 26
Page 2
Getting Started with CitSQL Version 1.3
StrictMode ................................................................................................................................................................... 27
StrictPictureMode ........................................................................................................................................................ 27
TargetPattern ................................................................................................................................................................ 27
TrimMode .................................................................................................................................................................... 28
TruncComments........................................................................................................................................................... 28
UTFInput ..................................................................................................................................................................... 28
Page 3
Getting Started with CitSQL Version 1.3
PORT LISTS...................................................................................................................... 63
CitSQL for MySQL ........................................................................................................................................................ 63
FAQ ................................................................................................................................... 66
Page 4
Getting Started with CitSQL Version 1.3
Acknowledgment
Microsoft and Windows are registered trademarks of the Microsoft Corporation. UNIX is a
registered trademark of the Open Group in the United States and other countries. Other brand and
product names are trademarks or registered trademarks of the holders of those trademarks.
Contact Information:
COBOL-IT
The Lawn
22-30 Old Bath Road
Newbury, Berkshire, RG14 1QN
United Kingdom
Tel: +44-0-1635-565-200
Page 5
Getting Started with CitSQL Version 1.3
Introduction
Overview
The CitSQL Family of Products allow COBOL source code that contains EXEC SQL statements to
be pre-processed, with the resulting output file being a COBOL source file, in which the EXEC
SQL statements have been commented out, and replaced with CALL statements. This file, which is
generated with a .cbp extension by default, can then be compiled by your COBOL-IT Compiler,
and the resulting object code can be run to provide connectivity with one of the CitSQL-supported
databases.
Page 6
Getting Started with CitSQL Version 1.3
Where the program being recompiled has been located in the parent directory of the
include directory containing the file SQLCA.
• Step 2- Compile the target source files creating executable object files
o For Step 2, you will need to have your COBOL-IT Compiler Suite Enterprise
Edition installed. The COBOL-IT Compiler Suite Enterprise Edition includes a
setup file, called setenv_cobolit.bat in Windows environments, and called cobol-it-
setup.sh in Linux/Unix environments. The Compiler setup file must be run prior to
using the COBOL-IT compiler..
A typical command line for using the COBOL-IT compiler is:
>cobc myprog.cbp
The following files should then be located, either in a directory that is in the PATH,
or in a directory that is in the COB_LIBRARY_PATH. This can be accomplished
by explicitly setting these environment variables to the locations of these files, or by
moving these files into directories that are in directories that are in your PATH or
COB_LIBRARY_PATH.
Page 7
Getting Started with CitSQL Version 1.3
On Linux/Unix platforms, the SQL Engine Client component should then be located
in the COBOL-IT installation lib directory, so that it will automatically be in the
LD_LIBRARY_PATH, after the cobol-it-setup.sh script has been run.
Example:
Note- In these examples, the files in the PreprocessorDistrib\bin directory are
copied into the COBOLITDIR\bin directory. In many cases, this will not be the
preferred solution, in which case you should explicitly set the PATH
environment variable to include the PreprocessorDistrib\bin directory.
In Windows:
>setenv_cobolit.bat
>copy PreprocessorDistrib\bin\*.* %COBOLITDIR%\bin
>set COB_LIBRARY_PATH=[location of myprog.dll]
>cobcrun myprog
In Unix: ( from the PreprocessorDistrib directory )
>source /opt/cobol-it/bin/cobol-it-setup.sh
>cp bin/* $COBOLITDIR/bin
>cp lib\* $COBOLITDIR/lib
>export COB_LIBRARY_PATH=[location of myprog.so]
>cobcrun myprog
o The program that is being run contains CALLs to the CitSQL runtime component
which in turn calls the SQL Engine Client component, which performs database
operations, and returns information to the runtime component.
Page 8
Getting Started with CitSQL Version 1.3
The CitSQL Runtime Component is used at Runtime only, and must be distributed with your compiled
application.
The SQL Engine Client Component is used at Runtime only, and must be distributed with your
compiled application. Note, however, that the end-user is responsible for acquiring the necessary
licenses for using the SQL Engine Client Component from the database vendor.
Page 9
Getting Started with CitSQL Version 1.3
• If CitSQL fails to recognized an SQL statement, and detects no reference to a host variable,
it will transmit the SQL statement “as-is” to the database engine. (see Section 5.1)
Getting Started
Installation
CitSQL is distributed as a tar.gz archive on Unix and a Zipped (.zip) archive on Windows.
• Copy the zipped archive into the COBOL-IT installation directory. See table below for defaults
for different platforms:
Page 10
Getting Started with CitSQL Version 1.3
Directory Structure
The process of unzipping the archive will create a directory called distribXXSQL, which
contains the following directory structure:
Directory Contains
/bin The Precompiler and Runtime Component.
(Windows): The Client Component of the
Database Engine.
/include The SQLCA COBOL structure
/lib ( Linux/UNIX ): The Client Component of the
Database Engine
/samples/cobol A sample COBOL application that can be used
to test that your installation of CitSQL.
/doc Documentation
As an example:
For a default installation of the PostgreSQL Development tools :
On Linux Redhat, for PostgreSQL :
License
Usage of the CitSQL Precompiler requires a valid license.
COBOL-IT has made changes to licensing to all products, effective with the the release of COBOL-
Page 11
Getting Started with CitSQL Version 1.3
IT Compiler Suite version 4.0 (and later). With the release of COBOL-IT Compiler Suite version
4.0, separate license files are required for each product/platform pairing. As a consequence, users
can no longer use the same license for multiple products, on multiple platforms; users deploying
multiple products require multiple license files.
Default location
The default location for COBOL-IT product license files in %COBOLITDIR% (Windows) and
$DEFAULT_CITDIR (Linux). For COBOLIT Compiler Suite version 4, the default installation
directory is /opt/cobol-it4-64 (Linux).
License files located in the default location named “citlicense.xml”, or with names prefixed by
“citlicense“ and with the “.xml” extension will be tested for validation by COBOL-IT products. As
examples, COBOL-IT products would automatically test licenses named citlicense.xml, citlicense-
001.xml, citlicense-myproduct.xml.
For cases where different naming conventions are used, or where license files are not stored in the
default installation directory, the user should use the COBOLIT_LICENSE environment variable to
indicate the full path(es) and name(s) of their license file(s).
When a Subscription is registered, the registered user receives download authorization to the
CitSQL Precompiler for the appropriate database, and a license file called citlicense.xml, which is
generated to match the duration of the registered subscription.
Note that CitSQL Precompiler Subscriptions and licenses are defined as lasting for a prescribed
period of time, from the date of the generation of the Subscription and corresponding license. That
is, a one-year Subscription is accompanied by a one-year license, and the expiration date is set at
one-year after the generation of the license, -not- one year after the installation of the software.
The CitSQL Precompiler and CitSQL Runtime Component search for a license file in the following
manner:
Example:
For Linux/Unix-based platforms:
>export COBOLIT_LICENSE=/opt/cobol-it/license/mycitlicense.xml
Note that when indicating multiple license files, the semicolon “ ; ” separator is used. In
Linux, the list of license files is started and finished with single-quote marks “ ‘ “. The
single-quote is located on the same key as the double-quote on most keyboards.
Example:
Page 12
Getting Started with CitSQL Version 1.3
>export COBOLIT_LICENSE=’/opt/cobol-it4-64/compilerlic.xml;/opt/cobol-it4-
64/citsqllic.xml’
2- Check to see if the COBOLITDIR environment variable is set. If set, check for a file called
citlicense.xml located in the directory defined by the COBOLITDIR environment variable.
Example:
For Linux/Unix-based platforms:
>export COBOLITDIR=/opt/cobol-it
For information about your license, including version, owner, and expiration date of the license,
type:
Usage
>citsql [options] [source file(s)] or
Options
CitSQL Options include:
Page 13
Getting Started with CitSQL Version 1.3
Page 14
Getting Started with CitSQL Version 1.3
is [TRUE].
Default [FALSE]
:FreeFormatOutput= [TRUE/FALSE] When set to TRUE, causes output of the
precompiler to be created in “free” source
format.
Page 15
Getting Started with CitSQL Version 1.3
Page 16
Getting Started with CitSQL Version 1.3
Note- When setting Boolean command-line arguments, the words “True” and “False” can be written
in upper or lower case, and their initials can be used as substitutes, as can equivalent integer codes.
Thus, :DebugMode=TRUE, :DebugMode=True, :DebugMode=T, :DebugMode=1 are all
equivalent.
CloseOnCommit
:CloseOnCommit=[True/False] The :CloseOnCommit option aligns CitSQL
behavior with Oracle behavior in cases when a
BEGIN … END construct contains an EXEC
SQL SELECT statement followed by a
COMMIT statement. When
:CloseOnCommit=True, the preprocessor does
not close the SQL cursor when the SELECT
statement has executed. Instead, the cursor is
closed after the COMMIT statement is
Page 17
Getting Started with CitSQL Version 1.3
executed.
In a construct such as the BEGIN … END construct below, the default behavior is to open the SQL
cursor before the execution of the SELECT statement, and to close the SQL cursor after the
execution of the SQL statement. When :CloseOnCommit=True, the SQL cursor is closed after the
COMMIT statement is executed.
BEGIN
EXEC SQL
SELECT aaa FROM X INTO :HostVar
END-EXEC
…
COMMIT
END
CursorSynteticName
:CursorSynteticName=[True/False] Causes the cursor name to be generated at
runtime by the RCQ runtime.
When “CursorSynteticName” is set to True, cursor names are generated at runtime by the RCQ
runtime. This can be required if you use the same cursor name in several modules.
DBEncoding
:DBEncoding=<Valid codepage or UTF-8> Specifies what encoding is used by the database
storage.
IF a “DBEncoding” is defined :
- NATIONAL PIC N fields are converted from NATIONAL to “DBEncoding” encoding when
writing to the database and from “DBEncoding” encoding to NATIONAL when reading
from the database.
Valid codepages are those accepted by the COBOL intrinsic functions NATIONAL-OF and
DISPLAY-OF. For a complete list of the valid codepages recognized by the COBOL-IT compiler,
run the command:
DeallocateCloseCursor
:DeallocateCloseCursor=[True/False] Causes the CLOSE cursor to also deallocate the
DECLARED cursor.
Normally when a program executes an OPEN Cursor, the RCQ runtime makes a DECLARE Cursor
the first time the OPEN is executed. Then, all subsequent executions of the same OPEN will reuse
Page 18
Getting Started with CitSQL Version 1.3
the previously declared cursor. In situations where several COBOL programs use the same
CURSOR name or when using CANCEL, this can result in the return of the POSTGres error:
“Prepared name xxx already exists” even if the cursor xxx is closed.
To fix this, use this flag so that the DECLAREd cursor is deallocated when the CLOSE cursor
statement is executed.
DefaultCCSID
:DefaultCCSID=<Valid codepage or UTF-8> Specifies the default CCSID for string fields
that have no explicit CCSID declaration.
Valid codepages are those accepted by the COBOL intrinsic functions NATIONAL-OF and
DISPLAY-OF. For a complete list of the valid codepages recognized by the COBOL-IT compiler,
run the command:
Different CCSIDs can be declared for different fields in the source code. The CCSID of individual
fields may be explicitly declared using the IBM syntax:
Example:
EXEC SQL DECLARE :<HOSTVARIABLE> VARIABLE CCSID <Valid codepage or UTF-8>
END-EXEC.
- Fields described with the PIC N clause are considered to be declared as USAGE
NATIONAL. Note- For fields described as PIC N VARCHAR, the length of the -LEN fields
is given in number of characters (not in number of bytes). For clarification, in this example,
the length of « 12345 » in FIELDA-ARR is 5, while the number of bytes in storage is 10:
- For fields described with the PIC N clause, CCSID values 1200, 1201 and UTF-16BE are
the only accepted values. Other values provoke a warning and are ignored.
Page 19
Getting Started with CitSQL Version 1.3
DebugMode
:DebugMode= [TRUE/FALSE] Default [FALSE]
When set to TRUE, causes log file
created when LogMode=TRUE to
contain more detail in some situations.
When set to TRUE, and when LogMode set to TRUE, the runtime logfile RCQDLL.log will
contain more detailed information about host variables. Set DebugMode to True to maximize the
information returned from CALLs to the runtime component.
ExpandIncludes
:ExpandIncludes= [TRUE/FALSE] Default [FALSE]
When set to TRUE, causes all COPY files
in the program to be expanded into the
source file prior to pre-compiling the
source.
When set to TRUE, COPY files are expanded in the source file prior to the pre-compiling of the
source. Note- If any SQL statements reference a field in a COPY book, the the command-line
option :ExpandIncludes= TRUE is required.
ForceStringMode
ForceStringMode=[TRUE/FALSE] Default is [FALSE] unless :DBEncoding is set to UTF-
8 or utf8. Then, the default is True.
The :ForceStringMode option affects whether a PIC X data field is sent to the database as a byte-
array, or as a C-String.
When set to False, CitSQL sends PIC X data to the database as a byte-array. This is done to respect
the COBOL semantic that does not consider the character X’00’ as the end of a string. This can be
a problem if the user passes a host variable describe with PIC X to a field declared as a DATE, for
example. DATEs are stored as 4-byte INTs by Postgres, so Postgres expects the DATE to have a
length of 4-bytes.
When set to True, CitSQL sends PIC X data to the database as a C-String (where the String is
Page 20
Getting Started with CitSQL Version 1.3
terminated by the character X’00’). In this case, Postgres can convert the C-String into a DATE.
This is not activated by default, as it is counter to the pure COBOL semantic.
:ForceStringMode=TRUE only applies to elementary data items. Group items containing sub-items
are not affected by this setting.
Rules:
• When :DBEncoding=UTF-8 or utf8 :ForceStringMode is set to True as UTF-8 does not
allow the X’00’ character.
• :ForceStringMode=True only affect the behavior of non-compound fields. That is,
In this case:
01 COL1 PIC X(10).
FreeFormatOutput
:FreeFormatOutput= [TRUE/FALSE] Default [FALSE]
When set to TRUE, causes output of the
precompiler to be created in “free” source
format.
The FreeFormatOutput option, when set to TRUE, causes the ouput of the precompiler to be created
in “free” source format. Free source format, or “terminal format” applies different rules for
establishing the location of the Area A, the Indicator Area, Area B, and the Identification Area.
COBOL-IT source programs that are written in Terminal Format must be compiled with the –free
compiler flag. For more details on the free source format, see Source Code Management Topics in
the Reference Manual.
ImmediateCursor
:ImmediateCursor=[True/False] (CitSQL for PostgreSQL Only)
When set to True, causes as PREPARE EXEC to be
executed before the OPEN when where a CURSOR
is declared with OPEN and FETCH statements:
The results of the PREPARE EXEC are stored, and returned by the FETCH.
Page 21
Getting Started with CitSQL Version 1.3
Attention should be taken when applying the ImmediateCursor preprocessor parameter. Since the
full results of the cursor are returned before the OPEN, this parameter should only be applied for
cursors returning small numbers of lines.
When not using the ImmediateCursor precompiler option, you can cause the PREPARE EXEC to
be executed prior to the OPEN for cursors using the statement :
IncludeSearchPath
:IncludeSearchPath=<Pathes> Default [Current Working Directory]
A comma, or semi-colon separated list of the
directories in which CitSQL will look for
Include files.
Note- The CitSQL precompiler must locate the file SQLCA.cpy fle, which, after installation, is
installed by default in the PreprocessorDistrib/include directory.
In an example, where the SQLCA.cpy file is located in a subdirectory called ./include, and the
source file is called prog1.cob, the command line would be:
LibName
:LibName=<libname> Defaults are:
RCQMYSQL (MySQL),
RCQPGSQL (PostgreSQL),
RCQODBC (ODBC).
The name of the RCQ runtime module.
This option is needed only if you rename
the RCQ runtime module.
As delivered, the runtime component name corresponds to the default settings for LibName. If you
wish to rename these libraries, you must use LibName to prompt the precompiler to change the
target of the CALL statement in the generated code.
Using the sample program provided with the distribution as an example, note how the EXEC SQL
CONNECT statement is translated by the CitSQL for PostgreSQL precompiler. In the example
below, the procompiler is generating code using the default LibName setting of RCQPGSQL:
EXEC SQL
Page 22
Getting Started with CitSQL Version 1.3
CONNECT TO :WRK-DB
USER :WRK-UNAME
USING :WRK-HOST
IDENTIFIED BY: WRK-PASSWORD
Is translated to:
*EXEC SQL
* CONNECT TO :WRK-DB
* USER :WRK-UNAME
* USING :WRK-HOST
* IDENTIFIED BY: WRK-PASSWORD
IF 1=1 THEN
CALL “RCQPGSQL” USING BY VALUE RCQ_C_CONN
BY REFERENCE RCQ-CFG
BY REFERENCE SQLCA
BY REFERENCE WRK-UNAME OF WRK-VARS RCQ-DESC-25
BY REFERENCE WRK-PASSWD OF WRK-VARS RCQ-DESC-25
BY REFERENCE WRK-HOST OF WRK-VARS RCQ-DESC-25
BY REFERENCE WRK-DB OF WRK-VARS RCQ-DESC-25
BY REFERENCE RCQ-NULL-VAR RCQ-NULL-VAR-DESC
END-IF
LogMode
:LogMode=[TRUE/FALSE] Default is: [FALSE]
When set to TRUE the runtime
component creates a log file called
RCQDLL.log that traces all SQL
operations.
When set to TRUE, causes a log file called RCQDLL.log to be created, which contains a trace of all
CALLs to the Runtime Component.
Observe below an excerpt of the output of cit_test when run with LOGMODE=True:
[Wed 2013-04-24 17:03:39]
[Wed 2013-04-24 17:03:39][EXECUTE QUERY]
[Wed 2013-04-24 17:03:39][statement: DROP TABLE TAB_1]
[Wed 2013-04-24 17:03:39][nbre of param : 0]
[Wed 2013-04-24 17:03:39]
[Wed 2013-04-24 17:03:39][MYSQL_STMT_QUERY] OK
[Wed 2013-04-24 17:03:39]
[Wed 2013-04-24 17:03:39][EXECUTE PREPARE]
[Wed 2013-04-24 17:03:39][statement: CREATE TABLE TAB_1(COL_1
CHAR(20),COL_2 FLOAT,COL_3 INT)]
[Wed 2013-04-24 17:03:39][nbre of param : 0]
[Wed 2013-04-24 17:03:39]
[Wed 2013-04-24 17:03:39][MYSQL_STMT_QUERY] OK
Page 23
Getting Started with CitSQL Version 1.3
MaxMem
:MaxMem=[Number] Default is: 100
Allocates <number megabytes> memory
for the precompilation of very large
source files.
Allocates <number megabytes> memory for the precompilation of very large source files.
To allocate 200 MB for the precompilation of a file, add the line
:MaxMem=200
By default, CitSQL will allocate 100MB of memory for the precompilation of a source file. In
most cases, this will be more than adequate. If this default memory allocation is too small, CitSQL
will fail, and abort, and you should increase the setting of MaxMem. If you provide a setting that is
in excess of what the system can allocate, this will also cause CitSQL to fail and abort.
NoRecCode
:NoRecCode=<numeric> Default is 1403
Allows mapping of value returned to indicate the
end of a FETCH statement.
The :NoRecCode option sets the value returned to indicate the end of a FETCH statement, when no
more records are found. The default value is 1403, which corresponds to the Oracle SQLCODE for
a NOT FOUND condition.
Prefetch
Allows for the prefetch of <numeric> records in a network transaction, where <numeric> is a whole
number that represents the number of records to read in a networked transaction..
Page 24
Getting Started with CitSQL Version 1.3
…
EXEC-SQL FETCH …
Where <numeric> is a whole number that represents the number of records to read in a networked
transaction.
Quote Translation
:QuoteTranslation=<pattern> Default is: QDB
Quoting is an area where the various database engines can have fairly different behaviours. Quotes
(of some form) are used to specify string literals and to refer to SQL elements (tables, columns)
which name clash with a reserved words – when a table is named “SELECT”, for instance.
Depending on the database engine at hand, different quotes are used for these different purposes.
When writing new applications, it is of course always possible to use the quotes according to the
target database’s rules at hand. However, things are trickier when dealing with a legacy
applications, where a given quoting convention is used and trying to use this application on another
database which then requires a different quoting convention.
Of course, one can always modify the programs manually to comply with this different quoting
convention, but CitSQL provides a more comfortable mechanism.
One can have the quotes remapped at compile time – hence, without any negative impact on
runtime performance – so that the actual quotes in the program’s SQL statements are translated
before being sent to the database engine.
This quoting replacement process is controlled by the :QuoteTranslation command-line
option. It takes a three character string argument, made of “Q”, “S”, “D”, and “B”.
The first character of this argument denoted what simple quotes must be mapped to. The second
denotes what denotes what double quotes must be mapped to, while the third denotes what the
backquote must be mapped to.
When defining these mapping, the following codes are used:
• ‘S’ or ‘Q’ for single quotes
• ‘D’ for double quotes
• ‘B’ for backquotes.
For instance, to have all quotes mapped to double quotes, one can use a command-line option such
as :QuoteTranslation=DDD. Similarly, to swap single and double quotes, one can use an
option such as :QuoteTranslation=DQB.
Since CitSQL’s default behaviour is to leave the quotes as they are expressed explicitly in the
source code, the default value for this command-line option is “QDB”.
Page 25
Getting Started with CitSQL Version 1.3
SelectPrepare
:SelectPrepare=[True/False] (CitSQL for PostgreSQL Only)
Default is TRUE. Now, the preprocessor causes the
PREPARE EXEC to be executed prior to the OPEN,
and the results stored. When set to False, the former
behavior is applied.
Previously, the preprocessor generated a CURSOR > OPEN > 1 FETCH > CLOSE sequence.
Now, the preprocessor causes the PREPARE EXEC to be executed prior to the OPEN, and the
results are stored. The result is a significant improvement in performance.
StandardPrefix
:StandardPrefix=<prefix> Default is: [None]
Characters prefixed to generated data
items.
StepLimit
:StepLimit=<numeric> Default is: [None]
Sets limit on the number of cases the CitSQL
backtracking will consider. Required when you
receive a Step Limit error.
The CitSQL parser is based on a Backtracking technology. In order to do this, it must set a limit on
the number of cases it must be able to consider. You can control this limit with the :StepLimit
option. Normally you will not need to use the :StepLimit option. However if, when pre-compiling
your source code, you receive a Step limit parse error, as in the example below, then you should
include the :StepLimit option in your pre-compilation command, and increase the value above the
default.
As an example:
citpgsql :IncludeSearchPath=/opt/distribPGSQL-64/include :StepLimit=2000000 ./src /testit.cbl
Page 26
Getting Started with CitSQL Version 1.3
StrictMode
:StrictMode=[TRUE/FALSE] Default is: [FALSE]
When set to TRUE, the CitSQL
precompiler aborts in cases where it does
not recognize an SQL syntax in an EXEC
statement.
When set to TRUE, the CitSQL precompiler aborts in cases where it does not recognize an SQL
syntax in an EXEC statement.
StrictPictureMode
:StrictPictureMode=[TRUE/FALSE] Default is: [FALSE]
When set to TRUE, the CitSQL
precompiler aborts in cases where it does
not recognize an PICTURE clause.
When set to TRUE, the CitSQL precompiler aborts in cases where it does not recognize an
PICTURE clause.
TargetPattern
:TargetPattern=<pattern> Default is: %d%r.cbp
The TargetPattern option involves stringing together a number of components to establish the
location, and naming convention to be applied to target (precompiled) files. It is recommended
that when using the TargetPattern option, a resource file be used.
TargetPattern takes as an argument a string of components, which represent various aspects of the
the naming and location of the target file.
Page 27
Getting Started with CitSQL Version 1.3
>citsql test.cob produces an output file called test.cbp in the same directory.
TrimMode
:TrimMode=[TRUE/FALSE] Default is: [FALSE]
When set to TRUE, alphanumeric (PIC
X) strings that are passed to the database
are first trimmed (right space removed) so
that the actual data in the database does
not have trailing spaces.
When set to TRUE, alphanumeric (PIC X) strings that are passed to the database are first trimmed
(right space removed) so that the actual data in the database does store character strings with trailing
spaces.
TruncComments
:TruncComments=[TRUE/FALSE] Default is: [TRUE]
UTFInput
Page 28
Getting Started with CitSQL Version 1.3
When using multiple options, it is best to store the options in a resource file. In a resource file,
options are stored on separate lines. Empty lines, and lines beginning with a “#” or “;” character
are ignored.
When invoking a resource file from the command line, the resource file is prefixed with an “@”
character.
:IncludeSearchPath=../../include
:TargetPattern=%d%r.cbl
Multiple programs may also be stored in a resource file, and invoked from the command line by
prefixing the resource file with an “@” character.
prog1.cbl
prog2.cbl
Page 29
Getting Started with CitSQL Version 1.3
Using Wildcards
Wildcards are not expanded by the precompiler. However, in Linux/Unix environments, wildcard
expansions are performed by the shell.
Would have the effect of causing each of the files with the .cob extension located in the current
directory to be passed through the precompiler.
<logfile> can include a complete path name followed by a file name. In the absence of a complete
path name, the file name will be applied, and the file will be generated in the current working
directory.
When the RCQLOG runtime environment variable is not set, the logfile is named RCQDDL.LOG,
and created in the current working directory. The RCQLOG runtime environment variable must be
set prior to the use of CitSQL.
Note that when using :LogMode=True, the runtime logfile will contain more detailed information
about host variables when also using :DebugMode=True.
Page 30
Getting Started with CitSQL Version 1.3
For PostgreSQL :
SET PATH=..\..\bin;%PATH%
citpgsql :IncludeSearchPath=../../include cit_test.cob
citpgsql :IncludeSearchPath=../../include dbconnect.cob
For ODBC:
SET PATH=..\..\bin;%PATH%
citodbc :IncludeSearchPath=../../include cit_test.cob
citodbc :IncludeSearchPath=../../include dbconnect.cob
SET COB_LIBRARY_PATH=.;..\..\bin
cit_test
Page 31
Getting Started with CitSQL Version 1.3
or
SET COB_LIBRARY_PATH=.;..\..\bin
cobcrun dbconnect
Page 32
Getting Started with CitSQL Version 1.3
USAGE VARCHAR
USAGE LONG VARCHAR
USAGE VARRAW
USAGE LONG VARRAW
USAGE VARYING.
When the CitSQL Precompiler encounters one of these clauses, the USAGE clause is
commented out and replaced with a group item of the same name, that consists of two
elementary items, one that contains the “-LEN” suffix, and one that contains the “-ARR” suffix.
As an example :
Is converted to:
*****RC*SQL**************
* 05 COL-5 PIC X(50) USAGE VARCHAR. *****RC*SQL**************
05 COL-5.
06 COL-5-LEN PIC S9(4) COMP-5 VALUE 0.
06 COL-5-ARR PIC X(50).
*****RC*SQL**************
The best matching database declaration for these data types depends on the database being used.
For guidelines see the table below:
Page 33
Getting Started with CitSQL Version 1.3
EXEC SQL
CONNECT :WRK-UNAME
IDENTIFIED BY :WRK-PASSWD
END-EXEC
EXEC SQL
CONNECT TO :WRK-DB
USER :WRK-UNAME
IDENTIFIED BY :WRK-PASSWD
END-EXEC
EXEC SQL
CONNECT TO :WRK-DB
USER :WRK-UNAME
USING :WRK-HOST
IDENTIFIED BY :WRK-PASSWD
END-EXEC
EXEC SQL
CONNECT :WRK-UNAME
IDENTIFIED BY :WRK-PASSWD
AT :WRK-DB
END-EXEC
Page 34
Getting Started with CitSQL Version 1.3
Addressing MySQL
Preparing the sample program
The following COBOL connection can be used
EXEC SQL
CONNECT TO :WRK-DB
USER :WRK-UNAME
USING :WRK-HOST
IDENTIFIED BY :WRK-PASSWD
END-EXEC
Where
• :WRK-DB is DBName
• :WRK-UNAME is DbUserName
• :WRK-HOST is “DbServer:PortNr”
• :WRK-PASSWD is DbPassword
The PortNr options is optional. By default, it use the default port (3306 for MySQL)
As an example:
Page 35
Getting Started with CitSQL Version 1.3
Addressing PostgreSQL
Preparing the sample program
The following COBOL connection can be used
EXEC SQL
CONNECT TO :WRK-DB
USER :WRK-UNAME
USING :WRK-HOST
IDENTIFIED BY :WRK-PASSWD
END-EXEC
Where
• :WRK-DB is “DBName”
• :WRK-UNAME is “DbUserName”
• :WRK-HOST is “DbServer:PortNr”
• :WRK-PASSWD is “DbPassword”
The PortNr options is optional. By default, it use the default port (5432 for PostgreSQL)
As an example:
Page 36
Getting Started with CitSQL Version 1.3
Page 37
Getting Started with CitSQL Version 1.3
As an example:
For more connection string samples, please visit the following web sites:
http://www.connectionstrings.com/sql-server-2005
http://www.connectionstrings.com/sql-server-2008
Where
• :ODBC-DB is the ODBC string
Limitations
The limitations are those of the ODBC drivers.
Page 38
Getting Started with CitSQL Version 1.3
Page 39
Getting Started with CitSQL Version 1.3
Page 40
Getting Started with CitSQL Version 1.3
Page 41
Getting Started with CitSQL Version 1.3
Page 42
Getting Started with CitSQL Version 1.3
Page 43
Getting Started with CitSQL Version 1.3
Page 44
Getting Started with CitSQL Version 1.3
Page 45
Getting Started with CitSQL Version 1.3
Precomp.bat
set CITSQLHOME=C:C\COBOL\COBOLIT\distribMYSQL
%CITSQLHOME%\bin\citmysql.exe :IncludeSearchPath=%CITSQLHOME%\include
:TargetPattern=%2 %1
Precomp.bat is used by the –preprocess command. In this command, %1 corresponds to the .COB
file that you will pre-compile. %2 corresponds to the intermediate file produced by the COBOL-IT
Compiler. This file will have a name assigned by the compiler, such as ppiFD1E3148_i.cob.
Page 46
Getting Started with CitSQL Version 1.3
Page 47
Getting Started with CitSQL Version 1.3
Environment Tab
Use the Defaults for the Main Tab and the Runtime Tab.
On the Environment Tab:
Set COB_LIBRARY_PATH to .\object; C:\COBOL\COBOLIT\distribMYSQL\bin.
Your object files are in the .\object folder. The RCQMYSQL.DLL file is in the distribMYSQL\bin
folder. Click Apply, and the Click the Run button.
Page 48
Getting Started with CitSQL Version 1.3
Page 49
Getting Started with CitSQL Version 1.3
Page 50
Getting Started with CitSQL Version 1.3
Precomp.bat
set CITSQLHOME=C:C\COBOL\COBOLIT\distribPGSQL
%CISQLHOME%\bin\citpgsql.exe :IncludeSearchPath=%CITSQLHOME%\include
:TargetPattern=%2 %1
Precomp.bat is used by the –preprocess command. In this command, %1 corresponds to the .COB
file that you will pre-compile. %2 corresponds to the intermediate file produced by the COBOL-IT
Compiler. This file will have a name assigned by the compiler, such as ppiFD1E3148_i.cob.
Page 51
Getting Started with CitSQL Version 1.3
Page 52
Getting Started with CitSQL Version 1.3
Page 53
Getting Started with CitSQL Version 1.3
Environment Tab
Use the Defaults for the Main Tab and the Runtime Tab.
On the Environment Tab:
Set COB_LIBRARY_PATH to .\object; C:\COBOL\COBOLIT\distribPGSQL\bin.
Your object files are in the .\object folder. The RCQPGSQL.DLL file is in the distribPGSQL\bin
folder. Click Apply, and the Click the Run button.
Page 54
Getting Started with CitSQL Version 1.3
Page 55
Getting Started with CitSQL Version 1.3
Page 56
Getting Started with CitSQL Version 1.3
Precomp.bat
set CITSQLHOME=C:C\COBOL\COBOLIT\distribODBC
%CISQLHOME%\bin\citpgsql.exe :IncludeSearchPath=%CITSQLHOME%\include
:TargetPattern=%2 %1
Precomp.bat is used by the –preprocess command. In this command, %1 corresponds to the .COB
file that you will pre-compile. %2 corresponds to the intermediate file produced by the COBOL-IT
Compiler. This file will have a name assigned by the compiler, such as ppiFD1E3148_i.cob.
Page 57
Getting Started with CitSQL Version 1.3
Page 58
Getting Started with CitSQL Version 1.3
Page 59
Getting Started with CitSQL Version 1.3
Page 60
Getting Started with CitSQL Version 1.3
Environment Tab
Use the Defaults for the Main Tab and the Runtime Tab.
On the Environment Tab:
Set COB_LIBRARY_PATH to .\object; C:\COBOL\COBOLIT\distribODBC\bin.
Your object files are in the .\object folder. The RCODBC.DLL file is in the distribODBC\bin
folder. Click Apply, and the Click the Run button.
Page 61
Getting Started with CitSQL Version 1.3
Good to know
This section lists details (where the devil usually lies) that can really help you in the process of
getting CitSQL to work. This heap of information is not structured, all issues are put together
without grouping them in related topics, but one might see this lack of organization as an
uncommon form of added value: it forces the reader to consider issues in a totally different area
than his/her own. Recommended reading!
By default, the components of a COBOL data structure are concatenated without padding. Even
though some COBOL compilers provide options to enable padding (typically to align binary data
values to hardware-defined boundaries for optimisation), this facility should never be used when
compiling precompiled COBOL programs, as the runtime for the precompiler assumes that no
padding is used.
A message such as “Host variable reference in unrecognized block” indicates that strict mode
(See 5.1) is not enforced (as it forbids unrecognized blocks altogether), and that your code contains
a SQL construct that is not recognized by CitSQL. When strict mode is not enabled, such SQL
statements are sent as is to the database server, as a character string, except when it contains host
variable references with a leading colon (“:XXX-YYY”) as there is no way it can guess whether the
host variable should be read or written.
Page 62
Getting Started with CitSQL Version 1.3
Port Lists
Page 63
Getting Started with CitSQL Version 1.3
SUSE 11.x “
OpenSUSE 10.x “
Open SUSE 11.x “
CENTOS 5.x “
CENTOS 6.x “
CENTOS 7.x “
Oracle Linux 5 “
Oracle Linux 6 “
Oracle Linux 7 “
AIX 32-bits OS Version MySQL Version
CitSQL for MySQL for AIX 5.x MySQL Version 5 and
Later
32-bits Xlc
6.x “
AIX 64-bits OS Version MySQL Version
CitSQL for MySQL for AIX 5.x MySQL Version 5 and
Later
64-bits Xlc
6.x “
HP-UX Itanium 64-bits OS Version MySQL Version
CitSQL for MySQL for HP-UX 11iv2 MySQL Version 5 and
Itanium Later
64-bits
11i v3 “
Sun x86 32-bits OS Version MySQL Version
CitSQL for MySQL for Solaris 10 Solaris 10 MySQL Version 5 and
x86 Later
32-bits
Sun x86 64-bits OS Version MySQL Version
CitSQL for MySQL for Solaris 10 Solaris 10 MySQL Version 5 and
x86 Later
64-bits
Sun SPARC 32-bits OS Version MySQL Version
CitSQL for MySQL for SUN Solaris Solaris 10 MySQL Version 5 and
10 SPARC 32-bits Later
Sun SPARC 64-bits OS Version MySQL Version
CitSQL for MySQL for SUN Solaris Solaris 10 MySQL Version 5 and
10 SPARC 64-bits Later
Windows 32-bits OS Version MySQL Version
CitSQL for MySQL for Windows 32- Windows 7 MySQL Version 5 and
bits Later
Windows 8 “
Windows Server 2012 “
Windows 10 “
Page 64
Getting Started with CitSQL Version 1.3
Page 65
Getting Started with CitSQL Version 1.3
FAQ
Q- I am running the sample program dbconnect on an HP-UX Itanium platform.
After running the program as follows:
>cobcrun dbconnect
I receive the following error:
dbconnect.COB:0: libcob: Cannot find module 'RCQPGSQL'
Please advise.:
A- The precompiler translates EXEC SQL into several CALL "RCQPGSQL"... statements. The
RCQPGSQL.so module is provided in /bin directory
You must make it available to the COBOL runtime CALL resolution by placing his path into the
COB_LIBRARY_PATH environment variable list.
Q- While executing a compiled program (cobol with sql ) , I receive an error. The shared object
file libssl.so.4 is expected, and is not part of your distribution. Please advise.
Page 66
Getting Started with CitSQL Version 1.3
A- This library is required by libpq.so. COBOL-IT provides a version of libpq.so with the
distribution, but it may be different than the version you have installed, so dependencies may be
different than expected. In that case, the best course of action is to :
• Install the PostgreSQL libraries from your Linux distribution.
• Rename the lib folder in your CitPostgreSQL distribution.
www.cobol-it.com
June, 2020
Page 67