スキップしてメイン コンテンツに移動

GnuCobolでPostgreSQLをWin10で最速スタート


解説:GnuCobol標準機能でDB(PostgrSQL)を使う。
参考:Windows上にPostgreSQLを導入する。
     OpenCOBOL FAQ

手順:

  1. PostgreSQL の win32 版の zip をダウンロード
    PostgreSQL へ行き、DownloadのBinaryPackagesのWindowsを開き、
    zip archive を開き、betaで無い最新の Win x86-32 をクリックして
    postgresql-9.5.5-1-windows-binaries.zip (今なら)をダウンロードする。
  2. postgresql-9.5.5-1-windows-binaries.zip を解凍して、中のpgsqlを
    C:\PgmFiles\ に移動する。
  3. そのC:\PgmFiles\pgsql\bin をパスに追加する。
  4. そのbinの中のPgAdmin3をディスクトップかスタートにショートカットを貼るとよい。
  5. pgsql 内に data と log のディレクトリを作る。
  6. > cd C:\PgmFiles
    > initdb -U postgres -A password -E utf8 -W -D data
    を実行する。パスワードの設定を要求されるので、入れて忘れないように。つぎに、
    > pg_ctl -D data -l log\logfile start
    を実行する。
  7. 上記4のPgAdmin3を実行して、サーバーを追加する。
    名前は適当に、ホストはlocalhost パスワードは上記6のパスワードを入れる。
  8. 次にCOBOL側の設定を前回までと同様に、特にコマンドプロンプトから最初に、
    C:\PgmFiles\gnu-cobol-2.0\set_env_vs.bat
    を忘れずに!
  9. ソースを作成。C:\PgmFiles\xampp\cgi-bin\gnucob\src などに pgcob.cob を作る。
    OCOBOL*> ***************************************************************
          *> Author:    Brian Tiffin
          *> Date:      20091129
          *> Purpose:   PostgreSQL connection test
          *> Tectonics: cobc -x -lpq pgcob.cob
          *> ***************************************************************
           identification division.
           program-id. pgcob.

           data division.
           working-storage section.
           01 pgconn usage pointer.
           01 pgres  usage pointer.
           01 resptr usage pointer.
           01 resstr pic x(80) based.
           01 result usage binary-long.
           01 answer pic x(80).

          *> ***************************************************************
           procedure division.
           display "Before connect:" pgconn end-display

           call static "PQconnectdb" using by reference
               "dbname = postgres user = postgres password = xxxx" & x"00"
               returning pgconn
           end-call
           display "After connect: " pgconn end-display

           call static "PQstatus" using by value pgconn returning result
            end-call
           display "Status:        " result end-display

           call static "PQuser" using by value pgconn returning resptr
            end-call

           set address of resstr to resptr
           string resstr delimited by x"00" into answer end-string
           display "User:          " function trim(answer) end-display

           display "call PQexec" end-display
           call static "PQexec" using
               by value pgconn
               by reference "SELECT VERSION();" & x"00"
               returning pgres
           end-call
           display pgres end-display

           if pgres not = null then
          *> Pull out a result. row 0, field 0 <*
               call static "PQgetvalue" using
                   by value pgres
                   by value 0
                   by value 0
                   returning resptr
               end-call
               set address of resstr to resptr
               string resstr delimited by x"00" into answer end-string
               display "Version:       " answer end-display
           end-if

           call static "PQfinish" using by value pgconn returning null
            end-call
           display "After finish:  " pgconn end-display

           call static "PQstatus" using by value pgconn returning result
            end-call
           display "Status:        " result end-display

          *> this will now return garbage  <*
           call static "PQuser" using by value pgconn returning resptr
            end-call
           set address of resstr to resptr
           string resstr delimited by x"00" into answer end-string
           display "User after:    " function trim(answer) end-display

           goback.
           end program pgcob.
  10. コマンドプロンプトから
    cd C:\PgmFiles\xampp\cgi-bin\gnucob\src
    cobc -x -v -l \Pgmfiles\pgsql\lib\libpq pgcob.cob
    を実行すると、pgcob.exe ができる。
  11. pgcob を実行すると、
    C:\PgmFiles\xampp\cgi-bin\gnucob\src>pgcob
    Before connect:0x00000000
    After connect: 0x01892a90
    Status:        +0000000000
    User:          postgres
    call PQexec
    0x0189b830
    Version:       PostgreSQL 9.5.5, compiled by Visual C++ build 1800, 32-bit     
    After finish:  0x01892a90
    Status:        +0000000001
    User after:    postgresQL 9.5.5, compiled by Visual C++ build 1800, 32-bit

    などと表示されれば完了。

コメント

このブログの人気の投稿

GnuCobolをWindows10で最速スタート

解説:Windows10でCOBOLをコンパイルする環境を簡単に作ります。 参考: MinGW と GunuCOBOL(OpenCOBOL)のインストールメモ 手順: GnuCobolをダウンロード  https://osdn.jp/projects/sfnet_open-cobol/releases/ ここの「その他全ファイル」の gnu-cobol の 2.0 の中の gnu-cobol-2.0_nightly_r658_win32_vc11_bin.7z   をダウンロードする。 7-zをダウンロード&インストール GnuCobolを展開 VisualStudioCommintyをインストール ソース作成>C:\PgmFiles\gnu-cobol-2.0\test1.cob コンパイル コマンドプロンプトを開く cd C:\PgmFiles\gnu-cobol-2.0 set_env_vs.bat path C:\PgmFiles\gnu-cobol-2.0\bin;%path% set COB_CONFIG_DIR=C:\PgmFiles\gnu-cobol-2.0\config cobc -x -v test1.cob

GnuCobolのscreen_sectionでWindows10で日本語を使う。

解説:Windowsのコマンドプロンプトでscreen sectionから日本語表示してみる。 参考: GnuCOBOL FAQ         Windowsでcursesを使う 手順:  先ず、日本語無しで、 GnuCOBOL FAQ の screening.cob をコピーしてコンパイルして実行してみる。…出来ない場合は前回までを参照してください。 screen section の … value "title line" . の部分を value "タイトル行". と、日本語を入れる。 ソースの文字コードはUTF-8で保存する。(エディタは使い易いのを使う) コンパイルして実行する。> cobc -x -v screening.cob 日本語は化けて表示されないはず。(ソースをSJIS保存してもダメなはず。) コマンドプロンプト環境をUTF-8に変える。>  chcp 65001 screening.exe を実行してみる。日本語は化けて表示されないはず。 GnuCobolに付属のpdcurses.dll を作り直します。 こちらのページ から pdcurses のソースのzipをダウンロードして解凍します。 set PDCURSES_SRCDIR=C:\(解凍した場所)\ "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" cd C:\(解凍した場所)\win32 nmake -f vcwin32.mak DLL=Y /A /D UTF8=1 pdcurses.dll 出来た pdcurses.dll を gnu-cobol-2.0\bin\ に上書き貼付けする。 上記4のscreening.exe を実行する。日本語が表示されるはず。  GnuCOBOL FAQ から gnucobol-colours.cob をコピーして screen section を日本語を入れてみてコンパイルして実行する。 日本語は内部で3バイト以上の場合もあるので、COBOL固定フォーマットでは72桁を超えやすいので注意して、...