以前在Linux机器上移植到AIX机器上就编译不过, 赶紧改动下。
【AIX机器上makefile】
### My first *.cpp make in AIX 2009-11-26 by tan
include $(ORACLE_HOME)/precomp/lib/env_precomp.mk
# ORACLE_HOME=/oracle/product/10.2.0
## /oracle/product/10.2.0/precomp/admin/pcscfg.cfg
#ys_include=(/usr/include)
#ltype=short
PRECOMPHOME=$$ORACLE_HOME/precomp/public
PROCINCLUDE=include=. /
include=${ORACLE_HOME}/precomp/syshdr /
include=${ORACLE_HOME}/precomp/public /
include=${ORACLE_HOME}/rdbms/public /
include=${ORACLE_HOME}/rdbms/demo /
include=${ORACLE_HOME}/plsql/public /
include=${ORACLE_HOME}/network/public /
include=$(ORACLE_HOME)/precomp/lib/env_precomp.mk
ORALIBPATH=$(ORACLE_HOME)/lib
ORALIBS=-lclntsh -ldl -lm -lnsl ##-lsqlora8
CC = xlc -q64 ## 注意:大写'C' for c++
CC_FLAGS = -g # -bnoquiet
ORACLE_INCLUDE = $(PRECOMPHOME) /
$(ORACLE_HOME)/rdbms/demo /
$(ORACLE_HOME)/otrace/public /
$(ORACLE_HOME)/rdbms/public /
$(ORACLE_HOME)/network/public /
$(ORACLE_HOME)/plsql/public /
INCLUDE= -I. -I/usr/include -I/usr/vacpp/include -I${ORACLE_HOME}/precomp/public /
-I${ORACLE_HOME}/rdbms/public /
-I${ORACLE_HOME}/rdbms/demo /
-I${ORACLE_HOME}/plsql/public
##-I${ORACLE_HOME}/network/public
LIBPATH=-L/usr/vacpp/lib -L/usr/lib -L/lib -L$(ORALIBPATH) $(ORALIBS)
all : connectDb
connectDb : connectDb.o
$(CC) -I${INCLUDE} -o connectDb connectDb.o $(LIBPATH)
connectDb.o : connectDb.pc
proc PARSE=NONE INAME=connectDb.pc ONAME=connectDb.c ${PROCINCLUDE} USERID=crmcn_demo/crmcn_demo@devdb81 IRECLEN=512 MODE=ANSI DYNAMIC=ANSI THREADS=YES SQLCHECK=SEMANTICS
$(CC) $(CC_FLAGS) ${INCLUDE} connectDb.c
##cp connectDb.o $(BIN_PATH)/connectDb.o
clean:
/rm -rf *.bak *.txt *.log *.o *.lis *.bak *.c connectDb t* run
[注意]
pc文件中的注释要用/**/, 而不能用//.
声明变量要放到函数模块的前部, 它的前面不能有其他语句。
【代码】
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE ORACA;
/* connectDb.pc */
#include "connectDb.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sqlca.h>
#include <sqlda.h>
#include <sqlcpr.h>
/**
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
**/
EXEC ORACLE OPTION (RELEASE_CURSOR = YES);
EXEC SQL BEGIN DECLARE SECTION;
#define MAX_VAR_LEN 200
#define MAX_NAME_LEN 31
#define DATA_ROW_NUM 100
#define DATA_COL_NUM 20
#define THREAD_NUMS 1 /* thread numbers */
char SQLSTATE[6];
long SQLCODE;
sql_context ctx[THREAD_NUMS];
EXEC SQL END DECLARE SECTION;
/* oracle database at machine 's address */
char g_oracle_db_ipaddr[20] = "192.168.202.253";
/***************************************************/
char username[] = "crmcn_demo";
char password[] = "crmcn_demo";
char dbname[] = "devdb81";
/***************************************************/
int g_disconnect_flag = 0;
typedef struct stru_one_row {
char one_row[DATA_COL_NUM][MAX_VAR_LEN];
} stru_one_row ;
void enableThreads(void);
void release_db();
int db_connect(sql_context ctx, char *username, char *password, char *server);
void db_close(sql_context ctx);
int sql_process(sql_context ctx, char *psql);
int table_isExist(sql_context ctx, char *ptablename);
int init_context_and_connectDB(sql_context *ctx, char *username, char *password, char *servername);
void free_context(sql_context *ctx);
int isConnected(sql_context ctx);
int create_TRIGGER_CDR_MAIN(sql_context ctx, char *ptime);
int create_trigger_cdr_siglink_xxx(sql_context ctx, char *ptime);
int isExist_Object(sql_context ctx, char *objectname);
stru_one_row * process_only_select(sql_context ctx, char *psql, int *nCol, int *nRow);
static stru_one_row * process_out(sql_context ctx, int *nCol, int *nRow);
static int do_re_connect();
static int ispingok(char *pIpAddr);
static void test_sql_process();
static void test_select();
int main(void)
{
test_sql_process();
return 0;
}
void test_select()
{
static char sz_sql[] = "select id from mytest ";
int nRow = 0, nCol = 0;
int i, j;
int k;
stru_one_row *p_mana_row = NULL;
enableThreads();
if( 1 != init_context_and_connectDB(&ctx[1], username, password, dbname) )
{ fprintf(stderr, "connect error/n");
free_context(&ctx[1]);
exit(1);
}
else
{test_sql_process();
fprintf(stderr, "db connect success/n");
}
for (k = 0; k < 10; k++)
{
p_mana_row = process_only_select(ctx[1], sz_sql, &nCol, &nRow);
if( NULL == p_mana_row )
{ fprintf(stderr, "NULL == p_mana_row, k = [%d] /n", k);
continue;
}
if(0 == nRow)
{ printf(