参考:Windows上にPostgreSQLを導入する。
OpenCOBOL FAQ
手順:
- PostgreSQL の win32 版の zip をダウンロード
PostgreSQL へ行き、DownloadのBinaryPackagesのWindowsを開き、
zip archive を開き、betaで無い最新の Win x86-32 をクリックして
postgresql-9.5.5-1-windows-binaries.zip (今なら)をダウンロードする。 - postgresql-9.5.5-1-windows-binaries.zip を解凍して、中のpgsqlを
C:\PgmFiles\ に移動する。 - そのC:\PgmFiles\pgsql\bin をパスに追加する。
- そのbinの中のPgAdmin3をディスクトップかスタートにショートカットを貼るとよい。
- pgsql 内に data と log のディレクトリを作る。
- > cd C:\PgmFiles
> initdb -U postgres -A password -E utf8 -W -D data
を実行する。パスワードの設定を要求されるので、入れて忘れないように。つぎに、
> pg_ctl -D data -l log\logfile start
を実行する。 - 上記4のPgAdmin3を実行して、サーバーを追加する。
名前は適当に、ホストはlocalhost パスワードは上記6のパスワードを入れる。 - 次にCOBOL側の設定を前回までと同様に、特にコマンドプロンプトから最初に、
C:\PgmFiles\gnu-cobol-2.0\set_env_vs.bat
を忘れずに! - ソースを作成。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. - コマンドプロンプトから
cd C:\PgmFiles\xampp\cgi-bin\gnucob\src
cobc -x -v -l \Pgmfiles\pgsql\lib\libpq pgcob.cob
を実行すると、pgcob.exe ができる。 - 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
などと表示されれば完了。
コメント
コメントを投稿