Advertisement
Guest User

Untitled

a guest
Jan 11th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <pthread.h>
  5. #include <signal.h>
  6. #include <unistd.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <time.h>
  10.  
  11. #include "FMEngine.h"
  12. #include "mxml.h"
  13. #include "log.h"
  14. #include "ocilib.h"
  15.  
  16. OCI_Connection *cn;
  17.  
  18. char *dbSource = "ORA920";
  19. char *dbUser = "omc";
  20. char *dbPass = "just5ismp";
  21.  
  22. char *sql1 = "select alarmno,alarmtitle,AlarmType,warnlevel,warn_cap,warn_cap_value, \
  23. to_char(warntime,'YYYY-MM-DD hh24:mi:ss'),to_char(warntime,'YYYY-MM-DD hh24:mi:ss'), \
  24. Factory ,BusinessCode,AlarmReason,Proposal,Explain from warn_record where isconfirm = 0 and isclear = 0";
  25.  
  26. char *sql2 = "select alarmno,alarmtitle,AlarmType,warnlevel,warn_cap,warn_cap_value, \
  27. to_char(warntime,'YYYY-MM-DD hh24:mi:ss'),to_char(warntime,'YYYY-MM-DD hh24:mi:ss'), \
  28. Factory ,BusinessCode,AlarmReason,Proposal,Explain from warn_record where isconfirm = 1 and isclear = 1";
  29.  
  30. char *update1 = "update warn_record set isconfirm = 1 where alarmno = :tint";
  31.  
  32. char *update2 = "update warn_record set isclear = 2 where alarmno = :tint";
  33.  
  34. int func()
  35. {
  36.  
  37. OCI_Statement *st1,*st2,*sti1,*sti2;
  38. OCI_Resultset *rs1,*rs2;
  39.  
  40. if(cn == NULL) return -1;
  41.  
  42. st1 = OCI_StatementCreate(cn);
  43.  
  44. if(st1==NULL)
  45. {
  46. printf("st1 ERR");
  47. return 0;
  48. }
  49.  
  50. //printf("show sql1[%s]\n",sql1);
  51. OCI_ExecuteStmt(st1,sql1);
  52.  
  53. rs1 = OCI_GetResultset(st1);
  54.  
  55. int alarmno[MAX_LEN];
  56. int tlen=0;
  57.  
  58. if(rs1 !=NULL)
  59. {
  60. while(OCI_FetchNext(rs1))
  61. {
  62. if(OCI_GetInt(rs1,1) == 0)
  63. {
  64. printf("after sql1,date inaccuracy!");
  65. continue;
  66. }
  67.  
  68. alarmno[tlen]=OCI_GetInt(rs1,1);
  69. tlen++;
  70.  
  71. printf("1st:AlarmNo==>[%d]\n",alarmno[tlen]);
  72.  
  73. }
  74.  
  75. if(rs1)
  76. OCI_ReleaseResultsets(st1);
  77. if(st1)
  78. OCI_StatementFree(st1);
  79.  
  80. sti1 = OCI_StatementCreate(cn);
  81.  
  82. if(sti1==NULL)
  83. {
  84. printf("sti1 ERR");
  85. return 0;
  86. }
  87.  
  88. OCI_Prepare(sti1,update1);
  89. OCI_BindArraySetSize(sti1,MAX_LEN);
  90. OCI_BindArrayOfInts(sti1,":tint",(int*)alarmno,0);
  91.  
  92. OCI_Execute(sti1);
  93. OCI_Commit(cn);
  94.  
  95. if(sti1)
  96. OCI_StatementFree(sti1);
  97. }
  98.  
  99. st2 = OCI_StatementCreate(cn);
  100.  
  101. if(st2==NULL)
  102. {
  103. printf("st2 ERR");
  104. return 0;
  105. }
  106.  
  107. OCI_ExecuteStmt(st2,sql2);
  108. //printf("show sql2[%s]\n",sql2);
  109.  
  110. rs2 = OCI_GetResultset(st2);
  111.  
  112. int talarmno[MAX_LEN];
  113. int ttlen=0;
  114.  
  115. if(rs2 !=NULL)
  116. {
  117. while(OCI_FetchNext(rs2))
  118. {
  119. if(OCI_GetInt(rs2,1) == 0)
  120. {
  121. printf("after sql2,date inaccuracy!");
  122. continue;
  123. }
  124.  
  125. talarmno[tlen]=OCI_GetInt(rs2,1);
  126. ttlen++;
  127.  
  128. printf("2nd: AlarmNo ==>[%d]\n",talarmno[tlen]);
  129.  
  130. }
  131. if(rs2)
  132. OCI_ReleaseResultsets(st2);
  133. if(st2)
  134. OCI_StatementFree(st2);
  135.  
  136. sti2 = OCI_StatementCreate(cn);
  137.  
  138. if(sti2==NULL)
  139. {
  140. printf("sti2 ERR");
  141. return 0;
  142. }
  143.  
  144. OCI_Prepare(sti2,update2);
  145. OCI_BindArraySetSize(sti2,MAX_LEN);
  146. OCI_BindArrayOfInts(sti2,":tint",(int*)talarmno,0);
  147.  
  148. OCI_Execute(sti2);
  149. OCI_Commit(cn);
  150.  
  151. if(sti2)
  152. OCI_StatementFree(sti2);
  153. }
  154. return 0;
  155.  
  156. }
  157.  
  158. int main()
  159. {
  160. OCI_Initialize(NULL,NULL,OCI_ENV_THREADED );
  161. printf("connInit dbSource [%s] dbUser [%s] dbPass [%s]",dbSource,dbUser,dbPass);
  162. cn = OCI_ConnectionCreate(dbSource,dbUser,dbPass,OCI_SESSION_DEFAULT);
  163. printf("catch connInit");
  164.  
  165.  
  166. while(1)
  167. func();
  168.  
  169. return 0;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement