如何使用 Gnucobol 在 cobol 中连接到 MYSQL 数据库(通过 Dockerfile)

问题描述 投票:0回答:1

我正在开发容器中 COBOL 应用程序的原型。现在我想将它连接到数据库,我找到了 ODBC。但它不起作用,因为我在 docker 构建过程中收到以下错误:

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)

这是我的 cobol SQL 代码:

    EXEC SQL
      INCLUDE SQLCA
    END-EXEC.
    EXEC SQL
     CONNECT TO 'MySQL' USER 'admin' IDENTIFIED BY 'ABCDEF'
    END-EXEC.
    EXEC SQL
       SELECT Vorname INTO :host_variable
       FROM table_name
       WHERE condition
     END-EXEC.

这是我的 Dockerfile:

RUN apt-get update && \
  apt-get install -y \
  g++ \
  make \
  cmake \
  unzip \
  wget \
  gnucobol \
  unixodbc \
  unixodbc-dev \
  wget \
  gnupg \
  && 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


# Set environment variables for MySQL Database configuration
ENV MYSQL_DATABASE=bank1 \
    MYSQL_USER=admin \
    MYSQL_PASSWORD=B:7L1f!r?xP3?8    \
    MYSQL_HOST=database-1.cho40iaoa3pu.eu-central-1.rds.amazonaws.com \
    MYSQL_PORT=3306

# Setup ODBC Driver in odbcinst.ini
RUN echo "[MySQL]\n\
Description=ODBC for MySQL\n\
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so\n\
Setup=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8S.so\n\
FileUsage=1\n\
Server=$MYSQL_HOST\n\
User=$MYSQL_USER\n\
Password=$MYSQL_PASSWORD\n\
Database=$MYSQL_DATABASE\n\
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 -lsqlca
docker odbc gnucobol
1个回答
0
投票

对于

EXEC anything
,您需要首先预处理文件,在本例中使用
EXEC SQL
预处理器。对于 MySQL,我建议使用 [GixSQL}(https://github.com/mridoni/gixsql)。

这会将

EXEC
转换为“纯 COBOL”,然后将其传递给 COBOL 编译器。

© www.soinside.com 2019 - 2024. All rights reserved.