Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API HELP

Status
Not open for further replies.

2742

Programmer
Apr 23, 2001
34
NZ
Hi Everyone
I'm need some help! Could someone please explain to me how API's work and how i could use one in simple english. I have looked up in DB2's help and found an API that i would like to use and it comes with a sample C program - but i have no idea of how it works or how i could use it. Do i need to compile it, is there extra code i need to write. If i need to compile, is there a compiler for os/2 that anyone would recommend. I can't find a simple explination any where - please help

Thanks in advance for any information you can give me.
 
Basically, there are two ways you could go. First, there is IBM's embedded SQL which allows you to essentially code your SQL statements in your C program. Second, there is the IBM DB2 Call Level Interface which I consider to be your best approach.

Developing a program with CLI is fairly straight-forward. First, you need to allocate an environment handle using the SQLAllocEnv function. Then you need to allocate a connection handle using the SQLAllocConnect function. Then you need to connect to your database using the SQLConnect function. From there, all you need to do is use the SQLAllocStmt function to allocate a statement handle and use SQLExecDirect to issue your SQL statement. If the statement is a SELECT statement you may need to use some other functions such as SQLNumResultCols, SQLRowCount, SQLDescribeCol, SQLBindCol, and SQLFetch. When you are done, you can commit your work using SQLTransact and free your handles using the SQLFreeStmt, SQLFreeConnect, and SQLFreeEnv.

As for compilers, for OS/2 I still use the tried and true IBMC2 compiler. But, we have also been successful using the IBM VisualAge for C++ compilers. If you join IBM's developer program, you can get IBM VisualAge for C++ for free!

Regards,
Suresh
 
Thank you very much. I have found a sample c program that i want to use that has came with DB/2. I have pre-compiled the .SQC program and ready to compile the .c program. I have already got visual age but finding it difficult to use. It kept hanging the server when i went to save. Do you know where i could get a copy of IBMC2 from?

Thanks
 
Unfortunately, IBMC2 is very old and not available anymore. However, VisualAge for C++ is the follow-on compiler. You might want to try compiling from a command line rather than using their cumbersome GUI interface. Here is a makefile that you can use as a model. Just change the PROG to your program name and run it from an OS/2 command window: NMAKE <makefile_name>

###########################################################################
# Makefile for Query Server DB/2 Interface
###########################################################################
# CHANGES:
# 11/14/98 SKG Created for OS/2 environment
###########################################################################

#** Environment variables used to identify source and target modules
PROG = MAQSDB2
LIBS =
OBJS =

#** Compiler/Linkage Editor definitions
CC = ICC
CLINK = LINK386
OBJEXT = obj

#** Libraries
SRCDIR = ..\SRC
OBJDIR = .
MAKDIR = .
EXEDIR = .

#** Environment variables used to identify Include and Library paths
INCLUDE=$(SRCDIR);U:\TOOLKT21\C\OS2H;U:\IBMCPP\INCLUDE;U:\TCPIP\INCLUDE;U:\SQLLIB\INCLUDE;
LIB=U:\TOOLKT21\OS2LIB;U:\IBMCPP\LIB;U:\TCPIP\LIB;U:\SQLLIB\LIB;

#** Compilation/Linkage Editor flags
CFLAGS = /DOS2 /C+ /Q+ /SS /G3 /Gm+ /Gt+ /Gd- /W3 /Ls+ /Li- /O- /Ti+
CPFLAGS = /DOS2 /C+ /Q+ /G3 /Gm+ /Gt+ /Gd- /W3 /Ls+ /Li- /O- /Ti+ /Tdp
LFLAGS = /CO /NOL /MAP:full /LINENUMBERS /BAT

#***************************************************************************
#** Inference rules for compilations and links
#***************************************************************************
.SUFFIXES: .c .cpp .h .obj .def .dll .exe .lib .lrf
{$(SRCDIR)}.c{$(OBJDIR)}.$(OBJEXT):
$(CC) $(CFLAGS) /I$(INCLUDE) /Fo$*.$(OBJEXT) /Fl$*.LST $<

{$(SRCDIR)}.h{$(OBJDIR)}.$(OBJEXT):
$(CC) $(CFLAGS) /I$(INCLUDE) /Fo$*.$(OBJEXT) /Fl$*.LST $<

{$(SRCDIR)}.cpp{$(OBJDIR)}.$(OBJEXT):
$(CC) $(CPFLAGS) /I$(INCLUDE) /Fo$*.$(OBJEXT) /Fl$*.LST $<

{$(OBJDIR)}.obj{$(EXEDIR)}.dll:
$(CLINK) $(LFLAGS) @$*.LRF

{$(MAKDIR)}.def{$(EXEDIR)}.dll:
$(CLINK) $(LFLAGS) @$*.LRF

{$(MAKDIR)}.lrf{$(EXEDIR)}.dll:
$(CLINK) $(LFLAGS) @$*.LRF

{$(OBJDIR)}.obj{$(EXEDIR)}.exe:
$(CLINK) $(LFLAGS) @$*.LRF

{$(MAKDIR)}.def{$(EXEDIR)}.lib:
IMPLIB $(IFLAGS) $*.LIB $<
#***************************************************************************

#** Query Server DB2 Subsystem components
all: $(EXEDIR)\$(PROG).exe

$(EXEDIR)\$(PROG).exe: $(OBJDIR)\$(PROG).$(OBJEXT) $(OBJDIR)\$(PROG).DEF $(OBJDIR)\$(PROG).LRF

$(OBJDIR)\$(PROG).$(OBJEXT): $(SRCDIR)\$(PROG).c $(SRCDIR)\$(PROG).h
#End
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top