全部博文(116)
分类:
2005-03-11 14:18:45
// Title: mysample.cpp
// Description:
// Submit simple query example with error handling and
// transaction monitoring
#include
#include
#include
#include
ITCallbackResult my_error_handler(const ITErrorManager &errorobject,void *userdata,long errorlevel)
{
// Cast the user data into a stream
ostream *stream = (ostream *) userdata;
(*stream) << "my_error_handler: errorlevel="
<< errorlevel
<< " sqlstate="
<< errorobject.SqlState()
<< ' '
<< errorobject.ErrorText()
<< endl;
return IT_NOTHANDLED;
}
int main(int, char *)
{
// Make a connection using defaults
ITConnection conn;
conn.Open();
// Create a query object
ITQuery query(conn);
char qtext[1024];
// Add the callback handler
query.AddCallback(my_error_handler, (void *) &cerr);
sprintf(qtext,"select * from sd_pkinfo");
if (!query.ExecForIteration(qtext))
{
cout << "Could not execute query: " << qtext << endl;
}
else
{
ITRow *row;
int rowcount = 0;
while ((row = query.NextRow()) != NULL)
{
rowcount++;
cout << row->Printable() << endl;
row->Release();
}
cout << rowcount << " rows received, Command:"<< query.Command() << endl;
}
conn.Close();
cout << endl;
return 0;
}
------------------------------------------cut here----------------------------------------------------------
#
# INFORMIX SOFTWARE, INC.
#
# PROPRIETARY DATA
#
# THIS DOCUMENT CONTAINS TRADE SECRET DATA WHICH IS THE PROPERTY OF
# INFORMIX SOFTWARE, INC. THIS DOCUMENT IS SUBMITTED TO RECIPIENT IN
# CONFIDENCE. INFORMATION CONTAINED HEREIN MAY NOT BE USED, COPIED OR
# DISCLOSED IN WHOLE OR IN PART EXCEPT AS PERMITTED BY WRITTEN AGREEMENT
# SIGNED BY AN OFFICER OF INFORMIX SOFTWARE, INC.
#
# THIS MATERIAL IS ALSO COPYRIGHTED AS AN UNPUBLISHED WORK UNDER
# SECTIONS 104 AND 408 OF TITLE 17 OF THE UNITED STATES CODE.
# UNAUTHORIZED USE, COPYING OR OTHER REPRODUCTION IS PROHIBITED BY LAW.
#
# Title: Makefile
#
# Description:
# This Makefile can be used to build C++ Interface examples on Solaris.
# It assumes INFORMIXDIR is set.
#
CPPIFDIR = $(INFORMIXDIR)
CCHOME = /opt/aCC
CCPP = $(CCHOME)/bin/aCC
CCPLUS = $(CCPP) $(HEADEROPTS)
CCFLAGS = +DS2.0 +DA2.0W -g $(CCDEFS)
CCPPFLAGS = -I$(INFORMIXDIR)/incl/public -I$(INFORMIXDIR)/incl -I$(INFORMIXDIR)/incl/esql
CCPLINK = $(CCPLUS) $(CCFLAGS) $(CCPPFLAGS)
CC = /opt/ansic/bin/cc
C-COMPILE-FLAGS = $(CCFLAGS)
CCDEFS = -ext -D__STDCPP__ -DMITRACE_OFF -DIT_HAS_DISTINCT_LONG_DOUBLE -DIT_COMPILER_HAS_LONG_LONG -D_PROTOTYPES -DIT_DO_NOT_SIMULATE_BOOL +Z
RANLIB = echo
RM = rm -f
ESQL = $(INFORMIXDIR)/bin/esql
LOCALINCL = -I$(CPPIFDIR)/incl/c++
LIBS_SYSTEM = -lm -lcl -lsec
LIBS_ESQL = -L$(INFORMIXDIR)/lib/esql -L$(INFORMIXDIR)/lib -lifsql -lifasf -lifgen -lifos -lifgls -lifglx $(INFORMIXDIR)/lib/esql/checkapi.o
LIBS_LIBMI = -L$(INFORMIXDIR)/lib/dmi -lifdmi
LIBS_CPPIF = -L$(CPPIFDIR)/lib/c++ -lifc++
LIBS = $(LIBS_CPPIF) $(LIBS_LIBMI) $(LIBS_ESQL) $(LIBS_SYSTEM)
PROGRAMS = mysample
.SUFFIXES: .cc .o .hdr .cpp
.cc.o:
@rm -f $@
$(CCPLUS) $(CCFLAGS) $(LOCALINCL) $(CCPPFLAGS) -c $<
.cpp.o:
@rm -f $@
$(CCPLUS) $(CCFLAGS) $(LOCALINCL) $(CCPPFLAGS) -c $<
all: $(PROGRAMS)
setup: all
blobload: blobload.ec
$(ESQL) blobload.ec -o blobload
mysample: mysample.o
$(CCPLINK) -o mysample mysample.o $(SUBSYSTEMS.link) $(LIBS)
clean:
$(RM) *.o $(PROGRAMS) core