[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [open-cobol-list] OpenCobol (Windows) and DB2
From: |
Frank Swarbrick |
Subject: |
Re: [open-cobol-list] OpenCobol (Windows) and DB2 |
Date: |
Tue, 08 Aug 2006 05:22:18 -0600 |
User-agent: |
Mozilla Thunderbird 1.0.7 (Macintosh/20050923) |
Franklin Ankum wrote:
Hi Frank,
Has anyone attempted, or better yet had success, with compiling any of
the DB2 LUW v8.2 samples using Sergey's OpenCOBOL Windows binaries?
From what I can tell the DB2 API functions must be called using the
__stdcall calling convention, while OpenCOBOL is built using the __cdecl
calling convention. Is there any way I can force the sqlapi calls to
use __stdcall while keeping all of the others as __cdecl?
Yes, i also had this problem!
I did i dirty trick to make these calls work:
By changing every call to "sqlg????" in the DB2 Precompiled output to
"sqla????"
These are the API Calls for C-Programs.
I did many test and everything seems to work fine, although i'm not
really pleased about this aproach.
We could ask IBM for an Enhancement of the Preprocessor to accept the
Target "OPENCOBOL"
We could, but I'm guessing we would not get very far! :-) There is
documentation on how to write your own DB2 pre-processor. Dunno how
difficult that might be, but it might be worth a shot.
Sergey's comment to this was:
OC will not work with stdcall and if stupid DB2 has only stdcall
library than it might be only choice to create (take from DB2) some
db2.h header file which will define those functions as stdcall, and
simply add the inclusion of this header to the libcob.h
That should resolve the issue.
Cool. Seems to work for me.
Here's my compile/link batch file:
cobc -fstatic-call -c checkerr.cbl -I"%DB2PATH%"\include\cobol_a
cobc -fstatic-call -c -x %1.cbl -I "%DB2PATH%"\include\cobol_a
link -debug -out:%1.exe %1.obj checkerr.obj "%DB2PATH%\lib\db2api.lib"
C:\OpenCobol\libcob.lib C:\OpenCobol\gmp.lib
(the preceeding link is just a single line)
Seems to me that IBM COBOL for Micro Focus COBOL must use stdcall for
all of their calls, which is why they use the sqlg_ functions, while
OpenCOBOL uses C linkage (cdecl), and thus the problem. Does this sound
right? Sounds like a job for the ENTRY-CONVENTION clause!
eg...
PROGRAM-ID. SQLGCALL IS PROTOTYPE AS 'sqlgcall'.
OPTIONS.
ENTRY-CONVENTION IS STDCALL.
DATA DIVISION.
LINKAGE SECTION.
01 CALL-TYPE BINARY-SHORT UNSIGNED.
01 SECTION-NBR BINARY-SHORT UNSIGNED.
01 SQLDA-ID-IN BINARY-SHORT UNSIGNED.
01 SQLDA-ID-OUT BINARY-SHORT UNSIGNED.
01 RESERVED-PTR POINTER.
01 RC BINARY-LONG.
PROCEDURE DIVISION USING
BY VALUE CALL-TYPE
SECTION-NBR
SQLDA-ID-IN
SQLDA-ID-OUT
RESERVED-PTR
RETURNING RC.
END PROGRAM SQLGCALL.
Boy, that sure is a lot of typing for what seems such a simple thing!
But that's COBOL for you... Not sure if the above is even correct, but
hey...
Anyway, I'll go with adding the following to libcob.h:
#include <sql.h>
#include <sqlaprep.h>
Thanks!
Frank