Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <pthread.h>
- #include <signal.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <time.h>
- #include "FMEngine.h"
- #include "mxml.h"
- #include "log.h"
- #include "ocilib.h"
- OCI_Connection *cn;
- char *dbSource = "ORA920";
- char *dbUser = "omc";
- char *dbPass = "just5ismp";
- char *sql1 = "select alarmno,alarmtitle,AlarmType,warnlevel,warn_cap,warn_cap_value, \
- to_char(warntime,'YYYY-MM-DD hh24:mi:ss'),to_char(warntime,'YYYY-MM-DD hh24:mi:ss'), \
- Factory ,BusinessCode,AlarmReason,Proposal,Explain from warn_record where isconfirm = 0 and isclear = 0";
- char *sql2 = "select alarmno,alarmtitle,AlarmType,warnlevel,warn_cap,warn_cap_value, \
- to_char(warntime,'YYYY-MM-DD hh24:mi:ss'),to_char(warntime,'YYYY-MM-DD hh24:mi:ss'), \
- Factory ,BusinessCode,AlarmReason,Proposal,Explain from warn_record where isconfirm = 1 and isclear = 1";
- char *update1 = "update warn_record set isconfirm = 1 where alarmno = :tint";
- char *update2 = "update warn_record set isclear = 2 where alarmno = :tint";
- int func()
- {
- OCI_Statement *st1,*st2,*sti1,*sti2;
- OCI_Resultset *rs1,*rs2;
- if(cn == NULL) return -1;
- st1 = OCI_StatementCreate(cn);
- if(st1==NULL)
- {
- printf("st1 ERR");
- return 0;
- }
- //printf("show sql1[%s]\n",sql1);
- OCI_ExecuteStmt(st1,sql1);
- rs1 = OCI_GetResultset(st1);
- int alarmno[MAX_LEN];
- int tlen=0;
- if(rs1 !=NULL)
- {
- while(OCI_FetchNext(rs1))
- {
- if(OCI_GetInt(rs1,1) == 0)
- {
- printf("after sql1,date inaccuracy!");
- continue;
- }
- alarmno[tlen]=OCI_GetInt(rs1,1);
- tlen++;
- printf("1st:AlarmNo==>[%d]\n",alarmno[tlen]);
- }
- if(rs1)
- OCI_ReleaseResultsets(st1);
- if(st1)
- OCI_StatementFree(st1);
- sti1 = OCI_StatementCreate(cn);
- if(sti1==NULL)
- {
- printf("sti1 ERR");
- return 0;
- }
- OCI_Prepare(sti1,update1);
- OCI_BindArraySetSize(sti1,MAX_LEN);
- OCI_BindArrayOfInts(sti1,":tint",(int*)alarmno,0);
- OCI_Execute(sti1);
- OCI_Commit(cn);
- if(sti1)
- OCI_StatementFree(sti1);
- }
- st2 = OCI_StatementCreate(cn);
- if(st2==NULL)
- {
- printf("st2 ERR");
- return 0;
- }
- OCI_ExecuteStmt(st2,sql2);
- //printf("show sql2[%s]\n",sql2);
- rs2 = OCI_GetResultset(st2);
- int talarmno[MAX_LEN];
- int ttlen=0;
- if(rs2 !=NULL)
- {
- while(OCI_FetchNext(rs2))
- {
- if(OCI_GetInt(rs2,1) == 0)
- {
- printf("after sql2,date inaccuracy!");
- continue;
- }
- talarmno[tlen]=OCI_GetInt(rs2,1);
- ttlen++;
- printf("2nd: AlarmNo ==>[%d]\n",talarmno[tlen]);
- }
- if(rs2)
- OCI_ReleaseResultsets(st2);
- if(st2)
- OCI_StatementFree(st2);
- sti2 = OCI_StatementCreate(cn);
- if(sti2==NULL)
- {
- printf("sti2 ERR");
- return 0;
- }
- OCI_Prepare(sti2,update2);
- OCI_BindArraySetSize(sti2,MAX_LEN);
- OCI_BindArrayOfInts(sti2,":tint",(int*)talarmno,0);
- OCI_Execute(sti2);
- OCI_Commit(cn);
- if(sti2)
- OCI_StatementFree(sti2);
- }
- return 0;
- }
- int main()
- {
- OCI_Initialize(NULL,NULL,OCI_ENV_THREADED );
- printf("connInit dbSource [%s] dbUser [%s] dbPass [%s]",dbSource,dbUser,dbPass);
- cn = OCI_ConnectionCreate(dbSource,dbUser,dbPass,OCI_SESSION_DEFAULT);
- printf("catch connInit");
- while(1)
- func();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement