Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <sqlca.h>
- #include <stdlib.h>
- #include <sqlda.h>
- #include <sqlcpr.h>
- struct testTableInfo{
- int Id;
- asciiz Name;
- asciiz Information;
- };
- void sql_error(msg)
- char *msg;
- {
- char err_msg[512];
- size_t buf_len, msg_len;
- EXEC SQL WHENEVER SQLERROR CONTINUE;
- printf("\n%s\n", msg);
- buf_len = sizeof (err_msg);
- sqlglm(err_msg, &buf_len, &msg_len);
- printf("%.*s\n", msg_len, err_msg);
- EXEC SQL ROLLBACK RELEASE;
- exit(EXIT_FAILURE);
- }
- void main()
- {
- struct testTableInfo *ptrRecrodsTestTable;
- char userid[70];
- if ((ptrRecrodsTestTable =
- (struct testTableInfo *) malloc(sizeof(struct testTableInfo))) == 0)
- {
- fprintf(stderr, "Memory allocation error.\n");
- exit(EXIT_FAILURE);
- }
- EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--");
- printf("Please enter a connection string :");
- scanf("%s",userid);
- EXEC SQL CONNECT :userid;
- EXEC SQL DECLARE recordCounter CURSOR FOR
- SELECT COUNT(*) FROM T_TESTTABLE;
- EXEC SQL OPEN recordCounter;
- EXEC SQL WHENEVER NOT FOUND DO break;
- for (;;)
- {
- EXEC SQL FETCH recordCounter INTO :ptrRecrodsTestTable;
- printf("%d",ptrRecrodsTestTable->Id);
- }
- EXEC SQL CLOSE recordCounter;
- EXEC SQL COMMIT WORK RELEASE;
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement