|
楼主 |
发表于 2003-9-2 16:34:57
|
显示全部楼层
to kj501:
正如老哥所说,的确是用./test1和./test2来运行make通过的程序,可是出现了如下错误
[root@BillingServer oci_demo]# ./test1
Connect OK
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Select 1 item fail
**********************************************
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
select from cursor failed
select from cursor succeed
**********************************************
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
Error - OCI_INVALID_HANDLE
段错误
下面为test1.c的文件内容
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <errno.h>
#include <math.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <semaphore.h>
#include <pthread.h>
#include "dbfunc.h"
int main()
{
int result, query_qt, i;
char buf[1024], sql[1024];
emp_t emp;
emp_t *pa_emp;
resume_t resume;
//连接到数据库
if(DbsInit()==DB_OK && DbsConnect(10)==DB_OK)
{
printf("Connect fail\n");
DbsDisConnect(10);
exit(1);
}
printf("Connect OK\n");
//select一条记录,使用bind
emp.no=0;
strcpy(sql, "select no,upd_ts,name,duty,age,salary from emp where no=:no");
if(DbsEMP_SEL(10, sql, &emp)!=DB_OK)
{
printf("Select 1 rec fail\n");
}
else
{
printf("no:%.0lf\n", emp.no);
printf("upd_ts:%s\n", emp.upd_ts);
printf("name:%s\n", emp.name);
printf("duty:%s\n", emp.duty);
printf("age:%d\n", emp.age);
printf("salary:%.2lf\n", emp.salary);
printf("select 1 rec succeed\n");
}
printf("**********************************************\n");
//select一批记录,使用带bind的cursor,由cursor函数分配空间
emp.age=35;
strcpy(sql, "select no,name,age from emp where age<:age order by no");
if(DbsEMP_CUR(10, sql, &emp, &pa_emp, &query_qt)!=DB_OK)
{
printf("select from cursor failed\n");
}
for(i=0; i<query_qt; i++)
{
printf("no:%.0lf name:%s age:%d\n",
pa_emp.no, pa_emp.name, pa_emp.age);
}
printf("select from cursor succeed\n");
free(pa_emp);
//由应用释放cursor函数分配的空间
printf("**********************************************\n");
//插入带blob类型域的记录
resume.no=10;
resume.resume=(char *)malloc(32768);
strcpy(buf, "我一个高中同学告诉我,他小时将“边区的太阳红又红”听成“变压器的太阳红又红”!!!!!他还给我讲了原因。因为他那时根本不知道“边区”是什么?只是记得很清楚,每天傍晚时可以看见村子西边红红的落日。最要命的是在他们村子西边的某个高处架着一台变压器。傍晚的时候,刚好可以看到变压器上方一轮红日此美景让我的同学印象颇深。于是便与每天傍晚都放的那首歌联系起来。此君还纳闷,为什么写歌的人知道他们村的变压器放在西边。");
resume.resume[0]='\0';
for(i=0; i<1; i++)
strcat(resume.resume, buf);
if(DbsRESUME_INS(10, NULL, &resume)!=DB_OK)
{
printf("insert blob fail\n");
DbsRollback(10);
}
else
{
printf("insert blob succeed\n");
DbsCommit(10);
}
printf("**********************************************\n");
//选出带blob类型域的记录
resume.no=10;
resume.resume[0]='\0';
if(DbsRESUME_SEL(10, NULL, &resume)!=DB_OK)
{
printf("select lob fail\n");
}
else
{
printf("no:%.0lf len:%d\n", resume.no, strlen(resume.resume));
printf("resume:%s\n", resume.resume);
printf("select lob succeed\n");
}
printf("**********************************************\n");
//删除一条记录,直接执行
sprintf(sql, "delete from resume where no=%d", 10);
if(DbsSQLExec(10, sql)!=DB_OK)
{
printf("Delete resume fail\n");
DbsRollback(10);
}
else
{
printf("Delete resume succeed\n");
DbsCommit(10);
}
printf("**********************************************\n");
ERROR:
DbsDisConnect(10);
exit(0);
}
和表情符号冲突了,希望没有什么大碍,不过都是printf语句里,没什么大关系
我随便建立了两个表emp和resume,下面是sql代码
create table emp
(
no number(12) not null,
upd_ts date not null,
name char(20) not null,
duty char(1) not null,
age number(6) not null,
salary number(12,2) not null,
primary key (no)
);
insert into emp values(0,sysdate,'职员0','1',20,1000);
insert into emp values(1,sysdate,'职员1','1',30,2000);
insert into emp values(2,sysdate,'职员2','1',40,2500);
create table resume
(
no number(12) not null,
resume blob not null,
primary key (no)
);
不知如何处理段错误呢
|
|