I am working on a prototype for a COBOL application in a container. Now I wanted to connect it to a database and I found ODBC. But it did not work our because I got the following error during docker build:
0.141 /function/YTR93.cob: 36: error: SQLCA: No such file or directory
0.141 /function/YTR93.cob: 36: error: syntax error, unexpected Identifier or Literal, expecting .
0.151 /function/YTR93.cob: 34: error: invalid level number 'EXEC'
0.152 cobc: call to cobc_plex_strdup with NULL pointer
0.152 cobc: aborting codegen for /function/YTR92.cob (unknown: unknown)
After that, someone recommended GixSQL for preprocessing the file. However, I was quite confused about the installation process. The instructions were not very clear, and I found myself struggling to understand how to connect it with ODBC. In addition, I was not sure where I needed to set the DATASRC connection string. Would you mind helping me with installing GixSQL the right way? Thank you so much in advance.
My DockerFile:
# Define app directory
ARG FUNCTION_DIR="/function"
FROM --platform=linux/amd64 python:3.10-buster as build-image
# Vermeiden von Interaktionen bei der Installation von Paketen
ENV DEBIAN_FRONTEND=noninteractive
# Install aws-lambda build dependencies
RUN apt-get update &&
apt-get install -y
g++
make
cmake
unzip
wget
gnucobol
gnucobol-cobsql
unixodbc
unixodbc-dev
wget
gnupg
default-libmysqlclient-dev
make
&& rm -rf /var/lib/apt/lists/*
&& wget https://dev.mysql.com/get/Downloads/Connector-ODBC/8.0/mysql-connector-odbc_8.0.29-1ubuntu20.04_amd64.deb
&& dpkg -i mysql-connector-odbc_8.0.29-1ubuntu20.04_amd64.deb || apt-get -f install -y
&& apt-get clean
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /mysql-connector-odbc_*.deb
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Create function directory
CMD mkdir -p ${FUNCTION_DIR}
# Copy code directory
COPY app/* ${FUNCTION_DIR}/
# Install the runtime interface client
RUN pip install
--target ${FUNCTION_DIR}
awslambdaric
# Install the AWS Software Development Kit for Python
RUN pip install
--target ${FUNCTION_DIR}
boto3
# Install requests for Python
RUN pip install
--target ${FUNCTION_DIR}
requests
# Set environment variables for MySQL Database configuration
ENV MYSQL_DATABASE=bank1
MYSQL_USER=admin
MYSQL_PASSWORD=12345
MYSQL_HOST=databasestring
MYSQL_PORT=3306
# Setup ODBC Driver in odbcinst.ini
RUN echo "[MySQL]n
Description=ODBC for MySQLn
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.son
Setup=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8S.son
FileUsage=1n
Server=$MYSQL_HOSTn
User=$MYSQL_USERn
Password=$MYSQL_PASSWORDn
Database=$MYSQL_DATABASEn
Port=$MYSQL_PORT" > /etc/odbcinst.ini
# Interaktive Frontend Einstellungen zurücksetzen
ENV DEBIAN_FRONTEND=dialog
# Compile the cobol programs
#RUN cobc -x --free ${FUNCTION_DIR}/YTR93.cob ${FUNCTION_DIR}/YTR92.cob -o ${FUNCTION_DIR}/cobol-program
#RUN cobc -x -free -std=default -I/usr/include/mysql/ ${FUNCTION_DIR}/YTR93.cob -o YTR93 -L/usr/lib -lmysqlclient
RUN cobc -x -std=default -free -I/usr/include/mysql /function/YTR93.cob -o YTR93 -L/usr/lib -lmysqlclient
# Multi-stage build: grab a fresh copy of the base image
FROM python:3.10-buster
# Ensure that the runtime requirements for cobol are met
RUN apt update && apt install libcob4
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the build image dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.handler" ]
My Cobol:
PROCEDURE DIVISION.
MAIN-PROCEDURE.
EXEC SQL
CONNECT TO :DB-NAME AT :DB-SERVER AS :DB-USER IDENTIFIED BY :DB-PASSWORD
END-EXEC.
EVALUATE SQLCODE
WHEN 0
DISPLAY "Connected successfully to remote MySQL server."
WHEN OTHER
DISPLAY "Connection error: ", SQLERRMC
END-EVALUATE.
I tried to integrate it into my application but I did not find a way to execute it via Dockerfile.