Chinaunix首页 | 论坛 | 博客
  • 博客访问: 425790
  • 博文数量: 116
  • 博客积分: 7087
  • 博客等级: 少将
  • 技术积分: 1175
  • 用 户 组: 普通用户
  • 注册时间: 2005-02-19 23:32
文章分类

全部博文(116)

文章存档

2012年(1)

2011年(2)

2010年(10)

2009年(21)

2008年(18)

2007年(12)

2006年(21)

2005年(31)

我的朋友

分类:

2005-03-11 14:18:45

用informix object interface 写了一个小程序,执行一条简单的查询语句.提供了makefile和mysample.cpp源码,有兴趣的可以试试.

//  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


阅读(1182) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~