Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sqlca.h>
  4. #include <stdlib.h>
  5. #include <sqlda.h>
  6. #include <sqlcpr.h>
  7.  
  8.  
  9. struct testTableInfo{
  10.   int     Id;
  11.   asciiz      Name;
  12.   asciiz      Information;
  13. };
  14.  
  15. void sql_error(msg)
  16.     char *msg;
  17. {
  18.     char err_msg[512];
  19.     size_t buf_len, msg_len;
  20.  
  21.     EXEC SQL WHENEVER SQLERROR CONTINUE;
  22.  
  23.     printf("\n%s\n", msg);
  24.  
  25.     buf_len = sizeof (err_msg);
  26.     sqlglm(err_msg, &buf_len, &msg_len);
  27.     printf("%.*s\n", msg_len, err_msg);
  28.  
  29.     EXEC SQL ROLLBACK RELEASE;
  30.     exit(EXIT_FAILURE);
  31. }
  32.  
  33. void main()
  34. {
  35.     struct testTableInfo *ptrRecrodsTestTable;
  36.     char userid[70];
  37.  
  38.     if ((ptrRecrodsTestTable =
  39.         (struct testTableInfo *) malloc(sizeof(struct testTableInfo))) == 0)
  40.     {
  41.         fprintf(stderr, "Memory allocation error.\n");
  42.         exit(EXIT_FAILURE);
  43.     }
  44.  
  45.     EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--");
  46.  
  47.     printf("Please enter a connection string :");
  48.     scanf("%s",userid);
  49.  
  50.     EXEC SQL CONNECT :userid;
  51.  
  52.     EXEC SQL DECLARE recordCounter CURSOR FOR
  53.         SELECT COUNT(*) FROM T_TESTTABLE;
  54.  
  55.     EXEC SQL OPEN recordCounter;
  56.  
  57.  
  58.     EXEC SQL WHENEVER NOT FOUND DO break;
  59.  
  60.     for (;;)
  61.     {
  62.         EXEC SQL FETCH recordCounter INTO :ptrRecrodsTestTable;
  63.         printf("%d",ptrRecrodsTestTable->Id);
  64.     }
  65.  
  66.     EXEC SQL CLOSE recordCounter;
  67.  
  68.     EXEC SQL COMMIT WORK RELEASE;
  69.     exit(EXIT_SUCCESS);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement