4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLから複数行を取得するCOBOLプログラムの例

Posted at

PostgreSQLに検索クエリを発行して、その結果の複数行を取得するCOBOLプログラム(以下)を作成する。このCOBOLプログラムでは、デフォルト値から変更されたPostgreSQLのすべての設定について、パラメータ名と設定値をpg_settingsから取得する。

COBOLプログラム例

このCOBOLプログラムのコードの各行は、8桁目以降から始まっていることに要注意。
COBOLプログラムのコンパイルについてはこちらを参考に。

       IDENTIFICATION DIVISION.
       PROGRAM-ID. DESCRIBE_CONFIG.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 PG_SETTINGS.
            03 NAME    PIC X(48).
            03 SETTING PIC X(48).

       EXEC SQL BEGIN DECLARE SECTION END-EXEC.
       01 DBNAME   PIC X(32) VALUE "postgres".
       01 USERNAME PIC X(32) VALUE "postgres".
       01 PASSWORD PIC X(32) VALUE SPACE.
       EXEC SQL END DECLARE SECTION END-EXEC.

       EXEC SQL INCLUDE SQLCA END-EXEC.

       PROCEDURE DIVISION.
       MAIN.
            EXEC SQL
                CONNECT :USERNAME IDENTIFIED BY :PASSWORD
                    USING :DBNAME
            END-EXEC.

            EXEC SQL DECLARE PSCURSOR CURSOR FOR
                 SELECT name, setting FROM pg_settings
                      WHERE setting <> boot_val ORDER BY name
            END-EXEC.

            EXEC SQL
                 OPEN PSCURSOR
            END-EXEC.

            EXEC SQL
                 FETCH PSCURSOR INTO :PG_SETTINGS
            END-EXEC

            PERFORM UNTIL SQLCODE NOT = 0
                 DISPLAY PG_SETTINGS
                 EXEC SQL
                      FETCH PSCURSOR INTO :PG_SETTINGS
                 END-EXEC
            END-PERFORM.

            EXEC SQL
                 CLOSE PSCURSOR
            END-EXEC

            EXEC SQL
                DISCONNECT ALL
            END-EXEC.

            STOP RUN.
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?